pci: add flag to force unbind device
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_pci.c
index f5c5626..074d7cf 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  * 
- *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
  * 
  *   Redistribution and use in source and binary forms, with or without
@@ -493,14 +493,14 @@ pci_uio_map_resource(struct rte_pci_device *dev)
         * or uio:uioX */
 
        rte_snprintf(dirname, sizeof(dirname),
-                "/sys/bus/pci/devices/" PCI_PRI_FMT "/uio",
+                SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/uio",
                 loc->domain, loc->bus, loc->devid, loc->function);
 
        dir = opendir(dirname);
        if (dir == NULL) {
                /* retry with the parent directory */
                rte_snprintf(dirname, sizeof(dirname),
-                        "/sys/bus/pci/devices/" PCI_PRI_FMT,
+                        SYSFS_PCI_DEVICES "/" PCI_PRI_FMT,
                         loc->domain, loc->bus, loc->devid, loc->function);
                dir = opendir(dirname);
 
@@ -941,13 +941,6 @@ int
 rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
 {
        struct rte_pci_id *id_table;
-#ifdef RTE_EAL_UNBIND_PORTS
-       const char *module_name = NULL;
-       int uio_status = -1;
-
-       if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO)
-               module_name = IGB_UIO_NAME;
-#endif
 
        for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
 
@@ -981,25 +974,23 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d
                }
 
 #ifdef RTE_EAL_UNBIND_PORTS
-               /* Unbind PCI devices if needed */
-               if (module_name != NULL)
-                       if (pci_switch_module(dr, dev, uio_status, module_name) < 0)
+               if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO) {
+                       /* unbind driver and load uio resources for Intel NICs */
+                       if (pci_switch_module(dr, dev, 1, IGB_UIO_NAME) < 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;
+               }
 #else
-               /* just map the NIC resources */
-               if (pci_uio_map_resource(dev) < 0)
-                       return -1;
+               if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO)
+                       /* just map resources for Intel NICs */
+                       if (pci_uio_map_resource(dev) < 0)
+                               return -1;
 #endif
 
-               /* 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);
-               }
                /* reference driver structure */
                dev->driver = dr;