Skip to contentSkip to conversation

Microsemi PHY cable

RFC In review Raju Lakkaraju 2 participants 4 messages Jun 12, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Microsemi PHY cable

This series of patches add the Microsemi PHY cable diagnostics command with PHY Netlink Interface.

1. phy_netlink.c and phy_netlink.h files add for PHY diagnostics features implementation through PHY Netlink interface.
2. phy.c contain the generic functions of "PHY diagnostics". This layer independ of the communication layer (i.e. Netlink or IOCTL etc)
3. mscc.c contain the 4-pair ethernet PHY driver along with PHY diagnostics feature.

Patches test on VSC8531 Microsemi PHY - Beaglebone Black target

Test results:
------------

# nl-app eth0 request
GroupID = 2
GroupName = phy_monitor

Cable Diagnostics Request:
Operation Status : Success
Cable Pairs mask : 0xf
Timeout count : 84
Cable diagnostics results:
Pair A: Correctly terminated pair, Loop Length: 0 m Pair B: Correctly terminated pair, Loop Length: 0 m Pair C: Correctly terminated pair, Loop Length: 0 m Pair D: Correctly terminated pair, Loop Length: 0 m

Application git repository path:
-------------------------------
https://github.com/lakkarajun/bbb_nl_app

Raju Lakkaraju (2):
net: phy: mscc: Add PHY Netlink Interface along with Cable Diagnostics
command
net: phy: mscc: Add PHY driver for Cable Diagnostics command

 drivers/net/phy/Kconfig       |   6 ++
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/mscc.c        | 128 ++++++++++++++++++++++++
 drivers/net/phy/phy.c         |  17 ++++
 drivers/net/phy/phy_netlink.c | 226 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy.h           |  88 ++++++++++++++++
 include/linux/phy_netlink.h   |  48 +++++++++
 7 files changed, 514 insertions(+)
 create mode 100644 drivers/net/phy/phy_netlink.c
 create mode 100644 include/linux/phy_netlink.h
Signature · 1 line
2.7.4
#1 lore raw

RFC 1/2 net: phy: mscc: Add PHY Netlink Interface along with Cable Diagnostics command

From: Raju Lakkaraju <[email protected]>

Add the PHY Netlink interface driver to implement the cable diagnostics of Microsemi Ethernet PHYs.

---
 drivers/net/phy/Kconfig       |   6 ++
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/phy.c         |  17 ++++
 drivers/net/phy/phy_netlink.c | 226 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy.h           |  88 ++++++++++++++++
 include/linux/phy_netlink.h   |  48 +++++++++
 6 files changed, 386 insertions(+)
 create mode 100644 drivers/net/phy/phy_netlink.c
 create mode 100644 include/linux/phy_netlink.h
drivers/net/phy/Kconfig +6 -0
index db5645b..a105058 100644
@@ -406,6 +406,12 @@ config MICROCHIP_T1_PHY
 	---help---
 	  Supports the LAN87XX PHYs.
 
+config PHY_NETLINK
+        tristate "PHY Netlink Interface"
+    depends on NET
+        ---help---
+          Supports the PHY netlink interface.
+
 config MICROSEMI_PHY
 	tristate "Microsemi PHYs"
 	---help---
drivers/net/phy/Makefile +1 -0
index bac339e..96aad9b 100644
@@ -80,6 +80,7 @@ obj-$(CONFIG_MICREL_KS8995MA)	+= spi_ks8995.o
 obj-$(CONFIG_MICREL_PHY)	+= micrel.o
 obj-$(CONFIG_MICROCHIP_PHY)	+= microchip.o
 obj-$(CONFIG_MICROCHIP_T1_PHY)	+= microchip_t1.o
+obj-$(CONFIG_PHY_NETLINK)	+= phy_netlink.o
 obj-$(CONFIG_MICROSEMI_PHY)	+= mscc.o
 obj-$(CONFIG_NATIONAL_PHY)	+= national.o
 obj-$(CONFIG_NXP_TJA11XX_PHY)	+= nxp-tja11xx.o
drivers/net/phy/phy.c +17 -0
index d915076..29b2921 100644
@@ -1251,3 +1251,20 @@ int phy_ethtool_nway_reset(struct net_device *ndev)
 	return phy_restart_aneg(phydev);
 }
 EXPORT_SYMBOL(phy_ethtool_nway_reset);
