Subject: Re: [PATCH RFC 03/18] net: marvell: mvneta: Simplify EEE configuration

From: "Russell King (Oracle)" <[email-masked]>
Date: Fri, 17 Feb 2023 13:13:03 +0000

On Fri, Feb 17, 2023 at 11:59:39AM +0000, Russell King (Oracle) wrote:
> On Fri, Feb 17, 2023 at 04:42:15AM +0100, Andrew Lunn wrote:
> > @@ -4221,10 +4218,8 @@ static void mvneta_mac_link_up(struct phylink_config *config,
> >  
> >  	mvneta_port_up(pp);
> >  
> > -	if (phy && pp->eee_enabled) {
> > -		pp->eee_active = phy_init_eee(phy, false) >= 0;
> > -		mvneta_set_eee(pp, pp->eee_active && pp->tx_lpi_enabled);
> > -	}
> > +	if (phy)
> > +		mvneta_set_eee(pp, phy->eee_active && pp->tx_lpi_enabled);
> 
> Thinking about this a bit more, I'm not convinced this is properly safe.
> What protects phy->eee_active from changing here? The phydev mutex won't
> be held at this point.
> 
> As I mentioned in my reply to the cover letter about passing a flag to
> mac_link_up() for EEE status, this would mean phylink could save the
> EEE active status just like it does with the other phydev parameters
> in phylink_phy_change() (which is called under the phydev mutex).

I suppose another option would be to add a new method to
phylink_mac_ops:

	int (*mac_set_eee)(struct phylink_config *config, bool eee,
			   u32 tx_lpi_timer);

and phylink calls this just before mac_link_up() or after
phylink_ethtool_set_eee(). The eee flag would be the effective result
of phydev->eee_active && tx_lpi_enabled, possibly also && tx_lpi_timer
!= 0, since a zero tx_lpi_timer is rather meaningless, unless we
explicitly have phylink_ethtool_set_eee() reject it is invalid.

All that mac_set_eee() implementations should then need to do is to
program the LPI timer in the MAC hardware, and enable or disable it
according to the "eee" flag.

The down-side to another mac_ops method is having to add a wrapper in
net/dsa/port.c for it.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!