Skip to contentSkip to conversation

ethtool: Extend to set PHY latencies

RFC PATCH In review Horatiu Vultur 2 participants 5 messages Apr 1, 2022

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

cover ethtool: Extend to set PHY latencies

Because there will always be a strugged to configure correct latencies, then don't allow the kernel or the DT to have these values but allow the userspace to configure them.
Therefore extend ethtool to allow to configure the latencies both per speed and direction.

Horatiu Vultur (2):
ethtool: Extend to allow to set PHY latencies
net: phy: micrel: Implement set/get_tunable

 drivers/net/phy/micrel.c     | 93 ++++++++++++++++++++++++++++++++++++
 include/uapi/linux/ethtool.h |  6 +++
 net/ethtool/common.c         |  6 +++
 net/ethtool/ioctl.c          | 10 ++++
 4 files changed, 115 insertions(+)
Signature · 1 line
2.33.0
#1 lore raw

RFC PATCH 1/2 ethtool: Extend to allow to set PHY latencies

Extend ethtool uapi to allow to configure the latencies for the PHY. Allow to configure the latency per speed and per direction.

---
 include/uapi/linux/ethtool.h |  6 ++++++
 net/ethtool/common.c         |  6 ++++++
 net/ethtool/ioctl.c          | 10 ++++++++++
 3 files changed, 22 insertions(+)
