Skip to contentSkip to conversation

PCI: Introduce Cray ClusterStor E1000 NVMe slot LED driver

PATCH Superseded Tony Hutter 3 participants 5 messages Sep 24, 2024 – Oct 30, 2025 PCI

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PCI: 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 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").

---
 MAINTAINERS                          |   5 +
 drivers/pci/hotplug/Kconfig          |  10 +
 drivers/pci/hotplug/Makefile         |   3 +
 drivers/pci/hotplug/pciehp.h         |   7 +
 drivers/pci/hotplug/pciehp_core.c    |  12 +
 drivers/pci/hotplug/pciehp_craye1k.c | 677 +++++++++++++++++++++++++++
 6 files changed, 714 insertions(+)
 create mode 100644 drivers/pci/hotplug/pciehp_craye1k.c
MAINTAINERS +5 -0
index 42d2d950877c..4e6edb323754 100644
@@ -5928,6 +5928,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
+
 CREATIVE SB0540
 M:	Bastien Nocera <[email protected]>
 L:	[email protected]
drivers/pci/hotplug/Kconfig +10 -0
index 1472aef0fb81..6cd664be6b66 100644
@@ -173,4 +173,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 ACPI_PCI_SLOT && 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 is it 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
index 240c99517d5e..b3cb75ff2db2 100644
@@ -65,6 +65,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
index 273dd8c66f4e..ea68ae041547 100644
@@ -198,6 +198,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 +12 -0
index ff458e692fed..9a7a7b320810 100644
@@ -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;
@@ -404,6 +411,11 @@ int __init pcie_hp_init(void)
 	pr_debug("pcie_port_service_register = %d\n", retval);
 	if (retval)
 		pr_debug("Failure to register service\n");
+#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 +677 -0

677 lines not on this page · raw message

Signature · 1 line
2.43.5
#1 lore raw
Quoted 6 lines · Tony Hutter

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.

I don't quite understand what the E1000 is and where this code runs. Since you have a DMI check for DMI_PRODUCT_NAME "VSSEP1EC", I assume E1000 is an attached storage controller, and this driver is part of an embedded OS running inside the E1000 itself, *not* on the system to which the E1000 is attached?

I guess this "attention" file is the one implemented by attention_write_file() at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/pci/hotplug/pci_hotplug_core.c?id=v6.11#n163,
right?

The existing implementations of set_attention_status() interpret the value written as:

0 = OFF
1 = ON
2 = blink (ampere, ibmphp, pciehp, rpaphp, shpchp) other values are no-op, OFF, or ON depending on the driver

I *think* this one is:

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 alias the above (interpreted as value & 0x3)

All this should have already been documented in Documentation/ABI/testing/sysfs-bus-pci along with the other similar attributes. I guess since we failed to document them in the past, this would be a good chance to do it.

Quoted 5 lines

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.

Quoted 8 lines

- 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").

The sysfs "attention" interface already exists, so I sort of see your point, although it can't work exactly the same with different enclosures because they only have a single LED that can be OFF, ON, or blinking. And of course, "attention" can't support all the additional indications NPEM and the _DSM support.

A few mostly superficial code comments below.

drivers/pci/hotplug/Kconfig config HOTPLUG_PCI_S390 · line 178

Quoted 3 lines
drivers/pci/hotplug/Kconfig +3 -0
+config HOTPLUG_PCI_PCIE_CRAY_E1000
+	bool "PCIe Hotplug extensions for Cray ClusterStor E1000"
+	depends on ACPI_PCI_SLOT && HOTPLUG_PCI_PCIE && IPMI_HANDLER=y

What's the ACPI_PCI_SLOT connection? I don't see the dependency.

drivers/pci/hotplug/Kconfig config HOTPLUG_PCI_S390 · line 182

Quoted 4 lines
drivers/pci/hotplug/Kconfig +4 -0
+	help
+	  Say Y here if you have a Cray ClusterStor E1000 and want to control
+	  your NVMe slot LEDs.  Without this driver is it not possible
+	  to control the fault and locate LEDs on the E1000's 24 NVMe slots.

If my guess about where this driver runs is correct, this is a little misleading. A user with a system that has an E1000 attached to it would read this and think the driver would be useful on the system to which the E1000 is attached. But IIUC, it's only relevant to the embedded processor *inside* the E1000.

drivers/pci/hotplug/pciehp_core.c static int init_slot(struct controller *ctrl) · line 82

Quoted 12 lines

