diff mbox series

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

Message ID 1505898014-18011-5-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>


Rename the source as loopback.c, move implementation
specific data structure into dedicated header file.

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

Signed-off-by: Balakrishna Garapati <balakrishna.garapati@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-dpdk/Makefile.am                         |  3 ++-
 platform/linux-dpdk/include/odp_packet_io_internal.h    |  7 +------
 platform/linux-generic/Makefile.am                      |  3 ++-
 platform/linux-generic/include/odp_packet_io_internal.h |  7 +------
 platform/linux-generic/include/odp_pktio_ops_loopback.h | 17 +++++++++++++++++
 .../linux-generic/include/odp_pktio_ops_subsystem.h     | 13 +++++++++++++
 platform/linux-generic/pktio/{loop.c => loopback.c}     | 14 +++++++-------
 7 files changed, 43 insertions(+), 21 deletions(-)
 create mode 100644 platform/linux-generic/include/odp_pktio_ops_loopback.h
 rename platform/linux-generic/pktio/{loop.c => loopback.c} (94%)
diff mbox series

Patch

diff --git a/platform/linux-dpdk/Makefile.am b/platform/linux-dpdk/Makefile.am
index 2ff44316e..9d13ec1ca 100644
--- a/platform/linux-dpdk/Makefile.am
+++ b/platform/linux-dpdk/Makefile.am
@@ -191,6 +191,7 @@  noinst_HEADERS = \
 		  ${srcdir}/include/odp_packet_dpdk.h \
 		  ${srcdir}/include/odp_packet_internal.h \
 		  ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_subsystem.h \
+		  ${top_srcdir}/platform/linux-generic/include/odp_pktio_ops_loopback.h \
 		  ${top_srcdir}/platform/linux-generic/include/odp_name_table_internal.h \
 		  ${srcdir}/include/odp_packet_io_internal.h \
 		  ${srcdir}/include/odp_errno_define.h \
@@ -248,7 +249,7 @@  __LIB__libodp_dpdk_la_SOURCES = \
 			   pktio/subsystem.c \
 			   odp_packet_flags.c \
 			   ../linux-generic/odp_packet_io.c \
-			   ../linux-generic/pktio/loop.c \
+			   ../linux-generic/pktio/loopback.c \
 			   ../linux-generic/odp_pkt_queue.c \
 			   pool/dpdk.c \
 			   ../linux-generic/odp_queue_if.c \
diff --git a/platform/linux-dpdk/include/odp_packet_io_internal.h b/platform/linux-dpdk/include/odp_packet_io_internal.h
index fde172fc5..ba388c9c2 100644
--- a/platform/linux-dpdk/include/odp_packet_io_internal.h
+++ b/platform/linux-dpdk/include/odp_packet_io_internal.h
@@ -43,11 +43,6 @@  typedef union pktio_entry_u pktio_entry_t;
 /* Forward declaration */
 struct pkt_dpdk_t;
 
