Lines Matching +full:use +full:- +full:sw +full:- +full:pm

1 // SPDX-License-Identifier: GPL-2.0
3 * Thunderbolt driver - bus logic (NHI independent)
23 * direction. This is 40G - 10% guard band bandwidth.
46 * struct tb_cm - Simple Thunderbolt connection manager
67 return ((void *)tcm - sizeof(struct tb)); in tcm_to_tb()
82 for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { in tb_init_bandwidth_groups()
83 struct tb_bandwidth_group *group = &tcm->groups[i]; in tb_init_bandwidth_groups()
85 group->tb = tcm_to_tb(tcm); in tb_init_bandwidth_groups()
86 group->index = i + 1; in tb_init_bandwidth_groups()
87 INIT_LIST_HEAD(&group->ports); in tb_init_bandwidth_groups()
94 if (!group || WARN_ON(in->group)) in tb_bandwidth_group_attach_port()
97 in->group = group; in tb_bandwidth_group_attach_port()
98 list_add_tail(&in->group_list, &group->ports); in tb_bandwidth_group_attach_port()
100 tb_port_dbg(in, "attached to bandwidth group %d\n", group->index); in tb_bandwidth_group_attach_port()
107 for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { in tb_find_free_bandwidth_group()
108 struct tb_bandwidth_group *group = &tcm->groups[i]; in tb_find_free_bandwidth_group()
110 if (list_empty(&group->ports)) in tb_find_free_bandwidth_group()
130 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_attach_bandwidth_group()
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()
136 group = tunnel->src_port->group; in tb_attach_bandwidth_group()
161 for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { in tb_discover_bandwidth_group()
162 if (tcm->groups[i].index == index) { in tb_discover_bandwidth_group()
163 tb_bandwidth_group_attach_port(&tcm->groups[i], in); in tb_discover_bandwidth_group()
174 struct tb_bandwidth_group *group = in->group; in tb_detach_bandwidth_group()
177 in->group = NULL; in tb_detach_bandwidth_group()
178 list_del_init(&in->group_list); in tb_detach_bandwidth_group()
180 tb_port_dbg(in, "detached from bandwidth group %d\n", group->index); in tb_detach_bandwidth_group()
194 ev->tb = tb; in tb_queue_hotplug()
195 ev->route = route; in tb_queue_hotplug()
196 ev->port = port; in tb_queue_hotplug()
197 ev->unplug = unplug; in tb_queue_hotplug()
198 INIT_WORK(&ev->work, tb_handle_hotplug); in tb_queue_hotplug()
199 queue_work(tb->wq, &ev->work); in tb_queue_hotplug()
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()
216 list_add_tail(&port->list, &tcm->dp_resources); in tb_add_dp_resources()
221 static void tb_remove_dp_resources(struct tb_switch *sw) in tb_remove_dp_resources() argument
223 struct tb_cm *tcm = tb_priv(sw->tb); in tb_remove_dp_resources()
227 tb_switch_for_each_port(sw, port) { in tb_remove_dp_resources()
229 tb_remove_dp_resources(port->remote->sw); in tb_remove_dp_resources()
232 list_for_each_entry_safe(port, tmp, &tcm->dp_resources, list) { in tb_remove_dp_resources()
233 if (port->sw == sw) { in tb_remove_dp_resources()
235 list_del_init(&port->list); in tb_remove_dp_resources()
245 list_for_each_entry(p, &tcm->dp_resources, list) { in tb_discover_dp_resource()
252 list_add_tail(&port->list, &tcm->dp_resources); in tb_discover_dp_resource()
260 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_discover_dp_resources()
262 tb_discover_dp_resource(tb, tunnel->dst_port); in tb_discover_dp_resources()
267 static int tb_enable_clx(struct tb_switch *sw) in tb_enable_clx() argument
269 struct tb_cm *tcm = tb_priv(sw->tb); in tb_enable_clx()
281 while (sw && tb_switch_depth(sw) > 1) in tb_enable_clx()
282 sw = tb_switch_parent(sw); in tb_enable_clx()
284 if (!sw) in tb_enable_clx()
287 if (tb_switch_depth(sw) != 1) in tb_enable_clx()
291 * If we are re-enabling then check if there is an active DMA in tb_enable_clx()
294 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_enable_clx()
296 if (tb_tunnel_port_on_path(tunnel, tb_upstream_port(sw))) in tb_enable_clx()
305 ret = tb_switch_clx_enable(sw, clx | TB_CL2); in tb_enable_clx()
306 if (ret == -EOPNOTSUPP) in tb_enable_clx()
307 ret = tb_switch_clx_enable(sw, clx); in tb_enable_clx()
308 return ret == -EOPNOTSUPP ? 0 : ret; in tb_enable_clx()
312 * tb_disable_clx() - Disable CL states up to host router
313 * @sw: Router to start
315 * Disables CL states from @sw up to the host router. Returns true if
320 static bool tb_disable_clx(struct tb_switch *sw) in tb_disable_clx() argument
327 ret = tb_switch_clx_disable(sw); in tb_disable_clx()
331 tb_sw_warn(sw, "failed to disable CL states\n"); in tb_disable_clx()
333 sw = tb_switch_parent(sw); in tb_disable_clx()
334 } while (sw); in tb_disable_clx()
341 struct tb_switch *sw; in tb_increase_switch_tmu_accuracy() local
343 sw = tb_to_switch(dev); in tb_increase_switch_tmu_accuracy()
344 if (!sw) in tb_increase_switch_tmu_accuracy()
347 if (tb_switch_tmu_is_configured(sw, TB_SWITCH_TMU_MODE_LOWRES)) { in tb_increase_switch_tmu_accuracy()
351 if (tb_switch_clx_is_enabled(sw, TB_CL1)) in tb_increase_switch_tmu_accuracy()
356 ret = tb_switch_tmu_configure(sw, mode); in tb_increase_switch_tmu_accuracy()
360 return tb_switch_tmu_enable(sw); in tb_increase_switch_tmu_accuracy()
368 struct tb_switch *sw; in tb_increase_tmu_accuracy() local
382 sw = tunnel->tb->root_switch; in tb_increase_tmu_accuracy()
383 device_for_each_child(&sw->dev, NULL, tb_increase_switch_tmu_accuracy); in tb_increase_tmu_accuracy()
388 struct tb_switch *sw = tb_to_switch(dev); in tb_switch_tmu_hifi_uni_required() local
390 if (sw && tb_switch_tmu_is_enabled(sw) && in tb_switch_tmu_hifi_uni_required()
391 tb_switch_tmu_is_configured(sw, TB_SWITCH_TMU_MODE_HIFI_UNI)) in tb_switch_tmu_hifi_uni_required()
400 return device_for_each_child(&tb->dev, NULL, in tb_tmu_hifi_uni_required()
404 static int tb_enable_tmu(struct tb_switch *sw) in tb_enable_tmu() argument
410 * enable the enhanched uni-directional mode. That covers all in tb_enable_tmu()
411 * the CL states. For v1 and before we need to use the normal in tb_enable_tmu()
415 ret = tb_switch_tmu_configure(sw, in tb_enable_tmu()
417 if (ret == -EOPNOTSUPP) { in tb_enable_tmu()
418 if (tb_switch_clx_is_enabled(sw, TB_CL1)) { in tb_enable_tmu()
420 * Figure out uni-directional HiFi TMU requirements in tb_enable_tmu()
422 * uni-directional HiFi requirements we can put the TMU in tb_enable_tmu()
425 * Deliberately skip bi-directional HiFi links in tb_enable_tmu()
429 if (tb_tmu_hifi_uni_required(sw->tb)) in tb_enable_tmu()
430 ret = tb_switch_tmu_configure(sw, in tb_enable_tmu()
433 ret = tb_switch_tmu_configure(sw, in tb_enable_tmu()
436 ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_MODE_HIFI_BI); in tb_enable_tmu()
439 /* If not supported, fallback to bi-directional HiFi */ in tb_enable_tmu()
440 if (ret == -EOPNOTSUPP) in tb_enable_tmu()
441 ret = tb_switch_tmu_configure(sw, TB_SWITCH_TMU_MODE_HIFI_BI); in tb_enable_tmu()
447 if (tb_switch_tmu_is_enabled(sw)) in tb_enable_tmu()
450 ret = tb_switch_tmu_disable(sw); in tb_enable_tmu()
454 ret = tb_switch_tmu_post_time(sw); in tb_enable_tmu()
458 return tb_switch_tmu_enable(sw); in tb_enable_tmu()
461 static void tb_switch_discover_tunnels(struct tb_switch *sw, in tb_switch_discover_tunnels() argument
465 struct tb *tb = sw->tb; in tb_switch_discover_tunnels()
468 tb_switch_for_each_port(sw, port) { in tb_switch_discover_tunnels()
471 switch (port->config.type) { in tb_switch_discover_tunnels()
490 list_add_tail(&tunnel->list, list); in tb_switch_discover_tunnels()
493 tb_switch_for_each_port(sw, port) { in tb_switch_discover_tunnels()
495 tb_switch_discover_tunnels(port->remote->sw, list, in tb_switch_discover_tunnels()
506 tb_switch_discover_tunnels(tb->root_switch, &tcm->tunnel_list, true); in tb_discover_tunnels()
508 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_discover_tunnels()
510 struct tb_switch *parent = tunnel->dst_port->sw; in tb_discover_tunnels()
512 while (parent != tunnel->src_port->sw) { in tb_discover_tunnels()
513 parent->boot = true; in tb_discover_tunnels()
517 struct tb_port *in = tunnel->src_port; in tb_discover_tunnels()
518 struct tb_port *out = tunnel->dst_port; in tb_discover_tunnels()
521 pm_runtime_get_sync(&in->sw->dev); in tb_discover_tunnels()
522 pm_runtime_get_sync(&out->sw->dev); in tb_discover_tunnels()
531 if (tb_switch_is_usb4(port->sw)) in tb_port_configure_xdomain()
538 if (tb_switch_is_usb4(port->sw)) in tb_port_unconfigure_xdomain()
543 tb_port_enable(port->dual_link_port); in tb_port_unconfigure_xdomain()
548 struct tb_switch *sw = port->sw; in tb_scan_xdomain() local
549 struct tb *tb = sw->tb; in tb_scan_xdomain()
563 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid, in tb_scan_xdomain()
566 tb_port_at(route, sw)->xdomain = xd; in tb_scan_xdomain()
573 * tb_find_unused_port() - return the first inactive port on @sw
574 * @sw: Switch to find the port on
577 static struct tb_port *tb_find_unused_port(struct tb_switch *sw, in tb_find_unused_port() argument
582 tb_switch_for_each_port(sw, port) { in tb_find_unused_port()
585 if (port->config.type != type) in tb_find_unused_port()
587 if (!port->cap_adap) in tb_find_unused_port()
596 static struct tb_port *tb_find_usb3_down(struct tb_switch *sw, in tb_find_usb3_down() argument
601 down = usb4_switch_map_usb3_down(sw, port); in tb_find_usb3_down()
614 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_find_tunnel()
615 if (tunnel->type == type && in tb_find_tunnel()
616 ((src_port && src_port == tunnel->src_port) || in tb_find_tunnel()
617 (dst_port && dst_port == tunnel->dst_port))) { in tb_find_tunnel()
630 struct tb_switch *sw; in tb_find_first_usb3_tunnel() local
634 sw = dst_port->sw; in tb_find_first_usb3_tunnel()
636 sw = src_port->sw; in tb_find_first_usb3_tunnel()
639 if (sw == tb->root_switch) in tb_find_first_usb3_tunnel()
643 port = tb_port_at(tb_route(sw), tb->root_switch); in tb_find_first_usb3_tunnel()
645 usb3_down = usb4_switch_map_usb3_down(tb->root_switch, port); in tb_find_first_usb3_tunnel()
653 * tb_consumed_usb3_pcie_bandwidth() - Consumed USB3/PCIe bandwidth over a single link
678 if (tunnel && tunnel->src_port != src_port && in tb_consumed_usb3_pcie_bandwidth()
679 tunnel->dst_port != dst_port) { in tb_consumed_usb3_pcie_bandwidth()
701 * tb_consumed_dp_bandwidth() - Consumed DP bandwidth over a single link
730 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_consumed_dp_bandwidth()
745 * re-calculating estimated bandwidth. in tb_consumed_dp_bandwidth()
747 if (tunnel->src_port == src_port && in tb_consumed_dp_bandwidth()
748 tunnel->dst_port == dst_port) in tb_consumed_dp_bandwidth()
778 * tb_maximum_banwidth() - Maximum bandwidth over a single link
808 link_speed = port->sw->link_speed; in tb_maximum_bandwidth()
810 * sw->link_width is from upstream perspective so we use in tb_maximum_bandwidth()
813 if (port->sw->link_width == TB_LINK_WIDTH_ASYM_TX) { in tb_maximum_bandwidth()
816 } else if (port->sw->link_width == TB_LINK_WIDTH_ASYM_RX) { in tb_maximum_bandwidth()
834 up_bw = link_speed * port->sw->link_width * 1000; in tb_maximum_bandwidth()
873 *max_up = up_bw - up_bw / 10; in tb_maximum_bandwidth()
874 *max_down = down_bw - down_bw / 10; in tb_maximum_bandwidth()
881 * tb_available_bandwidth() - Available bandwidth for tunneling
926 max_up -= consumed_up; in tb_available_bandwidth()
927 max_down -= consumed_down; in tb_available_bandwidth()
933 max_up -= consumed_up; in tb_available_bandwidth()
934 max_down -= consumed_down; in tb_available_bandwidth()
976 ret = tb_available_bandwidth(tb, tunnel->src_port, tunnel->dst_port, in tb_reclaim_usb3_bandwidth()
989 static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw) in tb_tunnel_usb3() argument
991 struct tb_switch *parent = tb_switch_parent(sw); in tb_tunnel_usb3()
1002 up = tb_switch_find_port(sw, TB_TYPE_USB3_UP); in tb_tunnel_usb3()
1006 if (!sw->link_usb4) in tb_tunnel_usb3()
1013 port = tb_switch_downstream_port(sw); in tb_tunnel_usb3()
1046 ret = -ENOMEM; in tb_tunnel_usb3()
1053 ret = -EIO; in tb_tunnel_usb3()
1057 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_tunnel_usb3()
1072 static int tb_create_usb3_tunnels(struct tb_switch *sw) in tb_create_usb3_tunnels() argument
1080 if (tb_route(sw)) { in tb_create_usb3_tunnels()
1081 ret = tb_tunnel_usb3(sw->tb, sw); in tb_create_usb3_tunnels()
1086 tb_switch_for_each_port(sw, port) { in tb_create_usb3_tunnels()
1089 ret = tb_create_usb3_tunnels(port->remote->sw); in tb_create_usb3_tunnels()
1098 * tb_configure_asym() - Transition links to asymmetric if needed
1116 struct tb_switch *sw; in tb_configure_asym() local
1128 sw = dst_port->sw; in tb_configure_asym()
1130 sw = src_port->sw; in tb_configure_asym()
1132 clx = tb_disable_clx(sw); in tb_configure_asym()
1146 * (40G - guard band 10%), and the requested is above in tb_configure_asym()
1150 ret = -ENOBUFS; in tb_configure_asym()
1161 ret = -ENOBUFS; in tb_configure_asym()
1170 if (up->sw->link_width == width) in tb_configure_asym()
1176 tb_sw_dbg(up->sw, "configuring asymmetric link\n"); in tb_configure_asym()
1182 ret = tb_switch_set_link_width(up->sw, width); in tb_configure_asym()
1184 tb_sw_warn(up->sw, "failed to set link width\n"); in tb_configure_asym()
1189 /* Re-enable CL states if they were previosly enabled */ in tb_configure_asym()
1191 tb_enable_clx(sw); in tb_configure_asym()
1197 * tb_configure_sym() - Transition links to symmetric if possible
1212 struct tb_switch *sw; in tb_configure_sym() local
1224 sw = dst_port->sw; in tb_configure_sym()
1226 sw = src_port->sw; in tb_configure_sym()
1228 clx = tb_disable_clx(sw); in tb_configure_sym()
1234 if (up->sw->link_width <= TB_LINK_WIDTH_DUAL) in tb_configure_sym()
1237 if (up->sw->is_unplugged) in tb_configure_sym()
1259 if (up->sw->link_width == TB_LINK_WIDTH_DUAL) 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()
1271 /* Re-enable CL states if they were previosly enabled */ 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()
1284 down->remote = up; in tb_configure_link()
1285 up->remote = down; in tb_configure_link()
1286 if (down->dual_link_port && up->dual_link_port) { in tb_configure_link()
1287 down->dual_link_port->remote = up->dual_link_port; in tb_configure_link()
1288 up->dual_link_port->remote = down->dual_link_port; 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()
1319 * tb_scan_switch() - scan for and initialize downstream switches
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()
1335 * tb_scan_port() - check for and initialize switches below port
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()
1355 if (port->config.type != TB_TYPE_PORT) in tb_scan_port()
1357 if (port->dual_link_port && port->link_nr) in tb_scan_port()
1363 if (port->usb4) in tb_scan_port()
1364 pm_runtime_get_sync(&port->usb4->dev); in tb_scan_port()
1368 if (port->remote) { in tb_scan_port()
1373 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev, in tb_scan_port()
1375 if (IS_ERR(sw)) { in tb_scan_port()
1387 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL) in tb_scan_port()
1392 if (tb_switch_configure(sw)) { in tb_scan_port()
1393 tb_switch_put(sw); in tb_scan_port()
1401 if (port->xdomain) { in tb_scan_port()
1402 tb_xdomain_remove(port->xdomain); in tb_scan_port()
1404 port->xdomain = NULL; in tb_scan_port()
1412 if (!tcm->hotplug_active) { in tb_scan_port()
1413 dev_set_uevent_suppress(&sw->dev, true); in tb_scan_port()
1419 * can support runtime PM. in tb_scan_port()
1421 sw->rpm = sw->generation > 1; in tb_scan_port()
1423 if (tb_switch_add(sw)) { in tb_scan_port()
1424 tb_switch_put(sw); in tb_scan_port()
1428 upstream_port = tb_upstream_port(sw); in tb_scan_port()
1429 tb_configure_link(port, upstream_port, sw); in tb_scan_port()
1444 tb_sw_dbg(sw, "discovery, not touching CL states\n"); in tb_scan_port()
1445 else if (tb_enable_clx(sw)) in tb_scan_port()
1446 tb_sw_warn(sw, "failed to enable CL states\n"); in tb_scan_port()
1448 if (tb_enable_tmu(sw)) in tb_scan_port()
1449 tb_sw_warn(sw, "failed to enable TMU\n"); in tb_scan_port()
1455 tb_switch_configuration_valid(sw); in tb_scan_port()
1466 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw)) in tb_scan_port()
1467 tb_sw_warn(sw, "USB3 tunnel creation failed\n"); in tb_scan_port()
1469 tb_add_dp_resources(sw); in tb_scan_port()
1470 tb_scan_switch(sw); in tb_scan_port()
1473 if (port->usb4) { in tb_scan_port()
1474 pm_runtime_mark_last_busy(&port->usb4->dev); in tb_scan_port()
1475 pm_runtime_put_autosuspend(&port->usb4->dev); in tb_scan_port()
1488 list_del(&tunnel->list); in tb_deactivate_and_free_tunnel()
1490 tb = tunnel->tb; in tb_deactivate_and_free_tunnel()
1491 src_port = tunnel->src_port; in tb_deactivate_and_free_tunnel()
1492 dst_port = tunnel->dst_port; in tb_deactivate_and_free_tunnel()
1494 switch (tunnel->type) { in tb_deactivate_and_free_tunnel()
1501 tb_switch_dealloc_dp_resource(src_port->sw, src_port); in tb_deactivate_and_free_tunnel()
1508 pm_runtime_mark_last_busy(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
1509 pm_runtime_put_autosuspend(&dst_port->sw->dev); in tb_deactivate_and_free_tunnel()
1510 pm_runtime_mark_last_busy(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
1511 pm_runtime_put_autosuspend(&src_port->sw->dev); in tb_deactivate_and_free_tunnel()
1530 * tb_free_invalid_tunnels() - destroy tunnels of devices that have gone away
1538 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) { in tb_free_invalid_tunnels()
1545 * tb_free_unplugged_children() - traverse hierarchy and free unplugged switches
1547 static void tb_free_unplugged_children(struct tb_switch *sw) in tb_free_unplugged_children() argument
1551 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_children()
1555 if (port->remote->sw->is_unplugged) { in tb_free_unplugged_children()
1557 tb_remove_dp_resources(port->remote->sw); in tb_free_unplugged_children()
1558 tb_switch_unconfigure_link(port->remote->sw); in tb_free_unplugged_children()
1559 tb_switch_set_link_width(port->remote->sw, in tb_free_unplugged_children()
1561 tb_switch_remove(port->remote->sw); in tb_free_unplugged_children()
1562 port->remote = NULL; in tb_free_unplugged_children()
1563 if (port->dual_link_port) in tb_free_unplugged_children()
1564 port->dual_link_port->remote = NULL; in tb_free_unplugged_children()
1566 tb_free_unplugged_children(port->remote->sw); in tb_free_unplugged_children()
1571 static struct tb_port *tb_find_pcie_down(struct tb_switch *sw, in tb_find_pcie_down() argument
1580 if (tb_switch_is_usb4(sw)) { in tb_find_pcie_down()
1581 down = usb4_switch_map_pcie_down(sw, port); in tb_find_pcie_down()
1582 } else if (!tb_route(sw)) { in tb_find_pcie_down()
1583 int phy_port = tb_phy_port_from_link(port->port); in tb_find_pcie_down()
1587 * Hard-coded Thunderbolt port to PCIe down port mapping in tb_find_pcie_down()
1590 if (tb_switch_is_cactus_ridge(sw) || in tb_find_pcie_down()
1591 tb_switch_is_alpine_ridge(sw)) in tb_find_pcie_down()
1593 else if (tb_switch_is_falcon_ridge(sw)) in tb_find_pcie_down()
1595 else if (tb_switch_is_titan_ridge(sw)) in tb_find_pcie_down()
1600 /* Validate the hard-coding */ in tb_find_pcie_down()
1601 if (WARN_ON(index > sw->config.max_port_number)) in tb_find_pcie_down()
1604 down = &sw->ports[index]; in tb_find_pcie_down()
1617 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN); in tb_find_pcie_down()
1624 struct tb *tb = group->tb; in tb_recalc_estimated_bandwidth_for_group()
1628 tb_dbg(tb, "re-calculating bandwidth estimation for group %u\n", in tb_recalc_estimated_bandwidth_for_group()
1629 group->index); in tb_recalc_estimated_bandwidth_for_group()
1632 list_for_each_entry(in, &group->ports, group_list) { in tb_recalc_estimated_bandwidth_for_group()
1654 first_tunnel->src_port, first_tunnel->dst_port); in tb_recalc_estimated_bandwidth_for_group()
1662 out = tunnel->dst_port; in tb_recalc_estimated_bandwidth_for_group()
1667 "failed to re-calculate estimated bandwidth\n"); in tb_recalc_estimated_bandwidth_for_group()
1673 * - already allocated bandwidth for the DP tunnel in tb_recalc_estimated_bandwidth_for_group()
1674 * - available bandwidth along the path in tb_recalc_estimated_bandwidth_for_group()
1675 * - bandwidth allocated for USB 3.x but not used. in tb_recalc_estimated_bandwidth_for_group()
1677 tb_port_dbg(in, "re-calculated estimated bandwidth %u/%u Mb/s\n", in tb_recalc_estimated_bandwidth_for_group()
1690 tb_reclaim_usb3_bandwidth(tb, first_tunnel->src_port, in tb_recalc_estimated_bandwidth_for_group()
1691 first_tunnel->dst_port); in tb_recalc_estimated_bandwidth_for_group()
1693 tb_dbg(tb, "bandwidth estimation for group %u done\n", group->index); in tb_recalc_estimated_bandwidth_for_group()
1701 tb_dbg(tb, "bandwidth consumption changed, re-calculating estimated bandwidth\n"); in tb_recalc_estimated_bandwidth()
1703 for (i = 0; i < ARRAY_SIZE(tcm->groups); i++) { in tb_recalc_estimated_bandwidth()
1704 struct tb_bandwidth_group *group = &tcm->groups[i]; in tb_recalc_estimated_bandwidth()
1706 if (!list_empty(&group->ports)) in tb_recalc_estimated_bandwidth()
1710 tb_dbg(tb, "bandwidth re-calculation done\n"); in tb_recalc_estimated_bandwidth()
1718 host_port = tb_route(in->sw) ? in tb_find_dp_out()
1719 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL; in tb_find_dp_out()
1721 list_for_each_entry(port, &tcm->dp_resources, list) { in tb_find_dp_out()
1726 tb_port_dbg(port, "DP OUT in use\n"); in tb_find_dp_out()
1736 if (host_port && tb_route(port->sw)) { in tb_find_dp_out()
1739 p = tb_port_at(tb_route(port->sw), tb->root_switch); in tb_find_dp_out()
1765 list_for_each_entry(tunnel, &tcm->tunnel_list, list) { in tb_tunnel_one_dp()
1780 pm_runtime_get_sync(&in->sw->dev); in tb_tunnel_one_dp()
1781 pm_runtime_get_sync(&out->sw->dev); in tb_tunnel_one_dp()
1783 if (tb_switch_alloc_dp_resource(in->sw, in)) { in tb_tunnel_one_dp()
1823 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_tunnel_one_dp()
1851 tb_switch_dealloc_dp_resource(in->sw, in); in tb_tunnel_one_dp()
1853 pm_runtime_mark_last_busy(&out->sw->dev); in tb_tunnel_one_dp()
1854 pm_runtime_put_autosuspend(&out->sw->dev); in tb_tunnel_one_dp()
1855 pm_runtime_mark_last_busy(&in->sw->dev); in tb_tunnel_one_dp()
1856 pm_runtime_put_autosuspend(&in->sw->dev); in tb_tunnel_one_dp()
1875 tb_dbg(tb, "looking for DP IN <-> DP OUT pairs:\n"); in tb_tunnel_dp()
1879 list_for_each_entry(port, &tcm->dp_resources, list) { in tb_tunnel_dp()
1884 tb_port_dbg(port, "DP IN in use\n"); in tb_tunnel_dp()
1904 struct tb_switch *sw = port->sw; in tb_enter_redrive() local
1906 if (!(sw->quirks & QUIRK_KEEP_POWER_IN_DP_REDRIVE)) in tb_enter_redrive()
1910 * If we get hot-unplug for the DP IN port of the host router in tb_enter_redrive()
1912 * is a monitor connected directly to the Type-C port and we are in tb_enter_redrive()
1914 * we bump up the runtime PM reference count here. in tb_enter_redrive()
1918 if (tb_route(sw)) in tb_enter_redrive()
1920 if (!tb_switch_query_dp_resource(sw, port)) { in tb_enter_redrive()
1921 port->redrive = true; in tb_enter_redrive()
1922 pm_runtime_get(&sw->dev); in tb_enter_redrive()
1929 struct tb_switch *sw = port->sw; in tb_exit_redrive() local
1931 if (!(sw->quirks & QUIRK_KEEP_POWER_IN_DP_REDRIVE)) in tb_exit_redrive()
1936 if (tb_route(sw)) in tb_exit_redrive()
1938 if (port->redrive && tb_switch_query_dp_resource(sw, port)) { in tb_exit_redrive()
1939 port->redrive = false; in tb_exit_redrive()
1940 pm_runtime_put(&sw->dev); in tb_exit_redrive()
1945 static void tb_switch_enter_redrive(struct tb_switch *sw) in tb_switch_enter_redrive() argument
1949 tb_switch_for_each_port(sw, port) in tb_switch_enter_redrive()
1957 static void tb_switch_exit_redrive(struct tb_switch *sw) in tb_switch_exit_redrive() argument
1961 if (!(sw->quirks & QUIRK_KEEP_POWER_IN_DP_REDRIVE)) in tb_switch_exit_redrive()
1964 tb_switch_for_each_port(sw, port) { in tb_switch_exit_redrive()
1968 if (port->redrive) { in tb_switch_exit_redrive()
1969 port->redrive = false; in tb_switch_exit_redrive()
1970 pm_runtime_put(&sw->dev); in tb_switch_exit_redrive()
1996 list_del_init(&port->list); in tb_dp_resource_unavailable()
2014 list_for_each_entry(p, &tcm->dp_resources, list) { in tb_dp_resource_available()
2021 list_add_tail(&port->list, &tcm->dp_resources); in tb_dp_resource_available()
2024 /* Look for suitable DP IN <-> DP OUT pairs now */ in tb_dp_resource_available()
2035 * will be re-established after resume based on plug events. in tb_disconnect_and_release_dp()
2037 list_for_each_entry_safe_reverse(tunnel, n, &tcm->tunnel_list, list) { in tb_disconnect_and_release_dp()
2042 while (!list_empty(&tcm->dp_resources)) { in tb_disconnect_and_release_dp()
2045 port = list_first_entry(&tcm->dp_resources, in tb_disconnect_and_release_dp()
2047 list_del_init(&port->list); in tb_disconnect_and_release_dp()
2051 static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw) in tb_disconnect_pci() argument
2056 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); in tb_disconnect_pci()
2058 return -ENODEV; in tb_disconnect_pci()
2062 return -ENODEV; in tb_disconnect_pci()
2064 tb_switch_xhci_disconnect(sw); in tb_disconnect_pci()
2067 list_del(&tunnel->list); in tb_disconnect_pci()
2072 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw) in tb_tunnel_pci() argument
2078 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP); in tb_tunnel_pci()
2086 port = tb_switch_downstream_port(sw); in tb_tunnel_pci()
2087 down = tb_find_pcie_down(tb_switch_parent(sw), port); in tb_tunnel_pci()
2093 return -ENOMEM; in tb_tunnel_pci()
2099 return -EIO; in tb_tunnel_pci()
2106 if (tb_switch_pcie_l1_enable(sw)) in tb_tunnel_pci()
2107 tb_sw_warn(sw, "failed to enable PCIe L1 for Titan Ridge\n"); in tb_tunnel_pci()
2109 if (tb_switch_xhci_connect(sw)) in tb_tunnel_pci()
2110 tb_sw_warn(sw, "failed to connect xHCI\n"); in tb_tunnel_pci()
2112 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_tunnel_pci()
2123 struct tb_switch *sw; in tb_approve_xdomain_paths() local
2126 sw = tb_to_switch(xd->dev.parent); in tb_approve_xdomain_paths()
2127 dst_port = tb_port_at(xd->route, sw); in tb_approve_xdomain_paths()
2128 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); in tb_approve_xdomain_paths()
2130 mutex_lock(&tb->lock); in tb_approve_xdomain_paths()
2136 tb_disable_clx(sw); in tb_approve_xdomain_paths()
2141 ret = -ENOMEM; in tb_approve_xdomain_paths()
2148 ret = -EIO; in tb_approve_xdomain_paths()
2152 list_add_tail(&tunnel->list, &tcm->tunnel_list); in tb_approve_xdomain_paths()
2153 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
2159 tb_enable_clx(sw); in tb_approve_xdomain_paths()
2160 mutex_unlock(&tb->lock); in tb_approve_xdomain_paths()
2172 struct tb_switch *sw; in __tb_disconnect_xdomain_paths() local
2174 sw = tb_to_switch(xd->dev.parent); in __tb_disconnect_xdomain_paths()
2175 dst_port = tb_port_at(xd->route, sw); in __tb_disconnect_xdomain_paths()
2176 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI); in __tb_disconnect_xdomain_paths()
2178 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) { in __tb_disconnect_xdomain_paths()
2181 if (tunnel->src_port != nhi_port || tunnel->dst_port != dst_port) in __tb_disconnect_xdomain_paths()
2190 * Try to re-enable CL states now, it is OK if this fails in __tb_disconnect_xdomain_paths()
2194 tb_enable_clx(sw); in __tb_disconnect_xdomain_paths()
2201 if (!xd->is_unplugged) { in tb_disconnect_xdomain_paths()
2202 mutex_lock(&tb->lock); in tb_disconnect_xdomain_paths()
2206 mutex_unlock(&tb->lock); in tb_disconnect_xdomain_paths()
2214 * tb_handle_hotplug() - handle hotplug event
2216 * Executes on tb->wq.
2221 struct tb *tb = ev->tb; in tb_handle_hotplug()
2223 struct tb_switch *sw; in tb_handle_hotplug() local
2227 pm_runtime_get_sync(&tb->dev); in tb_handle_hotplug()
2229 mutex_lock(&tb->lock); in tb_handle_hotplug()
2230 if (!tcm->hotplug_active) in tb_handle_hotplug()
2233 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_hotplug()
2234 if (!sw) { in tb_handle_hotplug()
2237 ev->route, ev->port, ev->unplug); in tb_handle_hotplug()
2240 if (ev->port > sw->config.max_port_number) { in tb_handle_hotplug()
2243 ev->route, ev->port, ev->unplug); in tb_handle_hotplug()
2246 port = &sw->ports[ev->port]; in tb_handle_hotplug()
2249 ev->route, ev->port, ev->unplug); in tb_handle_hotplug()
2253 pm_runtime_get_sync(&sw->dev); in tb_handle_hotplug()
2255 if (ev->unplug) { in tb_handle_hotplug()
2260 tb_sw_set_unplugged(port->remote->sw); in tb_handle_hotplug()
2262 tb_remove_dp_resources(port->remote->sw); in tb_handle_hotplug()
2263 tb_switch_tmu_disable(port->remote->sw); in tb_handle_hotplug()
2264 tb_switch_unconfigure_link(port->remote->sw); in tb_handle_hotplug()
2265 tb_switch_set_link_width(port->remote->sw, in tb_handle_hotplug()
2267 tb_switch_remove(port->remote->sw); in tb_handle_hotplug()
2268 port->remote = NULL; in tb_handle_hotplug()
2269 if (port->dual_link_port) in tb_handle_hotplug()
2270 port->dual_link_port->remote = NULL; in tb_handle_hotplug()
2274 } else if (port->xdomain) { in tb_handle_hotplug()
2275 struct tb_xdomain *xd = tb_xdomain_get(port->xdomain); in tb_handle_hotplug()
2285 xd->is_unplugged = true; in tb_handle_hotplug()
2287 port->xdomain = NULL; in tb_handle_hotplug()
2288 __tb_disconnect_xdomain_paths(tb, xd, -1, -1, -1, -1); in tb_handle_hotplug()
2293 } else if (!port->port) { in tb_handle_hotplug()
2294 tb_sw_dbg(sw, "xHCI disconnect request\n"); in tb_handle_hotplug()
2295 tb_switch_xhci_disconnect(sw); in tb_handle_hotplug()
2300 } else if (port->remote) { in tb_handle_hotplug()
2302 } else if (!port->port && sw->authorized) { in tb_handle_hotplug()
2303 tb_sw_dbg(sw, "xHCI connect request\n"); in tb_handle_hotplug()
2304 tb_switch_xhci_connect(sw); in tb_handle_hotplug()
2309 if (!port->remote) in tb_handle_hotplug()
2316 pm_runtime_mark_last_busy(&sw->dev); in tb_handle_hotplug()
2317 pm_runtime_put_autosuspend(&sw->dev); in tb_handle_hotplug()
2320 tb_switch_put(sw); in tb_handle_hotplug()
2322 mutex_unlock(&tb->lock); in tb_handle_hotplug()
2324 pm_runtime_mark_last_busy(&tb->dev); in tb_handle_hotplug()
2325 pm_runtime_put_autosuspend(&tb->dev); in tb_handle_hotplug()
2336 struct tb *tb = tunnel->tb; in tb_alloc_dp_bandwidth()
2343 in = tunnel->src_port; in tb_alloc_dp_bandwidth()
2344 out = tunnel->dst_port; in tb_alloc_dp_bandwidth()
2356 * Since the link cannot go higher than 17280 we use that in our in tb_alloc_dp_bandwidth()
2396 return -ENOBUFS; in tb_alloc_dp_bandwidth()
2428 * are also in the same group but we use the same function here in tb_alloc_dp_bandwidth()
2429 * that we use with the normal bandwidth allocation). in tb_alloc_dp_bandwidth()
2459 ret = -ENOBUFS; in tb_alloc_dp_bandwidth()
2473 struct tb *tb = ev->tb; in tb_handle_dp_bandwidth_request()
2475 struct tb_switch *sw; in tb_handle_dp_bandwidth_request() local
2477 pm_runtime_get_sync(&tb->dev); in tb_handle_dp_bandwidth_request()
2479 mutex_lock(&tb->lock); in tb_handle_dp_bandwidth_request()
2480 if (!tcm->hotplug_active) in tb_handle_dp_bandwidth_request()
2483 sw = tb_switch_find_by_route(tb, ev->route); in tb_handle_dp_bandwidth_request()
2484 if (!sw) { in tb_handle_dp_bandwidth_request()
2485 tb_warn(tb, "bandwidth request from non-existent router %llx\n", in tb_handle_dp_bandwidth_request()
2486 ev->route); in tb_handle_dp_bandwidth_request()
2490 in = &sw->ports[ev->port]; in tb_handle_dp_bandwidth_request()
2492 tb_port_warn(in, "bandwidth request to non-DP IN adapter\n"); in tb_handle_dp_bandwidth_request()
2505 if (ret == -ENODATA) in tb_handle_dp_bandwidth_request()
2521 out = tunnel->dst_port; in tb_handle_dp_bandwidth_request()
2524 requested_up = -1; in tb_handle_dp_bandwidth_request()
2528 requested_down = -1; in tb_handle_dp_bandwidth_request()
2533 if (ret == -ENOBUFS) in tb_handle_dp_bandwidth_request()
2546 tb_switch_put(sw); in tb_handle_dp_bandwidth_request()
2548 mutex_unlock(&tb->lock); in tb_handle_dp_bandwidth_request()
2550 pm_runtime_mark_last_busy(&tb->dev); in tb_handle_dp_bandwidth_request()
2551 pm_runtime_put_autosuspend(&tb->dev); in tb_handle_dp_bandwidth_request()
2564 ev->tb = tb; in tb_queue_dp_bandwidth_request()
2565 ev->route = route; in tb_queue_dp_bandwidth_request()
2566 ev->port = port; in tb_queue_dp_bandwidth_request()
2567 INIT_WORK(&ev->work, tb_handle_dp_bandwidth_request); in tb_queue_dp_bandwidth_request()
2568 queue_work(tb->wq, &ev->work); in tb_queue_dp_bandwidth_request()
2575 switch (error->error) { in tb_handle_notification()
2579 if (tb_cfg_ack_notification(tb->ctl, route, error)) in tb_handle_notification()
2585 if (tb_cfg_ack_notification(tb->ctl, route, error)) in tb_handle_notification()
2588 tb_queue_dp_bandwidth_request(tb, route, error->port); in tb_handle_notification()
2598 * tb_schedule_hotplug_handler() - callback function for the control channel
2606 u64 route = tb_cfg_get_route(&pkg->header); in tb_handle_event()
2619 if (tb_cfg_ack_plug(tb->ctl, route, pkg->port, pkg->unplug)) { in tb_handle_event()
2621 pkg->port); in tb_handle_event()
2624 tb_queue_hotplug(tb, route, pkg->port, pkg->unplug); in tb_handle_event()
2633 cancel_delayed_work(&tcm->remove_work); in tb_stop()
2635 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) { in tb_stop()
2645 tb_switch_remove(tb->root_switch); in tb_stop()
2646 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */ in tb_stop()
2652 struct tb_switch *sw = tb_to_switch(dev); in tb_scan_finalize_switch() local
2659 if (sw->boot) in tb_scan_finalize_switch()
2660 sw->authorized = 1; in tb_scan_finalize_switch()
2663 kobject_uevent(&dev->kobj, KOBJ_ADD); in tb_scan_finalize_switch()
2675 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0); in tb_start()
2676 if (IS_ERR(tb->root_switch)) in tb_start()
2677 return PTR_ERR(tb->root_switch); in tb_start()
2687 tb->root_switch->no_nvm_upgrade = !tb_switch_is_usb4(tb->root_switch); in tb_start()
2688 /* All USB4 routers support runtime PM */ in tb_start()
2689 tb->root_switch->rpm = tb_switch_is_usb4(tb->root_switch); in tb_start()
2691 ret = tb_switch_configure(tb->root_switch); in tb_start()
2693 tb_switch_put(tb->root_switch); in tb_start()
2698 ret = tb_switch_add(tb->root_switch); in tb_start()
2700 tb_switch_put(tb->root_switch); in tb_start()
2708 tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_MODE_LOWRES); in tb_start()
2710 tb_switch_tmu_enable(tb->root_switch); in tb_start()
2718 if (reset && usb4_switch_version(tb->root_switch) == 1) { in tb_start()
2719 tb_switch_reset(tb->root_switch); in tb_start()
2722 tb_scan_switch(tb->root_switch); in tb_start()
2733 tb_create_usb3_tunnels(tb->root_switch); in tb_start()
2735 tb_add_dp_resources(tb->root_switch); in tb_start()
2736 tb_switch_enter_redrive(tb->root_switch); in tb_start()
2738 device_for_each_child(&tb->root_switch->dev, NULL, in tb_start()
2742 tcm->hotplug_active = true; in tb_start()
2752 tb_switch_exit_redrive(tb->root_switch); in tb_suspend_noirq()
2753 tb_switch_suspend(tb->root_switch, false); in tb_suspend_noirq()
2754 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */ in tb_suspend_noirq()
2760 static void tb_restore_children(struct tb_switch *sw) in tb_restore_children() argument
2765 if (sw->is_unplugged) in tb_restore_children()
2768 if (tb_enable_clx(sw)) in tb_restore_children()
2769 tb_sw_warn(sw, "failed to re-enable CL states\n"); in tb_restore_children()
2771 if (tb_enable_tmu(sw)) in tb_restore_children()
2772 tb_sw_warn(sw, "failed to restore TMU configuration\n"); in tb_restore_children()
2774 tb_switch_configuration_valid(sw); in tb_restore_children()
2776 tb_switch_for_each_port(sw, port) { in tb_restore_children()
2777 if (!tb_port_has_remote(port) && !port->xdomain) in tb_restore_children()
2780 if (port->remote) { in tb_restore_children()
2781 tb_switch_set_link_width(port->remote->sw, in tb_restore_children()
2782 port->remote->sw->link_width); in tb_restore_children()
2783 tb_switch_configure_link(port->remote->sw); in tb_restore_children()
2785 tb_restore_children(port->remote->sw); in tb_restore_children()
2786 } else if (port->xdomain) { in tb_restore_children()
2787 tb_port_configure_xdomain(port, port->xdomain); in tb_restore_children()
2802 * For non-USB4 hosts (Apple systems) remove any PCIe devices in tb_resume_noirq()
2805 if (!tb_switch_is_usb4(tb->root_switch)) in tb_resume_noirq()
2806 tb_switch_reset(tb->root_switch); in tb_resume_noirq()
2808 tb_switch_resume(tb->root_switch, false); in tb_resume_noirq()
2810 tb_free_unplugged_children(tb->root_switch); in tb_resume_noirq()
2811 tb_restore_children(tb->root_switch); in tb_resume_noirq()
2819 tb_switch_discover_tunnels(tb->root_switch, &tunnels, false); in tb_resume_noirq()
2827 /* Re-create our tunnels now */ in tb_resume_noirq()
2828 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) { in tb_resume_noirq()
2829 /* USB3 requires delay before it can be re-activated */ in tb_resume_noirq()
2837 if (!list_empty(&tcm->tunnel_list)) { in tb_resume_noirq()
2845 tb_switch_enter_redrive(tb->root_switch); in tb_resume_noirq()
2847 tcm->hotplug_active = true; in tb_resume_noirq()
2853 static int tb_free_unplugged_xdomains(struct tb_switch *sw) in tb_free_unplugged_xdomains() argument
2858 tb_switch_for_each_port(sw, port) { in tb_free_unplugged_xdomains()
2861 if (port->xdomain && port->xdomain->is_unplugged) { in tb_free_unplugged_xdomains()
2863 tb_xdomain_remove(port->xdomain); in tb_free_unplugged_xdomains()
2865 port->xdomain = NULL; in tb_free_unplugged_xdomains()
2867 } else if (port->remote) { in tb_free_unplugged_xdomains()
2868 ret += tb_free_unplugged_xdomains(port->remote->sw); in tb_free_unplugged_xdomains()
2879 tcm->hotplug_active = false; in tb_freeze_noirq()
2887 tcm->hotplug_active = true; in tb_thaw_noirq()
2898 mutex_lock(&tb->lock); in tb_complete()
2899 if (tb_free_unplugged_xdomains(tb->root_switch)) in tb_complete()
2900 tb_scan_switch(tb->root_switch); in tb_complete()
2901 mutex_unlock(&tb->lock); in tb_complete()
2908 mutex_lock(&tb->lock); in tb_runtime_suspend()
2911 * re-entering redrive mode. in tb_runtime_suspend()
2914 tb_switch_exit_redrive(tb->root_switch); in tb_runtime_suspend()
2915 tb_switch_suspend(tb->root_switch, true); in tb_runtime_suspend()
2916 tcm->hotplug_active = false; in tb_runtime_suspend()
2917 mutex_unlock(&tb->lock); in tb_runtime_suspend()
2927 mutex_lock(&tb->lock); in tb_remove_work()
2928 if (tb->root_switch) { in tb_remove_work()
2929 tb_free_unplugged_children(tb->root_switch); in tb_remove_work()
2930 tb_free_unplugged_xdomains(tb->root_switch); in tb_remove_work()
2932 mutex_unlock(&tb->lock); in tb_remove_work()
2940 mutex_lock(&tb->lock); in tb_runtime_resume()
2941 tb_switch_resume(tb->root_switch, true); in tb_runtime_resume()
2943 tb_restore_children(tb->root_switch); in tb_runtime_resume()
2944 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) in tb_runtime_resume()
2946 tb_switch_enter_redrive(tb->root_switch); in tb_runtime_resume()
2947 tcm->hotplug_active = true; in tb_runtime_resume()
2948 mutex_unlock(&tb->lock); in tb_runtime_resume()
2955 queue_delayed_work(tb->wq, &tcm->remove_work, msecs_to_jiffies(50)); in tb_runtime_resume()
2991 switch (nhi->pdev->device) { in tb_apple_add_links()
3001 upstream = pci_upstream_bridge(nhi->pdev); in tb_apple_add_links()
3015 * back to NHI so that PCIe tunnels can be re-established after in tb_apple_add_links()
3019 for_each_pci_bridge(pdev, upstream->subordinate) { in tb_apple_add_links()
3025 !pdev->is_hotplug_bridge) in tb_apple_add_links()
3028 link = device_link_add(&pdev->dev, &nhi->pdev->dev, in tb_apple_add_links()
3032 dev_dbg(&nhi->pdev->dev, "created link from %s\n", in tb_apple_add_links()
3033 dev_name(&pdev->dev)); in tb_apple_add_links()
3036 dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n", in tb_apple_add_links()
3037 dev_name(&pdev->dev)); in tb_apple_add_links()
3054 tb->security_level = TB_SECURITY_USER; in tb_probe()
3056 tb->security_level = TB_SECURITY_NOPCIE; in tb_probe()
3058 tb->cm_ops = &tb_cm_ops; in tb_probe()
3061 INIT_LIST_HEAD(&tcm->tunnel_list); in tb_probe()
3062 INIT_LIST_HEAD(&tcm->dp_resources); in tb_probe()
3063 INIT_DELAYED_WORK(&tcm->remove_work, tb_remove_work); in tb_probe()