Lines Matching full:sw
134 if (tunnel->src_port->sw == in->sw && in tb_attach_bandwidth_group()
135 tunnel->dst_port->sw == out->sw) { in tb_attach_bandwidth_group()
204 static void tb_add_dp_resources(struct tb_switch *sw) in tb_add_dp_resources() argument
206 struct tb_cm *tcm = tb_priv(sw->tb); in tb_add_dp_resources()
209 tb_switch_for_each_port(sw, port) { in tb_add_dp_resources()
213 if (!tb_switch_query_dp_resource(sw, port)) in tb_add_dp_resources()
222 if (tb_route(sw)) in tb_add_dp_resources()
231 static void tb_remove_dp_resources(struct tb_switch *sw) in tb_remove_dp_resources() argument
233 struct tb_cm *tcm = tb_priv(sw->tb); in tb_remove_dp_resources()
237 tb_switch_for_each_port(sw, port) { in tb_remove_dp_resources()
239 tb_remove_dp_resources(port->remote->sw); in tb_remove_dp_resources()
243 if (port->sw == sw) { in tb_remove_dp_resources()
277 static int tb_enable_clx(struct tb_switch *sw) in tb_enable_clx() argument
279 struct tb_cm *tcm = tb_priv(sw->tb); in tb_enable_clx()
291 while (sw && tb_switch_depth(sw) > 1) in tb_enable_clx()
292 sw = tb_switch_parent(sw); in tb_enable_clx()
294 if (!sw) in tb_enable_clx()
297 if (tb_switch_depth(sw) != 1) in tb_enable_clx()
306 if (tb_tunnel_port_on_path(tunnel, tb_upstream_port(sw))) in tb_enable_clx()
315 ret = tb_switch_clx_enable(sw, clx | TB_CL2); in tb_enable_clx()
317 ret = tb_switch_clx_enable(sw, clx); in tb_enable_clx()
323 * @sw: Router to start
325 * Disables CL states from @sw up to the host router. Returns true if
330 static bool tb_disable_clx(struct tb_switch *sw) in tb_disable_clx() argument
337 ret = tb_switch_clx_disable(sw); in tb_disable_clx()
341 tb_sw_warn(sw, "failed to disable CL states\n"); in tb_disable_clx()
343 sw = tb_switch_parent(sw); in tb_disable_clx()
344 } while (sw); in tb_disable_clx()
351 struct tb_switch *sw; in tb_increase_switch_tmu_accuracy() local
353 sw = tb_to_switch(dev); in tb_increase_switch_tmu_accuracy()
354 if (!sw) in tb_increase_switch_tmu_accuracy()
357 if (tb_switch_tmu_is_configured(sw, TB_SWITCH_TMU_MODE_LOWRES)) { in tb_increase_switch_tmu_accuracy()
361 if (tb_switch_clx_is_enabled(sw, TB_CL1)) in tb_increase_switch_tmu_accuracy()
366 ret = tb_switch_tmu_configure(sw, mode); in tb_increase_switch_tmu_accuracy()
370 return tb_switch_tmu_enable(sw); in tb_increase_switch_tmu_accuracy()
378 struct tb_switch *sw; in tb_increase_tmu_accuracy() local
392 sw = tunnel->tb->root_switch; in tb_increase_tmu_accuracy()
393 device_for_each_child(&sw->dev, NULL, tb_increase_switch_tmu_accuracy); in tb_increase_tmu_accuracy()
396 static int tb_enable_tmu(struct tb_switch *sw) in tb_enable_tmu() argument
407 ret = tb_switch_tmu_configure(sw, in tb_enable_tmu()
410 if (tb_switch_clx_is_enabled(sw, TB_CL1)) in tb_enable_tmu()
411 ret = tb_switch_tmu_configure(sw, in tb_enable_tmu()
414 ret = tb_switch_tmu_configure(sw, in tb_enable_tmu()
421 if (tb_switch_tmu_is_enabled(sw)) in tb_enable_tmu()
424 ret = tb_switch_tmu_disable(sw); in tb_enable_tmu()
428 ret = tb_switch_tmu_post_time(sw); in tb_enable_tmu()
432 return tb_switch_tmu_enable(sw); in tb_enable_tmu()
435 static void tb_switch_discover_tunnels(struct tb_switch *sw, in tb_switch_discover_tunnels() argument
439 struct tb *tb = sw->tb; in tb_switch_discover_tunnels()
442 tb_switch_for_each_port(sw, port) { in tb_switch_discover_tunnels()
467 tb_switch_for_each_port(sw, port) { in tb_switch_discover_tunnels()
469 tb_switch_discover_tunnels(port->remote->sw, list, in tb_switch_discover_tunnels()
484 struct tb_switch *parent = tunnel->dst_port->sw; in tb_discover_tunnels()
486 while (parent != tunnel->src_port->sw) { in tb_discover_tunnels()
495 pm_runtime_get_sync(&in->sw->dev); in tb_discover_tunnels()
496 pm_runtime_get_sync(&out->sw->dev); in tb_discover_tunnels()
505 if (tb_switch_is_usb4(port->sw)) in tb_port_configure_xdomain()
512 if (tb_switch_is_usb4(port->sw)) in tb_port_unconfigure_xdomain()
520 struct tb_switch *sw = port->sw; in tb_scan_xdomain() local
521 struct tb *tb = sw->tb; in tb_scan_xdomain()
535 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid, in tb_scan_xdomain()
538 tb_port_at(route, sw)->xdomain = xd; in tb_scan_xdomain()
545 * tb_find_unused_port() - return the first inactive port on @sw
546 * @sw: Switch to find the port on
549 static struct tb_port *tb_find_unused_port(struct tb_switch *sw, in tb_find_unused_port() argument
554 tb_switch_for_each_port(sw, port) { in tb_find_unused_port()
568 static struct tb_port *tb_find_usb3_down(struct tb_switch *sw, in tb_find_usb3_down() argument
573 down = usb4_switch_map_usb3_down(sw, port); in tb_find_usb3_down()
602 struct tb_switch *sw; in tb_find_first_usb3_tunnel() local
606 sw = dst_port->sw; in tb_find_first_usb3_tunnel()
608 sw = src_port->sw; in tb_find_first_usb3_tunnel()
611 if (sw == tb->root_switch) in tb_find_first_usb3_tunnel()
615 port = tb_port_at(tb_route(sw), tb->root_switch); in tb_find_first_usb3_tunnel()
780 link_speed = port->sw->link_speed; in tb_maximum_bandwidth()
782 * sw->link_width is from upstream perspective so we use in tb_maximum_bandwidth()
785 if (port->sw->link_width == TB_LINK_WIDTH_ASYM_TX) { in tb_maximum_bandwidth()
788 } else if (port->sw->link_width == TB_LINK_WIDTH_ASYM_RX) { in tb_maximum_bandwidth()
806 up_bw = link_speed * port->sw->link_width * 1000; in tb_maximum_bandwidth()
961 static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw) in tb_tunnel_usb3() argument
963 struct tb_switch *parent = tb_switch_parent(sw); in tb_tunnel_usb3()
974 up = tb_switch_find_port(sw, TB_TYPE_USB3_UP); in tb_tunnel_usb3()
978 if (!sw->link_usb4) in tb_tunnel_usb3()
985 port = tb_switch_downstream_port(sw); in tb_tunnel_usb3()
1044 static int tb_create_usb3_tunnels(struct tb_switch *sw) in tb_create_usb3_tunnels() argument
1052 if (tb_route(sw)) { in tb_create_usb3_tunnels()
1053 ret = tb_tunnel_usb3(sw->tb, sw); in tb_create_usb3_tunnels()
1058 tb_switch_for_each_port(sw, port) { in tb_create_usb3_tunnels()
1061 ret = tb_create_usb3_tunnels(port->remote->sw); in tb_create_usb3_tunnels()
1089 struct tb_switch *sw; in tb_configure_asym() local
1099 sw = dst_port->sw; in tb_configure_asym()
1101 sw = src_port->sw; in tb_configure_asym()
1104 struct tb_port *down = tb_switch_downstream_port(up->sw); in tb_configure_asym()
1142 if (up->sw->link_width == width_up) in tb_configure_asym()
1155 clx = tb_disable_clx(sw); in tb_configure_asym()
1159 tb_sw_dbg(up->sw, "configuring asymmetric link\n"); in tb_configure_asym()
1165 ret = tb_switch_set_link_width(up->sw, width_up); in tb_configure_asym()
1167 tb_sw_warn(up->sw, "failed to set link width\n"); in tb_configure_asym()
1174 tb_enable_clx(sw); in tb_configure_asym()
1197 struct tb_switch *sw; in tb_configure_sym() local
1207 sw = dst_port->sw; in tb_configure_sym()
1209 sw = src_port->sw; in tb_configure_sym()
1215 if (up->sw->link_width <= TB_LINK_WIDTH_DUAL) in tb_configure_sym()
1218 if (up->sw->is_unplugged) in tb_configure_sym()
1240 if (up->sw->link_width == TB_LINK_WIDTH_DUAL) in tb_configure_sym()
1251 up->sw->preferred_link_width > TB_LINK_WIDTH_DUAL) { in tb_configure_sym()
1252 tb_sw_dbg(up->sw, "keeping preferred asymmetric link\n"); in tb_configure_sym()
1258 clx = tb_disable_clx(sw); in tb_configure_sym()
1262 tb_sw_dbg(up->sw, "configuring symmetric link\n"); in tb_configure_sym()
1264 ret = tb_switch_set_link_width(up->sw, TB_LINK_WIDTH_DUAL); in tb_configure_sym()
1266 tb_sw_warn(up->sw, "failed to set link width\n"); in tb_configure_sym()
1273 tb_enable_clx(sw); in tb_configure_sym()
1279 struct tb_switch *sw) in tb_configure_link() argument
1281 struct tb *tb = sw->tb; in tb_configure_link()
1295 if (sw->link_width < TB_LINK_WIDTH_DUAL) in tb_configure_link()
1296 tb_switch_set_link_width(sw, TB_LINK_WIDTH_DUAL); in tb_configure_link()
1303 if (tb_switch_depth(sw) > 1 && in tb_configure_link()
1305 up->sw->link_width == TB_LINK_WIDTH_DUAL) { in tb_configure_link()
1308 host_port = tb_port_at(tb_route(sw), tb->root_switch); in tb_configure_link()
1313 tb_switch_configure_link(sw); in tb_configure_link()
1321 static void tb_scan_switch(struct tb_switch *sw) in tb_scan_switch() argument
1325 pm_runtime_get_sync(&sw->dev); in tb_scan_switch()
1327 tb_switch_for_each_port(sw, port) in tb_scan_switch()
1330 pm_runtime_mark_last_busy(&sw->dev); in tb_scan_switch()
1331 pm_runtime_put_autosuspend(&sw->dev); in tb_scan_switch()
1339 struct tb_cm *tcm = tb_priv(port->sw->tb); in tb_scan_port()
1342 struct tb_switch *sw; in tb_scan_port() local
1350 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port, in tb_scan_port()
1375 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev, in tb_scan_port()
1377 if (IS_ERR(sw)) { in tb_scan_port()
1383 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL) in tb_scan_port()
1388 if (tb_switch_configure(sw)) { in tb_scan_port()
1389 tb_switch_put(sw); in tb_scan_port()
1409 dev_set_uevent_suppress(&sw->dev, true); in tb_scan_port()
1417 sw->rpm = sw->generation > 1; in tb_scan_port()
1419 if (tb_switch_add(sw)) { in tb_scan_port()
1420 tb_switch_put(sw); in tb_scan_port()
1424 upstream_port = tb_upstream_port(sw); in tb_scan_port()
1425 tb_configure_link(port, upstream_port, sw); in tb_scan_port()
1432 tb_sw_dbg(sw, "discovery, not touching CL states\n"); in tb_scan_port()
1433 else if (tb_enable_clx(sw)) in tb_scan_port()
1434 tb_sw_warn(sw, "failed to enable CL states\n"); in tb_scan_port()
1436 if (tb_enable_tmu(sw)) in tb_scan_port()
1437 tb_sw_warn(sw, "failed to enable TMU\n"); in tb_scan_port()
1443 tb_switch_configuration_valid(sw); in tb_scan_port()
1454 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw)) in tb_scan_port()
1455 tb_sw_warn(sw, "USB3 tunnel creation failed\n"); in tb_scan_port()
1457 tb_add_dp_resources(sw); in tb_scan_port()
1458 tb_scan_switch(sw); in tb_scan_port()
1489 tb_switch_dealloc_dp_resource(src_port->sw, src_port); in tb_deactivate_and_free_tunnel()
1496 pm_runtime_mark_last_busy(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
1497 pm_runtime_put_autosuspend(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
1498 pm_runtime_mark_last_busy(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
1499 pm_runtime_put_autosuspend(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
1535 static void tb_free_unplugged_children(struct tb_switch *sw) in tb_free_unplugged_children() argument
1539 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_children()
1543 if (port->remote->sw->is_unplugged) { in tb_free_unplugged_children()
1545 tb_remove_dp_resources(port->remote->sw); in tb_free_unplugged_children()
1546 tb_switch_unconfigure_link(port->remote->sw); in tb_free_unplugged_children()
1547 tb_switch_set_link_width(port->remote->sw, in tb_free_unplugged_children()
1549 tb_switch_remove(port->remote->sw); in tb_free_unplugged_children()
1554 tb_free_unplugged_children(port->remote->sw); in tb_free_unplugged_children()
1559 static struct tb_port *tb_find_pcie_down(struct tb_switch *sw, in tb_find_pcie_down() argument
1568 if (tb_switch_is_usb4(sw)) { in tb_find_pcie_down()
1569 down = usb4_switch_map_pcie_down(sw, port); in tb_find_pcie_down()
1570 } else if (!tb_route(sw)) { in tb_find_pcie_down()
1578 if (tb_switch_is_cactus_ridge(sw) || in tb_find_pcie_down()
1579 tb_switch_is_alpine_ridge(sw)) in tb_find_pcie_down()
1581 else if (tb_switch_is_falcon_ridge(sw)) in tb_find_pcie_down()
1583 else if (tb_switch_is_titan_ridge(sw)) in tb_find_pcie_down()
1589 if (WARN_ON(index > sw->config.max_port_number)) in tb_find_pcie_down()
1592 down = &sw->ports[index]; in tb_find_pcie_down()
1605 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN); in tb_find_pcie_down()
1708 host_port = tb_route(in->sw) ? in tb_find_dp_out()
1709 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL; in tb_find_dp_out()
1726 if (host_port && tb_route(port->sw)) { in tb_find_dp_out()
1729 p = tb_port_at(tb_route(port->sw), tb->root_switch); in tb_find_dp_out()
1804 pm_runtime_get_sync(&in->sw->dev); in tb_tunnel_one_dp()
1805 pm_runtime_get_sync(&out->sw->dev); in tb_tunnel_one_dp()
1807 if (tb_switch_alloc_dp_resource(in->sw, in)) { in tb_tunnel_one_dp()
1869 tb_switch_dealloc_dp_resource(in->sw, in); in tb_tunnel_one_dp()
1871 pm_runtime_mark_last_busy(&out->sw->dev); in tb_tunnel_one_dp()
1872 pm_runtime_put_autosuspend(&out->sw->dev); in tb_tunnel_one_dp()
1873 pm_runtime_mark_last_busy(&in->sw->dev); in tb_tunnel_one_dp()
1874 pm_runtime_put_autosuspend(&in->sw->dev); in tb_tunnel_one_dp()
1961 static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) in tb_disconnect_pci() argument
1966 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); in tb_disconnect_pci()
1974 tb_switch_xhci_disconnect(sw); in tb_disconnect_pci()
1982 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) in tb_tunnel_pci() argument
1988 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); in tb_tunnel_pci()
1996 port = tb_switch_downstream_port(sw); in tb_tunnel_pci()
1997 down = tb_find_pcie_down(tb_switch_parent(sw), port); in tb_tunnel_pci()
2016 if (tb_switch_pcie_l1_enable(sw)) in tb_tunnel_pci()
2017 tb_sw_warn(sw, "failed to enable PCIe L1 for Titan Ridge\n"); in tb_tunnel_pci()
2019 if (tb_switch_xhci_connect(sw)) in tb_tunnel_pci()
2020 tb_sw_warn(sw, "failed to connect xHCI\n"); in tb_tunnel_pci()
2033 struct tb_switch *sw; in tb_approve_xdomain_paths() local
2036 sw = tb_to_switch(xd->dev.parent); in tb_approve_xdomain_paths()
2037 dst_port = tb_port_at(xd->route, sw); in tb_approve_xdomain_paths()
2046 tb_disable_clx(sw); in tb_approve_xdomain_paths()
2069 tb_enable_clx(sw); in tb_approve_xdomain_paths()
2082 struct tb_switch *sw; in __tb_disconnect_xdomain_paths() local
2084 sw = tb_to_switch(xd->dev.parent); in __tb_disconnect_xdomain_paths()
2085 dst_port = tb_port_at(xd->route, sw); in __tb_disconnect_xdomain_paths()
2104 tb_enable_clx(sw); in __tb_disconnect_xdomain_paths()
2133 struct tb_switch *sw; in tb_handle_hotplug() local
2143 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_hotplug()
2144 if (!sw) { in tb_handle_hotplug()
2150 if (ev->port > sw->config.max_port_number) { in tb_handle_hotplug()
2156 port = &sw->ports[ev->port]; in tb_handle_hotplug()
2163 pm_runtime_get_sync(&sw->dev); in tb_handle_hotplug()
2170 tb_sw_set_unplugged(port->remote->sw); in tb_handle_hotplug()
2172 tb_remove_dp_resources(port->remote->sw); in tb_handle_hotplug()
2173 tb_switch_tmu_disable(port->remote->sw); in tb_handle_hotplug()
2174 tb_switch_unconfigure_link(port->remote->sw); in tb_handle_hotplug()
2175 tb_switch_set_link_width(port->remote->sw, in tb_handle_hotplug()
2177 tb_switch_remove(port->remote->sw); in tb_handle_hotplug()
2204 tb_sw_dbg(sw, "xHCI disconnect request\n"); in tb_handle_hotplug()
2205 tb_switch_xhci_disconnect(sw); in tb_handle_hotplug()
2212 } else if (!port->port && sw->authorized) { in tb_handle_hotplug()
2213 tb_sw_dbg(sw, "xHCI connect request\n"); in tb_handle_hotplug()
2214 tb_switch_xhci_connect(sw); in tb_handle_hotplug()
2226 pm_runtime_mark_last_busy(&sw->dev); in tb_handle_hotplug()
2227 pm_runtime_put_autosuspend(&sw->dev); in tb_handle_hotplug()
2230 tb_switch_put(sw); in tb_handle_hotplug()
2386 struct tb_switch *sw; in tb_handle_dp_bandwidth_request() local
2394 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_dp_bandwidth_request()
2395 if (!sw) { in tb_handle_dp_bandwidth_request()
2401 in = &sw->ports[ev->port]; in tb_handle_dp_bandwidth_request()
2460 tb_switch_put(sw); in tb_handle_dp_bandwidth_request()
2566 struct tb_switch *sw = tb_to_switch(dev); in tb_scan_finalize_switch() local
2573 if (sw->boot) in tb_scan_finalize_switch()
2574 sw->authorized = 1; in tb_scan_finalize_switch()
2660 static void tb_restore_children(struct tb_switch *sw) in tb_restore_children() argument
2665 if (sw->is_unplugged) in tb_restore_children()
2668 if (tb_enable_clx(sw)) in tb_restore_children()
2669 tb_sw_warn(sw, "failed to re-enable CL states\n"); in tb_restore_children()
2671 if (tb_enable_tmu(sw)) in tb_restore_children()
2672 tb_sw_warn(sw, "failed to restore TMU configuration\n"); in tb_restore_children()
2674 tb_switch_configuration_valid(sw); in tb_restore_children()
2676 tb_switch_for_each_port(sw, port) { in tb_restore_children()
2681 tb_switch_set_link_width(port->remote->sw, in tb_restore_children()
2682 port->remote->sw->link_width); in tb_restore_children()
2683 tb_switch_configure_link(port->remote->sw); in tb_restore_children()
2685 tb_restore_children(port->remote->sw); in tb_restore_children()
2748 static int tb_free_unplugged_xdomains(struct tb_switch *sw) in tb_free_unplugged_xdomains() argument
2753 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_xdomains()
2763 ret += tb_free_unplugged_xdomains(port->remote->sw); in tb_free_unplugged_xdomains()