Lines Matching refs:sw
58 static bool tb_switch_tmu_enhanced_is_supported(const struct tb_switch *sw) in tb_switch_tmu_enhanced_is_supported() argument
60 return usb4_switch_version(sw) > 1; in tb_switch_tmu_enhanced_is_supported()
63 static int tb_switch_set_tmu_mode_params(struct tb_switch *sw, in tb_switch_set_tmu_mode_params() argument
72 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_set_tmu_mode_params()
73 sw->tmu.cap + TMU_RTR_CS_0, 1); in tb_switch_set_tmu_mode_params()
80 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, in tb_switch_set_tmu_mode_params()
81 sw->tmu.cap + TMU_RTR_CS_0, 1); in tb_switch_set_tmu_mode_params()
85 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_set_tmu_mode_params()
86 sw->tmu.cap + TMU_RTR_CS_15, 1); in tb_switch_set_tmu_mode_params()
99 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, in tb_switch_set_tmu_mode_params()
100 sw->tmu.cap + TMU_RTR_CS_15, 1); in tb_switch_set_tmu_mode_params()
104 if (tb_switch_tmu_enhanced_is_supported(sw)) { in tb_switch_set_tmu_mode_params()
107 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_set_tmu_mode_params()
108 sw->tmu.cap + TMU_RTR_CS_18, 1); in tb_switch_set_tmu_mode_params()
115 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, in tb_switch_set_tmu_mode_params()
116 sw->tmu.cap + TMU_RTR_CS_18, 1); in tb_switch_set_tmu_mode_params()
122 static bool tb_switch_tmu_ucap_is_supported(struct tb_switch *sw) in tb_switch_tmu_ucap_is_supported() argument
127 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_tmu_ucap_is_supported()
128 sw->tmu.cap + TMU_RTR_CS_0, 1); in tb_switch_tmu_ucap_is_supported()
135 static int tb_switch_tmu_rate_read(struct tb_switch *sw) in tb_switch_tmu_rate_read() argument
140 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_tmu_rate_read()
141 sw->tmu.cap + TMU_RTR_CS_3, 1); in tb_switch_tmu_rate_read()
149 static int tb_switch_tmu_rate_write(struct tb_switch *sw, int rate) in tb_switch_tmu_rate_write() argument
154 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_tmu_rate_write()
155 sw->tmu.cap + TMU_RTR_CS_3, 1); in tb_switch_tmu_rate_write()
162 return tb_sw_write(sw, &val, TB_CFG_SWITCH, in tb_switch_tmu_rate_write()
163 sw->tmu.cap + TMU_RTR_CS_3, 1); in tb_switch_tmu_rate_write()
188 if (!port->sw->tmu.has_ucap) in tb_port_tmu_set_unidirectional()
237 if (!tb_switch_tmu_enhanced_is_supported(port->sw)) in tb_port_tmu_enhanced_enable()
300 if (!tb_switch_tmu_enhanced_is_supported(port->sw)) in tb_port_tmu_rate_write()
332 static int tb_switch_tmu_set_time_disruption(struct tb_switch *sw, bool set) in tb_switch_tmu_set_time_disruption() argument
337 if (tb_switch_is_usb4(sw)) { in tb_switch_tmu_set_time_disruption()
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()
345 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_tmu_set_time_disruption()
354 return tb_sw_write(sw, &val, TB_CFG_SWITCH, offset, 1); in tb_switch_tmu_set_time_disruption()
357 static int tmu_mode_init(struct tb_switch *sw) in tmu_mode_init() argument
362 ucap = tb_switch_tmu_ucap_is_supported(sw); in tmu_mode_init()
364 tb_sw_dbg(sw, "TMU: supports uni-directional mode\n"); in tmu_mode_init()
365 enhanced = tb_switch_tmu_enhanced_is_supported(sw); in tmu_mode_init()
367 tb_sw_dbg(sw, "TMU: supports enhanced uni-directional mode\n"); in tmu_mode_init()
369 ret = tb_switch_tmu_rate_read(sw); in tmu_mode_init()
375 sw->tmu.mode = TB_SWITCH_TMU_MODE_OFF; in tmu_mode_init()
377 if (tb_route(sw)) { in tmu_mode_init()
378 struct tb_port *up = tb_upstream_port(sw); 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()
395 sw->tmu.mode_request = sw->tmu.mode; in tmu_mode_init()
396 sw->tmu.has_ucap = ucap; in tmu_mode_init()
409 int tb_switch_tmu_init(struct tb_switch *sw) in tb_switch_tmu_init() argument
414 if (tb_switch_is_icm(sw)) in tb_switch_tmu_init()
417 ret = tb_switch_find_cap(sw, TB_SWITCH_CAP_TMU); in tb_switch_tmu_init()
419 sw->tmu.cap = ret; in tb_switch_tmu_init()
421 tb_switch_for_each_port(sw, port) { in tb_switch_tmu_init()
429 ret = tmu_mode_init(sw); 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()
443 int tb_switch_tmu_post_time(struct tb_switch *sw) in tb_switch_tmu_post_time() argument
447 struct tb_switch *root_switch = sw->tb->root_switch; in tb_switch_tmu_post_time()
452 if (!tb_route(sw)) in tb_switch_tmu_post_time()
455 if (!tb_switch_is_usb4(sw)) in tb_switch_tmu_post_time()
480 ret = tb_switch_tmu_set_time_disruption(sw, true); 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()
492 ret = tb_sw_write(sw, &local_time, TB_CFG_SWITCH, in tb_switch_tmu_post_time()
507 ret = tb_sw_write(sw, &post_time, TB_CFG_SWITCH, post_time_offset, 2); in tb_switch_tmu_post_time()
511 ret = tb_sw_write(sw, &post_time_high, TB_CFG_SWITCH, in tb_switch_tmu_post_time()
518 ret = tb_sw_read(sw, &post_time, TB_CFG_SWITCH, in tb_switch_tmu_post_time()
529 tb_sw_dbg(sw, "TMU: updated local time to %#llx\n", local_time); in tb_switch_tmu_post_time()
532 tb_switch_tmu_set_time_disruption(sw, false); in tb_switch_tmu_post_time()
559 int tb_switch_tmu_disable(struct tb_switch *sw) in tb_switch_tmu_disable() argument
562 if (sw->tmu.mode == TB_SWITCH_TMU_MODE_OFF) in tb_switch_tmu_disable()
565 if (tb_route(sw)) { in tb_switch_tmu_disable()
569 down = tb_switch_downstream_port(sw); in tb_switch_tmu_disable()
570 up = tb_upstream_port(sw); in tb_switch_tmu_disable()
582 ret = tb_switch_tmu_rate_write(sw, tmu_rates[TB_SWITCH_TMU_MODE_OFF]); in tb_switch_tmu_disable()
591 switch (sw->tmu.mode) { in tb_switch_tmu_disable()
611 tb_switch_tmu_rate_write(sw, tmu_rates[TB_SWITCH_TMU_MODE_OFF]); in tb_switch_tmu_disable()
614 sw->tmu.mode = TB_SWITCH_TMU_MODE_OFF; in tb_switch_tmu_disable()
616 tb_sw_dbg(sw, "TMU: disabled\n"); in tb_switch_tmu_disable()
621 static void tb_switch_tmu_off(struct tb_switch *sw) in tb_switch_tmu_off() argument
626 down = tb_switch_downstream_port(sw); in tb_switch_tmu_off()
627 up = tb_upstream_port(sw); in tb_switch_tmu_off()
638 switch (sw->tmu.mode_request) { in tb_switch_tmu_off()
641 tb_switch_tmu_rate_write(tb_switch_parent(sw), rate); in tb_switch_tmu_off()
651 tb_switch_tmu_rate_write(sw, rate); in tb_switch_tmu_off()
653 tb_switch_set_tmu_mode_params(sw, sw->tmu.mode); in tb_switch_tmu_off()
662 static int tb_switch_tmu_enable_bidirectional(struct tb_switch *sw) in tb_switch_tmu_enable_bidirectional() argument
667 up = tb_upstream_port(sw); in tb_switch_tmu_enable_bidirectional()
668 down = tb_switch_downstream_port(sw); in tb_switch_tmu_enable_bidirectional()
678 ret = tb_switch_tmu_rate_write(sw, tmu_rates[TB_SWITCH_TMU_MODE_HIFI_BI]); in tb_switch_tmu_enable_bidirectional()
693 tb_switch_tmu_off(sw); in tb_switch_tmu_enable_bidirectional()
698 static int tb_switch_tmu_disable_objections(struct tb_switch *sw) in tb_switch_tmu_disable_objections() argument
700 struct tb_port *up = tb_upstream_port(sw); in tb_switch_tmu_disable_objections()
704 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, in tb_switch_tmu_disable_objections()
705 sw->cap_vsec_tmu + TB_TIME_VSEC_3_CS_9, 1); in tb_switch_tmu_disable_objections()
711 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, in tb_switch_tmu_disable_objections()
712 sw->cap_vsec_tmu + TB_TIME_VSEC_3_CS_9, 1); in tb_switch_tmu_disable_objections()
726 static int tb_switch_tmu_enable_unidirectional(struct tb_switch *sw) in tb_switch_tmu_enable_unidirectional() argument
731 up = tb_upstream_port(sw); in tb_switch_tmu_enable_unidirectional()
732 down = tb_switch_downstream_port(sw); in tb_switch_tmu_enable_unidirectional()
733 ret = tb_switch_tmu_rate_write(tb_switch_parent(sw), in tb_switch_tmu_enable_unidirectional()
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()
761 tb_switch_tmu_off(sw); in tb_switch_tmu_enable_unidirectional()
769 static int tb_switch_tmu_enable_enhanced(struct tb_switch *sw) in tb_switch_tmu_enable_enhanced() argument
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()
780 up = tb_upstream_port(sw); in tb_switch_tmu_enable_enhanced()
781 down = tb_switch_downstream_port(sw); 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()
810 tb_switch_tmu_off(sw); in tb_switch_tmu_enable_enhanced()
814 static void tb_switch_tmu_change_mode_prev(struct tb_switch *sw) in tb_switch_tmu_change_mode_prev() argument
816 unsigned int rate = tmu_rates[sw->tmu.mode]; in tb_switch_tmu_change_mode_prev()
819 down = tb_switch_downstream_port(sw); in tb_switch_tmu_change_mode_prev()
820 up = tb_upstream_port(sw); in tb_switch_tmu_change_mode_prev()
827 switch (sw->tmu.mode) { in tb_switch_tmu_change_mode_prev()
831 tb_switch_tmu_rate_write(tb_switch_parent(sw), rate); in tb_switch_tmu_change_mode_prev()
836 tb_switch_tmu_rate_write(sw, rate); 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()
860 static int tb_switch_tmu_change_mode(struct tb_switch *sw) in tb_switch_tmu_change_mode() argument
862 unsigned int rate = tmu_rates[sw->tmu.mode_request]; in tb_switch_tmu_change_mode()
866 up = tb_upstream_port(sw); in tb_switch_tmu_change_mode()
867 down = tb_switch_downstream_port(sw); in tb_switch_tmu_change_mode()
870 switch (sw->tmu.mode_request) { in tb_switch_tmu_change_mode()
876 ret = tb_switch_tmu_rate_write(tb_switch_parent(sw), rate); in tb_switch_tmu_change_mode()
885 ret = tb_switch_tmu_rate_write(sw, rate); 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()
900 switch (sw->tmu.mode_request) { in tb_switch_tmu_change_mode()
930 tb_switch_tmu_change_mode_prev(sw); in tb_switch_tmu_change_mode()
942 int tb_switch_tmu_enable(struct tb_switch *sw) in tb_switch_tmu_enable() argument
946 if (tb_switch_tmu_is_enabled(sw)) in tb_switch_tmu_enable()
949 if (tb_switch_is_titan_ridge(sw) && in tb_switch_tmu_enable()
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()
952 ret = tb_switch_tmu_disable_objections(sw); in tb_switch_tmu_enable()
957 ret = tb_switch_tmu_set_time_disruption(sw, true); in tb_switch_tmu_enable()
961 if (tb_route(sw)) { 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()
971 ret = tb_switch_tmu_enable_unidirectional(sw); in tb_switch_tmu_enable()
975 ret = tb_switch_tmu_enable_bidirectional(sw); in tb_switch_tmu_enable()
978 ret = tb_switch_tmu_enable_enhanced(sw); 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()
987 ret = tb_switch_tmu_change_mode(sw); 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()
1009 return tb_switch_tmu_set_time_disruption(sw, false); in tb_switch_tmu_enable()
1024 int tb_switch_tmu_configure(struct tb_switch *sw, enum tb_switch_tmu_mode mode) in tb_switch_tmu_configure() argument
1032 if (!sw->tmu.has_ucap) in tb_switch_tmu_configure()
1040 const struct tb_switch *parent_sw = tb_switch_parent(sw); in tb_switch_tmu_configure()
1044 if (!tb_switch_tmu_enhanced_is_supported(sw)) in tb_switch_tmu_configure()
1051 tb_sw_warn(sw, "TMU: unsupported mode %u\n", mode); 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()