On Tue, 27 Jul 2004, Daniel Miller (IMI) wrote:

> I've got a system here with 3 NEC USB host chips on it, for 12 USB slots.  I
> need to be able to identify which slot a part was plugged into, based on USB
> data of some sort. In the past (under kernel 2.4.x and 2.6.4), there was a
> predictable, consistent mapping between USB bus/port number and the physical
> slot position.  However, under 2.6.7, that appears to be no longer true.  On
> one machine, the three host chips have been coming up as bus 7,8,6 ... on a
> second machine, they were coming up as 3,2,4 (which was the traditional
> sequence under 2.4.x).  Then I shut down the machine last night to install a
> CDROM drive (which is *not* USB), and now after booting back up, the busses
> appear to be 12,14,13 !!!
> 
> What is determining the USB bus numbers??  This is driving me nuts!!  How am
> I supposed to determine which slot a person has stuck a chip in???

The buses are numbered sequentially according to the order in which they
are discovered.  As you've seen, this order is subject to change when
devices are added or removed from the system.  It also depends on the
order your drivers are loaded.  So don't rely on the bus numbers for
identification!

Instead, use the sysfs device name for the bus controller.  For example,
on my computer I have a sysfs filesystem mounted on /sys.  The directory
for my usb1 host controller contains this:

/sys/class/usb_host/usb1:
total 0
lrwxrwxrwx    1 root     root            0 Jul  9 10:58 device -> 
../../../devices/pci0000:00/0000:00:07.2/
lrwxrwxrwx    1 root     root            0 Jul  9 10:58 driver -> 
../../../bus/pci/drivers/uhci_hcd/

The device name is 0000:00:07.2, and that name _won't_ change.  Even if 
your USB controller is on a removable card, the device name will stay the 
same so long as the card is in the same slot.

And for going the other direction, you only have to look in the
appropriate directory.  /sys/devices/pci0000:00/0000:00:07.2 contains a
subdirectory named usb1, and this tells you what bus number is being used 
for that controller.

Alan Stern



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-users

Reply via email to