/*
* nvme.c -- NVM-Express command line utility.
- *
+ *
* Copyright (c) 2014, Intel Corporation.
*
* Written by Keith Busch <keith.busch@intel.com>
static void show_error_log(struct nvme_error_log_page *err_log, int entries)
{
int i;
-
+
printf("Error Log Entries for device:%s entries:%d\n", devicename,
entries);
printf(".................\n");
return EINVAL;
}
struct nvme_error_log_page err_log[cfg.log_entries];
-
+
err = nvme_get_log(err_log,
sizeof(err_log), 0x1 | (((sizeof(err_log) / 4) - 1) << 16),
cfg.namespace_id);
} else {
unsigned char log[cfg.log_len];
- err = nvme_get_log(log, cfg.log_len, cfg.log_id | (((cfg.log_len / 4) - 1) << 16),
+ err = nvme_get_log(log, cfg.log_len, cfg.log_id | (((cfg.log_len / 4) - 1) << 16),
cfg.namespace_id);
if (!err) {
if (!cfg.raw_binary) {
printf("Device:%s log-id:%d namespace-id:%#x",
- devicename, cfg.log_id,
+ devicename, cfg.log_id,
cfg.namespace_id);
d(log, cfg.log_len, 16, 1);
} else
const char *s_suffix = suffix_si_get(&nsze);
const char *u_suffix = suffix_si_get(&nuse);
const char *l_suffix = suffix_binary_get(&lba);
-
+
char usage[128];
sprintf(usage,"%3.2f %sB / %3.1f %sB", nuse, u_suffix,
nsze, s_suffix);
sprintf(format,"%.0f %sB + %d B", (double)lba, l_suffix,
list_item.ns.lbaf[list_item.ns.flbas].ms);
char version[128];
- sprintf(version,"%d.%d", (list_item.ctrl.ver >> 16),
+ sprintf(version,"%d.%d", (list_item.ctrl.ver >> 16),
(list_item.ctrl.ver >> 8) & 0xff);
fprintf(stdout, "%-8s\t%-.20s\t%-8s\t%-8d\t%-26s\t%-.10s\n", list_item.node,
"----","------","-------","--------","------","-------");
for (unsigned i=0 ; i<len ; i++)
print_list_item(list_items[i]);
-
+
}
#ifndef LIBUDEV_EXISTS
struct udev_enumerate *enumerate;
struct udev_list_entry *devices, *dev_list_entry;
struct udev_device *dev;
-
+
struct list_item list_items[MAX_LIST_ITEMS];
unsigned count=0;
perror("nvme-list: Cannot create udev context.");
return errno;
}
-
+
enumerate = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(enumerate, "char");
udev_enumerate_add_match_subsystem(enumerate, "block");
show_nvme_id_ns(&ns, cfg.namespace_id, cfg.vendor_specific);
}
else if (err > 0)
- fprintf(stderr, "NVMe Status: %s NSID:%d\n", nvme_status_to_string(err),
+ fprintf(stderr, "NVMe Status: %s NSID:%d\n", nvme_status_to_string(err),
cfg.namespace_id);
return err;
}
buf = malloc(cfg.data_len);
cdw10 = cfg.sel << 8 | cfg.feature_id;
- err = nvme_feature(nvme_admin_get_features, buf, cfg.data_len, cdw10,
+ err = nvme_feature(nvme_admin_get_features, buf, cfg.data_len, cdw10,
cfg.namespace_id, cfg.cdw11, &result);
if (!err) {
printf("get-feature:%d(%s), value:%#08x\n", cfg.feature_id,
if (fw_size & 0x3) {
fprintf(stderr, "Invalid size:%d for f/w image\n", fw_size);
return EINVAL;
- }
+ }
if (posix_memalign(&fw_buf, getpagesize(), fw_size)) {
fprintf(stderr, "No memory for f/w size:%d\n", fw_size);
return ENOMEM;
cmd.addr = (__u64)fw_buf;
cmd.data_len = cfg.xfer;
cmd.cdw10 = (cfg.xfer >> 2) - 1;
- cmd.cdw11 = cfg.offset >> 2;
+ cmd.cdw11 = cfg.offset >> 2;
err = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
if (err < 0) {
argconfig_parse(argc, argv, "fw_activate", command_line_options,
&defaults, &cfg, sizeof(cfg));
get_dev(1, argc, argv);
-
+
if (cfg.slot > 7) {
fprintf(stderr, "invalid slot:%d\n", cfg.slot);
return EINVAL;
fprintf(stderr, "invalid action:%d\n", cfg.action);
return EINVAL;
}
-
+
memset(&cmd, 0, sizeof(cmd));
cmd.opcode = nvme_admin_activate_fw;
cmd.cdw10 = (cfg.action << 3) | cfg.slot;
else if (err != 0)
fprintf(stderr, "NVME Admin command error:%d\n", err);
else
- printf("Success activating firmware action:%d slot:%d\n",
+ printf("Success activating firmware action:%d slot:%d\n",
cfg.action, cfg.slot);
return err;
}
cmd.opcode = nvme_admin_format_nvm;
cmd.nsid = cfg.namespace_id;
cmd.cdw10 = (cfg.lbaf << 0) | (cfg.ms << 4) | (cfg.pi << 5) | (cfg.pil << 8) | (cfg.ses << 9);
-
+
err = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &cmd);
if (err < 0)
perror("ioctl");
if (cfg.data_len)
buf = malloc(cfg.data_len);
- err = nvme_feature(nvme_admin_set_features, buf, cfg.data_len, cfg.feature_id,
+ err = nvme_feature(nvme_admin_set_features, buf, cfg.data_len, cfg.feature_id,
cfg.namespace_id, cfg.value, &result);
if (!err) {
printf("set-feature:%d(%s), value:%#08x\n", cfg.feature_id,
io.control |= NVME_RW_FUA;
if (strlen(cfg.data)){
if (opcode & 1)
- dfd = open(cfg.data, O_RDONLY);
+ dfd = open(cfg.data, O_RDONLY);
else
- dfd = open(cfg.data, O_WRONLY | O_CREAT,
+ dfd = open(cfg.data, O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP| S_IROTH);
if (dfd < 0) {
perror(cfg.data);
err = ioctl(fd, NVME_IOCTL_SUBMIT_IO, &io);
gettimeofday(&end_time, NULL);
if (cfg.latency)
- fprintf(stdout, " latency: %s: %llu us\n",
+ fprintf(stdout, " latency: %s: %llu us\n",
command, elapsed_utime(start_time, end_time));
if (err < 0)
perror("ioctl");
static int compare(int argc, char **argv)
{
- return submit_io(nvme_cmd_compare, "compare", argc, argv);
+ return submit_io(nvme_cmd_compare, "compare", argc, argv);
}
static int read_cmd(int argc, char **argv)
{
- return submit_io(nvme_cmd_read, "read", argc, argv);
+ return submit_io(nvme_cmd_read, "read", argc, argv);
}
static int write_cmd(int argc, char **argv)
{
- return submit_io(nvme_cmd_write, "write", argc, argv);
+ return submit_io(nvme_cmd_write, "write", argc, argv);
}
static int sec_recv(int argc, char **argv)
char *input_file;
__u8 raw_binary;
__u8 show_command;
- __u8 dry_run;
- __u8 read;
- __u8 write;
+ __u8 dry_run;
+ __u8 read;
+ __u8 write;
};
struct config cfg;
memset(&cmd, 0, sizeof(cmd));
argconfig_parse(argc, argv, "nvme_passthrou", command_line_options,
&defaults, &cfg, sizeof(cfg));
-
+
cmd.cdw2 = cfg.cdw13;
cmd.cdw3 = cfg.cdw13;
cmd.cdw10 = cfg.cdw13;
cmd.metadata_len = cfg.metadata_len;
cmd.timeout_ms = cfg.timeout;
if (strlen(cfg.input_file)){
- wfd = open(cfg.input_file, O_RDONLY,
+ wfd = open(cfg.input_file, O_RDONLY,
S_IRUSR | S_IRGRP | S_IROTH);
if (wfd < 0) {
perror(cfg.input_file);