summaryrefslogtreecommitdiffstats
path: root/plugins/seagate/seagate-nvme.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-14 18:27:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-16 15:11:56 +0000
commit6197903bd42478987516bc4cc3f0769488a37065 (patch)
tree508d399340039960289dd1d96696db7c56c22321 /plugins/seagate/seagate-nvme.c
parentAdding upstream version 1.16. (diff)
downloadnvme-cli-6197903bd42478987516bc4cc3f0769488a37065.tar.xz
nvme-cli-6197903bd42478987516bc4cc3f0769488a37065.zip
Adding upstream version 2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/seagate/seagate-nvme.c')
-rw-r--r--plugins/seagate/seagate-nvme.c140
1 files changed, 82 insertions, 58 deletions
diff --git a/plugins/seagate/seagate-nvme.c b/plugins/seagate/seagate-nvme.c
index 9512cda..5f6ce90 100644
--- a/plugins/seagate/seagate-nvme.c
+++ b/plugins/seagate/seagate-nvme.c
@@ -26,16 +26,14 @@
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
-#include <sys/ioctl.h>
#include <sys/stat.h>
#include <ctype.h>
-#include "linux/nvme_ioctl.h"
+#include "common.h"
#include "nvme.h"
-#include "nvme-print.h"
-#include "nvme-ioctl.h"
+#include "libnvme.h"
#include "plugin.h"
-#include "argconfig.h"
-#include "suffix.h"
+#include "linux/types.h"
+#include "nvme-print.h"
#define CREATE_CMD
@@ -176,8 +174,7 @@ static int log_pages_supp(int argc, char **argv, struct command *cmd,
};
fd = parse_and_open(argc, argv, desc, opts);
- err = nvme_get_log(fd, 1, 0xc5, false, NVME_NO_LOG_LSP,
- sizeof(logPageMap), &logPageMap);
+ err = nvme_get_log_simple(fd, 0xc5, sizeof(logPageMap), &logPageMap);
if (!err) {
if (strcmp(cfg.output_format,"json")) {
printf ("Seagate Supported Log-pages count :%d\n",
@@ -201,8 +198,7 @@ static int log_pages_supp(int argc, char **argv, struct command *cmd,
}
if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;
}
@@ -739,8 +735,7 @@ static int vs_smart_log(int argc, char **argv, struct command *cmd, struct plugi
if (strcmp(cfg.output_format,"json"))
printf("Seagate Extended SMART Information :\n");
- err = nvme_get_log(fd, 1, 0xC4, false, NVME_NO_LOG_LSP,
- sizeof(ExtdSMARTInfo), &ExtdSMARTInfo);
+ err = nvme_get_log_simple(fd, 0xC4, sizeof(ExtdSMARTInfo), &ExtdSMARTInfo);
if (!err) {
if (strcmp(cfg.output_format,"json")) {
printf("%-39s %-15s %-19s \n", "Description", "Ext-Smart-Id", "Ext-Smart-Value");
@@ -762,8 +757,7 @@ static int vs_smart_log(int argc, char **argv, struct command *cmd, struct plugi
* Next get Log Page 0xCF
*/
- err = nvme_get_log(fd, 1, 0xCF, false, NVME_NO_LOG_LSP,
- sizeof(logPageCF), &logPageCF);
+ err = nvme_get_log_simple(fd, 0xCF, sizeof(logPageCF), &logPageCF);
if (!err) {
if(strcmp(cfg.output_format,"json")) {
/*printf("Seagate DRAM Supercap SMART Attributes :\n");*/
@@ -778,8 +772,7 @@ static int vs_smart_log(int argc, char **argv, struct command *cmd, struct plugi
} else if (!strcmp(cfg.output_format, "json"))
json_print_object(root, NULL);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;
}
@@ -844,7 +837,7 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
if(strcmp(cfg.output_format,"json"))
printf("Seagate Temperature Stats Information :\n");
/*STEP-1 : Get Current Temperature from SMART */
- err = nvme_smart_log(fd, 0xffffffff, &smart_log);
+ err = nvme_get_log_smart(fd, 0xffffffff, true, &smart_log);
if (!err) {
temperature = ((smart_log.temperature[1] << 8) | smart_log.temperature[0]);
temperature = temperature ? temperature - 273 : 0;
@@ -860,8 +853,7 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
}
/* STEP-2 : Get Max temperature form Ext SMART-id 194 */
- err = nvme_get_log(fd, 1, 0xC4, false, NVME_NO_LOG_LSP,
- sizeof(ExtdSMARTInfo), &ExtdSMARTInfo);
+ err = nvme_get_log_simple(fd, 0xC4, sizeof(ExtdSMARTInfo), &ExtdSMARTInfo);
if (!err) {
for(index = 0; index < NUMBER_EXTENDED_SMART_ATTRIBUTES; index++) {
if (ExtdSMARTInfo.vendorData[index].AttributeNumber == VS_ATTR_ID_MAX_LIFE_TEMPERATURE) {
@@ -880,11 +872,9 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin
}
}
else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
- cf_err = nvme_get_log(fd, 1, 0xCF, false, NVME_NO_LOG_LSP,
- sizeof(ExtdSMARTInfo), &logPageCF);
+ cf_err = nvme_get_log_simple(fd, 0xCF, sizeof(ExtdSMARTInfo), &logPageCF);
if(!cf_err) {
scCurrentTemp = logPageCF.AttrCF.SuperCapCurrentTemperature;
@@ -1013,8 +1003,7 @@ static int vs_pcie_error_log(int argc, char **argv, struct command *cmd, struct
if(strcmp(cfg.output_format,"json"))
printf("Seagate PCIe error counters Information :\n");
- err = nvme_get_log(fd, 1, 0xCB, false, NVME_NO_LOG_LSP,
- sizeof(pcieErrorLog), &pcieErrorLog);
+ err = nvme_get_log_simple(fd, 0xCB, sizeof(pcieErrorLog), &pcieErrorLog);
if (!err) {
if(strcmp(cfg.output_format,"json")) {
print_vs_pcie_error_log(pcieErrorLog);
@@ -1022,7 +1011,7 @@ static int vs_pcie_error_log(int argc, char **argv, struct command *cmd, struct
json_vs_pcie_error_log(pcieErrorLog);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
+ nvme_show_status(err);
return err;
}
@@ -1034,10 +1023,9 @@ static int vs_clr_pcie_correctable_errs(int argc, char **argv, struct command *c
const char *save = "specifies that the controller shall save the attribute";
int err, fd;
__u32 result;
- void *buf = NULL;
struct config {
- int save;
+ bool save;
};
struct config cfg = {
@@ -1051,7 +1039,7 @@ static int vs_clr_pcie_correctable_errs(int argc, char **argv, struct command *c
fd = parse_and_open(argc, argv, desc, opts);
- err = nvme_set_feature(fd, 0, 0xE1, 0xCB, 0, cfg.save, 0, 0, buf, &result);
+ err = nvme_set_features_simple(fd, 0xE1, 0, 0xCB, cfg.save, &result);
if (err < 0) {
perror("set-feature");
@@ -1080,7 +1068,7 @@ static int get_host_tele(int argc, char **argv, struct command *cmd, struct plug
struct config {
__u32 namespace_id;
__u32 log_id;
- int raw_binary;
+ bool raw_binary;
};
struct config cfg = {
@@ -1101,8 +1089,7 @@ static int get_host_tele(int argc, char **argv, struct command *cmd, struct plug
dump_fd = STDOUT_FILENO;
cfg.log_id = (cfg.log_id << 8) | 0x07;
- err = nvme_get_log13(fd, cfg.namespace_id, cfg.log_id,
- NVME_NO_LOG_LSP, offset, 0, false,
+ err = nvme_get_nsid_log(fd, false, cfg.log_id, cfg.namespace_id,
sizeof(tele_log), (void *)(&tele_log));
if (!err) {
maxBlk = tele_log.tele_data_area3;
@@ -1119,8 +1106,7 @@ static int get_host_tele(int argc, char **argv, struct command *cmd, struct plug
} else
seaget_d_raw((unsigned char *)(&tele_log), sizeof(tele_log), dump_fd);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
else
perror("log page");
@@ -1141,9 +1127,24 @@ static int get_host_tele(int argc, char **argv, struct command *cmd, struct plug
memset(log, 0, blksToGet * 512);
- err = nvme_get_log13(fd, cfg.namespace_id, cfg.log_id,
- NVME_NO_LOG_LSP, offset, 0, false,
- blksToGet * 512, (void *)log);
+ struct nvme_get_log_args args = {
+ .args_size = sizeof(args),
+ .fd = fd,
+ .lid = cfg.log_id,
+ .nsid = cfg.namespace_id,
+ .lpo = offset,
+ .lsp = 0,
+ .lsi = 0,
+ .rae = true,
+ .uuidx = 0,
+ .csi = NVME_CSI_NVM,
+ .ot = false,
+ .len = blksToGet * 512,
+ .log = (void *)log,
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .result = NULL,
+ };
+ err = nvme_get_log(&args);
if (!err) {
offset += blksToGet * 512;
@@ -1154,8 +1155,7 @@ static int get_host_tele(int argc, char **argv, struct command *cmd, struct plug
} else
seaget_d_raw((unsigned char *)log, blksToGet * 512, dump_fd);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
else
perror("log page");
@@ -1182,7 +1182,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *cmd, struct plug
struct config {
__u32 namespace_id;
- int raw_binary;
+ bool raw_binary;
};
struct config cfg = {
@@ -1202,8 +1202,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *cmd, struct plug
dump_fd = STDOUT_FILENO;
log_id = 0x08;
- err = nvme_get_log13(fd, cfg.namespace_id, log_id,
- NVME_NO_LOG_LSP, offset, 0, false,
+ err = nvme_get_nsid_log(fd, false, log_id, cfg.namespace_id,
sizeof(tele_log), (void *)(&tele_log));
if (!err) {
maxBlk = tele_log.tele_data_area3;
@@ -1219,8 +1218,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *cmd, struct plug
} else
seaget_d_raw((unsigned char *)(&tele_log), sizeof(tele_log), dump_fd);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
else
perror("log page");
@@ -1241,9 +1239,24 @@ static int get_ctrl_tele(int argc, char **argv, struct command *cmd, struct plug
memset(log, 0, blksToGet * 512);
- err = nvme_get_log13(fd, cfg.namespace_id, log_id,
- NVME_NO_LOG_LSP, offset, 0, false,
- blksToGet * 512, (void *)log);
+ struct nvme_get_log_args args = {
+ .args_size = sizeof(args),
+ .fd = fd,
+ .lid = log_id,
+ .nsid = cfg.namespace_id,
+ .lpo = offset,
+ .lsp = 0,
+ .lsi = 0,
+ .rae = true,
+ .uuidx = 0,
+ .csi = NVME_CSI_NVM,
+ .ot = false,
+ .len = blksToGet * 512,
+ .log = (void *)log,
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .result = NULL,
+ };
+ err = nvme_get_log(&args);
if (!err) {
offset += blksToGet * 512;
@@ -1254,8 +1267,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *cmd, struct plug
} else
seaget_d_raw((unsigned char *)log, blksToGet * 512, dump_fd);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
else
perror("log page");
@@ -1327,8 +1339,7 @@ static int vs_internal_log(int argc, char **argv, struct command *cmd, struct pl
}
log_id = 0x08;
- err = nvme_get_log13(fd, cfg.namespace_id, log_id,
- NVME_NO_LOG_LSP, offset, 0, false,
+ err = nvme_get_nsid_log(fd, false, log_id, cfg.namespace_id,
sizeof(tele_log), (void *)(&tele_log));
if (!err) {
maxBlk = tele_log.tele_data_area3;
@@ -1340,8 +1351,7 @@ static int vs_internal_log(int argc, char **argv, struct command *cmd, struct pl
*/
seaget_d_raw((unsigned char *)(&tele_log), sizeof(tele_log), dump_fd);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
else
perror("log page");
@@ -1363,17 +1373,31 @@ static int vs_internal_log(int argc, char **argv, struct command *cmd, struct pl
memset(log, 0, blksToGet * 512);
- err = nvme_get_log13(fd, cfg.namespace_id, log_id,
- NVME_NO_LOG_LSP, offset, 0, false,
- blksToGet * 512, (void *)log);
+ struct nvme_get_log_args args = {
+ .args_size = sizeof(args),
+ .fd = fd,
+ .lid = log_id,
+ .nsid = cfg.namespace_id,
+ .lpo = offset,
+ .lsp = 0,
+ .lsi = 0,
+ .rae = true,
+ .uuidx = 0,
+ .csi = NVME_CSI_NVM,
+ .ot = false,
+ .len = blksToGet * 512,
+ .log = (void *)log,
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .result = NULL,
+ };
+ err = nvme_get_log(&args);
if (!err) {
offset += blksToGet * 512;
seaget_d_raw((unsigned char *)log, blksToGet * 512, dump_fd);
} else if (err > 0)
- fprintf(stderr, "NVMe Status:%s(%x)\n",
- nvme_status_to_string(err), err);
+ nvme_show_status(err);
else
perror("log page");