Skip to contentSkip to conversation

leds: trigger: netdev: Configure LED blink interval for HW offload

PATCH Applied Marek Vasut 7 participants 8 messages Jan 20, 2025 – Jul 11, 2025 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: trigger: netdev: Configure LED blink interval for HW offload

In case a PHY LED implements .blink_set callback to set LED blink interval, call it even if .hw_control is already set, as that LED blink interval likely controls the blink rate of that HW offloaded LED. For PHY LEDs, that can be their activity blinking interval.

The software blinking is not affected by this change.

With this change, the LED interval setting looks something like this:

$ echo netdev > /sys/class/leds/led:green:lan/trigger
$ echo 1 > /sys/class/leds/led:green:lan/brightness
$ echo 250 > /sys/class/leds/led:green:lan/interval

---
Cc: Andrew Lunn <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heiner Kallweit <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: [email protected]

---
 drivers/leds/trigger/ledtrig-netdev.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/leds/trigger/ledtrig-netdev.c +13 -3
index 20dfc9506c0a6..47c44620ba585 100644
@@ -69,6 +69,7 @@ struct led_netdev_data {
 	unsigned int last_activity;
 
 	unsigned long mode;
+	unsigned long blink_delay;
 	int link_speed;
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_link_modes);
 	u8 duplex;
@@ -87,6 +88,10 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
 	/* Already validated, hw control is possible with the requested mode */
 	if (trigger_data->hw_control) {
 		led_cdev->hw_control_set(led_cdev, trigger_data->mode);
+		if (led_cdev->blink_set) {
+			led_cdev->blink_set(led_cdev, &trigger_data->blink_delay,
+					    &trigger_data->blink_delay);
+		}
 
 		return;
 	}
@@ -463,10 +468,11 @@ static ssize_t interval_store(struct device *dev,
 			      size_t size)
 {
 	struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
+	struct led_classdev *led_cdev = trigger_data->led_cdev;
 	unsigned long value;
 	int ret;
 
-	if (trigger_data->hw_control)
+	if (trigger_data->hw_control && !led_cdev->blink_set)
 		return -EINVAL;
 
 	ret = kstrtoul(buf, 0, &value);
@@ -475,9 +481,13 @@ static ssize_t interval_store(struct device *dev,
 
 	/* impose some basic bounds on the timer interval */
 	if (value >= 5 && value <= 10000) {
-		cancel_delayed_work_sync(&trigger_data->work);
+		if (trigger_data->hw_control) {
+			trigger_data->blink_delay = value;
+		} else {
+			cancel_delayed_work_sync(&trigger_data->work);
 
-		atomic_set(&trigger_data->interval, msecs_to_jiffies(value));
+			atomic_set(&trigger_data->interval, msecs_to_jiffies(value));
+		}
 		set_baseline_state(trigger_data);	/* resets timer */
 	}
 
Signature · 1 line
2.45.2
maintainer Applied
#1 lore raw

Re: (subset) [PATCH] leds: trigger: netdev: Configure LED blink interval for HW offload

Quoted 8 lines · Marek Vasut

In case a PHY LED implements .blink_set callback to set LED blink interval, call it even if .hw_control is already set, as that LED blink interval likely controls the blink rate of that HW offloaded LED. For PHY LEDs, that can be their activity blinking interval.

The software blinking is not affected by this change.

[...]

Applied, thanks!

[1/1] leds: trigger: netdev: Configure LED blink interval for HW offload

      commit: c629c972b310af41e9e072febb6dae9a299edde6

--
Lee Jones [李琼斯]

#2 lore raw
In reply to Marek Vasut
Quoted 67 lines · Marek Vasut

In case a PHY LED implements .blink_set callback to set LED blink interval, call it even if .hw_control is already set, as that LED blink interval likely controls the blink rate of that HW offloaded LED. For PHY LEDs, that can be their activity blinking interval.

The software blinking is not affected by this change.

With this change, the LED interval setting looks something like this:

$ echo netdev > /sys/class/leds/led:green:lan/trigger
$ echo 1 > /sys/class/leds/led:green:lan/brightness
$ echo 250 > /sys/class/leds/led:green:lan/interval

---
Cc: Andrew Lunn <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heiner Kallweit <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: [email protected]

---
  drivers/leds/trigger/ledtrig-netdev.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)
drivers/leds/trigger/ledtrig-netdev.c +8 -2
index 20dfc9506c0a6..47c44620ba585 100644
@@ -69,6 +69,7 @@ struct led_netdev_data {
  	unsigned int last_activity;
 
  	unsigned long mode;
+	unsigned long blink_delay;
  	int link_speed;
  	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_link_modes);
  	u8 duplex;
@@ -87,6 +88,10 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
  	/* Already validated, hw control is possible with the requested mode */
  	if (trigger_data->hw_control) {
  		led_cdev->hw_control_set(led_cdev, trigger_data->mode);
+		if (led_cdev->blink_set) {
+			led_cdev->blink_set(led_cdev, &trigger_data->blink_delay,
+					    &trigger_data->blink_delay);
+		}
 
  		return;
  	}
@@ -463,10 +468,11 @@ static ssize_t interval_store(struct device *dev,
  			      size_t size)
  {
  	struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
+	struct led_classdev *led_cdev = trigger_data->led_cdev;
  	unsigned long value;
  	int ret;
 
-	if (trigger_data->hw_control)
+	if (trigger_data->hw_control && !led_cdev->blink_set)
  		return -EINVAL;
 
  	ret = kstrtoul(buf, 0, &value);
@@ -475,9 +481,13 @@ static ssize_t interval_store(struct device *dev,
 
  	/* impose some basic bounds on the timer interval */
  	if (value >= 5 && value <= 10000) {
-		cancel_delayed_work_sync(&trigger_data->work);
+		if (trigger_data->hw_control) {

drivers/leds/trigger/ledtrig-netdev.c static ssize_t interval_store(struct device *dev, · line 493

Quoted 10 lines
drivers/leds/trigger/ledtrig-netdev.c +5 -1
+			trigger_data->blink_delay = value;
+		} else {
+			cancel_delayed_work_sync(&trigger_data->work);
 
-		atomic_set(&trigger_data->interval, msecs_to_jiffies(value));
+			atomic_set(&trigger_data->interval, msecs_to_jiffies(value));
+		}
  		set_baseline_state(trigger_data);	/* resets timer */
  	}
 

Hi there, a while ago OpenWRT 24.10 was updated to linux kernel 6.6.93 [1] which contains the backport of this commit. Unfortunately this caused the LAN and WAN port LEDs on some MediaTek based routers to not work properly, they just kept blinking.

According to a comment [2] by an experienced OpenWRT developer and from my understanding this is a breaking change. Could you please take some time to review the issue in the link and help revert the commit if necessary. Thanks in advance.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.6.y&id=3648ddabcdc25aad8af95778d7f87225272815e9
[2] https://github.com/openwrt/openwrt/issues/19263#issuecomment-3032228022

#3 lore raw
Quoted 32 lines · nyanmisaka
Quoted 21 lines · Marek Vasut

In case a PHY LED implements .blink_set callback to set LED blink interval, call it even if .hw_control is already set, as that LED blink interval likely controls the blink rate of that HW offloaded LED. For PHY LEDs, that can be their activity blinking interval.

The software blinking is not affected by this change.

With this change, the LED interval setting looks something like this:

$ echo netdev > /sys/class/leds/led:green:lan/trigger
$ echo 1 > /sys/class/leds/led:green:lan/brightness
$ echo 250 > /sys/class/leds/led:green:lan/interval

---
Cc: Andrew Lunn <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heiner Kallweit <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: [email protected]

Quoted 4 lines
---
  drivers/leds/trigger/ledtrig-netdev.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)

Hi there, a while ago OpenWRT 24.10 was updated to linux kernel 6.6.93 [1] which contains the backport of this commit. Unfortunately this caused the LAN and WAN port LEDs on some MediaTek based routers to not work properly, they just kept blinking.

Quoted 7 lines

According to a comment [2] by an experienced OpenWRT developer and from my understanding this is a breaking change. Could you please take some time to review the issue in the link and help revert the commit if necessary. Thanks in advance.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.6.y&id=3648ddabcdc25aad8af95778d7f87225272815e9
[2] https://github.com/openwrt/openwrt/issues/19263#issuecomment-3032228022

To clarify: This patch, which also got backported to Linux stable trees, changes the meaning of the ->blink_set() op. While previously, calling blink_set() would instruct the hardware to put the LED into a permanently blinking state, it is now (also?) used to adjust RX/TX blinking times while the 'netdev' trigger is selected. This means that all PHY drivers currently implementing a .led_blink_set op will need to check whether the 'netdev' trigger is currently active (and in this case interpret the call as being intended to change RX/TX blink intervals) or not (and then just put the LED into permanently blinking state, which is also the current behavior of all drivers I'm aware of).

I hence suggest to revert this change, as none of the drivers were changed to adapt to the new behavioral expectations -- if any of the drivers does behave as expected (which I somehow assume, as the patch was probably sent while specific hardware was on the developer's desk) that is coincidental.

It would also be better to not just change the definition of an existing operation in an incompatible way, but rather introduce a new op for that purpose (which may or may not replace the existing .led_blink_set op in the long run, once all drivers have been adapted).

#4 lore raw
Quoted 38 lines · Daniel Golle
Quoted 37 lines · nyanmisaka
Quoted 21 lines · Marek Vasut

In case a PHY LED implements .blink_set callback to set LED blink interval, call it even if .hw_control is already set, as that LED blink interval likely controls the blink rate of that HW offloaded LED. For PHY LEDs, that can be their activity blinking interval.

The software blinking is not affected by this change.

With this change, the LED interval setting looks something like this:

$ echo netdev > /sys/class/leds/led:green:lan/trigger
$ echo 1 > /sys/class/leds/led:green:lan/brightness
$ echo 250 > /sys/class/leds/led:green:lan/interval

---
Cc: Andrew Lunn <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heiner Kallweit <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: [email protected]

Quoted 4 lines
---
  drivers/leds/trigger/ledtrig-netdev.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)

Hi there, a while ago OpenWRT 24.10 was updated to linux kernel 6.6.93 [1] which contains the backport of this commit. Unfortunately this caused the LAN and WAN port LEDs on some MediaTek based routers to not work properly, they just kept blinking.

According to a comment [2] by an experienced OpenWRT developer and from my understanding this is a breaking change. Could you please take some time to review the issue in the link and help revert the commit if necessary. Thanks in advance.

Quoted 4 lines
Quoted 2 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.6.y&id=3648ddabcdc25aad8af95778d7f87225272815e9
[2] https://github.com/openwrt/openwrt/issues/19263#issuecomment-3032228022

To clarify: This patch, which also got backported to Linux stable trees,

Why was it back ported? This is clearly not a fix, and does not have a
Fixes: tag.

Quoted 4 lines

changes the meaning of the ->blink_set() op.While previously, calling blink_set() would instruct the hardware to put the LED into a permanently blinking state, it is now (also?) used to adjust RX/TX blinking times while the 'netdev' trigger is selected.

I agree this is a bad idea. The op should not be overloaded like this.

I suggest you submit a revert patch, and include a Fixes: tag.

What is also odd is that i don't see a patch adding a user for this. We generally don't add a new feature without a users!

Andrew

#5 lore raw
Quoted 39 lines · Andrew Lunn
Quoted 38 lines · Daniel Golle
Quoted 37 lines · nyanmisaka
Quoted 21 lines · Marek Vasut

In case a PHY LED implements .blink_set callback to set LED blink interval, call it even if .hw_control is already set, as that LED blink interval likely controls the blink rate of that HW offloaded LED. For PHY LEDs, that can be their activity blinking interval.

The software blinking is not affected by this change.

With this change, the LED interval setting looks something like this:

$ echo netdev > /sys/class/leds/led:green:lan/trigger
$ echo 1 > /sys/class/leds/led:green:lan/brightness
$ echo 250 > /sys/class/leds/led:green:lan/interval

---
Cc: Andrew Lunn <[email protected]>
Cc: Christian Marangi <[email protected]>
Cc: Heiner Kallweit <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Pavel Machek <[email protected]>
Cc: [email protected]

Quoted 4 lines
---
  drivers/leds/trigger/ledtrig-netdev.c | 16 +++++++++++++---
  1 file changed, 13 insertions(+), 3 deletions(-)

Hi there, a while ago OpenWRT 24.10 was updated to linux kernel 6.6.93 [1] which contains the backport of this commit. Unfortunately this caused the LAN and WAN port LEDs on some MediaTek based routers to not work properly, they just kept blinking.

According to a comment [2] by an experienced OpenWRT developer and from my understanding this is a breaking change. Could you please take some time to review the issue in the link and help revert the commit if necessary. Thanks in advance.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.6.y&id=3648ddabcdc25aad8af95778d7f87225272815e9
[2] https://github.com/openwrt/openwrt/issues/19263#issuecomment-3032228022

To clarify: This patch, which also got backported to Linux stable trees,

Why was it back ported? This is clearly not a fix, and does not have a
Fixes: tag.

LLM decides what to backport, with little to no human oversight :-(.

BR,
Pavel

Signature · 2 lines
I don't work for Nazis and criminals, and neither should you.
Boycott Putin, Trump, and Musk!
#6 lore raw
In reply to Andrew Lunn

On 7/11/25 3:04 AM, Andrew Lunn wrote:

Hi,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Hi there, a while ago OpenWRT 24.10 was updated to linux kernel 6.6.93 [1] which contains the backport of this commit. Unfortunately this caused the LAN and WAN port LEDs on some MediaTek based routers to not work properly, they just kept blinking.

According to a comment [2] by an experienced OpenWRT developer and from my understanding this is a breaking change. Could you please take some time to review the issue in the link and help revert the commit if necessary. Thanks in advance.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-6.6.y&id=3648ddabcdc25aad8af95778d7f87225272815e9
[2] https://github.com/openwrt/openwrt/issues/19263#issuecomment-3032228022

To clarify: This patch, which also got backported to Linux stable trees,

Why was it back ported? This is clearly not a fix, and does not have a
Fixes: tag.

This shouldn't have been backported.

Quoted 6 lines
Quoted 4 lines

changes the meaning of the ->blink_set() op.While previously, calling blink_set() would instruct the hardware to put the LED into a permanently blinking state, it is now (also?) used to adjust RX/TX blinking times while the 'netdev' trigger is selected.

I agree this is a bad idea. The op should not be overloaded like this.

The led-core.c led_blink_set() does have on and off delay parameters, so this only aligned the PHY subsystem and LED subsystem behavior, if I recall it right.

Quoted 4 lines

I suggest you submit a revert patch, and include a Fixes: tag.

What is also odd is that i don't see a patch adding a user for this. We generally don't add a new feature without a users!

I found one patch in tree here which makes use of the delay_on/delay_off parameters of .led_blink_set callback, I didn't get around to posting it yet it seems. It seems the other in-tree users only use delay_on/delay_off parameters of their .led_blink_set callbacks to decide whether or not to blink and that's all.

Signature · 2 lines
Best regards,
Marek Vasut
#7 lore raw
Quoted 5 lines

I found one patch in tree here which makes use of the delay_on/delay_off parameters of .led_blink_set callback, I didn't get around to posting it yet it seems. It seems the other in-tree users only use delay_on/delay_off parameters of their .led_blink_set callbacks to decide whether or not to blink and that's all.

I had a quick look at the PHY drivers.

marvell.c: m88e1318_led_blink_set(). Sets the LED function to blinking with an 84ms off/on period.

air_en8811h.c: air_led_blink_set(). Sets the LED for force_blink with a 50ms off/on period.

Neither of these drivers use the op to set the blink period when hardware acceleration is being used for packet RX/TX etc, which is what this patch is trying to do with the overloaded meaning. So this is a clear regression.

Going back to the original design philosophy for hardware offload of netdev blinking, we knew vendors had implemented all sorts of odd features, because they could. There is no standardisation. The aim of the framework was to provide a basic set of features which covered most users needs. We don't need to support ever feature of every vendor. Does the user really care how fast the LED blinks when there are packets? So long as it blinks, that should be sufficient. So i don't actually see any need for this feature, it is just complexity without any real gain.

Andrew