Linux USB
 help / color / mirror / Atom feed
* [PATCH 0/2] usb: dwc3: recover USB3 link after controller power loss
@ 2026-11-06 11:19 Xu Yang
  2026-11-06 11:19 ` [PATCH 1/2] usb: dwc3: wait for the port to leave RxDetect before xHCI reset Xu Yang
  2026-11-06 11:19 ` [PATCH 2/2] usb: dwc3: imx8mp: set needs_full_reinit as true Xu Yang
  0 siblings, 2 replies; 5+ messages in thread
From: Xu Yang @ 2026-11-06 11:19 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: Frank.Li, s.hauer, kernel, festevam, linux-usb, imx,
	linux-arm-kernel, linux-kernel, jun.li

From: Xu Yang <xu.yang_2@nxp.com>

This series fixes a USB3 link recovery failure observed on an i.MX SoC
when the DWC3 host controller loses power during system suspend.

After power is restored, the USB3 port starts in the Disconnected
(RxDetect) state instead of retaining its previous Enabled (U3) state.
Testing on the i.MX SoC shows that the port takes about 2 ms after host
mode is restored to leave RxDetect and enter Polling.

If xHCI is reset while the port is still in RxDetect, the port does not
issue a Warm Reset. Since the USB3 device may still be in U3, the
subsequent LFPS.Polling attempts time out and the controller eventually
reports the device as disconnected.

The first patch adds a DWC3 xHCI resume quirk that waits for the port to
leave RxDetect before xHCI is reset. The second patch enables this quirk
for the affected i.MX8MP platform by setting needs_full_reinit.

With this delay, xHCI is reset after the port can enter Polling, allowing
a Warm Reset to be issued and the USB3 link to recover normally.

Xu Yang (2):
  usb: dwc3: wait for the port to leave RxDetect before xHCI reset
  usb: dwc3: imx8mp: set needs_full_reinit as true

 drivers/usb/dwc3/dwc3-imx8mp.c |  1 +
 drivers/usb/dwc3/host.c        | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] usb: dwc3: wait for the port to leave RxDetect before xHCI reset
  2026-11-06 11:19 [PATCH 0/2] usb: dwc3: recover USB3 link after controller power loss Xu Yang
@ 2026-11-06 11:19 ` Xu Yang
  2026-11-06 11:36   ` sashiko-bot
  2026-11-06 11:19 ` [PATCH 2/2] usb: dwc3: imx8mp: set needs_full_reinit as true Xu Yang
  1 sibling, 1 reply; 5+ messages in thread
From: Xu Yang @ 2026-11-06 11:19 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: Frank.Li, s.hauer, kernel, festevam, linux-usb, imx,
	linux-arm-kernel, linux-kernel, jun.li

From: Xu Yang <xu.yang_2@nxp.com>

When the host controller loses power during system suspend, the port
state is not retained. After power is restored, the port starts in the
Disconnected (RxDetect) state instead of its previous Enabled (U3)
state.

After the controller is switched back to host mode, testing on an i.MX8/9
SoC shows that it takes about 2 ms for the port to leave RxDetect and
enter Polling. If xHCI is reset while the port is still in RxDetect, the
port does not issue a Warm Reset.

This prevents the link from recovering because the USB3 device may
still be in U3. Once the port enters Polling, it sends LFPS.Polling, but
the device does not respond as expected. After three Polling attempts,
each taking about 360 ms (tPollingLFPSTimeout), the controller reports
the device as disconnected.

If xHCI is reset after the port has entered Polling, the port issues a
Warm Reset and the link recovers quickly after the device responds.

Add a 2 ms delay through the xHCI resume quirk before resetting xHCI.
This allows the port to leave RxDetect so that a Warm Reset can be
issued, avoiding an unnecessary device disconnect during system
resume.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/dwc3/host.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index c5674161b2b0..465c170df12c 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -78,8 +78,29 @@ static void dwc3_xhci_plat_start(struct usb_hcd *hcd)
 	dwc3_enable_susphy(dwc, true);
 }
 
+static int dwc3_xhci_resume_quirk(struct usb_hcd *hcd)
+{
+	struct platform_device *pdev;
+	struct dwc3 *dwc;
+
+	pdev = to_platform_device(hcd->self.controller);
+	dwc = dev_get_drvdata(pdev->dev.parent);
+
+	if (dwc->needs_full_reinit) {
+		/*
+		 * The port needs some time to leave RxDetect after host mode
+		 * is restored. Delay the xHCI reset until the port can enter
+		 * Polling, allowing a Warm Reset to recover the USB3 link.
+		 */
+		usleep_range(2000, 2500);
+	}
+
+	return 0;
+}
+
 static const struct xhci_plat_priv dwc3_xhci_plat_quirk = {
 	.plat_start = dwc3_xhci_plat_start,
+	.resume_quirk = dwc3_xhci_resume_quirk,
 };
 
 static void dwc3_host_fill_xhci_irq_res(struct dwc3 *dwc,
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] usb: dwc3: imx8mp: set needs_full_reinit as true
  2026-11-06 11:19 [PATCH 0/2] usb: dwc3: recover USB3 link after controller power loss Xu Yang
  2026-11-06 11:19 ` [PATCH 1/2] usb: dwc3: wait for the port to leave RxDetect before xHCI reset Xu Yang
