Lines Matching full:sw
69 static void tb_add_dp_resources(struct tb_switch *sw) in tb_add_dp_resources() argument
71 struct tb_cm *tcm = tb_priv(sw->tb); in tb_add_dp_resources()
74 tb_switch_for_each_port(sw, port) { in tb_add_dp_resources()
78 if (!tb_switch_query_dp_resource(sw, port)) in tb_add_dp_resources()
86 static void tb_remove_dp_resources(struct tb_switch *sw) in tb_remove_dp_resources() argument
88 struct tb_cm *tcm = tb_priv(sw->tb); in tb_remove_dp_resources()
92 tb_switch_for_each_port(sw, port) { in tb_remove_dp_resources()
94 tb_remove_dp_resources(port->remote->sw); in tb_remove_dp_resources()
98 if (port->sw == sw) { in tb_remove_dp_resources()
105 static void tb_discover_tunnels(struct tb_switch *sw) in tb_discover_tunnels() argument
107 struct tb *tb = sw->tb; in tb_discover_tunnels()
111 tb_switch_for_each_port(sw, port) { in tb_discover_tunnels()
135 struct tb_switch *parent = tunnel->dst_port->sw; in tb_discover_tunnels()
137 while (parent != tunnel->src_port->sw) { in tb_discover_tunnels()
146 tb_switch_for_each_port(sw, port) { in tb_discover_tunnels()
148 tb_discover_tunnels(port->remote->sw); in tb_discover_tunnels()
160 if (tb_switch_is_usb4(port->sw)) in tb_port_configure_xdomain()
167 if (tb_switch_is_usb4(port->sw)) in tb_port_unconfigure_xdomain()
177 struct tb_switch *sw = port->sw; in tb_scan_xdomain() local
178 struct tb *tb = sw->tb; in tb_scan_xdomain()
189 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid, in tb_scan_xdomain()
192 tb_port_at(route, sw)->xdomain = xd; in tb_scan_xdomain()
198 static int tb_enable_tmu(struct tb_switch *sw) in tb_enable_tmu() argument
203 if (tb_switch_tmu_is_enabled(sw)) in tb_enable_tmu()
206 ret = tb_switch_tmu_disable(sw); in tb_enable_tmu()
210 ret = tb_switch_tmu_post_time(sw); in tb_enable_tmu()
214 return tb_switch_tmu_enable(sw); in tb_enable_tmu()
218 * tb_find_unused_port() - return the first inactive port on @sw
219 * @sw: Switch to find the port on
222 static struct tb_port *tb_find_unused_port(struct tb_switch *sw, in tb_find_unused_port() argument
227 tb_switch_for_each_port(sw, port) { in tb_find_unused_port()
241 static struct tb_port *tb_find_usb3_down(struct tb_switch *sw, in tb_find_usb3_down() argument
246 down = usb4_switch_map_usb3_down(sw, port); in tb_find_usb3_down()
275 struct tb_switch *sw; in tb_find_first_usb3_tunnel() local
278 if (dst_port->sw->config.depth > src_port->sw->config.depth) in tb_find_first_usb3_tunnel()
279 sw = dst_port->sw; in tb_find_first_usb3_tunnel()
281 sw = src_port->sw; in tb_find_first_usb3_tunnel()
284 if (sw == tb->root_switch) in tb_find_first_usb3_tunnel()
288 port = tb_port_at(tb_route(sw), tb->root_switch); in tb_find_first_usb3_tunnel()
328 link_speed = port->sw->link_speed; in tb_available_bandwidth()
429 static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw) in tb_tunnel_usb3() argument
431 struct tb_switch *parent = tb_switch_parent(sw); in tb_tunnel_usb3()
437 up = tb_switch_find_port(sw, TB_TYPE_USB3_UP); in tb_tunnel_usb3()
441 if (!sw->link_usb4) in tb_tunnel_usb3()
448 port = tb_port_at(tb_route(sw), parent); in tb_tunnel_usb3()
507 static int tb_create_usb3_tunnels(struct tb_switch *sw) in tb_create_usb3_tunnels() argument
512 if (tb_route(sw)) { in tb_create_usb3_tunnels()
513 ret = tb_tunnel_usb3(sw->tb, sw); in tb_create_usb3_tunnels()
518 tb_switch_for_each_port(sw, port) { in tb_create_usb3_tunnels()
521 ret = tb_create_usb3_tunnels(port->remote->sw); in tb_create_usb3_tunnels()
534 static void tb_scan_switch(struct tb_switch *sw) in tb_scan_switch() argument
538 pm_runtime_get_sync(&sw->dev); in tb_scan_switch()
540 tb_switch_for_each_port(sw, port) in tb_scan_switch()
543 pm_runtime_mark_last_busy(&sw->dev); in tb_scan_switch()
544 pm_runtime_put_autosuspend(&sw->dev); in tb_scan_switch()
552 struct tb_cm *tcm = tb_priv(port->sw->tb); in tb_scan_port()
554 struct tb_switch *sw; in tb_scan_port() local
562 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port, in tb_scan_port()
583 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev, in tb_scan_port()
585 if (IS_ERR(sw)) { in tb_scan_port()
591 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL) in tb_scan_port()
596 if (tb_switch_configure(sw)) { in tb_scan_port()
597 tb_switch_put(sw); in tb_scan_port()
617 dev_set_uevent_suppress(&sw->dev, true); in tb_scan_port()
623 sw->rpm = sw->generation > 1; in tb_scan_port()
625 if (tb_switch_add(sw)) { in tb_scan_port()
626 tb_switch_put(sw); in tb_scan_port()
631 upstream_port = tb_upstream_port(sw); in tb_scan_port()
640 tb_switch_lane_bonding_enable(sw); in tb_scan_port()
642 tb_switch_configure_link(sw); in tb_scan_port()
644 if (tb_enable_tmu(sw)) in tb_scan_port()
645 tb_sw_warn(sw, "failed to enable TMU\n"); in tb_scan_port()
656 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw)) in tb_scan_port()
657 tb_sw_warn(sw, "USB3 tunnel creation failed\n"); in tb_scan_port()
659 tb_add_dp_resources(sw); in tb_scan_port()
660 tb_scan_switch(sw); in tb_scan_port()
684 tb_switch_dealloc_dp_resource(src_port->sw, src_port); in tb_deactivate_and_free_tunnel()
686 pm_runtime_mark_last_busy(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
687 pm_runtime_put_autosuspend(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
688 pm_runtime_mark_last_busy(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
689 pm_runtime_put_autosuspend(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
725 static void tb_free_unplugged_children(struct tb_switch *sw) in tb_free_unplugged_children() argument
729 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_children()
733 if (port->remote->sw->is_unplugged) { in tb_free_unplugged_children()
735 tb_remove_dp_resources(port->remote->sw); in tb_free_unplugged_children()
736 tb_switch_unconfigure_link(port->remote->sw); in tb_free_unplugged_children()
737 tb_switch_lane_bonding_disable(port->remote->sw); in tb_free_unplugged_children()
738 tb_switch_remove(port->remote->sw); in tb_free_unplugged_children()
743 tb_free_unplugged_children(port->remote->sw); in tb_free_unplugged_children()
748 static struct tb_port *tb_find_pcie_down(struct tb_switch *sw, in tb_find_pcie_down() argument
757 if (tb_switch_is_usb4(sw)) { in tb_find_pcie_down()
758 down = usb4_switch_map_pcie_down(sw, port); in tb_find_pcie_down()
759 } else if (!tb_route(sw)) { in tb_find_pcie_down()
767 if (tb_switch_is_cactus_ridge(sw) || in tb_find_pcie_down()
768 tb_switch_is_alpine_ridge(sw)) in tb_find_pcie_down()
770 else if (tb_switch_is_falcon_ridge(sw)) in tb_find_pcie_down()
772 else if (tb_switch_is_titan_ridge(sw)) in tb_find_pcie_down()
778 if (WARN_ON(index > sw->config.max_port_number)) in tb_find_pcie_down()
781 down = &sw->ports[index]; in tb_find_pcie_down()
794 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN); in tb_find_pcie_down()
802 host_port = tb_route(in->sw) ? in tb_find_dp_out()
803 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL; in tb_find_dp_out()
820 if (host_port && tb_route(port->sw)) { in tb_find_dp_out()
823 p = tb_port_at(tb_route(port->sw), tb->root_switch); in tb_find_dp_out()
884 pm_runtime_get_sync(&in->sw->dev); in tb_tunnel_dp()
885 pm_runtime_get_sync(&out->sw->dev); in tb_tunnel_dp()
887 if (tb_switch_alloc_dp_resource(in->sw, in)) { in tb_tunnel_dp()
927 tb_switch_dealloc_dp_resource(in->sw, in); in tb_tunnel_dp()
929 pm_runtime_mark_last_busy(&out->sw->dev); in tb_tunnel_dp()
930 pm_runtime_put_autosuspend(&out->sw->dev); in tb_tunnel_dp()
931 pm_runtime_mark_last_busy(&in->sw->dev); in tb_tunnel_dp()
932 pm_runtime_put_autosuspend(&in->sw->dev); in tb_tunnel_dp()
1005 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) in tb_tunnel_pci() argument
1012 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); in tb_tunnel_pci()
1020 parent_sw = tb_to_switch(sw->dev.parent); in tb_tunnel_pci()
1021 port = tb_port_at(tb_route(sw), parent_sw); in tb_tunnel_pci()
1046 struct tb_switch *sw; in tb_approve_xdomain_paths() local
1048 sw = tb_to_switch(xd->dev.parent); in tb_approve_xdomain_paths()
1049 dst_port = tb_port_at(xd->route, sw); in tb_approve_xdomain_paths()
1078 struct tb_switch *sw; in __tb_disconnect_xdomain_paths() local
1080 sw = tb_to_switch(xd->dev.parent); in __tb_disconnect_xdomain_paths()
1081 dst_port = tb_port_at(xd->route, sw); in __tb_disconnect_xdomain_paths()
1114 struct tb_switch *sw; in tb_handle_hotplug() local
1124 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_hotplug()
1125 if (!sw) { in tb_handle_hotplug()
1131 if (ev->port > sw->config.max_port_number) { in tb_handle_hotplug()
1137 port = &sw->ports[ev->port]; in tb_handle_hotplug()
1144 pm_runtime_get_sync(&sw->dev); in tb_handle_hotplug()
1151 tb_sw_set_unplugged(port->remote->sw); in tb_handle_hotplug()
1153 tb_remove_dp_resources(port->remote->sw); in tb_handle_hotplug()
1154 tb_switch_tmu_disable(port->remote->sw); in tb_handle_hotplug()
1155 tb_switch_unconfigure_link(port->remote->sw); in tb_handle_hotplug()
1156 tb_switch_lane_bonding_disable(port->remote->sw); in tb_handle_hotplug()
1157 tb_switch_remove(port->remote->sw); in tb_handle_hotplug()
1199 pm_runtime_mark_last_busy(&sw->dev); in tb_handle_hotplug()
1200 pm_runtime_put_autosuspend(&sw->dev); in tb_handle_hotplug()
1203 tb_switch_put(sw); in tb_handle_hotplug()
1264 struct tb_switch *sw = tb_to_switch(dev); in tb_scan_finalize_switch() local
1271 if (sw->boot) in tb_scan_finalize_switch()
1272 sw->authorized = 1; in tb_scan_finalize_switch()
1348 static void tb_restore_children(struct tb_switch *sw) in tb_restore_children() argument
1353 if (sw->is_unplugged) in tb_restore_children()
1356 if (tb_enable_tmu(sw)) in tb_restore_children()
1357 tb_sw_warn(sw, "failed to restore TMU configuration\n"); in tb_restore_children()
1359 tb_switch_for_each_port(sw, port) { in tb_restore_children()
1364 tb_switch_lane_bonding_enable(port->remote->sw); in tb_restore_children()
1365 tb_switch_configure_link(port->remote->sw); in tb_restore_children()
1367 tb_restore_children(port->remote->sw); in tb_restore_children()
1405 static int tb_free_unplugged_xdomains(struct tb_switch *sw) in tb_free_unplugged_xdomains() argument
1410 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_xdomains()
1420 ret += tb_free_unplugged_xdomains(port->remote->sw); in tb_free_unplugged_xdomains()