Skip to contentSkip to conversation

Introducing EAL Bus-Device-Driver Model

PATCH Superseded Shreyansh Jain 7 participants 146 messages Jan 16, 2017 – Apr 14, 2017 Page 2 of 2

lore
Share & tools
lore
#107 lore raw

PATCH v11 6/13 app/test: check bus probe

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

---
 app/test/test_bus.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 149 insertions(+)
app/test/test_bus.c +149 -0
index de4f1ab..a3220f3 100644
@@ -120,12 +120,15 @@ static int scan_fn_for_busB(void);
 
 /* generic implementations wrapped around by above declarations */
 static int generic_scan_fn(struct rte_bus *bus);
+static int generic_probe_fn(void);
+static int dummy_match_fn(struct rte_driver *drv, struct rte_device *dev);
 
 struct dummy_bus busA = {
 	.name = "busA_impl", /* busA */
 	.bus = {
 		.name = "busA",
 		.scan = scan_fn_for_busA,
+		.probe = generic_probe_fn,
 	},
 };
 
@@ -134,6 +137,7 @@ struct dummy_bus busB = {
 	.bus = {
 		.name = "busB",
 		.scan = scan_fn_for_busB,
+		.probe = generic_probe_fn,
 	},
 };
 
@@ -283,6 +287,44 @@ generic_scan_fn(struct rte_bus *bus)
 	return 0;
 }
 
+/* @internal
+ * Obtain bus from driver object. Match the address of rte_device object
+ * with all the devices associated with that bus.
+ *
+ * Being a test function, all this does is validate that device object
+ * provided is available on the same bus to which driver is registered.
+ *
+ * @param drv
+ *	driver to match with
+ * @param dev
+ *	device object
+ * @return
+ *	0 for successful match
+ *	!0 for failed match
+ */
+static int
+dummy_match_fn(struct rte_driver *drv __rte_unused, struct rte_device *dev)
+{
+	struct dummy_device *ddev = NULL;
+	struct dummy_device *ddev_as_arg;
+	struct dummy_bus *dbus = NULL;
+
+	/* Match is based entirely on address of 'dev' and 'dev_p' extracted
+	 * from bus->device_list.
+	 */
+
+	/* a driver is registered with the bus *before* the scan. */
+	dbus = &busA; /* FIXME: bus cannot be retrieved without knowing the driver */
+	ddev_as_arg = container_of(dev, struct dummy_device, dev);
+
+	TAILQ_FOREACH(ddev, &dbus->device_list, next) {
+		if (ddev == ddev_as_arg)
+			return 0;
+	}
+
+	return 1;
+}
+
 int
 scan_fn_for_busA(void) {
 	struct dummy_bus_map *dbm;
@@ -499,6 +541,109 @@ test_bus_scan(void)
 	return 0;
 }
 
+/*
+ *
+ */
+static int
+generic_probe_fn(void)
+{
+	int ret = 0;
+	int i, j;
+	struct rte_driver *drv;
+	struct rte_device *dev;
+	struct dummy_bus *dbus = NULL;
+	struct dummy_device *ddev = NULL;
+	struct dummy_driver *ddrv = NULL;
+
+	/* In case of this test:
+	 * 1. for each bus in rte_bus_list
+	 * 2.  for each device on that bus (bus specific->device_list)
+	 * 3.   for each driver on that bus (bus specific->driver_list)
+	 * 4.    call match
+	 * 5.    link driver and device
+	 * 6. Verify the linkage.
+	 */
+	for (i = 0; bus_map[i].name; i++) {
+		/* get bus pointer from bus_map itself */
+		dbus = bus_map[i].dbus;
+
+		/* Looping over all scanned devices */
+		TAILQ_FOREACH(ddev, &dbus->device_list, next) {
+			/* There is a list of drivers within dummy_bus_map.
+			 * In case of PMDs, this would be driver registration
+			 * APIs/list
+			 */
+			for (j = 0; bus_map[i].ddrivers[j]; j++) {
+				ddrv = bus_map[i].ddrivers[j];
+
+				drv = &ddrv->drv;
+				dev = &ddev->dev;
+				ret = dummy_match_fn(drv, dev);
+				if (!ret) {
+					/* As match is generic, it always
+					 * results in dev->drv pointing to
+					 * first driver entry in bus_map[i]
+					 */
+					dev->driver = drv;
+				}
+				/* Else, continue */
+			}
+		}
+	}
+
+	/* Verify the linkage. All devices belonging to a bus_map[i]
+	 * should have same driver (first driver entry of bus_map[i])
+	 */
+	for (i = 0; bus_map[i].name; i++) {
+		ddrv = bus_map[i].ddrivers[0];
+		drv = &ddrv->drv;
+
+		for (j = 0; bus_map[i].ddevices[j]; j++) {
+			ddev = bus_map[i].ddevices[j];
+			dev = &ddev->dev;
+			if (dev->driver != drv) {
+				printf("Incorrect driver<->device linkage.\n");
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
+/* @internal
+ * Function to perform 'probe' and link devices and drivers on a bus.
+ * This would work over all the buses registered, and all devices and drivers
+ * registered with it - call match on each pair.
+ *
+ * @param void
+ * @return
+ *	0 for successful probe
+ *	!0 for failure in probe
+ *
+ */
+static int
+test_probe_on_bus(void)
+{
+	int ret = 0;
+	int i;
+	struct dummy_bus *dbus;
+	struct rte_bus *bus;
+
+	for (i = 0; bus_map[i].name; i++) {
+		/* get bus pointer from bus_map itself */
+		dbus = bus_map[i].dbus;
+		bus = &dbus->bus;
+		ret = bus->probe();
+		if (ret)
+			printf("Probe for %s failed.\n", bus_map[i].name);
+	}
+
+	printf("Probe on all buses successful.\n");
+	dump_device_tree();
+
+	return 0;
+}
 
 int
 test_bus(void)
@@ -513,6 +658,10 @@ test_bus(void)
 	if (test_bus_scan())
 		return -1;
 
+	/* Now that the devices and drivers are registered, perform probe */
+	if (test_probe_on_bus())
+		return -1;
+
 	if (test_device_unregistration_on_bus())
 		return -1;
 
Signature · 1 line
2.7.0
#108 lore raw

PATCH v11 7/13 pci: split match and probe

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).

Splitting the matching function into a public fn rte_pci_match.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 +
 lib/librte_eal/common/eal_common_pci.c          | 189 +++++++++++++-----------
 lib/librte_eal/common/include/rte_pci.h         |  15 ++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 +
 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
index a3d9fac..afa1643 100644
@@ -184,5 +184,6 @@ DPDK_17.02 {
 	rte_bus_register;
 	rte_bus_scan;
 	rte_bus_unregister;
+	rte_pci_match;
 
 } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85

233 lines not on this page · raw message

lib/librte_eal/common/include/rte_pci.h +15 -0
index 8557e47..adc20b9 100644
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
 int rte_eal_pci_scan(void);
 
 /**
+ * Match the PCI Driver and Device using the ID Table
+ *
+ * @param pci_drv
+ *	PCI driver from which ID table would be extracted
+ * @param pci_dev
+ *	PCI device to match against the driver
+ * @return
+ *	0 for successful match
+ *	!0 for unsuccessful match
+ */
+int
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+	      const struct rte_pci_device *pci_dev);
+
+/**
  * Probe the PCI bus for registered drivers.
  *
  * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -0
index 69e0e7b..b557e7c 100644
@@ -188,5 +188,6 @@ DPDK_17.02 {
 	rte_bus_register;
 	rte_bus_scan;
 	rte_bus_unregister;
+	rte_pci_match;
 
 } DPDK_16.11;
Signature · 1 line
2.7.0
#109 lore raw

Re: [PATCH v11 07/13] pci: split match and probe

Quoted 277 lines · Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).

Splitting the matching function into a public fn rte_pci_match.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 +
 lib/librte_eal/common/eal_common_pci.c          | 189 +++++++++++++-----------
 lib/librte_eal/common/include/rte_pci.h         |  15 ++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 +
 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
index a3d9fac..afa1643 100644
@@ -184,5 +184,6 @@ DPDK_17.02 {
        rte_bus_register;
        rte_bus_scan;
        rte_bus_unregister;
+       rte_pci_match;
 
 } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85
index 72547bd..4f155c6 100644
@@ -152,129 +152,148 @@ pci_unmap_resource(void *requested_addr, size_t size)
                                requested_addr);
 }
 
-/*
- * If vendor/device ID match, call the probe() function of the
- * driver.
- */
-static int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+int
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+             const struct rte_pci_device *pci_dev)
 {
-       int ret;
+       int match = 1;
        const struct rte_pci_id *id_table;
 
-       for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
+       if (!pci_drv || !pci_dev || !pci_drv->id_table) {
+               RTE_LOG(DEBUG, EAL, "Invalid PCI Driver object\n");
+               return -1;
+       }
 
+       for (id_table = pci_drv->id_table; id_table->vendor_id != 0;
+            id_table++) {
                /* check if device's identifiers match the driver's ones */
-               if (id_table->vendor_id != dev->id.vendor_id &&
+               if (id_table->vendor_id != pci_dev->id.vendor_id &&
                                id_table->vendor_id != PCI_ANY_ID)
                        continue;
-               if (id_table->device_id != dev->id.device_id &&
+               if (id_table->device_id != pci_dev->id.device_id &&
                                id_table->device_id != PCI_ANY_ID)
                        continue;
-               if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-                               id_table->subsystem_vendor_id != PCI_ANY_ID)
+               if (id_table->subsystem_vendor_id !=
+                   pci_dev->id.subsystem_vendor_id &&
+                   id_table->subsystem_vendor_id != PCI_ANY_ID)
                        continue;
-               if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-                               id_table->subsystem_device_id != PCI_ANY_ID)
+               if (id_table->subsystem_device_id !=
+                   pci_dev->id.subsystem_device_id &&
+                   id_table->subsystem_device_id != PCI_ANY_ID)
                        continue;
-               if (id_table->class_id != dev->id.class_id &&
+               if (id_table->class_id != pci_dev->id.class_id &&
                                id_table->class_id != RTE_CLASS_ANY_ID)
                        continue;
 
-               struct rte_pci_addr *loc = &dev->addr;
-
-               RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-                               loc->domain, loc->bus, loc->devid, loc->function,
-                               dev->device.numa_node);
-
-               /* no initialization when blacklisted, return without error */
-               if (dev->device.devargs != NULL &&
-                       dev->device.devargs->type ==
-                               RTE_DEVTYPE_BLACKLISTED_PCI) {
-                       RTE_LOG(INFO, EAL, "  Device is blacklisted, not initializing\n");
-                       return 1;
-               }
-
-               RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-                               dev->id.device_id, dr->driver.name);
-
-               if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-                       /* map resources for devices that use igb_uio */
-                       ret = rte_eal_pci_map_device(dev);
-                       if (ret != 0)
-                               return ret;
-               }
-
-               /* reference driver structure */
-               dev->driver = dr;
-
-               /* call the driver probe() function */
-               ret = dr->probe(dr, dev);
-               if (ret) {
-                       dev->driver = NULL;
-                       if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-                               rte_eal_pci_unmap_device(dev);
-               }
-
-               return ret;
+               match = 0;
+               break;
        }
-       /* return positive value if driver doesn't support this device */
-       return 1;
+
+       return match;
 }
 
 /*
- * If vendor/device ID match, call the remove() function of the
+ * If vendor/device ID match, call the probe() function of the
  * driver.
  */
 static int
-rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
-               struct rte_pci_device *dev)
+rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
+                            struct rte_pci_device *dev)
 {
-       const struct rte_pci_id *id_table;
+       int ret;
+       struct rte_pci_addr *loc;
 
        if ((dr == NULL) || (dev == NULL))
                return -EINVAL;
 
-       for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
+       loc = &dev->addr;
 
-               /* check if device's identifiers match the driver's ones */
-               if (id_table->vendor_id != dev->id.vendor_id &&
-                               id_table->vendor_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->device_id != dev->id.device_id &&
-                               id_table->device_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-                               id_table->subsystem_vendor_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-                               id_table->subsystem_device_id != PCI_ANY_ID)
-                       continue;
+       /* The device is not blacklisted; Check if driver supports it */
+       ret = rte_pci_match(dr, dev);
+       if (ret) {
+               /* Match of device and driver failed */
+               RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n",
+                       dr->driver.name);
+               return 1;
+       }
 
-               struct rte_pci_addr *loc = &dev->addr;
+       RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+                       loc->domain, loc->bus, loc->devid, loc->function,
+                       dev->device.numa_node);
+
+       /* no initialization when blacklisted, return without error */
+       if (dev->device.devargs != NULL &&
+               dev->device.devargs->type ==
+                       RTE_DEVTYPE_BLACKLISTED_PCI) {
+               RTE_LOG(INFO, EAL, "  Device is blacklisted, not"
+                       " initializing\n");
+               return 1;
+       }
 
-               RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-                               loc->domain, loc->bus, loc->devid,
-                               loc->function, dev->device.numa_node);
+       RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+               dev->id.device_id, dr->driver.name);
 
-               RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
-                               dev->id.device_id, dr->driver.name);
+       if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+               /* map resources for devices that use igb_uio */
+               ret = rte_eal_pci_map_device(dev);
+               if (ret != 0)
+                       return ret;
+       }
 
-               if (dr->remove && (dr->remove(dev) < 0))
-                       return -1;      /* negative value is an error */
+       /* reference driver structure */
+       dev->driver = dr;
 
-               /* clear driver structure */
+       /* call the driver probe() function */
+       ret = dr->probe(dr, dev);
+       if (ret) {
                dev->driver = NULL;
-
                if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-                       /* unmap resources for devices that use igb_uio */
                        rte_eal_pci_unmap_device(dev);
+       }
 
-               return 0;
+       return ret;
+}
+
+/*
+ * If vendor/device ID match, call the remove() function of the
+ * driver.
+ */
+static int
+rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
+               struct rte_pci_device *dev)
+{
+       int ret;
+       struct rte_pci_addr *loc;
+
+       if ((dr == NULL) || (dev == NULL))
+               return -EINVAL;
+
+       ret = rte_pci_match(dr, dev);
+       if (ret) {
+               /* Device and driver don't match */
+               return 1;
        }
 
-       /* return positive value if driver doesn't support this device */
-       return 1;
+       loc = &dev->addr;
+
+       RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+                       loc->domain, loc->bus, loc->devid,
+                       loc->function, dev->device.numa_node);
+
+       RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+                       dev->id.device_id, dr->driver.name);
+
+       if (dr->remove && (dr->remove(dev) < 0))
+               return -1;      /* negative value is an error */
+
+       /* clear driver structure */
+       dev->driver = NULL;
+
+       if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+               /* unmap resources for devices that use igb_uio */
+               rte_eal_pci_unmap_device(dev);
+
+       return 0;
 }
 
 /*
lib/librte_eal/common/include/rte_pci.h +3 -0
index 8557e47..adc20b9 100644
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
 int rte_eal_pci_scan(void);
 
 /**
+ * Match the PCI Driver and Device using the ID Table
+ *
+ * @param pci_drv

lib/librte_eal/common/include/rte_pci.h rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, · line 386

Quoted 10 lines
lib/librte_eal/common/include/rte_pci.h +10 -0
+ *     PCI driver from which ID table would be extracted
+ * @param pci_dev
+ *     PCI device to match against the driver
+ * @return
+ *     0 for successful match
+ *     !0 for unsuccessful match
+ */
+int
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+             const struct rte_pci_device *pci_dev);

I don't think this symbol needs to be exported and visible outside of EAL.

Quoted 19 lines
lib/librte_eal/common/include/rte_pci.h +2 -0
+
+/**
  * Probe the PCI bus for registered drivers.
  *
  * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -1
index 69e0e7b..b557e7c 100644
@@ -188,5 +188,6 @@ DPDK_17.02 {
        rte_bus_register;
        rte_bus_scan;
        rte_bus_unregister;
+       rte_pci_match;
 
 } DPDK_16.11;
--

2.7.0

#110 lore raw

Re: [PATCH v11 07/13] pci: split match and probe

2017-02-15 11:45, Jan Blunck:

Quoted 8 lines
Quoted 8 lines

/**
+ * Match the PCI Driver and Device using the ID Table
+ *
+ * @param pci_drv
+ * PCI driver from which ID table would be extracted
+ * @param pci_dev
+ * PCI device to match against the driver
+ * @return

Quoted 8 lines

lib/librte_eal/common/include/rte_pci.h rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, · line 386

Quoted 6 lines

+ * 0 for successful match
+ * !0 for unsuccessful match
+ */

lib/librte_eal/common/include/rte_pci.h +3 -0
+int
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+             const struct rte_pci_device *pci_dev);

I don't think this symbol needs to be exported and visible outside of EAL.

If I remember well, Shreyansh wants to re-use it for its own bus which is closed to PCI.
I think it is weird and we could look for another way to re-use some code. Shreyansh?

#111 lore raw

Re: [PATCH v11 07/13] pci: split match and probe

Quoted 27 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, February 15, 2017 4:53 PM
To: Jan Blunck <[email protected]>; Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH v11 07/13] pci: split match and probe

2017-02-15 11:45, Jan Blunck:

Quoted 8 lines
Quoted 8 lines

/**
+ * Match the PCI Driver and Device using the ID Table
+ *
+ * @param pci_drv
+ * PCI driver from which ID table would be extracted
+ * @param pci_dev
+ * PCI device to match against the driver
+ * @return

Quoted 8 lines

lib/librte_eal/common/include/rte_pci.h rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, · line 386

Quoted 6 lines

+ * 0 for successful match
+ * !0 for unsuccessful match
+ */

lib/librte_eal/common/include/rte_pci.h +3 -0
+int
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+             const struct rte_pci_device *pci_dev);

I don't think this symbol needs to be exported and visible outside of EAL.

Quoted 6 lines

If I remember well, Shreyansh wants to re-use it for its own bus which is closed to PCI.
I think it is weird and we could look for another way to re-use some code. Shreyansh?

From what I recall pci_match _was_ exported was because:

1. earlier match was a callback for bus. Which is not the case now
2. idea was that some other Buses might be able to re-use this. NXP DPAA2 implementation (in early stages).

I don't think this is needed anymore.

#112 lore raw

Re: [PATCH v11 07/13] pci: split match and probe

In reply to Jan Blunck
Quoted 275 lines · Jan Blunck
Quoted 273 lines · Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).

Splitting the matching function into a public fn rte_pci_match.

---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 +
 lib/librte_eal/common/eal_common_pci.c          | 189 +++++++++++++-----------
 lib/librte_eal/common/include/rte_pci.h         |  15 ++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 +
 4 files changed, 121 insertions(+), 85 deletions(-)
lib/librte_eal/bsdapp/eal/rte_eal_version.map +1 -0
index a3d9fac..afa1643 100644
@@ -184,5 +184,6 @@ DPDK_17.02 {
        rte_bus_register;
        rte_bus_scan;
        rte_bus_unregister;
+       rte_pci_match;
 
 } DPDK_16.11;
lib/librte_eal/common/eal_common_pci.c +104 -85
index 72547bd..4f155c6 100644
@@ -152,129 +152,148 @@ pci_unmap_resource(void *requested_addr, size_t size)
                                requested_addr);
 }
 
-/*
- * If vendor/device ID match, call the probe() function of the
- * driver.
- */
-static int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+int
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+             const struct rte_pci_device *pci_dev)
 {
-       int ret;
+       int match = 1;
        const struct rte_pci_id *id_table;
 
-       for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
+       if (!pci_drv || !pci_dev || !pci_drv->id_table) {
+               RTE_LOG(DEBUG, EAL, "Invalid PCI Driver object\n");
+               return -1;
+       }
 
+       for (id_table = pci_drv->id_table; id_table->vendor_id != 0;
+            id_table++) {
                /* check if device's identifiers match the driver's ones */
-               if (id_table->vendor_id != dev->id.vendor_id &&
+               if (id_table->vendor_id != pci_dev->id.vendor_id &&
                                id_table->vendor_id != PCI_ANY_ID)
                        continue;
-               if (id_table->device_id != dev->id.device_id &&
+               if (id_table->device_id != pci_dev->id.device_id &&
                                id_table->device_id != PCI_ANY_ID)
                        continue;
-               if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-                               id_table->subsystem_vendor_id != PCI_ANY_ID)
+               if (id_table->subsystem_vendor_id !=
+                   pci_dev->id.subsystem_vendor_id &&
+                   id_table->subsystem_vendor_id != PCI_ANY_ID)
                        continue;
-               if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-                               id_table->subsystem_device_id != PCI_ANY_ID)
+               if (id_table->subsystem_device_id !=
+                   pci_dev->id.subsystem_device_id &&
+                   id_table->subsystem_device_id != PCI_ANY_ID)
                        continue;
-               if (id_table->class_id != dev->id.class_id &&
+               if (id_table->class_id != pci_dev->id.class_id &&
                                id_table->class_id != RTE_CLASS_ANY_ID)
                        continue;
 
-               struct rte_pci_addr *loc = &dev->addr;
-
-               RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-                               loc->domain, loc->bus, loc->devid, loc->function,
-                               dev->device.numa_node);
-
-               /* no initialization when blacklisted, return without error */
-               if (dev->device.devargs != NULL &&
-                       dev->device.devargs->type ==
-                               RTE_DEVTYPE_BLACKLISTED_PCI) {
-                       RTE_LOG(INFO, EAL, "  Device is blacklisted, not initializing\n");
-                       return 1;
-               }
-
-               RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-                               dev->id.device_id, dr->driver.name);
-
-               if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-                       /* map resources for devices that use igb_uio */
-                       ret = rte_eal_pci_map_device(dev);
-                       if (ret != 0)
-                               return ret;
-               }
-
-               /* reference driver structure */
-               dev->driver = dr;
-
-               /* call the driver probe() function */
-               ret = dr->probe(dr, dev);
-               if (ret) {
-                       dev->driver = NULL;
-                       if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-                               rte_eal_pci_unmap_device(dev);
-               }
-
-               return ret;
+               match = 0;
+               break;
        }
-       /* return positive value if driver doesn't support this device */
-       return 1;
+
+       return match;
 }
 
 /*
- * If vendor/device ID match, call the remove() function of the
+ * If vendor/device ID match, call the probe() function of the
  * driver.
  */
 static int
-rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
-               struct rte_pci_device *dev)
+rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
+                            struct rte_pci_device *dev)
 {
-       const struct rte_pci_id *id_table;
+       int ret;
+       struct rte_pci_addr *loc;
 
        if ((dr == NULL) || (dev == NULL))
                return -EINVAL;
 
-       for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
+       loc = &dev->addr;
 
-               /* check if device's identifiers match the driver's ones */
-               if (id_table->vendor_id != dev->id.vendor_id &&
-                               id_table->vendor_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->device_id != dev->id.device_id &&
-                               id_table->device_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-                               id_table->subsystem_vendor_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-                               id_table->subsystem_device_id != PCI_ANY_ID)
-                       continue;
+       /* The device is not blacklisted; Check if driver supports it */
+       ret = rte_pci_match(dr, dev);
+       if (ret) {
+               /* Match of device and driver failed */
+               RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n",
+                       dr->driver.name);
+               return 1;
+       }
 
-               struct rte_pci_addr *loc = &dev->addr;
+       RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+                       loc->domain, loc->bus, loc->devid, loc->function,
+                       dev->device.numa_node);
+
+       /* no initialization when blacklisted, return without error */
+       if (dev->device.devargs != NULL &&
+               dev->device.devargs->type ==
+                       RTE_DEVTYPE_BLACKLISTED_PCI) {
+               RTE_LOG(INFO, EAL, "  Device is blacklisted, not"
+                       " initializing\n");
+               return 1;
+       }
 
-               RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-                               loc->domain, loc->bus, loc->devid,
-                               loc->function, dev->device.numa_node);
+       RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+               dev->id.device_id, dr->driver.name);
 
-               RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
-                               dev->id.device_id, dr->driver.name);
+       if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+               /* map resources for devices that use igb_uio */
+               ret = rte_eal_pci_map_device(dev);
+               if (ret != 0)
+                       return ret;
+       }
 
-               if (dr->remove && (dr->remove(dev) < 0))
-                       return -1;      /* negative value is an error */
+       /* reference driver structure */
+       dev->driver = dr;
 
-               /* clear driver structure */
+       /* call the driver probe() function */
+       ret = dr->probe(dr, dev);
+       if (ret) {
                dev->driver = NULL;
-
                if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-                       /* unmap resources for devices that use igb_uio */
                        rte_eal_pci_unmap_device(dev);
+       }
 
-               return 0;
+       return ret;
+}
+
+/*
+ * If vendor/device ID match, call the remove() function of the
+ * driver.
+ */
+static int
+rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
+               struct rte_pci_device *dev)
+{
+       int ret;
+       struct rte_pci_addr *loc;
+
+       if ((dr == NULL) || (dev == NULL))
+               return -EINVAL;
+
+       ret = rte_pci_match(dr, dev);
+       if (ret) {
+               /* Device and driver don't match */
+               return 1;
        }
 
-       /* return positive value if driver doesn't support this device */
-       return 1;
+       loc = &dev->addr;
+
+       RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+                       loc->domain, loc->bus, loc->devid,
+                       loc->function, dev->device.numa_node);
+
+       RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+                       dev->id.device_id, dr->driver.name);
+
+       if (dr->remove && (dr->remove(dev) < 0))
+               return -1;      /* negative value is an error */
+
+       /* clear driver structure */
+       dev->driver = NULL;
+
+       if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+               /* unmap resources for devices that use igb_uio */
+               rte_eal_pci_unmap_device(dev);
+
+       return 0;
 }
 
 /*
lib/librte_eal/common/include/rte_pci.h +0 -0
index 8557e47..adc20b9 100644
@@ -371,6 +371,21 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
 int rte_eal_pci_scan(void);
 
Quoted 16 lines
Quoted 4 lines
lib/librte_eal/common/include/rte_pci.h +3 -0
 /**
+ * Match the PCI Driver and Device using the ID Table
+ *
+ * @param pci_drv

lib/librte_eal/common/include/rte_pci.h rte_eal_compare_pci_addr(const struct rte_pci_addr *addr, · line 386

Quoted 10 lines
lib/librte_eal/common/include/rte_pci.h +10 -0
+ *     PCI driver from which ID table would be extracted
+ * @param pci_dev
+ *     PCI device to match against the driver
+ * @return
+ *     0 for successful match
+ *     !0 for unsuccessful match
+ */
+int
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+             const struct rte_pci_device *pci_dev);

I don't think this symbol needs to be exported and visible outside of EAL.

Agree.
2 reasons why this exists:
1. Initial RFC has match as a callback. That doesn't exist now.
2. Earlier the idea was that other buses/device-types might use this function (buses which are PCI like), but that is not a good assumption.

Quoted 21 lines
Quoted 20 lines
lib/librte_eal/common/include/rte_pci.h +2 -0
+
+/**
  * Probe the PCI bus for registered drivers.
  *
  * Scan the content of the PCI bus, and call the probe() function for
lib/librte_eal/linuxapp/eal/rte_eal_version.map +1 -1
index 69e0e7b..b557e7c 100644
@@ -188,5 +188,6 @@ DPDK_17.02 {
        rte_bus_register;
        rte_bus_scan;
        rte_bus_unregister;
+       rte_pci_match;
 
 } DPDK_16.11;
--

2.7.0

#113 lore raw

PATCH v11 8/13 pci: remove loop over drivers in device detach

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

rte_eal_pci_detach calls pci_detach_all_drivers which loops over all PCI drivers for detaching the device. This is unnecessary as the device already has the PCI driver reference which can be used directly.

Removing pci_detach_all_drivers and restructuring rte_eal_pci_detach and rte_eal_pci_detach_dev to work without looping over driver list.

---
 lib/librte_eal/common/eal_common_pci.c | 47 +++++++---------------------------
 1 file changed, 9 insertions(+), 38 deletions(-)
lib/librte_eal/common/eal_common_pci.c +9 -38
index 4f155c6..8b4ae2d 100644
@@ -259,21 +259,15 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
  * driver.
  */
 static int
-rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev)
+rte_eal_pci_detach_dev(struct rte_pci_device *dev)
 {
-	int ret;
 	struct rte_pci_addr *loc;
+	struct rte_pci_driver *dr;
 
-	if ((dr == NULL) || (dev == NULL))
+	if (dev == NULL)
 		return -EINVAL;
 
-	ret = rte_pci_match(dr, dev);
-	if (ret) {
-		/* Device and driver don't match */
-		return 1;
-	}
-
+	dr = dev->driver;
 	loc = &dev->addr;
 
 	RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
@@ -328,33 +322,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 }
 
 /*
- * If vendor/device ID match, call the remove() function of all
- * registered driver for the given device. Return -1 if initialization
- * failed, return 1 if no driver is found for this device.
- */
-static int
-pci_detach_all_drivers(struct rte_pci_device *dev)
-{
-	struct rte_pci_driver *dr = NULL;
-	int rc = 0;
-
-	if (dev == NULL)
-		return -1;
-
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
-		rc = rte_eal_pci_detach_dev(dr, dev);
-		if (rc < 0)
-			/* negative value is an error */
-			return -1;
-		if (rc > 0)
-			/* positive value means driver doesn't support it */
-			continue;
-		return 0;
-	}
-	return 1;
-}
-
-/*
  * Find the pci device specified by pci address, then invoke probe function of
  * the driver of the devive.
  */
@@ -407,9 +374,13 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
-		ret = pci_detach_all_drivers(dev);
+		ret = rte_eal_pci_detach_dev(dev);
 		if (ret < 0)
+			/* negative value is an error */
 			goto err_return;
+		if (ret > 0)
+			/* positive value means driver doesn't support it */
+			continue;
 
 		TAILQ_REMOVE(&pci_device_list, dev, next);
 		free(dev);
Signature · 1 line
2.7.0
#114 lore raw

PATCH v11 9/13 pci: add bus driver

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Based on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch.

EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices.

---
 lib/librte_eal/bsdapp/eal/eal.c         |  1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c     | 11 ++++++
 lib/librte_eal/common/eal_common_pci.c  | 25 +++++++++++++
 lib/librte_eal/common/include/rte_pci.h | 65 +++++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 12 ++++++
 5 files changed, 114 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +1 -0
index 534aeea..ee7c9de 100644
@@ -64,6 +64,7 @@
 #include <rte_string_fns.h>
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_dev.h>
 #include <rte_devargs.h>
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
index 3a5c315..48bfe24 100644
@@ -673,3 +673,14 @@ rte_eal_pci_init(void)
 	}
 	return 0;
 }
+
+struct rte_pci_bus rte_pci_bus = {
+	.bus = {
+		.scan = rte_eal_pci_scan,
+		.probe = rte_eal_pci_probe,
+	},
+	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
+};
+
+RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
lib/librte_eal/common/eal_common_pci.c +25 -0
index 8b4ae2d..c53e2bd 100644
@@ -71,6 +71,7 @@
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
@@ -87,6 +88,8 @@ struct pci_driver_list pci_driver_list =
 struct pci_device_list pci_device_list =
 	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
+extern struct rte_pci_bus rte_pci_bus;
+
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 
 const char *pci_get_sysfs_path(void)
@@ -479,3 +482,25 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)
 	rte_eal_driver_unregister(&driver->driver);
 	TAILQ_REMOVE(&pci_driver_list, driver, next);
 }
+
+/* Add a device to PCI bus */
+void
+rte_eal_pci_add_device(struct rte_pci_device *pci_dev)
+{
+	TAILQ_INSERT_TAIL(&rte_pci_bus.device_list, pci_dev, next);
+}
+
+/* Insert a device into a predefined position in PCI bus */
+void
+rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev,
+			  struct rte_pci_device *new_pci_dev)
+{
+	TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next);
+}
+
+/* Remove a device from PCI bus */
+void
+rte_eal_pci_remove_device(struct rte_pci_device *pci_dev)
+{
+	TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next);
+}
lib/librte_eal/common/include/rte_pci.h +65 -0

95 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/eal_pci.c +12 -0
index e2fc219..c40814d 100644
@@ -35,6 +35,7 @@
 #include <dirent.h>
 
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
@@ -723,3 +724,14 @@ rte_eal_pci_init(void)
 
 	return 0;
 }
+
+struct rte_pci_bus rte_pci_bus = {
+	.bus = {
+		.scan = rte_eal_pci_scan,
+		.probe = rte_eal_pci_probe,
+	},
+	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
+};
+
+RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
Signature · 1 line
2.7.0
#115 lore raw

Re: [PATCH v11 09/13] pci: add bus driver

Quoted 162 lines · Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Based on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch.

EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices.

---
 lib/librte_eal/bsdapp/eal/eal.c         |  1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c     | 11 ++++++
 lib/librte_eal/common/eal_common_pci.c  | 25 +++++++++++++
 lib/librte_eal/common/include/rte_pci.h | 65 +++++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 12 ++++++
 5 files changed, 114 insertions(+)
lib/librte_eal/bsdapp/eal/eal.c +1 -0
index 534aeea..ee7c9de 100644
@@ -64,6 +64,7 @@
 #include <rte_string_fns.h>
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_dev.h>
 #include <rte_devargs.h>
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
index 3a5c315..48bfe24 100644
@@ -673,3 +673,14 @@ rte_eal_pci_init(void)
        }
        return 0;
 }
+
+struct rte_pci_bus rte_pci_bus = {
+       .bus = {
+               .scan = rte_eal_pci_scan,
+               .probe = rte_eal_pci_probe,
+       },
+       .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+       .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
+};
+
+RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
lib/librte_eal/common/eal_common_pci.c +25 -0
index 8b4ae2d..c53e2bd 100644
@@ -71,6 +71,7 @@
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
@@ -87,6 +88,8 @@ struct pci_driver_list pci_driver_list =
 struct pci_device_list pci_device_list =
        TAILQ_HEAD_INITIALIZER(pci_device_list);
 
+extern struct rte_pci_bus rte_pci_bus;
+
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 
 const char *pci_get_sysfs_path(void)
@@ -479,3 +482,25 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)
        rte_eal_driver_unregister(&driver->driver);
        TAILQ_REMOVE(&pci_driver_list, driver, next);
 }
+
+/* Add a device to PCI bus */
+void
+rte_eal_pci_add_device(struct rte_pci_device *pci_dev)
+{
+       TAILQ_INSERT_TAIL(&rte_pci_bus.device_list, pci_dev, next);
+}
+
+/* Insert a device into a predefined position in PCI bus */
+void
+rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev,
+                         struct rte_pci_device *new_pci_dev)
+{
+       TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next);
+}
+
+/* Remove a device from PCI bus */
+void
+rte_eal_pci_remove_device(struct rte_pci_device *pci_dev)
+{
+       TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next);
+}
lib/librte_eal/common/include/rte_pci.h +30 -0
index adc20b9..957cddb 100644
@@ -85,6 +85,7 @@ extern "C" {
 #include <rte_debug.h>
 #include <rte_interrupts.h>
 #include <rte_dev.h>
+#include <rte_bus.h>
 
 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
 TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
@@ -111,6 +112,25 @@ const char *pci_get_sysfs_path(void);
 /** Maximum number of PCI resources. */
 #define PCI_MAX_RESOURCE 6
 
+/** Name of PCI Bus */
+#define PCI_BUS_NAME "PCI"
+
+/* Forward declarations */
+struct rte_pci_device;
+struct rte_pci_driver;
+
+/** List of PCI devices */
+TAILQ_HEAD(rte_pci_device_list, rte_pci_device);
+/** List of PCI drivers */
+TAILQ_HEAD(rte_pci_driver_list, rte_pci_driver);
+
+/* PCI Bus iterators */
+#define FOREACH_DEVICE_ON_PCIBUS(p)    \
+               TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
+
+#define FOREACH_DRIVER_ON_PCIBUS(p)    \
+               TAILQ_FOREACH(p, &(rte_pci_bus.driver_list), next)
+
 /**
  * A structure describing an ID for a PCI driver. Each driver provides a
  * table of these IDs for each device that it supports.
@@ -206,12 +226,22 @@ typedef int (pci_remove_t)(struct rte_pci_device *);
 struct rte_pci_driver {
        TAILQ_ENTRY(rte_pci_driver) next;       /**< Next in list. */
        struct rte_driver driver;               /**< Inherit core driver. */
+       struct rte_pci_bus *bus;                /**< PCI bus reference. */
        pci_probe_t *probe;                     /**< Device Probe function. */
        pci_remove_t *remove;                   /**< Device Remove function. */
        const struct rte_pci_id *id_table;      /**< ID table, NULL terminated. */
        uint32_t drv_flags;                     /**< Flags contolling handling of device. */
 };
 
+/**
+ * Structure describing the PCI bus
+ */
+struct rte_pci_bus {
+       struct rte_bus bus;               /**< Inherit the generic class */
+       struct rte_pci_device_list device_list;  /**< List of PCI devices */
+       struct rte_pci_driver_list driver_list;  /**< List of PCI drivers */
+};
+
 /** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */
 #define RTE_PCI_DRV_NEED_MAPPING 0x0001
 /** Device driver supports link state interrupt */
@@ -523,6 +553,41 @@ RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
 void rte_eal_pci_unregister(struct rte_pci_driver *driver);
 
 /**

lib/librte_eal/common/include/rte_pci.h RTE_PMD_EXPORT_NAME(nm, __COUNTER__) · line 565

Quoted 10 lines
lib/librte_eal/common/include/rte_pci.h +10 -0
+ * Add a PCI device to the PCI Bus (append to PCI Device list). This function
+ * also updates the bus references of the PCI Device (and the generic device
+ * object embedded within.
+ *
+ * @param pci_dev
+ *     PCI device to add
+ * @return void
+ */
+void rte_eal_pci_add_device(struct rte_pci_device *pci_dev);
+

Who would be the user of this?

Quoted 1 line

From my understanding a device will show up on the bus if:

1. bus->scan() finds it
2. bus->attach(devargs) explicitly adds it to the whitelist

Both methods shouldn't require us to expose the API outside of eal.

Quoted 42 lines
lib/librte_eal/common/include/rte_pci.h +25 -0
+/**
+ * Insert a PCI device in the PCI Bus at a particular location in the device
+ * list. It also updates the PCI Bus reference of the new devices to be
+ * inserted.
+ *
+ * @param exist_pci_dev
+ *     Existing PCI device in PCI Bus
+ * @param new_pci_dev
+ *     PCI device to be added before exist_pci_dev
+ * @return void
+ */
+void rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev,
+                              struct rte_pci_device *new_pci_dev);
+
+/**
+ * Remove a PCI device from the PCI Bus. This sets to NULL the bus references
+ * in the PCI device object as well as the generic device object.
+ *
+ * @param pci_device
+ *     PCI device to be removed from PCI Bus
+ * @return void
+ */
+void rte_eal_pci_remove_device(struct rte_pci_device *pci_device);
+
+/**
  * Read PCI config space.
  *
  * @param device
lib/librte_eal/linuxapp/eal/eal_pci.c +1 -0
index e2fc219..c40814d 100644
@@ -35,6 +35,7 @@
 #include <dirent.h>
 
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
@@ -723,3 +724,14 @@ rte_eal_pci_init(void)
 

lib/librte_eal/linuxapp/eal/eal_pci.c rte_eal_pci_init(void) · line 734

Quoted 10 lines
lib/librte_eal/linuxapp/eal/eal_pci.c +8 -0
        return 0;
 }
+
+struct rte_pci_bus rte_pci_bus = {
+       .bus = {
+               .scan = rte_eal_pci_scan,
+               .probe = rte_eal_pci_probe,
+       },
+       .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+       .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),

I don't see why this is necessary and I believe it makes people think we might want to model topology. It's better to keep it simple and have it locally in eal_common_pci.c.

#116 lore raw

Re: [PATCH v11 09/13] pci: add bus driver

2017-02-15 11:42, Jan Blunck:

Quoted 14 lines

Review

Quoted 11 lines

/**
+ * Add a PCI device to the PCI Bus (append to PCI Device list). This function
+ * also updates the bus references of the PCI Device (and the generic device
+ * object embedded within.
+ *
+ * @param pci_dev
+ * PCI device to add
+ * @return void
+ */

(quoted diff) +2 -0
+void rte_eal_pci_add_device(struct rte_pci_device *pci_dev);
+

Who would be the user of this?

Quoted 5 lines

From my understanding a device will show up on the bus if:
1. bus->scan() finds it
2. bus->attach(devargs) explicitly adds it to the whitelist

Both methods shouldn't require us to expose the API outside of eal.

I agree

Quoted 11 lines

lib/librte_eal/bsdapp/eal/eal_pci.c rte_eal_pci_init(void) · line 683

Quoted 7 lines
lib/librte_eal/bsdapp/eal/eal_pci.c +7 -0
+struct rte_pci_bus rte_pci_bus = {
+       .bus = {
+               .scan = rte_eal_pci_scan,
+               .probe = rte_eal_pci_probe,
+       },
+       .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+       .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),

I don't see why this is necessary and I believe it makes people think we might want to model topology. It's better to keep it simple and have it locally in eal_common_pci.c.

I agree

#117 lore raw

PATCH v11 10/13 app/test: add PCI bus driver

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

---
 app/test/test_pci.c | 164 ++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 114 insertions(+), 50 deletions(-)
app/test/test_pci.c +114 -50
index cda186d..09261cc 100644
@@ -38,9 +38,11 @@
 #include <sys/queue.h>
 
 #include <rte_interrupts.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_ethdev.h>
 #include <rte_devargs.h>
+#include <rte_tailq.h>
 
 #include "test.h"
 #include "resource.h"
@@ -61,10 +63,31 @@
 
 int test_pci_run = 0; /* value checked by the multiprocess test */
 static unsigned pci_dev_count;
+struct test_pci_bus;
+static struct test_pci_bus *pci_bus; /* global reference to a Test PCI bus */
+
+/** List of PCI devices */
+TAILQ_HEAD(test_pci_device_list, rte_pci_device);
+/** List of PCI drivers */
+TAILQ_HEAD(test_pci_driver_list, rte_pci_driver);
 
 static int my_driver_init(struct rte_pci_driver *dr,
 			  struct rte_pci_device *dev);
 
