[dpdk-dev,v3,1/3] nic_uio: Fix to allow any device to be bound to nic_uio

Message ID 5e6315c050b27539d567799a5b35c8cc9395cacf.1437392218.git.rahul.lakkireddy@chelsio.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Rahul Lakkireddy July 20, 2015, 5:31 p.m. UTC
nic_uio requires the pci ids to be present in rte_pci_dev_ids.h in order to
bind the devices to nic_uio.  However, it's better to remove this whitelist of
pci ids, and instead rely on hw.nic_uio.bdfs kenv parameter to allow binding
any device to nic_uio.

Suggested-by: David Marchand <david.marchand@6wind.com>
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Signed-off-by: Kumar Sanghvi <kumaras@chelsio.com>
---
v3:
- Use checks for bus, slot, and function info instead of vendor and device
  during nic_uio probe for better consistency.

v2:
- Replace "Intel(R) DPDK" with just "DPDK" in device description for nic_uio.

 lib/librte_eal/bsdapp/nic_uio/nic_uio.c | 54 +++++++++++----------------------
 1 file changed, 18 insertions(+), 36 deletions(-)
  

Comments

David Marchand July 21, 2015, 6:14 a.m. UTC | #1
On Mon, Jul 20, 2015 at 7:31 PM, Rahul Lakkireddy <
rahul.lakkireddy@chelsio.com> wrote:

> nic_uio requires the pci ids to be present in rte_pci_dev_ids.h in order to
> bind the devices to nic_uio.  However, it's better to remove this
> whitelist of
> pci ids, and instead rely on hw.nic_uio.bdfs kenv parameter to allow
> binding
> any device to nic_uio.
>
> Suggested-by: David Marchand <david.marchand@6wind.com>
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> Signed-off-by: Kumar Sanghvi <kumaras@chelsio.com>
> ---
> v3:
> - Use checks for bus, slot, and function info instead of vendor and device
>   during nic_uio probe for better consistency.
>

Looks good to me.
Acked-by: David Marchand <david.marchand@6wind.com>

Thanks Rahul.
  

Patch

diff --git a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c b/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
index 2354e84..99a4975 100644
--- a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
+++ b/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
@@ -106,24 +106,6 @@  struct pci_bdf {
 	uint32_t function;
 };
 
-
-#define RTE_PCI_DEV_ID_DECL_EM(vend, dev)      {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_IGB(vend, dev)     {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev)   {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev)   {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_IXGBEVF(vend, dev) {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_I40E(vend, dev)    {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_I40EVF(vend, dev)  {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_VIRTIO(vend, dev)  {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_VMXNET3(vend, dev) {vend, dev},
-#define RTE_PCI_DEV_ID_DECL_ENIC(vend, dev)    {vend, dev},
-
-const struct device devices[] = {
-#include <rte_pci_dev_ids.h>
-};
-#define NUM_DEVICES (sizeof(devices)/sizeof(devices[0]))
-
-
 static devclass_t nic_uio_devclass;
 
 DEFINE_CLASS_0(nic_uio, nic_uio_driver, nic_uio_methods, sizeof(struct nic_uio_softc));
@@ -194,12 +176,15 @@  static int
 nic_uio_probe (device_t dev)
 {
 	int i;
-
-	for (i = 0; i < NUM_DEVICES; i++)
-		if (pci_get_vendor(dev) == devices[i].vend &&
-			pci_get_device(dev) == devices[i].dev) {
-
-			device_set_desc(dev, "Intel(R) DPDK PCI Device");
+	unsigned int bus = pci_get_bus(dev);
+	unsigned int device = pci_get_slot(dev);
+	unsigned int function = pci_get_function(dev);
+
+	for (i = 0; i < num_detached; i++)
+		if (bus == pci_get_bus(detached_devices[i]) &&
+		    device == pci_get_slot(detached_devices[i]) &&
+		    function == pci_get_function(detached_devices[i])) {
+			device_set_desc(dev, "DPDK PCI Device");
 			return BUS_PROBE_SPECIFIC;
 		}
 
@@ -256,7 +241,6 @@  static void
 nic_uio_load(void)
 {
 	uint32_t bus, device, function;
-	int i;
 	device_t dev;
 	char bdf_str[256];
 	char *token, *remaining;
@@ -295,17 +279,15 @@  nic_uio_load(void)
 		if (dev == NULL)
 			continue;
 
-		for (i = 0; i < NUM_DEVICES; i++)
-			if (pci_get_vendor(dev) == devices[i].vend &&
-					pci_get_device(dev) == devices[i].dev) {
-						if (num_detached < MAX_DETACHED_DEVICES) {
-							printf("nic_uio_load: detaching and storing dev=%p\n", dev);
-							detached_devices[num_detached++] = dev;
-						} else
-							printf("nic_uio_load: reached MAX_DETACHED_DEVICES=%d. dev=%p won't be reattached\n",
-								MAX_DETACHED_DEVICES, dev);
-						device_detach(dev);
-			}
+		if (num_detached < MAX_DETACHED_DEVICES) {
+			printf("nic_uio_load: detaching and storing dev=%p\n",
+			       dev);
+			detached_devices[num_detached++] = dev;
+		} else {
+			printf("nic_uio_load: reached MAX_DETACHED_DEVICES=%d. dev=%p won't be reattached\n",
+			       MAX_DETACHED_DEVICES, dev);
+		}
+		device_detach(dev);
 	}
 }