From nobody Fri Sep 12 02:27:57 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 B786E32C312 for ; Thu, 11 Sep 2025 14:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757600473; cv=none; b=KXUvulypuWTvbA+0t5onQZ7UZmflMhcpwtU1VSFAlbHTf6JvklC21SbLfkFMH9sXQgr5KuTnHZh9rJumoA9qBf8WuV/fTI/wsjDcGH4N4A4vDkR1fWwv3/w0exBtonPF9ou5ziiP5X3v2Gk2W7Tny1E+ojA8dapfQdlwbId+f/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757600473; c=relaxed/simple; bh=faJE+cTueXsphf9F2YTETRq7iQrxqJIPSY5Wh3BTBzY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XDrXXGOmxcVe++gjZXdr/bmomRE1Aw76qsG0khl4NkaagoD7x9jbgQMRVc66dzKK3lcLxjtf5flhAtCUXvTyhT1Y4cQyQRwWhGKMjzXoyE6IlJc+ISKqOo+VYm9bnet2K0IFf362Bbb3CARI1IrHogUS0ij7iB/Er+Iufax2MPc= 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=zup7xF4Q; arc=none smtp.client-ip=209.85.210.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="zup7xF4Q" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-77264a9408cso1532685b3a.3 for ; Thu, 11 Sep 2025 07:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757600471; x=1758205271; 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=di9vlGGwM3+bJg1YPMe3g5gvCbV0sk+DG/t3kCN+JkE=; b=zup7xF4QMFeplfJCe42tIwLdzE52Ge0PA/59veXAquSw5GgWEd1w4F3WK69SsyEjwo 9LrROVzpMsF8dqU31smPQNRERvmxkngrAcbF26iZvLL+T17lBLx7p4Cy+6rVlVcsTW/b JUN5XcKKji06mRvVd5Qofqq2t+xLPpsTHyMBkK1ElM6EqXVKCJiGnMcNbu0HJGYji4nF oh7rOJMwH4I554VvZIgAcHjGg9u3J3beQIYRrNrzjozRevz4RGixTDzDKYbiqmsxSGkY C/QDQeqg1tF22a4tIyxxzqQBZThRI3wUPtTfqzwlSvET18IrrRXZlXaiRGC6ma2R3z7u pOlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757600471; x=1758205271; 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=di9vlGGwM3+bJg1YPMe3g5gvCbV0sk+DG/t3kCN+JkE=; b=dFCFjVc473yIEttjmbP0sU6nbcjVulf1hEP8AnDwreeyXKvt7s9vjm5BbyXZxez160 rn4bKlujtNJr4k9uVmorMv+798nlnfFlsKSb125vaWW3KzNJyES5gqDh4bK4ZPr000Vo DjLzrYp8J88pBifYryaVoGfxF48IEDSu6KFqCrvuoeTom609P4D6hV00gLDrjOO7+jeL DEHCaeiexjtV+nylVws9pdDAjraQeNUxJK7O6SudviC5pksOxfiML7kXR6bzwAWJdJTl U1FXWcwRA6j/Rets6HZfIh7hXYQcRLs8+URgUwhfAsOwgY11wX7owCB6Ek3uLSo2uMFt YBpg== X-Forwarded-Encrypted: i=1; AJvYcCXsu/4etlzibUO38Qjx3ZgYXIVIbVNFER48q7KuSYUMqau6nDKjS5TJ8LMTvgPwqLl1wOL6mBfjDVDwOdQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxbxeqMun2mJJv8I14VVHnM4EJqRBrcMHPmR3UqW6fNlHX+Wyhy fZVI/PkIsXOvBFtcQ7hlJ3JQ953HYcjqFCIGXR2Oxmn9+1z93JDLIs5bTMJqa7euA0SqLTtuvRn JN8k1ya2vYhrg98M/JQ== X-Google-Smtp-Source: AGHT+IEDuORbCh7ohTP+tivq97Pf4Ap22u0st5ArBD+NLXFiMsoCRDqV5AuP+Csi9xEgcunezW7ghFIJ8zClIOU= X-Received: from pgew14.prod.google.com ([2002:a63:af0e:0:b0:b4c:5356:a130]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:210b:b0:251:1b8c:5643 with SMTP id adf61e73a8af0-253466eca6amr27762178637.50.1757600470961; Thu, 11 Sep 2025 07:21:10 -0700 (PDT) Date: Thu, 11 Sep 2025 14:20:13 +0000 In-Reply-To: <20250911142051.90822-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: <20250911142051.90822-1-guanyulin@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250911142051.90822-2-guanyulin@google.com> Subject: [PATCH v16 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, amardeep.rai@intel.com, dominique.martinet@atmark-techno.com, quic_wcheng@quicinc.com, sakari.ailus@linux.intel.com, 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.51.0.384.g4c02a37b29-goog From nobody Fri Sep 12 02:27:57 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 2C60833A028 for ; Thu, 11 Sep 2025 14:21:14 +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=1757600477; cv=none; b=TwOyWYqolB/5a+9Hsw+eK82EuwvseaM3xQcf4/GOZPJm3At2GIz0/XlWx6yIKbeyI1cCS0kWHGlO+Lf7zZlSKFb9Ok2OQrz0dF9LtqSoSWpWpd7HwMGsWo1+fvZdTRrK0pUgi9nNdZg0dM4PRaXsqXZEYYj02xLRrd4blWrjx3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757600477; c=relaxed/simple; bh=ZBEWXSIeqmrC3ds4q0dvNNt4iprgbUvOMgGvcwRwVCM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ls0iOu6Em9mYXRnYbyNoBj/pgXNzUQeag7ThW5DwnevGD6Qh2LcW1fxIJYkQZKUHiKe8MOBWpb842XYtlO36elkl6nSN/U1M6fHgvlwO4YFNGckQEw+Qk30G+X9zyuirOUx1VcWYk35lvq4nIvwEC1CIqoPfZ1VI2Yyjf1HzJ1s= 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=sC8xv1PT; 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="sC8xv1PT" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b4fbb90b453so987515a12.2 for ; Thu, 11 Sep 2025 07:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757600474; x=1758205274; 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=cd4UolCkEdo/ZISJT1rflmMGOeP6XETs53xAhFcvlpo=; b=sC8xv1PT3luryLK1V70Fx2Y1wtK8KFDeeU83ulh35vEhPmgTpqUIvufamoqVCGCDuZ LFP2l6v8vF7U2ZHmiygpKIq4kT5AI9W8MJ249nLMIRC2T5iTw9LZfRwNNDQLaTuHr0Kp KJHgsNwnttozhhUXrx7qS6/FMM838bZ2FuS03FptfU40UPzWyxMzuStPFqwE94zkS9/4 +F7NhT43MJFbhHPkuwybJBrJfPUALzaY8jhEa0tE53pOo5w4kNq1deyK3EysLlrbYYeC AKLplgsA2Jqw6FZryCSKL0xK5ijjDYKwG4DQ40VyFh9jm9C6k8ZIllw/Y54lji2XXj9/ /bcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757600474; x=1758205274; 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=cd4UolCkEdo/ZISJT1rflmMGOeP6XETs53xAhFcvlpo=; b=pxbpIj+Ar+OrAHJmVApVGae6iayfHxApolrMQHuAmYaH5q5N+B36MFZBk+nPNqRU/0 s1kiPfaUNlKGcCz+2Pu4Z9aO6RCe4JrJqLW4t1WRucQQoo16ijUYBN7+Go1aiblBUt3C Zv9zGaSSjbEHSrVpuitR8RTBmc4JG8Y7DTTzcHocNzgUUWrHlJzZzXjifh2RtIeICFyW O+bD/y7ZVFSzXgiQgs9XR1fpL3kQY3eY3P/lxyW7XIHV4KCjf4uT5mQuj0YYq9xt5WV8 Q774Os58/j/33Oi08+W5VEZpdI/773prmvBMr+41GUbdpzDdikGjMelXbkBNwRJKlXe8 RDYQ== X-Forwarded-Encrypted: i=1; AJvYcCVtVnWL4NgxO0Hql5jZupUTPqaEEi6BKZ7FgChu8d7oU2PPXt9dVP4ZC7ldA7lGLuUMEVLh60bLXf8EYFk=@vger.kernel.org X-Gm-Message-State: AOJu0YyVSc5u+tD7BqVlEE+m3ITfqvW017TAZE5T6NzVTM4R+Z2ig51r HllAIcPaS6xYYpWKxINIxUk2QSzt639CRBrKWztXCHmUeKkiargr2KltXporWY2X0vqO9+yRhW5 olji9WP+d0KJ9YeOhfQ== X-Google-Smtp-Source: AGHT+IHIv06rwyIboIBXdOUfS11nPVbWxBONJJC6nZ8x4coRAIHSyEYiKps3YULVIH9Uh7RGK9BYFphhlPjrOQU= X-Received: from pgac28.prod.google.com ([2002:a05:6a02:295c:b0:b49:dbc4:f7a8]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a10a:b0:251:e4b4:7a44 with SMTP id adf61e73a8af0-2534556ea5emr29031640637.41.1757600474392; Thu, 11 Sep 2025 07:21:14 -0700 (PDT) Date: Thu, 11 Sep 2025 14:20:14 +0000 In-Reply-To: <20250911142051.90822-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: <20250911142051.90822-1-guanyulin@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250911142051.90822-3-guanyulin@google.com> Subject: [PATCH v16 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, amardeep.rai@intel.com, dominique.martinet@atmark-techno.com, quic_wcheng@quicinc.com, sakari.ailus@linux.intel.com, 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/Makefile | 1 + drivers/usb/core/offload.c | 136 +++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 1 + include/linux/usb.h | 18 +++++ 4 files changed, 156 insertions(+) create mode 100644 drivers/usb/core/offload.c diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile index ac006abd13b3..766000b4939e 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_XHCI_SIDEBAND) +=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 b88b6271cb30..b6b0b8489523 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 70ef00c42d22..e85105939af8 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_XHCI_SIDEBAND) +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.51.0.384.g4c02a37b29-goog From nobody Fri Sep 12 02:27:57 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 5AFBC33A02E for ; Thu, 11 Sep 2025 14:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757600479; cv=none; b=DWGVGCbOLw86Giaiapkhj8nj+spaJ02dy9GJ5KbWmgKigxTm1ke8y7tMcfi1yvBIJipKDOEbnsRLtSAQozZvJFDJ2GLJQEh2mJHBdCPGmIjFaGcuRjj0+7EdQ8cCrnwOWw5ATJBpNRntZoHsU9Ox9Wgtdvm0p6NF6WbpLBqlIWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757600479; c=relaxed/simple; bh=mdx6eG+7ml4VsoMCqwGhoY4J8bC5AkD5+1l0FkjARuw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gcYCJAGp/I+kMAvfffSkHSWrWFiKXHDVSHzC55A3I3zlGACTI+hzQgrDl1eaHk2US4/8aQVo+76uPB4jj5yoPw+LiafejAGQH/n4kC03vLiw+YS03g7d7e49hJ9trJlOA4F6cZwYhZnBk/0NDU2Nx569Ssy33EaxUncI1/H9mRc= 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=bXW0HILV; arc=none smtp.client-ip=209.85.215.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="bXW0HILV" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b471757d82fso609919a12.3 for ; Thu, 11 Sep 2025 07:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757600478; x=1758205278; 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=48S/R06M0Dnc7mgADD0bZrS065nRJq6arY7ofHgCeqs=; b=bXW0HILVHCh8mVtd+Ic48nf4MCrBpGKAK1YmmQojYzeOi22SA23YxlvtfD/iG8afuU R8otcqrNiPtncbuvDVX1r9nDD5dTbmNPixiNwyrA4GFfh3PyWUE1p9LRoV6FdjJqbQjQ cHvcpidtWDoJYrLJMIyMSyx44mzhg6XHHiAEtYc+ofpdPAhg94T6qJV13VjXatj6CABC TsTpwXdqxCcrsz2a9QaRCcWr0z9rL6PPPrbrrElanhodQj+N96pSALhx3cz+EOtit9Hu mSZ5M0anre9jvbHPrRP3ktp7W8ccdW1OFIGgxJP9J1SMC0Wlncj90Jd2BTCDIDbESw3v vQtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757600478; x=1758205278; 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=48S/R06M0Dnc7mgADD0bZrS065nRJq6arY7ofHgCeqs=; b=N6MppyocLXoeRqiJ7gIxz61WmRYxfcF/sfSuyuTmQbp58pKOYi4tW5fN7C4NP33wMC 9eG83Fhz9mIwnlRkooX1G/ckYTGPpZYrqTLvF8aQo+oZ4gqk34nXKpQiDJcu4wIvuMja H3OoX2eLvMk6PT4p67AVdiBcLWzJTVykMQUPCiNkObjvtT2LKIP2KiVWXNVUkMPOH1iY rGQ5vR1/vE0Wg1CmKgv1/UNS3E1q+KfhkifFnSzDq8gq2/mNmOzhSG3KW1RZRwhmgSsn AtcvVzPzqzsfahnNutt3NXpt/zsCjYV4J731DXX8zOtlVl07J4L8Y94IW1K/EL3T8wV9 y7jQ== X-Forwarded-Encrypted: i=1; AJvYcCXgjxAUSj9L1X4liqpyyfYM9Sp037riQmuWDzi+h9lEh/nro7sz4m5aAcyuJurIhnEK2feSOjpww69iSDI=@vger.kernel.org X-Gm-Message-State: AOJu0YwCqYP5hTegAHN5XQ+ezUqAa+QD95qeGRVSZb4HYPllAJqr+UcY fN2mLWUNGYfJxVlEqVXQj5Ss3huHRNVumdYnyNxs5attTAa+nY/O9YFRN1WnJM+yVP9JlyDC4Z9 hXZtvIuAD2zQI/OPX8Q== X-Google-Smtp-Source: AGHT+IFsG3zbN/kmvbNOuQouQ0ic1WH0IKXhyBribfWc70ashGg7Mq/eeT221uhkPlACgdQUrm0qBYb84SF5DWA= X-Received: from pfbdo14.prod.google.com ([2002:a05:6a00:4a0e:b0:775:f9fa:fb14]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:918a:b0:249:467e:ba4c with SMTP id adf61e73a8af0-25344dc4b17mr26377631637.42.1757600477715; Thu, 11 Sep 2025 07:21:17 -0700 (PDT) Date: Thu, 11 Sep 2025 14:20:15 +0000 In-Reply-To: <20250911142051.90822-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: <20250911142051.90822-1-guanyulin@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250911142051.90822-4-guanyulin@google.com> Subject: [PATCH v16 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, amardeep.rai@intel.com, dominique.martinet@atmark-techno.com, quic_wcheng@quicinc.com, sakari.ailus@linux.intel.com, 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/xhci-sideband.c | 36 +++++++++++++++++++++++++++++++ include/linux/usb/xhci-sideband.h | 9 ++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideb= and.c index d49f9886dd84..e771a476fef2 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -266,6 +266,31 @@ xhci_sideband_get_event_buffer(struct xhci_sideband *s= b) } EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); =20 +/** + * 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); + /** * xhci_sideband_create_interrupter - creates a new interrupter for this s= ideband * @sb: sideband instance for this usb device @@ -286,6 +311,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 +330,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 +352,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 +361,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..005257085dcb 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) +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) */ + int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, bool ip_autoclear, u32 imod_interval, int intr_num); --=20 2.51.0.384.g4c02a37b29-goog From nobody Fri Sep 12 02:27:57 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 D68DE326D67 for ; Thu, 11 Sep 2025 14:21:23 +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=1757600485; cv=none; b=PJybyg/JHzwl3nfnrS+eLH2dUKDqs/fKzw0dZ1h8KQsDemXCZUhL8i1Usto/GXED+2BUxmlUdzwd4MlPKJ903oRo7O9p0HpwJIRLiYNBzrEekW9DO2my7E5LJgg15hPRVf0hNy31d5vyLV/2TTOYAb4kEB0SWla+Tc0vu+zJ1LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757600485; c=relaxed/simple; bh=+J7/cO9gXG5kRzc2nEtM3dWl5SfXmoHOiY9WvXMCTBA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U3ySPcJmMvDVRNd1wtWbnmY/uh2HyIfTMfRmpFM4Y8T4Krzwmy+VGkK1cD5rkSIQEbFHdE7vZSrNz/yidlFaYeJFLijXZJCmpmsWoBZfyU6sM8W9tI4xKdcPFHJ7cg4IXeYw80xxFBnKc9zFcEIM1dVGiFeOds30ZYT0mHSy8MM= 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=syaqVM/z; 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="syaqVM/z" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-32b57b0aa25so851991a91.0 for ; Thu, 11 Sep 2025 07:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1757600483; x=1758205283; 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=dwcx5geWuvQ/zEMPdZ6AIVOaVOt2ShiW7ysN/KvEWSI=; b=syaqVM/znuoQDiRgGLWwigCmlilDjdRqE1wenLD+hH/LGOKmPiSoF/WefLrq9v0k2q S6rkZLdcpUGnNHsVTHpADLN7xrxxk9AxFvi6thNTzSCdhim6pLRY2DPnfiwANWtb2yCN 3jhyxiNEhjg7N6oEiAErzhJqU74uUa/ZIqdC/F0cvB5koufp1/aova04onloXvJnZO6z WRjOD1YGxS5tczXj8H4y7hWQKv5O4LrTXSCsJnct5T5NwBrCipNKdU1nZHwFeXG3fdN6 cCxHHFwqloztjCH8eRXVlQ1ehOn9uQ1c2TQu3pOy9oCr0YP3bHdd+zg7PcmQiIjTIieW oIZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757600483; x=1758205283; 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=dwcx5geWuvQ/zEMPdZ6AIVOaVOt2ShiW7ysN/KvEWSI=; b=MN5AJlda56BYDwby/qiZ1IFAnPVKa5NvSPcas5nYhHip+8MyIbPnWirkFd6ZXyW63N F4O6lgxNKIczHmFgDItmROMBkpDHiA8qcZvN8B6+cjB6Jp4d/81I1UBE8HtdxgqBYCo9 MSZx5TtaQSJt1/tK97PHfpRVlqXfBiZ0X/WKY3QKPCbDIEnnddbqVgrXp6fwEaQEoNtg /30FpwBLsHW27rXRptk7vn09yrTOPXiZlEG7l76iv4mytgOBTt66dFy37v01AKG6yKPB hY7uPJXFuM1yqHRESp3da4SF4vXlWuCxLBGqxCbe82EFwOhvKPO1JBjL1qjNcCs5Z4NM Oiqw== X-Forwarded-Encrypted: i=1; AJvYcCXvxOvu+GVrPmO6E+I672xUyJdP1qcj++fOzjEz8Lc1oigYVChAlwdkLcTu6bWUWfxXYg2yb1UnVwduq+w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3rMQufJ08Iwh8cpvKj02No0W4nOTlQdzRvCX5V0/sfWird+0/ dolJUXbF0j44FmoJy4H+uWmRZ0Sb54orvQ0JOFiQQnE/J5b6P8OuYw+k+klayw25Oie2Xqk/jCH TzWJdPNaUdgsLJ0s9yw== X-Google-Smtp-Source: AGHT+IFzlYBons8HbckVQJEgtKyyQaEqlGaW4mw3hEeEKKFZ+HhHUPGmHhs2V3X+S3wu7586m23KOGhjXW0Ds7w= X-Received: from pjuw5.prod.google.com ([2002:a17:90a:d605:b0:32b:8ba7:306a]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a0c:b0:32b:9489:c860 with SMTP id 98e67ed59e1d1-32d43f2f2a5mr22104288a91.11.1757600481383; Thu, 11 Sep 2025 07:21:21 -0700 (PDT) Date: Thu, 11 Sep 2025 14:20:16 +0000 In-Reply-To: <20250911142051.90822-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: <20250911142051.90822-1-guanyulin@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250911142051.90822-5-guanyulin@google.com> Subject: [PATCH v16 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, amardeep.rai@intel.com, dominique.martinet@atmark-techno.com, quic_wcheng@quicinc.com, sakari.ailus@linux.intel.com, 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 25358cf3e324..6418cfb0fb37 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.51.0.384.g4c02a37b29-goog