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 2/4] Check NIC model in some NIC init functions
Date: Thu,  8 Jan 2009 14:47:47 +0000	[thread overview]
Message-ID: <1231426069-28321-2-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1231426069-28321-1-git-send-email-markmc@redhat.com>

Some NIC init functions are only called when that model is
the only valid model. In that case, it makes sense to use
qemu_check_nic_model() from the NIC init function itself.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
 hw/axis_dev88.c     |    5 +----
 hw/etraxfs.c        |    5 +----
 hw/etraxfs_eth.c    |    2 ++
 hw/integratorcp.c   |   14 ++------------
 hw/mcf5208.c        |   14 ++------------
 hw/mcf_fec.c        |    2 ++
 hw/mips_mipssim.c   |   16 +++-------------
 hw/mips_r4k.c       |   14 ++------------
 hw/mipsnet.c        |    2 ++
 hw/musicpal.c       |    2 ++
 hw/ne2000.c         |    2 ++
 hw/pcnet.c          |    2 ++
 hw/realview.c       |    8 +++++---
 hw/smc91c111.c      |    2 ++
 hw/stellaris.c      |    4 +---
 hw/stellaris_enet.c |    2 ++
 hw/sun4m.c          |   33 +++------------------------------
 hw/versatilepb.c    |    8 +++++---
 18 files changed, 41 insertions(+), 96 deletions(-)

diff --git a/hw/axis_dev88.c b/hw/axis_dev88.c
index f7bdd14..3f90fa5 100644
--- a/hw/axis_dev88.c
+++ b/hw/axis_dev88.c
@@ -303,12 +303,9 @@ void axisdev88_init (ram_addr_t ram_size, int vga_ram_size,
     }
 
     /* Add the two ethernet blocks.  */
-    nd_table[0].model = nd_table[0].model ? nd_table[0].model : "fseth";
     eth[0] = etraxfs_eth_init(&nd_table[0], env, pic->irq + 25, 0x30034000);
-    if (nb_nics > 1) {
-        nd_table[1].model = nd_table[1].model ? nd_table[1].model : "fseth";
+    if (nb_nics > 1)
         eth[1] = etraxfs_eth_init(&nd_table[1], env, pic->irq + 26, 0x30036000);
-    }
 
     /* The DMA Connector block is missing, hardwire things for now.  */
     etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]);
diff --git a/hw/etraxfs.c b/hw/etraxfs.c
index 01b5a6e..5cd56f3 100644
--- a/hw/etraxfs.c
+++ b/hw/etraxfs.c
@@ -94,12 +94,9 @@ void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size,
     }
 
     /* Add the two ethernet blocks.  */
-    nd_table[0].model = nd_table[0].model ? nd_table[0].model : "fseth";
     eth[0] = etraxfs_eth_init(&nd_table[0], env, pic->irq + 25, 0x30034000);
-    if (nb_nics > 1) {
-        nd_table[1].model = nd_table[1].model ? nd_table[1].model : "fseth";
+    if (nb_nics > 1)
         eth[1] = etraxfs_eth_init(&nd_table[1], env, pic->irq + 26, 0x30036000);
-    }
 
     /* The DMA Connector block is missing, hardwire things for now.  */
     etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]);
diff --git a/hw/etraxfs_eth.c b/hw/etraxfs_eth.c
index 239e0d8..23026ca 100644
--- a/hw/etraxfs_eth.c
+++ b/hw/etraxfs_eth.c
@@ -546,6 +546,8 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
 	struct etraxfs_dma_client *dma = NULL;	
 	struct fs_eth *eth = NULL;
 
+	qemu_check_nic_model(nd, "fseth");
+
 	dma = qemu_mallocz(sizeof *dma * 2);
 	if (!dma)
 		return NULL;
