Blob Blame History Raw
From f3e6790b7986a4f9dd4a407901717ef8de3cbbc6 Mon Sep 17 00:00:00 2001
From: Jordan Hargrave <Jordan_Hargrave@dell.com>
Date: Tue, 25 Feb 2014 16:35:40 -0600
Subject: [PATCH] Add port structure to PCI device, handle multiple ports per
 BDF (Mellanox)

---
 src/pci.c | 21 +++++++++++++++++++++
 src/pci.h |  7 +++++++
 2 files changed, 28 insertions(+)

diff --git a/src/pci.c b/src/pci.c
index e85cb03..a2d8145 100644
--- a/src/pci.c
+++ b/src/pci.c
@@ -121,6 +121,25 @@ static int pci_vpd_find_info_subkey(const u8 *buf, unsigned int off, unsigned in
 	return -1;
 }
 
+/* Add port identifier(s) to PCI device */
+static void add_port(struct pci_device *pdev, int port, int pfi)
+{
+	struct pci_port *p;
+
+	list_for_each_entry(p, &pdev->ports, node) {
+		if (p->port == port && p->pfi == pfi)
+			return;
+	}
+	p = malloc(sizeof(*p));
+	if (p == NULL)
+		return;
+	memset(p, 0, sizeof(*p));
+	INIT_LIST_HEAD(&p->node);
+	p->port = port;
+	p->pfi = pfi;
+	list_add_tail(&p->node, &pdev->ports);
+}
+
 static int parse_vpd(struct libbiosdevname_state *state, struct pci_device *pdev, int len, unsigned char *vpd)
 {
 	int i, j, k, isz, jsz, port, func, pfi;
@@ -155,6 +174,7 @@ static int parse_vpd(struct libbiosdevname_state *state, struct pci_device *pdev
 						   pdev->pci_dev->bus,
 						   pdev->pci_dev->dev,
 						   func)) != NULL) {
+			add_port(vf, port, pfi);
 			if (vf->vpd_port == INT_MAX) {
 				vf->vpd_port = port;
 				vf->vpd_pfi = pfi;
@@ -597,6 +617,7 @@ static void add_pci_dev(struct libbiosdevname_state *state,
 	INIT_LIST_HEAD(&dev->node);
 	INIT_LIST_HEAD(&dev->vfnode);
 	INIT_LIST_HEAD(&dev->vfs);
+	INIT_LIST_HEAD(&dev->ports);
 	dev->pci_dev = p;
 	dev->physical_slot = PHYSICAL_SLOT_UNKNOWN;
 	dev->class         = pci_read_word(p, PCI_CLASS_DEVICE);
diff --git a/src/pci.h b/src/pci.h
index 77b4746..eacb539 100644
--- a/src/pci.h
+++ b/src/pci.h
@@ -20,6 +20,12 @@ struct slotlist
 	int count;
 };
 
+struct pci_port {
+	struct list_head node;
+	int port;
+	int pfi;
+};
+
 struct pci_device {
 	struct list_head node;
 	struct pci_dev *pci_dev;
@@ -44,6 +50,7 @@ struct pci_device {
 	struct pci_device *pf;
 	struct list_head vfnode;
 	struct list_head vfs;
+	struct list_head ports;
 	unsigned int is_sriov_physical_function:1;
 	unsigned int is_sriov_virtual_function:1;
 	unsigned int embedded_index_valid:1;
-- 
1.8.4.2