Skip to content

Controlling LEDs

Ido Schimmel edited this page Dec 15, 2016 · 8 revisions
Table of Contents
  1. Preparation
  2. Controlling LEDs
  3. Controlling LEDs Brightness
  4. LEDs Triggers
  5. Further Resources
Preparation -----------

The leds_mlxcpld kernel module is in charge of providing standard sysfs access to the LEDs on Mellanox switches. Hence, in order to control the LEDs, one must make sure that the module is compiled and loaded.

Module compilation is controlled via the CONFIG_LEDS_MLXCPLD config option.

To verify whether the module is loaded, the following command can be used:

$ lsmod | grep leds_mlxcpld

If the module is not loaded, it can be loaded using:

$ modprobe leds_mlxcpld

When installing the provided .iso file according to the instructions, the module will be automatically loaded on boot via /etc/modules-load.d/mlxleds.conf.

Controlling LEDs ----------------

To control the LEDs' status from user space, the sysfs interface can be used. For every LED and every color, there exist a directory named:

/sys/class/leds/<driver>:<LED name>:<LED color>

For example, on a Spectrum machine, the following directories are created:

$ ls /sys/class/leds/
mlxcpld:fan1:green
mlxcpld:fan1:red
mlxcpld:fan2:green
mlxcpld:fan2:red
mlxcpld:fan3:green
mlxcpld:fan3:red
mlxcpld:fan4:green
mlxcpld:fan4:red
mlxcpld:psu:green
mlxcpld:psu:red
mlxcpld:status:green
mlxcpld:status:red

#### Controlling LEDs Brightness

Controlling or querying the brightness of a specific LED and color can be done via the <LED dir>/brightness file. This file contains integer values that vary from 0 to <LED dir>/max_brightness value.

For example, to set the status LED to be green, the following commands can be used:

$ cd /sys/class/leds
$ echo 0 > mlxcpld\:status\:red/brightness
$ cat mlxcpld\:status\:green/max_brightness > mlxcpld\:status\:green/brightness
#### LEDs Triggers

The kernel LEDs infrastructure allows connecting certain LEDs to certain triggers. To control a LED trigger, the <LED dir>/trigger file can be used.

To list all available triggers, use the command:

$ cat <LED dir>/trigger

For example, to make a led blink, the timer trigger can be used. Once the following command is ran:

$ echo timer > <LED dir>/trigger

Tthe files delay_on and delay_off are added under <LED dir>. With those two files, it is possible to set the LED frequency and duty-cycle, as the delay_on sets the number of miliseconds that the LED will be in ON state, and the delay_off sets the number of miliseconds that the LED will be in OFF state. Hence, the total frequency is 1.0/(delay_on + delay_off) KHz.

Note: To use the timer trigger, one must make sure that the ledtrig-timer module is loaded. In the provided .iso file, the module is loaded on startup.

Further Resources -----------------
  1. LEDs class documentation in kernel source tree
  2. leds_mlxcpld documentation in kernel source tree
Clone this wiki locally