Lines Matching +full:switch +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
40 static const char *tmu_mode_name(enum tb_switch_tmu_mode mode) in tmu_mode_name() argument
42 switch (mode) { in tmu_mode_name()
46 return "uni-directional, LowRes"; in tmu_mode_name()
48 return "uni-directional, HiFi"; in tmu_mode_name()
50 return "bi-directional, HiFi"; in tmu_mode_name()
52 return "enhanced uni-directional, MedRes"; in tmu_mode_name()
64 enum tb_switch_tmu_mode mode) in tb_switch_set_tmu_mode_params() argument
69 freq = tmu_params[mode].freq_meas_window; in tb_switch_set_tmu_mode_params()
70 avg = tmu_params[mode].avg_const; in tb_switch_set_tmu_mode_params()
73 sw->tmu.cap + TMU_RTR_CS_0, 1); in tb_switch_set_tmu_mode_params()
81 sw->tmu.cap + TMU_RTR_CS_0, 1); in tb_switch_set_tmu_mode_params()
86 sw->tmu.cap + TMU_RTR_CS_15, 1); in tb_switch_set_tmu_mode_params()
100 sw->tmu.cap + TMU_RTR_CS_15, 1); in tb_switch_set_tmu_mode_params()
105 u32 delta_avg = tmu_params[mode].delta_avg_const; in tb_switch_set_tmu_mode_params()
108 sw->tmu.cap + TMU_RTR_CS_18, 1); in tb_switch_set_tmu_mode_params()
116 sw->tmu.cap + TMU_RTR_CS_18, 1); in tb_switch_set_tmu_mode_params()
128 sw->tmu.cap + TMU_RTR_CS_0, 1); in tb_switch_tmu_ucap_is_supported()
141 sw->tmu.cap + TMU_RTR_CS_3, 1); in tb_switch_tmu_rate_read()
155 sw->tmu.cap + TMU_RTR_CS_3, 1); in tb_switch_tmu_rate_write()
163 sw->tmu.cap + TMU_RTR_CS_3, 1); in tb_switch_tmu_rate_write()
172 ret = tb_port_read(port, &data, TB_CFG_PORT, port->cap_tmu + offset, 1); in tb_port_tmu_write()
180 port->cap_tmu + offset, 1); in tb_port_tmu_write()
188 if (!port->sw->tmu.has_ucap) in tb_port_tmu_set_unidirectional()
211 port->cap_tmu + TMU_ADP_CS_3, 1); in tb_port_tmu_is_unidirectional()
224 port->cap_tmu + TMU_ADP_CS_8, 1); in tb_port_tmu_is_enhanced()
231 /* Can be called to non-v2 lane adapters too */
237 if (!tb_switch_tmu_enhanced_is_supported(port->sw)) in tb_port_tmu_enhanced_enable()
241 port->cap_tmu + TMU_ADP_CS_8, 1); in tb_port_tmu_enhanced_enable()
251 port->cap_tmu + TMU_ADP_CS_8, 1); in tb_port_tmu_enhanced_enable()
255 enum tb_switch_tmu_mode mode) in tb_port_set_tmu_mode_params() argument
260 repl_timeout = tmu_params[mode].repl_timeout; in tb_port_set_tmu_mode_params()
261 repl_threshold = tmu_params[mode].repl_threshold; in tb_port_set_tmu_mode_params()
262 repl_n = tmu_params[mode].repl_n; in tb_port_set_tmu_mode_params()
263 dirswitch_n = tmu_params[mode].dirswitch_n; in tb_port_set_tmu_mode_params()
266 port->cap_tmu + TMU_ADP_CS_8, 1); in tb_port_set_tmu_mode_params()
276 port->cap_tmu + TMU_ADP_CS_8, 1); in tb_port_set_tmu_mode_params()
281 port->cap_tmu + TMU_ADP_CS_9, 1); in tb_port_set_tmu_mode_params()
291 port->cap_tmu + TMU_ADP_CS_9, 1); in tb_port_set_tmu_mode_params()
294 /* Can be called to non-v2 lane adapters too */
300 if (!tb_switch_tmu_enhanced_is_supported(port->sw)) in tb_port_tmu_rate_write()
304 port->cap_tmu + TMU_ADP_CS_9, 1); in tb_port_tmu_rate_write()
312 port->cap_tmu + TMU_ADP_CS_9, 1); in tb_port_tmu_rate_write()
338 offset = sw->tmu.cap + TMU_RTR_CS_0; in tb_switch_tmu_set_time_disruption()
341 offset = sw->cap_vsec_tmu + TB_TIME_VSEC_3_CS_26; in tb_switch_tmu_set_time_disruption()
364 tb_sw_dbg(sw, "TMU: supports uni-directional mode\n"); in tmu_mode_init()
367 tb_sw_dbg(sw, "TMU: supports enhanced uni-directional mode\n"); in tmu_mode_init()
375 sw->tmu.mode = TB_SWITCH_TMU_MODE_OFF; in tmu_mode_init()
381 sw->tmu.mode = TB_SWITCH_TMU_MODE_MEDRES_ENHANCED_UNI; in tmu_mode_init()
384 sw->tmu.mode = TB_SWITCH_TMU_MODE_LOWRES; in tmu_mode_init()
386 sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_UNI; in tmu_mode_init()
388 sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_BI; in tmu_mode_init()
391 sw->tmu.mode = TB_SWITCH_TMU_MODE_HIFI_BI; in tmu_mode_init()
394 /* Update the initial request to match the current mode */ in tmu_mode_init()
395 sw->tmu.mode_request = sw->tmu.mode; in tmu_mode_init()
396 sw->tmu.has_ucap = ucap; in tmu_mode_init()
402 * tb_switch_tmu_init() - Initialize switch TMU structures
403 * @sw: Switch to initialized
419 sw->tmu.cap = ret; in tb_switch_tmu_init()
426 port->cap_tmu = cap; in tb_switch_tmu_init()
433 tb_sw_dbg(sw, "TMU: current mode: %s\n", tmu_mode_name(sw->tmu.mode)); in tb_switch_tmu_init()
438 * tb_switch_tmu_post_time() - Update switch local time
439 * @sw: Switch whose time to update
441 * Updates switch local time using time posting procedure.
447 struct tb_switch *root_switch = sw->tb->root_switch; in tb_switch_tmu_post_time()
459 if (!root_switch->tmu.cap) in tb_switch_tmu_post_time()
463 root_switch->tmu.cap + TMU_RTR_CS_1, in tb_switch_tmu_post_time()
479 /* Tell the switch that time sync is disrupted for a while */ in tb_switch_tmu_post_time()
484 post_local_time_offset = sw->tmu.cap + TMU_RTR_CS_22; in tb_switch_tmu_post_time()
485 post_time_offset = sw->tmu.cap + TMU_RTR_CS_24; in tb_switch_tmu_post_time()
486 post_time_high_offset = sw->tmu.cap + TMU_RTR_CS_25; in tb_switch_tmu_post_time()
490 * of the new switch. in tb_switch_tmu_post_time()
498 * Have the new switch update its local time by: in tb_switch_tmu_post_time()
522 } while (--retries && post_time); in tb_switch_tmu_post_time()
525 ret = -ETIMEDOUT; in tb_switch_tmu_post_time()
554 * tb_switch_tmu_disable() - Disable TMU of a switch
555 * @sw: Switch whose TMU to disable
562 if (sw->tmu.mode == TB_SWITCH_TMU_MODE_OFF) in tb_switch_tmu_disable()
572 * In case of uni-directional time sync, TMU handshake is in tb_switch_tmu_disable()
573 * initiated by upstream router. In case of bi-directional in tb_switch_tmu_disable()
576 * cases although it is needed only for the bi-directional mode. in tb_switch_tmu_disable()
577 * We avoid changing upstream router's mode since it might in tb_switch_tmu_disable()
579 * uni-directional mode and we don't want to change it's TMU in tb_switch_tmu_disable()
580 * mode. in tb_switch_tmu_disable()
591 switch (sw->tmu.mode) { in tb_switch_tmu_disable()
594 /* The switch may be unplugged so ignore any errors */ in tb_switch_tmu_disable()
614 sw->tmu.mode = TB_SWITCH_TMU_MODE_OFF; in tb_switch_tmu_disable()
620 /* Called only when there is failure enabling requested mode */
630 * bi-directional or uni-directional TMU mode, get back to the TMU in tb_switch_tmu_off()
631 * configurations in off mode. In case of additional failures in in tb_switch_tmu_off()
638 switch (sw->tmu.mode_request) { in tb_switch_tmu_off()
653 tb_switch_set_tmu_mode_params(sw, sw->tmu.mode); in tb_switch_tmu_off()
659 * This function is called when the previous TMU mode was
705 sw->cap_vsec_tmu + TB_TIME_VSEC_3_CS_9, 1); in tb_switch_tmu_disable_objections()
712 sw->cap_vsec_tmu + TB_TIME_VSEC_3_CS_9, 1); in tb_switch_tmu_disable_objections()
723 * This function is called when the previous TMU mode was
734 tmu_rates[sw->tmu.mode_request]); in tb_switch_tmu_enable_unidirectional()
738 ret = tb_switch_set_tmu_mode_params(sw, sw->tmu.mode_request); in tb_switch_tmu_enable_unidirectional()
766 * This function is called when the previous TMU mode was
771 unsigned int rate = tmu_rates[sw->tmu.mode_request]; in tb_switch_tmu_enable_enhanced()
776 ret = tb_switch_set_tmu_mode_params(sw, sw->tmu.mode_request); in tb_switch_tmu_enable_enhanced()
783 ret = tb_port_set_tmu_mode_params(up, sw->tmu.mode_request); in tb_switch_tmu_enable_enhanced()
795 ret = tb_port_set_tmu_mode_params(down, sw->tmu.mode_request); in tb_switch_tmu_enable_enhanced()
816 unsigned int rate = tmu_rates[sw->tmu.mode]; in tb_switch_tmu_change_mode_prev()
822 * In case of any failure in one of the steps when change mode, in tb_switch_tmu_change_mode_prev()
823 * get back to the TMU configurations in previous mode. in tb_switch_tmu_change_mode_prev()
827 switch (sw->tmu.mode) { in tb_switch_tmu_change_mode_prev()
843 tb_switch_set_tmu_mode_params(sw, sw->tmu.mode); in tb_switch_tmu_change_mode_prev()
845 switch (sw->tmu.mode) { in tb_switch_tmu_change_mode_prev()
862 unsigned int rate = tmu_rates[sw->tmu.mode_request]; in tb_switch_tmu_change_mode()
870 switch (sw->tmu.mode_request) { in tb_switch_tmu_change_mode()
892 return -EINVAL; in tb_switch_tmu_change_mode()
895 ret = tb_switch_set_tmu_mode_params(sw, sw->tmu.mode_request); in tb_switch_tmu_change_mode()
899 /* Program the new mode and the downstream router lane adapter */ in tb_switch_tmu_change_mode()
900 switch (sw->tmu.mode_request) { in tb_switch_tmu_change_mode()
916 return -EINVAL; in tb_switch_tmu_change_mode()
935 * tb_switch_tmu_enable() - Enable TMU on a router
938 * Enables TMU of a router to be in uni-directional Normal/HiFi or
939 * bi-directional HiFi mode. Calling tb_switch_tmu_configure() is
950 (sw->tmu.mode_request == TB_SWITCH_TMU_MODE_LOWRES || in tb_switch_tmu_enable()
951 sw->tmu.mode_request == TB_SWITCH_TMU_MODE_HIFI_UNI)) { in tb_switch_tmu_enable()
963 * The used mode changes are from OFF to in tb_switch_tmu_enable()
964 * HiFi-Uni/HiFi-BiDir/Normal-Uni or from Normal-Uni to in tb_switch_tmu_enable()
965 * HiFi-Uni. in tb_switch_tmu_enable()
967 if (sw->tmu.mode == TB_SWITCH_TMU_MODE_OFF) { in tb_switch_tmu_enable()
968 switch (sw->tmu.mode_request) { in tb_switch_tmu_enable()
981 ret = -EINVAL; in tb_switch_tmu_enable()
984 } else if (sw->tmu.mode == TB_SWITCH_TMU_MODE_LOWRES || in tb_switch_tmu_enable()
985 sw->tmu.mode == TB_SWITCH_TMU_MODE_HIFI_UNI || in tb_switch_tmu_enable()
986 sw->tmu.mode == TB_SWITCH_TMU_MODE_HIFI_BI) { in tb_switch_tmu_enable()
989 ret = -EINVAL; in tb_switch_tmu_enable()
995 * of the child node - see above. in tb_switch_tmu_enable()
998 ret = tb_switch_tmu_rate_write(sw, tmu_rates[sw->tmu.mode_request]); in tb_switch_tmu_enable()
1002 tb_sw_warn(sw, "TMU: failed to enable mode %s: %d\n", in tb_switch_tmu_enable()
1003 tmu_mode_name(sw->tmu.mode_request), ret); in tb_switch_tmu_enable()
1005 sw->tmu.mode = sw->tmu.mode_request; in tb_switch_tmu_enable()
1006 tb_sw_dbg(sw, "TMU: mode set to: %s\n", tmu_mode_name(sw->tmu.mode)); in tb_switch_tmu_enable()
1013 * tb_switch_tmu_configure() - Configure the TMU mode
1014 * @sw: Router whose mode to change
1015 * @mode: Mode to configure
1017 * Selects the TMU mode that is enabled when tb_switch_tmu_enable() is
1021 * returns %-EOPNOTSUPP if the requested mode is not possible (not
1024 int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode) in tb_switch_tmu_configure() argument
1026 switch (mode) { in tb_switch_tmu_configure()
1032 if (!sw->tmu.has_ucap) in tb_switch_tmu_configure()
1033 return -EOPNOTSUPP; in tb_switch_tmu_configure()
1043 return -EOPNOTSUPP; in tb_switch_tmu_configure()
1045 return -EOPNOTSUPP; in tb_switch_tmu_configure()
1051 tb_sw_warn(sw, "TMU: unsupported mode %u\n", mode); in tb_switch_tmu_configure()
1052 return -EINVAL; in tb_switch_tmu_configure()
1055 if (sw->tmu.mode_request != mode) { in tb_switch_tmu_configure()
1056 tb_sw_dbg(sw, "TMU: mode change %s -> %s requested\n", in tb_switch_tmu_configure()
1057 tmu_mode_name(sw->tmu.mode), tmu_mode_name(mode)); in tb_switch_tmu_configure()
1058 sw->tmu.mode_request = mode; in tb_switch_tmu_configure()