From nobody Wed Nov 27 17:41:18 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 8C8DB161313 for ; Wed, 9 Oct 2024 05:45:27 +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=1728452729; cv=none; b=FtmnXoWB0GLtDKi3AvtS3sjYtlbo5ZEdrt8auJs1bhW8ULG05e6agj25J2+mYyzxso64NppZhIqq86alImFt0LVXpLD4UhS5FmCEfkiqpzY/cpOe0lQju7pM2vnoFPBh+g1BzqWINn9ctDUnJfw/z/+RK1YVBaUCTzXZMIZD1NM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728452729; c=relaxed/simple; bh=jIbnaTHgtuirgsNY3ISWXJAyFgcWfdkjNgjVzXsbgbQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bc781fR8k+7ehKbzsbE5KvYUHzHyifkq29TvGiRduIbec78jx82ybcdiRMKi2DEQZpGtCGw/qQVfDidYjdmLc6bD1BgAMLHRPBatD9vVYncKmuVp9Pm1rKwuUmwatSdo/HSakfIyfY+atsgXqxhz0myD52FUmGqEr6ezzhk2+sk= 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=D4S93nn1; 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="D4S93nn1" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e31e5d1739so13087597b3.1 for ; Tue, 08 Oct 2024 22:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728452726; x=1729057526; 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=oXpWvPQ3Bnbo8Iave6r4WAuwxHNQGna3l+dWKXVRiGs=; b=D4S93nn1hJvti164pjPBATy+uOB5J1c6DCP3+HRKOaORY+3bEx0G1py5NsaNYqIJNL S6O2cTxCTSMYh0oebwGJ7VlPXov0OHUctUKdW5vDFNct9aHd0MFLyE1lvERR2YPdtgNl K4qlDaPHVwXU7Jhpqd0FjcWEvv6Fk0//Of6W0NJmF+QfrOzNS0+HeTiTU4VcLxhpzyg5 CLhNKbxno2y7Muf8ZYRi7eQiIu8rz1ZpQIsbdw9nC5v06AO8gIwdeJ/xKh0Sju7liiSN B629DURzgxTfrdFld8jpF3qzzWkvo0UO56sn/AqYJhBFu1AVHmEA/mvyhkTTa141iSmu qKTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728452726; x=1729057526; 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=oXpWvPQ3Bnbo8Iave6r4WAuwxHNQGna3l+dWKXVRiGs=; b=Kjj4HUwCwNcIy9dLp5A55o0h9ou4NhSAKU7NhI6yYfLG3PLWo/YgLrwuvZ1U7SNiRh tF5BTqCWWjVNfFEY3D0FTbdmPoYy4DCknQT/gwRNkcnkDp/Mu0+ZB3taYT3P7F0acKIM qi6U3TQWX2IGxFsnv4M3wKXKQf/UIvUjTmsW5XGrSWCNEmy18zgrEnhOvvz2xPzKDW53 5Z81UYr/SaSJ1B+hZFTSqEuoIv+PhiD8bGKjaYx5VG4v/TPsRl/f7Koe8g+fn372wzja qfpMoL+4g2Y779nwj5ygk3h1xk8xVR33tNWjCSlSFujXLYixtVci5e4t+p817Q8BTmV2 4ERQ== X-Forwarded-Encrypted: i=1; AJvYcCWQPNeDKtcnxv4Rvj61dSbk6q3uTshbPAzaaYsU6D30CcYacGvV/hllfr1MNIjspmGYYSjtYy6RnYR7rR8=@vger.kernel.org X-Gm-Message-State: AOJu0YzeeRGHxn8h7bWZfPXBWmf4A8ZzrEQtSDyV0fmLx3GeHq8/3iKe Bd7YB68HRVw+4Vgd8WCbdpY6f4skTPzEKIFvhe3BPCeQpu/KGVHCQOxOCUfs5bbEhrqMgIeXc3w eUxcB6aHAAc3VKw== X-Google-Smtp-Source: AGHT+IEZQJLvdxSgG+wQehShtlfb17MEExjWTQ9LAcpQa9gV63RRjMiR64ZdHK5dbdoEiPGh+XtCBQ9/Q4uVKpE= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a25:69c5:0:b0:e28:e6a1:fc53 with SMTP id 3f1490d57ef6-e28fe4bc5f0mr17350276.5.1728452725953; Tue, 08 Oct 2024 22:45:25 -0700 (PDT) Date: Wed, 9 Oct 2024 05:42:55 +0000 In-Reply-To: <20241009054429.3970438-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: <20241009054429.3970438-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009054429.3970438-2-guanyulin@google.com> Subject: [PATCH v4 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, elder@kernel.org, oneukum@suse.com, yajun.deng@linux.dev, dianders@chromium.org, kekrby@gmail.com, perex@perex.cz, tiwai@suse.com, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, quic_jjohnson@quicinc.com, ricardo@marliere.net, grundler@chromium.org, niko.mauno@vaisala.com 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 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.rc0.187.ge670bccf7e-goog From nobody Wed Nov 27 17:41:18 2024 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 70FD536D for ; Wed, 9 Oct 2024 05:45:34 +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=1728452736; cv=none; b=M63mBakkiTTpStI4gMnNKNCtJ6t/dxDjmB3EunOpN76qKd0ZZfXltTDwYsoy30nI+/bUuVsmzWbCTmxpqmU56H4Z88clm+5/ceQ4CyMYXHsdS16vJLH9Mz+hB2Yov0eTM8fJ86ObNjCtWJgXgvzveRVMKBge4Xlxficw72bTjl8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728452736; c=relaxed/simple; bh=6d4o8eIxCt1jU6na9mB3egocnoX2vrJv2Z9X1xsrJ4A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W7cg9lxbG89UFDpexSQEhfb0K3Am4vEtdELVECxEndrFjFMPd5gHiE3BiBsqeF+UPuPRYa7JPqsKAsvAnlRbWjopXmsgDWb/DZnmR5LmtJ3VpcNU6w8r9Ra2ye97G/FxAtNBxuUXFVPK8I8TlpNA+yDsW6SIHuR6JmSnZIEuVY4= 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=PrufRME0; 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="PrufRME0" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e24b43799e9so6152919276.2 for ; Tue, 08 Oct 2024 22:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728452733; x=1729057533; 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=m7OxfjHBVOMntshe6fF8lKjduPpRHJuYOVoMFWNUSlg=; b=PrufRME0h3NXIAZ4rNNVHCyU+AEi/WH4hGhmFfiHZ821siW0dxnQrV1zAIJVWzFzRp hw7LIirHjHBKolCkXTJ2g9by+/QmUE82rHBljEzXSaEMN2z0xb7qZ62COdrgupuX1vfi BKJlcE9mSbx8yY5nBF4n0DfsCi/KQZcXp3bvSunfcZWnAeiVV0/TNxczy1l9p8LZMCUe P0XDsVZsqUjqBKOZgdx+7WBj4lPgJ/FSKd1PCHnWpsDU3TI3jOj9z6tSUGsvBu57du/w qh4WmE5wCcFoztSweDMlm9QldpiJ/64HdckC5hZynQRCiBtHtrkclelbxAhknRPkS6dA EPGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728452733; x=1729057533; 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=m7OxfjHBVOMntshe6fF8lKjduPpRHJuYOVoMFWNUSlg=; b=iEJbmu/6mxsiWTCxjOsiYAYSQluA1CEsri1zm6tVfQgkyqx8GBFnkGHvkKtmHDEi4L 68myFxhu7CFecAkSxCMEwPWHzJax4iwwJuBhIc0SLzeagwu56QTxYYwacYp60frLZcCb Pa3InekHJ5JfauplOGcPUrRx672I4dNH2w11Altb08CzZa7IIrMq3Y04ISdzc0k1diOG 5yam9dlPISIUfVCYJo9JAFKZ2WCfZSWlRuGLLK9I4LorcMzMvzsLjQB53X+4un8bv0kG 4SG36y18DU2ZwzRsjokbrQC7Gqg/MpQwaYxElRkZ872eqavfdYeY5K4u2ruGLFJVMN1O 6Nhg== X-Forwarded-Encrypted: i=1; AJvYcCWUJ5lGp/mxW+MW4hPgqgH8PcL1bIq0OE2agA+Sn5czf5X6hNln4/vwiLpOoldsNAZno8ooMzA5QDIsrmo=@vger.kernel.org X-Gm-Message-State: AOJu0YzYZ5V1m5hYpY1wmyRgOtDeKtVCD5Q1FuE88GnYYTBNUotzjQ3z s5Vu9RI/FfCPFAuHRBdEhrnlypMYdjqNwXDOcFGVGAcGP+C5k81jzXholRlIs05hzu0Z9NP9coC jVa3p++IyhVJjtw== X-Google-Smtp-Source: AGHT+IG0TjVBQAhPlnOaA7uJJP4BFVduzUTOPt4dgJIZVSVEuVbQs2SUr2CTFytM9/dWgOrIB0Aust+Xa594Smg= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a5b:a07:0:b0:e28:ef8f:7423 with SMTP id 3f1490d57ef6-e28fe355de0mr12613276.4.1728452733406; Tue, 08 Oct 2024 22:45:33 -0700 (PDT) Date: Wed, 9 Oct 2024 05:42:56 +0000 In-Reply-To: <20241009054429.3970438-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: <20241009054429.3970438-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009054429.3970438-3-guanyulin@google.com> Subject: [PATCH v4 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, elder@kernel.org, oneukum@suse.com, yajun.deng@linux.dev, dianders@chromium.org, kekrby@gmail.com, perex@perex.cz, tiwai@suse.com, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, quic_jjohnson@quicinc.com, ricardo@marliere.net, grundler@chromium.org, niko.mauno@vaisala.com 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 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.rc0.187.ge670bccf7e-goog From nobody Wed Nov 27 17:41:18 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 0448D17A596 for ; Wed, 9 Oct 2024 05:45:39 +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=1728452741; cv=none; b=lvWqytNjZNt0GxRywT/g6p8V1cUwaYbkBbyF+de1LeqJCB6PS9F2LoOldp+l45PXhcs2GN9fkjBW7JTVDXJ0lnVE9Av7AIo5PlrT3zLHaRppkch4gaucAVRC9++k1/gVFhHh3Ie36PfHFhdeShKoOlfxLJyXe+JlqsEmhTLmDoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728452741; c=relaxed/simple; bh=OEnEasctneyXPSWDbjrh/TEJGBN8UZEjmWt+j/RDpaY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TDSSuT6SqbhmB8azr/3cN8mrS2cjGaH5Jdogw975bAh0oASho1v0Op6j/g5wyS3lPXGgDCmRklJNHxh5IOlvWOsEdrx20DpEhb5wqM2e/6Ij2DF8QwsNCgynkSnEArnJWC941K15QU+poA82yMgVeZTukRzFVViIiw7h0vms7kE= 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=kfPX3Y+k; 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="kfPX3Y+k" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e28eea1074dso2294433276.0 for ; Tue, 08 Oct 2024 22:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728452739; x=1729057539; 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=mFDVI6R/1CwWgc1JLsOCgD08cArkJWhUepOJ8DVmKVE=; b=kfPX3Y+k051ThbiNPK44Pkf+A9Ma8OCusGdbGPBATp8xOQw1WDrkZZcJgEJ+tW93bh nq/0itufOejvvyDOdarodm1ve9+tZxJdNw2NEjFNSX8lQ97JpDdtvJ0/JesIucwqN65m hCIFfpf5JYx5ZmRB/5Vn41YlXZheoybY505kXDUIIFE1E7py9rYWLvZjqkY8Ao/CQp07 DhSfiLBfzmnXwJrZGS+fOy3H/KfFSsRjD7miK7p4AWhxvKBuU03xWUuzfWWj771qV3Ay z0JACP36CYWz0xf3hDhBxG91lJKX8ZPFpmbuArDwEYy9D5LVo4LmM45bQ4hl6FH/DtYj FSWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728452739; x=1729057539; 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=mFDVI6R/1CwWgc1JLsOCgD08cArkJWhUepOJ8DVmKVE=; b=fOgRsNnJ4c1Gxx+sQZnPpj46imlP8HbLsrSSaiVupUuOwZjMjpWUt+YpTB0H+1bSLd HZNGdE9bVzsAZeOJDaaJRMuROrgm8K3wWZENi12e47MhZZwtgA7lNSjdoNCVywIVOx6i JzLVCsW5nwRDOPpoFbFhBRMOU01jxesysl93QzXna0ldcoDWk9VyJvmc3pZjRjn/8cT+ OztEKGfvig9PRw92kD4BsBrClJ14qVwdtT67Nwy0rr1T/d02dam4dKh6mogJLv//gBvr OuY2mm7dRly3BGFxoiu9PrywjzAoBSlTPNknq6ikcHX8wwwpeeUeLEFRNkfh4rCr1bOr CLJg== X-Forwarded-Encrypted: i=1; AJvYcCVOswqg3CEwvxDUDVZhuNFntPT1Gecc0eXyJ5OP4cMOQlfnVLpy43t1WI7Z/nFzCfmd8WAzU1G1BvaAn0s=@vger.kernel.org X-Gm-Message-State: AOJu0YwaBVYvrQWaxOYgfT4nMvP37EPbed7ayoSSh64XLMXkjrw+NWGg sCpkYbhPCNVwqL0Cby7ku6RTqOj+A6PZ32O6JEvhCrixwxrQTI7b0W130A0MGFnrs7uQVrH2Vvx 2/75JytTaQV1l3w== X-Google-Smtp-Source: AGHT+IHTioHUqiDQFl5fHP3gNPgxe0xyIQ/BIR271liuspanypSr44hcwdxzy7cpXnxEhqq2oe/tf2xxRvaVpOk= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a25:6804:0:b0:e25:d596:4847 with SMTP id 3f1490d57ef6-e28fe3e62a8mr23070276.6.1728452738821; Tue, 08 Oct 2024 22:45:38 -0700 (PDT) Date: Wed, 9 Oct 2024 05:42:57 +0000 In-Reply-To: <20241009054429.3970438-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: <20241009054429.3970438-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009054429.3970438-4-guanyulin@google.com> Subject: [PATCH v4 3/5] usb: add apis for sideband uasge tracking From: Guan-Yu Lin To: Thinh.Nguyen@synopsys.com, gregkh@linuxfoundation.org, mathias.nyman@intel.com, stern@rowland.harvard.edu, elder@kernel.org, oneukum@suse.com, yajun.deng@linux.dev, dianders@chromium.org, kekrby@gmail.com, perex@perex.cz, tiwai@suse.com, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, quic_jjohnson@quicinc.com, ricardo@marliere.net, grundler@chromium.org, niko.mauno@vaisala.com 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 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 | 54 +++++++++++++++++++++++++++++++++++++++ include/linux/usb.h | 13 ++++++++++ 2 files changed, 67 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 0c3f12daac79..c1ba5ed15214 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1673,6 +1673,60 @@ void usb_disable_autosuspend(struct usb_device *udev) } EXPORT_SYMBOL_GPL(usb_disable_autosuspend); =20 +/** + * usb_sideband_get - notify usb driver there's a new active sideband + * @udev: the usb_device which has an active sideband + * + * An active sideband indicates that another entity is currently using the= usb + * device. Notify the usb device by increasing the sb_usage_count. This al= lows + * usb driver to adjust power management policy based on sideband activiti= es. + */ +void usb_sideband_get(struct usb_device *udev) +{ + struct usb_device *parent =3D udev; + + do { + atomic_inc(&parent->sb_usage_count); + parent =3D parent->parent; + } while (parent); +} +EXPORT_SYMBOL_GPL(usb_sideband_get); + +/** + * usb_sideband_put - notify usb driver there's a sideband deactivated + * @udev: the usb_device which has a sideband deactivated + * + * The inverse operation of usb_sideband_get, which notifies the usb devic= e by + * decreasing the sb_usage_count. This allows usb driver to adjust power + * management policy based on sideband activities. + */ +void usb_sideband_put(struct usb_device *udev) +{ + struct usb_device *parent =3D udev; + + do { + atomic_dec(&parent->sb_usage_count); + parent =3D parent->parent; + } while (parent); +} +EXPORT_SYMBOL_GPL(usb_sideband_put); + +/** + * usb_sideband_check - check sideband activities on the host controller + * @udev: the usb_device which has a sideband deactivated + * + * 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) +{ + return !!atomic_read(&udev->sb_usage_count); +} +EXPORT_SYMBOL_GPL(usb_sideband_check); + /** * usb_autosuspend_device - delayed autosuspend of a USB device and its in= terfaces * @udev: the usb_device to autosuspend diff --git a/include/linux/usb.h b/include/linux/usb.h index 672d8fc2abdb..5b9fea378960 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,8 @@ struct usb_device { =20 u16 hub_delay; unsigned use_generic_driver:1; + + atomic_t sb_usage_count; }; =20 #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 us= b_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); =20 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_de= vice *udev) static inline int usb_disable_autosuspend(struct usb_device *udev) { return 0; } =20 +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 *int= f) --=20 2.47.0.rc0.187.ge670bccf7e-goog From nobody Wed Nov 27 17:41:18 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 43E721714BF for ; Wed, 9 Oct 2024 05:45:47 +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=1728452749; cv=none; b=bcFNDbinFA+LoAYvtf7Piifon9uEVHUF40hhzOpmH8wOk4AzjDshXS3IhAr3IB+Cb34b5l4Fzd+ZL52HUAkhoAK0aPgqoF6QswfyfdxHn6p8LaeEXMjuF0br+k7vWPOELciWB9D+iSNqjtYkvNCSrR9ZqKCvQBgtfpKUD6tZF1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728452749; c=relaxed/simple; bh=5srtWWWJT0CCdGyZ/SlfbmwGzrK8IAuxzHoQXQJMwaQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HuTQWcUQSzrbG5F+li6btmfXUvamQvrg6kVc9/FAGSafAj+wgWsIDgGIkT+KbP6QUvDmmLy4K5urWdNH53YZAcCz9UVJ8ZdBM/E4OR7+3N56pgUN/2bSwhfxvAmiueTPC41lK0p83inDEjirDu1K437nbOmWxN301i2BnU0I1t4= 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=gWUUntEe; 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="gWUUntEe" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6d9e31e66eeso117399587b3.1 for ; Tue, 08 Oct 2024 22:45:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728452746; x=1729057546; 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=cnffki0NgArvI4HH0Kmw+XKiVaqViNFMJBPYhH1tQ6o=; b=gWUUntEeHDxzVfvhzYDWXpKIIy+6pIXWEjaHz0qQxQJNq/rrXzIRxNvsBugAmsVXQO LPXCt6q1S9ZQYpQ2+SHYbAJTrMQjT+yzbdK/8IuWtDw0KXuvhctRSNbXwLRUEhwmUK4J PIPG7las6Y335RVdueYQFWDQKvTfM1KtWkEBSGjkrYMerzFUAc6El9eLKgadUZg1Rvg7 80ndV/85lRqi8/oykEd/eKl7l5UdjGgZXxAdVNLJxV287ZKphLs83CO4i2pF95WsiWhS WR6seBZf/U25reG8WpXqzOkNjCpgPuwSw6QW9NyU5ZXIkYI7HWyva5WIzBdPV4qNQZJ7 avPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728452746; x=1729057546; 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=cnffki0NgArvI4HH0Kmw+XKiVaqViNFMJBPYhH1tQ6o=; b=nSCoZguWfd9syPNoG8QOece4bAtdQ0ZVS8ioQCowQLcd/pCcIhzWHrgJ5Rwx7o9g6/ PSoDw0dPLza1y5KWNryqg6xLpxtmOXHYnecWg1ILx+BG0pNxs0crZNSIKpW3aAPVgz6h VjoXMOxkZgVbSv/vV5wxoONuppErYpy6eQEoUqjBHC8PhOgrM8LNtuCctvnEYkIBh3FI dwtUA0Rat12ZOSFIWkweWWF1FLPRvHuXikG9yVOVD7aRIwOumH2BXPmMxXlNJDoceqqI z126MaZ9BTJexNHxfyp1/oj6/bwOOy5eJYokjLzHJE4/3cx5BhG0llrXoyWR1A2A9xfU RGMQ== X-Forwarded-Encrypted: i=1; AJvYcCVN6HPPHD9mPThgabjIN4GgsHTEJFbCahalnQEoVVJJ0QFVC156WFjdmMezKhlaaKR3py4tIz/uEZgn7g0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4SW2ufjDlX7h2kv9C3YVPrUZa/MUeHywE+yByu3sCZNFhW6Qd 3EF5AqD5rpUokRKPrFJefKGeuA3p603stARR38d77/XLeoEuV3dcZBCBh2YIvLHA0sbtoJTESMT nfyjrkC+yktGOHw== X-Google-Smtp-Source: AGHT+IFd8anC3e6ZW3A3zIZlr7M2ZlQpEH6kwWvuRjPpLB53MAHkqwJRYm40MrjnnE4YGQBluOFK3HFoGU9Hpfg= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a05:690c:4190:b0:69b:c01:82a5 with SMTP id 00721157ae682-6e3224f4220mr78017b3.7.1728452746125; Tue, 08 Oct 2024 22:45:46 -0700 (PDT) Date: Wed, 9 Oct 2024 05:42:58 +0000 In-Reply-To: <20241009054429.3970438-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: <20241009054429.3970438-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009054429.3970438-5-guanyulin@google.com> Subject: [PATCH v4 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, elder@kernel.org, oneukum@suse.com, yajun.deng@linux.dev, dianders@chromium.org, kekrby@gmail.com, perex@perex.cz, tiwai@suse.com, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, quic_jjohnson@quicinc.com, ricardo@marliere.net, grundler@chromium.org, niko.mauno@vaisala.com 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 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/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-sideb= and.c index d04cf0af57ae..29501e5d020f 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); =20 +/** + * xhci_sideband_get - notify 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. Notify 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_hcd *hcd; + struct usb_device *udev; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd =3D xhci_to_hcd(sb->xhci); + atomic_inc(&hcd->sb_usage_count); + + udev =3D sb->vdev->udev; + usb_sideband_get(udev); + + return 0; +} +EXPORT_SYMBOL_GPL(xhci_sideband_get); + +/** + * xhci_sideband_put - notify related drivers there's a sideband deactivat= ed + * @sb: sideband instance for this usb device + * + * The inverse operation of xhci_sideband_get, which notifies 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 =3D xhci_to_hcd(sb->xhci); + atomic_dec(&hcd->sb_usage_count); + + udev =3D 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 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 !!atomic_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..8b8106b9a31e 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. */ + atomic_t sb_usage_count; +#endif #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.rc0.187.ge670bccf7e-goog From nobody Wed Nov 27 17:41:18 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 D4AF11714C0 for ; Wed, 9 Oct 2024 05:45:55 +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=1728452757; cv=none; b=o8u95oTUuRnQStT2clBxPF5ZzVU00PsfNYC5Awvc5XBkzOp+yMCZKw3FH1YuCNyLLinj6TRdt+u4uJTY7IZBwhr1Ut9zqBwXB8yp9T/xhUatdeQZGssjcAkG0NhV5zPg+KBsuHKCjHlfwgL7nAhibAwMGXFsLXkSfzi0znSyy+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728452757; c=relaxed/simple; bh=7HdoGuIpVxIApwBZjbGWPc3lYhLTnwpC2A1CyC1PnpE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fHTZZt917JReVrjp/cci1KjdnWgGX8P/dUQoG0KZRlRo8Zi9Ml3GP8wFYEIKAFkz9HfCzOkRp4B7fqME/U8pd6E4Q8O+iDTT/LthH1oHEfk7LOodqEsTOImhkbNqMTqwan2DCGx0GloEQ4DSAgV5qqtHDT+6p6ZOyNki1suqqMU= 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=BzPZNA0V; 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="BzPZNA0V" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e23ee3110fso118831637b3.1 for ; Tue, 08 Oct 2024 22:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728452755; x=1729057555; 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=LS06mvVrFt6iBWJCEDFo5gcybGkFQKBBqdvmqbXJwpc=; b=BzPZNA0VSMSLROIZersAJ6lOS0zfvteDQlm7dHe61hMXzPNDuioZzddwHF4qN09vjK 9/vhuVBvV9soN1oeJb4db3dVDBBoXxijx/JE4kk+Ialrm4VCu7w3XxtSXC7IqKN9LGZF 9l+/quvg3u9iJ+TX/fZZpo4NvoFmRJgMn112mNkcg4B0RoqwaeH5tZpPpjeuTwDrPp6p CWbIa2DN0b3sDhbeNF8qJr/ygiemqRUaynMtSthiN3EAAnMC5iRZ/WxKOxBjc3Ajt9SN 1QIv8xYXXptCV6KgjIZ7RAhSSOC304G8WhlWhdFqqcUeaHbxHuV9musv06J/TPAjr/g8 dAZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728452755; x=1729057555; 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=LS06mvVrFt6iBWJCEDFo5gcybGkFQKBBqdvmqbXJwpc=; b=afNR0OOhvBSnjRUH8L7Jeop2Q0igmxxsvKCYiqtJvzR3oAxlMSorfcW69dauRXAH0C CDEOF5n7gu9FNr9rqasTgdtzRLDCnYFnBLirMmU9ra13EC/qO4W/RJ2v1yQxx9dqLXRM d0/BXWkKzQdF5GByUCPSApHRrc+1UHQlIFfB9tuLi7VhRWe2SI/WF7o1Qv5W5IpTEiuM zxr656L5Q8VgJcAYcWaDmjfbiFVmbk6GyBF7yif5a0gMi7wy6qJ5D+Z/3JB0N9bkOQHz 8ut81XyJwV/2RtsDj56qMf6eriW8oVnn8KPI5Jrfc5lDPL+FZnCF71a9bxc6t+20lN2a GJng== X-Forwarded-Encrypted: i=1; AJvYcCVVdnlE1QqWT5WTcQqFryivqQb3BP7gj1WtVRFcJUGL5vhhhvxgmOZVWelJmitxh/O+kHXl2/hiuuql1fg=@vger.kernel.org X-Gm-Message-State: AOJu0YxD3x48rDxAhPI01KM6luRtQER7XdSy85Ezyiax2bqlYInTk7BY kZKEM+aBDop8EvVhbK7bHsOGAJeSO5U9EcqDC0ZKza33QVhThJsvlodQJME9PTqg3ZXkXrM43F3 OiP//ddtJ8Y3/7A== X-Google-Smtp-Source: AGHT+IFmkWe5tDIFIeZ1czp1l1p3rAeg8htxrsKU7F9YBCSNh/yAgAeAVRTulxMkSVrE0E5lAU+yh0O4nmn/cTg= X-Received: from guanyulin.c.googlers.com ([fda3:e722:ac3:cc00:131:cd17:ac11:19c7]) (user=guanyulin job=sendgmr) by 2002:a05:690c:2a82:b0:6a9:3d52:79e9 with SMTP id 00721157ae682-6e322150753mr186647b3.4.1728452754886; Tue, 08 Oct 2024 22:45:54 -0700 (PDT) Date: Wed, 9 Oct 2024 05:42:59 +0000 In-Reply-To: <20241009054429.3970438-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: <20241009054429.3970438-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241009054429.3970438-6-guanyulin@google.com> Subject: [PATCH v4 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, elder@kernel.org, oneukum@suse.com, yajun.deng@linux.dev, dianders@chromium.org, kekrby@gmail.com, perex@perex.cz, tiwai@suse.com, tj@kernel.org, stanley_chang@realtek.com, andreyknvl@gmail.com, christophe.jaillet@wanadoo.fr, quic_jjohnson@quicinc.com, ricardo@marliere.net, grundler@chromium.org, niko.mauno@vaisala.com 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 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/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 c1ba5ed15214..83726bf88fb6 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_info(dev, "device active, skip %s", __func__); + 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_info(dev, "device active, skip %s", __func__); + 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..a41f1fa425bd 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_driv= er *driver, timer_setup(&hcd->rh_timer, rh_timer_func, 0); #ifdef CONFIG_PM INIT_WORK(&hcd->wakeup_work, hcd_resume_work); + atomic_set(&hcd->sb_usage_count, 0); #endif =20 INIT_WORK(&hcd->died_work, hcd_died_work); diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c index 0b4685aad2d5..69fbbc6f865f 100644 --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -671,6 +671,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *par= ent, dev->state =3D USB_STATE_ATTACHED; dev->lpm_disable_count =3D 1; atomic_set(&dev->urbnum, 0); + atomic_set(&dev->sb_usage_count, 0); =20 INIT_LIST_HEAD(&dev->ep0.urb_list); dev->ep0.desc.bLength =3D USB_DT_ENDPOINT_SIZE; diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 2fdafbcbe44c..d1ad817ff564 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 =3D dev_get_drvdata(dev); + struct platform_device *xhci =3D dwc->xhci; int ret; =20 + if (xhci && xhci_sideband_check(xhci->dev.driver_data)) { + dev_info(dev, "device active, skip %s", __func__); + return 0; + } + + ret =3D 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 =3D dev_get_drvdata(dev); + struct platform_device *xhci =3D dwc->xhci; int ret; =20 + if (xhci && xhci_sideband_check(xhci->dev.driver_data)) { + dev_info(dev, "device active, skip %s", __func__); + 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..e06d597ee3b0 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include =20 @@ -1704,4 +1705,11 @@ static inline void dwc3_ulpi_exit(struct dwc3 *dwc) { } #endif =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 /* __DRIVERS_USB_DWC3_CORE_H */ diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 6e49ef1908eb..b730320df70d 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_info(dev, "device active, skip %s", __func__); + 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_info(dev, "device active, skip %s", __func__); + 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/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; =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 /* _XHCI_PLAT_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_of= fload.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_hand= le *handle, mutex_lock(&chip->mutex); subs->opened =3D 0; mutex_unlock(&chip->mutex); + } else { + xhci_sideband_get(uadev[pcm_card_num].sb); } } else { + xhci_sideband_put(uadev[pcm_card_num].sb); info =3D &uadev[pcm_card_num].info[info_idx]; if (info->data_ep_pipe) { ep =3D usb_pipe_endpoint(uadev[pcm_card_num].udev, --=20 2.47.0.rc0.187.ge670bccf7e-goog