Skip to content

Commit

Permalink
net: phy: add genphy_c45_check_and_restart_aneg
Browse files Browse the repository at this point in the history
This function will be used by config_aneg callback implementations of
PHY drivers and allows to reduce boilerplate code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Heiner Kallweit authored and David S. Miller committed Feb 21, 2019
1 parent cc429d5 commit 1af9f16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions drivers/net/phy/phy-c45.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,36 @@ int genphy_c45_restart_aneg(struct phy_device *phydev)
}
EXPORT_SYMBOL_GPL(genphy_c45_restart_aneg);

/**
* genphy_c45_check_and_restart_aneg - Enable and restart auto-negotiation
* @phydev: target phy_device struct
* @restart: whether aneg restart is requested
*
* This assumes that the auto-negotiation MMD is present.
*
* Check, and restart auto-negotiation if needed.
*/
int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart)
{
int ret = 0;

if (!restart) {
/* Configure and restart aneg if it wasn't set before */
ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1);
if (ret < 0)
return ret;

if (!(ret & MDIO_AN_CTRL1_ENABLE))
restart = true;
}

if (restart)
ret = genphy_c45_restart_aneg(phydev);

return ret;
}
EXPORT_SYMBOL_GPL(genphy_c45_check_and_restart_aneg);

/**
* genphy_c45_aneg_done - return auto-negotiation complete status
* @phydev: target phy_device struct
Expand Down
1 change: 1 addition & 0 deletions include/linux/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ int genphy_write_mmd_unsupported(struct phy_device *phdev, int devnum,

/* Clause 45 PHY */
int genphy_c45_restart_aneg(struct phy_device *phydev);
int genphy_c45_check_and_restart_aneg(struct phy_device *phydev, bool restart);
int genphy_c45_aneg_done(struct phy_device *phydev);
int genphy_c45_read_link(struct phy_device *phydev);
int genphy_c45_read_lpa(struct phy_device *phydev);
Expand Down

0 comments on commit 1af9f16

Please sign in to comment.