Subject: Re: [PATCH RFC 12/18] net: dsa: mt7530: Call phylib for set_eee and get_eee

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

On Fri, Feb 17, 2023 at 04:42:24AM +0100, Andrew Lunn wrote:
> phylib should be called in order to manage the EEE settings in the
> PHY, and to return EEE status such are supported link modes, and what
> the link peer supports.
> 
> Signed-off-by: Andrew Lunn <[email-masked]>
> ---
>  drivers/net/dsa/mt7530.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
> index 214450378978..a472353f14f8 100644
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -3124,10 +3124,13 @@ static int mt753x_get_mac_eee(struct dsa_switch *ds, int port,
>  {
>  	struct mt7530_priv *priv = ds->priv;
>  	u32 eeecr = mt7530_read(priv, MT7530_PMEEECR_P(port));
> +	struct dsa_port *dp = dsa_to_port(ds, port);
>  
>  	e->tx_lpi_enabled = !(eeecr & LPI_MODE_EN);
>  	e->tx_lpi_timer = GET_LPI_THRESH(eeecr);
>  
> +	if (dp->slave->phydev)
> +		return phy_ethtool_get_eee(dp->slave->phydev, e);

Given that DSA makes use of phylink, is there a reason why we can't use
the phylink wrappers here (which may allow for future EEE improvements,
e.g. moving the gating of EEE with the TX LPI enable) ?

> @@ -3146,6 +3150,8 @@ static int mt753x_set_mac_eee(struct dsa_switch *ds, int port,
>  		set |= LPI_MODE_EN;
>  	mt7530_rmw(priv, MT7530_PMEEECR_P(port), mask, set);
>  
> +	if (dp->slave->phydev)
> +		return phy_ethtool_set_eee(dp->slave->phydev, e);
>  	return 0;

Is this the correct place to do the set_eee operation - I mean, the
register state has been altered (and it looks like it may enable LPI
irrespective of the negotiated state) but what concerns me is that
phy_ethtool_set_eee() can fail, and we return failure to userspace
yet we've modified register state.

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