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 F2EB3F9E8 for ; Wed, 29 Oct 2025 00:03:18 +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=1761696200; cv=none; b=c3FiVaAhRnrbVjMWnSrtEobcCt/7b/9AeTVWoC0pv+uaxx/Ocs8HUEKKTnFd2Rg+THDlQBfOXKEKCZC3H4D9INSOQn0UAhR5US1OU72MgSB1DcTevC9XWH7/bhlHVh1a8wtBwsVwfQ+YYC1pONRDfVhYGzEMRgzt374apuF9dc4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761696200; c=relaxed/simple; bh=L0y0alVDFNsgs62QDtcLzPgLEMFj6mFRZUSAEpkbEIY=; h=In-Reply-To:References:From:To:Cc:Subject:MIME-Version: Content-Disposition:Content-Type:Message-Id:Date; b=jJ4c45Nk4uQwjYgMMyrme0SlivIDcLpz8lvvIvpYyzq4CfpJQQ+ntDXyxsNx8ygzZsQYIjJcYd4hB4QiuKBowpUVFy9vtORRbYGwLXem/WlfHxator8mcUy95b+zHf4fgi/43C38dEpTPnw+aJrrnnoII8kCCcdbDLP9hi7E4GU= 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=Hsq6QadR; 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="Hsq6QadR" 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=l04AWp8VlL6VNXvTGxfhs7KxruzEM9sIHa9ZCvAn6Nk=; b=Hsq6QadRq9X+xAgbre4vH0GPxi b5u8mIbcMUM5DEgRHU9EsRyfPaKCh7LjWR92zFLrh2yLnYOUVuI2n+ZEHyBZSzNsaCsPLe9EohFgd zKgUvkaP/wHAJ2eNv0mjFXc1Di6icA/fXWTBV4sHm79AHA4gOkauWhhIIBnmx8ObupfCYvciAbxLz 6/lznSBxn++d4vSqqf5sXhPl1eSaxmLGhdTmjTqo3+ZVGijB7g+OOzrdRENpxeCFktjmoFkfXC7oL eIRQ11cuCqs+v180Xw0dASCAIAuCL8C1l1vcpf0FIa4Kn19HXWVkkzZyfvyJc4vNubR9AxNkpj8De hdp5A68g==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:54968 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 1vDteh-000000003gW-1yNW; Wed, 29 Oct 2025 00:03:11 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1vDteg-0000000CCBr-2m7q; Wed, 29 Oct 2025 00:03:10 +0000 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 v3 1/8] net: stmmac: move version handling into own function 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: Wed, 29 Oct 2025 00:03:10 +0000 Move the version handling out of stmmac_hwif_init() and into its own function, returning the version information through a structure. Reviewed-by: Andrew Lunn Tested-by: Maxime Chevallier Tested-by: Mohd Ayaan Anwar Signed-off-by: Russell King (Oracle) --- drivers/net/ethernet/stmicro/stmmac/hwif.c | 42 +++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c b/drivers/net/ethernet/stmicro/stmmac/hwif.c index 41a7e1841227..4924e74997e4 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -13,6 +13,11 @@ #include "dwmac4_descs.h" #include "dwxgmac2.h" +struct stmmac_version { + u8 snpsver; + u8 dev_id; +}; + static u32 stmmac_get_id(struct stmmac_priv *priv, u32 id_reg) { u32 reg = readl(priv->ioaddr + id_reg); @@ -40,6 +45,24 @@ static u32 stmmac_get_dev_id(struct stmmac_priv *priv, u32 id_reg) return (reg & GENMASK(15, 8)) >> 8; } +static void stmmac_get_version(struct stmmac_priv *priv, + struct stmmac_version *ver) +{ + enum dwmac_core_type core_type = priv->plat->core_type; + + ver->dev_id = 0; + + if (core_type == DWMAC_CORE_GMAC) { + ver->snpsver = stmmac_get_id(priv, GMAC_VERSION); + } else if (dwmac_is_xmac(core_type)) { + ver->snpsver = stmmac_get_id(priv, GMAC4_VERSION); + if (core_type == DWMAC_CORE_XGMAC) + ver->dev_id = stmmac_get_dev_id(priv, GMAC4_VERSION); + } else { + ver->snpsver = 0; + } +} + static void stmmac_dwmac_mode_quirk(struct stmmac_priv *priv) { struct mac_device_info *mac = priv->hw; @@ -292,23 +315,15 @@ int stmmac_hwif_init(struct stmmac_priv *priv) { enum dwmac_core_type core_type = priv->plat->core_type; const struct stmmac_hwif_entry *entry; + struct stmmac_version version; struct mac_device_info *mac; bool needs_setup = true; - u32 id, dev_id = 0; int i, ret; - if (core_type == DWMAC_CORE_GMAC) { - id = stmmac_get_id(priv, GMAC_VERSION); - } else if (dwmac_is_xmac(core_type)) { - id = stmmac_get_id(priv, GMAC4_VERSION); - if (core_type == DWMAC_CORE_XGMAC) - dev_id = stmmac_get_dev_id(priv, GMAC4_VERSION); - } else { - id = 0; - } + stmmac_get_version(priv, &version); /* Save ID for later use */ - priv->synopsys_id = id; + priv->synopsys_id = version.snpsver; /* Lets assume some safe values first */ if (core_type == DWMAC_CORE_GMAC4) { @@ -344,7 +359,8 @@ int stmmac_hwif_init(struct stmmac_priv *priv) /* Use synopsys_id var because some setups can override this */ if (priv->synopsys_id < entry->min_id) continue; - if (core_type == DWMAC_CORE_XGMAC && (dev_id ^ entry->dev_id)) + if (core_type == DWMAC_CORE_XGMAC && + (version.dev_id ^ entry->dev_id)) continue; /* Only use generic HW helpers if needed */ @@ -380,7 +396,7 @@ int stmmac_hwif_init(struct stmmac_priv *priv) } dev_err(priv->device, "Failed to find HW IF (id=0x%x, gmac=%d/%d)\n", - id, core_type == DWMAC_CORE_GMAC, + version.snpsver, core_type == DWMAC_CORE_GMAC, core_type == DWMAC_CORE_GMAC4); return -EINVAL; } -- 2.47.3