From: Yi He <yi...@linaro.org>

Rename implementation specific data structure
and move its dedicated header file to impl local,
decouple it from pktio_entry_t data structure.

Signed-off-by: Yi He <yi...@linaro.org>
Signed-off-by: Balakrishna Garapati <balakrishna.garap...@linaro.org>
Reviewed-by: Brian Brooks <brian.bro...@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagaraha...@arm.com>
Reviewed-by: Bill Fischofer <bill.fischo...@linaro.org>
---
/** Email created from pull request 139 (heyi-linaro:modular-pktio-ops)
 ** https://github.com/Linaro/odp/pull/139
 ** Patch: https://github.com/Linaro/odp/pull/139.patch
 ** Base sha: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a
 ** Merge commit sha: 407fcfe1baad9b95b5374f13221abdf50b8d6089
 **/
 platform/linux-dpdk/Makefile.am                    |   4 +-
 .../linux-dpdk/include/odp_packet_io_internal.h    |  25 +---
 platform/linux-dpdk/odp_init.c                     |   2 +-
 .../linux-dpdk/{odp_packet_dpdk.c => pktio/dpdk.c} | 127 ++++++++++++++-------
 .../{include/odp_packet_dpdk.h => pktio/dpdk.h}    |  21 +++-
 platform/linux-dpdk/pool/dpdk.c                    |   2 +-
 platform/linux-generic/Makefile.am                 |   4 +-
 .../linux-generic/include/odp_packet_io_internal.h |   5 -
 .../include/odp_pktio_ops_subsystem.h              |   1 +
 .../pktio/{pktio_common.c => common.c}             |   0
 platform/linux-generic/pktio/dpdk.c                |  94 ++++++++++-----
 .../{include/odp_packet_dpdk.h => pktio/dpdk.h}    |   6 +-
 12 files changed, 182 insertions(+), 109 deletions(-)
 rename platform/linux-dpdk/{odp_packet_dpdk.c => pktio/dpdk.c} (86%)
 rename platform/linux-dpdk/{include/odp_packet_dpdk.h => pktio/dpdk.h} (59%)
 rename platform/linux-generic/pktio/{pktio_common.c => common.c} (100%)
 rename platform/linux-generic/{include/odp_packet_dpdk.h => pktio/dpdk.h} (96%)

diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am
index 9d32defd5..f0d731213 100644
--- a/platform/linux-dpdk/Makefile.am
+++ b/platform/linux-dpdk/Makefile.am
@@ -187,7 +187,7 @@ noinst_HEADERS = \
                  
${top_srcdir}/platform/linux-generic/include/odp_crypto_internal.h \
                  
${top_srcdir}/platform/linux-generic/include/odp_forward_typedefs_internal.h \
                  ${top_srcdir}/platform/linux-generic/include/odp_internal.h \
-                 ${srcdir}/include/odp_packet_dpdk.h \
+                 ${srcdir}/pktio/dpdk.h \
                  ${srcdir}/include/odp_packet_internal.h \
                  
${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_ipc.h \
                  
${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \
@@ -243,7 +243,7 @@ __LIB__libodp_dpdk_la_SOURCES = \
                           ../linux-generic/odp_ipsec.c \
                           ../linux-generic/odp_name_table.c \
                           odp_packet.c \
-                          odp_packet_dpdk.c \
+                          pktio/dpdk.c \
                           pktio/subsystem.c \
                           odp_packet_flags.c \
                           ../linux-generic/odp_packet_io.c \
diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h 
b/platform/linux-dpdk/include/odp_packet_io_internal.h
index ba388c9c2..ec1d0c213 100644
--- a/platform/linux-dpdk/include/odp_packet_io_internal.h
+++ b/platform/linux-dpdk/include/odp_packet_io_internal.h
@@ -29,7 +29,7 @@ extern "C" {
 
 #define PKTIO_MAX_QUEUES 64
 #include <linux/if_ether.h>
-#include <odp_packet_dpdk.h>
+#include <pktio/dpdk.h>
 
 /* Forward declaration */
 typedef union pktio_entry_u pktio_entry_t;
@@ -40,26 +40,6 @@ typedef union pktio_entry_u pktio_entry_t;
 #define PKTIN_INVALID  ((odp_pktin_queue_t) {ODP_PKTIO_INVALID, 0})
 #define PKTOUT_INVALID ((odp_pktout_queue_t) {ODP_PKTIO_INVALID, 0})
 
-/* Forward declaration */
-struct pkt_dpdk_t;
-
-/** Packet socket using dpdk mmaped rings for both Rx and Tx */
-typedef struct {
-       odp_pktio_capability_t  capa;     /**< interface capabilities */
-
-       /********************************/
-       char ifname[32];
-       uint8_t min_rx_burst;
-       uint8_t portid;
-       odp_bool_t vdev_sysc_promisc;   /**< promiscuous mode defined with
-                                           system call */
-       odp_pktin_hash_proto_t hash;      /**< Packet input hash protocol */
-       odp_bool_t lockless_rx;           /**< no locking for rx */
-       odp_bool_t lockless_tx;           /**< no locking for tx */
-       odp_ticketlock_t rx_lock[PKTIO_MAX_QUEUES];  /**< RX queue locks */
-       odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES];  /**< TX queue locks */
-} pkt_dpdk_t;
-
 struct pktio_entry {
        const pktio_ops_module_t *ops;  /**< Implementation specific methods */
        pktio_ops_data_t ops_data;
@@ -68,9 +48,6 @@ struct pktio_entry {
        odp_ticketlock_t txl;           /**< TX ticketlock */
        int cls_enabled;                /**< is classifier enabled */
        odp_pktio_t handle;             /**< pktio handle */
-       union {
-               pkt_dpdk_t pkt_dpdk;    /**< using DPDK API for IO */
-       };
        enum {
                /* Not allocated */
                PKTIO_STATE_FREE = 0,
diff --git a/platform/linux-dpdk/odp_init.c b/platform/linux-dpdk/odp_init.c
index cd7abce65..0a6eb4695 100644
--- a/platform/linux-dpdk/odp_init.c
+++ b/platform/linux-dpdk/odp_init.c
@@ -5,13 +5,13 @@
  */
 
 #include <odp_posix_extensions.h>
-#include <odp_packet_dpdk.h>
 #include <odp/api/init.h>
 #include <odp_debug_internal.h>
 #include <odp/api/debug.h>
 #include <unistd.h>
 #include <odp_internal.h>
 #include <odp_schedule_if.h>
+#include <odp_packet_io_internal.h>
 #include <libconfig.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/platform/linux-dpdk/odp_packet_dpdk.c 
b/platform/linux-dpdk/pktio/dpdk.c
similarity index 86%
rename from platform/linux-dpdk/odp_packet_dpdk.c
rename to platform/linux-dpdk/pktio/dpdk.c
index 214116b76..0dda05a69 100644
--- a/platform/linux-dpdk/odp_packet_dpdk.c
+++ b/platform/linux-dpdk/pktio/dpdk.c
@@ -28,7 +28,7 @@
 #include <odp_debug_internal.h>
 #include <odp_classification_internal.h>
 #include <odp_packet_io_internal.h>
-#include <odp_packet_dpdk.h>
+#include <pktio/dpdk.h>
 #include <net/if.h>
 #include <math.h>
 
@@ -39,6 +39,18 @@ static pktio_ops_module_t dpdk_pktio_ops;
 
 static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry);
 
+static inline pktio_ops_dpdk_data_t *
+       __retrieve_op_data(pktio_entry_t *pktio)
+{
+       return (pktio_ops_dpdk_data_t *)(pktio->ops_data(dpdk));
+}
+
+static inline void __release_op_data(pktio_entry_t *pktio)
+{
+       free(pktio->ops_data(dpdk));
+       pktio->ops_data(dpdk) = NULL;
+}
+
 /* Test if s has only digits or not. Dpdk pktio uses only digits.*/
 static int _dpdk_netdev_is_valid(const char *s)
 {
@@ -95,6 +107,8 @@ static void _dpdk_print_port_mac(uint8_t portid)
 static int input_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry,
                                        const odp_pktin_queue_param_t *p)
 {
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        odp_pktin_mode_t mode = pktio_entry->s.param.in_mode;
 
        /**
@@ -102,19 +116,19 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t 
*pktio_entry,
         * at a time polls a queue */
        if (mode == ODP_PKTIN_MODE_SCHED ||
            p->op_mode == ODP_PKTIO_OP_MT_UNSAFE)
-               pktio_entry->s.pkt_dpdk.lockless_rx = 1;
+               pkt_dpdk->lockless_rx = 1;
        else
-               pktio_entry->s.pkt_dpdk.lockless_rx = 0;
+               pkt_dpdk->lockless_rx = 0;
 
        if (p->hash_enable && p->num_queues > 1) {
-               pktio_entry->s.pkt_dpdk.hash = p->hash_proto;
+               pkt_dpdk->hash = p->hash_proto;
        } else {
-               pktio_entry->s.pkt_dpdk.hash.proto.ipv4_udp = 1;
-               pktio_entry->s.pkt_dpdk.hash.proto.ipv4_tcp = 1;
-               pktio_entry->s.pkt_dpdk.hash.proto.ipv4 = 1;
-               pktio_entry->s.pkt_dpdk.hash.proto.ipv6_udp = 1;
-               pktio_entry->s.pkt_dpdk.hash.proto.ipv6_tcp = 1;
-               pktio_entry->s.pkt_dpdk.hash.proto.ipv6 = 1;
+               pkt_dpdk->hash.proto.ipv4_udp = 1;
+               pkt_dpdk->hash.proto.ipv4_tcp = 1;
+               pkt_dpdk->hash.proto.ipv4 = 1;
+               pkt_dpdk->hash.proto.ipv6_udp = 1;
+               pkt_dpdk->hash.proto.ipv6_tcp = 1;
+               pkt_dpdk->hash.proto.ipv6 = 1;
        }
 
        return 0;
@@ -123,7 +137,8 @@ static int input_queues_config_pkt_dpdk(pktio_entry_t 
*pktio_entry,
 static int output_queues_config_pkt_dpdk(pktio_entry_t *pktio_entry,
                                         const odp_pktout_queue_param_t *p)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
 
        if (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE)
                pkt_dpdk->lockless_tx = 1;
@@ -133,12 +148,14 @@ static int output_queues_config_pkt_dpdk(pktio_entry_t 
*pktio_entry,
        return 0;
 }
 
-static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t 
*pktio_entry,
-                  const char *netdev, odp_pool_t pool ODP_UNUSED)
+static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED,
+                         pktio_entry_t *pktio_entry,
+                         const char *netdev,
+                         odp_pool_t pool ODP_UNUSED)
 {
        uint8_t portid = 0;
        struct rte_eth_dev_info dev_info;
-       pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk = NULL;
        int i;
 
        if (!_dpdk_netdev_is_valid(netdev)) {
@@ -147,6 +164,14 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, 
pktio_entry_t *pktio_ent
                return -1;
        }
 
+       pktio_entry->ops_data(dpdk) = malloc(sizeof(pktio_ops_dpdk_data_t));
+       pkt_dpdk = __retrieve_op_data(pktio_entry);
+
+       if (odp_unlikely(pkt_dpdk == NULL)) {
+               ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct");
+               return -1;
+       }
+
        portid = atoi(netdev);
        pkt_dpdk->portid = portid;
        memset(&dev_info, 0, sizeof(struct rte_eth_dev_info));
@@ -176,17 +201,21 @@ static int setup_pkt_dpdk(odp_pktio_t pktio ODP_UNUSED, 
pktio_entry_t *pktio_ent
 
 static int close_pkt_dpdk(pktio_entry_t *pktio_entry)
 {
-       pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
 
        if (pktio_entry->s.state == PKTIO_STATE_STOPPED)
                rte_eth_dev_close(pkt_dpdk->portid);
+
+       __release_op_data(pktio_entry);
        return 0;
 }
 
 static int start_pkt_dpdk(pktio_entry_t *pktio_entry)
 {
        int ret, i;
-       pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        uint8_t portid = pkt_dpdk->portid;
        int sid = rte_eth_dev_socket_id(pkt_dpdk->portid);
        int socket_id =  sid < 0 ? 0 : sid;
@@ -294,7 +323,9 @@ static int start_pkt_dpdk(pktio_entry_t *pktio_entry)
 
 static int stop_pkt_dpdk(pktio_entry_t *pktio_entry)
 {
-       rte_eth_dev_stop(pktio_entry->s.pkt_dpdk.portid);
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
+       rte_eth_dev_stop(pkt_dpdk->portid);
        return 0;
 }
 
@@ -335,16 +366,15 @@ static void _odp_pktio_send_completion(pktio_entry_t 
*pktio_entry)
                        odp_ticketlock_unlock(&entry->s.txl);
                }
        }
-
-       return;
 }
 
 static int recv_pkt_dpdk(pktio_entry_t *pktio_entry, int index,
                         odp_packet_t pkt_table[], int len)
 {
        uint16_t nb_rx, i;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        odp_packet_t *saved_pkt_table;
-       pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;
        uint8_t min = pkt_dpdk->min_rx_burst;
        odp_time_t ts_val;
        odp_time_t *ts = NULL;
@@ -459,7 +489,8 @@ static int send_pkt_dpdk(pktio_entry_t *pktio_entry, int 
index,
                         const odp_packet_t pkt_table[], int len)
 {
        int pkts;
-       pkt_dpdk_t * const pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
 
        if (!pkt_dpdk->lockless_tx)
                odp_ticketlock_lock(&pkt_dpdk->tx_lock[index]);
@@ -511,10 +542,12 @@ static uint32_t _dpdk_vdev_mtu(uint8_t port_id)
 
 static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry)
 {
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        uint16_t mtu = 0;
        int ret;
 
-       ret = rte_eth_dev_get_mtu(pktio_entry->s.pkt_dpdk.portid, &mtu);
+       ret = rte_eth_dev_get_mtu(pkt_dpdk->portid, &mtu);
        if (ret < 0)
                return 0;
 
@@ -522,7 +555,7 @@ static uint32_t mtu_get_pkt_dpdk(pktio_entry_t *pktio_entry)
         * try to use system call if dpdk cannot get mtu value.
         */
        if (mtu == 0)
-               mtu = _dpdk_vdev_mtu(pktio_entry->s.pkt_dpdk.portid);
+               mtu = _dpdk_vdev_mtu(pkt_dpdk->portid);
        return mtu;
 }
 
@@ -570,13 +603,16 @@ static int _dpdk_vdev_promisc_mode_set(uint8_t port_id, 
int enable)
 
 static int promisc_mode_set_pkt_dpdk(pktio_entry_t *pktio_entry,  int enable)
 {
-       uint8_t portid = pktio_entry->s.pkt_dpdk.portid;
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
+       uint8_t portid = pkt_dpdk->portid;
+
        if (enable)
                rte_eth_promiscuous_enable(portid);
        else
                rte_eth_promiscuous_disable(portid);
 
-       if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc) {
+       if (pkt_dpdk->vdev_sysc_promisc) {
                int ret = _dpdk_vdev_promisc_mode_set(portid, enable);
                if (ret < 0)
                        ODP_DBG("vdev promisc mode fail\n");
@@ -605,23 +641,27 @@ static int _dpdk_vdev_promisc_mode(uint8_t port_id)
        if (ifr.ifr_flags & IFF_PROMISC) {
                ODP_DBG("promisc is 1\n");
                return 1;
-       } else
-               return 0;
+       }
+       return 0;
 }
 
 static int promisc_mode_get_pkt_dpdk(pktio_entry_t *pktio_entry)
 {
-       uint8_t portid = pktio_entry->s.pkt_dpdk.portid;
-       if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc)
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
+       uint8_t portid = pkt_dpdk->portid;
+
+       if (pkt_dpdk->vdev_sysc_promisc)
                return _dpdk_vdev_promisc_mode(portid);
        else
                return rte_eth_promiscuous_get(portid);
-
 }
 
 static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, void *mac_addr)
 {
-       rte_eth_macaddr_get(pktio_entry->s.pkt_dpdk.portid,
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
+       rte_eth_macaddr_get(pkt_dpdk->portid,
                            (struct ether_addr *)mac_addr);
        return ETH_ALEN;
 }
@@ -630,14 +670,18 @@ static int mac_get_pkt_dpdk(pktio_entry_t *pktio_entry, 
void *mac_addr)
 static int capability_pkt_dpdk(pktio_entry_t *pktio_entry,
                               odp_pktio_capability_t *capa)
 {
-       *capa = pktio_entry->s.pkt_dpdk.capa;
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
+       *capa = pkt_dpdk->capa;
        return 0;
 }
 static int link_status_pkt_dpdk(pktio_entry_t *pktio_entry)
 {
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        struct rte_eth_link link;
 
-       rte_eth_link_get(pktio_entry->s.pkt_dpdk.portid, &link);
+       rte_eth_link_get(pkt_dpdk->portid, &link);
        return link.link_status;
 }
 
@@ -657,25 +701,28 @@ static void stats_convert(struct rte_eth_stats *rte_stats,
 
 static int stats_pkt_dpdk(pktio_entry_t *pktio_entry, odp_pktio_stats_t *stats)
 {
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        int ret;
        struct rte_eth_stats rte_stats;
 
-       ret = rte_eth_stats_get(pktio_entry->s.pkt_dpdk.portid, &rte_stats);
+       ret = rte_eth_stats_get(pkt_dpdk->portid, &rte_stats);
 
        if (ret == 0) {
                stats_convert(&rte_stats, stats);
                return 0;
-       } else {
-               if (ret > 0)
-                       return -ret;
-               else
-                       return ret;
        }
+
+       if (ret > 0)
+               return -ret;
+       return ret;
 }
 
 static int stats_reset_pkt_dpdk(pktio_entry_t *pktio_entry)
 {
-       rte_eth_stats_reset(pktio_entry->s.pkt_dpdk.portid);
+       const pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
+       rte_eth_stats_reset(pkt_dpdk->portid);
        return 0;
 }
 
diff --git a/platform/linux-dpdk/include/odp_packet_dpdk.h 
b/platform/linux-dpdk/pktio/dpdk.h
similarity index 59%
rename from platform/linux-dpdk/include/odp_packet_dpdk.h
rename to platform/linux-dpdk/pktio/dpdk.h
index 495d5e6f1..064c5d8ce 100644
--- a/platform/linux-dpdk/include/odp_packet_dpdk.h
+++ b/platform/linux-dpdk/pktio/dpdk.h
@@ -4,8 +4,8 @@
  * SPDX-License-Identifier:     BSD-3-Clause
  */
 
-#ifndef ODP_PACKET_DPDK_H
-#define ODP_PACKET_DPDK_H
+#ifndef ODP_PKTIO_OPS_DPDK_H_
+#define ODP_PKTIO_OPS_DPDK_H_
 
 #include <stdint.h>
 #include <net/if.h>
@@ -46,4 +46,21 @@
 #define RTE_TEST_RX_DESC_DEFAULT 128
 #define RTE_TEST_TX_DESC_DEFAULT 512
 
+/** Packet socket using dpdk mmaped rings for both Rx and Tx */
+typedef struct {
+       odp_pktio_capability_t capa;    /**< interface capabilities */
+
+       /********************************/
+       char ifname[32];
+       uint8_t min_rx_burst;
+       uint8_t portid;
+       odp_bool_t vdev_sysc_promisc;   /**< promiscuous mode defined with
+                                            system call */
+       odp_pktin_hash_proto_t hash;    /**< Packet input hash protocol */
+       odp_bool_t lockless_rx;         /**< no locking for rx */
+       odp_bool_t lockless_tx;         /**< no locking for tx */
+       odp_ticketlock_t rx_lock[PKTIO_MAX_QUEUES]; /**< RX queue locks */
+       odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES]; /**< TX queue locks */
+} pktio_ops_dpdk_data_t;
+
 #endif
diff --git a/platform/linux-dpdk/pool/dpdk.c b/platform/linux-dpdk/pool/dpdk.c
index 499bea127..0e1dfde70 100644
--- a/platform/linux-dpdk/pool/dpdk.c
+++ b/platform/linux-dpdk/pool/dpdk.c
@@ -26,7 +26,7 @@
 #include <inttypes.h>
 
 /* for DPDK */
-#include <odp_packet_dpdk.h>
+#include <odp_packet_io_internal.h>
 
 #ifdef POOL_USE_TICKETLOCK
 #include <odp/api/ticketlock.h>
diff --git a/platform/linux-generic/Makefile.am 
b/platform/linux-generic/Makefile.am
index 6261cf0a6..5503535e4 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -186,7 +186,7 @@ noinst_HEADERS = \
                  ${srcdir}/include/odp_packet_internal.h \
                  ${srcdir}/include/odp_packet_io_internal.h \
                  ${srcdir}/include/odp_packet_io_ring_internal.h \
-                 ${srcdir}/include/odp_packet_dpdk.h \
+                 ${srcdir}/pktio/dpdk.h \
                  ${srcdir}/include/odp_pktio_ops_ipc.h \
                  ${srcdir}/include/odp_pktio_ops_loopback.h \
                  ${srcdir}/include/odp_pktio_ops_netmap.h \
@@ -267,7 +267,7 @@ __LIB__libodp_linux_la_SOURCES = \
                           pktio/ethtool.c \
                           pktio/subsystem.c \
                           pktio/ipc.c \
-                          pktio/pktio_common.c \
+                          pktio/common.c \
                           pktio/loopback.c \
                           pktio/netmap.c \
                           pktio/dpdk.c \
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h 
b/platform/linux-generic/include/odp_packet_io_internal.h
index 7c2833fc6..9fe9aeaa7 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -31,8 +31,6 @@ extern "C" {
 #include <net/if.h>
 
 #define PKTIO_MAX_QUEUES 64
-#include <odp_packet_dpdk.h>
-
 /* Forward declaration */
 typedef union pktio_entry_u pktio_entry_t;
 #include <odp_pktio_ops_subsystem.h>
@@ -56,9 +54,6 @@ struct pktio_entry {
        odp_ticketlock_t txl;           /**< TX ticketlock */
        int cls_enabled;                /**< is classifier enabled */
        odp_pktio_t handle;             /**< pktio handle */
-       union {
-               pkt_dpdk_t pkt_dpdk;            /**< using DPDK for IO */
-       };
        enum {
                /* Not allocated */
                PKTIO_STATE_FREE = 0,
diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h 
b/platform/linux-generic/include/odp_pktio_ops_subsystem.h
index 5c01e34f6..7a915b82c 100644
--- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h
+++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h
@@ -90,6 +90,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) {
  * TODO: refactory each implementation to hide it internally
  */
 typedef union {
+       void *dpdk;
        pktio_ops_ipc_data_t ipc;
        pktio_ops_loopback_data_t loopback;
        pktio_ops_netmap_data_t netmap;
diff --git a/platform/linux-generic/pktio/pktio_common.c 
b/platform/linux-generic/pktio/common.c
similarity index 100%
rename from platform/linux-generic/pktio/pktio_common.c
rename to platform/linux-generic/pktio/common.c
diff --git a/platform/linux-generic/pktio/dpdk.c 
b/platform/linux-generic/pktio/dpdk.c
index e72a76371..511c77783 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -20,9 +20,9 @@
 
 #include <odp_packet_io_internal.h>
 #include <odp_classification_internal.h>
-#include <odp_packet_dpdk.h>
 #include <odp_debug_internal.h>
 
+#include <pktio/dpdk.h>
 #include <protocols/eth.h>
 
 #include <rte_config.h>
@@ -32,6 +32,18 @@
 #include <rte_ethdev.h>
 #include <rte_string_fns.h>
 
+static inline pktio_ops_dpdk_data_t *
+       __retrieve_op_data(pktio_entry_t *pktio)
+{
+       return (pktio_ops_dpdk_data_t *)(pktio->ops_data(dpdk));
+}
+
+static inline void __release_op_data(pktio_entry_t *pktio)
+{
+       free(pktio->ops_data(dpdk));
+       pktio->ops_data(dpdk) = NULL;
+}
+
 #if ODP_DPDK_ZERO_COPY
 ODP_STATIC_ASSERT(CONFIG_PACKET_HEADROOM == RTE_PKTMBUF_HEADROOM,
                  "ODP and DPDK headroom sizes not matching!");
@@ -310,10 +322,10 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
        int i, j;
        int nb_pkts = 0;
        int alloc_len, num;
-       odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool;
+       odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool;
 
        /* Allocate maximum sized packets */
-       alloc_len = pktio_entry->s.pkt_dpdk.data_room;
+       alloc_len = __retrieve_op_data(pktio_entry)->data_room;
 
        num = packet_alloc_multi(pool, alloc_len, pkt_table, mbuf_num);
        if (num != mbuf_num) {
@@ -385,7 +397,8 @@ static inline int pkt_to_mbuf(pktio_entry_t *pktio_entry,
                              struct rte_mbuf *mbuf_table[],
                              const odp_packet_t pkt_table[], uint16_t num)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        int i, j;
        char *data;
        uint16_t pkt_len;
@@ -430,7 +443,7 @@ static inline int mbuf_to_pkt_zero(pktio_entry_t 
*pktio_entry,
        void *data;
        int i;
        int nb_pkts = 0;
-       odp_pool_t pool = pktio_entry->s.pkt_dpdk.pool;
+       odp_pool_t pool = __retrieve_op_data(pktio_entry)->pool;
 
        for (i = 0; i < mbuf_num; i++) {
                odp_packet_hdr_t parsed_hdr;
@@ -487,7 +500,8 @@ static inline int pkt_to_mbuf_zero(pktio_entry_t 
*pktio_entry,
                                   const odp_packet_t pkt_table[], uint16_t num,
                                   uint16_t *seg_count)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        int i;
 
        *seg_count = 0;
@@ -562,7 +576,8 @@ static uint32_t dpdk_vdev_mtu_get(uint8_t port_id)
 
 static uint32_t dpdk_mtu_get(pktio_entry_t *pktio_entry)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        uint32_t mtu = 0;
 
        if (rte_eth_dev_get_mtu(pkt_dpdk->port_id, (uint16_t *)&mtu))
@@ -655,7 +670,8 @@ static void rss_conf_to_hash_proto(struct rte_eth_rss_conf 
*rss_conf,
 static int dpdk_setup_port(pktio_entry_t *pktio_entry)
 {
        int ret;
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        struct rte_eth_rss_conf rss_conf;
 
        /* Always set some hash functions to enable DPDK RSS hash calculation */
@@ -697,7 +713,8 @@ static int dpdk_setup_port(pktio_entry_t *pktio_entry)
 
 static int dpdk_close(pktio_entry_t *pktio_entry)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        unsigned idx;
        unsigned i, j;
 
@@ -715,6 +732,7 @@ static int dpdk_close(pktio_entry_t *pktio_entry)
        if (!ODP_DPDK_ZERO_COPY)
                rte_mempool_free(pkt_dpdk->pkt_pool);
 
+       __release_op_data(pktio_entry);
        return 0;
 }
 
@@ -860,9 +878,9 @@ static int dpdk_input_queues_config(pktio_entry_t 
*pktio_entry,
                lockless = 0;
 
        if (p->hash_enable && p->num_queues > 1)
-               pktio_entry->s.pkt_dpdk.hash = p->hash_proto;
+               __retrieve_op_data(pktio_entry)->hash = p->hash_proto;
 
-       pktio_entry->s.pkt_dpdk.lockless_rx = lockless;
+       __retrieve_op_data(pktio_entry)->lockless_rx = lockless;
 
        return 0;
 }
@@ -870,7 +888,8 @@ static int dpdk_input_queues_config(pktio_entry_t 
*pktio_entry,
 static int dpdk_output_queues_config(pktio_entry_t *pktio_entry,
                                     const odp_pktout_queue_param_t *p)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        odp_bool_t lockless;
 
        if (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE)
@@ -886,7 +905,8 @@ static int dpdk_output_queues_config(pktio_entry_t 
*pktio_entry,
 static void dpdk_init_capability(pktio_entry_t *pktio_entry,
                                 struct rte_eth_dev_info *dev_info)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        odp_pktio_capability_t *capa = &pkt_dpdk->capa;
 
        memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
@@ -909,7 +929,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
                     const char *netdev,
                     odp_pool_t pool)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk = NULL;
        struct rte_eth_dev_info dev_info;
        struct rte_mempool *pkt_pool;
        char pool_name[RTE_MEMPOOL_NAMESIZE];
@@ -937,6 +957,14 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
                dpdk_initialized = 1;
        }
 
+       pktio_entry->ops_data(dpdk) = malloc(sizeof(pktio_ops_dpdk_data_t));
+       pkt_dpdk = __retrieve_op_data(pktio_entry);
+
+       if (odp_unlikely(pkt_dpdk == NULL)) {
+               ODP_ERR("Failed to allocate pktio_ops_dpdk_data_t struct");
+               return -1;
+       }
+
        /* Init pktio entry */
        memset(pkt_dpdk, 0, sizeof(*pkt_dpdk));
 
@@ -945,6 +973,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
 
        if (rte_eth_dev_count() == 0) {
                ODP_ERR("No DPDK ports found\n");
+               __release_op_data(pktio_entry);
                return -1;
        }
 
@@ -953,6 +982,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
        mtu = dpdk_mtu_get(pktio_entry);
        if (mtu == 0) {
                ODP_ERR("Failed to read interface MTU\n");
+               __release_op_data(pktio_entry);
                return -1;
        }
        pkt_dpdk->mtu = mtu + _ODP_ETHHDR_LEN;
@@ -989,6 +1019,7 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
        }
        if (pkt_pool == NULL) {
                ODP_ERR("Cannot init mbuf packet pool\n");
+               __release_op_data(pktio_entry);
                return -1;
        }
 
@@ -1013,7 +1044,8 @@ static int dpdk_open(odp_pktio_t id ODP_UNUSED,
 
 static int dpdk_start(pktio_entry_t *pktio_entry)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        uint8_t port_id = pkt_dpdk->port_id;
        int ret;
        unsigned i;
@@ -1064,7 +1096,7 @@ static int dpdk_start(pktio_entry_t *pktio_entry)
 
 static int dpdk_stop(pktio_entry_t *pktio_entry)
 {
-       rte_eth_dev_stop(pktio_entry->s.pkt_dpdk.port_id);
+       rte_eth_dev_stop(__retrieve_op_data(pktio_entry)->port_id);
 
        return 0;
 }
@@ -1072,7 +1104,8 @@ static int dpdk_stop(pktio_entry_t *pktio_entry)
 static int dpdk_recv(pktio_entry_t *pktio_entry, int index,
                     odp_packet_t pkt_table[], int num)
 {
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        pkt_cache_t *rx_cache = &pkt_dpdk->rx_cache[index];
        odp_time_t ts_val;
        odp_time_t *ts = NULL;
@@ -1104,7 +1137,7 @@ static int dpdk_recv(pktio_entry_t *pktio_entry, int 
index,
        } else if ((unsigned)num < pkt_dpdk->min_rx_burst) {
                struct rte_mbuf *new_mbufs[pkt_dpdk->min_rx_burst];
 
-               nb_rx = rte_eth_rx_burst(pktio_entry->s.pkt_dpdk.port_id, index,
+               nb_rx = rte_eth_rx_burst(pkt_dpdk->port_id, index,
                                         new_mbufs, pkt_dpdk->min_rx_burst);
                rx_cache->s.idx = 0;
                for (i = 0; i < nb_rx; i++) {
@@ -1119,7 +1152,7 @@ static int dpdk_recv(pktio_entry_t *pktio_entry, int 
index,
                nb_rx = RTE_MIN(num, nb_rx);
 
        } else {
-               nb_rx = rte_eth_rx_burst(pktio_entry->s.pkt_dpdk.port_id, index,
+               nb_rx = rte_eth_rx_burst(pkt_dpdk->port_id, index,
                                         rx_mbufs, num);
        }
 
@@ -1147,7 +1180,8 @@ static int dpdk_send(pktio_entry_t *pktio_entry, int 
index,
                     const odp_packet_t pkt_table[], int num)
 {
        struct rte_mbuf *tx_mbufs[num];
-       pkt_dpdk_t *pkt_dpdk = &pktio_entry->s.pkt_dpdk;
+       pktio_ops_dpdk_data_t *pkt_dpdk =
+               __retrieve_op_data(pktio_entry);
        uint16_t seg_count = 0;
        int tx_pkts;
        int i;
@@ -1210,16 +1244,16 @@ static int dpdk_send(pktio_entry_t *pktio_entry, int 
index,
 
 static int dpdk_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr)
 {
-       rte_eth_macaddr_get(pktio_entry->s.pkt_dpdk.port_id,
+       rte_eth_macaddr_get(__retrieve_op_data(pktio_entry)->port_id,
                            (struct ether_addr *)mac_addr);
        return ETH_ALEN;
 }
 
 static int dpdk_promisc_mode_set(pktio_entry_t *pktio_entry, odp_bool_t enable)
 {
-       uint8_t port_id = pktio_entry->s.pkt_dpdk.port_id;
+       uint8_t port_id = __retrieve_op_data(pktio_entry)->port_id;
 
-       if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc)
+       if (__retrieve_op_data(pktio_entry)->vdev_sysc_promisc)
                return dpdk_vdev_promisc_mode_set(port_id, enable);
 
        if (enable)
@@ -1232,9 +1266,9 @@ static int dpdk_promisc_mode_set(pktio_entry_t 
*pktio_entry, odp_bool_t enable)
 
 static int dpdk_promisc_mode_get(pktio_entry_t *pktio_entry)
 {
-       uint8_t port_id = pktio_entry->s.pkt_dpdk.port_id;
+       uint8_t port_id = __retrieve_op_data(pktio_entry)->port_id;
 
-       if (pktio_entry->s.pkt_dpdk.vdev_sysc_promisc)
+       if (__retrieve_op_data(pktio_entry)->vdev_sysc_promisc)
                return dpdk_vdev_promisc_mode_get(port_id);
        else
                return rte_eth_promiscuous_get(port_id);
@@ -1243,7 +1277,7 @@ static int dpdk_promisc_mode_get(pktio_entry_t 
*pktio_entry)
 static int dpdk_capability(pktio_entry_t *pktio_entry,
                           odp_pktio_capability_t *capa)
 {
-       *capa = pktio_entry->s.pkt_dpdk.capa;
+       *capa = __retrieve_op_data(pktio_entry)->capa;
        return 0;
 }
 
@@ -1253,7 +1287,8 @@ static int dpdk_link_status(pktio_entry_t *pktio_entry)
 
        memset(&link, 0, sizeof(struct rte_eth_link));
 
-       rte_eth_link_get_nowait(pktio_entry->s.pkt_dpdk.port_id, &link);
+       rte_eth_link_get_nowait(
+               __retrieve_op_data(pktio_entry)->port_id, &link);
 
        return link.link_status;
 }
@@ -1275,7 +1310,8 @@ static int dpdk_stats(pktio_entry_t *pktio_entry, 
odp_pktio_stats_t *stats)
        int ret;
        struct rte_eth_stats rte_stats;
 
-       ret = rte_eth_stats_get(pktio_entry->s.pkt_dpdk.port_id, &rte_stats);
+       ret = rte_eth_stats_get(
+               __retrieve_op_data(pktio_entry)->port_id, &rte_stats);
 
        if (ret == 0) {
                stats_convert(&rte_stats, stats);
@@ -1286,7 +1322,7 @@ static int dpdk_stats(pktio_entry_t *pktio_entry, 
odp_pktio_stats_t *stats)
 
 static int dpdk_stats_reset(pktio_entry_t *pktio_entry)
 {
-       rte_eth_stats_reset(pktio_entry->s.pkt_dpdk.port_id);
+       rte_eth_stats_reset(__retrieve_op_data(pktio_entry)->port_id);
        return 0;
 }
 
diff --git a/platform/linux-generic/include/odp_packet_dpdk.h 
b/platform/linux-generic/pktio/dpdk.h
similarity index 96%
rename from platform/linux-generic/include/odp_packet_dpdk.h
rename to platform/linux-generic/pktio/dpdk.h
index 5d80d84a3..7495b5965 100644
--- a/platform/linux-generic/include/odp_packet_dpdk.h
+++ b/platform/linux-generic/pktio/dpdk.h
@@ -4,8 +4,8 @@
  * SPDX-License-Identifier:     BSD-3-Clause
  */
 
-#ifndef ODP_PACKET_DPDK_H
-#define ODP_PACKET_DPDK_H
+#ifndef ODP_PKTIO_OPS_DPDK_H_
+#define ODP_PKTIO_OPS_DPDK_H_
 
 #include <odp/api/packet_io.h>
 #include <odp/api/pool.h>
@@ -63,6 +63,6 @@ typedef struct {
        odp_ticketlock_t tx_lock[PKTIO_MAX_QUEUES];  /**< TX queue locks */
        /** cache for storing extra RX packets */
        pkt_cache_t rx_cache[PKTIO_MAX_QUEUES];
-} pkt_dpdk_t;
+} pktio_ops_dpdk_data_t;
 
 #endif

Reply via email to