diff mbox series

[API-NEXT,4/5] linux-gen: queue: combine queue interface functions

Message ID 20170627132243.17298-5-petri.savolainen@linaro.org
State New
Headers show
Series Queue interface clean up | expand

Commit Message

Petri Savolainen June 27, 2017, 1:22 p.m. UTC
Combine enqueue and dequeue function pointer set functions into
pktin/pktout calls so that queue interface size gets smaller and
code more readable. Also provide single call for TM.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
 platform/linux-generic/include/odp_queue_if.h | 30 +++++++++--------
 platform/linux-generic/odp_packet_io.c        | 44 ++++++++++++-------------
 platform/linux-generic/odp_queue.c            | 46 +++++++++++++--------------
 platform/linux-generic/odp_traffic_mngr.c     |  6 ++--
 4 files changed, 61 insertions(+), 65 deletions(-)

-- 
2.13.0
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_queue_if.h b/platform/linux-generic/include/odp_queue_if.h
index b5cbd515..ad807d75 100644
--- a/platform/linux-generic/include/odp_queue_if.h
+++ b/platform/linux-generic/include/odp_queue_if.h
@@ -61,17 +61,22 @@  typedef int (*queue_enq_multi_fn_t)(queue_t q_int, odp_buffer_hdr_t **, int);
 typedef odp_buffer_hdr_t *(*queue_deq_fn_t)(queue_t q_int);
 typedef int (*queue_deq_multi_fn_t)(queue_t q_int, odp_buffer_hdr_t **, int);
 typedef odp_pktout_queue_t (*queue_get_pktout_fn_t)(queue_t q_int);
-typedef void (*queue_set_pktout_fn_t)(queue_t q_int, odp_pktio_t pktio,
-				      int index);
 typedef odp_pktin_queue_t (*queue_get_pktin_fn_t)(queue_t q_int);
-typedef void (*queue_set_pktin_fn_t)(queue_t q_int, odp_pktio_t pktio,
-				     int index);
-typedef void (*queue_set_enq_fn_t)(queue_t q_int, queue_enq_fn_t func);
-typedef void (*queue_set_enq_multi_fn_t)(queue_t q_int,
-					 queue_enq_multi_fn_t func);
-typedef void (*queue_set_deq_fn_t)(queue_t q_int, queue_deq_fn_t func);
-typedef void (*queue_set_deq_multi_fn_t)(queue_t q_int,
-					 queue_deq_multi_fn_t func);
+typedef void (*queue_set_pktin_fn_t)(odp_queue_t handle, odp_pktio_t pktio,
+				     int idx,
+				     queue_enq_fn_t enq,
+				     queue_enq_multi_fn_t enq_multi,
+				     queue_deq_fn_t deq,
+				     queue_deq_multi_fn_t deq_multi);
+typedef void (*queue_set_pktout_fn_t)(odp_queue_t handle, odp_pktio_t pktio,
+				      int idx,
+				      queue_enq_fn_t enq,
+				      queue_enq_multi_fn_t enq_multi,
+				      queue_deq_fn_t deq,
+				      queue_deq_multi_fn_t deq_multi);
+typedef void (*queue_set_enq_fn_t)(queue_t q_int,
+				   queue_enq_fn_t enq,
+				   queue_enq_multi_fn_t enq_multi);
 typedef void (*queue_set_type_fn_t)(queue_t q_int, odp_queue_type_t type);
 
 /* Queue functions towards other internal components */
@@ -90,10 +95,7 @@  typedef struct {
 	queue_set_pktout_fn_t set_pktout;
 	queue_get_pktin_fn_t get_pktin;
 	queue_set_pktin_fn_t set_pktin;
-	queue_set_enq_fn_t set_enq_fn;
-	queue_set_enq_multi_fn_t set_enq_multi_fn;
-	queue_set_deq_fn_t set_deq_fn;
-	queue_set_deq_multi_fn_t set_deq_multi_fn;
+	queue_set_enq_fn_t set_enq;
 	queue_set_type_fn_t set_type;
 } queue_fn_t;
 
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index f230db01..a48bbafb 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -1156,30 +1156,30 @@  int odp_pktio_stats_reset(odp_pktio_t pktio)
 	return ret;
 }
 
-static int pktin_enqueue(queue_t q_int ODP_UNUSED,
-			 odp_buffer_hdr_t *buf_hdr ODP_UNUSED)
+static int abort_pktin_enqueue(queue_t q_int ODP_UNUSED,
+			       odp_buffer_hdr_t *buf_hdr ODP_UNUSED)
 {
 	ODP_ABORT("attempted enqueue to a pktin queue");
 	return -1;
 }
 
