Linux USB
 help / color / mirror / Atom feed
* [PATCH v2 0/2] usb: dwc2: fix fifo reinit and workaround for isoc tx packet
@ 2026-11-04 13:20 Fabrice Gasnier
  2026-11-04 13:20 ` [PATCH v2 1/2] usb: dwc2: fix fifo reinit in dwc2_hsotg_core_init_disconnected Fabrice Gasnier
  2026-11-04 13:20 ` [PATCH v2 2/2] usb: dwc2: wa for isoc packet tx fifo flush at periodic frame boundary Fabrice Gasnier
  0 siblings, 2 replies; 5+ messages in thread
From: Fabrice Gasnier @ 2026-11-04 13:20 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, linux-stm32, stable, Fabrice Gasnier

This series addresses two issues in the dwc2 driver:
- First one fixes fifo re-initialisation when using dma
- Second one is a workaround on some cores that may send long TX
packets.
As these two changes may conflict together send them in a series.

Changes in v2:
- Send the two patches in series as advised by Thinh
- Address Thinh's Review comments
- Link to v1: https://patch.msgid.link/20261014-dwc2-fix-fifo-reinit-v1-1-d918de90ee3a@foss.st.com
- Link to v1: https://patch.msgid.link/20261014-dwc2-fix-wa-isoc-v1-1-f261ce0852bd@foss.st.com

---
Fabrice Gasnier (2):
      usb: dwc2: fix fifo reinit in dwc2_hsotg_core_init_disconnected
      usb: dwc2: wa for isoc packet tx fifo flush at periodic frame boundary

 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 19 +++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261104-dwc2-fifo-fixes-v2-10f08299c0f1

Best regards,
--  
Fabrice Gasnier <fabrice.gasnier@foss.st.com>


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

* [PATCH v2 1/2] usb: dwc2: fix fifo reinit in dwc2_hsotg_core_init_disconnected
  2026-11-04 13:20 [PATCH v2 0/2] usb: dwc2: fix fifo reinit and workaround for isoc tx packet Fabrice Gasnier
@ 2026-11-04 13:20 ` Fabrice Gasnier
  2026-11-04 13:24   ` sashiko-bot
  2026-11-04 13:20 ` [PATCH v2 2/2] usb: dwc2: wa for isoc packet tx fifo flush at periodic frame boundary Fabrice Gasnier
  1 sibling, 1 reply; 5+ messages in thread
From: Fabrice Gasnier @ 2026-11-04 13:20 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, linux-stm32, stable, Fabrice Gasnier

Currently, the fifo gets re-init, with a running DMA, e.g. when
using_desc_dma():
- dwc2_hsotg_init_fifo -> Flushes the FIFO, DMA may run in parallel
- DCFG_DESCDMA_EN gets cleared (e.g. disables dma desc)
- then DCFG_DESCDMA_EN gets set back again.

So move the dwc2_hsotg_init_fifo() call after DCFG_DESCDMA_EN gets
cleared e.g. DCFG write. Then the FIFO can be flushed safely, before
DCFG_DESCDMA_EN is set back on.

A BNA interrupt may happen on EP0, before this change. When it happens
we can't recover to a working device.

Fixes: a5c18f113150 ("usb: dwc2: gadget: Enable descriptor DMA mode")
Cc: stable@vger.kernel.org
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
---
Changes in v2:
- Update Fixes tag and collect Thinh's Acked-by tag.
---
 drivers/usb/dwc2/gadget.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 6c8a9f05fff0..bdabf3c39da1 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3486,8 +3486,6 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
 
 	dwc2_phy_init(hsotg, true);
 
-	dwc2_hsotg_init_fifo(hsotg);
-
 	if (!is_usb_reset) {
 		dwc2_set_bit(hsotg, DCTL, DCTL_SFTDISCON);
 		if (hsotg->params.eusb2_disc)
@@ -3515,6 +3513,8 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
 
 	dwc2_writel(hsotg, dcfg,  DCFG);
 
+	dwc2_hsotg_init_fifo(hsotg);
+
 	/* Clear any pending OTG interrupts */
 	dwc2_writel(hsotg, 0xffffffff, GOTGINT);
 

-- 
2.43.0


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

* [PATCH v2 2/2] usb: dwc2: wa for isoc packet tx fifo flush at periodic frame boundary
  2026-11-04 13:20 [PATCH v2 0/2] usb: dwc2: fix fifo reinit and workaround for isoc tx packet Fabrice Gasnier
  2026-11-04 13:20 ` [PATCH v2 1/2] usb: dwc2: fix fifo reinit in dwc2_hsotg_core_init_disconnected Fabrice Gasnier
