net: phylink: explicitly configure in-band autoneg for PHYs that support it
authorVladimir Oltean <vladimir.oltean@nxp.com>
Fri, 12 Feb 2021 17:01:52 +0000 (19:01 +0200)
committerVladimir Oltean <olteanv@gmail.com>
Tue, 8 Jun 2021 10:23:58 +0000 (13:23 +0300)
Currently Linux has no control over whether a MAC-to-PHY interface uses
in-band signaling or not, even though phylink has the
managed = "in-band-status";
property which denotes that the MAC expects in-band signaling to be used.

The problem is really that if the in-band signaling is configurable in
both the PHY and the MAC, there is a risk that they are out of sync
unless phylink manages them both. Most if not all in-band autoneg state
machines follow IEEE 802.3 clause 37, which means that they will not
change the operating mode of the SERDES lane from control to data mode
unless in-band AN completed successfully. Therefore traffic will not
work.

It is particularly unpleasant that currently, we assume that PHYs which
have configurable in-band AN come pre-configured from a prior boot stage
such as U-Boot, because once the bootloader changes, all bets are off.

Let's introduce a new PHY driver method for configuring in-band autoneg,
and make phylink be its first user. The main PHY library does not call
phy_config_inband_autoneg, because it does not know what to configure it
to. Presumably, non-phylink drivers can also call phy_config_inband_autoneg
individually.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
drivers/net/phy/phy.c
drivers/net/phy/phylink.c
include/linux/phy.h

index 28ddaad..7da6bdb 100644 (file)
@@ -766,6 +766,18 @@ static int phy_check_link_status(struct phy_device *phydev)
        return 0;
 }
 
+int phy_config_inband_aneg(struct phy_device *phydev, bool enabled)
+{
+       if (!phydev->drv)
+               return -EIO;
+
+       if (!phydev->drv->config_inband_aneg)
+               return -EOPNOTSUPP;
+
+       return phydev->drv->config_inband_aneg(phydev, enabled);
+}
+EXPORT_SYMBOL(phy_config_inband_aneg);
+
 /**
  * phy_start_aneg - start auto-negotiation for this PHY device
  * @phydev: the phy_device struct
index 6072e87..0cd9463 100644 (file)
@@ -978,6 +978,14 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
                return ret;
        }
 
+       ret = phy_config_inband_aneg(phy,
+                                    (pl->cur_link_an_mode == MLO_AN_INBAND));
+       if (ret && ret != -EOPNOTSUPP) {
+               phylink_warn(pl, "failed to configure PHY in-band autoneg: %d\n",
+                            ret);
+               return ret;
+       }
+
        phy->phylink = pl;
        phy->phy_link_change = phylink_phy_change;
 
index ce888ed..152a47a 100644 (file)
@@ -742,6 +742,13 @@ struct phy_driver {
         */
        int (*config_aneg)(struct phy_device *phydev);
 
+       /**
+        * @config_inband_aneg: Enable or disable in-band auto-negotiation for
+        * the system-side interface if the PHY operates in a mode that
+        * requires it: (Q)SGMII, USXGMII, 1000Base-X, etc.
+        */
+       int (*config_inband_aneg)(struct phy_device *phydev, bool enabled);
+
        /** @aneg_done: Determines the auto negotiation result */
        int (*aneg_done)(struct phy_device *phydev);
 
@@ -1396,6 +1403,7 @@ void phy_detach(struct phy_device *phydev);
 void phy_start(struct phy_device *phydev);
 void phy_stop(struct phy_device *phydev);
 int phy_start_aneg(struct phy_device *phydev);
+int phy_config_inband_aneg(struct phy_device *phydev, bool enabled);
 int phy_aneg_done(struct phy_device *phydev);
 int phy_speed_down(struct phy_device *phydev, bool sync);
 int phy_speed_up(struct phy_device *phydev);