* [PATCH v2 net-next] net: phylink: improve phylink_sfp_config_phy() error message with empty supported
@ 2024-12-11 17:25 Vladimir Oltean
2024-12-11 18:03 ` Russell King (Oracle)
0 siblings, 1 reply; 3+ messages in thread
From: Vladimir Oltean @ 2024-12-11 17:25 UTC (permalink / raw)
To: netdev
Cc: Russell King, Andrew Lunn, Heiner Kallweit, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
It seems that phylink does not support driving PHYs in SFP modules using
the Generic PHY or Generic Clause 45 PHY driver. I've come to this
conclusion after analyzing these facts:
- sfp_sm_probe_phy(), who is our caller here, first calls
phy_device_register() and then sfp_add_phy() -> ... ->
phylink_sfp_connect_phy().
- phydev->supported is populated by phy_probe()
- phy_probe() is usually called synchronously from phy_device_register()
via phy_bus_match(), if a precise device driver is found for the PHY.
In that case, phydev->supported has a good chance of being set to a
non-zero mask.
- There is an exceptional case for the PHYs for which phy_bus_match()
didn't find a driver. Those devices sit for a while without a driver,
then phy_attach_direct() force-binds the genphy_c45_driver or
genphy_driver to them. Again, this triggers phy_probe() and renders
a good chance of phydev->supported being populated, assuming
compatibility with genphy_read_abilities() or
genphy_c45_pma_read_abilities().
- phylink_sfp_config_phy() does not support the exceptional case of
retrieving phydev->supported from the Generic PHY driver, due to its
code flow. It expects the phydev->supported mask to already be
non-empty, because it first calls phylink_validate() on it, and only
calls phylink_attach_phy() if that succeeds. Thus, phylink_attach_phy()
-> phy_attach_direct() has no chance of running.
It is not my wish to change the state of affairs by altering the code
flow, but merely to document the limitation rather than have the current
unspecific error:
[ 61.800079] mv88e6085 d0032004.mdio-mii:12 sfp: validation with support 00,00000000,00000000,00000000 failed: -EINVAL
[ 61.820743] sfp sfp: sfp_add_phy failed: -EINVAL
On the premise that an empty phydev->supported is going to make
phylink_validate() fail anyway, it would be more informative to single
out that case, undercut the phylink_validate() call, and print a more
specific message:
[ 33.468000] mv88e6085 d0032004.mdio-mii:12 sfp: PHY i2c:sfp:16 (id 0x01410cc2) supports no link modes. Maybe its specific PHY driver not loaded?
[ 33.488187] mv88e6085 d0032004.mdio-mii:12 sfp: Common drivers for PHYs on SFP modules are CONFIG_BCM84881_PHY and CONFIG_MARVELL_PHY.
[ 33.518621] sfp sfp: sfp_add_phy failed: -EINVAL
Of course, there may be other reasons due to which phydev->supported is
empty, thus the use of the word "maybe", but I think the lack of a
driver would be the most common.
Link: https://lore.kernel.org/netdev/20241113144229.3ff4bgsalvj7spb7@skbuf/
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2: add one more informational line containing common Kconfig
options, as per review feedback.
Link to v1:
https://lore.kernel.org/netdev/20241114165348.2445021-1-vladimir.oltean@nxp.com/
drivers/net/phy/phylink.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 95fbc363f9a6..b9dee09f4cfc 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -3436,6 +3436,12 @@ static int phylink_sfp_config_phy(struct phylink *pl, struct phy_device *phy)
int ret;
linkmode_copy(support, phy->supported);
+ if (linkmode_empty(support)) {
+ phylink_err(pl, "PHY %s (id 0x%.8lx) supports no link modes. Maybe its specific PHY driver not loaded?\n",
+ phydev_name(phy), (unsigned long)phy->phy_id);
+ phylink_err(pl, "Common drivers for PHYs on SFP modules are CONFIG_BCM84881_PHY and CONFIG_MARVELL_PHY.\n");
+ return -EINVAL;
+ }
memset(&config, 0, sizeof(config));
linkmode_copy(config.advertising, phy->advertising);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net-next] net: phylink: improve phylink_sfp_config_phy() error message with empty supported
2024-12-11 17:25 [PATCH v2 net-next] net: phylink: improve phylink_sfp_config_phy() error message with empty supported Vladimir Oltean
@ 2024-12-11 18:03 ` Russell King (Oracle)
2024-12-11 21:12 ` Vladimir Oltean
0 siblings, 1 reply; 3+ messages in thread
From: Russell King (Oracle) @ 2024-12-11 18:03 UTC (permalink / raw)
To: Vladimir Oltean
Cc: netdev, Andrew Lunn, Heiner Kallweit, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Wed, Dec 11, 2024 at 07:25:36PM +0200, Vladimir Oltean wrote:
> It seems that phylink does not support driving PHYs in SFP modules using
> the Generic PHY or Generic Clause 45 PHY driver. I've come to this
> conclusion after analyzing these facts:
>
> - sfp_sm_probe_phy(), who is our caller here, first calls
> phy_device_register() and then sfp_add_phy() -> ... ->
> phylink_sfp_connect_phy().
>
> - phydev->supported is populated by phy_probe()
>
> - phy_probe() is usually called synchronously from phy_device_register()
> via phy_bus_match(), if a precise device driver is found for the PHY.
> In that case, phydev->supported has a good chance of being set to a
> non-zero mask.
>
> - There is an exceptional case for the PHYs for which phy_bus_match()
> didn't find a driver. Those devices sit for a while without a driver,
> then phy_attach_direct() force-binds the genphy_c45_driver or
> genphy_driver to them. Again, this triggers phy_probe() and renders
> a good chance of phydev->supported being populated, assuming
> compatibility with genphy_read_abilities() or
> genphy_c45_pma_read_abilities().
>
> - phylink_sfp_config_phy() does not support the exceptional case of
> retrieving phydev->supported from the Generic PHY driver, due to its
> code flow. It expects the phydev->supported mask to already be
> non-empty, because it first calls phylink_validate() on it, and only
> calls phylink_attach_phy() if that succeeds. Thus, phylink_attach_phy()
> -> phy_attach_direct() has no chance of running.
>
> It is not my wish to change the state of affairs by altering the code
> flow, but merely to document the limitation rather than have the current
> unspecific error:
>
> [ 61.800079] mv88e6085 d0032004.mdio-mii:12 sfp: validation with support 00,00000000,00000000,00000000 failed: -EINVAL
> [ 61.820743] sfp sfp: sfp_add_phy failed: -EINVAL
>
> On the premise that an empty phydev->supported is going to make
> phylink_validate() fail anyway, it would be more informative to single
> out that case, undercut the phylink_validate() call, and print a more
> specific message:
>
> [ 33.468000] mv88e6085 d0032004.mdio-mii:12 sfp: PHY i2c:sfp:16 (id 0x01410cc2) supports no link modes. Maybe its specific PHY driver not loaded?
> [ 33.488187] mv88e6085 d0032004.mdio-mii:12 sfp: Common drivers for PHYs on SFP modules are CONFIG_BCM84881_PHY and CONFIG_MARVELL_PHY.
> [ 33.518621] sfp sfp: sfp_add_phy failed: -EINVAL
>
> Of course, there may be other reasons due to which phydev->supported is
> empty, thus the use of the word "maybe", but I think the lack of a
> driver would be the most common.
>
> Link: https://lore.kernel.org/netdev/20241113144229.3ff4bgsalvj7spb7@skbuf/
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
> ---
> v1->v2: add one more informational line containing common Kconfig
> options, as per review feedback.
>
> Link to v1:
> https://lore.kernel.org/netdev/20241114165348.2445021-1-vladimir.oltean@nxp.com/
>
> drivers/net/phy/phylink.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
> index 95fbc363f9a6..b9dee09f4cfc 100644
> --- a/drivers/net/phy/phylink.c
> +++ b/drivers/net/phy/phylink.c
> @@ -3436,6 +3436,12 @@ static int phylink_sfp_config_phy(struct phylink *pl, struct phy_device *phy)
> int ret;
>
> linkmode_copy(support, phy->supported);
> + if (linkmode_empty(support)) {
> + phylink_err(pl, "PHY %s (id 0x%.8lx) supports no link modes. Maybe its specific PHY driver not loaded?\n",
> + phydev_name(phy), (unsigned long)phy->phy_id);
> + phylink_err(pl, "Common drivers for PHYs on SFP modules are CONFIG_BCM84881_PHY and CONFIG_MARVELL_PHY.\n");
> + return -EINVAL;
> + }
Wouldn't checking phy->drv == NULL be a better to detect that there is
no PHY driver bound (and thus indicating that the specific driver is
not loaded?)
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net-next] net: phylink: improve phylink_sfp_config_phy() error message with empty supported
2024-12-11 18:03 ` Russell King (Oracle)
@ 2024-12-11 21:12 ` Vladimir Oltean
0 siblings, 0 replies; 3+ messages in thread
From: Vladimir Oltean @ 2024-12-11 21:12 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: netdev, Andrew Lunn, Heiner Kallweit, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
On Wed, Dec 11, 2024 at 06:03:36PM +0000, Russell King (Oracle) wrote:
> Wouldn't checking phy->drv == NULL be a better to detect that there is
> no PHY driver bound (and thus indicating that the specific driver is
> not loaded?)
Yes, I can do this, and also move the check as the first thing in
phylink_sfp_connect_phy().
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-11 21:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 17:25 [PATCH v2 net-next] net: phylink: improve phylink_sfp_config_phy() error message with empty supported Vladimir Oltean
2024-12-11 18:03 ` Russell King (Oracle)
2024-12-11 21:12 ` Vladimir Oltean
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).