Skip to content

Commit

Permalink
net: phy: fix save wrong speed and duplex problem if autoneg is on
Browse files Browse the repository at this point in the history
[ Upstream commit d9032db ]

If phy uses generic driver and autoneg is on, enter command
"ethtool -s eth0 speed 50" will not change phy speed actually, but
command "ethtool eth0" shows speed is 50Mb/s because phydev->speed
has been set to 50 and no update later.

And duplex setting has same problem too.

However, if autoneg is on, phy only changes speed and duplex according to
phydev->advertising, but not phydev->speed and phydev->duplex. So in this
case, phydev->speed and phydev->duplex don't need to be set in function
phy_ethtool_ksettings_set() if autoneg is on.

Fixes: 51e2a38 ("PHY: Avoid unnecessary aneg restarts")
Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com>
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Guangbin Huang authored and gregkh committed Mar 17, 2021
1 parent aea71e9 commit 2e24fd3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/net/phy/phy.c
Expand Up @@ -345,15 +345,16 @@ int phy_ethtool_ksettings_set(struct phy_device *phydev,

phydev->autoneg = autoneg;

phydev->speed = speed;
if (autoneg == AUTONEG_DISABLE) {
phydev->speed = speed;
phydev->duplex = duplex;
}

linkmode_copy(phydev->advertising, advertising);

linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
phydev->advertising, autoneg == AUTONEG_ENABLE);

phydev->duplex = duplex;

phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl;

/* Restart the PHY */
Expand Down

0 comments on commit 2e24fd3

Please sign in to comment.