[API-NEXT,4/6] linux-generic: socket: implement pktio_start and pktio_stop

Message ID 1439466334-16497-5-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Aug. 13, 2015, 11:45 a.m.
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/pktio/socket.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Patch

diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c
index 55c3594..0c56d70 100644
--- a/platform/linux-generic/pktio/socket.c
+++ b/platform/linux-generic/pktio/socket.c
@@ -248,6 +248,7 @@  static int sock_setup_pkt(pktio_entry_t *pktio_entry, const char *netdev,
 		goto error;
 	}
 
+	pktio_entry->s.state = STATE_START;
 	return 0;
 
 error:
@@ -296,6 +297,9 @@  static int sock_basic_recv(pktio_entry_t *pktio_entry,
 	uint8_t *pkt_buf;
 	int nb_rx = 0;
 
+	if (pktio_entry->s.state == STATE_STOP)
+		return 0;
+
 	/*  recvfrom:
 	 *  If the address argument is not a null pointer
 	 *  and the protocol does not provide the source address of
@@ -355,6 +359,9 @@  static int sock_basic_send(pktio_entry_t *pktio_entry,
 	unsigned nb_tx;
 	int ret;
 
+	if (pktio_entry->s.state == STATE_STOP)
+		return 0;
+
 	sockfd = pkt_sock->sockfd;
 	flags = MSG_DONTWAIT;
 	i = 0;
@@ -400,6 +407,9 @@  static int sock_mmsg_recv(pktio_entry_t *pktio_entry,
 	int recv_msgs;
 	int i;
 
+	if (pktio_entry->s.state == STATE_STOP)
+		return 0;
+
 	if (odp_unlikely(len > ODP_PACKET_SOCKET_MAX_BURST_RX))
 		return -1;
 
@@ -465,6 +475,9 @@  static int sock_mmsg_send(pktio_entry_t *pktio_entry,
 	unsigned sent_msgs = 0;
 	unsigned flags;
 
+	if (pktio_entry->s.state == STATE_STOP)
+		return 0;
+
 	if (odp_unlikely(len > ODP_PACKET_SOCKET_MAX_BURST_TX))
 		return -1;
 
@@ -534,11 +547,25 @@  static int sock_promisc_mode_get(pktio_entry_t *pktio_entry)
 				   pktio_entry->s.name);
 }
 
+static int sock_start(pktio_entry_t *pktio_entry)
+{
+	pktio_entry->s.state = STATE_START;
+	return 0;
+}
+
+static int sock_stop(pktio_entry_t *pktio_entry)
+{
+	pktio_entry->s.state = STATE_STOP;
+	return 0;
+}
+
 const pktio_if_ops_t sock_basic_pktio_ops = {
 	.init = NULL,
 	.term = NULL,
 	.open = sock_basic_open,
 	.close = sock_close,
+	.start = sock_start,
+	.stop = sock_stop,
 	.recv = sock_basic_recv,
 	.send = sock_basic_send,
 	.mtu_get = sock_mtu_get,
@@ -552,6 +579,8 @@  const pktio_if_ops_t sock_mmsg_pktio_ops = {
 	.term = NULL,
 	.open = sock_mmsg_open,
 	.close = sock_close,
+	.start = sock_start,
+	.stop = sock_stop,
 	.recv = sock_mmsg_recv,
 	.send = sock_mmsg_send,
 	.mtu_get = sock_mtu_get,