Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [78.32.30.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E15019D092 for ; Fri, 24 Oct 2025 12:49:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.32.30.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761310165; cv=none; b=KUVGa6FCqOiEmuPPJEWlZLyMbGOmUHk4ZvEdTrjdxB1fbqKLumfA9SGORtjswJ6L1zstDHLDu/mkwF7uXYmKS50BCynH7U3Y0u9O8KdhLvghNmw1DNdLnW9i/I1t96ZqduGls83qaRIHuCUY8BGkqTs9e0g597+X3kHcDSrnR08= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761310165; c=relaxed/simple; bh=66UXQVFOmH4MOQb3XZ8yAhi6VHMGL5v1SN8si/PTLjY=; h=In-Reply-To:References:From:To:Cc:Subject:MIME-Version: Content-Disposition:Content-Type:Message-Id:Date; b=U1xhAuCJ3psJ8Gf5dG/rna1P4e+6AmwOXPdKrcL4yMIKrxbA74gle3SKYXd1bEV51SogvUI3aI9Jct13PNc/tOzK6Yuv8n/igTbeKRMBwgQx/dhZZ6UXnyncDqi9dgyKCR3DLLum3Nj4rVnfVqUSnRceRbFt+I0fyawAzgPmtkc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk; spf=none smtp.mailfrom=armlinux.org.uk; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b=oHMgLBVr; arc=none smtp.client-ip=78.32.30.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=armlinux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=armlinux.org.uk header.i=@armlinux.org.uk header.b="oHMgLBVr" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Date:Sender:Message-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References: In-Reply-To:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LSUmh1jpI9zBrymiusXEbO1vxH7E1qauVBHlErgl6Kw=; b=oHMgLBVrg5KBb2fU69311Vqy0l w+HeOIWpqQ7I17VsKLY6Xv7aJSZzRXxebS7Ln5YV5QrtIyDGbE2bgBx4/9sIFrFUfO5Mg1T4BKKux m5ve0ouUDp0hHM4M3ofHmkNUvV4S5Z5SsmsgaRv7XzUVtgmzlimGJp9/bWn7h+PqsMb8za2yrTxHU G0KSeRyte6gorOOjteyNhYTudj8wBfmsdaTEABA+jMsGDTlWTr/l+4a/ZzNAuBBLUxa7iISXGjd5s graFyTF4Ezchy1PkF8EnM3fosGL9FZJBDafT6UFemUqTI4jT+r0y6QolV09qzjzQMnRHn4Kk+kzmv DTUfgVcw==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:51300 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vCHEK-000000007aF-14PD; Fri, 24 Oct 2025 13:49:16 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1vCHEJ-0000000BPTs-1fkA; Fri, 24 Oct 2025 13:49:15 +0100 In-Reply-To: References: From: "Russell King (Oracle)" To: Andrew Lunn , Heiner Kallweit Cc: Alexandre Torgue , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, Maxime Coquelin , netdev@vger.kernel.org, Paolo Abeni , Richard Cochran Subject: [PATCH net-next v2 3/8] net: stmmac: consolidate version reading and validation Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Message-Id: Sender: Russell King Date: Fri, 24 Oct 2025 13:49:15 +0100 There is no need to read the version register twice, once in stmmac_get_id() and then again in stmmac_get_dev_id(). Consolidate this into stmmac_get_version() and pass each of these this value. As both functions unnecessarily issue the same warning for a zero register value, also move this into stmmac_get_version(). Reviewed-by: Andrew Lunn Tested-by: Maxime Chevallier Signed-off-by: Russell King (Oracle) --- drivers/net/ethernet/stmicro/stmmac/hwif.c | 29 ++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c b/drivers/net/ethernet/stmicro/stmmac/hwif.c index 6b001d3f57c6..699c94acfeff 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -18,30 +18,16 @@ struct stmmac_version { u8 dev_id; }; -static u32 stmmac_get_id(struct stmmac_priv *priv, u32 id_reg) +static u32 stmmac_get_id(struct stmmac_priv *priv, u32 reg) { - u32 reg = readl(priv->ioaddr + id_reg); - - if (!reg) { - dev_info(priv->device, "Version ID not available\n"); - return 0x0; - } - dev_info(priv->device, "User ID: 0x%x, Synopsys ID: 0x%x\n", (unsigned int)(reg & GENMASK(15, 8)) >> 8, (unsigned int)(reg & GENMASK(7, 0))); return reg & GENMASK(7, 0); } -static u32 stmmac_get_dev_id(struct stmmac_priv *priv, u32 id_reg) +static u32 stmmac_get_dev_id(struct stmmac_priv *priv, u32 reg) { - u32 reg = readl(priv->ioaddr + id_reg); - - if (!reg) { - dev_info(priv->device, "Version ID not available\n"); - return 0x0; - } - return (reg & GENMASK(15, 8)) >> 8; } @@ -50,6 +36,7 @@ static void stmmac_get_version(struct stmmac_priv *priv, { enum dwmac_core_type core_type = priv->plat->core_type; unsigned int version_offset; + u32 version; ver->snpsver = 0; ver->dev_id = 0; @@ -62,9 +49,15 @@ static void stmmac_get_version(struct stmmac_priv *priv, else version_offset = GMAC4_VERSION; - ver->snpsver = stmmac_get_id(priv, version_offset); + version = readl(priv->ioaddr + version_offset); + if (version == 0) { + dev_info(priv->device, "Version ID not available\n"); + return; + } + + ver->snpsver = stmmac_get_id(priv, version); if (core_type == DWMAC_CORE_XGMAC) - ver->dev_id = stmmac_get_dev_id(priv, version_offset); + ver->dev_id = stmmac_get_dev_id(priv, version); } static void stmmac_dwmac_mode_quirk(struct stmmac_priv *priv) -- 2.47.3