This change allows phytool [1] and similar tools to read and write C45 phy
registers from userspace.
This is useful for debugging and for porting vendor phy diagnostics tools.
[1] https://github.com/wkz/phytool
Signed-off-by: Nikita Yushchenko <[email protected]>
---
drivers/net/phy/phy.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e8885429293a..3d991958bde0 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -407,6 +407,7 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
struct mii_ioctl_data *mii_data = if_mii(ifr);
u16 val = mii_data->val_in;
bool change_autoneg = false;
+ int ret;
switch (cmd) {
case SIOCGMIIPHY:
@@ -414,12 +415,28 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
/* fall through */
case SIOCGMIIREG:
+ if (mdio_phy_id_is_c45(mii_data->phy_id)) {
+ ret = phy_read_mmd(phydev,
+ mdio_phy_id_devad(mii_data->phy_id),
+ mii_data->reg_num);
+ if (ret < 0)
+ return ret;
+ mii_data->val_out = ret;
+ return 0;
+ }
mii_data->val_out = mdiobus_read(phydev->mdio.bus,
mii_data->phy_id,
mii_data->reg_num);
return 0;
case SIOCSMIIREG:
+ if (mdio_phy_id_is_c45(mii_data->phy_id)) {
+ ret = phy_write_mmd(phydev,
+ mdio_phy_id_devad(mii_data->phy_id),
+ mii_data->reg_num,
+ mii_data->val_in);
+ return ret;
+ }
if (mii_data->phy_id == phydev->mdio.addr) {
switch (mii_data->reg_num) {
case MII_BMCR:
--
2.11.0
On Fri, May 31, 2019 at 10:47:27AM +0300, Nikita Yushchenko wrote:
> This change allows phytool [1] and similar tools to read and write C45 phy
> registers from userspace.
>
> This is useful for debugging and for porting vendor phy diagnostics tools.
>
> [1] https://github.com/wkz/phytool
Hi Nikita
Russell King submitted a similar patch a couple of days ago.
https://patchwork.ozlabs.org/patch/1102091/
Since he was first, we should probably take his, once he respins the
series.
Florian: Could you take a second look at
[net-next,1/4] net: phylink: support for link gpio interrupt
https://patchwork.ozlabs.org/patch/1102090/
Everything else in that patchset is good to go.
Thanks
Andrew