diff mbox series

[RFC,01/18] net: phy: Add phydev->eee_active to simplify adjust link callbacks

Message ID 20230217034230.1249661-2-andrew@lunn.ch (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Rework MAC drivers EEE support | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 410 this patch: 410
netdev/cc_maintainers warning 6 maintainers not CCed: linux-mediatek@lists.infradead.org pabeni@redhat.com davem@davemloft.net kuba@kernel.org edumazet@google.com linux-arm-kernel@lists.infradead.org
netdev/build_clang success Errors and warnings before: 283 this patch: 283
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 394 this patch: 394
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Andrew Lunn Feb. 17, 2023, 3:42 a.m. UTC
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>
---
 drivers/net/phy/phy.c | 3 +++
 include/linux/phy.h   | 2 ++
 2 files changed, 5 insertions(+)

Comments

Oleksij Rempel Feb. 17, 2023, 9:09 a.m. UTC | #1
On Fri, Feb 17, 2023 at 04:42:13AM +0100, Andrew Lunn wrote:
> 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>
> ---
>  drivers/net/phy/phy.c | 3 +++
>  include/linux/phy.h   | 2 ++
>  2 files changed, 5 insertions(+)
> 
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index b33e55a7364e..1e6df250d0d0 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -916,9 +916,12 @@ 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;
> +		phydev->eee_active = genphy_c45_eee_is_active(phydev,
> +							      NULL, NULL, NULL);

genphy_c45_eee_is_active() may return an error.
Russell King (Oracle) Feb. 17, 2023, 11:36 a.m. UTC | #2
On Fri, Feb 17, 2023 at 04:42:13AM +0100, Andrew Lunn wrote:
> 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>

Yay!

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!
Andrew Lunn Feb. 17, 2023, 1:35 p.m. UTC | #3
On Fri, Feb 17, 2023 at 10:09:19AM +0100, Oleksij Rempel wrote:
> On Fri, Feb 17, 2023 at 04:42:13AM +0100, Andrew Lunn wrote:
> > 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>
> > ---
> >  drivers/net/phy/phy.c | 3 +++
> >  include/linux/phy.h   | 2 ++
> >  2 files changed, 5 insertions(+)
> > 
> > diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> > index b33e55a7364e..1e6df250d0d0 100644
> > --- a/drivers/net/phy/phy.c
> > +++ b/drivers/net/phy/phy.c
> > @@ -916,9 +916,12 @@ 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;
> > +		phydev->eee_active = genphy_c45_eee_is_active(phydev,
> > +							      NULL, NULL, NULL);
> 
> genphy_c45_eee_is_active() may return an error.

Yep. So we want eee_active false on error.

Thanks
	Andrew
Andrew Lunn Feb. 17, 2023, 1:37 p.m. UTC | #4
On Fri, Feb 17, 2023 at 11:36:31AM +0000, Russell King (Oracle) wrote:
> On Fri, Feb 17, 2023 at 04:42:13AM +0100, Andrew Lunn wrote:
> > 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>
> 
> Yay!
> 
> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Hi Russell

I did wonder about making this a parameter for phylink mac up
callback, rather than having the driver look inside phydev. It is
something which can be done later.

	  Andrew
diff mbox series

Patch

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index b33e55a7364e..1e6df250d0d0 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -916,9 +916,12 @@  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;
+		phydev->eee_active = genphy_c45_eee_is_active(phydev,
+							      NULL, NULL, NULL);
 		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 727bff531a14..b1fbb52ac5a4 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -575,6 +575,7 @@  struct macsec_ops;
  * @advertising: Currently advertised linkmodes
  * @adv_old: Saved advertised while power saving for WoL
  * @supported_eee: supported PHY EEE linkmodes
+ * @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
@@ -687,6 +688,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;