Skip to contentSkip to conversation

Add support for handling master/slave in forced mode

PATCH In review Ilya A. Evenbach 4 participants 7 messages Aug 19, 2025 – Aug 22, 2025 1 message not in the archive

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

PATCH 1/1 Add support for handling master/slave in forced mode

88q2xxx PHYs have non-standard way of setting master/slave in forced mode.
This change adds support for changing and reporting this setting correctly through ethtool.

---
 drivers/net/phy/marvell-88q2xxx.c | 107 ++++++++++++++++++++++++++++--
 1 file changed, 102 insertions(+), 5 deletions(-)
drivers/net/phy/marvell-88q2xxx.c +102 -5
index f3d83b04c953..1ab450056e86 100644
@@ -9,6 +9,7 @@
 #include <linux/ethtool_netlink.h>
 #include <linux/hwmon.h>
 #include <linux/marvell_phy.h>
+#include <linux/mdio.h>
 #include <linux/of.h>
 #include <linux/phy.h>
 
@@ -118,6 +119,11 @@
 #define MV88Q2XXX_LED_INDEX_TX_ENABLE			0
 #define MV88Q2XXX_LED_INDEX_GPIO			1
 
+/* Marvell vendor PMA/PMD control for forced master/slave when AN is disabled */
+#define PMAPMD_MVL_PMAPMD_CTL				0x0834
+#define MASTER_MODE					BIT(14)
+#define MODE_MASK					BIT(14)
+
 struct mv88q2xxx_priv {
 	bool enable_led0;
 };
@@ -377,13 +383,57 @@ static int mv88q2xxx_read_link(struct phy_device *phydev)
 static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 {
 	int ret;
+	int adv_l, adv_m, stat, stat2;
+
+	/* In forced mode, state and config are controlled via PMAPMD 0x834 */
+	if (phydev->autoneg == AUTONEG_DISABLE) {
+		ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, PMAPMD_MVL_PMAPMD_CTL);
+		if (ret < 0)
+			return ret;
+
+		if (ret & MASTER_MODE) {
+			phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
+			phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
+		} else {
+			phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
+			phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_FORCE;
+		}
+		return 0;
+	}
 
-	phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
-	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
-	if (ret < 0)
-		return ret;
 
-	if (ret & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
+	adv_l = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_L);
+	if (adv_l < 0)
+		return adv_l;
+	adv_m = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_M);
+	if (adv_m < 0)
+		return adv_m;
+
+	if (adv_l & MDIO_AN_T1_ADV_L_FORCE_MS)
+		phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
+	else if (adv_m & MDIO_AN_T1_ADV_M_MST)
+		phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_PREFERRED;
+	else
+		phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_PREFERRED;
+
+	stat = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
+	if (stat < 0)
+		return stat;
+
+	if (stat & MDIO_MMD_AN_MV_STAT_MS_CONF_FAULT) {
+		phydev->master_slave_state = MASTER_SLAVE_STATE_ERR;
+		return 0;
+	}
+
+	stat2 = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT2);
+	if (stat2 < 0)
+		return stat2;
+	if (!(stat2 & MDIO_MMD_AN_MV_STAT2_AN_RESOLVED)) {
+		phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
+		return 0;
+	}
+
+	if (stat & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
 		phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
 	else
 		phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
@@ -391,6 +441,34 @@ static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 	return 0;
 }
 
+static int mv88q2xxx_setup_master_slave_forced(struct phy_device *phydev)
+{
+	int ret = 0;
+
+	switch (phydev->master_slave_set) {
+	case MASTER_SLAVE_CFG_MASTER_FORCE:
+	case MASTER_SLAVE_CFG_MASTER_PREFERRED:
+		ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+					     PMAPMD_MVL_PMAPMD_CTL,
+					     MODE_MASK, MASTER_MODE);
+		break;
+	case MASTER_SLAVE_CFG_SLAVE_FORCE:
+	case MASTER_SLAVE_CFG_SLAVE_PREFERRED:
+		ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+					     PMAPMD_MVL_PMAPMD_CTL,
+					     MODE_MASK, 0);
+		break;
+	case MASTER_SLAVE_CFG_UNKNOWN:
+	case MASTER_SLAVE_CFG_UNSUPPORTED:
+	default:
+		phydev_warn(phydev, "Unsupported Master/Slave mode\n");
+		ret = 0;
+		break;
+	}
+
+	return ret;
+}
+
 static int mv88q2xxx_read_aneg_speed(struct phy_device *phydev)
 {
 	int ret;
@@ -448,6 +526,11 @@ static int mv88q2xxx_read_status(struct phy_device *phydev)
 	if (ret < 0)
 		return ret;
 
+	/* Populate master/slave status also for forced modes */
+	ret = mv88q2xxx_read_master_slave_state(phydev);
+	if (ret < 0 && ret != -EOPNOTSUPP)
+		return ret;
+
 	return genphy_c45_read_pma(phydev);
 }
 
