Skip to content
Commit cac4cf36 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Xiaolei Wang
Browse files

net: phylink: fix in-band autoneg getting disabled with Generic PHY driver



commit 9e552b42a2a63adb2c2be409e74659e4a6152a39 from
https://source.codeaurora.org/external/imx/linux-imx

PHY devices without a specific driver have a NULL phydev->drv up until
the point when phy_attach_direct() runs and manually binds the genphy
driver to it.

The downstream phy_validate_inband_autoneg() function returns -EIO for
the case where phydev->drv is NULL, but none of the callers checks for
negative error codes.

One caller of phy_validate_inband_autoneg() is phylink_fixup_inband_aneg(),
which is in fact called from phylink_connect_phy() and
phylink_fwnode_connect_phy(). Lower in each of these functions is a
(direct or indirect) call to phy_attach_direct(), so we always have a
NULL phydev->drv pointer at that point.

The effect of phy_validate_inband_autoneg() returning -EIO is as
follows:

- The first check, ret == PHY_INBAND_ANEG_UNKNOWN, does not pass.
  This allows the code flow to unexpectedly continue.
- The second check, phylink_autoneg_inband(mode) &&
  !(ret & PHY_INBAND_ANEG_ON), passes. This is because -EIO (-5) does
  not have bit PHY_INBAND_ANEG_ON (2) set.
- As a result of passing the second check, phylink prints, and does,
  the following:

Requested in-band autoneg but driver does not support this, disabling it.

with the end result that the link breaks, if the PHY was pre-configured
by U-Boot to enable in-band autoneg, and in-band autoneg is described in
the device tree.

The expected behavior was for phy_validate_inband_autoneg() to return
PHY_INBAND_ANEG_UNKNOWN (because it _is_ unknown when using the Generic
PHY driver), and for phylink to leave the setting alone and hope for the
best.

We repair the problem by eliminating the possibility of
phy_validate_inband_autoneg() to return negative error codes, since they
have not proven to be useful, it is awkward to check for them, and they
introduce subtle bugs too.

This patch should be squashed into the blamed commit below if the series
is ever to be resent upstream.

Fixes: 67a4afb856c8 ("net: phylink: introduce a generic method for querying PHY in-band autoneg capability")
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarXiaolei Wang <xiaolei.wang@windriver.com>
parent daa9cc67
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment