From: Andrew Lunn <andrew@lunn.ch>
To: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
kernel@pengutronix.de, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, Russell King <linux@armlinux.org.uk>
Subject: Re: [PATCH v1] net: phy: at803x: add cable test support
Date: Wed, 13 May 2020 15:32:09 +0200 [thread overview]
Message-ID: <20200513133209.GC499265@lunn.ch> (raw)
In-Reply-To: <20200513120648.14415-1-o.rempel@pengutronix.de>
On Wed, May 13, 2020 at 02:06:48PM +0200, Oleksij Rempel wrote:
> The cable test seems to be support by all of currently support Atherso
> PHYs, so add support for all of them. This patch was tested only on
> AR9331 PHY with following results:
> - No cable is detected as short
> - A 15m long cable connected only on one side is detected as 9m open.
That sounds wrong. What about a shorted 15m cable? Is it also 9m? Do
you have any other long cables you can test with? Is it always 1/2 the
cable length?
> - A cable test with active link partner will provide no usable results.
>
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> drivers/net/phy/at803x.c | 141 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 141 insertions(+)
>
> diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c
> index f4fec5f644e91..03ec500defb34 100644
> --- a/drivers/net/phy/at803x.c
> +++ b/drivers/net/phy/at803x.c
> @@ -7,11 +7,13 @@
> * Author: Matus Ujhelyi <ujhelyi.m@gmail.com>
> */
>
> +#include <linux/bitfield.h>
> #include <linux/phy.h>
> #include <linux/module.h>
> #include <linux/string.h>
> #include <linux/netdevice.h>
> #include <linux/etherdevice.h>
> +#include <linux/ethtool_netlink.h>
> #include <linux/of_gpio.h>
> #include <linux/bitfield.h>
> #include <linux/gpio/consumer.h>
> @@ -48,6 +50,20 @@
> #define AT803X_SMART_SPEED_BYPASS_TIMER BIT(1)
> #define AT803X_LED_CONTROL 0x18
>
> +/* Cable Tester Contol Register */
> +#define AT803X_CABLE_DIAG_CTRL 0x16
> +#define AT803X_CABLE_DIAG_MDI_PAIR GENMASK(9, 8)
> +#define AT803X_CABLE_DIAG_EN BIT(0)
> +
> +/* Cable Tester Status Register */
> +#define AT803X_CABLE_DIAG_STATUS 0x1c
> +#define AT803X_CABLE_DIAG_RESULT GENMASK(9, 8)
> +#define AT803X_CABLE_DIAG_RESULT_OK 0
> +#define AT803X_CABLE_DIAG_RESULT_SHORT 1
> +#define AT803X_CABLE_DIAG_RESULT_OPEN 2
> +#define AT803X_CABLE_DIAG_RESULT_FAIL 3
> +#define AT803X_CABLE_DIAG_DTIME GENMASK(7, 0)
> +
> #define AT803X_DEVICE_ADDR 0x03
> #define AT803X_LOC_MAC_ADDR_0_15_OFFSET 0x804C
> #define AT803X_LOC_MAC_ADDR_16_31_OFFSET 0x804B
> @@ -122,6 +138,7 @@ MODULE_AUTHOR("Matus Ujhelyi");
> MODULE_LICENSE("GPL");
>
> struct at803x_priv {
> + struct phy_device *phydev;
> int flags;
> #define AT803X_KEEP_PLL_ENABLED BIT(0) /* don't turn off internal PLL */
> u16 clk_25m_reg;
> @@ -129,6 +146,9 @@ struct at803x_priv {
> struct regulator_dev *vddio_rdev;
> struct regulator_dev *vddh_rdev;
> struct regulator *vddio;
> + struct work_struct cable_test_work;
> + bool cable_test_finished;
> + int cable_test_ret;
> };
>
> struct at803x_context {
> @@ -168,6 +188,113 @@ static int at803x_debug_reg_mask(struct phy_device *phydev, u16 reg,
> return phy_write(phydev, AT803X_DEBUG_DATA, val);
> }
> +static void at803x_cable_test_work(struct work_struct *work)
> +{
> + struct at803x_priv *priv = container_of(work, struct at803x_priv,
> + cable_test_work);
> + struct phy_device *phydev = priv->phydev;
> + int i, ret = 0, pairs = 4;
> +
> + if (phydev->phy_id == ATH9331_PHY_ID)
> + pairs = 2;
> +
> + for (i = 0; i < pairs; i++) {
> + ret = at803x_cable_test_pair(phydev, i);
> + if (ret)
> + break;
> + }
> +
> + priv->cable_test_ret = ret;
> + priv->cable_test_finished = true;
> +
> + phy_queue_state_machine(phydev, 0);
> +}
> +
> +static int at803x_cable_test_start(struct phy_device *phydev)
> +{
> + struct at803x_priv *priv = phydev->priv;
> +
> + if (!priv->cable_test_finished) {
> + phydev_err(phydev, "cable test is already running\n");
> + return -EIO;
> + }
> +
> + priv->cable_test_finished = false;
> + schedule_work(&priv->cable_test_work);
You don't need the work queue. You cannot spend a long time in
at803x_cable_test_start(), but you can in
at803x_cable_test_get_status(). So start the first the measurement of
the first pair in at803x_cable_test_start(), and do the rest in
of the work in at803x_cable_test_get_status().
If we see there is a common pattern of wanting
at803x_cable_test_get_status() to run immediately, not one second
later, we can change to core to support that.
Andrew
next prev parent reply other threads:[~2020-05-13 13:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 12:06 [PATCH v1] net: phy: at803x: add cable test support Oleksij Rempel
2020-05-13 13:32 ` Andrew Lunn [this message]
2020-05-13 13:50 ` Russell King - ARM Linux admin
2020-05-13 15:23 ` Florian Fainelli
2020-05-13 15:45 ` Oleksij Rempel
2020-05-13 15:49 ` Andrew Lunn
2020-05-13 16:00 ` Oleksij Rempel
2020-05-13 16:23 ` Andrew Lunn
2020-05-13 16:26 ` Michael Walle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200513133209.GC499265@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).