From patchwork Wed Apr 16 14:43:01 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: 881823 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 08A631DED4C for ; Wed, 16 Apr 2025 14:49:44 +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=1744814986; cv=none; b=Yk5bsAgfY9hkVTatkmGWRKF0QtmPqbh2QZmyEwqeLI5vhup+x8MS4HJYdFBex3Ccg6Mi5zwk7xVOPhPUIooulyjCYJirWd5KX45/uLpXFMjw/vKXbKj9Kh+68qQn8HUJlxzZZTwp2Hd/vT4Z8RGC6hKhlkMhB4BrFnx/dXuJtoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744814986; c=relaxed/simple; bh=RmGXQWPOg0XHqbMDxkz8sqI1j76AnzNSSdYGP4N3py0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NlqpRjgza8z5F1c7uTM82aLpZz3VAhm/eOu3vjB1mhOXXVfiu5iWejeXn/R95oAgDB06PizeIBT6pzh/qEhXuyEOiOSDR24mAF6vNM3u1U+qTpLkmjfvK8osugu6uUCDFRI3vLAhuapDsSGlOLqd3Mqn5SMuLe9VKfPazP5CMwE= 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=05N7C1IQ; 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="05N7C1IQ" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-736bf7eb149so4965727b3a.0 for ; Wed, 16 Apr 2025 07:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744814984; x=1745419784; 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=z4QsznB5oM+PFUpeHGZHhA5kq133G5m+shQoot4idWM=; b=05N7C1IQkolKD8jCAGUtZLBEnVR4fUb+kMLhP1N/XeU1pDwZqvbT3V0e6Cix8PpGgI Ub9GPunm9ZAHmBAgWzZRQnIOTfnovu/SvO45g5UQJQQE/QAxSi9j6x9jRPQ7aVLEbGtv UkglsdcVY2HxOsPK6yQfaH349+nMFABox9HoGtYEbe8TDaIZvNsga7TzDTrwLtqsr5wi bNSnxSyKVRj9nUt4k3KvWdiJWa7TbwaKRlpsgWvJZda+HRassRHNJPV5gn24W8cHotqw GUTtxJ+zRmcmcvQT9BZf0sGJeLzY+8uRRlhvsAbLjPhpPZCsJ56bdV0XoZ+b0Acfjky3 iIog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744814984; x=1745419784; 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=z4QsznB5oM+PFUpeHGZHhA5kq133G5m+shQoot4idWM=; b=XF6coO1F+J0cg8AL8WGfcHFsq5N9auo6HoMwPRPjhRX/Y9lmjAP8yXgl6vd/W9J/Zn mg5CLytbJ6BkIufBLw/HNTmEOQtHzwe7Qd5b1CXjZF8iOUHIhqBPSh+82C1xWsPyGlkB YBJHSnJiTVUou55ZZw7JHJGEXO+G5K7Kz83pnXEgiBg6unu55s8ij0uWe5i4cjdT/YVQ 91YqCsd1hzWmQYigcUOFRW1lNciLKwVkPokyBC3lDKcmkxEJimUBS0IwfV2+bg+A2WGK CiiVau6HTUEKZuYTomGIxLwd4P3mZL7Js6gK+rXzctMn85SYJmFYIrQCWVD6Oh8cYjWg ihHA== X-Gm-Message-State: AOJu0YwFWMZuYDcaGbulRw/lUpov8PyIRPcOq0P1PExcHXeYkYjZh7Ly +q6NZ1kTUEXBYnnCHrBzwTzMWankSUVVAZZtJlaZ8SnNXEQBuploe/n2Glr/GHZ4L27CIPJWgbZ EOdBSGXMuYBfnpQ== X-Google-Smtp-Source: AGHT+IGjRPun4sEvM5OJ4M+Aysj70s9KHd7i9GdPhgft76VLdq628NC5EbLSluIzNS/rZGqQ/GdQ8mrvox1selc= X-Received: from pghl16.prod.google.com ([2002:a63:f310:0:b0:af2:681:e27a]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6d8c:b0:1fe:6bbf:af22 with SMTP id adf61e73a8af0-203b3e6aff2mr3084464637.1.1744814984013; Wed, 16 Apr 2025 07:49:44 -0700 (PDT) Date: Wed, 16 Apr 2025 14:43:01 +0000 In-Reply-To: <20250416144917.16822-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: <20250416144917.16822-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250416144917.16822-2-guanyulin@google.com> Subject: [PATCH v12 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, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Guan-Yu Lin Separate dev_pm_ops for different power events such as suspend, thaw, and hibernation. This is crucial when xhci-plat driver needs to adapt its behavior based on different power state changes. Signed-off-by: Guan-Yu Lin --- drivers/usb/host/xhci-plat.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 6dab142e7278..9843d3ad5cf4 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -453,7 +453,7 @@ void xhci_plat_remove(struct platform_device *dev) } EXPORT_SYMBOL_GPL(xhci_plat_remove); -static int xhci_plat_suspend(struct device *dev) +static int xhci_plat_suspend_common(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct xhci_hcd *xhci = hcd_to_xhci(hcd); @@ -481,6 +481,16 @@ static int xhci_plat_suspend(struct device *dev) return 0; } +static int xhci_plat_suspend(struct device *dev) +{ + return xhci_plat_suspend_common(dev); +} + +static int xhci_plat_freeze(struct device *dev) +{ + return xhci_plat_suspend_common(dev); +} + static int xhci_plat_resume_common(struct device *dev, bool power_lost) { struct usb_hcd *hcd = dev_get_drvdata(dev); @@ -528,6 +538,11 @@ static int xhci_plat_resume(struct device *dev) return xhci_plat_resume_common(dev, false); } +static int xhci_plat_thaw(struct device *dev) +{ + return xhci_plat_resume_common(dev, false); +} + static int xhci_plat_restore(struct device *dev) { return xhci_plat_resume_common(dev, true); @@ -557,9 +572,9 @@ static int __maybe_unused xhci_plat_runtime_resume(struct device *dev) const struct dev_pm_ops xhci_plat_pm_ops = { .suspend = pm_sleep_ptr(xhci_plat_suspend), .resume = pm_sleep_ptr(xhci_plat_resume), - .freeze = pm_sleep_ptr(xhci_plat_suspend), - .thaw = pm_sleep_ptr(xhci_plat_resume), - .poweroff = pm_sleep_ptr(xhci_plat_suspend), + .freeze = pm_sleep_ptr(xhci_plat_freeze), + .thaw = pm_sleep_ptr(xhci_plat_thaw), + .poweroff = pm_sleep_ptr(xhci_plat_freeze), .restore = pm_sleep_ptr(xhci_plat_restore), SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, From patchwork Wed Apr 16 14:43:02 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: 882248 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 B45161F875C for ; Wed, 16 Apr 2025 14:49:50 +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=1744814992; cv=none; b=fnF5F+gVOHa1aPardyh366S3nMOxuI1lq1kPf8xTNJATkIytAWHCdqfM7xvZFtG8ki/QM+swi4EoLW4H3evrg2I3qn7tVmfcWtFIT2NwEvCQj+v2jbvRLv4A4zEcCZuydIIWYZ+xQRAW+czIekLDFEfdfAAmVSfiPW5VDNErSSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744814992; c=relaxed/simple; bh=BF+JAj2OOaQYBf1pV/aU5GDWs5SSoNcddA0RfvFTnYo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dGoI1P0SBmAS3EhQv9fZMkH5NaZUFXpJG92b8X7dOCqtWzcMpgr7bxS/b3JscAqiwT+J2NBvz8A+Cto3ZDCd64ZrHprHLlDZZcydVIRb6dwl+BwtT9nvYzAVWgccxbqGbH9y8LX7B4HiBvIB80Rv7MI9HUApqXcf51nSgwuiwws= 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=uAVtuNV9; 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="uAVtuNV9" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af91804dd0bso4229117a12.2 for ; Wed, 16 Apr 2025 07:49:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744814990; x=1745419790; 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=jpoAHz8CQifRQNDsLq9w1aYT2twGEmc33VKgu5HbVd4=; b=uAVtuNV90u42vXQatI0OcZSAgqes+VqY3kTKs0rsIPOGNfgVEkUC2JJTCY63wNpvxR 6QbalZUGoQwLDhDzWflN45t8WWwie2BRi8O4ueyjUsSya9e9Wysz2xGeHlPs2sMNYoK+ L28PD54C17IbfF5N2KhRejE00iJ0ZTUaxI6OrXhsdbI/BlmhKp3S0r/t7Tj256UXKL6/ LJg93UMCpLjM89HYSzSn40Xm+jEW+b2DdOhDfuBnCdEj4B98n53vDlBkvG/iXeKOS6xm V6FRfcKhNLkx2zjOgMBth1RoYYQ/tr3c+p8Ye+EpNy8zsI31ZD2D5ZeBfRDsB1sgI00t JKpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744814990; x=1745419790; 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=jpoAHz8CQifRQNDsLq9w1aYT2twGEmc33VKgu5HbVd4=; b=t3sxZaaOqbw/3nRjKBW9bI7YYyg7O/DIMYUO9lnggXROFKSvPPce80revt8noX2ScM avDunh33y9lExMWa1Uv1oUxLPASc7cvIv6wr4KjFULQjUaniNt+yQbT3+r+iXgcVEW+q s7EpkESHFdsUQPxwv5A2xND97Vn0m8YQBTQy9Ywj2EW69l33Br4ieiEfslcYGTxFGgSe V/z4qNeRgaFVIqWAVzC7n0MVsMhGm61QkqpXsDp3Y6ipCrE/VqU6qrNAhyh9nSxL/8Nq hSqYlnFfbV35lpOy5Jp0Kk+uxUNog/6iNWRTD4F2VMqnAsRFEjlOEaefpa1qpOVsE2CM Impw== X-Gm-Message-State: AOJu0YwAfAaZBga1HWEV9deQ+II5+lVALAB6FH8hAOXKDuZZD9fytmuJ Zqu3M4tupQGo6eW+Cm5sNOtvhQ5dPL91H+ZkKTmVuWd2Xs6DIXcDuoMJeb0eoSpWaDOgK4tTX/e WELRKv8yajmifVg== X-Google-Smtp-Source: AGHT+IHWFuvR6Ztz9iFG7HJ6rrbohaJudddMdBJrQPKvVdlWZLt0+eDvsLNfkM/8AlAMBx6OIgZF13ireeqRb9o= X-Received: from plgw17.prod.google.com ([2002:a17:902:e891:b0:227:967c:4f38]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ef03:b0:223:3bf6:7e6a with SMTP id d9443c01a7336-22c358d9a54mr43379605ad.12.1744814989997; Wed, 16 Apr 2025 07:49:49 -0700 (PDT) Date: Wed, 16 Apr 2025 14:43:02 +0000 In-Reply-To: <20250416144917.16822-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: <20250416144917.16822-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250416144917.16822-3-guanyulin@google.com> Subject: [PATCH v12 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, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com 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 | 109 ++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 1 + drivers/usb/host/Kconfig | 11 ++++ include/linux/usb.h | 17 ++++++ 4 files changed, 138 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 460d4dde5994..76372690add0 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -2036,6 +2036,115 @@ 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; + + 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. */ + if (udev->offload_usage) + 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 !!udev->offload_usage; +} +EXPORT_SYMBOL_GPL(usb_offload_check); + +#endif /* IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND_SUSPEND) */ + const struct bus_type usb_bus_type = { .name = "usb", .match = usb_device_match, diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 118fa4c93a79..43efd9d939c0 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -670,6 +670,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, set_dev_node(&dev->dev, dev_to_node(bus->sysdev)); dev->state = USB_STATE_ATTACHED; dev->lpm_disable_count = 1; + dev->offload_usage = 0; atomic_set(&dev->urbnum, 0); INIT_LIST_HEAD(&dev->ep0.urb_list); diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig index 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 1b2545b4363b..ec8d839e1e2b 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; + + int 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 Wed Apr 16 14:43:03 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: 881822 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 B86501FDA8C for ; Wed, 16 Apr 2025 14:49:55 +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=1744814997; cv=none; b=ZqIlaf28JvFo3JcxyYmPz5yVmVYhjD+fumI9E9lDHr9b+zvVSSfLv6+WBkXh8q9DB4gX+TuCVUnFlWhEXAwS9XjkHYMvei9eDeHo7riMxKbDC1muVkjtvmiQSk3ZsmEZm3EAMSUsnDR18JuJIocnbZfjfVO4rg9mOIZtaYHbtFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744814997; c=relaxed/simple; bh=T2vPsaEuwx8PfRvxsYfCewBk5NKPJPyBtTxI/ez7vEw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nRAIkHq/mvSwlOnoWJbP4kpai5JAycyNg/1xnuhX+W1oq3zKwmbfN9eQAJOJwljYTQzwiMcNKwDuMs6yxI4285iuec7clUWS2VvRuyxO/J5hk10tZxnGRF0HAxQmSaPTfvO3+ojcWcduTHgetlMGPjehZB4mFunnNo8JECJAHq8= 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=BzLzS4At; 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="BzLzS4At" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-306b590faaeso5595380a91.3 for ; Wed, 16 Apr 2025 07:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744814995; x=1745419795; 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=65zsaMyb5cxxAQpoirenuK9YWVfgo8pyw/N+IrnZdgQ=; b=BzLzS4AtaGPLDByfbKeP/tKel1qZXM1Vyl9xFzwEqe46ihj7P7hV+Y+x0iIYy0LyXX poadQvvKg/FUFLQNMsj8C9jx09jn0atgDHUmklFKrWqxNmxDlVjlQeGzPUgwdCnT9Xg1 GAowvtUhazqB7/rEGmTtXtaO9tfXZ5KNV8SnRvmKgGQlQOrNPBAZ9USqwAshOZyV8lym YU+kTOgXJGIBve88rhPblitTWDdV6TEtr312eXIs/PUEYeAOelaoFJO+Acjr7wCle9xZ 6cNA4XNORyzCshgLoQXzpOuGzZMFYUrOIeAyxXvJaCbpBLL6EYaqFz5HBjMlVps48d4w AM9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744814995; x=1745419795; 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=65zsaMyb5cxxAQpoirenuK9YWVfgo8pyw/N+IrnZdgQ=; b=sgxAivFGue+Q9D2wQDhD2H7R+y+DGDZYvkuWAIH5WPK7mCunVFdLgqNoeJEC8CpSs0 CnxQtQ4ijnnSnUS4FwiY9ZIqvBPBPkJ+3EjdklFxqzFft5+SvtAcV+BtSofkVb7l6LFx QHQWvkiOSJF97D6QWJSZ2tnRAp95qaXJkt1or0pJZmok8CBdgytDIuDtsuWqiFnwbN82 nojvcgaOE3EiJccwwSBmlkAx5PgiJQMSmklFDB7MJ+xYgfV/77UD46ljjiVEWNNkjXNI 170hJptU7EEht84Q9c1IFtpS73teGmSa/UkoWfICIS6Mng24xYQN5BmDAXAZixq6J4r0 9NFw== X-Gm-Message-State: AOJu0YxWVp+elXSgcB2h6eh+VdXCuDOWo9LnntQpGXL9UUP2AibTHXJ3 9v0m6Jxcaue8Cl5QWC9+sm0wWHLejx9SZ99w3eBSB7jxLTFN6rC7Nxm7qBpDo2rF3S21Kls+jqr utz12kscbEm7k4A== X-Google-Smtp-Source: AGHT+IFkW15HV2K1v8lyXTXQkds0p5oOqdfhXN2k3Gs1ekSwRfK5md5o0PcHVRQg9zRBPcSgZDyaajTrWZEtTu8= X-Received: from pjbqc16.prod.google.com ([2002:a17:90b:2890:b0:2ff:8471:8e53]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:570f:b0:2ea:3f34:f18f with SMTP id 98e67ed59e1d1-30863f2fb9dmr3051598a91.19.1744814994992; Wed, 16 Apr 2025 07:49:54 -0700 (PDT) Date: Wed, 16 Apr 2025 14:43:03 +0000 In-Reply-To: <20250416144917.16822-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: <20250416144917.16822-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250416144917.16822-4-guanyulin@google.com> Subject: [PATCH v12 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, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com 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 Wed Apr 16 14:43:04 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: 882247 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 2F4241F8ACA for ; Wed, 16 Apr 2025 14:50:00 +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=1744815002; cv=none; b=Y+ZHWCpMatZypIN/23MxMB1GyMneC+oChJyVBHOXPYmXYxje5zZbYtTiVM7x/t1GQQFSMfeOxhjhdzjvadj3yWX2yU+UWY1xhWudWB7zv7wp2tYUJsRZfITAu59iOGWatrZKCJKUx0WOYKo0SPa6tt+8TWdwcHGb3I3H8s9foLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744815002; c=relaxed/simple; bh=vamw0maEHaBukVhssMS+S6Gwg15K722frOBUN1+Eaec=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uvVXeISwPslAoMJCSfsuWZMJG9/T3Jporjw4humGld+kA6yOogxNQ3yGPZ5EI2q7/r2++aoMbieFbJmgn8HVc6VuFYkHz0km+9o8LRmcIBiG6mQmdMZgdg6BH17Ct5Jf64B9VhH45TsXWra1/tBSIdOLFHTH9BiRfk1Cy8jArpg= 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=ubkYjl5e; 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="ubkYjl5e" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-736fff82264so721878b3a.1 for ; Wed, 16 Apr 2025 07:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744815000; x=1745419800; 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=7zUjS2x82QyAbbEFyP3zEMnOERceY+liurHl5RmB4q8=; b=ubkYjl5edCinKiSiDEnXN6QiG+Yed71AtQM9UQ7dsL8HN0BVwDTLe5ZjFkrTC4kOkK gD4VJjJfFxH0ymSUyxBTY+rybGRIeo/k7yfE8KX2OZfhlHNBH9QpsJQdAe5G1KsbL/Mi 3yxpDfyWVWq/iYmwyZLdlaZHqej8mBho8NROfWX5jj61o6D3+Hqgxo3n6EOlxzGHyLgc LWBiYe+wbJjjQV71NlfJ2eX6I+GqGyKPCPYm6vIBmyHztuFrnrozHcaV4LRrM/ey5jPn z111ymyLwG/XOYvJpPCReNKYClk/QXIAHloCEE15z0S5vSaE9D1rkVJtsS7fLkmQbmUY kagA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744815000; x=1745419800; 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=7zUjS2x82QyAbbEFyP3zEMnOERceY+liurHl5RmB4q8=; b=HH6IAuSaDrenU00q3PVe2wijUQZUxml1ZlKhqxc7d5dxTH4F9tJC9wO1+8cCYwNOa8 TImKXQ59MPRlYZP8aJIvhu0ykQS3GERXFDR7xDN5uqlL4pSYUHEDpIigOf8wF9wsiI+E QdpVmHtGMv/Y79hGeVqWgI57w4KcV2IVK+5MPDPqiurFFaXVn0RUc/VpB6EtJl1ZJ9v4 l/BiozPoLrpkBiJvEhAwtJDxALN4JY+wegwRXr2n+4ZHOKOucWPhzTJD+Gg3XpOLRAz/ BNQ/ox17VD91VGtQB4Q9I1C7UfliYDR5DruE5IOzJgAzouCNOeE0h4Wwfa3qVw50YgYz LLCQ== X-Gm-Message-State: AOJu0YyzEKsrs2Qrw/+o5J/cXM9/Tn8sACHijfqF9QBrygehvILlv9nP cwQkVGbEwa2h/SbCobVProsxoQYpcjWCgV1rtlvscFWRMzAZFx/ttkymkYEyaxbkqaxzU61klTs tZn1QWZC0KOZRfg== X-Google-Smtp-Source: AGHT+IHO9p0R6vx/xasgcNdYKoGnU97x1A00K9+39lodTTl67acuMpglei7UlMT7MGYETEDcubAg3m4QWvN/Hg4= X-Received: from pfih17.prod.google.com ([2002:a05:6a00:2191:b0:736:a134:94ad]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3a96:b0:736:aea8:c9b7 with SMTP id d2e1a72fcca58-73c26d17aa0mr3050071b3a.2.1744815000385; Wed, 16 Apr 2025 07:50:00 -0700 (PDT) Date: Wed, 16 Apr 2025 14:43:04 +0000 In-Reply-To: <20250416144917.16822-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: <20250416144917.16822-1-guanyulin@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250416144917.16822-5-guanyulin@google.com> Subject: [PATCH v12 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, gargaditya08@live.com, kekrby@gmail.com, jeff.johnson@oss.qualcomm.com, quic_zijuhu@quicinc.com, andriy.shevchenko@linux.intel.com, ben@decadent.org.uk, broonie@kernel.org, quic_wcheng@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Guan-Yu Lin Sharing a USB controller with another entity via xhci-sideband driver creates power management complexities. To prevent the USB controller from being inadvertently deactivated while in use by the other entity, a usage-count based mechanism is implemented. This allows the system to manage power effectively, ensuring the controller remains available whenever needed. In order to maintain full functionality of an offloaded USB devices, several changes are made within the suspend flow of such devices: - skip usb_suspend_device() so that the port/hub are still active for USB transfers via offloaded path. - not suspending the endpoints which are used by USB interfaces marked with needs_remote_wakeup. Namely, skip usb_suspend_interface() and usb_hcd_flush_endpoint() on associated USB interfaces. This reserves a pending interrupt urb during system suspend for handling the interrupt transfer, which is necessary since remote wakeup doesn't apply in the offloaded USB devices when controller is still active. - not flushing the endpoints of actively offloaded USB devices. Given that the USB devices is used by another entity, unilaterally flush the endpoint might lead to unexpected behavior on another entity. - not suspending the xhci controller. This is done by skipping the suspend/resume callbacks in the xhci platform driver. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 50 +++++++++++++++++++++++++++++++----- drivers/usb/host/xhci-plat.c | 19 ++++++++++++++ drivers/usb/host/xhci-plat.h | 1 + include/linux/usb.h | 7 ++--- 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 76372690add0..6c3eb8fb6310 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1420,11 +1420,28 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) udev->state == USB_STATE_SUSPENDED) goto done; + if (msg.event == PM_EVENT_SUSPEND && usb_offload_check(udev)) { + dev_dbg(&udev->dev, "device offloaded, skip suspend.\n"); + udev->offload_at_suspend = 1; + } + /* Suspend all the interfaces and then udev itself */ if (udev->actconfig) { n = udev->actconfig->desc.bNumInterfaces; for (i = n - 1; i >= 0; --i) { intf = udev->actconfig->interface[i]; + /* + * Don't suspend interfaces with remote wakeup while + * the controller is active. This preserves pending + * interrupt urbs, allowing interrupt events to be + * handled during system suspend. + */ + if (udev->offload_at_suspend && + intf->needs_remote_wakeup) { + dev_dbg(&intf->dev, + "device offloaded, skip suspend.\n"); + continue; + } status = usb_suspend_interface(udev, intf, msg); /* Ignore errors during system sleep transitions */ @@ -1435,7 +1452,8 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) } } if (status == 0) { - status = usb_suspend_device(udev, msg); + if (!udev->offload_at_suspend) + status = usb_suspend_device(udev, msg); /* * Ignore errors from non-root-hub devices during @@ -1480,9 +1498,11 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) */ } else { udev->can_submit = 0; - for (i = 0; i < 16; ++i) { - usb_hcd_flush_endpoint(udev, udev->ep_out[i]); - usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + if (!udev->offload_at_suspend) { + for (i = 0; i < 16; ++i) { + usb_hcd_flush_endpoint(udev, udev->ep_out[i]); + usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + } } } @@ -1524,17 +1544,35 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg) udev->can_submit = 1; /* Resume the device */ - if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) - status = usb_resume_device(udev, msg); + if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume) { + if (!udev->offload_at_suspend) + status = usb_resume_device(udev, msg); + else + dev_dbg(&udev->dev, + "device offloaded, skip resume.\n"); + } /* Resume the interfaces */ if (status == 0 && udev->actconfig) { for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { intf = udev->actconfig->interface[i]; + /* + * Interfaces with remote wakeup aren't suspended + * while the controller is active. This preserves + * pending interrupt urbs, allowing interrupt events + * to be handled during system suspend. + */ + if (udev->offload_at_suspend && + intf->needs_remote_wakeup) { + dev_dbg(&intf->dev, + "device offloaded, skip resume.\n"); + continue; + } usb_resume_interface(udev, intf, msg, udev->reset_resume); } } + udev->offload_at_suspend = 0; usb_mark_last_busy(udev); done: diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 9843d3ad5cf4..598f1b974347 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "xhci.h" #include "xhci-plat.h" @@ -483,6 +484,15 @@ static int xhci_plat_suspend_common(struct device *dev) static int xhci_plat_suspend(struct device *dev) { + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); + + if (xhci_sideband_check(hcd)) { + priv->sideband_at_suspend = 1; + dev_dbg(dev, "sideband instance active, skip suspend.\n"); + return 0; + } + return xhci_plat_suspend_common(dev); } @@ -535,6 +545,15 @@ static int xhci_plat_resume_common(struct device *dev, bool power_lost) static int xhci_plat_resume(struct device *dev) { + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); + + if (priv->sideband_at_suspend) { + priv->sideband_at_suspend = 0; + dev_dbg(dev, "sideband instance active, skip resume.\n"); + return 0; + } + return xhci_plat_resume_common(dev, false); } diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h index fe4f95e690fa..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 ec8d839e1e2b..f5bca317fa4c 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -635,6 +635,8 @@ struct usb3_lpm_parameters { * @do_remote_wakeup: remote wakeup should be enabled * @reset_resume: needs reset instead of resume * @port_is_suspended: the upstream port is suspended (L2 or U3) + * @offload_at_suspend: offload activities during suspend is enabled. + * @offload_usage: number of offload activities happening on this usb device. * @slot_id: Slot ID assigned by xHCI * @l1_params: best effor service latency for USB2 L1 LPM state, and L1 timeout. * @u1_params: exit latencies for USB3 U1 LPM state, and hub-initiated timeout. @@ -647,7 +649,6 @@ 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 @@ -724,6 +725,8 @@ struct usb_device { unsigned do_remote_wakeup:1; unsigned reset_resume:1; unsigned port_is_suspended:1; + unsigned offload_at_suspend:1; + int offload_usage; enum usb_link_tunnel_mode tunnel_mode; int slot_id; @@ -734,8 +737,6 @@ struct usb_device { u16 hub_delay; unsigned use_generic_driver:1; - - int offload_usage; }; #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, dev)