include/uapi/linux/ethtool.h +6 -0
index 7bc4b8def12c..f120904a4e43 100644
@@ -296,6 +296,12 @@ enum phy_tunable_id {
 	ETHTOOL_PHY_DOWNSHIFT,
 	ETHTOOL_PHY_FAST_LINK_DOWN,
 	ETHTOOL_PHY_EDPD,
+	ETHTOOL_PHY_LATENCY_RX_10MBIT,
+	ETHTOOL_PHY_LATENCY_TX_10MBIT,
+	ETHTOOL_PHY_LATENCY_RX_100MBIT,
+	ETHTOOL_PHY_LATENCY_TX_100MBIT,
+	ETHTOOL_PHY_LATENCY_RX_1000MBIT,
+	ETHTOOL_PHY_LATENCY_TX_1000MBIT,
 	/*
 	 * Add your fresh new phy tunable attribute above and remember to update
 	 * phy_tunable_strings[] in net/ethtool/common.c
net/ethtool/common.c +6 -0
index 0c5210015911..e0fec9eec047 100644
@@ -98,6 +98,12 @@ phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = {
 	[ETHTOOL_PHY_DOWNSHIFT]	= "phy-downshift",
 	[ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down",
 	[ETHTOOL_PHY_EDPD]	= "phy-energy-detect-power-down",
+	[ETHTOOL_PHY_LATENCY_RX_10MBIT] = "phy-latency-rx-10mbit",
+	[ETHTOOL_PHY_LATENCY_TX_10MBIT] = "phy-latency-tx-10mbit",
+	[ETHTOOL_PHY_LATENCY_RX_100MBIT] = "phy-latency-rx-100mbit",
+	[ETHTOOL_PHY_LATENCY_TX_100MBIT] = "phy-lantecy-tx-100mbit",
+	[ETHTOOL_PHY_LATENCY_RX_1000MBIT] = "phy-latency-rx-1000mbit",
+	[ETHTOOL_PHY_LATENCY_TX_1000MBIT] = "phy-latency-tx-1000mbit",
 };
 
 #define __LINK_MODE_NAME(speed, type, duplex) \
net/ethtool/ioctl.c +10 -0
index 326e14ee05db..a1caee4ef5b9 100644
@@ -2605,6 +2605,16 @@ static int ethtool_phy_tunable_valid(const struct ethtool_tunable *tuna)
 		    tuna->type_id != ETHTOOL_TUNABLE_U16)
 			return -EINVAL;
 		break;
+	case ETHTOOL_PHY_LATENCY_RX_10MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_10MBIT:
+	case ETHTOOL_PHY_LATENCY_RX_100MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_100MBIT:
+	case ETHTOOL_PHY_LATENCY_RX_1000MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_1000MBIT:
+		if (tuna->len != sizeof(s32) ||
+		    tuna->type_id != ETHTOOL_TUNABLE_S32)
+			return -EINVAL;
+		break;
 	default:
 		return -EINVAL;
 	}
Signature · 1 line
2.33.0
maintainer
#2 lore raw

Re: [RFC PATCH net-next 1/2] ethtool: Extend to allow to set PHY latencies

Quoted 15 lines · Horatiu Vultur

Extend ethtool uapi to allow to configure the latencies for the PHY. Allow to configure the latency per speed and per direction.

---
 include/uapi/linux/ethtool.h |  6 ++++++
 net/ethtool/common.c         |  6 ++++++
 net/ethtool/ioctl.c          | 10 ++++++++++
 3 files changed, 22 insertions(+)
include/uapi/linux/ethtool.h +0 -0
index 7bc4b8def12c..f120904a4e43 100644

include/uapi/linux/ethtool.h enum phy_tunable_id { · line 304

Quoted 9 lines
include/uapi/linux/ethtool.h +6 -0
@@ -296,6 +296,12 @@ enum phy_tunable_id {
 	ETHTOOL_PHY_DOWNSHIFT,
 	ETHTOOL_PHY_FAST_LINK_DOWN,
 	ETHTOOL_PHY_EDPD,
+	ETHTOOL_PHY_LATENCY_RX_10MBIT,
+	ETHTOOL_PHY_LATENCY_TX_10MBIT,
+	ETHTOOL_PHY_LATENCY_RX_100MBIT,
+	ETHTOOL_PHY_LATENCY_TX_100MBIT,
+	ETHTOOL_PHY_LATENCY_RX_1000MBIT,
+	ETHTOOL_PHY_LATENCY_TX_1000MBIT,

How does this scale with 2.5G, 5G, 10G, 14G, 40G, etc.

Could half duplex differ to full duplex? What about 1000BaseT vs 1000BaseT1 and 1000BaseT2? The Aquantia/Marvell PHY can do both 1000BaseT and 1000BaseT2 and will downshift from 4 pairs to 2 pairs if you have the correct magic in its firmware blobs.

A more generic API would pass a link mode, a direction and a latency. The driver can then return -EOPNOTSUPP for a mode it does not support.

Andrew

#3 lore raw

Re: [RFC PATCH net-next 1/2] ethtool: Extend to allow to set PHY latencies

Quoted 29 lines · Andrew Lunn
Quoted 15 lines · Horatiu Vultur

Extend ethtool uapi to allow to configure the latencies for the PHY. Allow to configure the latency per speed and per direction.

---
 include/uapi/linux/ethtool.h |  6 ++++++
 net/ethtool/common.c         |  6 ++++++
 net/ethtool/ioctl.c          | 10 ++++++++++
 3 files changed, 22 insertions(+)
include/uapi/linux/ethtool.h +0 -0
index 7bc4b8def12c..f120904a4e43 100644

include/uapi/linux/ethtool.h enum phy_tunable_id { · line 304

Quoted 9 lines
include/uapi/linux/ethtool.h +6 -0
@@ -296,6 +296,12 @@ enum phy_tunable_id {
      ETHTOOL_PHY_DOWNSHIFT,
      ETHTOOL_PHY_FAST_LINK_DOWN,
      ETHTOOL_PHY_EDPD,
+     ETHTOOL_PHY_LATENCY_RX_10MBIT,
+     ETHTOOL_PHY_LATENCY_TX_10MBIT,
+     ETHTOOL_PHY_LATENCY_RX_100MBIT,
+     ETHTOOL_PHY_LATENCY_TX_100MBIT,
+     ETHTOOL_PHY_LATENCY_RX_1000MBIT,
+     ETHTOOL_PHY_LATENCY_TX_1000MBIT,

How does this scale with 2.5G, 5G, 10G, 14G, 40G, etc.

Quoted 8 lines

Could half duplex differ to full duplex? What about 1000BaseT vs 1000BaseT1 and 1000BaseT2? The Aquantia/Marvell PHY can do both 1000BaseT and 1000BaseT2 and will downshift from 4 pairs to 2 pairs if you have the correct magic in its firmware blobs.

A more generic API would pass a link mode, a direction and a latency. The driver can then return -EOPNOTSUPP for a mode it does not support.

Yes, I can see your point, the proposed solution is not scalable. I will try implement something like you suggested.

Quoted 2 lines

Andrew

Signature · 1 line
/Horatiu
#4 lore raw

RFC PATCH 2/2 net: phy: micrel: Implement set/get_tunable

In reply to Horatiu Vultur

Implement set/get_tunable to set/get the PHY latencies.

---
 drivers/net/phy/micrel.c | 93 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)
drivers/net/phy/micrel.c +93 -0
index fc53b71dc872..f537e61cb61d 100644
@@ -99,6 +99,15 @@
 #define PTP_TIMESTAMP_EN_PDREQ_			BIT(2)
 #define PTP_TIMESTAMP_EN_PDRES_			BIT(3)
 
+#define PTP_RX_LATENCY_1000			0x0224
+#define PTP_TX_LATENCY_1000			0x0225
+
+#define PTP_RX_LATENCY_100			0x0222
+#define PTP_TX_LATENCY_100			0x0223
+
+#define PTP_RX_LATENCY_10			0x0220
+#define PTP_TX_LATENCY_10			0x0221
+
 #define PTP_TX_PARSE_L2_ADDR_EN			0x0284
 #define PTP_RX_PARSE_L2_ADDR_EN			0x0244
 
@@ -2591,6 +2600,88 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev)
 	return 0;
 }
 
+static void lan8814_get_latency(struct phy_device *phydev, u32 id, s32 *latency)
+{
+	switch (id) {
+	case ETHTOOL_PHY_LATENCY_RX_10MBIT:
+		*latency = lanphy_read_page_reg(phydev, 5, PTP_RX_LATENCY_10);
+		break;
+	case ETHTOOL_PHY_LATENCY_TX_10MBIT:
+		*latency = lanphy_read_page_reg(phydev, 5, PTP_TX_LATENCY_10);
+		break;
+	case ETHTOOL_PHY_LATENCY_RX_100MBIT:
+		*latency = lanphy_read_page_reg(phydev, 5, PTP_RX_LATENCY_100);
+		break;
+	case ETHTOOL_PHY_LATENCY_TX_100MBIT:
+		*latency = lanphy_read_page_reg(phydev, 5, PTP_TX_LATENCY_100);
+		break;
+	case ETHTOOL_PHY_LATENCY_RX_1000MBIT:
+		*latency = lanphy_read_page_reg(phydev, 5, PTP_RX_LATENCY_1000);
+		break;
+	case ETHTOOL_PHY_LATENCY_TX_1000MBIT:
+		*latency = lanphy_read_page_reg(phydev, 5, PTP_TX_LATENCY_1000);
+		break;
+	}
+}
+
+static int lan8814_get_tunable(struct phy_device *phydev,
+			       struct ethtool_tunable *tuna, void *data)
+{
+	switch (tuna->id) {
+	case ETHTOOL_PHY_LATENCY_RX_10MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_10MBIT:
+	case ETHTOOL_PHY_LATENCY_RX_100MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_100MBIT:
+	case ETHTOOL_PHY_LATENCY_RX_1000MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_1000MBIT:
+		lan8814_get_latency(phydev, tuna->id, data);
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static void lan8814_set_latency(struct phy_device *phydev, u32 id, s32 latency)
+{
+	switch (id) {
+	case ETHTOOL_PHY_LATENCY_RX_10MBIT:
+		lanphy_write_page_reg(phydev, 5, PTP_RX_LATENCY_10, latency);
+		break;
+	case ETHTOOL_PHY_LATENCY_TX_10MBIT:
+		lanphy_write_page_reg(phydev, 5, PTP_TX_LATENCY_10, latency);
+		break;
+	case ETHTOOL_PHY_LATENCY_RX_100MBIT:
+		lanphy_write_page_reg(phydev, 5, PTP_RX_LATENCY_100, latency);
+		break;
+	case ETHTOOL_PHY_LATENCY_TX_100MBIT:
+		lanphy_write_page_reg(phydev, 5, PTP_TX_LATENCY_100, latency);
+		break;
+	case ETHTOOL_PHY_LATENCY_RX_1000MBIT:
+		lanphy_write_page_reg(phydev, 5, PTP_RX_LATENCY_1000, latency);
+		break;
+	case ETHTOOL_PHY_LATENCY_TX_1000MBIT:
+		lanphy_write_page_reg(phydev, 5, PTP_TX_LATENCY_1000, latency);
+		break;
+	}
+}
+
+static int lan8814_set_tunable(struct phy_device *phydev,
+			       struct ethtool_tunable *tuna, const void *data)
+{
+	switch (tuna->id) {
+	case ETHTOOL_PHY_LATENCY_RX_10MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_10MBIT:
+	case ETHTOOL_PHY_LATENCY_RX_100MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_100MBIT:
+	case ETHTOOL_PHY_LATENCY_RX_1000MBIT:
+	case ETHTOOL_PHY_LATENCY_TX_1000MBIT:
+		lan8814_set_latency(phydev, tuna->id, *(const s32 *)data);
+		return 0;
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
 static int lan8814_config_init(struct phy_device *phydev)
 {
 	int val;
@@ -2827,6 +2918,8 @@ static struct phy_driver ksphy_driver[] = {
 	.probe		= lan8814_probe,
 	.soft_reset	= genphy_soft_reset,
 	.read_status	= ksz9031_read_status,
+	.get_tunable	= lan8814_get_tunable,
+	.set_tunable	= lan8814_set_tunable,
 	.get_sset_count	= kszphy_get_sset_count,
 	.get_strings	= kszphy_get_strings,
 	.get_stats	= kszphy_get_stats,
Signature · 1 line
2.33.0