]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
ocp: support OCP DSSD Async Event Config feature
authorBrandon Paupore <brandon.paupore@wdc.com>
Fri, 15 Mar 2024 21:36:47 +0000 (16:36 -0500)
committerDaniel Wagner <wagi@monom.org>
Wed, 10 Apr 2024 08:41:00 +0000 (10:41 +0200)
Adds two new OCP plugin functions for getting and setting this feature,
based on the 2.5 OCP spec.

Signed-off-by: Brandon Paupore <brandon.paupore@wdc.com>
Documentation/nvme-ocp-get-dssd-async-event-config.txt [new file with mode: 0644]
Documentation/nvme-ocp-set-dssd-async-event-config.txt [new file with mode: 0644]
completions/_nvme
completions/bash-nvme-completion.sh
plugins/ocp/ocp-nvme.c
plugins/ocp/ocp-nvme.h

diff --git a/Documentation/nvme-ocp-get-dssd-async-event-config.txt b/Documentation/nvme-ocp-get-dssd-async-event-config.txt
new file mode 100644 (file)
index 0000000..2254818
--- /dev/null
@@ -0,0 +1,53 @@
+nvme-ocp-get-dssd-async-event-config(1)
+=======================================
+
+NAME
+----
+nvme-ocp-get-dssd-async-event-config - Get dssd-async-event-config value
+
+SYNOPSIS
+--------
+[verse]
+'nvme ocp get-dssd-async-event-config' <device> [--sel=<select> | -s <select>]
+
+DESCRIPTION
+-----------
+Get dssd-async-event-config.
+
+The <device> parameter is mandatory and may be either the NVMe character
+device (ex: /dev/nvme0) or block device (ex: /dev/nvme0n1).
+
+This will only work on OCP compliant devices supporting this feature.
+Results for any other device are undefined.
+
+On success it returns 0, error code otherwise.
+
+OPTIONS
+-------
+
+-s <select>::
+--sel=<select>::
+       Select (SEL): This field specifies which value of the attributes
+       to return in the provided data:
++
+[]
+|==================
+|Select|Description
+|0|Current
+|1|Default
+|2|Saved
+|3|Supported capabilities
+|4-7|Reserved
+|==================
+
+EXAMPLES
+--------
+* Has the program issue a get-dssd-async-event-config to retrieve the saved 0xC9 get features.
++
+------------
+# nvme ocp get-dssd-async-event-config /dev/nvme0 -s 2
+------------
+
+NVME
+----
+Part of the nvme-user suite.
diff --git a/Documentation/nvme-ocp-set-dssd-async-event-config.txt b/Documentation/nvme-ocp-set-dssd-async-event-config.txt
new file mode 100644 (file)
index 0000000..de60bbf
--- /dev/null
@@ -0,0 +1,48 @@
+nvme-ocp-set-dssd-async-event-config(1)
+=======================================
+
+NAME
+----
+nvme-ocp-set-dssd-async-event-config - Set DSSD asynchronous event configuration
+
+SYNOPSIS
+--------
+[verse]
+'nvme ocp set-dssd-async-event-config' <device> [--enable-panic-notices | -e] [--save | -s]
+
+
+DESCRIPTION
+-----------
+Set DSSD asynchronous event configuration
+
+The <device> parameter is mandatory and may be either the NVMe character
+device (ex: /dev/nvme0) or block device (ex: /dev/nvme0n1).
+
+This will only work on OCP compliant devices supporting this feature.
+Results for any other device are undefined.
+
+On success it returns 0, error code otherwise.
+
+OPTIONS
+-------
+-e::
+--enable-panic-notices::
+       Set enable panic notices [0]
+
+-s::
+--save::
+       Save the attribute so that it persists through all power states and resets.
+
+
+EXAMPLES
+--------
+* Has the program issue a set-dssd-async-event-config to enable panic notices,
+persisting through power states.
++
+------------
+# nvme ocp set-dssd-async-event-config /dev/nvme0 -e -s
+------------
+
+NVME
+----
+Part of the nvme-user suite.
index 40e2c1df1137b2d4aa027b165a6e894e15977311..159a4ab61c24a2d537f30283e76b4e010d273748 100644 (file)
@@ -266,6 +266,29 @@ _nvme () {
                                _arguments '*:: :->subcmds'
                                _describe -t commands "nvme ocp telemetry-string-log options" _telemetry_string_log
                                ;;
+                       (set-dssd-async-event-config)
+                               local _set_dssd_async_event_config
+                               _set_dssd_async_event_config=(
+                               /dev/nvme':supply a device to use (required)'
+                               --enable-panic-notices':Specifies whether an asynchronous event notification
+                               is sent to the host for a panic event'
+                               -e':alias for --enable-panic-notices'
+                               --save':Specifies that the controller shall save the attribute'
+                               -s':alias for --save'
+                               )
+                               _arguments '*:: :->subcmds'
+                               _describe -t commands "nvme ocp set-dssd-async-event-config options" _set_dssd_async_event_config
+                               ;;
+                       (get-dssd-async-event-config)
+                               local _get_dssd_async_event_config
+                               _get_dssd_async_event_config=(
+                               /dev/nvme':supply a device to use (required)'
+                               --sel=':select from 0 - current, 1 - default, 2 - saved, 3 - supported'
+                               -S':alias to --sel'
+                               )
+                               _arguments '*:: :->subcmds'
+                               _describe -t commands "nvme ocp get-dssd-async-event-config options" _get_dssd_async_event_config
+                               ;;
                        (*)
                                _files
                                ;;
index 0a4305eb5cd94319a1725c06e9ff8b334b9f44ac..f5cdb436554a89fc39ee7397194ba096baff14de 100644 (file)
@@ -1461,6 +1461,12 @@ plugin_ocp_opts () {
                "set-telemetry-profile")
                opts+=" --telemetry-profile-select= -t"
                        ;;
+               "set-dssd-async-event-config")
+               opts+=" --enable-panic-notices -e --save -s"
+                       ;;
+               "get-dssd-power-state-feature")
+               opts+=" --sel= -S"
+                       ;;
                "help")
                opts+=$NO_OPTS
                        ;;
@@ -1537,7 +1543,8 @@ _nvme_subcmds () {
                        clear-pcie-correctable-error-counters \
                        vs-fw-activate-history device-capability-log \
                        set-dssd-power-state-feature telemetry-string-log \
-                       set-telemetry-profile"
+                       set-telemetry-profile set-dssd-async-event-config \
+                       get-dssd-async-event-config"
        )
 
        # Associative array mapping plugins to corresponding option completions
index a4d9fc9de8866950ddf624026fc61c09adbb3fbb..8acc9e97fb68a3dd600b907cab406357e40e42e5 100644 (file)
@@ -2377,6 +2377,140 @@ static int get_plp_health_check_interval(int argc, char **argv, struct command *
     return err;
 }
 
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+/// dssd_async_event_config
+
+static int set_dssd_async_event_config(int argc, char **argv, struct command *cmd,
+                                       struct plugin *plugin)
+{
+
+    const char *desc = "Issue Set Feature command (FID : 0xC9) DSSD Async Event Config";
+    const char *epn = "[0]:Enable Panic Notices";
+    const char *save = "Specifies that the controller shall save the attribute";
+    const __u32 nsid = 0;
+    const __u8 fid = 0xc9;
+    struct nvme_dev *dev;
+    int err;
+    __u32 result;
+    int uuid_index = 0;
+
+    struct config {
+        bool epn;
+        bool save;
+    };
+
+    struct config cfg = {
+        .epn = false,
+        .save = false,
+    };
+
+    OPT_ARGS(opts) = {
+        OPT_FLAG("enable-panic-notices", 'e', &cfg.epn, epn),
+        OPT_FLAG("save", 's', &cfg.save, save),
+        OPT_END()
+    };
+
+    err = parse_and_open(&dev, argc, argv, desc, opts);
+    if (err)
+        return err;
+
+    /* OCP 2.0 requires UUID index support */
+    err = ocp_get_uuid_index(dev, &uuid_index);
+    if (err || !uuid_index) {
+        printf("ERROR: No OCP UUID index found\n");
+        return err;
+    }
+
+    struct nvme_set_features_args args = {
+        .args_size = sizeof(args),
+        .fd = dev_fd(dev),
+        .fid = fid,
+        .nsid = nsid,
+        .cdw11 = cfg.epn ? 1 : 0,
+        .cdw12 = 0,
+        .save = cfg.save,
+        .uuidx = uuid_index,
+        .cdw15 = 0,
+        .data_len = 0,
+        .data = NULL,
+        .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+        .result = &result,
+    };
+
+    err = nvme_set_features(&args);
+    if (err > 0) {
+        nvme_show_status(err);
+    } else if (err < 0) {
+        nvme_show_perror("Set DSSD Asynchronous Event Configuration\n");
+        fprintf(stderr, "Command failed while parsing.\n");
+    } else {
+        printf("Successfully set the DSSD Asynchronous Event Configuration\n");
+        printf("Enable Panic Notices bit Value: 0x%x\n", cfg.epn);
+        printf("Save bit Value: 0x%x\n", cfg.save);
+    }
+    return err;
+}
+
+static int get_dssd_async_event_config(int argc, char **argv, struct command *cmd,
+                                       struct plugin *plugin)
+{
+
+    const char *desc = "Issue Get Feature command (FID : 0xC9) DSSD Async Event Config";
+    const char *sel = "[0-3]: current/default/saved/supported";
+    const __u32 nsid = 0;
+    const __u8 fid = 0xc9;
+    struct nvme_dev *dev;
+    __u32 result;
+    int err;
+
+    struct config {
+        __u8 sel;
+    };
+
+    struct config cfg = {
+        .sel = 0,
+    };
+
+    OPT_ARGS(opts) = {
+        OPT_BYTE("sel", 'S', &cfg.sel, sel),
+        OPT_END()
+    };
+
+    err = parse_and_open(&dev, argc, argv, desc, opts);
+    if (err)
+        return err;
+
+
+    struct nvme_get_features_args args = {
+        .args_size  = sizeof(args),
+        .fd         = dev_fd(dev),
+        .fid        = fid,
+        .nsid       = nsid,
+        .sel        = cfg.sel,
+        .cdw11      = 0,
+        .uuidx      = 0,
+        .data_len   = 0,
+        .data       = NULL,
+        .timeout    = NVME_DEFAULT_IOCTL_TIMEOUT,
+        .result     = &result,
+    };
+
+    err = nvme_get_features(&args);
+    if (!err) {
+        printf("get-feature:0xC9 %s value: %#08x\n", nvme_select_to_string(cfg.sel), result);
+
+        if (cfg.sel == NVME_GET_FEATURES_SEL_SUPPORTED)
+            nvme_show_select_result(fid, result);
+    } else {
+        nvme_show_error("Could not get feature: 0xC9\n");
+    }
+
+    return err;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
index 5ee68906c61e3920915abf49a802613e8c0f1b05..0317ea7cbc93862c06fbbca1e6fb3f21a266bbf0 100644 (file)
@@ -31,6 +31,8 @@ PLUGIN(NAME("ocp", "OCP cloud SSD extensions", NVME_VERSION),
                ENTRY("get-plp-health-check-interval", "Get PLP Health Check Interval", get_plp_health_check_interval)
                ENTRY("telemetry-string-log", "Retrieve Telemetry string Log Page", ocp_telemetry_str_log_format)
                ENTRY("set-telemetry-profile", "Set Telemetry Profile Feature", ocp_set_telemetry_profile_feature)
+               ENTRY("set-dssd-async-event-config", "Set DSSD Async Event Config", set_dssd_async_event_config)
+               ENTRY("get-dssd-async-event-config", "Get DSSD Async Event Config", get_dssd_async_event_config)
        )
 );