Skip to content

Commit bed37f0

Browse files
committed
Merge branch 'Ethernet-Cable-test-support'
Andrew Lunn says: ==================== Ethernet Cable test support any copper Ethernet PHY have support for performing diagnostics of the cable. Are the cable shorted, broken, not plugged into anything at the other end? And they can report roughly how far along the cable any fault is. Add infrastructure in ethtool and phylib support for triggering a cable test and reporting the results. The Marvell 1G PHY driver is then extended to make use of this infrastructure. For testing, a modified ethtool(1) can be found here: https://github.com/lunn/ethtool.git feature/cable-test-v4. This also contains extra code for TDR dump, which will be added to the kernel in a later patch series. Thanks to Chris Healy for extensive testing. v2: See individual patches but: Remove _REPLY messages Change length into a u32 Grammar fixes Rename functions for consistency Extack for cable test already running Remove ethnl_cable_test_act_ops Add status attributes Rename pairs from numbers to letters v3: See individual patches but: Remove ETHTOOL_MSG_CABLE_TEST_ACT_REPLY from documentation Remove unused cable_test_get_policy Fixed example in document Add ETHTOOL_A_CABLE_NEST_* enum Add ETHTOOL_MSG_CABLE_TEST_NTF to documentation Poison phydev->skb Return -EMSGSIZE when ethnl_bcastmsg_put() fails Return valid error code when nla_nest_start() fails Use u8 for results Actually put u32 length into message s/mavell/marvell/g Remove include of <uapi/linux/ethtool_netlink.h> EMSGSIZE when ethnl_bcastmsg_put() fails Print an error message on failure, since this is a void function. v4: See individual patches but: Remove unwanted blank line ENOTSUPP->EOPNOTSUPP Move EINVAL->EMSGSIZE fix to correct patch ==================== Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents b9f9642 + 9896a45 commit bed37f0

11 files changed

Lines changed: 722 additions & 4 deletions

File tree

‎Documentation/networking/ethtool-netlink.rst‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Userspace to kernel:
204204
``ETHTOOL_MSG_EEE_GET`` get EEE settings
205205
``ETHTOOL_MSG_EEE_SET`` set EEE settings
206206
``ETHTOOL_MSG_TSINFO_GET`` get timestamping info
207+
``ETHTOOL_MSG_CABLE_TEST_ACT`` action start cable test
207208
===================================== ================================
208209

209210
Kernel to userspace:
@@ -235,6 +236,7 @@ Kernel to userspace:
235236
``ETHTOOL_MSG_EEE_GET_REPLY`` EEE settings
236237
``ETHTOOL_MSG_EEE_NTF`` EEE settings
237238
``ETHTOOL_MSG_TSINFO_GET_REPLY`` timestamping info
239+
``ETHTOOL_MSG_CABLE_TEST_NTF`` Cable test results
238240
===================================== =================================
239241

240242
``GET`` requests are sent by userspace applications to retrieve device
@@ -958,13 +960,65 @@ Kernel response contents:
958960
is no special value for this case). The bitset attributes are omitted if they
959961
would be empty (no bit set).
960962