@@ -478,6 +561,20 @@ static int mv88q2xxx_config_aneg(struct phy_device *phydev)
 	if (ret)
 		return ret;
 
+	/* Configure Base-T1 master/slave per phydev->master_slave_set.
+	 * For AN disabled, program PMAPMD role directly; otherwise rely on
+	 * the standard Base-T1 AN advertisement bits.
+	 */
+	if (phydev->autoneg == AUTONEG_DISABLE) {
+		ret = mv88q2xxx_setup_master_slave_forced(phydev);
+		if (ret)
+			return ret;
+	} else {
+		ret = genphy_c45_pma_baset1_setup_master_slave(phydev);
+		if (ret)
+			return ret;
+	}
+
 	return phydev->drv->soft_reset(phydev);
 }
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 4 lines · Ilya A. Evenbach

88q2xxx PHYs have non-standard way of setting master/slave in forced mode.
This change adds support for changing and reporting this setting correctly through ethtool.

Please could you Cc: Dimitri Fedrau <[email protected]>. He has done most of the work on this driver.

Quoted 10 lines
---
 drivers/net/phy/marvell-88q2xxx.c | 107 ++++++++++++++++++++++++++++--
 1 file changed, 102 insertions(+), 5 deletions(-)
drivers/net/phy/marvell-88q2xxx.c +0 -0
index f3d83b04c953..1ab450056e86 100644

drivers/net/phy/marvell-88q2xxx.c line 12

Quoted 4 lines
drivers/net/phy/marvell-88q2xxx.c +1 -0
@@ -9,6 +9,7 @@
 #include <linux/ethtool_netlink.h>
 #include <linux/hwmon.h>
 #include <linux/marvell_phy.h>
+#include <linux/mdio.h>

I'm curious. What is needed from this?

Andrew

#2 lore raw

Quoted 2 lines

Please could you Cc: Dimitri Fedrau <[email protected]>. He has done most of the work on this driver.

Done

Quoted 3 lines
Quoted 1 line

+#include <linux/mdio.h>

I'm curious. What is needed from this?

Oops. This is, indeed, unneeded. Fixed.

#3 lore raw

PATCH 1/1 Add support for handling master/slave in forced mode

88q2xxx PHYs have non-standard way of setting master/slave in forced mode.
This change adds support for changing and reporting this setting correctly through ethtool.

---
 drivers/net/phy/marvell-88q2xxx.c | 106 ++++++++++++++++++++++++++++--
 1 file changed, 101 insertions(+), 5 deletions(-)
drivers/net/phy/marvell-88q2xxx.c +101 -5
index f3d83b04c953..b94d574fd9b7 100644
@@ -118,6 +118,11 @@
 #define MV88Q2XXX_LED_INDEX_TX_ENABLE			0
 #define MV88Q2XXX_LED_INDEX_GPIO			1
 
+/* Marvell vendor PMA/PMD control for forced master/slave when AN is disabled */
+#define PMAPMD_MVL_PMAPMD_CTL				0x0834
+#define MASTER_MODE					BIT(14)
+#define MODE_MASK					BIT(14)
+
 struct mv88q2xxx_priv {
 	bool enable_led0;
 };
@@ -377,13 +382,57 @@ static int mv88q2xxx_read_link(struct phy_device *phydev)
 static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 {
 	int ret;
+	int adv_l, adv_m, stat, stat2;
+
+	/* In forced mode, state and config are controlled via PMAPMD 0x834 */
+	if (phydev->autoneg == AUTONEG_DISABLE) {
+		ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, PMAPMD_MVL_PMAPMD_CTL);
+		if (ret < 0)
+			return ret;
+
+		if (ret & MASTER_MODE) {
+			phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
+			phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
+		} else {
+			phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
+			phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_FORCE;
+		}
+		return 0;
+	}
 
-	phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
-	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
-	if (ret < 0)
-		return ret;
 
-	if (ret & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
+	adv_l = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_L);
+	if (adv_l < 0)
+		return adv_l;
+	adv_m = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_M);
+	if (adv_m < 0)
+		return adv_m;
+
+	if (adv_l & MDIO_AN_T1_ADV_L_FORCE_MS)
+		phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
+	else if (adv_m & MDIO_AN_T1_ADV_M_MST)
+		phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_PREFERRED;
+	else
+		phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_PREFERRED;
+
+	stat = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
+	if (stat < 0)
+		return stat;
+
+	if (stat & MDIO_MMD_AN_MV_STAT_MS_CONF_FAULT) {
+		phydev->master_slave_state = MASTER_SLAVE_STATE_ERR;
+		return 0;
+	}
+
+	stat2 = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT2);
+	if (stat2 < 0)
+		return stat2;
+	if (!(stat2 & MDIO_MMD_AN_MV_STAT2_AN_RESOLVED)) {
+		phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
+		return 0;
+	}
+
+	if (stat & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
 		phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
 	else
 		phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
@@ -391,6 +440,34 @@ static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 	return 0;
 }
 
+static int mv88q2xxx_setup_master_slave_forced(struct phy_device *phydev)
+{
+	int ret = 0;
+
+	switch (phydev->master_slave_set) {
+	case MASTER_SLAVE_CFG_MASTER_FORCE:
+	case MASTER_SLAVE_CFG_MASTER_PREFERRED:
+		ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+					     PMAPMD_MVL_PMAPMD_CTL,
+					     MODE_MASK, MASTER_MODE);
+		break;
+	case MASTER_SLAVE_CFG_SLAVE_FORCE:
+	case MASTER_SLAVE_CFG_SLAVE_PREFERRED:
+		ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+					     PMAPMD_MVL_PMAPMD_CTL,
+					     MODE_MASK, 0);
+		break;
+	case MASTER_SLAVE_CFG_UNKNOWN:
+	case MASTER_SLAVE_CFG_UNSUPPORTED:
+	default:
+		phydev_warn(phydev, "Unsupported Master/Slave mode\n");
+		ret = 0;
+		break;
+	}
+
+	return ret;
+}
+
 static int mv88q2xxx_read_aneg_speed(struct phy_device *phydev)
 {
 	int ret;
@@ -448,6 +525,11 @@ static int mv88q2xxx_read_status(struct phy_device *phydev)
 	if (ret < 0)
 		return ret;
 
+	/* Populate master/slave status also for forced modes */
+	ret = mv88q2xxx_read_master_slave_state(phydev);
+	if (ret < 0 && ret != -EOPNOTSUPP)
+		return ret;
+
 	return genphy_c45_read_pma(phydev);
 }
 
@@ -478,6 +560,20 @@ static int mv88q2xxx_config_aneg(struct phy_device *phydev)
 	if (ret)
 		return ret;
 
+	/* Configure Base-T1 master/slave per phydev->master_slave_set.
+	 * For AN disabled, program PMAPMD role directly; otherwise rely on
+	 * the standard Base-T1 AN advertisement bits.
+	 */
+	if (phydev->autoneg == AUTONEG_DISABLE) {
+		ret = mv88q2xxx_setup_master_slave_forced(phydev);
+		if (ret)
+			return ret;
+	} else {
+		ret = genphy_c45_pma_baset1_setup_master_slave(phydev);
+		if (ret)
+			return ret;
+	}
+
 	return phydev->drv->soft_reset(phydev);
 }
 
Signature · 1 line
2.34.1
maintainer
#4 lore raw

A few drive-by comments...

Quoted 1 line · On Wed, 20 Aug 2025 11:11:43 -0700 Ilya A. Evenbach wrote:

In-Reply-To: <[email protected]>

Please start a new thread for each new revision. Change subject to [PATCH vN], where vN is the revision. Add

v1: https://lore.kernel.org/[email protected]

under the --- for reference to older versions

Quoted 1 line
Cc [email protected], "Ilya A. Evenbach" <[email protected]>

The cc list is still pretty sparse

Quoted 1 line

Subject: [PATCH] [88q2xxx] Add support for handling master/slave in forced mode

the [88q2xxx] will be stripped by git when applying. Please look thru the history of the file and find the correct way to prefix.

Quoted 4 lines

88q2xxx PHYs have non-standard way of setting master/slave in forced mode.
This change adds support for changing and reporting this setting correctly through ethtool.

imperative mood:

Add support for changing...

drivers/net/phy/marvell-88q2xxx.c line 124

Quoted 4 lines
drivers/net/phy/marvell-88q2xxx.c +4 -0
+/* Marvell vendor PMA/PMD control for forced master/slave when AN is disabled */
+#define PMAPMD_MVL_PMAPMD_CTL				0x0834
+#define MASTER_MODE					BIT(14)
+#define MODE_MASK					BIT(14)

Other defines in context seem to be prefixed with MV88Q2XXX_ please prefer prefixing local defines.

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device *phydev) · line 385

Quoted 8 lines

struct mv88q2xxx_priv {

drivers/net/phy/marvell-88q2xxx.c +1 -0
 	bool enable_led0;
 };
@@ -377,13 +382,57 @@ static int mv88q2xxx_read_link(struct phy_device *phydev)
 static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 {
 	int ret;
+	int adv_l, adv_m, stat, stat2;

nit: in networking we like variable declaration lines to be sorted longest to shortest.

Signature · 1 line
pw-bot: cr
#5 lore raw
In reply to Ilya A. Evenbach

Hi Ilya,

Am Wed, Aug 20, 2025 at 11:11:43AM -0700 schrieb Ilya A. Evenbach:

Quoted 15 lines

88q2xxx PHYs have non-standard way of setting master/slave in forced mode.
This change adds support for changing and reporting this setting correctly through ethtool.

---
 drivers/net/phy/marvell-88q2xxx.c | 106 ++++++++++++++++++++++++++++--
 1 file changed, 101 insertions(+), 5 deletions(-)
drivers/net/phy/marvell-88q2xxx.c +0 -0
index f3d83b04c953..b94d574fd9b7 100644

drivers/net/phy/marvell-88q2xxx.c line 122

Quoted 5 lines
drivers/net/phy/marvell-88q2xxx.c +2 -0
@@ -118,6 +118,11 @@
 #define MV88Q2XXX_LED_INDEX_TX_ENABLE			0
 #define MV88Q2XXX_LED_INDEX_GPIO			1
 
+/* Marvell vendor PMA/PMD control for forced master/slave when AN is disabled */
+#define PMAPMD_MVL_PMAPMD_CTL				0x0834

Already defined, see MDIO_PMA_PMD_BT1_CTRL.

drivers/net/phy/marvell-88q2xxx.c line 123

Quoted 1 line
drivers/net/phy/marvell-88q2xxx.c +1 -0
+#define MASTER_MODE					BIT(14)

Already defines, see MDIO_PMA_PMD_BT1_CTRL_CFG_MST.

Quoted 69 lines
drivers/net/phy/marvell-88q2xxx.c +51 -5
+#define MODE_MASK					BIT(14)
+
 struct mv88q2xxx_priv {
 	bool enable_led0;
 };
@@ -377,13 +382,57 @@ static int mv88q2xxx_read_link(struct phy_device *phydev)
 static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 {
 	int ret;
+	int adv_l, adv_m, stat, stat2;
+
+	/* In forced mode, state and config are controlled via PMAPMD 0x834 */
+	if (phydev->autoneg == AUTONEG_DISABLE) {
+		ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, PMAPMD_MVL_PMAPMD_CTL);
+		if (ret < 0)
+			return ret;
+
+		if (ret & MASTER_MODE) {
+			phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
+			phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
+		} else {
+			phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
+			phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_FORCE;
+		}
+		return 0;
+	}
 
-	phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
-	ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
-	if (ret < 0)
-		return ret;
 
-	if (ret & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
+	adv_l = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_L);
+	if (adv_l < 0)
+		return adv_l;
+	adv_m = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_M);
+	if (adv_m < 0)
+		return adv_m;
+
+	if (adv_l & MDIO_AN_T1_ADV_L_FORCE_MS)
+		phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
+	else if (adv_m & MDIO_AN_T1_ADV_M_MST)
+		phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_PREFERRED;
+	else
+		phydev->master_slave_get = MASTER_SLAVE_CFG_SLAVE_PREFERRED;
+
+	stat = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
+	if (stat < 0)
+		return stat;
+
+	if (stat & MDIO_MMD_AN_MV_STAT_MS_CONF_FAULT) {
+		phydev->master_slave_state = MASTER_SLAVE_STATE_ERR;
+		return 0;
+	}
+
+	stat2 = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT2);
+	if (stat2 < 0)
+		return stat2;
+	if (!(stat2 & MDIO_MMD_AN_MV_STAT2_AN_RESOLVED)) {
+		phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
+		return 0;
+	}
+
+	if (stat & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
 		phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
 	else
 		phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev) · line 442

Quoted 3 lines
drivers/net/phy/marvell-88q2xxx.c +0 -0
@@ -391,6 +440,34 @@ static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 	return 0;
 }
 

Is there a issue with the function you are trying to fix ? Seems that you copied some generic functions into it.

Quoted 18 lines
drivers/net/phy/marvell-88q2xxx.c +18 -0
+static int mv88q2xxx_setup_master_slave_forced(struct phy_device *phydev)
+{
+	int ret = 0;
+
+	switch (phydev->master_slave_set) {
+	case MASTER_SLAVE_CFG_MASTER_FORCE:
+	case MASTER_SLAVE_CFG_MASTER_PREFERRED:
+		ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+					     PMAPMD_MVL_PMAPMD_CTL,
+					     MODE_MASK, MASTER_MODE);
+		break;
+	case MASTER_SLAVE_CFG_SLAVE_FORCE:
+	case MASTER_SLAVE_CFG_SLAVE_PREFERRED:
+		ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+					     PMAPMD_MVL_PMAPMD_CTL,
+					     MODE_MASK, 0);
+		break;
+	case MASTER_SLAVE_CFG_UNKNOWN:

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev) · line 470

Quoted 10 lines
drivers/net/phy/marvell-88q2xxx.c +10 -0
+	case MASTER_SLAVE_CFG_UNSUPPORTED:
+	default:
+		phydev_warn(phydev, "Unsupported Master/Slave mode\n");
+		ret = 0;
+		break;
+	}
+
+	return ret;
+}
+

This function does the same as genphy_c45_pma_baset1_setup_master_slave. Please use the generic function. Besides you are introducing register PMAPMD_MVL_PMAPMD_CTL which is MDIO_PMA_PMD_BT1_CTRL.

Quoted 5 lines
drivers/net/phy/marvell-88q2xxx.c +0 -0
 static int mv88q2xxx_read_aneg_speed(struct phy_device *phydev)
 {
 	int ret;
@@ -448,6 +525,11 @@ static int mv88q2xxx_read_status(struct phy_device *phydev)
 	if (ret < 0)

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_status(struct phy_device *phydev) · line 535

Quoted 10 lines
drivers/net/phy/marvell-88q2xxx.c +5 -0
 		return ret;
 
+	/* Populate master/slave status also for forced modes */
+	ret = mv88q2xxx_read_master_slave_state(phydev);
+	if (ret < 0 && ret != -EOPNOTSUPP)
+		return ret;
+
 	return genphy_c45_read_pma(phydev);
 }
 

Why ? This function is only used in case AUTONEG_ENABLE.

Quoted 11 lines
drivers/net/phy/marvell-88q2xxx.c +7 -0
@@ -478,6 +560,20 @@ static int mv88q2xxx_config_aneg(struct phy_device *phydev)
 	if (ret)
 		return ret;
 
+	/* Configure Base-T1 master/slave per phydev->master_slave_set.
+	 * For AN disabled, program PMAPMD role directly; otherwise rely on
+	 * the standard Base-T1 AN advertisement bits.
+	 */
+	if (phydev->autoneg == AUTONEG_DISABLE) {
+		ret = mv88q2xxx_setup_master_slave_forced(phydev);
+		if (ret)

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_config_aneg(struct phy_device *phydev) · line 579

Quoted 10 lines
drivers/net/phy/marvell-88q2xxx.c +7 -0
+			return ret;
+	} else {
+		ret = genphy_c45_pma_baset1_setup_master_slave(phydev);
+		if (ret)
+			return ret;
+	}
+
 	return phydev->drv->soft_reset(phydev);
 }
 

I don't see any reason why genphy_c45_config_aneg isn't sufficient here. In case AUTONEG_DISABLE, genphy_c45_pma_setup_forced is called and calls genphy_c45_pma_baset1_setup_master_slave which is basically the same as mv88q2xxx_setup_master_slave_forced.
In case AUTONEG_ENABLE, calling genphy_c45_pma_baset1_setup_master_slave is wrong, please look how genphy_c45_an_config_aneg is implemented.

Please take other users of the driver into CC, they did a lot of reviewing and testing in the past. If there is some issue with the driver, they should know:

"Niklas Söderlund" <[email protected]> "Gregor Herburger" <[email protected]> "Stefan Eichenberger" <[email protected]>
"Geert Uytterhoeven" <[email protected]>

Which device are you using, and why did you need this patch ? Is there any issue you are trying to fix ? On my side I did a lot of testing with the different modes and never experienced any problems so far.

Best regards,
Dimitri Fedrau

A message that is not in the archive (sent off-list or not yet received): CAJmffrpUTzH0_siTUZodX7Gu5JPRvkgUb+73CgXSWu1QSzegSA@mail.gmail.com

#7 lore raw

Hi Ilya,

Am Thu, Aug 21, 2025 at 01:53:04PM -0700 schrieb Ilya Evenbach:

Quoted 4 lines

I am using 88Q2221, This PHY has a bug - MDIO_PMA_EXTABLE is not properly implemented (reads as 0x20).
As a result, genphy_c45_baset1_able() returns false, and master/slave is not set up or read properly in forced mode.

That is not 88Q2221 specific, please have a look at function mv88q2xxx_config_init which solves this issue:

/* The 88Q2XXX PHYs do have the extended ability register available, but
* register MDIO_PMA_EXTABLE where they should signalize it does not
* work according to specification. Therefore, we force it here. */
phydev->pma_extable = MDIO_PMA_EXTABLE_BT1;

Quoted 2 lines

I will try to clean up this patch to better utilize generic functions.

What you are trying to do is adding support for 88Q2221 which has the same phy_id as the 88Q2220 but needs a different(additional) setup to work properly(init sequence, ...).
Please change your commit message then.

Quoted 221 lines
Quoted 9 lines · Dimitri Fedrau

Hi Ilya,

Am Wed, Aug 20, 2025 at 11:11:43AM -0700 schrieb Ilya A. Evenbach:

Quoted 5 lines

88q2xxx PHYs have non-standard way of setting master/slave in forced mode.
This change adds support for changing and reporting this setting correctly through ethtool.

Quoted 6 lines

Review

Quoted 6 lines
---
 drivers/net/phy/marvell-88q2xxx.c | 106 ++++++++++++++++++++++++++++--
 1 file changed, 101 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/drivers/net/phy/marvell-88q2xxx.c

Quoted 8 lines

drivers/net/phy/marvell-88q2xxx.c line 121

Quoted 8 lines

index f3d83b04c953..b94d574fd9b7 100644

drivers/net/phy/marvell-88q2xxx.c +1 -0
@@ -118,6 +118,11 @@
 #define MV88Q2XXX_LED_INDEX_TX_ENABLE                        0
 #define MV88Q2XXX_LED_INDEX_GPIO                     1
 
+/* Marvell vendor PMA/PMD control for forced master/slave when AN is

disabled */

Quoted 6 lines

drivers/net/phy/marvell-88q2xxx.c line 122

Quoted 1 line
drivers/net/phy/marvell-88q2xxx.c +1 -0
+#define PMAPMD_MVL_PMAPMD_CTL                                0x0834

Already defined, see MDIO_PMA_PMD_BT1_CTRL.

drivers/net/phy/marvell-88q2xxx.c line 123

Quoted 1 line
drivers/net/phy/marvell-88q2xxx.c +1 -0
+#define MASTER_MODE                                  BIT(14)
Quoted 8 lines

Already defines, see MDIO_PMA_PMD_BT1_CTRL_CFG_MST.

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device

Quoted 6 lines
drivers/net/phy/marvell-88q2xxx.c +2 -0
+#define MODE_MASK                                    BIT(14)
+
 struct mv88q2xxx_priv {
      bool enable_led0;
 };
@@ -377,13 +382,57 @@ static int mv88q2xxx_read_link(struct phy_device

*phydev)

Quoted 6 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device *phydev)

Quoted 6 lines
drivers/net/phy/marvell-88q2xxx.c +3 -0
 static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev)
 {
      int ret;
+     int adv_l, adv_m, stat, stat2;
+
+     /* In forced mode, state and config are controlled via PMAPMD

0x834 */

Quoted 2 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device · line 389

Quoted 2 lines
drivers/net/phy/marvell-88q2xxx.c +2 -0
+     if (phydev->autoneg == AUTONEG_DISABLE) {
+             ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD,

PMAPMD_MVL_PMAPMD_CTL);

Quoted 5 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device *phydev)

