Rework matching of network devices to -nic options
Subsystems (9)
v2 cover Rework matching of network devices to -nic options
In https://lore.kernel.org/qemu-devel/[email protected]/
I lamented that the default NIC creation seemed fairly hackish but "that isn't a yak I want to shave today."
Yet here we are...
Most platforms iterating directly over the nd_table[] are doing one of two things. Either they are creating the NIC for their platform and want to find a matching -nic configuration for it, if such exists. Or they are only going to create that platform NIC if a matching config *does* exist.
All of those can be converted to the new qemu_configure_nic_device() and qemu_create_nic_device() functions. The latter of which will call qdev_new() to create the device (and apply the config) if a matching NIC config does exist for it. The existing behaviour of each platform has been preserved for now, despite it being apparently fairly random.
PCI and indeed XenBus can use a qemu_create_nic_bus_devices() which will create all NICs that live on a given bus type. That covers most platforms, but some PCI platforms do something special with the first NIC of a given type, placing it in the slot where it would have been on the real hardware. There were various inconsistencies in the way the platforms did so, and whether they cared what model the NIC was. Those subtle behavioural changes I *have* allowed to change, and now the pci_init_nic_slot() function will pick the first NIC that the user specified which isn't explicitly *not* the default type, and put that in the specified slot.
The tests for npcm7xx used to lament that they had to instantiate both NICs even when they wanted to test only the second, because there was no way to specify which hardware devices gets which configuration. I made that untrue, by allowing 'emc0' and 'emc1' aliases, and fixed up the test accordingly.
There are one or two special cases which want to do special things with the MAC address of the primary NIC, to set up a system identification (or force it to use an Apple OUI, in the case of m68k/q400). All those work out relatively cleanly too.
And I can clean up the ugly patch which fixed up the Xen network device handling, and replace it with a simple call to the new qemu_create_nic_bus_devices() function.
I suspect that we can remove the pci_init_nic_devices() from platform code and just do it later, except for platforms which *care* which PCI bus the dynamic devices go on (is that just sun4u which puts its primary NIC onto a different bus?).
Finally, while we're at it, clean up -nic model=help to only print the device models which are actually usable on the given platform rather than just listing them *all*.
And now we can make nd_table[] and nb_nics static in net/net.c because nothing else has any business poking at them directly.
v2: Some build fixes after better coverage testing, revert the Xen fix
in this series because I'm putting the less invasive hack into 8.2 (hopefully).
David Woodhouse (46):
net: add qemu_{configure,create}_nic_device(), qemu_find_nic_info()
net: report list of available models according to platform
net: add qemu_create_nic_bus_devices()
hw/pci: add pci_init_nic_devices(), pci_init_nic_in_slot() hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices() hw/xen: use qemu_create_nic_bus_devices() to instantiate Xen NICs hw/alpha/dp264: use pci_init_nic_devices()
hw/arm/sbsa-ref: use pci_init_nic_devices()
hw/arm/virt: use pci_init_nic_devices()
hw/hppa: use pci_init_nic_devices()
hw/loongarch: use pci_init_nic_devices()
hw/mips/fuloong2e: use pci_init_nic_devices()
hw/mips/malta: use pci_init_nic_devices() hw/mips/loongson3_virt: use pci_init_nic_devices() hw/ppc/prep: use pci_init_nic_devices()
hw/ppc/spapr: use qemu_get_nic_info() and pci_init_nic_devices() hw/ppc: use pci_init_nic_devices()
hw/sh4/r2d: use pci_init_nic_devices()
hw/sparc64/sun4u: use pci_init_nic_devices()
hw/xtensa/virt: use pci_init_nic_devices()
hw/arm/allwinner: use qemu_configure_nic_device() hw/arm/aspeed: use qemu_configure_nic_device() hw/arm/exynos4: use qemu_create_nic_device()
hw/arm/fsl: use qemu_configure_nic_device() hw/net/smc91c111: use qemu_configure_nic_device() hw/net/lan9118: use qemu_configure_nic_device() hw/arm/highbank: use qemu_create_nic_device() hw/arm/npcm7xx: use qemu_configure_nic_device, allow emc0/emc1 as aliases hw/arm/stellaris: use qemu_find_nic_info()
hw/arm: use qemu_configure_nic_device()
hw/net/etraxfs-eth: use qemu_configure_nic_device() hw/m68k/mcf5208: use qemu_create_nic_device()
hw/m68k/q800: use qemu_find_nic_info()
hw/microblaze: use qemu_configure_nic_device() hw/mips/mipssim: use qemu_create_nic_device()
hw/mips/jazz: use qemu_find_nic_info()
hw/net/lasi_i82596: use qemu_configure_nic_device() hw/openrisc/openrisc_sim: use qemu_create_nic_device() hw/riscv: use qemu_configure_nic_device() hw/s390x/s390-virtio-ccw: use qemu_create_nic_device() hw/sparc/sun4m: use qemu_find_nic_info()
hw/xtensa/xtfpga: use qemu_create_nic_device()
net: remove qemu_check_nic_model()
hw/pci: remove pci_nic_init_nofail()
net: remove qemu_show_nic_models(), qemu_find_nic_model()
net: make nb_nics and nd_table[] static in net/net.c
hw/alpha/dp264.c | 4 +- hw/arm/allwinner-a10.c | 6 +- hw/arm/allwinner-h3.c | 6 +- hw/arm/allwinner-r40.c | 27 +--- hw/arm/aspeed.c | 9 +- hw/arm/exynos4_boards.c | 6 +- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/fsl-imx6ul.c | 2 +- hw/arm/fsl-imx7.c | 2 +- hw/arm/gumstix.c | 6 +- hw/arm/highbank.c | 12 +- hw/arm/integratorcp.c | 5 +- hw/arm/kzm.c | 4 +- hw/arm/mainstone.c | 3 +- hw/arm/mps2-tz.c | 8 +- hw/arm/mps2.c | 2 +- hw/arm/msf2-soc.c | 6 +- hw/arm/musicpal.c | 3 +- hw/arm/npcm7xx.c | 16 +- hw/arm/realview.c | 25 ++- hw/arm/sbsa-ref.c | 4 +- hw/arm/stellaris.c | 30 +++- hw/arm/versatilepb.c | 15 +- hw/arm/vexpress.c | 4 +- hw/arm/virt.c | 4 +- hw/arm/xilinx_zynq.c | 11 +- hw/arm/xlnx-versal.c | 7 +- hw/arm/xlnx-zynqmp.c | 8 +- hw/cris/axis_dev88.c | 9 +- hw/hppa/machine.c | 7 +- hw/i386/pc.c | 33 ++-- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/loongarch/virt.c | 4 +- hw/m68k/mcf5208.c | 20 +-- hw/m68k/q800.c | 29 ++-- hw/microblaze/petalogix_ml605_mmu.c | 3 +- hw/microblaze/petalogix_s3adsp1800_mmu.c | 3 +- hw/mips/fuloong2e.c | 16 +- hw/mips/jazz.c | 15 +- hw/mips/loongson3_virt.c | 4 +- hw/mips/malta.c | 15 +- hw/mips/mipssim.c | 13 +- hw/net/etraxfs_eth.c | 5 +- hw/net/lan9118.c | 5 +- hw/net/lasi_i82596.c | 3 +- hw/net/smc91c111.c | 5 +- hw/openrisc/openrisc_sim.c | 18 +-- hw/pci/pci.c | 73 +++------ hw/ppc/e500.c | 4 +- hw/ppc/mac_newworld.c | 4 +- hw/ppc/mac_oldworld.c | 4 +- hw/ppc/ppc440_bamboo.c | 14 +- hw/ppc/prep.c | 8 +- hw/ppc/spapr.c | 18 +-- hw/riscv/microchip_pfsoc.c | 14 +- hw/riscv/sifive_u.c | 7 +- hw/s390x/s390-virtio-ccw.c | 11 +- hw/sh4/r2d.c | 6 +- hw/sparc/sun4m.c | 20 ++- hw/sparc64/sun4u.c | 27 +--- hw/xen/xen-bus.c | 6 +- hw/xen/xen_devconfig.c | 25 --- hw/xenpv/xen_machine_pv.c | 9 -- hw/xtensa/virt.c | 4 +- hw/xtensa/xtfpga.c | 13 +- include/hw/cris/etraxfs.h | 2 +- include/hw/i386/pc.h | 4 +- include/hw/net/lan9118.h | 2 +- include/hw/net/ne2000-isa.h | 2 - include/hw/net/smc91c111.h | 2 +- include/hw/pci/pci.h | 7 +- include/hw/xen/xen-bus.h | 2 +- include/hw/xen/xen-legacy-backend.h | 1 - include/net/net.h | 18 +-- net/net.c | 253 +++++++++++++++++++++++++------ system/globals.c | 2 - tests/qtest/npcm7xx_emc-test.c | 18 +-- 79 files changed, 479 insertions(+), 551 deletions(-)
PATCH v2 1/46 net: add qemu_{configure,create}_nic_device(), qemu_find_nic_info()
From: David Woodhouse <[email protected]>
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.
--- include/net/net.h | 7 ++++++- net/net.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-)
include/net/net.h +6 -1
@@ -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,
net/net.c +51 -0
57 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH v2 2/46 net: report list of available models according to platform
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
By noting the models for which a configuration was requested, we can give the user an accurate list of which NIC models were actually available on the platform/configuration that was otherwise chosen.
--- net/net.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)
net/net.c +94 -0
@@ -75,6 +75,8 @@ typedef QSIMPLEQ_HEAD(, NetdevQueueEntry) NetdevQueue;static NetdevQueue nd_queue =QSIMPLEQ_HEAD_INITIALIZER (nd_queue); +static GHashTable *nic_model_help; +/***********************************************************/ /* network device redirectors */
@@ -1072,12 +1074,94 @@ static int net_init_nic(const Netdev *netdev, const char *name,return idx; } +static gboolean add_nic_result (gpointer key,gpointer value,gpointer user_data) +{ +GPtrArray *results = user_data; +GPtrArray *alias_list = value; +const char *model = key; +char *result; + +if (!alias_list) { + result =g_strdup (model); + }else { +GString *result_str =g_string_new (model); +int i; + +g_string_append (result_str," (aka " ); +for (i =0 ; i < alias_list->len; i++) { +if (i) { +g_string_append (result_str,", " ); + } +g_string_append (result_str, alias_list->pdata[i]); + } +g_string_append (result_str,")" ); + result = result_str->str; +g_string_free (result_str, false); +g_ptr_array_unref (alias_list); + } +g_ptr_array_add (results, result); +return true; +} + +static int model_cmp (char **a,char **b) +{ +return strcmp (*a, *b); +} + +static void show_nic_models (void ) +{ +GPtrArray *results =g_ptr_array_new (); +int i; + +g_hash_table_foreach_remove (nic_model_help, add_nic_result, results); +g_ptr_array_sort (results, (GCompareFunc )model_cmp); + +printf ("Available NIC models for this configuration:\n" ); +for (i =0 ; i < results->len; i++) { +printf ("%s\n" , (char *)results->pdata[i]); + } +g_hash_table_unref (nic_model_help); + nic_model_help =NULL ; +} + +static void add_nic_model_help (const char *model,const char *alias) +{ +GPtrArray *alias_list =NULL ; + +if (g_hash_table_lookup_extended (nic_model_help, model,NULL , + (gpointer *)&alias_list)) { +/* Already exists, no alias to add: return */ +if (!alias) { +return ; + } +if (alias_list) { +/* Check if this alias is already in the list. Add if not. */ +if (!g_ptr_array_find_with_equal_func (alias_list, alias, + g_str_equal,NULL )) { +g_ptr_array_add (alias_list,g_strdup (alias)); + } +return ; + } + } +/* Either this model wasn't in the list already, or a first alias added */ +if (alias) { + alias_list =g_ptr_array_new (); +g_ptr_array_set_free_func (alias_list, g_free); +g_ptr_array_add (alias_list,g_strdup (alias)); + } +g_hash_table_replace (nic_model_help,g_strdup (model), alias_list); +} +NICInfo *qemu_find_nic_info (const char *typename,bool match_default,const char *alias) {NICInfo *nd;int i; +if (nic_model_help) { +add_nic_model_help (typename, alias); + } +for (i =0 ; i < nb_nics; i++) { nd = &nd_table[i];
@@ -1591,6 +1675,10 @@ void net_check_clients(void)NetClientState *nc;int i; +if (nic_model_help) { +show_nic_models (); +exit (0 ); + }net_hub_check_clients (); QTAILQ_FOREACH(nc, &net_clients, next) {
@@ -1670,6 +1758,12 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp)memset (ni,0 ,sizeof (*ni)); ni->model =qemu_opt_get_del (opts,"model" ); +if (!nic_model_help && !g_strcmp0 (ni->model,"help" )) { + nic_model_help =g_hash_table_new_full (g_str_hash, g_str_equal, + g_free,NULL ); +return 0 ; + } +/* Create an ID if the user did not specify one */ nd_id =g_strdup (qemu_opts_id (opts));if (!nd_id) {
Signature · 1 line
2.41.0
PATCH v2 3/46 net: add qemu_create_nic_bus_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
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).
--- include/net/net.h | 3 +++ net/net.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+)
include/net/net.h +3 -0
@@ -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,
net/net.c +53 -0
59 lines not on this page · raw message
Signature · 1 line
2.41.0
PATCH v2 4/46 hw/pci: add pci_init_nic_devices(), pci_init_nic_in_slot()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
The loop over nd_table[] to add PCI NICs is repeated in quite a few places. Add a helper function to do it.
Some platforms also try to instantiate a specific model in a specific slot, to match the real hardware. Add pci_init_nic_in_slot() for that purpose.
--- hw/pci/pci.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 4 +++- 2 files changed, 48 insertions(+), 1 deletion(-)
hw/pci/pci.c +45 -0
@@ -1925,6 +1925,51 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,return pci_dev; } +void pci_init_nic_devices (PCIBus *bus,const char *default_model) +{ +qemu_create_nic_bus_devices (&bus->qbus,TYPE_PCI_DEVICE , default_model, +"virtio" ,"virtio-net-pci" ); +} + +bool pci_init_nic_in_slot (PCIBus *rootbus,const char *model, +const char *alias,const char *devaddr) +{ +NICInfo *nd =qemu_find_nic_info (model, true, alias); +int dom, busnr, devfn; +PCIDevice *pci_dev; +unsigned slot; +PCIBus *bus; + +if (!nd) { +return false; + } + +if (!devaddr ||pci_parse_devaddr (devaddr, &dom, &busnr, &slot,NULL ) <0 ) { +error_report ("Invalid PCI device address %s for device %s" , + devaddr, model); +exit (1 ); + } + +if (dom !=0 ) { +error_report ("No support for non-zero PCI domains" ); +exit (1 ); + } + + devfn =PCI_DEVFN (slot,0 ); + + bus =pci_find_bus_nr (rootbus, busnr); +if (!bus) { +error_report ("Invalid PCI device address %s for device %s" , + devaddr, model); +exit (1 ); + } + + pci_dev =pci_new (devfn, model); +qdev_set_nic_properties (&pci_dev->qdev, nd); +pci_realize_and_unref (pci_dev, bus, &error_fatal); +return true; +} +PCIDevice *pci_vga_init (PCIBus *bus) { vga_interface_created = true;
include/hw/pci/pci.h +3 -1
@@ -317,7 +317,9 @@ void pci_device_reset(PCIDevice *dev);PCIDevice *pci_nic_init_nofail (NICInfo *nd,PCIBus *rootbus,const char *default_model,const char *default_devaddr); - +void pci_init_nic_devices (PCIBus *bus,const char *default_model); +bool pci_init_nic_in_slot (PCIBus *rootbus,const char *default_model, +const char *alias,const char *devaddr);PCIDevice *pci_vga_init (PCIBus *bus);static inline PCIBus *pci_get_bus (const PCIDevice *dev)
Signature · 1 line
2.41.0
Re: [PATCH for-8.3 v2 04/46] hw/pci: add pci_init_nic_devices(), pci_init_nic_in_slot()
Hi David,
Quoted 56 lines · David Woodhouse
From: David Woodhouse <[email protected]>
The loop over nd_table[] to add PCI NICs is repeated in quite a few places. Add a helper function to do it.
Some platforms also try to instantiate a specific model in a specific slot, to match the real hardware. Add
pci_init_nic_in_slot()for that purpose.Signed-off-by David Woodhouse <[email protected]>Reviewed-by Paul Durrant <[email protected]>--- hw/pci/pci.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 4 +++- 2 files changed, 48 insertions(+), 1 deletion(-)hw/pci/pci.c +32
-0@@ -1925,6 +1925,51 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,return pci_dev; } +void pci_init_nic_devices (PCIBus *bus,const char *default_model) +{ +qemu_create_nic_bus_devices (&bus->qbus,TYPE_PCI_DEVICE , default_model, +"virtio" ,"virtio-net-pci" ); +} + +bool pci_init_nic_in_slot (PCIBus *rootbus,const char *model, +const char *alias,const char *devaddr) +{ +NICInfo *nd =qemu_find_nic_info (model, true, alias); +int dom, busnr, devfn; +PCIDevice *pci_dev; +unsigned slot; +PCIBus *bus; + +if (!nd) { +return false; + } + +if (!devaddr ||pci_parse_devaddr (devaddr, &dom, &busnr, &slot,NULL ) <0 ) { +error_report ("Invalid PCI device address %s for device %s" , + devaddr, model); +exit (1 ); + } + +if (dom !=0 ) { +error_report ("No support for non-zero PCI domains" ); +exit (1 ); + } + + devfn =PCI_DEVFN (slot,0 ); +
hw/pci/pci.c PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, · line 1969
Quoted 10 lines
hw/pci/pci.c +10
-0+ bus =pci_find_bus_nr (rootbus, busnr); +if (!bus) { +error_report ("Invalid PCI device address %s for device %s" , + devaddr, model); +exit (1 ); + } + + pci_dev =pci_new (devfn, model); +qdev_set_nic_properties (&pci_dev->qdev, nd); +pci_realize_and_unref (pci_dev, bus, &error_fatal);
Could these functions be used with hotplug devices?
If so we should propagate the error, not make it fatal.
Quoted 21 lines
hw/pci/pci.c +3
-0+return true; +} +PCIDevice *pci_vga_init (PCIBus *bus) { vga_interface_created = true;include/hw/pci/pci.h +3
-1@@ -317,7 +317,9 @@ void pci_device_reset(PCIDevice *dev);PCIDevice *pci_nic_init_nofail (NICInfo *nd,PCIBus *rootbus,const char *default_model,const char *default_devaddr); - +void pci_init_nic_devices (PCIBus *bus,const char *default_model); +bool pci_init_nic_in_slot (PCIBus *rootbus,const char *default_model, +const char *alias,const char *devaddr);PCIDevice *pci_vga_init (PCIBus *bus);static inline PCIBus *pci_get_bus (const PCIDevice *dev)
Re: [PATCH for-8.3 v2 04/46] hw/pci: add pci_init_nic_devices(), pci_init_nic_in_slot()
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 4 lines
+
pci_dev=pci_new(devfn, model);
+qdev_set_nic_properties(&pci_dev->qdev, nd); +pci_realize_and_unref(pci_dev, bus, &error_fatal);Could these functions be used with hotplug devices?
If so we should propagate the error, not make it fatal.
Hm, not sure. Mostly, I'm trying not to change existing behaviour with this series (except in carefully noted cases where the minutiæ of the existing behaviour appear to be both unintended and unimportant, and it would be unnecessarily complex to preserve the gratuitous differences between the way that platforms have open-coded things).
I don't think it makes much sense *even* to use the new qemu_configure_nic_device() with hotplug devices. The user might create a *netdev* at startup, for later hotplug devices to use. But they wouldn't use -nic for that, and any devices explicitly added through hotplug will have an explicitly specified netdev, won't they?
I don't think we want to change that model and allow hotplug devices to magically get config from -nic on the command line... do we?
We even have a warning for the case where NIC configurations are provided with -nic but aren't consumed by the time the platform is instantiated (although that doesn't *prevent* them from being used later by hotplug).
But that's answering your question which was about "these functions".
For *this* particular function, pci_init_nic_in_slot(), it makes even less sense to consider hotplug. This is for platforms to handle the special cases, like "this board had an RTL8139 in slot 3", and make that NIC appear in the appropriate slot. It's done as a special case before processing the rest of the NICs which land in dynamically assigned slots — which may even be on a *different* bus, in the case of sun4u.
PATCH v2 5/46 hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Eliminate direct access to nd_table[] and nb_nics by processing the the Xen and ISA NICs first and then calling pci_init_nic_devices() for the rest.
--- hw/i386/pc.c | 26 ++++++++++++++++---------- include/hw/net/ne2000-isa.h | 2 -- 2 files changed, 16 insertions(+), 12 deletions(-)
hw/i386/pc.c +16 -10
@@ -652,8 +652,11 @@ static void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) {static int nb_ne2k =0 ; -if (nb_ne2k ==NE2000_NB_MAX ) +if (nb_ne2k ==NE2000_NB_MAX ) { +error_setg (&error_fatal, +"maximum number of ISA NE2000 devices exceeded" );return ; + }isa_ne2000_init (bus, ne2000_io[nb_ne2k], ne2000_irq[nb_ne2k], nd); nb_ne2k++;
@@ -1291,23 +1294,26 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus, BusState *xen_bus) {MachineClass *mc =MACHINE_CLASS (pcmc); -int i; +bool default_is_ne2k =g_str_equal (mc->default_nic,TYPE_ISA_NE2000 ); +NICInfo *nd;rom_set_order_override (FW_CFG_ORDER_OVERRIDE_NIC ); -for (i =0 ; i < nb_nics; i++) { -NICInfo *nd = &nd_table[i]; -const char *model = nd->model ? nd->model : mc->default_nic; -if (xen_bus && (!nd->model ||g_str_equal (model,"xen-net-device" ))) { +if (xen_bus) { +while (nc =qemu_find_nic_info ("xen-net-device" , true,NULL )) {DeviceState *dev =qdev_new ("xen-net-device" );qdev_set_nic_properties (dev, nd);qdev_realize_and_unref (dev, xen_bus, &error_fatal); - }else if (g_str_equal (model,"ne2k_isa" )) { -pc_init_ne2k_isa (isa_bus, nd); - }else { -pci_nic_init_nofail (nd, pci_bus, model,NULL ); } } + +while ((nd =qemu_find_nic_info (TYPE_ISA_NE2000 , default_is_ne2k,NULL ))) { +pc_init_ne2k_isa (isa_bus, nd); + } + +/* Anything remaining should be a PCI NIC */ +pci_init_nic_devices (pci_bus, mc->default_nic); +rom_reset_order_override (); }
include/hw/net/ne2000-isa.h +0 -2
@@ -22,8 +22,6 @@ static inline ISADevice *isa_ne2000_init(ISABus *bus, int base, int irq, {ISADevice *d; -qemu_check_nic_model (nd,"ne2k_isa" ); - d =isa_try_new (TYPE_ISA_NE2000 );if (d) {DeviceState *dev =DEVICE (d);
Signature · 1 line
2.41.0
Re: [PATCH for-8.3 v2 05/46] hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices()
Hi David,
+Markus/Bernhard
Quoted 18 lines · David Woodhouse
From: David Woodhouse <[email protected]>
Eliminate direct access to nd_table[] and
nb_nicsby processing the the Xen and ISA NICs first and then callingpci_init_nic_devices()for the rest.Signed-off-by David Woodhouse <[email protected]>Reviewed-by Paul Durrant <[email protected]>--- hw/i386/pc.c | 26 ++++++++++++++++---------- include/hw/net/ne2000-isa.h | 2 -- 2 files changed, 16 insertions(+), 12 deletions(-)hw/i386/pc.c +0
-0
hw/i386/pc.c static void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) · line 656
Quoted 6 lines
hw/i386/pc.c +2
-1@@ -652,8 +652,11 @@ static void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) {static int nb_ne2k =0 ; -if (nb_ne2k ==NE2000_NB_MAX ) +if (nb_ne2k ==NE2000_NB_MAX ) { + error_setg(&error_fatal,
In the context of dynamically created machines I'd rather have this function,
Quoted 15 lines
hw/i386/pc.c +4
-1+ "maximum number of ISA NE2000 devices exceeded");return ; + }isa_ne2000_init (bus, ne2000_io[nb_ne2k], ne2000_irq[nb_ne2k], nd); nb_ne2k++;@@ -1291,23 +1294,26 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus, BusState *xen_bus) {MachineClass *mc =MACHINE_CLASS (pcmc); -int i; +bool default_is_ne2k =g_str_equal (mc->default_nic,TYPE_ISA_NE2000 ); +NICInfo *nd;rom_set_order_override (FW_CFG_ORDER_OVERRIDE_NIC );
hw/i386/pc.c void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus, · line 1306
Quoted 10 lines
hw/i386/pc.c +2
-4-for (i =0 ; i < nb_nics; i++) { -NICInfo *nd = &nd_table[i]; -const char *model = nd->model ? nd->model : mc->default_nic; -if (xen_bus && (!nd->model ||g_str_equal (model,"xen-net-device" ))) { +if (xen_bus) { +while (nc =qemu_find_nic_info ("xen-net-device" , true,NULL )) {DeviceState *dev =qdev_new ("xen-net-device" );qdev_set_nic_properties (dev, nd);qdev_realize_and_unref (dev, xen_bus, &error_fatal);
and this one non-fatal (primarily for API example). But this is pending on a discussion on another thread, see:
https://lore.kernel.org/qemu-devel/[email protected]/
so no changed requested so far.
hw/i386/pc.c void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus, · line 1308
Quoted 6 lines
hw/i386/pc.c +0
-4- }else if (g_str_equal (model,"ne2k_isa" )) { -pc_init_ne2k_isa (isa_bus, nd); - }else { -pci_nic_init_nofail (nd, pci_bus, model,NULL ); } }
Regards,
Phil.
Re: [PATCH for-8.3 v2 05/46] hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices()
Quoted 55 lines · Philippe Mathieu-Daudé
Hi David,
+Markus/Bernhard
Quoted 20 lines · David Woodhouse
From: David Woodhouse <[email protected]>
Eliminate direct access to nd_table[] and
nb_nicsby processing the the Xen and ISA NICs first and then callingpci_init_nic_devices()for the rest.Signed-off-by David Woodhouse <[email protected]>Reviewed-by Paul Durrant <[email protected]>---
hw/i386/pc.c | 26 ++++++++++++++++----------include/hw/net/ne2000-isa.h| 2 --2 files changed, 16 insertions(+), 12 deletions(-)hw/i386/pc.c +0
-0@@ -652,8 +652,11 @@ static void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) { static int nb_ne2k = 0;Quoted 4 lines
- if (nb_ne2k==NE2000_NB_MAX)
+ if (nb_ne2k==NE2000_NB_MAX) {
+ error_setg(&error_fatal,In the context of dynamically created machines I'd rather have this function,
Quoted 22 lines
+ "maximum number of ISA NE2000 devices exceeded"); return;
+ }
isa_ne2000_init(bus, ne2000_io[nb_ne2k], ne2000_irq[nb_ne2k], nd);
nb_ne2k++;hw/i386/pc.c +2
-1@@ -1291,23 +1294,26 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus, BusState *xen_bus) { MachineClass *mc = MACHINE_CLASS(pcmc); - int i; + bool default_is_ne2k = g_str_equal(mc->default_nic, TYPE_ISA_NE2000); + NICInfo *nd;
rom_set_order_override(FW_CFG_ORDER_OVERRIDE_NIC);
- for (i = 0; i <nb_nics; i++) {
- NICInfo *nd = &nd_table[i];
- const char *model =nd->model?nd->model:mc->default_nic;
- if (xen_bus&& (!nd->model ||g_str_equal(model, "xen-net-device"))) { + if (xen_bus) {
+ while (nc =qemu_find_nic_info("xen-net-device", true, NULL)) {
Quoted 8 lines
Quoted 3 lines
DeviceState *dev =
qdev_new("xen-net-device");qdev_set_nic_properties(dev, nd);qdev_realize_and_unref(dev, xen_bus, &error_fatal);and this one non-fatal (primarily for API example). But this is pending on a discussion on another thread, see:
https://lore.kernel.org/qemu-devel/[email protected]/
so no changed requested so far.
Thanks for the reference.
I'm happy to make pc_init_ne2k_isa() and even pc_nic_init() take an 'Error **' argument and use that instead of &error_fatal... and for the *caller* to pass &error_fatal for now until/unless that discussion is resolved? Not sure it helps much?
Then again... I do not favour the "my caller cannot *currently* handle/propagate an error therefore I won't bother to return one coherently" approach. That leads to someone else thinking "my callee does not return an error coherently therefore I won't bother to handle it", and nothing ever gets fixed.
I'll go fix it to take an errp argument.
PATCH v2 6/46 hw/xen: use qemu_create_nic_bus_devices() to instantiate Xen NICs
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
When instantiating XenBus itself, for each NIC which is configured with either the model unspecified, or set to to "xen" or "xen-net-device", create a corresponding xen-net-device for it.
Now we can revert the previous more hackish version which relied on the platform code explicitly registering the NICs on its own XenBus, having returned the BusState* from xen_bus_init() itself.
This also fixes the setup for Xen PV guests, which was previously broken in various ways and never actually managed to peer with the netdev.
--- hw/i386/pc.c | 13 ++----------- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/xen/xen-bus.c | 6 ++++-- hw/xen/xen_devconfig.c | 25 ------------------------- hw/xenpv/xen_machine_pv.c | 9 --------- include/hw/i386/pc.h | 4 +--- include/hw/xen/xen-bus.h | 2 +- include/hw/xen/xen-legacy-backend.h | 1 - 9 files changed, 10 insertions(+), 54 deletions(-)
hw/i386/pc.c +2 -11
@@ -1262,7 +1262,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,if (pcms->bus) {pci_create_simple (pcms->bus,-1 ,"xen-platform" ); } - pcms->xenbus =xen_bus_init (); +xen_bus_init (); xen_be_init(); }#endif
@@ -1290,8 +1290,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, pcms->vmport != ON_OFF_AUTO_ON); } -void pc_nic_init (PCMachineClass *pcmc,ISABus *isa_bus,PCIBus *pci_bus, -BusState *xen_bus) +void pc_nic_init (PCMachineClass *pcmc,ISABus *isa_bus,PCIBus *pci_bus) {MachineClass *mc =MACHINE_CLASS (pcmc);bool default_is_ne2k =g_str_equal (mc->default_nic,TYPE_ISA_NE2000 );
@@ -1299,14 +1298,6 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus,rom_set_order_override (FW_CFG_ORDER_OVERRIDE_NIC ); -if (xen_bus) { -while (nc =qemu_find_nic_info ("xen-net-device" , true,NULL )) { -DeviceState *dev =qdev_new ("xen-net-device" ); -qdev_set_nic_properties (dev, nd); -qdev_realize_and_unref (dev, xen_bus, &error_fatal); - } - } -while ((nd =qemu_find_nic_info (TYPE_ISA_NE2000 , default_is_ne2k,NULL ))) {pc_init_ne2k_isa (isa_bus, nd); }
hw/i386/pc_piix.c +1 -1
@@ -342,7 +342,7 @@ static void pc_init1(MachineState *machine,pc_basic_device_init (pcms, isa_bus, x86ms->gsi, rtc_state, true,0x4 ); -pc_nic_init (pcmc, isa_bus, pci_bus, pcms->xenbus); +pc_nic_init (pcmc, isa_bus, pci_bus);if (pcmc->pci_enabled) {pc_cmos_init (pcms, idebus[0 ], idebus[1 ], rtc_state);
hw/i386/pc_q35.c +1 -1
@@ -340,7 +340,7 @@ static void pc_q35_init(MachineState *machine)/* the rest devices to which pci devfn is automatically assigned */ pc_vga_init (isa_bus, host_bus); -pc_nic_init (pcmc, isa_bus, host_bus, pcms->xenbus); +pc_nic_init (pcmc, isa_bus, host_bus);if (machine->nvdimms_state->is_enabled) { nvdimm_init_acpi_state(machine->nvdimms_state, system_io,
hw/xen/xen-bus.c +4 -2
@@ -19,6 +19,7 @@#include "qapi/error.h" #include "qapi/qmp/qdict.h" #include "sysemu/sysemu.h" +#include "net/net.h" #include "trace.h" static char *xen_device_get_backend_path (XenDevice *xendev)
@@ -1133,7 +1134,7 @@ static void xen_register_types(void)type_init (xen_register_types) -BusState *xen_bus_init(void) +void xen_bus_init(void) {DeviceState *dev =qdev_new (TYPE_XEN_BRIDGE );BusState *bus =qbus_new (TYPE_XEN_BUS , dev,NULL );
@@ -1141,5 +1142,6 @@ BusState *xen_bus_init(void)sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);qbus_set_bus_hotplug_handler (bus); -return bus; +qemu_create_nic_bus_devices (bus,TYPE_XEN_DEVICE ,"xen-net-device" , +"xen" ,"xen-net-device" ); }
hw/xen/xen_devconfig.c +0 -25
@@ -46,31 +46,6 @@ static int xen_config_dev_all(char *fe, char *be)/* ------------------------------------------------------------- */ -int xen_config_dev_nic (NICInfo *nic) -{ -char fe[256 ], be[256 ]; -char mac[20 ]; -int vlan_id =-1 ; - -net_hub_id_for_client (nic->netdev, &vlan_id); -snprintf (mac,sizeof (mac),"%02x:%02x:%02x:%02x:%02x:%02x" , - nic->macaddr.a[0 ], nic->macaddr.a[1 ], nic->macaddr.a[2 ], - nic->macaddr.a[3 ], nic->macaddr.a[4 ], nic->macaddr.a[5 ]); -xen_pv_printf (NULL ,1 ,"config nic %d: mac=\"%s\"\n" , vlan_id, mac); -xen_config_dev_dirs ("vif" ,"qnic" , vlan_id, fe, be,sizeof (fe)); - -/* frontend */ -xenstore_write_int (fe,"handle" , vlan_id); -xenstore_write_str (fe,"mac" , mac); - -/* backend */ -xenstore_write_int (be,"handle" , vlan_id); -xenstore_write_str (be,"mac" , mac); - -/* common stuff */ -return xen_config_dev_all (fe, be); -} -int xen_config_dev_vfb (int vdev,const char *type) {char fe[256 ], be[256 ];
hw/xenpv/xen_machine_pv.c +0 -9
@@ -32,8 +32,6 @@static void xen_init_pv (MachineState *machine) { -int i; -setup_xen_backend_ops ();/* Initialize backend core & drivers */
@@ -62,13 +60,6 @@ static void xen_init_pv(MachineState *machine) vga_interface_created = true; } -/* configure nics */ -for (i =0 ; i < nb_nics; i++) { -if (!nd_table[i].model ||0 !=strcmp (nd_table[i].model,"xen" )) -continue ; -xen_config_dev_nic (nd_table + i); - } -xen_bus_init ();/* config cleanup hook */
include/hw/i386/pc.h +1 -3
@@ -33,7 +33,6 @@ typedef struct PCMachineState {/* Pointers to devices and objects: */ PCIBus *bus; -BusState *xenbus;I2CBus *smbus;PFlashCFI01 *flash[2 ];ISADevice *pcspk;
@@ -185,8 +184,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,void pc_cmos_init (PCMachineState *pcms,BusState *ide0,BusState *ide1,ISADevice *s); -void pc_nic_init (PCMachineClass *pcmc,ISABus *isa_bus,PCIBus *pci_bus, -BusState *xen_bus); +void pc_nic_init (PCMachineClass *pcmc,ISABus *isa_bus,PCIBus *pci_bus);void pc_i8259_create (ISABus *isa_bus,qemu_irq *i8259_irqs);
include/hw/xen/xen-bus.h +1 -1
@@ -75,7 +75,7 @@ struct XenBusClass {OBJECT_DECLARE_TYPE (XenBus, XenBusClass, XEN_BUS) -BusState *xen_bus_init(void); +void xen_bus_init (void );void xen_device_backend_set_state (XenDevice *xendev,enum xenbus_state state);
include/hw/xen/xen-legacy-backend.h +0 -1
@@ -81,7 +81,6 @@ extern struct XenDevOps xen_usb_ops; /* xen-usb.c *//* configuration (aka xenbus setup) */ void xen_config_cleanup (void ); -int xen_config_dev_nic (NICInfo *nic);int xen_config_dev_vfb (int vdev,const char *type);int xen_config_dev_vkbd (int vdev);int xen_config_dev_console (int vdev);
Signature · 1 line
2.41.0
PATCH v2 7/46 hw/alpha/dp264: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/alpha/dp264.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/alpha/dp264.c +1 -3
@@ -124,9 +124,7 @@ static void clipper_init(MachineState *machine)pci_vga_init (pci_bus);/* Network setup. e1000 is good enough, failing Tulip support. */ -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci_bus, mc->default_nic);/* Super I/O */ isa_create_simple (isa_bus,TYPE_SMC37C669_SUPERIO );
Signature · 1 line
2.41.0
PATCH v2 8/46 hw/arm/sbsa-ref: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/sbsa-ref.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/arm/sbsa-ref.c +1 -3
@@ -689,9 +689,7 @@ static void create_pcie(SBSAMachineState *sms) pci =PCI_HOST_BRIDGE (dev);if (pci->bus) { -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci->bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci->bus, mc->default_nic); }pci_create_simple (pci->bus,-1 ,"bochs-display" );
Signature · 1 line
2.41.0
PATCH v2 9/46 hw/arm/virt: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/arm/virt.c +1 -3
@@ -1481,9 +1481,7 @@ static void create_pcie(VirtMachineState *vms) pci->bypass_iommu = vms->default_bus_bypass_iommu; vms->bus = pci->bus;if (vms->bus) { -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci->bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci->bus, mc->default_nic); } nodename = vms->pciehb_nodename =g_strdup_printf ("/pcie@%" PRIx64, base);
Signature · 1 line
2.41.0
PATCH v2 10/46 hw/hppa: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/hppa/machine.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
hw/hppa/machine.c +2 -5
@@ -309,7 +309,6 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus)uint64_t kernel_entry =0 , kernel_low, kernel_high;MemoryRegion *addr_space =get_system_memory ();MemoryRegion *rom_region; -long i;unsigned int smp_cpus = machine->smp.cpus;SysBusDevice *s;
@@ -333,10 +332,8 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus) qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA)); } -for (i =0 ; i < nb_nics; i++) { -if (!enable_lasi_lan ()) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic,NULL ); - } +if (!enable_lasi_lan ()) { +pci_init_nic_devices (pci_bus, mc->default_nic); }/* BMC board: HP Powerbar SP2 Diva (with console only) */
Signature · 1 line
2.41.0
PATCH v2 11/46 hw/loongarch: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/loongarch/virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/loongarch/virt.c +1 -3
@@ -504,9 +504,7 @@ static void loongarch_devices_init(DeviceState *pch_pic, LoongArchMachineState *fdt_add_uart_node (lams);/* Network init */ -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci_bus, mc->default_nic);/* * There are some invalid guest memory access.
Signature · 1 line
2.41.0
PATCH v2 12/46 hw/mips/fuloong2e: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
The previous behaviour was: *if* the first NIC specified on the command line was an RTL8139 (or unspecified model) then it gets assigned to PCI slot 7, which is where the Fuloong board had an RTL8139. All other devices (including the first, if it was specified a anything other then an rtl8319) get dynamically assigned on the bus.
The new behaviour is subtly different: If the first NIC was given a specific model *other* than rtl8139, and a subsequent NIC was not, then the rtl8139 (or unspecified) NIC will go to slot 7 and the rest will be dynamically assigned.
--- hw/mips/fuloong2e.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
hw/mips/fuloong2e.c +3 -13
@@ -201,19 +201,9 @@ static void main_cpu_reset(void *opaque)/* Network support */ static void network_init (PCIBus *pci_bus) { -int i; - -for (i =0 ; i < nb_nics; i++) { -NICInfo *nd = &nd_table[i]; -const char *default_devaddr =NULL ; - -if (i ==0 && (!nd->model ||strcmp (nd->model,"rtl8139" ) ==0 )) { -/* The Fuloong board has a RTL8139 card using PCI SLOT 7 */ - default_devaddr ="07" ; - } - -pci_nic_init_nofail (nd, pci_bus,"rtl8139" , default_devaddr); - } +/* The Fuloong board has a RTL8139 card using PCI SLOT 7 */ +pci_init_nic_in_slot (pci_bus,"rtl8139" ,NULL ,"07" ); +pci_init_nic_devices (pci_bus,"rtl8139" ); }static void mips_fuloong2e_init (MachineState *machine)
Signature · 1 line
2.41.0
PATCH v2 13/46 hw/mips/malta: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
The Malta board setup code would previously place the first NIC into PCI slot 11 if was a PCNet card, and the rest (including the first if it was anything other than a PCNet card) would be dynamically assigned.
Now it will place any PCNet NIC into slot 11, and then anything else will be dynamically assigned.
--- hw/mips/malta.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
hw/mips/malta.c +3 -12
@@ -605,18 +605,9 @@ static MaltaFPGAState *malta_fpga_init(MemoryRegion *address_space,/* Network support */ static void network_init (PCIBus *pci_bus) { -int i; - -for (i =0 ; i < nb_nics; i++) { -NICInfo *nd = &nd_table[i]; -const char *default_devaddr =NULL ; - -if (i ==0 && (!nd->model ||strcmp (nd->model,"pcnet" ) ==0 )) -/* The malta board has a PCNet card using PCI SLOT 11 */ - default_devaddr ="0b" ; - -pci_nic_init_nofail (nd, pci_bus,"pcnet" , default_devaddr); - } +/* The malta board has a PCNet card using PCI SLOT 11 */ +pci_init_nic_in_slot (pci_bus,"pcnet" ,NULL ,"0b" ); +pci_init_nic_devices (pci_bus,"pcnet" ); } static void bl_setup_gt64120_jump_kernel(void **p, uint64_t run_addr,
Signature · 1 line
2.41.0
PATCH v2 14/46 hw/mips/loongson3_virt: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/mips/loongson3_virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/mips/loongson3_virt.c +1 -3
@@ -451,9 +451,7 @@ static inline void loongson3_virt_devices_init(MachineState *machine,usb_create_simple (usb_bus_find (-1 ),"usb-tablet" ); } -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci_bus, mc->default_nic); }static void mips_loongson3_virt_init (MachineState *machine)
Signature · 1 line
2.41.0
PATCH v2 15/46 hw/ppc/prep: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Previously, the first PCI NIC would be placed in PCI slot 3 and the rest would be dynamically assigned. Even if the user overrode the default NIC type and made it something other than PCNet.
Now, the first PCNet NIC (that is, anything not explicitly specified to be anything different) will go to slot 3 even if it isn't the first NIC specified on the commnd line. And anything else will be dynamically assigned.
--- hw/ppc/prep.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
hw/ppc/prep.c +3 -5
@@ -241,7 +241,6 @@ static void ibm_40p_init(MachineState *machine)ISADevice *isa_dev;ISABus *isa_bus;void *fw_cfg; -int i;uint32_t kernel_base =0 , initrd_base =0 ;long kernel_size =0 , initrd_size =0 ;char boot_device;
@@ -336,10 +335,9 @@ static void ibm_40p_init(MachineState *machine)/* XXX: s3-trio at PCI_DEVFN(2, 0) */ pci_vga_init (pci_bus); -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic, - i ==0 ?"3" :NULL ); - } +/* First PCNET device at PCI_DEVFN(3, 0) */ +pci_init_nic_in_slot (pci_bus, mc->default_nic,NULL ,"3" ); +pci_init_nic_devices (pci_bus, mc->default_nic); }/* Prepare firmware configuration for OpenBIOS */
Signature · 1 line
2.41.0
PATCH v2 16/46 hw/ppc/spapr: use qemu_get_nic_info() and pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Avoid directly referencing nd_table[] by first instantiating any spapr-vlan devices using a qemu_get_nic_info() loop, then calling pci_init_nic_devices() to do the rest.
No functional change intended.
--- hw/ppc/spapr.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-)
hw/ppc/spapr.c +5 -13
@@ -2796,6 +2796,7 @@ static void spapr_machine_init(MachineState *machine)MemoryRegion *sysmem =get_system_memory ();long load_limit, fw_size;Error *resize_hpt_err =NULL ; +NICInfo *nd;if (!filename) {error_report ("Could not find LPAR firmware '%s'" , bios_name);
@@ -2996,21 +2997,12 @@ static void spapr_machine_init(MachineState *machine) phb =spapr_create_default_phb (); -for (i =0 ; i < nb_nics; i++) { -NICInfo *nd = &nd_table[i]; - -if (!nd->model) { - nd->model =g_strdup ("spapr-vlan" ); - } - -if (g_str_equal (nd->model,"spapr-vlan" ) || -g_str_equal (nd->model,"ibmveth" )) { -spapr_vlan_create (spapr->vio_bus, nd); - }else { -pci_nic_init_nofail (&nd_table[i], phb->bus, nd->model,NULL ); - } +while ((nd =qemu_find_nic_info ("spapr-vlan" , true,"ibmveth" ))) { +spapr_vlan_create (spapr->vio_bus, nd); } +pci_init_nic_devices (phb->bus,NULL ); +for (i =0 ; i <=drive_get_max_bus (IF_SCSI ); i++) {spapr_vscsi_create (spapr->vio_bus); }
Signature · 1 line
2.41.0
PATCH v2 17/46 hw/ppc: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/ppc/e500.c | 4 +--- hw/ppc/mac_newworld.c | 4 +--- hw/ppc/mac_oldworld.c | 4 +--- hw/ppc/ppc440_bamboo.c | 14 +++++--------- 4 files changed, 8 insertions(+), 18 deletions(-)
hw/ppc/e500.c +1 -3
@@ -1075,9 +1075,7 @@ void ppce500_init(MachineState *machine)if (pci_bus) {/* Register network interfaces. */ -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci_bus, mc->default_nic); }/* Register spinning region */
hw/ppc/mac_newworld.c +1 -3
@@ -444,9 +444,7 @@ static void ppc_core99_init(MachineState *machine) graphic_depth =15 ; } -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci_bus, mc->default_nic);/* The NewWorld NVRAM is not located in the MacIO device */ if (kvm_enabled () &&qemu_real_host_page_size () >4096 ) {
hw/ppc/mac_oldworld.c +1 -3
@@ -277,9 +277,7 @@ static void ppc_heathrow_init(MachineState *machine)pci_vga_init (pci_bus); -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci_bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci_bus, mc->default_nic);/* MacIO IDE */ ide_drive_get (hd,ARRAY_SIZE (hd));
hw/ppc/ppc440_bamboo.c +5 -9
@@ -161,7 +161,6 @@ static void bamboo_init(MachineState *machine)DeviceState *uicdev;SysBusDevice *uicsbd;int success; -int i;if (kvm_enabled ()) { error_report("machine %s does not support the KVM accelerator",
@@ -234,14 +233,11 @@ static void bamboo_init(MachineState *machine) }if (pcibus) { -/* Register network interfaces. */ -for (i =0 ; i < nb_nics; i++) { -/* -* There are no PCI NICs on the Bamboo board, but there are -* PCI slots, so we can pick whatever default model we want. -*/ -pci_nic_init_nofail (&nd_table[i], pcibus, mc->default_nic,NULL ); - } +/* +* There are no PCI NICs on the Bamboo board, but there are +* PCI slots, so we can pick whatever default model we want. +*/ +pci_init_nic_devices (pcibus, mc->default_nic); }/* Load kernel. */
Signature · 1 line
2.41.0
PATCH v2 18/46 hw/sh4/r2d: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Previously, the first PCI NIC would be assigned to slot 2 even if the user override the model and made it something other than an rtl8139 which is the default. Everything else would be dynamically assigned.
Now, the first rtl8139 gets slot 2 and everything else is dynamic.
--- hw/sh4/r2d.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/sh4/r2d.c +2 -4
@@ -240,7 +240,6 @@ static void r2d_init(MachineState *machine)MemoryRegion *sdram =g_new (MemoryRegion,1 );qemu_irq *irq;DriveInfo *dinfo; -int i;DeviceState *dev;SysBusDevice *busdev;MemoryRegion *address_space_mem =get_system_memory ();
@@ -309,9 +308,8 @@ static void r2d_init(MachineState *machine) 0x555, 0x2aa, 0);/* NIC: rtl8139 on-board, and 2 slots. */ -for (i =0 ; i < nb_nics; i++) -pci_nic_init_nofail (&nd_table[i], pci_bus, - mc->default_nic, i ==0 ?"2" :NULL ); +pci_init_nic_in_slot (pci_bus, mc->default_nic,NULL ,"2" ); +pci_init_nic_devices (pci_bus, mc->default_nic);/* USB keyboard */ usb_create_simple (usb_bus_find (-1 ),"usb-kbd" );
Signature · 1 line
2.41.0
PATCH v2 19/46 hw/sparc64/sun4u: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
The first sunhme NIC gets placed a function 1 on slot 1 of PCI bus A, and the rest are dynamically assigned on PCI bus B.
Previously, any PCI NIC would get the special treatment purely by virtue of being first in the list.
--- hw/sparc64/sun4u.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
hw/sparc64/sun4u.c +8 -19
@@ -642,29 +642,18 @@ static void sun4uv_init(MemoryRegion *address_space_mem,memset (&macaddr,0 ,sizeof (MACAddr)); onboard_nic = false; -for (i =0 ; i < nb_nics; i++) { -PCIBus *bus; - nd = &nd_table[i]; - -if (!nd->model ||strcmp (nd->model, mc->default_nic) ==0 ) { -if (!onboard_nic) { - pci_dev =pci_new_multifunction (PCI_DEVFN (1 ,1 ), mc->default_nic); - bus = pci_busA; -memcpy (&macaddr, &nd->macaddr.a,sizeof (MACAddr)); - onboard_nic = true; - }else { - pci_dev =pci_new (-1 , mc->default_nic); - bus = pci_busB; - } - }else { - pci_dev =pci_new (-1 , nd->model); - bus = pci_busB; - } + nd =qemu_find_nic_info (mc->default_nic, true,NULL ); +if (nd) { + pci_dev =pci_new_multifunction (PCI_DEVFN (1 ,1 ), mc->default_nic); dev = &pci_dev->qdev;qdev_set_nic_properties (dev, nd); -pci_realize_and_unref (pci_dev, bus, &error_fatal); +pci_realize_and_unref (pci_dev, pci_busA, &error_fatal); + +memcpy (&macaddr, &nd->macaddr.a,sizeof (MACAddr)); + onboard_nic = true; } +pci_init_nic_devices (pci_busB, mc->default_nic);/* If we don't have an onboard NIC, grab a default MAC address so that * we have a valid machine id */
Signature · 1 line
2.41.0
PATCH v2 20/46 hw/xtensa/virt: use pci_init_nic_devices()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/xtensa/virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/xtensa/virt.c +1 -3
@@ -102,9 +102,7 @@ static void create_pcie(MachineState *ms, CPUXtensaState *env, int irq_base, pci =PCI_HOST_BRIDGE (dev);if (pci->bus) { -for (i =0 ; i < nb_nics; i++) { -pci_nic_init_nofail (&nd_table[i], pci->bus, mc->default_nic,NULL ); - } +pci_init_nic_devices (pci->bus, mc->default_nic); } }
Signature · 1 line
2.41.0
PATCH v2 21/46 hw/arm/allwinner: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/allwinner-a10.c | 6 +----- hw/arm/allwinner-h3.c | 6 +----- hw/arm/allwinner-r40.c | 27 ++------------------------- 3 files changed, 4 insertions(+), 35 deletions(-)
hw/arm/allwinner-a10.c +1 -5
@@ -142,11 +142,7 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)sysbus_realize (SYS_BUS_DEVICE (&s->dramc), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (&s->dramc),0 ,AW_A10_DRAMC_BASE ); -/* FIXME use qdev NIC properties instead of nd_table[] */ -if (nd_table[0 ].used) { -qemu_check_nic_model (&nd_table[0 ],TYPE_AW_EMAC ); -qdev_set_nic_properties (DEVICE (&s->emac), &nd_table[0 ]); - } +qemu_configure_nic_device (DEVICE (&s->emac), true,NULL );if (!sysbus_realize (SYS_BUS_DEVICE (&s->emac), errp)) {return ; }
hw/arm/allwinner-h3.c +1 -5
@@ -369,11 +369,7 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp) "sd-bus");/* EMAC */ -/* FIXME use qdev NIC properties instead of nd_table[] */ -if (nd_table[0 ].used) { -qemu_check_nic_model (&nd_table[0 ],TYPE_AW_SUN8I_EMAC ); -qdev_set_nic_properties (DEVICE (&s->emac), &nd_table[0 ]); - } +qemu_configure_nic_device (DEVICE (&s->emac), true,NULL );object_property_set_link (OBJECT (&s->emac),"dma-memory" ,OBJECT (get_system_memory ()), &error_fatal);sysbus_realize (SYS_BUS_DEVICE (&s->emac), &error_fatal);
hw/arm/allwinner-r40.c +2 -25
@@ -294,7 +294,6 @@ static void allwinner_r40_init(Object *obj)static void allwinner_r40_realize (DeviceState *dev,Error **errp) { -const char *r40_nic_models[] = {"gmac" ,"emac" ,NULL };AwR40State *s =AW_R40 (dev);/* CPUs */
@@ -454,31 +453,8 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)sysbus_mmio_map (SYS_BUS_DEVICE (&s->dramc),2 , s->memmap[AW_R40_DEV_DRAMPHY ]); -/* nic support gmac and emac */ -for (int i =0 ; i <ARRAY_SIZE (r40_nic_models) -1 ; i++) { -NICInfo *nic = &nd_table[i]; - -if (!nic->used) { -continue ; - } -if (qemu_show_nic_models (nic->model, r40_nic_models)) { -exit (0 ); - } - -switch (qemu_find_nic_model (nic, r40_nic_models, r40_nic_models[0 ])) { -case 0 :/* gmac */ -qdev_set_nic_properties (DEVICE (&s->gmac), nic); -break ; -case 1 :/* emac */ -qdev_set_nic_properties (DEVICE (&s->emac), nic); -break ; -default : -exit (1 ); -break ; - } - } -/* GMAC */ +qemu_configure_nic_device (DEVICE (&s->gmac), true,"gmac" );object_property_set_link (OBJECT (&s->gmac),"dma-memory" ,OBJECT (get_system_memory ()), &error_fatal);sysbus_realize (SYS_BUS_DEVICE (&s->gmac), &error_fatal);
@@ -487,6 +463,7 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp) qdev_get_gpio_in(DEVICE(&s->gic), AW_R40_GIC_SPI_GMAC));/* EMAC */ +qemu_configure_nic_device (DEVICE (&s->emac), true,"emac" );sysbus_realize (SYS_BUS_DEVICE (&s->emac), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (&s->emac),0 , s->memmap[AW_R40_DEV_EMAC ]); sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,
Signature · 1 line
2.41.0
PATCH v2 22/46 hw/arm/aspeed: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/aspeed.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
hw/arm/aspeed.c +4 -5
@@ -356,7 +356,6 @@ static void aspeed_machine_init(MachineState *machine)AspeedMachineClass *amc =ASPEED_MACHINE_GET_CLASS (machine);AspeedSoCClass *sc;int i; -NICInfo *nd = &nd_table[0 ]; bmc->soc =ASPEED_SOC (object_new (amc->soc_name));object_property_add_child (OBJECT (machine),"soc" ,OBJECT (bmc->soc));
@@ -371,10 +370,10 @@ static void aspeed_machine_init(MachineState *machine) &error_fatal);for (i =0 ; i < sc->macs_num; i++) { -if ((amc->macs_mask & (1 << i)) && nd->used) { -qemu_check_nic_model (nd,TYPE_FTGMAC100 ); -qdev_set_nic_properties (DEVICE (&bmc->soc->ftgmac100[i]), nd); - nd++; +if ((amc->macs_mask & (1 << i)) && + !qemu_configure_nic_device (DEVICE (&bmc->soc->ftgmac100[i]), + true,NULL )) { +break ;/* No configs left; stop asking */ } }
Signature · 1 line
2.41.0
PATCH v2 23/46 hw/arm/exynos4: use qemu_create_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/exynos4_boards.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
hw/arm/exynos4_boards.c +2 -4
@@ -76,10 +76,8 @@ static void lan9215_init(uint32_t base, qemu_irq irq)SysBusDevice *s;/* This should be a 9215 but the 9118 is close enough */ -if (nd_table[0 ].used) { -qemu_check_nic_model (&nd_table[0 ],"lan9118" ); - dev =qdev_new (TYPE_LAN9118 ); -qdev_set_nic_properties (dev, &nd_table[0 ]); + dev =qemu_create_nic_device (TYPE_LAN9118 , true,NULL ); +if (dev) {qdev_prop_set_uint32 (dev,"mode_16bit" ,1 ); s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);
Signature · 1 line
2.41.0
PATCH v2 24/46 hw/arm/fsl: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/fsl-imx25.c | 2 +- hw/arm/fsl-imx6.c | 2 +- hw/arm/fsl-imx6ul.c | 2 +- hw/arm/fsl-imx7.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
hw/arm/fsl-imx25.c +1 -1
@@ -170,7 +170,7 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp) }object_property_set_uint (OBJECT (&s->fec),"phy-num" , s->phy_num, &err); -qdev_set_nic_properties (DEVICE (&s->fec), &nd_table[0 ]); +qemu_configure_nic_device (DEVICE (&s->fec), true,NULL );if (!sysbus_realize (SYS_BUS_DEVICE (&s->fec), errp)) {return ;
hw/arm/fsl-imx6.c +1 -1
@@ -380,7 +380,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp) }object_property_set_uint (OBJECT (&s->eth),"phy-num" , s->phy_num, &err); -qdev_set_nic_properties (DEVICE (&s->eth), &nd_table[0 ]); +qemu_configure_nic_device (DEVICE (&s->eth), true,NULL );if (!sysbus_realize (SYS_BUS_DEVICE (&s->eth), errp)) {return ; }
hw/arm/fsl-imx6ul.c +1 -1
@@ -442,7 +442,7 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) s->phy_num[i], &error_abort);object_property_set_uint (OBJECT (&s->eth[i]),"tx-ring-num" ,FSL_IMX6UL_ETH_NUM_TX_RINGS , &error_abort); -qdev_set_nic_properties (DEVICE (&s->eth[i]), &nd_table[i]); +qemu_configure_nic_device (DEVICE (&s->eth[i]), true,NULL );sysbus_realize (SYS_BUS_DEVICE (&s->eth[i]), &error_abort); sysbus_mmio_map(SYS_BUS_DEVICE(&s->eth[i]), 0,
hw/arm/fsl-imx7.c +1 -1
@@ -446,7 +446,7 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) s->phy_num[i], &error_abort);object_property_set_uint (OBJECT (&s->eth[i]),"tx-ring-num" ,FSL_IMX7_ETH_NUM_TX_RINGS , &error_abort); -qdev_set_nic_properties (DEVICE (&s->eth[i]), &nd_table[i]); +qemu_configure_nic_device (DEVICE (&s->eth[i]), true,NULL );sysbus_realize (SYS_BUS_DEVICE (&s->eth[i]), &error_abort);sysbus_mmio_map (SYS_BUS_DEVICE (&s->eth[i]),0 , FSL_IMX7_ENETn_ADDR[i]);
Signature · 1 line
2.41.0
PATCH v2 25/46 hw/net/smc91c111: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Some callers instantiate the device unconditionally, others will do so only if there is a NICInfo to go with it. This appears to be fairly random, but preserve the existing behaviour for now.
--- hw/arm/gumstix.c | 6 ++---- hw/arm/integratorcp.c | 5 +++-- hw/arm/mainstone.c | 3 +-- hw/arm/realview.c | 25 ++++++++++--------------- hw/arm/versatilepb.c | 15 ++++----------- hw/net/smc91c111.c | 5 ++--- include/hw/net/smc91c111.h | 2 +- 7 files changed, 23 insertions(+), 38 deletions(-)
hw/arm/gumstix.c +2 -4
@@ -74,8 +74,7 @@ static void connex_init(MachineState *machine) FLASH_SECTOR_SIZE, 2, 0, 0, 0, 0, 0);/* Interrupt line of NIC is connected to GPIO line 36 */ -smc91c111_init (&nd_table[0 ],0x04000300 , -qdev_get_gpio_in (cpu->gpio,36 )); +smc91c111_init (0x04000300 ,qdev_get_gpio_in (cpu->gpio,36 )); }static void verdex_init (MachineState *machine)
@@ -98,8 +97,7 @@ static void verdex_init(MachineState *machine) FLASH_SECTOR_SIZE, 2, 0, 0, 0, 0, 0);/* Interrupt line of NIC is connected to GPIO line 99 */ -smc91c111_init (&nd_table[0 ],0x04000300 , -qdev_get_gpio_in (cpu->gpio,99 )); +smc91c111_init (0x04000300 ,qdev_get_gpio_in (cpu->gpio,99 )); }static void connex_class_init (ObjectClass *oc,void *data)
hw/arm/integratorcp.c +3 -2
@@ -669,8 +669,9 @@ static void integratorcp_init(MachineState *machine)sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0x1d000000 );sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , pic[25 ]); -if (nd_table[0 ].used) -smc91c111_init (&nd_table[0 ],0xc8000000 , pic[27 ]); +if (qemu_find_nic_info ("smc91c111" , true,NULL )) { +smc91c111_init (0xc8000000 , pic[27 ]); + }sysbus_create_simple ("pl110" ,0xc0000000 , pic[22 ]);
hw/arm/mainstone.c +1 -2
@@ -153,8 +153,7 @@ static void mainstone_common_init(MachineState *machine,qdev_get_gpio_in (mst_irq,S1_IRQ ), qdev_get_gpio_in(mst_irq, S1_CD_IRQ)); -smc91c111_init (&nd_table[0 ],MST_ETH_PHYS , -qdev_get_gpio_in (mst_irq,ETHERNET_IRQ )); +smc91c111_init (MST_ETH_PHYS ,qdev_get_gpio_in (mst_irq,ETHERNET_IRQ )); mainstone_binfo.board_id = arm_id;arm_load_kernel (mpu->cpu, machine, &mainstone_binfo);
hw/arm/realview.c +10 -15
@@ -89,7 +89,6 @@ static void realview_init(MachineState *machine,I2CBus *i2c;int n;unsigned int smp_cpus = machine->smp.cpus; -int done_nic =0 ;qemu_irq cpu_irq[4 ];int is_mpcore =0 ;int is_pb =0 ;
@@ -295,24 +294,20 @@ static void realview_init(MachineState *machine, n--; } } -for (n =0 ; n < nb_nics; n++) { - nd = &nd_table[n]; - -if (!done_nic && (!nd->model || -strcmp (nd->model, is_pb ?"lan9118" :"smc91c111" ) ==0 )) { -if (is_pb) { -lan9118_init (nd,0x4e000000 , pic[28 ]); - }else { -smc91c111_init (nd,0x4e000000 , pic[28 ]); - } - done_nic =1 ; + + nd =qemu_find_nic_info (is_pb ?"lan9118" :"smc91c111" , true,NULL ); +if (nd) { +if (is_pb) { +lan9118_init (nd,0x4e000000 , pic[28 ]); }else { -if (pci_bus) { -pci_nic_init_nofail (nd, pci_bus,"rtl8139" ,NULL ); - } +smc91c111_init (0x4e000000 , pic[28 ]); } } +if (pci_bus) { +pci_init_nic_devices (pci_bus,"rtl8139" ); + } + dev =sysbus_create_simple (TYPE_ARM_SBCON_I2C ,0x10002000 ,NULL ); i2c = (I2CBus *)qdev_get_child_bus (dev,"i2c" );i2c_slave_create_simple (i2c,"ds1338" ,0x68 );
hw/arm/versatilepb.c +4 -11
@@ -192,10 +192,8 @@ static void versatile_init(MachineState *machine, int board_id)SysBusDevice *busdev;DeviceState *pl041;PCIBus *pci_bus; -NICInfo *nd;I2CBus *i2c;int n; -int done_smc =0 ;DriveInfo *dinfo;if (machine->ram_size >0x10000000 ) {
@@ -263,16 +261,11 @@ static void versatile_init(MachineState *machine, int board_id)sysbus_connect_irq (busdev,3 , sic[30 ]); pci_bus = (PCIBus *)qdev_get_child_bus (dev,"pci" ); -for (n =0 ; n < nb_nics; n++) { - nd = &nd_table[n]; - -if (!done_smc && (!nd->model ||strcmp (nd->model,"smc91c111" ) ==0 )) { -smc91c111_init (nd,0x10010000 , sic[25 ]); - done_smc =1 ; - }else { -pci_nic_init_nofail (nd, pci_bus,"rtl8139" ,NULL ); - } +if (qemu_find_nic_info ("smc91c111" , true,NULL )) { +smc91c111_init (0x10010000 , sic[25 ]); } +pci_init_nic_devices (pci_bus,"rtl8139" ); +if (machine_usb (machine)) {pci_create_simple (pci_bus,-1 ,"pci-ohci" ); }
hw/net/smc91c111.c +2 -3
@@ -817,14 +817,13 @@ static void smc91c111_register_types(void)/* Legacy helper function. Should go away when machine config files are implemented. */ -void smc91c111_init (NICInfo *nd,uint32_t base,qemu_irq irq) +void smc91c111_init (uint32_t base,qemu_irq irq) {DeviceState *dev;SysBusDevice *s; -qemu_check_nic_model (nd,"smc91c111" ); dev =qdev_new (TYPE_SMC91C111 ); -qdev_set_nic_properties (dev, nd); +qemu_configure_nic_device (dev, true,NULL ); s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);sysbus_mmio_map (s,0 , base);
include/hw/net/smc91c111.h +1 -1
@@ -13,6 +13,6 @@#include "net/net.h" -void smc91c111_init (NICInfo *,uint32_t ,qemu_irq ); +void smc91c111_init (uint32_t ,qemu_irq );#endif
Signature · 1 line
2.41.0
PATCH v2 26/46 hw/net/lan9118: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Some callers instantiate the device unconditionally, others will do so only if there is a NICInfo to go with it. This appears to be fairly random, but preseve the existing behaviour for now.
--- hw/arm/kzm.c | 4 ++-- hw/arm/mps2.c | 2 +- hw/arm/realview.c | 6 ++---- hw/arm/vexpress.c | 4 ++-- hw/net/lan9118.c | 5 ++--- include/hw/net/lan9118.h | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-)
hw/arm/kzm.c +2 -2
@@ -113,8 +113,8 @@ static void kzm_init(MachineState *machine) alias_offset += ram[i].size; } -if (nd_table[0 ].used) { -lan9118_init (&nd_table[0 ],KZM_LAN9118_ADDR , +if (qemu_find_nic_info ("lan9118" , true,NULL )) { +lan9118_init (KZM_LAN9118_ADDR ,qdev_get_gpio_in (DEVICE (&s->soc.avic),52 )); }
hw/arm/mps2.c +1 -1
@@ -458,7 +458,7 @@ static void mps2_common_init(MachineState *machine)/* In hardware this is a LAN9220; the LAN9118 is software compatible * except that it doesn't support the checksum-offload feature. */ -lan9118_init (&nd_table[0 ], mmc->ethernet_base, +lan9118_init (mmc->ethernet_base,qdev_get_gpio_in (armv7m, mmc->fpga_type ==FPGA_AN511 ?47 :13 ));
hw/arm/realview.c +2 -4
@@ -84,7 +84,6 @@ static void realview_init(MachineState *machine,SysBusDevice *busdev;qemu_irq pic[64 ];PCIBus *pci_bus =NULL ; -NICInfo *nd;DriveInfo *dinfo;I2CBus *i2c;int n;
@@ -295,10 +294,9 @@ static void realview_init(MachineState *machine, } } - nd =qemu_find_nic_info (is_pb ?"lan9118" :"smc91c111" , true,NULL ); -if (nd) { +if (qemu_find_nic_info (is_pb ?"lan9118" :"smc91c111" , true,NULL )) {if (is_pb) { -lan9118_init (nd,0x4e000000 , pic[28 ]); +lan9118_init (0x4e000000 , pic[28 ]); }else {smc91c111_init (0x4e000000 , pic[28 ]); }
hw/arm/vexpress.c +2 -2
@@ -686,8 +686,8 @@ static void vexpress_common_init(MachineState *machine)memory_region_add_subregion (sysmem, map[VE_VIDEORAM ], &vms->vram);/* 0x4e000000 LAN9118 Ethernet */ -if (nd_table[0 ].used) { -lan9118_init (&nd_table[0 ], map[VE_ETHERNET ], pic[15 ]); +if (qemu_find_nic_info ("lan9118" , true,NULL )) { +lan9118_init (map[VE_ETHERNET ], pic[15 ]); }/* VE_USB: not modelled */
hw/net/lan9118.c +2 -3
@@ -1407,14 +1407,13 @@ static void lan9118_register_types(void)/* Legacy helper function. Should go away when machine config files are implemented. */ -void lan9118_init (NICInfo *nd,uint32_t base,qemu_irq irq) +void lan9118_init (uint32_t base,qemu_irq irq) {DeviceState *dev;SysBusDevice *s; -qemu_check_nic_model (nd,"lan9118" ); dev =qdev_new (TYPE_LAN9118 ); -qdev_set_nic_properties (dev, nd); +qemu_configure_nic_device (dev, true,NULL ); s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);sysbus_mmio_map (s,0 , base);
include/hw/net/lan9118.h +1 -1
@@ -15,6 +15,6 @@#define TYPE_LAN9118 "lan9118" -void lan9118_init (NICInfo *,uint32_t ,qemu_irq ); +void lan9118_init (uint32_t ,qemu_irq );#endif
Signature · 1 line
2.41.0
PATCH v2 27/46 hw/arm/highbank: use qemu_create_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/highbank.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
hw/arm/highbank.c +5 -7
@@ -296,19 +296,17 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id)sysbus_create_simple (TYPE_SYSBUS_AHCI ,0xffe08000 , pic[83 ]); -if (nd_table[0 ].used) { -qemu_check_nic_model (&nd_table[0 ],"xgmac" ); - dev =qdev_new ("xgmac" ); -qdev_set_nic_properties (dev, &nd_table[0 ]); + dev =qemu_create_nic_device ("xgmac" , true,NULL ); +if (dev) {sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0xfff50000 );sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , pic[77 ]);sysbus_connect_irq (SYS_BUS_DEVICE (dev),1 , pic[78 ]);sysbus_connect_irq (SYS_BUS_DEVICE (dev),2 , pic[79 ]); + } -qemu_check_nic_model (&nd_table[1 ],"xgmac" ); - dev =qdev_new ("xgmac" ); -qdev_set_nic_properties (dev, &nd_table[1 ]); + dev =qemu_create_nic_device ("xgmac" , true,NULL ); +if (dev) {sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,0xfff51000 );sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , pic[80 ]);
Signature · 1 line
2.41.0
PATCH v2 28/46 hw/arm/npcm7xx: use qemu_configure_nic_device, allow emc0/emc1 as aliases
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Also update the test to specify which device to attach the test socket to, and remove the comment lamenting the fact that we can't do so.
--- hw/arm/npcm7xx.c | 16 +++++++++------- tests/qtest/npcm7xx_emc-test.c | 18 ++++-------------- 2 files changed, 13 insertions(+), 21 deletions(-)
hw/arm/npcm7xx.c +9 -7
@@ -655,8 +655,9 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)/* * EMC Modules. Cannot fail. -* The mapping of the device to its netdev backend works as follows: -* emc[i] = nd_table[i] +* Use the available NIC configurations in order, allowing 'emc0' and +* 'emc1' to by used as aliases for the model= parameter to override. +* * This works around the inability to specify the netdev property for the * emc device: it's not pluggable and thus the -device option can't be * used.
@@ -664,12 +665,13 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)QEMU_BUILD_BUG_ON (ARRAY_SIZE (npcm7xx_emc_addr) !=ARRAY_SIZE (s->emc));QEMU_BUILD_BUG_ON (ARRAY_SIZE (s->emc) !=2 );for (i =0 ; i <ARRAY_SIZE (s->emc); i++) { - s->emc[i].emc_num = i;SysBusDevice *sbd =SYS_BUS_DEVICE (&s->emc[i]); -if (nd_table[i].used) { -qemu_check_nic_model (&nd_table[i],TYPE_NPCM7XX_EMC ); -qdev_set_nic_properties (DEVICE (sbd), &nd_table[i]); - } +char alias[6 ]; + + s->emc[i].emc_num = i; +snprintf (alias,sizeof (alias),"emc%u" , i); +qemu_configure_nic_device (DEVICE (sbd), true, alias); +/* * The device exists regardless of whether it's connected to a QEMU * netdev backend. So always instantiate it even if there is no
tests/qtest/npcm7xx_emc-test.c +4 -14
@@ -225,21 +225,11 @@ static int *packet_test_init(int module_num, GString *cmd_line) g_assert_cmpint(ret, != , -1);/* -* KISS and use -nic. We specify two nics (both emc{0,1}) because there's -* currently no way to specify only emc1: The driver implicitly relies on -* emc[i] == nd_table[i]. +* KISS and use -nic. The driver accepts 'emc0' and 'emc1' as aliases +* in the 'model' field to specify the device to match. */ -if (module_num ==0 ) { -g_string_append_printf (cmd_line, -" -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " " -" -nic user,model=" TYPE_NPCM7XX_EMC " " , - test_sockets[1 ]); - }else { -g_string_append_printf (cmd_line, -" -nic user,model=" TYPE_NPCM7XX_EMC " " -" -nic socket,fd=%d,model=" TYPE_NPCM7XX_EMC " " , - test_sockets[1 ]); - } +g_string_append_printf (cmd_line," -nic socket,fd=%d,model=emc%d " , + test_sockets[1 ], module_num);g_test_queue_destroy (packet_test_clear, test_sockets);return test_sockets;
Signature · 1 line
2.41.0
PATCH v2 29/46 hw/arm/stellaris: use qemu_find_nic_info()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Rather than just using qemu_configure_nic_device(), populate the MAC address in the system-registers device by peeking at the NICInfo before it's assigned to the device.
Generate the MAC address early, if there is no matching -nic option. Otherwise the MAC address wouldn't be generated until net_client_init1() runs.
--- hw/arm/stellaris.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
hw/arm/stellaris.c +22 -8
@@ -1027,7 +1027,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)DeviceState *ssys_dev;int i;int j; -const uint8_t *macaddr; +NICInfo *nd; +MACAddr mac;MemoryRegion *sram =g_new (MemoryRegion,1 );MemoryRegion *flash =g_new (MemoryRegion,1 );
@@ -1050,12 +1051,22 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)* need its sysclk output. */ ssys_dev =qdev_new (TYPE_STELLARIS_SYS ); -/* Most devices come preprogrammed with a MAC address in the user data. */ - macaddr = nd_table[0 ].macaddr.a; + +/* +* Most devices come preprogrammed with a MAC address in the user data. +* Generate a MAC address now, if there isn't a matching -nic for it. +*/ + nd =qemu_find_nic_info ("stellaris_enet" , true,"stellaris" ); +if (nd) { +memcpy (mac.a, nd->macaddr.a,sizeof (mac.a)); + }else { +qemu_macaddr_default_if_unset (&mac); + } +qdev_prop_set_uint32 (ssys_dev,"user0" , - macaddr[0 ] | (macaddr[1 ] <<8 ) | (macaddr[2 ] <<16 )); + mac.a[0 ] | (mac.a[1 ] <<8 ) | (mac.a[2 ] <<16 ));qdev_prop_set_uint32 (ssys_dev,"user1" , - macaddr[3 ] | (macaddr[4 ] <<8 ) | (macaddr[5 ] <<16 )); + mac.a[3 ] | (mac.a[4 ] <<8 ) | (mac.a[5 ] <<16 ));qdev_prop_set_uint32 (ssys_dev,"did0" , board->did0);qdev_prop_set_uint32 (ssys_dev,"did1" , board->did1);qdev_prop_set_uint32 (ssys_dev,"dc0" , board->dc0);
@@ -1267,10 +1278,13 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)if (board->dc4 & (1 <<28 )) {DeviceState *enet; -qemu_check_nic_model (&nd_table[0 ],"stellaris" ); - enet =qdev_new ("stellaris_enet" ); -qdev_set_nic_properties (enet, &nd_table[0 ]); +if (nd) { +qdev_set_nic_properties (enet, nd); + }else { +qdev_prop_set_macaddr (enet,"mac" , mac.a); + } +sysbus_realize_and_unref (SYS_BUS_DEVICE (enet), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (enet),0 ,0x40048000 );sysbus_connect_irq (SYS_BUS_DEVICE (enet),0 ,qdev_get_gpio_in (nvic,42 ));
Signature · 1 line
2.41.0
PATCH v2 30/46 hw/arm: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/arm/mps2-tz.c | 8 ++------ hw/arm/msf2-soc.c | 6 +----- hw/arm/musicpal.c | 3 +-- hw/arm/xilinx_zynq.c | 11 ++++------- hw/arm/xlnx-versal.c | 7 +------ hw/arm/xlnx-zynqmp.c | 8 +------- 6 files changed, 10 insertions(+), 33 deletions(-)
hw/arm/mps2-tz.c +2 -6
@@ -499,14 +499,12 @@ static MemoryRegion *make_eth_dev(MPS2TZMachineState *mms, void *opaque, const PPCExtraData *extradata) {SysBusDevice *s; -NICInfo *nd = &nd_table[0 ];/* In hardware this is a LAN9220; the LAN9118 is software compatible * except that it doesn't support the checksum-offload feature. */ -qemu_check_nic_model (nd,"lan9118" ); mms->lan9118 =qdev_new (TYPE_LAN9118 ); -qdev_set_nic_properties (mms->lan9118, nd); +qemu_configure_nic_device (mms->lan9118, true,NULL ); s =SYS_BUS_DEVICE (mms->lan9118);sysbus_realize_and_unref (s, &error_fatal);
@@ -524,7 +522,6 @@ static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,* irqs[] is the ethernet IRQ. */ SysBusDevice *s; -NICInfo *nd = &nd_table[0 ];memory_region_init (&mms->eth_usb_container,OBJECT (mms),"mps2-tz-eth-usb-container" ,0x200000 );
@@ -533,9 +530,8 @@ static MemoryRegion *make_eth_usb(MPS2TZMachineState *mms, void *opaque,* In hardware this is a LAN9220; the LAN9118 is software compatible * except that it doesn't support the checksum-offload feature. */ -qemu_check_nic_model (nd,"lan9118" ); mms->lan9118 =qdev_new (TYPE_LAN9118 ); -qdev_set_nic_properties (mms->lan9118, nd); +qemu_configure_nic_device (mms->lan9118, true,NULL ); s =SYS_BUS_DEVICE (mms->lan9118);sysbus_realize_and_unref (s, &error_fatal);
hw/arm/msf2-soc.c +1 -5
@@ -197,12 +197,8 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)g_free (bus_name); } -/* FIXME use qdev NIC properties instead of nd_table[] */ -if (nd_table[0 ].used) { -qemu_check_nic_model (&nd_table[0 ],TYPE_MSS_EMAC ); -qdev_set_nic_properties (DEVICE (&s->emac), &nd_table[0 ]); - } dev =DEVICE (&s->emac); +qemu_configure_nic_device (dev, true,NULL );object_property_set_link (OBJECT (&s->emac),"ahb-bus" ,OBJECT (get_system_memory ()), &error_abort);if (!sysbus_realize (SYS_BUS_DEVICE (&s->emac), errp)) {
hw/arm/musicpal.c +1 -2
@@ -1286,9 +1286,8 @@ static void musicpal_init(MachineState *machine) }sysbus_create_simple (TYPE_MV88W8618_FLASHCFG ,MP_FLASHCFG_BASE ,NULL ); -qemu_check_nic_model (&nd_table[0 ],"mv88w8618" ); dev =qdev_new (TYPE_MV88W8618_ETH ); -qdev_set_nic_properties (dev, &nd_table[0 ]); +qemu_configure_nic_device (dev, true,"mv88w8618" );object_property_set_link (OBJECT (dev),"dma-memory" ,OBJECT (get_system_memory ()), &error_fatal);sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);
hw/arm/xilinx_zynq.c +4 -7
@@ -108,16 +108,13 @@ static void zynq_write_board_setup(ARMCPU *cpu,static struct arm_boot_info zynq_binfo = {}; -static void gem_init (NICInfo *nd,uint32_t base,qemu_irq irq) +static void gem_init (uint32_t base,qemu_irq irq) {DeviceState *dev;SysBusDevice *s; dev =qdev_new (TYPE_CADENCE_GEM ); -if (nd->used) { -qemu_check_nic_model (nd,TYPE_CADENCE_GEM ); -qdev_set_nic_properties (dev, nd); - } +qemu_configure_nic_device (dev, true,NULL );object_property_set_int (OBJECT (dev),"phy-addr" ,7 , &error_abort); s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);
@@ -279,8 +276,8 @@ static void zynq_init(MachineState *machine)sysbus_create_varargs ("cadence_ttc" ,0xF8002000 , pic[69 -IRQ_OFFSET ], pic[70 -IRQ_OFFSET ], pic[71 -IRQ_OFFSET ],NULL ); -gem_init (&nd_table[0 ],0xE000B000 , pic[54 -IRQ_OFFSET ]); -gem_init (&nd_table[1 ],0xE000C000 , pic[77 -IRQ_OFFSET ]); +gem_init (0xE000B000 , pic[54 -IRQ_OFFSET ]); +gem_init (0xE000C000 , pic[77 -IRQ_OFFSET ]);for (n =0 ; n <2 ; n++) {int hci_irq = n ?79 :56 ;
hw/arm/xlnx-versal.c +1 -6
@@ -249,18 +249,13 @@ static void versal_create_gems(Versal *s, qemu_irq *pic)static const int irqs[] = {VERSAL_GEM0_IRQ_0 ,VERSAL_GEM1_IRQ_0 };static const uint64_t addrs[] = {MM_GEM0 ,MM_GEM1 };char *name =g_strdup_printf ("gem%d" , i); -NICInfo *nd = &nd_table[i];DeviceState *dev;MemoryRegion *mr;object_initialize_child (OBJECT (s), name, &s->lpd.iou.gem[i],TYPE_CADENCE_GEM ); dev =DEVICE (&s->lpd.iou.gem[i]); -/* FIXME use qdev NIC properties instead of nd_table[] */ -if (nd->used) { -qemu_check_nic_model (nd,"cadence_gem" ); -qdev_set_nic_properties (dev, nd); - } +qemu_configure_nic_device (dev, true,NULL );object_property_set_int (OBJECT (dev),"phy-addr" ,23 , &error_abort);object_property_set_int (OBJECT (dev),"num-priority-queues" ,2 , &error_abort);
hw/arm/xlnx-zynqmp.c +1 -7
@@ -616,13 +616,7 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) }for (i =0 ; i <XLNX_ZYNQMP_NUM_GEMS ; i++) { -NICInfo *nd = &nd_table[i]; - -/* FIXME use qdev NIC properties instead of nd_table[] */ -if (nd->used) { -qemu_check_nic_model (nd,TYPE_CADENCE_GEM ); -qdev_set_nic_properties (DEVICE (&s->gem[i]), nd); - } +qemu_configure_nic_device (DEVICE (&s->gem[i]), true,NULL );object_property_set_int (OBJECT (&s->gem[i]),"revision" ,GEM_REVISION , &error_abort); object_property_set_int(OBJECT(&s->gem[i]), "phy-addr", 23,
Signature · 1 line
2.41.0
PATCH v2 31/46 hw/net/etraxfs-eth: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/cris/axis_dev88.c | 9 ++++----- hw/net/etraxfs_eth.c | 5 ++--- include/hw/cris/etraxfs.h | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-)
hw/cris/axis_dev88.c +4 -5
@@ -308,15 +308,14 @@ void axisdev88_init(MachineState *machine)/* Add the two ethernet blocks. */ dma_eth =g_malloc0 (sizeof dma_eth[0 ] *4 );/* Allocate 4 channels. */ -etraxfs_eth_init (&nd_table[0 ],0x30034000 ,1 , &dma_eth[0 ], &dma_eth[1 ]); -if (nb_nics >1 ) { -etraxfs_eth_init (&nd_table[1 ],0x30036000 ,2 , &dma_eth[2 ], &dma_eth[3 ]); - } +etraxfs_eth_init (0x30034000 ,1 , &dma_eth[0 ], &dma_eth[1 ]);/* The DMA Connector block is missing, hardwire things for now. */ etraxfs_dmac_connect_client (etraxfs_dmac,0 , &dma_eth[0 ]);etraxfs_dmac_connect_client (etraxfs_dmac,1 , &dma_eth[1 ]); -if (nb_nics >1 ) { + +if (qemu_find_nic_info ("etraxfs-eth" , true,"fseth" )) { +etraxfs_eth_init (0x30036000 ,2 , &dma_eth[2 ], &dma_eth[3 ]);etraxfs_dmac_connect_client (etraxfs_dmac,6 , &dma_eth[2 ]);etraxfs_dmac_connect_client (etraxfs_dmac,7 , &dma_eth[3 ]); }
hw/net/etraxfs_eth.c +2 -3
@@ -646,15 +646,14 @@ static void etraxfs_eth_class_init(ObjectClass *klass, void *data)/* Instantiate an ETRAXFS Ethernet MAC. */ DeviceState * -etraxfs_eth_init (NICInfo *nd,hwaddr base,int phyaddr, +etraxfs_eth_init (hwaddr base,int phyaddr,struct etraxfs_dma_client *dma_out,struct etraxfs_dma_client *dma_in) {DeviceState *dev; -qemu_check_nic_model (nd,"fseth" ); dev =qdev_new ("etraxfs-eth" ); -qdev_set_nic_properties (dev, nd); +qemu_configure_nic_device (dev, true,"fseth" );qdev_prop_set_uint32 (dev,"phyaddr" , phyaddr);/*
include/hw/cris/etraxfs.h +1 -1
@@ -31,7 +31,7 @@#include "hw/sysbus.h" #include "qapi/error.h" -DeviceState *etraxfs_eth_init (NICInfo *nd,hwaddr base,int phyaddr, +DeviceState *etraxfs_eth_init (hwaddr base,int phyaddr,struct etraxfs_dma_client *dma_out,struct etraxfs_dma_client *dma_in);
Signature · 1 line
2.41.0
PATCH v2 32/46 hw/m68k/mcf5208: use qemu_create_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/m68k/mcf5208.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-)
hw/m68k/mcf5208.c +6 -14
@@ -206,16 +206,16 @@ static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic) } } -static void mcf_fec_init (MemoryRegion *sysmem,NICInfo *nd,hwaddr base, -qemu_irq *irqs) +static void mcf_fec_init (MemoryRegion *sysmem,hwaddr base,qemu_irq *irqs) {DeviceState *dev;SysBusDevice *s;int i; -qemu_check_nic_model (nd,TYPE_MCF_FEC_NET ); - dev =qdev_new (TYPE_MCF_FEC_NET ); -qdev_set_nic_properties (dev, nd); + dev =qemu_create_nic_device (TYPE_MCF_FEC_NET , true,NULL ); +if (!dev) { +return ; + } s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);
@@ -267,17 +267,9 @@ static void mcf5208evb_init(MachineState *machine)mcf5208_sys_init (address_space_mem, pic); -if (nb_nics >1 ) { -error_report ("Too many NICs" ); -exit (1 ); - } -if (nd_table[0 ].used) { -mcf_fec_init (address_space_mem, &nd_table[0 ], -0xfc030000 , pic +36 ); - } +mcf_fec_init (address_space_mem,0xfc030000 , pic +36 );g_free (pic); -/* 0xfc000000 SCM. */ /* 0xfc004000 XBS. */ /* 0xfc008000 FlexBus CS. */
Signature · 1 line
2.41.0
PATCH v2 33/46 hw/m68k/q800: use qemu_find_nic_info()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
If a corresponding NIC configuration was found, it will have a MAC address already assigned, so use that. Else, generate and assign a default one.
Using qemu_find_nic_info() is simpler than the alternative of using qemu_configure_nic_device() and then having to fetch the "mac" property as a string and convert it.
--- hw/m68k/q800.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
hw/m68k/q800.c +16 -13
@@ -48,6 +48,7 @@#include "hw/display/macfb.h" #include "hw/block/swim.h" #include "net/net.h" +#include "net/util.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "sysemu/qtest.h"
@@ -271,6 +272,8 @@ static void q800_machine_init(MachineState *machine)BusState *adb_bus;NubusBus *nubus;DriveInfo *dinfo; +NICInfo *nd; +MACAddr mac;uint8_t rng_seed[32 ]; linux_boot = (kernel_filename !=NULL );
@@ -371,13 +374,6 @@ static void q800_machine_init(MachineState *machine)/* MACSONIC */ -if (nb_nics >1 ) { -error_report ("q800 can only have one ethernet interface" ); -exit (1 ); - } - -qemu_check_nic_model (&nd_table[0 ],"dp83932" ); -/* * MacSonic driver needs an Apple MAC address * Valid prefix are:
@@ -387,14 +383,21 @@ static void q800_machine_init(MachineState *machine)* 08:00:07 Apple * (Q800 use the last one) */ - nd_table[0 ].macaddr.a[0 ] =0x08 ; - nd_table[0 ].macaddr.a[1 ] =0x00 ; - nd_table[0 ].macaddr.a[2 ] =0x07 ; -object_initialize_child (OBJECT (machine),"dp8393x" , &m->dp8393x,TYPE_DP8393X ); dev =DEVICE (&m->dp8393x); -qdev_set_nic_properties (dev, &nd_table[0 ]); + nd =qemu_find_nic_info (TYPE_DP8393X , true,"dp83932" ); +if (nd) { +qdev_set_nic_properties (dev, nd); +memcpy (mac.a, nd->macaddr.a,sizeof (mac.a)); + }else { +qemu_macaddr_default_if_unset (&mac); + } + mac.a[0 ] =0x08 ; + mac.a[1 ] =0x00 ; + mac.a[2 ] =0x07 ; +qdev_prop_set_macaddr (dev,"mac" , mac.a); +qdev_prop_set_uint8 (dev,"it_shift" ,2 );qdev_prop_set_bit (dev,"big_endian" , true); object_property_set_link(OBJECT(dev), "dma_mr",
@@ -415,7 +418,7 @@ static void q800_machine_init(MachineState *machine) prom =memory_region_get_ram_ptr (dp8393x_prom); checksum =0 ;for (i =0 ; i <6 ; i++) { - prom[i] =revbit8 (nd_table[0 ].macaddr.a[i]); + prom[i] =revbit8 (mac.a[i]); checksum ^= prom[i]; } prom[7 ] =0xff - checksum;
Signature · 1 line
2.41.0
PATCH v2 34/46 hw/microblaze: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/microblaze/petalogix_ml605_mmu.c | 3 +-- hw/microblaze/petalogix_s3adsp1800_mmu.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
hw/microblaze/petalogix_ml605_mmu.c +1 -2
@@ -133,7 +133,6 @@ petalogix_ml605_init(MachineState *machine)sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[TIMER_IRQ ]);/* axi ethernet and dma initialization. */ -qemu_check_nic_model (&nd_table[0 ],"xlnx.axi-ethernet" ); eth0 =qdev_new ("xlnx.axi-ethernet" ); dma =qdev_new ("xlnx.axi-dma" );
@@ -145,7 +144,7 @@ petalogix_ml605_init(MachineState *machine) "axistream-connected-target", NULL); cs =object_property_get_link (OBJECT (dma),"axistream-control-connected-target" ,NULL ); -qdev_set_nic_properties (eth0, &nd_table[0 ]); +qemu_configure_nic_device (eth0, true,NULL );qdev_prop_set_uint32 (eth0,"rxmem" ,0x1000 );qdev_prop_set_uint32 (eth0,"txmem" ,0x1000 ); object_property_set_link(OBJECT(eth0), "axistream-connected", ds,
hw/microblaze/petalogix_s3adsp1800_mmu.c +1 -2
@@ -114,9 +114,8 @@ petalogix_s3adsp1800_init(MachineState *machine)sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 ,TIMER_BASEADDR );sysbus_connect_irq (SYS_BUS_DEVICE (dev),0 , irq[TIMER_IRQ ]); -qemu_check_nic_model (&nd_table[0 ],"xlnx.xps-ethernetlite" ); dev =qdev_new ("xlnx.xps-ethernetlite" ); -qdev_set_nic_properties (dev, &nd_table[0 ]); +qemu_configure_nic_device (dev, true,NULL );qdev_prop_set_uint32 (dev,"tx-ping-pong" ,0 );qdev_prop_set_uint32 (dev,"rx-ping-pong" ,0 );sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal);
Signature · 1 line
2.41.0
PATCH v2 35/46 hw/mips/mipssim: use qemu_create_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
The MIPS SIM platform instantiates its NIC only if a corresponding configuration exists for it. Use qemu_create_nic_device() function for that.
--- hw/mips/mipssim.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
hw/mips/mipssim.c +7 -6
@@ -110,13 +110,15 @@ static void main_cpu_reset(void *opaque) } } -static void mipsnet_init (int base,qemu_irq irq,NICInfo *nd) +static void mipsnet_init (int base,qemu_irq irq) {DeviceState *dev;SysBusDevice *s; - dev =qdev_new ("mipsnet" ); -qdev_set_nic_properties (dev, nd); + dev =qemu_create_nic_device ("mipsnet" , true,NULL ); +if (!dev) { +return ; + } s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);
@@ -217,9 +219,8 @@ mips_mipssim_init(MachineState *machine) sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0)); } -if (nd_table[0 ].used) -/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ -mipsnet_init (0x4200 , env->irq[2 ], &nd_table[0 ]); +/* MIPSnet uses the MIPS CPU INT0, which is interrupt 2. */ +mipsnet_init (0x4200 , env->irq[2 ]); }static void mips_mipssim_machine_init (MachineClass *mc)
Signature · 1 line
2.41.0
PATCH v2 36/46 hw/mips/jazz: use qemu_find_nic_info()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Extract the MAC address from the NICInfo, or generate one explicitly if there was no corresponding NIC configuration, to put it in the PROM.
--- hw/mips/jazz.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
hw/mips/jazz.c +7 -8
@@ -113,15 +113,19 @@ static const MemoryRegionOps dma_dummy_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void mips_jazz_init_net (NICInfo *nd,IOMMUMemoryRegion *rc4030_dma_mr, +static void mips_jazz_init_net (IOMMUMemoryRegion *rc4030_dma_mr,DeviceState *rc4030,MemoryRegion *dp8393x_prom) {DeviceState *dev;SysBusDevice *sysbus;int checksum, i;uint8_t *prom; +NICInfo *nd; -qemu_check_nic_model (nd,"dp83932" ); + nd =qemu_find_nic_info ("dp8393x" , true,"dp82932" ); +if (!nd) { +return ; + } dev =qdev_new ("dp8393x" );qdev_set_nic_properties (dev, nd);
@@ -316,12 +320,7 @@ static void mips_jazz_init(MachineState *machine, }/* Network controller */ -if (nb_nics ==1 ) { -mips_jazz_init_net (&nd_table[0 ], rc4030_dma_mr, rc4030, dp8393x_prom); - }else if (nb_nics >1 ) { -error_report ("This machine only supports one NIC" ); -exit (1 ); - } +mips_jazz_init_net (rc4030_dma_mr, rc4030, dp8393x_prom);/* SCSI adapter */ dev =qdev_new (TYPE_SYSBUS_ESP );
Signature · 1 line
2.41.0
PATCH v2 37/46 hw/net/lasi_i82596: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/net/lasi_i82596.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/net/lasi_i82596.c +1 -2
@@ -125,11 +125,10 @@ SysBusI82596State *lasi_82596_init(MemoryRegion *addr_space,static const MACAddr HP_MAC = { .a = {0x08 ,0x00 ,0x09 ,0xef ,0x34 ,0xf6 } }; -qemu_check_nic_model (&nd_table[0 ],TYPE_LASI_82596 ); dev =qdev_new (TYPE_LASI_82596 ); s =SYSBUS_I82596 (dev); s->state.irq = lan_irq; -qdev_set_nic_properties (dev, &nd_table[0 ]); +qemu_configure_nic_device (dev, true,NULL );sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); s->state.conf.macaddr =HP_MAC ;/* set HP MAC prefix */
Signature · 1 line
2.41.0
PATCH v2 38/46 hw/openrisc/openrisc_sim: use qemu_create_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/openrisc/openrisc_sim.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
hw/openrisc/openrisc_sim.c +9 -9
@@ -170,7 +170,7 @@ static void openrisc_create_fdt(Or1ksimState *state,static void openrisc_sim_net_init (Or1ksimState *state,hwaddr base,hwaddr size,int num_cpus,OpenRISCCPU *cpus[], -int irq_pin,NICInfo *nd) +int irq_pin) {void *fdt = state->fdt;DeviceState *dev;
@@ -178,8 +178,10 @@ static void openrisc_sim_net_init(Or1ksimState *state, hwaddr base, hwaddr size,char *nodename;int i; - dev =qdev_new ("open_eth" ); -qdev_set_nic_properties (dev, nd); + dev =qemu_create_nic_device ("open_eth" , true,NULL ); +if (!dev) { +return ; + } s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);
@@ -313,12 +315,10 @@ static void openrisc_sim_init(MachineState *machine)openrisc_create_fdt (state, or1ksim_memmap, smp_cpus, machine->ram_size, machine->kernel_cmdline); -if (nd_table[0 ].used) { -openrisc_sim_net_init (state, or1ksim_memmap[OR1KSIM_ETHOC ].base, - or1ksim_memmap[OR1KSIM_ETHOC ].size, - smp_cpus, cpus, -OR1KSIM_ETHOC_IRQ , nd_table); - } +openrisc_sim_net_init (state, or1ksim_memmap[OR1KSIM_ETHOC ].base, + or1ksim_memmap[OR1KSIM_ETHOC ].size, + smp_cpus, cpus, +OR1KSIM_ETHOC_IRQ );if (smp_cpus >1 ) { openrisc_sim_ompic_init(state, or1ksim_memmap[OR1KSIM_OMPIC].base,
Signature · 1 line
2.41.0
PATCH v2 39/46 hw/riscv: use qemu_configure_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/riscv/microchip_pfsoc.c | 14 ++------------ hw/riscv/sifive_u.c | 7 +------ 2 files changed, 3 insertions(+), 18 deletions(-)
hw/riscv/microchip_pfsoc.c +2 -12
@@ -202,7 +202,6 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)MemoryRegion *envm_data =g_new (MemoryRegion,1 );MemoryRegion *qspi_xip_mem =g_new (MemoryRegion,1 );char *plic_hart_config; -NICInfo *nd;int i;sysbus_realize (SYS_BUS_DEVICE (&s->e_cpus), &error_abort);
@@ -411,17 +410,8 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) memmap[MICROCHIP_PFSOC_USB].size);/* GEMs */ - - nd = &nd_table[0 ]; -if (nd->used) { -qemu_check_nic_model (nd,TYPE_CADENCE_GEM ); -qdev_set_nic_properties (DEVICE (&s->gem0), nd); - } - nd = &nd_table[1 ]; -if (nd->used) { -qemu_check_nic_model (nd,TYPE_CADENCE_GEM ); -qdev_set_nic_properties (DEVICE (&s->gem1), nd); - } +qemu_configure_nic_device (DEVICE (&s->gem0), true,NULL ); +qemu_configure_nic_device (DEVICE (&s->gem1), true,NULL );object_property_set_int (OBJECT (&s->gem0),"revision" ,GEM_REVISION , errp);object_property_set_int (OBJECT (&s->gem0),"phy-addr" ,8 , errp);
hw/riscv/sifive_u.c +1 -6
@@ -789,7 +789,6 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)MemoryRegion *l2lim_mem =g_new (MemoryRegion,1 );char *plic_hart_config;int i, j; -NICInfo *nd = &nd_table[0 ];qdev_prop_set_uint32 (DEVICE (&s->u_cpus),"num-harts" , ms->smp.cpus -1 );qdev_prop_set_uint32 (DEVICE (&s->u_cpus),"hartid-base" ,1 );
@@ -893,11 +892,7 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) }sysbus_mmio_map (SYS_BUS_DEVICE (&s->otp),0 , memmap[SIFIVE_U_DEV_OTP ].base); -/* FIXME use qdev NIC properties instead of nd_table[] */ -if (nd->used) { -qemu_check_nic_model (nd,TYPE_CADENCE_GEM ); -qdev_set_nic_properties (DEVICE (&s->gem), nd); - } +qemu_configure_nic_device (DEVICE (&s->gem), true,NULL );object_property_set_int (OBJECT (&s->gem),"revision" ,GEM_REVISION , &error_abort);if (!sysbus_realize (SYS_BUS_DEVICE (&s->gem), errp)) {
Signature · 1 line
2.41.0
PATCH v2 40/46 hw/s390x/s390-virtio-ccw: use qemu_create_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/s390x/s390-virtio-ccw.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
hw/s390x/s390-virtio-ccw.c +2 -9
@@ -221,16 +221,9 @@ static void s390_init_ipl_dev(const char *kernel_filename,static void s390_create_virtio_net (BusState *bus,const char *name) { -int i; - -for (i =0 ; i < nb_nics; i++) { -NICInfo *nd = &nd_table[i]; -DeviceState *dev; - -qemu_check_nic_model (nd,"virtio" ); +DeviceState *dev; - dev =qdev_new (name); -qdev_set_nic_properties (dev, nd); +while ((dev =qemu_create_nic_device (name, true,"virtio" ))) {qdev_realize_and_unref (dev, bus, &error_fatal); } }
Signature · 1 line
2.41.0
PATCH v2 41/46 hw/sparc/sun4m: use qemu_find_nic_info()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
Obtain the MAC address from the NIC configuration if there is one, or generate one explicitly so that it can be placed in the PROM.
--- hw/sparc/sun4m.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
hw/sparc/sun4m.c +14 -6
@@ -299,13 +299,15 @@ static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)static void *sparc32_dma_init (hwaddr dma_base,hwaddr esp_base,qemu_irq espdma_irq, -hwaddr le_base,qemu_irq ledma_irq,NICInfo *nd) +hwaddr le_base,qemu_irq ledma_irq, +MACAddr *mac) {DeviceState *dma;ESPDMADeviceState *espdma;LEDMADeviceState *ledma;SysBusESPState *esp;SysBusPCNetState *lance; +NICInfo *nd =qemu_find_nic_info ("lance" , true,NULL ); dma =qdev_new (TYPE_SPARC32_DMA ); espdma = SPARC32_ESPDMA_DEVICE(object_resolve_path_component(
@@ -320,7 +322,14 @@ static void *sparc32_dma_init(hwaddr dma_base, lance =SYSBUS_PCNET (object_resolve_path_component (OBJECT (ledma),"lance" )); -qdev_set_nic_properties (DEVICE (lance), nd); + +if (nd) { +qdev_set_nic_properties (DEVICE (lance), nd); +memcpy (mac->a, nd->macaddr.a,sizeof (mac->a)); + }else { +qemu_macaddr_default_if_unset (mac); +qdev_prop_set_macaddr (DEVICE (lance),"mac" , mac->a); + }sysbus_realize_and_unref (SYS_BUS_DEVICE (dma), &error_fatal);sysbus_mmio_map (SYS_BUS_DEVICE (dma),0 , dma_base);
@@ -832,7 +841,7 @@ static void sun4m_hw_init(MachineState *machine)unsigned int smp_cpus = machine->smp.cpus;unsigned int max_cpus = machine->smp.max_cpus;HostMemoryBackend *ram_memdev = machine->memdev; -NICInfo *nd = &nd_table[0 ]; +MACAddr hostid;if (machine->ram_size > hwdef->max_mem) { error_report("Too much memory for this machine: %" PRId64 ","
@@ -893,10 +902,9 @@ static void sun4m_hw_init(MachineState *machine) hwdef->iommu_pad_base, hwdef->iommu_pad_len); } -qemu_check_nic_model (nd,TYPE_LANCE );sparc32_dma_init (hwdef->dma_base, hwdef->esp_base, slavio_irq[18 ], - hwdef->le_base, slavio_irq[16 ], nd); + hwdef->le_base, slavio_irq[16 ], &hostid);if (graphic_depth !=8 && graphic_depth !=24 ) {error_report ("Unsupported depth: %d" , graphic_depth);
@@ -1048,7 +1056,7 @@ static void sun4m_hw_init(MachineState *machine) machine->initrd_filename, machine->ram_size, &initrd_size); -nvram_init (nvram, (uint8_t *)&nd->macaddr, machine->kernel_cmdline, +nvram_init (nvram, hostid.a, machine->kernel_cmdline, machine->boot_config.order, machine->ram_size, kernel_size, graphic_width, graphic_height, graphic_depth, hwdef->nvram_machine_id,"Sun4m" );
Signature · 1 line
2.41.0
PATCH v2 42/46 hw/xtensa/xtfpga: use qemu_create_nic_device()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- hw/xtensa/xtfpga.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
hw/xtensa/xtfpga.c +6 -7
@@ -141,14 +141,16 @@ static void xtfpga_net_init(MemoryRegion *address_space,hwaddr base, hwaddr descriptors, hwaddr buffers, - qemu_irq irq, NICInfo *nd) + qemu_irq irq) { DeviceState *dev;SysBusDevice *s;MemoryRegion *ram; - dev =qdev_new ("open_eth" ); -qdev_set_nic_properties (dev, nd); + dev =qemu_create_nic_device ("open_eth" , true,NULL ); +if (!dev) { +return ; + } s =SYS_BUS_DEVICE (dev);sysbus_realize_and_unref (s, &error_fatal);
@@ -301,10 +303,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)memory_region_add_subregion (system_memory, board->io[1 ], io); }xtfpga_fpga_init (system_io,0x0d020000 , freq); -if (nd_table[0 ].used) { -xtfpga_net_init (system_io,0x0d030000 ,0x0d030400 ,0x0d800000 , - extints[1 ], nd_table); - } +xtfpga_net_init (system_io,0x0d030000 ,0x0d030400 ,0x0d800000 , extints[1 ]);serial_mm_init (system_io,0x0d050020 ,2 , extints[0 ],115200 ,serial_hd (0 ),DEVICE_NATIVE_ENDIAN );
Signature · 1 line
2.41.0
PATCH v2 43/46 net: remove qemu_check_nic_model()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- include/net/net.h | 1 - net/net.c | 13 ------------- 2 files changed, 14 deletions(-)
include/net/net.h +0 -1
@@ -202,7 +202,6 @@ int qemu_set_vnet_le(NetClientState *nc, bool is_le);int qemu_set_vnet_be (NetClientState *nc,bool is_be);void qemu_macaddr_default_if_unset (MACAddr *macaddr);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,
net/net.c +0 -13
@@ -977,19 +977,6 @@ int qemu_show_nic_models(const char *arg, const char *const *models)return 1 ; } -void qemu_check_nic_model (NICInfo *nd,const char *model) -{ -const char *models[2 ]; - - models[0 ] = model; - models[1 ] =NULL ; - -if (qemu_show_nic_models (nd->model, models)) -exit (0 ); -if (qemu_find_nic_model (nd, models, model) <0 ) -exit (1 ); -} -int qemu_find_nic_model (NICInfo *nd,const char *const *models,const char *default_model) {
Signature · 1 line
2.41.0
PATCH v2 44/46 hw/pci: remove pci_nic_init_nofail()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
This function is no longer used.
--- hw/pci/pci.c | 72 -------------------------------------------- include/hw/pci/pci.h | 3 -- 2 files changed, 75 deletions(-)
hw/pci/pci.c +0 -72
@@ -1853,78 +1853,6 @@ const pci_class_desc *get_class_desc(int class)return desc; } -/* 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; -GPtrArray *pci_nic_models; -PCIBus *bus; -PCIDevice *pci_dev; -DeviceState *dev; -int devfn; -int i; -int dom, busnr; -unsigned slot; - -if (nd->model && !strcmp (nd->model,"virtio" )) { -g_free (nd->model); - nd->model =g_strdup ("virtio-net-pci" ); - } - - pci_nic_models =qemu_get_nic_models (TYPE_PCI_DEVICE ); - -if (qemu_show_nic_models (nd->model, (const char **)pci_nic_models->pdata)) { -exit (0 ); - } - - i =qemu_find_nic_model (nd, (const char **)pci_nic_models->pdata, - default_model); -if (i <0 ) { -exit (1 ); - } - -if (!rootbus) { -error_report ("No primary PCI bus" ); -exit (1 ); - } - -assert (!rootbus->parent_dev); - -if (!devaddr) { - devfn =-1 ; - busnr =0 ; - }else { -if (pci_parse_devaddr (devaddr, &dom, &busnr, &slot,NULL ) <0 ) { -error_report ("Invalid PCI device address %s for device %s" , - devaddr, nd->model); -exit (1 ); - } - -if (dom !=0 ) { -error_report ("No support for non-zero PCI domains" ); -exit (1 ); - } - - devfn =PCI_DEVFN (slot,0 ); - } - - bus =pci_find_bus_nr (rootbus, busnr); -if (!bus) { -error_report ("Invalid PCI device address %s for device %s" , - devaddr, nd->model); -exit (1 ); - } - - pci_dev =pci_new (devfn, nd->model); - dev = &pci_dev->qdev; -qdev_set_nic_properties (dev, nd); -pci_realize_and_unref (pci_dev, bus, &error_fatal); -g_ptr_array_free (pci_nic_models, true); -return pci_dev; -} -void pci_init_nic_devices (PCIBus *bus,const char *default_model) { qemu_create_nic_bus_devices(&bus->qbus, TYPE_PCI_DEVICE, default_model,
include/hw/pci/pci.h +0 -3
@@ -314,9 +314,6 @@ void pci_device_set_intx_routing_notifier(PCIDevice *dev, PCIINTxRoutingNotifier notifier);void pci_device_reset (PCIDevice *dev); -PCIDevice *pci_nic_init_nofail (NICInfo *nd,PCIBus *rootbus, -const char *default_model, -const char *default_devaddr);void pci_init_nic_devices (PCIBus *bus,const char *default_model);bool pci_init_nic_in_slot (PCIBus *rootbus,const char *default_model,const char *alias,const char *devaddr);
Signature · 1 line
2.41.0
PATCH v2 45/46 net: remove qemu_show_nic_models(), qemu_find_nic_model()
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
These old functions can be removed now too. Let net_param_nic() print the full set of network devices directly, and also make it note that a list more specific to this platform/config will be available by using '-nic model=help' instead.
--- include/net/net.h | 3 --- net/net.c | 39 ++++++--------------------------------- 2 files changed, 6 insertions(+), 36 deletions(-)
include/net/net.h +0 -3
@@ -201,9 +201,6 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len);int qemu_set_vnet_le (NetClientState *nc,bool is_le);int qemu_set_vnet_be (NetClientState *nc,bool is_be);void qemu_macaddr_default_if_unset (MACAddr *macaddr); -int qemu_show_nic_models (const char *arg,const char *const *models); -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,
net/net.c +6 -33
@@ -962,38 +962,6 @@ GPtrArray *qemu_get_nic_models(const char *device_type)return nic_models; } -int qemu_show_nic_models (const char *arg,const char *const *models) -{ -int i; - -if (!arg || !is_help_option (arg)) { -return 0 ; - } - -printf ("Available NIC models:\n" ); -for (i =0 ; models[i]; i++) { -printf ("%s\n" , models[i]); - } -return 1 ; -} - -int qemu_find_nic_model (NICInfo *nd,const char *const *models, -const char *default_model) -{ -int i; - -if (!nd->model) - nd->model =g_strdup (default_model); - -for (i =0 ; models[i]; i++) { -if (strcmp (nd->model, models[i]) ==0 ) -return i; - } - -error_report ("Unsupported NIC model: %s" , nd->model); -return -1 ; -} -static int net_init_nic (const Netdev *netdev,const char *name,NetClientState *peer,Error **errp) {
@@ -1776,9 +1744,14 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp) }if (is_help_option (type)) {GPtrArray *nic_models =qemu_get_nic_models (TYPE_DEVICE ); +int i;show_netdevs ();printf ("\n" ); -qemu_show_nic_models (type, (const char **)nic_models->pdata); +printf ("Supported NIC models " +"(use -nic model=help for a filtered list):\n" ); +for (i =0 ; nic_models->pdata[i]; i++) { +printf ("%s\n" , (char *)nic_models->pdata[i]); + }g_ptr_array_free (nic_models, true);exit (0 ); }
Signature · 1 line
2.41.0
PATCH v2 46/46 net: make nb_nics and nd_table[] static in net/net.c
In reply to David WoodhouseFrom: David Woodhouse <[email protected]>
--- include/net/net.h | 4 ---- net/net.c | 3 +++ system/globals.c | 2 -- 3 files changed, 3 insertions(+), 6 deletions(-)
include/net/net.h +0 -4
@@ -245,10 +245,6 @@ struct NICInfo {int nvectors; }; -extern int nb_nics; -extern NICInfo nd_table[MAX_NICS ]; -extern const char *host_net_devices[]; -/* from net.c */ extern NetClientStateList net_clients;bool netdev_is_modern (const char *optstr);
net/net.c +3 -0
@@ -77,6 +77,9 @@ static NetdevQueue nd_queue = QSIMPLEQ_HEAD_INITIALIZER(nd_queue);static GHashTable *nic_model_help; +static int nb_nics; +static NICInfo nd_table[MAX_NICS ]; +/***********************************************************/ /* network device redirectors */
system/globals.c +0 -2
@@ -36,8 +36,6 @@ int display_opengl;const char * keyboard_layout;bool enable_mlock;bool enable_cpu_pm; -int nb_nics; -NICInfo nd_table[MAX_NICS ];int autostart =1 ;int vga_interface_type =VGA_NONE ;bool vga_interface_created;
Signature · 1 line
2.41.0