+++ b/drivers/pci/hotplug/pciehp_core.c

drivers/pci/hotplug/pciehp_core.c +7 -0
@@ -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

I'm not really thrilled about dropping device-specific code in here, but I don't have a better suggestion yet.

Quoted 25 lines
(quoted diff) +20 -0
@@ -404,6 +411,11 @@ int __init pcie_hp_init(void)
 	pr_debug("pcie_port_service_register = %d\n", retval);
 	if (retval)
 		pr_debug("Failure to register service\n");
+#ifdef CONFIG_HOTPLUG_PCI_PCIE_CRAY_E1000
+	retval = craye1k_init();
+	if (retval)
+		pr_debug("Failure to register Cray E1000 extensions");
+#endif
 
+ * craye1k_do_message() - Send the message in 'craye1k' and wait for a response
+ *
+ * Context: craye1k->lock is already held.
+ * Return: 0 on success, non-zero on error.
+ */
+static int craye1k_do_message(struct craye1k *craye1k)
+{
+	int rc;
+	long rc2;
+	struct completion *read_complete = &craye1k->read_complete;
+	unsigned long tout = msecs_to_jiffies(craye1k->completion_timeout_ms);
+
+	rc = craye1k_send_message(craye1k);
+	if (rc == 0) {
+		rc2 = wait_for_completion_killable_timeout(read_complete, tout);

Review int __init pcie_hp_init(void)

Quoted 10 lines
(quoted diff) +10 -0
+		if (rc2 == 0) {
+			craye1k->completion_timeout++;
+			rc = -ETIME;
+		}
+	}
+
+	if (craye1k->rx_result == IPMI_UNKNOWN_ERR_COMPLETION_CODE || rc2 <= 0)
+		rc = -1;
+
+	return rc;

This doesn't make sense to me.

If craye1k_send_message() fails (returns non-zero), we test both craye1k->rx_result and rc2, which are uninitialized AFAICS.

If wait_for_completion_killable_timeout() returns "rc2 <= 0" (timeout or interrupted), it looks like we always return -1, so I don't know why we mention -ETIME in the middle.

And it doesn't look safe to test craye1k->rx_result because it's only valid if craye1k_msg_handler() has called complete(&craye1k->read_complete).

I think this might be easier to read as below. I don't *guarantee* that it's equivalent, but it seems like it on first glance:

  rc = craye1k_send_message(craye1k);
  if (rc)
    return rc;

rc2 = wait_for_completion_killable_timeout(read_complete, tout); if (rc2 > 0)
return 0; /* normal path, got response before timeout */

if (rc2 == 0)

    craye1k->completion_timeout++;

return -1; /* timed out or interrupted */

Quoted 15 lines

+ * __craye1k_do_command() - Do an IPMI command
+ *
+ * Send a command with optional data bytes, and read back response bytes.
+ * Context: craye1k->lock is already held.
+ * Returns: 0 on success, non-zero on error.
+ */

drivers/pci/hotplug/pciehp_craye1k.c new file +9 -0
+static int __craye1k_do_command(struct craye1k *craye1k, u8 netfn, u8 cmd,
+				u8 *send_data, u8 send_data_len, u8 *recv_data,
+				u8 recv_data_len)
+{
+	int rc;
+
+	craye1k->tx_msg.netfn = netfn;
+	craye1k->tx_msg.cmd = cmd;
+

drivers/pci/hotplug/pciehp_craye1k.c line 341

Quoted 10 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +10 -0
+	if (send_data) {
+		memcpy(&craye1k->tx_msg_data[0], send_data, send_data_len);
+		craye1k->tx_msg.data_len = send_data_len;
+	} else {
+		craye1k->tx_msg_data[0] = 0;
+		craye1k->tx_msg.data_len = 0;
+	}
+
+	rc = craye1k_do_message(craye1k);
+	memcpy(recv_data, craye1k->rx_msg_data, recv_data_len);

Seems wrong to copy into recv_data if this failed?

Looks like craye1k_do_command_and_netfn() is the only caller, and it supplies recv_data == NULL and recv_data_len = 0, so why do they exist?

drivers/pci/hotplug/pciehp_craye1k.c line 389

Quoted 5 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +5 -0
+static int craye1k_do_command(struct craye1k *craye1k, u8 cmd, u8 *send_data,
+			      u8 send_data_len)
+{
+	return (craye1k_do_command_and_netfn(craye1k, CRAYE1K_CMD_NETFN, cmd,
+					     send_data, send_data_len));

Unnecessary outer parens.

Quoted 4 lines

+ * craye1k_is_primary() - Are we the primary server?
+ *
+ * Returns: 1 if we are the primary server, 0 otherwise.
+ */

drivers/pci/hotplug/pciehp_craye1k.c line 423

Quoted 10 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +10 -0
+static int craye1k_is_primary(struct craye1k *craye1k)
+{
+	u8 byte = 0;
+	int rc;
+
+	/* Response byte is 0x1 on success */
+	rc = craye1k_do_command(craye1k, CRAYE1K_CMD_PRIMARY, &byte, 1);
+	craye1k->check_primary++;
+	if (rc == 0x1)
+		return 1;   /* success */

This isn't actually *success*, it's more like "true"; this function just answers a yes/no question and could return boolean.

If there's a possibility of failure, i.e., if "we can't tell whether we're primary" is a possible outcome, there would have to be three possible return values.

drivers/pci/hotplug/pciehp_craye1k.c line 432

Quoted 8 lines
drivers/pci/hotplug/pciehp_craye1k.c new file +8 -0
+	craye1k->check_primary_failed++;
+	return 0;   /* We are not the primary server node */
+}
+
+/*
+ * craye1k_set_primary() - Attempt to set ourselves as the primary server
+ *
+ * Returns: 0 on success, 1 otherwise.

Why 1 for failure here, <0 for failure elsewhere? Negative -ERRNO return value for failure is the usual convention.

Bjorn

#2 lore raw
Quoted 5 lines

I don't quite understand what the E1000 is and where this code runs. Since you have a DMI check for DMI_PRODUCT_NAME "VSSEP1EC", I assume E1000 is an attached storage controller, and this driver is part of an embedded OS running inside the E1000 itself, *not* on the system to which the E1000 is attached?

You can think of an E1000 as a standard rack mount storage server with 24 NVMe slots. They are often used as Lustre servers. The DMI check makes sure the E1000 LED driver can only be loaded on E1000 boards. The driver is running on the main system (where Lustre runs) rather than a embedded storage controller. The driver does communicate with a embedded controller via IPMI to control the LEDs though.

I'm currently on baby bonding leave, but I'll try to implement your review comments into a version 3 patch once I get back into the office.

-Tony

#3 lore raw
Quoted 14 lines · Tony Hutter
Quoted 5 lines

I don't quite understand what the E1000 is and where this code runs. Since you have a DMI check for DMI_PRODUCT_NAME "VSSEP1EC", I assume E1000 is an attached storage controller, and this driver is part of an embedded OS running inside the E1000 itself, *not* on the system to which the E1000 is attached?

You can think of an E1000 as a standard rack mount storage server with 24 NVMe slots. They are often used as Lustre servers. The DMI check makes sure the E1000 LED driver can only be loaded on E1000 boards. The driver is running on the main system (where Lustre runs) rather than a embedded storage controller. The driver does communicate with a embedded controller via IPMI to control the LEDs though.

Quoted 3 lines

I'm currently on baby bonding leave, but I'll try to implement your review comments into a version 3 patch once I get back into the office.

Congratulations! Hope your family is all doing well!

Bjorn

#4 lore raw
In reply to Bjorn Helgaas
Quoted 16 lines · Bjorn Helgaas

drivers/pci/hotplug/pciehp_core.c static int init_slot(struct controller *ctrl) · line 82

Quoted 12 lines · Tony Hutter

+++ b/drivers/pci/hotplug/pciehp_core.c

drivers/pci/hotplug/pciehp_core.c +7 -0
@@ -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

I'm not really thrilled about dropping device-specific code in here, but I don't have a better suggestion yet.

For acpiphp, we have an elaborate mechanism to register attention LED drivers via acpiphp_register_attention() / acpiphp_unregister_attention().

So far it's only used by two drivers (acpiphp_ampere_altra.c and acpiphp_ibm.c).

For pciehp we have one custom attention LED mechanism for VMD (enabled through pci_dev->hotplug_user_indicators) and now this Cray E1000 mechanism.

Personally I'm fine with keeping this lightweight and not add a similar register/unregister mechanism as we did for acpiphp.

However I think it might make sense to drop the hotplug_user_indicators flag and instead invoke the is_vmd() check directly from init_slot() to make it more explicit what this is about and to allow the code to be optimized away on non-x86.

Thanks,

Lukas