[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 01/45] net: add qemu_{configure, create}_nic_device(), qemu_find_
From: |
David Woodhouse |
Subject: |
[PATCH 01/45] net: add qemu_{configure, create}_nic_device(), qemu_find_nic_info() |
Date: |
Sun, 22 Oct 2023 16:51:16 +0100 |
From: David Woodhouse <dwmw@amazon.co.uk>
Most code which directly accesses nd_table[] and nb_nics uses them for
one of two things. Either "I have created a NIC device and I'd like a
configuration for it", or "I will create a NIC device *if* there is a
configuration for it". With some variants on the theme around whether
they actually *check* if the model specified in the configuration is
the right one.
Provide functions which perform both of those, allowing platforms to
be a little more consistent and as a step towards making nd_table[]
and nb_nics private to the net code.
Also export the qemu_find_nic_info() helper, as some platforms have
special cases they need to handle.
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
include/net/net.h | 7 ++++++-
net/net.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/include/net/net.h b/include/net/net.h
index 2fb1c9181c..56be694c75 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -205,7 +205,12 @@ int qemu_show_nic_models(const char *arg, const char
*const *models);
void qemu_check_nic_model(NICInfo *nd, const char *model);
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
const char *default_model);
-
+NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
+ const char *alias);
+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 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 bbe33da176..606816a3b3 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1072,6 +1072,56 @@ static int net_init_nic(const Netdev *netdev, const char
*name,
return idx;
}
+NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
+ const char *alias)
+{
+ NICInfo *nd;
+ int i;
+
+ for (i = 0; i < nb_nics; i++) {
+ nd = &nd_table[i];
+
+ if (!nd->used || nd->instantiated)
+ continue;
+
+ if ((match_default && !nd->model) || !g_strcmp0(nd->model, typename)
+ || (alias && !g_strcmp0(nd->model, alias))) {
+ return nd;
+ }
+ }
+ return NULL;
+}
+
+
+/* "I have created a device. Please configure it if you can" */
+bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
+ const char *alias)
+{
+ NICInfo *nd = qemu_find_nic_info(object_get_typename(OBJECT(dev)),
+ match_default, alias);
+
+ if (nd) {
+ qdev_set_nic_properties(dev, nd);
+ return true;
+ }
+ return false;
+}
+
+/* "Please create a device, if you have a configuration for it" */
+DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
+ const char *alias)
+{
+ NICInfo *nd = qemu_find_nic_info(typename, match_default, alias);
+ DeviceState *dev;
+
+ if (!nd) {
+ return NULL;
+ }
+
+ dev = qdev_new(typename);
+ qdev_set_nic_properties(dev, nd);
+ return dev;
+}
static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
const Netdev *netdev,
--
2.40.1
- [PATCH 22/45] hw/arm/aspeed: use qemu_configure_nic_device(), (continued)
- [PATCH 22/45] hw/arm/aspeed: use qemu_configure_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 19/45] hw/sparc64/sun4u: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 34/45] hw/microblaze: use qemu_configure_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 28/45] hw/arm/npcm7xx: use qemu_configure_nic_device, allow emc0/emc1 as aliases, David Woodhouse, 2023/10/22
- [PATCH 29/45] hw/arm/stellaris: use qemu_find_nic_info(), David Woodhouse, 2023/10/22
- [PATCH 05/45] hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 25/45] hw/net/smc91c111: use qemu_configure_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 39/45] hw/s390x/s390-virtio-ccw: use qemu_create_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 36/45] hw/net/lasi_i82596: use qemu_configure_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 14/45] hw/mips/loongson3_virt: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [PATCH 01/45] net: add qemu_{configure, create}_nic_device(), qemu_find_nic_info(),
David Woodhouse <=
- [PATCH 44/45] net: remove qemu_show_nic_models(), qemu_find_nic_model(), David Woodhouse, 2023/10/22
- [PATCH 21/45] hw/arm/allwinner: use qemu_configure_nic_device(), David Woodhouse, 2023/10/22
- [PATCH 13/45] hw/mips/malta: use pci_init_nic_devices(), David Woodhouse, 2023/10/22
- [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