Lines Matching +full:dp +full:- +full:port
1 // SPDX-License-Identifier: GPL-2.0
3 * Thunderbolt driver - bus logic (NHI independent)
19 * struct tb_cm - Simple Thunderbolt connection manager
21 * @dp_resources: List of available DP resources for DP tunneling
38 return ((void *)tcm - sizeof(struct tb)); in tcm_to_tb()
45 u8 port; member
51 static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug) in tb_queue_hotplug() argument
59 ev->tb = tb; in tb_queue_hotplug()
60 ev->route = route; in tb_queue_hotplug()
61 ev->port = port; in tb_queue_hotplug()
62 ev->unplug = unplug; in tb_queue_hotplug()
63 INIT_WORK(&ev->work, tb_handle_hotplug); in tb_queue_hotplug()
64 queue_work(tb->wq, &ev->work); in tb_queue_hotplug()
71 struct tb_cm *tcm = tb_priv(sw->tb); in tb_add_dp_resources()
72 struct tb_port *port; in tb_add_dp_resources() local
74 tb_switch_for_each_port(sw, port) { in tb_add_dp_resources()
75 if (!tb_port_is_dpin(port)) in tb_add_dp_resources()
78 if (!tb_switch_query_dp_resource(sw, port)) in tb_add_dp_resources()
81 list_add_tail(&port->list, &tcm->dp_resources); in tb_add_dp_resources()
82 tb_port_dbg(port, "DP IN resource available\n"); in tb_add_dp_resources()
88 struct tb_cm *tcm = tb_priv(sw->tb); in tb_remove_dp_resources()
89 struct tb_port *port, *tmp; in tb_remove_dp_resources() local
92 tb_switch_for_each_port(sw, port) { in tb_remove_dp_resources()
93 if (tb_port_has_remote(port)) in tb_remove_dp_resources()
94 tb_remove_dp_resources(port->remote->sw); in tb_remove_dp_resources()
97 list_for_each_entry_safe(port, tmp, &tcm->dp_resources, list) { in tb_remove_dp_resources()
98 if (port->sw == sw) { in tb_remove_dp_resources()
99 tb_port_dbg(port, "DP OUT resource unavailable\n"); in tb_remove_dp_resources()
100 list_del_init(&port->list); in tb_remove_dp_resources()
107 struct tb *tb = sw->tb; in tb_discover_tunnels()
109 struct tb_port *port; in tb_discover_tunnels() local
111 tb_switch_for_each_port(sw, port) { in tb_discover_tunnels()
114 switch (port->config.type) { in tb_discover_tunnels()
116 tunnel = tb_tunnel_discover_dp(tb, port); in tb_discover_tunnels()
120 tunnel = tb_tunnel_discover_pci(tb, port); in tb_discover_tunnels()
124 tunnel = tb_tunnel_discover_usb3(tb, 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()
138 parent->boot = true; in tb_discover_tunnels()
143 pm_runtime_get_sync(&tunnel->src_port->sw->dev); in tb_discover_tunnels()
144 pm_runtime_get_sync(&tunnel->dst_port->sw->dev); in tb_discover_tunnels()
147 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_discover_tunnels()
150 tb_switch_for_each_port(sw, port) { in tb_discover_tunnels()
151 if (tb_port_has_remote(port)) in tb_discover_tunnels()
152 tb_discover_tunnels(port->remote->sw); in tb_discover_tunnels()
156 static int tb_port_configure_xdomain(struct tb_port *port) in tb_port_configure_xdomain() argument
162 tb_port_disable(port->dual_link_port); in tb_port_configure_xdomain()
164 if (tb_switch_is_usb4(port->sw)) in tb_port_configure_xdomain()
165 return usb4_port_configure_xdomain(port); in tb_port_configure_xdomain()
166 return tb_lc_configure_xdomain(port); in tb_port_configure_xdomain()
169 static void tb_port_unconfigure_xdomain(struct tb_port *port) in tb_port_unconfigure_xdomain() argument
171 if (tb_switch_is_usb4(port->sw)) in tb_port_unconfigure_xdomain()
172 usb4_port_unconfigure_xdomain(port); in tb_port_unconfigure_xdomain()
174 tb_lc_unconfigure_xdomain(port); in tb_port_unconfigure_xdomain()
176 tb_port_enable(port->dual_link_port); in tb_port_unconfigure_xdomain()
179 static void tb_scan_xdomain(struct tb_port *port) in tb_scan_xdomain() argument
181 struct tb_switch *sw = port->sw; in tb_scan_xdomain()
182 struct tb *tb = sw->tb; in tb_scan_xdomain()
186 route = tb_downstream_route(port); in tb_scan_xdomain()
193 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid, in tb_scan_xdomain()
196 tb_port_at(route, sw)->xdomain = xd; in tb_scan_xdomain()
197 tb_port_configure_xdomain(port); in tb_scan_xdomain()
222 * tb_find_unused_port() - return the first inactive port on @sw
223 * @sw: Switch to find the port on
224 * @type: Port type to look for
229 struct tb_port *port; in tb_find_unused_port() local
231 tb_switch_for_each_port(sw, port) { in tb_find_unused_port()
232 if (tb_is_upstream_port(port)) in tb_find_unused_port()
234 if (port->config.type != type) in tb_find_unused_port()
236 if (!port->cap_adap) in tb_find_unused_port()
238 if (tb_port_is_enabled(port)) in tb_find_unused_port()
240 return port; in tb_find_unused_port()
246 const struct tb_port *port) in tb_find_usb3_down() argument
250 down = usb4_switch_map_usb3_down(sw, port); in tb_find_usb3_down()
263 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_find_tunnel()
264 if (tunnel->type == type && in tb_find_tunnel()
265 ((src_port && src_port == tunnel->src_port) || in tb_find_tunnel()
266 (dst_port && dst_port == tunnel->dst_port))) { in tb_find_tunnel()
278 struct tb_port *port, *usb3_down; in tb_find_first_usb3_tunnel() local
282 if (dst_port->sw->config.depth > src_port->sw->config.depth) in tb_find_first_usb3_tunnel()
283 sw = dst_port->sw; in tb_find_first_usb3_tunnel()
285 sw = src_port->sw; in tb_find_first_usb3_tunnel()
288 if (sw == tb->root_switch) in tb_find_first_usb3_tunnel()
291 /* Find the downstream USB4 port that leads to this router */ in tb_find_first_usb3_tunnel()
292 port = tb_port_at(tb_route(sw), tb->root_switch); in tb_find_first_usb3_tunnel()
293 /* Find the corresponding host router USB3 downstream port */ in tb_find_first_usb3_tunnel()
294 usb3_down = usb4_switch_map_usb3_down(tb->root_switch, port); in tb_find_first_usb3_tunnel()
307 struct tb_port *port; in tb_available_bandwidth() local
325 tb_for_each_port_on_path(src_port, dst_port, port) { in tb_available_bandwidth()
328 if (!tb_port_is_null(port)) in tb_available_bandwidth()
331 if (tb_is_upstream_port(port)) { in tb_available_bandwidth()
332 link_speed = port->sw->link_speed; in tb_available_bandwidth()
334 link_speed = tb_port_get_link_speed(port); in tb_available_bandwidth()
339 link_width = port->bonded ? 2 : 1; in tb_available_bandwidth()
343 up_bw -= up_bw / 10; in tb_available_bandwidth()
346 tb_port_dbg(port, "link total bandwidth %d Mb/s\n", up_bw); in tb_available_bandwidth()
349 * Find all DP tunnels that cross the port and reduce in tb_available_bandwidth()
352 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_available_bandwidth()
358 if (!tb_tunnel_port_on_path(tunnel, port)) in tb_available_bandwidth()
367 up_bw -= dp_consumed_up; in tb_available_bandwidth()
368 down_bw -= dp_consumed_down; in tb_available_bandwidth()
373 * branch leading to port we need to take USB3 consumed in tb_available_bandwidth()
375 * crosses the port. in tb_available_bandwidth()
377 up_bw -= usb3_consumed_up; in tb_available_bandwidth()
378 down_bw -= usb3_consumed_down; in tb_available_bandwidth()
420 ret = tb_available_bandwidth(tb, tunnel->src_port, tunnel->dst_port, in tb_reclaim_usb3_bandwidth()
437 struct tb_port *up, *down, *port; in tb_tunnel_usb3() local
445 if (!sw->link_usb4) in tb_tunnel_usb3()
449 * Look up available down port. Since we are chaining it should in tb_tunnel_usb3()
452 port = tb_port_at(tb_route(sw), parent); in tb_tunnel_usb3()
453 down = tb_find_usb3_down(parent, port); in tb_tunnel_usb3()
461 * port enabled. Otherwise the chain is not complete and in tb_tunnel_usb3()
485 ret = -ENOMEM; in tb_tunnel_usb3()
492 ret = -EIO; in tb_tunnel_usb3()
496 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_tunnel_usb3()
513 struct tb_port *port; in tb_create_usb3_tunnels() local
517 ret = tb_tunnel_usb3(sw->tb, sw); in tb_create_usb3_tunnels()
522 tb_switch_for_each_port(sw, port) { in tb_create_usb3_tunnels()
523 if (!tb_port_has_remote(port)) in tb_create_usb3_tunnels()
525 ret = tb_create_usb3_tunnels(port->remote->sw); in tb_create_usb3_tunnels()
533 static void tb_scan_port(struct tb_port *port);
536 * tb_scan_switch() - scan for and initialize downstream switches
540 struct tb_port *port; in tb_scan_switch() local
542 pm_runtime_get_sync(&sw->dev); in tb_scan_switch()
544 tb_switch_for_each_port(sw, port) in tb_scan_switch()
545 tb_scan_port(port); in tb_scan_switch()
547 pm_runtime_mark_last_busy(&sw->dev); in tb_scan_switch()
548 pm_runtime_put_autosuspend(&sw->dev); in tb_scan_switch()
552 * tb_scan_port() - check for and initialize switches below port
554 static void tb_scan_port(struct tb_port *port) in tb_scan_port() argument
556 struct tb_cm *tcm = tb_priv(port->sw->tb); in tb_scan_port()
560 if (tb_is_upstream_port(port)) in tb_scan_port()
563 if (tb_port_is_dpout(port) && tb_dp_port_hpd_is_active(port) == 1 && in tb_scan_port()
564 !tb_dp_port_is_enabled(port)) { in tb_scan_port()
565 tb_port_dbg(port, "DP adapter HPD set, queuing hotplug\n"); in tb_scan_port()
566 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port, in tb_scan_port()
571 if (port->config.type != TB_TYPE_PORT) in tb_scan_port()
573 if (port->dual_link_port && port->link_nr) in tb_scan_port()
576 * Only scan on the primary port (link_nr == 0). in tb_scan_port()
578 if (tb_wait_for_port(port, false) <= 0) in tb_scan_port()
580 if (port->remote) { in tb_scan_port()
581 tb_port_dbg(port, "port already has a remote\n"); in tb_scan_port()
585 tb_retimer_scan(port); in tb_scan_port()
587 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev, in tb_scan_port()
588 tb_downstream_route(port)); in tb_scan_port()
595 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL) in tb_scan_port()
596 tb_scan_xdomain(port); in tb_scan_port()
609 if (port->xdomain) { in tb_scan_port()
610 tb_xdomain_remove(port->xdomain); in tb_scan_port()
611 tb_port_unconfigure_xdomain(port); in tb_scan_port()
612 port->xdomain = NULL; in tb_scan_port()
620 if (!tcm->hotplug_active) in tb_scan_port()
621 dev_set_uevent_suppress(&sw->dev, true); in tb_scan_port()
627 sw->rpm = sw->generation > 1; in tb_scan_port()
636 port->remote = upstream_port; in tb_scan_port()
637 upstream_port->remote = port; in tb_scan_port()
638 if (port->dual_link_port && upstream_port->dual_link_port) { in tb_scan_port()
639 port->dual_link_port->remote = upstream_port->dual_link_port; in tb_scan_port()
640 upstream_port->dual_link_port->remote = port->dual_link_port; in tb_scan_port()
660 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw)) in tb_scan_port()
676 list_del(&tunnel->list); in tb_deactivate_and_free_tunnel()
678 tb = tunnel->tb; in tb_deactivate_and_free_tunnel()
679 src_port = tunnel->src_port; in tb_deactivate_and_free_tunnel()
680 dst_port = tunnel->dst_port; in tb_deactivate_and_free_tunnel()
682 switch (tunnel->type) { in tb_deactivate_and_free_tunnel()
685 * In case of DP tunnel make sure the DP IN resource is in tb_deactivate_and_free_tunnel()
688 tb_switch_dealloc_dp_resource(src_port->sw, src_port); in tb_deactivate_and_free_tunnel()
690 pm_runtime_mark_last_busy(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
691 pm_runtime_put_autosuspend(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
692 pm_runtime_mark_last_busy(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
693 pm_runtime_put_autosuspend(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
712 * tb_free_invalid_tunnels() - destroy tunnels of devices that have gone away
720 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) { in tb_free_invalid_tunnels()
727 * tb_free_unplugged_children() - traverse hierarchy and free unplugged switches
731 struct tb_port *port; in tb_free_unplugged_children() local
733 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_children()
734 if (!tb_port_has_remote(port)) in tb_free_unplugged_children()
737 if (port->remote->sw->is_unplugged) { in tb_free_unplugged_children()
738 tb_retimer_remove_all(port); in tb_free_unplugged_children()
739 tb_remove_dp_resources(port->remote->sw); in tb_free_unplugged_children()
740 tb_switch_unconfigure_link(port->remote->sw); in tb_free_unplugged_children()
741 tb_switch_lane_bonding_disable(port->remote->sw); in tb_free_unplugged_children()
742 tb_switch_remove(port->remote->sw); in tb_free_unplugged_children()
743 port->remote = NULL; in tb_free_unplugged_children()
744 if (port->dual_link_port) in tb_free_unplugged_children()
745 port->dual_link_port->remote = NULL; in tb_free_unplugged_children()
747 tb_free_unplugged_children(port->remote->sw); in tb_free_unplugged_children()
753 const struct tb_port *port) in tb_find_pcie_down() argument
762 down = usb4_switch_map_pcie_down(sw, port); in tb_find_pcie_down()
764 int phy_port = tb_phy_port_from_link(port->port); in tb_find_pcie_down()
768 * Hard-coded Thunderbolt port to PCIe down port mapping in tb_find_pcie_down()
781 /* Validate the hard-coding */ in tb_find_pcie_down()
782 if (WARN_ON(index > sw->config.max_port_number)) in tb_find_pcie_down()
785 down = &sw->ports[index]; in tb_find_pcie_down()
803 struct tb_port *host_port, *port; in tb_find_dp_out() local
806 host_port = tb_route(in->sw) ? in tb_find_dp_out()
807 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL; in tb_find_dp_out()
809 list_for_each_entry(port, &tcm->dp_resources, list) { in tb_find_dp_out()
810 if (!tb_port_is_dpout(port)) in tb_find_dp_out()
813 if (tb_port_is_enabled(port)) { in tb_find_dp_out()
814 tb_port_dbg(port, "in use\n"); in tb_find_dp_out()
818 tb_port_dbg(port, "DP OUT available\n"); in tb_find_dp_out()
821 * Keep the DP tunnel under the topology starting from in tb_find_dp_out()
822 * the same host router downstream port. in tb_find_dp_out()
824 if (host_port && tb_route(port->sw)) { in tb_find_dp_out()
827 p = tb_port_at(tb_route(port->sw), tb->root_switch); in tb_find_dp_out()
832 return port; in tb_find_dp_out()
842 struct tb_port *port, *in, *out; in tb_tunnel_dp() local
846 * Find pair of inactive DP IN and DP OUT adapters and then in tb_tunnel_dp()
847 * establish a DP tunnel between them. in tb_tunnel_dp()
849 tb_dbg(tb, "looking for DP IN <-> DP OUT pairs:\n"); in tb_tunnel_dp()
853 list_for_each_entry(port, &tcm->dp_resources, list) { in tb_tunnel_dp()
854 if (!tb_port_is_dpin(port)) in tb_tunnel_dp()
857 if (tb_port_is_enabled(port)) { in tb_tunnel_dp()
858 tb_port_dbg(port, "in use\n"); in tb_tunnel_dp()
862 tb_port_dbg(port, "DP IN available\n"); in tb_tunnel_dp()
864 out = tb_find_dp_out(tb, port); in tb_tunnel_dp()
866 in = port; in tb_tunnel_dp()
872 tb_dbg(tb, "no suitable DP IN adapter available, not tunneling\n"); in tb_tunnel_dp()
876 tb_dbg(tb, "no suitable DP OUT adapter available, not tunneling\n"); in tb_tunnel_dp()
881 * DP stream needs the domain to be active so runtime resume in tb_tunnel_dp()
885 * and keeps the domain from runtime suspending while the DP in tb_tunnel_dp()
888 pm_runtime_get_sync(&in->sw->dev); in tb_tunnel_dp()
889 pm_runtime_get_sync(&out->sw->dev); in tb_tunnel_dp()
891 if (tb_switch_alloc_dp_resource(in->sw, in)) { in tb_tunnel_dp()
892 tb_port_dbg(in, "no resource available for DP IN, not tunneling\n"); in tb_tunnel_dp()
896 /* Make all unused USB3 bandwidth available for the new DP tunnel */ in tb_tunnel_dp()
908 tb_dbg(tb, "available bandwidth for new DP tunnel %u/%u Mb/s\n", in tb_tunnel_dp()
913 tb_port_dbg(out, "could not allocate DP tunnel\n"); in tb_tunnel_dp()
918 tb_port_info(out, "DP tunnel activation failed, aborting\n"); in tb_tunnel_dp()
922 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_tunnel_dp()
931 tb_switch_dealloc_dp_resource(in->sw, in); in tb_tunnel_dp()
933 pm_runtime_mark_last_busy(&out->sw->dev); in tb_tunnel_dp()
934 pm_runtime_put_autosuspend(&out->sw->dev); in tb_tunnel_dp()
935 pm_runtime_mark_last_busy(&in->sw->dev); in tb_tunnel_dp()
936 pm_runtime_put_autosuspend(&in->sw->dev); in tb_tunnel_dp()
939 static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port) in tb_dp_resource_unavailable() argument
944 if (tb_port_is_dpin(port)) { in tb_dp_resource_unavailable()
945 tb_port_dbg(port, "DP IN resource unavailable\n"); in tb_dp_resource_unavailable()
946 in = port; in tb_dp_resource_unavailable()
949 tb_port_dbg(port, "DP OUT resource unavailable\n"); in tb_dp_resource_unavailable()
951 out = port; in tb_dp_resource_unavailable()
956 list_del_init(&port->list); in tb_dp_resource_unavailable()
959 * See if there is another DP OUT port that can be used for in tb_dp_resource_unavailable()
965 static void tb_dp_resource_available(struct tb *tb, struct tb_port *port) in tb_dp_resource_available() argument
970 if (tb_port_is_enabled(port)) in tb_dp_resource_available()
973 list_for_each_entry(p, &tcm->dp_resources, list) { in tb_dp_resource_available()
974 if (p == port) in tb_dp_resource_available()
978 tb_port_dbg(port, "DP %s resource available\n", in tb_dp_resource_available()
979 tb_port_is_dpin(port) ? "IN" : "OUT"); in tb_dp_resource_available()
980 list_add_tail(&port->list, &tcm->dp_resources); in tb_dp_resource_available()
982 /* Look for suitable DP IN <-> DP OUT pairs now */ in tb_dp_resource_available()
992 * Tear down all DP tunnels and release their resources. They in tb_disconnect_and_release_dp()
993 * will be re-established after resume based on plug events. in tb_disconnect_and_release_dp()
995 list_for_each_entry_safe_reverse(tunnel, n, &tcm->tunnel_list, list) { in tb_disconnect_and_release_dp()
1000 while (!list_empty(&tcm->dp_resources)) { in tb_disconnect_and_release_dp()
1001 struct tb_port *port; in tb_disconnect_and_release_dp() local
1003 port = list_first_entry(&tcm->dp_resources, in tb_disconnect_and_release_dp()
1005 list_del_init(&port->list); in tb_disconnect_and_release_dp()
1011 struct tb_port *up, *down, *port; in tb_tunnel_pci() local
1021 * Look up available down port. Since we are chaining it should in tb_tunnel_pci()
1024 parent_sw = tb_to_switch(sw->dev.parent); in tb_tunnel_pci()
1025 port = tb_port_at(tb_route(sw), parent_sw); in tb_tunnel_pci()
1026 down = tb_find_pcie_down(parent_sw, port); in tb_tunnel_pci()
1032 return -ENOMEM; in tb_tunnel_pci()
1038 return -EIO; in tb_tunnel_pci()
1041 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_tunnel_pci()
1052 sw = tb_to_switch(xd->dev.parent); in tb_approve_xdomain_paths()
1053 dst_port = tb_port_at(xd->route, sw); in tb_approve_xdomain_paths()
1054 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); in tb_approve_xdomain_paths()
1056 mutex_lock(&tb->lock); in tb_approve_xdomain_paths()
1057 tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, xd->transmit_ring, in tb_approve_xdomain_paths()
1058 xd->transmit_path, xd->receive_ring, in tb_approve_xdomain_paths()
1059 xd->receive_path); in tb_approve_xdomain_paths()
1061 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
1062 return -ENOMEM; in tb_approve_xdomain_paths()
1069 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
1070 return -EIO; in tb_approve_xdomain_paths()
1073 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_approve_xdomain_paths()
1074 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
1084 sw = tb_to_switch(xd->dev.parent); in __tb_disconnect_xdomain_paths()
1085 dst_port = tb_port_at(xd->route, sw); in __tb_disconnect_xdomain_paths()
1098 if (!xd->is_unplugged) { in tb_disconnect_xdomain_paths()
1099 mutex_lock(&tb->lock); in tb_disconnect_xdomain_paths()
1101 mutex_unlock(&tb->lock); in tb_disconnect_xdomain_paths()
1109 * tb_handle_hotplug() - handle hotplug event
1111 * Executes on tb->wq.
1116 struct tb *tb = ev->tb; in tb_handle_hotplug()
1119 struct tb_port *port; in tb_handle_hotplug() local
1122 pm_runtime_get_sync(&tb->dev); in tb_handle_hotplug()
1124 mutex_lock(&tb->lock); in tb_handle_hotplug()
1125 if (!tcm->hotplug_active) in tb_handle_hotplug()
1128 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_hotplug()
1132 ev->route, ev->port, ev->unplug); in tb_handle_hotplug()
1135 if (ev->port > sw->config.max_port_number) { in tb_handle_hotplug()
1137 "hotplug event from non existent port %llx:%x (unplug: %d)\n", in tb_handle_hotplug()
1138 ev->route, ev->port, ev->unplug); in tb_handle_hotplug()
1141 port = &sw->ports[ev->port]; in tb_handle_hotplug()
1142 if (tb_is_upstream_port(port)) { in tb_handle_hotplug()
1143 tb_dbg(tb, "hotplug event for upstream port %llx:%x (unplug: %d)\n", in tb_handle_hotplug()
1144 ev->route, ev->port, ev->unplug); in tb_handle_hotplug()
1148 pm_runtime_get_sync(&sw->dev); in tb_handle_hotplug()
1150 if (ev->unplug) { in tb_handle_hotplug()
1151 tb_retimer_remove_all(port); in tb_handle_hotplug()
1153 if (tb_port_has_remote(port)) { in tb_handle_hotplug()
1154 tb_port_dbg(port, "switch unplugged\n"); in tb_handle_hotplug()
1155 tb_sw_set_unplugged(port->remote->sw); in tb_handle_hotplug()
1157 tb_remove_dp_resources(port->remote->sw); in tb_handle_hotplug()
1158 tb_switch_tmu_disable(port->remote->sw); in tb_handle_hotplug()
1159 tb_switch_unconfigure_link(port->remote->sw); in tb_handle_hotplug()
1160 tb_switch_lane_bonding_disable(port->remote->sw); in tb_handle_hotplug()
1161 tb_switch_remove(port->remote->sw); in tb_handle_hotplug()
1162 port->remote = NULL; in tb_handle_hotplug()
1163 if (port->dual_link_port) in tb_handle_hotplug()
1164 port->dual_link_port->remote = NULL; in tb_handle_hotplug()
1165 /* Maybe we can create another DP tunnel */ in tb_handle_hotplug()
1167 } else if (port->xdomain) { in tb_handle_hotplug()
1168 struct tb_xdomain *xd = tb_xdomain_get(port->xdomain); in tb_handle_hotplug()
1170 tb_port_dbg(port, "xdomain unplugged\n"); in tb_handle_hotplug()
1178 xd->is_unplugged = true; in tb_handle_hotplug()
1180 port->xdomain = NULL; in tb_handle_hotplug()
1183 tb_port_unconfigure_xdomain(port); in tb_handle_hotplug()
1184 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) { in tb_handle_hotplug()
1185 tb_dp_resource_unavailable(tb, port); in tb_handle_hotplug()
1187 tb_port_dbg(port, in tb_handle_hotplug()
1188 "got unplug event for disconnected port, ignoring\n"); in tb_handle_hotplug()
1190 } else if (port->remote) { in tb_handle_hotplug()
1191 tb_port_dbg(port, "got plug event for connected port, ignoring\n"); in tb_handle_hotplug()
1193 if (tb_port_is_null(port)) { in tb_handle_hotplug()
1194 tb_port_dbg(port, "hotplug: scanning\n"); in tb_handle_hotplug()
1195 tb_scan_port(port); in tb_handle_hotplug()
1196 if (!port->remote) in tb_handle_hotplug()
1197 tb_port_dbg(port, "hotplug: no switch found\n"); in tb_handle_hotplug()
1198 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) { in tb_handle_hotplug()
1199 tb_dp_resource_available(tb, port); in tb_handle_hotplug()
1203 pm_runtime_mark_last_busy(&sw->dev); in tb_handle_hotplug()
1204 pm_runtime_put_autosuspend(&sw->dev); in tb_handle_hotplug()
1209 mutex_unlock(&tb->lock); in tb_handle_hotplug()
1211 pm_runtime_mark_last_busy(&tb->dev); in tb_handle_hotplug()
1212 pm_runtime_put_autosuspend(&tb->dev); in tb_handle_hotplug()
1218 * tb_schedule_hotplug_handler() - callback function for the control channel
1233 route = tb_cfg_get_route(&pkg->header); in tb_handle_event()
1235 if (tb_cfg_ack_plug(tb->ctl, route, pkg->port, pkg->unplug)) { in tb_handle_event()
1237 pkg->port); in tb_handle_event()
1240 tb_queue_hotplug(tb, route, pkg->port, pkg->unplug); in tb_handle_event()
1249 cancel_delayed_work(&tcm->remove_work); in tb_stop()
1251 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) { in tb_stop()
1261 tb_switch_remove(tb->root_switch); in tb_stop()
1262 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */ in tb_stop()
1275 if (sw->boot) in tb_scan_finalize_switch()
1276 sw->authorized = 1; in tb_scan_finalize_switch()
1279 kobject_uevent(&dev->kobj, KOBJ_ADD); in tb_scan_finalize_switch()
1291 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); in tb_start()
1292 if (IS_ERR(tb->root_switch)) in tb_start()
1293 return PTR_ERR(tb->root_switch); in tb_start()
1300 tb->root_switch->no_nvm_upgrade = true; in tb_start()
1302 tb->root_switch->rpm = tb_switch_is_usb4(tb->root_switch); in tb_start()
1304 ret = tb_switch_configure(tb->root_switch); in tb_start()
1306 tb_switch_put(tb->root_switch); in tb_start()
1311 ret = tb_switch_add(tb->root_switch); in tb_start()
1313 tb_switch_put(tb->root_switch); in tb_start()
1318 tb_switch_tmu_enable(tb->root_switch); in tb_start()
1320 tb_scan_switch(tb->root_switch); in tb_start()
1322 tb_discover_tunnels(tb->root_switch); in tb_start()
1327 tb_create_usb3_tunnels(tb->root_switch); in tb_start()
1328 /* Add DP IN resources for the root switch */ in tb_start()
1329 tb_add_dp_resources(tb->root_switch); in tb_start()
1331 device_for_each_child(&tb->root_switch->dev, NULL, in tb_start()
1335 tcm->hotplug_active = true; in tb_start()
1345 tb_switch_suspend(tb->root_switch, false); in tb_suspend_noirq()
1346 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */ in tb_suspend_noirq()
1354 struct tb_port *port; in tb_restore_children() local
1357 if (sw->is_unplugged) in tb_restore_children()
1363 tb_switch_for_each_port(sw, port) { in tb_restore_children()
1364 if (!tb_port_has_remote(port) && !port->xdomain) in tb_restore_children()
1367 if (port->remote) { in tb_restore_children()
1368 tb_switch_lane_bonding_enable(port->remote->sw); in tb_restore_children()
1369 tb_switch_configure_link(port->remote->sw); in tb_restore_children()
1371 tb_restore_children(port->remote->sw); in tb_restore_children()
1372 } else if (port->xdomain) { in tb_restore_children()
1373 tb_port_configure_xdomain(port); in tb_restore_children()
1386 tb_switch_reset(tb->root_switch); in tb_resume_noirq()
1388 tb_switch_resume(tb->root_switch); in tb_resume_noirq()
1390 tb_free_unplugged_children(tb->root_switch); in tb_resume_noirq()
1391 tb_restore_children(tb->root_switch); in tb_resume_noirq()
1392 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) in tb_resume_noirq()
1394 if (!list_empty(&tcm->tunnel_list)) { in tb_resume_noirq()
1403 tcm->hotplug_active = true; in tb_resume_noirq()
1411 struct tb_port *port; in tb_free_unplugged_xdomains() local
1414 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_xdomains()
1415 if (tb_is_upstream_port(port)) in tb_free_unplugged_xdomains()
1417 if (port->xdomain && port->xdomain->is_unplugged) { in tb_free_unplugged_xdomains()
1418 tb_retimer_remove_all(port); in tb_free_unplugged_xdomains()
1419 tb_xdomain_remove(port->xdomain); in tb_free_unplugged_xdomains()
1420 tb_port_unconfigure_xdomain(port); in tb_free_unplugged_xdomains()
1421 port->xdomain = NULL; in tb_free_unplugged_xdomains()
1423 } else if (port->remote) { in tb_free_unplugged_xdomains()
1424 ret += tb_free_unplugged_xdomains(port->remote->sw); in tb_free_unplugged_xdomains()
1435 tcm->hotplug_active = false; in tb_freeze_noirq()
1443 tcm->hotplug_active = true; in tb_thaw_noirq()
1454 mutex_lock(&tb->lock); in tb_complete()
1455 if (tb_free_unplugged_xdomains(tb->root_switch)) in tb_complete()
1456 tb_scan_switch(tb->root_switch); in tb_complete()
1457 mutex_unlock(&tb->lock); in tb_complete()
1464 mutex_lock(&tb->lock); in tb_runtime_suspend()
1465 tb_switch_suspend(tb->root_switch, true); in tb_runtime_suspend()
1466 tcm->hotplug_active = false; in tb_runtime_suspend()
1467 mutex_unlock(&tb->lock); in tb_runtime_suspend()
1477 mutex_lock(&tb->lock); in tb_remove_work()
1478 if (tb->root_switch) { in tb_remove_work()
1479 tb_free_unplugged_children(tb->root_switch); in tb_remove_work()
1480 tb_free_unplugged_xdomains(tb->root_switch); in tb_remove_work()
1482 mutex_unlock(&tb->lock); in tb_remove_work()
1490 mutex_lock(&tb->lock); in tb_runtime_resume()
1491 tb_switch_resume(tb->root_switch); in tb_runtime_resume()
1493 tb_restore_children(tb->root_switch); in tb_runtime_resume()
1494 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) in tb_runtime_resume()
1496 tcm->hotplug_active = true; in tb_runtime_resume()
1497 mutex_unlock(&tb->lock); in tb_runtime_resume()
1504 queue_delayed_work(tb->wq, &tcm->remove_work, msecs_to_jiffies(50)); in tb_runtime_resume()
1533 tb->security_level = TB_SECURITY_USER; in tb_probe()
1534 tb->cm_ops = &tb_cm_ops; in tb_probe()
1537 INIT_LIST_HEAD(&tcm->tunnel_list); in tb_probe()
1538 INIT_LIST_HEAD(&tcm->dp_resources); in tb_probe()
1539 INIT_DELAYED_WORK(&tcm->remove_work, tb_remove_work); in tb_probe()