Skip to contentSkip to conversation

Several fixes of AXI-ethernet/DMA

PATCH In review Jim Shu 2 participants 8 messages Aug 1, 2024 – Aug 12, 2024 Arm/Zynq architecture

lore
Share & tools
lore

Jim Shu

author
#0 lore raw

v2 cover Several fixes of AXI-ethernet/DMA

v2:
- Remove redundant RCW1_RX checking in enet_write()
- Remove qemu_set_irq() in DeviceState::reset()

Fix txlen value in the descriptor status field, DMA error handling, and ethernet/DMA reset flow.

Jim Shu (3):
hw/dma: xilinx_axidma: Correct the txlen value in the descriptor hw/dma: xilinx_axidma: Send DMA error IRQ if any memory access is
failed
hw/net: xilinx_axienet: Fix DMA RX IRQ if ethernet disable RX

 hw/dma/trace-events     |  1 +
 hw/dma/xilinx_axidma.c  | 74 +++++++++++++++++++++++++++++------------
 hw/net/xilinx_axienet.c | 71 +++++++++++++++++++++++----------------
 3 files changed, 95 insertions(+), 51 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/3 hw/dma: xilinx_axidma: Correct the txlen value in the descriptor

Currently, txlen is always decremented to 0 before filling to the descriptor. Keep the origin txlen value to have the correct value of descriptor status field.

It will fix the 'tx_bytes' statistic value in linux axi-ethernet driver.

---
 hw/dma/xilinx_axidma.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/dma/xilinx_axidma.c +3 -2
index c9cfc3169b..6aa8c9272c 100644
@@ -291,7 +291,7 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
                                  StreamSink *tx_control_dev)
 {
     uint32_t prev_d;
-    uint32_t txlen;
+    uint32_t txlen, origin_txlen;
     uint64_t addr;
     bool eop;
 
@@ -314,6 +314,7 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
         }
 
         txlen = s->desc.control & SDESC_CTRL_LEN_MASK;
+        origin_txlen = txlen;
 
         eop = stream_desc_eof(&s->desc);
         addr = s->desc.buffer_address;
@@ -334,7 +335,7 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
         }
 
         /* Update the descriptor.  */
-        s->desc.status = txlen | SDESC_STATUS_COMPLETE;
+        s->desc.status = origin_txlen | SDESC_STATUS_COMPLETE;
         stream_desc_store(s, s->regs[R_CURDESC]);
 
         /* Advance.  */
Signature · 1 line
2.17.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] hw/dma: xilinx_axidma: Correct the txlen value in the descriptor

Quoted 9 lines · Jim Shu

Currently, txlen is always decremented to 0 before filling to the descriptor. Keep the origin txlen value to have the correct value of descriptor status field.

It will fix the 'tx_bytes' statistic value in linux axi-ethernet driver.

---

thanks
-- PMM

author
#3 lore raw

PATCH v2 2/3 hw/dma: xilinx_axidma: Send DMA error IRQ if any memory access is failed

In reply to Jim Shu

The memory transactions from DMA could have bus-error in some cases. If it is failed, DMA device should send error IRQs.

---
 hw/dma/trace-events    |  1 +
 hw/dma/xilinx_axidma.c | 69 ++++++++++++++++++++++++++++++------------
 2 files changed, 50 insertions(+), 20 deletions(-)
hw/dma/trace-events +1 -0
index 4c09790f9a..7db38e0e93 100644
@@ -47,3 +47,4 @@ pl330_iomem_read(uint32_t addr, uint32_t data) "addr: 0x%08"PRIx32" data: 0x%08"
 
 # xilinx_axidma.c
 xilinx_axidma_loading_desc_fail(uint32_t res) "error:%u"
+xilinx_axidma_storing_desc_fail(uint32_t res) "error:%u"
hw/dma/xilinx_axidma.c +49 -20

131 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH v2 2/3] hw/dma: xilinx_axidma: Send DMA error IRQ if any memory access is failed

Quoted 25 lines · Jim Shu

The memory transactions from DMA could have bus-error in some cases. If it is failed, DMA device should send error IRQs.

---
 hw/dma/trace-events    |  1 +
 hw/dma/xilinx_axidma.c | 69 ++++++++++++++++++++++++++++++------------
 2 files changed, 50 insertions(+), 20 deletions(-)
