From nobody Fri Dec 19 15:57:38 2025 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 3D9C21A9B5D for ; Tue, 8 Apr 2025 03:58:55 +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=1744084737; cv=none; b=Vd0MzIofHueQDzjhDpTVqJqtQoQF4mlKxY7ommIILXy1JlpHb0AZ3piu81xuIpatxjELfk6zlqcs9Zf/YDgFedu/51i3HgRpYIvBFvNGwWKW6UgBGfJREF2WD0nFx0z+zG25p8Yxy9wEkhxFZAcRtEzBV/kxq337U0p3goWuTV8= 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.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="q6Lik4L8" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7377139d8b1so3692163b3a.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=IIIVzKETSM40pOsiL9KqWiy3T3aEzXSic7wGxYser0K12Voz5qqAz4e8FFzSgMlJuX XpJodrllQSPo4akQt8kQIxqx/TuDRl/9sycRWf7k3v3kMj1HNcQf9ncWrZBE8PjSEx1X pR1QosLFhaSIwe2XSbbAfF65VU1z4rNmtdQNBEMv6YH7A92Yl+07PV1prt/waU6Co69L 1K7oVp9MCgaV4z7+60loqTmYTDPaK/7fnkmtr0XyskXuQyt4VJsoUSM3G6YraSQR1oDV Q2GbHfNNebbo9yHtDo+Jt3c23p3wFbi0Vf+ujbL2R8ifp2SJ5KLtabx7gwdDGThk5OPy MNSQ== X-Forwarded-Encrypted: i=1; AJvYcCUTxC/B07EFUCjnycjNg8Z8ZNI8X7zVSsTnmjhigony2q724F69Wkg4DSsebpl4pazeZhFUS1NcWY7Hz6g=@vger.kernel.org X-Gm-Message-State: AOJu0YwJzSc89Ef2+S2mB1ti7Zoha61V+IwWvAhh9vl4BaHNkE6wwWCE LAAIUN5LIKty7hRZZiH5zBDmQ8R6DsK4duqQw0Afk0rfyuCDAOVJP6wXWoKPoavz4tftAFd0Njx gXFHQB/tmQmYd4w== 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-kernel@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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Separate dev_pm_ops for different power events such as suspend, thaw, and hibernation. This is crucial when xhci-plat driver needs to adapt its behavior based on different power state changes. Signed-off-by: Guan-Yu Lin --- drivers/usb/host/xhci-plat.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 6dab142e7278..9843d3ad5cf4 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -453,7 +453,7 @@ void xhci_plat_remove(struct platform_device *dev) } EXPORT_SYMBOL_GPL(xhci_plat_remove); =20 -static int xhci_plat_suspend(struct device *dev) +static int xhci_plat_suspend_common(struct device *dev) { struct usb_hcd *hcd =3D dev_get_drvdata(dev); struct xhci_hcd *xhci =3D hcd_to_xhci(hcd); @@ -481,6 +481,16 @@ static int xhci_plat_suspend(struct device *dev) return 0; } =20 +static int xhci_plat_suspend(struct device *dev) +{ + return xhci_plat_suspend_common(dev); +} + +static int xhci_plat_freeze(struct device *dev) +{ + return xhci_plat_suspend_common(dev); +} + static int xhci_plat_resume_common(struct device *dev, bool power_lost) { struct usb_hcd *hcd =3D dev_get_drvdata(dev); @@ -528,6 +538,11 @@ static int xhci_plat_resume(struct device *dev) return xhci_plat_resume_common(dev, false); } =20 +static int xhci_plat_thaw(struct device *dev) +{ + return xhci_plat_resume_common(dev, false); +} + static int xhci_plat_restore(struct device *dev) { return xhci_plat_resume_common(dev, true); @@ -557,9 +572,9 @@ static int __maybe_unused xhci_plat_runtime_resume(stru= ct device *dev) const struct dev_pm_ops xhci_plat_pm_ops =3D { .suspend =3D pm_sleep_ptr(xhci_plat_suspend), .resume =3D pm_sleep_ptr(xhci_plat_resume), - .freeze =3D pm_sleep_ptr(xhci_plat_suspend), - .thaw =3D pm_sleep_ptr(xhci_plat_resume), - .poweroff =3D pm_sleep_ptr(xhci_plat_suspend), + .freeze =3D pm_sleep_ptr(xhci_plat_freeze), + .thaw =3D pm_sleep_ptr(xhci_plat_thaw), + .poweroff =3D pm_sleep_ptr(xhci_plat_freeze), .restore =3D pm_sleep_ptr(xhci_plat_restore), =20 SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Dec 19 15:57:38 2025 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 758E925F975 for ; Tue, 8 Apr 2025 03:59:04 +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=1744084746; cv=none; b=slklhwGRN/NF7wWBcwacYJW398oLd5SMi884UU3DekKmoTPOR/ZRqHPKQa+OT1fVHE2GwiPt8IxQx+ljn/usN7+Gk46PQrRZ7Uro3R9Mxl82YWGoRxECz7pvbzlReHL3JqwGi+ZJzw+F9OVry/5lpfZw2fyS9CTlBRpbLkAp//8= 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=ndg/Y+65; 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="ndg/Y+65" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-73009f59215so6056410b3a.1 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=1744084743; x=1744689543; 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=ndg/Y+655A373DlehK3SyiDB6YyDYyjhyqhmcLgqyIiSSzEdaWHjQrz4gKZ8GWq+pt B/j9YmZ2696M5maXEChD641ahXGeZkjLtKY+5HX2B/cmSki6N3Ku/lmEgoiddevZ0Li3 7pS4lfrJwzwKEP9FSzDhqpw64lb/F45X2Jb3KuP222jZ1JCETBWt4yc+H2TAht7Kco1F vy14JuMoXB26IYKCd1TwGSHk3++MkGTSsiDyBAz/L/LN9ysQ2qeYMqI0QJKqDOaOet+c YYqA3/S+foQHWKhrw5/QpD3jdb+fGHkpAkOQX1Dp4bCMMr/8Dvuqg14KyaQjnZYpjrAE tQxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744084743; x=1744689543; 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=V3yIHto4NSNYVeMGu6gRQc5krz8xYmNCRP8lQvfYhuMi1Hq7NOrccqlepgrvUTtGlx RPJ5OCfw9bskkgHPx04i4quGSouxu2kHA2P4ntIkqLXnUTyphQ1c2m+SBZU6MBNRkwXc fg5aCwuHBuNK0v7dLpUccZZrRhw52PHP+M1JHpghOjIQ+mLV0BIWgx4FZOyi9G01LrIY hAxRShiNrJVv9yezMtdzpOAnnY66eg1VXwUxgIe+MXQBnDq9Uq+WF5uaEQvBCLwYLejX NAQgxfWR606W+T6gaKmOCC8PLrIaTvhA7X2BOvKtm/VCZdtP3ZcMKrEgC3Mz9U84GsW+ 8pPQ== X-Forwarded-Encrypted: i=1; AJvYcCWNj2gZnEywRWTWexYixoXuzsEp0FO16AVIPrtnE6s+bjcf2BR3F/cJqArLNAKvH21afoPjQrm/HUmOrzM=@vger.kernel.org X-Gm-Message-State: AOJu0Yxeu6tgjBwdAVR+9+ImqxUQGeDM+qGj5XMPp0xOHbSlzq6TycMo JejrV63jjswD+ClPjlT6lZEbekpTuFIoODMuEnGC+9cSjDnVZxUkEkuzcyxocWYBUgq5HSC7ZW3 K/YKReDABgoFoRg== 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-kernel@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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce offload_usage and corresponding apis to track offload usage on each USB device. Offload denotes that there is another co-processor accessing the USB device via the same USB host controller. To optimize power usage, it's essential to monitor whether the USB device is actively used by other co-processor. This information is vital when determining if a USB device can be safely suspended during system power state transitions. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 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) =20 #endif /* CONFIG_PM */ =20 +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) + +/** + * usb_offload_get - increment the offload_usage of a USB device + * @udev: the USB device to increment its offload_usage + * + * Incrementing the offload_usage of a usb_device indicates that offload is + * enabled on this usb_device; that is, another entity is actively handlin= g USB + * transfers. This information allows the USB driver to adjust its power + * management policy based on offload activity. + * + * 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 =3D=3D USB_STATE_NOTATTACHED || + udev->state =3D=3D 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 =3D 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 =3D=3D USB_STATE_NOTATTACHED || + udev->state =3D=3D 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 =3D usb_autoresume_device(udev); + + if (ret < 0) + return ret; + + /* Drop the count when it wasn't 0, ignore the operation otherwise. */ + ret =3D 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. Th= is + * information could be used for power management or other forms of resour= ce + * 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 =3D 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 =3D { .name =3D "usb", .match =3D 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 *par= ent, dev->state =3D USB_STATE_ATTACHED; dev->lpm_disable_count =3D 1; atomic_set(&dev->urbnum, 0); + refcount_set(&dev->offload_usage, 0); =20 INIT_LIST_HEAD(&dev->ep0.urb_list); dev->ep0.desc.bLength =3D 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. =20 +config USB_XHCI_SIDEBAND_SUSPEND + bool "xHCI support for sideband during system suspend" + depends on USB_XHCI_SIDEBAND + depends on USB_XHCI_PLATFORM + depends on SUSPEND + help + Say 'Y' to enable the support for the xHCI sideband capability + after system suspended. In addition to USB_XHCI_SIDEBAND, this + config allows endpoints and interrupters associated with the + sideband function when system is suspended. + config USB_XHCI_TEGRA tristate "xHCI support for NVIDIA Tegra SoCs" depends on PHY_TEGRA_XUSB diff --git a/include/linux/usb.h b/include/linux/usb.h index 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 drive= r. + * @offload_usage: number of offload activities happening on this usb devi= ce. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use @@ -733,6 +734,8 @@ struct usb_device { =20 u16 hub_delay; unsigned use_generic_driver:1; + + refcount_t offload_usage; }; =20 #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_devic= e *udev) { } #endif =20 +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) +int usb_offload_get(struct usb_device *udev); +int usb_offload_put(struct usb_device *udev); +bool usb_offload_check(struct usb_device *udev); +#else + +static inline int usb_offload_get(struct usb_device *udev) +{ return 0; } +static inline int usb_offload_put(struct usb_device *udev) +{ return 0; } +static inline bool usb_offload_check(struct usb_device *udev) +{ return false; } +#endif + extern int usb_disable_lpm(struct usb_device *udev); extern void usb_enable_lpm(struct usb_device *udev); /* Same as above, but these functions lock/unlock the bandwidth_mutex. */ --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Dec 19 15:57:38 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 BC19B25F96C 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-2240a96112fso77164545ad.2 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=icZXB8UqxWiL+Jj//YTZ6Nk3JlUHgt1d5q17qqZn8pa9yZyFNiKuwoPhO2DDOUj5zO kWMa9vqvKFR6VMXBJZWkuUiGFMu2IPnO+eToO7tyCsAd7wMUk1zxoSoHLc8NXJSb+y0d Zybcc+vCh4rXM0wOkgmtwqHSTOhJ3MpD1V+S3mouxeUJ3y5vHLUOTrpn1gtaGyotHiwj YORrut8w0jmW0ooCROxGx7AvFgaSyFKKZrrlz8ID3uJmy6I2XmdSrH9BE3kFTqJ2rnX5 1JqAeBqmbqxyzItxxWa/VeO/BN43FGU+vfVas2SzVSrCcdx1YkG0MCu/n/zoEc7aWQ9J CWhg== X-Forwarded-Encrypted: i=1; AJvYcCW4x6IHzvv1EPuWHpDg7k7UMc74BIXSaLucyB/j4TMb/OpZmAnCeeEOoW0jXIvPY3geZkITq5zjAY9oQPc=@vger.kernel.org X-Gm-Message-State: AOJu0YzpzpsmUosTEGDZyJszjLh5vWjBMhxInQjb46NLyJkDdpREeg01 HVagdEirjiPYbVsVqyVA5Qyqx4fo0cewUSAqaX5qPY7rXFdo563N559KhRGvl7tQ8VrR2mxD1xT /D9sn4phGfCXx/w== 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-kernel@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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The existing sideband driver only registers sidebands without tracking their active usage. To address this, sideband will now record its active usage when it creates/removes interrupters. In addition, a new api is introduced to provide a means for other dirvers to fetch sideband activity information on a USB host controller. Signed-off-by: Guan-Yu Lin --- drivers/usb/host/xhci-sideband.c | 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-sideb= and.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 *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. + * + * 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; + + device_lock(&udev->dev); + active =3D 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 s= ideband * @sb: sideband instance for this usb device @@ -286,6 +311,7 @@ xhci_sideband_create_interrupter(struct xhci_sideband *= sb, int num_seg, bool ip_autoclear, u32 imod_interval, int intr_num) { int ret =3D 0; + struct usb_device *udev; =20 if (!sb || !sb->xhci) return -ENODEV; @@ -304,6 +330,11 @@ xhci_sideband_create_interrupter(struct xhci_sideband = *sb, int num_seg, goto out; } =20 + udev =3D sb->vdev->udev; + device_lock(&udev->dev); + ret =3D usb_offload_get(udev); + device_unlock(&udev->dev); + 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,16 @@ 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=3D 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-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.504.g3bcea36a83-goog From nobody Fri Dec 19 15:57:38 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4293325F79F 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=1744084761; cv=none; b=jup5FH/7rmnIuhiW7OCvMt11zkZ4CZwSeEdDTMxJ/1aFvdjcLSfrlgY+JomOQG/MOfS5JML+wyd9EPi5CZC4KSnjewIEFaFU2f+C2brUAD9tdaWjeffeyvl0xTv0KYVf7nhaBI7fycvsFNQjmAM10HGzES6aWBD216cniBwdrQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744084761; c=relaxed/simple; bh=N8IOtk+KCPgxRChOUScSPuKKtNbqdNsY+7biU5NAWu4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jhaM/JbuIJUXWn794ciHZl5ZtJIs+NvrN0izOlHT9mfz31H7Kt+gCJWhiVhMSMT48geGjcAtTACjDhbM9U11k1WRuTRjvFnnU9ezlcLzLfOMXL9blCkHAVUQaKkhGeg2hpmKKccxQ9pNUTc1+HVabwJofVqqp/FCc6XLDKmtEAA= 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=na+nb6SM; 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="na+nb6SM" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-6c8f99fef10so5728461a12.3 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=1744084759; x=1744689559; 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=na+nb6SM0/ELWpUfjfd9txm89NircMZKoA+XG5isy8CY4Dxs9HrLI9fiBYTbMR9PGO 36skXpVG1eRrpcjnkePBi+rhSmHJLiiX0bHeAA63t3AeQX4j/cSpXcjjEa/+oWGiV/PS 9q0NHCMCYnGcHucVgObwrV2nAXyT+s+MhPUMSbo/Zrdc63qOix/db9j+9YBep5UqRAAc Tg7OTLcdAqE4k6vz5AV0EOMYucwK3FAU7uoqCUD5q0bIM9CBMdCHx04nz+nWR7UvaErB FdWmpvXID/jQ2qVSFjMcrK2m8WL2vRAHb8R/ysyqfjcarrWVpnka/DKXNu48Bx9CPiSE fG4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744084759; x=1744689559; 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=dHiqlmRAL3Bxo+NWjBoImfSakQcer/vplcrT6GJx68jFTNtmnA3W29+OvogFxLZPPi 6YApngCB7UN8Y50WvhW7zugBfUllOFQgYOXY2fZPw8JTgkejHf1Fb05SZ3IwbhmLqe+T PJGEi/qwW8+YCYzFQ/oTb/8qg1qD/C2gBEqRWxicemM0oRQ8rC+hrOeaFyZo+emQBDim jqacTt2ou9E1MdOue1z1I4gWa26K2VDYMxLRthApTKDRLDSk+2xglbCNOdqBJK5sX5Dc EOvnsJzUqXe56SbLGesgfzzC2GLoSWh7VNaeMvS8vPvfPBj19wFZhEyUruopsu/O2I+8 GZaw== X-Forwarded-Encrypted: i=1; AJvYcCW48TW6rdk3M0n9jLL3mi46Iog8zqc4U+I6HiylJQ8mmWLX4MzVWY2WHLvSk9YWNKJkGNGsz7pt3fP4XSQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx68TU3zK5lX9lTQQv5vsDJbGKDYK8jvaJX//jrb1UEsecwTpAN YoQr71K5S79cWDmUbdZrIH9dIzCqOvLm9eQ726z4zE/B/XwgwM2Qj+hSWzHcRmp6ovfnJgWGg1Y GuLtFENdXl1S/8A== 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-kernel@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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sharing a USB controller with another entity via xhci-sideband driver creates power management complexities. To prevent the USB controller from being inadvertently deactivated while in use by the other entity, a usage-count based mechanism is implemented. This allows the system to manage power effectively, ensuring the controller remains available whenever needed. In order to maintain full functionality of an offloaded USB devices, several changes are made within the suspend flow of such devices: - skip usb_suspend_device() so that the port/hub are still active for USB transfers via offloaded path. - not suspending the endpoints which are used by USB interfaces marked with needs_remote_wakeup. Namely, skip usb_suspend_interface() and usb_hcd_flush_endpoint() on associated USB interfaces. This reserves a pending interrupt urb during system suspend for handling the interrupt transfer, which is necessary since remote wakeup doesn't apply in the offloaded USB devices when controller is still active. - not flushing the endpoints of actively offloaded USB devices. Given that the USB devices is used by another entity, unilaterally flush the endpoint might lead to unexpected behavior on another entity. - not suspending the xhci controller. This is done by skipping the suspend/resume callbacks in the xhci platform driver. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 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 =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 offload active, 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, "active interface on offloaded devices\n"); + continue; + } status =3D usb_suspend_interface(udev, intf, msg); =20 /* 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 =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 +1495,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 +1541,31 @@ 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 offload active, 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, "active interface on offloaded devices\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..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 drive= r. * @offload_usage: number of offload activities happening on this usb devi= ce. + * @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; =20 refcount_t offload_usage; + unsigned offload_at_suspend:1; }; =20 #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, = dev) --=20 2.49.0.504.g3bcea36a83-goog