Revision 07caea31

b/hw/mips_malta.c
489 489
            /* The malta board has a PCNet card using PCI SLOT 11 */
490 490
            default_devaddr = "0b";
491 491

  
492
        pci_nic_init(nd, "pcnet", default_devaddr);
492
        pci_nic_init_nofail(nd, "pcnet", default_devaddr);
493 493
    }
494 494
}
495 495

  
b/hw/pc.c
1345 1345
        if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
1346 1346
            pc_init_ne2k_isa(nd);
1347 1347
        else
1348
            pci_nic_init(nd, "e1000", NULL);
1348
            pci_nic_init_nofail(nd, "e1000", NULL);
1349 1349
    }
1350 1350

  
1351 1351
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
b/hw/pci.c
867 867
                        const char *default_devaddr)
868 868
{
869 869
    const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
870
    PCIBus *bus;
871
    int devfn;
870 872
    PCIDevice *pci_dev;
871 873
    DeviceState *dev;
872 874
    int i;
873 875

  
874
    i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
875
    pci_dev = pci_create(pci_nic_names[i], devaddr);
876
    i = qemu_find_nic_model(nd, pci_nic_models, default_model);
877
    if (i < 0)
878
        return NULL;
879

  
880
    bus = pci_get_bus_devfn(&devfn, devaddr);
881
    if (!bus) {
882
        qemu_error("Invalid PCI device address %s for device %s\n",
883
                   devaddr, pci_nic_names[i]);
884
        return NULL;
885
    }
886

  
887
    pci_dev = pci_create_noinit(bus, devfn, pci_nic_names[i]);
876 888
    dev = &pci_dev->qdev;
877 889
    if (nd->id)
878 890
        dev->id = qemu_strdup(nd->id);
879 891
    dev->nd = nd;
880
    qdev_init(dev);
892
    if (qdev_init(dev) < 0)
893
        return NULL;
881 894
    nd->private = dev;
882 895
    return pci_dev;
883 896
}
884 897

  
898
PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
899
                               const char *default_devaddr)
900
{
901
    PCIDevice *res;
902

  
903
    if (qemu_show_nic_models(nd->model, pci_nic_models))
904
        exit(0);
905

  
906
    res = pci_nic_init(nd, default_model, default_devaddr);
907
    if (!res)
908
        exit(1);
909
    return res;
910
}
911

  
885 912
typedef struct {
886 913
    PCIDevice dev;
887 914
    PCIBus bus;
b/hw/pci.h
256 256
int pci_nic_supported(const char *model);
257 257
PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
258 258
                        const char *default_devaddr);
259
PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,
260
                               const char *default_devaddr);
259 261
void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);
260 262
uint32_t pci_data_read(void *opaque, uint32_t addr, int len);
261 263
int pci_bus_num(PCIBus *s);
b/hw/ppc440_bamboo.c
119 119
        for (i = 0; i < nb_nics; i++) {
120 120
            /* There are no PCI NICs on the Bamboo board, but there are
121 121
             * PCI slots, so we can pick whatever default model we want. */
122
            pci_nic_init(&nd_table[i], "e1000", NULL);
122
            pci_nic_init_nofail(&nd_table[i], "e1000", NULL);
123 123
        }
124 124
    }
125 125

  
b/hw/ppc_newworld.c
320 320
                               serial_hds[0], serial_hds[1], ESCC_CLOCK, 4);
321 321

  
322 322
    for(i = 0; i < nb_nics; i++)
323
        pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
323
        pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
324 324

  
325 325
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
326 326
        fprintf(stderr, "qemu: too many IDE bus\n");
b/hw/ppc_oldworld.c
333 333
                               serial_hds[1], ESCC_CLOCK, 4);
334 334

  
335 335
    for(i = 0; i < nb_nics; i++)
336
        pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
336
        pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
337 337

  
338 338

  
339 339
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
b/hw/ppc_prep.c
697 697
        if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
698 698
            isa_ne2000_init(ne2000_io[i], ne2000_irq[i], &nd_table[i]);
699 699
        } else {
700
            pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
700
            pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
701 701
        }
702 702
    }
703 703

  
b/hw/ppce500_mpc8544ds.c
219 219
    if (pci_bus) {
220 220
        /* Register network interfaces. */
221 221
        for (i = 0; i < nb_nics; i++) {
222
            pci_nic_init(&nd_table[i], "virtio", NULL);
222
            pci_nic_init_nofail(&nd_table[i], "virtio", NULL);
223 223
        }
224 224
    }
225 225

  
b/hw/r2d.c
236 236

  
237 237
    /* NIC: rtl8139 on-board, and 2 slots. */
238 238
    for (i = 0; i < nb_nics; i++)
239
        pci_nic_init(&nd_table[i], "rtl8139", i==0 ? "2" : NULL);
239
        pci_nic_init_nofail(&nd_table[i], "rtl8139", i==0 ? "2" : NULL);
240 240

  
241 241
    /* Todo: register on board registers */
242 242
    if (kernel_filename) {
b/hw/realview.c
125 125
            smc91c111_init(nd, 0x4e000000, pic[28]);
126 126
            done_smc = 1;
127 127
        } else {
128
            pci_nic_init(nd, "rtl8139", NULL);
128
            pci_nic_init_nofail(nd, "rtl8139", NULL);
129 129
        }
130 130
    }
131 131

  
b/hw/sun4u.c
610 610
    }
611 611

  
612 612
    for(i = 0; i < nb_nics; i++)
613
        pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
613
        pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
614 614

  
615 615
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
616 616
        fprintf(stderr, "qemu: too many IDE bus\n");
b/hw/versatilepb.c
213 213
            smc91c111_init(nd, 0x10010000, sic[25]);
214 214
            done_smc = 1;
215 215
        } else {
216
            pci_nic_init(nd, "rtl8139", NULL);
216
            pci_nic_init_nofail(nd, "rtl8139", NULL);
217 217
        }
218 218
    }
219 219
    if (usb_enabled) {
b/net.c
2348 2348
    return -1;
2349 2349
}
2350 2350

  
2351
int qemu_show_nic_models(const char *arg, const char *const *models)
2352
{
2353
    int i;
2354

  
2355
    if (!arg || strcmp(arg, "?"))
2356
        return 0;
2357

  
2358
    fprintf(stderr, "qemu: Supported NIC models: ");
2359
    for (i = 0 ; models[i]; i++)
2360
        fprintf(stderr, "%s%c", models[i], models[i+1] ? ',' : '\n');
2361
    return 1;
2362
}
2363

  
2351 2364
void qemu_check_nic_model(NICInfo *nd, const char *model)
2352 2365
{
2353 2366
    const char *models[2];
......
2355 2368
    models[0] = model;
2356 2369
    models[1] = NULL;
2357 2370

  
2358
    qemu_check_nic_model_list(nd, models, model);
2371
    if (qemu_show_nic_models(nd->model, models))
2372
        exit(0);
2373
    if (qemu_find_nic_model(nd, models, model) < 0)
2374
        exit(1);
2359 2375
}
2360 2376

  
2361
int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
2362
                              const char *default_model)
2377
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
2378
                        const char *default_model)
2363 2379
{
2364
    int i, exit_status = 0;
2380
    int i;
2365 2381

  
2366 2382
    if (!nd->model)
2367 2383
        nd->model = strdup(default_model);
2368 2384

  
2369
    if (strcmp(nd->model, "?") != 0) {
2370
        for (i = 0 ; models[i]; i++)
2371
            if (strcmp(nd->model, models[i]) == 0)
2372
                return i;
2373

  
2374
        fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
2375
        exit_status = 1;
2385
    for (i = 0 ; models[i]; i++) {
2386
        if (strcmp(nd->model, models[i]) == 0)
2387
            return i;
2376 2388
    }
2377 2389

  
2378
    fprintf(stderr, "qemu: Supported NIC models: ");
2379
    for (i = 0 ; models[i]; i++)
2380
        fprintf(stderr, "%s%c", models[i], models[i+1] ? ',' : '\n');
2381

  
2382
    exit(exit_status);
2390
    qemu_error("qemu: Unsupported NIC model: %s\n", nd->model);
2391
    return -1;
2383 2392
}
2384 2393

  
2385 2394
static int net_handle_fd_param(Monitor *mon, const char *param)
b/net.h
75 75
void qemu_purge_queued_packets(VLANClientState *vc);
76 76
void qemu_flush_queued_packets(VLANClientState *vc);
77 77
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
78
int qemu_show_nic_models(const char *arg, const char *const *models);
78 79
void qemu_check_nic_model(NICInfo *nd, const char *model);
79
int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
80
                              const char *default_model);
80
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
81
                        const char *default_model);
81 82
void qemu_handler_true(void *opaque);
82 83

  
83 84
void do_info_network(Monitor *mon);

Also available in: Unified diff