+struct test_pci_bus {
+	struct rte_bus bus;
+	struct test_pci_device_list test_device_list;
+	struct test_pci_driver_list test_driver_list;
+};
+
+struct test_pci_bus test_pci_bus = {
+	.bus = {
+		.name = "test_pci_bus",
+		.scan = rte_eal_pci_scan,
+		.probe = rte_eal_pci_probe,
+	},
+};
+
 /* IXGBE NICS */
 struct rte_pci_id my_driver_id[] = {
 	{RTE_PCI_DEVICE(0x0001, 0x1234)},
@@ -79,7 +102,7 @@ struct rte_pci_id my_driver_id2[] = {
 
 struct rte_pci_driver my_driver = {
 	.driver = {
-		.name = "test_driver"
+		.name = "test_driver",
 	},
 	.probe = my_driver_init,
 	.id_table = my_driver_id,
@@ -88,7 +111,7 @@ struct rte_pci_driver my_driver = {
 
 struct rte_pci_driver my_driver2 = {
 	.driver = {
-		.name = "test_driver2"
+		.name = "test_driver2",
 	},
 	.probe = my_driver_init,
 	.id_table = my_driver_id2,
@@ -108,6 +131,55 @@ my_driver_init(__attribute__((unused)) struct rte_pci_driver *dr,
 	return 0;
 }
 
+/* dump devices on the bus */
+static void
+do_pci_device_dump(FILE *f)
+{
+	int i;
+	struct rte_pci_device *dev = NULL;
+
+	TAILQ_FOREACH(dev, &test_pci_bus.test_device_list, next) {
+
+		fprintf(f, PCI_PRI_FMT, dev->addr.domain, dev->addr.bus,
+		       dev->addr.devid, dev->addr.function);
+		fprintf(f, " - vendor:%x device:%x\n", dev->id.vendor_id,
+		       dev->id.device_id);
+
+		for (i = 0; i != sizeof(dev->mem_resource) /
+			sizeof(dev->mem_resource[0]); i++) {
+			fprintf(f, "   %16.16"PRIx64" %16.16"PRIx64"\n",
+				dev->mem_resource[i].phys_addr,
+				dev->mem_resource[i].len);
+		}
+	}
+}
+
+/* Dummy implementation for rte_eal_pci_probe() over test_pci_bus */
+static int
+do_pci_bus_probe(void)
+{
+	int ret;
+	struct rte_pci_device *device;
+	struct rte_pci_driver *driver;
+
+	TAILQ_FOREACH(device, &test_pci_bus.test_device_list, next) {
+		TAILQ_FOREACH(driver, &test_pci_bus.test_driver_list, next) {
+			ret = rte_pci_match(driver, device);
+			if (!ret) {
+				if (!driver->probe)
+					continue;
+
+				device->driver = driver;
+				ret = driver->probe(driver, device);
+				if (ret != 0)
+					return ret;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static void
 blacklist_all_devices(void)
 {
@@ -115,7 +187,7 @@ blacklist_all_devices(void)
 	unsigned i = 0;
 	char pci_addr_str[16];
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	TAILQ_FOREACH(dev, &(test_pci_bus.test_device_list), next) {
 		snprintf(pci_addr_str, sizeof(pci_addr_str), PCI_PRI_FMT,
 			dev->addr.domain, dev->addr.bus, dev->addr.devid,
 			dev->addr.function);
@@ -142,19 +214,11 @@ static void free_devargs_list(void)
 	}
 }
 
-/* backup real devices & drivers (not used for testing) */
-struct pci_driver_list real_pci_driver_list =
-	TAILQ_HEAD_INITIALIZER(real_pci_driver_list);
-struct pci_device_list real_pci_device_list =
-	TAILQ_HEAD_INITIALIZER(real_pci_device_list);
-
 REGISTER_LINKED_RESOURCE(test_pci_sysfs);
 
 static int
 test_pci_setup(void)
 {
-	struct rte_pci_device *dev;
-	struct rte_pci_driver *dr;
 	const struct resource *r;
 	int ret;
 
@@ -167,22 +231,22 @@ test_pci_setup(void)
 	ret = setenv("SYSFS_PCI_DEVICES", "test_pci_sysfs/bus/pci/devices", 1);
 	TEST_ASSERT_SUCCESS(ret, "failed to setenv");
 
-	/* Unregister original devices & drivers lists */
-	while (!TAILQ_EMPTY(&pci_driver_list)) {
-		dr = TAILQ_FIRST(&pci_driver_list);
-		rte_eal_pci_unregister(dr);
-		TAILQ_INSERT_TAIL(&real_pci_driver_list, dr, next);
-	}
+	TAILQ_INIT(&test_pci_bus.test_device_list);
+	TAILQ_INIT(&test_pci_bus.test_driver_list);
 
-	while (!TAILQ_EMPTY(&pci_device_list)) {
-		dev = TAILQ_FIRST(&pci_device_list);
-		TAILQ_REMOVE(&pci_device_list, dev, next);
-		TAILQ_INSERT_TAIL(&real_pci_device_list, dev, next);
-	}
+	/* Create a new Bus called 'test_pci_bus' */
+	/* Bus doesn't exist; Create the test bus */
+	printf("Creating a Test PCI bus\n");
+	rte_bus_register(&test_pci_bus.bus);
+	pci_bus = &test_pci_bus;
+
+	printf("Scan for Test devices and add to bus\n");
+	ret = pci_bus->bus.scan();
 
-	ret = rte_eal_pci_scan();
 	TEST_ASSERT_SUCCESS(ret, "failed to scan PCI bus");
-	rte_eal_pci_dump(stdout);
+
+	printf("Dump of all devices scanned:\n");
+	do_pci_device_dump(stdout);
 
 	return 0;
 }
@@ -190,10 +254,11 @@ test_pci_setup(void)
 static int
 test_pci_cleanup(void)
 {
-	struct rte_pci_device *dev;
-	struct rte_pci_driver *dr;
+	struct rte_pci_device *dev = NULL;
+	struct rte_pci_driver *dr = NULL;
 	const struct resource *r;
 	int ret;
+	void *temp;
 
 	unsetenv("SYSFS_PCI_DEVICES");
 
@@ -203,28 +268,23 @@ test_pci_cleanup(void)
 	ret = resource_rm_by_tar(r);
 	TEST_ASSERT_SUCCESS(ret, "Failed to delete resource %s", r->name);
 
+	TEST_ASSERT_NOT_NULL(pci_bus, "Invalid bus specified");
+
 	/*
 	 * FIXME: there is no API in DPDK to free a rte_pci_device so we
 	 * cannot free the devices in the right way. Let's assume that we
 	 * don't care for tests.
 	 */
-	while (!TAILQ_EMPTY(&pci_device_list)) {
-		dev = TAILQ_FIRST(&pci_device_list);
-		TAILQ_REMOVE(&pci_device_list, dev, next);
+	TAILQ_FOREACH_SAFE(dev, &(test_pci_bus.test_device_list), next, temp) {
+		TAILQ_REMOVE(&(test_pci_bus.test_device_list), dev, next);
+		dev->driver = NULL;
 	}
 
-	/* Restore original devices & drivers lists */
-	while (!TAILQ_EMPTY(&real_pci_driver_list)) {
-		dr = TAILQ_FIRST(&real_pci_driver_list);
-		TAILQ_REMOVE(&real_pci_driver_list, dr, next);
-		rte_eal_pci_register(dr);
+	TAILQ_FOREACH_SAFE(dr, &(test_pci_bus.test_driver_list), next, temp) {
+		TAILQ_REMOVE(&(test_pci_bus.test_driver_list), dr, next);
 	}
 
-	while (!TAILQ_EMPTY(&real_pci_device_list)) {
-		dev = TAILQ_FIRST(&real_pci_device_list);
-		TAILQ_REMOVE(&real_pci_device_list, dev, next);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
-	}
+	rte_bus_unregister(&pci_bus->bus);
 
 	return 0;
 }
@@ -234,16 +294,19 @@ test_pci_blacklist(void)
 {
 	struct rte_devargs_list save_devargs_list;
 
-	printf("Dump all devices\n");
-	TEST_ASSERT(TAILQ_EMPTY(&pci_driver_list),
-			"pci_driver_list not empty");
+	TEST_ASSERT_NOT_NULL(pci_bus, "Invalid bus specified");
 
-	rte_eal_pci_register(&my_driver);
-	rte_eal_pci_register(&my_driver2);
+	TEST_ASSERT(TAILQ_EMPTY(&test_pci_bus.test_driver_list),
+		    "PCI Driver list not empty");
+
+	/* Add test drivers to Bus */
+	TAILQ_INSERT_TAIL(&test_pci_bus.test_driver_list, &my_driver, next);
+	TAILQ_INSERT_TAIL(&test_pci_bus.test_driver_list, &my_driver2, next);
 
 	pci_dev_count = 0;
-	printf("Scan bus\n");
-	rte_eal_pci_probe();
+
+	printf("Probe the Test Bus\n");
+	do_pci_bus_probe();
 
 	if (pci_dev_count == 0) {
 		printf("no device detected\n");
@@ -257,8 +320,8 @@ test_pci_blacklist(void)
 	blacklist_all_devices();
 
 	pci_dev_count = 0;
-	printf("Scan bus with all devices blacklisted\n");
-	rte_eal_pci_probe();
+	printf("Probe bus with all devices blacklisted\n");
+	do_pci_bus_probe();
 
 	free_devargs_list();
 	devargs_list = save_devargs_list;
@@ -270,8 +333,9 @@ test_pci_blacklist(void)
 
 	test_pci_run = 1;
 
-	rte_eal_pci_unregister(&my_driver);
-	rte_eal_pci_unregister(&my_driver2);
+	/* Clear the test drivers added to Test Bus */
+	TAILQ_REMOVE(&(test_pci_bus.test_driver_list), &my_driver, next);
+	TAILQ_REMOVE(&(test_pci_bus.test_driver_list), &my_driver2, next);
 
 	return 0;
 }
Signature · 1 line
2.7.0
#118 lore raw

PATCH v11 11/13 pci: use bus driver for scan/probe

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Remove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.

---
 lib/librte_eal/bsdapp/eal/eal.c                 |  7 -----
 lib/librte_eal/bsdapp/eal/eal_pci.c             | 32 ++++++++-------------
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 --
 lib/librte_eal/common/eal_common_pci.c          | 26 +++++++----------
 lib/librte_eal/common/eal_private.h             | 10 -------
 lib/librte_eal/common/include/rte_pci.h         | 19 +++----------
 lib/librte_eal/linuxapp/eal/eal.c               |  7 -----
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 38 +++++++++----------------
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 --
 9 files changed, 41 insertions(+), 102 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -7
index ee7c9de..a7f2671 100644
@@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_timer_init() < 0)
 		rte_panic("Cannot init HPET or TSC timers\n");
 
-	if (rte_eal_pci_init() < 0)
-		rte_panic("Cannot init PCI\n");
-
 	eal_check_mem_on_local_socket();
 
 	if (eal_plugins_init() < 0)
@@ -617,10 +614,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe())
-		rte_panic("Cannot probe PCI\n");
-
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
lib/librte_eal/bsdapp/eal/eal_pci.c +12 -20
index 48bfe24..103ad70 100644
@@ -87,6 +87,9 @@
  * enabling bus master.
  */
 
+/* Forward declaration of PCI bus */
+struct rte_pci_bus rte_pci_bus;
+
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
@@ -313,19 +316,19 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	}
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+	if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+		rte_eal_pci_add_device(dev);
 	}
 	else {
 		struct rte_pci_device *dev2 = NULL;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 			else if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
+				rte_eal_pci_insert_device(dev2, dev);
 				return 0;
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
@@ -337,7 +340,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 				return 0;
 			}
 		}
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+		rte_eal_pci_add_device(dev);
 	}
 
 	return 0;
@@ -365,6 +368,10 @@ rte_eal_pci_scan(void)
 			.matches = &matches[0],
 	};
 
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	fd = open("/dev/pci", O_RDONLY);
 	if (fd < 0) {
 		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
@@ -659,21 +666,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 	return ret;
 }
 
-/* Init the PCI EAL subsystem */
-int
-rte_eal_pci_init(void)
-{
-	/* for debug purposes, PCI can be disabled */
-	if (internal_config.no_pci)
-		return 0;
-
-	if (rte_eal_pci_scan() < 0) {
-		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
-		return -1;
-	}
-	return 0;
-}
-
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_eal_pci_scan,
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
index afa1643..c7c2a05 100644
@@ -6,8 +6,6 @@ DPDK_2.0 {
 	eal_parse_sysfs_value;
 	eal_timer_source;
 	lcore_config;
-	pci_device_list;
-	pci_driver_list;
 	per_lcore__lcore_id;
 	per_lcore__rte_errno;
 	rte_calloc;
lib/librte_eal/common/eal_common_pci.c +11 -15
index c53e2bd..5149e6e 100644
@@ -83,11 +83,6 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list =
-	TAILQ_HEAD_INITIALIZER(pci_driver_list);
-struct pci_device_list pci_device_list =
-	TAILQ_HEAD_INITIALIZER(pci_device_list);
-
 extern struct rte_pci_bus rte_pci_bus;
 
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
@@ -311,7 +306,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	if (dev->driver != NULL)
 		return 0;
 
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+	FOREACH_DRIVER_ON_PCIBUS(dr) {
 		rc = rte_eal_pci_probe_one_driver(dr, dev);
 		if (rc < 0)
 			/* negative value is an error */
@@ -332,6 +327,7 @@ int
 rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 {
 	struct rte_pci_device *dev = NULL;
+
 	int ret = 0;
 
 	if (addr == NULL)
@@ -343,7 +339,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	if (pci_update_device(addr) < 0)
 		goto err_return;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
@@ -373,7 +369,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 	if (addr == NULL)
 		return -1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
@@ -385,7 +381,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 			/* positive value means driver doesn't support it */
 			continue;
 
-		TAILQ_REMOVE(&pci_device_list, dev, next);
+		rte_eal_pci_remove_device(dev);
 		free(dev);
 		return 0;
 	}
@@ -414,7 +410,7 @@ rte_eal_pci_probe(void)
 	if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0)
 		probe_all = 1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 
 		/* set devargs in PCI structure */
 		devargs = pci_devargs_lookup(dev);
@@ -462,7 +458,7 @@ rte_eal_pci_dump(FILE *f)
 {
 	struct rte_pci_device *dev = NULL;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		pci_dump_one_device(f, dev);
 	}
 }
@@ -471,16 +467,16 @@ rte_eal_pci_dump(FILE *f)
 void
 rte_eal_pci_register(struct rte_pci_driver *driver)
 {
-	TAILQ_INSERT_TAIL(&pci_driver_list, driver, next);
-	rte_eal_driver_register(&driver->driver);
+	TAILQ_INSERT_TAIL(&rte_pci_bus.driver_list, driver, next);
+	driver->bus = &rte_pci_bus;
 }
 
 /* unregister a driver */
 void
 rte_eal_pci_unregister(struct rte_pci_driver *driver)
 {
-	rte_eal_driver_unregister(&driver->driver);
-	TAILQ_REMOVE(&pci_driver_list, driver, next);
+	TAILQ_REMOVE(&rte_pci_bus.driver_list, driver, next);
+	driver->bus = NULL;
 }
 
 /* Add a device to PCI bus */
lib/librte_eal/common/eal_private.h +0 -10
index 9e7d8f6..68386e8 100644
@@ -108,16 +108,6 @@ int rte_eal_timer_init(void);
  */
 int rte_eal_log_init(const char *id, int facility);
 
-/**
- * Init the PCI infrastructure
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_init(void);
-
 struct rte_pci_driver;
 struct rte_pci_device;
 
lib/librte_eal/common/include/rte_pci.h +4 -15
index 957cddb..bab8df4 100644
@@ -87,12 +87,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_bus.h>
 
-TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
-TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
-
-extern struct pci_driver_list pci_driver_list; /**< Global list of PCI drivers. */
-extern struct pci_device_list pci_device_list; /**< Global list of PCI devices. */
-
 /** Pathname of PCI devices directory. */
 const char *pci_get_sysfs_path(void);
 
@@ -208,8 +202,6 @@ struct rte_pci_device {
 	.subsystem_device_id = PCI_ANY_ID
 #endif
 
-struct rte_pci_driver;
-
 /**
  * Initialisation function for the driver called during PCI probing.
  */
@@ -416,17 +408,14 @@ rte_pci_match(const struct rte_pci_driver *pci_drv,
 	      const struct rte_pci_device *pci_dev);
 
 /**
- * Probe the PCI bus for registered drivers.
- *
- * Scan the content of the PCI bus, and call the probe() function for
- * all registered drivers that have a matching entry in its id_table
- * for discovered devices.
+ * Probe the PCI bus
  *
  * @return
  *   - 0 on success.
- *   - Negative on error.
+ *   - !0 on error.
  */
-int rte_eal_pci_probe(void);
+int
+rte_eal_pci_probe(void);
 
 /**
  * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -7
index bf6b818..6bb7fc9 100644
@@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0)
 		rte_panic("Cannot init logs\n");
 
-	if (rte_eal_pci_init() < 0)
-		rte_panic("Cannot init PCI\n");
-
 #ifdef VFIO_PRESENT
 	if (rte_eal_vfio_setup() < 0)
 		rte_panic("Cannot init VFIO\n");
@@ -888,10 +885,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe())
-		rte_panic("Cannot probe PCI\n");
-
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
lib/librte_eal/linuxapp/eal/eal_pci.c +14 -24
index c40814d..d6f9855 100644
@@ -55,6 +55,9 @@
  * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it).
  */
 
+/* Forward declaration of PCI bus */
+struct rte_pci_bus rte_pci_bus;
+
 static int
 pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
 {
@@ -347,21 +350,19 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 		dev->kdrv = RTE_KDRV_NONE;
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+	if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+		rte_eal_pci_add_device(dev);
 	} else {
 		struct rte_pci_device *dev2;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 
 			if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
-				rte_eal_device_insert(&dev->device);
+				rte_eal_pci_insert_device(dev2, dev);
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
 				dev2->max_vfs = dev->max_vfs;
@@ -371,8 +372,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 			}
 			return 0;
 		}
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+
+		rte_eal_pci_add_device(dev);
 	}
 
 	return 0;
@@ -448,6 +449,10 @@ rte_eal_pci_scan(void)
 	char dirname[PATH_MAX];
 	struct rte_pci_addr addr;
 
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	dir = opendir(pci_get_sysfs_path());
 	if (dir == NULL) {
 		RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
@@ -464,6 +469,7 @@ rte_eal_pci_scan(void)
 
 		snprintf(dirname, sizeof(dirname), "%s/%s",
 				pci_get_sysfs_path(), e->d_name);
+
 		if (pci_scan_one(dirname, &addr) < 0)
 			goto error;
 	}
@@ -709,22 +715,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 	return ret;
 }
 
-/* Init the PCI EAL subsystem */
-int
-rte_eal_pci_init(void)
-{
-	/* for debug purposes, PCI can be disabled */
-	if (internal_config.no_pci)
-		return 0;
-
-	if (rte_eal_pci_scan() < 0) {
-		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
-		return -1;
-	}
-
-	return 0;
-}
-
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_eal_pci_scan,
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
index b557e7c..84dfbe7 100644
@@ -6,8 +6,6 @@ DPDK_2.0 {
 	eal_parse_sysfs_value;
 	eal_timer_source;
 	lcore_config;
-	pci_device_list;
-	pci_driver_list;
 	per_lcore__lcore_id;
 	per_lcore__rte_errno;
 	rte_calloc;
Signature · 1 line
2.7.0
#119 lore raw

PATCH v11 12/13 pci: use bus driver for attach/detach

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  2 +
 lib/librte_eal/common/eal_common_dev.c  | 56 ++++++++++++++++-----
 lib/librte_eal/common/eal_common_pci.c  | 89 +++++++++++++++++++++++++++++++--
 lib/librte_eal/common/include/rte_bus.h | 31 ++++++++++++
 lib/librte_eal/common/include/rte_pci.h | 45 +++++++++++------
 lib/librte_eal/linuxapp/eal/eal_pci.c   |  2 +
 6 files changed, 193 insertions(+), 32 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
index 103ad70..38a75af 100644
@@ -670,6 +670,8 @@ struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_eal_pci_scan,
 		.probe = rte_eal_pci_probe,
+		.attach = rte_eal_pci_attach,
+		.detach = rte_eal_pci_detach,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
lib/librte_eal/common/eal_common_dev.c +44 -12

94 lines not on this page · raw message

lib/librte_eal/common/eal_common_pci.c +84 -5

111 lines not on this page · raw message

lib/librte_eal/common/include/rte_bus.h +31 -0
index 19954f4..9a096ec 100644
@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);
 /* Bus list exposed */
 extern struct rte_bus_list rte_bus_list;
 
+#define FOREACH_BUS(bus_p)	TAILQ_FOREACH(bus_p, &rte_bus_list, next)
+
 /**
  * Bus specific scan for devices attached on the bus.
  * For each bus object, the scan would be reponsible for finding devices and
@@ -85,6 +87,33 @@ typedef int (*rte_bus_scan_t)(void);
 typedef int (*rte_bus_probe_t)(void);
 
 /**
+ * Attach a device to a bus, assuming it is 'connected' to the bus.
+ * A bus is responsible for scanning for devices. Attaching a new device is
+ * for reenabling the device after being detached/removed.
+ *
+ * @param device_name
+ *	Name of the device to attach.
+ *
+ * @return
+ *	0 for successful attach
+ *	!0 for unsuccessful attach (or incorrect device name)
+ */
+typedef int (*rte_bus_attach_t)(const char *device_name);
+
+/**
+ * Detach a named device from a bus. Implementation would check the existence
+ * of device on the bus and detach it.
+ *
+ * @param device_name
+ *	Name of the device to detach
+ *
+ * @return
+ *	0 for successful detaching
+ *	!0 if device not found or can't detach
+ */
+typedef int (*rte_bus_detach_t)(const char *device_name);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -92,6 +121,8 @@ struct rte_bus {
 	const char *name;            /**< Name of the bus */
 	rte_bus_scan_t scan;         /**< Scan for devices attached to bus */
 	rte_bus_probe_t probe;       /**< Probe devices on bus */
+	rte_bus_attach_t attach;     /**< Attach a named device */
+	rte_bus_detach_t detach;     /**< Detach a named device */
 };
 
 /**
lib/librte_eal/common/include/rte_pci.h +30 -15

57 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/eal_pci.c +2 -0
index d6f9855..01f0c9a 100644
@@ -719,6 +719,8 @@ struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_eal_pci_scan,
 		.probe = rte_eal_pci_probe,
+		.attach = rte_eal_pci_attach,
+		.detach = rte_eal_pci_detach,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
Signature · 1 line
2.7.0
#120 lore raw

Re: [PATCH v11 12/13] pci: use bus driver for attach/detach

Quoted 53 lines · Thomas Monjalon

From: Shreyansh Jain <[email protected]>

Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  2 +
 lib/librte_eal/common/eal_common_dev.c  | 56 ++++++++++++++++-----
 lib/librte_eal/common/eal_common_pci.c  | 89 +++++++++++++++++++++++++++++++--
 lib/librte_eal/common/include/rte_bus.h | 31 ++++++++++++
 lib/librte_eal/common/include/rte_pci.h | 45 +++++++++++------
 lib/librte_eal/linuxapp/eal/eal_pci.c   |  2 +
 6 files changed, 193 insertions(+), 32 deletions(-)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
index 103ad70..38a75af 100644
@@ -670,6 +670,8 @@ struct rte_pci_bus rte_pci_bus = {
        .bus = {
                .scan = rte_eal_pci_scan,
                .probe = rte_eal_pci_probe,
+               .attach = rte_eal_pci_attach,
+               .detach = rte_eal_pci_detach,
        },
        .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
        .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
lib/librte_eal/common/eal_common_dev.c +3 -1
index 4f3b493..97d0cf5 100644
@@ -38,6 +38,7 @@
 #include <sys/queue.h>
 
 #include <rte_dev.h>
+#include <rte_bus.h>
 #include <rte_devargs.h>
 #include <rte_debug.h>
 #include <rte_devargs.h>
@@ -106,23 +107,37 @@ rte_eal_dev_init(void)
 
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
-       struct rte_pci_addr addr;
+       int ret = 1;
+       struct rte_bus *bus;
 
        if (name == NULL || devargs == NULL) {
                RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n");
                return -EINVAL;
        }

lib/librte_eal/common/eal_common_dev.c rte_eal_dev_init(void) · line 124

Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +7 -2
 
-       if (eal_parse_pci_DomBDF(name, &addr) == 0) {
-               if (rte_eal_pci_probe_one(&addr) < 0)
+       FOREACH_BUS(bus) {
+               if (!bus->attach) {
+                       RTE_LOG(DEBUG, EAL, "Bus (%s) doesn't implement"
+                               " attach.\n", bus->name);
+                       continue;
+               }
+               ret = bus->attach(name);

Enforcing a globally unique naming scheme for the low-level device makes this complicated for users. There are buses that enumerate the devices just by an integer so we will have conflicts.

I think it is better to change the signature of rte_eal_dev_attach() instead and find the correct bus based on its name. Also I believe the API is more user friendly if we pass the complete (raw) devargs string instead of the name/args pair.

Quoted 319 lines
lib/librte_eal/common/eal_common_dev.c +34 -9
+               if (!ret) /* device successfully attached */
+                       return ret;
+               if (ret > 0) /* device not found on bus */
+                       continue;
+               else
                        goto err;
+       }
 
-       } else {
-               if (rte_eal_vdev_init(name, devargs))
+       if (ret > 0) {
+               /* In case the device was not found on any bus, search VDEV */
+               ret = rte_eal_vdev_init(name, devargs);
+               if (ret)
                        goto err;
        }
 
-       return 0;
+       return ret;
 
 err:
        RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name);
@@ -131,21 +146,38 @@ int rte_eal_dev_attach(const char *name, const char *devargs)
 
 int rte_eal_dev_detach(const char *name)
 {
-       struct rte_pci_addr addr;
+       int ret = 1;
+       struct rte_bus *bus;
 
        if (name == NULL) {
                RTE_LOG(ERR, EAL, "Invalid device provided.\n");
                return -EINVAL;
        }
 
-       if (eal_parse_pci_DomBDF(name, &addr) == 0) {
-               if (rte_eal_pci_detach(&addr) < 0)
+       FOREACH_BUS(bus) {
+               if (!bus->detach) {
+                       RTE_LOG(DEBUG, EAL, "Bus (%s) doesn't implement"
+                               " detach.\n", bus->name);
+                       continue;
+               }
+
+               ret = bus->detach(name);
+               if (!ret) /* device successfully detached */
+                       return ret;
+               if (ret > 0) /* device not found on the bus */
+                       continue;
+               else
                        goto err;
-       } else {
-               if (rte_eal_vdev_uninit(name))
+       }
+
+       if (ret > 0) {
+               /* In case the device was not found on any bus, search VDEV */
+               ret = rte_eal_vdev_uninit(name);
+               if (ret)
                        goto err;
        }
-       return 0;
+
+       return ret;
 
 err:
        RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name);
lib/librte_eal/common/eal_common_pci.c +84 -5
index 5149e6e..6866b04 100644
@@ -358,19 +358,98 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 }
 
 /*
+ * Attach device specific by its name
+ */
+int
+rte_eal_pci_attach(const char *device_name)
+{
+       struct rte_pci_device *dev = NULL;
+       struct rte_pci_driver *drv = NULL;
+       struct rte_pci_addr addr;
+       int ret;
+
+       if (!device_name)
+               return -1;
+
+       memset(&addr, 0, sizeof(addr));
+       if (eal_parse_pci_DomBDF(device_name, &addr)) {
+               /* Device doesn't match PCI BDF naming format */
+               return 1;
+       }
+
+       if (pci_update_device(&addr) < 0)
+               goto err_return;
+
+       FOREACH_DEVICE_ON_PCIBUS(dev) {
+               if (rte_eal_compare_pci_addr(&dev->addr, &addr))
+                       continue;
+
+               FOREACH_DRIVER_ON_PCIBUS(drv) {
+                       ret = rte_pci_match(drv, dev);
+                       if (ret) {
+                               /* Match of device and driver failed */
+                               RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match"
+                                       " the device (%s)\n", drv->driver.name,
+                                       device_name);
+                               continue;
+                       }
+
+                       RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n",
+                               dev->id.vendor_id, dev->id.device_id,
+                               drv->driver.name);
+
+                       if (drv->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+                               /* map resources for devices that use
+                                * igb_uio
+                                */
+                               ret = rte_eal_pci_map_device(dev);
+                               if (ret != 0)
+                                       goto err_return;
+                       }
+
+                       /* reference driver structure */
+                       dev->driver = drv;
+
+                       /* call the driver probe() function */
+                       ret = drv->probe(drv, dev);
+                       if (ret) {
+                               dev->driver = NULL;
+                               if (drv->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+                                       rte_eal_pci_unmap_device(dev);
+                       }
+                       return ret;
+               }
+       }
+
+       return 1;
+err_return:
+       RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT
+                       " cannot be used\n", dev->addr.domain, dev->addr.bus,
+                       dev->addr.devid, dev->addr.function);
+       return -1;
+}
+
+/*
  * Detach device specified by its pci address.
  */
 int
