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>
18 * struct tb_cm - Simple Thunderbolt connection manager
19 * @tunnel_list: List of active tunnels
20 * @dp_resources: List of available DP resources for DP tunneling
21 * @hotplug_active: tb_handle_hotplug will stop progressing plug
22 * events and exit if this is not set (it needs to
23 * acquire the lock one more time). Used to drain wq
24 * after cfg has been paused.
27 struct list_head tunnel_list;
28 struct list_head dp_resources;
32 struct tb_hotplug_event {
33 struct work_struct work;
40 static void tb_handle_hotplug(struct work_struct *work);
42 static void tb_queue_hotplug(struct tb *tb, u64 route, u8 port, bool unplug)
44 struct tb_hotplug_event *ev;
46 ev = kmalloc(sizeof(*ev), GFP_KERNEL);
54 INIT_WORK(&ev->work, tb_handle_hotplug);
55 queue_work(tb->wq, &ev->work);
58 /* enumeration & hot plug handling */
60 static void tb_add_dp_resources(struct tb_switch *sw)
62 struct tb_cm *tcm = tb_priv(sw->tb);
65 tb_switch_for_each_port(sw, port) {
66 if (!tb_port_is_dpin(port))
69 if (!tb_switch_query_dp_resource(sw, port))
72 list_add_tail(&port->list, &tcm->dp_resources);
73 tb_port_dbg(port, "DP IN resource available\n");
77 static void tb_remove_dp_resources(struct tb_switch *sw)
79 struct tb_cm *tcm = tb_priv(sw->tb);
80 struct tb_port *port, *tmp;
82 /* Clear children resources first */
83 tb_switch_for_each_port(sw, port) {
84 if (tb_port_has_remote(port))
85 tb_remove_dp_resources(port->remote->sw);
88 list_for_each_entry_safe(port, tmp, &tcm->dp_resources, list) {
90 tb_port_dbg(port, "DP OUT resource unavailable\n");
91 list_del_init(&port->list);
96 static void tb_discover_tunnels(struct tb_switch *sw)
98 struct tb *tb = sw->tb;
99 struct tb_cm *tcm = tb_priv(tb);
100 struct tb_port *port;
102 tb_switch_for_each_port(sw, port) {
103 struct tb_tunnel *tunnel = NULL;
105 switch (port->config.type) {
106 case TB_TYPE_DP_HDMI_IN:
107 tunnel = tb_tunnel_discover_dp(tb, port);
110 case TB_TYPE_PCIE_DOWN:
111 tunnel = tb_tunnel_discover_pci(tb, port);
121 if (tb_tunnel_is_pci(tunnel)) {
122 struct tb_switch *parent = tunnel->dst_port->sw;
124 while (parent != tunnel->src_port->sw) {
126 parent = tb_switch_parent(parent);
130 list_add_tail(&tunnel->list, &tcm->tunnel_list);
133 tb_switch_for_each_port(sw, port) {
134 if (tb_port_has_remote(port))
135 tb_discover_tunnels(port->remote->sw);
139 static void tb_scan_xdomain(struct tb_port *port)
141 struct tb_switch *sw = port->sw;
142 struct tb *tb = sw->tb;
143 struct tb_xdomain *xd;
146 route = tb_downstream_route(port);
147 xd = tb_xdomain_find_by_route(tb, route);
153 xd = tb_xdomain_alloc(tb, &sw->dev, route, tb->root_switch->uuid,
156 tb_port_at(route, sw)->xdomain = xd;
161 static void tb_scan_port(struct tb_port *port);
164 * tb_scan_switch() - scan for and initialize downstream switches
166 static void tb_scan_switch(struct tb_switch *sw)
168 struct tb_port *port;
170 tb_switch_for_each_port(sw, port)
175 * tb_scan_port() - check for and initialize switches below port
177 static void tb_scan_port(struct tb_port *port)
179 struct tb_cm *tcm = tb_priv(port->sw->tb);
180 struct tb_port *upstream_port;
181 struct tb_switch *sw;
183 if (tb_is_upstream_port(port))
186 if (tb_port_is_dpout(port) && tb_dp_port_hpd_is_active(port) == 1 &&
187 !tb_dp_port_is_enabled(port)) {
188 tb_port_dbg(port, "DP adapter HPD set, queuing hotplug\n");
189 tb_queue_hotplug(port->sw->tb, tb_route(port->sw), port->port,
194 if (port->config.type != TB_TYPE_PORT)
196 if (port->dual_link_port && port->link_nr)
198 * Downstream switch is reachable through two ports.
199 * Only scan on the primary port (link_nr == 0).
201 if (tb_wait_for_port(port, false) <= 0)
204 tb_port_dbg(port, "port already has a remote\n");
207 sw = tb_switch_alloc(port->sw->tb, &port->sw->dev,
208 tb_downstream_route(port));
211 * If there is an error accessing the connected switch
212 * it may be connected to another domain. Also we allow
213 * the other domain to be connected to a max depth switch.
215 if (PTR_ERR(sw) == -EIO || PTR_ERR(sw) == -EADDRNOTAVAIL)
216 tb_scan_xdomain(port);
220 if (tb_switch_configure(sw)) {
226 * If there was previously another domain connected remove it
230 tb_xdomain_remove(port->xdomain);
231 port->xdomain = NULL;
235 * Do not send uevents until we have discovered all existing
236 * tunnels and know which switches were authorized already by
239 if (!tcm->hotplug_active)
240 dev_set_uevent_suppress(&sw->dev, true);
242 if (tb_switch_add(sw)) {
247 /* Link the switches using both links if available */
248 upstream_port = tb_upstream_port(sw);
249 port->remote = upstream_port;
250 upstream_port->remote = port;
251 if (port->dual_link_port && upstream_port->dual_link_port) {
252 port->dual_link_port->remote = upstream_port->dual_link_port;
253 upstream_port->dual_link_port->remote = port->dual_link_port;
256 /* Enable lane bonding if supported */
257 if (tb_switch_lane_bonding_enable(sw))
258 tb_sw_warn(sw, "failed to enable lane bonding\n");
263 static struct tb_tunnel *tb_find_tunnel(struct tb *tb, enum tb_tunnel_type type,
264 struct tb_port *src_port,
265 struct tb_port *dst_port)
267 struct tb_cm *tcm = tb_priv(tb);
268 struct tb_tunnel *tunnel;
270 list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
271 if (tunnel->type == type &&
272 ((src_port && src_port == tunnel->src_port) ||
273 (dst_port && dst_port == tunnel->dst_port))) {
281 static void tb_deactivate_and_free_tunnel(struct tb_tunnel *tunnel)
286 tb_tunnel_deactivate(tunnel);
287 list_del(&tunnel->list);
290 * In case of DP tunnel make sure the DP IN resource is deallocated
293 if (tb_tunnel_is_dp(tunnel)) {
294 struct tb_port *in = tunnel->src_port;
296 tb_switch_dealloc_dp_resource(in->sw, in);
299 tb_tunnel_free(tunnel);
303 * tb_free_invalid_tunnels() - destroy tunnels of devices that have gone away
305 static void tb_free_invalid_tunnels(struct tb *tb)
307 struct tb_cm *tcm = tb_priv(tb);
308 struct tb_tunnel *tunnel;
311 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
312 if (tb_tunnel_is_invalid(tunnel))
313 tb_deactivate_and_free_tunnel(tunnel);
318 * tb_free_unplugged_children() - traverse hierarchy and free unplugged switches
320 static void tb_free_unplugged_children(struct tb_switch *sw)
322 struct tb_port *port;
324 tb_switch_for_each_port(sw, port) {
325 if (!tb_port_has_remote(port))
328 if (port->remote->sw->is_unplugged) {
329 tb_remove_dp_resources(port->remote->sw);
330 tb_switch_lane_bonding_disable(port->remote->sw);
331 tb_switch_remove(port->remote->sw);
333 if (port->dual_link_port)
334 port->dual_link_port->remote = NULL;
336 tb_free_unplugged_children(port->remote->sw);
342 * tb_find_unused_port() - return the first inactive port on @sw
343 * @sw: Switch to find the port on
344 * @type: Port type to look for
346 static struct tb_port *tb_find_unused_port(struct tb_switch *sw,
347 enum tb_port_type type)
349 struct tb_port *port;
351 tb_switch_for_each_port(sw, port) {
352 if (tb_is_upstream_port(port))
354 if (port->config.type != type)
358 if (tb_port_is_enabled(port))
365 static struct tb_port *tb_find_pcie_down(struct tb_switch *sw,
366 const struct tb_port *port)
369 * To keep plugging devices consistently in the same PCIe
370 * hierarchy, do mapping here for root switch downstream PCIe
374 int phy_port = tb_phy_port_from_link(port->port);
378 * Hard-coded Thunderbolt port to PCIe down port mapping
381 if (tb_switch_is_cactus_ridge(sw) ||
382 tb_switch_is_alpine_ridge(sw))
383 index = !phy_port ? 6 : 7;
384 else if (tb_switch_is_falcon_ridge(sw))
385 index = !phy_port ? 6 : 8;
386 else if (tb_switch_is_titan_ridge(sw))
387 index = !phy_port ? 8 : 9;
391 /* Validate the hard-coding */
392 if (WARN_ON(index > sw->config.max_port_number))
394 if (WARN_ON(!tb_port_is_pcie_down(&sw->ports[index])))
396 if (WARN_ON(tb_pci_port_is_enabled(&sw->ports[index])))
399 return &sw->ports[index];
403 return tb_find_unused_port(sw, TB_TYPE_PCIE_DOWN);
406 static int tb_available_bw(struct tb_cm *tcm, struct tb_port *in,
409 struct tb_switch *sw = out->sw;
410 struct tb_tunnel *tunnel;
411 int bw, available_bw = 40000;
413 while (sw && sw != in->sw) {
414 bw = sw->link_speed * sw->link_width * 1000; /* Mb/s */
415 /* Leave 10% guard band */
419 * Check for any active DP tunnels that go through this
420 * switch and reduce their consumed bandwidth from
423 list_for_each_entry(tunnel, &tcm->tunnel_list, list) {
426 if (!tb_tunnel_switch_on_path(tunnel, sw))
429 consumed_bw = tb_tunnel_consumed_bandwidth(tunnel);
436 if (bw < available_bw)
439 sw = tb_switch_parent(sw);
445 static void tb_tunnel_dp(struct tb *tb)
447 struct tb_cm *tcm = tb_priv(tb);
448 struct tb_port *port, *in, *out;
449 struct tb_tunnel *tunnel;
453 * Find pair of inactive DP IN and DP OUT adapters and then
454 * establish a DP tunnel between them.
456 tb_dbg(tb, "looking for DP IN <-> DP OUT pairs:\n");
460 list_for_each_entry(port, &tcm->dp_resources, list) {
461 if (tb_port_is_enabled(port)) {
462 tb_port_dbg(port, "in use\n");
466 tb_port_dbg(port, "available\n");
468 if (!in && tb_port_is_dpin(port))
470 else if (!out && tb_port_is_dpout(port))
475 tb_dbg(tb, "no suitable DP IN adapter available, not tunneling\n");
479 tb_dbg(tb, "no suitable DP OUT adapter available, not tunneling\n");
483 if (tb_switch_alloc_dp_resource(in->sw, in)) {
484 tb_port_dbg(in, "no resource available for DP IN, not tunneling\n");
488 /* Calculate available bandwidth between in and out */
489 available_bw = tb_available_bw(tcm, in, out);
490 if (available_bw < 0) {
491 tb_warn(tb, "failed to determine available bandwidth\n");
495 tb_dbg(tb, "available bandwidth for new DP tunnel %u Mb/s\n",
498 tunnel = tb_tunnel_alloc_dp(tb, in, out, available_bw);
500 tb_port_dbg(out, "could not allocate DP tunnel\n");
504 if (tb_tunnel_activate(tunnel)) {
505 tb_port_info(out, "DP tunnel activation failed, aborting\n");
506 tb_tunnel_free(tunnel);
510 list_add_tail(&tunnel->list, &tcm->tunnel_list);
514 tb_switch_dealloc_dp_resource(in->sw, in);
517 static void tb_dp_resource_unavailable(struct tb *tb, struct tb_port *port)
519 struct tb_port *in, *out;
520 struct tb_tunnel *tunnel;
522 if (tb_port_is_dpin(port)) {
523 tb_port_dbg(port, "DP IN resource unavailable\n");
527 tb_port_dbg(port, "DP OUT resource unavailable\n");
532 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DP, in, out);
533 tb_deactivate_and_free_tunnel(tunnel);
534 list_del_init(&port->list);
537 * See if there is another DP OUT port that can be used for
538 * to create another tunnel.
543 static void tb_dp_resource_available(struct tb *tb, struct tb_port *port)
545 struct tb_cm *tcm = tb_priv(tb);
548 if (tb_port_is_enabled(port))
551 list_for_each_entry(p, &tcm->dp_resources, list) {
556 tb_port_dbg(port, "DP %s resource available\n",
557 tb_port_is_dpin(port) ? "IN" : "OUT");
558 list_add_tail(&port->list, &tcm->dp_resources);
560 /* Look for suitable DP IN <-> DP OUT pairs now */
564 static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
566 struct tb_port *up, *down, *port;
567 struct tb_cm *tcm = tb_priv(tb);
568 struct tb_switch *parent_sw;
569 struct tb_tunnel *tunnel;
571 up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
576 * Look up available down port. Since we are chaining it should
577 * be found right above this switch.
579 parent_sw = tb_to_switch(sw->dev.parent);
580 port = tb_port_at(tb_route(sw), parent_sw);
581 down = tb_find_pcie_down(parent_sw, port);
585 tunnel = tb_tunnel_alloc_pci(tb, up, down);
589 if (tb_tunnel_activate(tunnel)) {
591 "PCIe tunnel activation failed, aborting\n");
592 tb_tunnel_free(tunnel);
596 list_add_tail(&tunnel->list, &tcm->tunnel_list);
600 static int tb_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd)
602 struct tb_cm *tcm = tb_priv(tb);
603 struct tb_port *nhi_port, *dst_port;
604 struct tb_tunnel *tunnel;
605 struct tb_switch *sw;
607 sw = tb_to_switch(xd->dev.parent);
608 dst_port = tb_port_at(xd->route, sw);
609 nhi_port = tb_switch_find_port(tb->root_switch, TB_TYPE_NHI);
611 mutex_lock(&tb->lock);
612 tunnel = tb_tunnel_alloc_dma(tb, nhi_port, dst_port, xd->transmit_ring,
613 xd->transmit_path, xd->receive_ring,
616 mutex_unlock(&tb->lock);
620 if (tb_tunnel_activate(tunnel)) {
621 tb_port_info(nhi_port,
622 "DMA tunnel activation failed, aborting\n");
623 tb_tunnel_free(tunnel);
624 mutex_unlock(&tb->lock);
628 list_add_tail(&tunnel->list, &tcm->tunnel_list);
629 mutex_unlock(&tb->lock);
633 static void __tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd)
635 struct tb_port *dst_port;
636 struct tb_tunnel *tunnel;
637 struct tb_switch *sw;
639 sw = tb_to_switch(xd->dev.parent);
640 dst_port = tb_port_at(xd->route, sw);
643 * It is possible that the tunnel was already teared down (in
644 * case of cable disconnect) so it is fine if we cannot find it
647 tunnel = tb_find_tunnel(tb, TB_TUNNEL_DMA, NULL, dst_port);
648 tb_deactivate_and_free_tunnel(tunnel);
651 static int tb_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd)
653 if (!xd->is_unplugged) {
654 mutex_lock(&tb->lock);
655 __tb_disconnect_xdomain_paths(tb, xd);
656 mutex_unlock(&tb->lock);
661 /* hotplug handling */
664 * tb_handle_hotplug() - handle hotplug event
666 * Executes on tb->wq.
668 static void tb_handle_hotplug(struct work_struct *work)
670 struct tb_hotplug_event *ev = container_of(work, typeof(*ev), work);
671 struct tb *tb = ev->tb;
672 struct tb_cm *tcm = tb_priv(tb);
673 struct tb_switch *sw;
674 struct tb_port *port;
675 mutex_lock(&tb->lock);
676 if (!tcm->hotplug_active)
677 goto out; /* during init, suspend or shutdown */
679 sw = tb_switch_find_by_route(tb, ev->route);
682 "hotplug event from non existent switch %llx:%x (unplug: %d)\n",
683 ev->route, ev->port, ev->unplug);
686 if (ev->port > sw->config.max_port_number) {
688 "hotplug event from non existent port %llx:%x (unplug: %d)\n",
689 ev->route, ev->port, ev->unplug);
692 port = &sw->ports[ev->port];
693 if (tb_is_upstream_port(port)) {
694 tb_dbg(tb, "hotplug event for upstream port %llx:%x (unplug: %d)\n",
695 ev->route, ev->port, ev->unplug);
699 if (tb_port_has_remote(port)) {
700 tb_port_dbg(port, "switch unplugged\n");
701 tb_sw_set_unplugged(port->remote->sw);
702 tb_free_invalid_tunnels(tb);
703 tb_remove_dp_resources(port->remote->sw);
704 tb_switch_lane_bonding_disable(port->remote->sw);
705 tb_switch_remove(port->remote->sw);
707 if (port->dual_link_port)
708 port->dual_link_port->remote = NULL;
709 /* Maybe we can create another DP tunnel */
711 } else if (port->xdomain) {
712 struct tb_xdomain *xd = tb_xdomain_get(port->xdomain);
714 tb_port_dbg(port, "xdomain unplugged\n");
716 * Service drivers are unbound during
717 * tb_xdomain_remove() so setting XDomain as
718 * unplugged here prevents deadlock if they call
719 * tb_xdomain_disable_paths(). We will tear down
722 xd->is_unplugged = true;
723 tb_xdomain_remove(xd);
724 port->xdomain = NULL;
725 __tb_disconnect_xdomain_paths(tb, xd);
727 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) {
728 tb_dp_resource_unavailable(tb, port);
731 "got unplug event for disconnected port, ignoring\n");
733 } else if (port->remote) {
734 tb_port_dbg(port, "got plug event for connected port, ignoring\n");
736 if (tb_port_is_null(port)) {
737 tb_port_dbg(port, "hotplug: scanning\n");
740 tb_port_dbg(port, "hotplug: no switch found\n");
741 } else if (tb_port_is_dpout(port) || tb_port_is_dpin(port)) {
742 tb_dp_resource_available(tb, port);
749 mutex_unlock(&tb->lock);
754 * tb_schedule_hotplug_handler() - callback function for the control channel
756 * Delegates to tb_handle_hotplug.
758 static void tb_handle_event(struct tb *tb, enum tb_cfg_pkg_type type,
759 const void *buf, size_t size)
761 const struct cfg_event_pkg *pkg = buf;
764 if (type != TB_CFG_PKG_EVENT) {
765 tb_warn(tb, "unexpected event %#x, ignoring\n", type);
769 route = tb_cfg_get_route(&pkg->header);
771 if (tb_cfg_ack_plug(tb->ctl, route, pkg->port, pkg->unplug)) {
772 tb_warn(tb, "could not ack plug event on %llx:%x\n", route,
776 tb_queue_hotplug(tb, route, pkg->port, pkg->unplug);
779 static void tb_stop(struct tb *tb)
781 struct tb_cm *tcm = tb_priv(tb);
782 struct tb_tunnel *tunnel;
785 /* tunnels are only present after everything has been initialized */
786 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list) {
788 * DMA tunnels require the driver to be functional so we
789 * tear them down. Other protocol tunnels can be left
792 if (tb_tunnel_is_dma(tunnel))
793 tb_tunnel_deactivate(tunnel);
794 tb_tunnel_free(tunnel);
796 tb_switch_remove(tb->root_switch);
797 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */
800 static int tb_scan_finalize_switch(struct device *dev, void *data)
802 if (tb_is_switch(dev)) {
803 struct tb_switch *sw = tb_to_switch(dev);
806 * If we found that the switch was already setup by the
807 * boot firmware, mark it as authorized now before we
808 * send uevent to userspace.
813 dev_set_uevent_suppress(dev, false);
814 kobject_uevent(&dev->kobj, KOBJ_ADD);
815 device_for_each_child(dev, NULL, tb_scan_finalize_switch);
821 static int tb_start(struct tb *tb)
823 struct tb_cm *tcm = tb_priv(tb);
826 tb->root_switch = tb_switch_alloc(tb, &tb->dev, 0);
827 if (IS_ERR(tb->root_switch))
828 return PTR_ERR(tb->root_switch);
831 * ICM firmware upgrade needs running firmware and in native
832 * mode that is not available so disable firmware upgrade of the
835 tb->root_switch->no_nvm_upgrade = true;
837 ret = tb_switch_configure(tb->root_switch);
839 tb_switch_put(tb->root_switch);
843 /* Announce the switch to the world */
844 ret = tb_switch_add(tb->root_switch);
846 tb_switch_put(tb->root_switch);
850 /* Full scan to discover devices added before the driver was loaded. */
851 tb_scan_switch(tb->root_switch);
852 /* Find out tunnels created by the boot firmware */
853 tb_discover_tunnels(tb->root_switch);
854 /* Add DP IN resources for the root switch */
855 tb_add_dp_resources(tb->root_switch);
856 /* Make the discovered switches available to the userspace */
857 device_for_each_child(&tb->root_switch->dev, NULL,
858 tb_scan_finalize_switch);
860 /* Allow tb_handle_hotplug to progress events */
861 tcm->hotplug_active = true;
865 static int tb_suspend_noirq(struct tb *tb)
867 struct tb_cm *tcm = tb_priv(tb);
869 tb_dbg(tb, "suspending...\n");
870 tb_switch_suspend(tb->root_switch);
871 tcm->hotplug_active = false; /* signal tb_handle_hotplug to quit */
872 tb_dbg(tb, "suspend finished\n");
877 static void tb_restore_children(struct tb_switch *sw)
879 struct tb_port *port;
881 tb_switch_for_each_port(sw, port) {
882 if (!tb_port_has_remote(port))
885 if (tb_switch_lane_bonding_enable(port->remote->sw))
886 dev_warn(&sw->dev, "failed to restore lane bonding\n");
888 tb_restore_children(port->remote->sw);
892 static int tb_resume_noirq(struct tb *tb)
894 struct tb_cm *tcm = tb_priv(tb);
895 struct tb_tunnel *tunnel, *n;
897 tb_dbg(tb, "resuming...\n");
899 /* remove any pci devices the firmware might have setup */
900 tb_switch_reset(tb, 0);
902 tb_switch_resume(tb->root_switch);
903 tb_free_invalid_tunnels(tb);
904 tb_free_unplugged_children(tb->root_switch);
905 tb_restore_children(tb->root_switch);
906 list_for_each_entry_safe(tunnel, n, &tcm->tunnel_list, list)
907 tb_tunnel_restart(tunnel);
908 if (!list_empty(&tcm->tunnel_list)) {
910 * the pcie links need some time to get going.
911 * 100ms works for me...
913 tb_dbg(tb, "tunnels restarted, sleeping for 100ms\n");
916 /* Allow tb_handle_hotplug to progress events */
917 tcm->hotplug_active = true;
918 tb_dbg(tb, "resume finished\n");
923 static int tb_free_unplugged_xdomains(struct tb_switch *sw)
925 struct tb_port *port;
928 tb_switch_for_each_port(sw, port) {
929 if (tb_is_upstream_port(port))
931 if (port->xdomain && port->xdomain->is_unplugged) {
932 tb_xdomain_remove(port->xdomain);
933 port->xdomain = NULL;
935 } else if (port->remote) {
936 ret += tb_free_unplugged_xdomains(port->remote->sw);
943 static void tb_complete(struct tb *tb)
946 * Release any unplugged XDomains and if there is a case where
947 * another domain is swapped in place of unplugged XDomain we
948 * need to run another rescan.
950 mutex_lock(&tb->lock);
951 if (tb_free_unplugged_xdomains(tb->root_switch))
952 tb_scan_switch(tb->root_switch);
953 mutex_unlock(&tb->lock);
956 static const struct tb_cm_ops tb_cm_ops = {
959 .suspend_noirq = tb_suspend_noirq,
960 .resume_noirq = tb_resume_noirq,
961 .complete = tb_complete,
962 .handle_event = tb_handle_event,
963 .approve_switch = tb_tunnel_pci,
964 .approve_xdomain_paths = tb_approve_xdomain_paths,
965 .disconnect_xdomain_paths = tb_disconnect_xdomain_paths,
968 struct tb *tb_probe(struct tb_nhi *nhi)
973 tb = tb_domain_alloc(nhi, sizeof(*tcm));
977 tb->security_level = TB_SECURITY_USER;
978 tb->cm_ops = &tb_cm_ops;
981 INIT_LIST_HEAD(&tcm->tunnel_list);
982 INIT_LIST_HEAD(&tcm->dp_resources);