Skip to contentSkip to conversation

support AST2700 network

PATCH In review Jamin Lin via 4 participants 14 messages Jul 3, 2024 – Jul 4, 2024 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

v2 cover support AST2700 network

change from v1:
- ftgmac100
- fix coding style
- support 64 bits dma dram address for AST2700

change from v2:
- ftgmac100: update memory region size to 0x200.
- ftgmac100: introduce a new class(ftgmac100_high),
class attribute and memop handlers, for FTGMAC100_*_HIGH regs read/write.
- aspeed_ast27x0: update network model to ftgmac100_high to support 64 bits dram address DMA.
- m25p80: support quad mode for w25q01jvq

Jamin Lin (5):
hw/net:ftgmac100: update memory region size to 0x200 hw/net:ftgmac100: support 64 bits dma dram address for AST2700 aspeed/soc: update to ftgmac100_high model for AST2700 hw/block: m25p80: support quad mode for w25q01jvq test/avocado/machine_aspeed.py: update to test network for AST2700

 hw/arm/aspeed_ast27x0.c         |   3 +-
 hw/block/m25p80.c               |  16 ++++
 hw/net/ftgmac100.c              | 158 +++++++++++++++++++++++++++-----
 include/hw/net/ftgmac100.h      |  24 +++--
 tests/avocado/machine_aspeed.py |  13 +--
 5 files changed, 178 insertions(+), 36 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/5 hw/net:ftgmac100: update memory region size to 0x200

According to the datasheet of ASPEED SOCs,
one MAC controller owns 128KB of register space for AST2500.

However, one MAC controller only owns 64KB of register space for AST2600 and AST2700.

It set the memory region size 128KB and it occupied another controllers Address Spaces.

Currently, the ftgmac100 model use 0x100 register space.
To support DMA 64 bits dram address and new future mode(ftgmac100_high) which have "Normal Priority Transmit Ring Base Address Register High(0x17C)", "High Priority Transmit Ring Base Address Register High(0x184)" and "Receive Ring Base Address Register High(0x18C)" to save the high part physical address of descriptor manager.

Update memory region size to 0x200.

---
 hw/net/ftgmac100.c         | 2 +-
 include/hw/net/ftgmac100.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
hw/net/ftgmac100.c +1 -1
index 25e4c0cd5b..4e88430b2f 100644
@@ -1108,7 +1108,7 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
     }
 
     memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,
-                          TYPE_FTGMAC100, 0x2000);
+                          TYPE_FTGMAC100, FTGMAC100_NR_REGS);
     sysbus_init_mmio(sbd, &s->iomem);
     sysbus_init_irq(sbd, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
include/hw/net/ftgmac100.h +2 -0
index 765d1538a4..5a970676da 100644
@@ -14,6 +14,8 @@
 #define TYPE_FTGMAC100 "ftgmac100"
 OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
 
+#define FTGMAC100_NR_REGS   0x200
+
 #include "hw/sysbus.h"
 #include "net/net.h"
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/5] hw/net:ftgmac100: update memory region size to 0x200

Quoted 42 lines · Jamin Lin

According to the datasheet of ASPEED SOCs,
one MAC controller owns 128KB of register space for AST2500.

However, one MAC controller only owns 64KB of register space for AST2600 and AST2700.

It set the memory region size 128KB and it occupied another controllers Address Spaces.

Currently, the ftgmac100 model use 0x100 register space.
To support DMA 64 bits dram address and new future mode(ftgmac100_high) which have "Normal Priority Transmit Ring Base Address Register High(0x17C)", "High Priority Transmit Ring Base Address Register High(0x184)" and "Receive Ring Base Address Register High(0x18C)" to save the high part physical address of descriptor manager.

Update memory region size to 0x200.

---
  hw/net/ftgmac100.c         | 2 +-
  include/hw/net/ftgmac100.h | 2 ++
  2 files changed, 3 insertions(+), 1 deletion(-)
hw/net/ftgmac100.c +1 -1
index 25e4c0cd5b..4e88430b2f 100644
@@ -1108,7 +1108,7 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
      }
 
      memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,
-                          TYPE_FTGMAC100, 0x2000);
+                          TYPE_FTGMAC100, FTGMAC100_NR_REGS);
      sysbus_init_mmio(sbd, &s->iomem);
      sysbus_init_irq(sbd, &s->irq);
      qemu_macaddr_default_if_unset(&s->conf.macaddr);
include/hw/net/ftgmac100.h +0 -0
index 765d1538a4..5a970676da 100644

include/hw/net/ftgmac100.h line 17

Quoted 4 lines
include/hw/net/ftgmac100.h +1 -0
@@ -14,6 +14,8 @@
  #define TYPE_FTGMAC100 "ftgmac100"
  OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
 
+#define FTGMAC100_NR_REGS   0x200

Since this value will size a memory region, I think the define name should be changed to FTGMAC100_{MEM,REGION,MMIO}_SIZE. What ever you prefer.

Thanks,

C.

Quoted 4 lines
include/hw/net/ftgmac100.h +1 -0
+
  #include "hw/sysbus.h"
  #include "net/net.h"
 
#3 lore raw

RE: [PATCH v2 1/5] hw/net:ftgmac100: update memory region size to 0x200

Hi Cedric,

Quoted 52 lines

Subject: Re: [PATCH v2 1/5] hw/net:ftgmac100: update memory region size to 0x200

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev,

Quoted 29 lines · Jamin Lin

According to the datasheet of ASPEED SOCs, one MAC controller owns 128KB of register space for AST2500.

However, one MAC controller only owns 64KB of register space for AST2600 and AST2700.

It set the memory region size 128KB and it occupied another controllers Address Spaces.

Currently, the ftgmac100 model use 0x100 register space.
To support DMA 64 bits dram address and new future mode(ftgmac100_high) which have "Normal Priority Transmit Ring Base Address Register High(0x17C)", "High Priority Transmit Ring Base Address Register High(0x184)" and "Receive Ring Base Address Register High(0x18C)" to save the high part physical address of descriptor manager.

Update memory region size to 0x200.

---
  hw/net/ftgmac100.c         | 2 +-
  include/hw/net/ftgmac100.h | 2 ++
  2 files changed, 3 insertions(+), 1 deletion(-)
hw/net/ftgmac100.c index renamed from hw/net/ftgmac100.c +0 -0

25e4c0cd5b..4e88430b2f 100644

hw/net/ftgmac100.c +0 -0
@@ -1108,7 +1108,7 @@ static void ftgmac100_realize(DeviceState *dev,

Error **errp)

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, · line 1110

Quoted 3 lines
hw/net/ftgmac100.c +0 -0
      }
 
      memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops,

s,

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, · line 1111

Quoted 2 lines
hw/net/ftgmac100.c +1 -1
-                          TYPE_FTGMAC100, 0x2000);
+                          TYPE_FTGMAC100,

FTGMAC100_NR_REGS);

Quoted 11 lines
hw/net/ftgmac100.c +0 -0
      sysbus_init_mmio(sbd, &s->iomem);
      sysbus_init_irq(sbd, &s->irq);
      qemu_macaddr_default_if_unset(&s->conf.macaddr);
include/hw/net/ftgmac100.h +0 -0
index 765d1538a4..5a970676da 100644
@@ -14,6 +14,8 @@
  #define TYPE_FTGMAC100 "ftgmac100"
  OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
 
Quoted 5 lines

include/hw/net/ftgmac100.h line 17

Quoted 1 line
include/hw/net/ftgmac100.h +1 -0
+#define FTGMAC100_NR_REGS   0x200

Since this value will size a memory region, I think the define name should be changed to FTGMAC100_{MEM,REGION,MMIO}_SIZE. What ever you prefer.

Will fix
Thanks-Jamin

Quoted 11 lines

Thanks,

C.

Quoted 4 lines
include/hw/net/ftgmac100.h +1 -0
+
  #include "hw/sysbus.h"
  #include "net/net.h"
 
#4 lore raw

PATCH v2 3/5 aspeed/soc: update to ftgmac100_high model for AST2700

In reply to Jamin Lin via

ASPEED AST2700 SOC is a 64 bits quad core CPUs (Cortex-a35) And the base address of dram is "0x4 00000000" which is 64bits address.

Update its network model to ftgmac100_high to support 64bits dram address DMA.

---
 hw/arm/aspeed_ast27x0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/arm/aspeed_ast27x0.c +2 -1
index 18e6a8b10c..04604a4bef 100644
@@ -332,7 +332,7 @@ static void aspeed_soc_ast2700_init(Object *obj)
 
     for (i = 0; i < sc->macs_num; i++) {
         object_initialize_child(obj, "ftgmac100[*]", &s->ftgmac100[i],
-                                TYPE_FTGMAC100);
+                                TYPE_FTGMAC100_HIGH);
 
         object_initialize_child(obj, "mii[*]", &s->mii[i], TYPE_ASPEED_MII);
     }
