Skip to contentSkip to conversation

RFC: lowrisc_eth network model

RFC New Ben Dooks 1 participant 4 messages May 21, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

As part of the CVA6 project we're working on we did an ethernet implementation as part of adding a machine to emulate the FPGA build.

As part of this, we've done an MDIO bit-bang decoder which might be useful (although we can get by with just the ethernet MAC part)

author
#1 lore raw

RFC 1/3 hw/net: add lowrisc ethernet support

This is a model for the lowrisc_ethernet block, a simple network driver found in the CVA6 CoreV APU.

---
note, squashed in "hw/net: lowrisc cleanups"

---
 hw/net/Kconfig               |   3 +
 hw/net/lowrisc.c             | 474 +++++++++++++++++++++++++++++++++++
 hw/net/meson.build           |   1 +
 hw/net/trace-events          |  10 +
 include/hw/net/lowrisc_eth.h |  54 ++++
 5 files changed, 542 insertions(+)
 create mode 100644 hw/net/lowrisc.c
 create mode 100644 include/hw/net/lowrisc_eth.h
hw/net/Kconfig +3 -0
index 7f80218d10..790fe1ce60 100644
@@ -109,6 +109,9 @@ config LASI_82596
     bool
     select I82596_COMMON
 
+config LOWRISC_ETH
+    bool
+
 config SUNHME
     bool
 
hw/net/lowrisc.c new file +474 -0

474 lines not on this page · raw message

hw/net/meson.build +1 -0
index e6759e26ca..79a65850fc 100644
@@ -21,6 +21,7 @@ system_ss.add(when: 'CONFIG_SMC91C111', if_true: files('smc91c111.c'))
 system_ss.add(when: 'CONFIG_LAN9118', if_true: files('lan9118.c'))
 system_ss.add(when: 'CONFIG_LAN9118_PHY', if_true: files('lan9118_phy.c'))
 system_ss.add(when: 'CONFIG_NE2000_ISA', if_true: files('ne2000-isa.c'))
+system_ss.add(when: 'CONFIG_LOWRISC_ETH', if_true: files('lowrisc.c'))
 system_ss.add(when: 'CONFIG_OPENCORES_ETH', if_true: files('opencores_eth.c'))
 system_ss.add(when: 'CONFIG_XGMAC', if_true: files('xgmac.c'))
 system_ss.add(when: 'CONFIG_MIPSNET', if_true: files('mipsnet.c'))
hw/net/trace-events +10 -0
index 72b69c4a8b..acf1851eb4 100644
@@ -20,6 +20,16 @@ lan9118_phy_reset(void) ""
 lance_mem_readw(uint64_t addr, uint32_t ret) "addr=0x%"PRIx64"val=0x%04x"
 lance_mem_writew(uint64_t addr, uint32_t val) "addr=0x%"PRIx64"val=0x%04x"
 
+# lowrisc.c
+lowrisc_eth_io_read(uint64_t addr, uint64_t val) "addr=0x%04"PRIx64" val=0x%016"PRIx64
+lowrisc_eth_io_write(uint64_t addr, uint64_t val) "addr=0x%04"PRIx64" val=0x%016"PRIx64
+lowrisc_eth_tx(unsigned length) "transmitting packet (%u bytes)"
+lowrisc_eth_irq(bool set, unsigned first, unsigned next, unsigned irqen) "set=%d first=%u next=%u irqen=%u"
+lowrisc_eth_rx(unsigned length, unsigned first, unsigned next, unsigned last) "rx length %u (%u,%u,%u)"
+lowrisc_eth_rx_good(unsigned length, unsigned index) "received %u bytes to index %u"
+lowrisc_eth_rx_check(unsigned first, unsigned next, unsigned last, bool ok) "%u,%u,%u -> %u"
+lowrisc_eth_rx_upd_rsr(uint64_t val) "RSR 0x%"PRIx64
+
 # mipsnet.c
 mipsnet_send(uint32_t size) "sending len=%u"
 mipsnet_receive(uint32_t size) "receiving len=%u"
include/hw/net/lowrisc_eth.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.37.2.352.g3c44437643
author
#2 lore raw

RFC 2/3 hw/net: add bit-bang mdio decoding helper (mdio_bb)

In reply to Ben Dooks

