diff mbox series

[CLOUD-DEV,v5,6/10] linux-gen: pktio: netmap: minor code refactory

Message ID 1505898014-18011-7-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [CLOUD-DEV,v5,1/10] framework: modular: extern SUBSYSTEM_FOREACH_TEMPLATE | expand

Commit Message

Github ODP bot Sept. 20, 2017, 9 a.m. UTC
From: Yi He <yi.he@linaro.org>


Move implementation specific data structure
into dedicated header file.

Signed-off-by: Yi He <yi.he@linaro.org>

Reviewed-by: Brian Brooks <brian.brooks@arm.com>

Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>

Reviewed-by: Bogdan Pricope <bogdan.pricope@linaro.org>

Reviewed-by: Josep Puigdemont <josep.puigdemont@linaro.org>

Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>

---
/** Email created from pull request 139 (heyi-linaro:modular-pktio-ops)
 ** https://github.com/Linaro/odp/pull/139
 ** Patch: https://github.com/Linaro/odp/pull/139.patch
 ** Base sha: c6a520126eff39b7ebce8e790fb960259ce8f812
 ** Merge commit sha: 8d7f8c3de9639acb3a2b8eb8c3830c044eb6a437
 **/
 platform/linux-generic/Makefile.am                 |  2 +-
 .../linux-generic/include/odp_packet_io_internal.h |  2 -
 ...{odp_packet_netmap.h => odp_pktio_ops_netmap.h} |  6 +-
 .../include/odp_pktio_ops_subsystem.h              |  2 +
 platform/linux-generic/pktio/netmap.c              | 89 ++++++++++++----------
 5 files changed, 56 insertions(+), 45 deletions(-)
 rename platform/linux-generic/include/{odp_packet_netmap.h => odp_pktio_ops_netmap.h} (96%)
diff mbox series

Patch

diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index 5c4d02a3d..7911a91f5 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -186,12 +186,12 @@  noinst_HEADERS = \
 		  ${srcdir}/include/odp_packet_internal.h \
 		  ${srcdir}/include/odp_packet_io_internal.h \
 		  ${srcdir}/include/odp_packet_io_ring_internal.h \
-		  ${srcdir}/include/odp_packet_netmap.h \
 		  ${srcdir}/include/odp_packet_dpdk.h \
 		  ${srcdir}/include/odp_packet_socket.h \
 		  ${srcdir}/include/odp_packet_tap.h \
 		  ${srcdir}/include/odp_pktio_ops_ipc.h \
 		  ${srcdir}/include/odp_pktio_ops_loopback.h \
+		  ${srcdir}/include/odp_pktio_ops_netmap.h \
 		  ${srcdir}/include/odp_pktio_ops_subsystem.h \
 		  ${srcdir}/include/odp_pkt_queue_internal.h \
 		  ${srcdir}/include/odp_queue_subsystem.h \
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index 8d3c3ddff..af826b7e7 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -32,7 +32,6 @@  extern "C" {
 
 #define PKTIO_MAX_QUEUES 64
 #include <odp_packet_socket.h>
-#include <odp_packet_netmap.h>
 #include <odp_packet_tap.h>
 #include <odp_packet_dpdk.h>
 
@@ -78,7 +77,6 @@  struct pktio_entry {
 		pkt_sock_t pkt_sock;		/**< using socket API for IO */
 		pkt_sock_mmap_t pkt_sock_mmap;	/**< using socket mmap
 						 *   API for IO */
-		pkt_netmap_t pkt_nm;		/**< using netmap API for IO */
 		pkt_dpdk_t pkt_dpdk;		/**< using DPDK for IO */
 #ifdef HAVE_PCAP
 		pkt_pcap_t pkt_pcap;		/**< Using pcap for IO */
diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_pktio_ops_netmap.h
similarity index 96%
rename from platform/linux-generic/include/odp_packet_netmap.h
rename to platform/linux-generic/include/odp_pktio_ops_netmap.h
index a6f68d569..35592d85f 100644
--- a/platform/linux-generic/include/odp_packet_netmap.h
+++ b/platform/linux-generic/include/odp_pktio_ops_netmap.h
@@ -4,8 +4,8 @@ 
  * SPDX-License-Identifier:     BSD-3-Clause
  */
 
-#ifndef ODP_PACKET_NETMAP_H
-#define ODP_PACKET_NETMAP_H
+#ifndef ODP_PKTIO_OPS_NETMAP_H_
+#define ODP_PKTIO_OPS_NETMAP_H_
 
 #include <odp/api/align.h>
 #include <odp/api/debug.h>
@@ -63,6 +63,6 @@  typedef struct {
 	netmap_ring_t rx_desc_ring[PKTIO_MAX_QUEUES];
 	/** mapping of pktout queues to netmap tx descriptors */
 	netmap_ring_t tx_desc_ring[PKTIO_MAX_QUEUES];
-} pkt_netmap_t;
+} pktio_ops_netmap_data_t;
 
 #endif
diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h
index 650b36648..b1b735ced 100644
--- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h
+++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h
@@ -81,6 +81,7 @@  typedef ODP_MODULE_CLASS(pktio_ops) {
 /* All implementations of this subsystem */
 #include <odp_pktio_ops_ipc.h>
 #include <odp_pktio_ops_loopback.h>
+#include <odp_pktio_ops_netmap.h>
 
 /* Per implementation private data
  * TODO: refactory each implementation to hide it internally
@@ -88,6 +89,7 @@  typedef ODP_MODULE_CLASS(pktio_ops) {
 typedef union {
 	pktio_ops_ipc_data_t ipc;
 	pktio_ops_loopback_data_t loopback;
+	pktio_ops_netmap_data_t netmap;
 } pktio_ops_data_t;
 
 /* Extract pktio ops data from pktio entry structure */
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index c75f8be97..accac61c6 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -12,7 +12,6 @@ 
 #include <odp/api/packet.h>
 
 #include <odp_packet_io_internal.h>
-#include <odp_packet_netmap.h>
 #include <odp_packet_socket.h>
 #include <odp_debug_internal.h>
 #include <protocols/eth.h>
@@ -46,15 +45,16 @@  static int netmap_stats_reset(pktio_entry_t *pktio_entry);
 static int netmap_do_ioctl(pktio_entry_t *pktio_entry, unsigned long cmd,
 			   int subcmd)
 {
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 	struct ethtool_value eval;
 	struct ifreq ifr;
 	int err;
 	int fd = pkt_nm->sockfd;
 
 	memset(&ifr, 0, sizeof(ifr));
-	snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s",
-		 pktio_entry->s.pkt_nm.if_name);
+	snprintf(ifr.ifr_name, sizeof(ifr.ifr_name),
+		 "%s", pkt_nm->if_name);
 
 	switch (cmd) {
 	case SIOCSIFFLAGS:
@@ -133,7 +133,8 @@  static inline void map_netmap_rings(netmap_ring_t *rings,
 static int netmap_input_queues_config(pktio_entry_t *pktio_entry,
 				      const odp_pktin_queue_param_t *p)
 {
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 	odp_pktin_mode_t mode = pktio_entry->s.param.in_mode;
 	unsigned num_queues = p->num_queues;
 	odp_bool_t lockless;
@@ -146,8 +147,7 @@  static int netmap_input_queues_config(pktio_entry_t *pktio_entry,
 		lockless = (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE);
 
 	if (p->hash_enable && num_queues > 1) {
-		if (rss_conf_set_fd(pktio_entry->s.pkt_nm.sockfd,
-				    pktio_entry->s.pkt_nm.if_name,
+		if (rss_conf_set_fd(pkt_nm->sockfd, pkt_nm->if_name,
 				    &p->hash_proto)) {
 			ODP_ERR("Failed to configure input hash\n");
 			return -1;
@@ -162,7 +162,8 @@  static int netmap_input_queues_config(pktio_entry_t *pktio_entry,
 static int netmap_output_queues_config(pktio_entry_t *pktio_entry,
 				       const odp_pktout_queue_param_t *p)
 {
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 
 	pkt_nm->lockless_tx = (p->op_mode == ODP_PKTIO_OP_MT_UNSAFE);
 
@@ -179,7 +180,8 @@  static int netmap_output_queues_config(pktio_entry_t *pktio_entry,
 static inline void netmap_close_descriptors(pktio_entry_t *pktio_entry)
 {
 	int i, j;
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 
 	for (i = 0; i < PKTIO_MAX_QUEUES; i++) {
 		for (j = 0; j < NM_MAX_DESC; j++) {
@@ -202,7 +204,8 @@  static inline void netmap_close_descriptors(pktio_entry_t *pktio_entry)
 
 static int netmap_close(pktio_entry_t *pktio_entry)
 {
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 
 	netmap_close_descriptors(pktio_entry);
 
@@ -216,11 +219,11 @@  static int netmap_close(pktio_entry_t *pktio_entry)
 
 static int netmap_link_status(pktio_entry_t *pktio_entry)
 {
-	if (pktio_entry->s.pkt_nm.is_virtual)
+	if (pktio_entry->ops_data(netmap).is_virtual)
 		return 1;
 
-	return link_status_fd(pktio_entry->s.pkt_nm.sockfd,
-			      pktio_entry->s.pkt_nm.if_name);
+	return link_status_fd(pktio_entry->ops_data(netmap).sockfd,
+			      pktio_entry->ops_data(netmap).if_name);
 }
 
 /**
@@ -247,12 +250,12 @@  static inline int netmap_wait_for_link(pktio_entry_t *pktio_entry)
 		 * until the opposing end's interface comes back up again. In
 		 * this case without the additional sleep pktio validation
 		 * tests fail. */
-		if (!pktio_entry->s.pkt_nm.is_virtual)
+		if (!pktio_entry->ops_data(netmap).is_virtual)
 			sleep(1);
 		if (ret == 1)
 			return 1;
 	}
-	ODP_DBG("%s link is down\n", pktio_entry->s.pkt_nm.if_name);
+	ODP_DBG("%s link is down\n", pktio_entry->ops_data(netmap).if_name);
 	return 0;
 }
 
@@ -263,7 +266,8 @@  static inline int netmap_wait_for_link(pktio_entry_t *pktio_entry)
  */
 static void netmap_init_capability(pktio_entry_t *pktio_entry)
 {
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 	odp_pktio_capability_t *capa = &pkt_nm->capa;
 
 	memset(&pkt_nm->capa, 0, sizeof(odp_pktio_capability_t));
@@ -330,7 +334,8 @@  static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry,
 	const char *prefix;
 	uint32_t mtu;
 	uint32_t buf_size;
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 	struct nm_desc *desc;
 	struct netmap_ring *ring;
 	odp_pktin_hash_proto_t hash_proto;
@@ -407,7 +412,7 @@  static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry,
 
 	/* Use either interface MTU (+ ethernet header length) or netmap buffer
 	 * size as MTU, whichever is smaller. */
-	mtu = mtu_get_fd(pktio_entry->s.pkt_nm.sockfd, pkt_nm->if_name);
+	mtu = mtu_get_fd(pkt_nm->sockfd, pkt_nm->if_name);
 	if (mtu == 0) {
 		ODP_ERR("Unable to read interface MTU\n");
 		goto error;
@@ -432,7 +437,7 @@  static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry,
 		goto error;
 
 	/* netmap uses only ethtool to get statistics counters */
-	err = ethtool_stats_get_fd(pktio_entry->s.pkt_nm.sockfd,
+	err = ethtool_stats_get_fd(pkt_nm->sockfd,
 				   pkt_nm->if_name, &cur_stats);
 	if (err) {
 		ODP_ERR("netmap pktio %s does not support statistics counters\n",
@@ -453,7 +458,8 @@  static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry,
 
 static int netmap_start(pktio_entry_t *pktio_entry)
 {
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 	netmap_ring_t *desc_ring;
 	struct nm_desc *desc_ptr;
 	unsigned i;
@@ -610,7 +616,7 @@  static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry,
 				    odp_time_t *ts)
 {
 	odp_packet_t pkt;
-	odp_pool_t pool = pktio_entry->s.pkt_nm.pool;
+	odp_pool_t pool = pktio_entry->ops_data(netmap).pool;
 	odp_packet_hdr_t *pkt_hdr;
 	odp_packet_hdr_t parsed_hdr;
 	int i;
@@ -618,7 +624,7 @@  static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry,
 	int alloc_len;
 
 	/* Allocate maximum sized packets */
-	alloc_len = pktio_entry->s.pkt_nm.mtu;
+	alloc_len = pktio_entry->ops_data(netmap).mtu;
 
 	num = packet_alloc_multi(pool, alloc_len, pkt_tbl, slot_num);
 
@@ -631,9 +637,10 @@  static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry,
 
 		odp_prefetch(slot.buf);
 
-		if (odp_unlikely(len > pktio_entry->s.pkt_nm.max_frame_len)) {
+		if (odp_unlikely(len > pktio_entry->
+				 ops_data(netmap).max_frame_len)) {
 			ODP_ERR("RX: frame too big %" PRIu16 " %zu!\n", len,
-				pktio_entry->s.pkt_nm.max_frame_len);
+				pktio_entry->ops_data(netmap).max_frame_len);
 			goto fail;
 		}
 
@@ -729,7 +736,8 @@  static int netmap_recv(pktio_entry_t *pktio_entry, int index,
 		       odp_packet_t pkt_table[], int num)
 {
 	struct nm_desc *desc;
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 	unsigned first_desc_id = pkt_nm->rx_desc_ring[index].s.first;
 	unsigned last_desc_id = pkt_nm->rx_desc_ring[index].s.last;
 	unsigned desc_id;
@@ -782,7 +790,8 @@  static int netmap_recv(pktio_entry_t *pktio_entry, int index,
 static int netmap_send(pktio_entry_t *pktio_entry, int index,
 		       const odp_packet_t pkt_table[], int num)
 {
-	pkt_netmap_t *pkt_nm = &pktio_entry->s.pkt_nm;
+	pktio_ops_netmap_data_t *pkt_nm =
+		&pktio_entry->ops_data(netmap);
 	struct pollfd polld;
 	struct nm_desc *desc;
 	struct netmap_ring *ring;
@@ -857,40 +866,42 @@  static int netmap_send(pktio_entry_t *pktio_entry, int index,
 
 static int netmap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr)
 {
-	memcpy(mac_addr, pktio_entry->s.pkt_nm.if_mac, ETH_ALEN);
+	memcpy(mac_addr, pktio_entry->ops_data(netmap).if_mac, ETH_ALEN);
 	return ETH_ALEN;
 }
 
 static uint32_t netmap_mtu_get(pktio_entry_t *pktio_entry)
 {
-	return pktio_entry->s.pkt_nm.mtu;
+	return pktio_entry->ops_data(netmap).mtu;
 }
 
 static int netmap_promisc_mode_set(pktio_entry_t *pktio_entry,
 				   odp_bool_t enable)
 {
-	if (pktio_entry->s.pkt_nm.is_virtual) {
+	if (pktio_entry->ops_data(netmap).is_virtual) {
 		__odp_errno = ENOTSUP;
 		return -1;
 	}
 
-	return promisc_mode_set_fd(pktio_entry->s.pkt_nm.sockfd,
-				   pktio_entry->s.pkt_nm.if_name, enable);
+	return promisc_mode_set_fd(
+		pktio_entry->ops_data(netmap).sockfd,
+		pktio_entry->ops_data(netmap).if_name, enable);
 }
 
 static int netmap_promisc_mode_get(pktio_entry_t *pktio_entry)
 {
-	if (pktio_entry->s.pkt_nm.is_virtual)
+	if (pktio_entry->ops_data(netmap).is_virtual)
 		return 0;
 
-	return promisc_mode_get_fd(pktio_entry->s.pkt_nm.sockfd,
-				   pktio_entry->s.pkt_nm.if_name);
+	return promisc_mode_get_fd(
+		pktio_entry->ops_data(netmap).sockfd,
+		pktio_entry->ops_data(netmap).if_name);
 }
 
 static int netmap_capability(pktio_entry_t *pktio_entry,
 			     odp_pktio_capability_t *capa)
 {
-	*capa = pktio_entry->s.pkt_nm.capa;
+	*capa = pktio_entry->ops_data(netmap).capa;
 	return 0;
 }
 
@@ -904,7 +915,7 @@  static int netmap_stats(pktio_entry_t *pktio_entry,
 
 	return sock_stats_fd(pktio_entry,
 			     stats,
-			     pktio_entry->s.pkt_nm.sockfd);
+			     pktio_entry->ops_data(netmap).sockfd);
 }
 
 static int netmap_stats_reset(pktio_entry_t *pktio_entry)
@@ -916,15 +927,15 @@  static int netmap_stats_reset(pktio_entry_t *pktio_entry)
 	}
 
 	return sock_stats_reset_fd(pktio_entry,
-				   pktio_entry->s.pkt_nm.sockfd);
+				   pktio_entry->ops_data(netmap).sockfd);
 }
 
 static void netmap_print(pktio_entry_t *pktio_entry)
 {
 	odp_pktin_hash_proto_t hash_proto;
 
-	if (rss_conf_get_fd(pktio_entry->s.pkt_nm.sockfd,
-			    pktio_entry->s.pkt_nm.if_name, &hash_proto))
+	if (rss_conf_get_fd(pktio_entry->ops_data(netmap).sockfd,
+			    pktio_entry->ops_data(netmap).if_name, &hash_proto))
 		rss_conf_print(&hash_proto);
 }