[PATCH net-next V29 2/3] net: phy: Add support for Template Control register for PMA

From: Kyle Switch

Date: Tue Dec 01 2026 - 04:44:48 EST


Add support for the 10GBASE-T PMA Template Test Mode register
field, which allows selecting one of eight test modes (Normal and
TestMode1..TestMode7) used for PHY validation.

Reviewed-by: Andrew Lunn <andrew@xxxxxxx>
Signed-off-by: Kyle Switch <kyle.switch@xxxxxxxxxxxxxx>
---
drivers/net/phy/phy-c45.c | 20 ++++++++++++++++++++
include/linux/phy.h | 1 +
include/uapi/linux/mdio.h | 12 ++++++++++++
3 files changed, 33 insertions(+)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index 828af4c4e9d4..0136727767ac 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -1444,6 +1444,26 @@ int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable)
}
EXPORT_SYMBOL_GPL(genphy_c45_fast_retrain);

+/**
+ * genphy_c45_pma_test_mode - configure the 10GBASE-T PMA test mode register
+ * @phydev: target phy_device struct
+ * @test_mode: test mode to select, one of MDIO_PMA_10GBT_TESTMODE_*
+ *
+ * Set the 10GBASE-T PMA test mode to Normal or one of Test Mode 1..7.
+ *
+ * Return: 0 on success, or a negative error code on failure (e.g. register
+ * read/write error).
+ */
+int genphy_c45_pma_test_mode(struct phy_device *phydev, u16 test_mode)
+{
+ if (test_mode & ~MDIO_PMA_10GBT_TESTMODE_MASK)
+ return -EOPNOTSUPP;
+
+ return phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, MDIO_PMA_10GBT_TESTMODE,
+ MDIO_PMA_10GBT_TESTMODE_MASK, test_mode);
+}
+EXPORT_SYMBOL_GPL(genphy_c45_pma_test_mode);
+
/**
* genphy_c45_plca_get_cfg - get PLCA configuration from standard registers
* @phydev: target phy_device struct
diff --git a/include/linux/phy.h b/include/linux/phy.h
index f1b1ad1dd82f..7b401169ebe1 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -2368,6 +2368,7 @@ int genphy_c45_loopback(struct phy_device *phydev, bool enable, int speed);
int genphy_c45_pma_resume(struct phy_device *phydev);
int genphy_c45_pma_suspend(struct phy_device *phydev);
int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable);
+int genphy_c45_pma_test_mode(struct phy_device *phydev, u16 test_mode);
int genphy_c45_plca_get_cfg(struct phy_device *phydev,
struct phy_plca_cfg *plca_cfg);
int genphy_c45_plca_set_cfg(struct phy_device *phydev,
diff --git a/include/uapi/linux/mdio.h b/include/uapi/linux/mdio.h
index 2806f60ed105..40e76bc147be 100644
--- a/include/uapi/linux/mdio.h
+++ b/include/uapi/linux/mdio.h
@@ -63,6 +63,7 @@
/* Media-dependent registers. */
#define MDIO_PMA_10GBT_SWAPPOL 130 /* 10GBASE-T pair swap & polarity */
#define MDIO_PMA_10GBT_TXPWR 131 /* 10GBASE-T TX power control */
+#define MDIO_PMA_10GBT_TESTMODE 132 /* Test mode control */
#define MDIO_PMA_10GBT_SNR 133 /* 10GBASE-T SNR margin, lane A.
* Lanes B-D are numbered 134-136. */
#define MDIO_PMA_10GBR_FSRT_CSR 147 /* 10GBASE-R fast retrain status and control */
@@ -320,6 +321,17 @@
/* PMA 10GBASE-R Fast Retrain status and control register. */
#define MDIO_PMA_10GBR_FSRT_ENABLE 0x0001 /* Fast retrain enable */

+/* PMA 10GBASE-T test mode register */
+#define MDIO_PMA_10GBT_TESTMODE_MASK 0xE000 /* Test mode control */
+#define MDIO_PMA_10GBT_TESTMODE_NORMAL 0x0000 /* Normal */
+#define MDIO_PMA_10GBT_TESTMODE_1 0x2000 /* Test Mode 1 */
+#define MDIO_PMA_10GBT_TESTMODE_2 0x4000 /* Test Mode 2 */
+#define MDIO_PMA_10GBT_TESTMODE_3 0x6000 /* Test Mode 3 */
+#define MDIO_PMA_10GBT_TESTMODE_4 0x8000 /* Test Mode 4 */
+#define MDIO_PMA_10GBT_TESTMODE_5 0xA000 /* Test Mode 5 */
+#define MDIO_PMA_10GBT_TESTMODE_6 0xC000 /* Test Mode 6 */
+#define MDIO_PMA_10GBT_TESTMODE_7 0xE000 /* Test Mode 7 */
+
/* PCS 10GBASE-R/-T status register 1. */
#define MDIO_PCS_10GBRT_STAT1_BLKLK 0x0001 /* Block lock attained */

--
2.25.1