qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mark McLoughlin <markmc@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu-devel@nongnu.org, Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH 4/4] Make pci_nic_init() use qemu_setup_nic_model()
Date: Thu,  8 Jan 2009 14:47:49 +0000	[thread overview]
Message-ID: <1231426069-28321-4-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1231426069-28321-3-git-send-email-markmc@redhat.com>

Add a table of PCI NIC models to pass to qemu_setup_nic_model().

While we're at it, also add a corresponding table of NIC init
functions.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/mips_malta.c    |   17 ++++++--------
 hw/pc.c            |   26 ++++------------------
 hw/pci.c           |   60 ++++++++++++++++++++++++++++++---------------------
 hw/pci.h           |    3 +-
 hw/ppc440_bamboo.c |   11 ++-------
 hw/ppc_chrp.c      |    8 ++----
 hw/ppc_oldworld.c  |    7 +----
 hw/ppc_prep.c      |    2 +-
 hw/r2d.c           |    4 +-
 hw/realview.c      |    4 +--
 hw/sun4u.c         |    7 +----
 hw/versatilepb.c   |    4 +--
 12 files changed, 64 insertions(+), 89 deletions(-)

diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index 972c71c..3ca036b 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -487,19 +487,16 @@ static void audio_init (PCIBus *pci_bus)
 static void network_init (PCIBus *pci_bus)
 {
     int i;
-    NICInfo *nd;
 
     for(i = 0; i < nb_nics; i++) {
-        nd = &nd_table[i];
-        if (!nd->model) {
-            nd->model = "pcnet";
-        }
-        if (i == 0  && strcmp(nd->model, "pcnet") == 0) {
+        NICInfo *nd = &nd_table[i];
+        int devfn = -1;
+
+        if (i == 0 && (!nd->model || strcmp(nd->model, "pcnet") == 0))
             /* The malta board has a PCNet card using PCI SLOT 11 */
-            pci_nic_init(pci_bus, nd, 88);
-        } else {
-            pci_nic_init(pci_bus, nd, -1);
-        }
+            devfn = 88;
+
+        pci_nic_init(pci_bus, nd, devfn, "pcnet");
     }
 }
 
diff --git a/hw/pc.c b/hw/pc.c
index 64c08a4..6a1c8ec 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -764,7 +764,6 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
     PCIBus *pci_bus;
     int piix3_devfn = -1;
     CPUState *env;
-    NICInfo *nd;
     qemu_irq *cpu_irq;
     qemu_irq *i8259;
     int index;
@@ -1000,27 +999,12 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size,
     }
 
     for(i = 0; i < nb_nics; i++) {
-        nd = &nd_table[i];
-        if (!nd->model) {
-            if (pci_enabled) {
-                nd->model = "ne2k_pci";
-            } else {
-                nd->model = "ne2k_isa";
-            }
-        }
-        if (strcmp(nd->model, "ne2k_isa") == 0) {
+        NICInfo *nd = &nd_table[i];
+
+        if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
             pc_init_ne2k_isa(nd, i8259);
-        } else if (pci_enabled) {
-            if (strcmp(nd->model, "?") == 0)
-                fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n");
-            pci_nic_init(pci_bus, nd, -1);
-        } else if (strcmp(nd->model, "?") == 0) {
-            fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n");
-            exit(1);
-        } else {
-            fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model);
-            exit(1);
-        }
+        else
+            pci_nic_init(pci_bus, nd, -1, "ne2k_pci");
     }
 
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
diff --git a/hw/pci.c b/hw/pci.c
index 8252d21..bba50d0 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -652,33 +652,43 @@ void pci_info(void)
     pci_for_each_device(0, pci_info_device);
 }
 
+static const char * const pci_nic_models[] = {
+    "ne2k_pci",
+    "i82551",
+    "i82557b",
+    "i82559er",
+    "rtl8139",
+    "e1000",
+    "pcnet",
+    "virtio",
+    NULL
+};
+
+typedef void (*PCINICInitFn)(PCIBus *, NICInfo *, int);
+
+static PCINICInitFn pci_nic_init_fns[] = {
+    pci_ne2000_init,
+    pci_i82551_init,
+    pci_i82557b_init,
+    pci_i82559er_init,
+    pci_rtl8139_init,
+    pci_e1000_init,
+    pci_pcnet_init,
+    virtio_net_init,
+    NULL
+};
+
 /* Initialize a PCI NIC.  */
-void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn)
+void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
+                  const char *default_model)
 {
-    if (strcmp(nd->model, "ne2k_pci") == 0) {
-        pci_ne2000_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "i82551") == 0) {
-        pci_i82551_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "i82557b") == 0) {
-        pci_i82557b_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "i82559er") == 0) {
-        pci_i82559er_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "rtl8139") == 0) {
-        pci_rtl8139_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "e1000") == 0) {
-        pci_e1000_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "pcnet") == 0) {
-        pci_pcnet_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "virtio") == 0) {
-        virtio_net_init(bus, nd, devfn);
-    } else if (strcmp(nd->model, "?") == 0) {
-        fprintf(stderr, "qemu: Supported PCI NICs: i82551 i82557b i82559er"
-                        " ne2k_pci pcnet rtl8139 e1000 virtio\n");
-        exit (1);
-    } else {
-        fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model);
-        exit (1);
-    }
+    int i;
+
+    qemu_check_nic_model_list(nd, pci_nic_models, default_model);
+
+    for (i = 0; pci_nic_models[i]; i++)
+        if (strcmp(nd->model, pci_nic_models[i]) == 0)
+            pci_nic_init_fns[i](bus, nd, devfn);
 }
 
 typedef struct {
diff --git a/hw/pci.h b/hw/pci.h
index 3b1caf5..77a2a63 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -118,7 +118,8 @@ typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
 PCIBus *pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                          qemu_irq *pic, int devfn_min, int nirq);
 
-void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn);
+void pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
+                  const char *default_model);
 void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
 uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
 int pci_bus_num(PCIBus *s);
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index a6fc758..bc8a47b 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -90,7 +90,6 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,
                         const char *cpu_model)
 {
     unsigned int pci_irq_nrs[4] = { 28, 27, 26, 25 };
-    NICInfo *nd;
     PCIBus *pcibus;
     CPUState *env;
     uint64_t elf_entry;
@@ -118,13 +117,9 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,
 
         /* Register network interfaces. */
         for (i = 0; i < nb_nics; i++) {
-            nd = &nd_table[i];
-            if (!nd->model) {
-                /* There are no PCI NICs on the Bamboo board, but there are
-                 * PCI slots, so we can pick model whatever we want. */
-                nd->model = "e1000";
-            }
-            pci_nic_init(pcibus, nd, -1);
+            /* There are no PCI NICs on the Bamboo board, but there are
+             * PCI slots, so we can pick whatever default model we want. */
+            pci_nic_init(pcibus, &nd_table[i], -1, "e1000");
         }
     }
 
diff --git a/hw/ppc_chrp.c b/hw/ppc_chrp.c
index 5bdb805..dae5a1a 100644
--- a/hw/ppc_chrp.c
+++ b/hw/ppc_chrp.c
@@ -264,11 +264,9 @@ static void ppc_core99_init (ram_addr_t ram_size, int vga_ram_size,
 
     /* XXX: use Mac Serial port */
     serial_init(0x3f8, dummy_irq[4], 115200, serial_hds[0]);
-    for(i = 0; i < nb_nics; i++) {
-        if (!nd_table[i].model)
-            nd_table[i].model = "ne2k_pci";
-        pci_nic_init(pci_bus, &nd_table[i], -1);
-    }
+    for(i = 0; i < nb_nics; i++)
+        pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
+
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
         exit(1);
diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c
index 1d5e9d6..4a9f832 100644
--- a/hw/ppc_oldworld.c
+++ b/hw/ppc_oldworld.c
@@ -305,11 +305,8 @@ static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size,
     /* XXX: use Mac Serial port */
     serial_init(0x3f8, dummy_irq[4], 115200, serial_hds[0]);
 
-    for(i = 0; i < nb_nics; i++) {
-        if (!nd_table[i].model)
-            nd_table[i].model = "ne2k_pci";
-        pci_nic_init(pci_bus, &nd_table[i], -1);
-    }
+    for(i = 0; i < nb_nics; i++)
+        pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
 
     /* First IDE channel is a CMD646 on the PCI bus */
 
diff --git a/hw/ppc_prep.c b/hw/ppc_prep.c
index 571c48e..308b7af 100644
--- a/hw/ppc_prep.c
+++ b/hw/ppc_prep.c
@@ -675,7 +675,7 @@ static void ppc_prep_init (ram_addr_t ram_size, int vga_ram_size,
             || strcmp(nd_table[i].model, "ne2k_isa") == 0) {
             isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
         } else {
-            pci_nic_init(pci_bus, &nd_table[i], -1);
+            pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
         }
     }
 
diff --git a/hw/r2d.c b/hw/r2d.c
index 5d5eb1e..88853e7 100644
--- a/hw/r2d.c
+++ b/hw/r2d.c
@@ -230,9 +230,9 @@ static void r2d_init(ram_addr_t ram_size, int vga_ram_size,
         drives_table[drive_get_index(IF_IDE, 0, 0)].bdrv, NULL);
 
     /* NIC: rtl8139 on-board, and 2 slots. */
-    pci_rtl8139_init(pci, &nd_table[0], 2 << 3);
+    pci_nic_init(pci, &nd_table[0], 2 << 3, "rtl8139");
     for (i = 1; i < nb_nics; i++)
-        pci_nic_init(pci, &nd_table[i], -1);
+        pci_nic_init(pci, &nd_table[i], -1, "ne2k_pci");
 
     /* Todo: register on board registers */
     {
diff --git a/hw/realview.c b/hw/realview.c
index 5abbc16..e285338 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -126,9 +126,7 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size,
             smc91c111_init(nd, 0x4e000000, pic[28]);
             done_smc = 1;
         } else {
-            if (!nd->model)
-                nd->model = "rtl8139";
-            pci_nic_init(pci_bus, nd, -1);
+            pci_nic_init(pci_bus, nd, -1, "rtl8139");
         }
     }
 
diff --git a/hw/sun4u.c b/hw/sun4u.c
index b3ecc1e..9a6de32 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -488,11 +488,8 @@ static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size,
         }
     }
 
-    for(i = 0; i < nb_nics; i++) {
-        if (!nd_table[i].model)
-            nd_table[i].model = "ne2k_pci";
-        pci_nic_init(pci_bus, &nd_table[i], -1);
-    }
+    for(i = 0; i < nb_nics; i++)
+        pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
 
     irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
diff --git a/hw/versatilepb.c b/hw/versatilepb.c
index 38c040d..267aa42 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -199,9 +199,7 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size,
             smc91c111_init(nd, 0x10010000, sic[25]);
             done_smc = 1;
         } else {
-            if (!nd->model)
-                nd->model = "rtl8139";
-            pci_nic_init(pci_bus, nd, -1);
+            pci_nic_init(pci_bus, nd, -1, "rtl8139");
         }
     }
     if (usb_enabled) {
-- 
1.6.0.6

  reply	other threads:[~2009-01-08 14:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-07 17:42 [Qemu-devel] [6216] Add a model string to VLANClientState (Mark McLoughlin) Anthony Liguori
2009-01-07 19:23 ` Stefan Weil
2009-01-08 14:45   ` Mark McLoughlin
2009-01-08 14:47     ` [Qemu-devel] [PATCH 1/4] Add qemu_check_nic_model() and qemu_check_nic_model_list() Mark McLoughlin
2009-01-08 14:47       ` [Qemu-devel] [PATCH 2/4] Check NIC model in some NIC init functions Mark McLoughlin
2009-01-08 14:47         ` [Qemu-devel] [PATCH 3/4] Make virtio_net_init() return void Mark McLoughlin
2009-01-08 14:47           ` Mark McLoughlin [this message]
2009-01-13 19:25       ` [Qemu-devel] [PATCH 1/3] Check NIC model in some NIC init functions Mark McLoughlin
2009-01-13 19:25         ` [Qemu-devel] [PATCH 2/3] Make virtio_net_init() return void Mark McLoughlin
2009-01-13 19:25           ` [Qemu-devel] [PATCH 3/3] Make pci_nic_init() use qemu_setup_nic_model() Mark McLoughlin
2009-01-13 19:47         ` [Qemu-devel] Re: [PATCH 1/3] Check NIC model in some NIC init functions Anthony Liguori
2009-01-13 20:59           ` Sylvain Petreolle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1231426069-28321-4-git-send-email-markmc@redhat.com \
    --to=markmc@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).