* [PATCH net] net: phy: mediatek: do not report link and per-speed LED rules together
@ 2026-09-12 13:43 Ahmed Naseef
2026-09-14 12:37 ` Andrew Lunn
2026-09-15 2:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Ahmed Naseef @ 2026-09-12 13:43 UTC (permalink / raw)
To: netdev
Cc: David S. Miller, Andrew Lunn, AngeloGioacchino Del Regno,
Daniel Golle, Eric Dumazet, Heiner Kallweit, Jakub Kicinski,
Matthias Brugger, Paolo Abeni, Qingfang Deng, Russell King,
SkyLake Huang, linux-arm-kernel, linux-kernel, linux-mediatek,
Ahmed Naseef
mtk_phy_led_hw_ctrl_get() reports TRIGGER_NETDEV_LINK whenever any of the
speed bits in on_set is on, and in addition reports every individual
TRIGGER_NETDEV_LINK_* bit that is set. The netdev trigger refuses that
combination: netdev_led_attr_store() rejects TRIGGER_NETDEV_LINK together
with any per-speed rule, and it validates the whole resulting mode rather
than just the bit being written. Once the hardware has any link bit
programmed, every write to the trigger attributes of that LED therefore
fails with -EINVAL and the LED can no longer be configured.
The rules are also fed back into the hardware: the trigger stores what is
read back, and a later write of device_name programs it again, expanding
TRIGGER_NETDEV_LINK to every speed in on_set. An LED configured for a
single speed is thereby silently widened to "on at any link speed".
Both are easy to see on the EcoNet EN7528, whose four PHYs share one LED
block. The first LED programs the block correctly, the second reads those
rules back and rewrites them widened, and the remaining two then read the
widened value, so an LED configured for "link_10 link_100" ends up lit on a
1000 Mbps link.
on_set holds every speed the LED can indicate and is exactly what
mtk_phy_led_hw_ctrl_set() programs for TRIGGER_NETDEV_LINK, so report the
speed independent rule only when all of them are on, and the individual
speeds otherwise. The mapping is then the inverse of the one used when
programming the LED and round trips without changing the register.
Fixes: c66937b0f8db ("net: phy: mediatek-ge-soc: support PHY LEDs")
Cc: stable@vger.kernel.org
Signed-off-by: Ahmed Naseef <naseefkm@gmail.com>
---
drivers/net/phy/mediatek/mtk-phy-lib.c | 27 ++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/net/phy/mediatek/mtk-phy-lib.c b/drivers/net/phy/mediatek/mtk-phy-lib.c
index dfd0f4e439a2..608072fbfde9 100644
--- a/drivers/net/phy/mediatek/mtk-phy-lib.c
+++ b/drivers/net/phy/mediatek/mtk-phy-lib.c
@@ -156,20 +156,27 @@ int mtk_phy_led_hw_ctrl_get(struct phy_device *phydev, u8 index,
if (!rules)
return 0;
- if (on & on_set)
+ /* TRIGGER_NETDEV_LINK must not be reported together with any of the
+ * per-speed rules, the netdev trigger rejects that combination.
+ * on_set holds every speed this LED can indicate and is what
+ * mtk_phy_led_hw_ctrl_set() programs for TRIGGER_NETDEV_LINK, so
+ * report the speed independent rule only when they are all on.
+ */
+ if ((on & on_set) == on_set) {
*rules |= BIT(TRIGGER_NETDEV_LINK);
+ } else {
+ if (on & MTK_PHY_LED_ON_LINK10)
+ *rules |= BIT(TRIGGER_NETDEV_LINK_10);
- if (on & MTK_PHY_LED_ON_LINK10)
- *rules |= BIT(TRIGGER_NETDEV_LINK_10);
+ if (on & MTK_PHY_LED_ON_LINK100)
+ *rules |= BIT(TRIGGER_NETDEV_LINK_100);
- if (on & MTK_PHY_LED_ON_LINK100)
- *rules |= BIT(TRIGGER_NETDEV_LINK_100);
+ if (on & MTK_PHY_LED_ON_LINK1000)
+ *rules |= BIT(TRIGGER_NETDEV_LINK_1000);
- if (on & MTK_PHY_LED_ON_LINK1000)
- *rules |= BIT(TRIGGER_NETDEV_LINK_1000);
-
- if (on & MTK_PHY_LED_ON_LINK2500)
- *rules |= BIT(TRIGGER_NETDEV_LINK_2500);
+ if (on & MTK_PHY_LED_ON_LINK2500)
+ *rules |= BIT(TRIGGER_NETDEV_LINK_2500);
+ }
if (on & MTK_PHY_LED_ON_FDX)
*rules |= BIT(TRIGGER_NETDEV_FULL_DUPLEX);
base-commit: 78445023439506ebd83b86d40b1e428a3b309d4a
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] net: phy: mediatek: do not report link and per-speed LED rules together
2026-09-12 13:43 [PATCH net] net: phy: mediatek: do not report link and per-speed LED rules together Ahmed Naseef
@ 2026-09-14 12:37 ` Andrew Lunn
2026-09-15 2:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2026-09-14 12:37 UTC (permalink / raw)
To: Ahmed Naseef
Cc: netdev, David S. Miller, AngeloGioacchino Del Regno,
Daniel Golle, Eric Dumazet, Heiner Kallweit, Jakub Kicinski,
Matthias Brugger, Paolo Abeni, Qingfang Deng, Russell King,
SkyLake Huang, linux-arm-kernel, linux-kernel, linux-mediatek
On Sat, Sep 12, 2026 at 05:43:06PM +0400, Ahmed Naseef wrote:
> mtk_phy_led_hw_ctrl_get() reports TRIGGER_NETDEV_LINK whenever any of the
> speed bits in on_set is on, and in addition reports every individual
> TRIGGER_NETDEV_LINK_* bit that is set. The netdev trigger refuses that
> combination: netdev_led_attr_store() rejects TRIGGER_NETDEV_LINK together
> with any per-speed rule, and it validates the whole resulting mode rather
> than just the bit being written. Once the hardware has any link bit
> programmed, every write to the trigger attributes of that LED therefore
> fails with -EINVAL and the LED can no longer be configured.
>
> The rules are also fed back into the hardware: the trigger stores what is
> read back, and a later write of device_name programs it again, expanding
> TRIGGER_NETDEV_LINK to every speed in on_set. An LED configured for a
> single speed is thereby silently widened to "on at any link speed".
>
> Both are easy to see on the EcoNet EN7528, whose four PHYs share one LED
> block. The first LED programs the block correctly, the second reads those
> rules back and rewrites them widened, and the remaining two then read the
> widened value, so an LED configured for "link_10 link_100" ends up lit on a
> 1000 Mbps link.
>
> on_set holds every speed the LED can indicate and is exactly what
> mtk_phy_led_hw_ctrl_set() programs for TRIGGER_NETDEV_LINK, so report the
> speed independent rule only when all of them are on, and the individual
> speeds otherwise. The mapping is then the inverse of the one used when
> programming the LED and round trips without changing the register.
>
> Fixes: c66937b0f8db ("net: phy: mediatek-ge-soc: support PHY LEDs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ahmed Naseef <naseefkm@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net] net: phy: mediatek: do not report link and per-speed LED rules together
2026-09-12 13:43 [PATCH net] net: phy: mediatek: do not report link and per-speed LED rules together Ahmed Naseef
2026-09-14 12:37 ` Andrew Lunn
@ 2026-09-15 2:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-15 2:10 UTC (permalink / raw)
To: Ahmed Naseef
Cc: netdev, davem, andrew, angelogioacchino.delregno, daniel,
edumazet, hkallweit1, kuba, matthias.bgg, pabeni, dqfext, linux,
SkyLake.Huang, linux-arm-kernel, linux-kernel, linux-mediatek
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 12 Sep 2026 17:43:06 +0400 you wrote:
> mtk_phy_led_hw_ctrl_get() reports TRIGGER_NETDEV_LINK whenever any of the
> speed bits in on_set is on, and in addition reports every individual
> TRIGGER_NETDEV_LINK_* bit that is set. The netdev trigger refuses that
> combination: netdev_led_attr_store() rejects TRIGGER_NETDEV_LINK together
> with any per-speed rule, and it validates the whole resulting mode rather
> than just the bit being written. Once the hardware has any link bit
> programmed, every write to the trigger attributes of that LED therefore
> fails with -EINVAL and the LED can no longer be configured.
>
> [...]
Here is the summary with links:
- [net] net: phy: mediatek: do not report link and per-speed LED rules together
https://git.kernel.org/netdev/net/c/bde5212360bd
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-15 2:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-12 13:43 [PATCH net] net: phy: mediatek: do not report link and per-speed LED rules together Ahmed Naseef
2026-09-14 12:37 ` Andrew Lunn
2026-09-15 2:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®