* [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
2026-11-29 9:10 ` [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S netdev-bot+sashiko
0 siblings, 2 replies; 6+ 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] 6+ 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
2026-11-29 9:10 ` [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S netdev-bot+sashiko
1 sibling, 2 replies; 6+ 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] 6+ 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; 6+ 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] 6+ 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
2026-11-25 9:56 ` chengke
1 sibling, 1 reply; 6+ 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] 6+ messages in thread
* Re: [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout
2026-11-25 9:23 ` [PATCH v2 1/2] net: phy: motorcomm: return -ETIMEDOUT on BMCR reset timeout netdev-bot+sinfo
@ 2026-11-25 9:56 ` chengke
0 siblings, 0 replies; 6+ messages in thread
From: chengke @ 2026-11-25 9:56 UTC (permalink / raw)
To: netdev-bot+sinfo
Cc: Frank.Sae, netdev, andrew, hkallweit1, linux, davem, edumazet,
kuba, pabeni, mjkchengke
Hi,
Replying to the automated review of this series (this is not a repost).
Regarding patch 1/2 ("net: phy: motorcomm: return -ETIMEDOUT on BMCR
reset timeout"): the issue is theoretical, not triggered at runtime. It
was found by code inspection, and I do not have a stack trace or kernel
message to quote.
Reasoning:
yt8521_modify_bmcr_paged() polls BMCR_RESET with a 500ms budget
(500 x ~1ms). If the loop is exhausted while BMCR_RESET is still set,
the last __phy_read() result (the raw BMCR value, a positive number) is
left in ret, and the err_restore_page path hands it to
phy_restore_page(phydev, old_page, ret), which returns it to the caller
as success.
This is very unlikely to trigger in practice: the PHY completes the
self-clear of BMCR_RESET normally, and a >=500ms hang of the self-clear
would more likely indicate an MDIO bus problem, which would already
have failed the __phy_read() in the loop. So there are no observable
symptoms today; the motivation is correctness only, so that the helper
behaves as documented ("returns 0 or negative errno code") and does not
mask a stuck reset.
I also checked all callers under drivers/net/phy/motorcomm.c
(yt8521_soft_reset, yt8521_resume, yt8521_modify_utp_fiber_bmcr,
yt8531s_set_downshift added by 2/2, and yt8821_modify_utp_fiber_bmcr):
they all treat "ret < 0" as error and propagate it, so a negative
-ETIMEDOUT return does not introduce any new failure path; it only
converts the would-be positive BMCR value into a proper errno.
No functional change is expected on healthy hardware.
If reviewers prefer, I can respin with a "found by inspection" note in
the commit message in the next repost (there may be one anyway for
patch 2/2 review comments); per the bot's instruction I am not reposting
just for this.
Thanks,
chengke
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S
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-29 9:10 ` netdev-bot+sashiko
1 sibling, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-29 9:10 UTC (permalink / raw)
To: mjkchengke
Cc: Frank.Sae, netdev, andrew, hkallweit1, linux, davem, edumazet,
kuba, pabeni
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch adds .get_tunable/.set_tunable to the PHY_ID_YT8531
entry of motorcomm_phy_drvs[].
- [Medium] yt8531_set_downshift() commits the SADCR change by writing
BMCR_RESET to the UTP-space BMCR with yt8521_modify_bmcr_paged(phydev,…
- [Low] In yt8521_modify_bmcr_paged(), if BMCR_RESET has not self-cleared
after the ~500 iterations of usleep_range(1000,1100), the loop exits…
--
net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S
This commit exposes the YT8531/YT8531S Speed Auto Downgrade feature as the
ETHTOOL_PHY_DOWNSHIFT tunable. The retry limit is written to the Speed Auto
Downgrade Control Register in the UTP space. It is then committed with a
UTP-space BMCR software reset through yt8521_modify_bmcr_paged().
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index a87e83fdf590c..08bf8441fbd4e 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c
[ ... ]
> @@ -1205,6 +1208,96 @@ static int yt8521_probe(struct phy_device *phydev)
[ ... ]
> +static int yt8531_set_downshift(struct phy_device *phydev, u8 cnt)
> +{
[ ... ]
> + /* 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);
[Severity: Medium]
Can this reset leave the copper side out of sync with what phylib thinks
the PHY is doing?
Under Clause 22, a BMCR reset puts the control register back to its
defaults: autoneg enabled, default speed/duplex, power down cleared.
genphy_soft_reset() handles this after the reset:
drivers/net/phy/phy_device.c:genphy_soft_reset() {
...
phydev->suspended = 0;
ret = phy_poll_reset(phydev);
if (ret)
return ret;
/* BMCR may be reset to defaults */
if (phydev->autoneg == AUTONEG_DISABLE)
ret = genphy_setup_forced(phydev);
...
}
Here only the BMCR_RESET bit is polled. set_phy_tunable() only calls
drv->set_tunable under phydev->lock and does not re-run config_aneg.
Assuming the UTP BMCR reset behaves like a standard Clause 22 reset,
suppose the link was forced with "ethtool -s ethX autoneg off speed 100
duplex full" and the downshift tunable is set afterwards. Would the PHY go
back to autonegotiation while phylib still treats the link as forced?
Against a forced link partner, that could cause a duplex mismatch or no
link at all.
The suspend case is similar. After phy_stop(), the state machine calls
phy_suspend()->yt8521_suspend(), which sets BMCR_PDOWN in the UTP space.
If the tunable is changed while the interface is down, would PDOWN be
cleared and the copper side powered back up while phydev->suspended is
still set?
[Severity: Low]
What does the caller see if BMCR_RESET never self-clears? In
yt8521_modify_bmcr_paged(), the poll loop exits with ret still holding the
last BMCR value it read:
if (set == BMCR_RESET) {
while (max_cnt--) {
usleep_range(1000, 1100);
ret = __phy_read(phydev, MII_BMCR);
if (ret < 0)
goto err_restore_page;
if (!(ret & BMCR_RESET))
return phy_restore_page(phydev, old_page, 0);
}
}
err_restore_page:
return phy_restore_page(phydev, old_page, ret);
phy_restore_page() returns a non-negative ret unchanged. The existing
caller, yt8521_modify_utp_fiber_bmcr(), turns that into 0. Here the
positive value goes straight back through set_phy_tunable() as the ioctl
return value.
ethtool only treats err < 0 as an error, so would a reset timeout be
reported as success? Would returning -ETIMEDOUT on that path make more
sense?
[ ... ]
> @@ -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,
[Severity: High]
Does the downshift tunable work at all on the YT8531? This entry has no
.read_page or .write_page callback, but both new callbacks use the paged
helpers:
yt8531_get_tunable()
yt8531_get_downshift()
phy_read_paged()
phy_select_page()
phy_save_page()
__phy_read_page()
drivers/net/phy/phy-core.c:__phy_read_page() {
if (WARN_ONCE(!phydev->drv->read_page, "read_page callback not available, PHY driver not loaded?\n"))
return -EOPNOTSUPP;
...
}
The set path has the same problem. phy_modify_paged() and
yt8521_modify_bmcr_paged() both go through phy_select_page().
So on a YT8531 (non-S), every get or set would return -EOPNOTSUPP, and the
first call would print a WARN splat. The comment in
yt8531_set_downshift() says "Both helpers manage their own paged access
window", which does not seem to hold for this entry. The commit message
also mentions testing only on a YT8531S.
ETHTOOL_PHY_GTUNABLE is also on the list that skips the CAP_NET_ADMIN check
in __dev_ethtool(). That means an unprivileged "ethtool --get-phy-tunable
ethX downshift" can trigger the WARN, and on a panic_on_warn system that
panics the machine.
There are two possible fixes. If the 0xA000 space select register is
valid on the YT8531, the entry could get .read_page/.write_page.
Otherwise, the UTP-only YT8531 could use plain
phy_read()/phy_modify()/genphy_soft_reset() instead.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125085509.1844883-1-mjkchengke%40163.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-29 9:10 UTC | newest]
Thread overview: 6+ 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
2026-11-25 9:56 ` chengke
2026-11-29 9:10 ` [PATCH] net: phy: motorcomm: add downshift tunable support for YT8531/YT8531S netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox