From nobody Fri Dec 19 21:32:04 2025 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 4E9261D63F7 for ; Tue, 1 Apr 2025 06:30:16 +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=1743489018; cv=none; b=fitb71EN9kI8iV7K0/w/eTsKnR2+HSB0rv5mt8GSEv9mbGknsTz7f1baYvp4M0VI/3aCBw3kQ+YiRt+YAdobY03TM7/BswsBqmk6VqtBzAoBkydgEpZ5a/hESC9X8BK5gbC2gnDau4s3XKeAvyNiU0qjvmQrcTBvDeU+WY+dSw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743489018; c=relaxed/simple; bh=GC8luflfFudrWld/AM+Ewt6IdxJJ4dn/4qVZvzzuEV4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ota3ENYtBz4rgirW/SR1FHKHqBYfj5l+65isi22JLcQ1wanl6SzvTNkxtQzioK61m3fpmzo/N4EM1/wcF9gbZLJMDfs5Q/VhZJxjMormjeIiX3OvwNvRH+mwZwxJIGl6zx1AXgDS4FzucV9Av7jPQDunMc4j/Jvq/isybVL0GHc= 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=GjjG+jin; 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="GjjG+jin" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-227ed471999so84130655ad.3 for ; Mon, 31 Mar 2025 23:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743489015; x=1744093815; 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=G82tJsCWDISryXifn89lTAl+ld89TBbEQgTjv+aZOMU=; b=GjjG+jinxfMRctJUnlY1gN0XBeWH4LR2Cvvk6oBRE4CYO36dgXlbVrZqWXbwhrOXlX VeQSryjuIgLyFabAMKo6GVGfduXD1yOP338C4B2KMNPS4XEvp0cfzUdnFhxuv1fLfJcn Xflw1awjOUHzN4OQnLx9qo7yagta0KiFVAHoH0s5YDTYFYmlhTnVVDsSbU5OQkyuXi6S J5LxvhFiLDHHS0bdabyju8JgoFZ0W3eZMkUQ5is7RWTySTLBig8dqXc+byeoOe+YCM6H wQbSkEuRT5vDQt+SKlxGifVd9sZCtN1q+NzwHAND/q6kmQnz8PWlwv/UvuP9jD/OT//h 70Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743489015; x=1744093815; 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=G82tJsCWDISryXifn89lTAl+ld89TBbEQgTjv+aZOMU=; b=U2Ub8K5RZV7eOnWWOa9tL7r6xeOnTfed+246W3qAepUtt00+BgVIwTPbhua+6YcueN clBe2pDJRx5Z++58cSGnXoeyGVrDjoMEXjhqMfBZO7yW6BRbtKfYDk5a0+O24ThGiECI 8arIwlBpi+oxMLqI4lMaHHn7Z253/0PydcpLSC8rwhO9M08uyBsLb+DrcrNDQMEA8R5/ /uNafl6cvskuuJGyhoZGnIAkHzE4tYCOfPU5GQS27L83MKNO90OZZFcir+Di1C5Dt72X MUIuYNegvZ+DtE37J/l9/DijdW0hYA6fn4Dk1YkUzV9RwcN0fFoZNB2hqtEE0xHQKEij C+sg== X-Forwarded-Encrypted: i=1; AJvYcCW3zMMDpZltBbwUwblswqkzr3apBm8MVemlDmk7oOp/FJLD9Us7HVdoa/rzELCcsSlZpZoo+Lu6Yl96ltI=@vger.kernel.org X-Gm-Message-State: AOJu0YzhgBOEhRh5/V6CEPqbiF/RPQ9HlkAvSdvPquJTkfv6Gz5as5n6 VvCmEQVAU02KCV8zRaH3MiaOeM3JCHAxizpXQ/7WxE3aeFfV7XEGKcvRhVHIuuNV+z3rz6JM9RJ AY0TMHDHQH62VaQ== X-Google-Smtp-Source: AGHT+IGDn4p5Vlq4+h8UmJK0+M+KvQbP0/FDSg7s54pu1Ji+HBQ1kRiqrn+pptQTrbAOX27/AgCloGelERbtwkE= X-Received: from plbm1.prod.google.com ([2002:a17:902:d181:b0:223:2747:3d22]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e892:b0:220:fce7:d3a6 with SMTP id d9443c01a7336-2295be92d96mr24970385ad.23.1743489015611; Mon, 31 Mar 2025 23:30:15 -0700 (PDT) Date: Tue, 1 Apr 2025 06:22:39 +0000 In-Reply-To: <20250401062951.3180871-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: <20250401062951.3180871-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401062951.3180871-2-guanyulin@google.com> Subject: [PATCH v10 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, sumit.garg@kernel.org, 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.472.ge94155a9ec-goog From nobody Fri Dec 19 21:32:04 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 6F2E81D63F7 for ; Tue, 1 Apr 2025 06:30:24 +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=1743489026; cv=none; b=kg+edYVUgW6RXKN7Q3zd41W27bUZWEtZzcHSfl6bHVIpnT4m2N/7hc+cQBZgX0qsykH0aJp+4l0RP+9Ug+7il2bY2x8JkVqp6ZTRWcXLNl0QZieQTze6qpX4d3CBet2S3CxlNH+7/ApEf635vj59YZJJy1GZofL32Q8IlWWIKf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743489026; c=relaxed/simple; bh=5hdFmL1/8j9W1i3kFN4YbzKflh7LQHd2tn0lFrzBHvY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ABh91B4V1zksCO2UcHKqYBEV016eThoEWq0mO0MNcQ+BzDT53dgf2qyFTEzSji4Kbr5cT0hZLEQfda/HUC98UhMuI1jCqQdi8ID1jrsJuD9LNnAjhdZ91cd5c2Lueyvq4vK6hcAqNDEf+pPt4Olo4esh3/Q1i135MYaLrr4ijqQ= 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=vXMSfI3Z; 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="vXMSfI3Z" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-225429696a9so153653835ad.1 for ; Mon, 31 Mar 2025 23:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743489024; x=1744093824; 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=shtc6AwyPtBq3F/4afp3Rbwjl/RBBLfuWy8M0AyJIsI=; b=vXMSfI3Zr8pAnGexBfqDT3WgzdIM7xqC6p07wQnazQIVogoIywKTP3ciA4G1aEB6L9 AdNudlBTtzNpwdllZVYS4NQBGPHtQQFIsyevbzXPoD08YxGNdCAuBKyp2udyDHMf78Hq zu8zSfOzcpckW/vxu3Vw8f+8iY3pR4M8YHtpGw9SPJnpfMOsGkJfvFVybk/6n7SpwheS M0K//VkGmAS+V66u/o4A7b0KTtejMACXkcPMesE3oRKypARnKpxrH9qd1d8iN7Vl/Z7V 0nTIOIULCosYElBeUTOtKKjgMrsUjZLS9RtFqBzNYaq4348wieAT8qIis3l83rOZ36TT xhOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743489024; x=1744093824; 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=shtc6AwyPtBq3F/4afp3Rbwjl/RBBLfuWy8M0AyJIsI=; b=Mr8wb6VYhCcJVul49zzTaH+TEOZBG0p9UasdxfiO004z0Tz2liNOmbv2paBgm6s2jF v0CnC9N+j5CeAhlzWZUAFbsOe9XdPTRNcBiTRnSYJ2jvIhuoYb2/9ARW5z2S7j+EMLad 3eMvo2CR4ieMaQZWpFo/vNHVBs5bN7znlkGK0Zkj2YEh2AF+HhcHm2DmiovwxBvD27A2 Hn5bDRzg/PP5+OxnZj8HsFcVdpt1RZNnS04YMhA5yBLsZP2q2TWoIvVNQZCALHkWSN22 +8AHf5WwVibCe7++RRqB9wWHrbsvGzRyh3LTcLLCUOk+6tYA2K72f5yu0JqsC68/A/cI dlmg== X-Forwarded-Encrypted: i=1; AJvYcCXIvvGing0MTxMDwC2icTL+HXulbVg7BHBnXtOdCQwVVYsWXnORBkbSyyCswwZ/4aNAzbY2AiU6VetBy2A=@vger.kernel.org X-Gm-Message-State: AOJu0YyZTd2sSySOyU7UYRvDxMiju0lzAO0JwafVDCP7tkbIHab6+FGE zCeZqYwvpUGGNBnE6i/2DHflgXS8+fQMz3fzFZ26qK0joRNM6mz3Y+vtiRV0dqfadGlmknC3q/V HZHsZH1NiBx23vw== X-Google-Smtp-Source: AGHT+IGcgZP316ToZ6krrKxx/ciI2kwrOMpIi/D+Dv/ZNnJAaMCHXUEldZscoIBJ06qbnxpc2R0mw6b56uMLyQQ= X-Received: from pjbpq11.prod.google.com ([2002:a17:90b:3d8b:b0:2fa:1803:2f9f]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ea0a:b0:21f:617a:f1b2 with SMTP id d9443c01a7336-2292f9f981amr192115765ad.46.1743489023775; Mon, 31 Mar 2025 23:30:23 -0700 (PDT) Date: Tue, 1 Apr 2025 06:22:40 +0000 In-Reply-To: <20250401062951.3180871-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: <20250401062951.3180871-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401062951.3180871-3-guanyulin@google.com> Subject: [PATCH v10 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, sumit.garg@kernel.org, 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..2ba033bf7e4e 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 pm_runtime_resume_and_get(&udev->dev); + + if (ret < 0) + return ret; + + refcount_inc(&udev->offload_usage); + pm_runtime_put_sync(&udev->dev); + + 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 pm_runtime_resume_and_get(&udev->dev); + + 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); + pm_runtime_put_sync(&udev->dev); + + 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.472.ge94155a9ec-goog From nobody Fri Dec 19 21:32:04 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 CEAE51E5B88 for ; Tue, 1 Apr 2025 06:30:29 +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=1743489031; cv=none; b=Lo6grVvVRZlP1RID6lU2ONI3W5sK5boSN1QhMmXcCcikQSpUPfkI+OCIL+bd+q8955EcU375b1WqDH1l8JF8y+whssYAT4ABr3ZN94I58Dm1+1k6veRRJDq9YV16RhHY7r/LsG+Z0y3HSpcn5EgUb2Vx4h4rzqmDVGVxrGQltEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743489031; c=relaxed/simple; bh=F/qmGUFeMu9XvOZI7bo6qPejjKCgMa/4Q+1+JmF0sio=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UfzUIA2htvl6+S7QB2/E2am4Kh8v91hqJLci3FhsHdf8jcrILmWiVWB1sQF0HVOy+Q9ulTCbQ/fznlfZx9FE8QQDQ6IKpMGjHY6PPmVtTZkOpL9RaIhJvSALhW6Amqb6y0pgOWxzqOPNb42uEb6w98J4EBlq3d5S9LMfyDvXQSk= 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=PL61WlRr; 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="PL61WlRr" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2241ae15dcbso123747175ad.0 for ; Mon, 31 Mar 2025 23:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743489029; x=1744093829; 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=e/hhe8fHtkZGRjGoinV849CiQfAtFCFjSq4JrlJQc5o=; b=PL61WlRrBZ83k5vthPHOnDy5CRxNcTHEc83Z+zb/sYjaLZDwaKC/JI0MQNNow2tyui uYcAL6q96NOM+8wvzxcxq8OoTcLP6S93Kd2XyHiTw4YNmTD6hL+nphYZGmL2zv5vX6tq IXYilGI0To2P1gAavP+Lb2PfbZtMx8IXgxVmbQxUFiiseQXHinThxFSfaO876aRXwoLA hrs0p3baHpWpmrIcWG1KDhvX4F2KVjqRHB+MDw2/CfMa/Od/lVa1wdOGXlNFG80JD0Wt Ondy9h6iK/qe3ajS0xnWcqHZqulzUmAC8GFETEdwKV8EQ4AGXHHDxS0H52XZrflnaJMO YESw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743489029; x=1744093829; 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=e/hhe8fHtkZGRjGoinV849CiQfAtFCFjSq4JrlJQc5o=; b=JfQ3RyjPrdjLEXK7wX30RGl3hU4T07FJT/FupsKoZak/marnvzin46NQF2g8SoGEb2 ix3clo/JP05+0UcOTk7Fl/UW7cFhB7497UiZwSzRx2LjVJ9lY6LkALE6lilYiQsXU6mS 1TWn0v8dkbr+tStrGUoWkwWYuV49FHSjPCoASTW7xeYx+pj4I9vzveNe12swSQtBV+w5 al26PQ5MfOIfrjuC9c9DNMyoJcdPJQsy7JH55cJGKgx5vdYZ3fCoiXe+XMqFtds8Tp5R ejJGkXyP7xvmm9Mo1o1lqDTo+Y+hTcThvSadv1vac8aYpT/R5Z/XvwTqJrEiNFasFp/g tu4w== X-Forwarded-Encrypted: i=1; AJvYcCXG69izqp8hZxchF0JOasDJ1ejVtvrWwJulitxe822jAh+xDxEzNyIxVaBg34lEc/tzY3DW7aiWs7yr4Ek=@vger.kernel.org X-Gm-Message-State: AOJu0YxaB0YOEzzHtOxi+tOWVUgyNsMs9PTIpJARuDlmc5jpxA9pY6gW 0EweE3rXJQ2tluwRYa2W8LzSH1BnkaVuKOvFp5AKVxGAHyWcjiVy9zjjFMh1RQTW2KDyp4vVGnQ rLGG/rBK+od/Wxw== X-Google-Smtp-Source: AGHT+IH3sCEbiKXIhGq2v8KwoCB9c5CbhGko+7CXLOcauVYSMPBKmJVj1my29zrE/bSpoaO8NACdEeVe5spWsCE= X-Received: from plbjj22.prod.google.com ([2002:a17:903:496:b0:225:8a27:cd41]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1cb:b0:223:f928:4553 with SMTP id d9443c01a7336-2292f9f7646mr224444685ad.44.1743489029111; Mon, 31 Mar 2025 23:30:29 -0700 (PDT) Date: Tue, 1 Apr 2025 06:22:41 +0000 In-Reply-To: <20250401062951.3180871-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: <20250401062951.3180871-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401062951.3180871-4-guanyulin@google.com> Subject: [PATCH v10 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, sumit.garg@kernel.org, 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.472.ge94155a9ec-goog From nobody Fri Dec 19 21:32:04 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AAC619D8AC for ; Tue, 1 Apr 2025 06:30:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743489038; cv=none; b=iSuTvuAh0cK6LHb5vc5eqzftyUXi/1m1TkgWuqZhJioFP/zXzjjcIQG4TK3eV1T8GFLnQISTFJ2dnB5CUb9HXrY9ilXzoL73XdeOna03v9Gej53NMLP5JHJE4EMwKfr89OHic1cEb7aYzw1nU4UH2ZN6fdxluZqSx/lAvC4+9dI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743489038; c=relaxed/simple; bh=J/M6ym/3HaB2IbGY1t1wGYKVKwUFdldUw+cz1/kEueA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CiguxD9kafk01pAxNjJmoC+5gDv2pWEvZEeiZit6Sitkln2FBR0hwGjdeF4y9fH85HBz0hdJsv1p/hmfiwsQ5rxEno+CxIr6qXtqvwJXqxU9IGcuXcJn3id5xd/Th+8TlKtZvYkExT00A8dNyvlRl2cf3QweyOtlN9c4Y07xRnM= 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=ZsQMq8Yw; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZsQMq8Yw" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff8119b436so9510721a91.0 for ; Mon, 31 Mar 2025 23:30:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743489036; x=1744093836; 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=jiFiSExmIpswe63JqhLJ7F3T/vXcNa8/l4kRqI6BHnI=; b=ZsQMq8YwldqdPww2aNNCtLvgl8PDT8tmJiIUQ1Y+v5kcO5/3+yiDquHKfU9TvvSrIS 9o+MpZnuwTdxFExXq4WShoHwDscjDk+56zIorLOk4BAgedSwI/tgBgcif/j838Wij1Fb kHXKjkoPnsLLc50iQ+3dHPdbuN0NI1riP4wKYltSI1eDh3cZbXwmefwu0boPugjN8eNI t+7bRq5wrVYlBe3sobaRgbWy0zFEgsxDRnXXzXvoHwptMQnbJxlES8r9DNpAUJHUGzRz 93NuCAz6qkf0lPlJ6DebT0ribC8VkiFRFfdvFt3A8Tv6cPCE5GmTLy78pH0u5gK0LERD Z1+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743489036; x=1744093836; 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=jiFiSExmIpswe63JqhLJ7F3T/vXcNa8/l4kRqI6BHnI=; b=NcNS6ATfTE6QOTmFxVv2joBW/nLmQEWp5Upz3brofiqoAkWYVzafUeeE/O9zeuaIcO C/wphG9/wbL6cXFRFxVG3l4m4meeuoxBgnEDb7cgxG/00lhuMJg7y+wfnIE1JzT9tZYY xjMZSfMTnXDvN85pBaZqhuTMP2XAsHvwtHOitcSBQE+e4HZoJ7hechKKT6qkp6Xid2dZ q/8P5ZEE/fqeOJ7B/yVAj16nGt2ElWBdKdS9N8pDz60oiunNQdOutbRp+qHWITuiHiAm wDPLLQfu6icWH9aHiwYsryBn0qPDiAup+71EAor2UWKf+JT3f1ykxBCRxLwB34BluJ7h DOVw== X-Forwarded-Encrypted: i=1; AJvYcCVsH/6BvOeDka7DWWrlxIXw0v4XmxXtDa1Re1GMLTPd+o907OCBV2+k0o2REMPEKUbAVQK6N97oLUO/DsE=@vger.kernel.org X-Gm-Message-State: AOJu0Yzv7fXJbIbGoAkYh+h9PX+Gi4XOSAqhIATrfzezOmLCQSxnjLqr TgpD9gjurVi/pTTeaOAHgEBsdwZznZbO9azfnvCDNe9tpYEryFJPiWolk1hO3a5Jabi0/ZEPT0R hpQzITpmwBQo4lw== X-Google-Smtp-Source: AGHT+IGxI/ecbNMCBfYfN5C+BPG5kYRSq6a1FOzanRyj9Idz2E8lANjOYdUW6OJTmUG8JPe4h77qtxE+xQa7zhg= X-Received: from pgbg26.prod.google.com ([2002:a63:521a:0:b0:aee:900e:e3d6]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3953:b0:1f6:6539:e026 with SMTP id adf61e73a8af0-2009f5fe141mr16978771637.15.1743489035752; Mon, 31 Mar 2025 23:30:35 -0700 (PDT) Date: Tue, 1 Apr 2025 06:22:42 +0000 In-Reply-To: <20250401062951.3180871-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: <20250401062951.3180871-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401062951.3180871-5-guanyulin@google.com> Subject: [PATCH v10 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, sumit.garg@kernel.org, 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 | 33 +++++++++++++++++++++++++++------ drivers/usb/host/xhci-plat.c | 19 +++++++++++++++++++ drivers/usb/host/xhci-plat.h | 1 + include/linux/usb.h | 2 ++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 2ba033bf7e4e..678106e1c520 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1420,11 +1420,20 @@ 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]; + 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 +1444,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 +1490,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 +1536,26 @@ 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]; + if (udev->offload_at_suspend) { + 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.472.ge94155a9ec-goog