From nobody Sat Feb 7 17:52:50 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 D9A1427466C for ; Wed, 28 May 2025 09:09:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748423350; cv=none; b=iE25mODyAMq6il2RLdhM0bZQvkka5kBO11A0hDhQjzUPgJP7KXUc3uMjt+HMyPxeBg0MyMKnt4E2qTWEVEUrHxvWQgKY74V4gLAAXdv25wcwlTrtfO3IKKT9X8G4ZdqbyBNBPi8EDDwHiOdAEOJbggt25ooX+eNIEISBblt6zbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748423350; c=relaxed/simple; bh=yiqxlEef6e6oha1pchQ2m2q9rAFOKYzae/zmvK1wqYI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=SzM7r6e/HuLGDvyR5rq/+fAIrSo5KAoVuoJ+tgk42DME78md4ObtEfnPPL2NRLDD8R8MBVZw+0AvQpMR3FGfjtRmVZohvZYlDbvcF15OKI2W1okd6qLZCEoRxvPyg2pW/UdJ2uuRmUKq69O9Gzf8psFrJSyoIK2yFMLJ4d6xMB0= 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=na4J6OKs; arc=none smtp.client-ip=209.85.214.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="na4J6OKs" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2342ebb8a83so23163655ad.0 for ; Wed, 28 May 2025 02:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1748423348; x=1749028148; 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=TcH4wQEDitg7iKswMVLenRvnR5FQWdp+kaJqj06aZvk=; b=na4J6OKsqMB8oA2bft+eP55kA60mob1TU4mqPIq+qhOyLA0w/oT4Qj/l2WTqhbRNgL Gg1lYeIIYY8SQgrUUkTi7V+HjSGtrIrrb96SIkKQjU3paf2MGeqQPNRgsEHcMDnJkzDS USVB6G06W0adHpbY44+V4GimjwnN0z30KBjIN44gfG7DNRhafh9G1kPSXDwYHAFWYOK3 8yUmBlzVh3tmZnwhVXqsfp2ppKR0KlYMQOpY2h5Flm3cfUdT9x882IKW9oK85j/JGDyf SlGjV0l2qUzTtj51I+ZOwwUHYTNZ4AFifskYaMp02itwL/qMNSVUKgMiSR1CwBsUEZ9n TpEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748423348; x=1749028148; 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=TcH4wQEDitg7iKswMVLenRvnR5FQWdp+kaJqj06aZvk=; b=hClfdZ/V025/09F0okYekKGCYExCK39Und3JqqWKhmL8rXNFxhNG+Vtv1+KGTJJVYl Y+KkoeHsaCc+2NnqwwnZL+BuAeHsy0jAl3P3kRA4OJeK9b78ecOKG/bXsPDE4rw6Jczu Tus1gb9zRveQRwk5OoTRg7zMj6oLiEDAxJNPhQwFrCQO0KrjN5FDOPHnWaPsfTmafdxz 0+lpsMm7V/EAvntoCzTabmwRu80IaFbUgoR86Uq6s/mo9mxKNWKj5owQ+43aAt3cRLYd ypI6TtrezxXKzUD506B2RXsMdKfkSevtcSKMoZh89QgsvQNwarnBCOqdBRnpJKJPSxBE JqoA== X-Forwarded-Encrypted: i=1; AJvYcCV9HSsC3FXA/Oq5BrHjpUJRyWvRaLSEsXR9IOI8RziAhA44DcLgeZJhfYvBeDZwUr84gjt3p8CrU6VCqH4=@vger.kernel.org X-Gm-Message-State: AOJu0YyzlCNmvT/da5eSfHvLaNrSHC/MzkQzKo73lahCmBqV7dFf3UBa CvIib3BzAUaXk7jVE/hZWgBUPKQYlNbvo9A6BXDrAJh38y0DG0SsuoKSwyR3ZgNh5qqQuBvRokn xyT+dU8aIGlAL91gZdA== X-Google-Smtp-Source: AGHT+IH+Sq62F/bY1S8bL8pzuwSaysSESeNWCQygopA9Z8I3D+IHWKzwUJfPC9+GkMueR/1jmMaoWl6hpYoz05g= X-Received: from pllg6.prod.google.com ([2002:a17:902:7406:b0:234:aaa9:fcd1]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d490:b0:234:aa9a:9e0f with SMTP id d9443c01a7336-234aa9a9e76mr62606355ad.23.1748423348157; Wed, 28 May 2025 02:09:08 -0700 (PDT) Date: Wed, 28 May 2025 09:04:06 +0000 In-Reply-To: <20250528090849.2095085-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: <20250528090849.2095085-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250528090849.2095085-2-guanyulin@google.com> Subject: [PATCH v13 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, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org 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 6dab142e7278..9843d3ad5cf4 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -453,7 +453,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); @@ -481,6 +481,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); @@ -528,6 +538,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); @@ -557,9 +572,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.49.0.1164.gab81da1b16-goog From nobody Sat Feb 7 17:52:50 2026 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 527D92750EC for ; Wed, 28 May 2025 09:09:14 +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=1748423356; cv=none; b=LDGYvA8D4T4UM9qChhxPHURKYp20wkQNOnL9TfVqDKziLEbDVb0R1JawmZ3557YAs7E2OyLdstONe7MQmujzF6kkHFdlbKo2sOVKSLG8Ighs9V9uoEQrNGxzelgkfZyRgfD3HSz83oy942CS8d/H1kPZVWi9RusGP+qltKX8foQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748423356; c=relaxed/simple; bh=QZ8nwHA2Zs5IEnJ/86ZrMAoj82ULzOVmYhVsq8xnvV0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=G2//FpwNKyPMlcQ47wIT0+D27M3EtWVfsQnLe8qvGCRtx/9O3CEmnsDuw/DVJkLur9H1E9LoCvYEuiiEYv7P9OUzcjo/SuQPFbwPPaKk3ChCP0dcUD8L/oeeZE/x2cKvbqro7N0NZAwa5K5RwOrktXNakaEMlFGHYnpfaQoyS64= 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=Kk4Xas/i; 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="Kk4Xas/i" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7398d70abbfso6225034b3a.2 for ; Wed, 28 May 2025 02:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1748423354; x=1749028154; 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=7i0pI2VSaiukiHxpLuyRQrobpFu/1Ba7IiH2E3RcyA4=; b=Kk4Xas/imN00BaTVVlwEXFyFKxqLh4SF4jrmcQSq1Onjgk1s2qSjNIWP01OSHoF1bN fZjoyQqjN80C4MozsZG8FYdfQzSSyMto9gcKeukWUKTh15YsKAeg0lkB8flJn5kMQLyi 3nm2TqYCnXF3qRZpN7sVDemh8p+/PjDqGXehJHQjFjpXZizsSvvNQE835RrCK7l28vzM 7R9ZUvftCtNaH6Zs82jnHz3wJi+Fq3a0TFzHZ+jpv0qRXewhJ4w/7BK9Wc9dUx81G/Fi n7XN6nZbXpyACgYZOw9mMYvHf8C+pt1OYIc5Wsjbnwi9DiAs3vh0vD7ASOZCjJ3pcByi PK5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748423354; x=1749028154; 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=7i0pI2VSaiukiHxpLuyRQrobpFu/1Ba7IiH2E3RcyA4=; b=doMPTnlV1yEx5sPDQF+YwIGpI40NNwfOHKpNwIyO1T5VRL0NznJrFIykIzmBIy5PGk q4hHr8/o18RxyxVKlfWoPQz+vdtrjA4C5Zx39L7nHhcxABxW23BX6SqVVEA7jh82aRMW WLb/76bAuON5M1zxSM8h7x7h45jX73bDgIS3beHBeRoxkAHAUPaD5NvfwhnHrNvqjW0e Z4y6wooLk+tumbm/zr+QVnBV5xLJjJkPfRByUYs0EKkk3ZgL7qps7nKtbAhFl1ENUYsY R7fiOVhaY7+H0pHWHTem7nHRpcyZ9IMq8aNGoYGtrjkVm8FyXz2Z9+gIMw1TZdcW3ytK MDEw== X-Forwarded-Encrypted: i=1; AJvYcCX4pUGKnYwuRl98NkHRq48VRThg9DnTwXxOQttnVKQt4s+uCt9FsiO+HbEOY3r2g5WYHBQgvP8+YZdcrEI=@vger.kernel.org X-Gm-Message-State: AOJu0YyKcxEzLv5ft2rBrMuPsjL8TsXW6YHZAsZTk6xGbRPwPFlg5MYF HtZQLbkLoi+IP1j33TptcyUCOikveGpeqMLvbVSJKwIEXX5ZmNXDVguN43PDtY3in9W3N4UEuee aPUmBr8cHLmN6hO70kw== X-Google-Smtp-Source: AGHT+IGAY35NYQRKcefBr55JNYjQ76Ji/yrxDy5NkYKXawxtZr4Wq4bM8PsSVQhHqGBP3evI8i14j8qyWM/F92s= X-Received: from pfak3.prod.google.com ([2002:aa7:92c3:0:b0:746:270f:79c0]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:9154:b0:746:227c:a808 with SMTP id d2e1a72fcca58-746227ca91dmr11682121b3a.24.1748423353862; Wed, 28 May 2025 02:09:13 -0700 (PDT) Date: Wed, 28 May 2025 09:04:07 +0000 In-Reply-To: <20250528090849.2095085-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: <20250528090849.2095085-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250528090849.2095085-3-guanyulin@google.com> Subject: [PATCH v13 2/4] usb: add apis for offload usage tracking From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org 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/driver.c | 125 ++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 1 + drivers/usb/host/Kconfig | 11 ++++ include/linux/usb.h | 18 ++++++ 4 files changed, 155 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 460d4dde5994..0690619454fe 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -2036,6 +2036,131 @@ int usb_disable_usb2_hardware_lpm(struct usb_device= *udev) =20 #endif /* CONFIG_PM */ =20 +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) + +/** + * 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) { + ret =3D -ENODEV; + goto unlock_device; + } else if (udev->state =3D=3D USB_STATE_SUSPENDED || + udev->offload_at_suspend) { + ret =3D -EBUSY; + goto unlock_device; + } + + /* + * 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) + goto unlock_device; + + udev->offload_usage++; + usb_autosuspend_device(udev); + +unlock_device: + 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) { + ret =3D -ENODEV; + goto unlock_device; + } else if (udev->state =3D=3D USB_STATE_SUSPENDED || + udev->offload_at_suspend) { + ret =3D -EBUSY; + goto unlock_device; + } + + /* + * 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) + goto unlock_device; + + /* Drop the count when it wasn't 0, ignore the operation otherwise. */ + if (udev->offload_usage) + udev->offload_usage--; + usb_autosuspend_device(udev); + +unlock_device: + 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) +{ + 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); + +#endif /* IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) */ + const struct bus_type usb_bus_type =3D { .name =3D "usb", .match =3D usb_device_match, diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 118fa4c93a79..43efd9d939c0 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/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/include/linux/usb.h b/include/linux/usb.h index 1b2545b4363b..f5bca317fa4c 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -635,6 +635,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. @@ -723,6 +725,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; =20 int slot_id; @@ -839,6 +843,20 @@ static inline void usb_mark_last_busy(struct usb_devic= e *udev) { } #endif =20 +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) +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.49.0.1164.gab81da1b16-goog From nobody Sat Feb 7 17:52:50 2026 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 58E9327585D for ; Wed, 28 May 2025 09:09:20 +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=1748423362; cv=none; b=XMxHs3ndE6XPnGUJPf63QCU3h8hKB0wF5vA/R26ALtUD4LSp5yDtctNUlMJkbuWj9Pc39ciMPsIk9QAAsuY2dpa/G2yC+Luw+yZnjHJRE/EYRocVW/WShTZX2I/MmdpMeefodDdH0zbolv0NnlzRPXTpJa+nuqfkP7YopUVEFaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748423362; c=relaxed/simple; bh=hrgpN3OwJeQNAYG/6uuNH84rejxPQEHYyomN3p5Ed0o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jC7ZLJ5W/hu/FJpXEU8lAEMys8Uoar2Fs9JF06x60rM83e2nYUgrJ/6zFNN2by7ej+NhB/SAGwyKXofszL5MVrgGGj/bcsFVK2aZPn+HzR/9BH3+nFulUZ3xH7JYs4OK1mbRBj4YfAMvoqWnJSvfQrfa5j3M/qE3D1QiYkswys0= 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=IoV0hxOj; 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="IoV0hxOj" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7370e73f690so5186461b3a.3 for ; Wed, 28 May 2025 02:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1748423359; x=1749028159; 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=dsGGKROW/GfgKslG2eM9ME7ceuz0kmeKtOiEDD5cNB4=; b=IoV0hxOj0EfCBRp+I5YysGUdLXakuPeysacfEsj9yErV+8mUd3N6EOQMLppzaThAAL 2zs2FqlYx8dmFLUnxDx+XxsrpwZPbBfS0nsgDKFmRh57ayuz7Y3pY9/PNlUO0bwADMPt VYA/x+U1uLAasXHpbR3qnrXlOlLpf7ZSUmViLFTmY8Jnj65OII5uidGrw4oWgJfL+3uM UvaoxHzmHMg3SsxQJReSA7oFlz9Cej1Nm1hIgA0gpZQsqlyH1EQ11F9acSi8YKlrJ1Ce WQG6KHV2H87EjnuAwO8xjLuFtcWx2Y+kT0qAZ6SSBS2oJu5aHD55zqh2/pWz6ESymANr THYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748423359; x=1749028159; 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=dsGGKROW/GfgKslG2eM9ME7ceuz0kmeKtOiEDD5cNB4=; b=ptbYRQM/jpX4nfO2O1JhV7Z1cvWe6n8Bb8Bmj8kwJli0QfszVC5vvmOcNaQaVThwBA 77qJybWIrnyyxh+PU+tJCIwSwQqg8bAbf7S0v3GlPrKn7irH0oIk8qQwSdbPqmeAW1CH /QP1xdReyNFChxBJCBUlE6lPX0/ub17BnJ0Qs7Xnyx2z1gULhhpv+lhrw505J3iqrjkf q/pHs8skN41j9MdVHz+ctKl/AAxsW1NQpLkqVYdbU7A0MJVh4obsKewm/2j+/SPzYJaa IQ8xvUzvgLzoyTSYHqGO1Bzn8QpQg66PxdhMqwYb1qmLdjt0+8z/0fTgJR2H2XNGQL1F nKrA== X-Forwarded-Encrypted: i=1; AJvYcCXhY0AIjc6SdlQVHLdFhaPCkmTMD1lWEqzN9xQOmiyyZngeVNYQWzm/wKZmI4FTR3TspxqPt6DR0pFUQkc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6GylprkuL0HZAUpxBur/Jt9MzE10YUZts1I6g2MohmT0Gx04l v8cMZu2c7zy7uYyzsBBFC+0Y+ZYrzoH8JoozLAoan8KUmQC/LKc2gEyCH3K8KHRWx10e4a0HHI2 D8Lf/QyzFrZcAsgR2kw== X-Google-Smtp-Source: AGHT+IH0sOshcv2Eg/mtamrUvZLDqjNwkwxbBChcNpFlLYKw4WlgSYYlucjEvYWbAKYNpPLOtqR7MqHtvhlo92Y= X-Received: from pgfe7.prod.google.com ([2002:a63:aa07:0:b0:b2c:3c0e:f01c]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:b85:b0:1f5:70d8:6a98 with SMTP id adf61e73a8af0-2188bf2ac76mr26106597637.0.1748423359626; Wed, 28 May 2025 02:09:19 -0700 (PDT) Date: Wed, 28 May 2025 09:04:08 +0000 In-Reply-To: <20250528090849.2095085-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: <20250528090849.2095085-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250528090849.2095085-4-guanyulin@google.com> Subject: [PATCH v13 3/4] xhci: sideband: add api to trace sideband usage From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org 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 | 38 +++++++++++++++++++++++++++++++ include/linux/usb/xhci-sideband.h | 9 ++++++++ 2 files changed, 47 insertions(+) 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.49.0.1164.gab81da1b16-goog From nobody Sat Feb 7 17:52:50 2026 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 3CD7E7F7FC for ; Wed, 28 May 2025 09:09:27 +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=1748423368; cv=none; b=levRGFq7Eb0tHa99rqriKDVSqWKsCjKzLuwB9ubSZJ97AUJnQ3kKcqBXpjUJDSAgfJlHpeDONcFmfbZFOa/RHhrvZwQuOQ0cB52x9te3Kg9I/Nhsa5OC165+hzlbq7o40ltmh0IHyo8/kUi2wwLCaKklCr6LMbefPeSXXTQ5XOU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748423368; c=relaxed/simple; bh=jrMgYnui/1hVK+NOX5Q9Qlx3CZm/zQKpCUr+Qb1NX1U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sa8cMy8xxmF5mLxJ6WCwge27t+0y7bESzVPf6apId0901BmennEy4+wdnaOMsKaIGUbl6fOVrXxr4zENZtJfUqyxyi81RZUrZ0LIvTBn2u2HFfyinXsZEB42/N0HAxUplMcgjuO4kEGYH+7DzcUyeraeyVsHvploekN7k8x+IOA= 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=hMet6rKD; 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="hMet6rKD" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7394772635dso3029731b3a.0 for ; Wed, 28 May 2025 02:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1748423367; x=1749028167; 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=/SiziDgdhNeZTL9A0KOfLtmGGL2LYblCSJ9A9F+7hHo=; b=hMet6rKDQp02StRyefZt204NNzuJTySC0kS+4gDTz/L3Fkpaid8lPtnm8pwoyaRSGH mXRn4lMGICDH9JtcgtuEjDSTHkW7Omp6raXGERATKLqmP4avsGVoHBWOavsArPOZAzDN piRUT/p5HZVEZN4UO0lPFQ8tGd3iejSTK2GANayC0jaamFWuurwUFec/GhJRrhB8aOkH 3OAQ++irqNkV3ahEi5ATo7OgxbC55iZ6BDhfhqsRtguASu0JA2/rpjKgtvF3aJEVJ/GA pVDRTbiEfdhnCrlPtOf7FSYX3h17+sOv/JsjJhcyvEq9fOOCeHzTvA/Sb5Ux8DInpXKg /LyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748423367; x=1749028167; 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=/SiziDgdhNeZTL9A0KOfLtmGGL2LYblCSJ9A9F+7hHo=; b=dumrXBxcQuDVrn/8m1+w83H+538kIt/zTEU7jKUWqJx6n/XJ2SYffAQ2d26JRp6JGs fgFtZuMkg0ZurbogZcvOCgf9dzClFKbGcbimfTahWTKoSrh4KvMAgTyY8JMpZ5YeWQ8V fCCzFApnrFjCQWgv4Wr69RqwpCuG9F+Jprs3j/rywuofTYFe4QVuh+nRBE9V4oegwKxI KIHEFMayIPE3+PVfJoUSfXVMWriJWFEGmu5exquQxck8MLvA7hoISd6JxQaNSSjzjwl/ 9s6lvy9LV26jUaRQpwc6RF3gDJBtLS/5HxXZVo4ixD1jSIBlism5f9NzKVgG7kTRtZom X8pg== X-Forwarded-Encrypted: i=1; AJvYcCWLtU92zuh2FPgzH9rXAzp8cDTLFot8HB00PYQV0ZF0chDAx1S/gAKDUd2fnvgHu/lT2xUesR90Zv7AHPA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/4/cQJnOxGEwo0MF1keoCwidDRvO+OFhLwsIQFxYDr8ua8ETO +Ajrye2XZqFijQqyC7lgYyBXhgegzhPxZ6iiWe2J2vdUs2fSILi3rVR6ZylZDjD5YIeO2UB3435 H3JYPctiLjJSoxhZQIA== X-Google-Smtp-Source: AGHT+IGvGoiywFWqdw4XJjxAetPAW/GhM6SbBtnJ9W3r2UvhsnuVYFnszlWmq+mdtc9aesIlyy/EHaQ3B5KWm8Q= X-Received: from pgbdl13.prod.google.com ([2002:a05:6a02:d0d:b0:b2c:45e5:996d]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:b85:b0:216:1c88:df46 with SMTP id adf61e73a8af0-2188bf2c994mr25447975637.0.1748423366730; Wed, 28 May 2025 02:09:26 -0700 (PDT) Date: Wed, 28 May 2025 09:04:09 +0000 In-Reply-To: <20250528090849.2095085-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: <20250528090849.2095085-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250528090849.2095085-5-guanyulin@google.com> Subject: [PATCH v13 4/4] usb: host: enable USB offload during system sleep From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com, krzysztof.kozlowski@linaro.org 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 0690619454fe..9670c10f4ade 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 9843d3ad5cf4..598f1b974347 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" @@ -483,6 +484,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 @@ -535,6 +545,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.49.0.1164.gab81da1b16-goog