@@ -552,6 +552,7 @@ static void aspeed_soc_ast2700_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    /* Net */
     for (i = 0; i < sc->macs_num; i++) {
         object_property_set_bool(OBJECT(&s->ftgmac100[i]), "aspeed", true,
                                  &error_abort);
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 2/5 hw/net:ftgmac100: support 64 bits dma dram address for AST2700

In reply to Jamin Lin via

ASPEED AST2700 SOC is a 64 bits quad core CPUs (Cortex-a35) And the base address of dram is "0x4 00000000" which is 64bits address.

It have "Normal Priority Transmit Ring Base Address Register High(0x17C)", "High Priority Transmit Ring Base Address Register High(0x184)" and "Receive Ring Base Address Register High(0x18C)" to save the high part physical address of descriptor manager.
Ex: TX descriptor manager address [34:0]
The "Normal Priority Transmit Ring Base Address Register High(0x17C)" bits [2:0] which corresponds the bits [34:32] of the 64 bits address of the TX ring buffer address.
The "Normal Priority Transmit Ring Base Address Register(0x20)" bits [31:0] which corresponds the bits [31:0] of the 64 bits address
of the TX ring buffer address.

Besides, it have "TXDES 2" and "RXDES 2"
to save the high part physical address of packet buffer.
Ex: TX packet buffer address [34:0]
The "TXDES 2" bits [18:16] which corresponds the bits [34:32] of the 64 bits address of the TX packet buffer address and "TXDES 3" bits [31:0] which corresponds the bits [31:0] of the 64 bits address of the TX packet buffer address.

Update TX/RX ring and descriptor data type to uint64_t and supports TX/RX ring, descriptor and packet buffers 64 bits address for all ASPEED SOCs models.

Incrementing the version of vmstate to 2.

Introduce a new class(ftgmac100_high),
class attribute and memop handlers,
the realize handler instantiate a new memory
region and map it on top of the current one to
read/write FTGMAC100_*_HIGH regs.

---
 hw/net/ftgmac100.c         | 156 ++++++++++++++++++++++++++++++++-----
 include/hw/net/ftgmac100.h |  24 ++++--
 2 files changed, 151 insertions(+), 29 deletions(-)
hw/net/ftgmac100.c +135 -21
index 4e88430b2f..3d13f54efc 100644
@@ -56,6 +56,16 @@
 #define FTGMAC100_PHYDATA         0x64
 #define FTGMAC100_FCR             0x68
 
+/*
+ * FTGMAC100 High registers
+ *
+ * values below are offset by - FTGMAC100_HIGH_OFFSET from datasheet
+ * because its memory region is start at FTGMAC100_HIGH_OFFSET
+ */
+#define FTGMAC100_NPTXR_BADR_HIGH   (0x17C - FTGMAC100_HIGH_OFFSET)
+#define FTGMAC100_HPTXR_BADR_HIGH   (0x184 - FTGMAC100_HIGH_OFFSET)
+#define FTGMAC100_RXR_BADR_HIGH     (0x18C - FTGMAC100_HIGH_OFFSET)
+
 /*
  * Interrupt status register & interrupt enable register
  */
@@ -165,6 +175,8 @@
 #define FTGMAC100_TXDES1_TX2FIC          (1 << 30)
 #define FTGMAC100_TXDES1_TXIC            (1 << 31)
 
+#define FTGMAC100_TXDES2_TXBUF_BADR_HI(x)   (((x) >> 16) & 0x7)
+
 /*
  * Receive descriptor
  */
@@ -198,13 +210,15 @@
 #define FTGMAC100_RXDES1_UDP_CHKSUM_ERR  (1 << 26)
 #define FTGMAC100_RXDES1_IP_CHKSUM_ERR   (1 << 27)
 
+#define FTGMAC100_RXDES2_RXBUF_BADR_HI(x)   (((x) >> 16) & 0x7)
+
 /*
  * Receive and transmit Buffer Descriptor
  */
 typedef struct {
     uint32_t        des0;
     uint32_t        des1;
-    uint32_t        des2;        /* not used by HW */
+    uint32_t        des2;        /* used by HW high address */
     uint32_t        des3;
 } FTGMAC100Desc;
 
@@ -515,12 +529,14 @@ out:
     return frame_size;
 }
 
