PCI: Log device type during enumeration
authorBjorn Helgaas <bhelgaas@google.com>
Fri, 10 Nov 2023 21:43:15 +0000 (15:43 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 15 Dec 2023 23:26:21 +0000 (17:26 -0600)
Log the device type when enumeration a device.  Sample output changes:

  - pci 0000:00:00.0: [8086:1237] type 00 class 0x060000
  + pci 0000:00:00.0: [8086:1237] type 00 class 0x060000 conventional PCI endpoint

  - pci 0000:00:1c.0: [8086:a110] type 01 class 0x060400
  + pci 0000:00:1c.0: [8086:a110] type 01 class 0x060400 PCIe Root Port

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/probe.c

index ed6b7f48736ad8b3c1a0cd83b2c0d213bffce4f5..6ee84dc939cab7164eda5228f8bc69324e5840b4 100644 (file)
@@ -1817,6 +1817,43 @@ static void early_dump_pci_device(struct pci_dev *pdev)
                       value, 256, false);
 }
 
+static const char *pci_type_str(struct pci_dev *dev)
+{
+       static const char * const str[] = {
+               "PCIe Endpoint",
+               "PCIe Legacy Endpoint",
+               "PCIe unknown",
+               "PCIe unknown",
+               "PCIe Root Port",
+               "PCIe Switch Upstream Port",
+               "PCIe Switch Downstream Port",
+               "PCIe to PCI/PCI-X bridge",
+               "PCI/PCI-X to PCIe bridge",
+               "PCIe Root Complex Integrated Endpoint",
+               "PCIe Root Complex Event Collector",
+       };
+       int type;
+
+       if (pci_is_pcie(dev)) {
+               type = pci_pcie_type(dev);
+               if (type < ARRAY_SIZE(str))
+                       return str[type];
+
+               return "PCIe unknown";
+       }
+
+       switch (dev->hdr_type) {
+       case PCI_HEADER_TYPE_NORMAL:
+               return "conventional PCI endpoint";
+       case PCI_HEADER_TYPE_BRIDGE:
+               return "conventional PCI bridge";
+       case PCI_HEADER_TYPE_CARDBUS:
+               return "CardBus bridge";
+       default:
+               return "conventional PCI";
+       }
+}
+
 /**
  * pci_setup_device - Fill in class and map information of a device
  * @dev: the device structure to fill
@@ -1887,8 +1924,9 @@ int pci_setup_device(struct pci_dev *dev)
 
        pci_set_removable(dev);
 
-       pci_info(dev, "[%04x:%04x] type %02x class %#08x\n",
-                dev->vendor, dev->device, dev->hdr_type, dev->class);
+       pci_info(dev, "[%04x:%04x] type %02x class %#08x %s\n",
+                dev->vendor, dev->device, dev->hdr_type, dev->class,
+                pci_type_str(dev));
 
        /* Device class may be changed after fixup */
        class = dev->class >> 8;