Commit 0ae18ceeaaa2c1749e742c4b112f6c3bf0896408

Authored by aliguori
1 parent 973cbd37

Check NIC model in some NIC init functions (Mark McLoughlin)

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>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6286 c046a42c-6fe2-441c-8c8c-71466251a162
hw/axis_dev88.c
@@ -303,13 +303,10 @@ void axisdev88_init (ram_addr_t ram_size, int vga_ram_size, @@ -303,13 +303,10 @@ void axisdev88_init (ram_addr_t ram_size, int vga_ram_size,
303 } 303 }
304 304
305 /* Add the two ethernet blocks. */ 305 /* Add the two ethernet blocks. */
306 - nd_table[0].model = nd_table[0].model ? nd_table[0].model : "fseth";  
307 eth[0] = etraxfs_eth_init(&nd_table[0], env, pic->irq + 25, 0x30034000, 1); 306 eth[0] = etraxfs_eth_init(&nd_table[0], env, pic->irq + 25, 0x30034000, 1);
308 - if (nb_nics > 1) {  
309 - nd_table[1].model = nd_table[1].model ? nd_table[1].model : "fseth"; 307 + if (nb_nics > 1)
310 eth[1] = etraxfs_eth_init(&nd_table[1], env, 308 eth[1] = etraxfs_eth_init(&nd_table[1], env,
311 pic->irq + 26, 0x30036000, 2); 309 pic->irq + 26, 0x30036000, 2);
312 - }  
313 310
314 /* The DMA Connector block is missing, hardwire things for now. */ 311 /* The DMA Connector block is missing, hardwire things for now. */
315 etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]); 312 etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]);
hw/etraxfs.c
@@ -94,13 +94,10 @@ void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size, @@ -94,13 +94,10 @@ void bareetraxfs_init (ram_addr_t ram_size, int vga_ram_size,
94 } 94 }
95 95
96 /* Add the two ethernet blocks. */ 96 /* Add the two ethernet blocks. */
97 - nd_table[0].model = nd_table[0].model ? nd_table[0].model : "fseth";  
98 eth[0] = etraxfs_eth_init(&nd_table[0], env, pic->irq + 25, 0x30034000, 1); 97 eth[0] = etraxfs_eth_init(&nd_table[0], env, pic->irq + 25, 0x30034000, 1);
99 - if (nb_nics > 1) {  
100 - nd_table[1].model = nd_table[1].model ? nd_table[1].model : "fseth"; 98 + if (nb_nics > 1)
101 eth[1] = etraxfs_eth_init(&nd_table[1], env, 99 eth[1] = etraxfs_eth_init(&nd_table[1], env,
102 pic->irq + 26, 0x30036000, 2); 100 pic->irq + 26, 0x30036000, 2);
103 - }  
104 101
105 /* The DMA Connector block is missing, hardwire things for now. */ 102 /* The DMA Connector block is missing, hardwire things for now. */
106 etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]); 103 etraxfs_dmac_connect_client(etraxfs_dmac, 0, eth[0]);
hw/etraxfs_eth.c
@@ -561,6 +561,8 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env, @@ -561,6 +561,8 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
561 struct etraxfs_dma_client *dma = NULL; 561 struct etraxfs_dma_client *dma = NULL;
562 struct fs_eth *eth = NULL; 562 struct fs_eth *eth = NULL;
563 563
  564 + qemu_check_nic_model(nd, "fseth");
  565 +
564 dma = qemu_mallocz(sizeof *dma * 2); 566 dma = qemu_mallocz(sizeof *dma * 2);
565 if (!dma) 567 if (!dma)
566 return NULL; 568 return NULL;
hw/integratorcp.c
@@ -497,18 +497,8 @@ static void integratorcp_init(ram_addr_t ram_size, int vga_ram_size, @@ -497,18 +497,8 @@ static void integratorcp_init(ram_addr_t ram_size, int vga_ram_size,
497 exit(1); 497 exit(1);
498 } 498 }
499 pl181_init(0x1c000000, drives_table[sd].bdrv, pic[23], pic[24]); 499 pl181_init(0x1c000000, drives_table[sd].bdrv, pic[23], pic[24]);
500 - if (nd_table[0].vlan) {  
501 - if (nd_table[0].model == NULL  
502 - || strcmp(nd_table[0].model, "smc91c111") == 0) {  
503 - smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);  
504 - } else if (strcmp(nd_table[0].model, "?") == 0) {  
505 - fprintf(stderr, "qemu: Supported NICs: smc91c111\n");  
506 - exit (1);  
507 - } else {  
508 - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);  
509 - exit (1);  
510 - }  
511 - } 500 + if (nd_table[0].vlan)
  501 + smc91c111_init(&nd_table[0], 0xc8000000, pic[27]);
512 pl110_init(ds, 0xc0000000, pic[22], 0); 502 pl110_init(ds, 0xc0000000, pic[22], 0);
513 503
514 integrator_binfo.ram_size = ram_size; 504 integrator_binfo.ram_size = ram_size;
hw/mcf5208.c
@@ -241,18 +241,8 @@ static void mcf5208evb_init(ram_addr_t ram_size, int vga_ram_size, @@ -241,18 +241,8 @@ static void mcf5208evb_init(ram_addr_t ram_size, int vga_ram_size,
241 fprintf(stderr, "Too many NICs\n"); 241 fprintf(stderr, "Too many NICs\n");
242 exit(1); 242 exit(1);
243 } 243 }
244 - if (nd_table[0].vlan) {  
245 - if (nd_table[0].model == NULL  
246 - || strcmp(nd_table[0].model, "mcf_fec") == 0) {  
247 - mcf_fec_init(&nd_table[0], 0xfc030000, pic + 36);  
248 - } else if (strcmp(nd_table[0].model, "?") == 0) {  
249 - fprintf(stderr, "qemu: Supported NICs: mcf_fec\n");  
250 - exit (1);  
251 - } else {  
252 - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);  
253 - exit (1);  
254 - }  
255 - } 244 + if (nd_table[0].vlan)
  245 + mcf_fec_init(&nd_table[0], 0xfc030000, pic + 36);
256 246
257 /* 0xfc000000 SCM. */ 247 /* 0xfc000000 SCM. */
258 /* 0xfc004000 XBS. */ 248 /* 0xfc004000 XBS. */
hw/mcf_fec.c
@@ -446,6 +446,8 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) @@ -446,6 +446,8 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
446 mcf_fec_state *s; 446 mcf_fec_state *s;
447 int iomemtype; 447 int iomemtype;
448 448
  449 + qemu_check_nic_model(nd, "mcf_fec");
  450 +
449 s = (mcf_fec_state *)qemu_mallocz(sizeof(mcf_fec_state)); 451 s = (mcf_fec_state *)qemu_mallocz(sizeof(mcf_fec_state));
450 s->irq = irq; 452 s->irq = irq;
451 iomemtype = cpu_register_io_memory(0, mcf_fec_readfn, 453 iomemtype = cpu_register_io_memory(0, mcf_fec_readfn,
hw/mips_mipssim.c
@@ -175,19 +175,9 @@ mips_mipssim_init (ram_addr_t ram_size, int vga_ram_size, @@ -175,19 +175,9 @@ mips_mipssim_init (ram_addr_t ram_size, int vga_ram_size,
175 if (serial_hds[0]) 175 if (serial_hds[0])
176 serial_init(0x3f8, env->irq[4], 115200, serial_hds[0]); 176 serial_init(0x3f8, env->irq[4], 115200, serial_hds[0]);
177 177
178 - if (nd_table[0].vlan) {  
179 - if (nd_table[0].model == NULL  
180 - || strcmp(nd_table[0].model, "mipsnet") == 0) {  
181 - /* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */  
182 - mipsnet_init(0x4200, env->irq[2], &nd_table[0]);  
183 - } else if (strcmp(nd_table[0].model, "?") == 0) {  
184 - fprintf(stderr, "qemu: Supported NICs: mipsnet\n");  
185 - exit (1);  
186 - } else {  
187 - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);  
188 - exit (1);  
189 - }  
190 - } 178 + if (nd_table[0].vlan)
  179 + /* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */
  180 + mipsnet_init(0x4200, env->irq[2], &nd_table[0]);
191 } 181 }
192 182
193 QEMUMachine mips_mipssim_machine = { 183 QEMUMachine mips_mipssim_machine = {
hw/mips_r4k.c
@@ -247,20 +247,8 @@ void mips_r4k_init (ram_addr_t ram_size, int vga_ram_size, @@ -247,20 +247,8 @@ void mips_r4k_init (ram_addr_t ram_size, int vga_ram_size,
247 isa_vga_init(ds, phys_ram_base + ram_size, ram_size, 247 isa_vga_init(ds, phys_ram_base + ram_size, ram_size,
248 vga_ram_size); 248 vga_ram_size);
249 249
250 - if (nd_table[0].vlan) {  
251 - if (nd_table[i].model == NULL) {  
252 - nd_table[i].model = "ne2k_isa";  
253 - }  
254 - if (strcmp(nd_table[0].model, "ne2k_isa") == 0) {  
255 - isa_ne2000_init(0x300, i8259[9], &nd_table[0]);  
256 - } else if (strcmp(nd_table[0].model, "?") == 0) {  
257 - fprintf(stderr, "qemu: Supported NICs: ne2k_isa\n");  
258 - exit (1);  
259 - } else {  
260 - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);  
261 - exit (1);  
262 - }  
263 - } 250 + if (nd_table[0].vlan)
  251 + isa_ne2000_init(0x300, i8259[9], &nd_table[0]);
264 252
265 if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { 253 if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
266 fprintf(stderr, "qemu: too many IDE bus\n"); 254 fprintf(stderr, "qemu: too many IDE bus\n");
hw/mipsnet.c
@@ -236,6 +236,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) @@ -236,6 +236,8 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
236 { 236 {
237 MIPSnetState *s; 237 MIPSnetState *s;
238 238
  239 + qemu_check_nic_model(nd, "mipsnet");
  240 +
239 s = qemu_mallocz(sizeof(MIPSnetState)); 241 s = qemu_mallocz(sizeof(MIPSnetState));
240 if (!s) 242 if (!s)
241 return; 243 return;
hw/musicpal.c
@@ -714,6 +714,8 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq) @@ -714,6 +714,8 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
714 mv88w8618_eth_state *s; 714 mv88w8618_eth_state *s;
715 int iomemtype; 715 int iomemtype;
716 716
  717 + qemu_check_nic_model(nd, "mv88w8618");
  718 +
717 s = qemu_mallocz(sizeof(mv88w8618_eth_state)); 719 s = qemu_mallocz(sizeof(mv88w8618_eth_state));
718 if (!s) 720 if (!s)
719 return; 721 return;
hw/ne2000.c
@@ -722,6 +722,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd) @@ -722,6 +722,8 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
722 { 722 {
723 NE2000State *s; 723 NE2000State *s;
724 724
  725 + qemu_check_nic_model(nd, "ne2k_isa");
  726 +
725 s = qemu_mallocz(sizeof(NE2000State)); 727 s = qemu_mallocz(sizeof(NE2000State));
726 if (!s) 728 if (!s)
727 return; 729 return;
hw/pcnet.c
@@ -2087,6 +2087,8 @@ void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque, @@ -2087,6 +2087,8 @@ void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque,
2087 PCNetState *d; 2087 PCNetState *d;
2088 int lance_io_memory; 2088 int lance_io_memory;
2089 2089
  2090 + qemu_check_nic_model(nd, "lance");
  2091 +
2090 d = qemu_mallocz(sizeof(PCNetState)); 2092 d = qemu_mallocz(sizeof(PCNetState));
2091 if (!d) 2093 if (!d)
2092 return; 2094 return;
hw/realview.c
@@ -121,11 +121,13 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size, @@ -121,11 +121,13 @@ static void realview_init(ram_addr_t ram_size, int vga_ram_size,
121 } 121 }
122 for(n = 0; n < nb_nics; n++) { 122 for(n = 0; n < nb_nics; n++) {
123 nd = &nd_table[n]; 123 nd = &nd_table[n];
124 - if (!nd->model)  
125 - nd->model = done_smc ? "rtl8139" : "smc91c111";  
126 - if (strcmp(nd->model, "smc91c111") == 0) { 124 +
  125 + if ((!nd->model && !done_smc) || strcmp(nd->model, "smc91c111") == 0) {
127 smc91c111_init(nd, 0x4e000000, pic[28]); 126 smc91c111_init(nd, 0x4e000000, pic[28]);
  127 + done_smc = 1;
128 } else { 128 } else {
  129 + if (!nd->model)
  130 + nd->model = "rtl8139";
129 pci_nic_init(pci_bus, nd, -1); 131 pci_nic_init(pci_bus, nd, -1);
130 } 132 }
131 } 133 }
hw/smc91c111.c
@@ -695,6 +695,8 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq) @@ -695,6 +695,8 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
695 smc91c111_state *s; 695 smc91c111_state *s;
696 int iomemtype; 696 int iomemtype;
697 697
  698 + qemu_check_nic_model(nd, "smc91c111");
  699 +
698 s = (smc91c111_state *)qemu_mallocz(sizeof(smc91c111_state)); 700 s = (smc91c111_state *)qemu_mallocz(sizeof(smc91c111_state));
699 iomemtype = cpu_register_io_memory(0, smc91c111_readfn, 701 iomemtype = cpu_register_io_memory(0, smc91c111_readfn,
700 smc91c111_writefn, s); 702 smc91c111_writefn, s);
hw/stellaris.c
@@ -1361,10 +1361,8 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model, @@ -1361,10 +1361,8 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
1361 pl022_init(0x40008000, pic[7], NULL, NULL); 1361 pl022_init(0x40008000, pic[7], NULL, NULL);
1362 } 1362 }
1363 } 1363 }
1364 - if (board->dc4 & (1 << 28)) {  
1365 - /* FIXME: Obey network model. */ 1364 + if (board->dc4 & (1 << 28))
1366 stellaris_enet_init(&nd_table[0], 0x40048000, pic[42]); 1365 stellaris_enet_init(&nd_table[0], 0x40048000, pic[42]);
1367 - }  
1368 if (board->peripherals & BP_GAMEPAD) { 1366 if (board->peripherals & BP_GAMEPAD) {
1369 qemu_irq gpad_irq[5]; 1367 qemu_irq gpad_irq[5];
1370 static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d }; 1368 static const int gpad_keycode[5] = { 0xc8, 0xd0, 0xcb, 0xcd, 0x1d };
hw/stellaris_enet.c
@@ -389,6 +389,8 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq) @@ -389,6 +389,8 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
389 stellaris_enet_state *s; 389 stellaris_enet_state *s;
390 int iomemtype; 390 int iomemtype;
391 391
  392 + qemu_check_nic_model(nd, "stellaris");
  393 +
392 s = (stellaris_enet_state *)qemu_mallocz(sizeof(stellaris_enet_state)); 394 s = (stellaris_enet_state *)qemu_mallocz(sizeof(stellaris_enet_state));
393 iomemtype = cpu_register_io_memory(0, stellaris_enet_readfn, 395 iomemtype = cpu_register_io_memory(0, stellaris_enet_readfn,
394 stellaris_enet_writefn, s); 396 stellaris_enet_writefn, s);
hw/sun4m.c
@@ -536,17 +536,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, @@ -536,17 +536,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
536 tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, 536 tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
537 hwdef->vram_size, graphic_width, graphic_height, graphic_depth); 537 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
538 538
539 - if (nd_table[0].model == NULL)  
540 - nd_table[0].model = "lance";  
541 - if (strcmp(nd_table[0].model, "lance") == 0) {  
542 - lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);  
543 - } else if (strcmp(nd_table[0].model, "?") == 0) {  
544 - fprintf(stderr, "qemu: Supported NICs: lance\n");  
545 - exit (1);  
546 - } else {  
547 - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);  
548 - exit (1);  
549 - } 539 + lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
550 540
551 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 541 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
552 hwdef->nvram_size, 8); 542 hwdef->nvram_size, 8);
@@ -1329,17 +1319,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size, @@ -1329,17 +1319,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1329 tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, 1319 tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
1330 hwdef->vram_size, graphic_width, graphic_height, graphic_depth); 1320 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1331 1321
1332 - if (nd_table[0].model == NULL)  
1333 - nd_table[0].model = "lance";  
1334 - if (strcmp(nd_table[0].model, "lance") == 0) {  
1335 - lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);  
1336 - } else if (strcmp(nd_table[0].model, "?") == 0) {  
1337 - fprintf(stderr, "qemu: Supported NICs: lance\n");  
1338 - exit (1);  
1339 - } else {  
1340 - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);  
1341 - exit (1);  
1342 - } 1322 + lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1343 1323
1344 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0, 1324 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1345 hwdef->nvram_size, 8); 1325 hwdef->nvram_size, 8);
@@ -1545,17 +1525,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, @@ -1545,17 +1525,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1545 tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset, 1525 tcx_init(ds, hwdef->tcx_base, phys_ram_base + tcx_offset, tcx_offset,
1546 hwdef->vram_size, graphic_width, graphic_height, graphic_depth); 1526 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1547 1527
1548 - if (nd_table[0].model == NULL)  
1549 - nd_table[0].model = "lance";  
1550 - if (strcmp(nd_table[0].model, "lance") == 0) {  
1551 - lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);  
1552 - } else if (strcmp(nd_table[0].model, "?") == 0) {  
1553 - fprintf(stderr, "qemu: Supported NICs: lance\n");  
1554 - exit (1);  
1555 - } else {  
1556 - fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);  
1557 - exit (1);  
1558 - } 1528 + lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1559 1529
1560 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 1530 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
1561 hwdef->nvram_size, 2); 1531 hwdef->nvram_size, 2);
hw/versatilepb.c
@@ -194,11 +194,13 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size, @@ -194,11 +194,13 @@ static void versatile_init(ram_addr_t ram_size, int vga_ram_size,
194 so many of the qemu PCI devices are not useable. */ 194 so many of the qemu PCI devices are not useable. */
195 for(n = 0; n < nb_nics; n++) { 195 for(n = 0; n < nb_nics; n++) {
196 nd = &nd_table[n]; 196 nd = &nd_table[n];
197 - if (!nd->model)  
198 - nd->model = done_smc ? "rtl8139" : "smc91c111";  
199 - if (strcmp(nd->model, "smc91c111") == 0) { 197 +
  198 + if ((!nd->model && !done_smc) || strcmp(nd->model, "smc91c111") == 0) {
200 smc91c111_init(nd, 0x10010000, sic[25]); 199 smc91c111_init(nd, 0x10010000, sic[25]);
  200 + done_smc = 1;
201 } else { 201 } else {
  202 + if (!nd->model)
  203 + nd->model = "rtl8139";
202 pci_nic_init(pci_bus, nd, -1); 204 pci_nic_init(pci_bus, nd, -1);
203 } 205 }
204 } 206 }