-typedef struct {
-	odp_queue_t loopq;		/**< loopback queue for "loop" device */
-	odp_bool_t promisc;		/**< promiscuous mode state */
-} pkt_loop_t;
-
 /** Packet socket using dpdk mmaped rings for both Rx and Tx */
 typedef struct {
 	odp_pktio_capability_t	capa;	  /**< interface capabilities */
@@ -67,13 +62,13 @@  typedef struct {
 
 struct pktio_entry {
 	const pktio_ops_module_t *ops;	/**< Implementation specific methods */
+	pktio_ops_data_t ops_data;
 	/* These two locks together lock the whole pktio device */
 	odp_ticketlock_t rxl;		/**< RX ticketlock */
 	odp_ticketlock_t txl;		/**< TX ticketlock */
 	int cls_enabled;		/**< is classifier enabled */
 	odp_pktio_t handle;		/**< pktio handle */
 	union {
-		pkt_loop_t pkt_loop;	/**< Using loopback for IO */
 		pkt_dpdk_t pkt_dpdk;	/**< using DPDK API for IO */
 	};
 	enum {
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am
index ad6f14450..68fc246ab 100644
--- a/platform/linux-generic/Makefile.am
+++ b/platform/linux-generic/Makefile.am
@@ -191,6 +191,7 @@  noinst_HEADERS = \
 		  ${srcdir}/include/odp_packet_dpdk.h \
 		  ${srcdir}/include/odp_packet_socket.h \
 		  ${srcdir}/include/odp_packet_tap.h \
+		  ${srcdir}/include/odp_pktio_ops_loopback.h \
 		  ${srcdir}/include/odp_pktio_ops_subsystem.h \
 		  ${srcdir}/include/odp_pkt_queue_internal.h \
 		  ${srcdir}/include/odp_queue_subsystem.h \
@@ -267,7 +268,7 @@  __LIB__libodp_linux_la_SOURCES = \
 			   pktio/subsystem.c \
 			   pktio/ipc.c \
 			   pktio/pktio_common.c \
-			   pktio/loop.c \
+			   pktio/loopback.c \
 			   pktio/netmap.c \
 			   pktio/dpdk.c \
 			   pktio/socket.c \
diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index 589148400..893fa1144 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -51,11 +51,6 @@  typedef union pktio_entry_u pktio_entry_t;
  *  requested number of packets were not handled. */
 #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR)
 
-typedef struct {
-	odp_queue_t loopq;		/**< loopback queue for "loop" device */
-	odp_bool_t promisc;		/**< promiscuous mode state */
-} pkt_loop_t;
-
 #ifdef HAVE_PCAP
 typedef struct {
 	char *fname_rx;		/**< name of pcap file for rx */
@@ -111,13 +106,13 @@  typedef	struct {
 
 struct pktio_entry {
 	const pktio_ops_module_t *ops;	/**< Implementation specific methods */
+	pktio_ops_data_t ops_data;	/**< IO operation specific data */
 	/* These two locks together lock the whole pktio device */
 	odp_ticketlock_t rxl;		/**< RX ticketlock */
 	odp_ticketlock_t txl;		/**< TX ticketlock */
 	int cls_enabled;		/**< is classifier enabled */
 	odp_pktio_t handle;		/**< pktio handle */
 	union {
-		pkt_loop_t pkt_loop;            /**< Using loopback for IO */
 		pkt_sock_t pkt_sock;		/**< using socket API for IO */
 		pkt_sock_mmap_t pkt_sock_mmap;	/**< using socket mmap
 						 *   API for IO */
diff --git a/platform/linux-generic/include/odp_pktio_ops_loopback.h b/platform/linux-generic/include/odp_pktio_ops_loopback.h
new file mode 100644
index 000000000..932459472
--- /dev/null
+++ b/platform/linux-generic/include/odp_pktio_ops_loopback.h
@@ -0,0 +1,17 @@ 
+/* Copyright (c) 2017, ARM Limited. All rights reserved.
+ *
+ * Copyright (c) 2017, Linaro Limited
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef ODP_PKTIO_OPS_LOOPBACK_H_
+#define ODP_PKTIO_OPS_LOOPBACK_H_
+
+typedef struct {
+	odp_queue_t loopq;  /**< loopback queue for "loop" device */
+	odp_bool_t promisc; /**< promiscuous mode state */
+} pktio_ops_loopback_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 ff497a2ac..7b90ed3d3 100644
--- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h
+++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h
@@ -78,4 +78,17 @@  typedef ODP_MODULE_CLASS(pktio_ops) {
 	odp_api_proto(pktio_ops, print) print;
 } pktio_ops_module_t;
 
+/* All implementations of this subsystem */
+#include <odp_pktio_ops_loopback.h>
+
+/* Per implementation private data
+ * TODO: refactory each implementation to hide it internally
+ */
+typedef union {
+	pktio_ops_loopback_data_t loopback;
+} pktio_ops_data_t;
+
+/* Extract pktio ops data from pktio entry structure */
+#define ops_data(mod) s.ops_data.mod
+
 #endif
diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loopback.c
similarity index 94%
rename from platform/linux-generic/pktio/loop.c
rename to platform/linux-generic/pktio/loopback.c
index 3e6b41f80..3d4c764ab 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loopback.c
@@ -35,10 +35,10 @@  static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry,
 
 	snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loopq",
 		 odp_pktio_to_u64(id));
-	pktio_entry->s.pkt_loop.loopq =
+	pktio_entry->ops_data(loopback).loopq =
 		odp_queue_create(loopq_name, NULL);
 
-	if (pktio_entry->s.pkt_loop.loopq == ODP_QUEUE_INVALID)
+	if (pktio_entry->ops_data(loopback).loopq == ODP_QUEUE_INVALID)
 		return -1;
 
 	loopback_stats_reset(pktio_entry);
@@ -48,7 +48,7 @@  static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry,
 
 static int loopback_close(pktio_entry_t *pktio_entry)
 {
-	return odp_queue_destroy(pktio_entry->s.pkt_loop.loopq);
+	return odp_queue_destroy(pktio_entry->ops_data(loopback).loopq);
 }
 
 static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED,
@@ -70,7 +70,7 @@  static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED,
 
 	odp_ticketlock_lock(&pktio_entry->s.rxl);
 
-	queue = queue_fn->from_ext(pktio_entry->s.pkt_loop.loopq);
+	queue = queue_fn->from_ext(pktio_entry->ops_data(loopback).loopq);
 	nbr = queue_fn->deq_multi(queue, hdr_tbl, len);
 
 	if (pktio_entry->s.config.pktin.bit.ts_all ||
@@ -170,7 +170,7 @@  static int loopback_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED,
 
 	odp_ticketlock_lock(&pktio_entry->s.txl);
 
-	queue = queue_fn->from_ext(pktio_entry->s.pkt_loop.loopq);
+	queue = queue_fn->from_ext(pktio_entry->ops_data(loopback).loopq);
 	ret = queue_fn->enq_multi(queue, hdr_tbl, len);
 
 	if (ret > 0) {
@@ -223,13 +223,13 @@  static int loopback_capability(pktio_entry_t *pktio_entry ODP_UNUSED,
 static int loopback_promisc_mode_set(pktio_entry_t *pktio_entry,
 				     odp_bool_t enable)
 {
-	pktio_entry->s.pkt_loop.promisc = enable;
+	pktio_entry->ops_data(loopback).promisc = enable;
 	return 0;
 }
 
 static int loopback_promisc_mode_get(pktio_entry_t *pktio_entry)
 {
-	return pktio_entry->s.pkt_loop.promisc ? 1 : 0;
+	return pktio_entry->ops_data(loopback).promisc ? 1 : 0;
 }
 
 static int loopback_stats(pktio_entry_t *pktio_entry,