From patchwork Wed Oct 16 21:24:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 13838969 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 71261D2F7C5 for ; Wed, 16 Oct 2024 21:26:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1BVI-00026i-Gw; Wed, 16 Oct 2024 17:24:24 -0400 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 1t1BVH-00026D-34; Wed, 16 Oct 2024 17:24:23 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t1BVF-00012l-Jz; Wed, 16 Oct 2024 17:24:22 -0400 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-a9a3dc089d8so35288266b.3; Wed, 16 Oct 2024 14:24:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729113859; x=1729718659; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IVwI7uw91/Pzkk9Jwk813s5wFhg5RsQ7pjAvW6ZM0yk=; b=RWOAG7oYfTNfVRMiQMzHqb5HQibO/pAav7cYa8FlEJFBsf4rUBne8cD2OcO6zviTHr BIRIZtBbhFAxA83rIpobOdIjvZaLuEwRwKLQlMJgfvITOi89KkFjS0ybMNahIL4UMSN1 iL/jv4WJKGo57GoUdeeloUztWU1uXyrdMDNhq+EzSidn3ateUzBBiXJJFAIHppsfUpO0 iObzxSbaxllZx2/Spm7ywmI3VNByVk/YRoAxMCubQsXUIsW+FnBI3GdZt65lLQjMBwrh 17nASplr3lwfMszM1BvD3mw8WSUAZNdZNF3aqAk9/sDJ9SHjoDBk2Y2mBViBgFViozj+ wDHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729113859; x=1729718659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IVwI7uw91/Pzkk9Jwk813s5wFhg5RsQ7pjAvW6ZM0yk=; b=w3pq7gVxGb1GGvep8E1m6gaJG+6CROnvxsozml2zwqf7kEFQeh3PaMsGgkm/JirnhY tDK1Enb+uqNyCdpOKi67+c303punnV9G2zC/tV6tWenobPke42X+jAWcTkKRIBODR7e9 I/I3nkh0eacdihncORtbbQfsKkhvteoEKVxOLaBAlGrhJGvTQqkwFpsvPIUSEVAA/2b9 GR+ty8iLKIm3XucfTGZr7WlB4wudNsVMsoEBic4NLomwnPgBr9uGTNIqoxWbdPXtXYsB 2K0MkIGq4FgBv2BKqz2j7fi6Fe3INsuLPomgE3GWmyXpqQeoTtpwQkDTwRTQVUNULl+6 w1TQ== X-Forwarded-Encrypted: i=1; AJvYcCW7VmfSIG/enfooUthViXOut56iDursRKTzeNSdF02ee5Wl3FazNw5J/WB3f+DaNSFq8OXQJQJZ7A==@nongnu.org X-Gm-Message-State: AOJu0Yxi5PV3bDI0FoUReJQE40PbvgBxdijEz7N4WG7p6IVtv+H6pNxX o6CQT15Y/ELWtO9v+mRWOdDhUpL4lWOjWGjl6uLg9HLjbHcsy0S2PeG0ng== X-Google-Smtp-Source: AGHT+IErxbozJzZLEWdF0Ml4Mwe7FQHVIjkej4uQ+e6cllNdotEIZ7aupqpVDMk801ar+h6ZlrvmzQ== X-Received: by 2002:a17:907:788:b0:a99:46dd:f397 with SMTP id a640c23a62f3a-a99e3e9c018mr1643215366b.64.1729113858896; Wed, 16 Oct 2024 14:24:18 -0700 (PDT) Received: from archlinux.. (dynamic-077-191-025-143.77.191.pool.telefonica.de. [77.191.25.143]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29750a9asm218005766b.88.2024.10.16.14.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 14:24:17 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Jason Wang , qemu-arm@nongnu.org, Peter Maydell , Guenter Roeck , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 1/5] hw/resettable: Add SOFT reset type Date: Wed, 16 Oct 2024 23:24:03 +0200 Message-ID: <20241016212407.139390-2-shentey@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241016212407.139390-1-shentey@gmail.com> References: <20241016212407.139390-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=shentey@gmail.com; helo=mail-ej1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 This is a preparation for the next patch. Signed-off-by: Bernhard Beschow --- include/hw/resettable.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/hw/resettable.h b/include/hw/resettable.h index fd862f1e9f..0f25beaf21 100644 --- a/include/hw/resettable.h +++ b/include/hw/resettable.h @@ -40,6 +40,7 @@ typedef enum ResetType { RESET_TYPE_WAKEUP, RESET_TYPE_S390_CPU_INITIAL, RESET_TYPE_S390_CPU_NORMAL, + RESET_TYPE_SOFT, } ResetType; /* From patchwork Wed Oct 16 21:24:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 13838965 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 D2A56D2F7C7 for ; Wed, 16 Oct 2024 21:25:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1BVK-00027c-SX; Wed, 16 Oct 2024 17:24:26 -0400 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 1t1BVJ-00027K-L0; Wed, 16 Oct 2024 17:24:25 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t1BVH-00012z-Ea; Wed, 16 Oct 2024 17:24:25 -0400 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-5c9552d02e6so373973a12.2; Wed, 16 Oct 2024 14:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729113861; x=1729718661; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4pwMzFsI8pRJGAQHQBZx71yAsfOkq1Pp8cUgpMPjzxQ=; b=fDqdIlcSNucLxmuSmj3LqN4hcwrMG1/ykHgc4rblUYGawSVR9BgWowGvu6x8qTaekM tVCO+S5IGmz7hK8kkdfm0EccGzyz5V1bl/SJpmmNmXojmKXRXRVoyRejWVfB4gC4VRDE j7mxy2nhGYz2nNSMIv8GC55tokfiiCObj6LaFWltno6JNzMc8ChZ//Y4C+l/2ruBJE/a haJ2eLgM19ygsIcGcHm+Y9sBJTmxDpSnymebUHliIuqAKFStE2NVPaN9X5FZ7rfVPfxY YxUuRW18ziYuAEbbtZO7bAIxi9V8UtDQAUWz036+Q68OYZ+9lDijX2cvmaTNDhKMsG5n /7PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729113861; x=1729718661; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4pwMzFsI8pRJGAQHQBZx71yAsfOkq1Pp8cUgpMPjzxQ=; b=e3NyTd9XTte2tQ7h/L8Wn5EiPrXir2Kxbl8EmqAIptmDKfd71OdgvFt0nFCCyO5ftk v1rLQnsvMKNtWYV7juLUw+mjJZi4euYU34c+kRg92jUn8B2GIer5vs/XWW/matNxk7X7 ai02J2r4dYgPNJFAh+FsszQFzWKQKYIPt/hMvpPcCsUSwH0wXw+dBBPiOy8Kl6RVfZmg SF9ZVZrly0a+bLgQjyhl7W3TXHQd5wcTmaCTXKSCboZVSGQWwUZ5Ngo4qzHzEZ2HmnuC 6OpjQrAC/MPF7L4vA2SOHzUMnLFX1jP7etCiIqh6NesZu+J+5CFDota1GyHEPwY75dbk ZHuw== X-Forwarded-Encrypted: i=1; AJvYcCWj2D3NkTd0cXWFA/w0cuPa/jXgy5JiSX56KxfZuWTIFXro2IAbFl5m9L3PTVVpTc8VSyFbx1D09A==@nongnu.org X-Gm-Message-State: AOJu0YwHRRBPcyJsF1lSHaQNOZdqCe5VyT3qtJMEtYZBh29x97+aX7hb jwMPPVN9MdLzOaR8FCRDzlPO/ikiXMLLZ23AFWcHixZudnwncQRkAXSGyQ== X-Google-Smtp-Source: AGHT+IGHDcilAFZ2TNJ1RLdWmQIh8a4d9uX0xOYA4hIyie4L9t6WxrUNo7qi9Joj+XOtwHNrKOB/PQ== X-Received: by 2002:a17:907:e217:b0:a99:5d01:dbd4 with SMTP id a640c23a62f3a-a9a34e4b98cmr416714266b.59.1729113860494; Wed, 16 Oct 2024 14:24:20 -0700 (PDT) Received: from archlinux.. (dynamic-077-191-025-143.77.191.pool.telefonica.de. [77.191.25.143]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29750a9asm218005766b.88.2024.10.16.14.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 14:24:19 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Jason Wang , qemu-arm@nongnu.org, Peter Maydell , Guenter Roeck , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 2/5] hw/net/lan9118: Extract lan9118_phy Date: Wed, 16 Oct 2024 23:24:04 +0200 Message-ID: <20241016212407.139390-3-shentey@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241016212407.139390-1-shentey@gmail.com> References: <20241016212407.139390-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=shentey@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 A very similar implementation of the same device exists in imx_fec. Prepare for a common implementation by extracting a device model into its own files. Some migration state has been moved into the new device model which breaks migration compatibility for the following machines: * smdkc210 * realview-* * vexpress-* * kzm * mps2-* Signed-off-by: Bernhard Beschow --- include/hw/net/lan9118_phy.h | 36 ++++++++ hw/net/lan9118.c | 137 +++++------------------------ hw/net/lan9118_phy.c | 164 +++++++++++++++++++++++++++++++++++ hw/net/Kconfig | 4 + hw/net/meson.build | 1 + 5 files changed, 227 insertions(+), 115 deletions(-) create mode 100644 include/hw/net/lan9118_phy.h create mode 100644 hw/net/lan9118_phy.c diff --git a/include/hw/net/lan9118_phy.h b/include/hw/net/lan9118_phy.h new file mode 100644 index 0000000000..9c7e21f0c3 --- /dev/null +++ b/include/hw/net/lan9118_phy.h @@ -0,0 +1,36 @@ +/* + * SMSC LAN9118 PHY emulation + * + * Copyright (c) 2009 CodeSourcery, LLC. + * Written by Paul Brook + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef HW_NET_LAN9118_PHY_H +#define HW_NET_LAN9118_PHY_H + +#include "qom/object.h" +#include "hw/sysbus.h" + +#define TYPE_LAN9118_PHY "lan9118-phy" +OBJECT_DECLARE_SIMPLE_TYPE(Lan9118PhyState, LAN9118_PHY) + +typedef struct Lan9118PhyState { + SysBusDevice parent_obj; + + uint32_t status; + uint32_t control; + uint32_t advertise; + uint32_t ints; + uint32_t int_mask; + qemu_irq irq; + bool link_down; +} Lan9118PhyState; + +void lan9118_phy_update_link(Lan9118PhyState *s, bool link_down); +uint32_t lan9118_phy_read(Lan9118PhyState *s, int reg); +void lan9118_phy_write(Lan9118PhyState *s, int reg, uint32_t val); + +#endif diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c index db28a0ef30..debf0827cf 100644 --- a/hw/net/lan9118.c +++ b/hw/net/lan9118.c @@ -16,6 +16,7 @@ #include "net/net.h" #include "net/eth.h" #include "hw/irq.h" +#include "hw/net/lan9118_phy.h" #include "hw/net/lan9118.h" #include "hw/ptimer.h" #include "hw/qdev-properties.h" @@ -139,14 +140,6 @@ do { printf("lan9118: " fmt , ## __VA_ARGS__); } while (0) #define MAC_CR_RXEN 0x00000004 #define MAC_CR_RESERVED 0x7f404213 -#define PHY_INT_ENERGYON 0x80 -#define PHY_INT_AUTONEG_COMPLETE 0x40 -#define PHY_INT_FAULT 0x20 -#define PHY_INT_DOWN 0x10 -#define PHY_INT_AUTONEG_LP 0x08 -#define PHY_INT_PARFAULT 0x04 -#define PHY_INT_AUTONEG_PAGE 0x02 - #define GPT_TIMER_EN 0x20000000 /* @@ -228,11 +221,8 @@ struct lan9118_state { uint32_t mac_mii_data; uint32_t mac_flow; - uint32_t phy_status; - uint32_t phy_control; - uint32_t phy_advertise; - uint32_t phy_int; - uint32_t phy_int_mask; + Lan9118PhyState mii; + IRQState mii_irq; int32_t eeprom_writable; uint8_t eeprom[128]; @@ -274,8 +264,8 @@ struct lan9118_state { static const VMStateDescription vmstate_lan9118 = { .name = "lan9118", - .version_id = 2, - .minimum_version_id = 1, + .version_id = 3, + .minimum_version_id = 3, .fields = (const VMStateField[]) { VMSTATE_PTIMER(timer, lan9118_state), VMSTATE_UINT32(irq_cfg, lan9118_state), @@ -301,11 +291,6 @@ static const VMStateDescription vmstate_lan9118 = { VMSTATE_UINT32(mac_mii_acc, lan9118_state), VMSTATE_UINT32(mac_mii_data, lan9118_state), VMSTATE_UINT32(mac_flow, lan9118_state), - VMSTATE_UINT32(phy_status, lan9118_state), - VMSTATE_UINT32(phy_control, lan9118_state), - VMSTATE_UINT32(phy_advertise, lan9118_state), - VMSTATE_UINT32(phy_int, lan9118_state), - VMSTATE_UINT32(phy_int_mask, lan9118_state), VMSTATE_INT32(eeprom_writable, lan9118_state), VMSTATE_UINT8_ARRAY(eeprom, lan9118_state, 128), VMSTATE_INT32(tx_fifo_size, lan9118_state), @@ -385,9 +370,11 @@ static void lan9118_reload_eeprom(lan9118_state *s) lan9118_mac_changed(s); } -static void phy_update_irq(lan9118_state *s) +static void lan9118_update_irq(void *opaque, int n, int level) { - if (s->phy_int & s->phy_int_mask) { + lan9118_state *s = opaque; + + if (level) { s->int_sts |= PHY_INT; } else { s->int_sts &= ~PHY_INT; @@ -395,33 +382,10 @@ static void phy_update_irq(lan9118_state *s) lan9118_update(s); } -static void phy_update_link(lan9118_state *s) -{ - /* Autonegotiation status mirrors link status. */ - if (qemu_get_queue(s->nic)->link_down) { - s->phy_status &= ~0x0024; - s->phy_int |= PHY_INT_DOWN; - } else { - s->phy_status |= 0x0024; - s->phy_int |= PHY_INT_ENERGYON; - s->phy_int |= PHY_INT_AUTONEG_COMPLETE; - } - phy_update_irq(s); -} - static void lan9118_set_link(NetClientState *nc) { - phy_update_link(qemu_get_nic_opaque(nc)); -} - -static void phy_reset(lan9118_state *s) -{ - s->phy_status = 0x7809; - s->phy_control = 0x3000; - s->phy_advertise = 0x01e1; - s->phy_int_mask = 0; - s->phy_int = 0; - phy_update_link(s); + lan9118_phy_update_link(&LAN9118(qemu_get_nic_opaque(nc))->mii, + nc->link_down); } static void lan9118_reset(DeviceState *d) @@ -478,8 +442,6 @@ static void lan9118_reset(DeviceState *d) s->read_word_n = 0; s->write_word_n = 0; - phy_reset(s); - s->eeprom_writable = 0; lan9118_reload_eeprom(s); } @@ -678,7 +640,7 @@ static void do_tx_packet(lan9118_state *s) uint32_t status; /* FIXME: Honor TX disable, and allow queueing of packets. */ - if (s->phy_control & 0x4000) { + if (s->mii.control & 0x4000) { /* This assumes the receive routine doesn't touch the VLANClient. */ qemu_receive_packet(qemu_get_queue(s->nic), s->txp->data, s->txp->len); } else { @@ -834,68 +796,6 @@ static void tx_fifo_push(lan9118_state *s, uint32_t val) } } -static uint32_t do_phy_read(lan9118_state *s, int reg) -{ - uint32_t val; - - switch (reg) { - case 0: /* Basic Control */ - return s->phy_control; - case 1: /* Basic Status */ - return s->phy_status; - case 2: /* ID1 */ - return 0x0007; - case 3: /* ID2 */ - return 0xc0d1; - case 4: /* Auto-neg advertisement */ - return s->phy_advertise; - case 5: /* Auto-neg Link Partner Ability */ - return 0x0f71; - case 6: /* Auto-neg Expansion */ - return 1; - /* TODO 17, 18, 27, 29, 30, 31 */ - case 29: /* Interrupt source. */ - val = s->phy_int; - s->phy_int = 0; - phy_update_irq(s); - return val; - case 30: /* Interrupt mask */ - return s->phy_int_mask; - default: - qemu_log_mask(LOG_GUEST_ERROR, - "do_phy_read: PHY read reg %d\n", reg); - return 0; - } -} - -static void do_phy_write(lan9118_state *s, int reg, uint32_t val) -{ - switch (reg) { - case 0: /* Basic Control */ - if (val & 0x8000) { - phy_reset(s); - break; - } - s->phy_control = val & 0x7980; - /* Complete autonegotiation immediately. */ - if (val & 0x1000) { - s->phy_status |= 0x0020; - } - break; - case 4: /* Auto-neg advertisement */ - s->phy_advertise = (val & 0x2d7f) | 0x80; - break; - /* TODO 17, 18, 27, 31 */ - case 30: /* Interrupt mask */ - s->phy_int_mask = val & 0xff; - phy_update_irq(s); - break; - default: - qemu_log_mask(LOG_GUEST_ERROR, - "do_phy_write: PHY write reg %d = 0x%04x\n", reg, val); - } -} - static void do_mac_write(lan9118_state *s, int reg, uint32_t val) { switch (reg) { @@ -929,9 +829,9 @@ static void do_mac_write(lan9118_state *s, int reg, uint32_t val) if (val & 2) { DPRINTF("PHY write %d = 0x%04x\n", (val >> 6) & 0x1f, s->mac_mii_data); - do_phy_write(s, (val >> 6) & 0x1f, s->mac_mii_data); + lan9118_phy_write(&s->mii, (val >> 6) & 0x1f, s->mac_mii_data); } else { - s->mac_mii_data = do_phy_read(s, (val >> 6) & 0x1f); + s->mac_mii_data = lan9118_phy_read(&s->mii, (val >> 6) & 0x1f); DPRINTF("PHY read %d = 0x%04x\n", (val >> 6) & 0x1f, s->mac_mii_data); } @@ -1126,7 +1026,7 @@ static void lan9118_writel(void *opaque, hwaddr offset, break; case CSR_PMT_CTRL: if (val & 0x400) { - phy_reset(s); + resettable_reset(OBJECT(&s->mii), RESET_TYPE_SOFT); } s->pmt_ctrl &= ~0x34e; s->pmt_ctrl |= (val & 0x34e); @@ -1373,6 +1273,13 @@ static void lan9118_realize(DeviceState *dev, Error **errp) const MemoryRegionOps *mem_ops = s->mode_16bit ? &lan9118_16bit_mem_ops : &lan9118_mem_ops; + qemu_init_irq(&s->mii_irq, lan9118_update_irq, s, 0); + object_initialize_child(OBJECT(s), "mii", &s->mii, TYPE_LAN9118_PHY); + if (!sysbus_realize_and_unref(SYS_BUS_DEVICE(&s->mii), errp)) { + return; + } + qdev_connect_gpio_out(DEVICE(&s->mii), 0, &s->mii_irq); + memory_region_init_io(&s->mmio, OBJECT(dev), mem_ops, s, "lan9118-mmio", 0x100); sysbus_init_mmio(sbd, &s->mmio); diff --git a/hw/net/lan9118_phy.c b/hw/net/lan9118_phy.c new file mode 100644 index 0000000000..5c2faaf00a --- /dev/null +++ b/hw/net/lan9118_phy.c @@ -0,0 +1,164 @@ +/* + * SMSC LAN9118 PHY emulation + * + * Copyright (c) 2009 CodeSourcery, LLC. + * Written by Paul Brook + * + * This code is licensed under the GNU GPL v2 + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "hw/net/lan9118_phy.h" +#include "hw/irq.h" +#include "hw/resettable.h" +#include "migration/vmstate.h" +#include "qemu/log.h" + +#define PHY_INT_ENERGYON (1 << 7) +#define PHY_INT_AUTONEG_COMPLETE (1 << 6) +#define PHY_INT_FAULT (1 << 5) +#define PHY_INT_DOWN (1 << 4) +#define PHY_INT_AUTONEG_LP (1 << 3) +#define PHY_INT_PARFAULT (1 << 2) +#define PHY_INT_AUTONEG_PAGE (1 << 1) + +static void lan9118_phy_update_irq(Lan9118PhyState *s) +{ + qemu_set_irq(s->irq, !!(s->ints & s->int_mask)); +} + +void lan9118_phy_update_link(Lan9118PhyState *s, bool link_down) +{ + s->link_down = link_down; + + /* Autonegotiation status mirrors link status. */ + if (link_down) { + s->status &= ~0x0024; + s->ints |= PHY_INT_DOWN; + } else { + s->status |= 0x0024; + s->ints |= PHY_INT_ENERGYON; + s->ints |= PHY_INT_AUTONEG_COMPLETE; + } + lan9118_phy_update_irq(s); +} + +static void lan9118_phy_reset(Object *obj, ResetType type) +{ + Lan9118PhyState *s = LAN9118_PHY(obj); + + s->status = 0x7809; + s->control = 0x3000; + s->advertise = 0x01e1; + s->int_mask = 0; + s->ints = 0; + lan9118_phy_update_link(s, s->link_down); +} + +uint32_t lan9118_phy_read(Lan9118PhyState *s, int reg) +{ + uint32_t val; + + switch (reg) { + case 0: /* Basic Control */ + return s->control; + case 1: /* Basic Status */ + return s->status; + case 2: /* ID1 */ + return 0x0007; + case 3: /* ID2 */ + return 0xc0d1; + case 4: /* Auto-neg advertisement */ + return s->advertise; + case 5: /* Auto-neg Link Partner Ability */ + return 0x0f71; + case 6: /* Auto-neg Expansion */ + return 1; + /* TODO 17, 18, 27, 29, 30, 31 */ + case 29: /* Interrupt source. */ + val = s->ints; + s->ints = 0; + lan9118_phy_update_irq(s); + return val; + case 30: /* Interrupt mask */ + return s->int_mask; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "lan9118_phy_read: PHY read reg %d\n", reg); + return 0; + } +} + +void lan9118_phy_write(Lan9118PhyState *s, int reg, uint32_t val) +{ + switch (reg) { + case 0: /* Basic Control */ + if (val & 0x8000) { + lan9118_phy_reset(OBJECT(s), RESET_TYPE_SOFT); + break; + } + s->control = val & 0x7980; + /* Complete autonegotiation immediately. */ + if (val & 0x1000) { + s->status |= 0x0020; + } + break; + case 4: /* Auto-neg advertisement */ + s->advertise = (val & 0x2d7f) | 0x80; + break; + /* TODO 17, 18, 27, 31 */ + case 30: /* Interrupt mask */ + s->int_mask = val & 0xff; + lan9118_phy_update_irq(s); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "lan9118_phy_write: PHY write reg %d = 0x%04x\n", reg, val); + } +} + +static void lan9118_phy_init(Object *obj) +{ + Lan9118PhyState *s = LAN9118_PHY(obj); + + qdev_init_gpio_out(DEVICE(s), &s->irq, 1); +} + +static const VMStateDescription vmstate_lan9118_phy = { + .name = "lan9118-phy", + .version_id = 1, + .minimum_version_id = 1, + .fields = (const VMStateField[]) { + VMSTATE_UINT32(status, Lan9118PhyState), + VMSTATE_UINT32(control, Lan9118PhyState), + VMSTATE_UINT32(advertise, Lan9118PhyState), + VMSTATE_UINT32(ints, Lan9118PhyState), + VMSTATE_UINT32(int_mask, Lan9118PhyState), + VMSTATE_BOOL(link_down, Lan9118PhyState), + VMSTATE_END_OF_LIST() + } +}; + +static void lan9118_phy_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + DeviceClass *dc = DEVICE_CLASS(klass); + + rc->phases.hold = lan9118_phy_reset; + dc->vmsd = &vmstate_lan9118_phy; +} + +static const TypeInfo types[] = { + { + .name = TYPE_LAN9118_PHY, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(Lan9118PhyState), + .instance_init = lan9118_phy_init, + .class_init = lan9118_phy_class_init, + } +}; + +DEFINE_TYPES(types) diff --git a/hw/net/Kconfig b/hw/net/Kconfig index 7fcc0d7faa..6b2ff2f937 100644 --- a/hw/net/Kconfig +++ b/hw/net/Kconfig @@ -62,8 +62,12 @@ config VMXNET3_PCI config SMC91C111 bool +config LAN9118_PHY + bool + config LAN9118 bool + select LAN9118_PHY select PTIMER config NE2000_ISA diff --git a/hw/net/meson.build b/hw/net/meson.build index 00a9e9dd51..3bb5d749a8 100644 --- a/hw/net/meson.build +++ b/hw/net/meson.build @@ -19,6 +19,7 @@ system_ss.add(when: 'CONFIG_VMXNET3_PCI', if_true: files('vmxnet3.c')) system_ss.add(when: 'CONFIG_SMC91C111', if_true: files('smc91c111.c')) system_ss.add(when: 'CONFIG_LAN9118', if_true: files('lan9118.c')) +system_ss.add(when: 'CONFIG_LAN9118_PHY', if_true: files('lan9118_phy.c')) system_ss.add(when: 'CONFIG_NE2000_ISA', if_true: files('ne2000-isa.c')) system_ss.add(when: 'CONFIG_OPENCORES_ETH', if_true: files('opencores_eth.c')) system_ss.add(when: 'CONFIG_XGMAC', if_true: files('xgmac.c')) From patchwork Wed Oct 16 21:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 13838967 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 7F47AD2F7C6 for ; Wed, 16 Oct 2024 21:25:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1BVM-00028q-LS; Wed, 16 Oct 2024 17:24:28 -0400 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 1t1BVK-00027d-UT; Wed, 16 Oct 2024 17:24:26 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t1BVI-00013I-P7; Wed, 16 Oct 2024 17:24:26 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a99f3a5a44cso28882166b.3; Wed, 16 Oct 2024 14:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729113862; x=1729718662; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/YIisYjguex/Eo3l7bXcmDH0f/Tjcjxx12AvM8bQip8=; b=f0Npj+xnFi5Q3zI1vzSQAx1kh7ncM2x0cJLz7QJtjTeqOQ/7kv3lJUcyOCcnV3P6O9 Ky0RDsnRARyiaT9omBdKsgKaq+NxSMe7S4U2dWGkjmTFxeNoO3nsQrWKKAere4BMRO4f X7nI56voT/HdHHcxn3yDjH03goV9eIovMMxUrSMM6D9QLHkuh2U8vUrSEazOwj1ODeco PaBAuNE4iP7UTu0pp99gbaIdC5CZ4+NZsdTjqgpyZhWcW57h4Vryv7vfQW8eVyli1k/i a2fTvAFfmie1+NdAOkQhjjlDdFPc+Kzvdzh0Ha3/6xFgoXlbefOuGbeFOla6hznxkY7T qq5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729113862; x=1729718662; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/YIisYjguex/Eo3l7bXcmDH0f/Tjcjxx12AvM8bQip8=; b=huF5/6THfJczfaokaO3x28RKWQZ2DK/ivw5dJ6Xqo+c/MYng0wU9++bDPchHUnCV3m 3V5qb6puWjunDhX6abZEkOLcRWb7pyFScE9JKFJ2yOwY1YgMSj9svw7x25TH/BSxzmCH Wf1X5pZch0uLGxNV21x3fcGsoh3rdgOpyGWrNAZmnX/LU95P94iQ7Ovasl0agNC93bFc i+ekDKGLGsv/+N0KjeW7BFZsNT9YYw1omGnHGOcNj7TA2d3sNUa25RRrXQDBHVcZCCLR GI79BYzPD6f08h0n0mtjPy/uAS8PatdfOgtuvxl0a7djZXNaF+jiuF7qSWMebWNxQ8bX Nc6Q== X-Forwarded-Encrypted: i=1; AJvYcCU7aXGzDXBHCedtxSsvWg7D5mqoKaxTO7LAmuuhiQvMaPoF86GtKRHiR0A6zMVgGYrI1C9mCSSKhQ==@nongnu.org X-Gm-Message-State: AOJu0YyBHuNWNp8o8glrY6PaxH0LfeOViOk2U9mxJDFs+TNIGC2YR3uM qGeQWpf++XzPl/cmHeaKFmZetQUy2Rlg++klsUJvZDXKS6E9n80tnL/6Zg== X-Google-Smtp-Source: AGHT+IGoJPG4BgeG8QP7LYS4zEhBd+rkcoSNqBRB3F3zo06FtdvY0DFWPTYYjaVqCSU/cRxYq2HDsA== X-Received: by 2002:a17:907:c894:b0:a99:d6e1:605f with SMTP id a640c23a62f3a-a9a34cb582amr432935166b.14.1729113862216; Wed, 16 Oct 2024 14:24:22 -0700 (PDT) Received: from archlinux.. (dynamic-077-191-025-143.77.191.pool.telefonica.de. [77.191.25.143]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29750a9asm218005766b.88.2024.10.16.14.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 14:24:21 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Jason Wang , qemu-arm@nongnu.org, Peter Maydell , Guenter Roeck , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 3/5] hw/net/lan9118_phy: Reuse in imx_fec and consolidate implementations Date: Wed, 16 Oct 2024 23:24:05 +0200 Message-ID: <20241016212407.139390-4-shentey@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241016212407.139390-1-shentey@gmail.com> References: <20241016212407.139390-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=shentey@gmail.com; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 imx_fec models the same PHY as lan9118_phy. The code is almost the same with imx_fec having more logging and tracing. Merge these improvements into lan9118_phy and reuse in imx_fec to fix the code duplication. Some migration state how resides in the new device model which breaks migration compatibility for the following machines: * imx25-pdk * sabrelite * mcimx7d-sabre * mcimx6ul-evk Signed-off-by: Bernhard Beschow --- include/hw/net/imx_fec.h | 9 ++- hw/net/imx_fec.c | 146 ++++----------------------------------- hw/net/lan9118_phy.c | 80 +++++++++++++++------ hw/net/Kconfig | 1 + hw/net/trace-events | 10 +-- 5 files changed, 84 insertions(+), 162 deletions(-) diff --git a/include/hw/net/imx_fec.h b/include/hw/net/imx_fec.h index 2d13290c78..83b21637ee 100644 --- a/include/hw/net/imx_fec.h +++ b/include/hw/net/imx_fec.h @@ -31,6 +31,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(IMXFECState, IMX_FEC) #define TYPE_IMX_ENET "imx.enet" #include "hw/sysbus.h" +#include "hw/net/lan9118_phy.h" +#include "hw/irq.h" #include "net/net.h" #define ENET_EIR 1 @@ -264,11 +266,8 @@ struct IMXFECState { uint32_t tx_descriptor[ENET_TX_RING_NUM]; uint32_t tx_ring_num; - uint32_t phy_status; - uint32_t phy_control; - uint32_t phy_advertise; - uint32_t phy_int; - uint32_t phy_int_mask; + Lan9118PhyState mii; + IRQState mii_irq; uint32_t phy_num; bool phy_connected; struct IMXFECState *phy_consumer; diff --git a/hw/net/imx_fec.c b/hw/net/imx_fec.c index 6294d29202..4ee6f74206 100644 --- a/hw/net/imx_fec.c +++ b/hw/net/imx_fec.c @@ -203,17 +203,12 @@ static const VMStateDescription vmstate_imx_eth_txdescs = { static const VMStateDescription vmstate_imx_eth = { .name = TYPE_IMX_FEC, - .version_id = 2, - .minimum_version_id = 2, + .version_id = 3, + .minimum_version_id = 3, .fields = (const VMStateField[]) { VMSTATE_UINT32_ARRAY(regs, IMXFECState, ENET_MAX), VMSTATE_UINT32(rx_descriptor, IMXFECState), VMSTATE_UINT32(tx_descriptor[0], IMXFECState), - VMSTATE_UINT32(phy_status, IMXFECState), - VMSTATE_UINT32(phy_control, IMXFECState), - VMSTATE_UINT32(phy_advertise, IMXFECState), - VMSTATE_UINT32(phy_int, IMXFECState), - VMSTATE_UINT32(phy_int_mask, IMXFECState), VMSTATE_END_OF_LIST() }, .subsections = (const VMStateDescription * const []) { @@ -222,14 +217,6 @@ static const VMStateDescription vmstate_imx_eth = { }, }; -#define PHY_INT_ENERGYON (1 << 7) -#define PHY_INT_AUTONEG_COMPLETE (1 << 6) -#define PHY_INT_FAULT (1 << 5) -#define PHY_INT_DOWN (1 << 4) -#define PHY_INT_AUTONEG_LP (1 << 3) -#define PHY_INT_PARFAULT (1 << 2) -#define PHY_INT_AUTONEG_PAGE (1 << 1) - static void imx_eth_update(IMXFECState *s); /* @@ -238,47 +225,19 @@ static void imx_eth_update(IMXFECState *s); * For now we don't handle any GPIO/interrupt line, so the OS will * have to poll for the PHY status. */ -static void imx_phy_update_irq(IMXFECState *s) -{ - imx_eth_update(s); -} - -static void imx_phy_update_link(IMXFECState *s) +static void imx_phy_update_irq(void *opaque, int n, int level) { - /* Autonegotiation status mirrors link status. */ - if (qemu_get_queue(s->nic)->link_down) { - trace_imx_phy_update_link("down"); - s->phy_status &= ~0x0024; - s->phy_int |= PHY_INT_DOWN; - } else { - trace_imx_phy_update_link("up"); - s->phy_status |= 0x0024; - s->phy_int |= PHY_INT_ENERGYON; - s->phy_int |= PHY_INT_AUTONEG_COMPLETE; - } - imx_phy_update_irq(s); + imx_eth_update(opaque); } static void imx_eth_set_link(NetClientState *nc) { - imx_phy_update_link(IMX_FEC(qemu_get_nic_opaque(nc))); -} - -static void imx_phy_reset(IMXFECState *s) -{ - trace_imx_phy_reset(); - - s->phy_status = 0x7809; - s->phy_control = 0x3000; - s->phy_advertise = 0x01e1; - s->phy_int_mask = 0; - s->phy_int = 0; - imx_phy_update_link(s); + lan9118_phy_update_link(&IMX_FEC(qemu_get_nic_opaque(nc))->mii, + nc->link_down); } static uint32_t imx_phy_read(IMXFECState *s, int reg) { - uint32_t val; uint32_t phy = reg / 32; if (!s->phy_connected) { @@ -296,54 +255,7 @@ static uint32_t imx_phy_read(IMXFECState *s, int reg) reg %= 32; - switch (reg) { - case 0: /* Basic Control */ - val = s->phy_control; - break; - case 1: /* Basic Status */ - val = s->phy_status; - break; - case 2: /* ID1 */ - val = 0x0007; - break; - case 3: /* ID2 */ - val = 0xc0d1; - break; - case 4: /* Auto-neg advertisement */ - val = s->phy_advertise; - break; - case 5: /* Auto-neg Link Partner Ability */ - val = 0x0f71; - break; - case 6: /* Auto-neg Expansion */ - val = 1; - break; - case 29: /* Interrupt source. */ - val = s->phy_int; - s->phy_int = 0; - imx_phy_update_irq(s); - break; - case 30: /* Interrupt mask */ - val = s->phy_int_mask; - break; - case 17: - case 18: - case 27: - case 31: - qemu_log_mask(LOG_UNIMP, "[%s.phy]%s: reg %d not implemented\n", - TYPE_IMX_FEC, __func__, reg); - val = 0; - break; - default: - qemu_log_mask(LOG_GUEST_ERROR, "[%s.phy]%s: Bad address at offset %d\n", - TYPE_IMX_FEC, __func__, reg); - val = 0; - break; - } - - trace_imx_phy_read(val, phy, reg); - - return val; + return lan9118_phy_read(&s->mii, reg); } static void imx_phy_write(IMXFECState *s, int reg, uint32_t val) @@ -365,39 +277,7 @@ static void imx_phy_write(IMXFECState *s, int reg, uint32_t val) reg %= 32; - trace_imx_phy_write(val, phy, reg); - - switch (reg) { - case 0: /* Basic Control */ - if (val & 0x8000) { - imx_phy_reset(s); - } else { - s->phy_control = val & 0x7980; - /* Complete autonegotiation immediately. */ - if (val & 0x1000) { - s->phy_status |= 0x0020; - } - } - break; - case 4: /* Auto-neg advertisement */ - s->phy_advertise = (val & 0x2d7f) | 0x80; - break; - case 30: /* Interrupt mask */ - s->phy_int_mask = val & 0xff; - imx_phy_update_irq(s); - break; - case 17: - case 18: - case 27: - case 31: - qemu_log_mask(LOG_UNIMP, "[%s.phy)%s: reg %d not implemented\n", - TYPE_IMX_FEC, __func__, reg); - break; - default: - qemu_log_mask(LOG_GUEST_ERROR, "[%s.phy]%s: Bad address at offset %d\n", - TYPE_IMX_FEC, __func__, reg); - break; - } + lan9118_phy_write(&s->mii, reg, val); } static void imx_fec_read_bd(IMXFECBufDesc *bd, dma_addr_t addr) @@ -682,9 +562,6 @@ static void imx_eth_reset(DeviceState *d) s->rx_descriptor = 0; memset(s->tx_descriptor, 0, sizeof(s->tx_descriptor)); - - /* We also reset the PHY */ - imx_phy_reset(s); } static uint32_t imx_default_read(IMXFECState *s, uint32_t index) @@ -1329,6 +1206,13 @@ static void imx_eth_realize(DeviceState *dev, Error **errp) sysbus_init_irq(sbd, &s->irq[0]); sysbus_init_irq(sbd, &s->irq[1]); + qemu_init_irq(&s->mii_irq, imx_phy_update_irq, s, 0); + object_initialize_child(OBJECT(s), "mii", &s->mii, TYPE_LAN9118_PHY); + if (!sysbus_realize_and_unref(SYS_BUS_DEVICE(&s->mii), errp)) { + return; + } + qdev_connect_gpio_out(DEVICE(&s->mii), 0, &s->mii_irq); + qemu_macaddr_default_if_unset(&s->conf.macaddr); s->nic = qemu_new_nic(&imx_eth_net_info, &s->conf, diff --git a/hw/net/lan9118_phy.c b/hw/net/lan9118_phy.c index 5c2faaf00a..06e19c22c9 100644 --- a/hw/net/lan9118_phy.c +++ b/hw/net/lan9118_phy.c @@ -4,6 +4,8 @@ * Copyright (c) 2009 CodeSourcery, LLC. * Written by Paul Brook * + * Copyright (c) 2013 Jean-Christophe Dubois. + * * This code is licensed under the GNU GPL v2 * * Contributions after 2012-01-13 are licensed under the terms of the @@ -16,6 +18,7 @@ #include "hw/resettable.h" #include "migration/vmstate.h" #include "qemu/log.h" +#include "trace.h" #define PHY_INT_ENERGYON (1 << 7) #define PHY_INT_AUTONEG_COMPLETE (1 << 6) @@ -36,9 +39,11 @@ void lan9118_phy_update_link(Lan9118PhyState *s, bool link_down) /* Autonegotiation status mirrors link status. */ if (link_down) { + trace_lan9118_phy_update_link("down"); s->status &= ~0x0024; s->ints |= PHY_INT_DOWN; } else { + trace_lan9118_phy_update_link("up"); s->status |= 0x0024; s->ints |= PHY_INT_ENERGYON; s->ints |= PHY_INT_AUTONEG_COMPLETE; @@ -50,6 +55,8 @@ static void lan9118_phy_reset(Object *obj, ResetType type) { Lan9118PhyState *s = LAN9118_PHY(obj); + trace_lan9118_phy_reset(); + s->status = 0x7809; s->control = 0x3000; s->advertise = 0x01e1; @@ -64,59 +71,88 @@ uint32_t lan9118_phy_read(Lan9118PhyState *s, int reg) switch (reg) { case 0: /* Basic Control */ - return s->control; + val = s->control; + break; case 1: /* Basic Status */ - return s->status; + val = s->status; + break; case 2: /* ID1 */ - return 0x0007; + val = 0x0007; + break; case 3: /* ID2 */ - return 0xc0d1; + val = 0xc0d1; + break; case 4: /* Auto-neg advertisement */ - return s->advertise; + val = s->advertise; + break; case 5: /* Auto-neg Link Partner Ability */ - return 0x0f71; + val = 0x0f71; + break; case 6: /* Auto-neg Expansion */ - return 1; - /* TODO 17, 18, 27, 29, 30, 31 */ + val = 1; + break; case 29: /* Interrupt source. */ val = s->ints; s->ints = 0; lan9118_phy_update_irq(s); - return val; + break; case 30: /* Interrupt mask */ - return s->int_mask; + val = s->int_mask; + break; + case 17: + case 18: + case 27: + case 31: + qemu_log_mask(LOG_UNIMP, "%s: reg %d not implemented\n", + __func__, reg); + val = 0; + break; default: - qemu_log_mask(LOG_GUEST_ERROR, - "lan9118_phy_read: PHY read reg %d\n", reg); - return 0; + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset %d\n", + __func__, reg); + val = 0; + break; } + + trace_lan9118_phy_read(val, reg); + + return val; } void lan9118_phy_write(Lan9118PhyState *s, int reg, uint32_t val) { + trace_lan9118_phy_write(val, reg); + switch (reg) { case 0: /* Basic Control */ if (val & 0x8000) { lan9118_phy_reset(OBJECT(s), RESET_TYPE_SOFT); - break; - } - s->control = val & 0x7980; - /* Complete autonegotiation immediately. */ - if (val & 0x1000) { - s->status |= 0x0020; + } else { + s->control = val & 0x7980; + /* Complete autonegotiation immediately. */ + if (val & 0x1000) { + s->status |= 0x0020; + } } break; case 4: /* Auto-neg advertisement */ s->advertise = (val & 0x2d7f) | 0x80; break; - /* TODO 17, 18, 27, 31 */ case 30: /* Interrupt mask */ s->int_mask = val & 0xff; lan9118_phy_update_irq(s); break; + case 17: + case 18: + case 27: + case 31: + qemu_log_mask(LOG_UNIMP, "%s: reg %d not implemented\n", + __func__, reg); + break; default: - qemu_log_mask(LOG_GUEST_ERROR, - "lan9118_phy_write: PHY write reg %d = 0x%04x\n", reg, val); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad address at offset %d\n", + __func__, reg); + break; } } diff --git a/hw/net/Kconfig b/hw/net/Kconfig index 6b2ff2f937..7f80218d10 100644 --- a/hw/net/Kconfig +++ b/hw/net/Kconfig @@ -93,6 +93,7 @@ config ALLWINNER_SUN8I_EMAC config IMX_FEC bool + select LAN9118_PHY config CADENCE bool diff --git a/hw/net/trace-events b/hw/net/trace-events index 4c6687923e..b8e0076833 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -10,6 +10,12 @@ allwinner_sun8i_emac_set_link(bool active) "Set link: active=%u" allwinner_sun8i_emac_read(uint64_t offset, uint64_t val) "MMIO read: offset=0x%" PRIx64 " value=0x%" PRIx64 allwinner_sun8i_emac_write(uint64_t offset, uint64_t val) "MMIO write: offset=0x%" PRIx64 " value=0x%" PRIx64 +# lan9118_phy.c +lan9118_phy_read(uint32_t val, int reg) "[0x%02x] -> 0x%04" PRIx32 +lan9118_phy_write(uint32_t val, int reg) "[0x%02x] <- 0x%04" PRIx32 +lan9118_phy_update_link(const char *s) "%s" +lan9118_phy_reset(void) "" + # lance.c lance_mem_readw(uint64_t addr, uint32_t ret) "addr=0x%"PRIx64"val=0x%04x" lance_mem_writew(uint64_t addr, uint32_t val) "addr=0x%"PRIx64"val=0x%04x" @@ -426,12 +432,8 @@ i82596_set_multicast(uint16_t count) "Added %d multicast entries" i82596_channel_attention(void *s) "%p: Received CHANNEL ATTENTION" # imx_fec.c -imx_phy_read(uint32_t val, int phy, int reg) "0x%04"PRIx32" <= phy[%d].reg[%d]" imx_phy_read_num(int phy, int configured) "read request from unconfigured phy %d (configured %d)" -imx_phy_write(uint32_t val, int phy, int reg) "0x%04"PRIx32" => phy[%d].reg[%d]" imx_phy_write_num(int phy, int configured) "write request to unconfigured phy %d (configured %d)" -imx_phy_update_link(const char *s) "%s" -imx_phy_reset(void) "" imx_fec_read_bd(uint64_t addr, int flags, int len, int data) "tx_bd 0x%"PRIx64" flags 0x%04x len %d data 0x%08x" imx_enet_read_bd(uint64_t addr, int flags, int len, int data, int options, int status) "tx_bd 0x%"PRIx64" flags 0x%04x len %d data 0x%08x option 0x%04x status 0x%04x" imx_eth_tx_bd_busy(void) "tx_bd ran out of descriptors to transmit" From patchwork Wed Oct 16 21:24:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 13838968 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 6C5B5D2F7C5 for ; Wed, 16 Oct 2024 21:25:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1BVN-000293-Eg; Wed, 16 Oct 2024 17:24:29 -0400 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 1t1BVL-00028J-LI; Wed, 16 Oct 2024 17:24:27 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t1BVJ-00013U-WB; Wed, 16 Oct 2024 17:24:27 -0400 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a99cc265e0aso30576566b.3; Wed, 16 Oct 2024 14:24:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729113864; x=1729718664; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s3D1Ytcxm8HdYzUOAcr5hC/ohLTIwUIkdZ77sZiIviA=; b=DE48Xfwa+3rDm2Rcqy8ZJ9R036mZBf+V+ObGXG2XIzkMBeGIFXV4797nPOzofUAQwz gTIjzsMK4PF+1nqCum8D/hSmUMa3xLDKK1Ph1zCYFb9IFttb+Nt/KuqtkzpU3+1T5/An eGFbcBsWJOhVWaWj4fKlo0nCLMLZNbho0vre+E8wiPx5ygh91juNasxHvYi7Kan/WhcE 4PJFP5oUhO4UXsDgmQAvDtsTOkKHIvtnd2kV2gb7zyUc/ROyK7oJQGo+CBIh0uParW86 iOE3dHtgwZpf8H/J/5S8HUOn+PSYJkVenm4bIaGtlMUpmEzzwSdVy+gPqBdEvbOmunA3 bImA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729113864; x=1729718664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s3D1Ytcxm8HdYzUOAcr5hC/ohLTIwUIkdZ77sZiIviA=; b=PkePhFFsbQ87RsqkSxWsxSEGNzYfKS8URp03wgCp08lK0N3h5eyUk7cRc9LuSPdpCC uD0CoVQ0b736mJnyDHUmSsinakGlg3G/G72STawlYJ03MErcBkO/o5fYeYU0UMDUZzHd L+ZO865tQWR12M9yY9OLL4mVFB58DJNq3YG3R1K436fmy3liHR695O5lSsJgrFzubWk3 DYm9aT3v+AjvIlfMyAJ4spMIJY/2FcM+3kGPhC7KCgk9Aa/6y8tVbpZZ18vN9RoNW9Pe u7bOeVI43LqYDjDnMFXRc5WosH2Oy2irqIqkxGsNWzXCxVM2HKt5He3dMehdTkitzfNR 8Qnw== X-Forwarded-Encrypted: i=1; AJvYcCUAmCGOGtiXlYgVv1EoCkwTY6zpt1Nd2+fUW5S8eTbWgnaLUR+OQlDldrcRnDaN6CgQJsvlBwzMNA==@nongnu.org X-Gm-Message-State: AOJu0YyIS28VK8nB56LPW8zzN9vMD1SYJf+n6bAQ/8yxV8Jy8QL1cfDg ktdHyLX8s0aUgGtWiNe/B7/YBmnYSfdyXmIoeFB1JrB/+VjkqfmFtei3Fw== X-Google-Smtp-Source: AGHT+IGKd6OCOFOXu70RnPZ5BIRXoEUXsWNL/Z0Cu4hqm77oN25SshSthKtc+bRYb921VB0JzPTuBg== X-Received: by 2002:a17:907:e25f:b0:a99:529d:81ae with SMTP id a640c23a62f3a-a9a34e4c8e8mr398739366b.55.1729113863610; Wed, 16 Oct 2024 14:24:23 -0700 (PDT) Received: from archlinux.. (dynamic-077-191-025-143.77.191.pool.telefonica.de. [77.191.25.143]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29750a9asm218005766b.88.2024.10.16.14.24.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 14:24:22 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Jason Wang , qemu-arm@nongnu.org, Peter Maydell , Guenter Roeck , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 4/5] hw/net/lan9118_phy: Reuse MII constants Date: Wed, 16 Oct 2024 23:24:06 +0200 Message-ID: <20241016212407.139390-5-shentey@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241016212407.139390-1-shentey@gmail.com> References: <20241016212407.139390-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=shentey@gmail.com; helo=mail-ej1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 Prefer named constants over magic values for better readability. Reviewed-by: Peter Maydell Signed-off-by: Bernhard Beschow --- include/hw/net/mii.h | 6 +++++ hw/net/lan9118_phy.c | 59 +++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/include/hw/net/mii.h b/include/hw/net/mii.h index f7feddac9b..55bf7c92a1 100644 --- a/include/hw/net/mii.h +++ b/include/hw/net/mii.h @@ -71,6 +71,7 @@ #define MII_BMSR_JABBER (1 << 1) /* Jabber detected */ #define MII_BMSR_EXTCAP (1 << 0) /* Ext-reg capability */ +#define MII_ANAR_RFAULT (1 << 13) /* Say we can detect faults */ #define MII_ANAR_PAUSE_ASYM (1 << 11) /* Try for asymmetric pause */ #define MII_ANAR_PAUSE (1 << 10) /* Try for pause */ #define MII_ANAR_TXFD (1 << 8) @@ -78,6 +79,7 @@ #define MII_ANAR_10FD (1 << 6) #define MII_ANAR_10 (1 << 5) #define MII_ANAR_CSMACD (1 << 0) +#define MII_ANAR_SELECT (0x001f) /* Selector bits */ #define MII_ANLPAR_ACK (1 << 14) #define MII_ANLPAR_PAUSEASY (1 << 11) /* can pause asymmetrically */ @@ -112,6 +114,10 @@ #define RTL8201CP_PHYID1 0x0000 #define RTL8201CP_PHYID2 0x8201 +/* SMSC LAN9118 */ +#define SMSCLAN9118_PHYID1 0x0007 +#define SMSCLAN9118_PHYID2 0xc0d1 + /* RealTek 8211E */ #define RTL8211E_PHYID1 0x001c #define RTL8211E_PHYID2 0xc915 diff --git a/hw/net/lan9118_phy.c b/hw/net/lan9118_phy.c index 06e19c22c9..dafea5a875 100644 --- a/hw/net/lan9118_phy.c +++ b/hw/net/lan9118_phy.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "hw/net/lan9118_phy.h" +#include "hw/net/mii.h" #include "hw/irq.h" #include "hw/resettable.h" #include "migration/vmstate.h" @@ -40,11 +41,11 @@ void lan9118_phy_update_link(Lan9118PhyState *s, bool link_down) /* Autonegotiation status mirrors link status. */ if (link_down) { trace_lan9118_phy_update_link("down"); - s->status &= ~0x0024; + s->status &= ~(MII_BMSR_AN_COMP | MII_BMSR_LINK_ST); s->ints |= PHY_INT_DOWN; } else { trace_lan9118_phy_update_link("up"); - s->status |= 0x0024; + s->status |= MII_BMSR_AN_COMP | MII_BMSR_LINK_ST; s->ints |= PHY_INT_ENERGYON; s->ints |= PHY_INT_AUTONEG_COMPLETE; } @@ -57,9 +58,18 @@ static void lan9118_phy_reset(Object *obj, ResetType type) trace_lan9118_phy_reset(); - s->status = 0x7809; - s->control = 0x3000; - s->advertise = 0x01e1; + s->status = MII_BMSR_100TX_FD + | MII_BMSR_100TX_HD + | MII_BMSR_10T_FD + | MII_BMSR_10T_HD + | MII_BMSR_AUTONEG + | MII_BMSR_EXTCAP; + s->control = MII_BMCR_AUTOEN | MII_BMCR_SPEED100; + s->advertise = MII_ANAR_TXFD + | MII_ANAR_TX + | MII_ANAR_10FD + | MII_ANAR_10 + | MII_ANAR_CSMACD; s->int_mask = 0; s->ints = 0; lan9118_phy_update_link(s, s->link_down); @@ -70,26 +80,26 @@ uint32_t lan9118_phy_read(Lan9118PhyState *s, int reg) uint32_t val; switch (reg) { - case 0: /* Basic Control */ + case MII_BMCR: val = s->control; break; - case 1: /* Basic Status */ + case MII_BMSR: val = s->status; break; - case 2: /* ID1 */ - val = 0x0007; + case MII_PHYID1: + val = SMSCLAN9118_PHYID1; break; - case 3: /* ID2 */ - val = 0xc0d1; + case MII_PHYID2: + val = SMSCLAN9118_PHYID2; break; - case 4: /* Auto-neg advertisement */ + case MII_ANAR: val = s->advertise; break; - case 5: /* Auto-neg Link Partner Ability */ + case MII_ANLPAR: val = 0x0f71; break; - case 6: /* Auto-neg Expansion */ - val = 1; + case MII_ANER: + val = MII_ANER_NWAY; break; case 29: /* Interrupt source. */ val = s->ints; @@ -124,19 +134,24 @@ void lan9118_phy_write(Lan9118PhyState *s, int reg, uint32_t val) trace_lan9118_phy_write(val, reg); switch (reg) { - case 0: /* Basic Control */ - if (val & 0x8000) { + case MII_BMCR: + if (val & MII_BMCR_RESET) { lan9118_phy_reset(OBJECT(s), RESET_TYPE_SOFT); } else { - s->control = val & 0x7980; + s->control = val & (MII_BMCR_LOOPBACK | MII_BMCR_SPEED100 | + MII_BMCR_AUTOEN | MII_BMCR_PDOWN | MII_BMCR_FD | + MII_BMCR_CTST); /* Complete autonegotiation immediately. */ - if (val & 0x1000) { - s->status |= 0x0020; + if (val & MII_BMCR_AUTOEN) { + s->status |= MII_BMSR_AN_COMP; } } break; - case 4: /* Auto-neg advertisement */ - s->advertise = (val & 0x2d7f) | 0x80; + case MII_ANAR: + s->advertise = (val & (MII_ANAR_RFAULT | MII_ANAR_PAUSE_ASYM | + MII_ANAR_PAUSE | MII_ANAR_10FD | MII_ANAR_10 | + MII_ANAR_SELECT)) + | MII_ANAR_TX; break; case 30: /* Interrupt mask */ s->int_mask = val & 0xff; From patchwork Wed Oct 16 21:24:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernhard Beschow X-Patchwork-Id: 13838966 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 74B13D2F7C5 for ; Wed, 16 Oct 2024 21:25:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t1BVO-0002A2-FK; Wed, 16 Oct 2024 17:24:30 -0400 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 1t1BVM-00028s-RO; Wed, 16 Oct 2024 17:24:29 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t1BVL-00013p-DX; Wed, 16 Oct 2024 17:24:28 -0400 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c97c7852e8so440035a12.1; Wed, 16 Oct 2024 14:24:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729113865; x=1729718665; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tnMQo+rYjxc+6D6y/U+RZNjtUqKrnuqcrTxxP6UZ8ck=; b=ZpxUk89teF9wDoztiihljPps6VmsgFvy7z+erGmcwhX05MutdYtqnB8fhPiCdmL81w L8E6g6f+GzZFVoYM0zaNA28rliEr4eA9KHywn9MGiMLzJxYm3ja+JFe8pmhUIUI+NnMw s2yqtnH6IbydNjFJuSRmS7n4AMIXk4E+vt+psRSrYWmWtLYtH7u8l7ikuzl5vDAwb2Aw /Nj7MkJbSAreFT34/OkXeocfu8mzfk4d2NW1/pjwObkBMpjP3N2+3qDX24C+u8u1XFFy qdTdMPEKnKp+YWSyfGBW/0HK53bFCaG7brTK6JNBZ/9MtXIR7YF/ZC0UNmnWW1Zewqbo p0oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729113865; x=1729718665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tnMQo+rYjxc+6D6y/U+RZNjtUqKrnuqcrTxxP6UZ8ck=; b=D20dCSOvdRT46BQMdsj3UktQEcAvpOsMZ0RHlHO6Q10qLS9EN4JkJLf3SrigaKuQgv 5YNBQT9ZwyBxQDlHgh9tQEcrZnKW0Ia1qNXHp76ghaMeX6tkrTadxwAnbjkR+9uTlK7V 7I9UYtaELDurrGoBdEI600N4COBwxis71K1fwqwdTPqFzW7r0QdrQS6/kXL8zrvb31ea c7tnxER++xpt/C27UtxuVBUOE8vLmE8+OM75roGioP9TyzXkr9hdBzSAbZxDQaDZmH3T LHXfz+DpK/u+KfOL68YyMPiGY6yQVWn1EwwuB0YrXqosSMRVW+8lBZ5YOt/rC7uXq7+i IBEw== X-Forwarded-Encrypted: i=1; AJvYcCWHLP65N+DImbuC4luu267AAhh/SzPVDtJwrhcfCqTRIe9srghaqoWhDcdFburPJs2vSQT4l4stwA==@nongnu.org X-Gm-Message-State: AOJu0YwVrLV49BuxN3NTW0T1XGaKoEOmpZWRvfJVVFK6ltMUhiWD+Adz iH1qBJe/7viO6bTOqBqo/GtXIqq8PVi6GsroE4x0w53HGvk2fERcy1DHLw== X-Google-Smtp-Source: AGHT+IGEUaaGIUiqW7xl40Z73HDRtN8tEhjFaNzCNNHwbhZm240LyXu9+rlMFOboLs1e05fAH5+OyA== X-Received: by 2002:a17:907:7f12:b0:a99:f945:8776 with SMTP id a640c23a62f3a-a99f94588c4mr1369022166b.24.1729113864966; Wed, 16 Oct 2024 14:24:24 -0700 (PDT) Received: from archlinux.. (dynamic-077-191-025-143.77.191.pool.telefonica.de. [77.191.25.143]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29750a9asm218005766b.88.2024.10.16.14.24.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2024 14:24:24 -0700 (PDT) From: Bernhard Beschow To: qemu-devel@nongnu.org Cc: Jason Wang , qemu-arm@nongnu.org, Peter Maydell , Guenter Roeck , Paolo Bonzini , Bernhard Beschow Subject: [PATCH v2 5/5] hw/net/lan9118_phy: Add missing 100 mbps full duplex advertisement Date: Wed, 16 Oct 2024 23:24:07 +0200 Message-ID: <20241016212407.139390-6-shentey@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241016212407.139390-1-shentey@gmail.com> References: <20241016212407.139390-1-shentey@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=shentey@gmail.com; helo=mail-ed1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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 The real device advertises this mode and the device model already advertises 100 mbps half duplex and 10 mbps full+half duplex. So advertise this mode to make the model more realistic. Reviewed-by: Peter Maydell Signed-off-by: Bernhard Beschow --- hw/net/lan9118_phy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/net/lan9118_phy.c b/hw/net/lan9118_phy.c index dafea5a875..5f9737556f 100644 --- a/hw/net/lan9118_phy.c +++ b/hw/net/lan9118_phy.c @@ -149,8 +149,8 @@ void lan9118_phy_write(Lan9118PhyState *s, int reg, uint32_t val) break; case MII_ANAR: s->advertise = (val & (MII_ANAR_RFAULT | MII_ANAR_PAUSE_ASYM | - MII_ANAR_PAUSE | MII_ANAR_10FD | MII_ANAR_10 | - MII_ANAR_SELECT)) + MII_ANAR_PAUSE | MII_ANAR_TXFD | MII_ANAR_10FD | + MII_ANAR_10 | MII_ANAR_SELECT)) | MII_ANAR_TX; break; case 30: /* Interrupt mask */