@ 2026-11-04 13:20 ` Fabrice Gasnier
  2026-11-04 13:23   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Fabrice Gasnier @ 2026-11-04 13:20 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, linux-stm32, stable, Fabrice Gasnier

If an isochronous packet is still being transmitted, when the end of
periodic frame interval elapses, using dma desc on dwc2 controller,
the device wrongly flushes the pending packets from the tx fifo.
This can lead to a huge packet is sent on the bus, leading to the host
finally reset the bus, and re-enumerate it.

Workaround it by tuning the periodic frame interval limit from 80% to 95%,
on the affected cores (2.70a to 4.00a). It makes the issue very unlikely
to occur.

Fixes: 540ccba08599 ("usb: dwc2: gadget: Start and complete DDMA isoc transfers")
Cc: stable@vger.kernel.org
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
---
Changes in v2:
- Thinh review comments:
- Fix a typo 'flushes'
- Use DCFG_PERFRINT() macro
- Add DWC2_HS_IOT_REV_1_00a and DWC2_FS_IOT_REV_1_00a core revisions.
- Add a Fixes tag, and Cc stable
---
 drivers/usb/dwc2/core.h   |  1 +
 drivers/usb/dwc2/gadget.c | 15 +++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 015a5fb7842d..54c040da0cae 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1108,6 +1108,7 @@ struct dwc2_hsotg {
 
 	/* DWC OTG HW Release versions */
 #define DWC2_CORE_REV_4_30a	0x4f54430a
+#define DWC2_CORE_REV_2_70a	0x4f54270a
 #define DWC2_CORE_REV_2_71a	0x4f54271a
 #define DWC2_CORE_REV_2_72a     0x4f54272a
 #define DWC2_CORE_REV_2_80a	0x4f54280a
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index bdabf3c39da1..b84cb6b2cefa 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3511,6 +3511,21 @@ void dwc2_hsotg_core_init_disconnected(struct dwc2_hsotg *hsotg,
 	if (hsotg->params.ipg_isoc_en)
 		dcfg |= DCFG_IPG_ISOC_SUPPORDED;
 
+	/*
+	 * WA for Device Flushes Ongoing ISOC IN Packet at End-of-Periodic-Frame Boundary.
+	 * Once passed the end of periodic frame, and the controller is transmitting an
+	 * ISOC IN packet, the device flushes the transmit FIFO. Tune periodic frame
+	 * interval to 95% instead of 80% to avoid it.
+	 */
+	if (using_desc_dma(hsotg) &&
+	    ((hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_70a &&
+	      hsotg->hw_params.snpsid <= DWC2_CORE_REV_4_00a) ||
+	     hsotg->hw_params.snpsid == DWC2_FS_IOT_REV_1_00a ||
+	     hsotg->hw_params.snpsid == DWC2_HS_IOT_REV_1_00a)) {
+		dcfg &= ~DCFG_PERFRINT_MASK;
+		dcfg |= DCFG_PERFRINT(DCFG_PERFRINT_LIMIT);
+	}
+
 	dwc2_writel(hsotg, dcfg,  DCFG);
 
 	dwc2_hsotg_init_fifo(hsotg);

-- 
2.43.0


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

* Re: [PATCH v2 2/2] usb: dwc2: wa for isoc packet tx fifo flush at periodic frame boundary
  2026-11-04 13:20 ` [PATCH v2 2/2] usb: dwc2: wa for isoc packet tx fifo flush at periodic frame boundary Fabrice Gasnier
@ 2026-11-04 13:23   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-04 13:23 UTC (permalink / raw)
  To: Fabrice Gasnier; +Cc: linux-usb

> If an isochronous packet is still being transmitted, when the end of
> periodic frame interval elapses, using dma desc on dwc2 controller,
> the device wrongly flushes the pending packets from the tx fifo.
> This can lead to a huge packet is sent on the bus, leading to the host
> finally reset the bus, and re-enumerate it.
> 
> Workaround it by tuning the periodic frame interval limit from 80% to 95%,
> on the affected cores (2.70a to 4.00a). It makes the issue very unlikely
> to occur.
> 
> Fixes: 540ccba08599 ("usb: dwc2: gadget: Start and complete DDMA isoc transfers")
> Cc: stable@vger.kernel.org
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-dwc2-fifo-fixes-v2-v2-0-2bb13820f662@foss.st.com?part=2


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

* Re: [PATCH v2 1/2] usb: dwc2: fix fifo reinit in dwc2_hsotg_core_init_disconnected
  2026-11-04 13:20 ` [PATCH v2 1/2] usb: dwc2: fix fifo reinit in dwc2_hsotg_core_init_disconnected Fabrice Gasnier
@ 2026-11-04 13:24   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-04 13:24 UTC (permalink / raw)
  To: Fabrice Gasnier; +Cc: linux-usb

> Currently, the fifo gets re-init, with a running DMA, e.g. when
> using_desc_dma():
> - dwc2_hsotg_init_fifo -> Flushes the FIFO, DMA may run in parallel
> - DCFG_DESCDMA_EN gets cleared (e.g. disables dma desc)
> - then DCFG_DESCDMA_EN gets set back again.
> 
> So move the dwc2_hsotg_init_fifo() call after DCFG_DESCDMA_EN gets
> cleared e.g. DCFG write. Then the FIFO can be flushed safely, before
> DCFG_DESCDMA_EN is set back on.
> 
> A BNA interrupt may happen on EP0, before this change. When it happens
> we can't recover to a working device.
> 
> Fixes: a5c18f113150 ("usb: dwc2: gadget: Enable descriptor DMA mode")
> Cc: stable@vger.kernel.org
> Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104-dwc2-fifo-fixes-v2-v2-0-2bb13820f662@foss.st.com?part=1


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

end of thread, other threads:[~2026-11-04 13:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04 13:20 [PATCH v2 0/2] usb: dwc2: fix fifo reinit and workaround for isoc tx packet Fabrice Gasnier
2026-11-04 13:20 ` [PATCH v2 1/2] usb: dwc2: fix fifo reinit in dwc2_hsotg_core_init_disconnected Fabrice Gasnier
2026-11-04 13:24   ` sashiko-bot
2026-11-04 13:20 ` [PATCH v2 2/2] usb: dwc2: wa for isoc packet tx fifo flush at periodic frame boundary Fabrice Gasnier
2026-11-04 13:23   ` sashiko-bot

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