[PATCH v3 21/46] hw/arm/allwinner: use qemu_configure_nic_device()

David Woodhouse posted 46 patches 10 months, 3 weeks ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Beniamino Galvani <b.galvani@gmail.com>, Peter Maydell <peter.maydell@linaro.org>, Strahinja Jankovic <strahinja.p.jankovic@gmail.com>, Niek Linnenbank <nieklinnenbank@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, Andrew Jeffery <andrew@codeconstruct.com.au>, Joel Stanley <joel@jms.id.au>, Igor Mitsyanko <i.mitsyanko@gmail.com>, Jean-Christophe Dubois <jcd@tribudubois.net>, Andrey Smirnov <andrew.smirnov@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Rob Herring <robh@kernel.org>, Subbaraya Sundeep <sundeep.lkml@gmail.com>, Jan Kiszka <jan.kiszka@web.de>, Tyrone Ting <kfting@nuvoton.com>, Hao Wu <wuhaotsh@google.com>, Radoslaw Biernacki <rad@semihalf.com>, Leif Lindholm <quic_llindhol@quicinc.com>, Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Helge Deller <deller@gmx.de>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Song Gao <gaosong@loongson.cn>, Thomas Huth <huth@tuxfamily.org>, Laurent Vivier <laurent@vivier.eu>, Huacai Chen <chenhuacai@kernel.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Aurelien Jarno <aurelien@aurel32.net>, Jason Wang <jasowang@redhat.com>, Jia Liu <proljc@gmail.com>, Stafford Horne <shorne@gmail.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, David Gibson <david@gibson.dropbear.id.au>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Bin Meng <bin.meng@windriver.com>, Palmer Dabbelt <palmer@dabbelt.com>, Weiwei Li <liwei1518@gmail.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Magnus Damm <magnus.damm@gmail.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony Perard <anthony.perard@citrix.com>, Paul Durrant <paul@xen.org>, Max Filippov <jcmvbkbc@gmail.com>
There is a newer version of this series
[PATCH v3 21/46] hw/arm/allwinner: use qemu_configure_nic_device()
Posted by David Woodhouse 10 months, 3 weeks ago
From: David Woodhouse <dwmw@amazon.co.uk>

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 hw/arm/allwinner-a10.c |  6 +-----
 hw/arm/allwinner-h3.c  |  6 +-----
 hw/arm/allwinner-r40.c | 27 ++-------------------------
 3 files changed, 4 insertions(+), 35 deletions(-)

diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
index b0ea3f7f66..57f52871ec 100644
--- a/hw/arm/allwinner-a10.c
+++ b/hw/arm/allwinner-a10.c
@@ -142,11 +142,7 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
     sysbus_realize(SYS_BUS_DEVICE(&s->dramc), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 0, AW_A10_DRAMC_BASE);
 
-    /* FIXME use qdev NIC properties instead of nd_table[] */
-    if (nd_table[0].used) {
-        qemu_check_nic_model(&nd_table[0], TYPE_AW_EMAC);
-        qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
-    }
+    qemu_configure_nic_device(DEVICE(&s->emac), true, NULL);
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->emac), errp)) {
         return;
     }
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index f05afddf7e..4f102ad082 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -369,11 +369,7 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
                               "sd-bus");
 
     /* EMAC */
-    /* FIXME use qdev NIC properties instead of nd_table[] */
-    if (nd_table[0].used) {
-        qemu_check_nic_model(&nd_table[0], TYPE_AW_SUN8I_EMAC);
-        qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
-    }
+    qemu_configure_nic_device(DEVICE(&s->emac), true, NULL);
     object_property_set_link(OBJECT(&s->emac), "dma-memory",
                              OBJECT(get_system_memory()), &error_fatal);
     sysbus_realize(SYS_BUS_DEVICE(&s->emac), &error_fatal);
diff --git a/hw/arm/allwinner-r40.c b/hw/arm/allwinner-r40.c
index a0d367c60d..4d5661b014 100644
--- a/hw/arm/allwinner-r40.c
+++ b/hw/arm/allwinner-r40.c
@@ -294,7 +294,6 @@ static void allwinner_r40_init(Object *obj)
 
 static void allwinner_r40_realize(DeviceState *dev, Error **errp)
 {
-    const char *r40_nic_models[] = { "gmac", "emac", NULL };
     AwR40State *s = AW_R40(dev);
 
     /* CPUs */
@@ -454,31 +453,8 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 2,
                     s->memmap[AW_R40_DEV_DRAMPHY]);
 
-    /* nic support gmac and emac */
-    for (int i = 0; i < ARRAY_SIZE(r40_nic_models) - 1; i++) {
-        NICInfo *nic = &nd_table[i];
-
-        if (!nic->used) {
-            continue;
-        }
-        if (qemu_show_nic_models(nic->model, r40_nic_models)) {
-            exit(0);
-        }
-
-        switch (qemu_find_nic_model(nic, r40_nic_models, r40_nic_models[0])) {
-        case 0: /* gmac */
-            qdev_set_nic_properties(DEVICE(&s->gmac), nic);
-            break;
-        case 1: /* emac */
-            qdev_set_nic_properties(DEVICE(&s->emac), nic);
-            break;
-        default:
-            exit(1);
-            break;
-        }
-    }
-
     /* GMAC */
