Re: [Qemu-devel] [[Qemu devel] RFC] hw/net: Add Smartfusion2 emac block
Hi Peter, On Tue, May 29, 2018 at 10:13 PM, Peter Maydell wrote: > On 26 May 2018 at 10:51, Subbaraya Sundeep wrote: >> 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 > > Hi; thanks for this patch. I have some review comments, but they're > fairly minor things; this generally looks good. I think you could > drop the RFC tag for your next version. > >> --- >> 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 ++ > > I think it would be better to split this into two patches, where > patch 1 implements the new device, and then patch 2 adds an > instance of that device to the msf2-soc. (For multi-patch sets, > remember to include a cover letter.) Ok I will split into multiple patches. > >> 5 files changed, 591 insertions(+), 1 deletion(-) >> create mode 100644 hw/net/mss-emac.c >> create mode 100644 include/hw/net/mss-emac.h >> >> diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c >> index 75c44ad..ed3d0f5 100644 >> --- a/hw/arm/msf2-soc.c >> +++ b/hw/arm/msf2-soc.c >> @@ -35,6 +35,7 @@ >> >> #define MSF2_TIMER_BASE 0x40004000 >> #define MSF2_SYSREG_BASE 0x40038000 >> +#define MSF2_EMAC_BASE0x40041000 >> >> #define ENVM_BASE_ADDRESS 0x6000 >> >> @@ -55,6 +56,7 @@ static const uint32_t uart_addr[MSF2_NUM_UARTS] = { >> 0x4000 , 0x4001 }; >> 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", 0x4002, 0x1); >> -create_unimplemented_device("emac", 0x40041000, 0x1000); >> create_unimplemented_device("usb", 0x40043000, 0x1000); >> } >> >> diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs >> index ab22968..d9b4cae 100644 >> --- a/hw/net/Makefile.objs >> +++ b/hw/net/Makefile.objs >> @@ -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 >> diff --git a/hw/net/mss-emac.c b/hw/net/mss-emac.c >> new file mode 100644 >> index 000..a9588c0 >> --- /dev/null >> +++ b/hw/net/mss-emac.c >> @@ -0,0 +1,544 @@ >> +/* >> + * QEMU model of the Smartfusion2 Ethernet MAC. >> + * >> + * Copyright (c) 2018 Subbaraya Sundeep . >> + * >> + * 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 >> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell >> + * copies of the Software, and to permit persons to whom the Software is >> + * furnished to do so, subject to the following conditions: >> + * >> + * The above copyright notice and this permission notice shall be included >> in >> + * all copies or substantial portions of the Software. >> + * >> + * THE
Re: [Qemu-devel] [[Qemu devel] RFC] hw/net: Add Smartfusion2 emac block
Hi Philippe, On Sun, May 27, 2018 at 8:56 AM, Philippe Mathieu-Daudé wrote: > On 05/26/2018 06:53 AM, Subbaraya Sundeep wrote: >> 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 >> --- >> 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 >> >> diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c >> index 75c44ad..ed3d0f5 100644 >> --- a/hw/arm/msf2-soc.c >> +++ b/hw/arm/msf2-soc.c >> @@ -35,6 +35,7 @@ >> >> #define MSF2_TIMER_BASE 0x40004000 >> #define MSF2_SYSREG_BASE 0x40038000 >> +#define MSF2_EMAC_BASE0x40041000 >> >> #define ENVM_BASE_ADDRESS 0x6000 >> >> @@ -55,6 +56,7 @@ static const uint32_t uart_addr[MSF2_NUM_UARTS] = { >> 0x4000 , 0x4001 }; >> 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", 0x4002, 0x1); >> -create_unimplemented_device("emac", 0x40041000, 0x1000); >> create_unimplemented_device("usb", 0x40043000, 0x1000); >> } >> >> diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs >> index ab22968..d9b4cae 100644 >> --- a/hw/net/Makefile.objs >> +++ b/hw/net/Makefile.objs >> @@ -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 >> diff --git a/hw/net/mss-emac.c b/hw/net/mss-emac.c >> new file mode 100644 >> index 000..a9588c0 >> --- /dev/null >> +++ b/hw/net/mss-emac.c >> @@ -0,0 +1,544 @@ >> +/* >> + * QEMU model of the Smartfusion2 Ethernet MAC. >> + * >> + * Copyright (c) 2018 Subbaraya Sundeep . >> + * >> + * 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 >> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell >> + * copies of the Software, and to permit persons to whom the Software is >> + * furnished to do so, subject to the following conditions: >> + * >> + * The above copyright notice and this permission notice shall be included >> in >> + * all copies or substantial portions of the Software. >> + * >> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS >> OR >> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, >> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL >> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR >> OTHER >> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING >> FROM, >> + * OUT OF OR IN CONNECTION WITH THE SOF
Re: [Qemu-devel] [[Qemu devel] RFC] hw/net: Add Smartfusion2 emac block
On 26 May 2018 at 10:51, Subbaraya Sundeep wrote: > 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 Hi; thanks for this patch. I have some review comments, but they're fairly minor things; this generally looks good. I think you could drop the RFC tag for your next version. > --- > 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 ++ I think it would be better to split this into two patches, where patch 1 implements the new device, and then patch 2 adds an instance of that device to the msf2-soc. (For multi-patch sets, remember to include a cover letter.) > 5 files changed, 591 insertions(+), 1 deletion(-) > create mode 100644 hw/net/mss-emac.c > create mode 100644 include/hw/net/mss-emac.h > > diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c > index 75c44ad..ed3d0f5 100644 > --- a/hw/arm/msf2-soc.c > +++ b/hw/arm/msf2-soc.c > @@ -35,6 +35,7 @@ > > #define MSF2_TIMER_BASE 0x40004000 > #define MSF2_SYSREG_BASE 0x40038000 > +#define MSF2_EMAC_BASE0x40041000 > > #define ENVM_BASE_ADDRESS 0x6000 > > @@ -55,6 +56,7 @@ static const uint32_t uart_addr[MSF2_NUM_UARTS] = { > 0x4000 , 0x4001 }; > 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", 0x4002, 0x1); > -create_unimplemented_device("emac", 0x40041000, 0x1000); > create_unimplemented_device("usb", 0x40043000, 0x1000); > } > > diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs > index ab22968..d9b4cae 100644 > --- a/hw/net/Makefile.objs > +++ b/hw/net/Makefile.objs > @@ -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 > diff --git a/hw/net/mss-emac.c b/hw/net/mss-emac.c > new file mode 100644 > index 000..a9588c0 > --- /dev/null > +++ b/hw/net/mss-emac.c > @@ -0,0 +1,544 @@ > +/* > + * QEMU model of the Smartfusion2 Ethernet MAC. > + * > + * Copyright (c) 2018 Subbaraya Sundeep . > + * > + * 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 > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell > + * copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE AUTHOR
Re: [Qemu-devel] [[Qemu devel] RFC] hw/net: Add Smartfusion2 emac block
On 05/26/2018 06:53 AM, Subbaraya Sundeep wrote: > 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 > --- > 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 > > diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c > index 75c44ad..ed3d0f5 100644 > --- a/hw/arm/msf2-soc.c > +++ b/hw/arm/msf2-soc.c > @@ -35,6 +35,7 @@ > > #define MSF2_TIMER_BASE 0x40004000 > #define MSF2_SYSREG_BASE 0x40038000 > +#define MSF2_EMAC_BASE0x40041000 > > #define ENVM_BASE_ADDRESS 0x6000 > > @@ -55,6 +56,7 @@ static const uint32_t uart_addr[MSF2_NUM_UARTS] = { > 0x4000 , 0x4001 }; > 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", 0x4002, 0x1); > -create_unimplemented_device("emac", 0x40041000, 0x1000); > create_unimplemented_device("usb", 0x40043000, 0x1000); > } > > diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs > index ab22968..d9b4cae 100644 > --- a/hw/net/Makefile.objs > +++ b/hw/net/Makefile.objs > @@ -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 > diff --git a/hw/net/mss-emac.c b/hw/net/mss-emac.c > new file mode 100644 > index 000..a9588c0 > --- /dev/null > +++ b/hw/net/mss-emac.c > @@ -0,0 +1,544 @@ > +/* > + * QEMU model of the Smartfusion2 Ethernet MAC. > + * > + * Copyright (c) 2018 Subbaraya Sundeep . > + * > + * 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 > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell > + * copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > FROM, > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN > + * THE SOFTWARE. > + */ > + > +#include "qemu/osdep.h" > +#include "qemu-common.h" > +#include "qemu/log.h" > +#include "hw/net/mss-emac.h" > +#include "
[Qemu-devel] [[Qemu devel] 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 --- 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 diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c index 75c44ad..ed3d0f5 100644 --- a/hw/arm/msf2-soc.c +++ b/hw/arm/msf2-soc.c @@ -35,6 +35,7 @@ #define MSF2_TIMER_BASE 0x40004000 #define MSF2_SYSREG_BASE 0x40038000 +#define MSF2_EMAC_BASE0x40041000 #define ENVM_BASE_ADDRESS 0x6000 @@ -55,6 +56,7 @@ static const uint32_t uart_addr[MSF2_NUM_UARTS] = { 0x4000 , 0x4001 }; 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", 0x4002, 0x1); -create_unimplemented_device("emac", 0x40041000, 0x1000); create_unimplemented_device("usb", 0x40043000, 0x1000); } diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs index ab22968..d9b4cae 100644 --- a/hw/net/Makefile.objs +++ b/hw/net/Makefile.objs @@ -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 diff --git a/hw/net/mss-emac.c b/hw/net/mss-emac.c new file mode 100644 index 000..a9588c0 --- /dev/null +++ b/hw/net/mss-emac.c @@ -0,0 +1,544 @@ +/* + * QEMU model of the Smartfusion2 Ethernet MAC. + * + * Copyright (c) 2018 Subbaraya Sundeep . + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/log.h" +#include "hw/net/mss-emac.h" +#include "hw/net/mii.h" + +#define R_CFG1 (0x0 / 4) +#define R_CFG2 (0x4 / 4) +#define R_IFG (0x8 / 4) +#define R_HALF_DUPLEX (0xc / 4) +#define R_FRM_LEN (0x10 / 4) +#define R_MII_CFG (0x20 / 4) +#define R_MII_CMD
[Qemu-devel] [[Qemu devel] 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 --- 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 diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c index 75c44ad..ed3d0f5 100644 --- a/hw/arm/msf2-soc.c +++ b/hw/arm/msf2-soc.c @@ -35,6 +35,7 @@ #define MSF2_TIMER_BASE 0x40004000 #define MSF2_SYSREG_BASE 0x40038000 +#define MSF2_EMAC_BASE0x40041000 #define ENVM_BASE_ADDRESS 0x6000 @@ -55,6 +56,7 @@ static const uint32_t uart_addr[MSF2_NUM_UARTS] = { 0x4000 , 0x4001 }; 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", 0x4002, 0x1); -create_unimplemented_device("emac", 0x40041000, 0x1000); create_unimplemented_device("usb", 0x40043000, 0x1000); } diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs index ab22968..d9b4cae 100644 --- a/hw/net/Makefile.objs +++ b/hw/net/Makefile.objs @@ -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 diff --git a/hw/net/mss-emac.c b/hw/net/mss-emac.c new file mode 100644 index 000..a9588c0 --- /dev/null +++ b/hw/net/mss-emac.c @@ -0,0 +1,544 @@ +/* + * QEMU model of the Smartfusion2 Ethernet MAC. + * + * Copyright (c) 2018 Subbaraya Sundeep . + * + * 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 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/log.h" +#include "hw/net/mss-emac.h" +#include "hw/net/mii.h" + +#define R_CFG1 (0x0 / 4) +#define R_CFG2 (0x4 / 4) +#define R_IFG (0x8 / 4) +#define R_HALF_DUPLEX (0xc / 4) +#define R_FRM_LEN (0x10 / 4) +#define R_MII_CFG (0x20 / 4) +#define R_MII_CMD