-static int pktin_enq_multi(queue_t q_int ODP_UNUSED,
-			   odp_buffer_hdr_t *buf_hdr[] ODP_UNUSED,
-			   int num ODP_UNUSED)
+static int abort_pktin_enq_multi(queue_t q_int ODP_UNUSED,
+				 odp_buffer_hdr_t *buf_hdr[] ODP_UNUSED,
+				 int num ODP_UNUSED)
 {
 	ODP_ABORT("attempted enqueue to a pktin queue");
 	return 0;
 }
 
-static odp_buffer_hdr_t *pktout_dequeue(queue_t q_int ODP_UNUSED)
+static odp_buffer_hdr_t *abort_pktout_dequeue(queue_t q_int ODP_UNUSED)
 {
 	ODP_ABORT("attempted dequeue from a pktout queue");
 	return NULL;
 }
 
-static int pktout_deq_multi(queue_t q_int ODP_UNUSED,
-			    odp_buffer_hdr_t *buf_hdr[] ODP_UNUSED,
-			    int num ODP_UNUSED)
+static int abort_pktout_deq_multi(queue_t q_int ODP_UNUSED,
+				  odp_buffer_hdr_t *buf_hdr[] ODP_UNUSED,
+				  int num ODP_UNUSED)
 {
 	ODP_ABORT("attempted dequeue from a pktout queue");
 	return 0;
@@ -1273,13 +1273,12 @@  int odp_pktin_queue_config(odp_pktio_t pktio,
 			q_int = queue_fn->from_ext(queue);
 
 			if (mode == ODP_PKTIN_MODE_QUEUE) {
-				queue_fn->set_pktin(q_int, pktio, i);
-				queue_fn->set_enq_fn(q_int, pktin_enqueue);
-				queue_fn->set_deq_fn(q_int, pktin_dequeue);
-				queue_fn->set_enq_multi_fn(q_int,
-							   pktin_enq_multi);
-				queue_fn->set_deq_multi_fn(q_int,
-							   pktin_deq_multi);
+				/* Override default en-/dequeue functions */
+				queue_fn->set_pktin(queue, pktio, i,
+						    abort_pktin_enqueue,
+						    abort_pktin_enq_multi,
+						    pktin_dequeue,
+						    pktin_deq_multi);
 			}
 
 			entry->s.in_queue[i].queue = queue;
@@ -1379,7 +1378,6 @@  int odp_pktout_queue_config(odp_pktio_t pktio,
 		for (i = 0; i < num_queues; i++) {
 			odp_queue_t queue;
 			odp_queue_param_t queue_param;
-			queue_t q_int;
 			char name[ODP_QUEUE_NAME_LEN];
 			int pktio_id = pktio_to_id(pktio);
 
@@ -1399,14 +1397,12 @@  int odp_pktout_queue_config(odp_pktio_t pktio,
 				return -1;
 			}
 
-			q_int = queue_fn->from_ext(queue);
-			queue_fn->set_pktout(q_int, pktio, i);
-
 			/* Override default enqueue / dequeue functions */
-			queue_fn->set_enq_fn(q_int, pktout_enqueue);
-			queue_fn->set_deq_fn(q_int, pktout_dequeue);
-			queue_fn->set_enq_multi_fn(q_int, pktout_enq_multi);
-			queue_fn->set_deq_multi_fn(q_int, pktout_deq_multi);
+			queue_fn->set_pktout(queue, pktio, i,
+					     pktout_enqueue,
+					     pktout_enq_multi,
+					     abort_pktout_dequeue,
+					     abort_pktout_deq_multi);
 
 			entry->s.out_queue[i].queue = queue;
 		}
diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c
index 9d74f092..6cbf1040 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -781,12 +781,18 @@  static odp_pktout_queue_t queue_get_pktout(queue_t q_int)
 	return qentry_from_int(q_int)->s.pktout;
 }
 
-static void queue_set_pktout(queue_t q_int, odp_pktio_t pktio, int index)
+static void queue_set_pktout(odp_queue_t handle, odp_pktio_t pktio, int index,
+			     queue_enq_fn_t enq, queue_enq_multi_fn_t enq_multi,
+			     queue_deq_fn_t deq, queue_deq_multi_fn_t deq_multi)
 {
-	queue_entry_t *qentry = qentry_from_int(q_int);
+	queue_entry_t *qentry = handle_to_qentry(handle);
 
 	qentry->s.pktout.pktio = pktio;
 	qentry->s.pktout.index = index;
+	qentry->s.enqueue       = enq;
+	qentry->s.enqueue_multi = enq_multi;
+	qentry->s.dequeue       = deq;
+	qentry->s.dequeue_multi = deq_multi;
 }
 
 static odp_pktin_queue_t queue_get_pktin(queue_t q_int)
@@ -794,32 +800,27 @@  static odp_pktin_queue_t queue_get_pktin(queue_t q_int)
 	return qentry_from_int(q_int)->s.pktin;
 }
 
-static void queue_set_pktin(queue_t q_int, odp_pktio_t pktio, int index)
+static void queue_set_pktin(odp_queue_t handle, odp_pktio_t pktio, int index,
+			    queue_enq_fn_t enq, queue_enq_multi_fn_t enq_multi,
+			    queue_deq_fn_t deq, queue_deq_multi_fn_t deq_multi)
 {
-	queue_entry_t *qentry = qentry_from_int(q_int);
+	queue_entry_t *qentry = handle_to_qentry(handle);
 
 	qentry->s.pktin.pktio = pktio;
 	qentry->s.pktin.index = index;
+	qentry->s.enqueue       = enq;
+	qentry->s.enqueue_multi = enq_multi;
+	qentry->s.dequeue       = deq;
+	qentry->s.dequeue_multi = deq_multi;
 }
 
-static void queue_set_enq_func(queue_t q_int, queue_enq_fn_t func)
-{
-	qentry_from_int(q_int)->s.enqueue = func;
-}
-
-static void queue_set_enq_multi_func(queue_t q_int, queue_enq_multi_fn_t func)
+static void queue_set_enq(queue_t q_int,
+			  queue_enq_fn_t enq, queue_enq_multi_fn_t enq_multi)
 {
-	qentry_from_int(q_int)->s.enqueue_multi = func;
-}
-
-static void queue_set_deq_func(queue_t q_int, queue_deq_fn_t func)
-{
-	qentry_from_int(q_int)->s.dequeue = func;
-}
+	queue_entry_t *qentry = qentry_from_int(q_int);
 
-static void queue_set_deq_multi_func(queue_t q_int, queue_deq_multi_fn_t func)
-{
-	qentry_from_int(q_int)->s.dequeue_multi = func;
+	qentry->s.enqueue       = enq;
+	qentry->s.enqueue_multi = enq_multi;
 }
 
 static void queue_set_type(queue_t q_int, odp_queue_type_t type)
@@ -875,9 +876,6 @@  queue_fn_t queue_default_fn = {
 	.set_pktout = queue_set_pktout,
 	.get_pktin = queue_get_pktin,
 	.set_pktin = queue_set_pktin,
-	.set_enq_fn = queue_set_enq_func,
-	.set_enq_multi_fn = queue_set_enq_multi_func,
-	.set_deq_fn = queue_set_deq_func,
-	.set_deq_multi_fn = queue_set_deq_multi_func,
+	.set_enq = queue_set_enq,
 	.set_type = queue_set_type
 };
diff --git a/platform/linux-generic/odp_traffic_mngr.c b/platform/linux-generic/odp_traffic_mngr.c
index 8b5f3187..04239884 100644
--- a/platform/linux-generic/odp_traffic_mngr.c
+++ b/platform/linux-generic/odp_traffic_mngr.c
@@ -3927,9 +3927,9 @@  odp_tm_queue_t odp_tm_queue_create(odp_tm_t odp_tm,
 	}
 	tm_queue_obj->tm_qentry = queue_fn->from_ext(queue);
 	queue_fn->set_type(tm_queue_obj->tm_qentry, QUEUE_TYPE_TM);
-	queue_fn->set_enq_fn(tm_queue_obj->tm_qentry, queue_tm_reenq);
-	queue_fn->set_enq_multi_fn(tm_queue_obj->tm_qentry,
-				   queue_tm_reenq_multi);
+	queue_fn->set_enq(tm_queue_obj->tm_qentry,
+			  queue_tm_reenq,
+			  queue_tm_reenq_multi);
 
 	tm_system->queue_num_tbl[tm_queue_obj->queue_num - 1] = tm_queue_obj;
 	odp_ticketlock_lock(&tm_system->tm_system_lock);