Re: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion
From: Mathias Nyman
Date: Thu Dec 03 2026 - 07:32:17 EST
On 12/3/26 13:05, Michal Pecio wrote:
On Thu, 3 Dec 2026 12:48:55 +0200, Mathias Nyman wrote:
On 12/2/26 18:32, matthew Boyle wrote:
Good Morning,
Commit 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free'
tracking") removed ring->num_trbs_free and switched
xhci_dbc_queue_bulk_tx() to xhci_num_trbs_free(ring), which computes
free space from ring->enqueue and ring->dequeue.
However, DbC transfer rings never updated ring->dequeue on transfer
completion; previously only ring->num_trbs_free was incremented in
dbc_handle_xfer_event(). As a result, ring->dequeue remains stuck at
the start of the single-segment ring while ring->enqueue advances.
After exactly 254 TRBs (254 * 1024 B = 260,096 B on a 256-TRB segment
with one link TRB and the xhci_num_trbs_free(ring) <= num_trbs guard),
xhci_num_trbs_free() drops to 1 and every subsequent bulk transfer
fails permanently with -EBUSY ("failed to queue trbs").
nice catch, thanks
Add a dbc_inc_deq() helper mirroring xhci_dbc_queue_trb()'s link-TRB
wraparound and call it in dbc_handle_xfer_event() before giving back
completed and stale stalled requests (while dbc->lock is still held,
before completion callbacks can re-queue new TRBs).
The transfer event contains the dequeue TRB DMA address, how about setting
the ring->dequeue directly based on it instead.
Does this work for you:
diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 48ee6a4f9e1c..a9c011194cd8 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -835,6 +835,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event)
/* Match the pending request: */
list_for_each_entry(r, &dep->list_pending, list_pending) {
if (r->trb_dma == event->trans_event.buffer) {
+ ring->dequeue = xhci_dma_to_trb(ring->deq_seg, r->trb_dma, NULL);
req = r;
break;
}
Not familiar with DBC, but I suspect you actually want:
ring->dequeue = xhci_dma_to_trb(ring->deq_seg, r->trb_dma, &ring->deq_seg);
Yes, that would be more future proof.
Right now it doesn't matter as dbc uses one segment rings
Checking return value =! NULL before assigning ring->dequeue would also be good
Thanks
Mathias