From patchwork Fri Mar 14 14:19:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 14016942 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 A28C5200BB4 for ; Fri, 14 Mar 2025 14:19:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961949; cv=none; b=olAfzqEH0bSV9HBRXF92mvWBcOaGk4nJooYSvSiNIjo9gYrHdjT0uv1JocwQxebQKD2a2MD+7K1ov5DmMVEFhc/VHOE73rx1BxHqzVBHvnKgV4KjqxUzjx4M6IG98oF2hIv5C5hg/iFfjYdhK3z+eXFLU56+drTg0n4j8fVVILw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961949; c=relaxed/simple; bh=NjjW5EwZ660z+fPfGwHw1nEvTxWFsgchgPxMSZ3mVAw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iGrlY9A0D1LurJBDi0gyG2PEYqnlovOLjP0K+KqW4nDAlal5KC+I9j1hlsRNvlAiK5ApwBS4uH9FZjuxC0+GJKcNXttop7SInJiAAziWWoPQVtTR1T6QFF2FtmdJ4aobfwXctqwMnMelZiQEdZsC0SyxlCXTU6BmCBzxxy0nDmo= 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=TE4QJm/r; arc=none smtp.client-ip=198.175.65.13 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="TE4QJm/r" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741961947; x=1773497947; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NjjW5EwZ660z+fPfGwHw1nEvTxWFsgchgPxMSZ3mVAw=; b=TE4QJm/rgC9stipTrjYhbqxokrvUoNHvLSLm1ZTlyddrO3K6p47ddutq j13xw0Utl9uQ4F15ydfZxIb2T7uMg4MtPw4NICfj7nNihQNfhvuPzt+rT 5W7YpCcInBTmh/zmGAn3yva47tumYxm8Cw07NhhCtU9O3u0Ci6QZHRHKY Zr1oIVMt21V7iMj4Q5q+PPHc9BIRrPN2IomcDH6uXt2P5hf7MDl/SOa95 KrEbrYhR6fpIX2faOs1uIF5gDyDDw/Xfbnw8QdW4GVhq30KV3kBGCU8TM CyTaqmr9hUiRLwM2KbE+aNf03KlBqt14gDv5I8QjnnGRrNGn806GgC+CC w==; X-CSE-ConnectionGUID: 6wU1psy6QEivQhYg74fWpg== X-CSE-MsgGUID: GYuhOsHhQwq77P8ov9eRBg== X-IronPort-AV: E=McAfee;i="6700,10204,11373"; a="54110142" X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="54110142" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2025 07:19:07 -0700 X-CSE-ConnectionGUID: nOJkkT7DTjmLJlf9NHUT7w== X-CSE-MsgGUID: fvj4MEu5S3yO6ahK/YKOkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="126166605" Received: from unknown (HELO mattu-haswell.fi.intel.com) ([10.237.72.199]) by orviesa003.jf.intel.com with ESMTP; 14 Mar 2025 07:19:06 -0700 From: Mathias Nyman To: Cc: , , Mathias Nyman Subject: [PATCH 1/5] usb: hub: Block less in USB3 link power management LPM disable path Date: Fri, 14 Mar 2025 16:19:56 +0200 Message-ID: <20250314142000.93090-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314142000.93090-1-mathias.nyman@linux.intel.com> References: <20250314142000.93090-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 Several usb requests are needed to allow or forbid a USB3 link from going into U1 or U2 hardware link power management (LPM) states. Fail fast on issues in LPM disabling path. LPM disabling is done in hub workqueue paths that are often already handling possible link issues. Enabling and disabling LPM involves four usb requests. Two requests sent to the upstream hub of the connected device: SetPortFeature(U1_TIMEOUT) SetPortFeature(U2_TIMEOUT) And two to the device itself: SetFeature(U1_ENABLE) SetFeature(U2_ENABLE) The requests to the hub sets the inactivity timeout used by the hub to know when to initiate U1 and U2 LPM link state transitions. These requests are also used prevent U1/U2 LPM transitions completely by passing zero timeout value. The requsts sent to the device only controls if device is allowed to initiate U1/U2 transitions. If not enabled then only hub initiates U1/U2 transitions. Hub may block these device initiated attempts. Reorder and send the hub requests first, these are more likely to succeed due to shorter path, and we can consider LPM disabled if these succeed as U1/U2 link state can not be entered after that. Fail immediately if a request fails, and don't try to enable back LPM after a failed request, that will just send more LPM requests over a bad link. If a device request controlling device initiateed LPM fails then exit immediately, but consider LPM disabled at this stage. Signed-off-by: Mathias Nyman --- drivers/usb/core/hub.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 8c7f9cc785bb..a901d1b55856 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -4393,8 +4393,6 @@ static int usb_disable_link_state(struct usb_hcd *hcd, struct usb_device *udev, if (usb_set_lpm_timeout(udev, state, 0)) return -EBUSY; - usb_set_device_initiated_lpm(udev, state, false); - if (hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state)) dev_warn(&udev->dev, "Could not disable xHCI %s timeout, " "bus schedule bandwidth may be impacted.\n", @@ -4424,6 +4422,7 @@ static int usb_disable_link_state(struct usb_hcd *hcd, struct usb_device *udev, int usb_disable_lpm(struct usb_device *udev) { struct usb_hcd *hcd; + int err; if (!udev || !udev->parent || udev->speed < USB_SPEED_SUPER || @@ -4441,14 +4440,19 @@ int usb_disable_lpm(struct usb_device *udev) /* If LPM is enabled, attempt to disable it. */ if (usb_disable_link_state(hcd, udev, USB3_LPM_U1)) - goto enable_lpm; + goto disable_failed; if (usb_disable_link_state(hcd, udev, USB3_LPM_U2)) - goto enable_lpm; + goto disable_failed; + + err = usb_set_device_initiated_lpm(udev, USB3_LPM_U1, false); + if (!err) + usb_set_device_initiated_lpm(udev, USB3_LPM_U2, false); return 0; -enable_lpm: - usb_enable_lpm(udev); +disable_failed: + udev->lpm_disable_count--; + return -EBUSY; } EXPORT_SYMBOL_GPL(usb_disable_lpm); From patchwork Fri Mar 14 14:19:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 14016943 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 E90BC1FF614 for ; Fri, 14 Mar 2025 14:19:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961950; cv=none; b=lzNataofMTkcxMhC5gwaY8MT+a1P3XExCDO6L3/SMF23CJdTnN0YQotw1LUTP8hjygn962/EQM5zXK+RBXdbkaaukVHSKpMl2EUNNw0gVRuoAWbYjm5YXWjCO+v3YalMRwC8KBA2trPEpXeIikqVDVFnDc4zvugFuyLiOEkHHyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961950; c=relaxed/simple; bh=vMVtQLokhItnd46Va42rAPOljM3qfa9Cd+5cvihC9Vw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T+VTVm8JodRURq1/sJotNbe79lux0tFtXUpeZE6CSygzCmEMnpCWMmwvS9BFFdoXXkEnFMP+3gVH933EuoxKxv9Y3l87qrxTFFZFMHl2gkW+C2aiE+EHiz3TtQa5za9SdZRg3XTyPL4EOLeypvOqFGGWaUEi/qD0ZFVsyAw4y5c= 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=I+GTUbpx; arc=none smtp.client-ip=198.175.65.13 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="I+GTUbpx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741961949; x=1773497949; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vMVtQLokhItnd46Va42rAPOljM3qfa9Cd+5cvihC9Vw=; b=I+GTUbpxjZUvJfI5AP0NudMk+j6VXpQUGVyVMaSDiKSE3ypcYpUvXcNz P52vJ/o0lxpAsERh97KmoE8Ra+VkNqZiYs16kYaRwo1udgESv8fCYSlQz ovktyVfieJdnJTyxAVG5bp3IE2CarJx5aFCFRumRXtnftoXz5lTNWERqZ 549CENKLZnTR+Hho2y6mThmMl0QymR5y+3+9Mjqwx1kxE7YNuXbB83Vo+ 6JCTHWpE2riowjEyExODpmV/cZDLmGQp+g/6oHUt82FvySH/uZrqhtGNP BtR6TY954kI+1viEQQMeFZn1OTRbBNdzYpzXCJcwFIzGphU47VdefAo+b A==; X-CSE-ConnectionGUID: jOrpKahNSr2MyIdKPb4OuQ== X-CSE-MsgGUID: NaKT8tA/QECDr19nzmQ56g== X-IronPort-AV: E=McAfee;i="6700,10204,11373"; a="54110147" X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="54110147" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2025 07:19:09 -0700 X-CSE-ConnectionGUID: wt4raNPMSWuva8a/K0YCSA== X-CSE-MsgGUID: FzNDiK5JSAK3Wa4v2bo7FQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="126166606" Received: from unknown (HELO mattu-haswell.fi.intel.com) ([10.237.72.199]) by orviesa003.jf.intel.com with ESMTP; 14 Mar 2025 07:19:08 -0700 From: Mathias Nyman To: Cc: , , Mathias Nyman Subject: [PATCH 2/5] usb: hub: verify device is configured in usb_device_may_initiate_lpm() Date: Fri, 14 Mar 2025 16:19:57 +0200 Message-ID: <20250314142000.93090-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314142000.93090-1-mathias.nyman@linux.intel.com> References: <20250314142000.93090-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 Move device configured check into usb_device_may_initiate_lpm() instead of calling it before the function. No functional changes, helps rework to fail faster during link power management (LPM) enabling. Signed-off-by: Mathias Nyman --- drivers/usb/core/hub.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index a901d1b55856..10ef9f51fcfd 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -4234,9 +4234,9 @@ static int usb_set_lpm_timeout(struct usb_device *udev, } /* - * Don't allow device intiated U1/U2 if the system exit latency + one bus - * interval is greater than the minimum service interval of any active - * periodic endpoint. See USB 3.2 section 9.4.9 + * Don't allow device intiated U1/U2 if device isn't in the configured state, + * or the system exit latency + one bus interval is greater than the minimum + * service interval of any active periodic endpoint. See USB 3.2 section 9.4.9 */ static bool usb_device_may_initiate_lpm(struct usb_device *udev, enum usb3_link_state state) @@ -4244,7 +4244,7 @@ static bool usb_device_may_initiate_lpm(struct usb_device *udev, unsigned int sel; /* us */ int i, j; - if (!udev->lpm_devinit_allow) + if (!udev->lpm_devinit_allow || !udev->actconfig) return false; if (state == USB3_LPM_U1) @@ -4341,11 +4341,11 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, return; } - /* Only a configured device will accept the Set Feature - * U1/U2_ENABLE + /* + * Enable device initiated U1/U2 with a SetFeature(U1/U2_ENABLE) request + * if system exit latency is short enough and device is configured */ - if (udev->actconfig && - usb_device_may_initiate_lpm(udev, state)) { + if (usb_device_may_initiate_lpm(udev, state)) { if (usb_set_device_initiated_lpm(udev, state, true)) { /* * Request to enable device initiated U1/U2 failed, From patchwork Fri Mar 14 14:19:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 14016944 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 A479B20101F for ; Fri, 14 Mar 2025 14:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961952; cv=none; b=BdiMeMPJcixBlzbjTmJaJNPjXKrWPULTbb18r2wS9VAWEB81qM+ek4alcomDOGpw2L28sdANm1DqbOC3PxdyMDrYVsJ5+y5S7lM7dtU+RxOJNqRitaNZRJA3PI/qAd+qP1s9R4eW+Gn2y1Cv05UCt5vZJ7NiA4R7PnlwdzSYNYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961952; c=relaxed/simple; bh=AZnpE+rtQRbfFA3eATrG8KPBkaBWYrXwOyqcHFg/2CE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jb5EmYyGe+1w1ZK7G5kqbt4VI7u+LTcsqgAcyxZVmDUP0WeHBiq3KxJT9v4zOV3GPTyS+oFsgOYiq0zT9EHA1koL+eeFVGjMGbhKTPS+a4fewFdqvYnMZp/HuWkTAd3elyKvr6YHdlhmMR3sgxvsjwRARy5pKxsZ0RoiwS07aZE= 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=bqgWAuFH; arc=none smtp.client-ip=198.175.65.13 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="bqgWAuFH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741961950; x=1773497950; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AZnpE+rtQRbfFA3eATrG8KPBkaBWYrXwOyqcHFg/2CE=; b=bqgWAuFHRpDd8tsROd0RcbnyeGqLc2tKC9JD9tfOrceRExmy2shN/rmi bNYuitMo+SeOrmoj4G7yfMtDFyrdVS4uUWMKSb8C/GFoAswspjEQyzjYx 81DOxC8j1O2f7pPNMQSZNpdrLsT+SYTCscFPKZ450Sq/u+nI83ENawVCm SRWPXYzLdDozeJ1pOLj4o9QkT/N0zYrnAi53nvFyQFkRsnEf4jo0xDEkI EnPYGB/eMxUwZylc81aBYrFI8yYxiTjqeW/62L6fcUhDe02D4NkSXtfm7 jqZPrcPsz6PwRLLspjMZMXD9wILQubO30N5Z3ppQV12XNhVxM6Ni9Iqup Q==; X-CSE-ConnectionGUID: FrhKfpTET5Gs/rpay6t8zw== X-CSE-MsgGUID: Gc9L/JhnTpua6w9CzZYE/Q== X-IronPort-AV: E=McAfee;i="6700,10204,11373"; a="54110156" X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="54110156" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2025 07:19:10 -0700 X-CSE-ConnectionGUID: femo6hhrSsSEm+KWAJdofQ== X-CSE-MsgGUID: Y5BdotXbT7GfLbOKAetlEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="126166608" Received: from unknown (HELO mattu-haswell.fi.intel.com) ([10.237.72.199]) by orviesa003.jf.intel.com with ESMTP; 14 Mar 2025 07:19:09 -0700 From: Mathias Nyman To: Cc: , , Mathias Nyman Subject: [PATCH 3/5] usb: hub: Don't disable LPM completely if device initiated LPM fails Date: Fri, 14 Mar 2025 16:19:58 +0200 Message-ID: <20250314142000.93090-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314142000.93090-1-mathias.nyman@linux.intel.com> References: <20250314142000.93090-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 Enabling device initiated USB3 link power management (LPM) may fail for various reasons such as too long system exit latency, or link issues. These are not good reason to disable hub initiated LPM U1/U2 states, especially as it requires sending more requests over a possibly broken link, causing the hub work to block for even longer. Signed-off-by: Mathias Nyman --- drivers/usb/core/hub.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 10ef9f51fcfd..ccf21bb49038 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -4345,17 +4345,8 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, * Enable device initiated U1/U2 with a SetFeature(U1/U2_ENABLE) request * if system exit latency is short enough and device is configured */ - if (usb_device_may_initiate_lpm(udev, state)) { - if (usb_set_device_initiated_lpm(udev, state, true)) { - /* - * Request to enable device initiated U1/U2 failed, - * better to turn off lpm in this case. - */ - usb_set_lpm_timeout(udev, state, 0); - hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); - return; - } - } + if (usb_device_may_initiate_lpm(udev, state)) + usb_set_device_initiated_lpm(udev, state, true); if (state == USB3_LPM_U1) udev->usb3_lpm_u1_enabled = 1; From patchwork Fri Mar 14 14:19:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 14016945 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 B7D45201027 for ; Fri, 14 Mar 2025 14:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961954; cv=none; b=eIlt25dz/n6b6FtjHILkPXLFlLgjkOs3Cjj17/XrL7vzIswmYADZ5W7vsWYGakzWmRccG87DZq5aDu7Sq0GDEC9F9BISYlvJy6IOETMMy3pUPeqN/0JRMAd7F0J4raR4SGBJJuKy9eYtwo2GhHKlYmXOR6hx4Y+1KktyK5vjfHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961954; c=relaxed/simple; bh=qdZZ0iXnfuZAs12kkSgk+SsR/XyfaLDoZgkIwpNx5ak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XGWsV3KljgDzMW3+MNZKYV2jzDK5bDXFSn3lir+t+Pf0K6V+3uCsxoRS5YPAQJATMRFTVk/Vg9Q8iInF/lwXXiiwRTW3sr8iFnzWD2W+pfCsS0+vTY3hRy7MlOrly85KB8T+2qz7GpftxrbC0suPbbLUHXXcFx+TOB4CEUAI6/E= 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=KycdjEwD; arc=none smtp.client-ip=198.175.65.13 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="KycdjEwD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741961952; x=1773497952; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qdZZ0iXnfuZAs12kkSgk+SsR/XyfaLDoZgkIwpNx5ak=; b=KycdjEwD1y5Wkx4XU9ZG759KFkE800nArao/r+ML0vVeEDS0FdjXIHHU Y5hw3pJDJWvH/pk1znLQlJ0dNRLlAH96tY2cYUuPGPnYw6GD0GCOJqu6c F2pdIf2xA1R4rg1U6hdiv17V9IZiF/1ICEQCviWZGo+jI6k6iybBNNnty 2r8ajlBPfKW0Bt7FPFTCUJLra6DAqM6VJgKL4ELBA7KJTZ1UO+552kWkd vE57ziwJf3jz63IswLmVoYfxHzFMU9s7mQusHl2+Zwyu3nFH3/6O5w7lq 3qiIfU7Kf4uanmlo9P2V8WagMbnjAeg3UrH5NhedLjrH/U1ucSBpHd6Ge w==; X-CSE-ConnectionGUID: OFFkHvd9QvOt26YV0+NkQA== X-CSE-MsgGUID: cE+tY3fUQjqg4Z6T3GFvVA== X-IronPort-AV: E=McAfee;i="6700,10204,11373"; a="54110161" X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="54110161" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2025 07:19:12 -0700 X-CSE-ConnectionGUID: BlS6wycWRRS17otlZmXe0Q== X-CSE-MsgGUID: j/p4c4VFTUqroC6K1PcLTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="126166611" Received: from unknown (HELO mattu-haswell.fi.intel.com) ([10.237.72.199]) by orviesa003.jf.intel.com with ESMTP; 14 Mar 2025 07:19:11 -0700 From: Mathias Nyman To: Cc: , , Mathias Nyman Subject: [PATCH 4/5] usb: hub: reorder USB3 link power management enable requests Date: Fri, 14 Mar 2025 16:19:59 +0200 Message-ID: <20250314142000.93090-5-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314142000.93090-1-mathias.nyman@linux.intel.com> References: <20250314142000.93090-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 Several usb requests are needed to allow a USB3 link to enter U1/U2 hardware link power management LPM states. Reorder these requests and send the more significant and likely to succeed first. This is similar to the change done for disabling LPM Enable LPM by first sending requests to the upstream hub of the device SetPortFeature(U1_TIMEOUT) SetPortFeature(U2_TIMEOUT) These are more likely to succeed due to the shorter path, and LPM can be considered enabled as link may go to U1/U2 LPM states after those. Send the requests to the device after this, they allow the device to initialte U1/U2 link transitions. Hub can already initiate U1/U2 SetFeature(U1_ENABLE) SetFeature(U2_ENABLE) Fail fast and bail out if a requests to the device fails. This changes device initated LPM policy a bit. Device is no longer able to initiate U2 if it failed or is not allowed to initiate U1. Enabling and disabling Link power management is done as part of hub work. Avoid trying to send additional USB requests to a device when there are known issues. It just causes hub work to block for even longer. Signed-off-by: Mathias Nyman --- drivers/usb/core/hub.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index ccf21bb49038..d534d7b4606c 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -4160,7 +4160,7 @@ static int usb_set_device_initiated_lpm(struct usb_device *udev, "for unconfigured device.\n", __func__, str_enable_disable(enable), usb3_lpm_names[state]); - return 0; + return -EINVAL; } if (enable) { @@ -4341,13 +4341,6 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, return; } - /* - * Enable device initiated U1/U2 with a SetFeature(U1/U2_ENABLE) request - * if system exit latency is short enough and device is configured - */ - if (usb_device_may_initiate_lpm(udev, state)) - usb_set_device_initiated_lpm(udev, state, true); - if (state == USB3_LPM_U1) udev->usb3_lpm_u1_enabled = 1; else if (state == USB3_LPM_U2) @@ -4508,6 +4501,18 @@ void usb_enable_lpm(struct usb_device *udev) if (port_dev->usb3_lpm_u2_permit) usb_enable_link_state(hcd, udev, USB3_LPM_U2); + + /* + * Enable device initiated U1/U2 with a SetFeature(U1/U2_ENABLE) request + * if system exit latency is short enough and device is configured + */ + if (usb_device_may_initiate_lpm(udev, USB3_LPM_U1)) { + if (usb_set_device_initiated_lpm(udev, USB3_LPM_U1, true)) + return; + + if (usb_device_may_initiate_lpm(udev, USB3_LPM_U2)) + usb_set_device_initiated_lpm(udev, USB3_LPM_U2, true); + } } EXPORT_SYMBOL_GPL(usb_enable_lpm); From patchwork Fri Mar 14 14:20:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 14016946 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 7A1D7201012 for ; Fri, 14 Mar 2025 14:19:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961955; cv=none; b=U5j1IBnhVp82ES/CUlHm06JdwKyG3NpOXhF7VLRXSgtcgN2n5c3MaKSmR91YVTCCB2cVrOy6l2PXbUPAfAJ8jco4PUwNKjdxt2qjF8Q1nRzi6kWegERflpWxzcIX8FwTXt/+kYDcCdwr+QAwg+mfAfBamvg58xFg88iPYqqvPAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741961955; c=relaxed/simple; bh=EBxWfDPGME7JNusn1Pq7fGvc0FFQ2l2q9ggDTHVFElE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XXAWoFzbNdkUjMtzSiZ1iqKvILaSuRbxa2QGZTiPEekiFfqn0UWjjb+e32nrQfaO71s3E8c4vupjODl/yBhXKhAbv2CO+l6v0NVoB6pDotmIf2Y3NQe6ZGtvd0PSfB8Hv9z5bGmEJYCbgoIXjnnGQA0wczwDXYVew3Ryn5q7Btg= 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=Wziae2mN; arc=none smtp.client-ip=198.175.65.13 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="Wziae2mN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741961954; x=1773497954; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EBxWfDPGME7JNusn1Pq7fGvc0FFQ2l2q9ggDTHVFElE=; b=Wziae2mNsufb+hE3+fu/eYYKCPxv1j7+qo5ixMrj4Q5yQ9nCzZuR8nhC bwAQZulDBTpmVE3YvAtCE/0vSQkzaVP3Mx92L15JHGFld3V2J31bQJBl4 GxQS5Jonj4fqRmVKUVQ30hfFaW/bK12aRUjxripRkcQpsn/hrcOrDoGu/ PxxCk+i6ucoQOR2Vkxux+TnFS4SbQQki0M2FfisAFYGMaHZhKrwy8c8Qx mRclrU8NKTAsJ90Tl4yoTkiCZ/mJFLv9vSqXsfCBjmyur60kK0q9BaJZP QYlY3IabULNISyMZVHfcKAOpuhm+AlAObns03FcBf+9imHIcbQ5sN9eNQ Q==; X-CSE-ConnectionGUID: 5DKdku1QSeCv+dcUlvptfA== X-CSE-MsgGUID: 46vsXpO5RE6IOQ1D1eRd8A== X-IronPort-AV: E=McAfee;i="6700,10204,11373"; a="54110165" X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="54110165" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Mar 2025 07:19:14 -0700 X-CSE-ConnectionGUID: wrJPNVapQGeX/AL0CXonAQ== X-CSE-MsgGUID: AN7AnobqRF6hh7n9EUUG4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,246,1736841600"; d="scan'208";a="126166613" Received: from unknown (HELO mattu-haswell.fi.intel.com) ([10.237.72.199]) by orviesa003.jf.intel.com with ESMTP; 14 Mar 2025 07:19:13 -0700 From: Mathias Nyman To: Cc: , , Mathias Nyman Subject: [PATCH 5/5] usb: hub: Fail fast in USB3 link power management enable path Date: Fri, 14 Mar 2025 16:20:00 +0200 Message-ID: <20250314142000.93090-6-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314142000.93090-1-mathias.nyman@linux.intel.com> References: <20250314142000.93090-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 Enabling LPM is done in hub workqueue, often in paths handling possible link issues. So fail immediately on USB3 LPM issues and avoid hub wq from unnecessary blocking, thus allowing it to handle other port events faster. Detect errors when enabling U1/U2 link states, and return immediately if there is an issue. Signed-off-by: Mathias Nyman --- drivers/usb/core/hub.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index d534d7b4606c..fe8271f46c35 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -4292,7 +4292,7 @@ static bool usb_device_may_initiate_lpm(struct usb_device *udev, * driver know about it. If that call fails, it should be harmless, and just * take up more slightly more bus bandwidth for unnecessary U1/U2 exit latency. */ -static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, +static int usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, enum usb3_link_state state) { int timeout; @@ -4301,7 +4301,7 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, /* Skip if the device BOS descriptor couldn't be read */ if (!udev->bos) - return; + return -EINVAL; u1_mel = udev->bos->ss_cap->bU1devExitLat; u2_mel = udev->bos->ss_cap->bU2DevExitLat; @@ -4312,7 +4312,7 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, */ if ((state == USB3_LPM_U1 && u1_mel == 0) || (state == USB3_LPM_U2 && u2_mel == 0)) - return; + return -EINVAL; /* We allow the host controller to set the U1/U2 timeout internally * first, so that it can change its schedule to account for the @@ -4323,13 +4323,13 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, /* xHCI host controller doesn't want to enable this LPM state. */ if (timeout == 0) - return; + return -EINVAL; if (timeout < 0) { dev_warn(&udev->dev, "Could not enable %s link state, " "xHCI error %i.\n", usb3_lpm_names[state], timeout); - return; + return timeout; } if (usb_set_lpm_timeout(udev, state, timeout)) { @@ -4338,13 +4338,15 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev, * host know that this link state won't be enabled. */ hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state); - return; + return -EBUSY; } if (state == USB3_LPM_U1) udev->usb3_lpm_u1_enabled = 1; else if (state == USB3_LPM_U2) udev->usb3_lpm_u2_enabled = 1; + + return 0; } /* * Disable the hub-initiated U1/U2 idle timeouts, and disable device-initiated @@ -4497,10 +4499,12 @@ void usb_enable_lpm(struct usb_device *udev) port_dev = hub->ports[udev->portnum - 1]; if (port_dev->usb3_lpm_u1_permit) - usb_enable_link_state(hcd, udev, USB3_LPM_U1); + if (usb_enable_link_state(hcd, udev, USB3_LPM_U1)) + return; if (port_dev->usb3_lpm_u2_permit) - usb_enable_link_state(hcd, udev, USB3_LPM_U2); + if (usb_enable_link_state(hcd, udev, USB3_LPM_U2)) + return; /* * Enable device initiated U1/U2 with a SetFeature(U1/U2_ENABLE) request