Skip to content

Commit eb6014a

Browse files
ikegami-tigaw
authored andcommitted
nvme-print-json: update register print code to use libnvme definition
Use libnvme register definitions instead of the shift operator. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent a065b9d commit eb6014a

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

nvme-print-json.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,42 +1156,43 @@ static void json_registers_bpinfo(uint32_t bpinfo, struct json_object *r)
11561156
{
11571157
obj_add_uint_x(r, "bpinfo", bpinfo);
11581158

1159-
obj_add_uint(r, "Active Boot Partition ID (ABPID)", (bpinfo & 0x80000000) >> 31);
1160-
json_registers_bpinfo_brs((bpinfo & 0x3000000) >> 24, r);
1161-
obj_add_uint(r, "Boot Partition Size (BPSZ)", bpinfo & 0x7fff);
1159+
obj_add_uint(r, "Active Boot Partition ID (ABPID)", NVME_BPINFO_ABPID(bpinfo));
1160+
json_registers_bpinfo_brs(NVME_BPINFO_BRS(bpinfo), r);
1161+
obj_add_uint(r, "Boot Partition Size (BPSZ)", NVME_BPINFO_BPSZ(bpinfo));
11621162
}
11631163

11641164
static void json_registers_bprsel(uint32_t bprsel, struct json_object *r)
11651165
{
11661166
obj_add_uint_x(r, "bprsel", bprsel);
11671167

1168-
obj_add_uint(r, "Boot Partition Identifier (BPID)", (bprsel & 0x80000000) >> 31);
1169-
obj_add_uint_x(r, "Boot Partition Read Offset (BPROF)", (bprsel & 0x3ffffc00) >> 10);
1170-
obj_add_uint_x(r, "Boot Partition Read Size (BPRSZ)", bprsel & 0x3ff);
1168+
obj_add_uint(r, "Boot Partition Identifier (BPID)", NVME_BPRSEL_BPID(bprsel));
1169+
obj_add_uint_x(r, "Boot Partition Read Offset (BPROF)", NVME_BPRSEL_BPROF(bprsel));
1170+
obj_add_uint_x(r, "Boot Partition Read Size (BPRSZ)", NVME_BPRSEL_BPRSZ(bprsel));
11711171
}
11721172

11731173
static void json_registers_bpmbl(uint64_t bpmbl, struct json_object *r)
11741174
{
11751175
obj_add_prix64(r, "bpmbl", bpmbl);
11761176

1177-
obj_add_prix64(r, "Boot Partition Memory Buffer Base Address (BMBBA)", bpmbl);
1177+
obj_add_prix64(r, "Boot Partition Memory Buffer Base Address (BMBBA)",
1178+
(uint64_t)NVME_BPMBL_BMBBA(bpmbl));
11781179
}
11791180

11801181
static void json_registers_cmbmsc(uint64_t cmbmsc, struct json_object *r)
11811182
{
11821183
obj_add_prix64(r, "cmbmsc", cmbmsc);
11831184

1184-
obj_add_prix64(r, "Controller Base Address (CBA)", (cmbmsc & 0xfffffffffffff000) >> 12);
1185-
obj_add_prix64(r, "Controller Memory Space Enable (CMSE)", (cmbmsc & 2) >> 1);
1185+
obj_add_prix64(r, "Controller Base Address (CBA)", (uint64_t)NVME_CMBMSC_CBA(cmbmsc));
1186+
obj_add_prix64(r, "Controller Memory Space Enable (CMSE)", NVME_CMBMSC_CMSE(cmbmsc));
11861187
obj_add_str(r, "Capabilities Registers Enabled (CRE)",
1187-
cmbmsc & 1 ? "Enabled" : "Not enabled");
1188+
NVME_CMBMSC_CRE(cmbmsc) ? "Enabled" : "Not enabled");
11881189
}
11891190

11901191
static void json_registers_cmbsts(uint32_t cmbsts, struct json_object *r)
11911192
{
11921193
obj_add_uint_x(r, "cmbsts", cmbsts);
11931194

1194-
obj_add_uint_x(r, "Controller Base Address Invalid (CBAI)", cmbsts & 1);
1195+
obj_add_uint_x(r, "Controller Base Address Invalid (CBAI)", NVME_CMBSTS_CBAI(cmbsts));
11951196
}
11961197

11971198
static void json_registers_cmbebs(uint32_t cmbebs, struct json_object *r)
@@ -1200,11 +1201,11 @@ static void json_registers_cmbebs(uint32_t cmbebs, struct json_object *r)
12001201

12011202
obj_add_uint_nx(r, "cmbebs", cmbebs);
12021203

1203-
obj_add_uint_nx(r, "CMB Elasticity Buffer Size Base (CMBWBZ)", cmbebs >> 8);
1204-
sprintf(buffer, "%s", cmbebs & 0x10 ? "shall" : "may");
1204+
obj_add_uint_nx(r, "CMB Elasticity Buffer Size Base (CMBWBZ)", NVME_CMBEBS_CMBWBZ(cmbebs));
1205+
sprintf(buffer, "%s", NVME_CMBEBS_RBB(cmbebs) ? "shall" : "may");
12051206
obj_add_str(r, "CMB Read Bypass Behavior (CMBRBB)", buffer);
12061207
obj_add_str(r, "CMB Elasticity Buffer Size Units (CMBSZU)",
1207-
nvme_register_unit_to_string(cmbebs & 0xf));
1208+
nvme_register_unit_to_string(NVME_CMBEBS_CMBSZU(cmbebs)));
12081209
}
12091210

12101211
static void json_registers_cmbswtp(uint32_t cmbswtp, struct json_object *r)
@@ -1213,8 +1214,9 @@ static void json_registers_cmbswtp(uint32_t cmbswtp, struct json_object *r)
12131214

12141215
obj_add_uint_nx(r, "cmbswtp", cmbswtp);
12151216

1216-
obj_add_uint_nx(r, "CMB Sustained Write Throughput (CMBSWTV)", cmbswtp >> 8);
1217-
sprintf(str, "%s/second", nvme_register_unit_to_string(cmbswtp & 0xf));
1217+
obj_add_uint_nx(r, "CMB Sustained Write Throughput (CMBSWTV)",
1218+
NVME_CMBSWTP_CMBSWTV(cmbswtp));
1219+
sprintf(str, "%s/second", nvme_register_unit_to_string(NVME_CMBSWTP_CMBSWTU(cmbswtp)));
12181220
obj_add_str(r, "CMB Sustained Write Throughput Units (CMBSWTU)", str);
12191221
}
12201222

0 commit comments

Comments
 (0)