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 9AEE818E20 for ; Fri, 24 Oct 2025 12:49:12 +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=1761310154; cv=none; b=tqaai94zf0PxTynimv4VnwTXsIkz/aFAprupB/Zi9Y4z5uzGJyvygbzRnpBaWx4vnvkIqnjCZjv5YHqPiZ97iakA1g3/n5EheuZROPFTlZKgIkpixw6xuaXWGFeZjkAKFNXZiTA577XjADdT0imL60tRcaNmHia6DGPVKBWYRPo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761310154; c=relaxed/simple; bh=/2MMBRLdB3gkuv+SLL1IleBBRlFOR4IcSXHOUC5OmjA=; h=In-Reply-To:References:From:To:Cc:Subject:MIME-Version: Content-Disposition:Content-Type:Message-Id:Date; b=AjnSRJuT4A9yvf7ZaXYmv8JyfRSfwVcdK4U3ViZeKKH8jluMRETeLUlvi2ocrcv9x/qAlbmPWpY/cp+kfkpVZUW8Af3xTf48UrnARVkxw7VLoHKSdmLlhV+YBAqHwPKPFS/IutZqIsHYKLqGDW4A2S6yfuu0/tGIqwc864WsnVw= 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=XPXWl1gf; 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="XPXWl1gf" 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=sDbLc9KE3adeNWD5XjWtz5cZLPV8xFkcGEgD8CnOEFg=; b=XPXWl1gfluFYY1D5DoSGkX5ZoM drYKpMr0/l9dAskhKQp9mg+mgdGFhvi/NUc5y1qTHh/fFmhcv3NtDxpFT0ky0jBV1lTnDOIy8KhgT YIfHZFF/BwCaJ6Kih3xQDl7lASp4oipVG52Lc63aJwVH4ijpvZiDI5VkyxFFeqejMFkoHSURhdXir sqVtQ5KI5BrmMyppXk/ce6yA8DeQZBgZ7iz4l2JAL3pFo+rm9CE+ouLfUCpVnJbeiZK7rCcnAB3y0 7JscUJ6GwpRxGaNtLKMTbYHBrNelnOFyvjMoYGPSBgVYgBfcYOkXATc6GUALXA+YYXOvFwiesZ8TD jVMsUR6Q==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:59462 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 1vCHE9-000000007Zl-3m6Y; Fri, 24 Oct 2025 13:49:05 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1vCHE9-0000000BPTg-0jdL; Fri, 24 Oct 2025 13:49:05 +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 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: Fri, 24 Oct 2025 13:49:05 +0100 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 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 00083ce52549..44e34b6ab90a 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) { @@ -342,7 +357,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 */ @@ -378,7 +394,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