hw/net/xilinx_ethlite: Map RAM buffers as RAM and remove tswap() calls
v2 cover hw/net/xilinx_ethlite: Map RAM buffers as RAM and remove tswap() calls
Missing review: patch #19 (new)
Since v1:
- Addressed Edgar review comments
- New patch to map RSVD I/O region (Paolo)
- Added Edgar R-b tags
This is the result of a long discussion with Edgar (started few years ago!) and Paolo:
https://lore.kernel.org/qemu-devel/[email protected]/
After clarification from Richard on MMIO/RAM accesses, I figured strengthening the model regions would make things obvious, eventually allowing to remove the tswap() calls for good.
This costly series mostly plays around with MemoryRegions.
The model has a mix of RAM/MMIO in its address range. Currently they are implemented as a MMIO array of u32. Since the core memory layer swaps accesses for MMIO, the device implementation has to swap them back.
In order to avoid that, we'll map the RAM regions as RAM MRs. First we move each MMIO register to new MMIO regions (RX and TX). Then what is left are the RAM buffers; we convert them to RAM MRs, removing the need for tswap() at all.
Once reviewed, I'll respin my "hw/microblaze: Allow running cross-endian vCPUs" series based on this.
Tested using 'make check-functional-microblaze{,el}'.
Please review,
Phil.
Philippe Mathieu-Daudé (19):
hw/microblaze: Restrict MemoryRegionOps are implemented as 32-bit hw/net/xilinx_ethlite: Convert some debug logs to trace events hw/net/xilinx_ethlite: Remove unuseful debug logs hw/net/xilinx_ethlite: Update QOM style hw/net/xilinx_ethlite: Correct maximum RX buffer size hw/net/xilinx_ethlite: Map MDIO registers (as unimplemented) hw/net/xilinx_ethlite: Rename rxbuf -> port_index hw/net/xilinx_ethlite: Introduce txbuf_ptr() helper hw/net/xilinx_ethlite: Introduce rxbuf_ptr() helper hw/net/xilinx_ethlite: Access TX_GIE register for each port hw/net/xilinx_ethlite: Access TX_LEN register for each port hw/net/xilinx_ethlite: Access TX_CTRL register for each port hw/net/xilinx_ethlite: Map RX_CTRL as MMIO hw/net/xilinx_ethlite: Map TX_LEN as MMIO hw/net/xilinx_ethlite: Map TX_GIE as MMIO hw/net/xilinx_ethlite: Map TX_CTRL as MMIO hw/net/xilinx_ethlite: Map the RAM buffer as RAM memory region hw/net/xilinx_ethlite: Rename 'mmio' MR as 'container' hw/net/xilinx_ethlite: Map RESERVED I/O as unimplemented
hw/char/xilinx_uartlite.c | 4 + hw/intc/xilinx_intc.c | 4 + hw/net/xilinx_ethlite.c | 371 ++++++++++++++++++++++++-------------- hw/timer/xilinx_timer.c | 4 + hw/net/trace-events | 4 + 5 files changed, 256 insertions(+), 131 deletions(-)
Signature · 1 line
2.45.2
PATCH RESEND v2 1/19 hw/microblaze: Restrict MemoryRegionOps are implemented as 32-bit
All these MemoryRegionOps read() and write() handlers are implemented expecting 32-bit accesses. Clarify that setting .impl.min/max_access_size fields.
--- hw/char/xilinx_uartlite.c | 4 ++++ hw/intc/xilinx_intc.c | 4 ++++ hw/net/xilinx_ethlite.c | 4 ++++ hw/timer/xilinx_timer.c | 4 ++++ 4 files changed, 16 insertions(+)
hw/char/xilinx_uartlite.c +4 -0
@@ -170,6 +170,10 @@ static const MemoryRegionOps uart_ops = { .read = uart_read, .write = uart_write, .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, .valid = { .min_access_size =1 , .max_access_size = 4
hw/intc/xilinx_intc.c +4 -0
@@ -144,6 +144,10 @@ static const MemoryRegionOps pic_ops = { .read = pic_read, .write = pic_write, .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, .valid = { .min_access_size =4 , .max_access_size = 4
hw/net/xilinx_ethlite.c +4 -0
@@ -170,6 +170,10 @@ static const MemoryRegionOps eth_ops = { .read = eth_read, .write = eth_write, .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, .valid = { .min_access_size =4 , .max_access_size = 4
hw/timer/xilinx_timer.c +4 -0
@@ -193,6 +193,10 @@ static const MemoryRegionOps timer_ops = { .read = timer_read, .write = timer_write, .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + .min_access_size = 4, + .max_access_size = 4, + }, .valid = { .min_access_size =4 , .max_access_size = 4
Signature · 1 line
2.45.2
PATCH RESEND v2 2/19 hw/net/xilinx_ethlite: Convert some debug logs to trace events
In reply to Philippe Mathieu-Daudé--- hw/net/xilinx_ethlite.c | 5 +++-- hw/net/trace-events | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-)
hw/net/xilinx_ethlite.c +3 -2
@@ -30,6 +30,7 @@#include "hw/irq.h" #include "hw/qdev-properties.h" #include "net/net.h" +#include "trace.h" #define D (x)#define R_TX_BUF0 0
@@ -198,13 +199,13 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)return size;if (s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ) { -D (qemu_log ("ethlite lost packet %x\n" , s->regs[R_RX_CTRL0 ])); +trace_ethlite_pkt_lost (s->regs[R_RX_CTRL0 ]);return -1 ; }D (qemu_log ("%s %zd rxbase=%x\n" , __func__, size, rxbase));if (size > (R_MAX -R_RX_BUF0 - rxbase) *4 ) { -D (qemu_log ("ethlite packet is too big, size=%x\n" , size)); +trace_ethlite_pkt_size_too_big (size);return -1 ; }memcpy (&s->regs[rxbase +R_RX_BUF0 ], buf, size);
hw/net/trace-events +4 -0
@@ -511,3 +511,7 @@ xen_netdev_connect(int dev, unsigned int tx, unsigned int rx, int port) "vif%u t xen_netdev_frontend_changed(const char *dev, int state) "vif%s state %d" xen_netdev_tx(int dev, int ref, int off, int len, unsigned int flags, const char *c, const char *d, const char *m, const char *e) "vif%u ref %u off %u len %u flags 0x%x%s%s%s%s" xen_netdev_rx(int dev, int idx, int status, int flags) "vif%u idx %d status %d flags 0x%x" + +# xilinx_ethlite.c +ethlite_pkt_lost(uint32_t rx_ctrl) "rx_ctrl:0x%" PRIx32 +ethlite_pkt_size_too_big(uint64_t size) "size:0x%" PRIx64
Signature · 1 line
2.45.2
PATCH RESEND v2 3/19 hw/net/xilinx_ethlite: Remove unuseful debug logs
In reply to Philippe Mathieu-Daudé--- hw/net/xilinx_ethlite.c | 8 -------- 1 file changed, 8 deletions(-)
hw/net/xilinx_ethlite.c +0 -8
@@ -32,7 +32,6 @@#include "net/net.h" #include "trace.h" -#define D (x)#define R_TX_BUF0 0#define R_TX_LEN0 (0x07f4 / 4)#define R_TX_GIE0 (0x07f8 / 4)
@@ -100,7 +99,6 @@ eth_read(void *opaque, hwaddr addr, unsigned int size)case R_RX_CTRL1 :case R_RX_CTRL0 : r = s->regs[addr]; -D (qemu_log ("%s " HWADDR_FMT_plx"=%x\n" , __func__, addr *4 , r));break ;default :
@@ -126,13 +124,10 @@ eth_write(void *opaque, hwaddr addr,if (addr ==R_TX_CTRL1 ) base =0x800 /4 ; -D (qemu_log ("%s addr=" HWADDR_FMT_plx" val=%x\n" , - __func__, addr *4 , value));if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) {qemu_send_packet (qemu_get_queue (s->nic), (void *) &s->regs[base], s->regs[base +R_TX_LEN0 ]); -D (qemu_log ("eth_tx %d\n" , s->regs[base +R_TX_LEN0 ]));if (s->regs[base +R_TX_CTRL0 ] &CTRL_I )eth_pulse_irq (s); }else if ((value & (CTRL_P |CTRL_S )) == (CTRL_P |CTRL_S )) {
@@ -156,8 +151,6 @@ eth_write(void *opaque, hwaddr addr,case R_TX_LEN0 :case R_TX_LEN1 :case R_TX_GIE0 : -D (qemu_log ("%s addr=" HWADDR_FMT_plx" val=%x\n" , - __func__, addr *4 , value)); s->regs[addr] = value;break ;
@@ -203,7 +196,6 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)return -1 ; } -D (qemu_log ("%s %zd rxbase=%x\n" , __func__, size, rxbase));if (size > (R_MAX -R_RX_BUF0 - rxbase) *4 ) {trace_ethlite_pkt_size_too_big (size);return -1 ;
Signature · 1 line
2.45.2
PATCH RESEND v2 4/19 hw/net/xilinx_ethlite: Update QOM style
In reply to Philippe Mathieu-DaudéUse XlnxXpsEthLite typedef, OBJECT_DECLARE_SIMPLE_TYPE macro; convert type_init() to DEFINE_TYPES().
--- hw/net/xilinx_ethlite.c | 48 +++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 26 deletions(-)
hw/net/xilinx_ethlite.c +22 -26
@@ -53,10 +53,9 @@#define CTRL_S 0x1#define TYPE_XILINX_ETHLITE "xlnx.xps-ethernetlite" -DECLARE_INSTANCE_CHECKER(struct xlx_ethlite, XILINX_ETHLITE, - TYPE_XILINX_ETHLITE) +OBJECT_DECLARE_SIMPLE_TYPE(XlnxXpsEthLite, XILINX_ETHLITE) -struct xlx_ethlite +struct XlnxXpsEthLite {SysBusDevice parent_obj;
@@ -73,7 +72,7 @@ struct xlx_ethliteuint32_t regs[R_MAX ]; }; -static inline void eth_pulse_irq (struct xlx_ethlite *s) +static inline void eth_pulse_irq (XlnxXpsEthLite *s) {/* Only the first gie reg is active. */ if (s->regs[R_TX_GIE0 ] &GIE_GIE ) {
@@ -84,7 +83,7 @@ static inline void eth_pulse_irq(struct xlx_ethlite *s)static uint64_t eth_read (void *opaque,hwaddr addr,unsigned int size) { -struct xlx_ethlite *s = opaque; +XlnxXpsEthLite *s = opaque;uint32_t r =0 ; addr >>=2 ;
@@ -112,7 +111,7 @@ static void eth_write(void *opaque, hwaddr addr, uint64_t val64, unsigned int size) { -struct xlx_ethlite *s = opaque; +XlnxXpsEthLite *s = opaque;unsigned int base =0 ;uint32_t value = val64;
@@ -176,7 +175,7 @@ static const MemoryRegionOps eth_ops = {static bool eth_can_rx (NetClientState *nc) { -struct xlx_ethlite *s =qemu_get_nic_opaque (nc); +XlnxXpsEthLite *s =qemu_get_nic_opaque (nc);unsigned int rxbase = s->rxbuf * (0x800 /4 );return !(s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S );
@@ -184,7 +183,7 @@ static bool eth_can_rx(NetClientState *nc)static ssize_t eth_rx (NetClientState *nc,const uint8_t *buf,size_t size) { -struct xlx_ethlite *s =qemu_get_nic_opaque (nc); +XlnxXpsEthLite *s =qemu_get_nic_opaque (nc);unsigned int rxbase = s->rxbuf * (0x800 /4 );/* DA filter. */
@@ -214,7 +213,7 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)static void xilinx_ethlite_reset (DeviceState *dev) { -struct xlx_ethlite *s =XILINX_ETHLITE (dev); +XlnxXpsEthLite *s =XILINX_ETHLITE (dev); s->rxbuf =0 ; }
@@ -228,7 +227,7 @@ static NetClientInfo net_xilinx_ethlite_info = {static void xilinx_ethlite_realize (DeviceState *dev,Error **errp) { -struct xlx_ethlite *s =XILINX_ETHLITE (dev); +XlnxXpsEthLite *s =XILINX_ETHLITE (dev);qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf,
@@ -239,7 +238,7 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp)static void xilinx_ethlite_init (Object *obj) { -struct xlx_ethlite *s =XILINX_ETHLITE (obj); +XlnxXpsEthLite *s =XILINX_ETHLITE (obj);sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq);
@@ -249,9 +248,9 @@ static void xilinx_ethlite_init(Object *obj) }static Property xilinx_ethlite_properties[] = { - DEFINE_PROP_UINT32("tx-ping-pong", struct xlx_ethlite, c_tx_pingpong, 1), - DEFINE_PROP_UINT32("rx-ping-pong", struct xlx_ethlite, c_rx_pingpong, 1), - DEFINE_NIC_PROPERTIES(struct xlx_ethlite, conf), +DEFINE_PROP_UINT32 ("tx-ping-pong" , XlnxXpsEthLite, c_tx_pingpong,1 ), +DEFINE_PROP_UINT32 ("rx-ping-pong" , XlnxXpsEthLite, c_rx_pingpong,1 ), +DEFINE_NIC_PROPERTIES (XlnxXpsEthLite, conf),DEFINE_PROP_END_OF_LIST (), };
@@ -264,17 +263,14 @@ static void xilinx_ethlite_class_init(ObjectClass *klass, void *data)device_class_set_props (dc, xilinx_ethlite_properties); } -static const TypeInfo xilinx_ethlite_info = { - .name =TYPE_XILINX_ETHLITE , - .parent =TYPE_SYS_BUS_DEVICE , - .instance_size =sizeof (struct xlx_ethlite ), - .instance_init = xilinx_ethlite_init, - .class_init = xilinx_ethlite_class_init, +static const TypeInfo xilinx_ethlite_types[] = { + { + .name =TYPE_XILINX_ETHLITE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (XlnxXpsEthLite), + .instance_init = xilinx_ethlite_init, + .class_init = xilinx_ethlite_class_init, + }, }; -static void xilinx_ethlite_register_types (void ) -{ -type_register_static (&xilinx_ethlite_info); -} - -type_init (xilinx_ethlite_register_types) +DEFINE_TYPES (xilinx_ethlite_types)
Signature · 1 line
2.45.2
PATCH RESEND v2 5/19 hw/net/xilinx_ethlite: Correct maximum RX buffer size
In reply to Philippe Mathieu-DaudéThe current max RX bufsize is set to 0x800. This is invalid, since it contains the MMIO registers region. Add the correct definition (valid for both TX & RX, see datasheet p. 20, Table 11 "XPS Ethernet Lite MAC Memory Map") and use it.
--- hw/net/xilinx_ethlite.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/net/xilinx_ethlite.c +5 -1
@@ -3,6 +3,9 @@* * Copyright (c) 2009 Edgar E. Iglesias. * +* DS580: https://docs.amd.com/v/u/en-US/xps_ethernetlite +* LogiCORE IP XPS Ethernet Lite Media Access Controller +* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights
@@ -33,6 +36,7 @@#include "trace.h" #define R_TX_BUF0 0 +#define BUFSZ_MAX 0x07e4#define R_TX_LEN0 (0x07f4 / 4)#define R_TX_GIE0 (0x07f8 / 4)#define R_TX_CTRL0 (0x07fc / 4)
@@ -195,7 +199,7 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)return -1 ; } -if (size > (R_MAX -R_RX_BUF0 - rxbase) *4 ) { +if (size >=BUFSZ_MAX ) {trace_ethlite_pkt_size_too_big (size);return -1 ; }
Signature · 1 line
2.45.2
PATCH RESEND v2 6/19 hw/net/xilinx_ethlite: Map MDIO registers (as unimplemented)
In reply to Philippe Mathieu-DaudéRather than handling the MDIO registers as RAM, map them as unimplemented I/O within the device MR.
The memory flat view becomes:
(qemu) info mtree -f
FlatView #0
Root memory region: system
0000000081000000-00000000810007e3 (prio 0, i/o): xlnx.xps-ethernetlite
00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio
00000000810007f4-0000000081001fff (prio 0, i/o): xlnx.xps-ethernetlite @00000000000007f4--- hw/net/xilinx_ethlite.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
hw/net/xilinx_ethlite.c +12 -0
@@ -28,15 +28,18 @@#include "qemu/osdep.h" #include "qemu/module.h" #include "qom/object.h" +#include "qapi/error.h" #include "exec/tswap.h" #include "hw/sysbus.h" #include "hw/irq.h" #include "hw/qdev-properties.h" +#include "hw/misc/unimp.h" #include "net/net.h" #include "trace.h" #define R_TX_BUF0 0#define BUFSZ_MAX 0x07e4 +#define A_MDIO_BASE 0x07e4#define R_TX_LEN0 (0x07f4 / 4)#define R_TX_GIE0 (0x07f8 / 4)#define R_TX_CTRL0 (0x07fc / 4)
@@ -73,6 +76,7 @@ struct XlnxXpsEthLiteunsigned int txbuf;unsigned int rxbuf; +UnimplementedDeviceState mdio;uint32_t regs[R_MAX ]; };
@@ -233,6 +237,14 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp) {XlnxXpsEthLite *s =XILINX_ETHLITE (dev); +object_initialize_child (OBJECT (dev),"ethlite.mdio" , &s->mdio, +TYPE_UNIMPLEMENTED_DEVICE ); +qdev_prop_set_string (DEVICE (&s->mdio),"name" ,"ethlite.mdio" ); +qdev_prop_set_uint64 (DEVICE (&s->mdio),"size" ,4 *4 ); +sysbus_realize (SYS_BUS_DEVICE (&s->mdio), &error_fatal); +memory_region_add_subregion (&s->mmio,A_MDIO_BASE , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->mdio),0 )); +qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id,
Signature · 1 line
2.45.2
PATCH RESEND v2 7/19 hw/net/xilinx_ethlite: Rename rxbuf -> port_index
In reply to Philippe Mathieu-Daudé'rxbuf' is the index of the dual port RAM used.
Rename it as 'port_index'.
--- hw/net/xilinx_ethlite.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/net/xilinx_ethlite.c +5 -6
@@ -73,8 +73,7 @@ struct XlnxXpsEthLiteuint32_t c_tx_pingpong;uint32_t c_rx_pingpong; -unsigned int txbuf; -unsigned int rxbuf; +unsigned int port_index;/* dual port RAM index */ UnimplementedDeviceState mdio;uint32_t regs[R_MAX ];
@@ -184,7 +183,7 @@ static const MemoryRegionOps eth_ops = {static bool eth_can_rx (NetClientState *nc) {XlnxXpsEthLite *s =qemu_get_nic_opaque (nc); -unsigned int rxbase = s->rxbuf * (0x800 /4 ); +unsigned int rxbase = s->port_index * (0x800 /4 );return !(s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ); }
@@ -192,7 +191,7 @@ static bool eth_can_rx(NetClientState *nc)static ssize_t eth_rx (NetClientState *nc,const uint8_t *buf,size_t size) {XlnxXpsEthLite *s =qemu_get_nic_opaque (nc); -unsigned int rxbase = s->rxbuf * (0x800 /4 ); +unsigned int rxbase = s->port_index * (0x800 /4 );/* DA filter. */ if (!(buf[0 ] &0x80 ) &&memcmp (&s->conf.macaddr.a[0 ], buf,6 ))
@@ -215,7 +214,7 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size) }/* If c_rx_pingpong was set flip buffers. */ - s->rxbuf ^= s->c_rx_pingpong; + s->port_index ^= s->c_rx_pingpong;return size; }
@@ -223,7 +222,7 @@ static void xilinx_ethlite_reset(DeviceState *dev) {XlnxXpsEthLite *s =XILINX_ETHLITE (dev); - s->rxbuf =0 ; + s->port_index =0 ; }static NetClientInfo net_xilinx_ethlite_info = {
Signature · 1 line
2.45.2
PATCH RESEND v2 8/19 hw/net/xilinx_ethlite: Introduce txbuf_ptr() helper
In reply to Philippe Mathieu-DaudéFor a particular physical address within the EthLite MMIO range, addr_to_port_index() returns which port is accessed.
txbuf_ptr() points to the beginning of a (RAM) TX buffer within the device state.
--- hw/net/xilinx_ethlite.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
hw/net/xilinx_ethlite.c +16 -2
@@ -27,6 +27,7 @@#include "qemu/osdep.h" #include "qemu/module.h" +#include "qemu/bitops.h" #include "qom/object.h" #include "qapi/error.h" #include "exec/tswap.h"
@@ -87,6 +88,18 @@ static inline void eth_pulse_irq(XlnxXpsEthLite *s) } } +static unsigned addr_to_port_index (hwaddr addr) +{ +return extract64 (addr,11 ,1 ); +} + +static void *txbuf_ptr (XlnxXpsEthLite *s,unsigned port_index) +{ +unsigned int rxbase = port_index * (0x800 /4 ); + +return &s->regs[rxbase +R_TX_BUF0 ]; +} +static uint64_t eth_read (void *opaque,hwaddr addr,unsigned int size) {
@@ -119,6 +132,7 @@ eth_write(void *opaque, hwaddr addr, uint64_t val64, unsigned int size) {XlnxXpsEthLite *s = opaque; +unsigned int port_index =addr_to_port_index (addr);unsigned int base =0 ;uint32_t value = val64;
@@ -132,12 +146,12 @@ eth_write(void *opaque, hwaddr addr,if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) {qemu_send_packet (qemu_get_queue (s->nic), - (void *) &s->regs[base], +txbuf_ptr (s, port_index), s->regs[base +R_TX_LEN0 ]);if (s->regs[base +R_TX_CTRL0 ] &CTRL_I )eth_pulse_irq (s); }else if ((value & (CTRL_P |CTRL_S )) == (CTRL_P |CTRL_S )) { -memcpy (&s->conf.macaddr.a[0 ], &s->regs[base],6 ); +memcpy (&s->conf.macaddr.a[0 ],txbuf_ptr (s, port_index),6 );if (s->regs[base +R_TX_CTRL0 ] &CTRL_I )eth_pulse_irq (s); }
Signature · 1 line
2.45.2
PATCH RESEND v2 9/19 hw/net/xilinx_ethlite: Introduce rxbuf_ptr() helper
In reply to Philippe Mathieu-Daudérxbuf_ptr() points to the beginning of a (RAM) RX buffer within the device state.
--- hw/net/xilinx_ethlite.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-)
hw/net/xilinx_ethlite.c +30 -10
@@ -60,6 +60,13 @@#define CTRL_P 0x2#define CTRL_S 0x1 +typedef struct XlnxXpsEthLitePort +{ +struct { +uint32_t rx_ctrl; + } reg; +}XlnxXpsEthLitePort ; +#define TYPE_XILINX_ETHLITE "xlnx.xps-ethernetlite"OBJECT_DECLARE_SIMPLE_TYPE (XlnxXpsEthLite,XILINX_ETHLITE )
@@ -77,6 +84,7 @@ struct XlnxXpsEthLiteunsigned int port_index;/* dual port RAM index */ UnimplementedDeviceState mdio; +XlnxXpsEthLitePort port[2 ];uint32_t regs[R_MAX ]; };
@@ -100,10 +108,18 @@ static void *txbuf_ptr(XlnxXpsEthLite *s, unsigned port_index)return &s->regs[rxbase +R_TX_BUF0 ]; } +static void *rxbuf_ptr (XlnxXpsEthLite *s,unsigned port_index) +{ +unsigned int rxbase = port_index * (0x800 /4 ); + +return &s->regs[rxbase +R_RX_BUF0 ]; +} +static uint64_t eth_read (void *opaque,hwaddr addr,unsigned int size) {XlnxXpsEthLite *s = opaque; +unsigned port_index =addr_to_port_index (addr);uint32_t r =0 ; addr >>=2 ;
@@ -115,9 +131,12 @@ eth_read(void *opaque, hwaddr addr, unsigned int size)case R_TX_LEN1 :case R_TX_CTRL1 :case R_TX_CTRL0 : + r = s->regs[addr]; +break ; +case R_RX_CTRL1 :case R_RX_CTRL0 : - r = s->regs[addr]; + r = s->port[port_index].reg.rx_ctrl;break ;default :
@@ -167,7 +186,9 @@ eth_write(void *opaque, hwaddr addr,if (!(value &CTRL_S )) {qemu_flush_queued_packets (qemu_get_queue (s->nic)); } -/* fall through */ + s->port[port_index].reg.rx_ctrl = value; +break ; +case R_TX_LEN0 :case R_TX_LEN1 :case R_TX_GIE0 :
@@ -197,22 +218,21 @@ static const MemoryRegionOps eth_ops = {static bool eth_can_rx (NetClientState *nc) {XlnxXpsEthLite *s =qemu_get_nic_opaque (nc); -unsigned int rxbase = s->port_index * (0x800 /4 ); -return !(s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ); +return !(s->port[s->port_index].reg.rx_ctrl &CTRL_S ); }static ssize_t eth_rx (NetClientState *nc,const uint8_t *buf,size_t size) {XlnxXpsEthLite *s =qemu_get_nic_opaque (nc); -unsigned int rxbase = s->port_index * (0x800 /4 ); +unsigned int port_index = s->port_index;/* DA filter. */ if (!(buf[0 ] &0x80 ) &&memcmp (&s->conf.macaddr.a[0 ], buf,6 ))return size; -if (s->regs[rxbase +R_RX_CTRL0 ] &CTRL_S ) { -trace_ethlite_pkt_lost (s->regs[R_RX_CTRL0 ]); +if (s->port[port_index].reg.rx_ctrl &CTRL_S ) { +trace_ethlite_pkt_lost (s->port[port_index].reg.rx_ctrl);return -1 ; }
@@ -220,10 +240,10 @@ static ssize_t eth_rx(NetClientState *nc, const uint8_t *buf, size_t size)trace_ethlite_pkt_size_too_big (size);return -1 ; } -memcpy (&s->regs[rxbase +R_RX_BUF0 ], buf, size); +memcpy (rxbuf_ptr (s, port_index), buf, size); - s->regs[rxbase +R_RX_CTRL0 ] |=CTRL_S ; -if (s->regs[R_RX_CTRL0 ] &CTRL_I ) { + s->port[port_index].reg.rx_ctrl |=CTRL_S ; +if (s->port[port_index].reg.rx_ctrl &CTRL_I ) {eth_pulse_irq (s); }
Signature · 1 line
2.45.2
PATCH RESEND v2 10/19 hw/net/xilinx_ethlite: Access TX_GIE register for each port
In reply to Philippe Mathieu-DaudéRather than accessing the registers within the mixed RAM/MMIO region as indexed register, declare a per-port TX_GIE. This will help to map the RAM as RAM (keeping MMIO as MMIO) in few commits.
Previous s->regs[R_TX_GIE0] and s->regs[R_TX_GIE1] are now unused. Not a concern, this array will soon disappear.
--- hw/net/xilinx_ethlite.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
hw/net/xilinx_ethlite.c +10 -2
@@ -63,6 +63,8 @@typedef struct XlnxXpsEthLitePort {struct { +uint32_t tx_gie; +uint32_t rx_ctrl; } reg; }XlnxXpsEthLitePort ;
@@ -91,7 +93,7 @@ struct XlnxXpsEthLitestatic inline void eth_pulse_irq (XlnxXpsEthLite *s) {/* Only the first gie reg is active. */ -if (s->regs[R_TX_GIE0 ] &GIE_GIE ) { +if (s->port[0 ].reg.tx_gie &GIE_GIE ) {qemu_irq_pulse (s->irq); } }
@@ -127,6 +129,9 @@ eth_read(void *opaque, hwaddr addr, unsigned int size)switch (addr) {case R_TX_GIE0 : + r = s->port[port_index].reg.tx_gie; +break ; +case R_TX_LEN0 :case R_TX_LEN1 :case R_TX_CTRL1 :
@@ -191,10 +196,13 @@ eth_write(void *opaque, hwaddr addr,case R_TX_LEN0 :case R_TX_LEN1 : -case R_TX_GIE0 : s->regs[addr] = value;break ; +case R_TX_GIE0 : + s->port[port_index].reg.tx_gie = value; +break ; +default : s->regs[addr] =tswap32 (value);break ;
Signature · 1 line
2.45.2
PATCH RESEND v2 11/19 hw/net/xilinx_ethlite: Access TX_LEN register for each port
In reply to Philippe Mathieu-DaudéRather than accessing the registers within the mixed RAM/MMIO region as indexed register, declare a per-port TX_LEN. This will help to map the RAM as RAM (keeping MMIO as MMIO) in few commits.
Previous s->regs[R_TX_LEN0] and s->regs[R_TX_LEN1] are now unused. Not a concern, this array will soon disappear.
--- hw/net/xilinx_ethlite.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/net/xilinx_ethlite.c +6 -2
@@ -63,6 +63,7 @@ typedef struct XlnxXpsEthLitePort { struct { + uint32_t tx_len; uint32_t tx_gie; uint32_t rx_ctrl;
@@ -134,6 +135,9 @@ eth_read(void *opaque, hwaddr addr, unsigned int size)case R_TX_LEN0 :case R_TX_LEN1 : + r = s->port[port_index].reg.tx_len; +break ; +case R_TX_CTRL1 :case R_TX_CTRL0 : r = s->regs[addr];
@@ -171,7 +175,7 @@ eth_write(void *opaque, hwaddr addr,if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) {qemu_send_packet (qemu_get_queue (s->nic),txbuf_ptr (s, port_index), - s->regs[base +R_TX_LEN0 ]); + s->port[port_index].reg.tx_len);if (s->regs[base +R_TX_CTRL0 ] &CTRL_I )eth_pulse_irq (s); }else if ((value & (CTRL_P |CTRL_S )) == (CTRL_P |CTRL_S )) {
@@ -196,7 +200,7 @@ eth_write(void *opaque, hwaddr addr,case R_TX_LEN0 :case R_TX_LEN1 : - s->regs[addr] = value; + s->port[port_index].reg.tx_len = value;break ;case R_TX_GIE0 :
Signature · 1 line
2.45.2
PATCH RESEND v2 12/19 hw/net/xilinx_ethlite: Access TX_CTRL register for each port
In reply to Philippe Mathieu-DaudéRather than accessing the registers within the mixed RAM/MMIO region as indexed register, declare a per-port TX_CTRL. This will help to map the RAM as RAM (keeping MMIO as MMIO) in few commits.
Previous s->regs[R_TX_CTRL0] and s->regs[R_TX_CTRL1] are now unused. Not a concern, this array will soon disappear.
--- hw/net/xilinx_ethlite.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
hw/net/xilinx_ethlite.c +7 -8
@@ -65,6 +65,7 @@ typedef struct XlnxXpsEthLitePortstruct {uint32_t tx_len;uint32_t tx_gie; +uint32_t tx_ctrl;uint32_t rx_ctrl; } reg;
@@ -140,7 +141,7 @@ eth_read(void *opaque, hwaddr addr, unsigned int size)case R_TX_CTRL1 :case R_TX_CTRL0 : - r = s->regs[addr]; + r = s->port[port_index].reg.tx_ctrl;break ;case R_RX_CTRL1 :
@@ -161,7 +162,6 @@ eth_write(void *opaque, hwaddr addr, {XlnxXpsEthLite *s = opaque;unsigned int port_index =addr_to_port_index (addr); -unsigned int base =0 ;uint32_t value = val64; addr >>=2 ;
@@ -169,24 +169,23 @@ eth_write(void *opaque, hwaddr addr, {case R_TX_CTRL0 :case R_TX_CTRL1 : -if (addr ==R_TX_CTRL1 ) - base =0x800 /4 ; -if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) {qemu_send_packet (qemu_get_queue (s->nic),txbuf_ptr (s, port_index), s->port[port_index].reg.tx_len); -if (s->regs[base +R_TX_CTRL0 ] &CTRL_I ) +if (s->port[port_index].reg.tx_ctrl &CTRL_I ) {eth_pulse_irq (s); + } }else if ((value & (CTRL_P |CTRL_S )) == (CTRL_P |CTRL_S )) {memcpy (&s->conf.macaddr.a[0 ],txbuf_ptr (s, port_index),6 ); -if (s->regs[base +R_TX_CTRL0 ] &CTRL_I ) +if (s->port[port_index].reg.tx_ctrl &CTRL_I ) {eth_pulse_irq (s); + } }/* We are fast and get ready pretty much immediately so we actually never flip the S nor P bits to one. */ - s->regs[addr] = value & ~(CTRL_P |CTRL_S ); + s->port[port_index].reg.tx_ctrl = value & ~(CTRL_P |CTRL_S );break ;/* Keep these native. */
Signature · 1 line
2.45.2
PATCH RESEND v2 13/19 hw/net/xilinx_ethlite: Map RX_CTRL as MMIO
In reply to Philippe Mathieu-DaudéDeclare RX registers as MMIO region, split it out
of the current mixed RAM/MMIO region.
The memory flat view becomes:
(qemu) info mtree -f
FlatView #0
Root memory region: system
0000000081000000-00000000810007e3 (prio 0, i/o): xlnx.xps-ethernetlite
00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio
00000000810007f4-00000000810017fb (prio 0, i/o): xlnx.xps-ethernetlite @00000000000007f4
00000000810017fc-00000000810017ff (prio 0, i/o): ethlite.rx[0]io
0000000081001800-0000000081001ffb (prio 0, i/o): xlnx.xps-ethernetlite @0000000000001800
0000000081001ffc-0000000081001fff (prio 0, i/o): ethlite.rx[1]io--- hw/net/xilinx_ethlite.c | 82 +++++++++++++++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 15 deletions(-)
hw/net/xilinx_ethlite.c +67 -15
@@ -49,11 +49,16 @@#define R_TX_CTRL1 (0x0ffc / 4)#define R_RX_BUF0 (0x1000 / 4) -#define R_RX_CTRL0 (0x17fc / 4) +#define A_RX_BASE0 0x17fc#define R_RX_BUF1 (0x1800 / 4) -#define R_RX_CTRL1 (0x1ffc / 4) +#define A_RX_BASE1 0x1ffc#define R_MAX (0x2000 / 4) +enum { +RX_CTRL =0 , +RX_MAX +}; +#define GIE_GIE 0x80000000#define CTRL_I 0x8
@@ -62,6 +67,8 @@ typedef struct XlnxXpsEthLitePort { + MemoryRegion rxio; + struct { uint32_t tx_len; uint32_t tx_gie;
@@ -119,6 +126,55 @@ static void *rxbuf_ptr(XlnxXpsEthLite *s, unsigned port_index)return &s->regs[rxbase +R_RX_BUF0 ]; } +static uint64_t port_rx_read (void *opaque,hwaddr addr,unsigned int size) +{ +XlnxXpsEthLite *s = opaque; +unsigned port_index =addr_to_port_index (addr); +uint32_t r =0 ; + +switch (addr >>2 ) { +case RX_CTRL : + r = s->port[port_index].reg.rx_ctrl; +break ; +default : +g_assert_not_reached (); + } + +return r; +} + +static void port_rx_write (void *opaque,hwaddr addr,uint64_t value, +unsigned int size) +{ +XlnxXpsEthLite *s = opaque; +unsigned port_index =addr_to_port_index (addr); + +switch (addr >>2 ) { +case RX_CTRL : +if (!(value &CTRL_S )) { +qemu_flush_queued_packets (qemu_get_queue (s->nic)); + } + s->port[port_index].reg.rx_ctrl = value; +break ; +default : +g_assert_not_reached (); + } +} + +static const MemoryRegionOps eth_portrx_ops = { + .read = port_rx_read, + .write = port_rx_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = { + .min_access_size =4 , + .max_access_size =4 , + }, + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; +static uint64_t eth_read (void *opaque,hwaddr addr,unsigned int size) {
@@ -144,11 +200,6 @@ eth_read(void *opaque, hwaddr addr, unsigned int size) r = s->port[port_index].reg.tx_ctrl;break ; -case R_RX_CTRL1 : -case R_RX_CTRL0 : - r = s->port[port_index].reg.rx_ctrl; -break ; -default : r =tswap32 (s->regs[addr]);break ;
@@ -189,14 +240,6 @@ eth_write(void *opaque, hwaddr addr,break ;/* Keep these native. */ -case R_RX_CTRL0 : -case R_RX_CTRL1 : -if (!(value &CTRL_S )) { -qemu_flush_queued_packets (qemu_get_queue (s->nic)); - } - s->port[port_index].reg.rx_ctrl = value; -break ; -case R_TX_LEN0 :case R_TX_LEN1 : s->port[port_index].reg.tx_len = value;
@@ -289,6 +332,15 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&s->mmio,A_MDIO_BASE ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->mdio),0 )); +for (unsigned i =0 ; i <2 ; i++) { +memory_region_init_io (&s->port[i].rxio,OBJECT (dev), + ð_portrx_ops, s, + i ?"ethlite.rx[1]io" :"ethlite.rx[0]io" , +4 *RX_MAX ); +memory_region_add_subregion (&s->mmio, i ?A_RX_BASE1 :A_RX_BASE0 , + &s->port[i].rxio); + } +qemu_macaddr_default_if_unset (&s->conf.macaddr); s->nic = qemu_new_nic(&net_xilinx_ethlite_info, &s->conf, object_get_typename(OBJECT(dev)), dev->id,
Signature · 1 line
2.45.2
PATCH RESEND v2 14/19 hw/net/xilinx_ethlite: Map TX_LEN as MMIO
In reply to Philippe Mathieu-DaudéDeclare TX registers as MMIO region, split it out
of the current mixed RAM/MMIO region.
The memory flat view becomes:
(qemu) info mtree -f
FlatView #0
Root memory region: system
0000000081000000-00000000810007e3 (prio 0, i/o): xlnx.xps-ethernetlite
00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio
00000000810007f4-00000000810007f7 (prio 0, i/o): ethlite.tx[0]io
00000000810007f8-0000000081000ff3 (prio 0, i/o): xlnx.xps-ethernetlite @00000000000007f8
0000000081000ff4-0000000081000ff7 (prio 0, i/o): ethlite.tx[1]io
0000000081000ff8-00000000810017fb (prio 0, i/o): xlnx.xps-ethernetlite @0000000000000ff8
00000000810017fc-00000000810017ff (prio 0, i/o): ethlite.rx[0]io
0000000081001800-0000000081001ffb (prio 0, i/o): xlnx.xps-ethernetlite @0000000000001800
0000000081001ffc-0000000081001fff (prio 0, i/o): ethlite.rx[1]io--- hw/net/xilinx_ethlite.c | 73 ++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 12 deletions(-)
hw/net/xilinx_ethlite.c +61 -12
@@ -41,11 +41,11 @@#define R_TX_BUF0 0#define BUFSZ_MAX 0x07e4#define A_MDIO_BASE 0x07e4 -#define R_TX_LEN0 (0x07f4 / 4) +#define A_TX_BASE0 0x07f4#define R_TX_GIE0 (0x07f8 / 4)#define R_TX_CTRL0 (0x07fc / 4)#define R_TX_BUF1 (0x0800 / 4) -#define R_TX_LEN1 (0x0ff4 / 4) +#define A_TX_BASE1 0x0ff4#define R_TX_CTRL1 (0x0ffc / 4)#define R_RX_BUF0 (0x1000 / 4)
@@ -54,6 +54,11 @@#define A_RX_BASE1 0x1ffc#define R_MAX (0x2000 / 4) +enum { +TX_LEN =0 , +TX_MAX +}; +enum {RX_CTRL =0 ,RX_MAX
@@ -67,6 +72,7 @@ enum { typedef struct XlnxXpsEthLitePort { + MemoryRegion txio; MemoryRegion rxio; struct {
@@ -126,6 +132,52 @@ static void *rxbuf_ptr(XlnxXpsEthLite *s, unsigned port_index)return &s->regs[rxbase +R_RX_BUF0 ]; } +static uint64_t port_tx_read (void *opaque,hwaddr addr,unsigned int size) +{ +XlnxXpsEthLite *s = opaque; +unsigned port_index =addr_to_port_index (addr); +uint32_t r =0 ; + +switch (addr >>2 ) { +case TX_LEN : + r = s->port[port_index].reg.tx_len; +break ; +default : +g_assert_not_reached (); + } + +return r; +} + +static void port_tx_write (void *opaque,hwaddr addr,uint64_t value, +unsigned int size) +{ +XlnxXpsEthLite *s = opaque; +unsigned port_index =addr_to_port_index (addr); + +switch (addr >>2 ) { +case TX_LEN : + s->port[port_index].reg.tx_len = value; +break ; +default : +g_assert_not_reached (); + } +} + +static const MemoryRegionOps eth_porttx_ops = { + .read = port_tx_read, + .write = port_tx_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl = { + .min_access_size =4 , + .max_access_size =4 , + }, + .valid = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; +static uint64_t port_rx_read (void *opaque,hwaddr addr,unsigned int size) {XlnxXpsEthLite *s = opaque;
@@ -190,11 +242,6 @@ eth_read(void *opaque, hwaddr addr, unsigned int size) r = s->port[port_index].reg.tx_gie;break ; -case R_TX_LEN0 : -case R_TX_LEN1 : - r = s->port[port_index].reg.tx_len; -break ; -case R_TX_CTRL1 :case R_TX_CTRL0 : r = s->port[port_index].reg.tx_ctrl;
@@ -240,11 +287,6 @@ eth_write(void *opaque, hwaddr addr,break ;/* Keep these native. */ -case R_TX_LEN0 : -case R_TX_LEN1 : - s->port[port_index].reg.tx_len = value; -break ; -case R_TX_GIE0 : s->port[port_index].reg.tx_gie = value;break ;
@@ -333,6 +375,13 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp) sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mdio), 0));for (unsigned i =0 ; i <2 ; i++) { +memory_region_init_io (&s->port[i].txio,OBJECT (dev), + ð_porttx_ops, s, + i ?"ethlite.tx[1]io" :"ethlite.tx[0]io" , +4 *TX_MAX ); +memory_region_add_subregion (&s->mmio, i ?A_TX_BASE1 :A_TX_BASE0 , + &s->port[i].txio); + memory_region_init_io(&s->port[i].rxio, OBJECT(dev), ð_portrx_ops, s, i ? "ethlite.rx[1]io" : "ethlite.rx[0]io",
Signature · 1 line
2.45.2
PATCH RESEND v2 15/19 hw/net/xilinx_ethlite: Map TX_GIE as MMIO
In reply to Philippe Mathieu-DaudéAdd TX_GIE to the TX registers MMIO region.
Before TX_GIE1 was accessed as RAM, with no effect. Now it is accessed as MMIO, also without any effect.
The memory flat view becomes:
(qemu) info mtree -f
FlatView #0
Root memory region: system
0000000081000000-00000000810007e3 (prio 0, i/o): xlnx.xps-ethernetlite
00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio
00000000810007f4-00000000810007fb (prio 0, i/o): ethlite.tx[0]io
00000000810007fc-0000000081000ff3 (prio 0, i/o): xlnx.xps-ethernetlite @00000000000007fc
0000000081000ff4-0000000081000ffb (prio 0, i/o): ethlite.tx[1]io
0000000081000ffc-00000000810017fb (prio 0, i/o): xlnx.xps-ethernetlite @0000000000000ffc
00000000810017fc-00000000810017ff (prio 0, i/o): ethlite.rx[0]io
0000000081001800-0000000081001ffb (prio 0, i/o): xlnx.xps-ethernetlite @0000000000001800
0000000081001ffc-0000000081001fff (prio 0, i/o): ethlite.rx[1]io--- hw/net/xilinx_ethlite.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
hw/net/xilinx_ethlite.c +7 -10
@@ -42,7 +42,6 @@#define BUFSZ_MAX 0x07e4#define A_MDIO_BASE 0x07e4#define A_TX_BASE0 0x07f4 -#define R_TX_GIE0 (0x07f8 / 4)#define R_TX_CTRL0 (0x07fc / 4)#define R_TX_BUF1 (0x0800 / 4)#define A_TX_BASE1 0x0ff4
@@ -56,6 +55,7 @@enum {TX_LEN =0 , +TX_GIE =1 ,TX_MAX };
@@ -142,6 +142,9 @@ static uint64_t port_tx_read(void *opaque, hwaddr addr, unsigned int size)case TX_LEN : r = s->port[port_index].reg.tx_len;break ; +case TX_GIE : + r = s->port[port_index].reg.tx_gie; +break ;default :g_assert_not_reached (); }
@@ -159,6 +162,9 @@ static void port_tx_write(void *opaque, hwaddr addr, uint64_t value,case TX_LEN : s->port[port_index].reg.tx_len = value;break ; +case TX_GIE : + s->port[port_index].reg.tx_gie = value; +break ;default :g_assert_not_reached (); }
@@ -238,10 +244,6 @@ eth_read(void *opaque, hwaddr addr, unsigned int size)switch (addr) { -case R_TX_GIE0 : - r = s->port[port_index].reg.tx_gie; -break ; -case R_TX_CTRL1 :case R_TX_CTRL0 : r = s->port[port_index].reg.tx_ctrl;
@@ -286,11 +288,6 @@ eth_write(void *opaque, hwaddr addr, s->port[port_index].reg.tx_ctrl = value & ~(CTRL_P |CTRL_S );break ; -/* Keep these native. */ -case R_TX_GIE0 : - s->port[port_index].reg.tx_gie = value; -break ; -default : s->regs[addr] =tswap32 (value);break ;
Signature · 1 line
2.45.2
PATCH RESEND v2 16/19 hw/net/xilinx_ethlite: Map TX_CTRL as MMIO
In reply to Philippe Mathieu-DaudéAdd TX_CTRL to the TX registers MMIO region.
The memory flat view becomes:
(qemu) info mtree -f
FlatView #0
Root memory region: system
0000000081000000-00000000810007e3 (prio 0, i/o): xlnx.xps-ethernetlite
00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio
00000000810007f4-00000000810007ff (prio 0, i/o): ethlite.tx[0]io
0000000081000800-0000000081000ff3 (prio 0, i/o): xlnx.xps-ethernetlite @0000000000000800
0000000081000ff4-0000000081000fff (prio 0, i/o): ethlite.tx[1]io
0000000081001000-00000000810017fb (prio 0, i/o): xlnx.xps-ethernetlite @0000000000001000
00000000810017fc-00000000810017ff (prio 0, i/o): ethlite.rx[0]io
0000000081001800-0000000081001ffb (prio 0, i/o): xlnx.xps-ethernetlite @0000000000001800
0000000081001ffc-0000000081001fff (prio 0, i/o): ethlite.rx[1]io--- hw/net/xilinx_ethlite.c | 54 ++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 30 deletions(-)
hw/net/xilinx_ethlite.c +24 -30
@@ -42,10 +42,8 @@#define BUFSZ_MAX 0x07e4#define A_MDIO_BASE 0x07e4#define A_TX_BASE0 0x07f4 -#define R_TX_CTRL0 (0x07fc / 4)#define R_TX_BUF1 (0x0800 / 4)#define A_TX_BASE1 0x0ff4 -#define R_TX_CTRL1 (0x0ffc / 4)#define R_RX_BUF0 (0x1000 / 4)#define A_RX_BASE0 0x17fc
@@ -56,6 +54,7 @@enum {TX_LEN =0 ,TX_GIE =1 , +TX_CTRL =2 ,TX_MAX };
@@ -145,6 +144,9 @@ static uint64_t port_tx_read(void *opaque, hwaddr addr, unsigned int size)case TX_GIE : r = s->port[port_index].reg.tx_gie;break ; +case TX_CTRL : + r = s->port[port_index].reg.tx_ctrl; +break ;default :g_assert_not_reached (); }
@@ -165,6 +167,26 @@ static void port_tx_write(void *opaque, hwaddr addr, uint64_t value,case TX_GIE : s->port[port_index].reg.tx_gie = value;break ; +case TX_CTRL : +if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) { +qemu_send_packet (qemu_get_queue (s->nic), +txbuf_ptr (s, port_index), + s->port[port_index].reg.tx_len); +if (s->port[port_index].reg.tx_ctrl &CTRL_I ) { +eth_pulse_irq (s); + } + }else if ((value & (CTRL_P |CTRL_S )) == (CTRL_P |CTRL_S )) { +memcpy (&s->conf.macaddr.a[0 ],txbuf_ptr (s, port_index),6 ); +if (s->port[port_index].reg.tx_ctrl &CTRL_I ) { +eth_pulse_irq (s); + } + } +/* +* We are fast and get ready pretty much immediately +* so we actually never flip the S nor P bits to one. +*/ + s->port[port_index].reg.tx_ctrl = value & ~(CTRL_P |CTRL_S ); +break ;default :g_assert_not_reached (); }
@@ -237,18 +259,12 @@ static uint64_t eth_read(void *opaque, hwaddr addr, unsigned int size) {XlnxXpsEthLite *s = opaque; -unsigned port_index =addr_to_port_index (addr);uint32_t r =0 ; addr >>=2 ;switch (addr) { -case R_TX_CTRL1 : -case R_TX_CTRL0 : - r = s->port[port_index].reg.tx_ctrl; -break ; -default : r =tswap32 (s->regs[addr]);break ;
@@ -261,33 +277,11 @@ eth_write(void *opaque, hwaddr addr, uint64_t val64, unsigned int size) {XlnxXpsEthLite *s = opaque; -unsigned int port_index =addr_to_port_index (addr);uint32_t value = val64; addr >>=2 ;switch (addr) { -case R_TX_CTRL0 : -case R_TX_CTRL1 : -if ((value & (CTRL_P |CTRL_S )) ==CTRL_S ) { -qemu_send_packet (qemu_get_queue (s->nic), -txbuf_ptr (s, port_index), - s->port[port_index].reg.tx_len); -if (s->port[port_index].reg.tx_ctrl &CTRL_I ) { -eth_pulse_irq (s); - } - }else if ((value & (CTRL_P |CTRL_S )) == (CTRL_P |CTRL_S )) { -memcpy (&s->conf.macaddr.a[0 ],txbuf_ptr (s, port_index),6 ); -if (s->port[port_index].reg.tx_ctrl &CTRL_I ) { -eth_pulse_irq (s); - } - } - -/* We are fast and get ready pretty much immediately so -we actually never flip the S nor P bits to one. */ - s->port[port_index].reg.tx_ctrl = value & ~(CTRL_P |CTRL_S ); -break ; -default : s->regs[addr] =tswap32 (value);break ;
Signature · 1 line
2.45.2
PATCH RESEND v2 17/19 hw/net/xilinx_ethlite: Map the RAM buffer as RAM memory region
In reply to Philippe Mathieu-DaudéRather than using I/O registers for RAM buffer, having to swap endianness back and forth (because the core memory layer automatically swaps endiannes for us), declare the buffers as RAM regions. The "xlnx.xps-ethernetlite" MR doesn't have any more I/O regions. Remove the now unused s->regs[] array.
The memory flat view becomes:
FlatView #0
Root memory region: system
0000000081000000-00000000810007e3 (prio 0, ram): ethlite.tx[0]buf
00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio
00000000810007f4-00000000810007ff (prio 0, i/o): ethlite.tx[0]io
0000000081000800-0000000081000fe3 (prio 0, ram): ethlite.tx[1]buf
0000000081000ff4-0000000081000fff (prio 0, i/o): ethlite.tx[1]io
0000000081001000-00000000810017e3 (prio 0, ram): ethlite.rx[0]buf
00000000810017fc-00000000810017ff (prio 0, i/o): ethlite.rx[0]io
0000000081001800-0000000081001fe3 (prio 0, ram): ethlite.rx[1]buf
0000000081001ffc-0000000081001fff (prio 0, i/o): ethlite.rx[1]io--- hw/net/xilinx_ethlite.c | 81 +++++++++-------------------------------- 1 file changed, 17 insertions(+), 64 deletions(-)
hw/net/xilinx_ethlite.c +17 -64
@@ -2,6 +2,7 @@* QEMU model of the Xilinx Ethernet Lite MAC. * * Copyright (c) 2009 Edgar E. Iglesias. +* Copyright (c) 2024 Linaro, Ltd * * DS580: https://docs.amd.com/v/u/en-US/xps_ethernetlite * LogiCORE IP XPS Ethernet Lite Media Access Controller
@@ -30,7 +31,6 @@#include "qemu/bitops.h" #include "qom/object.h" #include "qapi/error.h" -#include "exec/tswap.h" #include "hw/sysbus.h" #include "hw/irq.h" #include "hw/qdev-properties.h"
@@ -38,18 +38,12 @@#include "net/net.h" #include "trace.h" -#define R_TX_BUF0 0#define BUFSZ_MAX 0x07e4#define A_MDIO_BASE 0x07e4#define A_TX_BASE0 0x07f4 -#define R_TX_BUF1 (0x0800 / 4)#define A_TX_BASE1 0x0ff4 - -#define R_RX_BUF0 (0x1000 / 4)#define A_RX_BASE0 0x17fc -#define R_RX_BUF1 (0x1800 / 4)#define A_RX_BASE1 0x1ffc -#define R_MAX (0x2000 / 4)enum {TX_LEN =0 ,
@@ -73,6 +67,8 @@ typedef struct XlnxXpsEthLitePort {MemoryRegion txio;MemoryRegion rxio; +MemoryRegion txbuf; +MemoryRegion rxbuf;struct {uint32_t tx_len;
@@ -101,7 +97,6 @@ struct XlnxXpsEthLiteUnimplementedDeviceState mdio;XlnxXpsEthLitePort port[2 ]; -uint32_t regs[R_MAX ]; };static inline void eth_pulse_irq (XlnxXpsEthLite *s)
@@ -119,16 +114,12 @@ static unsigned addr_to_port_index(hwaddr addr)static void *txbuf_ptr (XlnxXpsEthLite *s,unsigned port_index) { -unsigned int rxbase = port_index * (0x800 /4 ); - -return &s->regs[rxbase +R_TX_BUF0 ]; +return memory_region_get_ram_ptr (&s->port[port_index].txbuf); }static void *rxbuf_ptr (XlnxXpsEthLite *s,unsigned port_index) { -unsigned int rxbase = port_index * (0x800 /4 ); - -return &s->regs[rxbase +R_RX_BUF0 ]; +return memory_region_get_ram_ptr (&s->port[port_index].rxbuf); }static uint64_t port_tx_read (void *opaque,hwaddr addr,unsigned int size)
@@ -255,53 +246,6 @@ static const MemoryRegionOps eth_portrx_ops = { }, }; -static uint64_t -eth_read (void *opaque,hwaddr addr,unsigned int size) -{ -XlnxXpsEthLite *s = opaque; -uint32_t r =0 ; - - addr >>=2 ; - -switch (addr) - { -default : - r =tswap32 (s->regs[addr]); -break ; - } -return r; -} - -static void -eth_write (void *opaque,hwaddr addr, -uint64_t val64,unsigned int size) -{ -XlnxXpsEthLite *s = opaque; -uint32_t value = val64; - - addr >>=2 ; -switch (addr) - { -default : - s->regs[addr] =tswap32 (value); -break ; - } -} - -static const MemoryRegionOps eth_ops = { - .read = eth_read, - .write = eth_write, - .endianness =DEVICE_NATIVE_ENDIAN , - .impl = { - .min_access_size =4 , - .max_access_size =4 , - }, - .valid = { - .min_access_size =4 , - .max_access_size =4 - } -}; -static bool eth_can_rx (NetClientState *nc) {XlnxXpsEthLite *s =qemu_get_nic_opaque (nc);
@@ -357,6 +301,9 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp) {XlnxXpsEthLite *s =XILINX_ETHLITE (dev); +memory_region_init (&s->mmio,OBJECT (dev), +"xlnx.xps-ethernetlite" ,0x2000 ); +object_initialize_child (OBJECT (dev),"ethlite.mdio" , &s->mdio,TYPE_UNIMPLEMENTED_DEVICE );qdev_prop_set_string (DEVICE (&s->mdio),"name" ,"ethlite.mdio" );
@@ -366,6 +313,10 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp) sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mdio), 0));for (unsigned i =0 ; i <2 ; i++) { +memory_region_init_ram (&s->port[i].txbuf,OBJECT (dev), + i ?"ethlite.tx[1]buf" :"ethlite.tx[0]buf" , +BUFSZ_MAX , &error_abort); +memory_region_add_subregion (&s->mmio,0x0800 * i, &s->port[i].txbuf); memory_region_init_io(&s->port[i].txio, OBJECT(dev), ð_porttx_ops, s, i ? "ethlite.tx[1]io" : "ethlite.tx[0]io",
@@ -373,6 +324,11 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (&s->mmio, i ?A_TX_BASE1 :A_TX_BASE0 , &s->port[i].txio); +memory_region_init_ram (&s->port[i].rxbuf,OBJECT (dev), + i ?"ethlite.rx[1]buf" :"ethlite.rx[0]buf" , +BUFSZ_MAX , &error_abort); +memory_region_add_subregion (&s->mmio,0x1000 +0x0800 * i, + &s->port[i].rxbuf); memory_region_init_io(&s->port[i].rxio, OBJECT(dev), ð_portrx_ops, s, i ? "ethlite.rx[1]io" : "ethlite.rx[0]io",
@@ -393,9 +349,6 @@ static void xilinx_ethlite_init(Object *obj)XlnxXpsEthLite *s =XILINX_ETHLITE (obj);sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq); - -memory_region_init_io (&s->mmio, obj, ð_ops, s, -"xlnx.xps-ethernetlite" ,R_MAX *4 );sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); }
Signature · 1 line
2.45.2
PATCH RESEND v2 18/19 hw/net/xilinx_ethlite: Rename 'mmio' MR as 'container'
In reply to Philippe Mathieu-DaudéHaving all its address range mapped by subregions, s->mmio MemoryRegion effectively became a container. Rename it as 'container' for clarity.
--- hw/net/xilinx_ethlite.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
hw/net/xilinx_ethlite.c +8 -8
@@ -86,7 +86,7 @@ struct XlnxXpsEthLite {SysBusDevice parent_obj; -MemoryRegion mmio; +MemoryRegion container;qemu_irq irq;NICState *nic;NICConf conf;
@@ -301,7 +301,7 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp) {XlnxXpsEthLite *s =XILINX_ETHLITE (dev); -memory_region_init (&s->mmio,OBJECT (dev), +memory_region_init (&s->container,OBJECT (dev),"xlnx.xps-ethernetlite" ,0x2000 ); object_initialize_child(OBJECT(dev), "ethlite.mdio", &s->mdio,
@@ -309,31 +309,31 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp)qdev_prop_set_string (DEVICE (&s->mdio),"name" ,"ethlite.mdio" );qdev_prop_set_uint64 (DEVICE (&s->mdio),"size" ,4 *4 );sysbus_realize (SYS_BUS_DEVICE (&s->mdio), &error_fatal); -memory_region_add_subregion (&s->mmio,A_MDIO_BASE , +memory_region_add_subregion (&s->container,A_MDIO_BASE ,sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->mdio),0 ));for (unsigned i =0 ; i <2 ; i++) {memory_region_init_ram (&s->port[i].txbuf,OBJECT (dev), i ?"ethlite.tx[1]buf" :"ethlite.tx[0]buf" ,BUFSZ_MAX , &error_abort); -memory_region_add_subregion (&s->mmio,0x0800 * i, &s->port[i].txbuf); +memory_region_add_subregion (&s->container,0x0800 * i, &s->port[i].txbuf);memory_region_init_io (&s->port[i].txio,OBJECT (dev), ð_porttx_ops, s, i ?"ethlite.tx[1]io" :"ethlite.tx[0]io" ,4 *TX_MAX ); -memory_region_add_subregion (&s->mmio, i ?A_TX_BASE1 :A_TX_BASE0 , +memory_region_add_subregion (&s->container, i ?A_TX_BASE1 :A_TX_BASE0 , &s->port[i].txio);memory_region_init_ram (&s->port[i].rxbuf,OBJECT (dev), i ?"ethlite.rx[1]buf" :"ethlite.rx[0]buf" ,BUFSZ_MAX , &error_abort); -memory_region_add_subregion (&s->mmio,0x1000 +0x0800 * i, +memory_region_add_subregion (&s->container,0x1000 +0x0800 * i, &s->port[i].rxbuf);memory_region_init_io (&s->port[i].rxio,OBJECT (dev), ð_portrx_ops, s, i ?"ethlite.rx[1]io" :"ethlite.rx[0]io" ,4 *RX_MAX ); -memory_region_add_subregion (&s->mmio, i ?A_RX_BASE1 :A_RX_BASE0 , +memory_region_add_subregion (&s->container, i ?A_RX_BASE1 :A_RX_BASE0 , &s->port[i].rxio); }
@@ -349,7 +349,7 @@ static void xilinx_ethlite_init(Object *obj)XlnxXpsEthLite *s =XILINX_ETHLITE (obj);sysbus_init_irq (SYS_BUS_DEVICE (obj), &s->irq); -sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->mmio); +sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->container); }static Property xilinx_ethlite_properties[] = {
Signature · 1 line
2.45.2
PATCH RESEND v2 19/19 hw/net/xilinx_ethlite: Map RESERVED I/O as unimplemented
In reply to Philippe Mathieu-DaudéIn order to track access to reserved I/O space, use yet another UnimplementedDevice covering the whole device memory range. Mapped with lower priority (-1).
The memory flat view becomes:
(qemu) info mtree -f
FlatView #0
Root memory region: system
0000000081000000-00000000810007e3 (prio 0, ram): ethlite.tx[0]buf
00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio
00000000810007f4-00000000810007ff (prio 0, i/o): ethlite.tx[0]io
0000000081000800-0000000081000fe3 (prio 0, ram): ethlite.tx[1]buf
0000000081000fe4-0000000081000ff3 (prio -1, i/o): ethlite.reserved @0000000000000fe4
0000000081000ff4-0000000081000fff (prio 0, i/o): ethlite.tx[1]io
0000000081001000-00000000810017e3 (prio 0, ram): ethlite.rx[0]buf
00000000810017e4-00000000810017fb (prio -1, i/o): ethlite.reserved @00000000000017e4
00000000810017fc-00000000810017ff (prio 0, i/o): ethlite.rx[0]io
0000000081001800-0000000081001fe3 (prio 0, ram): ethlite.rx[1]buf
0000000081001fe4-0000000081001ffb (prio -1, i/o): ethlite.reserved @0000000000001fe4
0000000081001ffc-0000000081001fff (prio 0, i/o): ethlite.rx[1]io--- hw/net/xilinx_ethlite.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
hw/net/xilinx_ethlite.c +11 -0
@@ -95,6 +95,7 @@ struct XlnxXpsEthLiteuint32_t c_rx_pingpong;unsigned int port_index;/* dual port RAM index */ +UnimplementedDeviceState rsvd;UnimplementedDeviceState mdio;XlnxXpsEthLitePort port[2 ]; };
@@ -304,6 +305,16 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp)memory_region_init (&s->container,OBJECT (dev),"xlnx.xps-ethernetlite" ,0x2000 ); +object_initialize_child (OBJECT (dev),"ethlite.reserved" , &s->rsvd, +TYPE_UNIMPLEMENTED_DEVICE ); +qdev_prop_set_string (DEVICE (&s->rsvd),"name" ,"ethlite.reserved" ); +qdev_prop_set_uint64 (DEVICE (&s->rsvd),"size" , +memory_region_size (&s->container)); +sysbus_realize (SYS_BUS_DEVICE (&s->rsvd), &error_fatal); +memory_region_add_subregion_overlap (&s->container,0 , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->rsvd),0 ), +-1 ); +object_initialize_child (OBJECT (dev),"ethlite.mdio" , &s->mdio,TYPE_UNIMPLEMENTED_DEVICE );qdev_prop_set_string (DEVICE (&s->mdio),"name" ,"ethlite.mdio" );
Signature · 1 line
2.45.2
Re: [PATCH RESEND v2 19/19] hw/net/xilinx_ethlite: Map RESERVED I/O as unimplemented
Quoted 22 lines · Philippe Mathieu-Daudé
In order to track access to reserved I/O space, use yet another UnimplementedDevice covering the whole device memory range. Mapped with lower priority (-1).
The memory flat view becomes:
(qemu) info mtree -f
FlatView #0
Root memory region: system0000000081000000-00000000810007e3 (prio 0, ram): ethlite.tx[0]buf 00000000810007e4-00000000810007f3 (prio 0, i/o): ethlite.mdio 00000000810007f4-00000000810007ff (prio 0, i/o): ethlite.tx[0]io 0000000081000800-0000000081000fe3 (prio 0, ram): ethlite.tx[1]buf 0000000081000fe4-0000000081000ff3 (prio -1, i/o): ethlite.reserved @0000000000000fe4 0000000081000ff4-0000000081000fff (prio 0, i/o): ethlite.tx[1]io 0000000081001000-00000000810017e3 (prio 0, ram): ethlite.rx[0]buf 00000000810017e4-00000000810017fb (prio -1, i/o): ethlite.reserved @00000000000017e4 00000000810017fc-00000000810017ff (prio 0, i/o): ethlite.rx[0]io 0000000081001800-0000000081001fe3 (prio 0, ram): ethlite.rx[1]buf 0000000081001fe4-0000000081001ffb (prio -1, i/o): ethlite.reserved @0000000000001fe4 0000000081001ffc-0000000081001fff (prio 0, i/o): ethlite.rx[1]io
Quoted 1 line
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 33 lines
--- hw/net/xilinx_ethlite.c | 11 +++++++++++ 1 file changed, 11 insertions(+)hw/net/xilinx_ethlite.c +11
-0@@ -95,6 +95,7 @@ struct XlnxXpsEthLiteuint32_t c_rx_pingpong;unsigned int port_index;/* dual port RAM index */ +UnimplementedDeviceState rsvd;UnimplementedDeviceState mdio;XlnxXpsEthLitePort port[2 ]; };@@ -304,6 +305,16 @@ static void xilinx_ethlite_realize(DeviceState *dev, Error **errp)memory_region_init (&s->container,OBJECT (dev),"xlnx.xps-ethernetlite" ,0x2000 ); +object_initialize_child (OBJECT (dev),"ethlite.reserved" , &s->rsvd, +TYPE_UNIMPLEMENTED_DEVICE ); +qdev_prop_set_string (DEVICE (&s->rsvd),"name" ,"ethlite.reserved" ); +qdev_prop_set_uint64 (DEVICE (&s->rsvd),"size" , +memory_region_size (&s->container)); +sysbus_realize (SYS_BUS_DEVICE (&s->rsvd), &error_fatal); +memory_region_add_subregion_overlap (&s->container,0 , +sysbus_mmio_get_region (SYS_BUS_DEVICE (&s->rsvd),0 ), +-1 ); +object_initialize_child (OBJECT (dev),"ethlite.mdio" , &s->mdio,TYPE_UNIMPLEMENTED_DEVICE );qdev_prop_set_string (DEVICE (&s->mdio),"name" ,"ethlite.mdio" );
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 12 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (19):
hw/microblaze: Restrict MemoryRegionOps are implemented as 32-bit hw/net/xilinx_ethlite: Convert some debug logs to trace events hw/net/xilinx_ethlite: Remove unuseful debug logs hw/net/xilinx_ethlite: Update QOM style hw/net/xilinx_ethlite: Correct maximum RX buffer size hw/net/xilinx_ethlite: Map MDIO registers (as unimplemented) hw/net/xilinx_ethlite: Rename rxbuf ->port_indexhw/net/xilinx_ethlite: Introducetxbuf_ptr()helper hw/net/xilinx_ethlite: Introducerxbuf_ptr()helper hw/net/xilinx_ethlite: AccessTX_GIEregister for each port hw/net/xilinx_ethlite: AccessTX_LENregister for each port
Quoted 8 lines
hw/net/xilinx_ethlite: Access
TX_CTRLregister for each port hw/net/xilinx_ethlite: MapRX_CTRLas MMIO hw/net/xilinx_ethlite: MapTX_LENas MMIO hw/net/xilinx_ethlite: MapTX_GIEas MMIO hw/net/xilinx_ethlite: MapTX_CTRLas MMIO hw/net/xilinx_ethlite: Map the RAM buffer as RAM memory region hw/net/xilinx_ethlite: Rename 'mmio' MR as 'container' hw/net/xilinx_ethlite: Map RESERVED I/O as unimplemented
Series queued.