RFC] hw/net: Add Smartfusion2 emac block
Modelled Ethernet MAC of Smartfusion2 SoC.
Micrel KSZ8051 PHY is present on Emcraft's SOM kit hence same PHY is emulated.
Signed-off-by Subbaraya Sundeep <[email protected]>
--- hw/arm/msf2-soc.c | 21 +- hw/net/Makefile.objs | 1 + hw/net/mss-emac.c | 544 ++++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/msf2-soc.h | 3 + include/hw/net/mss-emac.h | 23 ++ 5 files changed, 591 insertions(+), 1 deletion(-) create mode 100644 hw/net/mss-emac.c create mode 100644 include/hw/net/mss-emac.h
hw/arm/msf2-soc.c +20 -1
@@ -35,6 +35,7 @@#define MSF2_TIMER_BASE 0x40004000#define MSF2_SYSREG_BASE 0x40038000 +#define MSF2_EMAC_BASE 0x40041000#define ENVM_BASE_ADDRESS 0x60000000
@@ -55,6 +56,7 @@ static const uint32_t uart_addr[MSF2_NUM_UARTS] = { 0x40000000 , 0x40010000 };static const int spi_irq[MSF2_NUM_SPIS ] = {2 ,3 };static const int uart_irq[MSF2_NUM_UARTS ] = {10 ,11 };static const int timer_irq[MSF2_NUM_TIMERS ] = {14 ,15 }; +static const int emac_irq[MSF2_NUM_EMACS ] = {12 };static void do_sys_reset (void *opaque,int n,int level) {
@@ -82,6 +84,13 @@ static void m2sxxx_soc_initfn(Object *obj) TYPE_MSS_SPI);qdev_set_parent_bus (DEVICE (&s->spi[i]),sysbus_get_default ()); } + +object_initialize (&s->emac,sizeof (s->emac),TYPE_MSS_EMAC ); +qdev_set_parent_bus (DEVICE (&s->emac),sysbus_get_default ()); +if (nd_table[0 ].used) { +qemu_check_nic_model (&nd_table[0 ],TYPE_MSS_EMAC ); +qdev_set_nic_properties (DEVICE (&s->emac), &nd_table[0 ]); + } }static void m2sxxx_soc_realize (DeviceState *dev_soc,Error **errp)
@@ -192,6 +201,17 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)g_free (bus_name); } + dev =DEVICE (&s->emac); +object_property_set_bool (OBJECT (&s->emac), true,"realized" , &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } + busdev =SYS_BUS_DEVICE (dev); +sysbus_mmio_map (busdev,0 ,MSF2_EMAC_BASE ); +sysbus_connect_irq (busdev,0 , +qdev_get_gpio_in (armv7m, emac_irq[0 ])); +/* Below devices are not modelled yet. */ create_unimplemented_device ("i2c_0" ,0x40002000 ,0x1000 );create_unimplemented_device ("dma" ,0x40003000 ,0x1000 );
@@ -202,7 +222,6 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)create_unimplemented_device ("can" ,0x40015000 ,0x1000 );create_unimplemented_device ("rtc" ,0x40017000 ,0x1000 );create_unimplemented_device ("apb_config" ,0x40020000 ,0x10000 ); -create_unimplemented_device ("emac" ,0x40041000 ,0x1000 );create_unimplemented_device ("usb" ,0x40043000 ,0x1000 ); }
hw/net/Makefile.objs +1 -0
@@ -48,3 +48,4 @@ common-obj-$(CONFIG_ROCKER) += rocker/rocker.o rocker/rocker_fp.o \ obj-$(call lnot,$(CONFIG_ROCKER)) += rocker/qmp-norocker.o common-obj-$(CONFIG_CAN_BUS) += can/ +common-obj-$(CONFIG_MSF2) += mss-emac.o
hw/net/mss-emac.c new file +544 -0
544 lines not on this page · raw message
include/hw/arm/msf2-soc.h +3 -0
@@ -29,12 +29,14 @@#include "hw/timer/mss-timer.h" #include "hw/misc/msf2-sysreg.h" #include "hw/ssi/mss-spi.h" +#include "hw/net/mss-emac.h" #define TYPE_MSF2_SOC "msf2-soc"#define MSF2_SOC (obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC)#define MSF2_NUM_SPIS 2#define MSF2_NUM_UARTS 2 +#define MSF2_NUM_EMACS 1/* * System timer consists of two programmable 32-bit
@@ -62,6 +64,7 @@ typedef struct MSF2State {MSF2SysregState sysreg;MSSTimerState timer;MSSSpiState spi[MSF2_NUM_SPIS ]; + MSSEmacState emac; } MSF2State;#endif
include/hw/net/mss-emac.h new file +23 -0
@@ -0,0 +1,23 @@ +#include "hw/sysbus.h" +#include "net/net.h" + +#define TYPE_MSS_EMAC "mss-emac" +#define MSS_EMAC (obj) \ + OBJECT_CHECK(MSSEmacState, (obj), TYPE_MSS_EMAC) + +#define R_MAX (0x1a0 / 4) + +typedef struct MSSEmacState { +SysBusDevice parent; + +MemoryRegion mmio; +qemu_irq irq; +NICState *nic; +NICConf conf; +uint32_t tx_desc; +uint32_t rx_desc; +bool rx_enabled; +uint16_t phy_regs[32 ]; + +uint32_t regs[R_MAX ]; +}MSSEmacState ;
Signature · 1 line
2.5.0