Skip to content

Commit

Permalink
nvme: Add get-reg command register offset symbol options
Browse files Browse the repository at this point in the history
Note: set-reg command also needed to change as same.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Jan 30, 2024
1 parent 1b6e87c commit ad67f4e
Showing 1 changed file with 132 additions and 6 deletions.
138 changes: 132 additions & 6 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -5354,33 +5354,160 @@ static int get_register(int argc, char **argv, struct command *cmd, struct plugi
"PMRSTS=0xe08, PMREBS=0xe0c, PMRSWTP=0xe10, PMRMSCL=0xe14, PMRMSCU=0xe18";
const char *offset = "offset of the requested register";
const char *human_readable = "show register in readable format";
const char *cap = "CAP=0x0 register offset";
const char *vs = "VS=0x8 register offset";
const char *intms = "INTMS=0xc register offset";
const char *intmc = "INTMC=0x10 register offset";
const char *cc = "CC=0x14 register offset";
const char *csts = "CSTS=0x1c register offset";
const char *nssr = "NSSR=0x20 register offset";
const char *aqa = "AQA=0x24 register offset";
const char *asq = "ASQ=0x28 register offset";
const char *acq = "ACQ=0x30 register offset";
const char *cmbloc = "CMBLOC=0x38 register offset";
const char *cmbsz = "CMBSZ=0x3c register offset";
const char *bpinfo = "BPINFO=0x40 register offset";
const char *bprsel = "BPRSEL=0x44 register offset";
const char *bpmbl = "BPMBL=0x48 register offset";
const char *cmbmsc = "CMBMSC=0x50 register offset";
const char *cmbsts = "CMBSTS=0x58 register offset";
const char *crto = "CRTO=0x68 register offset";
const char *pmrcap = "PMRCAP=0xe00 register offset";
const char *pmrctl = "PMRCTL=0xe04 register offset";
const char *pmrsts = "PMRSTS=0xe08 register offset";
const char *pmrebs = "PMREBS=0xe0c register offset";
const char *pmrswtp = "PMRSWTP=0xe10 register offset";
const char *pmrmscl = "PMRMSCL=0xe14 register offset";
const char *pmrmscu = "PMRMSCU=0xe18 register offset";

_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
int err;
enum nvme_print_flags flags;
bool fabrics = false;
nvme_root_t r;
_cleanup_nvme_root_ nvme_root_t r = NULL;
void *bar;

struct config {
int offset;
bool human_readable;
bool cap;
bool vs;
bool intms;
bool intmc;
bool cc;
bool csts;
bool nssr;
bool aqa;
bool asq;
bool acq;
bool cmbloc;
bool cmbsz;
bool bpinfo;
bool bprsel;
bool bpmbl;
bool cmbmsc;
bool cmbsts;
bool crto;
bool pmrcap;
bool pmrctl;
bool pmrsts;
bool pmrebs;
bool pmrswtp;
bool pmrmscl;
bool pmrmscu;
};

struct config cfg = {
.offset = -1,
.human_readable = false,
};

NVME_ARGS(opts, cfg,
OPT_UINT("offset", 'O', &cfg.offset, offset),
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable));
OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable),
OPT_FLAG("cap", 'c', &cfg.cap, cap),
OPT_FLAG("vs", 'V', &cfg.vs, vs),
OPT_FLAG("intms", 'i', &cfg.intms, intms),
OPT_FLAG("intmc", 'I', &cfg.intmc, intmc),
OPT_FLAG("cc", 'c', &cfg.cc, cc),
OPT_FLAG("csts", 'C', &cfg.csts, csts),
OPT_FLAG("nssr", 'n', &cfg.nssr, nssr),
OPT_FLAG("aqa", 'a', &cfg.aqa, aqa),
OPT_FLAG("asq", 'A', &cfg.asq, asq),
OPT_FLAG("acq", 'q', &cfg.acq, acq),
OPT_FLAG("cmbloc", 'm', &cfg.cmbloc, cmbloc),
OPT_FLAG("cmbsz", 'M', &cfg.cmbsz, cmbsz),
OPT_FLAG("bpinfo", 'b', &cfg.bpinfo, bpinfo),
OPT_FLAG("bprsel", 'B', &cfg.bprsel, bprsel),
OPT_FLAG("bpmbl", 'p', &cfg.bpmbl, bpmbl),
OPT_FLAG("cmbmsc", 's', &cfg.cmbmsc, cmbmsc),
OPT_FLAG("cmbsts", 'S', &cfg.cmbsts, cmbsts),
OPT_FLAG("crto", 'r', &cfg.crto, crto),
OPT_FLAG("pmrcap", 'P', &cfg.pmrcap, pmrcap),
OPT_FLAG("pmrctl", 'R', &cfg.pmrctl, pmrctl),
OPT_FLAG("pmrsts", 't', &cfg.pmrsts, pmrsts),
OPT_FLAG("pmrebs", 'e', &cfg.pmrebs, pmrebs),
OPT_FLAG("pmrswtp", 'w', &cfg.pmrswtp, pmrswtp),
OPT_FLAG("pmrmscl", 'l', &cfg.pmrmscl, pmrmscl),
OPT_FLAG("pmrmscu", 'u', &cfg.pmrmscu, pmrmscu));