hw/dma/trace-events +1 -0
index 4c09790f9a..7db38e0e93 100644
@@ -47,3 +47,4 @@ pl330_iomem_read(uint32_t addr, uint32_t data) "addr: 0x%08"PRIx32" data: 0x%08"
 
 # xilinx_axidma.c
 xilinx_axidma_loading_desc_fail(uint32_t res) "error:%u"
+xilinx_axidma_storing_desc_fail(uint32_t res) "error:%u"
hw/dma/xilinx_axidma.c +0 -0
index 6aa8c9272c..728246f925 100644
@@ -194,6 +194,20 @@ static inline int streamid_from_addr(hwaddr addr)
     return sid;

hw/dma/xilinx_axidma.c static inline int streamid_from_addr(hwaddr addr) · line 204

Quoted 10 lines
hw/dma/xilinx_axidma.c +8 -0
 }
 
+/* When DMA is error, fill in the register of this Stream. */
+static void stream_dma_error(struct Stream *s, MemTxResult result)
+{
+    if (result == MEMTX_DECODE_ERROR) {
+        s->regs[R_DMASR] |= DMASR_DECERR;
+    } else {
+        s->regs[R_DMASR] |= DMASR_SLVERR;
+    }

The MM2S_DMASR described in this doc:
https://docs.amd.com/r/en-US/pg021_axi_dma/MM2S_DMASR-MM2S-DMA-Status-Register-Offset-04h
has both DMASlvErr/DMADecErr bits and also SGSlvErr/SGDecErr bits. Is that the wrong documentation for the version of the device we model, or is there a situation where we should be setting the other SlvErr/DecErr bits when we get an error from our memory accesses? Similarly there's a separate S2MM_DMASR in those docs which we don't model at all (so maybe it is the wrong datasheet...)

Quoted 70 lines
hw/dma/xilinx_axidma.c +6 -0
+
+    s->regs[R_DMACR] &= ~DMACR_RUNSTOP;
+    s->regs[R_DMASR] |= DMASR_HALTED;
+    s->regs[R_DMASR] |= DMASR_ERR_IRQ;
+}
 
 
 
+

static MemTxResult stream_desc_load(struct Stream *s, hwaddr addr)

 {
     struct SDesc *d = &s->desc;
hw/dma/xilinx_axidma.c +12 -13
@@ -203,16 +217,7 @@ static MemTxResult stream_desc_load(struct Stream *s, hwaddr addr)
                                             d, sizeof *d);
     if (result != MEMTX_OK) {
         trace_xilinx_axidma_loading_desc_fail(result);
-
-        if (result == MEMTX_DECODE_ERROR) {
-            s->regs[R_DMASR] |= DMASR_DECERR;
-        } else {
-            s->regs[R_DMASR] |= DMASR_SLVERR;
-        }
-
-        s->regs[R_DMACR] &= ~DMACR_RUNSTOP;
-        s->regs[R_DMASR] |= DMASR_HALTED;
-        s->regs[R_DMASR] |= DMASR_ERR_IRQ;
+        stream_dma_error(s, result);
         return result;
     }
 
@@ -224,17 +229,24 @@ static MemTxResult stream_desc_load(struct Stream *s, hwaddr addr)
     return result;
 }
 
-static void stream_desc_store(struct Stream *s, hwaddr addr)
+static MemTxResult stream_desc_store(struct Stream *s, hwaddr addr)
 {
     struct SDesc *d = &s->desc;
+    MemTxResult result;
 
     /* Convert from host endianness into LE.  */
     d->buffer_address = cpu_to_le64(d->buffer_address);
     d->nxtdesc = cpu_to_le64(d->nxtdesc);
     d->control = cpu_to_le32(d->control);
     d->status = cpu_to_le32(d->status);
-    address_space_write(&s->dma->as, addr, MEMTXATTRS_UNSPECIFIED,
-                        d, sizeof *d);
+    result = address_space_write(&s->dma->as, addr, MEMTXATTRS_UNSPECIFIED,
+                                 d, sizeof *d);
+
+    if (result != MEMTX_OK) {
+        trace_xilinx_axidma_storing_desc_fail(result);
+        stream_dma_error(s, result);
+    }
+    return result;
 }
 
 static void stream_update_irq(struct Stream *s)
@@ -294,6 +306,7 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
     uint32_t txlen, origin_txlen;
     uint64_t addr;
     bool eop;
