netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: netdev <netdev@vger.kernel.org>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <rmk+kernel@armlinux.org.uk>,
	Oleksij Rempel <o.rempel@pengutronix.de>,
	Andrew Lunn <andrew@lunn.ch>
Subject: [RFC/RFT 01/23] net: phy: Add phydev->eee_active to simplify adjust link callbacks
Date: Mon, 27 Mar 2023 19:01:39 +0200	[thread overview]
Message-ID: <20230327170201.2036708-2-andrew@lunn.ch> (raw)
In-Reply-To: <20230327170201.2036708-1-andrew@lunn.ch>

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->eee_active 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.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
v2 Check for errors from genphy_c45_eee_is_active
---
 drivers/net/phy/phy.c | 7 +++++++
 include/linux/phy.h   | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 0c0df38cd1ab..68e1ce942dd6 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -928,9 +928,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->eee_active = false;
+		else
+			phydev->eee_active = err;
 		phy_link_up(phydev);
 	} else if (!phydev->link && phydev->state != PHY_NOLINK) {
 		phydev->state = PHY_NOLINK;
+		phydev->eee_active = false;
 		phy_link_down(phydev);
 	}
 
diff --git a/include/linux/phy.h b/include/linux/phy.h
index fefd5091bc24..5cc2dcb17eb0 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -577,6 +577,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
+ * @eee_active: EEE is active for the current link mode
  * @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
@@ -691,6 +692,7 @@ struct phy_device {
 
 	/* Energy efficient ethernet modes which should be prohibited */
 	u32 eee_broken_modes;
+	bool eee_active;
 
 #ifdef CONFIG_LED_TRIGGER_PHY
 	struct phy_led_trigger *phy_led_triggers;
-- 
2.39.2


  reply	other threads:[~2023-03-27 17:03 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-27 17:01 [RFC/RFT 00/23] net: ethernet: Rework EEE Andrew Lunn
2023-03-27 17:01 ` Andrew Lunn [this message]
2023-03-27 17:54   ` [RFC/RFT 01/23] net: phy: Add phydev->eee_active to simplify adjust link callbacks Russell King (Oracle)
2023-03-27 17:01 ` [RFC/RFT 02/23] net: phylink: Plumb eee_active in mac_link_up call Andrew Lunn
2023-03-27 17:57   ` Russell King (Oracle)
2023-03-27 21:53   ` Russell King (Oracle)
2023-03-27 22:45     ` Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 03/23] net: phy: Add helper to set EEE Clock stop enable bit Andrew Lunn
2023-03-27 17:58   ` Russell King (Oracle)
2023-03-28  5:03   ` Oleksij Rempel
2023-03-28  5:13     ` Oleksij Rempel
2023-03-28 12:09     ` Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 04/23] net: phy: Keep track of EEE tx_lpi_enabled Andrew Lunn
2023-03-27 17:58   ` Russell King (Oracle)
2023-03-27 17:01 ` [RFC/RFT 05/23] net: phy: Immediately call adjust_link if only tx_lpi_enabled changes Andrew Lunn
2023-03-27 18:02   ` Russell King (Oracle)
2023-03-27 22:13     ` Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 06/23] net: marvell: mvneta: Simplify EEE configuration Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 07/23] net: stmmac: Drop usage of phy_init_eee() Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 08/23] net: stmmac: Simplify ethtool get eee Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 09/23] net: lan743x: Fixup EEE Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 10/23] net: fec: Move fec_enet_eee_mode_set() and helper earlier Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 11/23] net: FEC: Fixup EEE Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 12/23] net: genet: " Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 13/23] net: sxgdb: " Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 14/23] net: dsa: mt7530: Swap to using phydev->eee_active Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 15/23] net: dsa: b53: " Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 16/23] net: phylink: Remove unused phylink_init_eee() Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 17/23] net: phy: remove unused phy_init_eee() Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 18/23] net: usb: lan78xx: Fixup EEE Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 19/23] net: phy: Add phy_support_eee() indicating MAC support EEE Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 20/23] net: phylink: Add MAC_EEE to mac_capabilites Andrew Lunn
2023-03-27 21:59   ` Russell King (Oracle)
2023-03-27 22:15     ` Andrew Lunn
2023-03-27 17:01 ` [RFC/RFT 21/23] net: phylink: Extend mac_capabilities in MAC drivers which support EEE Andrew Lunn
2023-03-27 17:02 ` [RFC/RFT 22/23] net: phylib: call phy_support_eee() " Andrew Lunn
2023-03-27 17:02 ` [RFC/RFT 23/23] net: phy: Disable EEE advertisement by default Andrew Lunn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230327170201.2036708-2-andrew@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=rmk+kernel@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).