From nobody Fri Dec 19 20:55:40 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 CDB5E27CB31 for ; Wed, 4 Jun 2025 08:25:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749025519; cv=none; b=bm2U24BZzS4tP2CtbVL+cKcVBMJGzJ7gAfVKmZCtACnnSqgmpqxmZ7O+YhY0CijRXPxFrAgVH8ZrVP5jph4cKQSq8kaw8Py4rZk1AWVnflGvdrYao0QL8T8iIG0aqflsqkZ/gTdmHg3xHLy+Vz0dxXn84/DSmowXLLzCNnY1bx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749025519; c=relaxed/simple; bh=lzCHfDuCjDrpXiwNQJbgcvSMvP+ebiegCrnWjJNf42Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OdIbdXzPaMbDGoVC5Uz+eumKUHjDrd0A1Nc2sI8GrbE1kVSYzvo+v2loPjNIVaYQO2lWCBvyudEuwlYIy3ZzSDymFqMQcF4Njky+58Mr2qbm9il2GQtO57oGSlSyg4qV1/4d85e38njdlkmYPTYMEleVt94dfKNhT2/yTypLzC8= 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=t22toakM; arc=none smtp.client-ip=209.85.214.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="t22toakM" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2358ddcb1e3so51137095ad.3 for ; Wed, 04 Jun 2025 01:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749025516; x=1749630316; 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=Co0ps7MHbpn7rkQnx+NzuLB263Q8VMNfFSEgEbirchY=; b=t22toakMy4g8wX+unEj2jk6cRZEGTTa4ICKc7Wlu6sVC6ZkJGR9J9wcC4+Nq9T3WE5 4B4Kcp91unH95SxbB0vHRhmwWjieKT/bFc+dpBgLwUQP5lMq1VRhcYoOiupHkjfyWzlt rg1jn77TM8QIxtiNq0JLkcIdvWPBsgAYrAJ351t4sP8Flfusd2/BSO4MdPdjEFj7ILsw dNw4zKFYVy1h03fMSWVAi9rP1sUP+tFndGJENDtjJVD7afU2za8jeW+YtpyfdMZ+d/ij Q1hBIEBMo0tk75lIKjVD0RwZFoIFXJAJSJ6wB7iJlSbeDifHJOEpOokAtZME0Lzxm7Vo +B1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749025516; x=1749630316; 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=Co0ps7MHbpn7rkQnx+NzuLB263Q8VMNfFSEgEbirchY=; b=H/bGZtzxHKmVOpliLCom9PXFzSh2wneM1pgm/g7ldOIXAts3Hn75eZ+amjPpklnW6P Eu8zaYgBlmKY8QwXPz8L6oYXFfm5l/HFIC5KW0ux9My8gc6NYMQHsOB3HzWF1/J3DRmi qiSIBfe4Nbi3YptxWk32M2ZjsDAw/0bFfFZoy3hOxjnNakYzNv3fp0Pjxwf0jajWEAo6 4VC9PanhwWW69djUA/BgpYUN3HnlXkCP9oWjijPHRI/pkfnIwHySvvocE7M0DV0uMPiz H8UC85Q/n+BFWTgIs21kGzbqus78z8EYTLKCBmZRA3RYzEYYfGP19FI3n4cgi62Z2dgh DFQw== X-Forwarded-Encrypted: i=1; AJvYcCUD4ujHWfxaPN/i7KouQxj1R+7KllaT42CA69X5dDfoPdiTGM8Qra3WlrWWkxt04Tbx9khp/klForCCbNY=@vger.kernel.org X-Gm-Message-State: AOJu0YzpdiNDu1SjPnEbX4iJfPeJQiqowWkQPbvLc9bxboBtxhJkBbJA 285LiOIDIoobr7/DFcQe3520x3YWkyiX41/mYu/D8GcJVsD5VGpp6rWbiGLKIKVQeUq7ad9YbUR YJvCXsTIx6dXqzwFAVg== X-Google-Smtp-Source: AGHT+IHF+WdkmlHfIoDpmKOjojy+Vo27TfduueaHwdLb3sRf0zC8mqwDEEIa4Dg0gLrSbdKSr8+6UZJYgZWFrrc= X-Received: from plje10.prod.google.com ([2002:a17:902:ed8a:b0:235:e89a:e839]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:240f:b0:234:d778:13fa with SMTP id d9443c01a7336-235e11ebd60mr27791485ad.26.1749025516040; Wed, 04 Jun 2025 01:25:16 -0700 (PDT) Date: Wed, 4 Jun 2025 08:23:07 +0000 In-Reply-To: <20250604082449.2029156-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: <20250604082449.2029156-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1204.g71687c7c1d-goog Message-ID: <20250604082449.2029156-2-guanyulin@google.com> Subject: [PATCH v14 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, sumit.garg@kernel.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 tested-by in order to even consider accepting this patch series based on --- 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.1204.g71687c7c1d-goog From nobody Fri Dec 19 20:55:40 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 C582C28C03F for ; Wed, 4 Jun 2025 08:25:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749025524; cv=none; b=VvNtGGHG6sKfvJx+8JMNDPlyEFUCXFlFucmNW2aHGY0O1/Ag/Qcwdb67SsOfQxOdoVer6Tb1ByFWghTjNyeNbxr5O+367xfXv6BsbrxVLAP9oT5ux1mYibnU6XJk13pK0m7yXoJt5UNJDbycq9THHNumOr6fQs8FVtc+1F6Auvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749025524; c=relaxed/simple; bh=Cvi+qX7V3yh4py8CpZwCPartnmTTJXgQ4sjZDl9R9/A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aBLar7T0VVxDJO4I0WY/A+SnzbOIcdJ4b0Ihnz3xY4Pnxi4rJD5uvkegS30guLFe0uubtOgJQoQjUE4jmv1zP1G8VpZmG2jusleu3uxHay0xW2qUKcUE3C8a4wKcbR0rlzvhHjGsNgqwJlFadVpLJyeriFSOOnQX+APjGbfK5YI= 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=2Ci6ILWt; arc=none smtp.client-ip=209.85.216.73 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="2Ci6ILWt" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-311c5d9307eso7539298a91.2 for ; Wed, 04 Jun 2025 01:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749025522; x=1749630322; 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=SOf8xK1w9I70ecjXO2yVBy3evGt+tsMF73h7OsoKTPA=; b=2Ci6ILWtqbf7roXcMWUJEP2a1c64O9DeWB+x4crePr3RdzbRUcHv00WD4RwEQwZS2V dOz4zHcPb/jJXie7xaAVXUieeXhw1K3iW7Fg2tIyXojQzlVCsvFphzcoYxqpZDC6sQuZ WvGZ2jszpD2sSpQUw3BPp/hMF8bN6z897o2ALFZES0BlH0Aq6sqewlr9uu51hnUXXhxd E/g0LufzNgQA3aj/qjiT/3h+Gt3H6KAEkw/kqdPVbmEVgDvoBrtT27HVMAUkVAU5CCAC uku8aZBtZLiLnXlq6U/jcs0sIHUmK3QMbibai9aopH2qmOfE1/ub9OAJWW/URfpyZvnY PlUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749025522; x=1749630322; 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=SOf8xK1w9I70ecjXO2yVBy3evGt+tsMF73h7OsoKTPA=; b=K9kjk0nxWJ+xa1hjwWaRRZo97syCxerUN20rVJv5CH0L2n6/KvUDKpMe3jAb4kwCh6 duvnPUBBnFY0PU6qPgsg8rtOccGiZNUm5DZO5CULOPqrCFuSPXzmkQp8OrUvOWYnLLE8 2Pm7d73pPuglfVH7blHNa+Z4B5Yil4oo+cFHoPY0TByD6ClTK5asN9IwHz8LdidhfHnX VjASI9mVYfPHCRXdmnanGBvJlVffgEpH0qKghp98AHGcTuFmRc6hhWmWsQcMSfy1Ibc2 w/Tce+MrJAvZoKW+xsaUSaY7aKs6ZnPWj4uanJnTEVcMA1y4OpIhpL+XNX1nsW1P/d3p 2zaA== X-Forwarded-Encrypted: i=1; AJvYcCUX9qQAfBV1faH0Ff94HoLgvJUExNwuZA+O3i6tZR7y6jG+40EEphl8cbWmlDCUXuEozjp8FYD3IPUp4Nw=@vger.kernel.org X-Gm-Message-State: AOJu0YwUjiY8rL1FbkHCBE6qp+n7Y9ltkIw8ge+w72YFHEw0m0eSYwpN yFM1QQXzokmbM7CNFRYQm2hAm0ylNofFETrW0k/QBJvK0rYgJgDoeESy4KQpPWw6OpBmInaFlgz ss/CmsA7b0pRjqryB7g== X-Google-Smtp-Source: AGHT+IFa4wqPiZhy7ZpMV4W/HCewzpBEiKsh+nqcdFS4jdQgSaYy4I/p61WPgjisw4AoVzrQvLtPz+fYIbMzXVI= X-Received: from pjbnd4.prod.google.com ([2002:a17:90b:4cc4:b0:312:f31a:af55]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2642:b0:311:df4b:4b91 with SMTP id 98e67ed59e1d1-3130ccf6f5cmr3245598a91.7.1749025522075; Wed, 04 Jun 2025 01:25:22 -0700 (PDT) Date: Wed, 4 Jun 2025 08:23:08 +0000 In-Reply-To: <20250604082449.2029156-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: <20250604082449.2029156-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1204.g71687c7c1d-goog Message-ID: <20250604082449.2029156-3-guanyulin@google.com> Subject: [PATCH v14 2/4] usb: offload: 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, sumit.garg@kernel.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 tested-by in order to even consider accepting this patch series based on --- 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 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/include/linux/usb.h b/include/linux/usb.h index 1b2545b4363b..86922f1233ef 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_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.49.0.1204.g71687c7c1d-goog From nobody Fri Dec 19 20:55:40 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 A758428C2AC for ; Wed, 4 Jun 2025 08:25:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749025530; cv=none; b=RmtQcuFuo7bfRWVXdl3bcZa6w+ACoQztWdYiKEgPb9sPh2X8hVh7HJLk7BqrO6pfA13S+L2aVa8OC8eS5Z5txo4si4z9ENcGiO2VR49ONmgEgGN8fyF//H5XglseLjNMqYIh5BhW7LlOVkZQcdzNPzS4cwiv4+6m6gmXyMGiin8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749025530; c=relaxed/simple; bh=LqCjgT0o86qpz1bAfVx/xUUv0oZr65BY+HYAir72dNQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qbEAV/CND/UQ0laMJMBItgH5rWiYf14FFrI0lOBYz8g9kqWLMUNwCZ+HJKqPs0RbR423sNxq3q6e6f0EMB78fPiPALhSYsLYr9dlPNIcWQdJ4Fxp9Ph5jsAK2ukV1EcEIOPgxiYCwOASOeaAh75W+KmpSciVk6H44Njt+EV9UQU= 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=ptZIDVdf; arc=none smtp.client-ip=209.85.216.73 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="ptZIDVdf" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-30ea0e890ccso6367088a91.2 for ; Wed, 04 Jun 2025 01:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749025528; x=1749630328; 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=vr9BR5zFeEkJuH9gfqHRpAFxp+Is7OurxJ3CD5N0N2g=; b=ptZIDVdfRgsgGARt90NEW8rAx5bbNt61BFn9UkZ4vrJlOGUIJShQVUNUirT8BpKGiL budvSdC80P3MsApNJykRQUO+RkO08r8yXLCZ1kxs9uXfNMheTSjHsWhHKgwq3woHfmMv 2q5Hrw/5w7ah964zMj5R5pN82m23pOBh2sPuHivn5rU8w/CbJYq8eu6lysGxrMOSeusd yYJjSHPR0uw+5DgPoJCQY94HFCl3HqBryt9dOH6eePPCwoqHb98PlQf/T1Inlklj954p WbSsr01QOmqABUnI+Y1iie4YfLMO0mPJgZMI5xMeYIJ5sZiKi6CXTTle0hE8EPf/lD4k ytSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749025528; x=1749630328; 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=vr9BR5zFeEkJuH9gfqHRpAFxp+Is7OurxJ3CD5N0N2g=; b=gfe6/7MkspuijePFInzWhkOgnmGHK+3a4tnKV+zSfj4Bm77Q/9QuVGwtaaZg2WAArH v8jcm0zCixHjO59WyoQi0uL6lh3xOrV31ESsF6KvEwcSyuynEuOBGK0wpBAlbE4/cX7/ ZgJ0XmPbs80M+Q28oEZchHcG1+VNja8AVRalss9LzG21Ho67ugzdg85mIzu32+11c4oj MlJ76NERSRuot4+IwHVMy/6ffTiFLfZqP6Am7fgqowEE7NHK5FAWLOCfyqYcmO0hx8s3 TwmFQPj0a1QDtBJhTOT8E6cXALYQU6D3dden7Q51X8x2V0WYlWwMxG6a7wYZ8H7l20b5 iIYg== X-Forwarded-Encrypted: i=1; AJvYcCXLRCxfHnsA/o8228hiKHC3IdQlvu2KItB/AvZHTxnORFjvk04p+vFXKyZg0aInh6LLZULELM6U6N43M9E=@vger.kernel.org X-Gm-Message-State: AOJu0YxNsBUpAgWGpVLzhAXAWwpM9Hm0DUPV1Oc2UwMjaG+Ow3H0FmgO FVzp+rtaKLx+VE7kroApidtwZUBbp03ehihCCZTNTdvachFIod4hZMX53XEv8xuIl79N8iJPB1l 1gZ4eWdp6/aOzvp0D6w== X-Google-Smtp-Source: AGHT+IHvWo1hnryqNLx7asfo8xGvTcYhV1b2+9enCYyP41vg0S5xWofxTjdyel4IF4lGoSrUsedQdrBouszQOsA= X-Received: from pjbnb5.prod.google.com ([2002:a17:90b:35c5:b0:312:1900:72e2]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:278f:b0:311:b0ec:1360 with SMTP id 98e67ed59e1d1-3130cd680a6mr3008711a91.29.1749025528036; Wed, 04 Jun 2025 01:25:28 -0700 (PDT) Date: Wed, 4 Jun 2025 08:23:09 +0000 In-Reply-To: <20250604082449.2029156-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: <20250604082449.2029156-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1204.g71687c7c1d-goog Message-ID: <20250604082449.2029156-4-guanyulin@google.com> Subject: [PATCH v14 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, sumit.garg@kernel.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 tested-by in order to even consider accepting this patch series based on --- 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.49.0.1204.g71687c7c1d-goog From nobody Fri Dec 19 20:55:40 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 A5A5B28C001 for ; Wed, 4 Jun 2025 08:25:35 +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=1749025538; cv=none; b=ojRmx/E4Fc01L6Iu5tQsVfwHEl7Az18JBV2Kmsq8gV9ZMRYEYTyg1KGOqXJbDr1fLcy834w3k1a8UbKMF9RNBoz9KJFxMrbG3BmwI85uERSOUJzFfbLftvg1JU4lGOhzoCZ2rUs+BxiX1H60IVi7bxeztJ90mMHjDU4iYBx2xSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749025538; c=relaxed/simple; bh=yX3t/dCpCtr5555ro4UndY8sNQPP4ux82f0hb5SqNvs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qMsmxI8nmB/qoS8E1Nge9oop7DdnyBEKzW3amDeqljKlvCjbR2Eu0VPwq+dDAsdG8cMZWAZ5fR06BUnZyZ7/ItAzAqFQCBEnOSgp2zXJ/n+gZquk4oNR9te/LpVFjo8rDvAme46s9q7g7Ac7t3KgUHDoC8AxgpQ3D1Cg3l7ROy4= 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=Z4Djtc7F; 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="Z4Djtc7F" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-311f4f2e6baso6374856a91.0 for ; Wed, 04 Jun 2025 01:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749025535; x=1749630335; 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=4XL89hn3edGr5/C3sJ6fxWWUscalAVpNktAagGHIzjk=; b=Z4Djtc7FOBy9qd2qW1et4yzovqWu//ynpQ4Wecgam5FWKjt+EfEaadcrFN8nnES5pU MhDjUE7rRBZWSQkTnPyQMbas5Tl8ahXsyYPdRw6vtkFRwF34pJCv+NoTdtbIJidRlV+3 GtjUzzrRM2FpwVPsqixnkFhB4XtOdE8XOJBR+4db8LRneTce3m8JdjuouXH5Lu9n8EMe XKIraQzmHQ/RmpXY68CFFLPZi0qIxLhj68JkLi9aovm8JWT5jKIPtqbxANhB+EGAvI4G Zc/bClJY3Dpf7hLx3+rW+N/fi0tPhkG1qe9t8jSvF9JOW2GsWuPBTSKgQSBe8srkoeaJ 2qqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749025535; x=1749630335; 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=4XL89hn3edGr5/C3sJ6fxWWUscalAVpNktAagGHIzjk=; b=lmpt1yN85Q9M5ecu75NEJ7Duk29SAcce5YPk9h9HMJHET2Hj7i80dPJBsqsJysMcp0 OoPeS7U/mQSG43zhLJl8tLRziqPWEvG/4YdY0wmGNKDo9+eT3k2FkgwX/RmZi8tNcAYg sw6bihfcNovix+42d65Tqe1Snc/VH8xhgIZvuKVJNTcqXczD41HKcU//RxH9Hhncxs2x IMxU3FHTFtBBY7w6rkcO/3NSLMsCaJJDBO2KtrRp3a059SS1dsYEVqIfscGcVt9Vt/NL 71Pd+NMt+pMJ331MWh1scKgBE9CFJpEPwHzC1OpdjAMlSF6F8uIeoKbyd2vI2NYit8o7 ZNEQ== X-Forwarded-Encrypted: i=1; AJvYcCU9AeRgssHpC50WknHFNPAfcqEW0ZKj+TZtklk+aOoWqUxeIH0KFkMADPWYl86akDvKatb1yjmYXv2wmKc=@vger.kernel.org X-Gm-Message-State: AOJu0YwHHijiGkSYAfmpxDFEYgjGKbkJVZSvTjca7vIX5fywla1E8rDE souMTGFqeROgkuViDCcEH5fs1UzNGJGG7NTwoOMrtHsrXAm6ZYa1xxDVBLbS4d0ZdtLw9/g0LZP aRcECcXOnyDrY3dWxmA== X-Google-Smtp-Source: AGHT+IGUIm/2m0kobXXwkRvujWW+QAGgYDsbL7UPZxfPqk00rry03tOVKFtPT3BpJtlUSrlbXyF1K9f0kAzEszo= X-Received: from pjbpt3.prod.google.com ([2002:a17:90b:3d03:b0:311:d264:6f5d]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:46:b0:311:c1ec:7d0a with SMTP id 98e67ed59e1d1-3130cdad279mr2907670a91.25.1749025534980; Wed, 04 Jun 2025 01:25:34 -0700 (PDT) Date: Wed, 4 Jun 2025 08:23:10 +0000 In-Reply-To: <20250604082449.2029156-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: <20250604082449.2029156-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.1204.g71687c7c1d-goog Message-ID: <20250604082449.2029156-5-guanyulin@google.com> Subject: [PATCH v14 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, sumit.garg@kernel.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 tested-by in order to even consider accepting this patch series based on --- 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 460d4dde5994..d46bac81d600 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.1204.g71687c7c1d-goog