From nobody Tue Nov 26 22:34:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1704747727; cv=none; d=zohomail.com; s=zohoarc; b=REcK5EUnXgX6lLLGmvEDjdK5/npGW3ojfuacHSziQlY0sYqPWIB3qL311az74jfQSJFFnyMEsKzO9iYpf1zA4cGI+NvvQzYIwKN+xxomvUcrq//nnD7DYeiqqdRpCTU5Iwli7wUeptLitRqu9J0axLuIa6+stwAliJy19n5BFnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704747727; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i9hItWZfcWRTcka7itvIlVb3WzSdfcm/EF0MHLcxS00=; b=H27dMEtwKLHDNfFuzQZTvoY7Bu0reMpozLvEVz9XGXwQeXxolFmNtsC/jqOLQ4MwkTLwW2M3K0B2FajJw7xX0xfAqtRtQO1QTyShHmGktlFS28Pg8F9qPANCAzZ4o7XHIk6Pbne0RLQ+HB3i2bdoaxcDM+RoMPUMOfx4WTcQOPg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1704747727014517.1408766446426; Mon, 8 Jan 2024 13:02:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.664005.1034096 (Exim 4.92) (envelope-from ) id 1rMwkr-0001M3-1j; Mon, 08 Jan 2024 21:01:53 +0000 Received: by outflank-mailman (output) from mailman id 664005.1034096; Mon, 08 Jan 2024 21:01:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rMwkq-0001Lw-Un; Mon, 08 Jan 2024 21:01:52 +0000 Received: by outflank-mailman (input) for mailman id 664005; Mon, 08 Jan 2024 21:01:52 +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 1rMwaU-0000R5-UQ for xen-devel@lists.xenproject.org; Mon, 08 Jan 2024 20:51:10 +0000 Received: from casper.infradead.org (casper.infradead.org [2001:8b0:10b:1236::1]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a69f7a23-ae67-11ee-98ef-6d05b1d4d9a1; Mon, 08 Jan 2024 21:51:10 +0100 (CET) Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1rMwYh-008RPJ-Rw; Mon, 08 Jan 2024 20:49:21 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96.2 #2 (Red Hat Linux)) id 1rMwYi-002NE7-1o; Mon, 08 Jan 2024 20:49:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: a69f7a23-ae67-11ee-98ef-6d05b1d4d9a1 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:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description; bh=i9hItWZfcWRTcka7itvIlVb3WzSdfcm/EF0MHLcxS00=; b=lTWq40DtjMn5XQVuUn8loyzT0I Pc1dg2yoA4UmhPLL2kSU//9y526qQpcf2MD3IkIaBHwJzIpLsMgl0wL2zb2LAnjSYOFuwoEpDpMIi 4Y8xUUJkE5sVfxJ8w3eE32+YCLVVlqscgNqIneZyfnd3rYGgXZgi9v2A+4E4C9xhfYmhO0/7xCnZj yxjkYTwbtPfAt+8hwWWuc+w4Go86FzyA7R8XHvZOH9/1uj2NQ8D8rmMG1hU698KD8Wt/gpUL1b0ZH vxKRNqZJHpxTFTnb/LxIiBOtGBFQ/VCNCrFugC4P+ZyxRUTxb4atUX2SUHmH6bFfLtqf/jCw6w0Wv 8WOpWVug==; 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=20Le=20Goater?= , Andrew Jeffery , Joel Stanley , Igor Mitsyanko , Jean-Christophe Dubois , Andrey Smirnov , =?UTF-8?q?Philippe=20Mathieu-Daud=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=20Poussineau?= , 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 v3 03/46] net: add qemu_create_nic_bus_devices() Date: Mon, 8 Jan 2024 20:26:32 +0000 Message-ID: <20240108204909.564514-4-dwmw2@infradead.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240108204909.564514-1-dwmw2@infradead.org> References: <20240108204909.564514-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) X-ZM-MESSAGEID: 1704747728017100001 From: David Woodhouse This will instantiate any NICs which live on a given bus type. Each bus is allowed *one* substitution (for PCI it's virtio =E2=86=92 virtio-net-pci= , for Xen it's xen =E2=86=92 xen-net-device; no point in overengineering it unles= s we actually want more). Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant Reviewed-by: Thomas Huth --- include/net/net.h | 3 +++ net/net.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 25ea83fd12..31e63d1f0d 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -213,6 +213,9 @@ bool qemu_configure_nic_device(DeviceState *dev, bool m= atch_default, const char *alias); DeviceState *qemu_create_nic_device(const char *typename, bool match_defau= lt, 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_targ= et); void print_net_client(Monitor *mon, NetClientState *nc); void net_socket_rs_init(SocketReadState *rs, SocketReadStateFinalize *finalize, diff --git a/net/net.c b/net/net.c index 962904eaef..4651b3f443 100644 --- a/net/net.c +++ b/net/net.c @@ -1223,6 +1223,59 @@ DeviceState *qemu_create_nic_device(const char *type= name, bool match_default, return dev; } =20 +void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type, + const char *default_model, + const char *alias, const char *alias_targ= et) +{ + GPtrArray *nic_models =3D qemu_get_nic_models(parent_type); + const char *model; + DeviceState *dev; + NICInfo *nd; + int i; + + if (nic_model_help) { + if (alias_target) { + add_nic_model_help(alias_target, alias); + } + for (i =3D 0; i < nic_models->len - 1; i++) { + add_nic_model_help(nic_models->pdata[i], NULL); + } + } + + /* Drop the NULL terminator which would make g_str_equal() unhappy */ + nic_models->len--; + + for (i =3D 0; i < nb_nics; i++) { + nd =3D &nd_table[i]; + + if (!nd->used || nd->instantiated) { + continue; + } + + model =3D nd->model ? nd->model : default_model; + if (!model) { + continue; + } + + /* Each bus type is allowed *one* substitution */ + if (g_str_equal(model, alias)) { + model =3D alias_target; + } + + if (!g_ptr_array_find_with_equal_func(nic_models, model, + g_str_equal, NULL)) { + /* This NIC does not live on this bus. */ + continue; + } + + dev =3D qdev_new(model); + qdev_set_nic_properties(dev, nd); + qdev_realize_and_unref(dev, bus, &error_fatal); + } + + g_ptr_array_free(nic_models, true); +} + static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])( const Netdev *netdev, const char *name, --=20 2.41.0