]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Extended SMART log parsing support
authorHanumanthu H <hanumanthuh@micron.com>
Fri, 1 Oct 2021 04:55:12 +0000 (10:25 +0530)
committerHanumanthu H <hanumanthuh@micron.com>
Fri, 1 Oct 2021 04:55:12 +0000 (10:25 +0530)
plugins/micron/micron-nvme.c
plugins/micron/micron-nvme.h

index 6665a0e117be25dc1a5cc4b2d9993d1d7f9a2236..b9abd446540e971014f7f4e4c9517bd23c83179b 100644 (file)
@@ -30,6 +30,7 @@
 #define C2_log_size 4096
 #define D0_log_size 512
 #define FB_log_size 512
+#define E1_log_size 256
 #define MaxLogChunk 16 * 1024
 #define CommonChunkSize 16 * 4096
 
@@ -39,7 +40,7 @@
 /* Plugin version major_number.minor_number.patch */
 static const char *__version_major = "1";
 static const char *__version_minor = "0";
-static const char *__version_patch = "6";
+static const char *__version_patch = "7";
 
 /* supported models of micron plugin; new models should be added at the end
  * before UNKNOWN_MODEL. Make sure M5410 is first in the list !
@@ -1096,6 +1097,36 @@ ocp_c0_log_page[] = {
     { "Log Page Version", 2},
     { "Log Page GUID", 16},
 },
+/* Extended SMART log information */
+e1_log_page[] = {
+    { "Reserved", 12},
+    { "Grown Bad Block Count", 4},
+    { "Per Block Max Erase Count", 4},
+    { "Power On Minutes", 4},
+    { "Reserved", 24},
+    { "Write Protect Reason", 4},
+    { "Reserved", 12},
+    { "Drive Capacity", 8},
+    { "Reserved", 8},
+    { "Total Erase Count", 8},
+    { "Lifetime Use Rate", 8},
+    { "Erase Fail Count", 8},
+    { "Reserved", 8},
+    { "Reported UC Errors", 8},
+    { "Reserved", 24},
+    { "Program Fail Count", 16},
+    { "Total Bytes Read", 16},
+    { "Total Bytes Written", 16},
+    { "Reserved", 16},
+    { "TU Size", 4},
+    { "Total Block Stripe Count", 4},
+    { "Free Block Stripe Count", 4},
+    { "Block Stripe Size", 8},
+    { "Reserved", 16},
+    { "User Block Min Erase Count", 4},
+    { "User Block Avg Erase Count", 4},
+    { "User Block Max Erase Count", 4},
+},
 /* Vendor Specific Health Log information */
 fb_log_page[] = {
     { "Physical Media Units Written - TLC",  16, 16 },
@@ -1365,7 +1396,8 @@ static int micron_nand_stats(int argc, char **argv,
 
     /* pull log details based on the model name */
     sscanf(argv[optind], "/dev/nvme%d", &ctrlIdx);
-    if ((eModel = GetDriveModel(ctrlIdx)) == UNKNOWN_MODEL) {
+    eModel = GetDriveModel(ctrlIdx);
+    if ((eModel == UNKNOWN_MODEL) || (eModel == M51CX)) {
         printf ("Unsupported drive model for vs-nand-stats command\n");
        err = -1;
         goto out;
@@ -1401,6 +1433,78 @@ out:
     return nvme_status_to_errno(err, false);
 }
 
+static void print_ext_smart_logs_e1(__u8 *buf, bool is_json)
+{
+    struct json_object *root;
+    struct json_object *logPages;
+    struct json_object *stats = NULL;
+    int    field_count = sizeof(e1_log_page)/sizeof(e1_log_page[0]);
+
+    if (is_json) {
+        root = json_create_object();
+        stats = json_create_object();
+        logPages = json_create_array();
+        json_object_add_value_array(root, "SMART Extended Log:0xE1", logPages);
+    }
+    else {
+        printf("SMART Extended Log:0xE1\n");
+    }
+
+    print_micron_vs_logs(buf, e1_log_page, field_count, stats, 0);
+
+    if (is_json) {
+        json_array_add_value_object(logPages, stats);
+        json_print_object(root, NULL);
+        printf("\n");
+        json_free_object(root);
+    }
+}
+
+static int micron_smart_ext_log(int argc, char **argv,
+                                struct command *cmd, struct plugin *plugin)
+{
+    const char *desc = "Retrieve extended SMART logs for the given device ";
+    unsigned int extSmartLog[E1_log_size/sizeof(int)] = { 0 };
+    eDriveModel eModel = UNKNOWN_MODEL;
+    int fd = 0, err = 0, ctrlIdx = 0;
+    bool is_json = true;
+    struct format {
+        char *fmt;
+    };
+    const char *fmt = "output format json|normal";
+    struct format cfg = {
+        .fmt = "json",
+    };
+    OPT_ARGS(opts) = {
+        OPT_FMT("format", 'f', &cfg.fmt, fmt),
+        OPT_END()
+    };
+
+    fd = parse_and_open(argc, argv, desc, opts);
+    if (fd < 0) {
+        printf("\nDevice not found \n");;
+        return -1;
+    }
+    if (strcmp(cfg.fmt, "normal") == 0)
+        is_json = false;
+
+    sscanf(argv[optind], "/dev/nvme%d", &ctrlIdx);
+    if ((eModel = GetDriveModel(ctrlIdx)) != M51CX) {
+        printf ("Unsupported drive model for vs-smart-ext-log command\n");
+        err = -1;
+        goto out;
+    }
+    err = nvme_get_log_simple(fd, 0xE1, E1_log_size, extSmartLog);
+    if (!err) {
+        print_ext_smart_logs_e1((__u8 *)extSmartLog, is_json);
+    }
+
+out:
+    close(fd);
+    if (err > 0)
+        nvme_show_status(err);
+    return nvme_status_to_errno(err, false);
+}
 
 static void GetDriveInfo(const char *strOSDirName, int nFD,
                          struct nvme_id_ctrl *ctrlp)
index 118f8cdfcc56e5993e8710e96add9f709d97948e..1156973a4974dc8739791f2431de3c32db0a3794 100644 (file)
@@ -12,8 +12,9 @@ PLUGIN(NAME("micron", "Micron vendor specific extensions"),
                ENTRY("vs-pcie-stats", "Retrieve Micron PCIe error stats", micron_pcie_stats)
                ENTRY("clear-pcie-correctable-errors", "Clear correctable PCIe errors", micron_clear_pcie_correctable_errors)
                ENTRY("vs-internal-log", "Retrieve Micron logs", micron_internal_logs)
-               ENTRY("vs-telemetry-controller-option", "Enable/Disable controller telemetry log generation", micron_telemetry_cntrl_option)
+               ENTRY("vs-telemetry-controller-option", "Enable/Disable controller telemetry log generation", micron_telemetry_cntrl_option)
                ENTRY("vs-nand-stats", "Retrieve NAND Stats", micron_nand_stats)
+               ENTRY("vs-smart-ext-log", "Retrieve extended SMART logs", micron_smart_ext_log)
                ENTRY("vs-drive-info", "Retrieve Drive information", micron_drive_info)
                ENTRY("plugin-version", "Display plugin version info", micron_plugin_version)
                ENTRY("cloud-SSD-plugin-version", "Display plugin version info", micron_cloud_ssd_plugin_version)