Skip to content

Commit b2be2b0

Browse files
committed
thunderbolt: Create device links from ACPI description
The new way to describe relationship between tunneled ports and USB4 NHI (Native Host Interface) is with ACPI _DSD looking like below for a PCIe downstream port: Scope (\_SB.PCI0) { Device (NHI0) { } // Thunderbolt NHI Device (DSB0) // Hotplug downstream port { Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () {"usb4-host-interface", \_SB.PCI0.NHI0}, ... } }) } } This is "documented" in these [1] USB-IF slides and being used on systems that ship with Windows. The _DSD can be added to tunneled USB3 and PCIe ports, and is needed to make sure the USB4 NHI is resumed before any of the tunneled ports so the protocol tunnels get established properly before the actual port itself is resumed. Othwerwise the USB/PCI core find the link may not be established and starts tearing down the device stack. This parses the ACPI description each time NHI is probed and tries to find devices that has the property and it references the NHI in question. For each matching device a device link from that device to the NHI is created. Since USB3 ports themselves do not get runtime suspended with the parent device (hub) we do not add the link from the USB3 port to USB4 NHI but instead we add the link from the xHCI device. This makes the device link usable for runtime PM as well. [1] https://www.usb.org/sites/default/files/D1T2-2%20-%20USB4%20on%20Windows.pdf Signed-off-by: Mika Westerberg <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]>
1 parent 1c9698f commit b2be2b0

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

drivers/thunderbolt/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ thunderbolt-objs := nhi.o nhi_ops.o ctl.o tb.o switch.o cap.o path.o tunnel.o ee
44
thunderbolt-objs += domain.o dma_port.o icm.o property.o xdomain.o lc.o tmu.o usb4.o
55
thunderbolt-objs += nvm.o retimer.o quirks.o
66

7+
thunderbolt-${CONFIG_ACPI} += acpi.o
8+
79
obj-${CONFIG_USB4_KUNIT_TEST} += test.o

drivers/thunderbolt/acpi.c

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* ACPI support
4+
*
5+
* Copyright (C) 2020, Intel Corporation
6+
* Author: Mika Westerberg <[email protected]>
7+
*/
8+
9+
#include <linux/acpi.h>
10+
11+
#include "tb.h"
12+
13+
static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data,
14+
void **return_value)
15+
{
16+
struct fwnode_reference_args args;
17+
struct fwnode_handle *fwnode;
18+
struct tb_nhi *nhi = data;
19+
struct acpi_device *adev;
20+
struct pci_dev *pdev;
21+
struct device *dev;
22+
int ret;
23+
24+
if (acpi_bus_get_device(handle, &adev))
25+
return AE_OK;
26+
27+
fwnode = acpi_fwnode_handle(adev);
28+
ret = fwnode_property_get_reference_args(fwnode, "usb4-host-interface",
29+
NULL, 0, 0, &args);
30+
if (ret)
31+
return AE_OK;
32+
33+
/* It needs to reference this NHI */
34+
if (nhi->pdev->dev.fwnode != args.fwnode)
35+
goto out_put;
36+
37+
/*
38+
* Try to find physical device walking upwards to the hierarcy.
39+
* We need to do this because the xHCI driver might not yet be
40+
* bound so the USB3 SuperSpeed ports are not yet created.
41+
*/
42+
dev = acpi_get_first_physical_node(adev);
43+
while (!dev) {
44+
adev = adev->parent;
45+
if (!adev)
46+
break;
47+
dev = acpi_get_first_physical_node(adev);
48+
}
49+
50+
if (!dev)
51+
goto out_put;
52+
53+
/*
54+
* Check that the device is PCIe. This is because USB3
55+
* SuperSpeed ports have this property and they are not power
56+
* managed with the xHCI and the SuperSpeed hub so we create the
57+
* link from xHCI instead.
58+
*/
59+
while (!dev_is_pci(dev))
60+
dev = dev->parent;
61+
62+
if (!dev)
63+
goto out_put;
64+
65+
/*
66+
* Check that this actually matches the type of device we
67+
* expect. It should either be xHCI or PCIe root/downstream
68+
* port.
69+
*/
70+
pdev = to_pci_dev(dev);
71+
if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI ||
72+
(pci_is_pcie(pdev) &&
73+
(pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT ||
74+
pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM))) {
75+
const struct device_link *link;
76+
77+
link = device_link_add(&pdev->dev, &nhi->pdev->dev,
78+
DL_FLAG_AUTOREMOVE_SUPPLIER |
79+
DL_FLAG_PM_RUNTIME);
80+
if (link) {
81+
dev_dbg(&nhi->pdev->dev, "created link from %s\n",
82+
dev_name(&pdev->dev));
83+
} else {
84+
dev_warn(&nhi->pdev->dev, "device link creation from %s failed\n",
85+
dev_name(&pdev->dev));
86+
}
87+
}
88+
89+
out_put:
90+
fwnode_handle_put(args.fwnode);
91+
return AE_OK;
92+
}
93+
94+
/**
95+
* tb_acpi_add_links() - Add device links based on ACPI description
96+
* @nhi: Pointer to NHI
97+
*
98+
* Goes over ACPI namespace finding tunneled ports that reference to
99+
* @nhi ACPI node. For each reference a device link is added. The link
100+
* is automatically removed by the driver core.
101+
*/
102+
void tb_acpi_add_links(struct tb_nhi *nhi)
103+
{
104+
acpi_status status;
105+
106+
if (!has_acpi_companion(&nhi->pdev->dev))
107+
return;
108+
109+
/*
110+
* Find all devices that have usb4-host-controller interface
111+
* property that references to this NHI.
112+
*/
113+
status = acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 32,
114+
tb_acpi_add_link, NULL, nhi, NULL);
115+
if (ACPI_FAILURE(status))
116+
dev_warn(&nhi->pdev->dev, "failed to enumerate tunneled ports\n");
117+
}

drivers/thunderbolt/nhi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,7 @@ static int nhi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
11991199
}
12001200

12011201
tb_apple_add_links(nhi);
1202+
tb_acpi_add_links(nhi);
12021203

12031204
tb = icm_probe(nhi);
12041205
if (!tb)

drivers/thunderbolt/tb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,4 +967,10 @@ int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,
967967

968968
void tb_check_quirks(struct tb_switch *sw);
969969

970+
#ifdef CONFIG_ACPI
971+
void tb_acpi_add_links(struct tb_nhi *nhi);
972+
#else
973+
static inline void tb_acpi_add_links(struct tb_nhi *nhi) { }
974+
#endif
975+
970976
#endif

0 commit comments

Comments
 (0)