Skip to contentSkip to conversation

Several fixes of AXI-ethernet/DMA

PATCH Superseded Jim Shu 2 participants 9 messages Jul 26, 2024 – Aug 1, 2024 Arm/Zynq architecture

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jim Shu

author
#0 lore raw

cover Several fixes of AXI-ethernet/DMA

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

*** BLURB HERE ***

Jim Shu (4):
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/dma: xilinx_axidma: Reset qemu_irq when DMA/Stream is reset hw/net: xilinx_axienet: Fix DMA RX IRQ if ethernet disable RX

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

PATCH 1/4 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
author
#2 lore raw

PATCH 2/4 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
author
#3 lore raw

PATCH 3/4 hw/dma: xilinx_axidma: Reset qemu_irq when DMA/Stream is reset

In reply to Jim Shu

Current DMA/Stream reset will clear interrupt pending bit of DMA device. The qemu_irq of device should be updated at the same time.

---
 hw/dma/xilinx_axidma.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
hw/dma/xilinx_axidma.c +13 -12
index 728246f925..beb3fbf1d5 100644
@@ -177,11 +177,24 @@ static inline int stream_halted(struct Stream *s)
     return !!(s->regs[R_DMASR] & DMASR_HALTED);
 }
 
+static void stream_update_irq(struct Stream *s)
+{
+    unsigned int pending, mask, irq;
+
+    pending = s->regs[R_DMASR] & DMASR_IRQ_MASK;
+    mask = s->regs[R_DMACR] & DMASR_IRQ_MASK;
+
+    irq = pending & mask;
+
+    qemu_set_irq(s->irq, !!irq);
+}
+
 static void stream_reset(struct Stream *s)
 {
     s->regs[R_DMASR] = DMASR_HALTED;  /* starts up halted.  */
     s->regs[R_DMACR] = 1 << 16; /* Starts with one in compl threshold.  */
     s->sof = true;
+    stream_update_irq(s); /* Clear interrupt */
 }
 
 /* Map an offset addr into a channel index.  */
@@ -249,18 +262,6 @@ static MemTxResult stream_desc_store(struct Stream *s, hwaddr addr)
     return result;
 }
 
-static void stream_update_irq(struct Stream *s)
-{
-    unsigned int pending, mask, irq;
-
-    pending = s->regs[R_DMASR] & DMASR_IRQ_MASK;
-    mask = s->regs[R_DMACR] & DMASR_IRQ_MASK;
-
-    irq = pending & mask;
-
-    qemu_set_irq(s->irq, !!irq);
-}
-
 static void stream_reload_complete_cnt(struct Stream *s)
 {
     unsigned int comp_th;
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH 3/4] hw/dma: xilinx_axidma: Reset qemu_irq when DMA/Stream is reset

Quoted 26 lines · Jim Shu

Current DMA/Stream reset will clear interrupt pending bit of DMA device. The qemu_irq of device should be updated at the same time.

---
 hw/dma/xilinx_axidma.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
hw/dma/xilinx_axidma.c +9 -0
index 728246f925..beb3fbf1d5 100644
@@ -177,11 +177,24 @@ static inline int stream_halted(struct Stream *s)
     return !!(s->regs[R_DMASR] & DMASR_HALTED);
 }
 
+static void stream_update_irq(struct Stream *s)
+{
+    unsigned int pending, mask, irq;
+
+    pending = s->regs[R_DMASR] & DMASR_IRQ_MASK;
+    mask = s->regs[R_DMACR] & DMASR_IRQ_MASK;
+
+    irq = pending & mask;
+

hw/dma/xilinx_axidma.c static inline int stream_halted(struct Stream *s) · line 198

Quoted 10 lines
hw/dma/xilinx_axidma.c +4 -0
+    qemu_set_irq(s->irq, !!irq);
+}
+
 static void stream_reset(struct Stream *s)
 {
     s->regs[R_DMASR] = DMASR_HALTED;  /* starts up halted.  */
     s->regs[R_DMACR] = 1 << 16; /* Starts with one in compl threshold.  */
     s->sof = true;
+    stream_update_irq(s); /* Clear interrupt */
 }

The general rule of thumb in QEMU is not to call qemu_set_irq() from a DeviceState::reset function, and xilinx_axidma_reset calls stream_reset. I think probably the best thing is to separate out whether this is a DeviceState::reset or a software-triggered reset, and only call qemu_set_irq() in the latter case.

thanks
-- PMM

author
#5 lore raw

Re: [PATCH 3/4] hw/dma: xilinx_axidma: Reset qemu_irq when DMA/Stream is reset

Hi Peter,

Except DeviceState::reset(), stream_reset() is only used in axidma_write() and axidma_write() has qemu_set_irq() at the end of function.
I think this commit could be dropped. I will remove it in the v2 patchset.

Thanks,
Jim Shu

Quoted 48 lines · Peter Maydell
Quoted 26 lines · Jim Shu

