diff mbox series

[v3,16/46] hw/ppc/spapr: use qemu_get_nic_info() and pci_init_nic_devices()

Message ID 20240108204909.564514-17-dwmw2@infradead.org
State Handled Elsewhere
Headers show
Series Rework matching of network devices to -nic options | expand

Commit Message

David Woodhouse Jan. 8, 2024, 8:26 p.m. UTC
From: David Woodhouse <dwmw@amazon.co.uk>

Avoid directly referencing nd_table[] by first instantiating any
spapr-vlan devices using a qemu_get_nic_info() loop, then calling
pci_init_nic_devices() to do the rest.

No functional change intended.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
 hw/ppc/spapr.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

Comments

Thomas Huth Jan. 26, 2024, 2:09 p.m. UTC | #1
On 08/01/2024 21.26, David Woodhouse wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
> 
> Avoid directly referencing nd_table[] by first instantiating any
> spapr-vlan devices using a qemu_get_nic_info() loop, then calling
> pci_init_nic_devices() to do the rest.
> 
> No functional change intended.
> 
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> ---
>   hw/ppc/spapr.c | 18 +++++-------------
>   1 file changed, 5 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 4997aa4f1d..37604e7caf 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -2796,6 +2796,7 @@ static void spapr_machine_init(MachineState *machine)
>       MemoryRegion *sysmem = get_system_memory();
>       long load_limit, fw_size;
>       Error *resize_hpt_err = NULL;
> +    NICInfo *nd;
>   
>       if (!filename) {
>           error_report("Could not find LPAR firmware '%s'", bios_name);
> @@ -2996,21 +2997,12 @@ static void spapr_machine_init(MachineState *machine)
>   
>       phb = spapr_create_default_phb();
>   
> -    for (i = 0; i < nb_nics; i++) {
> -        NICInfo *nd = &nd_table[i];
> -
> -        if (!nd->model) {
> -            nd->model = g_strdup("spapr-vlan");
> -        }
> -
> -        if (g_str_equal(nd->model, "spapr-vlan") ||
> -            g_str_equal(nd->model, "ibmveth")) {
> -            spapr_vlan_create(spapr->vio_bus, nd);
> -        } else {
> -            pci_nic_init_nofail(&nd_table[i], phb->bus, nd->model, NULL);
> -        }
> +    while ((nd = qemu_find_nic_info("spapr-vlan", true, "ibmveth"))) {
> +        spapr_vlan_create(spapr->vio_bus, nd);
>       }
>   
> +    pci_init_nic_devices(phb->bus, NULL);
> +
>       for (i = 0; i <= drive_get_max_bus(IF_SCSI); i++) {
>           spapr_vscsi_create(spapr->vio_bus);
>       }

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

Patch

diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 4997aa4f1d..37604e7caf 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -2796,6 +2796,7 @@  static void spapr_machine_init(MachineState *machine)
     MemoryRegion *sysmem = get_system_memory();
     long load_limit, fw_size;
     Error *resize_hpt_err = NULL;
+    NICInfo *nd;
 
     if (!filename) {
         error_report("Could not find LPAR firmware '%s'", bios_name);
@@ -2996,21 +2997,12 @@  static void spapr_machine_init(MachineState *machine)
 
     phb = spapr_create_default_phb();
 
-    for (i = 0; i < nb_nics; i++) {
-        NICInfo *nd = &nd_table[i];
-
-        if (!nd->model) {
-            nd->model = g_strdup("spapr-vlan");
-        }
-
-        if (g_str_equal(nd->model, "spapr-vlan") ||
-            g_str_equal(nd->model, "ibmveth")) {
-            spapr_vlan_create(spapr->vio_bus, nd);
-        } else {
-            pci_nic_init_nofail(&nd_table[i], phb->bus, nd->model, NULL);
-        }
+    while ((nd = qemu_find_nic_info("spapr-vlan", true, "ibmveth"))) {
+        spapr_vlan_create(spapr->vio_bus, nd);
     }
 
+    pci_init_nic_devices(phb->bus, NULL);
+
     for (i = 0; i <= drive_get_max_bus(IF_SCSI); i++) {
         spapr_vscsi_create(spapr->vio_bus);
     }