nl80211: add ability to describe USB devices
authorJo-Philipp Wich <jo@mein.io>
Thu, 15 Dec 2022 19:45:20 +0000 (20:45 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 15 Dec 2022 20:14:57 +0000 (21:14 +0100)
Treat USB vendor and product IDs like PCI subsystem vendor and device IDs
respectively to allow describing USB devices as `0000 0000 $vid $pid` in
the hardware database.

As a side effect, this also skips potentially expensive MTD lookups on
embedded devices with plugged in USB radios.

With a 5.15 kernel, such MTD lookups even spam dmesg with:

    mtdblock: MTD device 'factory' is NAND, please consider using UBI block devices instead.

This fix speeds up iwinfo considerably on affected systems:

Before:
sys     0m 3.56s

After:
sys     0m 0.09s

Suggested-by: Andre Heider <a.heider@gmail.com>
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
iwinfo_nl80211.c

index c1e53d7a3514914824e2e2d8a805bd7521270abe..50b1ab4085d9b86e66b3066180fa5b96488e03ef 100644 (file)
@@ -3468,7 +3468,9 @@ static int nl80211_get_hardware_id(const char *ifname, char *buf)
                { "vendor", &id->vendor_id },
                { "device", &id->device_id },
                { "subsystem_vendor", &id->subsystem_vendor_id },
-               { "subsystem_device", &id->subsystem_device_id }
+               { "subsystem_device", &id->subsystem_device_id },
+               { "../idVendor", &id->subsystem_vendor_id },
+               { "../idProduct", &id->subsystem_device_id }
        };
 
        memset(id, 0, sizeof(*id));
@@ -3487,12 +3489,14 @@ static int nl80211_get_hardware_id(const char *ifname, char *buf)
        }
 
        /* Failed to obtain hardware IDs, try FDT */
-       if (id->vendor_id == 0 || id->device_id == 0)
+       if (id->vendor_id == 0 && id->device_id == 0 &&
+           id->subsystem_vendor_id == 0 && id->subsystem_device_id == 0)
                if (!nl80211_hardware_id_from_fdt(id, ifname))
                        return 0;
 
        /* Failed to obtain hardware IDs, search board config */
-       if (id->vendor_id == 0 || id->device_id == 0)
+       if (id->vendor_id == 0 && id->device_id == 0 &&
+           id->subsystem_vendor_id == 0 && id->subsystem_device_id == 0)
                return iwinfo_hardware_id_from_mtd(id);
 
        return 0;