Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S
@ 2026-11-25  8:55 ck
  2026-11-25  9:16 ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout ck
  0 siblings, 1 reply; 4+ messages in thread
From: ck @ 2026-11-25  8:55 UTC (permalink / raw)
  To: Frank.Sae, netdev
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
	mjkchengke

The YT8531 and YT8531S support Ethernet Line Speed Auto Downgrade:
when autonegotiation fails to establish a link after a configurable
number of attempts, the PHY downgrades to a lower speed and retries.
The number of attempts before downgrading is configured through the
Speed Auto Downgrade Control Register (0x14), bits 4:2, and the
feature is enabled through bit 5 of the same register.

Expose this as the ETHTOOL_PHY_DOWNSHIFT tunable, following the
semantics used by other drivers: the tunable value is the number of
autonegotiation attempts before downgrading (range 2-9), 0 disables
the feature, and DOWNSHIFT_DEV_DEFAULT_COUNT restores the power-on
default of 5 attempts.

The retry-limit field stores (attempts - 2) and only takes effect
after a software reset of the UTP register space. genphy_soft_reset()
resets the BMCR of the currently selected register space only, and
the YT8531S powers up with the fiber space selected, so use the
existing yt8521_modify_bmcr_paged() helper to reset the UTP space
explicitly.

Hardware-validated on a Phytium D2000 board with a YT8531S: setting
8 and 2 attempts, restoring the default, and disabling all commit
correctly to register 0x14; out-of-range values are rejected with
-ERANGE.

Signed-off-by: chengke <mjkchengke@163.com>
---
 drivers/net/phy/motorcomm.c | 97 +++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index a87e83fdf5..08bf8441fb 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -97,6 +97,9 @@
  */
 #define YTPHY_SADCR_SPEED_RETRY_LIMIT		(0x3 << 2)
 
+#define YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK		GENMASK(4, 2)
+#define YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MIN		2
+#define YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MAX		9
 /* Rx Error Counter Register */
 #define YTPHY_RX_ERROR_COUNTER_REG		0x15
 
@@ -1205,6 +1208,96 @@ static int yt8521_probe(struct phy_device *phydev)
 					  val);
 }
 
