DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jerin Jacob <jerin.jacob@caviumnetworks.com>
To: <dev@dpdk.org>
Cc: <thomas.monjalon@6wind.com>, <bruce.richardson@intel.com>,
	<hemant.agrawal@nxp.com>, <gage.eads@intel.com>,
	<harry.van.haaren@intel.com>,
	Jerin Jacob <jerin.jacob@caviumnetworks.com>
Subject: [dpdk-dev] [PATCH v3 4/6] eventdev: implement PMD registration functions
Date: Sun, 18 Dec 2016 19:51:33 +0530	[thread overview]
Message-ID: <1482070895-32491-5-git-send-email-jerin.jacob@caviumnetworks.com> (raw)
In-Reply-To: <1482070895-32491-1-git-send-email-jerin.jacob@caviumnetworks.com>

This patch adds infrastructure for registering the vdev or
the PCI based event device.

Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
---
 lib/librte_eventdev/rte_eventdev.c           | 236 +++++++++++++++++++++++++++
 lib/librte_eventdev/rte_eventdev_pmd.h       | 111 +++++++++++++
 lib/librte_eventdev/rte_eventdev_version.map |   6 +
 3 files changed, 353 insertions(+)

diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c
index 92424dc..582de96 100644
--- a/lib/librte_eventdev/rte_eventdev.c
+++ b/lib/librte_eventdev/rte_eventdev.c
@@ -124,6 +124,8 @@ rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info)
 	(*dev->dev_ops->dev_infos_get)(dev, dev_info);
 
 	dev_info->pci_dev = dev->pci_dev;
+	if (dev->driver)
+		dev_info->driver_name = dev->driver->pci_drv.driver.name;
 	return 0;
 }
 
@@ -982,3 +984,237 @@ rte_event_dev_close(uint8_t dev_id)
 
 	return (*dev->dev_ops->dev_close)(dev);
 }
+
+static inline int
+rte_eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data,
+		int socket_id)
+{
+	char mz_name[RTE_EVENTDEV_NAME_MAX_LEN];
+	const struct rte_memzone *mz;
+	int n;
+
+	/* Generate memzone name */
+	n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id);
+	if (n >= (int)sizeof(mz_name))
+		return -EINVAL;
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		mz = rte_memzone_reserve(mz_name,
+				sizeof(struct rte_eventdev_data),
+				socket_id, 0);
+	} else
+		mz = rte_memzone_lookup(mz_name);
+
+	if (mz == NULL)
+		return -ENOMEM;
+
+	*data = mz->addr;
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+		memset(*data, 0, sizeof(struct rte_eventdev_data));
+
+	return 0;
+}
+
+static inline uint8_t
+rte_eventdev_find_free_device_index(void)
+{
+	uint8_t dev_id;
+
+	for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) {
+		if (rte_eventdevs[dev_id].attached ==
+				RTE_EVENTDEV_DETACHED)
+			return dev_id;
+	}
+	return RTE_EVENT_MAX_DEVS;
+}
+
+struct rte_eventdev *
+rte_event_pmd_allocate(const char *name, int socket_id)
+{
+	struct rte_eventdev *eventdev;
+	uint8_t dev_id;
+
+	if (rte_event_pmd_get_named_dev(name) != NULL) {
+		RTE_EDEV_LOG_ERR("Event device with name %s already "
+				"allocated!", name);
+		return NULL;
+	}
+
+	dev_id = rte_eventdev_find_free_device_index();
+	if (dev_id == RTE_EVENT_MAX_DEVS) {
+		RTE_EDEV_LOG_ERR("Reached maximum number of event devices");
+		return NULL;
+	}
+
+	eventdev = &rte_eventdevs[dev_id];
+
+	if (eventdev->data == NULL) {
+		struct rte_eventdev_data *eventdev_data = NULL;
+
+		int retval = rte_eventdev_data_alloc(dev_id, &eventdev_data,
+				socket_id);
+
+		if (retval < 0 || eventdev_data == NULL)
+			return NULL;
+
+		eventdev->data = eventdev_data;
+
+		snprintf(eventdev->data->name, RTE_EVENTDEV_NAME_MAX_LEN,
+				"%s", name);
+
+		eventdev->data->dev_id = dev_id;
+		eventdev->data->socket_id = socket_id;
+		eventdev->data->dev_started = 0;
+
+		eventdev->attached = RTE_EVENTDEV_ATTACHED;
+
+		eventdev_globals.nb_devs++;
+	}
+
+	return eventdev;
+}
+
+int
+rte_event_pmd_release(struct rte_eventdev *eventdev)
+{
+	int ret;
+
+	if (eventdev == NULL)
+		return -EINVAL;
+
+	ret = rte_event_dev_close(eventdev->data->dev_id);
+	if (ret < 0)
+		return ret;
+
+	eventdev->attached = RTE_EVENTDEV_DETACHED;
+	eventdev_globals.nb_devs--;
+	eventdev->data = NULL;
+
+	return 0;
+}
+
+struct rte_eventdev *
+rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
+		int socket_id)
+{
+	struct rte_eventdev *eventdev;
+
+	/* Allocate device structure */
+	eventdev = rte_event_pmd_allocate(name, socket_id);
+	if (eventdev == NULL)
+		return NULL;
+
+	/* Allocate private device structure */
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		eventdev->data->dev_private =
+				rte_zmalloc_socket("eventdev device private",
+						dev_private_size,
+						RTE_CACHE_LINE_SIZE,
+						socket_id);
+
+		if (eventdev->data->dev_private == NULL)
+			rte_panic("Cannot allocate memzone for private device"
+					" data");
+	}
+
+	return eventdev;
+}
+
+int
+rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
+			struct rte_pci_device *pci_dev)
+{
+	struct rte_eventdev_driver *eventdrv;
+	struct rte_eventdev *eventdev;
+
+	char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
+
+	int retval;
+
+	eventdrv = (struct rte_eventdev_driver *)pci_drv;
+	if (eventdrv == NULL)
+		return -ENODEV;
+
+	rte_eal_pci_device_name(&pci_dev->addr, eventdev_name,
+			sizeof(eventdev_name));
+
+	eventdev = rte_event_pmd_allocate(eventdev_name,
+			 pci_dev->device.numa_node);
+	if (eventdev == NULL)
+		return -ENOMEM;
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		eventdev->data->dev_private =
+				rte_zmalloc_socket(
+						"eventdev private structure",
+						eventdrv->dev_private_size,
+						RTE_CACHE_LINE_SIZE,
+						rte_socket_id());
+
+		if (eventdev->data->dev_private == NULL)
+			rte_panic("Cannot allocate memzone for private "
+					"device data");
+	}
+
+	eventdev->pci_dev = pci_dev;
+	eventdev->driver = eventdrv;
+
+	/* Invoke PMD device initialization function */
+	retval = (*eventdrv->eventdev_init)(eventdev);
+	if (retval == 0)
+		return 0;
+
+	RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)"
+			" failed", pci_drv->driver.name,
+			(unsigned int) pci_dev->id.vendor_id,
+			(unsigned int) pci_dev->id.device_id);
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+		rte_free(eventdev->data->dev_private);
+
+	eventdev->attached = RTE_EVENTDEV_DETACHED;
+	eventdev_globals.nb_devs--;
+
+	return -ENXIO;
+}
+
+int
+rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev)
+{
+	const struct rte_eventdev_driver *eventdrv;
+	struct rte_eventdev *eventdev;
+	char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN];
+	int ret;
+
+	if (pci_dev == NULL)
+		return -EINVAL;
+
+	rte_eal_pci_device_name(&pci_dev->addr, eventdev_name,
+			sizeof(eventdev_name));
+
+	eventdev = rte_event_pmd_get_named_dev(eventdev_name);
+	if (eventdev == NULL)
+		return -ENODEV;
+
+	eventdrv = (const struct rte_eventdev_driver *)pci_dev->driver;
+	if (eventdrv == NULL)
+		return -ENODEV;
+
+	/* Invoke PMD device un-init function */
+	if (*eventdrv->eventdev_uninit) {
+		ret = (*eventdrv->eventdev_uninit)(eventdev);
+		if (ret)
+			return ret;
+	}
+
+	/* Free event device */
+	rte_event_pmd_release(eventdev);
+
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+		rte_free(eventdev->data->dev_private);
+
+	eventdev->pci_dev = NULL;
+	eventdev->driver = NULL;
+
+	return 0;
+}
diff --git a/lib/librte_eventdev/rte_eventdev_pmd.h b/lib/librte_eventdev/rte_eventdev_pmd.h
index b146c5d..385272c 100644
--- a/lib/librte_eventdev/rte_eventdev_pmd.h
+++ b/lib/librte_eventdev/rte_eventdev_pmd.h
@@ -92,6 +92,60 @@ extern "C" {
 #define RTE_EVENTDEV_DETACHED  (0)
 #define RTE_EVENTDEV_ATTACHED  (1)
 
+/**
+ * Initialisation function of a event driver invoked for each matching
+ * event PCI device detected during the PCI probing phase.
+ *
+ * @param dev
+ *   The dev pointer is the address of the *rte_eventdev* structure associated
+ *   with the matching device and which has been [automatically] allocated in
+ *   the *rte_event_devices* array.
+ *
+ * @return
+ *   - 0: Success, the device is properly initialised by the driver.
+ *        In particular, the driver MUST have set up the *dev_ops* pointer
+ *        of the *dev* structure.
+ *   - <0: Error code of the device initialisation failure.
+ */
+typedef int (*eventdev_init_t)(struct rte_eventdev *dev);
+
+/**
+ * Finalisation function of a driver invoked for each matching
+ * PCI device detected during the PCI closing phase.
+ *
+ * @param dev
+ *   The dev pointer is the address of the *rte_eventdev* structure associated
+ *   with the matching device and which	has been [automatically] allocated in
+ *   the *rte_event_devices* array.
+ *
+ * @return
+ *   - 0: Success, the device is properly finalised by the driver.
+ *        In particular, the driver MUST free the *dev_ops* pointer
+ *        of the *dev* structure.
+ *   - <0: Error code of the device initialisation failure.
+ */
+typedef int (*eventdev_uninit_t)(struct rte_eventdev *dev);
+
+/**
+ * The structure associated with a PMD driver.
+ *
+ * Each driver acts as a PCI driver and is represented by a generic
+ * *event_driver* structure that holds:
+ *
+ * - An *rte_pci_driver* structure (which must be the first field).
+ *
+ * - The *eventdev_init* function invoked for each matching PCI device.
+ *
+ * - The size of the private data to allocate for each matching device.
+ */
+struct rte_eventdev_driver {
+	struct rte_pci_driver pci_drv;	/**< The PMD is also a PCI driver. */
+	unsigned int dev_private_size;	/**< Size of device private data. */
+
+	eventdev_init_t eventdev_init;	/**< Device init function. */
+	eventdev_uninit_t eventdev_uninit; /**< Device uninit function. */
+};
+
 /** Global structure used for maintaining state of allocated event devices */
 struct rte_eventdev_global {
 	uint8_t nb_devs;	/**< Number of devices found */
@@ -393,6 +447,63 @@ struct rte_eventdev_ops {
 	/* Dump internal information */
 };
 
+/**
+ * Allocates a new eventdev slot for an event device and returns the pointer
+ * to that slot for the driver to use.
+ *
+ * @param name
+ *   Unique identifier name for each device
+ * @param socket_id
+ *   Socket to allocate resources on.
+ * @return
+ *   - Slot in the rte_dev_devices array for a new device;
+ */
+struct rte_eventdev *
+rte_event_pmd_allocate(const char *name, int socket_id);
+
+/**
+ * Release the specified eventdev device.
+ *
+ * @param eventdev
+ * The *eventdev* pointer is the address of the *rte_eventdev* structure.
+ * @return
+ *   - 0 on success, negative on error
+ */
+int
+rte_event_pmd_release(struct rte_eventdev *eventdev);
+
+/**
+ * Creates a new virtual event device and returns the pointer to that device.
+ *
+ * @param name
+ *   PMD type name
+ * @param dev_private_size
+ *   Size of event PMDs private data
+ * @param socket_id
+ *   Socket to allocate resources on.
+ *
+ * @return
+ *   - Eventdev pointer if device is successfully created.
+ *   - NULL if device cannot be created.
+ */
+struct rte_eventdev *
+rte_event_pmd_vdev_init(const char *name, size_t dev_private_size,
+		int socket_id);
+
+
+/**
+ * Wrapper for use by pci drivers as a .probe function to attach to a event
+ * interface.
+ */
+int rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv,
+			    struct rte_pci_device *pci_dev);
+
+/**
+ * Wrapper for use by pci drivers as a .remove function to detach a event
+ * interface.
+ */
+int rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eventdev/rte_eventdev_version.map b/lib/librte_eventdev/rte_eventdev_version.map
index 3cae03d..68b8c81 100644
--- a/lib/librte_eventdev/rte_eventdev_version.map
+++ b/lib/librte_eventdev/rte_eventdev_version.map
@@ -29,5 +29,11 @@ DPDK_17.02 {
 
 	rte_event_dequeue_timeout_ticks;
 
+	rte_event_pmd_allocate;
+	rte_event_pmd_release;
+	rte_event_pmd_vdev_init;
+	rte_event_pmd_pci_probe;
+	rte_event_pmd_pci_remove;
+
 	local: *;
 };
-- 
2.5.5

  parent reply	other threads:[~2016-12-18 14:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-20  8:00 [dpdk-dev] [PATCH] eal: postpone vdev initialization Jerin Jacob
2016-11-20 16:05 ` David Marchand
2016-11-21  5:09 ` Shreyansh Jain
2016-11-21 16:56   ` Jerin Jacob
2016-11-21  9:54 ` Ferruh Yigit
2016-11-21 17:02   ` Jerin Jacob
2016-11-21 17:35     ` Ferruh Yigit
2016-11-23  0:07       ` Jerin Jacob
2016-11-23 13:29         ` Thomas Monjalon
2016-12-03 20:55 ` [dpdk-dev] [PATCH v2 0/2] " Jerin Jacob
2016-12-03 20:55   ` [dpdk-dev] [PATCH v2 1/2] eal: " Jerin Jacob
2016-12-03 20:55   ` [dpdk-dev] [PATCH v2 2/2] eal: rename dev init API for consistency Jerin Jacob
2016-12-05 10:12     ` Shreyansh Jain
2016-12-05 10:24       ` Jerin Jacob
2016-12-05 14:03         ` Shreyansh Jain
2016-12-18 14:21   ` [dpdk-dev] [PATCH v3 0/6] libeventdev API and northbound implementation Jerin Jacob
2016-12-18 14:21     ` [dpdk-dev] [PATCH v3 1/6] eventdev: introduce event driven programming model Jerin Jacob
2016-12-18 14:21     ` [dpdk-dev] [PATCH v3 2/6] eventdev: define southbound driver interface Jerin Jacob
2016-12-19 15:50       ` Bruce Richardson
2016-12-18 14:21     ` [dpdk-dev] [PATCH v3 3/6] eventdev: implement the northbound APIs Jerin Jacob
2016-12-18 14:21     ` Jerin Jacob [this message]
2016-12-18 14:21     ` [dpdk-dev] [PATCH v3 5/6] event/skeleton: add skeleton eventdev driver Jerin Jacob
2016-12-19 11:58       ` Bruce Richardson
2016-12-18 14:21     ` [dpdk-dev] [PATCH v3 6/6] app/test: unit test case for eventdev APIs Jerin Jacob
2016-12-19  5:16     ` [dpdk-dev] [PATCH v3 0/6] libeventdev API and northbound implementation Shreyansh Jain
2016-12-20 11:13     ` Bruce Richardson
2016-12-20 13:09       ` Jerin Jacob
2016-12-20 13:22         ` Bruce Richardson
2017-01-11 15:52           ` Jerin Jacob
2016-12-21 14:39   ` [dpdk-dev] [PATCH v2 0/2] postpone vdev initialization Thomas Monjalon
2016-12-21 14:42 ` [dpdk-dev] [PATCH] eal: " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482070895-32491-5-git-send-email-jerin.jacob@caviumnetworks.com \
    --to=jerin.jacob@caviumnetworks.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=gage.eads@intel.com \
    --cc=harry.van.haaren@intel.com \
    --cc=hemant.agrawal@nxp.com \
    --cc=thomas.monjalon@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).