From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Konrad Dybcio <konradybcio@kernel.org>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Mathias Nyman <mathias.nyman@intel.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"usb4-upstream@oss.qualcomm.com" <usb4-upstream@oss.qualcomm.com>,
Raghavendra Thoorpu <rthoorpu@qti.qualcomm.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Subject: Re: [PATCH v2 3/4] usb: xhci: Allow custom op for usb_link_tunnel_mode reporting
Date: Wed, 22 Jul 2026 22:37:47 +0000 [thread overview]
Message-ID: <amFDhkvhqQHtIk7w@vbox> (raw)
In-Reply-To: <20260715-topic-dwc3_tunneling_state-v2-3-026487a08119@oss.qualcomm.com>
On Wed, Jul 15, 2026, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
>
> 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@oss.qualcomm.com>
> ---
> 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);
We should add a boolean tunnel_mode_override. When set, ->tunnel_mode()
is called before the standard xhci v1.2 ext_cap check. If the
->tunnel_mode() returns USB_LINK_UNKNOWN, go to the standard path. This
allows the quirk to selectively bypass or override it.
BR,
Thinh
> };
>
> #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
>
next prev parent reply other threads:[~2026-07-22 22:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 12:29 [PATCH v2 0/4] DWC3 link tunneling state reporting Konrad Dybcio
2026-07-15 12:29 ` [PATCH v2 1/4] usb: xhci: debugfs: Expose the USB3 tunneling ext_cap register value Konrad Dybcio
2026-07-15 12:29 ` [PATCH v2 2/4] usb: xhci: Honor PORTSC.TM if valid Konrad Dybcio
2026-07-22 22:57 ` Thinh Nguyen
2026-07-15 12:29 ` [PATCH v2 3/4] usb: xhci: Allow custom op for usb_link_tunnel_mode reporting Konrad Dybcio
2026-07-22 22:37 ` Thinh Nguyen [this message]
2026-07-15 12:29 ` [PATCH v2 4/4] usb: dwc3: Notify XHCI core of tunneled status Konrad Dybcio
2026-07-22 23:01 ` Thinh Nguyen
2026-07-15 12:58 ` [PATCH v2 0/4] DWC3 link tunneling state reporting Konrad Dybcio
2026-07-22 23:07 ` Thinh Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=amFDhkvhqQHtIk7w@vbox \
--to=thinh.nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=mika.westerberg@linux.intel.com \
--cc=rthoorpu@qti.qualcomm.com \
--cc=usb4-upstream@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.