From nobody Sun Nov 24 09:50:24 2024 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 4FE5438F82 for ; Wed, 6 Nov 2024 08:35:19 +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=1730882120; cv=none; b=OzQlUZjeO9kLXXxoFBPu+fZlE9IQnlKxR75sdApxclmEBCLV5GHj8pHOVyPwfe91kNPbPJMpibuEAkbnLOny4KnZcsBt+iuASG6koF2QxBGokW6SYFDJuGPocvpXPl3B7mwERT6L/X8khvWXfjcAUKQL+wQ02o4EDghIfJ/lyYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730882120; c=relaxed/simple; bh=6quhFQ2ncrTjf4Me/OBMe3GF0xmYkzQjOFwbOPaWC0I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=G2O+baggqujD5yfsOMPp6aiiNA/2LF+FZrxZYfNii7bAVD09fF2YxaAOvzhWLVksVd/QOLetBKNUfdadYpW6fmA7xxLwWWwSsCT3Azp0RB+FfBFcqEQ88V0qJ06WO/vIRIz1CSXykTTqz51IZauwQX3YZyeDL/kdnnaGIhIeEfk= 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=SIUUBIpx; 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="SIUUBIpx" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e29142c79d6so10409595276.3 for ; Wed, 06 Nov 2024 00:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730882118; x=1731486918; 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=IumGmvr31fowXT167MDqh61gubvL7Xj6+sSzWudS0fI=; b=SIUUBIpxEU1QgoqFHps8B4/Ke/8J/e1WwIBPJtyqXg3FZggXJjtYIAC4RMA0p+5/SJ 53si1ypLpPducj41yiPSAuf0FvZCYvuQeVG3DSwLTuK4c55GdjkfWJeyZ2TXpIZZlpyA ITd5RWwKgSi5VAoxB/6P0JmCjKp+pkFZ9IR1V/IWU2IrIIes157H6+vw1eUTojaJCQC1 NE5xwCzdGPKw+Niq/oftZdU000OB3z562/qxWiHK6GSNHb2njnsUT6GS8wr6NvCCzhLP Di+yzRw81lN9ikeul9heYm6gBCSROVNfTcF54Gj2aR8e11E2uRZMijIJAQ2YTdc8wkaq tqCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730882118; x=1731486918; 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=IumGmvr31fowXT167MDqh61gubvL7Xj6+sSzWudS0fI=; b=if488rvubOXG+3V723qkZ4BqehpG4HTI4/UOchCqdR6PDstRzOv2ymz024q7Ezuir2 Ys1GqRMP1JAAriJfVWHoAKFbjyBy7vS2FUu1Swep6p4gVZbIuYLuSMZZCKOPphvCrdyG QYgTZGL8FXlDnEHC5ObxPKOYPMz5YBS46mxwBDstuH7If/gxCZGBLTMQIgPlvZkXI8Xn 0ano77OoUSVFLrJ7ZTpYbPxOLkCn9GFGN+JswC1Xyr260Am2bCOcAEjTV3jjoShRY/PS eugHDDj2SXEvXdt3aM6HGecCXHNzdKzu4xnma86FZEhFKqhJkg7BpAftbW8v0omKBvxd 8YMg== X-Forwarded-Encrypted: i=1; AJvYcCV4Bp2POVwZdUoDk6LX9RR/5m6cDS+Jg/+IApc26Std+CyDi4ph/pIPLA4L65M1x393CYZ7Y6GneiyvjTg=@vger.kernel.org X-Gm-Message-State: AOJu0YxLjpf9fzK9eaBPvq6WGmLvUCspkIvdqkNtDDOXzNFeDeG6EX8r EvXYfYChUDismWUCE02Gzhg2btFZiSj/b++jB6Xy3lDbIKq5jUFKwfXs6/RgdzWPo3C/Sgtyjeg GanlrRtwNCnUHDA== X-Google-Smtp-Source: AGHT+IFB0Awyro0SxbJwsUGskYgR6WNNcfW11Dy1ezhsMBzsh0YK7fbx+j5+Khbflu2XH4qFbZRp+ycq94C4avs= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a05:6902:1d1:b0:e2e:3031:3f0c with SMTP id 3f1490d57ef6-e30e5b0ee45mr15818276.7.1730882117985; Wed, 06 Nov 2024 00:35:17 -0800 (PST) Date: Wed, 6 Nov 2024 08:32:55 +0000 In-Reply-To: <20241106083501.408074-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: <20241106083501.408074-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241106083501.408074-2-guanyulin@google.com> Subject: [PATCH v6 1/5] usb: dwc3: separate dev_pm_ops for each pm_event From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, sumit.garg@linaro.org, dianders@chromium.org, kekrby@gmail.com, oneukum@suse.com, yajun.deng@linux.dev, niko.mauno@vaisala.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, quic_jjohnson@quicinc.com, ricardo@marliere.net 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 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; } =20 +static int dwc3_freeze(struct device *dev) +{ + struct dwc3 *dwc =3D dev_get_drvdata(dev); + int ret; + + ret =3D 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 =3D dev_get_drvdata(dev); + int ret; + + pinctrl_pm_select_default_state(dev); + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + + ret =3D 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 =3D dev_get_drvdata(dev); + int ret; + + ret =3D 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 =3D dev_get_drvdata(dev); + int ret; + + pinctrl_pm_select_default_state(dev); + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + + ret =3D 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 =3D dev_get_drvdata(dev); @@ -2599,7 +2669,12 @@ static void dwc3_complete(struct device *dev) #endif /* CONFIG_PM_SLEEP */ =20 static const struct dev_pm_ops dwc3_dev_pm_ops =3D { - SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) + .suspend =3D pm_sleep_ptr(dwc3_suspend), + .resume =3D pm_sleep_ptr(dwc3_resume), + .freeze =3D pm_sleep_ptr(dwc3_freeze), + .thaw =3D pm_sleep_ptr(dwc3_thaw), + .poweroff =3D pm_sleep_ptr(dwc3_poweroff), + .restore =3D pm_sleep_ptr(dwc3_restore), .complete =3D dwc3_complete, SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume, dwc3_runtime_idle) --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:50:24 2024 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 017331D79A4 for ; Wed, 6 Nov 2024 08:35:25 +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=1730882127; cv=none; b=Lp2IeDREWTsd7kY9IUIc0WcIQm+6kbfLNGM6WFdcZfbIdfDqJBe7MA+Lb53CAvVABl/y/nftF5K5wXjKrjKB8bxTi0KadRwn5zvHdNQIMGEWcw8LmWl4t65ImBuDkV+wVRVqe3Qi3gQfywY7w1iOGK71jMkYkQ8fItk2cRjCfTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730882127; c=relaxed/simple; bh=wSFwOkVM+mO5y/3u8DCOm6hsOTQ9xA6YsY1T5SxSGV4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cMSHw2B7msEdals6jGwD2zgPBY2iUBnGLzPlwtXnVnEJMUhThVsa9QdbXHAqOAzVVUTxZnaHNwmcUdKNEE4TNmpP/OmLJVxMSgiuFHkVC540zejzG5Ah9DwukQlOJWEiDMxKhwDSZ2Bk0DztI5VuWWML39pI5OhSRRhVcHFH+wE= 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=2yvWpNIa; 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="2yvWpNIa" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea90b6ee2fso50641367b3.1 for ; Wed, 06 Nov 2024 00:35:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730882125; x=1731486925; 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=/+9ba5PoLuD4xHrXW8Z318SApTB5yygR7YGjjV9I6Qk=; b=2yvWpNIa4r6SXgrgnTDwU6bnPG2z+zhWpoxZT2n+VEFbLkQ7lzZS4/DJ4QQOZK4Uqm N7lepL6htrPpovClAfgse1g8SMWRV8TIv7FvwwmMoWgA2Sr6UoT+vRPhWCcx2KfEDm3W b+h8phWkPLxoZfByI5uZxax9i2xEyxQDtPjdavix6XyIqBoVcP2hZ0dhbwy02MlG3G9G BMrnc/O/lvy+Xd6D1ThfelAQZu3odgpxIM/9Qu94MnNfq5v868i03faPZ2K00eF9cmYs 9lK0Q5DNWKpBoPqkWKXR/it34HhtXFbcyl+kMhfjiPkfO6FuUKcTS0mDYsAUdvbKZzjH h4Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730882125; x=1731486925; 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=/+9ba5PoLuD4xHrXW8Z318SApTB5yygR7YGjjV9I6Qk=; b=HzzHJcnTFSRw7muzPAYbvGy1m+n3PBgDCZmQ5xUhb5p+P22Mr/ceYioPKHUav+ZbOR EoCAeo215mbM+wHsIaBhIIBWwc+z0HhxMChF6Pw2N88lani/iHL8B4ikmuNmh/9LvDRN ZyWDkfpzrsrRDfCrT5jmD74InVlWcuJXbzLGvGYDdNTWwo8R9xnaG/QFoqCePrR/EhFV ynlW1dQ//LKxTdG6FTZxC+W4sSeP1N6oJBrdH/uSG9FES4frU+tbGDsTMDcSV0sRsKGr qgruKzOiPJQ6dp8vbjZKCiBM1ONislDbfS8as0PoCUHj+qDaBNaiPY/MIfrNFOyTf88c p2vg== X-Forwarded-Encrypted: i=1; AJvYcCX7GX295ZDQF5nLQbgizHiDO5VyEy7u4m+q7Eu/Zl+5kuoGTb+Nx2od6CjGcG0pSWoqzldu0KFANjzhP+g=@vger.kernel.org X-Gm-Message-State: AOJu0YyVYiqr8Esle9QxLjMax7KRA17+WPj64TWc/pteCJkgJZh56kWy VMvJbL7TwigFNMWvP1fp6smXpbbJEBDgwk6fTQDdVqoa2VJ2bFUkan5myp3+4/PSvflIrp1REeN 1DZhd7Y4t4RTi+Q== X-Google-Smtp-Source: AGHT+IFmbWrVFpsQS9VmcdMhtsMdkxe2ajlxASbMTbD3ZoxaYeV/VYnyNEsdPpB7139H2vGMF8BJ8Yv81OBrzPI= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a25:a3e6:0:b0:e30:be64:f7e6 with SMTP id 3f1490d57ef6-e30e5a3cb05mr13136276.3.1730882124935; Wed, 06 Nov 2024 00:35:24 -0800 (PST) Date: Wed, 6 Nov 2024 08:32:56 +0000 In-Reply-To: <20241106083501.408074-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: <20241106083501.408074-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241106083501.408074-3-guanyulin@google.com> Subject: [PATCH v6 2/5] usb: xhci-plat: separate dev_pm_ops for each pm_event From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, sumit.garg@linaro.org, dianders@chromium.org, kekrby@gmail.com, oneukum@suse.com, yajun.deng@linux.dev, niko.mauno@vaisala.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, quic_jjohnson@quicinc.com, ricardo@marliere.net 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 | 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); =20 -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 =3D dev_get_drvdata(dev); struct xhci_hcd *xhci =3D hcd_to_xhci(hcd); @@ -478,6 +478,21 @@ 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, 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 p= msg) { struct usb_hcd *hcd =3D dev_get_drvdata(dev); @@ -524,6 +539,11 @@ static int xhci_plat_resume(struct device *dev) return xhci_plat_resume_common(dev, PMSG_RESUME); } =20 +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(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_poweroff), .restore =3D pm_sleep_ptr(xhci_plat_restore), =20 SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:50:24 2024 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 A31F81D79A4 for ; Wed, 6 Nov 2024 08:35:31 +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=1730882133; cv=none; b=utSiFSPHlsj1MqvkUnSGXHl4zoes4nJYH/GSLZ3mk2iYUcDfIYvWqLXWdgPLV1spDxrhLX35UK4NAr0YfyCx4yOgTOAKfbj7m/7ghbGVGKaSbrP9IJMknLKyV1EvgOgFAyg6bLl/LJMBe4spfR9ADyRGmr/M76DUT8IS5zL2+UE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730882133; c=relaxed/simple; bh=B6p4p3RaVHzkY9djoERKZSs65zORZnN9q0i4fI+uKAA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=I99SIXMOP8rWnqYoTxYzVFMImbtc203Z7Xqde7Om4dXuI6mlBEe6eFBu+hEGKfkDwER1VyQOgZWtuGsbtym1OdlB7Qo3wR1c2n/avVPK5pIBA7zaZlC+515eLXAZxUyW60XPPyvxN8VYNbWtONlc31vrFsi3e/vPwRSZU+XfT5I= 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=oDuXFTYG; 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="oDuXFTYG" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e6101877abso120088797b3.0 for ; Wed, 06 Nov 2024 00:35:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730882131; x=1731486931; 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=wPOkMkTQsSQ3txDdSeNseAkMjkPXkTfXXf/33SK4kew=; b=oDuXFTYGZyCJw1OCBSztC9i5RQu1+d0RQ43jFN8umn3ReOhbBHCf+AGCby7pir59Tp C5kvMcY6frGDQ5xCTgCRd/0SFpI21Oaqzw5o3BvGI1tCG2b91w+Ygi+MC4PLwxG/ECln k/CMkdzlNxoH8bNKhRzdtRLDQxJl+HH1nM588gVBzXdDDgrMPbZugzqWmTTsRGrY6q/o NxeH49PE9tfBbAxaGYMPEu9JGD+SP3K78dekW0QuSBNftGC16JeuNxOWrEziZ/vyw9PG ggsyDq8zStCzZiuwONdbI24sSkrseDfgQb5mMDNDleUzKp0a1/R7SINEExug9H67y6Oy 32yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730882131; x=1731486931; 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=wPOkMkTQsSQ3txDdSeNseAkMjkPXkTfXXf/33SK4kew=; b=l7MGpW++9jGDAX3MY9dr3I/QYelngyNfZL2B0+ZXML9ngB0qaRRB2joklW0iW1Nvk4 Yy1OwhLw3ihMaHRCiIC8zDgqPeZwQdZ8Lu1xvNfnZn1J5TiBv3WwtAOC66RcVwByLnfC mabYWnq1xFfZjmbmsGJq/eaxlR9ZP98cieYhTLtScZ6wjDsdG7UjyifDUvqUx7qG4jnw PI//69xDldomA9z1UqQB9uNX85kokiZ/Zw8FW99BDIc0QeKDU98qF2Ro6ujCwQduqIHW QNoo/I9s3op5zbT3+aQ2nLQnfr6wTNbzyCSjUU32SgxgHIW5mcLfLjHdUWNmY67wnMVS 9UMQ== X-Forwarded-Encrypted: i=1; AJvYcCUMUWf6YRvAhs4kirX9ohZ+rgiEu8h6nkyVx3fBKMiZkYR3cOMQOFlh7zS5IvworVVlavBG4LaB4kpfb+E=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/Mz9qR3vvBz6tm60d6zhPgMKJhB+zFPMdLJ/vn50qBHZFtMMT sBDiZrnU/yS//OtQ1yM1uLrEutO7QRHSPq7MSKbcxDSzDWhng9pirl/p0WC+RbHSgdZZDX1gUdc 5KJAEnhIckDSmiQ== X-Google-Smtp-Source: AGHT+IHtr34MzS7WRAqT8AwaCjq3Bo2uic8Vg2HO0cH4FvuSZP7/upGi0yDH3DAk9HejDb7UKRdpuU69EuEYaUU= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a05:690c:6482:b0:6c1:298e:5a7 with SMTP id 00721157ae682-6ea64bed332mr3616927b3.5.1730882130762; Wed, 06 Nov 2024 00:35:30 -0800 (PST) Date: Wed, 6 Nov 2024 08:32:57 +0000 In-Reply-To: <20241106083501.408074-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: <20241106083501.408074-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241106083501.408074-4-guanyulin@google.com> Subject: [PATCH v6 3/5] usb: add apis for sideband usage tracking From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, sumit.garg@linaro.org, dianders@chromium.org, kekrby@gmail.com, oneukum@suse.com, yajun.deng@linux.dev, niko.mauno@vaisala.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, quic_jjohnson@quicinc.com, ricardo@marliere.net 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 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 | 77 +++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 4 ++ include/linux/usb.h | 20 ++++++++++ 3 files changed, 101 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 0c3f12daac79..e53cb4c267b3 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -2041,6 +2041,83 @@ int usb_disable_usb2_hardware_lpm(struct usb_device = *udev) =20 #endif /* CONFIG_PM */ =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND + +/** + * 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 sideba= nd is + * currently using the 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 sideband activity. + * + * The caller must hold @udev's device lock. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_sideband_get(struct usb_device *udev) +{ + if (udev->state =3D=3D USB_STATE_NOTATTACHED || + udev->state =3D=3D USB_STATE_SUSPENDED) + return -EAGAIN; + + refcount_inc(&udev->sb_usage_count); + + return 0; +} +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_cou= nt of + * a USB device. This information allows the USB driver to adjust its power + * management policy based on sideband activity. + * + * The caller must hold @udev's device lock. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_sideband_put(struct usb_device *udev) +{ + if (udev->state =3D=3D USB_STATE_NOTATTACHED || + udev->state =3D=3D USB_STATE_SUSPENDED) + return -EAGAIN; + + refcount_dec(&udev->sb_usage_count); + + return 0; +} +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. T= his + * information could be used for power management or other forms or resour= ce + * 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); + +#endif /* CONFIG_USB_XHCI_SIDEBAND */ + 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..00bb00d15875 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -672,6 +672,10 @@ struct usb_device *usb_alloc_dev(struct usb_device *pa= rent, dev->lpm_disable_count =3D 1; atomic_set(&dev->urbnum, 0); =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND + refcount_set(&dev->sb_usage_count, 0); +#endif + INIT_LIST_HEAD(&dev->ep0.urb_list); dev->ep0.desc.bLength =3D USB_DT_ENDPOINT_SIZE; dev->ep0.desc.bDescriptorType =3D USB_DT_ENDPOINT; diff --git a/include/linux/usb.h b/include/linux/usb.h index 672d8fc2abdb..c5586532cd12 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 drive= r. + * @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,10 @@ struct usb_device { =20 u16 hub_delay; unsigned use_generic_driver:1; + +#ifdef CONFIG_USB_XHCI_SIDEBAND + refcount_t sb_usage_count; +#endif }; =20 #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, = dev) @@ -837,6 +842,21 @@ static inline void usb_mark_last_busy(struct usb_devic= e *udev) { } #endif =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND +extern int usb_sideband_get(struct usb_device *udev); +extern int usb_sideband_put(struct usb_device *udev); +extern bool usb_sideband_check(struct usb_device *udev); + +#else + +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; } +#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.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:50:24 2024 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 B59331D79A4 for ; Wed, 6 Nov 2024 08:35:37 +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=1730882140; cv=none; b=Z3XrD8gJcMMwkN+h+rxB1vsl/0/0VtcyT9AVybsQHOxVvvJNg+DriSxgh6u0SpEoS9kzczqvB+CY3XtucdsHNi4x61px7dDVNDZpvPdwA5L3LjtQQz5rfUKn0oWVWmFHeSwrPUJaidTQz0l0w8E+ktZ9IW2go14ujNUYqcC0K1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730882140; c=relaxed/simple; bh=JqrI/y417lO2lfXhgkqQF0tA66aDyMukgTr/nW0zek4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dihxBI/3X13LK85PjNZK2JMs6zFO4wbjWgEUbGBXLdL+wbiKy+se/uAVd5e9JYJUCwIpwRrIznftOZRsuYfPEmc633I7OfqnmDoEqmszhA15rpKEPQiXxI2M27EDcOmUN2XhcXFJWkUMIkZ+ZYga4EDFtyLTl6Ga3Y4m6uD87G0= 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=Or3QXsTW; 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="Or3QXsTW" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e35a643200so115692047b3.0 for ; Wed, 06 Nov 2024 00:35:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730882137; x=1731486937; 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=moU1umJAlwIcW6CJtpZmFEP7kB4MQYjSX3i6CUT0ojI=; b=Or3QXsTWeRKEM28x30Ctib6SHqH5QUGcRtVogjyNcMArO9bL+6exmgRTxkCBF835xB 2Xy3yw08Ims3gG8Bx2TVsvmCuefF/LR9fVmHFsJnnzPq6cAyrOvuCUATcP8ktjjq0vfD TbjpDLAfoM/arp6S60/xSXaIJ0y5sULW3RYX3ZKd7WhlzUL4GHUblr91yClv3eRC8p3U +XhOJh93O1VxhrFeLZFzsnq+xw7khjMyR6K06oEDlfl5yPUNiG6OcbEbusercgGhhhOp SvsBAgbQhED4vBVPPB035CySi1fApOPx1Szdg8NnSR16f9aNG53nAsREo54zQAYH6vxP PstA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730882137; x=1731486937; 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=moU1umJAlwIcW6CJtpZmFEP7kB4MQYjSX3i6CUT0ojI=; b=htzk6a8kFf+MsWp/0bp7kdBayYzX9bQll3isyjRgNmb+iTFZbIgudjmapo2GG9tLka cwHTgU5LcGN2kwAvAFWCat0tmJcNN9PHYwQ1nl5jFrKs76GBKzkhD48hjw7oStKlSKae mknDOkwvZJeUhxIcLdBKpmtqgK8Kvc2czGXg/qK92kwK+W4XsKf55GKf5Zc8OQoZ3WF+ o4pU4RJWtIOcZE+Fbz5afj9M9d4LdQ1+BhIk5rXGgKJbYgCZfQfXxHJDlIn3uT1Dg46V xGpzTcYuRYBFxfuj6DN+4GzjX7zNdTZJZKoKkysloYVFl6g3BYIEvaQRWr44kH3ZHa75 INlQ== X-Forwarded-Encrypted: i=1; AJvYcCXb4Z+5F/tEKe7troLsSwoui9wgXlFTqlumvoKjgt+VkuQYIZA2BcIOtrgPXeTPyY9o90J2f6Ec7+JUmKM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywyu66+eu37KbnMp1nQtZnQnt3pHzVCRqmx9TDo4aGMJVLqX65S KAAQVVuzKNd7QTYbSGjPM0YVg2zn0M1Xcc83Ro17LWAJE4sXela+aSITt545yoe8aQjQhlCk+cT r/Y1H9ML16WFN2Q== X-Google-Smtp-Source: AGHT+IFQFnkuCf/v6ladehVoYM1WJRWgfBTSx9mlAsCcKpaQ0AKHa0ncYilNBiCFgL2E3rDcTyqyBpTqWkJJUvQ= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a05:690c:6481:b0:6de:19f:34d7 with SMTP id 00721157ae682-6ea5231763cmr1418007b3.2.1730882136853; Wed, 06 Nov 2024 00:35:36 -0800 (PST) Date: Wed, 6 Nov 2024 08:32:58 +0000 In-Reply-To: <20241106083501.408074-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: <20241106083501.408074-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241106083501.408074-5-guanyulin@google.com> Subject: [PATCH v6 4/5] xhci: sideband: add api to trace sideband usage From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, sumit.garg@linaro.org, dianders@chromium.org, kekrby@gmail.com, oneukum@suse.com, yajun.deng@linux.dev, niko.mauno@vaisala.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, quic_jjohnson@quicinc.com, ricardo@marliere.net 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, 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/core/hcd.c | 4 ++ drivers/usb/host/xhci-sideband.c | 92 +++++++++++++++++++++++++++++++ include/linux/usb/hcd.h | 6 ++ include/linux/usb/xhci-sideband.h | 5 ++ 4 files changed, 107 insertions(+) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 1ff7d901fede..6aca6c69bf74 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2595,6 +2595,10 @@ struct usb_hcd *__usb_create_hcd(const struct hc_dri= ver *driver, INIT_WORK(&hcd->wakeup_work, hcd_resume_work); #endif =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND + refcount_set(&hcd->sb_usage_count, 0); +#endif + INIT_WORK(&hcd->died_work, hcd_died_work); =20 hcd->driver =3D driver; diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideb= and.c index d04cf0af57ae..bd0fc1564052 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -334,6 +334,98 @@ xhci_sideband_interrupter_id(struct xhci_sideband *sb) } EXPORT_SYMBOL_GPL(xhci_sideband_interrupter_id); =20 +/** + * 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 incre= asing + * their sb_usage_count. This allows the corresponding drivers to dynamica= lly + * 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_device *udev; + struct usb_hcd *hcd; + int ret; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd =3D xhci_to_hcd(sb->xhci); + refcount_inc(&hcd->sb_usage_count); + + udev =3D sb->vdev->udev; + + device_lock(&udev->dev); + ret =3D usb_sideband_get(udev); + device_unlock(&udev->dev); + + if (ret) { + refcount_dec(&hcd->sb_usage_count); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_get); + +/** + * xhci_sideband_put - inform related drivers there's a sideband deactivat= ed + * @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_device *udev; + struct usb_hcd *hcd; + int ret; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd =3D xhci_to_hcd(sb->xhci); + refcount_dec(&hcd->sb_usage_count); + + udev =3D sb->vdev->udev; + + device_lock(&udev->dev); + ret =3D usb_sideband_put(udev); + device_unlock(&udev->dev); + + if (ret) { + refcount_inc(&hcd->sb_usage_count); + return ret; + } + + 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 contro= ller + * + * Allow other drivers, such as usb controller driver, to check if there a= re + * any sideband activity on the host controller right now. This information + * could be used for power management or other forms or resource managemen= t. + * + * 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..9867c178d188 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -85,6 +85,12 @@ struct usb_hcd { #ifdef CONFIG_PM struct work_struct wakeup_work; /* for remote wakeup */ #endif + +#ifdef CONFIG_USB_XHCI_SIDEBAND + /* Number of active sideband accessing the host controller. */ + refcount_t sb_usage_count; +#endif + struct work_struct died_work; /* for when the device dies */ =20 /* diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sid= eband.h index f0223c5535e0..4850fc826e00 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -12,6 +12,7 @@ =20 #include #include +#include =20 #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ =20 @@ -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); =20 +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); --=20 2.47.0.199.ga7371fff76-goog From nobody Sun Nov 24 09:50:24 2024 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 E3EF11D6DB7 for ; Wed, 6 Nov 2024 08:35:46 +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=1730882149; cv=none; b=Sirwl+yR7iWpUZdFGBIaRBMQvxmrl7eiZ9B0TwpxSsOZjVa74YjhG/FXB4hArQUU8NpgNYaOO7/w6m8E6rNLYkCaCAgEqsxTg13ylffsjLCOGDtQfs4+NhOXn6JH/4AlNFKp0bqLZ9kf3fjbNkezcVBKAU85g+B8w/aoBaAQiR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730882149; c=relaxed/simple; bh=Dq6sxgb2vTpQq5C2pUSyC8DgdGfKfTQVCyb6mHAbBig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rI0XMc6DseV1DVYFpLxHjFZjs9t9pgpB6wiLawbOOsRAhkWqZ0B0UN6hEnJB9kZausyQUta1KE5rviVD4YvXycbFsxNwRmqwbbSUGHFYuBfb6QJpvp9dBH02AEm7dI0+07aJ1HRLWZSPs9IsIbDgNhkkczQKIQOa0qdKPpJ77MU= 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=dYssTKMN; 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="dYssTKMN" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e0b8fa94718so11345260276.0 for ; Wed, 06 Nov 2024 00:35:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730882146; x=1731486946; 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=cXtRDw3t0JMnNxciD95IZs4DcdHE8C5XutldebSzr3s=; b=dYssTKMNa02wtFSdSD8tddczP7nznbTpgcchp2EqNRcoW5Z+PPSaEVhFmjCiQ7vQ0A gBXCPi1YubAy3EuK+XsfhwTY9If2OmJ39+kZsvXl3eTcU4r0DuxFIhVZGMdiRdK9fp7W xNuGVSToxmSojnHX917rrqUYWkXwPocTMhFPFb2Eu7+U/9labhSPp1u3efxMbNGyhwaA Ztpbb1xnrSl1QyU2zxAsxgygewrIwtvV64jcQrqvqCUHTDtTTQi0KybcqGqLaXGo4vTf xQv1qFgj+nVJ04yC7WUIL/JTns0dZg8KcIUZC2MZPhG2QhlR2olKS7x1rUZkpsvRa67X WokA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730882146; x=1731486946; 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=cXtRDw3t0JMnNxciD95IZs4DcdHE8C5XutldebSzr3s=; b=NBfIcjoSUnCJe5hCUGM9Q3rFLTc2PsKhqJ0Fp3h7fDKf87eWbqlSDrAcD7tSMv5SQO 9GH+vu0JloR6JRDf1sOl5Hv16vzaEps/kBoFsjYv5ydSCI+VkkiEe1yRx74N11R8nQrA pcU/jOzFavf8rZoV8+YuYuXetisR/a7O6LRJXJwxV03SsSVfrNouTTF++sv8+vVVvPJ3 G5Vx9Y+uzYqPYmbxgQilH9uM1TMIREkr23MJ4Iu6A75sTzXAQJDFOmo3x7D4Lui8deYv evUBV2i81kfLqQUNRQn1vvNi6E5+OjFbWucmrwQ1EaUElzmH4T/fOI/hgyzTvZF2dhgC ElLA== X-Forwarded-Encrypted: i=1; AJvYcCU/h5gbH5lVcQI/AbXhTypilUjqi+1htb2WOdE3R/CliJVSNepMUtFx3U87ObRhyFLfWQchGsmtFxGi1yc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz49SSqvKZrbrHtzzr67Zz1W62MfjNt7Tg+HGPH1e0U++YWiAPO TojVWDu1h00ZVcWLrZIQEDCXo+RDaEQ6W1cnYRX9lsWLPUyufFPQqAIwln+zU1t/nWx/Hd8xDCO XDOYA+SiZIUsjhA== X-Google-Smtp-Source: AGHT+IHcYTNQDnMOVwc6fZUnOUACET0zvNk3Da5TLzwhaqVFvPYd+NCLi84JDB/wEYzN4ScXaao6SLAgk0EZhb0= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a5b:308:0:b0:e33:2432:8b75 with SMTP id 3f1490d57ef6-e3324328dedmr19783276.7.1730882145927; Wed, 06 Nov 2024 00:35:45 -0800 (PST) Date: Wed, 6 Nov 2024 08:32:59 +0000 In-Reply-To: <20241106083501.408074-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: <20241106083501.408074-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Message-ID: <20241106083501.408074-6-guanyulin@google.com> Subject: [PATCH v6 5/5] usb: host: enable sideband transfer during system sleep From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, sumit.garg@linaro.org, dianders@chromium.org, kekrby@gmail.com, oneukum@suse.com, yajun.deng@linux.dev, niko.mauno@vaisala.com, christophe.jaillet@wanadoo.fr, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, quic_jjohnson@quicinc.com, ricardo@marliere.net 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. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 10 ++++++++++ drivers/usb/dwc3/core.c | 20 ++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + drivers/usb/host/xhci-plat.c | 10 ++++++++++ include/linux/usb/hcd.h | 7 +++++++ 5 files changed, 48 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index e53cb4c267b3..e5bb26e6c71a 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 =3D to_usb_device(dev); int r; =20 + if (msg.event =3D=3D PM_EVENT_SUSPEND && usb_sideband_check(udev)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + unbind_no_pm_drivers_interfaces(udev); =20 /* 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 =3D to_usb_device(dev); int status; =20 + if (msg.event =3D=3D 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/dwc3/core.c b/drivers/usb/dwc3/core.c index 2fdafbcbe44c..d85c68d5eba4 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2550,8 +2550,18 @@ static int dwc3_runtime_idle(struct device *dev) static int dwc3_suspend(struct device *dev) { struct dwc3 *dwc =3D dev_get_drvdata(dev); + struct platform_device *xhci =3D dwc->xhci; + struct usb_hcd *hcd; int ret; =20 + if (xhci) { + hcd =3D dev_get_drvdata(&xhci->dev); + if (xhci_sideband_check(hcd)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + } + ret =3D dwc3_suspend_common(dwc, PMSG_SUSPEND); if (ret) return ret; @@ -2564,8 +2574,18 @@ static int dwc3_suspend(struct device *dev) static int dwc3_resume(struct device *dev) { struct dwc3 *dwc =3D dev_get_drvdata(dev); + struct platform_device *xhci =3D dwc->xhci; + struct usb_hcd *hcd; int ret; =20 + if (xhci) { + hcd =3D dev_get_drvdata(&xhci->dev); + if (xhci_sideband_check(hcd)) { + dev_dbg(dev, "device accessed via sideband\n"); + return 0; + } + } + pinctrl_pm_select_default_state(dev); =20 pm_runtime_disable(dev); diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 80047d0df179..a585e9d80e59 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include =20 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 =3D hcd_to_xhci(hcd); int ret; =20 + if (pmsg.event =3D=3D 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); =20 @@ -499,6 +504,11 @@ static int xhci_plat_resume_common(struct device *dev,= struct pm_message pmsg) struct xhci_hcd *xhci =3D hcd_to_xhci(hcd); int ret; =20 + if (pmsg.event =3D=3D 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 =3D clk_prepare_enable(xhci->clk); if (ret) diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 9867c178d188..b22d25ccdf7c 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -772,6 +772,13 @@ extern struct rw_semaphore ehci_cf_port_reset_rwsem; #define USB_EHCI_LOADED 2 extern unsigned long usb_hcds_loaded; =20 +#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 /* __KERNEL__ */ =20 #endif /* __USB_CORE_HCD_H */ --=20 2.47.0.199.ga7371fff76-goog