@ 2026-11-06 11:19 ` Xu Yang
  2026-11-06 11:44   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Xu Yang @ 2026-11-06 11:19 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: Frank.Li, s.hauer, kernel, festevam, linux-usb, imx,
	linux-arm-kernel, linux-kernel, jun.li

From: Xu Yang <xu.yang_2@nxp.com>

On i.MX8MP Soc, the USB3 Controller power will not be maintained in system
suspened state. Setting dwc3->needs_full_reinit as true to indicate the
controller should be re-initialized after system PM operations.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/dwc3/dwc3-imx8mp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/dwc3/dwc3-imx8mp.c b/drivers/usb/dwc3/dwc3-imx8mp.c
index ee92a5efaa6e..78cb79fefba2 100644
--- a/drivers/usb/dwc3/dwc3-imx8mp.c
+++ b/drivers/usb/dwc3/dwc3-imx8mp.c
@@ -267,6 +267,7 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev)
 	}
 
 	dwc3->glue_ops = &dwc3_imx_glue_ops;
+	dwc3->needs_full_reinit = true;
 
 	if (dwc3->dr_mode == USB_DR_MODE_HOST)
 		pm_runtime_dont_use_autosuspend(dwc3->dev);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] usb: dwc3: wait for the port to leave RxDetect before xHCI reset
  2026-11-06 11:19 ` [PATCH 1/2] usb: dwc3: wait for the port to leave RxDetect before xHCI reset Xu Yang
@ 2026-11-06 11:36   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-06 11:36 UTC (permalink / raw)
  To: Xu Yang; +Cc: linux-usb