-rte_eal_pci_detach(const struct rte_pci_addr *addr)
+rte_eal_pci_detach(const char *device_name)
 {
        struct rte_pci_device *dev = NULL;
-       int ret = 0;
+       struct rte_pci_addr addr;
+       int ret = 1;
 
-       if (addr == NULL)
+       if (!device_name)
                return -1;
 
+       memset(&addr, 0, sizeof(addr));
+       if (eal_parse_pci_DomBDF(device_name, &addr)) {
+               /* Device doesn't match PCI BDF naming format */
+               return 1;
+       }
+
        FOREACH_DEVICE_ON_PCIBUS(dev) {
-               if (rte_eal_compare_pci_addr(&dev->addr, addr))
+               if (rte_eal_compare_pci_addr(&dev->addr, &addr))
                        continue;
 
                ret = rte_eal_pci_detach_dev(dev);
@@ -385,8 +464,8 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
                free(dev);
                return 0;
        }
-       return -1;
 
+       return ret;
 err_return:
        RTE_LOG(WARNING, EAL, "Requested device " PCI_PRI_FMT
                        " cannot be used\n", dev->addr.domain, dev->addr.bus,
lib/librte_eal/common/include/rte_bus.h +31 -0
index 19954f4..9a096ec 100644
@@ -59,6 +59,8 @@ TAILQ_HEAD(rte_bus_list, rte_bus);
 /* Bus list exposed */
 extern struct rte_bus_list rte_bus_list;
 
+#define FOREACH_BUS(bus_p)     TAILQ_FOREACH(bus_p, &rte_bus_list, next)
+
 /**
  * Bus specific scan for devices attached on the bus.
  * For each bus object, the scan would be reponsible for finding devices and
@@ -85,6 +87,33 @@ typedef int (*rte_bus_scan_t)(void);
 typedef int (*rte_bus_probe_t)(void);
 
 /**
+ * Attach a device to a bus, assuming it is 'connected' to the bus.
+ * A bus is responsible for scanning for devices. Attaching a new device is
+ * for reenabling the device after being detached/removed.
+ *
+ * @param device_name
+ *     Name of the device to attach.
+ *
+ * @return
+ *     0 for successful attach
+ *     !0 for unsuccessful attach (or incorrect device name)
+ */
+typedef int (*rte_bus_attach_t)(const char *device_name);
+
+/**
+ * Detach a named device from a bus. Implementation would check the existence
+ * of device on the bus and detach it.
+ *
+ * @param device_name
+ *     Name of the device to detach
+ *
+ * @return
+ *     0 for successful detaching
+ *     !0 if device not found or can't detach
+ */
+typedef int (*rte_bus_detach_t)(const char *device_name);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -92,6 +121,8 @@ struct rte_bus {
        const char *name;            /**< Name of the bus */
        rte_bus_scan_t scan;         /**< Scan for devices attached to bus */
        rte_bus_probe_t probe;       /**< Probe devices on bus */
+       rte_bus_attach_t attach;     /**< Attach a named device */
+       rte_bus_detach_t detach;     /**< Detach a named device */
 };
 
 /**
lib/librte_eal/common/include/rte_pci.h +30 -15
index bab8df4..215d732 100644
@@ -418,6 +418,36 @@ int
 rte_eal_pci_probe(void);
 
 /**
+ * Search and attach a PCI device to PCI Bus
+ * Implements rte_bus->attach
+ *
+ * @param device_name
+ *     Name of the device to search and attach
+ *
+ * @return
+ *     0 for successful removal of device
+ *     >0 if device not found on bus
+ *     <0 in case of error in removal.
+ */
+int
+rte_eal_pci_attach(const char *device_name);
+
+/**
+ * Search and detach a PCI device from PCI Bus
+ * Implements rte_bus->detach
+ *
+ * @param device_name
+ *     Name of the device to search and detach
+ *
+ * @return
+ *     0 for successful detaching of device
+ *     >0 if device not found on bus
+ *     <0 in case of error in removal.
+ */
+int
+rte_eal_pci_detach(const char *device_name);
+
+/**
  * Map the PCI device resources in user space virtual memory address
  *
  * Note that driver should not call this function when flag
@@ -491,21 +521,6 @@ void pci_unmap_resource(void *requested_addr, size_t size);
 int rte_eal_pci_probe_one(const struct rte_pci_addr *addr);
 
 /**
- * Close the single PCI device.
- *
- * Scan the content of the PCI bus, and find the pci device specified by pci
- * address, then call the remove() function for registered driver that has a
- * matching entry in its id_table for discovered device.
- *
- * @param addr
- *     The PCI Bus-Device-Function address to close.
- * @return
- *   - 0 on success.
- *   - Negative on error.
- */
-int rte_eal_pci_detach(const struct rte_pci_addr *addr);
-
-/**
  * Dump the content of the PCI bus.
  *
  * @param f
lib/librte_eal/linuxapp/eal/eal_pci.c +2 -1
index d6f9855..01f0c9a 100644
@@ -719,6 +719,8 @@ struct rte_pci_bus rte_pci_bus = {
        .bus = {
                .scan = rte_eal_pci_scan,
                .probe = rte_eal_pci_probe,
+               .attach = rte_eal_pci_attach,
+               .detach = rte_eal_pci_detach,
        },
        .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
        .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
--

2.7.0

#121 lore raw

Re: [PATCH v11 12/13] pci: use bus driver for attach/detach

2017-02-15 12:08, Jan Blunck:

Quoted 21 lines
Quoted 10 lines

int rte_eal_dev_attach(const char *name, const char *devargs) {

lib/librte_eal/common/eal_common_dev.c +2 -1
-       struct rte_pci_addr addr;
+       int ret = 1;
+       struct rte_bus *bus;
 
        if (name == NULL || devargs == NULL) {
                RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n");
                return -EINVAL;
        }

lib/librte_eal/common/eal_common_dev.c rte_eal_dev_init(void) · line 124

Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +7 -2
 
-       if (eal_parse_pci_DomBDF(name, &addr) == 0) {
-               if (rte_eal_pci_probe_one(&addr) < 0)
+       FOREACH_BUS(bus) {
+               if (!bus->attach) {
+                       RTE_LOG(DEBUG, EAL, "Bus (%s) doesn't implement"
+                               " attach.\n", bus->name);
+                       continue;
+               }
+               ret = bus->attach(name);
Quoted 8 lines

Enforcing a globally unique naming scheme for the low-level device makes this complicated for users. There are buses that enumerate the devices just by an integer so we will have conflicts.

I think it is better to change the signature of rte_eal_dev_attach() instead and find the correct bus based on its name. Also I believe the API is more user friendly if we pass the complete (raw) devargs string instead of the name/args pair.

I thought we could have a bus prefix in the name so there is no conflict. How do you imagine the full devargs?

Quoted 8 lines
Quoted 7 lines
lib/librte_eal/common/eal_common_dev.c +6 -0
+               if (!ret) /* device successfully attached */
+                       return ret;
+               if (ret > 0) /* device not found on bus */
+                       continue;
+               else
                        goto err;
+       }
#122 lore raw

Re: [PATCH v11 12/13] pci: use bus driver for attach/detach

Quoted 26 lines · Thomas Monjalon

2017-02-15 12:08, Jan Blunck:

Quoted 25 lines
Quoted 10 lines

int rte_eal_dev_attach(const char *name, const char *devargs) {

lib/librte_eal/common/eal_common_dev.c +2 -1
-       struct rte_pci_addr addr;
+       int ret = 1;
+       struct rte_bus *bus;
 
        if (name == NULL || devargs == NULL) {
                RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n");
                return -EINVAL;
        }

lib/librte_eal/common/eal_common_dev.c rte_eal_dev_init(void) · line 124

Quoted 10 lines
lib/librte_eal/common/eal_common_dev.c +7 -2
 
-       if (eal_parse_pci_DomBDF(name, &addr) == 0) {
-               if (rte_eal_pci_probe_one(&addr) < 0)
+       FOREACH_BUS(bus) {
+               if (!bus->attach) {
+                       RTE_LOG(DEBUG, EAL, "Bus (%s) doesn't implement"
+                               " attach.\n", bus->name);
+                       continue;
+               }
+               ret = bus->attach(name);

Enforcing a globally unique naming scheme for the low-level device makes this complicated for users. There are buses that enumerate the devices just by an integer so we will have conflicts.

Quoted 6 lines
Quoted 4 lines

I think it is better to change the signature of rte_eal_dev_attach() instead and find the correct bus based on its name. Also I believe the API is more user friendly if we pass the complete (raw) devargs string instead of the name/args pair.

I thought we could have a bus prefix in the name so there is no conflict.

Which raises the question of which separator to use. There are some buses like "xen" and "xen-backend" that might clash with a simple prefix. Also it makes is awkward to use for the case where the user is iterating over OS filesystem data structures (directories and files):
the user probably has busname and device identification already separate and needs to snprintf() into another buffer for our API just for us to call sscanf() to extract the busname ...

Quoted 1 line

How do you imagine the full devargs?

I'll send a patch.

#123 lore raw

RFC 1/1 eal: use busname and devargs to attach devices

Using just the device name to attach a device on the EAL level is not enough for a unique identification of the bus it should get attached to. Therefore lets change rte_eal_dev_attach() introduced in 16.11 to take the busname and the raw devargs string.

---
 lib/librte_eal/common/eal_common_dev.c | 61 ++++++++++++++++++++++++++--------
 lib/librte_ether/rte_ethdev.c          | 17 +---------
 2 files changed, 49 insertions(+), 29 deletions(-)
lib/librte_eal/common/eal_common_dev.c +48 -13
index 4bde430..bf41a94 100644
@@ -37,6 +37,7 @@
 #include <inttypes.h>
 #include <sys/queue.h>
 
+#include <rte_bus.h>
 #include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_debug.h>
@@ -76,29 +77,63 @@ void rte_eal_device_remove(struct rte_device *dev)
 	TAILQ_REMOVE(&dev_device_list, dev, next);
 }
 
-int rte_eal_dev_attach(const char *name, const char *devargs)
+int rte_eal_dev_attach(const char *busname, const char *devargs)
 {
-	struct rte_pci_addr addr;
+	struct rte_bus *bus;
+	rte_bus_attach_t attach;
+	int ret;
 
-	if (name == NULL || devargs == NULL) {
+	if (busname == NULL || devargs == NULL) {
 		RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n");
 		return -EINVAL;
 	}
 
-	if (eal_parse_pci_DomBDF(name, &addr) == 0) {
-		if (rte_eal_pci_probe_one(&addr) < 0)
-			goto err;
+	if (!busname) {
+		char *name, *args;
+		struct rte_pci_addr addr;
 
-	} else {
-		if (rte_eal_vdev_init(name, devargs))
-			goto err;
+		/*
+		 * We default to virtual device but lets check for PCI device format for
+		 * backwards compatibility reasons.
+		 */
+		busname = "virtual";
+
+		if (rte_eal_parse_devargs_str(devargs, &name, &args))
+			return -EINVAL;
+
+		if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+			RTE_LOG(ERR, EAL, "Deprectated\n");
+			busname = "pci";
+		}
+
+		free(name);
+		free(args);
 	}
 
-	return 0;
+	bus = rte_bus_find_by_name(busname);
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "Can't find bus (%s)\n", busname);
+		return -EINVAL;
+	}
 
-err:
-	RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name);
-	return -EINVAL;
+	attach = bus->attach;
+	if (!attach) {
+		RTE_LOG(ERR, EAL, "Function not supported\n");
+		return -ENOTSUP;
+	}
+
+	ret = attach(devargs);
+	if (ret) {
+		RTE_LOG(ERR, EAL, "Attaching device to bus failed \n");
+		return ret;
+	}
+
+	/*
+	 * Probing might fail because some devices are not claimed by any driver
+	 * but we don't care: the device is properly attached at this point.
+	 */
+	(void)bus->probe();
+	return 0;
 }
 
 int rte_eal_dev_detach(const char *name)
lib/librte_ether/rte_ethdev.c +1 -16
index eb0a94a..bbebc8f 100644
@@ -474,29 +474,16 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 {
 	int ret = -1;
 	int current = rte_eth_dev_count();
-	char *name = NULL;
-	char *args = NULL;
 
 	if ((devargs == NULL) || (port_id == NULL)) {
 		ret = -EINVAL;
 		goto err;
 	}
 
-	/* parse devargs, then retrieve device name and args */
-	if (rte_eal_parse_devargs_str(devargs, &name, &args))
-		goto err;
-
-	ret = rte_eal_dev_attach(name, args);
+	ret = rte_eal_dev_attach(NULL, devargs);
 	if (ret < 0)
 		goto err;
 
-	/* no point looking at the port count if no port exists */
-	if (!rte_eth_dev_count()) {
-		RTE_LOG(ERR, EAL, "No port found for device (%s)\n", name);
-		ret = -1;
-		goto err;
-	}
-
 	/* if nothing happened, there is a bug here, since some driver told us
 	 * it did attach a device, but did not create a port.
 	 */
@@ -509,8 +496,6 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 	ret = 0;
 
 err:
-	free(name);
-	free(args);
 	return ret;
 }
 
Signature · 1 line
2.7.4
#124 lore raw

PATCH v11 13/13 doc: remove deprecation notice for rte_bus

In reply to Thomas Monjalon

From: Shreyansh Jain <[email protected]>

---
 doc/guides/rel_notes/deprecation.rst   | 5 -----
 doc/guides/rel_notes/release_17_02.rst | 2 +-
 lib/librte_eal/bsdapp/eal/Makefile     | 2 +-
 lib/librte_eal/linuxapp/eal/Makefile   | 2 +-
 4 files changed, 3 insertions(+), 8 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -5
index 755dc65..a9b0aef 100644
@@ -13,11 +13,6 @@ Deprecation Notices
   has exposed, like the way we have done with uio-pci-generic. This change
   targets release 17.02.
 
-* ABI/API changes are planned for 17.02: ``rte_device``, ``rte_driver`` will be
-  impacted because of introduction of a new ``rte_bus`` hierarchy. This would
-  also impact the way devices are identified by EAL. A bus-device-driver model
-  will be introduced providing a hierarchical view of devices.
-
 * ``eth_driver`` is planned to be removed in 17.02. This currently serves as
   a placeholder for PMDs to register themselves. Changes for ``rte_bus`` will
   provide a way to handle device initialization currently being done in
doc/guides/rel_notes/release_17_02.rst +1 -1
index 0ecd720..666f386 100644
@@ -326,7 +326,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_cmdline.so.2
      librte_cryptodev.so.2
      librte_distributor.so.1
-     librte_eal.so.3
+   + librte_eal.so.4
    + librte_ethdev.so.6
      librte_hash.so.2
      librte_ip_frag.so.1
lib/librte_eal/bsdapp/eal/Makefile +1 -1
index cce99f7..63c1fda 100644
@@ -48,7 +48,7 @@ LDLIBS += -lgcc_s
 
 EXPORT_MAP := rte_eal_version.map
 
-LIBABIVER := 3
+LIBABIVER := 4
 
 # specific to bsdapp exec-env
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) := eal.c
lib/librte_eal/linuxapp/eal/Makefile +1 -1
index aa874a5..88fdc43 100644
@@ -37,7 +37,7 @@ ARCH_DIR ?= $(RTE_ARCH)
 EXPORT_MAP := rte_eal_version.map
 VPATH += $(RTE_SDK)/lib/librte_eal/common/arch/$(ARCH_DIR)
 
-LIBABIVER := 3
+LIBABIVER := 4
 
 VPATH += $(RTE_SDK)/lib/librte_eal/common
 
Signature · 1 line
2.7.0
Acked-by on v11 13/13
#125 lore raw

Re: [PATCH v11 13/13] doc: remove deprecation notice for rte_bus

Quoted 10 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Thursday, January 19, 2017 4:45 AM
To: Shreyansh Jain <[email protected]>
Cc: [email protected]
Subject: [dpdk-dev] [PATCH v11 13/13] doc: remove deprecation notice for rte_bus

Quoted 3 lines

From: Shreyansh Jain <[email protected]>

#126 lore raw

Re: [PATCH v11 00/13] rte_bus + rte_pci_bus

In reply to Thomas Monjalon

2017-01-19 05:45, Thomas Monjalon:

Quoted 13 lines

Unfortunately, it is not ready to be integrated in 17.02. More specifically:
- the tests need some review/rework
- the PCI implementation requires more work
- the documentation must be updated

However there are some new buses waiting for the bus abstraction, which is simple and good enough.
That's why I have isolated the generic bus model in first patches and will apply them in 17.02-rc1. It will allow to base new buses on top of rte_bus.

Quoted 4 lines

Shreyansh Jain (13):
bus: introduce bus abstraction
bus: add scanning
bus: add probing

First 3 patches applied.

I'll continue to work with Shreyansh on PCI implementation. Some help is required to convert VDEV into a bus driver.

Quoted 10 lines

app/test: check bus registration
app/test: check bus scan
app/test: check bus probe
pci: split match and probe
pci: remove loop over drivers in device detach
pci: add bus driver
app/test: add PCI bus driver
pci: use bus driver for scan/probe
pci: use bus driver for attach/detach
doc: remove deprecation notice for rte_bus

#127 lore raw

v12 cover rte_bus_pci

In reply to Thomas Monjalon