Quoted 5 lines
drivers/net/phy/marvell-88q2xxx.c +5 -0
+             if (ret < 0)
+                     return ret;
+
+             if (ret & MASTER_MODE) {
+                     phydev->master_slave_state =

MASTER_SLAVE_STATE_MASTER;

Quoted 1 line

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device · line 395

Quoted 1 line
drivers/net/phy/marvell-88q2xxx.c +1 -0
+                     phydev->master_slave_get =

MASTER_SLAVE_CFG_MASTER_FORCE;

Quoted 2 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device · line 397

Quoted 2 lines
drivers/net/phy/marvell-88q2xxx.c +2 -0
+             } else {
+                     phydev->master_slave_state =

MASTER_SLAVE_STATE_SLAVE;

Quoted 1 line

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device · line 398

Quoted 1 line
drivers/net/phy/marvell-88q2xxx.c +1 -0
+                     phydev->master_slave_get =

MASTER_SLAVE_CFG_SLAVE_FORCE;

Quoted 9 lines
Quoted 9 lines
drivers/net/phy/marvell-88q2xxx.c +3 -4
+             }
+             return 0;
+     }
 
-     phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
-     ret = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
-     if (ret < 0)
-             return ret;
 
Quoted 12 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device *phydev)

Quoted 12 lines
drivers/net/phy/marvell-88q2xxx.c +11 -1
-     if (ret & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
+     adv_l = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_L);
+     if (adv_l < 0)
+             return adv_l;
+     adv_m = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_T1_ADV_M);
+     if (adv_m < 0)
+             return adv_m;
+
+     if (adv_l & MDIO_AN_T1_ADV_L_FORCE_MS)
+             phydev->master_slave_get = MASTER_SLAVE_CFG_MASTER_FORCE;
+     else if (adv_m & MDIO_AN_T1_ADV_M_MST)
+             phydev->master_slave_get =

MASTER_SLAVE_CFG_MASTER_PREFERRED;

Quoted 2 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_link(struct phy_device · line 416

Quoted 2 lines
drivers/net/phy/marvell-88q2xxx.c +2 -0
+     else
+             phydev->master_slave_get =

MASTER_SLAVE_CFG_SLAVE_PREFERRED;

Quoted 15 lines
Quoted 15 lines
drivers/net/phy/marvell-88q2xxx.c +15 -0
+
+     stat = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT);
+     if (stat < 0)
+             return stat;
+
+     if (stat & MDIO_MMD_AN_MV_STAT_MS_CONF_FAULT) {
+             phydev->master_slave_state = MASTER_SLAVE_STATE_ERR;
+             return 0;
+     }
+
+     stat2 = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_MMD_AN_MV_STAT2);
+     if (stat2 < 0)
+             return stat2;
+     if (!(stat2 & MDIO_MMD_AN_MV_STAT2_AN_RESOLVED)) {
+             phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN;
Quoted 8 lines

drivers/net/phy/marvell-88q2xxx.c static int

Quoted 8 lines
drivers/net/phy/marvell-88q2xxx.c +4 -0
+             return 0;
+     }
+
+     if (stat & MDIO_MMD_AN_MV_STAT_LOCAL_MASTER)
              phydev->master_slave_state = MASTER_SLAVE_STATE_MASTER;
      else
              phydev->master_slave_state = MASTER_SLAVE_STATE_SLAVE;
@@ -391,6 +440,34 @@ static int

mv88q2xxx_read_master_slave_state(struct phy_device *phydev)

Quoted 8 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev) · line 442

Quoted 3 lines
drivers/net/phy/marvell-88q2xxx.c +0 -0
      return 0;
 }
 

Is there a issue with the function you are trying to fix ? Seems that you copied some generic functions into it.

Quoted 1 line
drivers/net/phy/marvell-88q2xxx.c +1 -0
+static int mv88q2xxx_setup_master_slave_forced(struct phy_device

*phydev)

