From patchwork Wed May 28 09:04:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 893314 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 D9A7F27466D 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-2344f88f9easo25079375ad.3 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=t2ICJPzFXAXtcmldjvIxyZ3r/Id+ASEfMbCcyRUk8BnfvQu+CJIXmWg2ykc4VOVr6Q OsLWxgVgALr0GXY6SifdzDH+IiygCNaldTAnFQf4ACeilz17Zn6uqXZitS/53eySaxAB /W+iJZx8iOrOXeVPT6U5qed6T5TzTVE7ISXpDh2KRK+q5wOLddQTPSIX9w5awWSWCtiG 2GOiIM6D6hiibTPAn+3q/R+ClrOtDVYLw7+VKUafsfpIu7qpc9NZO1DvpQ871LAdm/I0 ruFJQiDzxQlFNfdrII3eZLMbQpgGjuO94etvI4h/GRIpUVnInrlsSwriJqSpntLp7XJm hXkw== X-Gm-Message-State: AOJu0YwqrreQbc4rKoE3x60o3fxTZ7XWV8c88oduGWbITtIvpZ+YSIVI f83WLvzzIA9ae1inZsiAM/tiC5gLMFD9Z5XVtar6/VTfQjJNzjktvRuplfDYtKR6ITOub8d5xQV Z9pNvYUhC5vyi6zA2hQ== 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-usb@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 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); -static int xhci_plat_suspend(struct device *dev) +static int xhci_plat_suspend_common(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct xhci_hcd *xhci = hcd_to_xhci(hcd); @@ -481,6 +481,16 @@ static int xhci_plat_suspend(struct device *dev) return 0; } +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 = dev_get_drvdata(dev); @@ -528,6 +538,11 @@ static int xhci_plat_resume(struct device *dev) return xhci_plat_resume_common(dev, false); } +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(struct device *dev) const struct dev_pm_ops xhci_plat_pm_ops = { .suspend = pm_sleep_ptr(xhci_plat_suspend), .resume = pm_sleep_ptr(xhci_plat_resume), - .freeze = pm_sleep_ptr(xhci_plat_suspend), - .thaw = pm_sleep_ptr(xhci_plat_resume), - .poweroff = pm_sleep_ptr(xhci_plat_suspend), + .freeze = pm_sleep_ptr(xhci_plat_freeze), + .thaw = pm_sleep_ptr(xhci_plat_thaw), + .poweroff = pm_sleep_ptr(xhci_plat_freeze), .restore = pm_sleep_ptr(xhci_plat_restore), SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, From patchwork Wed May 28 09:04:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 893100 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 9EE862750F3 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=1748423357; cv=none; b=PVUq+kXhwzAaIbtr9PVx98R10RLIyFMhQT9O1wJN+mc7hrbYqnim3CG8+8BvSz4hYNUpdAz/kRqs8EJbQ8kV6/aq/YLcu4mLF2GIkWoW8mDJf0qjxDPiNoVR6PslT5HWbdBsM5n2n+KOIuwYwGqSZz6JVlGukujmL0hzSV5D0j8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748423357; c=relaxed/simple; bh=QZ8nwHA2Zs5IEnJ/86ZrMAoj82ULzOVmYhVsq8xnvV0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PRL10cgywnDLbVZpKQVOqH2lDq4wvQE8C4kkf69Dqo/87nFLsB9u1+FrTLToQkJIMsfn2Kc0H+Z7KkUQrKKmkSjLAIFymIN5bnHQUCXM3xlXfQC+qPFZGwIfc6OcJ9pY4ufJukOs6OFZGy8gf7DCc0ESXtf/n9Yob1/3RZwrcq4= 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-742c03c0272so5447366b3a.1 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=o96hTPMJ2OXDA2cmRh9TaOamP0UuFbgH3dpwqViyVPzXA2qH6rDZyP5eRO/GcCIhH9 PcfM2/3lANGtBXgTBBWnCNhotPtT/+LDxoCOhD9hCCLIrnENYkDTql/i3GSgR9Dm2ZKL B16ykuv4vPvi2/2X1QaO1ThPWiFGPKMh09XSgYSKHZy4KiMtwTU/y+SQOgNn5aH4920N 7WcvB72Y5JEksjFnM6O7Sap+zGZPOWtOJG0p2hVGfHH9lpagZcs3uuPR3OrP/Lg98SFf l8DvYVScmR+siqBknWFxfKBStbWfCi3ZyE6WsDKCgPgdp8g64eQb3PYvVU0SWvWktH5V kw7Q== X-Gm-Message-State: AOJu0YxDnCOuCf52/YIS1m1mWMCSfQb6Cvu0Vaf1vxXaOuC1brvL270o ia2CHekv0VCunnjzXPIIdjZ9ruJgUNqz/+ZrFXupzdIrGy8hkbKBsdSVssH6pX9S8VEOVDl5g5N PO+mdEATvVSJGATDpNA== 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-usb@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 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) #endif /* CONFIG_PM */ +#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 handling 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 == USB_STATE_NOTATTACHED) { + ret = -ENODEV; + goto unlock_device; + } else if (udev->state == USB_STATE_SUSPENDED || + udev->offload_at_suspend) { + ret = -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 = 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 == USB_STATE_NOTATTACHED) { + ret = -ENODEV; + goto unlock_device; + } else if (udev->state == USB_STATE_SUSPENDED || + udev->offload_at_suspend) { + ret = -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 = 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. This + * information could be used for power management or other forms of resource + * 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 = 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 = { .name = "usb", .match = 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 *parent, set_dev_node(&dev->dev, dev_to_node(bus->sysdev)); dev->state = USB_STATE_ATTACHED; dev->lpm_disable_count = 1; + dev->offload_usage = 0; atomic_set(&dev->urbnum, 0); 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. +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 device. * @slot_id: Slot ID assigned by xHCI * @l1_params: best effor service latency for USB2 L1 LPM state, and L1 timeout. * @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated timeout. @@ -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; int slot_id; @@ -839,6 +843,20 @@ static inline void usb_mark_last_busy(struct usb_device *udev) { } #endif +#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. */ From patchwork Wed May 28 09:04:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 893313 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 5BCFD2750EC 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-7398d70abbfso6225098b3a.2 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=pCXl8FW4sz0ChuAiHDTO7v9m+BJ3nJ7Sqt3WaXOw6Ly7171r/oCQLI0FjKtKcsLkq4 Orod0vYdxt8elCLIKms2TlIGY4S3bPatVWfRKE5vE4NrFAbT0lVmBFCttLJ/0d3N+/uJ ObDJM3B8BMyoCAjIdP0WOrvFUrZVdgGNlBVoxHDqhprkvPwi5pBlQvw27/xyzRD1VAW4 6byDDYk/1v5+f754hF3lzfNltrjng+abaq2cjZUIYOqEP65Jym/gH2G7nCz1pMMEWjJD livZu4ZZitVX0xwFNFAxbpZiLkK5XBILx/FNJKLJvuxjJGTzw3x8TmxWCWJBIkec1g2z rcrA== X-Gm-Message-State: AOJu0Yy12hilwdYYYdDhWyU2MOg3XHaMwMfbLDl6rFX+vwKv2g+OkAAo 3JHWAKwD9GFE5SnKIWZ1hDZJCzsNlA9wwJC8GOVFBIOiSc+XX284HMf6SsPK/2aRxBEWIej2Sjl RT5DwgWI4gNkgwvE8cg== 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-usb@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 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-sideband.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 *sb) } EXPORT_SYMBOL_GPL(xhci_sideband_get_event_buffer); +#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 controller + * + * Allow other drivers, such as usb controller driver, to check if there are + * 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 = hcd->self.root_hub; + bool active; + + usb_lock_device(udev); + active = 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 sideband * @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 = 0; + struct usb_device *udev; if (!sb || !sb->xhci) return -ENODEV; @@ -304,6 +332,9 @@ xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, goto out; } + udev = sb->vdev->udev; + ret = usb_offload_get(udev); + sb->ir->ip_autoclear = ip_autoclear; 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; @@ -330,6 +363,11 @@ xhci_sideband_remove_interrupter(struct xhci_sideband *sb) xhci_remove_secondary_interrupter(xhci_to_hcd(sb->xhci), sb->ir); sb->ir = NULL; + udev = sb->vdev->udev; + + if (udev->state != 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-sideband.h index 45288c392f6e..5174cc5afc98 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -11,6 +11,7 @@ #include #include +#include #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ @@ -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); From patchwork Wed May 28 09:04:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 893099 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 61C2E274654 for ; Wed, 28 May 2025 09:09:27 +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=1748423369; cv=none; b=tXgv88Yu53Mfw+dIvxNiCFcFoKUYZhXmaqFStLtqfq97QmtwstqMuOFvX2cO6tuuT3Y9OjwW40JGxqTxXZVBp3MTxyvfiBISZDIrt3TVXHBj0U7VcUZ9eZg0pGp+z7ikRgcxOl1ZpIClsm5tibpgIik8YDylFR8JTQnLz71ie9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748423369; 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=IIj1BXbukSCGIEaJq5lzzvudlKREe2dtGq1HsdkxmWL16UY6LT7FEY8W6ObCFzU1oibYHWgM4Ve+VgPcGo521jyI8WbrazKwftaKV79Q6jxAwmSM3SVBCa3bfVn1PWN8N6Qehga7AgntO9Ru7dVNuUNYVk8Lv2Yn9YiCSoiydWw= 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.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="hMet6rKD" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b2c0cbf9fddso2779021a12.3 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=Nff0XVJDrlfBW1GNCONjuxxcH1en4CsxyweRPyKMwK/dANZFX1DxpQ6ivkwgoU4WnU EaVkR5nAJKGxlpKs0CImsPC2lekWSqaUjxRaQkowkljPAUpfGZA60vMySFqDuvAjSZx5 HDaegy41PWeRbpthrV8B6yIYojcN+eaB8F6AMl+g/NzRoflVbicRTXYtKQIID0si8ZpS juQIPFNfEnA3W9nPxZc9K7VnMpMkX36xy0nIpyRkkyDS1cdIFZrWyPOYidLJkJ2H6vpX +aV/JMGDyjSF3WGgbg+AXqsZwI7Qf06h8IMTpe/K10o+CalQPOloRuY3D2g54VRaFueQ ou6w== X-Gm-Message-State: AOJu0Yx/8ypO4F6zCE+Wc/FcGhkt7v5P/NH7rYk2ARXzT783R9IBPVtx 6l870YkOrm6iC3TxDLRVgdRJj/hrTjO2ITzqPhtUhpeF3o6NRru3LN1nfTC50w1rHgWbpAq0yLS nveONzYyJlWuVw1u4BA== 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-usb@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 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 == USB_STATE_SUSPENDED) goto done; + if (msg.event == PM_EVENT_SUSPEND && usb_offload_check(udev)) { + dev_dbg(&udev->dev, "device offloaded, skip suspend.\n"); + udev->offload_at_suspend = 1; + } + /* Suspend all the interfaces and then udev itself */ if (udev->actconfig) { n = udev->actconfig->desc.bNumInterfaces; for (i = n - 1; i >= 0; --i) { intf = 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 = usb_suspend_interface(udev, intf, msg); /* 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 == 0) { - status = usb_suspend_device(udev, msg); + if (!udev->offload_at_suspend) + status = usb_suspend_device(udev, msg); /* * 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 = 0; - for (i = 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 = 0; i < 16; ++i) { + usb_hcd_flush_endpoint(udev, udev->ep_out[i]); + usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + } } } @@ -1524,17 +1544,35 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg) udev->can_submit = 1; /* Resume the device */ - if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) - status = usb_resume_device(udev, msg); + if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) { + if (!udev->offload_at_suspend) + status = usb_resume_device(udev, msg); + else + dev_dbg(&udev->dev, + "device offloaded, skip resume.\n"); + } /* Resume the interfaces */ if (status == 0 && udev->actconfig) { for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { intf = 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 = 0; usb_mark_last_busy(udev); 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 #include "xhci.h" #include "xhci-plat.h" @@ -483,6 +484,15 @@ static int xhci_plat_suspend_common(struct device *dev) static int xhci_plat_suspend(struct device *dev) { + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); + + if (xhci_sideband_check(hcd)) { + priv->sideband_at_suspend = 1; + dev_dbg(dev, "sideband instance active, skip suspend.\n"); + return 0; + } + return xhci_plat_suspend_common(dev); } @@ -535,6 +545,15 @@ static int xhci_plat_resume_common(struct device *dev, bool power_lost) static int xhci_plat_resume(struct device *dev) { + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); + + if (priv->sideband_at_suspend) { + priv->sideband_at_suspend = 0; + dev_dbg(dev, "sideband instance active, skip resume.\n"); + return 0; + } + return xhci_plat_resume_common(dev, false); } 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 *);