diff mbox

[ODP/PATCH,REQUIRE,TESTING] rework packet io selection

Message ID 1396012333-27985-1-git-send-email-maxim.uvarov@linaro.org
State Superseded
Headers show

Commit Message

Maxim Uvarov March 28, 2014, 1:12 p.m. UTC
Dynamically select type of packet I/O
sock_params->type =
	ODP_PKTIO_TYPE_SOCKET_BASIC
	ODP_PKTIO_TYPE_SOCKET_MMSG
	ODP_PKTIO_TYPE_SOCKET_MMAP
	ODP_PKTIO_TYPE_NETMAP
sock_params->fanout = 1;
pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 .../linux-generic/include/api/odp_pktio_types.h    |  6 +-
 .../linux-generic/include/odp_packet_io_internal.h |  1 +
 platform/linux-generic/include/odp_packet_socket.h | 56 +++++--------
 platform/linux-generic/source/odp_packet_io.c      | 61 +++++++++++---
 platform/linux-generic/source/odp_packet_socket.c  | 98 +++++++++-------------
 test/packet/odp_example_pktio.c                    |  4 +-
 6 files changed, 119 insertions(+), 107 deletions(-)

Comments

Ciprian Barbu March 28, 2014, 1:42 p.m. UTC | #1
Excellent! I've always wanted this done. But I see you've set the pktio
type to ODP_PKTIO_TYPE_SOCKET_BASIC in the packet example. I don't have a
problem with it, since the BASIC and MMSG modes work without unsetting the
IP addresses, just wanted to point it out.


On Fri, Mar 28, 2014 at 3:12 PM, Maxim Uvarov <maxim.uvarov@linaro.org>wrote:

> Dynamically select type of packet I/O
> sock_params->type =
>         ODP_PKTIO_TYPE_SOCKET_BASIC
>         ODP_PKTIO_TYPE_SOCKET_MMSG
>         ODP_PKTIO_TYPE_SOCKET_MMAP
>         ODP_PKTIO_TYPE_NETMAP
> sock_params->fanout = 1;
> pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  .../linux-generic/include/api/odp_pktio_types.h    |  6 +-
>  .../linux-generic/include/odp_packet_io_internal.h |  1 +
>  platform/linux-generic/include/odp_packet_socket.h | 56 +++++--------
>  platform/linux-generic/source/odp_packet_io.c      | 61 +++++++++++---
>  platform/linux-generic/source/odp_packet_socket.c  | 98
> +++++++++-------------
>  test/packet/odp_example_pktio.c                    |  4 +-
>  6 files changed, 119 insertions(+), 107 deletions(-)
>
> diff --git a/platform/linux-generic/include/api/odp_pktio_types.h
> b/platform/linux-generic/include/api/odp_pktio_types.h
> index e6b4cbf..c87bfc2 100644
> --- a/platform/linux-generic/include/api/odp_pktio_types.h
> +++ b/platform/linux-generic/include/api/odp_pktio_types.h
> @@ -17,9 +17,11 @@ extern "C" {
>   */
>
>  typedef enum {
> -       ODP_PKTIO_TYPE_SOCKET = 0x01,
> +       ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1,
> +       ODP_PKTIO_TYPE_SOCKET_MMSG =  0x2,
> +       ODP_PKTIO_TYPE_SOCKET_MMAP =  0x3,
>  #ifdef ODP_HAVE_NETMAP
> -       ODP_PKTIO_TYPE_NETMAP = 0x02,
> +       ODP_PKTIO_TYPE_NETMAP =   0x4,
>  #endif
>  } odp_pktio_type_t;
>
> diff --git a/platform/linux-generic/include/odp_packet_io_internal.h
> b/platform/linux-generic/include/odp_packet_io_internal.h
> index ba1ee9b..3ab7fa0 100644
> --- a/platform/linux-generic/include/odp_packet_io_internal.h
> +++ b/platform/linux-generic/include/odp_packet_io_internal.h
> @@ -31,6 +31,7 @@ struct pktio_entry {
>         odp_queue_t outq_default;       /**< default out queue */
>         odp_pktio_params_t params;      /**< pktio parameters */
>         pkt_sock_t pkt_sock;            /**< using socket API for IO */
> +       pkt_sock_mmap_t pkt_sock_mmap;  /**< using socket mmap API for IO
> */
>  #ifdef ODP_HAVE_NETMAP
>         pkt_netmap_t pkt_nm;            /**< using netmap API for IO */
>  #endif
> diff --git a/platform/linux-generic/include/odp_packet_socket.h
> b/platform/linux-generic/include/odp_packet_socket.h
> index fe216bb..98ceb98 100644
> --- a/platform/linux-generic/include/odp_packet_socket.h
> +++ b/platform/linux-generic/include/odp_packet_socket.h
> @@ -20,37 +20,15 @@
>
>  #include <linux/version.h>
>
> -
>  /*
>   * Packet socket config:
>   */
> -#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */
> -#define ODP_PACKET_SOCKET_MMSG  1 /** use recvmmsg()/sendmmsg() */
> -#define ODP_PACKET_SOCKET_MMAP  2 /** use PACKET_MMAP */
> -
> -
> -#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0)
> -/* PACKET_FANOUT feature not supported */
> -#define ODP_PACKET_SOCKET_FANOUT 0
> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC)
> -#else
> -/** PACKET_FANOUT mode spreads incoming packets over multiple sockets*/
> -#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */
> -/** Choose one from the alternatives above */
> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP)
> -#endif
> -
>
>  /** Max receive (Rx) burst size*/
>  #define ODP_PACKET_SOCKET_MAX_BURST_RX 32
>  /** Max transmit (Tx) burst size*/
>  #define ODP_PACKET_SOCKET_MAX_BURST_TX 32
>
> -
> -
> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> -       (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
> -
>  typedef struct {
>         int sockfd; /**< socket descriptor */
>         odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */
> @@ -60,12 +38,6 @@ typedef struct {
>         unsigned char if_mac[ETH_ALEN]; /**< IF eth mac addr */
>  } pkt_sock_t;
>
> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
> -
> -#if ODP_PACKET_SOCKET_FANOUT == 0
> -#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1"
> -#endif
> -
>  /** packet mmap ring */
>  struct ring {
>         struct iovec *rd;
> @@ -99,31 +71,45 @@ typedef struct {
>         unsigned mmap_len;
>         unsigned char if_mac[ETH_ALEN];
>         struct sockaddr_ll ll;
> -} pkt_sock_t;
> -
> -#else
> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> -#endif
> +       int fanout; /**< 0: off 1: on */
> +} pkt_sock_mmap_t;
>
>  /**
>   * Open & configure a raw packet socket
>   */
>  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>                    odp_buffer_pool_t pool);
> +
> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
> +                  odp_buffer_pool_t pool);
> +
>  /**
>   * Close a packet socket
>   */
>  int close_pkt_sock(pkt_sock_t * const pkt_sock);
>
> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock);
> +
>  /**
>   * Receive packets from the packet socket
>   */
> -int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> +int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
>                   unsigned len);
> +
> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> +                 unsigned len);
> +
> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> +                 odp_packet_t pkt_table[], unsigned len);
>  /**
>   * Send packets through the packet socket
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> +                 unsigned len);
> +
> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
>                   unsigned len);
>
> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> +                 odp_packet_t pkt_table[], unsigned len);
>  #endif
> diff --git a/platform/linux-generic/source/odp_packet_io.c
> b/platform/linux-generic/source/odp_packet_io.c
> index 92aed34..ab80aef 100644
> --- a/platform/linux-generic/source/odp_packet_io.c
> +++ b/platform/linux-generic/source/odp_packet_io.c
> @@ -117,8 +117,12 @@ static void init_pktio_entry(pktio_entry_t *entry,
> odp_pktio_params_t *params)
>         set_taken(entry);
>         entry->s.inq_default = ODP_QUEUE_INVALID;
>         switch (params->type) {
> -       case ODP_PKTIO_TYPE_SOCKET:
> +       case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +       case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +       case ODP_PKTIO_TYPE_SOCKET_MMAP:
>                 memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock));
> +               memset(&entry->s.pkt_sock_mmap, 0,
> +                     sizeof(entry->s.pkt_sock_mmap));
>                 break;
>  #ifdef ODP_HAVE_NETMAP
>         case ODP_PKTIO_TYPE_NETMAP:
> @@ -177,7 +181,9 @@ odp_pktio_t odp_pktio_open(char *dev,
> odp_buffer_pool_t pool,
>         }
>
>         switch (params->type) {
> -       case ODP_PKTIO_TYPE_SOCKET:
> +       case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +       case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +       case ODP_PKTIO_TYPE_SOCKET_MMAP:
>                 ODP_DBG("Allocating socket pktio\n");
>                 break;
>  #ifdef ODP_HAVE_NETMAP
> @@ -200,7 +206,8 @@ odp_pktio_t odp_pktio_open(char *dev,
> odp_buffer_pool_t pool,
>         pktio_entry = get_entry(id);
>
>         switch (params->type) {
> -       case ODP_PKTIO_TYPE_SOCKET:
> +       case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +       case ODP_PKTIO_TYPE_SOCKET_MMSG:
>                 res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool);
>                 if (res == -1) {
>                         close_pkt_sock(&pktio_entry->s.pkt_sock);
> @@ -208,10 +215,19 @@ odp_pktio_t odp_pktio_open(char *dev,
> odp_buffer_pool_t pool,
>                         id = ODP_PKTIO_INVALID;
>                 }
>                 break;
> +       case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +               res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> dev,
> +                               pool);
> +               if (res == -1) {
> +                       close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap);
> +                       free_pktio_entry(id);
> +                       id = ODP_PKTIO_INVALID;
> +               }
> +               break;
>  #ifdef ODP_HAVE_NETMAP
>         case ODP_PKTIO_TYPE_NETMAP:
>                 res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev,
> -                                      pool, &params->nm_params);
> +                               pool, &params->nm_params);
>                 if (res == -1) {
>                         close_pkt_netmap(&pktio_entry->s.pkt_nm);
>                         free_pktio_entry(id);
> @@ -237,9 +253,13 @@ int odp_pktio_close(odp_pktio_t id)
>         lock_entry(entry);
>         if (!is_free(entry)) {
>                 switch (entry->s.params.type) {
> -               case ODP_PKTIO_TYPE_SOCKET:
> +               case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +               case ODP_PKTIO_TYPE_SOCKET_MMSG:
>                         res  = close_pkt_sock(&entry->s.pkt_sock);
>                         break;
> +               case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +                       res  =
> close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
> +                       break;
>  #ifdef ODP_HAVE_NETMAP
>                 case ODP_PKTIO_TYPE_NETMAP:
>                         res  = close_pkt_netmap(&entry->s.pkt_nm);
> @@ -247,7 +267,7 @@ int odp_pktio_close(odp_pktio_t id)
>  #endif
>                 default:
>                         break;
> -               res |= free_pktio_entry(id);
> +                       res |= free_pktio_entry(id);
>                 }
>         }
>         unlock_entry(entry);
> @@ -279,8 +299,17 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
>
>         lock_entry(pktio_entry);
>         switch (pktio_entry->s.params.type) {
> -       case ODP_PKTIO_TYPE_SOCKET:
> -               pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table,
> len);
> +       case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +               pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> +                               pkt_table, len);
> +               break;
> +       case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +               pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> +                               pkt_table, len);
> +               break;
> +       case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +               pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> +                               pkt_table, len);
>                 break;
>  #ifdef ODP_HAVE_NETMAP
>         case ODP_PKTIO_TYPE_NETMAP:
> @@ -312,12 +341,22 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
>
>         lock_entry(pktio_entry);
>         switch (pktio_entry->s.params.type) {
> -       case ODP_PKTIO_TYPE_SOCKET:
> -               pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table,
> len);
> +       case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +               pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> +                               pkt_table, len);
> +               break;
> +       case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +               pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> +                               pkt_table, len);
> +               break;
> +       case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +               pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> +                               pkt_table, len);
>                 break;
>  #ifdef ODP_HAVE_NETMAP
>         case ODP_PKTIO_TYPE_NETMAP:
> -               pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table,
> len);
> +               pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
> +                               pkt_table, len);
>                 break;
>  #endif
>         default:
> diff --git a/platform/linux-generic/source/odp_packet_socket.c
> b/platform/linux-generic/source/odp_packet_socket.c
> index aaf2605..5f942dd 100644
> --- a/platform/linux-generic/source/odp_packet_socket.c
> +++ b/platform/linux-generic/source/odp_packet_socket.c
> @@ -63,15 +63,17 @@ static inline int ethaddrs_equal(unsigned char
> mac_a[], unsigned char mac_b[])
>         return !memcmp(mac_a, mac_b, ETH_ALEN);
>  }
>
> -static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int
> sock_group_idx)
> +static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock,
> +               int sock_group_idx)
>  {
> -#if ODP_PACKET_SOCKET_FANOUT == 1
> -       /* Use FANOUT-mode for socket */
>         int sockfd = pkt_sock->sockfd;
>         int val;
>         int err;
>         uint16_t fanout_group;
>
> +       if (!pkt_sock->fanout)
> +               return 0;
> +
>         fanout_group = (uint16_t) (sock_group_idx & 0xffff);
>         val = (PACKET_FANOUT_HASH << 16) | fanout_group;
>
> @@ -80,16 +82,9 @@ static int set_pkt_sock_fanout(pkt_sock_t * const
> pkt_sock, int sock_group_idx)
>                 perror("set_pkt_sock_fanout() -
> setsockopt(PACKET_FANOUT)");
>                 return -1;
>         }
> -#else
> -       (void)pkt_sock;
> -       (void)sock_group_idx;
> -#endif
> -
>         return 0;
>  }
>
> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> -       (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
>  /*
>   * ODP_PACKET_SOCKET_BASIC:
>   * ODP_PACKET_SOCKET_MMSG:
> @@ -163,11 +158,6 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char
> *netdev,
>                 return -1;
>         }
>
> -       /* configure PACKET_FANOUT mode for socket (if mode enabled) */
> -       err = set_pkt_sock_fanout(pkt_sock, if_idx);
> -       if (err != 0)
> -               return -1;
> -
>         return sockfd;
>  }
>
> @@ -184,13 +174,11 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>
>         return 0;
>  }
> -#endif
>
> -#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC
>  /*
>   * ODP_PACKET_SOCKET_BASIC:
>   */
> -int recv_pkt_sock(pkt_sock_t *const pkt_sock,
> +int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
>                   odp_packet_t pkt_table[], unsigned len)
>  {
>         ssize_t recv_bytes;
> @@ -240,7 +228,7 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock,
>  /*
>   * ODP_PACKET_SOCKET_BASIC:
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock,
>                   odp_packet_t pkt_table[], unsigned len)
>  {
>         odp_packet_t pkt;
> @@ -281,11 +269,10 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>         return nb_tx;
>  }
>
> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG
>  /*
>   * ODP_PACKET_SOCKET_MMSG:
>   */
> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>                   odp_packet_t pkt_table[], unsigned len)
>  {
>         const int sockfd = pkt_sock->sockfd;
> @@ -348,7 +335,7 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>  /*
>   * ODP_PACKET_SOCKET_MMSG:
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>                   odp_packet_t pkt_table[], unsigned len)
>  {
>         struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX];
> @@ -387,7 +374,6 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>         return len;
>  }
>
> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> @@ -402,7 +388,7 @@ union frame_map {
>         void *raw;
>  };
>
> -static int pkt_socket(void)
> +static int mmap_pkt_socket(void)
>  {
>         int ver = TPACKET_V2;
>
> @@ -421,23 +407,23 @@ static int pkt_socket(void)
>         return sock;
>  }
>
> -static inline int rx_kernel_ready(struct tpacket2_hdr *hdr)
> +static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr)
>  {
>         return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
>  }
>
> -static inline void rx_user_ready(struct tpacket2_hdr *hdr)
> +static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr)
>  {
>         hdr->tp_status = TP_STATUS_KERNEL;
>         __sync_synchronize();
>  }
>
> -static inline int tx_kernel_ready(struct tpacket2_hdr *hdr)
> +static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr)
>  {
>         return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST |
> TP_STATUS_SENDING));
>  }
>
> -static inline void tx_user_ready(struct tpacket2_hdr *hdr)
> +static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr)
>  {
>         hdr->tp_status = TP_STATUS_SEND_REQUEST;
>         __sync_synchronize();
> @@ -462,7 +448,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct
> ring *ring,
>         frame_num = ring->frame_num;
>
>         while (i < len) {
> -               if (rx_kernel_ready(ring->rd[frame_num].iov_base)) {
> +               if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) {
>                         ppd.raw = ring->rd[frame_num].iov_base;
>
>                         next_frame_num = (frame_num + 1) % ring->rd_num;
> @@ -474,7 +460,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct
> ring *ring,
>                         eth_hdr = (struct ethhdr *)pkt_buf;
>                         if (odp_unlikely(ethaddrs_equal(if_mac,
>
> eth_hdr->h_source))) {
> -                               rx_user_ready(ppd.raw); /* drop */
> +                               mmap_rx_user_ready(ppd.raw); /* drop */
>                                 continue;
>                         }
>
> @@ -486,7 +472,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct
> ring *ring,
>                                  + frame_offset;
>                         memcpy(l2_hdr, pkt_buf, pkt_len);
>
> -                       rx_user_ready(ppd.raw);
> +                       mmap_rx_user_ready(ppd.raw);
>
>                         /* Parse and set packet header data */
>                         odp_packet_parse(pkt_table[i], pkt_len,
> frame_offset);
> @@ -516,7 +502,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct
> ring *ring,
>         frame_num = ring->frame_num;
>
>         while (i < len) {
> -               if (tx_kernel_ready(ring->rd[frame_num].iov_base)) {
> +               if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) {
>                         ppd.raw = ring->rd[frame_num].iov_base;
>
>                         next_frame_num = (frame_num + 1) % ring->rd_num;
> @@ -530,7 +516,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct
> ring *ring,
>                         memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN -
>                                sizeof(struct sockaddr_ll), pkt_buf,
> pkt_len);
>
> -                       tx_user_ready(ppd.raw);
> +                       mmap_tx_user_ready(ppd.raw);
>
>                         odp_packet_free(pkt_table[i]);
>                         frame_num = next_frame_num;
> @@ -553,7 +539,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct
> ring *ring,
>         return i;
>  }
>
> -static void fill_ring(struct ring *ring, unsigned blocks)
> +static void mmap_fill_ring(struct ring *ring, unsigned blocks)
>  {
>         ring->req.tp_block_size = getpagesize() << 2;
>         ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7;
> @@ -567,7 +553,7 @@ static void fill_ring(struct ring *ring, unsigned
> blocks)
>         ring->flen = ring->req.tp_frame_size;
>  }
>
> -static int set_packet_loss_discard(int sock)
> +static int mmap_set_packet_loss_discard(int sock)
>  {
>         int ret, discard = 1;
>
> @@ -581,7 +567,7 @@ static int set_packet_loss_discard(int sock)
>         return 0;
>  }
>
> -static int setup_ring(int sock, struct ring *ring, int type)
> +static int mmap_setup_ring(int sock, struct ring *ring, int type)
>  {
>         int ret = 0;
>         unsigned blocks = 256;
> @@ -591,12 +577,12 @@ static int setup_ring(int sock, struct ring *ring,
> int type)
>         ring->version = TPACKET_V2;
>
>         if (type == PACKET_TX_RING) {
> -               ret = set_packet_loss_discard(sock);
> +               ret = mmap_set_packet_loss_discard(sock);
>                 if (ret != 0)
>                         return -1;
>         }
>
> -       fill_ring(ring, blocks);
> +       mmap_fill_ring(ring, blocks);
>
>         ret = setsockopt(sock, SOL_PACKET, type, &ring->req,
> sizeof(ring->req));
>         if (ret == -1) {
> @@ -614,7 +600,7 @@ static int setup_ring(int sock, struct ring *ring, int
> type)
>         return 0;
>  }
>
> -static int mmap_sock(pkt_sock_t *pkt_sock)
> +static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
>  {
>         int i;
>         int sock = pkt_sock->sockfd;
> @@ -655,14 +641,14 @@ static int mmap_sock(pkt_sock_t *pkt_sock)
>         return 0;
>  }
>
> -static void unmap_sock(pkt_sock_t *pkt_sock)
> +static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock)
>  {
>         munmap(pkt_sock->mmap_base, pkt_sock->mmap_len);
>         free(pkt_sock->rx_ring.rd);
>         free(pkt_sock->tx_ring.rd);
>  }
>
> -static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
> +static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev)
>  {
>         int ret;
>
> @@ -684,7 +670,7 @@ static int bind_sock(pkt_sock_t *pkt_sock, char
> *netdev)
>         return 0;
>  }
>
> -static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
> +static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char
> *netdev)
>  {
>         struct ifreq ethreq;
>         int ret;
> @@ -707,7 +693,7 @@ static int store_hw_addr(pkt_sock_t * const pkt_sock,
> char *netdev)
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
>                    odp_buffer_pool_t pool)
>  {
>         odp_packet_t pkt;
> @@ -733,17 +719,19 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char
> *netdev,
>         odp_packet_free(pkt);
>
>         pkt_sock->pool = pool;
> -       pkt_sock->sockfd = pkt_socket();
> +       pkt_sock->sockfd = mmap_pkt_socket();
>
> -       ret = bind_sock(pkt_sock, netdev);
> +       ret = mmap_bind_sock(pkt_sock, netdev);
>         if (ret != 0)
>                 return -1;
>
> -       ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
> PACKET_TX_RING);
> +       ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
> +                       PACKET_TX_RING);
>         if (ret != 0)
>                 return -1;
>
> -       ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
> PACKET_RX_RING);
> +       ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
> +                       PACKET_RX_RING);
>         if (ret != 0)
>                 return -1;
>
> @@ -751,7 +739,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char
> *netdev,
>         if (ret != 0)
>                 return -1;
>
> -       ret = store_hw_addr(pkt_sock, netdev);
> +       ret = mmap_store_hw_addr(pkt_sock, netdev);
>         if (ret != 0)
>                 return -1;
>
> @@ -761,7 +749,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char
> *netdev,
>                 return -1;
>         }
>
> -       ret = set_pkt_sock_fanout(pkt_sock, if_idx);
> +       ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx);
>         if (ret != 0)
>                 return -1;
>
> @@ -771,9 +759,9 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char
> *netdev,
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int close_pkt_sock(pkt_sock_t * const pkt_sock)
> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock)
>  {
> -       unmap_sock(pkt_sock);
> +       mmap_unmap_sock(pkt_sock);
>         if (close(pkt_sock->sockfd) != 0) {
>                 perror("close_pkt_sock() - close(sockfd)");
>                 return -1;
> @@ -785,7 +773,7 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>                   odp_packet_t pkt_table[], unsigned len)
>  {
>         return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring,
> @@ -796,13 +784,9 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>                   odp_packet_t pkt_table[], unsigned len)
>  {
>         return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring,
>                               pkt_table, len);
>  }
> -
> -#else
> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> -#endif
> diff --git a/test/packet/odp_example_pktio.c
> b/test/packet/odp_example_pktio.c
> index 85bbdd7..d6c9cd4 100644
> --- a/test/packet/odp_example_pktio.c
> +++ b/test/packet/odp_example_pktio.c
> @@ -111,7 +111,7 @@ static void *pktio_queue_thread(void *arg)
>         }
>
>         /* Open a packet IO instance for this thread */
> -       sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> +       sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>         pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool,
> &params);
>         if (pktio == ODP_PKTIO_INVALID) {
>                 ODP_ERR("  [%02i] Error: pktio create failed\n", thr);
> @@ -223,7 +223,7 @@ static void *pktio_ifburst_thread(void *arg)
>         }
>
>         /* Open a packet IO instance for this thread */
> -       sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> +       sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>         pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool,
> &params);
>         if (pktio == ODP_PKTIO_INVALID) {
>                 ODP_ERR("  [%02i] Error: pktio create failed.\n", thr);
> --
> 1.8.5.1.163.gd7aced9
>
> --
> You received this message because you are subscribed to the Google Groups
> "LNG ODP Sub-team - lng-odp@linaro.org" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to lng-odp+unsubscribe@linaro.org.
> To post to this group, send email to lng-odp@linaro.org.
> Visit this group at http://groups.google.com/a/linaro.org/group/lng-odp/.
> To view this discussion on the web visit
> https://groups.google.com/a/linaro.org/d/msgid/lng-odp/1396012333-27985-1-git-send-email-maxim.uvarov%40linaro.org
> .
> For more options, visit https://groups.google.com/a/linaro.org/d/optout.
>
Anders Roxell March 28, 2014, 1:43 p.m. UTC | #2
On 2014-03-28 17:12, Maxim Uvarov wrote:
> Dynamically select type of packet I/O
> sock_params->type =
> 	ODP_PKTIO_TYPE_SOCKET_BASIC
> 	ODP_PKTIO_TYPE_SOCKET_MMSG
> 	ODP_PKTIO_TYPE_SOCKET_MMAP
> 	ODP_PKTIO_TYPE_NETMAP
> sock_params->fanout = 1;
> pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
> 
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  .../linux-generic/include/api/odp_pktio_types.h    |  6 +-
>  .../linux-generic/include/odp_packet_io_internal.h |  1 +
>  platform/linux-generic/include/odp_packet_socket.h | 56 +++++--------
>  platform/linux-generic/source/odp_packet_io.c      | 61 +++++++++++---
>  platform/linux-generic/source/odp_packet_socket.c  | 98 +++++++++-------------
>  test/packet/odp_example_pktio.c                    |  4 +-
>  6 files changed, 119 insertions(+), 107 deletions(-)
> 
> diff --git a/platform/linux-generic/include/api/odp_pktio_types.h b/platform/linux-generic/include/api/odp_pktio_types.h
> index e6b4cbf..c87bfc2 100644
> --- a/platform/linux-generic/include/api/odp_pktio_types.h
> +++ b/platform/linux-generic/include/api/odp_pktio_types.h
> @@ -17,9 +17,11 @@ extern "C" {
>   */
>  
>  typedef enum {
> -	ODP_PKTIO_TYPE_SOCKET = 0x01,
> +	ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1,
> +	ODP_PKTIO_TYPE_SOCKET_MMSG =  0x2,
> +	ODP_PKTIO_TYPE_SOCKET_MMAP =  0x3,
>  #ifdef ODP_HAVE_NETMAP
> -	ODP_PKTIO_TYPE_NETMAP = 0x02,
> +	ODP_PKTIO_TYPE_NETMAP =   0x4,
>  #endif

Remove the "#ifdef ODP_HAVE_NETMAP" and let the enum do the job of
incremeting the value.

Cheers,
Anders

>  } odp_pktio_type_t;
>  
> diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
> index ba1ee9b..3ab7fa0 100644
> --- a/platform/linux-generic/include/odp_packet_io_internal.h
> +++ b/platform/linux-generic/include/odp_packet_io_internal.h
> @@ -31,6 +31,7 @@ struct pktio_entry {
>  	odp_queue_t outq_default;	/**< default out queue */
>  	odp_pktio_params_t params;	/**< pktio parameters */
>  	pkt_sock_t pkt_sock;		/**< using socket API for IO */
> +	pkt_sock_mmap_t pkt_sock_mmap;	/**< using socket mmap API for IO */
>  #ifdef ODP_HAVE_NETMAP
>  	pkt_netmap_t pkt_nm;		/**< using netmap API for IO */
>  #endif
> diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h
> index fe216bb..98ceb98 100644
> --- a/platform/linux-generic/include/odp_packet_socket.h
> +++ b/platform/linux-generic/include/odp_packet_socket.h
> @@ -20,37 +20,15 @@
>  
>  #include <linux/version.h>
>  
> -
>  /*
>   * Packet socket config:
>   */
> -#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */
> -#define ODP_PACKET_SOCKET_MMSG  1 /** use recvmmsg()/sendmmsg() */
> -#define ODP_PACKET_SOCKET_MMAP  2 /** use PACKET_MMAP */
> -
> -
> -#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0)
> -/* PACKET_FANOUT feature not supported */
> -#define ODP_PACKET_SOCKET_FANOUT 0
> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC)
> -#else
> -/** PACKET_FANOUT mode spreads incoming packets over multiple sockets*/
> -#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */
> -/** Choose one from the alternatives above */
> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP)
> -#endif
> -
>  
>  /** Max receive (Rx) burst size*/
>  #define ODP_PACKET_SOCKET_MAX_BURST_RX 32
>  /** Max transmit (Tx) burst size*/
>  #define ODP_PACKET_SOCKET_MAX_BURST_TX 32
>  
> -
> -
> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> -	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
> -
>  typedef struct {
>  	int sockfd; /**< socket descriptor */
>  	odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */
> @@ -60,12 +38,6 @@ typedef struct {
>  	unsigned char if_mac[ETH_ALEN];	/**< IF eth mac addr */
>  } pkt_sock_t;
>  
> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
> -
> -#if ODP_PACKET_SOCKET_FANOUT == 0
> -#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1"
> -#endif
> -
>  /** packet mmap ring */
>  struct ring {
>  	struct iovec *rd;
> @@ -99,31 +71,45 @@ typedef struct {
>  	unsigned mmap_len;
>  	unsigned char if_mac[ETH_ALEN];
>  	struct sockaddr_ll ll;
> -} pkt_sock_t;
> -
> -#else
> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> -#endif
> +	int fanout; /**< 0: off 1: on */
> +} pkt_sock_mmap_t;
>  
>  /**
>   * Open & configure a raw packet socket
>   */
>  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>  		   odp_buffer_pool_t pool);
> +
> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
> +		   odp_buffer_pool_t pool);
> +
>  /**
>   * Close a packet socket
>   */
>  int close_pkt_sock(pkt_sock_t * const pkt_sock);
>  
> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock);
> +
>  /**
>   * Receive packets from the packet socket
>   */
> -int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> +int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>  		  unsigned len);
> +
> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> +		  unsigned len);
> +
> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> +		  odp_packet_t pkt_table[], unsigned len);
>  /**
>   * Send packets through the packet socket
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> +		  unsigned len);
> +
> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>  		  unsigned len);
>  
> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> +		  odp_packet_t pkt_table[], unsigned len);
>  #endif
> diff --git a/platform/linux-generic/source/odp_packet_io.c b/platform/linux-generic/source/odp_packet_io.c
> index 92aed34..ab80aef 100644
> --- a/platform/linux-generic/source/odp_packet_io.c
> +++ b/platform/linux-generic/source/odp_packet_io.c
> @@ -117,8 +117,12 @@ static void init_pktio_entry(pktio_entry_t *entry, odp_pktio_params_t *params)
>  	set_taken(entry);
>  	entry->s.inq_default = ODP_QUEUE_INVALID;
>  	switch (params->type) {
> -	case ODP_PKTIO_TYPE_SOCKET:
> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>  		memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock));
> +		memset(&entry->s.pkt_sock_mmap, 0,
> +		      sizeof(entry->s.pkt_sock_mmap));
>  		break;
>  #ifdef ODP_HAVE_NETMAP
>  	case ODP_PKTIO_TYPE_NETMAP:
> @@ -177,7 +181,9 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>  	}
>  
>  	switch (params->type) {
> -	case ODP_PKTIO_TYPE_SOCKET:
> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>  		ODP_DBG("Allocating socket pktio\n");
>  		break;
>  #ifdef ODP_HAVE_NETMAP
> @@ -200,7 +206,8 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>  	pktio_entry = get_entry(id);
>  
>  	switch (params->type) {
> -	case ODP_PKTIO_TYPE_SOCKET:
> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>  		res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool);
>  		if (res == -1) {
>  			close_pkt_sock(&pktio_entry->s.pkt_sock);
> @@ -208,10 +215,19 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>  			id = ODP_PKTIO_INVALID;
>  		}
>  		break;
> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +		res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, dev,
> +				pool);
> +		if (res == -1) {
> +			close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap);
> +			free_pktio_entry(id);
> +			id = ODP_PKTIO_INVALID;
> +		}
> +		break;
>  #ifdef ODP_HAVE_NETMAP
>  	case ODP_PKTIO_TYPE_NETMAP:
>  		res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev,
> -				       pool, &params->nm_params);
> +				pool, &params->nm_params);
>  		if (res == -1) {
>  			close_pkt_netmap(&pktio_entry->s.pkt_nm);
>  			free_pktio_entry(id);
> @@ -237,9 +253,13 @@ int odp_pktio_close(odp_pktio_t id)
>  	lock_entry(entry);
>  	if (!is_free(entry)) {
>  		switch (entry->s.params.type) {
> -		case ODP_PKTIO_TYPE_SOCKET:
> +		case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +		case ODP_PKTIO_TYPE_SOCKET_MMSG:
>  			res  = close_pkt_sock(&entry->s.pkt_sock);
>  			break;
> +		case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +			res  = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
> +			break;
>  #ifdef ODP_HAVE_NETMAP
>  		case ODP_PKTIO_TYPE_NETMAP:
>  			res  = close_pkt_netmap(&entry->s.pkt_nm);
> @@ -247,7 +267,7 @@ int odp_pktio_close(odp_pktio_t id)
>  #endif
>  		default:
>  			break;
> -		res |= free_pktio_entry(id);
> +			res |= free_pktio_entry(id);
>  		}
>  	}
>  	unlock_entry(entry);
> @@ -279,8 +299,17 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
>  
>  	lock_entry(pktio_entry);
>  	switch (pktio_entry->s.params.type) {
> -	case ODP_PKTIO_TYPE_SOCKET:
> -		pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +		pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> +				pkt_table, len);
> +		break;
> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +		pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> +				pkt_table, len);
> +		break;
> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +		pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> +				pkt_table, len);
>  		break;
>  #ifdef ODP_HAVE_NETMAP
>  	case ODP_PKTIO_TYPE_NETMAP:
> @@ -312,12 +341,22 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
>  
>  	lock_entry(pktio_entry);
>  	switch (pktio_entry->s.params.type) {
> -	case ODP_PKTIO_TYPE_SOCKET:
> -		pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> +		pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> +				pkt_table, len);
> +		break;
> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> +		pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> +				pkt_table, len);
> +		break;
> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> +		pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> +				pkt_table, len);
>  		break;
>  #ifdef ODP_HAVE_NETMAP
>  	case ODP_PKTIO_TYPE_NETMAP:
> -		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len);
> +		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
> +				pkt_table, len);
>  		break;
>  #endif
>  	default:
> diff --git a/platform/linux-generic/source/odp_packet_socket.c b/platform/linux-generic/source/odp_packet_socket.c
> index aaf2605..5f942dd 100644
> --- a/platform/linux-generic/source/odp_packet_socket.c
> +++ b/platform/linux-generic/source/odp_packet_socket.c
> @@ -63,15 +63,17 @@ static inline int ethaddrs_equal(unsigned char mac_a[], unsigned char mac_b[])
>  	return !memcmp(mac_a, mac_b, ETH_ALEN);
>  }
>  
> -static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
> +static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock,
> +		int sock_group_idx)
>  {
> -#if ODP_PACKET_SOCKET_FANOUT == 1
> -	/* Use FANOUT-mode for socket */
>  	int sockfd = pkt_sock->sockfd;
>  	int val;
>  	int err;
>  	uint16_t fanout_group;
>  
> +	if (!pkt_sock->fanout)
> +		return 0;
> +
>  	fanout_group = (uint16_t) (sock_group_idx & 0xffff);
>  	val = (PACKET_FANOUT_HASH << 16) | fanout_group;
>  
> @@ -80,16 +82,9 @@ static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
>  		perror("set_pkt_sock_fanout() - setsockopt(PACKET_FANOUT)");
>  		return -1;
>  	}
> -#else
> -	(void)pkt_sock;
> -	(void)sock_group_idx;
> -#endif
> -
>  	return 0;
>  }
>  
> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> -	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
>  /*
>   * ODP_PACKET_SOCKET_BASIC:
>   * ODP_PACKET_SOCKET_MMSG:
> @@ -163,11 +158,6 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>  		return -1;
>  	}
>  
> -	/* configure PACKET_FANOUT mode for socket (if mode enabled) */
> -	err = set_pkt_sock_fanout(pkt_sock, if_idx);
> -	if (err != 0)
> -		return -1;
> -
>  	return sockfd;
>  }
>  
> @@ -184,13 +174,11 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>  
>  	return 0;
>  }
> -#endif
>  
> -#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC
>  /*
>   * ODP_PACKET_SOCKET_BASIC:
>   */
> -int recv_pkt_sock(pkt_sock_t *const pkt_sock,
> +int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
>  		  odp_packet_t pkt_table[], unsigned len)
>  {
>  	ssize_t recv_bytes;
> @@ -240,7 +228,7 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock,
>  /*
>   * ODP_PACKET_SOCKET_BASIC:
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock,
>  		  odp_packet_t pkt_table[], unsigned len)
>  {
>  	odp_packet_t pkt;
> @@ -281,11 +269,10 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>  	return nb_tx;
>  }
>  
> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG
>  /*
>   * ODP_PACKET_SOCKET_MMSG:
>   */
> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>  		  odp_packet_t pkt_table[], unsigned len)
>  {
>  	const int sockfd = pkt_sock->sockfd;
> @@ -348,7 +335,7 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>  /*
>   * ODP_PACKET_SOCKET_MMSG:
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>  		  odp_packet_t pkt_table[], unsigned len)
>  {
>  	struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX];
> @@ -387,7 +374,6 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>  	return len;
>  }
>  
> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> @@ -402,7 +388,7 @@ union frame_map {
>  	void *raw;
>  };
>  
> -static int pkt_socket(void)
> +static int mmap_pkt_socket(void)
>  {
>  	int ver = TPACKET_V2;
>  
> @@ -421,23 +407,23 @@ static int pkt_socket(void)
>  	return sock;
>  }
>  
> -static inline int rx_kernel_ready(struct tpacket2_hdr *hdr)
> +static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr)
>  {
>  	return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
>  }
>  
> -static inline void rx_user_ready(struct tpacket2_hdr *hdr)
> +static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr)
>  {
>  	hdr->tp_status = TP_STATUS_KERNEL;
>  	__sync_synchronize();
>  }
>  
> -static inline int tx_kernel_ready(struct tpacket2_hdr *hdr)
> +static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr)
>  {
>  	return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING));
>  }
>  
> -static inline void tx_user_ready(struct tpacket2_hdr *hdr)
> +static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr)
>  {
>  	hdr->tp_status = TP_STATUS_SEND_REQUEST;
>  	__sync_synchronize();
> @@ -462,7 +448,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>  	frame_num = ring->frame_num;
>  
>  	while (i < len) {
> -		if (rx_kernel_ready(ring->rd[frame_num].iov_base)) {
> +		if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) {
>  			ppd.raw = ring->rd[frame_num].iov_base;
>  
>  			next_frame_num = (frame_num + 1) % ring->rd_num;
> @@ -474,7 +460,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>  			eth_hdr = (struct ethhdr *)pkt_buf;
>  			if (odp_unlikely(ethaddrs_equal(if_mac,
>  							eth_hdr->h_source))) {
> -				rx_user_ready(ppd.raw); /* drop */
> +				mmap_rx_user_ready(ppd.raw); /* drop */
>  				continue;
>  			}
>  
> @@ -486,7 +472,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>  				 + frame_offset;
>  			memcpy(l2_hdr, pkt_buf, pkt_len);
>  
> -			rx_user_ready(ppd.raw);
> +			mmap_rx_user_ready(ppd.raw);
>  
>  			/* Parse and set packet header data */
>  			odp_packet_parse(pkt_table[i], pkt_len, frame_offset);
> @@ -516,7 +502,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>  	frame_num = ring->frame_num;
>  
>  	while (i < len) {
> -		if (tx_kernel_ready(ring->rd[frame_num].iov_base)) {
> +		if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) {
>  			ppd.raw = ring->rd[frame_num].iov_base;
>  
>  			next_frame_num = (frame_num + 1) % ring->rd_num;
> @@ -530,7 +516,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>  			memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN -
>  			       sizeof(struct sockaddr_ll), pkt_buf, pkt_len);
>  
> -			tx_user_ready(ppd.raw);
> +			mmap_tx_user_ready(ppd.raw);
>  
>  			odp_packet_free(pkt_table[i]);
>  			frame_num = next_frame_num;
> @@ -553,7 +539,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>  	return i;
>  }
>  
> -static void fill_ring(struct ring *ring, unsigned blocks)
> +static void mmap_fill_ring(struct ring *ring, unsigned blocks)
>  {
>  	ring->req.tp_block_size = getpagesize() << 2;
>  	ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7;
> @@ -567,7 +553,7 @@ static void fill_ring(struct ring *ring, unsigned blocks)
>  	ring->flen = ring->req.tp_frame_size;
>  }
>  
> -static int set_packet_loss_discard(int sock)
> +static int mmap_set_packet_loss_discard(int sock)
>  {
>  	int ret, discard = 1;
>  
> @@ -581,7 +567,7 @@ static int set_packet_loss_discard(int sock)
>  	return 0;
>  }
>  
> -static int setup_ring(int sock, struct ring *ring, int type)
> +static int mmap_setup_ring(int sock, struct ring *ring, int type)
>  {
>  	int ret = 0;
>  	unsigned blocks = 256;
> @@ -591,12 +577,12 @@ static int setup_ring(int sock, struct ring *ring, int type)
>  	ring->version = TPACKET_V2;
>  
>  	if (type == PACKET_TX_RING) {
> -		ret = set_packet_loss_discard(sock);
> +		ret = mmap_set_packet_loss_discard(sock);
>  		if (ret != 0)
>  			return -1;
>  	}
>  
> -	fill_ring(ring, blocks);
> +	mmap_fill_ring(ring, blocks);
>  
>  	ret = setsockopt(sock, SOL_PACKET, type, &ring->req, sizeof(ring->req));
>  	if (ret == -1) {
> @@ -614,7 +600,7 @@ static int setup_ring(int sock, struct ring *ring, int type)
>  	return 0;
>  }
>  
> -static int mmap_sock(pkt_sock_t *pkt_sock)
> +static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
>  {
>  	int i;
>  	int sock = pkt_sock->sockfd;
> @@ -655,14 +641,14 @@ static int mmap_sock(pkt_sock_t *pkt_sock)
>  	return 0;
>  }
>  
> -static void unmap_sock(pkt_sock_t *pkt_sock)
> +static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock)
>  {
>  	munmap(pkt_sock->mmap_base, pkt_sock->mmap_len);
>  	free(pkt_sock->rx_ring.rd);
>  	free(pkt_sock->tx_ring.rd);
>  }
>  
> -static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
> +static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev)
>  {
>  	int ret;
>  
> @@ -684,7 +670,7 @@ static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
>  	return 0;
>  }
>  
> -static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
> +static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char *netdev)
>  {
>  	struct ifreq ethreq;
>  	int ret;
> @@ -707,7 +693,7 @@ static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
>  		   odp_buffer_pool_t pool)
>  {
>  	odp_packet_t pkt;
> @@ -733,17 +719,19 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>  	odp_packet_free(pkt);
>  
>  	pkt_sock->pool = pool;
> -	pkt_sock->sockfd = pkt_socket();
> +	pkt_sock->sockfd = mmap_pkt_socket();
>  
> -	ret = bind_sock(pkt_sock, netdev);
> +	ret = mmap_bind_sock(pkt_sock, netdev);
>  	if (ret != 0)
>  		return -1;
>  
> -	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring, PACKET_TX_RING);
> +	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
> +			PACKET_TX_RING);
>  	if (ret != 0)
>  		return -1;
>  
> -	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring, PACKET_RX_RING);
> +	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
> +			PACKET_RX_RING);
>  	if (ret != 0)
>  		return -1;
>  
> @@ -751,7 +739,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>  	if (ret != 0)
>  		return -1;
>  
> -	ret = store_hw_addr(pkt_sock, netdev);
> +	ret = mmap_store_hw_addr(pkt_sock, netdev);
>  	if (ret != 0)
>  		return -1;
>  
> @@ -761,7 +749,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>  		return -1;
>  	}
>  
> -	ret = set_pkt_sock_fanout(pkt_sock, if_idx);
> +	ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx);
>  	if (ret != 0)
>  		return -1;
>  
> @@ -771,9 +759,9 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int close_pkt_sock(pkt_sock_t * const pkt_sock)
> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock)
>  {
> -	unmap_sock(pkt_sock);
> +	mmap_unmap_sock(pkt_sock);
>  	if (close(pkt_sock->sockfd) != 0) {
>  		perror("close_pkt_sock() - close(sockfd)");
>  		return -1;
> @@ -785,7 +773,7 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>  		  odp_packet_t pkt_table[], unsigned len)
>  {
>  	return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring,
> @@ -796,13 +784,9 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>  /*
>   * ODP_PACKET_SOCKET_MMAP:
>   */
> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>  		  odp_packet_t pkt_table[], unsigned len)
>  {
>  	return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring,
>  			      pkt_table, len);
>  }
> -
> -#else
> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> -#endif
> diff --git a/test/packet/odp_example_pktio.c b/test/packet/odp_example_pktio.c
> index 85bbdd7..d6c9cd4 100644
> --- a/test/packet/odp_example_pktio.c
> +++ b/test/packet/odp_example_pktio.c
> @@ -111,7 +111,7 @@ static void *pktio_queue_thread(void *arg)
>  	}
>  
>  	/* Open a packet IO instance for this thread */
> -	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> +	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>  	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>  	if (pktio == ODP_PKTIO_INVALID) {
>  		ODP_ERR("  [%02i] Error: pktio create failed\n", thr);
> @@ -223,7 +223,7 @@ static void *pktio_ifburst_thread(void *arg)
>  	}
>  
>  	/* Open a packet IO instance for this thread */
> -	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> +	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>  	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>  	if (pktio == ODP_PKTIO_INVALID) {
>  		ODP_ERR("  [%02i] Error: pktio create failed.\n", thr);
> -- 
> 1.8.5.1.163.gd7aced9
> 
> -- 
> You received this message because you are subscribed to the Google Groups "LNG ODP Sub-team - lng-odp@linaro.org" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to lng-odp+unsubscribe@linaro.org.
> To post to this group, send email to lng-odp@linaro.org.
> Visit this group at http://groups.google.com/a/linaro.org/group/lng-odp/.
> To view this discussion on the web visit https://groups.google.com/a/linaro.org/d/msgid/lng-odp/1396012333-27985-1-git-send-email-maxim.uvarov%40linaro.org.
> For more options, visit https://groups.google.com/a/linaro.org/d/optout.
Maxim Uvarov March 28, 2014, 2:42 p.m. UTC | #3
On 03/28/2014 05:43 PM, Anders Roxell wrote:
> On 2014-03-28 17:12, Maxim Uvarov wrote:
>> Dynamically select type of packet I/O
>> sock_params->type =
>> 	ODP_PKTIO_TYPE_SOCKET_BASIC
>> 	ODP_PKTIO_TYPE_SOCKET_MMSG
>> 	ODP_PKTIO_TYPE_SOCKET_MMAP
>> 	ODP_PKTIO_TYPE_NETMAP
>> sock_params->fanout = 1;
>> pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>>
>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>> ---
>>   .../linux-generic/include/api/odp_pktio_types.h    |  6 +-
>>   .../linux-generic/include/odp_packet_io_internal.h |  1 +
>>   platform/linux-generic/include/odp_packet_socket.h | 56 +++++--------
>>   platform/linux-generic/source/odp_packet_io.c      | 61 +++++++++++---
>>   platform/linux-generic/source/odp_packet_socket.c  | 98 +++++++++-------------
>>   test/packet/odp_example_pktio.c                    |  4 +-
>>   6 files changed, 119 insertions(+), 107 deletions(-)
>>
>> diff --git a/platform/linux-generic/include/api/odp_pktio_types.h b/platform/linux-generic/include/api/odp_pktio_types.h
>> index e6b4cbf..c87bfc2 100644
>> --- a/platform/linux-generic/include/api/odp_pktio_types.h
>> +++ b/platform/linux-generic/include/api/odp_pktio_types.h
>> @@ -17,9 +17,11 @@ extern "C" {
>>    */
>>   
>>   typedef enum {
>> -	ODP_PKTIO_TYPE_SOCKET = 0x01,
>> +	ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1,
>> +	ODP_PKTIO_TYPE_SOCKET_MMSG =  0x2,
>> +	ODP_PKTIO_TYPE_SOCKET_MMAP =  0x3,
>>   #ifdef ODP_HAVE_NETMAP
>> -	ODP_PKTIO_TYPE_NETMAP = 0x02,
>> +	ODP_PKTIO_TYPE_NETMAP =   0x4,
>>   #endif
> Remove the "#ifdef ODP_HAVE_NETMAP" and let the enum do the job of
> incremeting the value.
>
> Cheers,
> Anders
NETMAP depends on netmap headers which maynot be installed.

Maxim.
>
>>   } odp_pktio_type_t;
>>   
>> diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
>> index ba1ee9b..3ab7fa0 100644
>> --- a/platform/linux-generic/include/odp_packet_io_internal.h
>> +++ b/platform/linux-generic/include/odp_packet_io_internal.h
>> @@ -31,6 +31,7 @@ struct pktio_entry {
>>   	odp_queue_t outq_default;	/**< default out queue */
>>   	odp_pktio_params_t params;	/**< pktio parameters */
>>   	pkt_sock_t pkt_sock;		/**< using socket API for IO */
>> +	pkt_sock_mmap_t pkt_sock_mmap;	/**< using socket mmap API for IO */
>>   #ifdef ODP_HAVE_NETMAP
>>   	pkt_netmap_t pkt_nm;		/**< using netmap API for IO */
>>   #endif
>> diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h
>> index fe216bb..98ceb98 100644
>> --- a/platform/linux-generic/include/odp_packet_socket.h
>> +++ b/platform/linux-generic/include/odp_packet_socket.h
>> @@ -20,37 +20,15 @@
>>   
>>   #include <linux/version.h>
>>   
>> -
>>   /*
>>    * Packet socket config:
>>    */
>> -#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */
>> -#define ODP_PACKET_SOCKET_MMSG  1 /** use recvmmsg()/sendmmsg() */
>> -#define ODP_PACKET_SOCKET_MMAP  2 /** use PACKET_MMAP */
>> -
>> -
>> -#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0)
>> -/* PACKET_FANOUT feature not supported */
>> -#define ODP_PACKET_SOCKET_FANOUT 0
>> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC)
>> -#else
>> -/** PACKET_FANOUT mode spreads incoming packets over multiple sockets*/
>> -#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */
>> -/** Choose one from the alternatives above */
>> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP)
>> -#endif
>> -
>>   
>>   /** Max receive (Rx) burst size*/
>>   #define ODP_PACKET_SOCKET_MAX_BURST_RX 32
>>   /** Max transmit (Tx) burst size*/
>>   #define ODP_PACKET_SOCKET_MAX_BURST_TX 32
>>   
>> -
>> -
>> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
>> -	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
>> -
>>   typedef struct {
>>   	int sockfd; /**< socket descriptor */
>>   	odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */
>> @@ -60,12 +38,6 @@ typedef struct {
>>   	unsigned char if_mac[ETH_ALEN];	/**< IF eth mac addr */
>>   } pkt_sock_t;
>>   
>> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
>> -
>> -#if ODP_PACKET_SOCKET_FANOUT == 0
>> -#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1"
>> -#endif
>> -
>>   /** packet mmap ring */
>>   struct ring {
>>   	struct iovec *rd;
>> @@ -99,31 +71,45 @@ typedef struct {
>>   	unsigned mmap_len;
>>   	unsigned char if_mac[ETH_ALEN];
>>   	struct sockaddr_ll ll;
>> -} pkt_sock_t;
>> -
>> -#else
>> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
>> -#endif
>> +	int fanout; /**< 0: off 1: on */
>> +} pkt_sock_mmap_t;
>>   
>>   /**
>>    * Open & configure a raw packet socket
>>    */
>>   int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>   		   odp_buffer_pool_t pool);
>> +
>> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
>> +		   odp_buffer_pool_t pool);
>> +
>>   /**
>>    * Close a packet socket
>>    */
>>   int close_pkt_sock(pkt_sock_t * const pkt_sock);
>>   
>> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock);
>> +
>>   /**
>>    * Receive packets from the packet socket
>>    */
>> -int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>> +int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>   		  unsigned len);
>> +
>> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>> +		  unsigned len);
>> +
>> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>> +		  odp_packet_t pkt_table[], unsigned len);
>>   /**
>>    * Send packets through the packet socket
>>    */
>> -int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>> +		  unsigned len);
>> +
>> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>   		  unsigned len);
>>   
>> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>> +		  odp_packet_t pkt_table[], unsigned len);
>>   #endif
>> diff --git a/platform/linux-generic/source/odp_packet_io.c b/platform/linux-generic/source/odp_packet_io.c
>> index 92aed34..ab80aef 100644
>> --- a/platform/linux-generic/source/odp_packet_io.c
>> +++ b/platform/linux-generic/source/odp_packet_io.c
>> @@ -117,8 +117,12 @@ static void init_pktio_entry(pktio_entry_t *entry, odp_pktio_params_t *params)
>>   	set_taken(entry);
>>   	entry->s.inq_default = ODP_QUEUE_INVALID;
>>   	switch (params->type) {
>> -	case ODP_PKTIO_TYPE_SOCKET:
>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>   		memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock));
>> +		memset(&entry->s.pkt_sock_mmap, 0,
>> +		      sizeof(entry->s.pkt_sock_mmap));
>>   		break;
>>   #ifdef ODP_HAVE_NETMAP
>>   	case ODP_PKTIO_TYPE_NETMAP:
>> @@ -177,7 +181,9 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>>   	}
>>   
>>   	switch (params->type) {
>> -	case ODP_PKTIO_TYPE_SOCKET:
>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>   		ODP_DBG("Allocating socket pktio\n");
>>   		break;
>>   #ifdef ODP_HAVE_NETMAP
>> @@ -200,7 +206,8 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>>   	pktio_entry = get_entry(id);
>>   
>>   	switch (params->type) {
>> -	case ODP_PKTIO_TYPE_SOCKET:
>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>   		res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool);
>>   		if (res == -1) {
>>   			close_pkt_sock(&pktio_entry->s.pkt_sock);
>> @@ -208,10 +215,19 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>>   			id = ODP_PKTIO_INVALID;
>>   		}
>>   		break;
>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>> +		res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, dev,
>> +				pool);
>> +		if (res == -1) {
>> +			close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap);
>> +			free_pktio_entry(id);
>> +			id = ODP_PKTIO_INVALID;
>> +		}
>> +		break;
>>   #ifdef ODP_HAVE_NETMAP
>>   	case ODP_PKTIO_TYPE_NETMAP:
>>   		res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev,
>> -				       pool, &params->nm_params);
>> +				pool, &params->nm_params);
>>   		if (res == -1) {
>>   			close_pkt_netmap(&pktio_entry->s.pkt_nm);
>>   			free_pktio_entry(id);
>> @@ -237,9 +253,13 @@ int odp_pktio_close(odp_pktio_t id)
>>   	lock_entry(entry);
>>   	if (!is_free(entry)) {
>>   		switch (entry->s.params.type) {
>> -		case ODP_PKTIO_TYPE_SOCKET:
>> +		case ODP_PKTIO_TYPE_SOCKET_BASIC:
>> +		case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>   			res  = close_pkt_sock(&entry->s.pkt_sock);
>>   			break;
>> +		case ODP_PKTIO_TYPE_SOCKET_MMAP:
>> +			res  = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
>> +			break;
>>   #ifdef ODP_HAVE_NETMAP
>>   		case ODP_PKTIO_TYPE_NETMAP:
>>   			res  = close_pkt_netmap(&entry->s.pkt_nm);
>> @@ -247,7 +267,7 @@ int odp_pktio_close(odp_pktio_t id)
>>   #endif
>>   		default:
>>   			break;
>> -		res |= free_pktio_entry(id);
>> +			res |= free_pktio_entry(id);
>>   		}
>>   	}
>>   	unlock_entry(entry);
>> @@ -279,8 +299,17 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
>>   
>>   	lock_entry(pktio_entry);
>>   	switch (pktio_entry->s.params.type) {
>> -	case ODP_PKTIO_TYPE_SOCKET:
>> -		pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>> +		pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
>> +				pkt_table, len);
>> +		break;
>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>> +		pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
>> +				pkt_table, len);
>> +		break;
>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>> +		pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
>> +				pkt_table, len);
>>   		break;
>>   #ifdef ODP_HAVE_NETMAP
>>   	case ODP_PKTIO_TYPE_NETMAP:
>> @@ -312,12 +341,22 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
>>   
>>   	lock_entry(pktio_entry);
>>   	switch (pktio_entry->s.params.type) {
>> -	case ODP_PKTIO_TYPE_SOCKET:
>> -		pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>> +		pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
>> +				pkt_table, len);
>> +		break;
>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>> +		pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
>> +				pkt_table, len);
>> +		break;
>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>> +		pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
>> +				pkt_table, len);
>>   		break;
>>   #ifdef ODP_HAVE_NETMAP
>>   	case ODP_PKTIO_TYPE_NETMAP:
>> -		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len);
>> +		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
>> +				pkt_table, len);
>>   		break;
>>   #endif
>>   	default:
>> diff --git a/platform/linux-generic/source/odp_packet_socket.c b/platform/linux-generic/source/odp_packet_socket.c
>> index aaf2605..5f942dd 100644
>> --- a/platform/linux-generic/source/odp_packet_socket.c
>> +++ b/platform/linux-generic/source/odp_packet_socket.c
>> @@ -63,15 +63,17 @@ static inline int ethaddrs_equal(unsigned char mac_a[], unsigned char mac_b[])
>>   	return !memcmp(mac_a, mac_b, ETH_ALEN);
>>   }
>>   
>> -static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
>> +static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock,
>> +		int sock_group_idx)
>>   {
>> -#if ODP_PACKET_SOCKET_FANOUT == 1
>> -	/* Use FANOUT-mode for socket */
>>   	int sockfd = pkt_sock->sockfd;
>>   	int val;
>>   	int err;
>>   	uint16_t fanout_group;
>>   
>> +	if (!pkt_sock->fanout)
>> +		return 0;
>> +
>>   	fanout_group = (uint16_t) (sock_group_idx & 0xffff);
>>   	val = (PACKET_FANOUT_HASH << 16) | fanout_group;
>>   
>> @@ -80,16 +82,9 @@ static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
>>   		perror("set_pkt_sock_fanout() - setsockopt(PACKET_FANOUT)");
>>   		return -1;
>>   	}
>> -#else
>> -	(void)pkt_sock;
>> -	(void)sock_group_idx;
>> -#endif
>> -
>>   	return 0;
>>   }
>>   
>> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
>> -	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
>>   /*
>>    * ODP_PACKET_SOCKET_BASIC:
>>    * ODP_PACKET_SOCKET_MMSG:
>> @@ -163,11 +158,6 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>   		return -1;
>>   	}
>>   
>> -	/* configure PACKET_FANOUT mode for socket (if mode enabled) */
>> -	err = set_pkt_sock_fanout(pkt_sock, if_idx);
>> -	if (err != 0)
>> -		return -1;
>> -
>>   	return sockfd;
>>   }
>>   
>> @@ -184,13 +174,11 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>>   
>>   	return 0;
>>   }
>> -#endif
>>   
>> -#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC
>>   /*
>>    * ODP_PACKET_SOCKET_BASIC:
>>    */
>> -int recv_pkt_sock(pkt_sock_t *const pkt_sock,
>> +int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
>>   		  odp_packet_t pkt_table[], unsigned len)
>>   {
>>   	ssize_t recv_bytes;
>> @@ -240,7 +228,7 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock,
>>   /*
>>    * ODP_PACKET_SOCKET_BASIC:
>>    */
>> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
>> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock,
>>   		  odp_packet_t pkt_table[], unsigned len)
>>   {
>>   	odp_packet_t pkt;
>> @@ -281,11 +269,10 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>>   	return nb_tx;
>>   }
>>   
>> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG
>>   /*
>>    * ODP_PACKET_SOCKET_MMSG:
>>    */
>> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>>   		  odp_packet_t pkt_table[], unsigned len)
>>   {
>>   	const int sockfd = pkt_sock->sockfd;
>> @@ -348,7 +335,7 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>>   /*
>>    * ODP_PACKET_SOCKET_MMSG:
>>    */
>> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
>> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>>   		  odp_packet_t pkt_table[], unsigned len)
>>   {
>>   	struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX];
>> @@ -387,7 +374,6 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>>   	return len;
>>   }
>>   
>> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
>>   /*
>>    * ODP_PACKET_SOCKET_MMAP:
>>    */
>> @@ -402,7 +388,7 @@ union frame_map {
>>   	void *raw;
>>   };
>>   
>> -static int pkt_socket(void)
>> +static int mmap_pkt_socket(void)
>>   {
>>   	int ver = TPACKET_V2;
>>   
>> @@ -421,23 +407,23 @@ static int pkt_socket(void)
>>   	return sock;
>>   }
>>   
>> -static inline int rx_kernel_ready(struct tpacket2_hdr *hdr)
>> +static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr)
>>   {
>>   	return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
>>   }
>>   
>> -static inline void rx_user_ready(struct tpacket2_hdr *hdr)
>> +static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr)
>>   {
>>   	hdr->tp_status = TP_STATUS_KERNEL;
>>   	__sync_synchronize();
>>   }
>>   
>> -static inline int tx_kernel_ready(struct tpacket2_hdr *hdr)
>> +static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr)
>>   {
>>   	return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING));
>>   }
>>   
>> -static inline void tx_user_ready(struct tpacket2_hdr *hdr)
>> +static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr)
>>   {
>>   	hdr->tp_status = TP_STATUS_SEND_REQUEST;
>>   	__sync_synchronize();
>> @@ -462,7 +448,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>>   	frame_num = ring->frame_num;
>>   
>>   	while (i < len) {
>> -		if (rx_kernel_ready(ring->rd[frame_num].iov_base)) {
>> +		if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) {
>>   			ppd.raw = ring->rd[frame_num].iov_base;
>>   
>>   			next_frame_num = (frame_num + 1) % ring->rd_num;
>> @@ -474,7 +460,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>>   			eth_hdr = (struct ethhdr *)pkt_buf;
>>   			if (odp_unlikely(ethaddrs_equal(if_mac,
>>   							eth_hdr->h_source))) {
>> -				rx_user_ready(ppd.raw); /* drop */
>> +				mmap_rx_user_ready(ppd.raw); /* drop */
>>   				continue;
>>   			}
>>   
>> @@ -486,7 +472,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>>   				 + frame_offset;
>>   			memcpy(l2_hdr, pkt_buf, pkt_len);
>>   
>> -			rx_user_ready(ppd.raw);
>> +			mmap_rx_user_ready(ppd.raw);
>>   
>>   			/* Parse and set packet header data */
>>   			odp_packet_parse(pkt_table[i], pkt_len, frame_offset);
>> @@ -516,7 +502,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>>   	frame_num = ring->frame_num;
>>   
>>   	while (i < len) {
>> -		if (tx_kernel_ready(ring->rd[frame_num].iov_base)) {
>> +		if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) {
>>   			ppd.raw = ring->rd[frame_num].iov_base;
>>   
>>   			next_frame_num = (frame_num + 1) % ring->rd_num;
>> @@ -530,7 +516,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>>   			memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN -
>>   			       sizeof(struct sockaddr_ll), pkt_buf, pkt_len);
>>   
>> -			tx_user_ready(ppd.raw);
>> +			mmap_tx_user_ready(ppd.raw);
>>   
>>   			odp_packet_free(pkt_table[i]);
>>   			frame_num = next_frame_num;
>> @@ -553,7 +539,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>>   	return i;
>>   }
>>   
>> -static void fill_ring(struct ring *ring, unsigned blocks)
>> +static void mmap_fill_ring(struct ring *ring, unsigned blocks)
>>   {
>>   	ring->req.tp_block_size = getpagesize() << 2;
>>   	ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7;
>> @@ -567,7 +553,7 @@ static void fill_ring(struct ring *ring, unsigned blocks)
>>   	ring->flen = ring->req.tp_frame_size;
>>   }
>>   
>> -static int set_packet_loss_discard(int sock)
>> +static int mmap_set_packet_loss_discard(int sock)
>>   {
>>   	int ret, discard = 1;
>>   
>> @@ -581,7 +567,7 @@ static int set_packet_loss_discard(int sock)
>>   	return 0;
>>   }
>>   
>> -static int setup_ring(int sock, struct ring *ring, int type)
>> +static int mmap_setup_ring(int sock, struct ring *ring, int type)
>>   {
>>   	int ret = 0;
>>   	unsigned blocks = 256;
>> @@ -591,12 +577,12 @@ static int setup_ring(int sock, struct ring *ring, int type)
>>   	ring->version = TPACKET_V2;
>>   
>>   	if (type == PACKET_TX_RING) {
>> -		ret = set_packet_loss_discard(sock);
>> +		ret = mmap_set_packet_loss_discard(sock);
>>   		if (ret != 0)
>>   			return -1;
>>   	}
>>   
>> -	fill_ring(ring, blocks);
>> +	mmap_fill_ring(ring, blocks);
>>   
>>   	ret = setsockopt(sock, SOL_PACKET, type, &ring->req, sizeof(ring->req));
>>   	if (ret == -1) {
>> @@ -614,7 +600,7 @@ static int setup_ring(int sock, struct ring *ring, int type)
>>   	return 0;
>>   }
>>   
>> -static int mmap_sock(pkt_sock_t *pkt_sock)
>> +static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
>>   {
>>   	int i;
>>   	int sock = pkt_sock->sockfd;
>> @@ -655,14 +641,14 @@ static int mmap_sock(pkt_sock_t *pkt_sock)
>>   	return 0;
>>   }
>>   
>> -static void unmap_sock(pkt_sock_t *pkt_sock)
>> +static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock)
>>   {
>>   	munmap(pkt_sock->mmap_base, pkt_sock->mmap_len);
>>   	free(pkt_sock->rx_ring.rd);
>>   	free(pkt_sock->tx_ring.rd);
>>   }
>>   
>> -static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
>> +static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev)
>>   {
>>   	int ret;
>>   
>> @@ -684,7 +670,7 @@ static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
>>   	return 0;
>>   }
>>   
>> -static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
>> +static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char *netdev)
>>   {
>>   	struct ifreq ethreq;
>>   	int ret;
>> @@ -707,7 +693,7 @@ static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
>>   /*
>>    * ODP_PACKET_SOCKET_MMAP:
>>    */
>> -int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
>>   		   odp_buffer_pool_t pool)
>>   {
>>   	odp_packet_t pkt;
>> @@ -733,17 +719,19 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>   	odp_packet_free(pkt);
>>   
>>   	pkt_sock->pool = pool;
>> -	pkt_sock->sockfd = pkt_socket();
>> +	pkt_sock->sockfd = mmap_pkt_socket();
>>   
>> -	ret = bind_sock(pkt_sock, netdev);
>> +	ret = mmap_bind_sock(pkt_sock, netdev);
>>   	if (ret != 0)
>>   		return -1;
>>   
>> -	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring, PACKET_TX_RING);
>> +	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
>> +			PACKET_TX_RING);
>>   	if (ret != 0)
>>   		return -1;
>>   
>> -	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring, PACKET_RX_RING);
>> +	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
>> +			PACKET_RX_RING);
>>   	if (ret != 0)
>>   		return -1;
>>   
>> @@ -751,7 +739,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>   	if (ret != 0)
>>   		return -1;
>>   
>> -	ret = store_hw_addr(pkt_sock, netdev);
>> +	ret = mmap_store_hw_addr(pkt_sock, netdev);
>>   	if (ret != 0)
>>   		return -1;
>>   
>> @@ -761,7 +749,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>   		return -1;
>>   	}
>>   
>> -	ret = set_pkt_sock_fanout(pkt_sock, if_idx);
>> +	ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx);
>>   	if (ret != 0)
>>   		return -1;
>>   
>> @@ -771,9 +759,9 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>   /*
>>    * ODP_PACKET_SOCKET_MMAP:
>>    */
>> -int close_pkt_sock(pkt_sock_t * const pkt_sock)
>> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock)
>>   {
>> -	unmap_sock(pkt_sock);
>> +	mmap_unmap_sock(pkt_sock);
>>   	if (close(pkt_sock->sockfd) != 0) {
>>   		perror("close_pkt_sock() - close(sockfd)");
>>   		return -1;
>> @@ -785,7 +773,7 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>>   /*
>>    * ODP_PACKET_SOCKET_MMAP:
>>    */
>> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>>   		  odp_packet_t pkt_table[], unsigned len)
>>   {
>>   	return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring,
>> @@ -796,13 +784,9 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>>   /*
>>    * ODP_PACKET_SOCKET_MMAP:
>>    */
>> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
>> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>>   		  odp_packet_t pkt_table[], unsigned len)
>>   {
>>   	return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring,
>>   			      pkt_table, len);
>>   }
>> -
>> -#else
>> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
>> -#endif
>> diff --git a/test/packet/odp_example_pktio.c b/test/packet/odp_example_pktio.c
>> index 85bbdd7..d6c9cd4 100644
>> --- a/test/packet/odp_example_pktio.c
>> +++ b/test/packet/odp_example_pktio.c
>> @@ -111,7 +111,7 @@ static void *pktio_queue_thread(void *arg)
>>   	}
>>   
>>   	/* Open a packet IO instance for this thread */
>> -	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
>> +	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>>   	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>>   	if (pktio == ODP_PKTIO_INVALID) {
>>   		ODP_ERR("  [%02i] Error: pktio create failed\n", thr);
>> @@ -223,7 +223,7 @@ static void *pktio_ifburst_thread(void *arg)
>>   	}
>>   
>>   	/* Open a packet IO instance for this thread */
>> -	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
>> +	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>>   	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>>   	if (pktio == ODP_PKTIO_INVALID) {
>>   		ODP_ERR("  [%02i] Error: pktio create failed.\n", thr);
>> -- 
>> 1.8.5.1.163.gd7aced9
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups "LNG ODP Sub-team - lng-odp@linaro.org" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to lng-odp+unsubscribe@linaro.org.
>> To post to this group, send email to lng-odp@linaro.org.
>> Visit this group at http://groups.google.com/a/linaro.org/group/lng-odp/.
>> To view this discussion on the web visit https://groups.google.com/a/linaro.org/d/msgid/lng-odp/1396012333-27985-1-git-send-email-maxim.uvarov%40linaro.org.
>> For more options, visit https://groups.google.com/a/linaro.org/d/optout.
Anders Roxell March 28, 2014, 2:51 p.m. UTC | #4
On 2014-03-28 18:42, Maxim Uvarov wrote:
> On 03/28/2014 05:43 PM, Anders Roxell wrote:
> >On 2014-03-28 17:12, Maxim Uvarov wrote:
> >>Dynamically select type of packet I/O
> >>sock_params->type =
> >>	ODP_PKTIO_TYPE_SOCKET_BASIC
> >>	ODP_PKTIO_TYPE_SOCKET_MMSG
> >>	ODP_PKTIO_TYPE_SOCKET_MMAP
> >>	ODP_PKTIO_TYPE_NETMAP
> >>sock_params->fanout = 1;
> >>pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
> >>
> >>Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> >>---
> >>  .../linux-generic/include/api/odp_pktio_types.h    |  6 +-
> >>  .../linux-generic/include/odp_packet_io_internal.h |  1 +
> >>  platform/linux-generic/include/odp_packet_socket.h | 56 +++++--------
> >>  platform/linux-generic/source/odp_packet_io.c      | 61 +++++++++++---
> >>  platform/linux-generic/source/odp_packet_socket.c  | 98 +++++++++-------------
> >>  test/packet/odp_example_pktio.c                    |  4 +-
> >>  6 files changed, 119 insertions(+), 107 deletions(-)
> >>
> >>diff --git a/platform/linux-generic/include/api/odp_pktio_types.h b/platform/linux-generic/include/api/odp_pktio_types.h
> >>index e6b4cbf..c87bfc2 100644
> >>--- a/platform/linux-generic/include/api/odp_pktio_types.h
> >>+++ b/platform/linux-generic/include/api/odp_pktio_types.h
> >>@@ -17,9 +17,11 @@ extern "C" {
> >>   */
> >>  typedef enum {
> >>-	ODP_PKTIO_TYPE_SOCKET = 0x01,
> >>+	ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1,
> >>+	ODP_PKTIO_TYPE_SOCKET_MMSG =  0x2,
> >>+	ODP_PKTIO_TYPE_SOCKET_MMAP =  0x3,
> >>  #ifdef ODP_HAVE_NETMAP
> >>-	ODP_PKTIO_TYPE_NETMAP = 0x02,
> >>+	ODP_PKTIO_TYPE_NETMAP =   0x4,
> >>  #endif
> >Remove the "#ifdef ODP_HAVE_NETMAP" and let the enum do the job of
> >incremeting the value.
> >
> >Cheers,
> >Anders
> NETMAP depends on netmap headers which maynot be installed.

I understand that
However, why do you need an ifdef inside an enum for if netmap isn't
installed?
we should never use ifdefs inside enums right?
and let the enum do the job of incrementing the values...

or what do I miss?

Cheers,
Anders

> 
> Maxim.
> >
> >>  } odp_pktio_type_t;
> >>diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
> >>index ba1ee9b..3ab7fa0 100644
> >>--- a/platform/linux-generic/include/odp_packet_io_internal.h
> >>+++ b/platform/linux-generic/include/odp_packet_io_internal.h
> >>@@ -31,6 +31,7 @@ struct pktio_entry {
> >>  	odp_queue_t outq_default;	/**< default out queue */
> >>  	odp_pktio_params_t params;	/**< pktio parameters */
> >>  	pkt_sock_t pkt_sock;		/**< using socket API for IO */
> >>+	pkt_sock_mmap_t pkt_sock_mmap;	/**< using socket mmap API for IO */
> >>  #ifdef ODP_HAVE_NETMAP
> >>  	pkt_netmap_t pkt_nm;		/**< using netmap API for IO */
> >>  #endif
> >>diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h
> >>index fe216bb..98ceb98 100644
> >>--- a/platform/linux-generic/include/odp_packet_socket.h
> >>+++ b/platform/linux-generic/include/odp_packet_socket.h
> >>@@ -20,37 +20,15 @@
> >>  #include <linux/version.h>
> >>-
> >>  /*
> >>   * Packet socket config:
> >>   */
> >>-#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */
> >>-#define ODP_PACKET_SOCKET_MMSG  1 /** use recvmmsg()/sendmmsg() */
> >>-#define ODP_PACKET_SOCKET_MMAP  2 /** use PACKET_MMAP */
> >>-
> >>-
> >>-#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0)
> >>-/* PACKET_FANOUT feature not supported */
> >>-#define ODP_PACKET_SOCKET_FANOUT 0
> >>-#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC)
> >>-#else
> >>-/** PACKET_FANOUT mode spreads incoming packets over multiple sockets*/
> >>-#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */
> >>-/** Choose one from the alternatives above */
> >>-#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP)
> >>-#endif
> >>-
> >>  /** Max receive (Rx) burst size*/
> >>  #define ODP_PACKET_SOCKET_MAX_BURST_RX 32
> >>  /** Max transmit (Tx) burst size*/
> >>  #define ODP_PACKET_SOCKET_MAX_BURST_TX 32
> >>-
> >>-
> >>-#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> >>-	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
> >>-
> >>  typedef struct {
> >>  	int sockfd; /**< socket descriptor */
> >>  	odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */
> >>@@ -60,12 +38,6 @@ typedef struct {
> >>  	unsigned char if_mac[ETH_ALEN];	/**< IF eth mac addr */
> >>  } pkt_sock_t;
> >>-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
> >>-
> >>-#if ODP_PACKET_SOCKET_FANOUT == 0
> >>-#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1"
> >>-#endif
> >>-
> >>  /** packet mmap ring */
> >>  struct ring {
> >>  	struct iovec *rd;
> >>@@ -99,31 +71,45 @@ typedef struct {
> >>  	unsigned mmap_len;
> >>  	unsigned char if_mac[ETH_ALEN];
> >>  	struct sockaddr_ll ll;
> >>-} pkt_sock_t;
> >>-
> >>-#else
> >>-#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> >>-#endif
> >>+	int fanout; /**< 0: off 1: on */
> >>+} pkt_sock_mmap_t;
> >>  /**
> >>   * Open & configure a raw packet socket
> >>   */
> >>  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> >>  		   odp_buffer_pool_t pool);
> >>+
> >>+int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
> >>+		   odp_buffer_pool_t pool);
> >>+
> >>  /**
> >>   * Close a packet socket
> >>   */
> >>  int close_pkt_sock(pkt_sock_t * const pkt_sock);
> >>+int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock);
> >>+
> >>  /**
> >>   * Receive packets from the packet socket
> >>   */
> >>-int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> >>+int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> >>  		  unsigned len);
> >>+
> >>+int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> >>+		  unsigned len);
> >>+
> >>+int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> >>+		  odp_packet_t pkt_table[], unsigned len);
> >>  /**
> >>   * Send packets through the packet socket
> >>   */
> >>-int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> >>+int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> >>+		  unsigned len);
> >>+
> >>+int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
> >>  		  unsigned len);
> >>+int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> >>+		  odp_packet_t pkt_table[], unsigned len);
> >>  #endif
> >>diff --git a/platform/linux-generic/source/odp_packet_io.c b/platform/linux-generic/source/odp_packet_io.c
> >>index 92aed34..ab80aef 100644
> >>--- a/platform/linux-generic/source/odp_packet_io.c
> >>+++ b/platform/linux-generic/source/odp_packet_io.c
> >>@@ -117,8 +117,12 @@ static void init_pktio_entry(pktio_entry_t *entry, odp_pktio_params_t *params)
> >>  	set_taken(entry);
> >>  	entry->s.inq_default = ODP_QUEUE_INVALID;
> >>  	switch (params->type) {
> >>-	case ODP_PKTIO_TYPE_SOCKET:
> >>+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> >>  		memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock));
> >>+		memset(&entry->s.pkt_sock_mmap, 0,
> >>+		      sizeof(entry->s.pkt_sock_mmap));
> >>  		break;
> >>  #ifdef ODP_HAVE_NETMAP
> >>  	case ODP_PKTIO_TYPE_NETMAP:
> >>@@ -177,7 +181,9 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
> >>  	}
> >>  	switch (params->type) {
> >>-	case ODP_PKTIO_TYPE_SOCKET:
> >>+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> >>  		ODP_DBG("Allocating socket pktio\n");
> >>  		break;
> >>  #ifdef ODP_HAVE_NETMAP
> >>@@ -200,7 +206,8 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
> >>  	pktio_entry = get_entry(id);
> >>  	switch (params->type) {
> >>-	case ODP_PKTIO_TYPE_SOCKET:
> >>+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> >>  		res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool);
> >>  		if (res == -1) {
> >>  			close_pkt_sock(&pktio_entry->s.pkt_sock);
> >>@@ -208,10 +215,19 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
> >>  			id = ODP_PKTIO_INVALID;
> >>  		}
> >>  		break;
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> >>+		res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, dev,
> >>+				pool);
> >>+		if (res == -1) {
> >>+			close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap);
> >>+			free_pktio_entry(id);
> >>+			id = ODP_PKTIO_INVALID;
> >>+		}
> >>+		break;
> >>  #ifdef ODP_HAVE_NETMAP
> >>  	case ODP_PKTIO_TYPE_NETMAP:
> >>  		res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev,
> >>-				       pool, &params->nm_params);
> >>+				pool, &params->nm_params);
> >>  		if (res == -1) {
> >>  			close_pkt_netmap(&pktio_entry->s.pkt_nm);
> >>  			free_pktio_entry(id);
> >>@@ -237,9 +253,13 @@ int odp_pktio_close(odp_pktio_t id)
> >>  	lock_entry(entry);
> >>  	if (!is_free(entry)) {
> >>  		switch (entry->s.params.type) {
> >>-		case ODP_PKTIO_TYPE_SOCKET:
> >>+		case ODP_PKTIO_TYPE_SOCKET_BASIC:
> >>+		case ODP_PKTIO_TYPE_SOCKET_MMSG:
> >>  			res  = close_pkt_sock(&entry->s.pkt_sock);
> >>  			break;
> >>+		case ODP_PKTIO_TYPE_SOCKET_MMAP:
> >>+			res  = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
> >>+			break;
> >>  #ifdef ODP_HAVE_NETMAP
> >>  		case ODP_PKTIO_TYPE_NETMAP:
> >>  			res  = close_pkt_netmap(&entry->s.pkt_nm);
> >>@@ -247,7 +267,7 @@ int odp_pktio_close(odp_pktio_t id)
> >>  #endif
> >>  		default:
> >>  			break;
> >>-		res |= free_pktio_entry(id);
> >>+			res |= free_pktio_entry(id);
> >>  		}
> >>  	}
> >>  	unlock_entry(entry);
> >>@@ -279,8 +299,17 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
> >>  	lock_entry(pktio_entry);
> >>  	switch (pktio_entry->s.params.type) {
> >>-	case ODP_PKTIO_TYPE_SOCKET:
> >>-		pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
> >>+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> >>+		pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> >>+				pkt_table, len);
> >>+		break;
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> >>+		pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> >>+				pkt_table, len);
> >>+		break;
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> >>+		pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> >>+				pkt_table, len);
> >>  		break;
> >>  #ifdef ODP_HAVE_NETMAP
> >>  	case ODP_PKTIO_TYPE_NETMAP:
> >>@@ -312,12 +341,22 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
> >>  	lock_entry(pktio_entry);
> >>  	switch (pktio_entry->s.params.type) {
> >>-	case ODP_PKTIO_TYPE_SOCKET:
> >>-		pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
> >>+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
> >>+		pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> >>+				pkt_table, len);
> >>+		break;
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
> >>+		pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> >>+				pkt_table, len);
> >>+		break;
> >>+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
> >>+		pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> >>+				pkt_table, len);
> >>  		break;
> >>  #ifdef ODP_HAVE_NETMAP
> >>  	case ODP_PKTIO_TYPE_NETMAP:
> >>-		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len);
> >>+		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
> >>+				pkt_table, len);
> >>  		break;
> >>  #endif
> >>  	default:
> >>diff --git a/platform/linux-generic/source/odp_packet_socket.c b/platform/linux-generic/source/odp_packet_socket.c
> >>index aaf2605..5f942dd 100644
> >>--- a/platform/linux-generic/source/odp_packet_socket.c
> >>+++ b/platform/linux-generic/source/odp_packet_socket.c
> >>@@ -63,15 +63,17 @@ static inline int ethaddrs_equal(unsigned char mac_a[], unsigned char mac_b[])
> >>  	return !memcmp(mac_a, mac_b, ETH_ALEN);
> >>  }
> >>-static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
> >>+static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock,
> >>+		int sock_group_idx)
> >>  {
> >>-#if ODP_PACKET_SOCKET_FANOUT == 1
> >>-	/* Use FANOUT-mode for socket */
> >>  	int sockfd = pkt_sock->sockfd;
> >>  	int val;
> >>  	int err;
> >>  	uint16_t fanout_group;
> >>+	if (!pkt_sock->fanout)
> >>+		return 0;
> >>+
> >>  	fanout_group = (uint16_t) (sock_group_idx & 0xffff);
> >>  	val = (PACKET_FANOUT_HASH << 16) | fanout_group;
> >>@@ -80,16 +82,9 @@ static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
> >>  		perror("set_pkt_sock_fanout() - setsockopt(PACKET_FANOUT)");
> >>  		return -1;
> >>  	}
> >>-#else
> >>-	(void)pkt_sock;
> >>-	(void)sock_group_idx;
> >>-#endif
> >>-
> >>  	return 0;
> >>  }
> >>-#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> >>-	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
> >>  /*
> >>   * ODP_PACKET_SOCKET_BASIC:
> >>   * ODP_PACKET_SOCKET_MMSG:
> >>@@ -163,11 +158,6 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> >>  		return -1;
> >>  	}
> >>-	/* configure PACKET_FANOUT mode for socket (if mode enabled) */
> >>-	err = set_pkt_sock_fanout(pkt_sock, if_idx);
> >>-	if (err != 0)
> >>-		return -1;
> >>-
> >>  	return sockfd;
> >>  }
> >>@@ -184,13 +174,11 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
> >>  	return 0;
> >>  }
> >>-#endif
> >>-#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC
> >>  /*
> >>   * ODP_PACKET_SOCKET_BASIC:
> >>   */
> >>-int recv_pkt_sock(pkt_sock_t *const pkt_sock,
> >>+int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
> >>  		  odp_packet_t pkt_table[], unsigned len)
> >>  {
> >>  	ssize_t recv_bytes;
> >>@@ -240,7 +228,7 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock,
> >>  /*
> >>   * ODP_PACKET_SOCKET_BASIC:
> >>   */
> >>-int send_pkt_sock(pkt_sock_t * const pkt_sock,
> >>+int send_pkt_sock_basic(pkt_sock_t * const pkt_sock,
> >>  		  odp_packet_t pkt_table[], unsigned len)
> >>  {
> >>  	odp_packet_t pkt;
> >>@@ -281,11 +269,10 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
> >>  	return nb_tx;
> >>  }
> >>-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG
> >>  /*
> >>   * ODP_PACKET_SOCKET_MMSG:
> >>   */
> >>-int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> >>+int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
> >>  		  odp_packet_t pkt_table[], unsigned len)
> >>  {
> >>  	const int sockfd = pkt_sock->sockfd;
> >>@@ -348,7 +335,7 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> >>  /*
> >>   * ODP_PACKET_SOCKET_MMSG:
> >>   */
> >>-int send_pkt_sock(pkt_sock_t * const pkt_sock,
> >>+int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
> >>  		  odp_packet_t pkt_table[], unsigned len)
> >>  {
> >>  	struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX];
> >>@@ -387,7 +374,6 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
> >>  	return len;
> >>  }
> >>-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
> >>  /*
> >>   * ODP_PACKET_SOCKET_MMAP:
> >>   */
> >>@@ -402,7 +388,7 @@ union frame_map {
> >>  	void *raw;
> >>  };
> >>-static int pkt_socket(void)
> >>+static int mmap_pkt_socket(void)
> >>  {
> >>  	int ver = TPACKET_V2;
> >>@@ -421,23 +407,23 @@ static int pkt_socket(void)
> >>  	return sock;
> >>  }
> >>-static inline int rx_kernel_ready(struct tpacket2_hdr *hdr)
> >>+static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr)
> >>  {
> >>  	return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
> >>  }
> >>-static inline void rx_user_ready(struct tpacket2_hdr *hdr)
> >>+static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr)
> >>  {
> >>  	hdr->tp_status = TP_STATUS_KERNEL;
> >>  	__sync_synchronize();
> >>  }
> >>-static inline int tx_kernel_ready(struct tpacket2_hdr *hdr)
> >>+static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr)
> >>  {
> >>  	return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING));
> >>  }
> >>-static inline void tx_user_ready(struct tpacket2_hdr *hdr)
> >>+static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr)
> >>  {
> >>  	hdr->tp_status = TP_STATUS_SEND_REQUEST;
> >>  	__sync_synchronize();
> >>@@ -462,7 +448,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
> >>  	frame_num = ring->frame_num;
> >>  	while (i < len) {
> >>-		if (rx_kernel_ready(ring->rd[frame_num].iov_base)) {
> >>+		if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) {
> >>  			ppd.raw = ring->rd[frame_num].iov_base;
> >>  			next_frame_num = (frame_num + 1) % ring->rd_num;
> >>@@ -474,7 +460,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
> >>  			eth_hdr = (struct ethhdr *)pkt_buf;
> >>  			if (odp_unlikely(ethaddrs_equal(if_mac,
> >>  							eth_hdr->h_source))) {
> >>-				rx_user_ready(ppd.raw); /* drop */
> >>+				mmap_rx_user_ready(ppd.raw); /* drop */
> >>  				continue;
> >>  			}
> >>@@ -486,7 +472,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
> >>  				 + frame_offset;
> >>  			memcpy(l2_hdr, pkt_buf, pkt_len);
> >>-			rx_user_ready(ppd.raw);
> >>+			mmap_rx_user_ready(ppd.raw);
> >>  			/* Parse and set packet header data */
> >>  			odp_packet_parse(pkt_table[i], pkt_len, frame_offset);
> >>@@ -516,7 +502,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
> >>  	frame_num = ring->frame_num;
> >>  	while (i < len) {
> >>-		if (tx_kernel_ready(ring->rd[frame_num].iov_base)) {
> >>+		if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) {
> >>  			ppd.raw = ring->rd[frame_num].iov_base;
> >>  			next_frame_num = (frame_num + 1) % ring->rd_num;
> >>@@ -530,7 +516,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
> >>  			memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN -
> >>  			       sizeof(struct sockaddr_ll), pkt_buf, pkt_len);
> >>-			tx_user_ready(ppd.raw);
> >>+			mmap_tx_user_ready(ppd.raw);
> >>  			odp_packet_free(pkt_table[i]);
> >>  			frame_num = next_frame_num;
> >>@@ -553,7 +539,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
> >>  	return i;
> >>  }
> >>-static void fill_ring(struct ring *ring, unsigned blocks)
> >>+static void mmap_fill_ring(struct ring *ring, unsigned blocks)
> >>  {
> >>  	ring->req.tp_block_size = getpagesize() << 2;
> >>  	ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7;
> >>@@ -567,7 +553,7 @@ static void fill_ring(struct ring *ring, unsigned blocks)
> >>  	ring->flen = ring->req.tp_frame_size;
> >>  }
> >>-static int set_packet_loss_discard(int sock)
> >>+static int mmap_set_packet_loss_discard(int sock)
> >>  {
> >>  	int ret, discard = 1;
> >>@@ -581,7 +567,7 @@ static int set_packet_loss_discard(int sock)
> >>  	return 0;
> >>  }
> >>-static int setup_ring(int sock, struct ring *ring, int type)
> >>+static int mmap_setup_ring(int sock, struct ring *ring, int type)
> >>  {
> >>  	int ret = 0;
> >>  	unsigned blocks = 256;
> >>@@ -591,12 +577,12 @@ static int setup_ring(int sock, struct ring *ring, int type)
> >>  	ring->version = TPACKET_V2;
> >>  	if (type == PACKET_TX_RING) {
> >>-		ret = set_packet_loss_discard(sock);
> >>+		ret = mmap_set_packet_loss_discard(sock);
> >>  		if (ret != 0)
> >>  			return -1;
> >>  	}
> >>-	fill_ring(ring, blocks);
> >>+	mmap_fill_ring(ring, blocks);
> >>  	ret = setsockopt(sock, SOL_PACKET, type, &ring->req, sizeof(ring->req));
> >>  	if (ret == -1) {
> >>@@ -614,7 +600,7 @@ static int setup_ring(int sock, struct ring *ring, int type)
> >>  	return 0;
> >>  }
> >>-static int mmap_sock(pkt_sock_t *pkt_sock)
> >>+static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
> >>  {
> >>  	int i;
> >>  	int sock = pkt_sock->sockfd;
> >>@@ -655,14 +641,14 @@ static int mmap_sock(pkt_sock_t *pkt_sock)
> >>  	return 0;
> >>  }
> >>-static void unmap_sock(pkt_sock_t *pkt_sock)
> >>+static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock)
> >>  {
> >>  	munmap(pkt_sock->mmap_base, pkt_sock->mmap_len);
> >>  	free(pkt_sock->rx_ring.rd);
> >>  	free(pkt_sock->tx_ring.rd);
> >>  }
> >>-static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
> >>+static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev)
> >>  {
> >>  	int ret;
> >>@@ -684,7 +670,7 @@ static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
> >>  	return 0;
> >>  }
> >>-static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
> >>+static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char *netdev)
> >>  {
> >>  	struct ifreq ethreq;
> >>  	int ret;
> >>@@ -707,7 +693,7 @@ static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
> >>  /*
> >>   * ODP_PACKET_SOCKET_MMAP:
> >>   */
> >>-int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> >>+int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
> >>  		   odp_buffer_pool_t pool)
> >>  {
> >>  	odp_packet_t pkt;
> >>@@ -733,17 +719,19 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> >>  	odp_packet_free(pkt);
> >>  	pkt_sock->pool = pool;
> >>-	pkt_sock->sockfd = pkt_socket();
> >>+	pkt_sock->sockfd = mmap_pkt_socket();
> >>-	ret = bind_sock(pkt_sock, netdev);
> >>+	ret = mmap_bind_sock(pkt_sock, netdev);
> >>  	if (ret != 0)
> >>  		return -1;
> >>-	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring, PACKET_TX_RING);
> >>+	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
> >>+			PACKET_TX_RING);
> >>  	if (ret != 0)
> >>  		return -1;
> >>-	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring, PACKET_RX_RING);
> >>+	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
> >>+			PACKET_RX_RING);
> >>  	if (ret != 0)
> >>  		return -1;
> >>@@ -751,7 +739,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> >>  	if (ret != 0)
> >>  		return -1;
> >>-	ret = store_hw_addr(pkt_sock, netdev);
> >>+	ret = mmap_store_hw_addr(pkt_sock, netdev);
> >>  	if (ret != 0)
> >>  		return -1;
> >>@@ -761,7 +749,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> >>  		return -1;
> >>  	}
> >>-	ret = set_pkt_sock_fanout(pkt_sock, if_idx);
> >>+	ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx);
> >>  	if (ret != 0)
> >>  		return -1;
> >>@@ -771,9 +759,9 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> >>  /*
> >>   * ODP_PACKET_SOCKET_MMAP:
> >>   */
> >>-int close_pkt_sock(pkt_sock_t * const pkt_sock)
> >>+int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock)
> >>  {
> >>-	unmap_sock(pkt_sock);
> >>+	mmap_unmap_sock(pkt_sock);
> >>  	if (close(pkt_sock->sockfd) != 0) {
> >>  		perror("close_pkt_sock() - close(sockfd)");
> >>  		return -1;
> >>@@ -785,7 +773,7 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
> >>  /*
> >>   * ODP_PACKET_SOCKET_MMAP:
> >>   */
> >>-int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> >>+int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> >>  		  odp_packet_t pkt_table[], unsigned len)
> >>  {
> >>  	return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring,
> >>@@ -796,13 +784,9 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> >>  /*
> >>   * ODP_PACKET_SOCKET_MMAP:
> >>   */
> >>-int send_pkt_sock(pkt_sock_t * const pkt_sock,
> >>+int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> >>  		  odp_packet_t pkt_table[], unsigned len)
> >>  {
> >>  	return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring,
> >>  			      pkt_table, len);
> >>  }
> >>-
> >>-#else
> >>-#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> >>-#endif
> >>diff --git a/test/packet/odp_example_pktio.c b/test/packet/odp_example_pktio.c
> >>index 85bbdd7..d6c9cd4 100644
> >>--- a/test/packet/odp_example_pktio.c
> >>+++ b/test/packet/odp_example_pktio.c
> >>@@ -111,7 +111,7 @@ static void *pktio_queue_thread(void *arg)
> >>  	}
> >>  	/* Open a packet IO instance for this thread */
> >>-	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> >>+	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
> >>  	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
> >>  	if (pktio == ODP_PKTIO_INVALID) {
> >>  		ODP_ERR("  [%02i] Error: pktio create failed\n", thr);
> >>@@ -223,7 +223,7 @@ static void *pktio_ifburst_thread(void *arg)
> >>  	}
> >>  	/* Open a packet IO instance for this thread */
> >>-	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> >>+	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
> >>  	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
> >>  	if (pktio == ODP_PKTIO_INVALID) {
> >>  		ODP_ERR("  [%02i] Error: pktio create failed.\n", thr);
> >>-- 
> >>1.8.5.1.163.gd7aced9
> >>
> >>-- 
> >>You received this message because you are subscribed to the Google Groups "LNG ODP Sub-team - lng-odp@linaro.org" group.
> >>To unsubscribe from this group and stop receiving emails from it, send an email to lng-odp+unsubscribe@linaro.org.
> >>To post to this group, send email to lng-odp@linaro.org.
> >>Visit this group at http://groups.google.com/a/linaro.org/group/lng-odp/.
> >>To view this discussion on the web visit https://groups.google.com/a/linaro.org/d/msgid/lng-odp/1396012333-27985-1-git-send-email-maxim.uvarov%40linaro.org.
> >>For more options, visit https://groups.google.com/a/linaro.org/d/optout.
>
Mike Holmes March 28, 2014, 2:55 p.m. UTC | #5
I think the argument is that the API's interface should always remain the
same,  even if a given implementation has feature missing.
The SW should fail gracefully if a netmap feature is used and it is
unavailable.


On 28 March 2014 10:51, Anders Roxell <anders.roxell@linaro.org> wrote:

> On 2014-03-28 18:42, Maxim Uvarov wrote:
> > On 03/28/2014 05:43 PM, Anders Roxell wrote:
> > >On 2014-03-28 17:12, Maxim Uvarov wrote:
> > >>Dynamically select type of packet I/O
> > >>sock_params->type =
> > >>    ODP_PKTIO_TYPE_SOCKET_BASIC
> > >>    ODP_PKTIO_TYPE_SOCKET_MMSG
> > >>    ODP_PKTIO_TYPE_SOCKET_MMAP
> > >>    ODP_PKTIO_TYPE_NETMAP
> > >>sock_params->fanout = 1;
> > >>pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
> > >>
> > >>Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> > >>---
> > >>  .../linux-generic/include/api/odp_pktio_types.h    |  6 +-
> > >>  .../linux-generic/include/odp_packet_io_internal.h |  1 +
> > >>  platform/linux-generic/include/odp_packet_socket.h | 56 +++++--------
> > >>  platform/linux-generic/source/odp_packet_io.c      | 61
> +++++++++++---
> > >>  platform/linux-generic/source/odp_packet_socket.c  | 98
> +++++++++-------------
> > >>  test/packet/odp_example_pktio.c                    |  4 +-
> > >>  6 files changed, 119 insertions(+), 107 deletions(-)
> > >>
> > >>diff --git a/platform/linux-generic/include/api/odp_pktio_types.h
> b/platform/linux-generic/include/api/odp_pktio_types.h
> > >>index e6b4cbf..c87bfc2 100644
> > >>--- a/platform/linux-generic/include/api/odp_pktio_types.h
> > >>+++ b/platform/linux-generic/include/api/odp_pktio_types.h
> > >>@@ -17,9 +17,11 @@ extern "C" {
> > >>   */
> > >>  typedef enum {
> > >>-   ODP_PKTIO_TYPE_SOCKET = 0x01,
> > >>+   ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1,
> > >>+   ODP_PKTIO_TYPE_SOCKET_MMSG =  0x2,
> > >>+   ODP_PKTIO_TYPE_SOCKET_MMAP =  0x3,
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>-   ODP_PKTIO_TYPE_NETMAP = 0x02,
> > >>+   ODP_PKTIO_TYPE_NETMAP =   0x4,
> > >>  #endif
> > >Remove the "#ifdef ODP_HAVE_NETMAP" and let the enum do the job of
> > >incremeting the value.
> > >
> > >Cheers,
> > >Anders
> > NETMAP depends on netmap headers which maynot be installed.
>
> I understand that
> However, why do you need an ifdef inside an enum for if netmap isn't
> installed?
> we should never use ifdefs inside enums right?
> and let the enum do the job of incrementing the values...
>
> or what do I miss?
>
> Cheers,
> Anders
>
> >
> > Maxim.
> > >
> > >>  } odp_pktio_type_t;
> > >>diff --git a/platform/linux-generic/include/odp_packet_io_internal.h
> b/platform/linux-generic/include/odp_packet_io_internal.h
> > >>index ba1ee9b..3ab7fa0 100644
> > >>--- a/platform/linux-generic/include/odp_packet_io_internal.h
> > >>+++ b/platform/linux-generic/include/odp_packet_io_internal.h
> > >>@@ -31,6 +31,7 @@ struct pktio_entry {
> > >>    odp_queue_t outq_default;       /**< default out queue */
> > >>    odp_pktio_params_t params;      /**< pktio parameters */
> > >>    pkt_sock_t pkt_sock;            /**< using socket API for IO */
> > >>+   pkt_sock_mmap_t pkt_sock_mmap;  /**< using socket mmap API for IO
> */
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>    pkt_netmap_t pkt_nm;            /**< using netmap API for IO */
> > >>  #endif
> > >>diff --git a/platform/linux-generic/include/odp_packet_socket.h
> b/platform/linux-generic/include/odp_packet_socket.h
> > >>index fe216bb..98ceb98 100644
> > >>--- a/platform/linux-generic/include/odp_packet_socket.h
> > >>+++ b/platform/linux-generic/include/odp_packet_socket.h
> > >>@@ -20,37 +20,15 @@
> > >>  #include <linux/version.h>
> > >>-
> > >>  /*
> > >>   * Packet socket config:
> > >>   */
> > >>-#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */
> > >>-#define ODP_PACKET_SOCKET_MMSG  1 /** use recvmmsg()/sendmmsg() */
> > >>-#define ODP_PACKET_SOCKET_MMAP  2 /** use PACKET_MMAP */
> > >>-
> > >>-
> > >>-#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0)
> > >>-/* PACKET_FANOUT feature not supported */
> > >>-#define ODP_PACKET_SOCKET_FANOUT 0
> > >>-#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC)
> > >>-#else
> > >>-/** PACKET_FANOUT mode spreads incoming packets over multiple
> sockets*/
> > >>-#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */
> > >>-/** Choose one from the alternatives above */
> > >>-#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP)
> > >>-#endif
> > >>-
> > >>  /** Max receive (Rx) burst size*/
> > >>  #define ODP_PACKET_SOCKET_MAX_BURST_RX 32
> > >>  /** Max transmit (Tx) burst size*/
> > >>  #define ODP_PACKET_SOCKET_MAX_BURST_TX 32
> > >>-
> > >>-
> > >>-#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> > >>-   (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
> > >>-
> > >>  typedef struct {
> > >>    int sockfd; /**< socket descriptor */
> > >>    odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */
> > >>@@ -60,12 +38,6 @@ typedef struct {
> > >>    unsigned char if_mac[ETH_ALEN]; /**< IF eth mac addr */
> > >>  } pkt_sock_t;
> > >>-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
> > >>-
> > >>-#if ODP_PACKET_SOCKET_FANOUT == 0
> > >>-#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1"
> > >>-#endif
> > >>-
> > >>  /** packet mmap ring */
> > >>  struct ring {
> > >>    struct iovec *rd;
> > >>@@ -99,31 +71,45 @@ typedef struct {
> > >>    unsigned mmap_len;
> > >>    unsigned char if_mac[ETH_ALEN];
> > >>    struct sockaddr_ll ll;
> > >>-} pkt_sock_t;
> > >>-
> > >>-#else
> > >>-#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> > >>-#endif
> > >>+   int fanout; /**< 0: off 1: on */
> > >>+} pkt_sock_mmap_t;
> > >>  /**
> > >>   * Open & configure a raw packet socket
> > >>   */
> > >>  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> > >>               odp_buffer_pool_t pool);
> > >>+
> > >>+int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char
> *netdev,
> > >>+              odp_buffer_pool_t pool);
> > >>+
> > >>  /**
> > >>   * Close a packet socket
> > >>   */
> > >>  int close_pkt_sock(pkt_sock_t * const pkt_sock);
> > >>+int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock);
> > >>+
> > >>  /**
> > >>   * Receive packets from the packet socket
> > >>   */
> > >>-int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> > >>+int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> > >>              unsigned len);
> > >>+
> > >>+int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> > >>+             unsigned len);
> > >>+
> > >>+int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> > >>+             odp_packet_t pkt_table[], unsigned len);
> > >>  /**
> > >>   * Send packets through the packet socket
> > >>   */
> > >>-int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> > >>+int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> > >>+             unsigned len);
> > >>+
> > >>+int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t
> pkt_table[],
> > >>              unsigned len);
> > >>+int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> > >>+             odp_packet_t pkt_table[], unsigned len);
> > >>  #endif
> > >>diff --git a/platform/linux-generic/source/odp_packet_io.c
> b/platform/linux-generic/source/odp_packet_io.c
> > >>index 92aed34..ab80aef 100644
> > >>--- a/platform/linux-generic/source/odp_packet_io.c
> > >>+++ b/platform/linux-generic/source/odp_packet_io.c
> > >>@@ -117,8 +117,12 @@ static void init_pktio_entry(pktio_entry_t
> *entry, odp_pktio_params_t *params)
> > >>    set_taken(entry);
> > >>    entry->s.inq_default = ODP_QUEUE_INVALID;
> > >>    switch (params->type) {
> > >>-   case ODP_PKTIO_TYPE_SOCKET:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_BASIC:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMSG:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMAP:
> > >>            memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock));
> > >>+           memset(&entry->s.pkt_sock_mmap, 0,
> > >>+                 sizeof(entry->s.pkt_sock_mmap));
> > >>            break;
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>    case ODP_PKTIO_TYPE_NETMAP:
> > >>@@ -177,7 +181,9 @@ odp_pktio_t odp_pktio_open(char *dev,
> odp_buffer_pool_t pool,
> > >>    }
> > >>    switch (params->type) {
> > >>-   case ODP_PKTIO_TYPE_SOCKET:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_BASIC:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMSG:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMAP:
> > >>            ODP_DBG("Allocating socket pktio\n");
> > >>            break;
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>@@ -200,7 +206,8 @@ odp_pktio_t odp_pktio_open(char *dev,
> odp_buffer_pool_t pool,
> > >>    pktio_entry = get_entry(id);
> > >>    switch (params->type) {
> > >>-   case ODP_PKTIO_TYPE_SOCKET:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_BASIC:
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMSG:
> > >>            res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool);
> > >>            if (res == -1) {
> > >>                    close_pkt_sock(&pktio_entry->s.pkt_sock);
> > >>@@ -208,10 +215,19 @@ odp_pktio_t odp_pktio_open(char *dev,
> odp_buffer_pool_t pool,
> > >>                    id = ODP_PKTIO_INVALID;
> > >>            }
> > >>            break;
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMAP:
> > >>+           res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> dev,
> > >>+                           pool);
> > >>+           if (res == -1) {
> > >>+                   close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap);
> > >>+                   free_pktio_entry(id);
> > >>+                   id = ODP_PKTIO_INVALID;
> > >>+           }
> > >>+           break;
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>    case ODP_PKTIO_TYPE_NETMAP:
> > >>            res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev,
> > >>-                                  pool, &params->nm_params);
> > >>+                           pool, &params->nm_params);
> > >>            if (res == -1) {
> > >>                    close_pkt_netmap(&pktio_entry->s.pkt_nm);
> > >>                    free_pktio_entry(id);
> > >>@@ -237,9 +253,13 @@ int odp_pktio_close(odp_pktio_t id)
> > >>    lock_entry(entry);
> > >>    if (!is_free(entry)) {
> > >>            switch (entry->s.params.type) {
> > >>-           case ODP_PKTIO_TYPE_SOCKET:
> > >>+           case ODP_PKTIO_TYPE_SOCKET_BASIC:
> > >>+           case ODP_PKTIO_TYPE_SOCKET_MMSG:
> > >>                    res  = close_pkt_sock(&entry->s.pkt_sock);
> > >>                    break;
> > >>+           case ODP_PKTIO_TYPE_SOCKET_MMAP:
> > >>+                   res  =
> close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
> > >>+                   break;
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>            case ODP_PKTIO_TYPE_NETMAP:
> > >>                    res  = close_pkt_netmap(&entry->s.pkt_nm);
> > >>@@ -247,7 +267,7 @@ int odp_pktio_close(odp_pktio_t id)
> > >>  #endif
> > >>            default:
> > >>                    break;
> > >>-           res |= free_pktio_entry(id);
> > >>+                   res |= free_pktio_entry(id);
> > >>            }
> > >>    }
> > >>    unlock_entry(entry);
> > >>@@ -279,8 +299,17 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
> > >>    lock_entry(pktio_entry);
> > >>    switch (pktio_entry->s.params.type) {
> > >>-   case ODP_PKTIO_TYPE_SOCKET:
> > >>-           pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table,
> len);
> > >>+   case ODP_PKTIO_TYPE_SOCKET_BASIC:
> > >>+           pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> > >>+                           pkt_table, len);
> > >>+           break;
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMSG:
> > >>+           pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> > >>+                           pkt_table, len);
> > >>+           break;
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMAP:
> > >>+           pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> > >>+                           pkt_table, len);
> > >>            break;
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>    case ODP_PKTIO_TYPE_NETMAP:
> > >>@@ -312,12 +341,22 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t
> pkt_table[], unsigned len)
> > >>    lock_entry(pktio_entry);
> > >>    switch (pktio_entry->s.params.type) {
> > >>-   case ODP_PKTIO_TYPE_SOCKET:
> > >>-           pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table,
> len);
> > >>+   case ODP_PKTIO_TYPE_SOCKET_BASIC:
> > >>+           pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
> > >>+                           pkt_table, len);
> > >>+           break;
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMSG:
> > >>+           pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
> > >>+                           pkt_table, len);
> > >>+           break;
> > >>+   case ODP_PKTIO_TYPE_SOCKET_MMAP:
> > >>+           pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
> > >>+                           pkt_table, len);
> > >>            break;
> > >>  #ifdef ODP_HAVE_NETMAP
> > >>    case ODP_PKTIO_TYPE_NETMAP:
> > >>-           pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table,
> len);
> > >>+           pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
> > >>+                           pkt_table, len);
> > >>            break;
> > >>  #endif
> > >>    default:
> > >>diff --git a/platform/linux-generic/source/odp_packet_socket.c
> b/platform/linux-generic/source/odp_packet_socket.c
> > >>index aaf2605..5f942dd 100644
> > >>--- a/platform/linux-generic/source/odp_packet_socket.c
> > >>+++ b/platform/linux-generic/source/odp_packet_socket.c
> > >>@@ -63,15 +63,17 @@ static inline int ethaddrs_equal(unsigned char
> mac_a[], unsigned char mac_b[])
> > >>    return !memcmp(mac_a, mac_b, ETH_ALEN);
> > >>  }
> > >>-static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int
> sock_group_idx)
> > >>+static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock,
> > >>+           int sock_group_idx)
> > >>  {
> > >>-#if ODP_PACKET_SOCKET_FANOUT == 1
> > >>-   /* Use FANOUT-mode for socket */
> > >>    int sockfd = pkt_sock->sockfd;
> > >>    int val;
> > >>    int err;
> > >>    uint16_t fanout_group;
> > >>+   if (!pkt_sock->fanout)
> > >>+           return 0;
> > >>+
> > >>    fanout_group = (uint16_t) (sock_group_idx & 0xffff);
> > >>    val = (PACKET_FANOUT_HASH << 16) | fanout_group;
> > >>@@ -80,16 +82,9 @@ static int set_pkt_sock_fanout(pkt_sock_t * const
> pkt_sock, int sock_group_idx)
> > >>            perror("set_pkt_sock_fanout() -
> setsockopt(PACKET_FANOUT)");
> > >>            return -1;
> > >>    }
> > >>-#else
> > >>-   (void)pkt_sock;
> > >>-   (void)sock_group_idx;
> > >>-#endif
> > >>-
> > >>    return 0;
> > >>  }
> > >>-#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
> > >>-   (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_BASIC:
> > >>   * ODP_PACKET_SOCKET_MMSG:
> > >>@@ -163,11 +158,6 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock,
> char *netdev,
> > >>            return -1;
> > >>    }
> > >>-   /* configure PACKET_FANOUT mode for socket (if mode enabled) */
> > >>-   err = set_pkt_sock_fanout(pkt_sock, if_idx);
> > >>-   if (err != 0)
> > >>-           return -1;
> > >>-
> > >>    return sockfd;
> > >>  }
> > >>@@ -184,13 +174,11 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
> > >>    return 0;
> > >>  }
> > >>-#endif
> > >>-#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_BASIC:
> > >>   */
> > >>-int recv_pkt_sock(pkt_sock_t *const pkt_sock,
> > >>+int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
> > >>              odp_packet_t pkt_table[], unsigned len)
> > >>  {
> > >>    ssize_t recv_bytes;
> > >>@@ -240,7 +228,7 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock,
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_BASIC:
> > >>   */
> > >>-int send_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>+int send_pkt_sock_basic(pkt_sock_t * const pkt_sock,
> > >>              odp_packet_t pkt_table[], unsigned len)
> > >>  {
> > >>    odp_packet_t pkt;
> > >>@@ -281,11 +269,10 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>    return nb_tx;
> > >>  }
> > >>-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_MMSG:
> > >>   */
> > >>-int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>+int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
> > >>              odp_packet_t pkt_table[], unsigned len)
> > >>  {
> > >>    const int sockfd = pkt_sock->sockfd;
> > >>@@ -348,7 +335,7 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_MMSG:
> > >>   */
> > >>-int send_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>+int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
> > >>              odp_packet_t pkt_table[], unsigned len)
> > >>  {
> > >>    struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX];
> > >>@@ -387,7 +374,6 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>    return len;
> > >>  }
> > >>-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_MMAP:
> > >>   */
> > >>@@ -402,7 +388,7 @@ union frame_map {
> > >>    void *raw;
> > >>  };
> > >>-static int pkt_socket(void)
> > >>+static int mmap_pkt_socket(void)
> > >>  {
> > >>    int ver = TPACKET_V2;
> > >>@@ -421,23 +407,23 @@ static int pkt_socket(void)
> > >>    return sock;
> > >>  }
> > >>-static inline int rx_kernel_ready(struct tpacket2_hdr *hdr)
> > >>+static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr)
> > >>  {
> > >>    return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
> > >>  }
> > >>-static inline void rx_user_ready(struct tpacket2_hdr *hdr)
> > >>+static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr)
> > >>  {
> > >>    hdr->tp_status = TP_STATUS_KERNEL;
> > >>    __sync_synchronize();
> > >>  }
> > >>-static inline int tx_kernel_ready(struct tpacket2_hdr *hdr)
> > >>+static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr)
> > >>  {
> > >>    return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST |
> TP_STATUS_SENDING));
> > >>  }
> > >>-static inline void tx_user_ready(struct tpacket2_hdr *hdr)
> > >>+static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr)
> > >>  {
> > >>    hdr->tp_status = TP_STATUS_SEND_REQUEST;
> > >>    __sync_synchronize();
> > >>@@ -462,7 +448,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock,
> struct ring *ring,
> > >>    frame_num = ring->frame_num;
> > >>    while (i < len) {
> > >>-           if (rx_kernel_ready(ring->rd[frame_num].iov_base)) {
> > >>+           if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) {
> > >>                    ppd.raw = ring->rd[frame_num].iov_base;
> > >>                    next_frame_num = (frame_num + 1) % ring->rd_num;
> > >>@@ -474,7 +460,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock,
> struct ring *ring,
> > >>                    eth_hdr = (struct ethhdr *)pkt_buf;
> > >>                    if (odp_unlikely(ethaddrs_equal(if_mac,
> > >>
>  eth_hdr->h_source))) {
> > >>-                           rx_user_ready(ppd.raw); /* drop */
> > >>+                           mmap_rx_user_ready(ppd.raw); /* drop */
> > >>                            continue;
> > >>                    }
> > >>@@ -486,7 +472,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock,
> struct ring *ring,
> > >>                             + frame_offset;
> > >>                    memcpy(l2_hdr, pkt_buf, pkt_len);
> > >>-                   rx_user_ready(ppd.raw);
> > >>+                   mmap_rx_user_ready(ppd.raw);
> > >>                    /* Parse and set packet header data */
> > >>                    odp_packet_parse(pkt_table[i], pkt_len,
> frame_offset);
> > >>@@ -516,7 +502,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock,
> struct ring *ring,
> > >>    frame_num = ring->frame_num;
> > >>    while (i < len) {
> > >>-           if (tx_kernel_ready(ring->rd[frame_num].iov_base)) {
> > >>+           if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) {
> > >>                    ppd.raw = ring->rd[frame_num].iov_base;
> > >>                    next_frame_num = (frame_num + 1) % ring->rd_num;
> > >>@@ -530,7 +516,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock,
> struct ring *ring,
> > >>                    memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN -
> > >>                           sizeof(struct sockaddr_ll), pkt_buf,
> pkt_len);
> > >>-                   tx_user_ready(ppd.raw);
> > >>+                   mmap_tx_user_ready(ppd.raw);
> > >>                    odp_packet_free(pkt_table[i]);
> > >>                    frame_num = next_frame_num;
> > >>@@ -553,7 +539,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock,
> struct ring *ring,
> > >>    return i;
> > >>  }
> > >>-static void fill_ring(struct ring *ring, unsigned blocks)
> > >>+static void mmap_fill_ring(struct ring *ring, unsigned blocks)
> > >>  {
> > >>    ring->req.tp_block_size = getpagesize() << 2;
> > >>    ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7;
> > >>@@ -567,7 +553,7 @@ static void fill_ring(struct ring *ring, unsigned
> blocks)
> > >>    ring->flen = ring->req.tp_frame_size;
> > >>  }
> > >>-static int set_packet_loss_discard(int sock)
> > >>+static int mmap_set_packet_loss_discard(int sock)
> > >>  {
> > >>    int ret, discard = 1;
> > >>@@ -581,7 +567,7 @@ static int set_packet_loss_discard(int sock)
> > >>    return 0;
> > >>  }
> > >>-static int setup_ring(int sock, struct ring *ring, int type)
> > >>+static int mmap_setup_ring(int sock, struct ring *ring, int type)
> > >>  {
> > >>    int ret = 0;
> > >>    unsigned blocks = 256;
> > >>@@ -591,12 +577,12 @@ static int setup_ring(int sock, struct ring
> *ring, int type)
> > >>    ring->version = TPACKET_V2;
> > >>    if (type == PACKET_TX_RING) {
> > >>-           ret = set_packet_loss_discard(sock);
> > >>+           ret = mmap_set_packet_loss_discard(sock);
> > >>            if (ret != 0)
> > >>                    return -1;
> > >>    }
> > >>-   fill_ring(ring, blocks);
> > >>+   mmap_fill_ring(ring, blocks);
> > >>    ret = setsockopt(sock, SOL_PACKET, type, &ring->req,
> sizeof(ring->req));
> > >>    if (ret == -1) {
> > >>@@ -614,7 +600,7 @@ static int setup_ring(int sock, struct ring *ring,
> int type)
> > >>    return 0;
> > >>  }
> > >>-static int mmap_sock(pkt_sock_t *pkt_sock)
> > >>+static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
> > >>  {
> > >>    int i;
> > >>    int sock = pkt_sock->sockfd;
> > >>@@ -655,14 +641,14 @@ static int mmap_sock(pkt_sock_t *pkt_sock)
> > >>    return 0;
> > >>  }
> > >>-static void unmap_sock(pkt_sock_t *pkt_sock)
> > >>+static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock)
> > >>  {
> > >>    munmap(pkt_sock->mmap_base, pkt_sock->mmap_len);
> > >>    free(pkt_sock->rx_ring.rd);
> > >>    free(pkt_sock->tx_ring.rd);
> > >>  }
> > >>-static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
> > >>+static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev)
> > >>  {
> > >>    int ret;
> > >>@@ -684,7 +670,7 @@ static int bind_sock(pkt_sock_t *pkt_sock, char
> *netdev)
> > >>    return 0;
> > >>  }
> > >>-static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
> > >>+static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char
> *netdev)
> > >>  {
> > >>    struct ifreq ethreq;
> > >>    int ret;
> > >>@@ -707,7 +693,7 @@ static int store_hw_addr(pkt_sock_t * const
> pkt_sock, char *netdev)
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_MMAP:
> > >>   */
> > >>-int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
> > >>+int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char
> *netdev,
> > >>               odp_buffer_pool_t pool)
> > >>  {
> > >>    odp_packet_t pkt;
> > >>@@ -733,17 +719,19 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock,
> char *netdev,
> > >>    odp_packet_free(pkt);
> > >>    pkt_sock->pool = pool;
> > >>-   pkt_sock->sockfd = pkt_socket();
> > >>+   pkt_sock->sockfd = mmap_pkt_socket();
> > >>-   ret = bind_sock(pkt_sock, netdev);
> > >>+   ret = mmap_bind_sock(pkt_sock, netdev);
> > >>    if (ret != 0)
> > >>            return -1;
> > >>-   ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
> PACKET_TX_RING);
> > >>+   ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
> > >>+                   PACKET_TX_RING);
> > >>    if (ret != 0)
> > >>            return -1;
> > >>-   ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
> PACKET_RX_RING);
> > >>+   ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
> > >>+                   PACKET_RX_RING);
> > >>    if (ret != 0)
> > >>            return -1;
> > >>@@ -751,7 +739,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock,
> char *netdev,
> > >>    if (ret != 0)
> > >>            return -1;
> > >>-   ret = store_hw_addr(pkt_sock, netdev);
> > >>+   ret = mmap_store_hw_addr(pkt_sock, netdev);
> > >>    if (ret != 0)
> > >>            return -1;
> > >>@@ -761,7 +749,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock,
> char *netdev,
> > >>            return -1;
> > >>    }
> > >>-   ret = set_pkt_sock_fanout(pkt_sock, if_idx);
> > >>+   ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx);
> > >>    if (ret != 0)
> > >>            return -1;
> > >>@@ -771,9 +759,9 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock,
> char *netdev,
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_MMAP:
> > >>   */
> > >>-int close_pkt_sock(pkt_sock_t * const pkt_sock)
> > >>+int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock)
> > >>  {
> > >>-   unmap_sock(pkt_sock);
> > >>+   mmap_unmap_sock(pkt_sock);
> > >>    if (close(pkt_sock->sockfd) != 0) {
> > >>            perror("close_pkt_sock() - close(sockfd)");
> > >>            return -1;
> > >>@@ -785,7 +773,7 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_MMAP:
> > >>   */
> > >>-int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>+int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> > >>              odp_packet_t pkt_table[], unsigned len)
> > >>  {
> > >>    return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring,
> > >>@@ -796,13 +784,9 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>  /*
> > >>   * ODP_PACKET_SOCKET_MMAP:
> > >>   */
> > >>-int send_pkt_sock(pkt_sock_t * const pkt_sock,
> > >>+int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
> > >>              odp_packet_t pkt_table[], unsigned len)
> > >>  {
> > >>    return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring,
> > >>                          pkt_table, len);
> > >>  }
> > >>-
> > >>-#else
> > >>-#error "Unsupported ODP_PACKET_SOCKET_MODE!"
> > >>-#endif
> > >>diff --git a/test/packet/odp_example_pktio.c
> b/test/packet/odp_example_pktio.c
> > >>index 85bbdd7..d6c9cd4 100644
> > >>--- a/test/packet/odp_example_pktio.c
> > >>+++ b/test/packet/odp_example_pktio.c
> > >>@@ -111,7 +111,7 @@ static void *pktio_queue_thread(void *arg)
> > >>    }
> > >>    /* Open a packet IO instance for this thread */
> > >>-   sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> > >>+   sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
> > >>    pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool,
> &params);
> > >>    if (pktio == ODP_PKTIO_INVALID) {
> > >>            ODP_ERR("  [%02i] Error: pktio create failed\n", thr);
> > >>@@ -223,7 +223,7 @@ static void *pktio_ifburst_thread(void *arg)
> > >>    }
> > >>    /* Open a packet IO instance for this thread */
> > >>-   sock_params->type = ODP_PKTIO_TYPE_SOCKET;
> > >>+   sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
> > >>    pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool,
> &params);
> > >>    if (pktio == ODP_PKTIO_INVALID) {
> > >>            ODP_ERR("  [%02i] Error: pktio create failed.\n", thr);
> > >>--
> > >>1.8.5.1.163.gd7aced9
> > >>
> > >>--
> > >>You received this message because you are subscribed to the Google
> Groups "LNG ODP Sub-team - lng-odp@linaro.org" group.
> > >>To unsubscribe from this group and stop receiving emails from it, send
> an email to lng-odp+unsubscribe@linaro.org.
> > >>To post to this group, send email to lng-odp@linaro.org.
> > >>Visit this group at
> http://groups.google.com/a/linaro.org/group/lng-odp/.
> > >>To view this discussion on the web visit
> https://groups.google.com/a/linaro.org/d/msgid/lng-odp/1396012333-27985-1-git-send-email-maxim.uvarov%40linaro.org
> .
> > >>For more options, visit
> https://groups.google.com/a/linaro.org/d/optout.
> >
>
> --
> Anders Roxell
> anders.roxell@linaro.org
> M: +46 709 71 42 85 | IRC: roxell
>
> --
> You received this message because you are subscribed to the Google Groups
> "LNG ODP Sub-team - lng-odp@linaro.org" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to lng-odp+unsubscribe@linaro.org.
> To post to this group, send email to lng-odp@linaro.org.
> Visit this group at http://groups.google.com/a/linaro.org/group/lng-odp/.
> To view this discussion on the web visit
> https://groups.google.com/a/linaro.org/d/msgid/lng-odp/20140328145151.GA9024%408470w
> .
> For more options, visit https://groups.google.com/a/linaro.org/d/optout.
>
Maxim Uvarov March 28, 2014, 3:02 p.m. UTC | #6
On 03/28/2014 06:51 PM, Anders Roxell wrote:
> On 2014-03-28 18:42, Maxim Uvarov wrote:
>> On 03/28/2014 05:43 PM, Anders Roxell wrote:
>>> On 2014-03-28 17:12, Maxim Uvarov wrote:
>>>> Dynamically select type of packet I/O
>>>> sock_params->type =
>>>> 	ODP_PKTIO_TYPE_SOCKET_BASIC
>>>> 	ODP_PKTIO_TYPE_SOCKET_MMSG
>>>> 	ODP_PKTIO_TYPE_SOCKET_MMAP
>>>> 	ODP_PKTIO_TYPE_NETMAP
>>>> sock_params->fanout = 1;
>>>> pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>>>>
>>>> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
>>>> ---
>>>>   .../linux-generic/include/api/odp_pktio_types.h    |  6 +-
>>>>   .../linux-generic/include/odp_packet_io_internal.h |  1 +
>>>>   platform/linux-generic/include/odp_packet_socket.h | 56 +++++--------
>>>>   platform/linux-generic/source/odp_packet_io.c      | 61 +++++++++++---
>>>>   platform/linux-generic/source/odp_packet_socket.c  | 98 +++++++++-------------
>>>>   test/packet/odp_example_pktio.c                    |  4 +-
>>>>   6 files changed, 119 insertions(+), 107 deletions(-)
>>>>
>>>> diff --git a/platform/linux-generic/include/api/odp_pktio_types.h b/platform/linux-generic/include/api/odp_pktio_types.h
>>>> index e6b4cbf..c87bfc2 100644
>>>> --- a/platform/linux-generic/include/api/odp_pktio_types.h
>>>> +++ b/platform/linux-generic/include/api/odp_pktio_types.h
>>>> @@ -17,9 +17,11 @@ extern "C" {
>>>>    */
>>>>   typedef enum {
>>>> -	ODP_PKTIO_TYPE_SOCKET = 0x01,
>>>> +	ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1,
>>>> +	ODP_PKTIO_TYPE_SOCKET_MMSG =  0x2,
>>>> +	ODP_PKTIO_TYPE_SOCKET_MMAP =  0x3,
>>>>   #ifdef ODP_HAVE_NETMAP
>>>> -	ODP_PKTIO_TYPE_NETMAP = 0x02,
>>>> +	ODP_PKTIO_TYPE_NETMAP =   0x4,
>>>>   #endif
>>> Remove the "#ifdef ODP_HAVE_NETMAP" and let the enum do the job of
>>> incremeting the value.
>>>
>>> Cheers,
>>> Anders
>> NETMAP depends on netmap headers which maynot be installed.
> I understand that
> However, why do you need an ifdef inside an enum for if netmap isn't
> installed?
> we should never use ifdefs inside enums right?
> and let the enum do the job of incrementing the values...
>
> or what do I miss?
>
> Cheers,
> Anders
Ok, understood your suggestion. Will update patch.

Thanks,
Maxim.
>> Maxim.
>>>>   } odp_pktio_type_t;
>>>> diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
>>>> index ba1ee9b..3ab7fa0 100644
>>>> --- a/platform/linux-generic/include/odp_packet_io_internal.h
>>>> +++ b/platform/linux-generic/include/odp_packet_io_internal.h
>>>> @@ -31,6 +31,7 @@ struct pktio_entry {
>>>>   	odp_queue_t outq_default;	/**< default out queue */
>>>>   	odp_pktio_params_t params;	/**< pktio parameters */
>>>>   	pkt_sock_t pkt_sock;		/**< using socket API for IO */
>>>> +	pkt_sock_mmap_t pkt_sock_mmap;	/**< using socket mmap API for IO */
>>>>   #ifdef ODP_HAVE_NETMAP
>>>>   	pkt_netmap_t pkt_nm;		/**< using netmap API for IO */
>>>>   #endif
>>>> diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h
>>>> index fe216bb..98ceb98 100644
>>>> --- a/platform/linux-generic/include/odp_packet_socket.h
>>>> +++ b/platform/linux-generic/include/odp_packet_socket.h
>>>> @@ -20,37 +20,15 @@
>>>>   #include <linux/version.h>
>>>> -
>>>>   /*
>>>>    * Packet socket config:
>>>>    */
>>>> -#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */
>>>> -#define ODP_PACKET_SOCKET_MMSG  1 /** use recvmmsg()/sendmmsg() */
>>>> -#define ODP_PACKET_SOCKET_MMAP  2 /** use PACKET_MMAP */
>>>> -
>>>> -
>>>> -#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0)
>>>> -/* PACKET_FANOUT feature not supported */
>>>> -#define ODP_PACKET_SOCKET_FANOUT 0
>>>> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC)
>>>> -#else
>>>> -/** PACKET_FANOUT mode spreads incoming packets over multiple sockets*/
>>>> -#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */
>>>> -/** Choose one from the alternatives above */
>>>> -#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP)
>>>> -#endif
>>>> -
>>>>   /** Max receive (Rx) burst size*/
>>>>   #define ODP_PACKET_SOCKET_MAX_BURST_RX 32
>>>>   /** Max transmit (Tx) burst size*/
>>>>   #define ODP_PACKET_SOCKET_MAX_BURST_TX 32
>>>> -
>>>> -
>>>> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
>>>> -	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
>>>> -
>>>>   typedef struct {
>>>>   	int sockfd; /**< socket descriptor */
>>>>   	odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */
>>>> @@ -60,12 +38,6 @@ typedef struct {
>>>>   	unsigned char if_mac[ETH_ALEN];	/**< IF eth mac addr */
>>>>   } pkt_sock_t;
>>>> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
>>>> -
>>>> -#if ODP_PACKET_SOCKET_FANOUT == 0
>>>> -#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1"
>>>> -#endif
>>>> -
>>>>   /** packet mmap ring */
>>>>   struct ring {
>>>>   	struct iovec *rd;
>>>> @@ -99,31 +71,45 @@ typedef struct {
>>>>   	unsigned mmap_len;
>>>>   	unsigned char if_mac[ETH_ALEN];
>>>>   	struct sockaddr_ll ll;
>>>> -} pkt_sock_t;
>>>> -
>>>> -#else
>>>> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
>>>> -#endif
>>>> +	int fanout; /**< 0: off 1: on */
>>>> +} pkt_sock_mmap_t;
>>>>   /**
>>>>    * Open & configure a raw packet socket
>>>>    */
>>>>   int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>>>   		   odp_buffer_pool_t pool);
>>>> +
>>>> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
>>>> +		   odp_buffer_pool_t pool);
>>>> +
>>>>   /**
>>>>    * Close a packet socket
>>>>    */
>>>>   int close_pkt_sock(pkt_sock_t * const pkt_sock);
>>>> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock);
>>>> +
>>>>   /**
>>>>    * Receive packets from the packet socket
>>>>    */
>>>> -int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>>> +int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>>>   		  unsigned len);
>>>> +
>>>> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>>> +		  unsigned len);
>>>> +
>>>> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>>>> +		  odp_packet_t pkt_table[], unsigned len);
>>>>   /**
>>>>    * Send packets through the packet socket
>>>>    */
>>>> -int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>>> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>>> +		  unsigned len);
>>>> +
>>>> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
>>>>   		  unsigned len);
>>>> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>>>> +		  odp_packet_t pkt_table[], unsigned len);
>>>>   #endif
>>>> diff --git a/platform/linux-generic/source/odp_packet_io.c b/platform/linux-generic/source/odp_packet_io.c
>>>> index 92aed34..ab80aef 100644
>>>> --- a/platform/linux-generic/source/odp_packet_io.c
>>>> +++ b/platform/linux-generic/source/odp_packet_io.c
>>>> @@ -117,8 +117,12 @@ static void init_pktio_entry(pktio_entry_t *entry, odp_pktio_params_t *params)
>>>>   	set_taken(entry);
>>>>   	entry->s.inq_default = ODP_QUEUE_INVALID;
>>>>   	switch (params->type) {
>>>> -	case ODP_PKTIO_TYPE_SOCKET:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>>>   		memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock));
>>>> +		memset(&entry->s.pkt_sock_mmap, 0,
>>>> +		      sizeof(entry->s.pkt_sock_mmap));
>>>>   		break;
>>>>   #ifdef ODP_HAVE_NETMAP
>>>>   	case ODP_PKTIO_TYPE_NETMAP:
>>>> @@ -177,7 +181,9 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>>>>   	}
>>>>   	switch (params->type) {
>>>> -	case ODP_PKTIO_TYPE_SOCKET:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>>>   		ODP_DBG("Allocating socket pktio\n");
>>>>   		break;
>>>>   #ifdef ODP_HAVE_NETMAP
>>>> @@ -200,7 +206,8 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>>>>   	pktio_entry = get_entry(id);
>>>>   	switch (params->type) {
>>>> -	case ODP_PKTIO_TYPE_SOCKET:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>>>   		res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool);
>>>>   		if (res == -1) {
>>>>   			close_pkt_sock(&pktio_entry->s.pkt_sock);
>>>> @@ -208,10 +215,19 @@ odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
>>>>   			id = ODP_PKTIO_INVALID;
>>>>   		}
>>>>   		break;
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>>> +		res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, dev,
>>>> +				pool);
>>>> +		if (res == -1) {
>>>> +			close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap);
>>>> +			free_pktio_entry(id);
>>>> +			id = ODP_PKTIO_INVALID;
>>>> +		}
>>>> +		break;
>>>>   #ifdef ODP_HAVE_NETMAP
>>>>   	case ODP_PKTIO_TYPE_NETMAP:
>>>>   		res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev,
>>>> -				       pool, &params->nm_params);
>>>> +				pool, &params->nm_params);
>>>>   		if (res == -1) {
>>>>   			close_pkt_netmap(&pktio_entry->s.pkt_nm);
>>>>   			free_pktio_entry(id);
>>>> @@ -237,9 +253,13 @@ int odp_pktio_close(odp_pktio_t id)
>>>>   	lock_entry(entry);
>>>>   	if (!is_free(entry)) {
>>>>   		switch (entry->s.params.type) {
>>>> -		case ODP_PKTIO_TYPE_SOCKET:
>>>> +		case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>>> +		case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>>>   			res  = close_pkt_sock(&entry->s.pkt_sock);
>>>>   			break;
>>>> +		case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>>> +			res  = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
>>>> +			break;
>>>>   #ifdef ODP_HAVE_NETMAP
>>>>   		case ODP_PKTIO_TYPE_NETMAP:
>>>>   			res  = close_pkt_netmap(&entry->s.pkt_nm);
>>>> @@ -247,7 +267,7 @@ int odp_pktio_close(odp_pktio_t id)
>>>>   #endif
>>>>   		default:
>>>>   			break;
>>>> -		res |= free_pktio_entry(id);
>>>> +			res |= free_pktio_entry(id);
>>>>   		}
>>>>   	}
>>>>   	unlock_entry(entry);
>>>> @@ -279,8 +299,17 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
>>>>   	lock_entry(pktio_entry);
>>>>   	switch (pktio_entry->s.params.type) {
>>>> -	case ODP_PKTIO_TYPE_SOCKET:
>>>> -		pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
>>>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>>> +		pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
>>>> +				pkt_table, len);
>>>> +		break;
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>>> +		pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
>>>> +				pkt_table, len);
>>>> +		break;
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>>> +		pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
>>>> +				pkt_table, len);
>>>>   		break;
>>>>   #ifdef ODP_HAVE_NETMAP
>>>>   	case ODP_PKTIO_TYPE_NETMAP:
>>>> @@ -312,12 +341,22 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
>>>>   	lock_entry(pktio_entry);
>>>>   	switch (pktio_entry->s.params.type) {
>>>> -	case ODP_PKTIO_TYPE_SOCKET:
>>>> -		pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
>>>> +	case ODP_PKTIO_TYPE_SOCKET_BASIC:
>>>> +		pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
>>>> +				pkt_table, len);
>>>> +		break;
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMSG:
>>>> +		pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
>>>> +				pkt_table, len);
>>>> +		break;
>>>> +	case ODP_PKTIO_TYPE_SOCKET_MMAP:
>>>> +		pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
>>>> +				pkt_table, len);
>>>>   		break;
>>>>   #ifdef ODP_HAVE_NETMAP
>>>>   	case ODP_PKTIO_TYPE_NETMAP:
>>>> -		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len);
>>>> +		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
>>>> +				pkt_table, len);
>>>>   		break;
>>>>   #endif
>>>>   	default:
>>>> diff --git a/platform/linux-generic/source/odp_packet_socket.c b/platform/linux-generic/source/odp_packet_socket.c
>>>> index aaf2605..5f942dd 100644
>>>> --- a/platform/linux-generic/source/odp_packet_socket.c
>>>> +++ b/platform/linux-generic/source/odp_packet_socket.c
>>>> @@ -63,15 +63,17 @@ static inline int ethaddrs_equal(unsigned char mac_a[], unsigned char mac_b[])
>>>>   	return !memcmp(mac_a, mac_b, ETH_ALEN);
>>>>   }
>>>> -static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
>>>> +static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock,
>>>> +		int sock_group_idx)
>>>>   {
>>>> -#if ODP_PACKET_SOCKET_FANOUT == 1
>>>> -	/* Use FANOUT-mode for socket */
>>>>   	int sockfd = pkt_sock->sockfd;
>>>>   	int val;
>>>>   	int err;
>>>>   	uint16_t fanout_group;
>>>> +	if (!pkt_sock->fanout)
>>>> +		return 0;
>>>> +
>>>>   	fanout_group = (uint16_t) (sock_group_idx & 0xffff);
>>>>   	val = (PACKET_FANOUT_HASH << 16) | fanout_group;
>>>> @@ -80,16 +82,9 @@ static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
>>>>   		perror("set_pkt_sock_fanout() - setsockopt(PACKET_FANOUT)");
>>>>   		return -1;
>>>>   	}
>>>> -#else
>>>> -	(void)pkt_sock;
>>>> -	(void)sock_group_idx;
>>>> -#endif
>>>> -
>>>>   	return 0;
>>>>   }
>>>> -#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
>>>> -	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_BASIC:
>>>>    * ODP_PACKET_SOCKET_MMSG:
>>>> @@ -163,11 +158,6 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>>>   		return -1;
>>>>   	}
>>>> -	/* configure PACKET_FANOUT mode for socket (if mode enabled) */
>>>> -	err = set_pkt_sock_fanout(pkt_sock, if_idx);
>>>> -	if (err != 0)
>>>> -		return -1;
>>>> -
>>>>   	return sockfd;
>>>>   }
>>>> @@ -184,13 +174,11 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>>>>   	return 0;
>>>>   }
>>>> -#endif
>>>> -#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_BASIC:
>>>>    */
>>>> -int recv_pkt_sock(pkt_sock_t *const pkt_sock,
>>>> +int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
>>>>   		  odp_packet_t pkt_table[], unsigned len)
>>>>   {
>>>>   	ssize_t recv_bytes;
>>>> @@ -240,7 +228,7 @@ int recv_pkt_sock(pkt_sock_t *const pkt_sock,
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_BASIC:
>>>>    */
>>>> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
>>>> +int send_pkt_sock_basic(pkt_sock_t * const pkt_sock,
>>>>   		  odp_packet_t pkt_table[], unsigned len)
>>>>   {
>>>>   	odp_packet_t pkt;
>>>> @@ -281,11 +269,10 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>>>>   	return nb_tx;
>>>>   }
>>>> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_MMSG:
>>>>    */
>>>> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>>>> +int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>>>>   		  odp_packet_t pkt_table[], unsigned len)
>>>>   {
>>>>   	const int sockfd = pkt_sock->sockfd;
>>>> @@ -348,7 +335,7 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_MMSG:
>>>>    */
>>>> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
>>>> +int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
>>>>   		  odp_packet_t pkt_table[], unsigned len)
>>>>   {
>>>>   	struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX];
>>>> @@ -387,7 +374,6 @@ int send_pkt_sock(pkt_sock_t * const pkt_sock,
>>>>   	return len;
>>>>   }
>>>> -#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_MMAP:
>>>>    */
>>>> @@ -402,7 +388,7 @@ union frame_map {
>>>>   	void *raw;
>>>>   };
>>>> -static int pkt_socket(void)
>>>> +static int mmap_pkt_socket(void)
>>>>   {
>>>>   	int ver = TPACKET_V2;
>>>> @@ -421,23 +407,23 @@ static int pkt_socket(void)
>>>>   	return sock;
>>>>   }
>>>> -static inline int rx_kernel_ready(struct tpacket2_hdr *hdr)
>>>> +static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr)
>>>>   {
>>>>   	return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
>>>>   }
>>>> -static inline void rx_user_ready(struct tpacket2_hdr *hdr)
>>>> +static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr)
>>>>   {
>>>>   	hdr->tp_status = TP_STATUS_KERNEL;
>>>>   	__sync_synchronize();
>>>>   }
>>>> -static inline int tx_kernel_ready(struct tpacket2_hdr *hdr)
>>>> +static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr)
>>>>   {
>>>>   	return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING));
>>>>   }
>>>> -static inline void tx_user_ready(struct tpacket2_hdr *hdr)
>>>> +static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr)
>>>>   {
>>>>   	hdr->tp_status = TP_STATUS_SEND_REQUEST;
>>>>   	__sync_synchronize();
>>>> @@ -462,7 +448,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>>>>   	frame_num = ring->frame_num;
>>>>   	while (i < len) {
>>>> -		if (rx_kernel_ready(ring->rd[frame_num].iov_base)) {
>>>> +		if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) {
>>>>   			ppd.raw = ring->rd[frame_num].iov_base;
>>>>   			next_frame_num = (frame_num + 1) % ring->rd_num;
>>>> @@ -474,7 +460,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>>>>   			eth_hdr = (struct ethhdr *)pkt_buf;
>>>>   			if (odp_unlikely(ethaddrs_equal(if_mac,
>>>>   							eth_hdr->h_source))) {
>>>> -				rx_user_ready(ppd.raw); /* drop */
>>>> +				mmap_rx_user_ready(ppd.raw); /* drop */
>>>>   				continue;
>>>>   			}
>>>> @@ -486,7 +472,7 @@ static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
>>>>   				 + frame_offset;
>>>>   			memcpy(l2_hdr, pkt_buf, pkt_len);
>>>> -			rx_user_ready(ppd.raw);
>>>> +			mmap_rx_user_ready(ppd.raw);
>>>>   			/* Parse and set packet header data */
>>>>   			odp_packet_parse(pkt_table[i], pkt_len, frame_offset);
>>>> @@ -516,7 +502,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>>>>   	frame_num = ring->frame_num;
>>>>   	while (i < len) {
>>>> -		if (tx_kernel_ready(ring->rd[frame_num].iov_base)) {
>>>> +		if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) {
>>>>   			ppd.raw = ring->rd[frame_num].iov_base;
>>>>   			next_frame_num = (frame_num + 1) % ring->rd_num;
>>>> @@ -530,7 +516,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>>>>   			memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN -
>>>>   			       sizeof(struct sockaddr_ll), pkt_buf, pkt_len);
>>>> -			tx_user_ready(ppd.raw);
>>>> +			mmap_tx_user_ready(ppd.raw);
>>>>   			odp_packet_free(pkt_table[i]);
>>>>   			frame_num = next_frame_num;
>>>> @@ -553,7 +539,7 @@ static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
>>>>   	return i;
>>>>   }
>>>> -static void fill_ring(struct ring *ring, unsigned blocks)
>>>> +static void mmap_fill_ring(struct ring *ring, unsigned blocks)
>>>>   {
>>>>   	ring->req.tp_block_size = getpagesize() << 2;
>>>>   	ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7;
>>>> @@ -567,7 +553,7 @@ static void fill_ring(struct ring *ring, unsigned blocks)
>>>>   	ring->flen = ring->req.tp_frame_size;
>>>>   }
>>>> -static int set_packet_loss_discard(int sock)
>>>> +static int mmap_set_packet_loss_discard(int sock)
>>>>   {
>>>>   	int ret, discard = 1;
>>>> @@ -581,7 +567,7 @@ static int set_packet_loss_discard(int sock)
>>>>   	return 0;
>>>>   }
>>>> -static int setup_ring(int sock, struct ring *ring, int type)
>>>> +static int mmap_setup_ring(int sock, struct ring *ring, int type)
>>>>   {
>>>>   	int ret = 0;
>>>>   	unsigned blocks = 256;
>>>> @@ -591,12 +577,12 @@ static int setup_ring(int sock, struct ring *ring, int type)
>>>>   	ring->version = TPACKET_V2;
>>>>   	if (type == PACKET_TX_RING) {
>>>> -		ret = set_packet_loss_discard(sock);
>>>> +		ret = mmap_set_packet_loss_discard(sock);
>>>>   		if (ret != 0)
>>>>   			return -1;
>>>>   	}
>>>> -	fill_ring(ring, blocks);
>>>> +	mmap_fill_ring(ring, blocks);
>>>>   	ret = setsockopt(sock, SOL_PACKET, type, &ring->req, sizeof(ring->req));
>>>>   	if (ret == -1) {
>>>> @@ -614,7 +600,7 @@ static int setup_ring(int sock, struct ring *ring, int type)
>>>>   	return 0;
>>>>   }
>>>> -static int mmap_sock(pkt_sock_t *pkt_sock)
>>>> +static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
>>>>   {
>>>>   	int i;
>>>>   	int sock = pkt_sock->sockfd;
>>>> @@ -655,14 +641,14 @@ static int mmap_sock(pkt_sock_t *pkt_sock)
>>>>   	return 0;
>>>>   }
>>>> -static void unmap_sock(pkt_sock_t *pkt_sock)
>>>> +static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock)
>>>>   {
>>>>   	munmap(pkt_sock->mmap_base, pkt_sock->mmap_len);
>>>>   	free(pkt_sock->rx_ring.rd);
>>>>   	free(pkt_sock->tx_ring.rd);
>>>>   }
>>>> -static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
>>>> +static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev)
>>>>   {
>>>>   	int ret;
>>>> @@ -684,7 +670,7 @@ static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
>>>>   	return 0;
>>>>   }
>>>> -static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
>>>> +static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char *netdev)
>>>>   {
>>>>   	struct ifreq ethreq;
>>>>   	int ret;
>>>> @@ -707,7 +693,7 @@ static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_MMAP:
>>>>    */
>>>> -int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>>> +int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
>>>>   		   odp_buffer_pool_t pool)
>>>>   {
>>>>   	odp_packet_t pkt;
>>>> @@ -733,17 +719,19 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>>>   	odp_packet_free(pkt);
>>>>   	pkt_sock->pool = pool;
>>>> -	pkt_sock->sockfd = pkt_socket();
>>>> +	pkt_sock->sockfd = mmap_pkt_socket();
>>>> -	ret = bind_sock(pkt_sock, netdev);
>>>> +	ret = mmap_bind_sock(pkt_sock, netdev);
>>>>   	if (ret != 0)
>>>>   		return -1;
>>>> -	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring, PACKET_TX_RING);
>>>> +	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
>>>> +			PACKET_TX_RING);
>>>>   	if (ret != 0)
>>>>   		return -1;
>>>> -	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring, PACKET_RX_RING);
>>>> +	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
>>>> +			PACKET_RX_RING);
>>>>   	if (ret != 0)
>>>>   		return -1;
>>>> @@ -751,7 +739,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>>>   	if (ret != 0)
>>>>   		return -1;
>>>> -	ret = store_hw_addr(pkt_sock, netdev);
>>>> +	ret = mmap_store_hw_addr(pkt_sock, netdev);
>>>>   	if (ret != 0)
>>>>   		return -1;
>>>> @@ -761,7 +749,7 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>>>   		return -1;
>>>>   	}
>>>> -	ret = set_pkt_sock_fanout(pkt_sock, if_idx);
>>>> +	ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx);
>>>>   	if (ret != 0)
>>>>   		return -1;
>>>> @@ -771,9 +759,9 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_MMAP:
>>>>    */
>>>> -int close_pkt_sock(pkt_sock_t * const pkt_sock)
>>>> +int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock)
>>>>   {
>>>> -	unmap_sock(pkt_sock);
>>>> +	mmap_unmap_sock(pkt_sock);
>>>>   	if (close(pkt_sock->sockfd) != 0) {
>>>>   		perror("close_pkt_sock() - close(sockfd)");
>>>>   		return -1;
>>>> @@ -785,7 +773,7 @@ int close_pkt_sock(pkt_sock_t * const pkt_sock)
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_MMAP:
>>>>    */
>>>> -int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>>>> +int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>>>>   		  odp_packet_t pkt_table[], unsigned len)
>>>>   {
>>>>   	return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring,
>>>> @@ -796,13 +784,9 @@ int recv_pkt_sock(pkt_sock_t * const pkt_sock,
>>>>   /*
>>>>    * ODP_PACKET_SOCKET_MMAP:
>>>>    */
>>>> -int send_pkt_sock(pkt_sock_t * const pkt_sock,
>>>> +int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
>>>>   		  odp_packet_t pkt_table[], unsigned len)
>>>>   {
>>>>   	return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring,
>>>>   			      pkt_table, len);
>>>>   }
>>>> -
>>>> -#else
>>>> -#error "Unsupported ODP_PACKET_SOCKET_MODE!"
>>>> -#endif
>>>> diff --git a/test/packet/odp_example_pktio.c b/test/packet/odp_example_pktio.c
>>>> index 85bbdd7..d6c9cd4 100644
>>>> --- a/test/packet/odp_example_pktio.c
>>>> +++ b/test/packet/odp_example_pktio.c
>>>> @@ -111,7 +111,7 @@ static void *pktio_queue_thread(void *arg)
>>>>   	}
>>>>   	/* Open a packet IO instance for this thread */
>>>> -	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
>>>> +	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>>>>   	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>>>>   	if (pktio == ODP_PKTIO_INVALID) {
>>>>   		ODP_ERR("  [%02i] Error: pktio create failed\n", thr);
>>>> @@ -223,7 +223,7 @@ static void *pktio_ifburst_thread(void *arg)
>>>>   	}
>>>>   	/* Open a packet IO instance for this thread */
>>>> -	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
>>>> +	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
>>>>   	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
>>>>   	if (pktio == ODP_PKTIO_INVALID) {
>>>>   		ODP_ERR("  [%02i] Error: pktio create failed.\n", thr);
>>>> -- 
>>>> 1.8.5.1.163.gd7aced9
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google Groups "LNG ODP Sub-team - lng-odp@linaro.org" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an email to lng-odp+unsubscribe@linaro.org.
>>>> To post to this group, send email to lng-odp@linaro.org.
>>>> Visit this group at http://groups.google.com/a/linaro.org/group/lng-odp/.
>>>> To view this discussion on the web visit https://groups.google.com/a/linaro.org/d/msgid/lng-odp/1396012333-27985-1-git-send-email-maxim.uvarov%40linaro.org.
>>>> For more options, visit https://groups.google.com/a/linaro.org/d/optout.
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_pktio_types.h b/platform/linux-generic/include/api/odp_pktio_types.h
index e6b4cbf..c87bfc2 100644
--- a/platform/linux-generic/include/api/odp_pktio_types.h
+++ b/platform/linux-generic/include/api/odp_pktio_types.h
@@ -17,9 +17,11 @@  extern "C" {
  */
 
 typedef enum {
-	ODP_PKTIO_TYPE_SOCKET = 0x01,
+	ODP_PKTIO_TYPE_SOCKET_BASIC = 0x1,
+	ODP_PKTIO_TYPE_SOCKET_MMSG =  0x2,
+	ODP_PKTIO_TYPE_SOCKET_MMAP =  0x3,
 #ifdef ODP_HAVE_NETMAP
-	ODP_PKTIO_TYPE_NETMAP = 0x02,
+	ODP_PKTIO_TYPE_NETMAP =   0x4,
 #endif
 } odp_pktio_type_t;
 
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index ba1ee9b..3ab7fa0 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -31,6 +31,7 @@  struct pktio_entry {
 	odp_queue_t outq_default;	/**< default out queue */
 	odp_pktio_params_t params;	/**< pktio parameters */
 	pkt_sock_t pkt_sock;		/**< using socket API for IO */
+	pkt_sock_mmap_t pkt_sock_mmap;	/**< using socket mmap API for IO */
 #ifdef ODP_HAVE_NETMAP
 	pkt_netmap_t pkt_nm;		/**< using netmap API for IO */
 #endif
diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h
index fe216bb..98ceb98 100644
--- a/platform/linux-generic/include/odp_packet_socket.h
+++ b/platform/linux-generic/include/odp_packet_socket.h
@@ -20,37 +20,15 @@ 
 
 #include <linux/version.h>
 
-
 /*
  * Packet socket config:
  */
-#define ODP_PACKET_SOCKET_BASIC 0 /** use recv()/send() */
-#define ODP_PACKET_SOCKET_MMSG  1 /** use recvmmsg()/sendmmsg() */
-#define ODP_PACKET_SOCKET_MMAP  2 /** use PACKET_MMAP */
-
-
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 1, 0)
-/* PACKET_FANOUT feature not supported */
-#define ODP_PACKET_SOCKET_FANOUT 0
-#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_BASIC)
-#else
-/** PACKET_FANOUT mode spreads incoming packets over multiple sockets*/
-#define ODP_PACKET_SOCKET_FANOUT 1 /* 0=Off, 1=On */
-/** Choose one from the alternatives above */
-#define ODP_PACKET_SOCKET_MODE (ODP_PACKET_SOCKET_MMAP)
-#endif
-
 
 /** Max receive (Rx) burst size*/
 #define ODP_PACKET_SOCKET_MAX_BURST_RX 32
 /** Max transmit (Tx) burst size*/
 #define ODP_PACKET_SOCKET_MAX_BURST_TX 32
 
-
-
-#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
-	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
-
 typedef struct {
 	int sockfd; /**< socket descriptor */
 	odp_buffer_pool_t pool; /**< buffer pool to alloc packets from */
@@ -60,12 +38,6 @@  typedef struct {
 	unsigned char if_mac[ETH_ALEN];	/**< IF eth mac addr */
 } pkt_sock_t;
 
-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
-
-#if ODP_PACKET_SOCKET_FANOUT == 0
-#error "ODP_PACKET_SOCKET_MMAP requires ODP_PACKET_SOCKET_FANOUT=1"
-#endif
-
 /** packet mmap ring */
 struct ring {
 	struct iovec *rd;
@@ -99,31 +71,45 @@  typedef struct {
 	unsigned mmap_len;
 	unsigned char if_mac[ETH_ALEN];
 	struct sockaddr_ll ll;
-} pkt_sock_t;
-
-#else
-#error "Unsupported ODP_PACKET_SOCKET_MODE!"
-#endif
+	int fanout; /**< 0: off 1: on */
+} pkt_sock_mmap_t;
 
 /**
  * Open & configure a raw packet socket
  */
 int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
 		   odp_buffer_pool_t pool);
+
+int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
+		   odp_buffer_pool_t pool);
+
 /**
  * Close a packet socket
  */
 int close_pkt_sock(pkt_sock_t * const pkt_sock);
 
+int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock);
+
 /**
  * Receive packets from the packet socket
  */
-int recv_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
+int recv_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
 		  unsigned len);
+
+int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
+		  unsigned len);
+
+int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
+		  odp_packet_t pkt_table[], unsigned len);
 /**
  * Send packets through the packet socket
  */
-int send_pkt_sock(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
+int send_pkt_sock_basic(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
+		  unsigned len);
+
+int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock, odp_packet_t pkt_table[],
 		  unsigned len);
 
+int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
+		  odp_packet_t pkt_table[], unsigned len);
 #endif
diff --git a/platform/linux-generic/source/odp_packet_io.c b/platform/linux-generic/source/odp_packet_io.c
index 92aed34..ab80aef 100644
--- a/platform/linux-generic/source/odp_packet_io.c
+++ b/platform/linux-generic/source/odp_packet_io.c
@@ -117,8 +117,12 @@  static void init_pktio_entry(pktio_entry_t *entry, odp_pktio_params_t *params)
 	set_taken(entry);
 	entry->s.inq_default = ODP_QUEUE_INVALID;
 	switch (params->type) {
-	case ODP_PKTIO_TYPE_SOCKET:
+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
 		memset(&entry->s.pkt_sock, 0, sizeof(entry->s.pkt_sock));
+		memset(&entry->s.pkt_sock_mmap, 0,
+		      sizeof(entry->s.pkt_sock_mmap));
 		break;
 #ifdef ODP_HAVE_NETMAP
 	case ODP_PKTIO_TYPE_NETMAP:
@@ -177,7 +181,9 @@  odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
 	}
 
 	switch (params->type) {
-	case ODP_PKTIO_TYPE_SOCKET:
+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
 		ODP_DBG("Allocating socket pktio\n");
 		break;
 #ifdef ODP_HAVE_NETMAP
@@ -200,7 +206,8 @@  odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
 	pktio_entry = get_entry(id);
 
 	switch (params->type) {
-	case ODP_PKTIO_TYPE_SOCKET:
+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
 		res = setup_pkt_sock(&pktio_entry->s.pkt_sock, dev, pool);
 		if (res == -1) {
 			close_pkt_sock(&pktio_entry->s.pkt_sock);
@@ -208,10 +215,19 @@  odp_pktio_t odp_pktio_open(char *dev, odp_buffer_pool_t pool,
 			id = ODP_PKTIO_INVALID;
 		}
 		break;
+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
+		res = setup_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap, dev,
+				pool);
+		if (res == -1) {
+			close_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap);
+			free_pktio_entry(id);
+			id = ODP_PKTIO_INVALID;
+		}
+		break;
 #ifdef ODP_HAVE_NETMAP
 	case ODP_PKTIO_TYPE_NETMAP:
 		res = setup_pkt_netmap(&pktio_entry->s.pkt_nm, dev,
-				       pool, &params->nm_params);
+				pool, &params->nm_params);
 		if (res == -1) {
 			close_pkt_netmap(&pktio_entry->s.pkt_nm);
 			free_pktio_entry(id);
@@ -237,9 +253,13 @@  int odp_pktio_close(odp_pktio_t id)
 	lock_entry(entry);
 	if (!is_free(entry)) {
 		switch (entry->s.params.type) {
-		case ODP_PKTIO_TYPE_SOCKET:
+		case ODP_PKTIO_TYPE_SOCKET_BASIC:
+		case ODP_PKTIO_TYPE_SOCKET_MMSG:
 			res  = close_pkt_sock(&entry->s.pkt_sock);
 			break;
+		case ODP_PKTIO_TYPE_SOCKET_MMAP:
+			res  = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap);
+			break;
 #ifdef ODP_HAVE_NETMAP
 		case ODP_PKTIO_TYPE_NETMAP:
 			res  = close_pkt_netmap(&entry->s.pkt_nm);
@@ -247,7 +267,7 @@  int odp_pktio_close(odp_pktio_t id)
 #endif
 		default:
 			break;
-		res |= free_pktio_entry(id);
+			res |= free_pktio_entry(id);
 		}
 	}
 	unlock_entry(entry);
@@ -279,8 +299,17 @@  int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
 
 	lock_entry(pktio_entry);
 	switch (pktio_entry->s.params.type) {
-	case ODP_PKTIO_TYPE_SOCKET:
-		pkts = recv_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
+		pkts = recv_pkt_sock_basic(&pktio_entry->s.pkt_sock,
+				pkt_table, len);
+		break;
+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
+		pkts = recv_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
+				pkt_table, len);
+		break;
+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
+		pkts = recv_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
+				pkt_table, len);
 		break;
 #ifdef ODP_HAVE_NETMAP
 	case ODP_PKTIO_TYPE_NETMAP:
@@ -312,12 +341,22 @@  int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], unsigned len)
 
 	lock_entry(pktio_entry);
 	switch (pktio_entry->s.params.type) {
-	case ODP_PKTIO_TYPE_SOCKET:
-		pkts = send_pkt_sock(&pktio_entry->s.pkt_sock, pkt_table, len);
+	case ODP_PKTIO_TYPE_SOCKET_BASIC:
+		pkts = send_pkt_sock_basic(&pktio_entry->s.pkt_sock,
+				pkt_table, len);
+		break;
+	case ODP_PKTIO_TYPE_SOCKET_MMSG:
+		pkts = send_pkt_sock_mmsg(&pktio_entry->s.pkt_sock,
+				pkt_table, len);
+		break;
+	case ODP_PKTIO_TYPE_SOCKET_MMAP:
+		pkts = send_pkt_sock_mmap(&pktio_entry->s.pkt_sock_mmap,
+				pkt_table, len);
 		break;
 #ifdef ODP_HAVE_NETMAP
 	case ODP_PKTIO_TYPE_NETMAP:
-		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm, pkt_table, len);
+		pkts = send_pkt_netmap(&pktio_entry->s.pkt_nm,
+				pkt_table, len);
 		break;
 #endif
 	default:
