[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/45] net: add qemu_create_nic_bus_devices()
From: |
David Woodhouse |
Subject: |
[PATCH 03/45] net: add qemu_create_nic_bus_devices() |
Date: |
Sun, 22 Oct 2023 16:51:18 +0100 |
From: David Woodhouse <dwmw@amazon.co.uk>
This will instantiate any NICs which live on a given bus type. Each bus
is allowed *one* substitution (for PCI it's virtio → virtio-net-pci, for
Xen it's xen → xen-net-device; no point in overengineering it unless we
actually want more).
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
include/net/net.h | 3 +++
net/net.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/include/net/net.h b/include/net/net.h
index 56be694c75..ce830a47d0 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -211,6 +211,9 @@ bool qemu_configure_nic_device(DeviceState *dev, bool
match_default,
const char *alias);
DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
const char *alias);
+void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type,
+ const char *default_model,
+ const char *alias, const char *alias_target);
void print_net_client(Monitor *mon, NetClientState *nc);
void net_socket_rs_init(SocketReadState *rs,
SocketReadStateFinalize *finalize,
diff --git a/net/net.c b/net/net.c
index 6e20f9d2e9..23fd716b98 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1207,6 +1207,59 @@ DeviceState *qemu_create_nic_device(const char
*typename, bool match_default,
return dev;
}
+void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type,
+ const char *default_model,
+ const char *alias, const char *alias_target)
+{
+ GPtrArray *nic_models = qemu_get_nic_models(parent_type);
+ const char *model;
+ DeviceState *dev;
+ NICInfo *nd;
+ int i;
+
+ if (nic_model_help) {
+ if (alias_target) {
+ add_nic_model_help(alias_target, alias);
+ }
+ for (i = 0; i < nic_models->len - 1; i++) {
+ add_nic_model_help(nic_models->pdata[i], NULL);
+ }
+ }
+
+ /* Drop the NULL terminator which would make g_str_equal() unhappy */
+ nic_models->len--;
+
+ for (i = 0; i < nb_nics; i++) {
+ nd = &nd_table[i];
+
+ if (!nd->used || nd->instantiated) {
+ continue;
+ }
+
+ model = nd->model ? nd->model : default_model;
+ if (!model) {
+ continue;
+ }
+
+ /* Each bus type is allowed *one* substitution */
+ if (g_str_equal(model, alias)) {
+ model = alias_target;
+ }
+
+ if (!g_ptr_array_find_with_equal_func(nic_models, model,
+ g_str_equal, NULL)) {
+ /* This NIC does not live on this bus. */
+ continue;
+ }
+
+ dev = qdev_new(model);
+ qdev_set_nic_properties(dev, nd);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
+ }
+
+ g_ptr_array_free(nic_models, true);
+}
+
static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
const Netdev *netdev,
const char *name,
--
2.40.1
- [PATCH 31/45] hw/net/etraxfs-eth: use qemu_configure_nic_device(), (continued)
- [PATCH 31/45] hw/net/etraxfs-eth: use qemu_configure_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 12/45] hw/mips/fuloong2e: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 26/45] hw/net/lan9118: use qemu_configure_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 42/45] net: remove qemu_check_nic_model(), David Woodhouse, 2023/10/22
- [PATCH 10/45] hw/hppa: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 45/45] net: make nb_nics and nd_table[] static in net/net.c, David Woodhouse, 2023/10/22
- [PATCH 17/45] hw/ppc: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 11/45] hw/loongarch: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 23/45] hw/arm/exynos4: use qemu_create_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 43/45] hw/pci: remove pci_nic_init_nofail(), David Woodhouse, 2023/10/22
- [PATCH 03/45] net: add qemu_create_nic_bus_devices(),
David Woodhouse <=
- [PATCH 15/45] hw/ppc/prep: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 09/45] hw/arm/virt: use pci_init_nic_devices(), David Woodhouse, 2023/10/22