+    qemu_configure_nic_device(DEVICE(&s->gmac), true, "gmac");
     object_property_set_link(OBJECT(&s->gmac), "dma-memory",
                                      OBJECT(get_system_memory()), &error_fatal);
     sysbus_realize(SYS_BUS_DEVICE(&s->gmac), &error_fatal);
@@ -487,6 +463,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
                        qdev_get_gpio_in(DEVICE(&s->gic), AW_R40_GIC_SPI_GMAC));
 
     /* EMAC */
+    qemu_configure_nic_device(DEVICE(&s->emac), true, "emac");
     sysbus_realize(SYS_BUS_DEVICE(&s->emac), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->emac), 0, s->memmap[AW_R40_DEV_EMAC]);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,
-- 
2.41.0
Re: [PATCH v3 21/46] hw/arm/allwinner: use qemu_configure_nic_device()
Posted by Thomas Huth 10 months ago
On 08/01/2024 21.26, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
> 
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
>   hw/arm/allwinner-a10.c |  6 +-----
>   hw/arm/allwinner-h3.c  |  6 +-----
>   hw/arm/allwinner-r40.c | 27 ++-------------------------
>   3 files changed, 4 insertions(+), 35 deletions(-)
> 
> diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
> index b0ea3f7f66..57f52871ec 100644
> --- a/hw/arm/allwinner-a10.c
> +++ b/hw/arm/allwinner-a10.c
> @@ -142,11 +142,7 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
>       sysbus_realize(SYS_BUS_DEVICE(&s->dramc), &error_fatal);
>       sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 0, AW_A10_DRAMC_BASE);
>   
> -    /* FIXME use qdev NIC properties instead of nd_table[] */
> -    if (nd_table[0].used) {
> -        qemu_check_nic_model(&nd_table[0], TYPE_AW_EMAC);
> -        qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
> -    }
> +    qemu_configure_nic_device(DEVICE(&s->emac), true, NULL);
>       if (!sysbus_realize(SYS_BUS_DEVICE(&s->emac), errp)) {
>           return;
>       }
> diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
> index f05afddf7e..4f102ad082 100644
> --- a/hw/arm/allwinner-h3.c
> +++ b/hw/arm/allwinner-h3.c
> @@ -369,11 +369,7 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
>                                 "sd-bus");
>   
>       /* EMAC */
> -    /* FIXME use qdev NIC properties instead of nd_table[] */
> -    if (nd_table[0].used) {
> -        qemu_check_nic_model(&nd_table[0], TYPE_AW_SUN8I_EMAC);
> -        qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
> -    }
> +    qemu_configure_nic_device(DEVICE(&s->emac), true, NULL);
>       object_property_set_link(OBJECT(&s->emac), "dma-memory",
>                                OBJECT(get_system_memory()), &error_fatal);
>       sysbus_realize(SYS_BUS_DEVICE(&s->emac), &error_fatal);
> diff --git a/hw/arm/allwinner-r40.c b/hw/arm/allwinner-r40.c
> index a0d367c60d..4d5661b014 100644
> --- a/hw/arm/allwinner-r40.c
> +++ b/hw/arm/allwinner-r40.c
> @@ -294,7 +294,6 @@ static void allwinner_r40_init(Object *obj)
>   
>   static void allwinner_r40_realize(DeviceState *dev, Error **errp)
>   {
> -    const char *r40_nic_models[] = { "gmac", "emac", NULL };
>       AwR40State *s = AW_R40(dev);
>   
>       /* CPUs */
> @@ -454,31 +453,8 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
>       sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 2,
>                       s->memmap[AW_R40_DEV_DRAMPHY]);
>   
> -    /* nic support gmac and emac */
> -    for (int i = 0; i < ARRAY_SIZE(r40_nic_models) - 1; i++) {
> -        NICInfo *nic = &nd_table[i];
> -
> -        if (!nic->used) {
> -            continue;
> -        }
> -        if (qemu_show_nic_models(nic->model, r40_nic_models)) {
> -            exit(0);
> -        }
> -
> -        switch (qemu_find_nic_model(nic, r40_nic_models, r40_nic_models[0])) {
> -        case 0: /* gmac */
> -            qdev_set_nic_properties(DEVICE(&s->gmac), nic);
> -            break;
> -        case 1: /* emac */
> -            qdev_set_nic_properties(DEVICE(&s->emac), nic);
> -            break;
> -        default:
> -            exit(1);
> -            break;
> -        }
> -    }
> -
>       /* GMAC */
> +    qemu_configure_nic_device(DEVICE(&s->gmac), true, "gmac");
>       object_property_set_link(OBJECT(&s->gmac), "dma-memory",
>                                        OBJECT(get_system_memory()), &error_fatal);
>       sysbus_realize(SYS_BUS_DEVICE(&s->gmac), &error_fatal);
> @@ -487,6 +463,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
>                          qdev_get_gpio_in(DEVICE(&s->gic), AW_R40_GIC_SPI_GMAC));
>   
>       /* EMAC */
> +    qemu_configure_nic_device(DEVICE(&s->emac), true, "emac");
>       sysbus_realize(SYS_BUS_DEVICE(&s->emac), &error_fatal);
>       sysbus_mmio_map(SYS_BUS_DEVICE(&s->emac), 0, s->memmap[AW_R40_DEV_EMAC]);
>       sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,

Reviewed-by: Thomas Huth <thuth@redhat.com>