Re: [RFC] net: dsa: slave: Advertise correct EEE capabilities at slave PHY setup

From: Russell King (Oracle)
Date: Tue May 30 2023 - 09:00:31 EST


On Tue, May 30, 2023 at 02:26:21PM +0200, Lukasz Majewski wrote:
> One can disable in device tree advertising of EEE capabilities of PHY
> when 'eee-broken-100tx' property is present in DTS.
>
> With DSA switch it also may happen that one would need to disable EEE due
> to some network issues.
>
> Corresponding switch DTS description:
>
> switch@0 {
> ports {
> port@0 {
> reg = <0>;
> label = "lan1";
> phy-handle = <&switchphy0>;
> };
> }
> mdio {
> switchphy0: switchphy@0 {
> reg = <0>;
> eee-broken-100tx;
> };
> };
>
> This patch adjusts the content of MDIO_AN_EEE_ADV in MDIO_MMD_AN "device"
> so the phydev->eee_broken_modes are taken into account from the start of
> the slave PHYs.

This should be handled by phylib today in recent kernels without the
need for any patch (as I describe below, because the config_aneg PHY
method should be programming it.) Are you seeing a problem with it
in 6.4-rc?

> As a result the 'ethtool --show-eee lan1' shows that EEE is not supported
> from the outset.
>
> Questions:
>
> - Is the genphy_config_eee_advert() appropriate to be used here?
> As I found this issue on 5.15 kernel, it looks like mainline now uses
> PHY features for handle EEE (but the aforementioned function is still
> present in newest mainline - v6.4-rc1).
>
> - I've also observed strange behaviour for EEE capability register:
> Why the value in MDIO_MMD_PCS device; reg MDIO_PCS_EEE_ABLE is somewhat
> "volatile" - in a sense that when I use:
> ethtool --set-eee lan2 eee off
>
> It is cleared by PHY itself to 0x0 (from 0x2) and turning it on again is
> not working.
>
> Is this expected? Or am I missing something?

No - this register is supposed to report the capabilities of the PHY,
and bits 1..15 should be read-only, and as they report the capabilities
they should be fixed. Writing to bit 1 of this register will therefore
be ignored. It sounds like your PHY has some odd behaviour - maybe
someone misinterpreted 802.3 45.2.3.9?

> Signed-off-by: Lukasz Majewski <lukma@xxxxxxx>
> ---
> net/dsa/slave.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/dsa/slave.c b/net/dsa/slave.c
> index 353d8fff3166..712923c7d4e2 100644
> --- a/net/dsa/slave.c
> +++ b/net/dsa/slave.c
> @@ -2247,6 +2247,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
> phylink_destroy(dp->pl);
> }
>
> + genphy_config_eee_advert(slave_dev->phydev);

No network driver (which includes DSA) should be calling any function
starting genphy_*. These functions are purely for phylib or phy drivers
to use, and no one else.

genphy_config_eee_advert() is a deprecated function (see commit
5827b168125d ("net: phy: c45: migrate to genphy_c45_write_eee_adv()")
and thus should not be used.

genphy_c45_write_eee_adv() is called by genphy_c45_an_config_eee_aneg()
which will in turn be called by genphy_config_aneg() for a clause 22
PHY, or by genphy_c45_an_config_aneg() for a clause 45 PHY. These will
write the EEE advertisement mask to the PHY's AN MMD.

So, EEE should be handled by phylib according to the firmware settings.
The only thing that network drivers that use phylib have to deal with
is setting their hardware for the LPI timeout and enabling/disabling
the timeout as necessary.

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