Skip to content

Commit 4e89354

Browse files
mtkaczykbjorn-helgaas
authored andcommitted
PCI/NPEM: Add Native PCIe Enclosure Management support
Native PCIe Enclosure Management (NPEM, PCIe r6.1 sec 6.28) allows managing LEDs in storage enclosures. NPEM is indication oriented and it does not give direct access to LEDs. Although each indication *could* represent an individual LED, multiple indications could also be represented as a single, multi-color LED or a single LED blinking in a specific interval. The specification leaves that open. Each enabled indication (capability register bit on) is represented as a ledclass_dev which can be controlled through sysfs. For every ledclass device only 2 brightness states are allowed: LED_ON (1) or LED_OFF (0). This corresponds to the NPEM control register (Indication bit on/off). Ledclass devices appear in sysfs as child devices (subdirectory) of PCI device which has an NPEM Extended Capability and indication is enabled in NPEM capability register. For example, these are LEDs created for pcieport "10000:02:05.0" on my setup: leds/ ├── 10000:02:05.0:enclosure:fail ├── 10000:02:05.0:enclosure:locate ├── 10000:02:05.0:enclosure:ok └── 10000:02:05.0:enclosure:rebuild They can be also found in "/sys/class/leds" directory. The parent PCIe device domain/bus/device/function address is used to guarantee uniqueness across leds subsystem. To enable/disable a "fail" indication, the "brightness" file can be edited: echo 1 > ./leds/10000:02:05.0:enclosure:fail/brightness echo 0 > ./leds/10000:02:05.0:enclosure:fail/brightness PCIe r6.1, sec 7.9.19.2 defines the possible indications. Multiple indications for same parent PCIe device can conflict and hardware may update them when processing new request. To avoid issues, driver refresh all indications by reading back control register. This driver expects to be the exclusive NPEM extended capability manager. It waits up to 1 second after imposing new request, it doesn't verify if controller is busy before write, and it assumes the mutex lock gives protection from concurrent updates. If _DSM LED management is available, we assume the platform may be using NPEM for its own purposes (see PCI Firmware Spec r3.3 sec 4.7), so the driver does not use NPEM. A future patch will add _DSM support; an info message notes whether NPEM or _DSM is being used. NPEM is a PCIe extended capability so it should be registered in pcie_init_capabilities() but it is not possible due to LED dependency. The parent pci_device must be added earlier for led_classdev_register() to be successful. NPEM does not require configuration on kernel side, so it is safe to register LED devices later. Link: https://lore.kernel.org/r/20240904104848.23480-3-mariusz.tkaczyk@linux.intel.com Suggested-by: Lukas Wunner <lukas@wunner.de> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Tested-by: Stuart Hayes <stuart.w.hayes@gmail.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 78efa53 commit 4e89354

9 files changed

Lines changed: 546 additions & 0 deletions

File tree

Documentation/ABI/testing/sysfs-bus-pci

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,66 @@ Description:
500500
console drivers from the device. Raw users of pci-sysfs
501501
resourceN attributes must be terminated prior to resizing.
502502
Success of the resizing operation is not guaranteed.
503+
504+
What: /sys/bus/pci/devices/.../leds/*:enclosure:*/brightness
505+
What: /sys/class/leds/*:enclosure:*/brightness
506+
Date: August 2024
507+
KernelVersion: 6.12
508+
Description:
509+
LED indications on PCIe storage enclosures which are controlled
510+
through the NPEM interface (Native PCIe Enclosure Management,
511+
PCIe r6.1 sec 6.28) are accessible as led class devices, both
512+
below /sys/class/leds and below NPEM-capable PCI devices.
513+
514+
Although these led class devices could be manipulated manually,
515+
in practice they are typically manipulated automatically by an
516+
application such as ledmon(8).
517+
518+
The name of a led class device is as follows:
519+
<bdf>:enclosure:<indication>
520+
where:
521+
522+
- <bdf> is the domain, bus, device and function number
523+
(e.g. 10000:02:05.0)
524+
- <indication> is a short description of the LED indication
525+
526+
Valid indications per PCIe r6.1 table 6-27 are:
527+
528+
- ok (drive is functioning normally)
529+
- locate (drive is being identified by an admin)
530+
- fail (drive is not functioning properly)
531+
- rebuild (drive is part of an array that is rebuilding)
532+
- pfa (drive is predicted to fail soon)
533+
- hotspare (drive is marked to be used as a replacement)
534+
- ica (drive is part of an array that is degraded)
535+
- ifa (drive is part of an array that is failed)
536+
- idt (drive is not the right type for the connector)
537+
- disabled (drive is disabled, removal is safe)
538+
- specific0 to specific7 (enclosure-specific indications)
539+
540+
Broadly, the indications fall into one of these categories:
541+
542+
- to signify drive state (ok, locate, fail, idt, disabled)
543+
- to signify drive role or state in a software RAID array
544+
(rebuild, pfa, hotspare, ica, ifa)
545+
- to signify any other role or state (specific0 to specific7)
546+
547+
Mandatory indications per PCIe r6.1 sec 7.9.19.2 comprise:
548+
ok, locate, fail, rebuild. All others are optional.
549+
A led class device is only visible if the corresponding
550+
indication is supported by the device.
551+
552+
To manipulate the indications, write 0 (LED_OFF) or 1 (LED_ON)
553+
to the "brightness" file. Note that manipulating an indication
554+
may implicitly manipulate other indications at the vendor's
555+
discretion. E.g. when the user lights up the "ok" indication,
556+
the vendor may choose to automatically turn off the "fail"
557+
indication. The current state of an indication can be
558+
retrieved by reading its "brightness" file.
559+
560+
The PCIe Base Specification allows vendors leeway to choose
561+
different colors or blinking patterns for the indications,
562+
but they typically follow the IBPI standard. E.g. the "locate"
563+
indication is usually presented as one or two LEDs blinking at
564+
4 Hz frequency:
565+
https://en.wikipedia.org/wiki/International_Blinking_Pattern_Interpretation

drivers/pci/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ config PCI_IOV
143143

144144
If unsure, say N.
145145

146+
config PCI_NPEM
147+
bool "Native PCIe Enclosure Management"
148+
depends on LEDS_CLASS=y
149+
help
150+
Support for Native PCIe Enclosure Management. It allows managing LED
151+
indications in storage enclosures. Enclosure must support following
152+
indications: OK, Locate, Fail, Rebuild, other indications are
153+
optional.
154+
146155
config PCI_PRI
147156
bool "PCI PRI support"
148157
select PCI_ATS

drivers/pci/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
3535
obj-$(CONFIG_VGA_ARB) += vgaarb.o
3636
obj-$(CONFIG_PCI_DOE) += doe.o
3737
obj-$(CONFIG_PCI_DYNAMIC_OF_NODES) += of_property.o
38+
obj-$(CONFIG_PCI_NPEM) += npem.o
3839

3940
# Endpoint library must be initialized before its users
4041
obj-$(CONFIG_PCI_ENDPOINT) += endpoint/

0 commit comments

Comments
 (0)