From nobody Sun Oct 5 16:18:43 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0DB518C91F for ; Fri, 1 Aug 2025 03:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019639; cv=none; b=DfzmrsITejc2lNl6UD3/mx177ZVH3Kar8opV01GEQ1NQz2xlTrvdMyHaEDwMA0fmS15g/aKqQCoAVQ76pWySOWKfXZeFQI/b7ajLQyr6BanuIACMZ+57W0GKjTR0CmTWcF0Q+7iL5ECFJUbdoiKYBPeez9OjmcLA67YrAc8f/cU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019639; c=relaxed/simple; bh=qw/l+oOIaR35sp4DSrzqYgEX/oL/BUhtqCC1TeZTTIw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=j7umTmXtXd+YqV25+WzZJ3WU0IeziVUzDpN13/QKf5+U0l8atRnmbyz/MBzWLjO5Rnqk9YIe1uT/xsnjxnj98qOIasgJpRFqVrnGztncOkpd63y1+EwtA3wvV4Gd4M4f7xx6Q4A7EEp/nvo6KjsKW3NP0I57kaZ8sUwDDVsy/f0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=hYTY44ZO; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hYTY44ZO" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-75ab147e0f7so1743292b3a.2 for ; Thu, 31 Jul 2025 20:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1754019636; x=1754624436; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/wA8zWj3IHi5EGjxZe0hAzAqxv/u+HvHJFN6V2LV+9w=; b=hYTY44ZOOb16MU8qleS0Lo/G/8Us5GtWBy0FfIn0yeFp5GWgZmdY6m11/yxZxzNObv UxJvU+5+Kb9fID4Maci+/Etfs6BMzOMAQNMBj7vVYx4jxo+l/TM53tqA1USfPwQ3Pnmr ZMa2sF/LELZ/pA5EmbYRLkMDvhVkl40Fd8jA5pEZkb9uaxuhK8SPp3QmxX9x15ntj2SH OWbMhB6JuajSTHG4jADcbw1XMOTxZ7sgxEhZAh1gdeOoT3xI1ebSZe8zwbsuOri79Q98 pcGGHZfSVA0cm5gqZad996DcMNKn+r5aK1fskOGNRU903Px4v1b1rXg6Gpr7xrqjdv1A Y/jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754019636; x=1754624436; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/wA8zWj3IHi5EGjxZe0hAzAqxv/u+HvHJFN6V2LV+9w=; b=I+ZUXnmm/EKOQ9QlhwppXgGA7Au0v+xfVkJJogk7HEuI6hRKmihD0LOkbQTcIUwtDW oTf6aNOgvpKDsV9MusBnIFYlwySXTY/XEyFYRExuSzhKiA9bYMR4wZAZ+XuTBU4qDVMA OpNpr3FSroJAHwACz19gRVIY7SW/9GxOko37U2QDErYYcgUl0irifxLZaNChakxZwe0w +x/Jkz5sPJadADiXAgPp3iNbyGv+bv6pt+vqzyPgFyPQBlUJt50nU25x+7aTSLOGTY4E +SBw7F13PmgVY4XA2kRsxTEv96KR5qdjV7XfIAv+PWM0bXDH9Kb56Y5yXpDjgIHoLjqc kaeA== X-Forwarded-Encrypted: i=1; AJvYcCUatUiy9SArUpX+A8dGVaB2Qt3++fyhvebmq9lJQhGVwCkd4i3ZA0dbQj8Dzb9BDwN1CNsvz+s2KicjSMk=@vger.kernel.org X-Gm-Message-State: AOJu0YyFidawIXmG+B/sPCwNr4Pui5CJSj8rnCFk2mex+9EJlr6jgF4w Y4NfsuJcLKUaH7PG46/2MDfnUMCfd6o251mpRkURm7/s99vYk8ySYhAYhWlSa2YgmbZhdYmMXjG 87vnzEFxJi8QwKaBx2g== X-Google-Smtp-Source: AGHT+IE7ZYE2G78VMvgr7QyQY3UGFoBv6nWkO+JYjwWdIf2eRZA8qO2YgC01bcZhcgqpeVje8R/Z5rh7HqE6ikg= X-Received: from pfjw10.prod.google.com ([2002:aa7:9a0a:0:b0:748:fb38:1909]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:114a:b0:759:5208:59e with SMTP id d2e1a72fcca58-76ab0f21102mr14128350b3a.7.1754019635948; Thu, 31 Jul 2025 20:40:35 -0700 (PDT) Date: Fri, 1 Aug 2025 03:39:30 +0000 In-Reply-To: <20250801034004.3314737-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250801034004.3314737-1-guanyulin@google.com> X-Mailer: git-send-email 2.50.1.565.gc32cd1483b-goog Message-ID: <20250801034004.3314737-2-guanyulin@google.com> Subject: [PATCH v15 1/4] usb: xhci-plat: separate dev_pm_ops for each pm_event From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, hannelotta@gmail.com, zijun.hu@oss.qualcomm.com, xu.yang_2@nxp.com, stern@rowland.harvard.edu, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org, dh10.jung@samsung.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Guan-Yu Lin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Separate dev_pm_ops for different power events such as suspend, thaw, and hibernation. This is crucial when xhci-plat driver needs to adapt its behavior based on different power state changes. Signed-off-by: Guan-Yu Lin --- drivers/usb/host/xhci-plat.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 5eb51797de32..df2e942ad5f7 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -454,7 +454,7 @@ void xhci_plat_remove(struct platform_device *dev) } EXPORT_SYMBOL_GPL(xhci_plat_remove); =20 -static int xhci_plat_suspend(struct device *dev) +static int xhci_plat_suspend_common(struct device *dev) { struct usb_hcd *hcd =3D dev_get_drvdata(dev); struct xhci_hcd *xhci =3D hcd_to_xhci(hcd); @@ -482,6 +482,16 @@ static int xhci_plat_suspend(struct device *dev) return 0; } =20 +static int xhci_plat_suspend(struct device *dev) +{ + return xhci_plat_suspend_common(dev); +} + +static int xhci_plat_freeze(struct device *dev) +{ + return xhci_plat_suspend_common(dev); +} + static int xhci_plat_resume_common(struct device *dev, bool power_lost) { struct usb_hcd *hcd =3D dev_get_drvdata(dev); @@ -529,6 +539,11 @@ static int xhci_plat_resume(struct device *dev) return xhci_plat_resume_common(dev, false); } =20 +static int xhci_plat_thaw(struct device *dev) +{ + return xhci_plat_resume_common(dev, false); +} + static int xhci_plat_restore(struct device *dev) { return xhci_plat_resume_common(dev, true); @@ -558,9 +573,9 @@ static int __maybe_unused xhci_plat_runtime_resume(stru= ct device *dev) const struct dev_pm_ops xhci_plat_pm_ops =3D { .suspend =3D pm_sleep_ptr(xhci_plat_suspend), .resume =3D pm_sleep_ptr(xhci_plat_resume), - .freeze =3D pm_sleep_ptr(xhci_plat_suspend), - .thaw =3D pm_sleep_ptr(xhci_plat_resume), - .poweroff =3D pm_sleep_ptr(xhci_plat_suspend), + .freeze =3D pm_sleep_ptr(xhci_plat_freeze), + .thaw =3D pm_sleep_ptr(xhci_plat_thaw), + .poweroff =3D pm_sleep_ptr(xhci_plat_freeze), .restore =3D pm_sleep_ptr(xhci_plat_restore), =20 SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, --=20 2.50.1.565.gc32cd1483b-goog From nobody Sun Oct 5 16:18:43 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A271B1917F4 for ; Fri, 1 Aug 2025 03:40:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019647; cv=none; b=Z/RY4cMWenst0xdNIu5BpLAKqyxFu5ohpPGd9qPm92d2qyRiCXMIUN98/4628x3KQYq2SyXtTTGwqeyf9GyQhG0IURYYCeOf7gs72mn4f15Yi7FsMPm5VAEiDlfyOSjxea2HnwTpEumntKUa+VdII7JSezY8PAqGpCTPJjLKoXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019647; c=relaxed/simple; bh=b5avWyHXz/1OWZ/aBU1PJnAuPzJmoeYgCrTmNPRbjto=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QMmqzO7Gc8tCRdqFllpB02uy/TZIHWUBh8kjlhpnyxBb7yBs1z592t1zXYfDzX52JvH5+MZ0Hpau5g6DC+b+xw8Q1yVWeLSiVEoeGDCy2n7EQK71RJz7q/4KsvzAZ8cICI3HGwq+ui3iFgbeFYzdND3PjbepbUv2IePt3NG/D8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uEdPt6KK; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uEdPt6KK" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3132e7266d3so607323a91.2 for ; Thu, 31 Jul 2025 20:40:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1754019645; x=1754624445; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=GWbckXu8w1ij4VqvtPCrxTqcWwxpTgFRcitQcVlE1Os=; b=uEdPt6KKUJi897Ab9q2D3m9xYmJvopjJfeUpW7nMTouRREXTRNocB5vp6MCyDmeAuM Velvzcv75Tc/Iq3gzlD4HgwVUTb6/INUjYXq8TCyvwRElrFMJoApvHe2lIDXpSo8bs3v 5BMC34UFacCKkW8MQN8UWEaxBQGy7c98nehzxjqlEOWCnRPJdUVbZBt2WhvJfLaai3Ex 4y57VsYcxHC9kQP7oma8wWYOnP5C+qTNNQ/Z4/H1sg/RiBawR8F1Mi3KE7KzMh4eYzTL T0LidH5QcPZNy0XOnpmgqSRwquuFR0UbDmv+v4g3ePER4zOYl6QCsvfSy1IAv+kg8jR7 63Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754019645; x=1754624445; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=GWbckXu8w1ij4VqvtPCrxTqcWwxpTgFRcitQcVlE1Os=; b=QccyH2ZZt7/4WNOtu45cm8p+a6zXAfBB/yGktAXq8mNSfmwiVE6J1jaK6prk3WtFQ6 54vzHGajg+4sxz4gb4ftpTrL2MHaTOpbIyYFnZUALX+Omi52YlaeUgtxxRXDTUYDUdM7 ajL3lst6T3H7CtfhX7gkU1pCd6vjQ6Csd7u7Grk+Pp/Zt16A5Yvr29nzAozXbUjilhVT YK5DQet+ftLDdUYFoyk8pvCtPBrgMMmcUf3w+Wce7QgsqVus4E4/B2KXQAw/bhS6WdBG fQQInVqUInanAJDt5FTMqLf3KncAJ7Im4R4pwzqg7FmBHsw2ahPzTMiG1oF6nIzR4nL0 9hPw== X-Forwarded-Encrypted: i=1; AJvYcCV4SaVv0P5ZXDKmejK4IwGeMoZWMvXgUhtZY86ZrhGKEUrwEw8eeHDbWBMDKywHrRJQaHm5LU3A1nYPfpQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzP9bDe1WFmzdPlvQzFaWd4/fDCE+Xa8NX/WuLrV2ppoP4XYAQI xpR8ywhSgI/eqbgxjsMOaQuvvQsMapWRksWt5EXqmw0/GoLjzFSAWraUx9QSmrMe/b8NJeS6sav ucIot38VGzB0iIz4LVw== X-Google-Smtp-Source: AGHT+IH7gXP7DQrgws2wF/AzNXCxPAonzRIhflG+PxSPkDwmJiEggxfBi0vCz7RLILsIFXU65hTeWtGUPLYMcuU= X-Received: from pjbqo6.prod.google.com ([2002:a17:90b:3dc6:b0:311:ff0f:6962]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3c4f:b0:31f:e6e:7313 with SMTP id 98e67ed59e1d1-31f5dd6fd4cmr13217443a91.3.1754019644947; Thu, 31 Jul 2025 20:40:44 -0700 (PDT) Date: Fri, 1 Aug 2025 03:39:31 +0000 In-Reply-To: <20250801034004.3314737-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250801034004.3314737-1-guanyulin@google.com> X-Mailer: git-send-email 2.50.1.565.gc32cd1483b-goog Message-ID: <20250801034004.3314737-3-guanyulin@google.com> Subject: [PATCH v15 2/4] usb: offload: add apis for offload usage tracking From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, hannelotta@gmail.com, zijun.hu@oss.qualcomm.com, xu.yang_2@nxp.com, stern@rowland.harvard.edu, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org, dh10.jung@samsung.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Guan-Yu Lin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce offload_usage and corresponding apis to track offload usage on each USB device. Offload denotes that there is another co-processor accessing the USB device via the same USB host controller. To optimize power usage, it's essential to monitor whether the USB device is actively used by other co-processor. This information is vital when determining if a USB device can be safely suspended during system power state transitions. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/Kconfig | 10 +++ drivers/usb/core/Makefile | 1 + drivers/usb/core/offload.c | 136 +++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 1 + include/linux/usb.h | 18 +++++ 5 files changed, 166 insertions(+) create mode 100644 drivers/usb/core/offload.c diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig index 58e3ca7e4793..d5d38657f929 100644 --- a/drivers/usb/core/Kconfig +++ b/drivers/usb/core/Kconfig @@ -143,3 +143,13 @@ config USB_DEFAULT_AUTHORIZATION_MODE ACPI selecting value 2 is analogous to selecting value 0. =20 If unsure, keep the default value. + +config USB_OFFLOAD + bool "Enable USB offload feature" + depends on USB + depends on USB_XHCI_SIDEBAND_SUSPEND + help + Offload denotes that there is another co-processor accessing the + USB device via the same USB host controller, creating the + "offloaded USB transfers". Say Y to allow offloaded USB + transfers during system sleep (Suspend-to-RAM). diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index ac006abd13b3..df26c2885dd8 100644 --- a/drivers/usb/core/Makefile +++ b/drivers/usb/core/Makefile @@ -9,6 +9,7 @@ usbcore-y +=3D devio.o notify.o generic.o quirks.o devices.o usbcore-y +=3D phy.o port.o =20 usbcore-$(CONFIG_OF) +=3D of.o +usbcore-$(CONFIG_USB_OFFLOAD) +=3D offload.o usbcore-$(CONFIG_USB_PCI) +=3D hcd-pci.o usbcore-$(CONFIG_ACPI) +=3D usb-acpi.o =20 diff --git a/drivers/usb/core/offload.c b/drivers/usb/core/offload.c new file mode 100644 index 000000000000..7c699f1b8d2b --- /dev/null +++ b/drivers/usb/core/offload.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * offload.c - USB offload related functions + * + * Copyright (c) 2025, Google LLC. + * + * Author: Guan-Yu Lin + */ + +#include + +#include "usb.h" + +/** + * usb_offload_get - increment the offload_usage of a USB device + * @udev: the USB device to increment its offload_usage + * + * Incrementing the offload_usage of a usb_device indicates that offload is + * enabled on this usb_device; that is, another entity is actively handlin= g USB + * transfers. This information allows the USB driver to adjust its power + * management policy based on offload activity. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_offload_get(struct usb_device *udev) +{ + int ret; + + usb_lock_device(udev); + if (udev->state =3D=3D USB_STATE_NOTATTACHED) { + usb_unlock_device(udev); + return -ENODEV; + } + + if (udev->state =3D=3D USB_STATE_SUSPENDED || + udev->offload_at_suspend) { + usb_unlock_device(udev); + return -EBUSY; + } + + /* + * offload_usage could only be modified when the device is active, since + * it will alter the suspend flow of the device. + */ + ret =3D usb_autoresume_device(udev); + if (ret < 0) { + usb_unlock_device(udev); + return ret; + } + + udev->offload_usage++; + usb_autosuspend_device(udev); + usb_unlock_device(udev); + + return ret; +} +EXPORT_SYMBOL_GPL(usb_offload_get); + +/** + * usb_offload_put - drop the offload_usage of a USB device + * @udev: the USB device to drop its offload_usage + * + * The inverse operation of usb_offload_get, which drops the offload_usage= of + * a USB device. This information allows the USB driver to adjust its power + * management policy based on offload activity. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_offload_put(struct usb_device *udev) +{ + int ret; + + usb_lock_device(udev); + if (udev->state =3D=3D USB_STATE_NOTATTACHED) { + usb_unlock_device(udev); + return -ENODEV; + } + + if (udev->state =3D=3D USB_STATE_SUSPENDED || + udev->offload_at_suspend) { + usb_unlock_device(udev); + return -EBUSY; + } + + /* + * offload_usage could only be modified when the device is active, since + * it will alter the suspend flow of the device. + */ + ret =3D usb_autoresume_device(udev); + if (ret < 0) { + usb_unlock_device(udev); + return ret; + } + + /* Drop the count when it wasn't 0, ignore the operation otherwise. */ + if (udev->offload_usage) + udev->offload_usage--; + usb_autosuspend_device(udev); + usb_unlock_device(udev); + + return ret; +} +EXPORT_SYMBOL_GPL(usb_offload_put); + +/** + * usb_offload_check - check offload activities on a USB device + * @udev: the USB device to check its offload activity. + * + * Check if there are any offload activity on the USB device right now. Th= is + * information could be used for power management or other forms of resour= ce + * management. + * + * The caller must hold @udev's device lock. In addition, the caller should + * ensure downstream usb devices are all either suspended or marked as + * "offload_at_suspend" to ensure the correctness of the return value. + * + * Returns true on any offload activity, false otherwise. + */ +bool usb_offload_check(struct usb_device *udev) __must_hold(&udev->dev->mu= tex) +{ + struct usb_device *child; + bool active; + int port1; + + usb_hub_for_each_child(udev, port1, child) { + usb_lock_device(child); + active =3D usb_offload_check(child); + usb_unlock_device(child); + if (active) + return true; + } + + return !!udev->offload_usage; +} +EXPORT_SYMBOL_GPL(usb_offload_check); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index fca7735fc660..e6b9ab8b4a34 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -670,6 +670,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *par= ent, set_dev_node(&dev->dev, dev_to_node(bus->sysdev)); dev->state =3D USB_STATE_ATTACHED; dev->lpm_disable_count =3D 1; + dev->offload_usage =3D 0; atomic_set(&dev->urbnum, 0); =20 INIT_LIST_HEAD(&dev->ep0.urb_list); diff --git a/include/linux/usb.h b/include/linux/usb.h index 9d662c6abb4d..81fc0d93783f 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -636,6 +636,8 @@ struct usb3_lpm_parameters { * @do_remote_wakeup: remote wakeup should be enabled * @reset_resume: needs reset instead of resume * @port_is_suspended: the upstream port is suspended (L2 or U3) + * @offload_at_suspend: offload activities during suspend is enabled. + * @offload_usage: number of offload activities happening on this usb devi= ce. * @slot_id: Slot ID assigned by xHCI * @l1_params: best effor service latency for USB2 L1 LPM state, and L1 ti= meout. * @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated tim= eout. @@ -724,6 +726,8 @@ struct usb_device { unsigned do_remote_wakeup:1; unsigned reset_resume:1; unsigned port_is_suspended:1; + unsigned offload_at_suspend:1; + int offload_usage; enum usb_link_tunnel_mode tunnel_mode; struct device_link *usb4_link; =20 @@ -841,6 +845,20 @@ static inline void usb_mark_last_busy(struct usb_devic= e *udev) { } #endif =20 +#if IS_ENABLED(CONFIG_USB_OFFLOAD) +int usb_offload_get(struct usb_device *udev); +int usb_offload_put(struct usb_device *udev); +bool usb_offload_check(struct usb_device *udev); +#else + +static inline int usb_offload_get(struct usb_device *udev) +{ return 0; } +static inline int usb_offload_put(struct usb_device *udev) +{ return 0; } +static inline bool usb_offload_check(struct usb_device *udev) +{ return false; } +#endif + extern int usb_disable_lpm(struct usb_device *udev); extern void usb_enable_lpm(struct usb_device *udev); /* Same as above, but these functions lock/unlock the bandwidth_mutex. */ --=20 2.50.1.565.gc32cd1483b-goog From nobody Sun Oct 5 16:18:43 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8DF2918C91F for ; Fri, 1 Aug 2025 03:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019654; cv=none; b=T2fKPKKfKkUYG56fm84vSwQtBVmOC1S7Eu1iPj8WAA/YAllK3jLd55ZTJh5coqsn5Z7dKBtWMN/3Hmh8hgrsmCsyhgu0IEzXyWvzorCgWf0p8pNrmOgXEXiQGNR9FGabmDScpTFFqFB5ZGrFNgBWbLi8RLim595v7ZQ/o3ZoHso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019654; c=relaxed/simple; bh=0EsSSWp2StcoMyvDXKJJNPW/yPBt1h550IehLxYVt3E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MkYl1GyNwkeGL8yDcK0eij3WdxOJhEjfIPm8ySkuv/ygWbiY1kdkQH64eU/62j98flkZfQBc4Ab+mLF1ikgwg9ist2GHwHm3kWIJyCGKNWgTcX744PuHhfYICczMYXdbz1Ceo2Zprw4xQIHPekZuN6IWR4ZBsiDNY+X8dSDkWTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mr2Gxn/k; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mr2Gxn/k" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b31ca4b6a8eso779159a12.1 for ; Thu, 31 Jul 2025 20:40:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1754019652; x=1754624452; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=u52hHJ9rEIBAEk6jD+UXhZlTW31ESJk3DGssR2+OtF8=; b=mr2Gxn/kXHZ6zZgOTUgW63UAV480rvN7zwkUlQrnlm+HytNDliV9dFRErsnbkPh6c4 /Y47+T8W2UiALnwJyM+F658w4pGh/J1pWHO82xJThN3phrs1CSS+cdLrDJ0nItEfBQUU ft9EaboHAH4GB+N4v9plN+Orx5x4VyLnKj1II4mxpXVdy7UoPfGtZQJe2w4toE+/phDk GGLov1TNBIPkMGalb8gjYAJNyCyeAvpOVbmDnEn4+6gJsoXW5vXpYnk1B5kexpRqJ6Oa O88NqFRnBYPzUgUXp7S6F8Xyks6aoUfEbN669S2zkqIU6Sj2yoJ4/C4ZG/X7vfWRp/l6 6QXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754019652; x=1754624452; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u52hHJ9rEIBAEk6jD+UXhZlTW31ESJk3DGssR2+OtF8=; b=tCKDWciTW/rQXC6JHO4/L31YAbsV5Aod2oLcbcQn5Y0zoo6P+CdIjwcE30Rv4fTDSc dGDXF1GyIOQzl4ACNlTI9bnzhb8ZTzoVQiMhXh7+YyMInXHx+WCAfBT7e/MR2cD2r7He E0Dabq4wmbJXI1+KrHfH0XJUf4Q7gtJ0uSILCqHehU272MFdMAgE+qzgDgWdSVg8BzIo M3SM818uqKrTRb6GM0XCNIrkCoQNMhyp4xlMl4sU3fW0ZzMNUv91iYaa7o8tYnBcUXTu 3RqasdSmZ8JUtKWPp9Fze/pMvo49C9f7H/A3J1SlR+WGdscq7RSgPkWARM67Lo/l45OR OK1g== X-Forwarded-Encrypted: i=1; AJvYcCViPJfmC587LVIovJ4ZgydtM5WGx5kJFqj6zcrn6kS2hK4ZBcnAR4Jb7TJeitkwh14QWHzpDE+dJnMNjeg=@vger.kernel.org X-Gm-Message-State: AOJu0YwHJTXRxTB836XTOYPrbAwrsPdgzYOhWft533ex045zr8f6fLQN RnoFswmPcxtn4vuGYdS4NRx4tj590+rf9g/zf/OXIpTkOIPytvfzifeYBXLY9M+fA3eckbad6DF RD3Kmlq2A9zPZKpEBPA== X-Google-Smtp-Source: AGHT+IG9NseSYCHS4701vA745klXIXlscOCwfDHjui1CQjUPYEUOllMfnUKeDKdUYJzmE2Ho6fuqhz8N6jzk76U= X-Received: from pfst15.prod.google.com ([2002:aa7:8f8f:0:b0:749:1e51:d39a]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:94c8:b0:236:1d50:5b9c with SMTP id adf61e73a8af0-23dc0dca35emr13808948637.12.1754019651753; Thu, 31 Jul 2025 20:40:51 -0700 (PDT) Date: Fri, 1 Aug 2025 03:39:32 +0000 In-Reply-To: <20250801034004.3314737-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250801034004.3314737-1-guanyulin@google.com> X-Mailer: git-send-email 2.50.1.565.gc32cd1483b-goog Message-ID: <20250801034004.3314737-4-guanyulin@google.com> Subject: [PATCH v15 3/4] xhci: sideband: add api to trace sideband usage From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, hannelotta@gmail.com, zijun.hu@oss.qualcomm.com, xu.yang_2@nxp.com, stern@rowland.harvard.edu, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org, dh10.jung@samsung.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Guan-Yu Lin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing sideband driver only registers sidebands without tracking their active usage. To address this, sideband will now record its active usage when it creates/removes interrupters. In addition, a new api is introduced to provide a means for other dirvers to fetch sideband activity information on a USB host controller. Signed-off-by: Guan-Yu Lin --- drivers/usb/host/Kconfig | 11 +++++++++ drivers/usb/host/xhci-sideband.c | 38 +++++++++++++++++++++++++++++++ include/linux/usb/xhci-sideband.h | 9 ++++++++ 3 files changed, 58 insertions(+) diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 109100cc77a3..49b9cdc11298 100644 --- a/drivers/usb/host/Kconfig +++ b/drivers/usb/host/Kconfig @@ -113,6 +113,17 @@ config USB_XHCI_SIDEBAND xHCI USB endpoints directly, allowing CPU to sleep while playing audio. =20 +config USB_XHCI_SIDEBAND_SUSPEND + bool "xHCI support for sideband during system suspend" + depends on USB_XHCI_SIDEBAND + depends on USB_XHCI_PLATFORM + depends on SUSPEND + help + Say 'Y' to enable the support for the xHCI sideband capability + after system suspended. In addition to USB_XHCI_SIDEBAND, this + config allows endpoints and interrupters associated with the + sideband function when system is suspended. + config USB_XHCI_TEGRA tristate "xHCI support for NVIDIA Tegra SoCs" depends on PHY_TEGRA_XUSB diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideb= and.c index d49f9886dd84..15d72c23c0e0 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -266,6 +266,33 @@ xhci_sideband_get_event_buffer(struct xhci_sideband *s= b) } EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); =20 +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) +/** + * xhci_sideband_check - check the existence of active sidebands + * @hcd: the host controller driver associated with the target host contro= ller + * + * Allow other drivers, such as usb controller driver, to check if there a= re + * any sideband activity on the host controller. This information could be= used + * for power management or other forms of resource management. The caller = should + * ensure downstream usb devices are all either suspended or marked as + * "offload_at_suspend" to ensure the correctness of the return value. + * + * Returns true on any active sideband existence, false otherwise. + */ +bool xhci_sideband_check(struct usb_hcd *hcd) +{ + struct usb_device *udev =3D hcd->self.root_hub; + bool active; + + usb_lock_device(udev); + active =3D usb_offload_check(udev); + usb_unlock_device(udev); + + return active; +} +EXPORT_SYMBOL_GPL(xhci_sideband_check); +#endif /* IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) */ + /** * xhci_sideband_create_interrupter - creates a new interrupter for this s= ideband * @sb: sideband instance for this usb device @@ -286,6 +313,7 @@ xhci_sideband_create_interrupter(struct xhci_sideband *= sb, int num_seg, bool ip_autoclear, u32 imod_interval, int intr_num) { int ret =3D 0; + struct usb_device *udev; =20 if (!sb || !sb->xhci) return -ENODEV; @@ -304,6 +332,9 @@ xhci_sideband_create_interrupter(struct xhci_sideband *= sb, int num_seg, goto out; } =20 + udev =3D sb->vdev->udev; + ret =3D usb_offload_get(udev); + sb->ir->ip_autoclear =3D ip_autoclear; =20 out: @@ -323,6 +354,8 @@ EXPORT_SYMBOL_GPL(xhci_sideband_create_interrupter); void xhci_sideband_remove_interrupter(struct xhci_sideband *sb) { + struct usb_device *udev; + if (!sb || !sb->ir) return; =20 @@ -330,6 +363,11 @@ xhci_sideband_remove_interrupter(struct xhci_sideband = *sb) xhci_remove_secondary_interrupter(xhci_to_hcd(sb->xhci), sb->ir); =20 sb->ir =3D NULL; + udev =3D sb->vdev->udev; + + if (udev->state !=3D USB_STATE_NOTATTACHED) + usb_offload_put(udev); + mutex_unlock(&sb->mutex); } EXPORT_SYMBOL_GPL(xhci_sideband_remove_interrupter); diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sid= eband.h index 45288c392f6e..5174cc5afc98 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -11,6 +11,7 @@ =20 #include #include +#include =20 #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ =20 @@ -83,6 +84,14 @@ xhci_sideband_get_endpoint_buffer(struct xhci_sideband *= sb, struct usb_host_endpoint *host_ep); struct sg_table * xhci_sideband_get_event_buffer(struct xhci_sideband *sb); + +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) +bool xhci_sideband_check(struct usb_hcd *hcd); +#else +static inline bool xhci_sideband_check(struct usb_hcd *hcd) +{ return false; } +#endif /* IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) */ + int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, bool ip_autoclear, u32 imod_interval, int intr_num); --=20 2.50.1.565.gc32cd1483b-goog From nobody Sun Oct 5 16:18:43 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABB4B1A314F for ; Fri, 1 Aug 2025 03:40:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019659; cv=none; b=o+v7tKVgvauSpYYBexDao7px3s7rmZpFUmFTnhBO7rKibwC6qX0WKOKESmBXClHrpNNxl+di3EoN8t/zQ/+CCzizu2NFLV3/REiKPlitaL4wCimZgPiZazJsTwsqnImLiPUKNfKogi65RJ9VCz5zNno+egJYsu0UffxZWsVhFyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754019659; c=relaxed/simple; bh=teS/+aZOK08uAjWXkV1PKRDhG6i0pRZR3Pq9zRsGilU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XhwYbYJpoRUoY48quZk+7H7Q1MOcYG6kuUYvrJt/8jmEP8FkUgl4+ePFwDJGAYnFGRFBeWubPYrAQYex0pRo28iiqbRiZAPEV+e78ruAvwHP6DnSzLU8jZtIz7+nHi5O72CTKoEjZFjzu+ewdloI/GsbPjTRWwIRFzinSzdw0Yg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UZZupN0A; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UZZupN0A" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-75e28bcec3bso877081b3a.1 for ; Thu, 31 Jul 2025 20:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1754019657; x=1754624457; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fEKyx7rEaL9ClT6i1Uqn92+E8d8b0N4HGm0M5DzW4vU=; b=UZZupN0AlQXxonEBsYn+QwUh76oQBDGb+k/ZaHuplGeVdSEFVDhYlfs+u2pkR4kNjX Zj9cCgr+rrUsT4gpqLRiNOt82q4xjtQdHEl+2rWUmJymKaDiXP/BUMmjtAt5MiLphmW/ TKORzZobJ1kQByrYbi3h7YETHzw/3R8GuzGmM/+du+wjQ2YZMWH+Gs1FcH1LtLDzro4k 80okH9mD9M6RAK/Rnd/CKSWhkO31UAQfqhM6Sp40/JVoR4P5kFLp211cIQ2rk6BkP+DZ Khd3AYSQ3gOIdsZ1AtSZQUB03qmcPB9Am6TuTm0iQjSLSij0leZqP/VnjhTjxeUSpgg/ RRtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754019657; x=1754624457; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fEKyx7rEaL9ClT6i1Uqn92+E8d8b0N4HGm0M5DzW4vU=; b=OS0ija6C9qkFLCH9eg0a0ezKx7WTOdBv6jPhZK6Zjl/rhUeSqkpFCIrbCQycYBp7mL md/fkFf1cY7kd8IZdBFe/ZNdxyPegqjFekNDD5ceC54CIlBSg64af3/upt4jIlpr7OEZ EBG8oQoA9lso/Y6OPZ+tn86vhDdvQh414qzRF+YEpTvWjJqZscW9h1MPS6X79ig3Gw1F 2Hx1BtzXOiJY84PO8MNkjFgfTNg2Y9dgenDbppLlslvLikR6QIgX+GBAxrIcK8uneyeP rje9ngkhzncoY5Xq16N8xzeXeBn++iSutRa2SQVUcYhzsb6Ue3o7I06DMmuF9YRelScI L/sw== X-Forwarded-Encrypted: i=1; AJvYcCU4POCYlfSjUyVMV12xbY0uI/ZhOe13E8oEpHtFCJ0b+QOOMwDaEqLsbeg6ccKDiM3cvWoaI0V5YGx2SO8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3CoZXlTniPgPUNNjBKfaQq/xqoxDWvWQdtba4ouGumdz3v1nO QfyPRi0dEMUvxaMibVMJqUTgPqu3mLaN9uEkWRfkyFTkAXugtrSlQQgGJsmdlSLGGH7agr3PbrO QtDKDylgy81aVIJLF5A== X-Google-Smtp-Source: AGHT+IEUckZdgPpJBQcMD5oGM/FPiKa0Egdq8QTlH3cbIYwPC/r7pHST0Q+N93A0qNgQM2flPniCR9h/FZJnJRk= X-Received: from pfck16-n1.prod.google.com ([2002:a05:6a00:a050:10b0:748:fa5b:4163]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:a95:b0:748:ed51:1305 with SMTP id d2e1a72fcca58-76ab0a23c9amr14806735b3a.5.1754019657171; Thu, 31 Jul 2025 20:40:57 -0700 (PDT) Date: Fri, 1 Aug 2025 03:39:33 +0000 In-Reply-To: <20250801034004.3314737-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250801034004.3314737-1-guanyulin@google.com> X-Mailer: git-send-email 2.50.1.565.gc32cd1483b-goog Message-ID: <20250801034004.3314737-5-guanyulin@google.com> Subject: [PATCH v15 4/4] usb: host: enable USB offload during system sleep From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, hannelotta@gmail.com, zijun.hu@oss.qualcomm.com, xu.yang_2@nxp.com, stern@rowland.harvard.edu, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org, dh10.jung@samsung.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Guan-Yu Lin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sharing a USB controller with another entity via xhci-sideband driver creates power management complexities. To prevent the USB controller from being inadvertently deactivated while in use by the other entity, a usage-count based mechanism is implemented. This allows the system to manage power effectively, ensuring the controller remains available whenever needed. In order to maintain full functionality of an offloaded USB devices, several changes are made within the suspend flow of such devices: - skip usb_suspend_device() so that the port/hub are still active for USB transfers via offloaded path. - not suspending the endpoints which are used by USB interfaces marked with needs_remote_wakeup. Namely, skip usb_suspend_interface() and usb_hcd_flush_endpoint() on associated USB interfaces. This reserves a pending interrupt urb during system suspend for handling the interrupt transfer, which is necessary since remote wakeup doesn't apply in the offloaded USB devices when controller is still active. - not flushing the endpoints of actively offloaded USB devices. Given that the USB devices is used by another entity, unilaterally flush the endpoint might lead to unexpected behavior on another entity. - not suspending the xhci controller. This is done by skipping the suspend/resume callbacks in the xhci platform driver. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 50 +++++++++++++++++++++++++++++++----- drivers/usb/host/xhci-plat.c | 19 ++++++++++++++ drivers/usb/host/xhci-plat.h | 1 + 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index c3177034b779..275c0fd573d4 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1420,11 +1420,28 @@ static int usb_suspend_both(struct usb_device *udev= , pm_message_t msg) udev->state =3D=3D USB_STATE_SUSPENDED) goto done; =20 + if (msg.event =3D=3D PM_EVENT_SUSPEND && usb_offload_check(udev)) { + dev_dbg(&udev->dev, "device offloaded, skip suspend.\n"); + udev->offload_at_suspend =3D 1; + } + /* Suspend all the interfaces and then udev itself */ if (udev->actconfig) { n =3D udev->actconfig->desc.bNumInterfaces; for (i =3D n - 1; i >=3D 0; --i) { intf =3D udev->actconfig->interface[i]; + /* + * Don't suspend interfaces with remote wakeup while + * the controller is active. This preserves pending + * interrupt urbs, allowing interrupt events to be + * handled during system suspend. + */ + if (udev->offload_at_suspend && + intf->needs_remote_wakeup) { + dev_dbg(&intf->dev, + "device offloaded, skip suspend.\n"); + continue; + } status =3D usb_suspend_interface(udev, intf, msg); =20 /* Ignore errors during system sleep transitions */ @@ -1435,7 +1452,8 @@ static int usb_suspend_both(struct usb_device *udev, = pm_message_t msg) } } if (status =3D=3D 0) { - status =3D usb_suspend_device(udev, msg); + if (!udev->offload_at_suspend) + status =3D usb_suspend_device(udev, msg); =20 /* * Ignore errors from non-root-hub devices during @@ -1480,9 +1498,11 @@ static int usb_suspend_both(struct usb_device *udev,= pm_message_t msg) */ } else { udev->can_submit =3D 0; - for (i =3D 0; i < 16; ++i) { - usb_hcd_flush_endpoint(udev, udev->ep_out[i]); - usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + if (!udev->offload_at_suspend) { + for (i =3D 0; i < 16; ++i) { + usb_hcd_flush_endpoint(udev, udev->ep_out[i]); + usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + } } } =20 @@ -1524,17 +1544,35 @@ static int usb_resume_both(struct usb_device *udev,= pm_message_t msg) udev->can_submit =3D 1; =20 /* Resume the device */ - if (udev->state =3D=3D USB_STATE_SUSPENDED || udev->reset_resume) - status =3D usb_resume_device(udev, msg); + if (udev->state =3D=3D USB_STATE_SUSPENDED || udev->reset_resume) { + if (!udev->offload_at_suspend) + status =3D usb_resume_device(udev, msg); + else + dev_dbg(&udev->dev, + "device offloaded, skip resume.\n"); + } =20 /* Resume the interfaces */ if (status =3D=3D 0 && udev->actconfig) { for (i =3D 0; i < udev->actconfig->desc.bNumInterfaces; i++) { intf =3D udev->actconfig->interface[i]; + /* + * Interfaces with remote wakeup aren't suspended + * while the controller is active. This preserves + * pending interrupt urbs, allowing interrupt events + * to be handled during system suspend. + */ + if (udev->offload_at_suspend && + intf->needs_remote_wakeup) { + dev_dbg(&intf->dev, + "device offloaded, skip resume.\n"); + continue; + } usb_resume_interface(udev, intf, msg, udev->reset_resume); } } + udev->offload_at_suspend =3D 0; usb_mark_last_busy(udev); =20 done: diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index df2e942ad5f7..3a56d8f94519 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -20,6 +20,7 @@ #include #include #include +#include =20 #include "xhci.h" #include "xhci-plat.h" @@ -484,6 +485,15 @@ static int xhci_plat_suspend_common(struct device *dev) =20 static int xhci_plat_suspend(struct device *dev) { + struct usb_hcd *hcd =3D dev_get_drvdata(dev); + struct xhci_plat_priv *priv =3D hcd_to_xhci_priv(hcd); + + if (xhci_sideband_check(hcd)) { + priv->sideband_at_suspend =3D 1; + dev_dbg(dev, "sideband instance active, skip suspend.\n"); + return 0; + } + return xhci_plat_suspend_common(dev); } =20 @@ -536,6 +546,15 @@ static int xhci_plat_resume_common(struct device *dev,= bool power_lost) =20 static int xhci_plat_resume(struct device *dev) { + struct usb_hcd *hcd =3D dev_get_drvdata(dev); + struct xhci_plat_priv *priv =3D hcd_to_xhci_priv(hcd); + + if (priv->sideband_at_suspend) { + priv->sideband_at_suspend =3D 0; + dev_dbg(dev, "sideband instance active, skip resume.\n"); + return 0; + } + return xhci_plat_resume_common(dev, false); } =20 diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h index fe4f95e690fa..2b32a93d2b76 100644 --- a/drivers/usb/host/xhci-plat.h +++ b/drivers/usb/host/xhci-plat.h @@ -16,6 +16,7 @@ struct xhci_plat_priv { const char *firmware_name; unsigned long long quirks; bool power_lost; + unsigned sideband_at_suspend:1; void (*plat_start)(struct usb_hcd *); int (*init_quirk)(struct usb_hcd *); int (*suspend_quirk)(struct usb_hcd *); --=20 2.50.1.565.gc32cd1483b-goog