mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: Andrew Lunn <andrew@lunn.ch>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Florian Fainelli <f.fainelli@gmail.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next] net: phy: at803x: add cable diagnostics support
Date: Sun, 10 May 2020 17:04:11 +0200	[thread overview]
Message-ID: <8e64c94a4306a93578d9092c00bbc827@walle.cc> (raw)
In-Reply-To: <20200510145250.GK362499@lunn.ch>

Am 2020-05-10 16:52, schrieb Andrew Lunn:
> More of a note to self:
> 
> Now we have three implementations, we start to see bits of common code
> which could be pulled out and shared.
> 
>> +static bool at803x_cdt_fault_length_valid(u16 status)
>> +{
>> +	switch (FIELD_GET(AT803X_CDT_STATUS_STAT_MASK, status)) {
>> +	case AT803X_CDT_STATUS_STAT_OPEN:
>> +	case AT803X_CDT_STATUS_STAT_SHORT:
>> +		return true;
>> +	}
>> +	return false;
>> +}
> 
> If we uses the netlink attribute values, not the PHY specific values,
> this could be put in the core.
> 
>> +
>> +static int at803x_cdt_fault_length(u16 status)
>> +{
>> +	int dt;
>> +
>> +	/* According to the datasheet the distance to the fault is
>> +	 * DELTA_TIME * 0.824 meters.
>> +	 *
>> +	 * The author suspect the correct formula is:
>> +	 *
>> +	 *   fault_distance = DELTA_TIME * (c * VF) / 125MHz / 2
>> +	 *
>> +	 * where c is the speed of light, VF is the velocity factor of
>> +	 * the twisted pair cable, 125MHz the counter frequency and
>> +	 * we need to divide by 2 because the hardware will measure the
>> +	 * round trip time to the fault and back to the PHY.
>> +	 *
>> +	 * With a VF of 0.69 we get the factor 0.824 mentioned in the
>> +	 * datasheet.
>> +	 */
>> +	dt = FIELD_GET(AT803X_CDT_STATUS_DELTA_TIME_MASK, status);
>> +
>> +	return (dt * 824) / 10;
>> +}
> 
> There seems to be a general consensus of 0.824 meters. So we could
> have helpers to convert back and forth in the core.

Yeah, but I don't know why VF is 0.69 (and it differs per cable, so
its just some kind of sensible default value). According to
https://en.wikipedia.org/wiki/Velocity_factor it should be something
around 0.64 or 0.65.

-michael

> 
>> +static int at803x_cable_test_start(struct phy_device *phydev)
>> +{
>> +	/* Enable auto-negotiation, but advertise no capabilities, no link
>> +	 * will be established. A restart of the auto-negotiation is not
>> +	 * required, because the cable test will automatically break the 
>> link.
>> +	 */
>> +	phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
>> +	phy_write(phydev, MII_ADVERTISE, ADVERTISE_CSMA);
>> +	phy_write(phydev, MII_CTRL1000, 0);
> 
> Could be a genphy_ helper.
> 
> Lets get the code merged, when we can come back and do some
> refactoring.
> 
> 	Andrew

      reply	other threads:[~2020-05-10 15:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-09 22:17 Michael Walle
2020-05-10 14:30 ` Andrew Lunn
2020-05-10 14:52 ` Andrew Lunn
2020-05-10 15:04   ` Michael Walle [this message]

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=8e64c94a4306a93578d9092c00bbc827@walle.cc \
    --to=michael@walle.cc \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®