From 1cc8413aaf5f8fa6595aece1933462c096e88639 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 29 Apr 2024 06:41:05 +0200 Subject: Adding upstream version 2.4+really2.3. Signed-off-by: Daniel Baumann --- plugins/transcend/transcend-nvme.c | 90 ++++++++++++++++++++++++++++++++++++++ plugins/transcend/transcend-nvme.h | 21 +++++++++ 2 files changed, 111 insertions(+) create mode 100644 plugins/transcend/transcend-nvme.c create mode 100644 plugins/transcend/transcend-nvme.h (limited to 'plugins/transcend') diff --git a/plugins/transcend/transcend-nvme.c b/plugins/transcend/transcend-nvme.c new file mode 100644 index 0000000..024351f --- /dev/null +++ b/plugins/transcend/transcend-nvme.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include +#include +#include +#include +#include + +#include "nvme.h" +#include "libnvme.h" +#include "plugin.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 percent_used = 0, healthvalue=0; + struct nvme_dev *dev; + int result; + + OPT_ARGS(opts) = { + OPT_END() + }; + + result = parse_and_open(&dev, argc, argv, desc, opts); + if (result) { + printf("\nDevice not found \n");; + return -1; + } + result = nvme_get_log_smart(dev_fd(dev), 0xffffffff, false, &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); + } + + } + dev_close(dev); + return result; +} + + +static int getBadblock(int argc, char **argv, struct command *cmd, struct plugin *plugin) +{ + + char *desc = "Get nvme bad block number."; + struct nvme_dev *dev; + int result; + + OPT_ARGS(opts) = { + + OPT_END() + }; + + result = parse_and_open(&dev, argc, argv, desc, opts); + if (result) { + 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)(uintptr_t)data; + nvmecmd.data_len = 0x1; + result = nvme_submit_admin_passthru(dev_fd(dev), &nvmecmd, NULL); + if(!result) { + int badblock = data[0]; + printf("Transcend NVME badblock count: %d\n",badblock); + } + dev_close(dev); + return result; +} diff --git a/plugins/transcend/transcend-nvme.h b/plugins/transcend/transcend-nvme.h new file mode 100644 index 0000000..9c89883 --- /dev/null +++ b/plugins/transcend/transcend-nvme.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#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", NVME_VERSION), + COMMAND_LIST( + ENTRY("healthvalue", "NVME health percentage", getHealthValue) + ENTRY("badblock", "Get NVME bad block number", getBadblock) + + ) +); + +#endif + +#include "define_cmd.h" -- cgit v1.2.3