All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@xilinx.com, peter.maydell@linaro.org
Subject: [PULL v1 06/14] hw/net/xilinx_axienet: Handle fragmented packets from DMA
Date: Thu, 14 May 2020 16:13:54 +0200	[thread overview]
Message-ID: <20200514141402.12498-7-edgar.iglesias@gmail.com> (raw)
In-Reply-To: <20200514141402.12498-1-edgar.iglesias@gmail.com>

From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

Add support for fragmented packets from the DMA.

Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Message-Id: <20200506082513.18751-7-edgar.iglesias@gmail.com>
---
 hw/net/xilinx_axienet.c | 38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/hw/net/xilinx_axienet.c b/hw/net/xilinx_axienet.c
index bd48305577..498afe2f54 100644
--- a/hw/net/xilinx_axienet.c
+++ b/hw/net/xilinx_axienet.c
@@ -402,6 +402,9 @@ struct XilinxAXIEnet {
 
     uint32_t hdr[CONTROL_PAYLOAD_WORDS];
 
+    uint8_t *txmem;
+    uint32_t txpos;
+
     uint8_t *rxmem;
     uint32_t rxsize;
     uint32_t rxpos;
@@ -421,6 +424,7 @@ static void axienet_rx_reset(XilinxAXIEnet *s)
 static void axienet_tx_reset(XilinxAXIEnet *s)
 {
     s->tc = TC_JUM | TC_TX | TC_VLAN;
+    s->txpos = 0;
 }
 
 static inline int axienet_rx_resetting(XilinxAXIEnet *s)
@@ -902,17 +906,35 @@ xilinx_axienet_data_stream_push(StreamSlave *obj, uint8_t *buf, size_t size,
     XilinxAXIEnetStreamSlave *ds = XILINX_AXI_ENET_DATA_STREAM(obj);
     XilinxAXIEnet *s = ds->enet;
 
-    /* We don't support fragmented packets yet.  */
-    assert(eop);
-
     /* TX enable ?  */
     if (!(s->tc & TC_TX)) {
         return size;
     }
 
+    if (s->txpos + size > s->c_txmem) {
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Packet larger than txmem\n",
+                      TYPE_XILINX_AXI_ENET);
+        s->txpos = 0;
+        return size;
+    }
+
+    if (s->txpos == 0 && eop) {
+        /* Fast path single fragment.  */
+        s->txpos = size;
+    } else {
+        memcpy(s->txmem + s->txpos, buf, size);
+        buf = s->txmem;
+        s->txpos += size;
+
+        if (!eop) {
+            return size;
+        }
+    }
+
     /* Jumbo or vlan sizes ?  */
     if (!(s->tc & TC_JUM)) {
-        if (size > 1518 && size <= 1522 && !(s->tc & TC_VLAN)) {
+        if (s->txpos > 1518 && s->txpos <= 1522 && !(s->tc & TC_VLAN)) {
+            s->txpos = 0;
             return size;
         }
     }
@@ -923,7 +945,7 @@ xilinx_axienet_data_stream_push(StreamSlave *obj, uint8_t *buf, size_t size,
         uint32_t tmp_csum;
         uint16_t csum;
 
-        tmp_csum = net_checksum_add(size - start_off,
+        tmp_csum = net_checksum_add(s->txpos - start_off,
                                     buf + start_off);
         /* Accumulate the seed.  */
         tmp_csum += s->hdr[2] & 0xffff;
@@ -936,12 +958,13 @@ xilinx_axienet_data_stream_push(StreamSlave *obj, uint8_t *buf, size_t size,
         buf[write_off + 1] = csum & 0xff;
     }
 
-    qemu_send_packet(qemu_get_queue(s->nic), buf, size);
+    qemu_send_packet(qemu_get_queue(s->nic), buf, s->txpos);
 
-    s->stats.tx_bytes += size;
+    s->stats.tx_bytes += s->txpos;
     s->regs[R_IS] |= IS_TX_COMPLETE;
     enet_update_irq(s);
 
+    s->txpos = 0;
     return size;
 }
 
@@ -989,6 +1012,7 @@ static void xilinx_enet_realize(DeviceState *dev, Error **errp)
     s->TEMAC.parent = s;
 
     s->rxmem = g_malloc(s->c_rxmem);
+    s->txmem = g_malloc(s->c_txmem);
     return;
 
 xilinx_enet_realize_fail:
-- 
2.20.1



  parent reply	other threads:[~2020-05-14 14:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 14:13 [PULL v1 00/14] Xilinx queue 2020-05-14 Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 01/14] hw/net/xilinx_axienet: Auto-clear PHY Autoneg Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 02/14] hw/net/xilinx_axienet: Cleanup stream->push assignment Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 03/14] hw/net/xilinx_axienet: Remove unncessary cast Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 04/14] hw/dma/xilinx_axidma: Add DMA memory-region property Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 05/14] hw/core: stream: Add an end-of-packet flag Edgar E. Iglesias
2020-05-14 14:13 ` Edgar E. Iglesias [this message]
2020-05-14 14:13 ` [PULL v1 07/14] hw/dma/xilinx_axidma: mm2s: Stream descriptor by descriptor Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 08/14] hw/dma/xilinx_axidma: s2mm: Support stream fragments Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 09/14] MAINTAINERS: Add myself as streams maintainer Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 10/14] target/microblaze: Add MFS Rd,EDR translation Edgar E. Iglesias
2020-05-14 14:13 ` [PULL v1 11/14] target/microblaze: Fix FPU2 instruction check Edgar E. Iglesias
2020-05-14 14:14 ` [PULL v1 12/14] target/microblaze: gdb: Extend the number of registers presented to GDB Edgar E. Iglesias
2020-05-14 14:14 ` [PULL v1 13/14] target/microblaze: gdb: Fix incorrect SReg reporting Edgar E. Iglesias
2020-05-14 14:14 ` [PULL v1 14/14] target/microblaze: monitor: Increase the number of registers reported Edgar E. Iglesias
2020-05-14 15:17 ` [PULL v1 00/14] Xilinx queue 2020-05-14 Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200514141402.12498-7-edgar.iglesias@gmail.com \
    --to=edgar.iglesias@gmail.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.