pci: remove eal prefix
[dpdk.git] / lib / librte_eal / common / eal_common_dev.c
index 92a5a94..a7a2c4b 100644 (file)
 
 #include "eal_private.h"
 
-/** Global list of device drivers. */
-static struct rte_driver_list dev_driver_list =
-       TAILQ_HEAD_INITIALIZER(dev_driver_list);
-
-/* register a driver */
-void
-rte_eal_driver_register(struct rte_driver *driver)
-{
-       TAILQ_INSERT_TAIL(&dev_driver_list, driver, next);
-}
-
-/* unregister a driver */
-void
-rte_eal_driver_unregister(struct rte_driver *driver)
+int rte_eal_dev_attach(const char *name, const char *devargs)
 {
-       TAILQ_REMOVE(&dev_driver_list, driver, next);
-}
+       struct rte_pci_addr addr;
 
-int
-rte_eal_vdev_init(const char *name, const char *args)
-{
-       struct rte_driver *driver;
-
-       if (name == NULL)
+       if (name == NULL || devargs == NULL) {
+               RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n");
                return -EINVAL;
-
-       TAILQ_FOREACH(driver, &dev_driver_list, next) {
-               if (driver->type != PMD_VDEV)
-                       continue;
-
-               /*
-                * search a driver prefix in virtual device name.
-                * For example, if the driver is pcap PMD, driver->name
-                * will be "eth_pcap", but "name" will be "eth_pcapN".
-                * So use strncmp to compare.
-                */
-               if (!strncmp(driver->name, name, strlen(driver->name)))
-                       return driver->init(name, args);
        }
 
-       RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-       return -EINVAL;
-}
-
-int
-rte_eal_dev_init(void)
-{
-       struct rte_devargs *devargs;
-       struct rte_driver *driver;
-
-       /*
-        * Note that the dev_driver_list is populated here
-        * from calls made to rte_eal_driver_register from constructor functions
-        * embedded into PMD modules via the PMD_REGISTER_DRIVER macro
-        */
+       if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+               if (rte_pci_probe_one(&addr) < 0)
+                       goto err;
 
-       /* call the init function for each virtual device */
-       TAILQ_FOREACH(devargs, &devargs_list, next) {
-
-               if (devargs->type != RTE_DEVTYPE_VIRTUAL)
-                       continue;
-
-               if (rte_eal_vdev_init(devargs->virtual.drv_name,
-                                       devargs->args)) {
-                       RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-                                       devargs->virtual.drv_name);
-                       return -1;
-               }
+       } else {
+               if (rte_eal_vdev_init(name, devargs))
+                       goto err;
        }
 
-       /* Once the vdevs are initalized, start calling all the pdev drivers */
-       TAILQ_FOREACH(driver, &dev_driver_list, next) {
-               if (driver->type != PMD_PDEV)
-                       continue;
-               /* PDEV drivers don't get passed any parameters */
-               driver->init(NULL, NULL);
-       }
        return 0;
+
+err:
+       RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name);
+       return -EINVAL;
 }
 
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-int
-rte_eal_vdev_uninit(const char *name)
+int rte_eal_dev_detach(const char *name)
 {
-       struct rte_driver *driver;
+       struct rte_pci_addr addr;
 
-       if (name == NULL)
+       if (name == NULL) {
+               RTE_LOG(ERR, EAL, "Invalid device provided.\n");
                return -EINVAL;
+       }
 
-       TAILQ_FOREACH(driver, &dev_driver_list, next) {
-               if (driver->type != PMD_VDEV)
-                       continue;
-
-               /*
-                * search a driver prefix in virtual device name.
-                * For example, if the driver is pcap PMD, driver->name
-                * will be "eth_pcap", but "name" will be "eth_pcapN".
-                * So use strncmp to compare.
-                */
-               if (!strncmp(driver->name, name, strlen(driver->name)))
-                       return driver->uninit(name);
+       if (eal_parse_pci_DomBDF(name, &addr) == 0) {
+               if (rte_pci_detach(&addr) < 0)
+                       goto err;
+       } else {
+               if (rte_eal_vdev_uninit(name))
+                       goto err;
        }
+       return 0;
 
-       RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+err:
+       RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name);
        return -EINVAL;
 }
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */