[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <E1utmm8-00000001s0U-2VYX@rmk-PC.armlinux.org.uk>
Date: Wed, 03 Sep 2025 13:39:44 +0100
From: "Russell King (Oracle)" <rmk+kernel@...linux.org.uk>
To: Andrew Lunn <andrew@...n.ch>,
Heiner Kallweit <hkallweit1@...il.com>
Cc: Alexandre Torgue <alexandre.torgue@...s.st.com>,
Andrew Lunn <andrew+netdev@...n.ch>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
linux-arm-kernel@...ts.infradead.org,
linux-stm32@...md-mailman.stormreply.com,
Maxime Coquelin <mcoquelin.stm32@...il.com>,
netdev@...r.kernel.org,
Paolo Abeni <pabeni@...hat.com>
Subject: [PATCH net-next 06/11] net: stmmac: mdio: move runtime PM into
stmmac_mdio_access()
Move the runtime PM handling into the common stmmac_mdio_access()
function, rather than having it in the four top-level bus access
functions.
Signed-off-by: Russell King (Oracle) <rmk+kernel@...linux.org.uk>
---
.../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 71 ++++++-------------
1 file changed, 20 insertions(+), 51 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index 62e74467de49..2d6a5d40e2c1 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -246,9 +246,13 @@ static int stmmac_mdio_access(struct stmmac_priv *priv, unsigned int pa,
u32 addr;
int ret;
+ ret = pm_runtime_resume_and_get(priv->device);
+ if (ret < 0)
+ return ret;
+
ret = stmmac_mdio_wait(mii_address, MII_BUSY);
if (ret)
- return ret;
+ goto out;
addr = stmmac_mdio_format_addr(priv, pa, gr) | cmd;
@@ -257,10 +261,15 @@ static int stmmac_mdio_access(struct stmmac_priv *priv, unsigned int pa,
ret = stmmac_mdio_wait(mii_address, MII_BUSY);
if (ret)
- return ret;
+ goto out;
/* Read the data from the MII data register if in read mode */
- return read ? readl(mii_data) & MII_DATA_MASK : 0;
+ ret = read ? readl(mii_data) & MII_DATA_MASK : 0;
+
+out:
+ pm_runtime_put(priv->device);
+
+ return ret;
}
static int stmmac_mdio_read(struct stmmac_priv *priv, unsigned int pa,
@@ -288,23 +297,14 @@ static int stmmac_mdio_write(struct stmmac_priv *priv, unsigned int pa,
static int stmmac_mdio_read_c22(struct mii_bus *bus, int phyaddr, int phyreg)
{
struct stmmac_priv *priv = netdev_priv(bus->priv);
- int data = 0;
u32 cmd;
- data = pm_runtime_resume_and_get(priv->device);
- if (data < 0)
- return data;
-
if (priv->plat->has_gmac4)
cmd = MII_GMAC4_READ;
else
cmd = 0;
- data = stmmac_mdio_read(priv, phyaddr, phyreg, cmd, data);
-
- pm_runtime_put(priv->device);
-
- return data;
+ return stmmac_mdio_read(priv, phyaddr, phyreg, cmd, 0);
}
/**
@@ -322,22 +322,10 @@ static int stmmac_mdio_read_c45(struct mii_bus *bus, int phyaddr, int devad,
int phyreg)
{
struct stmmac_priv *priv = netdev_priv(bus->priv);
- int data = 0;
- u32 cmd;
-
- data = pm_runtime_resume_and_get(priv->device);
- if (data < 0)
- return data;
-
- cmd = MII_GMAC4_READ | MII_GMAC4_C45E;
-
- data |= phyreg << MII_GMAC4_REG_ADDR_SHIFT;
-
- data = stmmac_mdio_read(priv, phyaddr, devad, cmd, data);
+ int data = phyreg << MII_GMAC4_REG_ADDR_SHIFT;
+ u32 cmd = MII_GMAC4_READ | MII_GMAC4_C45E;
- pm_runtime_put(priv->device);
-
- return data;
+ return stmmac_mdio_read(priv, phyaddr, devad, cmd, data);
}
/**
@@ -352,23 +340,14 @@ static int stmmac_mdio_write_c22(struct mii_bus *bus, int phyaddr, int phyreg,
u16 phydata)
{
struct stmmac_priv *priv = netdev_priv(bus->priv);
- int ret, data = phydata;
u32 cmd;
- ret = pm_runtime_resume_and_get(priv->device);
- if (ret < 0)
- return ret;
-
if (priv->plat->has_gmac4)
cmd = MII_GMAC4_WRITE;
else
cmd = MII_WRITE;
- ret = stmmac_mdio_write(priv, phyaddr, phyreg, cmd, data);
-
- pm_runtime_put(priv->device);
-
- return ret;
+ return stmmac_mdio_write(priv, phyaddr, phyreg, cmd, phydata);
}
/**
@@ -384,22 +363,12 @@ static int stmmac_mdio_write_c45(struct mii_bus *bus, int phyaddr,
int devad, int phyreg, u16 phydata)
{
struct stmmac_priv *priv = netdev_priv(bus->priv);
- int ret, data = phydata;
- u32 cmd;
-
- ret = pm_runtime_resume_and_get(priv->device);
- if (ret < 0)
- return ret;
-
- cmd = MII_GMAC4_WRITE | MII_GMAC4_C45E;
+ u32 cmd = MII_GMAC4_WRITE | MII_GMAC4_C45E;
+ int data = phydata;
data |= phyreg << MII_GMAC4_REG_ADDR_SHIFT;
- ret = stmmac_mdio_write(priv, phyaddr, devad, cmd, data);
-
- pm_runtime_put(priv->device);
-
- return ret;
+ return stmmac_mdio_write(priv, phyaddr, devad, cmd, data);
}
/**
--
2.47.2
Powered by blists - more mailing lists