Skip to content

Commit 80662f4

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: phylink: Force link down and retrigger resolve on interface change
On PHY state change the phylink_resolve() function can read stale information from the MAC and report incorrect link speed and duplex to the kernel message log. Example with a Marvell 88X3310 PHY connected to a SerDes port on Marvell 88E6393X switch: - PHY driver triggers state change due to PHY interface mode being changed from 10gbase-r to 2500base-x due to copper change in speed from 10Gbps to 2.5Gbps, but the PHY itself either hasn't yet changed its interface to the host, or the interrupt about loss of SerDes link hadn't arrived yet (there can be a delay of several milliseconds for this), so we still think that the 10gbase-r mode is up - phylink_resolve() - phylink_mac_pcs_get_state() - this fills in speed=10g link=up - interface mode is updated to 2500base-x but speed is left at 10Gbps - phylink_major_config() - interface is changed to 2500base-x - phylink_link_up() - mv88e6xxx_mac_link_up() - .port_set_speed_duplex() - speed is set to 10Gbps - reports "Link is Up - 10Gbps/Full" to dmesg Afterwards when the interrupt finally arrives for mv88e6xxx, another resolve is forced in which we get the correct speed from phylink_mac_pcs_get_state(), but since the interface is not being changed anymore, we don't call phylink_major_config() but only phylink_mac_config(), which does not set speed/duplex anymore. To fix this, we need to force the link down and trigger another resolve on PHY interface change event. Fixes: 9525ae8 ("phylink: add phylink infrastructure") Signed-off-by: Russell King (Oracle) <[email protected]> Signed-off-by: Marek Behún <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ddb826c commit 80662f4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

drivers/net/phy/phylink.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ static void phylink_resolve(struct work_struct *w)
710710
struct phylink_link_state link_state;
711711
struct net_device *ndev = pl->netdev;
712712
bool mac_config = false;
713+
bool retrigger = false;
713714
bool cur_link_state;
714715

715716
mutex_lock(&pl->state_mutex);
@@ -723,6 +724,7 @@ static void phylink_resolve(struct work_struct *w)
723724
link_state.link = false;
724725
} else if (pl->mac_link_dropped) {
725726
link_state.link = false;
727+
retrigger = true;
726728
} else {
727729
switch (pl->cur_link_an_mode) {
728730
case MLO_AN_PHY:
@@ -747,6 +749,15 @@ static void phylink_resolve(struct work_struct *w)
747749

748750
/* Only update if the PHY link is up */
749751
if (pl->phydev && pl->phy_state.link) {
752+
/* If the interface has changed, force a
753+
* link down event if the link isn't already
754+
* down, and re-resolve.
755+
*/
756+
if (link_state.interface !=
757+
pl->phy_state.interface) {
758+
retrigger = true;
759+
link_state.link = false;
760+
}
750761
link_state.interface = pl->phy_state.interface;
751762

752763
/* If we have a PHY, we need to update with
@@ -789,7 +800,7 @@ static void phylink_resolve(struct work_struct *w)
789800
else
790801
phylink_link_up(pl, link_state);
791802
}
792-
if (!link_state.link && pl->mac_link_dropped) {
803+
if (!link_state.link && retrigger) {
793804
pl->mac_link_dropped = false;
794805
queue_work(system_power_efficient_wq, &pl->resolve);
795806
}

0 commit comments

Comments
 (0)