From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 4AF43F30931 for ; Thu, 5 Mar 2026 10:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Date: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-Owner; bh=ZgLn5gKTC6ltjP22vENPvguQQAUnJs1iU1xrD1qgNa0=; b=R0fTK/+lBCgHjYesmqCTvvkUiX 38E1+dhUk2RvyLWAvamXsMzddC5rjlZO509lumix2Ig0H3CpQM0g2t4/9Yyn+DJZ2lszghXrXt/xx 7Zl+xaqx8lHt+kket1BSYEA8FRcuXm5WjSD9W2geSdpZO9ELOLMETfxjZdGi6uMjfixrKW45bF28z GLkOtwsmi23McKps0fgqRxOihkNDFB+k9zsv9PbiNrItLtkRSqwuDhFM4xgdjBlgB6XnfuxINdSoX OwC1wEt7zwJAml8J1e67gPLnjmGzQJq8VAT0NDVa/36ons+h64dzK70RHAW7DJkGiMzUZJzJ3h6qL fPePEljw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vy6AO-00000001bSw-3zZ4; Thu, 05 Mar 2026 10:42:52 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:32c8:5054:ff:fe00:142]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vy6AM-00000001bQZ-2oYp for linux-arm-kernel@lists.infradead.org; Thu, 05 Mar 2026 10:42:51 +0000 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=ZgLn5gKTC6ltjP22vENPvguQQAUnJs1iU1xrD1qgNa0=; b=kjOZapz9Cy687qC4OkDRb34zzI aDvzNyVJBUL1P2nBVmBo55U8s+wJwYybrPZ0fKLXulCpOcFB87VEouy9exDrhtvmQJCmF8XGWZz9Z OZmFI+DXsQTMsLVYDyj2TcO7eOU83+/4VoyDpBodtQOCc1lhTU0dYOeywPSisj1kowKzv6V4ZZSuX tsE+Uiqv4L+5agHYuS5KLfy4EH6B7XpxjfEYEjAyXs5gX8VsMX9mkhKEUl0GyPrUsehenzS40TPSE G+9p/Ro3ia6PikvJs8gkG5lxNfYNgQVP+VpWqbKJG8P1wJLJ5dFjqAvDYAFOZo7c+7qNvfTqKqUbO om0dWTnA==; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:58672 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 1vy6AF-000000007nW-1SLf; Thu, 05 Mar 2026 10:42:43 +0000 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.98.2) (envelope-from ) id 1vy6AE-0000000Btwv-1LM4; Thu, 05 Mar 2026 10:42:42 +0000 In-Reply-To: References: From: "Russell King (Oracle)" To: Andrew Lunn Cc: Alexandre Torgue , Andrew Lunn , Chen-Yu Tsai , "David S. Miller" , Eric Dumazet , Jakub Kicinski , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@lists.linux.dev, netdev@vger.kernel.org, Paolo Abeni , Samuel Holland Subject: [PATCH net-next v2 4/8] net: stmmac: mdio: convert field prep to use field_prep() MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" Message-Id: Date: Thu, 05 Mar 2026 10:42:42 +0000 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260305_024250_871015_5E1FDC29 X-CRM114-Status: GOOD ( 12.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Convert the MDIO field preparation to use field_prep(), which removes the need to store separate mask and shifts. Also convert the clk_csr value using __ffs() to do the shift as we need to detect overflows for this. Signed-off-by: Russell King (Oracle) --- drivers/net/ethernet/stmicro/stmmac/common.h | 3 --- drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 3 --- drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c | 3 --- drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 3 --- drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c | 3 --- drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c | 3 --- drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 6 ------ drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 6 +++--- 8 files changed, 3 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index e4ce1167ebab..978f90065681 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -608,11 +608,8 @@ struct mac_link { struct mii_regs { unsigned int addr; /* MII Address */ unsigned int data; /* MII Data */ - unsigned int addr_shift; /* MII address shift */ - unsigned int reg_shift; /* MII reg shift */ unsigned int addr_mask; /* MII address mask */ unsigned int reg_mask; /* MII reg mask */ - unsigned int clk_csr_shift; unsigned int clk_csr_mask; }; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c index 9c51c96223ad..6dfccc969d0e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c @@ -367,11 +367,8 @@ static int loongson_dwmac_setup(void *apriv, struct mac_device_info *mac) mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES; mac->mii.addr = GMAC_MII_ADDR; mac->mii.data = GMAC_MII_DATA; - mac->mii.addr_shift = 11; mac->mii.addr_mask = 0x0000F800; - mac->mii.reg_shift = 6; mac->mii.reg_mask = 0x000007C0; - mac->mii.clk_csr_shift = 2; mac->mii.clk_csr_mask = GENMASK(5, 2); return 0; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c index c01b86fd64da..6b18072112db 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c @@ -1063,11 +1063,8 @@ static int sun8i_dwmac_setup(void *ppriv, struct mac_device_info *mac) mac->link.duplex = EMAC_DUPLEX_FULL; mac->mii.addr = EMAC_MDIO_CMD; mac->mii.data = EMAC_MDIO_DATA; - mac->mii.reg_shift = 4; mac->mii.reg_mask = GENMASK(8, 4); - mac->mii.addr_shift = 12; mac->mii.addr_mask = GENMASK(16, 12); - mac->mii.clk_csr_shift = 20; mac->mii.clk_csr_mask = GENMASK(22, 20); mac->unicast_filter_entries = 8; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c index af566636fad9..10acca806f4f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c @@ -496,11 +496,8 @@ int dwmac1000_setup(struct stmmac_priv *priv) mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES; mac->mii.addr = GMAC_MII_ADDR; mac->mii.data = GMAC_MII_DATA; - mac->mii.addr_shift = 11; mac->mii.addr_mask = 0x0000F800; - mac->mii.reg_shift = 6; mac->mii.reg_mask = 0x000007C0; - mac->mii.clk_csr_shift = 2; mac->mii.clk_csr_mask = GENMASK(5, 2); return 0; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c index db4fbe64a38a..911753b9889e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c @@ -184,11 +184,8 @@ int dwmac100_setup(struct stmmac_priv *priv) mac->link.speed_mask = MAC_CONTROL_PS; mac->mii.addr = MAC_MII_ADDR; mac->mii.data = MAC_MII_DATA; - mac->mii.addr_shift = 11; mac->mii.addr_mask = 0x0000F800; - mac->mii.reg_shift = 6; mac->mii.reg_mask = 0x000007C0; - mac->mii.clk_csr_shift = 2; mac->mii.clk_csr_mask = GENMASK(5, 2); return 0; diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c index 623868afe93d..0e87590c806b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c @@ -1030,11 +1030,8 @@ int dwmac4_setup(struct stmmac_priv *priv) mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS; mac->mii.addr = GMAC_MDIO_ADDR; mac->mii.data = GMAC_MDIO_DATA; - mac->mii.addr_shift = 21; mac->mii.addr_mask = GENMASK(25, 21); - mac->mii.reg_shift = 16; mac->mii.reg_mask = GENMASK(20, 16); - mac->mii.clk_csr_shift = 8; mac->mii.clk_csr_mask = GENMASK(11, 8); mac->num_vlan = stmmac_get_num_vlan(priv->ioaddr); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c index 49893b9fb88c..ba98e22f1c12 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c @@ -1551,11 +1551,8 @@ int dwxgmac2_setup(struct stmmac_priv *priv) mac->mii.addr = XGMAC_MDIO_ADDR; mac->mii.data = XGMAC_MDIO_DATA; - mac->mii.addr_shift = 16; mac->mii.addr_mask = GENMASK(20, 16); - mac->mii.reg_shift = 0; mac->mii.reg_mask = GENMASK(15, 0); - mac->mii.clk_csr_shift = 19; mac->mii.clk_csr_mask = GENMASK(21, 19); mac->num_vlan = stmmac_get_num_vlan(priv->ioaddr); @@ -1594,11 +1591,8 @@ int dwxlgmac2_setup(struct stmmac_priv *priv) mac->mii.addr = XGMAC_MDIO_ADDR; mac->mii.data = XGMAC_MDIO_DATA; - mac->mii.addr_shift = 16; mac->mii.addr_mask = GENMASK(20, 16); - mac->mii.reg_shift = 0; mac->mii.reg_mask = GENMASK(15, 0); - mac->mii.clk_csr_shift = 19; mac->mii.clk_csr_mask = GENMASK(21, 19); return 0; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index c9f0b8b601d2..afe98ff5bdcb 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -234,8 +234,8 @@ static u32 stmmac_mdio_format_addr(struct stmmac_priv *priv, { const struct mii_regs *mii_regs = &priv->hw->mii; - return ((pa << mii_regs->addr_shift) & mii_regs->addr_mask) | - ((gr << mii_regs->reg_shift) & mii_regs->reg_mask) | + return field_prep(mii_regs->addr_mask, pa) | + field_prep(mii_regs->reg_mask, gr) | priv->gmii_address_bus_config | MII_ADDR_GBUSY; } @@ -577,7 +577,7 @@ static void stmmac_mdio_bus_config(struct stmmac_priv *priv) else value = stmmac_clk_csr_set(priv); - value <<= priv->hw->mii.clk_csr_shift; + value <<= __ffs(priv->hw->mii.clk_csr_mask); if (value & ~priv->hw->mii.clk_csr_mask) dev_warn(priv->device, -- 2.47.3