-static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
-                            uint32_t tx_descriptor)
+static void ftgmac100_do_tx(FTGMAC100State *s, uint64_t tx_ring,
+                            uint64_t tx_descriptor)
 {
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
     int frame_size = 0;
     uint8_t *ptr = s->frame;
-    uint32_t addr = tx_descriptor;
+    uint64_t addr = tx_descriptor;
+    uint64_t buf_addr = 0;
     uint32_t flags = 0;
 
     while (1) {
@@ -559,7 +575,12 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
             len =  sizeof(s->frame) - frame_size;
         }
 
-        if (dma_memory_read(&address_space_memory, bd.des3,
+        buf_addr = bd.des3;
+        if (fc->is_dma64) {
+            buf_addr = deposit64(buf_addr, 32, 32,
+                                 FTGMAC100_TXDES2_TXBUF_BADR_HI(bd.des2));
+        }
+        if (dma_memory_read(&address_space_memory, buf_addr,
                             ptr, len, MEMTXATTRS_UNSPECIFIED)) {
             qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to read packet @ 0x%x\n",
                           __func__, bd.des3);
@@ -726,9 +747,9 @@ static uint64_t ftgmac100_read(void *opaque, hwaddr addr, unsigned size)
     case FTGMAC100_MATH1:
         return s->math[1];
     case FTGMAC100_RXR_BADR:
-        return s->rx_ring;
+        return extract64(s->rx_ring, 0, 32);
     case FTGMAC100_NPTXR_BADR:
-        return s->tx_ring;
+        return extract64(s->tx_ring, 0, 32);
     case FTGMAC100_ITC:
         return s->itc;
     case FTGMAC100_DBLAC:
@@ -799,9 +820,8 @@ static void ftgmac100_write(void *opaque, hwaddr addr,
                           HWADDR_PRIx "\n", __func__, value);
             return;
         }
-
-        s->rx_ring = value;
-        s->rx_descriptor = s->rx_ring;
+        s->rx_ring = deposit64(s->rx_ring, 0, 32, value);
+        s->rx_descriptor = deposit64(s->rx_descriptor, 0, 32, value);
         break;
 
     case FTGMAC100_RBSR: /* DMA buffer size */
@@ -814,8 +834,8 @@ static void ftgmac100_write(void *opaque, hwaddr addr,
                           HWADDR_PRIx "\n", __func__, value);
             return;
         }
-        s->tx_ring = value;
-        s->tx_descriptor = s->tx_ring;
+        s->tx_ring = deposit64(s->tx_ring, 0, 32, value);
+        s->tx_descriptor = deposit64(s->tx_descriptor, 0, 32, value);
         break;
 
     case FTGMAC100_NPTXPD: /* Trigger transmit */
@@ -914,6 +934,60 @@ static void ftgmac100_write(void *opaque, hwaddr addr,
     ftgmac100_update_irq(s);
 }
 
+static uint64_t ftgmac100_high_read(void *opaque, hwaddr addr, unsigned size)
+{
+    FTGMAC100State *s = FTGMAC100(opaque);
+    uint64_t val = 0;
+
+    switch (addr) {
+    case FTGMAC100_NPTXR_BADR_HIGH:
+        val = extract64(s->tx_ring, 32, 32);
+        break;
+    case FTGMAC100_HPTXR_BADR_HIGH:
+        /* High Priority Transmit Ring Base High Address */
+        qemu_log_mask(LOG_UNIMP, "%s: read to unimplemented register 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    case FTGMAC100_RXR_BADR_HIGH:
+        val = extract64(s->rx_ring, 32, 32);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    }
+
+    return val;
+}
+
+static void ftgmac100_high_write(void *opaque, hwaddr addr,
+                          uint64_t value, unsigned size)
+{
+    FTGMAC100State *s = FTGMAC100(opaque);
+
+    switch (addr) {
+    case FTGMAC100_NPTXR_BADR_HIGH:
+        s->tx_ring = deposit64(s->tx_ring, 32, 32, value);
+        s->tx_descriptor = deposit64(s->tx_descriptor, 32, 32, value);
+        break;
+    case FTGMAC100_HPTXR_BADR_HIGH:
+        /* High Priority Transmit Ring Base High Address */
+        qemu_log_mask(LOG_UNIMP, "%s: write to unimplemented register 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    case FTGMAC100_RXR_BADR_HIGH:
+        s->rx_ring = deposit64(s->rx_ring, 32, 32, value);
+        s->rx_descriptor = deposit64(s->rx_descriptor, 32, 32, value);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    }
+
+    ftgmac100_update_irq(s);
+}
+
 static int ftgmac100_filter(FTGMAC100State *s, const uint8_t *buf, size_t len)
 {
     unsigned mcast_idx;
@@ -955,11 +1029,12 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
                                  size_t len)
 {
     FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
     FTGMAC100Desc bd;
     uint32_t flags = 0;
-    uint32_t addr;
+    uint64_t addr;
     uint32_t crc;
-    uint32_t buf_addr;
+    uint64_t buf_addr = 0;
     uint8_t *crc_ptr;
     uint32_t buf_len;
     size_t size = len;
@@ -1024,7 +1099,12 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
         if (size < 4) {
             buf_len += size - 4;
         }
+
         buf_addr = bd.des3;
+        if (fc->is_dma64) {
+            buf_addr = deposit64(buf_addr, 32, 32,
+                                 FTGMAC100_RXDES2_RXBUF_BADR_HI(bd.des2));
+        }
         if (first && proto == ETH_P_VLAN && buf_len >= 18) {
             bd.des1 = lduw_be_p(buf + 14) | FTGMAC100_RXDES1_VLANTAG_AVAIL;
 
@@ -1078,6 +1158,14 @@ static const MemoryRegionOps ftgmac100_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
+static const MemoryRegionOps ftgmac100_high_ops = {
+    .read = ftgmac100_high_read,
+    .write = ftgmac100_high_write,
+    .valid.min_access_size = 4,
+    .valid.max_access_size = 4,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 static void ftgmac100_cleanup(NetClientState *nc)
 {
     FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
@@ -1097,6 +1185,7 @@ static NetClientInfo net_ftgmac100_info = {
 static void ftgmac100_realize(DeviceState *dev, Error **errp)
 {
     FTGMAC100State *s = FTGMAC100(dev);
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
     if (s->aspeed) {
@@ -1107,9 +1196,17 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
         s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR;
     }
 
-    memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,
+    memory_region_init_io(&s->iomem, OBJECT(s), &ftgmac100_ops, s,
                           TYPE_FTGMAC100, FTGMAC100_NR_REGS);
     sysbus_init_mmio(sbd, &s->iomem);
+
+    if (fc->is_dma64) {
+        memory_region_init_io(&s->iomem_high, OBJECT(s), &ftgmac100_high_ops,
+                              s, TYPE_FTGMAC100_HIGH, FTGMAC100_HIGH_NR_REGS);
+        memory_region_add_subregion(&s->iomem, FTGMAC100_HIGH_OFFSET,
+                                    &s->iomem_high);
+    }
+
     sysbus_init_irq(sbd, &s->irq);
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
@@ -1121,18 +1218,14 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
 
 static const VMStateDescription vmstate_ftgmac100 = {
     .name = TYPE_FTGMAC100,
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
     .fields = (const VMStateField[]) {
         VMSTATE_UINT32(irq_state, FTGMAC100State),
         VMSTATE_UINT32(isr, FTGMAC100State),
         VMSTATE_UINT32(ier, FTGMAC100State),
         VMSTATE_UINT32(rx_enabled, FTGMAC100State),
-        VMSTATE_UINT32(rx_ring, FTGMAC100State),
         VMSTATE_UINT32(rbsr, FTGMAC100State),
-        VMSTATE_UINT32(tx_ring, FTGMAC100State),
-        VMSTATE_UINT32(rx_descriptor, FTGMAC100State),
-        VMSTATE_UINT32(tx_descriptor, FTGMAC100State),
         VMSTATE_UINT32_ARRAY(math, FTGMAC100State, 2),
         VMSTATE_UINT32(itc, FTGMAC100State),
         VMSTATE_UINT32(aptcr, FTGMAC100State),
@@ -1151,6 +1244,10 @@ static const VMStateDescription vmstate_ftgmac100 = {
         VMSTATE_UINT32(phy_int_mask, FTGMAC100State),
         VMSTATE_UINT32(txdes0_edotr, FTGMAC100State),
         VMSTATE_UINT32(rxdes0_edorr, FTGMAC100State),
+        VMSTATE_UINT64(rx_ring, FTGMAC100State),
+        VMSTATE_UINT64(tx_ring, FTGMAC100State),
+        VMSTATE_UINT64(rx_descriptor, FTGMAC100State),
+        VMSTATE_UINT64(tx_descriptor, FTGMAC100State),
         VMSTATE_END_OF_LIST()
     }
 };
@@ -1180,6 +1277,22 @@ static const TypeInfo ftgmac100_info = {
     .class_init = ftgmac100_class_init,
 };
 
+static void ftgmac100_high_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    FTGMAC100Class *fc = FTGMAC100_CLASS(klass);
+
+    dc->desc = "Faraday FTGMAC100 Gigabit Ethernet High emulation";
+    fc->is_dma64 = true;
+}
+
+static const TypeInfo ftgmac100_high_info = {
+    .name = TYPE_FTGMAC100_HIGH,
+    .parent = TYPE_FTGMAC100,
+    .instance_size = sizeof(FTGMAC100State),
+    .class_init = ftgmac100_high_class_init,
+};
+
 /*
  * AST2600 MII controller
  */
@@ -1342,6 +1455,7 @@ static const TypeInfo aspeed_mii_info = {
 static void ftgmac100_register_types(void)
 {
     type_register_static(&ftgmac100_info);
+    type_register_static(&ftgmac100_high_info);
     type_register_static(&aspeed_mii_info);
 }
 
include/hw/net/ftgmac100.h +16 -8
index 5a970676da..3e44ed97c9 100644
@@ -12,13 +12,15 @@
 #include "qom/object.h"
 
 #define TYPE_FTGMAC100 "ftgmac100"
-OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
+#define TYPE_FTGMAC100_HIGH "ftgmac100_high"
+OBJECT_DECLARE_TYPE(FTGMAC100State, FTGMAC100Class, FTGMAC100)
 
-#define FTGMAC100_NR_REGS   0x200
+#define FTGMAC100_NR_REGS 0x200
+#define FTGMAC100_HIGH_OFFSET 0x100
+#define FTGMAC100_HIGH_NR_REGS 0x100
 
 #include "hw/sysbus.h"
 #include "net/net.h"
-
 /*
  * Max frame size for the receiving buffer
  */
@@ -33,6 +35,7 @@ struct FTGMAC100State {
     NICConf conf;
     qemu_irq irq;
     MemoryRegion iomem;
+    MemoryRegion iomem_high;
 
     uint8_t frame[FTGMAC100_MAX_FRAME_SIZE];
 
@@ -40,10 +43,6 @@ struct FTGMAC100State {
     uint32_t isr;
     uint32_t ier;
     uint32_t rx_enabled;
-    uint32_t rx_ring;
-    uint32_t rx_descriptor;
-    uint32_t tx_ring;
-    uint32_t tx_descriptor;
     uint32_t math[2];
     uint32_t rbsr;
     uint32_t itc;
@@ -56,7 +55,10 @@ struct FTGMAC100State {
     uint32_t phycr;
     uint32_t phydata;
     uint32_t fcr;
-
+    uint64_t rx_ring;
+    uint64_t rx_descriptor;
+    uint64_t tx_ring;
+    uint64_t tx_descriptor;
 
     uint32_t phy_status;
     uint32_t phy_control;
@@ -69,6 +71,12 @@ struct FTGMAC100State {
     uint32_t rxdes0_edorr;
 };
 
+struct FTGMAC100Class {
+    SysBusDeviceClass parent_class;
+
+    bool is_dma64;
+};
+
 #define TYPE_ASPEED_MII "aspeed-mmi"
 OBJECT_DECLARE_SIMPLE_TYPE(AspeedMiiState, ASPEED_MII)
 
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v2 2/5] hw/net:ftgmac100: support 64 bits dma dram address for AST2700

Quoted 94 lines · Jamin Lin

ASPEED AST2700 SOC is a 64 bits quad core CPUs (Cortex-a35) And the base address of dram is "0x4 00000000" which is 64bits address.

It have "Normal Priority Transmit Ring Base Address Register High(0x17C)", "High Priority Transmit Ring Base Address Register High(0x184)" and "Receive Ring Base Address Register High(0x18C)" to save the high part physical address of descriptor manager.
Ex: TX descriptor manager address [34:0]
The "Normal Priority Transmit Ring Base Address Register High(0x17C)" bits [2:0] which corresponds the bits [34:32] of the 64 bits address of the TX ring buffer address.
The "Normal Priority Transmit Ring Base Address Register(0x20)" bits [31:0] which corresponds the bits [31:0] of the 64 bits address
of the TX ring buffer address.

Besides, it have "TXDES 2" and "RXDES 2"
to save the high part physical address of packet buffer.
Ex: TX packet buffer address [34:0]
The "TXDES 2" bits [18:16] which corresponds the bits [34:32] of the 64 bits address of the TX packet buffer address and "TXDES 3" bits [31:0] which corresponds the bits [31:0] of the 64 bits address of the TX packet buffer address.

Update TX/RX ring and descriptor data type to uint64_t and supports TX/RX ring, descriptor and packet buffers 64 bits address for all ASPEED SOCs models.

Incrementing the version of vmstate to 2.

Introduce a new class(ftgmac100_high),
class attribute and memop handlers,
the realize handler instantiate a new memory
region and map it on top of the current one to
read/write FTGMAC100_*_HIGH regs.

---
  hw/net/ftgmac100.c         | 156 ++++++++++++++++++++++++++++++++-----
  include/hw/net/ftgmac100.h |  24 ++++--
  2 files changed, 151 insertions(+), 29 deletions(-)
hw/net/ftgmac100.c +15 -2
index 4e88430b2f..3d13f54efc 100644
@@ -56,6 +56,16 @@
  #define FTGMAC100_PHYDATA         0x64
  #define FTGMAC100_FCR             0x68
 
+/*
+ * FTGMAC100 High registers
+ *
+ * values below are offset by - FTGMAC100_HIGH_OFFSET from datasheet
+ * because its memory region is start at FTGMAC100_HIGH_OFFSET
+ */
+#define FTGMAC100_NPTXR_BADR_HIGH   (0x17C - FTGMAC100_HIGH_OFFSET)
+#define FTGMAC100_HPTXR_BADR_HIGH   (0x184 - FTGMAC100_HIGH_OFFSET)
+#define FTGMAC100_RXR_BADR_HIGH     (0x18C - FTGMAC100_HIGH_OFFSET)
+
  /*
   * Interrupt status register & interrupt enable register
   */
@@ -165,6 +175,8 @@
  #define FTGMAC100_TXDES1_TX2FIC          (1 << 30)
  #define FTGMAC100_TXDES1_TXIC            (1 << 31)
 
+#define FTGMAC100_TXDES2_TXBUF_BADR_HI(x)   (((x) >> 16) & 0x7)
+
  /*
   * Receive descriptor
   */
@@ -198,13 +210,15 @@
  #define FTGMAC100_RXDES1_UDP_CHKSUM_ERR  (1 << 26)
  #define FTGMAC100_RXDES1_IP_CHKSUM_ERR   (1 << 27)
 
+#define FTGMAC100_RXDES2_RXBUF_BADR_HI(x)   (((x) >> 16) & 0x7)
+
  /*
   * Receive and transmit Buffer Descriptor
   */
  typedef struct {
      uint32_t        des0;
      uint32_t        des1;
-    uint32_t        des2;        /* not used by HW */
+    uint32_t        des2;        /* used by HW high address */
      uint32_t        des3;
  } FTGMAC100Desc;
 
@@ -515,12 +529,14 @@ out:
      return frame_size;
  }
 
-static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,

hw/net/ftgmac100.c out: · line 539

Quoted 10 lines
hw/net/ftgmac100.c +5 -2
-                            uint32_t tx_descriptor)
+static void ftgmac100_do_tx(FTGMAC100State *s, uint64_t tx_ring,
+                            uint64_t tx_descriptor)
  {
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
      int frame_size = 0;
      uint8_t *ptr = s->frame;
-    uint32_t addr = tx_descriptor;
+    uint64_t addr = tx_descriptor;
+    uint64_t buf_addr = 0;

To ease reading, I would extract in a standalone patch the part converting addresses to 64 bits.

Quoted 169 lines
hw/net/ftgmac100.c +83 -11
      uint32_t flags = 0;
 
      while (1) {
@@ -559,7 +575,12 @@ static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
              len =  sizeof(s->frame) - frame_size;
          }
 
-        if (dma_memory_read(&address_space_memory, bd.des3,
+        buf_addr = bd.des3;
+        if (fc->is_dma64) {
+            buf_addr = deposit64(buf_addr, 32, 32,
+                                 FTGMAC100_TXDES2_TXBUF_BADR_HI(bd.des2));
+        }
+        if (dma_memory_read(&address_space_memory, buf_addr,
                              ptr, len, MEMTXATTRS_UNSPECIFIED)) {
              qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to read packet @ 0x%x\n",
                            __func__, bd.des3);
@@ -726,9 +747,9 @@ static uint64_t ftgmac100_read(void *opaque, hwaddr addr, unsigned size)
      case FTGMAC100_MATH1:
          return s->math[1];
      case FTGMAC100_RXR_BADR:
-        return s->rx_ring;
+        return extract64(s->rx_ring, 0, 32);
      case FTGMAC100_NPTXR_BADR:
-        return s->tx_ring;
+        return extract64(s->tx_ring, 0, 32);
      case FTGMAC100_ITC:
          return s->itc;
      case FTGMAC100_DBLAC:
@@ -799,9 +820,8 @@ static void ftgmac100_write(void *opaque, hwaddr addr,
                            HWADDR_PRIx "\n", __func__, value);
              return;
          }
-
-        s->rx_ring = value;
-        s->rx_descriptor = s->rx_ring;
+        s->rx_ring = deposit64(s->rx_ring, 0, 32, value);
+        s->rx_descriptor = deposit64(s->rx_descriptor, 0, 32, value);
          break;
 
      case FTGMAC100_RBSR: /* DMA buffer size */
@@ -814,8 +834,8 @@ static void ftgmac100_write(void *opaque, hwaddr addr,
                            HWADDR_PRIx "\n", __func__, value);
              return;
          }
-        s->tx_ring = value;
-        s->tx_descriptor = s->tx_ring;
+        s->tx_ring = deposit64(s->tx_ring, 0, 32, value);
+        s->tx_descriptor = deposit64(s->tx_descriptor, 0, 32, value);
          break;
 
      case FTGMAC100_NPTXPD: /* Trigger transmit */
@@ -914,6 +934,60 @@ static void ftgmac100_write(void *opaque, hwaddr addr,
      ftgmac100_update_irq(s);
  }
 
+static uint64_t ftgmac100_high_read(void *opaque, hwaddr addr, unsigned size)
+{
+    FTGMAC100State *s = FTGMAC100(opaque);
+    uint64_t val = 0;
+
+    switch (addr) {
+    case FTGMAC100_NPTXR_BADR_HIGH:
+        val = extract64(s->tx_ring, 32, 32);
+        break;
+    case FTGMAC100_HPTXR_BADR_HIGH:
+        /* High Priority Transmit Ring Base High Address */
+        qemu_log_mask(LOG_UNIMP, "%s: read to unimplemented register 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    case FTGMAC100_RXR_BADR_HIGH:
+        val = extract64(s->rx_ring, 32, 32);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    }
+
+    return val;
+}
+
+static void ftgmac100_high_write(void *opaque, hwaddr addr,
+                          uint64_t value, unsigned size)
+{
+    FTGMAC100State *s = FTGMAC100(opaque);
+
+    switch (addr) {
+    case FTGMAC100_NPTXR_BADR_HIGH:
+        s->tx_ring = deposit64(s->tx_ring, 32, 32, value);
+        s->tx_descriptor = deposit64(s->tx_descriptor, 32, 32, value);
+        break;
+    case FTGMAC100_HPTXR_BADR_HIGH:
+        /* High Priority Transmit Ring Base High Address */
+        qemu_log_mask(LOG_UNIMP, "%s: write to unimplemented register 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    case FTGMAC100_RXR_BADR_HIGH:
+        s->rx_ring = deposit64(s->rx_ring, 32, 32, value);
+        s->rx_descriptor = deposit64(s->rx_descriptor, 32, 32, value);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset 0x%"
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    }
+
+    ftgmac100_update_irq(s);
+}
+
  static int ftgmac100_filter(FTGMAC100State *s, const uint8_t *buf, size_t len)
  {
      unsigned mcast_idx;
@@ -955,11 +1029,12 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
                                   size_t len)
  {
      FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
      FTGMAC100Desc bd;
      uint32_t flags = 0;
-    uint32_t addr;
+    uint64_t addr;
      uint32_t crc;
-    uint32_t buf_addr;
+    uint64_t buf_addr = 0;
      uint8_t *crc_ptr;
      uint32_t buf_len;
      size_t size = len;
@@ -1024,7 +1099,12 @@ static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,
          if (size < 4) {
              buf_len += size - 4;
          }
+
          buf_addr = bd.des3;
+        if (fc->is_dma64) {
+            buf_addr = deposit64(buf_addr, 32, 32,
+                                 FTGMAC100_RXDES2_RXBUF_BADR_HI(bd.des2));
+        }
          if (first && proto == ETH_P_VLAN && buf_len >= 18) {
              bd.des1 = lduw_be_p(buf + 14) | FTGMAC100_RXDES1_VLANTAG_AVAIL;
 
@@ -1078,6 +1158,14 @@ static const MemoryRegionOps ftgmac100_ops = {
      .endianness = DEVICE_LITTLE_ENDIAN,
  };
 
+static const MemoryRegionOps ftgmac100_high_ops = {
+    .read = ftgmac100_high_read,
+    .write = ftgmac100_high_write,
+    .valid.min_access_size = 4,
+    .valid.max_access_size = 4,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
  static void ftgmac100_cleanup(NetClientState *nc)
  {
      FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
@@ -1097,6 +1185,7 @@ static NetClientInfo net_ftgmac100_info = {
  static void ftgmac100_realize(DeviceState *dev, Error **errp)
  {
      FTGMAC100State *s = FTGMAC100(dev);
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
      if (s->aspeed) {
@@ -1107,9 +1196,17 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
          s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR;
      }
 
-    memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, Error **errp) · line 1208

Quoted 10 lines
hw/net/ftgmac100.c +8 -0
+    memory_region_init_io(&s->iomem, OBJECT(s), &ftgmac100_ops, s,
                            TYPE_FTGMAC100, FTGMAC100_NR_REGS);
      sysbus_init_mmio(sbd, &s->iomem);
+
+    if (fc->is_dma64) {
+        memory_region_init_io(&s->iomem_high, OBJECT(s), &ftgmac100_high_ops,
+                              s, TYPE_FTGMAC100_HIGH, FTGMAC100_HIGH_NR_REGS);
+        memory_region_add_subregion(&s->iomem, FTGMAC100_HIGH_OFFSET,
+                                    &s->iomem_high);
+    }

I think that, first, we should introduce a container region. In this container region would be mapped a sub region for the current set of registers. This container region would be the one that the SoC maps as it is done today.

Then, in a second patch, we should introduce a extra sub region for the set of new registers and map it at 0x100 in the container region.

It is close to what you did but it lacks an overall container region. This container region should be sized as specified in the datasheet.

Quoted 37 lines
hw/net/ftgmac100.c +6 -6
      sysbus_init_irq(sbd, &s->irq);
      qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
@@ -1121,18 +1218,14 @@ static void ftgmac100_realize(DeviceState *dev, Error **errp)
 
  static const VMStateDescription vmstate_ftgmac100 = {
      .name = TYPE_FTGMAC100,
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
      .fields = (const VMStateField[]) {
          VMSTATE_UINT32(irq_state, FTGMAC100State),
          VMSTATE_UINT32(isr, FTGMAC100State),
          VMSTATE_UINT32(ier, FTGMAC100State),
          VMSTATE_UINT32(rx_enabled, FTGMAC100State),
-        VMSTATE_UINT32(rx_ring, FTGMAC100State),
          VMSTATE_UINT32(rbsr, FTGMAC100State),
-        VMSTATE_UINT32(tx_ring, FTGMAC100State),
-        VMSTATE_UINT32(rx_descriptor, FTGMAC100State),
-        VMSTATE_UINT32(tx_descriptor, FTGMAC100State),
          VMSTATE_UINT32_ARRAY(math, FTGMAC100State, 2),
          VMSTATE_UINT32(itc, FTGMAC100State),
          VMSTATE_UINT32(aptcr, FTGMAC100State),
@@ -1151,6 +1244,10 @@ static const VMStateDescription vmstate_ftgmac100 = {
          VMSTATE_UINT32(phy_int_mask, FTGMAC100State),
          VMSTATE_UINT32(txdes0_edotr, FTGMAC100State),
          VMSTATE_UINT32(rxdes0_edorr, FTGMAC100State),
+        VMSTATE_UINT64(rx_ring, FTGMAC100State),
+        VMSTATE_UINT64(tx_ring, FTGMAC100State),
+        VMSTATE_UINT64(rx_descriptor, FTGMAC100State),
+        VMSTATE_UINT64(tx_descriptor, FTGMAC100State),
          VMSTATE_END_OF_LIST()
      }
  };
@@ -1180,6 +1277,22 @@ static const TypeInfo ftgmac100_info = {
      .class_init = ftgmac100_class_init,

hw/net/ftgmac100.c static const TypeInfo ftgmac100_info = { · line 1287

Quoted 10 lines
hw/net/ftgmac100.c +8 -0
  };
 
+static void ftgmac100_high_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    FTGMAC100Class *fc = FTGMAC100_CLASS(klass);
+
+    dc->desc = "Faraday FTGMAC100 Gigabit Ethernet High emulation";
+    fc->is_dma64 = true;
+}

Using a property to activate the region for new registers, instead of a class, would simplify the changes IMO. Let's call the property "dma64" ?

Thanks,

C.

Quoted 86 lines
hw/net/ftgmac100.c +9 -0
+
+static const TypeInfo ftgmac100_high_info = {
+    .name = TYPE_FTGMAC100_HIGH,
+    .parent = TYPE_FTGMAC100,
+    .instance_size = sizeof(FTGMAC100State),
+    .class_init = ftgmac100_high_class_init,
+};
+
  /*
   * AST2600 MII controller
   */
@@ -1342,6 +1455,7 @@ static const TypeInfo aspeed_mii_info = {
  static void ftgmac100_register_types(void)
  {
      type_register_static(&ftgmac100_info);
+    type_register_static(&ftgmac100_high_info);
      type_register_static(&aspeed_mii_info);
  }
 
include/hw/net/ftgmac100.h +16 -8
index 5a970676da..3e44ed97c9 100644
@@ -12,13 +12,15 @@
  #include "qom/object.h"
 
  #define TYPE_FTGMAC100 "ftgmac100"
-OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
+#define TYPE_FTGMAC100_HIGH "ftgmac100_high"
+OBJECT_DECLARE_TYPE(FTGMAC100State, FTGMAC100Class, FTGMAC100)
 
-#define FTGMAC100_NR_REGS   0x200
+#define FTGMAC100_NR_REGS 0x200
+#define FTGMAC100_HIGH_OFFSET 0x100
+#define FTGMAC100_HIGH_NR_REGS 0x100
 
  #include "hw/sysbus.h"
  #include "net/net.h"
-
  /*
   * Max frame size for the receiving buffer
   */
@@ -33,6 +35,7 @@ struct FTGMAC100State {
      NICConf conf;
      qemu_irq irq;
      MemoryRegion iomem;
+    MemoryRegion iomem_high;
 
      uint8_t frame[FTGMAC100_MAX_FRAME_SIZE];
 
@@ -40,10 +43,6 @@ struct FTGMAC100State {
      uint32_t isr;
      uint32_t ier;
      uint32_t rx_enabled;
-    uint32_t rx_ring;
-    uint32_t rx_descriptor;
-    uint32_t tx_ring;
-    uint32_t tx_descriptor;
      uint32_t math[2];
      uint32_t rbsr;
      uint32_t itc;
@@ -56,7 +55,10 @@ struct FTGMAC100State {
      uint32_t phycr;
      uint32_t phydata;
      uint32_t fcr;
-
+    uint64_t rx_ring;
+    uint64_t rx_descriptor;
+    uint64_t tx_ring;
+    uint64_t tx_descriptor;
 
      uint32_t phy_status;
      uint32_t phy_control;
@@ -69,6 +71,12 @@ struct FTGMAC100State {
      uint32_t rxdes0_edorr;
  };
 
+struct FTGMAC100Class {
+    SysBusDeviceClass parent_class;
+
+    bool is_dma64;
+};
+
  #define TYPE_ASPEED_MII "aspeed-mmi"
  OBJECT_DECLARE_SIMPLE_TYPE(AspeedMiiState, ASPEED_MII)
 
#7 lore raw

RE: [PATCH v2 2/5] hw/net:ftgmac100: support 64 bits dma dram address for AST2700

Hi Cedric,

Quoted 95 lines · Jamin Lin
Quoted 29 lines

ASPEED AST2700 SOC is a 64 bits quad core CPUs (Cortex-a35) And the base address of dram is "0x4 00000000" which is 64bits address.

It have "Normal Priority Transmit Ring Base Address Register High(0x17C)", "High Priority Transmit Ring Base Address Register High(0x184)" and "Receive Ring Base Address Register High(0x18C)" to save the high part physical address of descriptor manager.
Ex: TX descriptor manager address [34:0] The "Normal Priority Transmit Ring Base Address Register High(0x17C)"
bits [2:0] which corresponds the bits [34:32] of the 64 bits address of the TX ring buffer address.
The "Normal Priority Transmit Ring Base Address Register(0x20)" bits [31:0] which corresponds the bits [31:0] of the 64 bits address of the TX ring buffer address.

Besides, it have "TXDES 2" and "RXDES 2"
to save the high part physical address of packet buffer.
Ex: TX packet buffer address [34:0]
The "TXDES 2" bits [18:16] which corresponds the bits [34:32] of the 64 bits address of the TX packet buffer address and "TXDES 3" bits [31:0] which corresponds the bits [31:0] of the 64 bits address of the TX packet buffer address.

Update TX/RX ring and descriptor data type to uint64_t and supports TX/RX ring, descriptor and packet buffers
64 bits address for all ASPEED SOCs models.

Incrementing the version of vmstate to 2.

Quoted 7 lines

Introduce a new class(ftgmac100_high), class attribute and memop handlers, the realize handler instantiate a new memory region and map it on top of the current one to read/write FTGMAC100_*_HIGH regs.

---
  hw/net/ftgmac100.c         | 156

++++++++++++++++++++++++++++++++-----

Quoted 8 lines
  include/hw/net/ftgmac100.h |  24 ++++--
  2 files changed, 151 insertions(+), 29 deletions(-)
hw/net/ftgmac100.c index renamed from hw/net/ftgmac100.c +0 -0

4e88430b2f..3d13f54efc 100644

hw/net/ftgmac100.c line 64

Quoted 9 lines
hw/net/ftgmac100.c +6 -0
@@ -56,6 +56,16 @@
  #define FTGMAC100_PHYDATA         0x64
  #define FTGMAC100_FCR             0x68
 
+/*
+ * FTGMAC100 High registers
+ *
+ * values below are offset by - FTGMAC100_HIGH_OFFSET from datasheet
+ * because its memory region is start at FTGMAC100_HIGH_OFFSET  */
+#define FTGMAC100_NPTXR_BADR_HIGH   (0x17C -

FTGMAC100_HIGH_OFFSET)

hw/net/ftgmac100.c line 65

Quoted 1 line
hw/net/ftgmac100.c +1 -0
+#define FTGMAC100_HPTXR_BADR_HIGH   (0x184 -

FTGMAC100_HIGH_OFFSET)

hw/net/ftgmac100.c line 66

Quoted 1 line
hw/net/ftgmac100.c +1 -0
+#define FTGMAC100_RXR_BADR_HIGH     (0x18C -

FTGMAC100_HIGH_OFFSET)

Quoted 34 lines
hw/net/ftgmac100.c +6 -1
+
  /*
   * Interrupt status register & interrupt enable register
   */
@@ -165,6 +175,8 @@
  #define FTGMAC100_TXDES1_TX2FIC          (1 << 30)
  #define FTGMAC100_TXDES1_TXIC            (1 << 31)
 
+#define FTGMAC100_TXDES2_TXBUF_BADR_HI(x)   (((x) >> 16) & 0x7)
+
  /*
   * Receive descriptor
   */
@@ -198,13 +210,15 @@
  #define FTGMAC100_RXDES1_UDP_CHKSUM_ERR  (1 << 26)
  #define FTGMAC100_RXDES1_IP_CHKSUM_ERR   (1 << 27)
 
+#define FTGMAC100_RXDES2_RXBUF_BADR_HI(x)   (((x) >> 16) & 0x7)
+
  /*
   * Receive and transmit Buffer Descriptor
   */
  typedef struct {
      uint32_t        des0;
      uint32_t        des1;
-    uint32_t        des2;        /* not used by HW */
+    uint32_t        des2;        /* used by HW high address */
      uint32_t        des3;
  } FTGMAC100Desc;
 
@@ -515,12 +529,14 @@ out:
      return frame_size;
  }
 
Quoted 14 lines

hw/net/ftgmac100.c out: · line 539

Quoted 11 lines
hw/net/ftgmac100.c +5 -3
-static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,
-                            uint32_t tx_descriptor)
+static void ftgmac100_do_tx(FTGMAC100State *s, uint64_t tx_ring,
+                            uint64_t tx_descriptor)
  {
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
      int frame_size = 0;
      uint8_t *ptr = s->frame;
-    uint32_t addr = tx_descriptor;
+    uint64_t addr = tx_descriptor;
+    uint64_t buf_addr = 0;

To ease reading, I would extract in a standalone patch the part converting addresses to 64 bits.

Will create a new patch

Quoted 205 lines

hw/net/ftgmac100.c static void ftgmac100_do_tx(FTGMAC100State *s,

Quoted 5 lines
hw/net/ftgmac100.c +0 -0
      uint32_t flags = 0;
 
      while (1) {
@@ -559,7 +575,12 @@ static void ftgmac100_do_tx(FTGMAC100State *s,

uint32_t tx_ring,

hw/net/ftgmac100.c static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,

Quoted 8 lines
hw/net/ftgmac100.c +4 -1
              len =  sizeof(s->frame) - frame_size;
          }
 
-        if (dma_memory_read(&address_space_memory, bd.des3,
+        buf_addr = bd.des3;
+        if (fc->is_dma64) {
+            buf_addr = deposit64(buf_addr, 32, 32,
+

FTGMAC100_TXDES2_TXBUF_BADR_HI(bd.des2));

hw/net/ftgmac100.c static void ftgmac100_do_tx(FTGMAC100State *s, uint32_t tx_ring,

Quoted 4 lines
hw/net/ftgmac100.c +2 -0
+        }
+        if (dma_memory_read(&address_space_memory, buf_addr,
                              ptr, len, MEMTXATTRS_UNSPECIFIED)) {
              qemu_log_mask(LOG_GUEST_ERROR, "%s: failed to read

packet @ 0x%x\n",

hw/net/ftgmac100.c static void ftgmac100_do_tx(FTGMAC100State *s, · line 586

Quoted 1 line
hw/net/ftgmac100.c +0 -0
                            __func__, bd.des3); @@ -726,9 +747,9

@@

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr

Quoted 13 lines

static uint64_t ftgmac100_read(void *opaque, hwaddr addr, unsigned size)

      case FTGMAC100_MATH1:
          return s->math[1];
      case FTGMAC100_RXR_BADR:
hw/net/ftgmac100.c +2 -2
-        return s->rx_ring;
+        return extract64(s->rx_ring, 0, 32);
      case FTGMAC100_NPTXR_BADR:
-        return s->tx_ring;
+        return extract64(s->tx_ring, 0, 32);
      case FTGMAC100_ITC:
          return s->itc;
      case FTGMAC100_DBLAC:
@@ -799,9 +820,8 @@ static void ftgmac100_write(void *opaque, hwaddr

addr,

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr addr,

Quoted 11 lines
hw/net/ftgmac100.c +2 -3
                            HWADDR_PRIx "\n", __func__, value);
              return;
          }
-
-        s->rx_ring = value;
-        s->rx_descriptor = s->rx_ring;
+        s->rx_ring = deposit64(s->rx_ring, 0, 32, value);
+        s->rx_descriptor = deposit64(s->rx_descriptor, 0, 32, value);
          break;
 
      case FTGMAC100_RBSR: /* DMA buffer size */ @@ -814,8 +834,8

@@

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr addr,

Quoted 11 lines

static void ftgmac100_write(void *opaque, hwaddr addr,

                            HWADDR_PRIx "\n", __func__, value);
              return;
          }
hw/net/ftgmac100.c +2 -2
-        s->tx_ring = value;
-        s->tx_descriptor = s->tx_ring;
+        s->tx_ring = deposit64(s->tx_ring, 0, 32, value);
+        s->tx_descriptor = deposit64(s->tx_descriptor, 0, 32, value);
          break;
 
      case FTGMAC100_NPTXPD: /* Trigger transmit */ @@ -914,6

+934,60

Quoted 6 lines

@@ static void ftgmac100_write(void *opaque, hwaddr addr,

      ftgmac100_update_irq(s);

}

hw/net/ftgmac100.c +2 -0
+static uint64_t ftgmac100_high_read(void *opaque, hwaddr addr,
+unsigned size) {

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr addr,

Quoted 10 lines
hw/net/ftgmac100.c +10 -0
+    FTGMAC100State *s = FTGMAC100(opaque);
+    uint64_t val = 0;
+
+    switch (addr) {
+    case FTGMAC100_NPTXR_BADR_HIGH:
+        val = extract64(s->tx_ring, 32, 32);
+        break;
+    case FTGMAC100_HPTXR_BADR_HIGH:
+        /* High Priority Transmit Ring Base High Address */
+        qemu_log_mask(LOG_UNIMP, "%s: read to unimplemented

register 0x%"

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr addr,

Quoted 7 lines
hw/net/ftgmac100.c +7 -0
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    case FTGMAC100_RXR_BADR_HIGH:
+        val = extract64(s->rx_ring, 32, 32);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset

0x%"

Quoted 9 lines
hw/net/ftgmac100.c +9 -0
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    }
+
+    return val;
+}
+
+static void ftgmac100_high_write(void *opaque, hwaddr addr,
+                          uint64_t value, unsigned size) {

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr addr,

Quoted 10 lines
hw/net/ftgmac100.c +10 -0
+    FTGMAC100State *s = FTGMAC100(opaque);
+
+    switch (addr) {
+    case FTGMAC100_NPTXR_BADR_HIGH:
+        s->tx_ring = deposit64(s->tx_ring, 32, 32, value);
+        s->tx_descriptor = deposit64(s->tx_descriptor, 32, 32, value);
+        break;
+    case FTGMAC100_HPTXR_BADR_HIGH:
+        /* High Priority Transmit Ring Base High Address */
+        qemu_log_mask(LOG_UNIMP, "%s: write to unimplemented

register 0x%"

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr addr,

Quoted 8 lines
hw/net/ftgmac100.c +8 -0
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    case FTGMAC100_RXR_BADR_HIGH:
+        s->rx_ring = deposit64(s->rx_ring, 32, 32, value);
+        s->rx_descriptor = deposit64(s->rx_descriptor, 32, 32, value);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset

0x%"

hw/net/ftgmac100.c static void ftgmac100_write(void *opaque, hwaddr addr,

Quoted 8 lines
hw/net/ftgmac100.c +7 -0
+                      HWADDR_PRIx "\n", __func__, addr);
+        break;
+    }
+
+    ftgmac100_update_irq(s);
+}
+
  static int ftgmac100_filter(FTGMAC100State *s, const uint8_t *buf, size_t

len)

hw/net/ftgmac100.c static ssize_t ftgmac100_receive(NetClientState

Quoted 3 lines
  {
      unsigned mcast_idx;
hw/net/ftgmac100.c +0 -0
@@ -955,11 +1029,12 @@ static ssize_t ftgmac100_receive(NetClientState

*nc, const uint8_t *buf,

hw/net/ftgmac100.c static ssize_t ftgmac100_receive(NetClientState

Quoted 15 lines
hw/net/ftgmac100.c +3 -2
                                   size_t len)
  {
      FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
      FTGMAC100Desc bd;
      uint32_t flags = 0;
-    uint32_t addr;
+    uint64_t addr;
      uint32_t crc;
-    uint32_t buf_addr;
+    uint64_t buf_addr = 0;
      uint8_t *crc_ptr;
      uint32_t buf_len;
      size_t size = len;
@@ -1024,7 +1099,12 @@ static ssize_t ftgmac100_receive(NetClientState

*nc, const uint8_t *buf,

hw/net/ftgmac100.c static ssize_t ftgmac100_receive(NetClientState *nc, const uint8_t *buf,

Quoted 8 lines
hw/net/ftgmac100.c +4 -0
          if (size < 4) {
              buf_len += size - 4;
          }
+
          buf_addr = bd.des3;
+        if (fc->is_dma64) {
+            buf_addr = deposit64(buf_addr, 32, 32,
+

FTGMAC100_RXDES2_RXBUF_BADR_HI(bd.des2));

hw/net/ftgmac100.c static const MemoryRegionOps ftgmac100_ops =

Quoted 6 lines
hw/net/ftgmac100.c +1 -0
+        }
          if (first && proto == ETH_P_VLAN && buf_len >= 18) {
              bd.des1 = lduw_be_p(buf + 14) |
 FTGMAC100_RXDES1_VLANTAG_AVAIL;
@@ -1078,6 +1158,14 @@ static const MemoryRegionOps ftgmac100_ops =

{

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev,

Quoted 22 lines
hw/net/ftgmac100.c +8 -0
      .endianness = DEVICE_LITTLE_ENDIAN,
  };
 
+static const MemoryRegionOps ftgmac100_high_ops = {
+    .read = ftgmac100_high_read,
+    .write = ftgmac100_high_write,
+    .valid.min_access_size = 4,
+    .valid.max_access_size = 4,
+    .endianness = DEVICE_LITTLE_ENDIAN, };
+
  static void ftgmac100_cleanup(NetClientState *nc)
  {
      FTGMAC100State *s = FTGMAC100(qemu_get_nic_opaque(nc));
@@ -1097,6 +1185,7 @@ static NetClientInfo net_ftgmac100_info = {
  static void ftgmac100_realize(DeviceState *dev, Error **errp)
  {
      FTGMAC100State *s = FTGMAC100(dev);
+    FTGMAC100Class *fc = FTGMAC100_GET_CLASS(s);
      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 
      if (s->aspeed) {
@@ -1107,9 +1196,17 @@ static void ftgmac100_realize(DeviceState *dev,

Error **errp)

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, Error **errp)

Quoted 6 lines
hw/net/ftgmac100.c +1 -1
          s->rxdes0_edorr = FTGMAC100_RXDES0_EDORR;
      }
 
-    memory_region_init_io(&s->iomem, OBJECT(dev), &ftgmac100_ops, s,
+    memory_region_init_io(&s->iomem, OBJECT(s), &ftgmac100_ops, s,
                            TYPE_FTGMAC100,

FTGMAC100_NR_REGS);

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, Error **errp)

Quoted 4 lines
hw/net/ftgmac100.c +3 -0
      sysbus_init_mmio(sbd, &s->iomem);
+
+    if (fc->is_dma64) {
+        memory_region_init_io(&s->iomem_high, OBJECT(s),

&ftgmac100_high_ops,

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, · line 1205

Quoted 1 line
hw/net/ftgmac100.c +1 -0
+                              s, TYPE_FTGMAC100_HIGH,

FTGMAC100_HIGH_NR_REGS);

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, · line 1206

Quoted 1 line
hw/net/ftgmac100.c +1 -0
+        memory_region_add_subregion(&s->iomem,

FTGMAC100_HIGH_OFFSET,

hw/net/ftgmac100.c static void ftgmac100_realize(DeviceState *dev, Error **errp) · line 1208

Quoted 2 lines
hw/net/ftgmac100.c +2 -0
+                                    &s->iomem_high);
+    }

I think that, first, we should introduce a container region. In this container region would be mapped a sub region for the current set of registers. This container region would be the one that the SoC maps as it is done today.

Quoted 6 lines

Then, in a second patch, we should introduce a extra sub region for the set of new registers and map it at 0x100 in the container region.

It is close to what you did but it lacks an overall container region. This container region should be sized as specified in the datasheet.

Do you mean to change as following?

ftgmac100.h
#define FTGMAC100_MEM_SIZE 0x200
#define FTGMAC100_NR_REGS 0x100
#define FTGMAC100_REGS_HIGH_OFFSET 0x100
#define FTGMAC100_NR_REGS_HIGH 0x100

struct FTGMAC100State {
    MemoryRegion iomem_container;
    MemoryRegion iomem;
    MemoryRegion iomem_high;
}

Ftgmac100.c
static void ftgmac100_realize(DeviceState *dev, Error **errp)

{
    memory_region_init(&s->iomem_container, OBJECT(s),
                     TYPE_FTGMAC100 ".container", FTGMAC100_MEM_SIZE);  --> container size 0x200
    sysbus_init_mmio(sbd, &s->iomem_container);

    memory_region_init_io(&s->iomem, OBJECT(s), &ftgmac100_ops, s,
                          TYPE_FTGMAC100 ".regs", FTGMAC100_NR_REGS); --> current register 0x0-0xff
    memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);

    if (s-> dma64) {
        memory_region_init_io(&s->iomem_high, OBJECT(s), &ftgmac100_high_ops,
                              s, TYPE_FTGMAC100 ".regs.high", FTGMAC100_NR_REGS_HIGH); --> high register 0x100-0x1ff
        memory_region_add_subregion(&s->iomem_container, FTGMAC100_REGS_HIGH_OFFSET,
                                    &s->iomem_high);
    }
}
Quoted 41 lines
Quoted 24 lines
hw/net/ftgmac100.c +2 -6
      sysbus_init_irq(sbd, &s->irq);
      qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
@@ -1121,18 +1218,14 @@ static void ftgmac100_realize(DeviceState
 *dev, Error **errp)
 
  static const VMStateDescription vmstate_ftgmac100 = {
      .name = TYPE_FTGMAC100,
-    .version_id = 1,
-    .minimum_version_id = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
      .fields = (const VMStateField[]) {
          VMSTATE_UINT32(irq_state, FTGMAC100State),
          VMSTATE_UINT32(isr, FTGMAC100State),
          VMSTATE_UINT32(ier, FTGMAC100State),
          VMSTATE_UINT32(rx_enabled, FTGMAC100State),
-        VMSTATE_UINT32(rx_ring, FTGMAC100State),
          VMSTATE_UINT32(rbsr, FTGMAC100State),
-        VMSTATE_UINT32(tx_ring, FTGMAC100State),
-        VMSTATE_UINT32(rx_descriptor, FTGMAC100State),
-        VMSTATE_UINT32(tx_descriptor, FTGMAC100State),
          VMSTATE_UINT32_ARRAY(math, FTGMAC100State, 2),
          VMSTATE_UINT32(itc, FTGMAC100State),
Quoted 1 line
          VMSTATE_UINT32(aptcr, FTGMAC100State), @@ -1151,6

+1244,10

Quoted 15 lines
@@ static const VMStateDescription vmstate_ftgmac100 = {
          VMSTATE_UINT32(phy_int_mask, FTGMAC100State),
          VMSTATE_UINT32(txdes0_edotr, FTGMAC100State),
          VMSTATE_UINT32(rxdes0_edorr, FTGMAC100State),
hw/net/ftgmac100.c +4 -0
+        VMSTATE_UINT64(rx_ring, FTGMAC100State),
+        VMSTATE_UINT64(tx_ring, FTGMAC100State),
+        VMSTATE_UINT64(rx_descriptor, FTGMAC100State),
+        VMSTATE_UINT64(tx_descriptor, FTGMAC100State),
          VMSTATE_END_OF_LIST()
      }
  };
@@ -1180,6 +1277,22 @@ static const TypeInfo ftgmac100_info = {
      .class_init = ftgmac100_class_init,
  };
 
Quoted 12 lines

hw/net/ftgmac100.c static const TypeInfo ftgmac100_info = { · line 1287

Quoted 8 lines
hw/net/ftgmac100.c +8 -0
+static void ftgmac100_high_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    FTGMAC100Class *fc = FTGMAC100_CLASS(klass);
+
+    dc->desc = "Faraday FTGMAC100 Gigabit Ethernet High emulation";
+    fc->is_dma64 = true;
+}

Using a property to activate the region for new registers, instead of a class, would simplify the changes IMO. Let's call the property "dma64" ?

Thanks for suggestion.
Will change to use object attribute and property instead of a class

Thanks-Jamin

Quoted 91 lines

Thanks,

C.

Quoted 85 lines
hw/net/ftgmac100.c +8 -0
+
+static const TypeInfo ftgmac100_high_info = {
+    .name = TYPE_FTGMAC100_HIGH,
+    .parent = TYPE_FTGMAC100,
+    .instance_size = sizeof(FTGMAC100State),
+    .class_init = ftgmac100_high_class_init, };
+
  /*
   * AST2600 MII controller
   */
@@ -1342,6 +1455,7 @@ static const TypeInfo aspeed_mii_info = {
  static void ftgmac100_register_types(void)
  {
      type_register_static(&ftgmac100_info);
+    type_register_static(&ftgmac100_high_info);
      type_register_static(&aspeed_mii_info);
  }
 
include/hw/net/ftgmac100.h +16 -8
index 5a970676da..3e44ed97c9 100644
@@ -12,13 +12,15 @@
  #include "qom/object.h"
 
  #define TYPE_FTGMAC100 "ftgmac100"
-OBJECT_DECLARE_SIMPLE_TYPE(FTGMAC100State, FTGMAC100)
+#define TYPE_FTGMAC100_HIGH "ftgmac100_high"
+OBJECT_DECLARE_TYPE(FTGMAC100State, FTGMAC100Class, FTGMAC100)
 
-#define FTGMAC100_NR_REGS   0x200
+#define FTGMAC100_NR_REGS 0x200
+#define FTGMAC100_HIGH_OFFSET 0x100
+#define FTGMAC100_HIGH_NR_REGS 0x100
 
  #include "hw/sysbus.h"
  #include "net/net.h"
-
  /*
   * Max frame size for the receiving buffer
   */
@@ -33,6 +35,7 @@ struct FTGMAC100State {
      NICConf conf;
      qemu_irq irq;
      MemoryRegion iomem;
+    MemoryRegion iomem_high;
 
      uint8_t frame[FTGMAC100_MAX_FRAME_SIZE];
 
@@ -40,10 +43,6 @@ struct FTGMAC100State {
      uint32_t isr;
      uint32_t ier;
      uint32_t rx_enabled;
-    uint32_t rx_ring;
-    uint32_t rx_descriptor;
-    uint32_t tx_ring;
-    uint32_t tx_descriptor;
      uint32_t math[2];
      uint32_t rbsr;
      uint32_t itc;
@@ -56,7 +55,10 @@ struct FTGMAC100State {
      uint32_t phycr;
      uint32_t phydata;
      uint32_t fcr;
-
+    uint64_t rx_ring;
+    uint64_t rx_descriptor;
+    uint64_t tx_ring;
+    uint64_t tx_descriptor;
 
      uint32_t phy_status;
      uint32_t phy_control;
@@ -69,6 +71,12 @@ struct FTGMAC100State {
      uint32_t rxdes0_edorr;
  };
 
+struct FTGMAC100Class {
+    SysBusDeviceClass parent_class;
+
+    bool is_dma64;
+};
+
  #define TYPE_ASPEED_MII "aspeed-mmi"
  OBJECT_DECLARE_SIMPLE_TYPE(AspeedMiiState, ASPEED_MII)
 
#8 lore raw

Re: [PATCH v2 2/5] hw/net:ftgmac100: support 64 bits dma dram address for AST2700

Hello Jamin,

Quoted 7 lines
Quoted 7 lines

I think that, first, we should introduce a container region. In this container region would be mapped a sub region for the current set of registers. This container region would be the one that the SoC maps as it is done today.

Then, in a second patch, we should introduce a extra sub region for the set of new registers and map it at 0x100 in the container region.

Quoted 7 lines
Quoted 3 lines

It is close to what you did but it lacks an overall container region. This container region should be sized as specified in the datasheet.

Do you mean to change as following?

ftgmac100.h
#define FTGMAC100_MEM_SIZE 0x200

I would use the total size of the MMIO aperture, 0x1000, because this region is reserved for the MAC unit logic, which means it could grow. That's minor.

Quoted 1 line

#define FTGMAC100_NR_REGS 0x100

Value is fine.

However, the NR_REGS suffix is confusing. It is not a number of registers but a MMIO aperture width. I would use a _MEM_SIZE suffix instead. Could be FTGMAC100_REG_MEM_SIZE.

Quoted 2 lines

#define FTGMAC100_REGS_HIGH_OFFSET 0x100
#define FTGMAC100_NR_REGS_HIGH 0x100

Same here.

Quoted 9 lines
struct FTGMAC100State {
     MemoryRegion iomem_container;
     MemoryRegion iomem;
     MemoryRegion iomem_high;
}

Ftgmac100.c
static void ftgmac100_realize(DeviceState *dev, Error **errp)

Quoted 16 lines
{
     memory_region_init(&s->iomem_container, OBJECT(s),
                      TYPE_FTGMAC100 ".container", FTGMAC100_MEM_SIZE);  --> container size 0x200
     sysbus_init_mmio(sbd, &s->iomem_container);

     memory_region_init_io(&s->iomem, OBJECT(s), &ftgmac100_ops, s,
                           TYPE_FTGMAC100 ".regs", FTGMAC100_NR_REGS); --> current register 0x0-0xff
     memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);

     if (s-> dma64) {
         memory_region_init_io(&s->iomem_high, OBJECT(s), &ftgmac100_high_ops,
                               s, TYPE_FTGMAC100 ".regs.high", FTGMAC100_NR_REGS_HIGH); --> high register 0x100-0x1ff
         memory_region_add_subregion(&s->iomem_container, FTGMAC100_REGS_HIGH_OFFSET,
                                     &s->iomem_high);
     }
}

Looks good.

Thanks,

C.

#9 lore raw

PATCH v2 4/5 hw/block: m25p80: support quad mode for w25q01jvq

In reply to Jamin Lin via

According to the w25q01jv datasheet at page 16,
it is required to set QE bit in "Status Register 2". Besides, users are able to utilize "Write Status Register 1(0x01)" command to set QE bit in "Status Register 2" and
utilize "Read Status Register 2(0x35)" command to get the QE bit status.

To support quad mode for w25q01jvq, update collecting data needed 2 bytes for WRSR command in decode_new_cmd function and verify QE bit at the second byte of collecting data bit 2 in complete_collecting_data.

Update RDCR_EQIO command to set bit 2 of return data if quad mode enable in decode_new_cmd.

---
 hw/block/m25p80.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
hw/block/m25p80.c +16 -0
index 8dec134832..9e99107b42 100644
@@ -416,6 +416,7 @@ typedef enum {
     /*
      * Micron: 0x35 - enable QPI
      * Spansion: 0x35 - read control register
+     * Winbond: 0x35 - quad enable
      */
     RDCR_EQIO = 0x35,
     RSTQIO = 0xf5,
@@ -798,6 +799,11 @@ static void complete_collecting_data(Flash *s)
                 s->four_bytes_address_mode = extract32(s->data[1], 5, 1);
             }
             break;
+        case MAN_WINBOND:
+            if (s->len > 1) {
+                s->quad_enable = !!(s->data[1] & 0x02);
+            }
+            break;
         default:
             break;
         }
@@ -1254,6 +1260,10 @@ static void decode_new_cmd(Flash *s, uint32_t value)
             s->needed_bytes = 2;
             s->state = STATE_COLLECTING_VAR_LEN_DATA;
             break;
+        case MAN_WINBOND:
+            s->needed_bytes = 2;
+            s->state = STATE_COLLECTING_VAR_LEN_DATA;
+            break;
         default:
             s->needed_bytes = 1;
             s->state = STATE_COLLECTING_DATA;
@@ -1431,6 +1441,12 @@ static void decode_new_cmd(Flash *s, uint32_t value)
         case MAN_MACRONIX:
             s->quad_enable = true;
             break;
+        case MAN_WINBOND:
+            s->data[0] = (!!s->quad_enable) << 1;
+            s->pos = 0;
+            s->len = 1;
+            s->state = STATE_READING_DATA;
+            break;
         default:
             break;
         }
Signature · 1 line
2.34.1
Reviewed-by on v2 4/5
#10 lore raw

Re: [PATCH v2 4/5] hw/block: m25p80: support quad mode for w25q01jvq

Quoted 11 lines · Jamin Lin

According to the w25q01jv datasheet at page 16,
it is required to set QE bit in "Status Register 2". Besides, users are able to utilize "Write Status Register 1(0x01)" command to set QE bit in "Status Register 2" and
utilize "Read Status Register 2(0x35)" command to get the QE bit status.

To support quad mode for w25q01jvq, update collecting data needed 2 bytes for WRSR command in decode_new_cmd function and verify QE bit at the second byte of collecting data bit 2 in complete_collecting_data.

Quoted 5 lines

Update RDCR_EQIO command to set bit 2 of return data if quad mode enable in decode_new_cmd.

Thanks,

C.

Quoted 52 lines
---
  hw/block/m25p80.c | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
hw/block/m25p80.c +16 -0
index 8dec134832..9e99107b42 100644
@@ -416,6 +416,7 @@ typedef enum {
      /*
       * Micron: 0x35 - enable QPI
       * Spansion: 0x35 - read control register
+     * Winbond: 0x35 - quad enable
       */
      RDCR_EQIO = 0x35,
      RSTQIO = 0xf5,
@@ -798,6 +799,11 @@ static void complete_collecting_data(Flash *s)
                  s->four_bytes_address_mode = extract32(s->data[1], 5, 1);
              }
              break;
+        case MAN_WINBOND:
+            if (s->len > 1) {
+                s->quad_enable = !!(s->data[1] & 0x02);
+            }
+            break;
          default:
              break;
          }
@@ -1254,6 +1260,10 @@ static void decode_new_cmd(Flash *s, uint32_t value)
              s->needed_bytes = 2;
              s->state = STATE_COLLECTING_VAR_LEN_DATA;
              break;
+        case MAN_WINBOND:
+            s->needed_bytes = 2;
+            s->state = STATE_COLLECTING_VAR_LEN_DATA;
+            break;
          default:
              s->needed_bytes = 1;
              s->state = STATE_COLLECTING_DATA;
@@ -1431,6 +1441,12 @@ static void decode_new_cmd(Flash *s, uint32_t value)
          case MAN_MACRONIX:
              s->quad_enable = true;
              break;
+        case MAN_WINBOND:
+            s->data[0] = (!!s->quad_enable) << 1;
+            s->pos = 0;
+            s->len = 1;
+            s->state = STATE_READING_DATA;
+            break;
          default:
              break;
          }
#11 lore raw

PATCH v2 5/5 test/avocado/machine_aspeed.py: update to test network for AST2700

In reply to Jamin Lin via

Update a test case to test network connection via ssh and changes to test Aspeed OpenBMC SDK v09.02 for AST2700.

ASPEED fixed TX mask issue from linux/drivers/ftgmac100.c. It is required to use ASPEED SDK image since v09.02 for AST2700 QEMU network testing.

A test image is downloaded from the ASPEED Forked OpenBMC GitHub release repository :
https://github.com/AspeedTech-BMC/openbmc/releases/

Test command:

```
cd build
pyvenv/bin/avocado run ../qemu/tests/avocado/machine_aspeed.py:AST2x00MachineSDK.test_aarch64_ast2700_evb_sdk_v09_02
```
---
 tests/avocado/machine_aspeed.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
tests/avocado/machine_aspeed.py +7 -6
index 3a20644fb2..855da805ae 100644
@@ -313,14 +313,14 @@ def do_test_arm_aspeed_sdk_start(self, image):
 
     def do_test_aarch64_aspeed_sdk_start(self, image):
         self.vm.set_console()
-        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw')
+        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
+                         '-net', 'nic', '-net', 'user,hostfwd=:127.0.0.1:0-:22')
 
         self.vm.launch()
 
         self.wait_for_console_pattern('U-Boot 2023.10')
         self.wait_for_console_pattern('## Loading kernel from FIT Image')
         self.wait_for_console_pattern('Starting kernel ...')
-        self.wait_for_console_pattern("systemd[1]: Hostname set to")
 
     @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
 
@@ -387,15 +387,15 @@ def test_arm_ast2600_evb_sdk(self):
         year = time.strftime("%Y")
         self.ssh_command_output_contains('/sbin/hwclock -f /dev/rtc1', year);
 
-    def test_aarch64_ast2700_evb_sdk_v09_01(self):
+    def test_aarch64_ast2700_evb_sdk_v09_02(self):
         """
         :avocado: tags=arch:aarch64
         :avocado: tags=machine:ast2700-evb
         """
 
         image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
-                     'download/v09.01/ast2700-default-obmc.tar.gz')
-        image_hash = 'b1cc0fd73c7650d34c9c8459a243f52a91e9e27144b8608b2645ab19461d1e07'
+                     'download/v09.02/ast2700-default-obmc.tar.gz')
+        image_hash = 'ac969c2602f4e6bdb69562ff466b89ae3fe1d86e1f6797bb7969d787f82116a7'
         image_path = self.fetch_asset(image_url, asset_hash=image_hash,
                                       algorithm='sha256')
         archive.extract(image_path, self.workdir)
@@ -436,4 +436,5 @@ def test_aarch64_ast2700_evb_sdk_v09_01(self):
 
         self.vm.add_args('-smp', str(num_cpu))
         self.do_test_aarch64_aspeed_sdk_start(image_dir + 'image-bmc')
-
+        self.wait_for_console_pattern('nodistro.0 ast2700-default ttyS12')
+        self.ssh_connect('root', '0penBmc', False)
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH v2 5/5] test/avocado/machine_aspeed.py: update to test network for AST2700

Quoted 11 lines · Jamin Lin

Update a test case to test network connection via ssh and changes to test Aspeed OpenBMC SDK v09.02 for AST2700.

ASPEED fixed TX mask issue from linux/drivers/ftgmac100.c. It is required to use ASPEED SDK image since v09.02 for AST2700 QEMU network testing.

A test image is downloaded from the ASPEED Forked OpenBMC GitHub release repository :
https://github.com/AspeedTech-BMC/openbmc/releases/

Quoted 7 lines

Test command:

```
cd build
pyvenv/bin/avocado run ../qemu/tests/avocado/machine_aspeed.py:AST2x00MachineSDK.test_aarch64_ast2700_evb_sdk_v09_02
```

Could you please split the patch ? The change of SDK should be a standalone patch.

Thanks,

C.

Quoted 51 lines
---
  tests/avocado/machine_aspeed.py | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)
tests/avocado/machine_aspeed.py +7 -6
index 3a20644fb2..855da805ae 100644
@@ -313,14 +313,14 @@ def do_test_arm_aspeed_sdk_start(self, image):
 
      def do_test_aarch64_aspeed_sdk_start(self, image):
          self.vm.set_console()
-        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw')
+        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
+                         '-net', 'nic', '-net', 'user,hostfwd=:127.0.0.1:0-:22')
 
          self.vm.launch()
 
          self.wait_for_console_pattern('U-Boot 2023.10')
          self.wait_for_console_pattern('## Loading kernel from FIT Image')
          self.wait_for_console_pattern('Starting kernel ...')
-        self.wait_for_console_pattern("systemd[1]: Hostname set to")
 
      @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
 
@@ -387,15 +387,15 @@ def test_arm_ast2600_evb_sdk(self):
          year = time.strftime("%Y")
          self.ssh_command_output_contains('/sbin/hwclock -f /dev/rtc1', year);
 
-    def test_aarch64_ast2700_evb_sdk_v09_01(self):
+    def test_aarch64_ast2700_evb_sdk_v09_02(self):
          """
          :avocado: tags=arch:aarch64
          :avocado: tags=machine:ast2700-evb
          """
 
          image_url = ('https://github.com/AspeedTech-BMC/openbmc/releases/'
-                     'download/v09.01/ast2700-default-obmc.tar.gz')
-        image_hash = 'b1cc0fd73c7650d34c9c8459a243f52a91e9e27144b8608b2645ab19461d1e07'
+                     'download/v09.02/ast2700-default-obmc.tar.gz')
+        image_hash = 'ac969c2602f4e6bdb69562ff466b89ae3fe1d86e1f6797bb7969d787f82116a7'
          image_path = self.fetch_asset(image_url, asset_hash=image_hash,
                                        algorithm='sha256')
          archive.extract(image_path, self.workdir)
@@ -436,4 +436,5 @@ def test_aarch64_ast2700_evb_sdk_v09_01(self):
 
          self.vm.add_args('-smp', str(num_cpu))
          self.do_test_aarch64_aspeed_sdk_start(image_dir + 'image-bmc')
-
+        self.wait_for_console_pattern('nodistro.0 ast2700-default ttyS12')
+        self.ssh_connect('root', '0penBmc', False)
#13 lore raw

RE: [PATCH v2 5/5] test/avocado/machine_aspeed.py: update to test network for AST2700

Quoted 36 lines

-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Wednesday, July 3, 2024 5:18 PM
To: Jamin Lin <[email protected]>; Peter Maydell <[email protected]>; Steven Lee <[email protected]>; Troy Lee <[email protected]>; Andrew Jeffery <[email protected]>; Joel Stanley <[email protected]>; Alistair Francis <[email protected]>; Kevin Wolf <[email protected]>; Hanna Reitz <[email protected]>; Jason Wang <[email protected]>; Cleber Rosa <[email protected]>; Philippe Mathieu-Daudé <[email protected]>; Wainer dos Santos Moschetta <[email protected]>; Beraldo Leal <[email protected]>; open list:ASPEED BMCs <[email protected]>; open list:All patches CC here <[email protected]>; open list:Block layer core <[email protected]>
Cc: Troy Lee <[email protected]>; Yunlin Tang <[email protected]>
Subject: Re: [PATCH v2 5/5] test/avocado/machine_aspeed.py: update to test network for AST2700

Quoted 11 lines · Jamin Lin

Update a test case to test network connection via ssh and changes to test Aspeed OpenBMC SDK v09.02 for AST2700.

ASPEED fixed TX mask issue from linux/drivers/ftgmac100.c. It is required to use ASPEED SDK image since v09.02 for AST2700 QEMU network testing.

A test image is downloaded from the ASPEED Forked OpenBMC GitHub release repository :
https://github.com/AspeedTech-BMC/openbmc/releases/

Quoted 5 lines

Test command:
```
cd build
pyvenv/bin/avocado run ../qemu/tests/avocado/machine_aspeed.py:AST2x00MachineSDK.test_aarch

Quoted 9 lines

64

Quoted 4 lines

_ast2700_evb_sdk_v09_02
```

Could you please split the patch ? The change of SDK should be a standalone patch.

Will fix
Thanks-Jamin

Quoted 66 lines

Thanks,

C.

Quoted 11 lines
---
  tests/avocado/machine_aspeed.py | 13 +++++++------
  1 file changed, 7 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/tests/avocado/machine_aspeed.py index 3a20644fb2..855da805ae 100644

tests/avocado/machine_aspeed.py +0 -0
@@ -313,14 +313,14 @@ def do_test_arm_aspeed_sdk_start(self, image):
 
      def do_test_aarch64_aspeed_sdk_start(self, image):

tests/avocado/machine_aspeed.py def do_test_arm_aspeed_sdk_start(self, image): · line 323

Quoted 10 lines
tests/avocado/machine_aspeed.py +3 -1
          self.vm.set_console()
-        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw')
+        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
+                         '-net', 'nic', '-net',
+ 'user,hostfwd=:127.0.0.1:0-:22')
 
          self.vm.launch()
 
          self.wait_for_console_pattern('U-Boot 2023.10')
          self.wait_for_console_pattern('## Loading kernel from FIT

Image')

Quoted 9 lines
tests/avocado/machine_aspeed.py +0 -1
          self.wait_for_console_pattern('Starting kernel ...')
-        self.wait_for_console_pattern("systemd[1]: Hostname set to")
 
      @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is

unstable on GitLab')

tests/avocado/machine_aspeed.py +0 -0
@@ -387,15 +387,15 @@ def test_arm_ast2600_evb_sdk(self):
          year = time.strftime("%Y")
          self.ssh_command_output_contains('/sbin/hwclock -f

tests/avocado/machine_aspeed.py def test_arm_ast2600_evb_sdk(self): · line 397

Quoted 10 lines
tests/avocado/machine_aspeed.py +1 -1
 /dev/rtc1', year);
 
-    def test_aarch64_ast2700_evb_sdk_v09_01(self):
+    def test_aarch64_ast2700_evb_sdk_v09_02(self):
          """
          :avocado: tags=arch:aarch64
          :avocado: tags=machine:ast2700-evb
          """
 
          image_url =

('https://github.com/AspeedTech-BMC/openbmc/releases/'

tests/avocado/machine_aspeed.py def test_arm_ast2600_evb_sdk(self): · line 399

Quoted 2 lines
tests/avocado/machine_aspeed.py +0 -2
-                     'download/v09.01/ast2700-default-obmc.tar.gz')
-        image_hash =

'b1cc0fd73c7650d34c9c8459a243f52a91e9e27144b8608b2645ab19461d1e07'

tests/avocado/machine_aspeed.py def test_arm_ast2600_evb_sdk(self): · line 399

Quoted 2 lines
tests/avocado/machine_aspeed.py +2 -0
+                     'download/v09.02/ast2700-default-obmc.tar.gz')
+        image_hash =

'ac969c2602f4e6bdb69562ff466b89ae3fe1d86e1f6797bb7969d787f82116a7'

tests/avocado/machine_aspeed.py def test_arm_ast2600_evb_sdk(self): · line 400

Quoted 1 line
tests/avocado/machine_aspeed.py +0 -0
          image_path = self.fetch_asset(image_url,

asset_hash=image_hash,

Quoted 10 lines
tests/avocado/machine_aspeed.py +0 -0
                                        algorithm='sha256')
          archive.extract(image_path, self.workdir) @@ -436,4 +436,5

@@ def test_aarch64_ast2700_evb_sdk_v09_01(self):

          self.vm.add_args('-smp', str(num_cpu))
          self.do_test_aarch64_aspeed_sdk_start(image_dir +

'image-bmc')

tests/avocado/machine_aspeed.py +2 -1
-
+        self.wait_for_console_pattern('nodistro.0 ast2700-default ttyS12')
+        self.ssh_connect('root', '0penBmc', False)