git: 3b795a9b0be5 - main - xhci: Enlarge total transfer number

From: ShengYi Hung <aokblast_at_FreeBSD.org>
Date: Sat, 14 Nov 2026 20:54:39 UTC
The branch main has been updated by aokblast:

URL: https://cgit.FreeBSD.org/src/commit/?id=3b795a9b0be5f8a09d290cc147a0c0407f9f36ef

commit 3b795a9b0be5f8a09d290cc147a0c0407f9f36ef
Author:     ShengYi Hung <aokblast@FreeBSD.org>
AuthorDate: 2026-11-05 23:15:58 +0000
Commit:     ShengYi Hung <aokblast@FreeBSD.org>
CommitDate: 2026-11-14 20:54:11 +0000

    xhci: Enlarge total transfer number
    
    We enlarge the total number of queued transfer. Also, to make controller
    always busy. We enqueue the xfer as much as possible to the ring in
    multiple enter code.
    
    Differential Revision: https://reviews.freebsd.org/D61246
---
 sys/dev/usb/controller/xhci.c | 29 +++++++++++++++--------------
 sys/dev/usb/controller/xhci.h |  5 ++++-
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/sys/dev/usb/controller/xhci.c b/sys/dev/usb/controller/xhci.c
index 5cc541b9f634..5807d2b1c15a 100644
--- a/sys/dev/usb/controller/xhci.c
+++ b/sys/dev/usb/controller/xhci.c
@@ -3183,7 +3183,10 @@ xhci_transfer_insert(struct usb_xfer *xfer)
 		trb_limit = 1;
 		break;
 	default:
-		/* multi buffered */
+		/*
+		 * multi buffered, less the hardcoded LINK TRB and the
+		 * chain end marker
+		 */
 		trb_limit = (XHCI_MAX_TRANSFERS - 2);
 		break;
 	}
@@ -3363,27 +3366,25 @@ xhci_device_generic_multi_enter(struct usb_endpoint *ep,
 
 	/*
 	 * Check if the current transfer is started and then pickup
-	 * the next one, if any. Else wait for next start event due to
+	 * the next ones, if any. Else wait for next start event due to
 	 * block on failure feature.
 	 */
 	if (!xfer->flags_int.bandwidth_reclaimed)
 		return;
 
-	xfer = TAILQ_FIRST(&ep->endpoint_q[stream_id].head);
-	if (xfer == NULL) {
-		/*
-		 * In case of enter we have to consider that the
-		 * transfer is queued by the USB core after the enter
-		 * method is called.
-		 */
-		xfer = enter_xfer;
-
-		if (xfer == NULL)
+	/*
+	 * Try to multi buffer all waiting transfers, in order.
+	 */
+	TAILQ_FOREACH(xfer, &ep->endpoint_q[stream_id].head, wait_entry) {
+		if (xfer->flags_int.bandwidth_reclaimed)
+			continue;
+		if (xhci_transfer_insert(xfer) != 0 ||
+		    !xfer->flags_int.bandwidth_reclaimed)
 			return;
 	}
 
-	/* try to multi buffer */
-	xhci_transfer_insert(xfer);
+	if (enter_xfer != NULL)
+		xhci_transfer_insert(enter_xfer);
 }
 
 static void
diff --git a/sys/dev/usb/controller/xhci.h b/sys/dev/usb/controller/xhci.h
index 6818f0e177e8..22a06a88df19 100644
--- a/sys/dev/usb/controller/xhci.h
+++ b/sys/dev/usb/controller/xhci.h
@@ -35,7 +35,7 @@
 #define	XHCI_MAX_EVENTS		232
 #define	XHCI_MAX_COMMANDS	(16 * 1)
 #define	XHCI_MAX_RSEG		1
-#define	XHCI_MAX_TRANSFERS	4
+#define	XHCI_MAX_TRANSFERS	8
 #if USB_MAX_EP_STREAMS == 8
 #define	XHCI_MAX_STREAMS	8
 #define	XHCI_MAX_STREAMS_LOG	3
@@ -355,6 +355,9 @@ struct xhci_dev_endpoint_trbs {
 	    XHCI_MAX_TRANSFERS) + XHCI_MAX_STREAMS];
 };
 
+/* The endpoint rings are addressed from a single physical page */
+CTASSERT(sizeof(struct xhci_dev_endpoint_trbs) <= 4096);
+
 #if (USB_PAGE_SIZE < 4096)
 #error "The XHCI driver needs a pagesize above or equal to 4K"
 #endif