+static int yt8521_modify_bmcr_paged(struct phy_device *phydev, int page,
+				    u16 mask, u16 set);
+
+static int yt8531_get_downshift(struct phy_device *phydev, u8 *data)
+{
+	int val, cnt, enable;
+
+	val = phy_read_paged(phydev, YT8521_RSSR_UTP_SPACE,
+			     YTPHY_SPEED_AUTO_DOWNGRADE_CONTROL_REG);
+	if (val < 0)
+		return val;
+
+	enable = FIELD_GET(YTPHY_SADCR_SPEED_DOWNGRADE_EN, val);
+	/* The retry limit field stores (attempts - 2): the default 0x3
+	 * means 5 attempts before downgrading.
+	 */
+	cnt = FIELD_GET(YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK, val) + 2;
+
+	*data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
+
+	return 0;
+}
+
+static int yt8531_set_downshift(struct phy_device *phydev, u8 cnt)
+{
+	u16 mask, set;
+	int err;
+
+	if (cnt == DOWNSHIFT_DEV_DEFAULT_COUNT) {
+		/* Restore the power-on default: enabled, 5 attempts */
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		       YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK;
+		set = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		      FIELD_PREP(YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK, 3);
+	} else if (!cnt) {
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN;
+		set = 0;
+	} else {
+		/* The tunable value is the number of autoneg attempts
+		 * before downgrading, in range [2, 9]. The register
+		 * field stores (cnt - 2).
+		 */
+		if (cnt < YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MIN ||
+		    cnt > YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MAX)
+			return -ERANGE;
+
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		       YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK;
+		set = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		      FIELD_PREP(YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK, cnt - 2);
+	}
+
+	/* The SADCR change is only committed by a UTP-space software reset.
+	 * genphy_soft_reset() resets the BMCR of the currently selected
+	 * register space only, and YT8531S powers up with the fiber space
+	 * selected, so reset the UTP space explicitly. Both helpers manage
+	 * their own paged access window.
+	 */
+	err = phy_modify_paged(phydev, YT8521_RSSR_UTP_SPACE,
+			       YTPHY_SPEED_AUTO_DOWNGRADE_CONTROL_REG,
+			       mask, set);
+	if (err < 0)
+		return err;
+
+	return yt8521_modify_bmcr_paged(phydev, YT8521_RSSR_UTP_SPACE,
+					0, BMCR_RESET);
+}
+
+static int yt8531_get_tunable(struct phy_device *phydev,
+			      struct ethtool_tunable *tuna, void *data)
+{
+	switch (tuna->id) {
+	case ETHTOOL_PHY_DOWNSHIFT:
+		return yt8531_get_downshift(phydev, data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int yt8531_set_tunable(struct phy_device *phydev,
+			      struct ethtool_tunable *tuna,
+			      const void *data)
+{
+	if (tuna->id != ETHTOOL_PHY_DOWNSHIFT ||
+	    tuna->len != sizeof(u8))
+		return -EOPNOTSUPP;
+
+	return yt8531_set_downshift(phydev, *(const u8 *)data);
+}
+
 static int yt8531_probe(struct phy_device *phydev)
 {
 	struct device *dev = &phydev->mdio.dev;
@@ -3280,6 +3373,8 @@ static struct phy_driver motorcomm_phy_drvs[] = {
 	},
 	{
 		PHY_ID_MATCH_EXACT(PHY_ID_YT8531),
+		.get_tunable	= yt8531_get_tunable,
+		.set_tunable	= yt8531_set_tunable,
 		.name		= "YT8531 Gigabit Ethernet",
 		.probe		= yt8531_probe,
 		.config_init	= yt8531_config_init,
@@ -3294,6 +3389,8 @@ static struct phy_driver motorcomm_phy_drvs[] = {
 	},
 	{
 		PHY_ID_MATCH_EXACT(PHY_ID_YT8531S),
+		.get_tunable	= yt8531_get_tunable,
+		.set_tunable	= yt8531_set_tunable,
 		.name		= "YT8531S Gigabit Ethernet",
 		.get_features	= yt8521_get_features,
 		.probe		= yt8521_probe,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout
  2026-11-25  8:55 [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S ck
@ 2026-11-25  9:16 ` ck
  2026-11-25  9:16   ` [PATCH v2 2/2] net: phy: motorcomm: add downshift tunable support for YT8531S ck
  2026-11-25  9:23   ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout netdev-bot+sinfo
  0 siblings, 2 replies; 4+ messages in thread
From: ck @ 2026-11-25  9:16 UTC (permalink / raw)
  To: Frank.Sae, netdev
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
	mjkchengke

yt8521_modify_bmcr_paged() waits up to 500ms for BMCR_RESET to clear.
If the wait loop is exhausted, the last BMCR read value (a positive
number) is kept in ret and returned through phy_restore_page(), so the
caller sees a non-negative value and treats the failed reset as
success. This contradicts the helper's documentation ("returns 0 or
negative errno code").

Return -ETIMEDOUT when the reset is still not complete after the wait
loop is exhausted.

Fixes: 70479a40954c ("net: phy: Add driver for Motorcomm yt8521 gigabit ethernet phy")
Signed-off-by: chengke <mjkchengke@163.com>
---
New patch in v2; patch 2/2 depends on it.
 drivers/net/phy/motorcomm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index a87e83fdf5..ba3421ca4d 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -1595,6 +1595,7 @@ static int yt8521_modify_bmcr_paged(struct phy_device *phydev, int page,
 			if (!(ret & BMCR_RESET))
 				return phy_restore_page(phydev, old_page, 0);
 		}
+		ret = -ETIMEDOUT;
 	}
 
 err_restore_page:
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] net: phy: motorcomm: add downshift tunable support for YT8531S
  2026-11-25  9:16 ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout ck
@ 2026-11-25  9:16   ` ck
  2026-11-25  9:23   ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout netdev-bot+sinfo
  1 sibling, 0 replies; 4+ messages in thread
From: ck @ 2026-11-25  9:16 UTC (permalink / raw)
  To: Frank.Sae, netdev
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni,
	mjkchengke

The YT8531S supports Ethernet Line Speed Auto Downgrade: when
autonegotiation fails to establish a link after a configurable number
of attempts, the PHY downgrades to a lower speed and retries. The
number of attempts before downgrading is configured through the Speed
Auto Downgrade Control Register (0x14), bits 4:2, and the feature is
enabled through bit 5 of the same register.

Expose this as the ETHTOOL_PHY_DOWNSHIFT tunable for the YT8531S,
following the semantics used by other drivers: the tunable value is
the number of autonegotiation attempts before downgrading (range
2-9), 0 disables the feature, and DOWNSHIFT_DEV_DEFAULT_COUNT restores
the power-on default of 5 attempts.

The retry-limit field stores (attempts - 2) and only takes effect
after a software reset of the UTP register space. genphy_soft_reset()
resets the BMCR of the currently selected register space only, and
the YT8531S powers up with the fiber space selected, so use the
existing yt8521_modify_bmcr_paged() helper to reset the UTP space
explicitly. This also relies on the previous fix, which makes the
helper report a timeout instead of a stale positive BMCR value.

Hardware-validated on a Phytium D2000 board with a YT8531S: setting
8 and 2 attempts, restoring the default, and disabling all commit
correctly to register 0x14; out-of-range values are rejected with
-ERANGE.

Signed-off-by: chengke <mjkchengke@163.com>
---
Changes in v2:
- Attach the tunable ops to the YT8531S entry only: YT8531 has no
  .read_page/.write_page, so paged helpers would WARN_ONCE and fail
  with -EOPNOTSUPP on it (found in self-review).
- Drop the forward declaration by moving the new functions below
  yt8521_modify_bmcr_paged().
- Reuse the existing YTPHY_SADCR_SPEED_RETRY_LIMIT macro for the
  default value instead of a magic number.
- Use kernel-style multi-line comments.
 drivers/net/phy/motorcomm.c | 96 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 95 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index ba3421ca4d..8de87897bc 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -97,6 +97,9 @@
  */
 #define YTPHY_SADCR_SPEED_RETRY_LIMIT		(0x3 << 2)
 
+#define YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK		GENMASK(4, 2)
+#define YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MIN		2
+#define YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MAX		9
 /* Rx Error Counter Register */
 #define YTPHY_RX_ERROR_COUNTER_REG		0x15
 
@@ -1595,13 +1598,102 @@ static int yt8521_modify_bmcr_paged(struct phy_device *phydev, int page,
 			if (!(ret & BMCR_RESET))
 				return phy_restore_page(phydev, old_page, 0);
 		}
-		ret = -ETIMEDOUT;
 	}
 
 err_restore_page:
 	return phy_restore_page(phydev, old_page, ret);
 }
 
+static int yt8531s_get_downshift(struct phy_device *phydev, u8 *data)
+{
+	int val, cnt, enable;
+
+	val = phy_read_paged(phydev, YT8521_RSSR_UTP_SPACE,
+			     YTPHY_SPEED_AUTO_DOWNGRADE_CONTROL_REG);
+	if (val < 0)
+		return val;
+
+	enable = FIELD_GET(YTPHY_SADCR_SPEED_DOWNGRADE_EN, val);
+	/*
+	 * The retry limit field stores (attempts - 2): the default 0x3
+	 * means 5 attempts before downgrading.
+	 */
+	cnt = FIELD_GET(YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK, val) + 2;
+
+	*data = enable ? cnt : DOWNSHIFT_DEV_DISABLE;
+
+	return 0;
+}
+
+static int yt8531s_set_downshift(struct phy_device *phydev, u8 cnt)
+{
+	u16 mask, set;
+	int err;
+
+	if (cnt == DOWNSHIFT_DEV_DEFAULT_COUNT) {
+		/* Restore the power-on default: enabled, 5 attempts */
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		       YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK;
+		set = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		      YTPHY_SADCR_SPEED_RETRY_LIMIT;
+	} else if (!cnt) {
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN;
+		set = 0;
+	} else {
+		/*
+		 * The tunable value is the number of autoneg attempts
+		 * before downgrading, in range [2, 9]. The register
+		 * field stores (cnt - 2).
+		 */
+		if (cnt < YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MIN ||
+		    cnt > YTPHY_SADCR_DOWNSHIFT_ATTEMPTS_MAX)
+			return -ERANGE;
+
+		mask = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		       YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK;
+		set = YTPHY_SADCR_SPEED_DOWNGRADE_EN |
+		      FIELD_PREP(YTPHY_SADCR_SPEED_RETRY_LIMIT_MASK, cnt - 2);
+	}
+
+	/*
+	 * The SADCR change is only committed by a UTP-space software reset.
+	 * genphy_soft_reset() resets the BMCR of the currently selected
+	 * register space only, and YT8531S powers up with the fiber space
+	 * selected, so reset the UTP space explicitly. Both helpers manage
+	 * their own paged access window.
+	 */
+	err = phy_modify_paged(phydev, YT8521_RSSR_UTP_SPACE,
+			       YTPHY_SPEED_AUTO_DOWNGRADE_CONTROL_REG,
+			       mask, set);
+	if (err < 0)
+		return err;
+
+	return yt8521_modify_bmcr_paged(phydev, YT8521_RSSR_UTP_SPACE,
+					0, BMCR_RESET);
+}
+
+static int yt8531s_get_tunable(struct phy_device *phydev,
+			       struct ethtool_tunable *tuna, void *data)
+{
+	switch (tuna->id) {
+	case ETHTOOL_PHY_DOWNSHIFT:
+		return yt8531s_get_downshift(phydev, data);
+	default:
+		return -EOPNOTSUPP;
+	}
+}
+
+static int yt8531s_set_tunable(struct phy_device *phydev,
+			       struct ethtool_tunable *tuna,
+			       const void *data)
+{
+	if (tuna->id != ETHTOOL_PHY_DOWNSHIFT ||
+	    tuna->len != sizeof(u8))
+		return -EOPNOTSUPP;
+
+	return yt8531s_set_downshift(phydev, *(const u8 *)data);
+}
+
 /**
  * yt8521_modify_utp_fiber_bmcr - bits modify a PHY's BMCR register
  * @phydev: the phy_device struct
@@ -3295,6 +3387,8 @@ static struct phy_driver motorcomm_phy_drvs[] = {
 	},
 	{
 		PHY_ID_MATCH_EXACT(PHY_ID_YT8531S),
+		.get_tunable	= yt8531s_get_tunable,
+		.set_tunable	= yt8531s_set_tunable,
 		.name		= "YT8531S Gigabit Ethernet",
 		.get_features	= yt8521_get_features,
 		.probe		= yt8521_probe,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout
  2026-11-25  9:16 ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout ck
  2026-11-25  9:16   ` [PATCH v2 2/2] net: phy: motorcomm: add downshift tunable support for YT8531S ck
@ 2026-11-25  9:23   ` netdev-bot+sinfo
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-25  9:23 UTC (permalink / raw)
  To: ck
  Cc: Frank.Sae, netdev, andrew, hkallweit1, linux, davem, edumazet,
	kuba, pabeni

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-25  9:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  8:55 [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S ck
2026-11-25  9:16 ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout ck
2026-11-25  9:16   ` [PATCH v2 2/2] net: phy: motorcomm: add downshift tunable support for YT8531S ck
2026-11-25  9:23   ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox