[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 02/69] net: allow using any PCI NICs in -net or -nic
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 02/69] net: allow using any PCI NICs in -net or -nic |
Date: |
Tue, 13 Mar 2018 23:46:12 +0100 |
Remove the hard-coded list of PCI NIC names; instead, fill an array
using all PCI devices listed under DEVICE_CATEGORY_NETWORK. Keep
the old shortcut "virtio" for virtio-net-pci.
Suggested-by: Thomas Huth <address@hidden>
Reviewed-by: Thomas Huth <address@hidden>
Reviewed-by: Jason Wang <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/pci/pci.c | 61 +++++++++++++++++++++++++++++------------------------------
hw/ppc/e500.c | 2 +-
2 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 2174c254eb..67a3f72bd6 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1815,49 +1815,48 @@ PciInfoList *qmp_query_pci(Error **errp)
return head;
}
-static const char * const pci_nic_models[] = {
- "ne2k_pci",
- "i82551",
- "i82557b",
- "i82559er",
- "rtl8139",
- "e1000",
- "pcnet",
- "virtio",
- "sungem",
- NULL
-};
-
-static const char * const pci_nic_names[] = {
- "ne2k_pci",
- "i82551",
- "i82557b",
- "i82559er",
- "rtl8139",
- "e1000",
- "pcnet",
- "virtio-net-pci",
- "sungem",
- NULL
-};
-
/* Initialize a PCI NIC. */
PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
const char *default_model,
const char *default_devaddr)
{
const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr;
+ GSList *list;
+ GPtrArray *pci_nic_models;
PCIBus *bus;
PCIDevice *pci_dev;
DeviceState *dev;
int devfn;
int i;
- if (qemu_show_nic_models(nd->model, pci_nic_models)) {
+ if (nd->model && !strcmp(nd->model, "virtio")) {
+ g_free(nd->model);
+ nd->model = g_strdup("virtio-net-pci");
+ }
+
+ list = object_class_get_list_sorted(TYPE_PCI_DEVICE, false);
+ pci_nic_models = g_ptr_array_new();
+ while (list) {
+ DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, list->data,
+ TYPE_DEVICE);
+ GSList *next;
+ if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
+ dc->user_creatable) {
+ const char *name = object_class_get_name(list->data);
+ g_ptr_array_add(pci_nic_models, (gpointer)name);
+ }
+ next = list->next;
+ g_slist_free_1(list);
+ list = next;
+ }
+ g_ptr_array_add(pci_nic_models, NULL);
+
+ if (qemu_show_nic_models(nd->model, (const char **)pci_nic_models->pdata))
{
exit(0);
}
- i = qemu_find_nic_model(nd, pci_nic_models, default_model);
+ i = qemu_find_nic_model(nd, (const char **)pci_nic_models->pdata,
+ default_model);
if (i < 0) {
exit(1);
}
@@ -1865,15 +1864,15 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus
*rootbus,
bus = pci_get_bus_devfn(&devfn, rootbus, devaddr);
if (!bus) {
error_report("Invalid PCI device address %s for device %s",
- devaddr, pci_nic_names[i]);
+ devaddr, nd->model);
exit(1);
}
- pci_dev = pci_create(bus, devfn, pci_nic_names[i]);
+ pci_dev = pci_create(bus, devfn, nd->model);
dev = &pci_dev->qdev;
qdev_set_nic_properties(dev, nd);
qdev_init_nofail(dev);
-
+ g_ptr_array_free(pci_nic_models, true);
return pci_dev;
}
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index 43c15d18c4..2238f963c4 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -916,7 +916,7 @@ void ppce500_init(MachineState *machine, PPCE500Params
*params)
if (pci_bus) {
/* Register network interfaces. */
for (i = 0; i < nb_nics; i++) {
- pci_nic_init_nofail(&nd_table[i], pci_bus, "virtio", NULL);
+ pci_nic_init_nofail(&nd_table[i], pci_bus, "virtio-net-pci", NULL);
}
}
--
2.14.3
- [Qemu-devel] [PULL 00/69] Misc patches for QEMU soft freeze, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 05/69] qemu-doc: update deprecation section to use -nic and -netdev hubport, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 01/69] qom: introduce object_class_get_list_sorted, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 03/69] q35: change default NIC to e1000e, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 04/69] scsi-disk.c: consider bl->max_transfer in INQUIRY emulation, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 06/69] qemu-doc: Add the paragraph about the -no-frame deprecation again, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 07/69] build-sys: make help could have 'modules' target, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 02/69] net: allow using any PCI NICs in -net or -nic,
Paolo Bonzini <=
- [Qemu-devel] [PULL 09/69] checkpatch: Exempt long URLs, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 11/69] chardev: fix handling of EAGAIN for TCP chardev, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 10/69] vl: export machine_init_done, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 08/69] hw: Do not include "sysemu/block-backend.h" if it is not necessary, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 13/69] chardev: allow telnet gsource to switch gcontext, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 15/69] chardev: use chardev's gcontext for async connect, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 12/69] chardev: update net listener gcontext, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 14/69] chardev: introduce chr_machine_done hook, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 16/69] chardev: tcp: postpone async connection setup, Paolo Bonzini, 2018/03/13
- [Qemu-devel] [PULL 19/69] hw/i386: make IOMMUs configurable via default-configs/, Paolo Bonzini, 2018/03/13