Introduce Cray ClusterStor E1000 NVMe slot LED driver
PATCH v6 1/1 Introduce Cray ClusterStor E1000 NVMe slot LED driver
Add driver to control the NVMe slot LEDs on the Cray ClusterStor E1000. The driver provides hotplug attention status callbacks for the 24 NVMe slots on the E1000. This allows users to access the E1000's locate and fault LEDs via the normal /sys/bus/pci/slots/<slot>/attention sysfs entries. This driver uses IPMI to communicate with the E1000 controller to toggle the LEDs.
---
Changes in v6:
- Change some dev_info_ratelimited() calls to dev_info().
- Don't call craye1k_init() if pcie_port_service_register() fails.
- Fix stray indent in #define CRAYE1K_POST_CMD_WAIT_MS
Changes in v5:
- Removed unnecessary ipmi_smi.h #include.
- Added WARN_ON() to craye1k_do_message() to sanity check that craye1k->lock is held.
- Added additional comments for when craye1k->lock should be held.
Changes in v4:
- Fix typo in Kconfig: "is it" -> "it is"
- Rename some #defines to CRAYE1K_SUBCMD_*
- Use IS_ERR() check in craye1k_debugfs_init()
- Return -EIO instead of -EINVAL when LED value check fails
Changes in v3:
- Add 'attention' values in Documentation/ABI/testing/sysfs-bus-pci.
- Remove ACPI_PCI_SLOT dependency.
- Cleanup craye1k_do_message() error checking.
- Skip unneeded memcpy() on failure in __craye1k_do_command().
- Merge craye1k_do_command_and_netfn() code into craye1k_do_command().
- Make craye1k_is_primary() return boolean.
- Return negative error code on failure in craye1k_set_primary().
Changes in v2:
- Integrated E1000 code into the pciehp driver as an built-in extention rather than as a standalone module.
- Moved debug tunables and counters to debugfs.
- Removed forward declarations.
- Kept the /sys/bus/pci/slots/<slot>/attention interface rather than using NPEM/_DSM or led_classdev as suggested. The "attention" interface is more beneficial for our site, since it allows us to control the NVMe slot LEDs agnostically across different enclosure vendors and kernel versions using the same scripts. It is also nice to use the same /sys/bus/pci/slots/<slot>/ sysfs directory for both slot LED toggling ("attention") and slot power control ("power").
--- Documentation/ABI/testing/sysfs-bus-pci | 21 + MAINTAINERS | 5 + drivers/pci/hotplug/Kconfig | 10 + drivers/pci/hotplug/Makefile | 3 + drivers/pci/hotplug/pciehp.h | 7 + drivers/pci/hotplug/pciehp_core.c | 17 +- drivers/pci/hotplug/pciehp_craye1k.c | 671 ++++++++++++++++++++++++ 7 files changed, 733 insertions(+), 1 deletion(-) create mode 100644 drivers/pci/hotplug/pciehp_craye1k.c
Documentation/ABI/testing/sysfs-bus-pci +21 -0
@@ -231,6 +231,27 @@ Description: - scXX contains the device subclass; - iXX contains the device class programming interface. +What: /sys/bus/pci/slots/.../attention +Date: February 2025 +Contact: [email protected] +Description: + The attention attribute is used to read or write the attention + status for an enclosure slot. This is often used to set the + slot LED value on a NVMe storage enclosure. + + Common values: + 0 = OFF + 1 = ON + 2 = blink (ampere, ibmphp, pciehp, rpaphp, shpchp) + + Using the pciehp_craye1k extensions: + 0 = fault LED OFF, locate LED OFF + 1 = fault LED ON, locate LED OFF + 2 = fault LED OFF, locate LED ON + 3 = fault LED ON, locate LED ON + + Other values are no-op, OFF, or ON depending on the driver. + What: /sys/bus/pci/slots/.../module Date: June 2009 Contact: [email protected]
MAINTAINERS +5 -0
@@ -6531,6 +6531,11 @@ S: Maintained F: Documentation/filesystems/cramfs.rst F: fs/cramfs/ +CRAY CLUSTERSTOR E1000 NVME SLOT LED DRIVER EXTENSIONS +M: Tony Hutter <[email protected]> +S: Maintained +F: drivers/pci/hotplug/pciehp_craye1k.c + CRC LIBRARY M: Eric Biggers <[email protected]> R: Ard Biesheuvel <[email protected]>
drivers/pci/hotplug/Kconfig +10 -0
@@ -183,4 +183,14 @@ config HOTPLUG_PCI_S390 When in doubt, say Y. +config HOTPLUG_PCI_PCIE_CRAY_E1000 + bool "PCIe Hotplug extensions for Cray ClusterStor E1000" + depends on HOTPLUG_PCI_PCIE && IPMI_HANDLER=y + help + Say Y here if you have a Cray ClusterStor E1000 and want to control + your NVMe slot LEDs. Without this driver it is not possible + to control the fault and locate LEDs on the E1000's 24 NVMe slots. + + When in doubt, say N. + endif # HOTPLUG_PCI
drivers/pci/hotplug/Makefile +3 -0
@@ -66,6 +66,9 @@ pciehp-objs := pciehp_core.o \ pciehp_ctrl.o \ pciehp_pci.o \ pciehp_hpc.o +ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 +pciehp-objs += pciehp_craye1k.o +endif shpchp-objs := shpchp_core.o \ shpchp_ctrl.o \
drivers/pci/hotplug/pciehp.h +7 -0
@@ -199,6 +199,13 @@ int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status);int pciehp_slot_reset (struct pcie_device *dev); +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 +int craye1k_get_attention_status (struct hotplug_slot *hotplug_slot,u8 *status); +int craye1k_set_attention_status (struct hotplug_slot *hotplug_slot,u8 status); +bool is_craye1k_slot (struct controller *ctrl); +int craye1k_init (void ); +#endif +static inline const char *slot_name (struct controller *ctrl) {return hotplug_slot_name (&ctrl->hotplug_slot);
drivers/pci/hotplug/pciehp_core.c +16 -1
@@ -73,6 +73,13 @@ static int init_slot(struct controller *ctrl) ops->get_attention_status = pciehp_get_raw_indicator_status; ops->set_attention_status = pciehp_set_raw_indicator_status; } +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 +if (is_craye1k_slot (ctrl)) { +/* slots 1-24 on Cray E1000s are controlled differently */ + ops->get_attention_status = craye1k_get_attention_status; + ops->set_attention_status = craye1k_set_attention_status; + } +#endif /* register this slot with the hotplug pci core */ ctrl->hotplug_slot.ops = ops;
@@ -376,8 +383,16 @@ int __init pcie_hp_init(void) retval =pcie_port_service_register (&hpdriver_portdrv);pr_debug ("pcie_port_service_register = %d\n" , retval); -if (retval) +if (retval) {pr_debug ("Failure to register service\n" ); +return retval; + } + +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 + retval =craye1k_init (); +if (retval) +pr_debug ("Failure to register Cray E1000 extensions" ); +#endif return retval; }
drivers/pci/hotplug/pciehp_craye1k.c new file +671 -0
671 lines not on this page · raw message
Signature · 1 line
2.43.7
Documentation/ABI/testing/sysfs-bus-pci Description: · line 235
Quoted 7 lines · Tony Hutter
+++ b/Documentation/ABI/testing/sysfs-bus-pci
Documentation/ABI/testing/sysfs-bus-pci +2
-0@@ -231,6 +231,27 @@ Description: - scXX contains the device subclass; - iXX contains the device class programming interface. +What: /sys/bus/pci/slots/.../attention +Date: February 2025
Please update the "Date" timestamp to the month of submission to the list.
Quoted 6 lines
Documentation/ABI/testing/sysfs-bus-pci +6
-0+Contact: [email protected] +Description: + The attention attribute is used to read or write the attention + status for an enclosure slot. This is often used to set the + slot LED value on a NVMe storage enclosure. +
Documentation/ABI/testing/sysfs-bus-pci Description: · line 251
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-pci +10
-0+ Common values: + 0 = OFF + 1 = ON + 2 = blink (ampere, ibmphp, pciehp, rpaphp, shpchp) + + Using the pciehp_craye1k extensions: + 0 = fault LED OFF, locate LED OFF + 1 = fault LED ON, locate LED OFF + 2 = fault LED OFF, locate LED ON + 3 = fault LED ON, locate LED ON
An end user might not be able to understand all these driver names, so I'd omit "(ampere, ibmphp, pciehp, rpaphp, shpchp)", and replace "pciehp_craye1k" with "Cray ClusterStor E1000".
drivers/pci/hotplug/pciehp_core.c static int init_slot(struct controller *ctrl) · line 82
Quoted 12 lines
drivers/pci/hotplug/pciehp_core.c +8
-0+++ b/drivers/pci/hotplug/pciehp_core.c@@ -73,6 +73,13 @@ static int init_slot(struct controller *ctrl) ops->get_attention_status = pciehp_get_raw_indicator_status; ops->set_attention_status = pciehp_set_raw_indicator_status; } +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 +if (is_craye1k_slot (ctrl)) { +/* slots 1-24 on Cray E1000s are controlled differently */ + ops->get_attention_status = craye1k_get_attention_status; + ops->set_attention_status = craye1k_set_attention_status; + } +#endif
Per section 21 of Documentation/process/coding-style.rst, please avoid the use of #ifdef and instead add an #else section to pciehp.h with an inline stub for is_craye1k_slot() which returns false and #define craye1k_{get,set}_attention_status to NULL.
Do these hotplug slots on the Cray E1000 have the Attention Indicator Present bit set in the Slot Capabilities register? If they do not, please use "if else" instead of "if". Right now you're overwriting the default {get,set}_attention_status pointers, which only makes sense if ATTN_LED(ctrl) is true.
When is craye1k_new_smi() called? Is it guaranteed to be called before the first invocation of craye1k_{get,set}_attention_status()?
I'm asking because craye1k_{get,set}_attention_status() do not contain any checks whether the craye1k_global struct has been populated. You would need such checks if craye1k_new_smi() may run later than the "attention" attribute appearing in sysfs.
Actually craye1k_new_smi() may fail, e.g. because of kzalloc() returning NULL, so I think you'll need additional checks in any case. However if craye1k_new_smi() is guaranteed to run before init_slot(), you could check for an uninitialized craye1k_global struct already in is_craye1k_slot().
Note that just checking "craye1k_global == NULL" is insufficient as craye1k_new_smi() might run concurrently to craye1k_{get,set}_attention_status().
I note that is_craye1k_slot() calls dmi_match(), so you should add "depends on DMI" to the Kconfig entry you're adding.
Quoted 5 lines
drivers/pci/hotplug/pciehp_core.c +0
-1@@ -376,8 +383,16 @@ int __init pcie_hp_init(void) retval =pcie_port_service_register (&hpdriver_portdrv);pr_debug ("pcie_port_service_register = %d\n" , retval); -if (retval)
drivers/pci/hotplug/pciehp_core.c int __init pcie_hp_init(void) · line 395
Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +9
-0+if (retval) {pr_debug ("Failure to register service\n" ); +return retval; + } + +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 + retval =craye1k_init (); +if (retval) +pr_debug ("Failure to register Cray E1000 extensions" ); +#endif
Another #ifdef that should be eliminated.
You also need to annotate craye1k_init() with __init.
Quoted 1 line
(quoted diff) +1
-0+++ b/drivers/pci/hotplug/pciehp_craye1k.c
[...]
drivers/pci/hotplug/pciehp_craye1k.c line 27
Quoted 10 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +10
-0+#include <linux/debugfs.h> +#include <linux/delay.h> +#include <linux/errno.h> +#include <linux/dmi.h> +#include <linux/ipmi.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/pci_hotplug.h> +#include <linux/random.h> +#include "pciehp.h"
dmi.h isn't inserted in alphabetical order.
Quoted 6 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +6
-0+/* debugfs stats */ +u64 check_primary; +u64 check_primary_failed; +u64 was_already_primary; +u64 was_not_already_primary; +u64 set_primary;
drivers/pci/hotplug/pciehp_craye1k.c line 79
Quoted 10 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +10
-0+u64 set_initial_primary_failed; +u64 set_primary_failed; +u64 set_led_locate_failed; +u64 set_led_fault_failed; +u64 set_led_readback_failed; +u64 set_led_failed; +u64 get_led_failed; +u64 completion_timeout; +u64 wrong_msgid; +u64 request_failed;
I'm wondering if having all this debug code in mainline is useful? Is the IPMI interface this brittle? Was this just necessary for initial development and may not be useful going forward?
drivers/pci/hotplug/pciehp_craye1k.c line 168
Quoted 10 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +10
-0+static void craye1k_msg_handler (struct ipmi_recv_msg *msg,void *user_msg_data) +{ +struct craye1k *craye1k = user_msg_data; + +if (msg->msgid != craye1k->tx_msg_id) { + craye1k->wrong_msgid++; +if (craye1k->print_errors) { +dev_warn_ratelimited (craye1k->dev,"rx msgid %d != %d" , + (int )msg->msgid, + (int )craye1k->tx_msg_id);
Why use casts instead of %ld in the format string?
drivers/pci/hotplug/pciehp_craye1k.c line 246
Quoted 4 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +4
-0+static void craye1k_smi_gone (int iface) +{ +pr_warn ("craye1k: Got unexpected smi_gone, iface=%d" , iface); +}
Why not kfree() the craye1k struct here, tear down debugfs etc?
Thanks,
Lukas
Quoted 18 lines · Lukas Wunner
Quoted 5 lines · Tony Hutter
drivers/pci/hotplug/pciehp_core.c +0
-1@@ -376,8 +383,16 @@ int __init pcie_hp_init(void) retval =pcie_port_service_register (&hpdriver_portdrv);pr_debug ("pcie_port_service_register = %d\n" , retval); -if (retval)drivers/pci/hotplug/pciehp_core.c int __init pcie_hp_init(void) · line 395
Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +9
-0+if (retval) {pr_debug ("Failure to register service\n" ); +return retval; + } + +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 + retval =craye1k_init (); +if (retval) +pr_debug ("Failure to register Cray E1000 extensions" ); +#endif You also need to annotate
craye1k_init()with__init.
Sorry, I've realized that I made the following note during review of your patch but forgot to include it in the reply above:
You may want to consider making this driver modular and auto-load it using a MODULE_DEVICE_TABLE(dmi, ...) declaration. craye1k_init() would then become the module_init() call and you could tear down everything in a module_exit() call. If you want to run craye1k_init() earlier if built-in, use e.g. an arch_initcall() instead of a module_init() call. There's precedent in the tree for combinations of arch_initcall() + module_exit().
Thanks,
Lukas
Quoted 2 lines
You may want to consider making this driver modular and auto-load it using a
MODULE_DEVICE_TABLE(dmi, ...)declaration.
Thanks for the suggestion. One of the issues of making it modular is that craye1k has a dependency on IPMI. So craye1k could get loaded first and create the /sys/bus/pci/slots/<slot>/attention files, but none of those files would be usable until IPMI loads. If you force it to be built-in, then you pretty much guarantee that if the 'attention' file exist, it's usable.
Quoted 34 lines · Lukas Wunner
Quoted 18 lines · Lukas Wunner
Quoted 5 lines · Tony Hutter
drivers/pci/hotplug/pciehp_core.c +0
-1@@ -376,8 +383,16 @@ int __init pcie_hp_init(void) retval =pcie_port_service_register (&hpdriver_portdrv);pr_debug ("pcie_port_service_register = %d\n" , retval); -if (retval)drivers/pci/hotplug/pciehp_core.c int __init pcie_hp_init(void) · line 395
Quoted 10 lines
drivers/pci/hotplug/pciehp_core.c +9
-0+if (retval) {pr_debug ("Failure to register service\n" ); +return retval; + } + +#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000 + retval =craye1k_init (); +if (retval) +pr_debug ("Failure to register Cray E1000 extensions" ); +#endif You also need to annotate
craye1k_init()with__init.Sorry, I've realized that I made the following note during review of your patch but forgot to include it in the reply above:
You may want to consider making this driver modular and auto-load it using a
MODULE_DEVICE_TABLE(dmi, ...)declaration.craye1k_init()would then become themodule_init()call and you could tear down everything in amodule_exit()call. If you want to runcraye1k_init()earlier if built-in, use e.g. anarch_initcall()instead of amodule_init()call. There's precedent in the tree for combinations ofarch_initcall()+module_exit().Thanks,
Lukas