Lines Matching full:sw

72 static void tb_add_dp_resources(struct tb_switch *sw)  in tb_add_dp_resources()  argument
74 struct tb_cm *tcm = tb_priv(sw->tb); in tb_add_dp_resources()
77 tb_switch_for_each_port(sw, port) { in tb_add_dp_resources()
81 if (!tb_switch_query_dp_resource(sw, port)) in tb_add_dp_resources()
89 static void tb_remove_dp_resources(struct tb_switch *sw) in tb_remove_dp_resources() argument
91 struct tb_cm *tcm = tb_priv(sw->tb); in tb_remove_dp_resources()
95 tb_switch_for_each_port(sw, port) { in tb_remove_dp_resources()
97 tb_remove_dp_resources(port->remote->sw); in tb_remove_dp_resources()
101 if (port->sw == sw) { in tb_remove_dp_resources()
108 static void tb_discover_tunnels(struct tb_switch *sw) in tb_discover_tunnels() argument
110 struct tb *tb = sw->tb; in tb_discover_tunnels()
114 tb_switch_for_each_port(sw, port) { in tb_discover_tunnels()
138 struct tb_switch *parent = tunnel->dst_port->sw; in tb_discover_tunnels()
140 while (parent != tunnel->src_port->sw) { in tb_discover_tunnels()
146 pm_runtime_get_sync(&tunnel->src_port->sw->dev); in tb_discover_tunnels()
147 pm_runtime_get_sync(&tunnel->dst_port->sw->dev); in tb_discover_tunnels()
153 tb_switch_for_each_port(sw, port) { in tb_discover_tunnels()
155 tb_discover_tunnels(port->remote->sw); in tb_discover_tunnels()
167 if (tb_switch_is_usb4(port->sw)) in tb_port_configure_xdomain()
174 if (tb_switch_is_usb4(port->sw)) in tb_port_unconfigure_xdomain()
184 struct tb_switch *sw = port->sw; in tb_scan_xdomain() local
185 struct tb *tb = sw->tb; in tb_scan_xdomain()
199 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid, in tb_scan_xdomain()
202 tb_port_at(route, sw)->xdomain = xd; in tb_scan_xdomain()
208 static int tb_enable_tmu(struct tb_switch *sw) in tb_enable_tmu() argument
213 if (tb_switch_tmu_is_enabled(sw)) in tb_enable_tmu()
216 ret = tb_switch_tmu_disable(sw); in tb_enable_tmu()
220 ret = tb_switch_tmu_post_time(sw); in tb_enable_tmu()
224 return tb_switch_tmu_enable(sw); in tb_enable_tmu()
228 * tb_find_unused_port() - return the first inactive port on @sw
229 * @sw: Switch to find the port on
232 static struct tb_port *tb_find_unused_port(struct tb_switch *sw, in tb_find_unused_port() argument
237 tb_switch_for_each_port(sw, port) { in tb_find_unused_port()
251 static struct tb_port *tb_find_usb3_down(struct tb_switch *sw, in tb_find_usb3_down() argument
256 down = usb4_switch_map_usb3_down(sw, port); in tb_find_usb3_down()
285 struct tb_switch *sw; in tb_find_first_usb3_tunnel() local
288 if (dst_port->sw->config.depth > src_port->sw->config.depth) in tb_find_first_usb3_tunnel()
289 sw = dst_port->sw; in tb_find_first_usb3_tunnel()
291 sw = src_port->sw; in tb_find_first_usb3_tunnel()
294 if (sw == tb->root_switch) in tb_find_first_usb3_tunnel()
298 port = tb_port_at(tb_route(sw), tb->root_switch); in tb_find_first_usb3_tunnel()
338 link_speed = port->sw->link_speed; in tb_available_bandwidth()
439 static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw) in tb_tunnel_usb3() argument
441 struct tb_switch *parent = tb_switch_parent(sw); in tb_tunnel_usb3()
452 up = tb_switch_find_port(sw, TB_TYPE_USB3_UP); in tb_tunnel_usb3()
456 if (!sw->link_usb4) in tb_tunnel_usb3()
463 port = tb_port_at(tb_route(sw), parent); in tb_tunnel_usb3()
522 static int tb_create_usb3_tunnels(struct tb_switch *sw) in tb_create_usb3_tunnels() argument
530 if (tb_route(sw)) { in tb_create_usb3_tunnels()
531 ret = tb_tunnel_usb3(sw->tb, sw); in tb_create_usb3_tunnels()
536 tb_switch_for_each_port(sw, port) { in tb_create_usb3_tunnels()
539 ret = tb_create_usb3_tunnels(port->remote->sw); in tb_create_usb3_tunnels()
552 static void tb_scan_switch(struct tb_switch *sw) in tb_scan_switch() argument
556 pm_runtime_get_sync(&sw->dev); in tb_scan_switch()
558 tb_switch_for_each_port(sw, port) in tb_scan_switch()
561 pm_runtime_mark_last_busy(&sw->dev); in tb_scan_switch()
562 pm_runtime_put_autosuspend(&sw->dev); in tb_scan_switch()
570 struct tb_cm *tcm = tb_priv(port->sw->tb); in tb_scan_port()
572 struct tb_switch *sw; in tb_scan_port() local
580 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port, in tb_scan_port()
601 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev, in tb_scan_port()
603 if (IS_ERR(sw)) { in tb_scan_port()
609 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL) in tb_scan_port()
614 if (tb_switch_configure(sw)) { in tb_scan_port()
615 tb_switch_put(sw); in tb_scan_port()
635 dev_set_uevent_suppress(&sw->dev, true); in tb_scan_port()
641 sw->rpm = sw->generation > 1; in tb_scan_port()
643 if (tb_switch_add(sw)) { in tb_scan_port()
644 tb_switch_put(sw); in tb_scan_port()
649 upstream_port = tb_upstream_port(sw); in tb_scan_port()
658 tb_switch_lane_bonding_enable(sw); in tb_scan_port()
660 tb_switch_configure_link(sw); in tb_scan_port()
662 if (tb_enable_tmu(sw)) in tb_scan_port()
663 tb_sw_warn(sw, "failed to enable TMU\n"); in tb_scan_port()
674 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw)) in tb_scan_port()
675 tb_sw_warn(sw, "USB3 tunnel creation failed\n"); in tb_scan_port()
677 tb_add_dp_resources(sw); in tb_scan_port()
678 tb_scan_switch(sw); in tb_scan_port()
702 tb_switch_dealloc_dp_resource(src_port->sw, src_port); in tb_deactivate_and_free_tunnel()
704 pm_runtime_mark_last_busy(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
705 pm_runtime_put_autosuspend(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
706 pm_runtime_mark_last_busy(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
707 pm_runtime_put_autosuspend(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
743 static void tb_free_unplugged_children(struct tb_switch *sw) in tb_free_unplugged_children() argument
747 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_children()
751 if (port->remote->sw->is_unplugged) { in tb_free_unplugged_children()
753 tb_remove_dp_resources(port->remote->sw); in tb_free_unplugged_children()
754 tb_switch_unconfigure_link(port->remote->sw); in tb_free_unplugged_children()
755 tb_switch_lane_bonding_disable(port->remote->sw); in tb_free_unplugged_children()
756 tb_switch_remove(port->remote->sw); in tb_free_unplugged_children()
761 tb_free_unplugged_children(port->remote->sw); in tb_free_unplugged_children()
766 static struct tb_port *tb_find_pcie_down(struct tb_switch *sw, in tb_find_pcie_down() argument
775 if (tb_switch_is_usb4(sw)) { in tb_find_pcie_down()
776 down = usb4_switch_map_pcie_down(sw, port); in tb_find_pcie_down()
777 } else if (!tb_route(sw)) { in tb_find_pcie_down()
785 if (tb_switch_is_cactus_ridge(sw) || in tb_find_pcie_down()
786 tb_switch_is_alpine_ridge(sw)) in tb_find_pcie_down()
788 else if (tb_switch_is_falcon_ridge(sw)) in tb_find_pcie_down()
790 else if (tb_switch_is_titan_ridge(sw)) in tb_find_pcie_down()
796 if (WARN_ON(index > sw->config.max_port_number)) in tb_find_pcie_down()
799 down = &sw->ports[index]; in tb_find_pcie_down()
812 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN); in tb_find_pcie_down()
820 host_port = tb_route(in->sw) ? in tb_find_dp_out()
821 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL; in tb_find_dp_out()
838 if (host_port && tb_route(port->sw)) { in tb_find_dp_out()
841 p = tb_port_at(tb_route(port->sw), tb->root_switch); in tb_find_dp_out()
907 pm_runtime_get_sync(&in->sw->dev); in tb_tunnel_dp()
908 pm_runtime_get_sync(&out->sw->dev); in tb_tunnel_dp()
910 if (tb_switch_alloc_dp_resource(in->sw, in)) { in tb_tunnel_dp()
950 tb_switch_dealloc_dp_resource(in->sw, in); in tb_tunnel_dp()
952 pm_runtime_mark_last_busy(&out->sw->dev); in tb_tunnel_dp()
953 pm_runtime_put_autosuspend(&out->sw->dev); in tb_tunnel_dp()
954 pm_runtime_mark_last_busy(&in->sw->dev); in tb_tunnel_dp()
955 pm_runtime_put_autosuspend(&in->sw->dev); in tb_tunnel_dp()
1028 static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) in tb_disconnect_pci() argument
1033 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); in tb_disconnect_pci()
1047 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) in tb_tunnel_pci() argument
1054 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); in tb_tunnel_pci()
1062 parent_sw = tb_to_switch(sw->dev.parent); in tb_tunnel_pci()
1063 port = tb_port_at(tb_route(sw), parent_sw); in tb_tunnel_pci()
1090 struct tb_switch *sw; in tb_approve_xdomain_paths() local
1092 sw = tb_to_switch(xd->dev.parent); in tb_approve_xdomain_paths()
1093 dst_port = tb_port_at(xd->route, sw); in tb_approve_xdomain_paths()
1124 struct tb_switch *sw; in __tb_disconnect_xdomain_paths() local
1126 sw = tb_to_switch(xd->dev.parent); in __tb_disconnect_xdomain_paths()
1127 dst_port = tb_port_at(xd->route, sw); in __tb_disconnect_xdomain_paths()
1168 struct tb_switch *sw; in tb_handle_hotplug() local
1178 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_hotplug()
1179 if (!sw) { in tb_handle_hotplug()
1185 if (ev->port > sw->config.max_port_number) { in tb_handle_hotplug()
1191 port = &sw->ports[ev->port]; in tb_handle_hotplug()
1198 pm_runtime_get_sync(&sw->dev); in tb_handle_hotplug()
1205 tb_sw_set_unplugged(port->remote->sw); in tb_handle_hotplug()
1207 tb_remove_dp_resources(port->remote->sw); in tb_handle_hotplug()
1208 tb_switch_tmu_disable(port->remote->sw); in tb_handle_hotplug()
1209 tb_switch_unconfigure_link(port->remote->sw); in tb_handle_hotplug()
1210 tb_switch_lane_bonding_disable(port->remote->sw); in tb_handle_hotplug()
1211 tb_switch_remove(port->remote->sw); in tb_handle_hotplug()
1253 pm_runtime_mark_last_busy(&sw->dev); in tb_handle_hotplug()
1254 pm_runtime_put_autosuspend(&sw->dev); in tb_handle_hotplug()
1257 tb_switch_put(sw); in tb_handle_hotplug()
1318 struct tb_switch *sw = tb_to_switch(dev); in tb_scan_finalize_switch() local
1325 if (sw->boot) in tb_scan_finalize_switch()
1326 sw->authorized = 1; in tb_scan_finalize_switch()
1402 static void tb_restore_children(struct tb_switch *sw) in tb_restore_children() argument
1407 if (sw->is_unplugged) in tb_restore_children()
1410 if (tb_enable_tmu(sw)) in tb_restore_children()
1411 tb_sw_warn(sw, "failed to restore TMU configuration\n"); in tb_restore_children()
1413 tb_switch_for_each_port(sw, port) { in tb_restore_children()
1418 tb_switch_lane_bonding_enable(port->remote->sw); in tb_restore_children()
1419 tb_switch_configure_link(port->remote->sw); in tb_restore_children()
1421 tb_restore_children(port->remote->sw); in tb_restore_children()
1459 static int tb_free_unplugged_xdomains(struct tb_switch *sw) in tb_free_unplugged_xdomains() argument
1464 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_xdomains()
1474 ret += tb_free_unplugged_xdomains(port->remote->sw); in tb_free_unplugged_xdomains()