From patchwork Tue Apr 8 03:57:21 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: 880575 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 541AA21421A for ; Tue, 8 Apr 2025 03:58:55 +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=1744084737; cv=none; b=jitWJG1bTBCt6skTRpYndj8j9pqIf2gFU9+nZR2d57lkjDkDs/TSDSzNSrKEWt9rDbZavm7GJOQdqMWJcoW8GpDKU4gRuuiYpWuSG8bnle7a4YlB6ZS5Ew7GuvMnkV4uPhC97VAgJLO3BtFy9H3ltuEARD+1+rBtEdhggTx1cI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744084737; c=relaxed/simple; bh=bc9X/p13qI/cu7A28+rZtnN5F0QHAdqaRJS2ANaTxSo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Qhi/FvELJc0JjFoTu8qPkOAfxBO56ynf1ZYNgstGf+lfMVGvPvohXS/EUP7PL7s0XhhlzDubty1FYXlBRXbY6AAs8ODyNR0gJ16dp2foRflVKTVTA4CGgiyXcoOdgUdI7dG/OQLCzOGRFcCK/6arCIYQk3NZY++WmY8vFILwqZc= 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=q6Lik4L8; 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="q6Lik4L8" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7377139d8b1so3692161b3a.0 for ; Mon, 07 Apr 2025 20:58:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744084735; x=1744689535; 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=wLvCKTSXk2lVXCQdG+iI6ItCMd6CTfWDVCsxzhUvfs0=; b=q6Lik4L8V0jZpkh6kQv/+qZ0HhPSDtcVXA6CWSSm7X5xix+sY4CSHVfqHkJoKFNfTp SIGU/XMRv45K/AgwjTPyzHKaeWc2VxM2ul+Udj/CE+UhQoPME5jFTATrGHkBllOBCiO2 GY06Y6zdCxHUmTTv7jv2D5wj9HLSXJYj0MJiLeyqpGgtqpf5Gj4oTgB3qIiJxY/R8aPu gBtrj1JkCd7E2xxEjnr+qb9zdQYSY/StM7mWd77xInbkz/Wwz4jlhPAOTu0HU0tRZcgS ZxrGInxhuYVieJ76x//vOUTtCFnNCXnsgdapn2XxFJhGxDT4fcc8RrmJik5rn50lngVc Simg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744084735; x=1744689535; 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=wLvCKTSXk2lVXCQdG+iI6ItCMd6CTfWDVCsxzhUvfs0=; b=DhSN3ViHyF4DD0wdfVM7enW1FakH2fTRHlolMdxNVKA1sKvKHdTdvH5plgJydBI1Sw sNrUqHl8jMMqYy9Kb6Z5j5apFgccMkxSvGU21ICGdtlh9DV50o3hBD5hl0/l0g9jo7YW 9pqHt6+r4i0B6v1/qEfMY/kjvI/o+FbCxJAhHiw8xje/+W8Hw4KIqlKjjwPF0/s6Ce7A BGa/lJyeYWFg+zWbReX1tp9ER0lrUg+T3WiveuPyFJrXdTFmIaiMIZu1/f5OePVbiu/8 tmijrGgOLTR7lXmbSazwKYVqkUGK30ljL6zVnvB6drugX7NpySmFrs85MxDm0HlSgPlF 32lA== X-Gm-Message-State: AOJu0Yz8wahAaRib4NeyEFzVR0PHKimWGC3NAWpSYZ6l7TQH3t6reeJF cXvu98TKmCwA34zTspv98AZ9EyLjHSO5sIslI5iX1C/Efk7wMS6o/WnGunSva+ayW0JzFyXqEfr ls6HTL+qyOs31vw== X-Google-Smtp-Source: AGHT+IHtjkaCNKIXog8qjPTh5DJlz+7q6dPhwrkdBsvaX6WQmzp25JZs3q6u6Lj7sZiM+2iVmIdtFNadooCrMJw= X-Received: from pgaa38.prod.google.com ([2002:a63:1a26:0:b0:af2:3c1d:c04a]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c887:b0:1f5:57d0:7014 with SMTP id adf61e73a8af0-2010801c97fmr20370794637.25.1744084735440; Mon, 07 Apr 2025 20:58:55 -0700 (PDT) Date: Tue, 8 Apr 2025 03:57:21 +0000 In-Reply-To: <20250408035833.844821-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: <20250408035833.844821-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250408035833.844821-2-guanyulin@google.com> Subject: [PATCH v11 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, stern@rowland.harvard.edu, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, elder@kernel.org, quic_zijuhu@quicinc.com, ben@decadent.org.uk 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 Tue Apr 8 03:57:22 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: 879311 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 7588125F973 for ; Tue, 8 Apr 2025 03:59:04 +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=1744084746; cv=none; b=SoRxjsY+BRNXxJXnQY28EFyZ51Er99WY/wAP5EhfXG1FNLp+tCtAlH6QrBt+onJ1CryjZkPn78BhnNNB4HIOC5Vw3ATcpLtc0zD9eb9d9ovdETjGrP+ZhKyK3MLyCjMli7jq89jqpgV7+m8qe8cbljE/BIxcagUBC38fL6JJN2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744084746; c=relaxed/simple; bh=RibN4QgqE5xMPr1ZKGpoGt2oAOe0z8rhNV3swHrAWD4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T5uKUqNsp5qdjk1D/uu+K34yqxjpf6MhSDnfjCwIv9f4pxl7YrTY+Tk2ddRHCDLogLE6FlzAf2deboIJODFq5pdXtU4pNuPxBf89bYbJKfYTvPX40Z32RKXUnnwAfE25mDFCGbdYTDjKKseTq7xYA3MHG8Lj3iUjNtAL7YtS8RY= 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=qsTZQ504; 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="qsTZQ504" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-73720b253fcso3993570b3a.2 for ; Mon, 07 Apr 2025 20:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744084744; x=1744689544; 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=OO5iv9e72a70N1g2aLkVy/GCvTS8/7rBW6udCvn3pog=; b=qsTZQ504xsAxqhU+IiArvhYAXeqZUd5+u67jt+HzjG8gWx4jOTStROzvauh18Haxgv x57GbptkH1O6rifOBWjjgpBnbN8R28xfrMKgxUo5mvqTGnvWt6+u2jfdsHSqs1KxeySF m4BtiTyvoZf0YqdlGCutqCHn5UgE1ECGrhib2dF2Rl7MbkOWyZh1J8/BEQlsPcmTkx8G yudNAJClg5O2IQhNqvuEffHfpXeVLK6z/5qrNmQRO2xuWtA3mQC01/NMZ5wGDMQPh+lJ U/nrWElNri9GKVLOPNtTbSeWo1kLz1Whlnvugnu0vPc6hL/3qFmUtFYuAFZ9iyq5ijJq WAcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744084744; x=1744689544; 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=OO5iv9e72a70N1g2aLkVy/GCvTS8/7rBW6udCvn3pog=; b=JW/0OEJKqX2VKf+t/Mul2a2zvw0YFA2NLzu4mUcPPB/vwrBJKRdn2lnqif91JagUGY +PgfovT5Pb6t6EpKFm88xlSDKp444rPhkyoetWzGRgTrV6QrTiaf6O+W5+ygaygsAhnV mHPmMGpKo11z+BN+OH9z/5KF+0yk4XR3I/wFAyOHOXk9vhw1eGXCQ2SqDVFTVqHjV8Id BkTqrfOC/MYKgVrsrQAez3wr69f6J4qbc7pz7wX8dQ0Z9TmE+2cMrlUI7qjFC1dg0CVc COe63/qZJileeYHFlDBNKL1JFabdAuTV90nmrDTIPfVOvZdzrFXgimXwUqHw8xwzMIzv Q6XQ== X-Gm-Message-State: AOJu0YysGKyR2PBdH+XUQmRN0dIa2lDNnKLtv+BhqMcqy4/uDepEZ4pU 6kQbj2y+G43Ra8sgZPsIuSzOVhV7kSe0xmnzJMvoUH3JvPFvFt5c4joQoent5MlrGmoj4xgkfG0 4LQ+XRJEWShlC+Q== X-Google-Smtp-Source: AGHT+IGUPMma6QbD+bHi6ubi7iRVOcAyPx/zMonP4drQkTzULbSKaVeWg3usn+yY4sbZsviN5z3GuhS6W1ei9zc= X-Received: from pgbgb3.prod.google.com ([2002:a05:6a02:4b43:b0:af9:1196:c39c]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c887:b0:1fd:f48b:f397 with SMTP id adf61e73a8af0-201080117demr23193480637.23.1744084743655; Mon, 07 Apr 2025 20:59:03 -0700 (PDT) Date: Tue, 8 Apr 2025 03:57:22 +0000 In-Reply-To: <20250408035833.844821-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: <20250408035833.844821-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250408035833.844821-3-guanyulin@google.com> Subject: [PATCH v11 2/4] usb: add apis for offload usage tracking From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, elder@kernel.org, quic_zijuhu@quicinc.com, ben@decadent.org.uk 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 | 108 ++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 1 + drivers/usb/host/Kconfig | 11 ++++ include/linux/usb.h | 17 ++++++ 4 files changed, 137 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 460d4dde5994..316526a05250 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -2036,6 +2036,114 @@ 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. + * + * The caller must hold @udev's device lock. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_offload_get(struct usb_device *udev) +{ + int ret; + + if (udev->state == USB_STATE_NOTATTACHED || + udev->state == USB_STATE_SUSPENDED) + return -EAGAIN; + + /* + * 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) + return ret; + + refcount_inc(&udev->offload_usage); + usb_autosuspend_device(udev); + + return 0; +} +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. + * + * The caller must hold @udev's device lock. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_offload_put(struct usb_device *udev) +{ + int ret; + + if (udev->state == USB_STATE_NOTATTACHED || + udev->state == USB_STATE_SUSPENDED) + return -EAGAIN; + + /* + * 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) + return ret; + + /* Drop the count when it wasn't 0, ignore the operation otherwise. */ + ret = refcount_add_not_zero(-1, &udev->offload_usage); + usb_autosuspend_device(udev); + + return 0; +} +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. + * + * 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) { + device_lock(&child->dev); + active = usb_offload_check(child); + device_unlock(&child->dev); + if (active) + return true; + } + + return !!refcount_read(&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 0b4685aad2d5..765987813630 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -671,6 +671,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, dev->state = USB_STATE_ATTACHED; dev->lpm_disable_count = 1; atomic_set(&dev->urbnum, 0); + refcount_set(&dev->offload_usage, 0); INIT_LIST_HEAD(&dev->ep0.urb_list); dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 033a9a4b51fe..b564f46f1c87 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 b46738701f8d..f3a4064c729c 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -647,6 +647,7 @@ struct usb3_lpm_parameters { * parent->hub_delay + wHubDelay + tTPTransmissionDelay (40ns) * Will be used as wValue for SetIsochDelay requests. * @use_generic_driver: ask driver core to reprobe using the generic driver. + * @offload_usage: number of offload activities happening on this usb device. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use @@ -733,6 +734,8 @@ struct usb_device { u16 hub_delay; unsigned use_generic_driver:1; + + refcount_t offload_usage; }; #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, dev) @@ -839,6 +842,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 Tue Apr 8 03:57:23 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: 880574 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 BC13025F969 for ; Tue, 8 Apr 2025 03:59:12 +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=1744084754; cv=none; b=Va4oiRhewxiWvZ4qOYiKzWbuGMNOpPLFVvy/5E/e3q4CSg0XNXwOfUXAYvFrht+9MpjGdFO1wbGlVj/NGPecKfFebBIauDnX4zYTeZjQTreMCJZj4kM2yBXnTM2w52Qaohm82s/aVgC2FSj78W+arnUUKZ2JmFW4KK5BpuK8aL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744084754; c=relaxed/simple; bh=/wmwzEeZuyPe4wA2TVYRVkkTxWQx1D+8tMoAscunngA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pj4phv/QH7q671zMNx+6yvnH0kCFhhkUwxMs0Fy53VglAI3GLnPW8VpmQaa5bcITtU+hMVo0Js0j4y50cIKPlfJxuV07csmJZn6a76AbZzkxny0gbgkWmq6+ZNLgbWd9VAfh7RfSMdPAwnhO8Q67wYX//XvzvsxPIvR5MAKXmPc= 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=aVpXUwiQ; 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="aVpXUwiQ" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-225429696a9so73315555ad.1 for ; Mon, 07 Apr 2025 20:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744084752; x=1744689552; 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=0tVzRCkzl6BKtBB0KhFs5d331UTfXX8A8KLdCOv4By0=; b=aVpXUwiQ792ThSF9NKIHXs95d1vJpdzdE3uQuiIFpN+RHGZQqNDG839ClV5kRwSyw5 zWhBgNY0EDavd4/dbDTyN6bkWbTecQ/leJQxultyDyjajJUnh5dPZAC/hCwUQw0yIHOP ak+5vVwNfJ7oGfwCk4Uai5InULffUsHsXn8HyGErK9cA8gIm7S7jqwqQJSK3GAe3b2zA 1FkaGhEQdNeV3bpltBN8/MtuM8wOlnengaNVKUBXXKUYXsXsQ6XZNFZ0PBx0wrQ5REzM J+Dudq9XhgKde/0cEBwmovVjOIFqiLwG+NxV9cg/cQrgZSwuYbTAO8t6rANhiWoqu97i DQug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744084752; x=1744689552; 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=0tVzRCkzl6BKtBB0KhFs5d331UTfXX8A8KLdCOv4By0=; b=QPPotsnuupjTFFRVN8mOO92B7ZAVCgYgmSfrtUEe+SY6AH9TI1hIrwIAR1oeqwhwfg FjgjKcFoiWNkalrjFmiUWSiq0s9Z8BBCTbsVVhnx0O5X2ZYXpBsS1I4fadBPyCishFMD 169HQo3JpjClh4rPq6tqr0g4TQSva51UNRmNs1nRbx5rmDZREPEO7JINSakcQIqf0qMr CqHbLpAS0Yl32MTVq1Bk0z22X1gVYTlblKjDOLDVXJKLGTiCao+fl+9GCqMXkmU0VjH0 TCqSZcnuE0RN6lEFeFvxtd+2MRjYprp6gHip++yOVRty+pXSoDNU/IC9G8ntJbiC6NiV fGWw== X-Gm-Message-State: AOJu0YyRbAb0zpsVJiYhMDz8yYtM7SdKe+8AYEDgp3I8Cw7jKb86Du/F Z88Ix9h3RVMLX8ry5C2mK1sBYeKnXshrt0bx7USwnwGUusTCyUAUZ//ZER3wZg2Aet7Zxausofw Ph7nLTAtILqHeTg== X-Google-Smtp-Source: AGHT+IH1fBzgv/Nf+REbL9Jf7WRAwyoUupvMjS7dwTTYCPMY9IV2BeRaIZrKEOX8zQS0505iQZfF+B5H7ASuAPg= X-Received: from plpj21.prod.google.com ([2002:a17:903:3d95:b0:226:342c:5750]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d4c2:b0:21f:74ec:1ff0 with SMTP id d9443c01a7336-22a8a0a3892mr158530955ad.32.1744084751912; Mon, 07 Apr 2025 20:59:11 -0700 (PDT) Date: Tue, 8 Apr 2025 03:57:23 +0000 In-Reply-To: <20250408035833.844821-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: <20250408035833.844821-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250408035833.844821-4-guanyulin@google.com> Subject: [PATCH v11 3/4] xhci: sideband: add api to trace sideband usage From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, elder@kernel.org, quic_zijuhu@quicinc.com, ben@decadent.org.uk 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 | 43 +++++++++++++++++++++++++++++++ include/linux/usb/xhci-sideband.h | 9 +++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideband.c index d49f9886dd84..67f31b0ec726 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -266,6 +266,31 @@ xhci_sideband_get_event_buffer(struct xhci_sideband *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. + * + * 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; + + device_lock(&udev->dev); + active = usb_offload_check(udev); + device_unlock(&udev->dev); + + 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 +311,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 +330,11 @@ xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, goto out; } + udev = sb->vdev->udev; + device_lock(&udev->dev); + ret = usb_offload_get(udev); + device_unlock(&udev->dev); + 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,16 @@ 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); + } else { + device_lock(&udev->dev); + usb_offload_put(udev); + device_unlock(&udev->dev); + } + 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 Tue Apr 8 03:57:24 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: 879310 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 0377D25F963 for ; Tue, 8 Apr 2025 03:59:20 +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=1744084762; cv=none; b=k67ParChgjCMUfMvGgDbj9x7kDftm+gbvsJtAxa3k3U1RYDZq5hhGn7eP2YTgLFA0STuGnOXTBqAt451wQvsvCj1tZ9+NB/4cdkL2/lz1KQizo+UhJA3WitmxMwucNoEsRJOW2IXLf34I9Pu/mXi5LAZIto+sRxuLRDjHVHp8y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744084762; c=relaxed/simple; bh=N8IOtk+KCPgxRChOUScSPuKKtNbqdNsY+7biU5NAWu4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XR9LQTIQTm/bxOBb7G5mkxc40rNOHcltfbjHfL5dS6WYC+rr1uXSuaNo/t7kYOQmJTEGPXo0BtKswt9u/E/FSdm7ylA8ke/p6rnbf7bex84xioV3n5RRxcqW9oXekafTUgfIfHMgvGv0RASHuC0srMDOpONc0kZdv75h+91CKxA= 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=u8qylPtw; 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="u8qylPtw" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af8c34d03a1so5137488a12.0 for ; Mon, 07 Apr 2025 20:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744084760; x=1744689560; 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=Nq70c9PTBvJCLyTf24I/PKmrwX82PnQf7xrAJUmbXKs=; b=u8qylPtwTNFvNmEPMA05alrHgA2UdI3f+Khxn4Wx1OhS2581ZyLD96UyAHLWkS+bCi 0ZrOxkw6gU1w2MrayotPUL5sUH71IqihS4BHBTUl7bw3tLMWqIK/scO54TiHAsPWnGw9 SGosH/DigU/7WnsdDE+fjwfOHDA7o8n8NprvUPQd/AzxqgDsuHxKuElSB5DH9abxTqaB EVrX9+gm6w6cyPIeGWw1xC+9P/5mZxmXu1gq0vSObq05vhWeQE4h4DpgDAuhQ3BqrAK9 jt/88ulgVAiNTat7jXeYAiSy4VMuRiVMQRzSn/NAiNNWfANVU8ymPJ99lAHcyQcgpNVB SuPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744084760; x=1744689560; 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=Nq70c9PTBvJCLyTf24I/PKmrwX82PnQf7xrAJUmbXKs=; b=Q6d5syL7cz6WYhpHUZwchS8ZVjkArQ4cU+gEOsaznwCt+19ayzwDNie7oVNf68ZlDq 8Mf54xAhNz2cKof+JiV/N+E2awgb8V8ooK8+G8JYu9d9L/86O0kOwWLmhTo4Rb5PkACH phN79TU5PtaGs7t00tRzyTRMcs7BKfOlvQMLHCo6boFf6O3kmKSsatENbLRO3Fq7oDDC jmAUbrEI2Wrehl8akvpVpfLjhOZttOzF4692ie1OPT75EFL11OH8HjT6aXnKktHa5CEd ZvRNQJtd0N0f7DGEU6B2iumGH6V96TXkUj2Sv3J1J+qMJ2iSzrSfsajpDyTV2p5u0UzF BYvg== X-Gm-Message-State: AOJu0Yw/y871A8/j4KLviquZjMFGLLNh4wKVNEM5yh3dL9aTYRuWaW4f oi+aQWs3t85BabaiRC+qlVurAYfW//7GNIcEUPoQwsYLU1VqrSjnIGAWV3/dGstu6fOFBuowRPj tz7Vb+mZ58Ra83w== X-Google-Smtp-Source: AGHT+IHmogGzsX9mjrOUn8Ny9K7H71dH/B3u0x+6YXO76QczAeRH2Kkvav8Kmqt4tB1Azg8tSHIMnIZYgppN084= X-Received: from pgjc18.prod.google.com ([2002:a63:d152:0:b0:af3:27c:5603]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2592:b0:1f5:8678:183d with SMTP id adf61e73a8af0-2010460355fmr27010355637.14.1744084759643; Mon, 07 Apr 2025 20:59:19 -0700 (PDT) Date: Tue, 8 Apr 2025 03:57:24 +0000 In-Reply-To: <20250408035833.844821-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: <20250408035833.844821-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250408035833.844821-5-guanyulin@google.com> Subject: [PATCH v11 4/4] usb: host: enable USB offload during system sleep From: Guan-Yu Lin To: gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, elder@kernel.org, quic_zijuhu@quicinc.com, ben@decadent.org.uk 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 | 43 +++++++++++++++++++++++++++++++----- drivers/usb/host/xhci-plat.c | 19 ++++++++++++++++ drivers/usb/host/xhci-plat.h | 1 + include/linux/usb.h | 2 ++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 316526a05250..59b33e5e9a87 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1420,11 +1420,25 @@ 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 offload active, 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, "active interface on offloaded devices\n"); + continue; + } status = usb_suspend_interface(udev, intf, msg); /* Ignore errors during system sleep transitions */ @@ -1435,7 +1449,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 +1495,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 +1541,31 @@ 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 offload active, 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, "active interface on offloaded devices\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..cd07b22adc60 100644 --- a/drivers/usb/host/xhci-plat.h +++ b/drivers/usb/host/xhci-plat.h @@ -15,6 +15,7 @@ struct usb_hcd; struct xhci_plat_priv { const char *firmware_name; unsigned long long quirks; + unsigned sideband_at_suspend:1; bool power_lost; void (*plat_start)(struct usb_hcd *); int (*init_quirk)(struct usb_hcd *); diff --git a/include/linux/usb.h b/include/linux/usb.h index f3a4064c729c..bc3a84870907 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -648,6 +648,7 @@ struct usb3_lpm_parameters { * Will be used as wValue for SetIsochDelay requests. * @use_generic_driver: ask driver core to reprobe using the generic driver. * @offload_usage: number of offload activities happening on this usb device. + * @offload_at_suspend: offload activities during suspend is enabled. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use @@ -736,6 +737,7 @@ struct usb_device { unsigned use_generic_driver:1; refcount_t offload_usage; + unsigned offload_at_suspend:1; }; #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, dev)