PCIe Enclosure LED Management
v5 cover PCIe Enclosure LED Management
Patchset is named as PCIe Enclosure LED Management because it adds two features:
- Native PCIe Enclosure Management (NPEM)
- PCIe SSD Status LED Management (DSM)
Both are pattern oriented standards, they tell which "indication" should blink. It doesn't control physical LED or pattern visualization.
Overall, driver is simple but it was not simple to fit it into interfaces we have in kernel (We considered leds and enclosure interfaces). It reuses leds interface, this approach seems to be the best because:
- leds are actively maintained, no new interface added.
- leds do not require any extensions, enclosure needs to be adjusted first.
There are trade-offs:
- "brightness" is the name of sysfs file to control led. It is not natural to use brightness to set patterns, that is why multiple led devices are created (one per indication);
- Update of one led may affect other leds, led triggers may not work as expected.
Changes from v1:
- Renamed "pattern" to indication.
- DSM support added.
- fixed nits reported by Bjorn.
Changes from v2:
- Introduce lazy loading to allow DELL _DSM quirks to work, reported by Stuart.
- leds class initcall moved up in Makefile, proposed by Dan.
- fix other nits reported by Dan and Iipo.
Changes from v3:
- Remove unnecessary packed attr.
- Fix doc issue reported by lkp.
- Fix read_poll_timeout() error handling reported by Iipo.
- Minor fixes reported by Christoph.
Changes from v4:
- Use 0 / 1 instead of LED_OFF/LED_ON, suggested by Marek.
- Documentation added, suggested by Bjorn.
Mariusz Tkaczyk (3):
leds: Init leds class earlier
PCI/NPEM: Add Native PCIe Enclosure Management support PCI/NPEM: Add _DSM PCIe SSD status LED management
Documentation/ABI/testing/sysfs-bus-pci | 72 +++ drivers/Makefile | 4 +- drivers/pci/Kconfig | 9 + drivers/pci/Makefile | 1 + drivers/pci/npem.c | 590 ++++++++++++++++++++++++ drivers/pci/pci.h | 8 + drivers/pci/probe.c | 2 + drivers/pci/remove.c | 2 + include/linux/pci.h | 3 + include/uapi/linux/pci_regs.h | 35 ++ 10 files changed, 725 insertions(+), 1 deletion(-) create mode 100644 drivers/pci/npem.c
Signature · 1 line
2.35.3
PATCH v5 1/3 leds: Init leds class earlier
NPEM driver will require leds class, there is an init-order conflict. Make sure that LEDs initialization happens first and add comment.
--- drivers/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/Makefile +3 -1
@@ -17,6 +17,9 @@ obj-$(CONFIG_PINCTRL) += pinctrl/ obj-$(CONFIG_GPIOLIB) += gpio/ obj-y += pwm/ +# LEDs must come before PCI, it is needed by NPEM driver +obj-y += leds/ + obj-y += pci/ obj-$(CONFIG_PARISC) += parisc/
@@ -130,7 +133,6 @@ obj-$(CONFIG_CPU_IDLE) += cpuidle/ obj-y += mmc/ obj-y += ufs/ obj-$(CONFIG_MEMSTICK) += memstick/ -obj-y += leds/ obj-$(CONFIG_INFINIBAND) += infiniband/ obj-y += firmware/ obj-$(CONFIG_CRYPTO) += crypto/
Signature · 1 line
2.35.3
PATCH v5 2/3 PCI/NPEM: Add Native PCIe Enclosure Management support
In reply to Mariusz TkaczykNative PCIe Enclosure Management (NPEM, PCIe r6.1 sec 6.28) allows managing LED in storage enclosures. NPEM is indication oriented and it does not give direct access to LED. Although each of the indications *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). It is corresponding to 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. Parent PCIe device bdf is used to guarantee uniqueness across leds subsystem.
To enable/disable fail indication "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.
Driver is projected to be 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, assuming that mutex lock gives protection from concurrent updates. Driver is not registered if _DSM LED management is available.
NPEM is a PCIe extended capability so it should be registered in pcie_init_capabilities() but it is not possible due to LED dependency. Parent pci_device must be added earlier for led_classdev_register() to be successful. NPEM does not require configuration on kernel side, it is safe to register LED devices later.
--- Documentation/ABI/testing/sysfs-bus-pci | 63 ++++ drivers/pci/Kconfig | 9 + drivers/pci/Makefile | 1 + drivers/pci/npem.c | 449 ++++++++++++++++++++++++ drivers/pci/pci.h | 8 + drivers/pci/probe.c | 2 + drivers/pci/remove.c | 2 + include/linux/pci.h | 3 + include/uapi/linux/pci_regs.h | 35 ++ 9 files changed, 572 insertions(+) create mode 100644 drivers/pci/npem.c
Documentation/ABI/testing/sysfs-bus-pci +63 -0
@@ -500,3 +500,66 @@ Description: console drivers from the device. Raw users of pci-sysfs resourceN attributes must be terminated prior to resizing. Success of the resizing operation is not guaranteed. + +What: /sys/bus/pci/devices/.../leds/*:enclosure:*/brightness +What: /sys/class/leds/*:enclosure:*/brightness +Date: August 2024 +KernelVersion: 6.12 +Description: + LED indications on PCIe storage enclosures which are controlled + through the NPEM interface (Native PCIe Enclosure Management, + PCIe r6.1 sec 6.28) are accessible as led class devices, both + below /sys/class/leds and below NPEM-capable PCI devices. + + Although these led class devices could be manipulated manually, + in practice they are typically manipulated automatically by an + application such as ledmon(8). + + The name of a led class device is as follows: + <bdf>:enclosure:<indication> + where: + + - <bdf> is the domain, bus, device and function number + (e.g. 10000:02:05.0) + - <indication> is a short description of the LED indication + + Valid indications per PCIe r6.1 table 6-27 are: + + - ok (drive is functioning normally) + - locate (drive is being identified by an admin) + - fail (drive is not functioning properly) + - rebuild (drive is part of an array that is rebuilding) + - pfa (drive is predicted to fail soon) + - hotspare (drive is marked to be used as a replacement) + - ica (drive is part of an array that is degraded) + - ifa (drive is part of an array that is failed) + - idt (drive is not the right type for the connector) + - disabled (drive is disabled, removal is safe) + - specific0 to specific7 (enclosure-specific indications) + + Broadly, the indications fall into one of these categories: + + - to signify drive state (ok, locate, fail, idt, disabled) + - to signify drive role or state in a software RAID array + (rebuild, pfa, hotspare, ica, ifa) + - to signify any other role or state (specific0 to specific7) + + Mandatory indications per PCIe r6.1 sec 7.9.19.2 comprise: + ok, locate, fail, rebuild. All others are optional. + A led class device is only visible if the corresponding + indication is supported by the device. + + To manipulate the indications, write 0 (LED_OFF) or 1 (LED_ON) + to the "brightness" file. Note that manipulating an indication + may implicitly manipulate other indications at the vendor's + discretion. E.g. when the user lights up the "ok" indication, + the vendor may choose to automatically turn off the "fail" + indication. The current state of an indication can be + retrieved by reading its "brightness" file. + + The PCIe Base Specification allows vendors leeway to choose + different colors or blinking patterns for the indications, + but they typically follow the IBPI standard. E.g. the "locate" + indication is usually presented as one or two LEDs blinking at + 4 Hz frequency: + https://en.wikipedia.org/wiki/International_Blinking_Pattern_Interpretation
drivers/pci/Kconfig +9 -0
@@ -143,6 +143,15 @@ config PCI_IOV If unsure, say N. +config PCI_NPEM + bool "Native PCIe Enclosure Management" + depends on LEDS_CLASS=y + help + Support for Native PCIe Enclosure Management. It allows managing LED + indications in storage enclosures. Enclosure must support following + indications: OK, Locate, Fail, Rebuild, other indications are + optional. + config PCI_PRI bool "PCI PRI support" select PCI_ATS
drivers/pci/Makefile +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o obj-$(CONFIG_VGA_ARB) += vgaarb.o obj-$(CONFIG_PCI_DOE) += doe.o obj-$(CONFIG_PCI_DYNAMIC_OF_NODES) += of_property.o +obj-$(CONFIG_PCI_NPEM) += npem.o # Endpoint library must be initialized before its users obj-$(CONFIG_PCI_ENDPOINT) += endpoint/
drivers/pci/npem.c new file +449 -0
449 lines not on this page · raw message
drivers/pci/pci.h +8 -0
@@ -398,6 +398,14 @@ static inline void pci_doe_destroy(struct pci_dev *pdev) { }static inline void pci_doe_disconnected (struct pci_dev *pdev) { }#endif +#ifdef CONFIG_PCI_NPEM +void pci_npem_create (struct pci_dev *dev); +void pci_npem_remove (struct pci_dev *dev); +#else +static inline void pci_npem_create (struct pci_dev *dev) { } +static inline void pci_npem_remove (struct pci_dev *dev) { } +#endif +/** * pci_dev_set_io_state - Set the new error state if possible. *
drivers/pci/probe.c +2 -0
@@ -2593,6 +2593,8 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) dev->match_driver = false; ret =device_add (&dev->dev);WARN_ON (ret <0 ); + +pci_npem_create (dev); }struct pci_dev *pci_scan_single_device (struct pci_bus *bus,int devfn)
drivers/pci/remove.c +2 -0
@@ -34,6 +34,8 @@ static void pci_destroy_dev(struct pci_dev *dev)if (!dev->dev.kobj.parent)return ; +pci_npem_remove (dev); +device_del (&dev->dev);down_write (&pci_bus_sem);
include/linux/pci.h +3 -0
@@ -516,6 +516,9 @@ struct pci_dev {#endif #ifdef CONFIG_PCI_DOE struct xarray doe_mbs;/* Data Object Exchange mailboxes */ +#endif +#ifdef CONFIG_PCI_NPEM +struct npem *npem;/* Native PCIe Enclosure Management */ #endif u16 acs_cap;/* ACS Capability offset */ phys_addr_t rom;/* Physical address if not from BAR */
include/uapi/linux/pci_regs.h +35 -0
@@ -740,6 +740,7 @@#define PCI_EXT_CAP_ID_DVSEC 0x23/* Designated Vendor-Specific */ #define PCI_EXT_CAP_ID_DLF 0x25/* Data Link Feature */ #define PCI_EXT_CAP_ID_PL_16GT 0x26/* Physical Layer 16.0 GT/s */ +#define PCI_EXT_CAP_ID_NPEM 0x29/* Native PCIe Enclosure Management */ #define PCI_EXT_CAP_ID_PL_32GT 0x2A/* Physical Layer 32.0 GT/s */ #define PCI_EXT_CAP_ID_DOE 0x2E/* Data Object Exchange */ #define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_DOE
@@ -1121,6 +1122,40 @@#define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK 0x000000F0#define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT 4 +/* Native PCIe Enclosure Management */ +#define PCI_NPEM_CAP 0x04/* NPEM capability register */ +#define PCI_NPEM_CAP_CAPABLE 0x00000001/* NPEM Capable */ + +#define PCI_NPEM_CTRL 0x08/* NPEM control register */ +#define PCI_NPEM_CTRL_ENABLE 0x00000001/* NPEM Enable */ + +/* +* Native PCIe Enclosure Management indication bits and Reset command bit +* are corresponding for capability and control registers. +*/ +#define PCI_NPEM_CMD_RESET 0x00000002/* NPEM Reset Command */ +#define PCI_NPEM_IND_OK 0x00000004/* NPEM indication OK */ +#define PCI_NPEM_IND_LOCATE 0x00000008/* NPEM indication Locate */ +#define PCI_NPEM_IND_FAIL 0x00000010/* NPEM indication Fail */ +#define PCI_NPEM_IND_REBUILD 0x00000020/* NPEM indication Rebuild */ +#define PCI_NPEM_IND_PFA 0x00000040/* NPEM indication Predicted Failure Analysis */ +#define PCI_NPEM_IND_HOTSPARE 0x00000080/* NPEM indication Hot Spare */ +#define PCI_NPEM_IND_ICA 0x00000100/* NPEM indication In Critical Array */ +#define PCI_NPEM_IND_IFA 0x00000200/* NPEM indication In Failed Array */ +#define PCI_NPEM_IND_IDT 0x00000400/* NPEM indication Invalid Device Type */ +#define PCI_NPEM_IND_DISABLED 0x00000800/* NPEM indication Disabled */ +#define PCI_NPEM_IND_SPEC_0 0x01000000 +#define PCI_NPEM_IND_SPEC_1 0x02000000 +#define PCI_NPEM_IND_SPEC_2 0x04000000 +#define PCI_NPEM_IND_SPEC_3 0x08000000 +#define PCI_NPEM_IND_SPEC_4 0x10000000 +#define PCI_NPEM_IND_SPEC_5 0x20000000 +#define PCI_NPEM_IND_SPEC_6 0x40000000 +#define PCI_NPEM_IND_SPEC_7 0x80000000 + +#define PCI_NPEM_STATUS 0x0c/* NPEM status register */ +#define PCI_NPEM_STATUS_CC 0x00000001/* NPEM Command completed */ +/* Data Object Exchange */ #define PCI_DOE_CAP 0x04/* DOE Capabilities Register */ #define PCI_DOE_CAP_INT_SUP 0x00000001/* Interrupt Support */
Signature · 1 line
2.35.3
Re: [PATCH v5 2/3] PCI/NPEM: Add Native PCIe Enclosure Management support
Quoted 5 lines · Mariusz Tkaczyk
drivers/pci/Kconfig +0
-0
drivers/pci/Kconfig config PCI_IOV · line 152
Quoted 10 lines
drivers/pci/Kconfig +7
-0@@ -143,6 +143,15 @@ config PCI_IOV If unsure, say N. +config PCI_NPEM + bool "Native PCIe Enclosure Management" + depends on LEDS_CLASS=y + help + Support for Native PCIe Enclosure Management. It allows managing LED + indications in storage enclosures. Enclosure must support following + indications: OK, Locate, Fail, Rebuild, other indications are
Rebuild. Other
Quoted 1 line
drivers/pci/Kconfig +1
-0+ optional.
Signature · 1 line
~Randy
Re: [PATCH v5 2/3] PCI/NPEM: Add Native PCIe Enclosure Management support
In reply to Mariusz TkaczykQuoted 8 lines
Documentation/ABI/testing/sysfs-bus-pci +0
-0@@ -500,3 +500,66 @@ Description: console drivers from the device. Raw users of pci-sysfs resourceN attributes must be terminated prior to resizing.
Documentation/ABI/testing/sysfs-bus-pci Description: · line 511
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-pci +9
-0Success of the resizing operation is not guaranteed. + +What: /sys/bus/pci/devices/.../leds/*:enclosure:*/brightness +What: /sys/class/leds/*:enclosure:*/brightness +Date: August 2024 +KernelVersion: 6.12 +Description: + LED indications on PCIe storage enclosures which are controlled + through the NPEM interface (Native PCIe Enclosure Management, + PCIe r6.1 sec 6.28) are accessible as led class devices, both
s/led/LED/ preferably.
Documentation/ABI/testing/sysfs-bus-pci Description: · line 514
Quoted 3 lines
Documentation/ABI/testing/sysfs-bus-pci +3
-0+ below /sys/class/leds and below NPEM-capable PCI devices. + + Although these led class devices could be manipulated manually,
ditto
Documentation/ABI/testing/sysfs-bus-pci Description: · line 518
Quoted 4 lines
Documentation/ABI/testing/sysfs-bus-pci +4
-0+ in practice they are typically manipulated automatically by an + application such as ledmon(8). + + The name of a led class device is as follows:
an LED
Quoted 21 lines
Documentation/ABI/testing/sysfs-bus-pci +21
-0+ <bdf>:enclosure:<indication> + where: + + - <bdf> is the domain, bus, device and function number + (e.g. 10000:02:05.0) + - <indication> is a short description of the LED indication + + Valid indications per PCIe r6.1 table 6-27 are: + + - ok (drive is functioning normally) + - locate (drive is being identified by an admin) + - fail (drive is not functioning properly) + - rebuild (drive is part of an array that is rebuilding) + - pfa (drive is predicted to fail soon) + - hotspare (drive is marked to be used as a replacement) + - ica (drive is part of an array that is degraded) + - ifa (drive is part of an array that is failed) + - idt (drive is not the right type for the connector) + - disabled (drive is disabled, removal is safe) + - specific0 to specific7 (enclosure-specific indications) +
Documentation/ABI/testing/sysfs-bus-pci Description: · line 549
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-pci +10
-0+ Broadly, the indications fall into one of these categories: + + - to signify drive state (ok, locate, fail, idt, disabled) + - to signify drive role or state in a software RAID array + (rebuild, pfa, hotspare, ica, ifa) + - to signify any other role or state (specific0 to specific7) + + Mandatory indications per PCIe r6.1 sec 7.9.19.2 comprise: + ok, locate, fail, rebuild. All others are optional. + A led class device is only visible if the corresponding
An LED
Quoted 16 lines
Documentation/ABI/testing/sysfs-bus-pci +16
-0+ indication is supported by the device. + + To manipulate the indications, write 0 (LED_OFF) or 1 (LED_ON) + to the "brightness" file. Note that manipulating an indication + may implicitly manipulate other indications at the vendor's + discretion. E.g. when the user lights up the "ok" indication, + the vendor may choose to automatically turn off the "fail" + indication. The current state of an indication can be + retrieved by reading its "brightness" file. + + The PCIe Base Specification allows vendors leeway to choose + different colors or blinking patterns for the indications, + but they typically follow the IBPI standard. E.g. the "locate" + indication is usually presented as one or two LEDs blinking at + 4 Hz frequency: + https://en.wikipedia.org/wiki/International_Blinking_Pattern_Interpretation
Signature · 1 line
~Randy
PATCH v5 3/3 PCI/NPEM: Add _DSM PCIe SSD status LED management
In reply to Mariusz TkaczykDevice Specific Method PCIe SSD Status LED Management (_DSM) defined in PCI Firmware Spec r3.3 sec 4.7 provides a way to manage LEDs via ACPI.
The design is similar to NPEM defined in PCIe Base Specification r6.1 sec 6.28:
- both standards are indication oriented,
- _DSM supported bits are corresponding to NPEM capability register bits
- _DSM control bits are corresponding to NPEM control register bits.
_DSM does not support enclosure specific indications and special NPEM commands NPEM_ENABLE and NPEM_RESET.
_DSM is implemented as a second op in NPEM driver. The standard used in background is not presented to user. The interface is accessed same as NPEM.
According to spec, _DSM has higher priority and availability of _DSM in not limited to devices with NPEM support. It is followed in implementation.
--- Documentation/ABI/testing/sysfs-bus-pci | 9 ++ drivers/pci/npem.c | 147 +++++++++++++++++++++++- 2 files changed, 153 insertions(+), 3 deletions(-)
Documentation/ABI/testing/sysfs-bus-pci +9 -0
@@ -563,3 +563,12 @@ Description: indication is usually presented as one or two LEDs blinking at 4 Hz frequency: https://en.wikipedia.org/wiki/International_Blinking_Pattern_Interpretation + + PCI Firmware Specification r3.3 sec 4.7 defines a DSM interface + to facilitate shared access by operating system and platform + firmware to a device's NPEM registers. The kernel will use + this DSM interface where available, instead of accessing NPEM + registers directly. The DSM interface does not support the + enclosure-specific indications "specific0" to "specific7", + hence the corresponding led class devices are unavailable if + the DSM interface is used.
drivers/pci/npem.c +144 -3
173 lines not on this page · raw message
Signature · 1 line
2.35.3
Re: [PATCH v5 3/3] PCI/NPEM: Add _DSM PCIe SSD status LED management
Still looks good to me (despite the still pointless __packed):
Re: [PATCH v5 3/3] PCI/NPEM: Add _DSM PCIe SSD status LED management
In reply to Mariusz TkaczykQuoted 6 lines · Mariusz Tkaczyk
Documentation/ABI/testing/sysfs-bus-pci +0
-0@@ -563,3 +563,12 @@ Description: indication is usually presented as one or two LEDs blinking at
Documentation/ABI/testing/sysfs-bus-pci Description: · line 573
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-pci +8
-04 Hz frequency: https://en.wikipedia.org/wiki/International_Blinking_Pattern_Interpretation + + PCI Firmware Specification r3.3 sec 4.7 defines a DSM interface + to facilitate shared access by operating system and platform + firmware to a device's NPEM registers. The kernel will use + this DSM interface where available, instead of accessing NPEM + registers directly. The DSM interface does not support the + enclosure-specific indications "specific0" to "specific7", + hence the corresponding led class devices are unavailable if
s/led/LED/ please.
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-pci +1
-0+ the DSM interface is used.
Signature · 1 line
~Randy