Skip to content

Commit

Permalink
nvme-print-stdout: Use nvme_register_symbol_to_string() by show-regs
Browse files Browse the repository at this point in the history
Refactor the show-regs command implementation to use the function.

Signed-off-by: Tokunori Ikegami <[email protected]>
  • Loading branch information
ikegami-t committed Feb 4, 2024
1 parent 7662760 commit de5ccae
Showing 1 changed file with 105 additions and 178 deletions.
283 changes: 105 additions & 178 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,14 +1238,23 @@ static void stdout_registers_aqa(__u32 aqa)

}

static void stdout_registers_cmbloc(__u32 cmbloc, __u32 cmbsz)
static bool stdout_registers_cmbloc_support(__u32 cmbsz)
{
if (cmbsz)
return true;

return false;
}

static void stdout_registers_cmbloc(__u32 cmbloc, bool support)
{
static const char *enforced[] = { "Enforced", "Not Enforced" };

if (cmbsz == 0) {
if (!support) {
printf("\tController Memory Buffer feature is not supported\n\n");
return;
}

printf("\tOffset (OFST): 0x%x (See cmbsz.szu for granularity)\n",
(cmbloc & 0xfffff000) >> 12);

Expand Down Expand Up @@ -1397,24 +1406,30 @@ static void stdout_registers_pmrcap(__u32 pmrcap)
(pmrcap & 0x00000008) ? "supported" : "not supported");
}

static bool stdout_registers_pmrctl_ready(__u32 pmrctl)
{
if (pmrctl & 1)
return true;

return false;
}

static void stdout_registers_pmrctl(__u32 pmrctl)
{
printf("\tEnable (EN): PMR is %s\n", (pmrctl & 0x00000001) ?
"READY" : "Disabled");
printf("\tEnable (EN): PMR is %s\n",
stdout_registers_pmrctl_ready(pmrctl) ? "READY" : "Disabled");
}

static void stdout_registers_pmrsts(__u32 pmrsts, __u32 pmrctl)
static void stdout_registers_pmrsts(__u32 pmrsts, bool ready)
{
printf("\tController Base Address Invalid (CBAI): %x\n",
(pmrsts & 0x00001000) >> 12);
printf("\tController Base Address Invalid (CBAI): %x\n", (pmrsts & 0x1000) >> 12);
printf("\tHealth Status (HSTS): %s\n",
nvme_register_pmr_hsts_to_string((pmrsts & 0x00000e00) >> 9));
nvme_register_pmr_hsts_to_string((pmrsts & 0xe00) >> 9));
printf("\tNot Ready (NRDY): "\
"The Persistent Memory Region is %s to process "\
"PCI Express memory read and write requests\n",
(pmrsts & 0x00000100) == 0 && (pmrctl & 0x00000001) ?
"READY" : "Not Ready");
printf("\tError (ERR): %x\n", (pmrsts & 0x000000ff));
"The Persistent Memory Region is %s to process "\
"PCI Express memory read and write requests\n",
!(pmrsts & 0x100) && ready ? "READY" : "Not Ready");
printf("\tError (ERR): %x\n", (pmrsts & 0xff));
}

static void stdout_registers_pmrebs(__u32 pmrebs)
Expand Down Expand Up @@ -1449,7 +1464,7 @@ static void stdout_registers_pmrmscu(uint32_t pmrmscu)
pmrmscu);
}

static void stdout_ctrl_register_human(int offset, uint64_t value64)
static void stdout_ctrl_register_human(int offset, uint64_t value64, bool *support)
{
uint32_t value32 = (uint32_t)value64;

Expand Down Expand Up @@ -1485,7 +1500,7 @@ static void stdout_ctrl_register_human(int offset, uint64_t value64)
printf("\tAdmin Completion Queue Base (ACQB): %"PRIx64"\n\n", value64);
break;
case NVME_REG_CMBLOC:
stdout_registers_cmbloc(value32, 1);
stdout_registers_cmbloc(value32, support ? *support : true);
break;
case NVME_REG_CMBSZ:
stdout_registers_cmbsz(value32);
Expand Down Expand Up @@ -1524,7 +1539,7 @@ static void stdout_ctrl_register_human(int offset, uint64_t value64)
stdout_registers_pmrctl(value32);
break;
case NVME_REG_PMRSTS:
stdout_registers_pmrsts(value32, 1);
stdout_registers_pmrsts(value32, support ? *support : true);
break;
case NVME_REG_PMREBS:
stdout_registers_pmrebs(value32);
Expand Down Expand Up @@ -1561,161 +1576,78 @@ static void stdout_ctrl_register(int offset, uint64_t value64)
printf("0x%x\n", value32);

if (human)
stdout_ctrl_register_human(offset, value64);
stdout_ctrl_register_human(offset, value64, NULL);
}

void stdout_ctrl_registers(void *bar, bool fabrics)
static void stdout_ctrl_register_support(int offset, uint64_t value64, bool human, bool support)
{
uint64_t cap, asq, acq, bpmbl, cmbmsc;
uint32_t vs, intms, intmc, cc, csts, nssr, crto, aqa, cmbsz, cmbloc, bpinfo,
bprsel, cmbsts, pmrcap, pmrctl, pmrsts, pmrebs, pmrswtp,
pmrmscl, pmrmscu;
int human = stdout_print_ops.flags & VERBOSE;

cap = mmio_read64(bar + NVME_REG_CAP);
vs = mmio_read32(bar + NVME_REG_VS);
intms = mmio_read32(bar + NVME_REG_INTMS);
intmc = mmio_read32(bar + NVME_REG_INTMC);
cc = mmio_read32(bar + NVME_REG_CC);
csts = mmio_read32(bar + NVME_REG_CSTS);
nssr = mmio_read32(bar + NVME_REG_NSSR);
crto = mmio_read32(bar + NVME_REG_CRTO);
aqa = mmio_read32(bar + NVME_REG_AQA);
asq = mmio_read64(bar + NVME_REG_ASQ);
acq = mmio_read64(bar + NVME_REG_ACQ);
cmbloc = mmio_read32(bar + NVME_REG_CMBLOC);
cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
bpinfo = mmio_read32(bar + NVME_REG_BPINFO);
bprsel = mmio_read32(bar + NVME_REG_BPRSEL);
bpmbl = mmio_read64(bar + NVME_REG_BPMBL);
cmbmsc = mmio_read64(bar + NVME_REG_CMBMSC);
cmbsts = mmio_read32(bar + NVME_REG_CMBSTS);
pmrcap = mmio_read32(bar + NVME_REG_PMRCAP);
pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
pmrsts = mmio_read32(bar + NVME_REG_PMRSTS);
pmrebs = mmio_read32(bar + NVME_REG_PMREBS);
pmrswtp = mmio_read32(bar + NVME_REG_PMRSWTP);
pmrmscl = mmio_read32(bar + NVME_REG_PMRMSCL);
pmrmscu = mmio_read32(bar + NVME_REG_PMRMSCU);

if (human) {
if (cap != 0xffffffff) {
printf("cap : %"PRIx64"\n", cap);
stdout_ctrl_register_human(NVME_REG_CAP, cap);
}
if (vs != 0xffffffff) {
printf("version : %x\n", vs);
stdout_ctrl_register_human(NVME_REG_VS, vs);
}
if (cc != 0xffffffff) {
printf("cc : %x\n", cc);
stdout_ctrl_register_human(NVME_REG_CC, cc);
}
if (csts != 0xffffffff) {
printf("csts : %x\n", csts);
stdout_ctrl_register_human(NVME_REG_CSTS, csts);
}
if (nssr != 0xffffffff) {
printf("nssr : %x\n", nssr);
stdout_ctrl_register_human(NVME_REG_NSSR, nssr);
}
if (crto != 0xffffffff) {
printf("crto : %x\n", crto);
stdout_ctrl_register_human(NVME_REG_CRTO, crto);
}
if (!fabrics) {
printf("intms : %x\n", intms);
stdout_ctrl_register_human(NVME_REG_INTMS, intms);

printf("intmc : %x\n", intmc);
stdout_ctrl_register_human(NVME_REG_INTMC, intmc);

printf("aqa : %x\n", aqa);
stdout_ctrl_register_human(NVME_REG_AQA, aqa);

printf("asq : %"PRIx64"\n", asq);
stdout_ctrl_register_human(NVME_REG_ASQ, asq);

printf("acq : %"PRIx64"\n", acq);
stdout_ctrl_register_human(NVME_REG_ACQ, acq);

printf("cmbloc : %x\n", cmbloc);
stdout_registers_cmbloc(cmbloc, cmbsz);

printf("cmbsz : %x\n", cmbsz);
stdout_ctrl_register_human(NVME_REG_CMBSZ, cmbsz);
uint32_t value32 = (uint32_t)value64;

printf("bpinfo : %x\n", bpinfo);
stdout_ctrl_register_human(NVME_REG_BPINFO, bpinfo);
printf("%-8s: ", nvme_register_symbol_to_string(offset));

printf("bprsel : %x\n", bprsel);
stdout_ctrl_register_human(NVME_REG_BPRSEL, bprsel);
if (nvme_is_64bit_reg(offset))
printf("%"PRIx64"\n", value64);
else
printf("%x\n", value32);

printf("bpmbl : %"PRIx64"\n", bpmbl);
stdout_ctrl_register_human(NVME_REG_BPMBL, bpmbl);
if (human)
stdout_ctrl_register_human(offset, value64, &support);
}

printf("cmbmsc : %"PRIx64"\n", cmbmsc);
stdout_ctrl_register_human(NVME_REG_CMBMSC, cmbmsc);
void stdout_ctrl_registers(void *bar, bool fabrics)
{
uint64_t cap = mmio_read64(bar + NVME_REG_CAP);
uint32_t vs = mmio_read32(bar + NVME_REG_VS);
uint32_t cc = mmio_read32(bar + NVME_REG_CC);
uint32_t csts = mmio_read32(bar + NVME_REG_CSTS);
uint32_t nssr = mmio_read32(bar + NVME_REG_NSSR);
uint32_t crto = mmio_read32(bar + NVME_REG_CRTO);
uint32_t cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
uint32_t pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
bool human = stdout_print_ops.flags & VERBOSE ? true : false;

printf("cmbsts : %x\n", cmbsts);
stdout_ctrl_register_human(NVME_REG_CMBSTS, cmbsts);
if (cap != 0xffffffff)
stdout_ctrl_register_support(NVME_REG_CAP, mmio_read64(bar + NVME_REG_CAP), human, true);

printf("pmrcap : %x\n", pmrcap);
stdout_ctrl_register_human(NVME_REG_PMRCAP, pmrcap);
if (vs != 0xffffffff)
stdout_ctrl_register_support(NVME_REG_VS, vs, human, true);

printf("pmrctl : %x\n", pmrctl);
stdout_ctrl_register_human(NVME_REG_PMRCTL, pmrctl);
if (cc != 0xffffffff)
stdout_ctrl_register_support(NVME_REG_CC, cc, human, true);

printf("pmrsts : %x\n", pmrsts);
stdout_registers_pmrsts(pmrsts, pmrctl);
if (csts != 0xffffffff)
stdout_ctrl_register_support(NVME_REG_CSTS, csts, human, true);

printf("pmrebs : %x\n", pmrebs);
stdout_ctrl_register_human(NVME_REG_PMREBS, pmrebs);
if (nssr != 0xffffffff)
stdout_ctrl_register_support(NVME_REG_NSSR, nssr, human, true);

printf("pmrswtp : %x\n", pmrswtp);
stdout_ctrl_register_human(NVME_REG_PMRSWTP, pmrswtp);
if (crto != 0xffffffff)
stdout_ctrl_register_support(NVME_REG_CRTO, crto, human, true);

printf("pmrmscl : %#x\n", pmrmscl);
stdout_ctrl_register_human(NVME_REG_PMRMSCL, pmrmscl);
if (fabrics)
return;

printf("pmrmscu : %#x\n", pmrmscu);
stdout_ctrl_register_human(NVME_REG_PMRMSCU, pmrmscu);
}
} else {
if (cap != 0xffffffff)
printf("cap : %"PRIx64"\n", cap);
if (vs != 0xffffffff)
printf("version : %x\n", vs);
if (cc != 0xffffffff)
printf("cc : %x\n", cc);
if (csts != 0xffffffff)
printf("csts : %x\n", csts);
if (nssr != 0xffffffff)
printf("nssr : %x\n", nssr);
if (crto != 0xffffffff)
printf("crto : %x\n", crto);
if (!fabrics) {
printf("intms : %x\n", intms);
printf("intmc : %x\n", intmc);
printf("aqa : %x\n", aqa);
printf("asq : %"PRIx64"\n", asq);
printf("acq : %"PRIx64"\n", acq);
printf("cmbloc : %x\n", cmbloc);
printf("cmbsz : %x\n", cmbsz);
printf("bpinfo : %x\n", bpinfo);
printf("bprsel : %x\n", bprsel);
printf("bpmbl : %"PRIx64"\n", bpmbl);
printf("cmbmsc : %"PRIx64"\n", cmbmsc);
printf("cmbsts : %x\n", cmbsts);
printf("pmrcap : %x\n", pmrcap);
printf("pmrctl : %x\n", pmrctl);
printf("pmrsts : %x\n", pmrsts);
printf("pmrebs : %x\n", pmrebs);
printf("pmrswtp : %x\n", pmrswtp);
printf("pmrmscl : %#x\n", pmrmscl);
printf("pmrmscu : %#x\n", pmrmscu);
}
}
stdout_ctrl_register_support(NVME_REG_INTMS, mmio_read32(bar + NVME_REG_INTMS), human, true);
stdout_ctrl_register_support(NVME_REG_INTMC, mmio_read32(bar + NVME_REG_INTMC), human, true);
stdout_ctrl_register_support(NVME_REG_AQA, mmio_read32(bar + NVME_REG_AQA), human, true);
stdout_ctrl_register_support(NVME_REG_ASQ, mmio_read64(bar + NVME_REG_ASQ), human, true);
stdout_ctrl_register_support(NVME_REG_ACQ, mmio_read64(bar + NVME_REG_ACQ), human, true);
stdout_ctrl_register_support(NVME_REG_CMBLOC, mmio_read32(bar + NVME_REG_CMBLOC), human,
stdout_registers_cmbloc_support(cmbsz));
stdout_ctrl_register_support(NVME_REG_CMBSZ, cmbsz, human, true);
stdout_ctrl_register_support(NVME_REG_BPINFO, mmio_read32(bar + NVME_REG_BPINFO), human, true);
stdout_ctrl_register_support(NVME_REG_BPRSEL, mmio_read32(bar + NVME_REG_BPRSEL), human, true);
stdout_ctrl_register_support(NVME_REG_BPMBL, mmio_read64(bar + NVME_REG_BPMBL), human, true);
stdout_ctrl_register_support(NVME_REG_CMBMSC, mmio_read64(bar + NVME_REG_CMBMSC), human, true);
stdout_ctrl_register_support(NVME_REG_CMBSTS, mmio_read32(bar + NVME_REG_CMBSTS), human, true);
stdout_ctrl_register_support(NVME_REG_PMRCAP, mmio_read32(bar + NVME_REG_PMRCAP), human, true);
stdout_ctrl_register_support(NVME_REG_PMRCTL, pmrctl, human, true);
stdout_ctrl_register_support(NVME_REG_PMRSTS, mmio_read32(bar + NVME_REG_PMRSTS), human,
stdout_registers_pmrctl_ready(pmrctl));
stdout_ctrl_register_support(NVME_REG_PMREBS, mmio_read32(bar + NVME_REG_PMREBS), human, true);
stdout_ctrl_register_support(NVME_REG_PMRSWTP, mmio_read32(bar + NVME_REG_PMRSWTP), human, true);
stdout_ctrl_register_support(NVME_REG_PMRMSCL, mmio_read32(bar + NVME_REG_PMRMSCL), human, true);
stdout_ctrl_register_support(NVME_REG_PMRMSCU, mmio_read32(bar + NVME_REG_PMRMSCU), human, true);
}

static void stdout_single_property(int offset, uint64_t value64)
Expand All @@ -1733,30 +1665,25 @@ static void stdout_single_property(int offset, uint64_t value64)
return;
}

switch (offset) {
case NVME_REG_CAP:
printf("cap : %"PRIx64"\n", value64);
break;
case NVME_REG_VS:
printf("version : %x\n", value32);
break;
case NVME_REG_CC:
printf("cc : %x\n", value32);
break;
case NVME_REG_CSTS:
printf("csts : %x\n", value32);
break;
case NVME_REG_NSSR:
printf("nssr : %x\n", value32);
break;
case NVME_REG_CRTO:
printf("crto : %x\n", value32);
break;
default:
break;
if (nvme_is_fabrics_reg(offset)) {
printf("%s : ", nvme_register_symbol_to_string(offset));
switch (offset) {
case NVME_REG_CAP:
printf("%"PRIx64"\n", value64);
break;
case NVME_REG_VS:
case NVME_REG_CC:
case NVME_REG_CSTS:
case NVME_REG_NSSR:
case NVME_REG_CRTO:
printf("%x\n", value32);
break;
default:
break;
}
}

stdout_ctrl_register_human(offset, value64);
stdout_ctrl_register_human(offset, value64, NULL);
}

static void stdout_status(int status)
Expand Down

0 comments on commit de5ccae

Please sign in to comment.