1
0
Fork 0

Adding upstream version 2.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-16 12:15:30 +01:00
parent 50aec1e4c5
commit 1b3a431c1d
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
521 changed files with 21541 additions and 21644 deletions

View file

@ -5,15 +5,11 @@
#include <unistd.h>
#include <time.h>
#include "linux/nvme_ioctl.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
#include "memblaze-nvme.h"
@ -79,22 +75,19 @@ static int compare_fw_version(const char *fw1, const char *fw2)
#define STR_VER_SIZE (5)
int getlogpage_format_type(char *fw_ver)
int getlogpage_format_type(char *model_name)
{
char fw_ver_local[STR_VER_SIZE];
strncpy(fw_ver_local, fw_ver, STR_VER_SIZE);
*(fw_ver_local + STR_VER_SIZE - 1) = '\0';
if ( IS_RAISIN(fw_ver_local)
|| IS_KUMQUAT(fw_ver_local)
|| IS_LOQUAT(fw_ver_local)
)
int logpage_format_type = INTEL_FORMAT;
const char *boundary_model_name1 = "P"; // MEMBLAZE P7936DT0640M00
const char *boundary_model_name2 = "P5920"; // Use INTEL_FORMAT from Raisin P5920.
if (0 == strncmp(model_name, boundary_model_name1, strlen(boundary_model_name1)))
{
return INTEL_FORMAT;
}
else
{
return MEMBLAZE_FORMAT;
if (strncmp(model_name, boundary_model_name2, strlen(boundary_model_name2)) < 0)
{
logpage_format_type = MEMBLAZE_FORMAT;
}
}
return logpage_format_type;
}
static __u32 item_id_2_u32(struct nvme_memblaze_smart_log_item *item)
@ -232,8 +225,6 @@ static void show_memblaze_smart_log_new(struct nvme_memblaze_smart_log *s,
printf("%-32s: %3d%% %s%u%s%u%s%u\n", STR17_01, *nm, STR17_03, *raw,
STR17_04, *(raw+2), STR17_05, *(raw+4));
/* 18 RAISIN_SI_VD_POWER_LOSS_PROTECTION */
get_memblaze_new_smart_info(smart, RAISIN_SI_VD_POWER_LOSS_PROTECTION, nm, raw);
printf("%-32s: %3d%% %"PRIu64"\n", STR18_01, *nm, int48_to_long(raw));
/* 19 RAISIN_SI_VD_READ_FAIL */
get_memblaze_new_smart_info(smart, RAISIN_SI_VD_READ_FAIL, nm, raw);
printf("%-32s: %3d%% %"PRIu64"\n", STR19_01, *nm, int48_to_long(raw));
@ -392,7 +383,7 @@ static int show_memblaze_smart_log(int fd, __u32 nsid, const char *devname,
ctrl.fr[0], ctrl.fr[1], ctrl.fr[2], ctrl.fr[3],
ctrl.fr[4], ctrl.fr[5], ctrl.fr[6]);
if (getlogpage_format_type(fw_ver)) // Intel Format & new format
if (getlogpage_format_type(ctrl.mn)) // Intel Format & new format
{
show_memblaze_smart_log_new(smart, nsid, devname);
}
@ -419,7 +410,7 @@ int parse_params(char *str, int number, ...)
exit(EINVAL);
}
if (isalnum(*c) == 0) {
if (isalnum((int)*c) == 0) {
printf("%s is not a valid number\n", c);
return 1;
}
@ -448,7 +439,7 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *cm
const char *raw = "dump output in binary format";
struct config {
__u32 namespace_id;
int raw_binary;
bool raw_binary;
};
struct config cfg = {
@ -465,8 +456,8 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *cm
if (fd < 0)
return fd;
err = nvme_get_log(fd, cfg.namespace_id, 0xca, false,
NVME_NO_LOG_LSP, sizeof(smart_log), &smart_log);
err = nvme_get_nsid_log(fd, false, 0xca, cfg.namespace_id,
sizeof(smart_log), &smart_log);
if (!err) {
if (!cfg.raw_binary)
err = show_memblaze_smart_log(fd, cfg.namespace_id, devicename, &smart_log);
@ -474,7 +465,7 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *cm
d_raw((unsigned char *)&smart_log, sizeof(smart_log));
}
if (err > 0)
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
nvme_show_status(err);
return err;
}
@ -503,7 +494,20 @@ static int mb_get_powermanager_status(int argc, char **argv, struct command *cmd
fd = parse_and_open(argc, argv, desc, opts);
if (fd < 0) return fd;
err = nvme_get_feature(fd, 0, feature_id, 0, 0, 0, 0, NULL, &result);
struct nvme_get_features_args args = {
.args_size = sizeof(args),
.fd = fd,
.fid = feature_id,
.nsid = 0,
.sel = 0,
.cdw11 = 0,
.uuidx = 0,
.data_len = 0,
.data = NULL,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
err = nvme_get_features(&args);
if (err < 0) {
perror("get-feature");
}
@ -512,7 +516,7 @@ static int mb_get_powermanager_status(int argc, char **argv, struct command *cmd
mb_feature_to_string(feature_id),
nvme_select_to_string(0), result);
} else if (err > 0)
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
nvme_show_status(err);
return err;
}
@ -527,7 +531,7 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *cmd
struct config {
__u32 feature_id;
__u32 value;
int save;
bool save;
};
struct config cfg = {
@ -545,7 +549,22 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *cmd
fd = parse_and_open(argc, argv, desc, opts);
if (fd < 0) return fd;
err = nvme_set_feature(fd, 0, cfg.feature_id, cfg.value, 0, cfg.save, 0, 0, NULL, &result);
struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fd = fd,
.fid = cfg.feature_id,
.nsid = 0,
.cdw11 = cfg.value,
.cdw12 = 0,
.save = cfg.save,
.uuidx = 0,
.cdw15 = 0,
.data_len = 0,
.data = NULL,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
err = nvme_set_features(&args);
if (err < 0) {
perror("set-feature");
}
@ -553,7 +572,7 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *cmd
printf("set-feature:%02x (%s), value:%#08x\n", cfg.feature_id,
mb_feature_to_string(cfg.feature_id), cfg.value);
} else if (err > 0)
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
nvme_show_status(err);
return err;
}
@ -602,7 +621,22 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *cmd, s
}
cfg.value = (param1 << MB_FEAT_HIGH_LATENCY_VALUE_SHIFT) | param2;
err = nvme_set_feature(fd, 0, cfg.feature_id, cfg.value, 0, 0, 0, 0, NULL, &result);
struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fd = fd,
.fid = cfg.feature_id,
.nsid = 0,
.cdw11 = cfg.value,
.cdw12 = 0,
.save = false,
.uuidx = 0,
.cdw15 = 0,
.data_len = 0,
.data = NULL,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
err = nvme_set_features(&args);
if (err < 0) {
perror("set-feature");
}
@ -610,7 +644,7 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *cmd, s
printf("set-feature:0x%02X (%s), value:%#08x\n", cfg.feature_id,
mb_feature_to_string(cfg.feature_id), cfg.value);
} else if (err > 0)
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
nvme_show_status(err);
return err;
}
@ -721,13 +755,13 @@ static int mb_high_latency_log_print(int argc, char **argv, struct command *cmd,
if (fd < 0) return fd;
glp_high_latency_show_bar(fdi, DO_PRINT_FLAG);
err = nvme_get_log(fd, NVME_NSID_ALL, GLP_ID_VU_GET_HIGH_LATENCY_LOG, 0, NVME_NO_LOG_LSP, sizeof(buf), &buf);
err = nvme_get_log_simple(fd, GLP_ID_VU_GET_HIGH_LATENCY_LOG, sizeof(buf), &buf);
while ( 1) {
while (1) {
if (!glp_high_latency(fdi, buf, LOG_PAGE_SIZE, DO_PRINT_FLAG)) break;
err = nvme_get_log(fd, NVME_NSID_ALL, GLP_ID_VU_GET_HIGH_LATENCY_LOG, 0, NVME_NO_LOG_LSP, sizeof(buf), &buf);
err = nvme_get_log_simple(fd, GLP_ID_VU_GET_HIGH_LATENCY_LOG, sizeof(buf), &buf);
if ( err) {
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
nvme_show_status(err);
break;
}
}
@ -739,13 +773,13 @@ static int mb_high_latency_log_print(int argc, char **argv, struct command *cmd,
static int memblaze_fw_commit(int fd, int select)
{
struct nvme_admin_cmd cmd = {
.opcode = nvme_admin_activate_fw,
struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_fw_commit,
.cdw10 = 8,
.cdw12 = select,
};
return nvme_submit_admin_passthru(fd, &cmd);
return nvme_submit_admin_passthru(fd, &cmd, NULL);
}
static int mb_selective_download(int argc, char **argv, struct command *cmd, struct plugin *plugin)
@ -839,13 +873,21 @@ static int mb_selective_download(int argc, char **argv, struct command *cmd, str
while (fw_size > 0) {
xfer = min(xfer, fw_size);
err = nvme_fw_download(fd, offset, xfer, fw_buf);
struct nvme_fw_download_args args = {
.args_size = sizeof(args),
.fd = fd,
.offset = offset,
.data_len = xfer,
.data = fw_buf,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = NULL,
};
err = nvme_fw_download(&args);
if (err < 0) {
perror("fw-download");
goto out;
} else if (err != 0) {
fprintf(stderr, "NVME Admin command error:%s(%x)\n",
nvme_status_to_string(err), err);
nvme_show_status(err);
goto out;
}
fw_buf += xfer;
@ -980,7 +1022,7 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *cmd, st
const char *write = "Get write statistics (read default)";
struct config {
int write;
bool write;
};
struct config cfg = {
.write = 0,
@ -994,12 +1036,12 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *cmd, st
fd = parse_and_open(argc, argv, desc, opts);
if (fd < 0) return fd;
err = nvme_get_log(fd, NVME_NSID_ALL, cfg.write ? 0xc2 : 0xc1, false, NVME_NO_LOG_LSP, sizeof(stats), &stats);
err = nvme_get_log_simple(fd, cfg.write ? 0xc2 : 0xc1, sizeof(stats), &stats);
if (!err)
io_latency_histogram(cfg.write ? f2 : f1, stats, DO_PRINT_FLAG,
cfg.write ? GLP_ID_VU_GET_WRITE_LATENCY_HISTOGRAM : GLP_ID_VU_GET_READ_LATENCY_HISTOGRAM);
else
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
nvme_show_status(err);
close(fd);
return err;
@ -1009,8 +1051,8 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *cmd, st
#define FID 0x68
static int memblaze_clear_error_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
int err, fd;
char *desc = "Clear Memblaze devices error log.";
int err, fd;
char *desc = "Clear Memblaze devices error log.";
//const char *value = "new value of feature (required)";
//const char *save = "specifies that the controller shall save the attribute";
@ -1028,24 +1070,38 @@ static int memblaze_clear_error_log(int argc, char **argv, struct command *cmd,
.save = 0,
};
OPT_ARGS(opts) = {
OPT_END()
};
OPT_ARGS(opts) = {
OPT_END()
};
fd = parse_and_open(argc, argv, desc, opts);
if (fd < 0)
return fd;
fd = parse_and_open(argc, argv, desc, opts);
if (fd < 0)
return fd;
err = nvme_set_feature(fd, 0, cfg.feature_id, cfg.value, 0, cfg.save, 0, 0, NULL, &result);
struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fd = fd,
.fid = cfg.feature_id,
.nsid = 0,
.cdw11 = cfg.value,
.cdw12 = 0,
.save = cfg.save,
.uuidx = 0,
.cdw15 = 0,
.data_len = 0,
.data = NULL,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
err = nvme_set_features(&args);
if (err < 0) {
perror("set-feature");
}
if (!err) {
printf("set-feature:%02x (%s), value:%#08x\n", cfg.feature_id, mb_feature_to_string(cfg.feature_id), cfg.value);
} else if (err > 0)
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
nvme_show_status(err);
/*
struct nvme_admin_cmd admin_cmd = {
.opcode = OP,
@ -1060,7 +1116,7 @@ static int memblaze_clear_error_log(int argc, char **argv, struct command *cmd,
printf("NVMe Status:%s(%x)\n", nvme_status_to_string(err), err);
};
*/
return err;
return err;
}
static int mb_set_lat_stats(int argc, char **argv,
@ -1092,8 +1148,8 @@ static int mb_set_lat_stats(int argc, char **argv,
};
const struct argconfig_commandline_options command_line_options[] = {
{"enable", 'e', "", CFG_NONE, &cfg.enable, no_argument, enable_desc},
{"disable", 'd', "", CFG_NONE, &cfg.disable, no_argument, disable_desc},
{"enable", 'e', "", CFG_FLAG, &cfg.enable, no_argument, enable_desc},
{"disable", 'd', "", CFG_FLAG, &cfg.disable, no_argument, disable_desc},
{NULL}
};
@ -1111,12 +1167,41 @@ static int mb_set_lat_stats(int argc, char **argv,
else if (cfg.enable || cfg.disable)
option = cfg.enable;
struct nvme_get_features_args args_get = {
.args_size = sizeof(args_get),
.fd = fd,
.fid = fid,
.nsid = nsid,
.sel = sel,
.cdw11 = cdw11,
.uuidx = 0,
.data_len = data_len,
.data = buf,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
struct nvme_set_features_args args_set = {
.args_size = sizeof(args_set),
.fd = fd,
.fid = fid,
.nsid = nsid,
.cdw11 = option,
.cdw12 = cdw12,
.save = save,
.uuidx = 0,
.cdw15 = 0,
.data_len = data_len,
.data = buf,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
if (fd < 0)
return fd;
switch (option) {
case None:
err = nvme_get_feature(fd, nsid, fid, sel, cdw11, 0, data_len, buf,
&result);
err = nvme_get_features(&args_get);
if (!err) {
printf(
"Latency Statistics Tracking (FID 0x%X) is currently (%i).\n",
@ -1128,17 +1213,15 @@ static int mb_set_lat_stats(int argc, char **argv,
break;
case True:
case False:
err = nvme_set_feature(fd, nsid, fid, option, cdw12, save, 0,
data_len, buf, &result);
err = nvme_set_features(&args_set);
if (err > 0) {
fprintf(stderr, "NVMe Status:%s(%x)\n",
nvme_status_to_string(err), err);
nvme_show_status(err);
} else if (err < 0) {
perror("Enable latency tracking");
fprintf(stderr, "Command failed while parsing.\n");
} else {
printf("Successfully set enable bit for FID (0x%X) to %i.\n",
fid, option);
0xe2, option);
}
break;
default: