From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.130.70 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624372; b=z/MNtxTmC25PkTNMaI4h1v5eiJ+ILONwZk6VvOXsbNXDE2gll0MEX1dPtGAxtv1S/n66 PfUqySKgNlvbvKMPvPQvjE5c85757dwzS6/9I1+c/1xg5LfC1QnTU6/dnHxd7jxYS7CG0 YUZHf3TNSGcopu2qK9pGo2LxSPkkcq4l1BOTr5VYhKQWiehsGuBOGXDP+MxoXCt2HWRRY xXFCc1BrbRfSxxbajguKpbuDg7V+dmharrBenaPXecOtw6v6vNeFZcqD2eVNBcg/9eDrr /UIn7NGfsiqnjZWo27bEoVhJ84ibXVnuRNzlFxdyXw1Phj5z4lt1j8X2JMYbWwZet0g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624372; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=WTT5uAKxCp1y51P4lhR+sRkq309dyXeCTveWZSftt9s=; b=1m6fEgc689DCiZsMccqQY82zopdfaO7gnWh4TvUAPrgoCu9VR/awxTPZJIBe39mPj3n2 +V5pM0DsE01dU1/f3kl+QkVFxf5vLPDAMdBQFS1ZrlAmAbaiEo+9KTMTSgA2vydGIVUev CkZrfEjXdicN0oL8yDnGgNncsyQ23mKEFfHAZpLH2pAZqe0Ch0NnVSTxNxdTGT4LDkuFs fjJ35niMlpFFLCZ257LsB7qxgAJmGictwRO3EdrXxxFP6wRJ/oPkn127w8ekBOyQF7Dqm ro0Lf6ttNgyOgBNPBEYetWz0cYTiPUBdbr/BSqLFx23DSNCU899i76pBQd1Xwf3YZdw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=MkdDwyoH; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.130.70 Received: from MRWPR03CU001.outbound.protection.outlook.com (mail-francesouthazon11011070.outbound.protection.outlook.com [40.107.130.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C87D9606A68B; Wed, 25 Nov 2026 16:32:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C87D9606A68B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=MkdDwyoH ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jl/NdJRHcbkZi6ttumYLx9v2ABHPzL0CGqKH9mU80dJ1rGvLUPXe4vNMPwxfX8RcCkCqw3/hQrpISNLS+J6+GC7542HFssnM8nozy1+v9asd7pt36FeMX2uVds+d0fc/OjKdZ6gj+m8vHgC8bHzDsz4T6nwNaSsBwRJN65j5hi1rUn3irUTmgx2O2chTQeX5XMmqJ4aXVANRxmZsAap4T++Jhe7oTiow0lGHo9JAoaDeiVe/zNOcXAP80flhsJ34q/1O29pqOsKXe+nR3Yrr2jGd9vNCBJqQrJwa7T1oKdx6Spl7yhKuqSscYiE7bDmgPuJAg2j3AXGD0ONuWjLNlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WTT5uAKxCp1y51P4lhR+sRkq309dyXeCTveWZSftt9s=; b=m50csLDCD0RflExMVNyBuJ6g730M3Jra0jcVpzG7Gp+qvmvQbO+YQaArjOQ2HN1UOzrTDSsb0Kg1Za1Wq0e0FOvcTXciGiyzX/zyKkvGY9TZlfK5ALDchOsb914qaW2sYSBsYAVgzrxlAE7Jb7R+AsjSeZR7+kmIhvkqLyuyYoiEMIngE1H8mKuBJPZ16+x6sw/+8nWwKuRrNVXKNbM+f0h+6cprofFTZmThdLXmpW8y/hjr4WklhD0ZVgw6cf07bia+kbQ9b2tgeYNigKfjrgYj7DdKi38QGXrBPsm2PATi8G8kOtEP1fr0zWA7zo16pi2l8Yf6mZqocNi1dHXbmA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.60) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WTT5uAKxCp1y51P4lhR+sRkq309dyXeCTveWZSftt9s=; b=MkdDwyoHBWVFE4IqhYnB1W4oo7m1vaVmoebywxNRlysCZGf3XUCta/N5Pa5N/vFwXGxtWtfSpWY8VDO1ASRMJBbVXHle74NaDAaCXSKAb1x+GkL+jXe0fgWcTkdlNe2eTPYpCQcTkcALLOuMxiaBPWPVDQY4vrq93nWTwfeabB/jnhxZj3svCxUkkSV9yhiHrFQgATSNCvK3PEnxrNzXtEbUgOqXEjPwT0yVTeoa2gKYtk9HT/Yx/GUtWhGyATfAmHL9NdcQXYM0gemZ7oH6Fln8bFTQ63hd2Yu2hDJjboxt02iKzfsbwCw5CfQPOp2YrQwUPV61hvazg1mWOd2Iag== Received: from DUZPR01CA0329.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::28) by AM7PR10MB3304.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:10f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.6; Wed, 25 Nov 2026 16:32:46 +0000 Received: from DU2PEPF00028D04.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::51) by DUZPR01CA0329.outlook.office365.com (2603:10a6:10:4ba::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.7 via Frontend Transport; Wed, 25 Nov 2026 16:32:45 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.60) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.60 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.60; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.60) by DU2PEPF00028D04.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.5 via Frontend Transport; Wed, 25 Nov 2026 16:32:44 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpO365.st.com (10.250.44.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:49 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:43 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:02 +0100 Subject: [PATCH v6 01/11] usb: dwc2: fix recovery after PM domain off X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-1-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D04:EE_|AM7PR10MB3304:EE_ X-MS-Office365-Filtering-Correlation-Id: ee782e58-6b5e-458b-cb4d-08df4b11bbde X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|7416014|376014|1800799024|36860700016|18002099003|22082099003|6133799003|261009223027099003|11063799006|56012099006|10067099003|261102123227099003|261026140227099003|261022105027099003|261022075727099003|261026121527099003|261021123027099003|261028144727099003|261021121427099003; X-Microsoft-Antispam-Message-Info: YVzpRvT1SBosCiogJAXbBuDXoydpfC0cx0A1n6VG0Hu0se66JjpS5X0AG4oM2bMcmSExFtEw4euB0cOa0bf/RH8NyaIFpf4zNdRLeGOmpNgH1ILDe/KSrNpHyPsNk5dFdi3RJUr0UJhJyA7giHg3QKj/bEEqxi4alRjleFZpeGx9aeKCuKLoO14a902GLc4qu7Vn9/MEEH7hHFnGrN/Eo2SqdkEPiQz1iqYwoLQXHKJwnDVprCKQnBRVFETAd3vg7TV9Vkg4N+4tb3rTt30MCrWLRHSC7xGwqyIIIoKYoqNpWe6THJz00tut0rJUfugZV4Hovp5dgdi0Tbhramp6x+Oj3zns9hMVpHKOdQncR08Mccun6MV/xFKBojlDF0SRBQGMnFP8a7zLEehLwP+bDvTIHU8nmfbE8NMjcipMx7p89LT2UBixbGPZuPYN4NqeYORRKmwNHT5Iz8D3RL7byXebJZVv7RWwzBSfx3G6Q727PpkK+EqWmTaP/p60BPOuvt3/0wyaocIlwHhwlypDw+u1rDWUG44CCiv3K25OI96TH4Qb/O2Q7uf77gyU1OdNNJd/AgftDEmCpk4tpn8TRYy36RlbnXJ663NOpXjNuxejwV0IX/rKOwE1JUhlalR4WITKEeN2dhRx29O/LokfE7K+Uim1z4SSeWSQy4KBXDptR3bNkacy2fCzxTO6sO361TvCQC8/km12/7p9KJtpHg== X-Forefront-Antispam-Report: CIP:164.130.1.60;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(82310400026)(7416014)(376014)(1800799024)(36860700016)(18002099003)(22082099003)(6133799003)(261009223027099003)(11063799006)(56012099006)(10067099003)(261102123227099003)(261026140227099003)(261022105027099003)(261022075727099003)(261026121527099003)(261021123027099003)(261028144727099003)(261021121427099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GHXewGAdDAAezydU8NWNffe7P+WWC3EkowY7ZbMTCo7TwMs2Qk6CUKgVsWeyojXeC85/WldINumuP/NjcbaRyNTOAH6rF2Mxsvx8bRHh6uy3x1YqnDdqrJT/vUylOdqq9+FOV8LIEnE9BD8wi9ViVs2D8sCAZF335yTugTMVLhMbfdKdlOvSFZl1cQ0LIlJrruCwmewU5UiY/iB+jLQNULJV8HygexFgeEkXdbyZ7xuALs4Ji0gRgiwl7TlWwWLXBDnGgDJCkXIdePabu5f5jC+4MubN6/9SmMNsbjEAnMTY0wcZ8gXQ9S3MaT1Y2gjoVe2PIJkIlbQMPeSdYveRdwqyjiT+McF0gpRl+YBX4Q5wNrKOBTrThI/mDzsNvTJjSrWUwldJ/BUnitWQ3tKElMkcf7vwtdLsXiri6TBB4xyMRS5cX1cqcWxXlay0j6Tw X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:44.7122 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ee782e58-6b5e-458b-cb4d-08df4b11bbde X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.60];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D04.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR10MB3304 When the power domain containing the DWC2 controller is disabled during suspend, its registers are lost. Reading registers to back them up from dwc2_suspend() after clock gating can hang STM32MP1x in both host and device mode. Host suspend enters clock gating directly; in device mode, this can happen if the host suspended the USB bus before system suspend. Instead of unconditional backup of gadget/host registers, check if these registers have already been back'ed up (e.g. gr->valid =3D=3D true). This is the case when the controller has already been put into one of the low power modes. This avoid unclocked access. When entering clock gating, add backup of the gadget/host registers. This will address the case when the bus has entered suspend state, prior the PM suspend sequence. Discard the valid flag upon exit from clock gating. There's no need to restore registers in clock-gating exit routines. Protect the backup/restore of the registers against interrupt that may arise during these phases (with a spin_lock). Move the registers restore after the STM32 vbus/id detection glue has been restored, as a wrong mode may be temporarily observed, triggering ID status change IRQs. Fixes: ba6e518d136b ("usb: dwc2: Implement recovery after PM domain off") Cc: stable@vger.kernel.org Signed-off-by: Fabrice Gasnier --- Changes in v6: - Basically keep original approach instead of reworking it as discussed with Stefan. - Re-visit the way to restore registers: add registers backup in clock gating entry routines. When controller is suspended (bus suspend) and platform PM suspend is requested, the registers have already been back'ed up so the problematic backup phase becomes redundant and can be skipped. - Address sashiko remarks on stale variables in subsequent separate patches to ease review. Changes in v5: - Sashiko comments: stale variables in device mode, possible race caused by early call to dwc2_enable_global_interrupts during dwc2_resume(), drop outdated note from the commit message. Changes in v4: - Disconnect the gadget and clear stale endpoint and low-power state. Sashiko comment "usb: dwc2: incomplete gadget state cleanup in dwc2_hsotg_resume()" - Reinitialize host state and clear stale backups after register loss. Sashiko comment "usb: dwc2: incomplete host mode recovery in dwc2_resume() after PM domain off" - Revisit commit message Changes in v3: - Add a note in the commit message since Sashiko comment on _dwc2_hcd_resume() check on HPRT0_CONNSTS bit. - Add need_restore flag and pass it to dwc2_hsotg_resume() to avoid possible interrupt race with lx_state update as raised by Sashiko, instead of updating lx_state to DWC2_L0. Changes in v2: - In case registers have been lost, ensure the device mode resume takes place by updating the lx_state to DWC2_L0, as reported by Sashiko. Note in case of error in dwc2_core_init() choice is made to leave the low level HW init, as it is the expected state out of the resume routine. --- drivers/usb/dwc2/gadget.c | 13 +++++++++++++ drivers/usb/dwc2/hcd.c | 12 ++++++++++++ drivers/usb/dwc2/platform.c | 42 ++++++++++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index adc3df0ca7dd..02c93a41043a 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -5766,6 +5766,15 @@ void dwc2_gadget_enter_clock_gating(struct dwc2_hsot= g *hsotg) =20 dev_dbg(hsotg->dev, "Entering device clock gating.\n"); =20 + /* + * Clock gating doesn't need a register backup. Do it here anyway, in + * anticipation of a platform PM suspend: once the USB bus is suspended + * and the clock gated, registers can't be read safely (access may hang + * on some platforms). dwc2_resume() uses this backup to restore the + * registers if the PM domain was turned off. + */ + dwc2_gadget_backup_critical_registers(hsotg); + /* Set the Phy Clock bit as suspend is received. */ pcgctl =3D dwc2_readl(hsotg, PCGCTL); pcgctl |=3D PCGCTL_STOPPCLK; @@ -5792,6 +5801,7 @@ void dwc2_gadget_enter_clock_gating(struct dwc2_hsotg= *hsotg) */ void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeu= p) { + struct dwc2_gregs_backup *gr =3D &hsotg->gr_backup; u32 pcgctl; u32 dctl; =20 @@ -5820,4 +5830,7 @@ void dwc2_gadget_exit_clock_gating(struct dwc2_hsotg = *hsotg, int rem_wakeup) call_gadget(hsotg, resume); hsotg->lx_state =3D DWC2_L0; hsotg->bus_suspended =3D false; + + /* Discard previously stored registers */ + gr->valid =3D false; } diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 40ab50538334..db6126cd72c8 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -5935,6 +5935,14 @@ void dwc2_host_enter_clock_gating(struct dwc2_hsotg = *hsotg) u32 pcgctl; =20 dev_dbg(hsotg->dev, "Entering host clock gating.\n"); + /* + * Clock gating doesn't need a register backup. Do it here anyway, in + * anticipation of a platform PM suspend: once the USB bus is suspended + * and the clock gated, registers can't be read safely (access may hang + * on some platforms). dwc2_resume() uses this backup to restore the + * registers if the PM domain was turned off. + */ + dwc2_host_backup_critical_registers(hsotg); =20 /* Put this port in suspend mode. */ hprt0 =3D dwc2_read_hprt0(hsotg); @@ -5967,6 +5975,7 @@ void dwc2_host_enter_clock_gating(struct dwc2_hsotg *= hsotg) */ void dwc2_host_exit_clock_gating(struct dwc2_hsotg *hsotg, int rem_wakeup) { + struct dwc2_gregs_backup *gr =3D &hsotg->gr_backup; u32 hprt0; u32 pcgctl; =20 @@ -6006,4 +6015,7 @@ void dwc2_host_exit_clock_gating(struct dwc2_hsotg *h= sotg, int rem_wakeup) mod_timer(&hsotg->wkp_timer, jiffies + msecs_to_jiffies(71)); } + + /* Discard previously stored registers */ + gr->valid =3D false; } diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 3df9b198d1b2..7f3436e6a153 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -649,6 +649,8 @@ static int dwc2_driver_probe(struct platform_device *de= v) static int __maybe_unused dwc2_suspend(struct device *dev) { struct dwc2_hsotg *dwc2 =3D dev_get_drvdata(dev); + struct dwc2_gregs_backup *gr; + unsigned long flags; bool is_device_mode; int ret =3D 0; =20 @@ -692,10 +694,15 @@ static int __maybe_unused dwc2_suspend(struct device = *dev) regulator_disable(dwc2->usb33d); } =20 - if (is_device_mode) - ret =3D dwc2_gadget_backup_critical_registers(dwc2); - else - ret =3D dwc2_host_backup_critical_registers(dwc2); + spin_lock_irqsave(&dwc2->lock, flags); + gr =3D &dwc2->gr_backup; + if (!gr->valid) { + if (is_device_mode) + ret =3D dwc2_gadget_backup_critical_registers(dwc2); + else + ret =3D dwc2_host_backup_critical_registers(dwc2); + } + spin_unlock_irqrestore(&dwc2->lock, flags); =20 if (ret) return ret; @@ -730,6 +737,7 @@ static int dwc2_restore_critical_registers(struct dwc2_= hsotg *hsotg) static int __maybe_unused dwc2_resume(struct device *dev) { struct dwc2_hsotg *dwc2 =3D dev_get_drvdata(dev); + unsigned long flags; int ret =3D 0; =20 if (!dwc2->ll_hw_enabled) @@ -742,18 +750,6 @@ static int __maybe_unused dwc2_resume(struct device *d= ev) } dwc2->phy_off_for_suspend =3D false; =20 - /* - * During suspend it's possible that the power domain for the - * DWC2 controller is disabled and all register values get lost. - * In case the GUSBCFG register is not initialized, it's clear the - * registers must be restored. - */ - if (!(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK)) { - ret =3D dwc2_restore_critical_registers(dwc2); - if (ret) - return ret; - } - if (dwc2->params.activate_stm_id_vb_detection) { unsigned long flags; u32 ggpio, gotgctl; @@ -786,6 +782,20 @@ static int __maybe_unused dwc2_resume(struct device *d= ev) dwc2_drd_resume(dwc2); } =20 + /* + * During suspend it's possible that the power domain for the + * DWC2 controller is disabled and all register values get lost. + * In case the GUSBCFG register is not initialized, it's clear the + * registers must be restored. + */ + if (!(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK)) { + spin_lock_irqsave(&dwc2->lock, flags); + ret =3D dwc2_restore_critical_registers(dwc2); + spin_unlock_irqrestore(&dwc2->lock, flags); + if (ret) + return ret; + } + if (dwc2_is_device_mode(dwc2)) ret =3D dwc2_hsotg_resume(dwc2); =20 --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.66.26 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624381; b=jeEEnuKk4IY7AjdZnS5Fm1mVTEVb6oqmESgubI1RSwXhprn7oxKn+Kzz9SxjYLJcsW/n c6sJQFTqb+NhFnHZwH8TzNqCz1s9Eelo6gdIdPgPX2Ll2CY/02TuMgJ6Gu6MjFC8l8Rfe MJsLGOA4tu+UtLU+IuD+yd04VLH7iuT+ugiY2xVeMV/0hy0oAoPhqK7EmdIx5wWATaFAe n7kEksGttf4lPbyVyFQnr+CvaY+VWneM2hfXRfSEHcjP8TnKRa9hT8VGLDNTNbYVqfOK7 b4x7t6YoXLg5FzphRufJcPJEMm/fB3XR5flRZ3kgzVXjf8Jx1oxkQwjJJsF3hUgDp0Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624381; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=x83gnRExLo5mA8Icuk/MAcOlEsttoRf793T7alLvGkI=; b=LiIcxoEwbuYKKcfK/OTtbfiV2CRXSrKn01mLWmT6N2iYT+dpTYB7rgFFaQFA42P4nwd9 dk1krCzX2sQY7ZAkNkjIVSPmge/LVSW46pZKvzzizjsALFfDsc535DA6BXqPTH7X8snFo RFki5t1YqOcwEogEqTH2OWZYTfOizHuNwFF5kFg8PTlC0wFLCr3wbQpxXQ7uobBxBzmtS aS3ZS56L/ijxGCE6DOIwBW47eOcXQIWZvNHemQb7fcap9hO5wpvAYq2gJeDmKV9OdfqNQ YJgBd2v+LFGusozHzAQptY4VSxFhTnnkNgy5I6VrwKjT9iCPyk1UrZ1/A8/AUt08KTg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=NXTVkluz; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.66.26 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012026.outbound.protection.outlook.com [52.101.66.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8889606A68E; Wed, 25 Nov 2026 16:32:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C8889606A68E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=NXTVkluz ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tcLNprDc3RvFFCl3zlyXrh3UliCaFL0nlobxmdWs5qTXzm1Bq50srNRbOaeHOQhxmngPq/VFtHLCMRfBeFQmJR6GaZWAFMmzaSs8xnd9/KBU6giXIxkocJCS7+fEy2WbjiG1AIJ9ZWdvq26BtrxnyjYSNOPkipLoaUK1fyYTr6CZoyycBX+K88dGjrMsAWxl/mvwLBepkiCUk54GAcKiYabPnCOzJ8670Pj3jZJwHNJENM4+pxwL1vPrY//dlspwujb+0DfArWkYwwARzKISUWqk4GctT4lQPGdufQ0BgLAJhGb6EP5jNDnJ9nTFeJanVdfeSLwUd6bCTAYnHV3HVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x83gnRExLo5mA8Icuk/MAcOlEsttoRf793T7alLvGkI=; b=Xa5zIO7SMxqPOnr2O0VCbEqWP73AUkRO36/Dk5KM8z+72NJ0Y+d6YM5x64NU80HDX3hhOmdvCFeCwRrAxDc3tZwEFHVDtCzEeGqxOIlZJEMtcAJdnb0ID98SA20djB5e0+xH267bl0l2YveG8kB7T49PuxsoiomRKJ+N5Vy+y29vCtSfTwlc9igFaX9JpaFzX2xEQOThEb0rsJNZR8sVJ4phzEgqNkpPL1XPLDr/8FfSX6fAIH4KvWpAHUYyV+F7lPlEyZtZSePsqRqKTTtBhK1Eq7As69GRGeJJ0ulj61XRYYPRqD7KfYfog8sG8bZ2E2klSeh5qKjvc7nHA2G/hQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.59) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x83gnRExLo5mA8Icuk/MAcOlEsttoRf793T7alLvGkI=; b=NXTVkluzBggQkjSRjf6+HEkGUi1y8Kdv5sB7qE6ZFzweXY10XbzEZIp62KiXPpWmP/COQDyWJu9bWqRUywxFfBMhk9DvyU0KAEgB7vsqpoUURNVmhavLao2a4YfAKESeH4QWxU3TnMGsKdY+sGt1OH3n8rzOhtpM6lJrWqlcktrM0CMh2H0DUweXNZlfNqJfsfI30PATdLH82v030rqyKh+Fwqs0H5xbd8LqHdDaPUvxjQXpEPki9hCaWnzBEIkBYOciVbuOXv+vxC5PtQZ3WLhRqmEMXdlJ9lpjfuOUYDUlfWL3Xn3mP8LyYZ96N3I+jILoKxTkyqVjV8CbNjvK8Q== Received: from GV2PEPF0004811E.SWEP280.PROD.OUTLOOK.COM (2603:10a6:158:400::1ef) by AS1PR10MB5697.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:479::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.4; Wed, 25 Nov 2026 16:32:47 +0000 Received: from WA1PEPF00009B3A.eurprd05.prod.outlook.com (2603:10a6:1d8::118) by GV2PEPF0004811E.outlook.office365.com (2603:10a6:158:400::1ef) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.10 via Frontend Transport; Wed, 25 Nov 2026 16:32:47 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.59) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.59 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.59; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.59) by WA1PEPF00009B3A.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Wed, 25 Nov 2026 16:32:46 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpo365.st.com (10.250.44.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:34 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:44 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:03 +0100 Subject: [PATCH v6 02/11] usb: dwc2: keep TOUTCAL canary valid after PHY init X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-2-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: WA1PEPF00009B3A:EE_|AS1PR10MB5697:EE_ X-MS-Office365-Filtering-Correlation-Id: 80cada5c-4bb4-4389-3496-08df4b11bd30 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|7416014|376014|1800799024|23010399003|82310400026|56012099006|10067099003|261102123227099003|11063799006|261022075727099003|261021123027099003|261026121527099003|261022105027099003|261026140227099003|261028144727099003|261021121427099003|261009223027099003|22082099003|18002099003|6133799003|13003099007; X-Microsoft-Antispam-Message-Info: ZlEhOISxMKmp8RtJXGIr6llwG2AyfDFFCT59W2EIBl7PzPzXiO5EEZya7uePlFr2AJNx0JkpVAdJgPJJtyMDx0UdgEmbhLRCxFZf7CWFGS4FW+FTkr4LwWPAz6tWBCMJvpEX20q6OiYRkHYAafFacPTUYyLcyhGqf+pKNzqUjUw6n3TY+6jp5Q0BIwdWJhkco9VrcWDTdUfW44oDeiUtIBKpuER7J9eUUAAbGM0pFqccgZxsqz7a+jh+j6zrfHMh6vTPTji0kNuNGf1cAOwolrKGboYM/voh9C4PG1e7FnsJd3WztTG16oZNuQsJjHg1SfDIwduu50IB9zRR7wyxv66izKH1UZdAanzBEAG47CkoMnllHcJJGvE6ZNHOUlXY2XUAZQeEdZyrAXLszhhiHR++MvKQytwRFZqnl+B/es748FfNepj1Ztk0eF6yVJvSEi6XiBiJ8cZhH/RY5uJNplqvOkV1nmiaKPL3jTaS2BwEABs8Tcnn6AtlpoUah4S7bgqGKvhCE4snOMAOWeWGZ+320OzkNra7j4/jSJUpNlmKNnR8anzhQ1nMEdqPtszIozilifjvcigTAFNYoVkQtEhEhI9/73vEwKy/QgJi+mLHcn2hovnpGDDEzYNTNW9Be+izXPZa4ZG7rbifwqZeXg== X-Forefront-Antispam-Report: CIP:164.130.1.59;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(7416014)(376014)(1800799024)(23010399003)(82310400026)(56012099006)(10067099003)(261102123227099003)(11063799006)(261022075727099003)(261021123027099003)(261026121527099003)(261022105027099003)(261026140227099003)(261028144727099003)(261021121427099003)(261009223027099003)(22082099003)(18002099003)(6133799003)(13003099007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TMYr0cB08JrUOS7zEi194lOpXRm0CbkdGpLMQnA5ePOIVbEQV/HfRTA6XyYORSa37wIIdEuT3Oo9dTFT9pHEz7wjr2ForGpL1v1JYl9Ap1iD7n+QPtE82vvNfM1vRFw1FwE3IEE765CNsr86L8dZPcXAFhTUtqrmh14NmNaaJuxsnFRhpTgApqvkGHoMAANcrlFSmXjGWFpe5XJKJmvZuZ6zK1iWluwfCVTQfXFAP821MsCPa/GRsJSIuUb96LXB9on/ap45HSFGk1YZR/Is+dzL5gC8GgDdxuOSiFhG8dZWUli0EQ9jWGO8MF0m37hnkWKWiHJh5OHZuGjhqCj+NqjYafQcLH2JaNljeW8cQXM6Va6oSwfuz2RIgeziTN1KptLpFf/mLh+Ojkn7hm63H31V15cytmcjoWN0TE82mvYugsRFVGuKnXdg4tnmdUZF X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:46.9409 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 80cada5c-4bb4-4389-3496-08df4b11bd30 X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.59];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: WA1PEPF00009B3A.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR10MB5697 dwc2_resume() uses GUSBCFG.TOUTCAL as a canary for register loss during system resume. PHY initialization can reset the core and clear TOUTCAL. In dual-role device mode without a gadget driver, TOUTCAL can also remain at its power-on value of zero. Either case can make resume falsely detect register loss. Run PHY initialization before setting TOUTCAL in dwc2_hsotg_core_init_disconnected(), and initialize TOUTCAL in dwc2_gusbcfg_init() after PHY setup. This keeps the canary nonzero after PHY initialization and in driverless dual-role device mode. Fixes: ba6e518d136b ("usb: dwc2: Implement recovery after PM domain off") Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/linux-usb/sashiko-outbox-219256@kernel.org/ Signed-off-by: Fabrice Gasnier --- Changes in v6: - New patch to address 1st finding of the Sashiko review of "usb: dwc2: fix recovery after PM domain off". --- drivers/usb/dwc2/gadget.c | 4 ++-- drivers/usb/dwc2/hcd.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 02c93a41043a..5e75d6975baa 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3461,6 +3461,8 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hs= otg *hsotg, } } =20 + dwc2_phy_init(hsotg, true); + /* * we must now enable ep0 ready for host detection and then * set configuration. @@ -3484,8 +3486,6 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hs= otg *hsotg, usbcfg |=3D GUSBCFG_SRPCAP; dwc2_writel(hsotg, usbcfg, GUSBCFG); =20 - dwc2_phy_init(hsotg, true); - if (!is_usb_reset) { dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON); if (hsotg->params.eusb2_disc) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index db6126cd72c8..0d20b9de857a 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -128,6 +128,13 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) break; } =20 + /* + * dwc2_resume() uses TOUTCAL to detect register loss. Set it here + * for dual-role device mode before a gadget driver binds. + */ + usbcfg &=3D ~GUSBCFG_TOUTCAL_MASK; + usbcfg |=3D GUSBCFG_TOUTCAL(7); + dwc2_writel(hsotg, usbcfg, GUSBCFG); } =20 --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.69.26 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624376; b=k8j6zsz9QQr0Yc0GE8PZzPNtuJT9Nb8qSdJtc7gJKYRzUgZMiWxDUl0GRRTYBCQPd7za 4s3Ic3XGsFrWFpiSkzzBlFfPEn6ohkYwEbhk3mlaORC/gbw5T2ZHZwffAg8fwY9I0y2cO l7JKki36ekJjYbuOIYUlhYsiWUBkM83QxcSyGFHCGbPOLdJVwCpjtW9f9humbuqNC3tAe qAqYXINf49FSgm6C13/CrIeF8l8NtU+OBxnwVJDbrZDerhIePqnMTuUSETDMcIVtnvMwN oGH4bXd75JlMkjpkeDFScZG2j2Q6LqqDo/lqylzoLKtCTbO23ZGjQ1QwxKeksZphtpw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624376; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=cX4ieytK3JB714PlJhzyua0FX/8x869vyx/gj+u/EaU=; b=oWZ4thtwPBpWxxBXF/Ite7Eh12JUiqX/tVV8h58dDy7z9FbLQu3ryNQDVI/k5qmKh31K hCH8prVbaRoLNqzbGl7QTHf9evZI/2yum6EJauPNUh8uE1Xj0L6bknErXgdgokfM1ttWx /IqcTO0eYmpia5fiMP62SM51vLtlv05kEAOWZOmKGJPg4//lC4q5WP67bTbryEoAB3aLe ipMgMqOKtYFomJNVO4u2GUbc+HRD7KLaPADdVGxxgE5NBl2ZUktbfBA7pfehjowCSglCb DrPdUKBoeZF/H5Y/SBNJUON/0nl8IWUsN3nVQfsnBjroCyyeSSfT1m/bem59MqUgRlw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=W7EHDPdd; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.69.26 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010026.outbound.protection.outlook.com [52.101.69.26]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E76E606A696; Wed, 25 Nov 2026 16:32:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1E76E606A696 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=W7EHDPdd ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c0JpyeKnZ9eVXyimQpsAdy6q0QhaZrgqGbDumXDOR2IDuapGGvwRYJupll+zNS2r6pW432F2TDWESw1M8HebNyye4w0oHb7AvKAeBtccQae9L0iAtD19/PO2wSAeNBDyWoON0qGL4qnlFddKPYS/gKqd81iZGkECrzao2PZy14+gBoELIOw410ELdwCxC6z4teQyHNohWDYWx0HUuMgh6VElXwxaYcnUTjrE8bVOtQF05sqS5jBHturwXCjerwWoOfmnnWRKBtH/KskQ8O5ZRUFYk5Q7c0iOIEaqgYUk0ChfGmIAk3LbrgFFpcZB/JdDqXUOkHpvq8TYSqDO+SuV2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cX4ieytK3JB714PlJhzyua0FX/8x869vyx/gj+u/EaU=; b=A1g+oUEI2pVGq5nxXglmnUSZBlZ1HkxWTqQR39ov1yJHcIMDQ5pw3zeFlUhRNCuKOT556Jg1ZIaJRj+PgN3ateRDVuYNI1l/PhCZBe8AUTjxo5pub8RNRXx1BeP+FcThIb8kf9bpXNEQSS0c+xbENx4rpwpBuhOn4eNHtjiDYeoGCeki5rCuvaTVO+KJ3BjlXNTuYd7P4R8Pk9Rx/toKRYhOaC1tq0c+HyZZ0l9LWbNmDjedD0WK2x7PfveWfXhqWXKng+w2BVuMfaHIl/wQyhKiAr3oaWPEx2MuuaUYm3FJ7zGhjfFqenW4zoVrnA28dYzy/yJNvMuQTVVujsO4RA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.60) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cX4ieytK3JB714PlJhzyua0FX/8x869vyx/gj+u/EaU=; b=W7EHDPdd2LNF3/Th/lh5Lz1c10+ZtJQB4+4hjOLrv5mEgseAVq1s/eG+TNrzkv3waZTQNLNcoTG2T/q8eW47f4whvOd5MUIgDVsZH9R5hdeoVV6re6c4LqYupgyhJcvCGG/qtaIP2ugStcpJkdhrIlA8Z5kUddV7usALyjet1M2fHtRSlzBWIXjICkLgv2ffbzpSeOfioH3lmoALj92PZcOBDTtZmHZMks+omcuhKZamnQ1dLDEHryRHMT1YqRBrU66NxLarqAXNRYN/BNJxLo30SYJ3aQecUIMTbLvfPUAqklLlVwyXdiB0aLbFkqh2LS5LsA+A6qAlYA6SI2N3nw== Received: from DUZPR01CA0318.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::7) by VI0PR10MB9467.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:2ce::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.5; Wed, 25 Nov 2026 16:32:46 +0000 Received: from DU2PEPF00028D04.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::88) by DUZPR01CA0318.outlook.office365.com (2603:10a6:10:4ba::7) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.7 via Frontend Transport; Wed, 25 Nov 2026 16:32:46 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.60) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.60 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.60; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.60) by DU2PEPF00028D04.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.5 via Frontend Transport; Wed, 25 Nov 2026 16:32:46 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpO365.st.com (10.250.44.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:51 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:45 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:04 +0100 Subject: [PATCH v6 03/11] usb: dwc2: drop stale state after register restore on resume X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-3-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D04:EE_|VI0PR10MB9467:EE_ X-MS-Office365-Filtering-Correlation-Id: e423150b-5674-4eb1-5502-08df4b11bd06 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700016|1800799024|23010399003|82310400026|10067099003|56012099006|11063799006|261021121427099003|261022105027099003|261026121527099003|261021123027099003|261026140227099003|261028144727099003|261022075727099003|261102123227099003|261009223027099003|18002099003|22082099003|6133799003|13003099007; X-Microsoft-Antispam-Message-Info: 9SMY5mNwxEqrQWTUN68DpXaaIXHHpAFUmBRGb8J3FPWsYRwHUe/Ghum3J99rVzhg6bb9pnVYag984765PAsFwYLyGcSaF3MNqJuvOPHy3gasgV+/RuaPrpirNQlZyDH8dvy1bQOOJW2jIMuq8DeLcLXLS2u5yUmGwLr+Z/uL3uLo6uThF5S9uRIcAYJGDrkyJJnTKUioY4Izb9mupXrNLbieFLfDwQO78aT79BeMn3pnrIYVT3moRE14XwHrFfkyWKXfI8pdHN/TyGwRDsxRsYl2XUB1W3GPaQ25QSKv1R2TUZClGxoB+0apeblbopD8jfJvTimqyRnmi2jp4oHj8BNLUSdxH08SjtatxHxrDyzSDFxb/J9ieOcLgC50hMforTtpqudMiXGsDVFc0I7fftgTcAElB6TGEwtDLbjxVM2mFikJt5MRfXTXctsPcQUR6Ng4Tea1Cz+CXsQCCwiO3JRw5bnUk01Z00JHg6s7qDsfIXQFa4SxNMCOSqvQZ+P9akS4WDLm7SwtuFuTFyWAqrwv7KQY4f5YBZ5/sKP7aqsgK9d6TIOhR3nJaaqX3Ap6PB1sMoh9bzFrm/792n50kjxKEkz4i6WdyK5jM2XgFcl/LATxsSLmy91cNOSZGtZTlwDsrI508D1CQDBFsbjOP4XB3fJ1X7L7Vxx/f1q7rxs= X-Forefront-Antispam-Report: CIP:164.130.1.60;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(7416014)(376014)(36860700016)(1800799024)(23010399003)(82310400026)(10067099003)(56012099006)(11063799006)(261021121427099003)(261022105027099003)(261026121527099003)(261021123027099003)(261026140227099003)(261028144727099003)(261022075727099003)(261102123227099003)(261009223027099003)(18002099003)(22082099003)(6133799003)(13003099007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4MFCiiKlwJTqvds3/cPYifngoOEZOVtV5tWEjODEJ63ut4i/ZNd9iGCKtY1NhgDRFwtuo9fIG+ChCiOkdUvtfVILbsdXYJmTOToz/W4x1kBHg/Lf3HjSecvL7J1ts7Rv1Ptjq9cKkks8TG4Og9n0lHhetS23zTVRR1kIwLWUrK1eK8DFmNbsjzvWrdRK9wWd0W2YQ4DxKZcDYOGb42QoVRTeePIEcoAS+yjzgiBIsnfjtqWd6GhtVCixzzJ1DLgWrC7sKim9lS8wBvdiVd3NPUz7AoZwlUaWmNJ7cFxriuNSIrboMcbyv+qUvxP1ARBvfTT9ICNB+nsomvyD+Sc7nqJjd5DdfrlzKXawdd4iZcaTUPaV+TRR+xhnSstv0sH4BmsKaQKUtZt73Upwwcw/Xn8cLymUr/zlGqeJUI+0dUvCruun5E3XhOlHdkVnbyJo X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:46.6524 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e423150b-5674-4eb1-5502-08df4b11bd06 X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.60];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D04.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR10MB9467 After a power domain loss, dwc2_resume() restores the registers that were backed up when entering a low power mode (clock gating, partial power down), or in dwc2_suspend() when no backup exists yet. The restore only brings the hardware back to the state it had when the backup was taken. The software state is still the one of the suspended controller, and events that occurred while the power domain was off have been missed: - lx_state is DWC2_L2 and bus_suspended is set, so dwc2_hsotg_resume() returns early and _dwc2_hcd_resume() tries to resume the port, even though the controller has been fully restored. - in_ppd, hibernated and the backup valid flags may be left over. - In device mode, the gadget speed and the enabled endpoints are stale, although the host most likely saw a disconnect while the platform was unpowered. - In host mode, a connect or disconnect that happened during suspend is not reported, as GINTSTS is cleared by the restore. Add dwc2_clear_lost_state() to reset the common software state, and use it after a register loss is detected (GUSBCFG.TOUTCAL cleared): - device mode: dwc2_hsotg_resume() gets a "lost" parameter. When set, it disconnects the gadget, disables the non-EP0 endpoints, sets the speed to unknown and clears the stale state, then reinitializes the core and reconnects as for a regular resume. - host mode: dwc2_hcd_lost_state() clears the stale state and flags a connect and suspend status change, so the hub re-evaluates the port. Global interrupts are disabled by the restore under the lock, and only re-enabled once this cleanup is done, so an interrupt cannot run on stale state in between. Fixes: ba6e518d136b ("usb: dwc2: Implement recovery after PM domain off") Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/all/sashiko-outbox-202003@kernel.org/ Signed-off-by: Fabrice Gasnier --- Changes in v6: - patch split from "usb: dwc2: fix recovery after PM domain off" to ease the review --- drivers/usb/dwc2/core.c | 17 +++++++++++++++++ drivers/usb/dwc2/core.h | 8 ++++++-- drivers/usb/dwc2/gadget.c | 24 +++++++++++++++++++----- drivers/usb/dwc2/hcd.c | 20 ++++++++++++++++++++ drivers/usb/dwc2/platform.c | 18 ++++++++++++++++-- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index 6a0135e06b00..5da76f0fbcf6 100644 --- a/drivers/usb/dwc2/core.c +++ b/drivers/usb/dwc2/core.c @@ -600,6 +600,23 @@ void dwc2_force_dr_mode(struct dwc2_hsotg *hsotg) } } =20 +/** + * dwc2_clear_lost_state() - Clear software state made stale by register l= oss + * @hsotg: Programming view of DWC_otg controller + * + * Must be called with the spinlock held. + */ +void dwc2_clear_lost_state(struct dwc2_hsotg *hsotg) +{ + hsotg->hibernated =3D 0; + hsotg->in_ppd =3D 0; + hsotg->bus_suspended =3D false; + hsotg->gr_backup.valid =3D false; + hsotg->dr_backup.valid =3D false; + hsotg->hr_backup.valid =3D false; + hsotg->lx_state =3D DWC2_L0; +} + /* * dwc2_enable_acg - enable active clock gating feature */ diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 54c040da0cae..9873ae7b52c2 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -1411,12 +1411,14 @@ void dwc2_dump_dev_registers(struct dwc2_hsotg *hso= tg); void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg); void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg); =20 +void dwc2_clear_lost_state(struct dwc2_hsotg *hsotg); + /* Gadget defines */ #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \ IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg); int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2); -int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2); +int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2, bool lost); int dwc2_gadget_init(struct dwc2_hsotg *hsotg); void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2, bool reset); @@ -1452,7 +1454,7 @@ static inline int dwc2_hsotg_remove(struct dwc2_hsotg= *dwc2) { return 0; } static inline int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2) { return 0; } -static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2) +static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2, bool lost) { return 0; } static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg) { return 0; } @@ -1503,6 +1505,7 @@ static inline void dwc2_clear_fifo_map(struct dwc2_hs= otg *hsotg) {} #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_RO= LE) int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us); +void dwc2_hcd_lost_state(struct dwc2_hsotg *hsotg); void dwc2_hcd_connect(struct dwc2_hsotg *hsotg); void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force); void dwc2_hcd_start(struct dwc2_hsotg *hsotg); @@ -1530,6 +1533,7 @@ static inline int dwc2_hcd_get_frame_number(struct dw= c2_hsotg *hsotg) static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsot= g, int us) { return 0; } +static inline void dwc2_hcd_lost_state(struct dwc2_hsotg *hsotg) {} static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {} static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool forc= e) {} static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 5e75d6975baa..295091a87b12 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -5213,26 +5213,40 @@ int dwc2_hsotg_suspend(struct dwc2_hsotg *hsotg) return 0; } =20 -int dwc2_hsotg_resume(struct dwc2_hsotg *hsotg) +int dwc2_hsotg_resume(struct dwc2_hsotg *hsotg, bool lost) { unsigned long flags; + int ep; =20 - if (hsotg->lx_state =3D=3D DWC2_L2) + if (!lost && hsotg->lx_state =3D=3D DWC2_L2) return 0; =20 - if (hsotg->driver) { + if (hsotg->driver) dev_info(hsotg->dev, "resuming usb gadget %s\n", hsotg->driver->driver.name); =20 - spin_lock_irqsave(&hsotg->lock, flags); + spin_lock_irqsave(&hsotg->lock, flags); + if (lost) { + /* Host likely saw a disconnect: drop stale gadget state */ + dwc2_hsotg_disconnect(hsotg); + for (ep =3D 1; ep < hsotg->num_of_eps; ep++) { + if (hsotg->eps_in[ep]) + dwc2_hsotg_ep_disable(&hsotg->eps_in[ep]->ep); + if (hsotg->eps_out[ep]) + dwc2_hsotg_ep_disable(&hsotg->eps_out[ep]->ep); + } + hsotg->gadget.speed =3D USB_SPEED_UNKNOWN; + dwc2_clear_lost_state(hsotg); + } + if (hsotg->driver) { dwc2_hsotg_core_init_disconnected(hsotg, false); if (hsotg->enabled) { /* Enable ACG feature in device mode,if supported */ dwc2_enable_acg(hsotg); dwc2_hsotg_core_connect(hsotg); } - spin_unlock_irqrestore(&hsotg->lock, flags); } + spin_unlock_irqrestore(&hsotg->lock, flags); =20 return 0; } diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 0d20b9de857a..6f2b192f68f8 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -2324,6 +2324,26 @@ static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg) dwc2_core_host_init(hsotg); } =20 +/** + * dwc2_hcd_lost_state - drop stale host state after registers were restor= ed + * @hsotg: Programming view of the DWC_otg controller + * + * Make the hub re-evaluate the port, as a connect change may have been lo= st + * while the controller was powered off. + */ +void dwc2_hcd_lost_state(struct dwc2_hsotg *hsotg) +{ + struct usb_hcd *hcd =3D dwc2_hsotg_to_hcd(hsotg); + unsigned long flags; + + spin_lock_irqsave(&hsotg->lock, flags); + dwc2_clear_lost_state(hsotg); + hsotg->flags.b.port_connect_status_change =3D 1; + hsotg->flags.b.port_suspend_change =3D 1; + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); + spin_unlock_irqrestore(&hsotg->lock, flags); +} + static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb) diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 7f3436e6a153..53c34a42f760 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -738,6 +738,7 @@ static int __maybe_unused dwc2_resume(struct device *de= v) { struct dwc2_hsotg *dwc2 =3D dev_get_drvdata(dev); unsigned long flags; + bool lost; int ret =3D 0; =20 if (!dwc2->ll_hw_enabled) @@ -788,16 +789,29 @@ static int __maybe_unused dwc2_resume(struct device *= dev) * In case the GUSBCFG register is not initialized, it's clear the * registers must be restored. */ - if (!(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK)) { + lost =3D !(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK); + if (lost) { spin_lock_irqsave(&dwc2->lock, flags); ret =3D dwc2_restore_critical_registers(dwc2); + /* + * The restore re-enables global interrupts: keep them off + * until the stale state is cleaned up below. + */ + if (!ret) + dwc2_disable_global_interrupts(dwc2); spin_unlock_irqrestore(&dwc2->lock, flags); if (ret) return ret; } =20 if (dwc2_is_device_mode(dwc2)) - ret =3D dwc2_hsotg_resume(dwc2); + ret =3D dwc2_hsotg_resume(dwc2, lost); + else if (lost) + dwc2_hcd_lost_state(dwc2); + + /* Global interrupts are off after a restore, enable them back */ + if (lost) + dwc2_enable_global_interrupts(dwc2); =20 return ret; } --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.66.49 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624381; b=11c1vjxpyCajUzsxyzQdY3WeV6IxhHHpWFQquQkLMd03TLFz5kKXHhYSp+GyfYaRav73 nwntXW8Cqgw/q+BDH3xw9R68/Sm4FZCJRcixAexyzEUhxzNoOJCprySNNHMwP1tpNT5yc 1bKNTdRhlBxEmPFVQMafS7MSwh48fy4um6yN0VA4pnQJNWanjVbe+qldjQAGpQzYjgBmf D7VqxkDO26zta5h0ZVjl8cgIZz+GtPPmPo7sakbuhdKhdmiHHrPxrm+Ptt5hjQa/U5AQW /OzOf5ih9IZ8kiZ8HvYw0rPQyar71VfdOXqJnlLuzaXKYWr8soOZgk3i7Hh8+jf8fug== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624381; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=5v7CY7Uqdb/iDuxnv9M7e19xM/o64AV8+RNpBjx1CaI=; b=eg9GXbKqtNrfCy0OD+Xbv+waprJH+9YgF+zbEA2y/do0zqD9Pq7g6Kin9wHTQCQjyJ43 SoOBgRDepirfZj9YkDx0RoP3IhcctxgvHCT0JO25ZVabGn9m5OF3qrSFLFvEQJcGvxYfd ZXThirUFvcT7HWzvt6yhLZri1ncb9ZlJnrwWTutEyGsf88x6IbSje8CXW4cJEu+gY2jZw FNCz0KEGNEwblvnSZ5G+2W8XHq4Q9ZUw9h6TCBoqN8FE3M56tNLBmleU7Z8edz/bxNQI/ mS6Vqnh7EptM2L+kym/DymYaHBeXjBpV/pDRrByAXHFUxrB8Pf336KdcCQi70yNG6wA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=KOlsanW6; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.66.49 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012049.outbound.protection.outlook.com [52.101.66.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D5BD60A2613; Wed, 25 Nov 2026 16:32:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6D5BD60A2613 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=KOlsanW6 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TbLHKjK4ZGDP0fmvM9nNm00TfSBQ+ZslDvf2v7v5vlULbNi32d3sJcxbQV9t/cQvWRVVLXDcj5S1fWfHHfl0kDw2Ona0T7cC8BuseuVk+AQOSnqtaAI5BQzbW/16kAkVVEkhIR657u9JrfJUNQ1BABpkbcIa3s7Tm2LrIWihjIio/dKD6mYiUW8+3BgdnvZLYNQSh4UEqG7sA6MklNRN816dGEYilkTgAY/0YIkCYGqUuIJQ/Oe/BKcnqf8r2/DUYA/2btV3Pgbx+Nby4jJKXofNKiePe9SXwn2uvN08x65YqbA2kRLjSEZgJo/XwXf00yu+NjsE4Iu1v2plgciwqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5v7CY7Uqdb/iDuxnv9M7e19xM/o64AV8+RNpBjx1CaI=; b=geYSQn94rtrlAkayLxTgoNcc7Ce62EWyJ52nFDH4WqHjdbxP3frObghE0SxD8T9HVbopSQhjYLjjQblRA1pFhnGZiMaFyhz4Uu74WIcIN+rMviOHHjPMFOqo049POL924+59wVz1imYCvAuGsXQem7DeReyG5WGA8DK6312lA9fvSIs1O67fF0thXPlGaLqPtGqi4vAuSCxT2qVYOiea+km3rglfcJGREud6DZI0GNik9ll9XnBWacV0hrj9tvkQeCtothswkXd+jhvrt/s3uO9GUNBs8wlhSon+CMN6Q23+lD/0vhZ83TD+n1Y94sOI6/WNrT8I4tIjBEScJf4BVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.59) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5v7CY7Uqdb/iDuxnv9M7e19xM/o64AV8+RNpBjx1CaI=; b=KOlsanW6gU+P3e8ok2GUVhydJcSsP4EF0plFZNvBDf3/rdBuZB4oo84WgNr7PccZnor/qMlf/FZNdlv/b0ebT+p1dKsc+Hv1g3h3RFnfDdHakVHLWrZF3KnugBSuzvpK+Ow411TSpc1zusA65HIwEHMtjJRqNk5E1ybkH9Kc8naUhde5dR2sOwzMc+4VM2PkPh9UEJ7hcAEZ1ESFdAouykjudHMV9uuibpckK4iuShRfP3EiAvhtd5ZXWUcL+5hzRsoXX1BKIp3BaZFASw+lZ9UIvCwvXKxLGa9h7opxoJjIee6mQ/owq3KGKITuHjiYwlnj58sKGAosMhlNbCQOMg== Received: from GV2PEPF0004811E.SWEP280.PROD.OUTLOOK.COM (2603:10a6:158:400::1ef) by VE1PR10MB194643.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:1f2::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3; Wed, 25 Nov 2026 16:32:49 +0000 Received: from WA1PEPF00009B3A.eurprd05.prod.outlook.com (2603:10a6:1d8::118) by GV2PEPF0004811E.outlook.office365.com (2603:10a6:158:400::1ef) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.10 via Frontend Transport; Wed, 25 Nov 2026 16:32:47 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.59) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.59 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.59; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.59) by WA1PEPF00009B3A.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Wed, 25 Nov 2026 16:32:47 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpo365.st.com (10.250.44.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:35 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:46 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:05 +0100 Subject: [PATCH v6 04/11] usb: dwc2: clean up old role on mode change during suspend X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-4-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: WA1PEPF00009B3A:EE_|VE1PR10MB194643:EE_ X-MS-Office365-Filtering-Correlation-Id: e1f482a6-0a79-49dd-dff4-08df4b11bda9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|36860700016|376014|7416014|1800799024|82310400026|10067099003|11063799006|261022105027099003|56012099006|261026121527099003|261021121427099003|261022075727099003|261102123227099003|261009223027099003|261026140227099003|261028144727099003|261021123027099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: sanK9ugfERqXd45mHTLSUb/QBuvaFM106A2MgtfsOcz6FR/G888Ml0Jd1LbB1SF71onIu5KexNhU9mBIIuIO1X3B35CVYEGfxupiR9LfPC2wXC4iXvrQtpO4osB9VPPrDPMjZcV1UqDTP6hQjnZMob2+kRoJFFslgytuF9YhY6nSm0Ma2YgukzDLtlDwSlcNuTJOB+/OdpCi6ldpZMEZQPQxNeuE/xBkZ+hqH/ZWtXSnf626lmKWCHqPcMHUZtMGLMnLa+INT2YOW6j+0kDDqEPWbC2nRzZomo0LkyP+3/Kn1O/XUXNduY9ncVbt2Fnjp/CcXeGBjdCGiRcYte0dc+5RTrUFQkJFygsDUgP4CS+dyzGfo3h/TcOzs6xGG5xEuM52YTiNZRFOjg7LiZRq7xAo3tTDdt5uwf2WDiFG01M1tZW/7szwrQX8Mo0IjfP3u4n89temy9kf+UmNdEmy0YffM4kX6qzfr5JlMt/rFARrXmNBHCDQh+YqwmZYDdTEyOtPwQOkTaj/HMFXeBJ6A/6v8Au7xgeAPg0mw+zKNtsjsofOvIGgM9ZiqKoLV9auaTFFeNjYcVzApstDucAcCJjIoXWtLl/DACVAgbcPYY8o0Nm2gjQs7bA+lp1S98U43z39TcT9bFz/tqDSBufUig== X-Forefront-Antispam-Report: CIP:164.130.1.59;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(36860700016)(376014)(7416014)(1800799024)(82310400026)(10067099003)(11063799006)(261022105027099003)(56012099006)(261026121527099003)(261021121427099003)(261022075727099003)(261102123227099003)(261009223027099003)(261026140227099003)(261028144727099003)(261021123027099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i4U1/gQH3C9fMCRiXJz2dWTSBEtVMe9TJhFfy02+KYgKPAPmfMlxIwDe4l1kB5qCYlZeYgBFT1j5kt/+V4GYp/VqopCQxrUVWyGVBY2vXIhujbdC9wpqGy4f79Oc5lO6vk6Aqkv6GExCY2TLxg0O8zaDr+yE8e0n47eJ2Z4xpXKVuHc0z+KU2hvr8BD5P4whMCReihP0sAAYmx2sB+JXe6he54OVFNIpaTd1oPyTefhrNK/b00O2+VnwJbziN5XtsLQ3D3iH7c+8ZHGKpKc9BNbCiD1dVCbiHKbio99xADBakYxIatiuBowiF2e0OmP5wxRjCxCPcU40Boi0kKDw4MBJkixpqj+y86OVvG3IxnsYZjwXOrqNaSo5PQDcucUU8nsCbsI+ft8CjD67m6Kc9vmxowL+qZ9whZp3HkZZyOvG8j9sMI8SDyD5dAfryNWa X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:47.7410 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1f482a6-0a79-49dd-dff4-08df4b11bda9 X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.59];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: WA1PEPF00009B3A.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR10MB194643 If the power domain is off during system suspend and the OTG ID pin changes meanwhile, dwc2_resume() sees a register loss but the role that was active at suspend is never cleaned up. No connector ID interrupt reports the change, as GINTSTS is cleared by the register restore, and the register backup belongs to the old role: host registers could be restored in device mode, or the other way around. When the core was in device mode at suspend and resumes in host mode, the gadget driver is never told about the disconnect and the gadget state stays stale. When it was in host mode and resumes in device mode, URBs and host flags stay as they were and the external VBUS supply is left enabled. Record the mode in dwc2_suspend(). On register loss with dr_mode otg, compare it with the mode after resume. If it differs, skip the register restore and clean up the old role before initializing the new one: - device to host: disconnect the gadget, clear stale state, the FIFO map and set the speed to unknown, without accessing endpoint registers that are unusable in host mode. Then reinitialize the host with the new dwc2_hcd_restore(). If it fails, the HCD was not reinitialized, so it is left inaccessible. - host to device: fail pending URBs, clear stale state, make the HCD accessible and release VBUS, then reinitialize the core and resume the gadget. This addresses the second finding of the Sashiko review of "usb: dwc2: fix recovery after PM domain off". Fixes: ba6e518d136b ("usb: dwc2: Implement recovery after PM domain off") Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/linux-usb/sashiko-outbox-219256@kernel.org/ Signed-off-by: Fabrice Gasnier --- Changes in v6: - New patch added since Sashiko finding --- drivers/usb/dwc2/core.h | 9 +++++++ drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++ drivers/usb/dwc2/hcd.c | 58 +++++++++++++++++++++++++++++++++++++++++= ++++ drivers/usb/dwc2/platform.c | 25 ++++++++++++++++--- 4 files changed, 109 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 9873ae7b52c2..89a34956bf22 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -876,6 +876,7 @@ struct dwc2_hregs_backup { * @reset_phy_on_wake: Quirk saying that we should assert PHY reset on a * remote wakeup. * @phy_off_for_suspend: Status of whether we turned the PHY off at suspen= d. + * @suspended_in_device_mode: True if the core was in device mode at suspe= nd. * @need_phy_for_wake: Quirk saying that we should keep the PHY on at * suspend if we need USB to wake us up. * @frame_number: Frame number read from the core. For both device @@ -1074,6 +1075,7 @@ struct dwc2_hsotg { unsigned int reset_phy_on_wake:1; unsigned int need_phy_for_wake:1; unsigned int phy_off_for_suspend:1; + unsigned int suspended_in_device_mode:1; u16 frame_number; =20 struct phy *phy; @@ -1419,6 +1421,7 @@ void dwc2_clear_lost_state(struct dwc2_hsotg *hsotg); int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg); int dwc2_hsotg_suspend(struct dwc2_hsotg *dwc2); int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2, bool lost); +void dwc2_hsotg_role_lost(struct dwc2_hsotg *hsotg); int dwc2_gadget_init(struct dwc2_hsotg *hsotg); void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2, bool reset); @@ -1456,6 +1459,7 @@ static inline int dwc2_hsotg_suspend(struct dwc2_hsot= g *dwc2) { return 0; } static inline int dwc2_hsotg_resume(struct dwc2_hsotg *dwc2, bool lost) { return 0; } +static inline void dwc2_hsotg_role_lost(struct dwc2_hsotg *hsotg) {} static inline int dwc2_gadget_init(struct dwc2_hsotg *hsotg) { return 0; } static inline void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *dw= c2, @@ -1505,7 +1509,9 @@ static inline void dwc2_clear_fifo_map(struct dwc2_hs= otg *hsotg) {} #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_RO= LE) int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg); int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsotg, int us); +int dwc2_hcd_restore(struct dwc2_hsotg *hsotg); void dwc2_hcd_lost_state(struct dwc2_hsotg *hsotg); +void dwc2_hcd_role_lost(struct dwc2_hsotg *hsotg); void dwc2_hcd_connect(struct dwc2_hsotg *hsotg); void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool force); void dwc2_hcd_start(struct dwc2_hsotg *hsotg); @@ -1533,7 +1539,10 @@ static inline int dwc2_hcd_get_frame_number(struct d= wc2_hsotg *hsotg) static inline int dwc2_hcd_get_future_frame_number(struct dwc2_hsotg *hsot= g, int us) { return 0; } +static inline int dwc2_hcd_restore(struct dwc2_hsotg *hsotg) +{ return 0; } static inline void dwc2_hcd_lost_state(struct dwc2_hsotg *hsotg) {} +static inline void dwc2_hcd_role_lost(struct dwc2_hsotg *hsotg) {} static inline void dwc2_hcd_connect(struct dwc2_hsotg *hsotg) {} static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg, bool forc= e) {} static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {} diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 295091a87b12..9b12c336e4aa 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -5251,6 +5251,26 @@ int dwc2_hsotg_resume(struct dwc2_hsotg *hsotg, bool= lost) return 0; } =20 +/** + * dwc2_hsotg_role_lost - drop gadget state after a role change in suspend + * @hsotg: Programming view of the DWC_otg controller + * + * The core came back from register loss in host mode while the gadget was + * active at suspend. Disconnect the gadget and clear stale software state + * without touching the endpoint registers, which are not usable in host m= ode. + */ +void dwc2_hsotg_role_lost(struct dwc2_hsotg *hsotg) +{ + unsigned long flags; + + spin_lock_irqsave(&hsotg->lock, flags); + dwc2_hsotg_disconnect(hsotg); + dwc2_clear_fifo_map(hsotg); + hsotg->gadget.speed =3D USB_SPEED_UNKNOWN; + dwc2_clear_lost_state(hsotg); + spin_unlock_irqrestore(&hsotg->lock, flags); +} + /** * dwc2_backup_device_registers() - Backup controller device registers. * When suspending usb bus, registers needs to be backuped diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 6f2b192f68f8..60b39ccd0cad 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -2324,6 +2324,42 @@ static void dwc2_hcd_reinit(struct dwc2_hsotg *hsotg) dwc2_core_host_init(hsotg); } =20 +/** + * dwc2_hcd_restore - reinitialize host state after a role change in suspe= nd + * @hsotg: Programming view of the DWC_otg controller + * + * Return: 0 on success, or a negative error code on failure. + */ +int dwc2_hcd_restore(struct dwc2_hsotg *hsotg) +{ + struct usb_hcd *hcd =3D dwc2_hsotg_to_hcd(hsotg); + unsigned long flags; + int ret; + + clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); + dwc2_disable_global_interrupts(hsotg); + + ret =3D dwc2_vbus_supply_init(hsotg); + if (ret) + return ret; + + ret =3D dwc2_core_init(hsotg, true); + if (ret) { + dwc2_vbus_supply_exit(hsotg); + return ret; + } + + spin_lock_irqsave(&hsotg->lock, flags); + dwc2_hcd_reinit(hsotg); + dwc2_clear_lost_state(hsotg); + hsotg->flags.b.port_connect_status_change =3D 1; + hsotg->flags.b.port_suspend_change =3D 1; + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); + spin_unlock_irqrestore(&hsotg->lock, flags); + + return 0; +} + /** * dwc2_hcd_lost_state - drop stale host state after registers were restor= ed * @hsotg: Programming view of the DWC_otg controller @@ -2344,6 +2380,28 @@ void dwc2_hcd_lost_state(struct dwc2_hsotg *hsotg) spin_unlock_irqrestore(&hsotg->lock, flags); } =20 +/** + * dwc2_hcd_role_lost - drop host state after a role change in suspend + * @hsotg: Programming view of the DWC_otg controller + * + * The core came back from register loss in device mode while the host was + * active at suspend. Fail pending URBs, release VBUS and clear stale soft= ware + * state so the host can be started again on the next role switch. + */ +void dwc2_hcd_role_lost(struct dwc2_hsotg *hsotg) +{ + struct usb_hcd *hcd =3D dwc2_hsotg_to_hcd(hsotg); + unsigned long flags; + + spin_lock_irqsave(&hsotg->lock, flags); + dwc2_hcd_disconnect(hsotg, true); + dwc2_clear_lost_state(hsotg); + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); + spin_unlock_irqrestore(&hsotg->lock, flags); + + dwc2_vbus_supply_exit(hsotg); +} + static void dwc2_hc_init_split(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb) diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 53c34a42f760..d89a30308f86 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -658,6 +658,7 @@ static int __maybe_unused dwc2_suspend(struct device *d= ev) return 0; =20 is_device_mode =3D dwc2_is_device_mode(dwc2); + dwc2->suspended_in_device_mode =3D is_device_mode; if (is_device_mode) dwc2_hsotg_suspend(dwc2); =20 @@ -738,7 +739,7 @@ static int __maybe_unused dwc2_resume(struct device *de= v) { struct dwc2_hsotg *dwc2 =3D dev_get_drvdata(dev); unsigned long flags; - bool lost; + bool lost, role_changed; int ret =3D 0; =20 if (!dwc2->ll_hw_enabled) @@ -790,7 +791,25 @@ static int __maybe_unused dwc2_resume(struct device *d= ev) * registers must be restored. */ lost =3D !(dwc2_readl(dwc2, GUSBCFG) & GUSBCFG_TOUTCAL_MASK); - if (lost) { + role_changed =3D lost && dwc2->dr_mode =3D=3D USB_DR_MODE_OTG && + dwc2->suspended_in_device_mode !=3D dwc2_is_device_mode(dwc2); + if (role_changed) { + /* + * The ID pin changed while the registers were lost: no + * connector ID interrupt reports it and the register backup + * belongs to the old role. Clean up the old role and + * initialize the new one instead of restoring. + */ + if (dwc2->suspended_in_device_mode) { + dwc2_hsotg_role_lost(dwc2); + ret =3D dwc2_hcd_restore(dwc2); + } else { + dwc2_hcd_role_lost(dwc2); + ret =3D dwc2_core_init(dwc2, true); + } + if (ret) + return ret; + } else if (lost) { spin_lock_irqsave(&dwc2->lock, flags); ret =3D dwc2_restore_critical_registers(dwc2); /* @@ -806,7 +825,7 @@ static int __maybe_unused dwc2_resume(struct device *de= v) =20 if (dwc2_is_device_mode(dwc2)) ret =3D dwc2_hsotg_resume(dwc2, lost); - else if (lost) + else if (lost && !role_changed) dwc2_hcd_lost_state(dwc2); =20 /* Global interrupts are off after a restore, enable them back */ --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.66.19 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624374; b=Z6fdoYNHtqzdO4EYqWH0IqRH7uTzRRVv0bDwHo5k6wXgb8vxxFaYu10Mcki9fGOfLqp8 5bNwXgkW1EzWXzJE/TRMUVIO/ksGSJm+m58h0f84CcKopLrpZn5xAJqPamLZkuOkWGKAl 9v+x2cUD/hFOpo/ZGIjDL0+xhIoXbESnXYpnQ2N8Y8DBFlPjZ26pxBGyGh+SsICzGzUmu EWR2A0XVkSToG/HYrAvHe19cpnuj0Bvaf6eEe/85t77zvlCv8Yt8/HY9WpRyER7DW9ibX NAYorGVowVnVxZ9Q1v5JSQpzBhAd6b/r+sxeeel/htUEjVB4fPeUJ/GevllkiHHG3RA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624374; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=KYutawCpzkVhtZ0aWBvYB4MGJXEzxRjJAJ9CxvXCmdU=; b=GR+7TYAaxB7QInE3U8OBitXlC5NdqopqPgdAFE/XVg10lsuLf+CKkmAfPVhbNdT70vOC MBMORNX3RYSBJdTuNtJFjxuJEiviP4CBsT+otE+zU5MkrsoIBHDPHVcT8ITIWoWb/Co1i /WEKIsDXwqSi6kQEZ4JnuSy7c4k8a81ElIYcn3pbNVMRNPGAStwB5Gv5IohKL8YJdDw0a oA8YX2tdTiHScPyprfZ0NFJOTnPLAhWZsbxV09yhGeVh5Vug6QQ+0q0sXNv1L6gj9HSB+ DnZNlIIsuoex3e1c11ObQRz/nz06bxcceubYf6iI+7jo78k45X0rEvr//Z8Guo3eVlw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=oPtRlj4h; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.66.19 Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11012019.outbound.protection.outlook.com [52.101.66.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2211F606A682; Wed, 25 Nov 2026 16:32:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2211F606A682 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=oPtRlj4h ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jrCEr3jdkmF/x3f9fMwAuXO0dKKknjz1npe+a2q8TNL2l3hfSoowUBnlpHyeqCwT30o2V2OgK0okIRYbLefqDUo/kpWXDtjIu4ck0oe5cZ312xjrm7axFKrIMVD8W36WVYFnWK6+9FuSuf4BxZcxwKbwXFBwkVsSPmfvuqCN0zbUyZ0h2j3Ca3bIxPvzQkF6wjhPvxeRIJ1G8f8//hdZ3ymVzTTYPCLiE9HYm933KI7/AuRL6ooZz9w8HQKEx1Pi3V9IYvhwvopTHOqTT+5xv+PorU7LI5JQEc13bFwOP0prUuViSYDw4hC5uiu+XPSCHbhAx5hs6Y1ehxbuAlXyrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KYutawCpzkVhtZ0aWBvYB4MGJXEzxRjJAJ9CxvXCmdU=; b=Y94VwNiAOKKKuDC8dHygAhYpWy0lEzdyaQqqGwS+RoPHk3ADBWSJRQ8BUV99xKXfOkDCCa2LkYlVWtp/OpztT0pzHZzZUviHzAYOqayJl6pvlRZoqUGaLqJ2/BX08lboXLhF+T8abFydoDqW9ftnIkgAdM/Uu5DNHJ414VOdQFrLFkWh5NIkXXxhfgS+nXfDgoUOnXDM/fQfGUJk71DNpPdheFri4GSRXAUkeaewqNzzI0ejbhS2mlfFpAxoErnawS70CFJnbrFWfBoOlNXD3jH8A8KQujCSphXRgcc7tbGHwSjePrZ8VdsLGRgKCuCqN5SSGOkHK7LgUHaSkxhWtA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.60) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KYutawCpzkVhtZ0aWBvYB4MGJXEzxRjJAJ9CxvXCmdU=; b=oPtRlj4h0+IOgcvgzXIu7aZe9YEREs+MMimPG1zltg/NaGIU3V1iVoAN4FwKxP2kHncGVvtWX3eazpt9blNb7Pnc8wvJQ4iVX7q8Zv8+0zLUCQl1eOdlpMv+tkiBA3VVutxDEp5fyKj/yiVffag10W5PU6LgvWP1oPzN4tKOrT9PgNbCjIM7BeKfgbF2ZHNea2FoaveapAdmkgzR4wl8DdgtF0ZhYHk9+lGxGNt+TV2JrpvMYR/TbP/car5EIXAO4/5UzvblOekBFnsQvzUEx824hez4lrkPBXQEUOoeJ3wbZWhAAEgnJIfNhLDS2BxbHD2ZQ7kNBawe50iI6sICSQ== Received: from DUZPR01CA0319.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::18) by DB8PR10MB3878.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:164::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3; Wed, 25 Nov 2026 16:32:47 +0000 Received: from DU2PEPF00028D04.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::26) by DUZPR01CA0319.outlook.office365.com (2603:10a6:10:4ba::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.7 via Frontend Transport; Wed, 25 Nov 2026 16:32:47 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.60) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.60 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.60; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.60) by DU2PEPF00028D04.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.5 via Frontend Transport; Wed, 25 Nov 2026 16:32:47 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpO365.st.com (10.250.44.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:52 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:46 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:06 +0100 Subject: [PATCH v6 05/11] usb: dwc2: fix a possible interrupt storm in hcd resume X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-5-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D04:EE_|DB8PR10MB3878:EE_ X-MS-Office365-Filtering-Correlation-Id: 09930035-be94-445d-8cdf-08df4b11bd9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|23010399003|376014|1800799024|36860700016|18002099003|22082099003|56012099006|11063799006|261021121427099003|261102123227099003|261021123027099003|261022075727099003|261009223027099003|10067099003; X-Microsoft-Antispam-Message-Info: A7Svr7pEFRt2OnFD5VMuKDMv1eY/elMkZlBcvts74D3RGTzJlU6FLQE3cLbdjQZhbDayOc/kLcTaQ3Z4VkvvtvO7U9NMZ+AiZaCSSoMU95896yl169FgXJCdcgx+NFaRG1qx0X0OwuNN8tENlE4c74byATLkXSZLUj0nzronsLhr+AnP3rXEU2Pgb9g7sCvVc+GwNaMjbuCCFHqDNnVp4QTflz/YfCDc4gGivL3dGh5JwB+bMENgR5L4eDs8aJmDppgmKTnATR1uZQMsSD9ROfwmq/6QYc53E8bmTXnvIzQxPw2MjH8KcBghl1lMH8OjGTI6tTJwp/dzSoR1DKmpBrIfWSmOhHVs+8uihnoE49NISztGbtp7RwsEk6KCR/N8LcXScGl+je3cFLwQEonhYk45ltoXJVNOBhqsWQ86NBrWOHecohuRAps8Y/L1gyDSpBvNdOqvpXuMGCXhZaJVJ6XBT5N0pXXXiNuGlVFD1W90aSI8rukyZvZdFdO0+8ZHG4G5IFM+l/F/wj8f3l+T/suTUgcgpK5/5TQg6/I+Ci0nAudbs2MmQSqTp1/IB9v/MoQWKg49HgFlcmvfRHKYcz75yfcGw0KSDDL9mEBcT1U2ilFjiOyK+sW+BzH6ekrhfM5DrL4Yzz+FQRQmdhiegX5O5wrSWyh+wK/6a8a0fPzWAsu7iDHCe/SjCQoniwAesTbZNOEMleQoLIgMMcJ1Ig== X-Forefront-Antispam-Report: CIP:164.130.1.60;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(23010399003)(376014)(1800799024)(36860700016)(18002099003)(22082099003)(56012099006)(11063799006)(261021121427099003)(261102123227099003)(261021123027099003)(261022075727099003)(261009223027099003)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /zyWyYEkZlb6of37s/YkhVKCgZS8YPykZMJjtadTc18vHv0rWmBGUd/Fe1mcTbtZOEya02uqQ87v47bqRu5/cqlR+iXohatRQ9OhbA7rgBhdbJRcom9Ox3PBIlVQwlCJ6JNOwWvrWrwVNk0d8sMNmn2/etse12kSruHAvgJTfxqwPFeLbGfMVyi8Ic2ir7WNSq2ou5uTyFpxqESDhvUYUwMIQrhNRm1J6RpRPbJd/hXgq7MO22GA3D6rMQ4+mIYJvTWwm+PANFh+BjP2XQgTkKxClxDmGE3eTzY/CSjrV+APFxWeHXlZ01JTZpv+VprqrkgP9akUuLDFqPWyijcwiimTAHw7ncq7dvdncxVxm/8OU3lRGYjr3c2Rb+VjWCoGdHxxZECfZaTrwWEkPquIDbhstv7Kvn7xgSz+Tv3ohho4aBzR0vijpnEEyqaDYoCt X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:47.6434 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 09930035-be94-445d-8cdf-08df4b11bd9c X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.60];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D04.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR10MB3878 The host interrupts are re-enabled in dwc2_hcd_reinit(). So there is a race during resume between a possible hcd IRQ, and the HW accessible bit to be set. This can result in a bad_irq to be reported (nobody cared). Note dwc2_hcd_reinit() "Must be called with interrupt disabled and spinlock held." So, move dwc2_hcd_reinit() and the glocal irq enabling inside the critical section, after HCD_FLAG_HW_ACCESSIBLE has been set. Fixes: ef5e0eec4764 ("usb: dwc2: Add clock gating exiting flow by system re= sume") Cc: stable@vger.kernel.org Signed-off-by: Fabrice Gasnier --- Note it's been found while debugging with additional mdelay after dwc2_hcd_reinit() call. --- Changes in v4: - Address Sashiko comment "usb: dwc2: unlocked dwc2_hcd_reinit() call in _dwc2_hcd_resume()": rather move the dwc2_hcd_reinit() and irq enabling under the critical section, after HCD_FLAG_HW_ACCESSIBLE has been set. - Update commit msg. Changes in v3: - Introduce this patch since debug session (since sashiko comment on patch 1) --- drivers/usb/dwc2/hcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 60b39ccd0cad..7729581d1102 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -4568,8 +4568,6 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) * the global interrupts are disabled. */ dwc2_core_init(hsotg, false); - dwc2_enable_global_interrupts(hsotg); - dwc2_hcd_reinit(hsotg); spin_lock_irqsave(&hsotg->lock, flags); =20 /* @@ -4577,6 +4575,8 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) * since an interrupt may rise. */ set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); + dwc2_enable_global_interrupts(hsotg); + dwc2_hcd_reinit(hsotg); break; default: hsotg->lx_state =3D DWC2_L0; --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.72.61 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624379; b=WpOtfVRi/DlDl9EYYprp3QlEUUu+M6GvWR9dnB5SkpCqoJuZ/WhQA2xcbDz+ifWDBaQa qGTYa9mOW2KZ0j+SFlXsivoRDl2HXhom5lMakBjdmgC+27+YKtFya9PCxOsCG+unBJ5QM OUgK5+bBN1b9mka2VI450Ckgxjt9jh6rV02KGLZRwURzNsnwDrHuoiyRnm0nFC7k7iP+X G7FDKmgSitJzKBGR/Y5gRdQ02DQpd58rjD5vRXDFtzjYyWN0NvCydv9Dge1WXiV6wez3N WnJ3o5NYNp6LCmxdvcPKiGKmIArxwbCaBXK8RNDYCTBLQYo0E9h01iR1mDqA65g029A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624379; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=NwQw/Qhm/3DyzCAZ0QUMsPWQJ75PNFDp/MNgGf8Z2C4=; b=Xt/SjLlk9XOowI1FtvVZvnsrpPyaSeCOPSgy9moZHEL4ytSVQMZoiE8xymTaT3tfOj8u MPx6fDIg4wE8mkKp919Qco2ddr1NEInNEtU4CHXIBOHk3RyxzKPwkPu9ICX1pry8bOt5P 3mCxDlANS23LaLcamZgKN4J+V1uwFAF4KbU5LAFvQfwnBiGD1SmAWRsBAQrKNboFz7nXb 2kKTdHbwZ5Wv+5ydcIN07CZU0muJ5f7NG28D5KLok+G2vTlUmmIit/VDXGpRyDbWeOQ+z nwHPS2HjY8Qp6dUTbtxUmkXntX7stvgW3OIoFgfCQDVvrVQKz5CPvI8uJAO+IycY9pg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=DHiH+iWF; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.72.61 Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11013061.outbound.protection.outlook.com [52.101.72.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE2AD606A689; Wed, 25 Nov 2026 16:32:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE2AD606A689 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=DHiH+iWF ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ean2NZD1b5Oz6v0ImVIdUd9515nbEGf7sN3nneHs9HfAh6OXvGGUclrUDFzQrra2I2BRlscbNyfLBB7LAdjpmpEmmRLiVxdCvCDICdTT3XgOEjn4HLFvF+4XOfWJ10JeOIm3/lzJY3dbKSuKhymzHUHDfiffwFsCw/lEdBf/ZOOEJGTYsZ9299vDfNEYSCkuuvjUEDUx7u39PLv5H7x2ueoBNv27lCf3qynIFLHHRemjjDCTXRT1ISZMGTSPH59nlIhhITMgfVvVH6u3MlK3hIfAuwc/ad+d8yU+lzlgzK/vA7veWfUnPy6PSiBmueGc63jFOeAeiH6SgYLyOboAww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NwQw/Qhm/3DyzCAZ0QUMsPWQJ75PNFDp/MNgGf8Z2C4=; b=o/oz/A9j7JkJfvdyb6/yBPZSuD1Z6MiEs6evxQD1Pvfm/nLBJZVefa4qdKeJl4Sv93VWREO5oeMLbYGL2S8dM8F4qhfAmR/jAqGRApU82a7/y+D159lWdJfVS9Vpp08D7rQ+5nUTb3ReC8QDeh5hLfj2BLx8JxSVxsDsXt1rcCuTY1IA1u6oD8C4Nmt5CERO2f7U7w6ZoVhaZnnGnAbvV0/ObYMGHKwLGdGHGWlLxe+GWerlzwLliCHX3ouGrFqbOMiTIDB5QxibaRzTu5nKf00vw5VL+G66xzMDOa1ichpo5s91Em5nSAq7DXI1W6erhFqFH1Zd8Nno0ZrAjnbwlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.59) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NwQw/Qhm/3DyzCAZ0QUMsPWQJ75PNFDp/MNgGf8Z2C4=; b=DHiH+iWFFANZEZEqvHAX384O7mUgflORn1VkcRL/usgpcazJwLVU8zmYgP7Kj+ByAHtrxS061ZCmrtaFTCj478t/YJDk8D9v8rIx/m0KWyxa5IAXzH3dFDKpHTgLPgbuCL4FKLuiKA6XO7k+kFrHyof1S3NB8uK6fFFsreeABW0ebxsqZTYaVNuCfFlU4TaX0E5Q235jlNeiELeBOmhWjINs/l9YaUMbL3YfR6HdzcDIpRgpZM+w5aQjW67rXGzVaRCFDa+qhJ8ydxUysL9byRNxF2ec8pYV8MXzmFTMed+ojXcfrJfqZrmSQV3aZLgK2EzaV6XijNnFqf7d2/q+qw== Received: from GV2PEPF0004811E.SWEP280.PROD.OUTLOOK.COM (2603:10a6:158:400::1ef) by VI0PR10MB8747.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:234::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.4; Wed, 25 Nov 2026 16:32:50 +0000 Received: from WA1PEPF00009B3A.eurprd05.prod.outlook.com (2603:10a6:1d8::118) by GV2PEPF0004811E.outlook.office365.com (2603:10a6:158:400::1ef) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.10 via Frontend Transport; Wed, 25 Nov 2026 16:32:49 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.59) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.59 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.59; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.59) by WA1PEPF00009B3A.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Wed, 25 Nov 2026 16:32:49 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpo365.st.com (10.250.44.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:36 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:47 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:07 +0100 Subject: [PATCH v6 06/11] usb: dwc2: fix a possible interrupt storm on stm32mp1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-6-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: WA1PEPF00009B3A:EE_|VI0PR10MB8747:EE_ X-MS-Office365-Filtering-Correlation-Id: 866a7004-aa1a-4221-1fca-08df4b11bee2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|36860700016|1800799024|376014|7416014|23010399003|18002099003|22082099003|261009223027099003|5023799004|56012099006|11063799006|261026140227099003|261022075727099003|261028144727099003|261021121427099003|261021123027099003|261102123227099003|261026121527099003|261022105027099003|10067099003; X-Microsoft-Antispam-Message-Info: MvCuz1BIUnYA064fkFjGhpTLdqWgDca4Ja1sKNaFoRP8pmHBtEpALiklK7xs6mjqLGhFCqgoiWTr08JVOi72tMoFrhOMWOpKVD6aovJ02rrZgn6dDeWBlaIM/CBHCJY+fwmvc0t/pF+Hy1xGv3YpNoGJoz1qeCKRePxfzJ79FlkgUC9nIfk1zJv3+iHrG6hD0mpGaNnOpSxXxccKT6XsCzpxrF9msC5j4xl2O6Mmej5jHaq78Z5zdBkfpsHpOhoaVbuROV7CzRK/Tg1p2sEPn6KLa6QCUxSqbVpcgWI390uUF0Lduz2dI6UBZWeu/84tnetVfxnijQUsUDb6+3gMSVYiKlOEgeVxCczwjbN9AmQr1/sv2dUmlVJU0/dcyfIHDNoGKjx3Tedu54hGyflYC5rVSI18RAmdsPZ5+RwHTAscmapb1UonrY1MZAelgDGoEwaKN286/GBF9cf8h4KYrfaRBClMSlFMgiIQ0+rQe5TtPsM89Hx+2d6CXPUtbbfnUxaaE0y2wForvscPwKCQFNkjNCUo9FTGBNQLzWuI3i+hNlv8tzb5Chk4WMwyG4wWKAxpc8cHs9dz9gbM1yXvTnsh9sc03F4h5NRV9NZpErs8cHOrRxb3t6Fbpt1NXppQk8RUKU2qmw4Ev4QL5mr4SxrsoRxTgaMp0LTnWZc+CRakEMNdILwKjtqZedsKhCgDVe8hg9wizLcogu/RaPiHsA== X-Forefront-Antispam-Report: CIP:164.130.1.59;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(36860700016)(1800799024)(376014)(7416014)(23010399003)(18002099003)(22082099003)(261009223027099003)(5023799004)(56012099006)(11063799006)(261026140227099003)(261022075727099003)(261028144727099003)(261021121427099003)(261021123027099003)(261102123227099003)(261026121527099003)(261022105027099003)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jmb/KIYcLTdj03ERfO+e/sPt+erpE4yVrQSz//wvcxjhcQaupT5bkZSUvDdM+b3Eh9vNL6B4ZFi5JNgnMMHYvFaFBczNkLo4EMgEOB+SqTvj437JAfZo7DVngIe+MFv8R+WInl6cClpQe69VnIxSYfDmtI335hCPyIMFhxQx0nAME4SvuWDILfHfHWHI9kYlz7QTkQRLtvP5+Yt/gXV8aToKM9ZvLCf5VgzvO7mQtRK9ZjIXI3bM9sJI9bu1VBKECysTJe1FFiO8E5NIsY/dbpAr1pKU3Q6VpR+CrfHSge4aZfIX2J/k2bHFEwmDMo32vbYuXbAZJc7q3+BmHKF79IbXX0UitiK9UqQmWAOuh7C7t9FkRveN21/JnWjsurTJ/NF61jT2+fN1p3/rOyZMCeASgDHubT2HsukF922+72hCE0+ACBhXuAGCrlzlJfFO X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:49.7855 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 866a7004-aa1a-4221-1fca-08df4b11bee2 X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.59];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: WA1PEPF00009B3A.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR10MB8747 On stm32mp1, upon resume from low power (stop) mode, in host mode, a port interrupt storm may be seen before the hardware is accessible. The core is able to generate interrupts during system resume in platform.c when calling dwc2_resume()->__dwc2_lowlevel_hw_enable(). As the PHY and clocks become available, a resume IRQ can be seen with a Host Port Interrupt (PrtInt). The wakeup interrupt handler make the controller to exit power down mode, but the HCD handler returns IRQ_NONE, due to the HW accessible flag has been cleared in _dwc2_hcd_suspend() earlier. It ends-up with the bad_irq handler. So set the HCD_FLAG_HW_ACCESSIBLE flag when the resume IRQ is handled to exit from power down mode. Fixes: ef5e0eec4764 ("usb: dwc2: Add clock gating exiting flow by system re= sume") Cc: stable@vger.kernel.org Signed-off-by: Fabrice Gasnier --- Changes in v3: - Set HCD_FLAG_HW_ACCESSIBLE only when dwc2_exit_partial_power_down() succeeds. Changes in v2: - Add check on hcd before setting HCD_FLAG_HW_ACCESSIBLE flag, to avoid a NULL pointer dereference on hcd in peripheral-only mode as raised by Sashiko. - Add same handling in PPD mode as raised by Sashiko. Only handle clock gating and partial power down mode (PPD) as pre-existing wakeup handler manages these two modes. I don't have Hibernation capable hardware to cross-check this mode. --- drivers/usb/dwc2/core_intr.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c index 9565e6a52725..df9f6b963fb8 100644 --- a/drivers/usb/dwc2/core_intr.c +++ b/drivers/usb/dwc2/core_intr.c @@ -453,18 +453,25 @@ static void dwc2_handle_wakeup_detected_intr(struct d= wc2_hsotg *hsotg) } } else { if (hsotg->lx_state =3D=3D DWC2_L2) { + struct usb_hcd *hcd =3D hsotg->priv; + if (hsotg->in_ppd) { ret =3D dwc2_exit_partial_power_down(hsotg, 1, true); if (ret) dev_err(hsotg->dev, "exit partial_power_down failed\n"); + else if (hcd) + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); } =20 if (hsotg->params.power_down =3D=3D DWC2_POWER_DOWN_PARAM_NONE && hsotg->bus_suspended && - !hsotg->params.no_clock_gating) + !hsotg->params.no_clock_gating) { dwc2_host_exit_clock_gating(hsotg, 1); + if (hcd) + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); + } =20 /* * If we've got this quirk then the PHY is stuck upon --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.69.25 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624375; b=TmTlD9K+u5wlxms4Q+FHEyeqPRFEx7/XiBb8lJiySwcEQvDcV/+oNCz4+BFp+e6geE61 dE82gjyKNSx+Q5JYHm2RMw4PzYC7ruW8yy+/4M3o0nRnZ03MWcFyrM5pezz+W8e026vjd 688o7PLDyWOFsFBlZNpxfP0yDg8DuTnP4PCHRBlwqWCbuRZwRkdJV42DusOf63aFS7n7Y Y3oaN5dg6SOhRLE1SEaQNxZLgPNGPQID4xYeaAsUGpXgRhKZ422fOp0itoTz+YHAEiSYk Ryor/05EkmyMtd8F+uPC/vcQrGuObUHPifMRNUtUJYWmp+KuvYWV49Sxv99EyMTcEow== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624375; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=KfmUk8QI1AV4ZYL3wSAlG0i2GOI4oVzm2QONpbqQMr0=; b=FVWb+bkPaLEa4gNDq/dtigu69qef4ySPKWgNmtxoMnOXTuKGglOsXmkvHYGa8B/iuB0b y3MqsPzuDed3wpxm2nJFKNtCk810MM/O2PV0DHc2DlPXDmDlcjqjG215SvPmEd4mk6tKz znnWmUVj5NN1omrGDrv0Oc0CRNwSkQGJeybImLs6h/L8tCV0EJDW5k1xUB4We0er+7sHE bGI6Vmynt1mYqZ8cuEe17fl69hf7AIKlbyrGgSEenZXLttqHEjO7Vt37VZhUS9U0+gELi tn9eE/tvbLxK3+2+0dfn6PDNWBcQUnA1UUtbxlMQdgwueVLC3CLBK7IClgr/OmpttNg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=XC9i466h; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.69.25 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010025.outbound.protection.outlook.com [52.101.69.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45607606A33B; Wed, 25 Nov 2026 16:32:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 45607606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=XC9i466h ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vti0NvE46x+R2kl7BFAjicQCL/vVCAfadUlJemm0Ed1PI36gdfmVFm/urKMsbfDw90LsO3TnVdHQrqAq9UgI3VIVQfMTGuBIIsnB0mRrLv91mG6pw8bOdK6WSlAmGCpVG6HWc/IeM2Y+vXd1PIM8kPdflr+DcwEVvHZwR0tTLkXj7B/Y3IlXPHEXwfKa/wJSYvJoTSsfTmXaPniGeVHRTIkt2sELaUVz60K46jfJlXUIaoDMALagUGA1F6Dk2FEgCowENIAT/pTFHAYP5kqpOVwDg5CK8hw45LBuLwoAAttMvX6WonWsNF40xJoRsDwNE0/U4lAi6zo2HD0Y6kpZTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KfmUk8QI1AV4ZYL3wSAlG0i2GOI4oVzm2QONpbqQMr0=; b=e9R0zgiHAfmcC2Np7kYY6cUwC9x1DutjoTGjLy0Av+G/t0KXC38pJKDirX/JVT68pw798Mpd8bfWrvgpUZqJ42t8NdrA+8MUpqL5ksXx2J00XZccBdAX7WP2ffTSSMHbMFutcQvPHw+0zUNIg67ADOA4IM5eJJe57/uDE3ndY2dJ62BHAvinxqDfnQGj6J5t+Qq2TZYEGeRkynd8RggIcYDXX4aG09YbbTgOkcfWiqhEdMS0YzdfBndkw6n+V7XNuaWyLIxy21hd3LMNL3fkv0mJIsM0opXbAy/e/XJyhqPLJZlaeFYlxoeO1goiizv8jzKhxFtHEKQz43Y7stjxew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.60) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KfmUk8QI1AV4ZYL3wSAlG0i2GOI4oVzm2QONpbqQMr0=; b=XC9i466hltJOkUVXb9ZaLZl6XilKhmgvGfnVYKohp2pq8QVQxTvOO4UAzpkEBGdudDR96VsBsMw2qO8vCipYMV6Q8poJxJFJIRYHV4ChwvlSF8WQVzTTtEgwUXpAHL5TWvCbcMehFvOqDxeuW8tpgkusCI1a/Nl2LuiYuhq7wFg1w6EjKAnBwZtmiDaYib8NLC5IPkSr7u8NtkYDpM3jJDs4S0qjWsSlvM4pry/BAyrttisQ7aaQeGRbO+gqS/OwtexIY2Ung0XFV17/ZUSjX3283dU7ePficj2SWHwmZ9/FnQrT3SaFKkmFN/N7DJwb6eQ5+u2R2nPJL1hzxAaY0A== Received: from DU2PR04CA0349.eurprd04.prod.outlook.com (2603:10a6:10:2b4::6) by FRWPR10MB9493.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:d10:1b2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.4; Wed, 25 Nov 2026 16:32:49 +0000 Received: from DU2PEPF00028D07.eurprd03.prod.outlook.com (2603:10a6:10:2b4:cafe::69) by DU2PR04CA0349.outlook.office365.com (2603:10a6:10:2b4::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.6 via Frontend Transport; Wed, 25 Nov 2026 16:32:49 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.60) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.60 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.60; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.60) by DU2PEPF00028D07.mail.protection.outlook.com (10.167.242.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Wed, 25 Nov 2026 16:32:48 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpO365.st.com (10.250.44.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:54 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:48 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:08 +0100 Subject: [PATCH v6 07/11] usb: dwc2: hcd: fix possible successive vbus supply enables X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-7-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D07:EE_|FRWPR10MB9493:EE_ X-MS-Office365-Filtering-Correlation-Id: 4bf3d04c-494a-40a0-8560-08df4b11be5d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|1800799024|82310400026|376014|7416014|261026121527099003|261022075727099003|261021123027099003|261021121427099003|11063799006|5023799004|56012099006|10067099003|261102123227099003|22082099003|261009223027099003|18002099003; X-Microsoft-Antispam-Message-Info: fAdj4OK3i6pJowIQh/2OTvb3YHRoGUrTWHTzb7XHSZ50U64Inex4j7HG9WbZU1gwcc083EiK5Hb2qwnOqswLdgC/13sKYgSz8frYJNxkgJgTQicF8ug4ps2I9s91JYZMyTXQUA94iXSKQkFWZBRTr1/nFFxY4pY6PU3fn6xsJh4JqzGzlQe9gCryTNSuQxq6HkjvvoH/YiSKLhpB3Z8dj7jJAfjV3nvjCNzLycG1u1v7x/75WYtNXDPH1Sa1h1z5H+h5kMSLI+7NMy336ve3Wo8vt16UUreb8w5sYlrYxJntzqL6FGqmkUI96zG4wVZEk0ijEzvybVe2RTn8sdDjfMOf4eVYY6GdzbtqigioJ+Y4CDNmmF+pwVMi4GzJENY+Y4qRH/pU9iPbSs3Ed5FeiqMBvWVOhlY2FrhW+6WlJoWK6DnAVR1OaPKJsEJvKWUq87rbn8PrwA28sjITALte1g4EH856G2jiCawaHTsqD1e9rA1sKZ+bSEGFe7CdarYVGBtAHYShhAEtNgSP/q6lZy6Cf6kCpcs62Z+chBSr1i5CEIfPf/8wRs5woZAbASVTDdM+4O17HKcSqBx4k1h8fjC8fcZJmmrYNlIKTxdtLgbgIXvkNwXfbeTdvPjCD+vphy/ShSzn/gsNntsFT1vn12pR/yUYgrzHlMCbzBFWzjZlm1PDqeBJwDRttGPT3w1GWcU1Yd7JMlyciWzNeXoq/w== X-Forefront-Antispam-Report: CIP:164.130.1.60;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(23010399003)(1800799024)(82310400026)(376014)(7416014)(261026121527099003)(261022075727099003)(261021123027099003)(261021121427099003)(11063799006)(5023799004)(56012099006)(10067099003)(261102123227099003)(22082099003)(261009223027099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lqVn10CxNHGVy19mNX2iHyxwjeCT8yUbNh5F8j37iX/ynTcYDBKkOJ2Fqkb2Z+DiWesFZ/EurxWK1WCLhnMmKIug5a5kCoqwwrpWgKo3eKXUWeLQxbXgzEl9J0fk0yzGShTQS4olBCu/otMjOxwEWLEEpLtWg9QCjdHVDXQNTwhbna1B6iY0vn/k/d9FYb9aSAxitkdvaXmWKFqj5mcwMJJCVu/aY5zNfwiMisfzNPnE5LwZXq9NkPqnJsvcKX+/RhfraQNS3RXEME4MNDYIrBBiwgNAMxW5cubfqEm5/PKabtsfmYTdbNYqzS+lJ3MB5RB81ZRdHqplvL6ZQ93b0bd/PziC1VVVRQOC6lrOVt9y8E56FCnxbHHUYZobMCCBDVIlxGbjP5Kasr6ebYzZymSTYiAEuwZwnAB/cRbyCbcxngD46rWIQ1PwyvEsZUEC X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:48.9057 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4bf3d04c-494a-40a0-8560-08df4b11be5d X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.60];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D07.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: FRWPR10MB9493 Relying on HPRT0_PWR value to call dwc2_vbus_supply_init() shows some corner case resulting in vbus enable count to increase. As consequence, dwc2_vbus_supply_exit call done when clearing PWR bit won't disable vbus (for example upon suspend request). Address two case that has been seen: - In _dwc2_hcd_start(), external VBUS supply may have already been enabled, before entering dwc2_hcd_reinit (e.g. the controller is in host mode, without any device plugged). - Upon resume from low power in case registers have been lost. In clock gating mode PM suspend flow doesn't disable vbus while in host mode: - dwc2_port_suspend() enters clock gating (it sets lx_state to DWC2_L2) - _dwc2_hcd_suspend() nothing more to do as already in L2. - _dwc2_hcd_resume() - checks HPRT0_CONNSTS. If it's not set (register loss) it sets HPRT0_PWR and call dwc2_vbus_supply_init(). Fix this by adding a boolean flag to balance vbus enable/disable calls instead of relying on HPRT0_PWR value. Clean the existing checks on pwr bit. A mutex is added as dwc2_vbus_supply_init/_exit calls can run concurrently from hub_control and dwc2_conn_id_status_change. Fixes: cd7cd0e6cedf ("usb: dwc2: fix unbalanced use of external vbus-supply= ") Cc: stable@vger.kernel.org Signed-off-by: Fabrice Gasnier --- Changes in v4: - drop previous vbus_was_off boolean. Introduce vbus_supply_enabled flag instead and vbus_supply_lock. - remove checks on pwr when possible as now replaced by this flag to keep balanced calls. Changes in v2: - Add a vbus_was_off boolean to check explicitly an off-on transition on port power, to enable vbus supply, instead of relying an XOR check that would be symmetric, e.g. wrongly enable it in case it gets switched off (1 to 0) as reported by Sashiko. --- drivers/usb/dwc2/core.h | 6 ++++++ drivers/usb/dwc2/hcd.c | 45 ++++++++++++++++++++++++-----------------= ---- drivers/usb/dwc2/platform.c | 1 + 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 89a34956bf22..1bd652c1bb42 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -10,6 +10,7 @@ =20 #include #include +#include #include #include #include @@ -889,6 +890,9 @@ struct dwc2_hregs_backup { * removed once all SoCs support usb transceiver. * @supplies: Definition of USB power supplies * @vbus_supply: Regulator supplying vbus. + * @vbus_supply_lock: Protects vbus_supply state and regulator operations. + * @vbus_supply_enabled: True if this driver holds an enable reference to + * vbus_supply. * @usb33d: Optional 3.3v regulator used on some stm32 devices to * supply ID and VBUS detection hardware. * @lock: Spinlock that protects all the driver data structures @@ -1083,6 +1087,8 @@ struct dwc2_hsotg { struct dwc2_hsotg_plat *plat; struct regulator_bulk_data supplies[DWC2_NUM_SUPPLIES]; struct regulator *vbus_supply; + struct mutex vbus_supply_lock; + bool vbus_supply_enabled; struct regulator *usb33d; =20 spinlock_t lock; diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 7729581d1102..cfa5d2af60d1 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -140,18 +140,32 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsot= g) =20 static int dwc2_vbus_supply_init(struct dwc2_hsotg *hsotg) { - if (hsotg->vbus_supply) - return regulator_enable(hsotg->vbus_supply); + int ret =3D 0; =20 - return 0; + scoped_guard(mutex, &hsotg->vbus_supply_lock) { + if (hsotg->vbus_supply && !hsotg->vbus_supply_enabled) { + ret =3D regulator_enable(hsotg->vbus_supply); + if (!ret) + hsotg->vbus_supply_enabled =3D true; + } + } + + return ret; } =20 static int dwc2_vbus_supply_exit(struct dwc2_hsotg *hsotg) { - if (hsotg->vbus_supply) - return regulator_disable(hsotg->vbus_supply); + int ret =3D 0; =20 - return 0; + scoped_guard(mutex, &hsotg->vbus_supply_lock) { + if (hsotg->vbus_supply && hsotg->vbus_supply_enabled) { + ret =3D regulator_disable(hsotg->vbus_supply); + if (!ret) + hsotg->vbus_supply_enabled =3D false; + } + } + + return ret; } =20 /** @@ -3488,7 +3502,6 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hs= otg, u16 typereq, u32 port_status; u32 speed; u32 pcgctl; - u32 pwr; =20 switch (typereq) { case ClearHubFeature: @@ -3533,11 +3546,9 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *h= sotg, u16 typereq, dev_dbg(hsotg->dev, "ClearPortFeature USB_PORT_FEAT_POWER\n"); hprt0 =3D dwc2_read_hprt0(hsotg); - pwr =3D hprt0 & HPRT0_PWR; hprt0 &=3D ~HPRT0_PWR; dwc2_writel(hsotg, hprt0, HPRT0); - if (pwr) - dwc2_vbus_supply_exit(hsotg); + dwc2_vbus_supply_exit(hsotg); break; =20 case USB_PORT_FEAT_INDICATOR: @@ -3741,11 +3752,9 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *h= sotg, u16 typereq, dev_dbg(hsotg->dev, "SetPortFeature - USB_PORT_FEAT_POWER\n"); hprt0 =3D dwc2_read_hprt0(hsotg); - pwr =3D hprt0 & HPRT0_PWR; hprt0 |=3D HPRT0_PWR; dwc2_writel(hsotg, hprt0, HPRT0); - if (!pwr) - dwc2_vbus_supply_init(hsotg); + dwc2_vbus_supply_init(hsotg); break; =20 case USB_PORT_FEAT_RESET: @@ -3780,7 +3789,6 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hs= otg, u16 typereq, dwc2_writel(hsotg, 0, PCGCTL); =20 hprt0 =3D dwc2_read_hprt0(hsotg); - pwr =3D hprt0 & HPRT0_PWR; /* Clear suspend bit if resetting from suspend state */ hprt0 &=3D ~HPRT0_SUSP; =20 @@ -3794,8 +3802,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hs= otg, u16 typereq, dev_dbg(hsotg->dev, "In host mode, hprt0=3D%08x\n", hprt0); dwc2_writel(hsotg, hprt0, HPRT0); - if (!pwr) - dwc2_vbus_supply_init(hsotg); + dwc2_vbus_supply_init(hsotg); } =20 /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */ @@ -4397,7 +4404,6 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd) { struct dwc2_hsotg *hsotg =3D dwc2_hcd_to_hsotg(hcd); unsigned long flags; - u32 hprt0; =20 /* Turn off all host-specific interrupts */ dwc2_disable_host_interrupts(hsotg); @@ -4406,7 +4412,6 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd) synchronize_irq(hcd->irq); =20 spin_lock_irqsave(&hsotg->lock, flags); - hprt0 =3D dwc2_read_hprt0(hsotg); /* Ensure hcd is disconnected */ dwc2_hcd_disconnect(hsotg, true); dwc2_hcd_stop(hsotg); @@ -4415,9 +4420,7 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd) clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); spin_unlock_irqrestore(&hsotg->lock, flags); =20 - /* keep balanced supply init/exit by checking HPRT0_PWR */ - if (hprt0 & HPRT0_PWR) - dwc2_vbus_supply_exit(hsotg); + dwc2_vbus_supply_exit(hsotg); =20 usleep_range(1000, 3000); } diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index d89a30308f86..24ede0b6ab81 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -471,6 +471,7 @@ static int dwc2_driver_probe(struct platform_device *de= v) return retval; =20 spin_lock_init(&hsotg->lock); + mutex_init(&hsotg->vbus_supply_lock); =20 hsotg->vbus_supply =3D devm_regulator_get_optional(hsotg->dev, "vbus"); if (IS_ERR(hsotg->vbus_supply)) { --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.65.34 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624378; b=ATxFvmbAyEUj37IJNAEIWnxLxYv7Bc6AEaVKJA5XfTn8jdBMFbX7zA2ke6Lo7P/T0Sd/ 9JFS9XtxritUdRifj/q83gqsEw/fM0Il/Ig3/H3OZQdy14B6rGSt7os5zmlkV7SjDQisz B3g/kHx548JJG2pod7Mh0LzpOxA7CXKJpCx+G4Yr4necoUbaQlckVAsnHPcWO12cI8Y3L J22FdqsLdJ4kdQp1If3UoGqVdhkx+sg4R5lt00GleYr8gOZBvnf8ABh1Di2jaWE4EiOy7 bNttNib58Z1stGKvec6QP0AeY398rtljXbBeQLls118uVDtjGEepeadAaiBjktTzj1A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624378; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=1TpJ6tl6aKWfY87mkDQVgw+co7QobZNUZTTVZZFqj/o=; b=PSYyaGkruMIOPrjtGjAvpax2JSz5Yu6rUCB8mXz7ccO8GzTHG2hPWKMx606H2OaYT9Cc 4zms3gxWm6yzCs8PvvVHs+O2l0UPTHjRH/dr4pi1Lnu8lov1qn21vbQa6frjcOa6BB7Nq dcULT9fiX2u+b0rC8o9xkSjHqSaGPtMzromq+wc/3JxvQJCEGylS0IQ6BDmpOvCG6aBsF PVraoKjQfBrRkFLHW56+659zzwWoRk94XjG4UxfcbqmYSQ/ug/4U9V6Lk2FSX9MVYkkVl JRMtv4gSR5cF8x5G0IiGzKJOJFumn/QNoysu6RIoCSKLEqt9xg4MU2jpVqloSv6C7Bg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=gcuqUuoo; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.65.34 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11011034.outbound.protection.outlook.com [52.101.65.34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5398C60A2600; Wed, 25 Nov 2026 16:32:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5398C60A2600 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=gcuqUuoo ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JOph9CVtD/aDTvRIMFCt9DA8lj0PEeiMFhcp5oX14K4+oLkCXM89m7zQxpDR9PKtPx2dLjKr5HOhrL3jl1b5tzNrwwKphv5gYPKCuvUPfqstVpj29vX1SYB/BrQZnyHgwjIrFq+ixaCbhg+POIwpMln0UnvEY+0u/jlYEhOmIudCykuz5yTUv4Ql2YEPALLBtEsyNa5viTfC7iX+FjIt27ruy7SM6PZBx3XxWN+KZS1Iua/ttkn0LdaRDwJeN4f/f5GADX6rfT81T2O2oTd2TIG5oCnN+xFl7B++oAiElvDWZNiwlWDKJwg6/XvTUZpDAaFuz1K+YES57tN5okIkCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1TpJ6tl6aKWfY87mkDQVgw+co7QobZNUZTTVZZFqj/o=; b=hdYxY+9hjCVuGEclZfMibZsfmv97hnz8FXUPlDoAUrF5dTrRdcYpC0TkRNKQOJrIuUvkppzVavEU6Ca0K6V6oWlOVUXaJTwfIkmsOSdYUjflHiBkHt5T+ZXug4dNHYPxLW7BZXpWAJ5x8x9GSd3lg4J5E+s/YkleESPYJi/PjiAH07NNFK93p26PBQ6tIws7padGLZOkRRLYKI9QvzxvV7A6z1Bo6yQ34dt0RZHG9oD+A8Gq6b5hzDFJu59gukgfivvS1y8B92OyN7VKTNMSPJrWw2CHij2z82QxHmYlU1dU3jba8kAGbXNWpaV8pM7472liF58bn+NEfkB4R9IkwA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.59) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1TpJ6tl6aKWfY87mkDQVgw+co7QobZNUZTTVZZFqj/o=; b=gcuqUuoolSAP348XFTEW64j7PcVyTtDaXn7jdctEliGaudk5kZIikc+b2OiXEWnEtDR4lJ9c/Y1dKIKmTHjQyCtMY0WVPxiA3HuGq76UaE0/+FSJnIQM5LAYt3Cm4mCpNozZ6DXbGzhZqbGT7mdDA/l8GZR5hPmgcK7nzK3QQ/z6fNZ1dwLZmA6Ll0ufI9SVkPRdv6NCYM7VJwBVZvs/jNn671V3myhNi3X4jhrjoWSKKgVdHqrglYa/A2dq2qMbYk3lY3ulJ6vAR2CnDIeMxeBHadP0b3OCHP7uMqsXEJibZ5lG/DJBHv1FkvNC2G9EKT52q/hkwsp5t0kCz0te7Q== Received: from GV2PEPF00048121.SWEP280.PROD.OUTLOOK.COM (2603:10a6:158:400::1f3) by DU4PR10MB9141.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:10:56c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.4; Wed, 25 Nov 2026 16:32:51 +0000 Received: from WA1PEPF00009B3A.eurprd05.prod.outlook.com (2603:10a6:1d8::118) by GV2PEPF00048121.outlook.office365.com (2603:10a6:158:400::1f3) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.10 via Frontend Transport; Wed, 25 Nov 2026 16:32:51 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.59) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.59 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.59; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.59) by WA1PEPF00009B3A.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Wed, 25 Nov 2026 16:32:51 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpo365.st.com (10.250.44.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:38 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:48 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:09 +0100 Subject: [PATCH v6 08/11] usb: dwc2: hcd: don't disable external vbus in system suspend X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-8-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: WA1PEPF00009B3A:EE_|DU4PR10MB9141:EE_ X-MS-Office365-Filtering-Correlation-Id: e5bd7bd4-13c5-45df-04db-08df4b11bfbb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|23010399003|1800799024|7416014|376014|82310400026|261028144727099003|261102123227099003|261026121527099003|261022075727099003|261022105027099003|261021121427099003|261026140227099003|10067099003|11063799006|261021123027099003|56012099006|18002099003|22082099003|6133799003|261009223027099003; X-Microsoft-Antispam-Message-Info: z2mV33lHmPjj5z+Rm5+ANXZBhR6qh46lsElyF6AOtZ/ag9ddCX8V/DZpd465UrQg6qhql9CiocqWy/JST3M/jChhAwkgkPQ5xLyryBOaedhnAjlu+xLu8oTyauGt7j9olzt93S6J3UUBINrxYbvQP0/hKUUKSiHQiFeLpisOvtWxWIb2JnrTvmZ9XMXlGBPfWMDwi9zUpLxVLqGFCmPhwJL1I4vHRRr1CyYNkr+7FV9q1pWenY19ZmN+C01oKzrM1zqsHuYTItsSwPqQ5TNTVE9pJRT5lMNIOljkKLq8t8zHAldfj/UPtoWgUNqgfYJCpMThSMn9TKXFzvxSDd1Hk573ZChOygKcurASse1MQfI/NM5EOv+aPCdgcm1gf4l6ucrZgMSIQ8OJqnkls2c6jsKztq+GrcljbI/jlYowMjdo0lgkJB4Adr1MIkLJR5E4xx+nXeSLxseuAUHqI2rmTt+wvfJSDmmAVibj8+Zrxfl9I6fCvhnadQIsFwGpETkauRpPO18ZtYseYMizFURR2j3GRbpRPw4pAsSZgTQY3e+D1riIwP/e5JeRA5UfQih6aocUcUTtADY9HEhaKEYvZ/e/72nRFTheBfzpiyKvMJEchHmH9HgFyBQKZIissf8XKVEsbKLIvbPD4rTS0oC00Tr+Tj+xHR3bjpnQwErbyJpnBenFq4PzbD+6iiIMY9B8MBOAuClSIGlgTYo1LM+kFw== X-Forefront-Antispam-Report: CIP:164.130.1.59;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700016)(23010399003)(1800799024)(7416014)(376014)(82310400026)(261028144727099003)(261102123227099003)(261026121527099003)(261022075727099003)(261022105027099003)(261021121427099003)(261026140227099003)(10067099003)(11063799006)(261021123027099003)(56012099006)(18002099003)(22082099003)(6133799003)(261009223027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VF/kWWRmoJ/u5AtDFfBqswMftlBDPq8KbZHUnmfK0yxUFLp82TG3l/krjhNrIF7BWLObDZO3eZbnoF4FJ3hF04TumhIUPKMCbrGFKk7QJen0ToPcPvNgkMxhdYFL6b5To9lxQzR+8iEaonuXlGev1DM8xf+FtHqnKpcqjHrjZ50j0XsGntKaXNekN6B9zzbngalc8aTZgKfsV7NNC5uHcuHnxyjn7spjWaOOE9LX8KI/SlA9p4mm1071n+MQRADinWiGOnanBuE/2k/C11jCqrcne2Xlpj5lYYj6n6oTMIUu1/hGHIWoNUwHEKrtfzcwCnVy+w7UxM2DUhUSE7koGdD8K141zCOmtrP2q0BtftGGmaJ9Z0X4FdceWFWXDhewvMYvhTxB7XReVof9qiyoY4gMk0O9W0WRoCkVTkwXpb3AaM5Ukk0CDY7srHYzBtmB X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:51.2022 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5bd7bd4-13c5-45df-04db-08df4b11bfbb X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.59];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: WA1PEPF00009B3A.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR10MB9141 It's not required to remove port power upon system suspend, as explained in commit 113f86d0c302 ("usb: dwc2: Update partial power down entering by system suspend"). It can be addressed with hub ctrl (USB_PORT_FEAT_POWER). When PM suspend flow disables Vbus while in host mode by calling dwc2_vbus_supply_exit()) in _dwc2_hcd_suspend() and the core has been put into clock gating mode, it triggers a disconnect and a resume IRQ (during suspend): ++Disconnect Detected Interrupt++ (Host) a_host ++Resume or Remote Wakeup Detected Interrupt++ That starts the wkp_timer in dwc2_host_exit_clock_gating() that will finally resume the port, e.g. call dwc2_wakeup_detected() and set lx_state =3D DWC2_L0 after ~70ms. It races with PM suspend/resume flow. During _dwc2_hcd_resume() the port may already be in DWC2_L0 state skipping the dwc2_vbus_supply_init(), leaving the Vbus disabled. So remove the disable of external Vbus in bus suspend to avoid this. Fixes: 113f86d0c302 ("usb: dwc2: Update partial power down entering by syst= em suspend") Cc: stable@vger.kernel.org Signed-off-by: Fabrice Gasnier --- Changes in v4: - Rename the commit title and re-visit the commit message. - Drop dwc2_vbus_supply_restore() but keep dwc2_vbus_supply_init() to enforce vbus is present when setting PWR bit. Changes in v3: - Sashiko comment (state desync leaves VBUS regulator permanently off) Add a dwc2_vbus_supply_restore() to check regulator enable state during hcd resume, if it has been turned off earlier, enable it, so it is kept sync'ed with PWR bit that gets set. Changes in v2: - rephrase commit message since Sashiko review. Hopefully it better explains the issue, and why HPRT0_PWR is kept synchronized with external vbus supply. --- drivers/usb/dwc2/hcd.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index cfa5d2af60d1..a39dcbddac84 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -4488,10 +4488,6 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd) goto skip_power_saving; } =20 - spin_unlock_irqrestore(&hsotg->lock, flags); - dwc2_vbus_supply_exit(hsotg); - spin_lock_irqsave(&hsotg->lock, flags); - /* Ask phy to be suspended */ if (!IS_ERR_OR_NULL(hsotg->uphy)) { spin_unlock_irqrestore(&hsotg->lock, flags); --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.72.46 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624378; b=enpYcHRl9hclKlYqBTcQGBdFF2lqFVB3ZXgY3mcZ0aNp17LgUweQEGfAYNIhVIPylPEp qeCfHdDxIHzUIEKrPUJbmzte7rSYNT/a4f/zD1nfQ6dLFpVL4Cs5lJ3aYIY0kPfW6ZaDi 8LckbXimUwcJYPUxorXPJxoh8muMJ0KipgSKOLmFuBGnj3e36AsCGetyRrxnmY0Kjmylp 3FJPpBf9V7A6uLq/O23UK79Ve2+KYHKdnrhDW+aK8126m6o1YI+0COugJ8C+hoDUWujQq Y30UbmDbzilt/Ko8JqkPSeKvjwJ68T6JEpGZC74y5A8P/87iyS9Tb7dsnEHYMe4Bz+Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624378; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=H45BjX8T/R64QiwV+Emc1kWhRKM4agy57BaKYDaly+8=; b=xy88IZI+y6Yg+YeDAMy54FjSE057i9UFym60DmyQB3vBWKxGS4gbZxs6HEwxfQHeBmwB QXhBz6+RKIgHFG+oy2X9/EPr+GuKOe2nZnwSDWntj+vqkOxzpCQSfhyEOo+TdYDOlK5aB MlXBAQBRESrGvI64gM6xj4ftEmE5X+OKAjO7z7MpigCrEtgvNx8tw2P+seRMiuvoJCHjN Ksk5k/q54jUprvetwSf9viK02fxkNwcBBNB+vjlSKGzO1695WqSMgSVUD09+PcBOMglGd y5yVr4MAhlvh398g0J/D5pyOpTbDWL5J97tfVnEaJWO4faxLdwTE9arvbdLau9iukQw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=jeqrDcIl; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.72.46 Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11013046.outbound.protection.outlook.com [52.101.72.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEDF3606A331; Wed, 25 Nov 2026 16:32:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BEDF3606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=jeqrDcIl ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vDZD/0djnccwTET6/MHSwimf2RQrmGshfzGdpNRuFcPafe92ivfQKp4GVvgIg9k1T+T75buA3GPOvA2Ot8tI/FDkea6cr16WcaCSa+qQyXM9VTsf82/yBRhdDw7E/ihd+xePqZb5PssisI7C54PZZrBbfJ1Na9MTPBQArPcR7XNe8RRf0ePve2mo8ZbOYWxkbEQTxiW/qZ26qGuLf6cyTdZEZupXFG3AgpI70ZbNnQ9bTIQIyFvf2dZS90XOgEDSkYdR+w8AS06ju4sVMh7Yd9ImNCHyzATsCBn9zUnQmf404+9TATrrc5EOV2nD4HRYy/w+UMdkkF/scVWvf/yFqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H45BjX8T/R64QiwV+Emc1kWhRKM4agy57BaKYDaly+8=; b=YuLPT3MqOe11+FdWCXgaRc6cVMtHUZblQ5oNFFpGMm24CNpi8Q2O7ICAQepWyAdDXhk0de5vjeBjEkiVr7ST6gKmsqv2jo6s9pmOjIyHodXm9blfMdsIPuVpzNb3rvLELoMRbdefGRNQboBRklquy0vPyTz/QpB4uqt0CSLzyz2NmC90kdPzvqPytl1ZZZ3WU54lBCozSDyFdZ+dJzABZqssNnDLhKX0UOHLw8wn9eKUWdFw222tpjug2mxX9a1Ab6gTmN8weC5kCwszoi5cN/39JKoE46a/GfvkveZg7sJTXwJBpx6DhjUplllAdmnqFlVoFQDHbyBzalCXmsEkkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.60) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H45BjX8T/R64QiwV+Emc1kWhRKM4agy57BaKYDaly+8=; b=jeqrDcIlM5lnf/IF/2mLIMGiUjzDQR5GoX+ppNWz5dBvnlR9EGiVDNXSM3ICcZfJcGrIYQetyPbrLub5BnriJ1KQsm5R+p+JEKgurr+QUd/9z080p7sSaOqqsMDTece1dpmdty53FRARmgucFXOV2VZ0fGI8p2iYCVQ8sCghwJuKV2qmaiRzZAs0dsAPmV8hmj7atMzX/DNlMUp/ZZLCxVHJj+K3RnnnUgluPLBBDWIdT8opNuHnRP6cwqwxEk+BKfW7FJNUHUUn8hGuCHqEm6/o6L71RoNP/C7Z00ExGg3nhXBFssCqYFOIya8xCukBtKdD8jdjn61zk3uTufQ82w== Received: from DUZPR01CA0322.eurprd01.prod.exchangelabs.com (2603:10a6:10:4ba::20) by PA2PR10MB8720.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:102:422::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.6; Wed, 25 Nov 2026 16:32:50 +0000 Received: from DU2PEPF00028D04.eurprd03.prod.outlook.com (2603:10a6:10:4ba:cafe::26) by DUZPR01CA0322.outlook.office365.com (2603:10a6:10:4ba::20) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.662.7 via Frontend Transport; Wed, 25 Nov 2026 16:32:50 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.60) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.60 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.60; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.60) by DU2PEPF00028D04.mail.protection.outlook.com (10.167.242.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.639.5 via Frontend Transport; Wed, 25 Nov 2026 16:32:50 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpO365.st.com (10.250.44.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:55 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:49 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:10 +0100 Subject: [PATCH v6 09/11] usb: dwc2: restore peripheral mode on low-level enable X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-9-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D04:EE_|PA2PR10MB8720:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bc6cc91-1954-4124-fdde-08df4b11bf2c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|82310400026|7416014|376014|1800799024|36860700016|18002099003|22082099003|261009223027099003|3023799007|13003099007|11063799006|56012099006|5023799004|10067099003|261102123227099003|261026140227099003|261022105027099003|261022075727099003|261026121527099003|261021123027099003|261028144727099003|261021121427099003; X-Microsoft-Antispam-Message-Info: kvsfPK6KXnD8O9/KhWoy5XjhPP9R4bnuSCQis99XOF7SdSDxsPrt5BaDG6wYM4aHcM1XCD3UscKyMT8usTV5br0WeqNnkl4NKwE7mVI2XibVKdqt8FQVGuxyf+dR9Kl8nMdlMXW8J4K9Wzk0/OVjdmePT4Sluxap5gvQ3BC6GSud24U6pV8S+maMUv5coS25oTSpYmlCPAQp2XjXwfNtvfVHJQJJT6pXXzlaC5ZiMMyXZPHOlecfXrd8aB0jAg06zMf5CXvDGPCxBPC4JApyhTcOJwa/ak6g0zrULlD8AukJ4TJmRhMWlHppPGE7D9zANXwe8Jk9P91wcsctOBC69OdpCNWBULn5IhxjMzer0eNd+/JtyigXZZsnE6ZJjo/yGS0e58Gfq1MB4Ioo0iDNBGKEdXPGpwbrrRheq6jjHmzCN6DFqMcfpszZWxR+/3+2CWQ8aHyzmcM+/R4PxDpbwoDRow4VQQRV/BQh2Q6mU1a8UvJOV46DKQDIgeGds9FdraVFZ6IVS5WJSpEQRBK53aab0ym2rxqUFtl42YO4CDbmh4Y+Y86MKmRikZf6IXv8oAcx/kyqVOpTke0tTpN88XNwHRX6iN/uZu5Xre7mZSjFwPkVCrbOXJkZWsRsN+YKiQ60MyCAw6vp3aLElhFYPQ== X-Forefront-Antispam-Report: CIP:164.130.1.60;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(23010399003)(82310400026)(7416014)(376014)(1800799024)(36860700016)(18002099003)(22082099003)(261009223027099003)(3023799007)(13003099007)(11063799006)(56012099006)(5023799004)(10067099003)(261102123227099003)(261026140227099003)(261022105027099003)(261022075727099003)(261026121527099003)(261021123027099003)(261028144727099003)(261021121427099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4Ibl2cY9Ej8rnyXbdSeN38qNlCzFYsoDQujo0iTo+zjYLiN4E2pNOW6H8ar+oXf5E0cq44QCwvTL/IwfDl5yYhmUJSSTu84tf+UN0aRIBBcRb2Luel4foZOrIDW+OfGx58uDicRQ2t867j9fI1w6pgkBodOEQsjrO6YYOoelkTjEM7hITKaURpYxmpLOF2re2j/PtCvxEDDQ6ZKyrTh/V04HxXSTeX2IA71OGq/Bx2+yabMdqUmQT0b8HHH7rFaHwVnznhrNWHpkKXpcH5PkklHFSQ0C8CjfFaNgD4pb+yDFwNAYauMJ/THKLOUCb9UoMtAVruAe46SJvdXnbQUG5fILR0pLRr0EVYam2zYUQRTq0YcqfeCpKKHmaRVoVS0Hzn+B7RXTG78ARESsPKEMH/zPI6iMnFHel0Ije+fBxsBXZMijdUiza88lGcjI3HD6 X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:50.2685 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8bc6cc91-1954-4124-fdde-08df4b11bf2c X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.60];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D04.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR10MB8720 In fixed peripheral mode, the gadget code manages the low-level hardware on its own: it is disabled after probe, and enabled again when a gadget driver binds. While it is disabled, dwc2_suspend() and dwc2_resume() return early since ll_hw_enabled is false. If the DWC2 registers are lost during system suspend, nothing restores the mode selection when the gadget driver binds later: - FORCEDEVMODE is not set, so the core may not come up in device mode. - With a usb-role-switch, the session overrides set by dwc2_drd_resume() are not restored either. Restore them at the end of __dwc2_lowlevel_hw_enable() when dr_mode is peripheral: call dwc2_drd_resume() if a role switch is registered, or dwc2_force_dr_mode() otherwise. The dr_mode check leaves the probe-time enable unchanged, as dr_mode is parsed later and the role switch isn't registered yet. As this is now done on low-level enable, skip the peripheral case in dwc2_resume(). Other modes still restore the forced mode or the role switch session there. Fixes: 2b94b054ac49 ("usb: dwc2: fix hang during suspend if set as peripher= al") Cc: stable@vger.kernel.org Closes: https://lore.kernel.org/linux-usb/sashiko-outbox-219235@kernel.org/ Signed-off-by: Fabrice Gasnier --- Changes in v6: - Also restore the role switch session overrides with dwc2_drd_resume() when a usb-role-switch is registered in peripheral mode. Issue raised by Sashiko. Changes in v5: - New separate patch added since issue raised by Sashiko on next patch pre-exists, e.g. missing forced mode restore in peripheral-only mode. --- drivers/usb/dwc2/platform.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 24ede0b6ab81..38954dee6ad0 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -129,6 +129,18 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg= *hsotg) if (ret) goto err_dis_clk; =20 + if (hsotg->dr_mode =3D=3D USB_DR_MODE_PERIPHERAL) { + /* + * Gadget code manages low-level hardware on its own. Restore + * the mode and role switch session after register loss while + * it was disabled. + */ + if (hsotg->role_sw) + dwc2_drd_resume(hsotg); + else + dwc2_force_dr_mode(hsotg); + } + return 0; =20 err_dis_clk: @@ -778,11 +790,12 @@ static int __maybe_unused dwc2_resume(struct device *= dev) spin_unlock_irqrestore(&dwc2->lock, flags); } =20 - if (!dwc2->role_sw) { - /* Need to restore FORCEDEVMODE/FORCEHOSTMODE */ - dwc2_force_dr_mode(dwc2); - } else { - dwc2_drd_resume(dwc2); + if (dwc2->dr_mode !=3D USB_DR_MODE_PERIPHERAL) { + if (!dwc2->role_sw) + /* Need to restore FORCEDEVMODE/FORCEHOSTMODE */ + dwc2_force_dr_mode(dwc2); + else + dwc2_drd_resume(dwc2); } =20 /* --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.159.3 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624380; b=IFZ2RiP6VFEbkebg5QewBjUfAIUQ4GdGdJ4JBcu3NxInmf6JTvIsCfM7X0LoP+F7/msa PS1RufKx62yaR9Qq+SGOxB/ziCSqAH9z/z4GY8JDbuuyDUCGbo+4QvmARyvZsQugZgf71 O0gDQ8ZA/nSP18oM3U7rAnzXwIggJNsNrnB/n9cm46CLeYaVEUgSOnDEo1LMuC0SXXS7z 0gMbEusgmAbDTN3BaHaQhueFv4oPXWqlKaYfbEBM7NDOi2VEoUTWxWPndXsjGzyPfDbjW y+ozM5lfXUcp8LPLBnD5BzgEiCADZKhUUE5MF2XCWlQ0Pqko2SGlu/kRIUvW2Ep4RiA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624380; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=EEGbrS4K6C/6pC2mAOyqkHWx4fF+vTiq+oFnii/QJ0A=; b=VCOs86O+pkK1yy8RscyjjvxeHcLr7GYkTKQm2hRKeODsAqRNAxfBkI95EiO0KdOVOLhx 8EGaAbiykYO1/ZhslV7CuCalimgM2dZ/6uEP6O4jLZ5oelSOoWe9iqigPTAiqaCKL9Tws pT9gayxrnZi7AX1tLbj+zHgBSdgQZa7trYqRCw7PQEDtaBlo2tg4frhOknRmSmDUgPIu7 tZk4NOV4RzWdjZ4wf1m4npYNO1WsyGvuvYEunekvFBkAckVZnMDPYPA6ZnT0SM1H/BKSz qR4CpJuoUvIqdPk3DlsZRYc5/7jIw1jKKvTEf+vbPJyXEOcRB8oo9ImrHE8vNZ99a1A== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=StKsDmv1; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.159.3 Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11013003.outbound.protection.outlook.com [40.107.159.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ECFB60A2615; Wed, 25 Nov 2026 16:32:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3ECFB60A2615 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=StKsDmv1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QQ9rIHEa8YivGs1h6ePoXo7LW70mFuuY808wPU0LYfaHZtj270IPgzzqQ6//9fXKzuO+o0FwwFMmRENWgrv5+49rXr+f6CZQ6hrdypGjgwL6lwRzbUZoMHJdI00ESy1wfP/mRc0+EH/t03+/GgTVZ8MemHDLMoILf5usct1UIkPWcNhFn3fKQubBgfooanWOp/tocwkWIUVpnmKcIug/zttiOMomrGgQ25Hb049QhcHvHAwTZqg35AXjtLV5hrccZD6tl7IaGZjY904sDcHoqFDM6+2udxjgLOxblZBLgrCuPn8ap0QU+dlnDYVyhfDJ21Rqdhjrg8F+gY0K8T11ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EEGbrS4K6C/6pC2mAOyqkHWx4fF+vTiq+oFnii/QJ0A=; b=JqyHagLItrI8cb/5Xvv/TXaSMCRe1yQe6Eq2kgR7ad6aV1c9NY433Ea6jEIFRsDEqySXi7gTZtsIP9gfUA8HO0Kfh4PSFI5I6pIJHRdxRveAP+t2/EtrkZ6c9W8s9hvrmU6lUU4uXb/+Ge5ANQ8uUVwAvegUtipVOnrLdWoBCcD7JEc43smO+tLkqkILO+Phf765I92LMzNJIJ/t37I4a+B70q292uGR46dgtyjx9oOAlXXXuXUDsuu7uvDxxlKiUlfBduzu2lR42Gs5DDyDFjZr7v9scZM7KyHoeQvFU/qUWEjr88Hjp80yvNhXFcW3/WCOz20ErqzbMXGXi0nkew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.60) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EEGbrS4K6C/6pC2mAOyqkHWx4fF+vTiq+oFnii/QJ0A=; b=StKsDmv1fYTcw9ps6R1M8Uv5w+B2w8gVs9jDbut/8NPXOpWm51Y90DPqBa/E7yrj6/HuMe3TAVE3mmmXkp1yJpdKBh9HQeHAp7TcdCsEvTYjqe0CHAoVkgnTjQ9erETLI79UYCBl4pf29h+1R1O5+0RgwxjUefo7oVfXAzdSFnX0lSNmhwv4BwUDITaHK0ftv0tftlGkqTD8Zq+7xhu4acTYrTprYZ1QAPm6YEPGd0UG7pT/Pi5c2VjdIxJATMzIBDeGXkAGeUcCP5QsBsLBupez/E5D88DLl/fcDHVbrAT3TQiKv6QprO+Yr16QW1SKCKyFp3mSZkoiiBSe3KIsZQ== Received: from DB8P191CA0009.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:130::19) by VI0PR10MB8835.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:234::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3; Wed, 25 Nov 2026 16:32:51 +0000 Received: from DU2PEPF00028D06.eurprd03.prod.outlook.com (2603:10a6:10:130:cafe::69) by DB8P191CA0009.outlook.office365.com (2603:10a6:10:130::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.639.14 via Frontend Transport; Wed, 25 Nov 2026 16:32:51 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.60) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.60 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.60; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.60) by DU2PEPF00028D06.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Wed, 25 Nov 2026 16:32:51 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpO365.st.com (10.250.44.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:56 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:50 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:11 +0100 Subject: [PATCH v6 10/11] usb: dwc2: platform: fix stm32mp15 detection logic power management X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-10-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PEPF00028D06:EE_|VI0PR10MB8835:EE_ X-MS-Office365-Filtering-Correlation-Id: 7275cce3-c7df-4fbf-fbda-08df4b11bfab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|36860700016|376014|1800799024|23010399003|22082099003|6133799003|3023799007|18002099003|11063799006|261028144727099003|261102123227099003|261021123027099003|261021121427099003|261009223027099003|261026121527099003|261026140227099003|5023799004|261022075727099003|261022105027099003|56012099006|10067099003; X-Microsoft-Antispam-Message-Info: fEru+n30HNWrdw6fWo9dKJzMfuCeCHQamhHlDp3JmrrGfJSNdRuMbIwNK2Ww81wgKPQkj7OYmK4fxvGLJ/dNHe12/ywYxqC+IK71PNV2Zb2tEIlVwSRDXJpsM9ailK1K3ZhiQG0CL/Lk6Rs+NT4YS7DSupwi2syZbCgWgh6pWK6ysd8ZOy+5qG2BVEOiIDV9ZCeIwfPQDPqdT6owEnb9mKswWlUiC6t6IJs56WHdIhjsX7A8mPXxxSS16fmXRoIwfaL/3LeiiENlgg1EADW+T4Mrle5dl9nle06JE9o4RISaUP9EYczEnLMEFmGX+W/ENVUO0kmQZRt7GrZGsmFGiYh91H/fXrdZvzesaxqBx1TF/ngj6FaPMcUqyizgdNh4NMfY0AqSvah7qEbHGJCkvfh3ZhF3BNffJtN9Zs09rUjU2chNNHOxGdDTp7+eIDhW2k8AeGr05+qg309zIthHAnNnPo5XV2En3vpuWUZET3l+iPagObDscZ/2JAxzggNEiSToUHVKqRYzYx3Co4Iy3Pfi790LqMOxQ3mOAmy48rcDOF2myR0pc6RPwXFTKz9YbBX9lkrBpwYhDFPlLn/asO9tDg4ijjxnvu05OGwZC65fuluzrwLwQCQGu4xfhrYokZparvL4pBfiabHfts+ip9ipjJBD0zz0/HdHioTp8dbhgEklSA1wdXBj5lQBdFHCrO6+AFQ6UHlPsmw30PUAiA== X-Forefront-Antispam-Report: CIP:164.130.1.60;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(36860700016)(376014)(1800799024)(23010399003)(22082099003)(6133799003)(3023799007)(18002099003)(11063799006)(261028144727099003)(261102123227099003)(261021123027099003)(261021121427099003)(261009223027099003)(261026121527099003)(261026140227099003)(5023799004)(261022075727099003)(261022105027099003)(56012099006)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z1OPvw0Cb99IwJW5jiqywnNWzQRU1UUJXaqjZCAC0hJMrTwStGQYscGBtvuap6/bQw5eB5+E1YbMQSsa1x6Q+tYrbY4rLzih7UZmgp0/il9q1niWJt0yGg8PJsbyX27aVOX8UppkQRu0HjZRDehMDvxEveG6RM7ra/yrNQRHrCq9Ghe1Aa8s9dTZZ65xagH/IapuLzQgcPnP+J3jf/Dti6P9aXN8KvRN91AGam8+5x8wOP9oRZ9rUtqyCJ9kI+5glsFTTEIzHUs+0BYX/+64DaftANz5pyuskJty21dz5/zUu2zDU/ZQ1QoQXfw1iUWd1YQvSBRARevxtF8NT3aBD/TE5CwjMRg8WHsIga/DGBnspFPrEvCnt8TixHnOxUhFs0qdGKazfvseG1evCnA79H35+UVhLwl0FPq0Kusg7Zm5oVNWcvpV7eT1rbhPVzfG X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:51.0045 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7275cce3-c7df-4fbf-fbda-08df4b11bfab X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.60];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: DU2PEPF00028D06.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR10MB8835 On stm32mp15, the STM32 detection logic can remain enabled even though the other hardware resources are disabled during probe in peripheral mode: /* Gadget code manages lowlevel hw on its own */ if (hsotg->dr_mode =3D=3D USB_DR_MODE_PERIPHERAL) dwc2_lowlevel_hw_disable(hsotg); When entering system low power, the detection logic resources would then remain enabled because dwc2_suspend() checks: if (!dwc2->ll_hw_enabled) return 0; If the stm32mp15 enters standby, the register contents can be lost and not restored, leaving dwc2 unusable. This can happen when no gadget driver has been bound. Move the STM32 detection logic enable/disable procedures into dedicated dwc2_stm32_hw_[enable/disable]() routines and call them from the __dwc2_lowlevel_hw_[enable/disable]() routines. Factorize the probe code by replacing regulator_enable() and GGPIO register access with a call to dwc2_stm32_hw_enable(). The earlier dwc2_lowlevel_hw_enable() call during probe cannot do this because activate_stm_id_vb_detection is only known after dwc2_init_params() runs and the usb33d supply is acquired. Track VBUS/ID detection state in stm32_id_vb_detection_enabled so it is disabled only after successful enablement. Fixes: 2b94b054ac49 ("usb: dwc2: fix hang during suspend if set as peripher= al") Fixes: a415083a11cc ("usb: dwc2: add support for STM32MP15 SoCs USB OTG HS = and FS") Cc: stable@vger.kernel.org Signed-off-by: Fabrice Gasnier --- Changes in v5: - rebased on ("usb: dwc2: restore peripheral mode on low-level enable") intended to address sashiko comment "usb: dwc2: missing forced mode restore in dwc2_stm32_hw_enable()" Changes in v4: - Track successful STM32 ID/VBUS detection enablement with stm32_id_vb_detection_enabled, avoiding an invalid regulator disable during probe error cleanup, as reported by Sashiko. Changes in v3: - Roll back if regulator_disable() fails in dwc2_stm32_hw_disable(), as reported by Sashiko. - Add a note in response to Sashiko's v2 review. Changes in v2: - Fix the probe error path if devm_regulator_get() or dwc2_stm32_hw_enable() fails, as reported by Sashiko. - Describe the hardware-disable error handling in the commit message. Notes: - If dwc2_stm32_hw_disable() fails in __dwc2_lowlevel_hw_disable(), there is nothing to roll back, so return immediately. Alternatively, the error could be ignored to continue disabling other resources. Similar behavior already exists for phy shutdown/exit/power_off errors; this could be addressed separately. - In host mode with remote wakeup enabled and a descendant enabled to wake the system, phy_off_for_suspend is false. The STM32 power domain is not expected to turn off, so registers should not be lost. --- drivers/usb/dwc2/core.h | 2 + drivers/usb/dwc2/platform.c | 185 ++++++++++++++++++++++++++--------------= ---- 2 files changed, 112 insertions(+), 75 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 1bd652c1bb42..9a3bf6a5047c 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -878,6 +878,7 @@ struct dwc2_hregs_backup { * remote wakeup. * @phy_off_for_suspend: Status of whether we turned the PHY off at suspen= d. * @suspended_in_device_mode: True if the core was in device mode at suspe= nd. + * @stm32_id_vb_detection_enabled: True if STM32 ID/VBUS detection is enab= led. * @need_phy_for_wake: Quirk saying that we should keep the PHY on at * suspend if we need USB to wake us up. * @frame_number: Frame number read from the core. For both device @@ -1080,6 +1081,7 @@ struct dwc2_hsotg { unsigned int need_phy_for_wake:1; unsigned int phy_off_for_suspend:1; unsigned int suspended_in_device_mode:1; + bool stm32_id_vb_detection_enabled; u16 frame_number; =20 struct phy *phy; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 38954dee6ad0..c1f5e03c0d03 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -91,6 +91,95 @@ static int dwc2_get_dr_mode(struct dwc2_hsotg *hsotg) return 0; } =20 +static void dwc2_stm32_hw_activate_id_vb_detection(struct dwc2_hsotg *hsot= g) +{ + unsigned long flags; + u32 ggpio, gotgctl; + + ggpio =3D dwc2_readl(hsotg, GGPIO); + ggpio |=3D GGPIO_STM32_OTG_GCCFG_IDEN; + ggpio |=3D GGPIO_STM32_OTG_GCCFG_VBDEN; + dwc2_writel(hsotg, ggpio, GGPIO); + + /* ID/VBUS detection startup time */ + usleep_range(5000, 7000); + + spin_lock_irqsave(&hsotg->lock, flags); + /* Remove overrides when resuming from the disable */ + gotgctl =3D dwc2_readl(hsotg, GOTGCTL); + gotgctl &=3D ~GOTGCTL_DBNCE_FLTR_BYPASS; + gotgctl &=3D ~(GOTGCTL_BVALOEN | GOTGCTL_AVALOEN | + GOTGCTL_BVALOVAL | GOTGCTL_AVALOVAL); + dwc2_writel(hsotg, gotgctl, GOTGCTL); + spin_unlock_irqrestore(&hsotg->lock, flags); +} + +static int dwc2_stm32_hw_enable(struct dwc2_hsotg *hsotg) +{ + int ret; + + /* params are only known, once dwc2_init_params() has been probed */ + if (!hsotg->params.activate_stm_id_vb_detection) + return 0; + + if (hsotg->stm32_id_vb_detection_enabled) + return 0; + + ret =3D regulator_enable(hsotg->usb33d); + if (ret) + return ret; + + dwc2_stm32_hw_activate_id_vb_detection(hsotg); + hsotg->stm32_id_vb_detection_enabled =3D true; + + return 0; +} + +static int dwc2_stm32_hw_disable(struct dwc2_hsotg *hsotg) +{ + unsigned long flags; + u32 ggpio, gotgctl; + int ret; + + if (!hsotg->stm32_id_vb_detection_enabled) + return 0; + + /* + * Need to force the mode to the current mode to avoid Mode + * Mismatch Interrupt when ID detection will be disabled. + */ + dwc2_force_mode(hsotg, !dwc2_is_device_mode(hsotg)); + + spin_lock_irqsave(&hsotg->lock, flags); + gotgctl =3D dwc2_readl(hsotg, GOTGCTL); + /* bypass debounce filter, enable overrides */ + gotgctl |=3D GOTGCTL_DBNCE_FLTR_BYPASS; + gotgctl |=3D GOTGCTL_BVALOEN | GOTGCTL_AVALOEN; + /* Force A / B session if needed */ + if (gotgctl & GOTGCTL_ASESVLD) + gotgctl |=3D GOTGCTL_AVALOVAL; + if (gotgctl & GOTGCTL_BSESVLD) + gotgctl |=3D GOTGCTL_BVALOVAL; + dwc2_writel(hsotg, gotgctl, GOTGCTL); + spin_unlock_irqrestore(&hsotg->lock, flags); + + ggpio =3D dwc2_readl(hsotg, GGPIO); + ggpio &=3D ~GGPIO_STM32_OTG_GCCFG_IDEN; + ggpio &=3D ~GGPIO_STM32_OTG_GCCFG_VBDEN; + dwc2_writel(hsotg, ggpio, GGPIO); + + ret =3D regulator_disable(hsotg->usb33d); + if (ret) { + dwc2_stm32_hw_activate_id_vb_detection(hsotg); + dwc2_force_dr_mode(hsotg); + return ret; + } + + hsotg->stm32_id_vb_detection_enabled =3D false; + + return 0; +} + static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg *hsotg) { struct platform_device *pdev =3D to_platform_device(hsotg->dev); @@ -141,8 +230,22 @@ static int __dwc2_lowlevel_hw_enable(struct dwc2_hsotg= *hsotg) dwc2_force_dr_mode(hsotg); } =20 + ret =3D dwc2_stm32_hw_enable(hsotg); + if (ret) + goto err_dis_phy; + return 0; =20 +err_dis_phy: + if (hsotg->uphy) { + usb_phy_shutdown(hsotg->uphy); + } else if (hsotg->plat && hsotg->plat->phy_exit) { + hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); + } else { + phy_power_off(hsotg->phy); + phy_exit(hsotg->phy); + } + err_dis_clk: if (hsotg->clk) clk_disable_unprepare(hsotg->clk); @@ -178,6 +281,10 @@ static int __dwc2_lowlevel_hw_disable(struct dwc2_hsot= g *hsotg) struct platform_device *pdev =3D to_platform_device(hsotg->dev); int ret =3D 0; =20 + ret =3D dwc2_stm32_hw_disable(hsotg); + if (ret) + return ret; + if (hsotg->uphy) { usb_phy_shutdown(hsotg->uphy); } else if (hsotg->plat && hsotg->plat->phy_exit) { @@ -358,9 +465,6 @@ static void dwc2_driver_remove(struct platform_device *= dev) =20 dwc2_drd_exit(hsotg); =20 - if (hsotg->params.activate_stm_id_vb_detection) - regulator_disable(hsotg->usb33d); - if (hsotg->ll_hw_enabled) dwc2_lowlevel_hw_disable(hsotg); } @@ -554,33 +658,23 @@ static int dwc2_driver_probe(struct platform_device *= dev) goto error; =20 if (hsotg->params.activate_stm_id_vb_detection) { - u32 ggpio; - hsotg->usb33d =3D devm_regulator_get(hsotg->dev, "usb33d"); if (IS_ERR(hsotg->usb33d)) { retval =3D PTR_ERR(hsotg->usb33d); dev_err_probe(hsotg->dev, retval, "failed to request usb33d supply\n"); goto error; } - retval =3D regulator_enable(hsotg->usb33d); + retval =3D dwc2_stm32_hw_enable(hsotg); if (retval) { - dev_err_probe(hsotg->dev, retval, "failed to enable usb33d supply\n"); + dev_err_probe(hsotg->dev, retval, "dwc2_stm32_hw_enable failed\n"); goto error; } - - ggpio =3D dwc2_readl(hsotg, GGPIO); - ggpio |=3D GGPIO_STM32_OTG_GCCFG_IDEN; - ggpio |=3D GGPIO_STM32_OTG_GCCFG_VBDEN; - dwc2_writel(hsotg, ggpio, GGPIO); - - /* ID/VBUS detection startup time */ - usleep_range(5000, 7000); } =20 retval =3D dwc2_drd_init(hsotg); if (retval) { dev_err_probe(hsotg->dev, retval, "failed to initialize dual-role\n"); - goto error_init; + goto error; } =20 if (hsotg->dr_mode !=3D USB_DR_MODE_HOST) { @@ -650,9 +744,6 @@ static int dwc2_driver_probe(struct platform_device *de= v) error_drd: dwc2_drd_exit(hsotg); =20 -error_init: - if (hsotg->params.activate_stm_id_vb_detection) - regulator_disable(hsotg->usb33d); error: if (hsotg->ll_hw_enabled) dwc2_lowlevel_hw_disable(hsotg); @@ -677,37 +768,6 @@ static int __maybe_unused dwc2_suspend(struct device *= dev) =20 dwc2_drd_suspend(dwc2); =20 - if (dwc2->params.activate_stm_id_vb_detection) { - unsigned long flags; - u32 ggpio, gotgctl; - - /* - * Need to force the mode to the current mode to avoid Mode - * Mismatch Interrupt when ID detection will be disabled. - */ - dwc2_force_mode(dwc2, !is_device_mode); - - spin_lock_irqsave(&dwc2->lock, flags); - gotgctl =3D dwc2_readl(dwc2, GOTGCTL); - /* bypass debounce filter, enable overrides */ - gotgctl |=3D GOTGCTL_DBNCE_FLTR_BYPASS; - gotgctl |=3D GOTGCTL_BVALOEN | GOTGCTL_AVALOEN; - /* Force A / B session if needed */ - if (gotgctl & GOTGCTL_ASESVLD) - gotgctl |=3D GOTGCTL_AVALOVAL; - if (gotgctl & GOTGCTL_BSESVLD) - gotgctl |=3D GOTGCTL_BVALOVAL; - dwc2_writel(dwc2, gotgctl, GOTGCTL); - spin_unlock_irqrestore(&dwc2->lock, flags); - - ggpio =3D dwc2_readl(dwc2, GGPIO); - ggpio &=3D ~GGPIO_STM32_OTG_GCCFG_IDEN; - ggpio &=3D ~GGPIO_STM32_OTG_GCCFG_VBDEN; - dwc2_writel(dwc2, ggpio, GGPIO); - - regulator_disable(dwc2->usb33d); - } - spin_lock_irqsave(&dwc2->lock, flags); gr =3D &dwc2->gr_backup; if (!gr->valid) { @@ -765,31 +825,6 @@ static int __maybe_unused dwc2_resume(struct device *d= ev) } dwc2->phy_off_for_suspend =3D false; =20 - if (dwc2->params.activate_stm_id_vb_detection) { - unsigned long flags; - u32 ggpio, gotgctl; - - ret =3D regulator_enable(dwc2->usb33d); - if (ret) - return ret; - - ggpio =3D dwc2_readl(dwc2, GGPIO); - ggpio |=3D GGPIO_STM32_OTG_GCCFG_IDEN; - ggpio |=3D GGPIO_STM32_OTG_GCCFG_VBDEN; - dwc2_writel(dwc2, ggpio, GGPIO); - - /* ID/VBUS detection startup time */ - usleep_range(5000, 7000); - - spin_lock_irqsave(&dwc2->lock, flags); - gotgctl =3D dwc2_readl(dwc2, GOTGCTL); - gotgctl &=3D ~GOTGCTL_DBNCE_FLTR_BYPASS; - gotgctl &=3D ~(GOTGCTL_BVALOEN | GOTGCTL_AVALOEN | - GOTGCTL_BVALOVAL | GOTGCTL_AVALOVAL); - dwc2_writel(dwc2, gotgctl, GOTGCTL); - spin_unlock_irqrestore(&dwc2->lock, flags); - } - if (dwc2->dr_mode !=3D USB_DR_MODE_PERIPHERAL) { if (!dwc2->role_sw) /* Need to restore FORCEDEVMODE/FORCEHOSTMODE */ --=20 2.43.0 From nobody Wed Nov 25 17:40:05 2026 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.70.16 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795624379; b=nPoNS1Cu0H3bcLuYx3/OVbBVHvmi/Pyrn5HNneA0YT9rh/RefbnlkKylpPKPePtfqOXN M21xlW9mSzFV2+KDhhI7BCU6ThNPQt9iAq6UM4ih7Y0Pku9aF66AfLfTdoWT7Xle/DeKj HgghyZiHGrqvViY1R2zKT8dZpOHJZyTuhoagI3E7v+VBU38mB0mwbweWF1ywGpAZ/W1SW FgahmCbvuJMU920wZgKrwYKnpQKcaZbYIPbIuvRsGE7fctYZlTSeU0vsRbxqW4BtI0pRK N4c6M48sqS74IfP6zGTK0eDLgU8+qQtWGztqarNP5g3gikNo/+tdI3J2OnrIzVjwnNg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624379; h=DMARC-Filter:DKIM-Signature:Received:Received: X-MS-Exchange-Authentication-Results:Received-SPF:Received:Received: Received:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-ID:References:In-Reply-To:To:CC: X-Mailer:X-Originating-IP:X-ClientProxiedBy:X-EOPAttributedMessage: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-Id: X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=NFLX4rRbcAiEZGMbKsjxTtjQvEFW3sSPQNu2+MARLW8=; b=m1pNPy5ADWheQEPcokRNATnA0JmBDblAzZw4/e8ebGE5CF3EdHsxH+Sg/AhRXj2qb/ie Ex/aaHgngVyKwgrAfiqsWDxylgijatwf1ar5SoG5Y96RZh02AguMziYSb5XMZHDYeMgcF bptFkZ3Dkt3HalhCjqw82PxoZ0cCjRU1G5FBergRDJ/aqhfF2hiAlBhSx7kWIZ36HhYxN B8VykbrbSY6SrxkwKQTtsFBol44Z5IMrFVbjgWhiit93FYXEpzwVwcQcbzoUSajQdsDOm 0tSkzdprr/RuPcPFsVC6QvHbdkAo8MGaBw4QQK6bHtblMV7Q2KmjsSeAePFbOoYAJpA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=foss.st.com; spf=pass smtp.mailfrom=foss.st.com; dkim=pass header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=mgdmi9v3; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.70.16 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011016.outbound.protection.outlook.com [52.101.70.16]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA94E606A6B6; Wed, 25 Nov 2026 16:32:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA94E606A6B6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foss.st.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector2 header.b=mgdmi9v3 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dAJSBrE5Cky5FfXjUayWTbIKkmOV4hO+4gHO/Qtj2p+C2vWTwrs1hyH6wY4r69UuoohRmzLjW9x7zcEa55dvRNrNFKyvCm7Tl1h5IiVbSYlcctnNBqvUpz6SHJtcEprtnu7zb56hVO4h2xUBa65El8CamkdGnRLYyiiY0zkzO9BO7DqnrNOG7kZ4jwDIGwXGJTVQoXS61SmVnZxqmSP2Nbt3+WGjkQP8VNKRMqBeIoJZJ8cRfJNwJ2ZN1OzP6+nXRsQiIsm06SY5ZGRTROB6GLEbWYmTI04CcUe8hLzGfrPS560xa8dip4P5l42kLftvg00ceAKodox0ACao8vUAvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NFLX4rRbcAiEZGMbKsjxTtjQvEFW3sSPQNu2+MARLW8=; b=agyD61EyOlUeEI8bcBV2zEn8AciWEBTkivedDfjgkkqYfnU+qgyJxKNDgI2SQJqaDe5Iem1w2h1M+ixWkohsoyKx1EPAuPlCrGQspCHboPBWlWSD4tCvHpcTEr70oGHDuUTDK/JLE0l3tpPnSLWRIqMsMix0cpzgVjtVKegRt2us1/JMgVTK+GMg/9aZJQK0yPsPwy5Lu5mhHmfk0lKcLlsY/g9bHZoPeHyIfwO0x5/VR+rAyUY5kSDco6eWG08kOdqkExZ+PFquvwOcgTmypsTM9Zdri/kKxR3/euQVabfnXFX0gTP9iiQ6FpDcqy2S0VXwGE33VIFx9gAuiqU6Vw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=fail (sender ip is 164.130.1.59) smtp.rcpttodomain=st-md-mailman.stormreply.com smtp.mailfrom=foss.st.com; dmarc=fail (p=none sp=none pct=100) action=none header.from=foss.st.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NFLX4rRbcAiEZGMbKsjxTtjQvEFW3sSPQNu2+MARLW8=; b=mgdmi9v3pxar8Dh63uATSGj8cdvoxC2Wre4bGGiZ6eNKr61cyalcE8JJSEeApBlq770z7Zai4uYcjRpilLUOs0T46vALaAwwB1ow8Rv7unvs8+G2rD33HM+RtQVb08IPP3VjxCG2DqV7LlbQYvjKx+uCGdHog1MVaknxy845RE5EsQ3mcMRQqsKr67S1tS2hJ46DdHFxAJvoPWg2kN8bMQ5xpxdIArgAD7Qdgu4Vt684xwkAH9DIUiUd0qsqWiqKTi+FfbqnvvmTDiryB88syIwSNiqgnV19F5Mcf26eHC3DkQCcbQgmu5pqgufqMC078PoA2DCy8JfXc/AXoOGvbw== Received: from GV2PEPF0004812D.SWEP280.PROD.OUTLOOK.COM (2603:10a6:158:400::1fa) by GV2PR10MB9873.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:340::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3; Wed, 25 Nov 2026 16:32:52 +0000 Received: from WA1PEPF00009B3A.eurprd05.prod.outlook.com (2603:10a6:1d8::118) by GV2PEPF0004812D.outlook.office365.com (2603:10a6:158:400::1fa) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.615.10 via Frontend Transport; Wed, 25 Nov 2026 16:32:52 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=fail (sender IP is 164.130.1.59) smtp.mailfrom=foss.st.com; dkim=none (message not signed) header.d=none;dmarc=fail action=none header.from=foss.st.com; Received-SPF: Fail (protection.outlook.com: domain of foss.st.com does not designate 164.130.1.59 as permitted sender) receiver=protection.outlook.com; client-ip=164.130.1.59; helo=smtpO365.st.com; Received: from smtpO365.st.com (164.130.1.59) by WA1PEPF00009B3A.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.3 via Frontend Transport; Wed, 25 Nov 2026 16:32:52 +0000 Received: from STKDAG1NODE2.st.com (10.75.128.133) by smtpo365.st.com (10.250.44.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Wed, 25 Nov 2026 17:33:40 +0100 Received: from localhost (10.48.86.251) by STKDAG1NODE2.st.com (10.75.128.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.46; Wed, 25 Nov 2026 17:32:50 +0100 From: Fabrice Gasnier Date: Wed, 25 Nov 2026 17:32:12 +0100 Subject: [PATCH v6 11/11] usb: dwc2: drop redundant ll_hw_enabled checks in suspend/resume X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20261125-dwc2-low-power-fixes-stm32-v6-11-d5df33b93eaf@foss.st.com> References: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> In-Reply-To: <20261125-dwc2-low-power-fixes-stm32-v6-0-d5df33b93eaf@foss.st.com> To: Thinh Nguyen , Greg Kroah-Hartman , Douglas Anderson , Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Fabrice Gasnier , Jisheng Zhang , Felipe Balbi CC: , , X-Mailer: b4 0.16.0 X-ClientProxiedBy: STKCAS1NODE1.st.com (10.75.128.134) To STKDAG1NODE2.st.com (10.75.128.133) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: WA1PEPF00009B3A:EE_|GV2PR10MB9873:EE_ X-MS-Office365-Filtering-Correlation-Id: 3225d8af-93be-4580-61a3-08df4b11c09d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|7416014|376014|23010399003|1800799024|36860700016|18002099003|6133799003|22082099003|56012099006|261021123027099003|11063799006|261102123227099003|261022075727099003|261009223027099003|261021121427099003|10067099003; X-Microsoft-Antispam-Message-Info: Btg+7p8/ssmBMBvjJ61eA+2oDQp8GP6H5xTBGLN2Lf6ebvyzGnAxKfZDNXKoikpm78Rm+0/HBNpAbxZT+ZHg5yRaM1aj8xDI2xny5aYDvl0IPG67oWf1RWKxhxmbmKQH1Lo0G6tmTI0H7DduKXFCJKkJFQZemZbUEgGhLAJaBmp1yTCB0YXO7/+mnUgHoanHgMJLyqDZB5gzVABEQV4T8dCZpEQnR/a8Cc3+dx4k17X7rilSJU8ZkI1gVpUkXNY/tvF5wkEOfK8SskrXmtuIdLHtbLj92mvW82A5ePRUU0IA3ZvEv6AjQoOUZk8h/i7N/XyV98TioOa4Vro74mGKtTS51jDEmjEr0TEitgxK72e/WbzER31ZFoXDYhbBcVd1h4ybHHlTZC4c3p9khWL/myZKwN/bupi8GgiEA8TZauTwRX9chvBUzwBB1Qdg9MUpBK8qDYxFMdA4PmynRPgzzn8qOr1gCsram72qPn0J7zktD2attJpmKWRWIbftmtHUVzETRnOVcovfudnPSYmQkkI9aLZJyc5LomSAcPfqt4HuKP+49S9rDfLTB2OGJiGlXYPdia7fF7P6fkjYyE1t8HoT9vWrMl5/NPP/ojvKfAb4+8X+RY8OYkLv98QYFfwwR9z2zjTA1DivipmHbCcKLtUATavpWhTSNsh/4GdTuh6QSQSpxeOIrCUZgDNKoZ4E6fdXd1J66l78fvSgUFTQzQ== X-Forefront-Antispam-Report: CIP:164.130.1.59;CTRY:IT;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:smtpO365.st.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(7416014)(376014)(23010399003)(1800799024)(36860700016)(18002099003)(6133799003)(22082099003)(56012099006)(261021123027099003)(11063799006)(261102123227099003)(261022075727099003)(261009223027099003)(261021121427099003)(10067099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: q693JMu6zzsS7WCgn8c0SQBfzr0sAKGcQrsgPOqAu7FzW6AFQDSIu41YH3Rl1Kpytoi6bG2o2nc2NY49RBIn5hFR7x37iO18c6tcHBmFwoTIMw9hrnROKrZBEc2T8q+ng0bVhHp6/e376ERgmgggassYMXHCGQ7EjBoU2pKg+pmquFe4KFFXVxvtrPi0ZCFdiH3Bhu3SSf0b9n3FUegHCd8Ev+t0r9LhIAz5ii+D2lqQHYd/sbXFC60TfgyRF89DlgbT8xJarT/hm0sWuDYJmPFteZd+/XINwTJXmyOeA90fBUEh+71/96t3+7MIRf9BKQFKARkuD3mdzGz11l7ZjcW7OXBmT8w/aHktT/ReGA65XoFqCOZW4YgKXvVDYrTksW+Lu2MASXEJSSk8kY6lMstA4bgCkQ5/eeItO6f6nb1WW0c60L3nZ18VbKej2qu6 X-OriginatorOrg: foss.st.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Nov 2026 16:32:52.6848 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3225d8af-93be-4580-61a3-08df4b11c09d X-MS-Exchange-CrossTenant-Id: 75e027c9-20d5-47d5-b82f-77d7cd041e8f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=75e027c9-20d5-47d5-b82f-77d7cd041e8f;Ip=[164.130.1.59];Helo=[smtpO365.st.com] X-MS-Exchange-CrossTenant-AuthSource: WA1PEPF00009B3A.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR10MB9873 Since commit 2b94b054ac49 ("usb: dwc2: fix hang during suspend if set as peripheral"), dwc2_suspend() and dwc2_resume() return early when ll_hw_enabled is false. The later ll_hw_enabled checks in both functions are therefore always true. Remove them. No functional change. Signed-off-by: Fabrice Gasnier --- drivers/usb/dwc2/platform.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index c1f5e03c0d03..733b05191dd7 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -781,8 +781,7 @@ static int __maybe_unused dwc2_suspend(struct device *d= ev) if (ret) return ret; =20 - if (dwc2->ll_hw_enabled && - (is_device_mode || dwc2_host_can_poweroff_phy(dwc2))) { + if (is_device_mode || dwc2_host_can_poweroff_phy(dwc2)) { ret =3D __dwc2_lowlevel_hw_disable(dwc2); dwc2->phy_off_for_suspend =3D true; } @@ -818,7 +817,7 @@ static int __maybe_unused dwc2_resume(struct device *de= v) if (!dwc2->ll_hw_enabled) return 0; =20 - if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) { + if (dwc2->phy_off_for_suspend) { ret =3D __dwc2_lowlevel_hw_enable(dwc2); if (ret) return ret; --=20 2.43.0