Subject: Re: [PATCH net-next v1 2/3] net: phy: at803x: AR8085: add loopback support

From: Andrew Lunn <[email-masked]>
Date: Tue, 30 Mar 2021 16:49:28 +0200

On Tue, Mar 30, 2021 at 03:54:06PM +0200, Oleksij Rempel wrote:
> PHY loopback is needed for the ethernet controller self test support.
> This PHY was tested with the FEC sefltest.
> 
> Signed-off-by: Oleksij Rempel <[email-masked]>
> ---
>  drivers/net/phy/at803x.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
> index d7799beb811c..8679738cf2ab 100644
> --- a/drivers/net/phy/at803x.c
> +++ b/drivers/net/phy/at803x.c
> @@ -326,6 +326,30 @@ static int at803x_resume(struct phy_device *phydev)
>  	return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
>  }
>  
> +static int at803x_loopback(struct phy_device *phydev, bool enable)
> +{
> +	int ret;
> +
> +	if (enable)
> +		ret = phy_clear_bits(phydev, MII_BMCR, BMCR_ANENABLE);
> +	else
> +		ret = phy_set_bits(phydev, MII_BMCR, BMCR_ANENABLE);

Auto-neg might of been turned off when entering self test. So you
should leave it off when existing self test.

Or maybe call phy_config_aneg() which should reconfigure the PHY back
how it was.

       Andrew