From: Marek Behún <kabel@kernel.org> Date: 2021-11-23 15:44:09
With information from me and my nagging, Russell has produced two fixes
for phylink, which add code that triggers another phylink_resolve() from
phylink_resolve(), if certain conditions are met:
interface is being changed
or
link is down and previous link was up
These are needed because sometimes the PCS callbacks may provide stale
values if link / speed / ...
Changes from v1:
- set Russell as author of the commits, since I only wrote the commit
messages
- updated the second patch according to Russell's comment (and updated
commit message)
Russell King (Oracle) (2):
net: phylink: Force link down and retrigger resolve on interface
change
net: phylink: Force retrigger in case of latched link-fail indicator
drivers/net/phy/phylink.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
--
2.32.0
From: Marek Behún <kabel@kernel.org> Date: 2021-11-23 15:44:11
From: "Russell King (Oracle)" <redacted>
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: 9525ae83959b ("phylink: add phylink infrastructure")
Signed-off-by: Russell King (Oracle) <redacted>
Signed-off-by: Marek Behún <kabel@kernel.org>
---
drivers/net/phy/phylink.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
@@ -1000,6 +1002,15 @@ static void phylink_resolve(struct work_struct *w)/* Only update if the PHY link is up */if(pl->phydev&&pl->phy_state.link){+/* If the interface has changed, force a+*linkdowneventifthelinkisn'talready+*down,andre-resolve.+*/+if(link_state.interface!=+pl->phy_state.interface){+retrigger=true;+link_state.link=false;+}link_state.interface=pl->phy_state.interface;/* If we have a PHY, we need to update with
From: Marek Behún <kabel@kernel.org> Date: 2021-11-23 15:44:13
From: "Russell King (Oracle)" <redacted>
On mv88e6xxx 1G/2.5G PCS, the SerDes register 4.2001.2 has the following
description:
This register bit indicates when link was lost since the last
read. For the current link status, read this register
back-to-back.
Thus to get current link state, we need to read the register twice.
But doing that in the link change interrupt handler would lead to
potentially ignoring link down events, which we really want to avoid.
Thus this needs to be solved in phylink's resolve, by retriggering
another resolve in the event when PCS reports link down and previous
link was up, and by re-reading PCS state if the previous link was down.
The wrong value is read when phylink requests change from sgmii to
2500base-x mode, and link won't come up. This fixes the bug.
Fixes: 9525ae83959b ("phylink: add phylink infrastructure")
Signed-off-by: Russell King (Oracle) <redacted>
Signed-off-by: Marek Behún <kabel@kernel.org>
---
drivers/net/phy/phylink.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
@@ -994,6 +994,19 @@ static void phylink_resolve(struct work_struct *w)caseMLO_AN_INBAND:phylink_mac_pcs_get_state(pl,&link_state);+/* The PCS may have a latching link-fail indicator.+*Ifthelinkwasup,bringthelinkdownand+*re-triggertheresolve.Otherwise,re-readthe+*PCSstatetogetthecurrentstatusofthelink.+*/+if(!link_state.link){+if(cur_link_state)+retrigger=true;+else+phylink_mac_pcs_get_state(pl,+&link_state);+}+/* If we have a phy, the "up" state is the union of*boththePHYandtheMAC*/
Hello:
This series was applied to netdev/net.git (master)
by Jakub Kicinski [off-list ref]:
On Tue, 23 Nov 2021 16:44:01 +0100 you wrote:
With information from me and my nagging, Russell has produced two fixes
for phylink, which add code that triggers another phylink_resolve() from
phylink_resolve(), if certain conditions are met:
interface is being changed
or
link is down and previous link was up
These are needed because sometimes the PCS callbacks may provide stale
values if link / speed / ...
[...]