From patchwork Wed Jun 19 13:03:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 13703816 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 F40D4145B09 for ; Wed, 19 Jun 2024 13:01:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802076; cv=none; b=k2bN293ye4MLnnzhQBIlhz0mjvfM3WPck9A7f4rOdypfSN36ifmi+CVJ31H/eVPGojSyPFkqIADGXO7IgJ8/FC74uTlAlGO1rvxvIiUBjyppPe4QNy5HXsKInyXEATmF2g41qFgc3BHd5k/1HeqqqFiEfgzKHr5V9T/QXm7LZ/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802076; c=relaxed/simple; bh=ErXBcQVpgZwVMiOGg1Byo/CgnZ1ue/CgTDjsTMPKvUk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m9tiN1ZPuQLSmxqZTcyUflHlX9gCt1fTsmLkFZ99B0L26M34pSqNwYQFNjlXdnaZ9AnWu3zxsBVd4zzzcwIgWwa6SNCUrdoKjMMfaY+28Yz8ZRIPg6mQY5ynDZgVjrMMV8sIuuyQpLzbO+6o1n4sqnLw8eLZuEXg3xMvGZB1UX0= 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=AAqxHcoi; arc=none smtp.client-ip=198.175.65.16 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="AAqxHcoi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718802076; x=1750338076; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ErXBcQVpgZwVMiOGg1Byo/CgnZ1ue/CgTDjsTMPKvUk=; b=AAqxHcoiIXbPjPVFW+5+Sihpb4GVnDZTIiupaT7lCqAiF4Z2Yh9g6dNu cGxUFn5xYMIGV4oskacwXmIJ600jF/Oenhg5gz56HTdBsIkcTm6M0EHSi XioI0VeeMzgR6jCLnVB+7E5WBpeqXvr14SKk33R4l7Nr3c3VcrLrO8lfK ZWdqZBDcXrEtSt4Y3eSYNCd5cN+RHxixUI65yxzr95E6T3IMPdE+JbLZ9 Qf6MWM5UqkiFf+XyPsnT4FzeJs0QA9sOhhQV1ZeCaC8/Ft9oXwiWvqPTC pAguBEnzYJiYkig5PbZA5WPSR/Gqk0HQShsokg+CROgebzvFgcOKVRCpI A==; X-CSE-ConnectionGUID: VrvpUzUxSL6nT9wFFr2NQQ== X-CSE-MsgGUID: Cn6s3UA+TjWLUAbFA1N/xw== X-IronPort-AV: E=McAfee;i="6700,10204,11107"; a="15868291" X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="15868291" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2024 06:01:15 -0700 X-CSE-ConnectionGUID: txj8F0Q1TRueFL2a662Fqw== X-CSE-MsgGUID: T/p/uuDQTPe890GWf+9yKA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="47040468" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orviesa004.jf.intel.com with ESMTP; 19 Jun 2024 06:01:13 -0700 From: Mathias Nyman To: , Cc: mika.westerberg@linux.intel.com, Mathias Nyman Subject: [PATCH 1/4] xhci: Add USB4 tunnel detection for USB3 devices on Intel hosts Date: Wed, 19 Jun 2024 16:03:02 +0300 Message-Id: <20240619130305.2617784-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240619130305.2617784-1-mathias.nyman@linux.intel.com> References: <20240619130305.2617784-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 --- drivers/usb/host/xhci-ext-caps.h | 5 +++++ drivers/usb/host/xhci-hub.c | 29 +++++++++++++++++++++++++++++ drivers/usb/host/xhci.c | 11 +++++++++++ drivers/usb/host/xhci.h | 1 + 4 files changed, 46 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..a8043c15a390 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -752,6 +752,35 @@ 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; + return !!(readl(base + offset) & XHCI_INTEL_SPR_TUNEN); + } + + 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 37eb37b0affa..a85173098de1 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4513,6 +4513,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 78d014c4d884..d9f706d80ac6 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1926,6 +1926,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 Wed Jun 19 13:03:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 13703817 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 34A7714532C for ; Wed, 19 Jun 2024 13:01:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802077; cv=none; b=XQ0q1Fdc3c2BVwnd1xcd/7JvEgbNukfipWloJdnFtxhQv78HwVI3sw4kb3ryvjoxXrgzbi607IHcweG2xOxJlv3PNG+6K+6p1OVfGrwYeDPR6fXd/HlRKFUSXJkhGhoKVXz8ptf+pzhK8W9udRN1Y8HSOBsbwq6Zcs+MsFEmGCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802077; c=relaxed/simple; bh=ylzkqJRVSfHTqISmIX8Uzce5RftmPAJfUFfEbR666a4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=its87Ab0Yt+l6lIY6l6eDROlDNkwRMnESHbVEjkiBS3RL7hIaMn0QDia4sDNQaIL/xbSkGO31Qsm2khajiRryMJKmLDGWa1L44w3o5y0x/tcyOfWqDdmggLiXp5c1cpY8qSrhO/bgeG/uwfITyTk8fr/0rKhP14WziiSjhJ8jHE= 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=KZxieKUU; arc=none smtp.client-ip=198.175.65.16 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="KZxieKUU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718802077; x=1750338077; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ylzkqJRVSfHTqISmIX8Uzce5RftmPAJfUFfEbR666a4=; b=KZxieKUUyUcS1J0JLY5OCaNFGo14hgmW8YVCcxvqBdu8VKMVMmoqrA9c xgBOvffSWjgbeSFtfBkopnrLxBDwwf+Pw1aB0wrnWhYhtSsgcvKheWxol YYVcDYZczDOBVs7afhmNttjuak2g4O3YvFjKdkvw6KWXvrv9t4RDg3Whj B+H0tmd7uqsQ28EfO4FlDxjxqxAopCb/Wui6Vv9CwatXPfVOGYU1WswiM L35CTpZ3cxonojjzfRVWwHuBqh3V//yMGKZ2hhY+V7miPiawDjVfREGXh flUwNSNll8gHoXqRaJAC77ykZM1j9vOoXJvMbCfB8m8B981KtflfKsOOM w==; X-CSE-ConnectionGUID: f5wlooCVRfmNOJxljiofdw== X-CSE-MsgGUID: biNVa49cSb6amsiyB7Q8aA== X-IronPort-AV: E=McAfee;i="6700,10204,11107"; a="15868294" X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="15868294" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2024 06:01:17 -0700 X-CSE-ConnectionGUID: LuQgVL5lRi2Sw96F1VuMOQ== X-CSE-MsgGUID: H2dNWCbcRt6YvSdJ08JFtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="47040483" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orviesa004.jf.intel.com with ESMTP; 19 Jun 2024 06:01:15 -0700 From: Mathias Nyman To: , Cc: mika.westerberg@linux.intel.com, Mathias Nyman Subject: [PATCH 2/4] usb: Add tunneled parameter to usb device structure Date: Wed, 19 Jun 2024 16:03:03 +0300 Message-Id: <20240619130305.2617784-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240619130305.2617784-1-mathias.nyman@linux.intel.com> References: <20240619130305.2617784-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 'tunneled' parameter to usb device structure to describe if a device connection is tunneled over USB4 or connected directly using native USB2/USB3. 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 have vendor specific ways to detect tunneled connections. This 'tunneled' parameter can be set by USB3 host driver during hcd->driver->update_device(hcd, udev) callback Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 3 ++- include/linux/usb.h | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index a85173098de1..e11251e3e4fc 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4517,7 +4517,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]; - if (xhci_port_is_tunneled(xhci, port)) + udev->tunneled = xhci_port_is_tunneled(xhci, port); + if (udev->tunneled) dev_dbg(&udev->dev, "tunneled over USB4 link\n"); else dev_dbg(&udev->dev, "native USB 3.x link\n"); diff --git a/include/linux/usb.h b/include/linux/usb.h index 1913a13833f2..a4c5c09ea2bd 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -605,6 +605,7 @@ struct usb3_lpm_parameters { * WUSB devices are not, until we authorize them from user space. * FIXME -- complete doc * @authenticated: Crypto authentication passed + * @tunneled: Connected to root port and 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 @@ -685,6 +686,7 @@ struct usb_device { unsigned have_langid:1; unsigned authorized:1; unsigned authenticated:1; + unsigned tunneled:1; unsigned lpm_capable:1; unsigned lpm_devinit_allow:1; unsigned usb2_hw_lpm_capable:1; From patchwork Wed Jun 19 13:03:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 13703818 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 0ADBF14F9FE for ; Wed, 19 Jun 2024 13:01:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802079; cv=none; b=G6d+GQIiNnbLSU1vtPeJLnkxmKxfgMfUlILe9g/WOpPdpfvMkjEaa8XcvHG4AxGy6uEqietJ9zWa18Yoc7dgBjxipiZWX8xDEyb6v+jGXPb9oSHADexB9WyLg6rfmF/rbQp3KUnV32kB89vnTnOpzotu/lMVf3h07mUehYy/VmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802079; c=relaxed/simple; bh=09SbUEks1l3icVqzm4T5A7DqT95CQcinB29fS88rk/c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=caA8j7pGzvLwreOZ/HyttdSWwqp53bQH3UFuwVFQQQ6J8Dus+mld+5X5uzwcG6nEuRg9uZNZ9vfszCU6QPrUkkNwO4iZ/4eIZT2UWxrv9MSatqXdC+50nGcCFklWsCImZWnmUbGSDO1DaT+Kh6Wqt4UXBfEXOD6EDIPaTtqnREI= 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=QjWJdg7V; arc=none smtp.client-ip=198.175.65.16 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="QjWJdg7V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718802079; x=1750338079; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=09SbUEks1l3icVqzm4T5A7DqT95CQcinB29fS88rk/c=; b=QjWJdg7VIoa+3GcixPTr8ynd9qz+DMOmEUUfHGYcK3Uh46OnZ4hFRBWR EWoxYlCcaWw6mkKfWgH3leYDSkk9/DG8uGKoh7qV6W7O3Rv5cRVCV/UKV XpjOinos/Pbm3L2uvn1/UhVMnTasD1wGwxhKMmxZEGBpq28ScYXLI7Eqf HSb/PyIYgi3tMrZntyMXMZOrX1GMPf769Hn24OTZsSIikl9Ej5zIHraPM 91TbRyP+7C8lnQT2yafvmoI0vwkCoTnFTym8vLvdZgTSCQme2IxkgZ+t2 unZo/ACwt+eQE5XtFKkQ6Sc7r5adpoYjwRoni0iOfkQwDfRq3+6FP5l6k A==; X-CSE-ConnectionGUID: Pb5NZhGdS0ezdqL/PzqW3A== X-CSE-MsgGUID: bcdQPQbjSNaEiTD3Pcfh1Q== X-IronPort-AV: E=McAfee;i="6700,10204,11107"; a="15868303" X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="15868303" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2024 06:01:18 -0700 X-CSE-ConnectionGUID: VQWu1qSkQ/a2w5qAG04QFA== X-CSE-MsgGUID: dYSl8vg+SY+GyuaJyWKWgQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="47040516" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orviesa004.jf.intel.com with ESMTP; 19 Jun 2024 06:01:16 -0700 From: Mathias Nyman To: , Cc: mika.westerberg@linux.intel.com, Mathias Nyman Subject: [PATCH 3/4] usb: acpi: add device link between tunneled USB3 device and USB4 Host Interface Date: Wed, 19 Jun 2024 16:03:04 +0300 Message-Id: <20240619130305.2617784-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240619130305.2617784-1-mathias.nyman@linux.intel.com> References: <20240619130305.2617784-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 --- drivers/usb/core/usb-acpi.c | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c index 7f8a912d4fe2..316bcc168e76 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,11 @@ usb_acpi_find_companion_for_device(struct usb_device *udev) if (!hub) return NULL; + + /* Tunneled devices depend on USB4 Host Interface, set device link to it */ + if (udev->tunneled && !udev->parent->parent) + 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 Wed Jun 19 13:03:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 13703819 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 E638315098D for ; Wed, 19 Jun 2024 13:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802081; cv=none; b=m7m8xAn4flR/5b4c1cH8P7b6CK0IecvXQuPL9Ckm+DD0lqumQVXGbfGWD46tdQHXoHD3IoGWZNEdkSM+fMoUz9ADsHXCYCh0NZHl0voMT3FebC+/wueMZqHr317y0Sppn/ifrgCrnYayrAJEKdzYrLSdIykVDWye9icAb5IW43M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718802081; c=relaxed/simple; bh=ETz0h53BYwLAJiwuFSFgaqF56R5KnO4eNd47Q3C+Wt8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pbHQIx1z/lGdm9ZUaDrXOhwcDNDmXyA8yMoDYAoDpQte7Fon80lj8AKB75CtaL9cJROXog4eyB5BttFz/eTz0XX9uvhREHGu9DA25R8Sdvh6lVWxj4eIZlKnP/2WycW2wHIzJTuZtomiOI8Fvbw9wcKtSxSCSSSRjqAZNgmlqkw= 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=Zs1TLHf5; arc=none smtp.client-ip=198.175.65.16 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="Zs1TLHf5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718802081; x=1750338081; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ETz0h53BYwLAJiwuFSFgaqF56R5KnO4eNd47Q3C+Wt8=; b=Zs1TLHf5vA34XPZ3dtNBz8/cdRz6uZKGSH3CpxF9ehzICxpt2qEPvrA/ 0CejnIA4562XXdi7D+pAQTyOquiYLYVuFkdGEbfQW7ftNIc7RHeDn4STH hpHOGFfXC4l6fXGHg7MGLpMgueVNh4oAh8RLo9lGuciTdkn2qWT90H/Wy Ep39ftKdyGWh3455Tay7CGovBtUhrcDHEne/jTf5FyR3vCL5LPzGEPxdZ IkTXDjz6DJ8KkBjEdNMQzydzdrOAqOpcwcajfKbVUAjOUcDH62+7R2RWY kSjIuFdzb/+Zrhrv6zSUXPpt2BlR8fuYp3YYqmAJ781Yvgh8plOaCYpEk g==; X-CSE-ConnectionGUID: Utz5WnQ8Qr2+O+DK82xp4w== X-CSE-MsgGUID: hhR20SY1TkOenUiMLrCtpQ== X-IronPort-AV: E=McAfee;i="6700,10204,11107"; a="15868311" X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="15868311" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2024 06:01:20 -0700 X-CSE-ConnectionGUID: T2XUgqX/S36QtffRnmehfA== X-CSE-MsgGUID: 6FOrCKOxQzqfwUBPNdDF7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,250,1712646000"; d="scan'208";a="47040555" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orviesa004.jf.intel.com with ESMTP; 19 Jun 2024 06:01:18 -0700 From: Mathias Nyman To: , Cc: mika.westerberg@linux.intel.com, Mathias Nyman , Rajaram Regupathy , Saranya Gopal Subject: [PATCH 4/4] thunderbolt: Don't create device link from USB4 Host Interface to USB3 xHC host Date: Wed, 19 Jun 2024 16:03:05 +0300 Message-Id: <20240619130305.2617784-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240619130305.2617784-1-mathias.nyman@linux.intel.com> References: <20240619130305.2617784-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 --- 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; /*