public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] usb: dwc3: Fix TRB reclaim regression and clean up reclaim logic
@ 2025-06-21 19:07 Johannes Schneider
  2025-06-21 19:07 ` [PATCH 1/3] usb: dwc3: gadget: Fix TRB reclaim logic for short transfers and ZLPs Johannes Schneider
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Johannes Schneider @ 2025-06-21 19:07 UTC (permalink / raw)
  To: Thinh Nguyen, Greg Kroah-Hartman
  Cc: Pengutronix Kernel Team, linux-usb, linux-kernel,
	bsp-development.geo, Johannes Schneider

Hoi,

This patch series fixes a subtle regression introduced in the recent
scatter-gather cleanup for the DWC3 USB gadget driver, and follows up
with two clean-up patches to simplify and clarify related logic.

Background:

Commit 61440628a4ff ("usb: dwc3: gadget: Cleanup SG handling") removed
some redundant state tracking in the DWC3 gadget driver, including how
scatter-gather TRBs are reclaimed after use. However, the reclaim logic
began relying on the TRB CHN (chain) bit to determine whether TRBs
belonged to a chain — which led to missed TRB reclamation in some
cases.

This broke userspace-facing protocols like MTP (Media Transfer Protocol)
when used via FunctionFS, causing incomplete transfers due to skipped
zero-length packets (ZLPs) or improperly reclaimed short TRBs.

The "offending" chunk from 61440628a4ff:
80                 ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req,
81 -                               trb, event, status, true);
82 +                               trb, event, status,
83 +                               !!(trb->ctrl & DWC3_TRB_CTRL_CHN));

Patch 1 fixes the issue by ensuring the HWO bit is always cleared
on reclaimed TRBs, regardless of the CHN bit.

Patches 2 and 3 follow up with simplifications:
- Patch 2 removes the now-redundant `chain` argument to the reclaim function
- Patch 3 simplifies the logic in `dwc3_needs_extra_trb()` to make the conditions easier to read and maintain

All three patches have been tested on a imx8mp based hardware, with
userspace MTP (viveris/uMTP-Responder) over FunctionFS and resolve the
regression while preserving the recent cleanup work.

Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
---
Johannes Schneider (3):
      usb: dwc3: gadget: Fix TRB reclaim logic for short transfers and ZLPs
      usb: dwc3: gadget: Simplify TRB reclaim logic by removing redundant 'chain' argument
      usb: dwc3: gadget: Simplify logic in dwc3_needs_extra_trb()

 drivers/usb/dwc3/gadget.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
---
base-commit: d0c22de9995b624f563bc5004d44ac2655712a56
change-id: 20250621-dwc3-fix-gadget-mtp-3c09a6ab84c6

Best regards,
-- 
Johannes Schneider <johannes.schneider@leica-geosystems.com>


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

end of thread, other threads:[~2025-06-29  9:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-21 19:07 [PATCH 0/3] usb: dwc3: Fix TRB reclaim regression and clean up reclaim logic Johannes Schneider
2025-06-21 19:07 ` [PATCH 1/3] usb: dwc3: gadget: Fix TRB reclaim logic for short transfers and ZLPs Johannes Schneider
2025-06-23 22:41   ` Thinh Nguyen
2025-06-25  7:49   ` [PATCH v3] " SCHNEIDER Johannes
2025-06-28 15:18     ` Greg Kroah-Hartman
2025-06-28 15:19     ` Greg Kroah-Hartman
2025-06-21 19:07 ` [PATCH 2/3] usb: dwc3: gadget: Simplify TRB reclaim logic by removing redundant 'chain' argument Johannes Schneider
2025-06-23 22:43   ` Thinh Nguyen
2025-06-25  7:53     ` [PATCH v3] " SCHNEIDER Johannes
2025-06-28 15:23       ` Greg Kroah-Hartman
2025-06-29  8:45         ` SCHNEIDER Johannes
2025-06-29  9:06           ` Greg Kroah-Hartman
2025-06-21 19:07 ` [PATCH 3/3] usb: dwc3: gadget: Simplify logic in dwc3_needs_extra_trb() Johannes Schneider
2025-06-23 22:31   ` Thinh Nguyen
2025-06-24 10:47     ` SCHNEIDER Johannes

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