Re: [PATCH net-next v1 4/4] net: phy: Always read EEE LPA in genphy_c45_ethtool_get_eee()

From: Oleksij Rempel
Date: Fri Apr 25 2025 - 00:42:12 EST


On Thu, Apr 24, 2025 at 03:47:03PM +0100, Russell King (Oracle) wrote:
> On Thu, Apr 24, 2025 at 04:34:27PM +0200, Andrew Lunn wrote:
> > On Thu, Apr 24, 2025 at 02:16:01PM +0100, Russell King (Oracle) wrote:
> > > However, I've no objection to reading the LPA EEE state and
> > > reporting it.
> >
> > What happens with normal link mode LPA when autoneg is disabled? I
> > guess they are not reported because the PHY is not even listening for
> > the autoneg pulses. We could be inconsistent between normal LPA and
> > LPA EEE, but is that a good idea?
>
> With autoneg state, that controls whether the various pages get
> exchanged or not - which includes the EEE capabilties. This is the
> big hammer for anything that is negotiated.
>
> With EEE, as long as autoneg in the main config is true, the PHY will
> exchange the EEE capability pages if it supports them. Our eee_enabled
> is purely just a software switch, there's nothing that corresponds to it
> in hardware, unlike autoneg which has a bit in BMCR.
>
> We implement eee_enabled by clearing the advertisement in the hardware
> but accepting (and remembering) the advertisement from userspace
> unmodified.
>
> The two things are entirely different in hardware.
>
> Since:
>
> ethtool --set-eee eee off
>
> Will use ETHTOOL_GEEE, modify eee_enabled to be false (via
> do_generic_set), and then use ETHTOOL_SEEE to write it back, the
> old advertisement will be passed back to the kernel in this case.
>
> If we don't preserve the advertisement, then:
>
> ethtool --set-eee eee off
>
> will clear the advertisement, and then:
>
> ethtool --set-eee eee on
>
> will set eee_enabled true but we'll have an empty advertisement. Not
> ideal.
>
> If we think about forcing it for an empty advertisement to e.g. fully
> populated, then:
>
> ethtool --set-eee eee on advertise 0
>
> will surprisingly not end up with an empty advertisement.
>
> So, I don't think it's realistic to come up with a way that --set-eee
> behaves the same way as -s because of the way ethtool has been
> implemented.

Thank you for the detailed explanation. I completely forgot that
"advertising_eee" is part of a read-modify-write cycle in the ethtool flow.
That makes sense now. In this case, I agree - there's nothing much I can
do code-wise. In this case, the only thing I can do is document this
behavior on both the kernel and ethtool sides to avoid confusion for
others.

Best Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |