#
#  Intel(R) Enclosure LED Utilities
#  Copyright (C) 2009-2023 Intel Corporation.
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms and conditions of the GNU General Public License,
#  version 2, as published by the Free Software Foundation.
#
#  This program is distributed in the hope it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#  more details.
#
#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc.,
#  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
#
=head1 NAME

ledctl - Intel(R) LED control application for a storage enclosures.

=head1 SYNOPSIS

B<ledctl> [I<OPTIONS>] I<pattern_name>=I<list_of_devices> ...

=head1 DESCRIPTION

The ledctl is an user space application designed to control LEDs associated with each
slot in an enclosure or a drive bay. The LEDs of devices listed in I<list_of_devices>
are set to the given pattern I<pattern_name> and all other LEDs are turned off.
User must have root privileges to use this application.

There are two types of systems: 2-LEDs systems (Activity LED, Status LED)
and 3-LEDs systems (Activity LED, Locate LED, Fail LED).

The ledctl application supports LED management of the SAS/SATA and PCIe
storages.

=head4 Supported protocols/methods for LED management are:

=over

=item

B<SES-2 and SMP> for SAS devices,

=item

B<LED messages over SGPIO> for SATA,

=item

B<VMD and NPEM> for PCIe.

=back

B<SAF-TE> protocol is not supported.

For SAS/SATA storages supporting controllers may transmit LED management
information to the backplane controllers via the SGPIO interface. The SGPIO
bus carries bit patterns, which translate into LED blink patterns in
accordance with the International Blinking Pattern Interpretation (IBPI)
of SFF-8489 specification for SGPIO.
Please note some enclosures do not stick close to the SFF-8489
specification. It might happen that the enclosure processor will accept
the IBPI pattern but it will blink LEDs not according to SFF-8489
specification or it has a limited number of patterns supported.

The ledctl application has been verified to work with Intel(R) storage
controllers (i.e. Intel(R) AHCI controller and Intel(R) SAS controller).
The application might work with storage controllers of other vendors
(especially SCSI/SAS controllers). However, storage controllers of other
vendors have not been tested.

The ledmon application has the highest priority when accessing LEDs.
It means that some patterns set by ledctl may have no effect if ledmon is running
(except Locate pattern).

The ledctl application is a part of Intel(R) Enclosure LED Utilities.

=head4 The ledctl utilizes the following documents as references:

=over

=item

SGPIO (Serial GPIO) - SFF-8485

=item

IBPI (International Blinking Pattern Interpretation) - SFF-8489

=item

LED Enclosure management messages - AHCI specification rev 1.3,
section 12.2.1.

=item

SAS (Serial Attached SCSI) - T10/1760-D

=item

SES-2 (SCSI Enclosure Services-2) - T10/1559-D

=item

SMP (Serial Management Protocol) - T10/1760-D

=item

NPEM (Native PCIe Enclosure Management) - PCIe base specification rev 4.0

=item

VMD (Intel(R) Volume Management Device) - Intel(R) VROC (VMD NVMe RAID) Quick

Configuration Guide rev 1.2

=back

=head2 Pattern Names

The ledctl application accepts the following names for I<pattern_name> argument
according to SFF-8489 specification.

=over 8

=item B<locate>

Turns Locate LED associated with the given device(s) on.

=item B<locate_off>

Turns only Locate LED off.

=item B<normal>

Turns Status LED, Failure LED and Locate LED off.

=item B<off>

Turns only Status LED and Failure LED off.

=item B<ica> or B<degraded>

Visualizes "In a Critical Array" pattern.

=item B<rebuild>

Visualizes "Rebuild" pattern.

=item B<ifa> or B<failed_array>

Visualizes "In a Failed Array" pattern.

=item B<hotspare>

Visualizes "Hotspare" pattern.

=item B<pfa>

Visualizes "Predicted Failure Analysis" pattern.

=item B<failure> or B<disk_failed>

Visualizes "Failure" pattern.

=item B<ses_abort>

SES-2 R/R ABORD

=item B<ses_rebuild>

SES-2 REBUILD/REMAP

=item B<ses_ifa>

SES-2 IN FAILED ARRAY

=item B<ses_ica>

SES-2 IN CRIT ARRAY

=item B<ses_cons_check>

SES-2 CONS CHECK

=item B<ses_hotspare>

SES-2 HOT SPARE

=item B<ses_rsvd_dev>

SES-2 RSVD DEVICE

=item B<ses_ok>

SES-2 OK

=item B<ses_ident>

SES-2 IDENT

=item B<ses_rm>

SES-2 REMOVE

=item B<ses_insert>

SES-2 INSERT

=item B<ses_missing>

SES-2 MISSING

=item B<ses_dnr>

SES-2 DO NOT REMOVE

=item B<ses_active>

SES-2 ACTIVE

=item B<ses_enable_bb>

SES-2 ENABLE BYP B

=item B<ses_enable_ba>

SES-2 ENABLE BYP A

=item B<ses_devoff>

SES-2 DEVICE OFF

=item B<ses_fault>

SES-2 FAULT

=item B<ses_prdfail>

SES-2 PRDFAIL

=back

=head2 Patterns Translation