The mdio_bb allows PHY interfaces that are basically IO lines that are twiddle by registers (although GPIO isn't supported at this time, it would not be difficult to add)

The code processes the clock changes and issues a callback to the driver when there is data to be transfered. It supports both read and write, any other OP code is deemed invalid and will abort the transfer.

todo:
- add proper vmstate helper for users
- get implementation fully tested with lowrisc_eth

---
notes:
- squashed in tracing and fixups

---
 hw/net/Kconfig           |   3 +
 hw/net/mdio_bb.c         | 167 +++++++++++++++++++++++++++++++++++++++
 hw/net/meson.build       |   1 +
 hw/net/trace-events      |   8 ++
 include/hw/net/mdio_bb.h |  50 ++++++++++++
 5 files changed, 229 insertions(+)
 create mode 100644 hw/net/mdio_bb.c
 create mode 100644 include/hw/net/mdio_bb.h
hw/net/Kconfig +3 -0
index 790fe1ce60..3abee9130e 100644
@@ -109,6 +109,9 @@ config LASI_82596
     bool
     select I82596_COMMON
 
+config MDIO_BB
+    bool
+
 config LOWRISC_ETH
     bool
 
hw/net/mdio_bb.c new file +167 -0

167 lines not on this page · raw message

hw/net/meson.build +1 -0
index 79a65850fc..fe34ee5c15 100644
@@ -1,6 +1,7 @@
 system_ss.add(when: 'CONFIG_DP8393X', if_true: files('dp8393x.c'))
 system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen_nic.c'))
 system_ss.add(when: 'CONFIG_NE2000_COMMON', if_true: files('ne2000.c'))
+system_ss.add(when: 'CONFIG_MDIO_BB', if_true: files('mdio_bb.c'))
 
 # PCI network cards
 system_ss.add(when: 'CONFIG_NE2000_PCI', if_true: files('ne2000-pci.c'))
hw/net/trace-events +8 -0
index acf1851eb4..e35324c4fd 100644
@@ -312,6 +312,14 @@ igb_wrn_rx_desc_modes_not_supp(int desc_type) "Not supported descriptor type: %d
 # igbvf.c
 igbvf_wrn_io_addr_unknown(uint64_t addr) "IO unknown register 0x%"PRIx64
 
+# mdio_bb.c
+mdio_bb_update(const char *name, unsigned state, bool mdc, bool mdo) "(%s) state %u, mdc=%u mdo=%u"
+mdio_bb_start(const char *name) "(%s) starting transaction"
+mdio_bb_read(const char *name, unsigned phy, unsigned reg, unsigned data) "(%s) phy %d reg %u -> read %04x"
+mdio_bb_write(const char *name, unsigned phy, unsigned reg, unsigned data) "(%s) phy %d reg %u -> write  %04x"
+mdio_bb_new_state(const char *name, unsigned prev, unsigned state) "(%s) state %u to new state %u"
+mdio_bb_illegal_state(const char *name, unsigned last, unsigned mdo) "(%s) illegal state from %u (mdo %u)"
+
 # spapr_llan.c
 spapr_vlan_get_rx_bd_from_pool_found(int pool, int32_t count, uint32_t rx_bufs) "pool=%d count=%"PRId32" rxbufs=%"PRIu32
 spapr_vlan_get_rx_bd_from_page(int buf_ptr, uint64_t bd) "use_buf_ptr=%d bd=0x%016"PRIx64
include/hw/net/mdio_bb.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.37.2.352.g3c44437643
author
#3 lore raw

RFC 3/3 hw/net: lowrisc: initial mdio_bb work

In reply to Ben Dooks

Add initial implementation of PHY via bit-banged code.

This is to test the mdio_bb code and will need updating for real board values.

---
 hw/net/Kconfig               |  1 +
 hw/net/lowrisc.c             | 42 +++++++++++++++++++++++++++++++-----
 include/hw/net/lowrisc_eth.h |  4 ++++
 3 files changed, 42 insertions(+), 5 deletions(-)
hw/net/Kconfig +1 -0
index 3abee9130e..0bc11e567a 100644
@@ -114,6 +114,7 @@ config MDIO_BB
 
 config LOWRISC_ETH
     bool
+    select MDIO_BB
 
 config SUNHME
     bool
hw/net/lowrisc.c +37 -5

61 lines not on this page · raw message

include/hw/net/lowrisc_eth.h +4 -0
index 1f27d92ca8..5c15549cc1 100644
@@ -17,6 +17,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(LowriscEthState, LOWRISC_ETH)
 
 #include "net/net.h"
 #include "hw/sysbus.h"
+#include "hw/net/mdio_bb.h"
 
 #define RX_SZ           (2048)
 #define NR_RX_BUFFS     (8)
@@ -37,6 +38,9 @@ struct LowriscEthState {
     NICConf conf;
     qemu_irq irq;
 
+    /* the mdio bus */
+    struct mdio_bb mdio_bb;
+
     /* register states */
     uint32_t r_maclo;
     uint32_t r_machi;
Signature · 1 line
2.37.2.352.g3c44437643