Skip to contentSkip to conversation

leds: trigger: netdev: add core support for hw not supporting fallback to LED sw control

PATCH Applied Heiner Kallweit 3 participants 8 messages Dec 17, 2023 – Jan 11, 2024

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

PATCH 1/1 leds: trigger: netdev: add core support for hw not supporting fallback to LED sw control

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

Add a comment explaining how a driver for such hw is supposed to behave.

---
 drivers/leds/trigger/ledtrig-netdev.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/leds/trigger/ledtrig-netdev.c +15 -0
index d76214fa9..27f090bc8 100644
@@ -38,6 +38,16 @@
  * tx -  LED blinks on transmitted data
  * rx -  LED blinks on receive data
  *
+ * Note: If the user selects a mode that is not supported by hw, default
+ * behavior is to fall back to software control of the LED. However not every
+ * hw supports software control. LED callbacks brightness_set() and
+ * brightness_set_blocking() are NULL in this case. hw_control_is_supported()
+ * should use available means supported by hw to inform the user that selected
+ * mode isn't supported by hw. This could be switching off the LED or any
+ * hw blink mode. If software control fallback isn't possible, we return
+ * -EOPNOTSUPP to the user, but still store the selected mode. This is needed
+ * in case an intermediate unsupported mode is necessary to switch from one
+ * supported mode to another.
  */
 
 struct led_netdev_data {
@@ -306,6 +316,7 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
 				     size_t size, enum led_trigger_netdev_modes attr)
 {
 	struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
+	struct led_classdev *led_cdev = trigger_data->led_cdev;
 	unsigned long state, mode = trigger_data->mode;
 	int ret;
 	int bit;
@@ -345,6 +356,10 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
 	trigger_data->mode = mode;
 	trigger_data->hw_control = can_hw_control(trigger_data);
 
+	if (!led_cdev->brightness_set && !led_cdev->brightness_set_blocking &&
+	    !trigger_data->hw_control)
+		return -EOPNOTSUPP;
+
 	set_baseline_state(trigger_data);
 
 	return size;
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Heiner Kallweit

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

Quoted 4 lines

Add a comment explaining how a driver for such hw is supposed to behave.

---

For whatever reason this patch (original version and resubmit) doesn't show up on linux-leds patchwork. In netdev patchwork it's visible.

maintainer
#2 lore raw
Quoted 9 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

Quoted 7 lines
Quoted 4 lines

Add a comment explaining how a driver for such hw is supposed to behave.

---

For whatever reason this patch (original version and resubmit) doesn't show up on linux-leds patchwork. In netdev patchwork it's visible.

Never used it. Do you have a link?

Signature · 1 line
Lee Jones [李琼斯]
#3 lore raw
Quoted 13 lines · Lee Jones
Quoted 11 lines · Heiner Kallweit
Quoted 10 lines · Heiner Kallweit

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

Add a comment explaining how a driver for such hw is supposed to behave.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

---

For whatever reason this patch (original version and resubmit) doesn't show up on linux-leds patchwork. In netdev patchwork it's visible.

Never used it. Do you have a link?

This is the original patch in netdev patchwork
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

This is my patches in linux-leds patchwork. The one from Dec 6th is missing here.
https://patches.linaro.org/project/linux-leds/list/?series=&submitter=6702&state=*&q=&archive=&delegate=
However the resubmitted one showed up later.

maintainer
#4 lore raw
Quoted 20 lines · Heiner Kallweit
Quoted 19 lines · Lee Jones
Quoted 16 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

Quoted 4 lines

Add a comment explaining how a driver for such hw is supposed to behave.

---

For whatever reason this patch (original version and resubmit) doesn't show up on linux-leds patchwork. In netdev patchwork it's visible.

Quoted 8 lines
Quoted 2 lines

Never used it. Do you have a link?

This is the original patch in netdev patchwork
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

This is my patches in linux-leds patchwork. The one from Dec 6th is missing here.
https://patches.linaro.org/project/linux-leds/list/?series=&submitter=6702&state=*&q=&archive=&delegate=
However the resubmitted one showed up later.

AFAIW, that's not the official Patchwork for LEDs.

And as I say, I don't use it, so I'm not really in a position to comment.

Do we still have something outstanding?

Signature · 1 line
Lee Jones [李琼斯]
#5 lore raw
Quoted 31 lines · Lee Jones
Quoted 20 lines · Heiner Kallweit
Quoted 19 lines · Lee Jones
Quoted 16 lines · Heiner Kallweit
Quoted 8 lines · Heiner Kallweit

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

Quoted 4 lines

Add a comment explaining how a driver for such hw is supposed to behave.

---

For whatever reason this patch (original version and resubmit) doesn't show up on linux-leds patchwork. In netdev patchwork it's visible.

Quoted 8 lines
Quoted 2 lines

Never used it. Do you have a link?

This is the original patch in netdev patchwork
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

This is my patches in linux-leds patchwork. The one from Dec 6th is missing here.
https://patches.linaro.org/project/linux-leds/list/?series=&submitter=6702&state=*&q=&archive=&delegate=
However the resubmitted one showed up later.

Quoted 6 lines

AFAIW, that's not the official Patchwork for LEDs.

And as I say, I don't use it, so I'm not really in a position to comment.

Do we still have something outstanding?

Thanks for asking. No, that's it for now.

Reviewed-by on v1 1/1
#6 lore raw
In reply to Heiner Kallweit
Quoted 11 lines · Heiner Kallweit

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

Add a comment explaining how a driver for such hw is supposed to behave.

Andrew

maintainer Applied
#7 lore raw

Re: (subset) [PATCH RESUBMIT] leds: trigger: netdev: add core support for hw not supporting fallback to LED sw control

In reply to Heiner Kallweit
Quoted 9 lines · Heiner Kallweit

If hw doesn't support sw control of the LED and we switch to a mode not supported by hw, currently we get lots of errors because neither brigthness_set() nor brithness_set_blocking() is set. Deal with this by not falling back to sw control, and return -EOPNOTSUPP to the user. Note that we still store the new mode. This is needed in case an intermediate unsupported mode is necessary to switch from one supported mode to another.

[...]

Applied, thanks!

[1/1] leds: trigger: netdev: add core support for hw not supporting fallback to LED sw control

      commit: cb2ab62ae08af6a5ef1e3aaf954a8eaadd6ce17a

--
Lee Jones [李琼斯]