963+
CABLE_TEST
964+
==========
965+
966+
Start a cable test.
967+
968+
Request contents:
969+
970+
==================================== ====== ==========================
971+
``ETHTOOL_A_CABLE_TEST_HEADER`` nested request header
972+
==================================== ====== ==========================
973+
974+
Notification contents:
975+
976+
An Ethernet cable typically contains 1, 2 or 4 pairs. The length of
977+
the pair can only be measured when there is a fault in the pair and
978+
hence a reflection. Information about the fault may not be available,
979+
depending on the specific hardware. Hence the contents of the notify
980+
message are mostly optional. The attributes can be repeated an
981+
arbitrary number of times, in an arbitrary order, for an arbitrary
982+
number of pairs.
983+
984+
The example shows the notification sent when the test is completed for
985+
a T2 cable, i.e. two pairs. One pair is OK and hence has no length
986+
information. The second pair has a fault and does have length
987+
information.
988+
989+
+---------------------------------------------+--------+---------------------+
990+
| ``ETHTOOL_A_CABLE_TEST_HEADER`` | nested | reply header |
991+
+---------------------------------------------+--------+---------------------+
992+
| ``ETHTOOL_A_CABLE_TEST_STATUS`` | u8 | completed |
993+
+---------------------------------------------+--------+---------------------+
994+
| ``ETHTOOL_A_CABLE_TEST_NTF_NEST`` | nested | all the results |
995+
+-+-------------------------------------------+--------+---------------------+
996+
| | ``ETHTOOL_A_CABLE_NEST_RESULT`` | nested | cable test result |
997+
+-+-+-----------------------------------------+--------+---------------------+
998+
| | | ``ETHTOOL_A_CABLE_RESULTS_PAIR`` | u8 | pair number |
999+
+-+-+-----------------------------------------+--------+---------------------+
1000+
| | | ``ETHTOOL_A_CABLE_RESULTS_CODE`` | u8 | result code |
1001+
+-+-+-----------------------------------------+--------+---------------------+
1002+
| | ``ETHTOOL_A_CABLE_NEST_RESULT`` | nested | cable test results |
1003+
+-+-+-----------------------------------------+--------+---------------------+
1004+
| | | ``ETHTOOL_A_CABLE_RESULTS_PAIR`` | u8 | pair number |
1005+
+-+-+-----------------------------------------+--------+---------------------+
1006+
| | | ``ETHTOOL_A_CABLE_RESULTS_CODE`` | u8 | result code |
1007+
+-+-+-----------------------------------------+--------+---------------------+
1008+
| | ``ETHTOOL_A_CABLE_NEST_FAULT_LENGTH`` | nested | cable length |
1009+
+-+-+-----------------------------------------+--------+---------------------+
1010+
| | | ``ETHTOOL_A_CABLE_FAULT_LENGTH_PAIR`` | u8 | pair number |
1011+
+-+-+-----------------------------------------+--------+---------------------+
1012+
| | | ``ETHTOOL_A_CABLE_FAULT_LENGTH_CM`` | u32 | length in cm |
1013+
+-+-+-----------------------------------------+--------+---------------------+
9611014

9621015
Request translation
9631016
===================
9641017

9651018
The following table maps ioctl commands to netlink commands providing their
9661019
functionality. Entries with "n/a" in right column are commands which do not
967-
have their netlink replacement yet.
1020+
have their netlink replacement yet. Entries which "n/a" in the left column
1021+
are netlink only.
9681022

9691023
=================================== =====================================
9701024
ioctl command netlink command
@@ -1053,4 +1107,5 @@ have their netlink replacement yet.
10531107
``ETHTOOL_PHY_STUNABLE`` n/a
10541108
``ETHTOOL_GFECPARAM`` n/a
10551109
``ETHTOOL_SFECPARAM`` n/a
1110+
n/a ''ETHTOOL_MSG_CABLE_TEST_ACT''
10561111
=================================== =====================================

‎drivers/net/phy/marvell.c‎

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/module.h>
2828
#include <linux/mii.h>
2929
#include <linux/ethtool.h>
30+
#include <linux/ethtool_netlink.h>
3031
#include <linux/phy.h>
3132
#include <linux/marvell_phy.h>
3233
#include <linux/bitfield.h>
@@ -42,6 +43,7 @@
4243
#define MII_MARVELL_MSCR_PAGE 0x02
4344
#define MII_MARVELL_LED_PAGE 0x03
4445
#define MII_MARVELL_MISC_TEST_PAGE 0x06
46+
#define MII_MARVELL_VCT7_PAGE 0x07
4547
#define MII_MARVELL_WOL_PAGE 0x11
4648

4749
#define MII_M1011_IEVENT 0x13
@@ -162,6 +164,36 @@
162164
#define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */
163165
#define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
164166

167+
#define MII_VCT7_PAIR_0_DISTANCE 0x10
168+
#define MII_VCT7_PAIR_1_DISTANCE 0x11
169+
#define MII_VCT7_PAIR_2_DISTANCE 0x12
170+
#define MII_VCT7_PAIR_3_DISTANCE 0x13
171+
172+
#define MII_VCT7_RESULTS 0x14
173+
#define MII_VCT7_RESULTS_PAIR3_MASK 0xf000
174+
#define MII_VCT7_RESULTS_PAIR2_MASK 0x0f00
175+
#define MII_VCT7_RESULTS_PAIR1_MASK 0x00f0
176+
#define MII_VCT7_RESULTS_PAIR0_MASK 0x000f
177+
#define MII_VCT7_RESULTS_PAIR3_SHIFT 12
178+
#define MII_VCT7_RESULTS_PAIR2_SHIFT 8
179+
#define MII_VCT7_RESULTS_PAIR1_SHIFT 4
180+
#define MII_VCT7_RESULTS_PAIR0_SHIFT 0
181+
#define MII_VCT7_RESULTS_INVALID 0
182+
#define MII_VCT7_RESULTS_OK 1
183+
#define MII_VCT7_RESULTS_OPEN 2
184+
#define MII_VCT7_RESULTS_SAME_SHORT 3
185+
#define MII_VCT7_RESULTS_CROSS_SHORT 4
186+
#define MII_VCT7_RESULTS_BUSY 9
187+
188+
#define MII_VCT7_CTRL 0x15
189+
#define MII_VCT7_CTRL_RUN_NOW BIT(15)
190+
#define MII_VCT7_CTRL_RUN_ANEG BIT(14)
191+
#define MII_VCT7_CTRL_DISABLE_CROSS BIT(13)
192+
#define MII_VCT7_CTRL_RUN_AFTER_BREAK_LINK BIT(12)
193+
#define MII_VCT7_CTRL_IN_PROGRESS BIT(11)
194+
#define MII_VCT7_CTRL_METERS BIT(10)
195+
#define MII_VCT7_CTRL_CENTIMETERS 0
196+
165197
#define LPA_PAUSE_FIBER 0x180
166198
#define LPA_PAUSE_ASYM_FIBER 0x100
167199

@@ -1658,6 +1690,163 @@ static void marvell_get_stats(struct phy_device *phydev,
16581690
data[i] = marvell_get_stat(phydev, i);
16591691
}
16601692

1693+
static int marvell_vct7_cable_test_start(struct phy_device *phydev)
1694+
{
1695+
int bmcr, bmsr, ret;
1696+
1697+
/* If auto-negotiation is enabled, but not complete, the cable
1698+
* test never completes. So disable auto-neg.
1699+
*/
1700+
bmcr = phy_read(phydev, MII_BMCR);
1701+
if (bmcr < 0)
1702+
return bmcr;
1703+
1704+
bmsr = phy_read(phydev, MII_BMSR);
1705+
1706+
if (bmsr < 0)
1707+
return bmsr;
1708+
1709+
if (bmcr & BMCR_ANENABLE) {
1710+
ret = phy_modify(phydev, MII_BMCR, BMCR_ANENABLE, 0);
1711+
if (ret < 0)
1712+
return ret;
1713+
ret = genphy_soft_reset(phydev);
1714+
if (ret < 0)
1715+
return ret;
1716+
}
1717+
1718+
/* If the link is up, allow it some time to go down */
1719+
if (bmsr & BMSR_LSTATUS)
1720+
msleep(1500);
1721+
1722+
return phy_write_paged(phydev, MII_MARVELL_VCT7_PAGE,
1723+
MII_VCT7_CTRL,
1724+
MII_VCT7_CTRL_RUN_NOW |
1725+
MII_VCT7_CTRL_CENTIMETERS);
1726+
}
1727+
1728+
static int marvell_vct7_distance_to_length(int distance, bool meter)
1729+
{
1730+
if (meter)
1731+
distance *= 100;
1732+
1733+
return distance;
1734+
}
1735+
1736+
static bool marvell_vct7_distance_valid(int result)
1737+
{
1738+
switch (result) {
1739+
case MII_VCT7_RESULTS_OPEN:
1740+
case MII_VCT7_RESULTS_SAME_SHORT:
1741+
case MII_VCT7_RESULTS_CROSS_SHORT:
1742+
return true;
1743+
}
1744+
return false;
1745+
}
1746+
1747+
static int marvell_vct7_report_length(struct phy_device *phydev,
1748+
int pair, bool meter)
1749+
{
1750+
int length;
1751+
int ret;
1752+
1753+
ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE,
1754+
MII_VCT7_PAIR_0_DISTANCE + pair);
1755+
if (ret < 0)
1756+
return ret;
1757+
1758+
length = marvell_vct7_distance_to_length(ret, meter);
1759+
1760+
ethnl_cable_test_fault_length(phydev, pair, length);
1761+
1762+
return 0;
1763+
}
1764+
1765+
static int marvell_vct7_cable_test_report_trans(int result)
1766+
{
1767+
switch (result) {
1768+
case MII_VCT7_RESULTS_OK:
1769+
return ETHTOOL_A_CABLE_RESULT_CODE_OK;
1770+
case MII_VCT7_RESULTS_OPEN:
1771+
return ETHTOOL_A_CABLE_RESULT_CODE_OPEN;
1772+
case MII_VCT7_RESULTS_SAME_SHORT:
1773+
return ETHTOOL_A_CABLE_RESULT_CODE_SAME_SHORT;
1774+
case MII_VCT7_RESULTS_CROSS_SHORT:
1775+
return ETHTOOL_A_CABLE_RESULT_CODE_CROSS_SHORT;
1776+
default:
1777+
return ETHTOOL_A_CABLE_RESULT_CODE_UNSPEC;
1778+
}
1779+
}
1780+
1781+
static int marvell_vct7_cable_test_report(struct phy_device *phydev)
1782+
{
1783+
int pair0, pair1, pair2, pair3;
1784+
bool meter;
1785+
int ret;
1786+
1787+
ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE,
1788+
MII_VCT7_RESULTS);
1789+
if (ret < 0)
1790+
return ret;
1791+
1792+
pair3 = (ret & MII_VCT7_RESULTS_PAIR3_MASK) >>
1793+
MII_VCT7_RESULTS_PAIR3_SHIFT;
1794+
pair2 = (ret & MII_VCT7_RESULTS_PAIR2_MASK) >>
1795+
MII_VCT7_RESULTS_PAIR2_SHIFT;
1796+
pair1 = (ret & MII_VCT7_RESULTS_PAIR1_MASK) >>
1797+
MII_VCT7_RESULTS_PAIR1_SHIFT;
1798+
pair0 = (ret & MII_VCT7_RESULTS_PAIR0_MASK) >>
1799+
MII_VCT7_RESULTS_PAIR0_SHIFT;
1800+
1801+
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_A,
1802+
marvell_vct7_cable_test_report_trans(pair0));
1803+
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_B,
1804+
marvell_vct7_cable_test_report_trans(pair1));
1805+
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_C,
1806+
marvell_vct7_cable_test_report_trans(pair2));
1807+
ethnl_cable_test_result(phydev, ETHTOOL_A_CABLE_PAIR_D,
1808+
marvell_vct7_cable_test_report_trans(pair3));
1809+
1810+
ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE, MII_VCT7_CTRL);
1811+
if (ret < 0)
1812+
return ret;
1813+
1814+
meter = ret & MII_VCT7_CTRL_METERS;
1815+
1816+
if (marvell_vct7_distance_valid(pair0))
1817+
marvell_vct7_report_length(phydev, 0, meter);
1818+
if (marvell_vct7_distance_valid(pair1))
1819+
marvell_vct7_report_length(phydev, 1, meter);
1820+
if (marvell_vct7_distance_valid(pair2))
1821+
marvell_vct7_report_length(phydev, 2, meter);
1822+
if (marvell_vct7_distance_valid(pair3))
1823+
marvell_vct7_report_length(phydev, 3, meter);
1824+
1825+
return 0;
1826+
}
1827+
1828+
static int marvell_vct7_cable_test_get_status(struct phy_device *phydev,
1829+
bool *finished)
1830+
{
1831+
int ret;
1832+
1833+
*finished = false;
1834+
1835+
ret = phy_read_paged(phydev, MII_MARVELL_VCT7_PAGE,
1836+
MII_VCT7_CTRL);
1837+
1838+
if (ret < 0)
1839+
return ret;
1840+
1841+
if (!(ret & MII_VCT7_CTRL_IN_PROGRESS)) {
1842+
*finished = true;
1843+
1844+
return marvell_vct7_cable_test_report(phydev);
1845+
}
1846+
1847+
return 0;
1848+
}
1849+
16611850
#ifdef CONFIG_HWMON
16621851
static int m88e1121_get_temp(struct phy_device *phydev, long *temp)
16631852
{
@@ -2353,6 +2542,7 @@ static struct phy_driver marvell_drivers[] = {
23532542
.phy_id_mask = MARVELL_PHY_ID_MASK,
23542543
.name = "Marvell 88E1510",
23552544
.features = PHY_GBIT_FIBRE_FEATURES,
2545+
.flags = PHY_POLL_CABLE_TEST,
23562546
.probe = &m88e1510_probe,
23572547
.config_init = &m88e1510_config_init,
23582548
.config_aneg = &m88e1510_config_aneg,
@@ -2372,12 +2562,15 @@ static struct phy_driver marvell_drivers[] = {
23722562
.set_loopback = genphy_loopback,
23732563
.get_tunable = m88e1011_get_tunable,
23742564
.set_tunable = m88e1011_set_tunable,
2565+
.cable_test_start = marvell_vct7_cable_test_start,
2566+
.cable_test_get_status = marvell_vct7_cable_test_get_status,
23752567
},
23762568
{
23772569
.phy_id = MARVELL_PHY_ID_88E1540,
23782570
.phy_id_mask = MARVELL_PHY_ID_MASK,
23792571
.name = "Marvell 88E1540",
23802572
/* PHY_GBIT_FEATURES */
2573+
.flags = PHY_POLL_CABLE_TEST,
23812574
.probe = m88e1510_probe,
23822575
.config_init = &marvell_config_init,
23832576
.config_aneg = &m88e1510_config_aneg,
@@ -2394,13 +2587,16 @@ static struct phy_driver marvell_drivers[] = {
23942587
.get_stats = marvell_get_stats,
23952588
.get_tunable = m88e1540_get_tunable,
23962589
.set_tunable = m88e1540_set_tunable,
2590+
.cable_test_start = marvell_vct7_cable_test_start,
2591+
.cable_test_get_status = marvell_vct7_cable_test_get_status,
23972592
},
23982593
{
23992594
.phy_id = MARVELL_PHY_ID_88E1545,
24002595
.phy_id_mask = MARVELL_PHY_ID_MASK,
24012596
.name = "Marvell 88E1545",
24022597
.probe = m88e1510_probe,
24032598
/* PHY_GBIT_FEATURES */
2599+
.flags = PHY_POLL_CABLE_TEST,
24042600
.config_init = &marvell_config_init,
24052601
.config_aneg = &m88e1510_config_aneg,
24062602
.read_status = &marvell_read_status,
@@ -2416,6 +2612,8 @@ static struct phy_driver marvell_drivers[] = {
24162612
.get_stats = marvell_get_stats,
24172613
.get_tunable = m88e1540_get_tunable,
24182614
.set_tunable = m88e1540_set_tunable,
2615+
.cable_test_start = marvell_vct7_cable_test_start,
2616+
.cable_test_get_status = marvell_vct7_cable_test_get_status,
24192617
},
24202618
{
24212619
.phy_id = MARVELL_PHY_ID_88E3016,
@@ -2442,6 +2640,7 @@ static struct phy_driver marvell_drivers[] = {
24422640
.phy_id_mask = MARVELL_PHY_ID_MASK,
24432641
.name = "Marvell 88E6390",
24442642
/* PHY_GBIT_FEATURES */
2643+
.flags = PHY_POLL_CABLE_TEST,
24452644
.probe = m88e6390_probe,
24462645
.config_init = &marvell_config_init,
24472646
.config_aneg = &m88e6390_config_aneg,
@@ -2458,6 +2657,8 @@ static struct phy_driver marvell_drivers[] = {
24582657
.get_stats = marvell_get_stats,
24592658
.get_tunable = m88e1540_get_tunable,
24602659
.set_tunable = m88e1540_set_tunable,
2660+
.cable_test_start = marvell_vct7_cable_test_start,
2661+
.cable_test_get_status = marvell_vct7_cable_test_get_status,
24612662
},
24622663
};
24632664

0 commit comments

Comments
 (0)