Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions nvme-rpmb.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,8 @@ struct rpmb_config_block_t {
static int send_rpmb_req(nvme_link_t l, unsigned char tgt, int size,
struct rpmb_data_frame_t *req)
{
struct nvme_security_send_args args = {
.args_size = sizeof(args),
.nsid = 0,
.nssf = tgt,
.spsp0 = RPMB_NVME_SPSP,
.spsp1 = 0,
.secp = RPMB_NVME_SECP,
.tl = 0,
.data_len = size,
.data = (void *)req,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = NULL,
};

return nvme_security_send(l, &args);
return nvme_security_send(l, 0, tgt, RPMB_NVME_SPSP, RPMB_NVME_SECP, 0,
(void *)req, size, NULL);
}

static int recv_rpmb_rsp(nvme_link_t l, int tgt, int size,
Expand Down
179 changes: 62 additions & 117 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -3394,7 +3394,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
for (i = 0; i < num_phandle; i++)
data->phndl[i] = cpu_to_le16(phndl[i]);

err = nvme_ns_mgmt_create(l, NULL, &nsid, nvme_cfg.timeout, cfg.csi, data);
err = nvme_ns_mgmt_create(l, cfg.csi, data, &nsid);
ns_mgmt_show_status(l, err, cmd->name, nsid);

return err;
Expand Down Expand Up @@ -4977,22 +4977,13 @@ static int fw_download_single(nvme_link_t l, void *fw_buf,
offset, fw_len, (int)(100 * offset / fw_len));
}

struct nvme_fw_download_args args = {
.args_size = sizeof(args),
.offset = offset,
.data_len = len,
.data = fw_buf,
.timeout = nvme_cfg.timeout,
.result = NULL,
};

for (try = 0; try < max_retries; try++) {
if (try > 0) {
fprintf(stderr, "retrying offset %x (%u/%u)\n",
offset, try, max_retries);
}

err = nvme_fw_download(l, &args);
err = nvme_fw_download(l, fw_buf, len, offset, NULL);
if (!err)
return 0;

Expand Down Expand Up @@ -5239,8 +5230,8 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *
"reset following firmware activation. A reset may be issued "
"with an 'echo 1 > /sys/class/nvme/nvmeX/reset_controller'. "
"Ensure nvmeX is the device you just activated before reset.";
const char *slot = "[0-7]: firmware slot for commit action";
const char *action = "[0-7]: commit action";
const char *fs = "[0-7]: firmware slot for commit action";
const char *ca = "[0-7]: commit action";
const char *bpid = "[0,1]: boot partition identifier, if applicable (default: 0)";

_cleanup_nvme_root_ nvme_root_t r = NULL;
Expand All @@ -5250,21 +5241,21 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *
nvme_print_flags_t flags;

struct config {
__u8 slot;
__u8 action;
__u8 fs;
__u8 ca;
__u8 bpid;
};

struct config cfg = {
.slot = 0,
.action = 0,
.fs = 0,
.ca = 0,
.bpid = 0,
};

NVME_ARGS(opts,
OPT_BYTE("slot", 's', &cfg.slot, slot),
OPT_BYTE("action", 'a', &cfg.action, action),
OPT_BYTE("bpid", 'b', &cfg.bpid, bpid));
OPT_BYTE("slot", 's', &cfg.fs, fs),
OPT_BYTE("action", 'a', &cfg.ca, ca),
OPT_BYTE("bpid", 'b', &cfg.bpid, bpid));

err = parse_and_open(&r, &l, argc, argv, desc, opts);
if (err)
Expand All @@ -5276,29 +5267,20 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *
return err;
}

if (cfg.slot > 7) {
nvme_show_error("invalid slot:%d", cfg.slot);
if (cfg.fs > 7) {
nvme_show_error("invalid slot:%d", cfg.fs);
return -EINVAL;
}
if (cfg.action > 7 || cfg.action == 4 || cfg.action == 5) {
nvme_show_error("invalid action:%d", cfg.action);
if (cfg.ca > 7 || cfg.ca == 4 || cfg.ca == 5) {
nvme_show_error("invalid action:%d", cfg.ca);
return -EINVAL;
}
if (cfg.bpid > 1) {
nvme_show_error("invalid boot partition id:%d", cfg.bpid);
return -EINVAL;
}

struct nvme_fw_commit_args args = {
.args_size = sizeof(args),
.slot = cfg.slot,
.action = cfg.action,
.bpid = cfg.bpid,
.timeout = nvme_cfg.timeout,
.result = &result,
};

err = nvme_fw_commit(l, &args);
err = nvme_fw_commit(l, cfg.fs, cfg.ca, cfg.bpid, &result);
if (err < 0) {
nvme_show_error("fw-commit: %s", nvme_strerror(-err));
} else if (err != 0) {
Expand All @@ -5311,8 +5293,8 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *
case NVME_SC_FW_NEEDS_SUBSYS_RESET:
case NVME_SC_FW_NEEDS_RESET:
printf("Success activating firmware action:%d slot:%d",
cfg.action, cfg.slot);
if (cfg.action == 6 || cfg.action == 7)
cfg.ca, cfg.fs);
if (cfg.ca == 6 || cfg.ca == 7)
printf(" bpid:%d", cfg.bpid);
printf(", but firmware requires %s reset\n",
nvme_fw_status_reset_type(val));
Expand All @@ -5326,8 +5308,8 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *
}
} else {
printf("Success committing firmware action:%d slot:%d",
cfg.action, cfg.slot);
if (cfg.action == 6 || cfg.action == 7)
cfg.ca, cfg.fs);
if (cfg.ca == 6 || cfg.ca == 7)
printf(" bpid:%d", cfg.bpid);
printf("\n");
fw_commit_print_mud(l, result);
Expand Down Expand Up @@ -6395,7 +6377,7 @@ static int format_cmd(int argc, char **argv, struct command *cmd, struct plugin
const char *ses = "[0-2]: secure erase";
const char *pil = "[0-1]: protection info location last/first bytes of metadata";
const char *pi = "[0-3]: protection info off/Type 1/Type 2/Type 3";
const char *ms = "[0-1]: extended format off/on";
const char *mset = "[0-1]: extended format off/on";
const char *reset = "Automatically reset the controller after successful format";
const char *bs = "target block size";
const char *force = "The \"I know what I'm doing\" flag, skip confirmation before sending command";
Expand All @@ -6415,7 +6397,7 @@ static int format_cmd(int argc, char **argv, struct command *cmd, struct plugin
__u8 ses;
__u8 pi;
__u8 pil;
__u8 ms;
__u8 mset;
bool reset;
bool force;
__u64 bs;
Expand All @@ -6427,7 +6409,7 @@ static int format_cmd(int argc, char **argv, struct command *cmd, struct plugin
.ses = 0,
.pi = 0,
.pil = 0,
.ms = 0,
.mset = 0,
.reset = false,
.force = false,
.bs = 0,
Expand All @@ -6441,7 +6423,7 @@ static int format_cmd(int argc, char **argv, struct command *cmd, struct plugin
OPT_BYTE("ses", 's', &cfg.ses, ses),
OPT_BYTE("pi", 'i', &cfg.pi, pi),
OPT_BYTE("pil", 'p', &cfg.pil, pil),
OPT_BYTE("ms", 'm', &cfg.ms, ms),
OPT_BYTE("ms", 'm', &cfg.mset, mset),
OPT_FLAG("reset", 'r', &cfg.reset, reset),
OPT_FLAG("force", 0, &cfg.force, force),
OPT_SUFFIX("block-size", 'b', &cfg.bs, bs));
Expand Down Expand Up @@ -6572,8 +6554,8 @@ static int format_cmd(int argc, char **argv, struct command *cmd, struct plugin
nvme_show_error("invalid pil:%d", cfg.pil);
return -EINVAL;
}
if (cfg.ms > 1) {
nvme_show_error("invalid ms:%d", cfg.ms);
if (cfg.mset > 1) {
nvme_show_error("invalid mset:%d", cfg.mset);
return -EINVAL;
}

Expand All @@ -6590,19 +6572,8 @@ static int format_cmd(int argc, char **argv, struct command *cmd, struct plugin
fprintf(stderr, "Sending format operation ...\n");
}

struct nvme_format_nvm_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.lbafu = (cfg.lbaf >> 4) & 0x3,
.lbaf = cfg.lbaf & 0xf,
.mset = cfg.ms,
.pi = cfg.pi,
.pil = cfg.pil,
.ses = cfg.ses,
.timeout = nvme_cfg.timeout,
.result = NULL,
};
err = nvme_format_nvm(l, &args);
err = nvme_format_nvm(l, cfg.namespace_id, cfg.lbaf, cfg.mset,
cfg.pi, cfg.pil, cfg.ses, NULL);
if (err < 0) {
nvme_show_error("format: %s", nvme_strerror(-err));
} else if (err != 0) {
Expand Down Expand Up @@ -6659,11 +6630,11 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
"for each Feature are vendor-specific and may not be modified."
"Use get-feature to determine which Features are supported by"
"the controller and are saveable/changeable.";
const char *feature_id = "feature identifier (required)";
const char *fid = "feature identifier (required)";
const char *data = "optional file for feature data (default stdin)";
const char *value = "new value of feature (required)";
const char *cdw12 = "feature cdw12, if used";
const char *save = "specifies that the controller shall save the attribute";
const char *sv = "specifies that the controller shall save the attribute";

_cleanup_nvme_root_ nvme_root_t r = NULL;
_cleanup_nvme_link_ nvme_link_t l = NULL;
Expand All @@ -6674,35 +6645,35 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
nvme_print_flags_t flags;

struct config {
__u32 namespace_id;
__u8 feature_id;
__u32 nsid;
__u8 fid;
__u64 value;
__u32 cdw12;
__u8 uuid_index;
__u8 uidx;
__u32 data_len;
char *file;
bool save;
bool sv;
};

struct config cfg = {
.namespace_id = 0,
.feature_id = 0,
.nsid = 0,
.fid = 0,
.value = 0,
.uuid_index = 0,
.uidx = 0,
.data_len = 0,
.file = "",
.save = false,
.sv = false,
};

NVME_ARGS(opts,
OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace_desired),
OPT_BYTE("feature-id", 'f', &cfg.feature_id, feature_id, feature_name),
OPT_SUFFIX("value", 'V', &cfg.value, value),
OPT_UINT("cdw12", 'c', &cfg.cdw12, cdw12),
OPT_BYTE("uuid-index", 'U', &cfg.uuid_index, uuid_index_specify),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_FLAG("save", 's', &cfg.save, save));
OPT_UINT("namespace-id", 'n', &cfg.nsid, namespace_desired),
OPT_BYTE("feature-id", 'f', &cfg.fid, fid, feature_name),
OPT_SUFFIX("value", 'V', &cfg.value, value),
OPT_UINT("cdw12", 'c', &cfg.cdw12, cdw12),
OPT_BYTE("uuid-index", 'U', &cfg.uidx, uuid_index_specify),
OPT_UINT("data-len", 'l', &cfg.data_len, buf_len),
OPT_FILE("data", 'd', &cfg.file, data),
OPT_FLAG("save", 's', &cfg.sv, sv));

err = parse_and_open(&r, &l, argc, argv, desc, opts);
if (err)
Expand All @@ -6715,28 +6686,28 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
}

if (!argconfig_parse_seen(opts, "namespace-id")) {
err = nvme_get_nsid(l, &cfg.namespace_id);
err = nvme_get_nsid(l, &cfg.nsid);
if (err < 0) {
if (err != -ENOTTY) {
nvme_show_error("get-namespace-id: %s", nvme_strerror(-err));
return err;
}
cfg.namespace_id = NVME_NSID_ALL;
cfg.nsid = NVME_NSID_ALL;
}
}

if (!cfg.feature_id) {
if (!cfg.fid) {
nvme_show_error("feature-id required param");
return -EINVAL;
}

if (cfg.uuid_index > 127) {
nvme_show_error("invalid uuid index param: %u", cfg.uuid_index);
if (cfg.uidx > 127) {
nvme_show_error("invalid uuid index param: %u", cfg.uidx);
return -1;
}

if (!cfg.data_len)
nvme_get_feature_length(cfg.feature_id, cfg.value,
nvme_get_feature_length(cfg.fid, cfg.value,
NVME_DATA_TFR_HOST_TO_CTRL,
&cfg.data_len);

Expand All @@ -6753,7 +6724,7 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
* should use the buffer method if the value exceeds this
* length.
*/
if (cfg.feature_id == NVME_FEAT_FID_TIMESTAMP &&
if (cfg.fid == NVME_FEAT_FID_TIMESTAMP &&
argconfig_parse_seen(opts, "value")) {
memcpy(buf, &cfg.value, NVME_FEAT_TIMESTAMP_DATA_SIZE);
} else {
Expand All @@ -6775,33 +6746,20 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
}
}

struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fid = cfg.feature_id,
.nsid = cfg.namespace_id,
.cdw11 = cfg.value,
.cdw12 = cfg.cdw12,
.save = cfg.save,
.uuidx = cfg.uuid_index,
.cdw15 = 0,
.data_len = cfg.data_len,
.data = buf,
.timeout = nvme_cfg.timeout,
.result = &result,
};
err = nvme_set_features(l, &args);
err = nvme_set_features(l, cfg.nsid, cfg.fid, cfg.sv, cfg.value, cfg.cdw12,
0, 0, cfg.uidx, buf, cfg.data_len, &result);
if (err < 0) {
nvme_show_error("set-feature: %s", nvme_strerror(-err));
} else if (!err) {
printf("set-feature:%#0*x (%s), value:%#0*"PRIx64", cdw12:%#0*x, save:%#x\n",
cfg.feature_id ? 4 : 2, cfg.feature_id,
nvme_feature_to_string(cfg.feature_id),
cfg.fid ? 4 : 2, cfg.fid,
nvme_feature_to_string(cfg.fid),
cfg.value ? 10 : 8, (uint64_t)cfg.value,
cfg.cdw12 ? 10 : 8, cfg.cdw12, cfg.save);
if (cfg.feature_id == NVME_FEAT_FID_LBA_STS_INTERVAL)
cfg.cdw12 ? 10 : 8, cfg.cdw12, cfg.sv);
if (cfg.fid == NVME_FEAT_FID_LBA_STS_INTERVAL)
nvme_show_lba_status_info(result);
if (buf) {
if (cfg.feature_id == NVME_FEAT_FID_LBA_RANGE)
if (cfg.fid == NVME_FEAT_FID_LBA_RANGE)
nvme_show_lba_range((struct nvme_lba_range_type *)buf, result, 0);
else
d(buf, cfg.data_len, 16, 1);
Expand Down Expand Up @@ -6905,21 +6863,8 @@ static int sec_send(int argc, char **argv, struct command *cmd, struct plugin *p
return -errno;
}

struct nvme_security_send_args args = {
.args_size = sizeof(args),
.nsid = cfg.namespace_id,
.nssf = cfg.nssf,
.spsp0 = cfg.spsp & 0xff,
.spsp1 = cfg.spsp >> 8,
.secp = cfg.secp,
.tl = cfg.tl,
.data_len = cfg.tl,
.data = sec_buf,
.timeout = nvme_cfg.timeout,
.result = NULL,
};

err = nvme_security_send(l, &args);
err = nvme_security_send(l, cfg.namespace_id, cfg.nssf, cfg.spsp,
cfg.secp, cfg.tl, sec_buf, cfg.tl, NULL);

if (err < 0)
nvme_show_error("security-send: %s", nvme_strerror(-err));
Expand Down
Loading