From patchwork Fri Jan 26 17:24:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13533056 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 994C5C47422 for ; Fri, 26 Jan 2024 17:43:39 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.672366.1046355 (Exim 4.92) (envelope-from ) id 1rTQEk-0007wP-SM; Fri, 26 Jan 2024 17:43:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 672366.1046355; Fri, 26 Jan 2024 17:43:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rTQEk-0007vi-O2; Fri, 26 Jan 2024 17:43:30 +0000 Received: by outflank-mailman (input) for mailman id 672366; Fri, 26 Jan 2024 17:43:29 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rTQ4s-0004Zo-PM for xen-devel@lists.xenproject.org; Fri, 26 Jan 2024 17:33:18 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fd88dcc9-bc70-11ee-8a43-1f161083a0e0; Fri, 26 Jan 2024 18:33:17 +0100 (CET) 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-0000000EKUE-0fRh; 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 1rTQ47-00000001elS-1KpR; Fri, 26 Jan 2024 17:32:31 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list X-Inumbo-ID: fd88dcc9-bc70-11ee-8a43-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=aYJS/1ZmHvWqcX4ZFiiuaV9MoKjFfmvD/b97zwR6RTs=; b=D64f2o9ExjTpXRh6lNheHhod11 XLpJhKTr1/lZ/clcWVHv+r0qH+hO9IuX+5OCKW5QJDKRgIlMeO3iBkxLep82231pjtiQUg/SOyZ+3 kjhYLEKlDpIMgbFMrc8eYUxT4T8BGApCoyxV8aAB2/qvZUVpaASy7tZZMOxv7/BwJeSYZ/WieflzD /vCQ5+IuDJHnHL+ksoy+2BpeR5ZcOp5mCPGHs8j+26cZsHFYatY5+TeRVWxRD3Ho5bnXnogPiHuc8 WSVGXMZp17QLskVWHPyiskERlqsA36ZvCQf/XY5SJw5rEWhvHK2BKKZ4JwepyYFw8DtXSoYj/1ob7 vYN8tDSQ==; 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, David Woodhouse Subject: [PATCH v4 05/47] hw/i386/pc: use qemu_get_nic_info() and pci_init_nic_devices() Date: Fri, 26 Jan 2024 17:24:42 +0000 Message-ID: <20240126173228.394202-6-dwmw2@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126173228.394202-1-dwmw2@infradead.org> References: <20240126173228.394202-1-dwmw2@infradead.org> MIME-Version: 1.0 Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html From: David Woodhouse 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. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/i386/pc.c | 31 +++++++++++++++++++------------ include/hw/net/ne2000-isa.h | 2 -- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 803244e5cc..ebb0b1c667 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -654,15 +654,19 @@ static const int ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 }; static const int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 }; -static void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd) +static gboolean pc_init_ne2k_isa(ISABus *bus, NICInfo *nd, Error **errp) { static int nb_ne2k = 0; - if (nb_ne2k == NE2000_NB_MAX) - return; + if (nb_ne2k == NE2000_NB_MAX) { + error_setg(errp, + "maximum number of ISA NE2000 devices exceeded"); + return false; + } isa_ne2000_init(bus, ne2000_io[nb_ne2k], ne2000_irq[nb_ne2k], nd); nb_ne2k++; + return true; } void pc_acpi_smi_interrupt(void *opaque, int irq, int level) @@ -1297,23 +1301,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 ((nd = 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, &error_fatal); + } + + /* Anything remaining should be a PCI NIC */ + pci_init_nic_devices(pci_bus, mc->default_nic); + rom_reset_order_override(); } diff --git a/include/hw/net/ne2000-isa.h b/include/hw/net/ne2000-isa.h index af59ee0b02..73bae10ad1 100644 --- a/include/hw/net/ne2000-isa.h +++ b/include/hw/net/ne2000-isa.h @@ -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);