From nobody Fri Dec 19 20:55:58 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 10908154C05 for ; Thu, 9 Jan 2025 03:56:38 +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=1736395000; cv=none; b=CWEdIVwrwMsEWmrJfg99axYUtvCU8spUrnPQPWBC1d2kcqfZG732LcwqGuVFWJJUSKaPRDmnBuJNJ7GVJq3BWL+mPJVsA66IWMKNaaA7as/8t8Zq6WfN2tWBjvEgaOge98/rez7auQlLaoRXNbsjPzHGjwW6fQpGaoRos+LTDhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395000; c=relaxed/simple; bh=KfAu+/Q9zgHYQiNdpnwbI68oYIXktrQNbrxwqoISvl0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PzSy1M0LXyvzUm4sznF4+mhbgKF3QMqk+Hg8yLRlbp46n6xQ7lcQxN27YIXt2zhusTo3WJV3K6p/ijBv7qQLXr3DhoyWNSnlRz9zoh8rqbwpqGPbe/XjjytnvnUAyyybrkQ+cSIGl+Sjms6GqZ1bhZ8IorgJWLisNNUrA3k8lDs= 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=iHY9UXW4; 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="iHY9UXW4" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2163d9a730aso8750555ad.1 for ; Wed, 08 Jan 2025 19:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736394998; x=1736999798; 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=1bqpoVW3vY/Vp4JhJHrnaJZTqoC1FMmiLXRADQekEsQ=; b=iHY9UXW4RmrRfKaK9/G/dxMouHOZFKSWkRr1IXso3lXpJD1x3RwdP2MnwW1hDACS+Q gUyXoAC2/9II+YQc607nO9qjxJlhUS0YbGDAasTMCjHl83CV/RgMQcC1WXN44CWni8ht 4NsAYuWvv05GnGNAFcsGFXthLdhery7D4K1RUrbU0qKB0omWounsb0kL0wXaz0glp06v 7ZI1oPDZymUQkTU+1Xe6cdGa/dsh+ddJuzgJGeKx0tNCNeFRXKyKyX6H62opAhbumFBj oLrOoHeRAZHJNy9TS7q5eqfvdbIhTR/Fmlx5tMEfyQsbRV4ReZto7eU+p9Pnm2Qm0m09 uL6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736394998; x=1736999798; 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=1bqpoVW3vY/Vp4JhJHrnaJZTqoC1FMmiLXRADQekEsQ=; b=JOXYWNKNQCA5xjSLfhS1a+v02NVANOYT2RU73+zs3ObUMKstUueRhb4VUngqe3GgKy yhbTj5aGX+3Qn1AiptuXrXWYTm3c3NbfM0wNoH8xEy7Kp9NIjy8aPVIG9g6tpQBWk89Z qUANVns5FCBHdKSCzjb2m2WKpT9VEWLtln26Qk+vrw3cyIrIzDG4G1rCcyoZ8O0PiF7s koGOPPIovRn6g3df8G6w45ZR4FGtXIjwE4lrSBQ5lXQaMiGxLU2fsjHEnL6jUUAqWeyJ cDFNHtmV7jNqVMp/2homyAagsYQ6fmgJjGr9nTo5gU6oThnZIpRtq+HaniGtmnK3/ifc fZNQ== X-Forwarded-Encrypted: i=1; AJvYcCVKB7GEI82CBEIIWxwkPtgyiUOleGvIvswwILZIVebLJ5S9EwR1Y/OZfx01gf9tfgDfq0PC8RIhzyhTkL8=@vger.kernel.org X-Gm-Message-State: AOJu0YwspWb8EXlaab8Dz3PkzZziAo2TYQ1xI85d8jGlsIP3GYBP91q8 NZwsWfJXkHL/QjNohszzw3Siykljvh9YMv+qXhIbuP6o0i1uAcoW5dFFflW3/upnzk2p4vAn5CS rue4AE9wKxX0s8g== X-Google-Smtp-Source: AGHT+IFVJIqG3yFsoeHkU0ahRDewZcWXAEwQdrSTVFc9DwLmOYW/hNR1O09jqREMSRezVrFqq1pb58ualnh7MVc= X-Received: from pldp13.prod.google.com ([2002:a17:902:eacd:b0:21a:807a:3652]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:aa85:b0:21a:7e04:7021 with SMTP id d9443c01a7336-21a8d6b903amr22214385ad.24.1736394998346; Wed, 08 Jan 2025 19:56:38 -0800 (PST) Date: Thu, 9 Jan 2025 03:55:05 +0000 In-Reply-To: <20250109035605.1486717-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: <20250109035605.1486717-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109035605.1486717-2-guanyulin@google.com> Subject: [PATCH v7 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.47.1.613.gc27f4b7a9f-goog From nobody Fri Dec 19 20:55:58 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 F3B56165F16 for ; Thu, 9 Jan 2025 03:56:44 +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=1736395006; cv=none; b=ERzt3V9xMYOA7wR/8jT4dRZ+ZFHK7BUuo2xHzfJc2wR2jd+L9jhj1xXdYb30pzicwNZ7aVrDtB4OHhfzbGRoR2txaYM+t7UGpnoSChUjhOKl07QiaL5nW+cqqnpy5/NGmBJxH9cqEXTUAelzntJIDig28IDPScRccF46rCQdUt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395006; c=relaxed/simple; bh=U8jc42PW7/ktoftpSHk8MRrsiNyFroAZ122yKoykeWk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Dx2QGABSREHLvA8kHLU4s4Kg7Uruz5LTreSLaPNMMmNFstf7HgsywyR4q+DyJLbSRyW98Swr2cWB2l0X41j69tjQ76H8TDzgpMhRAjaxSQ31vFxPsIgLPlgorLgV938PkFWP0HLxYG/QHstQiwK5NiEfKC+N/j8C1GVNu6XEOHE= 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=FsCXlOsc; 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="FsCXlOsc" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21632eacb31so5972245ad.0 for ; Wed, 08 Jan 2025 19:56:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736395004; x=1736999804; 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=kLfOoQDnujr5A1F2r70MA5lfjVLn4qtfns7H9XAvRjU=; b=FsCXlOscOAAOE66PSUT71F7aMzd0jILLTAlrO3XI4vKV4sDpqmoQcdH+r/iXKdt5me STuRQ4pLHDhwebDpOiSwMpG5V4Mfu1KDwUBDzUrQAfRzYdTnnHnquHdrNY5LASX2xQLO JlVPruqY4j8f0mRgEY3jtR7pHXnjLeqblIQVmbbpIzoJ4vDZhJGiPEXFJIBrd1TrE0d2 w/6Rg7AlF0A+SftpR9/SMuzxci1zZNahofP0Zzp0OihusG588ClSJAdsOU0jb6HnAKeu zKWyCi5bVoChQOFrsO/LZOGMyBkWM55iaujmk74oY8RsIHOuKiKXCdyNn8oHC4t7h7nd 9TjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736395004; x=1736999804; 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=kLfOoQDnujr5A1F2r70MA5lfjVLn4qtfns7H9XAvRjU=; b=kUSORXqZUS5NkaGwBu8UjNqFJ6otAE6xxpUByv4JLzxwDVZxUnJjOzsNkcQqp9tfnC 55ESFkZSeL/22xHKI1WJiDoCYTJkGuhkq5M0wVHNZW+xYoI/ltJDW10RdM7I6G6dy25M G/nGBTEwDJL2D+pE/47vsUtVwGBR8IZdbUElS8Cz0d9gsKVJZo+ZU+E3faOVVLTzr0ru C2HWdQ5NVbzSbp1t6GFW/2U4rU1Ax9F2ZsA+GZMN5LT4iqMGbKUra8wrx3rLRbdNhN9S IdpCny+wVRrdHRkSHmt2ZnjZfNkTAl2E03kxUPOiZP8kBZDEQj98X5DCwuilYNPKadBj CbaQ== X-Forwarded-Encrypted: i=1; AJvYcCWLtXAReoEgObkVD3RwiY576o9YQSA0ShI/ESqXuwI8KzXzfac465b6SH8E65dF/PHjy/cCVvV12Rl6G3A=@vger.kernel.org X-Gm-Message-State: AOJu0Yw08B8zJtsmhUpgTsP5JEUIH39d3qF+m7F6MHEytRPqw4X5G9GA 5OP/VuBx0f/CZwRVahqLzc4rHJCj3b+EHWIS4oT3BQcSBraup1wTCtKiQuLfHDhib4nLMvjpurs KpalzdeEeDpWvGA== X-Google-Smtp-Source: AGHT+IHGWPQ97evR6CX9zmw6SJkm14AscRbwGnyXik8xyoj2Fb/TGu2ud6/l7gVV23yEO+9v9zzFyVQSJlVKoKg= X-Received: from pgg14.prod.google.com ([2002:a05:6a02:4d8e:b0:845:b983:9e34]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:101a:b0:1e1:aba4:2095 with SMTP id adf61e73a8af0-1e88d0bb4bfmr10227278637.32.1736395004396; Wed, 08 Jan 2025 19:56:44 -0800 (PST) Date: Thu, 9 Jan 2025 03:55:06 +0000 In-Reply-To: <20250109035605.1486717-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: <20250109035605.1486717-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109035605.1486717-3-guanyulin@google.com> Subject: [PATCH v7 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.47.1.613.gc27f4b7a9f-goog From nobody Fri Dec 19 20:55:58 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 451861632FE for ; Thu, 9 Jan 2025 03:56:51 +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=1736395012; cv=none; b=RAj3Ad6uONLmLlfcHkqmljLX6baq55PzGMJ0axV0FcM3/vic/ogJBPfhwB2Setwuqq/JJPaRKOXZ9EWxfkqy2DJBqQjpX8ukGnf03yZ312ArgYHwaTmHlhPcDpEkHLtzLdX6uimzTzNXuMSjVaNeOULW5/SEe+o8bgMqyO4eeZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395012; c=relaxed/simple; bh=qD47mFE3rEqJaFm2tUJyM5imvW+agFlxeHfG7ZpS6Oo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mdIxNc8oS2AuldtI1OC96CJqzoHWERnGklcTvFxGlzHcWFE7ks+CUgLOcFqNQc/+X+t+lj9lBFCH6W3DDrgCMkpfEUIUX7NZA4mr5dcByGb4RhL9yQv/VDGtKkR5qDrTn3oEKD1IzT295EpOZII42oPzF2auT99ZZrEGk+tj0RQ= 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=k2oqESLV; 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="k2oqESLV" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-216430a88b0so8371915ad.0 for ; Wed, 08 Jan 2025 19:56:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736395011; x=1736999811; 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=2aovcihj81aQ72/90alHYAGugMvajBS9wOWu8mRVTbM=; b=k2oqESLVKvsLBDD/S4N9Wzx4emFN2fcj05jb7OYqcOBOl6ATz2M5UF+oJFExAQNwbu giDpU+PMZhw3ZcduoWVexKNRsSFuaoM7/0tJIG6A2OryKraQ6cex21tq3HXjdpHiUmJI cLDWaanDBKvaHzl6dwQVlGrvnHzcQbfoVgZhqHjLk+0nNmQvLbrNx0+qzf5HzHsomECS xGBIUiedOjBh13SXnt4zmqgwxzOQVgRJroj704kPEEqaFGgsZnemMCDHJxXR1cg5EDM0 4iJ5cYbJK+Kj8Qo4cv8Oi9Nq2guF8nD44Cuw7RrObmHfJtUxLbRs1KA3G5SiN1oqQX+I EOSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736395011; x=1736999811; 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=2aovcihj81aQ72/90alHYAGugMvajBS9wOWu8mRVTbM=; b=Lrxstq0nNDVbe/a7f71DdPyRM4ssIljv7V1TgEKhslg2w4OkBjYhMgZX1v1PVSoTD9 uYwhFTebkxuV+TyaQntNKOB1CmXyfjugkZfdEZUXdVOrIQwiOvricczUCkswJvI1+Vw9 YjsYMOsun0Qnl1akyMmpZG80mS51JUV94v+KHI6M/OyJqKPWF5w7Ps8wGT95luROzSsY cK5+9cXQbQ22URK6oZYP71PGcLKNeqsi9b6pbzSrMUbgUlH5hVXhzu9M4ub1inh+tUIA sbUJ/2u4LzPBJe0qF09cqkkx/cPKuWwcV2j+yxy0qePEQL6sr+TBrYErSVbAVZPVU/rp xBNg== X-Forwarded-Encrypted: i=1; AJvYcCXZQ1NxKgrAi03hYfoGqee5r6N444ULt3OgJK7xrzSYbHRemZxnO7VWHOMJyFUDFPJ2UZYT5lEFhHY6t44=@vger.kernel.org X-Gm-Message-State: AOJu0YwGU3kzmbH0r1IxPY73yxKBC7mjJQw12+k6p56tshhh7rE3QWVE c8TL13V/I/iPzc/tKfCjYQybCtPSBRYMErOSKvfEAInnSiHfZyV/ov12dB16OuDQ2yNT0RscIW4 0FHztfee/tICHhw== X-Google-Smtp-Source: AGHT+IF9SEICxhuGaDaYAOJsDAfUX42u4sbhlCKIXa4C2f+APQNh+Y/TdDoeKJtYIjbny0ziK/9kFlamEEWWHys= X-Received: from plbje5.prod.google.com ([2002:a17:903:2645:b0:216:37d8:bda6]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:230b:b0:215:b087:5d62 with SMTP id d9443c01a7336-21a83fe4b38mr93216155ad.36.1736395010709; Wed, 08 Jan 2025 19:56:50 -0800 (PST) Date: Thu, 9 Jan 2025 03:55:07 +0000 In-Reply-To: <20250109035605.1486717-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: <20250109035605.1486717-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109035605.1486717-4-guanyulin@google.com> Subject: [PATCH v7 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..01f6287cf73f 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_get_sync(&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_get_sync(&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.47.1.613.gc27f4b7a9f-goog From nobody Fri Dec 19 20:55:58 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 4EE7F1891A8 for ; Thu, 9 Jan 2025 03:56:56 +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=1736395017; cv=none; b=MVwWIuK9MHwPGryLiGbCc/qj/bTox3NuQpHk352Jde1ycKFFq/xUkT0k8p75PeoUmn+D6wqRo9hF/JYygFufmwmHSV0IztT7jgqNbnzAbZ7cbNu9WRD64ePYRtBVQNLY4tGw1zwk9daXzTXDVY2lTy5dA/jgyDmJ7s4GBqLuQaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395017; c=relaxed/simple; bh=faUlm+0/aqfwj/ZyUJRA6KayiX/ZHmaYLZuAWi+8Tt8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VWZlsz9H9jk0tmF7I1+zaNhixScjUuiqGf50CqrFHTyMnBDmNUcshPHUNvADbLt0+uCjstb30OfDfXmyAg6ZnEv+Ox/i8APgv5vgaroKwIKTXshMMw1o8hyxesEUGX7Eqos8jcEsWxVC+52wF6dtXoSW3BGvgxOJR2nskWrTxIE= 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=gao4ejgX; 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="gao4ejgX" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2166464e236so13771445ad.1 for ; Wed, 08 Jan 2025 19:56:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736395015; x=1736999815; 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=yq1k1+crakqu6xGV6adPZX7kzIgk4M719hbmyURwKps=; b=gao4ejgXK8SeUr0S/m8BAosG1o07awuEi5pj9H44I9Z0v1FWtkhp6h6vV0du/I48yH D5lK6T6rU+i7vNipGt7okEONq5Z2OUXst0Y0WXlGSkBEoo9rRR0j+1qBBrmzuXJz9/yA r5/RhfE56PaWkySKC+emJUwOc+tjByzqTkgm6PdJYr7GF2kWexsbWV7Z+Msw2QRaWMqY BU6rBWG4WOCtZAazaSBxPkzQStMXRUfoj+ewteDBGGZmBSdkpNHaTZ1TbnwhvFMXcRwP fnOBV14hrlX3ilYn9KiX32z7l00VU7DiLzZfvjkDmYCsauPwmE9biAnnlYIfPMGL/tL+ GkPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736395015; x=1736999815; 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=yq1k1+crakqu6xGV6adPZX7kzIgk4M719hbmyURwKps=; b=fNPvoK2NcKdhZqS9KYBQULe3Oap92sA7fO3svhIbigktpwJXGXi9ye6o8xLUulaK8y l1RGwfLdy0wuI3gJPsMTfChPwB8+oCdrijEP4KVmvXzIWcjU3wETzlvs0zQouProw1pb KWISvduWc1ooziAuSFKw53XsPOZttRo/ZNNeEJ5uEaJ+BjBrZX75j1mYIuMEFN3zLeTP 6465uKlIcDcRyNizjeQCx2xiwf/HPYYTpmqFL/zU942RAuoZ/BgjVmU9IJrpd32+3rin rjqa8PYwnLy2oVBQAXEZsij2l9s5djnoSLB6UWCJ51Per3JSWqFh2C4WhPO8NjyiCq0Y vUFw== X-Forwarded-Encrypted: i=1; AJvYcCXqz/drItT0zvprYI2xCnQYyuOH00bmxKu6327KnlYJIIU2uNFI9hEefJLFc1KV7cDtfXb/C1SaPVwRQuA=@vger.kernel.org X-Gm-Message-State: AOJu0Ywq+mti2jp9sTLKFzaPKLdUUXSifDDvknuDsI7KOIgDSPjXjmUf tCAv7MtlwG6x4YjL0ATYf2V1BgZhR1KNa/CYkGqM0y07jQl6cCmoJ3XRy1miqNrBE8nyZoB6fHM C1aU1x0im/T7GiA== X-Google-Smtp-Source: AGHT+IG+uiVZJFTFW1Pc7BABtMZ+mTFebYnx6zwKTzfzwanRWkoXb+6jWySyhgbUQv+K78k1W2dmItnKFD09gYo= X-Received: from plblc11.prod.google.com ([2002:a17:902:fa8b:b0:216:248e:8fab]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e843:b0:215:a3fb:b4d6 with SMTP id d9443c01a7336-21a83f3f50dmr83119925ad.8.1736395015667; Wed, 08 Jan 2025 19:56:55 -0800 (PST) Date: Thu, 9 Jan 2025 03:55:08 +0000 In-Reply-To: <20250109035605.1486717-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: <20250109035605.1486717-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109035605.1486717-5-guanyulin@google.com> Subject: [PATCH v7 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.47.1.613.gc27f4b7a9f-goog From nobody Fri Dec 19 20:55:58 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 CC1AB18A922 for ; Thu, 9 Jan 2025 03:57:01 +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=1736395023; cv=none; b=chJAy1uZpKX6+X8Z5x8fpjrAPzO8ol3G9CHkrZkjHmEJC+8zwRn4sTFkKAzEXR4ORkblfG8h7MKkwkvnAZGNM+ZwNFTDfwzrzYVXw1PMjdubq18B2MWEwp2BEyxyDgTo2bgZRkqn0UHkHVb1QH8mQoo2YiTX4VUunrAUXjKCE0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736395023; c=relaxed/simple; bh=zIu3mkFQEdRuVFyLlkBColU3jo3Y6o5V9YwSIWBJAHE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pnKawxmu2/Su+e0W3BdgnOpsd9Xr/+5d+o0o4B725/nUFR8VlMhT5vwnRtXU0ffNQ7RlymYN+qNGr7/6k4aVoxZ+AxgP4KtwnH42yGaZVGJctI0BTkhCbOMQMapG5DTWQbh0WJjZMk1a65a0gLkZGAaUg1B3VH0nEGEMTElejdw= 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=k43qo/Me; 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="k43qo/Me" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21631cbf87dso8138605ad.3 for ; Wed, 08 Jan 2025 19:57:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736395021; x=1736999821; 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=ddchxYBmHDxGkGbNYTXj4haAP604kWKrrwtl9P00xoU=; b=k43qo/Me6u7m1QhLuNUUiTaYjgbN30os2k8FmGAYtZ0Ku5bEPu7oKig8PCGFbxEl2A vtZvNcWA8OPNVEHjsOEOK8ga3k0dnVDgSJX1xQEIEoZsrVxkPyYachAfFdxZzEi1N8Tw KHtVkFEnTPsqDuWcaqqT995aK3O17HCXO3yzsJotiJdpZhbVz3RJVwRbeaXIC1NSM+Lh zkrHYQHcAx1WzmioSCz1uU6VUy1L1qABk5yg4hUuLBtCWaJCVRjWd6Agb7wRFyC+OV7Y FIPUmzwdfK68d717l+gYmVP8rYtV3hFs4bJXAZzpNpj9KRyB5vVjF5TRfwBdibQX5n3G +nRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736395021; x=1736999821; 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=ddchxYBmHDxGkGbNYTXj4haAP604kWKrrwtl9P00xoU=; b=tBSL3U0qlHxNuT4+h9/4PmZ7WtqZVWuBRNBUmhF2gsiVq+IkQXhscxaZEnq/oEbMxY 4PFAZsycN/wMlgyehKv2Cn4Iz20JZNwns6/lD9jWGa+DKL7CtZW879WgDw393bYhgUuh sPd1ht3h/M1x8nP608xryXA/KJSBPU/YtDwPXvtLKHCT+JcXiqoZJDZ/m86x7O6JR/Jo 5j4Xs0+zZHQDiTTBGxNm2fPJbwKZDNP+71sIaL8/Bgeq/Ckg8i/8n1vttwwb3fGAyeG3 s32LOUH7Ql+ByYn3OGrIlzD6IKhtFAW3+hSN/HwIJXMD2cr4JoGmVt0Md6lCTVmCBkgL CPzA== X-Forwarded-Encrypted: i=1; AJvYcCXptQYub90Rf07Q531PDREJfDo5dNRqWEk1t8TsxRA1XaCsL3Xbvx0SGAdgjIajFsNPJ09vueWcaa6k8Zw=@vger.kernel.org X-Gm-Message-State: AOJu0YzGbbUHH/r+3hFsNJ3tHxAJW87C/YbWn9ZtGil8menoetQ88dw5 OdOp91vEUqFj3pk6I9KxtUGVKcMoVq/r4kFWw7LXRI6HYwxV+cEkPIBtJCrhTqYITl0xzYLc0ND 5Nv7ETFIgUyYSng== X-Google-Smtp-Source: AGHT+IGMQpT2N2xu3uiFZIpo9M4OReVfIW/xSsKSBRe77zdn+GWUb+mcChBtX/TWTXDKSxdHdWl/a8tX+zwnSmI= X-Received: from plry6.prod.google.com ([2002:a17:902:b486:b0:216:5808:bc6f]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ecc7:b0:216:2259:a4bd with SMTP id d9443c01a7336-21a83fda87cmr73619255ad.52.1736395021215; Wed, 08 Jan 2025 19:57:01 -0800 (PST) Date: Thu, 9 Jan 2025 03:55:09 +0000 In-Reply-To: <20250109035605.1486717-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: <20250109035605.1486717-1-guanyulin@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20250109035605.1486717-6-guanyulin@google.com> Subject: [PATCH v7 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 flushing 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. Signed-off-by: Guan-Yu Lin --- drivers/usb/core/driver.c | 37 ++++++++++++++++++++++++++----- 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, 91 insertions(+), 15 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 01f6287cf73f..06f9809e2d92 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1413,19 +1413,32 @@ static int usb_resume_interface(struct usb_device *= udev, */ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) { - int status =3D 0; - int i =3D 0, n =3D 0; - struct usb_interface *intf; + int status =3D 0; + int i =3D 0, n =3D 0; + bool offload =3D false; + struct usb_interface *intf; + struct usb_host_endpoint *ep; =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 +1449,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 @@ -1482,8 +1496,19 @@ 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 (udev->ep_out[i]) { + ep =3D udev->ep_out[i]; + intf =3D to_usb_interface(ep->ep_dev->dev.parent); + if (!(offload && intf->needs_remote_wakeup)) + usb_hcd_flush_endpoint(udev, ep); + } + + if (udev->ep_in[i]) { + ep =3D udev->ep_in[i]; + intf =3D to_usb_interface(ep->ep_dev->dev.parent); + if (!(offload && intf->needs_remote_wakeup)) + usb_hcd_flush_endpoint(udev, ep); + } } } =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..7928df8df075 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.47.1.613.gc27f4b7a9f-goog