Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: phy: fix save wrong speed and duplex problem if autoneg is on

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: 51e2a3846eab ("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>

authored by

Guangbin Huang and committed by
David S. Miller
d9032dba 4372339e

+4 -2
+4 -2
drivers/net/phy/phy.c
··· 276 276 277 277 phydev->autoneg = autoneg; 278 278 279 - phydev->speed = speed; 279 + if (autoneg == AUTONEG_DISABLE) { 280 + phydev->speed = speed; 281 + phydev->duplex = duplex; 282 + } 280 283 281 284 linkmode_copy(phydev->advertising, advertising); 282 285 283 286 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, 284 287 phydev->advertising, autoneg == AUTONEG_ENABLE); 285 288 286 - phydev->duplex = duplex; 287 289 phydev->master_slave_set = cmd->base.master_slave_cfg; 288 290 phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl; 289 291