Lines Matching refs:sw

14 static const char *tb_switch_tmu_mode_name(const struct tb_switch *sw)
16 bool root_switch = !tb_route(sw);
18 switch (sw->tmu.rate) {
26 if (sw->tmu.unidirectional)
40 static bool tb_switch_tmu_ucap_supported(struct tb_switch *sw)
45 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH,
46 sw->tmu.cap + TMU_RTR_CS_0, 1);
53 static int tb_switch_tmu_rate_read(struct tb_switch *sw)
58 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH,
59 sw->tmu.cap + TMU_RTR_CS_3, 1);
67 static int tb_switch_tmu_rate_write(struct tb_switch *sw, int rate)
72 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH,
73 sw->tmu.cap + TMU_RTR_CS_3, 1);
80 return tb_sw_write(sw, &val, TB_CFG_SWITCH,
81 sw->tmu.cap + TMU_RTR_CS_3, 1);
106 if (!port->sw->tmu.has_ucap)
131 static int tb_switch_tmu_set_time_disruption(struct tb_switch *sw, bool set)
136 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH,
137 sw->tmu.cap + TMU_RTR_CS_0, 1);
146 return tb_sw_write(sw, &val, TB_CFG_SWITCH,
147 sw->tmu.cap + TMU_RTR_CS_0, 1);
152 * @sw: Switch to initialized
158 int tb_switch_tmu_init(struct tb_switch *sw)
163 if (tb_switch_is_icm(sw))
166 ret = tb_switch_find_cap(sw, TB_SWITCH_CAP_TMU);
168 sw->tmu.cap = ret;
170 tb_switch_for_each_port(sw, port) {
178 ret = tb_switch_tmu_rate_read(sw);
182 sw->tmu.rate = ret;
184 sw->tmu.has_ucap = tb_switch_tmu_ucap_supported(sw);
185 if (sw->tmu.has_ucap) {
186 tb_sw_dbg(sw, "TMU: supports uni-directional mode\n");
188 if (tb_route(sw)) {
189 struct tb_port *up = tb_upstream_port(sw);
191 sw->tmu.unidirectional =
195 sw->tmu.unidirectional = false;
198 tb_sw_dbg(sw, "TMU: current mode: %s\n", tb_switch_tmu_mode_name(sw));
204 * @sw: Switch whose time to update
208 int tb_switch_tmu_post_time(struct tb_switch *sw)
211 struct tb_switch *root_switch = sw->tb->root_switch;
216 if (!tb_route(sw))
219 if (!tb_switch_is_usb4(sw))
244 ret = tb_switch_tmu_set_time_disruption(sw, true);
248 post_local_time_offset = sw->tmu.cap + TMU_RTR_CS_22;
249 post_time_offset = sw->tmu.cap + TMU_RTR_CS_24;
255 ret = tb_sw_write(sw, &local_time, TB_CFG_SWITCH,
268 ret = tb_sw_write(sw, &post_time, TB_CFG_SWITCH, post_time_offset, 2);
274 ret = tb_sw_read(sw, &post_time, TB_CFG_SWITCH,
285 tb_sw_dbg(sw, "TMU: updated local time to %#llx\n", local_time);
288 tb_switch_tmu_set_time_disruption(sw, false);
294 * @sw: Switch whose TMU to disable
296 * Turns off TMU of @sw if it is enabled. If not enabled does nothing.
298 int tb_switch_tmu_disable(struct tb_switch *sw)
302 if (!tb_switch_is_usb4(sw))
306 if (sw->tmu.rate == TB_SWITCH_TMU_RATE_OFF)
309 if (sw->tmu.unidirectional) {
310 struct tb_switch *parent = tb_switch_parent(sw);
313 up = tb_upstream_port(sw);
314 down = tb_port_at(tb_route(sw), parent);
323 tb_switch_tmu_rate_write(sw, TB_SWITCH_TMU_RATE_OFF);
325 sw->tmu.unidirectional = false;
326 sw->tmu.rate = TB_SWITCH_TMU_RATE_OFF;
328 tb_sw_dbg(sw, "TMU: disabled\n");
334 * @sw: Switch whose TMU to enable
339 int tb_switch_tmu_enable(struct tb_switch *sw)
343 if (!tb_switch_is_usb4(sw))
346 if (tb_switch_tmu_is_enabled(sw))
349 ret = tb_switch_tmu_set_time_disruption(sw, true);
354 if (tb_route(sw) && sw->tmu.unidirectional) {
355 struct tb_switch *parent = tb_switch_parent(sw);
358 up = tb_upstream_port(sw);
359 down = tb_port_at(tb_route(sw), parent);
365 ret = tb_switch_tmu_rate_write(sw, TB_SWITCH_TMU_RATE_HIFI);
373 ret = tb_switch_tmu_rate_write(sw, TB_SWITCH_TMU_RATE_HIFI);
378 sw->tmu.unidirectional = false;
379 sw->tmu.rate = TB_SWITCH_TMU_RATE_HIFI;
380 tb_sw_dbg(sw, "TMU: mode set to: %s\n", tb_switch_tmu_mode_name(sw));
382 return tb_switch_tmu_set_time_disruption(sw, false);