From ed046adeb499cc14ac7e7c3a195cbc59089b6bf4 Mon Sep 17 00:00:00 2001 From: Justin Hammond Date: Sat, 8 Aug 2026 14:39:09 +0800 Subject: [PATCH] drivers/usbhost: Tell the host stack which controller a port belongs to. struct usbhost_roothubport_s carries the number of the controller its port belongs to, so a port can be named on a system with more than one. Nothing set it. Take the number from whoever brings the controller up rather than counting registrations, which would agree with the name the driver reports only while controllers are registered in the order they are named. Assisted-by: Claude:claude-opus-5 Signed-off-by: Justin Hammond --- drivers/usbhost/usbhost_xhci.c | 11 ++++++++++- drivers/usbhost/usbhost_xhci_pci.c | 2 +- include/nuttx/usb/xhci.h | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/usbhost/usbhost_xhci.c b/drivers/usbhost/usbhost_xhci.c index 625a074c174..db2e94934f1 100644 --- a/drivers/usbhost/usbhost_xhci.c +++ b/drivers/usbhost/usbhost_xhci.c @@ -248,6 +248,7 @@ struct usbhost_xhci_s /* xHCI parameters */ uint8_t no_ports; /* Number of USB Ports */ + uint8_t bus; /* Which controller this is */ uint8_t no_slots; /* Maximum number of Device Slots (one per USB device) */ uint8_t no_scratch; /* Number of scratch buffers */ uint8_t no_erst; /* Event Ring Segment Table size */ @@ -5830,6 +5831,7 @@ static inline int xhci_sw_initialize(FAR struct usbhost_xhci_s *priv) rhport->ep0.epno = 0; rhport->ep0.devaddr = 0; nxsem_init(&rhport->ep0.iocsem, 0, 0); + rhport->hport.bus = priv->bus; nxmutex_init(&rhport->ep0.lock); /* Initialize the public port representation */ @@ -5874,7 +5876,7 @@ static inline int xhci_sw_initialize(FAR struct usbhost_xhci_s *priv) ****************************************************************************/ FAR struct usbhost_connection_s * -xhci_initialize(FAR const char *name, uintptr_t base, +xhci_initialize(FAR const char *name, uint8_t bus, uintptr_t base, FAR const struct xhci_bus_ops_s *ops, FAR void *arg) { FAR struct usbhost_conn_xhci_s *conn = NULL; @@ -5903,6 +5905,13 @@ xhci_initialize(FAR const char *name, uintptr_t base, conn->priv = priv; priv->name = name; + + /* The bus is what the controller calls itself, so that a port reported + * through the generic host stack and a message from this driver name the + * same thing. Numbering them here instead would agree only by accident. + */ + + priv->bus = bus; priv->ops = ops; priv->arg = arg; priv->base = base; diff --git a/drivers/usbhost/usbhost_xhci_pci.c b/drivers/usbhost/usbhost_xhci_pci.c index 95b794c4c26..8c7f0819b44 100644 --- a/drivers/usbhost/usbhost_xhci_pci.c +++ b/drivers/usbhost/usbhost_xhci_pci.c @@ -213,7 +213,7 @@ static int pci_xhci_probe(FAR struct pci_device_s *dev) goto errout; } - pcix->conn = xhci_initialize("usb", base, &g_pci_xhci_ops, pcix); + pcix->conn = xhci_initialize("usb", 0, base, &g_pci_xhci_ops, pcix); if (pcix->conn == NULL) { pcierr("xhci_initialize failed\n"); diff --git a/include/nuttx/usb/xhci.h b/include/nuttx/usb/xhci.h index 1010811244b..32a6638a940 100644 --- a/include/nuttx/usb/xhci.h +++ b/include/nuttx/usb/xhci.h @@ -95,7 +95,7 @@ struct xhci_bus_ops_s ****************************************************************************/ FAR struct usbhost_connection_s * -xhci_initialize(FAR const char *name, uintptr_t base, +xhci_initialize(FAR const char *name, uint8_t bus, uintptr_t base, FAR const struct xhci_bus_ops_s *ops, FAR void *arg); /****************************************************************************