From patchwork Thu Jan 16 13:50:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 13941701 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 57B6B22ACE4 for ; Thu, 16 Jan 2025 13:54:29 +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=1737035670; cv=none; b=iUu6s2QdYg7V8u+QeQeheCgP6+TBGnIInHrSp3gXX6U0bYruk8JKocM1vUoD/7CRscEgF8d07796Nsv/0h7IUxsnSWydb1sWXrSIxPtvNQTZrcyBgoApfzcNZ2CRJbmG1gFumfm4Zx5bhUl22P8XCJLuQNmYodDfHKgSYX3bSK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035670; c=relaxed/simple; bh=FNJJD9zaL9tYqwWTeIV7vxHf0s0Y2Sf04iiJXfVPKQo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PbaU0LL6cMrA3KNlWTyNMBg5pEaRc7zti7b3C/NZBgH1W69UXMfUNwjZCnPyKfyVV3+OSFxS26rKKEsemOlIoIctpgXWVUtdt2Fjt2Q1m6ak+vMHXgR7dhd/C9Rlhiw2ZWOE0LCKss/C1liKqkgsrTgCK4zXLTkC9X9RvpU81Mc= 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=rMYTIe8F; 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="rMYTIe8F" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2165433e229so21412385ad.1 for ; Thu, 16 Jan 2025 05:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737035669; x=1737640469; 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=rMYTIe8FmIboJgrrskfdFDge2n4JQCpqfJj6KjGbVCV495xIYtglN/7s3m+qEjVPEm 6dXsXDMnDCQX5tTZAqSfXcresH6ji3hQ/In7YuXBPeG4vbr6RRIPM3DorHUpQ4iyxddB hA15VS/0UULSA0M6xES3aATOmz0T9fSI9SJd1IbQBwGcJElwbqfhrb0jD7Vnnl7jdokk tksUj5NzEHovgHU0fKbeFPNWHd5EupmcbavHrLEw8DS/Zf0wJiWlzwwb20XV6AIRuZin 6paCTjPV+/snJlexmz4KWtfVGb4G6hQLR29zqxnDLA+cMLiETafAC2IY3XZ65ioEUqhZ KC0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737035669; x=1737640469; 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=U3ujgczsv+BsRHSoI5MrVh/totJqX51FoLlwqGflUodIMz7QsmWvluqSGtvvC3MjLQ tmDrQfQ34xoF9UMN8U2GHdxj27g1QNWrkz8vnrUm1kbwEMvzGhOqmbHEkk606dA9zDeC bCOgT+mTQ8eG3hSSjH99OI93WoS7QtL/sjovOXEJpcZQTOj0FyC0ecqvfmBew/Ymrsyt rJQVTuxctuE2LReAacEGJxC+ZwvTUAcoi6Zi0CZmM5DmAYTDwLj66HZw1v6G/EpTUx8y PK7SrAS5vtR8MMCmLkoGzJ2PpCxmmG6pP0ohpW7ajsO4ZydGya1wU67zecZoGVowd2TU QkoQ== X-Forwarded-Encrypted: i=1; AJvYcCVr458mDB2TJQCUJyTrxrX4s4IGh9Ky5gMw/t/Yo87N2KLJimwg3kviu3eqkfUuDiCE4HraokXaK+Lqhw==@vger.kernel.org X-Gm-Message-State: AOJu0YyYphUTAZYlfaytEveTArKwtGeIieLrzS+Yplo8K1UL2zCqT7Ai UC9fmNtGSIG4bw7ed+1QEp3pcMtPj2sCcol0+kQdn+Tp2DTsCETLkUix1jRPxSVYU0CgeMFpVc2 EvrHOk3mwzckRrA== X-Google-Smtp-Source: AGHT+IFqmSXycg5rTI+nDAw3e/9Mk9f12jOfkBuGsUIM97ZO8VsDgl5Onr1+2lRYWdP+5PJgF5pKtlVtwNgxRRk= X-Received: from pgf11.prod.google.com ([2002:a05:6a02:4d0b:b0:7fd:3ffb:bf1b]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7f8a:b0:1e0:d4f4:5b2f with SMTP id adf61e73a8af0-1e88d2f6a3dmr61959632637.32.1737035668832; Thu, 16 Jan 2025 05:54:28 -0800 (PST) Date: Thu, 16 Jan 2025 13:50:13 +0000 In-Reply-To: <20250116135358.2335615-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250116135358.2335615-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250116135358.2335615-2-guanyulin@google.com> Subject: [PATCH v8 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 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; } +static int dwc3_freeze(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + ret = dwc3_suspend_common(dwc, PMSG_FREEZE); + if (ret) + return ret; + + pinctrl_pm_select_sleep_state(dev); + + return 0; +} + +static int dwc3_thaw(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + pinctrl_pm_select_default_state(dev); + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + + ret = dwc3_resume_common(dwc, PMSG_THAW); + if (ret) { + pm_runtime_set_suspended(dev); + return ret; + } + + pm_runtime_enable(dev); + + return 0; +} + +static int dwc3_poweroff(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + ret = dwc3_suspend_common(dwc, PMSG_HIBERNATE); + if (ret) + return ret; + + pinctrl_pm_select_sleep_state(dev); + + return 0; +} + +static int dwc3_restore(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + int ret; + + pinctrl_pm_select_default_state(dev); + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + + ret = dwc3_resume_common(dwc, PMSG_RESTORE); + if (ret) { + pm_runtime_set_suspended(dev); + return ret; + } + + pm_runtime_enable(dev); + + return 0; +} + static void dwc3_complete(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); @@ -2649,7 +2719,12 @@ static void dwc3_complete(struct device *dev) #endif /* CONFIG_PM_SLEEP */ static const struct dev_pm_ops dwc3_dev_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume) + .suspend = pm_sleep_ptr(dwc3_suspend), + .resume = pm_sleep_ptr(dwc3_resume), + .freeze = pm_sleep_ptr(dwc3_freeze), + .thaw = pm_sleep_ptr(dwc3_thaw), + .poweroff = pm_sleep_ptr(dwc3_poweroff), + .restore = pm_sleep_ptr(dwc3_restore), .complete = dwc3_complete, /* From patchwork Thu Jan 16 13:50:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 13941702 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 A092322B8AB for ; Thu, 16 Jan 2025 13:54:34 +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=1737035677; cv=none; b=RANAGcq3DOaUiKvxodAY5B5UnzifS8cC21ZJxD7YXDyX88vwzI9n7UlGF3FOKvobnONoart/WAorAz26MWEKutc0FxYqcfuMZSxqOnnWcNNWieDG328gKwDuK1k7iW3bSmIa5puvjmFy1dWVFtggjJqpB658tfBB6dwbqLlgDZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035677; c=relaxed/simple; bh=0NycYGu5HX5HIzAcJbBdr0cNDobK1Lk+gWnlktNiraE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZIlbxZbEa99JqMbk5h5qqUh1j9ZbunV5m2nO/IBAYLxyJAgeZXWimEGX5Q6ZnEZfAo7bugl9PbdVhfmPkRPHp8dDrmAIl2DRfAUGbB/MvCDypbGd0+KGSR9CTrD88a9T57LTpbFK/fk6mjL4K8to+VD/1msldn1vUqIH1JzehNk= 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=tG72xwNg; 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="tG72xwNg" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2162f80040aso18280215ad.1 for ; Thu, 16 Jan 2025 05:54:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737035674; x=1737640474; 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=tG72xwNgpCNUc77WEbnoHqP/PsDRN6jp32u3HWgMpEOtpX6g71Q0y+qrfBoPnMKBZt zfqkbbmgMYV+GosaHNrPOwOos3gNVoRhAJlFfS9suIoCzdr6kpUeZ9MrRPhMFs71R2aY 3WrG4PDdYmxXmMyZcC/kjH2N+M3X/H6uIGGlZYSYCmn+nL3MS5dWkku7s4LDBEjfH8vj 0/RmEE2XA8a0xiN4ixfEulae+C1huonY40hKamPRidJetDiEa3YIBSyCsjFn4FOsFZ5+ s33ssgPgsRFsYd/ugGJuFsQ7c5F+DhPvymZ3Oi/euJ4mBYZAz9hzjdOF8AF8x9ErNbqh pdpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737035674; x=1737640474; 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=i+zWGUlaZqX0CFinYkTUlEG8S+3seRZSW9ncBxPTU01lpY4CoHuJyP+drDSAH72KjK rOjOOh898cV9VjW5mnOAniJ6oAYzM+bWy8Umny4j8dF05gNNXrFYf75z8pSDE5kQER/2 U+ynymYAJLRGR9jy5ChSpBv05l6wOl8qmlQqWDtn9qDxaBQK6ykqS/8w7CEoWwcwzTHt haVLpXp2ZSnvawMV76l9V0pMoiWG9oNPBCACzdhocz51CG3Z9XmjFI9zgaylODmbmBgM 0QP40bRQXpn98mVKmHM6JdUcojpMmxnbnUQbVWh7NG5Ch7mBnNxqTsKrvkX1gk715KBt ckKA== X-Forwarded-Encrypted: i=1; AJvYcCWrYdp7lOcUtrtybVfwabkysCiImMevLa3qM03AJKn5WAjB0tMqbciPcuiS2WHZKxNXaKPvqAitXbpb1w==@vger.kernel.org X-Gm-Message-State: AOJu0YwfQmOxkUFFz593gdrHOJLPTzESv80ELScg9PND1n6hvrPWNPSJ ZKBko2r0Fomw6M0gRXfj59ixvzdC3emqwhBfhOHNV3ja0LlSvOUaHLSF68LhwnxqbxXOtbBRk6D Wtz+RM3sPLpV+mA== X-Google-Smtp-Source: AGHT+IEkH31TPDocapE0PpSLmzIIe3ly9TWrLnZP68uAj+iMOBcC23frOUBvtBRsh3pTGeGl/9K/82zsf9tEAEw= X-Received: from pgvi5.prod.google.com ([2002:a65:61a5:0:b0:7fd:558c:c660]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:840a:b0:1e3:e77d:1431 with SMTP id adf61e73a8af0-1e88d10ccbbmr53259101637.23.1737035673983; Thu, 16 Jan 2025 05:54:33 -0800 (PST) Date: Thu, 16 Jan 2025 13:50:14 +0000 In-Reply-To: <20250116135358.2335615-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250116135358.2335615-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250116135358.2335615-3-guanyulin@google.com> Subject: [PATCH v8 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 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); -static int xhci_plat_suspend(struct device *dev) +static int xhci_plat_suspend_common(struct device *dev, struct pm_message pmsg) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct xhci_hcd *xhci = hcd_to_xhci(hcd); @@ -478,6 +478,21 @@ static int xhci_plat_suspend(struct device *dev) return 0; } +static int xhci_plat_suspend(struct device *dev) +{ + return xhci_plat_suspend_common(dev, PMSG_SUSPEND); +} + +static int xhci_plat_freeze(struct device *dev) +{ + return xhci_plat_suspend_common(dev, PMSG_FREEZE); +} + +static int xhci_plat_poweroff(struct device *dev) +{ + return xhci_plat_suspend_common(dev, PMSG_HIBERNATE); +} + static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg) { struct usb_hcd *hcd = dev_get_drvdata(dev); @@ -524,6 +539,11 @@ static int xhci_plat_resume(struct device *dev) return xhci_plat_resume_common(dev, PMSG_RESUME); } +static int xhci_plat_thaw(struct device *dev) +{ + return xhci_plat_resume_common(dev, PMSG_THAW); +} + static int xhci_plat_restore(struct device *dev) { return xhci_plat_resume_common(dev, PMSG_RESTORE); @@ -553,9 +573,9 @@ static int __maybe_unused xhci_plat_runtime_resume(struct device *dev) const struct dev_pm_ops xhci_plat_pm_ops = { .suspend = pm_sleep_ptr(xhci_plat_suspend), .resume = pm_sleep_ptr(xhci_plat_resume), - .freeze = pm_sleep_ptr(xhci_plat_suspend), - .thaw = pm_sleep_ptr(xhci_plat_resume), - .poweroff = pm_sleep_ptr(xhci_plat_suspend), + .freeze = pm_sleep_ptr(xhci_plat_freeze), + .thaw = pm_sleep_ptr(xhci_plat_thaw), + .poweroff = pm_sleep_ptr(xhci_plat_poweroff), .restore = pm_sleep_ptr(xhci_plat_restore), SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, From patchwork Thu Jan 16 13:50:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 13941703 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 D376922A804 for ; Thu, 16 Jan 2025 13:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035682; cv=none; b=LpEdKSthSO48+NmQwVVE64FI3ACoop16ek1yLo4hZ0BZO0P+fOXtA36et+1lfKYIzDZ1t153rhypYp6GnvBwgCuKml93U1yepZYIIesQeZ6FvieEdhlBNijyQVBbuzcbu/iENQLDgUvgUwHsqc3lDPOduoksyvtEEPs+XNMja6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035682; c=relaxed/simple; bh=iHbXpApZXMdoYmO22LcNZiKWepotlBPXNi3hKmTmmTQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CpRHBbbkiLUSlHQkzLeqClaOBIQzgkvKqpp8N6nutJRoEepqsETruMujZ4qbwTxMxrIB3F/ekqrJg6rF66U/j//2vjq5e/HJY3xyxj0ZNN+vcS4AHOye+5vGXOqJM7L9z5ovAOTox8I0iJLTQOM/UmAIbWwGcE0mcMn6DU0lfyU= 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=zXM7CRV2; arc=none smtp.client-ip=209.85.216.74 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="zXM7CRV2" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ef114d8346so2043205a91.0 for ; Thu, 16 Jan 2025 05:54:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737035680; x=1737640480; 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=zXM7CRV23PYb7E3Eyo0jd9wkVBdN+KBRFM3sVdGmk8mnL23rDTnWo+q8mXve+I/7Yb 2jup6msmE96/yNjPx+JFQviaRp8H1pWi5dCA/FQGe4c3b7R1ujM76sbbaBCygz9ROFDD zHeAYHVgFJOSrNOjyOgn0XG1kjyms4isd8LK8GHSOD8JRJrlUTqmVx/azG4eE+7Sq7DI cJOi11zi2Uk5S+PgFzbw9oU7y0BbZJEy1Nm2l5yVQaejPdt++NJvAYTi3AW7hjcfkcq8 wb/TZVD0XmoK56tTeremOjbjU6ynUOnuAM/H/0ED+HgNJYjZ7MWu+UfV8IUsEZDqftE1 Owag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737035680; x=1737640480; 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=K3jlEAxY2yjjFtE8sxXspHyV6C07qfoAyE1khvXVTi5a23aw7kYpAcyD4Th1HgH6Bx ACCoCYwK71RTY/5Z8Y0XBXcWiSEjO3rhcNDZAVNjqm/qmlY2XvbzjwU+u+B7gVrsOvvj YIhsyr2QPp+Y51Ot2UCBGZjiEsajyl91Fp25ihSzUvr3JLNUohbjNdvAe5NBPI5cnw+7 0o5Kfcj+PEhZPvZwWK7dQJKM5LDzWZ4VkkawwwwgvNH5EguxHZ56GPwTze637zxlE5vg AHXKkOSJYyt1eUMXUoB2xSCQ4ViBJFjrpOOqtG72iNB/1A06mGhGBH8CCvwb7nWvI6ek xSYQ== X-Forwarded-Encrypted: i=1; AJvYcCXOy4r6eM/3eH0Kz00BYBSfDE65Ylyc+dcj2D7z47okAQT4sGZ2rxJNkai0Oxecn6iJQqluRKoyJCCVFQ==@vger.kernel.org X-Gm-Message-State: AOJu0YyaLiUwdbsC7NazwEAG0oD7N8Ki17Y1tggfz2p7J/lwDOBIkylp ErgdbT1DV0R4xgkevEqtY6vrMPvKsAUiBOtj3ZKxJia5M2rb7y8xw+q5Z+zfzdw4KN2R+cVrZQ7 ap+8WDlP9JQRL3w== X-Google-Smtp-Source: AGHT+IEFXpmhl6Uk6fSDur8w3nPtXbWer5SIEq/xjrwyyv25VZQnR2zXm1NoGGgYMQnYj1N80prvPspuV5zRs7g= X-Received: from pjbcz3.prod.google.com ([2002:a17:90a:d443:b0:2ea:aa56:49c]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:56cb:b0:2ee:c04a:4281 with SMTP id 98e67ed59e1d1-2f548f102demr43736693a91.6.1737035680439; Thu, 16 Jan 2025 05:54:40 -0800 (PST) Date: Thu, 16 Jan 2025 13:50:15 +0000 In-Reply-To: <20250116135358.2335615-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250116135358.2335615-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250116135358.2335615-4-guanyulin@google.com> Subject: [PATCH v8 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 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) #endif /* CONFIG_PM */ +#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 handling 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 == USB_STATE_NOTATTACHED || + udev->state == 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 = 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 == USB_STATE_NOTATTACHED || + udev->state == 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 = 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 = 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. This + * information could be used for power management or other forms of resource + * 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 = 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 = { .name = "usb", .match = 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 *parent, dev->lpm_disable_count = 1; atomic_set(&dev->urbnum, 0); +#ifdef CONFIG_USB_XHCI_SIDEBAND + refcount_set(&dev->offload_usage, 0); +#endif + INIT_LIST_HEAD(&dev->ep0.urb_list); dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; dev->ep0.desc.bDescriptorType = 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 driver. + * @offload_usage: number of offload activities happening on this usb device. * * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use @@ -731,6 +732,10 @@ struct usb_device { u16 hub_delay; unsigned use_generic_driver:1; + +#ifdef CONFIG_USB_XHCI_SIDEBAND + refcount_t offload_usage; +#endif }; #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_device *udev) { } #endif +#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. */ From patchwork Thu Jan 16 13:50:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 13941704 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 4485B22BAB0 for ; Thu, 16 Jan 2025 13:54:46 +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=1737035687; cv=none; b=SXSfJdheaIhNdetLGFyg0por8dQt+PnzGLV0y8Rkbf/9qAd86Tf56+nKRMJ7TmAr3gru82WmVy/VgvE/lBTUBbjeKxK7tthP51gXbQoij3tYBw8ZXBYyjZMQd3W3wuyHbR1pbglijLj76S8ATPAMKYmzlUOHgEKGca11nZApd1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035687; c=relaxed/simple; bh=44d/KNFe8ozkeaq7IQ5Sv9h6dT0hWOgYDawnmRWXc0k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Qvl1FwQtQpWGdZ7chIDIQRQtP9BBgvboif+SZix9uI1c5f9cE38chmOa95H0HP9DLaSxGTtdDJFdNu3WR6NTEOSGgHmrbZyner/skG+rhYpkrOpda++vzQ6UI/NIZS/UgXJ+jH9zig8NztHeJQJT3dlR9Q8XdxR3Hr3vsSstxeY= 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=Mo7Vu29J; 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="Mo7Vu29J" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2164861e1feso17947175ad.1 for ; Thu, 16 Jan 2025 05:54:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737035686; x=1737640486; 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=Mo7Vu29JiXXtNA8+gyzykHt//UxzBkojog95A9vjED4JQK8e7OTVlENraGZBk7Mxli AYWSewxr35Ki4y1KjYiyIwSaABBUdPjxmJo0D5SmBfPFP2EnzWF3CcX/mKzj/AJs96qK XNF1U/7IBumZEPw2GayixhGeTf2TUCjnNdWG1DUjT99i8W1uDAQtB23gta6ZUZNrBH9j lSYn6vnuf87pOM9CcSpeG1hHjaqIOtrGcjhbSzi/SlkcV33vUoPgzU/MWfdnftPDXxXi OUuTvGBEQbg+OUAa/g6mo+HNq/jw7pmBtzVIEZh28tK3t1vl2TeUbb5Q8OI2pPNbBvfH tmhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737035686; x=1737640486; 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=Gj+pPgmYstkfCeTl9PBqXdHWt9m65hIoAXTErbTDIApAiL9ffVKfU+SiDe6S3NRkY5 i4GbyVWbe2wMV8pvO00sWWOD6LNKOrv5t4ZGHLzFORpyrW5P7nBDBfGyMweVQIlEeSNp 79PbX6XG2bqg35XbPldxENp8GbUVs3oiiUI/8hJDPivxWNiOTORmzQ9Y9GLrgaeHERCI 5gkox+PBMevPExLm/NOMVkt+I3pnkPc+VACOoZlyTH0HpYbhFrQ/2ssRCanCJQHdRdwd zz6jzT/+hpEZMXmjf+Lp+odBXc9uYipnrZjOG+cPbG3U9LEuD1M7/dYnJuttmuGrvvMU kSJg== X-Forwarded-Encrypted: i=1; AJvYcCXYH8+NQr4sYUS+IQloKKFNMmPcghekLHZQjGlHC9Bl/blQh8TUiaMVR8iy5Dv2Lrw/b/Te/A8sOgetjw==@vger.kernel.org X-Gm-Message-State: AOJu0YwISi/Fma0UqQ1xGoIGRixxjddMOac9uCPoMhZ7MIpuTNm2vG7O 8GdXWqJHoRQy7SiWEFs4hX3TSR8yrj+V/UGhcrDFQH8ATwvVABCMGX/QKt8XxPLNWo9TVpPIXsN xlD+p4JCFl1+epQ== X-Google-Smtp-Source: AGHT+IEN6RJMTRCurCA5eBKu8ibDx+SBYtk85d0q5M8XnMck/wVGJLpwmEbnoafhYxK2i9Tb3qQcC2ddBxlcFQ8= X-Received: from pgy29.prod.google.com ([2002:a63:185d:0:b0:a97:3102:ea5d]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7881:b0:1cf:27bf:8e03 with SMTP id adf61e73a8af0-1e88d048873mr50006234637.26.1737035685770; Thu, 16 Jan 2025 05:54:45 -0800 (PST) Date: Thu, 16 Jan 2025 13:50:16 +0000 In-Reply-To: <20250116135358.2335615-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250116135358.2335615-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250116135358.2335615-5-guanyulin@google.com> Subject: [PATCH v8 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 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-sideband.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); +/** + * 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 instance 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 = 0; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd = xhci_to_hcd(sb->xhci); + udev = sb->vdev->udev; + device_lock(&udev->dev); + ret = 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 activities. + * + * 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 = 0; + + if (!sb || !sb->xhci) + return -ENODEV; + + hcd = xhci_to_hcd(sb->xhci); + udev = sb->vdev->udev; + device_lock(&udev->dev); + ret = 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 controller + * + * Allow other drivers, such as usb controller driver, to check if there are + * 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 = hcd->self.root_hub; + bool active; + + device_lock(&udev->dev); + active = 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-sideband.h index 72aa17eb068d..6de1d9c161a1 100644 --- a/include/linux/usb/xhci-sideband.h +++ b/include/linux/usb/xhci-sideband.h @@ -11,6 +11,7 @@ #include #include +#include #define EP_CTX_PER_DEV 31 /* FIXME defined twice, from xhci.h */ @@ -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); From patchwork Thu Jan 16 13:50:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guan-Yu Lin X-Patchwork-Id: 13941705 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 05D9222BADF for ; Thu, 16 Jan 2025 13:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035692; cv=none; b=SAhc5f4/blJouTeTyiRcLi1p4w6DMR6AABzhXl4bZcoXfpR96i5YfNuR6U1cIuBgd1WP0eVeMvE4QKHcgwAkBbNQa0u9kXBei1HnRxi1NrqfImd4RQXbvz+3rlnvHA4rtBxxvv1T1B6hIin16Bz32IdeABPZ+vrOHlAzurB68h8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737035692; c=relaxed/simple; bh=tUjefOwafsseucnbiLWYgdphgCgIdur/lXiNIX80kgA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GUG8pdSPK1IJoWHS6GCW+tGFWzomVtc/zRFa5IeRoY6mg/QT8CNNkc9SlGDPooeqe344/G/XbTlRG/TLRx6MB0lp44KQaKdShBpW8oK7Itoh/q1423wRHrhaALP90fAxoXHfsirmxh8lbAg7oaKiVZh2/FFY+OGQIo8aa6r/bew= 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=F29hdy05; arc=none smtp.client-ip=209.85.216.74 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="F29hdy05" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2f46b7851fcso2954218a91.1 for ; Thu, 16 Jan 2025 05:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737035690; x=1737640490; 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=xwn6iGbuRtN04xqe3vFVe3ONk5MpqAVXvEfWYNrWPPA=; b=F29hdy05He1V6yoHwziHSpbs2fPe92c3lfopFnJm4i5Uhs1WjOYIOPnuZepEKLWoxo un1CcCUNfKkSOATXYhsb1Krx/lqqWz+5p7dZzCusz4QeWGwNMjZs61iohK/zZqermGkL 0HAwxPEWXuOjOpKdc7+PJrhQSMhkBKML12Hrbfmxl5jpi1sciPaq10kq6eGOQEGMCFhM 2OYfnnsS6NRL4yTh/SLosmtLom6YBAYvAt/bgTyA+wZ8EWXvTy0scIvcGuO5IPJTKxKH TEURnDaqOIv93St4EVcHtrqXQshtOJtb09/DLgiWOpFVz31viGFJ410AlPFOtkkAKFEs zYbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737035690; x=1737640490; 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=xwn6iGbuRtN04xqe3vFVe3ONk5MpqAVXvEfWYNrWPPA=; b=rTF9FwZNDd1/bClVo+tZx2xV5WV2DVmaA/vmwxogJyOL4Sdh6xpVDl4oVwMvsKvpim eSRKvkorG8p0P+1bSB5Gee+L82fqZQe4adFDQUHzHzKysqM4dgdSQmGj5Y7xYFrZNtH8 KD0nkTFEpr/fYDhKwVme2TMhWdmTZZ/nVpN879q0CRhwJ7a8vgIeLu0NvqB7X3UFUv1L ASiTtV7gE1hDoMBvawuKUjrdtW59kEMjAVyF+OzHsPphkz/g7RTLww4c4U1O0bBVADTJ lwqvKHwgQlKMfDw8c6iXrf7ykRk01tbrDzCiTJw5IGtJI75+42dH+yXYz5NAuz1VRnnd HzDw== X-Forwarded-Encrypted: i=1; AJvYcCW5BRCp58o/MpbgGEUOXNXa3ou9875NwR2WWvXZHcV5+MnQTRKcATNoVz2OMYpnahwTyF3xytmxEEdSdQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yw8kjJ7BjCEAAk+cyhJEoslQ79Fps7qdIxs8vZuPTH3Tv8RAXqd PKfCtSSXO2g3qLYojM9RjmY/g4asU2L+4hK3BL1VtZF0iSRbctLlJYN7id4DAHe2YJv2o+rd3x3 HHXh5Rxz/YHEgTw== X-Google-Smtp-Source: AGHT+IHSbpnc4Yeh5feaJxP2xbzgigNdCiHt0WowqTGKRkjIvnXACFCzzbUW7yHLOkc/HSqYiUU3VDtfmNeAGIg= X-Received: from pjbpt8.prod.google.com ([2002:a17:90b:3d08:b0:2ef:95f4:4619]) (user=guanyulin job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:274a:b0:2ee:7862:1b10 with SMTP id 98e67ed59e1d1-2f548f2a149mr50723470a91.11.1737035690360; Thu, 16 Jan 2025 05:54:50 -0800 (PST) Date: Thu, 16 Jan 2025 13:50:17 +0000 In-Reply-To: <20250116135358.2335615-1-guanyulin@google.com> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250116135358.2335615-1-guanyulin@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250116135358.2335615-6-guanyulin@google.com> Subject: [PATCH v8 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 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 | 29 ++++++++++++++++++++++------- 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, 82 insertions(+), 16 deletions(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index 1bbf9592724f..6441742869ff 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -1413,19 +1413,31 @@ static int usb_resume_interface(struct usb_device *udev, */ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) { - int status = 0; - int i = 0, n = 0; - struct usb_interface *intf; + int status = 0; + int i = 0, n = 0; + bool offload = false; + struct usb_interface *intf; if (udev->state == USB_STATE_NOTATTACHED || udev->state == USB_STATE_SUSPENDED) goto done; +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (msg.event == PM_EVENT_SUSPEND && usb_offload_check(udev)) { + dev_dbg(&udev->dev, "device offload active.\n"); + offload = true; + } +#endif + /* Suspend all the interfaces and then udev itself */ if (udev->actconfig) { n = udev->actconfig->desc.bNumInterfaces; for (i = n - 1; i >= 0; --i) { intf = udev->actconfig->interface[i]; + if (offload && intf->needs_remote_wakeup) { + dev_dbg(&intf->dev, "interface stays active on an offloaded device\n"); + continue; + } status = usb_suspend_interface(udev, intf, msg); /* 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 == 0) { - status = usb_suspend_device(udev, msg); + if (!offload) + status = usb_suspend_device(udev, msg); /* * 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 = 0; - for (i = 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 = 0; i < 16; ++i) { + usb_hcd_flush_endpoint(udev, udev->ep_out[i]); + usb_hcd_flush_endpoint(udev, udev->ep_in[i]); + } } } 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" -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 = dev_get_drvdata(dev); +#ifdef CONFIG_USB_XHCI_SIDEBAND + struct platform_device *xhci = dwc->xhci; + struct usb_hcd *hcd; +#endif int ret; +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (xhci) { + hcd = dev_get_drvdata(&xhci->dev); + if (xhci_sideband_check(hcd)) { + dev_dbg(dev, "sideband instance active.\n"); + return 0; + } + } +#endif + ret = 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 = dev_get_drvdata(dev); +#ifdef CONFIG_USB_XHCI_SIDEBAND + struct platform_device *xhci = dwc->xhci; + struct usb_hcd *hcd; +#endif int ret = 0; +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (xhci) { + hcd = 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); 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 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 = hcd_to_xhci(hcd); int ret; +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (pmsg.event == 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); @@ -499,6 +506,13 @@ static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg) struct xhci_hcd *xhci = hcd_to_xhci(hcd); int ret; +#ifdef CONFIG_USB_XHCI_SIDEBAND + if (pmsg.event == 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 = 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. */ -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) /** * 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; +#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__ */ #endif /* __USB_CORE_HCD_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.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_handle *handle, mutex_lock(&chip->mutex); subs->opened = 0; mutex_unlock(&chip->mutex); + } else { + xhci_sideband_get(uadev[pcm_card_num].si); } } else { + xhci_sideband_put(uadev[pcm_card_num].si); info = &uadev[pcm_card_num].info[info_idx]; if (info->data_ep_pipe) { ep = usb_pipe_endpoint(uadev[pcm_card_num].udev,