> From: Xu Yang <xu.yang_2@nxp.com>
> 
> When the host controller loses power during system suspend, the port
> state is not retained. After power is restored, the port starts in the
> Disconnected (RxDetect) state instead of its previous Enabled (U3)
> state.
> 
> After the controller is switched back to host mode, testing on an i.MX8/9
> SoC shows that it takes about 2 ms for the port to leave RxDetect and
> enter Polling. If xHCI is reset while the port is still in RxDetect, the
> port does not issue a Warm Reset.
> 
> This prevents the link from recovering because the USB3 device may
> still be in U3. Once the port enters Polling, it sends LFPS.Polling, but
> the device does not respond as expected. After three Polling attempts,
> each taking about 360 ms (tPollingLFPSTimeout), the controller reports
> the device as disconnected.
> 
> If xHCI is reset after the port has entered Polling, the port issues a
> Warm Reset and the link recovers quickly after the device responds.
> 
> Add a 2 ms delay through the xHCI resume quirk before resetting xHCI.
> This allows the port to leave RxDetect so that a Warm Reset can be
> issued, avoiding an unnecessary device disconnect during system
> resume.
> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261106111943.2868733-1-xu.yang_2@oss.nxp.com?part=1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] usb: dwc3: imx8mp: set needs_full_reinit as true
  2026-11-06 11:19 ` [PATCH 2/2] usb: dwc3: imx8mp: set needs_full_reinit as true Xu Yang
@ 2026-11-06 11:44   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-06 11:44 UTC (permalink / raw)
  To: Xu Yang; +Cc: linux-usb, imx, Frank.Li

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: dwc3: imx8mp: bitfield race on needs_full_reinit in
  dwc3_imx8mp_probe()
--

commit f35ce9daa116e0df2a34cb6ec0a405a630719820
Author: Xu Yang <xu.yang_2@nxp.com>

usb: dwc3: imx8mp: set needs_full_reinit as true

This commit sets dwc3->needs_full_reinit in dwc3_imx8mp_probe() so that the
USB3 controller is re-initialized after system suspend on i.MX8MP.

> diff --git a/drivers/usb/dwc3/dwc3-imx8mp.c b/drivers/usb/dwc3/dwc3-imx8mp.c
> index ee92a5efaa6e8..78cb79fefba2c 100644
> --- a/drivers/usb/dwc3/dwc3-imx8mp.c
> +++ b/drivers/usb/dwc3/dwc3-imx8mp.c
> @@ -267,6 +267,7 @@ static int dwc3_imx8mp_probe(struct platform_device *pdev)
>  	}
>  
>  	dwc3->glue_ops = &dwc3_imx_glue_ops;
> +	dwc3->needs_full_reinit = true;

[Severity: Medium]
Can setting dwc3->needs_full_reinit without holding dwc3->lock clobber
adjacent bitfields in struct dwc3?

needs_full_reinit is a 1-bit bitfield sharing a storage word with runtime
gadget flags:

drivers/usb/dwc3/core.h:struct dwc3 {
    ...
	unsigned		connected:1;
	unsigned		softconnect:1;
    ...
	unsigned		pending_events:1;
	unsigned		do_fifo_resize:1;
	unsigned		pullups_connected:1;
	unsigned		setup_packet_pending:1;
	unsigned		three_stage_setup:1;
    ...
	unsigned		needs_full_reinit:1;
};

Earlier in dwc3_imx8mp_probe(), of_platform_populate() synchronously runs
dwc3_probe() -> dwc3_core_probe() -> dwc3_core_init_mode().  In peripheral
mode, usb_add_gadget() registers the UDC, allowing a gadget driver to bind
and start the controller before of_platform_populate() returns:

CPU0                              CPU1
dwc3_imx8mp_probe()
  of_platform_populate()
    ...
      usb_add_gadget()
                                  gadget_bind_driver()
                                    ...
                                      dwc3_gadget_pullup()
                                        spin_lock_irqsave(&dwc->lock)
  /* RMW loads bitfield word */
                                        dwc3_gadget_soft_connect()
                                          dwc->pullups_connected = true;
                                        spin_unlock_irqrestore(&dwc->lock)
  dwc3->needs_full_reinit = true;
  /* RMW store overwrites pullups_connected */

Overwriting pullups_connected or adjacent EP0 and event flags can corrupt
EP0 state or cause dwc3_gadget_soft_disconnect() to see pullups_connected
as zero and skip halting the controller before suspend.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261106111943.2868733-1-xu.yang_2@oss.nxp.com?part=2

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-06 11:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 11:19 [PATCH 0/2] usb: dwc3: recover USB3 link after controller power loss Xu Yang
2026-11-06 11:19 ` [PATCH 1/2] usb: dwc3: wait for the port to leave RxDetect before xHCI reset Xu Yang
2026-11-06 11:36   ` sashiko-bot
2026-11-06 11:19 ` [PATCH 2/2] usb: dwc3: imx8mp: set needs_full_reinit as true Xu Yang
2026-11-06 11:44   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox