[v6,1/4] ethdev: Add eal device event callback

Message ID 1534503016-31805-2-git-send-email-jia.guo@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series Install eal event handler in i40e/ixgbe |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Guo, Jia Aug. 17, 2018, 10:50 a.m. UTC
  Implement a couple of eal device event handler install/unintall APIs in
Ethdev as below:
 - rte_eth_dev_event_handler_install
 - rte_eth_dev_event_handler_uninstall

Each ethdev could call these APIs to install eal event handler in the PMDs,
with each callback corresponding to one port, and process the eal device
event for the specific port. Especially, it could use for process the
hotplug event.

Signed-off-by: Jeff Guo <jia.guo@intel.com>
Reviewed-by: Qi Zhang <qi.z.zhang@intel.com>
---
v6->v5:
refine commit log
---
 doc/guides/rel_notes/release_18_08.rst   | 12 +++++++
 lib/librte_ethdev/rte_ethdev.c           | 61 ++++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev_driver.h    | 32 +++++++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |  2 ++
 4 files changed, 107 insertions(+)
  

Patch

diff --git a/doc/guides/rel_notes/release_18_08.rst b/doc/guides/rel_notes/release_18_08.rst
index 95dc1e0..90478cf 100644
--- a/doc/guides/rel_notes/release_18_08.rst
+++ b/doc/guides/rel_notes/release_18_08.rst
@@ -122,6 +122,18 @@  New Features
   ``rte_dev_hotplug_handle_enable`` and ``rte_dev_hotplug_handle_disable`` are
   for enable or disable failure handle mechanism for hotplug.
 
+* **Added eal device event process helper in ethdev.**
+
+  Implement a couple of eal device event handler install/uninstall APIs in
+  ethdev, these helper could let PMDs have chance to manage the eal device
+  event, such as register device event callback, then monitor and process
+  hotplug event.
+
+  * ``rte_eth_dev_event_handler_install`` for PMDs use to install the device
+    event handler.
+  * ``rte_eth_dev_event_handler_uninstall`` for PMDs use to uninstall the device
+    event handler.
+
 
 API Changes
 -----------
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 4c32025..d68bd4c 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -4417,6 +4417,67 @@  rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da)
 	return result;
 }
 
+static void __rte_experimental
+eth_dev_event_callback(char *device_name, enum rte_dev_event_type type,
+		       void *arg)
+{
+	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)arg;
+
+	switch (type) {
+	case RTE_DEV_EVENT_REMOVE:
+		RTE_ETHDEV_LOG(INFO, "The device %s has been removed!\n",
+			       device_name);
+
+		if (!device_name || !eth_dev)
+			return;
+
+		if (!(eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))
+			return;
+
+		if (!strcmp(device_name, eth_dev->device->name))
+			_rte_eth_dev_callback_process(eth_dev,
+						      RTE_ETH_EVENT_INTR_RMV,
+						      NULL);
+		break;
+	case RTE_DEV_EVENT_ADD:
+		RTE_ETHDEV_LOG(INFO, "The device %s has been added!\n",
+			       device_name);
+		break;
+	default:
+		break;
+	}
+}
+
+int __rte_experimental
+rte_eth_dev_event_handler_install(struct rte_eth_dev *eth_dev)
+{
+	int result = 0;
+
+	result = rte_dev_event_callback_register(eth_dev->device->name,
+						 eth_dev_event_callback,
+						 eth_dev);
+	if (result)
+		RTE_ETHDEV_LOG(ERR, "device event callback register failed "
+			       "for device:%s!\n", eth_dev->device->name);
+
+	return result;
+}
+
+int __rte_experimental
+rte_eth_dev_event_handler_uninstall(struct rte_eth_dev *eth_dev)
+{
+	int result = 0;
+
+	result = rte_dev_event_callback_unregister(eth_dev->device->name,
+						   eth_dev_event_callback,
+						   eth_dev);
+	if (result)
+		RTE_ETHDEV_LOG(ERR, "device event callback unregister failed "
+			       "for device:%s!\n", eth_dev->device->name);
+
+	return result;
+}
+
 RTE_INIT(ethdev_init_log)
 {
 	rte_eth_dev_logtype = rte_log_register("lib.ethdev");
diff --git a/lib/librte_ethdev/rte_ethdev_driver.h b/lib/librte_ethdev/rte_ethdev_driver.h
index c6d9bc1..7e3d085 100644
--- a/lib/librte_ethdev/rte_ethdev_driver.h
+++ b/lib/librte_ethdev/rte_ethdev_driver.h
@@ -81,6 +81,38 @@  int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
 void _rte_eth_dev_reset(struct rte_eth_dev *dev);
 
 /**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Implement a helper to install the device event handler for the specific
+ * ether device.
+ *
+ * @param dev
+ *  Pointer to struct rte_eth_dev.
+ *
+ * @return
+ *   - 0 on success, negative on error
+ */
+int __rte_experimental
+rte_eth_dev_event_handler_install(struct rte_eth_dev *dev);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Implement a helper to uninstall the device event handler for the specific
+ * ether device.
+ *
+ * @param dev
+ *  Pointer to struct rte_eth_dev.
+ *
+ * @return
+ *   - 0 on success, negative on error
+ */
+int __rte_experimental
+rte_eth_dev_event_handler_uninstall(struct rte_eth_dev *dev);
+
+/**
  * @internal Executes all the user application registered callbacks for
  * the specific device. It is for DPDK internal user only. User
  * application should not call it directly.
diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map
index 38f117f..3cc02b6 100644
--- a/lib/librte_ethdev/rte_ethdev_version.map
+++ b/lib/librte_ethdev/rte_ethdev_version.map
@@ -227,6 +227,8 @@  EXPERIMENTAL {
 	rte_eth_dev_count_total;
 	rte_eth_dev_create;
 	rte_eth_dev_destroy;
+	rte_eth_dev_event_handler_install;
+	rte_eth_dev_event_handler_uninstall;
 	rte_eth_dev_get_module_eeprom;
 	rte_eth_dev_get_module_info;
 	rte_eth_dev_is_removed;