diff mbox

[API-NEXT,2/6] linux-generic: loop: implement pktio_start and pktio_stop

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

Commit Message

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

Comments

Bill Fischofer Aug. 13, 2015, 12:44 p.m. UTC | #1
On Thu, Aug 13, 2015 at 6:45 AM, Maxim Uvarov <maxim.uvarov@linaro.org>
wrote:

> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>  platform/linux-generic/pktio/loop.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/platform/linux-generic/pktio/loop.c
> b/platform/linux-generic/pktio/loop.c
> index 188a9ee..8c45e47 100644
> --- a/platform/linux-generic/pktio/loop.c
> +++ b/platform/linux-generic/pktio/loop.c
> @@ -39,6 +39,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 +55,9 @@ 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)
> +               return 0;
> +
>         qentry = queue_to_qentry(pktio_entry->s.pkt_loop.loopq);
>         nbr = queue_deq_multi(qentry, hdr_tbl, len);
>
> @@ -72,6 +76,9 @@ 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)
> +               return 0;
> +
>

Shouldn't this be an error return?  If I call a send function and it does
nothing and returns 0 ("OK") then those buffers are going to be leaked, no?


>         for (i = 0; i < len; ++i)
>                 hdr_tbl[i] =
> odp_buf_to_hdr(_odp_packet_to_buffer(pkt_tbl[i]));
>
> @@ -103,11 +110,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,
> --
> 1.9.1
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
Maxim Uvarov Aug. 13, 2015, 3:21 p.m. UTC | #2
On 08/13/15 15:44, Bill Fischofer wrote:
>
>     @@ -72,6 +76,9 @@ 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)
>     +               return 0;
>     +
>
>
> Shouldn't this be an error return?  If I call a send function and it 
> does nothing and returns 0 ("OK") then those buffers are going to be 
> leaked, no?

Yes, I should about what to return here. If it's 0 that means 0 packets 
were transmitted, and 0 packet were free by platform. So application should
take care what to do with it.

But yes, agree that we need to give app some feedback that transmission 
fails due to stopped pktio.
Something like

__odp_errno == -EPERM;
return -1;

For read path, more likely we need the same thing.

Maxim.
diff mbox

Patch

diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c
index 188a9ee..8c45e47 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loop.c
@@ -39,6 +39,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 +55,9 @@  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)
+		return 0;
+
 	qentry = queue_to_qentry(pktio_entry->s.pkt_loop.loopq);
 	nbr = queue_deq_multi(qentry, hdr_tbl, len);
 
@@ -72,6 +76,9 @@  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)
+		return 0;
+
 	for (i = 0; i < len; ++i)
 		hdr_tbl[i] = odp_buf_to_hdr(_odp_packet_to_buffer(pkt_tbl[i]));
 
@@ -103,11 +110,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,