err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;

if (!argconfig_parse_seen(opts, "offset")) {
if (argconfig_parse_seen(opts, "cap"))
cfg.offset = NVME_REG_CAP;
else if (argconfig_parse_seen(opts, "vs"))
cfg.offset = NVME_REG_VS;
else if (argconfig_parse_seen(opts, "intms"))
cfg.offset = NVME_REG_INTMS;
else if (argconfig_parse_seen(opts, "intmc"))
cfg.offset = NVME_REG_INTMC;
else if (argconfig_parse_seen(opts, "cc"))
cfg.offset = NVME_REG_CC;
else if (argconfig_parse_seen(opts, "csts"))
cfg.offset = NVME_REG_CSTS;
else if (argconfig_parse_seen(opts, "nssr"))
cfg.offset = NVME_REG_NSSR;
else if (argconfig_parse_seen(opts, "aqa"))
cfg.offset = NVME_REG_AQA;
else if (argconfig_parse_seen(opts, "asq"))
cfg.offset = NVME_REG_ASQ;
else if (argconfig_parse_seen(opts, "acq"))
cfg.offset = NVME_REG_ACQ;
else if (argconfig_parse_seen(opts, "cmbloc"))
cfg.offset = NVME_REG_CMBLOC;
else if (argconfig_parse_seen(opts, "cmbsz"))
cfg.offset = NVME_REG_CMBSZ;
else if (argconfig_parse_seen(opts, "bpinfo"))
cfg.offset = NVME_REG_BPINFO;
else if (argconfig_parse_seen(opts, "bprsel"))
cfg.offset = NVME_REG_BPRSEL;
else if (argconfig_parse_seen(opts, "bpmbl"))
cfg.offset = NVME_REG_BPMBL;
else if (argconfig_parse_seen(opts, "cmbmsc"))
cfg.offset = NVME_REG_CMBMSC;
else if (argconfig_parse_seen(opts, "cmbsts"))
cfg.offset = NVME_REG_CMBSTS;
else if (argconfig_parse_seen(opts, "crto"))
cfg.offset = NVME_REG_CRTO;
else if (argconfig_parse_seen(opts, "pmrcap"))
cfg.offset = NVME_REG_PMRCAP;
else if (argconfig_parse_seen(opts, "pmrctl"))
cfg.offset = NVME_REG_PMRCTL;
else if (argconfig_parse_seen(opts, "pmrsts"))
cfg.offset = NVME_REG_PMRSTS;
else if (argconfig_parse_seen(opts, "pmrebs"))
cfg.offset = NVME_REG_PMREBS;
else if (argconfig_parse_seen(opts, "pmrswtp"))
cfg.offset = NVME_REG_PMRSWTP;
else if (argconfig_parse_seen(opts, "pmrmscl"))
cfg.offset = NVME_REG_PMRMSCL;
else if (argconfig_parse_seen(opts, "pmrmscu"))
cfg.offset = NVME_REG_PMRMSCU;
}

if (cfg.offset < 0) {
nvme_show_error("offset required param");
return -EINVAL;
}
Expand All @@ -5399,7 +5526,7 @@ static int get_register(int argc, char **argv, struct command *cmd, struct plugi
if (!bar) {
err = nvme_get_properties(dev_fd(dev), &bar);
if (err)
goto free_tree;
return err;
fabrics = true;
}

Expand All @@ -5408,8 +5535,7 @@ static int get_register(int argc, char **argv, struct command *cmd, struct plugi
free(bar);
else
munmap(bar, getpagesize());
free_tree:
nvme_free_tree(r);

return err;
}

Expand Down

0 comments on commit ad67f4e

Please sign in to comment.