When non SES-2 pattern is send to device in enclosure automatic
translation is being done.

=over 8

=item B<locate>

I<locate> is translated to I<ses_ident>

=item B<locate_off>

I<locate_off> is translated to I<~ses_ident>

=item B<normal> or B<off>

I<normal> or I<off> is translated to I<ses_ok>

=item B<ica> or B<degraded>

I<ica> or I<degraded> is translated to I<ses_ica>

=item B<rebuild>

I<rebuild> is translated to I<ses_rebuild>

=item B<ifa> or B<failed_array>

I<ifa> or I<failed_array> is translated to I<ses_ifa>

=item B<hotspare>

I<hotspare> is translated to I<ses_hotspare>

=item B<pfa>

I<pfa> is translated to I<ses_prdfail>

=item B<failure> or B<disk_failed>

I<failure> or I<disk_failed> is translated to I<ses_fault>

=back

=head2 List of Devices

The application accepts a list of devices in two formats. The first
format is a list with comma separated elements. The second format is S<a
list> in curly braces and elements are separated by space. See examples
section below for details.

A device is a path to file in /dev directory or in /sys/block directory.

The LEDs of devices listed in I<list_of_devices> are set to the given
pattern I<pattern_name> and all other LEDs, on all devices, are turned off (unless --listed-only
option is given).

=head1 OPTIONS

=over 8

=item B<-l> or B<--log>=I<path>

Sets a path to local log file. If this option is specified the global log
file F</var/log/ledctl.log> is not used.

=item B<-h> or B<--help>

Prints this text out and exits.

=item B<-v> or B<--version>

Displays version of ledctl and information about the license and exits.

=item B<-L> or B<--list-controllers>

Prints information (system path and type) of all controllers detected by
ledmon and exits.

=item B<-P> or B<--list-slots> B<--controller-type>=I<controller-type>

Prints all slots for the controller type. Slot definition depends on the controller
and is unique across all controllers of the same type.

Definitions for supported controller types are described below:

=over

=item

VMD - PCI Express Hot Plug Controller Driver slot number

=item

NPEM - PCI Express Downstream Port address

=back

Command returns a list of all slots for the controller type with current state and
attached device name (if any). I<controller-type> is type of controller
(vmd, NPEM) that should be scanned here.

=item B<-G> or B<--get-slot> B<--controller-type>=I<controller-type> B<--device>=I<device>

Displays slot details of given device. I<device> is devnode of selected drive.

=item B<-G> or B<--get-slot> B<--controller-type>=I<controlle-typer> B<--slot>=I<slot>

Displays details of given slot. I<slot> is unique slot identifier.

=item B<-S> or B<--set-slot> B<--controller-type>=I<controller-type> B<--slot>=I<slot> B<--state>=I<IBPI_state>

Changes led state for given slot. I<controller-type> is type of the controller.
I<slot> is unique slot identifier. I<IBPI_state> is led pattern.

=item B<-x> or B<--listed-only>

With this option ledctl will change state only on devices listed in CLI. The
rest of devices will not be touched.

=item B<--quiet> or B<--error> or B<--warning> or B<--info> or B<--debug> or B<--all>

Verbose level - 'quiet' means no logging at all and 'all' means to log
everything. The levels are given in order. If user specifies more then one
verbose option the last option comes into effect. The default level is
'warning'. Verbose level also can be set by B<--log-level>=I<level>.

=back

=head1 FILES

=over 8

=item F</var/log/ledctl.log>

Global log file, used by all instances of ledctl application. To force logging
to user defined file use I<-l> option switch.

=back

=head1 EXAMPLES

The following example illustrates how to set I<locate> on a single
block device. Note that all remaining LEDs, on all devices, will be turned off.

    ledctl locate=/dev/sda

The following example illustrates how to set I<locate_off> on a single
block device.

    ledctl --listed-only locate_off=/dev/sda

The following example illustrates how to set I<off> on the given devices. It
uses second format of device list.

     ledctl --listed-only off={ /dev/sda /dev/sdb }

The following example illustrates how to set I<locate> and I<rebuild> on
different devices at the same time. It uses the second format of device list.

     ledctl --listed-only locate={ /dev/sdb } rebuild={ /sys/block/sdc }

The following example illustrates how to I<locate> on three block devices. It
uses the first format of device list.

     ledctl --listed-only locate=/dev/sda,/dev/sdb,/dev/sdc

The following example illustrates how to set I<locate> and I<rebuild> on
different devices at the same time. It uses the first format of device list.

     ledctl --listed-only locate=/dev/sdb rebuild=/sys/block/sdc

The following example illustrates how to set I<locate> and I<rebuild> on
different devices at the same time. It uses the both formats of device list.

     ledctl --listed-only locate={ /dev/sdb } rebuild=/sys/block/sdc

=head1 LICENSE

Copyright (c) 2009-2022 Intel Corporation.

This program is distributed under the terms of the GNU General Public License
as published by the Free Software Foundation. See the built-in help for
details on the License and the lack of warranty.

=head1 SEE ALSO

ledmon(8), ledmon.conf(5)

=head1 AUTHOR

This manual page was written by Artur Wojcik <artur.wojcik@intel.com>. It may
be used by others.