I have rebased the work done by Shreyansh and Thomas to follow the bus abstraction introduced in v17.02 for the PCI bus implementation.
This series is only a partial version of the previous one, because some of the patches have already been integrated, and others still need rework.

changes in v12:
- Change the rte_pci_match function semantic to match its name.
- Make the rte_pci_match function private.
- Removed the PCI tests. They cannot follow the bus implementation anymore, and it is an opportunity to update their original design.

Additional work is needed:
- The PCI bus should be moved to the relevant bus sub-directory.
- The documentation must be updated.

But this version should allow for the PCI bus implementation to be integrated in v17.05-rc2.

Gaetan Rivet (1):
test: remove pci tests

Shreyansh Jain (4):
pci: split match and probe
pci: remove loop over drivers in device detach
pci: add bus driver
pci: use bus driver for scan/probe

 MAINTAINERS                                        |   2 -
 lib/librte_eal/bsdapp/eal/eal.c                    |  14 -
 lib/librte_eal/bsdapp/eal/eal_pci.c                |  42 +--
 lib/librte_eal/bsdapp/eal/rte_eal_version.map      |   2 -
 lib/librte_eal/common/eal_common_pci.c             | 260 +++++++++--------
 lib/librte_eal/common/eal_private.h                |  10 -
 lib/librte_eal/common/include/rte_pci.h            |  84 +++++-
 lib/librte_eal/linuxapp/eal/eal.c                  |  14 -
 lib/librte_eal/linuxapp/eal/eal_pci.c              |  46 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map    |   2 -
 test/test/Makefile                                 |   2 -
 test/test/test.h                                   |   3 -
 test/test/test_mp_secondary.c                      |  17 --
 test/test/test_pci.c                               | 322 ---------------------
 .../bus/pci/devices/0000:01:00.0/class             |   1 -
 .../bus/pci/devices/0000:01:00.0/config            | Bin 64 -> 0 bytes
 .../devices/0000:01:00.0/consistent_dma_mask_bits  |   1 -
 .../bus/pci/devices/0000:01:00.0/device            |   1 -
 .../bus/pci/devices/0000:01:00.0/dma_mask_bits     |   1 -
 .../bus/pci/devices/0000:01:00.0/enable            |   1 -
 .../bus/pci/devices/0000:01:00.0/irq               |   1 -
 .../bus/pci/devices/0000:01:00.0/modalias          |   1 -
 .../bus/pci/devices/0000:01:00.0/msi_bus           |   1 -
 .../bus/pci/devices/0000:01:00.0/numa_node         |   1 -
 .../bus/pci/devices/0000:01:00.0/resource          |  13 -
 .../bus/pci/devices/0000:01:00.0/sriov_numvfs      |   1 -
 .../bus/pci/devices/0000:01:00.0/sriov_totalvfs    |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:00.0/uevent            |   6 -
 .../bus/pci/devices/0000:01:00.0/vendor            |   1 -
 .../bus/pci/devices/0000:01:02.0/class             |   1 -
 .../bus/pci/devices/0000:01:02.0/device            |   1 -
 .../bus/pci/devices/0000:01:02.0/resource          |  13 -
 .../bus/pci/devices/0000:01:02.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:02.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:02.0/vendor            |   1 -
 .../bus/pci/devices/0000:02:ab.0/class             |   1 -
 .../bus/pci/devices/0000:02:ab.0/device            |   1 -
 .../bus/pci/devices/0000:02:ab.0/resource          |  13 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:02:ab.0/vendor            |   1 -
 43 files changed, 251 insertions(+), 638 deletions(-)
 delete mode 100644 test/test/test_pci.c
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/vendor
Signature · 1 line
2.1.4
#128 lore raw

PATCH v12 1/5 pci: split match and probe

From: Shreyansh Jain <[email protected]>

Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).

Refactor the match logic as a single function.

---
 lib/librte_eal/common/eal_common_pci.c | 176 ++++++++++++++++++---------------
 1 file changed, 98 insertions(+), 78 deletions(-)
lib/librte_eal/common/eal_common_pci.c +98 -78
index 1ab92c9..83a81c4 100644
@@ -154,73 +154,108 @@ pci_unmap_resource(void *requested_addr, size_t size)
 }
 
 /*
- * If vendor/device ID match, call the probe() function of the
- * driver.
+ * Match the PCI Driver and Device using the ID Table
+ *
+ * @param pci_drv
+ *	PCI driver from which ID table would be extracted
+ * @param pci_dev
+ *	PCI device to match against the driver
+ * @return
+ *	1 for successful match
+ *	0 for unsuccessful match
  */
 static int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+	      const struct rte_pci_device *pci_dev)
 {
-	int ret;
 	const struct rte_pci_id *id_table;
 
-	for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
-
+	for (id_table = pci_drv->id_table; id_table->vendor_id != 0;
+	     id_table++) {
 		/* check if device's identifiers match the driver's ones */
-		if (id_table->vendor_id != dev->id.vendor_id &&
+		if (id_table->vendor_id != pci_dev->id.vendor_id &&
 				id_table->vendor_id != PCI_ANY_ID)
 			continue;
-		if (id_table->device_id != dev->id.device_id &&
+		if (id_table->device_id != pci_dev->id.device_id &&
 				id_table->device_id != PCI_ANY_ID)
 			continue;
-		if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-				id_table->subsystem_vendor_id != PCI_ANY_ID)
+		if (id_table->subsystem_vendor_id !=
+		    pci_dev->id.subsystem_vendor_id &&
+		    id_table->subsystem_vendor_id != PCI_ANY_ID)
 			continue;
-		if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-				id_table->subsystem_device_id != PCI_ANY_ID)
+		if (id_table->subsystem_device_id !=
+		    pci_dev->id.subsystem_device_id &&
+		    id_table->subsystem_device_id != PCI_ANY_ID)
 			continue;
-		if (id_table->class_id != dev->id.class_id &&
+		if (id_table->class_id != pci_dev->id.class_id &&
 				id_table->class_id != RTE_CLASS_ANY_ID)
 			continue;
 
-		struct rte_pci_addr *loc = &dev->addr;
+		return 1;
+	}
 
-		RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->device.numa_node);
+	return 0;
+}
 
-		/* no initialization when blacklisted, return without error */
-		if (dev->device.devargs != NULL &&
-			dev->device.devargs->type ==
-				RTE_DEVTYPE_BLACKLISTED_PCI) {
-			RTE_LOG(INFO, EAL, "  Device is blacklisted, not initializing\n");
-			return 1;
-		}
+/*
+ * If vendor/device ID match, call the probe() function of the
+ * driver.
+ */
+static int
+rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
+			     struct rte_pci_device *dev)
+{
+	int ret;
+	struct rte_pci_addr *loc;
 
-		RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->driver.name);
+	if ((dr == NULL) || (dev == NULL))
+		return -EINVAL;
 
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio or VFIO */
-			ret = rte_eal_pci_map_device(dev);
-			if (ret != 0)
-				return ret;
-		}
+	loc = &dev->addr;
 
-		/* reference driver structure */
-		dev->driver = dr;
+	/* The device is not blacklisted; Check if driver supports it */
+	if (!rte_pci_match(dr, dev)) {
+		/* Match of device and driver failed */
+		RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n",
+			dr->driver.name);
+		return 1;
+	}
 
-		/* call the driver probe() function */
-		ret = dr->probe(dr, dev);
-		if (ret) {
-			dev->driver = NULL;
-			if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-				rte_eal_pci_unmap_device(dev);
-		}
+	RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+			loc->domain, loc->bus, loc->devid, loc->function,
+			dev->device.numa_node);
+
+	/* no initialization when blacklisted, return without error */
+	if (dev->device.devargs != NULL &&
+		dev->device.devargs->type ==
+			RTE_DEVTYPE_BLACKLISTED_PCI) {
+		RTE_LOG(INFO, EAL, "  Device is blacklisted, not"
+			" initializing\n");
+		return 1;
+	}
 
-		return ret;
+	RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+		dev->id.device_id, dr->driver.name);
+
+	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+		/* map resources for devices that use igb_uio */
+		ret = rte_eal_pci_map_device(dev);
+		if (ret != 0)
+			return ret;
 	}
-	/* return positive value if driver doesn't support this device */
-	return 1;
+
+	/* reference driver structure */
+	dev->driver = dr;
+
+	/* call the driver probe() function */
+	ret = dr->probe(dr, dev);
+	if (ret) {
+		dev->driver = NULL;
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+			rte_eal_pci_unmap_device(dev);
+	}
+
+	return ret;
 }
 
 /*
@@ -231,51 +266,36 @@ static int
 rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
 		struct rte_pci_device *dev)
 {
-	const struct rte_pci_id *id_table;
+	struct rte_pci_addr *loc;
 
 	if ((dr == NULL) || (dev == NULL))
 		return -EINVAL;
 
-	for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
-
-		/* check if device's identifiers match the driver's ones */
-		if (id_table->vendor_id != dev->id.vendor_id &&
-				id_table->vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->device_id != dev->id.device_id &&
-				id_table->device_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-				id_table->subsystem_vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-				id_table->subsystem_device_id != PCI_ANY_ID)
-			continue;
-
-		struct rte_pci_addr *loc = &dev->addr;
+	if (!rte_pci_match(dr, dev)) {
+		/* Device and driver don't match */
+		return 1;
+	}
 
-		RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-				loc->domain, loc->bus, loc->devid,
-				loc->function, dev->device.numa_node);
+	loc = &dev->addr;
 
-		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->driver.name);
+	RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+			loc->domain, loc->bus, loc->devid,
+			loc->function, dev->device.numa_node);
 
-		if (dr->remove && (dr->remove(dev) < 0))
-			return -1;	/* negative value is an error */
+	RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+			dev->id.device_id, dr->driver.name);
 
-		/* clear driver structure */
-		dev->driver = NULL;
+	if (dr->remove && (dr->remove(dev) < 0))
+		return -1;	/* negative value is an error */
 
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-			/* unmap resources for devices that use igb_uio */
-			rte_eal_pci_unmap_device(dev);
+	/* clear driver structure */
+	dev->driver = NULL;
 
-		return 0;
-	}
+	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+		/* unmap resources for devices that use igb_uio */
+		rte_eal_pci_unmap_device(dev);
 
-	/* return positive value if driver doesn't support this device */
-	return 1;
+	return 0;
 }
 
 /*
Signature · 1 line
2.1.4
#129 lore raw

PATCH v12 2/5 pci: remove loop over drivers in device detach

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

rte_eal_pci_detach calls pci_detach_all_drivers which loops over all PCI drivers for detaching the device. This is unnecessary as the device already has the PCI driver reference which can be used directly.

Removing pci_detach_all_drivers and restructuring rte_eal_pci_detach and rte_eal_pci_detach_dev to work without looping over driver list.

---
 lib/librte_eal/common/eal_common_pci.c | 45 +++++++---------------------------
 1 file changed, 9 insertions(+), 36 deletions(-)
lib/librte_eal/common/eal_common_pci.c +9 -36
index 83a81c4..498a3bb 100644
@@ -263,19 +263,15 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
  * driver.
  */
 static int
-rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev)
+rte_eal_pci_detach_dev(struct rte_pci_device *dev)
 {
 	struct rte_pci_addr *loc;
+	struct rte_pci_driver *dr;
 
-	if ((dr == NULL) || (dev == NULL))
+	if (dev == NULL)
 		return -EINVAL;
 
-	if (!rte_pci_match(dr, dev)) {
-		/* Device and driver don't match */
-		return 1;
-	}
-
+	dr = dev->driver;
 	loc = &dev->addr;
 
 	RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
@@ -330,33 +326,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 }
 
 /*
- * If vendor/device ID match, call the remove() function of all
- * registered driver for the given device. Return -1 if initialization
- * failed, return 1 if no driver is found for this device.
- */
-static int
-pci_detach_all_drivers(struct rte_pci_device *dev)
-{
-	struct rte_pci_driver *dr = NULL;
-	int rc = 0;
-
-	if (dev == NULL)
-		return -1;
-
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
-		rc = rte_eal_pci_detach_dev(dr, dev);
-		if (rc < 0)
-			/* negative value is an error */
-			return -1;
-		if (rc > 0)
-			/* positive value means driver doesn't support it */
-			continue;
-		return 0;
-	}
-	return 1;
-}
-
-/*
  * Find the pci device specified by pci address, then invoke probe function of
  * the driver of the devive.
  */
@@ -409,9 +378,13 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
-		ret = pci_detach_all_drivers(dev);
+		ret = rte_eal_pci_detach_dev(dev);
 		if (ret < 0)
+			/* negative value is an error */
 			goto err_return;
+		if (ret > 0)
+			/* positive value means driver doesn't support it */
+			continue;
 
 		TAILQ_REMOVE(&pci_device_list, dev, next);
 		free(dev);
Signature · 1 line
2.1.4
#130 lore raw

PATCH v12 3/5 pci: add bus driver

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

Based on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch.

EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c     | 11 ++++++
 lib/librte_eal/common/eal_common_pci.c  | 25 +++++++++++++
 lib/librte_eal/common/include/rte_pci.h | 65 +++++++++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c   | 12 ++++++
 4 files changed, 113 insertions(+)
lib/librte_eal/bsdapp/eal/eal_pci.c +11 -0
index 16a1743..06b5a3a 100644
@@ -675,3 +675,14 @@ rte_eal_pci_init(void)
 	}
 	return 0;
 }
+
+struct rte_pci_bus rte_pci_bus = {
+	.bus = {
+		.scan = rte_eal_pci_scan,
+		.probe = rte_eal_pci_probe,
+	},
+	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
+};
+
+RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
lib/librte_eal/common/eal_common_pci.c +25 -0
index 498a3bb..853a12c 100644
@@ -72,6 +72,7 @@
 #include <rte_errno.h>
 #include <rte_interrupts.h>
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
@@ -88,6 +89,8 @@ struct pci_driver_list pci_driver_list =
 struct pci_device_list pci_device_list =
 	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
+extern struct rte_pci_bus rte_pci_bus;
+
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 
 const char *pci_get_sysfs_path(void)
@@ -489,3 +492,25 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)
 	rte_eal_driver_unregister(&driver->driver);
 	TAILQ_REMOVE(&pci_driver_list, driver, next);
 }
+
+/* Add a device to PCI bus */
+void
+rte_eal_pci_add_device(struct rte_pci_device *pci_dev)
+{
+	TAILQ_INSERT_TAIL(&rte_pci_bus.device_list, pci_dev, next);
+}
+
+/* Insert a device into a predefined position in PCI bus */
+void
+rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev,
+			  struct rte_pci_device *new_pci_dev)
+{
+	TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next);
+}
+
+/* Remove a device from PCI bus */
+void
+rte_eal_pci_remove_device(struct rte_pci_device *pci_dev)
+{
+	TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next);
+}
lib/librte_eal/common/include/rte_pci.h +65 -0

95 lines not on this page · raw message

lib/librte_eal/linuxapp/eal/eal_pci.c +12 -0
index 7d6f50a..979b6f3 100644
@@ -35,6 +35,7 @@
 #include <dirent.h>
 
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
@@ -728,3 +729,14 @@ rte_eal_pci_init(void)
 
 	return 0;
 }
+
+struct rte_pci_bus rte_pci_bus = {
+	.bus = {
+		.scan = rte_eal_pci_scan,
+		.probe = rte_eal_pci_probe,
+	},
+	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
+};
+
+RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
Signature · 1 line
2.1.4
#131 lore raw

PATCH v12 4/5 pci: use bus driver for scan/probe

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

Remove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.

---
 lib/librte_eal/bsdapp/eal/eal.c                 | 14 ---------
 lib/librte_eal/bsdapp/eal/eal_pci.c             | 35 ++++++++---------------
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 --
 lib/librte_eal/common/eal_common_pci.c          | 26 +++++++----------
 lib/librte_eal/common/eal_private.h             | 10 -------
 lib/librte_eal/common/include/rte_pci.h         | 19 +++----------
 lib/librte_eal/linuxapp/eal/eal.c               | 14 ---------
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 38 +++++++++----------------
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 --
 9 files changed, 41 insertions(+), 119 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -14
index fae6c7e..7321ac6 100644
@@ -602,13 +602,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	if (rte_eal_pci_init() < 0) {
-		rte_eal_init_alert("Cannot init PCI\n");
-		rte_errno = EPROTO;
-		rte_atomic32_clear(&run_once);
-		return -1;
-	}
-
 	eal_check_mem_on_local_socket();
 
 	if (eal_plugins_init() < 0)
@@ -667,13 +660,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe()) {
-		rte_eal_init_alert("Cannot probe PCI\n");
-		rte_errno = ENOTSUP;
-		return -1;
-	}
-
 	if (rte_eal_dev_init() < 0)
 		rte_eal_init_alert("Cannot init pmd devices\n");
 
lib/librte_eal/bsdapp/eal/eal_pci.c +12 -23
index 06b5a3a..f796ef6 100644
@@ -87,6 +87,9 @@
  * enabling bus master.
  */
 
+/* Forward declaration of PCI bus */
+struct rte_pci_bus rte_pci_bus;
+
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
@@ -313,21 +316,19 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	}
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+	if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+		rte_eal_pci_add_device(dev);
 	}
 	else {
 		struct rte_pci_device *dev2 = NULL;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 			else if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
-				rte_eal_device_insert(&dev->device);
+				rte_eal_pci_insert_device(dev2, dev);
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
 				dev2->max_vfs = dev->max_vfs;
@@ -338,8 +339,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 			}
 			return 0;
 		}
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+		rte_eal_pci_add_device(dev);
 	}
 
 	return 0;
@@ -367,6 +367,10 @@ rte_eal_pci_scan(void)
 			.matches = &matches[0],
 	};
 
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	fd = open("/dev/pci", O_RDONLY);
 	if (fd < 0) {
 		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
@@ -661,21 +665,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 	return ret;
 }
 
-/* Init the PCI EAL subsystem */
-int
-rte_eal_pci_init(void)
-{
-	/* for debug purposes, PCI can be disabled */
-	if (internal_config.no_pci)
-		return 0;
-
-	if (rte_eal_pci_scan() < 0) {
-		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
-		return -1;
-	}
-	return 0;
-}
-
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_eal_pci_scan,
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
index e1fbebc..ca12d89 100644
@@ -6,8 +6,6 @@ DPDK_2.0 {
 	eal_parse_sysfs_value;
 	eal_timer_source;
 	lcore_config;
-	pci_device_list;
-	pci_driver_list;
 	per_lcore__lcore_id;
 	per_lcore__rte_errno;
 	rte_calloc;
lib/librte_eal/common/eal_common_pci.c +11 -15
index 853a12c..02d92b9 100644
@@ -84,11 +84,6 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list =
-	TAILQ_HEAD_INITIALIZER(pci_driver_list);
-struct pci_device_list pci_device_list =
-	TAILQ_HEAD_INITIALIZER(pci_device_list);
-
 extern struct rte_pci_bus rte_pci_bus;
 
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
@@ -315,7 +310,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	if (dev->driver != NULL)
 		return 0;
 
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+	FOREACH_DRIVER_ON_PCIBUS(dr) {
 		rc = rte_eal_pci_probe_one_driver(dr, dev);
 		if (rc < 0)
 			/* negative value is an error */
@@ -336,6 +331,7 @@ int
 rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 {
 	struct rte_pci_device *dev = NULL;
+
 	int ret = 0;
 
 	if (addr == NULL)
@@ -347,7 +343,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	if (pci_update_device(addr) < 0)
 		goto err_return;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
@@ -377,7 +373,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 	if (addr == NULL)
 		return -1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
@@ -389,7 +385,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 			/* positive value means driver doesn't support it */
 			continue;
 
-		TAILQ_REMOVE(&pci_device_list, dev, next);
+		rte_eal_pci_remove_device(dev);
 		free(dev);
 		return 0;
 	}
@@ -419,7 +415,7 @@ rte_eal_pci_probe(void)
 	if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0)
 		probe_all = 1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		probed++;
 
 		/* set devargs in PCI structure */
@@ -472,7 +468,7 @@ rte_eal_pci_dump(FILE *f)
 {
 	struct rte_pci_device *dev = NULL;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		pci_dump_one_device(f, dev);
 	}
 }
@@ -481,16 +477,16 @@ rte_eal_pci_dump(FILE *f)
 void
 rte_eal_pci_register(struct rte_pci_driver *driver)
 {
-	TAILQ_INSERT_TAIL(&pci_driver_list, driver, next);
-	rte_eal_driver_register(&driver->driver);
+	TAILQ_INSERT_TAIL(&rte_pci_bus.driver_list, driver, next);
+	driver->bus = &rte_pci_bus;
 }
 
 /* unregister a driver */
 void
 rte_eal_pci_unregister(struct rte_pci_driver *driver)
 {
-	rte_eal_driver_unregister(&driver->driver);
-	TAILQ_REMOVE(&pci_driver_list, driver, next);
+	TAILQ_REMOVE(&rte_pci_bus.driver_list, driver, next);
+	driver->bus = NULL;
 }
 
 /* Add a device to PCI bus */
lib/librte_eal/common/eal_private.h +0 -10
index 8b2d323..260dcbb 100644
@@ -109,16 +109,6 @@ int rte_eal_timer_init(void);
  */
 int rte_eal_log_init(const char *id, int facility);
 
-/**
- * Init the PCI infrastructure
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_init(void);
-
 struct rte_pci_driver;
 struct rte_pci_device;
 
lib/librte_eal/common/include/rte_pci.h +4 -15
index 6984fd5..f8d6fcb 100644
@@ -87,12 +87,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_bus.h>
 
-TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
-TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
-
-extern struct pci_driver_list pci_driver_list; /**< Global list of PCI drivers. */
-extern struct pci_device_list pci_device_list; /**< Global list of PCI devices. */
-
 /** Pathname of PCI devices directory. */
 const char *pci_get_sysfs_path(void);
 
