From 69e664cefb2a9992ebd194f864044b70b0601a19 Mon Sep 17 00:00:00 2001 From: hpanosy Date: Thu, 11 Aug 2022 16:34:13 -0700 Subject: [PATCH] solidigm, ocp: Added OCP-Clear-FW-Update-History support, and exposed feature on ocp and solidigm plug-ins. --- Documentation/meson.build | 1 + .../nvme-ocp-clear-fw-activate-history.txt | 49 +++++++++++++ plugins/meson.build | 2 +- plugins/ocp/meson.build | 6 ++ plugins/ocp/ocp-clear-fw-update-history.c | 73 +++++++++++++++++++ plugins/ocp/ocp-clear-fw-update-history.h | 9 +++ plugins/ocp/ocp-nvme.c | 7 ++ plugins/ocp/ocp-nvme.h | 11 ++- plugins/ocp/ocp-utils.c | 30 ++++++++ plugins/ocp/ocp-utils.h | 18 +++++ plugins/solidigm/solidigm-nvme.c | 9 ++- plugins/solidigm/solidigm-nvme.h | 5 +- 12 files changed, 213 insertions(+), 7 deletions(-) create mode 100644 Documentation/nvme-ocp-clear-fw-activate-history.txt create mode 100644 plugins/ocp/meson.build create mode 100644 plugins/ocp/ocp-clear-fw-update-history.c create mode 100644 plugins/ocp/ocp-clear-fw-update-history.h create mode 100644 plugins/ocp/ocp-utils.c create mode 100644 plugins/ocp/ocp-utils.h diff --git a/Documentation/meson.build b/Documentation/meson.build index a15d1e4b..68be45fa 100644 --- a/Documentation/meson.build +++ b/Documentation/meson.build @@ -78,6 +78,7 @@ adoc_sources = [ 'nvme-nvm-id-ctrl', 'nvme-ocp-latency-monitor-log', 'nvme-ocp-smart-add-log', + 'nvme-ocp-clear-fw-activate-history', 'nvme-persistent-event-log', 'nvme-pred-lat-event-agg-log', 'nvme-predictable-lat-log', diff --git a/Documentation/nvme-ocp-clear-fw-activate-history.txt b/Documentation/nvme-ocp-clear-fw-activate-history.txt new file mode 100644 index 00000000..21084808 --- /dev/null +++ b/Documentation/nvme-ocp-clear-fw-activate-history.txt @@ -0,0 +1,49 @@ +nvme-ocp-clear-fw-activate-history(1) +===================================== + +NAME +---- +nvme-ocp-clear-fw-activate-history - Clear the OCP Firmware Update History Log + +SYNOPSIS +-------- +[verse] +'nvme ocp clear-fw-activate-history' [--no-uuid | -n>] + +DESCRIPTION +----------- +For the NVMe device given, Clear OCP Firmware Update History Log. + +The parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0) or block device (ex: /dev/nvme0n1). + +This command with no option added, will try to automatically detect the +parameters of the command. This will work successfully or fail gracefully for +devices supporting UUID for Vendor Specific Information (NVMe 1.4 or later, +OCP 2.0 requires NVMe 1.4b). For devices that do not support OCP 2.0 the +command will fail gracefully, unless the --no-uuid option is provided. + +For OCP 1.0 devices (before NVMe 1.4) the --no-uuid option is required. +When --no-uuid option is provided, results for devices before NVMe 1.4 without +OCP support are undefined. + +On success it returns 0, error code otherwise. + +OPTIONS +------- +-n:: +--no-uuid:: + Do not try to automatically detect UUID index for this command (required + for old OCP 1.0 support) + +EXAMPLES +-------- +* Clears OCP Firmware Activation History Log for the device: ++ +------------ +# nvme ocp clear-fw-activate-history /dev/nvme0 +------------ + +NVME +---- +Part of the nvme-user suite. \ No newline at end of file diff --git a/plugins/meson.build b/plugins/meson.build index e6d9aaab..52b7f4ae 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -22,7 +22,7 @@ sources += [ 'plugins/wdc/wdc-nvme.c', 'plugins/ymtc/ymtc-nvme.c', 'plugins/zns/zns.c', - 'plugins/ocp/ocp-nvme.c', 'plugins/inspur/inspur-nvme.c', ] subdir('solidigm') +subdir('ocp') diff --git a/plugins/ocp/meson.build b/plugins/ocp/meson.build new file mode 100644 index 00000000..a4e5d205 --- /dev/null +++ b/plugins/ocp/meson.build @@ -0,0 +1,6 @@ +sources += [ + 'plugins/ocp/ocp-utils.c', + 'plugins/ocp/ocp-nvme.c', + 'plugins/ocp/ocp-clear-fw-update-history.c', +] + diff --git a/plugins/ocp/ocp-clear-fw-update-history.c b/plugins/ocp/ocp-clear-fw-update-history.c new file mode 100644 index 00000000..fef09cff --- /dev/null +++ b/plugins/ocp/ocp-clear-fw-update-history.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Solidigm. + * + * Authors: haro.panosyan@solidigm.com + * leonardo.da.cunha@solidigm.com + */ + +#include +#include "ocp-utils.h" +#include "nvme-print.h" + +static const __u8 OCP_FID_CLEAR_FW_ACTIVATION_HISTORY = 0xC1; + +int ocp_clear_fw_update_history(int argc, char **argv, struct command *cmd, struct plugin *plugin) +{ + const char *desc = "OCP Clear Firmware Update History"; + __u32 result = 0; + __u32 clear_fw_history = 1 << 31; + struct nvme_dev *dev; + int uuid_index = 0; + bool no_uuid = false; + int err; + + OPT_ARGS(opts) = { + OPT_FLAG("no-uuid", 'n', &no_uuid, + "Skip UUID index search (UUID index not required for OCP 1.0)"), + OPT_END() + }; + + err = parse_and_open(&dev, argc, argv, desc, opts); + if (err) + return err; + if (no_uuid == false) { + // OCP 2.0 requires UUID index support + err = ocp_get_uuid_index(dev, &uuid_index); + if (err || uuid_index == 0) { + fprintf(stderr, "ERROR: No OCP UUID index found\n"); + goto close_dev; + } + } + + struct nvme_set_features_args args = { + .result = &result, + .data = NULL, + .args_size = sizeof(args), + .fd = dev_fd(dev), + .timeout = NVME_DEFAULT_IOCTL_TIMEOUT, + .nsid = 0, + .cdw11 = clear_fw_history, + .cdw12 = 0, + .cdw13 = 0, + .cdw15 = 0, + .data_len = 0, + .save = 0, + .uuidx = uuid_index, + .fid = OCP_FID_CLEAR_FW_ACTIVATION_HISTORY, + }; + + err = nvme_set_features(&args); + + if (err == 0) + printf("Success : %s\n", desc); + else if (err > 0) + nvme_show_status(err); + else + printf("Fail : %s\n", desc); +close_dev: + /* Redundant close() to make static code analysis happy */ + close(dev->direct.fd); + dev_close(dev); + return err; +} diff --git a/plugins/ocp/ocp-clear-fw-update-history.h b/plugins/ocp/ocp-clear-fw-update-history.h new file mode 100644 index 00000000..25fb6b1f --- /dev/null +++ b/plugins/ocp/ocp-clear-fw-update-history.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2022 Solidigm. + * + * Authors: haro.panosyan@solidigm.com + * leonardo.da.cunha@solidigm.com + */ + +int ocp_clear_fw_update_history(int argc, char **argv, struct command *cmd, struct plugin *plugin); diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index 5cbf6cb2..14a5f306 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -22,6 +22,7 @@ #include "linux/types.h" #include "util/types.h" #include "nvme-print.h" +#include "ocp-clear-fw-update-history.h" #define CREATE_CMD #include "ocp-nvme.h" @@ -765,3 +766,9 @@ static int ocp_latency_monitor_log(int argc, char **argv, struct command *comman dev_close(dev); return ret; } + +static int clear_fw_update_history(int argc, char **argv, struct command *cmd, + struct plugin *plugin) +{ + return ocp_clear_fw_update_history(argc, argv, cmd, plugin); +} diff --git a/plugins/ocp/ocp-nvme.h b/plugins/ocp/ocp-nvme.h index 3e3f437a..c20646a2 100644 --- a/plugins/ocp/ocp-nvme.h +++ b/plugins/ocp/ocp-nvme.h @@ -14,10 +14,13 @@ #include "cmd.h" PLUGIN(NAME("ocp", "OCP cloud SSD extensions", NVME_VERSION), - COMMAND_LIST( - ENTRY("smart-add-log", "Retrieve extended SMART Information", ocp_smart_add_log) - ENTRY("latency-monitor-log", "Get Latency Monitor Log Page", ocp_latency_monitor_log) - ) + COMMAND_LIST( + ENTRY("smart-add-log", "Retrieve extended SMART Information", ocp_smart_add_log) + ENTRY("latency-monitor-log", "Get Latency Monitor Log Page", + ocp_latency_monitor_log) + ENTRY("clear-fw-activate-history", "Clear firmware update history log", + clear_fw_update_history) + ) ); #endif diff --git a/plugins/ocp/ocp-utils.c b/plugins/ocp/ocp-utils.c new file mode 100644 index 00000000..9294c05d --- /dev/null +++ b/plugins/ocp/ocp-utils.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 Solidigm. + * + * Author: leonardo.da.cunha@solidigm.com + */ + +#include "ocp-utils.h" + +const unsigned char ocp_uuid[NVME_UUID_LEN] = { + 0x6f, 0xbe, 0x56, 0x8f, 0x99, 0x29, 0x1d, 0xa2, 0x94, 0x47, + 0x94, 0xe0, 0x5b, 0xd5, 0x94, 0xc1 }; + +int ocp_get_uuid_index(struct nvme_dev *dev, int *index) +{ + struct nvme_id_uuid_list uuid_list; + int err = nvme_identify_uuid(dev_fd(dev), &uuid_list); + + *index = 0; + if (err) + return err; + + for (int i = 0; i < NVME_ID_UUID_LIST_MAX; i++) { + if (memcmp(ocp_uuid, &uuid_list.entry[i].uuid, NVME_UUID_LEN) == 0) { + *index = i + 1; + break; + } + } + return err; +} diff --git a/plugins/ocp/ocp-utils.h b/plugins/ocp/ocp-utils.h new file mode 100644 index 00000000..44d0af4a --- /dev/null +++ b/plugins/ocp/ocp-utils.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2022 Solidigm. + * + * Author: leonardo.da.cunha@solidigm.com + */ + +#include "nvme.h" + +/** + * ocp_get_uuid_index() - Get OCP UUID index + * @dev: nvme device + * @index: integer ponter to here to save the index + * @result: The command completion result from CQE dword0 + * + * Return: Zero if nvme device has UUID list log page, or result of get uuid list otherwise. + */ +int ocp_get_uuid_index(struct nvme_dev *dev, int *index); diff --git a/plugins/solidigm/solidigm-nvme.c b/plugins/solidigm/solidigm-nvme.c index 684648ad..b547035c 100644 --- a/plugins/solidigm/solidigm-nvme.c +++ b/plugins/solidigm/solidigm-nvme.c @@ -14,6 +14,7 @@ #include "solidigm-garbage-collection.h" #include "solidigm-latency-tracking.h" #include "solidigm-telemetry.h" +#include "plugins/ocp/ocp-clear-fw-update-history.h" static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { @@ -33,4 +34,10 @@ static int get_latency_tracking_log(int argc, char **argv, struct command *cmd, static int get_telemetry_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { return solidigm_get_telemetry_log(argc, argv, cmd, plugin); -} \ No newline at end of file +} + +static int clear_fw_update_history(int argc, char **argv, struct command *cmd, + struct plugin *plugin) +{ + return ocp_clear_fw_update_history(argc, argv, cmd, plugin); +} diff --git a/plugins/solidigm/solidigm-nvme.h b/plugins/solidigm/solidigm-nvme.h index ed484000..778dbf99 100644 --- a/plugins/solidigm/solidigm-nvme.h +++ b/plugins/solidigm/solidigm-nvme.h @@ -13,7 +13,7 @@ #include "cmd.h" -#define SOLIDIGM_PLUGIN_VERSION "0.6" +#define SOLIDIGM_PLUGIN_VERSION "0.7" PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_VERSION), COMMAND_LIST( @@ -21,6 +21,9 @@ PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_V ENTRY("garbage-collect-log", "Retrieve Garbage Collection Log", get_garbage_collection_log) ENTRY("latency-tracking-log", "Enable/Retrieve Latency tracking Log", get_latency_tracking_log) ENTRY("parse-telemetry-log", "Parse Telemetry Log binary", get_telemetry_log) + ENTRY("clear-fw-activate-history", + "Clear firmware update history log (redirects to ocp plug-in)", + clear_fw_update_history) ) ); -- 2.50.1