3

Having had a bit of an internet-scour, I think the answer may be "No", but:

Can I find the USB port description (as per dmidecode) corresponding to the USB device from sysfs?

We can enumerate all USB hubs and devices by listing /sys/bus/usb/devices. For example:

lrwxrwxrwx 1 root root 0 May 18 09:40 1-2 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-2
lrwxrwxrwx 1 root root 0 May 18 09:40 1-2:1.0 -> ../../../devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0
lrwxrwxrwx 1 root root 0 May 18 09:36 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-0:1.0
lrwxrwxrwx 1 root root 0 May 18 09:36 2-3 -> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-3
lrwxrwxrwx 1 root root 0 May 18 09:36 2-3:1.0 -> ../../../devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3:1.0
lrwxrwxrwx 1 root root 0 May 18 09:36 usb1 -> ../../../devices/pci0000:00/0000:00:14.0/usb1
lrwxrwxrwx 1 root root 0 May 18 09:36 usb2 -> ../../../devices/pci0000:00/0000:00:14.0/usb2

…And we can list all built-in USB ports on the machine by doing dmidecode -t connector. For example it shows (among many other connectors):

Handle 0x000D, DMI type 8, 9 bytes
Port Connector Information
    Internal Reference Designator: USB REAR
    Internal Connector Type: Proprietary
    External Reference Designator: Rear: USB-1
    External Connector Type: Access Bus (USB)
    Port Type: USB

[...]

Handle 0x0014, DMI type 8, 9 bytes
Port Connector Information
    Internal Reference Designator: USB 3.0 REAR
    Internal Connector Type: Proprietary
    External Reference Designator: Rear: USB 1
    External Connector Type: Access Bus (USB)
    Port Type: USB

(On my machine, it looks like each USB port appears twice, in the guise of "USB" and "USB 3.0".)

I’d love to be able show the connector description ("Rear: USB 1") corresponding to a particular USB device— but there does not seem to be a reliable way to relate /sys/bus/USB devices to dmidecode connectors— Is there?

(In my particular case, it would be tempting to relate "usb1" from the bus to "USB 1" from Dmidecode… but I’m willing to bet that that’s a coincidence.)

Edit: Or if not dmidecode, some other tool which could provide an external description of the port.

andrewf
  • 133
  • 5
  • The `lsusb -t` command will list your USB connections for each hub - you might be able to try plugging various devices in, to see how things change. Some of your hubs might not be connected to anything! – Jeremy Boden Jun 05 '21 at 17:04
  • @JeremyBoden, Thanks, but I’m trying to write a program to make the connection, so relating them for my _own particular machine_ is not so important as a general approach. – andrewf Jun 06 '21 at 21:10

1 Answers1

2

The output of dmidecode is based on SMBIOS data.

Here is apparently-latest version of the SMBIOS specification, as of this writing.

The lower half of page 70 describes the data structure for the port connector information. The only meaningful values there are the DMI structure handle (a simple 16-bit number), internal & external connector type values, and two strings describing the connector identifier on the system board and on the exterior of the chassis, respectively.

Only the handle number would be unique to a particular connector, so only it might be used as an identifier that could tie a particular USB device to a SMBIOS/DMI connector information. But it doesn't seem that there is anything on the USB hardware side that could refer to these numbers to indicate which connector belongs to which device.

Also, usb1 and usb2 in the /sys/bus/usb/devices listing don't refer to individual connectors, but different USB buses. A USB 3.x system will always have at least two buses: one bus to handle the USB 2 and older speeds, and another bus for the USB 3+ speeds. This reflects the fact that the older speeds use one set of data wires, and the newer super-fast transfer modes of USB3.x will use a different set of data wires. Each bus will usually have its own root hub, which can have a varying number of USB connectors.

So, to tie a specific DMI connector information structure to a particular USB port device, the USB hub descriptor would have to have a data field that would specify the appropriate DMI structure handle.

Alternatively, the PCI device information of the USB controller would have to include a list of DMI handles belonging to that controller, but that would only allow the identification of which set of USB ports belongs to which controller, not unique identification of a specific port.

Unfortunately, I cannot find any data field on the USB or PCI bus information that would contain such DMI handles or equivalent port descriptions. So I'm afraid the answer seems to be "no, it is not generally possible to tie the physical port identifiers to individual Linux USB bus/port objects at this time."

Some name-brand systems might have some vendor-specific bus data extensions that would in fact include this information, but as long as there is no widely-adopted standard practice that could be relied on, the general answer would remain a "no, that information is not available."

telcoM
  • 87,318
  • 3
  • 112
  • 232