diff --git a/platform/linux-generic/source/odp_packet_socket.c b/platform/linux-generic/source/odp_packet_socket.c
index aaf2605..5f942dd 100644
--- a/platform/linux-generic/source/odp_packet_socket.c
+++ b/platform/linux-generic/source/odp_packet_socket.c
@@ -63,15 +63,17 @@  static inline int ethaddrs_equal(unsigned char mac_a[], unsigned char mac_b[])
 	return !memcmp(mac_a, mac_b, ETH_ALEN);
 }
 
-static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
+static int set_pkt_sock_fanout_mmap(pkt_sock_mmap_t * const pkt_sock,
+		int sock_group_idx)
 {
-#if ODP_PACKET_SOCKET_FANOUT == 1
-	/* Use FANOUT-mode for socket */
 	int sockfd = pkt_sock->sockfd;
 	int val;
 	int err;
 	uint16_t fanout_group;
 
+	if (!pkt_sock->fanout)
+		return 0;
+
 	fanout_group = (uint16_t) (sock_group_idx & 0xffff);
 	val = (PACKET_FANOUT_HASH << 16) | fanout_group;
 
@@ -80,16 +82,9 @@  static int set_pkt_sock_fanout(pkt_sock_t * const pkt_sock, int sock_group_idx)
 		perror("set_pkt_sock_fanout() - setsockopt(PACKET_FANOUT)");
 		return -1;
 	}
