[PATCH v2 3/4] usb: xhci: Allow custom op for usb_link_tunnel_mode reporting
From: Konrad Dybcio
Date: Wed Jul 15 2026 - 08:35:53 EST
From: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
The Thunderbolt framework relies on the USB core to create device links
for tunneled ports, so that the USB3 controller is only kept
runtime-resumed for the duration of the tunneling.
Currently, retrieving that information is only possibe on Intel XHCI
hosts, through a vendor-specific capability. Extend xhci-plat to allow
plumbing a custom one.
Signed-off-by: Konrad Dybcio <konrad.dybcio@xxxxxxxxxxxxxxxx>
---
drivers/usb/host/xhci-hub.c | 13 +++++++++----
drivers/usb/host/xhci-plat.c | 2 ++
drivers/usb/host/xhci-plat.h | 1 +
drivers/usb/host/xhci.c | 3 ++-
drivers/usb/host/xhci.h | 5 ++++-
5 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 402e98ab95ee..9964cbd154ab 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -749,7 +749,7 @@ static int xhci_exit_test_mode(struct xhci_hcd *xhci)
}
/**
- * xhci_port_is_tunneled() - Check if USB3 connection is tunneled over USB4
+ * xhci_port_tunnel_mode() - Check if USB3 connection is tunneled over USB4
* @xhci: xhci host controller
* @port: USB3 port to be checked.
*
@@ -763,7 +763,7 @@ static int xhci_exit_test_mode(struct xhci_hcd *xhci)
* detecting USB3 over USB4 tunnels. USB_LINK_NATIVE or USB_LINK_TUNNELED
* otherwise.
*/
-enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci,
+enum usb_link_tunnel_mode xhci_port_tunnel_mode(struct xhci_hcd *xhci,
struct xhci_port *port)
{
void __iomem *base = &xhci->cap_regs->hc_capbase;
@@ -787,8 +787,13 @@ enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci,
/* Fall back to the legacy Intel-specific ext_cap */
hcd = xhci_to_hcd(xhci);
if (!dev_is_pci(hcd->self.controller) ||
- to_pci_dev(hcd->self.controller)->vendor != PCI_VENDOR_ID_INTEL)
- return USB_LINK_UNKNOWN;
+ to_pci_dev(hcd->self.controller)->vendor != PCI_VENDOR_ID_INTEL) {
+ /* Last chance - if the controller has a custom tunnel_mode op, try that */
+ if (xhci->tunnel_mode)
+ return xhci->tunnel_mode(xhci_to_hcd(xhci), port->hcd_portnum);
+ else
+ return USB_LINK_UNKNOWN;
+ }
offset = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_INTEL_SPR_SHADOW);
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 074d9c731639..dbaca694baa2 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -244,6 +244,8 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
priv = hcd_to_xhci_priv(hcd);
/* Just copy data for now */
*priv = *priv_match;
+
+ xhci->tunnel_mode = priv->tunnel_mode;
}
device_set_wakeup_capable(&pdev->dev, true);
diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h
index 00751d851831..c5042766a486 100644
--- a/drivers/usb/host/xhci-plat.h
+++ b/drivers/usb/host/xhci-plat.h
@@ -22,6 +22,7 @@ struct xhci_plat_priv {
int (*suspend_quirk)(struct usb_hcd *);
int (*resume_quirk)(struct usb_hcd *);
int (*post_resume_quirk)(struct usb_hcd *);
+ enum usb_link_tunnel_mode (*tunnel_mode)(struct usb_hcd *hcd, int portnum);
};
#define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 091c82ca8ee2..118401a74244 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4760,7 +4760,8 @@ static int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
if (hcd->speed >= HCD_USB3 && !udev->parent->parent) {
port = xhci->usb3_rhub.ports[udev->portnum - 1];
- udev->tunnel_mode = xhci_port_is_tunneled(xhci, port);
+ udev->tunnel_mode = xhci_port_tunnel_mode(xhci, port);
+
if (udev->tunnel_mode == USB_LINK_UNKNOWN)
dev_dbg(&udev->dev, "link tunnel state unknown\n");
else if (udev->tunnel_mode == USB_LINK_TUNNELED)
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 2d3941b5e1e3..a85968008a94 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1675,6 +1675,9 @@ struct xhci_hcd {
struct list_head regset_list;
void *dbc;
+
+ enum usb_link_tunnel_mode (*tunnel_mode)(struct usb_hcd *hcd, int portnum);
+
/* platform-specific data -- must come last */
unsigned long priv[] __aligned(sizeof(s64));
};
@@ -1981,7 +1984,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1);
struct xhci_hub *xhci_get_rhub(struct usb_hcd *hcd);
-enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci,
+enum usb_link_tunnel_mode xhci_port_tunnel_mode(struct xhci_hcd *xhci,
struct xhci_port *port);
void xhci_hc_died(struct xhci_hcd *xhci);
--
2.55.0