@@ -208,8 +202,6 @@ struct rte_pci_device {
 	.subsystem_device_id = PCI_ANY_ID
 #endif
 
-struct rte_pci_driver;
-
 /**
  * Initialisation function for the driver called during PCI probing.
  */
@@ -401,17 +393,14 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
 int rte_eal_pci_scan(void);
 
 /**
- * Probe the PCI bus for registered drivers.
- *
- * Scan the content of the PCI bus, and call the probe() function for
- * all registered drivers that have a matching entry in its id_table
- * for discovered devices.
+ * Probe the PCI bus
  *
  * @return
  *   - 0 on success.
- *   - Negative on error.
+ *   - !0 on error.
  */
-int rte_eal_pci_probe(void);
+int
+rte_eal_pci_probe(void);
 
 /**
  * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -14
index d98d56d..7cf33d6 100644
@@ -830,13 +830,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	if (rte_eal_pci_init() < 0) {
-		rte_eal_init_alert("Cannot init PCI\n");
-		rte_errno = EPROTO;
-		rte_atomic32_clear(&run_once);
-		return -1;
-	}
-
 #ifdef VFIO_PRESENT
 	if (rte_eal_vfio_setup() < 0) {
 		rte_eal_init_alert("Cannot init VFIO\n");
@@ -946,13 +939,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe()) {
-		rte_eal_init_alert("Cannot probe PCI\n");
-		rte_errno = ENOTSUP;
-		return -1;
-	}
-
 	if (rte_eal_dev_init() < 0)
 		rte_eal_init_alert("Cannot init pmd devices\n");
 
lib/librte_eal/linuxapp/eal/eal_pci.c +14 -24
index 979b6f3..858d36b 100644
@@ -55,6 +55,9 @@
  * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it).
  */
 
+/* Forward declaration of PCI bus */
+struct rte_pci_bus rte_pci_bus;
+
 static int
 pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
 {
@@ -352,21 +355,19 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 		dev->kdrv = RTE_KDRV_NONE;
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+	if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+		rte_eal_pci_add_device(dev);
 	} else {
 		struct rte_pci_device *dev2;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 
 			if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
-				rte_eal_device_insert(&dev->device);
+				rte_eal_pci_insert_device(dev2, dev);
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
 				dev2->max_vfs = dev->max_vfs;
@@ -376,8 +377,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 			}
 			return 0;
 		}
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+
+		rte_eal_pci_add_device(dev);
 	}
 
 	return 0;
@@ -453,6 +454,10 @@ rte_eal_pci_scan(void)
 	char dirname[PATH_MAX];
 	struct rte_pci_addr addr;
 
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	dir = opendir(pci_get_sysfs_path());
 	if (dir == NULL) {
 		RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
@@ -469,6 +474,7 @@ rte_eal_pci_scan(void)
 
 		snprintf(dirname, sizeof(dirname), "%s/%s",
 				pci_get_sysfs_path(), e->d_name);
+
 		if (pci_scan_one(dirname, &addr) < 0)
 			goto error;
 	}
@@ -714,22 +720,6 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 	return ret;
 }
 
-/* Init the PCI EAL subsystem */
-int
-rte_eal_pci_init(void)
-{
-	/* for debug purposes, PCI can be disabled */
-	if (internal_config.no_pci)
-		return 0;
-
-	if (rte_eal_pci_scan() < 0) {
-		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
-		return -1;
-	}
-
-	return 0;
-}
-
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_eal_pci_scan,
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
index d5d05ee..94da1e7 100644
@@ -6,8 +6,6 @@ DPDK_2.0 {
 	eal_parse_sysfs_value;
 	eal_timer_source;
 	lcore_config;
-	pci_device_list;
-	pci_driver_list;
 	per_lcore__lcore_id;
 	per_lcore__rte_errno;
 	rte_calloc;
Signature · 1 line
2.1.4
#132 lore raw

PATCH v12 5/5 test: remove pci tests

In reply to Gaetan Rivet

These tests are not suited for the rte_bus PCI implementation anymore.

---
 MAINTAINERS                                        |   2 -
 test/test/Makefile                                 |   2 -
 test/test/test.h                                   |   3 -
 test/test/test_mp_secondary.c                      |  17 --
 test/test/test_pci.c                               | 322 ---------------------
 .../bus/pci/devices/0000:01:00.0/class             |   1 -
 .../bus/pci/devices/0000:01:00.0/config            | Bin 64 -> 0 bytes
 .../devices/0000:01:00.0/consistent_dma_mask_bits  |   1 -
 .../bus/pci/devices/0000:01:00.0/device            |   1 -
 .../bus/pci/devices/0000:01:00.0/dma_mask_bits     |   1 -
 .../bus/pci/devices/0000:01:00.0/enable            |   1 -
 .../bus/pci/devices/0000:01:00.0/irq               |   1 -
 .../bus/pci/devices/0000:01:00.0/modalias          |   1 -
 .../bus/pci/devices/0000:01:00.0/msi_bus           |   1 -
 .../bus/pci/devices/0000:01:00.0/numa_node         |   1 -
 .../bus/pci/devices/0000:01:00.0/resource          |  13 -
 .../bus/pci/devices/0000:01:00.0/sriov_numvfs      |   1 -
 .../bus/pci/devices/0000:01:00.0/sriov_totalvfs    |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:00.0/uevent            |   6 -
 .../bus/pci/devices/0000:01:00.0/vendor            |   1 -
 .../bus/pci/devices/0000:01:02.0/class             |   1 -
 .../bus/pci/devices/0000:01:02.0/device            |   1 -
 .../bus/pci/devices/0000:01:02.0/resource          |  13 -
 .../bus/pci/devices/0000:01:02.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:02.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:02.0/vendor            |   1 -
 .../bus/pci/devices/0000:02:ab.0/class             |   1 -
 .../bus/pci/devices/0000:02:ab.0/device            |   1 -
 .../bus/pci/devices/0000:02:ab.0/resource          |  13 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:02:ab.0/vendor            |   1 -
 34 files changed, 415 deletions(-)
 delete mode 100644 test/test/test_pci.c
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/vendor
MAINTAINERS +0 -2
index 382f740..39bf1fc 100644
@@ -98,8 +98,6 @@ F: test/test/test_errno.c
 F: test/test/test_interrupts.c
 F: test/test/test_logs.c
 F: test/test/test_memcpy*
-F: test/test/test_pci.c
-F: test/test/test_pci_sysfs/
 F: test/test/test_per_lcore.c
 F: test/test/test_prefetch.c
 F: test/test/test_rwlock.c
test/test/Makefile +0 -2
index 278b508..ee240be 100644
@@ -83,8 +83,6 @@ test_resource.res: test_resource.c
 	@ cp $< $@
 $(eval $(call linked_resource,test_resource_c,test_resource.res))
 $(eval $(call linked_tar_resource,test_resource_tar,test_resource.c))
-SRCS-$(CONFIG_RTE_APP_TEST_RESOURCE_TAR) += test_pci.c
-$(eval $(call linked_tar_resource,test_pci_sysfs,test_pci_sysfs))
 SRCS-$(CONFIG_RTE_APP_TEST_RESOURCE_TAR) += test_cfgfile.c
 $(eval $(call linked_tar_resource,test_cfgfiles,test_cfgfiles))
 SRCS-y += test_prefetch.c
test/test/test.h +0 -3
index 9a979d3..08ffe94 100644
@@ -228,9 +228,6 @@ extern const char *prgname;
 
 int commands_init(void);
 
-int test_pci(void);
-int test_pci_run;
-
 int test_mp_secondary(void);
 
 int test_set_rxtx_conf(cmdline_fixed_string_t mode);
test/test/test_mp_secondary.c +0 -17
index 26c4afd..94042e5 100644
@@ -245,16 +245,6 @@ run_object_creation_tests(void)
 	printf("# Checked rte_lpm_create() OK\n");
 #endif
 
-#ifdef RTE_APP_TEST_RESOURCE_TAR
-	/* Run a test_pci call */
-	if (test_pci() != 0) {
-		printf("PCI scan failed in secondary\n");
-		if (getuid() == 0) /* pci scans can fail as non-root */
-			return -1;
-	} else
-		printf("PCI scan succeeded in secondary\n");
-#endif
-
 	return 0;
 }
 
@@ -267,13 +257,6 @@ int
 test_mp_secondary(void)
 {
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-		if (!test_pci_run) {
-#ifdef RTE_APP_TEST_RESOURCE_TAR
-			printf("=== Running pre-requisite test of test_pci\n");
-			test_pci();
-			printf("=== Requisite test done\n");
-#endif
-		}
 		return run_secondary_instances();
 	}
 
test/test/test_pci.c deleted +0 -322

322 lines not on this page · raw message

test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class deleted +0 -1
deleted file mode 100644
index 2f9c1da..0000000
@@ -1 +0,0 @@
-0x020000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config deleted binary +0 -0
deleted file mode 100644
index 7752421cf13a5aa00a28eaee02cac2add9ce5566..0000000000000000000000000000000000000000
GIT binary patch
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits deleted +0 -1
deleted file mode 100644
index 900731f..0000000
@@ -1 +0,0 @@
-64
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device deleted +0 -1
deleted file mode 100644
index 48a6290..0000000
@@ -1 +0,0 @@
-0x1234
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits deleted +0 -1
deleted file mode 100644
index 900731f..0000000
@@ -1 +0,0 @@
-64
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable deleted +0 -1
deleted file mode 100644
index d00491f..0000000
@@ -1 +0,0 @@
-1
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq deleted +0 -1
deleted file mode 100644
index 573541a..0000000
@@ -1 +0,0 @@
-0
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias deleted +0 -1
deleted file mode 100644
index f4c76ed..0000000
@@ -1 +0,0 @@
-pci:v00008086d000010FBsv00008086sd00000003bc02sc00i00
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus deleted +0 -1
deleted file mode 100644
index d00491f..0000000
@@ -1 +0,0 @@
-1
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node deleted +0 -1
deleted file mode 100644
index 3a2e3f4..0000000
@@ -1 +0,0 @@
--1
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource deleted +0 -13
deleted file mode 100644
index f388929..0000000
@@ -1,13 +0,0 @@
-0x00000000d0080000 0x00000000d00fffff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x000000000000e020 0x000000000000e03f 0x0000000000040101
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000d0104000 0x00000000d0107fff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab000000 0x00000000ab0fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab100000 0x00000000ab1fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs deleted +0 -1
deleted file mode 100644
index 573541a..0000000
@@ -1 +0,0 @@
-0
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs deleted +0 -1
deleted file mode 100644
index 4b9026d..0000000
@@ -1 +0,0 @@
-63
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device deleted +0 -1
deleted file mode 100644
index 89a932c..0000000
@@ -1 +0,0 @@
-0x0003
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent deleted +0 -6
deleted file mode 100644
index 1dbe34d..0000000
@@ -1,6 +0,0 @@
-DRIVER=ixgbe
-PCI_CLASS=20000
-PCI_ID=8086:10FB
-PCI_SUBSYS_ID=8086:0003
-PCI_SLOT_NAME=0000:01:00.0
-MODALIAS=pci:v00008086d000010FBsv00008086sd00000003bc02sc00i00
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/class deleted +0 -1
deleted file mode 100644
index 22dd936..0000000
@@ -1 +0,0 @@
-0x100000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/device deleted +0 -1
deleted file mode 100644
index f61bbe6..0000000
@@ -1 +0,0 @@
-0xabcd
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/resource deleted +0 -13
deleted file mode 100644
index f388929..0000000
@@ -1,13 +0,0 @@
-0x00000000d0080000 0x00000000d00fffff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x000000000000e020 0x000000000000e03f 0x0000000000040101
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000d0104000 0x00000000d0107fff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab000000 0x00000000ab0fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab100000 0x00000000ab1fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_device deleted +0 -1
deleted file mode 100644
index f61bbe6..0000000
@@ -1 +0,0 @@
-0xabcd
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_vendor deleted +0 -1
deleted file mode 100644
index 4321b81..0000000
@@ -1 +0,0 @@
-0x0002
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/vendor deleted +0 -1
deleted file mode 100644
index 4321b81..0000000
@@ -1 +0,0 @@
-0x0002
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/class deleted +0 -1
deleted file mode 100644
index 22dd936..0000000
@@ -1 +0,0 @@
-0x100000
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/device deleted +0 -1
deleted file mode 100644
index ccaa498..0000000
@@ -1 +0,0 @@
-0x4444
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/resource deleted +0 -13
deleted file mode 100644
index f388929..0000000
@@ -1,13 +0,0 @@
-0x00000000d0080000 0x00000000d00fffff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x000000000000e020 0x000000000000e03f 0x0000000000040101
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000d0104000 0x00000000d0107fff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab000000 0x00000000ab0fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab100000 0x00000000ab1fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_device deleted +0 -1
deleted file mode 100644
index ccaa498..0000000
@@ -1 +0,0 @@
-0x4444
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
Signature · 1 line
2.1.4
#133 lore raw

v13 cover rte_bus_pci

In reply to Gaetan Rivet

I have rebased the work done by Shreyansh and Thomas to follow the bus abstraction introduced in v17.02 for the PCI bus implementation.
This series is only a partial version of the previous one, because some of the patches have already been integrated, and others still need rework.

Additionally, Jan Blunck sent this RFC:

[RFC] eal: use busname and devargs to attach devices

That has not been considered for this version as it had not yet spawned a discussion.

changes in v13:
- Removed the PCI tests. They cannot follow the bus implementation anymore, and it is an opportunity to update their original design.
- Changed the rte_pci_match function semantic to match its name.
- Made the rte_pci_match function private.
- Made the rte_bus_list private
- Made rte_eal_pci_add_device,
rte_eal_pci_insert_device, rte_eal_pci_remove_device,
functions private.

Additional work is needed:
- The PCI bus should be moved to the relevant bus sub-directory.
- The documentation must be updated.

But this version should allow for the PCI bus implementation to be integrated in v17.05-rc2.

Gaetan Rivet (1):
test: remove pci tests

Shreyansh Jain (6):
pci: split match and probe
pci: remove loop over drivers in device detach
pci: add bus driver
pci: use bus driver for scan/probe
pci: use bus driver for attach/detach
doc: remove deprecation notice for rte_bus

 MAINTAINERS                                        |   2 -
 doc/guides/rel_notes/release_17_02.rst             |   2 +-
 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +-
 lib/librte_eal/bsdapp/eal/eal.c                    |  14 -
 lib/librte_eal/bsdapp/eal/eal_pci.c                |  34 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map      |   2 -
 lib/librte_eal/common/eal_bus.h                    |  45 +++
 lib/librte_eal/common/eal_common_dev.c             |  57 +++-
 lib/librte_eal/common/eal_common_pci.c             | 362 +++++++++++++--------
 lib/librte_eal/common/eal_private.h                |  41 ++-
 lib/librte_eal/common/include/rte_bus.h            |  29 ++
 lib/librte_eal/common/include/rte_pci.h            |  94 ++++--
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +-
 lib/librte_eal/linuxapp/eal/eal.c                  |  14 -
 lib/librte_eal/linuxapp/eal/eal_pci.c              |  38 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map    |   2 -
 test/test/Makefile                                 |   2 -
 test/test/test.h                                   |   3 -
 test/test/test_mp_secondary.c                      |  17 -
 test/test/test_pci.c                               | 322 ------------------
 .../bus/pci/devices/0000:01:00.0/class             |   1 -
 .../bus/pci/devices/0000:01:00.0/config            | Bin 64 -> 0 bytes
 .../devices/0000:01:00.0/consistent_dma_mask_bits  |   1 -
 .../bus/pci/devices/0000:01:00.0/device            |   1 -
 .../bus/pci/devices/0000:01:00.0/dma_mask_bits     |   1 -
 .../bus/pci/devices/0000:01:00.0/enable            |   1 -
 .../bus/pci/devices/0000:01:00.0/irq               |   1 -
 .../bus/pci/devices/0000:01:00.0/modalias          |   1 -
 .../bus/pci/devices/0000:01:00.0/msi_bus           |   1 -
 .../bus/pci/devices/0000:01:00.0/numa_node         |   1 -
 .../bus/pci/devices/0000:01:00.0/resource          |  13 -
 .../bus/pci/devices/0000:01:00.0/sriov_numvfs      |   1 -
 .../bus/pci/devices/0000:01:00.0/sriov_totalvfs    |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:00.0/uevent            |   6 -
 .../bus/pci/devices/0000:01:00.0/vendor            |   1 -
 .../bus/pci/devices/0000:01:02.0/class             |   1 -
 .../bus/pci/devices/0000:01:02.0/device            |   1 -
 .../bus/pci/devices/0000:01:02.0/resource          |  13 -
 .../bus/pci/devices/0000:01:02.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:02.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:02.0/vendor            |   1 -
 .../bus/pci/devices/0000:02:ab.0/class             |   1 -
 .../bus/pci/devices/0000:02:ab.0/device            |   1 -
 .../bus/pci/devices/0000:02:ab.0/resource          |  13 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:02:ab.0/vendor            |   1 -
 49 files changed, 478 insertions(+), 675 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_bus.h
 delete mode 100644 test/test/test_pci.c
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/vendor
Signature · 1 line
2.1.4
#134 lore raw

PATCH v13 1/7 test: remove pci tests

These tests are not suited for the rte_bus PCI implementation anymore.

---
 MAINTAINERS                                        |   2 -
 test/test/Makefile                                 |   2 -
 test/test/test.h                                   |   3 -
 test/test/test_mp_secondary.c                      |  17 --
 test/test/test_pci.c                               | 322 ---------------------
 .../bus/pci/devices/0000:01:00.0/class             |   1 -
 .../bus/pci/devices/0000:01:00.0/config            | Bin 64 -> 0 bytes
 .../devices/0000:01:00.0/consistent_dma_mask_bits  |   1 -
 .../bus/pci/devices/0000:01:00.0/device            |   1 -
 .../bus/pci/devices/0000:01:00.0/dma_mask_bits     |   1 -
 .../bus/pci/devices/0000:01:00.0/enable            |   1 -
 .../bus/pci/devices/0000:01:00.0/irq               |   1 -
 .../bus/pci/devices/0000:01:00.0/modalias          |   1 -
 .../bus/pci/devices/0000:01:00.0/msi_bus           |   1 -
 .../bus/pci/devices/0000:01:00.0/numa_node         |   1 -
 .../bus/pci/devices/0000:01:00.0/resource          |  13 -
 .../bus/pci/devices/0000:01:00.0/sriov_numvfs      |   1 -
 .../bus/pci/devices/0000:01:00.0/sriov_totalvfs    |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:00.0/uevent            |   6 -
 .../bus/pci/devices/0000:01:00.0/vendor            |   1 -
 .../bus/pci/devices/0000:01:02.0/class             |   1 -
 .../bus/pci/devices/0000:01:02.0/device            |   1 -
 .../bus/pci/devices/0000:01:02.0/resource          |  13 -
 .../bus/pci/devices/0000:01:02.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:02.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:02.0/vendor            |   1 -
 .../bus/pci/devices/0000:02:ab.0/class             |   1 -
 .../bus/pci/devices/0000:02:ab.0/device            |   1 -
 .../bus/pci/devices/0000:02:ab.0/resource          |  13 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:02:ab.0/vendor            |   1 -
 34 files changed, 415 deletions(-)
 delete mode 100644 test/test/test_pci.c
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/vendor
MAINTAINERS +0 -2
index 382f740..39bf1fc 100644
@@ -98,8 +98,6 @@ F: test/test/test_errno.c
 F: test/test/test_interrupts.c
 F: test/test/test_logs.c
 F: test/test/test_memcpy*
-F: test/test/test_pci.c
-F: test/test/test_pci_sysfs/
 F: test/test/test_per_lcore.c
 F: test/test/test_prefetch.c
 F: test/test/test_rwlock.c
test/test/Makefile +0 -2
index 278b508..ee240be 100644
@@ -83,8 +83,6 @@ test_resource.res: test_resource.c
 	@ cp $< $@
 $(eval $(call linked_resource,test_resource_c,test_resource.res))
 $(eval $(call linked_tar_resource,test_resource_tar,test_resource.c))
-SRCS-$(CONFIG_RTE_APP_TEST_RESOURCE_TAR) += test_pci.c
-$(eval $(call linked_tar_resource,test_pci_sysfs,test_pci_sysfs))
 SRCS-$(CONFIG_RTE_APP_TEST_RESOURCE_TAR) += test_cfgfile.c
 $(eval $(call linked_tar_resource,test_cfgfiles,test_cfgfiles))
 SRCS-y += test_prefetch.c
test/test/test.h +0 -3
index 9a979d3..08ffe94 100644
@@ -228,9 +228,6 @@ extern const char *prgname;
 
 int commands_init(void);
 
-int test_pci(void);
-int test_pci_run;
-
 int test_mp_secondary(void);
 
 int test_set_rxtx_conf(cmdline_fixed_string_t mode);
test/test/test_mp_secondary.c +0 -17
index 26c4afd..94042e5 100644
@@ -245,16 +245,6 @@ run_object_creation_tests(void)
 	printf("# Checked rte_lpm_create() OK\n");
 #endif
 
-#ifdef RTE_APP_TEST_RESOURCE_TAR
-	/* Run a test_pci call */
-	if (test_pci() != 0) {
-		printf("PCI scan failed in secondary\n");
-		if (getuid() == 0) /* pci scans can fail as non-root */
-			return -1;
-	} else
-		printf("PCI scan succeeded in secondary\n");
-#endif
-
 	return 0;
 }
 
@@ -267,13 +257,6 @@ int
 test_mp_secondary(void)
 {
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-		if (!test_pci_run) {
-#ifdef RTE_APP_TEST_RESOURCE_TAR
-			printf("=== Running pre-requisite test of test_pci\n");
-			test_pci();
-			printf("=== Requisite test done\n");
-#endif
-		}
 		return run_secondary_instances();
 	}
 
test/test/test_pci.c deleted +0 -322

322 lines not on this page · raw message

