lkml.org 
[lkml]   [2022]   [Mar]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RFC net-next v2 3/8] net: phy: add error checks in __phy_mmd_indirect() and export it
Date
Add missing error checks and export it so it can be reused. Rename the
function to have the common "phy_" prefix.

Signed-off-by: Michael Walle <michael@walle.cc>
---
drivers/net/phy/phy-core.c | 34 ++++++++++++++++++++++++++--------
include/linux/phy.h | 2 ++
2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index 2001f3329133..dd9b6b64757d 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -437,19 +437,37 @@ 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)
+/**
+ * __phy_mmd_indirect - prepare an indirect C45 register access
+ *
+ * @bus: the target MII bus
+ * @phy_addr: PHY address on the MII bus
+ * @devad: The target MMD (0..31)
+ * @regnum: The target register on the MMD (0..65535)
+ *
+ * Prepare an indirect C45 read or write transfer using the MII_MMD_CTRL and
+ * MII_MMD_DATA registers in C22 space.
+ */
+int __phy_mmd_indirect(struct mii_bus *bus, int phy_addr, int devad,
+ u16 regnum)
{
+ 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 (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 (ret)
+ return ret;

/* Select the Function : DATA with no post increment */
- __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
- devad | MII_MMD_CTRL_NOINCR);
+ return __mdiobus_write(bus, phy_addr, MII_MMD_CTRL,
+ devad | MII_MMD_CTRL_NOINCR);
}
+EXPORT_SYMBOL(__phy_mmd_indirect);

/**
* __phy_read_mmd - Convenience function for reading a register
@@ -476,7 +494,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);
+ __phy_mmd_indirect(bus, phy_addr, devad, regnum);

/* Read the content of the MMD's selected register */
val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
@@ -532,7 +550,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);
+ __phy_mmd_indirect(bus, phy_addr, devad, regnum);

/* Write the data into MMD's selected register */
__mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 36ca2b5c2253..c81c209d4abd 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1110,6 +1110,8 @@ int phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum);
__ret; \
})

+int __phy_mmd_indirect(struct mii_bus *bus, int phy_addr, int devad,
+ u16 regnum);
/*
* __phy_read_mmd - Convenience function for reading a register
* from an MMD on a given PHY.
--
2.30.2
\
 
 \ /
  Last update: 2022-03-25 22:40    [W:2.199 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site