Quoted 32 lines
Quoted 17 lines
drivers/net/phy/marvell-88q2xxx.c +17 -0
+{
+     int ret = 0;
+
+     switch (phydev->master_slave_set) {
+     case MASTER_SLAVE_CFG_MASTER_FORCE:
+     case MASTER_SLAVE_CFG_MASTER_PREFERRED:
+             ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+                                          PMAPMD_MVL_PMAPMD_CTL,
+                                          MODE_MASK, MASTER_MODE);
+             break;
+     case MASTER_SLAVE_CFG_SLAVE_FORCE:
+     case MASTER_SLAVE_CFG_SLAVE_PREFERRED:
+             ret = phy_modify_mmd_changed(phydev, MDIO_MMD_PMAPMD,
+                                          PMAPMD_MVL_PMAPMD_CTL,
+                                          MODE_MASK, 0);
+             break;
+     case MASTER_SLAVE_CFG_UNKNOWN:

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_master_slave_state(struct phy_device *phydev) · line 470

Quoted 10 lines
drivers/net/phy/marvell-88q2xxx.c +10 -0
+     case MASTER_SLAVE_CFG_UNSUPPORTED:
+     default:
+             phydev_warn(phydev, "Unsupported Master/Slave mode\n");
+             ret = 0;
+             break;
+     }
+
+     return ret;
+}
+

This function does the same as genphy_c45_pma_baset1_setup_master_slave. Please use the generic function. Besides you are introducing register PMAPMD_MVL_PMAPMD_CTL which is MDIO_PMA_PMD_BT1_CTRL.

Quoted 4 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_status(struct phy_device

Quoted 4 lines
drivers/net/phy/marvell-88q2xxx.c +0 -0
 static int mv88q2xxx_read_aneg_speed(struct phy_device *phydev)
 {
      int ret;
@@ -448,6 +525,11 @@ static int mv88q2xxx_read_status(struct phy_device

*phydev)

Quoted 12 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_read_status(struct phy_device *phydev) · line 535

Quoted 11 lines
drivers/net/phy/marvell-88q2xxx.c +5 -0
      if (ret < 0)
              return ret;
 
+     /* Populate master/slave status also for forced modes */
+     ret = mv88q2xxx_read_master_slave_state(phydev);
+     if (ret < 0 && ret != -EOPNOTSUPP)
+             return ret;
+
      return genphy_c45_read_pma(phydev);
 }
 
Quoted 3 lines

Why ? This function is only used in case AUTONEG_ENABLE.

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_config_aneg(struct phy_device

Quoted 1 line
drivers/net/phy/marvell-88q2xxx.c +0 -0
@@ -478,6 +560,20 @@ static int mv88q2xxx_config_aneg(struct phy_device

*phydev)

Quoted 5 lines

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_config_aneg(struct phy_device *phydev)

Quoted 5 lines
drivers/net/phy/marvell-88q2xxx.c +2 -0
      if (ret)
              return ret;
 
+     /* Configure Base-T1 master/slave per phydev->master_slave_set.
+      * For AN disabled, program PMAPMD role directly; otherwise rely

on

Quoted 16 lines
Quoted 5 lines
drivers/net/phy/marvell-88q2xxx.c +5 -0
+      * the standard Base-T1 AN advertisement bits.
+      */
+     if (phydev->autoneg == AUTONEG_DISABLE) {
+             ret = mv88q2xxx_setup_master_slave_forced(phydev);
+             if (ret)

drivers/net/phy/marvell-88q2xxx.c static int mv88q2xxx_config_aneg(struct phy_device *phydev) · line 579

Quoted 10 lines
drivers/net/phy/marvell-88q2xxx.c +7 -0
+                     return ret;
+     } else {
+             ret = genphy_c45_pma_baset1_setup_master_slave(phydev);
+             if (ret)
+                     return ret;
+     }
+
      return phydev->drv->soft_reset(phydev);
 }
 
Quoted 5 lines

I don't see any reason why genphy_c45_config_aneg isn't sufficient here. In case AUTONEG_DISABLE, genphy_c45_pma_setup_forced is called and calls genphy_c45_pma_baset1_setup_master_slave which is basically the same as mv88q2xxx_setup_master_slave_forced.
In case AUTONEG_ENABLE, calling genphy_c45_pma_baset1_setup_master_slave

is

Quoted 17 lines

wrong, please look how genphy_c45_an_config_aneg is implemented.

Please take other users of the driver into CC, they did a lot of reviewing and testing in the past. If there is some issue with the driver, they should know:

"Niklas Söderlund" <[email protected]> "Gregor Herburger" <[email protected]> "Stefan Eichenberger" <[email protected]>
"Geert Uytterhoeven" <[email protected]>

Which device are you using, and why did you need this patch ? Is there any issue you are trying to fix ? On my side I did a lot of testing with the different modes and never experienced any problems so far.

Best regards,
Dimitri Fedrau