diff mbox series

[1/7] PCI: Log device type during enumeration

Message ID 20231205171119.680358-2-helgaas@kernel.org (mailing list archive)
State Accepted
Commit 24d7d693d9991751039c6332b30eaa58ce2f45b1
Delegated to: Bjorn Helgaas
Headers show
Series PCI: Improve enumeration logging | expand

Commit Message

Bjorn Helgaas Dec. 5, 2023, 5:11 p.m. UTC
From: Bjorn Helgaas <bhelgaas@google.com>

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 | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

Comments

Bjorn Helgaas Dec. 6, 2023, 12:31 a.m. UTC | #1
On Tue, Dec 05, 2023 at 11:11:13AM -0600, Bjorn Helgaas wrote:
> +		"PCIe Upstream Switch Port",
> +		"PCIe Downstream Switch Port",

Nit: I think I would change these to "PCIe Switch Upstream Port" and
"PCIe Switch Downstream Port" because that's the usual usage in the
spec.
diff mbox series

Patch

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index ed6b7f48736a..1dbc06f0305c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -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 *str[] = {
+		"PCIe Endpoint",
+		"PCIe Legacy Endpoint",
+		"PCIe unknown",
+		"PCIe unknown",
+		"PCIe Root Port",
+		"PCIe Upstream Switch Port",
+		"PCIe Downstream Switch 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;