From 23bd45b5c3f3f5aff723be5d9d7f84bfc30afaf9 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Fri, 17 Mar 2023 01:14:09 +0900 Subject: [PATCH] plugins/ocp: Refactor to clear feature identifier C1h and C3h Signed-off-by: Tokunori Ikegami --- plugins/ocp/ocp-clear-fw-update-history.c | 56 +------------------ plugins/ocp/ocp-nvme.c | 60 +-------------------- plugins/ocp/ocp-utils.c | 65 +++++++++++++++++++++++ plugins/ocp/ocp-utils.h | 2 + 4 files changed, 71 insertions(+), 112 deletions(-) diff --git a/plugins/ocp/ocp-clear-fw-update-history.c b/plugins/ocp/ocp-clear-fw-update-history.c index fef09cff..b9235b82 100644 --- a/plugins/ocp/ocp-clear-fw-update-history.c +++ b/plugins/ocp/ocp-clear-fw-update-history.c @@ -15,59 +15,7 @@ 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; + return ocp_clear_feature(argc, argv, desc, + OCP_FID_CLEAR_FW_ACTIVATION_HISTORY); } diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index a8c841ba..cc09a9f4 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -956,63 +956,7 @@ static int clear_pcie_corectable_error_counters(int argc, char **argv, struct plugin *plugin) { const char *desc = "OCP Clear PCIe Correctable Error Counters"; - __u32 result = 0; - __u32 clear_pcie_error_counters = 1 << 31; - struct nvme_dev *dev; - int uuid_index = 0; - bool uuid = true; - int err; - - OPT_ARGS(opts) = { - OPT_FLAG("no-uuid", 'n', NULL, - "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 (opts[0].seen) - uuid = false; - - if (uuid) { - /* OCP 2.0 requires UUID index support */ - err = ocp_get_uuid_index(dev, &uuid_index); - if (err || !uuid_index) { - 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_pcie_error_counters, - .cdw12 = 0, - .cdw13 = 0, - .cdw15 = 0, - .data_len = 0, - .save = 0, - .uuidx = uuid_index, - .fid = OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS, - }; - - 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; + return ocp_clear_feature(argc, argv, desc, + OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS); } diff --git a/plugins/ocp/ocp-utils.c b/plugins/ocp/ocp-utils.c index 34b212ba..a37a58c6 100644 --- a/plugins/ocp/ocp-utils.c +++ b/plugins/ocp/ocp-utils.c @@ -5,7 +5,9 @@ * Author: leonardo.da.cunha@solidigm.com */ +#include #include "ocp-utils.h" +#include "nvme-print.h" const unsigned char ocp_uuid[NVME_UUID_LEN] = { 0xc1, 0x94, 0xd5, 0x5b, 0xe0, 0x94, 0x47, 0x94, 0xa2, 0x1d, @@ -28,3 +30,66 @@ int ocp_get_uuid_index(struct nvme_dev *dev, int *index) } return err; } + +int ocp_clear_feature(int argc, char **argv, const char *desc, const __u8 fid) +{ + __u32 result = 0; + __u32 clear = 1 << 31; + struct nvme_dev *dev; + int uuid_index = 0; + bool uuid = true; + int err; + + OPT_ARGS(opts) = { + OPT_FLAG("no-uuid", 'n', NULL, + "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 (opts[0].seen) + uuid = false; + + if (uuid) { + /* OCP 2.0 requires UUID index support */ + err = ocp_get_uuid_index(dev, &uuid_index); + if (err || !uuid_index) { + 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, + .cdw12 = 0, + .cdw13 = 0, + .cdw15 = 0, + .data_len = 0, + .save = 0, + .uuidx = uuid_index, + .fid = fid, + }; + + 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-utils.h b/plugins/ocp/ocp-utils.h index 44d0af4a..a9621690 100644 --- a/plugins/ocp/ocp-utils.h +++ b/plugins/ocp/ocp-utils.h @@ -16,3 +16,5 @@ * 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); + +int ocp_clear_feature(int argc, char **argv, const char *desc, const __u8 fid); -- 2.50.1