test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class deleted +0 -1
deleted file mode 100644
index 2f9c1da..0000000
@@ -1 +0,0 @@
-0x020000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config deleted binary +0 -0
deleted file mode 100644
index 7752421cf13a5aa00a28eaee02cac2add9ce5566..0000000000000000000000000000000000000000
GIT binary patch
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits deleted +0 -1
deleted file mode 100644
index 900731f..0000000
@@ -1 +0,0 @@
-64
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device deleted +0 -1
deleted file mode 100644
index 48a6290..0000000
@@ -1 +0,0 @@
-0x1234
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits deleted +0 -1
deleted file mode 100644
index 900731f..0000000
@@ -1 +0,0 @@
-64
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable deleted +0 -1
deleted file mode 100644
index d00491f..0000000
@@ -1 +0,0 @@
-1
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq deleted +0 -1
deleted file mode 100644
index 573541a..0000000
@@ -1 +0,0 @@
-0
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias deleted +0 -1
deleted file mode 100644
index f4c76ed..0000000
@@ -1 +0,0 @@
-pci:v00008086d000010FBsv00008086sd00000003bc02sc00i00
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus deleted +0 -1
deleted file mode 100644
index d00491f..0000000
@@ -1 +0,0 @@
-1
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node deleted +0 -1
deleted file mode 100644
index 3a2e3f4..0000000
@@ -1 +0,0 @@
--1
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource deleted +0 -13
deleted file mode 100644
index f388929..0000000
@@ -1,13 +0,0 @@
-0x00000000d0080000 0x00000000d00fffff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x000000000000e020 0x000000000000e03f 0x0000000000040101
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000d0104000 0x00000000d0107fff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab000000 0x00000000ab0fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab100000 0x00000000ab1fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs deleted +0 -1
deleted file mode 100644
index 573541a..0000000
@@ -1 +0,0 @@
-0
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs deleted +0 -1
deleted file mode 100644
index 4b9026d..0000000
@@ -1 +0,0 @@
-63
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device deleted +0 -1
deleted file mode 100644
index 89a932c..0000000
@@ -1 +0,0 @@
-0x0003
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent deleted +0 -6
deleted file mode 100644
index 1dbe34d..0000000
@@ -1,6 +0,0 @@
-DRIVER=ixgbe
-PCI_CLASS=20000
-PCI_ID=8086:10FB
-PCI_SUBSYS_ID=8086:0003
-PCI_SLOT_NAME=0000:01:00.0
-MODALIAS=pci:v00008086d000010FBsv00008086sd00000003bc02sc00i00
test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/class deleted +0 -1
deleted file mode 100644
index 22dd936..0000000
@@ -1 +0,0 @@
-0x100000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/device deleted +0 -1
deleted file mode 100644
index f61bbe6..0000000
@@ -1 +0,0 @@
-0xabcd
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/resource deleted +0 -13
deleted file mode 100644
index f388929..0000000
@@ -1,13 +0,0 @@
-0x00000000d0080000 0x00000000d00fffff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x000000000000e020 0x000000000000e03f 0x0000000000040101
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000d0104000 0x00000000d0107fff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab000000 0x00000000ab0fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab100000 0x00000000ab1fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_device deleted +0 -1
deleted file mode 100644
index f61bbe6..0000000
@@ -1 +0,0 @@
-0xabcd
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_vendor deleted +0 -1
deleted file mode 100644
index 4321b81..0000000
@@ -1 +0,0 @@
-0x0002
test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/vendor deleted +0 -1
deleted file mode 100644
index 4321b81..0000000
@@ -1 +0,0 @@
-0x0002
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/class deleted +0 -1
deleted file mode 100644
index 22dd936..0000000
@@ -1 +0,0 @@
-0x100000
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/device deleted +0 -1
deleted file mode 100644
index ccaa498..0000000
@@ -1 +0,0 @@
-0x4444
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/resource deleted +0 -13
deleted file mode 100644
index f388929..0000000
@@ -1,13 +0,0 @@
-0x00000000d0080000 0x00000000d00fffff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x000000000000e020 0x000000000000e03f 0x0000000000040101
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000d0104000 0x00000000d0107fff 0x000000000014220c
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab000000 0x00000000ab0fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x00000000ab100000 0x00000000ab1fffff 0x0000000000140204
-0x0000000000000000 0x0000000000000000 0x0000000000000000
-0x0000000000000000 0x0000000000000000 0x0000000000000000
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_device deleted +0 -1
deleted file mode 100644
index ccaa498..0000000
@@ -1 +0,0 @@
-0x4444
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/vendor deleted +0 -1
deleted file mode 100644
index 446afb4..0000000
@@ -1 +0,0 @@
-0x0001
Signature · 1 line
2.1.4
#135 lore raw

PATCH v13 2/7 pci: split match and probe

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

Matching of PCI device address and driver ID table is being done at two discreet locations duplicating the code. (rte_eal_pci_probe_one_driver and rte_eal_pci_detach_dev).

Refactor the match logic as a single function.

---
 lib/librte_eal/common/eal_common_pci.c | 176 ++++++++++++++++++---------------
 1 file changed, 98 insertions(+), 78 deletions(-)
lib/librte_eal/common/eal_common_pci.c +98 -78
index 1ab92c9..83a81c4 100644
@@ -154,73 +154,108 @@ pci_unmap_resource(void *requested_addr, size_t size)
 }
 
 /*
- * If vendor/device ID match, call the probe() function of the
- * driver.
+ * Match the PCI Driver and Device using the ID Table
+ *
+ * @param pci_drv
+ *	PCI driver from which ID table would be extracted
+ * @param pci_dev
+ *	PCI device to match against the driver
+ * @return
+ *	1 for successful match
+ *	0 for unsuccessful match
  */
 static int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+rte_pci_match(const struct rte_pci_driver *pci_drv,
+	      const struct rte_pci_device *pci_dev)
 {
-	int ret;
 	const struct rte_pci_id *id_table;
 
-	for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
-
+	for (id_table = pci_drv->id_table; id_table->vendor_id != 0;
+	     id_table++) {
 		/* check if device's identifiers match the driver's ones */
-		if (id_table->vendor_id != dev->id.vendor_id &&
+		if (id_table->vendor_id != pci_dev->id.vendor_id &&
 				id_table->vendor_id != PCI_ANY_ID)
 			continue;
-		if (id_table->device_id != dev->id.device_id &&
+		if (id_table->device_id != pci_dev->id.device_id &&
 				id_table->device_id != PCI_ANY_ID)
 			continue;
-		if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-				id_table->subsystem_vendor_id != PCI_ANY_ID)
+		if (id_table->subsystem_vendor_id !=
+		    pci_dev->id.subsystem_vendor_id &&
+		    id_table->subsystem_vendor_id != PCI_ANY_ID)
 			continue;
-		if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-				id_table->subsystem_device_id != PCI_ANY_ID)
+		if (id_table->subsystem_device_id !=
+		    pci_dev->id.subsystem_device_id &&
+		    id_table->subsystem_device_id != PCI_ANY_ID)
 			continue;
-		if (id_table->class_id != dev->id.class_id &&
+		if (id_table->class_id != pci_dev->id.class_id &&
 				id_table->class_id != RTE_CLASS_ANY_ID)
 			continue;
 
-		struct rte_pci_addr *loc = &dev->addr;
+		return 1;
+	}
 
-		RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->device.numa_node);
+	return 0;
+}
 
-		/* no initialization when blacklisted, return without error */
-		if (dev->device.devargs != NULL &&
-			dev->device.devargs->type ==
-				RTE_DEVTYPE_BLACKLISTED_PCI) {
-			RTE_LOG(INFO, EAL, "  Device is blacklisted, not initializing\n");
-			return 1;
-		}
+/*
+ * If vendor/device ID match, call the probe() function of the
+ * driver.
+ */
+static int
+rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
+			     struct rte_pci_device *dev)
+{
+	int ret;
+	struct rte_pci_addr *loc;
 
-		RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->driver.name);
+	if ((dr == NULL) || (dev == NULL))
+		return -EINVAL;
 
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio or VFIO */
-			ret = rte_eal_pci_map_device(dev);
-			if (ret != 0)
-				return ret;
-		}
+	loc = &dev->addr;
 
-		/* reference driver structure */
-		dev->driver = dr;
+	/* The device is not blacklisted; Check if driver supports it */
+	if (!rte_pci_match(dr, dev)) {
+		/* Match of device and driver failed */
+		RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n",
+			dr->driver.name);
+		return 1;
+	}
 
-		/* call the driver probe() function */
-		ret = dr->probe(dr, dev);
-		if (ret) {
-			dev->driver = NULL;
-			if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-				rte_eal_pci_unmap_device(dev);
-		}
+	RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+			loc->domain, loc->bus, loc->devid, loc->function,
+			dev->device.numa_node);
+
+	/* no initialization when blacklisted, return without error */
+	if (dev->device.devargs != NULL &&
+		dev->device.devargs->type ==
+			RTE_DEVTYPE_BLACKLISTED_PCI) {
+		RTE_LOG(INFO, EAL, "  Device is blacklisted, not"
+			" initializing\n");
+		return 1;
+	}
 
-		return ret;
+	RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+		dev->id.device_id, dr->driver.name);
+
+	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+		/* map resources for devices that use igb_uio */
+		ret = rte_eal_pci_map_device(dev);
+		if (ret != 0)
+			return ret;
 	}
-	/* return positive value if driver doesn't support this device */
-	return 1;
+
+	/* reference driver structure */
+	dev->driver = dr;
+
+	/* call the driver probe() function */
+	ret = dr->probe(dr, dev);
+	if (ret) {
+		dev->driver = NULL;
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+			rte_eal_pci_unmap_device(dev);
+	}
+
+	return ret;
 }
 
 /*
@@ -231,51 +266,36 @@ static int
 rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
 		struct rte_pci_device *dev)
 {
-	const struct rte_pci_id *id_table;
+	struct rte_pci_addr *loc;
 
 	if ((dr == NULL) || (dev == NULL))
 		return -EINVAL;
 
-	for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
-
-		/* check if device's identifiers match the driver's ones */
-		if (id_table->vendor_id != dev->id.vendor_id &&
-				id_table->vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->device_id != dev->id.device_id &&
-				id_table->device_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-				id_table->subsystem_vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-				id_table->subsystem_device_id != PCI_ANY_ID)
-			continue;
-
-		struct rte_pci_addr *loc = &dev->addr;
+	if (!rte_pci_match(dr, dev)) {
+		/* Device and driver don't match */
+		return 1;
+	}
 
-		RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-				loc->domain, loc->bus, loc->devid,
-				loc->function, dev->device.numa_node);
+	loc = &dev->addr;
 
-		RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->driver.name);
+	RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+			loc->domain, loc->bus, loc->devid,
+			loc->function, dev->device.numa_node);
 
-		if (dr->remove && (dr->remove(dev) < 0))
-			return -1;	/* negative value is an error */
+	RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
+			dev->id.device_id, dr->driver.name);
 
-		/* clear driver structure */
-		dev->driver = NULL;
+	if (dr->remove && (dr->remove(dev) < 0))
+		return -1;	/* negative value is an error */
 
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
-			/* unmap resources for devices that use igb_uio */
-			rte_eal_pci_unmap_device(dev);
+	/* clear driver structure */
+	dev->driver = NULL;
 
-		return 0;
-	}
+	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
+		/* unmap resources for devices that use igb_uio */
+		rte_eal_pci_unmap_device(dev);
 
-	/* return positive value if driver doesn't support this device */
-	return 1;
+	return 0;
 }
 
 /*
Signature · 1 line
2.1.4
#136 lore raw

PATCH v13 3/7 pci: remove loop over drivers in device detach

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

rte_eal_pci_detach calls pci_detach_all_drivers which loops over all PCI drivers for detaching the device. This is unnecessary as the device already has the PCI driver reference which can be used directly.

Removing pci_detach_all_drivers and restructuring rte_eal_pci_detach and rte_eal_pci_detach_dev to work without looping over driver list.

---
 lib/librte_eal/common/eal_common_pci.c | 45 +++++++---------------------------
 1 file changed, 9 insertions(+), 36 deletions(-)
lib/librte_eal/common/eal_common_pci.c +9 -36
index 83a81c4..498a3bb 100644
@@ -263,19 +263,15 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
  * driver.
  */
 static int
-rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
-		struct rte_pci_device *dev)
+rte_eal_pci_detach_dev(struct rte_pci_device *dev)
 {
 	struct rte_pci_addr *loc;
+	struct rte_pci_driver *dr;
 
-	if ((dr == NULL) || (dev == NULL))
+	if (dev == NULL)
 		return -EINVAL;
 
-	if (!rte_pci_match(dr, dev)) {
-		/* Device and driver don't match */
-		return 1;
-	}
-
+	dr = dev->driver;
 	loc = &dev->addr;
 
 	RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
@@ -330,33 +326,6 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 }
 
 /*
- * If vendor/device ID match, call the remove() function of all
- * registered driver for the given device. Return -1 if initialization
- * failed, return 1 if no driver is found for this device.
- */
-static int
-pci_detach_all_drivers(struct rte_pci_device *dev)
-{
-	struct rte_pci_driver *dr = NULL;
-	int rc = 0;
-
-	if (dev == NULL)
-		return -1;
-
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
-		rc = rte_eal_pci_detach_dev(dr, dev);
-		if (rc < 0)
-			/* negative value is an error */
-			return -1;
-		if (rc > 0)
-			/* positive value means driver doesn't support it */
-			continue;
-		return 0;
-	}
-	return 1;
-}
-
-/*
  * Find the pci device specified by pci address, then invoke probe function of
  * the driver of the devive.
  */
@@ -409,9 +378,13 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
-		ret = pci_detach_all_drivers(dev);
+		ret = rte_eal_pci_detach_dev(dev);
 		if (ret < 0)
+			/* negative value is an error */
 			goto err_return;
+		if (ret > 0)
+			/* positive value means driver doesn't support it */
+			continue;
 
 		TAILQ_REMOVE(&pci_device_list, dev, next);
 		free(dev);
Signature · 1 line
2.1.4
#137 lore raw

PATCH v13 4/7 pci: add bus driver

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

Based on EAL Bus APIs, PCI bus callbacks and support functions are introduced in this patch.

EAL continues to have direct PCI init/scan calls as well. These would be removed in subsequent patches to enable bus only PCI devices.

---
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  2 ++
 lib/librte_eal/common/eal_common_pci.c  | 36 +++++++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h     | 35 ++++++++++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h | 30 +++++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c   |  3 +++
 5 files changed, 106 insertions(+)
lib/librte_eal/bsdapp/eal/eal_pci.c +2 -0
index 16a1743..6ef8781 100644
@@ -87,6 +87,8 @@
  * enabling bus master.
  */
 
+extern struct rte_pci_bus rte_pci_bus;
+
 /* Map pci device */
 int
 rte_eal_pci_map_device(struct rte_pci_device *dev)
lib/librte_eal/common/eal_common_pci.c +36 -0
index 498a3bb..5ac050a 100644
@@ -72,6 +72,7 @@
 #include <rte_errno.h>
 #include <rte_interrupts.h>
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
@@ -88,6 +89,8 @@ struct pci_driver_list pci_driver_list =
 struct pci_device_list pci_device_list =
 	TAILQ_HEAD_INITIALIZER(pci_device_list);
 
+extern struct rte_pci_bus rte_pci_bus;
+
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
 
 const char *pci_get_sysfs_path(void)
@@ -489,3 +492,36 @@ rte_eal_pci_unregister(struct rte_pci_driver *driver)
 	rte_eal_driver_unregister(&driver->driver);
 	TAILQ_REMOVE(&pci_driver_list, driver, next);
 }
+
+/* Add a device to PCI bus */
+void
+rte_eal_pci_add_device(struct rte_pci_device *pci_dev)
+{
+	TAILQ_INSERT_TAIL(&rte_pci_bus.device_list, pci_dev, next);
+}
+
+/* Insert a device into a predefined position in PCI bus */
+void
+rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev,
+			  struct rte_pci_device *new_pci_dev)
+{
+	TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next);
+}
+
+/* Remove a device from PCI bus */
+void
+rte_eal_pci_remove_device(struct rte_pci_device *pci_dev)
+{
+	TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next);
+}
+
+struct rte_pci_bus rte_pci_bus = {
+	.bus = {
+		.scan = rte_eal_pci_scan,
+		.probe = rte_eal_pci_probe,
+	},
+	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
+	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
+};
+
+RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
lib/librte_eal/common/eal_private.h +35 -0
index 8b2d323..47c84df 100644
@@ -123,6 +123,41 @@ struct rte_pci_driver;
 struct rte_pci_device;
 
 /**
+ * Add a PCI device to the PCI Bus (append to PCI Device list). This function
+ * also updates the bus references of the PCI Device (and the generic device
+ * object embedded within.
+ *
+ * @param pci_dev
+ *	PCI device to add
+ * @return void
+ */
+void rte_eal_pci_add_device(struct rte_pci_device *pci_dev);
+
+/**
+ * Insert a PCI device in the PCI Bus at a particular location in the device
+ * list. It also updates the PCI Bus reference of the new devices to be
+ * inserted.
+ *
+ * @param exist_pci_dev
+ *	Existing PCI device in PCI Bus
+ * @param new_pci_dev
+ *	PCI device to be added before exist_pci_dev
+ * @return void
+ */
+void rte_eal_pci_insert_device(struct rte_pci_device *exist_pci_dev,
+			       struct rte_pci_device *new_pci_dev);
+
+/**
+ * Remove a PCI device from the PCI Bus. This sets to NULL the bus references
+ * in the PCI device object as well as the generic device object.
+ *
+ * @param pci_device
+ *	PCI device to be removed from PCI Bus
+ * @return void
+ */
+void rte_eal_pci_remove_device(struct rte_pci_device *pci_device);
+
+/**
  * Update a pci device object by asking the kernel for the latest information.
  *
  * This function is private to EAL.
lib/librte_eal/common/include/rte_pci.h +30 -0
index 8557e47..729429f 100644
@@ -85,6 +85,7 @@ extern "C" {
 #include <rte_debug.h>
 #include <rte_interrupts.h>
 #include <rte_dev.h>
+#include <rte_bus.h>
 
 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
 TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
@@ -111,6 +112,25 @@ const char *pci_get_sysfs_path(void);
 /** Maximum number of PCI resources. */
 #define PCI_MAX_RESOURCE 6
 
+/** Name of PCI Bus */
+#define PCI_BUS_NAME "PCI"
+
+/* Forward declarations */
+struct rte_pci_device;
+struct rte_pci_driver;
+
+/** List of PCI devices */
+TAILQ_HEAD(rte_pci_device_list, rte_pci_device);
+/** List of PCI drivers */
+TAILQ_HEAD(rte_pci_driver_list, rte_pci_driver);
+
+/* PCI Bus iterators */
+#define FOREACH_DEVICE_ON_PCIBUS(p)	\
+		TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
+
+#define FOREACH_DRIVER_ON_PCIBUS(p)	\
+		TAILQ_FOREACH(p, &(rte_pci_bus.driver_list), next)
+
 /**
  * A structure describing an ID for a PCI driver. Each driver provides a
  * table of these IDs for each device that it supports.
@@ -206,12 +226,22 @@ typedef int (pci_remove_t)(struct rte_pci_device *);
 struct rte_pci_driver {
 	TAILQ_ENTRY(rte_pci_driver) next;       /**< Next in list. */
 	struct rte_driver driver;               /**< Inherit core driver. */
+	struct rte_pci_bus *bus;                /**< PCI bus reference. */
 	pci_probe_t *probe;                     /**< Device Probe function. */
 	pci_remove_t *remove;                   /**< Device Remove function. */
 	const struct rte_pci_id *id_table;	/**< ID table, NULL terminated. */
 	uint32_t drv_flags;                     /**< Flags contolling handling of device. */
 };
 
+/**
+ * Structure describing the PCI bus
+ */
+struct rte_pci_bus {
+	struct rte_bus bus;               /**< Inherit the generic class */
+	struct rte_pci_device_list device_list;  /**< List of PCI devices */
+	struct rte_pci_driver_list driver_list;  /**< List of PCI drivers */
+};
+
 /** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */
 #define RTE_PCI_DRV_NEED_MAPPING 0x0001
 /** Device driver supports link state interrupt */
lib/librte_eal/linuxapp/eal/eal_pci.c +3 -0
index 7d6f50a..1bd3496 100644
@@ -35,6 +35,7 @@
 #include <dirent.h>
 
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
@@ -54,6 +55,8 @@
  * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it).
  */
 
+extern struct rte_pci_bus rte_pci_bus;
+
 static int
 pci_get_kernel_driver_by_path(const char *filename, char *dri_name)
 {
Signature · 1 line
2.1.4
#138 lore raw

PATCH v13 5/7 pci: use bus driver for scan/probe

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

Remove EAL initiated direct PCI scan/probe and enable PCI Bus linkage.

---
 lib/librte_eal/bsdapp/eal/eal.c                 | 14 ----------
 lib/librte_eal/bsdapp/eal/eal_pci.c             | 32 +++++++---------------
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 --
 lib/librte_eal/common/eal_common_pci.c          | 26 ++++++++----------
 lib/librte_eal/common/eal_private.h             | 10 -------
 lib/librte_eal/common/include/rte_pci.h         | 19 +++-----------
 lib/librte_eal/linuxapp/eal/eal.c               | 14 ----------
 lib/librte_eal/linuxapp/eal/eal_pci.c           | 35 ++++++++-----------------
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 --
 9 files changed, 35 insertions(+), 119 deletions(-)
lib/librte_eal/bsdapp/eal/eal.c +0 -14
index fae6c7e..7321ac6 100644
@@ -602,13 +602,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	if (rte_eal_pci_init() < 0) {
-		rte_eal_init_alert("Cannot init PCI\n");
-		rte_errno = EPROTO;
-		rte_atomic32_clear(&run_once);
-		return -1;
-	}
-
 	eal_check_mem_on_local_socket();
 
 	if (eal_plugins_init() < 0)
@@ -667,13 +660,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe()) {
-		rte_eal_init_alert("Cannot probe PCI\n");
-		rte_errno = ENOTSUP;
-		return -1;
-	}
-
 	if (rte_eal_dev_init() < 0)
 		rte_eal_init_alert("Cannot init pmd devices\n");
 
lib/librte_eal/bsdapp/eal/eal_pci.c +9 -23
index 6ef8781..1e9031c 100644
@@ -315,21 +315,19 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	}
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+	if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+		rte_eal_pci_add_device(dev);
 	}
 	else {
 		struct rte_pci_device *dev2 = NULL;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 			else if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
-				rte_eal_device_insert(&dev->device);
+				rte_eal_pci_insert_device(dev2, dev);
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
 				dev2->max_vfs = dev->max_vfs;
@@ -340,8 +338,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 			}
 			return 0;
 		}
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+		rte_eal_pci_add_device(dev);
 	}
 
 	return 0;
@@ -369,6 +366,10 @@ rte_eal_pci_scan(void)
 			.matches = &matches[0],
 	};
 
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	fd = open("/dev/pci", O_RDONLY);
 	if (fd < 0) {
 		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
@@ -662,18 +663,3 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 
 	return ret;
 }
-
-/* Init the PCI EAL subsystem */
-int
-rte_eal_pci_init(void)
-{
-	/* for debug purposes, PCI can be disabled */
-	if (internal_config.no_pci)
-		return 0;
-
-	if (rte_eal_pci_scan() < 0) {
-		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
-		return -1;
-	}
-	return 0;
-}
lib/librte_eal/bsdapp/eal/rte_eal_version.map +0 -2
index e1fbebc..ca12d89 100644
@@ -6,8 +6,6 @@ DPDK_2.0 {
 	eal_parse_sysfs_value;
 	eal_timer_source;
 	lcore_config;
-	pci_device_list;
-	pci_driver_list;
 	per_lcore__lcore_id;
 	per_lcore__rte_errno;
 	rte_calloc;
lib/librte_eal/common/eal_common_pci.c +11 -15
index 5ac050a..6f0d4d8 100644
@@ -84,11 +84,6 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list =
-	TAILQ_HEAD_INITIALIZER(pci_driver_list);
-struct pci_device_list pci_device_list =
-	TAILQ_HEAD_INITIALIZER(pci_device_list);
-
 extern struct rte_pci_bus rte_pci_bus;
 
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
@@ -315,7 +310,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	if (dev->driver != NULL)
 		return 0;
 
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+	FOREACH_DRIVER_ON_PCIBUS(dr) {
 		rc = rte_eal_pci_probe_one_driver(dr, dev);
 		if (rc < 0)
 			/* negative value is an error */
@@ -336,6 +331,7 @@ int
 rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 {
 	struct rte_pci_device *dev = NULL;
+
 	int ret = 0;
 
 	if (addr == NULL)
@@ -347,7 +343,7 @@ rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 	if (pci_update_device(addr) < 0)
 		goto err_return;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
@@ -377,7 +373,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 	if (addr == NULL)
 		return -1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
@@ -389,7 +385,7 @@ rte_eal_pci_detach(const struct rte_pci_addr *addr)
 			/* positive value means driver doesn't support it */
 			continue;
 
-		TAILQ_REMOVE(&pci_device_list, dev, next);
+		rte_eal_pci_remove_device(dev);
 		free(dev);
 		return 0;
 	}
@@ -419,7 +415,7 @@ rte_eal_pci_probe(void)
 	if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0)
 		probe_all = 1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		probed++;
 
 		/* set devargs in PCI structure */
@@ -472,7 +468,7 @@ rte_eal_pci_dump(FILE *f)
 {
 	struct rte_pci_device *dev = NULL;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	FOREACH_DEVICE_ON_PCIBUS(dev) {
 		pci_dump_one_device(f, dev);
 	}
 }
@@ -481,16 +477,16 @@ rte_eal_pci_dump(FILE *f)
 void
 rte_eal_pci_register(struct rte_pci_driver *driver)
 {
-	TAILQ_INSERT_TAIL(&pci_driver_list, driver, next);
-	rte_eal_driver_register(&driver->driver);
+	TAILQ_INSERT_TAIL(&rte_pci_bus.driver_list, driver, next);
+	driver->bus = &rte_pci_bus;
 }
 
 /* unregister a driver */
 void
 rte_eal_pci_unregister(struct rte_pci_driver *driver)
 {
-	rte_eal_driver_unregister(&driver->driver);
-	TAILQ_REMOVE(&pci_driver_list, driver, next);
+	TAILQ_REMOVE(&rte_pci_bus.driver_list, driver, next);
+	driver->bus = NULL;
 }
 
 /* Add a device to PCI bus */
lib/librte_eal/common/eal_private.h +0 -10
index 47c84df..280126d 100644
@@ -109,16 +109,6 @@ int rte_eal_timer_init(void);
  */
 int rte_eal_log_init(const char *id, int facility);
 
-/**
- * Init the PCI infrastructure
- *
- * This function is private to EAL.
- *
- * @return
- *   0 on success, negative on error
- */
-int rte_eal_pci_init(void);
-
 struct rte_pci_driver;
 struct rte_pci_device;
 
lib/librte_eal/common/include/rte_pci.h +4 -15
index 729429f..5980dd1 100644
@@ -87,12 +87,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_bus.h>
 
-TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
-TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
-
-extern struct pci_driver_list pci_driver_list; /**< Global list of PCI drivers. */
-extern struct pci_device_list pci_device_list; /**< Global list of PCI devices. */
-
 /** Pathname of PCI devices directory. */
 const char *pci_get_sysfs_path(void);
 
@@ -208,8 +202,6 @@ struct rte_pci_device {
 	.subsystem_device_id = PCI_ANY_ID
 #endif
 
-struct rte_pci_driver;
-
 /**
  * Initialisation function for the driver called during PCI probing.
  */
@@ -401,17 +393,14 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
 int rte_eal_pci_scan(void);
 
 /**
- * Probe the PCI bus for registered drivers.
- *
- * Scan the content of the PCI bus, and call the probe() function for
- * all registered drivers that have a matching entry in its id_table
- * for discovered devices.
+ * Probe the PCI bus
  *
  * @return
  *   - 0 on success.
- *   - Negative on error.
+ *   - !0 on error.
  */
-int rte_eal_pci_probe(void);
+int
+rte_eal_pci_probe(void);
 
 /**
  * Map the PCI device resources in user space virtual memory address
lib/librte_eal/linuxapp/eal/eal.c +0 -14
index d98d56d..7cf33d6 100644
@@ -830,13 +830,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	if (rte_eal_pci_init() < 0) {
-		rte_eal_init_alert("Cannot init PCI\n");
-		rte_errno = EPROTO;
-		rte_atomic32_clear(&run_once);
-		return -1;
-	}
-
 #ifdef VFIO_PRESENT
 	if (rte_eal_vfio_setup() < 0) {
 		rte_eal_init_alert("Cannot init VFIO\n");
@@ -946,13 +939,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe()) {
-		rte_eal_init_alert("Cannot probe PCI\n");
-		rte_errno = ENOTSUP;
-		return -1;
-	}
-
 	if (rte_eal_dev_init() < 0)
 		rte_eal_init_alert("Cannot init pmd devices\n");
 
lib/librte_eal/linuxapp/eal/eal_pci.c +11 -24
index 1bd3496..7897e15 100644
@@ -354,21 +354,19 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 		dev->kdrv = RTE_KDRV_NONE;
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+	if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+		rte_eal_pci_add_device(dev);
 	} else {
 		struct rte_pci_device *dev2;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 
 			if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
-				rte_eal_device_insert(&dev->device);
+				rte_eal_pci_insert_device(dev2, dev);
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
 				dev2->max_vfs = dev->max_vfs;
@@ -378,8 +376,8 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 			}
 			return 0;
 		}
-		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+
+		rte_eal_pci_add_device(dev);
 	}
 
 	return 0;
@@ -455,6 +453,10 @@ rte_eal_pci_scan(void)
 	char dirname[PATH_MAX];
 	struct rte_pci_addr addr;
 
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	dir = opendir(pci_get_sysfs_path());
 	if (dir == NULL) {
 		RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
@@ -471,6 +473,7 @@ rte_eal_pci_scan(void)
 
 		snprintf(dirname, sizeof(dirname), "%s/%s",
 				pci_get_sysfs_path(), e->d_name);
+
 		if (pci_scan_one(dirname, &addr) < 0)
 			goto error;
 	}
@@ -715,19 +718,3 @@ rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
 
 	return ret;
 }
-
-/* Init the PCI EAL subsystem */
-int
-rte_eal_pci_init(void)
-{
-	/* for debug purposes, PCI can be disabled */
-	if (internal_config.no_pci)
-		return 0;
-
-	if (rte_eal_pci_scan() < 0) {
-		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
-		return -1;
-	}
-
-	return 0;
-}
lib/librte_eal/linuxapp/eal/rte_eal_version.map +0 -2
index d5d05ee..94da1e7 100644
@@ -6,8 +6,6 @@ DPDK_2.0 {
 	eal_parse_sysfs_value;
 	eal_timer_source;
 	lcore_config;
-	pci_device_list;
-	pci_driver_list;
 	per_lcore__lcore_id;
 	per_lcore__rte_errno;
 	rte_calloc;
Signature · 1 line
2.1.4
#139 lore raw

PATCH v13 6/7 pci: use bus driver for attach/detach

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

Given a bus, attach and detach callbacks allow the implementation to handles calls from EAL for attaching or detaching a named device.

---
 lib/librte_eal/common/eal_bus.h         | 45 ++++++++++++++++
 lib/librte_eal/common/eal_common_dev.c  | 57 ++++++++++++++++-----
 lib/librte_eal/common/eal_common_pci.c  | 91 +++++++++++++++++++++++++++++++--
 lib/librte_eal/common/include/rte_bus.h | 29 +++++++++++
 lib/librte_eal/common/include/rte_pci.h | 45 ++++++++++------
 5 files changed, 235 insertions(+), 32 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_bus.h
lib/librte_eal/common/eal_bus.h new file +45 -0
new file mode 100644
index 0000000..4148f16
@@ -0,0 +1,45 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright 2017 6WIND S.A.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of 6WIND S.A. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _EAL_BUS_H_
+#define _EAL_BUS_H_
+
+#include <sys/queue.h>
+
+#include <rte_bus.h>
+
+/* Private bus list */
+extern struct rte_bus_list rte_bus_list;
+
+#define FOREACH_BUS(bus_p)	TAILQ_FOREACH(bus_p, &rte_bus_list, next)
+
+#endif /* _EAL_BUS_H_ */
lib/librte_eal/common/eal_common_dev.c +45 -12

101 lines not on this page · raw message

lib/librte_eal/common/eal_common_pci.c +86 -5

119 lines not on this page · raw message

lib/librte_eal/common/include/rte_bus.h +29 -0
index 7c36969..e23b9e5 100644
@@ -82,6 +82,33 @@ typedef int (*rte_bus_scan_t)(void);
 typedef int (*rte_bus_probe_t)(void);
 
 /**
+ * Attach a device to a bus, assuming it is 'connected' to the bus.
+ * A bus is responsible for scanning for devices. Attaching a new device is
+ * for reenabling the device after being detached/removed.
+ *
+ * @param device_name
+ *	Name of the device to attach.
+ *
+ * @return
+ *	0 for successful attach
+ *	!0 for unsuccessful attach (or incorrect device name)
+ */
+typedef int (*rte_bus_attach_t)(const char *device_name);
+
+/**
+ * Detach a named device from a bus. Implementation would check the existence
+ * of device on the bus and detach it.
+ *
+ * @param device_name
+ *	Name of the device to detach
+ *
+ * @return
+ *	0 for successful detaching
+ *	!0 if device not found or can't detach
+ */
+typedef int (*rte_bus_detach_t)(const char *device_name);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -89,6 +116,8 @@ struct rte_bus {
 	const char *name;            /**< Name of the bus */
 	rte_bus_scan_t scan;         /**< Scan for devices attached to bus */
 	rte_bus_probe_t probe;       /**< Probe devices on bus */
+	rte_bus_attach_t attach;     /**< Attach a named device */
+	rte_bus_detach_t detach;     /**< Detach a named device */
 };
 
 /**
lib/librte_eal/common/include/rte_pci.h +30 -15

57 lines not on this page · raw message

Signature · 1 line
2.1.4
#140 lore raw

Re: [PATCH v13 6/7] pci: use bus driver for attach/detach

2017-04-11 13:07, Gaetan Rivet:

lib/librte_eal/common/eal_common_dev.c rte_eal_dev_init(void) · line 137

Quoted 3 lines
lib/librte_eal/common/eal_common_dev.c +3 -0
+       if (ret > 0) {
+               /* In case the device was not found on any bus, search VDEV */
+               ret = rte_eal_vdev_init(name, devargs);

I think we should avoid to directly call a vdev function.

Anyway, Jan is preparing a new series for attach/detach rework. Let's discuss it for 17.08.

The series will be applied without this patch.

#141 lore raw

PATCH v13 7/7 doc: remove deprecation notice for rte_bus

In reply to Gaetan Rivet

From: Shreyansh Jain <[email protected]>

---
 doc/guides/rel_notes/release_17_02.rst | 2 +-
 lib/librte_eal/bsdapp/eal/Makefile     | 2 +-
 lib/librte_eal/linuxapp/eal/Makefile   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
doc/guides/rel_notes/release_17_02.rst +1 -1
index 357965a..e9d2e00 100644
@@ -357,7 +357,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_cmdline.so.2
      librte_cryptodev.so.2
      librte_distributor.so.1
-     librte_eal.so.3
+   + librte_eal.so.4
    + librte_ethdev.so.6
      librte_hash.so.2
      librte_ip_frag.so.1
lib/librte_eal/bsdapp/eal/Makefile +1 -1
index 16791df..a0f9950 100644
@@ -48,7 +48,7 @@ LDLIBS += -lgcc_s
 
 EXPORT_MAP := rte_eal_version.map
 
-LIBABIVER := 3
+LIBABIVER := 4
 
 # specific to bsdapp exec-env
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) := eal.c
lib/librte_eal/linuxapp/eal/Makefile +1 -1
index 8624ad2..640afd0 100644
@@ -37,7 +37,7 @@ ARCH_DIR ?= $(RTE_ARCH)
 EXPORT_MAP := rte_eal_version.map
 VPATH += $(RTE_SDK)/lib/librte_eal/common/arch/$(ARCH_DIR)
 
-LIBABIVER := 3
+LIBABIVER := 4
 
 VPATH += $(RTE_SDK)/lib/librte_eal/common
 
Signature · 1 line
2.1.4
#142 lore raw

Re: [PATCH v13 7/7] doc: remove deprecation notice for rte_bus

Hello Gaetan,

Quoted 8 lines · Gaetan Rivet

From: Shreyansh Jain <[email protected]>

---
 doc/guides/rel_notes/release_17_02.rst | 2 +-
 lib/librte_eal/bsdapp/eal/Makefile     | 2 +-
 lib/librte_eal/linuxapp/eal/Makefile   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

[...]

I think you removed the deprecation.rst file from original patch. In which case, the headline of the patch is now not correct.

-
Shreyansh

#143 lore raw

Re: [PATCH v13 7/7] doc: remove deprecation notice for rte_bus

Hi Shreyansh,

Quoted 12 lines · Shreyansh Jain

Hello Gaetan,

Quoted 8 lines · Gaetan Rivet

From: Shreyansh Jain <[email protected]>

---

doc/guides/rel_notes/release_17_02.rst | 2 +-
lib/librte_eal/bsdapp/eal/Makefile     | 2 +-
lib/librte_eal/linuxapp/eal/Makefile   | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
Quoted 4 lines

[...]

I think you removed the deprecation.rst file from original patch. In which case, the headline of the patch is now not correct.

Yes you're right, actually the deprecation notice had already been removed. I wanted to keep the patches the way they were as much as possible however in order for readers to be able to find the reference in the original series.

Now that you highlighted this patch, I see that I made an error by keeping the release note update in the 17.02 file instead of 17.05.

Signature · 2 lines
Gaëtan Rivet
6WIND
Acked-by on the v13 series
#144 lore raw

Re: [PATCH v13 0/7] rte_bus_pci

In reply to Gaetan Rivet
Quoted 116 lines · On Tue, 11 Apr 2017 13:07:27 +0200 Gaetan Rivet <[email protected]> wrote:

I have rebased the work done by Shreyansh and Thomas to follow the bus abstraction introduced in v17.02 for the PCI bus implementation.
This series is only a partial version of the previous one, because some of the patches have already been integrated, and others still need rework.

Additionally, Jan Blunck sent this RFC:

[RFC] eal: use busname and devargs to attach devices

That has not been considered for this version as it had not yet spawned a discussion.

changes in v13:
- Removed the PCI tests. They cannot follow the bus implementation anymore, and it is an opportunity to update their original design.
- Changed the rte_pci_match function semantic to match its name.
- Made the rte_pci_match function private.
- Made the rte_bus_list private
- Made rte_eal_pci_add_device,
rte_eal_pci_insert_device, rte_eal_pci_remove_device,
functions private.

Additional work is needed:
- The PCI bus should be moved to the relevant bus sub-directory.
- The documentation must be updated.

But this version should allow for the PCI bus implementation to be integrated in v17.05-rc2.

Gaetan Rivet (1):
test: remove pci tests

Shreyansh Jain (6):
pci: split match and probe
pci: remove loop over drivers in device detach
pci: add bus driver
pci: use bus driver for scan/probe
pci: use bus driver for attach/detach
doc: remove deprecation notice for rte_bus

 MAINTAINERS                                        |   2 -
 doc/guides/rel_notes/release_17_02.rst             |   2 +-
 lib/librte_eal/bsdapp/eal/Makefile                 |   2 +-
 lib/librte_eal/bsdapp/eal/eal.c                    |  14 -
 lib/librte_eal/bsdapp/eal/eal_pci.c                |  34 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map      |   2 -
 lib/librte_eal/common/eal_bus.h                    |  45 +++
 lib/librte_eal/common/eal_common_dev.c             |  57 +++-
 lib/librte_eal/common/eal_common_pci.c             | 362 +++++++++++++--------
 lib/librte_eal/common/eal_private.h                |  41 ++-
 lib/librte_eal/common/include/rte_bus.h            |  29 ++
 lib/librte_eal/common/include/rte_pci.h            |  94 ++++--
 lib/librte_eal/linuxapp/eal/Makefile               |   2 +-
 lib/librte_eal/linuxapp/eal/eal.c                  |  14 -
 lib/librte_eal/linuxapp/eal/eal_pci.c              |  38 +--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map    |   2 -
 test/test/Makefile                                 |   2 -
 test/test/test.h                                   |   3 -
 test/test/test_mp_secondary.c                      |  17 -
 test/test/test_pci.c                               | 322 ------------------
 .../bus/pci/devices/0000:01:00.0/class             |   1 -
 .../bus/pci/devices/0000:01:00.0/config            | Bin 64 -> 0 bytes
 .../devices/0000:01:00.0/consistent_dma_mask_bits  |   1 -
 .../bus/pci/devices/0000:01:00.0/device            |   1 -
 .../bus/pci/devices/0000:01:00.0/dma_mask_bits     |   1 -
 .../bus/pci/devices/0000:01:00.0/enable            |   1 -
 .../bus/pci/devices/0000:01:00.0/irq               |   1 -
 .../bus/pci/devices/0000:01:00.0/modalias          |   1 -
 .../bus/pci/devices/0000:01:00.0/msi_bus           |   1 -
 .../bus/pci/devices/0000:01:00.0/numa_node         |   1 -
 .../bus/pci/devices/0000:01:00.0/resource          |  13 -
 .../bus/pci/devices/0000:01:00.0/sriov_numvfs      |   1 -
 .../bus/pci/devices/0000:01:00.0/sriov_totalvfs    |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:00.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:00.0/uevent            |   6 -
 .../bus/pci/devices/0000:01:00.0/vendor            |   1 -
 .../bus/pci/devices/0000:01:02.0/class             |   1 -
 .../bus/pci/devices/0000:01:02.0/device            |   1 -
 .../bus/pci/devices/0000:01:02.0/resource          |  13 -
 .../bus/pci/devices/0000:01:02.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:01:02.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:01:02.0/vendor            |   1 -
 .../bus/pci/devices/0000:02:ab.0/class             |   1 -
 .../bus/pci/devices/0000:02:ab.0/device            |   1 -
 .../bus/pci/devices/0000:02:ab.0/resource          |  13 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_device  |   1 -
 .../bus/pci/devices/0000:02:ab.0/subsystem_vendor  |   1 -
 .../bus/pci/devices/0000:02:ab.0/vendor            |   1 -
 49 files changed, 478 insertions(+), 675 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_bus.h
 delete mode 100644 test/test/test_pci.c
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/config
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/consistent_dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/dma_mask_bits
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/enable
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/irq
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/modalias
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/msi_bus
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/numa_node
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_numvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/sriov_totalvfs
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/uevent
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:00.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_device
Quoted 9 lines
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:01:02.0/vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/class
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/resource
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_device
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/subsystem_vendor
 delete mode 100644 test/test/test_pci_sysfs/bus/pci/devices/0000:02:ab.0/vendor

Looks good. Removing dependencies on PCI is part of the roadblocks in supporting Hyper-V/VMBUS and Xen netfront properly.

#145 lore raw

Re: [PATCH v13 0/7] rte_bus_pci

2017-04-12 09:09, Stephen Hemminger:

Quoted 46 lines
Quoted 35 lines · On Tue, 11 Apr 2017 13:07:27 +0200 Gaetan Rivet <[email protected]> wrote:

I have rebased the work done by Shreyansh and Thomas to follow the bus abstraction introduced in v17.02 for the PCI bus implementation.
This series is only a partial version of the previous one, because some of the patches have already been integrated, and others still need rework.

Additionally, Jan Blunck sent this RFC:

[RFC] eal: use busname and devargs to attach devices

That has not been considered for this version as it had not yet spawned a discussion.

changes in v13:
- Removed the PCI tests. They cannot follow the bus implementation anymore, and it is an opportunity to update their original design.
- Changed the rte_pci_match function semantic to match its name.
- Made the rte_pci_match function private.
- Made the rte_bus_list private
- Made rte_eal_pci_add_device,
rte_eal_pci_insert_device, rte_eal_pci_remove_device,
functions private.

Additional work is needed:
- The PCI bus should be moved to the relevant bus sub-directory.
- The documentation must be updated.

But this version should allow for the PCI bus implementation to be integrated in v17.05-rc2.

Gaetan Rivet (1):
test: remove pci tests

Quoted 7 lines

Shreyansh Jain (6):
pci: split match and probe
pci: remove loop over drivers in device detach
pci: add bus driver
pci: use bus driver for scan/probe
pci: use bus driver for attach/detach
doc: remove deprecation notice for rte_bus

Quoted 4 lines

Looks good. Removing dependencies on PCI is part of the roadblocks in supporting Hyper-V/VMBUS and Xen netfront properly.

Applied without the attach/detach patch because it requires more work. Thanks everybody