]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
[Add] Transcend plugin command
authorvictor_chen <victor_chen@transcend-info.com>
Thu, 19 Mar 2020 07:48:51 +0000 (15:48 +0800)
committerKeith Busch <kbusch@kernel.org>
Thu, 23 Apr 2020 20:13:14 +0000 (14:13 -0600)
Documentation/nvme-transcend-badblock.txt [new file with mode: 0644]
Documentation/nvme-transcend-healthvalue.txt [new file with mode: 0644]
Makefile
plugins/transcend/transcend-nvme.c [new file with mode: 0644]
plugins/transcend/transcend-nvme.h [new file with mode: 0644]

diff --git a/Documentation/nvme-transcend-badblock.txt b/Documentation/nvme-transcend-badblock.txt
new file mode 100644 (file)
index 0000000..bdb4992
--- /dev/null
@@ -0,0 +1,37 @@
+nvme-transcend-badblock(1)
+=================
+
+NAME
+----
+nvme-transcend-badblock - Retrieve Transcend NVMe device's bad blocks.
+
+SYNOPSIS
+--------
+[verse]
+'nvme transcend badblock' <device> 
+
+DESCRIPTION
+-----------
+For the NVMe device given, sends the Transcend vendor command and return the bad block of the device.
+
+The <device> parameter is mandatory and may be either the NVMe character
+device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
+
+On success, the returned value would print the amount of bad blocks.
+
+OPTIONS
+-------
+none
+
+
+EXAMPLES
+--------
+* Print the Transcend device's bad blocks in a human readable format:
++
+------------
+# nvme transcend badblock /dev/nvme0
+------------
+
+NVME
+----
+Part of the nvme-user suite
diff --git a/Documentation/nvme-transcend-healthvalue.txt b/Documentation/nvme-transcend-healthvalue.txt
new file mode 100644 (file)
index 0000000..c2047ef
--- /dev/null
@@ -0,0 +1,37 @@
+nvme-transcend-healthvalue(1)
+=================
+
+NAME
+----
+nvme-transcend-healthvalue - Use NVMe SMART table to analyse the health value of Transcend device.
+
+SYNOPSIS
+--------
+[verse]
+'nvme transcned healthvalue' <device> 
+
+DESCRIPTION
+-----------
+Retrieves the NVMe Device SMART log page from the Transcend device and evaluate health status of Transcend device.
+
+The <device> parameter is mandatory and may be either the NVMe character
+device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
+
+On success, the returned value would print health percentage value.
+
+OPTIONS
+-------
+none
+
+
+EXAMPLES
+--------
+* Print the Transcend Device health value in a human readable format:
++
+------------
+# nvme transcned healthvalue /dev/nvme0
+------------
+
+NVME
+----
+Part of the nvme-user suite
index 5c5c8b21471e403bf80a73a900455ebcfed5b9cb..1a1753ebb83f4ad6d0d1d1cc6d3de7bda745c3d6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -76,7 +76,8 @@ PLUGIN_OBJS :=                                        \
        plugins/seagate/seagate-nvme.o          \
        plugins/virtium/virtium-nvme.o          \
        plugins/shannon/shannon-nvme.o          \
-       plugins/dera/dera-nvme.o
+       plugins/dera/dera-nvme.o            \
+    plugins/transcend/transcend-nvme.o
 
 nvme: nvme.c nvme.h $(OBJS) $(PLUGIN_OBJS) $(UTIL_OBJS) NVME-VERSION-FILE
        $(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) $(INC) $< -o $(NVME) $(OBJS) $(PLUGIN_OBJS) $(UTIL_OBJS) $(LDFLAGS)
diff --git a/plugins/transcend/transcend-nvme.c b/plugins/transcend/transcend-nvme.c
new file mode 100644 (file)
index 0000000..550eb31
--- /dev/null
@@ -0,0 +1,92 @@
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include "linux/nvme_ioctl.h"
+#include "nvme.h"
+#include "nvme-print.h"
+#include "nvme-ioctl.h"
+#include "plugin.h"
+#include "argconfig.h"
+#include "suffix.h"
+
+#define CREATE_CMD
+#include "transcend-nvme.h"
+
+static const __u32 OP_BAD_BLOCK = 0xc2;
+static const __u32 DW10_BAD_BLOCK = 0x400;
+static const __u32 DW12_BAD_BLOCK = 0x5a;
+
+static int getHealthValue(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+       struct nvme_smart_log smart_log;
+       char *desc = "Get nvme health percentage.";
+       int result=0, fd;
+       int  percent_used = 0, healthvalue=0;
+        
+       OPT_ARGS(opts) = {
+               OPT_END()
+       };
+
+       fd = parse_and_open(argc, argv, desc, opts);
+        
+       if (fd < 0) {
+               printf("\nDevice not found \n");;
+               return -1;
+       }
+       result = nvme_smart_log(fd, 0xffffffff, &smart_log);
+       if (!result) {
+               printf("Transcend NVME heath value: ");
+               percent_used =smart_log.percent_used;
+               
+               if(percent_used>100 || percent_used<0)
+               {
+                       printf("0%%\n");
+               }
+               else
+               {
+                       healthvalue = 100 - percent_used;
+                       printf("%d%%\n",healthvalue);
+               }
+                        
+       }
+
+       return result;
+}
+
+static int getBadblock(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+
+       char *desc = "Get nvme bad block number.";
+       int result=0, fd;
+       OPT_ARGS(opts) = {
+                
+               OPT_END()
+       };
+
+       fd = parse_and_open(argc, argv, desc, opts);
+       if (fd < 0) {
+               printf("\nDevice not found \n");;
+               return -1;
+       }
+       unsigned char data[1]={0};
+       struct nvme_passthru_cmd nvmecmd;
+       memset(&nvmecmd,0,sizeof(nvmecmd));
+       nvmecmd.opcode=OP_BAD_BLOCK;
+       nvmecmd.cdw10=DW10_BAD_BLOCK;
+       nvmecmd.cdw12=DW12_BAD_BLOCK;
+       nvmecmd.addr =(__u64) data;
+       nvmecmd.data_len = 0x1;
+       result = nvme_submit_admin_passthru(fd,&nvmecmd);
+       if(!result) {
+               int badblock  = data[0];
+               printf("Transcend NVME badblock count: %d\n",badblock);
+       }
+
+       return result;
+}
diff --git a/plugins/transcend/transcend-nvme.h b/plugins/transcend/transcend-nvme.h
new file mode 100644 (file)
index 0000000..14d62ec
--- /dev/null
@@ -0,0 +1,20 @@
+#undef CMD_INC_FILE
+#define CMD_INC_FILE plugins/transcend/transcend-nvme
+
+#if !defined(TRANSCEND_NVME) || defined(CMD_HEADER_MULTI_READ)
+#define TRANSCEND_NVME
+
+#include "cmd.h"
+
+PLUGIN(NAME("transcend", "Transcend vendor specific extensions"),
+    COMMAND_LIST(
+                       ENTRY("healthvalue", "NVME health percentage", getHealthValue)
+                       ENTRY("badblock", "Get NVME bad block number", getBadblock)
+    )
+);
+
+#endif
+
+#include "define_cmd.h"