diff --git a/hw/integratorcp.c b/hw/integratorcp.c
index a2d3d43..fdbfe20 100644
--- a/hw/integratorcp.c
+++ b/hw/integratorcp.c
@@ -497,18 +497,8 @@ static void integratorcp_init(ram_addr_t ram_size, int vga_ram_size,
         exit(1);
     }
     pl181_init(0x1c000000, drives_table[sd].bdrv, pic[23], pic[24]);
-    if (nd_table[0].vlan) {
-        if (nd_table[0].model == NULL
-            || strcmp(nd_table[0].model, "smc91c111") == 0) {
-            smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
-        } else if (strcmp(nd_table[0].model, "?") == 0) {
-            fprintf(stderr, "qemu: Supported NICs: smc91c111\n");
-            exit (1);
-        } else {
-            fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
-            exit (1);
-        }
-    }
+    if (nd_table[0].vlan)
+        smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
     pl110_init(ds, 0xc0000000, pic[22], 0);
 
     integrator_binfo.ram_size = ram_size;
diff --git a/hw/mcf5208.c b/hw/mcf5208.c
index 71ba3fb..f06c25a 100644
--- a/hw/mcf5208.c
+++ b/hw/mcf5208.c
@@ -241,18 +241,8 @@ static void mcf5208evb_init(ram_addr_t ram_size, int vga_ram_size,
         fprintf(stderr, "Too many NICs\n");
         exit(1);
     }
-    if (nd_table[0].vlan) {
-        if (nd_table[0].model == NULL
-            || strcmp(nd_table[0].model, "mcf_fec") == 0) {
-            mcf_fec_init(&nd_table[0], 0xfc030000, pic + 36);
-        } else if (strcmp(nd_table[0].model, "?") == 0) {
-            fprintf(stderr, "qemu: Supported NICs: mcf_fec\n");
-            exit (1);
-        } else {
-            fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
-            exit (1);
-        }
-    }
+    if (nd_table[0].vlan)
+        mcf_fec_init(&nd_table[0], 0xfc030000, pic + 36);
 
     /*  0xfc000000 SCM.  */
     /*  0xfc004000 XBS.  */
diff --git a/hw/mcf_fec.c b/hw/mcf_fec.c
index 49ae69b..413c569 100644
--- a/hw/mcf_fec.c
+++ b/hw/mcf_fec.c
@@ -446,6 +446,8 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
     mcf_fec_state *s;
     int iomemtype;
 
+    qemu_check_nic_model(nd, "mcf_fec");
+
     s = (mcf_fec_state *)qemu_mallocz(sizeof(mcf_fec_state));
     s->irq = irq;
     iomemtype = cpu_register_io_memory(0, mcf_fec_readfn,
diff --git a/hw/mips_mipssim.c b/hw/mips_mipssim.c
index dc62f69..83f1a63 100644
--- a/hw/mips_mipssim.c
+++ b/hw/mips_mipssim.c
@@ -175,19 +175,9 @@ mips_mipssim_init (ram_addr_t ram_size, int vga_ram_size,
     if (serial_hds[0])
         serial_init(0x3f8, env->irq[4], 115200, serial_hds[0]);
 
-    if (nd_table[0].vlan) {
-        if (nd_table[0].model == NULL
-            || strcmp(nd_table[0].model, "mipsnet") == 0) {
-            /* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */
-            mipsnet_init(0x4200, env->irq[2], &nd_table[0]);
-        } else if (strcmp(nd_table[0].model, "?") == 0) {
-            fprintf(stderr, "qemu: Supported NICs: mipsnet\n");
-            exit (1);
-        } else {
-            fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
-            exit (1);
-        }
-    }
+    if (nd_table[0].vlan)
+        /* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */
+        mipsnet_init(0x4200, env->irq[2], &nd_table[0]);
 }
 
 QEMUMachine mips_mipssim_machine = {
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index 6551b02..c12ab54 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -247,18 +247,8 @@ void mips_r4k_init (ram_addr_t ram_size, int vga_ram_size,
     isa_vga_init(ds, phys_ram_base + ram_size, ram_size,
                  vga_ram_size);
 
-    if (nd_table[0].vlan) {
-        if (nd_table[0].model == NULL
-            || strcmp(nd_table[0].model, "ne2k_isa") == 0) {
-            isa_ne2000_init(0x300, i8259[9], &nd_table[0]);
-        } else if (strcmp(nd_table[0].model, "?") == 0) {
-            fprintf(stderr, "qemu: Supported NICs: ne2k_isa\n");
-            exit (1);
-        } else {
-            fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
-            exit (1);
-        }
-    }
+    if (nd_table[0].vlan)
+        isa_ne2000_init(0x300, i8259[9], &nd_table[0]);
 
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
diff --git a/hw/mipsnet.c b/hw/mipsnet.c
index 0eb4c1e..04ce322 100644
--- a/hw/mipsnet.c
+++ b/hw/mipsnet.c
@@ -236,6 +236,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
 {
     MIPSnetState *s;
 
+    qemu_check_nic_model(nd, "mipsnet");
+
     s = qemu_mallocz(sizeof(MIPSnetState));
     if (!s)
         return;
diff --git a/hw/musicpal.c b/hw/musicpal.c
index 1c932ec..f64bb1c 100644
--- a/hw/musicpal.c
+++ b/hw/musicpal.c
@@ -714,6 +714,8 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     mv88w8618_eth_state *s;
     int iomemtype;
 
+    qemu_check_nic_model(nd, "mv88w8618");
+
     s = qemu_mallocz(sizeof(mv88w8618_eth_state));
     if (!s)
         return;
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 200db90..a85730f 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -722,6 +722,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
 {
     NE2000State *s;
 
+    qemu_check_nic_model(nd, "ne2k_isa");
+
     s = qemu_mallocz(sizeof(NE2000State));
     if (!s)
         return;
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 102166e..6198968 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -2087,6 +2087,8 @@ void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque,
     PCNetState *d;
     int lance_io_memory;
 
+    qemu_check_nic_model(nd, "lance");
+
     d = qemu_mallocz(sizeof(PCNetState));
     if (!d)
         return;
diff --git a/hw/realview.c b/hw/realview.c
index a9d20ed..5abbc16 100644
--- a/hw/realview.c
+++ b/hw/realview.c
@@ -121,11 +121,13 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size,
     }
     for(n = 0; n < nb_nics; n++) {
         nd = &nd_table[n];
-        if (!nd->model)
-            nd->model = done_smc ? "rtl8139" : "smc91c111";
-        if (strcmp(nd->model, "smc91c111") == 0) {
+
+        if ((!nd->model && !done_smc) || strcmp(nd->model, "smc91c111") == 0) {
             smc91c111_init(nd, 0x4e000000, pic[28]);
+            done_smc = 1;
         } else {
+            if (!nd->model)
+                nd->model = "rtl8139";
             pci_nic_init(pci_bus, nd, -1);
         }
     }
diff --git a/hw/smc91c111.c b/hw/smc91c111.c
index 27a3158..f5b29a7 100644
--- a/hw/smc91c111.c
+++ b/hw/smc91c111.c
@@ -695,6 +695,8 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     smc91c111_state *s;
     int iomemtype;
 
+    qemu_check_nic_model(nd, "smc91c111");
+
     s = (smc91c111_state *)qemu_mallocz(sizeof(smc91c111_state));
     iomemtype = cpu_register_io_memory(0, smc91c111_readfn,
                                        smc91c111_writefn, s);
diff --git a/hw/stellaris.c b/hw/stellaris.c
index 703ef7e..7069518 100644
--- a/hw/stellaris.c
+++ b/hw/stellaris.c
@@ -1361,10 +1361,8 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
             pl022_init(0x40008000, pic[7], NULL, NULL);
         }
     }
-    if (board->dc4 & (1 << 28)) {
-        /* FIXME: Obey network model.  */
+    if (board->dc4 & (1 << 28))
         stellaris_enet_init(&nd_table[0], 0x40048000, pic[42]);
-    }
     if (board->peripherals & BP_GAMEPAD) {
         qemu_irq gpad_irq[5];
         static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d };
diff --git a/hw/stellaris_enet.c b/hw/stellaris_enet.c
index a5cd163..88c5620 100644
--- a/hw/stellaris_enet.c
+++ b/hw/stellaris_enet.c
@@ -389,6 +389,8 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
     stellaris_enet_state *s;
     int iomemtype;
 
+    qemu_check_nic_model(nd, "stellaris");
+
     s = (stellaris_enet_state *)qemu_mallocz(sizeof(stellaris_enet_state));
     iomemtype = cpu_register_io_memory(0, stellaris_enet_readfn,
                                        stellaris_enet_writefn, s);
diff --git a/hw/sun4m.c b/hw/sun4m.c
index e6a538a..c99ee1a 100644
--- a/hw/sun4m.c
+++ b/hw/sun4m.c
@@ -533,16 +533,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
     tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
              hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
 
-    if (nd_table[0].model == NULL
-        || strcmp(nd_table[0].model, "lance") == 0) {
-        lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
-    } else if (strcmp(nd_table[0].model, "?") == 0) {
-        fprintf(stderr, "qemu: Supported NICs: lance\n");
-        exit (1);
-    } else {
-        fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
-        exit (1);
-    }
+    lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
 
     nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
                         hwdef->nvram_size, 8);
@@ -1325,16 +1316,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
     tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
              hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
 
-    if (nd_table[0].model == NULL
-        || strcmp(nd_table[0].model, "lance") == 0) {
-        lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
-    } else if (strcmp(nd_table[0].model, "?") == 0) {
-        fprintf(stderr, "qemu: Supported NICs: lance\n");
-        exit (1);
-    } else {
-        fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
-        exit (1);
-    }
+    lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
 
     nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
                         hwdef->nvram_size, 8);
@@ -1540,16 +1522,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
     tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
              hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
 
-    if (nd_table[0].model == NULL
-        || strcmp(nd_table[0].model, "lance") == 0) {
-        lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
-    } else if (strcmp(nd_table[0].model, "?") == 0) {
-        fprintf(stderr, "qemu: Supported NICs: lance\n");
-        exit (1);
-    } else {
-        fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
-        exit (1);
-    }
+    lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
 
     nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
                         hwdef->nvram_size, 2);
diff --git a/hw/versatilepb.c b/hw/versatilepb.c
index e5d02f2..38c040d 100644
--- a/hw/versatilepb.c
+++ b/hw/versatilepb.c
@@ -194,11 +194,13 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size,
        so many of the qemu PCI devices are not useable.  */
     for(n = 0; n < nb_nics; n++) {
         nd = &nd_table[n];
-        if (!nd->model)
-            nd->model = done_smc ? "rtl8139" : "smc91c111";
-        if (strcmp(nd->model, "smc91c111") == 0) {
+
+        if ((!nd->model && !done_smc) || strcmp(nd->model, "smc91c111") == 0) {
             smc91c111_init(nd, 0x10010000, sic[25]);
+            done_smc = 1;
         } else {
+            if (!nd->model)
+                nd->model = "rtl8139";
             pci_nic_init(pci_bus, nd, -1);
         }
     }
-- 
1.6.0.6

  reply	other threads:[~2009-01-08 14:47 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       ` Mark McLoughlin [this message]
2009-01-08 14:47         ` [Qemu-devel] [PATCH 3/4] Make virtio_net_init() return void Mark McLoughlin
2009-01-08 14:47           ` [Qemu-devel] [PATCH 4/4] Make pci_nic_init() use qemu_setup_nic_model() Mark McLoughlin
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-2-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).