From patchwork Fri Aug 30 15:26:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 824341 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 BC6A31B1D42 for ; Fri, 30 Aug 2024 15:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031477; cv=none; b=qrn3R2n2YnUUssbj5HR9fCNlRTFNhDWO2TCr1yHf9Wnqr7nsfJ3aeSRF7UjdneV2QCk0btIBnHHIOO4yOi7pN+SSPhjP+w00pjvM7veRJTV1adqsYpbJPa1sltc5O+J71tPfLMlMXE2ozWfkJ6fRb8wuPvDoqM2HedyBuKwPcAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031477; c=relaxed/simple; bh=y3G75Sxycr4SXNQRm3vvkou9hTLu/dECBZzXpy8AR1g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dt6AxiZG+Mpf+LdamiUxvcMQ6tbhnxC21aYGQ2dCCLg9hcmwygeQhCZPOvaUrH7QslOGg9Atvjl/fZa0SNnFLNeHf/2ne/AKQT+Qa9F11XkUJOA6Agtm48xGYBTkVN1RtUUgqmmDQr5hOvYtDDG9/6XbhpV9nC7OlH6uAaiRMf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GH8Vv0Zq; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GH8Vv0Zq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725031476; x=1756567476; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=y3G75Sxycr4SXNQRm3vvkou9hTLu/dECBZzXpy8AR1g=; b=GH8Vv0Zq95+npGozYYH4KEOye0+VSYytyzWYpV/7DjlyB8mLJmkb9ynv BArv7BximJF3cPi30RIvV07uYNQhCbOdFGS0/BDv0+eOtFrTdH7/k24fq Oqr87WuSb6IjH92LxUbx11jbUXYq+GXfwsYAZpU2u6e2RlnSloIK4DJzE O9EeXLLCPAZ5SZYmUVE61xbJErRVK2fiDEXHOnZoaMMEuT3XEPSyZIThM JYnMS/7AkNRzHacnjWpNyunexKz9lJkt8NtaYc/mc6E9/xku6ajJLuPvE B9SojoS6qkfX0AZVuxrh+4vr9gm3xyNavwvtRy6cujVcGcUT03/dmi7OX A==; X-CSE-ConnectionGUID: z7LmwSLDSL6e9OaGfWhZPA== X-CSE-MsgGUID: MTsUO8W+TluuTP6TWdiIFA== X-IronPort-AV: E=McAfee;i="6700,10204,11180"; a="23861945" X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="23861945" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2024 08:24:35 -0700 X-CSE-ConnectionGUID: llR6Bi/mRQevARFhNEircw== X-CSE-MsgGUID: FQi63AU0QY6ja7JRz5RfAA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="63981646" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 30 Aug 2024 08:24:33 -0700 From: Mathias Nyman To: linux-usb@vger.kernel.org Cc: gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, mario.limonciello@amd.com, Mathias Nyman Subject: [PATCH v2 1/4] xhci: Add USB4 tunnel detection for USB3 devices on Intel hosts Date: Fri, 30 Aug 2024 18:26:27 +0300 Message-Id: <20240830152630.3943215-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> References: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Knowledge about tunneled devices is useful in order to correctly describe the relationship between tunneled USB3 device and USB4 Host Interface, ensuring proper suspend and resume order, and to be able to power down Thunderbolt if there is no need for tunneling. Intel hosts share if a USB3 connection is native or tunneled via vendor specific "SPR eSS PORT" registers. These vendor registers are available if host supports a vendor specific SPR shadow extended capability with ID 206. Registers are per USB3 port and 0x20 apart. Knowing the tunneling status of the device connected to roothub is enough as all its children will have the same status. Signed-off-by: Mathias Nyman --- v2: minor return statement change, open up "return !!x" drivers/usb/host/xhci-ext-caps.h | 5 +++++ drivers/usb/host/xhci-hub.c | 31 +++++++++++++++++++++++++++++++ drivers/usb/host/xhci.c | 11 +++++++++++ drivers/usb/host/xhci.h | 1 + 4 files changed, 48 insertions(+) diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h index 96eb36a58738..67ecf7320c62 100644 --- a/drivers/usb/host/xhci-ext-caps.h +++ b/drivers/usb/host/xhci-ext-caps.h @@ -42,6 +42,7 @@ #define XHCI_EXT_CAPS_DEBUG 10 /* Vendor caps */ #define XHCI_EXT_CAPS_VENDOR_INTEL 192 +#define XHCI_EXT_CAPS_INTEL_SPR_SHADOW 206 /* USB Legacy Support Capability - section 7.1.1 */ #define XHCI_HC_BIOS_OWNED (1 << 16) #define XHCI_HC_OS_OWNED (1 << 24) @@ -64,6 +65,10 @@ #define XHCI_HLC (1 << 19) #define XHCI_BLC (1 << 20) +/* 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 */ + /* command register values to disable interrupts and halt the HC */ /* start/stop HC execution - do not write unless HC is halted*/ #define XHCI_CMD_RUN (1 << 0) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 61f083de6e19..4ba910eadd3f 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -752,6 +752,37 @@ static int xhci_exit_test_mode(struct xhci_hcd *xhci) return xhci_reset(xhci, XHCI_RESET_SHORT_USEC); } +/** + * xhci_port_is_tunneled() - Check if USB3 connection is tunneled over USB4 + * @xhci: xhci host controller + * @port: USB3 port to be checked. + * + * Some hosts can detect if a USB3 connection is native USB3 or tunneled over + * USB4. Intel hosts expose this via vendor specific extended capability 206 + * eSS PORT registers TUNEN (tunnel enabled) bit. + * + * A USB3 device must be connected to the port to detect the tunnel. + * + * Return: true if USB3 connection is tunneled over USB4 + */ +bool xhci_port_is_tunneled(struct xhci_hcd *xhci, struct xhci_port *port) +{ + void __iomem *base; + u32 offset; + + base = &xhci->cap_regs->hc_capbase; + offset = xhci_find_next_ext_cap(base, 0, XHCI_EXT_CAPS_INTEL_SPR_SHADOW); + + if (offset && offset <= XHCI_INTEL_SPR_ESS_PORT_OFFSET) { + offset = XHCI_INTEL_SPR_ESS_PORT_OFFSET + port->hcd_portnum * 0x20; + + if (readl(base + offset) & XHCI_INTEL_SPR_TUNEN) + return true; + } + + return false; +} + void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, u32 link_state) { diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index efdf4c228b8c..1ea2c91106b7 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4525,6 +4525,17 @@ static int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev) struct xhci_port *port; u32 capability; + /* Check if USB3 device at root port is tunneled over USB4 */ + if (hcd->speed >= HCD_USB3 && !udev->parent->parent) { + port = xhci->usb3_rhub.ports[udev->portnum - 1]; + + if (xhci_port_is_tunneled(xhci, port)) + dev_dbg(&udev->dev, "tunneled over USB4 link\n"); + else + dev_dbg(&udev->dev, "native USB 3.x link\n"); + return 0; + } + if (hcd->speed >= HCD_USB3 || !udev->lpm_capable || !xhci->hw_lpm_support) return 0; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index ebd0afd59a60..aa1062a595b6 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1929,6 +1929,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); +bool xhci_port_is_tunneled(struct xhci_hcd *xhci, struct xhci_port *port); void xhci_hc_died(struct xhci_hcd *xhci); From patchwork Fri Aug 30 15:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 825277 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 C1A541B4C56 for ; Fri, 30 Aug 2024 15:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031478; cv=none; b=sIfD3QxqMCNs6Zt1p/H/aXFJenI1sPUZyDeH0rtcD3ekl6Rfihnut/gJ8nPbwlZp83u5patbevZVe/YGuFBOkgTYFE3FE24A5/zRkdRw6H52jEVRXUvibLtCrAOr4kZq0nImPhienIJgsUr54q2dXqhcOYZe47mBftFZv8qCe1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031478; c=relaxed/simple; bh=h/PLgWcN6IRMNVOWqjexSynCBkmGyQjtubfjbqcBiMw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y+0VvI0v7MxaPAAeINkRL4TLR+uYpFprN1+xL3oCLiT2QmdCpUnqSgQaZJr9X8dm5oBtkK0Tf8X8XzfFi/2myVTnhiV+Dq8ErLUyNiQ7DdiGeYKdUQ8oAq5evXARx7G8udnisEGf/tv8lqHx/ZalXEqstuOAKupNRB31WMA3e0U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RSCClhAb; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RSCClhAb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725031477; x=1756567477; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h/PLgWcN6IRMNVOWqjexSynCBkmGyQjtubfjbqcBiMw=; b=RSCClhAb4svXjX4xhEzmX5yaUWJo1iZ5aM8zO1YqrKILd102iQqeRfoF flNZ8Fl0VVD6zKAMad/7+uUJNMvYB8rZD/5+ETuXvemZ/tTBLCZzS1xPg M86x1AR+/f8fPQg9/za6o2hoHAJktl9aR6I30FXY/9HBbrnoRIOy/+ut1 gvMRr/8emHk7DBO6wTU3CYK55GM7NSzgaRL8rih1vcszYVijw4ta3GsHc oEciGNbwE5M2zRXpSbBKwf4/dztX1Y2/7uZufgcC8xXU2jXLTvHnaenNT ROKVkXBhWRx05EBwREt/xRd/hFVC+CsXtTvpVQI8IqOBjSjw3MpL6Qpwc w==; X-CSE-ConnectionGUID: jWQMLTjQSpyqSMnJSLe8EQ== X-CSE-MsgGUID: zFeuLl6eRtKbaPpJ7AL7Pw== X-IronPort-AV: E=McAfee;i="6700,10204,11180"; a="23861950" X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="23861950" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2024 08:24:36 -0700 X-CSE-ConnectionGUID: z4F53FYZQAKr0vyySO2jww== X-CSE-MsgGUID: 8vz6qIJ3QRKCt9fbPG8sPw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="63981647" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 30 Aug 2024 08:24:35 -0700 From: Mathias Nyman To: linux-usb@vger.kernel.org Cc: gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, mario.limonciello@amd.com, Mathias Nyman Subject: [PATCH v2 2/4] usb: Add tunnel_mode parameter to usb device structure Date: Fri, 30 Aug 2024 18:26:28 +0300 Message-Id: <20240830152630.3943215-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> References: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add 'tunnel_mode' enum to usb device structure to describe if a USB3 link is tunneled over USB4, or connected directly using native USB2/USB3 protocols. Tunneled devices depend on USB4 NHI host to maintain the tunnel. Knowledge about tunneled devices is important to ensure correct suspend and resume order between USB4 hosts and tunneled devices. i.e. make sure tunnel is up before the USB device using it resumes. USB hosts such as xHCI may have vendor specific ways to detect tunneled connections. This 'tunnel_mode' parameter can be set by USB3 host driver during hcd->driver->update_device(hcd, udev) callback. tunnel_mode can be set to: USB_LINK_UNKNOWN = 0 USB_LINK_NATIVE USB_LINK_TUNNELED USB_LINK_UNKNOWN is used in case host is not capable of detecting tunneled links. Signed-off-by: Mathias Nyman --- v2: Add and use a 3 state enum to describe and store tunnel mode instead of bool. drivers/usb/host/xhci-hub.c | 13 +++++++++---- drivers/usb/host/xhci.c | 7 +++++-- drivers/usb/host/xhci.h | 4 ++-- include/linux/usb.h | 8 ++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 4ba910eadd3f..d27c30ac17fd 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -763,9 +763,12 @@ static int xhci_exit_test_mode(struct xhci_hcd *xhci) * * A USB3 device must be connected to the port to detect the tunnel. * - * Return: true if USB3 connection is tunneled over USB4 + * Return: link tunnel mode enum, USB_LINK_UNKNOWN if host is incapable of + * detecting USB3 over USB4 tunnels. USB_LINK_NATIVE or USB_LINK_TUNNELED + * otherwise. */ -bool xhci_port_is_tunneled(struct xhci_hcd *xhci, struct xhci_port *port) +enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci, + struct xhci_port *port) { void __iomem *base; u32 offset; @@ -777,10 +780,12 @@ bool xhci_port_is_tunneled(struct xhci_hcd *xhci, struct xhci_port *port) offset = XHCI_INTEL_SPR_ESS_PORT_OFFSET + port->hcd_portnum * 0x20; if (readl(base + offset) & XHCI_INTEL_SPR_TUNEN) - return true; + return USB_LINK_TUNNELED; + else + return USB_LINK_NATIVE; } - return false; + return USB_LINK_UNKNOWN; } void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 1ea2c91106b7..a69245074395 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4529,9 +4529,12 @@ 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]; - if (xhci_port_is_tunneled(xhci, port)) + udev->tunnel_mode = xhci_port_is_tunneled(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) dev_dbg(&udev->dev, "tunneled over USB4 link\n"); - else + else if (udev->tunnel_mode == USB_LINK_NATIVE) dev_dbg(&udev->dev, "native USB 3.x link\n"); return 0; } diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index aa1062a595b6..0a9d663cdfff 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1929,8 +1929,8 @@ 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); -bool xhci_port_is_tunneled(struct xhci_hcd *xhci, struct xhci_port *port); - +enum usb_link_tunnel_mode xhci_port_is_tunneled(struct xhci_hcd *xhci, + struct xhci_port *port); void xhci_hc_died(struct xhci_hcd *xhci); #ifdef CONFIG_PM diff --git a/include/linux/usb.h b/include/linux/usb.h index 832997a9da0a..672d8fc2abdb 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -495,6 +495,12 @@ struct usb_dev_state; struct usb_tt; +enum usb_link_tunnel_mode { + USB_LINK_UNKNOWN = 0, + USB_LINK_NATIVE, + USB_LINK_TUNNELED, +}; + enum usb_port_connect_type { USB_PORT_CONNECT_TYPE_UNKNOWN = 0, USB_PORT_CONNECT_TYPE_HOT_PLUG, @@ -605,6 +611,7 @@ struct usb3_lpm_parameters { * WUSB devices are not, until we authorize them from user space. * FIXME -- complete doc * @authenticated: Crypto authentication passed + * @tunnel_mode: Connection native or tunneled over USB4 * @lpm_capable: device supports LPM * @lpm_devinit_allow: Allow USB3 device initiated LPM, exit latency is in range * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM @@ -714,6 +721,7 @@ struct usb_device { unsigned do_remote_wakeup:1; unsigned reset_resume:1; unsigned port_is_suspended:1; + enum usb_link_tunnel_mode tunnel_mode; int slot_id; struct usb2_lpm_parameters l1_params; From patchwork Fri Aug 30 15:26:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 824340 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 6F9931B5323 for ; Fri, 30 Aug 2024 15:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031480; cv=none; b=FkjrzTJdh03O9y3WzDgALYq3WwSFNb9zKgccGIpYD5LdbUO/HkMJp4eitMKrRTIT3pyj8K2/yBd95hpRUB/uaX4LS/KXJGJdAUnnsrI1ZZpmTSHlBPM8J1B3ppcoJYBoq7xU8AU0fm8mS6fy/J7+TsEA+pqAGgqvjC8J7KHq9TY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031480; c=relaxed/simple; bh=VRqYs2WV9RUavq8HQiVRm//9zVRFX6Qx4nw6ePE9BLY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mUh6Eycm0481kfK3wZRK1jzSp+CUY9U6QB+Huku5Ka8nC0W4Yrrrzi3jn7ebkQacE7er4VmUGxeKndM+7VxV1qUePYUpFglMzWs1XBEZSkoBFdtZ+X7SAte1BOzd+hbhuMCgfcJpJ7cIus5nm+McE943JelZJPu8dA3/GP2tFtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XckUzKZw; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XckUzKZw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725031478; x=1756567478; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VRqYs2WV9RUavq8HQiVRm//9zVRFX6Qx4nw6ePE9BLY=; b=XckUzKZw0lqSeXMRLa1MB2/OvlET+ew9x8+TsSY9j+OdNVAcIjiNUiVG /cILbs8cMviLpoSyDyMr9w8oc+diHoCS6FSlfMWvACwJUBTVpMJ4NWA3W c/+OdlxSG3hVZS4aHC8aIHWEHiXSBnNV+3L7JgrEjPamXp2kflGsdtEpy to5r6fp1DPDGWxcxZUvxtEHiX1zm8kNjWVH9tm/Bi4Okjcat8xShOotnB Mxaovqa/qSXSb0vArPgxQphtzWxv+94miSUCZRGpaen88XNh47NghFG/3 jFp8clZT16Z/VJTK1ppJPI97fcTgyRteDWgy84t7OUqXf3jNBkl6/Rh8/ w==; X-CSE-ConnectionGUID: s0CgcS9rTHaLz3wsvSeo9Q== X-CSE-MsgGUID: dPBlFSFLTbu7OS3NPHizHQ== X-IronPort-AV: E=McAfee;i="6700,10204,11180"; a="23861955" X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="23861955" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2024 08:24:38 -0700 X-CSE-ConnectionGUID: qgPO2DrcQIaEAfvylvB/lQ== X-CSE-MsgGUID: gAa0oQEiT1eTdLQxqDdxeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="63981649" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 30 Aug 2024 08:24:37 -0700 From: Mathias Nyman To: linux-usb@vger.kernel.org Cc: gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, mario.limonciello@amd.com, Mathias Nyman Subject: [PATCH v2 3/4] usb: acpi: add device link between tunneled USB3 device and USB4 Host Interface Date: Fri, 30 Aug 2024 18:26:29 +0300 Message-Id: <20240830152630.3943215-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> References: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Describe the power management relationship between a tunneled USB3 device and the tunnel providing USB4 host with a device link as the relationship between them is not evident from normal device hierarchy. Tunneling capable ports have an ACPI _DSD object pointing to the USB4 Host Interface that is used to establish USB3 3.x tunnels Set the link directly between tunneled USB3 devices and USB4 Host Interface to ensure that the USB4 host can runtime suspend if no tunneled USB 3.x devices exist. Current Thunderbolt code sets a link between USB4 Host Interface and USB3 xHCI host which prevents USB4 Host Interface from runtime suspending even if the USB3 host is only serving native USB devices. See commit b2be2b05cf3b ("thunderbolt: Create device links from ACPI description") for details. As the device link is only set for USB3 devices that are already tunneled we know that USB4 Host Interface exists and is bound to its driver. Signed-off-by: Mathias Nyman --- v2: - Don't check twice if device is connected to roothub port - also create device link if tunnel mode is unknown and port supports tunneling. drivers/usb/core/usb-acpi.c | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c index 7f8a912d4fe2..21585ed89ef8 100644 --- a/drivers/usb/core/usb-acpi.c +++ b/drivers/usb/core/usb-acpi.c @@ -142,6 +142,53 @@ int usb_acpi_set_power_state(struct usb_device *hdev, int index, bool enable) } EXPORT_SYMBOL_GPL(usb_acpi_set_power_state); +/** + * usb_acpi_add_usb4_devlink - add device link to USB4 Host Interface for tunneled USB3 devices + * + * @udev: Tunneled USB3 device connected to a roothub. + * + * Adds a device link between a tunneled USB3 device and the USB4 Host Interface + * device to ensure correct runtime PM suspend and resume order. This function + * should only be called for tunneled USB3 devices. + * The USB4 Host Interface this tunneled device depends on is found from the roothub + * port ACPI device specific data _DSD entry. + * + * Return: negative error code on failure, 0 otherwise + */ +static int usb_acpi_add_usb4_devlink(struct usb_device *udev) +{ + const struct device_link *link; + struct usb_port *port_dev; + struct usb_hub *hub; + + if (!udev->parent || udev->parent->parent) + return 0; + + hub = usb_hub_to_struct_hub(udev->parent); + port_dev = hub->ports[udev->portnum - 1]; + + struct fwnode_handle *nhi_fwnode __free(fwnode_handle) = + fwnode_find_reference(dev_fwnode(&port_dev->dev), "usb4-host-interface", 0); + + if (IS_ERR(nhi_fwnode)) + return 0; + + link = device_link_add(&port_dev->child->dev, nhi_fwnode->dev, + DL_FLAG_AUTOREMOVE_CONSUMER | + DL_FLAG_RPM_ACTIVE | + DL_FLAG_PM_RUNTIME); + if (!link) { + dev_err(&port_dev->dev, "Failed to created device link from %s to %s\n", + dev_name(&port_dev->child->dev), dev_name(nhi_fwnode->dev)); + return -EINVAL; + } + + dev_dbg(&port_dev->dev, "Created device link from %s to %s\n", + dev_name(&port_dev->child->dev), dev_name(nhi_fwnode->dev)); + + return 0; +} + /* * Private to usb-acpi, all the core needs to know is that * port_dev->location is non-zero when it has been set by the firmware. @@ -262,6 +309,12 @@ usb_acpi_find_companion_for_device(struct usb_device *udev) if (!hub) return NULL; + + /* Tunneled USB3 devices depend on USB4 Host Interface, set device link to it */ + if (udev->speed >= USB_SPEED_SUPER && + udev->tunnel_mode != USB_LINK_NATIVE) + usb_acpi_add_usb4_devlink(udev); + /* * This is an embedded USB device connected to a port and such * devices share port's ACPI companion. From patchwork Fri Aug 30 15:26:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 825276 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (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 DC9F41B5818 for ; Fri, 30 Aug 2024 15:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031482; cv=none; b=L8CaQ9ndZgsu92hnyz2+nZJV2TnJUoinJPjWu2B1X9K75BwZjrsrbBhtFbHJSmMJFCiCqkJ/UJxdu0NfxoTtk6rl+TBLp7rITzxYzcEzHfwE4z8JgiVhcIEcBFPNlSF2FotsKw3whw/jVkCj0d1l5MAjuLXqQdV2xZBX+kb2hpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725031482; c=relaxed/simple; bh=1a4BEl/a3n4EvTDjun1yx6BvmqO2xegJ6/FvOKAhuK4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Trq2pHbM7Zozwn2Q2YEukMYxfXAAlLcAW5pN4TlOhvhJKrJOmPcifnSog2K33h/VcwvpEvx9OVEa46eeULA4tRNj1Sah9zDd6W3rii62SBnEQGbqwwwiTah/kpEbX+vfAbrU6tfiiLJkpEuYFu9VNQMz0MHtwstXJY4ghA97i9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ANos+/Ru; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ANos+/Ru" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1725031481; x=1756567481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1a4BEl/a3n4EvTDjun1yx6BvmqO2xegJ6/FvOKAhuK4=; b=ANos+/Ru0VDLfdYKFyKk9U7650jejw8Wlsx807sEB1oVYfTdsl/aaM5+ m0ikBgCWLGHFOvB2IwVPg3EnffpYxPEuOPw0bALknHoD8oGoZ3zPAuJDY gCQZq4pnQMuqMZ0HYQihZkwQtDgrVNYvKoI1CHp6sn2BEBF44YSQK6EH3 7lyLHcfmMkQ1MGSHTWo92rpe37M28+XhiyktVGppl4J1MZfVs4c0Ptgh2 a5k3jEkFRdpMp4kdfh9jxjfq8rd6OIDvz2J49p9UgqGQXc8i9NUSaHp1P nSqH0+8OwGnDk0ffF0F87uyMreodd3Hr9iXsWdiZp7EHT/q2E+nzzR+eY w==; X-CSE-ConnectionGUID: EelKEML2R4Ss6Dtbf7W/3A== X-CSE-MsgGUID: tKygKLxoT52pxBGeb69Skg== X-IronPort-AV: E=McAfee;i="6700,10204,11180"; a="23861963" X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="23861963" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2024 08:24:40 -0700 X-CSE-ConnectionGUID: sBzy5m+3SZqGs5Bik6+GOQ== X-CSE-MsgGUID: KYqLVH3YRRO82D+kCxPh9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,189,1719903600"; d="scan'208";a="63981655" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by fmviesa009.fm.intel.com with ESMTP; 30 Aug 2024 08:24:38 -0700 From: Mathias Nyman To: linux-usb@vger.kernel.org Cc: gregkh@linuxfoundation.org, mika.westerberg@linux.intel.com, mario.limonciello@amd.com, Mathias Nyman , Rajaram Regupathy , Saranya Gopal Subject: [PATCH v2 4/4] thunderbolt: Don't create device link from USB4 Host Interface to USB3 xHC host Date: Fri, 30 Aug 2024 18:26:30 +0300 Message-Id: <20240830152630.3943215-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> References: <20240830152630.3943215-1-mathias.nyman@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 USB core will create device links between tunneled USB3 devices and USB4 Host Interface during USB device creation. Those device links are removed with the tunneled USB3 devices, allowing USB4 Host Interface to runtime suspend if USB3 tunnels are not used. So remove device link creation between USB4 Host Interface and USB3 xHC during NHI probe Reported-by: Rajaram Regupathy Reported-by: Saranya Gopal Tested-by: Saranya Gopal Acked-by: Mika Westerberg Signed-off-by: Mathias Nyman --- v2: no change drivers/thunderbolt/acpi.c | 40 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/drivers/thunderbolt/acpi.c b/drivers/thunderbolt/acpi.c index c9b6bb46111c..d2a0054217da 100644 --- a/drivers/thunderbolt/acpi.c +++ b/drivers/thunderbolt/acpi.c @@ -32,40 +32,20 @@ static acpi_status tb_acpi_add_link(acpi_handle handle, u32 level, void *data, goto out_put; /* - * Try to find physical device walking upwards to the hierarcy. - * We need to do this because the xHCI driver might not yet be - * bound so the USB3 SuperSpeed ports are not yet created. + * Ignore USB3 ports here as USB core will set up device links between + * tunneled USB3 devices and NHI host during USB device creation. + * USB3 ports might not even have a physical device yet if xHCI driver + * isn't bound yet. */ - do { - dev = acpi_get_first_physical_node(adev); - if (dev) - break; - - adev = acpi_dev_parent(adev); - } while (adev); - - /* - * Check that the device is PCIe. This is because USB3 - * SuperSpeed ports have this property and they are not power - * managed with the xHCI and the SuperSpeed hub so we create the - * link from xHCI instead. - */ - while (dev && !dev_is_pci(dev)) - dev = dev->parent; - - if (!dev) + dev = acpi_get_first_physical_node(adev); + if (!dev || !dev_is_pci(dev)) goto out_put; - /* - * Check that this actually matches the type of device we - * expect. It should either be xHCI or PCIe root/downstream - * port. - */ + /* Check that this matches a PCIe root/downstream port. */ pdev = to_pci_dev(dev); - if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI || - (pci_is_pcie(pdev) && - (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || - pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM))) { + if (pci_is_pcie(pdev) && + (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT || + pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM)) { const struct device_link *link; /*