1 // SPDX-License-Identifier: GPL-2.0
3 * Thunderbolt driver - bus logic (NHI independent)
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6 * Copyright (C) 2019, Intel Corporation
9 #include <linux/slab.h>
10 #include <linux/errno.h>
11 #include <linux/delay.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/platform_data/x86/apple.h>
19 #define TB_TIMEOUT 100 /* ms */
22 * struct tb_cm - Simple Thunderbolt connection manager
23 * @tunnel_list: List of active tunnels
24 * @dp_resources: List of available DP resources for DP tunneling
25 * @hotplug_active: tb_handle_hotplug will stop progressing plug
26 * events and exit if this is not set (it needs to
27 * acquire the lock one more time). Used to drain wq
28 * after cfg has been paused.
29 * @remove_work: Work used to remove any unplugged routers after
33 struct list_head tunnel_list;
34 struct list_head dp_resources;
36 struct delayed_work remove_work;
39 static inline struct tb *tcm_to_tb(struct tb_cm *tcm)
41 return ((void *)tcm - sizeof(struct tb));
44 struct tb_hotplug_event {
45 struct work_struct work;
52 static void tb_handle_hotplug(struct work_struct *work);
54 static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug)
56 struct tb_hotplug_event *ev;
58 ev = kmalloc(sizeof(*ev), GFP_KERNEL);
66 INIT_WORK(&ev->work, tb_handle_hotplug);
67 queue_work(tb->wq, &ev->work);
70 /* enumeration & hot plug handling */
72 static void tb_add_dp_resources(struct tb_switch *sw)
74 struct tb_cm *tcm = tb_priv(sw->tb);
77 tb_switch_for_each_port(sw, port) {
78 if (!tb_port_is_dpin(port))
81 if (!tb_switch_query_dp_resource(sw, port))
84 list_add_tail(&port->list, &tcm->dp_resources);
85 tb_port_dbg(port, "DP IN resource available\n");
89 static void tb_remove_dp_resources(struct tb_switch *sw)
91 struct tb_cm *tcm = tb_priv(sw->tb);
92 struct tb_port *port, *tmp;
94 /* Clear children resources first */
95 tb_switch_for_each_port(sw, port) {
96 if (tb_port_has_remote(port))
97 tb_remove_dp_resources(port->remote->sw);
100 list_for_each_entry_safe(port, tmp, &tcm->dp_resources, list) {
101 if (port->sw == sw) {
102 tb_port_dbg(port, "DP OUT resource unavailable\n");
103 list_del_init(&port->list);
108 static void tb_switch_discover_tunnels(struct tb_switch *sw,
109 struct list_head *list,
112 struct tb *tb = sw->tb;
113 struct tb_port *port;
115 tb_switch_for_each_port(sw, port) {
116 struct tb_tunnel *tunnel = NULL;
118 switch (port->config.type) {
119 case TB_TYPE_DP_HDMI_IN:
120 tunnel = tb_tunnel_discover_dp(tb, port, alloc_hopids);
122 * In case of DP tunnel exists, change host router's
123 * 1st children TMU mode to HiFi for CL0s to work.
126 tb_switch_enable_tmu_1st_child(tb->root_switch,
127 TB_SWITCH_TMU_RATE_HIFI);
130 case TB_TYPE_PCIE_DOWN:
131 tunnel = tb_tunnel_discover_pci(tb, port, alloc_hopids);
134 case TB_TYPE_USB3_DOWN:
135 tunnel = tb_tunnel_discover_usb3(tb, port, alloc_hopids);
143 list_add_tail(&tunnel->list, list);
146 tb_switch_for_each_port(sw, port) {
147 if (tb_port_has_remote(port)) {
148 tb_switch_discover_tunnels(port->remote->sw, list,
154 static void tb_discover_tunnels(struct tb *tb)
156 struct tb_cm *tcm = tb_priv(tb);
157 struct tb_tunnel *tunnel;
159 tb_switch_discover_tunnels(tb->root_switch, &tcm->tunnel_list, true);
161 list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
162 if (tb_tunnel_is_pci(tunnel)) {
163 struct tb_switch *parent = tunnel->dst_port->sw;
165 while (parent != tunnel->src_port->sw) {
167 parent = tb_switch_parent(parent);
169 } else if (tb_tunnel_is_dp(tunnel)) {
170 /* Keep the domain from powering down */
171 pm_runtime_get_sync(&tunnel->src_port->sw->dev);
172 pm_runtime_get_sync(&tunnel->dst_port->sw->dev);
177 static int tb_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd)
179 if (tb_switch_is_usb4(port->sw))
180 return usb4_port_configure_xdomain(port, xd);
181 return tb_lc_configure_xdomain(port);
184 static void tb_port_unconfigure_xdomain(struct tb_port *port)
186 if (tb_switch_is_usb4(port->sw))
187 usb4_port_unconfigure_xdomain(port);
189 tb_lc_unconfigure_xdomain(port);
191 tb_port_enable(port->dual_link_port);
194 static void tb_scan_xdomain(struct tb_port *port)
196 struct tb_switch *sw = port->sw;
197 struct tb *tb = sw->tb;
198 struct tb_xdomain *xd;
201 if (!tb_is_xdomain_enabled())
204 route = tb_downstream_route(port);
205 xd = tb_xdomain_find_by_route(tb, route);
211 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid,
214 tb_port_at(route, sw)->xdomain = xd;
215 tb_port_configure_xdomain(port, xd);
220 static int tb_enable_tmu(struct tb_switch *sw)
224 /* If it is already enabled in correct mode, don't touch it */
225 if (tb_switch_tmu_is_enabled(sw, sw->tmu.unidirectional_request))
228 ret = tb_switch_tmu_disable(sw);
232 ret = tb_switch_tmu_post_time(sw);
236 return tb_switch_tmu_enable(sw);
240 * tb_find_unused_port() - return the first inactive port on @sw
241 * @sw: Switch to find the port on
242 * @type: Port type to look for
244 static struct tb_port *tb_find_unused_port(struct tb_switch *sw,
245 enum tb_port_type type)
247 struct tb_port *port;
249 tb_switch_for_each_port(sw, port) {
250 if (tb_is_upstream_port(port))
252 if (port->config.type != type)
256 if (tb_port_is_enabled(port))
263 static struct tb_port *tb_find_usb3_down(struct tb_switch *sw,
264 const struct tb_port *port)
266 struct tb_port *down;
268 down = usb4_switch_map_usb3_down(sw, port);
269 if (down && !tb_usb3_port_is_enabled(down))
274 static struct tb_tunnel *tb_find_tunnel(struct tb *tb, enum tb_tunnel_type type,
275 struct tb_port *src_port,
276 struct tb_port *dst_port)
278 struct tb_cm *tcm = tb_priv(tb);
279 struct tb_tunnel *tunnel;
281 list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
282 if (tunnel->type == type &&
283 ((src_port && src_port == tunnel->src_port) ||
284 (dst_port && dst_port == tunnel->dst_port))) {
292 static struct tb_tunnel *tb_find_first_usb3_tunnel(struct tb *tb,
293 struct tb_port *src_port,
294 struct tb_port *dst_port)
296 struct tb_port *port, *usb3_down;
297 struct tb_switch *sw;
299 /* Pick the router that is deepest in the topology */
300 if (dst_port->sw->config.depth > src_port->sw->config.depth)
305 /* Can't be the host router */
306 if (sw == tb->root_switch)
309 /* Find the downstream USB4 port that leads to this router */
310 port = tb_port_at(tb_route(sw), tb->root_switch);
311 /* Find the corresponding host router USB3 downstream port */
312 usb3_down = usb4_switch_map_usb3_down(tb->root_switch, port);
316 return tb_find_tunnel(tb, TB_TUNNEL_USB3, usb3_down, NULL);
319 static int tb_available_bandwidth(struct tb *tb, struct tb_port *src_port,
320 struct tb_port *dst_port, int *available_up, int *available_down)
322 int usb3_consumed_up, usb3_consumed_down, ret;
323 struct tb_cm *tcm = tb_priv(tb);
324 struct tb_tunnel *tunnel;
325 struct tb_port *port;
327 tb_port_dbg(dst_port, "calculating available bandwidth\n");
329 tunnel = tb_find_first_usb3_tunnel(tb, src_port, dst_port);
331 ret = tb_tunnel_consumed_bandwidth(tunnel, &usb3_consumed_up,
332 &usb3_consumed_down);
336 usb3_consumed_up = 0;
337 usb3_consumed_down = 0;
340 *available_up = *available_down = 40000;
342 /* Find the minimum available bandwidth over all links */
343 tb_for_each_port_on_path(src_port, dst_port, port) {
344 int link_speed, link_width, up_bw, down_bw;
346 if (!tb_port_is_null(port))
349 if (tb_is_upstream_port(port)) {
350 link_speed = port->sw->link_speed;
352 link_speed = tb_port_get_link_speed(port);
357 link_width = port->bonded ? 2 : 1;
359 up_bw = link_speed * link_width * 1000; /* Mb/s */
360 /* Leave 10% guard band */
364 tb_port_dbg(port, "link total bandwidth %d Mb/s\n", up_bw);
367 * Find all DP tunnels that cross the port and reduce
368 * their consumed bandwidth from the available.
370 list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
371 int dp_consumed_up, dp_consumed_down;
373 if (!tb_tunnel_is_dp(tunnel))
376 if (!tb_tunnel_port_on_path(tunnel, port))
379 ret = tb_tunnel_consumed_bandwidth(tunnel,
385 up_bw -= dp_consumed_up;
386 down_bw -= dp_consumed_down;
390 * If USB3 is tunneled from the host router down to the
391 * branch leading to port we need to take USB3 consumed
392 * bandwidth into account regardless whether it actually
395 up_bw -= usb3_consumed_up;
396 down_bw -= usb3_consumed_down;
398 if (up_bw < *available_up)
399 *available_up = up_bw;
400 if (down_bw < *available_down)
401 *available_down = down_bw;
404 if (*available_up < 0)
406 if (*available_down < 0)
412 static int tb_release_unused_usb3_bandwidth(struct tb *tb,
413 struct tb_port *src_port,
414 struct tb_port *dst_port)
416 struct tb_tunnel *tunnel;
418 tunnel = tb_find_first_usb3_tunnel(tb, src_port, dst_port);
419 return tunnel ? tb_tunnel_release_unused_bandwidth(tunnel) : 0;
422 static void tb_reclaim_usb3_bandwidth(struct tb *tb, struct tb_port *src_port,
423 struct tb_port *dst_port)
425 int ret, available_up, available_down;
426 struct tb_tunnel *tunnel;
428 tunnel = tb_find_first_usb3_tunnel(tb, src_port, dst_port);
432 tb_dbg(tb, "reclaiming unused bandwidth for USB3\n");
435 * Calculate available bandwidth for the first hop USB3 tunnel.
436 * That determines the whole USB3 bandwidth for this branch.
438 ret = tb_available_bandwidth(tb, tunnel->src_port, tunnel->dst_port,
439 &available_up, &available_down);
441 tb_warn(tb, "failed to calculate available bandwidth\n");
445 tb_dbg(tb, "available bandwidth for USB3 %d/%d Mb/s\n",
446 available_up, available_down);
448 tb_tunnel_reclaim_available_bandwidth(tunnel, &available_up, &available_down);
451 static int tb_tunnel_usb3(struct tb *tb, struct tb_switch *sw)
453 struct tb_switch *parent = tb_switch_parent(sw);
454 int ret, available_up, available_down;
455 struct tb_port *up, *down, *port;
456 struct tb_cm *tcm = tb_priv(tb);
457 struct tb_tunnel *tunnel;
459 if (!tb_acpi_may_tunnel_usb3()) {
460 tb_dbg(tb, "USB3 tunneling disabled, not creating tunnel\n");
464 up = tb_switch_find_port(sw, TB_TYPE_USB3_UP);
472 * Look up available down port. Since we are chaining it should
473 * be found right above this switch.
475 port = tb_port_at(tb_route(sw), parent);
476 down = tb_find_usb3_down(parent, port);
480 if (tb_route(parent)) {
481 struct tb_port *parent_up;
483 * Check first that the parent switch has its upstream USB3
484 * port enabled. Otherwise the chain is not complete and
485 * there is no point setting up a new tunnel.
487 parent_up = tb_switch_find_port(parent, TB_TYPE_USB3_UP);
488 if (!parent_up || !tb_port_is_enabled(parent_up))
491 /* Make all unused bandwidth available for the new tunnel */
492 ret = tb_release_unused_usb3_bandwidth(tb, down, up);
497 ret = tb_available_bandwidth(tb, down, up, &available_up,
502 tb_port_dbg(up, "available bandwidth for new USB3 tunnel %d/%d Mb/s\n",
503 available_up, available_down);
505 tunnel = tb_tunnel_alloc_usb3(tb, up, down, available_up,
512 if (tb_tunnel_activate(tunnel)) {
514 "USB3 tunnel activation failed, aborting\n");
519 list_add_tail(&tunnel->list, &tcm->tunnel_list);
520 if (tb_route(parent))
521 tb_reclaim_usb3_bandwidth(tb, down, up);
526 tb_tunnel_free(tunnel);
528 if (tb_route(parent))
529 tb_reclaim_usb3_bandwidth(tb, down, up);
534 static int tb_create_usb3_tunnels(struct tb_switch *sw)
536 struct tb_port *port;
539 if (!tb_acpi_may_tunnel_usb3())
543 ret = tb_tunnel_usb3(sw->tb, sw);
548 tb_switch_for_each_port(sw, port) {
549 if (!tb_port_has_remote(port))
551 ret = tb_create_usb3_tunnels(port->remote->sw);
559 static void tb_scan_port(struct tb_port *port);
562 * tb_scan_switch() - scan for and initialize downstream switches
564 static void tb_scan_switch(struct tb_switch *sw)
566 struct tb_port *port;
568 pm_runtime_get_sync(&sw->dev);
570 tb_switch_for_each_port(sw, port)
573 pm_runtime_mark_last_busy(&sw->dev);
574 pm_runtime_put_autosuspend(&sw->dev);
578 * tb_scan_port() - check for and initialize switches below port
580 static void tb_scan_port(struct tb_port *port)
582 struct tb_cm *tcm = tb_priv(port->sw->tb);
583 struct tb_port *upstream_port;
584 struct tb_switch *sw;
587 if (tb_is_upstream_port(port))
590 if (tb_port_is_dpout(port) && tb_dp_port_hpd_is_active(port) == 1 &&
591 !tb_dp_port_is_enabled(port)) {
592 tb_port_dbg(port, "DP adapter HPD set, queuing hotplug\n");
593 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port,
598 if (port->config.type != TB_TYPE_PORT)
600 if (port->dual_link_port && port->link_nr)
602 * Downstream switch is reachable through two ports.
603 * Only scan on the primary port (link_nr == 0).
605 if (tb_wait_for_port(port, false) <= 0)
608 tb_port_dbg(port, "port already has a remote\n");
612 tb_retimer_scan(port, true);
614 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev,
615 tb_downstream_route(port));
618 * If there is an error accessing the connected switch
619 * it may be connected to another domain. Also we allow
620 * the other domain to be connected to a max depth switch.
622 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL)
623 tb_scan_xdomain(port);
627 if (tb_switch_configure(sw)) {
633 * If there was previously another domain connected remove it
637 tb_xdomain_remove(port->xdomain);
638 tb_port_unconfigure_xdomain(port);
639 port->xdomain = NULL;
643 * Do not send uevents until we have discovered all existing
644 * tunnels and know which switches were authorized already by
647 if (!tcm->hotplug_active)
648 dev_set_uevent_suppress(&sw->dev, true);
651 * At the moment Thunderbolt 2 and beyond (devices with LC) we
652 * can support runtime PM.
654 sw->rpm = sw->generation > 1;
656 if (tb_switch_add(sw)) {
661 /* Link the switches using both links if available */
662 upstream_port = tb_upstream_port(sw);
663 port->remote = upstream_port;
664 upstream_port->remote = port;
665 if (port->dual_link_port && upstream_port->dual_link_port) {
666 port->dual_link_port->remote = upstream_port->dual_link_port;
667 upstream_port->dual_link_port->remote = port->dual_link_port;
670 /* Enable lane bonding if supported */
671 tb_switch_lane_bonding_enable(sw);
672 /* Set the link configured */
673 tb_switch_configure_link(sw);
675 * CL0s and CL1 are enabled and supported together.
676 * Silently ignore CLx enabling in case CLx is not supported.
678 ret = tb_switch_enable_clx(sw, TB_CL1);
679 if (ret && ret != -EOPNOTSUPP)
680 tb_sw_warn(sw, "failed to enable %s on upstream port\n",
681 tb_switch_clx_name(TB_CL1));
683 if (tb_switch_is_clx_enabled(sw, TB_CL1))
685 * To support highest CLx state, we set router's TMU to
688 tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true);
690 /* If CLx disabled, configure router's TMU to HiFi-Bidir mode*/
691 tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false);
693 if (tb_enable_tmu(sw))
694 tb_sw_warn(sw, "failed to enable TMU\n");
696 /* Scan upstream retimers */
697 tb_retimer_scan(upstream_port, true);
700 * Create USB 3.x tunnels only when the switch is plugged to the
701 * domain. This is because we scan the domain also during discovery
702 * and want to discover existing USB 3.x tunnels before we create
705 if (tcm->hotplug_active && tb_tunnel_usb3(sw->tb, sw))
706 tb_sw_warn(sw, "USB3 tunnel creation failed\n");
708 tb_add_dp_resources(sw);
712 static void tb_deactivate_and_free_tunnel(struct tb_tunnel *tunnel)
714 struct tb_port *src_port, *dst_port;
720 tb_tunnel_deactivate(tunnel);
721 list_del(&tunnel->list);
724 src_port = tunnel->src_port;
725 dst_port = tunnel->dst_port;
727 switch (tunnel->type) {
730 * In case of DP tunnel make sure the DP IN resource is
731 * deallocated properly.
733 tb_switch_dealloc_dp_resource(src_port->sw, src_port);
734 /* Now we can allow the domain to runtime suspend again */
735 pm_runtime_mark_last_busy(&dst_port->sw->dev);
736 pm_runtime_put_autosuspend(&dst_port->sw->dev);
737 pm_runtime_mark_last_busy(&src_port->sw->dev);
738 pm_runtime_put_autosuspend(&src_port->sw->dev);
742 tb_reclaim_usb3_bandwidth(tb, src_port, dst_port);
747 * PCIe and DMA tunnels do not consume guaranteed
753 tb_tunnel_free(tunnel);
757 * tb_free_invalid_tunnels() - destroy tunnels of devices that have gone away
759 static void tb_free_invalid_tunnels(struct tb *tb)
761 struct tb_cm *tcm = tb_priv(tb);
762 struct tb_tunnel *tunnel;
765 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
766 if (tb_tunnel_is_invalid(tunnel))
767 tb_deactivate_and_free_tunnel(tunnel);
772 * tb_free_unplugged_children() - traverse hierarchy and free unplugged switches
774 static void tb_free_unplugged_children(struct tb_switch *sw)
776 struct tb_port *port;
778 tb_switch_for_each_port(sw, port) {
779 if (!tb_port_has_remote(port))
782 if (port->remote->sw->is_unplugged) {
783 tb_retimer_remove_all(port);
784 tb_remove_dp_resources(port->remote->sw);
785 tb_switch_unconfigure_link(port->remote->sw);
786 tb_switch_lane_bonding_disable(port->remote->sw);
787 tb_switch_remove(port->remote->sw);
789 if (port->dual_link_port)
790 port->dual_link_port->remote = NULL;
792 tb_free_unplugged_children(port->remote->sw);
797 static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,
798 const struct tb_port *port)
800 struct tb_port *down = NULL;
803 * To keep plugging devices consistently in the same PCIe
804 * hierarchy, do mapping here for switch downstream PCIe ports.
806 if (tb_switch_is_usb4(sw)) {
807 down = usb4_switch_map_pcie_down(sw, port);
808 } else if (!tb_route(sw)) {
809 int phy_port = tb_phy_port_from_link(port->port);
813 * Hard-coded Thunderbolt port to PCIe down port mapping
816 if (tb_switch_is_cactus_ridge(sw) ||
817 tb_switch_is_alpine_ridge(sw))
818 index = !phy_port ? 6 : 7;
819 else if (tb_switch_is_falcon_ridge(sw))
820 index = !phy_port ? 6 : 8;
821 else if (tb_switch_is_titan_ridge(sw))
822 index = !phy_port ? 8 : 9;
826 /* Validate the hard-coding */
827 if (WARN_ON(index > sw->config.max_port_number))
830 down = &sw->ports[index];
834 if (WARN_ON(!tb_port_is_pcie_down(down)))
836 if (tb_pci_port_is_enabled(down))
843 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN);
846 static struct tb_port *tb_find_dp_out(struct tb *tb, struct tb_port *in)
848 struct tb_port *host_port, *port;
849 struct tb_cm *tcm = tb_priv(tb);
851 host_port = tb_route(in->sw) ?
852 tb_port_at(tb_route(in->sw), tb->root_switch) : NULL;
854 list_for_each_entry(port, &tcm->dp_resources, list) {
855 if (!tb_port_is_dpout(port))
858 if (tb_port_is_enabled(port)) {
859 tb_port_dbg(port, "in use\n");
863 tb_port_dbg(port, "DP OUT available\n");
866 * Keep the DP tunnel under the topology starting from
867 * the same host router downstream port.
869 if (host_port && tb_route(port->sw)) {
872 p = tb_port_at(tb_route(port->sw), tb->root_switch);
883 static void tb_tunnel_dp(struct tb *tb)
885 int available_up, available_down, ret, link_nr;
886 struct tb_cm *tcm = tb_priv(tb);
887 struct tb_port *port, *in, *out;
888 struct tb_tunnel *tunnel;
890 if (!tb_acpi_may_tunnel_dp()) {
891 tb_dbg(tb, "DP tunneling disabled, not creating tunnel\n");
896 * Find pair of inactive DP IN and DP OUT adapters and then
897 * establish a DP tunnel between them.
899 tb_dbg(tb, "looking for DP IN <-> DP OUT pairs:\n");
903 list_for_each_entry(port, &tcm->dp_resources, list) {
904 if (!tb_port_is_dpin(port))
907 if (tb_port_is_enabled(port)) {
908 tb_port_dbg(port, "in use\n");
912 tb_port_dbg(port, "DP IN available\n");
914 out = tb_find_dp_out(tb, port);
922 tb_dbg(tb, "no suitable DP IN adapter available, not tunneling\n");
926 tb_dbg(tb, "no suitable DP OUT adapter available, not tunneling\n");
931 * This is only applicable to links that are not bonded (so
932 * when Thunderbolt 1 hardware is involved somewhere in the
933 * topology). For these try to share the DP bandwidth between
937 list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
938 if (tb_tunnel_is_dp(tunnel)) {
945 * DP stream needs the domain to be active so runtime resume
946 * both ends of the tunnel.
948 * This should bring the routers in the middle active as well
949 * and keeps the domain from runtime suspending while the DP
952 pm_runtime_get_sync(&in->sw->dev);
953 pm_runtime_get_sync(&out->sw->dev);
955 if (tb_switch_alloc_dp_resource(in->sw, in)) {
956 tb_port_dbg(in, "no resource available for DP IN, not tunneling\n");
960 /* Make all unused USB3 bandwidth available for the new DP tunnel */
961 ret = tb_release_unused_usb3_bandwidth(tb, in, out);
963 tb_warn(tb, "failed to release unused bandwidth\n");
967 ret = tb_available_bandwidth(tb, in, out, &available_up,
972 tb_dbg(tb, "available bandwidth for new DP tunnel %u/%u Mb/s\n",
973 available_up, available_down);
975 tunnel = tb_tunnel_alloc_dp(tb, in, out, link_nr, available_up,
978 tb_port_dbg(out, "could not allocate DP tunnel\n");
982 if (tb_tunnel_activate(tunnel)) {
983 tb_port_info(out, "DP tunnel activation failed, aborting\n");
987 list_add_tail(&tunnel->list, &tcm->tunnel_list);
988 tb_reclaim_usb3_bandwidth(tb, in, out);
990 * In case of DP tunnel exists, change host router's 1st children
991 * TMU mode to HiFi for CL0s to work.
993 tb_switch_enable_tmu_1st_child(tb->root_switch, TB_SWITCH_TMU_RATE_HIFI);
998 tb_tunnel_free(tunnel);
1000 tb_reclaim_usb3_bandwidth(tb, in, out);
1002 tb_switch_dealloc_dp_resource(in->sw, in);
1004 pm_runtime_mark_last_busy(&out->sw->dev);
1005 pm_runtime_put_autosuspend(&out->sw->dev);
1006 pm_runtime_mark_last_busy(&in->sw->dev);
1007 pm_runtime_put_autosuspend(&in->sw->dev);
1010 static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port)
1012 struct tb_port *in, *out;
1013 struct tb_tunnel *tunnel;
1015 if (tb_port_is_dpin(port)) {
1016 tb_port_dbg(port, "DP IN resource unavailable\n");
1020 tb_port_dbg(port, "DP OUT resource unavailable\n");
1025 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, out);
1026 tb_deactivate_and_free_tunnel(tunnel);
1027 list_del_init(&port->list);
1030 * See if there is another DP OUT port that can be used for
1031 * to create another tunnel.
1036 static void tb_dp_resource_available(struct tb *tb, struct tb_port *port)
1038 struct tb_cm *tcm = tb_priv(tb);
1041 if (tb_port_is_enabled(port))
1044 list_for_each_entry(p, &tcm->dp_resources, list) {
1049 tb_port_dbg(port, "DP %s resource available\n",
1050 tb_port_is_dpin(port) ? "IN" : "OUT");
1051 list_add_tail(&port->list, &tcm->dp_resources);
1053 /* Look for suitable DP IN <-> DP OUT pairs now */
1057 static void tb_disconnect_and_release_dp(struct tb *tb)
1059 struct tb_cm *tcm = tb_priv(tb);
1060 struct tb_tunnel *tunnel, *n;
1063 * Tear down all DP tunnels and release their resources. They
1064 * will be re-established after resume based on plug events.
1066 list_for_each_entry_safe_reverse(tunnel, n, &tcm->tunnel_list, list) {
1067 if (tb_tunnel_is_dp(tunnel))
1068 tb_deactivate_and_free_tunnel(tunnel);
1071 while (!list_empty(&tcm->dp_resources)) {
1072 struct tb_port *port;
1074 port = list_first_entry(&tcm->dp_resources,
1075 struct tb_port, list);
1076 list_del_init(&port->list);
1080 static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw)
1082 struct tb_tunnel *tunnel;
1085 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
1089 tunnel = tb_find_tunnel(tb, TB_TUNNEL_PCI, NULL, up);
1090 if (WARN_ON(!tunnel))
1093 tb_switch_xhci_disconnect(sw);
1095 tb_tunnel_deactivate(tunnel);
1096 list_del(&tunnel->list);
1097 tb_tunnel_free(tunnel);
1101 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
1103 struct tb_port *up, *down, *port;
1104 struct tb_cm *tcm = tb_priv(tb);
1105 struct tb_switch *parent_sw;
1106 struct tb_tunnel *tunnel;
1108 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
1113 * Look up available down port. Since we are chaining it should
1114 * be found right above this switch.
1116 parent_sw = tb_to_switch(sw->dev.parent);
1117 port = tb_port_at(tb_route(sw), parent_sw);
1118 down = tb_find_pcie_down(parent_sw, port);
1122 tunnel = tb_tunnel_alloc_pci(tb, up, down);
1126 if (tb_tunnel_activate(tunnel)) {
1128 "PCIe tunnel activation failed, aborting\n");
1129 tb_tunnel_free(tunnel);
1134 * PCIe L1 is needed to enable CL0s for Titan Ridge so enable it
1137 if (tb_switch_pcie_l1_enable(sw))
1138 tb_sw_warn(sw, "failed to enable PCIe L1 for Titan Ridge\n");
1140 if (tb_switch_xhci_connect(sw))
1141 tb_sw_warn(sw, "failed to connect xHCI\n");
1143 list_add_tail(&tunnel->list, &tcm->tunnel_list);
1147 static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
1148 int transmit_path, int transmit_ring,
1149 int receive_path, int receive_ring)
1151 struct tb_cm *tcm = tb_priv(tb);
1152 struct tb_port *nhi_port, *dst_port;
1153 struct tb_tunnel *tunnel;
1154 struct tb_switch *sw;
1156 sw = tb_to_switch(xd->dev.parent);
1157 dst_port = tb_port_at(xd->route, sw);
1158 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI);
1160 mutex_lock(&tb->lock);
1161 tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, transmit_path,
1162 transmit_ring, receive_path, receive_ring);
1164 mutex_unlock(&tb->lock);
1168 if (tb_tunnel_activate(tunnel)) {
1169 tb_port_info(nhi_port,
1170 "DMA tunnel activation failed, aborting\n");
1171 tb_tunnel_free(tunnel);
1172 mutex_unlock(&tb->lock);
1176 list_add_tail(&tunnel->list, &tcm->tunnel_list);
1177 mutex_unlock(&tb->lock);
1181 static void __tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
1182 int transmit_path, int transmit_ring,
1183 int receive_path, int receive_ring)
1185 struct tb_cm *tcm = tb_priv(tb);
1186 struct tb_port *nhi_port, *dst_port;
1187 struct tb_tunnel *tunnel, *n;
1188 struct tb_switch *sw;
1190 sw = tb_to_switch(xd->dev.parent);
1191 dst_port = tb_port_at(xd->route, sw);
1192 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI);
1194 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
1195 if (!tb_tunnel_is_dma(tunnel))
1197 if (tunnel->src_port != nhi_port || tunnel->dst_port != dst_port)
1200 if (tb_tunnel_match_dma(tunnel, transmit_path, transmit_ring,
1201 receive_path, receive_ring))
1202 tb_deactivate_and_free_tunnel(tunnel);
1206 static int tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
1207 int transmit_path, int transmit_ring,
1208 int receive_path, int receive_ring)
1210 if (!xd->is_unplugged) {
1211 mutex_lock(&tb->lock);
1212 __tb_disconnect_xdomain_paths(tb, xd, transmit_path,
1213 transmit_ring, receive_path,
1215 mutex_unlock(&tb->lock);
1220 /* hotplug handling */
1223 * tb_handle_hotplug() - handle hotplug event
1225 * Executes on tb->wq.
1227 static void tb_handle_hotplug(struct work_struct *work)
1229 struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work);
1230 struct tb *tb = ev->tb;
1231 struct tb_cm *tcm = tb_priv(tb);
1232 struct tb_switch *sw;
1233 struct tb_port *port;
1235 /* Bring the domain back from sleep if it was suspended */
1236 pm_runtime_get_sync(&tb->dev);
1238 mutex_lock(&tb->lock);
1239 if (!tcm->hotplug_active)
1240 goto out; /* during init, suspend or shutdown */
1242 sw = tb_switch_find_by_route(tb, ev->route);
1245 "hotplug event from non existent switch %llx:%x (unplug: %d)\n",
1246 ev->route, ev->port, ev->unplug);
1249 if (ev->port > sw->config.max_port_number) {
1251 "hotplug event from non existent port %llx:%x (unplug: %d)\n",
1252 ev->route, ev->port, ev->unplug);
1255 port = &sw->ports[ev->port];
1256 if (tb_is_upstream_port(port)) {
1257 tb_dbg(tb, "hotplug event for upstream port %llx:%x (unplug: %d)\n",
1258 ev->route, ev->port, ev->unplug);
1262 pm_runtime_get_sync(&sw->dev);
1265 tb_retimer_remove_all(port);
1267 if (tb_port_has_remote(port)) {
1268 tb_port_dbg(port, "switch unplugged\n");
1269 tb_sw_set_unplugged(port->remote->sw);
1270 tb_free_invalid_tunnels(tb);
1271 tb_remove_dp_resources(port->remote->sw);
1272 tb_switch_tmu_disable(port->remote->sw);
1273 tb_switch_unconfigure_link(port->remote->sw);
1274 tb_switch_lane_bonding_disable(port->remote->sw);
1275 tb_switch_remove(port->remote->sw);
1276 port->remote = NULL;
1277 if (port->dual_link_port)
1278 port->dual_link_port->remote = NULL;
1279 /* Maybe we can create another DP tunnel */
1281 } else if (port->xdomain) {
1282 struct tb_xdomain *xd = tb_xdomain_get(port->xdomain);
1284 tb_port_dbg(port, "xdomain unplugged\n");
1286 * Service drivers are unbound during
1287 * tb_xdomain_remove() so setting XDomain as
1288 * unplugged here prevents deadlock if they call
1289 * tb_xdomain_disable_paths(). We will tear down
1290 * all the tunnels below.
1292 xd->is_unplugged = true;
1293 tb_xdomain_remove(xd);
1294 port->xdomain = NULL;
1295 __tb_disconnect_xdomain_paths(tb, xd, -1, -1, -1, -1);
1297 tb_port_unconfigure_xdomain(port);
1298 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) {
1299 tb_dp_resource_unavailable(tb, port);
1300 } else if (!port->port) {
1301 tb_sw_dbg(sw, "xHCI disconnect request\n");
1302 tb_switch_xhci_disconnect(sw);
1305 "got unplug event for disconnected port, ignoring\n");
1307 } else if (port->remote) {
1308 tb_port_dbg(port, "got plug event for connected port, ignoring\n");
1309 } else if (!port->port && sw->authorized) {
1310 tb_sw_dbg(sw, "xHCI connect request\n");
1311 tb_switch_xhci_connect(sw);
1313 if (tb_port_is_null(port)) {
1314 tb_port_dbg(port, "hotplug: scanning\n");
1317 tb_port_dbg(port, "hotplug: no switch found\n");
1318 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) {
1319 tb_dp_resource_available(tb, port);
1323 pm_runtime_mark_last_busy(&sw->dev);
1324 pm_runtime_put_autosuspend(&sw->dev);
1329 mutex_unlock(&tb->lock);
1331 pm_runtime_mark_last_busy(&tb->dev);
1332 pm_runtime_put_autosuspend(&tb->dev);
1338 * tb_schedule_hotplug_handler() - callback function for the control channel
1340 * Delegates to tb_handle_hotplug.
1342 static void tb_handle_event(struct tb *tb, enum tb_cfg_pkg_type type,
1343 const void *buf, size_t size)
1345 const struct cfg_event_pkg *pkg = buf;
1348 if (type != TB_CFG_PKG_EVENT) {
1349 tb_warn(tb, "unexpected event %#x, ignoring\n", type);
1353 route = tb_cfg_get_route(&pkg->header);
1355 if (tb_cfg_ack_plug(tb->ctl, route, pkg->port, pkg->unplug)) {
1356 tb_warn(tb, "could not ack plug event on %llx:%x\n", route,
1360 tb_queue_hotplug(tb, route, pkg->port, pkg->unplug);
1363 static void tb_stop(struct tb *tb)
1365 struct tb_cm *tcm = tb_priv(tb);
1366 struct tb_tunnel *tunnel;
1367 struct tb_tunnel *n;
1369 cancel_delayed_work(&tcm->remove_work);
1370 /* tunnels are only present after everything has been initialized */
1371 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
1373 * DMA tunnels require the driver to be functional so we
1374 * tear them down. Other protocol tunnels can be left
1377 if (tb_tunnel_is_dma(tunnel))
1378 tb_tunnel_deactivate(tunnel);
1379 tb_tunnel_free(tunnel);
1381 tb_switch_remove(tb->root_switch);
1382 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */
1385 static int tb_scan_finalize_switch(struct device *dev, void *data)
1387 if (tb_is_switch(dev)) {
1388 struct tb_switch *sw = tb_to_switch(dev);
1391 * If we found that the switch was already setup by the
1392 * boot firmware, mark it as authorized now before we
1393 * send uevent to userspace.
1398 dev_set_uevent_suppress(dev, false);
1399 kobject_uevent(&dev->kobj, KOBJ_ADD);
1400 device_for_each_child(dev, NULL, tb_scan_finalize_switch);
1406 static int tb_start(struct tb *tb)
1408 struct tb_cm *tcm = tb_priv(tb);
1411 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0);
1412 if (IS_ERR(tb->root_switch))
1413 return PTR_ERR(tb->root_switch);
1416 * ICM firmware upgrade needs running firmware and in native
1417 * mode that is not available so disable firmware upgrade of the
1420 tb->root_switch->no_nvm_upgrade = true;
1421 /* All USB4 routers support runtime PM */
1422 tb->root_switch->rpm = tb_switch_is_usb4(tb->root_switch);
1424 ret = tb_switch_configure(tb->root_switch);
1426 tb_switch_put(tb->root_switch);
1430 /* Announce the switch to the world */
1431 ret = tb_switch_add(tb->root_switch);
1433 tb_switch_put(tb->root_switch);
1438 * To support highest CLx state, we set host router's TMU to
1441 tb_switch_tmu_configure(tb->root_switch, TB_SWITCH_TMU_RATE_NORMAL,
1443 /* Enable TMU if it is off */
1444 tb_switch_tmu_enable(tb->root_switch);
1445 /* Full scan to discover devices added before the driver was loaded. */
1446 tb_scan_switch(tb->root_switch);
1447 /* Find out tunnels created by the boot firmware */
1448 tb_discover_tunnels(tb);
1450 * If the boot firmware did not create USB 3.x tunnels create them
1451 * now for the whole topology.
1453 tb_create_usb3_tunnels(tb->root_switch);
1454 /* Add DP IN resources for the root switch */
1455 tb_add_dp_resources(tb->root_switch);
1456 /* Make the discovered switches available to the userspace */
1457 device_for_each_child(&tb->root_switch->dev, NULL,
1458 tb_scan_finalize_switch);
1460 /* Allow tb_handle_hotplug to progress events */
1461 tcm->hotplug_active = true;
1465 static int tb_suspend_noirq(struct tb *tb)
1467 struct tb_cm *tcm = tb_priv(tb);
1469 tb_dbg(tb, "suspending...\n");
1470 tb_disconnect_and_release_dp(tb);
1471 tb_switch_suspend(tb->root_switch, false);
1472 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */
1473 tb_dbg(tb, "suspend finished\n");
1478 static void tb_restore_children(struct tb_switch *sw)
1480 struct tb_port *port;
1483 /* No need to restore if the router is already unplugged */
1484 if (sw->is_unplugged)
1488 * CL0s and CL1 are enabled and supported together.
1489 * Silently ignore CLx re-enabling in case CLx is not supported.
1491 ret = tb_switch_enable_clx(sw, TB_CL1);
1492 if (ret && ret != -EOPNOTSUPP)
1493 tb_sw_warn(sw, "failed to re-enable %s on upstream port\n",
1494 tb_switch_clx_name(TB_CL1));
1496 if (tb_switch_is_clx_enabled(sw, TB_CL1))
1498 * To support highest CLx state, we set router's TMU to
1501 tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_NORMAL, true);
1503 /* If CLx disabled, configure router's TMU to HiFi-Bidir mode*/
1504 tb_switch_tmu_configure(sw, TB_SWITCH_TMU_RATE_HIFI, false);
1506 if (tb_enable_tmu(sw))
1507 tb_sw_warn(sw, "failed to restore TMU configuration\n");
1509 tb_switch_for_each_port(sw, port) {
1510 if (!tb_port_has_remote(port) && !port->xdomain)
1514 tb_switch_lane_bonding_enable(port->remote->sw);
1515 tb_switch_configure_link(port->remote->sw);
1517 tb_restore_children(port->remote->sw);
1518 } else if (port->xdomain) {
1519 tb_port_configure_xdomain(port, port->xdomain);
1524 static int tb_resume_noirq(struct tb *tb)
1526 struct tb_cm *tcm = tb_priv(tb);
1527 struct tb_tunnel *tunnel, *n;
1528 unsigned int usb3_delay = 0;
1531 tb_dbg(tb, "resuming...\n");
1533 /* remove any pci devices the firmware might have setup */
1534 tb_switch_reset(tb->root_switch);
1536 tb_switch_resume(tb->root_switch);
1537 tb_free_invalid_tunnels(tb);
1538 tb_free_unplugged_children(tb->root_switch);
1539 tb_restore_children(tb->root_switch);
1542 * If we get here from suspend to disk the boot firmware or the
1543 * restore kernel might have created tunnels of its own. Since
1544 * we cannot be sure they are usable for us we find and tear
1547 tb_switch_discover_tunnels(tb->root_switch, &tunnels, false);
1548 list_for_each_entry_safe_reverse(tunnel, n, &tunnels, list) {
1549 if (tb_tunnel_is_usb3(tunnel))
1551 tb_tunnel_deactivate(tunnel);
1552 tb_tunnel_free(tunnel);
1555 /* Re-create our tunnels now */
1556 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
1557 /* USB3 requires delay before it can be re-activated */
1558 if (tb_tunnel_is_usb3(tunnel)) {
1560 /* Only need to do it once */
1563 tb_tunnel_restart(tunnel);
1565 if (!list_empty(&tcm->tunnel_list)) {
1567 * the pcie links need some time to get going.
1568 * 100ms works for me...
1570 tb_dbg(tb, "tunnels restarted, sleeping for 100ms\n");
1573 /* Allow tb_handle_hotplug to progress events */
1574 tcm->hotplug_active = true;
1575 tb_dbg(tb, "resume finished\n");
1580 static int tb_free_unplugged_xdomains(struct tb_switch *sw)
1582 struct tb_port *port;
1585 tb_switch_for_each_port(sw, port) {
1586 if (tb_is_upstream_port(port))
1588 if (port->xdomain && port->xdomain->is_unplugged) {
1589 tb_retimer_remove_all(port);
1590 tb_xdomain_remove(port->xdomain);
1591 tb_port_unconfigure_xdomain(port);
1592 port->xdomain = NULL;
1594 } else if (port->remote) {
1595 ret += tb_free_unplugged_xdomains(port->remote->sw);
1602 static int tb_freeze_noirq(struct tb *tb)
1604 struct tb_cm *tcm = tb_priv(tb);
1606 tcm->hotplug_active = false;
1610 static int tb_thaw_noirq(struct tb *tb)
1612 struct tb_cm *tcm = tb_priv(tb);
1614 tcm->hotplug_active = true;
1618 static void tb_complete(struct tb *tb)
1621 * Release any unplugged XDomains and if there is a case where
1622 * another domain is swapped in place of unplugged XDomain we
1623 * need to run another rescan.
1625 mutex_lock(&tb->lock);
1626 if (tb_free_unplugged_xdomains(tb->root_switch))
1627 tb_scan_switch(tb->root_switch);
1628 mutex_unlock(&tb->lock);
1631 static int tb_runtime_suspend(struct tb *tb)
1633 struct tb_cm *tcm = tb_priv(tb);
1635 mutex_lock(&tb->lock);
1636 tb_switch_suspend(tb->root_switch, true);
1637 tcm->hotplug_active = false;
1638 mutex_unlock(&tb->lock);
1643 static void tb_remove_work(struct work_struct *work)
1645 struct tb_cm *tcm = container_of(work, struct tb_cm, remove_work.work);
1646 struct tb *tb = tcm_to_tb(tcm);
1648 mutex_lock(&tb->lock);
1649 if (tb->root_switch) {
1650 tb_free_unplugged_children(tb->root_switch);
1651 tb_free_unplugged_xdomains(tb->root_switch);
1653 mutex_unlock(&tb->lock);
1656 static int tb_runtime_resume(struct tb *tb)
1658 struct tb_cm *tcm = tb_priv(tb);
1659 struct tb_tunnel *tunnel, *n;
1661 mutex_lock(&tb->lock);
1662 tb_switch_resume(tb->root_switch);
1663 tb_free_invalid_tunnels(tb);
1664 tb_restore_children(tb->root_switch);
1665 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list)
1666 tb_tunnel_restart(tunnel);
1667 tcm->hotplug_active = true;
1668 mutex_unlock(&tb->lock);
1671 * Schedule cleanup of any unplugged devices. Run this in a
1672 * separate thread to avoid possible deadlock if the device
1673 * removal runtime resumes the unplugged device.
1675 queue_delayed_work(tb->wq, &tcm->remove_work, msecs_to_jiffies(50));
1679 static const struct tb_cm_ops tb_cm_ops = {
1682 .suspend_noirq = tb_suspend_noirq,
1683 .resume_noirq = tb_resume_noirq,
1684 .freeze_noirq = tb_freeze_noirq,
1685 .thaw_noirq = tb_thaw_noirq,
1686 .complete = tb_complete,
1687 .runtime_suspend = tb_runtime_suspend,
1688 .runtime_resume = tb_runtime_resume,
1689 .handle_event = tb_handle_event,
1690 .disapprove_switch = tb_disconnect_pci,
1691 .approve_switch = tb_tunnel_pci,
1692 .approve_xdomain_paths = tb_approve_xdomain_paths,
1693 .disconnect_xdomain_paths = tb_disconnect_xdomain_paths,
1697 * During suspend the Thunderbolt controller is reset and all PCIe
1698 * tunnels are lost. The NHI driver will try to reestablish all tunnels
1699 * during resume. This adds device links between the tunneled PCIe
1700 * downstream ports and the NHI so that the device core will make sure
1701 * NHI is resumed first before the rest.
1703 static void tb_apple_add_links(struct tb_nhi *nhi)
1705 struct pci_dev *upstream, *pdev;
1707 if (!x86_apple_machine)
1710 switch (nhi->pdev->device) {
1711 case PCI_DEVICE_ID_INTEL_LIGHT_RIDGE:
1712 case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C:
1713 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI:
1714 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI:
1720 upstream = pci_upstream_bridge(nhi->pdev);
1722 if (!pci_is_pcie(upstream))
1724 if (pci_pcie_type(upstream) == PCI_EXP_TYPE_UPSTREAM)
1726 upstream = pci_upstream_bridge(upstream);
1733 * For each hotplug downstream port, create add device link
1734 * back to NHI so that PCIe tunnels can be re-established after
1737 for_each_pci_bridge(pdev, upstream->subordinate) {
1738 const struct device_link *link;
1740 if (!pci_is_pcie(pdev))
1742 if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM ||
1743 !pdev->is_hotplug_bridge)
1746 link = device_link_add(&pdev->dev, &nhi->pdev->dev,
1747 DL_FLAG_AUTOREMOVE_SUPPLIER |
1748 DL_FLAG_PM_RUNTIME);
1750 dev_dbg(&nhi->pdev->dev, "created link from %s\n",
1751 dev_name(&pdev->dev));
1753 dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n",
1754 dev_name(&pdev->dev));
1759 struct tb *tb_probe(struct tb_nhi *nhi)
1764 tb = tb_domain_alloc(nhi, TB_TIMEOUT, sizeof(*tcm));
1768 if (tb_acpi_may_tunnel_pcie())
1769 tb->security_level = TB_SECURITY_USER;
1771 tb->security_level = TB_SECURITY_NOPCIE;
1773 tb->cm_ops = &tb_cm_ops;
1776 INIT_LIST_HEAD(&tcm->tunnel_list);
1777 INIT_LIST_HEAD(&tcm->dp_resources);
1778 INIT_DELAYED_WORK(&tcm->remove_work, tb_remove_work);
1780 tb_dbg(tb, "using software connection manager\n");
1782 tb_apple_add_links(nhi);
1783 tb_acpi_add_links(nhi);