Skip to content

[25.12] leds: add "network" LED trigger (lan/wan/wlan)#23685

Merged
openwrt-bot merged 1 commit into
openwrt:openwrt-25.12from
namiltd:ledtrig
Jun 27, 2026
Merged

[25.12] leds: add "network" LED trigger (lan/wan/wlan)#23685
openwrt-bot merged 1 commit into
openwrt:openwrt-25.12from
namiltd:ledtrig

Conversation

@namiltd

@namiltd namiltd commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Cherry picked from commit 2aa1185

I noticed two solutions for displaying the status of several devices/ports using a single LED:

  • we are using DSA switch and we need simultaneous status of LAN1, LAN2, LAN3 and LAN4 on single LED_LAN (br-lan also includes WLAN so it cannot be used, the switch also has WAN port)
  • there is one LED_WLAN and two interfaces phy0 and phy1

Additionally, it's not possible to define a WAN LED directly in the DTS file.

That's why he created an additional ledtrig_network module to solve all these problems at once.

Features:

  • Automatic recognition of interface family (lan/wan/wlan) from LED name, or explicitly from device-tree property 'family'.
  • Flags (link/tx/rx) are taken from device-tree property 'mode' (only tokens "link", "tx", "rx" are allowed). If 'mode' is absent, flags default to link+tx+rx.
  • Precedence: DT 'mode' overrides any flags in the name; DT 'family' overrides family from the name.
  • LED name may be suffixed with "-online" (e.g. "green:wlan-online") — this makes the LED online-only (link=true, tx=false, rx=false), but only when DT 'mode' is absent.
  • You can set the trigger parameters at runtime via the trigger sysfs, for example:
    • echo "network" > /sys/class/leds/<led>/trigger
    • echo "lan" > /sys/class/leds/<led>/family
    • echo 0 > /sys/class/leds/<led>/link
  • Three families supported:
    • lan: oneshot blink on packet-count change (suitable for wired LAN ports).
    • wan: oneshot blink on packet-count change (suitable for upstream/WAN).
    • wlan: throughput-driven blinking with multiple thresholds to change blink on/off durations according to traffic level.
  • Aggregates multiple interfaces of the same family and updates all subscribed LEDs from the aggregated statistics.
  • Interfaces are auto-tracked by name match (lan0, wan1, wlan2, phy0, wl1, ath0, ra0...).
  • Safe notifier/refcounting and background worker for periodic aggregation.

Sample DTS file:

		led-1 {
			function = LED_FUNCTION_WLAN;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio3 0 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "network";
		};

		led-2 {
			function = LED_FUNCTION_WAN;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "network";
		};

		led-3 {
			function = LED_FUNCTION_ACTIVITY;
			color = <LED_COLOR_ID_GREEN>;
			gpios = <&gpio2 3 GPIO_ACTIVE_LOW>;
			linux,default-trigger = "network";
			family = "lan";
			mode = "link rx";
		};

dmesg | grep ledtrig_network

[    5.143901] ledtrig_network: LED green:wlan - trigger wlan(link tx rx) attached
[    5.150785] ledtrig_network: wan - interface wan registered
[    5.156560] ledtrig_network: LED green:wan - trigger wan(link tx rx) attached
[    5.163063] ledtrig_network: lan - interface lan1 registered
[    5.168902] ledtrig_network: lan - interface lan2 registered
[    5.174680] ledtrig_network: lan - interface lan3 registered
[    5.180485] ledtrig_network: LED green:activity - trigger lan(link rx) attached
[   90.465399] ledtrig_network: wlan - interface phy0-ap0 registered
[  129.460576] ledtrig_network: wlan - interface phy1-ap0 registered

Link: #19903

@github-actions github-actions Bot added target/bcm27xx pull request/issue for bcm27xx target kernel pull request/issue with Linux kernel related changes core packages pull request/issue for core (in-tree) packages release/25.12 pull request/issue targeted (also) for OpenWrt 24.10 release labels Jun 6, 2026
@namiltd namiltd changed the title leds: add "network" LED trigger (lan/wan/wlan) [25.12] leds: add "network" LED trigger (lan/wan/wlan) Jun 6, 2026
@namiltd
namiltd marked this pull request as ready for review June 6, 2026 11:51

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit; no new issues found.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 new commit; no new issues found.

Backport verification: the (cherry picked from commit 2aa1185fb05eb7f2e4c7e4f9c66e3727010328af) trailer is present and correct. The four substantive files (package/kernel/linux/modules/leds.mk, the bcm27xx 950-0189 patch refresh, ledtrig-network.c, and hack-6.12/820-ledtrig-network-module.patch) are byte-identical to the upstream commit. The upstream commit also touched config-6.18 and hack-6.18/820-ledtrig-network-module.patch; dropping those is correct since the openwrt-25.12 base branch carries only kernel 6.12 under target/linux/generic/. The commit message matches the diff.


Generated by Claude Code

LED trigger for network interfaces.

 - Aggregated per-family (lan/wan/wlan).
 - Family and flags are taken from device tree properties:
   - "family" : simple family string "lan" | "wan" | "wlan"
   - "mode"   : any combination of "link", "tx", "rx" flags
  Priority/combination:
   * If "mode" present: flags come from "mode" and take precedence.
     Family is taken from "family" if present, otherwise from the LED name.
   * If only "family" present: use its family and default flags = link+tx+rx.
   * If neither present: fall back to LED device name parsing.

 - Suffix "-online" is valid ONLY in the LED name (label),
   e.g. "green:wlan-online". It indicates the online variant but is applied
   only when DT "mode" is absent.

Behaviour:
 - wlan (normal): blink/solid driven by throughput table
 - lan/wan (normal): one-shot blink on TX/RX packet change
 - *-online variants: steady ON while any interface of the family has carrier

 Interfaces are auto-tracked by name match (lan0, wan1, wlan2, phy0, wl1,
 ath0, ra0...). Up to MAX_IFACES (16) interfaces per family

This trigger is intended for board/device authors and drivers to provide simple
network-activity LED behaviour without per-interface wiring in userspace.

Refresh bcm27xx patches in the same commit to account for line shifts in
drivers/leds/trigger/Kconfig and Makefile, ensuring clean applies for
bisectability.

Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
Link: openwrt#19903
Signed-off-by: Robert Marko <robimarko@gmail.com>
(cherry picked from commit 2aa1185)
Link: openwrt#23685
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
@openwrt-bot
openwrt-bot merged commit f191b85 into openwrt:openwrt-25.12 Jun 27, 2026
4 checks passed
@namiltd
namiltd deleted the ledtrig branch June 27, 2026 12:41
oxavelar pushed a commit to oxavelar/openwrt that referenced this pull request Jul 2, 2026
LED trigger for network interfaces.

 - Aggregated per-family (lan/wan/wlan).
 - Family and flags are taken from device tree properties:
   - "family" : simple family string "lan" | "wan" | "wlan"
   - "mode"   : any combination of "link", "tx", "rx" flags
  Priority/combination:
   * If "mode" present: flags come from "mode" and take precedence.
     Family is taken from "family" if present, otherwise from the LED name.
   * If only "family" present: use its family and default flags = link+tx+rx.
   * If neither present: fall back to LED device name parsing.

 - Suffix "-online" is valid ONLY in the LED name (label),
   e.g. "green:wlan-online". It indicates the online variant but is applied
   only when DT "mode" is absent.

Behaviour:
 - wlan (normal): blink/solid driven by throughput table
 - lan/wan (normal): one-shot blink on TX/RX packet change
 - *-online variants: steady ON while any interface of the family has carrier

 Interfaces are auto-tracked by name match (lan0, wan1, wlan2, phy0, wl1,
 ath0, ra0...). Up to MAX_IFACES (16) interfaces per family

This trigger is intended for board/device authors and drivers to provide simple
network-activity LED behaviour without per-interface wiring in userspace.

Refresh bcm27xx patches in the same commit to account for line shifts in
drivers/leds/trigger/Kconfig and Makefile, ensuring clean applies for
bisectability.

Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
Link: openwrt#19903
Signed-off-by: Robert Marko <robimarko@gmail.com>
(cherry picked from commit 2aa1185)
Link: openwrt#23685
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
liudf0716 pushed a commit to liudf0716/chawrt that referenced this pull request Jul 21, 2026
LED trigger for network interfaces.

 - Aggregated per-family (lan/wan/wlan).
 - Family and flags are taken from device tree properties:
   - "family" : simple family string "lan" | "wan" | "wlan"
   - "mode"   : any combination of "link", "tx", "rx" flags
  Priority/combination:
   * If "mode" present: flags come from "mode" and take precedence.
     Family is taken from "family" if present, otherwise from the LED name.
   * If only "family" present: use its family and default flags = link+tx+rx.
   * If neither present: fall back to LED device name parsing.

 - Suffix "-online" is valid ONLY in the LED name (label),
   e.g. "green:wlan-online". It indicates the online variant but is applied
   only when DT "mode" is absent.

Behaviour:
 - wlan (normal): blink/solid driven by throughput table
 - lan/wan (normal): one-shot blink on TX/RX packet change
 - *-online variants: steady ON while any interface of the family has carrier

 Interfaces are auto-tracked by name match (lan0, wan1, wlan2, phy0, wl1,
 ath0, ra0...). Up to MAX_IFACES (16) interfaces per family

This trigger is intended for board/device authors and drivers to provide simple
network-activity LED behaviour without per-interface wiring in userspace.

Refresh bcm27xx patches in the same commit to account for line shifts in
drivers/leds/trigger/Kconfig and Makefile, ensuring clean applies for
bisectability.

Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
Link: openwrt/openwrt#19903
Signed-off-by: Robert Marko <robimarko@gmail.com>
(cherry picked from commit 2aa1185fb05eb7f2e4c7e4f9c66e3727010328af)
Link: openwrt/openwrt#23685
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
(cherry picked from commit f191b85d2f7b90b7f907958cfccc0e291ed5e2b3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes release/25.12 pull request/issue targeted (also) for OpenWrt 24.10 release target/bcm27xx pull request/issue for bcm27xx target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants