Commit 759ec282 authored by Mariusz Tkaczyk's avatar Mariusz Tkaczyk Committed by Bjorn Helgaas

PCI/NPEM: Add _DSM PCIe SSD status LED management

The 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 correspond to NPEM capability register bits,

  - _DSM control bits correspond to NPEM control register bits.

_DSM does not support enclosure-specific indications or the special NPEM
commands NPEM_ENABLE and NPEM_RESET.

_DSM is implemented as a second backend in NPEM driver. The backend used is
logged with info priority. The same sysfs interface is used for both NPEM
and _DSM.

According to spec, _DSM has higher priority, and availability  of _DSM in
not limited to devices with NPEM support.

The Dell implementation of DSM uses acpi ipmi, which may not be available
immediately (in fact it may take up to 10s for this interface to be
available). It can determine if DSM is supported (GET_SUPPORTED_STATES_DSM
is working) but it cannot serve GET_STATE_DSM or SET_STATE_DSM commands in
this time.

From userspace application perspective (primarily configured by systemd
service) it is better to have not working but configured interface rather
than have it available after few seconds.

For that reason, npem->active_indications cache is now loaded lazily, i.e.
any GET or SET request want cache to be updated if it is not done yet.

Link: https://lore.kernel.org/r/20240904104848.23480-4-mariusz.tkaczyk@linux.intel.comSuggested-by: default avatarLukas Wunner <lukas@wunner.de>
Signed-off-by: default avatarStuart Hayes <stuart.w.hayes@gmail.com>
Signed-off-by: default avatarMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Tested-by: default avatarStuart Hayes <stuart.w.hayes@gmail.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent 4e893545
...@@ -563,3 +563,12 @@ Description: ...@@ -563,3 +563,12 @@ Description:
indication is usually presented as one or two LEDs blinking at indication is usually presented as one or two LEDs blinking at
4 Hz frequency: 4 Hz frequency:
https://en.wikipedia.org/wiki/International_Blinking_Pattern_Interpretation 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.
...@@ -10,6 +10,14 @@ ...@@ -10,6 +10,14 @@
* Native PCIe Enclosure Management (NPEM) * Native PCIe Enclosure Management (NPEM)
* PCIe Base Specification r6.1 sec 6.28, 7.9.19 * PCIe Base Specification r6.1 sec 6.28, 7.9.19
* *
* _DSM Definitions for PCIe SSD Status LED
* PCI Firmware Specification, r3.3 sec 4.7
*
* Two backends are supported to manipulate indications: Direct NPEM register
* access (npem_ops) and indirect access through the ACPI _DSM (dsm_ops).
* _DSM is used if supported, else NPEM.
*
* Copyright (c) 2021-2022 Dell Inc.
* Copyright (c) 2023-2024 Intel Corporation * Copyright (c) 2023-2024 Intel Corporation
* Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> * Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
*/ */
...@@ -54,6 +62,21 @@ static const struct indication npem_indications[] = { ...@@ -54,6 +62,21 @@ static const struct indication npem_indications[] = {
{0, NULL} {0, NULL}
}; };
/* _DSM PCIe SSD LED States correspond to NPEM register values */
static const struct indication dsm_indications[] = {
{PCI_NPEM_IND_OK, "enclosure:ok"},
{PCI_NPEM_IND_LOCATE, "enclosure:locate"},
{PCI_NPEM_IND_FAIL, "enclosure:fail"},
{PCI_NPEM_IND_REBUILD, "enclosure:rebuild"},
{PCI_NPEM_IND_PFA, "enclosure:pfa"},
{PCI_NPEM_IND_HOTSPARE, "enclosure:hotspare"},
{PCI_NPEM_IND_ICA, "enclosure:ica"},
{PCI_NPEM_IND_IFA, "enclosure:ifa"},
{PCI_NPEM_IND_IDT, "enclosure:idt"},
{PCI_NPEM_IND_DISABLED, "enclosure:disabled"},
{0, NULL}
};
#define for_each_indication(ind, inds) \ #define for_each_indication(ind, inds) \
for (ind = inds; ind->bit; ind++) for (ind = inds; ind->bit; ind++)
...@@ -123,6 +146,14 @@ struct npem_ops { ...@@ -123,6 +146,14 @@ struct npem_ops {
* @active_indications: cached bit mask of active indications; * @active_indications: cached bit mask of active indications;
* non-indication and reserved bits in the NPEM Control Register are * non-indication and reserved bits in the NPEM Control Register are
* cleared in this bit mask * cleared in this bit mask
* @active_inds_initialized: whether @active_indications has been initialized;
* On Dell platforms, it is required that IPMI drivers are loaded before
* the GET_STATE_DSM method is invoked: They use an IPMI OpRegion to
* get/set the active LEDs. By initializing @active_indications lazily
* (on first access to an LED), IPMI drivers are given a chance to load.
* If they are not loaded in time, users will see various errors on LED
* access in dmesg. Once they are loaded, the errors go away and LED
* access becomes possible.
* @led_cnt: size of @leds array * @led_cnt: size of @leds array
* @leds: array containing LED class devices of all supported LEDs * @leds: array containing LED class devices of all supported LEDs
*/ */
...@@ -133,6 +164,7 @@ struct npem { ...@@ -133,6 +164,7 @@ struct npem {
u16 pos; u16 pos;
u32 supported_indications; u32 supported_indications;
u32 active_indications; u32 active_indications;
unsigned int active_inds_initialized:1;
int led_cnt; int led_cnt;
struct npem_led leds[]; struct npem_led leds[];
}; };
...@@ -246,6 +278,139 @@ static bool npem_has_dsm(struct pci_dev *pdev) ...@@ -246,6 +278,139 @@ static bool npem_has_dsm(struct pci_dev *pdev)
BIT(GET_STATE_DSM) | BIT(SET_STATE_DSM)); BIT(GET_STATE_DSM) | BIT(SET_STATE_DSM));
} }
struct dsm_output {
u16 status;
u8 function_specific_err;
u8 vendor_specific_err;
u32 state;
};
/**
* dsm_evaluate() - send DSM PCIe SSD Status LED command
* @pdev: PCI device
* @dsm_func: DSM LED Function
* @output: buffer to copy DSM Response
* @value_to_set: value for SET_STATE_DSM function
*
* To not bother caller with ACPI context, the returned _DSM Output Buffer is
* copied.
*/
static int dsm_evaluate(struct pci_dev *pdev, u64 dsm_func,
struct dsm_output *output, u32 value_to_set)
{
acpi_handle handle = ACPI_HANDLE(&pdev->dev);
union acpi_object *out_obj, arg3[2];
union acpi_object *arg3_p = NULL;
if (dsm_func == SET_STATE_DSM) {
arg3[0].type = ACPI_TYPE_PACKAGE;
arg3[0].package.count = 1;
arg3[0].package.elements = &arg3[1];
arg3[1].type = ACPI_TYPE_BUFFER;
arg3[1].buffer.length = 4;
arg3[1].buffer.pointer = (u8 *)&value_to_set;
arg3_p = arg3;
}
out_obj = acpi_evaluate_dsm_typed(handle, &dsm_guid, 0x1, dsm_func,
arg3_p, ACPI_TYPE_BUFFER);
if (!out_obj)
return -EIO;
if (out_obj->buffer.length < sizeof(struct dsm_output)) {
ACPI_FREE(out_obj);
return -EIO;
}
memcpy(output, out_obj->buffer.pointer, sizeof(struct dsm_output));
ACPI_FREE(out_obj);
return 0;
}
static int dsm_get(struct pci_dev *pdev, u64 dsm_func, u32 *buf)
{
struct dsm_output output;
int ret = dsm_evaluate(pdev, dsm_func, &output, 0);
if (ret)
return ret;
if (output.status != 0)
return -EIO;
*buf = output.state;
return 0;
}
static int dsm_get_active_indications(struct npem *npem, u32 *buf)
{
int ret = dsm_get(npem->dev, GET_STATE_DSM, buf);
/* Filter out not supported indications in response */
*buf &= npem->supported_indications;
return ret;
}
static int dsm_set_active_indications(struct npem *npem, u32 value)
{
struct dsm_output output;
int ret = dsm_evaluate(npem->dev, SET_STATE_DSM, &output, value);
if (ret)
return ret;
switch (output.status) {
case 4:
/*
* Not all bits are set. If this bit is set, the platform
* disregarded some or all of the request state changes. OSPM
* should check the resulting PCIe SSD Status LED States to see
* what, if anything, has changed.
*
* PCI Firmware Specification, r3.3 Table 4-19.
*/
if (output.function_specific_err != 1)
return -EIO;
fallthrough;
case 0:
break;
default:
return -EIO;
}
npem->active_indications = output.state;
return 0;
}
static const struct npem_ops dsm_ops = {
.get_active_indications = dsm_get_active_indications,
.set_active_indications = dsm_set_active_indications,
.name = "_DSM PCIe SSD Status LED Management",
.inds = dsm_indications,
};
static int npem_initialize_active_indications(struct npem *npem)
{
int ret;
lockdep_assert_held(&npem->lock);
if (npem->active_inds_initialized)
return 0;
ret = npem->ops->get_active_indications(npem,
&npem->active_indications);
if (ret)
return ret;
npem->active_inds_initialized = true;
return 0;
}
/* /*
* The status of each indicator is cached on first brightness_ get/set time * The status of each indicator is cached on first brightness_ get/set time
* and updated at write time. brightness_get() is only responsible for * and updated at write time. brightness_get() is only responsible for
...@@ -261,9 +426,14 @@ static enum led_brightness brightness_get(struct led_classdev *led) ...@@ -261,9 +426,14 @@ static enum led_brightness brightness_get(struct led_classdev *led)
if (ret) if (ret)
return ret; return ret;
ret = npem_initialize_active_indications(npem);
if (ret)
goto out;
if (npem->active_indications & nled->indication->bit) if (npem->active_indications & nled->indication->bit)
val = 1; val = 1;
out:
mutex_unlock(&npem->lock); mutex_unlock(&npem->lock);
return val; return val;
} }
...@@ -280,6 +450,10 @@ static int brightness_set(struct led_classdev *led, ...@@ -280,6 +450,10 @@ static int brightness_set(struct led_classdev *led,
if (ret) if (ret)
return ret; return ret;
ret = npem_initialize_active_indications(npem);
if (ret)
goto out;
if (brightness == 0) if (brightness == 0)
indications = npem->active_indications & ~(nled->indication->bit); indications = npem->active_indications & ~(nled->indication->bit);
else else
...@@ -287,6 +461,7 @@ static int brightness_set(struct led_classdev *led, ...@@ -287,6 +461,7 @@ static int brightness_set(struct led_classdev *led,
ret = npem->ops->set_active_indications(npem, indications); ret = npem->ops->set_active_indications(npem, indications);
out:
mutex_unlock(&npem->lock); mutex_unlock(&npem->lock);
return ret; return ret;
} }
...@@ -359,11 +534,6 @@ static int pci_npem_init(struct pci_dev *dev, const struct npem_ops *ops, ...@@ -359,11 +534,6 @@ static int pci_npem_init(struct pci_dev *dev, const struct npem_ops *ops,
npem->dev = dev; npem->dev = dev;
npem->ops = ops; npem->ops = ops;
ret = npem->ops->get_active_indications(npem,
&npem->active_indications);
if (ret)
return ret;
mutex_init(&npem->lock); mutex_init(&npem->lock);
for_each_indication(indication, npem_indications) { for_each_indication(indication, npem_indications) {
...@@ -401,9 +571,11 @@ void pci_npem_create(struct pci_dev *dev) ...@@ -401,9 +571,11 @@ void pci_npem_create(struct pci_dev *dev)
* OS should use the DSM for LED control if it is available * OS should use the DSM for LED control if it is available
* PCI Firmware Spec r3.3 sec 4.7. * PCI Firmware Spec r3.3 sec 4.7.
*/ */
pci_info(dev, "Not configuring %s because _DSM is present\n", ret = dsm_get(dev, GET_SUPPORTED_STATES_DSM, &cap);
ops->name); if (ret)
return; return;
ops = &dsm_ops;
} else { } else {
pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_NPEM); pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_NPEM);
if (pos == 0) if (pos == 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment