linux-next/drivers/leds/trigger
Marek Vasut 0dfda50988 leds: trigger: netdev: Check offload ability on interface up
The trigger_data->hw_control indicates whether the LED is controlled by HW
offload, i.e. the PHY. The trigger_data->hw_control = can_hw_control() is
currently called only from netdev_led_attr_store(), i.e. when writing any
sysfs attribute of the netdev trigger instance associated with a PHY LED.

The can_hw_control() calls validate_net_dev() which internally calls
led_cdev->hw_control_get_device(), which is phy_led_hw_control_get_device()
for PHY LEDs. The phy_led_hw_control_get_device() returns NULL if the PHY
is not attached.

At least in case of DWMAC (STM32MP, iMX8M, ...), the PHY device is attached
only when the interface is brought up and is detached again when the
interface is brought down. In case e.g. udev rules configure the netdev
LED trigger sysfs attributes before the interface is brought up, then when
the interface is brought up, the LEDs are not blinking.

This is because trigger_data->hw_control = can_hw_control() was called
when udev wrote the sysfs attribute files, before the interface was up,
so can_hw_control() resp. validate_net_dev() returned false, and the
trigger_data->hw_control = can_hw_control() was never called again to
update the trigger_data->hw_control content and let the offload take
over the LED blinking.

Call data->hw_control = can_hw_control() from netdev_trig_notify() to
update the offload capability of the LED when the UP notification arrives.
This makes the LEDs blink after the interface is brought up.

On STM32MP13xx with RTL8211F, it is enough to have the following udev rule
in place, boot the machine with cable plugged in, and the LEDs won't work
without this patch once the interface is brought up, even if they should:
"
ACTION=="add", SUBSYSTEM=="leds", KERNEL=="stmmac-0:01:green:wan", ATTR{trigger}="netdev", ATTR{link_10}="1", ATTR{link_100}="1", ATTR{link_1000}="1", ATTR{device_name}="end0"
ACTION=="add", SUBSYSTEM=="leds", KERNEL=="stmmac-0:01:yellow:wan", ATTR{trigger}="netdev", ATTR{rx}="1", ATTR{tx}="1", ATTR{device_name}="end0"
"

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/20241216104826.6946-1-marex@denx.de
Signed-off-by: Lee Jones <lee@kernel.org>
2024-12-17 13:10:48 +00:00
..
Kconfig leds: trigger: Add new LED Input events trigger 2024-06-21 11:57:17 +01:00
ledtrig-activity.c leds: ledtrig-activity: Fix the wrong format specifier 2024-12-12 17:28:27 +00:00
ledtrig-backlight.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ledtrig-camera.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ledtrig-cpu.c leds: trigger: ledtrig-cpu:: Fix 'output may be truncated' issue for 'cpu' 2023-11-01 11:28:51 +00:00
ledtrig-default-on.c leds: triggers: default-on: Add module alias for module auto-loading 2024-03-07 08:48:00 +00:00
ledtrig-disk.c leds: Change led_trigger_blink[_oneshot]() delay parameters to pass-by-value 2023-05-25 12:16:27 +01:00
ledtrig-gpio.c leds: trigger: gpio: Convert to DEVICE_ATTR_RW() 2023-12-13 11:28:39 +00:00
ledtrig-heartbeat.c treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
ledtrig-input-events.c leds: trigger: input-events: Rewrite to fix a serious locking issue 2024-06-26 16:56:12 +01:00
ledtrig-mtd.c leds: Change led_trigger_blink[_oneshot]() delay parameters to pass-by-value 2023-05-25 12:16:27 +01:00
ledtrig-netdev.c leds: trigger: netdev: Check offload ability on interface up 2024-12-17 13:10:48 +00:00
ledtrig-oneshot.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
ledtrig-panic.c leds: trigger: panic: Simplify led_trigger_set_panic 2024-03-07 08:48:01 +00:00
ledtrig-pattern.c leds: trigger: pattern: Add support for hrtimer 2024-05-02 17:32:01 +01:00
ledtrig-timer.c leds: triggers: Flush pending brightness before activating trigger 2024-06-26 16:56:07 +01:00
ledtrig-transient.c treewide: Convert del_timer*() to timer_shutdown*() 2022-12-25 13:38:09 -08:00
ledtrig-tty.c leds: ledtrig-tty: Add additional line state evaluation 2023-12-13 11:28:51 +00:00
Makefile leds: trigger: Add new LED Input events trigger 2024-06-21 11:57:17 +01:00