Fwd: [PATCH] usb: xhci: dbc: advance transfer ring dequeue pointer on completion

From: matthew Boyle

Date: Wed Dec 02 2026 - 11:32:38 EST


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").

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).

Fixes: 7ee645963075 ("usb: xhci: remove legacy 'num_trbs_free' tracking")
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222348
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Matthew Boyle <mcboyle1865@xxxxxxxxx>
---
(Note: sent via Gmail web; the clean git format-patch file with
preserved tabs is also attached as
0001-usb-xhci-dbc-advance-transfer-ring-dequeue-pointer-o.patch.)

drivers/usb/host/xhci-dbgcap.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 48ee6a4f9..39a501002 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -812,6 +812,15 @@ dbc_handle_port_status(struct xhci_dbc *dbc,
union xhci_trb *event)
writel(portsc & ~DBC_PORTSC_RESET_CHANGE, &dbc->regs->portsc);
}

+static void dbc_inc_deq(struct xhci_ring *ring)
+{
+ union xhci_trb *next;
+
+ next = ++ring->dequeue;
+ if (TRB_TYPE_LINK_LE32(next->link.control))
+ ring->dequeue = ring->deq_seg->trbs;
+}
+
static void dbc_handle_xfer_event(struct xhci_dbc *dbc, union xhci_trb *event)
{
struct dbc_ep *dep;
@@ -840,6 +849,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc
*dbc, union xhci_trb *event)
}
if (r->status == -COMP_STALL_ERROR) {
dev_warn(dbc->dev, "Give back stale stalled req\n");
+ dbc_inc_deq(ring);
xhci_dbc_giveback(r, 0);
}
}
@@ -904,6 +914,7 @@ static void dbc_handle_xfer_event(struct xhci_dbc
*dbc, union xhci_trb *event)
break;
}

+ dbc_inc_deq(ring);
req->actual = req->length - remain_length;
xhci_dbc_giveback(req, status);
}
--
2.53.0

Very respectfully,
Matthew Boyle

Attachment: 0002-usb-xhci-dbc-increase-request-queue-depth-and-write-.patch
Description: Binary data

Attachment: 0001-usb-xhci-dbc-advance-transfer-ring-dequeue-pointer-o.patch
Description: Binary data