From nobody Sat Sep 26 13:09:28 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E21AE478E56; Tue, 1 Sep 2026 10:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257156; cv=none; b=COxJZvjFPlqiHTbJ9T384kAY+dUPWKf/YY+QHHBqAeqT+ntromBlHJALm/pQLMJenGx4LK6nrDmrHGdzZs7lx6PZeKPrXdzyCLt9lZlZw+mTnpjWEUgAAaW/fu2ogBy1RAoRnARKPzS+ba01gKDSYctcUKFBV8wVmwU1/PyrcoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257156; c=relaxed/simple; bh=PkpB4+pkEgMP4SQTFp14JuZl+BC388LwIYCEsgFxZXE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GfD/WtNnBByHT4xB92VI7B3s70xjMwJeyZps/JEDI5q0q4O5Tqra6h1w8xSlg3JHxojE+NKhyRx6V2sopQGAsUVAcX3Fz1DIre/EN7IafhVoxl9XLUA31inAC83/MBnHLL/iv0pqlJsMXQT8jN0/I/jB3v4tYa4ZMgOzVrIkXV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JJkvQkJK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JJkvQkJK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 272CB1F00A3D; Tue, 1 Sep 2026 10:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788257153; bh=be0Lk1c1EPMLsvHe1SiuO/oX6tRh9CySvTwV5BBLgGg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=JJkvQkJKid72OD2rn1cm0RSnVt5EvepCYHKqLCBiYEYSosfd5Nox9gycmIVApF1Am oBNQ2fJy2xrFtjxqPPeq1WDmzvCy0D9qm6Cv8DuHtk0EMZC/ftZzikeP58fCRIUvWS P/4K6Wl4YLu5JumKQLQpqN+xI7IGHAjhkxlf34O+60dS+YH1EmaHFok5jK9fGd35nQ 6/1bRfQQH0CUGzKPFj6a1CVHTdjg2ALdxpmyOrRhDsxBtBZCsxATAkeHxG2rCQQUrP Sev7YEhBQLTV95yyERkmmvxg4sT9mA8W325wSoEv/n0G9HsFW6jFkwBvINszz6RmwG 4Jgh3OXWAAppg== From: Konrad Dybcio Date: Tue, 01 Sep 2026 12:05:43 +0200 Subject: [PATCH v3 1/4] usb: xhci: debugfs: Expose the USB3 tunneling ext_cap register value Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260901-topic-dwc3_tunneling_state-v3-1-22fdced8de55@oss.qualcomm.com> References: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> In-Reply-To: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> To: Thinh Nguyen , Greg Kroah-Hartman , Mathias Nyman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, usb4-upstream@oss.qualcomm.com, Raghavendra Thoorpu , Mika Westerberg , Sven Peter , Konrad Dybcio X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788257146; l=2275; i=konrad.dybcio@oss.qualcomm.com; s=20230215; h=from:subject:message-id; bh=wuYmnoHK2aZ+IH1Vx6nM1Y18Ks5FNSxDzKLCVZBW5Ns=; b=fjB1t+7V6x/mTUnYuHJastnaxa4Fx9NZsXn8ZG/jFgmB674+ij3zf5+pVEvmda/B6EboMt3o9 xwuNRqKScw1AEmrfPGmTd5LvPmf2vx6UM8KTgKjosjyjAoKXNbeQ4um X-Developer-Key: i=konrad.dybcio@oss.qualcomm.com; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= From: Konrad Dybcio The USB3 Tunneling Support Capability (idx 18) features a single register. Expose it over debugfs, if supported by the controller. Signed-off-by: Konrad Dybcio --- drivers/usb/host/xhci-debugfs.c | 9 +++++++++ drivers/usb/host/xhci-debugfs.h | 2 ++ drivers/usb/host/xhci-ext-caps.h | 1 + 3 files changed, 12 insertions(+) diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugf= s.c index 2aa01d99f23d..f4bb66a9845a 100644 --- a/drivers/usb/host/xhci-debugfs.c +++ b/drivers/usb/host/xhci-debugfs.c @@ -82,6 +82,10 @@ static const struct debugfs_reg32 xhci_extcap_dbc[] =3D { dump_register(EXTCAP_DBC_DEVINFO2), }; =20 +static const struct debugfs_reg32 xhci_extcap_usb3_tunneling[] =3D { + dump_register(EXTCAP_USB3_TUNNELING), +}; + static struct dentry *xhci_debugfs_root; =20 static struct xhci_regset *xhci_debugfs_alloc_regset(struct xhci_hcd *xhci) @@ -816,6 +820,11 @@ void xhci_debugfs_init(struct xhci_hcd *xhci) ARRAY_SIZE(xhci_extcap_dbc), "reg-ext-dbc"); =20 + xhci_debugfs_extcap_regset(xhci, XHCI_EXT_CAPS_USB3_TUNNELING, + xhci_extcap_usb3_tunneling, + ARRAY_SIZE(xhci_extcap_usb3_tunneling), + "reg-usb3-tunneling"); + xhci_debugfs_create_ring_dir(xhci, &xhci->cmd_ring, "command-ring", xhci->debugfs_root); diff --git a/drivers/usb/host/xhci-debugfs.h b/drivers/usb/host/xhci-debugf= s.h index 7c074b4be819..ca6b7f2da8e3 100644 --- a/drivers/usb/host/xhci-debugfs.h +++ b/drivers/usb/host/xhci-debugfs.h @@ -70,6 +70,8 @@ #define REG_EXTCAP_DBC_DEVINFO1 0x38 #define REG_EXTCAP_DBC_DEVINFO2 0x3c =20 +#define REG_EXTCAP_USB3_TUNNELING 0x00 + #define dump_register(nm) \ { \ .name =3D __stringify(nm), \ diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-c= aps.h index 67ecf7320c62..22e53a750e2a 100644 --- a/drivers/usb/host/xhci-ext-caps.h +++ b/drivers/usb/host/xhci-ext-caps.h @@ -40,6 +40,7 @@ #define XHCI_EXT_CAPS_ROUTE 5 /* IDs 6-9 reserved */ #define XHCI_EXT_CAPS_DEBUG 10 +#define XHCI_EXT_CAPS_USB3_TUNNELING 18 /* Vendor caps */ #define XHCI_EXT_CAPS_VENDOR_INTEL 192 #define XHCI_EXT_CAPS_INTEL_SPR_SHADOW 206 --=20 2.55.0 From nobody Sat Sep 26 13:09:28 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E185847ACF5; Tue, 1 Sep 2026 10:05:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257158; cv=none; b=I0RPtM6Ebnrp3BViYymxFDBM9fau8Wle/x8rMChyNM20MPyHWqnN9lIRei1jF+fGMt2WvLhbpB19aoIN6L5d9jDyUvJyY6IHEQkJJYZF/X/d9Btr1Ixhi0NCa7bckJut2CGvBmWdCTUezVx7kPP24vrquyG+YDVGqlkVx+AMxtc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257158; c=relaxed/simple; bh=snFNMf14ebGTlxFj8iQKxIHE9cJLdi6o2E4QN9xqXfM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TNsHfNfiDf4Ewo7jqG91O6FJQVYcTQUPhVZEkhWJ7YzakJcRHGU2veNrRnjVfukodhcPFOMA35gjao4YykIz940906iLcn+xMDSDZBJ5N2Rl9uiPWHT1v9N/9Vxt5UOOePqURFnr9CKP2rOXVMx2I1EC1Ljv+RBr9o6zLXr4LW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eC6UqtT6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eC6UqtT6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D4541F000E9; Tue, 1 Sep 2026 10:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788257156; bh=JCVwKMs0+G1PVd5uyxVRWAAPEqtNswabRiH/ZRT3d+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=eC6UqtT6zDS5vo+x9Du7xv/DPs/Fet3pJVe8H3DRjZcoSUcfwO2Kz9V4RTiyvLxz8 lST1ReWuC3oigXsQC32BdUIQer5Q0blO5xETF54YClRzTxafWHEe8qzreQmhoo8ucb A1bPlGxIrFcz/0DlGdlcOH4DPQeqi4/p8CLeCTvMk2YWX71fes9Tzhly1cUDbBE0+V QV6FBuDq+Uo8awNnRCzvrX4L3hiSWIGuTQP2Rd6nCGb7tjeoFvnk6iMAGO8kfiOtis cVuqUfbZk5ue/dVqDplSF4WsCDBc4YQ/Y129nVObrvWpg9me9HluC4mWT9PAJPuS4h yuu4kIQtTiZzw== From: Konrad Dybcio Date: Tue, 01 Sep 2026 12:05:44 +0200 Subject: [PATCH v3 2/4] usb: xhci: Honor PORTSC.TM if valid Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260901-topic-dwc3_tunneling_state-v3-2-22fdced8de55@oss.qualcomm.com> References: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> In-Reply-To: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> To: Thinh Nguyen , Greg Kroah-Hartman , Mathias Nyman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, usb4-upstream@oss.qualcomm.com, Raghavendra Thoorpu , Mika Westerberg , Sven Peter , Konrad Dybcio X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788257146; l=4600; i=konrad.dybcio@oss.qualcomm.com; s=20230215; h=from:subject:message-id; bh=rgAwW4+JYqiSjjzL1uUMCXBODSZYgrfvS/7eZrFkHZM=; b=M6T5vignot6Bh+yr+PAuCiMgi+HH+wGVKxPAzOcMdLADNqELYpBVhO7QfMjwrj5LTzWOGDYpI RFsZYlz1ea2ANCXwa4e9YiMuuqHnv+tKyhhkxEkWqiQTXPjHDiIioZF X-Developer-Key: i=konrad.dybcio@oss.qualcomm.com; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= From: Konrad Dybcio Currently, the only way for the USB core to determine whether the link is native or tunneled is via an Intel vendor-specific Extended Capability. The XHCI specification v1.2 and newer expose a common ext_cap, indicating whether BIT(2) of PORTSC can be interpreted as the tunneling status. Make use of that and fall back to the existing Intel-specific path if the ext_cap is absent. Signed-off-by: Konrad Dybcio --- drivers/usb/host/xhci-ext-caps.h | 3 +++ drivers/usb/host/xhci-hub.c | 11 ++++++++++- drivers/usb/host/xhci-port.h | 3 ++- drivers/usb/host/xhci.c | 8 ++++++++ drivers/usb/host/xhci.h | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-c= aps.h index 22e53a750e2a..af7d624cd38e 100644 --- a/drivers/usb/host/xhci-ext-caps.h +++ b/drivers/usb/host/xhci-ext-caps.h @@ -66,6 +66,9 @@ #define XHCI_HLC (1 << 19) #define XHCI_BLC (1 << 20) =20 +/* USB3 tunneling support capability - section 7.11 */ +#define XHCI_USB3_TUNNELING_SUPPORTED BIT(16) + /* Intel SPR shadow capability */ #define XHCI_INTEL_SPR_ESS_PORT_OFFSET 0x8ac4 /* SuperSpeed port control = */ #define XHCI_INTEL_SPR_TUNEN BIT(4) /* Tunnel mode enabled */ diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 470bafe1802b..80f07bd5081d 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -769,8 +769,17 @@ enum usb_link_tunnel_mode xhci_port_is_tunneled(struct= xhci_hcd *xhci, struct usb_hcd *hcd; void __iomem *base; u32 offset; + u32 val; =20 - /* Don't try and probe this capability for non-Intel hosts */ + if (xhci->portsc_tunnel_reporting) { + val =3D xhci_portsc_readl(port); + if (val & PORT_TM) + return USB_LINK_TUNNELED; + + return USB_LINK_NATIVE; + } + + /* Fall back to the legacy Intel-specific ext_cap */ hcd =3D xhci_to_hcd(xhci); if (!dev_is_pci(hcd->self.controller) || to_pci_dev(hcd->self.controller)->vendor !=3D PCI_VENDOR_ID_INTEL) diff --git a/drivers/usb/host/xhci-port.h b/drivers/usb/host/xhci-port.h index 889b5fb0fcd8..215c9cadbc34 100644 --- a/drivers/usb/host/xhci-port.h +++ b/drivers/usb/host/xhci-port.h @@ -5,7 +5,8 @@ #define PORT_CONNECT (1 << 0) /* true: port enabled */ #define PORT_PE (1 << 1) -/* bit 2 reserved and zeroed */ +/* true: port is tunneling traffic over USB4 */ +#define PORT_TM (1 << 2) /* true: port has an over-current condition */ #define PORT_OC (1 << 3) /* true: port reset signaling asserted */ diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index a9e47e178c28..5fb78613a993 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5433,9 +5433,11 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_qui= rks_t get_quirks) * quirks */ struct device *dev =3D hcd->self.sysdev; + void __iomem *base; int retval; u32 hcs_params1; u32 hc_capbase; + u32 tunnel_cap; =20 /* Accept arbitrarily long scatter-gather lists */ hcd->self.sg_tablesize =3D ~0; @@ -5456,6 +5458,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quir= ks_t get_quirks) mutex_init(&xhci->mutex); xhci->main_hcd =3D hcd; xhci->cap_regs =3D hcd->regs; + base =3D &xhci->cap_regs->hc_capbase; hc_capbase =3D readl(&xhci->cap_regs->hc_capbase); if (hc_capbase =3D=3D U32_MAX) { xhci_warn(xhci, "Host controller not accessible, removed?\n"); @@ -5473,6 +5476,11 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_qui= rks_t get_quirks) xhci->hcc_params =3D readl(&xhci->cap_regs->hcc_params); if (xhci->hci_version > 0x100) xhci->hcc_params2 =3D readl(&xhci->cap_regs->hcc_params2); + tunnel_cap =3D xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_USB3_TUNNELI= NG); + if (tunnel_cap) { + xhci->portsc_tunnel_reporting =3D + !!(readl(base + tunnel_cap) & XHCI_USB3_TUNNELING_SUPPORTED); + } =20 xhci->dma_mask_bits =3D 64; xhci->max_slots =3D min(FIELD_GET(HCS_SLOTS_MASK, hcs_params1), MAX_HC_SL= OTS); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index c7bfa7f028d3..480fcbac4525 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1662,6 +1662,7 @@ struct xhci_hcd { /* cached extended protocol port capabilities */ struct xhci_port_cap *port_caps; unsigned int num_port_caps; + bool portsc_tunnel_reporting; /* Compliance Mode Recovery Data */ struct timer_list comp_mode_recovery_timer; u32 port_status_u0; --=20 2.55.0 From nobody Sat Sep 26 13:09:28 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7C8747B422; Tue, 1 Sep 2026 10:06:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257162; cv=none; b=guYSQ4ZhXG1r1FErBfCxjw+zsKflSwOemwNdIrtjZ0s06V+El1qn8CvAG5hcAK9jyPXFKiidMA4xfABf0hdQvMa3rZwSYzcc84q/ohk8gXdiyzO2c8WvS7DU6uaGtWzYdZgfo04pMBXAhi28MVjlp8h5S3vOM2zII5kfuNVhC4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257162; c=relaxed/simple; bh=HV33eBkz82Sr5gSAlrPsYXMVZ631U2iWdYGRj42KciM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XcV/xgnKbff3lRuhW9+jPkqQyxUlsXKxP3Q3RGCyRKTvk1WYP7dvEjHogvfotDPuSVliMZULPIyMaE/q6VTscT97FCW2Pr7SrEHVtp21OM+miy0nlr7peeXSpVlyKfVTZJcy8ScIUg2O626ZYGTdWlwkGoWnxn0k3l/hvLrw9uk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ibs2MPjy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ibs2MPjy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 197301F00A3E; Tue, 1 Sep 2026 10:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788257160; bh=fc6hyZ+BA0cZhnojEs5GW6hLLEjAvGFTcaHOTKu+uiw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Ibs2MPjyPrnjH4E+Yfr94blyPDKq7In55OzYHe6Qi10v8u1ivE5++12O+ciCVzwmn VYLmkMsdxpaAnak91NCgrrqseo1eXEb3lRFUHg8eHVUeNc9pH2YBC8v1AX+VowFU1C rS3X6pm2odV9w5pOyHY6V7JXpSqHxECgALTRV5RNDw6llcDrd6kiIRC6SbnuFilM9C fg65Wq9M8wks8wvraCeGtaBoyUy6CAHc8WVO4n0OMcabt6o4xTY9l00FioHsCBtcLG g4uWeKvAH/Nee8CJfxLiAdCI7/dSd4VgX3Bs1ojEYifi/RnCYzgzFoSWc96Bya9zdn R+C2VMWeOKQnQ== From: Konrad Dybcio Date: Tue, 01 Sep 2026 12:05:45 +0200 Subject: [PATCH v3 3/4] usb: xhci: Allow custom op for usb_link_tunnel_mode reporting Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260901-topic-dwc3_tunneling_state-v3-3-22fdced8de55@oss.qualcomm.com> References: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> In-Reply-To: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> To: Thinh Nguyen , Greg Kroah-Hartman , Mathias Nyman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, usb4-upstream@oss.qualcomm.com, Raghavendra Thoorpu , Mika Westerberg , Sven Peter , Konrad Dybcio X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788257146; l=4944; i=konrad.dybcio@oss.qualcomm.com; s=20230215; h=from:subject:message-id; bh=Og6Huok4WhUiJJiPdT4xAr9QhuaSVER5hlUs0Xfdi7g=; b=jKqUoeBgAcZmD1xfQwF01huuiXY0Msh2ejfIF8XgApR8NJXOvFtSlk9LM3mocXafv44M1wCdj HOnWvg6kf4OAQFOQC2E83eiMMsozs5hU15PJz/cfcAk4GVfVXzqJI6M X-Developer-Key: i=konrad.dybcio@oss.qualcomm.com; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= From: Konrad Dybcio 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 --- 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 80f07bd5081d..c585e4d02d84 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) } =20 /** - * 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) { struct usb_hcd *hcd; @@ -782,8 +782,13 @@ enum usb_link_tunnel_mode xhci_port_is_tunneled(struct= xhci_hcd *xhci, /* Fall back to the legacy Intel-specific ext_cap */ hcd =3D xhci_to_hcd(xhci); if (!dev_is_pci(hcd->self.controller) || - to_pci_dev(hcd->self.controller)->vendor !=3D PCI_VENDOR_ID_INTEL) - return USB_LINK_UNKNOWN; + to_pci_dev(hcd->self.controller)->vendor !=3D 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; + } =20 base =3D &xhci->cap_regs->hc_capbase; offset =3D 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 6fd595f81a30..c19bc5d7a7b5 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, struc= t device *sysdev, const s priv =3D hcd_to_xhci_priv(hcd); /* Just copy data for now */ *priv =3D *priv_match; + + xhci->tunnel_mode =3D priv->tunnel_mode; } =20 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= ); }; =20 #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 5fb78613a993..a7e3c46937fa 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4762,7 +4762,8 @@ static int xhci_update_device(struct usb_hcd *hcd, st= ruct usb_device *udev) if (hcd->speed >=3D HCD_USB3 && !udev->parent->parent) { port =3D xhci->usb3_rhub.ports[udev->portnum - 1]; =20 - udev->tunnel_mode =3D xhci_port_is_tunneled(xhci, port); + udev->tunnel_mode =3D xhci_port_tunnel_mode(xhci, port); + if (udev->tunnel_mode =3D=3D USB_LINK_UNKNOWN) dev_dbg(&udev->dev, "link tunnel state unknown\n"); else if (udev->tunnel_mode =3D=3D USB_LINK_TUNNELED) diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 480fcbac4525..2b5c0b304c6b 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; =20 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); =20 --=20 2.55.0 From nobody Sat Sep 26 13:09:28 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8808347CA95; Tue, 1 Sep 2026 10:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257165; cv=none; b=AyUXGdo5zE3s1CZpI25hAUEHqb28OCEbo6kH1FFbet9QUJ39HYn0oBzbM8D2DXPPjvDIhjP4zen/sGeTdgJaRiL0N6TqmMD0CKpq/O00Ebf2IFoknE3tiqlUADdi5Rnm3/wgPjkCOta0J903OleEpyMK1kaCRpUxokee0VdRyvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788257165; c=relaxed/simple; bh=Q+3pj/vnTA7xV0+Z/9qCObPeTNlsm4LzE3wz2Lk7Duc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TQ0dMIE22ihzgh8oeS/ZopPcd6em3ZcoelvCfbaop7mg//lXRRnF5AITIbWjvONZrJOrelNlPtNXvGscN8O3f/r21dIYTZzFmqZvJN8De8zfveYiSdVpzfuyq2het/fB6PI/0wGfFjdZTBCnXdp4tAwPX1SgcjMqARvKjcVNP3w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VPLPYtn2; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VPLPYtn2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2BFF1F000E9; Tue, 1 Sep 2026 10:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788257164; bh=reri38xtBHKiLor8QA7An/7PP6yRyTuLkxSPSjIM2Ms=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=VPLPYtn2ZUTMYJk9w0hVENUQxBMmc6/xMOREvbq8++1j1lMW3VRtV/phIKrWYIhrB s05KgyyS9mOImLQd/SJIL7fCv/xlosWooeO0wPO200mqsCWV0OwGAZ6/FCqNf0lHPD Ys1o24ADSM8g0YSnd8mYnz23m+oV7dpcIcPOILCvysS1NQw9jWF90VZQIu4M+cIfy1 6yhRvVi+M/vbHWOWyJZ+iKhLgbIQ5LQYTwswQ+yAMJMSyyKV5DrVVP57qxaBJLUi92 wsT28mdj2ff+WmeIxftC17bMqk8pBsAXRFZNi6oFUBgLViWDL23w3xBy/eKqEpGb7Q 9Z+xkNKXA+DOw== From: Konrad Dybcio Date: Tue, 01 Sep 2026 12:05:46 +0200 Subject: [PATCH v3 4/4] usb: dwc3: Notify XHCI core of tunneled status Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260901-topic-dwc3_tunneling_state-v3-4-22fdced8de55@oss.qualcomm.com> References: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> In-Reply-To: <20260901-topic-dwc3_tunneling_state-v3-0-22fdced8de55@oss.qualcomm.com> To: Thinh Nguyen , Greg Kroah-Hartman , Mathias Nyman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, usb4-upstream@oss.qualcomm.com, Raghavendra Thoorpu , Mika Westerberg , Sven Peter , Konrad Dybcio X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1788257146; l=4047; i=konrad.dybcio@oss.qualcomm.com; s=20230215; h=from:subject:message-id; bh=DIvE0BBVaBASrRJ+URFMpKtlSBMj9uhytSqW4wNW96M=; b=YwCGAMS1XX99MZQr72bp6h0+5nEbMaSJWWtWULe9G4/qEiC/nttjY/sD6medFff2UivCdiY0q aJmBr9qfAjHCtYJIAftWBuUH3PoNYJmyYw04c6WxI1Fxz6RImyjL5KF X-Developer-Key: i=konrad.dybcio@oss.qualcomm.com; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= From: Konrad Dybcio 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. This depends on first knowing whether a connection is tunneled or native. Add the logic to handle that for DWC3 controllers. Signed-off-by: Konrad Dybcio --- drivers/usb/dwc3/core.c | 16 ++++++++++++++++ drivers/usb/dwc3/core.h | 18 ++++++++++++++++++ drivers/usb/dwc3/host.c | 12 ++++++++++++ 3 files changed, 46 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index fd5c2cd36c59..6af8937525ff 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -162,6 +162,22 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool = ignore_susphy) } EXPORT_SYMBOL_GPL(dwc3_set_prtcap); =20 +enum usb_link_tunnel_mode dwc3_link_tunnel_mode(struct dwc3 *dwc, u8 port) +{ + /* Prior versions had no CIO support */ + if (!DWC3_VER_IS_WITHIN(DWC31, 191A, ANY)) + return USB_LINK_UNKNOWN; + + /* Not all DWC3 instances have CIO HW, trust the platform firmware */ + if (!device_property_present(dwc->dev, "usb4-host-interface")) + return USB_LINK_UNKNOWN; + + if (dwc3_readl(dwc, DWC3_CIOCTRL(port)) & DWC3_CIOCTRL_CIO_EN) + return USB_LINK_TUNNELED; + + return USB_LINK_NATIVE; +} + static void __dwc3_set_mode(struct work_struct *work) { struct dwc3 *dwc =3D work_to_dwc(work); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 608daeb7ef10..decc51cd6505 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -179,6 +179,11 @@ #define DWC3_OEVTEN 0xcc0C #define DWC3_OSTS 0xcc10 =20 +/* CIO regs */ +#define DWC3_CIO_BASE(n) (0xcd20 + ((n) * 0x30)) +#define DWC3_CIOCTRL(n) (DWC3_CIO_BASE(n) + 0x00) +#define DWC3_CIOCTRL_CIO_EN BIT(0) + #define DWC3_LLUCTL(n) (0xd024 + ((n) * 0x80)) =20 /* Bit fields */ @@ -1314,6 +1319,7 @@ struct dwc3 { #define DWC31_REVISION_170A 0x3137302a #define DWC31_REVISION_180A 0x3138302a #define DWC31_REVISION_190A 0x3139302a +#define DWC31_REVISION_191A 0x3139312a #define DWC31_REVISION_200A 0x3230302a =20 #define DWC32_REVISION_ANY 0x0 @@ -1658,11 +1664,23 @@ static inline void dwc3_pre_run_stop(struct dwc3 *d= wc, bool is_on) #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_RO= LE) int dwc3_host_init(struct dwc3 *dwc); void dwc3_host_exit(struct dwc3 *dwc); + +/** + * dwc3_link_tunnel_mode - Check whether the link is tunneled over TBT/USB4 + * @dwc: Pointer to DWC3 controller context + * @port: 0-based port index + * + * Returns: USB_LINK_TUNNELED if tunneled, USB_LINK_NATIVE if not, or + * when the controller does not have USB4 capabilities. + */ +enum usb_link_tunnel_mode dwc3_link_tunnel_mode(struct dwc3 *dwc, u8 port); #else static inline int dwc3_host_init(struct dwc3 *dwc) { return 0; } static inline void dwc3_host_exit(struct dwc3 *dwc) { } +static inline enum usb_link_tunnel_mode dwc3_link_tunnel_mode(struct dwc3 = *dwc, u8 port) +{ return USB_LINK_UNKNOWN; } #endif =20 #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_= ROLE) diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index c5674161b2b0..1b9c4f94c2fd 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -78,8 +78,20 @@ static void dwc3_xhci_plat_start(struct usb_hcd *hcd) dwc3_enable_susphy(dwc, true); } =20 +static enum usb_link_tunnel_mode dwc3_xhci_tunnel_mode(struct usb_hcd *hcd= , int portnum) +{ + struct platform_device *pdev; + struct dwc3 *dwc; + + pdev =3D to_platform_device(hcd->self.controller); + dwc =3D dev_get_drvdata(pdev->dev.parent); + + return dwc3_link_tunnel_mode(dwc, portnum); +} + static const struct xhci_plat_priv dwc3_xhci_plat_quirk =3D { .plat_start =3D dwc3_xhci_plat_start, + .tunnel_mode =3D dwc3_xhci_tunnel_mode, }; =20 static void dwc3_host_fill_xhci_irq_res(struct dwc3 *dwc, --=20 2.55.0