Skip to content

Commit

Permalink
Merge branch 'for-79/set-alert-config' into pending
Browse files Browse the repository at this point in the history
CXL 3.0 Spec 8.2.9.8.3.3 defines Set Alert Configuration mailbox command,
which configures device's warning alerts.
This patchset adds support for the command.

The implementation is based on the 'ndctl-inject-smart'. Variable and function
names are aligned with the implementation of 'Get Alert Configuration'.
  • Loading branch information
stellarhopper committed Oct 27, 2023
2 parents d32dc01 + 5ae5063 commit e3f6046
Show file tree
Hide file tree
Showing 10 changed files with 436 additions and 1 deletion.
152 changes: 152 additions & 0 deletions Documentation/cxl/cxl-set-alert-config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// SPDX-License-Identifier: GPL-2.0

cxl-set-alert-config(1)
=======================

NAME
----
cxl-set-alert-config - set the warning alert threshold on a CXL memdev

SYNOPSIS
--------
[verse]
'cxl set-alert-config <mem0> [<mem1>..<memN>] [<options>]'

DESCRIPTION
-----------
CXL device raises an alert when its health status is changed. Critical alert
shall automatically be configured by the device after a device reset.
If supported, programmable warning thresholds also be initialized to vendor
recommended defaults, then could be configured by the user.

Use this command to configure warning alert thresholds of a device.
Having issued this command, the newly requested warning thresholds would
override the previously programmed warning thresholds.

To enable warning alert, set both 'threshold=value' and 'alert=on'. To disable
warning alert, set only 'alert=off'. Other cases would cause errors.

Use "cxl list -m <memdev> -A" to examine the programming warning threshold
capabilities of a device.

EXAMPLES
--------
Set warning threshold to 30 and enable alert for life used.
----
# cxl set-alert-config mem0 --life-used-threshold=30 --life-used-alert=on
{
  "memdev":"mem0",
  "ram_size":"1024.00 MiB (1073.74 MB)",
  "alert_config":{
    "life_used_prog_warn_threshold_valid":true,
    "dev_over_temperature_prog_warn_threshold_valid":false,
    "dev_under_temperature_prog_warn_threshold_valid":false,
    "corrected_volatile_mem_err_prog_warn_threshold_valid":false,
    "corrected_pmem_err_prog_warn_threshold_valid":false,
    "life_used_prog_warn_threshold_writable":true,
    "dev_over_temperature_prog_warn_threshold_writable":true,
    "dev_under_temperature_prog_warn_threshold_writable":true,
    "corrected_volatile_mem_err_prog_warn_threshold_writable":true,
    "corrected_pmem_err_prog_warn_threshold_writable":true,
    "life_used_crit_alert_threshold":75,
    "life_used_prog_warn_threshold":30,
    "dev_over_temperature_crit_alert_threshold":0,
    "dev_under_temperature_crit_alert_threshold":0,
    "dev_over_temperature_prog_warn_threshold":0,
    "dev_under_temperature_prog_warn_threshold":0,
    "corrected_volatile_mem_err_prog_warn_threshold":0,
    "corrected_pmem_err_prog_warn_threshold":0
  },
  "serial":"0",
  "host":"0000:0d:00.0"
}
cxl memdev: cmd_set_alert_config: set alert configuration 1 mem
----

Disable warning alert for life_used.
----
# cxl set-alert-config mem0 --life-used-alert=off
{
  "memdev":"mem0",
  "ram_size":"1024.00 MiB (1073.74 MB)",
  "alert_config":{
    "life_used_prog_warn_threshold_valid":false,
    "dev_over_temperature_prog_warn_threshold_valid":false,
    "dev_under_temperature_prog_warn_threshold_valid":false,
    "corrected_volatile_mem_err_prog_warn_threshold_valid":false,
    "corrected_pmem_err_prog_warn_threshold_valid":false,
    "life_used_prog_warn_threshold_writable":true,
    "dev_over_temperature_prog_warn_threshold_writable":true,
    "dev_under_temperature_prog_warn_threshold_writable":true,
    "corrected_volatile_mem_err_prog_warn_threshold_writable":true,
    "corrected_pmem_err_prog_warn_threshold_writable":true,
    "life_used_crit_alert_threshold":75,
    "life_used_prog_warn_threshold":30,
    "dev_over_temperature_crit_alert_threshold":0,
    "dev_under_temperature_crit_alert_threshold":0,
    "dev_over_temperature_prog_warn_threshold":0,
    "dev_under_temperature_prog_warn_threshold":0,
    "corrected_volatile_mem_err_prog_warn_threshold":0,
    "corrected_pmem_err_prog_warn_threshold":0
  },
  "serial":"0",
  "host":"0000:0d:00.0"
}
cxl memdev: cmd_set_alert_config: set alert configuration 1 mem
----

OPTIONS
-------
<memory device(s)>::
include::memdev-option.txt[]

-L::
--life-used-threshold=::
Set <value> for the life used warning alert threshold.

--life-used-alert=::
Enable or disable the life used warning alert.
Options are 'on' or 'off'.

-O::
--over-temperature-threshold=::
Set <value> for the device over temperature warning alert threshold.

--over-temperature-alert=::
Enable or disable the device over temperature warning alert.
Options are 'on' or 'off'.

-U::
--under-temperature-threshold=::
Set <value> for the device under temperature warning alert threshold.

--under-temperature-alert=::
Enable or disable the device under temperature warning alert.
Options are 'on' or 'off'.

-V::
--volatile-mem-err-threshold=::
Set <value> for the corrected volatile memory error warning alert
threshold.

--volatile-mem-err-alert=::
Enable or disable the corrected volatile memory error warning alert.
Options are 'on' or 'off'.

-P::
--pmem-err-threshold=::
Set <value> for the corrected persistent memory error warning alert
threshold.

--pmem-err-alert=::
Enable or disable the corrected persistent memory error warning alert.
Options are 'on' or 'off'.

-v::
--verbose::
Turn on verbose debug messages in the library (if libcxl was built with
logging and debug enabled).

SEE ALSO
--------
CXL-3.0 8.2.9.8.3.3
1 change: 1 addition & 0 deletions Documentation/cxl/lib/libcxl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev, int opcode);
struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev);
struct cxl_cmd *cxl_cmd_new_get_health_info(struct cxl_memdev *memdev);
struct cxl_cmd *cxl_cmd_new_get_alert_config(struct cxl_memdev *memdev);
struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev);
struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
unsigned int offset, unsigned int length);
struct cxl_cmd *cxl_cmd_new_write_label(struct cxl_memdev *memdev, void *buf,
Expand Down
1 change: 1 addition & 0 deletions Documentation/cxl/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ cxl_manpages = [
'cxl-destroy-region.txt',
'cxl-monitor.txt',
'cxl-update-firmware.txt',
'cxl-set-alert-config.txt',
]

foreach man : cxl_manpages
Expand Down
1 change: 1 addition & 0 deletions cxl/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ int cmd_enable_memdev(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_reserve_dpa(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_free_dpa(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_update_fw(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_set_alert_config(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_disable_port(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_enable_port(int argc, const char **argv, struct cxl_ctx *ctx);
int cmd_set_partition(int argc, const char **argv, struct cxl_ctx *ctx);
Expand Down
1 change: 1 addition & 0 deletions cxl/cxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ static struct cmd_struct commands[] = {
{ "reserve-dpa", .c_fn = cmd_reserve_dpa },
{ "free-dpa", .c_fn = cmd_free_dpa },
{ "update-firmware", .c_fn = cmd_update_fw },
{ "set-alert-config", .c_fn = cmd_set_alert_config },
{ "disable-port", .c_fn = cmd_disable_port },
{ "enable-port", .c_fn = cmd_enable_port },
{ "set-partition", .c_fn = cmd_set_partition },
Expand Down
21 changes: 21 additions & 0 deletions cxl/lib/libcxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4465,3 +4465,24 @@ CXL_EXPORT int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf,
{
return lsa_op(memdev, LSA_OP_GET, buf, length, offset);
}

#define cxl_alert_config_set_field(field) \
CXL_EXPORT int cxl_cmd_alert_config_set_##field(struct cxl_cmd *cmd, int val) \
{ \
struct cxl_cmd_set_alert_config *setalert = cmd->input_payload; \
setalert->field = val; \
return 0; \
}

cxl_alert_config_set_field(life_used_prog_warn_threshold)
cxl_alert_config_set_field(dev_over_temperature_prog_warn_threshold)
cxl_alert_config_set_field(dev_under_temperature_prog_warn_threshold)
cxl_alert_config_set_field(corrected_volatile_mem_err_prog_warn_threshold)
cxl_alert_config_set_field(corrected_pmem_err_prog_warn_threshold)
cxl_alert_config_set_field(valid_alert_actions)
cxl_alert_config_set_field(enable_alert_actions)

CXL_EXPORT struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev)
{
return cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_SET_ALERT_CONFIG);
}
12 changes: 12 additions & 0 deletions cxl/lib/libcxl.sym
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,15 @@ global:
cxl_memdev_update_fw;
cxl_memdev_cancel_fw_update;
} LIBCXL_5;

LIBCXL_7 {
global:
cxl_cmd_alert_config_set_life_used_prog_warn_threshold;
cxl_cmd_alert_config_set_dev_over_temperature_prog_warn_threshold;
cxl_cmd_alert_config_set_dev_under_temperature_prog_warn_threshold;
cxl_cmd_alert_config_set_corrected_volatile_mem_err_prog_warn_threshold;
cxl_cmd_alert_config_set_corrected_pmem_err_prog_warn_threshold;
cxl_cmd_alert_config_set_valid_alert_actions;
cxl_cmd_alert_config_set_enable_alert_actions;
cxl_cmd_new_set_alert_config;
} LIBCXL_6;
12 changes: 12 additions & 0 deletions cxl/lib/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,18 @@ struct cxl_cmd_get_alert_config {
#define CXL_CMD_ALERT_CONFIG_PROG_ALERTS_CORRECTED_PMEM_ERR_PROG_WARN_THRESHOLD_MASK \
BIT(4)

/* CXL 3.0 8.2.9.8.3.3 Set Alert Configuration */
struct cxl_cmd_set_alert_config {
u8 valid_alert_actions;
u8 enable_alert_actions;
u8 life_used_prog_warn_threshold;
u8 rsvd;
le16 dev_over_temperature_prog_warn_threshold;
le16 dev_under_temperature_prog_warn_threshold;
le16 corrected_volatile_mem_err_prog_warn_threshold;
le16 corrected_pmem_err_prog_warn_threshold;
} __attribute__((packed));

struct cxl_cmd_get_partition {
le64 active_volatile;
le64 active_persistent;
Expand Down
16 changes: 16 additions & 0 deletions cxl/libcxl.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,22 @@ enum cxl_setpartition_mode {
int cxl_cmd_partition_set_mode(struct cxl_cmd *cmd,
enum cxl_setpartition_mode mode);

int cxl_cmd_alert_config_set_life_used_prog_warn_threshold(struct cxl_cmd *cmd,
int threshold);
int cxl_cmd_alert_config_set_dev_over_temperature_prog_warn_threshold(
struct cxl_cmd *cmd, int threshold);
int cxl_cmd_alert_config_set_dev_under_temperature_prog_warn_threshold(
struct cxl_cmd *cmd, int threshold);
int cxl_cmd_alert_config_set_corrected_volatile_mem_err_prog_warn_threshold(
struct cxl_cmd *cmd, int threshold);
int cxl_cmd_alert_config_set_corrected_pmem_err_prog_warn_threshold(
struct cxl_cmd *cmd, int threshold);
int cxl_cmd_alert_config_set_valid_alert_actions(struct cxl_cmd *cmd,
int action);
int cxl_cmd_alert_config_set_enable_alert_actions(struct cxl_cmd *cmd,
int enable);
struct cxl_cmd *cxl_cmd_new_set_alert_config(struct cxl_memdev *memdev);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
Loading

0 comments on commit e3f6046

Please sign in to comment.