eal: add hotplug operations for PCI and vdev
authorDavid Marchand <david.marchand@6wind.com>
Tue, 20 Sep 2016 12:41:24 +0000 (18:11 +0530)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Mon, 3 Oct 2016 14:33:32 +0000 (16:33 +0200)
Hotplug invocations, which deals with devices, should come from the layer
that already handles them, i.e. EAL.

For both attach and detach operations, 'name' is used to select the bus
that will handle the request.

Signed-off-by: David Marchand <david.marchand@6wind.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
lib/librte_eal/bsdapp/eal/rte_eal_version.map
lib/librte_eal/common/eal_common_dev.c
lib/librte_eal/common/include/rte_dev.h
lib/librte_eal/linuxapp/eal/rte_eal_version.map

index a06acc1..fa8a138 100644 (file)
@@ -168,5 +168,7 @@ DPDK_16.11 {
 
        rte_delay_us_block;
        rte_delay_us_callback_register;
+       rte_eal_dev_attach;
+       rte_eal_dev_detach;
 
 } DPDK_16.07;
index a8a4146..88f9d3f 100644 (file)
@@ -150,3 +150,51 @@ rte_eal_vdev_uninit(const char *name)
        RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
        return -EINVAL;
 }
+
+int rte_eal_dev_attach(const char *name, const char *devargs)
+{
+       struct rte_pci_addr addr;
+
+       if (name == 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;
+
+       } else {
+               if (rte_eal_vdev_init(name, devargs))
+                       goto err;
+       }
+
+       return 0;
+
+err:
+       RTE_LOG(ERR, EAL, "Driver cannot attach the device (%s)\n", name);
+       return -EINVAL;
+}
+
+int rte_eal_dev_detach(const char *name)
+{
+       struct rte_pci_addr addr;
+
+       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)
+                       goto err;
+       } else {
+               if (rte_eal_vdev_uninit(name))
+                       goto err;
+       }
+       return 0;
+
+err:
+       RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", name);
+       return -EINVAL;
+}
index 94ae14e..6cc9b01 100644 (file)
@@ -178,6 +178,32 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);
 
+/**
+ * Attach a device to a registered driver.
+ *
+ * @param name
+ *   The device name, that refers to a pci device (or some private
+ *   way of designating a vdev device). Based on this device name, eal
+ *   will identify a driver capable of handling it and pass it to the
+ *   driver probing function.
+ * @param devargs
+ *   Device arguments to be passed to the driver.
+ * @return
+ *   0 on success, negative on error.
+ */
+int rte_eal_dev_attach(const char *name, const char *devargs);
+
+/**
+ * Detach a device from its driver.
+ *
+ * @param name
+ *   Same description as for rte_eal_dev_attach().
+ *   Here, eal will call the driver detaching function.
+ * @return
+ *   0 on success, negative on error.
+ */
+int rte_eal_dev_detach(const char *name);
+
 #define DRIVER_EXPORT_NAME_ARRAY(n, idx) n##idx[]
 
 #define DRIVER_EXPORT_NAME(name, idx) \
index db216cc..cdd0033 100644 (file)
@@ -172,5 +172,7 @@ DPDK_16.11 {
 
        rte_delay_us_block;
        rte_delay_us_callback_register;
+       rte_eal_dev_attach;
+       rte_eal_dev_detach;
 
 } DPDK_16.07;