DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 4/6] eal/common: handle bus abstraction for device/driver objects
From: Shreyansh Jain @ 2016-11-17  5:30 UTC (permalink / raw)
  To: david.marchand; +Cc: dev, Shreyansh Jain
In-Reply-To: <1479360605-20558-1-git-send-email-shreyansh.jain@nxp.com>

Primary changes done by this patch are based on:
 - Devices belong to the bus hence the device list is bus instance
   specific
 - Similarly, drivers belong to the bus and thus they too are enclosed
   within the bus instance.
 - All device insertion and driver registration should proceed through
   bus APIs. A new file, eal_common_bus.c has been added for that.

Exiting driver registration and device insert/remove APIs have been
modified to work with bus on which device/driver belong. On the same
lines, the PCI common functions have been modified to work with bus rather
than device/driver directly.

rte_eal_pci_scan is no longer an exposed API. It is part of the bus
implementation. Though, probe continues to be part of the common PCI
operations.

Probe has been split into match and probe. Match has been moved to bus/*
code and is a hook now. EAL code would be modified to handle this hook.

Missing/Grey area:
 - Some API like inserting a device at a particular position in the device
   list are missing. Same for driver. These are needed for cases where
   device update is done rather than addition.
 - Probe is a property of a driver but it should be initiated from a bus,
   for example when added a new device (hotplugging). At present
   rte_driver has the probe hook. This should be wrapped around some API
   at the bus level so that bus can search through multiple drivers
   associated with it for calling probe.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_bus.c  | 188 ++++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_dev.c  |  31 +++--
 lib/librte_eal/common/eal_common_pci.c  | 226 +++++++++++++++++++-------------
 lib/librte_eal/common/include/rte_pci.h |  11 +-
 4 files changed, 342 insertions(+), 114 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_bus.c

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
new file mode 100644
index 0000000..3de1ac7
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -0,0 +1,188 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 NXP
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of NXP nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <sys/queue.h>
+
+#include <rte_dev.h>
+#include <rte_devargs.h>
+#include <rte_debug.h>
+#include <rte_devargs.h>
+#include <rte_log.h>
+
+#include "eal_private.h"
+
+/** @internal
+ * Add a device to a bus.
+ */
+void
+rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev)
+{
+	/* XXX all the additions can be address ordered ?
+	 * for example, calling rte_eal_compare_pci_addr and getting <=
+	 * and performing insert a specific location
+	 */
+	RTE_VERIFY(bus);
+	RTE_VERIFY(dev);
+
+	TAILQ_INSERT_TAIL(&bus->device_list, dev, next);
+}
+
+/** @internal
+ * Remove a device from its bus.
+ */
+void
+rte_eal_bus_remove_device(struct rte_device *dev)
+{
+	struct rte_bus *bus;
+	RTE_VERIFY(bus);
+	RTE_VERIFY(dev);
+
+	bus = dev->bus;
+	TAILQ_REMOVE(&bus->device_list, dev, next);
+}
+
+/** @internal
+ * Associate a driver with a bus.
+ */
+void
+rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv)
+{
+	RTE_VERIFY(bus);
+	RTE_VERIFY(drv);
+
+	TAILQ_INSERT_TAIL(&bus->driver_list, drv, next);
+}
+
+/** @internal
+ * Disassociate a driver from bus.
+ */
+void
+rte_eal_bus_remove_driver(struct rte_driver *drv)
+{
+	struct rte_bus *bus;
+	RTE_VERIFY(bus);
+	RTE_VERIFY(drv);
+
+	bus = drv->bus;
+	TAILQ_REMOVE(&bus->driver_list, dev, next);
+}
+
+/**
+ * Scan all the associated buses
+ */
+int
+rte_eal_bus_scan(void)
+{
+	int ret = 0;
+	struct rte_bus *bus;
+
+	if (TAILQ_EMPTY(&rte_bus_list)) {
+		return 0;
+	}
+
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		ret = bus->scan();
+		if (ret) {
+			RTE_LOG(ERR, EAL, "Scan for [%s] bus failed.\n",
+				bus->name);
+			continue; /* not a reason to break other bus scan */
+		}
+	}
+
+	/* This function essentially never returns an error - in case of error
+	 * no devices (or limited devices) are available to the application
+	 * which then can fail/report error.
+	 */
+	return 0;
+}
+
+/**
+ * Get the bus handle using its name
+ */
+struct rte_bus *
+rte_eal_get_bus(const char *bus_name)
+{
+	struct rte_bus *bus;
+
+	RTE_VERIFY(bus_name);
+
+	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		RTE_VERIFY(bus->name);
+
+		if (!strncmp(bus_name, bus->name)) {
+			RTE_LOG(DEBUG, EAL, "Returning Bus object %p\n", bus);
+			return bus;
+		}
+	}
+
+	/* Unable to find bus requested */
+	return NULL;
+}
+
+/* register a bus */
+void
+rte_eal_bus_register(struct rte_bus *bus)
+{
+	/* 3 conditions must meet:
+	 * 1. scan hook should be defined.
+	 * 2. match hook should be defined.
+	 * 3. Name should be a valid string. (valid?)
+	 */
+	RTE_VERIFY(bus);
+	RTE_VERIFY(bus->scan);
+	RTE_VERIFY(bus->probe);
+	RTE_VERIFY(bus->name && strlen(bus->name));
+
+	/* Initialize the driver and device list associated with the bus */
+	TAILQ_HEAD_INITIALIZER(&(bus->driver_list));
+	TAILQ_HEAD_INITIALIZER(&(bus->device_list));
+
+	TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
+	RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name);
+}
+
+/* unregister a bus */
+void
+rte_eal_bus_unregister(struct rte_bus *bus)
+{
+	/* All devices and drivers associated with the bus should have been
+	 * 'device->uninit' and 'driver->remove()' already.
+	 */
+	RTE_VERIFY(TAILQ_EMPTY(&(bus->driver_list)));
+	RTE_VERIFY(TAILQ_EMPTY(&(bus->device_list)));
+
+	TAILQ_REMOVE(&rte_bus_list, bus, next);
+}
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4f3b493..bb8d266 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -45,35 +45,44 @@
 
 #include "eal_private.h"
 
-/** Global list of device drivers. */
-static struct rte_driver_list dev_driver_list =
-	TAILQ_HEAD_INITIALIZER(dev_driver_list);
-/** Global list of device drivers. */
-static struct rte_device_list dev_device_list =
-	TAILQ_HEAD_INITIALIZER(dev_device_list);
-
 /* register a driver */
 void
 rte_eal_driver_register(struct rte_driver *driver)
 {
-	TAILQ_INSERT_TAIL(&dev_driver_list, driver, next);
+	struct rte_bus *bus;
+
+	RTE_VERIFY(driver && driver->bus);
+	bus = driver->bus;
+	TAILQ_INSERT_TAIL(&(bus->driver_list), driver, next);
 }
 
 /* unregister a driver */
 void
 rte_eal_driver_unregister(struct rte_driver *driver)
 {
-	TAILQ_REMOVE(&dev_driver_list, driver, next);
+	struct rte_bus;
+
+	RTE_VERIFY(driver && driver->bus);
+	bus = driver->bus;
+	TAILQ_REMOVE(&(bus->driver_list), driver, next);
 }
 
 void rte_eal_device_insert(struct rte_device *dev)
 {
-	TAILQ_INSERT_TAIL(&dev_device_list, dev, next);
+	struct rte_bus *bus;
+
+	RTE_VERIFY(dev && dev->bus);
+	bus = dev->bus;
+	TAILQ_INSERT_TAIL(&(bus->device_list), dev, next);
 }
 
 void rte_eal_device_remove(struct rte_device *dev)
 {
-	TAILQ_REMOVE(&dev_device_list, dev, next);
+	struct rte_bus *bus;
+
+	RTE_VERIFY(dev && dev->bus);
+	bus = dev->bus;
+	TAILQ_REMOVE(&(bus->device_list), dev, next);
 }
 
 int
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 971ad20..7a6d258 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -82,12 +82,13 @@
 
 #include "eal_private.h"
 
-struct pci_driver_list pci_driver_list =
-	TAILQ_HEAD_INITIALIZER(pci_driver_list);
-struct pci_device_list pci_device_list =
-	TAILQ_HEAD_INITIALIZER(pci_device_list);
-
 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
+#define PCI_BUS_NAME "pci_bus"
+
+static struct rte_bus_list pci_bus_list =
+	TAILQ_HEAD_INITIALIZER(pci_bus_list);
+
+struct rte_bus pci_bus;
 
 const char *pci_get_sysfs_path(void)
 {
@@ -160,64 +161,40 @@ static int
 rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
 {
 	int ret;
-	const struct rte_pci_id *id_table;
-
-	for (id_table = dr->id_table; id_table->vendor_id != 0; id_table++) {
-
-		/* check if device's identifiers match the driver's ones */
-		if (id_table->vendor_id != dev->id.vendor_id &&
-				id_table->vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->device_id != dev->id.device_id &&
-				id_table->device_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-				id_table->subsystem_vendor_id != PCI_ANY_ID)
-			continue;
-		if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-				id_table->subsystem_device_id != PCI_ANY_ID)
-			continue;
-		if (id_table->class_id != dev->id.class_id &&
-				id_table->class_id != RTE_CLASS_ANY_ID)
-			continue;
-
-		struct rte_pci_addr *loc = &dev->addr;
-
-		RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-				loc->domain, loc->bus, loc->devid, loc->function,
-				dev->device.numa_node);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->device.devargs != NULL &&
-			dev->device.devargs->type ==
-				RTE_DEVTYPE_BLACKLISTED_PCI) {
-			RTE_LOG(INFO, EAL, "  Device is blacklisted, not initializing\n");
-			return 1;
-		}
-
-		RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->driver.name);
+	struct rte_pci_addr *loc = &dev->addr;
+
+	RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
+			loc->domain, loc->bus, loc->devid, loc->function,
+			dev->device.numa_node);
+
+	/* no initialization when blacklisted, return without error */
+	if (dev->device.devargs != NULL &&
+		dev->device.devargs->type ==
+			RTE_DEVTYPE_BLACKLISTED_PCI) {
+		RTE_LOG(INFO, EAL, "  Device is blacklisted, not initializing\n");
+		return 1;
+	}
 
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio */
-			ret = rte_eal_pci_map_device(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-				rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
+	RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+			dev->id.device_id, dr->driver.name);
+
+	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+		/* map resources for devices that use igb_uio */
+		ret = rte_eal_pci_map_device(dev);
+		if (ret != 0)
+			return ret;
+	} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
+			rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		/* unbind current driver */
+		if (pci_unbind_kernel_driver(dev) < 0)
+			return -1;
+	}
 
-		/* reference driver structure */
-		dev->driver = dr;
+	/* reference driver structure */
+	dev->driver = dr;
 
-		/* call the driver probe() function */
-		return dr->probe(dr, dev);
-	}
-	/* return positive value if driver doesn't support this device */
-	return 1;
+	/* call the driver probe() function */
+	return dr->probe(dr, dev);
 }
 
 /*
@@ -284,6 +261,7 @@ static int
 pci_probe_all_drivers(struct rte_pci_device *dev)
 {
 	struct rte_pci_driver *dr = NULL;
+	struct rte_bus *pci_bus;
 	int rc = 0;
 
 	if (dev == NULL)
@@ -293,15 +271,21 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 	if (dev->driver != NULL)
 		return 0;
 
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
-		rc = rte_eal_pci_probe_one_driver(dr, dev);
-		if (rc < 0)
-			/* negative value is an error */
-			return -1;
-		if (rc > 0)
-			/* positive value means driver doesn't support it */
-			continue;
-		return 0;
+	TAILQ_FOREACH(dr, &(pci_bus->driver_list), next) {
+		rc = pci_bus->match(dr, dev);
+		if (!rc) {
+			rc = rte_eal_pci_probe_one_driver(dr, dev);
+			if (rc < 0)
+				/* negative value is an error */
+				return -1;
+			if (rc > 0)
+				/* positive value means driver doesn't support
+				 * it
+				 */
+				continue;
+			return 0;
+		}
+		/* Else, continue to next driver */
 	}
 	return 1;
 }
@@ -314,13 +298,19 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
 static int
 pci_detach_all_drivers(struct rte_pci_device *dev)
 {
-	struct rte_pci_driver *dr = NULL;
+	struct rte_pci_driver *pci_drv= NULL;
+	struct rte_driver *drv = NULL;
+	struct rte_bus *pci_bus;
 	int rc = 0;
 
 	if (dev == NULL)
 		return -1;
 
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+	RTE_VERIFY(dev->device->bus);
+	pci_bus = dev->device->bus;
+
+	TAILQ_FOREACH(drv, &pci_bus->driver_list, next) {
+		pci_drv = container_of(drv, struct rte_pci_driver, driver);
 		rc = rte_eal_pci_detach_dev(dr, dev);
 		if (rc < 0)
 			/* negative value is an error */
@@ -340,19 +330,28 @@ pci_detach_all_drivers(struct rte_pci_device *dev)
 int
 rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 {
-	struct rte_pci_device *dev = NULL;
+	struct rte_bus *pci_bus = NULL;
+	struct rte_device *dev = NULL;
+	struct rte_pci_device *pci_dev = NULL;
 	int ret = 0;
 
 	if (addr == NULL)
 		return -1;
 
+	pci_bus = rte_eal_get_bus(PCI_BUS_NAME);
+	if (!pci_bus) {
+		RTE_LOG(DEBUG, EAL, "Unable to find PCI bus\n");
+		return -1;
+	}
+
 	/* update current pci device in global list, kernel bindings might have
 	 * changed since last time we looked at it.
 	 */
 	if (pci_update_device(addr) < 0)
 		goto err_return;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	TAILQ_FOREACH(dev, &pci_bus->device_list, next) {
+		pci_dev = container_of(dev, struct rte_pci_device, device);
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
@@ -376,22 +375,31 @@ err_return:
 int
 rte_eal_pci_detach(const struct rte_pci_addr *addr)
 {
-	struct rte_pci_device *dev = NULL;
+	struct rte_pci_device *pci_dev = NULL;
+	struct rte_bus *pci_bus = NULL;
+	struct rte_device *dev = NULL;
 	int ret = 0;
 
 	if (addr == NULL)
 		return -1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
-		if (rte_eal_compare_pci_addr(&dev->addr, addr))
+	pci_bus = rte_eal_get_bus(PCI_BUS_NAME);
+	if (!pci_bus) {
+		RTE_LOG(DEBUG, EAL, "Unable to find PCI bus\n");
+		return -1;
+	}
+
+	TAILQ_FOREACH(dev, &(bus->device_list), next) {
+		pci_dev = container_of(dev, struct rte_pci_device, device);
+		if (rte_eal_compare_pci_addr(&pci_dev->addr, addr))
 			continue;
 
-		ret = pci_detach_all_drivers(dev);
+		ret = pci_detach_all_drivers(pci_dev);
 		if (ret < 0)
 			goto err_return;
 
-		TAILQ_REMOVE(&pci_device_list, dev, next);
-		free(dev);
+		TAILQ_REMOVE(&pci_bus->device_list, dev, next);
+		free(pci_dev);
 		return 0;
 	}
 	return -1;
@@ -411,31 +419,42 @@ err_return:
 int
 rte_eal_pci_probe(void)
 {
-	struct rte_pci_device *dev = NULL;
+	struct rte_device *dev = NULL;
+	struct rte_bus *pci_bus;
+	struct rte_pci_device *pci_dev;
 	struct rte_devargs *devargs;
 	int probe_all = 0;
 	int ret = 0;
 
+	pci_bus = rte_eal_get_bus(PCI_BUS_NAME);
+	if (!pci_bus) {
+		RTE_LOG(INFO, EAL, "(%s): No such bus exists\n", PCI_BUS_NAME);
+		/* Cannot continue ahead and this is not an error */
+		return;
+	}
+
 	if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) == 0)
 		probe_all = 1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	TAILQ_FOREACH(dev, &(pci_bus->device_list), next) {
+		pci_dev = container_of(dev, struct rte_pci_device, device);
 
 		/* set devargs in PCI structure */
-		devargs = pci_devargs_lookup(dev);
+		devargs = pci_devargs_lookup(pci_dev);
 		if (devargs != NULL)
-			dev->device.devargs = devargs;
+			pci_dev->device.devargs = devargs;
 
 		/* probe all or only whitelisted devices */
 		if (probe_all)
-			ret = pci_probe_all_drivers(dev);
+			ret = pci_probe_all_drivers(pci_dev);`
 		else if (devargs != NULL &&
 			devargs->type == RTE_DEVTYPE_WHITELISTED_PCI)
-			ret = pci_probe_all_drivers(dev);
+			ret = pci_probe_all_drivers(pci_dev);
 		if (ret < 0)
 			rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT
-				 " cannot be used\n", dev->addr.domain, dev->addr.bus,
-				 dev->addr.devid, dev->addr.function);
+				 " cannot be used\n", pci_dev->addr.domain,
+				 pci_dev->addr.bus, pci_dev->addr.devid,
+				 pci_dev->addr.function);
 	}
 
 	return 0;
@@ -465,10 +484,19 @@ pci_dump_one_device(FILE *f, struct rte_pci_device *dev)
 void
 rte_eal_pci_dump(FILE *f)
 {
-	struct rte_pci_device *dev = NULL;
+	struct rte_device *dev = NULL;
+	struct rte_pci_device *pci_dev = NULL;
+	struct rte_bus *bus;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
-		pci_dump_one_device(f, dev);
+	bus = rte_eal_get_bus(PCI_BUS_NAME);
+	if (!bus) {
+		RTE_LOG(INFO, EAL, "(%s): No such bus exists\n", PCI_BUS_NAME);
+		return;
+	}
+
+	TAILQ_FOREACH(dev, &(bus->device_list), next) {
+		pci_dev = container_of(dev, struct rte_pci_device, device);
+		pci_dump_one_device(f, pci_dev);
 	}
 }
 
@@ -476,7 +504,16 @@ rte_eal_pci_dump(FILE *f)
 void
 rte_eal_pci_register(struct rte_pci_driver *driver)
 {
-	TAILQ_INSERT_TAIL(&pci_driver_list, driver, next);
+	struct rte_bus *pci_bus;
+
+	pci_bus = rte_eal_get_bus(PCI_BUS_NAME);
+	if (!pci_bus) {
+		RTE_LOG(INFO, EAL, "(%s) No such bus exists\n", PCI_BUS_NAME);
+		return;
+		/* TODO: How to return error from here? */
+	}
+
+	driver->driver->bus = pci_bus;
 	rte_eal_driver_register(&driver->driver);
 }
 
@@ -484,6 +521,9 @@ rte_eal_pci_register(struct rte_pci_driver *driver)
 void
 rte_eal_pci_unregister(struct rte_pci_driver *driver)
 {
-	rte_eal_driver_unregister(&driver->driver);
-	TAILQ_REMOVE(&pci_driver_list, driver, next);
+	struct rte_bus *pci_bus;
+
+	pci_bus = driver->driver->bus;
+	rte_eal_driver_unregister(&pci_bus, &driver->driver);
+	driver->driver->bus = NULL;
 }
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 9ce8847..cffc449 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -110,7 +110,7 @@ const char *pci_get_sysfs_path(void);
 
 /** Maximum number of PCI resources. */
 #define PCI_MAX_RESOURCE 6
-
+/
 /**
  * A structure describing an ID for a PCI driver. Each driver provides a
  * table of these IDs for each device that it supports.
@@ -360,15 +360,6 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
 }
 
 /**
- * Scan the content of the PCI bus, and the devices in the devices
- * list
- *
- * @return
- *  0 on success, negative on error
- */
-int rte_eal_pci_scan(void);
-
-/**
  * Probe the PCI bus for registered drivers.
  *
  * Scan the content of the PCI bus, and call the probe() function for
-- 
2.7.4

^ permalink raw reply related

* [RFC PATCH 3/6] bus: add bus driver layer
From: Shreyansh Jain @ 2016-11-17  5:30 UTC (permalink / raw)
  To: david.marchand; +Cc: dev, Shreyansh Jain
In-Reply-To: <1479360605-20558-1-git-send-email-shreyansh.jain@nxp.com>

A bus is managed using a 'bus driver'. This patch introduces a sample
PCI bus driver which essentially is the scan and match implementation for
PCI.

There are multiple possible alternatives to where such a driver can be
kept within the DPDK code:
1. librte_bus
 - For each type of bus, there would a file like 'eal_xxx_bus' which would
   then be bound with the eal library.
 - Within this way, another possibility was librte_bus_xxx.

2. Within the drivers/* folder:
 - drivers/bus, parallel to drivers/net and drivers/crypto
 - This way, each bus implmentation would be within the drivers/* area and
   a new implementation would only mean adding a new set of files and
   corresponding changes to the Makefiles.

3. Problem with (3) is that the naming is misleading. drivers/net and
   drivers/crypto are essentially two functionalities rather than drivers.
   Putting driver/bus parallel to these would be misleading in literal
   terms.
   Another possibility is to keep the drivers parallel to 'drivers' folder
   in root of DPDK.
   This is the implementation preferred in this patch.
   A new bus would mean adding a new folder structure within 'bus' -
   including distinction between linuxapp and bsdapp.

In all the three cases, the bus drivers would be instantiated using a
constructor similar to RTE_PMD_REGISTER_XXX. OR, specifically in case of
(2), it would be a priority based constructor.
(__attribute__((contructor(XX))) to assure that buses are loaded before
the drivers are loaded.

Further, as of now the 'pci_bus.c' only shows the scan and dump hooks.
rte_bus also includes hooks for 'dump'ing all devices on the bus and
'find_dev' for finding a device given its rte_device. Each of these
'optional' implementation are more like helpers but have implementation
which is specific to the bus. Hooks for finding a device can be used for
hotplugging (searching before adding a new device, removing existing).
Similarly, 'dump' is a way to represent device information in bus specific
way.

Missing/Grey areas:
 - A lot of PCI specific code is still in EAL - for example mapping. These
   can be moved into bus. Mapping of memory should be a bus property.
 - PMDINFOGEN symbol support for bus - this patch doesn't take care of
   that
 - there would be multiple lists for each bus. Would those be shared
   across various libraries, internal or external, which can be associated
   with DPDK? Should a tailq registration like method be used?

Pending work:
 - The integration of bus/* with librte_eal is not complete. There might
   be symbol issues.
 - Notification support for drivers over a bus doesn't exist yet. Probably
   that needs to be integrated with interrupt handling - no work on this
   has been done yet.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 bus/Makefile               |  36 ++++
 bus/pci/Makefile           |  37 ++++
 bus/pci/linuxapp/pci_bus.c | 418 +++++++++++++++++++++++++++++++++++++++++++++
 bus/pci/linuxapp/pci_bus.h |  55 ++++++
 4 files changed, 546 insertions(+)
 create mode 100644 bus/Makefile
 create mode 100644 bus/pci/Makefile
 create mode 100644 bus/pci/linuxapp/pci_bus.c
 create mode 100644 bus/pci/linuxapp/pci_bus.h

diff --git a/bus/Makefile b/bus/Makefile
new file mode 100644
index 0000000..cfa548c
--- /dev/null
+++ b/bus/Makefile
@@ -0,0 +1,36 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2016 NXP.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of NXP nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+DIRS-y += pci
+
+include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/bus/pci/Makefile b/bus/pci/Makefile
new file mode 100644
index 0000000..fb6cc44
--- /dev/null
+++ b/bus/pci/Makefile
@@ -0,0 +1,37 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += linuxapp
+DIRS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += bsdapp
+
+include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/bus/pci/linuxapp/pci_bus.c b/bus/pci/linuxapp/pci_bus.c
new file mode 100644
index 0000000..b61cb0a
--- /dev/null
+++ b/bus/pci/linuxapp/pci_bus.c
@@ -0,0 +1,418 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 NXP.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of NXP nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <dirent.h>
+
+#include <rte_log.h>
+#include <rte_bus.h>
+#include <rte_pci.h>
+#include <rte_eal_memconfig.h>
+#include <rte_malloc.h>
+#include <rte_devargs.h>
+#include <rte_memcpy.h>
+
+#include "eal_filesystem.h"
+#include "eal_private.h"
+#include "eal_pci_init.h"
+
+
+
+/**
+ * Default PCI matching function called duing probe for drivers
+ *
+ * @param drv
+ *	The PCI driver handle
+ * @param dev
+ *	The PCI device handle
+ * @return
+ *	0 for successful match
+ *	!0 for unsuccessful match
+ */
+int rte_eal_pci_match_default(struct rte_pci_driver *drv,
+			      struct rte_pci_device *dev);
+
+
+/*
+ * split up a pci address into its constituent parts.
+ */
+static int
+parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain,
+		      uint8_t *bus, uint8_t *devid, uint8_t *function)
+{
+	/* first split on ':' */
+	union splitaddr {
+		struct {
+			char *domain;
+			char *bus;
+			char *devid;
+			char *function;
+		};
+		char *str[PCI_FMT_NVAL];
+		/* last element-separator is "." not ":" */
+	} splitaddr;
+
+	char *buf_copy = strndup(buf, bufsize);
+	if (buf_copy == NULL)
+		return -1;
+
+	if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':')
+			!= PCI_FMT_NVAL - 1)
+		goto error;
+	/* final split is on '.' between devid and function */
+	splitaddr.function = strchr(splitaddr.devid,'.');
+	if (splitaddr.function == NULL)
+		goto error;
+	*splitaddr.function++ = '\0';
+
+	/* now convert to int values */
+	errno = 0;
+	*domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
+	*bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
+	*devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
+	*function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
+	if (errno != 0)
+		goto error;
+
+	free(buf_copy); /* free the copy made with strdup */
+	return 0;
+error:
+	free(buf_copy);
+	return -1;
+}
+
+/* parse the "resource" sysfs file */
+static int
+pci_parse_sysfs_resource(const char *filename,
+			 struct rte_pci_device *dev)
+{
+	FILE *f;
+	char buf[BUFSIZ];
+	int i;
+	uint64_t phys_addr, end_addr, flags;
+
+	f = fopen(filename, "r");
+	if (f == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot open sysfs resource\n");
+		return -1;
+	}
+
+	for (i = 0; i<PCI_MAX_RESOURCE; i++) {
+
+		if (fgets(buf, sizeof(buf), f) == NULL) {
+			RTE_LOG(ERR, EAL,
+				"%s(): cannot read resource\n", __func__);
+			goto error;
+		}
+		if (pci_parse_one_sysfs_resource(buf, sizeof(buf), &phys_addr,
+				&end_addr, &flags) < 0)
+			goto error;
+
+		if (flags & IORESOURCE_MEM) {
+			dev->mem_resource[i].phys_addr = phys_addr;
+			dev->mem_resource[i].len = end_addr - phys_addr + 1;
+			/* not mapped for now */
+			dev->mem_resource[i].addr = NULL;
+		}
+	}
+	fclose(f);
+	return 0;
+
+error:
+	fclose(f);
+	return -1;
+}
+
+/* Scan one pci sysfs entry, and fill the devices list from it. */
+static int
+pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,uint8_t devid,
+	     uint8_t function)
+{
+	char filename[PATH_MAX];
+	unsigned long tmp;
+	struct rte_pci_device *pci_dev;
+	struct rte_bus *pci_bus;
+	struct rte_device *dev;
+	char driver[PATH_MAX];
+	int ret;
+
+	/* Get the PCI bus for device; It it doesn't exist, can't continue */
+	pci_bus = rte_eal_get_bus(PCI_BUS_NAME);
+	if (!pci_bus) {
+		RTE_LOG(ERR, EAL, "Unable to get PCI bus.\n");
+		return -1;
+	}
+
+	pci_dev = malloc(sizeof(*pci_dev));
+	if (pci_dev == NULL)
+		return -1;
+
+	memset(pci_dev, 0, sizeof(*pci_dev));
+	pci_dev->addr.domain = domain;
+	pci_dev->addr.bus = bus;
+	pci_dev->addr.devid = devid;
+	pci_dev->addr.function = function;
+
+	/* Set Bus */
+	pci_dev->device->bus = pci_bus;
+
+	/* get vendor id */
+	snprintf(filename, sizeof(filename), "%s/vendor", dirname);
+	if (eal_parse_sysfs_value(filename, &tmp) < 0) {
+		free(pci_dev);
+		return -1;
+	}
+	pci_dev->id.vendor_id = (uint16_t)tmp;
+
+	/* get device id */
+	snprintf(filename, sizeof(filename), "%s/device", dirname);
+	if (eal_parse_sysfs_value(filename, &tmp) < 0) {
+		free(pci_dev);
+		return -1;
+	}
+	pci_dev->id.device_id = (uint16_t)tmp;
+
+	/* get subsystem_vendor id */
+	snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
+		 dirname);
+	if (eal_parse_sysfs_value(filename, &tmp) < 0) {
+		free(pci_dev);
+		return -1;
+	}
+	pci_dev->id.subsystem_vendor_id = (uint16_t)tmp;
+
+	/* get subsystem_device id */
+	snprintf(filename, sizeof(filename), "%s/subsystem_device",
+		 dirname);
+	if (eal_parse_sysfs_value(filename, &tmp) < 0) {
+		free(pci_dev);
+		return -1;
+	}
+	pci_dev->id.subsystem_device_id = (uint16_t)tmp;
+
+	/* get class_id */
+	snprintf(filename, sizeof(filename), "%s/class",
+		 dirname);
+	if (eal_parse_sysfs_value(filename, &tmp) < 0) {
+		free(pci_dev);
+		return -1;
+	}
+	/* the least 24 bits are valid: class, subclass, program interface */
+	pci_dev->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID;
+
+	/* get max_vfs */
+	pci_dev->max_vfs = 0;
+	snprintf(filename, sizeof(filename), "%s/max_vfs", dirname);
+	if (!access(filename, F_OK) &&
+	    eal_parse_sysfs_value(filename, &tmp) == 0)
+		pci_dev->max_vfs = (uint16_t)tmp;
+	else {
+		/* for non igb_uio driver, need kernel version >= 3.8 */
+		snprintf(filename, sizeof(filename),
+			 "%s/sriov_numvfs", dirname);
+		if (!access(filename, F_OK) &&
+		    eal_parse_sysfs_value(filename, &tmp) == 0)
+			pci_dev->max_vfs = (uint16_t)tmp;
+	}
+
+	/* get numa node */
+	snprintf(filename, sizeof(filename), "%s/numa_node",
+		 dirname);
+	if (access(filename, R_OK) != 0) {
+		/* if no NUMA support, set default to 0 */
+		pci_dev->device.numa_node = 0;
+	} else {
+		if (eal_parse_sysfs_value(filename, &tmp) < 0) {
+			free(pci_dev);
+			return -1;
+		}
+		pci_dev->device.numa_node = tmp;
+	}
+
+	/* parse resources */
+	snprintf(filename, sizeof(filename), "%s/resource", dirname);
+	if (pci_parse_sysfs_resource(filename, pci_dev) < 0) {
+		RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__);
+		free(pci_dev);
+		return -1;
+	}
+
+	/* parse driver */
+	snprintf(filename, sizeof(filename), "%s/driver", dirname);
+	ret = pci_get_kernel_driver_by_path(filename, driver);
+	if (ret < 0) {
+		RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
+		free(pci_dev);
+		return -1;
+	}
+
+	if (!ret) {
+		if (!strcmp(driver, "vfio-pci"))
+			pci_dev->kdrv = RTE_KDRV_VFIO;
+		else if (!strcmp(driver, "igb_uio"))
+			pci_dev->kdrv = RTE_KDRV_IGB_UIO;
+		else if (!strcmp(driver, "uio_pci_generic"))
+			pci_dev->kdrv = RTE_KDRV_UIO_GENERIC;
+		else
+			pci_dev->kdrv = RTE_KDRV_UNKNOWN;
+	} else
+		pci_dev->kdrv = RTE_KDRV_NONE;
+
+	/* device is valid, add in list (sorted) */
+	if (TAILQ_EMPTY(&pci_bus->device_list)) {
+		rte_eal_bus_add_device(pci_bus, dev->device);
+	} else {
+		struct rte_device *dev2 = NULL;
+		struct rte_pci_device *pci_dev2;
+		int ret;
+
+		TAILQ_FOREACH(dev2, &pci_bus->device_list, next) {
+			pci_dev2 = container_of(dev2, struct rte_pci_device,
+						device);
+
+			ret = rte_eal_compare_pci_addr(&pci_dev->addr,
+						       &pci_dev2->addr);
+			if (ret > 0)
+				continue;
+
+			if (ret < 0) {
+				/* TODO Pending: 'before' handler for
+				 * bus->device_list
+				 */
+				rte_eal_bus_add_device(pci_bus,
+						       pci_dev2->device);
+			} else { /* already registered */
+				pci_dev2->kdrv = pci_dev->kdrv;
+				pci_dev2->max_vfs = pci_dev->max_vfs;
+				memmove(pci_dev2->mem_resource,
+					pci_dev->mem_resource,
+					sizeof(pci_dev->mem_resource));
+				free(pci_dev);
+			}
+			return 0;
+		}
+		rte_eal_device_insert(&pci_dev->device);
+		TAILQ_INSERT_TAIL(&pci_device_list, pci_dev, next);
+	}
+
+	return 0;
+}
+
+/* Default PCI match implementation */
+int
+pci_bus_match(struct rte_pci_driver *drv,
+			  struct rte_pci_device *dev)
+{
+	int ret = 1;
+	const struct rte_pci_id *id_table;
+
+	for (id_table = drv->id_table; id_table->vendor_id != 0; id_table++) {
+
+		/* check if device's identifiers match the driver's ones */
+		if (id_table->vendor_id != dev->id.vendor_id &&
+				id_table->vendor_id != PCI_ANY_ID)
+			continue;
+		if (id_table->device_id != dev->id.device_id &&
+				id_table->device_id != PCI_ANY_ID)
+			continue;
+		if (id_table->subsystem_vendor_id !=
+		    dev->id.subsystem_vendor_id &&
+		    id_table->subsystem_vendor_id != PCI_ANY_ID)
+			continue;
+		if (id_table->subsystem_device_id !=
+		    dev->id.subsystem_device_id &&
+		    id_table->subsystem_device_id != PCI_ANY_ID)
+			continue;
+		if (id_table->class_id != dev->id.class_id &&
+				id_table->class_id != RTE_CLASS_ANY_ID)
+			continue;
+		ret = 0;
+		break;
+	}
+
+	/* Returning a >0 value as <0 is considered error by caller */
+	return ret;
+}
+
+/*
+ * Scan the content of the PCI bus, and the devices in the devices
+ * list
+ */
+int
+pci_bus_scan(void)
+{
+	struct dirent *e;
+	DIR *dir;
+	char dirname[PATH_MAX];
+	uint16_t domain;
+	uint8_t bus, devid, function;
+
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
+	dir = opendir(pci_get_sysfs_path());
+	if (dir == NULL) {
+		RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
+			__func__, strerror(errno));
+		return -1;
+	}
+
+	while ((e = readdir(dir)) != NULL) {
+		if (e->d_name[0] == '.')
+			continue;
+
+		if (parse_pci_addr_format(e->d_name, sizeof(e->d_name),
+				&domain, &bus, &devid, &function) != 0)
+			continue;
+
+		snprintf(dirname, sizeof(dirname), "%s/%s",
+				pci_get_sysfs_path(), e->d_name);
+		if (pci_scan_one(dirname, domain, bus, devid, function) < 0)
+			goto error;
+	}
+	closedir(dir);
+	return 0;
+
+error:
+	closedir(dir);
+	return -1;
+}
+
+struct rte_bus pci_bus = {
+	.scan = pci_bus_scan,
+	.match = pci_bus_match,
+	.dump = NULL,
+};
+
+RTE_PMD_REGISTER_BUS("pci_bus", pci_bus);
diff --git a/bus/pci/linuxapp/pci_bus.h b/bus/pci/linuxapp/pci_bus.h
new file mode 100644
index 0000000..580fa36
--- /dev/null
+++ b/bus/pci/linuxapp/pci_bus.h
@@ -0,0 +1,55 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 NXP
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of NXP nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * Default PCI matching function called duing probe for drivers
+ *
+ * @param drv
+ *	The PCI driver handle
+ * @param dev
+ *	The PCI device handle
+ * @return
+ *	0 for successful match
+ *	!0 for unsuccessful match
+ */
+int bus_pci_match(struct rte_pci_driver *drv,
+		  struct rte_pci_device *dev);
+
+/**
+* Scan the content of the PCI bus, and the devices in the devices
+* list
+*
+* @return
+*  0 on success, negative on error
+*/
+int bus_pci_scan(void);
-- 
2.7.4

^ permalink raw reply related

* [RFC PATCH 2/6] eal: introduce bus-device-driver structure
From: Shreyansh Jain @ 2016-11-17  5:30 UTC (permalink / raw)
  To: david.marchand; +Cc: dev, Shreyansh Jain
In-Reply-To: <1479360605-20558-1-git-send-email-shreyansh.jain@nxp.com>

A device is connected to a bus and services by a driver associated with
the bus. It is responsibility of the bus to identify the devices (scan)
and then assign each device to a matching driver.

A PMD would allocate a rte_xxx_driver and rte_xxx_device.
rte_xxx_driver has rte_driver and rte_bus embedded. Similarly, rte_xxx_device
has rte_device and rte_bus embedded.

When a ethernet or crypto device (rte_eth_dev, rte_cryptodev) is allocated,
it contains a reference of rte_device and rte_driver.
Each ethernet device implementation would use container_of for finding the
enclosing structure of rte_xxx_*.

                            +-------------------+
 +--------------+           |rte_pci_device     |
 |rte_eth_dev   |           |+-----------------+|
 |+------------+|   .-------->rte_device       ||
 ||rte_device*-----'        |+-----------------+|
 |+------------+|           ||rte_bus          ||
 |              |           |+-----------------+|
 /              /           +-------------------+

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_bus.h | 243 ++++++++++++++++++++++++++++++++
 lib/librte_eal/common/include/rte_dev.h |  36 ++---
 2 files changed, 261 insertions(+), 18 deletions(-)
 create mode 100644 lib/librte_eal/common/include/rte_bus.h

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
new file mode 100644
index 0000000..dc3aeb8
--- /dev/null
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -0,0 +1,243 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 NXP
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of NXP nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_BUS_H_
+#define _RTE_BUS_H_
+
+/**
+ * @file
+ *
+ * RTE PMD Bus Abstraction interfaces
+ *
+ * This file exposes APIs and Interfaces for Bus Abstraction over the devices
+ * drivers in EAL.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <sys/queue.h>
+
+#include <rte_log.h>
+#include <rte_dev.h>
+
+
+/** Double linked list of buses */
+TAILQ_HEAD(rte_bus_list, rte_bus);
+
+/**
+ * Bus specific scan for devices attached on the bus.
+ * For each bus object, the scan would be reponsible for finding devices and
+ * adding them to its private device list.
+ *
+ * Successful detection of a device results in rte_device object which is
+ * embedded within the respective device type (rte_pci_device, for example).
+ * Thereafter, PCI specific bus would need to perform
+ * container_of(rte_pci_device) to obtain PCI device object.
+ *
+ * Scan failure of a bus is not treated as exit criteria for application. Scan
+ * for all other buses would still continue.
+ *
+ * @param void
+ * @return
+ *	0 for successful scan
+ *	!0 (<0) for unsuccessful scan with error value
+ */
+typedef int (* bus_scan_t)(void);
+
+/**
+ * Bus specific match for devices and drivers which can service them.
+ * For each scanned device, during probe the match would link the devices with
+ * drivers which can service the device.
+ *
+ * It is the work of each bus handler to obtain the specific device object
+ * using container_of (or typecasting, as a less preferred way).
+ *
+ * @param drv
+ *	Driver object attached to the bus
+ * @param dev
+ *	Device object which is being probed.
+ * @return
+ *	0 for successful match
+ *	!0 for unsuccessful match
+ */
+typedef int (* bus_match_t)(struct rte_driver *drv, struct rte_device *dev);
+
+/**
+ * Dump the devices on the bus.
+ * Each bus type can define its own definition of information to dump.
+ *
+ * @param bus
+ *	Handle for bus, device from which are to be dumped.
+ * @param f
+ *	Handle to output device or file.
+ * @return void
+ */
+typedef void (* bus_dump_t)(struct rte_bus *bus, FILE *f);
+
+/**
+ * Search for a specific device in device list of the bus
+ * This would rely on the bus specific addressing. Each implementation would
+ * extract its specific device type and perform address compare.
+ *
+ * @param dev
+ *	device handle to search for.
+ * @return
+ *	rte_device handle for matched device, or NULL
+ */
+typedef struct rte_device * (* bus_device_get_t)(struct rte_device *dev);
+
+struct rte_bus {
+	TAILQ_ENTRY(rte_bus) next;   /**< Next bus object in linked list */
+	struct rte_driver_list driver_list; /**< List of all drivers of bus */
+	struct rte_device_list device_list; /**< List of all devices on bus */
+	const char *name;            /**< Name of the bus */
+	/* Mandatory hooks */
+	bus_scan_t *scan;            /**< Hook for scanning for devices */
+	bus_match_t *match;          /**< Hook for matching device & driver */
+	/* Optional hooks */
+	bus_dump_t *dump_dev;        /**< Hook for dumping devices on bus */
+	bus_device_get_t *find_dev;  /**< Search for a device on bus */
+};
+
+/** @internal
+ * Add a device to a bus.
+ *
+ * @param bus
+ *	Bus on which device is to be added
+ * @param dev
+ *	Device handle
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_add_device(struct rte_bus *bus, struct rte_device *dev);
+
+/** @internal
+ * Remove a device from its bus.
+ *
+ * @param dev
+ *	Device handle to remove
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_remove_device(struct rte_device *dev);
+
+/** @internal
+ * Associate a driver with a bus.
+ *
+ * @param bus
+ *	Bus on which driver is to be added
+ * @param dev
+ *	Driver handle
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_add_driver(struct rte_bus *bus, struct rte_driver *drv);
+
+/** @internal
+ * Disassociate a driver from its bus.
+ *
+ * @param dev
+ *	Driver handle to remove
+ * @return
+ *	None
+ */
+void
+rte_eal_bus_remove_driver(struct rte_driver *drv);
+
+/**
+ * Register a Bus handler.
+ *
+ * @param driver
+ *   A pointer to a rte_bus structure describing the bus
+ *   to be registered.
+ */
+void rte_eal_bus_register(struct rte_bus *bus);
+
+/**
+ * Unregister a Bus handler.
+ *
+ * @param driver
+ *   A pointer to a rte_bus structure describing the bus
+ *   to be unregistered.
+ */
+void rte_eal_bus_unregister(struct rte_bus *bus);
+
+/**
+ * Obtain handle for bus given its name.
+ *
+ * @param bus_name
+ *	Name of the bus handle to search
+ * @return
+ *	Pointer to Bus object if name matches any registered bus object
+ *	NULL, if no matching bus found
+ */
+struct rte_bus * rte_eal_get_bus(const char *bus_name);
+
+/**
+ * Register a device driver.
+ *
+ * @param driver
+ *   A pointer to a rte_dev structure describing the driver
+ *   to be registered.
+ */
+void rte_eal_driver_register(struct rte_driver *driver);
+
+/**
+ * Unregister a device driver.
+ *
+ * @param driver
+ *   A pointer to a rte_dev structure describing the driver
+ *   to be unregistered.
+ */
+void rte_eal_driver_unregister(struct rte_driver *driver);
+
+/** Helper for Bus registration */
+#define RTE_PMD_REGISTER_BUS(nm, bus) \
+RTE_INIT(businitfn_ ##nm); \
+static void businitfn_ ##nm(void) \
+{\
+	(bus).name = RTE_STR(nm);\
+	rte_eal_bus_register(&bus); \
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_BUS_H */
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index 8840380..b08bab5 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -116,12 +116,14 @@ TAILQ_HEAD(rte_device_list, rte_device);
 
 /* Forward declaration */
 struct rte_driver;
+struct rte_bus;
 
 /**
  * A structure describing a generic device.
  */
 struct rte_device {
 	TAILQ_ENTRY(rte_device) next; /**< Next device */
+	struct rte_bus *bus;          /**< Bus on which device is placed */
 	struct rte_driver *driver;    /**< Associated driver */
 	int numa_node;                /**< NUMA node connection */
 	struct rte_devargs *devargs;  /**< Device user arguments */
@@ -144,31 +146,29 @@ void rte_eal_device_insert(struct rte_device *dev);
 void rte_eal_device_remove(struct rte_device *dev);
 
 /**
- * A structure describing a device driver.
+ * @internal
+ * TODO
  */
-struct rte_driver {
-	TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
-	const char *name;                   /**< Driver name. */
-	const char *alias;              /**< Driver alias. */
-};
+typedef int (*driver_init_t)(struct rte_device *eth_dev);
 
 /**
- * Register a device driver.
- *
- * @param driver
- *   A pointer to a rte_dev structure describing the driver
- *   to be registered.
+ * @internal
+ * TODO
  */
-void rte_eal_driver_register(struct rte_driver *driver);
+typedef int (*driver_uninit_t)(struct rte_device *eth_dev);
 
 /**
- * Unregister a device driver.
- *
- * @param driver
- *   A pointer to a rte_dev structure describing the driver
- *   to be unregistered.
+ * A structure describing a device driver.
  */
-void rte_eal_driver_unregister(struct rte_driver *driver);
+struct rte_driver {
+	TAILQ_ENTRY(rte_driver) next;  /**< Next in list. */
+	struct rte_bus *bus;           /**< Bus which drivers services */
+	const char *name;              /**< Driver name. */
+	const char *alias;             /**< Driver alias. */
+	driver_init_t *init;           /**< Driver initialization */
+	driver_uninit_t *uninit;       /**< Driver uninitialization */
+	unsigned int dev_private_size; /**< Size of device private data ??*/
+};
 
 /**
  * Initalize all the registered drivers in this process
-- 
2.7.4

^ permalink raw reply related

* [RFC PATCH 1/6] eal: define container macro
From: Shreyansh Jain @ 2016-11-17  5:30 UTC (permalink / raw)
  To: david.marchand; +Cc: dev, Jan Viktorin, Shreyansh Jain
In-Reply-To: <1479360605-20558-1-git-send-email-shreyansh.jain@nxp.com>

From: Jan Viktorin <viktorin@rehivetech.com>

Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_common.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index db5ac91..8152bd9 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -331,6 +331,24 @@ rte_bsf32(uint32_t v)
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
 #endif
 
+/**
+ * Return pointer to the wrapping struct instance.
+ * Example:
+ *
+ *  struct wrapper {
+ *      ...
+ *      struct child c;
+ *      ...
+ *  };
+ *
+ *  struct child *x = obtain(...);
+ *  struct wrapper *w = container_of(x, struct wrapper, c);
+ */
+#ifndef container_of
+#define container_of(p, type, member) \
+	((type *) (((char *) (p)) - offsetof(type, member)))
+#endif
+
 #define _RTE_STR(x) #x
 /** Take a macro value and get a string version of it */
 #define RTE_STR(x) _RTE_STR(x)
-- 
2.7.4

^ permalink raw reply related

* [RFC PATCH 0/6] Restructure EAL device model for bus support
From: Shreyansh Jain @ 2016-11-17  5:29 UTC (permalink / raw)
  To: david.marchand; +Cc: dev, Shreyansh Jain

DPDK has been inherently a PCI inclined framework. Because of this, the
design of device tree (or list) within DPDK is also PCI inclined. A non-PCI
device doesn't have a way of being expressed without using hooks started from
EAL to PMD.

With this cover letter, some patches are presented which try to break this
strict linkage of EAL with PCI devices. Aim is to generalize the device
hierarchy on the lines of how Linux handles it:

        device A1
          |
  +==.===='==============.============+ Bus A.
     |                    `--> driver A11     \
  device A2                `-> driver A12      \______
                                                |CPU |
                                                /`````
        device A1                              /
          |                                   /
  +==.===='==============.============+ Bus A`
     |                    `--> driver B11
  device A2                `-> driver B12

Simply put:
 - a bus is connect to CPU (or core)
 - devices are conneted to Bus
 - drivers are running instances which manage one or more devices
 - bus is responsible for identifying devices (and interrupt propogation)
 - driver is responsible for initializing the device

(*Reusing text from email [1])
In context of DPDK EAL:
 - a generic bus (not a driver, not a device). I don't know how to categorize
   a bus. It is certainly not a device, and then handler for a bus (physical)
   can be considered a 'bus driver'. So, just 'rte_bus'.
 - there is a bus for each physical implementation (or virtual). So, a rte_bus
   Object for PCI, VDEV, ABC, DEF and so on.
 - Buses are registered just like a PMD - RTE_PMD_BUS_REGISTER()
 - Each registered bus is part of a doubly list.
   -- Each device inherits rte_bus
   -- Each driver inherits rte_bus
   -- Device and Drivers lists are part of rte_bus
 - eth_driver is no more required - it was just a holder for PMDs to register
   themselves. It can be replaced with rte_xxx_driver and corresponding init/
   uninit moved to rte_driver
 - rte_eth_dev modified to disassociate itself from rte_pci_device and connect
   to generic rte_device

Once again, improvising from [1]:

                                  __ rte_bus_list
                                 /
                     +----------'---+
                     |rte_bus       |
                     | driver_list------> List of rte_bus specific
                     | device_list----    devices
                     | scan         | `-> List of rte_bus associated
                     | match        |     drivers
                     | dump         |
                     | ..some refcnt| (#)
                     +--|------|----+
              _________/        \_________
    +--------/----+                     +-\---------------+
    |rte_device   |                     |rte_driver       |
    | rte_bus     |                     | rte_bus         |
    | rte_driver  |(#)                  | init            |
    |             |                     | uninit          |
    |  devargs    |                     | dev_private_size|
    +---||--------+                     | drv_flags       |(#)
        ||                              | intr_handle(2*) |(#)
        | \                             +----------\\\----+
        |  \_____________                           \\\
        |                \                          |||
 +------|---------+ +----|----------+               |||
 |rte_pci_device  | |rte_xxx_device | (4*)          |||
 | PCI specific   | | xxx device    |               |||
 | info (mem,)    | | specific fns  |              / | \
 +----------------+ +---------------+             /  |  \
                            _____________________/  /    \
                           /                    ___/      \
            +-------------'--+    +------------'---+    +--'------------+
            |rte_pci_driver  |    |rte_vdev_driver |    |rte_xxx_driver |
            | PCI id table,  |    | <probably,     |    | ....          |
            | other driver   |    |  nothing>      |    +---------------+
            | data           |    +----------------+
            +----------------+
    
    (1*) Problem is that probe functions have different arguments. So,
         generalizing them might be some rework in the respective device
         layers
    (2*) Interrupt handling for each driver type might be different. I am not
         sure how to generalize that either. This is grey area for me.
    (3*) Probably exposing a bitmask for device capabilities. Nothing similar
         exists now to relate it. Don't know if that is useful. Allowing
         applications to question a device about what it supports and what it
         doesn't - making it more flexible at application layer (but more code
         as well.)
    (4*) Even vdev would be an instantiated as a device. It is not being done
         currently.
    (#)  Items which are still pending

With this cover letter, some patches have been posted. These are _only_ for
discussion purpose. They are not complete and neither compilable.
All the patches, except 0001, have sufficient context about what the changes
are and rationale for same. Obviously, code is best answer.

=== Patch description: ===

Patch 0001: Introduce container_of macro. Originally a patch from Jan.

Patch 0002: introduce changes to rte_device/rte_driver for rte_bus, and
            rte_bus definition itself.

Patch 0003: Add a new layer for 'bus driver' with linuxapp PCI as an example

Patch 0004: Changes with respect to rte_bus APIs and impact on eal_common_pci

Patch 0005: Change to rte_eal_init (of linuxapp only, for now) for supporting
            bus->scan. Probe is still being done old way, but in a new wrapper

Patch 0006: eth_driver removal and corresponding changes in ixgbe_ethdev, as
            an example. Includes changes to rte_ethdev to remove most possible
            PCI references. But, work still remains.

=== Pending Items/Questions: ===

 - Interrupt and notification handling. How to allow drivers to be notified
   of presence/plugging of a device.
 - Placement of bus driver/handling code. librte_bus, bus/, drivers/bus?
 -- Also from a pespective of a external library and whether symbols would be
    available in that.
 -- and secondary processes
 - VDEV bus is missing from current set.
 - Locking of list for supporting hotplugging. Or, at the least safe add/
   remove
 - PMDINFOGEN support or lack of it.
 - Is there ever a case where rte_eth_dev needs to be resolved from
   rte_pci_device? I couldn't find any such use and neither a use-case for it.
 - There should be a way for Bus APIs to return a generic list handle so that
   EAL doesn't need to bother about bus->driver_list like dereferencing. This
   is untidy as well as less portable (in terms of code movement, not arch).
 - Are more helper hooks required for a bus?
 -- I can think of scan, match, dump, find, plug (device), unplug (device),
    associate (driver), disassociate (driver). But, most of the work is
    already being done by lower instances (rte_device/driver etc).

Further:
 - In next few days I will make all necessary changes on the lines mentioned
   in the patches. This would include changing the drivers/* and librte_eal/*
 - As an when review comments float in and agreement reached, I will keep
   changing the model
 - There are grey areas like interrupt, notification, locking of bus/list
   which require more discussion. I will try and post a rfc for those as well
   or if someone can help me on those - great
 - Change would include PCI bus and VDEV bus handling. A new bus (NXP's FSLMC)
   would also be layered over this series to verify the model of 'bus
   registration'. This is also part of 17.02 roadmap.

[1] http://dpdk.org/ml/archives/dev/2016-November/050186.html

Jan Viktorin (1):
  eal: define container macro

Shreyansh Jain (5):
  eal: introduce bus-device-driver structure
  bus: add bus driver layer
  eal/common: handle bus abstraction for device/driver objects
  eal: supporting bus model in init process
  eal: removing eth_driver

 bus/Makefile                               |  36 +++
 bus/pci/Makefile                           |  37 +++
 bus/pci/linuxapp/pci_bus.c                 | 418 +++++++++++++++++++++++++++++
 bus/pci/linuxapp/pci_bus.h                 |  55 ++++
 drivers/net/ixgbe/ixgbe_ethdev.c           |  49 ++--
 lib/librte_eal/common/eal_common_bus.c     | 188 +++++++++++++
 lib/librte_eal/common/eal_common_dev.c     |  31 ++-
 lib/librte_eal/common/eal_common_pci.c     | 226 +++++++++-------
 lib/librte_eal/common/include/rte_bus.h    | 243 +++++++++++++++++
 lib/librte_eal/common/include/rte_common.h |  18 ++
 lib/librte_eal/common/include/rte_dev.h    |  36 +--
 lib/librte_eal/common/include/rte_pci.h    |  11 +-
 lib/librte_eal/linuxapp/eal/Makefile       |   1 +
 lib/librte_eal/linuxapp/eal/eal.c          |  51 +++-
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 298 --------------------
 lib/librte_ether/rte_ethdev.c              |  36 ++-
 lib/librte_ether/rte_ethdev.h              |   6 +-
 17 files changed, 1262 insertions(+), 478 deletions(-)
 create mode 100644 bus/Makefile
 create mode 100644 bus/pci/Makefile
 create mode 100644 bus/pci/linuxapp/pci_bus.c
 create mode 100644 bus/pci/linuxapp/pci_bus.h
 create mode 100644 lib/librte_eal/common/eal_common_bus.c
 create mode 100644 lib/librte_eal/common/include/rte_bus.h

-- 
2.7.4

^ permalink raw reply

* Re: [dpdk-announce] DPDK 16.11 released
From: Xu, Qian Q @ 2016-11-17  3:51 UTC (permalink / raw)
  To: Thomas Monjalon, Liu, Yong; +Cc: dev@dpdk.org
In-Reply-To: <1609004.OL7hRRQnMz@xps13>

It is good that RC1 on Jan.11th is a hard deadline. We also need ensure that RC1 is a complete package with all features. If RC1 is out but missing some big features, then the test results on RC1 vs RC2 may have big difference. 
So, could we ensure that RC1 is a complete feature package, if any feature missing RC1, then we may postpone the feature to 17.05? Does it make sense? 

-----Original Message-----
From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
Sent: Tuesday, November 15, 2016 5:06 PM
To: Liu, Yong <yong.liu@intel.com>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [dpdk-announce] DPDK 16.11 released

Hi and thanks for sharing your time constraints,

2016-11-15 01:46, Liu, Yong:
> As prospect for 17.02, our intel validation team have some concern about the release date.
> The official day off for Chinese Sprint Festival holiday will be from 27th Jan to 3th Feb.
> Most of our members may ask for more days leave either before or after the official day off.
> From our previous experience, it will take 3~4 weeks to do the full function and performance test.
> If the first candidate release in the middle of Jan, we can do first 
> round of validation and raise issues to developers.

The integration deadline is January 5.
So we can target/expect a RC1 on January 11.

> And after the holiday, we can keep on the validation process and finish in two weeks.
> If release date is after Feb, it will be hard for us to cover all cases in release window.

Yes, we must remind that mid-January is a hard deadline for RC1.
Then the release will be in mid-February to make sure you have some time after the holidays.
What about Valentine's day? :)

^ permalink raw reply

* Re: dpdk/vpp and cross-version migration for vhost
From: Maxime Coquelin @ 2016-11-16 20:43 UTC (permalink / raw)
  To: Michael S. Tsirkin, Yuanhan Liu
  Cc: dev, Stephen Hemminger, qemu-devel, libvir-list, vpp-dev
In-Reply-To: <20161011173526-mutt-send-email-mst@kernel.org>

Hi Michael,

On 10/13/2016 07:50 PM, Michael S. Tsirkin wrote:
> Hi!
> So it looks like we face a problem with cross-version
> migration when using vhost. It's not new but became more
> acute with the advent of vhost user.
>
> For users to be able to migrate between different versions
> of the hypervisor the interface exposed to guests
> by hypervisor must stay unchanged.
>
> The problem is that a qemu device is connected
> to a backend in another process, so the interface
> exposed to guests depends on the capabilities of that
> process.
>
> Specifically, for vhost user interface based on virtio, this includes
> the "host features" bitmap that defines the interface, as well as more
> host values such as the max ring size.  Adding new features/changing
> values to this interface is required to make progress, but on the other
> hand we need ability to get the old host features to be compatible.
>
> To solve this problem within qemu, qemu has a versioning system based on
> a machine type concept which fundamentally is a version string, by
> specifying that string one can get hardware compatible with a previous
> qemu version. QEMU also reports the latest version and list of versions
> supported so libvirt records the version at VM creation and then is
> careful to use this machine version whenever it migrates a VM.
>
> One might wonder how is this solved with a kernel vhost backend. The
> answer is that it mostly isn't - instead an assumption is made, that
> qemu versions are deployed together with the kernel - this is generally
> true for downstreams.  Thus whenever qemu gains a new feature, it is
> already supported by the kernel as well.  However, if one attempts
> migration with a new qemu from a system with a new to old kernel, one
> would get a failure.
>
> In the world where we have multiple userspace backends, with some of
> these supplied by ISVs, this seems non-realistic.
>
> IMO we need to support vhost backend versioning, ideally
> in a way that will also work for vhost kernel backends.
>
> So I'd like to get some input from both backend and management
> developers on what a good solution would look like.
>
> If we want to emulate the qemu solution, this involves adding the
> concept of interface versions to dpdk.  For example, dpdk could supply a
> file (or utility printing?) with list of versions: latest and versions
> supported. libvirt could read that and

So if I understand correctly, it would be generated at build time?
One problem I see is that the DPDK's vhost-user lib API provides a way
to disable features:
"
rte_vhost_feature_disable/rte_vhost_feature_enable(feature_mask)

This function disables/enables some features. For example, it can be 
used to disable mergeable buffers and TSO features, which both are 
enabled by default.
"

I think we should not have this capability on host side, it should be
guest's decision to use or not some features, and if it has to be done
on host, QEMU already provides a way to disable features (moreover
per-device, which is not the case with rte_vhost_feature_disable).
IMHO, we should consider deprecating this API in v17.02.

That said, the API is here, and it would break migration if the version
file advertises some features the vSwitch has disabled at runtime.

> - store latest version at vm creation
> - pass it around with the vm
> - pass it to qemu
> From here, qemu could pass this over the vhost-user channel,
> thus making sure it's initialized with the correct
> compatible interface.

Using vhost-user protocol features I guess?

> As version here is an opaque string for libvirt and qemu,
> anything can be used - but I suggest either a list
> of values defining the interface, e.g.
> any_layout=on,max_ring=256
> or a version including the name and vendor of the backend,
> e.g. "org.dpdk.v4.5.6".

I think the first option provides more flexibility.
For example, we could imagine migrating from a process using DPDK's
vhost-user lib, to another process using its own implementation (VPP
has its own implementation currently if I'm not mistaken).
Maybe this scenario does not make sense, but in this case, exposing
values directly would avoid the need for synchronization between
vhost-user implementations.

>
> Note that typically the list of supported versions can only be
> extended, not shrunk. Also, if the host/guest interface
> does not change, don't change the current version as
> this just creates work for everyone.
>
> Thoughts? Would this work well for management? dpdk? vpp?

One thing I'm not clear is how it will work for the MTU feature, if the
process it is migrated to exposes a larger MTU that the guest doesn't
support (if it has sized receive buffers to pre-migration MTU for
example).

Thanks,
Maxime

^ permalink raw reply

* Re: [RFC PATCH 0/7] RFC: EventDev Software PMD
From: Jerin Jacob @ 2016-11-16 20:19 UTC (permalink / raw)
  To: Harry van Haaren; +Cc: dev
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

On Wed, Nov 16, 2016 at 06:00:00PM +0000, Harry van Haaren wrote:
> This series of RFC patches implements the libeventdev API and a software
> eventdev PMD.
> 
> The implementation here is intended to enable the community to use the
> eventdev API, specifically to test if the API serves the purpose that it is
> designed to. It should be noted this is an RFC implementation, and hence
> there should be no performance expectations.
> 
> An RFC for the eventdev was sent in August[1] by Jerin Jacob of Cavium,
> which introduced the core concepts of the eventdev to the community. Since
> then there has been extensive discussion[2] on the mailing list, which had
> led to various modifications to the initial proposed API.
> 
> The API as presented in the first patch contains a number of changes that
> have not yet been discussed. These changes were noticed during the
> implementation of the software eventdev PMD, and were added to the API to
> enable completion of the PMD. These modifications include a statistics API
> and a dump API. For more details, please refer to the commit message of the
> patch itself.
> 
> The functionality provided by each of the patches is as follows:
>   1: Add eventdev API and library infrastructure
>   2: Enable compilation of library
>   3: Add software eventdev PMD
>   4: Enable compilation of PMD
>   5: Add test code
>   6: Enable test code compilation
>   7: Sample application demonstrating basic usage
> 
> This breakdown of the patchset hopefully enables the community to experiment
> with the eventdev API, and allows us all to gain first-hand experience in
> using the eventdev API.  Note also that this patchset has not passed
> checkpatch testing just yet - will fix for v2 :)
> 
> As next steps I see value in discussing the proposed changes included in
> this version of the header file, while welcoming feedback from the community
> on the API in general too.

Thanks. Harry.

Even I was writing the similar stuff.I took a bit different approach on
the common code side, where I was trying to have fat common code(
lib/librte_eventdev/rte_eventdev.c) with start/stop support for the
slow-path code. I will post the implementation in few days and then we
can work on a converged solution.

Following sections of code does not have any overlap at all.
test/eventdev: unit and functional tests
event/sw: software eventdev implementation
examples/eventdev_pipeline: adding example

Some questions and initial feedback
1) I thought RTE_EVENT_OP_DROP and rte_event_release() are same ? No ?
2) device stats API can be based on capability, HW implementations may not
support all the stats
3) From the HW implementation perspective, eventdev_pipeline application
needs to have a lot of changes.I will post the comments in coming days
and we can work together on the converged solution.

Jerin


> 
> Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
> 
> [1] http://dpdk.org/ml/archives/dev/2016-August/045181.html
> [2] http://dpdk.org/ml/archives/dev/2016-October/thread.html#48196
> 
> Harry van Haaren (7):
>   eventdev: header and implementation
>   eventdev: makefiles
>   event/sw: software eventdev implementation
>   event/sw: makefiles and config
>   test/eventdev: unit and functional tests
>   test/eventdev: unit func makefiles
>   examples/eventdev_pipeline: adding example
> 
>  app/test/Makefile                             |    3 +
>  app/test/test_eventdev_func.c                 | 1272 ++++++++++++++++++++++++
>  app/test/test_eventdev_unit.c                 |  557 +++++++++++
>  config/common_base                            |   12 +
>  drivers/Makefile                              |    1 +
>  drivers/event/Makefile                        |   36 +
>  drivers/event/sw/Makefile                     |   59 ++
>  drivers/event/sw/event_ring.h                 |  142 +++
>  drivers/event/sw/iq_ring.h                    |  160 +++
>  drivers/event/sw/rte_pmd_evdev_sw_version.map |    3 +
>  drivers/event/sw/sw_evdev.c                   |  619 ++++++++++++
>  drivers/event/sw/sw_evdev.h                   |  234 +++++
>  drivers/event/sw/sw_evdev_scheduler.c         |  660 +++++++++++++
>  drivers/event/sw/sw_evdev_worker.c            |  218 +++++
>  examples/eventdev_pipeline/Makefile           |   49 +
>  examples/eventdev_pipeline/main.c             |  717 ++++++++++++++
>  lib/Makefile                                  |    1 +
>  lib/librte_eal/common/include/rte_vdev.h      |    1 +
>  lib/librte_eventdev/Makefile                  |   54 ++
>  lib/librte_eventdev/rte_eventdev.c            |  466 +++++++++
>  lib/librte_eventdev/rte_eventdev.h            | 1289 +++++++++++++++++++++++++
>  lib/librte_eventdev/rte_eventdev_ops.h        |  177 ++++
>  lib/librte_eventdev/rte_eventdev_pmd.h        |   69 ++
>  lib/librte_eventdev/rte_eventdev_version.map  |   33 +
>  mk/rte.app.mk                                 |    5 +
>  25 files changed, 6837 insertions(+)
>  create mode 100644 app/test/test_eventdev_func.c
>  create mode 100644 app/test/test_eventdev_unit.c
>  create mode 100644 drivers/event/Makefile
>  create mode 100644 drivers/event/sw/Makefile
>  create mode 100644 drivers/event/sw/event_ring.h
>  create mode 100644 drivers/event/sw/iq_ring.h
>  create mode 100644 drivers/event/sw/rte_pmd_evdev_sw_version.map
>  create mode 100644 drivers/event/sw/sw_evdev.c
>  create mode 100644 drivers/event/sw/sw_evdev.h
>  create mode 100644 drivers/event/sw/sw_evdev_scheduler.c
>  create mode 100644 drivers/event/sw/sw_evdev_worker.c
>  create mode 100644 examples/eventdev_pipeline/Makefile
>  create mode 100644 examples/eventdev_pipeline/main.c
>  create mode 100644 lib/librte_eventdev/Makefile
>  create mode 100644 lib/librte_eventdev/rte_eventdev.c
>  create mode 100644 lib/librte_eventdev/rte_eventdev.h
>  create mode 100644 lib/librte_eventdev/rte_eventdev_ops.h
>  create mode 100644 lib/librte_eventdev/rte_eventdev_pmd.h
>  create mode 100644 lib/librte_eventdev/rte_eventdev_version.map
> 
> -- 
> 2.7.4
> 

^ permalink raw reply

* [PATCH 7/7] examples/eventdev_pipeline: adding example
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, Gage Eads, Bruce Richardson
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

This patch adds a sample app to the examples/ directory, which can be used
as a reference application and for general testing. The application requires
two ethdev ports and expects traffic to be flowing. The application must be
run with the --vdev flags as follows to indicate to EAL that a virtual
eventdev device called "evdev_sw0" is available to be used:

    ./build/eventdev_pipeline --vdev evdev_sw0

The general flow of the traffic is as follows:

    Rx core -> Atomic Queue => 4 worker cores => TX core

A scheduler core is required to do the packet scheduling, making this
configuration require 7 cores (Rx, Tx, Scheduler, and 4 workers). Finally
a master core brings the core count to 8 for this configuration. The
application can be configured for various numbers of flows and worker
cores. Run the application with -h for details.

Signed-off-by: Gage Eads <gage.eads@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 examples/eventdev_pipeline/Makefile |  49 +++
 examples/eventdev_pipeline/main.c   | 718 ++++++++++++++++++++++++++++++++++++
 2 files changed, 767 insertions(+)
 create mode 100644 examples/eventdev_pipeline/Makefile
 create mode 100644 examples/eventdev_pipeline/main.c

diff --git a/examples/eventdev_pipeline/Makefile b/examples/eventdev_pipeline/Makefile
new file mode 100644
index 0000000..bab8916
--- /dev/null
+++ b/examples/eventdev_pipeline/Makefile
@@ -0,0 +1,49 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2016 Intel Corporation. All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = eventdev_pipeline
+
+# all source are stored in SRCS-y
+SRCS-y := main.c
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/eventdev_pipeline/main.c b/examples/eventdev_pipeline/main.c
new file mode 100644
index 0000000..6a8052c
--- /dev/null
+++ b/examples/eventdev_pipeline/main.c
@@ -0,0 +1,718 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <getopt.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <signal.h>
+
+#include <rte_eal.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+#include <rte_launch.h>
+#include <rte_malloc.h>
+#include <rte_cycles.h>
+#include <rte_ethdev.h>
+#include <rte_eventdev.h>
+
+#define BATCH_SIZE 32
+
+static unsigned int num_workers = 4;
+static unsigned long num_packets = (1L << 25); /* do ~32M packets */
+static unsigned int num_fids = 16;
+static unsigned int num_priorities = 1;
+static int sched_type = RTE_SCHED_TYPE_ATOMIC;
+
+struct prod_data {
+	uint8_t event_dev_id;
+	uint8_t event_port_id;
+	int32_t qid;
+	unsigned num_ports;
+};
+
+struct cons_data {
+	uint8_t event_dev_id;
+	uint8_t event_port_id;
+};
+
+struct worker_data {
+	uint8_t event_dev_id;
+	int event_port_id;
+	int32_t qid;
+};
+
+static volatile int done = 0;
+static int quiet = 0;
+struct rte_mempool *mp;
+
+static int
+worker(void *arg)
+{
+	struct rte_event rcv_events[BATCH_SIZE];
+
+	struct worker_data *data = (struct worker_data *)arg;
+	uint8_t event_dev_id = data->event_dev_id;
+	uint8_t event_port_id = data->event_port_id;
+	int32_t qid = data->qid;
+	size_t sent = 0, received = 0;
+
+	while (!done) {
+		uint16_t i;
+
+		uint16_t n = rte_event_dequeue_burst(event_dev_id,
+						     event_port_id,
+						     rcv_events,
+						     RTE_DIM(rcv_events),
+						     false);
+		if (n == 0){
+			rte_pause();
+			/* Flush any buffered events */
+			rte_event_dequeue(event_dev_id,
+					  event_port_id,
+					  NULL,
+					  false);
+			continue;
+		}
+		received += n;
+
+		for (i = 0; i < n; i++) {
+			struct ether_hdr *eth;
+			struct ether_addr addr;
+			struct rte_event *ev = &rcv_events[i];
+
+			ev->queue_id = qid;
+			ev->flow_id = 0;
+			ev->priority = 0;
+			ev->sched_type = RTE_SCHED_TYPE_ATOMIC;
+			ev->operation = RTE_EVENT_OP_FORWARD;
+
+			uint64_t now = rte_rdtsc();
+			while(now + 750 > rte_rdtsc()) {}
+
+			/* change mac addresses on packet */
+			eth = rte_pktmbuf_mtod(ev->mbuf, struct ether_hdr *);
+			ether_addr_copy(&eth->d_addr, &addr);
+			ether_addr_copy(&eth->s_addr, &eth->d_addr);
+			ether_addr_copy(&addr, &eth->s_addr);
+		}
+		int ret = rte_event_enqueue_burst(event_dev_id, event_port_id,
+					rcv_events, n, false);
+		if (ret != n)
+			rte_panic("worker %u thread failed to enqueue event\n",
+				rte_lcore_id());
+	}
+
+	/* Flush the buffered events */
+	rte_event_dequeue(event_dev_id, event_port_id, NULL, false);
+
+	if (!quiet)
+		printf("  worker %u thread done. RX=%zu TX=%zu\n",
+				rte_lcore_id(), received, sent);
+
+	return 0;
+}
+
+static int
+scheduler(void *arg)
+{
+	RTE_SET_USED(arg);
+	size_t loops = 0;
+
+	while (!done) {
+		/* Assumes an event dev ID of 0 */
+		rte_event_schedule(0);
+		loops++;
+	}
+
+	printf("  scheduler thread done. loops=%zu\n", loops);
+
+	return 0;
+}
+
+static int
+consumer(void *arg)
+{
+	struct rte_event events[BATCH_SIZE];
+
+	struct cons_data *data = (struct cons_data *)arg;
+	uint8_t event_dev_id = data->event_dev_id;
+	uint8_t event_port_id = data->event_port_id;
+	struct rte_eth_dev_tx_buffer *tx_buf[RTE_MAX_ETHPORTS];
+	size_t npackets = num_packets;
+	size_t received = 0;
+	size_t received_printed = 0; /* tracks when we last printed receive count */
+	uint64_t start_time = 0;
+	uint64_t freq_khz = rte_get_timer_hz() / 1000;
+	uint64_t dropped = 0;
+	unsigned i;
+
+	for (i = 0; i < rte_eth_dev_count(); i++) {
+		tx_buf[i] = rte_malloc(NULL, RTE_ETH_TX_BUFFER_SIZE(32), 0);
+		if (tx_buf[i] == NULL)
+			rte_panic("Out of memory\n");
+		rte_eth_tx_buffer_init(tx_buf[i], 32);
+		rte_eth_tx_buffer_set_err_callback(tx_buf[i],
+				rte_eth_tx_buffer_count_callback, &dropped);
+	}
+
+	while (!done) {
+		uint16_t i;
+		uint16_t n = rte_event_dequeue_burst(event_dev_id,
+						     event_port_id,
+						     events,
+						     RTE_DIM(events),
+						     false);
+
+		if (n == 0){
+			rte_pause();
+			continue;
+		}
+		if (start_time == 0)
+			start_time = rte_get_timer_cycles();
+
+		received += n;
+		for (i = 0; i < n; i++) {
+			uint8_t outport = events[i].mbuf->port;
+			rte_eth_tx_buffer(outport, 0, tx_buf[outport], events[i].mbuf);
+		}
+
+		if (!quiet && received >= received_printed + (1<<22)) {
+			printf("# consumer RX=%zu, time %"PRIu64"ms\n",
+					received,
+					(rte_get_timer_cycles() - start_time) / freq_khz);
+			received_printed = received;
+		}
+
+		if (num_packets > 0 && npackets > 0) {
+			npackets -= n;
+			if (npackets == 0)
+				done = 1;
+		}
+	}
+
+	for (i = 0; i < rte_eth_dev_count(); i++)
+		rte_eth_tx_buffer_flush(i, 0, tx_buf[i]);
+
+	printf("  consumer done! RX=%zu, time %"PRIu64"ms\n",
+			received,
+			(rte_get_timer_cycles() - start_time) / freq_khz);
+
+	return 0;
+}
+
+static int
+producer(void *arg)
+{
+
+	struct prod_data *data = (struct prod_data *)arg;
+	size_t npackets = num_packets;
+	unsigned i;
+	uint64_t mbuf_seqno = 0;
+	size_t sent = 0;
+	uint8_t eth_port = 0;
+	uint8_t event_dev_id = data->event_dev_id;
+	uint8_t event_port_id = data->event_port_id;
+	int fid_counter = 0;
+
+	while (!done) {
+		int ret;
+		unsigned num_ports = data->num_ports;
+		int32_t qid = data->qid;
+		struct rte_event events[BATCH_SIZE];
+		struct rte_mbuf *mbufs[BATCH_SIZE];
+
+		uint16_t nb_rx = rte_eth_rx_burst(eth_port, 0, mbufs, BATCH_SIZE);
+		if (++eth_port == num_ports)
+			eth_port = 0;
+		if (nb_rx == 0) {
+			rte_pause();
+			/* Flush any buffered events */
+			rte_event_dequeue(event_dev_id,
+					  event_port_id,
+					  NULL,
+					  false);
+			continue;
+		}
+
+		for (i = 0; i < nb_rx; i++) {
+			struct rte_mbuf *m = mbufs[i];
+			struct rte_event *ev = &events[i];
+
+			ev->queue_id = qid;
+			ev->flow_id = fid_counter++ % 6;
+			ev->priority = 0;
+			m->udata64 = mbuf_seqno++;
+			ev->mbuf = m;
+			ev->sched_type = sched_type;
+			ev->operation = RTE_EVENT_OP_NEW;
+		}
+
+		do {
+			ret = rte_event_enqueue_burst(event_dev_id,
+							event_port_id,
+							events,
+							nb_rx,
+							false);
+		} while (ret == -ENOSPC);
+		if (ret != nb_rx)
+			rte_panic("producer thread failed to enqueue *all* events\n");
+
+		sent += nb_rx;
+
+		if (num_packets > 0 && npackets > 0) {
+			npackets -= nb_rx;
+			if (npackets == 0)
+				break;
+		}
+	}
+
+	/* Flush any buffered events */
+	while (!done)
+		rte_event_dequeue(event_dev_id, event_port_id, NULL, false);
+
+	printf("  prod thread done! TX=%zu across %u flows\n", sent, num_fids);
+
+	return 0;
+}
+
+static struct option long_options[] = {
+	{"workers", required_argument, 0, 'w'},
+	{"packets", required_argument, 0, 'n'},
+	{"atomic-flows", required_argument, 0, 'f'},
+	{"priority", required_argument, 0, 'p'},
+	{"ordered", no_argument, 0, 'o'},
+	{"quiet", no_argument, 0, 'q'},
+	{0, 0, 0, 0}
+};
+
+static void
+usage(void)
+{
+	const char *usage_str =
+		"  Usage: eventdev_pipeline [options]\n"
+		"  Options:\n"
+		"  -w, --workers=N       Use N workers (default 4)\n"
+		"  -n, --packets=N       Send N packets (default ~32M), 0 implies no limit\n"
+		"  -f, --atomic-flows=N  Use N random flows from 1 to N (default 16)\n"
+		"  -p, --priority=N      Use N number of priorities (default 1)\n"
+		"  -o, --ordered         Use ordered scheduling\n"
+		"  -q, --quiet           Minimize printed output\n"
+		"\n";
+
+	fprintf(stderr, "%s", usage_str);
+	exit(1);
+}
+
+static void
+parse_app_args(int argc, char** argv)
+{
+	/* Parse cli options*/
+	int option_index;
+	int c;
+	opterr = 0;
+
+	for (;;) {
+		c = getopt_long(argc, argv, "w:n:f:p:oq", long_options,
+				&option_index);
+		if (c == -1)
+			break;
+
+		switch (c) {
+			case 'w':
+				num_workers = (unsigned int)atoi(optarg);
+				break;
+			case 'n':
+				num_packets = (unsigned long )atol(optarg);
+				break;
+			case 'f':
+				num_fids = (unsigned int)atoi(optarg);
+				break;
+			case 'p':
+				num_priorities = (unsigned int)atoi(optarg);
+				break;
+			case 'o':
+				sched_type = RTE_SCHED_TYPE_ORDERED;
+				break;
+			case 'q':
+				quiet = 1;
+				break;
+			default:
+				usage();
+		}
+	}
+	if (num_workers == 0)
+		usage();
+}
+
+/*
+ * Initializes a given port using global settings and with the RX buffers
+ * coming from the mbuf_pool passed as a parameter.
+ */
+static inline int
+port_init(uint8_t port, struct rte_mempool *mbuf_pool)
+{
+	static const struct rte_eth_conf port_conf_default = {
+		.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }
+	};
+	const uint16_t rx_rings = 1, tx_rings = 1;
+	const uint16_t rx_ring_size = 512, tx_ring_size = 512;
+	struct rte_eth_conf port_conf = port_conf_default;
+	int retval;
+	uint16_t q;
+
+	if (port >= rte_eth_dev_count())
+		return -1;
+
+	/* Configure the Ethernet device. */
+	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
+	if (retval != 0)
+		return retval;
+
+	/* Allocate and set up 1 RX queue per Ethernet port. */
+	for (q = 0; q < rx_rings; q++) {
+		retval = rte_eth_rx_queue_setup(port, q, rx_ring_size,
+				rte_eth_dev_socket_id(port), NULL, mbuf_pool);
+		if (retval < 0)
+			return retval;
+	}
+
+	/* Allocate and set up 1 TX queue per Ethernet port. */
+	for (q = 0; q < tx_rings; q++) {
+		retval = rte_eth_tx_queue_setup(port, q, tx_ring_size,
+				rte_eth_dev_socket_id(port), NULL);
+		if (retval < 0)
+			return retval;
+	}
+
+	/* Start the Ethernet port. */
+	retval = rte_eth_dev_start(port);
+	if (retval < 0)
+		return retval;
+
+	/* Display the port MAC address. */
+	struct ether_addr addr;
+	rte_eth_macaddr_get(port, &addr);
+	printf("Port %u MAC: %02" PRIx8 " %02" PRIx8 " %02" PRIx8
+			   " %02" PRIx8 " %02" PRIx8 " %02" PRIx8 "\n",
+			(unsigned)port,
+			addr.addr_bytes[0], addr.addr_bytes[1],
+			addr.addr_bytes[2], addr.addr_bytes[3],
+			addr.addr_bytes[4], addr.addr_bytes[5]);
+
+	/* Enable RX in promiscuous mode for the Ethernet device. */
+	rte_eth_promiscuous_enable(port);
+
+	return 0;
+}
+
+static int
+init_ports(unsigned num_ports)
+{
+	uint8_t portid;
+
+	mp = rte_pktmbuf_pool_create("packet_pool",
+			/* mbufs */ 16384 * num_ports,
+			/* cache_size */ 512,
+			/* priv_size*/ 0,
+			/* data_room_size */ RTE_MBUF_DEFAULT_BUF_SIZE,
+			rte_socket_id());
+
+	for (portid = 0; portid < num_ports; portid++)
+		if (port_init(portid, mp) != 0)
+			rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n",
+					portid);
+	return 0;
+}
+
+static uint8_t
+setup_event_dev(struct prod_data *prod_data,
+		struct cons_data *cons_data,
+		struct worker_data *worker_data)
+{
+	struct rte_event_dev_config config;
+	struct rte_event_queue_conf queue_config;
+	struct rte_event_port_conf port_config;
+	struct rte_event_queue_link link;
+	int prod_port;
+	int cons_port;
+	int qid0;
+	int cons_qid;
+	int prod_qid;
+	unsigned i;
+	int ret;
+	int8_t id;
+
+	const char *dev_name = "evdev_sw0";
+	id = rte_event_dev_get_dev_id(dev_name);
+	if (id < 0)
+		rte_panic("Failed to get %s device ID\n", dev_name);
+
+	config.nb_event_queues = 3;
+	config.nb_event_ports = num_workers + 2;
+	config.nb_events_limit = 256;
+	config.dequeue_wait_ns = 0;
+
+	ret = rte_event_dev_configure(id, &config);
+	if (ret)
+		rte_panic("Failed to configure the event dev\n");
+
+	/* Create queues */
+	queue_config.event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY;
+	queue_config.priority = 0;
+
+	qid0 = 0;
+	ret = rte_event_queue_setup(id, qid0, &queue_config);
+	if (ret < 0)
+		rte_panic("Failed to create the scheduled QID\n");
+
+	queue_config.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER;
+	queue_config.priority = 0;
+
+	cons_qid = 1;
+	ret = rte_event_queue_setup(id, cons_qid, &queue_config);
+	if (ret < 0)
+		rte_panic("Failed to create the cons directed QID\n");
+
+	queue_config.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER;
+	queue_config.priority = 0;
+
+	prod_qid = 2;
+	ret = rte_event_queue_setup(id, prod_qid, &queue_config);
+	if (ret < 0)
+		rte_panic("Failed to create the prod directed QID\n");
+
+	/* Create ports */
+#define LB_PORT_DEPTH 16
+#define DIR_PORT_DEPTH 32
+	port_config.enqueue_queue_depth = LB_PORT_DEPTH;
+	port_config.dequeue_queue_depth = LB_PORT_DEPTH;
+	port_config.new_event_threshold = 255;
+
+	prod_port = 0;
+	ret = rte_event_port_setup(id, prod_port, &port_config);
+	if (ret < 0)
+		rte_panic("Failed to create the producer port\n");
+
+	cons_port = 1;
+	port_config.enqueue_queue_depth = DIR_PORT_DEPTH;
+	port_config.dequeue_queue_depth = DIR_PORT_DEPTH;
+	ret = rte_event_port_setup(id, cons_port, &port_config);
+	if (ret < 0)
+		rte_panic("Failed to create the consumer port\n");
+
+	port_config.enqueue_queue_depth = LB_PORT_DEPTH;
+	port_config.dequeue_queue_depth = LB_PORT_DEPTH;
+	for (i = 0; i < num_workers; i++) {
+		worker_data[i].event_port_id = i + 2;
+		ret = rte_event_port_setup(id, worker_data[i].event_port_id, &port_config);
+		if (ret < 0)
+			rte_panic("Failed to create worker port #%d\n", i);
+	}
+
+	/* Map ports/qids */
+	for (i = 0; i < num_workers; i++) {
+		link.queue_id = qid0;
+		link.priority = 0;
+
+		ret = rte_event_port_link(id, worker_data[i].event_port_id, &link, 1);
+		if (ret != 1)
+			rte_panic("Failed to map worker%d port to qid0\n", i);
+	}
+
+	/* Link consumer port to its QID */
+	link.queue_id = cons_qid;
+	link.priority = 0;
+
+	ret = rte_event_port_link(id, cons_port, &link, 1);
+	if (ret != 1)
+		rte_panic("Failed to map consumer port to cons_qid\n");
+
+	/* Link producer port to its QID */
+	link.queue_id = prod_qid;
+	link.priority = 0;
+
+	ret = rte_event_port_link(id, prod_port, &link, 1);
+	if (ret != 1)
+		rte_panic("Failed to map producer port to prod_qid\n");
+
+	/* Dispatch to slaves */
+	*prod_data = (struct prod_data){.event_dev_id = id,
+					.event_port_id = prod_port,
+					.qid = qid0};
+	*cons_data = (struct cons_data){.event_dev_id = id,
+					.event_port_id = cons_port};
+
+	for (i = 0; i < num_workers; i++) {
+		struct worker_data *w = &worker_data[i];
+		w->event_dev_id = id;
+		w->qid = cons_qid;
+	}
+
+	if (rte_event_dev_start(id) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	return (uint8_t) id;
+}
+
+static void sighndlr(int sig)
+{
+	/* Ctlr-Z to dump stats */
+	if(sig == SIGTSTP) {
+		rte_mempool_dump(stdout, mp);
+		rte_event_dev_dump(stdout, 0);
+	}
+	/* Ctlr-C to exit */
+	if(sig == SIGINT)
+		rte_exit(0, "sigint arrived, quitting\n");
+}
+
+int
+main(int argc, char **argv)
+{
+	signal(SIGINT , sighndlr);
+	signal(SIGTSTP, sighndlr);
+
+	struct prod_data prod_data = {0};
+	struct cons_data cons_data = {0};
+	struct worker_data *worker_data;
+	unsigned nworkers = 0;
+	unsigned num_ports;
+	int lcore_id;
+	int err;
+	int has_prod = 0;
+	int has_cons = 0;
+	int has_scheduler = 0;
+
+	err = rte_eal_init(argc, argv);
+	if (err < 0)
+		rte_panic("Invalid EAL arguments\n");
+
+	argc -= err;
+	argv += err;
+
+	/* Parse cli options*/
+	parse_app_args(argc, argv);
+
+	num_ports = rte_eth_dev_count();
+	if (num_ports == 0)
+		rte_panic("No ethernet ports found\n");
+
+	if (!quiet) {
+		printf("  Config:\n");
+		printf("\tports: %u\n", num_ports);
+		printf("\tworkers: %u\n", num_workers);
+		printf("\tpackets: %lu\n", num_packets);
+		printf("\tflows: %u\n", num_fids);
+		printf("\tpriorities: %u\n", num_priorities);
+		if (sched_type == RTE_SCHED_TYPE_ORDERED)
+			printf("\tqid0 type: ordered\n");
+		if (sched_type == RTE_SCHED_TYPE_ATOMIC)
+			printf("\tqid0 type: atomic\n");
+		printf("\n");
+	}
+
+	const unsigned cores_needed = num_workers +
+			/*main*/1 +
+			/*sched*/1 +
+			/*TX*/1 +
+			/*RX*/1;
+
+	if (!quiet) {
+		printf("Number of cores available: %u\n", rte_lcore_count());
+		printf("Number of cores to be used: %u\n", cores_needed);
+	}
+
+	if (rte_lcore_count() < cores_needed)
+		rte_panic("Too few cores\n");
+
+	const uint8_t ndevs = rte_event_dev_count();
+	if (ndevs == 0)
+		rte_panic("No event devs found. Do you need to pass in a --vdev flag?\n");
+	if (ndevs > 1)
+		fprintf(stderr, "Warning: More than one event dev, using idx 0");
+
+	worker_data = rte_calloc(0, num_workers, sizeof(worker_data[0]), 0);
+	if (worker_data == NULL)
+		rte_panic("rte_calloc failed\n");
+
+	uint8_t id = setup_event_dev(&prod_data, &cons_data, worker_data);
+	RTE_SET_USED(id);
+
+	prod_data.num_ports = num_ports;
+	init_ports(num_ports);
+
+	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+		if (has_prod && has_cons && has_scheduler && nworkers == num_workers)
+			break;
+
+		if (!has_scheduler) {
+			err = rte_eal_remote_launch(scheduler, NULL, lcore_id);
+			if (err)
+				rte_panic("Failed to launch scheduler\n");
+
+			has_scheduler = 1;
+			continue;
+		}
+
+		if (nworkers < num_workers) {
+			err = rte_eal_remote_launch(worker, &worker_data[nworkers], lcore_id);
+			if (err)
+				rte_panic("Failed to launch worker%d\n", nworkers);
+			nworkers++;
+			continue;
+		}
+
+		if (!has_cons) {
+			err = rte_eal_remote_launch(consumer, &cons_data, lcore_id);
+			if (err)
+				rte_panic("Failed to launch consumer\n");
+			has_cons = 1;
+			continue;
+		}
+
+		if (!has_prod) {
+			err = rte_eal_remote_launch(producer, &prod_data, lcore_id);
+			if (err)
+				rte_panic("Failed to launch producer\n");
+			has_prod = 1;
+			continue;
+		}
+	}
+
+	rte_eal_mp_wait_lcore();
+
+	/* Cleanup done automatically by kernel on app exit */
+
+	return 0;
+}
-- 
2.7.4

^ permalink raw reply related

* [PATCH 6/7] test/eventdev: unit func makefiles
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, Gage Eads, David Hunt
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

Enable the functional and unit tests in the makefile. To run the unit tests,
apply these patches, and run the test app with the following arguments and
choose the unit or functional test to run:
     ./test --vdev evdev_sw0
     RTE>> eventdev_func_autotest
     RTE>> eventdev_unit_autotest

Signed-off-by: Gage Eads <gage.eads@intel.com>
Signed-off-by: David Hunt <david.hunt@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 app/test/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/app/test/Makefile b/app/test/Makefile
index 5be023a..6d43cb7 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -197,6 +197,9 @@ SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_blockcipher.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev_perf.c
 SRCS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += test_cryptodev.c
 
+SRCS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += test_eventdev_unit.c
+SRCS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += test_eventdev_func.c
+
 SRCS-$(CONFIG_RTE_LIBRTE_KVARGS) += test_kvargs.c
 
 CFLAGS += -O3
-- 
2.7.4

^ permalink raw reply related

* [PATCH 5/7] test/eventdev: unit and functional tests
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, Gage Eads, David Hunt
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

This commit adds basic unit and functional tests for the eventdev
API. The test code is added in this commit, but not yet enabled until
the next commit.

Signed-off-by: Gage Eads <gage.eads@intel.com>
Signed-off-by: David Hunt <david.hunt@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 app/test/test_eventdev_func.c | 1268 +++++++++++++++++++++++++++++++++++++++++
 app/test/test_eventdev_unit.c |  557 ++++++++++++++++++
 2 files changed, 1825 insertions(+)
 create mode 100644 app/test/test_eventdev_func.c
 create mode 100644 app/test/test_eventdev_unit.c

diff --git a/app/test/test_eventdev_func.c b/app/test/test_eventdev_func.c
new file mode 100644
index 0000000..d7fe481
--- /dev/null
+++ b/app/test/test_eventdev_func.c
@@ -0,0 +1,1268 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/queue.h>
+
+#include <rte_memory.h>
+#include <rte_memzone.h>
+#include <rte_launch.h>
+#include <rte_eal.h>
+#include <rte_per_lcore.h>
+#include <rte_lcore.h>
+#include <rte_debug.h>
+#include <rte_ethdev.h>
+#include <rte_cycles.h>
+
+#include <rte_eventdev.h>
+#include "test.h"
+
+#define MAX_PORTS 16
+#define MAX_QIDS 16
+#define NUM_PACKETS (1<<18)
+
+struct test {
+	struct rte_mempool *mbuf_pool;
+	int ev;
+	int port[MAX_PORTS];
+	int qid[MAX_QIDS];
+	int nb_qids;
+};
+
+static inline struct rte_mbuf *
+rte_gen_arp(int portid, struct rte_mempool *mp)
+{
+	/*
+	* len = 14 + 46
+	* ARP, Request who-has 10.0.0.1 tell 10.0.0.2, length 46
+	*/
+	static const uint8_t arp_request[] = {
+		/*0x0000:*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xec, 0xa8,
+		0x6b, 0xfd, 0x02, 0x29, 0x08, 0x06, 0x00, 0x01,
+		/*0x0010:*/ 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xec, 0xa8,
+		0x6b, 0xfd, 0x02, 0x29, 0x0a, 0x00, 0x00, 0x01,
+		/*0x0020:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00,
+		0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		/*0x0030:*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00
+	};
+	struct rte_mbuf *m;
+	int pkt_len = sizeof(arp_request) - 1;
+
+	m = rte_pktmbuf_alloc(mp);
+	if (!m)
+		return 0;
+
+	memcpy((void *)((uint64_t)m->buf_addr + m->data_off),
+		arp_request, pkt_len);
+	rte_pktmbuf_pkt_len(m) = pkt_len;
+	rte_pktmbuf_data_len(m) = pkt_len;
+
+	RTE_SET_USED(portid);
+	/*
+	 * Ignore MAC address for super-simple testing
+	 * struct ether_addr mac_addr;
+	 * rte_eth_macaddr_get(portid, &mac_addr);
+	 * memcpy((void *)((uint64_t)m->buf_addr + m->data_off + 6),
+	 * &mac_addr, 6);
+	 */
+
+	return m;
+}
+
+/* initialization and config */
+static inline int
+init(struct test *t, int nb_queues, int nb_ports)
+{
+	struct rte_event_dev_config config = {
+			.nb_event_queues = nb_queues,
+			.nb_event_ports = nb_ports,
+	};
+	int ret, nevdevs = rte_event_dev_count();
+
+	void *temp = t->mbuf_pool; /* save and restore mbuf pool */
+
+	memset(t, 0, sizeof(*t));
+	t->mbuf_pool = temp;
+
+	if (nevdevs < 1) {
+		printf("%d: No Eventdev Devices Found\n", __LINE__);
+		return -1;
+	}
+
+	const char *eventdev_name = "evdev_sw0";
+
+	t->ev = rte_event_dev_get_dev_id(eventdev_name);
+	if (t->ev < 0) {
+		printf("%d: Eventdev %s not found - quitting.\n", __LINE__, eventdev_name);
+		return -1;
+	}
+
+	ret = rte_event_dev_configure(t->ev, &config);
+	if (ret < 0)
+		printf("%d: Error configuring device\n", __LINE__);
+	return ret;
+};
+
+static inline int
+create_ports(struct test *t, int num_ports)
+{
+	int i;
+	static const struct rte_event_port_conf conf = {
+			.dequeue_queue_depth = 32,
+			.enqueue_queue_depth = 64,
+	};
+
+	for (i = 0; i < num_ports; i++) {
+		if (rte_event_port_setup(t->ev, i, &conf) < 0) {
+			printf("Error setting up port %d\n", i);
+			return -1;
+		}
+		t->port[i] = i;
+	}
+
+	return 0;
+}
+
+static inline int
+create_atomic_qids(struct test *t, int num_qids)
+{
+	int i;
+
+	/* Q creation */
+	static const struct rte_event_queue_conf conf = {
+			.priority = RTE_EVENT_QUEUE_PRIORITY_NORMAL,
+			.nb_atomic_flows = 1024,
+	};
+
+	for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
+		if (rte_event_queue_setup(t->ev, i, &conf) < 0) {
+			printf("%d: error creating qid %d\n", __LINE__, i);
+			return -1;
+		}
+		t->qid[i] = i;
+	}
+	t->nb_qids += num_qids;
+
+	return 0;
+}
+
+static inline int
+create_ordered_qids(struct test *t, int num_qids)
+{
+	int i;
+
+	/* Q creation */
+	static const struct rte_event_queue_conf conf = {
+			.priority = RTE_EVENT_QUEUE_PRIORITY_NORMAL,
+			.nb_atomic_order_sequences = 1024,
+	};
+
+	for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
+		if (rte_event_queue_setup(t->ev, i, &conf) < 0) {
+			printf("%d: error creating qid %d\n", __LINE__, i);
+			return -1;
+		}
+		t->qid[i] = i;
+	}
+	t->nb_qids += num_qids;
+
+	return 0;
+}
+
+static inline int
+create_unordered_qids(struct test *t, int num_qids)
+{
+	int i;
+
+	/* Q creation */
+	static const struct rte_event_queue_conf conf = {
+			.priority = RTE_EVENT_QUEUE_PRIORITY_NORMAL,
+	};
+
+	for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
+		if (rte_event_queue_setup(t->ev, i, &conf) < 0) {
+			printf("%d: error creating qid %d\n", __LINE__, i);
+			return -1;
+		}
+		t->qid[i] = i;
+	}
+	t->nb_qids += num_qids;
+
+	return 0;
+}
+
+static inline int
+create_directed_qids(struct test *t, int num_qids, int ports[])
+{
+	int i;
+
+	/* Q creation */
+	static const struct rte_event_queue_conf conf = {
+			.priority = RTE_EVENT_QUEUE_PRIORITY_NORMAL,
+			.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER,
+	};
+
+	for (i = t->nb_qids; i < t->nb_qids + num_qids; i++) {
+		struct rte_event_queue_link link;
+
+		if (rte_event_queue_setup(t->ev, i, &conf) < 0) {
+			printf("%d: error creating qid %d\n", __LINE__, i);
+			return -1;
+		}
+		t->qid[i] = i;
+
+		link = (struct rte_event_queue_link){
+			t->qid[i],
+			RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL
+		};
+		if (rte_event_port_link(t->ev, ports[i - t->nb_qids], &link, 1) != 1) {
+			printf("%d: error creating link for qid %d\n",
+					__LINE__, i);
+			return -1;
+		}
+	}
+	t->nb_qids += num_qids;
+
+	return 0;
+}
+
+/* destruction */
+static inline int
+cleanup(struct test *t)
+{
+	rte_event_dev_stop(t->ev);
+	rte_event_dev_close(t->ev);
+	return 0;
+};
+
+/* run_prio_packet_test
+ * This performs a basic packet priority check on the test instance passed in.
+ * It is factored out of the main priority tests as the same tests must be
+ * performed to ensure prioritization of each type of QID.
+ *
+ * Requirements:
+ *  - An initialized test structure, including mempool
+ *  - t->port[0] is initialized for both Enq / Deq of packets to the QID
+ *  - t->qid[0] is the QID to be tested
+ *  - if LB QID, the CQ must be mapped to the QID.
+ */
+static int
+run_prio_packet_test(struct test *t)
+{
+	int err;
+	const uint32_t MAGIC_SEQN[] = {4711, 1234};
+	const uint32_t PRIORITY[] = {3, 0};
+	unsigned i;
+	for(i = 0; i < RTE_DIM(MAGIC_SEQN); i++) {
+		/* generate pkt and enqueue */
+		struct rte_event ev;
+		struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
+		if (!arp) {
+			printf("%d: gen of pkt failed\n", __LINE__);
+			return -1;
+		}
+		arp->seqn = MAGIC_SEQN[i];
+
+		ev = (struct rte_event){
+			.priority = PRIORITY[i],
+			.operation = RTE_EVENT_OP_NEW,
+			.queue_id = t->qid[0],
+			.mbuf = arp
+		};
+		err = rte_event_enqueue(t->ev, t->port[0], &ev, 0);
+		if (err < 0) {
+			printf("%d: error failed to enqueue\n", __LINE__);
+			return -1;
+		}
+	}
+
+	rte_event_schedule(t->ev);
+
+	struct rte_event_dev_stats stats;
+	err = rte_event_dev_stats_get(t->ev, &stats);
+	if (err) {
+		printf("%d: error failed to get stats\n", __LINE__);
+		return -1;
+	}
+
+	if (stats.port_rx_pkts[t->port[0]] != 2) {
+		printf("%d: error stats incorrect for directed port\n", __LINE__);
+		rte_event_dev_dump(stdout, t->ev);
+		return -1;
+	}
+
+	struct rte_event ev, ev2;
+	uint32_t deq_pkts;
+	deq_pkts = rte_event_dequeue(t->ev, t->port[0], &ev, 0);
+	if (deq_pkts != 1) {
+		printf("%d: error failed to deq\n", __LINE__);
+		rte_event_dev_dump(stdout, t->ev);
+		return -1;
+	}
+	if(ev.mbuf->seqn != MAGIC_SEQN[1]) {
+		printf("%d: first packet out not highest priority\n", __LINE__);
+		rte_event_dev_dump(stdout, t->ev);
+		return -1;
+	}
+	rte_pktmbuf_free(ev.mbuf);
+
+	deq_pkts = rte_event_dequeue(t->ev, t->port[0], &ev2, 0);
+	if (deq_pkts != 1) {
+		printf("%d: error failed to deq\n", __LINE__);
+		rte_event_dev_dump(stdout, t->ev);
+		return -1;
+	}
+	if(ev2.mbuf->seqn != MAGIC_SEQN[0]) {
+		printf("%d: second packet out not lower priority\n", __LINE__);
+		rte_event_dev_dump(stdout, t->ev);
+		return -1;
+	}
+	rte_pktmbuf_free(ev2.mbuf);
+
+	cleanup(t);
+	return 0;
+}
+
+static int
+test_single_directed_packet(struct test *t)
+{
+	const int rx_enq = 0;
+	const int wrk_enq = 2;
+	int err;
+
+	/* Create instance with 3 directed QIDs going to 3 ports */
+	if (init(t, 3, 3) < 0 ||
+			create_ports(t, 3) < 0 ||
+			create_directed_qids(t, 3, t->port) < 0)
+		return -1;
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	/************** FORWARD ****************/
+	struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
+	struct rte_event ev = {
+			.operation = RTE_EVENT_OP_NEW,
+			.queue_id = wrk_enq,
+			.mbuf = arp,
+	};
+
+	if (!arp) {
+		printf("%d: gen of pkt failed\n", __LINE__);
+		return -1;
+	}
+
+	const uint32_t MAGIC_SEQN = 4711;
+	arp->seqn = MAGIC_SEQN;
+
+	/* generate pkt and enqueue */
+	err = rte_event_enqueue(t->ev, rx_enq, &ev, 0);
+	if (err < 0) {
+		printf("%d: error failed to enqueue\n", __LINE__);
+		return -1;
+	}
+
+	/* Run schedule() as dir packets may need to be re-ordered */
+	if (rte_event_schedule(t->ev) < 0) {
+		printf("%d: Error with schedule call\n", __LINE__);
+		return -1;
+	}
+
+	struct rte_event_dev_stats stats;
+	err = rte_event_dev_stats_get(t->ev, &stats);
+	if (err) {
+		printf("%d: error failed to get stats\n", __LINE__);
+		return -1;
+	}
+
+	if (stats.port_rx_pkts[rx_enq] != 1) {
+		printf("%d: error stats incorrect for directed port\n", __LINE__);
+		return -1;
+	}
+
+	uint32_t deq_pkts;
+	deq_pkts = rte_event_dequeue(t->ev, wrk_enq, &ev, 1);
+	if (deq_pkts != 1) {
+		printf("%d: error failed to deq\n", __LINE__);
+		return -1;
+	}
+
+	err = rte_event_dev_stats_get(t->ev, &stats);
+	if (stats.port_rx_pkts[wrk_enq] != 0 &&
+			stats.port_rx_pkts[wrk_enq] != 1) {
+		printf("%d: error directed stats post-dequeue\n", __LINE__);
+		return -1;
+	}
+
+	if (ev.mbuf->seqn != MAGIC_SEQN) {
+		printf("%d: error magic sequence number not dequeued\n", __LINE__);
+		return -1;
+	}
+
+	rte_pktmbuf_free(ev.mbuf);
+	cleanup(t);
+	return 0;
+}
+
+static int
+test_overload_trip(struct test *t)
+{
+	int err;
+
+	/* Create instance with 3 directed QIDs going to 3 ports */
+	if (init(t, 1, 1) < 0 ||
+			create_ports(t, 1) < 0 ||
+			create_atomic_qids(t, 1) < 0)
+		return -1;
+
+	struct rte_event_queue_link link = {t->qid[0],
+			RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+	int ret = rte_event_port_link(t->ev, t->port[0], &link, 1);
+	if (ret != 1) {
+		printf("%d: error mapping lb qid0\n", __LINE__);
+		return -1;
+	}
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
+	if (!arp) {
+		printf("%d: gen of pkt failed\n", __LINE__);
+		return -1;
+	}
+
+	/* 512 packets is threshold
+	 * iters 0 - 511 is 512 packets, then overload will be flagged
+	 * iter 512 (the 513th pkt) is the first refused NEW packet */
+	const uint32_t THRES = (256+1);
+	uint32_t i;
+	for (i = 0; i < THRES; i++) {
+		struct rte_event ev = {
+				.operation = RTE_EVENT_OP_NEW,
+				.queue_id = t->qid[0],
+				.mbuf = arp,
+		};
+		err = rte_event_enqueue(t->ev, 0, &ev, 0);
+		if(i == THRES-1) {
+			if(err != -ENOSPC) {
+				printf("%d: overload trip didn't cause NEW pkt enq fail\n", __LINE__);
+				return -1;
+			}
+			else {
+				//printf("iter %d -ENOSPC returned for new enq as expected.\n", i);
+			}
+		} else {
+			if (err < 0) {
+				printf("%d: error failed to enqueue\n", __LINE__);
+				return -1;
+			}
+		}
+	}
+
+	for (i = 0; i < THRES; i++) {
+		if (rte_event_schedule(t->ev) < 0) {
+			printf("%d: Error with schedule call\n", __LINE__);
+			return -1;
+		}
+
+		uint32_t deq_pkts;
+		struct rte_event ev;
+		deq_pkts = rte_event_dequeue(t->ev, 0, &ev, 1);
+
+		/* i == THRES-1 *should* fail to deq, due to NEW pkt rejection
+		 * when enqueue is attempted in overload mode */
+		if (i == (THRES-1) && deq_pkts == 0)
+			break;
+
+		if (deq_pkts != 1) {
+			printf("%d: warning failed to deq event i = %d\n",
+					__LINE__, i);
+			//return -1;
+		}
+	}
+
+	rte_pktmbuf_free(arp);
+	cleanup(t);
+	return 0;
+}
+
+static int
+test_directed_overload(struct test *t)
+{
+	int err;
+
+	/* Create instance with 3 directed QIDs going to 3 ports */
+	if (init(t, 1, 1) < 0 ||
+			create_ports(t, 1) < 0 ||
+			create_directed_qids(t, 1, t->port) < 0)
+		return -1;
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	/* 512 packets is threshold
+	 * iters 0 - 511 is 512 packets, then overload will be flagged
+	 * iter 512 (the 513th pkt) is the first refused NEW packet */
+	const uint32_t THRES = (256+1);
+	uint32_t i;
+	for (i = 0; i < THRES; i++) {
+		struct rte_event ev = {
+				.operation = RTE_EVENT_OP_NEW,
+				.queue_id = t->qid[0],
+				.event = (uintptr_t)i,
+		};
+		err = rte_event_enqueue(t->ev, 0, &ev, 0);
+		if(i == THRES-1) {
+			if(err != -ENOSPC) {
+				printf("%d: overload trip didn't cause NEW pkt enq fail\n", __LINE__);
+				//return -1;
+			}
+			else {
+				//printf("iter %d -ENOSPC returned for new enq as expected.\n", i);
+			}
+		} else {
+			if (err < 0) {
+				printf("%d: error failed to enqueue\n", __LINE__);
+				return -1;
+			}
+		}
+	}
+
+	if (rte_event_schedule(t->ev) < 0) {
+		printf("%d: Error with schedule call\n", __LINE__);
+		return -1;
+	}
+
+	uint32_t pkt_deq_cntr = 0;
+	for (i = 0; i < THRES; i++) {
+		if (rte_event_schedule(t->ev) < 0) {
+			printf("%d: Error with schedule call\n", __LINE__);
+			return -1;
+		}
+
+		int32_t deq_pkts;
+		struct rte_event ev;
+		deq_pkts = rte_event_dequeue(t->ev, 0, &ev, 1);
+
+		/* i == THRES-1 *should* fail to deq, due to NEW pkt rejection
+		 * when enqueue is attempted in overload mode */
+		if (i == (THRES-1) && deq_pkts == 0)
+			break;
+
+		if (deq_pkts != 1) {
+			printf("%d: warning failed to deq (iter = %d), ret %d. Dumping stats\n",
+					__LINE__, i, deq_pkts);
+			rte_event_dev_dump(stdout, t->ev);
+			return -1;
+		}
+		pkt_deq_cntr += deq_pkts;
+	}
+
+	cleanup(t);
+	return 0;
+}
+
+
+static int
+test_priority_directed(struct test *t)
+{
+	if (init(t, 1, 1) < 0 ||
+			create_ports(t, 1) < 0 ||
+			create_directed_qids(t, 1, t->port) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	return run_prio_packet_test(t);
+}
+
+static int
+test_priority_atomic(struct test *t)
+{
+	if (init(t, 1, 1) < 0 ||
+			create_ports(t, 1) < 0 ||
+			create_atomic_qids(t, 1) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	/* map the QID */
+	struct rte_event_queue_link link = {t->qid[0],
+			RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+	if (rte_event_port_link(t->ev, t->port[0], &link, 1) != 1) {
+		printf("%d: error mapping qid to port\n", __LINE__);
+		return -1;
+	}
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	return run_prio_packet_test(t);
+}
+
+static int
+test_priority_ordered(struct test *t)
+{
+	if (init(t, 1, 1) < 0 ||
+			create_ports(t, 1) < 0 ||
+			create_ordered_qids(t, 1) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	/* map the QID */
+	struct rte_event_queue_link link = {t->qid[0],
+			RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+	if (rte_event_port_link(t->ev, t->port[0], &link, 1) != 1) {
+		printf("%d: error mapping qid to port\n", __LINE__);
+		return -1;
+	}
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	return run_prio_packet_test(t);
+}
+
+static int
+test_priority_unordered(struct test *t)
+{
+	if (init(t, 1, 1) < 0 ||
+			create_ports(t, 1) < 0 ||
+			create_unordered_qids(t, 1) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	/* map the QID */
+	struct rte_event_queue_link link = {t->qid[0],
+			RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+	if (rte_event_port_link(t->ev, t->port[0], &link, 1) != 1) {
+		printf("%d: error mapping qid to port\n", __LINE__);
+		return -1;
+	}
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	return run_prio_packet_test(t);
+}
+
+static int
+burst_packets(struct test *t)
+{
+	/************** CONFIG ****************/
+	uint32_t i;
+	int err;
+	int ret;
+
+	/* Create instance with 4 ports and 2 queues */
+	if (init(t, 2, 2) < 0 ||
+			create_ports(t, 2) < 0 ||
+			create_atomic_qids(t, 2) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	/* CQ mapping to QID */
+	struct rte_event_queue_link link = {t->qid[0],
+			RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+	ret = rte_event_port_link(t->ev, t->port[0], &link, 1);
+	if (ret != 1) {
+		printf("%d: error mapping lb qid0\n", __LINE__);
+		return -1;
+	}
+	link.queue_id = t->qid[1];
+	ret = rte_event_port_link(t->ev, t->port[1], &link, 1);
+	if (ret != 1) {
+		printf("%d: error mapping lb qid1\n", __LINE__);
+		return -1;
+	}
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	/************** FORWARD ****************/
+	const uint32_t rx_port = 0;
+	const uint32_t NUM_PKTS = 2;
+
+	for (i = 0; i < NUM_PKTS; i++) {
+		struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
+		if (!arp) {
+			printf("%d: error generating pkt\n" , __LINE__);
+			return -1;
+		}
+
+		struct rte_event ev = {
+				.operation = RTE_EVENT_OP_NEW,
+				.queue_id = i % 2,
+				.flow_id = i % 3,
+				.mbuf = arp,
+		};
+		/* generate pkt and enqueue */
+		err = rte_event_enqueue(t->ev, t->port[rx_port], &ev, 0);
+		if (err < 1) {
+			printf("%d: Failed to enqueue\n", __LINE__);
+			return -1;
+		}
+	}
+	int16_t pkts = rte_event_schedule(t->ev);
+
+	RTE_SET_USED(pkts);
+
+	/* Check stats for all NUM_PKTS arrived to sched core */
+	struct rte_event_dev_stats stats;
+
+	err = rte_event_dev_stats_get(t->ev, &stats);
+	if (err) {
+		printf("%d: failed to get stats\n", __LINE__);
+		return -1;
+	}
+	if (stats.rx_pkts != NUM_PKTS || stats.tx_pkts != NUM_PKTS) {
+		printf("%d: Sched core didn't receive all %d pkts\n", __LINE__, NUM_PKTS);
+		rte_event_dev_dump(stdout, t->ev);
+		return -1;
+	}
+
+	uint32_t deq_pkts;
+	int p;
+
+	deq_pkts = 0;
+	/******** DEQ QID 1 *******/
+	do {
+		struct rte_event ev;
+		p = rte_event_dequeue(t->ev, t->port[0], &ev, 0);
+		deq_pkts += p;
+		rte_pktmbuf_free(ev.mbuf);
+	} while (p);
+
+	if (deq_pkts != NUM_PKTS/2) {
+		printf("%d: Half of NUM_PKTS didn't arrive at port 1\n", __LINE__);
+		return -1;
+	}
+
+	/******** DEQ QID 2 *******/
+	deq_pkts = 0;
+	do {
+		struct rte_event ev;
+		p = rte_event_dequeue(t->ev, t->port[1], &ev, 0);
+		deq_pkts += p;
+		rte_pktmbuf_free(ev.mbuf);
+	} while (p);
+	if (deq_pkts != NUM_PKTS/2) {
+		printf("%d: Half of NUM_PKTS didn't arrive at port 2\n", __LINE__);
+		return -1;
+	}
+
+	cleanup(t);
+	return 0;
+}
+
+static int
+load_balancing(struct test *t)
+{
+	const int rx_enq = 0;
+	int err;
+	uint32_t i;
+
+	if (init(t, 1, 4) < 0 ||
+			create_ports(t, 4) < 0 ||
+			create_atomic_qids(t, 1) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	struct rte_event_queue_link link = {t->qid[0],
+			RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+	for (i = 0; i < 3; i++) {
+		/* map port 1 - 3 inclusive */
+		if (rte_event_port_link(t->ev, t->port[i+1], &link, 1) != 1) {
+			printf("%d: error mapping qid to port %d\n", __LINE__, i);
+			return -1;
+		}
+	}
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	/************** FORWARD ****************/
+	/*
+	 * Create a set of flows that test the load-balancing operation of the
+	 * implementation. Fill CQ 0 and 1 with flows 0 and 1, and test
+	 * with a new flow, which should be sent to the 3rd mapped CQ
+	 */
+	static uint32_t flows[] = {0, 1, 1, 0, 0, 2, 2, 0, 2};
+#define PKT_NUM (sizeof(flows) / sizeof(flows[0]))
+	for (i = 0; i < PKT_NUM; i++) {
+		struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
+		if (!arp) {
+			printf("%d: gen of pkt failed\n", __LINE__);
+			return -1;
+		}
+
+		struct rte_event ev = {
+				.operation = RTE_EVENT_OP_NEW,
+				.queue_id = t->qid[0],
+				.flow_id = flows[i],
+				.mbuf = arp,
+		};
+		/* generate pkt and enqueue */
+		err = rte_event_enqueue(t->ev, t->port[rx_enq], &ev, 0);
+		if (err < 1) {
+			printf("%d: Failed to enqueue\n", __LINE__);
+			return -1;
+		}
+	}
+
+	rte_event_schedule(t->ev);
+
+	struct rte_event_dev_stats stats;
+	err = rte_event_dev_stats_get(t->ev, &stats);
+	if (err) {
+		printf("%d: failed to get stats\n", __LINE__);
+		return -1;
+	}
+
+	if (stats.port_inflight[1] != 4) {
+		printf("%d:%s: port 1 inflight not correct\n", __LINE__, __func__);
+		return -1;
+	}
+	if (stats.port_inflight[2] != 2) {
+		printf("%d:%s: port 2 inflight not correct\n", __LINE__, __func__);
+		return -1;
+	}
+	if (stats.port_inflight[3] != 3) {
+		printf("%d:%s: port 3 inflight not correct\n", __LINE__, __func__);
+		return -1;
+	}
+
+	cleanup(t);
+	return 0;
+}
+
+static int
+invalid_qid(struct test *t)
+{
+	struct rte_event_dev_stats stats;
+	const int rx_enq = 0;
+	int err;
+	uint32_t i;
+
+	if (init(t, 1, 4) < 0 ||
+			create_ports(t, 4) < 0 ||
+			create_atomic_qids(t, 1) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	/* CQ mapping to QID */
+	for(i = 0; i < 4; i++) {
+		struct rte_event_queue_link link = {t->qid[0],
+				RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+		err = rte_event_port_link(t->ev, t->port[i], &link, 1);
+		if (err != 1) {
+			printf("%d: error mapping port 1 qid\n", __LINE__);
+			return -1;
+		}
+	}
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	/*
+	 * Send in a packet with an invalid qid to the scheduler.
+	 * We should see the packed enqueued OK, but the inflights for
+	 * that packet should not be incremented, and the rx_dropped
+	 * should be incremented.
+	 */
+	static uint32_t flows1[] = {20};
+
+#define PKT_NUM1 (sizeof(flows1) / sizeof(flows1[0]))
+
+	for (i = 0; i < PKT_NUM1; i++) {
+		struct rte_mbuf *arp = rte_gen_arp(0, t->mbuf_pool);
+		if (!arp) {
+			printf("%d: gen of pkt failed\n", __LINE__);
+			return -1;
+		}
+
+		struct rte_event ev = {
+				.operation = RTE_EVENT_OP_NEW,
+				.queue_id = t->qid[0] + flows1[i],
+				.flow_id = i,
+				.mbuf = arp,
+		};
+		/* generate pkt and enqueue */
+		err = rte_event_enqueue(t->ev, t->port[rx_enq], &ev, 0);
+		if (err < 1) {
+			printf("%d: Failed to enqueue\n", __LINE__);
+			return -1;
+		}
+	}
+
+	/* call the scheduler */
+	int16_t pkts = rte_event_schedule(t->ev);
+	RTE_SET_USED(pkts);
+
+	err = rte_event_dev_stats_get(t->ev, &stats);
+	if (err) {
+		printf("%d: failed to get stats\n", __LINE__);
+		return -1;
+	}
+
+	/*
+	 * Now check the resulting inflights on the port, and the rx_dropped.
+	 */
+	if (stats.port_inflight[0] != 0) {
+		printf("%d:%s: port 1 inflight count not correct\n", __LINE__, __func__);
+		rte_event_dev_dump(stdout, 0);
+		return -1;
+	}
+	if (stats.port_rx_dropped[0] != 1) {
+		printf("%d:%s: port 1 drops\n", __LINE__, __func__);
+		rte_event_dev_dump(stdout, 0);
+		return -1;
+	}
+	/* each packet drop should only be counted in one place - port or dev */
+	if (stats.rx_dropped != 0) {
+		printf("%d:%s: port 1 dropped count not correct\n", __LINE__, __func__);
+		rte_event_dev_dump(stdout, 0);
+		return -1;
+	}
+
+	cleanup(t);
+	return 0;
+}
+
+static int
+worker_loopback_worker_fn(void *arg)
+{
+	struct test *t = arg;
+	uint8_t port = t->port[1];
+	int count = 0;
+	int err;
+
+	/*
+	 * Takes packets from the input port and then loops them back through
+	 * the Queue Manager. Each packet gets looped through QIDs 0-8, 16 times,
+	 * so each packet goes through 8*16 = 128 times.
+	 */
+	printf("%d: \tWorker function started\n", __LINE__);
+	while (count < NUM_PACKETS) {
+#define BURST_SIZE 32
+		struct rte_event ev[BURST_SIZE];
+		uint16_t i, nb_rx = rte_event_dequeue(t->ev, port, ev, BURST_SIZE);
+		if (nb_rx == 0) {
+			rte_pause();
+			continue;
+		}
+
+		for (i = 0; i < nb_rx; i++) {
+			ev[i].queue_id++;
+			if (ev[i].queue_id != 8) {
+				ev[i].operation = RTE_EVENT_OP_FORWARD;
+				err = rte_event_enqueue(t->ev, port, &ev[i], 0);
+				if (err <= 0) {
+					printf("%d: Can't enqueue FWD!!\n", __LINE__);
+					return -1;
+				}
+				continue;
+			}
+
+			ev[i].queue_id = 0;
+			ev[i].mbuf->udata64++;
+			if (ev[i].mbuf->udata64 != 16) {
+				ev[i].operation = RTE_EVENT_OP_FORWARD;
+				err = rte_event_enqueue(t->ev, port, &ev[i], 0);
+				if (err <= 0) {
+					printf("%d: Can't enqueue FWD!!\n", __LINE__);
+					return -1;
+				}
+				continue;
+			}
+			/* we have hit 16 iterations through system - drop */
+			rte_pktmbuf_free(ev[i].mbuf);
+			count++;
+			ev[i].operation = RTE_EVENT_OP_DROP;
+			err = rte_event_enqueue(t->ev, port, &ev[i], 0);
+			if(err != 1) {
+				printf("%d drop enqueue failed\n", __LINE__);
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int
+worker_loopback_producer_fn(void *arg)
+{
+	struct test *t = arg;
+	uint8_t port = t->port[0];
+	uint64_t count = 0;
+
+	printf("%d: \tProducer function started\n", __LINE__);
+	while (count < NUM_PACKETS) {
+		struct rte_mbuf *m = rte_pktmbuf_alloc(t->mbuf_pool);
+		if (m == NULL) {
+			printf("%d: Error allocating mbuf\n", __LINE__);
+			return -1;
+		}
+		m->udata64 = 0;
+
+		struct rte_event ev = {
+				.operation = RTE_EVENT_OP_NEW,
+				.queue_id = t->qid[0],
+				.flow_id = (uintptr_t)m & 0xFFFF,
+				.mbuf = m,
+		};
+
+		while (rte_event_enqueue(t->ev, port, &ev, 0) != 1)
+			rte_pause();
+
+		count++;
+	}
+
+	return 0;
+}
+
+static int
+worker_loopback(struct test *t)
+{
+	/* use a single producer core, and a worker core to see what happens
+	 * if the worker loops packets back multiple times
+	 */
+	struct rte_event_dev_stats stats;
+	uint64_t print_cycles = 0, cycles = 0;
+	uint64_t tx_pkts = 0;
+	int err;
+	int w_lcore, p_lcore;
+	uint32_t i;
+
+	if (init(t, 8, 2) < 0 ||
+			create_ports(t, 2) < 0 ||
+			create_atomic_qids(t, 8) < 0) {
+		printf("%d: Error initialising device\n", __LINE__);
+		return -1;
+	}
+
+	/* CQ mapping to QID */
+	for(i = 0; i < 8; i++) {
+		struct rte_event_queue_link link = {t->qid[i],
+				RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL };
+		err = rte_event_port_link(t->ev, t->port[1], &link, 1);
+		if (err != 1) {
+			printf("%d: error mapping port 2 qid %d\n", __LINE__, i);
+			return -1;
+		}
+	}
+
+	if (rte_event_dev_start(t->ev) < 0) {
+		printf("%d: Error with start call\n", __LINE__);
+		return -1;
+	}
+
+	p_lcore = rte_get_next_lcore(
+			/* start core */ -1,
+			/* skip master */ 1,
+			/* wrap */ 0);
+	w_lcore = rte_get_next_lcore(p_lcore, 1, 0);
+
+	rte_eal_remote_launch(worker_loopback_producer_fn, t, p_lcore);
+	rte_eal_remote_launch(worker_loopback_worker_fn, t, w_lcore);
+
+	print_cycles = cycles = rte_get_timer_cycles();
+	while (rte_eal_get_lcore_state(p_lcore) != FINISHED ||
+			rte_eal_get_lcore_state(w_lcore) != FINISHED) {
+
+		rte_event_schedule(t->ev);
+
+		uint64_t new_cycles = rte_get_timer_cycles();
+
+		if (new_cycles - print_cycles > rte_get_timer_hz()) {
+			rte_event_dev_stats_get(t->ev, &stats);
+			printf("%d: \tSched Rx = %" PRIu64 ", Tx = %" PRIu64 "\n",
+					__LINE__, stats.rx_pkts, stats.tx_pkts);
+
+			print_cycles = new_cycles;
+		}
+		if (new_cycles - cycles > rte_get_timer_hz() * 3) {
+			rte_event_dev_stats_get(t->ev, &stats);
+			if (stats.tx_pkts == tx_pkts) {
+				rte_event_dev_dump(stdout, t->ev);
+				printf("%d: \nNo schedules for seconds, deadlock\n", __LINE__);
+				return -1;
+			}
+			tx_pkts = stats.tx_pkts;
+			cycles = new_cycles;
+		}
+	}
+
+	rte_eal_mp_wait_lcore();
+
+	//rte_event_dev_dump(stdout, 0);
+
+	cleanup(t);
+	return 0;
+}
+
+static struct rte_mempool *eventdev_func_mempool;
+
+static int
+test_eventdev(void)
+{
+	struct test *t = malloc(sizeof(struct test));
+	int ret;
+
+	/* Only create mbuf pool once, reuse for each test run */
+	if (!eventdev_func_mempool) {
+		eventdev_func_mempool = rte_pktmbuf_pool_create("EVDEV_SA_MBUF_POOL",
+				(1<<16), /* size */
+				32 /*MBUF_CACHE_SIZE*/,
+				0,
+				RTE_MBUF_DEFAULT_BUF_SIZE,
+				rte_socket_id());
+		if (!eventdev_func_mempool) {
+			printf("ERROR creating mempool\n");
+			return -1;
+		}
+	}
+	t->mbuf_pool = eventdev_func_mempool;
+
+	printf("*** Running Single Directed Packet test...\n");
+	ret = test_single_directed_packet(t);
+	if (ret != 0) {
+		printf("ERROR - Single Directed Packet test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Overload Trip test...\n");
+	ret = test_overload_trip(t);
+	if (ret != 0) {
+		printf("ERROR - Overload Trip test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Directed Overload test...\n");
+	ret = test_directed_overload(t);
+	if (ret != 0) {
+		printf("ERROR - Directed Overload test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Prioritized Directed test...\n");
+	ret = test_priority_directed(t);
+	if (ret != 0) {
+		printf("ERROR - Prioritized Directed test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Prioritized Atomic test...\n");
+	ret = test_priority_atomic(t);
+	if (ret != 0) {
+		printf("ERROR - Prioritized Atomic test FAILED.\n");
+		return ret;
+	}
+
+	printf("*** Running Prioritized Ordered test...\n");
+	ret = test_priority_ordered(t);
+	if (ret != 0) {
+		printf("ERROR - Prioritized Ordered test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Prioritized Unordered test...\n");
+	ret = test_priority_unordered(t);
+	if (ret != 0) {
+		printf("ERROR - Prioritized Unordered test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Burst Packets test...\n");
+	ret = burst_packets(t);
+	if (ret != 0) {
+		printf("ERROR - Burst Packets test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Load Balancing test...\n");
+	ret = load_balancing(t);
+	if (ret != 0) {
+		printf("ERROR - Load Balancing test FAILED.\n");
+		return ret;
+	}
+	printf("*** Running Invalid QID test...\n");
+	ret = invalid_qid(t);
+	if (ret != 0) {
+		printf("ERROR - Invalid QID test FAILED.\n");
+		return ret;
+	}
+	if (rte_lcore_count() >= 3) {
+		printf("*** Running Worker loopback test...\n");
+		ret = worker_loopback(t);
+		if (ret != 0) {
+			printf("ERROR - Worker loopback test FAILED.\n");
+			return ret;
+		}
+	} else {
+		printf("### Not enough cores for worker loopback test. \n");
+		printf("### Need at least 3 cores for test.\n");
+	}
+	/* Free test instance, leaving mempool initialized, and a pointer to it
+	 * in the static eventdev_func_mempool variable. It is re-used on re-runs */
+	free(t);
+
+	return 0;
+}
+
+REGISTER_TEST_COMMAND(eventdev_func_autotest, test_eventdev);
diff --git a/app/test/test_eventdev_unit.c b/app/test/test_eventdev_unit.c
new file mode 100644
index 0000000..c145401
--- /dev/null
+++ b/app/test/test_eventdev_unit.c
@@ -0,0 +1,557 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include "test.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+
+#include <rte_eventdev.h>
+#include <rte_lcore.h>
+#include <rte_mbuf.h>
+
+typedef enum eventdev_api_ut_ids_s {
+	EVENTDEV_API_UT_001 = 1,
+	EVENTDEV_API_UT_002,
+	EVENTDEV_API_UT_003,
+	EVENTDEV_API_UT_004,
+	EVENTDEV_API_UT_005,
+	EVENTDEV_API_UT_006,
+	EVENTDEV_API_UT_007,
+	EVENTDEV_API_UT_008,
+	EVENTDEV_API_UT_009,
+	EVENTDEV_API_UT_010,
+	EVENTDEV_API_UT_011,
+	EVENTDEV_API_UT_012,
+	EVENTDEV_API_UT_013,
+	EVENTDEV_API_UT_014,
+	EVENTDEV_API_UT_015,
+	EVENTDEV_API_UT_016,
+	EVENTDEV_API_UT_017,
+	EVENTDEV_API_UT_MAX
+} eventdev_api_ut_ids_t;
+
+typedef enum eventdev_tc_status_s {
+	TC_FAILED,
+	TC_PASSED
+} eventdev_tc_status_t;
+
+typedef struct eventdev_api_ut_status_s {
+	bool executed;
+	eventdev_tc_status_t status;
+} eventdev_api_ut_status_t;
+
+eventdev_api_ut_status_t api_ut_status[EVENTDEV_API_UT_MAX];
+
+#define CONFIG_NB_EVENT_QUEUES 2
+#define CONFIG_NB_EVENT_PORTS 2
+#define CONFIG_NB_EVENT_LIMIT 128
+
+uint8_t queues[CONFIG_NB_EVENT_QUEUES];
+uint8_t ports[CONFIG_NB_EVENT_PORTS];
+
+/* FIXME: Check that dependent tests have executed */
+
+static int test_EVENTDEV_API_UT_001_rte_event_dev_count(void)
+{
+	uint8_t count = rte_event_dev_count();
+
+	if (count == 1) {
+		api_ut_status[EVENTDEV_API_UT_001].status = TC_PASSED;
+		return 0;
+	} else {
+		api_ut_status[EVENTDEV_API_UT_001].status = TC_FAILED;
+		return 1;
+	}
+}
+
+static int test_EVENTDEV_API_UT_002_rte_event_dev_get_dev_id(void)
+{
+	int8_t id;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	if (id < 0) {
+		api_ut_status[EVENTDEV_API_UT_002].status = TC_FAILED;
+		return 1;
+	}
+
+	id = rte_event_dev_get_dev_id("evdev_abcd123");
+
+	if (id >= 0) {
+		api_ut_status[EVENTDEV_API_UT_002].status = TC_FAILED;
+		return 1;
+	}
+
+	api_ut_status[EVENTDEV_API_UT_002].status = TC_PASSED;
+	return 0;
+}
+
+static int test_EVENTDEV_API_UT_003_rte_event_dev_info_get(void)
+{
+	struct rte_event_dev_info info;
+	int8_t id;
+	int ret;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	ret = rte_event_dev_info_get(id, &info);
+	if (ret)
+		goto fail;
+
+	if (strncmp(info.driver_name, "evdev_sw", sizeof("evdev_sw")) != 0)
+		goto fail;
+
+	/* FIXME: Add checks for remaining fields */
+
+	api_ut_status[EVENTDEV_API_UT_003].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_003].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_004_rte_event_dev_configure(void)
+{
+	struct rte_event_dev_config config;
+	int8_t id;
+	int ret;
+
+	api_ut_status[EVENTDEV_API_UT_004].executed = true;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	config.nb_event_queues = CONFIG_NB_EVENT_QUEUES; /* FIXME: Test max */
+	config.nb_event_ports = CONFIG_NB_EVENT_PORTS; /* FIXME: Test max */
+	config.nb_events_limit = CONFIG_NB_EVENT_LIMIT; /* FIXME: Test max */
+	config.dequeue_wait_ns = 0; /* FIXME: Test max */
+
+	ret = rte_event_dev_configure(id, &config);
+	if (ret)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_004].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_004].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_005_rte_event_queue_count_pre(void)
+{
+	int8_t id;
+	uint8_t count;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	count = rte_event_queue_count(id);
+	if (count != CONFIG_NB_EVENT_QUEUES)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_005].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_005].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_006_rte_event_queue_setup(void)
+{
+	struct rte_event_queue_conf config;
+	int8_t id;
+	int ret;
+
+	api_ut_status[EVENTDEV_API_UT_006].executed = true;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	config.event_queue_cfg = 0;
+	config.priority = 0;
+
+	queues[0] = 0;
+
+	ret = rte_event_queue_setup(id, queues[0], &config);
+	if (ret < 0)
+		goto fail;
+
+	config.event_queue_cfg = RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER;
+	config.priority = 0;
+
+	queues[1] = 1;
+
+	ret = rte_event_queue_setup(id, queues[1], &config);
+	if (ret < 0)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_006].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_006].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_007_rte_event_queue_count_post(void)
+{
+	int8_t id;
+	uint8_t count;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	if (!api_ut_status[EVENTDEV_API_UT_006].executed)
+		test_EVENTDEV_API_UT_006_rte_event_queue_setup();
+	if (api_ut_status[EVENTDEV_API_UT_006].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	count = rte_event_queue_count(id);
+	if (count != CONFIG_NB_EVENT_QUEUES)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_007].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_007].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_008_rte_event_port_count_pre(void)
+{
+	int8_t id;
+	uint8_t count;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	count = rte_event_port_count(id);
+	if (count != CONFIG_NB_EVENT_PORTS)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_008].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_008].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_009_rte_event_port_setup(void)
+{
+	struct rte_event_port_conf config;
+	int8_t id;
+	int ret;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_009].executed = true;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	config.dequeue_queue_depth = 4;
+	config.enqueue_queue_depth = 4;
+	config.new_event_threshold = 64;
+
+	ports[0] = 0;
+
+	ret = rte_event_port_setup(id, ports[0], &config);
+	if (ret < 0)
+		goto fail;
+
+	config.dequeue_queue_depth = 4;
+	config.enqueue_queue_depth = 4;
+	config.new_event_threshold = 64;
+
+	ports[1] = 1;
+
+	ret = rte_event_port_setup(id, ports[1], &config);
+	if (ret < 0)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_009].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_009].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_010_rte_event_port_count_post(void)
+{
+	int8_t id;
+	uint8_t count;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	if (!api_ut_status[EVENTDEV_API_UT_009].executed)
+		test_EVENTDEV_API_UT_009_rte_event_port_setup();
+	if (api_ut_status[EVENTDEV_API_UT_009].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	count = rte_event_port_count(id);
+	if (count != CONFIG_NB_EVENT_PORTS)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_010].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_010].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_011_rte_event_dev_start(void)
+{
+	int8_t id;
+	int ret;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	ret = rte_event_dev_start(id);
+	if (ret != 0)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_011].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_011].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_012_rte_event_port_link(void)
+{
+	struct rte_event_queue_link link;
+	int8_t id;
+	int ret;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	if (!api_ut_status[EVENTDEV_API_UT_006].executed)
+		test_EVENTDEV_API_UT_006_rte_event_queue_setup();
+	if (api_ut_status[EVENTDEV_API_UT_006].status == TC_FAILED)
+		goto fail;
+
+	if (!api_ut_status[EVENTDEV_API_UT_009].executed)
+		test_EVENTDEV_API_UT_009_rte_event_port_setup();
+	if (api_ut_status[EVENTDEV_API_UT_009].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	link.queue_id = queues[0];
+	link.priority = 0;
+
+	/* Connect port to previously configured scheduled queue */
+	ret = rte_event_port_link(id, ports[0], &link, 1);
+	if (ret != 1) {
+		printf("%d: failed here\n", __LINE__);
+		goto fail;
+	}
+
+	/* Check idempotency of re-linking port to queues[0] */
+	ret = rte_event_port_link(id, ports[0], &link, 1);
+	if (ret != 1) {
+		printf("%d: failed here\n", __LINE__);
+		goto fail;
+	}
+
+	link.queue_id = queues[1];
+	link.priority = 0;
+
+	/* Attempt to connect to FIFO queue as well */
+	ret = rte_event_port_link(id, ports[0], &link, 1);
+	if (ret == 1) {
+		printf("%d: failed here\n", __LINE__);
+		goto fail;
+	}
+
+	link.queue_id = queues[1];
+	link.priority = 0;
+
+	/* Connect port to previously configured FIFO queue */
+	ret = rte_event_port_link(id, ports[1], &link, 1);
+	if (ret != 1) {
+		printf("%d: failed here\n", __LINE__);
+		goto fail;
+	}
+
+	link.queue_id = queues[0];
+	link.priority = 0;
+
+	/* Attempt to connect to scheduled queue as well */
+	ret = rte_event_port_link(id, ports[1], &link, 1);
+	if (ret == 1) {
+		printf("%d: failed here\n", __LINE__);
+		goto fail;
+	}
+
+	/* link to 2nd queue, enabling start() to pass later */
+	link.queue_id = queues[1];
+	link.priority = 0;
+	ret = rte_event_port_link(id, ports[1], &link, 1);
+	if (ret == 1) {
+		printf("%d: failed here\n", __LINE__);
+		goto fail;
+	}
+
+	api_ut_status[EVENTDEV_API_UT_012].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_012].status = TC_FAILED;
+	return 1;
+}
+
+static int test_EVENTDEV_API_UT_014_rte_event_dev_stop(void)
+{
+	int8_t id;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		return 1;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	rte_event_dev_stop(id);
+
+	api_ut_status[EVENTDEV_API_UT_014].status = TC_PASSED;
+	return 0;
+}
+
+static int test_EVENTDEV_API_UT_015_rte_event_dev_close(void)
+{
+	int8_t id;
+	int ret;
+
+	if (!api_ut_status[EVENTDEV_API_UT_004].executed)
+		test_EVENTDEV_API_UT_004_rte_event_dev_configure();
+	if (api_ut_status[EVENTDEV_API_UT_004].status == TC_FAILED)
+		goto fail;
+
+	id = rte_event_dev_get_dev_id("evdev_sw0");
+
+	ret = rte_event_dev_close(id);
+	if (ret != 0)
+		goto fail;
+
+	api_ut_status[EVENTDEV_API_UT_015].status = TC_PASSED;
+	return 0;
+
+fail:
+	api_ut_status[EVENTDEV_API_UT_015].status = TC_FAILED;
+	return 1;
+}
+
+static int
+test_setup(void)
+{
+	return 0;
+}
+
+static struct unit_test_suite eventdev_test_suite  = {
+	.setup = test_setup,
+	.suite_name = "Eventdev Test Suite",
+	.unit_test_cases = {
+		/* device aquisition and config */
+		TEST_CASE(test_EVENTDEV_API_UT_001_rte_event_dev_count),
+		TEST_CASE(test_EVENTDEV_API_UT_002_rte_event_dev_get_dev_id),
+		TEST_CASE(test_EVENTDEV_API_UT_003_rte_event_dev_info_get),
+		TEST_CASE(test_EVENTDEV_API_UT_004_rte_event_dev_configure),
+		/* queue config */
+		TEST_CASE(test_EVENTDEV_API_UT_005_rte_event_queue_count_pre),
+		TEST_CASE(test_EVENTDEV_API_UT_006_rte_event_queue_setup),
+		TEST_CASE(test_EVENTDEV_API_UT_007_rte_event_queue_count_post),
+		/* port config */
+		TEST_CASE(test_EVENTDEV_API_UT_008_rte_event_port_count_pre),
+		TEST_CASE(test_EVENTDEV_API_UT_009_rte_event_port_setup),
+		TEST_CASE(test_EVENTDEV_API_UT_010_rte_event_port_count_post),
+		TEST_CASE(test_EVENTDEV_API_UT_012_rte_event_port_link),
+		TEST_CASE(test_EVENTDEV_API_UT_011_rte_event_dev_start),
+		/* device cleanup */
+		TEST_CASE(test_EVENTDEV_API_UT_014_rte_event_dev_stop),
+		TEST_CASE(test_EVENTDEV_API_UT_015_rte_event_dev_close),
+		TEST_CASES_END()
+	}
+};
+
+static int
+test_eventdev_unit(void)
+{
+	return unit_test_suite_runner(&eventdev_test_suite);
+}
+
+REGISTER_TEST_COMMAND(eventdev_unit_autotest, test_eventdev_unit);
-- 
2.7.4

^ permalink raw reply related

* [PATCH 4/7] event/sw: makefiles and config
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, Gage Eads, Bruce Richardson
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

This commit modifies the existing Makefiles to have the sw_evdev instance
compiled.  At this point in the patchset, the infrastructure and sw_evdev
pmd is compiled, which means that it can be instantiated and used
successfully.

Signed-off-by: Gage Eads <gage.eads@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 config/common_base     | 6 ++++++
 drivers/event/Makefile | 2 ++
 mk/rte.app.mk          | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/config/common_base b/config/common_base
index a0a07f6..862178a 100644
--- a/config/common_base
+++ b/config/common_base
@@ -417,6 +417,12 @@ CONFIG_RTE_LIBRTE_EVENTDEV=y
 CONFIG_RTE_LIBRTE_EVENTDEV_DEBUG=n
 
 #
+# Compile a pure sw event device instance
+#
+CONFIG_RTE_LIBRTE_PMD_EVDEV_SW=y
+CONFIG_RTE_LIBRTE_PMD_EVDEV_SW_DEBUG=n
+
+#
 # Compile librte_ring
 #
 CONFIG_RTE_LIBRTE_RING=y
diff --git a/drivers/event/Makefile b/drivers/event/Makefile
index 93f90eb..b9c37d7 100644
--- a/drivers/event/Makefile
+++ b/drivers/event/Makefile
@@ -31,4 +31,6 @@
 
 include $(RTE_SDK)/mk/rte.vars.mk
 
+DIRS-$(CONFIG_RTE_LIBRTE_PMD_EVDEV_SW) += sw
+
 include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 716725a..2fce863 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -148,6 +148,10 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_ZUC)         += -lrte_pmd_zuc
 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_ZUC)         += -L$(LIBSSO_ZUC_PATH)/build -lsso_zuc
 endif # CONFIG_RTE_LIBRTE_CRYPTODEV
 
+ifeq ($(CONFIG_RTE_LIBRTE_EVENTDEV),y)
+_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_EVDEV_SW)    += -lrte_pmd_evdev_sw
+endif # CONFIG_RTE_LIBRTE_EVENTDEV
+
 endif # !CONFIG_RTE_BUILD_SHARED_LIBS
 
 _LDLIBS-y += --no-whole-archive
-- 
2.7.4

^ permalink raw reply related

* [PATCH 3/7] event/sw: software eventdev implementation
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, Gage Eads, Bruce Richardson
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

This commit adds a software implementation of the eventdev API. The
implementation here is intended to enable the community to use the eventdev
API, and test if the API serves the purpose that it is designed to. It
should be noted this is an RFC implementation, and hence there should be no
performance expectations. Note that the code added here is based on a
prototype implementation, and hence some cleanup is expected to be
necessary.

The main components of the implementation is three files:
  - sw_evdev.c              Creation, configuration, etc
  - sw_evdev_worker.c       Worker cores' enqueue (etc) functions
  - sw_evdev_scheduler.c    Core pkt scheduling implementation

This commit only adds the implementation, no existing DPDK files are modified.

Signed-off-by: Gage Eads <gage.eads@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 drivers/event/sw/Makefile                     |  59 +++
 drivers/event/sw/event_ring.h                 | 142 ++++++
 drivers/event/sw/iq_ring.h                    | 160 +++++++
 drivers/event/sw/rte_pmd_evdev_sw_version.map |   3 +
 drivers/event/sw/sw_evdev.c                   | 619 ++++++++++++++++++++++++
 drivers/event/sw/sw_evdev.h                   | 234 +++++++++
 drivers/event/sw/sw_evdev_scheduler.c         | 660 ++++++++++++++++++++++++++
 drivers/event/sw/sw_evdev_worker.c            | 218 +++++++++
 8 files changed, 2095 insertions(+)
 create mode 100644 drivers/event/sw/Makefile
 create mode 100644 drivers/event/sw/event_ring.h
 create mode 100644 drivers/event/sw/iq_ring.h
 create mode 100644 drivers/event/sw/rte_pmd_evdev_sw_version.map
 create mode 100644 drivers/event/sw/sw_evdev.c
 create mode 100644 drivers/event/sw/sw_evdev.h
 create mode 100644 drivers/event/sw/sw_evdev_scheduler.c
 create mode 100644 drivers/event/sw/sw_evdev_worker.c

diff --git a/drivers/event/sw/Makefile b/drivers/event/sw/Makefile
new file mode 100644
index 0000000..7fc4371
--- /dev/null
+++ b/drivers/event/sw/Makefile
@@ -0,0 +1,59 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2016 Intel Corporation. All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+
+# library name
+LIB = librte_pmd_evdev_sw.a
+
+# build flags
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+# library version
+LIBABIVER := 1
+
+# versioning export map
+EXPORT_MAP := rte_pmd_evdev_sw_version.map
+
+# library source files
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_EVDEV_SW) += sw_evdev.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_EVDEV_SW) += sw_evdev_worker.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_EVDEV_SW) += sw_evdev_scheduler.c
+
+# export include files
+SYMLINK-y-include +=
+
+# library dependencies
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_EVDEV_SW) += lib/librte_eal
+DEPDIRS-$(CONFIG_RTE_LIBRTE_PMD_EVDEV_SW) += lib/librte_eventdev
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/event/sw/event_ring.h b/drivers/event/sw/event_ring.h
new file mode 100644
index 0000000..531fb68
--- /dev/null
+++ b/drivers/event/sw/event_ring.h
@@ -0,0 +1,142 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _EVENT_RING_
+#define _EVENT_RING_
+
+#include <stdint.h>
+#include <x86intrin.h>
+
+#include <rte_common.h>
+#include <rte_memory.h>
+#include <rte_malloc.h>
+
+#define QE_RING_NAMESIZE 32
+
+struct qe_ring {
+	char name[QE_RING_NAMESIZE] __rte_cache_aligned;
+	uint32_t ring_size; /* size of memory block allocated to the ring */
+	uint32_t mask;      /* mask for read/write values == ring_size -1 */
+	uint32_t size;      /* actual usable space in the ring */
+	volatile uint32_t write_idx __rte_cache_aligned;
+	volatile uint32_t read_idx __rte_cache_aligned;
+
+	struct rte_event ring[0] __rte_cache_aligned;
+};
+
+#ifndef force_inline
+#define force_inline inline __attribute__((always_inline))
+#endif
+
+static inline struct qe_ring * __attribute__((cold))
+qe_ring_create(const char *name, unsigned int size, unsigned socket_id)
+{
+	struct qe_ring *retval;
+	const uint32_t ring_size = rte_align32pow2(size + 1);
+	size_t memsize = sizeof(*retval) +
+			(ring_size * sizeof(retval->ring[0]));
+
+	retval = rte_zmalloc_socket(NULL, memsize, 0, socket_id);
+	if (retval == NULL)
+		goto end;
+
+	snprintf(retval->name, sizeof(retval->name), "EVDEV_RG_%s", name);
+	retval->ring_size = ring_size;
+	retval->mask = ring_size - 1;
+	retval->size = size;
+end:
+	return retval;
+}
+
+static inline void
+qe_ring_destroy(struct qe_ring *r)
+{
+	rte_free(r);
+}
+
+static force_inline unsigned int
+qe_ring_count(const struct qe_ring *r)
+{
+	return r->write_idx - r->read_idx;
+}
+
+static force_inline unsigned int
+qe_ring_free_count(const struct qe_ring *r)
+{
+	return r->size - qe_ring_count(r);
+}
+
+static force_inline unsigned int
+qe_ring_enqueue_burst(struct qe_ring *r, struct rte_event *qes,
+		unsigned int nb_qes, uint16_t *free_count)
+{
+	const uint32_t size = r->size;
+	const uint32_t mask = r->mask;
+	const uint32_t read = r->read_idx;
+	uint32_t write = r->write_idx;
+	const uint32_t space = read + size - write;
+	uint32_t i;
+
+	if (space < nb_qes)
+		nb_qes = space;
+
+	for (i = 0; i < nb_qes; i++, write++)
+		r->ring[write & mask] = qes[i];
+
+	r->write_idx = write;
+
+	*free_count = space - nb_qes;
+
+	return nb_qes;
+}
+
+static force_inline unsigned int
+qe_ring_dequeue_burst(struct qe_ring *r, struct rte_event *qes,
+		unsigned int nb_qes)
+{
+	const uint32_t mask = r->mask;
+	uint32_t read = r->read_idx;
+	const uint32_t write = r->write_idx;
+	const uint32_t items = write - read;
+	uint32_t i;
+
+	if (items < nb_qes)
+		nb_qes = items;
+
+	for (i = 0; i < nb_qes; i++, read++)
+		qes[i] = r->ring[read & mask];
+
+	r->read_idx += nb_qes;
+
+	return nb_qes;
+}
+
+#endif
diff --git a/drivers/event/sw/iq_ring.h b/drivers/event/sw/iq_ring.h
new file mode 100644
index 0000000..a870e59
--- /dev/null
+++ b/drivers/event/sw/iq_ring.h
@@ -0,0 +1,160 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _IQ_RING_
+#define _IQ_RING_
+
+#include <stdint.h>
+#include <x86intrin.h>
+
+#include <rte_common.h>
+#include <rte_memory.h>
+#include <rte_malloc.h>
+#include <rte_eventdev.h>
+
+#define IQ_RING_NAMESIZE 12
+#define QID_IQ_DEPTH 128
+#define QID_IQ_MASK (uint16_t)(QID_IQ_DEPTH - 1)
+
+struct iq_ring {
+	char name[IQ_RING_NAMESIZE] __rte_cache_aligned;
+	uint16_t write_idx;
+	uint16_t read_idx;
+
+	struct rte_event ring[QID_IQ_DEPTH];
+};
+
+#ifndef force_inline
+#define force_inline inline __attribute__((always_inline))
+#endif
+
+static inline struct iq_ring * __attribute__((cold))
+iq_ring_create(const char *name, unsigned socket_id)
+{
+	struct iq_ring *retval;
+
+	retval = rte_malloc_socket(NULL, sizeof(*retval), 0, socket_id);
+	if (retval == NULL)
+		goto end;
+
+	snprintf(retval->name, sizeof(retval->name), "%s", name);
+	retval->write_idx = retval->read_idx = 0;
+end:
+	return retval;
+}
+
+static inline void
+iq_ring_destroy(struct iq_ring *r)
+{
+	rte_free(r);
+}
+
+static force_inline uint16_t
+iq_ring_count(const struct iq_ring *r)
+{
+	return r->write_idx - r->read_idx;
+}
+
+static force_inline uint16_t
+iq_ring_free_count(const struct iq_ring *r)
+{
+	return QID_IQ_MASK - iq_ring_count(r);
+}
+
+static force_inline uint16_t
+iq_ring_enqueue_burst(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
+{
+	const uint16_t read = r->read_idx;
+	uint16_t write = r->write_idx;
+	const uint16_t space = read + QID_IQ_MASK - write;
+	uint16_t i;
+
+	if (space < nb_qes)
+		nb_qes = space;
+
+	for (i = 0; i < nb_qes; i++, write++)
+		r->ring[write & QID_IQ_MASK] = qes[i];
+
+	r->write_idx = write;
+
+	return nb_qes;
+}
+
+static force_inline uint16_t
+iq_ring_dequeue_burst(struct iq_ring *r, struct rte_event *qes, uint16_t nb_qes)
+{
+	uint16_t read = r->read_idx;
+	const uint16_t write = r->write_idx;
+	const uint16_t items = write - read;
+	uint16_t i;
+
+	for (i = 0; i < nb_qes; i++, read++)
+		qes[i] = r->ring[read & QID_IQ_MASK];
+
+	if (items < nb_qes)
+		nb_qes = items;
+
+	r->read_idx += nb_qes;
+
+	return nb_qes;
+}
+
+static force_inline const struct rte_event *
+iq_ring_peek(const struct iq_ring *r)
+{
+	return &r->ring[r->read_idx & QID_IQ_MASK];
+}
+
+static force_inline void
+iq_ring_pop(struct iq_ring *r)
+{
+	r->read_idx++;
+}
+
+static force_inline int
+iq_ring_enqueue(struct iq_ring *r, const struct rte_event *qe)
+{
+	const uint16_t read = r->read_idx;
+	const uint16_t write = r->write_idx;
+	const uint16_t space = read + QID_IQ_MASK - write;
+
+	if (space == 0)
+		return -1;
+
+	r->ring[write & QID_IQ_MASK] = *qe;
+
+	r->write_idx = write + 1;
+
+	return 0;
+}
+
+#endif
diff --git a/drivers/event/sw/rte_pmd_evdev_sw_version.map b/drivers/event/sw/rte_pmd_evdev_sw_version.map
new file mode 100644
index 0000000..1f84b68
--- /dev/null
+++ b/drivers/event/sw/rte_pmd_evdev_sw_version.map
@@ -0,0 +1,3 @@
+DPDK_17.02 {
+	local: *;
+};
diff --git a/drivers/event/sw/sw_evdev.c b/drivers/event/sw/sw_evdev.c
new file mode 100644
index 0000000..4868122
--- /dev/null
+++ b/drivers/event/sw/sw_evdev.c
@@ -0,0 +1,619 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#include <rte_vdev.h>
+#include <rte_memzone.h>
+#include <rte_kvargs.h>
+#include <rte_ring.h>
+#include <rte_eventdev_pmd.h>
+
+#include "sw_evdev.h"
+#include "iq_ring.h"
+
+#define NUMA_NODE_ARG "numa_node"
+
+static int
+sw_dev_stats_get(const struct rte_event_dev *dev,
+		struct rte_event_dev_stats *stats)
+{
+	const struct sw_evdev *sw = (const void *)dev;
+	unsigned int i;
+
+	if (dev == NULL || stats == NULL)
+		return -EINVAL;
+
+	memset(stats, 0, sizeof(*stats));
+
+	stats->rx_pkts = sw->stats.rx_pkts;
+	stats->rx_dropped = sw->stats.rx_dropped;
+	stats->tx_pkts = sw->stats.tx_pkts;
+
+	for (i = 0; i < sw->port_count; i++) {
+		stats->port_rx_pkts[i] = sw->ports[i].stats.rx_pkts;
+		stats->port_rx_dropped[i] = sw->ports[i].stats.rx_dropped;
+		stats->port_inflight[i] = sw->ports[i].inflights;
+		stats->port_tx_pkts[i] = sw->ports[i].stats.tx_pkts;
+	}
+
+	for (i = 0; i < sw->qid_count; i++) {
+		stats->queue_rx_pkts[i] = sw->qids[i].stats.rx_pkts;
+		stats->queue_rx_dropped[i] = sw->qids[i].stats.rx_dropped;
+		stats->queue_tx_pkts[i] = sw->qids[i].stats.tx_pkts;
+	}
+	return 0;
+}
+
+static int
+sw_port_link(struct rte_event_dev *dev, uint8_t port_id,
+		struct rte_event_queue_link link[], int num)
+{
+	struct sw_evdev *sw = (void *)dev;
+	struct sw_port *p = &sw->ports[port_id];
+	int i;
+
+	if (link == NULL) {
+		/* TODO: map all queues */
+		rte_errno = -EDQUOT;
+		return 0;
+	}
+	if (port_id > sw->port_count) {
+		rte_errno = -EINVAL;
+		return 0;
+	}
+
+	for (i = 0; i < num; i++) {
+		struct sw_qid *q;
+		uint32_t qid = link[i].queue_id;
+		if (qid >= sw->qid_count) {
+			break; /* error - invalid QIDs */
+		}
+		q = &sw->qids[qid];
+
+		/* check for qid map overflow */
+		if (q->cq_num_mapped_cqs >= RTE_DIM(q->cq_map))
+			break;
+
+		if (p->is_directed && p->num_qids_mapped > 0)
+			break;
+
+		if (q->type == RTE_SCHED_TYPE_DIRECT) {
+			/* check directed qids only map to one port */
+			if (p->num_qids_mapped > 0)
+				break;
+			/* check port only takes a directed flow */
+			if (num > 1)
+				break;
+
+			p->is_directed = 1;
+			p->num_qids_mapped = 1;
+		} else if (q->type == RTE_SCHED_TYPE_ORDERED) {
+			p->num_ordered_qids++;
+			p->num_qids_mapped++;
+		} else if (q->type == RTE_SCHED_TYPE_ATOMIC) {
+			p->num_qids_mapped++;
+		}
+
+		q->cq_map[q->cq_num_mapped_cqs++] = port_id;
+	}
+	return i;
+}
+
+static void
+sw_dump(FILE *f, const struct rte_event_dev *dev)
+{
+	static const char *q_type_strings[] = {"Ordered" , "Atomic",
+			"Parallel", "Directed"
+	};
+	uint32_t i;
+	const struct sw_evdev *sw = (const void *)dev;
+	fprintf(f, "EventDev %s: ports %d, qids %d\n", sw->dev.name,
+			sw->port_count, sw->qid_count);
+
+	fprintf(f, "\trx   %"PRIu64"\n\tdrop %"PRIu64"\n\ttx   %"PRIu64"\n",
+		sw->stats.rx_pkts, sw->stats.rx_dropped, sw->stats.tx_pkts);
+	fprintf(f, "\tsched calls: %"PRIu64"\n", sw->sched_called);
+	fprintf(f, "\tsched cq/qid call: %"PRIu64"\n", sw->sched_cq_qid_called);
+	fprintf(f, "\tsched no IQ enq: %"PRIu64"\n", sw->sched_no_iq_enqueues);
+	fprintf(f, "\tsched no CQ enq: %"PRIu64"\n", sw->sched_no_cq_enqueues);
+	fprintf(f, "\toverloads %"PRIu64"\t%s\n", sw->sched_overload_counter,
+			sw->overloaded ? " [OVERLOADED NOW]" : "");
+
+#define COL_RED "\x1b[31m"
+#define COL_RESET "\x1b[0m"
+
+	for (i = 0; i < sw->port_count; i++) {
+		const struct sw_port *p = &sw->ports[i];
+		fprintf(f, "  Port %d %s %s\n", i,
+				p->is_directed ? " (SingleCons)" : "",
+				p->overloaded ? " ["COL_RED"OVERLOAD"COL_RESET"]" : "");
+		fprintf(f, "\trx   %"PRIu64"\n\tdrop %"PRIu64"\n\ttx   %"PRIu64"\n"
+			"\tinf %d\n", sw->ports[i].stats.rx_pkts,
+			sw->ports[i].stats.rx_dropped,
+			sw->ports[i].stats.tx_pkts, sw->ports[i].inflights);
+
+		uint64_t rx_used = qe_ring_count(p->rx_worker_ring);
+		uint64_t rx_free = qe_ring_free_count(p->rx_worker_ring);
+		const char *rxcol = (rx_free == 0) ? COL_RED : COL_RESET;
+		fprintf(f, "\t%srx ring used: %ld\tfree: %ld"COL_RESET"\n",
+				rxcol, rx_used, rx_free);
+
+		uint64_t tx_used = qe_ring_count(p->cq_worker_ring);
+		uint64_t tx_free = qe_ring_free_count(p->cq_worker_ring);
+		const char *txcol = (tx_free == 0) ? COL_RED : COL_RESET;
+		fprintf(f, "\t%scq ring used: %ld\tfree: %ld"COL_RESET"\n",
+				txcol, tx_used, tx_free);
+	}
+
+	for (i = 0; i < sw->qid_count; i++) {
+		fprintf(f, "  Queue %d (%s)\n", i, q_type_strings[sw->qids[i].type]);
+		fprintf(f, "\trx   %"PRIu64"\n\tdrop %"PRIu64"\n\ttx   %"PRIu64"\n",
+			sw->qids[i].stats.rx_pkts, sw->qids[i].stats.rx_dropped,
+			sw->qids[i].stats.tx_pkts);
+		uint32_t iq;
+		for(iq = 0; iq < SW_IQS_MAX; iq++) {
+			uint32_t used = iq_ring_count(sw->qids[i].iq[iq]);
+			uint32_t free = iq_ring_free_count(sw->qids[i].iq[iq]);
+			const char *col = (free == 0) ? COL_RED : COL_RESET;
+			fprintf(f, "\t%siq %d: Used %d\tFree %d"COL_RESET"\n",
+					col, iq, used, free);
+		}
+	}
+}
+
+static int
+sw_port_setup(struct rte_event_dev *dev, uint8_t port_id,
+		const struct rte_event_port_conf *conf)
+{
+	struct sw_evdev *sw = (void *)dev;
+	struct sw_port *p = &sw->ports[port_id];
+	char buf[QE_RING_NAMESIZE];
+	unsigned i;
+
+	if (conf->enqueue_queue_depth >
+				dev->info.max_event_port_enqueue_queue_depth ||
+			conf->dequeue_queue_depth >
+				dev->info.max_event_port_dequeue_queue_depth){
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	*p = (struct sw_port){0}; /* zero entire structure */
+	p->id = port_id;
+
+	/* TODO: how do we work with an overload scheme here?
+	 * For now, still use a huge buffer, with per-port thresholds.
+	 * When it fills beyond the configured max size, we throttle.
+	 */
+	snprintf(buf, sizeof(buf), "%s_%s", dev->name, "rx_worker_ring");
+	p->rx_worker_ring = qe_ring_create(buf, MAX_SW_PROD_Q_DEPTH,
+			dev->socket_id);
+	if (p->rx_worker_ring == NULL)
+		return -1;
+
+	/* threshold is number of free spaces that are left in ring
+	 * before overload should kick in. QE ring returns free_count,
+	 * so storing this way makes more sense than actual depth
+	 */
+	uint32_t requested = MAX_SW_PROD_Q_DEPTH - conf->new_event_threshold;
+	p->overload_threshold = requested > 255 ? 255 : requested;
+
+	snprintf(buf, sizeof(buf), "%s_%s", dev->name, "cq_worker_ring");
+	p->cq_worker_ring = qe_ring_create(buf, conf->dequeue_queue_depth,
+			dev->socket_id);
+	if (p->cq_worker_ring == NULL) {
+		qe_ring_destroy(p->rx_worker_ring);
+		return -1;
+	}
+	sw->cq_ring_space[port_id] = conf->dequeue_queue_depth;
+
+	/* set hist list contents to empty */
+	for (i = 0; i < SW_PORT_HIST_LIST; i++) {
+		p->hist_list[i].fid = -1;
+		p->hist_list[i].qid = -1;
+	}
+
+	return 0;
+}
+
+static int
+sw_port_cleanup(struct sw_evdev *sw, uint8_t port_id)
+{
+	struct sw_port *p = &sw->ports[port_id];
+
+	qe_ring_destroy(p->rx_worker_ring);
+	qe_ring_destroy(p->cq_worker_ring);
+	memset(p, 0, sizeof(*p));
+
+	return 0;
+}
+
+static uint8_t
+sw_port_count(struct rte_event_dev *dev)
+{
+	struct sw_evdev *sw = (void *)dev;
+	return sw->port_count;
+}
+
+
+static uint16_t
+sw_queue_count(struct rte_event_dev *dev)
+{
+	struct sw_evdev *sw = (void *)dev;
+	return sw->qid_count;
+}
+
+static int32_t
+qid_cleanup(struct sw_evdev *sw, uint32_t idx)
+{
+	struct sw_qid *qid = &sw->qids[idx];
+	uint32_t i;
+
+	for (i = 0; i < SW_IQS_MAX; i++) {
+		iq_ring_destroy(qid->iq[i]);
+	}
+
+	if (qid->type == RTE_SCHED_TYPE_ORDERED) {
+		rte_free(qid->reorder_buffer);
+		rte_ring_free(qid->reorder_buffer_freelist);
+	}
+	memset(qid, 0, sizeof(*qid));
+
+	return 0;
+}
+
+static int32_t
+qid_init(struct sw_evdev *sw, unsigned idx, int type,
+		const struct rte_event_queue_conf *queue_conf)
+{
+	int i;
+	int socket_id = sw->dev.socket_id;
+	char buf[IQ_RING_NAMESIZE];
+	struct sw_qid *qid = &sw->qids[idx];
+
+	for (i = 0; i < SW_IQS_MAX; i++) {
+		snprintf(buf, sizeof(buf), "q_%u_iq_%d", idx, i);
+		qid->iq[i] = iq_ring_create(buf, socket_id);
+		if (!qid->iq[i]) {
+			SW_LOG_DBG("ring create failed");
+			goto cleanup;
+		}
+	}
+
+	/* Initialize the iq packet mask to 1, as __builtin_clz() is undefined
+	 * if the value passed in is zero.
+	 */
+	qid->iq_pkt_mask = 1;
+
+	/* Initialize the FID structures to no pinning (-1), and zero packets */
+	struct sw_fid_t fid = {.cq = -1, .count = 0};
+	for (i = 0; i < SW_QID_NUM_FIDS; i++)
+		qid->fids[i] = fid;
+
+	qid->id = idx;
+	qid->type = type;
+	qid->priority = queue_conf->priority;
+
+	if (qid->type == RTE_SCHED_TYPE_ORDERED) {
+		uint32_t window_size;
+
+		/* rte_ring and window_size_mask require require window_size to
+		 * be a power-of-2.
+		 */
+		window_size = rte_align32pow2(
+				queue_conf->nb_atomic_order_sequences);
+
+		qid->window_size = window_size - 1;
+
+		if (!window_size) {
+			SW_LOG_DBG("invalid reorder_window_size for ordered queue\n");
+			goto cleanup;
+		}
+
+		snprintf(buf, sizeof(buf), "%s_iq_%d_rob", sw->dev.name, i);
+		qid->reorder_buffer = rte_zmalloc_socket(buf,
+				window_size * sizeof(qid->reorder_buffer[0]),
+				0, socket_id);
+		if (!qid->reorder_buffer) {
+			SW_LOG_DBG("reorder_buffer malloc failed\n");
+			goto cleanup;
+		}
+
+		memset(&qid->reorder_buffer[0],
+		       0,
+		       window_size * sizeof(qid->reorder_buffer[0]));
+
+		snprintf(buf, sizeof(buf), "%s_iq_%d_freelist", sw->dev.name, i);
+		qid->reorder_buffer_freelist = rte_ring_create(buf,
+				window_size,
+				socket_id,
+				RING_F_SP_ENQ | RING_F_SC_DEQ);
+		if (!qid->reorder_buffer_freelist) {
+			SW_LOG_DBG("freelist ring create failed");
+			goto cleanup;
+		}
+
+		/* Populate the freelist with reorder buffer entries. Enqueue
+		 * 'window_size - 1' entries because the rte_ring holds only
+		 * that many.
+		 */
+		for (i = 0; i < (int) window_size - 1; i++) {
+			if (rte_ring_sp_enqueue(qid->reorder_buffer_freelist,
+						&qid->reorder_buffer[i]) < 0)
+				goto cleanup;
+		}
+
+		qid->reorder_buffer_index = 0;
+		qid->cq_next_tx = 0;
+	}
+
+	return 0;
+
+cleanup:
+	for (i = 0; i < SW_IQS_MAX; i++) {
+		if (qid->iq[i])
+			iq_ring_destroy(qid->iq[i]);
+	}
+
+	if (qid->reorder_buffer) {
+		rte_free(qid->reorder_buffer);
+		qid->reorder_buffer = NULL;
+	}
+
+	if (qid->reorder_buffer_freelist) {
+		rte_ring_free(qid->reorder_buffer_freelist);
+		qid->reorder_buffer_freelist = NULL;
+	}
+
+	return -EINVAL;
+}
+
+static int
+sw_queue_setup(struct rte_event_dev *dev,
+		uint8_t queue_id,
+		const struct rte_event_queue_conf *conf)
+{
+	int type;
+	if (conf->nb_atomic_flows > 0 &&
+			conf ->nb_atomic_order_sequences > 0)
+		return -1;
+
+	if (conf->event_queue_cfg & RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER)
+		type = RTE_SCHED_TYPE_DIRECT;
+	else if (conf->nb_atomic_flows > 0)
+		type = RTE_SCHED_TYPE_ATOMIC;
+	else if (conf->nb_atomic_order_sequences > 0)
+		type = RTE_SCHED_TYPE_ORDERED;
+	else
+		type = RTE_SCHED_TYPE_PARALLEL;
+
+	return qid_init((void *)dev, queue_id, type, conf);
+}
+
+static int
+sw_dev_configure(struct rte_event_dev *dev,
+			struct rte_event_dev_config *config)
+{
+	struct sw_evdev *se = (void *)dev;
+
+	if (config->nb_event_queues > dev->info.max_event_queues ||
+			config->nb_event_ports > dev->info.max_event_ports)
+		return -1;
+
+	se->qid_count = config->nb_event_queues;
+	se->port_count = config->nb_event_ports;
+	return 0;
+}
+
+static int
+assign_numa_node(const char *key __rte_unused, const char *value, void *opaque)
+{
+	int *socket_id = opaque;
+	*socket_id = atoi(value);
+	if (*socket_id > RTE_MAX_NUMA_NODES)
+		return -1;
+	return 0;
+}
+
+static inline void
+swap_ptr(void *a, void *b)
+{
+	void *tmp = a;
+	a = b;
+	b= tmp;
+}
+
+static int
+sw_start(struct rte_event_dev *dev)
+{
+	unsigned int i, j;
+	struct sw_evdev *sw = (void *)dev;
+	/* check all ports are set up */
+	for (i = 0; i < sw->port_count; i++)
+		if (sw->ports[i].rx_worker_ring == NULL)
+			return -1;
+
+	/* check all queues are configured and mapped to ports*/
+	for (i = 0; i < sw->qid_count; i++)
+		if (sw->qids[i].iq[0] == NULL ||
+				sw->qids[i].cq_num_mapped_cqs == 0)
+			return -1;
+
+	/* build up our prioritized array of qids */
+	/* We don't use qsort here, as if all/multiple entries have the same
+	 * priority, the result is non-deterministic. From "man 3 qsort":
+	 * "If two members compare as equal, their order in the sorted
+	 * array is undefined."
+	 */
+	for (i = 0; i < sw->qid_count; i++) {
+		sw->qids_prioritized[i] = &sw->qids[i];
+		for (j = i; j > 0; j--)
+			if (sw->qids_prioritized[j]->priority <
+					sw->qids_prioritized[j-1]->priority)
+				swap_ptr(sw->qids_prioritized[j],
+						sw->qids_prioritized[j-1]);
+	}
+	sw->started = 1;
+	return 0;
+}
+
+static void
+sw_stop(struct rte_event_dev *dev)
+{
+	struct sw_evdev *sw = (void *)dev;
+	sw->started = 0;
+}
+static int
+sw_close(struct rte_event_dev *dev)
+{
+	struct sw_evdev *sw = (void *)dev;
+	uint32_t i;
+
+	for(i = 0; i < sw->qid_count; i++) {
+		qid_cleanup(sw, i);
+	}
+	sw->qid_count = 0;
+
+	for (i = 0; i < sw->port_count; i++) {
+		sw_port_cleanup(sw, i);
+	}
+	sw->port_count = 0;
+
+	memset(&sw->stats, 0, sizeof(sw->stats));
+
+	return 0;
+}
+
+static int
+sw_probe(const char *name, const char *params)
+{
+	static const struct rte_event_dev_ops evdev_sw_ops = {
+			.configure = sw_dev_configure,
+			.queue_setup = sw_queue_setup,
+			.queue_count = sw_queue_count,
+			.port_setup = sw_port_setup,
+			.port_link = sw_port_link,
+			.port_count = sw_port_count,
+			.start = sw_start,
+			.stop = sw_stop,
+			.close = sw_close,
+			.stats_get = sw_dev_stats_get,
+			.dump = sw_dump,
+
+			.enqueue = sw_event_enqueue,
+			.enqueue_burst = sw_event_enqueue_burst,
+			.dequeue = sw_event_dequeue,
+			.dequeue_burst = sw_event_dequeue_burst,
+			.release = sw_event_release,
+			.schedule = sw_event_schedule,
+	};
+	static const char *args[] = { NUMA_NODE_ARG, NULL };
+	const struct rte_memzone *mz;
+	struct sw_evdev *se;
+	struct rte_event_dev_info evdev_sw_info = {
+			.driver_name = PMD_NAME,
+			.max_event_queues = SW_QIDS_MAX,
+			.max_event_queue_flows = SW_QID_NUM_FIDS,
+			.max_event_queue_priority_levels = SW_Q_PRIORITY_MAX,
+			.max_event_priority_levels = SW_IQS_MAX,
+			.max_event_ports = SW_PORTS_MAX,
+			.max_event_port_dequeue_queue_depth = MAX_SW_CONS_Q_DEPTH,
+			.max_event_port_enqueue_queue_depth = MAX_SW_PROD_Q_DEPTH,
+			/* for event limits, there is no hard limit, but it
+			 * depends on number of Queues configured and depth of
+			 * producer/consumer queues
+			 */
+			.max_num_events = -1,
+			.event_dev_cap = (RTE_EVENT_DEV_CAP_QUEUE_QOS |
+					RTE_EVENT_DEV_CAP_EVENT_QOS),
+	};
+	int socket_id = 0;
+
+	if (params != NULL && params[0] != '\0') {
+		struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
+
+		if (!kvlist) {
+			RTE_LOG(INFO, PMD,
+				"Ignoring unsupported parameters when creating device '%s'\n",
+				name);
+		} else {
+			int ret = rte_kvargs_process(kvlist, NUMA_NODE_ARG,
+					assign_numa_node, &socket_id);
+			rte_kvargs_free(kvlist);
+
+			if (ret != 0) {
+				RTE_LOG(ERR, PMD,
+					"%s: Error parsing numa node parameter",
+					name);
+				return ret;
+			}
+		}
+	}
+
+	RTE_LOG(INFO, PMD, "Creating eventdev sw device %s, on numa node %d\n",
+			name, socket_id);
+
+	mz = rte_memzone_reserve(name, sizeof(*se), socket_id, 0);
+	if (mz == NULL)
+		return -1; /* memzone_reserve sets rte_errno on error */
+
+	se = mz->addr;
+	se->mz = mz;
+	snprintf(se->dev.name, sizeof(se->dev.name), "%s", name);
+	se->dev.configured = false;
+	se->dev.info = evdev_sw_info;
+	se->dev.ops = &evdev_sw_ops;
+	se->dev.socket_id = socket_id;
+
+	return rte_event_dev_register(&se->dev);
+}
+
+static int
+sw_remove(const char *name)
+{
+	if (name == NULL)
+		return -EINVAL;
+
+	RTE_LOG(INFO, PMD, "Closing eventdev sw device %s\n", name);
+	/* TODO unregister eventdev and release memzone */
+
+	return 0;
+}
+
+static struct rte_vdev_driver evdev_sw_pmd_drv = {
+	.probe = sw_probe,
+	.remove = sw_remove
+};
+
+RTE_PMD_REGISTER_VDEV(evdev_sw, evdev_sw_pmd_drv);
+RTE_PMD_REGISTER_PARAM_STRING(evdev_sw,"numa_node=<int>");
diff --git a/drivers/event/sw/sw_evdev.h b/drivers/event/sw/sw_evdev.h
new file mode 100644
index 0000000..534e078
--- /dev/null
+++ b/drivers/event/sw/sw_evdev.h
@@ -0,0 +1,234 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SW_EVDEV_H_
+#define _SW_EVDEV_H_
+
+#include <rte_eventdev.h>
+#include <rte_eventdev_pmd.h>
+#include "event_ring.h"
+
+#define PMD_NAME "evdev_sw"
+
+#define SW_QIDS_MAX 128
+#define SW_QID_NUM_FIDS 16384
+#define SW_IQS_MAX 4
+#define SW_Q_PRIORITY_MAX 255
+#define SW_PORTS_MAX 128
+#define MAX_SW_CONS_Q_DEPTH 255
+
+/* allow for lots of over-provisioning */
+#define MAX_SW_PROD_Q_DEPTH 4096
+
+#define SW_FRAGMENTS_MAX 16
+#define PORT_DEQUEUE_BURST_SIZE 16
+#define SW_PORT_HIST_LIST (MAX_SW_PROD_Q_DEPTH + (MAX_SW_CONS_Q_DEPTH*2))
+
+#define SW_PORT_OVERLOAD_THRES (512)
+
+#define RTE_SCHED_TYPE_DIRECT (RTE_SCHED_TYPE_PARALLEL + 1)
+
+#ifdef RTE_LIBRTE_PMD_EVDEV_SW_DEBUG
+#define SW_LOG_INFO(fmt, args...) \
+	RTE_LOG(INFO, PMD, "[%s] %s() line %u: " fmt "\n", \
+			PMD_NAME, \
+			__func__, __LINE__, ## args)
+
+#define SW_LOG_DBG(fmt, args...) \
+	RTE_LOG(DEBUG, PMD, "[%s] %s() line %u: " fmt "\n", \
+			PMD_NAME, \
+			__func__, __LINE__, ## args)
+#else
+#define SW_LOG_INFO(fmt, args...)
+#define SW_LOG_DBG(fmt, args...)
+#endif
+
+enum {
+	QE_FLAG_VALID_SHIFT = 0,
+	QE_FLAG_COMPLETE_SHIFT,
+	QE_FLAG_NOT_EOP_SHIFT,
+	_QE_FLAG_COUNT
+};
+
+#define QE_FLAG_VALID    (1 << QE_FLAG_VALID_SHIFT)  /* set for NEW, FWD, FRAG */
+#define QE_FLAG_COMPLETE (1 << QE_FLAG_COMPLETE_SHIFT)  /* set for FWD, DROP */
+#define QE_FLAG_NOT_EOP  (1 << QE_FLAG_NOT_EOP_SHIFT)  /* set for FRAG only */
+
+static const uint8_t sw_qe_flag_map[] = {
+		QE_FLAG_VALID /* RTE_QEENT_OP_NEW */,
+		QE_FLAG_VALID | QE_FLAG_COMPLETE /* RTE_QEENT_OP_FWD */,
+		QE_FLAG_COMPLETE /* RTE_QEENT_OP_DROP */,
+		QE_FLAG_VALID | QE_FLAG_COMPLETE | QE_FLAG_NOT_EOP,
+};
+
+/* Records basic event stats at a given point. Used in port and qid structs */
+struct sw_point_stats {
+	uint64_t rx_pkts;
+	uint64_t rx_dropped;
+	uint64_t tx_pkts;
+};
+
+struct reorder_buffer_entry {
+	uint16_t num_fragments;		/**< Number of packet fragments */
+	uint16_t fragment_index;	/**< Points to the oldest valid frag */
+	uint8_t ready;			/**< Entry is ready to be reordered */
+	struct rte_event fragments[SW_FRAGMENTS_MAX];
+};
+
+struct sw_hist_list_entry {
+	int32_t qid;
+	int32_t fid;
+	struct reorder_buffer_entry *rob_entry;
+};
+
+struct sw_port {
+	/* A numeric ID for the port. This should be used to access the
+	 * statistics as returned by *rte_event_dev_stats_get*, and in other
+	 * places where the API requires accessing a port by integer. It is not
+	 * valid to assume that ports will be allocated in a linear sequence.
+	 */
+	uint8_t id;
+
+	/** Indicates if this port is overloaded, and we need to throttle input */
+	uint8_t overloaded;
+	uint8_t overload_threshold;
+
+	int16_t is_directed; /** Takes from a single directed QID */
+	int16_t num_ordered_qids; /** For loadbalanced we can optimise pulling
+			    packets from producers if there is no reordering
+			    involved */
+
+	/* track packets in and out of this port */
+	struct sw_point_stats stats;
+
+	/** Ring and buffer for pulling events from workers for scheduling */
+	struct qe_ring *rx_worker_ring __rte_cache_aligned;
+	uint32_t pp_buf_start;
+	uint32_t pp_buf_count;
+	struct rte_event pp_buf[PORT_DEQUEUE_BURST_SIZE];
+
+
+	/** Ring and buffer for pushing packets to workers after scheduling */
+	struct qe_ring *cq_worker_ring __rte_cache_aligned;
+	uint16_t cq_buf_count;
+	uint16_t outstanding_releases; /* num releases yet to be completed */
+	struct rte_event cq_buf[MAX_SW_CONS_Q_DEPTH];
+
+	/* History list structs, containing info on pkts egressed to worker */
+	uint16_t hist_head __rte_cache_aligned;
+	uint16_t hist_tail;
+	uint16_t inflights;
+	struct sw_hist_list_entry hist_list[SW_PORT_HIST_LIST];
+
+	uint8_t num_qids_mapped;
+};
+
+struct sw_fid_t {
+	/* which CQ this FID is currently pinned to */
+	uint32_t cq;
+	/* number of packets gone to the CQ with this FID */
+	uint32_t count;
+};
+
+struct sw_qid {
+	/* The type of this QID */
+	int type;
+	/* Integer ID representing the queue. This is used in history lists,
+	 * to identify the stage of processing. */
+	uint32_t id;
+	struct sw_point_stats stats;
+
+	/* Internal priority rings for packets */
+	struct iq_ring *iq[SW_IQS_MAX];
+	uint32_t iq_pkt_mask; 	/* A mask to indicate packets in an IQ */
+	uint64_t iq_pkt_count[SW_IQS_MAX];
+
+	/* Information on what CQs are polling this IQ */
+	uint32_t cq_num_mapped_cqs;
+	uint32_t cq_next_tx; /* cq to write next (non-atomic) packet */
+	uint32_t cq_map[SW_PORTS_MAX];
+
+	/* Track flow ids for atomic load balancing */
+	struct sw_fid_t fids[SW_QID_NUM_FIDS];
+
+	/* Track packet order for reordering when needed */
+	struct reorder_buffer_entry *reorder_buffer; /* packets awaiting reordering */
+	struct rte_ring *reorder_buffer_freelist; /* available reorder slots */
+	uint32_t reorder_buffer_index; /* oldest valid reorder buffer entry */
+	uint32_t window_size;          /* Used to wrap reorder_buffer_index */
+
+	uint8_t priority;
+};
+
+struct sw_evdev {
+	/* must be the first item in the private dev struct */
+	struct rte_event_dev dev;
+
+	const struct rte_memzone *mz;
+
+	/* Contains all ports - load balanced and directed */
+	struct sw_port ports[SW_PORTS_MAX];
+	uint32_t port_count;
+	uint16_t cq_ring_space[SW_PORTS_MAX]; /* How many packets are in the cq */
+
+	/* All qids - allocated in one slab for vectorization */
+	struct sw_qid qids[SW_QIDS_MAX];
+	uint32_t qid_count;
+
+	/* Array of pointers to load-balanced QIDs sorted by priority level */
+	struct sw_qid *qids_prioritized[SW_QIDS_MAX];
+
+	/* Stats */
+	struct sw_point_stats stats __rte_cache_aligned;
+	uint64_t sched_called;
+	uint64_t sched_no_iq_enqueues;
+	uint64_t sched_no_cq_enqueues;
+	uint64_t sched_cq_qid_called;
+	uint64_t sched_overload_counter;
+
+	uint8_t started;
+
+	uint32_t overloaded __rte_cache_aligned;
+};
+
+int  sw_event_enqueue(struct rte_event_dev *dev, uint8_t port_id,
+		     struct rte_event *ev, bool pin_event);
+int  sw_event_enqueue_burst(struct rte_event_dev *dev, uint8_t port_id,
+			   struct rte_event ev[], int num, bool pin_event);
+bool sw_event_dequeue(struct rte_event_dev *dev, uint8_t port_id,
+		      struct rte_event *ev, uint64_t wait);
+int  sw_event_dequeue_burst(struct rte_event_dev *dev, uint8_t port_id,
+			   struct rte_event *ev, int num, uint64_t wait);
+void sw_event_release(struct rte_event_dev *dev, uint8_t port_id, uint8_t index);
+int  sw_event_schedule(struct rte_event_dev *dev);
+
+#endif /* _SW_EVDEV_H_ */
diff --git a/drivers/event/sw/sw_evdev_scheduler.c b/drivers/event/sw/sw_evdev_scheduler.c
new file mode 100644
index 0000000..02831d2
--- /dev/null
+++ b/drivers/event/sw/sw_evdev_scheduler.c
@@ -0,0 +1,660 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_ring.h>
+#include "sw_evdev.h"
+#include "iq_ring.h"
+
+#define SW_IQS_MASK (SW_IQS_MAX-1)
+
+/* Retrieve the highest priority IQ or -1 if no pkts available. Doing the
+ * CLZ twice is faster than caching the value due to data dependencies
+ */
+#define PKT_MASK_TO_IQ(pkts) \
+	(__builtin_ctz(pkts | (1 << SW_IQS_MAX)))
+
+/* Clamp the highest priorities to the max value as allowed by
+ * the mask. Assums MASK is (powerOfTwo - 1). Priority 0 (highest) are shifted
+ * into leftmost IQ so that clz() reads it first on dequeue
+ */
+#define PRIO_TO_IQ(prio) (prio > SW_IQS_MASK ? SW_IQS_MASK : prio)
+
+static inline uint32_t
+sw_schedule_atomic_to_cq(struct sw_evdev *sw, struct sw_qid * const qid,
+		    uint32_t iq_num, unsigned int count)
+{
+	uint32_t i;
+
+	if(count == 0)
+		return 0;
+
+	/* This is the QID ID. The QID ID is static, hence it can be
+	 * used to identify the stage of processing in history lists etc */
+	uint32_t qid_id = qid->id;
+
+	for (i = 0; i < count; i++) {
+		const struct rte_event *qe = iq_ring_peek(qid->iq[iq_num]);
+		struct sw_fid_t *fid = &qid->fids[qe->flow_id];
+		int cq = fid->cq;
+
+		/* If no CQ is assigned, pick one */
+		if (cq < 0) {
+			/* select CQ based on least inflights,
+			 * defaulting to the first mapped CQ
+			 */
+			uint32_t cq_idx = qid->cq_next_tx++;
+			if (qid->cq_next_tx == qid->cq_num_mapped_cqs)
+				qid->cq_next_tx = 0;
+			cq = qid->cq_map[cq_idx];
+			int cq_free_cnt = sw->cq_ring_space[cq];
+
+			for (cq_idx = 0; cq_idx < qid->cq_num_mapped_cqs; cq_idx++) {
+				int test_cq = qid->cq_map[cq_idx];
+				int test_cq_free = sw->cq_ring_space[test_cq];
+
+				if (test_cq_free > cq_free_cnt)
+					cq = test_cq, cq_free_cnt = test_cq_free;
+			}
+		}
+
+		struct sw_port *p = &sw->ports[cq];
+
+		/* If the destination CQ or its history list is full, move on
+		* to the next queue.
+		*/
+		if (sw->cq_ring_space[cq] == 0 ||
+				p->inflights == SW_PORT_HIST_LIST) {
+			struct qe_ring *worker = sw->ports[cq].cq_worker_ring;
+			qe_ring_enqueue_burst(worker, sw->ports[cq].cq_buf,
+					sw->ports[cq].cq_buf_count,
+					&sw->cq_ring_space[cq]);
+			sw->ports[cq].cq_buf_count = 0;
+#if 0
+			printf("%s cq %d was 0, now %d\n", __func__,
+					cq, sw->cq_ring_space[cq]);
+#endif
+			if(sw->cq_ring_space[cq] == 0)
+				break;
+		}
+
+		sw->cq_ring_space[cq]--;
+
+		/* store which CQ this FID is active on,
+		 * for future pkts of the same flow
+		 */
+		fid->cq = cq;
+		fid->count++;
+
+		qid->stats.tx_pkts++;
+		sw->ports[cq].inflights++;
+
+		int head = (p->hist_head & (SW_PORT_HIST_LIST-1));
+
+		p->hist_list[head].fid = qe->flow_id;
+		p->hist_list[head].qid = qid_id;
+
+		p->hist_head++;
+		p->stats.tx_pkts++;
+		sw->ports[cq].cq_buf[sw->ports[cq].cq_buf_count++] = *qe;
+		iq_ring_pop(qid->iq[iq_num]);
+	}
+	return i;
+}
+
+static inline uint32_t
+sw_schedule_parallel_to_cq(struct sw_evdev *sw, struct sw_qid * const qid,
+		      uint32_t iq_num, unsigned int count, int keep_order)
+{
+	uint32_t i;
+	uint32_t cq_idx = qid->cq_next_tx;
+
+	/* This is the QID ID. The QID ID is static, hence it can be
+	 * used to identify the stage of processing in history lists etc */
+	uint32_t qid_id = qid->id;
+
+
+	if (keep_order)
+		/* only schedule as many as we have reorder buffer entries */
+		count = RTE_MIN(count, rte_ring_count(qid->reorder_buffer_freelist));
+
+	for (i = 0; i < count; i++) {
+		const struct rte_event *qe = iq_ring_peek(qid->iq[iq_num]);
+		uint32_t cq_check_count = 0;
+		uint32_t cq;
+
+		/*
+		 *  for parallel, just send to next available CQ in round-robin
+		 * fashion. So scan for an available CQ. If all CQs are full
+		 * just return and move on to next QID
+		 */
+		do {
+			if (++cq_check_count > qid->cq_num_mapped_cqs)
+				goto exit;
+			cq = qid->cq_map[cq_idx];
+			if (++cq_idx == qid->cq_num_mapped_cqs)
+				cq_idx = 0;
+		} while (qe_ring_free_count(sw->ports[cq].cq_worker_ring) == 0 ||
+				sw->ports[cq].inflights == SW_PORT_HIST_LIST);
+
+		struct sw_port *p = &sw->ports[cq];
+		if (sw->cq_ring_space[cq] == 0 ||
+				p->inflights == SW_PORT_HIST_LIST)
+			break;
+
+		sw->cq_ring_space[cq]--;
+
+		qid->stats.tx_pkts++;
+
+		const int head = (p->hist_head & (SW_PORT_HIST_LIST-1));
+
+		p->hist_list[head].fid = qe->flow_id;
+		p->hist_list[head].qid = qid_id;
+
+		if (keep_order)
+			rte_ring_sc_dequeue(qid->reorder_buffer_freelist,
+					(void *)&p->hist_list[head].rob_entry);
+
+		sw->ports[cq].cq_buf[sw->ports[cq].cq_buf_count++] = *qe;
+		iq_ring_pop(qid->iq[iq_num]);
+
+		rte_compiler_barrier();
+		p->inflights++;
+		p->stats.tx_pkts++;
+		p->hist_head++;
+	}
+exit:
+	qid->cq_next_tx = cq_idx;
+	return i;
+}
+
+static uint32_t
+sw_schedule_dir_to_cq(struct sw_evdev *sw, struct sw_qid * const qid,
+		    uint32_t iq_num, unsigned int count)
+{
+	uint32_t cq_id = qid->cq_map[0];
+	struct sw_port *port = &sw->ports[cq_id];
+
+	/* get max burst enq size for cq_ring */
+	uint32_t count_free = sw->cq_ring_space[cq_id];
+	if (count == 0 || count_free == 0)
+		return 0;
+
+	/* burst dequeue from the QID IQ ring */
+	struct iq_ring *ring = qid->iq[iq_num];
+	uint32_t ret = iq_ring_dequeue_burst(ring,
+			&port->cq_buf[port->cq_buf_count], count_free);
+	port->cq_buf_count += ret;
+
+	/* Update QID, Port and Total TX stats */
+	qid->stats.tx_pkts += ret;
+	port->stats.tx_pkts += ret;
+
+	/* Subtract credits from cached value */
+	sw->cq_ring_space[cq_id] -= ret;
+
+	return ret;
+}
+
+static uint32_t
+sw_schedule_qid_to_cq(struct sw_evdev *sw)
+{
+	uint32_t pkts = 0;
+	uint32_t qid_idx;
+
+	sw->sched_cq_qid_called++;
+
+	for (qid_idx = 0; qid_idx < sw->qid_count; qid_idx++) {
+		/* make the QID lookup here be based on priority of the QID */
+		struct sw_qid *qid = sw->qids_prioritized[qid_idx];
+
+		int type = qid->type;
+		int iq_num = PKT_MASK_TO_IQ(qid->iq_pkt_mask);
+
+		/* zero mapped CQs indicates directed */
+		if (iq_num >= SW_IQS_MAX)
+			continue;
+
+		unsigned int count = iq_ring_count(qid->iq[iq_num]);
+		uint32_t pkts_done = 0;
+
+		if (type == RTE_SCHED_TYPE_DIRECT)
+			pkts_done += sw_schedule_dir_to_cq(sw, qid,
+					iq_num, count);
+		else if (type == RTE_SCHED_TYPE_ATOMIC)
+			pkts_done += sw_schedule_atomic_to_cq(sw, qid,
+					iq_num, count);
+		else
+			pkts_done += sw_schedule_parallel_to_cq(sw, qid,
+					iq_num, count,
+					(type == RTE_SCHED_TYPE_ORDERED));
+
+		/* Check if the IQ that was polled is now empty, and unset it
+		 * in the IQ mask if its empty.
+		 */
+		int all_done = (pkts_done == count);
+
+		qid->iq_pkt_mask &= ~(all_done << (iq_num));
+		pkts += pkts_done;
+	}
+
+	return pkts;
+}
+
+/* This function will perform re-ordering of packets, and injecting into
+ * the appropriate QID IQ. As LB and DIR QIDs are in the same array, but *NOT*
+ * contiguous in that array, this function accepts a "range" of QIDs to scan.
+ */
+static uint16_t
+sw_schedule_reorder(struct sw_evdev *sw, int qid_start, int qid_end)
+{
+	/* Perform egress reordering */
+	struct rte_event *qe;
+	uint32_t pkts_iter = 0;
+
+	for (; qid_start < qid_end; qid_start++) {
+		struct sw_qid *qid = &sw->qids[qid_start];
+		int i, num_entries_in_use;
+
+		if (qid->type != RTE_SCHED_TYPE_ORDERED)
+			continue;
+
+		num_entries_in_use = rte_ring_free_count(
+					qid->reorder_buffer_freelist);
+
+		for (i = 0; i < num_entries_in_use; i++) {
+			struct reorder_buffer_entry *entry;
+			int j;
+
+			entry = &qid->reorder_buffer[qid->reorder_buffer_index];
+
+			if (!entry->ready)
+				break;
+
+			for (j = 0; j < entry->num_fragments; j++) {
+				uint16_t dest_qid;
+				uint16_t dest_iq;
+
+				qe = &entry->fragments[entry->fragment_index + j];
+
+				dest_qid = qe->flow_id;
+				dest_iq  = PRIO_TO_IQ(qe->priority);
+
+				if(dest_qid >= sw->qid_count) {
+					sw->stats.rx_dropped++;
+					continue;
+				}
+
+				struct sw_qid *dest_qid_ptr = &sw->qids[dest_qid];
+				const struct iq_ring *dest_iq_ptr = dest_qid_ptr->iq[dest_iq];
+				if (iq_ring_free_count(dest_iq_ptr) == 0)
+					break;
+
+				pkts_iter++;
+
+				struct sw_qid *q = &sw->qids[dest_qid];
+				struct iq_ring *r = q->iq[dest_iq];
+
+				/* we checked for space above, so enqueue must
+				 * succeed
+				 */
+				iq_ring_enqueue(r, qe);
+				q->iq_pkt_mask |= (1 << (dest_iq));
+				q->iq_pkt_count[dest_iq]++;
+				q->stats.rx_pkts++;
+			}
+
+			entry->ready = (j != entry->num_fragments);
+			entry->num_fragments -= j;
+			entry->fragment_index += j;
+
+			if (!entry->ready) {
+				entry->fragment_index = 0;
+
+				rte_ring_sp_enqueue(qid->reorder_buffer_freelist,
+						    entry);
+
+				qid->reorder_buffer_index++;
+				qid->reorder_buffer_index %= qid->window_size;
+			}
+		}
+	}
+	return pkts_iter;
+}
+
+static uint32_t
+sw_schedule_pull_port_lb(struct sw_evdev *sw, uint32_t port_id)
+{
+	uint32_t pkts_iter = 0;
+	struct sw_port *port = &sw->ports[port_id];
+	struct qe_ring *worker = port->rx_worker_ring;
+
+	/* If shadow ring has 0 pkts, pull from worker ring */
+	if(port->pp_buf_count == 0) {
+		port->pp_buf_start = 0;
+		port->pp_buf_count = qe_ring_dequeue_burst(worker, port->pp_buf,
+				RTE_DIM(port->pp_buf));
+
+		if (port->overloaded &&
+				qe_ring_count(worker) < SW_PORT_OVERLOAD_THRES/2) {
+			port->overloaded = 0;
+			sw->sched_overload_counter++;
+			rte_atomic32_dec((void *)&sw->overloaded);
+		}
+	}
+
+	while (port->pp_buf_count) {
+		const struct rte_event *qe = &port->pp_buf[port->pp_buf_start];
+		struct sw_hist_list_entry *hist_entry = NULL;
+		uint8_t flags = qe->operation;
+		const uint16_t eop = !(flags & QE_FLAG_NOT_EOP);
+		int needs_reorder = 0;
+
+		static const struct reorder_buffer_entry dummy_rob;
+
+		/*
+		 * if we don't have space for this packet in an IQ,
+		 * then move on to next queue. Technically, for a
+		 * packet that needs reordering, we don't need to check
+		 * here, but it simplifies things not to special-case
+		 */
+		uint32_t iq_num = PRIO_TO_IQ(qe->priority);
+		struct sw_qid *qid = &sw->qids[qe->queue_id];
+		struct iq_ring *iq_ring = qid->iq[iq_num];
+
+		if ((flags & QE_FLAG_VALID) &&
+				iq_ring_free_count(iq_ring) == 0)
+			break;
+
+		/* now process based on flags. Note that for directed
+		 * queues, the enqueue_flush masks off all but the
+		 * valid flag. This makes FWD and partial enqueues just
+		 * NEW type, and makes DROPS no-op calls.
+		 */
+		if ((flags & QE_FLAG_COMPLETE) && port->inflights > 0) {
+			const uint32_t hist_tail = port->hist_tail &
+					(SW_PORT_HIST_LIST - 1);
+
+			hist_entry = &port->hist_list[hist_tail];
+			const uint32_t hist_qid = hist_entry->qid;
+			const uint32_t hist_fid = hist_entry->fid;
+
+			struct sw_fid_t *fid = &sw->qids[hist_qid].fids[hist_fid];
+			fid->count -= eop;
+			if (fid->count == 0)
+				fid->cq = -1;
+
+			/* set reorder ready if an ordered QID */
+			uintptr_t rob_ptr = (uintptr_t)hist_entry->rob_entry;
+			const uintptr_t valid = (rob_ptr != 0);
+			needs_reorder = valid;
+			rob_ptr |= ((valid - 1) & (uintptr_t)&dummy_rob);
+			((struct reorder_buffer_entry*)rob_ptr)->ready =
+					eop * needs_reorder;
+
+			port->inflights -= eop;
+			port->hist_tail += eop;
+		}
+		if (flags & QE_FLAG_VALID) {
+			port->stats.rx_pkts++;
+
+			if (needs_reorder) {
+				struct reorder_buffer_entry *rob_entry =
+						hist_entry->rob_entry;
+
+				//TODO: How do we alert the user that they've exceeded max frags?
+				if (rob_entry->num_fragments == SW_FRAGMENTS_MAX)
+					sw->stats.rx_dropped++;
+				else
+					rob_entry->fragments[rob_entry->num_fragments++] = *qe;
+				goto end_qe;
+			}
+
+			/* Use the iq_num from above to push the QE
+			 * into the qid at the right priority
+			 */
+
+			qid->iq_pkt_mask |= (1 << (iq_num));
+			iq_ring_enqueue(iq_ring, qe);
+			qid->iq_pkt_count[iq_num]++;
+			qid->stats.rx_pkts++;
+			pkts_iter++;
+		}
+
+		end_qe:
+		port->pp_buf_start++;
+		port->pp_buf_count--;
+	} /* while (avail_qes) */
+
+	return pkts_iter;
+}
+
+static uint32_t
+sw_schedule_pull_port_dir(struct sw_evdev *sw, uint32_t port_id)
+{
+	uint32_t pkts_iter = 0;
+	struct sw_port *port = &sw->ports[port_id];
+	struct qe_ring *worker = port->rx_worker_ring;
+
+	/* If shadow ring has 0 pkts, pull from worker ring */
+	if (port->pp_buf_count == 0) {
+		port->pp_buf_start = 0;
+		port->pp_buf_count = qe_ring_dequeue_burst(worker, port->pp_buf,
+				RTE_DIM(port->pp_buf));
+
+		if (port->overloaded &&
+				qe_ring_count(worker) < SW_PORT_OVERLOAD_THRES/2) {
+			port->overloaded = 0;
+			sw->sched_overload_counter++;
+			rte_atomic32_dec((void *)&sw->overloaded);
+		}
+	}
+
+	while (port->pp_buf_count) {
+		const struct rte_event *qe = &port->pp_buf[port->pp_buf_start];
+		uint8_t flags = qe->operation;
+
+		if ((flags & QE_FLAG_VALID) == 0)
+			goto end_qe;
+
+		uint32_t iq_num = PRIO_TO_IQ(qe->priority);
+		struct sw_qid *qid = &sw->qids[qe->queue_id];
+		struct iq_ring *iq_ring = qid->iq[iq_num];
+
+		if (iq_ring_free_count(iq_ring) == 0)
+			break; /* move to next port */
+
+		port->stats.rx_pkts++;
+
+		/* Use the iq_num from above to push the QE
+		 * into the qid at the right priority
+		 */
+		qid->iq_pkt_mask |= (1 << (iq_num));
+		iq_ring_enqueue(iq_ring, qe);
+		qid->iq_pkt_count[iq_num]++;
+		qid->stats.rx_pkts++;
+		pkts_iter++;
+
+		end_qe:
+		port->pp_buf_start++;
+		port->pp_buf_count--;
+	} /* while port->pp_buf_count */
+
+	return pkts_iter;
+}
+
+static uint32_t
+sw_schedule_pull_port_no_reorder(struct sw_evdev *sw, uint32_t port_id)
+{
+	uint32_t pkts_iter = 0;
+	struct sw_port *port = &sw->ports[port_id];
+	struct qe_ring *worker = port->rx_worker_ring;
+
+	if (port->pp_buf_count == 0) {
+		port->pp_buf_start = 0;
+		port->pp_buf_count = qe_ring_dequeue_burst(worker, port->pp_buf,
+				RTE_DIM(port->pp_buf));
+
+		if (port->overloaded &&
+				qe_ring_count(worker) < SW_PORT_OVERLOAD_THRES/2) {
+			port->overloaded = 0;
+			sw->sched_overload_counter++;
+			rte_atomic32_dec((void *)&sw->overloaded);
+		}
+	}
+
+	while (port->pp_buf_count) {
+		const struct rte_event *ev = &port->pp_buf[port->pp_buf_start];
+		struct sw_hist_list_entry *hist_entry = NULL;
+		uint8_t flags = ev->operation;
+
+		/* for fragments, ignore completion
+		 * NOTE: if not_eop flag is set, completion flag must
+		 * also be set so we can use xor */
+		flags ^= !(flags & QE_FLAG_NOT_EOP) >>
+				(QE_FLAG_NOT_EOP_SHIFT - QE_FLAG_COMPLETE_SHIFT);
+
+		/*
+		 * if we don't have space for this packet in an IQ,
+		 * then move on to next queue.
+		 */
+		uint32_t iq_num = PRIO_TO_IQ(ev->priority);
+		struct sw_qid *qid = &sw->qids[ev->queue_id];
+		struct iq_ring *iq_ring = qid->iq[iq_num];
+
+		if ((flags & QE_FLAG_VALID) &&
+				iq_ring_free_count(iq_ring) == 0)
+			break;
+
+		/* now process based on flags. Note that for directed
+		 * queues, the enqueue_flush masks off all but the
+		 * valid flag. This makes FWD and partial enqueues just
+		 * NEW type, and makes DROPS no-op calls.
+		 */
+		if ((flags & QE_FLAG_COMPLETE) && port->inflights > 0) {
+			const uint32_t hist_tail = port->hist_tail &
+					(SW_PORT_HIST_LIST - 1);
+
+			hist_entry = &port->hist_list[hist_tail];
+			const uint32_t hist_qid = hist_entry->qid;
+			const uint32_t hist_fid = hist_entry->fid;
+
+			struct sw_fid_t *fid = &sw->qids[hist_qid].fids[hist_fid];
+			fid->count--;
+			if (fid->count == 0)
+				fid->cq = -1;
+
+			port->inflights --;
+			port->hist_tail ++;
+		}
+		if (flags & QE_FLAG_VALID) {
+			port->stats.rx_pkts++;
+
+			/* Use the iq_num from above to push the QE
+			 * into the qid at the right priority
+			 */
+
+			qid->iq_pkt_mask |= (1 << (iq_num));
+			iq_ring_enqueue(iq_ring, ev);
+			qid->iq_pkt_count[iq_num]++;
+			qid->stats.rx_pkts++;
+			pkts_iter++;
+		}
+
+		port->pp_buf_start++;
+		port->pp_buf_count--;
+	} /* while (avail_qes) */
+
+	return pkts_iter;
+}
+
+int
+sw_event_schedule(struct rte_event_dev *dev)
+{
+	static const uint32_t num_pkts = 256;
+	struct sw_evdev *sw = (struct sw_evdev *)dev;
+	uint32_t in_pkts, out_pkts;
+	uint32_t out_pkts_total = 0, in_pkts_total = 0;
+	uint32_t i;
+
+	sw->sched_called++;
+	if (!sw->started)
+		return -1;
+
+	do {
+		uint32_t in_pkts_this_iteration = 0;
+
+		/* Pull from rx_ring for ports */
+		do {
+			in_pkts = 0;
+			for (i = 0; i < sw->port_count; i++)
+				/* TODO: use a function pointer in the port itself */
+				if (sw->ports[i].is_directed)
+					in_pkts += sw_schedule_pull_port_dir(sw, i);
+				else if (sw->ports[i].num_ordered_qids > 0)
+					in_pkts += sw_schedule_pull_port_lb(sw, i);
+				else
+					in_pkts += sw_schedule_pull_port_no_reorder(sw, i);
+
+			/* QID scan for re-ordered */
+			in_pkts += sw_schedule_reorder(sw, 0,
+					sw->qid_count);
+			in_pkts_this_iteration += in_pkts;
+		} while (in_pkts > 0 && in_pkts_this_iteration < num_pkts);
+
+		out_pkts = 0;
+		out_pkts += sw_schedule_qid_to_cq(sw);
+		out_pkts_total += out_pkts;
+		in_pkts_total += in_pkts_this_iteration;
+
+		if (in_pkts == 0 && out_pkts == 0)
+			break;
+	} while (out_pkts_total < num_pkts);
+
+	/* push all the internal buffered QEs in port->cq_ring to the
+	 * worker cores: aka, do the ring transfers batched.
+	 */
+	for(i = 0; i < sw->port_count; i++) {
+		struct qe_ring *worker = sw->ports[i].cq_worker_ring;
+		qe_ring_enqueue_burst(worker, sw->ports[i].cq_buf,
+				sw->ports[i].cq_buf_count,
+				&sw->cq_ring_space[i]);
+		sw->ports[i].cq_buf_count = 0;
+	}
+
+	sw->stats.tx_pkts += out_pkts_total;
+	sw->stats.rx_pkts += in_pkts_total;
+
+	sw->sched_no_iq_enqueues += (in_pkts_total == 0);
+	sw->sched_no_cq_enqueues += (out_pkts_total == 0);
+
+	return out_pkts_total;
+}
diff --git a/drivers/event/sw/sw_evdev_worker.c b/drivers/event/sw/sw_evdev_worker.c
new file mode 100644
index 0000000..1b055cc
--- /dev/null
+++ b/drivers/event/sw/sw_evdev_worker.c
@@ -0,0 +1,218 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sw_evdev.h"
+
+#include <rte_atomic.h>
+#include <rte_hash_crc.h>
+
+#define FLOWID_MASK (SW_QID_NUM_FIDS-1)
+
+static inline void
+sw_overload_check_and_set(struct sw_evdev *sw, struct sw_port *p,
+			  uint16_t free_count)
+{
+	if (!p->overloaded &&
+			free_count < MAX_SW_PROD_Q_DEPTH - p->overload_threshold) {
+		p->overloaded = 1;
+		rte_atomic32_inc((void *)&sw->overloaded);
+	}
+}
+
+int
+sw_event_enqueue(struct rte_event_dev *dev, uint8_t port_id, struct rte_event *ev,
+		  bool pin_event)
+{
+	RTE_SET_USED(pin_event);
+	uint16_t free_count;
+	struct sw_evdev *sw = (void *)dev;
+
+	if(port_id >= sw->port_count)
+		return -1;
+
+	struct sw_port *p = &sw->ports[port_id];
+	/* TODO: Concider optimization: keep port overloaded in flat array in
+	 * sw instance, do a lookup and just one return branch together with
+	 * port_id check above */
+	if(sw->overloaded && ev->operation == RTE_EVENT_OP_NEW)
+		return -ENOSPC;
+
+	ev->operation = sw_qe_flag_map[ev->operation];
+	const uint8_t invalid_qid = (ev[0].queue_id >= sw->qid_count);
+	ev[0].operation &= ~(invalid_qid << QE_FLAG_VALID_SHIFT);
+	/* mask flowID to valid range after a crc to jumble bits */
+	ev[0].flow_id = FLOWID_MASK & rte_hash_crc_4byte(ev[0].flow_id, -1);
+
+	if(invalid_qid) {
+		p->stats.rx_dropped++;
+	}
+
+	unsigned int num_enq = qe_ring_enqueue_burst(p->rx_worker_ring,
+						     ev, 1, &free_count);
+
+	sw_overload_check_and_set(sw, p, free_count);
+
+	/* TODO: Discuss on ML and fix this inconsistency in API:
+	 * num_enq is the number of packet enqueued, so
+	 * 0 = no packets
+	 * 1 = got a packet
+	 * This is different to how currently documented in API.
+	 */
+	return num_enq;
+}
+
+int
+sw_event_enqueue_burst(struct rte_event_dev *dev, uint8_t port_id,
+			struct rte_event ev[], int num, bool pin_event)
+{
+	/* TODO: change enqueue API to uint32_t for num? */
+	int32_t i;
+	uint16_t free_count;
+	struct sw_evdev *sw = (void *)dev;
+
+	if(port_id >= sw->port_count)
+		return 0;
+
+	struct sw_port *p = &sw->ports[port_id];
+	RTE_SET_USED(pin_event);
+
+	for (i = 0; i < num; i++) {
+		/* optimize to two loops, with and without overload */
+		if(sw->overloaded && ev[i].operation == RTE_EVENT_OP_NEW)
+			return -ENOSPC;
+
+		ev[i].operation = sw_qe_flag_map[ev[i].operation];
+		const uint8_t invalid_qid = (ev[i].queue_id >= sw->qid_count);
+		ev[i].operation &= ~(invalid_qid << QE_FLAG_VALID_SHIFT);
+		ev[i].flow_id = FLOWID_MASK & rte_hash_crc_4byte(ev[i].flow_id, -1);
+
+		if(invalid_qid) {
+			p->stats.rx_dropped++;
+		}
+	}
+
+	/* returns number of events actually enqueued */
+	uint32_t deq = qe_ring_enqueue_burst(p->rx_worker_ring, ev, num,
+					     &free_count);
+	sw_overload_check_and_set(sw, p, free_count);
+	return deq;
+}
+
+bool
+sw_event_dequeue(struct rte_event_dev *dev, uint8_t port_id,
+		  struct rte_event *ev, uint64_t wait)
+{
+	RTE_SET_USED(wait);
+	struct sw_evdev *sw = (void *)dev;
+
+	if(port_id >= sw->port_count)
+		return 0;
+
+	struct sw_port *p = &sw->ports[port_id];
+	struct qe_ring *ring = p->cq_worker_ring;
+
+	/* check that all previous dequeus have been released */
+	uint16_t out_rels = p->outstanding_releases;
+	uint16_t i;
+	for(i = 0; i < out_rels; i++) {
+		sw_event_release(dev, port_id, i);
+	}
+
+	/* Intel modification: may not be in final API */
+	if(ev == 0)
+		return 0;
+
+	/* returns number of events actually dequeued, after storing */
+	uint32_t ndeq = qe_ring_dequeue_burst(ring, ev, 1);
+	p->outstanding_releases = ndeq;
+	return ndeq;
+}
+
+int
+sw_event_dequeue_burst(struct rte_event_dev *dev, uint8_t port_id,
+			struct rte_event *ev, int num, uint64_t wait)
+{
+	RTE_SET_USED(wait);
+	struct sw_evdev *sw = (void *)dev;
+
+	if(port_id >= sw->port_count)
+		return 0;
+
+	struct sw_port *p = &sw->ports[port_id];
+	struct qe_ring *ring = p->cq_worker_ring;
+
+	/* check that all previous dequeus have been released */
+	if (!p->is_directed) {
+		uint16_t out_rels = p->outstanding_releases;
+		uint16_t i;
+		for(i = 0; i < out_rels; i++) {
+			sw_event_release(dev, port_id, i);
+		}
+	}
+
+	/* Intel modification: may not be in final API */
+	if(ev == 0)
+		return 0;
+
+	/* returns number of events actually dequeued */
+	uint32_t ndeq = qe_ring_dequeue_burst(ring, ev, num);
+	p->outstanding_releases = ndeq;
+	return ndeq;
+}
+
+void
+sw_event_release(struct rte_event_dev *dev, uint8_t port_id, uint8_t index)
+{
+	struct sw_evdev *sw = (void *)dev;
+	struct sw_port *p = &sw->ports[port_id];
+	RTE_SET_USED(p);
+	RTE_SET_USED(index);
+
+	/* This function "hints" the scheduler that packet *index* of the
+	 * previous burst:
+	 * (Atomic)  has completed is critical section
+	 * (Ordered) is ready for egress
+	 *
+	 * It is not mandatory to implement this functionality, but it may
+	 * improve load-balancing / parallelism in the packet flows.
+	 */
+
+	/* create drop message */
+	struct rte_event ev = {
+		.operation = sw_qe_flag_map[RTE_EVENT_OP_DROP],
+	};
+
+	uint16_t free_count;
+	qe_ring_enqueue_burst(p->rx_worker_ring, &ev, 1, &free_count);
+
+	p->outstanding_releases--;
+}
-- 
2.7.4

^ permalink raw reply related

* [PATCH 2/7] eventdev: makefiles
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, Gage Eads, Bruce Richardson
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

Makefiles that compile the previously committed eventdev header and
infrastructure files.  This commit changes the Makefiles and config/base
to add the config options of building the eventdev.

Signed-off-by: Gage Eads <gage.eads@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 config/common_base                       |  6 ++++
 drivers/Makefile                         |  1 +
 drivers/event/Makefile                   | 34 ++++++++++++++++++++
 lib/Makefile                             |  1 +
 lib/librte_eal/common/include/rte_vdev.h |  1 +
 lib/librte_eventdev/Makefile             | 54 ++++++++++++++++++++++++++++++++
 mk/rte.app.mk                            |  1 +
 7 files changed, 98 insertions(+)
 create mode 100644 drivers/event/Makefile
 create mode 100644 lib/librte_eventdev/Makefile

diff --git a/config/common_base b/config/common_base
index 4bff83a..a0a07f6 100644
--- a/config/common_base
+++ b/config/common_base
@@ -411,6 +411,12 @@ CONFIG_RTE_LIBRTE_PMD_ZUC_DEBUG=n
 CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO=y
 
 #
+# Compile event device library
+#
+CONFIG_RTE_LIBRTE_EVENTDEV=y
+CONFIG_RTE_LIBRTE_EVENTDEV_DEBUG=n
+
+#
 # Compile librte_ring
 #
 CONFIG_RTE_LIBRTE_RING=y
diff --git a/drivers/Makefile b/drivers/Makefile
index 81c03a8..40b8347 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -33,5 +33,6 @@ include $(RTE_SDK)/mk/rte.vars.mk
 
 DIRS-y += net
 DIRS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += crypto
+DIRS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += event
 
 include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/drivers/event/Makefile b/drivers/event/Makefile
new file mode 100644
index 0000000..93f90eb
--- /dev/null
+++ b/drivers/event/Makefile
@@ -0,0 +1,34 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+include $(RTE_SDK)/mk/rte.subdir.mk
diff --git a/lib/Makefile b/lib/Makefile
index 990f23a..75b9868 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -58,6 +58,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_TABLE) += librte_table
 DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += librte_pipeline
 DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
+DIRS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += librte_eventdev
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 784e837..22c1e19 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -38,6 +38,7 @@ extern "C" {
 #endif
 
 #include <sys/queue.h>
+#include <rte_eal.h>
 #include <rte_dev.h>
 
 /** Double linked list of virtual device drivers. */
diff --git a/lib/librte_eventdev/Makefile b/lib/librte_eventdev/Makefile
new file mode 100644
index 0000000..5e2c467
--- /dev/null
+++ b/lib/librte_eventdev/Makefile
@@ -0,0 +1,54 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2016 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_eventdev.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR)
+
+EXPORT_MAP := rte_eventdev_version.map
+
+LIBABIVER := 1
+
+# all source are stored in SRCS-y
+SRCS-$(CONFIG_RTE_LIBRTE_EVENTDEV) := rte_eventdev.c
+
+# install this header file
+SYMLINK-$(CONFIG_RTE_LIBRTE_EVENTDEV)-include := rte_eventdev.h rte_eventdev_pmd.h rte_eventdev_ops.h
+
+# this lib depends upon:
+DEPDIRS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += lib/librte_eal
+DEPDIRS-$(CONFIG_RTE_LIBRTE_EVENTDEV) += lib/librte_kvargs
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index f75f0e2..716725a 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -93,6 +93,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_MBUF)           += -lrte_mbuf
 _LDLIBS-$(CONFIG_RTE_LIBRTE_NET)            += -lrte_net
 _LDLIBS-$(CONFIG_RTE_LIBRTE_ETHER)          += -lrte_ethdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_CRYPTODEV)      += -lrte_cryptodev
+_LDLIBS-$(CONFIG_RTE_LIBRTE_EVENTDEV)       += -lrte_eventdev
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
 _LDLIBS-$(CONFIG_RTE_LIBRTE_RING)           += -lrte_ring
 _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL)            += -lrte_eal
-- 
2.7.4

^ permalink raw reply related

* [PATCH 1/7] eventdev: header and implementation
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren, Gage Eads, Bruce Richardson
In-Reply-To: <1479319207-130646-1-git-send-email-harry.van.haaren@intel.com>

This commit adds the eventdev API header, and the library infrastructure
necessary to work with an eventdev instance.  The header is mostly the same
as discussed on the mailing list, in particular see the libeventdev RFC
thread[1].  A second thread[2] gathered input from the community, which
resulted in various modifications to the header.

Since then, some modifications have been made that were discovered during
the implementation of the software implementation of an eventdev. These
changes are present in this header as suggestions, and feedback on these
changes is welcomed. Some of the main items are:
   - A statistics API, similar to rte_ethdev_stats_get()
   - A dump API, similar to rte_ring_dump()
   - Return value of rte_eventdev_enqueue() changed for dequeue consistency
   - rte_event has implementation/operation field as discussed[3]
   - Add enqueue types using operation[4]

This commit does not change any existing DPDK code - only adds the eventdev
header and infrastructure.

Signed-off-by: Gage Eads <gage.eads@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

[1] http://dpdk.org/ml/archives/dev/2016-August/045181.html
[2] http://dpdk.org/ml/archives/dev/2016-October/048196.html
[3] http://dpdk.org/ml/archives/dev/2016-October/049459.html
[4] http://dpdk.org/ml/archives/dev/2016-October/049641.html
---
 lib/librte_eventdev/rte_eventdev.c           |  466 ++++++++++
 lib/librte_eventdev/rte_eventdev.h           | 1272 ++++++++++++++++++++++++++
 lib/librte_eventdev/rte_eventdev_ops.h       |  177 ++++
 lib/librte_eventdev/rte_eventdev_pmd.h       |   69 ++
 lib/librte_eventdev/rte_eventdev_version.map |   33 +
 5 files changed, 2017 insertions(+)
 create mode 100644 lib/librte_eventdev/rte_eventdev.c
 create mode 100644 lib/librte_eventdev/rte_eventdev.h
 create mode 100644 lib/librte_eventdev/rte_eventdev_ops.h
 create mode 100644 lib/librte_eventdev/rte_eventdev_pmd.h
 create mode 100644 lib/librte_eventdev/rte_eventdev_version.map

diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c
new file mode 100644
index 0000000..aace5ca
--- /dev/null
+++ b/lib/librte_eventdev/rte_eventdev.c
@@ -0,0 +1,466 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+
+#include <rte_eal.h>
+#include <rte_eal_memconfig.h>
+#include <rte_dev.h>
+#include "rte_eventdev.h"
+#include "rte_eventdev_pmd.h"
+#include "rte_eventdev_ops.h"
+
+#define RTE_MAX_EVENT_DEVS 32
+struct rte_event_dev *event_devs[RTE_MAX_EVENT_DEVS];
+static int rte_num_event_dev_pmds;
+
+TAILQ_HEAD(rte_eventdev_list, rte_event_dev);
+
+static struct rte_tailq_elem rte_eventdev_tailq = {
+	.name = "EVENT_DEVS",
+};
+EAL_REGISTER_TAILQ(rte_eventdev_tailq)
+
+#ifdef RTE_LIBRTE_EVENTDEV_DEBUG
+#define RTE_PMD_DEBUG_TRACE(...) \
+	rte_pmd_debug_trace(__func__, __VA_ARGS__)
+#else
+#define RTE_PMD_DEBUG_TRACE(...)
+#endif
+
+
+int
+rte_event_dev_register(struct rte_event_dev *new_dev)
+{
+	uint8_t index = rte_num_event_dev_pmds;
+	struct rte_eventdev_list *list;
+
+	list = RTE_TAILQ_CAST(rte_eventdev_tailq.head, rte_eventdev_list);
+
+	/* The primary process is responsible for adding the eventdevs to the
+	 * tailQ, and the secondary processes simply look up the eventdev in
+	 * the list and add it to their local array for fast access.
+	 */
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		new_dev->id = index;
+
+		rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
+		TAILQ_INSERT_TAIL(list, new_dev, next);
+		rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+	} else {
+		struct rte_event_dev *dev;
+
+		bool found = false;
+		rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
+		TAILQ_FOREACH(dev, list, next) {
+			if (strcmp(dev->name, new_dev->name) == 0) {
+				found = true;
+				break;
+			}
+		}
+		rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK);
+
+		if (!found)
+			return -1;
+	}
+
+	event_devs[new_dev->id] = new_dev;
+
+	rte_num_event_dev_pmds++;
+
+	return 0;
+}
+
+uint8_t
+rte_event_dev_count(void)
+{
+	return rte_num_event_dev_pmds;
+}
+
+int8_t
+rte_event_dev_get_dev_id(const char *name)
+{
+	struct rte_event_dev *d;
+	int i;
+
+	/* FIXME: This loop only works on secondary processes when the same
+	 * eventdev vdevs as the primary process are passed on the command
+	 * line.
+	 */
+	for (i = 0; i < rte_num_event_dev_pmds; i++) {
+		d = event_devs[i];
+		if (strcmp(d->name, name) == 0)
+			return d->id;
+	}
+	return -EINVAL;
+}
+
+int
+rte_event_dev_socket_id(uint8_t dev_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev)
+		return -EINVAL;
+
+	return dev->socket_id;
+}
+
+int
+rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev_info)
+		return -EINVAL;
+
+	*dev_info = dev->info;
+
+	return 0;
+}
+
+int
+rte_event_dev_configure(uint8_t dev_id, struct rte_event_dev_config *config)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+	int ret;
+
+	if (!dev || dev->configured || !config)
+		return -EINVAL;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->configure, -ENOTSUP);
+	ret = dev->ops->configure(dev, config);
+	if (ret)
+		return ret;
+
+	dev->configured = true;
+
+	return 0;
+}
+
+void
+rte_event_queue_default_conf_get(uint8_t dev_id,
+				 uint8_t queue_id,
+				 struct rte_event_queue_conf *queue_conf)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return;
+
+	RTE_FUNC_PTR_OR_RET(dev->ops->queue_default_conf_get);
+	return dev->ops->queue_default_conf_get(dev, queue_id, queue_conf);
+}
+
+int
+rte_event_queue_setup(uint8_t dev_id,
+		      uint8_t queue_id,
+		      const struct rte_event_queue_conf *queue_conf)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return 0;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->queue_setup, -ENOTSUP);
+	return dev->ops->queue_setup(dev, queue_id, queue_conf);
+}
+
+uint16_t
+rte_event_queue_count(uint8_t dev_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return 0;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->queue_count, -ENOTSUP);
+	return dev->ops->queue_count(dev);
+}
+
+uint8_t
+rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return 0;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->queue_priority, -ENOTSUP);
+	return dev->ops->queue_priority(dev, queue_id);
+}
+
+void
+rte_event_port_default_conf_get(uint8_t dev_id,
+				uint8_t port_id,
+				struct rte_event_port_conf *port_conf)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return;
+
+	RTE_FUNC_PTR_OR_RET(dev->ops->port_default_conf_get);
+	return dev->ops->port_default_conf_get(dev, port_id, port_conf);
+}
+
+int
+rte_event_port_setup(uint8_t dev_id,
+		     uint8_t port_id,
+		     const struct rte_event_port_conf *port_conf)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->port_setup, -ENOTSUP);
+	return dev->ops->port_setup(dev, port_id, port_conf);
+}
+
+uint8_t
+rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->port_dequeue_depth, -ENOTSUP);
+	return dev->ops->port_dequeue_depth(dev, port_id);
+}
+
+uint8_t
+rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->port_enqueue_depth, -ENOTSUP);
+	return dev->ops->port_enqueue_depth(dev, port_id);
+}
+
+uint8_t
+rte_event_port_count(uint8_t dev_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return 0;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->port_count, -ENOTSUP);
+	return dev->ops->port_count(dev);
+}
+
+int
+rte_event_dev_start(uint8_t dev_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->start, -ENOTSUP);
+	return dev->ops->start(dev);
+}
+
+void
+rte_event_dev_stop(uint8_t dev_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return;
+
+	RTE_FUNC_PTR_OR_RET(dev->ops->stop);
+	return dev->ops->stop(dev);
+}
+
+int
+rte_event_dev_close(uint8_t dev_id)
+{
+	int ret;
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->close, -ENOTSUP);
+	ret = dev->ops->close(dev);
+	if (ret)
+		return ret;
+
+	dev->configured = false;
+	return 0;
+}
+
+int
+rte_event_enqueue(uint8_t dev_id,
+		  uint8_t event_port_id,
+		  struct rte_event *ev,
+		  bool pin_event)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->enqueue, -ENOTSUP);
+	return dev->ops->enqueue(dev, event_port_id, ev, pin_event);
+}
+
+int
+rte_event_enqueue_burst(uint8_t dev_id, uint8_t event_port_id,
+			struct rte_event ev[], int num, bool pin_event)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->enqueue_burst, -ENOTSUP);
+	return dev->ops->enqueue_burst(dev, event_port_id, ev, num, pin_event);
+}
+
+uint64_t
+rte_event_dequeue_wait_time(uint8_t dev_id, uint64_t ns)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return 0;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->dequeue_wait_time, -ENOTSUP);
+	return dev->ops->dequeue_wait_time(dev, ns);
+}
+
+bool
+rte_event_dequeue(uint8_t dev_id, uint8_t event_port_id,
+		  struct rte_event *ev, uint64_t wait)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return false;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->dequeue, -ENOTSUP);
+	return dev->ops->dequeue(dev, event_port_id, ev, wait);
+}
+
+int
+rte_event_dequeue_burst(uint8_t dev_id, uint8_t event_port_id,
+			struct rte_event ev[], int num, uint64_t wait)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->dequeue_burst, -ENOTSUP);
+	return dev->ops->dequeue_burst(dev, event_port_id, ev, num, wait);
+}
+
+int
+rte_event_schedule(uint8_t dev_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->schedule, -ENOTSUP);
+	return dev->ops->schedule(dev);
+}
+
+void
+rte_event_release(uint8_t dev_id, uint8_t event_port_id, uint8_t index)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return;
+
+	RTE_FUNC_PTR_OR_RET(dev->ops->release);
+	dev->ops->release(dev, event_port_id, index);
+}
+
+int
+rte_event_port_link(uint8_t dev_id, uint8_t port_id,
+		struct rte_event_queue_link link[], int num)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->port_link, -ENOTSUP);
+	return dev->ops->port_link(dev, port_id, link, num);
+}
+
+int
+rte_event_port_unlink(uint8_t dev_id, uint8_t port_id, uint8_t queues[], int num)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->port_unlink, -ENOTSUP);
+	return dev->ops->port_unlink(dev, port_id, queues, num);
+}
+
+int
+rte_event_dev_stats_get(uint8_t dev_id, struct rte_event_dev_stats *stats)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return -1;
+
+	RTE_FUNC_PTR_OR_ERR_RET(dev->ops->stats_get, -ENOTSUP);
+	return dev->ops->stats_get(dev, stats);
+}
+
+void
+rte_event_dev_dump(FILE *f, uint8_t dev_id)
+{
+	struct rte_event_dev *dev = event_devs[dev_id];
+
+	if (!dev || !dev->configured)
+		return;
+
+	RTE_FUNC_PTR_OR_RET(dev->ops->dump);
+	dev->ops->dump(f, dev);
+}
diff --git a/lib/librte_eventdev/rte_eventdev.h b/lib/librte_eventdev/rte_eventdev.h
new file mode 100644
index 0000000..d0b5f7d
--- /dev/null
+++ b/lib/librte_eventdev/rte_eventdev.h
@@ -0,0 +1,1272 @@
+/*
+ *   BSD LICENSE
+ *
+ *   Copyright 2016 Cavium.
+ *   Copyright 2016 Intel Corporation.
+ *   Copyright 2016 NXP.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Cavium nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_EVENTDEV_H_
+#define _RTE_EVENTDEV_H_
+
+/**
+ * @file
+ *
+ * RTE Event Device API
+ *
+ * The Event Device API is composed of two parts:
+ *
+ * - The application-oriented Event API that includes functions to setup
+ *   an event device (configure it, setup its queues, ports and start it), to
+ *   establish the link between queues to port and to receive events, and so on.
+ *
+ * - The driver-oriented Event API that exports a function allowing
+ *   an event poll Mode Driver (PMD) to simultaneously register itself as
+ *   an event device driver.
+ *
+ * Event device components:
+ *
+ *                     +-----------------+
+ *                     | +-------------+ |
+ *        +-------+    | |    flow 0   | |
+ *        |Packet |    | +-------------+ |
+ *        |event  |    | +-------------+ |
+ *        |       |    | |    flow 1   | |event_port_link(port0, queue0)
+ *        +-------+    | +-------------+ |     |     +--------+
+ *        +-------+    | +-------------+ o-----v-----o        |dequeue +------+
+ *        |Crypto |    | |    flow n   | |           | event  +------->|Core 0|
+ *        |work   |    | +-------------+ o----+      | port 0 |        |      |
+ *        |done ev|    |  event queue 0  |    |      +--------+        +------+
+ *        +-------+    +-----------------+    |
+ *        +-------+                           |
+ *        |Timer  |    +-----------------+    |      +--------+
+ *        |expiry |    | +-------------+ |    +------o        |dequeue +------+
+ *        |event  |    | |    flow 0   | o-----------o event  +------->|Core 1|
+ *        +-------+    | +-------------+ |      +----o port 1 |        |      |
+ *       Event enqueue | +-------------+ |      |    +--------+        +------+
+ *     o-------------> | |    flow 1   | |      |
+ *        enqueue(     | +-------------+ |      |
+ *        queue_id,    |                 |      |    +--------+        +------+
+ *        flow_id,     | +-------------+ |      |    |        |dequeue |Core 2|
+ *        sched_type,  | |    flow n   | o-----------o event  +------->|      |
+ *        event_type,  | +-------------+ |      |    | port 2 |        +------+
+ *        subev_type,  |  event queue 1  |      |    +--------+
+ *        event)       +-----------------+      |    +--------+
+ *                                              |    |        |dequeue +------+
+ *        +-------+    +-----------------+      |    | event  +------->|Core n|
+ *        |Core   |    | +-------------+ o-----------o port n |        |      |
+ *        |(SW)   |    | |    flow 0   | |      |    +--------+        +--+---+
+ *        |event  |    | +-------------+ |      |                         |
+ *        +-------+    | +-------------+ |      |                         |
+ *            ^        | |    flow 1   | |      |                         |
+ *            |        | +-------------+ o------+                         |
+ *            |        | +-------------+ |                                |
+ *            |        | |    flow n   | |                                |
+ *            |        | +-------------+ |                                |
+ *            |        |  event queue n  |                                |
+ *            |        +-----------------+                                |
+ *            |                                                           |
+ *            +-----------------------------------------------------------+
+ *
+ *
+ *
+ * Event device: A hardware or software-based event scheduler.
+ *
+ * Event: A unit of scheduling that encapsulates a packet or other datatype
+ * like SW generated event from the core, Crypto work completion notification,
+ * Timer expiry event notification etc as well as metadata.
+ * The metadata includes flow ID, scheduling type, event priority, event_type,
+ * sub_event_type etc.
+ *
+ * Event queue: A queue containing events that are scheduled by the event dev.
+ * An event queue contains events of different flows associated with scheduling
+ * types, such as atomic, ordered, or parallel.
+ *
+ * Event port: An application's interface into the event dev for enqueue and
+ * dequeue operations. Each event port can be linked with one or more
+ * event queues for dequeue operations.
+ *
+ * By default, all the functions of the Event Device API exported by a PMD
+ * are lock-free functions which assume to not be invoked in parallel on
+ * different logical cores to work on the same target object. For instance,
+ * the dequeue function of a PMD cannot be invoked in parallel on two logical
+ * cores to operates on same  event port. Of course, this function
+ * can be invoked in parallel by different logical cores on different ports.
+ * It is the responsibility of the upper level application to enforce this rule.
+ *
+ * In all functions of the Event API, the Event device is
+ * designated by an integer >= 0 named the device identifier *dev_id*
+ *
+ * At the Event driver level, Event devices are represented by a generic
+ * data structure of type *rte_event_dev*.
+ *
+ * Event devices are dynamically registered during the PCI/SoC device probing
+ * phase performed at EAL initialization time.
+ * When an Event device is being probed, a *rte_event_dev* structure and
+ * a new device identifier are allocated for that device. Then, the
+ * event_dev_init() function supplied by the Event driver matching the probed
+ * device is invoked to properly initialize the device.
+ *
+ * The role of the device init function consists of resetting the hardware or
+ * software event driver implementations.
+ *
+ * If the device init operation is successful, the correspondence between
+ * the device identifier assigned to the new device and its associated
+ * *rte_event_dev* structure is effectively registered.
+ * Otherwise, both the *rte_event_dev* structure and the device identifier are
+ * freed.
+ *
+ * The functions exported by the application Event API to setup a device
+ * designated by its device identifier must be invoked in the following order:
+ *     - rte_event_dev_configure()
+ *     - rte_event_queue_setup()
+ *     - rte_event_port_setup()
+ *     - rte_event_port_link()
+ *     - rte_event_dev_start()
+ *
+ * Then, the application can invoke, in any order, the functions
+ * exported by the Event API to schedule events, dequeue events, enqueue events,
+ * change event queue(s) to event port [un]link establishment and so on.
+ *
+ * Application may use rte_event_[queue/port]_default_conf_get() to get the
+ * default configuration to set up an event queue or event port by
+ * overriding few default values.
+ *
+ * If the application wants to change the configuration (i.e. call
+ * rte_event_dev_configure(), rte_event_queue_setup(), or
+ * rte_event_port_setup()), it must call rte_event_dev_stop() first to stop the
+ * device and then do the reconfiguration before calling rte_event_dev_start()
+ * again. The schedule, enqueue and dequeue functions should not be invoked
+ * when the device is stopped.
+ *
+ * Finally, an application can close an Event device by invoking the
+ * rte_event_dev_close() function.
+ *
+ * Each function of the application Event API invokes a specific function
+ * of the PMD that controls the target device designated by its device
+ * identifier.
+ *
+ * For this purpose, all device-specific functions of an Event driver are
+ * supplied through a set of pointers contained in a generic structure of type
+ * *event_dev_ops*.
+ * The address of the *event_dev_ops* structure is stored in the *rte_event_dev*
+ * structure by the device init function of the Event driver, which is
+ * invoked during the PCI/SoC device probing phase, as explained earlier.
+ *
+ * In other words, each function of the Event API simply retrieves the
+ * *rte_event_dev* structure associated with the device identifier and
+ * performs an indirect invocation of the corresponding driver function
+ * supplied in the *event_dev_ops* structure of the *rte_event_dev* structure.
+ *
+ * For performance reasons, the address of the fast-path functions of the
+ * Event driver is not contained in the *event_dev_ops* structure.
+ * Instead, they are directly stored at the beginning of the *rte_event_dev*
+ * structure to avoid an extra indirect memory access during their invocation.
+ *
+ * RTE event device drivers do not use interrupts for enqueue or dequeue
+ * operation. Instead, Event drivers export Poll-Mode enqueue and dequeue
+ * functions to applications.
+ *
+ * An event driven based application has following typical workflow on fastpath:
+ * \code{.c}
+ *	while (1) {
+ *
+ *		rte_event_schedule(dev_id);
+ *
+ *		rte_event_dequeue(...);
+ *
+ *		(event processing)
+ *
+ *		rte_event_enqueue(...);
+ *	}
+ * \endcode
+ *
+ * The *schedule* operation is intended to do event scheduling, and the
+ * *dequeue* operation returns the scheduled events. An implementation
+ * is free to define the semantics between *schedule* and *dequeue*. For
+ * example, a system based on a hardware scheduler can define its
+ * rte_event_schedule() to be an NOOP, whereas a software scheduler can use
+ * the *schedule* operation to schedule events.
+ *
+ * The events are injected to event device through *enqueue* operation by
+ * event producers in the system. The typical event producers are ethdev
+ * subsystem for generating packet events, core(SW) for generating events based
+ * on different stages of application processing, cryptodev for generating
+ * crypto work completion notification etc
+ *
+ * The *dequeue* operation gets one or more events from the event ports.
+ * The application process the events and send to downstream event queue through
+ * rte_event_enqueue() if it is an intermediate stage of event processing, on
+ * the final stage, the application may send to different subsystem like ethdev
+ * to send the packet/event on the wire using ethdev rte_eth_tx_burst() API.
+ *
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdbool.h>
+
+#include <rte_pci.h>
+#include <rte_dev.h>
+#include <rte_devargs.h>
+#include <rte_errno.h>
+
+/**
+ * Get the total number of event devices that have been successfully
+ * initialised.
+ *
+ * @return
+ *   The total number of usable event devices.
+ */
+uint8_t
+rte_event_dev_count(void);
+
+/**
+ * Get the device identifier for the named event device.
+ *
+ * @param name
+ *   Event device name to select the event device identifier.
+ *
+ * @return
+ *   Returns event device identifier on success.
+ *   - <0: Failure to find named event device.
+ */
+int8_t
+rte_event_dev_get_dev_id(const char *name);
+
+/**
+ * Return the NUMA socket to which a device is connected.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @return
+ *   The NUMA socket id to which the device is connected or
+ *   a default of zero if the socket could not be determined.
+ *   - -1: dev_id value is out of range.
+ */
+int
+rte_event_dev_socket_id(uint8_t dev_id);
+
+/* Event device capability bitmap flags */
+#define RTE_EVENT_DEV_CAP_QUEUE_QOS        (1 << 0)
+/**< Event scheduling prioritization is based on the priority associated with
+ *  each event queue.
+ *
+ *  \see rte_event_queue_setup(), RTE_EVENT_QUEUE_PRIORITY_NORMAL
+ */
+#define RTE_EVENT_DEV_CAP_EVENT_QOS        (1 << 1)
+/**< Event scheduling prioritization is based on the priority associated with
+ *  each event. Priority of each event is supplied in *rte_event* structure
+ *  on each enqueue operation.
+ *
+ *  \see rte_event_enqueue()
+ */
+
+/**
+ * Event device information
+ */
+struct rte_event_dev_info {
+	const char *driver_name;	/**< Event driver name */
+	struct rte_pci_device *pci_dev;	/**< PCI information */
+	uint32_t min_dequeue_wait_ns;
+	/**< Minimum supported global dequeue wait delay(ns) by this device */
+	uint32_t max_dequeue_wait_ns;
+	/**< Maximum supported global dequeue wait delay(ns) by this device */
+	uint32_t dequeue_wait_ns;
+	/**< Configured global dequeue wait delay(ns) for this device */
+	uint8_t max_event_queues;
+	/**< Maximum event_queues supported by this device */
+	uint32_t max_event_queue_flows;
+	/**< Maximum supported flows in an event queue by this device*/
+	uint8_t max_event_queue_priority_levels;
+	/**< Maximum number of event queue priority levels by this device.
+	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
+	 */
+	uint8_t nb_event_queues;
+	/**< Configured number of event queues for this device */
+	uint8_t max_event_priority_levels;
+	/**< Maximum number of event priority levels by this device.
+	 * Valid when the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability
+         */
+	uint8_t max_event_ports;
+	/**< Maximum number of event ports supported by this device */
+	uint8_t nb_event_ports;
+	/**< Configured number of event ports for this device */
+	uint8_t max_event_port_dequeue_queue_depth;
+	/**< Maximum dequeue queue depth for any event port.
+	 * Implementations can schedule N events at a time to an event port.
+	 * A device that does not support bulk dequeue will set this as 1.
+	 * \see rte_event_port_setup()
+	 */
+	uint32_t max_event_port_enqueue_queue_depth;
+	/**< Maximum enqueue queue depth for any event port. Implementations
+	 * can batch N events at a time to enqueue through event port
+	 * \see rte_event_port_setup()
+	 */
+	int32_t max_num_events;
+	/**< A *closed system* event dev has a limit on the number of events it
+	 * can manage at a time. An *open system* event dev does not have a
+	 * limit and will specify this as -1.
+	 */
+	uint32_t event_dev_cap;
+	/**< Event device capabilities(RTE_EVENT_DEV_CAP_)*/
+};
+
+/**
+ * Retrieve the contextual information of an event device.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ *
+ * @param[out] dev_info
+ *   A pointer to a structure of type *rte_event_dev_info* to be filled with the
+ *   contextual information of the device.
+ *
+ * @return
+ *   Returns event device identifier on success.
+ *   - <0: Failure to find event device with dev_id.
+ */
+int
+rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info);
+
+/* Event device configuration bitmap flags */
+#define RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT (1 << 0)
+/**< Override the global *dequeue_wait_ns* and use per dequeue wait in ns.
+ *  \see rte_event_dequeue_wait_time(), rte_event_dequeue()
+ */
+
+/** Event device configuration structure */
+struct rte_event_dev_config {
+	uint32_t dequeue_wait_ns;
+	/**< rte_event_dequeue() wait for *dequeue_wait_ns* ns on this device.
+	 * This value should be in the range of *min_dequeue_wait_ns* and
+	 * *max_dequeue_wait_ns* which previously provided in
+	 * rte_event_dev_info_get()
+	 * \see RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT
+	 */
+	int32_t nb_events_limit;
+	/**< Applies to *closed system* event dev only. This field indicates a
+	 * limit to ethdev-like devices to limit the number of events injected
+	 * into the system to not overwhelm core-to-core events.
+	 * This value cannot exceed the *max_num_events* which previously
+	 * provided in rte_event_dev_info_get()
+	 */
+	uint8_t nb_event_queues;
+	/**< Number of event queues to configure on this device.
+	 * This value cannot exceed the *max_event_queues* which previously
+	 * provided in rte_event_dev_info_get()
+	 */
+	uint8_t nb_event_ports;
+	/**< Number of event ports to configure on this device.
+	 * This value cannot exceed the *max_event_ports* which previously
+	 * provided in rte_event_dev_info_get()
+	 */
+	uint32_t event_dev_cfg;
+	/**< Event device config flags(RTE_EVENT_DEV_CFG_)*/
+};
+
+/**
+ * Configure an event device.
+ *
+ * This function must be invoked first before any other function in the
+ * API. This function can also be re-invoked when a device is in the
+ * stopped state.
+ *
+ * The caller may use rte_event_dev_info_get() to get the capability of each
+ * resources available for this event device.
+ *
+ * @param dev_id
+ *   The identifier of the device to configure.
+ * @param config
+ *   The event device configuration structure.
+ *
+ * @return
+ *   - 0: Success, device configured.
+ *   - <0: Error code returned by the driver configuration function.
+ */
+int
+rte_event_dev_configure(uint8_t dev_id, struct rte_event_dev_config *config);
+
+
+/* Event queue specific APIs */
+
+#define RTE_EVENT_QUEUE_PRIORITY_HIGHEST   0
+/**< Highest event queue priority */
+#define RTE_EVENT_QUEUE_PRIORITY_NORMAL    128
+/**< Normal event queue priority */
+#define RTE_EVENT_QUEUE_PRIORITY_LOWEST    255
+/**< Lowest event queue priority */
+
+/* Event queue configuration bitmap flags */
+#define RTE_EVENT_QUEUE_CFG_TYPE_MASK       (3ULL << 0) /**< Mask CFG types */
+#define RTE_EVENT_QUEUE_CFG_ALL_TYPES       (0ULL << 0) /**< Enable all types */
+#define RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY     (1ULL << 0) /**< Atomic scheduling only */
+#define RTE_EVENT_QUEUE_CFG_ORDERED_ONLY    (2ULL << 0) /**< Ordered scheduling only */
+#define RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY   (3ULL << 0) /**< Parallel scheduling only */
+#define RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER (1ULL << 2)
+/**< This event queue links only to a single event port.
+ *
+ *  \see rte_event_port_setup(), rte_event_port_link()
+ */
+
+/** Event queue configuration structure */
+struct rte_event_queue_conf {
+	uint32_t nb_atomic_flows;
+	/**< The maximum number of active flows this queue can track at any
+	 * given time. The value must be in the range of
+	 * [1 - max_event_queue_flows)] which previously supplied
+	 * to rte_event_dev_configure().
+	 */
+	uint32_t nb_atomic_order_sequences;
+	/**< The maximum number of outstanding events waiting to be (egress-)
+	 * reordered by this queue. In other words, the number of entries in
+	 * this queue’s reorder buffer.The value must be in the range of
+	 * [1 - max_event_queue_flows)] which previously supplied
+	 * to rte_event_dev_configure().
+	 */
+	uint32_t event_queue_cfg; /**< Queue config flags(EVENT_QUEUE_CFG_) */
+	uint8_t priority;
+	/**< Priority for this event queue relative to other event queues.
+	 * The requested priority should in the range of
+	 * [RTE_EVENT_QUEUE_PRIORITY_HIGHEST, RTE_EVENT_QUEUE_PRIORITY_LOWEST].
+	 * The implementation shall normalize the requested priority to
+	 * event device supported priority value.
+	 * Valid when the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability
+	 */
+};
+
+/**
+ * Retrieve the default configuration information of an event queue designated
+ * by its *queue_id* from the event driver for an event device.
+ *
+ * This function intended to be used in conjunction with rte_event_queue_setup()
+ * where caller needs to set up the queue by overriding few default values.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param queue_id
+ *   The index of the event queue to get the configuration information.
+ *   The value must be in the range [0, nb_event_queues - 1]
+ *   previously supplied to rte_event_dev_configure().
+ * @param[out] queue_conf
+ *   The pointer to the default event queue configuration data.
+ *
+ * \see rte_event_queue_setup()
+ *
+ */
+void
+rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
+				 struct rte_event_queue_conf *queue_conf);
+
+/**
+ * Allocate and set up an event queue for an event device.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param queue_id
+ *   The index of the event queue to setup. The value must be in the range
+ *   [0, nb_event_queues - 1] previously supplied to rte_event_dev_configure().
+ * @param queue_conf
+ *   The pointer to the configuration data to be used for the event queue.
+ *   NULL value is allowed, in which case default configuration	used.
+ *
+ * \see rte_event_queue_default_conf_get()
+ *
+ * @return
+ *   - 0: Success, event queue correctly set up.
+ *   - <0: event queue configuration failed
+ */
+int
+rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
+		      const struct rte_event_queue_conf *queue_conf);
+
+/**
+ * Get the number of event queues on a specific event device
+ *
+ * @param dev_id
+ *   Event device identifier.
+ * @return
+ *   - The number of configured event queues
+ */
+uint16_t
+rte_event_queue_count(uint8_t dev_id);
+
+/**
+ * Get the priority of the event queue on a specific event device
+ *
+ * @param dev_id
+ *   Event device identifier.
+ * @param queue_id
+ *   Event queue identifier.
+ * @return
+ *   - If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then the
+ *    configured priority of the event queue in
+ *    [RTE_EVENT_QUEUE_PRIORITY_HIGHEST, RTE_EVENT_QUEUE_PRIORITY_LOWEST] range
+ *    else the value one
+ */
+uint8_t
+rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id);
+
+/* Event port specific APIs */
+
+/** Event port configuration structure */
+struct rte_event_port_conf {
+	int32_t new_event_threshold;
+	/**< A backpressure threshold for new event enqueues on this port.
+	 * Use for *closed system* event dev where event capacity is limited,
+	 * and cannot exceed the capacity of the event dev.
+	 * Configuring ports with different thresholds can make higher priority
+	 * traffic less likely to  be backpressured.
+	 * For example, a port used to inject NIC Rx packets into the event dev
+	 * can have a lower threshold so as not to overwhelm the device,
+	 * while ports used for worker pools can have a higher threshold.
+	 */
+	uint8_t dequeue_queue_depth;
+	/**< Configure number of bulk dequeues for this event port.
+	 * This value cannot exceed the *max_event_port_dequeue_queue_depth*
+	 * which previously supplied to rte_event_dev_configure()
+	 */
+	uint8_t enqueue_queue_depth;
+	/**< Configure number of bulk enqueues for this event port.
+	 * This value cannot exceed the *max_event_port_enqueue_queue_depth*
+	 * which previously supplied to rte_event_dev_configure()
+	 */
+};
+
+/**
+ * Retrieve the default configuration information of an event port designated
+ * by its *port_id* from the event driver for an event device.
+ *
+ * This function intended to be used in conjunction with rte_event_port_setup()
+ * where caller needs to set up the port by overriding few default values.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param port_id
+ *   The index of the event port to get the configuration information.
+ *   The value must be in the range [0, nb_event_ports - 1]
+ *   previously supplied to rte_event_dev_configure().
+ * @param[out] port_conf
+ *   The pointer to the default event port configuration data
+ *
+ * \see rte_event_port_setup()
+ *
+ */
+void
+rte_event_port_default_conf_get(uint8_t dev_id, uint8_t port_id,
+				struct rte_event_port_conf *port_conf);
+
+/**
+ * Allocate and set up an event port for an event device.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param port_id
+ *   The index of the event port to setup. The value must be in the range
+ *   [0, nb_event_ports - 1] previously supplied to rte_event_dev_configure().
+ * @param port_conf
+ *   The pointer to the configuration data to be used for the queue.
+ *   NULL value is allowed, in which case default configuration	used.
+ *
+ * \see rte_event_port_default_conf_get()
+ *
+ * @return
+ *   - 0: Success, event port correctly set up.
+ *   - <0: Port configuration failed
+ *   - (-EDQUOT) Quota exceeded(Application tried to link the queue configured
+ *   with RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER to more than one event ports)
+ */
+int
+rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
+		     const struct rte_event_port_conf *port_conf);
+
+/**
+ * Get the number of dequeue queue depth configured for event port designated
+ * by its *port_id* on a specific event device
+ *
+ * @param dev_id
+ *   Event device identifier.
+ * @param port_id
+ *   Event port identifier.
+ * @return
+ *   - The number of configured dequeue queue depth
+ *
+ * \see rte_event_dequeue_burst()
+ */
+uint8_t
+rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id);
+
+/**
+ * Get the number of enqueue queue depth configured for event port designated
+ * by its *port_id* on a specific event device
+ *
+ * @param dev_id
+ *   Event device identifier.
+ * @param port_id
+ *   Event port identifier.
+ * @return
+ *   - The number of configured enqueue queue depth
+ *
+ * \see rte_event_enqueue_burst()
+ */
+uint8_t
+rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id);
+
+/**
+ * Get the number of ports on a specific event device
+ *
+ * @param dev_id
+ *   Event device identifier.
+ * @return
+ *   - The number of configured ports
+ */
+uint8_t
+rte_event_port_count(uint8_t dev_id);
+
+/**
+ * Start an event device.
+ *
+ * The device start step is the last one and consists of setting the event
+ * queues to start accepting the events and schedules to event ports.
+ *
+ * On success, all basic functions exported by the API (event enqueue,
+ * event dequeue and so on) can be invoked.
+ *
+ * @param dev_id
+ *   Event device identifier
+ * @return
+ *   - 0: Success, device started.
+ *   - <0: Error code of the driver device start function.
+ */
+int
+rte_event_dev_start(uint8_t dev_id);
+
+/**
+ * Stop an event device. The device can be restarted with a call to
+ * rte_event_dev_start()
+ *
+ * @param dev_id
+ *   Event device identifier.
+ */
+void
+rte_event_dev_stop(uint8_t dev_id);
+
+/**
+ * Close an event device. The device cannot be restarted!
+ *
+ * @param dev_id
+ *   Event device identifier
+ *
+ * @return
+ *  - 0 on successfully closing device
+ *  - <0 on failure to close device
+ */
+int
+rte_event_dev_close(uint8_t dev_id);
+
+/* Scheduler type definitions */
+#define RTE_SCHED_TYPE_ORDERED		0
+/**< Ordered scheduling
+ *
+ * Events from an ordered flow of an event queue can be scheduled to multiple
+ * ports for concurrent processing while maintaining the original event order.
+ * This scheme enables the user to achieve high single flow throughput by
+ * avoiding SW synchronization for ordering between ports which bound to cores.
+ *
+ * The source flow ordering from an event queue is maintained when events are
+ * enqueued to their destination queue within the same ordered flow context.
+ * An event port holds the context until application call rte_event_dequeue()
+ * from the same port, which implicitly releases the context.
+ * User may allow the scheduler to release the context earlier than that
+ * by calling rte_event_release()
+ *
+ * Events from the source queue appear in their original order when dequeued
+ * from a destination queue.
+ * Event ordering is based on the received event(s), but also other
+ * (newly allocated or stored) events are ordered when enqueued within the same
+ * ordered context. Events not enqueued (e.g. released or stored) within the
+ * context are  considered missing from reordering and are skipped at this time
+ * (but can be ordered again within another context).
+ *
+ * \see rte_event_dequeue(), rte_event_release()
+ */
+
+#define RTE_SCHED_TYPE_ATOMIC		1
+/**< Atomic scheduling
+ *
+ * Events from an atomic flow of an event queue can be scheduled only to a
+ * single port at a time. The port is guaranteed to have exclusive (atomic)
+ * access to the associated flow context, which enables the user to avoid SW
+ * synchronization. Atomic flows also help to maintain event ordering
+ * since only one port at a time can process events from a flow of an
+ * event queue.
+ *
+ * The atomic queue synchronization context is dedicated to the port until
+ * application call rte_event_dequeue() from the same port, which implicitly
+ * releases the context. User may allow the scheduler to release the context
+ * earlier than that by calling rte_event_release()
+ *
+ * \see rte_event_dequeue(), rte_event_release()
+ */
+
+#define RTE_SCHED_TYPE_PARALLEL		2
+/**< Parallel scheduling
+ *
+ * The scheduler performs priority scheduling, load balancing, etc. functions
+ * but does not provide additional event synchronization or ordering.
+ * It is free to schedule events from a single parallel flow of an event queue
+ * to multiple events ports for concurrent processing.
+ * The application is responsible for flow context synchronization and
+ * event ordering (SW synchronization).
+ */
+
+/* Event types to classify the event source */
+#define RTE_EVENT_TYPE_ETHDEV		0x0
+/**< The event generated from ethdev subsystem */
+#define RTE_EVENT_TYPE_CRYPTODEV	0x1
+/**< The event generated from crypodev subsystem */
+#define RTE_EVENT_TYPE_TIMERDEV		0x2
+/**< The event generated from timerdev subsystem */
+#define RTE_EVENT_TYPE_CORE		0x3
+/**< The event generated from core.
+ * Application may use *sub_event_type* to further classify the event
+ */
+#define RTE_EVENT_TYPE_MAX		0x10
+/**< Maximum number of event types */
+
+/* Event priority */
+#define RTE_EVENT_PRIORITY_HIGHEST      0
+/**< Highest event priority */
+#define RTE_EVENT_PRIORITY_NORMAL       128
+/**< Normal event priority */
+#define RTE_EVENT_PRIORITY_LOWEST       255
+/**< Lowest event priority */
+
+
+#define RTE_EVENT_OP_NEW                0 /**< New event without previous ctx */
+#define RTE_EVENT_OP_FORWARD            1 /**< Re-enqueue prev dequeued event */
+#define RTE_EVENT_OP_DROP               2 /**< Discard context for event */
+
+/**
+ * The generic *rte_event* structure to hold the event attributes
+ * for dequeue and enqueue operation
+ */
+struct rte_event {
+	/** WORD0 */
+	union {
+		uint64_t u64;
+		/** Event attributes for dequeue or enqueue operation */
+		struct {
+			uint32_t flow_id:24;
+			/**< Targeted flow identifier for the enqueue and
+			 * dequeue operation.
+			 * The value must be in the range of
+			 * [1 - max_event_queue_flows)] which
+			 * previously supplied to rte_event_dev_configure().
+			 */
+			uint32_t operation:6;
+			/**< The type of event being enqueued - new/forward/etc
+			 *  This field is not preserved across an instance and
+			 *  is undefined on dequeue.
+			 */
+			uint32_t  sched_type:2;
+			/**< Scheduler synchronization type (RTE_SCHED_TYPE_)
+			 * associated with flow id on a given event queue
+			 * for the enqueue and dequeue operation.
+			 */
+			uint8_t queue_id:8;
+			/**< Targeted event queue identifier for the enqueue or
+			 * dequeue operation.
+			 * The value must be in the range of
+			 * [0, nb_event_queues - 1] which previously supplied to
+			 * rte_event_dev_configure().
+			 */
+			uint8_t  event_type;
+			/**< Event type to classify the event source. */
+			uint8_t  sub_event_type;
+			/**< Sub-event types based on the event source.
+			 * \see RTE_EVENT_TYPE_CORE
+			 */
+			uint8_t  priority;
+			/**< Event priority relative to other events in the
+			 * event queue. The requested priority should in the
+			 * range of  [RTE_EVENT_PRIORITY_HIGHEST,
+			 * RTE_EVENT_PRIORITY_LOWEST].
+			 * The implementation shall normalize the requested
+			 * priority to supported priority value.
+			 * Valid when the device has RTE_EVENT_DEV_CAP_EVENT_QOS
+			 * capability.
+			 */
+		};
+	};
+	/** WORD1 */
+	union {
+		uintptr_t event;
+		/**< Opaque event pointer */
+		struct rte_mbuf *mbuf;
+		/**< mbuf pointer if dequeued event is associated with mbuf */
+	};
+};
+
+/**
+ * Schedule one or more events in the event dev.
+ *
+ * An event dev implementation may define this is a NOOP, for instance if
+ * the event dev performs its scheduling in hardware.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ */
+int
+rte_event_schedule(uint8_t dev_id);
+
+/**
+ * Enqueue the event object supplied in the *rte_event* structure on an
+ * event device designated by its *dev_id* through the event port specified by
+ * *port_id*. The event object specifies the event queue on which this
+ * event will be enqueued.
+ *
+ * @param dev_id
+ *   Event device identifier.
+ * @param port_id
+ *   The identifier of the event port.
+ * @param ev
+ *   Pointer to struct rte_event
+ *
+ * @param pin_event
+ *   Hint to the scheduler that the event can be pinned to the same port for
+ *   the next scheduling stage. For implementations that support it, this
+ *   allows the same core to process the next stage in the pipeline for a given
+ *   event, taking advantage of cache locality. The pinned event will be
+ *   received through rte_event_dequeue(). This is a hint and the event is
+ *   not guaranteed to be pinned to the port. This hint is valid only when the
+ *   event is dequeued with rte_event_dequeue() followed by rte_event_enqueue().
+ *
+ * @return
+ *  - 0 on success
+ *  - <0 on failure. Failure can occur if the event port's output queue is
+ *     backpressured, for instance.
+ */
+int
+rte_event_enqueue(uint8_t dev_id, uint8_t port_id, struct rte_event *ev,
+		  bool pin_event);
+
+/**
+ * Enqueue a burst of events objects supplied in *rte_event* structure on an
+ * event device designated by its *dev_id* through the event port specified by
+ * *port_id*. Each event object specifies the event queue on which it
+ * will be enqueued.
+ *
+ * The rte_event_enqueue_burst() function is invoked to enqueue
+ * multiple event objects.
+ * It is the burst variant of rte_event_enqueue() function.
+ *
+ * The *num* parameter is the number of event objects to enqueue which are
+ * supplied in the *ev* array of *rte_event* structure.
+ *
+ * The rte_event_enqueue_burst() function returns the number of
+ * events objects it actually enqueued. A return value equal to *num* means
+ * that all event objects have been enqueued.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param port_id
+ *   The identifier of the event port.
+ * @param ev
+ *   An array of *num* pointers to *rte_event* structure
+ *   which contain the event object enqueue operations to be processed.
+ * @param num
+ *   The number of event objects to enqueue, typically number of
+ *   rte_event_port_enqueue_depth() available for this port.
+ * @param pin_event
+ *   Hint to the scheduler that the event can be pinned to the same port for
+ *   the next scheduling stage. For implementations that support it, this
+ *   allows the same core to process the next stage in the pipeline for a given
+ *   event, taking advantage of cache locality. The pinned event will be
+ *   received through rte_event_dequeue(). This is a hint and the event is
+ *   not guaranteed to be pinned to the port. This hint is valid only when the
+ *   event is dequeued with rte_event_dequeue() followed by rte_event_enqueue().
+ *
+ * @return
+ *   The number of event objects actually enqueued on the event device. The
+ *   return value can be less than the value of the *num* parameter when the
+ *   event devices queue is full or if invalid parameters are specified in a
+ *   *rte_event*. If return value is less than *num*, the remaining events at
+ *   the end of ev[] are not consumed, and the caller has to take care of them.
+ *
+ * \see rte_event_enqueue(), rte_event_port_enqueue_depth()
+ */
+int
+rte_event_enqueue_burst(uint8_t dev_id, uint8_t port_id,
+			struct rte_event ev[], int num, bool pin_event);
+
+/**
+ * Converts nanoseconds to *wait* value for rte_event_dequeue()
+ *
+ * If the device is configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT flag then
+ * application can use this function to convert wait value in nanoseconds to
+ * implementations specific wait value supplied in rte_event_dequeue()
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param ns
+ *   Wait time in nanosecond
+ *
+ * @return
+ * Value for the *wait* parameter in rte_event_dequeue() function
+ *
+ * \see rte_event_dequeue(), RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT
+ * \see rte_event_dev_configure()
+ *
+ */
+uint64_t
+rte_event_dequeue_wait_time(uint8_t dev_id, uint64_t ns);
+
+/**
+ * Dequeue an event from the event port specified by *port_id* on the
+ * event device designated by its *dev_id*.
+ *
+ * rte_event_dequeue() does not dictate the specifics of scheduling algorithm as
+ * each eventdev driver may have different criteria to schedule an event.
+ * However, in general, from an application perspective scheduler may use the
+ * following scheme to dispatch an event to the port.
+ *
+ * 1) Selection of event queue based on
+ *   a) The list of event queues are linked to the event port.
+ *   b) If the device has RTE_EVENT_DEV_CAP_QUEUE_QOS capability then event
+ *   queue selection from list is based on event queue priority relative to
+ *   other event queue supplied as *priority* in rte_event_queue_setup()
+ *   c) If the device has RTE_EVENT_DEV_CAP_EVENT_QOS capability then event
+ *   queue selection from the list is based on event priority supplied as
+ *   *priority* in rte_event_enqueue_burst()
+ * 2) Selection of event
+ *   a) The number of flows available in selected event queue.
+ *   b) Schedule type method associated with the event
+ *
+ * On a successful dequeue, the event port holds flow id and schedule type
+ * context associated with the dispatched event. The context is automatically
+ * released in the next rte_event_dequeue() invocation, or rte_event_release()
+ * can be called to release the context early.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param port_id
+ *   The identifier of the event port.
+ * @param[out] ev
+ *   Pointer to struct rte_event. On successful event dispatch, implementation
+ *   updates the event attributes.
+ *
+ * @param wait
+ *   0 - no-wait, returns immediately if there is no event.
+ *   >0 - wait for the event, if the device is configured with
+ *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT then this function will wait until
+ *   the event available or *wait* time.
+ *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT
+ *   then this function will wait until the event available or *dequeue_wait_ns*
+ *   ns which was previously supplied to rte_event_dev_configure()
+ *
+ * @return
+ * When true, a valid event has been dispatched by the scheduler.
+ *
+ */
+bool
+rte_event_dequeue(uint8_t dev_id, uint8_t port_id,
+		  struct rte_event *ev, uint64_t wait);
+
+/**
+ * Dequeue a burst of events objects from the event port designated by its
+ * *event_port_id*, on an event device designated by its *dev_id*.
+ *
+ * The rte_event_dequeue_burst() function is invoked to dequeue
+ * multiple event objects. It is the burst variant of rte_event_dequeue()
+ * function.
+ *
+ * The *num* parameter is the maximum number of event objects to dequeue which
+ * are returned in the *ev* array of *rte_event* structure.
+ *
+ * The rte_event_dequeue_burst() function returns the number of
+ * events objects it actually dequeued. A return value equal to
+ * *num* means that all event objects have been dequeued.
+ *
+ * The number of events dequeued is the number of scheduler contexts held by
+ * this port. These contexts are automatically released in the next
+ * rte_event_dequeue() invocation, or rte_event_release() can be called once
+ * per event to release the contexts early.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param port_id
+ *   The identifier of the event port.
+ * @param ev
+ *   An array of *num* *rte_event* structures which is populated with the
+ *   dequeued event objects.
+ *
+ * @param num
+ *   The maximum number of event objects to dequeue, typically number of
+ *   rte_event_port_dequeue_depth() available for this port.
+ *
+ * @param wait
+ *   0 - no-wait, returns immediately if there is no event.
+ *   >0 - wait for the event, if the device is configured with
+ *   RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT then this function will wait until the
+ *   event available or *wait* time.
+ *   if the device is not configured with RTE_EVENT_DEV_CFG_PER_DEQUEUE_WAIT
+ *   then this function will wait until the event available or *dequeue_wait_ns*
+ *   ns which was previously supplied to rte_event_dev_configure()
+ *
+ * @return
+ * The number of event objects actually dequeued from the port. The return
+ * value can be less than the value of the *num* parameter when the
+ * event port's queue is not full.
+ *
+ * \see rte_event_dequeue(), rte_event_port_dequeue_depth()
+ */
+int
+rte_event_dequeue_burst(uint8_t dev_id, uint8_t port_id,
+			struct rte_event *ev, int num, uint64_t wait);
+
+/**
+ * Release the current flow context associated with a schedule type which
+ * dequeued from a given event queue though the event port designated by
+ * its *port_id*
+ *
+ * If current flow's scheduler type method is *RTE_SCHED_TYPE_ATOMIC*
+ * then this function hints the scheduler that the user has completed critical
+ * section processing in the current atomic context.
+ * The scheduler is now allowed to schedule events from the same flow from
+ * an event queue to another port. However, the context may be still held
+ * until the next rte_event_dequeue() or rte_event_dequeue_burst() call, this
+ * call allows but does not force the scheduler to release the context early.
+ *
+ * Early atomic context release may increase parallelism and thus system
+ * performance, but the user needs to design carefully the split into critical
+ * vs non-critical sections.
+ *
+ * If current flow's scheduler type method is *RTE_SCHED_TYPE_ORDERED*
+ * then this function hints the scheduler that the user has done all that need
+ * to maintain event order in the current ordered context.
+ * The scheduler is allowed to release the ordered context of this port and
+ * avoid reordering any following enqueues.
+ *
+ * Early ordered context release may increase parallelism and thus system
+ * performance.
+ *
+ * If current flow's scheduler type method is *RTE_SCHED_TYPE_PARALLEL*
+ * or no scheduling context is held then this function may be an NOOP,
+ * depending on the implementation.
+ *
+ * If multiple events are dequeued with rte_event_dequeue_burst(),
+ * rte_event_release() will release each flow context associated with a
+ * schedule type of an event though *index*, it denotes the order in
+ * which it was dequeued with rte_event_dequeue_burst()
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param port_id
+ *   The identifier of the event port.
+ * @param index
+ *   The index of the event that dequeued with rte_event_dequeue_burst()
+ *   which needs to release. The value zero used if the event dequeued with
+ *   rte_event_dequeue()
+ *
+ *  \see rte_event_dequeue(), rte_event_dequeue_burst()
+ */
+void
+rte_event_release(uint8_t dev_id, uint8_t port_id, uint8_t index);
+
+#define RTE_EVENT_QUEUE_SERVICE_PRIORITY_HIGHEST  0
+/**< Highest event queue servicing priority */
+#define RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL   128
+/**< Normal event queue servicing priority */
+#define RTE_EVENT_QUEUE_SERVICE_PRIORITY_LOWEST   255
+/**< Lowest event queue servicing priority */
+
+/** Structure to hold the queue to port link establishment attributes */
+struct rte_event_queue_link {
+	uint8_t queue_id;
+	/**< Event queue identifier to select the source queue to link */
+	uint8_t priority;
+	/**< The priority of the event queue for this event port.
+	 * The priority defines the event port's servicing priority for
+	 * event queue, which may be ignored by an implementation.
+	 * The requested priority should in the range of
+	 * [RTE_EVENT_QUEUE_SERVICE_PRIORITY_HIGHEST,
+	 * RTE_EVENT_QUEUE_SERVICE_PRIORITY_LOWEST].
+	 * The implementation shall normalize the requested priority to
+	 * implementation supported priority value.
+	 */
+};
+
+/**
+ * Link multiple source event queues supplied in *rte_event_queue_link*
+ * structure as *queue_id* to the destination event port designated by its
+ * *port_id* on the event device designated by its *dev_id*.
+ *
+ * The link establishment shall enable the event port *port_id* from
+ * receiving events from the specified event queue *queue_id*
+ *
+ * An event queue may link to one or more event ports.
+ * The number of links can be established from an event queue to event port is
+ * implementation defined.
+ *
+ * Event queue(s) to event port link establishment can be changed at runtime
+ * without re-configuring the device to support scaling and to reduce the
+ * latency of critical work by establishing the link with more event ports
+ * at runtime.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ *
+ * @param port_id
+ *   Event port identifier to select the destination port to link.
+ *
+ * @param link
+ *   An array of *num* pointers to *rte_event_queue_link* structure
+ *   which contain the event queue to event port link establishment attributes.
+ *   NULL value is allowed, in which case this function links all the configured
+ *   event queues *nb_event_queues* which previously supplied to
+ *   rte_event_dev_configure() to the event port *port_id* with normal servicing
+ *   priority(RTE_EVENT_QUEUE_SERVICE_PRIORITY_NORMAL).
+ *
+ * @param num
+ *   The number of links to establish
+ *
+ * @return
+ * The number of links actually established on the event device. The return
+ * value can be less than the value of the *num* parameter when the
+ * implementation has the limitation on specific queue to port link
+ * establishment or if invalid parameters are specified
+ * in a *rte_event_queue_link*.
+ * If the return value is less than *num*, the remaining links at the end of
+ * link[] are not established, and the caller has to take care of them.
+ * If return value is less than *num* then implementation shall update the
+ * rte_errno accordingly, Possible rte_errno values are
+ * (-EDQUOT) Quota exceeded(Application tried to link the queue configured with
+ *  RTE_EVENT_QUEUE_CFG_SINGLE_CONSUMER to more than one event ports)
+ * (-EINVAL) Invalid parameter
+ *
+ */
+int
+rte_event_port_link(uint8_t dev_id, uint8_t port_id,
+		    struct rte_event_queue_link link[], int num);
+
+/**
+ * Unlink multiple source event queues supplied in *queues* from the destination
+ * event port designated by its *port_id* on the event device designated
+ * by its *dev_id*.
+ *
+ * The unlink establishment shall disable the event port *port_id* from
+ * receiving events from the specified event queue *queue_id*
+ *
+ * Event queue(s) to event port unlink establishment can be changed at runtime
+ * without re-configuring the device.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ *
+ * @param port_id
+ *   Event port identifier to select the destination port to unlink.
+ *
+ * @param queues
+ *   An array of *num* event queues to be unlinked from the event port.
+ *   NULL value is allowed, in which case this function unlinks all the
+ *   event queue(s) from the event port *port_id*.
+ *
+ * @param num
+ *   The number of unlinks to establish
+ *
+ * @return
+ * The number of unlinks actually established on the event device. The return
+ * value can be less than the value of the *num* parameter when the
+ * implementation has the limitation on specific queue to port unlink
+ * establishment or if invalid parameters are specified.
+ * If the return value is less than *num*, the remaining queues at the end of
+ * queues[] are not established, and the caller has to take care of them.
+ * If return value is less than *num* then implementation shall update the
+ * rte_errno accordingly, Possible rte_errno values are
+ * (-EINVAL) Invalid parameter
+ *
+ */
+int
+rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
+		    uint8_t queues[], int num);
+
+#define RTE_EVENT_DEV_MAX_PORTS 256   /**< Max number of ports for an instance */
+#define RTE_EVENT_DEV_MAX_QUEUES 256  /**< Max number of queues for an instance */
+
+/**
+ * Struct that contains the general statistics of the eventdev instance.
+ */
+struct rte_event_dev_stats {
+	uint64_t rx_pkts;       /**< Total packets received */
+	uint64_t rx_dropped;    /**< Total packets dropped (Eg Invalid QID) */
+	uint64_t tx_pkts;       /**< Total packets transmitted */
+
+	/**> Packets received on this port */
+	uint64_t port_rx_pkts[RTE_EVENT_DEV_MAX_PORTS];
+	/**> Packets dropped on this port */
+	uint64_t port_rx_dropped[RTE_EVENT_DEV_MAX_PORTS];
+	/**> Packets inflight on this port */
+	uint64_t port_inflight[RTE_EVENT_DEV_MAX_PORTS];
+	/**> Packets transmitted on this port */
+	uint64_t port_tx_pkts[RTE_EVENT_DEV_MAX_PORTS];
+	/**> Packets received on this qid */
+	uint64_t queue_rx_pkts[RTE_EVENT_DEV_MAX_QUEUES];
+	/**> Packets dropped on this qid */
+	uint64_t queue_rx_dropped[RTE_EVENT_DEV_MAX_QUEUES];
+	/**> Packets transmitted on this qid */
+	uint64_t queue_tx_pkts[RTE_EVENT_DEV_MAX_QUEUES];
+};
+
+/**
+ * Return stats for the eventdev instance, packets enqueued and dequeued
+ * per port and per queue.
+ *
+ * @param dev_id
+ *   The identifier of the device.
+ * @param stats
+ *   Stats structure to be completed by the API
+ * @return
+ *   0 on success, negative errno value on error
+ */
+int
+rte_event_dev_stats_get(uint8_t dev_id, struct rte_event_dev_stats *stats);
+
+/**
+ * Dump internal information about *dev_id* to the FILE* provided in *f*.
+ */
+void rte_event_dev_dump(FILE *f, uint8_t dev_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_EVENTDEV_H_ */
diff --git a/lib/librte_eventdev/rte_eventdev_ops.h b/lib/librte_eventdev/rte_eventdev_ops.h
new file mode 100644
index 0000000..e4f3062
--- /dev/null
+++ b/lib/librte_eventdev/rte_eventdev_ops.h
@@ -0,0 +1,177 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_EVENT_DEV_OPS_
+#define _RTE_EVENT_DEV_OPS_
+
+#include <stdint.h>
+
+struct rte_event;
+struct rte_event_dev;
+struct rte_event_link;
+struct rte_event_dev_info;
+struct rte_event_dev_config;
+struct rte_event_queue_conf;
+struct rte_event_port_conf;
+
+/* Creation and info */
+typedef int (*event_dev_configure)(
+		struct rte_event_dev *dev,
+		struct rte_event_dev_config *config);
+typedef int (*event_dev_start)(struct rte_event_dev *dev);
+typedef void (*event_dev_stop)(struct rte_event_dev *dev);
+typedef int (*event_dev_close)(struct rte_event_dev *dev);
+
+/* Queue control */
+typedef void (*event_queue_default_conf_get)(
+		struct rte_event_dev *dev,
+		uint8_t queue_id,
+		struct rte_event_queue_conf *queue_conf);
+typedef int (*event_dev_queue_setup)(
+		struct rte_event_dev *dev,
+		uint8_t queue_id,
+		const struct rte_event_queue_conf *queue_conf);
+typedef uint16_t (*event_dev_queue_count)(struct rte_event_dev *dev);
+typedef uint8_t (*event_queue_priority)(
+		struct rte_event_dev *dev,
+		uint8_t queue_id);
+
+
+/* Port control */
+typedef void (*event_port_default_conf_get)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		struct rte_event_port_conf *port_conf);
+typedef int (*event_dev_port_setup)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		const struct rte_event_port_conf *port_conf);
+typedef uint8_t (*event_dev_port_dequeue_depth)(
+		struct rte_event_dev *dev,
+		uint8_t port_id);
+typedef uint8_t (*event_dev_port_enqueue_depth)(
+		struct rte_event_dev *dev,
+		uint8_t port_id);
+typedef uint8_t (*event_dev_port_count)(struct rte_event_dev *dev);
+
+/* Enqueue, dequeue and scheduling */
+typedef int (*event_dev_enqueue)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		struct rte_event *ev,
+		bool pin_event);
+typedef int (*event_dev_enqueue_burst)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		struct rte_event ev[],
+		int num,
+		bool pin_event);
+typedef bool (*event_dev_dequeue_wait_time)(
+		struct rte_event_dev *dev,
+		uint64_t ns);
+typedef bool (*event_dev_dequeue)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		struct rte_event *ev,
+		uint64_t wait);
+typedef int (*event_dev_dequeue_burst)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		struct rte_event ev[],
+		int num,
+		uint64_t wait);
+typedef int (*event_dev_schedule)(struct rte_event_dev *dev);
+typedef void (*event_dev_release)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		uint8_t index);
+
+/* Mapping */
+typedef int (*event_dev_port_link)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		struct rte_event_queue_link link[],
+		int num);
+typedef int (*event_dev_port_unlink)(
+		struct rte_event_dev *dev,
+		uint8_t port_id,
+		uint8_t queues[],
+		int num);
+
+/* stats */
+typedef int (*event_dev_stats_get)(
+		const struct rte_event_dev *dev,
+		struct rte_event_dev_stats *stats);
+typedef void (*event_dev_dump)(
+		FILE *f,
+		const struct rte_event_dev *dev);
+
+struct rte_event_dev_ops {
+	/* Creation and info */
+	event_dev_configure	configure;
+	event_dev_start		start;
+	event_dev_stop		stop;
+	event_dev_close		close;
+
+	/* Port control */
+	event_port_default_conf_get port_default_conf_get;
+	event_dev_port_setup	port_setup;
+	event_dev_port_dequeue_depth port_dequeue_depth;
+	event_dev_port_enqueue_depth port_enqueue_depth;
+	event_dev_port_count    port_count;
+
+	/* Queue control */
+	event_queue_default_conf_get queue_default_conf_get;
+	event_dev_queue_setup	queue_setup;
+	event_dev_queue_count   queue_count;
+	event_queue_priority	queue_priority;
+
+	/* Enqueue, dequeue and scheduling */
+	event_dev_enqueue	enqueue;
+	event_dev_enqueue_burst	enqueue_burst;
+	event_dev_dequeue_wait_time	dequeue_wait_time;
+	event_dev_dequeue	dequeue;
+	event_dev_dequeue_burst	dequeue_burst;
+	event_dev_schedule	schedule;
+	event_dev_release	release;
+
+	/* Mapping */
+	event_dev_port_link	port_link;
+	event_dev_port_unlink	port_unlink;
+
+	/* Stats */
+	event_dev_stats_get	stats_get;
+	event_dev_dump          dump;
+};
+
+#endif /* _RTE_EVENT_DEV_OPS_ */
diff --git a/lib/librte_eventdev/rte_eventdev_pmd.h b/lib/librte_eventdev/rte_eventdev_pmd.h
new file mode 100644
index 0000000..d8346b3
--- /dev/null
+++ b/lib/librte_eventdev/rte_eventdev_pmd.h
@@ -0,0 +1,69 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_EVENTDEV_PMD_H_
+#define _RTE_EVENTDEV_PMD_H_
+
+/** @file
+ * RTE EVENTDEV PMD API
+ *
+ * @note
+ * This API is for the Event Dev PMD only, and user applications should never
+ * call these functions directly.
+ */
+
+#include "rte_eventdev.h"
+#include "rte_eventdev_ops.h"
+
+/** Max number of chars in an eventdev name */
+#define RTE_EVENTDEV_PMD_NAME_SIZE 64
+
+/* Main struct that is passed around - contains pointers to all other structs
+ * linked with this dev. A dev represents the PMD behind an event device.
+ */
+struct rte_event_dev {
+	char name[RTE_EVENTDEV_PMD_NAME_SIZE];
+	const struct rte_event_dev_ops *ops;
+	struct rte_event_dev_info info;
+	uint32_t socket_id;
+	uint8_t id;
+	bool configured;
+	TAILQ_ENTRY(rte_event_dev) next;
+};
+
+/**
+ * Registers a PMD in the list of available event dev PMDs
+ */
+int
+rte_event_dev_register(struct rte_event_dev *new_dev);
+
+#endif /* _RTE_EVENTDEV_PMD_H_ */
diff --git a/lib/librte_eventdev/rte_eventdev_version.map b/lib/librte_eventdev/rte_eventdev_version.map
new file mode 100644
index 0000000..26f1dd5
--- /dev/null
+++ b/lib/librte_eventdev/rte_eventdev_version.map
@@ -0,0 +1,33 @@
+DPDK_17.02 {
+	global:
+
+	rte_event_dequeue;
+	rte_event_dequeue_burst;
+
+	rte_event_dev_close;
+	rte_event_dev_configure;
+	rte_event_dev_count;
+	rte_event_dev_get_dev_id;
+	rte_event_dev_info_get;
+	rte_event_dev_register;
+	rte_event_dev_socket_id;
+	rte_event_dev_start;
+	rte_event_dev_stop;
+
+	rte_event_enqueue;
+	rte_event_enqueue_burst;
+
+	rte_event_port_count;
+	rte_event_port_link;
+	rte_event_port_setup;
+	rte_event_port_unlink;
+
+	rte_event_queue_setup;
+	rte_event_queue_count;
+
+	rte_event_release;
+	rte_event_run;
+	rte_event_schedule;
+
+	local: *;
+};
-- 
2.7.4

^ permalink raw reply related

* [RFC PATCH 0/7] RFC: EventDev Software PMD
From: Harry van Haaren @ 2016-11-16 18:00 UTC (permalink / raw)
  To: dev; +Cc: Harry van Haaren

This series of RFC patches implements the libeventdev API and a software
eventdev PMD.

The implementation here is intended to enable the community to use the
eventdev API, specifically to test if the API serves the purpose that it is
designed to. It should be noted this is an RFC implementation, and hence
there should be no performance expectations.

An RFC for the eventdev was sent in August[1] by Jerin Jacob of Cavium,
which introduced the core concepts of the eventdev to the community. Since
then there has been extensive discussion[2] on the mailing list, which had
led to various modifications to the initial proposed API.

The API as presented in the first patch contains a number of changes that
have not yet been discussed. These changes were noticed during the
implementation of the software eventdev PMD, and were added to the API to
enable completion of the PMD. These modifications include a statistics API
and a dump API. For more details, please refer to the commit message of the
patch itself.

The functionality provided by each of the patches is as follows:
  1: Add eventdev API and library infrastructure
  2: Enable compilation of library
  3: Add software eventdev PMD
  4: Enable compilation of PMD
  5: Add test code
  6: Enable test code compilation
  7: Sample application demonstrating basic usage

This breakdown of the patchset hopefully enables the community to experiment
with the eventdev API, and allows us all to gain first-hand experience in
using the eventdev API.  Note also that this patchset has not passed
checkpatch testing just yet - will fix for v2 :)

As next steps I see value in discussing the proposed changes included in
this version of the header file, while welcoming feedback from the community
on the API in general too.

Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>

[1] http://dpdk.org/ml/archives/dev/2016-August/045181.html
[2] http://dpdk.org/ml/archives/dev/2016-October/thread.html#48196

Harry van Haaren (7):
  eventdev: header and implementation
  eventdev: makefiles
  event/sw: software eventdev implementation
  event/sw: makefiles and config
  test/eventdev: unit and functional tests
  test/eventdev: unit func makefiles
  examples/eventdev_pipeline: adding example

 app/test/Makefile                             |    3 +
 app/test/test_eventdev_func.c                 | 1272 ++++++++++++++++++++++++
 app/test/test_eventdev_unit.c                 |  557 +++++++++++
 config/common_base                            |   12 +
 drivers/Makefile                              |    1 +
 drivers/event/Makefile                        |   36 +
 drivers/event/sw/Makefile                     |   59 ++
 drivers/event/sw/event_ring.h                 |  142 +++
 drivers/event/sw/iq_ring.h                    |  160 +++
 drivers/event/sw/rte_pmd_evdev_sw_version.map |    3 +
 drivers/event/sw/sw_evdev.c                   |  619 ++++++++++++
 drivers/event/sw/sw_evdev.h                   |  234 +++++
 drivers/event/sw/sw_evdev_scheduler.c         |  660 +++++++++++++
 drivers/event/sw/sw_evdev_worker.c            |  218 +++++
 examples/eventdev_pipeline/Makefile           |   49 +
 examples/eventdev_pipeline/main.c             |  717 ++++++++++++++
 lib/Makefile                                  |    1 +
 lib/librte_eal/common/include/rte_vdev.h      |    1 +
 lib/librte_eventdev/Makefile                  |   54 ++
 lib/librte_eventdev/rte_eventdev.c            |  466 +++++++++
 lib/librte_eventdev/rte_eventdev.h            | 1289 +++++++++++++++++++++++++
 lib/librte_eventdev/rte_eventdev_ops.h        |  177 ++++
 lib/librte_eventdev/rte_eventdev_pmd.h        |   69 ++
 lib/librte_eventdev/rte_eventdev_version.map  |   33 +
 mk/rte.app.mk                                 |    5 +
 25 files changed, 6837 insertions(+)
 create mode 100644 app/test/test_eventdev_func.c
 create mode 100644 app/test/test_eventdev_unit.c
 create mode 100644 drivers/event/Makefile
 create mode 100644 drivers/event/sw/Makefile
 create mode 100644 drivers/event/sw/event_ring.h
 create mode 100644 drivers/event/sw/iq_ring.h
 create mode 100644 drivers/event/sw/rte_pmd_evdev_sw_version.map
 create mode 100644 drivers/event/sw/sw_evdev.c
 create mode 100644 drivers/event/sw/sw_evdev.h
 create mode 100644 drivers/event/sw/sw_evdev_scheduler.c
 create mode 100644 drivers/event/sw/sw_evdev_worker.c
 create mode 100644 examples/eventdev_pipeline/Makefile
 create mode 100644 examples/eventdev_pipeline/main.c
 create mode 100644 lib/librte_eventdev/Makefile
 create mode 100644 lib/librte_eventdev/rte_eventdev.c
 create mode 100644 lib/librte_eventdev/rte_eventdev.h
 create mode 100644 lib/librte_eventdev/rte_eventdev_ops.h
 create mode 100644 lib/librte_eventdev/rte_eventdev_pmd.h
 create mode 100644 lib/librte_eventdev/rte_eventdev_version.map

-- 
2.7.4

^ permalink raw reply

* [PATCH 22/22] app/testpmd: add queue actions to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

- QUEUE: assign packets to a given queue index.
- DUP: duplicate packets to a given queue index.
- RSS: spread packets among several queues.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 152 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 152 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index e166045..70e2b76 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -157,8 +157,15 @@ enum index {
 	ACTION_MARK,
 	ACTION_MARK_ID,
 	ACTION_FLAG,
+	ACTION_QUEUE,
+	ACTION_QUEUE_INDEX,
 	ACTION_DROP,
 	ACTION_COUNT,
+	ACTION_DUP,
+	ACTION_DUP_INDEX,
+	ACTION_RSS,
+	ACTION_RSS_QUEUES,
+	ACTION_RSS_QUEUE,
 	ACTION_PF,
 	ACTION_VF,
 	ACTION_VF_ORIGINAL,
@@ -172,6 +179,14 @@ enum index {
 #define ITEM_RAW_SIZE \
 	(offsetof(struct rte_flow_item_raw, pattern) + ITEM_RAW_PATTERN_SIZE)
 
+/** Number of queue[] entries in struct rte_flow_action_rss. */
+#define ACTION_RSS_NUM 32
+
+/** Storage size for struct rte_flow_action_rss including queues. */
+#define ACTION_RSS_SIZE \
+	(offsetof(struct rte_flow_action_rss, queue) + \
+	 sizeof(*((struct rte_flow_action_rss *)0)->queue) * ACTION_RSS_NUM)
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -489,8 +504,11 @@ static const enum index next_action[] = {
 	ACTION_PASSTHRU,
 	ACTION_MARK,
 	ACTION_FLAG,
+	ACTION_QUEUE,
 	ACTION_DROP,
 	ACTION_COUNT,
+	ACTION_DUP,
+	ACTION_RSS,
 	ACTION_PF,
 	ACTION_VF,
 	0,
@@ -502,6 +520,24 @@ static const enum index action_mark[] = {
 	0,
 };
 
+static const enum index action_queue[] = {
+	ACTION_QUEUE_INDEX,
+	ACTION_NEXT,
+	0,
+};
+
+static const enum index action_dup[] = {
+	ACTION_DUP_INDEX,
+	ACTION_NEXT,
+	0,
+};
+
+static const enum index action_rss[] = {
+	ACTION_RSS_QUEUES,
+	ACTION_NEXT,
+	0,
+};
+
 static const enum index action_vf[] = {
 	ACTION_VF_ORIGINAL,
 	ACTION_VF_ID,
@@ -519,6 +555,9 @@ static int parse_vc_spec(struct context *, const struct token *,
 			 const char *, unsigned int, void *, unsigned int);
 static int parse_vc_conf(struct context *, const struct token *,
 			 const char *, unsigned int, void *, unsigned int);
+static int parse_vc_action_rss_queue(struct context *, const struct token *,
+				     const char *, unsigned int, void *,
+				     unsigned int);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
@@ -568,6 +607,8 @@ static int comp_port(struct context *, const struct token *,
 		     unsigned int, char *, unsigned int);
 static int comp_rule_id(struct context *, const struct token *,
 			unsigned int, char *, unsigned int);
+static int comp_vc_action_rss_queue(struct context *, const struct token *,
+				    unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -1169,6 +1210,21 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
 		.call = parse_vc,
 	},
+	[ACTION_QUEUE] = {
+		.name = "queue",
+		.help = "assign packets to a given queue index",
+		.priv = PRIV_ACTION(QUEUE,
+				    sizeof(struct rte_flow_action_queue)),
+		.next = NEXT(action_queue),
+		.call = parse_vc,
+	},
+	[ACTION_QUEUE_INDEX] = {
+		.name = "index",
+		.help = "queue index to use",
+		.next = NEXT(action_queue, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
+		.call = parse_vc_conf,
+	},
 	[ACTION_DROP] = {
 		.name = "drop",
 		.help = "drop packets (note: passthru has priority)",
@@ -1183,6 +1239,39 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
 		.call = parse_vc,
 	},
+	[ACTION_DUP] = {
+		.name = "dup",
+		.help = "duplicate packets to a given queue index",
+		.priv = PRIV_ACTION(DUP, sizeof(struct rte_flow_action_dup)),
+		.next = NEXT(action_dup),
+		.call = parse_vc,
+	},
+	[ACTION_DUP_INDEX] = {
+		.name = "index",
+		.help = "queue index to duplicate packets to",
+		.next = NEXT(action_dup, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_dup, index)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_RSS] = {
+		.name = "rss",
+		.help = "spread packets among several queues",
+		.priv = PRIV_ACTION(RSS, ACTION_RSS_SIZE),
+		.next = NEXT(action_rss),
+		.call = parse_vc,
+	},
+	[ACTION_RSS_QUEUES] = {
+		.name = "queues",
+		.help = "queue indices to use",
+		.next = NEXT(action_rss, NEXT_ENTRY(ACTION_RSS_QUEUE)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_RSS_QUEUE] = {
+		.name = "{queue}",
+		.help = "queue index",
+		.call = parse_vc_action_rss_queue,
+		.comp = comp_vc_action_rss_queue,
+	},
 	[ACTION_PF] = {
 		.name = "pf",
 		.help = "redirect packets to physical device function",
@@ -1562,6 +1651,51 @@ parse_vc_conf(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/**
+ * Parse queue field for RSS action.
+ *
+ * Valid tokens are queue indices and the "end" token.
+ */
+static int
+parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
+			  const char *str, unsigned int len,
+			  void *buf, unsigned int size)
+{
+	static const enum index const next[] = NEXT_ENTRY(ACTION_RSS_QUEUE);
+	int ret;
+	int i;
+
+	(void)token;
+	(void)buf;
+	(void)size;
+	if (ctx->curr != ACTION_RSS_QUEUE)
+		return -1;
+	i = ctx->objdata >> 16;
+	if (!strncmp(str, "end", len)) {
+		ctx->objdata &= 0xffff;
+		return len;
+	}
+	if (i >= ACTION_RSS_NUM)
+		return -1;
+	if (push_args(ctx, ARGS_ENTRY(struct rte_flow_action_rss, queue[i])))
+		return -1;
+	ret = parse_int(ctx, token, str, len, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		return -1;
+	}
+	++i;
+	ctx->objdata = i << 16 | (ctx->objdata & 0xffff);
+	/* Repeat token. */
+	if (ctx->next_num == RTE_DIM(ctx->next))
+		return -1;
+	ctx->next[ctx->next_num++] = next;
+	if (!ctx->object)
+		return len;
+	((struct rte_flow_action_rss *)ctx->object)->queues = i;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
@@ -2136,6 +2270,24 @@ comp_rule_id(struct context *ctx, const struct token *token,
 	return i;
 }
 
+/** Complete queue field for RSS action. */
+static int
+comp_vc_action_rss_queue(struct context *ctx, const struct token *token,
+			 unsigned int ent, char *buf, unsigned int size)
+{
+	static const char *const str[] = { "", "end", NULL };
+	unsigned int i;
+
+	(void)ctx;
+	(void)token;
+	for (i = 0; str[i] != NULL; ++i)
+		if (buf && i == ent)
+			return snprintf(buf, size, "%s", str[i]);
+	if (buf)
+		return -1;
+	return i;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
-- 
2.1.4

^ permalink raw reply related

* [PATCH 21/22] app/testpmd: add various actions to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

- MARK: attach 32 bit value to packets.
- FLAG: flag packets.
- DROP: drop packets.
- COUNT: enable counters for a rule.
- PF: redirect packets to physical device function.
- VF: redirect packets to virtual device function.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 121 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 892f300..e166045 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -154,6 +154,15 @@ enum index {
 	ACTION_END,
 	ACTION_VOID,
 	ACTION_PASSTHRU,
+	ACTION_MARK,
+	ACTION_MARK_ID,
+	ACTION_FLAG,
+	ACTION_DROP,
+	ACTION_COUNT,
+	ACTION_PF,
+	ACTION_VF,
+	ACTION_VF_ORIGINAL,
+	ACTION_VF_ID,
 };
 
 /** Size of pattern[] field in struct rte_flow_item_raw. */
@@ -478,6 +487,25 @@ static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
 	ACTION_PASSTHRU,
+	ACTION_MARK,
+	ACTION_FLAG,
+	ACTION_DROP,
+	ACTION_COUNT,
+	ACTION_PF,
+	ACTION_VF,
+	0,
+};
+
+static const enum index action_mark[] = {
+	ACTION_MARK_ID,
+	ACTION_NEXT,
+	0,
+};
+
+static const enum index action_vf[] = {
+	ACTION_VF_ORIGINAL,
+	ACTION_VF_ID,
+	ACTION_NEXT,
 	0,
 };
 
@@ -489,6 +517,8 @@ static int parse_vc(struct context *, const struct token *,
 		    void *, unsigned int);
 static int parse_vc_spec(struct context *, const struct token *,
 			 const char *, unsigned int, void *, unsigned int);
+static int parse_vc_conf(struct context *, const struct token *,
+			 const char *, unsigned int, void *, unsigned int);
 static int parse_destroy(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
@@ -1118,6 +1148,70 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
 		.call = parse_vc,
 	},
+	[ACTION_MARK] = {
+		.name = "mark",
+		.help = "attach 32 bit value to packets",
+		.priv = PRIV_ACTION(MARK, sizeof(struct rte_flow_action_mark)),
+		.next = NEXT(action_mark),
+		.call = parse_vc,
+	},
+	[ACTION_MARK_ID] = {
+		.name = "id",
+		.help = "32 bit value to return with packets",
+		.next = NEXT(action_mark, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_mark, id)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_FLAG] = {
+		.name = "flag",
+		.help = "flag packets",
+		.priv = PRIV_ACTION(FLAG, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_DROP] = {
+		.name = "drop",
+		.help = "drop packets (note: passthru has priority)",
+		.priv = PRIV_ACTION(DROP, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_COUNT] = {
+		.name = "count",
+		.help = "enable counters for this rule",
+		.priv = PRIV_ACTION(COUNT, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_PF] = {
+		.name = "pf",
+		.help = "redirect packets to physical device function",
+		.priv = PRIV_ACTION(PF, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_VF] = {
+		.name = "vf",
+		.help = "redirect packets to virtual device function",
+		.priv = PRIV_ACTION(VF, sizeof(struct rte_flow_action_vf)),
+		.next = NEXT(action_vf),
+		.call = parse_vc,
+	},
+	[ACTION_VF_ORIGINAL] = {
+		.name = "original",
+		.help = "use original VF ID if possible",
+		.next = NEXT(action_vf, NEXT_ENTRY(BOOLEAN)),
+		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_action_vf,
+					   original)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_VF_ID] = {
+		.name = "id",
+		.help = "VF ID to redirect packets to",
+		.next = NEXT(action_vf, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
@@ -1441,6 +1535,33 @@ parse_vc_spec(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse action configuration field. */
+static int
+parse_vc_conf(struct context *ctx, const struct token *token,
+	      const char *str, unsigned int len,
+	      void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+
+	(void)size;
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Update configuration pointer. */
+	action->conf = ctx->object;
+	return len;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
-- 
2.1.4

^ permalink raw reply related

* [PATCH 20/22] app/testpmd: add L4 items to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

Add the ability to match a few properties of common L4[.5] protocol
headers:

- ICMP: type and code.
- UDP: source and destination ports.
- TCP: source and destination ports.
- SCTP: source and destination ports.
- VXLAN: network identifier.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 163 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 163 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 75096df..892f300 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -133,6 +133,20 @@ enum index {
 	ITEM_IPV6,
 	ITEM_IPV6_SRC,
 	ITEM_IPV6_DST,
+	ITEM_ICMP,
+	ITEM_ICMP_TYPE,
+	ITEM_ICMP_CODE,
+	ITEM_UDP,
+	ITEM_UDP_SRC,
+	ITEM_UDP_DST,
+	ITEM_TCP,
+	ITEM_TCP_SRC,
+	ITEM_TCP_DST,
+	ITEM_SCTP,
+	ITEM_SCTP_SRC,
+	ITEM_SCTP_DST,
+	ITEM_VXLAN,
+	ITEM_VXLAN_VNI,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -360,6 +374,11 @@ static const enum index next_item[] = {
 	ITEM_VLAN,
 	ITEM_IPV4,
 	ITEM_IPV6,
+	ITEM_ICMP,
+	ITEM_UDP,
+	ITEM_TCP,
+	ITEM_SCTP,
+	ITEM_VXLAN,
 	0,
 };
 
@@ -421,6 +440,40 @@ static const enum index item_ipv6[] = {
 	0,
 };
 
+static const enum index item_icmp[] = {
+	ITEM_ICMP_TYPE,
+	ITEM_ICMP_CODE,
+	ITEM_NEXT,
+	0,
+};
+
+static const enum index item_udp[] = {
+	ITEM_UDP_SRC,
+	ITEM_UDP_DST,
+	ITEM_NEXT,
+	0,
+};
+
+static const enum index item_tcp[] = {
+	ITEM_TCP_SRC,
+	ITEM_TCP_DST,
+	ITEM_NEXT,
+	0,
+};
+
+static const enum index item_sctp[] = {
+	ITEM_SCTP_SRC,
+	ITEM_SCTP_DST,
+	ITEM_NEXT,
+	0,
+};
+
+static const enum index item_vxlan[] = {
+	ITEM_VXLAN_VNI,
+	ITEM_NEXT,
+	0,
+};
+
 static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
@@ -936,6 +989,103 @@ static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
 					     hdr.dst_addr)),
 	},
+	[ITEM_ICMP] = {
+		.name = "icmp",
+		.help = "match ICMP header",
+		.priv = PRIV_ITEM(ICMP, sizeof(struct rte_flow_item_icmp)),
+		.next = NEXT(item_icmp),
+		.call = parse_vc,
+	},
+	[ITEM_ICMP_TYPE] = {
+		.name = "type",
+		.help = "ICMP packet type",
+		.next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
+					     hdr.icmp_type)),
+	},
+	[ITEM_ICMP_CODE] = {
+		.name = "code",
+		.help = "ICMP packet code",
+		.next = NEXT(item_icmp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_icmp,
+					     hdr.icmp_code)),
+	},
+	[ITEM_UDP] = {
+		.name = "udp",
+		.help = "match UDP header",
+		.priv = PRIV_ITEM(UDP, sizeof(struct rte_flow_item_udp)),
+		.next = NEXT(item_udp),
+		.call = parse_vc,
+	},
+	[ITEM_UDP_SRC] = {
+		.name = "src",
+		.help = "UDP source port",
+		.next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
+					     hdr.src_port)),
+	},
+	[ITEM_UDP_DST] = {
+		.name = "dst",
+		.help = "UDP destination port",
+		.next = NEXT(item_udp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_udp,
+					     hdr.dst_port)),
+	},
+	[ITEM_TCP] = {
+		.name = "tcp",
+		.help = "match TCP header",
+		.priv = PRIV_ITEM(TCP, sizeof(struct rte_flow_item_tcp)),
+		.next = NEXT(item_tcp),
+		.call = parse_vc,
+	},
+	[ITEM_TCP_SRC] = {
+		.name = "src",
+		.help = "TCP source port",
+		.next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
+					     hdr.src_port)),
+	},
+	[ITEM_TCP_DST] = {
+		.name = "dst",
+		.help = "TCP destination port",
+		.next = NEXT(item_tcp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_tcp,
+					     hdr.dst_port)),
+	},
+	[ITEM_SCTP] = {
+		.name = "sctp",
+		.help = "match SCTP header",
+		.priv = PRIV_ITEM(SCTP, sizeof(struct rte_flow_item_sctp)),
+		.next = NEXT(item_sctp),
+		.call = parse_vc,
+	},
+	[ITEM_SCTP_SRC] = {
+		.name = "src",
+		.help = "SCTP source port",
+		.next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
+					     hdr.src_port)),
+	},
+	[ITEM_SCTP_DST] = {
+		.name = "dst",
+		.help = "SCTP destination port",
+		.next = NEXT(item_sctp, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_sctp,
+					     hdr.dst_port)),
+	},
+	[ITEM_VXLAN] = {
+		.name = "vxlan",
+		.help = "match VXLAN header",
+		.priv = PRIV_ITEM(VXLAN, sizeof(struct rte_flow_item_vxlan)),
+		.next = NEXT(item_vxlan),
+		.call = parse_vc,
+	},
+	[ITEM_VXLAN_VNI] = {
+		.name = "vni",
+		.help = "VXLAN identifier",
+		.next = NEXT(item_vxlan, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vxlan, vni)),
+	},
 	/* Validate/create actions. */
 	[ACTIONS] = {
 		.name = "actions",
@@ -1497,6 +1647,19 @@ parse_int(struct context *ctx, const struct token *token,
 	case sizeof(uint16_t):
 		*(uint16_t *)buf = arg->hton ? rte_cpu_to_be_16(u) : u;
 		break;
+	case sizeof(uint8_t [3]):
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+		if (!arg->hton) {
+			((uint8_t *)buf)[0] = u;
+			((uint8_t *)buf)[1] = u >> 8;
+			((uint8_t *)buf)[2] = u >> 16;
+			break;
+		}
+#endif
+		((uint8_t *)buf)[0] = u >> 16;
+		((uint8_t *)buf)[1] = u >> 8;
+		((uint8_t *)buf)[2] = u;
+		break;
 	case sizeof(uint32_t):
 		*(uint32_t *)buf = arg->hton ? rte_cpu_to_be_32(u) : u;
 		break;
-- 
2.1.4

^ permalink raw reply related

* [PATCH 19/22] app/testpmd: add items ipv4/ipv6 to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

Add the ability to match basic fields from IPv4 and IPv6 headers (source
and destination addresses only).

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 177 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 177 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index f2bd405..75096df 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -38,6 +38,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
+#include <arpa/inet.h>
 
 #include <rte_common.h>
 #include <rte_ethdev.h>
@@ -61,6 +62,8 @@ enum index {
 	BOOLEAN,
 	STRING,
 	MAC_ADDR,
+	IPV4_ADDR,
+	IPV6_ADDR,
 	RULE_ID,
 	PORT_ID,
 	GROUP_ID,
@@ -124,6 +127,12 @@ enum index {
 	ITEM_VLAN,
 	ITEM_VLAN_TPID,
 	ITEM_VLAN_TCI,
+	ITEM_IPV4,
+	ITEM_IPV4_SRC,
+	ITEM_IPV4_DST,
+	ITEM_IPV6,
+	ITEM_IPV6_SRC,
+	ITEM_IPV6_DST,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -349,6 +358,8 @@ static const enum index next_item[] = {
 	ITEM_RAW,
 	ITEM_ETH,
 	ITEM_VLAN,
+	ITEM_IPV4,
+	ITEM_IPV6,
 	0,
 };
 
@@ -396,6 +407,20 @@ static const enum index item_vlan[] = {
 	0,
 };
 
+static const enum index item_ipv4[] = {
+	ITEM_IPV4_SRC,
+	ITEM_IPV4_DST,
+	ITEM_NEXT,
+	0,
+};
+
+static const enum index item_ipv6[] = {
+	ITEM_IPV6_SRC,
+	ITEM_IPV6_DST,
+	ITEM_NEXT,
+	0,
+};
+
 static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
@@ -441,6 +466,12 @@ static int parse_string(struct context *, const struct token *,
 static int parse_mac_addr(struct context *, const struct token *,
 			  const char *, unsigned int,
 			  void *, unsigned int);
+static int parse_ipv4_addr(struct context *, const struct token *,
+			   const char *, unsigned int,
+			   void *, unsigned int);
+static int parse_ipv6_addr(struct context *, const struct token *,
+			   const char *, unsigned int,
+			   void *, unsigned int);
 static int parse_port(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -511,6 +542,20 @@ static const struct token token_list[] = {
 		.call = parse_mac_addr,
 		.comp = comp_none,
 	},
+	[IPV4_ADDR] = {
+		.name = "{IPv4 address}",
+		.type = "IPV4 ADDRESS",
+		.help = "standard IPv4 address notation",
+		.call = parse_ipv4_addr,
+		.comp = comp_none,
+	},
+	[IPV6_ADDR] = {
+		.name = "{IPv6 address}",
+		.type = "IPV6 ADDRESS",
+		.help = "standard IPv6 address notation",
+		.call = parse_ipv6_addr,
+		.comp = comp_none,
+	},
 	[RULE_ID] = {
 		.name = "{rule id}",
 		.type = "RULE ID",
@@ -849,6 +894,48 @@ static const struct token token_list[] = {
 		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
 		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
 	},
+	[ITEM_IPV4] = {
+		.name = "ipv4",
+		.help = "match IPv4 header",
+		.priv = PRIV_ITEM(IPV4, sizeof(struct rte_flow_item_ipv4)),
+		.next = NEXT(item_ipv4),
+		.call = parse_vc,
+	},
+	[ITEM_IPV4_SRC] = {
+		.name = "src",
+		.help = "source address",
+		.next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
+					     hdr.src_addr)),
+	},
+	[ITEM_IPV4_DST] = {
+		.name = "dst",
+		.help = "destination address",
+		.next = NEXT(item_ipv4, NEXT_ENTRY(IPV4_ADDR), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv4,
+					     hdr.dst_addr)),
+	},
+	[ITEM_IPV6] = {
+		.name = "ipv6",
+		.help = "match IPv6 header",
+		.priv = PRIV_ITEM(IPV6, sizeof(struct rte_flow_item_ipv6)),
+		.next = NEXT(item_ipv6),
+		.call = parse_vc,
+	},
+	[ITEM_IPV6_SRC] = {
+		.name = "src",
+		.help = "source address",
+		.next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
+					     hdr.src_addr)),
+	},
+	[ITEM_IPV6_DST] = {
+		.name = "dst",
+		.help = "destination address",
+		.next = NEXT(item_ipv6, NEXT_ENTRY(IPV6_ADDR), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_ipv6,
+					     hdr.dst_addr)),
+	},
 	/* Validate/create actions. */
 	[ACTIONS] = {
 		.name = "actions",
@@ -1520,6 +1607,96 @@ parse_mac_addr(struct context *ctx, const struct token *token,
 	return -1;
 }
 
+/**
+ * Parse an IPv4 address.
+ *
+ * Last argument (ctx->args) is retrieved to determine storage size and
+ * location.
+ */
+static int
+parse_ipv4_addr(struct context *ctx, const struct token *token,
+		const char *str, unsigned int len,
+		void *buf, unsigned int size)
+{
+	const struct arg *arg = pop_args(ctx);
+	char str2[len + 1];
+	struct in_addr tmp;
+	int ret;
+
+	/* Argument is expected. */
+	if (!arg)
+		return -1;
+	size = arg->size;
+	/* Bit-mask fill is not supported. */
+	if (arg->mask || size != sizeof(tmp))
+		goto error;
+	/* Only network endian is supported. */
+	if (!arg->hton)
+		goto error;
+	memcpy(str2, str, len);
+	str2[len] = '\0';
+	ret = inet_pton(AF_INET, str2, &tmp);
+	if (ret != 1) {
+		/* Attempt integer parsing. */
+		push_args(ctx, arg);
+		return parse_int(ctx, token, str, len, buf, size);
+	}
+	if (!ctx->object)
+		return len;
+	buf = (uint8_t *)ctx->object + arg->offset;
+	memcpy(buf, &tmp, size);
+	if (ctx->objmask)
+		memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
+	return len;
+error:
+	push_args(ctx, arg);
+	return -1;
+}
+
+/**
+ * Parse an IPv6 address.
+ *
+ * Last argument (ctx->args) is retrieved to determine storage size and
+ * location.
+ */
+static int
+parse_ipv6_addr(struct context *ctx, const struct token *token,
+		const char *str, unsigned int len,
+		void *buf, unsigned int size)
+{
+	const struct arg *arg = pop_args(ctx);
+	char str2[len + 1];
+	struct in6_addr tmp;
+	int ret;
+
+	(void)token;
+	/* Argument is expected. */
+	if (!arg)
+		return -1;
+	size = arg->size;
+	/* Bit-mask fill is not supported. */
+	if (arg->mask || size != sizeof(tmp))
+		goto error;
+	/* Only network endian is supported. */
+	if (!arg->hton)
+		goto error;
+	memcpy(str2, str, len);
+	str2[len] = '\0';
+	ret = inet_pton(AF_INET6, str2, &tmp);
+	if (ret != 1)
+		goto error;
+	if (!ctx->object)
+		return len;
+	buf = (uint8_t *)ctx->object + arg->offset;
+	memcpy(buf, &tmp, size);
+	if (ctx->objmask)
+		memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
+	return len;
+error:
+	push_args(ctx, arg);
+	return -1;
+}
+
 /** Boolean values (even indices stand for false). */
 static const char *const boolean_name[] = {
 	"0", "1",
-- 
2.1.4

^ permalink raw reply related

* [PATCH 18/22] app/testpmd: add items eth/vlan to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

These pattern items match basic Ethernet headers (source, destination and
type) and related 802.1Q/ad VLAN headers.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 126 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 6f2f26c..f2bd405 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -43,6 +43,7 @@
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
+#include <cmdline_parse_etheraddr.h>
 #include <rte_flow.h>
 
 #include "testpmd.h"
@@ -59,6 +60,7 @@ enum index {
 	PREFIX,
 	BOOLEAN,
 	STRING,
+	MAC_ADDR,
 	RULE_ID,
 	PORT_ID,
 	GROUP_ID,
@@ -115,6 +117,13 @@ enum index {
 	ITEM_RAW_OFFSET,
 	ITEM_RAW_LIMIT,
 	ITEM_RAW_PATTERN,
+	ITEM_ETH,
+	ITEM_ETH_DST,
+	ITEM_ETH_SRC,
+	ITEM_ETH_TYPE,
+	ITEM_VLAN,
+	ITEM_VLAN_TPID,
+	ITEM_VLAN_TCI,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -239,6 +248,14 @@ struct token {
 		.size = (sz), \
 	})
 
+/** Same as ARGS_ENTRY() using network byte ordering. */
+#define ARGS_ENTRY_HTON(s, f) \
+	(&(const struct arg){ \
+		.hton = 1, \
+		.offset = offsetof(s, f), \
+		.size = sizeof(((s *)0)->f), \
+	})
+
 /** Parser output buffer layout expected by cmd_flow_parsed(). */
 struct buffer {
 	enum index command; /**< Flow command. */
@@ -330,6 +347,8 @@ static const enum index next_item[] = {
 	ITEM_VF,
 	ITEM_PORT,
 	ITEM_RAW,
+	ITEM_ETH,
+	ITEM_VLAN,
 	0,
 };
 
@@ -362,6 +381,21 @@ static const enum index item_raw[] = {
 	0,
 };
 
+static const enum index item_eth[] = {
+	ITEM_ETH_DST,
+	ITEM_ETH_SRC,
+	ITEM_ETH_TYPE,
+	ITEM_NEXT,
+	0,
+};
+
+static const enum index item_vlan[] = {
+	ITEM_VLAN_TPID,
+	ITEM_VLAN_TCI,
+	ITEM_NEXT,
+	0,
+};
+
 static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
@@ -404,6 +438,9 @@ static int parse_boolean(struct context *, const struct token *,
 static int parse_string(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
+static int parse_mac_addr(struct context *, const struct token *,
+			  const char *, unsigned int,
+			  void *, unsigned int);
 static int parse_port(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -467,6 +504,13 @@ static const struct token token_list[] = {
 		.call = parse_string,
 		.comp = comp_none,
 	},
+	[MAC_ADDR] = {
+		.name = "{MAC address}",
+		.type = "MAC-48",
+		.help = "standard MAC address notation",
+		.call = parse_mac_addr,
+		.comp = comp_none,
+	},
 	[RULE_ID] = {
 		.name = "{rule id}",
 		.type = "RULE ID",
@@ -761,6 +805,50 @@ static const struct token token_list[] = {
 					    pattern,
 					    ITEM_RAW_PATTERN_SIZE)),
 	},
+	[ITEM_ETH] = {
+		.name = "eth",
+		.help = "match Ethernet header",
+		.priv = PRIV_ITEM(ETH, sizeof(struct rte_flow_item_eth)),
+		.next = NEXT(item_eth),
+		.call = parse_vc,
+	},
+	[ITEM_ETH_DST] = {
+		.name = "dst",
+		.help = "destination MAC",
+		.next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_eth, dst)),
+	},
+	[ITEM_ETH_SRC] = {
+		.name = "src",
+		.help = "source MAC",
+		.next = NEXT(item_eth, NEXT_ENTRY(MAC_ADDR), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_eth, src)),
+	},
+	[ITEM_ETH_TYPE] = {
+		.name = "type",
+		.help = "EtherType",
+		.next = NEXT(item_eth, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_eth, type)),
+	},
+	[ITEM_VLAN] = {
+		.name = "vlan",
+		.help = "match 802.1Q/ad VLAN tag",
+		.priv = PRIV_ITEM(VLAN, sizeof(struct rte_flow_item_vlan)),
+		.next = NEXT(item_vlan),
+		.call = parse_vc,
+	},
+	[ITEM_VLAN_TPID] = {
+		.name = "tpid",
+		.help = "tag protocol identifier",
+		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tpid)),
+	},
+	[ITEM_VLAN_TCI] = {
+		.name = "tci",
+		.help = "tag control information",
+		.next = NEXT(item_vlan, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_vlan, tci)),
+	},
 	/* Validate/create actions. */
 	[ACTIONS] = {
 		.name = "actions",
@@ -1394,6 +1482,44 @@ parse_string(struct context *ctx, const struct token *token,
 	return -1;
 }
 
+/**
+ * Parse a MAC address.
+ *
+ * Last argument (ctx->args) is retrieved to determine storage size and
+ * location.
+ */
+static int
+parse_mac_addr(struct context *ctx, const struct token *token,
+	       const char *str, unsigned int len,
+	       void *buf, unsigned int size)
+{
+	const struct arg *arg = pop_args(ctx);
+	struct ether_addr tmp;
+	int ret;
+
+	(void)token;
+	/* Argument is expected. */
+	if (!arg)
+		return -1;
+	size = arg->size;
+	/* Bit-mask fill is not supported. */
+	if (arg->mask || size != sizeof(tmp))
+		goto error;
+	ret = cmdline_parse_etheraddr(NULL, str, &tmp, size);
+	if (ret < 0 || (unsigned int)ret != len)
+		goto error;
+	if (!ctx->object)
+		return len;
+	buf = (uint8_t *)ctx->object + arg->offset;
+	memcpy(buf, &tmp, size);
+	if (ctx->objmask)
+		memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size);
+	return len;
+error:
+	push_args(ctx, arg);
+	return -1;
+}
+
 /** Boolean values (even indices stand for false). */
 static const char *const boolean_name[] = {
 	"0", "1",
-- 
2.1.4

^ permalink raw reply related

* [PATCH 17/22] app/testpmd: add item raw to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

Matches arbitrary byte strings with properties:

- relative: look for pattern after the previous item.
- search: search pattern from offset (see also limit).
- offset: absolute or relative offset for pattern.
- limit: search area limit for start of pattern.
- length: pattern length.
- pattern: byte string to look for.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 206 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 206 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index c61e31e..6f2f26c 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -57,6 +57,8 @@ enum index {
 	INTEGER,
 	UNSIGNED,
 	PREFIX,
+	BOOLEAN,
+	STRING,
 	RULE_ID,
 	PORT_ID,
 	GROUP_ID,
@@ -107,6 +109,12 @@ enum index {
 	ITEM_VF_ID,
 	ITEM_PORT,
 	ITEM_PORT_INDEX,
+	ITEM_RAW,
+	ITEM_RAW_RELATIVE,
+	ITEM_RAW_SEARCH,
+	ITEM_RAW_OFFSET,
+	ITEM_RAW_LIMIT,
+	ITEM_RAW_PATTERN,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -116,6 +124,13 @@ enum index {
 	ACTION_PASSTHRU,
 };
 
+/** Size of pattern[] field in struct rte_flow_item_raw. */
+#define ITEM_RAW_PATTERN_SIZE 36
+
+/** Storage size for struct rte_flow_item_raw including pattern. */
+#define ITEM_RAW_SIZE \
+	(offsetof(struct rte_flow_item_raw, pattern) + ITEM_RAW_PATTERN_SIZE)
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -217,6 +232,13 @@ struct token {
 		.size = sizeof(*((s *)0)->f), \
 	})
 
+/** Static initializer for ARGS() with arbitrary size. */
+#define ARGS_ENTRY_USZ(s, f, sz) \
+	(&(const struct arg){ \
+		.offset = offsetof(s, f), \
+		.size = (sz), \
+	})
+
 /** Parser output buffer layout expected by cmd_flow_parsed(). */
 struct buffer {
 	enum index command; /**< Flow command. */
@@ -307,6 +329,7 @@ static const enum index next_item[] = {
 	ITEM_PF,
 	ITEM_VF,
 	ITEM_PORT,
+	ITEM_RAW,
 	0,
 };
 
@@ -329,6 +352,16 @@ static const enum index item_port[] = {
 	0,
 };
 
+static const enum index item_raw[] = {
+	ITEM_RAW_RELATIVE,
+	ITEM_RAW_SEARCH,
+	ITEM_RAW_OFFSET,
+	ITEM_RAW_LIMIT,
+	ITEM_RAW_PATTERN,
+	ITEM_NEXT,
+	0,
+};
+
 static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
@@ -365,11 +398,19 @@ static int parse_int(struct context *, const struct token *,
 static int parse_prefix(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
+static int parse_boolean(struct context *, const struct token *,
+			 const char *, unsigned int,
+			 void *, unsigned int);
+static int parse_string(struct context *, const struct token *,
+			const char *, unsigned int,
+			void *, unsigned int);
 static int parse_port(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
 static int comp_none(struct context *, const struct token *,
 		     unsigned int, char *, unsigned int);
+static int comp_boolean(struct context *, const struct token *,
+			unsigned int, char *, unsigned int);
 static int comp_action(struct context *, const struct token *,
 		       unsigned int, char *, unsigned int);
 static int comp_port(struct context *, const struct token *,
@@ -412,6 +453,20 @@ static const struct token token_list[] = {
 		.call = parse_prefix,
 		.comp = comp_none,
 	},
+	[BOOLEAN] = {
+		.name = "{boolean}",
+		.type = "BOOLEAN",
+		.help = "any boolean value",
+		.call = parse_boolean,
+		.comp = comp_boolean,
+	},
+	[STRING] = {
+		.name = "{string}",
+		.type = "STRING",
+		.help = "fixed string",
+		.call = parse_string,
+		.comp = comp_none,
+	},
 	[RULE_ID] = {
 		.name = "{rule id}",
 		.type = "RULE ID",
@@ -662,6 +717,50 @@ static const struct token token_list[] = {
 		.next = NEXT(item_port, NEXT_ENTRY(UNSIGNED), item_param),
 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_port, index)),
 	},
+	[ITEM_RAW] = {
+		.name = "raw",
+		.help = "match an arbitrary byte string",
+		.priv = PRIV_ITEM(RAW, ITEM_RAW_SIZE),
+		.next = NEXT(item_raw),
+		.call = parse_vc,
+	},
+	[ITEM_RAW_RELATIVE] = {
+		.name = "relative",
+		.help = "look for pattern after the previous item",
+		.next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
+		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw, relative)),
+	},
+	[ITEM_RAW_SEARCH] = {
+		.name = "search",
+		.help = "search pattern from offset (see also limit)",
+		.next = NEXT(item_raw, NEXT_ENTRY(BOOLEAN), item_param),
+		.args = ARGS(ARGS_ENTRY_BF(struct rte_flow_item_raw, search)),
+	},
+	[ITEM_RAW_OFFSET] = {
+		.name = "offset",
+		.help = "absolute or relative offset for pattern",
+		.next = NEXT(item_raw, NEXT_ENTRY(INTEGER), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, offset)),
+	},
+	[ITEM_RAW_LIMIT] = {
+		.name = "limit",
+		.help = "search area limit for start of pattern",
+		.next = NEXT(item_raw, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, limit)),
+	},
+	[ITEM_RAW_PATTERN] = {
+		.name = "pattern",
+		.help = "byte string to look for",
+		.next = NEXT(item_raw,
+			     NEXT_ENTRY(STRING),
+			     NEXT_ENTRY(ITEM_PARAM_FIX,
+					ITEM_PARAM_SPEC,
+					ITEM_PARAM_MASK)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_raw, length),
+			     ARGS_ENTRY_USZ(struct rte_flow_item_raw,
+					    pattern,
+					    ITEM_RAW_PATTERN_SIZE)),
+	},
 	/* Validate/create actions. */
 	[ACTIONS] = {
 		.name = "actions",
@@ -1243,6 +1342,96 @@ parse_int(struct context *ctx, const struct token *token,
 	return -1;
 }
 
+/**
+ * Parse a string.
+ *
+ * Two arguments (ctx->args) are retrieved from the stack to store data and
+ * its length (in that order).
+ */
+static int
+parse_string(struct context *ctx, const struct token *token,
+	     const char *str, unsigned int len,
+	     void *buf, unsigned int size)
+{
+	const struct arg *arg_data = pop_args(ctx);
+	const struct arg *arg_len = pop_args(ctx);
+	char tmp[16]; /* Ought to be enough. */
+	int ret;
+
+	/* Arguments are expected. */
+	if (!arg_data)
+		return -1;
+	if (!arg_len) {
+		push_args(ctx, arg_data);
+		return -1;
+	}
+	size = arg_data->size;
+	/* Bit-mask fill is not supported. */
+	if (arg_data->mask || size < len)
+		goto error;
+	if (!ctx->object)
+		return len;
+	/* Let parse_int() fill length information first. */
+	ret = snprintf(tmp, sizeof(tmp), "%u", len);
+	if (ret < 0)
+		goto error;
+	push_args(ctx, arg_len);
+	ret = parse_int(ctx, token, tmp, ret, NULL, 0);
+	if (ret < 0) {
+		pop_args(ctx);
+		goto error;
+	}
+	buf = (uint8_t *)ctx->object + arg_data->offset;
+	/* Output buffer is not necessarily NUL-terminated. */
+	memcpy(buf, str, len);
+	memset((uint8_t *)buf + len, 0x55, size - len);
+	if (ctx->objmask)
+		memset((uint8_t *)ctx->objmask + arg_data->offset, 0xff, len);
+	return len;
+error:
+	push_args(ctx, arg_len);
+	push_args(ctx, arg_data);
+	return -1;
+}
+
+/** Boolean values (even indices stand for false). */
+static const char *const boolean_name[] = {
+	"0", "1",
+	"false", "true",
+	"no", "yes",
+	"N", "Y",
+	NULL,
+};
+
+/**
+ * Parse a boolean value.
+ *
+ * Last argument (ctx->args) is retrieved to determine storage size and
+ * location.
+ */
+static int
+parse_boolean(struct context *ctx, const struct token *token,
+	      const char *str, unsigned int len,
+	      void *buf, unsigned int size)
+{
+	const struct arg *arg = pop_args(ctx);
+	unsigned int i;
+	int ret;
+
+	/* Argument is expected. */
+	if (!arg)
+		return -1;
+	for (i = 0; boolean_name[i]; ++i)
+		if (!strncmp(str, boolean_name[i], len))
+			break;
+	/* Process token as integer. */
+	if (boolean_name[i])
+		str = i & 1 ? "1" : "0";
+	push_args(ctx, arg);
+	ret = parse_int(ctx, token, str, strlen(str), buf, size);
+	return ret > 0 ? (int)len : ret;
+}
+
 /** Parse port and update context. */
 static int
 parse_port(struct context *ctx, const struct token *token,
@@ -1281,6 +1470,23 @@ comp_none(struct context *ctx, const struct token *token,
 	return 0;
 }
 
+/** Complete boolean values. */
+static int
+comp_boolean(struct context *ctx, const struct token *token,
+	     unsigned int ent, char *buf, unsigned int size)
+{
+	unsigned int i;
+
+	(void)ctx;
+	(void)token;
+	for (i = 0; boolean_name[i]; ++i)
+		if (buf && i == ent)
+			return snprintf(buf, size, "%s", boolean_name[i]);
+	if (buf)
+		return -1;
+	return i;
+}
+
 /** Complete action names. */
 static int
 comp_action(struct context *ctx, const struct token *token,
-- 
2.1.4

^ permalink raw reply related

* [PATCH 16/22] app/testpmd: add various items to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

- PF: match packets addressed to the physical function.
- VF: match packets addressed to a virtual function ID.
- PORT: device-specific physical port index to use.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 53 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 5816be4..c61e31e 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -102,6 +102,11 @@ enum index {
 	ITEM_ANY,
 	ITEM_ANY_MIN,
 	ITEM_ANY_MAX,
+	ITEM_PF,
+	ITEM_VF,
+	ITEM_VF_ID,
+	ITEM_PORT,
+	ITEM_PORT_INDEX,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -299,6 +304,9 @@ static const enum index next_item[] = {
 	ITEM_VOID,
 	ITEM_INVERT,
 	ITEM_ANY,
+	ITEM_PF,
+	ITEM_VF,
+	ITEM_PORT,
 	0,
 };
 
@@ -309,6 +317,18 @@ static const enum index item_any[] = {
 	0,
 };
 
+static const enum index item_vf[] = {
+	ITEM_VF_ID,
+	ITEM_NEXT,
+	0,
+};
+
+static const enum index item_port[] = {
+	ITEM_PORT_INDEX,
+	ITEM_NEXT,
+	0,
+};
+
 static const enum index next_action[] = {
 	ACTION_END,
 	ACTION_VOID,
@@ -609,6 +629,39 @@ static const struct token token_list[] = {
 		.next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
 		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, max)),
 	},
+	[ITEM_PF] = {
+		.name = "pf",
+		.help = "match packets addressed to the physical function",
+		.priv = PRIV_ITEM(PF, 0),
+		.next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
+		.call = parse_vc,
+	},
+	[ITEM_VF] = {
+		.name = "vf",
+		.help = "match packets addressed to a virtual function ID",
+		.priv = PRIV_ITEM(VF, sizeof(struct rte_flow_item_vf)),
+		.next = NEXT(item_vf),
+		.call = parse_vc,
+	},
+	[ITEM_VF_ID] = {
+		.name = "id",
+		.help = "destination VF ID",
+		.next = NEXT(item_vf, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_vf, id)),
+	},
+	[ITEM_PORT] = {
+		.name = "port",
+		.help = "device-specific physical port index to use",
+		.priv = PRIV_ITEM(PORT, sizeof(struct rte_flow_item_port)),
+		.next = NEXT(item_port),
+		.call = parse_vc,
+	},
+	[ITEM_PORT_INDEX] = {
+		.name = "index",
+		.help = "physical port index",
+		.next = NEXT(item_port, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_port, index)),
+	},
 	/* Validate/create actions. */
 	[ACTIONS] = {
 		.name = "actions",
-- 
2.1.4

^ permalink raw reply related

* [PATCH 15/22] app/testpmd: add item any to flow command
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

This pattern item matches any protocol in place of the current layer and
has two properties:

- min: minimum number of layers covered (0 or more).
- max: maximum number of layers covered (0 means infinity).

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 81930e1..5816be4 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -99,6 +99,9 @@ enum index {
 	ITEM_END,
 	ITEM_VOID,
 	ITEM_INVERT,
+	ITEM_ANY,
+	ITEM_ANY_MIN,
+	ITEM_ANY_MAX,
 
 	/* Validate/create actions. */
 	ACTIONS,
@@ -295,6 +298,14 @@ static const enum index next_item[] = {
 	ITEM_END,
 	ITEM_VOID,
 	ITEM_INVERT,
+	ITEM_ANY,
+	0,
+};
+
+static const enum index item_any[] = {
+	ITEM_ANY_MIN,
+	ITEM_ANY_MAX,
+	ITEM_NEXT,
 	0,
 };
 
@@ -579,6 +590,25 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ITEM_NEXT)),
 		.call = parse_vc,
 	},
+	[ITEM_ANY] = {
+		.name = "any",
+		.help = "match any protocol for the current layer",
+		.priv = PRIV_ITEM(ANY, sizeof(struct rte_flow_item_any)),
+		.next = NEXT(item_any),
+		.call = parse_vc,
+	},
+	[ITEM_ANY_MIN] = {
+		.name = "min",
+		.help = "minimum number of layers covered",
+		.next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, min)),
+	},
+	[ITEM_ANY_MAX] = {
+		.name = "max",
+		.help = "maximum number of layers covered, 0 for infinity",
+		.next = NEXT(item_any, NEXT_ENTRY(UNSIGNED), item_param),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_item_any, max)),
+	},
 	/* Validate/create actions. */
 	[ACTIONS] = {
 		.name = "actions",
-- 
2.1.4

^ permalink raw reply related

* [PATCH 14/22] app/testpmd: add rte_flow bit-field support
From: Adrien Mazarguil @ 2016-11-16 16:23 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Pablo de Lara, Olivier Matz
In-Reply-To: <cover.1479309719.git.adrien.mazarguil@6wind.com>

Several rte_flow structures expose bit-fields that cannot be set in a
generic fashion at byte level. Add bit-mask support to handle them.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
 app/test-pmd/cmdline_flow.c | 59 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 89307cb..81930e1 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -136,6 +136,7 @@ struct arg {
 	uint32_t sign:1; /**< Value is signed. */
 	uint32_t offset; /**< Relative offset from ctx->object. */
 	uint32_t size; /**< Field size. */
+	const uint8_t *mask; /**< Bit-mask to use instead of offset/size. */
 };
 
 /** Parser token definition. */
@@ -195,6 +196,13 @@ struct token {
 		.size = sizeof(((s *)0)->f), \
 	})
 
+/** Static initializer for ARGS() to target a bit-field. */
+#define ARGS_ENTRY_BF(s, f) \
+	(&(const struct arg){ \
+		.size = sizeof(s), \
+		.mask = (const void *)&(const s){ .f = -1 }, \
+	})
+
 /** Static initializer for ARGS() to target a pointer. */
 #define ARGS_ENTRY_PTR(s, f) \
 	(&(const struct arg){ \
@@ -622,6 +630,34 @@ push_args(struct context *ctx, const struct arg *arg)
 	return 0;
 }
 
+/** Spread value into buffer according to bit-mask. */
+static size_t
+arg_entry_bf_fill(void *dst, uintmax_t val, const struct arg *arg)
+{
+	uint32_t i;
+	size_t len = 0;
+
+	/* Endian conversion is not supported on bit-fields. */
+	if (!arg->mask || arg->hton)
+		return 0;
+	for (i = 0; i != arg->size; ++i) {
+		unsigned int shift = 0;
+		uint8_t *buf = (uint8_t *)dst + i;
+
+		for (shift = 0; arg->mask[i] >> shift; ++shift) {
+			if (!(arg->mask[i] & (1 << shift)))
+				continue;
+			++len;
+			if (!dst)
+				continue;
+			*buf &= ~(1 << shift);
+			*buf |= (val & 1) << shift;
+			val >>= 1;
+		}
+	}
+	return len;
+}
+
 /**
  * Parse a prefix length and generate a bit-mask.
  *
@@ -648,6 +684,23 @@ parse_prefix(struct context *ctx, const struct token *token,
 	u = strtoumax(str, &end, 0);
 	if (errno || (size_t)(end - str) != len)
 		goto error;
+	if (arg->mask) {
+		uintmax_t v = 0;
+
+		extra = arg_entry_bf_fill(NULL, 0, arg);
+		if (u > extra)
+			goto error;
+		if (!ctx->object)
+			return len;
+		extra -= u;
+		while (u--)
+			(v <<= 1, v |= 1);
+		v <<= extra;
+		if (!arg_entry_bf_fill(ctx->object, v, arg) ||
+		    !arg_entry_bf_fill(ctx->objmask, -1, arg))
+			goto error;
+		return len;
+	}
 	bytes = u / 8;
 	extra = u % 8;
 	size = arg->size;
@@ -1071,6 +1124,12 @@ parse_int(struct context *ctx, const struct token *token,
 		goto error;
 	if (!ctx->object)
 		return len;
+	if (arg->mask) {
+		if (!arg_entry_bf_fill(ctx->object, u, arg) ||
+		    !arg_entry_bf_fill(ctx->objmask, -1, arg))
+			goto error;
+		return len;
+	}
 	buf = (uint8_t *)ctx->object + arg->offset;
 	size = arg->size;
 objmask:
-- 
2.1.4

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox