Re: [PATCH 1/3] usb: dwc2: gadget: restart descriptor DMA isochronous OUT endpoints after BNA
From: Vadim Yuzifovich
Date: Sun Nov 15 2026 - 17:03:13 EST
Please do not apply this patch. It is wrong, and I found that only now,
testing the changes for the Sashiko review. Patches 2 and 3 are not
affected; numbers for them are at the end.
The test: SG2002 (DWC_otg 4.20a), a tone played into the UAC1 gadget,
eight 200 byte requests queued, and interrupts held off for 12 ms once
to cause a BNA. With this patch the endpoint is restarted, as the
changelog says. But from then on it takes one BNA and one restart for
every packet, about 2000 interrupts a second, until the host closes the
stream. Most of the audio still arrives, so the test I did before, which
only looked at whether the stream went on, passed.
A trace of the endpoint interrupt and of the restart shows why (time in
microseconds from the start of the hold; desc0 and desc1 are the status
words of the first two descriptors as the CPU reads them):
12015 irq DOEPINT 0211 DOEPCTL 000480c8
12121 restart DOEPCTL 800480c8 DOEPINT 2201
desc0 8e2d8008 desc1 020000c8
12129 irq DOEPINT 0201 DOEPCTL 800480c8
12630 irq DOEPINT 0200 DOEPCTL 000480c8 DOEPDMA at desc1
desc0 8e2d8008 desc1 020000c8
12715 restart DOEPCTL 800480c8 DOEPINT 2201
desc0 8e2f8008 desc1 020000c8
12725 irq DOEPINT 0201 DOEPCTL 800480c8
13633 irq DOEPINT 0200 DOEPCTL 000480c8 DOEPDMA at desc1
... and so on, once a millisecond
Right after the restart descriptor 0 is already DMA done, with 192
bytes received, the frame number of the current frame and the L bit
set, while descriptor 1 is host ready and never used. A second trace
point shows descriptor 0 done even before DOEPDMA and EPENA are
written.
So, as far as I can tell from outside:
- After the BNA the core keeps the OUT packet that met it. DOEPCTL
shows EPENA clear, but the core goes on trying the descriptor at the
start of the chain and raises BNA each time. That is the repeating
BNA of the changelog. Flushing the RxFIFO, which
dwc2_gadget_handle_isoc_bna() does, does not remove the packet.
- The moment descriptor 0 is host ready, the core writes the packet to
it, without the endpoint being enabled.
dwc2_gadget_start_isoc_ddma() fills the chain front to back, so at
that moment descriptor 0 still has L set.
- After that the core is done. DOEPDMA and EPENA are written, the next
packet finds descriptor 0 used, and there is the next BNA.
What I tried:
- RxFIFO flush just before the restart, clearing DOEPINT.BNA just
before the enable, reading every descriptor back: no change.
- Global OUT NAK around the restart: GOUTNAKEFF does not come within
100 us, no change.
- Marking descriptor 0 host ready last, after DOEPDMA is written: the
chain then runs normally if the core takes descriptor 0 after EPENA
is set. If it takes it before, the chain again ends after that one
packet.
- The same, plus: if the core takes descriptor 0 before the enable,
wait for the packet to land, give the request back, build the chain
again and enable. No packet is waiting for that second chain. This
gave one BNA and one restart per hold for 34 holds of 9 to 50 ms.
Then three runs failed after 10, 19 and 9 restarts, each time on a
9 ms hold, which is the edge of the eight queued requests: the stream
stopped, and twice the host reset the port. I have not traced that
case yet.
Thinh, what does the core expect the driver to do with an isochronous
OUT endpoint after a BNA in descriptor DMA mode? In particular, is
there a way to make it drop the packet it holds, or a defined point at
which the chain may be written again? I would rather do what the core
is designed for than poll a descriptor in the interrupt handler.
The Sashiko findings on this patch (BNA handled after the chain was
restarted in the same interrupt, a BNA latched before the restart) are
real as well and are fixed in what I have, but they do not matter until
the above is solved.
Patches 2 and 3, same board, TEST UNIT READY as fast as the host can
with a 1080p60 H.264 encode running, counters added for the test:
- With the read-back of patch 3 switched off to get BNAs: 368000
commands in 120 s (3070 a second), 13103 BNAs, 12809 of them
restarted by patch 2, no port reset. The other 294 were on the bulk
OUT endpoint, came together with XferCompl and found no request
current. Two more such runs: one the same, one with a port reset
whose cause I did not capture.
- With the read-back on: 546000 commands in 180 s, no BNA, no reset.
- In about 40000 BNAs on bulk endpoints the endpoint was disabled when
the BNA was handled, and no endpoint-disabled interrupt followed. So
the timing cases Sashiko describes for patch 2 did not occur on this
core. I do not know what the core guarantees there.
- Patch 2 in that test restarted the request from req.actual, as
Sashiko suggested, not from its beginning as posted. A BNA on a later
part of a long request did not occur, so that path is still not
exercised.
I will send a v2 with the review fixes for patches 2 and 3, and with
patch 1 either done properly or left out.
Vadim