[PATCHv3,5/7] linux-generic: socket: implement pktio_start and pktio_stop

Message ID 1439990341-12037-6-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Aug. 19, 2015, 1:18 p.m.
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 platform/linux-generic/pktio/socket.c | 37 +++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Patch

diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c
index 55c3594..7db9747 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,11 @@  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) {
+		__odp_errno = EPERM;
+		return -1;
+	}
+
 	/*  recvfrom:
 	 *  If the address argument is not a null pointer
 	 *  and the protocol does not provide the source address of
@@ -355,6 +361,11 @@  static int sock_basic_send(pktio_entry_t *pktio_entry,
 	unsigned nb_tx;
 	int ret;
 
+	if (pktio_entry->s.state == STATE_STOP) {
+		__odp_errno = EPERM;
+		return -1;
+	}
+
 	sockfd = pkt_sock->sockfd;
 	flags = MSG_DONTWAIT;
 	i = 0;
@@ -400,6 +411,11 @@  static int sock_mmsg_recv(pktio_entry_t *pktio_entry,
 	int recv_msgs;
 	int i;
 
+	if (pktio_entry->s.state == STATE_STOP) {
+		__odp_errno = EPERM;
+		return -1;
+	}
+
 	if (odp_unlikely(len > ODP_PACKET_SOCKET_MAX_BURST_RX))
 		return -1;
 
@@ -465,6 +481,11 @@  static int sock_mmsg_send(pktio_entry_t *pktio_entry,
 	unsigned sent_msgs = 0;
 	unsigned flags;
 
+	if (pktio_entry->s.state == STATE_STOP) {
+		__odp_errno = EPERM;
+		return -1;
+	}
+
 	if (odp_unlikely(len > ODP_PACKET_SOCKET_MAX_BURST_TX))
 		return -1;
 
@@ -534,11 +555,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 +587,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,