+    MemTxResult result;
 
     if (!stream_running(s) || stream_idle(s) || stream_halted(s)) {
         return;
@@ -322,9 +335,14 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
             unsigned int len;
 
             len = txlen > sizeof s->txbuf ? sizeof s->txbuf : txlen;

hw/dma/xilinx_axidma.c static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev, · line 344

Quoted 10 lines
hw/dma/xilinx_axidma.c +7 -3
-            address_space_read(&s->dma->as, addr,
-                               MEMTXATTRS_UNSPECIFIED,
-                               s->txbuf, len);
+            result = address_space_read(&s->dma->as, addr,
+                                        MEMTXATTRS_UNSPECIFIED,
+                                        s->txbuf, len);
+            if (result != MEMTX_OK) {
+                stream_dma_error(s, result);
+                return;
+            }

In this function we only use result in the immediately following if(), so I think it would be slightly clearer to write them as

      if (stream_desc_store(...) != MEMTX_OK) {
          break;
      }

without the use of the variable.

Quoted 40 lines
hw/dma/xilinx_axidma.c +12 -3
+
             stream_push(tx_data_dev, s->txbuf, len, eop && len == txlen);
             txlen -= len;
             addr += len;
@@ -336,7 +354,9 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
 
         /* Update the descriptor.  */
         s->desc.status = origin_txlen | SDESC_STATUS_COMPLETE;
-        stream_desc_store(s, s->regs[R_CURDESC]);
+        if (stream_desc_store(s, s->regs[R_CURDESC]) != MEMTX_OK) {
+            break;
+        }
 
         /* Advance.  */
         prev_d = s->regs[R_CURDESC];
@@ -354,6 +374,7 @@ static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
     uint32_t prev_d;
     unsigned int rxlen;
     size_t pos = 0;
+    MemTxResult result;
 
     if (!stream_running(s) || stream_idle(s) || stream_halted(s)) {
         return 0;
@@ -375,8 +396,13 @@ static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
             rxlen = len;
         }
 
-        address_space_write(&s->dma->as, s->desc.buffer_address,
-                            MEMTXATTRS_UNSPECIFIED, buf + pos, rxlen);
+        result = address_space_write(&s->dma->as, s->desc.buffer_address,
+                                     MEMTXATTRS_UNSPECIFIED, buf + pos, rxlen);
+        if (result != MEMTX_OK) {
+            stream_dma_error(s, result);
+            break;
+        }
+
         len -= rxlen;
         pos += rxlen;
 

hw/dma/xilinx_axidma.c static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf, · line 421

Quoted 8 lines
hw/dma/xilinx_axidma.c +4 -1
@@ -389,7 +415,10 @@ static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
 
         s->desc.status |= s->sof << SDESC_STATUS_SOF_BIT;
         s->desc.status |= SDESC_STATUS_COMPLETE;
-        stream_desc_store(s, s->regs[R_CURDESC]);
+        result = stream_desc_store(s, s->regs[R_CURDESC]);
+        if (result != MEMTX_OK) {
+            break;
+        }

In these two places also we don't need the variable.

hw/dma/xilinx_axidma.c static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,

Quoted 4 lines
hw/dma/xilinx_axidma.c +0 -1
         s->sof = eop;
 
         /* Advance.  */
--

thanks
-- PMM

author
#5 lore raw

Re: [PATCH v2 2/3] hw/dma: xilinx_axidma: Send DMA error IRQ if any memory access is failed

Quoted 40 lines · Peter Maydell
Quoted 25 lines · Jim Shu

The memory transactions from DMA could have bus-error in some cases. If it is failed, DMA device should send error IRQs.

---
 hw/dma/trace-events    |  1 +
 hw/dma/xilinx_axidma.c | 69 ++++++++++++++++++++++++++++++------------
 2 files changed, 50 insertions(+), 20 deletions(-)
hw/dma/trace-events +1 -0
index 4c09790f9a..7db38e0e93 100644
@@ -47,3 +47,4 @@ pl330_iomem_read(uint32_t addr, uint32_t data) "addr: 0x%08"PRIx32" data: 0x%08"
 
 # xilinx_axidma.c
 xilinx_axidma_loading_desc_fail(uint32_t res) "error:%u"
+xilinx_axidma_storing_desc_fail(uint32_t res) "error:%u"
hw/dma/xilinx_axidma.c +0 -0
index 6aa8c9272c..728246f925 100644
@@ -194,6 +194,20 @@ static inline int streamid_from_addr(hwaddr addr)
     return sid;

hw/dma/xilinx_axidma.c static inline int streamid_from_addr(hwaddr addr) · line 204

Quoted 10 lines
hw/dma/xilinx_axidma.c +8 -0
 }
 
