diff mbox series

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

Message ID 20210330135407.17010-3-o.rempel@pengutronix.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series provide basic selftest support for the ethernet FEC driver | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 2 maintainers not CCed: davem@davemloft.net kuba@kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst WARNING: networking block comments don't use an empty /* line, use /* Comment...
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Oleksij Rempel March 30, 2021, 1:54 p.m. UTC
PHY loopback is needed for the ethernet controller self test support.
This PHY was tested with the FEC sefltest.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/phy/at803x.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Marc Kleine-Budde March 30, 2021, 2:08 p.m. UTC | #1
On 3/30/21 3:54 PM, 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 <o.rempel@pengutronix.de>
> ---
>  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);
> +
> +	if (ret)
> +		return ret;
> +
> +	ret = genphy_loopback(phydev, enable);
> +
> +	/*
> +	 * Loop back needs some time to start transmitting packets in the loop.
> +	 * Documentation says nothing about it, so I take time which seems to
> +	 * work on AR8085.
> +	 */

/* Keep in mind the net multi line comment
 * style.
 */

Marc
Andrew Lunn March 30, 2021, 2:49 p.m. UTC | #2
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 <o.rempel@pengutronix.de>
> ---
>  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
diff mbox series

Patch

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);
+
+	if (ret)
+		return ret;
+
+	ret = genphy_loopback(phydev, enable);
+
+	/*
+	 * Loop back needs some time to start transmitting packets in the loop.
+	 * Documentation says nothing about it, so I take time which seems to
+	 * work on AR8085.
+	 */
+	msleep(1);
+
+	return ret;
+}
+
 static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
 					    unsigned int selector)
 {
@@ -1128,6 +1152,7 @@  static struct phy_driver at803x_driver[] = {
 	.get_wol		= at803x_get_wol,
 	.suspend		= at803x_suspend,
 	.resume			= at803x_resume,
+	.set_loopback		= at803x_loopback,
 	/* PHY_GBIT_FEATURES */
 	.read_status		= at803x_read_status,
 	.config_intr		= at803x_config_intr,