From patchwork Fri Jan 26 17:24:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13533007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FE42C47422 for ; Fri, 26 Jan 2024 17:35:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rTQ5G-0008LT-Tw; Fri, 26 Jan 2024 12:33:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rTQ5B-0008BX-I0; Fri, 26 Jan 2024 12:33:37 -0500 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rTQ58-0001cb-2j; Fri, 26 Jan 2024 12:33:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To: Content-ID:Content-Description:In-Reply-To:References; bh=uxZ4mGKFLew5MTQuKKAqXya97kMNkAzbjIcyINbmJGE=; b=L789Dzt6MRyCiK291RHRqqMe+V Srde9pmzJin4uUey0pMnEejE6xMp/9M6g9l8tUpziOzuA1LQmG6rsV3bmoeH8/PT+8JfpGSUEFn5l KxevtOxzueFYY2OObJ6DIyZ+82yb9ytGPa+mQTtz19N3nWl+4/q/3wIcad7/RyYkvIeZscD1AYX1D ZDDDvEFxB4zmkvOJJ44emRqdLNkEefIa4QpkmBquuL1m0pNRPsbTylK21NAJ3DbQoxa93w8Wxy/WM UDxk8pkVmj4SueJNAqldB8zJeNLBWFacCReO65PwoSiWKbu+ybgxJaJ4uYzWsw0+hY35mfFeiGZNr UTejY6hA==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQ48-0000000EKUB-0emG; Fri, 26 Jan 2024 17:32:33 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rTQ46-00000001elD-3aD3; Fri, 26 Jan 2024 17:32:30 +0000 From: David Woodhouse To: qemu-devel@nongnu.org Cc: Richard Henderson , Beniamino Galvani , Peter Maydell , Strahinja Jankovic , Niek Linnenbank , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Andrew Jeffery , Joel Stanley , Igor Mitsyanko , Jean-Christophe Dubois , Andrey Smirnov , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Rob Herring , Subbaraya Sundeep , Jan Kiszka , Tyrone Ting , Hao Wu , Radoslaw Biernacki , Leif Lindholm , Marcin Juszkiewicz , "Edgar E. Iglesias" , Alistair Francis , Helge Deller , Paolo Bonzini , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Song Gao , Thomas Huth , Laurent Vivier , Huacai Chen , Jiaxun Yang , =?utf-8?q?Herv=C3=A9_Poussineau?= , Aleksandar Rikalo , Aurelien Jarno , Jason Wang , Jia Liu , Stafford Horne , Mark Cave-Ayland , Nicholas Piggin , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , Halil Pasic , Christian Borntraeger , Eric Farman , David Hildenbrand , Ilya Leoshkevich , Yoshinori Sato , Magnus Damm , Artyom Tarasenko , Stefano Stabellini , Anthony Perard , Paul Durrant , Max Filippov , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, xen-devel@lists.xenproject.org Subject: [PATCH v4 00/47] Rework matching of network devices to -nic options Date: Fri, 26 Jan 2024 17:24:37 +0000 Message-ID: <20240126173228.394202-1-dwmw2@infradead.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Received-SPF: none client-ip=2001:8b0:10b:1236::1; envelope-from=BATV+7caeb094913322f6f00d+7460+infradead.org+dwmw2@casper.srs.infradead.org; helo=casper.infradead.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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. v4: Fix LASI_82596 build and rework HPPA machine support for it. Slight improvement to ISA NE2000 error handling in hw/i386/pc.c. Document new functions better in include/net/net.h. v3: Rebase to 8.2 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 (47): 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: Re-enable build hw/net/lasi_i82596: use qemu_create_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 | 14 +- hw/i386/pc.c | 38 +++-- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/loongarch/virt.c | 4 +- hw/m68k/mcf5208.c | 19 +-- 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 | 13 +- hw/net/meson.build | 2 +- 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/lasi_82596.h | 4 +- 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 | 70 ++++++++- net/net.c | 253 +++++++++++++++++++++++++------ system/globals.c | 2 - tests/qtest/npcm7xx_emc-test.c | 18 +-- 81 files changed, 547 insertions(+), 562 deletions(-)