[PATCH net-next v3 06/11] net: phy: add error checks in mmd_phy_indirect()

From: Michael Walle
Date: Wed Jul 12 2023 - 11:08:38 EST


Add missing error checks in mmd_phy_indirect(). The error checks need to
be disabled to retain the current behavior in phy_read_mmd() and
phy_write_mmd(). Therefore, add a new parameter to enable the error
checks.

This is a preparation patch to introduce a new C45-over-C22 access
method which will make use of the new error checking.

Regarding the legacy handling, Russell states:

| The reason for that goes back to commit a59a4d192166 ("phy: add the
| EEE support and the way to access to the MMD registers.")
|
| and to maintain compatibility with that; if we start checking for
| errors now, we might trigger a kernel regression sadly.

Signed-off-by: Michael Walle <mwalle@xxxxxxxxxx>
---
v3:
- don't export it anymore, instead there will be a dedicated helper
---
drivers/net/phy/phy-core.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index 686a57d56885..598023610ee5 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -524,18 +524,26 @@ int phy_speed_down_core(struct phy_device *phydev)
return 0;
}

-static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
- u16 regnum)
+static int mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad,
+ u16 regnum, bool check_rc)
{
+ int ret;
+
/* Write the desired MMD Devad */
- __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
+ ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL, devad);
+ if (check_rc && ret)
+ return ret;

/* Write the desired MMD register address */
- __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
+ ret = __mdiobus_write(bus, phy_addr, MII_MMD_DATA, regnum);
+ if (check_rc && ret)
+ return ret;

/* Select the Function : DATA with no post increment */
- __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
- devad | MII_MMD_CTRL_NOINCR);
+ ret = __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
+ devad | MII_MMD_CTRL_NOINCR);
+
+ return check_rc ? ret : 0;
}

/**
@@ -563,7 +571,7 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
struct mii_bus *bus = phydev->mdio.bus;
int phy_addr = phydev->mdio.addr;

- mmd_phy_indirect(bus, phy_addr, devad, regnum);
+ mmd_phy_indirect(bus, phy_addr, devad, regnum, false);

/* Read the content of the MMD's selected register */
val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
@@ -619,7 +627,7 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
struct mii_bus *bus = phydev->mdio.bus;
int phy_addr = phydev->mdio.addr;

- mmd_phy_indirect(bus, phy_addr, devad, regnum);
+ mmd_phy_indirect(bus, phy_addr, devad, regnum, false);

/* Write the data into MMD's selected register */
__mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);

--
2.39.2