How to find kernel module for a given device

kernel-modulesusb

I am trying to troubleshoot a problem: usb mouse doesn't work on a freshly installed linux.

I suspect the problem is that there is no suitable kernel module/driver for my usb hardware. Indeed:

$ lspci -knn
...
01:00.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Device [1022:43b9] (rev 02)
        Subsystem: ASMedia Technology Inc. Device [1b21:1142]
01:00.1 SATA controller [0106]: Advanced Micro Devices, Inc. [AMD] Device [1022:43b5] (rev 02)
        Subsystem: ASMedia Technology Inc. Device [1b21:1062]
        Kernel driver in use: ahci
...

As you can see no kernel driver is reported for USB controller device (I suppose it should be reported in a way similar to driver reported for SATA controller)

So, I need to rebuild kernel with a module which would be suitable for my device. But how can I find out what module should I build? I have information which identifies my device: it's vendor id and hardware id ([1b21:43b9]). How to find out corresponding kernel module name given this information?

Best Answer

PCI ID 1022:43b9 is an AMD X370 Series Chipset USB 3.1 xHCI Controller. The PCI subsystem ID 1b21:1142 would suggest it might actually be an ASMedia ASM1042A USB 3 controller, possibly integrated into the AMD chipset.

For most USB 3.x controller chips, the appropriate driver module is xhci_pci which depends on module xhci_hcd. Both these modules are part of the standard Linux kernel, so they should be available in all modern Linux distributions. The corresponding kernel configuration options are CONFIG_USB_XHCI_PCI and CONFIG_USB_XHCI_HCD.

Many distributions include the kernel configuration file as /boot/config-<kernel version number>. So, you could run this command:

$ grep XHCI /boot/config-$(uname -r)
CONFIG_USB_XHCI_HCD=m
CONFIG_USB_XHCI_PCI=m
# CONFIG_USB_XHCI_PLATFORM is not set

Here, both xhci_hcd and xhci_pci are configured to be available as modules. If the lines would say ...=y instead, the USB 3 support would be compiled into the main kernel.

PCI ID 1022:43b5, subsystem ID 1b21:1062 is an AHCI SATA (or eSATA) controller, which is already covered by module ahci.

You can look up PCI IDs in PCI ID Repository.

If a driver has been specified by vendor/product IDs, you could use /sbin/modprobe -c | grep '<vendor ID>.*<product ID>'. If you get back a line like this, you've found a match:

alias pci:v0000<vendor ID>:d0000<product ID>sv... <module name>

This information comes from /lib/modules/modules.alias[.bin], which is generated by the depmod command from the device support information embedded in the kernel modules themselves (defined in the source code with a MODULE_DEVICE_TABLE macro). You can also use modinfo <module name> | grep alias to view the hardware support claimed by a particular module.

However, not all modules are specified by vendor/product IDs. Some drivers will cover an entire class of devices; for example, the xhci_pci module claims support of PCI base class 0x0C, subclass 0x03, interface 0x30... which maps to "Serial bus controller", "USB controller" and "XHCI" respectively. This is expressed as

alias:          pci:v*d*sv*sd*bc0Csc03i30*

Note that you should not normally need to do any of these lookups manually unless you've blacklisted some modules or the auto-detection fails for some reason. For example, when the Linux kernel detects the original poster's USB 3 controller, it will cause (the equivalent of) the following command to be executed:

modprobe pci:v00001022d000043b9sv1b21sd1142bc0Csc03i30

which contains all the hardware vendor/device/class/subclass/interface IDs available for the device. If one of the wildcarded aliases on record in modprobe configuration matches this string, the respective module will get loaded automatically.

For USB devices (and indeed for any autoprobeable buses), there is a similar system of module aliases, and a USB ID repository.

If you don't have the appropriate module compiled on your system, your best bet is to use the PCI ID repository to identify the device or the chip used within it. Sometimes the repository entry identifies the Linux kernel module that will provide support for it. If that information is not present, you may need to google using the device/chip model; this will usually allow you to find any alternative/experimental driver modules that have not (yet?) been included in the standard kernel.

Related Question