+/* When DMA is error, fill in the register of this Stream. */
+static void stream_dma_error(struct Stream *s, MemTxResult result)
+{
+    if (result == MEMTX_DECODE_ERROR) {
+        s->regs[R_DMASR] |= DMASR_DECERR;
+    } else {
+        s->regs[R_DMASR] |= DMASR_SLVERR;
+    }

The MM2S_DMASR described in this doc:
https://docs.amd.com/r/en-US/pg021_axi_dma/MM2S_DMASR-MM2S-DMA-Status-Register-Offset-04h

Quoted 8 lines

has both DMASlvErr/DMADecErr bits and also SGSlvErr/SGDecErr bits. Is that the wrong documentation for the version of the device we model, or is there a situation where we should be setting the other SlvErr/DecErr bits when we get an error from our memory accesses? Similarly there's a separate S2MM_DMASR in those docs which we don't model at all (so maybe it is the wrong datasheet...)

I also use this spec (PG021, AXI DMA v7.1). I think it is the right one.

1. For DMASlvErr/DMADecErr & SGSlvErr/SGDecErr
Spec has Scatter/Gather mode & Direct Register mode. It looks like a HW config instead of SW config.
The SG mode uses MM2S_CURDESC (0x08) / TAIL_DESC (0x10) and direct mode uses MM2S_SA (0x18) / MM2S_LENGTH (0x28) to transfer. I think the QEMU model only implements SG mode now (S2MM also). stream_dma_error() should set SGSlvErr/SGDecErr instead of DMA ones. I will fix it in v3.

2. For MM2S & S2MM
QEMU has implemented 2 Streams. Stream[0] is MM2S and Stream[1] is S2MM. The register read/write function will redirect to Stream[0] if addr < 0x30 and Stream[1] if 0x30 <= addr < 0x60.
stream_dma_error() is based on Stream* so it could support both MM2S & S2MM.

Quoted 84 lines
Quoted 71 lines
hw/dma/xilinx_axidma.c +6 -0
+
+    s->regs[R_DMACR] &= ~DMACR_RUNSTOP;
+    s->regs[R_DMASR] |= DMASR_HALTED;
+    s->regs[R_DMASR] |= DMASR_ERR_IRQ;
+}
 
 
 
+

static MemTxResult stream_desc_load(struct Stream *s, hwaddr addr)

 {
     struct SDesc *d = &s->desc;
hw/dma/xilinx_axidma.c +12 -13
@@ -203,16 +217,7 @@ static MemTxResult stream_desc_load(struct Stream *s, hwaddr addr)
                                             d, sizeof *d);
     if (result != MEMTX_OK) {
         trace_xilinx_axidma_loading_desc_fail(result);
-
-        if (result == MEMTX_DECODE_ERROR) {
-            s->regs[R_DMASR] |= DMASR_DECERR;
-        } else {
-            s->regs[R_DMASR] |= DMASR_SLVERR;
-        }
-
-        s->regs[R_DMACR] &= ~DMACR_RUNSTOP;
-        s->regs[R_DMASR] |= DMASR_HALTED;
-        s->regs[R_DMASR] |= DMASR_ERR_IRQ;
+        stream_dma_error(s, result);
         return result;
     }
 
@@ -224,17 +229,24 @@ static MemTxResult stream_desc_load(struct Stream *s, hwaddr addr)
     return result;
 }
 
-static void stream_desc_store(struct Stream *s, hwaddr addr)
+static MemTxResult stream_desc_store(struct Stream *s, hwaddr addr)
 {
     struct SDesc *d = &s->desc;
+    MemTxResult result;
 
     /* Convert from host endianness into LE.  */
     d->buffer_address = cpu_to_le64(d->buffer_address);
     d->nxtdesc = cpu_to_le64(d->nxtdesc);
     d->control = cpu_to_le32(d->control);
     d->status = cpu_to_le32(d->status);
-    address_space_write(&s->dma->as, addr, MEMTXATTRS_UNSPECIFIED,
-                        d, sizeof *d);
+    result = address_space_write(&s->dma->as, addr, MEMTXATTRS_UNSPECIFIED,
+                                 d, sizeof *d);
+
+    if (result != MEMTX_OK) {
+        trace_xilinx_axidma_storing_desc_fail(result);
+        stream_dma_error(s, result);
+    }
+    return result;
 }
 
 static void stream_update_irq(struct Stream *s)