-#else
-	(void)pkt_sock;
-	(void)sock_group_idx;
-#endif
-
 	return 0;
 }
 
-#if (ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC) || \
-	(ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG)
 /*
  * ODP_PACKET_SOCKET_BASIC:
  * ODP_PACKET_SOCKET_MMSG:
@@ -163,11 +158,6 @@  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
 		return -1;
 	}
 
-	/* configure PACKET_FANOUT mode for socket (if mode enabled) */
-	err = set_pkt_sock_fanout(pkt_sock, if_idx);
-	if (err != 0)
-		return -1;
-
 	return sockfd;
 }
 
@@ -184,13 +174,11 @@  int close_pkt_sock(pkt_sock_t * const pkt_sock)
 
 	return 0;
 }
-#endif
 
-#if ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_BASIC
 /*
  * ODP_PACKET_SOCKET_BASIC:
  */
-int recv_pkt_sock(pkt_sock_t *const pkt_sock,
+int recv_pkt_sock_basic(pkt_sock_t *const pkt_sock,
 		  odp_packet_t pkt_table[], unsigned len)
 {
 	ssize_t recv_bytes;
@@ -240,7 +228,7 @@  int recv_pkt_sock(pkt_sock_t *const pkt_sock,
 /*
  * ODP_PACKET_SOCKET_BASIC:
  */
-int send_pkt_sock(pkt_sock_t * const pkt_sock,
+int send_pkt_sock_basic(pkt_sock_t * const pkt_sock,
 		  odp_packet_t pkt_table[], unsigned len)
 {
 	odp_packet_t pkt;
@@ -281,11 +269,10 @@  int send_pkt_sock(pkt_sock_t * const pkt_sock,
 	return nb_tx;
 }
 
-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMSG
 /*
  * ODP_PACKET_SOCKET_MMSG:
  */
-int recv_pkt_sock(pkt_sock_t * const pkt_sock,
+int recv_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
 		  odp_packet_t pkt_table[], unsigned len)
 {
 	const int sockfd = pkt_sock->sockfd;
@@ -348,7 +335,7 @@  int recv_pkt_sock(pkt_sock_t * const pkt_sock,
 /*
  * ODP_PACKET_SOCKET_MMSG:
  */
-int send_pkt_sock(pkt_sock_t * const pkt_sock,
+int send_pkt_sock_mmsg(pkt_sock_t * const pkt_sock,
 		  odp_packet_t pkt_table[], unsigned len)
 {
 	struct mmsghdr msgvec[ODP_PACKET_SOCKET_MAX_BURST_TX];
@@ -387,7 +374,6 @@  int send_pkt_sock(pkt_sock_t * const pkt_sock,
 	return len;
 }
 
-#elif ODP_PACKET_SOCKET_MODE == ODP_PACKET_SOCKET_MMAP
 /*
  * ODP_PACKET_SOCKET_MMAP:
  */
@@ -402,7 +388,7 @@  union frame_map {
 	void *raw;
 };
 
-static int pkt_socket(void)
+static int mmap_pkt_socket(void)
 {
 	int ver = TPACKET_V2;
 
@@ -421,23 +407,23 @@  static int pkt_socket(void)
 	return sock;
 }
 
-static inline int rx_kernel_ready(struct tpacket2_hdr *hdr)
+static inline int mmap_rx_kernel_ready(struct tpacket2_hdr *hdr)
 {
 	return ((hdr->tp_status & TP_STATUS_USER) == TP_STATUS_USER);
 }
 
-static inline void rx_user_ready(struct tpacket2_hdr *hdr)
+static inline void mmap_rx_user_ready(struct tpacket2_hdr *hdr)
 {
 	hdr->tp_status = TP_STATUS_KERNEL;
 	__sync_synchronize();
 }
 
-static inline int tx_kernel_ready(struct tpacket2_hdr *hdr)
+static inline int mmap_tx_kernel_ready(struct tpacket2_hdr *hdr)
 {
 	return !(hdr->tp_status & (TP_STATUS_SEND_REQUEST | TP_STATUS_SENDING));
 }
 
-static inline void tx_user_ready(struct tpacket2_hdr *hdr)
+static inline void mmap_tx_user_ready(struct tpacket2_hdr *hdr)
 {
 	hdr->tp_status = TP_STATUS_SEND_REQUEST;
 	__sync_synchronize();
@@ -462,7 +448,7 @@  static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
 	frame_num = ring->frame_num;
 
 	while (i < len) {
-		if (rx_kernel_ready(ring->rd[frame_num].iov_base)) {
+		if (mmap_rx_kernel_ready(ring->rd[frame_num].iov_base)) {
 			ppd.raw = ring->rd[frame_num].iov_base;
 
 			next_frame_num = (frame_num + 1) % ring->rd_num;
@@ -474,7 +460,7 @@  static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
 			eth_hdr = (struct ethhdr *)pkt_buf;
 			if (odp_unlikely(ethaddrs_equal(if_mac,
 							eth_hdr->h_source))) {
-				rx_user_ready(ppd.raw); /* drop */
+				mmap_rx_user_ready(ppd.raw); /* drop */
 				continue;
 			}
 
@@ -486,7 +472,7 @@  static inline unsigned pkt_mmap_v2_rx(int sock, struct ring *ring,
 				 + frame_offset;
 			memcpy(l2_hdr, pkt_buf, pkt_len);
 
-			rx_user_ready(ppd.raw);
+			mmap_rx_user_ready(ppd.raw);
 
 			/* Parse and set packet header data */
 			odp_packet_parse(pkt_table[i], pkt_len, frame_offset);
@@ -516,7 +502,7 @@  static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
 	frame_num = ring->frame_num;
 
 	while (i < len) {
-		if (tx_kernel_ready(ring->rd[frame_num].iov_base)) {
+		if (mmap_tx_kernel_ready(ring->rd[frame_num].iov_base)) {
 			ppd.raw = ring->rd[frame_num].iov_base;
 
 			next_frame_num = (frame_num + 1) % ring->rd_num;
@@ -530,7 +516,7 @@  static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
 			memcpy((uint8_t *)ppd.raw + TPACKET2_HDRLEN -
 			       sizeof(struct sockaddr_ll), pkt_buf, pkt_len);
 
-			tx_user_ready(ppd.raw);
+			mmap_tx_user_ready(ppd.raw);
 
 			odp_packet_free(pkt_table[i]);
 			frame_num = next_frame_num;
@@ -553,7 +539,7 @@  static inline unsigned pkt_mmap_v2_tx(int sock, struct ring *ring,
 	return i;
 }
 
-static void fill_ring(struct ring *ring, unsigned blocks)
+static void mmap_fill_ring(struct ring *ring, unsigned blocks)
 {
 	ring->req.tp_block_size = getpagesize() << 2;
 	ring->req.tp_frame_size = TPACKET_ALIGNMENT << 7;
@@ -567,7 +553,7 @@  static void fill_ring(struct ring *ring, unsigned blocks)
 	ring->flen = ring->req.tp_frame_size;
 }
 
-static int set_packet_loss_discard(int sock)
+static int mmap_set_packet_loss_discard(int sock)
 {
 	int ret, discard = 1;
 
@@ -581,7 +567,7 @@  static int set_packet_loss_discard(int sock)
 	return 0;
 }
 
-static int setup_ring(int sock, struct ring *ring, int type)
+static int mmap_setup_ring(int sock, struct ring *ring, int type)
 {
 	int ret = 0;
 	unsigned blocks = 256;
@@ -591,12 +577,12 @@  static int setup_ring(int sock, struct ring *ring, int type)
 	ring->version = TPACKET_V2;
 
 	if (type == PACKET_TX_RING) {
-		ret = set_packet_loss_discard(sock);
+		ret = mmap_set_packet_loss_discard(sock);
 		if (ret != 0)
 			return -1;
 	}
 
-	fill_ring(ring, blocks);
+	mmap_fill_ring(ring, blocks);
 
 	ret = setsockopt(sock, SOL_PACKET, type, &ring->req, sizeof(ring->req));
 	if (ret == -1) {
@@ -614,7 +600,7 @@  static int setup_ring(int sock, struct ring *ring, int type)
 	return 0;
 }
 
-static int mmap_sock(pkt_sock_t *pkt_sock)
+static int mmap_sock(pkt_sock_mmap_t *pkt_sock)
 {
 	int i;
 	int sock = pkt_sock->sockfd;
@@ -655,14 +641,14 @@  static int mmap_sock(pkt_sock_t *pkt_sock)
 	return 0;
 }
 
-static void unmap_sock(pkt_sock_t *pkt_sock)
+static void mmap_unmap_sock(pkt_sock_mmap_t *pkt_sock)
 {
 	munmap(pkt_sock->mmap_base, pkt_sock->mmap_len);
 	free(pkt_sock->rx_ring.rd);
 	free(pkt_sock->tx_ring.rd);
 }
 
-static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
+static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, char *netdev)
 {
 	int ret;
 
@@ -684,7 +670,7 @@  static int bind_sock(pkt_sock_t *pkt_sock, char *netdev)
 	return 0;
 }
 
-static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
+static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, char *netdev)
 {
 	struct ifreq ethreq;
 	int ret;
@@ -707,7 +693,7 @@  static int store_hw_addr(pkt_sock_t * const pkt_sock, char *netdev)
 /*
  * ODP_PACKET_SOCKET_MMAP:
  */
-int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
+int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, char *netdev,
 		   odp_buffer_pool_t pool)
 {
 	odp_packet_t pkt;
@@ -733,17 +719,19 @@  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
 	odp_packet_free(pkt);
 
 	pkt_sock->pool = pool;
-	pkt_sock->sockfd = pkt_socket();
+	pkt_sock->sockfd = mmap_pkt_socket();
 
-	ret = bind_sock(pkt_sock, netdev);
+	ret = mmap_bind_sock(pkt_sock, netdev);
 	if (ret != 0)
 		return -1;
 
-	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring, PACKET_TX_RING);
+	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->tx_ring,
+			PACKET_TX_RING);
 	if (ret != 0)
 		return -1;
 
-	ret = setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring, PACKET_RX_RING);
+	ret = mmap_setup_ring(pkt_sock->sockfd, &pkt_sock->rx_ring,
+			PACKET_RX_RING);
 	if (ret != 0)
 		return -1;
 
@@ -751,7 +739,7 @@  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
 	if (ret != 0)
 		return -1;
 
-	ret = store_hw_addr(pkt_sock, netdev);
+	ret = mmap_store_hw_addr(pkt_sock, netdev);
 	if (ret != 0)
 		return -1;
 
@@ -761,7 +749,7 @@  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
 		return -1;
 	}
 
-	ret = set_pkt_sock_fanout(pkt_sock, if_idx);
+	ret = set_pkt_sock_fanout_mmap(pkt_sock, if_idx);
 	if (ret != 0)
 		return -1;
 
@@ -771,9 +759,9 @@  int setup_pkt_sock(pkt_sock_t * const pkt_sock, char *netdev,
 /*
  * ODP_PACKET_SOCKET_MMAP:
  */
-int close_pkt_sock(pkt_sock_t * const pkt_sock)
+int close_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock)
 {
-	unmap_sock(pkt_sock);
+	mmap_unmap_sock(pkt_sock);
 	if (close(pkt_sock->sockfd) != 0) {
 		perror("close_pkt_sock() - close(sockfd)");
 		return -1;
@@ -785,7 +773,7 @@  int close_pkt_sock(pkt_sock_t * const pkt_sock)
 /*
  * ODP_PACKET_SOCKET_MMAP:
  */
-int recv_pkt_sock(pkt_sock_t * const pkt_sock,
+int recv_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
 		  odp_packet_t pkt_table[], unsigned len)
 {
 	return pkt_mmap_v2_rx(pkt_sock->rx_ring.sock, &pkt_sock->rx_ring,
@@ -796,13 +784,9 @@  int recv_pkt_sock(pkt_sock_t * const pkt_sock,
 /*
  * ODP_PACKET_SOCKET_MMAP:
  */
-int send_pkt_sock(pkt_sock_t * const pkt_sock,
+int send_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock,
 		  odp_packet_t pkt_table[], unsigned len)
 {
 	return pkt_mmap_v2_tx(pkt_sock->tx_ring.sock, &pkt_sock->tx_ring,
 			      pkt_table, len);
 }
-
-#else
-#error "Unsupported ODP_PACKET_SOCKET_MODE!"
-#endif
diff --git a/test/packet/odp_example_pktio.c b/test/packet/odp_example_pktio.c
index 85bbdd7..d6c9cd4 100644
--- a/test/packet/odp_example_pktio.c
+++ b/test/packet/odp_example_pktio.c
@@ -111,7 +111,7 @@  static void *pktio_queue_thread(void *arg)
 	}
 
 	/* Open a packet IO instance for this thread */
-	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
+	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
 	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
 	if (pktio == ODP_PKTIO_INVALID) {
 		ODP_ERR("  [%02i] Error: pktio create failed\n", thr);
@@ -223,7 +223,7 @@  static void *pktio_ifburst_thread(void *arg)
 	}
 
 	/* Open a packet IO instance for this thread */
-	sock_params->type = ODP_PKTIO_TYPE_SOCKET;
+	sock_params->type = ODP_PKTIO_TYPE_SOCKET_BASIC;
 	pktio = odp_pktio_open(thr_args->pktio_dev, thr_args->pool, &params);
 	if (pktio == ODP_PKTIO_INVALID) {
 		ODP_ERR("  [%02i] Error: pktio create failed.\n", thr);