Skip to contentSkip to conversation

Extending DPDK with multiple device support

RFC PATCH In review Keith Wiles 6 participants 28 messages Apr 13, 2015 – May 4, 2015 12 messages not in the archive Library code

lore
Share & tools
lore
#0 lore raw

v2 cover Extending DPDK with multiple device support

Hi All,

Here is a set of RFC patches to update DPDK to support a generic set of devices. The patches that follow create two files eal_common_device.h and rte_common_device.c and then a few items in rte_ethdev.[ch] were moved to cleanup those files by moving the device generic values and functions into a common set of device generic files.

In the rte_common_device.h file are a couple of macros to abstract a few common items from rte_ethdev.h which are not ethernet specific. These generic device specific structure members are place into macros to be placed at the top of each new device type crypto, hardware offload, dpi, compression and possible others to be defined later. In version 2 I used nested structures a bit cleaner from the macro design, but modified a lot more files.

Most of the changes are to update the code to locate the new location of the members in the nested structures. To not try and rewrite code I used macros to help hide the changes, but these constructs are now used in a lot of files withint DPDK.

I did not pull the Rx/Tx Routines into a common function, but it could be done if everyone agrees. It does not mean every device will use a common Rx/Tx routine. Without pulling Rx/Tx routines into a common file allows the device writer to have similar or different set of routines.

These patches do not contain any new devices as these are being work on today. I could have included the DPI (dpidev) routines we did in the PoC, but the DPI is not open source.

More cleanup of ethdev could be done to remove NIC specific features not supported in all devices and someone needs to do that cleanup IMO.

The code is untested and I wanted to get something our for others to poke at today and more could be pulled out of ethdev as well. I/We will be looking at testing the code as we get more completed.

I have not finished up the crypto APIs yet, but I am planning to work on those additions today. The crypto code we are using is the Quick Assist code found on 01.org, but we need to update the code to be move DPDK friendly.

The QAT code does have a modified like API similar to Linux Kernel crypto API and I want to review that code first.

Regards,
++Keith

Keith Wiles (4):
Adding the common device files for multiple device support Add the ethdev changes for multiple device support Add the test file changes for common device support Update PMD files for new common device support

 app/test-pmd/config.c                             |   6 +-
 app/test-pmd/testpmd.h                            |   4 +-
 app/test/test_kni.c                               |  12 +-
 app/test/test_link_bonding.c                      |  24 +-
 app/test/virtual_pmd.c                            | 106 +--
 examples/link_status_interrupt/main.c             |   6 +-
 lib/librte_eal/bsdapp/eal/Makefile                |   1 +
 lib/librte_eal/common/Makefile                    |   1 +
 lib/librte_eal/common/eal_common_device.c         | 185 +++++
 lib/librte_eal/common/include/rte_common_device.h | 674 +++++++++++++++
 lib/librte_eal/common/include/rte_log.h           |   1 +
 lib/librte_eal/linuxapp/eal/Makefile              |   1 +
 lib/librte_ether/rte_ethdev.c                     | 944 +++++++++-------------
 lib/librte_ether/rte_ethdev.h                     | 340 ++------
 lib/librte_kni/rte_kni.c                          |   4 +-
 lib/librte_pmd_af_packet/rte_eth_af_packet.c      |  38 +-
 lib/librte_pmd_bond/rte_eth_bond_8023ad.c         |  18 +-
 lib/librte_pmd_bond/rte_eth_bond_alb.c            |  10 +-
 lib/librte_pmd_bond/rte_eth_bond_api.c            | 142 ++--
 lib/librte_pmd_bond/rte_eth_bond_args.c           |   2 +-
 lib/librte_pmd_bond/rte_eth_bond_pmd.c            | 164 ++--
 lib/librte_pmd_bond/rte_eth_bond_private.h        |   2 +-
 lib/librte_pmd_e1000/em_ethdev.c                  | 156 ++--
 lib/librte_pmd_e1000/em_rxtx.c                    |  94 +--
 lib/librte_pmd_e1000/igb_ethdev.c                 | 302 +++----
 lib/librte_pmd_e1000/igb_pf.c                     |  86 +-
 lib/librte_pmd_e1000/igb_rxtx.c                   | 168 ++--
 lib/librte_pmd_enic/enic.h                        |   4 +-
 lib/librte_pmd_enic/enic_ethdev.c                 | 140 ++--
 lib/librte_pmd_enic/enic_main.c                   |  30 +-
 lib/librte_pmd_fm10k/fm10k_ethdev.c               | 154 ++--
 lib/librte_pmd_fm10k/fm10k_rxtx.c                 |   4 +-
 lib/librte_pmd_i40e/i40e_ethdev.c                 | 172 ++--
 lib/librte_pmd_i40e/i40e_ethdev_vf.c              | 194 ++---
 lib/librte_pmd_i40e/i40e_fdir.c                   |  28 +-
 lib/librte_pmd_i40e/i40e_pf.c                     |   8 +-
 lib/librte_pmd_i40e/i40e_rxtx.c                   |  88 +-
 lib/librte_pmd_ixgbe/ixgbe_ethdev.c               | 392 ++++-----
 lib/librte_pmd_ixgbe/ixgbe_fdir.c                 |  50 +-
 lib/librte_pmd_ixgbe/ixgbe_pf.c                   | 114 ++-
 lib/librte_pmd_ixgbe/ixgbe_rxtx.c                 | 276 +++----
 lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c             |   6 +-
 lib/librte_pmd_mlx4/mlx4.c                        |   2 +-
 lib/librte_pmd_null/rte_eth_null.c                |  36 +-
 lib/librte_pmd_pcap/rte_eth_pcap.c                |   2 +-
 lib/librte_pmd_ring/rte_eth_ring.c                |  36 +-
 lib/librte_pmd_virtio/virtio_ethdev.c             | 120 +--
 lib/librte_pmd_virtio/virtio_rxtx.c               |  20 +-
 lib/librte_pmd_vmxnet3/vmxnet3_ethdev.c           |  64 +-
 lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c             |  40 +-
 lib/librte_pmd_xenvirt/rte_eth_xenvirt.c          |   2 +-
 51 files changed, 2990 insertions(+), 2483 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_device.c
 create mode 100644 lib/librte_eal/common/include/rte_common_device.h
Signature · 1 line
2.3.0
#2 lore raw

RFC PATCH v2 1/4 Adding the common device files for multiple device support

In reply to a message not in the archive

Add the eal_common_device.c and rte_common_device.h and include the build support changes.

---
 lib/librte_eal/bsdapp/eal/Makefile                |   1 +
 lib/librte_eal/common/Makefile                    |   1 +
 lib/librte_eal/common/eal_common_device.c         | 185 ++++++
 lib/librte_eal/common/include/rte_common_device.h | 674 ++++++++++++++++++++++
 lib/librte_eal/common/include/rte_log.h           |   1 +
 lib/librte_eal/linuxapp/eal/Makefile              |   1 +
 lib/librte_kni/rte_kni.c                          |   4 +-
 7 files changed, 865 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_device.c
 create mode 100644 lib/librte_eal/common/include/rte_common_device.h
lib/librte_eal/bsdapp/eal/Makefile +1 -0
index 2357cfa..7bb2689 100644
@@ -78,6 +78,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_device.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/common/Makefile +1 -0
index 3ea3bbf..c4bf805 100644
@@ -40,6 +40,7 @@ INC += rte_string_fns.h rte_version.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
 INC += rte_hexdump.h rte_devargs.h rte_dev.h
 INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
+INC += rte_common_device.h
 
 ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y)
 INC += rte_warnings.h
lib/librte_eal/common/eal_common_device.c new file +185 -0

185 lines not on this page · raw message

lib/librte_eal/common/include/rte_common_device.h new file +674 -0

674 lines not on this page · raw message

lib/librte_eal/common/include/rte_log.h +1 -0
index f83a0d9..543deb7 100644
@@ -77,6 +77,7 @@ extern struct rte_logs rte_logs;
 #define RTE_LOGTYPE_PORT    0x00002000 /**< Log related to port. */
 #define RTE_LOGTYPE_TABLE   0x00004000 /**< Log related to table. */
 #define RTE_LOGTYPE_PIPELINE 0x00008000 /**< Log related to pipeline. */
+#define RTE_LOGTYPE_DEV     0x00010000 /**< Log related to device. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1   0x01000000 /**< User-defined log type 1. */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 01f7b70..935720a 100644
@@ -90,6 +90,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_device.c
 
 CFLAGS_eal.o := -D_GNU_SOURCE
 CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
lib/librte_kni/rte_kni.c +2 -2
index 4e70fa0..87ee7a3 100644
@@ -320,8 +320,8 @@ rte_kni_create(uint8_t port_id,
 	rte_eth_dev_info_get(port_id, &info);
 
 	snprintf(conf.name, sizeof(conf.name), "vEth%u", port_id);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+	conf.addr = info.di.pci_dev->addr;
+	conf.id = info.di.pci_dev->id;
 	conf.group_id = (uint16_t)port_id;
 	conf.mbuf_size = mbuf_size;
 
Signature · 1 line
2.3.0
#7 lore raw

RFC PATCH v2 2/4 Add the ethdev changes for multiple device support

In reply to a message not in the archive
---
 lib/librte_ether/rte_ethdev.c | 944 +++++++++++++++++-------------------------
 lib/librte_ether/rte_ethdev.h | 340 ++++-----------
 2 files changed, 466 insertions(+), 818 deletions(-)
lib/librte_ether/rte_ethdev.c +382 -562
index e20cca5..0c68d8d 100644
@@ -77,38 +77,20 @@
 #define PMD_DEBUG_TRACE(fmt, args...)
 #endif
 
-/* Macros for checking for restricting functions to primary instance only */
-#define PROC_PRIMARY_OR_ERR_RET(retval) do { \
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
-		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
-		return (retval); \
-	} \
-} while(0)
-#define PROC_PRIMARY_OR_RET() do { \
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
-		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
-		return; \
-	} \
-} while(0)
-
-/* Macros to check for invlaid function pointers in dev_ops structure */
-#define FUNC_PTR_OR_ERR_RET(func, retval) do { \
-	if ((func) == NULL) { \
-		PMD_DEBUG_TRACE("Function not supported\n"); \
-		return (retval); \
-	} \
-} while(0)
-#define FUNC_PTR_OR_RET(func) do { \
-	if ((func) == NULL) { \
-		PMD_DEBUG_TRACE("Function not supported\n"); \
-		return; \
-	} \
-} while(0)
-
-static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
-static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
-static uint8_t nb_ports = 0;
+
+static struct eth_dev_global eth_globals = {
+        .devs           = &rte_eth_devices[0],
+        .data           = NULL,
+        .nb_ports       = 0,
+        .max_ports      = RTE_MAX_ETHPORTS,
+        .dflt_mtu       = ETHER_MTU,
+        .dev_size       = sizeof(struct rte_eth_dev),
+        .data_size      = sizeof(struct rte_eth_dev_data),
+        .mz_dev_data    = "rte_eth_dev_data"
+};
+
+struct eth_dev_global * rte_eth_globals = &eth_globals;
 
 /* spinlock for eth device callbacks */
 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
@@ -155,49 +137,30 @@ static struct rte_eth_xstats_name_off rte_txq_stats_strings[] = {
 		sizeof(rte_txq_stats_strings[0]))
 
 
-/**
- * The user application callback description.
- *
- * It contains callback address to be registered by user application,
- * the pointer to the parameters for callback, and the event type.
- */
-struct rte_eth_dev_callback {
-	TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */
-	rte_eth_dev_cb_fn cb_fn;                /**< Callback address */
-	void *cb_arg;                           /**< Parameter for callback */
-	enum rte_eth_event_type event;          /**< Interrupt event type */
-	uint32_t active;                        /**< Callback is executing */
-};
-
 enum {
 	STAT_QMAP_TX = 0,
 	STAT_QMAP_RX
 };
 
-enum {
-	DEV_DETACHED = 0,
-	DEV_ATTACHED
-};
-
 static inline void
 rte_eth_dev_data_alloc(void)
 {
 	const unsigned flags = 0;
 	const struct rte_memzone *mz;
 
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY){
-		mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA,
-				RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data),
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
+		mz = rte_memzone_reserve(eth_globals.mz_dev_data,
+				eth_globals.max_ports * eth_globals.data_size,
 				rte_socket_id(), flags);
 	} else
-		mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
+		mz = rte_memzone_lookup(eth_globals.mz_dev_data);
 	if (mz == NULL)
 		rte_panic("Cannot allocate memzone for ethernet port data\n");
 
-	rte_eth_dev_data = mz->addr;
+	eth_globals.data = mz->addr;
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		memset(rte_eth_dev_data, 0,
-				RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));
+		memset(eth_globals.data, 0,
+				eth_globals.max_ports * eth_globals.data_size);
 }
 
 struct rte_eth_dev *
@@ -205,9 +168,9 @@ rte_eth_dev_allocated(const char *name)
 {
 	unsigned i;
 
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+	for (i = 0; i < eth_globals.max_ports; i++) {
 		if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
-		    strcmp(rte_eth_devices[i].data->name, name) == 0)
+		    strcmp(_DD(&rte_eth_devices[i], name), name) == 0)
 			return &rte_eth_devices[i];
 	}
 	return NULL;
@@ -218,26 +181,26 @@ rte_eth_dev_find_free_port(void)
 {
 	unsigned i;
 
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+	for (i = 0; i < eth_globals.max_ports; i++) {
 		if (rte_eth_devices[i].attached == DEV_DETACHED)
 			return i;
 	}
-	return RTE_MAX_ETHPORTS;
+	return eth_globals.max_ports;
 }
 
 struct rte_eth_dev *
-rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
+rte_eth_dev_allocate(const char *name, enum rte_dev_type type)
 {
 	uint8_t port_id;
-	struct rte_eth_dev *eth_dev;
+	struct rte_eth_dev *dev;
 
 	port_id = rte_eth_dev_find_free_port();
-	if (port_id == RTE_MAX_ETHPORTS) {
+	if (port_id == eth_globals.max_ports) {
 		PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
 		return NULL;
 	}
 
-	if (rte_eth_dev_data == NULL)
+	if (eth_globals.data == NULL)
 		rte_eth_dev_data_alloc();
 
 	if (rte_eth_dev_allocated(name) != NULL) {
@@ -245,14 +208,15 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
 		return NULL;
 	}
 
-	eth_dev = &rte_eth_devices[port_id];
-	eth_dev->data = &rte_eth_dev_data[port_id];
-	snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
-	eth_dev->data->port_id = port_id;
-	eth_dev->attached = DEV_ATTACHED;
-	eth_dev->dev_type = type;
-	nb_ports++;
-	return eth_dev;
+	dev = &rte_eth_devices[port_id];
+	dev->data = &eth_globals.data[port_id];
+	snprintf(_DD(dev, name), sizeof(_DD(dev, name)), "%s", name);
+	_DD(dev, unit_id) = port_id;
+	dev->attached = DEV_ATTACHED;
+	dev->dev_info = NULL;
+	dev->dev_type = type;
+	eth_globals.nb_ports++;
+	return dev;
 }
 
 static inline int
@@ -273,13 +237,13 @@ rte_eth_dev_create_unique_device_name(char *name, size_t size,
 }
 
 int
-rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
+rte_eth_dev_release_port(struct rte_eth_dev *dev)
 {
-	if (eth_dev == NULL)
+	if (dev == NULL)
 		return -EINVAL;
 
-	eth_dev->attached = 0;
-	nb_ports--;
+	dev->attached = 0;
+	eth_globals.nb_ports--;
 	return 0;
 }
 
@@ -287,8 +251,8 @@ static int
 rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 		 struct rte_pci_device *pci_dev)
 {
-	struct eth_driver    *eth_drv;
-	struct rte_eth_dev *eth_dev;
+	struct eth_driver   *eth_drv;
+	struct rte_eth_dev	*dev;
 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
 
 	int diag;
@@ -299,31 +263,31 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 	rte_eth_dev_create_unique_device_name(ethdev_name,
 			sizeof(ethdev_name), pci_dev);
 
-	eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
-	if (eth_dev == NULL)
+	dev = rte_eth_dev_allocate(ethdev_name, RTE_DEV_PCI);
+	if (dev == NULL)
 		return -ENOMEM;
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY){
-		eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",
+		_DD_PRIVATE(dev) = rte_zmalloc("ethdev private structure",
 				  eth_drv->dev_private_size,
 				  RTE_CACHE_LINE_SIZE);
-		if (eth_dev->data->dev_private == NULL)
+		if (_DD_PRIVATE(dev) == NULL)
 			rte_panic("Cannot allocate memzone for private port data\n");
 	}
-	eth_dev->pci_dev = pci_dev;
-	eth_dev->driver = eth_drv;
-	eth_dev->data->rx_mbuf_alloc_failed = 0;
+	dev->pci_dev = pci_dev;
+	dev->driver = (struct rte_dev_drv *)eth_drv;
+	_DD(dev, rx_mbuf_alloc_failed) = 0;
 
 	/* init user callbacks */
-	TAILQ_INIT(&(eth_dev->link_intr_cbs));
+	TAILQ_INIT(&(dev->link_intr_cbs));
 
 	/*
 	 * Set the default MTU.
 	 */
-	eth_dev->data->mtu = ETHER_MTU;
+	_DD(dev, mtu) = ETHER_MTU;
 
 	/* Invoke PMD device initialization function */
-	diag = (*eth_drv->eth_dev_init)(eth_dev);
+	diag = (*eth_drv->dev_init)(dev);
 	if (diag == 0)
 		return (0);
 
@@ -332,9 +296,9 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
 			(unsigned) pci_dev->id.vendor_id,
 			(unsigned) pci_dev->id.device_id);
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		rte_free(eth_dev->data->dev_private);
-	eth_dev->attached = DEV_DETACHED;
-	nb_ports--;
+		rte_free(_DD_PRIVATE(dev));
+	dev->attached = DEV_DETACHED;
+	eth_globals.nb_ports--;
 	return diag;
 }
 
@@ -342,7 +306,7 @@ static int
 rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 {
 	const struct eth_driver *eth_drv;
-	struct rte_eth_dev *eth_dev;
+	struct rte_eth_dev *dev;
 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
 	int ret;
 
@@ -353,28 +317,28 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev)
 	rte_eth_dev_create_unique_device_name(ethdev_name,
 			sizeof(ethdev_name), pci_dev);
 
-	eth_dev = rte_eth_dev_allocated(ethdev_name);
-	if (eth_dev == NULL)
+	dev = rte_eth_dev_allocated(ethdev_name);
+	if (dev == NULL)
 		return -ENODEV;
 
 	eth_drv = (const struct eth_driver *)pci_dev->driver;
 
 	/* Invoke PMD device uninit function */
-	if (*eth_drv->eth_dev_uninit) {
-		ret = (*eth_drv->eth_dev_uninit)(eth_dev);
+	if (*eth_drv->dev_uninit) {
+		ret = (*eth_drv->dev_uninit)(dev);
 		if (ret)
 			return ret;
 	}
 
 	/* free ether device */
-	rte_eth_dev_release_port(eth_dev);
+	rte_eth_dev_release_port(dev);
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-		rte_free(eth_dev->data->dev_private);
+		rte_free(_DD_PRIVATE(dev));
 
-	eth_dev->pci_dev = NULL;
-	eth_dev->driver = NULL;
-	eth_dev->data = NULL;
+	dev->pci_dev = NULL;
+	dev->driver = NULL;
+	dev->data = NULL;
 
 	return 0;
 }
@@ -401,16 +365,6 @@ rte_eth_driver_register(struct eth_driver *eth_drv)
 	rte_eal_pci_register(&eth_drv->pci_drv);
 }
 
-static int
-rte_eth_dev_is_valid_port(uint8_t port_id)
-{
-	if (port_id >= RTE_MAX_ETHPORTS ||
-	    rte_eth_devices[port_id].attached != DEV_ATTACHED)
-		return 0;
-	else
-		return 1;
-}
-
 int
 rte_eth_dev_socket_id(uint8_t port_id)
 {
@@ -419,20 +373,14 @@ rte_eth_dev_socket_id(uint8_t port_id)
 	return rte_eth_devices[port_id].pci_dev->numa_node;
 }
 
-uint8_t
-rte_eth_dev_count(void)
-{
-	return (nb_ports);
-}
-
 /* So far, DPDK hotplug function only supports linux */
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 
-static enum rte_eth_dev_type
+static enum rte_dev_type
 rte_eth_dev_get_device_type(uint8_t port_id)
 {
 	if (!rte_eth_dev_is_valid_port(port_id))
-		return RTE_ETH_DEV_UNKNOWN;
+		return RTE_DEV_UNKNOWN;
 	return rte_eth_devices[port_id].dev_type;
 }
 
@@ -440,7 +388,7 @@ static int
 rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
 {
 	if ((devs == NULL) ||
-	    (size != sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS))
+	    (size != sizeof(struct rte_eth_dev) * eth_globals.max_ports))
 		return -EINVAL;
 
 	/* save current rte_eth_devices */
@@ -455,7 +403,7 @@ rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)
 		return -EINVAL;
 
 	/* check which port was attached or detached */
-	for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) {
+	for (*port_id = 0; *port_id < eth_globals.max_ports; (*port_id)++, devs++) {
 		if (rte_eth_devices[*port_id].attached ^ devs->attached)
 			return 0;
 	}
@@ -496,7 +444,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
 
 	/* shouldn't check 'rte_eth_devices[i].data',
 	 * because it might be overwritten by VDEV PMD */
-	tmp = rte_eth_dev_data[port_id].name;
+	tmp = eth_globals.data[port_id].name;
 	strcpy(name, tmp);
 	return 0;
 }
@@ -506,12 +454,12 @@ rte_eth_dev_is_detachable(uint8_t port_id)
 {
 	uint32_t drv_flags;
 
-	if (port_id >= RTE_MAX_ETHPORTS) {
+	if (port_id >= eth_globals.max_ports) {
 		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
 		return -EINVAL;
 	}
 
-	if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
+	if (rte_eth_devices[port_id].dev_type == RTE_DEV_PCI) {
 		switch (rte_eth_devices[port_id].pci_dev->kdrv) {
 		case RTE_KDRV_IGB_UIO:
 		case RTE_KDRV_UIO_GENERIC:
@@ -691,7 +639,7 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 	if (name == NULL)
 		return -EINVAL;
 
-	if (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {
+	if (rte_eth_dev_get_device_type(port_id) == RTE_DEV_PCI) {
 		ret = rte_eth_dev_get_addr_by_port(port_id, &addr);
 		if (ret < 0)
 			return ret;
@@ -729,25 +677,25 @@ rte_eth_dev_detach(uint8_t port_id __rte_unused,
 static int
 rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
 {
-	uint16_t old_nb_queues = dev->data->nb_rx_queues;
+	uint16_t old_nb_queues = _DD(dev, nb_rx_queues);
 	void **rxq;
 	unsigned i;
 
-	if (dev->data->rx_queues == NULL) { /* first time configuration */
-		dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues",
-				sizeof(dev->data->rx_queues[0]) * nb_queues,
+	if (_DD(dev, rx_queues) == NULL) { /* first time configuration */
+		_DD(dev, rx_queues) = rte_zmalloc("ethdev->rx_queues",
+				sizeof(_DD(dev, rx_queues[0])) * nb_queues,
 				RTE_CACHE_LINE_SIZE);
-		if (dev->data->rx_queues == NULL) {
-			dev->data->nb_rx_queues = 0;
+		if (_DD(dev, rx_queues) == NULL) {
+			_DD(dev, nb_rx_queues) = 0;
 			return -(ENOMEM);
 		}
 	} else { /* re-configure */
-		FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_release, -ENOTSUP);
+		FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rx_queue_release), -ENOTSUP);
 
-		rxq = dev->data->rx_queues;
+		rxq = _DD(dev, rx_queues);
 
 		for (i = nb_queues; i < old_nb_queues; i++)
-			(*dev->dev_ops->rx_queue_release)(rxq[i]);
+			ETH_OPS(dev, rx_queue_release)(rxq[i]);
 		rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
 				RTE_CACHE_LINE_SIZE);
 		if (rxq == NULL)
@@ -758,10 +706,10 @@ rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
 				sizeof(rxq[0]) * new_qs);
 		}
 
-		dev->data->rx_queues = rxq;
+		_DD(dev, rx_queues) = rxq;
 
 	}
-	dev->data->nb_rx_queues = nb_queues;
+	_DD(dev, nb_rx_queues) = nb_queues;
 	return (0);
 }
 
@@ -780,14 +728,14 @@ rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (rx_queue_id >= dev->data->nb_rx_queues) {
+	if (rx_queue_id >= _DD(dev, nb_rx_queues)) {
 		PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
 		return -EINVAL;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rx_queue_start), -ENOTSUP);
 
-	return dev->dev_ops->rx_queue_start(dev, rx_queue_id);
+	return ETH_OPS(dev, rx_queue_start)(dev, rx_queue_id);
 
 }
 
@@ -806,14 +754,14 @@ rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (rx_queue_id >= dev->data->nb_rx_queues) {
+	if (rx_queue_id >= _DD(dev, nb_rx_queues)) {
 		PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
 		return -EINVAL;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rx_queue_stop), -ENOTSUP);
 
-	return dev->dev_ops->rx_queue_stop(dev, rx_queue_id);
+	return ETH_OPS(dev, rx_queue_stop)(dev, rx_queue_id);
 
 }
 
@@ -832,14 +780,14 @@ rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (tx_queue_id >= dev->data->nb_tx_queues) {
+	if (tx_queue_id >= _DD(dev, nb_tx_queues)) {
 		PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
 		return -EINVAL;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, tx_queue_start), -ENOTSUP);
 
-	return dev->dev_ops->tx_queue_start(dev, tx_queue_id);
+	return ETH_OPS(dev, tx_queue_start)(dev, tx_queue_id);
 
 }
 
@@ -858,39 +806,39 @@ rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (tx_queue_id >= dev->data->nb_tx_queues) {
+	if (tx_queue_id >= _DD(dev, nb_tx_queues)) {
 		PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
 		return -EINVAL;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, tx_queue_stop), -ENOTSUP);
 
-	return dev->dev_ops->tx_queue_stop(dev, tx_queue_id);
+	return ETH_OPS(dev, tx_queue_stop)(dev, tx_queue_id);
 
 }
 
 static int
 rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
 {
-	uint16_t old_nb_queues = dev->data->nb_tx_queues;
+	uint16_t old_nb_queues = _DD(dev, nb_tx_queues);
 	void **txq;
 	unsigned i;
 
-	if (dev->data->tx_queues == NULL) { /* first time configuration */
-		dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues",
-				sizeof(dev->data->tx_queues[0]) * nb_queues,
+	if (_DD(dev, tx_queues) == NULL) { /* first time configuration */
+		_DD(dev, tx_queues) = rte_zmalloc("ethdev->tx_queues",
+				sizeof(_DD(dev, tx_queues[0])) * nb_queues,
 				RTE_CACHE_LINE_SIZE);
-		if (dev->data->tx_queues == NULL) {
-			dev->data->nb_tx_queues = 0;
+		if (_DD(dev, tx_queues) == NULL) {
+			_DD(dev, nb_tx_queues) = 0;
 			return -(ENOMEM);
 		}
 	} else { /* re-configure */
-		FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_release, -ENOTSUP);
+		FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, tx_queue_release), -ENOTSUP);
 
-		txq = dev->data->tx_queues;
+		txq = _DD(dev, tx_queues);
 
 		for (i = nb_queues; i < old_nb_queues; i++)
-			(*dev->dev_ops->tx_queue_release)(txq[i]);
+			ETH_OPS(dev, tx_queue_release)(txq[i]);
 		txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
 				RTE_CACHE_LINE_SIZE);
 		if (txq == NULL)
@@ -901,10 +849,10 @@ rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)
 				sizeof(txq[0]) * new_qs);
 		}
 
-		dev->data->tx_queues = txq;
+		_DD(dev, tx_queues) = txq;
 
 	}
-	dev->data->nb_tx_queues = nb_queues;
+	_DD(dev, nb_tx_queues) = nb_queues;
 	return (0);
 }
 
@@ -915,19 +863,19 @@ rte_eth_dev_check_vf_rss_rxq_num(uint8_t port_id, uint16_t nb_rx_q)
 	switch (nb_rx_q) {
 	case 1:
 	case 2:
-		RTE_ETH_DEV_SRIOV(dev).active =
+		ETH_SRIOV(dev).active =
 			ETH_64_POOLS;
 		break;
 	case 4:
-		RTE_ETH_DEV_SRIOV(dev).active =
+		ETH_SRIOV(dev).active =
 			ETH_32_POOLS;
 		break;
 	default:
 		return -EINVAL;
 	}
 
-	RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = nb_rx_q;
-	RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
+	ETH_SRIOV(dev).nb_q_per_pool = nb_rx_q;
+	ETH_SRIOV(dev).def_pool_q_idx =
 		dev->pci_dev->max_vfs * nb_rx_q;
 
 	return 0;
@@ -939,7 +887,7 @@ rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 
-	if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
+	if (ETH_SRIOV(dev).active != 0) {
 		/* check multi-queue mode */
 		if ((dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB) ||
 		    (dev_conf->rxmode.mq_mode == ETH_MQ_RX_DCB_RSS) ||
@@ -970,10 +918,10 @@ rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 					"mq_mode %u into VMDQ mq_mode %u\n",
 					port_id,
 					dev_conf->rxmode.mq_mode,
-					dev->data->dev_conf.rxmode.mq_mode);
+					ETH_DATA(dev)->dd.dev_conf.rxmode.mq_mode);
 		case ETH_MQ_RX_VMDQ_RSS:
-			dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
-			if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
+			ETH_CONF(dev).rxmode.mq_mode = ETH_MQ_RX_VMDQ_RSS;
+			if (nb_rx_q <= ETH_SRIOV(dev).nb_q_per_pool)
 				if (rte_eth_dev_check_vf_rss_rxq_num(port_id, nb_rx_q) != 0) {
 					PMD_DEBUG_TRACE("ethdev port_id=%d"
 						" SRIOV active, invalid queue"
@@ -985,9 +933,9 @@ rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 			break;
 		default: /* ETH_MQ_RX_VMDQ_ONLY or ETH_MQ_RX_NONE */
 			/* if nothing mq mode configure, use default scheme */
-			dev->data->dev_conf.rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
-			if (RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool > 1)
-				RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool = 1;
+			ETH_CONF(dev).rxmode.mq_mode = ETH_MQ_RX_VMDQ_ONLY;
+			if (ETH_SRIOV(dev).nb_q_per_pool > 1)
+				ETH_SRIOV(dev).nb_q_per_pool = 1;
 			break;
 		}
 
@@ -1001,16 +949,16 @@ rte_eth_dev_check_mq_mode(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 			return (-EINVAL);
 		default: /* ETH_MQ_TX_VMDQ_ONLY or ETH_MQ_TX_NONE */
 			/* if nothing mq mode configure, use default scheme */
-			dev->data->dev_conf.txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
+			ETH_CONF(dev).txmode.mq_mode = ETH_MQ_TX_VMDQ_ONLY;
 			break;
 		}
 
 		/* check valid queue number */
-		if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
-		    (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
+		if ((nb_rx_q > ETH_SRIOV(dev).nb_q_per_pool) ||
+		    (nb_tx_q > ETH_SRIOV(dev).nb_q_per_pool)) {
 			PMD_DEBUG_TRACE("ethdev port_id=%d SRIOV active, "
 				    "queue number must less equal to %d\n",
-					port_id, RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
+					port_id, ETH_SRIOV(dev).nb_q_per_pool);
 			return (-EINVAL);
 		}
 	} else {
@@ -1130,10 +1078,10 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_infos_get), -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_configure), -ENOTSUP);
 
-	if (dev->data->dev_started) {
+	if (ETH_DATA(dev)->dev_started) {
 		PMD_DEBUG_TRACE(
 		    "port %d must be stopped to allow configuration\n", port_id);
 		return (-EBUSY);
@@ -1144,10 +1092,10 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	 * than the maximum number of RX and TX queues supported by the
 	 * configured device.
 	 */
-	(*dev->dev_ops->dev_infos_get)(dev, &dev_info);
+	ETH_OPS(dev, dev_infos_get)(dev, &dev_info);
 	if (nb_rx_q > dev_info.max_rx_queues) {
 		PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n",
-				port_id, nb_rx_q, dev_info.max_rx_queues);
+				port_id, nb_rx_q, ETH_INFO(dev_info)->max_rx_queues);
 		return (-EINVAL);
 	}
 	if (nb_rx_q == 0) {
@@ -1157,7 +1105,7 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 
 	if (nb_tx_q > dev_info.max_tx_queues) {
 		PMD_DEBUG_TRACE("ethdev port_id=%d nb_tx_queues=%d > %d\n",
-				port_id, nb_tx_q, dev_info.max_tx_queues);
+				port_id, nb_tx_q, ETH_INFO(dev_info)->max_tx_queues);
 		return (-EINVAL);
 	}
 	if (nb_tx_q == 0) {
@@ -1166,7 +1114,7 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	}
 
 	/* Copy the dev_conf parameter into the dev structure */
-	memcpy(&dev->data->dev_conf, dev_conf, sizeof(dev->data->dev_conf));
+	memcpy(&ETH_CONF(dev), dev_conf, sizeof(ETH_CONF(dev)));
 
 	/*
 	 * If link state interrupt is enabled, check that the
@@ -1208,7 +1156,7 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		if (dev_conf->rxmode.max_rx_pkt_len < ETHER_MIN_LEN ||
 			dev_conf->rxmode.max_rx_pkt_len > ETHER_MAX_LEN)
 			/* Use default value */
-			dev->data->dev_conf.rxmode.max_rx_pkt_len =
+			ETH_CONF(dev).rxmode.max_rx_pkt_len =
 							ETHER_MAX_LEN;
 	}
 
@@ -1238,7 +1186,7 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 		return diag;
 	}
 
-	diag = (*dev->dev_ops->dev_configure)(dev);
+	diag = ETH_OPS(dev, dev_configure)(dev);
 	if (diag != 0) {
 		PMD_DEBUG_TRACE("port%d dev_configure = %d\n",
 				port_id, diag);
@@ -1263,21 +1211,21 @@ rte_eth_dev_config_restore(uint8_t port_id)
 
 	rte_eth_dev_info_get(port_id, &dev_info);
 
-	if (RTE_ETH_DEV_SRIOV(dev).active)
-		pool = RTE_ETH_DEV_SRIOV(dev).def_vmdq_idx;
+	if (ETH_SRIOV(dev).active)
+		pool = ETH_SRIOV(dev).def_vmdq_idx;
 
 	/* replay MAC address configuration */
 	for (i = 0; i < dev_info.max_mac_addrs; i++) {
-		addr = dev->data->mac_addrs[i];
+		addr = ETH_DATA(dev)->mac_addrs[i];
 
 		/* skip zero address */
 		if (is_zero_ether_addr(&addr))
 			continue;
 
 		/* add address to the hardware */
-		if  (*dev->dev_ops->mac_addr_add &&
-			(dev->data->mac_pool_sel[i] & (1ULL << pool)))
-			(*dev->dev_ops->mac_addr_add)(dev, &addr, i, pool);
+		if  (ETH_OPS(dev, mac_addr_add) &&
+			(ETH_DATA(dev)->mac_pool_sel[i] & (1ULL << pool)))
+			ETH_OPS(dev, mac_addr_add)(dev, &addr, i, pool);
 		else {
 			PMD_DEBUG_TRACE("port %d: MAC address array not supported\n",
 					port_id);
@@ -1316,26 +1264,26 @@ rte_eth_dev_start(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_start), -ENOTSUP);
 
-	if (dev->data->dev_started != 0) {
+	if (ETH_DATA(dev)->dev_started != 0) {
 		PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
 			" already started\n",
 			port_id);
 		return (0);
 	}
 
-	diag = (*dev->dev_ops->dev_start)(dev);
+	diag = ETH_OPS(dev, dev_start)(dev);
 	if (diag == 0)
-		dev->data->dev_started = 1;
+		ETH_DATA(dev)->dev_started = 1;
 	else
 		return diag;
 
 	rte_eth_dev_config_restore(port_id);
 
-	if (dev->data->dev_conf.intr_conf.lsc != 0) {
-		FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
-		(*dev->dev_ops->link_update)(dev, 0);
+	if (ETH_DATA(dev)->dev_conf.intr_conf.lsc != 0) {
+		FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, link_update), -ENOTSUP);
+		ETH_OPS(dev, link_update)(dev, 0);
 	}
 	return 0;
 }
@@ -1356,17 +1304,17 @@ rte_eth_dev_stop(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop);
+	FUNC_PTR_OR_RET(ETH_OPS(dev, dev_stop));
 
-	if (dev->data->dev_started == 0) {
+	if (ETH_DATA(dev)->dev_started == 0) {
 		PMD_DEBUG_TRACE("Device with port_id=%" PRIu8
 			" already stopped\n",
 			port_id);
 		return;
 	}
 
-	dev->data->dev_started = 0;
-	(*dev->dev_ops->dev_stop)(dev);
+	ETH_DATA(dev)->dev_started = 0;
+	ETH_OPS(dev, dev_stop)(dev);
 }
 
 int
@@ -1385,8 +1333,8 @@ rte_eth_dev_set_link_up(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP);
-	return (*dev->dev_ops->dev_set_link_up)(dev);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_set_link_up), -ENOTSUP);
+	return ETH_OPS(dev, dev_set_link_up)(dev);
 }
 
 int
@@ -1405,8 +1353,8 @@ rte_eth_dev_set_link_down(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP);
-	return (*dev->dev_ops->dev_set_link_down)(dev);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_set_link_down), -ENOTSUP);
+	return ETH_OPS(dev, dev_set_link_down)(dev);
 }
 
 void
@@ -1425,9 +1373,9 @@ rte_eth_dev_close(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->dev_close);
-	dev->data->dev_started = 0;
-	(*dev->dev_ops->dev_close)(dev);
+	FUNC_PTR_OR_RET(ETH_OPS(dev, dev_close));
+	ETH_DATA(dev)->dev_started = 0;
+	ETH_OPS(dev, dev_close)(dev);
 }
 
 int
@@ -1452,19 +1400,19 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (rx_queue_id >= dev->data->nb_rx_queues) {
+	if (rx_queue_id >= ETH_DATA(dev)->dd.nb_rx_queues) {
 		PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id);
 		return (-EINVAL);
 	}
 
