lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220401093909.3341836-3-horatiu.vultur@microchip.com>
Date:   Fri, 1 Apr 2022 11:39:09 +0200
From:   Horatiu Vultur <horatiu.vultur@...rochip.com>
To:     <netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     <andrew@...n.ch>, <hkallweit1@...il.com>, <linux@...linux.org.uk>,
        <davem@...emloft.net>, <kuba@...nel.org>,
        <richardcochran@...il.com>, <UNGLinuxDriver@...rochip.com>,
        Horatiu Vultur <horatiu.vultur@...rochip.com>
Subject: [RFC PATCH net-next 2/2] net: phy: micrel: Implement set/get_tunable

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

Signed-off-by: Horatiu Vultur <horatiu.vultur@...rochip.com>
---
 drivers/net/phy/micrel.c | 93 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
index fc53b71dc872..f537e61cb61d 100644
--- a/drivers/net/phy/micrel.c
+++ b/drivers/net/phy/micrel.c
@@ -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,
-- 
2.33.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