From: David Marchand <david.march...@6wind.com>

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 at 6wind.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain at nxp.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 ++++
 lib/librte_eal/common/eal_common_dev.c          | 48 +++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_dev.h         | 26 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 ++++
 4 files changed, 88 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map 
b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index a335e04..7b3d409 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -162,3 +162,10 @@ DPDK_16.07 {
        rte_thread_setname;

 } DPDK_16.04;
+
+DPDK_16.11 {
+       global:
+
+       rte_eal_dev_attach;
+       rte_eal_dev_detach;
+} DPDK_16.07;
diff --git a/lib/librte_eal/common/eal_common_dev.c 
b/lib/librte_eal/common/eal_common_dev.c
index a8a4146..88f9d3f 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -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;
+}
diff --git a/lib/librte_eal/common/include/rte_dev.h 
b/lib/librte_eal/common/include/rte_dev.h
index 94ae14e..6cc9b01 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -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) \
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map 
b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index db8c984..c0bd391 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -166,3 +166,10 @@ DPDK_16.07 {
        rte_thread_setname;

 } DPDK_16.04;
+
+DPDK_16.11 {
+       global:
+
+       rte_eal_dev_attach;
+       rte_eal_dev_detach;
+} DPDK_16.07;
-- 
2.7.4

Reply via email to