-	if (dev->data->dev_started) {
+	if (ETH_DATA(dev)->dev_started) {
 		PMD_DEBUG_TRACE(
 		    "port %d must be stopped to allow configuration\n", port_id);
 		return -EBUSY;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_infos_get), -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rx_queue_setup), -ENOTSUP);
 
 	/*
 	 * Check the size of the mbuf data buffer.
@@ -1497,12 +1445,12 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
 	if (rx_conf == NULL)
 		rx_conf = &dev_info.default_rxconf;
 
-	ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
+	ret = ETH_OPS(dev, rx_queue_setup)(dev, rx_queue_id, nb_rx_desc,
 					      socket_id, rx_conf, mp);
 	if (!ret) {
-		if (!dev->data->min_rx_buf_size ||
-		    dev->data->min_rx_buf_size > mbp_buf_size)
-			dev->data->min_rx_buf_size = mbp_buf_size;
+		if (!ETH_DATA(dev)->dd.min_rx_buf_size ||
+		    ETH_DATA(dev)->dd.min_rx_buf_size > mbp_buf_size)
+			ETH_DATA(dev)->dd.min_rx_buf_size = mbp_buf_size;
 	}
 
 	return ret;
@@ -1526,26 +1474,26 @@ rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (tx_queue_id >= dev->data->nb_tx_queues) {
+	if (tx_queue_id >= ETH_DATA(dev)->dd.nb_tx_queues) {
 		PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id);
 		return (-EINVAL);
 	}
 
-	if (dev->data->dev_started) {
+	if (ETH_DATA(dev)->dev_started) {
 		PMD_DEBUG_TRACE(
 		    "port %d must be stopped to allow configuration\n", port_id);
 		return -EBUSY;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP);
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_infos_get), -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, tx_queue_setup), -ENOTSUP);
 
 	rte_eth_dev_info_get(port_id, &dev_info);
 
 	if (tx_conf == NULL)
 		tx_conf = &dev_info.default_txconf;
 
-	return (*dev->dev_ops->tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
+	return ETH_OPS(dev, tx_queue_setup)(dev, tx_queue_id, nb_tx_desc,
 					       socket_id, tx_conf);
 }
 
@@ -1561,9 +1509,9 @@ rte_eth_promiscuous_enable(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable);
-	(*dev->dev_ops->promiscuous_enable)(dev);
-	dev->data->promiscuous = 1;
+	FUNC_PTR_OR_RET(ETH_OPS(dev, promiscuous_enable));
+	ETH_OPS(dev, promiscuous_enable)(dev);
+	ETH_DATA(dev)->promiscuous = 1;
 }
 
 void
@@ -1578,9 +1526,9 @@ rte_eth_promiscuous_disable(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable);
-	dev->data->promiscuous = 0;
-	(*dev->dev_ops->promiscuous_disable)(dev);
+	FUNC_PTR_OR_RET(ETH_OPS(dev, promiscuous_disable));
+	ETH_DATA(dev)->promiscuous = 0;
+	ETH_OPS(dev, promiscuous_disable)(dev);
 }
 
 int
@@ -1594,7 +1542,7 @@ rte_eth_promiscuous_get(uint8_t port_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	return dev->data->promiscuous;
+	return ETH_DATA(dev)->promiscuous;
 }
 
 void
@@ -1609,9 +1557,9 @@ rte_eth_allmulticast_enable(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
-	(*dev->dev_ops->allmulticast_enable)(dev);
-	dev->data->all_multicast = 1;
+	FUNC_PTR_OR_RET(ETH_OPS(dev, allmulticast_enable));
+	ETH_OPS(dev, allmulticast_enable)(dev);
+	ETH_DATA(dev)->all_multicast = 1;
 }
 
 void
@@ -1626,9 +1574,9 @@ rte_eth_allmulticast_disable(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
-	dev->data->all_multicast = 0;
-	(*dev->dev_ops->allmulticast_disable)(dev);
+	FUNC_PTR_OR_RET(ETH_OPS(dev, allmulticast_disable));
+	ETH_DATA(dev)->all_multicast = 0;
+	ETH_OPS(dev, allmulticast_disable)(dev);
 }
 
 int
@@ -1642,7 +1590,7 @@ rte_eth_allmulticast_get(uint8_t port_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	return dev->data->all_multicast;
+	return ETH_DATA(dev)->all_multicast;
 }
 
 static inline int
@@ -1650,7 +1598,7 @@ rte_eth_dev_atomic_read_link_status(struct rte_eth_dev *dev,
 				struct rte_eth_link *link)
 {
 	struct rte_eth_link *dst = link;
-	struct rte_eth_link *src = &(dev->data->dev_link);
+	struct rte_eth_link *src = &(ETH_DATA(dev)->dev_link);
 
 	if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
 					*(uint64_t *)src) == 0)
@@ -1671,12 +1619,12 @@ rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.intr_conf.lsc != 0)
+	if (ETH_DATA(dev)->dev_conf.intr_conf.lsc != 0)
 		rte_eth_dev_atomic_read_link_status(dev, eth_link);
 	else {
-		FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
-		(*dev->dev_ops->link_update)(dev, 1);
-		*eth_link = dev->data->dev_link;
+		FUNC_PTR_OR_RET(ETH_OPS(dev, link_update));
+		ETH_OPS(dev, link_update)(dev, 1);
+		*eth_link = ETH_DATA(dev)->dev_link;
 	}
 }
 
@@ -1692,12 +1640,12 @@ rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.intr_conf.lsc != 0)
+	if (ETH_DATA(dev)->dev_conf.intr_conf.lsc != 0)
 		rte_eth_dev_atomic_read_link_status(dev, eth_link);
 	else {
-		FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
-		(*dev->dev_ops->link_update)(dev, 0);
-		*eth_link = dev->data->dev_link;
+		FUNC_PTR_OR_RET(ETH_OPS(dev, link_update));
+		ETH_OPS(dev, link_update)(dev, 0);
+		*eth_link = ETH_DATA(dev)->dev_link;
 	}
 }
 
@@ -1714,9 +1662,9 @@ rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
 	dev = &rte_eth_devices[port_id];
 	memset(stats, 0, sizeof(*stats));
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP);
-	(*dev->dev_ops->stats_get)(dev, stats);
-	stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, stats_get), -ENOTSUP);
+	ETH_OPS(dev, stats_get)(dev, stats);
+	stats->rx_nombuf = ETH_DATA(dev)->dd.rx_mbuf_alloc_failed;
 	return 0;
 }
 
@@ -1732,8 +1680,8 @@ rte_eth_stats_reset(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
-	(*dev->dev_ops->stats_reset)(dev);
+	FUNC_PTR_OR_RET(ETH_OPS(dev, stats_reset));
+	ETH_OPS(dev, stats_reset)(dev);
 }
 
 /* retrieve ethdev extended statistics */
@@ -1755,13 +1703,13 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 	dev = &rte_eth_devices[port_id];
 
 	/* implemented by the driver */
-	if (dev->dev_ops->xstats_get != NULL)
-		return (*dev->dev_ops->xstats_get)(dev, xstats, n);
+	if (ETH_OPS(dev, xstats_get) != NULL)
+		return ETH_OPS(dev, xstats_get)(dev, xstats, n);
 
 	/* else, return generic statistics */
 	count = RTE_NB_STATS;
-	count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
-	count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
+	count += ETH_DATA(dev)->dd.nb_rx_queues * RTE_NB_RXQ_STATS;
+	count += ETH_DATA(dev)->dd.nb_tx_queues * RTE_NB_TXQ_STATS;
 	if (n < count)
 		return count;
 
@@ -1781,7 +1729,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 	}
 
 	/* per-rxq stats */
-	for (q = 0; q < dev->data->nb_rx_queues; q++) {
+	for (q = 0; q < ETH_DATA(dev)->dd.nb_rx_queues; q++) {
 		for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
 			stats_ptr = (char *)&eth_stats;
 			stats_ptr += rte_rxq_stats_strings[i].offset;
@@ -1795,7 +1743,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 	}
 
 	/* per-txq stats */
-	for (q = 0; q < dev->data->nb_tx_queues; q++) {
+	for (q = 0; q < ETH_DATA(dev)->dd.nb_tx_queues; q++) {
 		for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
 			stats_ptr = (char *)&eth_stats;
 			stats_ptr += rte_txq_stats_strings[i].offset;
@@ -1825,8 +1773,8 @@ rte_eth_xstats_reset(uint8_t port_id)
 	dev = &rte_eth_devices[port_id];
 
 	/* implemented by the driver */
-	if (dev->dev_ops->xstats_reset != NULL) {
-		(*dev->dev_ops->xstats_reset)(dev);
+	if (ETH_OPS(dev, xstats_reset) != NULL) {
+		ETH_OPS(dev, xstats_reset)(dev);
 		return;
 	}
 
@@ -1847,9 +1795,8 @@ set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP);
-	return (*dev->dev_ops->queue_stats_mapping_set)
-			(dev, queue_id, stat_idx, is_rx);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, queue_stats_mapping_set), -ENOTSUP);
+	return ETH_OPS(dev, queue_stats_mapping_set)(dev, queue_id, stat_idx, is_rx);
 }
 
 
@@ -1885,11 +1832,11 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
 
 	memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
 
-	FUNC_PTR_OR_RET(*dev->dev_ops->dev_infos_get);
-	(*dev->dev_ops->dev_infos_get)(dev, dev_info);
-	dev_info->pci_dev = dev->pci_dev;
+	FUNC_PTR_OR_RET(ETH_OPS(dev, dev_infos_get));
+	ETH_OPS(dev, dev_infos_get)(dev, dev_info);
+	dev_info->di.pci_dev = dev->pci_dev;
 	if (dev->driver)
-		dev_info->driver_name = dev->driver->pci_drv.name;
+		dev_info->di.driver_name = dev->driver->pci_drv.name;
 }
 
 void
@@ -1903,7 +1850,7 @@ rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
+	ether_addr_copy(&ETH_DATA(dev)->mac_addrs[0], mac_addr);
 }
 
 
@@ -1918,7 +1865,7 @@ rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	*mtu = dev->data->mtu;
+	*mtu = ETH_DATA(dev)->dd.mtu;
 	return 0;
 }
 
@@ -1934,11 +1881,11 @@ rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, mtu_set), -ENOTSUP);
 
-	ret = (*dev->dev_ops->mtu_set)(dev, mtu);
+	ret = ETH_OPS(dev, mtu_set)(dev, mtu);
 	if (!ret)
-		dev->data->mtu = mtu;
+		ETH_DATA(dev)->dd.mtu = mtu;
 
 	return ret;
 }
@@ -1954,7 +1901,7 @@ rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) {
+	if (! (ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_filter)) {
 		PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id);
 		return (-ENOSYS);
 	}
@@ -1964,9 +1911,9 @@ rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
 				port_id, (unsigned) vlan_id);
 		return (-EINVAL);
 	}
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, vlan_filter_set), -ENOTSUP);
 
-	return (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on);
+	return ETH_OPS(dev, vlan_filter_set)(dev, vlan_id, on);
 }
 
 int
@@ -1980,13 +1927,13 @@ rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int o
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (rx_queue_id >= dev->data->nb_rx_queues) {
+	if (rx_queue_id >= ETH_DATA(dev)->dd.nb_rx_queues) {
 		PMD_DEBUG_TRACE("Invalid rx_queue_id=%d\n", port_id);
 		return (-EINVAL);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
-	(*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, vlan_strip_queue_set), -ENOTSUP);
+	ETH_OPS(dev, vlan_strip_queue_set)(dev, rx_queue_id, on);
 
 	return (0);
 }
@@ -2002,8 +1949,8 @@ rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP);
-	(*dev->dev_ops->vlan_tpid_set)(dev, tpid);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, vlan_tpid_set), -ENOTSUP);
+	ETH_OPS(dev, vlan_tpid_set)(dev, tpid);
 
 	return (0);
 }
@@ -2025,23 +1972,23 @@ rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
 
 	/*check which option changed by application*/
 	cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD);
-	org = !!(dev->data->dev_conf.rxmode.hw_vlan_strip);
+	org = !!(ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_strip);
 	if (cur != org){
-		dev->data->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
+		ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_strip = (uint8_t)cur;
 		mask |= ETH_VLAN_STRIP_MASK;
 	}
 
 	cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD);
-	org = !!(dev->data->dev_conf.rxmode.hw_vlan_filter);
+	org = !!(ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_filter);
 	if (cur != org){
-		dev->data->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
+		ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_filter = (uint8_t)cur;
 		mask |= ETH_VLAN_FILTER_MASK;
 	}
 
 	cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD);
-	org = !!(dev->data->dev_conf.rxmode.hw_vlan_extend);
+	org = !!(ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_extend);
 	if (cur != org){
-		dev->data->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
+		ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_extend = (uint8_t)cur;
 		mask |= ETH_VLAN_EXTEND_MASK;
 	}
 
@@ -2049,8 +1996,8 @@ rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
 	if(mask == 0)
 		return ret;
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP);
-	(*dev->dev_ops->vlan_offload_set)(dev, mask);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, vlan_offload_set), -ENOTSUP);
+	ETH_OPS(dev, vlan_offload_set)(dev, mask);
 
 	return ret;
 }
@@ -2068,13 +2015,13 @@ rte_eth_dev_get_vlan_offload(uint8_t port_id)
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.rxmode.hw_vlan_strip)
+	if (ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_strip)
 		ret |= ETH_VLAN_STRIP_OFFLOAD ;
 
-	if (dev->data->dev_conf.rxmode.hw_vlan_filter)
+	if (ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_filter)
 		ret |= ETH_VLAN_FILTER_OFFLOAD ;
 
-	if (dev->data->dev_conf.rxmode.hw_vlan_extend)
+	if (ETH_DATA(dev)->dev_conf.rxmode.hw_vlan_extend)
 		ret |= ETH_VLAN_EXTEND_OFFLOAD ;
 
 	return ret;
@@ -2091,8 +2038,8 @@ rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP);
-	(*dev->dev_ops->vlan_pvid_set)(dev, pvid, on);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, vlan_pvid_set), -ENOTSUP);
+	ETH_OPS(dev, vlan_pvid_set)(dev, pvid, on);
 
 	return 0;
 }
@@ -2111,9 +2058,9 @@ rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
+	if (ETH_DATA(dev)->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
 		PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
-				port_id, dev->data->dev_conf.fdir_conf.mode);
+				port_id, ETH_DATA(dev)->dd.dev_conf.fdir_conf.mode);
 		return (-ENOSYS);
 	}
 
@@ -2126,9 +2073,8 @@ rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
 		return (-EINVAL);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_signature_filter, -ENOTSUP);
-	return (*dev->dev_ops->fdir_add_signature_filter)(dev, fdir_filter,
-								queue);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_add_signature_filter), -ENOTSUP);
+	return ETH_OPS(dev, fdir_add_signature_filter)(dev, fdir_filter, queue);
 }
 
 int
@@ -2145,9 +2091,9 @@ rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
+	if (ETH_DATA(dev)->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
 		PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
-				port_id, dev->data->dev_conf.fdir_conf.mode);
+				port_id, ETH_DATA(dev)->dev_conf.fdir_conf.mode);
 		return (-ENOSYS);
 	}
 
@@ -2160,9 +2106,8 @@ rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
 		return (-EINVAL);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_signature_filter, -ENOTSUP);
-	return (*dev->dev_ops->fdir_update_signature_filter)(dev, fdir_filter,
-								queue);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_update_signature_filter), -ENOTSUP);
+	return ETH_OPS(dev, fdir_update_signature_filter)(dev, fdir_filter, queue);
 
 }
 
@@ -2179,9 +2124,9 @@ rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
+	if (ETH_DATA(dev)->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_SIGNATURE) {
 		PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
-				port_id, dev->data->dev_conf.fdir_conf.mode);
+				port_id, ETH_DATA(dev)->dev_conf.fdir_conf.mode);
 		return (-ENOSYS);
 	}
 
@@ -2194,8 +2139,8 @@ rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
 		return (-EINVAL);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_signature_filter, -ENOTSUP);
-	return (*dev->dev_ops->fdir_remove_signature_filter)(dev, fdir_filter);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_remove_signature_filter), -ENOTSUP);
+	return ETH_OPS(dev, fdir_remove_signature_filter)(dev, fdir_filter);
 }
 
 int
@@ -2209,14 +2154,14 @@ rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (! (dev->data->dev_conf.fdir_conf.mode)) {
+	if (! (ETH_DATA(dev)->dev_conf.fdir_conf.mode)) {
 		PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
 		return (-ENOSYS);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_infos_get, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_infos_get), -ENOTSUP);
 
-	(*dev->dev_ops->fdir_infos_get)(dev, fdir);
+	ETH_OPS(dev, fdir_infos_get)(dev, fdir);
 	return (0);
 }
 
@@ -2235,9 +2180,9 @@ rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
+	if (ETH_DATA(dev)->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
 		PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
-				port_id, dev->data->dev_conf.fdir_conf.mode);
+				port_id, ETH_DATA(dev)->dev_conf.fdir_conf.mode);
 		return (-ENOSYS);
 	}
 
@@ -2254,10 +2199,9 @@ rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
 	if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
 		return (-ENOTSUP);
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_add_perfect_filter, -ENOTSUP);
-	return (*dev->dev_ops->fdir_add_perfect_filter)(dev, fdir_filter,
-								soft_id, queue,
-								drop);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_add_perfect_filter), -ENOTSUP);
+	return ETH_OPS(dev, fdir_add_perfect_filter)(dev, fdir_filter,
+								soft_id, queue, drop);
 }
 
 int
@@ -2275,9 +2219,9 @@ rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
+	if (ETH_DATA(dev)->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
 		PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
-				port_id, dev->data->dev_conf.fdir_conf.mode);
+				port_id, ETH_DATA(dev)->dd.dev_conf.fdir_conf.mode);
 		return (-ENOSYS);
 	}
 
@@ -2294,8 +2238,8 @@ rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
 	if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
 		return (-ENOTSUP);
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_update_perfect_filter, -ENOTSUP);
-	return (*dev->dev_ops->fdir_update_perfect_filter)(dev, fdir_filter,
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_update_perfect_filter), -ENOTSUP);
+	return ETH_OPS(dev, fdir_update_perfect_filter)(dev, fdir_filter,
 							soft_id, queue, drop);
 }
 
@@ -2313,9 +2257,9 @@ rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
 
 	dev = &rte_eth_devices[port_id];
 
-	if (dev->data->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
+	if (ETH_DATA(dev)->dev_conf.fdir_conf.mode != RTE_FDIR_MODE_PERFECT) {
 		PMD_DEBUG_TRACE("port %d: invalid FDIR mode=%u\n",
-				port_id, dev->data->dev_conf.fdir_conf.mode);
+				port_id, ETH_DATA(dev)->dev_conf.fdir_conf.mode);
 		return (-ENOSYS);
 	}
 
@@ -2332,9 +2276,8 @@ rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
 	if (fdir_filter->iptype == RTE_FDIR_IPTYPE_IPV6)
 		return (-ENOTSUP);
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_remove_perfect_filter, -ENOTSUP);
-	return (*dev->dev_ops->fdir_remove_perfect_filter)(dev, fdir_filter,
-								soft_id);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_remove_perfect_filter), -ENOTSUP);
+	return ETH_OPS(dev, fdir_remove_perfect_filter)(dev, fdir_filter, soft_id);
 }
 
 int
@@ -2348,13 +2291,13 @@ rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	if (! (dev->data->dev_conf.fdir_conf.mode)) {
+	if (! (ETH_DATA(dev)->dev_conf.fdir_conf.mode)) {
 		PMD_DEBUG_TRACE("port %d: pkt-filter disabled\n", port_id);
 		return (-ENOSYS);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fdir_set_masks, -ENOTSUP);
-	return (*dev->dev_ops->fdir_set_masks)(dev, fdir_mask);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, fdir_set_masks), -ENOTSUP);
+	return ETH_OPS(dev, fdir_set_masks)(dev, fdir_mask);
 }
 
 int
@@ -2368,9 +2311,9 @@ rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, flow_ctrl_get), -ENOTSUP);
 	memset(fc_conf, 0, sizeof(*fc_conf));
-	return (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf);
+	return ETH_OPS(dev, flow_ctrl_get)(dev, fc_conf);
 }
 
 int
@@ -2389,8 +2332,8 @@ rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP);
-	return (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, flow_ctrl_set), -ENOTSUP);
+	return ETH_OPS(dev, flow_ctrl_set)(dev, fc_conf);
 }
 
 int
@@ -2410,8 +2353,8 @@ rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc
 
 	dev = &rte_eth_devices[port_id];
 	/* High water, low water validation are device specific */
-	if  (*dev->dev_ops->priority_flow_ctrl_set)
-		return (*dev->dev_ops->priority_flow_ctrl_set)(dev, pfc_conf);
+	if  (ETH_OPS(dev, priority_flow_ctrl_set))
+		return ETH_OPS(dev, priority_flow_ctrl_set)(dev, pfc_conf);
 	return (-ENOTSUP);
 }
 
@@ -2491,12 +2434,12 @@ rte_eth_dev_rss_reta_update(uint8_t port_id,
 
 	/* Check entry value */
 	ret = rte_eth_check_reta_entry(reta_conf, reta_size,
-				dev->data->nb_rx_queues);
+				ETH_DATA(dev)->dd.nb_rx_queues);
 	if (ret < 0)
 		return ret;
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP);
-	return (*dev->dev_ops->reta_update)(dev, reta_conf, reta_size);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, reta_update), -ENOTSUP);
+	return ETH_OPS(dev, reta_update)(dev, reta_conf, reta_size);
 }
 
 int
@@ -2507,7 +2450,7 @@ rte_eth_dev_rss_reta_query(uint8_t port_id,
 	struct rte_eth_dev *dev;
 	int ret;
 
-	if (port_id >= nb_ports) {
+	if (port_id >= eth_globals.nb_ports) {
 		PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
 		return -ENODEV;
 	}
@@ -2518,8 +2461,8 @@ rte_eth_dev_rss_reta_query(uint8_t port_id,
 		return ret;
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP);
-	return (*dev->dev_ops->reta_query)(dev, reta_conf, reta_size);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, reta_query), -ENOTSUP);
+	return ETH_OPS(dev, reta_query)(dev, reta_conf, reta_size);
 }
 
 int
@@ -2541,8 +2484,8 @@ rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
 		return (-EINVAL);
 	}
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP);
-	return (*dev->dev_ops->rss_hash_update)(dev, rss_conf);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rss_hash_update), -ENOTSUP);
+	return ETH_OPS(dev, rss_hash_update)(dev, rss_conf);
 }
 
 int
@@ -2557,8 +2500,8 @@ rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP);
-	return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rss_hash_conf_get), -ENOTSUP);
+	return ETH_OPS(dev, rss_hash_conf_get)(dev, rss_conf);
 }
 
 int
@@ -2583,8 +2526,8 @@ rte_eth_dev_udp_tunnel_add(uint8_t port_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_add, -ENOTSUP);
-	return (*dev->dev_ops->udp_tunnel_add)(dev, udp_tunnel);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, udp_tunnel_add), -ENOTSUP);
+	return ETH_OPS(dev, udp_tunnel_add)(dev, udp_tunnel);
 }
 
 int
@@ -2610,8 +2553,8 @@ rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
 		return -EINVAL;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_del, -ENOTSUP);
-	return (*dev->dev_ops->udp_tunnel_del)(dev, udp_tunnel);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, udp_tunnel_del), -ENOTSUP);
+	return ETH_OPS(dev, udp_tunnel_del)(dev, udp_tunnel);
 }
 
 int
@@ -2625,8 +2568,8 @@ rte_eth_led_on(uint8_t port_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP);
-	return ((*dev->dev_ops->dev_led_on)(dev));
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_led_on), -ENOTSUP);
+	return ETH_OPS(dev, dev_led_on)(dev);
 }
 
 int
@@ -2640,8 +2583,8 @@ rte_eth_led_off(uint8_t port_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP);
-	return ((*dev->dev_ops->dev_led_off)(dev));
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, dev_led_off), -ENOTSUP);
+	return ETH_OPS(dev, dev_led_off)(dev);
 }
 
 /*
@@ -2658,7 +2601,7 @@ get_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
 	rte_eth_dev_info_get(port_id, &dev_info);
 
 	for (i = 0; i < dev_info.max_mac_addrs; i++)
-		if (memcmp(addr, &dev->data->mac_addrs[i], ETHER_ADDR_LEN) == 0)
+		if (memcmp(addr, &ETH_DATA(dev)->mac_addrs[i], ETHER_ADDR_LEN) == 0)
 			return i;
 
 	return -1;
@@ -2680,7 +2623,7 @@ rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, mac_addr_add), -ENOTSUP);
 
 	if (is_zero_ether_addr(addr)) {
 		PMD_DEBUG_TRACE("port %d: Cannot add NULL MAC address\n",
@@ -2701,7 +2644,7 @@ rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
 			return (-ENOSPC);
 		}
 	} else {
-		pool_mask = dev->data->mac_pool_sel[index];
+		pool_mask = ETH_DATA(dev)->mac_pool_sel[index];
 
 		/* Check if both MAC address and pool is alread there, and do nothing */
 		if (pool_mask & (1ULL << pool))
@@ -2709,13 +2652,13 @@ rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
 	}
 
 	/* Update NIC */
-	(*dev->dev_ops->mac_addr_add)(dev, addr, index, pool);
+	ETH_OPS(dev, mac_addr_add)(dev, addr, index, pool);
 
 	/* Update address in NIC data structure */
-	ether_addr_copy(addr, &dev->data->mac_addrs[index]);
+	ether_addr_copy(addr, &ETH_DATA(dev)->mac_addrs[index]);
 
 	/* Update pool bitmap in NIC data structure */
-	dev->data->mac_pool_sel[index] |= (1ULL << pool);
+	ETH_DATA(dev)->mac_pool_sel[index] |= (1ULL << pool);
 
 	return 0;
 }
@@ -2732,7 +2675,7 @@ rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, mac_addr_remove), -ENOTSUP);
 
 	index = get_mac_addr_index(port_id, addr);
 	if (index == 0) {
@@ -2742,13 +2685,13 @@ rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
 		return 0;  /* Do nothing if address wasn't found */
 
 	/* Update NIC */
-	(*dev->dev_ops->mac_addr_remove)(dev, index);
+	ETH_OPS(dev, mac_addr_remove)(dev, index);
 
 	/* Update address in NIC data structure */
-	ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
+	ether_addr_copy(&null_mac_addr, &ETH_DATA(dev)->mac_addrs[index]);
 
 	/* reset pool bitmap */
-	dev->data->mac_pool_sel[index] = 0;
+	ETH_DATA(dev)->mac_pool_sel[index] = 0;
 
 	return 0;
 }
@@ -2781,8 +2724,8 @@ rte_eth_dev_set_vf_rxmode(uint8_t port_id,  uint16_t vf,
 		PMD_DEBUG_TRACE("set VF RX mode:mode mask ca not be zero\n");
 		return (-EINVAL);
 	}
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx_mode, -ENOTSUP);
-	return (*dev->dev_ops->set_vf_rx_mode)(dev, vf, rx_mode, on);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, set_vf_rx_mode), -ENOTSUP);
+	return ETH_OPS(dev, set_vf_rx_mode)(dev, vf, rx_mode, on);
 }
 
 /*
@@ -2797,11 +2740,11 @@ get_hash_mac_addr_index(uint8_t port_id, struct ether_addr *addr)
 	unsigned i;
 
 	rte_eth_dev_info_get(port_id, &dev_info);
-	if (!dev->data->hash_mac_addrs)
+	if (!ETH_DATA(dev)->hash_mac_addrs)
 		return -1;
 
 	for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
-		if (memcmp(addr, &dev->data->hash_mac_addrs[i],
+		if (memcmp(addr, &ETH_DATA(dev)->hash_mac_addrs[i],
 			ETHER_ADDR_LEN) == 0)
 			return i;
 
@@ -2849,16 +2792,16 @@ rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
 		}
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP);
-	ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, uc_hash_table_set), -ENOTSUP);
+	ret = ETH_OPS(dev, uc_hash_table_set)(dev, addr, on);
 	if (ret == 0) {
 		/* Update address in NIC data structure */
 		if (on)
 			ether_addr_copy(addr,
-					&dev->data->hash_mac_addrs[index]);
+					&ETH_DATA(dev)->hash_mac_addrs[index]);
 		else
 			ether_addr_copy(&null_mac_addr,
-					&dev->data->hash_mac_addrs[index]);
+					&ETH_DATA(dev)->hash_mac_addrs[index]);
 	}
 
 	return ret;
@@ -2877,8 +2820,8 @@ rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
 
 	dev = &rte_eth_devices[port_id];
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP);
-	return (*dev->dev_ops->uc_all_hash_table_set)(dev, on);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, uc_all_hash_table_set), -ENOTSUP);
+	return ETH_OPS(dev, uc_all_hash_table_set)(dev, on);
 }
 
 int
@@ -2903,8 +2846,8 @@ rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
 		return (-EINVAL);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rx, -ENOTSUP);
-	return (*dev->dev_ops->set_vf_rx)(dev, vf,on);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, set_vf_rx), -ENOTSUP);
+	return ETH_OPS(dev, set_vf_rx)(dev, vf,on);
 }
 
 int
@@ -2929,8 +2872,8 @@ rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
 		return (-EINVAL);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_tx, -ENOTSUP);
-	return (*dev->dev_ops->set_vf_tx)(dev, vf,on);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, set_vf_tx), -ENOTSUP);
+	return ETH_OPS(dev, set_vf_tx)(dev, vf,on);
 }
 
 int
@@ -2958,8 +2901,8 @@ rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
 		return (-EINVAL);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_vlan_filter, -ENOTSUP);
-	return (*dev->dev_ops->set_vf_vlan_filter)(dev, vlan_id,
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, set_vf_vlan_filter), -ENOTSUP);
+	return ETH_OPS(dev, set_vf_vlan_filter)(dev, vlan_id,
 						vf_mask,vlan_on);
 }
 
@@ -2978,7 +2921,7 @@ int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
 
 	dev = &rte_eth_devices[port_id];
 	rte_eth_dev_info_get(port_id, &dev_info);
-	link = dev->data->dev_link;
+	link = ETH_DATA(dev)->dev_link;
 
 	if (queue_idx > dev_info.max_tx_queues) {
 		PMD_DEBUG_TRACE("set queue rate limit:port %d: "
@@ -2993,8 +2936,8 @@ int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
 		return -EINVAL;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP);
-	return (*dev->dev_ops->set_queue_rate_limit)(dev, queue_idx, tx_rate);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, set_queue_rate_limit), -ENOTSUP);
+	return ETH_OPS(dev, set_queue_rate_limit)(dev, queue_idx, tx_rate);
 }
 
 int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
@@ -3015,7 +2958,7 @@ int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
 
 	dev = &rte_eth_devices[port_id];
 	rte_eth_dev_info_get(port_id, &dev_info);
-	link = dev->data->dev_link;
+	link = ETH_DATA(dev)->dev_link;
 
 	if (vf > dev_info.max_vfs) {
 		PMD_DEBUG_TRACE("set VF rate limit:port %d: "
@@ -3030,8 +2973,8 @@ int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
 		return -EINVAL;
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_vf_rate_limit, -ENOTSUP);
-	return (*dev->dev_ops->set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, set_vf_rate_limit), -ENOTSUP);
+	return ETH_OPS(dev, set_vf_rate_limit)(dev, vf, tx_rate, q_msk);
 }
 
 int
@@ -3072,9 +3015,9 @@ rte_eth_mirror_rule_set(uint8_t port_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_set, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, mirror_rule_set), -ENOTSUP);
 
-	return (*dev->dev_ops->mirror_rule_set)(dev, mirror_conf, rule_id, on);
+	return ETH_OPS(dev, mirror_rule_set)(dev, mirror_conf, rule_id, on);
 }
 
 int
@@ -3095,9 +3038,9 @@ rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mirror_rule_reset, -ENOTSUP);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, mirror_rule_reset), -ENOTSUP);
 
-	return (*dev->dev_ops->mirror_rule_reset)(dev, rule_id);
+	return ETH_OPS(dev, mirror_rule_reset)(dev, rule_id);
 }
 
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
@@ -3113,12 +3056,12 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0);
-	if (queue_id >= dev->data->nb_rx_queues) {
+	FUNC_PTR_OR_ERR_RET(dev->rx_pkt_burst, 0);
+	if (queue_id >= ETH_DATA(dev)->dd.nb_rx_queues) {
 		PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", queue_id);
 		return 0;
 	}
-	return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
+	return (*dev->rx_pkt_burst)(ETH_DATA(dev)->dd.rx_queues[queue_id],
 						rx_pkts, nb_pkts);
 }
 
@@ -3136,11 +3079,11 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
 	dev = &rte_eth_devices[port_id];
 
 	FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0);
-	if (queue_id >= dev->data->nb_tx_queues) {
+	if (queue_id >= ETH_DATA(dev)->dd.nb_tx_queues) {
 		PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", queue_id);
 		return 0;
 	}
-	return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id],
+	return (*dev->tx_pkt_burst)(ETH_DATA(dev)->dd.tx_queues[queue_id],
 						tx_pkts, nb_pkts);
 }
 
@@ -3155,8 +3098,8 @@ rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0);
-	return (*dev->dev_ops->rx_queue_count)(dev, queue_id);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rx_queue_count), 0);
+	return ETH_OPS(dev, rx_queue_count)(dev, queue_id);
 }
 
 int
@@ -3170,19 +3113,18 @@ rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP);
-	return (*dev->dev_ops->rx_descriptor_done)( \
-		dev->data->rx_queues[queue_id], offset);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, rx_descriptor_done), -ENOTSUP);
+	return ETH_OPS(dev, rx_descriptor_done)
+			(ETH_DATA(dev)->rx_queues[queue_id], offset);
 }
 #endif
 
 int
 rte_eth_dev_callback_register(uint8_t port_id,
-			enum rte_eth_event_type event,
-			rte_eth_dev_cb_fn cb_fn, void *cb_arg)
+			enum rte_dev_event_type event,
+			rte_dev_cb_fn cb_fn, void *cb_arg)
 {
 	struct rte_eth_dev *dev;
-	struct rte_eth_dev_callback *user_cb;
 
 	if (!cb_fn)
 		return (-EINVAL);
@@ -3193,37 +3135,16 @@ rte_eth_dev_callback_register(uint8_t port_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	rte_spinlock_lock(&rte_eth_dev_cb_lock);
-
-	TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
-		if (user_cb->cb_fn == cb_fn &&
-			user_cb->cb_arg == cb_arg &&
-			user_cb->event == event) {
-			break;
-		}
-	}
-
-	/* create a new callback. */
-	if (user_cb == NULL && (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
-			sizeof(struct rte_eth_dev_callback), 0)) != NULL) {
-		user_cb->cb_fn = cb_fn;
-		user_cb->cb_arg = cb_arg;
-		user_cb->event = event;
-		TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
-	}
-
-	rte_spinlock_unlock(&rte_eth_dev_cb_lock);
-	return ((user_cb == NULL) ? -ENOMEM : 0);
+	return rte_dev_callback_register(&dev->link_intr_cbs,
+				&rte_eth_dev_cb_lock, event, cb_fn, cb_arg);
 }
 
 int
 rte_eth_dev_callback_unregister(uint8_t port_id,
-			enum rte_eth_event_type event,
-			rte_eth_dev_cb_fn cb_fn, void *cb_arg)
+			enum rte_dev_event_type event,
+			rte_dev_cb_fn cb_fn, void *cb_arg)
 {
-	int ret;
 	struct rte_eth_dev *dev;
-	struct rte_eth_dev_callback *cb, *next;
 
 	if (!cb_fn)
 		return (-EINVAL);
@@ -3234,55 +3155,18 @@ rte_eth_dev_callback_unregister(uint8_t port_id,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	rte_spinlock_lock(&rte_eth_dev_cb_lock);
-
-	ret = 0;
-	for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) {
-
-		next = TAILQ_NEXT(cb, next);
-
-		if (cb->cb_fn != cb_fn || cb->event != event ||
-				(cb->cb_arg != (void *)-1 &&
-				cb->cb_arg != cb_arg))
-			continue;
-
-		/*
-		 * if this callback is not executing right now,
-		 * then remove it.
-		 */
-		if (cb->active == 0) {
-			TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
-			rte_free(cb);
-		} else {
-			ret = -EAGAIN;
-		}
-	}
-
-	rte_spinlock_unlock(&rte_eth_dev_cb_lock);
-	return (ret);
+	return rte_dev_callback_unregister(&dev->link_intr_cbs,
+				&rte_eth_dev_cb_lock, event, cb_fn, cb_arg);
 }
 
 void
 _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
-	enum rte_eth_event_type event)
+	enum rte_dev_event_type event)
 {
-	struct rte_eth_dev_callback *cb_lst;
-	struct rte_eth_dev_callback dev_cb;
-
-	rte_spinlock_lock(&rte_eth_dev_cb_lock);
-	TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) {
-		if (cb_lst->cb_fn == NULL || cb_lst->event != event)
-			continue;
-		dev_cb = *cb_lst;
-		cb_lst->active = 1;
-		rte_spinlock_unlock(&rte_eth_dev_cb_lock);
-		dev_cb.cb_fn(dev->data->port_id, dev_cb.event,
-						dev_cb.cb_arg);
-		rte_spinlock_lock(&rte_eth_dev_cb_lock);
-		cb_lst->active = 0;
-	}
-	rte_spinlock_unlock(&rte_eth_dev_cb_lock);
+	rte_dev_callback_process(&dev->link_intr_cbs, ETH_DATA(dev)->dd.port_id,
+			event, &rte_eth_dev_cb_lock);
 }
+
 #ifdef RTE_NIC_BYPASS
 int rte_eth_dev_bypass_init(uint8_t port_id)
 {
@@ -3298,8 +3182,8 @@ int rte_eth_dev_bypass_init(uint8_t port_id)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_init, -ENOTSUP);
-	(*dev->dev_ops->bypass_init)(dev);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_init), -ENOTSUP);
+	ETH_OPS(dev, bypass_init)(dev);
 	return 0;
 }
 
@@ -3317,8 +3201,8 @@ rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
 		PMD_DEBUG_TRACE("Invalid port device\n");
 		return (-ENODEV);
 	}
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
-	(*dev->dev_ops->bypass_state_show)(dev, state);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_state_show), -ENOTSUP);
+	ETH_OPS(dev, bypass_state_show)(dev, state);
 	return 0;
 }
 
