From nobody Wed Nov 27 04:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701650124; cv=none; d=zohomail.com; s=zohoarc; b=KYhrVFsEr504OHW3Nv7xuJPKHnJvwymj2EGdhJOMBNDfRkW37xy9sLN5WMj4EoMVpvzlNWF3FuDIyewAEO8Q9VXR5PVcqzu/SwElp2GffCOQGNbhbEL0rEKBKnotrCfpvKbsKwZzfhC2/ZymAXYfgo88eFlW4EufwKdpTowtb8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701650124; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=v0plx2CSfyD/hqodRTCcCQxsf1hkYu3FpLFu5vV8rvY=; b=Giq3/5zdYsRkld+qTDGdi0DrIUt8ZIM3CQaVd5oZopdfh10Wh4PK0u1Ymac8bUrRi8wMdkRBF79xeVJFCxhc0+ZEARFgNm+LGMKyO9Apgi8OopTRAzILWLg4nLBt/y+spEe603XOoOwS1o5jZO6PXAjaH38E1/WOoqj21zrT6b8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701650124229715.7580173436396; Sun, 3 Dec 2023 16:35:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9woO-0006fe-BT; Sun, 03 Dec 2023 19:27:48 -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 1r9wnj-0004gu-Ny; Sun, 03 Dec 2023 19:27:09 -0500 Received: from mail-yw1-x1130.google.com ([2607:f8b0:4864:20::1130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9wnh-0000Ec-HJ; Sun, 03 Dec 2023 19:27:07 -0500 Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-5cd81e76164so43078507b3.1; Sun, 03 Dec 2023 16:27:01 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id l63-20020a0de242000000b005d3e6ce07e7sm2443187ywe.6.2023.12.03.16.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 16:27:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701649621; x=1702254421; 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=v0plx2CSfyD/hqodRTCcCQxsf1hkYu3FpLFu5vV8rvY=; b=Sva123iC6YQ5S2bK88tAy+v0w8ul8jcyqUjPYm3I98WHhihCdWq82JS6SvnsEcSKbD G+0qqBKX5JWJG4jg38GdFX6GHwECtxrn8lpuoEdtR/jvvLL8wu3XO0bUsEMkzUxn8x9d 5NHogBE68xvSwYKZjeXzJrFIlIv/vhFYOjLyo+yNOAcvRFmJBJzgh5T0zgeQOP4NEAkJ kkl7lmfhh6VAx6sBsRo4CrJkIzVIuH2jP0xV/VkiKaTAZdMBvfWs3nTimjbvk98LcETf oLT07Hh/PHoREmWPqIl2FTLUbWaeS7c9Fpf0Amd1ss++qLJlVuhLCrXqlwUzRfxYKpPb WXtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701649621; x=1702254421; 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=v0plx2CSfyD/hqodRTCcCQxsf1hkYu3FpLFu5vV8rvY=; b=oSmZymjgOMq7IE8SmyXH5li2dTHRiyR9zvA7UqElGc+nGBK4gN3YUzsRu7/uL/SSrm HL7onxLo/HrfYWR6wa/KABR9kHNv8XxDVUOl3GKh7KN0SnT4kDzeRpx+jlR1j2EMksm/ WHW4y5Kh5Yeb3D85LE8iNqCnnlNm4qZ4xzDjFWQ1vW3OGQ/z0yjHj/yq/NUs7k/aPjFY QffNAA98nuEusImDiZQAgGKLQ3TfSWpcoCNXUACcGfp07etjT/psozqg/Km11dm3Dvsh LYcoNx67yTlIxVj7PS5NJ8u0Hy9ABX6TJZ3b53CirGFihbptECH0RKizxvgGnVLyBAEe rWQw== X-Gm-Message-State: AOJu0Yxi5W08WgA6fiHw8fVt9ttskkKKriFlTvC+yiwmc6Db6hBU80pS zT7rlxNWKVPVFF46nDGC0uyZwgbhXET6lQ== X-Google-Smtp-Source: AGHT+IGuKr4jdjdnw3J9Ddgoa0/Dr3zrKNNlWkysrbFEVVOLL5Qm+wy68O4FviEXr3Jby2CgHkz0cA== X-Received: by 2002:a81:5753:0:b0:5d4:195e:31db with SMTP id l80-20020a815753000000b005d4195e31dbmr2052172ywb.2.1701649621131; Sun, 03 Dec 2023 16:27:01 -0800 (PST) From: Sergey Kambalin X-Google-Original-From: Sergey Kambalin To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, Sergey Kambalin Subject: [PATCH v3 29/45] Implement GENET MDIO Date: Sun, 3 Dec 2023 18:26:03 -0600 Message-Id: <20231204002619.1367044-30-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204002619.1367044-1-sergey.kambalin@auriga.com> References: <20231204002619.1367044-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1130; envelope-from=serg.oker@gmail.com; helo=mail-yw1-x1130.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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1701651027083100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Sergey Kambalin --- hw/net/bcm2838_genet.c | 126 ++++++++++++++++++++++++++++++++- include/hw/net/bcm2838_genet.h | 3 +- 2 files changed, 126 insertions(+), 3 deletions(-) diff --git a/hw/net/bcm2838_genet.c b/hw/net/bcm2838_genet.c index 56ff6a6f39..1fae3ecbc2 100644 --- a/hw/net/bcm2838_genet.c +++ b/hw/net/bcm2838_genet.c @@ -213,6 +213,7 @@ FIELD(GENET_PHY_STAT_1000, LOCALRXOK, 13, 1) FIELD(GENET_PHY_STAT_1000, MSRES, 14, 1) FIELD(GENET_PHY_STAT_1000, MSFAIL, 15, 1) =20 +/* There are two data representations for PHY_AUX_CTRL register */ REG16(GENET_PHY_AUX_CTRL_0, 0) FIELD(GENET_PHY_AUX_CTRL_0, REG_ID_MASK, 0, 3) FIELD(GENET_PHY_AUX_CTRL_0, RSVD_3, 3, 1) @@ -269,6 +270,123 @@ static void bcm2838_genet_set_irq_prio(BCM2838GenetSt= ate *s) qemu_set_irq(s->irq_prio, level); } =20 +static void bcm2838_genet_phy_aux_ctl_write(BCM2838GenetState *s, + uint16_t value) +{ + uint16_t reg_id =3D FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, REG_ID); + uint16_t reg_id_mask =3D FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, REG_I= D_MASK); + uint16_t misc_wren =3D FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, MISC_WR= EN); + uint16_t reg_data =3D FIELD_EX16(value, GENET_PHY_AUX_CTRL_0, REG_DATA= ); + uint16_t reg_data12 =3D FIELD_EX16(value, GENET_PHY_AUX_CTRL_1, REG_DA= TA); + + uint16_t *phy_aux_ctl_shd_reg_id =3D (uint16_t *)&s->phy_aux_ctl_shd_r= egs + reg_id; + uint16_t *phy_aux_ctl_shd_reg_id_mask =3D (uint16_t *)&s->phy_aux_ctl_= shd_regs + reg_id_mask; + + if (reg_id_mask =3D=3D BCM2838_GENET_PHY_AUX_CTL_MISC) { + if (reg_id =3D=3D BCM2838_GENET_PHY_AUX_CTL_MISC) { + if (misc_wren =3D=3D 0) { + /* write for subsequent read (8-bit from AUX_CTL_MISC) */ + FIELD_DP16(value, GENET_PHY_AUX_CTRL_0, REG_DATA, *phy_aux= _ctl_shd_reg_id); + } else { + /* write 8 bits to AUX_CTL_MISC */ + *phy_aux_ctl_shd_reg_id_mask =3D reg_data; + } + } else { + /* write for subsequent read (12-bit) */ + FIELD_DP16(value, GENET_PHY_AUX_CTRL_1, REG_DATA, *phy_aux_ctl= _shd_reg_id); + } + } else { + /* write 12 bits */ + *phy_aux_ctl_shd_reg_id_mask =3D reg_data12; + } + + s->phy_regs.aux_ctl =3D value; +} + +static void bcm2838_genet_phy_shadow_write(BCM2838GenetState *s, + uint16_t value) +{ + uint16_t reg_id =3D FIELD_EX16(value, GENET_PHY_SHADOW, REG_ID); + uint16_t wr =3D FIELD_EX16(value, GENET_PHY_SHADOW, WR); + uint16_t reg_data =3D FIELD_EX16(value, GENET_PHY_SHADOW, REG_DATA); + + uint16_t *phy_shd_reg =3D (uint16_t *)&s->phy_shd_regs + reg_id; + + if (wr =3D=3D 0) { + FIELD_DP16(value, GENET_PHY_SHADOW, REG_DATA, *phy_shd_reg); + } else { + *phy_shd_reg =3D reg_data; + } + + s->phy_regs.shd =3D value; +} + +static void bcm2838_genet_phy_exp_shadow_write(BCM2838GenetState *s, + uint16_t value) +{ + /* TODO Stub implementation without side effect, + just storing registers values */ + uint16_t reg_id =3D FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, REG_ID); + uint16_t block_id =3D FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, BLOCK_ID); + + s->phy_exp_shd_regs.regs[block_id][reg_id] =3D value; +} + +static uint16_t bcm2838_genet_phy_exp_shadow_read(BCM2838GenetState *s) +{ + uint16_t reg_id =3D FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, REG_ID); + uint16_t block_id =3D FIELD_EX16(s->phy_regs.exp_ctrl, + GENET_PHY_EXP_SEL, BLOCK_ID); + + return s->phy_exp_shd_regs.regs[block_id][reg_id]; +} + +static uint64_t bcm2838_genet_mdio_cmd(BCM2838GenetState *s, uint64_t cmd) +{ + uint32_t phy_reg_id =3D FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, REG_ID); + uint32_t phy_reg_data =3D FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, REG_DAT= A); + uint32_t start_busy =3D FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, START_BUS= Y); + uint32_t rd =3D FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, RD); + uint32_t wr =3D FIELD_EX32(cmd, GENET_UMAC_MDIO_CMD, WR); + uint16_t *phy_reg =3D (uint16_t *)&s->phy_regs + phy_reg_id; + + uint16_t anrestart =3D FIELD_EX16(phy_reg_data, GENET_PHY_BMCR, ANREST= ART); + + if (start_busy !=3D 0) { + cmd =3D FIELD_DP32(cmd, GENET_UMAC_MDIO_CMD, START_BUSY, 0); + + if (rd !=3D 0) { + if (phy_reg_id =3D=3D BCM2838_GENET_EXP_DATA) { + cmd =3D FIELD_DP32(cmd, GENET_UMAC_MDIO_CMD, REG_DATA, + bcm2838_genet_phy_exp_shadow_read(s)); + } else { + cmd =3D FIELD_DP32(cmd, GENET_UMAC_MDIO_CMD, REG_DATA, *ph= y_reg); + } + } else if (wr !=3D 0) { + if (phy_reg_id =3D=3D BCM2838_GENET_PHY_AUX_CTL) { + bcm2838_genet_phy_aux_ctl_write(s, phy_reg_data); + } else if (phy_reg_id =3D=3D BCM2838_GENET_PHY_SHD) { + bcm2838_genet_phy_shadow_write(s, phy_reg_data); + } else if (phy_reg_id =3D=3D BCM2838_GENET_EXP_DATA) { + bcm2838_genet_phy_exp_shadow_write(s, phy_reg_data); + } else { + if (phy_reg_id =3D=3D BCM2838_GENET_PHY_BMCR) { + /* Initiate auto-negotiation once it has been restarte= d */ + if (anrestart =3D=3D 1) { + FIELD_DP16(phy_reg_data, GENET_PHY_BMCR, ANRESTART= , 0); + } + } + *phy_reg =3D phy_reg_data; + } + } + } + + return cmd; +} + static uint64_t bcm2838_genet_read(void *opaque, hwaddr offset, unsigned s= ize) { uint64_t value =3D ~0; @@ -353,10 +471,13 @@ static void bcm2838_genet_write(void *opaque, hwaddr = offset, uint64_t value, trace_bcm2838_genet_mac_address(ncs->info_str); break; case BCM2838_GENET_UMAC_MDIO_CMD: + value =3D bcm2838_genet_mdio_cmd(s, value); + s->regs.intrl0.stat =3D FIELD_DP32(s->regs.intrl0.stat, + GENET_INTRL_0, MDIO_DONE, 1); + break; case BCM2838_GENET_TDMA_REGS ... BCM2838_GENET_TDMA_REGS + sizeof(BCM2838GenetRegsTdma) - 1: - qemu_log_mask(LOG_UNIMP, - "UMAC MDIO and TDMA aren't implemented yet"); + qemu_log_mask(LOG_UNIMP, "TDMA isn't implemented yet"); break; default: break; @@ -452,6 +573,7 @@ static void bcm2838_genet_reset(DeviceState *d) =20 trace_bcm2838_genet_reset("done"); =20 + bcm2838_genet_set_qemu_mac(s); bcm2838_genet_phy_reset(s); } =20 diff --git a/include/hw/net/bcm2838_genet.h b/include/hw/net/bcm2838_genet.h index b9d6d35cce..7a483bd265 100644 --- a/include/hw/net/bcm2838_genet.h +++ b/include/hw/net/bcm2838_genet.h @@ -101,7 +101,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(BCM2838GenetState, BCM2838_G= ENET) #define BCM2838_GENET_EXP_DATA BCM2838_GENET_PHY_REG(exp_data) #define BCM2838_GENET_EXP_SEL BCM2838_GENET_PHY_REG(exp_ctrl) =20 -#define BCM2838_GENET_PHY_AUX_CTL_MISC 0x7 +#define BCM2838_GENET_PHY_AUX_CTL_AUXCTL 0x0 +#define BCM2838_GENET_PHY_AUX_CTL_MISC 0x7 #define BCM2838_GENET_PHY_AUX_CTL_REGS_SIZE 8 =20 #define BCM2838_GENET_PHY_EXP_SHD_BLOCKS_CNT 256 --=20 2.34.1