]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: phy: Add phydev->enable_tx_lpi to simplify adjust link callbacks
authorAndrew Lunn <andrew@lunn.ch>
Sat, 2 Mar 2024 19:53:01 +0000 (20:53 +0100)
committerJakub Kicinski <kuba@kernel.org>
Wed, 6 Mar 2024 03:21:17 +0000 (19:21 -0800)
MAC drivers which support EEE need to know the results of the EEE
auto-neg in order to program the hardware to perform EEE or not.  The
oddly named phy_init_eee() can be used to determine this, it returns 0
if EEE should be used, or a negative error code,
e.g. -EOPPROTONOTSUPPORT if the PHY does not support EEE or negotiate
resulted in it not being used.

However, many MAC drivers get this wrong. Add phydev->enable_tx_lpi
which indicates the result of the autoneg for EEE, including if EEE is
administratively disabled with ethtool. The MAC driver can then access
this in the same way as link speed and duplex in the adjust link
callback. If enable_tx_lpi is true, the MAC should send low power
indications and does not need to consider anything else with respect
to EEE.

Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20240302195306.3207716-3-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phy.c
include/linux/phy.h

index 14224e06d69faabfec2d34d22286ff9d8c0c56c2..2bc0a7d51c63f17116f47300b808c0599b8148d1 100644 (file)
@@ -983,9 +983,16 @@ static int phy_check_link_status(struct phy_device *phydev)
        if (phydev->link && phydev->state != PHY_RUNNING) {
                phy_check_downshift(phydev);
                phydev->state = PHY_RUNNING;
+               err = genphy_c45_eee_is_active(phydev,
+                                              NULL, NULL, NULL);
+               if (err < 0)
+                       phydev->enable_tx_lpi = false;
+               else
+                       phydev->enable_tx_lpi = !!err;
                phy_link_up(phydev);
        } else if (!phydev->link && phydev->state != PHY_NOLINK) {
                phydev->state = PHY_NOLINK;
+               phydev->enable_tx_lpi = false;
                phy_link_down(phydev);
        }
 
index e3ab2c347a598b661a6183473afa92b0381ded13..a880f6d7170eaa295a49bbaa43bf23f5c3ab9db7 100644 (file)
@@ -594,6 +594,7 @@ struct macsec_ops;
  * @supported_eee: supported PHY EEE linkmodes
  * @advertising_eee: Currently advertised EEE linkmodes
  * @eee_enabled: Flag indicating whether the EEE feature is enabled
+ * @enable_tx_lpi: When True, MAC should transmit LPI to PHY
  * @lp_advertising: Current link partner advertised linkmodes
  * @host_interfaces: PHY interface modes supported by host
  * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited
@@ -713,6 +714,7 @@ struct phy_device {
 
        /* Energy efficient ethernet modes which should be prohibited */
        u32 eee_broken_modes;
+       bool enable_tx_lpi;
 
 #ifdef CONFIG_LED_TRIGGER_PHY
        struct phy_led_trigger *phy_led_triggers;