@@ -3337,8 +3221,8 @@ rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_set, -ENOTSUP);
-	(*dev->dev_ops->bypass_state_set)(dev, new_state);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_state_set), -ENOTSUP);
+	ETH_OPS(dev, bypass_state_set)(dev, new_state);
 	return 0;
 }
 
@@ -3357,8 +3241,8 @@ rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_state_show, -ENOTSUP);
-	(*dev->dev_ops->bypass_event_show)(dev, event, state);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_state_show), -ENOTSUP);
+	ETH_OPS(dev, bypass_event_show)(dev, event, state);
 	return 0;
 }
 
@@ -3377,8 +3261,8 @@ rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_event_set, -ENOTSUP);
-	(*dev->dev_ops->bypass_event_set)(dev, event, state);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_event_set), -ENOTSUP);
+	ETH_OPS(dev, bypass_event_set)(dev, event, state);
 	return 0;
 }
 
@@ -3397,8 +3281,8 @@ rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_set, -ENOTSUP);
-	(*dev->dev_ops->bypass_wd_timeout_set)(dev, timeout);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_wd_timeout_set), -ENOTSUP);
+	ETH_OPS(dev, bypass_wd_timeout_set)(dev, timeout);
 	return 0;
 }
 
@@ -3417,8 +3301,8 @@ rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_ver_show, -ENOTSUP);
-	(*dev->dev_ops->bypass_ver_show)(dev, ver);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_ver_show), -ENOTSUP);
+	ETH_OPS(dev, bypass_ver_show)(dev, ver);
 	return 0;
 }
 
@@ -3437,8 +3321,8 @@ rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_timeout_show, -ENOTSUP);
-	(*dev->dev_ops->bypass_wd_timeout_show)(dev, wd_timeout);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_wd_timeout_show), -ENOTSUP);
+	ETH_OPS(dev, bypass_wd_timeout_show)(dev, wd_timeout);
 	return 0;
 }
 
@@ -3457,8 +3341,8 @@ rte_eth_dev_bypass_wd_reset(uint8_t port_id)
 		return (-ENODEV);
 	}
 
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->bypass_wd_reset, -ENOTSUP);
-	(*dev->dev_ops->bypass_wd_reset)(dev);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, bypass_wd_reset), -ENOTSUP);
+	ETH_OPS(dev, bypass_wd_reset)(dev);
 	return 0;
 }
 #endif
@@ -3474,8 +3358,8 @@ rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
-	return (*dev->dev_ops->filter_ctrl)(dev, filter_type,
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, filter_ctrl), -ENOTSUP);
+	return ETH_OPS(dev, filter_ctrl)(dev, filter_type,
 				RTE_ETH_FILTER_NOP, NULL);
 }
 
@@ -3491,8 +3375,8 @@ rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
 	}
 
 	dev = &rte_eth_devices[port_id];
-	FUNC_PTR_OR_ERR_RET(*dev->dev_ops->filter_ctrl, -ENOTSUP);
-	return (*dev->dev_ops->filter_ctrl)(dev, filter_type, filter_op, arg);
+	FUNC_PTR_OR_ERR_RET(ETH_OPS(dev, filter_ctrl), -ENOTSUP);
+	return ETH_OPS(dev, filter_ctrl)(dev, filter_type, filter_op, arg);
 }
 
 void *
@@ -3505,23 +3389,12 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
 #endif
 	/* check input parameters */
 	if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
-		    queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
+		    queue_id >= ETH_DATA(&rte_eth_devices[port_id])->dd.nb_rx_queues) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
 
-	struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
-
-	if (cb == NULL) {
-		rte_errno = ENOMEM;
-		return NULL;
-	}
-
-	cb->fn.rx = fn;
-	cb->param = user_param;
-	cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
-	rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
-	return cb;
+	return rte_dev_add_callback(&rte_eth_devices[port_id].post_rx_burst_cbs[queue_id], fn, user_param);
 }
 
 void *
@@ -3534,99 +3407,46 @@ rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
 #endif
 	/* check input parameters */
 	if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
-		    queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
+		    queue_id >= ETH_DATA(&rte_eth_devices[port_id])->dd.nb_tx_queues) {
 		rte_errno = EINVAL;
 		return NULL;
 	}
 
-	struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
-
-	if (cb == NULL) {
-		rte_errno = ENOMEM;
-		return NULL;
-	}
-
-	cb->fn.tx = fn;
-	cb->param = user_param;
-	cb->next = rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
-	rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
-	return cb;
+	return rte_dev_add_callback(&rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id], fn, user_param);
 }
 
 int
 rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
-		struct rte_eth_rxtx_callback *user_cb)
+		struct rte_dev_rxtx_callback *user_cb)
 {
 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
 	return (-ENOTSUP);
 #endif
 	/* Check input parameters. */
 	if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
-		    queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
+		    queue_id >= ETH_DATA(&rte_eth_devices[port_id])->dd.nb_rx_queues) {
 		return (-EINVAL);
 	}
 
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
-	struct rte_eth_rxtx_callback *prev_cb;
-
-	/* Reset head pointer and remove user cb if first in the list. */
-	if (cb == user_cb) {
-		dev->post_rx_burst_cbs[queue_id] = user_cb->next;
-		return 0;
-	}
-
-	/* Remove the user cb from the callback list. */
-	do {
-		prev_cb = cb;
-		cb = cb->next;
-
-		if (cb == user_cb) {
-			prev_cb->next = user_cb->next;
-			return 0;
-		}
-
-	} while (cb != NULL);
 
-	/* Callback wasn't found. */
-	return (-EINVAL);
+	return rte_dev_remove_callback(&dev->post_rx_burst_cbs[queue_id], user_cb);
 }
 
 int
 rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
-		struct rte_eth_rxtx_callback *user_cb)
+		struct rte_dev_rxtx_callback *user_cb)
 {
 #ifndef RTE_ETHDEV_RXTX_CALLBACKS
 	return (-ENOTSUP);
 #endif
 	/* Check input parameters. */
 	if (!rte_eth_dev_is_valid_port(port_id) || user_cb == NULL ||
-		    queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
+		    queue_id >= ETH_DATA(&rte_eth_devices[port_id])->dd.nb_tx_queues) {
 		return (-EINVAL);
 	}
 
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
-	struct rte_eth_rxtx_callback *prev_cb;
-
-	/* Reset head pointer and remove user cb if first in the list. */
-	if (cb == user_cb) {
-		dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
-		return 0;
-	}
-
-	/* Remove the user cb from the callback list. */
-	do {
-		prev_cb = cb;
-		cb = cb->next;
-
-		if (cb == user_cb) {
-			prev_cb->next = user_cb->next;
-			return 0;
-		}
-
-	} while (cb != NULL);
 
-	/* Callback wasn't found. */
-	return (-EINVAL);
+	return rte_dev_remove_callback(&dev->pre_tx_burst_cbs[queue_id], user_cb);
 }
lib/librte_ether/rte_ethdev.h +84 -256

501 lines not on this page · raw message

Signature · 1 line
2.3.0
#8 lore raw

RFC PATCH v2 3/4 Add the test file changes for common device support

In reply to a message not in the archive
---
 app/test-pmd/config.c                 |   6 +-
 app/test-pmd/testpmd.h                |   4 +-
 app/test/test_kni.c                   |  12 ++--
 app/test/test_link_bonding.c          |  24 ++++----
 app/test/virtual_pmd.c                | 106 +++++++++++++++++-----------------
 examples/link_status_interrupt/main.c |   6 +-
 6 files changed, 79 insertions(+), 79 deletions(-)
app/test-pmd/config.c +3 -3
index f788ed5..6e70add 100644
@@ -415,7 +415,7 @@ port_reg_off_is_invalid(portid_t port_id, uint32_t reg_off)
 		       (unsigned)reg_off);
 		return 1;
 	}
-	pci_len = ports[port_id].dev_info.pci_dev->mem_resource[0].len;
+	pci_len = ports[port_id].dev_info.di.pci_dev->mem_resource[0].len;
 	if (reg_off >= pci_len) {
 		printf("Port %d: register offset %u (0x%X) out of port PCI "
 		       "resource (length=%"PRIu64")\n",
@@ -641,7 +641,7 @@ ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id)
 	const struct rte_memzone *mz;
 
 	snprintf(mz_name, sizeof(mz_name), "%s_%s_%d_%d",
-		 ports[port_id].dev_info.driver_name, ring_name, port_id, q_id);
+		 ports[port_id].dev_info.di.driver_name, ring_name, port_id, q_id);
 	mz = rte_memzone_lookup(mz_name);
 	if (mz == NULL)
 		printf("%s ring memory zoneof (port %d, queue %d) not"
@@ -698,7 +698,7 @@ ring_rx_descriptor_display(const struct rte_memzone *ring_mz,
 
 	memset(&dev_info, 0, sizeof(dev_info));
 	rte_eth_dev_info_get(port_id, &dev_info);
-	if (strstr(dev_info.driver_name, "i40e") != NULL) {
+	if (strstr(dev_info.di.driver_name, "i40e") != NULL) {
 		/* 32 bytes RX descriptor, i40e only */
 		struct igb_ring_desc_32_bytes *ring =
 			(struct igb_ring_desc_32_bytes *)ring_mz->addr;
app/test-pmd/testpmd.h +2 -2
index 389fc24..af4e280 100644
@@ -438,7 +438,7 @@ port_pci_reg_read(struct rte_port *port, uint32_t reg_off)
 	uint32_t reg_v;
 
 	reg_addr = (void *)
-		((char *)port->dev_info.pci_dev->mem_resource[0].addr +
+		((char *)port->dev_info.di.pci_dev->mem_resource[0].addr +
 			reg_off);
 	reg_v = *((volatile uint32_t *)reg_addr);
 	return rte_le_to_cpu_32(reg_v);
@@ -453,7 +453,7 @@ port_pci_reg_write(struct rte_port *port, uint32_t reg_off, uint32_t reg_v)
 	void *reg_addr;
 
 	reg_addr = (void *)
-		((char *)port->dev_info.pci_dev->mem_resource[0].addr +
+		((char *)port->dev_info.di.pci_dev->mem_resource[0].addr +
 			reg_off);
 	*((volatile uint32_t *)reg_addr) = rte_cpu_to_le_32(reg_v);
 }
app/test/test_kni.c +6 -6
index 608901d..456dd65 100644
@@ -387,8 +387,8 @@ test_kni_processing(uint8_t port_id, struct rte_mempool *mp)
 	memset(&ops, 0, sizeof(ops));
 
 	rte_eth_dev_info_get(port_id, &info);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+	conf.addr = info.di.pci_dev->addr;
+	conf.id = info.di.pci_dev->id;
 	snprintf(conf.name, sizeof(conf.name), TEST_KNI_PORT);
 
 	/* core id 1 configured for kernel thread */
@@ -555,8 +555,8 @@ test_kni(void)
 	memset(&conf, 0, sizeof(conf));
 	memset(&ops, 0, sizeof(ops));
 	rte_eth_dev_info_get(port_id, &info);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+	conf.addr = info.di.pci_dev->addr;
+	conf.id = info.di.pci_dev->id;
 	conf.group_id = (uint16_t)port_id;
 	conf.mbuf_size = MAX_PACKET_SZ;
 
@@ -584,8 +584,8 @@ test_kni(void)
 	memset(&info, 0, sizeof(info));
 	memset(&ops, 0, sizeof(ops));
 	rte_eth_dev_info_get(port_id, &info);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+	conf.addr = info.di.pci_dev->addr;
+	conf.id = info.di.pci_dev->id;
 	conf.group_id = (uint16_t)port_id;
 	conf.mbuf_size = MAX_PACKET_SZ;
 
app/test/test_link_bonding.c +12 -12
index 8c24314..20e74c3 100644
@@ -1179,7 +1179,7 @@ int test_lsc_interrupt_count;
 
 static void
 test_bonding_lsc_event_callback(uint8_t port_id __rte_unused,
-		enum rte_eth_event_type type  __rte_unused, void *param __rte_unused)
+		enum rte_dev_event_type type  __rte_unused, void *param __rte_unused)
 {
 	pthread_mutex_lock(&mutex);
 	test_lsc_interrupt_count++;
@@ -1231,7 +1231,7 @@ test_status_interrupt(void)
 
 	/* register link status change interrupt callback */
 	rte_eth_dev_callback_register(test_params->bonded_port_id,
-			RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
+			RTE_DEV_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
 			&test_params->bonded_port_id);
 
 	slave_count = rte_eth_bond_active_slaves_get(test_params->bonded_port_id,
@@ -1298,7 +1298,7 @@ test_status_interrupt(void)
 
 	/* unregister lsc callback before exiting */
 	rte_eth_dev_callback_unregister(test_params->bonded_port_id,
-				RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
+				RTE_DEV_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
 				&test_params->bonded_port_id);
 
 	/* Clean up and remove slaves from bonded device */
@@ -2031,7 +2031,7 @@ test_roundrobin_verfiy_polling_slave_link_status_change(void)
 
 	/* Register link status change interrupt callback */
 	rte_eth_dev_callback_register(test_params->bonded_port_id,
-			RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
+			RTE_DEV_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
 			&test_params->bonded_port_id);
 
 	/* link status change callback for first slave link up */
@@ -2059,7 +2059,7 @@ test_roundrobin_verfiy_polling_slave_link_status_change(void)
 
 	/* Un-Register link status change interrupt callback */
 	rte_eth_dev_callback_unregister(test_params->bonded_port_id,
-			RTE_ETH_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
+			RTE_DEV_EVENT_INTR_LSC, test_bonding_lsc_event_callback,
 			&test_params->bonded_port_id);
 
 
@@ -4590,7 +4590,7 @@ test_alb_change_mac_in_reply_sent(void)
 	}
 
 	ether_addr_copy(
-			rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
+			ETH_DATA(&rte_eth_devices[test_params->bonded_port_id])->mac_addrs,
 			&bond_mac);
 
 	/*
@@ -4638,9 +4638,9 @@ test_alb_change_mac_in_reply_sent(void)
 	rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
 
 	slave_mac1 =
-			rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
+			ETH_DATA(&rte_eth_devices[test_params->slave_port_ids[0]])->mac_addrs;
 	slave_mac2 =
-			rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
+			ETH_DATA(&rte_eth_devices[test_params->slave_port_ids[1]])->mac_addrs;
 
 	/*
 	 * Checking if packets are properly distributed on bonding ports. Packets
@@ -4703,7 +4703,7 @@ test_alb_reply_from_client(void)
 	}
 
 	ether_addr_copy(
-			rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
+			ETH_DATA(&rte_eth_devices[test_params->bonded_port_id])->mac_addrs,
 			&bond_mac);
 
 	/*
@@ -4761,8 +4761,8 @@ test_alb_reply_from_client(void)
 	rte_eth_rx_burst(test_params->bonded_port_id, 0, pkts_sent, MAX_PKT_BURST);
 	rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
 
-	slave_mac1 = rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
-	slave_mac2 = rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
+	slave_mac1 = ETH_DATA(&rte_eth_devices[test_params->slave_port_ids[0]])->mac_addrs;
+	slave_mac2 = ETH_DATA(&rte_eth_devices[test_params->slave_port_ids[1]])->mac_addrs;
 
 	/*
 	 * Checking if update ARP packets were properly send on slave ports.
@@ -4830,7 +4830,7 @@ test_alb_receive_vlan_reply(void)
 	}
 
 	ether_addr_copy(
-			rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
+			ETH_DATA(&rte_eth_devices[test_params->bonded_port_id])->mac_addrs,
 			&bond_mac);
 
 	/*
app/test/virtual_pmd.c +53 -53

295 lines not on this page · raw message

examples/link_status_interrupt/main.c +3 -3
index e6fb218..9e31028 100644
@@ -516,14 +516,14 @@ lsi_parse_args(int argc, char **argv)
  *  void.
  */
 static void
-lsi_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param)
+lsi_event_callback(uint8_t port_id, enum rte_dev_event_type type, void *param)
 {
 	struct rte_eth_link link;
 
 	RTE_SET_USED(param);
 
 	printf("\n\nIn registered callback...\n");
-	printf("Event type: %s\n", type == RTE_ETH_EVENT_INTR_LSC ? "LSC interrupt" : "unknown event");
+	printf("Event type: %s\n", type == RTE_DEV_EVENT_INTR_LSC ? "LSC interrupt" : "unknown event");
 	rte_eth_link_get_nowait(port_id, &link);
 	if (link.link_status) {
 		printf("Port %d Link Up - speed %u Mbps - %s\n\n",
@@ -703,7 +703,7 @@ main(int argc, char **argv)
 		 * be registered will never be called.
 		 */
 		rte_eth_dev_callback_register(portid,
-			RTE_ETH_EVENT_INTR_LSC, lsi_event_callback, NULL);
+			RTE_DEV_EVENT_INTR_LSC, lsi_event_callback, NULL);
 
 		rte_eth_macaddr_get(portid,
 				    &lsi_ports_eth_addr[portid]);
Signature · 1 line
2.3.0
#9 lore raw

RFC PATCH v2 4/4 Update PMD files for new common device support

In reply to a message not in the archive
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c |  38 +--
 lib/librte_pmd_bond/rte_eth_bond_8023ad.c    |  18 +-
 lib/librte_pmd_bond/rte_eth_bond_alb.c       |  10 +-
 lib/librte_pmd_bond/rte_eth_bond_api.c       | 142 +++++-----
 lib/librte_pmd_bond/rte_eth_bond_args.c      |   2 +-
 lib/librte_pmd_bond/rte_eth_bond_pmd.c       | 164 +++++------
 lib/librte_pmd_bond/rte_eth_bond_private.h   |   2 +-
 lib/librte_pmd_e1000/em_ethdev.c             | 156 +++++------
 lib/librte_pmd_e1000/em_rxtx.c               |  94 +++----
 lib/librte_pmd_e1000/igb_ethdev.c            | 302 ++++++++++-----------
 lib/librte_pmd_e1000/igb_pf.c                |  86 +++---
 lib/librte_pmd_e1000/igb_rxtx.c              | 168 ++++++------
 lib/librte_pmd_enic/enic.h                   |   4 +-
 lib/librte_pmd_enic/enic_ethdev.c            | 140 +++++-----
 lib/librte_pmd_enic/enic_main.c              |  30 +-
 lib/librte_pmd_fm10k/fm10k_ethdev.c          | 154 +++++------
 lib/librte_pmd_fm10k/fm10k_rxtx.c            |   4 +-
 lib/librte_pmd_i40e/i40e_ethdev.c            | 172 ++++++------
 lib/librte_pmd_i40e/i40e_ethdev_vf.c         | 194 ++++++-------
 lib/librte_pmd_i40e/i40e_fdir.c              |  28 +-
 lib/librte_pmd_i40e/i40e_pf.c                |   8 +-
 lib/librte_pmd_i40e/i40e_rxtx.c              |  88 +++---
 lib/librte_pmd_ixgbe/ixgbe_ethdev.c          | 392 +++++++++++++--------------
 lib/librte_pmd_ixgbe/ixgbe_fdir.c            |  50 ++--
 lib/librte_pmd_ixgbe/ixgbe_pf.c              | 114 ++++----
 lib/librte_pmd_ixgbe/ixgbe_rxtx.c            | 276 +++++++++----------
 lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c        |   6 +-
 lib/librte_pmd_mlx4/mlx4.c                   |   2 +-
 lib/librte_pmd_null/rte_eth_null.c           |  36 +--
 lib/librte_pmd_pcap/rte_eth_pcap.c           |   2 +-
 lib/librte_pmd_ring/rte_eth_ring.c           |  36 +--
 lib/librte_pmd_virtio/virtio_ethdev.c        | 120 ++++----
 lib/librte_pmd_virtio/virtio_rxtx.c          |  20 +-
 lib/librte_pmd_vmxnet3/vmxnet3_ethdev.c      |  64 ++---
 lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c        |  40 +--
 lib/librte_pmd_xenvirt/rte_eth_xenvirt.c     |   2 +-
 36 files changed, 1580 insertions(+), 1584 deletions(-)
lib/librte_pmd_af_packet/rte_eth_af_packet.c +19 -19
index 2ac50ba..4735fb3 100644
@@ -231,7 +231,7 @@ eth_af_packet_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 static int
 eth_dev_start(struct rte_eth_dev *dev)
 {
-	dev->data->dev_link.link_status = 1;
+	ETH_DATA(dev)->dev_link.link_status = 1;
 	return 0;
 }
 
@@ -243,7 +243,7 @@ eth_dev_stop(struct rte_eth_dev *dev)
 {
 	unsigned i;
 	int sockfd;
-	struct pmd_internals *internals = dev->data->dev_private;
+	struct pmd_internals *internals = _DD_PRIVATE(dev);
 
 	for (i = 0; i < internals->nb_queues; i++) {
 		sockfd = internals->rx_queue[i].sockfd;
@@ -254,7 +254,7 @@ eth_dev_stop(struct rte_eth_dev *dev)
 			close(sockfd);
 	}
 
-	dev->data->dev_link.link_status = 0;
+	ETH_DATA(dev)->dev_link.link_status = 0;
 }
 
 static int
@@ -266,16 +266,16 @@ eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
 static void
 eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
-	struct pmd_internals *internals = dev->data->dev_private;
+	struct pmd_internals *internals = _DD_PRIVATE(dev);
 
-	dev_info->driver_name = drivername;
-	dev_info->if_index = internals->if_index;
+	dev_info->di.driver_name = drivername;
+	dev_info->di.if_index = internals->if_index;
 	dev_info->max_mac_addrs = 1;
 	dev_info->max_rx_pktlen = (uint32_t)ETH_FRAME_LEN;
 	dev_info->max_rx_queues = (uint16_t)internals->nb_queues;
 	dev_info->max_tx_queues = (uint16_t)internals->nb_queues;
 	dev_info->min_rx_bufsize = 0;
-	dev_info->pci_dev = NULL;
+	dev_info->di.pci_dev = NULL;
 }
 
 static void
@@ -283,7 +283,7 @@ eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *igb_stats)
 {
 	unsigned i, imax;
 	unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
-	const struct pmd_internals *internal = dev->data->dev_private;
+	const struct pmd_internals *internal = _DD_PRIVATE(dev);
 
 	imax = (internal->nb_queues < RTE_ETHDEV_QUEUE_STAT_CNTRS ?
 	        internal->nb_queues : RTE_ETHDEV_QUEUE_STAT_CNTRS);
@@ -310,7 +310,7 @@ static void
 eth_stats_reset(struct rte_eth_dev *dev)
 {
 	unsigned i;
-	struct pmd_internals *internal = dev->data->dev_private;
+	struct pmd_internals *internal = _DD_PRIVATE(dev);
 
 	for (i = 0; i < internal->nb_queues; i++)
 		internal->rx_queue[i].rx_pkts = 0;
@@ -346,7 +346,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
                    const struct rte_eth_rxconf *rx_conf __rte_unused,
                    struct rte_mempool *mb_pool)
 {
-	struct pmd_internals *internals = dev->data->dev_private;
+	struct pmd_internals *internals = _DD_PRIVATE(dev);
 	struct pkt_rx_queue *pkt_q = &internals->rx_queue[rx_queue_id];
 	struct rte_pktmbuf_pool_private *mbp_priv;
 	uint16_t buf_size;
@@ -361,11 +361,11 @@ eth_rx_queue_setup(struct rte_eth_dev *dev,
 	if (ETH_FRAME_LEN > buf_size) {
 		RTE_LOG(ERR, PMD,
 			"%s: %d bytes will not fit in mbuf (%d bytes)\n",
-			dev->data->name, ETH_FRAME_LEN, buf_size);
+			_DD(dev, name), ETH_FRAME_LEN, buf_size);
 		return -ENOMEM;
 	}
 
-	dev->data->rx_queues[rx_queue_id] = pkt_q;
+	_DD(dev, rx_queues[rx_queue_id]) = pkt_q;
 
 	return 0;
 }
@@ -378,9 +378,9 @@ eth_tx_queue_setup(struct rte_eth_dev *dev,
                    const struct rte_eth_txconf *tx_conf __rte_unused)
 {
 
-	struct pmd_internals *internals = dev->data->dev_private;
+	struct pmd_internals *internals = _DD_PRIVATE(dev);
 
-	dev->data->tx_queues[tx_queue_id] = &internals->tx_queue[tx_queue_id];
+	_DD(dev, tx_queues[tx_queue_id]) = &internals->tx_queue[tx_queue_id];
 	return 0;
 }
 
@@ -650,7 +650,7 @@ rte_pmd_init_internals(const char *name,
 	}
 
 	/* reserve an ethdev entry */
-	*eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+	*eth_dev = rte_eth_dev_allocate(name, RTE_DEV_VIRTUAL);
 	if (*eth_dev == NULL)
 		goto error;
 
@@ -664,10 +664,10 @@ rte_pmd_init_internals(const char *name,
 
 	(*internals)->nb_queues = nb_queues;
 
-	data->dev_private = *internals;
-	data->port_id = (*eth_dev)->data->port_id;
-	data->nb_rx_queues = (uint16_t)nb_queues;
-	data->nb_tx_queues = (uint16_t)nb_queues;
+	data->dd.dev_private = *internals;
+	data->dd.port_id = _DD((*eth_dev), port_id);
+	data->dd.nb_rx_queues = (uint16_t)nb_queues;
+	data->dd.nb_tx_queues = (uint16_t)nb_queues;
 	data->dev_link = pmd_link;
 	data->mac_addrs = &(*internals)->eth_addr;
 
lib/librte_pmd_bond/rte_eth_bond_8023ad.c +9 -9
index 97a828e..3b6424e 100644
@@ -741,7 +741,7 @@ static void
 bond_mode_8023ad_periodic_cb(void *arg)
 {
 	struct rte_eth_dev *bond_dev = arg;
-	struct bond_dev_private *internals = bond_dev->data->dev_private;
+	struct bond_dev_private *internals = _DD(bond_dev, dev_private);
 	struct port *port;
 	struct rte_eth_link link_info;
 	struct ether_addr slave_addr;
@@ -837,7 +837,7 @@ bond_mode_8023ad_periodic_cb(void *arg)
 void
 bond_mode_8023ad_activate_slave(struct rte_eth_dev *bond_dev, uint8_t slave_id)
 {
-	struct bond_dev_private *internals = bond_dev->data->dev_private;
+	struct bond_dev_private *internals = _DD(bond_dev, dev_private);
 
 	struct port *port = &mode_8023ad_ports[slave_id];
 	struct port_params initial = {
@@ -927,7 +927,7 @@ int
 bond_mode_8023ad_deactivate_slave(struct rte_eth_dev *bond_dev,
 		uint8_t slave_id)
 {
-	struct bond_dev_private *internals = bond_dev->data->dev_private;
+	struct bond_dev_private *internals = _DD(bond_dev, dev_private);
 	void *pkt = NULL;
 	struct port *port;
 	uint8_t i;
@@ -966,7 +966,7 @@ bond_mode_8023ad_deactivate_slave(struct rte_eth_dev *bond_dev,
 void
 bond_mode_8023ad_mac_address_update(struct rte_eth_dev *bond_dev)
 {
-	struct bond_dev_private *internals = bond_dev->data->dev_private;
+	struct bond_dev_private *internals = _DD(bond_dev, dev_private);
 	struct ether_addr slave_addr;
 	struct port *slave, *agg_slave;
 	uint8_t slave_id, i, j;
@@ -994,7 +994,7 @@ bond_mode_8023ad_mac_address_update(struct rte_eth_dev *bond_dev)
 		}
 	}
 
-	if (bond_dev->data->dev_started)
+	if (ETH_DATA(bond_dev)->dev_started)
 		bond_mode_8023ad_start(bond_dev);
 }
 
@@ -1002,7 +1002,7 @@ void
 bond_mode_8023ad_conf_get(struct rte_eth_dev *dev,
 		struct rte_eth_bond_8023ad_conf *conf)
 {
-	struct bond_dev_private *internals = dev->data->dev_private;
+	struct bond_dev_private *internals = _DD_PRIVATE(dev);
 	struct mode8023ad_private *mode4 = &internals->mode4;
 	uint64_t ms_ticks = rte_get_tsc_hz() / 1000;
 
@@ -1020,7 +1020,7 @@ bond_mode_8023ad_setup(struct rte_eth_dev *dev,
 		struct rte_eth_bond_8023ad_conf *conf)
 {
 	struct rte_eth_bond_8023ad_conf def_conf;
-	struct bond_dev_private *internals = dev->data->dev_private;
+	struct bond_dev_private *internals = _DD_PRIVATE(dev);
 	struct mode8023ad_private *mode4 = &internals->mode4;
 	uint64_t ms_ticks = rte_get_tsc_hz() / 1000;
 
@@ -1049,7 +1049,7 @@ bond_mode_8023ad_setup(struct rte_eth_dev *dev,
 int
 bond_mode_8023ad_enable(struct rte_eth_dev *bond_dev)
 {
-	struct bond_dev_private *internals = bond_dev->data->dev_private;
+	struct bond_dev_private *internals = _DD(bond_dev, dev_private);
 	uint8_t i;
 
 	for (i = 0; i < internals->active_slave_count; i++)
@@ -1196,7 +1196,7 @@ rte_eth_bond_8023ad_slave_info(uint8_t port_id, uint8_t slave_id,
 
 	bond_dev = &rte_eth_devices[port_id];
 
-	internals = bond_dev->data->dev_private;
+	internals = _DD(bond_dev, dev_private);
 	if (find_slave_by_id(internals->active_slaves,
 			internals->active_slave_count, slave_id) ==
 				internals->active_slave_count)
lib/librte_pmd_bond/rte_eth_bond_alb.c +5 -5
index 5778b25..476231f 100644
@@ -60,7 +60,7 @@ calculate_slave(struct bond_dev_private *internals)
 int
 bond_mode_alb_enable(struct rte_eth_dev *bond_dev)
 {
-	struct bond_dev_private *internals = bond_dev->data->dev_private;
+	struct bond_dev_private *internals = _DD(bond_dev, dev_private);
 	struct client_data *hash_table = internals->mode6.client_table;
 
 	uint16_t element_size;
@@ -80,7 +80,7 @@ bond_mode_alb_enable(struct rte_eth_dev *bond_dev)
 		 * The value is chosen to be cache aligned.
 		 */
 		element_size = 256 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM;
-		snprintf(mem_name, sizeof(mem_name), "%s_MODE6", bond_dev->data->name);
+		snprintf(mem_name, sizeof(mem_name), "%s_MODE6", _DD(bond_dev, name));
 		internals->mode6.mempool = rte_mempool_create(mem_name,
 				512 * RTE_MAX_ETHPORTS,
 				element_size,
@@ -91,11 +91,11 @@ bond_mode_alb_enable(struct rte_eth_dev *bond_dev)
 
 		if (internals->mode6.mempool == NULL) {
 			RTE_LOG(ERR, PMD, "%s: Failed to initialize ALB mempool.\n",
-					bond_dev->data->name);
+					_DD(bond_dev, name));
 			rte_panic(
 					"Failed to allocate memory pool ('%s')\n"
 					"for bond device '%s'\n",
-					mem_name, bond_dev->data->name);
+					mem_name, _DD(bond_dev, name));
 		}
 	}
 
@@ -265,7 +265,7 @@ bond_mode_alb_arp_upd(struct client_data *client_info,
 void
 bond_mode_alb_client_list_upd(struct rte_eth_dev *bond_dev)
 {
-	struct bond_dev_private *internals = bond_dev->data->dev_private;
+	struct bond_dev_private *internals = _DD(bond_dev, dev_private);
 	struct client_data *client_info;
 
 	int i;
lib/librte_pmd_bond/rte_eth_bond_api.c +71 -71

408 lines not on this page · raw message

lib/librte_pmd_bond/rte_eth_bond_args.c +1 -1
index 02ecde6..5fbb709 100644
@@ -82,7 +82,7 @@ find_port_id_by_dev_name(const char *name)
 		if (rte_eth_devices[i].data == NULL)
 			continue;
 
-		if (strcmp(rte_eth_devices[i].data->name, name) == 0)
+		if (strcmp(_DD(&rte_eth_devices[i], name), name) == 0)
 			return i;
 	}
 	return -1;
lib/librte_pmd_bond/rte_eth_bond_pmd.c +82 -82

485 lines not on this page · raw message

lib/librte_pmd_bond/rte_eth_bond_private.h +1 -1
index 45e5c65..f285518 100644
@@ -244,7 +244,7 @@ bond_ethdev_primary_set(struct bond_dev_private *internals,
 		uint8_t slave_port_id);
 
 void
-bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_eth_event_type type,
+bond_ethdev_lsc_event_callback(uint8_t port_id, enum rte_dev_event_type type,
 		void *param);
 
 int
lib/librte_pmd_e1000/em_ethdev.c +78 -78

476 lines not on this page · raw message

lib/librte_pmd_e1000/em_rxtx.c +47 -47

285 lines not on this page · raw message

lib/librte_pmd_e1000/igb_ethdev.c +151 -151

935 lines not on this page · raw message

lib/librte_pmd_e1000/igb_pf.c +42 -44

172 lines not on this page · raw message

lib/librte_pmd_e1000/igb_rxtx.c +84 -84

168 lines not on this page · raw message

lib/librte_pmd_enic/enic.h +2 -2
index a50bff1..594592d 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_enic/enic_ethdev.c +70 -70

140 lines not on this page · raw message

lib/librte_pmd_enic/enic_main.c +15 -15
index 0892b3e..551517c 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_fm10k/fm10k_ethdev.c +77 -77

154 lines not on this page · raw message

lib/librte_pmd_fm10k/fm10k_rxtx.c +2 -2
index 83bddfc..54ac471 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_i40e/i40e_ethdev.c +86 -86

172 lines not on this page · raw message

lib/librte_pmd_i40e/i40e_ethdev_vf.c +97 -97

194 lines not on this page · raw message

lib/librte_pmd_i40e/i40e_fdir.c +14 -14
index 7b68c78..0a25294 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_i40e/i40e_pf.c +4 -4
index cbb2dcc..c67f75c 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_i40e/i40e_rxtx.c +44 -44

88 lines not on this page · raw message

lib/librte_pmd_ixgbe/ixgbe_ethdev.c +196 -196

392 lines not on this page · raw message

lib/librte_pmd_ixgbe/ixgbe_fdir.c +25 -25

50 lines not on this page · raw message

lib/librte_pmd_ixgbe/ixgbe_pf.c +56 -58

114 lines not on this page · raw message

lib/librte_pmd_ixgbe/ixgbe_rxtx.c +138 -138

276 lines not on this page · raw message

lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c +3 -3
index 7ac6b61..536fb7a 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_mlx4/mlx4.c +1 -1
index fa749f4..7a3ccae 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_null/rte_eth_null.c +18 -18
index 0e18502..1f2bb68 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_pcap/rte_eth_pcap.c +1 -1
index 204ae68..e295510 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_ring/rte_eth_ring.c +18 -18
index 1e66d4e..18930e9 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_virtio/virtio_ethdev.c +60 -60

120 lines not on this page · raw message

lib/librte_pmd_virtio/virtio_rxtx.c +10 -10
index 3ff275c..d0227a5 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_vmxnet3/vmxnet3_ethdev.c +32 -32

64 lines not on this page · raw message

lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c +20 -20
index a530c80..3b8a7fc 100644

Lines of this file are not shown. View the raw message.

lib/librte_pmd_xenvirt/rte_eth_xenvirt.c +1 -1
index bc403d6..a63e041 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.3.0

Part of the diff is not shown here. View the raw message.

#10 lore raw

cover pktdev

In reply to a message not in the archive

Hi all,

to continue this discussion a bit more, here is my, slightly different, slant on what a pktdev abstraction may look like.

The primary objective I had in mind when drafting this is to provide the minimal abstraction that can be *easily* used as a common device abstraction for existing (and future) device types to be passed to dataplane code. The patchset demonstrates this by defining a minimal interface for pktdev - since I firmly believe the interface should be as small as possible - and then showing how that common interface can be used to unify rings and ethdevs under a common API for the datapath. I believe any attempt to unify things much beyond this to the control plane or setup phase is not worth doing - at least not initially - as at init time the code always needs to be aware of the underlying resource type in order to configure it properly for dataplane use.

The overall objective I look to achieve is illustrated by the final patch in the series, which is a sample app where the same code is used for all cores, irrespective of the underlying device type.

To get to that point, patch 1 defines the minimal API - just RX and TX. The .c file in the library is empty for simplicity, though I would see some functionality moving there when/if it makes sense e.g. the callback support from ethdev, as is done in Keith's patchset.
Patch 2 then makes very minimal changes to ethdev to allow ethdevs to be used as pktdevs, and to make use of the pktdev functions when appropriate Patch 3 was, for me, the key test for this implementation - how hard was it to make an rte_ring usable as a pktdev too. Two single-line functions for RX/TX and a separate "converter" function proved to be all that was necessary here - and I believe simpler solutions may be possible too, as the extra structures allocated on conversion could be merged into the rte_ring structure itself and initialized on ring creation if we prefer that option. It is hoped/presumed that wrapping other structures, such as KNI, may prove to be just as easily done. [Not attempted yet - left as an exercise for the reader :-)].

Now, in terms of pktdev vs ethdev, there is nothing in this proposal that cannot also be done using ethdev AFAIK. However, pktdev as outlined here should make the process far easier than trying to create a full PMD for something. All NIC specific functions, including things like stop/start, are stripped out, as they don't make sense for an rte_ring or other software objects. Also, the other thing this provides is that we can move away from just using port ids. Instead in the same way as we now reference rings/mempools/KNIs etc via pointer, we can do the same with ethernet ports as pktdevs on the data path. There was discussion previously on moving beyond 8-bit port ids. If we look to use ethdev as a common abstraction, I feel that change will soon have to be made causing a large amount of code churn.

Bruce Richardson (4):
Add example pktdev implementation
Make ethdev explicitly a subclass of pktdev
add support for a ring to be a pktdev
example app showing pktdevs used in a chain

 config/common_bsdapp           |   5 +
 config/common_linuxapp         |   5 +
 examples/pktdev/Makefile       |  57 +++++++++++
 examples/pktdev/basicfwd.c     | 222 +++++++++++++++++++++++++++++++++++++++++
 lib/Makefile                   |   1 +
 lib/librte_ether/rte_ethdev.h  |  26 ++---
 lib/librte_pktdev/Makefile     |  56 +++++++++++
 lib/librte_pktdev/rte_pktdev.c |  35 +++++++
 lib/librte_pktdev/rte_pktdev.h | 144 ++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.c     |  41 ++++++++
 lib/librte_ring/rte_ring.h     |   3 +
 11 files changed, 582 insertions(+), 13 deletions(-)
 create mode 100644 examples/pktdev/Makefile
 create mode 100644 examples/pktdev/basicfwd.c
 create mode 100644 lib/librte_pktdev/Makefile
 create mode 100644 lib/librte_pktdev/rte_pktdev.c
 create mode 100644 lib/librte_pktdev/rte_pktdev.h
Signature · 1 line
2.1.0
#12 lore raw

RFC PATCH 1/4 Add example pktdev implementation

In reply to a message not in the archive

This commit demonstrates what a minimal API for all packet handling types would look like. It simply provides the necessary parts for receiving and transmiting packets, and is based off the ethdev implementation.

---
 config/common_bsdapp           |   5 ++
 config/common_linuxapp         |   5 ++
 lib/Makefile                   |   1 +
 lib/librte_pktdev/Makefile     |  56 ++++++++++++++++
 lib/librte_pktdev/rte_pktdev.c |  35 ++++++++++
 lib/librte_pktdev/rte_pktdev.h | 144 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 246 insertions(+)
 create mode 100644 lib/librte_pktdev/Makefile
 create mode 100644 lib/librte_pktdev/rte_pktdev.c
 create mode 100644 lib/librte_pktdev/rte_pktdev.h
config/common_bsdapp +5 -0
index 8ff4dc2..d2b932c 100644
@@ -132,6 +132,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
config/common_linuxapp +5 -0
index 09a58ac..5bda416 100644
@@ -129,6 +129,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
lib/Makefile +1 -0
index d94355d..4db5ee0 100644
@@ -32,6 +32,7 @@
 include $(RTE_SDK)/mk/rte.vars.mk
 
 DIRS-y += librte_compat
+DIRS-$(CONFIG_RTE_LIBRTE_PKTDEV) += librte_pktdev
 DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_MALLOC) += librte_malloc
 DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring
lib/librte_pktdev/Makefile new file +56 -0

56 lines not on this page · raw message

lib/librte_pktdev/rte_pktdev.c new file +36 -0
new file mode 100644
index 0000000..4c32d86
@@ -0,0 +1,36 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_pktdev.h"
+
+/* For future use */
lib/librte_pktdev/rte_pktdev.h new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
2.1.0
#20 lore raw

RFC PATCH 2/4 Make ethdev explicitly a subclass of pktdev

In reply to a message not in the archive

This patch allows us to take an ethdev port id and get from it a generic pktdev object that we can call using the pktdev routines, if we like. Change the actual rx/tx calls in the ethdev api to call the pktdev versions - which becuase of inlining will work the same as before, with no impact.

---
 lib/librte_ether/rte_ethdev.h | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
lib/librte_ether/rte_ethdev.h +13 -13
index 21aa359..4986d6b 100644
@@ -178,6 +178,7 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_mbuf.h>
+#include <rte_pktdev.h>
 #include "rte_ether.h"
 #include "rte_eth_ctrl.h"
 
@@ -1446,9 +1447,7 @@ enum rte_eth_dev_type {
  * process, while the actual configuration data for the device is shared.
  */
 struct rte_eth_dev {
-	eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */
-	eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */
-	struct rte_eth_dev_data *data;  /**< Pointer to device data */
+	RTE_PKT_DEV_HDR(rte_eth_dev);
 	const struct eth_driver *driver;/**< Driver for this device */
 	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
 	struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
@@ -1486,13 +1485,7 @@ struct rte_eth_dev_sriov {
  * processes in a multi-process configuration.
  */
 struct rte_eth_dev_data {
-	char name[RTE_ETH_NAME_MAX_LEN]; /**< Unique identifier name */
-
-	void **rx_queues; /**< Array of pointers to RX queues. */
-	void **tx_queues; /**< Array of pointers to TX queues. */
-	uint16_t nb_rx_queues; /**< Number of RX queues. */
-	uint16_t nb_tx_queues; /**< Number of TX queues. */
-
+	RTE_PKT_DEV_DATA_HDR;
 	struct rte_eth_dev_sriov sriov;    /**< SRIOV data */
 
 	void *dev_private;              /**< PMD-specific private data */
@@ -2298,6 +2291,12 @@ extern int rte_eth_dev_get_vlan_offload(uint8_t port_id);
  */
 extern int rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on);
 
+static inline struct rte_pkt_dev *
+rte_eth_get_dev(uint8_t port_id)
+{
+	return (void *)&rte_eth_devices[port_id];
+}
+
 /**
  *
  * Retrieve a burst of input packets from a receive queue of an Ethernet
@@ -2392,8 +2391,8 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
 
 	dev = &rte_eth_devices[port_id];
 
-	int16_t nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
-			rx_pkts, nb_pkts);
+	int16_t nb_rx = rte_pkt_rx_burst(rte_eth_get_dev(port_id), queue_id,
+			rx_pkts, nb_pkts);
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
@@ -2547,7 +2546,8 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
 	}
 #endif
 
-	return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id], tx_pkts, nb_pkts);
+	return rte_pkt_tx_burst(rte_eth_get_dev(port_id), queue_id,
+			tx_pkts, nb_pkts);
 }
 #endif
 
Signature · 1 line
2.1.0
#21 lore raw

RFC PATCH 3/4 add support for a ring to be a pktdev

In reply to a message not in the archive

Add a new public API function, and two internal wrapper functions so we can use ring as a pktdev.

---
 lib/librte_ring/rte_ring.c | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.h |  3 +++
 2 files changed, 44 insertions(+)
lib/librte_ring/Makefile +1 -1
index 84ad3d3..bc5dd09 100644
@@ -47,6 +47,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c
 SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h
 
 # this lib needs eal and rte_malloc
-DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc
+DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc lib/librte_pktdev
 
 include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_ring/rte_ring.c +42 -0

54 lines not on this page · raw message

lib/librte_ring/rte_ring.h +4 -0
index af68888..c2f28be 100644
@@ -301,6 +302,10 @@ int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 struct rte_ring *rte_ring_create(const char *name, unsigned count,
 				 int socket_id, unsigned flags);
 
+struct rte_pkt_dev;
+
+struct rte_pkt_dev *rte_ring_get_dev(struct rte_ring *r);
+
 /**
  * Change the high water mark.
  *
Signature · 1 line
2.1.0
#26 lore raw

RFC PATCH 4/4 example app showing pktdevs used in a chain

In reply to a message not in the archive

This is a trivial example showing code which is using ethdevs and rings in a neutral manner, with the same piece of pipeline code passing mbufs along a chain without ever having to query its source or destination type.

---
 examples/pktdev/Makefile   |  57 ++++++++++++
 examples/pktdev/basicfwd.c | 222 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 279 insertions(+)
 create mode 100644 examples/pktdev/Makefile
 create mode 100644 examples/pktdev/basicfwd.c
examples/pktdev/Makefile new file +57 -0
new file mode 100644
index 0000000..4a5d99f
@@ -0,0 +1,57 @@
+#   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.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overridden by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = basicfwd
+
+# all source are stored in SRCS-y
+SRCS-y := basicfwd.c
+
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+EXTRA_CFLAGS += -O3 -g -Wfatal-errors
+
+include $(RTE_SDK)/mk/rte.extapp.mk
examples/pktdev/basicfwd.c new file +222 -0

222 lines not on this page · raw message

Signature · 1 line
2.1.0
#27 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to a message not in the archive
Quoted 35 lines · Bruce Richardson

Hi all,

to continue this discussion a bit more, here is my, slightly different, slant on what a pktdev abstraction may look like.

The primary objective I had in mind when drafting this is to provide the minimal abstraction that can be *easily* used as a common device abstraction for existing (and future) device types to be passed to dataplane code. The patchset demonstrates this by defining a minimal interface for pktdev - since I firmly believe the interface should be as small as possible - and then showing how that common interface can be used to unify rings and ethdevs under a common API for the datapath. I believe any attempt to unify things much beyond this to the control plane or setup phase is not worth doing - at least not initially - as at init time the code always needs to be aware of the underlying resource type in order to configure it properly for dataplane use.

The overall objective I look to achieve is illustrated by the final patch in the series, which is a sample app where the same code is used for all cores, irrespective of the underlying device type.

To get to that point, patch 1 defines the minimal API - just RX and TX. The .c file in the library is empty for simplicity, though I would see some functionality moving there when/if it makes sense e.g. the callback support from ethdev, as is done in Keith's patchset.
Patch 2 then makes very minimal changes to ethdev to allow ethdevs to be used as pktdevs, and to make use of the pktdev functions when appropriate Patch 3 was, for me, the key test for this implementation - how hard was it to make an rte_ring usable as a pktdev too. Two single-line functions for RX/TX and a separate "converter" function proved to be all that was necessary here - and I believe simpler solutions may be possible too, as the extra structures allocated on conversion could be merged into the rte_ring structure itself and initialized on ring creation if we prefer that option. It is hoped/presumed that wrapping other structures, such as KNI, may prove to be just as easily done. [Not attempted yet - left as an exercise for the reader :-)].

Quoted 12 lines

Now, in terms of pktdev vs ethdev, there is nothing in this proposal that cannot also be done using ethdev AFAIK. However, pktdev as outlined here should make the process far easier than trying to create a full PMD for something. All NIC specific functions, including things like stop/start, are stripped out, as they don't make sense for an rte_ring or other software objects. Also, the other thing this provides is that we can move away from just using port ids. Instead in the same way as we now reference rings/mempools/KNIs etc via pointer, we can do the same with ethernet ports as pktdevs on the data path. There was discussion previously on moving beyond 8-bit port ids. If we look to use ethdev as a common abstraction, I feel that change will soon have to be made causing a large amount of code churn.

This is the thing that I think we are really disagreeing on here. The ease of use increase. As you claim above, theres nothing you can do with a pktdev that you can't do with an ethdev, so why not just use an ethdev? Its no more difficult, the API already exists and contains checks so that any ethdev method
that is unimplemented just return EOPNOTSUPP. Its a well understood model,
just use it.

Neil

#23 lore raw

Re: [RFC PATCH 3/4] add support for a ring to be a pktdev

In reply to a message not in the archive
Quoted 66 lines · Bruce Richardson

Add a new public API function, and two internal wrapper functions so we can use ring as a pktdev.

---
 lib/librte_ring/rte_ring.c | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.h |  3 +++
 2 files changed, 44 insertions(+)
lib/librte_ring/Makefile +1 -1
index 84ad3d3..bc5dd09 100644
@@ -47,6 +47,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c
 SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h
 
 # this lib needs eal and rte_malloc
-DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc
+DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc lib/librte_pktdev
 
 include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_ring/rte_ring.c +32 -0
index c9e59d4..424da20 100644
@@ -86,6 +86,7 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 #include <rte_spinlock.h>
+#include <rte_pktdev.h>
 
 #include "rte_ring.h"
 
@@ -208,6 +208,47 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
 	return r;
 }
 
+static uint16_t
+dev_rx(void *r, struct rte_mbuf **pkts, uint16_t max_pkts)
+{
+	return rte_ring_dequeue_burst(r, (void *)pkts, max_pkts);
+}
+
+static uint16_t
+dev_tx(void *r, struct rte_mbuf **pkts, uint16_t max_pkts)
+{
+	return rte_ring_enqueue_burst(r, (void *)pkts, max_pkts);
+}
+
+#define rte_ring_dev_data rte_pkt_dev_data
+
+struct rte_pkt_dev *
+rte_ring_get_dev(struct rte_ring *r)
+{
+	struct ring_as_pktdev {
+		RTE_PKT_DEV_HDR(rte_ring_dev);
+		struct rte_ring_dev_data dev_data;
+		void *ring;
+	} *p;
+	if (r == NULL ||
+			(p = rte_zmalloc(NULL, sizeof(*p), 0)) == NULL)
+		return NULL;
+
+	p->ring = r;
+	p->rx_pkt_burst = dev_rx;
+	p->tx_pkt_burst = dev_tx;
+	p->data = &p->dev_data;
+

lib/librte_ring/rte_ring.c rte_ring_create(const char *name, unsigned count, int socket_id, · line 251

Quoted 10 lines
lib/librte_ring/rte_ring.c +10 -0
+	snprintf(p->dev_data.name, sizeof(p->dev_data.name), "%s", r->name);
+	p->dev_data.nb_rx_queues = 1;
+	p->dev_data.nb_tx_queues = 1;
+	p->dev_data.rx_queues = &p->ring;
+	p->dev_data.tx_queues = &p->ring;
+
+	return (void *)p;
+}
+
+

So, yeah, you have the ability to get a new ethdev out of the ring api here, thats great. But to do it, you've created an additional API call point. I don't think thats a reasonable trade off. If you had just registered a PMD, with minimal methods (rx and tx), you might have had a little more code involved, but for that additional code you would have bought yourself all the infrastructure that ethdevs provide, like the ability to allocate and register them at exeution time administratively (with the --vdev option). You saved yourself a bit of code here, but lost the ability to do all the other things that you might want to do with ring ethdevs.

Neil

#28 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to a message not in the archive
Quoted 35 lines · Bruce Richardson

Hi all,

to continue this discussion a bit more, here is my, slightly different, slant on what a pktdev abstraction may look like.

The primary objective I had in mind when drafting this is to provide the minimal abstraction that can be *easily* used as a common device abstraction for existing (and future) device types to be passed to dataplane code. The patchset demonstrates this by defining a minimal interface for pktdev - since I firmly believe the interface should be as small as possible - and then showing how that common interface can be used to unify rings and ethdevs under a common API for the datapath. I believe any attempt to unify things much beyond this to the control plane or setup phase is not worth doing - at least not initially - as at init time the code always needs to be aware of the underlying resource type in order to configure it properly for dataplane use.

The overall objective I look to achieve is illustrated by the final patch in the series, which is a sample app where the same code is used for all cores, irrespective of the underlying device type.

To get to that point, patch 1 defines the minimal API - just RX and TX. The .c file in the library is empty for simplicity, though I would see some functionality moving there when/if it makes sense e.g. the callback support from ethdev, as is done in Keith's patchset.
Patch 2 then makes very minimal changes to ethdev to allow ethdevs to be used as pktdevs, and to make use of the pktdev functions when appropriate Patch 3 was, for me, the key test for this implementation - how hard was it to make an rte_ring usable as a pktdev too. Two single-line functions for RX/TX and a separate "converter" function proved to be all that was necessary here - and I believe simpler solutions may be possible too, as the extra structures allocated on conversion could be merged into the rte_ring structure itself and initialized on ring creation if we prefer that option. It is hoped/presumed that wrapping other structures, such as KNI, may prove to be just as easily done. [Not attempted yet - left as an exercise for the reader :-)].

Quoted 11 lines

Now, in terms of pktdev vs ethdev, there is nothing in this proposal that cannot also be done using ethdev AFAIK. However, pktdev as outlined here should make the process far easier than trying to create a full PMD for something. All NIC specific functions, including things like stop/start, are stripped out, as they don't make sense for an rte_ring or other software objects. Also, the other thing this provides is that we can move away from just using port ids. Instead in the same way as we now reference rings/mempools/KNIs etc via pointer, we can do the same with ethernet ports as pktdevs on the data path. There was discussion previously on moving beyond 8-bit port ids. If we look to use ethdev as a common abstraction, I feel that change will soon have to be made causing a large amount of code churn.

Hi Richard,

First thank you both for taking the time to look at this. I did not not reply to Keith because you Richard summarized most of my concerns.

I had a brief look to this second proposal. It is more aligned to what I had in mind. But still I feel it is slightly too complicated. I don't like much the necessary (in your approach) MACRO-like pkt_dev_data struct. It is also slightly inconvenient that the user has to do:

+ struct rte_pkt_dev *in = rte_eth_get_dev(0);

+ struct rte_pkt_dev *out = rte_ring_get_dev(
+ rte_ring_create(name, 4096, rte_socket_id(), 0));

What about something like (~pseudo-code):

rte_pkt_dev_data.h:

   enum rte_pkt_dev_type{
        RTE_PKT_DEV_ETH,
        RTE_PKT_DEV_RING,
        RTE_PKT_DEV_KNI,
        //Keep adding as more PMDs are supported
   };

//This struct may be redundant if there is nothing more

   struct rte_pkt_dev_data{
        enum rte_pkt_dev_type;
        //Placeholder, maybe we need more...

};

//Make RX/TX pktdev APIs more readable, but not really needed typedef void pkt_dev_t;

(In all PMDs and e.g. KNI and RINGs):

struct rte_eth_dev {
struct rte_pkt_dev_data pkt_dev;// <++++++++++++++++++++++++++++++++++ eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */ struct rte_eth_dev_data *data; /**< Pointer to device data */ /...

rte_pkt_dev.h:

      #include <rte_ethdev.h>
      //Include PMD (and non-PMD) TX/RX headers...
   static inline uint16_t
   rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
             struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
   {
        switch (((struct rte_pkt_dev_data*)dev)->type){
            case  RTE_PKT_DEV_ETH:
                struct rte_eth_dev* eth_dev = (struct rte_eth_dev*)pkt_dev;
                rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                break;
            case RTE_PKT_DEV_RING:
                //...
        }
   }

//...

Maybe it is oversimplified? With this approach tough, we would barely touch the PMDs and the functionality can be built on top of the existing PMDs.

Thoughts?
Marc

Quoted 25 lines

Bruce Richardson (4):
Add example pktdev implementation
Make ethdev explicitly a subclass of pktdev
add support for a ring to be a pktdev
example app showing pktdevs used in a chain

  config/common_bsdapp           |   5 +
  config/common_linuxapp         |   5 +
  examples/pktdev/Makefile       |  57 +++++++++++
  examples/pktdev/basicfwd.c     | 222 +++++++++++++++++++++++++++++++++++++++++
  lib/Makefile                   |   1 +
  lib/librte_ether/rte_ethdev.h  |  26 ++---
  lib/librte_pktdev/Makefile     |  56 +++++++++++
  lib/librte_pktdev/rte_pktdev.c |  35 +++++++
  lib/librte_pktdev/rte_pktdev.h | 144 ++++++++++++++++++++++++++
  lib/librte_ring/rte_ring.c     |  41 ++++++++
  lib/librte_ring/rte_ring.h     |   3 +
  11 files changed, 582 insertions(+), 13 deletions(-)

create mode 100644 examples/pktdev/Makefile create mode 100644 examples/pktdev/basicfwd.c create mode 100644 lib/librte_pktdev/Makefile create mode 100644 lib/librte_pktdev/rte_pktdev.c create mode 100644 lib/librte_pktdev/rte_pktdev.h

#30 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to a message not in the archive

Hi Marc and Bruce,

Quoted 145 lines · Marc Sune
Quoted 66 lines · Bruce Richardson

Hi all,

to continue this discussion a bit more, here is my, slightly different, slant
on what a pktdev abstraction may look like.

The primary objective I had in mind when drafting this is to provide the minimal abstraction that can be *easily* used as a common device abstraction for
existing (and future) device types to be passed to dataplane code. The patchset
demonstrates this by defining a minimal interface for pktdev - since I firmly
believe the interface should be as small as possible - and then showing how that
common interface can be used to unify rings and ethdevs under a common API for the
datapath. I believe any attempt to unify things much beyond this to the control
plane or setup phase is not worth doing - at least not initially - as at init time the code always needs to be aware of the underlying resource type in
order to configure it properly for dataplane use.

The overall objective I look to achieve is illustrated by the final patch in
the series, which is a sample app where the same code is used for all cores,
irrespective of the underlying device type.

To get to that point, patch 1 defines the minimal API - just RX and TX. The .c
file in the library is empty for simplicity, though I would see some functionality moving there when/if it makes sense e.g. the callback support
from ethdev, as is done in Keith's patchset.
Patch 2 then makes very minimal changes to ethdev to allow ethdevs to be used
as pktdevs, and to make use of the pktdev functions when appropriate Patch 3 was, for me, the key test for this implementation - how hard was it to
make an rte_ring usable as a pktdev too. Two single-line functions for RX/TX
and a separate "converter" function proved to be all that was necessary here -
and I believe simpler solutions may be possible too, as the extra structures
allocated on conversion could be merged into the rte_ring structure itself and
initialized on ring creation if we prefer that option. It is hoped/presumed that
wrapping other structures, such as KNI, may prove to be just as easily done.
[Not attempted yet - left as an exercise for the reader :-)].

Now, in terms of pktdev vs ethdev, there is nothing in this proposal that
cannot also be done using ethdev AFAIK. However, pktdev as outlined here should make the process far easier than trying to create a full PMD for something.
All NIC specific functions, including things like stop/start, are stripped out,
as they don't make sense for an rte_ring or other software objects. Also, the other thing this provides is that we can move away from just using
port ids. Instead in the same way as we now reference

Quoted 8 lines

rings/mempools/KNIs etc
via pointer, we can do the same with ethernet ports as pktdevs on the data path.
There was discussion previously on moving beyond 8-bit port ids. If we look to
use ethdev as a common abstraction, I feel that change will soon have to be made
causing a large amount of code churn.

Hi Richard,

First thank you both for taking the time to look at this. I did not not reply to Keith because you Richard summarized most of my concerns.

I had a brief look to this second proposal. It is more aligned to what I had in mind. But still I feel it is slightly too complicated. I don't like much the necessary (in your approach) MACRO-like pkt_dev_data struct. It is also slightly inconvenient that the user has to do:

(quoted diff) +3 -0
+	struct rte_pkt_dev *in = rte_eth_get_dev(0);
 
+		struct rte_pkt_dev *out = rte_ring_get_dev(
+				rte_ring_create(name, 4096, rte_socket_id(), 0));

What about something like (~pseudo-code):

rte_pkt_dev_data.h:

   enum rte_pkt_dev_type{
        RTE_PKT_DEV_ETH,
        RTE_PKT_DEV_RING,
        RTE_PKT_DEV_KNI,
        //Keep adding as more PMDs are supported
   };
   //This struct may be redundant if there is nothing more
   struct rte_pkt_dev_data{
        enum rte_pkt_dev_type;
        //Placeholder, maybe we need more...
   };

   //Make RX/TX pktdev APIs more readable, but not really needed
   typedef void pkt_dev_t;

(In all PMDs and e.g. KNI and RINGs):

struct rte_eth_dev {
struct rte_pkt_dev_data pkt_dev;//
<++++++++++++++++++++++++++++++++++
eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function.
*/
struct rte_eth_dev_data *data; /**< Pointer to device data */ /...

rte_pkt_dev.h:

      #include <rte_ethdev.h>
      //Include PMD (and non-PMD) TX/RX headers...

static inline uint16_t rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
{
switch (((struct rte_pkt_dev_data*)dev)->type){
case RTE_PKT_DEV_ETH:
struct rte_eth_dev* eth_dev = (struct

rte_eth_dev*)pkt_dev;
                rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                break;
            case RTE_PKT_DEV_RING:
                //...
        }
Quoted 3 lines

}

   //...

I do not see the functional different from my proposal other then a bit more search/replace, which does effect some of the PMD¹s. The changes to the PMD is just to use the macros as we now have a nested structure.

The nesting and movement some structures and code to a common location is to provide a better way to add other devices. Moving code into a common set of structures and APIs should only improve the code as we get more devices added to DPDK. The basic flow and design is the same.

Quoted 1 line

From rte_common_device.h (format screwed with cut/paste and not all of the

code)

struct rte_dev_data {
char name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */

void **rx_queues; /**< Array of pointers to RX queues. */
void **tx_queues; /**< Array of pointers to TX queues. */

uint16_t nb_rx_queues; /**< Number of RX queues. */
uint16_t nb_tx_queues; /**< Number of TX queues. */

uint16_t mtu; /**< Maximum Transmission Unit. */
uint8_t unit_id; /**< Unit/Port ID for this instance */
uint8_t _pad0; /* alignment filler */

void *dev_private; /**< PMD-specific private data */
uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation failures. */
uint32_t min_rx_buf_size; /**< Common rx buffer size handled by all
queues */
};

struct rte_dev_info {
struct rte_pci_device *pci_dev; /**< Device PCI information. */
const char *driver_name; /**< Device Driver name. */
unsigned int if_index; /**< Index to bound host interface, or 0
if none. */

	/* Use if_indextoname() to translate into an interface name. */
	unsigned int	_pad0;
};

struct rte_dev {
dev_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive
function. */
dev_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit
function. */

	void				  	*data;      	/**< Pointer to device data */
	struct rte_dev_global	*gbl_data;      /**< Pointer to device global data

*/
const struct rte_dev_drv *driver; /**< Driver for this device */
void *dev_ops; /**< Functions exported by PMD */
struct rte_pci_device *pci_dev; /**< PCI info. supplied by
probing */
struct rte_dev_info *dev_info; /**< Pointer to the device info
structure */

	/** User application callback for interrupts if present */
	struct rte_dev_cb_list  link_intr_cbs;
	/**
	* User-supplied functions called from rx_burst to post-process
	* received packets before passing them to the user
	*/
	struct rte_dev_rxtx_callback **post_rx_burst_cbs;
	/**
	* User-supplied functions called from tx_burst to pre-process
	* received packets before passing them to the driver for transmission.
	*/
	struct rte_dev_rxtx_callback **pre_tx_burst_cbs;
	enum rte_dev_type		dev_type;       /**< Flag indicating the device type */
	uint8_t                 attached;        /**< Flag indicating the port is

attached */
};

Quoted 1 line

From rte_ethdev.h

struct rte_eth_dev_info {
struct rte_dev_info di; /**< Common device information */

/* Rest of structure is for private device data */ uint32_t min_rx_bufsize; /**< Minimum size of RX buffer. */ uint32_t max_rx_pktlen; /**< Maximum configurable length of RX pkt. */ uint16_t max_rx_queues; /**< Maximum number of RX queues. */ uint16_t max_tx_queues; /**< Maximum number of TX queues. */ uint32_t max_mac_addrs; /**< Maximum number of MAC addresses. */ uint32_t max_hash_mac_addrs;
/** Maximum number of hash MAC addresses for MTA and UTA. */ uint16_t max_vfs; /**< Maximum number of VFs. */
uint16_t max_vmdq_pools; /**< Maximum number of VMDq pools. */ uint32_t rx_offload_capa; /**< Device RX offload capabilities. */ uint32_t tx_offload_capa; /**< Device TX offload capabilities. */ uint16_t reta_size;
/**< Device redirection table size, the total number of entries. */ /** Bit mask of RSS offloads, the bit offset also means flow type */ uint64_t flow_type_rss_offloads;
struct rte_eth_rxconf default_rxconf; /**< Default RX configuration */ struct rte_eth_txconf default_txconf; /**< Default TX configuration */ uint16_t vmdq_queue_base; /**< First queue ID for VMDQ pools. */ uint16_t vmdq_queue_num; /**< Queue number for VMDQ pools. */ uint16_t vmdq_pool_base; /**< First ID of VMDQ pools. */
};

struct rte_eth_dev_data {
	struct rte_dev_data		dd;			/**< Common device data */

	/* Rest of the structure is private data */
	struct rte_eth_dev_sriov sriov;    /**< SRIOV data */

	struct rte_eth_link dev_link;
	/**< Link-level information & status */

	struct rte_eth_conf dev_conf;   /**< Configuration applied to device. */
	struct ether_addr* mac_addrs;	/**< Device Ethernet Link address. */
	uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
	/** bitmap array of associating Ethernet MAC addresses to pools */
	struct ether_addr* hash_mac_addrs;

	/** Device Ethernet MAC addresses of hash filtering. */
	uint8_t promiscuous  : 1,   /**< RX promiscuous mode ON(1) / OFF(0). */
		scattered_rx : 1,	/**< RX of scattered packets is ON(1) / OFF(0) */
		all_multicast: 1,   /**< RX all multicast mode ON(1) / OFF(0). */
		dev_started  : 1;   /**< Device state: STARTED(1) / STOPPED(0). */
};

In the case of rte_ethdev.h the rte_eth_dev turns into a macro '#define rte_eth_dev rte_dev', in other devices they may have a rte_xyz_dev structure rte_dev as the first member and then private members. Also later if we find something private to ethdev then a structure can be created.

Most of the code changes outside of these changes are because using a macro to fix the code was easier. Rewriting the functions to use real variables instead of casting void pointer could yield without the macros. Not sure as the performance impact in rewriting some of these functions to eliminate the macros.

This is the heart of what I am proposing and it just so happens to allow Bruce¹ ideas as well. I have another patch I have not sent that includes Bruce¹s ideas using my suggestions.

Being able to use a single API for all devices does have its benefits IMO, but I want to cleanup ethdev to allow for other devices to be added to the system.

At some point (when the cryptodev is done) I want to add it to this framework, plus add more APIs for crypto similar to Linux Crypto API or something we can agree is a reasonable set of APIs for DPDK.

Regards,

++Keith

Quoted 37 lines

Maybe it is oversimplified? With this approach tough, we would barely touch the PMDs and the functionality can be built on top of the existing PMDs.

Thoughts?
Marc

Quoted 26 lines

Bruce Richardson (4):
Add example pktdev implementation
Make ethdev explicitly a subclass of pktdev
add support for a ring to be a pktdev
example app showing pktdevs used in a chain

  config/common_bsdapp           |   5 +
  config/common_linuxapp         |   5 +
  examples/pktdev/Makefile       |  57 +++++++++++
  examples/pktdev/basicfwd.c     | 222
+++++++++++++++++++++++++++++++++++++++++
  lib/Makefile                   |   1 +
  lib/librte_ether/rte_ethdev.h  |  26 ++---
  lib/librte_pktdev/Makefile     |  56 +++++++++++
  lib/librte_pktdev/rte_pktdev.c |  35 +++++++
  lib/librte_pktdev/rte_pktdev.h | 144 ++++++++++++++++++++++++++
  lib/librte_ring/rte_ring.c     |  41 ++++++++
  lib/librte_ring/rte_ring.h     |   3 +
  11 files changed, 582 insertions(+), 13 deletions(-)

create mode 100644 examples/pktdev/Makefile create mode 100644 examples/pktdev/basicfwd.c create mode 100644 lib/librte_pktdev/Makefile create mode 100644 lib/librte_pktdev/rte_pktdev.c create mode 100644 lib/librte_pktdev/rte_pktdev.h

#24 lore raw

Re: [RFC PATCH 3/4] add support for a ring to be a pktdev

In reply to a message not in the archive
Quoted 69 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Friday, April 17, 2015 11:17 PM
To: [email protected]; Wiles, Keith
Subject: [dpdk-dev] [RFC PATCH 3/4] add support for a ring to be a pktdev

Add a new public API function, and two internal wrapper functions so we can use ring as a pktdev.

---
 lib/librte_ring/rte_ring.c | 41
+++++++++++++++++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.h |  3 +++
 2 files changed, 44 insertions(+)
lib/librte_ring/Makefile index renamed from lib/librte_ring/Makefile +0 -0

84ad3d3..bc5dd09 100644

lib/librte_ring/Makefile +0 -0
@@ -47,6 +47,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c

SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h

 # this lib needs eal and rte_malloc
lib/librte_ring/Makefile +2 -1
-DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc
+DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc
+lib/librte_pktdev
 
 include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_ring/rte_ring.c index renamed from lib/librte_ring/rte_ring.c +0 -0

c9e59d4..424da20 100644

lib/librte_ring/rte_ring.c +24 -0
@@ -86,6 +86,7 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 #include <rte_spinlock.h>
+#include <rte_pktdev.h>
 
 #include "rte_ring.h"
 
@@ -208,6 +208,47 @@ rte_ring_create(const char *name, unsigned count,
 int socket_id,
 	return r;
 }
 
+static uint16_t
+dev_rx(void *r, struct rte_mbuf **pkts, uint16_t max_pkts) {
+	return rte_ring_dequeue_burst(r, (void *)pkts, max_pkts); }
+
+static uint16_t
+dev_tx(void *r, struct rte_mbuf **pkts, uint16_t max_pkts) {
+	return rte_ring_enqueue_burst(r, (void *)pkts, max_pkts); }
+
+#define rte_ring_dev_data rte_pkt_dev_data
+
+struct rte_pkt_dev *
+rte_ring_get_dev(struct rte_ring *r)
+{
+	struct ring_as_pktdev {
+		RTE_PKT_DEV_HDR(rte_ring_dev);
+		struct rte_ring_dev_data dev_data;
+		void *ring;
+	} *p;
+	if (r == NULL ||
+			(p = rte_zmalloc(NULL, sizeof(*p), 0)) == NULL)
+		return NULL;
+
+	p->ring = r;

lib/librte_ring/rte_ring.c rte_ring_create(const char *name, unsigned count, · line 244

Quoted 10 lines
lib/librte_ring/rte_ring.c +9 -0
+	p->rx_pkt_burst = dev_rx;
+	p->tx_pkt_burst = dev_tx;
+	p->data = &p->dev_data;
+
+	snprintf(p->dev_data.name, sizeof(p->dev_data.name), "%s", r-
 >name);
+	p->dev_data.nb_rx_queues = 1;
+	p->dev_data.nb_tx_queues = 1;
+	p->dev_data.rx_queues = &p->ring;
+	p->dev_data.tx_queues = &p->ring;

Why rx and tx doesn't need different ring here?

Quoted 26 lines
lib/librte_ring/rte_ring.c +5 -0
+
+	return (void *)p;
+}
+
+
 /*
  * change the high water mark. If *count* is 0, water marking is
  * disabled
lib/librte_ring/rte_ring.h index renamed from lib/librte_ring/rte_ring.h +0 -0

af68888..c2f28be 100644

lib/librte_ring/rte_ring.h +4 -0
@@ -301,6 +302,10 @@ int rte_ring_init(struct rte_ring *r, const char *name,
 unsigned count,  struct rte_ring *rte_ring_create(const char *name,
 unsigned count,
 				 int socket_id, unsigned flags);
 
+struct rte_pkt_dev;
+
+struct rte_pkt_dev *rte_ring_get_dev(struct rte_ring *r);
+
 /**
  * Change the high water mark.

*
--
2.1.0

#32 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to a message not in the archive
Quoted 1 line · Keith

Hi Marc and Bruce,

Hi Keith, Bruce,

Quoted 148 lines · Marc Sune
Quoted 146 lines · Bruce Richardson
Quoted 66 lines

Hi all,

to continue this discussion a bit more, here is my, slightly different, slant
on what a pktdev abstraction may look like.

The primary objective I had in mind when drafting this is to provide the minimal abstraction that can be *easily* used as a common device abstraction for
existing (and future) device types to be passed to dataplane code. The patchset
demonstrates this by defining a minimal interface for pktdev - since I firmly
believe the interface should be as small as possible - and then showing how that
common interface can be used to unify rings and ethdevs under a common API for the
datapath. I believe any attempt to unify things much beyond this to the control
plane or setup phase is not worth doing - at least not initially - as at init time the code always needs to be aware of the underlying resource type in
order to configure it properly for dataplane use.

The overall objective I look to achieve is illustrated by the final patch in
the series, which is a sample app where the same code is used for all cores,
irrespective of the underlying device type.

To get to that point, patch 1 defines the minimal API - just RX and TX. The .c
file in the library is empty for simplicity, though I would see some functionality moving there when/if it makes sense e.g. the callback support
from ethdev, as is done in Keith's patchset.
Patch 2 then makes very minimal changes to ethdev to allow ethdevs to be used
as pktdevs, and to make use of the pktdev functions when appropriate Patch 3 was, for me, the key test for this implementation - how hard was it to
make an rte_ring usable as a pktdev too. Two single-line functions for RX/TX
and a separate "converter" function proved to be all that was necessary here -
and I believe simpler solutions may be possible too, as the extra structures
allocated on conversion could be merged into the rte_ring structure itself and
initialized on ring creation if we prefer that option. It is hoped/presumed that
wrapping other structures, such as KNI, may prove to be just as easily done.
[Not attempted yet - left as an exercise for the reader :-)].

Now, in terms of pktdev vs ethdev, there is nothing in this proposal that
cannot also be done using ethdev AFAIK. However, pktdev as outlined here should make the process far easier than trying to create a full PMD for something.
All NIC specific functions, including things like stop/start, are stripped out,
as they don't make sense for an rte_ring or other software objects. Also, the other thing this provides is that we can move away from just using
port ids. Instead in the same way as we now reference

Quoted 8 lines

rings/mempools/KNIs etc
via pointer, we can do the same with ethernet ports as pktdevs on the data path.
There was discussion previously on moving beyond 8-bit port ids. If we look to
use ethdev as a common abstraction, I feel that change will soon have to be made
causing a large amount of code churn.

Hi Richard,

First thank you both for taking the time to look at this. I did not not reply to Keith because you Richard summarized most of my concerns.

I had a brief look to this second proposal. It is more aligned to what I had in mind. But still I feel it is slightly too complicated. I don't like much the necessary (in your approach) MACRO-like pkt_dev_data struct. It is also slightly inconvenient that the user has to do:

(quoted diff) +3 -0
+	struct rte_pkt_dev *in = rte_eth_get_dev(0);
 
+		struct rte_pkt_dev *out = rte_ring_get_dev(
+				rte_ring_create(name, 4096, rte_socket_id(), 0));

What about something like (~pseudo-code):

rte_pkt_dev_data.h:

    enum rte_pkt_dev_type{
         RTE_PKT_DEV_ETH,
         RTE_PKT_DEV_RING,
         RTE_PKT_DEV_KNI,
         //Keep adding as more PMDs are supported
    };


    //This struct may be redundant if there is nothing more
    struct rte_pkt_dev_data{
         enum rte_pkt_dev_type;
         //Placeholder, maybe we need more...
    };

    //Make RX/TX pktdev APIs more readable, but not really needed
    typedef void pkt_dev_t;

(In all PMDs and e.g. KNI and RINGs):

struct rte_eth_dev {
struct rte_pkt_dev_data pkt_dev;//
<++++++++++++++++++++++++++++++++++
eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function.
*/
struct rte_eth_dev_data *data; /**< Pointer to device data */ /...

rte_pkt_dev.h:

       #include <rte_ethdev.h>
       //Include PMD (and non-PMD) TX/RX headers...

    static inline uint16_t
    rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
              struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
    {
         switch (((struct rte_pkt_dev_data*)dev)->type){
             case  RTE_PKT_DEV_ETH:
                 struct rte_eth_dev* eth_dev = (struct
rte_eth_dev*)pkt_dev;
                 rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                 break;
             case RTE_PKT_DEV_RING:
                 //...
         }
    }
Quoted 4 lines
Quoted 1 line
    //...

I do not see the functional different from my proposal other then a bit more search/replace, which does effect some of the PMD¹s. The changes to the PMD is just to use the macros as we now have a nested structure.

I think what I am proposing is different. See below.

Quoted 5 lines

The nesting and movement some structures and code to a common location is to provide a better way to add other devices. Moving code into a common set of structures and APIs should only improve the code as we get more devices added to DPDK. The basic flow and design is the same.

In your proposal you are movig TX/RX queues as well as some shared stuff and, most importantly, you are using function pointers to execute the RX/TX routines.

What I was proposing is to try to add the minimum common shared state in order to properly demultiplex the RX/TX call and have a common set of abstract calls (the pkt_dev type). In a way, I was proposing to deliberately not have a shared struct rte_dev_data because I think the internals of the "pkt_dev" can be very different across devices (e.g. queues in kni vs eth port vs. crypto?). I treat the pkt_dev as a "black box" that conforms to TX/RX API, leaving the developer of that device to define its internal structures as it better suites the needs. I only use each of the specific device type TX/RX APIs (external to us, pkt_dev library) in rte_pkt_dev.h. This also simplifies the refactor required to eventually integrate the rte_pkt_dev library and builds it "on top" of the existing APIs.

The other important difference with both, Bruce and your approach, and mine is the use of function pointers for RX/TX. I don't use them, which makes the entire abstracted TX/RX (including the final RX/TX routines itself) functions be "inlinable".

Btw, I forgot to add something basic in the previous pseudo-code. The different types have to be conditionally compiled according to compiled-in DPDK libs:

rte_pkt_dev.h:

    #include <rte_config.h>

    //Eth devices
    #ifdef RTE_LIBRTE_ETHER
    #include <rte_ethdev.h>
    #endif

    //KNI
    #ifdef RTE_LIBRTE_KNI
    #include <rte_kni.h>
    #endif

    //...
    //Include PMD (and non-PMD) TX/RX headers...
   static inline uint16_t
   rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
             struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
   {
        switch (((struct rte_pkt_dev_data*)dev)->type){
            #ifdef RTE_LIBRTE_ETHER
            case  RTE_PKT_DEV_ETH:
                struct rte_eth_dev* eth_dev = (struct rte_eth_dev*)pkt_dev;
                rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                break;
            #endif
            #ifdef RTE_LIBRTE_KNI
            case RTE_PKT_DEV_KNI:
                //...
                break;
            #endif

            default:
                    //Corrupted type or unsupported (without compiled 
support)
                    //Ignore or fail(fatal error)?
                    break;
        }

}

//...

Quoted 50 lines

From rte_common_device.h (format screwed with cut/paste and not all of the
code)

struct rte_dev_data {
char name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */

void **rx_queues; /**< Array of pointers to RX queues. */
void **tx_queues; /**< Array of pointers to TX queues. */

uint16_t nb_rx_queues; /**< Number of RX queues. */
uint16_t nb_tx_queues; /**< Number of TX queues. */

uint16_t mtu; /**< Maximum Transmission Unit. */
uint8_t unit_id; /**< Unit/Port ID for this instance */
uint8_t _pad0; /* alignment filler */

void *dev_private; /**< PMD-specific private data */
uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation failures. */
uint32_t min_rx_buf_size; /**< Common rx buffer size handled by all
queues */
};

struct rte_dev_info {
struct rte_pci_device *pci_dev; /**< Device PCI information. */
const char *driver_name; /**< Device Driver name. */
unsigned int if_index; /**< Index to bound host interface, or 0
if none. */

	/* Use if_indextoname() to translate into an interface name. */
	unsigned int	_pad0;
};

struct rte_dev {
dev_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive
function. */
dev_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit
function. */

	void				  	*data;      	/**< Pointer to device data */
	struct rte_dev_global	*gbl_data;      /**< Pointer to device global data

*/
const struct rte_dev_drv *driver; /**< Driver for this device */
void *dev_ops; /**< Functions exported by PMD */
struct rte_pci_device *pci_dev; /**< PCI info. supplied by
probing */
struct rte_dev_info *dev_info; /**< Pointer to the device info
structure */

Quoted 12 lines
	/** User application callback for interrupts if present */
	struct rte_dev_cb_list  link_intr_cbs;
	/**
	* User-supplied functions called from rx_burst to post-process
	* received packets before passing them to the user
	*/
	struct rte_dev_rxtx_callback **post_rx_burst_cbs;
	/**
	* User-supplied functions called from tx_burst to pre-process
	* received packets before passing them to the driver for transmission.
	*/
	struct rte_dev_rxtx_callback **pre_tx_burst_cbs;

What is the indended use of these callbacks and what is the benefit? If the user is supplying the callback, why not putting it directly after the RX and before the TX call in user's code (anyway)?

Quoted 71 lines

enum rte_dev_type dev_type; /**< Flag indicating the device type */
uint8_t attached; /**< Flag indicating the port is
attached */
};

From rte_ethdev.h

struct rte_eth_dev_info {
struct rte_dev_info di; /**< Common device information */

/* Rest of structure is for private device data */ uint32_t min_rx_bufsize; /**< Minimum size of RX buffer. */ uint32_t max_rx_pktlen; /**< Maximum configurable length of RX pkt. */ uint16_t max_rx_queues; /**< Maximum number of RX queues. */ uint16_t max_tx_queues; /**< Maximum number of TX queues. */ uint32_t max_mac_addrs; /**< Maximum number of MAC addresses. */ uint32_t max_hash_mac_addrs;
/** Maximum number of hash MAC addresses for MTA and UTA. */ uint16_t max_vfs; /**< Maximum number of VFs. */
uint16_t max_vmdq_pools; /**< Maximum number of VMDq pools. */ uint32_t rx_offload_capa; /**< Device RX offload capabilities. */ uint32_t tx_offload_capa; /**< Device TX offload capabilities. */ uint16_t reta_size;
/**< Device redirection table size, the total number of entries. */ /** Bit mask of RSS offloads, the bit offset also means flow type */ uint64_t flow_type_rss_offloads;
struct rte_eth_rxconf default_rxconf; /**< Default RX configuration */ struct rte_eth_txconf default_txconf; /**< Default TX configuration */ uint16_t vmdq_queue_base; /**< First queue ID for VMDQ pools. */ uint16_t vmdq_queue_num; /**< Queue number for VMDQ pools. */ uint16_t vmdq_pool_base; /**< First ID of VMDQ pools. */
};

struct rte_eth_dev_data {
	struct rte_dev_data		dd;			/**< Common device data */

	/* Rest of the structure is private data */
	struct rte_eth_dev_sriov sriov;    /**< SRIOV data */

	struct rte_eth_link dev_link;
	/**< Link-level information & status */

	struct rte_eth_conf dev_conf;   /**< Configuration applied to device. */
	struct ether_addr* mac_addrs;	/**< Device Ethernet Link address. */
	uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
	/** bitmap array of associating Ethernet MAC addresses to pools */
	struct ether_addr* hash_mac_addrs;

	/** Device Ethernet MAC addresses of hash filtering. */
	uint8_t promiscuous  : 1,   /**< RX promiscuous mode ON(1) / OFF(0). */
		scattered_rx : 1,	/**< RX of scattered packets is ON(1) / OFF(0) */
		all_multicast: 1,   /**< RX all multicast mode ON(1) / OFF(0). */
		dev_started  : 1;   /**< Device state: STARTED(1) / STOPPED(0). */
};

In the case of rte_ethdev.h the rte_eth_dev turns into a macro '#define rte_eth_dev rte_dev', in other devices they may have a rte_xyz_dev structure rte_dev as the first member and then private members. Also later if we find something private to ethdev then a structure can be created.

Most of the code changes outside of these changes are because using a macro to fix the code was easier. Rewriting the functions to use real variables instead of casting void pointer could yield without the macros. Not sure as the performance impact in rewriting some of these functions to eliminate the macros.

This is the heart of what I am proposing and it just so happens to allow Bruce¹ ideas as well. I have another patch I have not sent that includes Bruce¹s ideas using my suggestions.

Quoted 7 lines

Being able to use a single API for all devices does have its benefits IMO, but I want to cleanup ethdev to allow for other devices to be added to the system.

At some point (when the cryptodev is done) I want to add it to this framework, plus add more APIs for crypto similar to Linux Crypto API or something we can agree is a reasonable set of APIs for DPDK.

I currently don't see the benefit of abstracting beyond the RX/TX functions, and I see more cons than pros. Doing so we will also make librte_pkt_dev sort of mandatory, even if you are not using it our abstracted RX/TX functions at all.

regards
marc

Quoted 39 lines

Regards,

++Keith

Quoted 34 lines

Maybe it is oversimplified? With this approach tough, we would barely touch the PMDs and the functionality can be built on top of the existing PMDs.

Thoughts?
Marc

Quoted 25 lines

Bruce Richardson (4):
Add example pktdev implementation
Make ethdev explicitly a subclass of pktdev
add support for a ring to be a pktdev
example app showing pktdevs used in a chain

   config/common_bsdapp           |   5 +
   config/common_linuxapp         |   5 +
   examples/pktdev/Makefile       |  57 +++++++++++
   examples/pktdev/basicfwd.c     | 222
+++++++++++++++++++++++++++++++++++++++++
   lib/Makefile                   |   1 +
   lib/librte_ether/rte_ethdev.h  |  26 ++---
   lib/librte_pktdev/Makefile     |  56 +++++++++++
   lib/librte_pktdev/rte_pktdev.c |  35 +++++++
   lib/librte_pktdev/rte_pktdev.h | 144 ++++++++++++++++++++++++++
   lib/librte_ring/rte_ring.c     |  41 ++++++++
   lib/librte_ring/rte_ring.h     |   3 +
   11 files changed, 582 insertions(+), 13 deletions(-)

create mode 100644 examples/pktdev/Makefile create mode 100644 examples/pktdev/basicfwd.c create mode 100644 lib/librte_pktdev/Makefile create mode 100644 lib/librte_pktdev/rte_pktdev.c create mode 100644 lib/librte_pktdev/rte_pktdev.h

#25 lore raw

Re: [RFC PATCH 3/4] add support for a ring to be a pktdev

In reply to a message not in the archive

Hi Bruce,

Quoted 30 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Friday, April 17, 2015 4:17 PM
To: [email protected]; Wiles, Keith
Subject: [dpdk-dev] [RFC PATCH 3/4] add support for a ring to be a pktdev

Add a new public API function, and two internal wrapper functions so we can use ring as a pktdev.

---
 lib/librte_ring/rte_ring.c | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.h |  3 +++
 2 files changed, 44 insertions(+)
lib/librte_ring/Makefile +1 -1
index 84ad3d3..bc5dd09 100644
@@ -47,6 +47,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_RING) := rte_ring.c
 SYMLINK-$(CONFIG_RTE_LIBRTE_RING)-include := rte_ring.h
 
 # this lib needs eal and rte_malloc
-DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc
+DEPDIRS-$(CONFIG_RTE_LIBRTE_RING) += lib/librte_eal lib/librte_malloc lib/librte_pktdev
 
 include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_ring/rte_ring.c +0 -0
index c9e59d4..424da20 100644

lib/librte_ring/rte_ring.c line 89

Quoted 4 lines
lib/librte_ring/rte_ring.c +1 -0
@@ -86,6 +86,7 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 #include <rte_spinlock.h>
+#include <rte_pktdev.h>

I don't think it is a good idea to make rte_ring dependent on rte_pktdev (or rte_ethdev). If we'd like to have pkt (or eth) device based on rte_ring, why not to create librte_pmd_ring and put all that stuff there?
Konstantin

Quoted 68 lines
lib/librte_ring/rte_ring.c +41 -0
 #include "rte_ring.h"
 
@@ -208,6 +208,47 @@ rte_ring_create(const char *name, unsigned count, int socket_id,
 	return r;
 }
 
+static uint16_t
+dev_rx(void *r, struct rte_mbuf **pkts, uint16_t max_pkts)
+{
+	return rte_ring_dequeue_burst(r, (void *)pkts, max_pkts);
+}
+
+static uint16_t
+dev_tx(void *r, struct rte_mbuf **pkts, uint16_t max_pkts)
+{
+	return rte_ring_enqueue_burst(r, (void *)pkts, max_pkts);
+}
+
+#define rte_ring_dev_data rte_pkt_dev_data
+
+struct rte_pkt_dev *
+rte_ring_get_dev(struct rte_ring *r)
+{
+	struct ring_as_pktdev {
+		RTE_PKT_DEV_HDR(rte_ring_dev);
+		struct rte_ring_dev_data dev_data;
+		void *ring;
+	} *p;
+	if (r == NULL ||
+			(p = rte_zmalloc(NULL, sizeof(*p), 0)) == NULL)
+		return NULL;
+
+	p->ring = r;
+	p->rx_pkt_burst = dev_rx;
+	p->tx_pkt_burst = dev_tx;
+	p->data = &p->dev_data;
+
+	snprintf(p->dev_data.name, sizeof(p->dev_data.name), "%s", r->name);
+	p->dev_data.nb_rx_queues = 1;
+	p->dev_data.nb_tx_queues = 1;
+	p->dev_data.rx_queues = &p->ring;
+	p->dev_data.tx_queues = &p->ring;
+
+	return (void *)p;
+}
+
+
 /*
  * change the high water mark. If *count* is 0, water marking is
  * disabled
lib/librte_ring/rte_ring.h +4 -1
index af68888..c2f28be 100644
@@ -301,6 +302,10 @@ int rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 struct rte_ring *rte_ring_create(const char *name, unsigned count,
 				 int socket_id, unsigned flags);
 
+struct rte_pkt_dev;
+
+struct rte_pkt_dev *rte_ring_get_dev(struct rte_ring *r);
+
 /**
  * Change the high water mark.
  *
--

2.1.0

#34 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to a message not in the archive
Quoted 71 lines · Marc Sune
Quoted 1 line · Keith

Hi Marc and Bruce,

Hi Keith, Bruce,

Quoted 2 lines · Marc Sune

What I was proposing is to try to add the minimum common shared state in order to properly demultiplex the RX/TX call and have a common set of abstract calls (the pkt_dev type). In a way, I was proposing to deliberately not have a shared struct rte_dev_data because I think the internals of the "pkt_dev" can be very different across devices (e.g. queues in kni vs eth port vs. crypto?). I treat the pkt_dev as a "black box" that conforms to TX/RX API, leaving the developer of that device to define its internal structures as it better suites the needs. I only use each of the specific device type TX/RX APIs (external to us, pkt_dev library) in rte_pkt_dev.h. This also simplifies the refactor required to eventually integrate the rte_pkt_dev library and builds it "on top" of the existing APIs.

The other important difference with both, Bruce and your approach, and mine is the use of function pointers for RX/TX. I don't use them, which makes the entire abstracted TX/RX (including the final RX/TX routines itself) functions be "inlinable".

Btw, I forgot to add something basic in the previous pseudo-code. The different types have to be conditionally compiled according to compiled-in DPDK libs:

rte_pkt_dev.h:

    #include <rte_config.h>

    //Eth devices
    #ifdef RTE_LIBRTE_ETHER
    #include <rte_ethdev.h>
    #endif

    //KNI
    #ifdef RTE_LIBRTE_KNI
    #include <rte_kni.h>
    #endif

    //...
    //Include PMD (and non-PMD) TX/RX headers...
   static inline uint16_t
   rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
             struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
   {
        switch (((struct rte_pkt_dev_data*)dev)->type){
            #ifdef RTE_LIBRTE_ETHER
            case  RTE_PKT_DEV_ETH:
                struct rte_eth_dev* eth_dev = (struct rte_eth_dev*)pkt_dev;
                rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                break;
            #endif
            #ifdef RTE_LIBRTE_KNI
            case RTE_PKT_DEV_KNI:
                //...
                break;
            #endif

            default:
                    //Corrupted type or unsupported (without compiled
support)
                    //Ignore or fail(fatal error)?
                    break;
        }
Quoted 3 lines

}

   //...

Yes, this is an interesting approach, and with the inlining could indeed be less overhead for the ring and kni compared to my suggestion due to the inlining. There might be a slight overhead for the RX/TX ethdev functions though - 1/2 cycles due to the extra (hopefully predictable) branch in the RX/TX call, since we always need the indirect function call for the PMDs.

I also like the use of pointers rather than port ids.

Let me think on this a bit more.

/Bruce

#14 lore raw

Re: [RFC PATCH 1/4] Add example pktdev implementation

In reply to a message not in the archive
Quoted 305 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Friday, April 17, 2015 4:17 PM
To: [email protected]; Wiles, Keith
Subject: [dpdk-dev] [RFC PATCH 1/4] Add example pktdev implementation

This commit demonstrates what a minimal API for all packet handling types would look like. It simply provides the necessary parts for receiving and transmiting packets, and is based off the ethdev implementation.

---
 config/common_bsdapp           |   5 ++
 config/common_linuxapp         |   5 ++
 lib/Makefile                   |   1 +
 lib/librte_pktdev/Makefile     |  56 ++++++++++++++++
 lib/librte_pktdev/rte_pktdev.c |  35 ++++++++++
 lib/librte_pktdev/rte_pktdev.h | 144 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 246 insertions(+)
 create mode 100644 lib/librte_pktdev/Makefile
 create mode 100644 lib/librte_pktdev/rte_pktdev.c
 create mode 100644 lib/librte_pktdev/rte_pktdev.h
config/common_bsdapp +5 -0
index 8ff4dc2..d2b932c 100644
@@ -132,6 +132,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
config/common_linuxapp +5 -0
index 09a58ac..5bda416 100644
@@ -129,6 +129,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
lib/Makefile +1 -0
index d94355d..4db5ee0 100644
@@ -32,6 +32,7 @@
 include $(RTE_SDK)/mk/rte.vars.mk
 
 DIRS-y += librte_compat
+DIRS-$(CONFIG_RTE_LIBRTE_PKTDEV) += librte_pktdev
 DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_MALLOC) += librte_malloc
 DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring
lib/librte_pktdev/Makefile new file +56 -0
new file mode 100644
index 0000000..2d3b3a1
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2015 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 = libpktdev.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+EXPORT_MAP := rte_pktdev_version.map
+
+LIBABIVER := 1
+
+SRCS-y += rte_pktdev.c
+
+#
+# Export include files
+#
+SYMLINK-y-include += rte_pktdev.h
+
+# this lib depends upon no others:
+DEPDIRS-y +=
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_pktdev/rte_pktdev.c new file +36 -0
new file mode 100644
index 0000000..4c32d86
@@ -0,0 +1,36 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_pktdev.h"
+
+/* For future use */
lib/librte_pktdev/rte_pktdev.h new file +127 -0
new file mode 100644
index 0000000..8a5699a
@@ -0,0 +1,144 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_PKTDEV_H_
+#define _RTE_PKTDEV_H_
+
+#include <stdint.h>
+
+/**
+ * @file
+ *
+ * RTE Packet Processing Device API
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* forward definition of mbuf structure. We don't need full mbuf header here */
+struct rte_mbuf;
+
+#define RTE_PKT_NAME_MAX_LEN (32)
+
+typedef uint16_t (*pkt_rx_burst_t)(void *rxq,
+				   struct rte_mbuf **rx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Retrieve packets from a queue of a device. */
+
+typedef uint16_t (*pkt_tx_burst_t)(void *txq,
+				   struct rte_mbuf **tx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Send packets on a queue of a device. */
+
+#define RTE_PKT_DEV_HDR(structname) struct { \
+	pkt_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ \
+	pkt_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */ \
+	struct structname ## _data *data;  /**< Pointer to device data */ \
+}
+
+#define RTE_PKT_DEV_DATA_HDR struct { \
+	char name[RTE_PKT_NAME_MAX_LEN]; /**< Unique identifier name */ \
+\
+	void **rx_queues; /**< Array of pointers to RX queues. */ \
+	void **tx_queues; /**< Array of pointers to TX queues. */ \
+	uint16_t nb_rx_queues; /**< Number of RX queues. */ \
+	uint16_t nb_tx_queues; /**< Number of TX queues. */ \
+}
+
+struct rte_pkt_dev {
+	RTE_PKT_DEV_HDR(rte_pkt_dev);
+};
+
+struct rte_pkt_dev_data {
+	RTE_PKT_DEV_DATA_HDR;
+};
+
+/**
+ *
+ * Retrieve a burst of input packets from a receive queue of a
+ * device. The retrieved packets are stored in *rte_mbuf* structures whose
+ * pointers are supplied in the *rx_pkts* array.
+ *
+ * @param dev
+ *   The device to be polled for packets
+ * @param queue_id
+ *   The index of the receive queue from which to retrieve input packets.
+ * @param rx_pkts
+ *   The address of an array of pointers to *rte_mbuf* structures that
+ *   must be large enough to store *nb_pkts* pointers in it.
+ * @param nb_pkts
+ *   The maximum number of packets to retrieve.
+ * @return
+ *   The number of packets actually retrieved, which is the number
+ *   of pointers to *rte_mbuf* structures effectively supplied to the
+ *   *rx_pkts* array.
+ */
+static inline uint16_t
+rte_pkt_rx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
+			rx_pkts, nb_pkts);
+}
+
+/**
+ * Send a burst of output packets on a transmit queue of a device.
+ *
+ * @param dev
+ *   The device to be given the packets.
+ * @param queue_id
+ *   The index of the queue through which output packets must be sent.
+ * @param tx_pkts
+ *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
+ *   which contain the output packets.
+ * @param nb_pkts
+ *   The maximum number of packets to transmit.
+ * @return

lib/librte_pktdev/rte_pktdev.h line 137

Quoted 10 lines
lib/librte_pktdev/rte_pktdev.h new file +10 -0
+ *   The number of output packets actually stored in transmit descriptors of
+ *   the transmit ring. The return value can be less than the value of the
+ *   *tx_pkts* parameter when the transmit ring is full or has been filled up.
+ */
+static inline uint16_t
+rte_pkt_tx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id], tx_pkts, nb_pkts);
+}

That one looks much more lightweight, then Keith one :)
I have a question here:
Why are you guys so confident, that all foreseeable devices would fit into current eth_dev rx_burst/tx_burst API? As I understand, QAT devices have HW request/response ring pairs, so the idea probably is to make tx_burst() populate an request ring and rx_burst() to read from response ring, right?
Though right now rte_mbuf contains a lot of flags and data fields that are specific for ethdev, and probably have no sense for crypto dev.

Quoted 1 line

From other side, for QAT devices, I suppose you'll need crypto specific flags and data:

encrypt/decrypt, source and destination buffer addresses, some cipher specific data, etc.
Wonder do you plan to fit all that into current rte_mbuf structure, or do you plan to have some superset structure, that would consist of rte_mbuf plus some extra stuff, or ... ?
Konstantin

Quoted 9 lines
lib/librte_pktdev/rte_pktdev.h new file +7 -1
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_PKTDEV_H_ */
--

2.1.0

#36 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to a message not in the archive

From: Marc Sune <[email protected]<mailto:[email protected]>>
Date: Monday, April 20, 2015 at 1:51 AM
To: Keith Wiles <[email protected]<mailto:[email protected]>>, "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Subject: Re: [dpdk-dev] [RFC PATCH 0/4] pktdev

On 17/04/15 21:50, Wiles, Keith wrote:

Hi Marc and Bruce,

Hi Keith, Bruce,

On 4/17/15, 1:49 PM, "Marc Sune" <[email protected]><mailto:[email protected]> wrote:

On 17/04/15 17:16, Bruce Richardson wrote:

Hi all,

to continue this discussion a bit more, here is my, slightly different, slant
on what a pktdev abstraction may look like.

The primary objective I had in mind when drafting this is to provide the minimal abstraction that can be *easily* used as a common device abstraction for
existing (and future) device types to be passed to dataplane code. The patchset
demonstrates this by defining a minimal interface for pktdev - since I firmly
believe the interface should be as small as possible - and then showing how that
common interface can be used to unify rings and ethdevs under a common API for the
datapath. I believe any attempt to unify things much beyond this to the control
plane or setup phase is not worth doing - at least not initially - as at init time the code always needs to be aware of the underlying resource type in
order to configure it properly for dataplane use.

The overall objective I look to achieve is illustrated by the final patch in
the series, which is a sample app where the same code is used for all cores,
irrespective of the underlying device type.

To get to that point, patch 1 defines the minimal API - just RX and TX. The .c
file in the library is empty for simplicity, though I would see some functionality moving there when/if it makes sense e.g. the callback support
from ethdev, as is done in Keith's patchset.
Patch 2 then makes very minimal changes to ethdev to allow ethdevs to be used
as pktdevs, and to make use of the pktdev functions when appropriate Patch 3 was, for me, the key test for this implementation - how hard was it to
make an rte_ring usable as a pktdev too. Two single-line functions for RX/TX
and a separate "converter" function proved to be all that was necessary here -
and I believe simpler solutions may be possible too, as the extra structures
allocated on conversion could be merged into the rte_ring structure itself and
initialized on ring creation if we prefer that option. It is hoped/presumed that
wrapping other structures, such as KNI, may prove to be just as easily done.
[Not attempted yet - left as an exercise for the reader :-)].

Now, in terms of pktdev vs ethdev, there is nothing in this proposal that
cannot also be done using ethdev AFAIK. However, pktdev as outlined here should make the process far easier than trying to create a full PMD for something.
All NIC specific functions, including things like stop/start, are stripped out,
as they don't make sense for an rte_ring or other software objects. Also, the other thing this provides is that we can move away from just using
port ids. Instead in the same way as we now reference rings/mempools/KNIs etc
via pointer, we can do the same with ethernet ports as pktdevs on the data path.
There was discussion previously on moving beyond 8-bit port ids. If we look to
use ethdev as a common abstraction, I feel that change will soon have to be made
causing a large amount of code churn.

Hi Richard,

First thank you both for taking the time to look at this. I did not not reply to Keith because you Richard summarized most of my concerns.

I had a brief look to this second proposal. It is more aligned to what I had in mind. But still I feel it is slightly too complicated. I don't like much the necessary (in your approach) MACRO-like pkt_dev_data struct. It is also slightly inconvenient that the user has to do:

+ struct rte_pkt_dev *in = rte_eth_get_dev(0);

+ struct rte_pkt_dev *out = rte_ring_get_dev(
+ rte_ring_create(name, 4096, rte_socket_id(), 0));

What about something like (~pseudo-code):

rte_pkt_dev_data.h:

   enum rte_pkt_dev_type{
        RTE_PKT_DEV_ETH,
        RTE_PKT_DEV_RING,
        RTE_PKT_DEV_KNI,
        //Keep adding as more PMDs are supported
   };

//This struct may be redundant if there is nothing more

   struct rte_pkt_dev_data{
        enum rte_pkt_dev_type;
        //Placeholder, maybe we need more...

};

//Make RX/TX pktdev APIs more readable, but not really needed typedef void pkt_dev_t;

(In all PMDs and e.g. KNI and RINGs):

struct rte_eth_dev {
struct rte_pkt_dev_data pkt_dev;//
<++++++++++++++++++++++++++++++++++
eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function.
*/
struct rte_eth_dev_data *data; /**< Pointer to device data */ /...

rte_pkt_dev.h:

      #include <rte_ethdev.h>
      //Include PMD (and non-PMD) TX/RX headers...

static inline uint16_t rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
{
switch (((struct rte_pkt_dev_data*)dev)->type){
case RTE_PKT_DEV_ETH:
struct rte_eth_dev* eth_dev = (struct

rte_eth_dev*)pkt_dev;
                rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                break;
            case RTE_PKT_DEV_RING:
                //...
        }

}

//...

I do not see the functional different from my proposal other then a bit more search/replace, which does effect some of the PMD¹s. The changes to the PMD is just to use the macros as we now have a nested structure.

I think what I am proposing is different. See below.

The nesting and movement some structures and code to a common location is to provide a better way to add other devices. Moving code into a common set of structures and APIs should only improve the code as we get more devices added to DPDK. The basic flow and design is the same.

In your proposal you are movig TX/RX queues as well as some shared stuff and, most importantly, you are using function pointers to execute the RX/TX routines.

What I was proposing is to try to add the minimum common shared state in order to properly demultiplex the RX/TX call and have a common set of abstract calls (the pkt_dev type). In a way, I was proposing to deliberately not have a shared struct rte_dev_data because I think the internals of the "pkt_dev" can be very different across devices (e.g. queues in kni vs eth port vs. crypto?). I treat the pkt_dev as a "black box" that conforms to TX/RX API, leaving the developer of that device to define its internal structures as it better suites the needs. I only use each of the specific device type TX/RX APIs (external to us, pkt_dev library) in rte_pkt_dev.h. This also simplifies the refactor required to eventually integrate the rte_pkt_dev library and builds it "on top" of the existing APIs.

The other important difference with both, Bruce and your approach, and mine is the use of function pointers for RX/TX. I don't use them, which makes the entire abstracted TX/RX (including the final RX/TX routines itself) functions be "inlinable".

Btw, I forgot to add something basic in the previous pseudo-code. The different types have to be conditionally compiled according to compiled-in DPDK libs:

rte_pkt_dev.h:

    #include <rte_config.h>

    //Eth devices
    #ifdef RTE_LIBRTE_ETHER
    #include <rte_ethdev.h>
    #endif

    //KNI
    #ifdef RTE_LIBRTE_KNI
    #include <rte_kni.h>
    #endif

    //...
    //Include PMD (and non-PMD) TX/RX headers...
   static inline uint16_t
   rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
             struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
   {
        switch (((struct rte_pkt_dev_data*)dev)->type){
            #ifdef RTE_LIBRTE_ETHER
            case  RTE_PKT_DEV_ETH:
                struct rte_eth_dev* eth_dev = (struct rte_eth_dev*)pkt_dev;
                rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                break;
            #endif
            #ifdef RTE_LIBRTE_KNI
            case RTE_PKT_DEV_KNI:
                //...
                break;
            #endif

            default:
                    //Corrupted type or unsupported (without compiled support)
                    //Ignore or fail(fatal error)?
                    break;
        }

}

//...

This adds a switch into the performance path, not a great solution IMO.

From rte_common_device.h (format screwed with cut/paste and not all of the code)

struct rte_dev_data {
char name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */

void **rx_queues; /**< Array of pointers to RX queues. */
void **tx_queues; /**< Array of pointers to TX queues. */

uint16_t nb_rx_queues; /**< Number of RX queues. */
uint16_t nb_tx_queues; /**< Number of TX queues. */

uint16_t mtu; /**< Maximum Transmission Unit. */
uint8_t unit_id; /**< Unit/Port ID for this instance */
uint8_t _pad0; /* alignment filler */

void *dev_private; /**< PMD-specific private data */
uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation failures. */
uint32_t min_rx_buf_size; /**< Common rx buffer size handled by all
queues */
};

struct rte_dev_info {
struct rte_pci_device *pci_dev; /**< Device PCI information. */
const char *driver_name; /**< Device Driver name. */
unsigned int if_index; /**< Index to bound host interface, or 0
if none. */

        /* Use if_indextoname() to translate into an interface name. */
        unsigned int    _pad0;
};

struct rte_dev {
dev_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive
function. */
dev_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit
function. */
void *data; /**< Pointer to device data */
struct rte_dev_global *gbl_data; /**< Pointer to device global data
*/

        const struct rte_dev_drv *driver;       /**< Driver for this device */
        void                                    *dev_ops;       /**< Functions exported by PMD */
        struct rte_pci_device   *pci_dev;       /**< PCI info. supplied by

probing */
struct rte_dev_info *dev_info; /**< Pointer to the device info
structure */

        /** User application callback for interrupts if present */
        struct rte_dev_cb_list  link_intr_cbs;
        /**
        * User-supplied functions called from rx_burst to post-process
        * received packets before passing them to the user
        */
        struct rte_dev_rxtx_callback **post_rx_burst_cbs;
        /**
        * User-supplied functions called from tx_burst to pre-process
        * received packets before passing them to the driver for transmission.
        */
        struct rte_dev_rxtx_callback **pre_tx_burst_cbs;

What is the indended use of these callbacks and what is the benefit? If the user is supplying the callback, why not putting it directly after the RX and before the TX call in user's code (anyway)?

Just moving the callback routines next to the Rx/Tx routine pointers does not make a lot of different in this structure, right?

enum rte_dev_type dev_type; /**< Flag indicating the device type */
uint8_t attached; /**< Flag indicating the port is
attached */
};

From rte_ethdev.h

struct rte_eth_dev_info {
struct rte_dev_info di; /**< Common device information */

/* Rest of structure is for private device data */ uint32_t min_rx_bufsize; /**< Minimum size of RX buffer. */ uint32_t max_rx_pktlen; /**< Maximum configurable length of RX pkt. */ uint16_t max_rx_queues; /**< Maximum number of RX queues. */ uint16_t max_tx_queues; /**< Maximum number of TX queues. */ uint32_t max_mac_addrs; /**< Maximum number of MAC addresses. */ uint32_t max_hash_mac_addrs;
/** Maximum number of hash MAC addresses for MTA and UTA. */ uint16_t max_vfs; /**< Maximum number of VFs. */
uint16_t max_vmdq_pools; /**< Maximum number of VMDq pools. */ uint32_t rx_offload_capa; /**< Device RX offload capabilities. */ uint32_t tx_offload_capa; /**< Device TX offload capabilities. */ uint16_t reta_size;
/**< Device redirection table size, the total number of entries. */ /** Bit mask of RSS offloads, the bit offset also means flow type */ uint64_t flow_type_rss_offloads;
struct rte_eth_rxconf default_rxconf; /**< Default RX configuration */ struct rte_eth_txconf default_txconf; /**< Default TX configuration */ uint16_t vmdq_queue_base; /**< First queue ID for VMDQ pools. */ uint16_t vmdq_queue_num; /**< Queue number for VMDQ pools. */ uint16_t vmdq_pool_base; /**< First ID of VMDQ pools. */
};

struct rte_eth_dev_data {
        struct rte_dev_data             dd;                     /**< Common device data */

        /* Rest of the structure is private data */
        struct rte_eth_dev_sriov sriov;    /**< SRIOV data */

        struct rte_eth_link dev_link;
        /**< Link-level information & status */

        struct rte_eth_conf dev_conf;   /**< Configuration applied to device. */
        struct ether_addr* mac_addrs;   /**< Device Ethernet Link address. */
        uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
        /** bitmap array of associating Ethernet MAC addresses to pools */
        struct ether_addr* hash_mac_addrs;

        /** Device Ethernet MAC addresses of hash filtering. */
        uint8_t promiscuous  : 1,   /**< RX promiscuous mode ON(1) / OFF(0). */
                scattered_rx : 1,       /**< RX of scattered packets is ON(1) / OFF(0) */
                all_multicast: 1,   /**< RX all multicast mode ON(1) / OFF(0). */
                dev_started  : 1;   /**< Device state: STARTED(1) / STOPPED(0). */
};

In the case of rte_ethdev.h the rte_eth_dev turns into a macro '#define rte_eth_dev rte_dev', in other devices they may have a rte_xyz_dev structure rte_dev as the first member and then private members. Also later if we find something private to ethdev then a structure can be created.

Most of the code changes outside of these changes are because using a macro to fix the code was easier. Rewriting the functions to use real variables instead of casting void pointer could yield without the macros. Not sure as the performance impact in rewriting some of these functions to eliminate the macros.

This is the heart of what I am proposing and it just so happens to allow Bruce¹ ideas as well. I have another patch I have not sent that includes Bruce¹s ideas using my suggestions.

Being able to use a single API for all devices does have its benefits IMO, but I want to cleanup ethdev to allow for other devices to be added to the system.

At some point (when the cryptodev is done) I want to add it to this framework, plus add more APIs for crypto similar to Linux Crypto API or something we can agree is a reasonable set of APIs for DPDK.

I currently don't see the benefit of abstracting beyond the RX/TX functions, and I see more cons than pros. Doing so we will also make librte_pkt_dev sort of mandatory, even if you are not using it our abstracted RX/TX functions at all.

I do not see why we would not pull these common items out. Can you list your cons as I do not see your point here.

regards
marc

Regards,

++Keith

Maybe it is oversimplified? With this approach tough, we would barely touch the PMDs and the functionality can be built on top of the existing PMDs.

Thoughts?
Marc

Bruce Richardson (4):
Add example pktdev implementation
Make ethdev explicitly a subclass of pktdev
add support for a ring to be a pktdev
example app showing pktdevs used in a chain

  config/common_bsdapp           |   5 +
  config/common_linuxapp         |   5 +
  examples/pktdev/Makefile       |  57 +++++++++++
  examples/pktdev/basicfwd.c     | 222
+++++++++++++++++++++++++++++++++++++++++
  lib/Makefile                   |   1 +
  lib/librte_ether/rte_ethdev.h  |  26 ++---
  lib/librte_pktdev/Makefile     |  56 +++++++++++
  lib/librte_pktdev/rte_pktdev.c |  35 +++++++
  lib/librte_pktdev/rte_pktdev.h | 144 ++++++++++++++++++++++++++
  lib/librte_ring/rte_ring.c     |  41 ++++++++
  lib/librte_ring/rte_ring.h     |   3 +
  11 files changed, 582 insertions(+), 13 deletions(-)

create mode 100644 examples/pktdev/Makefile create mode 100644 examples/pktdev/basicfwd.c create mode 100644 lib/librte_pktdev/Makefile create mode 100644 lib/librte_pktdev/rte_pktdev.c create mode 100644 lib/librte_pktdev/rte_pktdev.h

#38 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to a message not in the archive
Quoted 171 lines · Keith

From: Marc Sune <[email protected]<mailto:[email protected]>>
Date: Monday, April 20, 2015 at 1:51 AM
To: Keith Wiles <[email protected]<mailto:[email protected]>>, "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
Subject: Re: [dpdk-dev] [RFC PATCH 0/4] pktdev

On 17/04/15 21:50, Wiles, Keith wrote:

Hi Marc and Bruce,

Hi Keith, Bruce,

On 4/17/15, 1:49 PM, "Marc Sune" <[email protected]><mailto:[email protected]> wrote:

On 17/04/15 17:16, Bruce Richardson wrote:

Hi all,

to continue this discussion a bit more, here is my, slightly different, slant
on what a pktdev abstraction may look like.

The primary objective I had in mind when drafting this is to provide the minimal abstraction that can be *easily* used as a common device abstraction for
existing (and future) device types to be passed to dataplane code. The patchset
demonstrates this by defining a minimal interface for pktdev - since I firmly
believe the interface should be as small as possible - and then showing how that
common interface can be used to unify rings and ethdevs under a common API for the
datapath. I believe any attempt to unify things much beyond this to the control
plane or setup phase is not worth doing - at least not initially - as at init time the code always needs to be aware of the underlying resource type in
order to configure it properly for dataplane use.

The overall objective I look to achieve is illustrated by the final patch in
the series, which is a sample app where the same code is used for all cores,
irrespective of the underlying device type.

To get to that point, patch 1 defines the minimal API - just RX and TX. The .c
file in the library is empty for simplicity, though I would see some functionality moving there when/if it makes sense e.g. the callback support
from ethdev, as is done in Keith's patchset.
Patch 2 then makes very minimal changes to ethdev to allow ethdevs to be used
as pktdevs, and to make use of the pktdev functions when appropriate Patch 3 was, for me, the key test for this implementation - how hard was it to
make an rte_ring usable as a pktdev too. Two single-line functions for RX/TX
and a separate "converter" function proved to be all that was necessary here -
and I believe simpler solutions may be possible too, as the extra structures
allocated on conversion could be merged into the rte_ring structure itself and
initialized on ring creation if we prefer that option. It is hoped/presumed that
wrapping other structures, such as KNI, may prove to be just as easily done.
[Not attempted yet - left as an exercise for the reader :-)].

Now, in terms of pktdev vs ethdev, there is nothing in this proposal that
cannot also be done using ethdev AFAIK. However, pktdev as outlined here should make the process far easier than trying to create a full PMD for something.
All NIC specific functions, including things like stop/start, are stripped out,
as they don't make sense for an rte_ring or other software objects. Also, the other thing this provides is that we can move away from just using
port ids. Instead in the same way as we now reference rings/mempools/KNIs etc
via pointer, we can do the same with ethernet ports as pktdevs on the data path.
There was discussion previously on moving beyond 8-bit port ids. If we look to
use ethdev as a common abstraction, I feel that change will soon have to be made
causing a large amount of code churn.

Hi Richard,

First thank you both for taking the time to look at this. I did not not reply to Keith because you Richard summarized most of my concerns.

I had a brief look to this second proposal. It is more aligned to what I had in mind. But still I feel it is slightly too complicated. I don't like much the necessary (in your approach) MACRO-like pkt_dev_data struct. It is also slightly inconvenient that the user has to do:

(quoted diff) +3 -0
+       struct rte_pkt_dev *in = rte_eth_get_dev(0);
 
+               struct rte_pkt_dev *out = rte_ring_get_dev(
+                               rte_ring_create(name, 4096,

rte_socket_id(), 0));

What about something like (~pseudo-code):

rte_pkt_dev_data.h:

  enum rte_pkt_dev_type{
       RTE_PKT_DEV_ETH,
       RTE_PKT_DEV_RING,
       RTE_PKT_DEV_KNI,
       //Keep adding as more PMDs are supported
  };

//This struct may be redundant if there is nothing more

  struct rte_pkt_dev_data{
       enum rte_pkt_dev_type;
       //Placeholder, maybe we need more...

};

//Make RX/TX pktdev APIs more readable, but not really needed typedef void pkt_dev_t;

(In all PMDs and e.g. KNI and RINGs):

struct rte_eth_dev {
struct rte_pkt_dev_data pkt_dev;//
<++++++++++++++++++++++++++++++++++
eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function.
*/
struct rte_eth_dev_data *data; /**< Pointer to device data */ /...

rte_pkt_dev.h:

     #include <rte_ethdev.h>
     //Include PMD (and non-PMD) TX/RX headers...

static inline uint16_t rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
{
switch (((struct rte_pkt_dev_data*)dev)->type){
case RTE_PKT_DEV_ETH:
struct rte_eth_dev* eth_dev = (struct

rte_eth_dev*)pkt_dev;
               rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
               break;
           case RTE_PKT_DEV_RING:
               //...
       }

}

Quoted 9 lines

//...

I do not see the functional different from my proposal other then a bit more search/replace, which does effect some of the PMD¹s. The changes to the PMD is just to use the macros as we now have a nested structure.

I think what I am proposing is different. See below.

Start of Keith's comment.

Quoted 5 lines

The nesting and movement some structures and code to a common location is to provide a better way to add other devices. Moving code into a common set of structures and APIs should only improve the code as we get more devices added to DPDK. The basic flow and design is the same.

End of Keith’s comment.

Quoted 18 lines

In your proposal you are movig TX/RX queues as well as some shared stuff and, most importantly, you are using function pointers to execute the RX/TX routines.

What I was proposing is to try to add the minimum common shared state in order to properly demultiplex the RX/TX call and have a common set of abstract calls (the pkt_dev type). In a way, I was proposing to deliberately not have a shared struct rte_dev_data because I think the internals of the "pkt_dev" can be very different across devices (e.g. queues in kni vs eth port vs. crypto?). I treat the pkt_dev as a "black box" that conforms to TX/RX API, leaving the developer of that device to define its internal structures as it better suites the needs. I only use each of the specific device type TX/RX APIs (external to us, pkt_dev library) in rte_pkt_dev.h. This also simplifies the refactor required to eventually integrate the rte_pkt_dev library and builds it "on top" of the existing APIs.

Quoted 4 lines

The other important difference with both, Bruce and your approach, and mine is the use of function pointers for RX/TX. I don't use them, which makes the entire abstracted TX/RX (including the final RX/TX routines itself) functions be "inlinable".

Making something inlinable is not based on using a pointer or not, is that what you mean?

Quoted 132 lines

Btw, I forgot to add something basic in the previous pseudo-code. The different types have to be conditionally compiled according to compiled-in DPDK libs:

rte_pkt_dev.h:

   #include <rte_config.h>

   //Eth devices
   #ifdef RTE_LIBRTE_ETHER
   #include <rte_ethdev.h>
   #endif

   //KNI
   #ifdef RTE_LIBRTE_KNI
   #include <rte_kni.h>
   #endif
   //...
   //Include PMD (and non-PMD) TX/RX headers...

static inline uint16_t rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
struct rte_mbuf **tx_pkts, uint16_t nb_pkts)

  {
       switch (((struct rte_pkt_dev_data*)dev)->type){
           #ifdef RTE_LIBRTE_ETHER
           case  RTE_PKT_DEV_ETH:
               struct rte_eth_dev* eth_dev = (struct
rte_eth_dev*)pkt_dev;
               rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
               break;
           #endif

           #ifdef RTE_LIBRTE_KNI
           case RTE_PKT_DEV_KNI:
               //...
               break;
           #endif

           default:
                   //Corrupted type or unsupported (without compiled
support)
                   //Ignore or fail(fatal error)?
                   break;
       }

}

//...

This adds a switch into the performance path, not a great solution IMO.

From rte_common_device.h (format screwed with cut/paste and not all of the code)

struct rte_dev_data {
char name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */

void **rx_queues; /**< Array of pointers to RX
queues. */
void **tx_queues; /**< Array of pointers to TX
queues. */

uint16_t nb_rx_queues; /**< Number of RX queues. */
uint16_t nb_tx_queues; /**< Number of TX queues. */

uint16_t mtu; /**< Maximum Transmission Unit. */
uint8_t unit_id; /**< Unit/Port ID for this
instance */
uint8_t _pad0; /* alignment filler */

void *dev_private; /**< PMD-specific private data */
uint64_t rx_mbuf_alloc_failed; /**< RX ring mbuf allocation
failures. */
uint32_t min_rx_buf_size; /**< Common rx buffer size
handled by all
queues */
};

struct rte_dev_info {
struct rte_pci_device *pci_dev; /**< Device PCI information.
*/
const char *driver_name; /**< Device Driver name.
*/
unsigned int if_index; /**< Index to bound host
interface, or 0
if none. */

       /* Use if_indextoname() to translate into an interface name. */
       unsigned int    _pad0;
};

struct rte_dev {
dev_rx_burst_t rx_pkt_burst; /**< Pointer to PMD
receive
function. */
dev_tx_burst_t tx_pkt_burst; /**< Pointer to PMD
transmit
function. */
void *data; /**<
Pointer to device data */
struct rte_dev_global *gbl_data; /**< Pointer to device
global data
*/
const struct rte_dev_drv *driver; /**< Driver for this
device */
void *dev_ops; /**<
Functions exported by PMD */
struct rte_pci_device *pci_dev; /**< PCI info. supplied by
probing */
struct rte_dev_info *dev_info; /**<
Pointer to the device info
structure */

       /** User application callback for interrupts if present */
       struct rte_dev_cb_list  link_intr_cbs;
       /**
       * User-supplied functions called from rx_burst to post-process
       * received packets before passing them to the user
       */
       struct rte_dev_rxtx_callback **post_rx_burst_cbs;
       /**
       * User-supplied functions called from tx_burst to pre-process
       * received packets before passing them to the driver for
transmission.
       */
       struct rte_dev_rxtx_callback **pre_tx_burst_cbs;
Quoted 3 lines

What is the indended use of these callbacks and what is the benefit? If the user is supplying the callback, why not putting it directly after the RX and before the TX call in user's code (anyway)?

Keith’s Comment.

Quoted 3 lines

Just moving the callback routines next to the Rx/Tx routine pointers does not make a lot of different in this structure, right?

Keith’s comment end.

Quoted 92 lines

enum rte_dev_type dev_type; /**< Flag
indicating the device type */
uint8_t attached; /**< Flag indicating the
port is
attached */
};

From rte_ethdev.h

struct rte_eth_dev_info {
struct rte_dev_info di; /**< Common device information */

/* Rest of structure is for private device data */ uint32_t min_rx_bufsize; /**< Minimum size of RX buffer. */ uint32_t max_rx_pktlen; /**< Maximum configurable length of RX
pkt. */
uint16_t max_rx_queues; /**< Maximum number of RX queues. */ uint16_t max_tx_queues; /**< Maximum number of TX queues. */ uint32_t max_mac_addrs; /**< Maximum number of MAC addresses. */ uint32_t max_hash_mac_addrs;
/** Maximum number of hash MAC addresses for MTA and UTA. */ uint16_t max_vfs; /**< Maximum number of VFs. */ uint16_t max_vmdq_pools; /**< Maximum number of VMDq pools. */ uint32_t rx_offload_capa; /**< Device RX offload capabilities. */ uint32_t tx_offload_capa; /**< Device TX offload capabilities. */ uint16_t reta_size;
/**< Device redirection table size, the total number of entries.
*/

       /** Bit mask of RSS offloads, the bit offset also means flow type

*/
uint64_t flow_type_rss_offloads;
struct rte_eth_rxconf default_rxconf; /**< Default RX
configuration */
struct rte_eth_txconf default_txconf; /**< Default TX
configuration */
uint16_t vmdq_queue_base; /**< First queue ID for VMDQ pools. */ uint16_t vmdq_queue_num; /**< Queue number for VMDQ pools. */ uint16_t vmdq_pool_base; /**< First ID of VMDQ pools. */
};

struct rte_eth_dev_data {
struct rte_dev_data dd; /**<
Common device data */

       /* Rest of the structure is private data */
       struct rte_eth_dev_sriov sriov;    /**< SRIOV data */

       struct rte_eth_link dev_link;
       /**< Link-level information & status */

       struct rte_eth_conf dev_conf;   /**< Configuration applied to
device. */
       struct ether_addr* mac_addrs;   /**< Device Ethernet Link
address. */
       uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
       /** bitmap array of associating Ethernet MAC addresses to pools */
       struct ether_addr* hash_mac_addrs;

       /** Device Ethernet MAC addresses of hash filtering. */
       uint8_t promiscuous  : 1,   /**< RX promiscuous mode ON(1) /

OFF(0). */
scattered_rx : 1, /**< RX of scattered packets is
ON(1) / OFF(0) */
all_multicast: 1, /**< RX all multicast mode ON(1) /
OFF(0). */

               dev_started  : 1;   /**< Device state: STARTED(1) /

STOPPED(0). */
};

In the case of rte_ethdev.h the rte_eth_dev turns into a macro '#define rte_eth_dev rte_dev', in other devices they may have a rte_xyz_dev structure rte_dev as the first member and then private members. Also later if we find something private to ethdev then a structure can be created.

Most of the code changes outside of these changes are because using a macro to fix the code was easier. Rewriting the functions to use real variables instead of casting void pointer could yield without the macros. Not sure as the performance impact in rewriting some of these functions to eliminate the macros.

This is the heart of what I am proposing and it just so happens to allow Bruce¹ ideas as well. I have another patch I have not sent that includes Bruce¹s ideas using my suggestions.

Being able to use a single API for all devices does have its benefits IMO, but I want to cleanup ethdev to allow for other devices to be added to the system.

Quoted 8 lines

At some point (when the cryptodev is done) I want to add it to this framework, plus add more APIs for crypto similar to Linux Crypto API or something we can agree is a reasonable set of APIs for DPDK.

I currently don't see the benefit of abstracting beyond the RX/TX functions, and I see more cons than pros. Doing so we will also make librte_pkt_dev sort of mandatory, even if you are not using it our abstracted RX/TX functions at all.

Keith Comment.

Quoted 3 lines

I do not see why we would not pull these common items out. Can you list your cons as I do not see your point here.

Keith Comment

Quoted 49 lines

regards
marc

Regards,

++Keith

Maybe it is oversimplified? With this approach tough, we would barely touch the PMDs and the functionality can be built on top of the existing PMDs.

Thoughts?
Marc

Bruce Richardson (4):
Add example pktdev implementation
Make ethdev explicitly a subclass of pktdev
add support for a ring to be a pktdev
example app showing pktdevs used in a chain

 config/common_bsdapp           |   5 +
 config/common_linuxapp         |   5 +
 examples/pktdev/Makefile       |  57 +++++++++++
 examples/pktdev/basicfwd.c     | 222
+++++++++++++++++++++++++++++++++++++++++
 lib/Makefile                   |   1 +
 lib/librte_ether/rte_ethdev.h  |  26 ++---
 lib/librte_pktdev/Makefile     |  56 +++++++++++
 lib/librte_pktdev/rte_pktdev.c |  35 +++++++
 lib/librte_pktdev/rte_pktdev.h | 144 ++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.c     |  41 ++++++++
 lib/librte_ring/rte_ring.h     |   3 +
 11 files changed, 582 insertions(+), 13 deletions(-)
 create mode 100644 examples/pktdev/Makefile
 create mode 100644 examples/pktdev/basicfwd.c
 create mode 100644 lib/librte_pktdev/Makefile
 create mode 100644 lib/librte_pktdev/rte_pktdev.c
 create mode 100644 lib/librte_pktdev/rte_pktdev.h
#16 lore raw

Re: [RFC PATCH 1/4] Add example pktdev implementation

In reply to a message not in the archive
Quoted 330 lines · Konstantin
Quoted 305 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Friday, April 17, 2015 4:17 PM
To: [email protected]; Wiles, Keith
Subject: [dpdk-dev] [RFC PATCH 1/4] Add example pktdev implementation

This commit demonstrates what a minimal API for all packet handling types would look like. It simply provides the necessary parts for receiving and transmiting packets, and is based off the ethdev implementation.

---
 config/common_bsdapp           |   5 ++
 config/common_linuxapp         |   5 ++
 lib/Makefile                   |   1 +
 lib/librte_pktdev/Makefile     |  56 ++++++++++++++++
 lib/librte_pktdev/rte_pktdev.c |  35 ++++++++++
 lib/librte_pktdev/rte_pktdev.h | 144 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 246 insertions(+)
 create mode 100644 lib/librte_pktdev/Makefile
 create mode 100644 lib/librte_pktdev/rte_pktdev.c
 create mode 100644 lib/librte_pktdev/rte_pktdev.h
config/common_bsdapp +5 -0
index 8ff4dc2..d2b932c 100644
@@ -132,6 +132,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
config/common_linuxapp +5 -0
index 09a58ac..5bda416 100644
@@ -129,6 +129,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
lib/Makefile +1 -0
index d94355d..4db5ee0 100644
@@ -32,6 +32,7 @@
 include $(RTE_SDK)/mk/rte.vars.mk
 
 DIRS-y += librte_compat
+DIRS-$(CONFIG_RTE_LIBRTE_PKTDEV) += librte_pktdev
 DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_MALLOC) += librte_malloc
 DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring
lib/librte_pktdev/Makefile new file +56 -0
new file mode 100644
index 0000000..2d3b3a1
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2015 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 = libpktdev.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+EXPORT_MAP := rte_pktdev_version.map
+
+LIBABIVER := 1
+
+SRCS-y += rte_pktdev.c
+
+#
+# Export include files
+#
+SYMLINK-y-include += rte_pktdev.h
+
+# this lib depends upon no others:
+DEPDIRS-y +=
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_pktdev/rte_pktdev.c new file +36 -0
new file mode 100644
index 0000000..4c32d86
@@ -0,0 +1,36 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_pktdev.h"
+
+/* For future use */
lib/librte_pktdev/rte_pktdev.h new file +127 -0
new file mode 100644
index 0000000..8a5699a
@@ -0,0 +1,144 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_PKTDEV_H_
+#define _RTE_PKTDEV_H_
+
+#include <stdint.h>
+
+/**
+ * @file
+ *
+ * RTE Packet Processing Device API
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* forward definition of mbuf structure. We don't need full mbuf header here */
+struct rte_mbuf;
+
+#define RTE_PKT_NAME_MAX_LEN (32)
+
+typedef uint16_t (*pkt_rx_burst_t)(void *rxq,
+				   struct rte_mbuf **rx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Retrieve packets from a queue of a device. */
+
+typedef uint16_t (*pkt_tx_burst_t)(void *txq,
+				   struct rte_mbuf **tx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Send packets on a queue of a device. */
+
+#define RTE_PKT_DEV_HDR(structname) struct { \
+	pkt_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ \
+	pkt_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */ \
+	struct structname ## _data *data;  /**< Pointer to device data */ \
+}
+
+#define RTE_PKT_DEV_DATA_HDR struct { \
+	char name[RTE_PKT_NAME_MAX_LEN]; /**< Unique identifier name */ \
+\
+	void **rx_queues; /**< Array of pointers to RX queues. */ \
+	void **tx_queues; /**< Array of pointers to TX queues. */ \
+	uint16_t nb_rx_queues; /**< Number of RX queues. */ \
+	uint16_t nb_tx_queues; /**< Number of TX queues. */ \
+}
+
+struct rte_pkt_dev {
+	RTE_PKT_DEV_HDR(rte_pkt_dev);
+};
+
+struct rte_pkt_dev_data {
+	RTE_PKT_DEV_DATA_HDR;
+};
+
+/**
+ *
+ * Retrieve a burst of input packets from a receive queue of a
+ * device. The retrieved packets are stored in *rte_mbuf* structures whose
+ * pointers are supplied in the *rx_pkts* array.
+ *
+ * @param dev
+ *   The device to be polled for packets
+ * @param queue_id
+ *   The index of the receive queue from which to retrieve input packets.
+ * @param rx_pkts
+ *   The address of an array of pointers to *rte_mbuf* structures that
+ *   must be large enough to store *nb_pkts* pointers in it.
+ * @param nb_pkts
+ *   The maximum number of packets to retrieve.
+ * @return
+ *   The number of packets actually retrieved, which is the number
+ *   of pointers to *rte_mbuf* structures effectively supplied to the
+ *   *rx_pkts* array.
+ */
+static inline uint16_t
+rte_pkt_rx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
+			rx_pkts, nb_pkts);
+}
+
+/**
+ * Send a burst of output packets on a transmit queue of a device.
+ *
+ * @param dev
+ *   The device to be given the packets.
+ * @param queue_id
+ *   The index of the queue through which output packets must be sent.
+ * @param tx_pkts
+ *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
+ *   which contain the output packets.
+ * @param nb_pkts
+ *   The maximum number of packets to transmit.
+ * @return

lib/librte_pktdev/rte_pktdev.h line 137

Quoted 10 lines
lib/librte_pktdev/rte_pktdev.h new file +10 -0
+ *   The number of output packets actually stored in transmit descriptors of
+ *   the transmit ring. The return value can be less than the value of the
+ *   *tx_pkts* parameter when the transmit ring is full or has been filled up.
+ */
+static inline uint16_t
+rte_pkt_tx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id], tx_pkts, nb_pkts);
+}

That one looks much more lightweight, then Keith one :)
I have a question here:
Why are you guys so confident, that all foreseeable devices would fit into current eth_dev rx_burst/tx_burst API? As I understand, QAT devices have HW request/response ring pairs, so the idea probably is to make tx_burst() populate an request ring and rx_burst() to read from response ring, right?
Though right now rte_mbuf contains a lot of flags and data fields that are specific for ethdev, and probably have no sense for crypto dev. From other side, for QAT devices, I suppose you'll need crypto specific flags and data:
encrypt/decrypt, source and destination buffer addresses, some cipher specific data, etc.
Wonder do you plan to fit all that into current rte_mbuf structure, or do you plan to have some superset structure, that would consist of rte_mbuf plus some extra stuff, or ... ?
Konstantin

Quoted 1 line

From my point of view, the purpose of a pktdev API to to define a common API

for devices that read/write (i.e. RX/TX) mbufs. If other devices don't fit that model, then they don't use it. However, we already have a number of different device types that already read/write mbufs, and there are likely more in future, so it would be nice to have a common API that can be used across those types so the data path can be source-neutral when processing mbufs. So far, we have three proposals on how that might be achieved. :-)

As for the crypto, there is still a lot of investigation work to be done here, and Keith is probably better placed than me to comment on it. But if you look at any application using DPDK for packet processing, the mbuf is still going to be at the heart of it, so whatever the actual crypto API is like, it's going to have to have to fit into an "mbuf world" anyway. If the crypto-dev APIs don't work with mbufs, then it's pushing work onto the app (or higher level libs) to extract the meaningful fields from the mbuf to pass to the dev. Therefore, in a DPDK library, I would think it better to have the dev work with mbufs directly, as the rest of DPDK does. For the extra data, my suggestion would be to have the mbuf store a pointer to a crypto context, rather than trying to store it directly in the mbuf itself - there's no way we'd fit a crypto key in there! - and the context would be shared among a set of packets rather than per-mbuf.

