]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/solidigm: Added support for temperature statistics log page
authorda Cunha, Leonardo <leonardo.da.cunha@solidigm.com>
Fri, 22 Sep 2023 15:27:51 +0000 (08:27 -0700)
committerDaniel Wagner <wagi@monom.org>
Thu, 2 Nov 2023 16:43:52 +0000 (17:43 +0100)
Signed-off-by: leonardo.da.cunha <leonardo.da.cunha@solidigm.com>
plugins/solidigm/meson.build
plugins/solidigm/solidigm-nvme.c
plugins/solidigm/solidigm-nvme.h
plugins/solidigm/solidigm-temp-stats.c [new file with mode: 0644]
plugins/solidigm/solidigm-temp-stats.h [new file with mode: 0644]

index 84495a1439d080d6ee91999c4fe21067700adcfc..fb5e60d95c62e1504846d00f0ebb9e79fb76fa33 100644 (file)
@@ -8,6 +8,7 @@ sources += [
   'plugins/solidigm/solidigm-telemetry.c',
   'plugins/solidigm/solidigm-internal-logs.c',
   'plugins/solidigm/solidigm-market-log.c',
+  'plugins/solidigm/solidigm-temp-stats.c',
 ]
 subdir('solidigm-telemetry')
 
index b0db1ea2a4d67191e2802a53dd697fdf74ba63c9..a000f8eb9b108f45470e664f705c2d9661df5b55 100644 (file)
@@ -18,6 +18,7 @@
 #include "solidigm-telemetry.h"
 #include "solidigm-log-page-dir.h"
 #include "solidigm-market-log.h"
+#include "solidigm-temp-stats.h"
 
 #include "plugins/ocp/ocp-clear-fw-update-history.h"
 #include "plugins/ocp/ocp-smart-extended-log.h"
@@ -82,3 +83,8 @@ static int get_market_log(int argc, char **argv, struct command *cmd,
 {
        return sldgm_get_market_log(argc, argv, cmd, plugin);
 }
+
+static int get_temp_stats_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       return sldgm_get_temp_stats_log(argc, argv, cmd, plugin);
+}
index bc4a20170e6e91d926aceda291c0255f70879031..895c6720ac6f15467bc64dd32a3f8340e51ac556 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "cmd.h"
 
-#define SOLIDIGM_PLUGIN_VERSION "0.16"
+#define SOLIDIGM_PLUGIN_VERSION "0.17"
 
 PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_VERSION),
        COMMAND_LIST(
@@ -28,6 +28,7 @@ PLUGIN(NAME("solidigm", "Solidigm vendor specific extensions", SOLIDIGM_PLUGIN_V
                ENTRY("clear-fw-activate-history", "Clear firmware update history log (redirects to ocp plug-in)", clear_fw_update_history)
                ENTRY("vs-fw-activate-history", "Get firmware activation history log (redirects to ocp plug-in)", fw_activation_history)
                ENTRY("log-page-directory", "Retrieve log page directory", get_log_page_directory_log)
+               ENTRY("temp-stats", "Retrieve Temperature Statistics log", get_temp_stats_log)
        )
 );
 
diff --git a/plugins/solidigm/solidigm-temp-stats.c b/plugins/solidigm/solidigm-temp-stats.c
new file mode 100644 (file)
index 0000000..85a3c37
--- /dev/null
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Solidigm.
+ *
+ * Author: leonardo.da.cunha@solidigm.com
+ */
+
+#include <errno.h>
+
+#include "common.h"
+#include "nvme-print.h"
+#include "solidigm-util.h"
+
+#define SLDGM_TEMP_STATS_LID 0xC5
+
+struct temp_stats {
+       __le64  curr;
+       __le64  last_overtemp;
+       __le64  life_overtemp;
+       __le64  highest_temp;
+       __le64  lowest_temp;
+       __u8    rsvd[40];
+       __le64  max_operating_temp;
+       __le64  min_operating_temp;
+       __le64  est_offset;
+};
+
+static void show_temp_stats(struct temp_stats *stats)
+{
+       printf("Current temperature         : %"PRIu64"\n", le64_to_cpu(stats->curr));
+       printf("Last critical overtemp flag : %"PRIu64"\n", le64_to_cpu(stats->last_overtemp));
+       printf("Life critical overtemp flag : %"PRIu64"\n", le64_to_cpu(stats->life_overtemp));
+       printf("Highest temperature         : %"PRIu64"\n", le64_to_cpu(stats->highest_temp));
+       printf("Lowest temperature          : %"PRIu64"\n", le64_to_cpu(stats->lowest_temp));
+       printf("Max operating temperature   : %"PRIu64"\n", le64_to_cpu(stats->max_operating_temp));
+       printf("Min operating temperature   : %"PRIu64"\n", le64_to_cpu(stats->min_operating_temp));
+       printf("Estimated offset            : %"PRIu64"\n", le64_to_cpu(stats->est_offset));
+}
+
+int sldgm_get_temp_stats_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       unsigned char buffer[4096] = {0};
+       struct nvme_dev *dev;
+       __u8 uuid_idx;
+       int err;
+
+       const char *desc = "Get/show Temperature Statistics log.";
+       const char *raw = "dump output in binary format";
+       struct config {
+               bool  raw_binary;
+       };
+
+       struct config cfg = {
+               .raw_binary = false,
+       };
+
+       OPT_ARGS(opts) = {
+               OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
+               OPT_END()
+       };
+
+       err = parse_and_open(&dev, argc, argv, desc, opts);
+       if (err)
+               return err;
+
+       uuid_idx = solidigm_get_vu_uuid_index(dev);
+
+       struct nvme_get_log_args args = {
+               .lpo    = 0,
+               .result = NULL,
+               .log    = buffer,
+               .args_size = sizeof(args),
+               .fd     = dev_fd(dev),
+               .uuidx  = uuid_idx,
+               .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+               .lid    = SLDGM_TEMP_STATS_LID,
+               .len    = sizeof(buffer),
+               .nsid   = NVME_NSID_ALL,
+               .csi    = NVME_CSI_NVM,
+               .lsi    = NVME_LOG_LSI_NONE,
+               .lsp    = NVME_LOG_LSP_NONE,
+               .rae    = false,
+               .ot     = false,
+       };
+
+       err = nvme_get_log(&args);
+       if (!err) {
+               uint64_t *guid = (uint64_t *)&buffer[4080];
+
+               if (guid[1] == 0xC7BB98B7D0324863 && guid[0] == 0xBB2C23990E9C722F) {
+                       fprintf(stderr, "Error: Log page has 'OCP unsupported Requirements' GUID\n");
+                       err = -EBADMSG;
+                       goto closefd;
+               }
+               if (!cfg.raw_binary)
+                       show_temp_stats((struct temp_stats *) buffer);
+               else
+                       d_raw(buffer, sizeof(struct temp_stats));
+       } else if (err > 0) {
+               nvme_show_status(err);
+       }
+
+closefd:
+       /* Redundant close() to make static code analysis happy */
+       close(dev->direct.fd);
+       dev_close(dev);
+       return err;
+}
diff --git a/plugins/solidigm/solidigm-temp-stats.h b/plugins/solidigm/solidigm-temp-stats.h
new file mode 100644 (file)
index 0000000..58d5a86
--- /dev/null
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2023 Solidigm.
+ *
+ * Author: leonardo.da.cunha@solidigm.com
+ */
+
+int sldgm_get_temp_stats_log(int argc, char **argv, struct command *cmd, struct plugin *plugin);