From patchwork Fri Feb 2 16:22:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13543137 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 09410C4828F for ; Fri, 2 Feb 2024 16:24:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVwJr-0001ys-Gs; Fri, 02 Feb 2024 11:23:11 -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 1rVwJq-0001yg-BO for qemu-devel@nongnu.org; Fri, 02 Feb 2024 11:23:10 -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 1rVwJn-0003eq-Oe for qemu-devel@nongnu.org; Fri, 02 Feb 2024 11:23:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:References: In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=51n49u1/rLdX+t/45andZIaaSAHe5YgY5tOFM/xaxWc=; b=LmaTys10P7teAZqhi/Fwq0i7pG X/w0TDnsCBuWXRyhMhG38zMRIiVv6kRMCZHu2lsjIIj+YQ/jaQYNHHJaod6vk//JIUpE5iLoIWEym Pi7oBVMvqYcSIqI4wnjVZJmSsmtxERWMU68+fR8qEuIsWXasoyValZXk8Ety+DYoUA6RD6hWMZEvB 3FqnuWlf3L3YtfbMXZ52oswoKXEYDhxniHuWtpe2R7Z9P6sV+lukSktohub4kcasD/CSGPurMg8ux GeagBJxSHu8DsnaAXgbnYnWgQBBI0VURIRJ+kT+4dKp31F/vbJtz2MegTSho31Wuxflybou+dYdKi iiG3/ppw==; Received: from [205.251.233.110] (helo=freeip.amazon.com) by casper.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVwJg-00000001VpX-2Af9; Fri, 02 Feb 2024 16:23:03 +0000 Message-ID: Subject: [PATCH v4.1 38/47] hw/net/lasi_i82596: use qemu_create_nic_device() From: David Woodhouse To: qemu-devel@nongnu.org Cc: Peter Maydell , Helge Deller , Jason Wang , Thomas Huth Date: Fri, 02 Feb 2024 08:22:56 -0800 In-Reply-To: <20240126173228.394202-39-dwmw2@infradead.org> References: <20240126173228.394202-1-dwmw2@infradead.org> <20240126173228.394202-39-dwmw2@infradead.org> User-Agent: Evolution 3.44.4-0ubuntu2 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+836f8942eaadfea8137c+7467+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 From: David Woodhouse Create the device only if there is a corresponding NIC config for it. Remove the explicit check on nd_table[0].used from hw/hppa/machine.c which (since commit d8a3220005d7) tries to do the same thing. The lasi_82596 support has been disabled since it was first introduced, since enable_lasi_lan() has always been zero. This allows the user to enable it by explicitly requesting a NIC model 'lasi_82596' or just using the alias 'lasi'. Otherwise, it defaults to a PCI NIC as before. Signed-off-by: David Woodhouse Reviewed-by: Thomas Huth --- v4.1: Only attempt to find GPIOs on the lasi_dev if it exists. This was theoretically broken already, but enable_lasi_dev() is hard-coded to zero, so adding the user override to enable it is what actually exposed the bug. (Not reposting the whole series for that) hw/hppa/machine.c | 9 ++++----- hw/net/lasi_i82596.c | 12 +++++++----- include/hw/net/lasi_82596.h | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index a1045b48cc..eb78c46ff1 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -362,14 +362,13 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, } /* Network setup. */ - if (nd_table[0].used && enable_lasi_lan()) { + if (lasi_dev) { lasi_82596_init(addr_space, translate(NULL, LASI_LAN_HPA), - qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA)); + qdev_get_gpio_in(lasi_dev, LASI_IRQ_LAN_HPA), + enable_lasi_lan()); } - if (!enable_lasi_lan()) { - pci_init_nic_devices(pci_bus, mc->default_nic); - } + pci_init_nic_devices(pci_bus, mc->default_nic); /* BMC board: HP Powerbar SP2 Diva (with console only) */ pci_dev = pci_new(-1, "pci-serial"); diff --git a/hw/net/lasi_i82596.c b/hw/net/lasi_i82596.c index 09e830ba5f..fcf7fae941 100644 --- a/hw/net/lasi_i82596.c +++ b/hw/net/lasi_i82596.c @@ -118,19 +118,21 @@ static void lasi_82596_realize(DeviceState *dev, Error **errp) i82596_common_init(dev, s, &net_lasi_82596_info); } -SysBusI82596State *lasi_82596_init(MemoryRegion *addr_space, - hwaddr hpa, qemu_irq lan_irq) +SysBusI82596State *lasi_82596_init(MemoryRegion *addr_space, hwaddr hpa, + qemu_irq lan_irq, gboolean match_default) { DeviceState *dev; SysBusI82596State *s; 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); + dev = qemu_create_nic_device(TYPE_LASI_82596, match_default, "lasi"); + if (!dev) { + return NULL; + } + s = SYSBUS_I82596(dev); s->state.irq = lan_irq; - qdev_set_nic_properties(dev, &nd_table[0]); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); s->state.conf.macaddr = HP_MAC; /* set HP MAC prefix */ diff --git a/include/hw/net/lasi_82596.h b/include/hw/net/lasi_82596.h index 3ef2f47ba2..439356ec19 100644 --- a/include/hw/net/lasi_82596.h +++ b/include/hw/net/lasi_82596.h @@ -25,7 +25,7 @@ struct SysBusI82596State { int val_index:1; }; -SysBusI82596State *lasi_82596_init(MemoryRegion *addr_space, - hwaddr hpa, qemu_irq irq); +SysBusI82596State *lasi_82596_init(MemoryRegion *addr_space, hwaddr hpa, + qemu_irq irq, gboolean match_default); #endif