From patchwork Mon Oct 14 08:50:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 835379 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 960EE15884A for ; Mon, 14 Oct 2024 08:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896320; cv=none; b=kbL8uF+e7O4yYfYxJ2XoHB83Gl2yvv/DqoVW7EXD18Rpthg3V+xQYppQhl8osDQRJXT041y+Q3E1Wdt7xj9WfkYtKGK4s/Tvr+pZw/otl4bbhIBOk9c6Kd16gz9XqjTYOduipzPUGw+FdhNJk8ADSj+OrDem4KSCrI+Wo4K6DG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896320; c=relaxed/simple; bh=GMwCb54K5fwAFj7CdJY410A+DGpUZKZFwOlbLbNO1Rk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=A69qecL028v+YWooHN1q88k8ldoqqXVhybqlYG86aniPWoghXhhCJ4osjMqbGCVdN+QA+JXr1OHA/v8GRmMqQOQ8HLcfxjv/QPJuxf6E0ImeZfn2jFN6m+Xi4mEv/CYvmG7o651MMEolDySPmdAoBWSEFEF9zko1EEuGS94B2iY= 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=3U1mDPob; arc=none smtp.client-ip=209.85.219.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="3U1mDPob" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e290b8b69f8so6708680276.2 for ; Mon, 14 Oct 2024 01:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728896317; x=1729501117; 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=CBCkOZOzlb8OpyLWnTs3NTPuF3GCuKe+Ddcqr6JZX/0=; b=3U1mDPobFnGgHq84Pv0g6bNH0GHiZbP4HPFjkDevwtzcBDYQ794TIino5NpGFE9IW3 anEo6nhGnK7VcLPVgFm8hG8xAMjNuTAp+qvKvjm+Oq/98CR4OYBtjPOm5f8VN503oKRC jqbT7IeKmKaBMmeFrkgM+d2R/FhW2n0f3I2jTxwoJZT6TBMw9vGrMKk86xXZjjw6LmeJ rZU8d1ZUBsg7bfVCtblTNMF+FSAO4XUgpohnznQ0Tp+7REd+gYvl5LgbIJc5GmpQTbvE 89IPFq0ZaDwaED56YqOe3GltrxmBFjAiQFSwyQGK/tK0G/aVJUBcNxfgyn2uZWkbPsLR oe0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896317; x=1729501117; 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=CBCkOZOzlb8OpyLWnTs3NTPuF3GCuKe+Ddcqr6JZX/0=; b=sUNfCNvZU/snl6VIJb6HlEylW8YKioWdOavE6UoGbX1FhaH89PMOX7C4UqGAQ894zn TFxvqFBpPBPWa41HbquzHt1WjAWtkx7Lm6cDIovWkHW0jmQk2gG66M7UGZEOvsPx7VHX 46KO4/xd3RanpV++1v0lwkaYyQ7bbp2OPu9hHrV9U8bSFWc9ZJznFa/y7tp4StpPwNDr wlVf0b/k6i/Z70fR6OcLDG7Reuf6x7vdJGGy6LyGGIgVRRqiBMXFVaZ4bgQY+4LT0CdA LH6dnBis4GjUL4MO5YSK9tmSJN64P96xeuRs/hej4Ga8aAyCKIgCt4xncGKh3BxEgr2b 0y4w== X-Gm-Message-State: AOJu0YxVBGiG9aMaQ4RjYXwewsliAe1lezg9vgrWFENfHMZhPjgAv9qy wfMQ6XRXa7peVKjvfJLtttZ9+eYZ4B+oWATRpJp7ST30SGjWM7oPQCuv15/lB48q4FhKjumUD43 tX8q7uD+EHw/oxw== X-Google-Smtp-Source: AGHT+IFsur8fmOZLkwe4HhkxKg7dnhiw5z6XfD/hxTsXEwag7FFm57X7hNgZDDjovJC655vxY59/fqhW7oMQlLM= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a25:d344:0:b0:e20:2502:be14 with SMTP id 3f1490d57ef6-e291a2024cfmr6856276.7.1728896317491; Mon, 14 Oct 2024 01:58:37 -0700 (PDT) Date: Mon, 14 Oct 2024 08:50:25 +0000 In-Reply-To: <20241014085816.1401364-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: <20241014085816.1401364-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241014085816.1401364-2-guanyulin@google.com> Subject: [PATCH v5 1/5] usb: dwc3: separate dev_pm_ops for each pm_event From: Guan-Yu Lin To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, yajun.deng@linux.dev, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, dianders@chromium.org, perex@perex.cz, tiwai@suse.com, niko.mauno@vaisala.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, quic_jjohnson@quicinc.com, ricardo@marliere.net Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, badhri@google.com, albertccwang@google.com, quic_wcheng@quicinc.com, pumahsu@google.com, Guan-Yu Lin Separate dev_pm_ops for different power events such as suspend, thaw, and hibernation. This is crucial when dwc3 driver needs to adapt its behavior based on different power state changes. Signed-off-by: Guan-Yu Lin --- drivers/usb/dwc3/core.c | 77 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index b25d80f318a9..2fdafbcbe44c 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2582,6 +2582,76 @@ static int dwc3_resume(struct device *dev) return 0; } +static int dwc3_freeze(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + ret = dwc3_suspend_common(dwc, PMSG_FREEZE); + if (ret) + return ret; + + pinctrl_pm_select_sleep_state(dev); + + return 0; +} + +static int dwc3_thaw(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + pinctrl_pm_select_default_state(dev); + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + + ret = dwc3_resume_common(dwc, PMSG_THAW); + if (ret) { + pm_runtime_set_suspended(dev); + return ret; + } + + pm_runtime_enable(dev); + + return 0; +} + +static int dwc3_poweroff(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + ret = dwc3_suspend_common(dwc, PMSG_HIBERNATE); + if (ret) + return ret; + + pinctrl_pm_select_sleep_state(dev); + + return 0; +} + +static int dwc3_restore(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + pinctrl_pm_select_default_state(dev); + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + + ret = dwc3_resume_common(dwc, PMSG_RESTORE); + if (ret) { + pm_runtime_set_suspended(dev); + return ret; + } + + pm_runtime_enable(dev); + + return 0; +} + static void dwc3_complete(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); @@ -2599,7 +2669,12 @@ static void dwc3_complete(struct device *dev) #endif /* CONFIG_PM_SLEEP */ static const struct dev_pm_ops dwc3_dev_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) + .suspend = pm_sleep_ptr(dwc3_suspend), + .resume = pm_sleep_ptr(dwc3_resume), + .freeze = pm_sleep_ptr(dwc3_freeze), + .thaw = pm_sleep_ptr(dwc3_thaw), + .poweroff = pm_sleep_ptr(dwc3_poweroff), + .restore = pm_sleep_ptr(dwc3_restore), .complete = dwc3_complete, SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume, dwc3_runtime_idle) From patchwork Mon Oct 14 08:50:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 835735 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 AC53215748A for ; Mon, 14 Oct 2024 08:58:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896325; cv=none; b=NmRcSSBVN9IOL2UDzglxrTjT2HyAV6Bfbu0vypfSEbEfeYc0PiZE8lUr56NWtzuipBHQfmcko+D5LpS2mJqb8BqUnkm1m5BKaRZz9sdtKmqrfX7LEn5NZ/AtudPKnPTFLnOQnQnVshTXDpZFyxEWiVvH8bM/zyCurZ5AtAjdcKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896325; c=relaxed/simple; bh=2lp7pWa+Y9Lda05LwotKzYc/laDTaan9URjSvGwxaaI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iU+Xy465x37aQpGOQF/tMJoolltulZGFN6hbEzlBFjG6bmikr452mcwWr9aRvrj5msuJvCPjA39xv1SSdo1/r+JFZlR5v3bmxA8NppwUCRYI1OKNmbr0HKwcij2RRcjPTlzvt4OhUDCwJZMVJobz7iKUncUc9RnIMuR+fIDj53I= 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=A6h32L9y; arc=none smtp.client-ip=209.85.128.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="A6h32L9y" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e35199eb2bso37343297b3.3 for ; Mon, 14 Oct 2024 01:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728896323; x=1729501123; 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=QbiVbUE4n2QmVYqe4n4Co2Ibt4J5qV8FN5F6a1txb10=; b=A6h32L9yC8ytugPzN5dK+Dq7bIFrJOLY6W14oSM2KuOYXcv6M0m0AOCdsnJQfUqLct WDJHvYHEU638lSbSrVnQ1OpLS9fevWK3lvhgazF0Wp9Cuk2kHaU3ykmMg9AiILxVXzhd zulCkrENajD66ZmohMQ6b//2ezl0Zc9SXqSVnP7ZyWQcMCKiAt4rTXymfROEfNDBYj0v 3GWGX/dIH4LSc5QecX432xi8tHa4Ri7JN4IKqP/byJww4bKF37sjd1Yd/TA9iW7QzSlL pduRm34h+QE28i3l+Cn6LlKFv5Y3M5jdQ8m2kakJVBN8V54HuqGrdNZDh60TvWwWFxkK qt5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896323; x=1729501123; 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=QbiVbUE4n2QmVYqe4n4Co2Ibt4J5qV8FN5F6a1txb10=; b=IWfgwp7E6CfH2vlUsUx/4HL9imqKE4IxcWFiMMJuEA2KN2A1M8QbjUXtW4UZpSZyEt Wbd2fPmwL/jjLoWWTS7Kl/SjKp7XZnH639X0SmWCahd+fbfIn+d03s9ZSDP503uQimvU LkVluPRMy56rJpXkz/phBV9jJPlKodwSkX7SfLWnMTsMdhgEGZQC9rOaj7lx0EB12FGL wNjrALBlDk8doPW4HmrLQNNrppm0XixHPxEN8Y2N4HQPGs+jSCgfMy8kIuNNo7IpHDuc Rvj4G2Z5dxH5qgwvlbB0R3ObgsBW4ClzU+DVImRbQrF4mEk411NXlpD0RlwHO8A8Ix8f OE+A== X-Gm-Message-State: AOJu0YwLq4C1/lTQBhvagBGz7GrJrhZTe0nA8JKrUF3txslyoMu1+L4u nl+ZyVLV9G+4sHPMTi4vg03IQQ4/tRIH466A5E58kl2nb2oF3CI4Ag1VJ+G8ZIK34MDOL8Ngw0M 8CzLNx30ZT0Bl2A== X-Google-Smtp-Source: AGHT+IE/5EOgs1bQNwKCDuXAlvqCP9BqZx0Xs7qoml7G+FtAvsXrY1GIN+Lb4ymiqx+wllbQf0cGzNfuJtzOSng= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a05:690c:2b83:b0:62c:f976:a763 with SMTP id 00721157ae682-6e3477b6b5bmr908487b3.1.1728896322306; Mon, 14 Oct 2024 01:58:42 -0700 (PDT) Date: Mon, 14 Oct 2024 08:50:26 +0000 In-Reply-To: <20241014085816.1401364-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: <20241014085816.1401364-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241014085816.1401364-3-guanyulin@google.com> Subject: [PATCH v5 2/5] usb: xhci-plat: separate dev_pm_ops for each pm_event From: Guan-Yu Lin To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, yajun.deng@linux.dev, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, dianders@chromium.org, perex@perex.cz, tiwai@suse.com, niko.mauno@vaisala.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, quic_jjohnson@quicinc.com, ricardo@marliere.net Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, badhri@google.com, albertccwang@google.com, quic_wcheng@quicinc.com, pumahsu@google.com, 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 | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 8dc23812b204..6e49ef1908eb 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -450,7 +450,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 pm_message pmsg) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct xhci_hcd *xhci = hcd_to_xhci(hcd); @@ -478,6 +478,21 @@ static int xhci_plat_suspend(struct device *dev) return 0; } +static int xhci_plat_suspend(struct device *dev) +{ + return xhci_plat_suspend_common(dev, PMSG_SUSPEND); +} + +static int xhci_plat_freeze(struct device *dev) +{ + return xhci_plat_suspend_common(dev, PMSG_FREEZE); +} + +static int xhci_plat_poweroff(struct device *dev) +{ + return xhci_plat_suspend_common(dev, PMSG_HIBERNATE); +} + static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg) { struct usb_hcd *hcd = dev_get_drvdata(dev); @@ -524,6 +539,11 @@ static int xhci_plat_resume(struct device *dev) return xhci_plat_resume_common(dev, PMSG_RESUME); } +static int xhci_plat_thaw(struct device *dev) +{ + return xhci_plat_resume_common(dev, PMSG_THAW); +} + static int xhci_plat_restore(struct device *dev) { return xhci_plat_resume_common(dev, PMSG_RESTORE); @@ -553,9 +573,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_poweroff), .restore = pm_sleep_ptr(xhci_plat_restore), SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, From patchwork Mon Oct 14 08:50:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 835378 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 5CEF315B104 for ; Mon, 14 Oct 2024 08:58:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896331; cv=none; b=A3Wm3xUFqt3pBWEuD9/MdcG+BTQeaTuUhTl+PQtuVUvK7O4pD+KTWXK2VWlCaHzwlEJ49N9+IV5gYyenfvJSyK/ngRibhtQ9Pr8Xk/5wDOm5V5FDFToYaU58v+7Stq1mdZNtAGxcp7Engda4qN0Zq6o/VF/pkAXuC+q34x886o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896331; c=relaxed/simple; bh=EU15+Ru20MN5GJaR2Iq5WSX2NUmdvQcj26opweRi4qQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=r9D37D//jLCUJL8+XBGkpi0b5ZW4lKIxYQpfCiYxWh+uMNigV/XGefz4Z2phg0/5IZfY9SfxxmK3uht9vDFFOk/0iMxjsOYQDGrp/FgrFw9unH7Qy2CMaPtOQmZI6W5nmF+njXjIO0MyuQk6jDf5epSbn2NoNqBe1W44liPNvJ0= 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=eOZqAOxj; arc=none smtp.client-ip=209.85.219.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="eOZqAOxj" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e290222fde4so4399485276.1 for ; Mon, 14 Oct 2024 01:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728896327; x=1729501127; 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=m3Gr3/dhYM6/ZLOl5nRxFncYa9Ac7JDDqUDonxbjd0Y=; b=eOZqAOxjrXBRkb8eFCumCLM6inem4JclBbZWOb8chzNH95m+YKVHDl9VAfMF0IXB5F m3QbvVJzRcTsDpE6EXT8FKCJwZ0WMPwAylm7mCwo71KgnamRVMVLYajCemzBhtItckaF vip+snoHffNIftqf38UeTsrV40Z+yjnELa3YT0xZQaT2vQVsD//e/Hc17UwOY6xS/rHM c8B5yr56jkI0ZJ89o9a8Wa8mgi2B6nSAzB2SdB0mmGvNkQHdLcKEWLkeGgfjjU5RlYYl gZPyAJaQ//SaHiQlN/ZDtCEvvaEE6bHXQ8mhqAZmG4qZh3sc9jRdHYGMjPoABlchXFLB IUng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896327; x=1729501127; 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=m3Gr3/dhYM6/ZLOl5nRxFncYa9Ac7JDDqUDonxbjd0Y=; b=rAl4lheZTvpQgPUHGAXdwXcR3+zU3WtlaK9QeWml/nzJs6HIzA5RazOnnuBi27SEH6 G2TkIRG3gL3FXGKN0Zfje53zeH52h78Ol8+Bf0VKHfpCJyHPfr5XTP1pEldkn8LNJczU rx0hzJeiw2hBRmRC4E+9jJ4+iIlVYCG4gN0+eTQvBCaNaoDOXHFlAYZ8pgI8IIe52VTf yHUVzqJqdkwpnwHu4eGAqIWCPr+8B+M+HjiO3cGF8ODtVVa8m5eryifCwwfuQfZwagEu FPXXDgVUGSrEzReUMSVJO9M9wfdQ8rqzX3Jg4uMaULudEAJsmtOgiG1DsV+/xiemT2Zn dYuQ== X-Gm-Message-State: AOJu0YzgOVKAxKrpLdhWBR3W7wl9V5WUXvWlxww406v0dsSLDbev5rZ0 dGjviwMWwc2LfbRIFpfDDfK3KSmCFHfdS1hIuDWuXv4C/B4/TqP7JiaMn1AWCYqc4ytsfVwc5BG Qqf1WJe/jTMDqQQ== X-Google-Smtp-Source: AGHT+IFkp0At4RJQAY5NZEsgtLShOUCl9IUeoX1HIsgFMsKuDYqKxKF1EtyJ1HJX86U8UKYYju/aeUg4Qv4RJO0= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a25:d3d2:0:b0:e28:e9ea:8cca with SMTP id 3f1490d57ef6-e2919fe7b3cmr43777276.8.1728896327307; Mon, 14 Oct 2024 01:58:47 -0700 (PDT) Date: Mon, 14 Oct 2024 08:50:27 +0000 In-Reply-To: <20241014085816.1401364-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: <20241014085816.1401364-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241014085816.1401364-4-guanyulin@google.com> Subject: [PATCH v5 3/5] usb: add apis for sideband usage tracking From: Guan-Yu Lin To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, yajun.deng@linux.dev, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, dianders@chromium.org, perex@perex.cz, tiwai@suse.com, niko.mauno@vaisala.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, quic_jjohnson@quicinc.com, ricardo@marliere.net Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, badhri@google.com, albertccwang@google.com, quic_wcheng@quicinc.com, pumahsu@google.com, Guan-Yu Lin Introduce sb_usage_count and corresponding apis to track sideband usage on each USB device. A sideband refers to the co-processor that accesses the usb_device via shared control on the same USB host controller. To optimize power usage, it's essential to monitor whether ther sideband is actively using the USB device. 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 | 53 +++++++++++++++++++++++++++++++++++++++ include/linux/usb.h | 13 ++++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 0c3f12daac79..e713cf9b3dd2 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1673,6 +1673,59 @@ void usb_disable_autosuspend(struct usb_device *udev) } EXPORT_SYMBOL_GPL(usb_disable_autosuspend); +/** + * usb_sideband_get - increment the sb_usage_count of a USB device + * @udev: the USB device to increment its sb_usage_count + * + * Incrementing the sb_usage_count of a usb_device indicates that a sideband is + * currently using the device; that is, another entity is actively handling USB + * transfers. This information allows the USB driver to adjust its power + * management policy based on sideband activity. + */ +void usb_sideband_get(struct usb_device *udev) +{ + refcount_inc(&udev->sb_usage_count); +} +EXPORT_SYMBOL_GPL(usb_sideband_get); + +/** + * usb_sideband_put - drop the sb_usage_count of a USB device + * @udev: the USB device to drop its sb_usage_count + * + * The inverse operation of usb_sideband_get, which drops the sb_usage_count of + * a USB device. This information allows the USB driver to adjust its power + * management policy based on sideband activity. + */ +void usb_sideband_put(struct usb_device *udev) +{ + refcount_dec(&udev->sb_usage_count); +} +EXPORT_SYMBOL_GPL(usb_sideband_put); + +/** + * usb_sideband_check - check sideband activities on a USB device + * @udev: the USB device to check its sideband activity. + * + * Check if there are any sideband activity on the USB device right now. This + * information could be used for power management or other forms or resource + * management. + * + * Returns true on any active sideband existence, false otherwise + */ +bool usb_sideband_check(struct usb_device *udev) +{ + struct usb_device *child; + int port1; + + usb_hub_for_each_child(udev, port1, child) { + if (usb_sideband_check(child)) + return true; + } + + return !!refcount_read(&udev->sb_usage_count); +} +EXPORT_SYMBOL_GPL(usb_sideband_check); + /** * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces * @udev: the usb_device to autosuspend diff --git a/include/linux/usb.h b/include/linux/usb.h index 672d8fc2abdb..37a36750a851 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -645,6 +645,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. + * @sb_usage_count: number of active sideband accessing this usb device. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use @@ -731,6 +732,8 @@ struct usb_device { u16 hub_delay; unsigned use_generic_driver:1; + + refcount_t sb_usage_count; }; #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, dev) @@ -798,6 +801,9 @@ static inline int usb_acpi_port_lpm_incapable(struct usb_device *hdev, int index #ifdef CONFIG_PM extern void usb_enable_autosuspend(struct usb_device *udev); extern void usb_disable_autosuspend(struct usb_device *udev); +extern void usb_sideband_get(struct usb_device *udev); +extern void usb_sideband_put(struct usb_device *udev); +extern bool usb_sideband_check(struct usb_device *udev); extern int usb_autopm_get_interface(struct usb_interface *intf); extern void usb_autopm_put_interface(struct usb_interface *intf); @@ -818,6 +824,13 @@ static inline int usb_enable_autosuspend(struct usb_device *udev) static inline int usb_disable_autosuspend(struct usb_device *udev) { return 0; } +static inline int usb_sideband_get(struct usb_device *udev) +{ return 0; } +static inline int usb_sideband_put(struct usb_device *udev) +{ return 0; } +static inline bool usb_sideband_check(struct usb_device *udev) +{ return false; } + static inline int usb_autopm_get_interface(struct usb_interface *intf) { return 0; } static inline int usb_autopm_get_interface_async(struct usb_interface *intf) From patchwork Mon Oct 14 08:50:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 835734 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 D40C515C14D for ; Mon, 14 Oct 2024 08:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896334; cv=none; b=CDFc2AIYniTajz+jiCtcA37e2j4onVY5BXXyqoXIutSZk/+qS/2JNw5GXaRmalg7JjrZmnNNrYQgeCVhMTeUUM3WSY+h3r+6Q1T1E4vPTLQUlRw1km3mAmxrAKLUwh/xAir4TUFOOKZctvwsQ3cADVFO76KQKxOIJqfnEpFaZ0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896334; c=relaxed/simple; bh=00RezD4fZXgbmVjvyaGx9y1/uF7V89ZgLGz+dUck3vw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VNcHuqlUs4Ht8hCLFkIdhWuTsKOt+sltu3MscpEjoVtcLQzJ2qxiuAfVpbMM7ND+ZqJ+xWkine2xyZmLg75oIwt95Px802X6Tq6JRDZNDSh5HU8Rat60Sap9nVAAlTrFCr8lodQM1NE2nbAMbO5Wa6Wo3BfBf785VEZ0lUi9JGQ= 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=OsSupcw4; arc=none smtp.client-ip=209.85.219.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="OsSupcw4" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e290222fde4so4399525276.1 for ; Mon, 14 Oct 2024 01:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728896332; x=1729501132; 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=bMcgk3CcUjXi+uoOfgcbw4Mfb3bioMSfzYjoaeWoO/o=; b=OsSupcw4QO1wrI9/nUWcLEfElCcNNbi4J2TT9DdsOs4qcUjGlrtkTfiPAiLvuOKulh 1s4i7XEsj5VdNj1azSBeBtSUtmavCPbEcCV7BwqNrM9ekFzpAkppl+m/2JszoOHVwpUs A33OAoeEQoZDNJoUT485bdVvWA84xyXSV0EedMS5FhII0SgJVDKShvmzbvUhmN2xMxSZ LPoNA/CZXzvVAF+xKYtzadpdSXW6DhdD+6JBxYCx2TJtxRJOqicKHUSC2hxWrlV5P6MY VfWkkYpDEqEHPEgyMJuIES1X8G37zhmBVuTMOKRYIEvB0WdrVv3f943eeUwg5VE38qM4 47Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896332; x=1729501132; 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=bMcgk3CcUjXi+uoOfgcbw4Mfb3bioMSfzYjoaeWoO/o=; b=MKCNad6G0HZ6zOYxYA7ZdtaEdCqZKLNseCm7ouC8J6dOv9p9bZXWqErv8+V/B5YhRT +8AO3WkxuC6exobARpo/CnpEbLb0ttTJOaBBygzDt9eQK8OaxhrRNoBmfN5CysMizFck QFUpvUbisKWpUUDZuUfglaU5YjkOcBJtrx9FHKb9GAwklQtFvlaOp0wBdE2EduEl8ChJ HuR+03/zKfi/iJbEXmCCi5tpOED21+Fh8X2TF93uKZ7LMyMOGTx7ILpXpV618gg6OWES XmCQqEo1aEPZaSOEPFxTm39+aJZoYCHNVGQEHd8zJ/5H9yVxGCt16A/NafDaHSfOo07B x4wg== X-Gm-Message-State: AOJu0Yyzn2pA8n45FeU1/jHFxXO3YSH/UW6GZtxxOX8ctmlS8sJwhTnr lej7F/kBUP1SHL/PmUs6p6KQb6lN0g+C/bVTcQlUYiltsqXZQH6Nx1IOuveg9IeApCg2Ryq2Xxg /I11rwoGdIMFxOg== X-Google-Smtp-Source: AGHT+IEQKdL9Plag6ZA1vhHt8ZLUYQhQJYeN3Urx8uogAw0TWmuM/he1UtGVOy7Ebzmw1h4YomDg2lD5HqH2srQ= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a25:26c6:0:b0:e0b:f69b:da30 with SMTP id 3f1490d57ef6-e2919fe7a11mr54743276.9.1728896331800; Mon, 14 Oct 2024 01:58:51 -0700 (PDT) Date: Mon, 14 Oct 2024 08:50:28 +0000 In-Reply-To: <20241014085816.1401364-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: <20241014085816.1401364-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241014085816.1401364-5-guanyulin@google.com> Subject: [PATCH v5 4/5] xhci: sideband: add api to trace sideband usage From: Guan-Yu Lin To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, yajun.deng@linux.dev, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, dianders@chromium.org, perex@perex.cz, tiwai@suse.com, niko.mauno@vaisala.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, quic_jjohnson@quicinc.com, ricardo@marliere.net Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, badhri@google.com, albertccwang@google.com, quic_wcheng@quicinc.com, pumahsu@google.com, Guan-Yu Lin The existing sideband driver only registers sidebands without tracking their active usage. To address this, new apis are introduced to: - mark sideband usage: record the sideband usage information in the USB host controller driver and USB device driver. - query sideband status: provide a means for other drivers to fetch sideband activity information on a USB host controller. Signed-off-by: Guan-Yu Lin --- drivers/usb/host/xhci-sideband.c | 74 +++++++++++++++++++++++++++++++ include/linux/usb/hcd.h | 4 ++ include/linux/usb/xhci-sideband.h | 5 +++ 3 files changed, 83 insertions(+) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideband.c index d04cf0af57ae..87dd66056324 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -334,6 +334,80 @@ xhci_sideband_interrupter_id(struct xhci_sideband *sb) } EXPORT_SYMBOL_GPL(xhci_sideband_interrupter_id); +/** + * xhci_sideband_get - inform related drivers there's a new active sideband + * @sb: sideband instance for this usb device + * + * An active sideband indicates that another entity is currently using the host + * controller. Inform the host controller and related usb devices by increasing + * their sb_usage_count. This allows the corresponding drivers to dynamically + * adjust power management actions based on current sideband activity. + * + * Returns 0 on success, negative error otherwise + */ +int xhci_sideband_get(struct xhci_sideband *sb) +{ + struct usb_hcd *hcd; + struct usb_device *udev; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd = xhci_to_hcd(sb->xhci); + refcount_inc(&hcd->sb_usage_count); + + udev = sb->vdev->udev; + usb_sideband_get(udev); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_get); + +/** + * xhci_sideband_put - inform related drivers there's a sideband deactivated + * @sb: sideband instance for this usb device + * + * The inverse operation of xhci_sideband_get, which informs the host + * controller and related usb devices by decreasing their sb_usage_count. This + * allows the corresponding drivers to dynamically adjust power management + * actions based on current sideband activity. + * + * Returns 0 on success, negative error otherwise + */ +int xhci_sideband_put(struct xhci_sideband *sb) +{ + struct usb_hcd *hcd; + struct usb_device *udev; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd = xhci_to_hcd(sb->xhci); + refcount_dec(&hcd->sb_usage_count); + + udev = sb->vdev->udev; + usb_sideband_put(udev); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_put); + +/** + * xhci_sideband_check - check sideband activities on the host controller + * @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 right now. This information + * could be used for power management or other forms or resource management. + * + * Returns true on any active sideband existence, false otherwise + */ +bool xhci_sideband_check(struct usb_hcd *hcd) +{ + return !!refcount_read(&hcd->sb_usage_count); +} +EXPORT_SYMBOL_GPL(xhci_sideband_check); + /** * xhci_sideband_register - register a sideband for a usb device * @udev: usb device to be accessed via sideband diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index ac95e7c89df5..d4f5e57b0c00 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -84,6 +84,10 @@ struct usb_hcd { struct urb *status_urb; /* the current status urb */ #ifdef CONFIG_PM struct work_struct wakeup_work; /* for remote wakeup */ +#ifdef CONFIG_USB_XHCI_SIDEBAND + /* Number of active sideband accessing the host controller. */ + refcount_t sb_usage_count; +#endif #endif struct work_struct died_work; /* for when the device dies */ diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sideband.h index f0223c5535e0..4850fc826e00 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -12,6 +12,7 @@ #include #include +#include #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ @@ -57,6 +58,10 @@ xhci_sideband_get_endpoint_buffer(struct xhci_sideband *sb, struct sg_table * xhci_sideband_get_event_buffer(struct xhci_sideband *sb); +int xhci_sideband_get(struct xhci_sideband *sb); +int xhci_sideband_put(struct xhci_sideband *sb); +bool xhci_sideband_check(struct usb_hcd *hcd); + int xhci_sideband_create_interrupter(struct xhci_sideband *sb, int num_seg, bool ip_autoclear, u32 imod_interval, int intr_num); From patchwork Mon Oct 14 08:50:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 835377 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 229D715DBAB for ; Mon, 14 Oct 2024 08:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896338; cv=none; b=E3/RV4eT+PRH1Y5rmxHmPH6WayY2bini3Cd7LpMR7+PwSNdLN7EL5kcR6RYdExDPaECFuvKNjKyc60jLGcfzBEj/D3MdC2L15ZY4V9q0dl2mI0QvZtcSMqLbsm7HvjQKmVQ0lWFx8sX2C7hr69iICaE0ppsRz5j9Y31R1QDN0sc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728896338; c=relaxed/simple; bh=gwBxetmHAUs6dpF8OWOjFANRyC9Za3R8kPrSPs0nUDc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=F3wGOXrYdS0jTdFxGatpuowSUEoc1vpYFp86jIEUAqKSkXNy6SjHtVjSudKGeSJAe6NO4JK54/NvG3xjMMO/gM8KLX7up8VmAk1RByedYUXX/s47PYx1l7eu9+MSpf00k6OC5opKziQpcpgoJ1Ym4y9wrmydIBAHcA/uK6mzlf4= 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=J1qAmHHC; arc=none smtp.client-ip=209.85.219.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="J1qAmHHC" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e2605ce4276so6970533276.3 for ; Mon, 14 Oct 2024 01:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728896336; x=1729501136; 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=6y7M/9jWGeDkCGLYRuLSMJUH16Au0fuqCfkifg79sVM=; b=J1qAmHHCiJFaH4fnfBwsmBmxMg9/7ininbnEjPznkTu1oJQ+abrO+D0Y6ellY3OqcL VWZggXSrzH6aULJxqzommvsH5q9s0KXsloO194I/QQSTqMzuqYRyMjLdFqWlKjj84fLQ Bs6PRPr3IOWdZajnh7eqcOoc1PtU2yXWA7DDeoQo5/9VpfBDfpHlV42Z3Sq9wU4Jk9gn N5nLxu1uifURZ6IKKBiEfGnFCDXKVzE6xmTOABAJQbyshF76VG3g1nNXUzSekqaAv2C6 0VPHzTmwHnF5uRL4WPkckyTfgcrc1y8KY+Yg+75iS6lKnI2RJlfCylk1kAHmFpU9zWOF 8Kfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728896336; x=1729501136; 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=6y7M/9jWGeDkCGLYRuLSMJUH16Au0fuqCfkifg79sVM=; b=Z9YZ4gOLgrSems4/EsGtb1eMyyb9oVoZ0ZrU9hO4FuYBkv67SMJRrLmnXo+uo5pzEh elx/P2NeMEPs3xsMkh0XCybKcjv/ajBeIRo3ziavgWYeGpTAykSC4M8pDiG+H+ysSQrK 80lhz/FBO+KHrfCiKP5F0j86wYeBcjCK8ng1ml36ZavbRTcLy4Frnu0QuOQcQxTr3wZq wCQk+n5plhBZoaZaXcCqj3mPxX/DheDJvwyNjQMcqhtbFgE6Szf9cOnAu+9OtyluXhCS EjEr6LVOz7iYXOf3Fgny+flJ4J/j6p96PLT3ZReW5bkNnEIc9OESRJAUIlo9SMLsweiG emUQ== X-Gm-Message-State: AOJu0YytbbdG68swmWi1VNRy4X77ix34HIW3xaQQQl6pTuIBTSMmqLwJ sbqmYAEjcHHSzGWtFXm2fR1ORkDBCLVPaKvB8wkyxpm4qr9IlSEoxAYI7AZMNz9KejY8USbjnM0 FO55L5JiEelz+WQ== X-Google-Smtp-Source: AGHT+IGuAVHy2wuJJSYKKNO9RPkGqP4RolspviXlmTe441Amv5yytcCNW+/6FnAEGZYrCIN0X9y14RK49kCdPM4= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a25:8702:0:b0:e29:1864:5215 with SMTP id 3f1490d57ef6-e2919dbd114mr7115276.1.1728896336194; Mon, 14 Oct 2024 01:58:56 -0700 (PDT) Date: Mon, 14 Oct 2024 08:50:29 +0000 In-Reply-To: <20241014085816.1401364-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: <20241014085816.1401364-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241014085816.1401364-6-guanyulin@google.com> Subject: [PATCH v5 5/5] usb: host: enable sideband transfer during system sleep From: Guan-Yu Lin To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, yajun.deng@linux.dev, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, dianders@chromium.org, perex@perex.cz, tiwai@suse.com, niko.mauno@vaisala.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, quic_jjohnson@quicinc.com, ricardo@marliere.net Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, badhri@google.com, albertccwang@google.com, quic_wcheng@quicinc.com, pumahsu@google.com, 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. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 10 ++++++++++ drivers/usb/core/hcd.c | 1 + drivers/usb/core/usb.c | 1 + drivers/usb/dwc3/core.c | 13 +++++++++++++ drivers/usb/dwc3/core.h | 8 ++++++++ drivers/usb/host/xhci-plat.c | 10 ++++++++++ drivers/usb/host/xhci-plat.h | 7 +++++++ sound/usb/qcom/qc_audio_offload.c | 3 +++ 8 files changed, 53 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index e713cf9b3dd2..eb85cbb1a2ff 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1583,6 +1583,11 @@ int usb_suspend(struct device *dev, pm_message_t msg) struct usb_device *udev = to_usb_device(dev); int r; + if (msg.event == PM_EVENT_SUSPEND && usb_sideband_check(udev)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + unbind_no_pm_drivers_interfaces(udev); /* From now on we are sure all drivers support suspend/resume @@ -1619,6 +1624,11 @@ int usb_resume(struct device *dev, pm_message_t msg) struct usb_device *udev = to_usb_device(dev); int status; + if (msg.event == PM_EVENT_RESUME && usb_sideband_check(udev)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + /* For all calls, take the device back to full power and * tell the PM core in case it was autosuspended previously. * Unbind the interfaces that will need rebinding later, diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 1ff7d901fede..9876b3940281 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2593,6 +2593,7 @@ struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver, timer_setup(&hcd->rh_timer, rh_timer_func, 0); #ifdef CONFIG_PM INIT_WORK(&hcd->wakeup_work, hcd_resume_work); + refcount_set(&hcd->sb_usage_count, 0); #endif INIT_WORK(&hcd->died_work, hcd_died_work); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 0b4685aad2d5..d315d066a56b 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -671,6 +671,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent, dev->state = USB_STATE_ATTACHED; dev->lpm_disable_count = 1; atomic_set(&dev->urbnum, 0); + refcount_set(&dev->sb_usage_count, 0); INIT_LIST_HEAD(&dev->ep0.urb_list); dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 2fdafbcbe44c..18c743ce5ac5 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2550,8 +2550,15 @@ static int dwc3_runtime_idle(struct device *dev) static int dwc3_suspend(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); + struct platform_device *xhci = dwc->xhci; int ret; + if (xhci && xhci_sideband_check(xhci->dev.driver_data)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + + ret = dwc3_suspend_common(dwc, PMSG_SUSPEND); if (ret) return ret; @@ -2564,8 +2571,14 @@ static int dwc3_suspend(struct device *dev) static int dwc3_resume(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); + struct platform_device *xhci = dwc->xhci; int ret; + if (xhci && xhci_sideband_check(xhci->dev.driver_data)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + pinctrl_pm_select_default_state(dev); pm_runtime_disable(dev); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 80047d0df179..e06d597ee3b0 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -1704,4 +1705,11 @@ static inline void dwc3_ulpi_exit(struct dwc3 *dwc) { } #endif +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND) +extern bool xhci_sideband_check(struct usb_hcd *hcd); +#else +static inline bool xhci_sideband_check(struct usb_hcd *hcd) +{ return false; } +#endif + #endif /* __DRIVERS_USB_DWC3_CORE_H */ diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 6e49ef1908eb..5fdbdf0c7f1a 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -456,6 +456,11 @@ static int xhci_plat_suspend_common(struct device *dev, struct pm_message pmsg) struct xhci_hcd *xhci = hcd_to_xhci(hcd); int ret; + if (pmsg.event == PM_EVENT_SUSPEND && xhci_sideband_check(hcd)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + if (pm_runtime_suspended(dev)) pm_runtime_resume(dev); @@ -499,6 +504,11 @@ static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg) struct xhci_hcd *xhci = hcd_to_xhci(hcd); int ret; + if (pmsg.event == PM_EVENT_RESUME && xhci_sideband_check(hcd)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + if (!device_may_wakeup(dev) && (xhci->quirks & XHCI_SUSPEND_RESUME_CLKS)) { ret = clk_prepare_enable(xhci->clk); if (ret) diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h index 6475130eac4b..432a040c81e5 100644 --- a/drivers/usb/host/xhci-plat.h +++ b/drivers/usb/host/xhci-plat.h @@ -30,4 +30,11 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, void xhci_plat_remove(struct platform_device *dev); extern const struct dev_pm_ops xhci_plat_pm_ops; +#if IS_ENABLED(CONFIG_USB_XHCI_SIDEBAND) +extern bool xhci_sideband_check(struct usb_hcd *hcd); +#else +static inline bool xhci_sideband_check(struct usb_hcd *hcd) +{ return false; } +#endif + #endif /* _XHCI_PLAT_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 2dc651cd3d05..c82b5dbef2d7 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1516,8 +1516,11 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, mutex_lock(&chip->mutex); subs->opened = 0; mutex_unlock(&chip->mutex); + } else { + xhci_sideband_get(uadev[pcm_card_num].sb); } } else { + xhci_sideband_put(uadev[pcm_card_num].sb); info = &uadev[pcm_card_num].info[info_idx]; if (info->data_ep_pipe) { ep = usb_pipe_endpoint(uadev[pcm_card_num].udev,