Thank you.
I will think about how to avoid copying..
Regards,
Pavel
On 16.02.2017 00:31, Lino Sanfilippo wrote:
On 15.02.2017 21:01, Pavel Belous wrote:
From: Pavel Belous <pavel.bel...@aquantia.com>
This fix simplified copying data to the ring buffer.
Also, there was an error in the code when the second memcpy
is called with zero length. It didn't break the driver, but it's bad.
Signed-off-by: Pavel Belous <pavel.bel...@aquantia.com>
---
drivers/net/ethernet/aquantia/atlantic/aq_ring.c | 25
++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
index 4c40644..8ebed0d 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_ring.c
@@ -108,18 +108,19 @@ void aq_ring_tx_append_buffs(struct aq_ring_s
*self,
struct aq_ring_buff_s *buffer,
unsigned int buffers)
{
- if (likely(self->sw_tail + buffers < self->size)) {
- memcpy(&self->buff_ring[self->sw_tail], buffer,
- sizeof(buffer[0]) * buffers);
- } else {
- unsigned int first_part = self->size - self->sw_tail;
- unsigned int second_part = buffers - first_part;
-
- memcpy(&self->buff_ring[self->sw_tail], buffer,
- sizeof(buffer[0]) * first_part);
-
- memcpy(&self->buff_ring[0], &buffer[first_part],
- sizeof(buffer[0]) * second_part);
+ int buff_len = min(self->size - self->sw_tail, buffers);
+
+ memcpy(&self->buff_ring[self->sw_tail],
+ buffer,
+ sizeof(struct aq_ring_buff_s) * buff_len);
+
+ /* We are in the end of the ring.
+ * Copy remains data to beginning of the ring
+ */
+ if (buffers > buff_len) {
+ memcpy(self->buff_ring,
+ &buffer[buff_len],
+ sizeof(struct aq_ring_buff_s) * (buffers - buff_len));
}
}
Well, you should really try to avoid copying the tx buffers _at all_.
E.g. by passing self->buff_ring to aq_ring_tx_append_buffs() instead of
the temporary array.
Regards,
Lino
buffer array.