From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>, Heiner Kallweit <hkallweit1@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
linux-arm-kernel@lists.infradead.org,
linux-stm32@st-md-mailman.stormreply.com,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
netdev@vger.kernel.org, Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v2 03/11] net: stmmac: mdio: provide priv->gmii_address_bus_config
Date: Thu, 04 Sep 2025 13:11:10 +0100 [thread overview]
Message-ID: <E1uu8o2-00000001vog-1LyK@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <aLmBwsMdW__XBv7g@shell.armlinux.org.uk>
Provide a pre-formatted value for the MDIO address register fields
which remain constant across the various different transactions
rather than recreating the register value from scratch every time.
Currently, we only do this for the CR (clock range) field.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 +
.../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 26 ++++++++++++-------
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index 78d6b3737a26..4d5577935b13 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -290,6 +290,7 @@ struct stmmac_priv {
int wolopts;
int wol_irq;
int clk_csr;
+ u32 gmii_address_bus_config;
struct timer_list eee_ctrl_timer;
int lpi_irq;
u32 tx_lpi_timer;
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 6acce54b5d55..4294262c208d 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -104,9 +104,7 @@ static int stmmac_xgmac2_mdio_read(struct stmmac_priv *priv, u32 addr,
if (ret)
goto err_disable_clks;
- value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
- & priv->hw->mii.clk_csr_mask;
- value |= MII_XGMAC_READ;
+ value |= priv->gmii_address_bus_config | MII_XGMAC_READ;
/* Wait until any existing MII operation is complete */
ret = stmmac_mdio_wait(priv->ioaddr + mii_data, MII_XGMAC_BUSY);
@@ -174,10 +172,7 @@ static int stmmac_xgmac2_mdio_write(struct stmmac_priv *priv, u32 addr,
if (ret)
goto err_disable_clks;
- value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
- & priv->hw->mii.clk_csr_mask;
- value |= phydata;
- value |= MII_XGMAC_WRITE;
+ value |= priv->gmii_address_bus_config | phydata | MII_XGMAC_WRITE;
/* Wait until any existing MII operation is complete */
ret = stmmac_mdio_wait(priv->ioaddr + mii_data, MII_XGMAC_BUSY);
@@ -241,8 +236,7 @@ static u32 stmmac_mdio_format_addr(struct stmmac_priv *priv,
return ((pa << mii_regs->addr_shift) & mii_regs->addr_mask) |
((gr << mii_regs->reg_shift) & mii_regs->reg_mask) |
- ((priv->clk_csr << mii_regs->clk_csr_shift) &
- mii_regs->clk_csr_mask) |
+ priv->gmii_address_bus_config |
MII_BUSY;
}
@@ -517,6 +511,18 @@ void stmmac_pcs_clean(struct net_device *ndev)
priv->hw->xpcs = NULL;
}
+static void stmmac_mdio_bus_config(struct stmmac_priv *priv, u32 value)
+{
+ value <<= priv->hw->mii.clk_csr_shift;
+
+ if (value & ~priv->hw->mii.clk_csr_mask)
+ dev_warn(priv->device,
+ "clk_csr value out of range (0x%08x exceeds mask 0x%08x), truncating\n",
+ value, priv->hw->mii.clk_csr_mask);
+
+ priv->gmii_address_bus_config = value & priv->hw->mii.clk_csr_mask;
+}
+
/**
* stmmac_mdio_register
* @ndev: net device structure
@@ -537,6 +543,8 @@ int stmmac_mdio_register(struct net_device *ndev)
if (!mdio_bus_data)
return 0;
+ stmmac_mdio_bus_config(priv, priv->clk_csr);
+
new_bus = mdiobus_alloc();
if (!new_bus)
return -ENOMEM;
--
2.47.2
next prev parent reply other threads:[~2025-09-04 12:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 12:10 [PATCH net-next v2 00/11] net: stmmac: mdio cleanups Russell King (Oracle)
2025-09-04 12:11 ` [PATCH net-next v2 01/11] net: stmmac: mdio: provide address register formatter Russell King (Oracle)
2025-09-04 18:56 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 02/11] net: stmmac: mdio: provide stmmac_mdio_wait() Russell King (Oracle)
2025-09-04 18:56 ` Andrew Lunn
2025-09-04 12:11 ` Russell King (Oracle) [this message]
2025-09-04 18:57 ` [PATCH net-next v2 03/11] net: stmmac: mdio: provide priv->gmii_address_bus_config Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 04/11] net: stmmac: mdio: move stmmac_mdio_format_addr() into read/write Russell King (Oracle)
2025-09-04 18:58 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 05/11] net: stmmac: mdio: merge stmmac_mdio_read() and stmmac_mdio_write() Russell King (Oracle)
2025-09-04 19:00 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 06/11] net: stmmac: mdio: move runtime PM into stmmac_mdio_access() Russell King (Oracle)
2025-09-04 19:01 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 07/11] net: stmmac: mdio: improve mdio register field definitions Russell King (Oracle)
2025-09-04 19:02 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 08/11] net: stmmac: mdio: move initialisation of priv->clk_csr to stmmac_mdio Russell King (Oracle)
2025-09-04 19:04 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 09/11] net: stmmac: mdio: return clk_csr value from stmmac_clk_csr_set() Russell King (Oracle)
2025-09-04 19:05 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 10/11] net: stmmac: mdio: remove redundant clock rate tests Russell King (Oracle)
2025-09-04 19:06 ` Andrew Lunn
2025-09-04 12:11 ` [PATCH net-next v2 11/11] net: stmmac: use STMMAC_CSR_xxx definitions in platform glue Russell King (Oracle)
2025-09-04 19:06 ` Andrew Lunn
2025-09-05 13:30 ` [PATCH net-next v2 00/11] net: stmmac: mdio cleanups Mohd Ayaan Anwar
2025-09-09 1:30 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1uu8o2-00000001vog-1LyK@rmk-PC.armlinux.org.uk \
--to=rmk+kernel@armlinux.org.uk \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).