Skip to content

Commit

Permalink
net: phy: improve genphy_c45_read_link
Browse files Browse the repository at this point in the history
Let's make genphy_c45_read_link behave the same as genphy_update_link
and set phydev->link in the function directly. This allows to simplify
the callers. In addition don't check further devices once we detect
that at least one device reports link as down.

v2:
- remove an unused variable

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 7, 2019
1 parent 7d8e249 commit a6e11f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 0 additions & 2 deletions drivers/net/phy/marvell10g.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,6 @@ static int mv3310_read_status(struct phy_device *phydev)
if (val < 0)
return val;

phydev->link = val > 0 ? 1 : 0;

val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
if (val < 0)
return val;
Expand Down
15 changes: 6 additions & 9 deletions drivers/net/phy/phy-c45.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ EXPORT_SYMBOL_GPL(genphy_c45_aneg_done);
* @mmd_mask: MMDs to read status from
*
* Read the link status from the specified MMDs, and if they all indicate
* that the link is up, return positive. If an error is encountered,
* that the link is up, set phydev->link to 1. If an error is encountered,
* a negative errno will be returned, otherwise zero.
*/
int genphy_c45_read_link(struct phy_device *phydev, u32 mmd_mask)
{
int val, devad;
bool link = true;

while (mmd_mask) {
while (mmd_mask && link) {
devad = __ffs(mmd_mask);
mmd_mask &= ~BIT(devad);

Expand All @@ -145,7 +145,9 @@ int genphy_c45_read_link(struct phy_device *phydev, u32 mmd_mask)
link = false;
}

return link;
phydev->link = link;

return 0;
}
EXPORT_SYMBOL_GPL(genphy_c45_read_link);

Expand Down Expand Up @@ -265,7 +267,6 @@ EXPORT_SYMBOL_GPL(gen10g_config_aneg);
int gen10g_read_status(struct phy_device *phydev)
{
u32 mmd_mask = phydev->c45_ids.devices_in_package;
int ret;

/* For now just lie and say it's 10G all the time */
phydev->speed = SPEED_10000;
Expand All @@ -274,11 +275,7 @@ int gen10g_read_status(struct phy_device *phydev)
/* Avoid reading the vendor MMDs */
mmd_mask &= ~(BIT(MDIO_MMD_VEND1) | BIT(MDIO_MMD_VEND2));

ret = genphy_c45_read_link(phydev, mmd_mask);

phydev->link = ret > 0 ? 1 : 0;

return 0;
return genphy_c45_read_link(phydev, mmd_mask);
}
EXPORT_SYMBOL_GPL(gen10g_read_status);

Expand Down

0 comments on commit a6e11f6

Please sign in to comment.