Actually when a device calls usb_fill_deviceinfo() it gets its
'udi_bus' field set to the *host controller unit number*.

That means if your machine has two controllers with the same minor 
number (i.e. ehci0 and ohci0) you will see two buses #0. Obviously
this leads to conflicts when trying to enumerate/access devices 
using buses and addresses.

This diff corrects this by setting the usb(4) unit number as bus
number, which also increases coherency between nodes and bus numbers
such that /dev/usb1 correspond to the bus #1.

Ok?

Martin


Index: usb.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb.c,v
retrieving revision 1.80
diff -u -p -r1.80 usb.c
--- usb.c       12 May 2012 17:27:44 -0000      1.80
+++ usb.c       13 May 2012 09:44:20 -0000
@@ -152,7 +152,7 @@ usb_attach(struct device *parent, struct
 
        usbd_init();
        sc->sc_bus = aux;
-       sc->sc_bus->usbctl = sc;
+       sc->sc_bus->usbctl = self;
        sc->sc_port.power = USB_MAX_POWER;
 
        usbrev = sc->sc_bus->usbrev;
@@ -719,16 +719,17 @@ usb_explore(void *v)
 void
 usb_needs_explore(usbd_device_handle dev, int first_explore)
 {
-       DPRINTFN(3,("%s: %s\n", dev->bus->usbctl->sc_dev.dv_xname, __func__));
+       struct usb_softc *usbctl = (struct usb_softc *)dev->bus->usbctl;
 
-       if (!first_explore &&
-           (dev->bus->flags & USB_BUS_CONFIG_PENDING)) {
+       DPRINTFN(3,("%s: %s\n", usbctl->sc_dev.dv_xname, __func__));
+
+       if (!first_explore && (dev->bus->flags & USB_BUS_CONFIG_PENDING)) {
                DPRINTF(("%s: %s: not exploring before first explore\n",
-                   __func__, dev->bus->usbctl->sc_dev.dv_xname));
+                   __func__, usbctl->sc_dev.dv_xname));
                return;
        }
 
-       usb_add_task(dev, &dev->bus->usbctl->sc_explore_task);
+       usb_add_task(dev, &usbctl->sc_explore_task);
 }
 
 void
Index: usbdivar.h
===================================================================
RCS file: /cvs/src/sys/dev/usb/usbdivar.h,v
retrieving revision 1.43
diff -u -p -r1.43 usbdivar.h
--- usbdivar.h  8 Jan 2012 13:12:38 -0000       1.43
+++ usbdivar.h  13 May 2012 09:42:01 -0000
@@ -91,10 +91,6 @@ struct usbd_hub {
        struct usbd_port        *ports;
 };
 
-struct usb_softc;
-
-/*****/
-
 struct usbd_bus {
        /* Filled by HC driver */
        struct device           bdev; /* base device, host adapter */
@@ -107,7 +103,7 @@ struct usbd_bus {
        char                    dying;
        int                     flags;
 #define USB_BUS_CONFIG_PENDING 0x01
-       struct usb_softc       *usbctl;
+       struct device          *usbctl;
        struct usb_device_stats stats;
        int                     intr_context;
        u_int                   no_intrs;
Index: usb_subr.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/usb_subr.c,v
retrieving revision 1.81
diff -u -p -r1.81 usb_subr.c
--- usb_subr.c  8 Jan 2012 13:12:38 -0000       1.81
+++ usb_subr.c  13 May 2012 09:42:01 -0000
@@ -1356,7 +1356,7 @@ usbd_fill_deviceinfo(usbd_device_handle 
        struct usbd_port *p;
        int i, err, s;
 
-       di->udi_bus = dev->bus->bdev.dv_unit;
+       di->udi_bus = dev->bus->usbctl->dv_unit;
        di->udi_addr = dev->address;
        usbd_devinfo_vp(dev, di->udi_vendor, sizeof(di->udi_vendor),
            di->udi_product, sizeof(di->udi_product), usedev);

Reply via email to