@@ -294,6 +306,7 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
     uint32_t txlen, origin_txlen;
     uint64_t addr;
     bool eop;
+    MemTxResult result;
 
     if (!stream_running(s) || stream_idle(s) || stream_halted(s)) {
         return;
@@ -322,9 +335,14 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
             unsigned int len;
 
             len = txlen > sizeof s->txbuf ? sizeof s->txbuf : txlen;

hw/dma/xilinx_axidma.c static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev, · line 344

Quoted 10 lines
hw/dma/xilinx_axidma.c +7 -3
-            address_space_read(&s->dma->as, addr,
-                               MEMTXATTRS_UNSPECIFIED,
-                               s->txbuf, len);
+            result = address_space_read(&s->dma->as, addr,
+                                        MEMTXATTRS_UNSPECIFIED,
+                                        s->txbuf, len);
+            if (result != MEMTX_OK) {
+                stream_dma_error(s, result);
+                return;
+            }

In this function we only use result in the immediately following if(), so I think it would be slightly clearer to write them as

Quoted 5 lines
      if (stream_desc_store(...) != MEMTX_OK) {
          break;
      }

without the use of the variable.

Thanks for the suggestion. I will fix it in v3.

Quoted 42 lines
Quoted 42 lines
hw/dma/xilinx_axidma.c +12 -3
+
             stream_push(tx_data_dev, s->txbuf, len, eop && len == txlen);
             txlen -= len;
             addr += len;
@@ -336,7 +354,9 @@ static void stream_process_mem2s(struct Stream *s, StreamSink *tx_data_dev,
 
         /* Update the descriptor.  */
         s->desc.status = origin_txlen | SDESC_STATUS_COMPLETE;
-        stream_desc_store(s, s->regs[R_CURDESC]);
+        if (stream_desc_store(s, s->regs[R_CURDESC]) != MEMTX_OK) {
+            break;
+        }
 
         /* Advance.  */
         prev_d = s->regs[R_CURDESC];
@@ -354,6 +374,7 @@ static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
     uint32_t prev_d;
     unsigned int rxlen;
     size_t pos = 0;
+    MemTxResult result;
 
     if (!stream_running(s) || stream_idle(s) || stream_halted(s)) {
         return 0;
@@ -375,8 +396,13 @@ static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
             rxlen = len;
         }
 
-        address_space_write(&s->dma->as, s->desc.buffer_address,
-                            MEMTXATTRS_UNSPECIFIED, buf + pos, rxlen);
+        result = address_space_write(&s->dma->as, s->desc.buffer_address,
+                                     MEMTXATTRS_UNSPECIFIED, buf + pos, rxlen);
+        if (result != MEMTX_OK) {
+            stream_dma_error(s, result);
+            break;
+        }
+
         len -= rxlen;
         pos += rxlen;
 
@@ -389,7 +415,10 @@ static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,
 
Quoted 9 lines

hw/dma/xilinx_axidma.c static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf, · line 421

Quoted 7 lines
hw/dma/xilinx_axidma.c +4 -1
         s->desc.status |= s->sof << SDESC_STATUS_SOF_BIT;
         s->desc.status |= SDESC_STATUS_COMPLETE;
-        stream_desc_store(s, s->regs[R_CURDESC]);
+        result = stream_desc_store(s, s->regs[R_CURDESC]);
+        if (result != MEMTX_OK) {
+            break;
+        }

In these two places also we don't need the variable.

Thanks for the suggestion. I will fix it in v3.

Quoted 8 lines

hw/dma/xilinx_axidma.c static size_t stream_process_s2mem(struct Stream *s, unsigned char *buf,

Quoted 5 lines
hw/dma/xilinx_axidma.c +0 -1
         s->sof = eop;
 
         /* Advance.  */
--

thanks
-- PMM

author
#6 lore raw

PATCH v2 3/3 hw/net: xilinx_axienet: Fix DMA RX IRQ if ethernet disable RX

In reply to Jim Shu

When AXI ethernet RX is disabled, it shouldn't send packets to AXI DMA, which may let AXI DMA to send RX full IRQs. It is aligned with real AXI DMA/ethernet IP behavior in the FPGA.

Also, now ethernet RX blocks the RX packets when it is disabled. It should send and clear the remaining RX packets when enabling it.

---
 hw/net/xilinx_axienet.c | 71 ++++++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 29 deletions(-)
hw/net/xilinx_axienet.c +42 -29
index 05d41bd548..0ecdc30be6 100644
@@ -530,6 +530,40 @@ static uint64_t enet_read(void *opaque, hwaddr addr, unsigned size)
     return r;
 }
 
+static void axienet_eth_rx_notify(void *opaque)
+{
+    XilinxAXIEnet *s = XILINX_AXI_ENET(opaque);
+
+    /* If RX is disabled, don't trigger DMA to update RX desc and send IRQ */
+    if (!axienet_rx_enabled(s)) {
+        return;
+    }
+
+    while (s->rxappsize && stream_can_push(s->tx_control_dev,
+                                           axienet_eth_rx_notify, s)) {
+        size_t ret = stream_push(s->tx_control_dev,
+                                 (void *)s->rxapp + CONTROL_PAYLOAD_SIZE
+                                 - s->rxappsize, s->rxappsize, true);
+        s->rxappsize -= ret;
+    }
+
+    while (s->rxsize && stream_can_push(s->tx_data_dev,
+                                        axienet_eth_rx_notify, s)) {
+        size_t ret = stream_push(s->tx_data_dev, (void *)s->rxmem + s->rxpos,
+                                 s->rxsize, true);
+        s->rxsize -= ret;
+        s->rxpos += ret;
+        if (!s->rxsize) {
+            s->regs[R_IS] |= IS_RX_COMPLETE;
+            if (s->need_flush) {
+                s->need_flush = false;
+                qemu_flush_queued_packets(qemu_get_queue(s->nic));
+            }
+        }
+    }
+    enet_update_irq(s);
+}
+
 static void enet_write(void *opaque, hwaddr addr,
                        uint64_t value, unsigned size)
 {
@@ -546,6 +580,14 @@ static void enet_write(void *opaque, hwaddr addr,
             } else {
                 qemu_flush_queued_packets(qemu_get_queue(s->nic));
             }
+
+            /*
+             * When RX is enabled, check if any remaining data in rxmem
+             * and send them.
+             */
+            if (addr & 1) {
+                axienet_eth_rx_notify(s);
+            }
             break;
 
         case R_TC:
@@ -666,35 +708,6 @@ static int enet_match_addr(const uint8_t *buf, uint32_t f0, uint32_t f1)
     return match;
 }
 
-static void axienet_eth_rx_notify(void *opaque)
-{
-    XilinxAXIEnet *s = XILINX_AXI_ENET(opaque);
-
-    while (s->rxappsize && stream_can_push(s->tx_control_dev,
-                                           axienet_eth_rx_notify, s)) {
-        size_t ret = stream_push(s->tx_control_dev,
-                                 (void *)s->rxapp + CONTROL_PAYLOAD_SIZE
-                                 - s->rxappsize, s->rxappsize, true);
-        s->rxappsize -= ret;
-    }
-
-    while (s->rxsize && stream_can_push(s->tx_data_dev,
-                                        axienet_eth_rx_notify, s)) {
-        size_t ret = stream_push(s->tx_data_dev, (void *)s->rxmem + s->rxpos,
-                                 s->rxsize, true);
-        s->rxsize -= ret;
-        s->rxpos += ret;
-        if (!s->rxsize) {
-            s->regs[R_IS] |= IS_RX_COMPLETE;
-            if (s->need_flush) {
-                s->need_flush = false;
-                qemu_flush_queued_packets(qemu_get_queue(s->nic));
-            }
-        }
-    }
-    enet_update_irq(s);
-}
-
 static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)
 {
     XilinxAXIEnet *s = qemu_get_nic_opaque(nc);
Signature · 1 line
2.17.1
Reviewed-by on v2 3/3
#7 lore raw

Re: [PATCH v2 3/3] hw/net: xilinx_axienet: Fix DMA RX IRQ if ethernet disable RX

Quoted 9 lines · Jim Shu

When AXI ethernet RX is disabled, it shouldn't send packets to AXI DMA, which may let AXI DMA to send RX full IRQs. It is aligned with real AXI DMA/ethernet IP behavior in the FPGA.

Also, now ethernet RX blocks the RX packets when it is disabled. It should send and clear the remaining RX packets when enabling it.

thanks
-- PMM