]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/ocp: Reorganized clear feature code for better reuse
authorleonardo.da.cunha <leonardo.da.cunha@solidigm.com>
Mon, 16 Oct 2023 16:33:09 +0000 (09:33 -0700)
committerDaniel Wagner <wagi@monom.org>
Mon, 27 Nov 2023 12:29:48 +0000 (13:29 +0100)
Signed-off-by: leonardo.da.cunha <leonardo.da.cunha@solidigm.com>
plugins/ocp/meson.build
plugins/ocp/ocp-clear-features.c [new file with mode: 0644]
plugins/ocp/ocp-clear-features.h [new file with mode: 0644]
plugins/ocp/ocp-clear-fw-update-history.c [deleted file]
plugins/ocp/ocp-clear-fw-update-history.h [deleted file]
plugins/ocp/ocp-nvme.c
plugins/ocp/ocp-utils.c
plugins/ocp/ocp-utils.h
plugins/solidigm/solidigm-nvme.c

index 405ee512f31c5bbd3106f13a5e7f41bf99e88762..64447ff66c723ebdfdebc8d336d297959e166f47 100644 (file)
@@ -1,7 +1,7 @@
 sources += [
   'plugins/ocp/ocp-utils.c',
   'plugins/ocp/ocp-nvme.c',
-  'plugins/ocp/ocp-clear-fw-update-history.c',
+  'plugins/ocp/ocp-clear-features.c',
   'plugins/ocp/ocp-smart-extended-log.c',
   'plugins/ocp/ocp-fw-activation-history.c',
 ]
diff --git a/plugins/ocp/ocp-clear-features.c b/plugins/ocp/ocp-clear-features.c
new file mode 100644 (file)
index 0000000..7c4e7e5
--- /dev/null
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Solidigm.
+ *
+ * Authors: haro.panosyan@solidigm.com
+ *          leonardo.da.cunha@solidigm.com
+ */
+
+#include <unistd.h>
+#include "ocp-utils.h"
+#include "nvme-print.h"
+
+static const __u8 OCP_FID_CLEAR_FW_ACTIVATION_HISTORY = 0xC1;
+static const __u8 OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS = 0xC3;
+
+static 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;
+}
+
+int ocp_clear_fw_update_history(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       const char *desc = "OCP Clear Firmware Update History";
+
+       return ocp_clear_feature(argc, argv, desc, OCP_FID_CLEAR_FW_ACTIVATION_HISTORY);
+}
+
+int ocp_clear_pcie_corectable_error_counters(int argc, char **argv, struct command *cmd,
+                                            struct plugin *plugin)
+{
+       const char *desc = "OCP Clear PCIe Correctable Error Counters";
+
+       return ocp_clear_feature(argc, argv, desc,
+                                OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS);
+}
diff --git a/plugins/ocp/ocp-clear-features.h b/plugins/ocp/ocp-clear-features.h
new file mode 100644 (file)
index 0000000..cbecd4b
--- /dev/null
@@ -0,0 +1,12 @@
+/* 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);
+
+int ocp_clear_pcie_corectable_error_counters(int argc, char **argv, struct command *cmd,
+                                            struct plugin *plugin);
diff --git a/plugins/ocp/ocp-clear-fw-update-history.c b/plugins/ocp/ocp-clear-fw-update-history.c
deleted file mode 100644 (file)
index 6b256b1..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2022 Solidigm.
- *
- * Authors: haro.panosyan@solidigm.com
- *          leonardo.da.cunha@solidigm.com
- */
-
-#include <unistd.h>
-#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";
-
-       return ocp_clear_feature(argc, argv, desc, OCP_FID_CLEAR_FW_ACTIVATION_HISTORY);
-}
diff --git a/plugins/ocp/ocp-clear-fw-update-history.h b/plugins/ocp/ocp-clear-fw-update-history.h
deleted file mode 100644 (file)
index cd0844c..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-/* 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);
index cc67a091cd37e267a3dfd7bea59b44e52de84363..cebb0d9dd4b330ba5443dfb4011286e7f5fda3b2 100644 (file)
@@ -25,7 +25,7 @@
 #include "nvme-print.h"
 
 #include "ocp-smart-extended-log.h"
-#include "ocp-clear-fw-update-history.h"
+#include "ocp-clear-features.h"
 #include "ocp-fw-activation-history.h"
 
 #define CREATE_CMD
@@ -2106,8 +2106,6 @@ static int get_plp_health_check_interval(int argc, char **argv, struct command *
 ///////////////////////////////////////////////////////////////////////////////
 /// Misc
 
-static const __u8 OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS = 0xC3;
-
 static int clear_fw_update_history(int argc, char **argv,
                                   struct command *cmd, struct plugin *plugin)
 {
@@ -2120,14 +2118,10 @@ static int smart_add_log(int argc, char **argv, struct command *cmd,
        return ocp_smart_add_log(argc, argv, cmd, plugin);
 }
 
-static int clear_pcie_corectable_error_counters(int argc, char **argv,
-                                               struct command *cmd,
+static int clear_pcie_corectable_error_counters(int argc, char **argv, struct command *cmd,
                                                struct plugin *plugin)
 {
-       const char *desc = "OCP Clear PCIe Correctable Error Counters";
-
-       return ocp_clear_feature(argc, argv, desc,
-                                OCP_FID_CLEAR_PCIE_CORRECTABLE_ERROR_COUNTERS);
+       return ocp_clear_pcie_corectable_error_counters(argc, argv, cmd, plugin);
 }
 
 static int fw_activation_history_log(int argc, char **argv, struct command *cmd,
index a37a58c6de0152532e688821023f81a332b53ff1..1257b300fca45f0eb9803c9df486275c87d6f400 100644 (file)
@@ -30,66 +30,3 @@ 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;
-}
index 76a4b9418473f662cfa2c04c8fd8bb8939571a7c..d02bea99a029c2c4d61e07b6add0623a3e609766 100644 (file)
@@ -16,5 +16,3 @@
  * 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);
index a000f8eb9b108f45470e664f705c2d9661df5b55..ecb515a07c97426c9a5d77b44e62fa3f9b8517a3 100644 (file)
@@ -20,7 +20,7 @@
 #include "solidigm-market-log.h"
 #include "solidigm-temp-stats.h"
 
-#include "plugins/ocp/ocp-clear-fw-update-history.h"
+#include "plugins/ocp/ocp-clear-features.h"
 #include "plugins/ocp/ocp-smart-extended-log.h"
 #include "plugins/ocp/ocp-fw-activation-history.h"