Skip to content

Commit

Permalink
nvme: use NVME_GET_FEATURES_SEL definitions
Browse files Browse the repository at this point in the history
These changes are to replace the hardcoded SEL values.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
  • Loading branch information
ikegami-t committed Sep 15, 2024
1 parent f7c7953 commit 5938900
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
19 changes: 13 additions & 6 deletions nvme-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,13 +962,20 @@ const char *nvme_register_to_string(int reg)
const char *nvme_select_to_string(int sel)
{
switch (sel) {
case 0: return "Current";
case 1: return "Default";
case 2: return "Saved";
case 3: return "Supported capabilities";
case 8: return "Changed";
default: return "Reserved";
case NVME_GET_FEATURES_SEL_CURRENT:
return "Current";
case NVME_GET_FEATURES_SEL_DEFAULT:
return "Default";
case NVME_GET_FEATURES_SEL_SAVED:
return "Saved";
case NVME_GET_FEATURES_SEL_SUPPORTED:
return "Supported capabilities";
case NVME_GET_FEATURES_SEL_CHANGED:
return "Changed";
default:
break;
}
return "Reserved";
}

void nvme_show_select_result(enum nvme_features_id fid, __u32 result)
Expand Down
12 changes: 6 additions & 6 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -4622,17 +4622,17 @@ static int get_feature_id_changed(struct nvme_dev *dev, struct feat_cfg cfg,
_cleanup_free_ void *buf_def = NULL;

if (changed)
cfg.sel = 0;
cfg.sel = NVME_GET_FEATURES_SEL_CURRENT;

err = get_feature_id(dev, &cfg, &buf, &result);

if (!err && changed) {
cfg.sel = 1;
cfg.sel = NVME_GET_FEATURES_SEL_DEFAULT;
err_def = get_feature_id(dev, &cfg, &buf_def, &result_def);
}

if (changed)
cfg.sel = 8;
cfg.sel = NVME_GET_FEATURES_SEL_CHANGED;

if (err || !changed || err_def || result != result_def ||
(buf && buf_def && !strcmp(buf, buf_def)))
Expand All @@ -4651,7 +4651,7 @@ static int get_feature_ids(struct nvme_dev *dev, struct feat_cfg cfg)
int status = 0;
enum nvme_status_type type = NVME_STATUS_TYPE_NVME;

if (cfg.sel == 8)
if (cfg.sel == NVME_GET_FEATURES_SEL_CHANGED)
changed = true;

if (cfg.feature_id)
Expand Down Expand Up @@ -4701,7 +4701,7 @@ static int get_feature(int argc, char **argv, struct command *cmd,
struct feat_cfg cfg = {
.feature_id = 0,
.namespace_id = 0,
.sel = 0,
.sel = NVME_GET_FEATURES_SEL_CURRENT,
.data_len = 0,
.raw_binary = false,
.cdw11 = 0,
Expand Down Expand Up @@ -4734,7 +4734,7 @@ static int get_feature(int argc, char **argv, struct command *cmd,
}
}

if (cfg.sel > 8) {
if (cfg.sel > NVME_GET_FEATURES_SEL_CHANGED) {
nvme_show_error("invalid 'select' param:%d", cfg.sel);
return -EINVAL;
}
Expand Down
2 changes: 2 additions & 0 deletions nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ struct nvme_config {
OPT_END() \
}

#define NVME_GET_FEATURES_SEL_CHANGED 8

static inline int __dev_fd(struct nvme_dev *dev, const char *func, int line)
{
if (dev->type != NVME_DEV_DIRECT) {
Expand Down

0 comments on commit 5938900

Please sign in to comment.