pci: align bsd implementation on linux
authorDavid Marchand <david.marchand@6wind.com>
Fri, 9 May 2014 13:15:54 +0000 (15:15 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 13 May 2014 11:20:29 +0000 (13:20 +0200)
bsd implementation lacks check on driver flags, fix this.
Besides, check on BAR0 is not needed and could cause trouble for devices that
have no BAR0.

Signed-off-by: David Marchand <david.marchand@6wind.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
lib/librte_eal/bsdapp/eal/eal_pci.c

index 987b446..5d8bcbd 100644 (file)
@@ -108,8 +108,14 @@ TAILQ_HEAD(uio_res_list, uio_resource);
 
 static struct uio_res_list *uio_res_list = NULL;
 
-/* forward prototype of function called in pci_switch_module below */
-static int pci_uio_map_resource(struct rte_pci_device *dev);
+/* unbind kernel driver for this device */
+static int
+pci_unbind_kernel_driver(struct rte_pci_device *dev)
+{
+       RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
+               "for BSD\n");
+       return -ENOTSUP;
+}
 
 /* map a particular resource from a file */
 static void *
@@ -214,6 +220,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)
 
        dev->intr_handle.fd = -1;
 
+       /* secondary processes - use already recorded details */
+       if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
+               (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
+               return (pci_uio_map_secondary(dev));
+
        rte_snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
                        dev->addr.bus, dev->addr.devid, dev->addr.function);
 
@@ -223,11 +234,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)
                return -1;
        }
 
-       /* secondary processes - use already recorded details */
-       if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
-               (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
-               return (pci_uio_map_secondary(dev));
-
        if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) {
                /* I/O port address already assigned */
                /* rte_virtio_pmd does not need any other bar even if available */
@@ -479,19 +485,17 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
                        return 0;
                }
 
-               /* just map the NIC resources */
-               if (pci_uio_map_resource(dev) < 0)
-                       return -1;
-
-               /* We always should have BAR0 mapped */
-               if (rte_eal_process_type() == RTE_PROC_PRIMARY && 
-                       dev->mem_resource[0].addr == NULL) {
-                       RTE_LOG(ERR, EAL,
-                               "%s(): BAR0 is not mapped\n",
-                               __func__);
-                       return (-1);
+               if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) {
+                       /* map resources for devices that use igb_uio */
+                       if (pci_uio_map_resource(dev) < 0)
+                               return -1;
+               } else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
+                          rte_eal_process_type() == RTE_PROC_PRIMARY) {
+                       /* unbind current driver */
+                       if (pci_unbind_kernel_driver(dev) < 0)
+                               return -1;
                }
+
                /* reference driver structure */
                dev->driver = dr;