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

From: Andrew Lunn <[email-masked]>
Date: Fri, 17 Feb 2023 14:35:05 +0100

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 <[email-masked]>
> > ---
> >  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