aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>2018-05-30 19:14:36 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2018-06-01 23:06:58 +0300
commit7cc7193c74553b5f46db482b6d8c7af599d0464a (patch)
tree0b9e88b339326e4ef6ee715e9680349d635878fb /platform/linux-generic
parent27de124db6343381c25335e611853b487880e9fc (diff)
linux-gen: pktio: make tap use generic private data field
Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform/linux-generic')
-rw-r--r--platform/linux-generic/Makefile.am1
-rw-r--r--platform/linux-generic/include/odp_packet_io_internal.h2
-rw-r--r--platform/linux-generic/include/odp_packet_tap.h21
-rw-r--r--platform/linux-generic/pktio/tap.c47
4 files changed, 32 insertions, 39 deletions
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index ae87d2221..c6f1bafd0 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -113,7 +113,6 @@ noinst_HEADERS = \
include/odp_packet_io_ring_internal.h \
include/odp_packet_null.h \
include/odp_packet_socket.h \
- include/odp_packet_tap.h \
include/odp_pcapng.h \
include/odp_pkt_queue_internal.h \
include/odp_pool_internal.h \
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index 216d71850..702b34f90 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -34,7 +34,6 @@ extern "C" {
#define PKTIO_MAX_QUEUES 64
#include <odp_packet_socket.h>
-#include <odp_packet_tap.h>
#include <odp_packet_null.h>
#define PKTIO_NAME_LEN 256
@@ -106,7 +105,6 @@ struct pktio_entry {
uint8_t chksum_insert_ena; /**< pktout checksum offload enabled */
odp_pktio_t handle; /**< pktio handle */
union {
- pkt_tap_t pkt_tap; /**< using TAP for IO */
_ipc_pktio_t ipc; /**< IPC pktio data */
pkt_null_t pkt_null; /**< using null for IO */
unsigned char ODP_ALIGNED_CACHE pkt_priv[PKTIO_PRIVATE_SIZE];
diff --git a/platform/linux-generic/include/odp_packet_tap.h b/platform/linux-generic/include/odp_packet_tap.h
deleted file mode 100644
index a90bfbce0..000000000
--- a/platform/linux-generic/include/odp_packet_tap.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Copyright (c) 2015, Ilya Maximets <i.maximets@samsung.com>
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef ODP_PACKET_TAP_H_
-#define ODP_PACKET_TAP_H_
-
-#include <odp/api/pool.h>
-
-typedef struct {
- int fd; /**< file descriptor for tap interface*/
- int skfd; /**< socket descriptor */
- uint32_t mtu; /**< cached mtu */
- unsigned char if_mac[ETH_ALEN]; /**< MAC address of pktio side (not a
- MAC address of kernel interface)*/
- odp_pool_t pool; /**< pool to alloc packets from */
-} pkt_tap_t;
-
-#endif
diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c
index a3587f10b..12a1945de 100644
--- a/platform/linux-generic/pktio/tap.c
+++ b/platform/linux-generic/pktio/tap.c
@@ -51,6 +51,23 @@
#define BUF_SIZE 65536
+typedef struct {
+ int fd; /**< file descriptor for tap interface*/
+ int skfd; /**< socket descriptor */
+ uint32_t mtu; /**< cached mtu */
+ unsigned char if_mac[ETH_ALEN]; /**< MAC address of pktio side (not a
+ MAC address of kernel interface)*/
+ odp_pool_t pool; /**< pool to alloc packets from */
+} pkt_tap_t;
+
+ODP_STATIC_ASSERT(PKTIO_PRIVATE_SIZE >= sizeof(pkt_tap_t),
+ "PKTIO_PRIVATE_SIZE too small");
+
+static inline pkt_tap_t *pkt_priv(pktio_entry_t *pktio_entry)
+{
+ return (pkt_tap_t *)(uintptr_t)(pktio_entry->s.pkt_priv);
+}
+
static int gen_random_mac(unsigned char *mac)
{
mac[0] = 0x7a; /* not multicast and local assignment bit is set */
@@ -91,7 +108,7 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED,
int fd, skfd, flags;
uint32_t mtu;
struct ifreq ifr;
- pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+ pkt_tap_t *tap = pkt_priv(pktio_entry);
if (strncmp(devname, "tap:", 4) != 0)
return -1;
@@ -175,7 +192,7 @@ tap_err:
static int tap_pktio_start(pktio_entry_t *pktio_entry)
{
struct ifreq ifr;
- pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+ pkt_tap_t *tap = pkt_priv(pktio_entry);
odp_memset(&ifr, 0, sizeof(ifr));
snprintf(ifr.ifr_name, IF_NAMESIZE, "%s",
@@ -206,7 +223,7 @@ sock_err:
static int tap_pktio_stop(pktio_entry_t *pktio_entry)
{
struct ifreq ifr;
- pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+ pkt_tap_t *tap = pkt_priv(pktio_entry);
odp_memset(&ifr, 0, sizeof(ifr));
snprintf(ifr.ifr_name, IF_NAMESIZE, "%s",
@@ -237,7 +254,7 @@ sock_err:
static int tap_pktio_close(pktio_entry_t *pktio_entry)
{
int ret = 0;
- pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+ pkt_tap_t *tap = pkt_priv(pktio_entry);
if (tap->fd != -1 && close(tap->fd) != 0) {
__odp_errno = errno;
@@ -264,13 +281,13 @@ static odp_packet_t pack_odp_pkt(pktio_entry_t *pktio_entry, const void *data,
if (pktio_cls_enabled(pktio_entry)) {
if (cls_classify_packet(pktio_entry, data, len, len,
- &pktio_entry->s.pkt_tap.pool,
+ &pkt_priv(pktio_entry)->pool,
&parsed_hdr, true)) {
return ODP_PACKET_INVALID;
}
}
- num = packet_alloc_multi(pktio_entry->s.pkt_tap.pool, len, &pkt, 1);
+ num = packet_alloc_multi(pkt_priv(pktio_entry)->pool, len, &pkt, 1);
if (num != 1)
return ODP_PACKET_INVALID;
@@ -302,7 +319,7 @@ static int tap_pktio_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED,
ssize_t retval;
int i;
uint8_t buf[BUF_SIZE];
- pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+ pkt_tap_t *tap = pkt_priv(pktio_entry);
odp_time_t ts_val;
odp_time_t *ts = NULL;
@@ -342,7 +359,7 @@ static int tap_pktio_send_lockless(pktio_entry_t *pktio_entry,
int i, n;
uint32_t pkt_len;
uint8_t buf[BUF_SIZE];
- pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+ pkt_tap_t *tap = pkt_priv(pktio_entry);
for (i = 0; i < num; i++) {
pkt_len = odp_packet_len(pkts[i]);
@@ -405,10 +422,10 @@ static uint32_t tap_mtu_get(pktio_entry_t *pktio_entry)
{
uint32_t ret;
- ret = mtu_get_fd(pktio_entry->s.pkt_tap.skfd,
+ ret = mtu_get_fd(pkt_priv(pktio_entry)->skfd,
pktio_entry->s.name + 4);
if (ret > 0)
- pktio_entry->s.pkt_tap.mtu = ret;
+ pkt_priv(pktio_entry)->mtu = ret;
return ret;
}
@@ -416,25 +433,25 @@ static uint32_t tap_mtu_get(pktio_entry_t *pktio_entry)
static int tap_promisc_mode_set(pktio_entry_t *pktio_entry,
odp_bool_t enable)
{
- return promisc_mode_set_fd(pktio_entry->s.pkt_tap.skfd,
+ return promisc_mode_set_fd(pkt_priv(pktio_entry)->skfd,
pktio_entry->s.name + 4, enable);
}
static int tap_promisc_mode_get(pktio_entry_t *pktio_entry)
{
- return promisc_mode_get_fd(pktio_entry->s.pkt_tap.skfd,
+ return promisc_mode_get_fd(pkt_priv(pktio_entry)->skfd,
pktio_entry->s.name + 4);
}
static int tap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr)
{
- memcpy(mac_addr, pktio_entry->s.pkt_tap.if_mac, ETH_ALEN);
+ memcpy(mac_addr, pkt_priv(pktio_entry)->if_mac, ETH_ALEN);
return ETH_ALEN;
}
static int tap_mac_addr_set(pktio_entry_t *pktio_entry, const void *mac_addr)
{
- pkt_tap_t *tap = &pktio_entry->s.pkt_tap;
+ pkt_tap_t *tap = pkt_priv(pktio_entry);
memcpy(tap->if_mac, mac_addr, ETH_ALEN);
@@ -444,7 +461,7 @@ static int tap_mac_addr_set(pktio_entry_t *pktio_entry, const void *mac_addr)
static int tap_link_status(pktio_entry_t *pktio_entry)
{
- return link_status_fd(pktio_entry->s.pkt_tap.skfd,
+ return link_status_fd(pkt_priv(pktio_entry)->skfd,
pktio_entry->s.name + 4);
}