diff mbox

[API-NEXT,PATCHv5,3/7] linux-generic: loop: implement pktio_start and pktio_stop

Message ID 1440604147-24703-4-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit cdb9eb6691eaf3ab4d6e0788610203509776d82a
Headers show

Commit Message

Maxim Uvarov Aug. 26, 2015, 3:49 p.m. UTC
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/pktio/loop.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox

Patch

diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c
index 188a9ee..f61ccd5 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loop.c
@@ -18,6 +18,8 @@ 
 #include <odp/helper/eth.h>
 #include <odp/helper/ip.h>
 
+#include <errno.h>
+
 /* MTU to be reported for the "loop" interface */
 #define PKTIO_LOOP_MTU 1500
 /* MAC address for the "loop" interface */
@@ -39,6 +41,7 @@  static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry,
 	if (pktio_entry->s.pkt_loop.loopq == ODP_QUEUE_INVALID)
 		return -1;
 
+	pktio_entry->s.state = STATE_START;
 	return 0;
 }
 
@@ -54,6 +57,11 @@  static int loopback_recv(pktio_entry_t *pktio_entry, odp_packet_t pkts[],
 	odp_buffer_hdr_t *hdr_tbl[QUEUE_MULTI_MAX];
 	queue_entry_t *qentry;
 
+	if (pktio_entry->s.state == STATE_STOP) {
+		__odp_errno = EPERM;
+		return -1;
+	}
+
 	qentry = queue_to_qentry(pktio_entry->s.pkt_loop.loopq);
 	nbr = queue_deq_multi(qentry, hdr_tbl, len);
 
@@ -72,6 +80,11 @@  static int loopback_send(pktio_entry_t *pktio_entry, odp_packet_t pkt_tbl[],
 	queue_entry_t *qentry;
 	unsigned i;
 
+	if (pktio_entry->s.state == STATE_STOP) {
+		__odp_errno = EPERM;
+		return -1;
+	}
+
 	for (i = 0; i < len; ++i)
 		hdr_tbl[i] = odp_buf_to_hdr(_odp_packet_to_buffer(pkt_tbl[i]));
 
@@ -103,11 +116,25 @@  static int loopback_promisc_mode_get(pktio_entry_t *pktio_entry)
 	return pktio_entry->s.pkt_loop.promisc ? 1 : 0;
 }
 
+static int loopback_start(pktio_entry_t *pktio_entry)
+{
+	pktio_entry->s.state = STATE_START;
+	return 0;
+}
+
+static int loopback_stop(pktio_entry_t *pktio_entry)
+{
+	pktio_entry->s.state = STATE_STOP;
+	return 0;
+}
+
 const pktio_if_ops_t loopback_pktio_ops = {
 	.init = NULL,
 	.term = NULL,
 	.open = loopback_open,
 	.close = loopback_close,
+	.start = loopback_start,
+	.stop = loopback_stop,
 	.recv = loopback_recv,
 	.send = loopback_send,
 	.mtu_get = loopback_mtu_get,