net: stmmac: mdio cleanups
Subsystems (4)
v2 cover net: stmmac: mdio cleanups
On Wed, Sep 03, 2025 at 01:38:57PM +0100, Russell King (Oracle) wrote:
Hi,
Clean up the stmmac MDIO code:
- provide an address register formatter to avoid repeated code
- provide a common function to wait for the busy bit to clear
- pre-compute the CR field (mdio clock divider)
- move address formatter into read/write functions
- combine the read/write functions into a common accessor function
- move runtime PM handling into common accessor function
- rename register constants to better reflect manufacturer names
- move stmmac_clk_csr_set() into stmmac_mdio
- make stmmac_clk_csr_set() return the CR field value and remove priv->clk_csr
- clean up if() range tests in stmmac_clk_csr_set()
- use STMMAC_CSR_xxx definitions in initialisers
Untested on hardware; would be grateful for any testing people can do.
v2: add "Return:" to patch 1 and 9
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 5 +- .../net/ethernet/stmicro/stmmac/dwmac-loongson.c | 3 +- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 82 ----- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 345 ++++++++++++--------- drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 5 +- 6 files changed, 207 insertions(+), 235 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH v2 1/11 net: stmmac: mdio: provide address register formatter
Rather than duplicating the logic for filling the PA (MDIO address), GR (MDIO register/devad), CR (clock range) and GB (busy) fields of the address register in four locations, provide a helper to do this.
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +28 -27
@@ -229,6 +229,26 @@ static int stmmac_xgmac2_mdio_write_c45(struct mii_bus *bus, int phyaddr, phydata); } +/** +* stmmac_mdio_format_addr() - format the address register +* @priv: struct stmmac_priv pointer +* @pa: 5-bit MDIO package address +* @gr: 5-bit MDIO register address (C22) or MDIO device address (C45) +* +* Return: formatted address register +*/ +static u32 stmmac_mdio_format_addr (struct stmmac_priv *priv, +unsigned int pa,unsigned int gr) +{ +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) | + ((priv->clk_csr << mii_regs->clk_csr_shift) & + mii_regs->clk_csr_mask) | +MII_BUSY ; +} +static int stmmac_mdio_read (struct stmmac_priv *priv,int data,u32 value) {unsigned int mii_address = priv->hw->mii.addr;
@@ -263,18 +283,14 @@ static int stmmac_mdio_read(struct stmmac_priv *priv, int data, u32 value)static int stmmac_mdio_read_c22 (struct mii_bus *bus,int phyaddr,int phyreg) {struct stmmac_priv *priv =netdev_priv (bus->priv); -u32 value =MII_BUSY ;int data =0 ; +u32 value; data =pm_runtime_resume_and_get (priv->device);if (data <0 )return data; - value |= (phyaddr << priv->hw->mii.addr_shift) - & priv->hw->mii.addr_mask; - value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask; - value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift) - & priv->hw->mii.clk_csr_mask; + value =stmmac_mdio_format_addr (priv, phyaddr, phyreg);if (priv->plat->has_gmac4) value |=MII_GMAC4_READ ;
@@ -300,20 +316,16 @@ static int stmmac_mdio_read_c45(struct mii_bus *bus, int phyaddr, int devad, int phyreg) {struct stmmac_priv *priv =netdev_priv (bus->priv); -u32 value =MII_BUSY ;int data =0 ; +u32 value; data =pm_runtime_resume_and_get (priv->device);if (data <0 )return data; - value |= (phyaddr << priv->hw->mii.addr_shift) - & priv->hw->mii.addr_mask; - value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift) - & priv->hw->mii.clk_csr_mask; + value =stmmac_mdio_format_addr (priv, phyaddr, devad); value |=MII_GMAC4_READ ; value |=MII_GMAC4_C45E ; - value |= (devad << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask; data |= phyreg <<MII_GMAC4_REG_ADDR_SHIFT ;
@@ -357,18 +369,13 @@ static int stmmac_mdio_write_c22(struct mii_bus *bus, int phyaddr, int phyreg, {struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata; -u32 value =MII_BUSY ; +u32 value; ret =pm_runtime_resume_and_get (priv->device);if (ret <0 )return ret; - value |= (phyaddr << priv->hw->mii.addr_shift) - & priv->hw->mii.addr_mask; - value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask; - - value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift) - & priv->hw->mii.clk_csr_mask; + value =stmmac_mdio_format_addr (priv, phyaddr, phyreg);if (priv->plat->has_gmac4) value |=MII_GMAC4_WRITE ;else
@@ -395,21 +402,15 @@ static int stmmac_mdio_write_c45(struct mii_bus *bus, int phyaddr, {struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata; -u32 value =MII_BUSY ; +u32 value; ret =pm_runtime_resume_and_get (priv->device);if (ret <0 )return ret; - value |= (phyaddr << priv->hw->mii.addr_shift) - & priv->hw->mii.addr_mask; - - value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift) - & priv->hw->mii.clk_csr_mask; - + value =stmmac_mdio_format_addr (priv, phyaddr, devad); value |=MII_GMAC4_WRITE ; value |=MII_GMAC4_C45E ; - value |= (devad << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask; data |= phyreg <<MII_GMAC4_REG_ADDR_SHIFT ;
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 01/11] net: stmmac: mdio: provide address register formatter
Quoted 5 lines · Russell King (Oracle)
Rather than duplicating the logic for filling the PA (MDIO address), GR (MDIO register/devad), CR (clock range) and GB (busy) fields of the address register in four locations, provide a helper to do this.
Signed-off-by Russell King (Oracle) <[email protected]>
I cannot test any of these patches, so please don't merge just because of my review. Russell specifically asked for testers.
Andrew
PATCH v2 2/11 net: stmmac: mdio: provide stmmac_mdio_wait()
In reply to Russell King (Oracle)All the readl_poll_timeout()s follow the same pattern - test a register for a bit being clear every 100us, and timeout after 10ms returning -EBUSY. Wrap this up into a function to avoid duplicating this.
This slightly changes the return value for stmmac_mdio_write() if the second readl_poll_timeout() fails - rather than returning -ETIMEDOUT we return -EBUSY matching the stmmac_mdio_read() behaviour.
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +33 -37
@@ -45,6 +45,16 @@#define MII_XGMAC_PA_SHIFT 16#define MII_XGMAC_DA_SHIFT 21 +static int stmmac_mdio_wait (void __iomem *reg,u32 mask) +{ +u32 v; + +if (readl_poll_timeout (reg, v, !(v & mask),100 ,10000 )) +return -EBUSY ; + +return 0 ; +} +static void stmmac_xgmac2_c45_format (struct stmmac_priv *priv,int phyaddr,int devad,int phyreg,u32 *hw_addr) {
@@ -83,7 +93,6 @@ static int stmmac_xgmac2_mdio_read(struct stmmac_priv *priv, u32 addr, {unsigned int mii_address = priv->hw->mii.addr;unsigned int mii_data = priv->hw->mii.data; -u32 tmp;int ret; ret =pm_runtime_resume_and_get (priv->device);
@@ -91,33 +100,27 @@ static int stmmac_xgmac2_mdio_read(struct stmmac_priv *priv, u32 addr,return ret;/* Wait until any existing MII operation is complete */ -if (readl_poll_timeout (priv->ioaddr + mii_data, tmp, - !(tmp &MII_XGMAC_BUSY ),100 ,10000 )) { - ret = -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_data,MII_XGMAC_BUSY ); +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 ;/* Wait until any existing MII operation is complete */ -if (readl_poll_timeout (priv->ioaddr + mii_data, tmp, - !(tmp &MII_XGMAC_BUSY ),100 ,10000 )) { - ret = -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_data,MII_XGMAC_BUSY ); +if (ret) goto err_disable_clks; - }/* Set the MII address register to read */ writel (addr, priv->ioaddr + mii_address);writel (value, priv->ioaddr + mii_data);/* Wait until any existing MII operation is complete */ -if (readl_poll_timeout (priv->ioaddr + mii_data, tmp, - !(tmp &MII_XGMAC_BUSY ),100 ,10000 )) { - ret = -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_data,MII_XGMAC_BUSY ); +if (ret) goto err_disable_clks; - }/* Read the data from the MII data register */ ret = (int )readl (priv->ioaddr + mii_data) &GENMASK (15 ,0 );
@@ -160,7 +163,6 @@ static int stmmac_xgmac2_mdio_write(struct stmmac_priv *priv, u32 addr, {unsigned int mii_address = priv->hw->mii.addr;unsigned int mii_data = priv->hw->mii.data; -u32 tmp;int ret; ret =pm_runtime_resume_and_get (priv->device);
@@ -168,11 +170,9 @@ static int stmmac_xgmac2_mdio_write(struct stmmac_priv *priv, u32 addr,return ret;/* Wait until any existing MII operation is complete */ -if (readl_poll_timeout (priv->ioaddr + mii_data, tmp, - !(tmp &MII_XGMAC_BUSY ),100 ,10000 )) { - ret = -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_data,MII_XGMAC_BUSY ); +if (ret) goto err_disable_clks; - } value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift) & priv->hw->mii.clk_csr_mask;
@@ -180,19 +180,16 @@ static int stmmac_xgmac2_mdio_write(struct stmmac_priv *priv, u32 addr, value |=MII_XGMAC_WRITE ;/* Wait until any existing MII operation is complete */ -if (readl_poll_timeout (priv->ioaddr + mii_data, tmp, - !(tmp &MII_XGMAC_BUSY ),100 ,10000 )) { - ret = -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_data,MII_XGMAC_BUSY ); +if (ret) goto err_disable_clks; - }/* Set the MII address register to write */ writel (addr, priv->ioaddr + mii_address);writel (value, priv->ioaddr + mii_data);/* Wait until any existing MII operation is complete */ - ret =readl_poll_timeout (priv->ioaddr + mii_data, tmp, - !(tmp &MII_XGMAC_BUSY ),100 ,10000 ); + ret =stmmac_mdio_wait (priv->ioaddr + mii_data,MII_XGMAC_BUSY ); err_disable_clks:pm_runtime_put (priv->device);
@@ -253,18 +250,18 @@ static int stmmac_mdio_read(struct stmmac_priv *priv, int data, u32 value) {unsigned int mii_address = priv->hw->mii.addr;unsigned int mii_data = priv->hw->mii.data; -u32 v; +int ret; -if (readl_poll_timeout (priv->ioaddr + mii_address, v, !(v &MII_BUSY ), -100 ,10000 )) -return -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); +if (ret) +return ret;writel (data, priv->ioaddr + mii_data);writel (value, priv->ioaddr + mii_address); -if (readl_poll_timeout (priv->ioaddr + mii_address, v, !(v &MII_BUSY ), -100 ,10000 )) -return -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); +if (ret) +return ret;/* Read the data from the MII data register */ return readl (priv->ioaddr + mii_data) &MII_DATA_MASK ;
@@ -340,20 +337,19 @@ static int stmmac_mdio_write(struct stmmac_priv *priv, int data, u32 value) {unsigned int mii_address = priv->hw->mii.addr;unsigned int mii_data = priv->hw->mii.data; -u32 v; +int ret;/* Wait until any existing MII operation is complete */ -if (readl_poll_timeout (priv->ioaddr + mii_address, v, !(v &MII_BUSY ), -100 ,10000 )) -return -EBUSY ; + ret =stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); +if (ret) +return ret;/* Set the MII address register to write */ writel (data, priv->ioaddr + mii_data);writel (value, priv->ioaddr + mii_address);/* Wait until any existing MII operation is complete */ -return readl_poll_timeout (priv->ioaddr + mii_address, v, - !(v &MII_BUSY ),100 ,10000 ); +return stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); }/**
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 02/11] net: stmmac: mdio: provide stmmac_mdio_wait()
Quoted 9 lines · Russell King (Oracle)
All the readl_poll_timeout()s follow the same pattern - test a register for a bit being clear every 100us, and timeout after 10ms returning
-EBUSY. Wrap this up into a function to avoid duplicating this.This slightly changes the return value for
stmmac_mdio_write()if the secondreadl_poll_timeout()fails - rather than returning-ETIMEDOUTwe return-EBUSYmatching thestmmac_mdio_read()behaviour.Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
PATCH v2 3/11 net: stmmac: mdio: provide priv->gmii_address_bus_config
In reply to Russell King (Oracle)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.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +1 -0
@@ -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;
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +17 -9
@@ -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 ;
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 03/11] net: stmmac: mdio: provide priv->gmii_address_bus_config
Quoted 6 lines · Russell King (Oracle)
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) <[email protected]>
Andrew
PATCH v2 4/11 net: stmmac: mdio: move stmmac_mdio_format_addr() into read/write
In reply to Russell King (Oracle)Move stmmac_mdio_format_addr() into stmmac_mdio_read() and stmmac_mdio_write().
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +25 -21
@@ -240,16 +240,20 @@ static u32 stmmac_mdio_format_addr(struct stmmac_priv *priv,MII_BUSY ; } -static int stmmac_mdio_read (struct stmmac_priv *priv,int data,u32 value) +static int stmmac_mdio_read (struct stmmac_priv *priv,unsigned int pa, +unsigned int gr,u32 cmd,int data) {unsigned int mii_address = priv->hw->mii.addr;unsigned int mii_data = priv->hw->mii.data; +u32 value;int ret; ret =stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY );if (ret)return ret; + value =stmmac_mdio_format_addr (priv, pa, gr) | cmd; +writel (data, priv->ioaddr + mii_data);writel (value, priv->ioaddr + mii_address);
@@ -275,17 +279,18 @@ 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 value; +u32 cmd; data =pm_runtime_resume_and_get (priv->device);if (data <0 )return data; - value =stmmac_mdio_format_addr (priv, phyaddr, phyreg);if (priv->plat->has_gmac4) - value |=MII_GMAC4_READ ; + cmd =MII_GMAC4_READ ; +else + cmd =0 ; - data =stmmac_mdio_read (priv, data, value); + data =stmmac_mdio_read (priv, phyaddr, phyreg, cmd, data);pm_runtime_put (priv->device);
@@ -308,29 +313,29 @@ static int stmmac_mdio_read_c45(struct mii_bus *bus, int phyaddr, int devad, {struct stmmac_priv *priv =netdev_priv (bus->priv);int data =0 ; -u32 value; +u32 cmd; data =pm_runtime_resume_and_get (priv->device);if (data <0 )return data; - value =stmmac_mdio_format_addr (priv, phyaddr, devad); - value |=MII_GMAC4_READ ; - value |=MII_GMAC4_C45E ; + cmd =MII_GMAC4_READ |MII_GMAC4_C45E ; data |= phyreg <<MII_GMAC4_REG_ADDR_SHIFT ; - data =stmmac_mdio_read (priv, data, value); + data =stmmac_mdio_read (priv, phyaddr, devad, cmd, data);pm_runtime_put (priv->device);return data; } -static int stmmac_mdio_write (struct stmmac_priv *priv,int data,u32 value) +static int stmmac_mdio_write (struct stmmac_priv *priv,unsigned int pa, +unsigned int gr,u32 cmd,int data) {unsigned int mii_address = priv->hw->mii.addr;unsigned int mii_data = priv->hw->mii.data; +u32 value;int ret;/* Wait until any existing MII operation is complete */
@@ -338,6 +343,8 @@ static int stmmac_mdio_write(struct stmmac_priv *priv, int data, u32 value)if (ret)return ret; + value =stmmac_mdio_format_addr (priv, pa, gr) | cmd; +/* Set the MII address register to write */ writel (data, priv->ioaddr + mii_data);writel (value, priv->ioaddr + mii_address);
@@ -359,19 +366,18 @@ static int stmmac_mdio_write_c22(struct mii_bus *bus, int phyaddr, int phyreg, {struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata; -u32 value; +u32 cmd; ret =pm_runtime_resume_and_get (priv->device);if (ret <0 )return ret; - value =stmmac_mdio_format_addr (priv, phyaddr, phyreg);if (priv->plat->has_gmac4) - value |=MII_GMAC4_WRITE ; + cmd =MII_GMAC4_WRITE ;else - value |=MII_WRITE ; + cmd =MII_WRITE ; - ret =stmmac_mdio_write (priv, data, value); + ret =stmmac_mdio_write (priv, phyaddr, phyreg, cmd, data);pm_runtime_put (priv->device);
@@ -392,19 +398,17 @@ static int stmmac_mdio_write_c45(struct mii_bus *bus, int phyaddr, {struct stmmac_priv *priv =netdev_priv (bus->priv);int ret, data = phydata; -u32 value; +u32 cmd; ret =pm_runtime_resume_and_get (priv->device);if (ret <0 )return ret; - value =stmmac_mdio_format_addr (priv, phyaddr, devad); - value |=MII_GMAC4_WRITE ; - value |=MII_GMAC4_C45E ; + cmd =MII_GMAC4_WRITE |MII_GMAC4_C45E ; data |= phyreg <<MII_GMAC4_REG_ADDR_SHIFT ; - ret =stmmac_mdio_write (priv, data, value); + ret =stmmac_mdio_write (priv, phyaddr, devad, cmd, data);pm_runtime_put (priv->device);
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 04/11] net: stmmac: mdio: move stmmac_mdio_format_addr() into read/write
Quoted 4 lines · Russell King (Oracle)
Move
stmmac_mdio_format_addr()intostmmac_mdio_read()andstmmac_mdio_write().Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
PATCH v2 5/11 net: stmmac: mdio: merge stmmac_mdio_read() and stmmac_mdio_write()
In reply to Russell King (Oracle)stmmac_mdio_read() and stmmac_mdio_write() are virtually identical except for the final read in the stmmac_mdio_read(). Handle this as a flag.
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 59 ++++++++----------- 1 file changed, 24 insertions(+), 35 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +24 -35
@@ -240,29 +240,41 @@ static u32 stmmac_mdio_format_addr(struct stmmac_priv *priv,MII_BUSY ; } -static int stmmac_mdio_read (struct stmmac_priv *priv,unsigned int pa, -unsigned int gr,u32 cmd,int data) +static int stmmac_mdio_access (struct stmmac_priv *priv,unsigned int pa, +unsigned int gr,u32 cmd,u32 data,bool read) { -unsigned int mii_address = priv->hw->mii.addr; -unsigned int mii_data = priv->hw->mii.data; -u32 value; +void __iomem *mii_address = priv->ioaddr + priv->hw->mii.addr; +void __iomem *mii_data = priv->ioaddr + priv->hw->mii.data; +u32 addr;int ret; - ret =stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); + ret =stmmac_mdio_wait (mii_address,MII_BUSY );if (ret)return ret; - value =stmmac_mdio_format_addr (priv, pa, gr) | cmd; + addr =stmmac_mdio_format_addr (priv, pa, gr) | cmd; -writel (data, priv->ioaddr + mii_data); -writel (value, priv->ioaddr + mii_address); +writel (data, mii_data); +writel (addr, mii_address); - ret =stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); + ret =stmmac_mdio_wait (mii_address,MII_BUSY );if (ret)return ret; -/* Read the data from the MII data register */ -return readl (priv->ioaddr + mii_data) &MII_DATA_MASK ; +/* Read the data from the MII data register if in read mode */ +return read ?readl (mii_data) &MII_DATA_MASK :0 ; +} + +static int stmmac_mdio_read (struct stmmac_priv *priv,unsigned int pa, +unsigned int gr,u32 cmd,int data) +{ +return stmmac_mdio_access (priv, pa, gr, cmd, data, true); +} + +static int stmmac_mdio_write (struct stmmac_priv *priv,unsigned int pa, +unsigned int gr,u32 cmd,int data) +{ +return stmmac_mdio_access (priv, pa, gr, cmd, data, false); }/**
@@ -330,29 +342,6 @@ static int stmmac_mdio_read_c45(struct mii_bus *bus, int phyaddr, int devad,return data; } -static int stmmac_mdio_write (struct stmmac_priv *priv,unsigned int pa, -unsigned int gr,u32 cmd,int data) -{ -unsigned int mii_address = priv->hw->mii.addr; -unsigned int mii_data = priv->hw->mii.data; -u32 value; -int ret; - -/* Wait until any existing MII operation is complete */ - ret =stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); -if (ret) -return ret; - - value =stmmac_mdio_format_addr (priv, pa, gr) | cmd; - -/* Set the MII address register to write */ -writel (data, priv->ioaddr + mii_data); -writel (value, priv->ioaddr + mii_address); - -/* Wait until any existing MII operation is complete */ -return stmmac_mdio_wait (priv->ioaddr + mii_address,MII_BUSY ); -} -/** * stmmac_mdio_write_c22 * @bus: points to the mii_bus structure
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 05/11] net: stmmac: mdio: merge stmmac_mdio_read() and stmmac_mdio_write()
Quoted 5 lines · Russell King (Oracle)
stmmac_mdio_read()andstmmac_mdio_write()are virtually identical except for the final read in thestmmac_mdio_read(). Handle this as a flag.Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
PATCH v2 6/11 net: stmmac: mdio: move runtime PM into stmmac_mdio_access()
In reply to Russell King (Oracle)Move the runtime PM handling into the common stmmac_mdio_access() function, rather than having it in the four top-level bus access functions.
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 71 ++++++------------- 1 file changed, 20 insertions(+), 51 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +20 -51
@@ -248,9 +248,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;
@@ -259,10 +263,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,
@@ -290,23 +299,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 ); }/**
@@ -324,22 +324,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); }/**
@@ -354,23 +342,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); }/**
@@ -386,22 +365,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); }/**
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 06/11] net: stmmac: mdio: move runtime PM into stmmac_mdio_access()
Quoted 5 lines · Russell King (Oracle)
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) <[email protected]>
Andrew
PATCH v2 7/11 net: stmmac: mdio: improve mdio register field definitions
In reply to Russell King (Oracle)Include the register name in the definitions, and use a name which more closely resembles that used in documentation, while still being descriptive.
--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +8 -8
@@ -23,9 +23,9 @@#include "dwxgmac2.h" #include "stmmac.h" -#define MII_BUSY 0x00000001 -#define MII_WRITE 0x00000002 -#define MII_DATA_MASK GENMASK(15, 0) +#define MII_ADDR_GBUSY BIT(0) +#define MII_ADDR_GWRITE BIT(1) +#define MII_DATA_GD_MASK GENMASK(15, 0)/* GMAC4 defines */ #define MII_GMAC4_GOC_SHIFT 2
@@ -237,7 +237,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->gmii_address_bus_config | -MII_BUSY ; +MII_ADDR_GBUSY ; } static int stmmac_mdio_access(struct stmmac_priv *priv, unsigned int pa,
@@ -252,7 +252,7 @@ static int stmmac_mdio_access(struct stmmac_priv *priv, unsigned int pa,if (ret <0 )return ret; - ret =stmmac_mdio_wait (mii_address,MII_BUSY ); + ret =stmmac_mdio_wait (mii_address,MII_ADDR_GBUSY );if (ret) goto out;
@@ -261,12 +261,12 @@ static int stmmac_mdio_access(struct stmmac_priv *priv, unsigned int pa,writel (data, mii_data);writel (addr, mii_address); - ret =stmmac_mdio_wait (mii_address,MII_BUSY ); + ret =stmmac_mdio_wait (mii_address,MII_ADDR_GBUSY );if (ret) goto out;/* Read the data from the MII data register if in read mode */ - ret = read ?readl (mii_data) &MII_DATA_MASK :0 ; + ret = read ?readl (mii_data) &MII_DATA_GD_MASK :0 ; out:pm_runtime_put (priv->device);
@@ -347,7 +347,7 @@ static int stmmac_mdio_write_c22(struct mii_bus *bus, int phyaddr, int phyreg,if (priv->plat->has_gmac4) cmd =MII_GMAC4_WRITE ;else - cmd =MII_WRITE ; + cmd =MII_ADDR_GWRITE ;return stmmac_mdio_write (priv, phyaddr, phyreg, cmd, phydata); }
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 07/11] net: stmmac: mdio: improve mdio register field definitions
Quoted 5 lines · Russell King (Oracle)
Include the register name in the definitions, and use a name which more closely resembles that used in documentation, while still being descriptive.
Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
PATCH v2 8/11 net: stmmac: mdio: move initialisation of priv->clk_csr to stmmac_mdio
In reply to Russell King (Oracle)The only user of priv->clk_csr is the MDIO code, so move its initialisation to stmmac_mdio.c.
--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 82 ----------------- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 88 ++++++++++++++++++- 2 files changed, 86 insertions(+), 84 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +0 -82
@@ -314,77 +314,6 @@ static void stmmac_global_err(struct stmmac_priv *priv)stmmac_service_event_schedule (priv); } -/** -* stmmac_clk_csr_set - dynamically set the MDC clock -* @priv: driver private structure -* Description: this is to dynamically set the MDC clock according to the csr -* clock input. -* Note: -* If a specific clk_csr value is passed from the platform -* this means that the CSR Clock Range selection cannot be -* changed at run-time and it is fixed (as reported in the driver -* documentation). Viceversa the driver will try to set the MDC -* clock dynamically according to the actual clock input. -*/ -static void stmmac_clk_csr_set (struct stmmac_priv *priv) -{ -unsigned long clk_rate; - - clk_rate =clk_get_rate (priv->plat->stmmac_clk); - -/* Platform provided default clk_csr would be assumed valid -* for all other cases except for the below mentioned ones. -* For values higher than the IEEE 802.3 specified frequency -* we can not estimate the proper divider as it is not known -* the frequency of clk_csr_i. So we do not change the default -* divider. -*/ -if (!(priv->clk_csr &MAC_CSR_H_FRQ_MASK )) { -if (clk_rate <CSR_F_35M ) - priv->clk_csr =STMMAC_CSR_20_35M ; -else if ((clk_rate >=CSR_F_35M ) && (clk_rate <CSR_F_60M )) - priv->clk_csr =STMMAC_CSR_35_60M ; -else if ((clk_rate >=CSR_F_60M ) && (clk_rate <CSR_F_100M )) - priv->clk_csr =STMMAC_CSR_60_100M ; -else if ((clk_rate >=CSR_F_100M ) && (clk_rate <CSR_F_150M )) - priv->clk_csr =STMMAC_CSR_100_150M ; -else if ((clk_rate >=CSR_F_150M ) && (clk_rate <CSR_F_250M )) - priv->clk_csr =STMMAC_CSR_150_250M ; -else if ((clk_rate >=CSR_F_250M ) && (clk_rate <=CSR_F_300M )) - priv->clk_csr =STMMAC_CSR_250_300M ; -else if ((clk_rate >=CSR_F_300M ) && (clk_rate <CSR_F_500M )) - priv->clk_csr =STMMAC_CSR_300_500M ; -else if ((clk_rate >=CSR_F_500M ) && (clk_rate <CSR_F_800M )) - priv->clk_csr =STMMAC_CSR_500_800M ; - } - -if (priv->plat->flags &STMMAC_FLAG_HAS_SUN8I ) { -if (clk_rate >160000000 ) - priv->clk_csr =0x03 ; -else if (clk_rate >80000000 ) - priv->clk_csr =0x02 ; -else if (clk_rate >40000000 ) - priv->clk_csr =0x01 ; -else - priv->clk_csr =0 ; - } - -if (priv->plat->has_xgmac) { -if (clk_rate >400000000 ) - priv->clk_csr =0x5 ; -else if (clk_rate >350000000 ) - priv->clk_csr =0x4 ; -else if (clk_rate >300000000 ) - priv->clk_csr =0x3 ; -else if (clk_rate >250000000 ) - priv->clk_csr =0x2 ; -else if (clk_rate >150000000 ) - priv->clk_csr =0x1 ; -else - priv->clk_csr =0x0 ; - } -} -static void print_pkt (unsigned char *buf,int len) {pr_debug ("len = %d byte, buf addr: 0x%p\n" , len, buf);
@@ -7718,17 +7647,6 @@ int stmmac_dvr_probe(struct device *device,stmmac_fpe_init (priv); -/* If a specific clk_csr value is passed from the platform -* this means that the CSR Clock Range selection cannot be -* changed at run-time and it is fixed. Viceversa the driver'll try to -* set the MDC clock dynamically according to the csr actual -* clock input. -*/ -if (priv->plat->clk_csr >=0 ) - priv->clk_csr = priv->plat->clk_csr; -else -stmmac_clk_csr_set (priv); -stmmac_check_pcs_mode (priv);pm_runtime_get_noresume (device);
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +86 -2
101 lines not on this page · raw message
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 08/11] net: stmmac: mdio: move initialisation of priv->clk_csr to stmmac_mdio
Quoted 4 lines · Russell King (Oracle)
The only user of
priv->clk_csris the MDIO code, so move its initialisation tostmmac_mdio.c.Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
PATCH v2 9/11 net: stmmac: mdio: return clk_csr value from stmmac_clk_csr_set()
In reply to Russell King (Oracle)Return the clk_csr value from stmmac_clk_csr_set() rather than using priv->clk_csr, as this struct member now serves very little purpose. This allows us to remove priv->clk_csr.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 - .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 68 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +0 -1
@@ -289,7 +289,6 @@ struct stmmac_priv {u32 msg_enable;int wolopts;int wol_irq; -int clk_csr;u32 gmii_address_bus_config;struct timer_list eee_ctrl_timer;int lpi_irq;
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +34 -34
111 lines not on this page · raw message
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 09/11] net: stmmac: mdio: return clk_csr value from stmmac_clk_csr_set()
Quoted 5 lines · Russell King (Oracle)
Return the
clk_csrvalue fromstmmac_clk_csr_set()rather than usingpriv->clk_csr, as this struct member now serves very little purpose. This allows us to removepriv->clk_csr.Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
PATCH v2 10/11 net: stmmac: mdio: remove redundant clock rate tests
In reply to Russell King (Oracle)The pattern:
... if (v < A) ... else if (v >= A && v < B) ...
can be simplified to:
... if (v < A) ... else if (v < B) ...
which makes the string of ifelse more readable.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +7 -7
@@ -502,19 +502,19 @@ static u32 stmmac_clk_csr_set(struct stmmac_priv *priv)*/ if (clk_rate <CSR_F_35M ) value =STMMAC_CSR_20_35M ; -else if ((clk_rate >=CSR_F_35M ) && (clk_rate <CSR_F_60M )) +else if (clk_rate <CSR_F_60M ) value =STMMAC_CSR_35_60M ; -else if ((clk_rate >=CSR_F_60M ) && (clk_rate <CSR_F_100M )) +else if (clk_rate <CSR_F_100M ) value =STMMAC_CSR_60_100M ; -else if ((clk_rate >=CSR_F_100M ) && (clk_rate <CSR_F_150M )) +else if (clk_rate <CSR_F_150M ) value =STMMAC_CSR_100_150M ; -else if ((clk_rate >=CSR_F_150M ) && (clk_rate <CSR_F_250M )) +else if (clk_rate <CSR_F_250M ) value =STMMAC_CSR_150_250M ; -else if ((clk_rate >=CSR_F_250M ) && (clk_rate <=CSR_F_300M )) +else if (clk_rate <=CSR_F_300M ) value =STMMAC_CSR_250_300M ; -else if ((clk_rate >=CSR_F_300M ) && (clk_rate <CSR_F_500M )) +else if (clk_rate <CSR_F_500M ) value =STMMAC_CSR_300_500M ; -else if ((clk_rate >=CSR_F_500M ) && (clk_rate <CSR_F_800M )) +else if (clk_rate <CSR_F_800M ) value =STMMAC_CSR_500_800M ;if (priv->plat->flags &STMMAC_FLAG_HAS_SUN8I ) {
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 10/11] net: stmmac: mdio: remove redundant clock rate tests
Quoted 9 lines · Russell King (Oracle)
The pattern:
... if (v < A) ... else if (v >= A && v < B) ...can be simplified to:
Quoted 8 lines
... if (v < A) ... else if (v < B) ...which makes the string of ifelse more readable.
Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
PATCH v2 11/11 net: stmmac: use STMMAC_CSR_xxx definitions in platform glue
In reply to Russell King (Oracle)Use the STMMAC_CSR_xxx definitions to initialise plat->clk_csr in the platform glue drivers to make the integer values meaningful.
--- drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 5 +++-- drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c | 3 ++- drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +3 -2
@@ -566,7 +566,8 @@ static int intel_mac_finish(struct net_device *ndev,static void common_default_data (struct plat_stmmacenet_data *plat) { - plat->clk_csr =2 ;/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ +/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ + plat->clk_csr =STMMAC_CSR_20_35M ; plat->has_gmac =1 ; plat->force_sf_dma_mode =1 ;
@@ -613,7 +614,7 @@ static int intel_mgbe_common_data(struct pci_dev *pdev, plat->pdev = pdev; plat->phy_addr =-1 ; - plat->clk_csr =5 ; + plat->clk_csr =STMMAC_CSR_250_300M ; plat->has_gmac =0 ; plat->has_gmac4 =1 ; plat->force_sf_dma_mode =0 ;
drivers/net/ethernet/stmicro/stmmac/dwmac-loongson.c +2 -1
@@ -90,7 +90,8 @@ static void loongson_default_data(struct pci_dev *pdev,/* Get bus_id, this can be overwritten later */ plat->bus_id =pci_dev_id (pdev); - plat->clk_csr =2 ;/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ +/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ + plat->clk_csr =STMMAC_CSR_20_35M ; plat->has_gmac =1 ; plat->force_sf_dma_mode =1 ;
drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c +3 -2
@@ -21,7 +21,8 @@ struct stmmac_pci_info {static void common_default_data (struct plat_stmmacenet_data *plat) { - plat->clk_csr =2 ;/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ +/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ + plat->clk_csr =STMMAC_CSR_20_35M ; plat->has_gmac =1 ; plat->force_sf_dma_mode =1 ;
@@ -74,7 +75,7 @@ static int snps_gmac5_default_data(struct pci_dev *pdev, {int i; - plat->clk_csr =5 ; + plat->clk_csr =STMMAC_CSR_250_300M ; plat->has_gmac4 =1 ; plat->force_sf_dma_mode =1 ; plat->flags |=STMMAC_FLAG_TSO_EN ;
Signature · 1 line
2.47.2
Re: [PATCH net-next v2 11/11] net: stmmac: use STMMAC_CSR_xxx definitions in platform glue
Quoted 4 lines · Russell King (Oracle)
Use the
STMMAC_CSR_xxxdefinitions to initialiseplat->clk_csrin the platform glue drivers to make the integer values meaningful.Signed-off-by Russell King (Oracle) <[email protected]>
Andrew
Quoted 17 lines · Russell King (Oracle)
On Wed, Sep 03, 2025 at 01:38:57PM +0100, Russell King (Oracle) wrote:
Hi,Clean up the stmmac MDIO code:
- provide an address register formatter to avoid repeated code
- provide a common function to wait for the busy bit to clear
- pre-compute the CR field (mdio clock divider)
- move address formatter into read/write functions
- combine the read/write functions into a common accessor function
- move runtime PM handling into common accessor function
- rename register constants to better reflect manufacturer names
- movestmmac_clk_csr_set()intostmmac_mdio
- makestmmac_clk_csr_set()return the CR field value and removepriv->clk_csr
- clean upif()range tests instmmac_clk_csr_set()
- useSTMMAC_CSR_xxxdefinitions in initialisers
Quoted 2 lines
Untested on hardware; would be grateful for any testing people can do.
Picked this series on top of net-next and was able to test on the Qualcomm QCS9100 Ride R3 board with the AQR115C Phy. No issues seen with C45 MDIO operations, so:
Ayaan
Quoted 14 lines
v2: add "Return:" to patch 1 and 9
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c | 5 +- .../net/ethernet/stmicro/stmmac/dwmac-loongson.c | 3 +- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 82 ----- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 345 ++++++++++++--------- drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c | 5 +- 6 files changed, 207 insertions(+), 235 deletions(-)Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 17 lines · On Thu, 4 Sep 2025 13:10:42 +0100 you wrote:
On Wed, Sep 03, 2025 at 01:38:57PM +0100, Russell King (Oracle) wrote:
Hi,Clean up the stmmac MDIO code:
- provide an address register formatter to avoid repeated code
- provide a common function to wait for the busy bit to clear
- pre-compute the CR field (mdio clock divider)
- move address formatter into read/write functions
- combine the read/write functions into a common accessor function
- move runtime PM handling into common accessor function
- rename register constants to better reflect manufacturer names
- movestmmac_clk_csr_set()intostmmac_mdio
- makestmmac_clk_csr_set()return the CR field value and removepriv->clk_csr
- clean upif()range tests instmmac_clk_csr_set()
- useSTMMAC_CSR_xxxdefinitions in initialisers
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v2,01/11] net: stmmac: mdio: provide address register formatter
https://git.kernel.org/netdev/net-next/c/16e03235d51b - [net-next,v2,02/11] net: stmmac: mdio: provide stmmac_mdio_wait() https://git.kernel.org/netdev/net-next/c/9eb633ad1d69 - [net-next,v2,03/11] net: stmmac: mdio: provide priv->gmii_address_bus_config https://git.kernel.org/netdev/net-next/c/6717746f33ab - [net-next,v2,04/11] net: stmmac: mdio: move stmmac_mdio_format_addr() into read/write https://git.kernel.org/netdev/net-next/c/6cb3d67ad624 - [net-next,v2,05/11] net: stmmac: mdio: merge stmmac_mdio_read() and stmmac_mdio_write() https://git.kernel.org/netdev/net-next/c/9b0ed33a4256 - [net-next,v2,06/11] net: stmmac: mdio: move runtime PM into stmmac_mdio_access() https://git.kernel.org/netdev/net-next/c/9b88194a3b68 - [net-next,v2,07/11] net: stmmac: mdio: improve mdio register field definitions https://git.kernel.org/netdev/net-next/c/3581acbb789a - [net-next,v2,08/11] net: stmmac: mdio: move initialisation of priv->clk_csr to stmmac_mdio https://git.kernel.org/netdev/net-next/c/661a868937a1 - [net-next,v2,09/11] net: stmmac: mdio: return clk_csr value from stmmac_clk_csr_set() https://git.kernel.org/netdev/net-next/c/231e2b016fb2 - [net-next,v2,10/11] net: stmmac: mdio: remove redundant clock rate tests https://git.kernel.org/netdev/net-next/c/78c91bec8fb9 - [net-next,v2,11/11] net: stmmac: use STMMAC_CSR_xxx definitions in platform glue https://git.kernel.org/netdev/net-next/c/fc8f62c827ea
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html