diff mbox

[7/9] linux-generic: netmap: support segmented packets

Message ID 1446060551-21029-8-git-send-email-stuart.haslam@linaro.org
State Superseded
Headers show

Commit Message

Stuart Haslam Oct. 28, 2015, 7:29 p.m. UTC
Replace the nm_inject() helper with our own version so that
odp_packet_copydata_out() can be used as this understands segmented
packets.

Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
---
 platform/linux-generic/pktio/netmap.c | 59 ++++++++++++++++++++++++++++++++---
 1 file changed, 54 insertions(+), 5 deletions(-)

Comments

Maxim Uvarov Oct. 29, 2015, 11:54 a.m. UTC | #1
On 10/28/2015 22:29, Stuart Haslam wrote:
> Replace the nm_inject() helper with our own version so that
> odp_packet_copydata_out() can be used as this understands segmented
> packets.
>
> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
> ---
>   platform/linux-generic/pktio/netmap.c | 59 ++++++++++++++++++++++++++++++++---
>   1 file changed, 54 insertions(+), 5 deletions(-)
>
> diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
> index 7d47fc1..d72af3d 100644
> --- a/platform/linux-generic/pktio/netmap.c
> +++ b/platform/linux-generic/pktio/netmap.c
> @@ -268,32 +268,81 @@ static int netmap_recv(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
>   	return args.nb_rx;
>   }
>   
> +static struct netmap_ring *netmap_tx_ring(struct nm_desc *d)
> +{
> +	unsigned c, n = d->last_tx_ring - d->first_tx_ring + 1;
> +
> +	for (c = 0; c < n ; c++) {
why c and not i as everywhere? Also can n be some read friendly name, 
like num_rings?

Maxim.
> +		struct netmap_ring *ring;
> +		unsigned ri = d->cur_tx_ring + c;
> +
> +		if (ri > d->last_tx_ring)
> +			ri = d->first_tx_ring;
> +		ring = NETMAP_TXRING(d->nifp, ri);
> +		if (nm_ring_empty(ring))
> +			continue;
> +
> +		return ring;
> +	}
> +
> +	return NULL;
> +}
> +
> +static int netmap_inject(struct nm_desc *d, odp_packet_t pkt)
> +{
> +	struct netmap_ring *ring;
> +	unsigned i;
> +	uint32_t pkt_len = odp_packet_len(pkt);
> +	uint32_t offset = 0;
> +	char *buf;
> +
> +	ring = netmap_tx_ring(d);
> +	if (!ring)
> +		return 0;
> +
> +	if (pkt_len > ring->nr_buf_size) {
> +		__odp_errno = -EMSGSIZE;
> +		return 0;
> +	}
> +
> +	i = ring->cur;
> +	ring->slot[i].flags = 0;
> +	ring->slot[i].len = pkt_len;
> +	buf = NETMAP_BUF(ring, ring->slot[i].buf_idx);
> +
> +	if (odp_packet_copydata_out(pkt, offset, pkt_len, buf))
> +		return 0;
> +
> +	ring->cur = nm_ring_next(ring, i);
> +	ring->head = ring->cur;
> +
> +	return 1;
> +}
> +
>   static int netmap_send(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
>   		       unsigned num)
>   {
>   	struct pollfd polld;
>   	struct nm_desc *nm_desc = pktio_entry->s.pkt_nm.tx_desc;
>   	unsigned i, nb_tx;
> -	uint8_t *frame;
> -	uint32_t frame_len;
>   
>   	polld.fd = nm_desc->fd;
>   	polld.events = POLLOUT;
>   
>   	for (nb_tx = 0; nb_tx < num; nb_tx++) {
> -		frame_len = 0;
> -		frame = odp_packet_l2_ptr(pkt_table[nb_tx], &frame_len);
>   		for (i = 0; i < NM_INJECT_RETRIES; i++) {
> -			if (nm_inject(nm_desc, frame, frame_len) == 0)
> +			if (netmap_inject(nm_desc, pkt_table[nb_tx]) == 0)
>   				poll(&polld, 1, 0);
>   			else
>   				break;
>   		}
> +
>   		if (odp_unlikely(i == NM_INJECT_RETRIES)) {
>   			ioctl(nm_desc->fd, NIOCTXSYNC, NULL);
>   			break;
>   		}
>   	}
> +
>   	/* Send pending packets */
>   	poll(&polld, 1, 0);
>
Stuart Haslam Oct. 30, 2015, 10:05 a.m. UTC | #2
On Thu, Oct 29, 2015 at 02:54:59PM +0300, Maxim Uvarov wrote:
> On 10/28/2015 22:29, Stuart Haslam wrote:
> >Replace the nm_inject() helper with our own version so that
> >odp_packet_copydata_out() can be used as this understands segmented
> >packets.
> >
> >Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
> >---
> >  platform/linux-generic/pktio/netmap.c | 59 ++++++++++++++++++++++++++++++++---
> >  1 file changed, 54 insertions(+), 5 deletions(-)
> >
> >diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
> >index 7d47fc1..d72af3d 100644
> >--- a/platform/linux-generic/pktio/netmap.c
> >+++ b/platform/linux-generic/pktio/netmap.c
> >@@ -268,32 +268,81 @@ static int netmap_recv(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
> >  	return args.nb_rx;
> >  }
> >+static struct netmap_ring *netmap_tx_ring(struct nm_desc *d)
> >+{
> >+	unsigned c, n = d->last_tx_ring - d->first_tx_ring + 1;
> >+
> >+	for (c = 0; c < n ; c++) {
> why c and not i as everywhere? Also can n be some read friendly
> name, like num_rings?
> 
> Maxim.

OK. This started out as a copy of nm_inject() and the variable names
initially came from there.
Maxim Uvarov Nov. 12, 2015, 7:52 a.m. UTC | #3
Hi Stuart,

You will send updated patch, right?

Maxim.

On 10/30/2015 13:05, Stuart Haslam wrote:
> On Thu, Oct 29, 2015 at 02:54:59PM +0300, Maxim Uvarov wrote:
>> On 10/28/2015 22:29, Stuart Haslam wrote:
>>> Replace the nm_inject() helper with our own version so that
>>> odp_packet_copydata_out() can be used as this understands segmented
>>> packets.
>>>
>>> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
>>> ---
>>>   platform/linux-generic/pktio/netmap.c | 59 ++++++++++++++++++++++++++++++++---
>>>   1 file changed, 54 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
>>> index 7d47fc1..d72af3d 100644
>>> --- a/platform/linux-generic/pktio/netmap.c
>>> +++ b/platform/linux-generic/pktio/netmap.c
>>> @@ -268,32 +268,81 @@ static int netmap_recv(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
>>>   	return args.nb_rx;
>>>   }
>>> +static struct netmap_ring *netmap_tx_ring(struct nm_desc *d)
>>> +{
>>> +	unsigned c, n = d->last_tx_ring - d->first_tx_ring + 1;
>>> +
>>> +	for (c = 0; c < n ; c++) {
>> why c and not i as everywhere? Also can n be some read friendly
>> name, like num_rings?
>>
>> Maxim.
> OK. This started out as a copy of nm_inject() and the variable names
> initially came from there.
>
Stuart Haslam Nov. 12, 2015, 9:43 a.m. UTC | #4
On Thu, Nov 12, 2015 at 10:52:18AM +0300, Maxim Uvarov wrote:
> Hi Stuart,
> 
> You will send updated patch, right?
> 
> Maxim.

Yes will do, I was waiting to see if anyone had comments on some of the
other patches, but I'll rebase the series and send out a v2 shortly.

--
Stuart.

> 
> On 10/30/2015 13:05, Stuart Haslam wrote:
> >On Thu, Oct 29, 2015 at 02:54:59PM +0300, Maxim Uvarov wrote:
> >>On 10/28/2015 22:29, Stuart Haslam wrote:
> >>>Replace the nm_inject() helper with our own version so that
> >>>odp_packet_copydata_out() can be used as this understands segmented
> >>>packets.
> >>>
> >>>Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
> >>>---
> >>>  platform/linux-generic/pktio/netmap.c | 59 ++++++++++++++++++++++++++++++++---
> >>>  1 file changed, 54 insertions(+), 5 deletions(-)
> >>>
> >>>diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
> >>>index 7d47fc1..d72af3d 100644
> >>>--- a/platform/linux-generic/pktio/netmap.c
> >>>+++ b/platform/linux-generic/pktio/netmap.c
> >>>@@ -268,32 +268,81 @@ static int netmap_recv(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
> >>>  	return args.nb_rx;
> >>>  }
> >>>+static struct netmap_ring *netmap_tx_ring(struct nm_desc *d)
> >>>+{
> >>>+	unsigned c, n = d->last_tx_ring - d->first_tx_ring + 1;
> >>>+
> >>>+	for (c = 0; c < n ; c++) {
> >>why c and not i as everywhere? Also can n be some read friendly
> >>name, like num_rings?
> >>
> >>Maxim.
> >OK. This started out as a copy of nm_inject() and the variable names
> >initially came from there.
> >
>
diff mbox

Patch

diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index 7d47fc1..d72af3d 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -268,32 +268,81 @@  static int netmap_recv(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
 	return args.nb_rx;
 }
 
+static struct netmap_ring *netmap_tx_ring(struct nm_desc *d)
+{
+	unsigned c, n = d->last_tx_ring - d->first_tx_ring + 1;
+
+	for (c = 0; c < n ; c++) {
+		struct netmap_ring *ring;
+		unsigned ri = d->cur_tx_ring + c;
+
+		if (ri > d->last_tx_ring)
+			ri = d->first_tx_ring;
+		ring = NETMAP_TXRING(d->nifp, ri);
+		if (nm_ring_empty(ring))
+			continue;
+
+		return ring;
+	}
+
+	return NULL;
+}
+
+static int netmap_inject(struct nm_desc *d, odp_packet_t pkt)
+{
+	struct netmap_ring *ring;
+	unsigned i;
+	uint32_t pkt_len = odp_packet_len(pkt);
+	uint32_t offset = 0;
+	char *buf;
+
+	ring = netmap_tx_ring(d);
+	if (!ring)
+		return 0;
+
+	if (pkt_len > ring->nr_buf_size) {
+		__odp_errno = -EMSGSIZE;
+		return 0;
+	}
+
+	i = ring->cur;
+	ring->slot[i].flags = 0;
+	ring->slot[i].len = pkt_len;
+	buf = NETMAP_BUF(ring, ring->slot[i].buf_idx);
+
+	if (odp_packet_copydata_out(pkt, offset, pkt_len, buf))
+		return 0;
+
+	ring->cur = nm_ring_next(ring, i);
+	ring->head = ring->cur;
+
+	return 1;
+}
+
 static int netmap_send(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
 		       unsigned num)
 {
 	struct pollfd polld;
 	struct nm_desc *nm_desc = pktio_entry->s.pkt_nm.tx_desc;
 	unsigned i, nb_tx;
-	uint8_t *frame;
-	uint32_t frame_len;
 
 	polld.fd = nm_desc->fd;
 	polld.events = POLLOUT;
 
 	for (nb_tx = 0; nb_tx < num; nb_tx++) {
-		frame_len = 0;
-		frame = odp_packet_l2_ptr(pkt_table[nb_tx], &frame_len);
 		for (i = 0; i < NM_INJECT_RETRIES; i++) {
-			if (nm_inject(nm_desc, frame, frame_len) == 0)
+			if (netmap_inject(nm_desc, pkt_table[nb_tx]) == 0)
 				poll(&polld, 1, 0);
 			else
 				break;
 		}
+
 		if (odp_unlikely(i == NM_INJECT_RETRIES)) {
 			ioctl(nm_desc->fd, NIOCTXSYNC, NULL);
 			break;
 		}
 	}
+
 	/* Send pending packets */
 	poll(&polld, 1, 0);