From nobody Wed Feb 5 21:54:36 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC62B15B984 for ; Fri, 17 Jan 2025 14:52:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125567; cv=none; b=flYbikN9Uv/sMjoW/QuChuPMvtVx9egVvoUPa38pjJACGf0uxHvB6Qo+S/3g+RMqj8XytfsUKcbYtuKeYk0wANMBMvQP2MUTqzmHv94UipUcvMSLJWavwcxJKAAYJqALhBZnY4ZuHPC9enWpNSGD23pUsXUj5IIixFp3Ql698Cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125567; c=relaxed/simple; bh=FNJJD9zaL9tYqwWTeIV7vxHf0s0Y2Sf04iiJXfVPKQo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BHEF+9mMouX/WaPz9SknNgTlJdlfszo3+EuQ7rxshjLIBDZS+YebbjJvu2yW6MpPoSDD+8ECOJ1GARlecQ2njSKR3RCg8k62odVcTciCeGYAmze9UwlXV/kBwTDNnnRD3VzwDShgsN8bTjUtsSN1tK2lkPkfnOZKINKQB5mdceo= 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=OFrJ+Ltf; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OFrJ+Ltf" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-21631cbf87dso43793525ad.3 for ; Fri, 17 Jan 2025 06:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737125565; x=1737730365; 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=LBcwJTu+fcJiwVaAq8fITjD7AnDF8kvfA86ysnCa1q4=; b=OFrJ+LtfTzgZrjtMaAVZclJCBsi3EsDrrXojY+L5nFlKrIuDJ6spu8eCWkUN8DhNqH kN7wWRGi4qYCRkaUiNBY3kHcOxW1snohWrXcckWU32X63kakAd5zWR5sbSrfFQfFBqPA e8s2gWvUgFoEotnxX+DolR6hB1vV1Xuz65dhGFDMzr4pqaF4H7gFJTb/8LVhGcnmTyKy WhIhCaqbLbFbYfFKaocbibIFwIHnwqLJZ8NtLa2oq/lOcA6KUIO5j6NgJhnPo2a8Tepn lzp18wSrqre3RzswG0VBYC0N7PEfdGOrB/yzHgaz/TIKNaeJMVuNk55UV4IMVUPx9GiY AzcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737125565; x=1737730365; 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=LBcwJTu+fcJiwVaAq8fITjD7AnDF8kvfA86ysnCa1q4=; b=RVmgUGU4UqVmgdX/OV/js42oZzZUK6TN4Dl1WFhIDFDKpkQy1eMH19AoJj9WZcfDJM kmvc+wY8h0cun1wrgKVWO2qV6WvCUkblh1XNZicnAztkSXuJbcIbxhJI+LCh1QACBT0r HPV+VFOUSqUwsXeiaXpKo+kMTbucSg6kKWUlJVXbYEViX++Gf04ksQgZxepPBg/NV0Hk 1odGEkIa4J+81Tnq+ohSwT470FFRg5fuhy4UYOmvHSn1GQkqPW1ioqEgcO2EEkv15+iw BPq1GTXs2Sz8wBdHB7KANYFWV3fb7QBxvyGCmyowaDkOjOCsPdWcEShpaYGon0moIKYq peYQ== X-Forwarded-Encrypted: i=1; AJvYcCUBwXgNMQWZ5BvPaEOxctUnRiQMtxMtHblsY/9UHXyKdvjQckERQpHZYDUnC33XbK6G5ysZhn7OtBum5Nw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+WNIFQxL4WGTY2VWTt0oEGUP01CQwIjlieq140vrjl513WRc4 4zWKy3YHUmIQl9GQu2KsYnAVi3eqXwjb/YCWTO3/9DwD6XCnYL9cFu/597c7lpKWVMEqHFlRXKB ZoRPMCam4jNf9HA== X-Google-Smtp-Source: AGHT+IEoQgeczoM7fP36NuD2loQcNHOykfJKRvojEFPOft+QuArtSr1uer2ouUY/qHidSyvb/ZEyaw9Woj6DI6A= X-Received: from plu4.prod.google.com ([2002:a17:903:3684:b0:216:6463:1a1f]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:11c3:b0:215:af12:b61a with SMTP id d9443c01a7336-21c35629a68mr39854665ad.50.1737125565203; Fri, 17 Jan 2025 06:52:45 -0800 (PST) Date: Fri, 17 Jan 2025 14:48:01 +0000 In-Reply-To: <20250117145145.3093352-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: <20250117145145.3093352-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117145145.3093352-2-guanyulin@google.com> Subject: [PATCH v9 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, perex@perex.cz, tiwai@suse.com, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, ricardo@marliere.net, lijiayi@kylinos.cn, quic_jjohnson@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@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 6c960ff30c92..0735881d4650 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2632,6 +2632,76 @@ static int dwc3_resume(struct device *dev) return ret; } =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); @@ -2649,7 +2719,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, =20 /* --=20 2.48.0.rc2.279.g1de40edade-goog From nobody Wed Feb 5 21:54:36 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84CD718A6BD for ; Fri, 17 Jan 2025 14:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125576; cv=none; b=h2pZy7xU1bu+mz5RJe9DmHXRZJ5OfMqKknCAcIf7Etc4cwI7AIxGaR5HheL5TMq2FKbJa+69BgJQDkMY6B6tW77YvrhoxmdeIwJWGR9gyb5p9Pgk5dWoWbSXEg9JMTSClHtauWO/Yf8raw4wb97HMxQ3o1UjVXqkPu7KByzg3uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125576; c=relaxed/simple; bh=0NycYGu5HX5HIzAcJbBdr0cNDobK1Lk+gWnlktNiraE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MArJKIvURFuvIz7zUQ9cbkCOkVEcOuJMa4xu8GYIC00y3ygb69puBuEg7ThKOB2Rcr1Uuv390MXGnwNzSwnfyce+j9UHCLgY3VPifm8DKEij8t/zPS5CXe0/m3TD2t0urmuqRXPwJK9tfptGnyXsE39WgXgYg40+uuo8ZvF4Hik= 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=sB/QKbVX; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sB/QKbVX" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2efa74481fdso4162554a91.1 for ; Fri, 17 Jan 2025 06:52:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737125574; x=1737730374; 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=RCJkWTokxKqqVc3PnxwU+b4mjlCy0+MI0S9WquV+jXU=; b=sB/QKbVXk4qjJwAcUE2Vvh0eYv1aYM8FriI5YVyUjTdlCBccJ1t0eB5buSl1fp+fnB 8rzvQnjm/zYenJ/a4TzeHB5Ml6pNGZ7CMdPJp59zOIRRv/8HATZ9SRo4cd2kAj10AtK2 7TIi4UT1DNlfkUV7krUg7X/M01lwWUliuHyjIa8XVUMMdHEi4kzzCTFOFLFnfchYxEfr fvulf9okjcvpyAJmo9tlDtUFJh6jNpDZIMwRFHeG0B0A1K+vru66XXhjywsBQ2Nxw556 Q+LrCCMxHn+7RgUOHQwyy6PNUlN1Epn5x4SXuIal0vQuwic6MLO0zGikqdwpwS1f+ISx k44Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737125574; x=1737730374; 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=RCJkWTokxKqqVc3PnxwU+b4mjlCy0+MI0S9WquV+jXU=; b=V2dRM4A3iEVcdlsDeuA8xD1VV1kE1gqVz44OzGIOXn/5G1uLQoOw4kIj96/1RWchMP XWUEfT1/4Ny2ROB5M7djNUFnJ9OUYy5r0nabjkgP0XGelVJcFnXk0lWA+1TcP5dyRIDI oS8p2/BXWKRac5kJfM9+lKhM5/GtXztigO6yLW0BOg5YQpuwuQZtounYiaCIcEaqDf7M HbFm5YFo56OTaVNm862KQkrY/+GxObuBGQRzKGjnnx/5Lj3heCSANaBrjB6QLb3sVSVu obZFZZ7KKjQcdnTitSVjMM+OE8yi176NoMljJu20qKsFPGS/njBNTEkkHyG7AohEkcqr 2OBg== X-Forwarded-Encrypted: i=1; AJvYcCW7KclOMzRQLWptwxwBl5xCHMHzxuK8UH5iXIKvTzPz3LTp3te3AdNaZWA5jh6J1VJZLJOUgU/JjhMrF8E=@vger.kernel.org X-Gm-Message-State: AOJu0YzgDz0xtf0tGPilvOIKbSu06eemHSlMdEU4Yxw+dsIquo65vhKD hLb9IwPvvhnGS0V26rGtv/Dc2tvnsFZdVtyvYuir6VhyiTYPz0yxoqeRWv/gPbWnC9J/56Vc3Ed sKYxko419DXv8ig== X-Google-Smtp-Source: AGHT+IFuJ5ng71y+Dmn+KpRUE/OoajnStDmKGLDO/wmhPEz4Oiiu3kTjumYtiZyjjRbDNDd1+9iHmhUypVehviU= X-Received: from pjwx14.prod.google.com ([2002:a17:90a:c2ce:b0:2ef:d283:5089]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2c84:b0:2ee:9a82:5a93 with SMTP id 98e67ed59e1d1-2f782c94021mr4783109a91.14.1737125573912; Fri, 17 Jan 2025 06:52:53 -0800 (PST) Date: Fri, 17 Jan 2025 14:48:02 +0000 In-Reply-To: <20250117145145.3093352-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: <20250117145145.3093352-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117145145.3093352-3-guanyulin@google.com> Subject: [PATCH v9 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, perex@perex.cz, tiwai@suse.com, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, ricardo@marliere.net, lijiayi@kylinos.cn, quic_jjohnson@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@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 3acdbbd9aea3..b676d4dbcec1 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.48.0.rc2.279.g1de40edade-goog From nobody Wed Feb 5 21:54:36 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36D26192D76 for ; Fri, 17 Jan 2025 14:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125584; cv=none; b=KFLG6MNUTQ1C0nG8QwBRqTUdcrb8uGEUOUALWRYmaT+PejSX2tVJhAb7HVmOhiI5OwPHhMcEtpVFOvjWE+ZUOoK2QjMbu7pRYKYe2pN40IIHpfKbDclAotLQZMgopNEydK19ec1JHcSsWi6C7KrnN/n0QhMStJrcKEeG8/IfrWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125584; c=relaxed/simple; bh=iHbXpApZXMdoYmO22LcNZiKWepotlBPXNi3hKmTmmTQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MlPiJonbu0SJprZF1/JRGVJUQ++SPcXgXO/xApJwoDljyBjF+c5vNWlOIBwAibG3g36NB/407+hbB4MaKGwjf8npovuapExNhoHz9mazIFEXHglKYOzNlp9bX0Bt+BA2EXKoDnGfChwvSffmZUPF+pPyg1IzPYfCT7leJKdxAIM= 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=k6D7UWPr; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="k6D7UWPr" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2f2a9f056a8so4308115a91.2 for ; Fri, 17 Jan 2025 06:53:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737125582; x=1737730382; 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=frSvqT6dyBKNEvGXV8Wp1l7540diAFryFwfnWgvRajk=; b=k6D7UWPrWDNCOwTIwnWlfQaQdOh4J7hJn+h8gv4ohAUQRHSbSz/IC7MP2RmNYmOxIf XvwK5PlstP1IwVrzWJAWVP9EIqq43P0CU+PgKksF56O5qUycrMpkHjXcw0Pua6lOUCjB q4NGQHgU5CoEFrhOJc6CeqkbVaKpewF0vX5IhLdzUE6rpzY7LYHetJCf0kqo6LP4gOXd 3Z8rsWxKb/cKOeUhectEZAGrED9D7ZljF9xDf60lWyMo2MQ8kr4oPt/zqc0YW0XU6Zfj XMnlbA8rtnr2LU347m3tR0B+Rq8mcZpBqOxNL8dYs5w4pWiOO2w0troGUGsE3Jp8me68 z6mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737125582; x=1737730382; 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=frSvqT6dyBKNEvGXV8Wp1l7540diAFryFwfnWgvRajk=; b=pX+anvGly1DRajVa4Cc92qrDLbEdpin7RVbT0WLvyuXsK5X859/sXuGcpjB6LpMdFe m6+VCyHu+WswPAahqnDfoBXt4DKN9xYaWU/txlADrDatydvE/bx5AS9mi1VvsWUn445t o0ACqhKX+XfiGkAhKEnEYgynG6WwfYmju3fsDLktqVIH1JuJjTgpFzdwyRGvnlLjHXU0 4kI6r98RgFGwLHo/H8QjsBIn9yeTFQuvegI/y9QsrbdRzqFBzFMoE6p9QW2UQ2FxwmPh HooOBoBIGXapjRISPG/sfJelunRsdZrV/ZfAK6xkQxvoLhWNO3QOLn3oa0hdlGFCazRh STiA== X-Forwarded-Encrypted: i=1; AJvYcCWdRffdLd3HesK5Z8re6pbj9kIHm79OSSG6A6+zcZxdBcJXTPcn4td6989gjTxT71xDt7WwQZ7e1FykCLg=@vger.kernel.org X-Gm-Message-State: AOJu0YzQkzLj2crPlt3gxukf31qg19eRASlUg4ewg8W6TsGImeKCup1S yzlQ28i5hZ4rQG2hKK1hRjp1DEbE1ZTDG8rs7oLMVZln18GU2BSLfxWH02vxBrcXiRg6RGFBj2O QLzub5bNkKwP57w== X-Google-Smtp-Source: AGHT+IF55fT+MIQRNgHb5FBEpqG+tB9zVOthP5UrALOkQrxjIkT0YPsd0Q/19oxIvzGCDSGgyzh9KIWvk9sQ9GY= X-Received: from pfvb5.prod.google.com ([2002:a05:6a00:cc5:b0:72a:bcc3:4c9a]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:148e:b0:725:db34:6a7d with SMTP id d2e1a72fcca58-72dafbe9ca8mr4994052b3a.23.1737125582491; Fri, 17 Jan 2025 06:53:02 -0800 (PST) Date: Fri, 17 Jan 2025 14:48:03 +0000 In-Reply-To: <20250117145145.3093352-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: <20250117145145.3093352-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117145145.3093352-4-guanyulin@google.com> Subject: [PATCH v9 3/5] usb: add apis for offload usage tracking From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, perex@perex.cz, tiwai@suse.com, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, ricardo@marliere.net, lijiayi@kylinos.cn, quic_jjohnson@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, Guan-Yu Lin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce offload_usage and corresponding apis to track offload usage on each USB device. Offload denotes that there is another co-processor accessing the USB device via the same USB host controller. To optimize power usage, it's essential to monitor whether the USB device is actively used by other co-processor. This information is vital when determining if a USB device can be safely suspended during system power state transitions. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 108 ++++++++++++++++++++++++++++++++++++++ drivers/usb/core/usb.c | 4 ++ include/linux/usb.h | 19 +++++++ 3 files changed, 131 insertions(+) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index f203fdbfb6f6..1bbf9592724f 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -2037,6 +2037,114 @@ int usb_disable_usb2_hardware_lpm(struct usb_device= *udev) =20 #endif /* CONFIG_PM */ =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND + +/** + * usb_offload_get - increment the offload_usage of a USB device + * @udev: the USB device to increment its offload_usage + * + * Incrementing the offload_usage of a usb_device indicates that offload is + * enabled on this usb_device; that is, another entity is actively handlin= g USB + * transfers. This information allows the USB driver to adjust its power + * management policy based on offload activity. + * + * The caller must hold @udev's device lock. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_offload_get(struct usb_device *udev) +{ + int ret; + + if (udev->state =3D=3D USB_STATE_NOTATTACHED || + udev->state =3D=3D USB_STATE_SUSPENDED) + return -EAGAIN; + + /* + * offload_usage could only be modified when the device is active, since + * it will alter the suspend flow of the device. + */ + ret =3D pm_runtime_resume_and_get(&udev->dev); + + if (ret < 0) + return ret; + + refcount_inc(&udev->offload_usage); + pm_runtime_put_sync(&udev->dev); + + return 0; +} +EXPORT_SYMBOL_GPL(usb_offload_get); + +/** + * usb_offload_put - drop the offload_usage of a USB device + * @udev: the USB device to drop its offload_usage + * + * The inverse operation of usb_offload_get, which drops the offload_usage= of + * a USB device. This information allows the USB driver to adjust its power + * management policy based on offload activity. + * + * The caller must hold @udev's device lock. + * + * Return: 0 on success. A negative error code otherwise. + */ +int usb_offload_put(struct usb_device *udev) +{ + int ret; + + if (udev->state =3D=3D USB_STATE_NOTATTACHED || + udev->state =3D=3D USB_STATE_SUSPENDED) + return -EAGAIN; + + /* + * offload_usage could only be modified when the device is active, since + * it will alter the suspend flow of the device. + */ + ret =3D pm_runtime_resume_and_get(&udev->dev); + + if (ret < 0) + return ret; + + /* Drop the count when it wasn't 0, ignore the operation otherwise. */ + ret =3D refcount_add_not_zero(-1, &udev->offload_usage); + pm_runtime_put_sync(&udev->dev); + + return 0; +} +EXPORT_SYMBOL_GPL(usb_offload_put); + +/** + * usb_offload_check - check offload activities on a USB device + * @udev: the USB device to check its offload activity. + * + * Check if there are any offload activity on the USB device right now. Th= is + * information could be used for power management or other forms of resour= ce + * management. + * + * The caller must hold @udev's device lock. + * + * Returns true on any offload activity, false otherwise. + */ +bool usb_offload_check(struct usb_device *udev) +{ + struct usb_device *child; + bool active; + int port1; + + usb_hub_for_each_child(udev, port1, child) { + device_lock(&child->dev); + active =3D usb_offload_check(child); + device_unlock(&child->dev); + if (active) + return true; + } + + return !!refcount_read(&udev->offload_usage); +} +EXPORT_SYMBOL_GPL(usb_offload_check); + +#endif /* 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..888ab599fd06 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->offload_usage, 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 cfa8005e24f9..9b3f630e763e 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. + * @offload_usage: number of offload activities happening on this usb devi= ce. * * 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 offload_usage; +#endif }; =20 #define to_usb_device(__dev) container_of_const(__dev, struct usb_device, = dev) @@ -837,6 +842,20 @@ static inline void usb_mark_last_busy(struct usb_devic= e *udev) { } #endif =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND +extern int usb_offload_get(struct usb_device *udev); +extern int usb_offload_put(struct usb_device *udev); +extern bool usb_offload_check(struct usb_device *udev); +#else + +static inline int usb_offload_get(struct usb_device *udev) +{ return 0; } +static inline int usb_offload_put(struct usb_device *udev) +{ return 0; } +static inline bool usb_offload_check(struct usb_device *udev) +{ return false; } +#endif + extern int usb_disable_lpm(struct usb_device *udev); extern void usb_enable_lpm(struct usb_device *udev); /* Same as above, but these functions lock/unlock the bandwidth_mutex. */ --=20 2.48.0.rc2.279.g1de40edade-goog From nobody Wed Feb 5 21:54:36 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2ED7194C75 for ; Fri, 17 Jan 2025 14:53:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125592; cv=none; b=CFj4J4JS6cn1H/TeyihgPKT73190sP7nNo8Ck+bYK3VLJM1DL7PEzO21OO2nb2BxSL9Vi1Oqx/FmaAZPba2SCOIcEnq3MCznGC4iLz8J5fj+7+iyJ8gnpQ6z/qKL6VIypL8SCuV8UPnqhgVLf8iMsaEQYBQct3+o7HecYCcnO78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125592; c=relaxed/simple; bh=44d/KNFe8ozkeaq7IQ5Sv9h6dT0hWOgYDawnmRWXc0k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CzTLHZCtLMf8S4D5dazx6gJlWEw9ChX85Q7z+XscEWr7KMUrQMZG2UtyV7XLa7PTvttJN23hPB/CLZhYJOrjsV8Mx8Nu0t8RyeJ2AUpzrrCzs/XPfX7zfRXpWVAw9eg5H72kDgEKgBv27XjrqNjDE07+k/T0a93lwRqjk3B5lEw= 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=u3b3+Pr2; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="u3b3+Pr2" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ee6dccd3c9so4092565a91.3 for ; Fri, 17 Jan 2025 06:53:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737125590; x=1737730390; 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=NYrUzWw505HeBsvBgwJ+7hL3A+NEhIeuEpkKA+DPI1o=; b=u3b3+Pr2ZTQUAs7YPDSpICjdj3S2TuLh6h/zraNvmpohA7BmiwRxi03ck7QJkb1YZY 87rAEoICUDWIU5Eg4mUoaCgyFIzfTAbmdELACG1EFeZ4kDvjs6ftLqQfeG5+GbWJVpqc +SFK4UXpVpKH9P/WwyQi8kH6sKVEdYcN0wzz4PSUj/pQcZFMHtmfXzL76yUBeNLHYp8/ ExU6bJXEqcat+1UXDQ3sBp9IsSNOa0ghu0zAQ+FPo7P2lgL6NdFQeHyonEw1rqbkqlK1 l1q8AoJgMZH4IWes1LaMMe8OZ5FixQ1MHim8c/jvP1OgIAbuUhvJJ1UcE3652Q0fLlq3 Eqyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737125590; x=1737730390; 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=NYrUzWw505HeBsvBgwJ+7hL3A+NEhIeuEpkKA+DPI1o=; b=RpENXRQM0tvE6/UGAXxXJPRLvOAg3fh065EN10gVQc3nPrD5dxJ1JePSNw1IpjZ6Hm D5wIuyKvWJ1i1kWefnFDc0Q5MXJ/2mt3RgKZ254qLz0JPzmTu5ldCRJk+N5Ef1Cjy2cY XtcXU3B0Hr1lKUIn7Bv0mrWeFmbMUeMPtwnu5ahnonni13SnWCYyH8dI/RivJYDCukow 9wrLE47Y954iTK11V7aQ16euRwb4jX22wwGeVNtWS76F9pWpZCy9BeM7Eww0kuFrj3vg xU/piPc2X8rqJUjHr6QXkk9lmsvzXsPA0OIQOP4IVql01dJ5HOqWg7UHtIsxTHWvinZQ 9ndQ== X-Forwarded-Encrypted: i=1; AJvYcCWiWzbTOOg8HY3CCs7NZQ9r8Mcqdtrf8jI4sOw7OBfQ9T5dqLzx87CHMuO/V96H0sZrpgIPQqZjMrv9Skw=@vger.kernel.org X-Gm-Message-State: AOJu0YyHiE9dc8Sw6s8ZMGHG0HFwlbK/+T8oGvu+QB5cIS9NnbMk6kS7 kSjwgbsm3rRprwcx6oGX3KY5O/tYk1/ohJtk3c04nXOI9WSQ4QWCBWpuzUBck3/eIESslxd8Vjs wO9uS0ge51ZStog== X-Google-Smtp-Source: AGHT+IFt+bRNV23OgMCgSntbifLFt0TVJJs9kgJ82JMJ1FwsFDPqFHRvqkDif03QQ9NgDHVTiNXi5XUv9Wd/pcM= X-Received: from pjz16.prod.google.com ([2002:a17:90b:56d0:b0:2ea:931d:7ced]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5146:b0:2ee:c04a:4281 with SMTP id 98e67ed59e1d1-2f782c6579dmr3876073a91.6.1737125589990; Fri, 17 Jan 2025 06:53:09 -0800 (PST) Date: Fri, 17 Jan 2025 14:48:04 +0000 In-Reply-To: <20250117145145.3093352-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: <20250117145145.3093352-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117145145.3093352-5-guanyulin@google.com> Subject: [PATCH v9 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, perex@perex.cz, tiwai@suse.com, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, ricardo@marliere.net, lijiayi@kylinos.cn, quic_jjohnson@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@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 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 | 82 +++++++++++++++++++++++++++++++ include/linux/usb/xhci-sideband.h | 6 +++ 2 files changed, 88 insertions(+) diff --git a/drivers/usb/host/xhci-sideband.c b/drivers/usb/host/xhci-sideb= and.c index ffa6f1b825ff..d4931315dcf4 100644 --- a/drivers/usb/host/xhci-sideband.c +++ b/drivers/usb/host/xhci-sideband.c @@ -358,6 +358,88 @@ xhci_sideband_interrupter_id(struct xhci_sideband *sb) } EXPORT_SYMBOL_GPL(xhci_sideband_interrupter_id); =20 +/** + * xhci_sideband_get - record a new active sideband instance + * @sb: sideband instance for this usb device + * + * An active sideband indicates that another entity is currently using the= host + * controller. Inform the usb_device associated with this sideband instanc= e via + * usb_offload_get(). This allows the corresponding drivers to dynamically + * adjust power management actions based on current sideband activities. + * + * 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 =3D 0; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd =3D xhci_to_hcd(sb->xhci); + udev =3D sb->vdev->udev; + device_lock(&udev->dev); + ret =3D usb_offload_get(udev); + device_unlock(&udev->dev); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_sideband_get); + +/** + * xhci_sideband_put - record a deactivated sideband instance + * @sb: sideband instance for this usb device + * + * The inverse operation of xhci_sideband_get, which informs the associated + * usb_device via usb_offload_put(). This allows the corresponding drivers= to + * dynamically adjust power management actions based on sideband activitie= s. + * + * 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 =3D 0; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd =3D xhci_to_hcd(sb->xhci); + udev =3D sb->vdev->udev; + device_lock(&udev->dev); + ret =3D usb_offload_put(udev); + device_unlock(&udev->dev); + + return ret; +} +EXPORT_SYMBOL_GPL(xhci_sideband_put); + +/** + * xhci_sideband_check - check the existence of active sidebands + * @hcd: the host controller driver associated with the target host contro= ller + * + * Allow other drivers, such as usb controller driver, to check if there a= re + * any sideband activity on the host controller. This information could be= used + * for power management or other forms of resource management. + * + * Returns true on any active sideband existence, false otherwise. + */ +bool xhci_sideband_check(struct usb_hcd *hcd) +{ + struct usb_device *udev =3D hcd->self.root_hub; + bool active; + + device_lock(&udev->dev); + active =3D usb_offload_check(udev); + device_unlock(&udev->dev); + + return active; +} +EXPORT_SYMBOL_GPL(xhci_sideband_check); + /** * xhci_sideband_register - register a sideband for a usb device * @intf: usb interface associated with the sideband device diff --git a/include/linux/usb/xhci-sideband.h b/include/linux/usb/xhci-sid= eband.h index 72aa17eb068d..6de1d9c161a1 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -11,6 +11,7 @@ =20 #include #include +#include =20 #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ =20 @@ -82,6 +83,11 @@ xhci_sideband_get_endpoint_buffer(struct xhci_sideband *= sb, struct usb_host_endpoint *host_ep); struct sg_table * xhci_sideband_get_event_buffer(struct xhci_sideband *sb); + +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.48.0.rc2.279.g1de40edade-goog From nobody Wed Feb 5 21:54:36 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E12619882F for ; Fri, 17 Jan 2025 14:53:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125599; cv=none; b=u9vdFyu/Q3V6hPrbZROJ+mel0UhxHjyygpU7piVCbqKhcwZHF5Kvu+PWBmQcQ8FfMSLnLrQNabEzQIrmr5mRak5X2g0szJUDUrEEXz77HuQKSNOp+YK1yxgVjQQ4WL8czkopwR+4QbeZqv95TZ6apl3mXBa2j05QsnCglFpuZwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737125599; c=relaxed/simple; bh=P3zdn3McJmsyzpYTZJuOTPL2OEq/l5AWCoOxkslRlp4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JanmvB4BE+6Lpt7qDNCkbO/JzaRSfeAAXYPJD85oWKObLFROxGIxFNVjhYdjzZ7aTO/DBNCVzZYRrGGDXxXJGlJtyKk8W6l2NrNB03xnYRMlGSu8Ukr2JC7GVKXQkCNLVx7bUxO365wYd7Vlkwwoam4NCRKREz6xkCi6eRT2+b8= 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=mmLi2qKb; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--guanyulin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mmLi2qKb" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2165433e229so46345535ad.1 for ; Fri, 17 Jan 2025 06:53:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737125597; x=1737730397; 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=GVR6FxEUaufqkmZpxlHK16x/t28tR59Z3ucl0Vcwuwc=; b=mmLi2qKbjBLuo0uRRxIRvJbhRtWIY59FcDDIEE4mD3gUPucyA/HL9CDhxdeNE4hJf4 Txc6CfR3Rdy9e/PI6F1CgGa45oTxat8g9cRtdhL/wXBOI5PhdNOFafAyjManF0JBL6ll quuhG4tel7XYINKHB4DuNlmFz616wFGSL3tHvJhtfXtx387wIHh5I6yHCAAB1Ys5tOWQ wp7azUDrx5+ksjPcDnxUabioiOnaQOQBbVYKy+oxFvDr4YfZbY0ZDI7UCzjufy3gfuoN epThwwsDcj+oqd6lEDEfLqI3Zj97b+x4lS2zZvEuGT0ZMUYcUuoOwkW1V6gz+apzHNTp eknw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737125597; x=1737730397; 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=GVR6FxEUaufqkmZpxlHK16x/t28tR59Z3ucl0Vcwuwc=; b=W015d26M1JhWQw0OzFu0S0v6PLDlAk0GlY2yiOrXPLLscSAvyo9/Yq0de8EhyfkYwf Y9lC15XD8hVsy/kbJyj6tRZKGc0cIGZLuGue5qIAs5YZvHWWMMmu7vTKyTkrsRy9ZI9i bTQ9kAza0w9pg9ub+VYy73XlA5a8uTm8slb0VtbKqsWjA1RA5XhN8RCuKAVBcIoLroqs /UcNvkTa3aA7pjQbKNeayhQO6ek/QOEnFeLzlBNN/rZd2gJyd93zndjf2NO0ox8ohF1/ 8RlE+ikEL+hQ1p5Yagdwmjk9ahJz0Dz646NWgrL46JAINCH50bO/H8FngT1wQwNkE4M2 tl5g== X-Forwarded-Encrypted: i=1; AJvYcCV04RceXsiYQ0SSyW0f19QxH6fIeNmK0azqICyjDLEFY0u61MtPK3ZAIeltEZGt1O8Ra0kZyrLawePWWNc=@vger.kernel.org X-Gm-Message-State: AOJu0Yyvnqs5LLdelQO1sN+HurS5iC4nNC154b3y2PthD99VOMObcHUo sAc5WE1/d1f5w2t2xw+khArwCuAAZEBo0+JvYmSf1Ob/T0H98GaD6TwkU6P1neARndnfIu5Q9FX cXJa+y3KQwlM/xQ== X-Google-Smtp-Source: AGHT+IHU0PJBV4WLgiNVl/lj+GZxzVPMi//fbFeWdYI4fPfpzpbB4C1mX87Gu/0lPXmaCBbD0ytJpHqKH7Ml7pM= X-Received: from pgvn10.prod.google.com ([2002:a65:63ca:0:b0:837:acbb:873a]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ec85:b0:216:4e9f:4ebe with SMTP id d9443c01a7336-21c355cca2bmr48727045ad.42.1737125597465; Fri, 17 Jan 2025 06:53:17 -0800 (PST) Date: Fri, 17 Jan 2025 14:48:05 +0000 In-Reply-To: <20250117145145.3093352-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: <20250117145145.3093352-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250117145145.3093352-6-guanyulin@google.com> Subject: [PATCH v9 5/5] usb: host: enable USB offload during system sleep From: Guan-Yu Lin To: gregkh@linuxfoundation.org, Thinh.Nguyen@synopsys.com, mathias.nyman@intel.com, stern@rowland.harvard.edu, perex@perex.cz, tiwai@suse.com, sumit.garg@linaro.org, kekrby@gmail.com, oneukum@suse.com, ricardo@marliere.net, lijiayi@kylinos.cn, quic_jjohnson@quicinc.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, Guan-Yu Lin Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sharing a USB controller with another entity via xhci-sideband driver creates power management complexities. To prevent the USB controller from being inadvertently deactivated while in use by the other entity, a usage-count based mechanism is implemented. This allows the system to manage power effectively, ensuring the controller remains available whenever needed. In order to maintain full functionality of an offloaded USB devices, several changes are made within the suspend flow of such devices: - skip usb_suspend_device() so that the port/hub are still active for USB transfers via offloaded path. - not suspending the endpoints which are used by USB interfaces marked with needs_remote_wakeup. Namely, skip usb_suspend_interface() and usb_hcd_flush_endpoint() on associated USB interfaces. This reserves a pending interrupt urb during system suspend for handling the interrupt transfer, which is necessary since remote wakeup doesn't apply in the offloaded USB devices when controller is still active. - not flushing the endpoints of actively offloaded USB devices. Given that the USB devices is used by another entity, unilaterally flush the endpoint might lead to unexpected behavior on another entity. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 23 +++++++++++++++++++---- drivers/usb/core/endpoint.c | 8 -------- drivers/usb/dwc3/core.c | 28 ++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 1 + drivers/usb/host/xhci-plat.c | 14 ++++++++++++++ include/linux/usb.h | 8 +++++++- include/linux/usb/hcd.h | 7 +++++++ sound/usb/qcom/qc_audio_offload.c | 3 +++ 8 files changed, 79 insertions(+), 13 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 1bbf9592724f..f8d3b50c188a 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1415,17 +1415,29 @@ static int usb_suspend_both(struct usb_device *udev= , pm_message_t msg) { int status =3D 0; int i =3D 0, n =3D 0; + bool offload =3D false; struct usb_interface *intf; =20 if (udev->state =3D=3D USB_STATE_NOTATTACHED || udev->state =3D=3D USB_STATE_SUSPENDED) goto done; =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (msg.event =3D=3D PM_EVENT_SUSPEND && usb_offload_check(udev)) { + dev_dbg(&udev->dev, "device offload active.\n"); + offload =3D true; + } +#endif + /* Suspend all the interfaces and then udev itself */ if (udev->actconfig) { n =3D udev->actconfig->desc.bNumInterfaces; for (i =3D n - 1; i >=3D 0; --i) { intf =3D udev->actconfig->interface[i]; + if (offload && intf->needs_remote_wakeup) { + dev_dbg(&intf->dev, "interface stays active on an offloaded device\n"); + continue; + } status =3D usb_suspend_interface(udev, intf, msg); =20 /* Ignore errors during system sleep transitions */ @@ -1436,7 +1448,8 @@ static int usb_suspend_both(struct usb_device *udev, = pm_message_t msg) } } if (status =3D=3D 0) { - status =3D usb_suspend_device(udev, msg); + if (!offload) + status =3D usb_suspend_device(udev, msg); =20 /* * Ignore errors from non-root-hub devices during @@ -1481,9 +1494,11 @@ static int usb_suspend_both(struct usb_device *udev,= pm_message_t msg) */ } else { udev->can_submit =3D 0; - for (i =3D 0; i < 16; ++i) { - usb_hcd_flush_endpoint(udev, udev->ep_out[i]); - usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + if (!offload) { + for (i =3D 0; i < 16; ++i) { + usb_hcd_flush_endpoint(udev, udev->ep_out[i]); + usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + } } } =20 diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c index e48399401608..658ef39ebcd1 100644 --- a/drivers/usb/core/endpoint.c +++ b/drivers/usb/core/endpoint.c @@ -18,14 +18,6 @@ #include #include "usb.h" =20 -struct ep_device { - struct usb_endpoint_descriptor *desc; - struct usb_device *udev; - struct device dev; -}; -#define to_ep_device(_dev) \ - container_of(_dev, struct ep_device, dev) - struct ep_attribute { struct attribute attr; ssize_t (*show)(struct usb_device *, diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 0735881d4650..793fbc030fc4 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2602,8 +2602,22 @@ static int dwc3_runtime_idle(struct device *dev) static int dwc3_suspend(struct device *dev) { struct dwc3 *dwc =3D dev_get_drvdata(dev); +#ifdef CONFIG_USB_XHCI_SIDEBAND + struct platform_device *xhci =3D dwc->xhci; + struct usb_hcd *hcd; +#endif int ret; =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (xhci) { + hcd =3D dev_get_drvdata(&xhci->dev); + if (xhci_sideband_check(hcd)) { + dev_dbg(dev, "sideband instance active.\n"); + return 0; + } + } +#endif + ret =3D dwc3_suspend_common(dwc, PMSG_SUSPEND); if (ret) return ret; @@ -2616,8 +2630,22 @@ static int dwc3_suspend(struct device *dev) static int dwc3_resume(struct device *dev) { struct dwc3 *dwc =3D dev_get_drvdata(dev); +#ifdef CONFIG_USB_XHCI_SIDEBAND + struct platform_device *xhci =3D dwc->xhci; + struct usb_hcd *hcd; +#endif int ret =3D 0; =20 +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (xhci) { + hcd =3D dev_get_drvdata(&xhci->dev); + if (xhci_sideband_check(hcd)) { + dev_dbg(dev, "sideband instance active.\n"); + return 0; + } + } +#endif + 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 0b6a07202609..57c3e768cdac 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 b676d4dbcec1..9e01450328d7 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -456,6 +456,13 @@ 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 +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (pmsg.event =3D=3D PM_EVENT_SUSPEND && xhci_sideband_check(hcd)) { + dev_dbg(dev, "sideband instance active.\n"); + return 0; + } +#endif + if (pm_runtime_suspended(dev)) pm_runtime_resume(dev); =20 @@ -499,6 +506,13 @@ 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 +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (pmsg.event =3D=3D PM_EVENT_RESUME && xhci_sideband_check(hcd)) { + dev_dbg(dev, "sideband instance active.\n"); + return 0; + } +#endif + 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.h b/include/linux/usb.h index 9b3f630e763e..c4ff11ad14d5 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -44,7 +44,13 @@ struct usb_driver; * Devices may also have class-specific or vendor-specific descriptors. */ =20 -struct ep_device; +struct ep_device { + struct usb_endpoint_descriptor *desc; + struct usb_device *udev; + struct device dev; +}; +#define to_ep_device(_dev) \ + container_of(_dev, struct ep_device, dev) =20 /** * struct usb_host_endpoint - host-side endpoint descriptor and queue diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index ac95e7c89df5..a9577da6ecff 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -766,6 +766,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 */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_of= fload.c index 7dd7e51109df..d201b1ad33b1 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1619,8 +1619,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].si); } } else { + xhci_sideband_put(uadev[pcm_card_num].si); 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.48.0.rc2.279.g1de40edade-goog