Current DMA/Stream reset will clear interrupt pending bit of DMA device. The qemu_irq of device should be updated at the same time.

---
 hw/dma/xilinx_axidma.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
hw/dma/xilinx_axidma.c +9 -0
index 728246f925..beb3fbf1d5 100644
@@ -177,11 +177,24 @@ static inline int stream_halted(struct Stream *s)
     return !!(s->regs[R_DMASR] & DMASR_HALTED);
 }
 
+static void stream_update_irq(struct Stream *s)
+{
+    unsigned int pending, mask, irq;
+
+    pending = s->regs[R_DMASR] & DMASR_IRQ_MASK;
+    mask = s->regs[R_DMACR] & DMASR_IRQ_MASK;
+
+    irq = pending & mask;
+

hw/dma/xilinx_axidma.c static inline int stream_halted(struct Stream *s) · line 198

Quoted 10 lines
hw/dma/xilinx_axidma.c +4 -0
+    qemu_set_irq(s->irq, !!irq);
+}
+
 static void stream_reset(struct Stream *s)
 {
     s->regs[R_DMASR] = DMASR_HALTED;  /* starts up halted.  */
     s->regs[R_DMACR] = 1 << 16; /* Starts with one in compl threshold.  */
     s->sof = true;
+    stream_update_irq(s); /* Clear interrupt */
 }

The general rule of thumb in QEMU is not to call qemu_set_irq() from a DeviceState::reset function, and xilinx_axidma_reset calls stream_reset. I think probably the best thing is to separate out whether this is a DeviceState::reset or a software-triggered reset, and only call qemu_set_irq() in the latter case.

thanks
-- PMM

author
#6 lore raw

PATCH 4/4 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..8428f10946 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) && s->rcw[addr & 1] & RCW1_RX) {
+                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
#7 lore raw

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

Quoted 19 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.

---
 hw/net/xilinx_axienet.c | 71 ++++++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 29 deletions(-)
hw/net/xilinx_axienet.c +0 -0
index 05d41bd548..8428f10946 100644
@@ -530,6 +530,40 @@ static uint64_t enet_read(void *opaque, hwaddr addr, unsigned size)
     return r;

hw/net/xilinx_axienet.c static uint64_t enet_read(void *opaque, hwaddr addr, unsigned size) · line 540

Quoted 10 lines
hw/net/xilinx_axienet.c +8 -0
 }
 
+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;
+    }

This checks s->rcw[1] & RCW1_RX, and does nothing if it's not set...

Quoted 5 lines
hw/net/xilinx_axienet.c +0 -0
 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 {

hw/net/xilinx_axienet.c static void enet_write(void *opaque, hwaddr addr, · line 590

Quoted 10 lines
hw/net/xilinx_axienet.c +8 -0
                 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) && s->rcw[addr & 1] & RCW1_RX) {
+                axienet_eth_rx_notify(s);
+            }

...but at this callsite we open-code a check on RCW1_RX and skip the call if it's not set. We don't need to check twice.

hw/net/xilinx_axienet.c static void enet_write(void *opaque, hwaddr addr, · line 593

Quoted 3 lines
hw/net/xilinx_axienet.c +0 -0
             break;
 
         case R_TC:

thanks
-- PMM

author
#8 lore raw

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

Hi Peter,

Thanks for the suggestion.

axienet_eth_rx_notify() is also called by axidma_write() as a notify() callback, so we need to check RCW1_RX in the function.
I think I could remove RCW1_RX checking in the enet_write() to avoid double checking.
I will fix it in the v2 patchset.

Thanks,
JIm Shu.

Quoted 59 lines · Peter Maydell
Quoted 19 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.

---
 hw/net/xilinx_axienet.c | 71 ++++++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 29 deletions(-)
hw/net/xilinx_axienet.c +0 -0
index 05d41bd548..8428f10946 100644
@@ -530,6 +530,40 @@ static uint64_t enet_read(void *opaque, hwaddr addr, unsigned size)
     return r;

hw/net/xilinx_axienet.c static uint64_t enet_read(void *opaque, hwaddr addr, unsigned size) · line 540

Quoted 10 lines
hw/net/xilinx_axienet.c +8 -0
 }
 
+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;
+    }

This checks s->rcw[1] & RCW1_RX, and does nothing if it's not set...

Quoted 5 lines
hw/net/xilinx_axienet.c +0 -0
 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 {

hw/net/xilinx_axienet.c static void enet_write(void *opaque, hwaddr addr, · line 590

Quoted 10 lines
hw/net/xilinx_axienet.c +8 -0
                 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) && s->rcw[addr & 1] & RCW1_RX) {
+                axienet_eth_rx_notify(s);
+            }

...but at this callsite we open-code a check on RCW1_RX and skip the call if it's not set. We don't need to check twice.

hw/net/xilinx_axienet.c static void enet_write(void *opaque, hwaddr addr, · line 593

Quoted 3 lines
hw/net/xilinx_axienet.c +0 -0
             break;
 
         case R_TC:

thanks
-- PMM