+
+int phy_cabdiag_request(struct net_device *ndev, struct phy_cabdiag_req *cfg)
+{
+	struct phy_device *phydev = ndev->phydev;
+
+	if (!phydev)
+		return -ENODEV;
+
+	if (!phydev->drv)
+		return -EIO;
+
+	if (phydev->drv->request_cable_diag)
+		return phydev->drv->request_cable_diag(phydev, cfg);
+
+	return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL(phy_cabdiag_request);
drivers/net/phy/phy_netlink.c new file +226 -0

226 lines not on this page · raw message

include/linux/phy.h +88 -0

106 lines not on this page · raw message

include/linux/phy_netlink.h new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

RFC 2/2 net: phy: mscc: Add PHY driver for Cable Diagnostics command

In reply to Raju Lakkaraju

From: Raju Lakkaraju <[email protected]>

Add the Cable diagnostics command to VSC85xx PHYs.

---
 drivers/net/phy/mscc.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 128 insertions(+)
drivers/net/phy/mscc.c +128 -0
index 28676af..98e3925 100644
@@ -153,9 +153,29 @@ enum rgmii_rx_clock_delay {
 #define MSCC_PHY_EXT_PHY_CNTL_4		  23
 #define PHY_CNTL_4_ADDR_POS		  11
 
+#define MSCC_PHY_VERIPHY_CNTL_1           24
+#define VERIPHY_TRIGGER_CNTL_MASK	  0x8000
+#define VERIPHY_VALID_MASK		  0x4000
+#define VERIPHY_PAIR_A_DISTANCE_MASK	  0x2F00
+#define VERIPHY_PAIR_A_DISTANCE_POS	  8
+#define VERIPHY_PAIR_B_DISTANCE_MASK	  0x002F
+#define VERIPHY_PAIR_B_DISTANCE_POS	  0
+
 #define MSCC_PHY_VERIPHY_CNTL_2		  25
+#define VERIPHY_PAIR_C_DISTANCE_MASK	  0x2F00
+#define VERIPHY_PAIR_C_DISTANCE_POS	  8
+#define VERIPHY_PAIR_D_DISTANCE_MASK	  0x002F
+#define VERIPHY_PAIR_D_DISTANCE_POS	  0
 
 #define MSCC_PHY_VERIPHY_CNTL_3		  26
+#define VERIPHY_PAIR_A_STATUS_MASK	  0xF000
+#define VERIPHY_PAIR_A_STATUS_POS	  12
+#define VERIPHY_PAIR_B_STATUS_MASK	  0x0F00
+#define VERIPHY_PAIR_B_STATUS_POS	  8
+#define VERIPHY_PAIR_C_STATUS_MASK	  0x00F0
+#define VERIPHY_PAIR_C_STATUS_POS	  4
+#define VERIPHY_PAIR_D_STATUS_MASK	  0x000F
+#define VERIPHY_PAIR_D_STATUS_POS	  0
 
 /* Extended Page 2 Registers */
 #define MSCC_PHY_CU_PMD_TX_CNTL		  16
@@ -442,6 +462,107 @@ static int vsc85xx_phy_write_page(struct phy_device *phydev, int page)
 	return __phy_write(phydev, MSCC_EXT_PAGE_ACCESS, page);
 }
 
+static int vsc85xx_cabdiag_request(struct phy_device *phydev,
+				   struct phy_cabdiag_req *cfg)
+{
+	u16 reg_val;
+	u8 timeout_cnt = 0;
+	int rc;
+
+	if (cfg->pairs_bitmask < CABDIAG_PAIR_A_MASK   ||
+	    (cfg->pairs_bitmask > (CABDIAG_PAIR_A_MASK |
+				   CABDIAG_PAIR_B_MASK |
+				   CABDIAG_PAIR_C_MASK |
+				   CABDIAG_PAIR_D_MASK))) {
+		cfg->op_status = CD_REQ_INVALID_PAIR_MASK;
+		return 0;
+	}
+	if (cfg->timeout_cnt == 0) {
+		cfg->op_status = CD_REQ_INVALID_TIMEOUT;
+		return 0;
+	}
+
+	mutex_lock(&phydev->lock);
+	rc = phy_select_page(phydev, MSCC_PHY_PAGE_EXTENDED);
+	if (rc < 0)
+		goto out_unlock;
+
+	reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_1);
+	if (reg_val & VERIPHY_TRIGGER_CNTL_MASK) {
+		cfg->op_status = CD_REQ_REJECTED_BUSY;
+		goto out_unlock;
+	}
+	/* Start Cable Diagnostics operation */
+	reg_val |= VERIPHY_TRIGGER_CNTL_MASK;
+	__phy_write(phydev, MSCC_PHY_VERIPHY_CNTL_1, reg_val);
+
+	/* Wait till VeriPHY has completed */
+	do {
+		msleep(30);
+		reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_1);
+	} while ((reg_val & VERIPHY_TRIGGER_CNTL_MASK) &&
+		 (timeout_cnt++ < cfg->timeout_cnt));
+
+	if (timeout_cnt >= cfg->timeout_cnt) {
+		cfg->op_status = CD_STATUS_FAILED_TIMEOUT;
+		goto out_unlock;
+	}
+	cfg->timeout_cnt = timeout_cnt;
+
+	if (reg_val & VERIPHY_VALID_MASK) {
+		/* VeriPHY results are valid */
+		if (cfg->pairs_bitmask & CABDIAG_PAIR_A_MASK) {
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_1);
+			cfg->pairs[CABDIAG_PAIR_A].length =
+			(reg_val & VERIPHY_PAIR_A_DISTANCE_MASK) >>
+			VERIPHY_PAIR_A_DISTANCE_POS;
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_3);
+			cfg->pairs[CABDIAG_PAIR_A].status =
+			(reg_val & VERIPHY_PAIR_A_STATUS_MASK) >>
+			VERIPHY_PAIR_A_STATUS_POS;
+		}
+		if (cfg->pairs_bitmask & CABDIAG_PAIR_B_MASK) {
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_1);
+			cfg->pairs[CABDIAG_PAIR_B].length =
+			(reg_val & VERIPHY_PAIR_B_DISTANCE_MASK) >>
+			VERIPHY_PAIR_B_DISTANCE_POS;
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_3);
+			cfg->pairs[CABDIAG_PAIR_B].status =
+			(reg_val & VERIPHY_PAIR_B_STATUS_MASK) >>
+			VERIPHY_PAIR_B_STATUS_POS;
+		}
+		if (cfg->pairs_bitmask & CABDIAG_PAIR_C_MASK) {
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_2);
+			cfg->pairs[CABDIAG_PAIR_C].length =
+			(reg_val & VERIPHY_PAIR_C_DISTANCE_MASK) >>
+			VERIPHY_PAIR_C_DISTANCE_POS;
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_3);
+			cfg->pairs[CABDIAG_PAIR_C].status =
+			(reg_val & VERIPHY_PAIR_C_STATUS_MASK) >>
+			VERIPHY_PAIR_C_STATUS_POS;
+		}
+		if (cfg->pairs_bitmask & CABDIAG_PAIR_D_MASK) {
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_2);
+			cfg->pairs[CABDIAG_PAIR_D].length =
+			(reg_val & VERIPHY_PAIR_D_DISTANCE_MASK) >>
+			VERIPHY_PAIR_D_DISTANCE_POS;
+			reg_val = __phy_read(phydev, MSCC_PHY_VERIPHY_CNTL_3);
+			cfg->pairs[CABDIAG_PAIR_D].status =
+			(reg_val & VERIPHY_PAIR_D_STATUS_MASK) >>
+			VERIPHY_PAIR_D_STATUS_POS;
+		}
+		cfg->op_status = CD_STATUS_SUCCESS;
+	} else {
+		cfg->op_status = CD_STATUS_FAILED_INVALID;
+	}
+
+out_unlock:
+	phy_restore_page(phydev, rc, rc > 0 ? 0 : rc);
+	mutex_unlock(&phydev->lock);
+
+	return rc;
+}
+
 static int vsc85xx_get_sset_count(struct phy_device *phydev)
 {
 	struct vsc8531_private *priv = phydev->priv;
@@ -2343,6 +2464,7 @@ static struct phy_driver vsc85xx_driver[] = {
 	.get_sset_count = &vsc85xx_get_sset_count,
 	.get_strings    = &vsc85xx_get_strings,
 	.get_stats      = &vsc85xx_get_stats,
+	.request_cable_diag = &vsc85xx_cabdiag_request,
 },
 {
 	.phy_id		= PHY_ID_VSC8530,
@@ -2368,6 +2490,7 @@ static struct phy_driver vsc85xx_driver[] = {
 	.get_sset_count = &vsc85xx_get_sset_count,
 	.get_strings    = &vsc85xx_get_strings,
 	.get_stats      = &vsc85xx_get_stats,
+	.request_cable_diag = &vsc85xx_cabdiag_request,
 },
 {
 	.phy_id		= PHY_ID_VSC8531,
@@ -2393,6 +2516,7 @@ static struct phy_driver vsc85xx_driver[] = {
 	.get_sset_count = &vsc85xx_get_sset_count,
 	.get_strings    = &vsc85xx_get_strings,
 	.get_stats      = &vsc85xx_get_stats,
+	.request_cable_diag = &vsc85xx_cabdiag_request,
 },
 {
 	.phy_id		= PHY_ID_VSC8540,
@@ -2418,6 +2542,7 @@ static struct phy_driver vsc85xx_driver[] = {
 	.get_sset_count = &vsc85xx_get_sset_count,
 	.get_strings    = &vsc85xx_get_strings,
 	.get_stats      = &vsc85xx_get_stats,
+	.request_cable_diag = &vsc85xx_cabdiag_request,
 },
 {
 	.phy_id		= PHY_ID_VSC8541,
@@ -2443,6 +2568,7 @@ static struct phy_driver vsc85xx_driver[] = {
 	.get_sset_count = &vsc85xx_get_sset_count,
 	.get_strings    = &vsc85xx_get_strings,
 	.get_stats      = &vsc85xx_get_stats,
+	.request_cable_diag = &vsc85xx_cabdiag_request,
 },
 {
 	.phy_id		= PHY_ID_VSC8574,
@@ -2469,6 +2595,7 @@ static struct phy_driver vsc85xx_driver[] = {
 	.get_sset_count = &vsc85xx_get_sset_count,
 	.get_strings    = &vsc85xx_get_strings,
 	.get_stats      = &vsc85xx_get_stats,
+	.request_cable_diag = &vsc85xx_cabdiag_request,
 },
 {
 	.phy_id		= PHY_ID_VSC8584,
@@ -2493,6 +2620,7 @@ static struct phy_driver vsc85xx_driver[] = {
 	.get_sset_count = &vsc85xx_get_sset_count,
 	.get_strings    = &vsc85xx_get_strings,
 	.get_stats      = &vsc85xx_get_stats,
+	.request_cable_diag = &vsc85xx_cabdiag_request,
 }
 
 };
Signature · 1 line
2.7.4
#3 lore raw
In reply to Raju Lakkaraju
Quoted 9 lines · Raju Lakkaraju

This series of patches add the Microsemi PHY cable diagnostics command with PHY Netlink Interface.

1. phy_netlink.c and phy_netlink.h files add for PHY diagnostics features implementation through PHY Netlink interface.
2. phy.c contain the generic functions of "PHY diagnostics". This layer independ of the communication layer (i.e. Netlink or IOCTL etc)
3. mscc.c contain the 4-pair ethernet PHY driver along with PHY diagnostics feature.

Andrew just submitted a similar feature set, except that his changes are much more comprehensive, and also build on top of ethtool-nl, meaning he has payed attention to the work that was going on within the netdev community.

Your submission on the other end appears to be looking for the minimum amount of code necessary to support the Microsemi PHYs product lines and does not try very hard to possibly think about an abstraction layer for other PHYs but Microsemi, that does not really give maintainers confidence that you have.

Can you review Andrew's patch series and see if you find something missing for you to plug in support for the Microsemi PHYs?

Quoted 35 lines

------------

# nl-app eth0 request
GroupID = 2
GroupName = phy_monitor

Cable Diagnostics Request:
Operation Status : Success
Cable Pairs mask : 0xf
Timeout count : 84
Cable diagnostics results:
Pair A: Correctly terminated pair, Loop Length: 0 m Pair B: Correctly terminated pair, Loop Length: 0 m Pair C: Correctly terminated pair, Loop Length: 0 m Pair D: Correctly terminated pair, Loop Length: 0 m

Application git repository path:
-------------------------------
https://github.com/lakkarajun/bbb_nl_app

Raju Lakkaraju (2):
net: phy: mscc: Add PHY Netlink Interface along with Cable Diagnostics
command
net: phy: mscc: Add PHY driver for Cable Diagnostics command

 drivers/net/phy/Kconfig       |   6 ++
 drivers/net/phy/Makefile      |   1 +
 drivers/net/phy/mscc.c        | 128 ++++++++++++++++++++++++
 drivers/net/phy/phy.c         |  17 ++++
 drivers/net/phy/phy_netlink.c | 226 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/phy.h           |  88 ++++++++++++++++
 include/linux/phy_netlink.h   |  48 +++++++++
 7 files changed, 514 insertions(+)
 create mode 100644 drivers/net/phy/phy_netlink.c
 create mode 100644 include/linux/phy_netlink.h
Signature · 1 line
Florian