Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvme: use NVME_GET_FEATURES_SEL definitions #2501

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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