/Bruce

#35 lore raw

Re: [RFC PATCH 0/4] pktdev

In reply to Bruce Richardson

Bruce,

Quoted 71 lines · Bruce Richardson
Quoted 70 lines · Marc Sune
Quoted 1 line · Keith

Hi Marc and Bruce,

Hi Keith, Bruce,

Quoted 1 line · Marc Sune

What I was proposing is to try to add the minimum common shared state in order to properly demultiplex the RX/TX call and have a common set of abstract calls (the pkt_dev type). In a way, I was proposing to deliberately not have a shared struct rte_dev_data because I think the internals of the "pkt_dev" can be very different across devices (e.g. queues in kni vs eth port vs. crypto?). I treat the pkt_dev as a "black box" that conforms to TX/RX API, leaving the developer of that device to define its internal structures as it better suites the needs. I only use each of the specific device type TX/RX APIs (external to us, pkt_dev library) in rte_pkt_dev.h. This also simplifies the refactor required to eventually integrate the rte_pkt_dev library and builds it "on top" of the existing APIs.

The other important difference with both, Bruce and your approach, and mine is the use of function pointers for RX/TX. I don't use them, which makes the entire abstracted TX/RX (including the final RX/TX routines itself) functions be "inlinable".

Btw, I forgot to add something basic in the previous pseudo-code. The different types have to be conditionally compiled according to compiled-in DPDK libs:

rte_pkt_dev.h:

     #include <rte_config.h>

     //Eth devices
     #ifdef RTE_LIBRTE_ETHER
     #include <rte_ethdev.h>
     #endif

     //KNI
     #ifdef RTE_LIBRTE_KNI
     #include <rte_kni.h>
     #endif

     //...
     //Include PMD (and non-PMD) TX/RX headers...

    static inline uint16_t
    rte_pkt_tx_burst(pkt_dev_t* dev, uint16_t queue_id,
              struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
    {
         switch (((struct rte_pkt_dev_data*)dev)->type){
             #ifdef RTE_LIBRTE_ETHER
             case  RTE_PKT_DEV_ETH:
                 struct rte_eth_dev* eth_dev = (struct rte_eth_dev*)pkt_dev;
                 rte_pkt_tx_burst(eth_dev, queue_id, tx_pkts, nb_pkts);
                 break;
             #endif

             #ifdef RTE_LIBRTE_KNI
             case RTE_PKT_DEV_KNI:
                 //...
                 break;
             #endif

             default:
                     //Corrupted type or unsupported (without compiled
support)
                     //Ignore or fail(fatal error)?
                     break;
         }
    }
Quoted 6 lines
Quoted 1 line
    //...

Yes, this is an interesting approach, and with the inlining could indeed be less overhead for the ring and kni compared to my suggestion due to the inlining. There might be a slight overhead for the RX/TX ethdev functions though - 1/2 cycles due to the extra (hopefully predictable) branch in the RX/TX call, since we always need the indirect function call for the PMDs.

I guess if the user application uses multiple types of port (pkt devs), which is basically when you get a benefit out of the abstracted API, they likely are doing a similar if / switch statement.

Ofc, with this approach single type pkt-dev applicationss can always use the "lower-level" APIs remain the same, as of now.

Quoted 4 lines

I also like the use of pointers rather than port ids.

Let me think on this a bit more.

If you (both, Keith&you) think it is worth, I can propose an RFC patch based on (v3?).

Marc

Quoted 2 lines

/Bruce

#17 lore raw

Re: [RFC PATCH 1/4] Add example pktdev implementation

In reply to Bruce Richardson
Quoted 338 lines

-----Original Message-----
From: Richardson, Bruce
Sent: Monday, April 20, 2015 4:03 PM
To: Ananyev, Konstantin
Cc: [email protected]; Wiles, Keith
Subject: Re: [dpdk-dev] [RFC PATCH 1/4] Add example pktdev implementation

Quoted 319 lines · Konstantin
Quoted 305 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Friday, April 17, 2015 4:17 PM
To: [email protected]; Wiles, Keith
Subject: [dpdk-dev] [RFC PATCH 1/4] Add example pktdev implementation

This commit demonstrates what a minimal API for all packet handling types would look like. It simply provides the necessary parts for receiving and transmiting packets, and is based off the ethdev implementation.

---
 config/common_bsdapp           |   5 ++
 config/common_linuxapp         |   5 ++
 lib/Makefile                   |   1 +
 lib/librte_pktdev/Makefile     |  56 ++++++++++++++++
 lib/librte_pktdev/rte_pktdev.c |  35 ++++++++++
 lib/librte_pktdev/rte_pktdev.h | 144 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 246 insertions(+)
 create mode 100644 lib/librte_pktdev/Makefile
 create mode 100644 lib/librte_pktdev/rte_pktdev.c
 create mode 100644 lib/librte_pktdev/rte_pktdev.h
config/common_bsdapp +5 -0
index 8ff4dc2..d2b932c 100644
@@ -132,6 +132,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
config/common_linuxapp +5 -0
index 09a58ac..5bda416 100644
@@ -129,6 +129,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
lib/Makefile +1 -0
index d94355d..4db5ee0 100644
@@ -32,6 +32,7 @@
 include $(RTE_SDK)/mk/rte.vars.mk
 
 DIRS-y += librte_compat
+DIRS-$(CONFIG_RTE_LIBRTE_PKTDEV) += librte_pktdev
 DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_MALLOC) += librte_malloc
 DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring
lib/librte_pktdev/Makefile new file +56 -0
new file mode 100644
index 0000000..2d3b3a1
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2015 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 = libpktdev.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+EXPORT_MAP := rte_pktdev_version.map
+
+LIBABIVER := 1
+
+SRCS-y += rte_pktdev.c
+
+#
+# Export include files
+#
+SYMLINK-y-include += rte_pktdev.h
+
+# this lib depends upon no others:
+DEPDIRS-y +=
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_pktdev/rte_pktdev.c new file +36 -0
new file mode 100644
index 0000000..4c32d86
@@ -0,0 +1,36 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_pktdev.h"
+
+/* For future use */
lib/librte_pktdev/rte_pktdev.h new file +127 -0
new file mode 100644
index 0000000..8a5699a
@@ -0,0 +1,144 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_PKTDEV_H_
+#define _RTE_PKTDEV_H_
+
+#include <stdint.h>
+
+/**
+ * @file
+ *
+ * RTE Packet Processing Device API
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* forward definition of mbuf structure. We don't need full mbuf header here */
+struct rte_mbuf;
+
+#define RTE_PKT_NAME_MAX_LEN (32)
+
+typedef uint16_t (*pkt_rx_burst_t)(void *rxq,
+				   struct rte_mbuf **rx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Retrieve packets from a queue of a device. */
+
+typedef uint16_t (*pkt_tx_burst_t)(void *txq,
+				   struct rte_mbuf **tx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Send packets on a queue of a device. */
+
+#define RTE_PKT_DEV_HDR(structname) struct { \
+	pkt_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ \
+	pkt_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */ \
+	struct structname ## _data *data;  /**< Pointer to device data */ \
+}
+
+#define RTE_PKT_DEV_DATA_HDR struct { \
+	char name[RTE_PKT_NAME_MAX_LEN]; /**< Unique identifier name */ \
+\
+	void **rx_queues; /**< Array of pointers to RX queues. */ \
+	void **tx_queues; /**< Array of pointers to TX queues. */ \
+	uint16_t nb_rx_queues; /**< Number of RX queues. */ \
+	uint16_t nb_tx_queues; /**< Number of TX queues. */ \
+}
+
+struct rte_pkt_dev {
+	RTE_PKT_DEV_HDR(rte_pkt_dev);
+};
+
+struct rte_pkt_dev_data {
+	RTE_PKT_DEV_DATA_HDR;
+};
+
+/**
+ *
+ * Retrieve a burst of input packets from a receive queue of a
+ * device. The retrieved packets are stored in *rte_mbuf* structures whose
+ * pointers are supplied in the *rx_pkts* array.
+ *
+ * @param dev
+ *   The device to be polled for packets
+ * @param queue_id
+ *   The index of the receive queue from which to retrieve input packets.
+ * @param rx_pkts
+ *   The address of an array of pointers to *rte_mbuf* structures that
+ *   must be large enough to store *nb_pkts* pointers in it.
+ * @param nb_pkts
+ *   The maximum number of packets to retrieve.
+ * @return
+ *   The number of packets actually retrieved, which is the number
+ *   of pointers to *rte_mbuf* structures effectively supplied to the
+ *   *rx_pkts* array.
+ */
+static inline uint16_t
+rte_pkt_rx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
+			rx_pkts, nb_pkts);
+}
+
+/**
+ * Send a burst of output packets on a transmit queue of a device.
+ *
+ * @param dev
+ *   The device to be given the packets.
+ * @param queue_id
+ *   The index of the queue through which output packets must be sent.
+ * @param tx_pkts
+ *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
+ *   which contain the output packets.
+ * @param nb_pkts
+ *   The maximum number of packets to transmit.
+ * @return

lib/librte_pktdev/rte_pktdev.h line 137

Quoted 10 lines
lib/librte_pktdev/rte_pktdev.h new file +10 -0
+ *   The number of output packets actually stored in transmit descriptors of
+ *   the transmit ring. The return value can be less than the value of the
+ *   *tx_pkts* parameter when the transmit ring is full or has been filled up.
+ */
+static inline uint16_t
+rte_pkt_tx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id], tx_pkts, nb_pkts);
+}

That one looks much more lightweight, then Keith one :)
I have a question here:
Why are you guys so confident, that all foreseeable devices would fit into current eth_dev rx_burst/tx_burst API?

Quoted 10 lines

As I understand, QAT devices have HW request/response ring pairs, so the idea probably is to make tx_burst() populate an request ring and rx_burst() to read from response ring, right?
Though right now rte_mbuf contains a lot of flags and data fields that are specific for ethdev, and probably have no sense for crypto dev. From other side, for QAT devices, I suppose you'll need crypto specific flags and data:
encrypt/decrypt, source and destination buffer addresses, some cipher specific data, etc.
Wonder do you plan to fit all that into current rte_mbuf structure, or do you plan to have some superset structure, that would consist of rte_mbuf plus some extra stuff, or ... ?
Konstantin

Quoted 7 lines

From my point of view, the purpose of a pktdev API to to define a common API for devices that read/write (i.e. RX/TX) mbufs. If other devices don't fit that model, then they don't use it. However, we already have a number of different device types that already read/write mbufs, and there are likely more in future, so it would be nice to have a common API that can be used across those types so the data path can be source-neutral when processing mbufs. So far, we have three proposals on how that might be achieved. :-)

Ok, probably I misunderstood previous RFCs about pktdev.
So pktdev is not going to be a generic abstraction for any foreseeable device types: eth, crypto, compress, dpi, etc? It would represent only subset of dev types: real eth devices, plus SW emulated ones
that can mimic rx_burst/tx_burst, but don't support any other eth specific ops (kni, pmd_ring)? Basically what we support right now?
And for future device types to support (crypto, etc) there would be something else?

Quoted 9 lines

As for the crypto, there is still a lot of investigation work to be done here, and Keith is probably better placed than me to comment on it. But if you look at any application using DPDK for packet processing, the mbuf is still going to be at the heart of it, so whatever the actual crypto API is like, it's going to have to have to fit into an "mbuf world" anyway.
If the crypto-dev APIs don't work
with mbufs, then it's pushing work onto the app (or higher level libs) to extract the meaningful fields from the mbuf to pass to the dev.

As I understand application (or some upper layer lib) would have to do that work anyway:
RX packet, find and read related to this packet crypto data, and pass all that info to the crypto dev, right? I can hardly imagine, that in reality you always would be able to do:

n = rx_burst(eth_dev, pkts, n);
n = tx_burst(crypto_dev, pkts, n);

without any processing of incoming packets in between.
The difference is only how that information will be passed into crypto device:
Would you need to to update an mbuf, or fill some other structure.

Quoted 3 lines

Therefore, in a DPDK
library, I would think it better to have the dev work with mbufs directly, as the rest of DPDK does.

I wouldn't say that all DPDK libs accepts data as mbufs only.
Only those where it makes sense: PMDs, ip_frag/reassembly, pipeline fw.
Let say rte_hash and rte_acl accept input data in a neutral way.
You wouldn't expect rte_hash_lookup() or rte_acl_classify() to accept pointer(s) to the mbuf.
if you'll have a SW implemented encrypt()/decrypt() routines, you probably wouldn't require an mbuf as input parameter either. Wouldn't it be more plausible to create a new struct rte_crypto_buf (or something) to pass information to/from crypto devices. Then we can provide for it an ability to attach/detach to rte_mbuf(s) buf_addr(s).
That way we can probably make crypto_buf to attach to 2 mbufs at once (source and destination).

Konstantin

Quoted 6 lines

For the extra data, my suggestion would be to have the
mbuf store a pointer to a crypto context, rather than trying to store it directly in the mbuf itself - there's no way we'd fit a crypto key in there! - and the context would be shared among a set of packets rather than per-mbuf.

/Bruce

#19 lore raw

Re: [RFC PATCH 1/4] Add example pktdev implementation

In reply to a message not in the archive
Quoted 346 lines · Konstantin
Quoted 338 lines

-----Original Message-----
From: Richardson, Bruce
Sent: Monday, April 20, 2015 4:03 PM
To: Ananyev, Konstantin
Cc: [email protected]; Wiles, Keith
Subject: Re: [dpdk-dev] [RFC PATCH 1/4] Add example pktdev implementation

Quoted 319 lines · Konstantin
Quoted 305 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Friday, April 17, 2015 4:17 PM
To: [email protected]; Wiles, Keith
Subject: [dpdk-dev] [RFC PATCH 1/4] Add example pktdev implementation

This commit demonstrates what a minimal API for all packet handling types would look like. It simply provides the necessary parts for receiving and transmiting packets, and is based off the ethdev implementation.

---
 config/common_bsdapp           |   5 ++
 config/common_linuxapp         |   5 ++
 lib/Makefile                   |   1 +
 lib/librte_pktdev/Makefile     |  56 ++++++++++++++++
 lib/librte_pktdev/rte_pktdev.c |  35 ++++++++++
 lib/librte_pktdev/rte_pktdev.h | 144 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 246 insertions(+)
 create mode 100644 lib/librte_pktdev/Makefile
 create mode 100644 lib/librte_pktdev/rte_pktdev.c
 create mode 100644 lib/librte_pktdev/rte_pktdev.h
config/common_bsdapp +5 -0
index 8ff4dc2..d2b932c 100644
@@ -132,6 +132,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
config/common_linuxapp +5 -0
index 09a58ac..5bda416 100644
@@ -129,6 +129,11 @@ CONFIG_RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT=y
 CONFIG_RTE_LIBRTE_KVARGS=y
 
 #
+# Compile generic packet handling device library
+#
+CONFIG_RTE_LIBRTE_PKTDEV=y
+
+#
 # Compile generic ethernet library
 #
 CONFIG_RTE_LIBRTE_ETHER=y
lib/Makefile +1 -0
index d94355d..4db5ee0 100644
@@ -32,6 +32,7 @@
 include $(RTE_SDK)/mk/rte.vars.mk
 
 DIRS-y += librte_compat
+DIRS-$(CONFIG_RTE_LIBRTE_PKTDEV) += librte_pktdev
 DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal
 DIRS-$(CONFIG_RTE_LIBRTE_MALLOC) += librte_malloc
 DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring
lib/librte_pktdev/Makefile new file +56 -0
new file mode 100644
index 0000000..2d3b3a1
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2015 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 = libpktdev.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+EXPORT_MAP := rte_pktdev_version.map
+
+LIBABIVER := 1
+
+SRCS-y += rte_pktdev.c
+
+#
+# Export include files
+#
+SYMLINK-y-include += rte_pktdev.h
+
+# this lib depends upon no others:
+DEPDIRS-y +=
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_pktdev/rte_pktdev.c new file +36 -0
new file mode 100644
index 0000000..4c32d86
@@ -0,0 +1,36 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_pktdev.h"
+
+/* For future use */
lib/librte_pktdev/rte_pktdev.h new file +127 -0
new file mode 100644
index 0000000..8a5699a
@@ -0,0 +1,144 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 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_PKTDEV_H_
+#define _RTE_PKTDEV_H_
+
+#include <stdint.h>
+
+/**
+ * @file
+ *
+ * RTE Packet Processing Device API
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* forward definition of mbuf structure. We don't need full mbuf header here */
+struct rte_mbuf;
+
+#define RTE_PKT_NAME_MAX_LEN (32)
+
+typedef uint16_t (*pkt_rx_burst_t)(void *rxq,
+				   struct rte_mbuf **rx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Retrieve packets from a queue of a device. */
+
+typedef uint16_t (*pkt_tx_burst_t)(void *txq,
+				   struct rte_mbuf **tx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Send packets on a queue of a device. */
+
+#define RTE_PKT_DEV_HDR(structname) struct { \
+	pkt_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ \
+	pkt_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */ \
+	struct structname ## _data *data;  /**< Pointer to device data */ \
+}
+
+#define RTE_PKT_DEV_DATA_HDR struct { \
+	char name[RTE_PKT_NAME_MAX_LEN]; /**< Unique identifier name */ \
+\
+	void **rx_queues; /**< Array of pointers to RX queues. */ \
+	void **tx_queues; /**< Array of pointers to TX queues. */ \
+	uint16_t nb_rx_queues; /**< Number of RX queues. */ \
+	uint16_t nb_tx_queues; /**< Number of TX queues. */ \
+}
+
+struct rte_pkt_dev {
+	RTE_PKT_DEV_HDR(rte_pkt_dev);
+};
+
+struct rte_pkt_dev_data {
+	RTE_PKT_DEV_DATA_HDR;
+};
+
+/**
+ *
+ * Retrieve a burst of input packets from a receive queue of a
+ * device. The retrieved packets are stored in *rte_mbuf* structures whose
+ * pointers are supplied in the *rx_pkts* array.
+ *
+ * @param dev
+ *   The device to be polled for packets
+ * @param queue_id
+ *   The index of the receive queue from which to retrieve input packets.
+ * @param rx_pkts
+ *   The address of an array of pointers to *rte_mbuf* structures that
+ *   must be large enough to store *nb_pkts* pointers in it.
+ * @param nb_pkts
+ *   The maximum number of packets to retrieve.
+ * @return
+ *   The number of packets actually retrieved, which is the number
+ *   of pointers to *rte_mbuf* structures effectively supplied to the
+ *   *rx_pkts* array.
+ */
+static inline uint16_t
+rte_pkt_rx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
+			rx_pkts, nb_pkts);
+}
+
+/**
+ * Send a burst of output packets on a transmit queue of a device.
+ *
+ * @param dev
+ *   The device to be given the packets.
+ * @param queue_id
+ *   The index of the queue through which output packets must be sent.
+ * @param tx_pkts
+ *   The address of an array of *nb_pkts* pointers to *rte_mbuf* structures
+ *   which contain the output packets.
+ * @param nb_pkts
+ *   The maximum number of packets to transmit.
+ * @return

lib/librte_pktdev/rte_pktdev.h line 137

Quoted 10 lines
lib/librte_pktdev/rte_pktdev.h new file +10 -0
+ *   The number of output packets actually stored in transmit descriptors of
+ *   the transmit ring. The return value can be less than the value of the
+ *   *tx_pkts* parameter when the transmit ring is full or has been filled up.
+ */
+static inline uint16_t
+rte_pkt_tx_burst(struct rte_pkt_dev *dev, uint16_t queue_id,
+		 struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
+{
+	return (*dev->tx_pkt_burst)(dev->data->tx_queues[queue_id], tx_pkts, nb_pkts);
+}

That one looks much more lightweight, then Keith one :)
I have a question here:
Why are you guys so confident, that all foreseeable devices would fit into current eth_dev rx_burst/tx_burst API?

Quoted 10 lines

As I understand, QAT devices have HW request/response ring pairs, so the idea probably is to make tx_burst() populate an request ring and rx_burst() to read from response ring, right?
Though right now rte_mbuf contains a lot of flags and data fields that are specific for ethdev, and probably have no sense for crypto dev. From other side, for QAT devices, I suppose you'll need crypto specific flags and data:
encrypt/decrypt, source and destination buffer addresses, some cipher specific data, etc.
Wonder do you plan to fit all that into current rte_mbuf structure, or do you plan to have some superset structure, that would consist of rte_mbuf plus some extra stuff, or ... ?
Konstantin

Quoted 7 lines

From my point of view, the purpose of a pktdev API to to define a common API for devices that read/write (i.e. RX/TX) mbufs. If other devices don't fit that model, then they don't use it. However, we already have a number of different device types that already read/write mbufs, and there are likely more in future, so it would be nice to have a common API that can be used across those types so the data path can be source-neutral when processing mbufs. So far, we have three proposals on how that might be achieved. :-)

Quoted 7 lines

Ok, probably I misunderstood previous RFCs about pktdev.
So pktdev is not going to be a generic abstraction for any foreseeable device types: eth, crypto, compress, dpi, etc? It would represent only subset of dev types: real eth devices, plus SW emulated ones
that can mimic rx_burst/tx_burst, but don't support any other eth specific ops (kni, pmd_ring)? Basically what we support right now?
And for future device types to support (crypto, etc) there would be something else?

Not necessarily. I would expect future device types to also use this model - but I wouldn't want to be prescriptive, if it really doesn't make sense. I was really hoping to get multiple-benefit from a pktdev abstraction:
* commonality of interface across existing pkt-handling types
* framework for any new types to actually use.

Quoted 14 lines
Quoted 9 lines

As for the crypto, there is still a lot of investigation work to be done here, and Keith is probably better placed than me to comment on it. But if you look at any application using DPDK for packet processing, the mbuf is still going to be at the heart of it, so whatever the actual crypto API is like, it's going to have to have to fit into an "mbuf world" anyway.
If the crypto-dev APIs don't work
with mbufs, then it's pushing work onto the app (or higher level libs) to extract the meaningful fields from the mbuf to pass to the dev.

As I understand application (or some upper layer lib) would have to do that work anyway:
RX packet, find and read related to this packet crypto data, and pass all that info to the crypto dev, right? I can hardly imagine, that in reality you always would be able to do:

Quoted 6 lines

n = rx_burst(eth_dev, pkts, n);
n = tx_burst(crypto_dev, pkts, n);

without any processing of incoming packets in between.
The difference is only how that information will be passed into crypto device:
Would you need to to update an mbuf, or fill some other structure.

Possibly not. However, I would hope we may be able to get to something like:

n = rx_burst(eth_dev, pkts, n);
for (i = 0; i < n; i++)

	 bufs[i]->crypto_context = lookup_sa(bufs[i]);

n = tx_burst(crypto_dev, pkts, n);

Quoted 5 lines
Quoted 4 lines

Therefore, in a DPDK
library, I would think it better to have the dev work with mbufs directly, as the rest of DPDK does.

Quoted 8 lines

I wouldn't say that all DPDK libs accepts data as mbufs only.
Only those where it makes sense: PMDs, ip_frag/reassembly, pipeline fw.
Let say rte_hash and rte_acl accept input data in a neutral way.
You wouldn't expect rte_hash_lookup() or rte_acl_classify() to accept pointer(s) to the mbuf.
if you'll have a SW implemented encrypt()/decrypt() routines, you probably wouldn't require an mbuf as input parameter either. Wouldn't it be more plausible to create a new struct rte_crypto_buf (or something) to pass information to/from crypto devices. Then we can provide for it an ability to attach/detach to rte_mbuf(s) buf_addr(s).
That way we can probably make crypto_buf to attach to 2 mbufs at once (source and destination).

Maybe what you suggest is the way to go. However, on the hash side, I actually think it would be very useful to have our hash library have APIs to work directly off mbufs. For a single lookup pulling out a key is ok, but when working off a full burst of traffic, doing optimized code to extract keys from packets to pass as an array into a hash is awkward for the app, and also prevents full code pipelining in the lookup. [Ideally, you want your key extraction to be running in parallel with lookups of previously extracted keys. Something a bit similar to what is done for lookups in lib/librte_table/rte_table_hash_key16.c]

/Bruce

#39 lore raw
In reply to a message not in the archive
Quoted 7 lines · Keith Wiles

Hi All,

Here is a set of RFC patches to update DPDK to support a generic set of devices. The patches that follow create two files eal_common_device.h and rte_common_device.c and then a few items in rte_ethdev.[ch] were moved to cleanup those files by moving the device generic values and functions into a common set of device generic files.

(Old thread. But in the context of some private pktdev discussions, I was asked to give some feedback on this specific version)

Quoted 8 lines

In the rte_common_device.h file are a couple of macros to abstract a few common items from rte_ethdev.h which are not ethernet specific. These generic device specific structure members are place into macros to be placed at the top of each new device type crypto, hardware offload, dpi, compression and possible others to be defined later. In version 2 I used nested structures a bit cleaner from the macro design, but modified a lot more files.

I don't see easy and that really pays off to have a common rte_dev_data structure. So far the common data, as far as I can see, is name and _maybe_ MTU. The queues and number of queues is something difficult to abstract (e.g. KNI or rte_ring, 1 TX and 1 RX queue?), although it can be done.

Quoted 10 lines

Most of the changes are to update the code to locate the new location of the members in the nested structures. To not try and rewrite code I used macros to help hide the changes, but these constructs are now used in a lot of files withint DPDK.

I did not pull the Rx/Tx Routines into a common function, but it could be done if everyone agrees. It does not mean every device will use a common Rx/Tx routine. Without pulling Rx/Tx routines into a common file allows the device writer to have similar or different set of routines.

Actually, to me this is the part that makes more sense to abstract, because all the DPDK applications that have to deal with RX/TX over heterogeneous devices have to construct the same de-multiplexing logic (create an abstraction of a generic port on top of rte libraries) that we could provide.

I think this patch set addresses more of a fundamental re-organization of data structures to maximize reusage than this "higher level" abstraction. I am commenting some stuff inline, to the point that I could.

Quoted 12 lines

These patches do not contain any new devices as these are being work on today. I could have included the DPI (dpidev) routines we did in the PoC, but the DPI is not open source.

More cleanup of ethdev could be done to remove NIC specific features not supported in all devices and someone needs to do that cleanup IMO.

The code is untested and I wanted to get something our for others to poke at today and more could be pulled out of ethdev as well. I/We will be looking at testing the code as we get more completed.

Quoted 7 lines

I have not finished up the crypto APIs yet, but I am planning to work on those additions today. The crypto code we are using is the Quick Assist code found on 01.org, but we need to update the code to be move DPDK friendly.

The QAT code does have a modified like API similar to Linux Kernel crypto API and I want to review that code first.

Seeing the balance of additions/deletions doesn't look like much of a gain in terms of number of lines too.

Marc

Quoted 66 lines

Regards,
++Keith

Keith Wiles (4):
Adding the common device files for multiple device support Add the ethdev changes for multiple device support Add the test file changes for common device support Update PMD files for new common device support

  app/test-pmd/config.c                             |   6 +-
  app/test-pmd/testpmd.h                            |   4 +-
  app/test/test_kni.c                               |  12 +-
  app/test/test_link_bonding.c                      |  24 +-
  app/test/virtual_pmd.c                            | 106 +--
  examples/link_status_interrupt/main.c             |   6 +-
  lib/librte_eal/bsdapp/eal/Makefile                |   1 +
  lib/librte_eal/common/Makefile                    |   1 +
  lib/librte_eal/common/eal_common_device.c         | 185 +++++
  lib/librte_eal/common/include/rte_common_device.h | 674 +++++++++++++++
  lib/librte_eal/common/include/rte_log.h           |   1 +
  lib/librte_eal/linuxapp/eal/Makefile              |   1 +
  lib/librte_ether/rte_ethdev.c                     | 944 +++++++++-------------
  lib/librte_ether/rte_ethdev.h                     | 340 ++------
  lib/librte_kni/rte_kni.c                          |   4 +-
  lib/librte_pmd_af_packet/rte_eth_af_packet.c      |  38 +-
  lib/librte_pmd_bond/rte_eth_bond_8023ad.c         |  18 +-
  lib/librte_pmd_bond/rte_eth_bond_alb.c            |  10 +-
  lib/librte_pmd_bond/rte_eth_bond_api.c            | 142 ++--
  lib/librte_pmd_bond/rte_eth_bond_args.c           |   2 +-
  lib/librte_pmd_bond/rte_eth_bond_pmd.c            | 164 ++--
  lib/librte_pmd_bond/rte_eth_bond_private.h        |   2 +-
  lib/librte_pmd_e1000/em_ethdev.c                  | 156 ++--
  lib/librte_pmd_e1000/em_rxtx.c                    |  94 +--
  lib/librte_pmd_e1000/igb_ethdev.c                 | 302 +++----
  lib/librte_pmd_e1000/igb_pf.c                     |  86 +-
  lib/librte_pmd_e1000/igb_rxtx.c                   | 168 ++--
  lib/librte_pmd_enic/enic.h                        |   4 +-
  lib/librte_pmd_enic/enic_ethdev.c                 | 140 ++--
  lib/librte_pmd_enic/enic_main.c                   |  30 +-
  lib/librte_pmd_fm10k/fm10k_ethdev.c               | 154 ++--
  lib/librte_pmd_fm10k/fm10k_rxtx.c                 |   4 +-
  lib/librte_pmd_i40e/i40e_ethdev.c                 | 172 ++--
  lib/librte_pmd_i40e/i40e_ethdev_vf.c              | 194 ++---
  lib/librte_pmd_i40e/i40e_fdir.c                   |  28 +-
  lib/librte_pmd_i40e/i40e_pf.c                     |   8 +-
  lib/librte_pmd_i40e/i40e_rxtx.c                   |  88 +-
  lib/librte_pmd_ixgbe/ixgbe_ethdev.c               | 392 ++++-----
  lib/librte_pmd_ixgbe/ixgbe_fdir.c                 |  50 +-
  lib/librte_pmd_ixgbe/ixgbe_pf.c                   | 114 ++-
  lib/librte_pmd_ixgbe/ixgbe_rxtx.c                 | 276 +++----
  lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c             |   6 +-
  lib/librte_pmd_mlx4/mlx4.c                        |   2 +-
  lib/librte_pmd_null/rte_eth_null.c                |  36 +-
  lib/librte_pmd_pcap/rte_eth_pcap.c                |   2 +-
  lib/librte_pmd_ring/rte_eth_ring.c                |  36 +-
  lib/librte_pmd_virtio/virtio_ethdev.c             | 120 +--
  lib/librte_pmd_virtio/virtio_rxtx.c               |  20 +-
  lib/librte_pmd_vmxnet3/vmxnet3_ethdev.c           |  64 +-
  lib/librte_pmd_vmxnet3/vmxnet3_rxtx.c             |  40 +-
  lib/librte_pmd_xenvirt/rte_eth_xenvirt.c          |   2 +-
  51 files changed, 2990 insertions(+), 2483 deletions(-)

create mode 100644 lib/librte_eal/common/eal_common_device.c create mode 100644 lib/librte_eal/common/include/rte_common_device.h

#4 lore raw

Re: [RFC PATCH 1/4 v2] Adding the common device files for multiple device support

In reply to a message not in the archive
Quoted 426 lines · Keith Wiles

Add the eal_common_device.c and rte_common_device.h and include the build support changes.

---
  lib/librte_eal/bsdapp/eal/Makefile                |   1 +
  lib/librte_eal/common/Makefile                    |   1 +
  lib/librte_eal/common/eal_common_device.c         | 185 ++++++
  lib/librte_eal/common/include/rte_common_device.h | 674 ++++++++++++++++++++++
  lib/librte_eal/common/include/rte_log.h           |   1 +
  lib/librte_eal/linuxapp/eal/Makefile              |   1 +
  lib/librte_kni/rte_kni.c                          |   4 +-
  7 files changed, 865 insertions(+), 2 deletions(-)

create mode 100644 lib/librte_eal/common/eal_common_device.c create mode 100644 lib/librte_eal/common/include/rte_common_device.h

lib/librte_eal/bsdapp/eal/Makefile +1 -0
index 2357cfa..7bb2689 100644
@@ -78,6 +78,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_devargs.c
  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c
  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c
  SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_device.c
 
  CFLAGS_eal.o := -D_GNU_SOURCE
  #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/common/Makefile +1 -0
index 3ea3bbf..c4bf805 100644
@@ -40,6 +40,7 @@ INC += rte_string_fns.h rte_version.h
  INC += rte_eal_memconfig.h rte_malloc_heap.h
  INC += rte_hexdump.h rte_devargs.h rte_dev.h
  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
+INC += rte_common_device.h
 
  ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y)
  INC += rte_warnings.h
lib/librte_eal/common/eal_common_device.c new file +185 -0
new file mode 100644
index 0000000..a9ef925
@@ -0,0 +1,185 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2014 6WIND S.A.
+ *   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 <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 <rte_malloc.h>
+#include <rte_errno.h>
+
+#include "rte_common_device.h"
+
+void *
+rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
+		void * fn, void *user_param)
+{
+	struct rte_dev_rxtx_callback *cb;
+
+	cb = rte_zmalloc(NULL, sizeof(*cb), 0);
+
+	if (cb == NULL) {
+		rte_errno = ENOMEM;
+		return NULL;
+	}
+
+	cb->fn.vp = fn;
+	cb->param = user_param;
+	cb->next = *cbp;
+	*cbp = cb;
+	return cb;
+}
+
+int
+rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
+		struct rte_dev_rxtx_callback *user_cb)
+{
+	struct rte_dev_rxtx_callback *cb = *cbp;
+	struct rte_dev_rxtx_callback *prev_cb;
+
+	/* Reset head pointer and remove user cb if first in the list. */
+	if (cb == user_cb) {
+		*cbp = user_cb->next;
+		return 0;
+	}
+
+	/* Remove the user cb from the callback list. */
+	do {
+		prev_cb = cb;
+		cb = cb->next;
+
+		if (cb == user_cb) {
+			prev_cb->next = user_cb->next;
+			return 0;
+		}
+	} while (cb != NULL);
+
+	/* Callback wasn't found. */
+	return (-EINVAL);
+}
+
+int
+rte_dev_callback_register(struct rte_dev_cb_list * cb_list,
+		rte_spinlock_t * lock,
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg)
+{
+	struct rte_dev_callback *cb;
+
+	rte_spinlock_lock(lock);
+
+	TAILQ_FOREACH(cb, cb_list, next) {
+		if (cb->cb_fn == cb_fn &&
+			cb->cb_arg == cb_arg &&
+			cb->event == event) {
+			break;
+		}
+	}
+
+	/* create a new callback. */
+	if (cb == NULL && (cb = rte_zmalloc("INTR_USER_CALLBACK",
+			sizeof(struct rte_dev_callback), 0)) != NULL) {
+		cb->cb_fn = cb_fn;
+		cb->cb_arg = cb_arg;
+		cb->event = event;
+		TAILQ_INSERT_TAIL(cb_list, cb, next);
+	}
+
+	rte_spinlock_unlock(lock);
+	return ((cb == NULL) ? -ENOMEM : 0);
+}
+
+int
+rte_dev_callback_unregister(struct rte_dev_cb_list * cb_list,
+		rte_spinlock_t * lock,
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg)
+{
+	int ret;
+	struct rte_dev_callback *cb, *next;
+
+	rte_spinlock_lock(lock);
+
+	ret = 0;
+	for (cb = TAILQ_FIRST(cb_list); cb != NULL; cb = next) {
+
+		next = TAILQ_NEXT(cb, next);
+
+		if (cb->cb_fn != cb_fn || cb->event != event ||
+				(cb->cb_arg != (void *)-1 &&
+				cb->cb_arg != cb_arg))
+			continue;
+
+		/*
+		 * if this callback is not executing right now,
+		 * then remove it.
+		 */
+		if (cb->active == 0) {
+			TAILQ_REMOVE(cb_list, cb, next);
+			rte_free(cb);
+		} else {
+			ret = -EAGAIN;
+		}
+	}
+
+	rte_spinlock_unlock(lock);
+	return (ret);
+}
+
+void
+rte_dev_callback_process(struct rte_dev_cb_list * cb_list, uint8_t port_id,
+	enum rte_dev_event_type event, rte_spinlock_t *lock)
+{
+	struct rte_dev_callback *cb;
+	struct rte_dev_callback dev_cb;
+
+	rte_spinlock_lock(lock);
+	TAILQ_FOREACH(cb, cb_list, next) {
+		if (cb->cb_fn == NULL || cb->event != event)
+			continue;
+		dev_cb = *cb;
+		cb->active = 1;
+		rte_spinlock_unlock(lock);
+		dev_cb.cb_fn(port_id, dev_cb.event, dev_cb.cb_arg);
+		rte_spinlock_lock(lock);
+		cb->active = 0;
+	}
+	rte_spinlock_unlock(lock);
+}
lib/librte_eal/common/include/rte_common_device.h new file +189 -0
new file mode 100644
index 0000000..de48ad7
@@ -0,0 +1,674 @@
+/*-
+ *   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, WHPDF 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_COMMON_DEVICE_H_
+#define _RTE_COMMON_DEVICE_H_
+
+/**
+ * @file
+ *
+ * Common Device Helpers in RTE
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <rte_spinlock.h>
+
+/* Macros for checking for restricting functions to primary instance only */
+#define PROC_PRIMARY_OR_ERR_RET(retval) do { \
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
+		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
+		return (retval); \
+	} \
+} while(0)
+#define PROC_PRIMARY_OR_RET() do { \
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
+		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
+		return; \
+	} \
+} while(0)
+
+#ifndef NULL
+#define NULL	(void *)0
+#endif
+
+/* Macros to check for invalid function pointers in dev_ops structure */
+#define FUNC_PTR_OR_ERR_RET(func, retval) do { \
+	if ((func) == NULL) { \
+		PMD_DEBUG_TRACE("Function not supported\n"); \
+		return (retval); \
+	} \
+} while(0)
+#define FUNC_PTR_OR_RET(func) do { \
+	if ((func) == NULL) { \
+		PMD_DEBUG_TRACE("Function not supported\n"); \
+		return; \
+	} \
+} while(0)
+
+enum {
+	DEV_DETACHED = 0,
+	DEV_ATTACHED
+};
+
+/*
+ * The device type
+ */
+enum rte_dev_type {
+	RTE_DEV_UNKNOWN,	/**< unknown device type */
+	RTE_DEV_PCI,
+		/**< Physical function and Virtual function of PCI devices */
+	RTE_DEV_VIRTUAL,	/**< non hardware device */
+	RTE_DEV_MAX			/**< max value of this enum */
+};
+
+/**
+ * The device event type for interrupt, and maybe others in the future.
+ */
+enum rte_dev_event_type {
+	RTE_DEV_EVENT_UNKNOWN,  /**< unknown event type */
+	RTE_DEV_EVENT_INTR_LSC, /**< lsc interrupt event */
+	RTE_DEV_EVENT_MAX       /**< max value of this enum */
+};
+
+struct rte_dev_callback;
+
+/** @internal Structure to keep track of registered callback */
+TAILQ_HEAD(rte_dev_cb_list, rte_dev_callback);
+
+struct rte_mbuf;
+
+typedef uint16_t (*dev_rx_burst_t)(void *rxq,
+				   struct rte_mbuf **rx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Retrieve input packets from a receive queue of a device. */
+
+typedef uint16_t (*dev_tx_burst_t)(void *txq,
+				   struct rte_mbuf **tx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Send output packets on a transmit queue of a device. */
+
+typedef void (*rte_dev_cb_fn)(uint8_t port_id, \
+		enum rte_dev_event_type event, void *cb_arg);
+/**< user application callback to be registered for interrupts */
+
+#define RTE_DEV_NAME_MAX_LEN (32)
+
+struct rte_dev;
+/**
+ * @internal
+ * Initialization function of an Ethernet driver invoked for each matching
+ * Ethernet PCI device detected during the PCI probing phase.
+ *
+ * @param dev
+ *   The *dev* pointer is the address of the *rte_xyz_dev* structure
+ *   associated with the matching device and which have been [automatically]
+ *   allocated in the *rte_eth_devices* array.
+ *   The *eth_dev* structure is supplied to the driver initialization function
+ *   with the following fields already initialized:
+ *
+ *   - *pci_dev*: Holds the pointers to the *rte_pci_device* structure which
+ *     contains the generic PCI information of the matching device.
+ *
+ *   - *driver*: Holds the pointer to the *eth_driver* structure.
+ *
+ *   - *dev_private*: Holds a pointer to the device private data structure.
+ *
+ *   - *mtu*: Contains the default Ethernet maximum frame length (1500).
+ *
+ *   - *port_id*: Contains the port index of the device (actually the index
+ *     of the *eth_dev* structure in the *rte_eth_devices* array).
+ *
+ * @return
+ *   - 0: Success, the device is properly initialized by the driver.
+ *        In particular, the driver MUST have set up the *dev_ops* pointer
+ *        of the *dev* structure.
+ *   - <0: Error code of the device initialization failure.
+ */
+typedef int (*dev_init_t)(struct rte_dev *dev);
+
+/**
+ * @internal
+ * Finalization function of an Ethernet driver invoked for each matching
+ * Ethernet PCI device detected during the PCI closing phase.
+ *
+ * @param dev
+ *   The *dev* pointer is the address of the *rte_eth_dev* structure
+ *   associated with the matching device and which have been [automatically]
+ *   allocated in the *rte_eth_devices* array.
+ * @return
+ *   - 0: Success, the device is properly finalized by the driver.
+ *        In particular, the driver MUST free the *dev_ops* pointer
+ *        of the *eth_dev* structure.
+ *   - <0: Error code of the device initialization failure.
+ */
+typedef int (*dev_uninit_t)(struct rte_dev *dev);
+
+/**
+ * @internal
+ * The data part, with no function pointers, associated with each device.
+ *
+ * This structure is safe to place in shared memory to be common among different
+ * processes in a multi-process configuration.
+ */
+struct rte_dev_data {

lib/librte_eal/common/include/rte_common_device.h line 199

Quoted 10 lines
lib/librte_eal/common/include/rte_common_device.h new file +10 -0
+    char name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */
+
+    void	**rx_queues;            /**< Array of pointers to RX queues. */
+    void	**tx_queues;            /**< Array of pointers to TX queues. */
+
+    uint16_t nb_rx_queues;          /**< Number of RX queues. */
+    uint16_t nb_tx_queues;          /**< Number of TX queues. */
+
+    uint16_t mtu;                   /**< Maximum Transmission Unit. */
+    uint8_t  unit_id;               /**< Unit/Port ID for this instance */

Besides port_id, what is the other usage of unit_id so that it has to be in the common place?

lib/librte_eal/common/include/rte_common_device.h line 204

Quoted 5 lines
lib/librte_eal/common/include/rte_common_device.h new file +5 -0
+    uint8_t  _pad0;             	/* alignment filler */
+
+    void	*dev_private;           /**< PMD-specific private data */
+    uint64_t rx_mbuf_alloc_failed;  /**< RX ring mbuf allocation failures. */
+    uint32_t min_rx_buf_size;       /**< Common rx buffer size handled by all queues */

The same way; is this really common for all the abstracted devices?

lib/librte_eal/common/include/rte_common_device.h line 214

Quoted 10 lines
lib/librte_eal/common/include/rte_common_device.h new file +10 -0
+};
+
+/**
+ * @internal
+ * Cast the rte_xyz_dev_data pointer into rte_dev_data to retrieve the value.
+ */
+#define _DD(dev, m)			((struct rte_dev_data *)(dev)->data)->m
+#define _DD_PRIVATE(dev)	_DD(dev, dev_private)
+#define _DD_PORT(dev)		_DD(dev, unit_id)
+#define _DD_UNIT(dev)		_DD(dev, unit_id)

I don't like the approach of using these MACROs, because it makes the code less readable. Also because _DD name is pretty generic (although afterwards I realised it is the acronym of Device Data).

Does it really provide that much of a benefit?

Quoted 56 lines
lib/librte_eal/common/include/rte_common_device.h new file +56 -0
+
+/**
+ * @internal
+ * Common set of members for all devices'
+ */
+struct rte_dev_global {
+    struct rte_dev 		*devs;	/**< Device information array */
+    struct rte_dev_data *data;	/**< Device private data */
+    uint8_t     nb_ports;       /**< Number of ports/units found */
+    uint8_t     max_ports;      /**< Max number of ports or units */
+    uint16_t    dflt_mtu;       /**< Default MTU if needed by device */
+    uint16_t    dev_size;       /**< Internal size of device struct */
+    uint16_t    data_size;      /**< Internal size of data structure */
+    const char  *mz_dev_data;    /**< String constant for device data */
+	void		*gbl_private;	/**< Global private data for device to use */
+};
+
+/**
+ * @internal
+ * The structure associated with a PMD Ethernet driver.
+ *
+ * Each Ethernet driver acts as a PCI driver and is represented by a generic
+ * *eth_driver* structure that holds:
+ *
+ * - An *rte_pci_driver* structure (which must be the first field).
+ *
+ * - The *eth_dev_init* function invoked for each matching PCI device.
+ *
+ * - The *eth_dev_uninit* function invoked for each matching PCI device.
+ *
+ * - The size of the private data to allocate for each matching device.
+ */
+struct rte_dev_drv {
+	struct rte_pci_driver pci_drv;  /**< The PMD is also a PCI driver. */
+	dev_init_t dev_init;      		/**< Device init function. */
+	dev_uninit_t dev_uninit;  		/**< Device uninit function. */
+	unsigned int dev_private_size;  /**< Size of device private data. */
+};
+
+/**
+ * @internal
+ * Common set of members for all devices included at the top of 'struct rte_xyz_dev_info'
+ */
+struct rte_dev_info {
+    struct rte_pci_device   *pci_dev;   /**< Device PCI information. */
+    const char      *driver_name;   	/**< Device Driver name. */
+    unsigned int    if_index;       	/**< Index to bound host interface, or 0 if none. */
+        /* Use if_indextoname() to translate into an interface name. */
+    unsigned int	_pad0;
+};
+
+/**
+ * @internal
+ * The generic data structure associated with each device.
+ *
+ * Pointers to burst-oriented packet receive and transmit functions are

lib/librte_eal/common/include/rte_common_device.h line 280

Quoted 10 lines
lib/librte_eal/common/include/rte_common_device.h new file +10 -0
+ * located at the beginning of the structure, along with the pointer to
+ * where all the data elements for the particular device are stored in shared
+ * memory. This split allows the function pointer and driver data to be per-
+ * process, while the actual configuration data for the device is shared.
+ */
+struct rte_dev {
+    dev_rx_burst_t          rx_pkt_burst;   /**< Pointer to PMD receive function. */
+    dev_tx_burst_t          tx_pkt_burst;   /**< Pointer to PMD transmit function. */
+    void				  	*data;      	/**< Pointer to device data */
+    struct rte_dev_global	*gbl_data;      /**< Pointer to device global data */

Why is this gbl_data really necessary?

I think I am missing something fundamental here...

lib/librte_eal/common/include/rte_common_device.h line 283

Quoted 3 lines
lib/librte_eal/common/include/rte_common_device.h new file +3 -0
+    const struct rte_dev_drv *driver;       /**< Driver for this device */
+    void					*dev_ops;       /**< Functions exported by PMD */
+    struct rte_pci_device   *pci_dev;       /**< PCI info. supplied by probing */

Why not in (private) data?

lib/librte_eal/common/include/rte_common_device.h line 284

Quoted 1 line
lib/librte_eal/common/include/rte_common_device.h new file +1 -0
+    struct rte_dev_info		*dev_info;		/**< Pointer to the device info structure */

Idem.

Quoted 8 lines
lib/librte_eal/common/include/rte_common_device.h new file +8 -0
+
+    /** User application callback for interrupts if present */
+    struct rte_dev_cb_list  link_intr_cbs;
+    /**
+     * User-supplied functions called from rx_burst to post-process
+     * received packets before passing them to the user
+     */
+    struct rte_dev_rxtx_callback **post_rx_burst_cbs;

lib/librte_eal/common/include/rte_common_device.h line 302

Quoted 10 lines
lib/librte_eal/common/include/rte_common_device.h new file +10 -0
+    /**
+     * User-supplied functions called from tx_burst to pre-process
+     * received packets before passing them to the driver for transmission.
+     */
+    struct rte_dev_rxtx_callback **pre_tx_burst_cbs;
+    enum rte_dev_type		dev_type;       /**< Flag indicating the device type */
+    uint8_t                 attached;        /**< Flag indicating the port is attached */
+};
+
+#define port_id		unit_id

This is very dangerous and will mess user's code; why is it necessary?

marc

Quoted 411 lines
lib/librte_eal/common/include/rte_common_device.h new file +372 -0
+
+/**
+ * Get the rte_pkt_dev structure device pointer for the device.
+ *
+ * @param   gbl     pointer to device specific global structure.
+ * @param   port_id Port ID value to select the device structure.
+ *
+ * @return
+ *   - The rte_pkt_dev structure pointer for the given port ID.
+ */
+static inline void *
+rte_get_dev(void * _gbl, uint8_t port_id)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+
+    return (void *)((uint8_t *)gbl->devs + (port_id * gbl->dev_size));
+}
+
+/**
+ * Get the number of device ports in the system.
+ *
+ * @param gbl
+ *  The pointer to the current global data structure for xyzdev.
+ *
+ * @return
+ *   - Number of ports found in the system.
+ */
+static inline uint8_t
+rte_pkt_dev_count(void * _gbl)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    return gbl->nb_ports;
+}
+
+/**
+ * Validate if the port number is valid
+ *
+ * @param   gbl The pointer to the current global data structure for xyzdev.
+ * @param   port_id Port ID value to select the device.
+ *
+ * @return
+ *   - Number of ports found in the system.
+ */
+static inline int
+rte_dev_is_valid_port(void * _gbl, uint8_t port_id)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev * dev;
+
+    if (port_id >= gbl->nb_ports)
+        return 0;
+
+    dev = rte_get_dev(gbl, port_id);
+    if (dev->attached != DEV_ATTACHED)
+        return 0;
+    else
+        return 1;
+}
+
+/**
+ * Get the number of device ports in the system.
+ *
+ * @param gbl
+ *  The pointer to the current global data structure for xyzdev.
+ *
+ * @return
+ *   - Number of ports found in the system.
+ */
+static inline uint8_t
+rte_dev_count(void * _gbl)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    return gbl->nb_ports;
+}
+
+/**
+ * Get the rte_pkt_dev structure device pointer for the device by name.
+ *
+ * @param   gbl     pointer to device specific global structure.
+ * @param   name    Name of device.
+ *
+ * @return
+ *   - The rte_dev structure pointer for the given name.
+ */
+static inline struct rte_dev *
+rte_get_named_dev(void * _gbl, const char *name)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev *dev;
+    int i;
+
+    if (name == NULL)
+        return NULL;
+
+    for (i = 0; i < gbl->nb_ports; i++) {
+        dev = (struct rte_dev *)((uint8_t *)gbl->devs +
+                (i * gbl->dev_size));
+
+        if (strcmp(_DD(dev, name), name) == 0)
+            return dev;
+    }
+
+    return NULL;
+}
+
+/**
+ * Get the rte_pkt_dev structure device pointer for the PCI name.
+ *
+ * @param   gbl     pointer to device specific global structure.
+ * @param   name    Name of PCI device.
+ *
+ * @return
+ *   - The rte_dev structure pointer for the given PCIname.
+ */
+static inline struct rte_dev *
+rte_get_pci_named_dev(void * _gbl, struct rte_pci_addr *pci_addr)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev *dev;
+    int i;
+
+    if (pci_addr == NULL)
+        return NULL;
+
+    for (i = 0; i < gbl->nb_ports; i++) {
+        dev = (struct rte_dev *)((uint8_t *)gbl->devs +
+                (i * gbl->dev_size));
+
+        if (rte_eal_compare_pci_addr(&dev->pci_dev->addr, pci_addr) == 0)
+            return dev;
+    }
+
+    return NULL;
+}
+
+/*
+ * Return the NUMA socket to which a device is connected
+ *
+ * @param gbl
+ *   The global structure pointer for a given xyzdev.
+ * @param port_id
+ *   The port 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 is returned is the port_id value is out of range.
+ */
+static inline int
+rte_dev_socket_id(void * _gbl, uint8_t port_id)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev * dev;
+
+    if (!rte_dev_is_valid_port(gbl, port_id))
+        return -1;
+
+    dev = rte_get_dev(gbl, port_id);
+
+    if ( dev->pci_dev )
+        return dev->pci_dev->numa_node;
+    else
+        return 0;
+}
+/**
+ * Function type used for RX packet processing packet a callback.
+ *
+ * The callback function is called on RX with a burst of packets that have
+ * been received on the given port and queue.
+ *
+ * @param port
+ *   The Ethernet port on which RX is being performed.
+ * @param queue
+ *   The queue on the Ethernet port which is being used to receive the packets.
+ * @param pkts
+ *   The burst of packets that have just been received.
+ * @param nb_pkts
+ *   The number of packets in the burst pointed to by "pkts".
+ * @param max_pkts
+ *   The max number of packets that can be stored in the "pkts" array.
+ * @param user_param
+ *   The arbitrary user parameter passed in by the application when the callback
+ *   was originally configured.
+ * @return
+ *   The number of packets returned to the user.
+ */
+typedef uint16_t (*rte_rx_callback_fn)(uint8_t port, uint16_t queue,
+	struct rte_mbuf *pkts[], uint16_t nb_pkts, uint16_t max_pkts,
+	void *user_param);
+
+/**
+ * Function type used for TX packet processing packet a callback.
+ *
+ * The callback function is called on TX with a burst of packets immediately
+ * before the packets are put onto the hardware queue for transmission.
+ *
+ * @param port
+ *   The Ethernet port on which TX is being performed.
+ * @param queue
+ *   The queue on the Ethernet port which is being used to transmit the packets.
+ * @param pkts
+ *   The burst of packets that are about to be transmitted.
+ * @param nb_pkts
+ *   The number of packets in the burst pointed to by "pkts".
+ * @param user_param
+ *   The arbitrary user parameter passed in by the application when the callback
+ *   was originally configured.
+ * @return
+ *   The number of packets to be written to the NIC.
+ */
+typedef uint16_t (*rte_tx_callback_fn)(uint8_t port, uint16_t queue,
+	struct rte_mbuf *pkts[], uint16_t nb_pkts, void *user_param);
+
+/**
+ * @internal
+ * Union used to hold the callback function pointers for RX and TX callback.
+ */
+union rte_dev_callback_fn {
+	void * vp;						/**< Allow for a generic function pointer to avoid casting in common routines */
+	rte_rx_callback_fn rx;			/**< Ethernet or packet based callback function for RX packets */
+	rte_tx_callback_fn tx;			/**< Ethernet or packet based callback function for TX packets */
+	/**< Add other device callback prototypes here */
+};
+
+/**
+ * @internal
+ * Structure used to hold information about a callback to be called for a
+ * queue on RX and TX.
+ */
+struct rte_dev_rxtx_callback {
+	struct rte_dev_rxtx_callback *next;
+	union rte_dev_callback_fn fn;
+	void *param;
+};
+
+/**
+ * The user application callback description.
+ *
+ * It contains callback address to be registered by user application,
+ * the pointer to the parameters for callback, and the event type.
+ */
+struct rte_dev_callback {
+	TAILQ_ENTRY(rte_dev_callback) next;		/**< Callback list */
+	rte_dev_cb_fn cb_fn;                	/**< Callback address */
+	void *cb_arg;                           /**< Parameter for callback */
+	enum rte_dev_event_type event;          /**< Interrupt event type */
+	uint32_t active;                        /**< Callback is executing */
+};
+
+/**
+ * Register a callback function for specific port id.
+ *
+ * @param cbp
+ *  Pointer to the ret_dev_cb_list structure.
+ * @param lock
+ *  Pointer to the rte_spinlock_t structure.
+ * @param event
+ *  Event interested.
+ * @param cb_fn
+ *  User supplied callback function to be called.
+ * @param cb_arg
+ *  Pointer to the parameters for the registered callback.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+int rte_dev_callback_register(struct rte_dev_cb_list * cbp, rte_spinlock_t * lock,
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg);
+
+/**
+ * Unregister a callback function for specific port id.
+ *
+ * @param cb_list
+ *  Pointer to the ret_dev_cb_list structure.
+ * @param lock
+ *  Pointer to the rte_spinlock_t structure.
+ * @param event
+ *  Event interested.
+ * @param cb_fn
+ *  User supplied callback function to be called.
+ * @param cb_arg
+ *  Pointer to the parameters for the registered callback. -1 means to
+ *  remove all for the same callback address and same event.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+int rte_dev_callback_unregister(struct rte_dev_cb_list * cb_list, rte_spinlock_t * lock,
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg);
+
+/**
+ * @internal Executes all the user application registered callbacks for
+ * the specific device. It is for DPDK internal user only. User
+ * application should not call it directly.
+ *
+ * @param cb_list
+ *  Pointer to struct rte_dev_cb_list.
+ * @param port_id
+ *  Port_id or unit_id value.
+ * @param event
+ *  Eth device interrupt event type.
+ * @param lock
+ *  Pointer to the lock structure.
+ *
+ * @return
+ *  void
+ */
+void rte_dev_callback_process(struct rte_dev_cb_list * cb_list, uint8_t port_id,
+	enum rte_dev_event_type event, rte_spinlock_t *lock);
+
+/**
+ * Add a callback to be called on packet RX or TX on a given port and queue.
+ *
+ * This API configures a function to be called for each burst of
+ * packets received on a given NIC port queue. The return value is a pointer
+ * that can be used to later remove the callback using
+ * rte_dev_remove_callback().
+ *
+ * @param cbp
+ *  Pointer to a pointer of the ret_dev_cb_list structure.
+ * @param fn
+ *   The callback function
+ * @param user_param
+ *   A generic pointer parameter which will be passed to each invocation of the
+ *   callback function on this port and queue.
+ *
+ * @return
+ *   NULL on error.
+ *   On success, a pointer value which can later be used to remove the callback.
+ */
+void *rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
+		void * fn, void *user_param);
+
+/**
+ * Remove an RX or TX packet callback from a given port and queue.
+ *
+ * This function is used to removed a callback that were added to a NIC port
+ * queue using rte_dev_add_callback().
+ *
+ * Note: the callback is removed from the callback list but it isn't freed
+ * since the it may still be in use. The memory for the callback can be
+ * subsequently freed back by the application by calling rte_free():
+ *
+ *  - Immediately - if the port is stopped, or the user knows that no
+ *    callback's are in flight e.g. if called from the thread doing RX/TX
+ *    on that queue.
+ *
+ * - After a short delay - where the delay is sufficient to allow any
+ *   in-flight callback's to complete.
+ *
+ * @param cbp
+ *   Pointer to a pointer to use as the head of the list.
+ * @param user_cb
+ *   User supplied callback created via rte_dev_add_callback().
+ *
+ * @return
+ *   - 0: Success. Callback was removed.
+ *   - -ENOTSUP: Callback support is not available.
+ *   - -EINVAL:  The port_id or the queue_id is out of range, or the callback
+ *               is NULL or not found for the port/queue.
+ */
+int rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
+		struct rte_dev_rxtx_callback *user_cb);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_COMMON_DEVICE_H_ */
lib/librte_eal/common/include/rte_log.h +1 -0
index f83a0d9..543deb7 100644
@@ -77,6 +77,7 @@ extern struct rte_logs rte_logs;
  #define RTE_LOGTYPE_PORT    0x00002000 /**< Log related to port. */
  #define RTE_LOGTYPE_TABLE   0x00004000 /**< Log related to table. */
  #define RTE_LOGTYPE_PIPELINE 0x00008000 /**< Log related to pipeline. */
+#define RTE_LOGTYPE_DEV     0x00010000 /**< Log related to device. */
 
  /* these log types can be used in an application */
  #define RTE_LOGTYPE_USER1   0x01000000 /**< User-defined log type 1. */
lib/librte_eal/linuxapp/eal/Makefile +1 -0
index 01f7b70..935720a 100644
@@ -90,6 +90,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_devargs.c
  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c
  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c
  SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_device.c
 
  CFLAGS_eal.o := -D_GNU_SOURCE
  CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
lib/librte_kni/rte_kni.c +2 -2
index 4e70fa0..87ee7a3 100644
@@ -320,8 +320,8 @@ rte_kni_create(uint8_t port_id,
  	rte_eth_dev_info_get(port_id, &info);
 
  	snprintf(conf.name, sizeof(conf.name), "vEth%u", port_id);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+	conf.addr = info.di.pci_dev->addr;
+	conf.id = info.di.pci_dev->id;
  	conf.group_id = (uint16_t)port_id;
  	conf.mbuf_size = mbuf_size;
 
#6 lore raw

Re: [RFC PATCH 1/4 v2] Adding the common device files for multiple device support

In reply to a message not in the archive

Hi Marc

Quoted 482 lines · Marc Sune
Quoted 479 lines · Keith Wiles

Add the eal_common_device.c and rte_common_device.h and include the build support changes.

---
  lib/librte_eal/bsdapp/eal/Makefile                |   1 +
  lib/librte_eal/common/Makefile                    |   1 +
  lib/librte_eal/common/eal_common_device.c         | 185 ++++++
  lib/librte_eal/common/include/rte_common_device.h | 674
++++++++++++++++++++++
  lib/librte_eal/common/include/rte_log.h           |   1 +
  lib/librte_eal/linuxapp/eal/Makefile              |   1 +
  lib/librte_kni/rte_kni.c                          |   4 +-
  7 files changed, 865 insertions(+), 2 deletions(-)

create mode 100644 lib/librte_eal/common/eal_common_device.c create mode 100644 lib/librte_eal/common/include/rte_common_device.h

lib/librte_eal/bsdapp/eal/Makefile +0 -0
index 2357cfa..7bb2689 100644
@@ -78,6 +78,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) +=

eal_common_devargs.c
SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_options.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_thread.c

lib/librte_eal/bsdapp/eal/Makefile +1 -0
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_device.c
 
  CFLAGS_eal.o := -D_GNU_SOURCE
  #CFLAGS_eal_thread.o := -D_GNU_SOURCE
lib/librte_eal/common/Makefile +1 -0
index 3ea3bbf..c4bf805 100644
@@ -40,6 +40,7 @@ INC += rte_string_fns.h rte_version.h
  INC += rte_eal_memconfig.h rte_malloc_heap.h
  INC += rte_hexdump.h rte_devargs.h rte_dev.h
  INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
+INC += rte_common_device.h
 
  ifeq ($(CONFIG_RTE_INSECURE_FUNCTION_WARNING),y)
  INC += rte_warnings.h
lib/librte_eal/common/eal_common_device.c new file +14 -0
new file mode 100644
index 0000000..a9ef925
@@ -0,0 +1,185 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2014 6WIND S.A.
+ *   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.
+ */

lib/librte_eal/common/eal_common_device.c new file +134 -0
+
+#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 <rte_malloc.h>
+#include <rte_errno.h>
+
+#include "rte_common_device.h"
+
+void *
+rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
+		void * fn, void *user_param)
+{
+	struct rte_dev_rxtx_callback *cb;
+
+	cb = rte_zmalloc(NULL, sizeof(*cb), 0);
+
+	if (cb == NULL) {
+		rte_errno = ENOMEM;
+		return NULL;
+	}
+
+	cb->fn.vp = fn;
+	cb->param = user_param;
+	cb->next = *cbp;
+	*cbp = cb;
+	return cb;
+}
+
+int
+rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
+		struct rte_dev_rxtx_callback *user_cb)
+{
+	struct rte_dev_rxtx_callback *cb = *cbp;
+	struct rte_dev_rxtx_callback *prev_cb;
+
+	/* Reset head pointer and remove user cb if first in the list. */
+	if (cb == user_cb) {
+		*cbp = user_cb->next;
+		return 0;
+	}
+
+	/* Remove the user cb from the callback list. */
+	do {
+		prev_cb = cb;
+		cb = cb->next;
+
+		if (cb == user_cb) {
+			prev_cb->next = user_cb->next;
+			return 0;
+		}
+	} while (cb != NULL);
+
+	/* Callback wasn't found. */
+	return (-EINVAL);
+}
+
+int
+rte_dev_callback_register(struct rte_dev_cb_list * cb_list,
+		rte_spinlock_t * lock,
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg)
+{
+	struct rte_dev_callback *cb;
+
+	rte_spinlock_lock(lock);
+
+	TAILQ_FOREACH(cb, cb_list, next) {
+		if (cb->cb_fn == cb_fn &&
+			cb->cb_arg == cb_arg &&
+			cb->event == event) {
+			break;
+		}
+	}
+
+	/* create a new callback. */
+	if (cb == NULL && (cb = rte_zmalloc("INTR_USER_CALLBACK",
+			sizeof(struct rte_dev_callback), 0)) != NULL) {
+		cb->cb_fn = cb_fn;
+		cb->cb_arg = cb_arg;
+		cb->event = event;
+		TAILQ_INSERT_TAIL(cb_list, cb, next);
+	}
+
+	rte_spinlock_unlock(lock);
+	return ((cb == NULL) ? -ENOMEM : 0);
+}
+
+int
+rte_dev_callback_unregister(struct rte_dev_cb_list * cb_list,
+		rte_spinlock_t * lock,
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg)
+{
+	int ret;
+	struct rte_dev_callback *cb, *next;
+
+	rte_spinlock_lock(lock);
+
+	ret = 0;
+	for (cb = TAILQ_FIRST(cb_list); cb != NULL; cb = next) {
+
+		next = TAILQ_NEXT(cb, next);
+
+		if (cb->cb_fn != cb_fn || cb->event != event ||
+				(cb->cb_arg != (void *)-1 &&
+				cb->cb_arg != cb_arg))
+			continue;
+
+		/*
+		 * if this callback is not executing right now,
+		 * then remove it.
+		 */
+		if (cb->active == 0) {
+			TAILQ_REMOVE(cb_list, cb, next);
+			rte_free(cb);
+		} else {
+			ret = -EAGAIN;
+		}
+	}
+
+	rte_spinlock_unlock(lock);
+	return (ret);
+}
+
+void
+rte_dev_callback_process(struct rte_dev_cb_list * cb_list, uint8_t

port_id,

lib/librte_eal/common/eal_common_device.c new file +18 -0
+	enum rte_dev_event_type event, rte_spinlock_t *lock)
+{
+	struct rte_dev_callback *cb;
+	struct rte_dev_callback dev_cb;
+
+	rte_spinlock_lock(lock);
+	TAILQ_FOREACH(cb, cb_list, next) {
+		if (cb->cb_fn == NULL || cb->event != event)
+			continue;
+		dev_cb = *cb;
+		cb->active = 1;
+		rte_spinlock_unlock(lock);
+		dev_cb.cb_fn(port_id, dev_cb.event, dev_cb.cb_arg);
+		rte_spinlock_lock(lock);
+		cb->active = 0;
+	}
+	rte_spinlock_unlock(lock);
+}
lib/librte_eal/common/include/rte_common_device.h new file +13 -0
new file mode 100644
index 0000000..de48ad7
@@ -0,0 +1,674 @@
+/*-
+ *   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, WHPDF 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.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +20 -0
+
+#ifndef _RTE_COMMON_DEVICE_H_
+#define _RTE_COMMON_DEVICE_H_
+
+/**
+ * @file
+ *
+ * Common Device Helpers in RTE
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <rte_spinlock.h>
+
+/* Macros for checking for restricting functions to primary instance

only */

lib/librte_eal/common/include/rte_common_device.h new file +18 -0
+#define PROC_PRIMARY_OR_ERR_RET(retval) do { \
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
+		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
+		return (retval); \
+	} \
+} while(0)
+#define PROC_PRIMARY_OR_RET() do { \
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY) { \
+		PMD_DEBUG_TRACE("Cannot run in secondary processes\n"); \
+		return; \
+	} \
+} while(0)
+
+#ifndef NULL
+#define NULL	(void *)0
+#endif
+
+/* Macros to check for invalid function pointers in dev_ops structure

*/

lib/librte_eal/common/include/rte_common_device.h new file +49 -0
+#define FUNC_PTR_OR_ERR_RET(func, retval) do { \
+	if ((func) == NULL) { \
+		PMD_DEBUG_TRACE("Function not supported\n"); \
+		return (retval); \
+	} \
+} while(0)
+#define FUNC_PTR_OR_RET(func) do { \
+	if ((func) == NULL) { \
+		PMD_DEBUG_TRACE("Function not supported\n"); \
+		return; \
+	} \
+} while(0)
+
+enum {
+	DEV_DETACHED = 0,
+	DEV_ATTACHED
+};
+
+/*
+ * The device type
+ */
+enum rte_dev_type {
+	RTE_DEV_UNKNOWN,	/**< unknown device type */
+	RTE_DEV_PCI,
+		/**< Physical function and Virtual function of PCI devices */
+	RTE_DEV_VIRTUAL,	/**< non hardware device */
+	RTE_DEV_MAX			/**< max value of this enum */
+};
+
+/**
+ * The device event type for interrupt, and maybe others in the future.
+ */
+enum rte_dev_event_type {
+	RTE_DEV_EVENT_UNKNOWN,  /**< unknown event type */
+	RTE_DEV_EVENT_INTR_LSC, /**< lsc interrupt event */
+	RTE_DEV_EVENT_MAX       /**< max value of this enum */
+};
+
+struct rte_dev_callback;
+
+/** @internal Structure to keep track of registered callback */
+TAILQ_HEAD(rte_dev_cb_list, rte_dev_callback);
+
+struct rte_mbuf;
+
+typedef uint16_t (*dev_rx_burst_t)(void *rxq,
+				   struct rte_mbuf **rx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Retrieve input packets from a receive queue of a

device. */

lib/librte_eal/common/include/rte_common_device.h new file +16 -0
+
+typedef uint16_t (*dev_tx_burst_t)(void *txq,
+				   struct rte_mbuf **tx_pkts,
+				   uint16_t nb_pkts);
+/**< @internal Send output packets on a transmit queue of a device. */
+
+typedef void (*rte_dev_cb_fn)(uint8_t port_id, \
+		enum rte_dev_event_type event, void *cb_arg);
+/**< user application callback to be registered for interrupts */
+
+#define RTE_DEV_NAME_MAX_LEN (32)
+
+struct rte_dev;
+/**
+ * @internal
+ * Initialization function of an Ethernet driver invoked for each

matching
+ * Ethernet PCI device detected during the PCI probing phase.
+ *
+ * @param dev
+ * The *dev* pointer is the address of the *rte_xyz_dev* structure
+ * associated with the matching device and which have been
[automatically]
+ * allocated in the *rte_eth_devices* array.
+ * The *eth_dev* structure is supplied to the driver initialization
function
+ * with the following fields already initialized:
+ *
+ * - *pci_dev*: Holds the pointers to the *rte_pci_device* structure
which
+ * contains the generic PCI information of the matching device.
+ *
+ * - *driver*: Holds the pointer to the *eth_driver* structure.
+ *
+ * - *dev_private*: Holds a pointer to the device private data
structure.
+ *
+ * - *mtu*: Contains the default Ethernet maximum frame length
(1500).
+ *
+ * - *port_id*: Contains the port index of the device (actually the
index
+ * of the *eth_dev* structure in the *rte_eth_devices* array).
+ *
+ * @return
+ * - 0: Success, the device is properly initialized by the driver.
+ * In particular, the driver MUST have set up the *dev_ops*
pointer
+ * of the *dev* structure.
+ * - <0: Error code of the device initialization failure.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +5 -0
+typedef int (*dev_init_t)(struct rte_dev *dev);
+
+/**
+ * @internal
+ * Finalization function of an Ethernet driver invoked for each

matching
+ * Ethernet PCI device detected during the PCI closing phase.
+ *
+ * @param dev
+ * The *dev* pointer is the address of the *rte_eth_dev* structure
+ * associated with the matching device and which have been
[automatically]
+ * allocated in the *rte_eth_devices* array.
+ * @return
+ * - 0: Success, the device is properly finalized by the driver.
+ * In particular, the driver MUST free the *dev_ops* pointer
+ * of the *eth_dev* structure.
+ * - <0: Error code of the device initialization failure.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +5 -0
+typedef int (*dev_uninit_t)(struct rte_dev *dev);
+
+/**
+ * @internal
+ * The data part, with no function pointers, associated with each

device.
+ *
+ * This structure is safe to place in shared memory to be common among different
+ * processes in a multi-process configuration.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +4 -0
+struct rte_dev_data {
+    char name[RTE_DEV_NAME_MAX_LEN]; /**< Unique identifier name */
+
+    void	**rx_queues;            /**< Array of pointers to RX queues.

*/
+ void **tx_queues; /**< Array of pointers to TX queues.
*/

lib/librte_eal/common/include/rte_common_device.h new file +2 -0
+
+    uint16_t nb_rx_queues;          /**< Number of RX queues. */
Quoted 8 lines
Quoted 5 lines
lib/librte_eal/common/include/rte_common_device.h new file +4 -0
+    uint16_t nb_tx_queues;          /**< Number of TX queues. */
+
+    uint16_t mtu;                   /**< Maximum Transmission Unit. */
+    uint8_t  unit_id;               /**< Unit/Port ID for this

instance */

Besides port_id, what is the other usage of unit_id so that it has to be in the common place?

The unit_id seemed more generic to me then port_id as not all devices will have a port, but could have more then one unit with in the device.

Quoted 27 lines
Quoted 8 lines
lib/librte_eal/common/include/rte_common_device.h new file +4 -0
+    uint8_t  _pad0;             	/* alignment filler */
+
+    void	*dev_private;           /**< PMD-specific private data */
+    uint64_t rx_mbuf_alloc_failed;  /**< RX ring mbuf allocation

failures. */
+ uint32_t min_rx_buf_size; /**< Common rx buffer size handled
by all queues */

The same way; is this really common for all the abstracted devices?

lib/librte_eal/common/include/rte_common_device.h line 214

Quoted 11 lines
lib/librte_eal/common/include/rte_common_device.h new file +5 -0
+};
+
+/**
+ * @internal
+ * Cast the rte_xyz_dev_data pointer into rte_dev_data to retrieve the

value.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +4 -0
+#define _DD(dev, m)			((struct rte_dev_data *)(dev)->data)->m
+#define _DD_PRIVATE(dev)	_DD(dev, dev_private)
+#define _DD_PORT(dev)		_DD(dev, unit_id)
+#define _DD_UNIT(dev)		_DD(dev, unit_id)

I don't like the approach of using these MACROs, because it makes the code less readable. Also because _DD name is pretty generic (although afterwards I realised it is the acronym of Device Data).

Quoted 1 line

Does it really provide that much of a benefit?

The Device Data macro helped hide some of the messy stuff and help convert the code quicker then editing ever instance. We use macros all of the time in DPDK and this one is no exception IMO.

Quoted 81 lines
Quoted 77 lines
lib/librte_eal/common/include/rte_common_device.h new file +14 -0
+
+/**
+ * @internal
+ * Common set of members for all devices'
+ */
+struct rte_dev_global {
+    struct rte_dev 		*devs;	/**< Device information array */
+    struct rte_dev_data *data;	/**< Device private data */
+    uint8_t     nb_ports;       /**< Number of ports/units found */
+    uint8_t     max_ports;      /**< Max number of ports or units */
+    uint16_t    dflt_mtu;       /**< Default MTU if needed by device */
+    uint16_t    dev_size;       /**< Internal size of device struct */
+    uint16_t    data_size;      /**< Internal size of data structure */
+    const char  *mz_dev_data;    /**< String constant for device data

*/

lib/librte_eal/common/include/rte_common_device.h new file +8 -0
+	void		*gbl_private;	/**< Global private data for device to use */
+};
+
+/**
+ * @internal
+ * The structure associated with a PMD Ethernet driver.
+ *
+ * Each Ethernet driver acts as a PCI driver and is represented by a

generic
+ * *eth_driver* structure that holds:
+ *
+ * - An *rte_pci_driver* structure (which must be the first field).
+ *
+ * - The *eth_dev_init* function invoked for each matching PCI device.
+ *
+ * - The *eth_dev_uninit* function invoked for each matching PCI device.
+ *
+ * - The size of the private data to allocate for each matching device.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +10 -0
+struct rte_dev_drv {
+	struct rte_pci_driver pci_drv;  /**< The PMD is also a PCI driver. */
+	dev_init_t dev_init;      		/**< Device init function. */
+	dev_uninit_t dev_uninit;  		/**< Device uninit function. */
+	unsigned int dev_private_size;  /**< Size of device private data. */
+};
+
+/**
+ * @internal
+ * Common set of members for all devices included at the top of

'struct rte_xyz_dev_info'
+ */

lib/librte_eal/common/include/rte_common_device.h new file +4 -0
+struct rte_dev_info {
+    struct rte_pci_device   *pci_dev;   /**< Device PCI information. */
+    const char      *driver_name;   	/**< Device Driver name. */
+    unsigned int    if_index;       	/**< Index to bound host

interface, or 0 if none. */

lib/librte_eal/common/include/rte_common_device.h new file +11 -0
+        /* Use if_indextoname() to translate into an interface name. */
+    unsigned int	_pad0;
+};
+
+/**
+ * @internal
+ * The generic data structure associated with each device.
+ *
+ * Pointers to burst-oriented packet receive and transmit functions are
+ * located at the beginning of the structure, along with the pointer to
+ * where all the data elements for the particular device are stored in

shared
+ * memory. This split allows the function pointer and driver data to be per-
+ * process, while the actual configuration data for the device is shared.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +2 -0
+struct rte_dev {
+    dev_rx_burst_t          rx_pkt_burst;   /**< Pointer to PMD

receive function. */
+ dev_tx_burst_t tx_pkt_burst; /**< Pointer to PMD
transmit function. */

lib/librte_eal/common/include/rte_common_device.h new file +2 -0
+    void				  	*data;      	/**< Pointer to device data */
+    struct rte_dev_global	*gbl_data;      /**< Pointer to device
Quoted 1 line

global data */

Why is this gbl_data really necessary?

Quoted 1 line

I think I am missing something fundamental here...

As we add more and more devices you will start to see the global variables in the device will grow, so I decided to move all of the globals into a device specific structure to hide the device data. This is nothing new, just some data hiding.

Quoted 27 lines
Quoted 6 lines

+ const struct rte_dev_drv *driver; /**< Driver for this
device */

lib/librte_eal/common/include/rte_common_device.h new file +2 -0
+    void					*dev_ops;       /**< Functions exported by PMD */
+    struct rte_pci_device   *pci_dev;       /**< PCI info. supplied by

probing */

Why not in (private) data?

Quoted 2 lines

+ struct rte_dev_info *dev_info; /**< Pointer to the device info
structure */

Idem.

Quoted 15 lines
lib/librte_eal/common/include/rte_common_device.h new file +11 -0
+
+    /** User application callback for interrupts if present */
+    struct rte_dev_cb_list  link_intr_cbs;
+    /**
+     * User-supplied functions called from rx_burst to post-process
+     * received packets before passing them to the user
+     */
+    struct rte_dev_rxtx_callback **post_rx_burst_cbs;
+    /**
+     * User-supplied functions called from tx_burst to pre-process
+     * received packets before passing them to the driver for

transmission.

lib/librte_eal/common/include/rte_common_device.h new file +3 -0
+     */
+    struct rte_dev_rxtx_callback **pre_tx_burst_cbs;
+    enum rte_dev_type		dev_type;       /**< Flag indicating the device
Quoted 8 lines

lib/librte_eal/common/include/rte_common_device.h line 302

Quoted 6 lines

type */
+ uint8_t attached; /**< Flag indicating the
port is attached */

lib/librte_eal/common/include/rte_common_device.h new file +3 -0
+};
+
+#define port_id		unit_id

This is very dangerous and will mess user's code; why is it necessary?

We can remove it and replace every instance with unit_id, but as for dangerous it is not. We do these types of things all of the time. Making everyone device use port when they are not a port device seemed messy to me.

++Keith

Quoted 444 lines

marc

Quoted 440 lines
lib/librte_eal/common/include/rte_common_device.h new file +38 -0
+
+/**
+ * Get the rte_pkt_dev structure device pointer for the device.
+ *
+ * @param   gbl     pointer to device specific global structure.
+ * @param   port_id Port ID value to select the device structure.
+ *
+ * @return
+ *   - The rte_pkt_dev structure pointer for the given port ID.
+ */
+static inline void *
+rte_get_dev(void * _gbl, uint8_t port_id)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+
+    return (void *)((uint8_t *)gbl->devs + (port_id * gbl->dev_size));
+}
+
+/**
+ * Get the number of device ports in the system.
+ *
+ * @param gbl
+ *  The pointer to the current global data structure for xyzdev.
+ *
+ * @return
+ *   - Number of ports found in the system.
+ */
+static inline uint8_t
+rte_pkt_dev_count(void * _gbl)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    return gbl->nb_ports;
+}
+
+/**
+ * Validate if the port number is valid
+ *
+ * @param   gbl The pointer to the current global data structure for

xyzdev.
+ * @param port_id Port ID value to select the device.
+ *
+ * @return
+ * - Number of ports found in the system.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +86 -0
+static inline int
+rte_dev_is_valid_port(void * _gbl, uint8_t port_id)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev * dev;
+
+    if (port_id >= gbl->nb_ports)
+        return 0;
+
+    dev = rte_get_dev(gbl, port_id);
+    if (dev->attached != DEV_ATTACHED)
+        return 0;
+    else
+        return 1;
+}
+
+/**
+ * Get the number of device ports in the system.
+ *
+ * @param gbl
+ *  The pointer to the current global data structure for xyzdev.
+ *
+ * @return
+ *   - Number of ports found in the system.
+ */
+static inline uint8_t
+rte_dev_count(void * _gbl)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    return gbl->nb_ports;
+}
+
+/**
+ * Get the rte_pkt_dev structure device pointer for the device by name.
+ *
+ * @param   gbl     pointer to device specific global structure.
+ * @param   name    Name of device.
+ *
+ * @return
+ *   - The rte_dev structure pointer for the given name.
+ */
+static inline struct rte_dev *
+rte_get_named_dev(void * _gbl, const char *name)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev *dev;
+    int i;
+
+    if (name == NULL)
+        return NULL;
+
+    for (i = 0; i < gbl->nb_ports; i++) {
+        dev = (struct rte_dev *)((uint8_t *)gbl->devs +
+                (i * gbl->dev_size));
+
+        if (strcmp(_DD(dev, name), name) == 0)
+            return dev;
+    }
+
+    return NULL;
+}
+
+/**
+ * Get the rte_pkt_dev structure device pointer for the PCI name.
+ *
+ * @param   gbl     pointer to device specific global structure.
+ * @param   name    Name of PCI device.
+ *
+ * @return
+ *   - The rte_dev structure pointer for the given PCIname.
+ */
+static inline struct rte_dev *
+rte_get_pci_named_dev(void * _gbl, struct rte_pci_addr *pci_addr)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev *dev;
+    int i;
+
+    if (pci_addr == NULL)
+        return NULL;
+
+    for (i = 0; i < gbl->nb_ports; i++) {
+        dev = (struct rte_dev *)((uint8_t *)gbl->devs +
+                (i * gbl->dev_size));
+
+        if (rte_eal_compare_pci_addr(&dev->pci_dev->addr, pci_addr) ==

0)

lib/librte_eal/common/include/rte_common_device.h new file +38 -0
+            return dev;
+    }
+
+    return NULL;
+}
+
+/*
+ * Return the NUMA socket to which a device is connected
+ *
+ * @param gbl
+ *   The global structure pointer for a given xyzdev.
+ * @param port_id
+ *   The port 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 is returned is the port_id value is out of range.
+ */
+static inline int
+rte_dev_socket_id(void * _gbl, uint8_t port_id)
+{
+    struct rte_dev_global * gbl = (struct rte_dev_global *)_gbl;
+    struct rte_dev * dev;
+
+    if (!rte_dev_is_valid_port(gbl, port_id))
+        return -1;
+
+    dev = rte_get_dev(gbl, port_id);
+
+    if ( dev->pci_dev )
+        return dev->pci_dev->numa_node;
+    else
+        return 0;
+}
+/**
+ * Function type used for RX packet processing packet a callback.
+ *
+ * The callback function is called on RX with a burst of packets that

have
+ * been received on the given port and queue.
+ *
+ * @param port
+ * The Ethernet port on which RX is being performed.
+ * @param queue
+ * The queue on the Ethernet port which is being used to receive the
packets.
+ * @param pkts
+ * The burst of packets that have just been received.
+ * @param nb_pkts
+ * The number of packets in the burst pointed to by "pkts".
+ * @param max_pkts
+ * The max number of packets that can be stored in the "pkts" array.
+ * @param user_param
+ * The arbitrary user parameter passed in by the application when
the callback
+ * was originally configured.
+ * @return
+ * The number of packets returned to the user.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +8 -0
+typedef uint16_t (*rte_rx_callback_fn)(uint8_t port, uint16_t queue,
+	struct rte_mbuf *pkts[], uint16_t nb_pkts, uint16_t max_pkts,
+	void *user_param);
+
+/**
+ * Function type used for TX packet processing packet a callback.
+ *
+ * The callback function is called on TX with a burst of packets

immediately
+ * before the packets are put onto the hardware queue for transmission.
+ *
+ * @param port
+ * The Ethernet port on which TX is being performed.
+ * @param queue
+ * The queue on the Ethernet port which is being used to transmit
the packets.
+ * @param pkts
+ * The burst of packets that are about to be transmitted.
+ * @param nb_pkts
+ * The number of packets in the burst pointed to by "pkts".
+ * @param user_param
+ * The arbitrary user parameter passed in by the application when
the callback
+ * was originally configured.
+ * @return
+ * The number of packets to be written to the NIC.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +6 -0
+typedef uint16_t (*rte_tx_callback_fn)(uint8_t port, uint16_t queue,
+	struct rte_mbuf *pkts[], uint16_t nb_pkts, void *user_param);
+
+/**
+ * @internal
+ * Union used to hold the callback function pointers for RX and TX

callback.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +2 -0
+union rte_dev_callback_fn {
+	void * vp;						/**< Allow for a generic function pointer to avoid

casting in common routines */

lib/librte_eal/common/include/rte_common_device.h new file +1 -0
+	rte_rx_callback_fn rx;			/**< Ethernet or packet based callback

function for RX packets */

lib/librte_eal/common/include/rte_common_device.h new file +1 -0
+	rte_tx_callback_fn tx;			/**< Ethernet or packet based callback

function for TX packets */

lib/librte_eal/common/include/rte_common_device.h new file +6 -0
+	/**< Add other device callback prototypes here */
+};
+
+/**
+ * @internal
+ * Structure used to hold information about a callback to be called

for a
+ * queue on RX and TX.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +39 -0
+struct rte_dev_rxtx_callback {
+	struct rte_dev_rxtx_callback *next;
+	union rte_dev_callback_fn fn;
+	void *param;
+};
+
+/**
+ * The user application callback description.
+ *
+ * It contains callback address to be registered by user application,
+ * the pointer to the parameters for callback, and the event type.
+ */
+struct rte_dev_callback {
+	TAILQ_ENTRY(rte_dev_callback) next;		/**< Callback list */
+	rte_dev_cb_fn cb_fn;                	/**< Callback address */
+	void *cb_arg;                           /**< Parameter for callback */
+	enum rte_dev_event_type event;          /**< Interrupt event type */
+	uint32_t active;                        /**< Callback is executing */
+};
+
+/**
+ * Register a callback function for specific port id.
+ *
+ * @param cbp
+ *  Pointer to the ret_dev_cb_list structure.
+ * @param lock
+ *  Pointer to the rte_spinlock_t structure.
+ * @param event
+ *  Event interested.
+ * @param cb_fn
+ *  User supplied callback function to be called.
+ * @param cb_arg
+ *  Pointer to the parameters for the registered callback.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+int rte_dev_callback_register(struct rte_dev_cb_list * cbp,

rte_spinlock_t * lock,

lib/librte_eal/common/include/rte_common_device.h new file +23 -0
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg);
+
+/**
+ * Unregister a callback function for specific port id.
+ *
+ * @param cb_list
+ *  Pointer to the ret_dev_cb_list structure.
+ * @param lock
+ *  Pointer to the rte_spinlock_t structure.
+ * @param event
+ *  Event interested.
+ * @param cb_fn
+ *  User supplied callback function to be called.
+ * @param cb_arg
+ *  Pointer to the parameters for the registered callback. -1 means to
+ *  remove all for the same callback address and same event.
+ *
+ * @return
+ *  - On success, zero.
+ *  - On failure, a negative value.
+ */
+int rte_dev_callback_unregister(struct rte_dev_cb_list * cb_list,

rte_spinlock_t * lock,

lib/librte_eal/common/include/rte_common_device.h new file +21 -0
+		enum rte_dev_event_type event,
+		rte_dev_cb_fn cb_fn, void *cb_arg);
+
+/**
+ * @internal Executes all the user application registered callbacks for
+ * the specific device. It is for DPDK internal user only. User
+ * application should not call it directly.
+ *
+ * @param cb_list
+ *  Pointer to struct rte_dev_cb_list.
+ * @param port_id
+ *  Port_id or unit_id value.
+ * @param event
+ *  Eth device interrupt event type.
+ * @param lock
+ *  Pointer to the lock structure.
+ *
+ * @return
+ *  void
+ */
+void rte_dev_callback_process(struct rte_dev_cb_list * cb_list,

uint8_t port_id,

lib/librte_eal/common/include/rte_common_device.h new file +4 -0
+	enum rte_dev_event_type event, rte_spinlock_t *lock);
+
+/**
+ * Add a callback to be called on packet RX or TX on a given port and

queue.
+ *
+ * This API configures a function to be called for each burst of
+ * packets received on a given NIC port queue. The return value is a pointer
+ * that can be used to later remove the callback using
+ * rte_dev_remove_callback().
+ *
+ * @param cbp
+ * Pointer to a pointer of the ret_dev_cb_list structure.
+ * @param fn
+ * The callback function
+ * @param user_param
+ * A generic pointer parameter which will be passed to each
invocation of the
+ * callback function on this port and queue.
+ *
+ * @return
+ * NULL on error.
+ * On success, a pointer value which can later be used to remove the
callback.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +7 -0
+void *rte_dev_add_callback(struct rte_dev_rxtx_callback ** cbp,
+		void * fn, void *user_param);
+
+/**
+ * Remove an RX or TX packet callback from a given port and queue.
+ *
+ * This function is used to removed a callback that were added to a 

NIC port
+ * queue using rte_dev_add_callback().
+ *
+ * Note: the callback is removed from the callback list but it isn't freed
+ * since the it may still be in use. The memory for the callback can be
+ * subsequently freed back by the application by calling rte_free():
+ *
+ * - Immediately - if the port is stopped, or the user knows that no
+ * callback's are in flight e.g. if called from the thread doing
RX/TX
+ * on that queue.
+ *
+ * - After a short delay - where the delay is sufficient to allow any
+ * in-flight callback's to complete.
+ *
+ * @param cbp
+ * Pointer to a pointer to use as the head of the list.
+ * @param user_cb
+ * User supplied callback created via rte_dev_add_callback().
+ *
+ * @return

+ *   - 0: Success. Callback was removed.
+ *   - -ENOTSUP: Callback support is not available.
+ *   - -EINVAL:  The port_id or the queue_id is out of range, or the 

callback
+ * is NULL or not found for the port/queue.
+ */

lib/librte_eal/common/include/rte_common_device.h new file +8 -0
+int rte_dev_remove_callback(struct rte_dev_rxtx_callback ** cbp,
+		struct rte_dev_rxtx_callback *user_cb);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_COMMON_DEVICE_H_ */
lib/librte_eal/common/include/rte_log.h +1 -0
index f83a0d9..543deb7 100644
@@ -77,6 +77,7 @@ extern struct rte_logs rte_logs;
  #define RTE_LOGTYPE_PORT    0x00002000 /**< Log related to port. */
  #define RTE_LOGTYPE_TABLE   0x00004000 /**< Log related to table. */
  #define RTE_LOGTYPE_PIPELINE 0x00008000 /**< Log related to pipeline. 
 */
+#define RTE_LOGTYPE_DEV     0x00010000 /**< Log related to device. */
 
  /* these log types can be used in an application */

#define RTE_LOGTYPE_USER1 0x01000000 /**< User-defined log type 1.
*/

lib/librte_eal/linuxapp/eal/Makefile +0 -0
index 01f7b70..935720a 100644
@@ -90,6 +90,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += 

eal_common_devargs.c
SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_options.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_thread.c

lib/librte_eal/linuxapp/eal/Makefile +1 -0
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_device.c
 
  CFLAGS_eal.o := -D_GNU_SOURCE
  CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
lib/librte_kni/rte_kni.c +2 -2
index 4e70fa0..87ee7a3 100644
@@ -320,8 +320,8 @@ rte_kni_create(uint8_t port_id,
  	rte_eth_dev_info_get(port_id, &info);
 
  	snprintf(conf.name, sizeof(conf.name), "vEth%u", port_id);
-	conf.addr = info.pci_dev->addr;
-	conf.id = info.pci_dev->id;
+	conf.addr = info.di.pci_dev->addr;
+	conf.id = info.di.pci_dev->id;
  	conf.group_id = (uint16_t)port_id;
  	conf.mbuf_size = mbuf_size;