]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
[NVMe-CLI] Add clear-fw-activate-history WDC plugin command
authorJeff Lien <jeff.lien@wdc.com>
Thu, 10 Oct 2019 20:56:01 +0000 (15:56 -0500)
committerJeff Lien <jeff.lien@wdc.com>
Fri, 11 Oct 2019 21:18:32 +0000 (16:18 -0500)
plugins/wdc/wdc-nvme.c
plugins/wdc/wdc-nvme.h

index 7ede9b7831e0793b021c9ae167130a98a3a1a1b0..25ab1154c8015fe2b5d5ff032c1386e89b8c58de 100644 (file)
@@ -90,6 +90,7 @@
 #define WDC_DRIVE_CAP_CRASH_DUMP                       0x0000000000000800
 #define WDC_DRIVE_CAP_PFAIL_DUMP                       0x0000000000001000
 #define WDC_DRIVE_CAP_FW_ACTIVATE_HISTORY   0x0000000000002000
+#define WDC_DRIVE_CAP_CLEAR_FW_ACT_HISTORY  0x0000000000004000
 
 #define WDC_DRIVE_CAP_DRIVE_ESSENTIALS      0x0000000100000000
 #define WDC_DRIVE_CAP_DUI_DATA                         0x0000000200000000
 #define WDC_NVME_CLEAR_CRASH_DUMP_SUBCMD               0x05
 #define WDC_NVME_CLEAR_PF_CRASH_DUMP_SUBCMD            0x06
 
+/* Clear FW Activate History */
+#define WDC_NVME_CLEAR_FW_ACT_HIST_OPCODE       0xC6
+#define WDC_NVME_CLEAR_FW_ACT_HIST_CMD                 0x23
+#define WDC_NVME_CLEAR_FW_ACT_HIST_SUBCMD              0x05
+
 /* Additional Smart Log */
 #define WDC_ADD_LOG_BUF_LEN                            0x4000
 #define WDC_NVME_ADD_LOG_OPCODE                                0xC1
@@ -805,7 +811,7 @@ static __u64 wdc_get_drive_capabilities(int fd) {
                        capabilities = (WDC_DRIVE_CAP_CAP_DIAG | WDC_DRIVE_CAP_INTERNAL_LOG |
                                        WDC_DRIVE_CAP_DRIVE_STATUS | WDC_DRIVE_CAP_CLEAR_ASSERT |
                                        WDC_DRIVE_CAP_RESIZE | WDC_DRIVE_CAP_CLEAR_PCIE |
-                                       WDC_DRIVE_CAP_FW_ACTIVATE_HISTORY);
+                                       WDC_DRIVE_CAP_FW_ACTIVATE_HISTORY | WDC_DRIVE_CAP_CLEAR_FW_ACT_HISTORY);
 
                        /* verify the 0xCA log page is supported */
                        if (wdc_nvme_check_supported_log_page(fd, WDC_NVME_GET_DEVICE_INFO_LOG_OPCODE) == true)
@@ -3442,6 +3448,42 @@ static int wdc_vs_fw_activate_history(int argc, char **argv, struct command *com
        return ret;
 }
 
+static int wdc_clear_fw_activate_history(int argc, char **argv, struct command *command,
+               struct plugin *plugin)
+{
+       char *desc = "Clear FW activate history table.";
+       int fd;
+       int ret = -1;
+       __u64 capabilities = 0;
+       struct nvme_passthru_cmd admin_cmd;
+
+       OPT_ARGS(opts) = {
+               OPT_END()
+       };
+
+       fd = parse_and_open(argc, argv, desc, opts, NULL, 0);
+       if (fd < 0)
+               return fd;
+
+       capabilities = wdc_get_drive_capabilities(fd);
+       if ((capabilities & WDC_DRIVE_CAP_CLEAR_FW_ACT_HISTORY) != WDC_DRIVE_CAP_CLEAR_FW_ACT_HISTORY) {
+               fprintf(stderr, "ERROR : WDC: unsupported device for this command\n");
+               ret = -1;
+               goto out;
+       }
+
+       memset(&admin_cmd, 0, sizeof (admin_cmd));
+       admin_cmd.opcode = WDC_NVME_CLEAR_FW_ACT_HIST_OPCODE;
+       admin_cmd.cdw12 = ((WDC_NVME_CLEAR_FW_ACT_HIST_SUBCMD << WDC_NVME_SUBCMD_SHIFT) |
+                       WDC_NVME_CLEAR_FW_ACT_HIST_CMD);
+
+       ret = nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD, &admin_cmd);
+       fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret);
+
+out:
+       return ret;
+}
+
 static int wdc_get_serial_and_fw_rev(int fd, char *sn, char *fw_rev)
 {
        int i;
index 5dce4b1df84f84dc9748f122b36f953d04b2a4b9..3b6d5fc6b3c0c169230f6a3355d52b931acf9e0f 100644 (file)
@@ -24,6 +24,7 @@ PLUGIN(NAME("wdc", "Western Digital vendor specific extensions"),
                ENTRY("clear-assert-dump", "WDC Clear Assert Dump", wdc_clear_assert_dump)
                ENTRY("drive-resize", "WDC Drive Resize", wdc_drive_resize)
                ENTRY("vs-fw-activate-history", "WDC Get FW Activate History", wdc_vs_fw_activate_history)
+               ENTRY("clear-fw-activate-history", "WDC Clear FW Activate History", wdc_clear_fw_activate_history)
        )
 );