Bug Summary

File:.build-ci/../nvme-print-json.c
Warning:line 2332, column 2
Argument to free() is offset by 2 bytes from the start of memory allocated by malloc()

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name nvme-print-json.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -fcoverage-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -resource-dir /usr/lib/llvm-19/lib/clang/19 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I nvme.p -I . -I .. -I ccan -I ../ccan -I libnvme/src -I ../libnvme/src -I /usr/include/json-c -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -std=gnu99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-opt-analyze-headers -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-06-24-175442-590-1 -x c ../nvme-print-json.c
1// SPDX-License-Identifier: GPL-2.0-or-later
2
3#include <assert.h>
4#include <errno(*__errno_location ()).h>
5#include <time.h>
6#include <sys/types.h>
7
8#ifdef CONFIG_FABRICS
9#include <sys/socket.h>
10#include <arpa/inet.h>
11#endif
12
13#include <ccan/compiler/compiler.h>
14
15#include <libnvme.h>
16
17#include "nvme-print.h"
18
19#include "util/json.h"
20#include "logging.h"
21#include "nvme.h"
22#include "common.h"
23
24#define ERROR_MSG_LEN100 100
25#define NAME_LEN128 128
26#define BUF_LEN320 320
27#define VAL_LEN4096 4096
28#define BYTE_TO_BIT(byte)((byte) * 8) ((byte) * 8)
29#define MS_TO_SEC(time)((time) / 1000) ((time) / 1000)
30#define MS500_TO_MS(time)((time) * 500) ((time) * 500)
31#define MS500_TO_SEC(time)(((((time) * 500)) / 1000)) (MS_TO_SEC(MS500_TO_MS(time))((((time) * 500)) / 1000))
32
33#define array_add_objjson_array_add_value_object json_array_add_value_object
34#define array_add_strjson_array_add_value_string json_array_add_value_string
35
36#define obj_add_arrayjson_object_add_value_array json_object_add_value_array
37#define obj_add_intjson_object_add_value_int json_object_add_value_int
38#define obj_add_objjson_object_add_value_object json_object_add_value_object
39#define obj_add_uintjson_object_add_value_uint json_object_add_value_uint
40#define obj_add_uint128json_object_add_value_uint128 json_object_add_value_uint128
41#define obj_add_uint64json_object_add_value_uint64 json_object_add_value_uint64
42#define obj_add_strjson_object_add_value_string json_object_add_value_string
43#define obj_add_uint_02xjson_object_add_uint_02x json_object_add_uint_02x
44#define obj_add_uint_0xjson_object_add_uint_0x json_object_add_uint_0x
45#define obj_add_byte_arrayjson_object_add_byte_array json_object_add_byte_array
46#define obj_add_nprix64json_object_add_nprix64 json_object_add_nprix64
47#define obj_add_uint_0nxjson_object_add_uint_0nx json_object_add_uint_0nx
48#define obj_add_0nprix64json_object_add_0nprix64 json_object_add_0nprix64
49#define obj_add_stringjson_object_add_string json_object_add_string
50
51static const uint8_t zero_uuid[16] = { 0 };
52static struct print_ops json_print_ops;
53static struct json_object *json_r;
54static int json_init;
55
56static void json_feature_show_fields(enum nvme_features_id fid, unsigned int result,
57 unsigned char *buf);
58
59static void d_json(unsigned char *buf, int len, int width, int group, struct json_object *array)
60{
61 int i;
62 char ascii[32 + 1] = { 0 };
63
64 assert(width < sizeof(ascii))((void) sizeof ((width < sizeof(ascii)) ? 1 : 0), __extension__
({ if (width < sizeof(ascii)) ; else __assert_fail ("width < sizeof(ascii)"
, "../nvme-print-json.c", 64, __extension__ __PRETTY_FUNCTION__
); }))
;
65
66 for (i = 0; i < len; i++) {
67 ascii[i % width] = (buf[i] >= '!' && buf[i] <= '~') ? buf[i] : '.';
68 if (!((i + 1) % width)) {
69 array_add_strjson_array_add_value_string(array, ascii);
70 memset(ascii, 0, sizeof(ascii));
71 }
72 }
73
74 if (strlen(ascii)) {
75 ascii[i % width + 1] = '\0';
76 array_add_strjson_array_add_value_string(array, ascii);
77 }
78}
79
80static void obj_d(struct json_object *o, const char *k, unsigned char *buf, int len, int width,
81 int group)
82{
83 struct json_object *data = json_create_array()json_object_new_array();
84
85 d_json(buf, len, width, group, data);
86 obj_add_array(o, k, data)json_object_object_add(o, k, data);
87}
88
89static void obj_add_uint_x(struct json_object *o, const char *k, __u32 v)
90{
91 char str[STR_LEN100];
92
93 sprintf(str, "%x", v);
94 obj_add_strjson_object_add_value_string(o, k, str);
95}
96
97static void obj_add_uint_nx(struct json_object *o, const char *k, __u32 v)
98{
99 char str[STR_LEN100];
100
101 sprintf(str, "%#x", v);
102 obj_add_strjson_object_add_value_string(o, k, str);
103}
104
105static void obj_add_prix64(struct json_object *o, const char *k, uint64_t v)
106{
107 char str[STR_LEN100];
108
109 sprintf(str, "%"PRIx64"l" "x""", v);
110 obj_add_strjson_object_add_value_string(o, k, str);
111}
112
113static void obj_add_ctrl_address_details(struct json_object *o, const char *k,
114 libnvme_ctrl_t c)
115{
116 struct json_object *address_details = json_create_object()json_object_new_object();
117 const char *value;
118 bool_Bool has_value = false0;
119
120 value = libnvme_ctrl_get_traddr(c);
121 if (value) {
122 obj_add_strjson_object_add_value_string(address_details, "traddr", value);
123 has_value = true1;
124 }
125
126 value = libnvme_ctrl_get_host_traddr(c);
127 if (value) {
128 obj_add_strjson_object_add_value_string(address_details, "host_traddr", value);
129 has_value = true1;
130 }
131
132 value = libnvme_ctrl_get_host_iface(c);
133 if (value) {
134 obj_add_strjson_object_add_value_string(address_details, "host_iface", value);
135 has_value = true1;
136 }
137
138 value = libnvme_ctrl_get_trsvcid(c);
139 if (value) {
140 obj_add_strjson_object_add_value_string(address_details, "trsvcid", value);
141 has_value = true1;
142 }
143
144 if (!has_value) {
145 json_free_object(address_details)json_object_put(address_details);
146 return;
147 }
148
149 obj_add_obj(o, k, address_details)json_object_object_add(o, k, address_details);
150}
151
152static void obj_add_int_secs(struct json_object *o, const char *k, int v)
153{
154 char str[STR_LEN100];
155
156 sprintf(str, "%d secs", v);
157 obj_add_strjson_object_add_value_string(o, k, str);
158}
159
160static void obj_add_result(struct json_object *o, const char *v, ...)
161{
162 va_list ap;
163
164 __cleanup_free__attribute__((cleanup(freep))) char *value = NULL((void*)0);
165
166 va_start(ap, v)__builtin_va_start(ap, v);
167
168 if (vasprintf(&value, v, ap) < 0)
169 value = NULL((void*)0);
170
171 obj_add_strjson_object_add_value_string(o, "Result", value ? value : alloc_error);
172
173 va_end(ap)__builtin_va_end(ap);
174}
175
176static void obj_add_key(struct json_object *o, const char *k, const char *v, ...)
177{
178 va_list ap;
179
180 __cleanup_free__attribute__((cleanup(freep))) char *value = NULL((void*)0);
181
182 va_start(ap, v)__builtin_va_start(ap, v);
183
184 if (vasprintf(&value, v, ap) < 0)
185 value = NULL((void*)0);
186
187 obj_add_strjson_object_add_value_string(o, k, value ? value : alloc_error);
188
189 va_end(ap)__builtin_va_end(ap);
190}
191
192struct json_object *obj_create_array_obj(struct json_object *o, const char *k)
193{
194 struct json_object *array = json_create_array()json_object_new_array();
195 struct json_object *obj = json_create_object()json_object_new_object();
196
197 obj_add_array(o, k, array)json_object_object_add(o, k, array);
198 array_add_obj(array, obj)json_object_array_add(array, obj);
199
200 return obj;
201}
202
203static struct json_object *obj_create(const char *k)
204{
205 struct json_object *array;
206 struct json_object *obj = json_create_object()json_object_new_object();
207
208 if (json_r) {
209 array = json_create_array()json_object_new_array();
210 obj_add_array(json_r, k, array)json_object_object_add(json_r, k, array);
211 array_add_obj(array, obj)json_object_array_add(array, obj);
212 }
213
214 return obj;
215}
216
217void json_print(struct json_object *r)
218{
219 json_print_object(r, NULL)printf("%s", json_object_to_json_string_ext(r, (1 << 1)
| (1 << 4)))
;
220 printf("\n");
221 json_free_object(r)json_object_put(r);
222}
223
224static void obj_print(struct json_object *o)
225{
226 if (!json_r)
227 json_print(o);
228}
229
230static void json_id_iocs_iocsc(struct json_object *obj_iocsc, __u64 iocsc)
231{
232 __u8 cpncs = NVME_GET(iocsc, IOCS_IOCSC_CPNCS)(((iocsc) >> NVME_IOCS_IOCSC_CPNCS_SHIFT) & NVME_IOCS_IOCSC_CPNCS_MASK
)
;
233 __u8 slmcs = NVME_GET(iocsc, IOCS_IOCSC_SLMCS)(((iocsc) >> NVME_IOCS_IOCSC_SLMCS_SHIFT) & NVME_IOCS_IOCSC_SLMCS_MASK
)
;
234 __u8 znscs = NVME_GET(iocsc, IOCS_IOCSC_ZNSCS)(((iocsc) >> NVME_IOCS_IOCSC_ZNSCS_SHIFT) & NVME_IOCS_IOCSC_ZNSCS_MASK
)
;
235 __u8 kvcs = NVME_GET(iocsc, IOCS_IOCSC_KVCS)(((iocsc) >> NVME_IOCS_IOCSC_KVCS_SHIFT) & NVME_IOCS_IOCSC_KVCS_MASK
)
;
236 __u8 nvmcs = NVME_GET(iocsc, IOCS_IOCSC_NVMCS)(((iocsc) >> NVME_IOCS_IOCSC_NVMCS_SHIFT) & NVME_IOCS_IOCSC_NVMCS_MASK
)
;
237
238 obj_add_strjson_object_add_value_string(obj_iocsc, "Computational Programs Namespace Command Set", cpncs ?
239 "Selected" : "Not selected");
240 obj_add_strjson_object_add_value_string(obj_iocsc, "Subsystem Local Memory Command Set", slmcs ?
241 "Selected" : "Not selected");
242 obj_add_strjson_object_add_value_string(obj_iocsc, "Zoned Namespace Command Set", znscs ? "Selected" : "Not selected");
243 obj_add_strjson_object_add_value_string(obj_iocsc, "Key Value Command Set", kvcs ? "Selected" : "Not selected");
244 obj_add_strjson_object_add_value_string(obj_iocsc, "NVM Command Set", nvmcs ? "Selected" : "Not selected");
245}
246
247static bool_Bool verbose_mode(void)
248{
249 return json_print_ops.flags & VERBOSE;
250}
251
252static void json_id_iocs(struct nvme_id_iocs *iocs)
253{
254 struct json_object *r = json_create_object()json_object_new_object();
255 struct json_object *obj_iocsc;
256 char json_str[STR_LEN100];
257 __u16 i;
258
259 for (i = 0; i < ARRAY_SIZE(iocs->iocsc)(sizeof(iocs->iocsc) / sizeof((iocs->iocsc)[0])); i++) {
260 if (iocs->iocsc[i]) {
261 sprintf(json_str, "I/O Command Set Combination[%u]", i);
262 obj_add_uint64(r, json_str, le64_to_cpu(iocs->iocsc[i]))json_object_object_add(r, json_str, json_object_new_uint64(le64_to_cpu
(iocs->iocsc[i])))
;
263
264 obj_iocsc = json_create_object()json_object_new_object();
265 sprintf(json_str, "IOCSC%u", i);
266 json_id_iocs_iocsc(obj_iocsc, le64_to_cpu(iocs->iocsc[i]));
267 obj_add_obj(r, json_str, obj_iocsc)json_object_object_add(r, json_str, obj_iocsc);
268 }
269 }
270
271 json_print(r);
272}
273
274static void json_nvme_id_ns_lbaf(struct nvme_id_ns *ns, int i, struct json_object *lbafs)
275{
276 struct json_object *lbaf = json_create_object()json_object_new_object();
277 __u8 flbas;
278
279 nvme_id_ns_flbas_to_lbaf_inuse(ns->flbas, &flbas);
280
281 if (verbose_mode()) {
282 obj_add_int(lbaf, "LBA Format", i)json_object_object_add(lbaf, "LBA Format", json_object_new_int
(i))
;
283 obj_add_stringjson_object_add_string(lbaf, "Metadata Size", "%d bytes", le16_to_cpu(ns->lbaf[i].ms));
284 obj_add_stringjson_object_add_string(lbaf, "Data Size", "%d bytes", 1 << ns->lbaf[i].ds);
285 obj_add_stringjson_object_add_string(lbaf, "Relative Performance", "0x%x %s", ns->lbaf[i].rp,
286 ns->lbaf[i].rp == 3 ? "Degraded" : ns->lbaf[i].rp == 2 ? "Good" :
287 ns->lbaf[i].rp == 1 ? "Better" : "Best");
288 obj_add_strjson_object_add_value_string(lbaf, "in use", i == flbas ? "yes" : "no");
289 } else {
290 obj_add_int(lbaf, "lbaf", i)json_object_object_add(lbaf, "lbaf", json_object_new_int(i));
291 obj_add_int(lbaf, "ms", le16_to_cpu(ns->lbaf[i].ms))json_object_object_add(lbaf, "ms", json_object_new_int(le16_to_cpu
(ns->lbaf[i].ms)))
;
292 obj_add_int(lbaf, "ds", ns->lbaf[i].ds)json_object_object_add(lbaf, "ds", json_object_new_int(ns->
lbaf[i].ds))
;
293 obj_add_int(lbaf, "rp", ns->lbaf[i].rp)json_object_object_add(lbaf, "rp", json_object_new_int(ns->
lbaf[i].rp))
;
294 obj_add_int(lbaf, "in_use", i == flbas)json_object_object_add(lbaf, "in_use", json_object_new_int(i ==
flbas))
;
295 }
296
297 array_add_obj(lbafs, lbaf)json_object_array_add(lbafs, lbaf);
298}
299
300static void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
301 unsigned int lba_index, bool_Bool cap_only)
302{
303 char nguid_buf[2 * sizeof(ns->nguid) + 1],
304 eui64_buf[2 * sizeof(ns->eui64) + 1];
305 char *nguid = nguid_buf, *eui64 = eui64_buf;
306 struct json_object *r = json_create_object()json_object_new_object();
307 struct json_object *lbafs = json_create_array()json_object_new_array();
308 struct json_object *vs = json_create_array()json_object_new_array();
309 int i;
310 nvme_uint128_t nvmcap = le128_to_cpu(ns->nvmcap);
311
312 if (!cap_only) {
313 obj_add_uint64(r, "nsze", le64_to_cpu(ns->nsze))json_object_object_add(r, "nsze", json_object_new_uint64(le64_to_cpu
(ns->nsze)))
;
314 obj_add_uint64(r, "ncap", le64_to_cpu(ns->ncap))json_object_object_add(r, "ncap", json_object_new_uint64(le64_to_cpu
(ns->ncap)))
;
315 obj_add_uint64(r, "nuse", le64_to_cpu(ns->nuse))json_object_object_add(r, "nuse", json_object_new_uint64(le64_to_cpu
(ns->nuse)))
;
316 obj_add_int(r, "nsfeat", ns->nsfeat)json_object_object_add(r, "nsfeat", json_object_new_int(ns->
nsfeat))
;
317 }
318
319 obj_add_int(r, "nlbaf", ns->nlbaf)json_object_object_add(r, "nlbaf", json_object_new_int(ns->
nlbaf))
;
320
321 if (!cap_only)
322 obj_add_int(r, "flbas", ns->flbas)json_object_object_add(r, "flbas", json_object_new_int(ns->
flbas))
;
323
324 obj_add_int(r, "mc", ns->mc)json_object_object_add(r, "mc", json_object_new_int(ns->mc
))
;
325 obj_add_int(r, "dpc", ns->dpc)json_object_object_add(r, "dpc", json_object_new_int(ns->dpc
))
;
326
327 if (!cap_only) {
328 obj_add_int(r, "dps", ns->dps)json_object_object_add(r, "dps", json_object_new_int(ns->dps
))
;
329 obj_add_int(r, "nmic", ns->nmic)json_object_object_add(r, "nmic", json_object_new_int(ns->
nmic))
;
330 obj_add_int(r, "rescap", ns->rescap)json_object_object_add(r, "rescap", json_object_new_int(ns->
rescap))
;
331 obj_add_int(r, "fpi", ns->fpi)json_object_object_add(r, "fpi", json_object_new_int(ns->fpi
))
;
332 obj_add_int(r, "dlfeat", ns->dlfeat)json_object_object_add(r, "dlfeat", json_object_new_int(ns->
dlfeat))
;
333 obj_add_int(r, "nawun", le16_to_cpu(ns->nawun))json_object_object_add(r, "nawun", json_object_new_int(le16_to_cpu
(ns->nawun)))
;
334 obj_add_int(r, "nawupf", le16_to_cpu(ns->nawupf))json_object_object_add(r, "nawupf", json_object_new_int(le16_to_cpu
(ns->nawupf)))
;
335 obj_add_int(r, "nacwu", le16_to_cpu(ns->nacwu))json_object_object_add(r, "nacwu", json_object_new_int(le16_to_cpu
(ns->nacwu)))
;
336 obj_add_int(r, "nabsn", le16_to_cpu(ns->nabsn))json_object_object_add(r, "nabsn", json_object_new_int(le16_to_cpu
(ns->nabsn)))
;
337 obj_add_int(r, "nabo", le16_to_cpu(ns->nabo))json_object_object_add(r, "nabo", json_object_new_int(le16_to_cpu
(ns->nabo)))
;
338 obj_add_int(r, "nabspf", le16_to_cpu(ns->nabspf))json_object_object_add(r, "nabspf", json_object_new_int(le16_to_cpu
(ns->nabspf)))
;
339 obj_add_int(r, "noiob", le16_to_cpu(ns->noiob))json_object_object_add(r, "noiob", json_object_new_int(le16_to_cpu
(ns->noiob)))
;
340 obj_add_uint128(r, "nvmcap", nvmcap)json_object_object_add(r, "nvmcap", util_json_object_new_uint128
(nvmcap))
;
341
342 if (ns->nsfeat & 0x30) {
343 obj_add_int(r, "npwg", le16_to_cpu(ns->npwg))json_object_object_add(r, "npwg", json_object_new_int(le16_to_cpu
(ns->npwg)))
;
344 obj_add_int(r, "npwa", le16_to_cpu(ns->npwa))json_object_object_add(r, "npwa", json_object_new_int(le16_to_cpu
(ns->npwa)))
;
345 if (ns->nsfeat & 0x10)
346 obj_add_int(r, "npdg", le16_to_cpu(ns->npdg))json_object_object_add(r, "npdg", json_object_new_int(le16_to_cpu
(ns->npdg)))
;
347 obj_add_int(r, "npda", le16_to_cpu(ns->npda))json_object_object_add(r, "npda", json_object_new_int(le16_to_cpu
(ns->npda)))
;
348 obj_add_int(r, "nows", le16_to_cpu(ns->nows))json_object_object_add(r, "nows", json_object_new_int(le16_to_cpu
(ns->nows)))
;
349 }
350
351 obj_add_int(r, "mssrl", le16_to_cpu(ns->mssrl))json_object_object_add(r, "mssrl", json_object_new_int(le16_to_cpu
(ns->mssrl)))
;
352 obj_add_uint(r, "mcl", le32_to_cpu(ns->mcl))json_object_object_add(r, "mcl", json_object_new_uint64(le32_to_cpu
(ns->mcl)))
;
353 obj_add_int(r, "msrc", ns->msrc)json_object_object_add(r, "msrc", json_object_new_int(ns->
msrc))
;
354 obj_add_uint(r, "kpios", ns->kpios)json_object_object_add(r, "kpios", json_object_new_uint64(ns->
kpios))
;
355 }
356
357 obj_add_int(r, "nulbaf", ns->nulbaf)json_object_object_add(r, "nulbaf", json_object_new_int(ns->
nulbaf))
;
358
359 if (!cap_only) {
360 obj_add_uint(r, "kpiodaag", le32_to_cpu(ns->kpiodaag))json_object_object_add(r, "kpiodaag", json_object_new_uint64(
le32_to_cpu(ns->kpiodaag)))
;
361 obj_add_uint(r, "anagrpid", le32_to_cpu(ns->anagrpid))json_object_object_add(r, "anagrpid", json_object_new_uint64(
le32_to_cpu(ns->anagrpid)))
;
362 obj_add_int(r, "nsattr", ns->nsattr)json_object_object_add(r, "nsattr", json_object_new_int(ns->
nsattr))
;
363 obj_add_int(r, "nvmsetid", le16_to_cpu(ns->nvmsetid))json_object_object_add(r, "nvmsetid", json_object_new_int(le16_to_cpu
(ns->nvmsetid)))
;
364 obj_add_int(r, "endgid", le16_to_cpu(ns->endgid))json_object_object_add(r, "endgid", json_object_new_int(le16_to_cpu
(ns->endgid)))
;
365
366 memset(eui64, 0, sizeof(eui64_buf));
367
368 for (i = 0; i < sizeof(ns->eui64); i++)
369 eui64 += sprintf(eui64, "%02x", ns->eui64[i]);
370
371 memset(nguid, 0, sizeof(nguid_buf));
372
373 for (i = 0; i < sizeof(ns->nguid); i++)
374 nguid += sprintf(nguid, "%02x", ns->nguid[i]);
375
376 obj_add_strjson_object_add_value_string(r, "nguid", nguid_buf);
377 obj_add_strjson_object_add_value_string(r, "eui64", eui64_buf);
378 }
379
380 obj_add_array(r, "lbafs", lbafs)json_object_object_add(r, "lbafs", lbafs);
381
382 for (i = 0; i <= ns->nlbaf; i++)
383 json_nvme_id_ns_lbaf(ns, i, lbafs);
384
385 d_json(ns->vs, strnlen((const char *)ns->vs, sizeof(ns->vs)), 16, 1, vs);
386 obj_add_array(r, "vs", vs)json_object_object_add(r, "vs", vs);
387
388 json_print(r);
389}
390
391void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, const char *product_name,
392 void (*vs)(__u8 *vs, struct json_object *r))
393{
394 struct json_object *r = json_create_object()json_object_new_object();
395 struct json_object *psds = json_create_array()json_object_new_array();
396 nvme_uint128_t tnvmcap = le128_to_cpu(ctrl->tnvmcap);
397 nvme_uint128_t unvmcap = le128_to_cpu(ctrl->unvmcap);
398 nvme_uint128_t megcap = le128_to_cpu(ctrl->megcap);
399 nvme_uint128_t maxdna = le128_to_cpu(ctrl->maxdna);
400 char sn[sizeof(ctrl->sn) + 1], mn[sizeof(ctrl->mn) + 1],
401 fr[sizeof(ctrl->fr) + 1], subnqn[sizeof(ctrl->subnqn) + 1];
402 __u32 ieee = ctrl->ieee[2] << 16 | ctrl->ieee[1] << 8 | ctrl->ieee[0];
403 int i;
404
405 snprintf(sn, sizeof(sn), "%-.*s", (int)sizeof(ctrl->sn), ctrl->sn);
406 snprintf(mn, sizeof(mn), "%-.*s", (int)sizeof(ctrl->mn), ctrl->mn);
407 snprintf(fr, sizeof(fr), "%-.*s", (int)sizeof(ctrl->fr), ctrl->fr);
408 snprintf(subnqn, sizeof(subnqn), "%-.*s", (int)sizeof(ctrl->subnqn), ctrl->subnqn);
409
410 if (product_name)
411 obj_add_strjson_object_add_value_string(r, "product_name", product_name);
412
413 obj_add_int(r, "vid", le16_to_cpu(ctrl->vid))json_object_object_add(r, "vid", json_object_new_int(le16_to_cpu
(ctrl->vid)))
;
414 obj_add_int(r, "ssvid", le16_to_cpu(ctrl->ssvid))json_object_object_add(r, "ssvid", json_object_new_int(le16_to_cpu
(ctrl->ssvid)))
;
415 obj_add_strjson_object_add_value_string(r, "sn", sn);
416 obj_add_strjson_object_add_value_string(r, "mn", mn);
417 obj_add_strjson_object_add_value_string(r, "fr", fr);
418 obj_add_int(r, "rab", ctrl->rab)json_object_object_add(r, "rab", json_object_new_int(ctrl->
rab))
;
419 obj_add_int(r, "ieee", ieee)json_object_object_add(r, "ieee", json_object_new_int(ieee));
420 obj_add_int(r, "cmic", ctrl->cmic)json_object_object_add(r, "cmic", json_object_new_int(ctrl->
cmic))
;
421 obj_add_int(r, "mdts", ctrl->mdts)json_object_object_add(r, "mdts", json_object_new_int(ctrl->
mdts))
;
422 obj_add_int(r, "cntlid", le16_to_cpu(ctrl->cntlid))json_object_object_add(r, "cntlid", json_object_new_int(le16_to_cpu
(ctrl->cntlid)))
;
423 obj_add_uint(r, "ver", le32_to_cpu(ctrl->ver))json_object_object_add(r, "ver", json_object_new_uint64(le32_to_cpu
(ctrl->ver)))
;
424 obj_add_uint(r, "rtd3r", le32_to_cpu(ctrl->rtd3r))json_object_object_add(r, "rtd3r", json_object_new_uint64(le32_to_cpu
(ctrl->rtd3r)))
;
425 obj_add_uint(r, "rtd3e", le32_to_cpu(ctrl->rtd3e))json_object_object_add(r, "rtd3e", json_object_new_uint64(le32_to_cpu
(ctrl->rtd3e)))
;
426 obj_add_uint(r, "oaes", le32_to_cpu(ctrl->oaes))json_object_object_add(r, "oaes", json_object_new_uint64(le32_to_cpu
(ctrl->oaes)))
;
427 obj_add_uint(r, "ctratt", le32_to_cpu(ctrl->ctratt))json_object_object_add(r, "ctratt", json_object_new_uint64(le32_to_cpu
(ctrl->ctratt)))
;
428 obj_add_int(r, "rrls", le16_to_cpu(ctrl->rrls))json_object_object_add(r, "rrls", json_object_new_int(le16_to_cpu
(ctrl->rrls)))
;
429 obj_add_int(r, "bpcap", ctrl->bpcap)json_object_object_add(r, "bpcap", json_object_new_int(ctrl->
bpcap))
;
430 obj_add_uint(r, "nssl", le32_to_cpu(ctrl->nssl))json_object_object_add(r, "nssl", json_object_new_uint64(le32_to_cpu
(ctrl->nssl)))
;
431 obj_add_int(r, "plsi", ctrl->plsi)json_object_object_add(r, "plsi", json_object_new_int(ctrl->
plsi))
;
432 obj_add_int(r, "cntrltype", ctrl->cntrltype)json_object_object_add(r, "cntrltype", json_object_new_int(ctrl
->cntrltype))
;
433 obj_add_strjson_object_add_value_string(r, "fguid", util_uuid_to_string(ctrl->fguid));
434 obj_add_int(r, "crdt1", le16_to_cpu(ctrl->crdt1))json_object_object_add(r, "crdt1", json_object_new_int(le16_to_cpu
(ctrl->crdt1)))
;
435 obj_add_int(r, "crdt2", le16_to_cpu(ctrl->crdt2))json_object_object_add(r, "crdt2", json_object_new_int(le16_to_cpu
(ctrl->crdt2)))
;
436 obj_add_int(r, "crdt3", le16_to_cpu(ctrl->crdt3))json_object_object_add(r, "crdt3", json_object_new_int(le16_to_cpu
(ctrl->crdt3)))
;
437 obj_add_int(r, "crcap", ctrl->crcap)json_object_object_add(r, "crcap", json_object_new_int(ctrl->
crcap))
;
438 obj_add_int(r, "nvmsr", ctrl->nvmsr)json_object_object_add(r, "nvmsr", json_object_new_int(ctrl->
nvmsr))
;
439 obj_add_int(r, "vwci", ctrl->vwci)json_object_object_add(r, "vwci", json_object_new_int(ctrl->
vwci))
;
440 obj_add_int(r, "mec", ctrl->mec)json_object_object_add(r, "mec", json_object_new_int(ctrl->
mec))
;
441 obj_add_int(r, "oacs", le16_to_cpu(ctrl->oacs))json_object_object_add(r, "oacs", json_object_new_int(le16_to_cpu
(ctrl->oacs)))
;
442 obj_add_int(r, "acl", ctrl->acl)json_object_object_add(r, "acl", json_object_new_int(ctrl->
acl))
;
443 obj_add_int(r, "aerl", ctrl->aerl)json_object_object_add(r, "aerl", json_object_new_int(ctrl->
aerl))
;
444 obj_add_int(r, "frmw", ctrl->frmw)json_object_object_add(r, "frmw", json_object_new_int(ctrl->
frmw))
;
445 obj_add_int(r, "lpa", ctrl->lpa)json_object_object_add(r, "lpa", json_object_new_int(ctrl->
lpa))
;
446 obj_add_int(r, "elpe", ctrl->elpe)json_object_object_add(r, "elpe", json_object_new_int(ctrl->
elpe))
;
447 obj_add_int(r, "npss", ctrl->npss)json_object_object_add(r, "npss", json_object_new_int(ctrl->
npss))
;
448 obj_add_int(r, "avscc", ctrl->avscc)json_object_object_add(r, "avscc", json_object_new_int(ctrl->
avscc))
;
449 obj_add_int(r, "apsta", ctrl->apsta)json_object_object_add(r, "apsta", json_object_new_int(ctrl->
apsta))
;
450 obj_add_int(r, "wctemp", le16_to_cpu(ctrl->wctemp))json_object_object_add(r, "wctemp", json_object_new_int(le16_to_cpu
(ctrl->wctemp)))
;
451 obj_add_int(r, "cctemp", le16_to_cpu(ctrl->cctemp))json_object_object_add(r, "cctemp", json_object_new_int(le16_to_cpu
(ctrl->cctemp)))
;
452 obj_add_int(r, "mtfa", le16_to_cpu(ctrl->mtfa))json_object_object_add(r, "mtfa", json_object_new_int(le16_to_cpu
(ctrl->mtfa)))
;
453 obj_add_uint(r, "hmpre", le32_to_cpu(ctrl->hmpre))json_object_object_add(r, "hmpre", json_object_new_uint64(le32_to_cpu
(ctrl->hmpre)))
;
454 obj_add_uint(r, "hmmin", le32_to_cpu(ctrl->hmmin))json_object_object_add(r, "hmmin", json_object_new_uint64(le32_to_cpu
(ctrl->hmmin)))
;
455 obj_add_uint128(r, "tnvmcap", tnvmcap)json_object_object_add(r, "tnvmcap", util_json_object_new_uint128
(tnvmcap))
;
456 obj_add_uint128(r, "unvmcap", unvmcap)json_object_object_add(r, "unvmcap", util_json_object_new_uint128
(unvmcap))
;
457 obj_add_uint(r, "rpmbs", le32_to_cpu(ctrl->rpmbs))json_object_object_add(r, "rpmbs", json_object_new_uint64(le32_to_cpu
(ctrl->rpmbs)))
;
458 obj_add_int(r, "edstt", le16_to_cpu(ctrl->edstt))json_object_object_add(r, "edstt", json_object_new_int(le16_to_cpu
(ctrl->edstt)))
;
459 obj_add_int(r, "dsto", ctrl->dsto)json_object_object_add(r, "dsto", json_object_new_int(ctrl->
dsto))
;
460 obj_add_int(r, "fwug", ctrl->fwug)json_object_object_add(r, "fwug", json_object_new_int(ctrl->
fwug))
;
461 obj_add_int(r, "kas", le16_to_cpu(ctrl->kas))json_object_object_add(r, "kas", json_object_new_int(le16_to_cpu
(ctrl->kas)))
;
462 obj_add_int(r, "hctma", le16_to_cpu(ctrl->hctma))json_object_object_add(r, "hctma", json_object_new_int(le16_to_cpu
(ctrl->hctma)))
;
463 obj_add_int(r, "mntmt", le16_to_cpu(ctrl->mntmt))json_object_object_add(r, "mntmt", json_object_new_int(le16_to_cpu
(ctrl->mntmt)))
;
464 obj_add_int(r, "mxtmt", le16_to_cpu(ctrl->mxtmt))json_object_object_add(r, "mxtmt", json_object_new_int(le16_to_cpu
(ctrl->mxtmt)))
;
465 obj_add_uint(r, "sanicap", le32_to_cpu(ctrl->sanicap))json_object_object_add(r, "sanicap", json_object_new_uint64(le32_to_cpu
(ctrl->sanicap)))
;
466 obj_add_uint(r, "hmminds", le32_to_cpu(ctrl->hmminds))json_object_object_add(r, "hmminds", json_object_new_uint64(le32_to_cpu
(ctrl->hmminds)))
;
467 obj_add_int(r, "hmmaxd", le16_to_cpu(ctrl->hmmaxd))json_object_object_add(r, "hmmaxd", json_object_new_int(le16_to_cpu
(ctrl->hmmaxd)))
;
468 obj_add_int(r, "nsetidmax", le16_to_cpu(ctrl->nsetidmax))json_object_object_add(r, "nsetidmax", json_object_new_int(le16_to_cpu
(ctrl->nsetidmax)))
;
469 obj_add_int(r, "endgidmax", le16_to_cpu(ctrl->endgidmax))json_object_object_add(r, "endgidmax", json_object_new_int(le16_to_cpu
(ctrl->endgidmax)))
;
470 obj_add_int(r, "anatt", ctrl->anatt)json_object_object_add(r, "anatt", json_object_new_int(ctrl->
anatt))
;
471 obj_add_int(r, "anacap", ctrl->anacap)json_object_object_add(r, "anacap", json_object_new_int(ctrl->
anacap))
;
472 obj_add_uint(r, "anagrpmax", le32_to_cpu(ctrl->anagrpmax))json_object_object_add(r, "anagrpmax", json_object_new_uint64
(le32_to_cpu(ctrl->anagrpmax)))
;
473 obj_add_uint(r, "nanagrpid", le32_to_cpu(ctrl->nanagrpid))json_object_object_add(r, "nanagrpid", json_object_new_uint64
(le32_to_cpu(ctrl->nanagrpid)))
;
474 obj_add_uint(r, "pels", le32_to_cpu(ctrl->pels))json_object_object_add(r, "pels", json_object_new_uint64(le32_to_cpu
(ctrl->pels)))
;
475 obj_add_int(r, "domainid", le16_to_cpu(ctrl->domainid))json_object_object_add(r, "domainid", json_object_new_int(le16_to_cpu
(ctrl->domainid)))
;
476 obj_add_int(r, "kpioc", ctrl->kpioc)json_object_object_add(r, "kpioc", json_object_new_int(ctrl->
kpioc))
;
477 obj_add_int(r, "mptfawr", le16_to_cpu(ctrl->mptfawr))json_object_object_add(r, "mptfawr", json_object_new_int(le16_to_cpu
(ctrl->mptfawr)))
;
478 obj_add_uint128(r, "megcap", megcap)json_object_object_add(r, "megcap", util_json_object_new_uint128
(megcap))
;
479 obj_add_int(r, "tmpthha", ctrl->tmpthha)json_object_object_add(r, "tmpthha", json_object_new_int(ctrl
->tmpthha))
;
480 obj_add_int(r, "cqt", le16_to_cpu(ctrl->cqt))json_object_object_add(r, "cqt", json_object_new_int(le16_to_cpu
(ctrl->cqt)))
;
481 obj_add_int(r, "cdpa", le16_to_cpu(ctrl->cdpa))json_object_object_add(r, "cdpa", json_object_new_int(le16_to_cpu
(ctrl->cdpa)))
;
482 obj_add_int(r, "mup", le16_to_cpu(ctrl->mup))json_object_object_add(r, "mup", json_object_new_int(le16_to_cpu
(ctrl->mup)))
;
483 obj_add_int(r, "ipmsr", le16_to_cpu(ctrl->ipmsr))json_object_object_add(r, "ipmsr", json_object_new_int(le16_to_cpu
(ctrl->ipmsr)))
;
484 obj_add_int(r, "msmt", le16_to_cpu(ctrl->msmt))json_object_object_add(r, "msmt", json_object_new_int(le16_to_cpu
(ctrl->msmt)))
;
485 obj_add_int(r, "sqes", ctrl->sqes)json_object_object_add(r, "sqes", json_object_new_int(ctrl->
sqes))
;
486 obj_add_int(r, "cqes", ctrl->cqes)json_object_object_add(r, "cqes", json_object_new_int(ctrl->
cqes))
;
487 obj_add_int(r, "maxcmd", le16_to_cpu(ctrl->maxcmd))json_object_object_add(r, "maxcmd", json_object_new_int(le16_to_cpu
(ctrl->maxcmd)))
;
488 obj_add_uint(r, "nn", le32_to_cpu(ctrl->nn))json_object_object_add(r, "nn", json_object_new_uint64(le32_to_cpu
(ctrl->nn)))
;
489 obj_add_int(r, "oncs", le16_to_cpu(ctrl->oncs))json_object_object_add(r, "oncs", json_object_new_int(le16_to_cpu
(ctrl->oncs)))
;
490 obj_add_int(r, "fuses", le16_to_cpu(ctrl->fuses))json_object_object_add(r, "fuses", json_object_new_int(le16_to_cpu
(ctrl->fuses)))
;
491 obj_add_int(r, "fna", ctrl->fna)json_object_object_add(r, "fna", json_object_new_int(ctrl->
fna))
;
492 obj_add_int(r, "vwc", ctrl->vwc)json_object_object_add(r, "vwc", json_object_new_int(ctrl->
vwc))
;
493 obj_add_int(r, "awun", le16_to_cpu(ctrl->awun))json_object_object_add(r, "awun", json_object_new_int(le16_to_cpu
(ctrl->awun)))
;
494 obj_add_int(r, "awupf", le16_to_cpu(ctrl->awupf))json_object_object_add(r, "awupf", json_object_new_int(le16_to_cpu
(ctrl->awupf)))
;
495 obj_add_int(r, "icsvscc", ctrl->icsvscc)json_object_object_add(r, "icsvscc", json_object_new_int(ctrl
->icsvscc))
;
496 obj_add_int(r, "nwpc", ctrl->nwpc)json_object_object_add(r, "nwpc", json_object_new_int(ctrl->
nwpc))
;
497 obj_add_int(r, "acwu", le16_to_cpu(ctrl->acwu))json_object_object_add(r, "acwu", json_object_new_int(le16_to_cpu
(ctrl->acwu)))
;
498 obj_add_int(r, "ocfs", le16_to_cpu(ctrl->ocfs))json_object_object_add(r, "ocfs", json_object_new_int(le16_to_cpu
(ctrl->ocfs)))
;
499 obj_add_uint(r, "sgls", le32_to_cpu(ctrl->sgls))json_object_object_add(r, "sgls", json_object_new_uint64(le32_to_cpu
(ctrl->sgls)))
;
500 obj_add_uint(r, "mnan", le32_to_cpu(ctrl->mnan))json_object_object_add(r, "mnan", json_object_new_uint64(le32_to_cpu
(ctrl->mnan)))
;
501 obj_add_uint128(r, "maxdna", maxdna)json_object_object_add(r, "maxdna", util_json_object_new_uint128
(maxdna))
;
502 obj_add_uint(r, "maxcna", le32_to_cpu(ctrl->maxcna))json_object_object_add(r, "maxcna", json_object_new_uint64(le32_to_cpu
(ctrl->maxcna)))
;
503 obj_add_uint(r, "oaqd", le32_to_cpu(ctrl->oaqd))json_object_object_add(r, "oaqd", json_object_new_uint64(le32_to_cpu
(ctrl->oaqd)))
;
504 obj_add_int(r, "rhiri", ctrl->rhiri)json_object_object_add(r, "rhiri", json_object_new_int(ctrl->
rhiri))
;
505 obj_add_int(r, "hirt", ctrl->hirt)json_object_object_add(r, "hirt", json_object_new_int(ctrl->
hirt))
;
506 obj_add_int(r, "cmmrtd", le16_to_cpu(ctrl->cmmrtd))json_object_object_add(r, "cmmrtd", json_object_new_int(le16_to_cpu
(ctrl->cmmrtd)))
;
507 obj_add_int(r, "nmmrtd", le16_to_cpu(ctrl->nmmrtd))json_object_object_add(r, "nmmrtd", json_object_new_int(le16_to_cpu
(ctrl->nmmrtd)))
;
508 obj_add_int(r, "minmrtg", ctrl->minmrtg)json_object_object_add(r, "minmrtg", json_object_new_int(ctrl
->minmrtg))
;
509 obj_add_int(r, "maxmrtg", ctrl->maxmrtg)json_object_object_add(r, "maxmrtg", json_object_new_int(ctrl
->maxmrtg))
;
510 obj_add_int(r, "trattr", ctrl->trattr)json_object_object_add(r, "trattr", json_object_new_int(ctrl->
trattr))
;
511 obj_add_int(r, "mcudmq", le16_to_cpu(ctrl->mcudmq))json_object_object_add(r, "mcudmq", json_object_new_int(le16_to_cpu
(ctrl->mcudmq)))
;
512 obj_add_int(r, "mnsudmq", le16_to_cpu(ctrl->mnsudmq))json_object_object_add(r, "mnsudmq", json_object_new_int(le16_to_cpu
(ctrl->mnsudmq)))
;
513 obj_add_int(r, "mcmr", le16_to_cpu(ctrl->mcmr))json_object_object_add(r, "mcmr", json_object_new_int(le16_to_cpu
(ctrl->mcmr)))
;
514 obj_add_int(r, "nmcmr", le16_to_cpu(ctrl->nmcmr))json_object_object_add(r, "nmcmr", json_object_new_int(le16_to_cpu
(ctrl->nmcmr)))
;
515 obj_add_int(r, "mcdqpc", le16_to_cpu(ctrl->mcdqpc))json_object_object_add(r, "mcdqpc", json_object_new_int(le16_to_cpu
(ctrl->mcdqpc)))
;
516
517 if (strlen(subnqn))
518 obj_add_strjson_object_add_value_string(r, "subnqn", subnqn);
519
520 obj_add_uint(r, "ioccsz", le32_to_cpu(ctrl->ioccsz))json_object_object_add(r, "ioccsz", json_object_new_uint64(le32_to_cpu
(ctrl->ioccsz)))
;
521 obj_add_uint(r, "iorcsz", le32_to_cpu(ctrl->iorcsz))json_object_object_add(r, "iorcsz", json_object_new_uint64(le32_to_cpu
(ctrl->iorcsz)))
;
522 obj_add_int(r, "icdoff", le16_to_cpu(ctrl->icdoff))json_object_object_add(r, "icdoff", json_object_new_int(le16_to_cpu
(ctrl->icdoff)))
;
523 obj_add_int(r, "fcatt", ctrl->fcatt)json_object_object_add(r, "fcatt", json_object_new_int(ctrl->
fcatt))
;
524 obj_add_int(r, "msdbd", ctrl->msdbd)json_object_object_add(r, "msdbd", json_object_new_int(ctrl->
msdbd))
;
525 obj_add_int(r, "ofcs", le16_to_cpu(ctrl->ofcs))json_object_object_add(r, "ofcs", json_object_new_int(le16_to_cpu
(ctrl->ofcs)))
;
526 obj_add_int(r, "dctype", ctrl->dctype)json_object_object_add(r, "dctype", json_object_new_int(ctrl->
dctype))
;
527 obj_add_int(r, "ccrl", ctrl->ccrl)json_object_object_add(r, "ccrl", json_object_new_int(ctrl->
ccrl))
;
528
529 obj_add_array(r, "psds", psds)json_object_object_add(r, "psds", psds);
530
531 for (i = 0; i <= ctrl->npss; i++) {
532 struct json_object *psd = json_create_object()json_object_new_object();
533
534 obj_add_int(psd, "max_power", le16_to_cpu(ctrl->psd[i].mp))json_object_object_add(psd, "max_power", json_object_new_int(
le16_to_cpu(ctrl->psd[i].mp)))
;
535 obj_add_int(psd, "max_power_scale", ctrl->psd[i].flags & NVME_PSD_FLAGS_MXPS)json_object_object_add(psd, "max_power_scale", json_object_new_int
(ctrl->psd[i].flags & NVME_PSD_FLAGS_MXPS))
;
536 obj_add_int(psd, "non-operational_state",json_object_object_add(psd, "non-operational_state", json_object_new_int
(!!(ctrl->psd[i].flags & NVME_PSD_FLAGS_NOPS)))
537 !!(ctrl->psd[i].flags & NVME_PSD_FLAGS_NOPS))json_object_object_add(psd, "non-operational_state", json_object_new_int
(!!(ctrl->psd[i].flags & NVME_PSD_FLAGS_NOPS)))
;
538 obj_add_uint(psd, "entry_lat", le32_to_cpu(ctrl->psd[i].enlat))json_object_object_add(psd, "entry_lat", json_object_new_uint64
(le32_to_cpu(ctrl->psd[i].enlat)))
;
539 obj_add_uint(psd, "exit_lat", le32_to_cpu(ctrl->psd[i].exlat))json_object_object_add(psd, "exit_lat", json_object_new_uint64
(le32_to_cpu(ctrl->psd[i].exlat)))
;
540 obj_add_int(psd, "read_tput", ctrl->psd[i].rrt)json_object_object_add(psd, "read_tput", json_object_new_int(
ctrl->psd[i].rrt))
;
541 obj_add_int(psd, "read_lat", ctrl->psd[i].rrl)json_object_object_add(psd, "read_lat", json_object_new_int(ctrl
->psd[i].rrl))
;
542 obj_add_int(psd, "write_tput", ctrl->psd[i].rwt)json_object_object_add(psd, "write_tput", json_object_new_int
(ctrl->psd[i].rwt))
;
543 obj_add_int(psd, "write_lat", ctrl->psd[i].rwl)json_object_object_add(psd, "write_lat", json_object_new_int(
ctrl->psd[i].rwl))
;
544 obj_add_int(psd, "idle_power", le16_to_cpu(ctrl->psd[i].idlp))json_object_object_add(psd, "idle_power", json_object_new_int
(le16_to_cpu(ctrl->psd[i].idlp)))
;
545 obj_add_int(psd, "idle_scale", nvme_psd_power_scale(ctrl->psd[i].ips))json_object_object_add(psd, "idle_scale", json_object_new_int
(nvme_psd_power_scale(ctrl->psd[i].ips)))
;
546 obj_add_int(psd, "active_power", le16_to_cpu(ctrl->psd[i].actp))json_object_object_add(psd, "active_power", json_object_new_int
(le16_to_cpu(ctrl->psd[i].actp)))
;
547 obj_add_int(psd, "active_power_work", ctrl->psd[i].apws & 7)json_object_object_add(psd, "active_power_work", json_object_new_int
(ctrl->psd[i].apws & 7))
;
548 obj_add_int(psd, "active_scale", nvme_psd_power_scale(ctrl->psd[i].apws))json_object_object_add(psd, "active_scale", json_object_new_int
(nvme_psd_power_scale(ctrl->psd[i].apws)))
;
549 obj_add_int(psd, "emerg_power_fail_recover_time", ctrl->psd[i].epfrt)json_object_object_add(psd, "emerg_power_fail_recover_time", json_object_new_int
(ctrl->psd[i].epfrt))
;
550 obj_add_int(psd, "emerg_power_fail_recover_scale", ctrl->psd[i].epfr_fqv_ts & 0xf)json_object_object_add(psd, "emerg_power_fail_recover_scale",
json_object_new_int(ctrl->psd[i].epfr_fqv_ts & 0xf))
;
551 obj_add_int(psd, "force_quiesce_vault_time", ctrl->psd[i].fqvt)json_object_object_add(psd, "force_quiesce_vault_time", json_object_new_int
(ctrl->psd[i].fqvt))
;
552 obj_add_int(psd, "force_quiesce_vault_scale", ctrl->psd[i].epfr_fqv_ts >> 4)json_object_object_add(psd, "force_quiesce_vault_scale", json_object_new_int
(ctrl->psd[i].epfr_fqv_ts >> 4))
;
553 obj_add_int(psd, "emerg_power_fail_vault_time", ctrl->psd[i].epfvt)json_object_object_add(psd, "emerg_power_fail_vault_time", json_object_new_int
(ctrl->psd[i].epfvt))
;
554 obj_add_int(psd, "emerg_power_fail_vault_scale", ctrl->psd[i].epfvts & 0xf)json_object_object_add(psd, "emerg_power_fail_vault_scale", json_object_new_int
(ctrl->psd[i].epfvts & 0xf))
;
555
556 array_add_obj(psds, psd)json_object_array_add(psds, psd);
557 }
558
559 if (vs)
560 vs(ctrl->vs, r);
561
562 json_print(r);
563}
564
565static void json_error_log(struct nvme_error_log_page *err_log, int entries,
566 const char *devname,
567 struct nvme_error_log_filter *flt)
568{
569 struct json_object *r = json_create_object()json_object_new_object();
570 struct json_object *errors = json_create_array()json_object_new_array();
571 struct json_object *error;
572 __u16 sts;
573 int i;
574
575 obj_add_array(r, "errors", errors)json_object_object_add(r, "errors", errors);
576
577 for (i = 0; i < entries; i++) {
578 if (nvme_is_error_log_filter(&err_log[i], flt))
579 continue;
580
581 error = json_create_object()json_object_new_object();
582 sts = le16_to_cpu(err_log[i].status_field);
583
584 obj_add_uint64(error, "error_count",json_object_object_add(error, "error_count", json_object_new_uint64
(le64_to_cpu(err_log[i].error_count)))
585 le64_to_cpu(err_log[i].error_count))json_object_object_add(error, "error_count", json_object_new_uint64
(le64_to_cpu(err_log[i].error_count)))
;
586 obj_add_int(error, "sqid", le16_to_cpu(err_log[i].sqid))json_object_object_add(error, "sqid", json_object_new_int(le16_to_cpu
(err_log[i].sqid)))
;
587 obj_add_int(error, "cmdid", le16_to_cpu(err_log[i].cmdid))json_object_object_add(error, "cmdid", json_object_new_int(le16_to_cpu
(err_log[i].cmdid)))
;
588 obj_add_int(error, "status_field",json_object_object_add(error, "status_field", json_object_new_int
((((sts) >> NVME_ERR_SF_STATUS_FIELD_SHIFT) & NVME_ERR_SF_STATUS_FIELD_MASK
)))
589 NVME_ERR_SF_STATUS_FIELD(sts))json_object_object_add(error, "status_field", json_object_new_int
((((sts) >> NVME_ERR_SF_STATUS_FIELD_SHIFT) & NVME_ERR_SF_STATUS_FIELD_MASK
)))
;
590 obj_add_int(error, "phase_tag", NVME_ERR_SF_PHASE_TAG(sts))json_object_object_add(error, "phase_tag", json_object_new_int
((((sts) >> NVME_ERR_SF_PHASE_TAG_SHIFT) & NVME_ERR_SF_PHASE_TAG_MASK
)))
;
591 obj_add_int(error, "parm_error_location",json_object_object_add(error, "parm_error_location", json_object_new_int
(le16_to_cpu(err_log[i].parm_error_location)))
592 le16_to_cpu(err_log[i].parm_error_location))json_object_object_add(error, "parm_error_location", json_object_new_int
(le16_to_cpu(err_log[i].parm_error_location)))
;
593 obj_add_uint64(error, "lba", le64_to_cpu(err_log[i].lba))json_object_object_add(error, "lba", json_object_new_uint64(le64_to_cpu
(err_log[i].lba)))
;
594 obj_add_uint(error, "nsid", le32_to_cpu(err_log[i].nsid))json_object_object_add(error, "nsid", json_object_new_uint64(
le32_to_cpu(err_log[i].nsid)))
;
595 obj_add_int(error, "vs", err_log[i].vs)json_object_object_add(error, "vs", json_object_new_int(err_log
[i].vs))
;
596 obj_add_int(error, "trtype", err_log[i].trtype)json_object_object_add(error, "trtype", json_object_new_int(err_log
[i].trtype))
;
597 obj_add_int(error, "csi", err_log[i].csi)json_object_object_add(error, "csi", json_object_new_int(err_log
[i].csi))
;
598 obj_add_int(error, "opcode", err_log[i].opcode)json_object_object_add(error, "opcode", json_object_new_int(err_log
[i].opcode))
;
599 obj_add_uint64(error, "cs", le64_to_cpu(err_log[i].cs))json_object_object_add(error, "cs", json_object_new_uint64(le64_to_cpu
(err_log[i].cs)))
;
600 obj_add_int(error, "trtype_spec_info",json_object_object_add(error, "trtype_spec_info", json_object_new_int
(le16_to_cpu(err_log[i].trtype_spec_info)))
601 le16_to_cpu(err_log[i].trtype_spec_info))json_object_object_add(error, "trtype_spec_info", json_object_new_int
(le16_to_cpu(err_log[i].trtype_spec_info)))
;
602 obj_add_int(error, "log_page_version",json_object_object_add(error, "log_page_version", json_object_new_int
(err_log[i].log_page_version))
603 err_log[i].log_page_version)json_object_object_add(error, "log_page_version", json_object_new_int
(err_log[i].log_page_version))
;
604
605 array_add_obj(errors, error)json_object_array_add(errors, error);
606 }
607
608 json_print(r);
609}
610
611void json_nvme_resv_report(struct nvme_resv_status *status,
612 int bytes, bool_Bool eds)
613{
614 struct json_object *r = json_create_object()json_object_new_object();
615 struct json_object *rcs = json_create_array()json_object_new_array();
616 int i, j, entries;
617 int regctl = status->regctl[0] | (status->regctl[1] << 8);
618
619 obj_add_uint(r, "gen", le32_to_cpu(status->gen))json_object_object_add(r, "gen", json_object_new_uint64(le32_to_cpu
(status->gen)))
;
620 obj_add_int(r, "rtype", status->rtype)json_object_object_add(r, "rtype", json_object_new_int(status
->rtype))
;
621 obj_add_int(r, "regctl", regctl)json_object_object_add(r, "regctl", json_object_new_int(regctl
))
;
622 obj_add_int(r, "ptpls", status->ptpls)json_object_object_add(r, "ptpls", json_object_new_int(status
->ptpls))
;
623
624 /* check Extended Data Structure bit */
625 if (!eds) {
626 /*
627 * if status buffer was too small, don't loop past the end of
628 * the buffer
629 */
630 entries = (bytes - 24) / 24;
631 if (entries < regctl)
632 regctl = entries;
633
634 obj_add_array(r, "regctls", rcs)json_object_object_add(r, "regctls", rcs);
635 for (i = 0; i < regctl; i++) {
636 struct json_object *rc = json_create_object()json_object_new_object();
637
638 obj_add_int(rc, "cntlid", le16_to_cpu(status->regctl_ds[i].cntlid))json_object_object_add(rc, "cntlid", json_object_new_int(le16_to_cpu
(status->regctl_ds[i].cntlid)))
;
639 obj_add_int(rc, "rcsts", status->regctl_ds[i].rcsts)json_object_object_add(rc, "rcsts", json_object_new_int(status
->regctl_ds[i].rcsts))
;
640 obj_add_uint64(rc, "hostid", le64_to_cpu(status->regctl_ds[i].hostid))json_object_object_add(rc, "hostid", json_object_new_uint64(le64_to_cpu
(status->regctl_ds[i].hostid)))
;
641 obj_add_uint64(rc, "rkey", le64_to_cpu(status->regctl_ds[i].rkey))json_object_object_add(rc, "rkey", json_object_new_uint64(le64_to_cpu
(status->regctl_ds[i].rkey)))
;
642
643 array_add_obj(rcs, rc)json_object_array_add(rcs, rc);
644 }
645 } else {
646 char hostid[33];
647
648 /* if status buffer was too small, don't loop past the end of the buffer */
649 entries = (bytes - 64) / 64;
650
651 if (entries < regctl)
652 regctl = entries;
653
654 obj_add_array(r, "regctlext", rcs)json_object_object_add(r, "regctlext", rcs);
655
656 for (i = 0; i < regctl; i++) {
657 struct json_object *rc = json_create_object()json_object_new_object();
658
659 obj_add_int(rc, "cntlid", le16_to_cpu(status->regctl_eds[i].cntlid))json_object_object_add(rc, "cntlid", json_object_new_int(le16_to_cpu
(status->regctl_eds[i].cntlid)))
;
660 obj_add_int(rc, "rcsts", status->regctl_eds[i].rcsts)json_object_object_add(rc, "rcsts", json_object_new_int(status
->regctl_eds[i].rcsts))
;
661 obj_add_uint64(rc, "rkey", le64_to_cpu(status->regctl_eds[i].rkey))json_object_object_add(rc, "rkey", json_object_new_uint64(le64_to_cpu
(status->regctl_eds[i].rkey)))
;
662
663 for (j = 0; j < 16; j++)
664 sprintf(hostid + j * 2, "%02x", status->regctl_eds[i].hostid[j]);
665
666 obj_add_strjson_object_add_value_string(rc, "hostid", hostid);
667 array_add_obj(rcs, rc)json_object_array_add(rcs, rc);
668 }
669 }
670
671 json_print(r);
672}
673
674void json_fw_log(struct nvme_firmware_slot *fw_log, const char *devname)
675{
676 struct json_object *r = json_create_object()json_object_new_object();
677 struct json_object *fwsi = json_create_object()json_object_new_object();
678 char fmt[21];
679 char str[32];
680 int i;
681 __le64 *frs;
682
683 obj_add_int(fwsi, "Active Firmware Slot (afi)", fw_log->afi)json_object_object_add(fwsi, "Active Firmware Slot (afi)", json_object_new_int
(fw_log->afi))
;
684
685 for (i = 0; i < 7; i++) {
686 if (fw_log->frs[i][0]) {
687 snprintf(fmt, sizeof(fmt), "Firmware Rev Slot %d",
688 i + 1);
689 frs = (__le64 *)&fw_log->frs[i];
690 snprintf(str, sizeof(str), "%"PRIu64"l" "u"" (%s)",
691 le64_to_cpu(*frs),
692 util_fw_to_string(fw_log->frs[i]));
693 obj_add_strjson_object_add_value_string(fwsi, fmt, str);
694 }
695 }
696
697 obj_add_obj(r, devname, fwsi)json_object_object_add(r, devname, fwsi);
698
699 json_print(r);
700}
701
702void json_changed_ns_list_log(struct nvme_ns_list *log, const char *devname, bool_Bool alloc)
703{
704 struct json_object *r = json_create_object()json_object_new_object();
705 struct json_object *nsi = json_create_object()json_object_new_object();
706 char fmt[32];
707 char str[32];
708 __u32 nsid;
709 int i;
710
711 __cleanup_free__attribute__((cleanup(freep))) char *k = NULL((void*)0);
712
713 if (log->ns[0] == cpu_to_le32(0xffffffff))
714 return;
715
716 if (asprintf(&k, "Changed %s Namespace List Log", alloc ? "Allocated" : "Attached") > 0)
717 obj_add_strjson_object_add_value_string(r, k, devname);
718
719 for (i = 0; i < NVME_ID_NS_LIST_MAX; i++) {
720 nsid = le32_to_cpu(log->ns[i]);
721
722 if (nsid == 0)
723 break;
724
725 snprintf(fmt, sizeof(fmt), "[%4u]", i + 1);
726 snprintf(str, sizeof(str), "%#x", nsid);
727 obj_add_strjson_object_add_value_string(nsi, fmt, str);
728 }
729
730 obj_add_obj(r, devname, nsi)json_object_object_add(r, devname, nsi);
731
732 json_print(r);
733}
734
735static void json_endurance_log(struct nvme_endurance_group_log *endurance_group, __u16 group_id,
736 const char *devname)
737{
738 struct json_object *r = json_create_object()json_object_new_object();
739 nvme_uint128_t endurance_estimate = le128_to_cpu(endurance_group->endurance_estimate);
740 nvme_uint128_t data_units_read = le128_to_cpu(endurance_group->data_units_read);
741 nvme_uint128_t data_units_written = le128_to_cpu(endurance_group->data_units_written);
742 nvme_uint128_t media_units_written = le128_to_cpu(endurance_group->media_units_written);
743 nvme_uint128_t host_read_cmds = le128_to_cpu(endurance_group->host_read_cmds);
744 nvme_uint128_t host_write_cmds = le128_to_cpu(endurance_group->host_write_cmds);
745 nvme_uint128_t media_data_integrity_err =
746 le128_to_cpu(endurance_group->media_data_integrity_err);
747 nvme_uint128_t num_err_info_log_entries =
748 le128_to_cpu(endurance_group->num_err_info_log_entries);
749 nvme_uint128_t total_end_grp_cap = le128_to_cpu(endurance_group->total_end_grp_cap);
750 nvme_uint128_t unalloc_end_grp_cap = le128_to_cpu(endurance_group->unalloc_end_grp_cap);
751
752 obj_add_int(r, "critical_warning", endurance_group->critical_warning)json_object_object_add(r, "critical_warning", json_object_new_int
(endurance_group->critical_warning))
;
753 obj_add_int(r, "endurance_group_features", endurance_group->endurance_group_features)json_object_object_add(r, "endurance_group_features", json_object_new_int
(endurance_group->endurance_group_features))
;
754 obj_add_int(r, "avl_spare", endurance_group->avl_spare)json_object_object_add(r, "avl_spare", json_object_new_int(endurance_group
->avl_spare))
;
755 obj_add_int(r, "avl_spare_threshold", endurance_group->avl_spare_threshold)json_object_object_add(r, "avl_spare_threshold", json_object_new_int
(endurance_group->avl_spare_threshold))
;
756 obj_add_int(r, "percent_used", endurance_group->percent_used)json_object_object_add(r, "percent_used", json_object_new_int
(endurance_group->percent_used))
;
757 obj_add_int(r, "domain_identifier", endurance_group->domain_identifier)json_object_object_add(r, "domain_identifier", json_object_new_int
(endurance_group->domain_identifier))
;
758 obj_add_uint128(r, "endurance_estimate", endurance_estimate)json_object_object_add(r, "endurance_estimate", util_json_object_new_uint128
(endurance_estimate))
;
759 obj_add_uint128(r, "data_units_read", data_units_read)json_object_object_add(r, "data_units_read", util_json_object_new_uint128
(data_units_read))
;
760 obj_add_uint128(r, "data_units_written", data_units_written)json_object_object_add(r, "data_units_written", util_json_object_new_uint128
(data_units_written))
;
761 obj_add_uint128(r, "media_units_written", media_units_written)json_object_object_add(r, "media_units_written", util_json_object_new_uint128
(media_units_written))
;
762 obj_add_uint128(r, "host_read_cmds", host_read_cmds)json_object_object_add(r, "host_read_cmds", util_json_object_new_uint128
(host_read_cmds))
;
763 obj_add_uint128(r, "host_write_cmds", host_write_cmds)json_object_object_add(r, "host_write_cmds", util_json_object_new_uint128
(host_write_cmds))
;
764 obj_add_uint128(r, "media_data_integrity_err", media_data_integrity_err)json_object_object_add(r, "media_data_integrity_err", util_json_object_new_uint128
(media_data_integrity_err))
;
765 obj_add_uint128(r, "num_err_info_log_entries", num_err_info_log_entries)json_object_object_add(r, "num_err_info_log_entries", util_json_object_new_uint128
(num_err_info_log_entries))
;
766 obj_add_uint128(r, "total_end_grp_cap", total_end_grp_cap)json_object_object_add(r, "total_end_grp_cap", util_json_object_new_uint128
(total_end_grp_cap))
;
767 obj_add_uint128(r, "unalloc_end_grp_cap", unalloc_end_grp_cap)json_object_object_add(r, "unalloc_end_grp_cap", util_json_object_new_uint128
(unalloc_end_grp_cap))
;
768
769 json_print(r);
770}
771
772static void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
773 const char *devname)
774{
775 struct json_object *r = json_create_object()json_object_new_object();
776 int c;
777 char key[21];
778 unsigned int temperature = ((smart->temperature[1] << 8) |
779 smart->temperature[0]);
780 nvme_uint128_t data_units_read = le128_to_cpu(smart->data_units_read);
781 nvme_uint128_t data_units_written = le128_to_cpu(smart->data_units_written);
782 nvme_uint128_t host_read_commands = le128_to_cpu(smart->host_reads);
783 nvme_uint128_t host_write_commands = le128_to_cpu(smart->host_writes);
784 nvme_uint128_t controller_busy_time = le128_to_cpu(smart->ctrl_busy_time);
785 nvme_uint128_t power_cycles = le128_to_cpu(smart->power_cycles);
786 nvme_uint128_t power_on_hours = le128_to_cpu(smart->power_on_hours);
787 nvme_uint128_t unsafe_shutdowns = le128_to_cpu(smart->unsafe_shutdowns);
788 nvme_uint128_t media_errors = le128_to_cpu(smart->media_errors);
789 nvme_uint128_t num_err_log_entries = le128_to_cpu(smart->num_err_log_entries);
790
791 if (verbose_mode()) {
792 struct json_object *crt = json_create_object()json_object_new_object();
793
794 obj_add_int(crt, "value", smart->critical_warning)json_object_object_add(crt, "value", json_object_new_int(smart
->critical_warning))
;
795 obj_add_int(crt, "available_spare", smart->critical_warning & 1)json_object_object_add(crt, "available_spare", json_object_new_int
(smart->critical_warning & 1))
;
796 obj_add_int(crt, "temp_threshold", (smart->critical_warning & 2) >> 1)json_object_object_add(crt, "temp_threshold", json_object_new_int
((smart->critical_warning & 2) >> 1))
;
797 obj_add_int(crt, "reliability_degraded", (smart->critical_warning & 4) >> 2)json_object_object_add(crt, "reliability_degraded", json_object_new_int
((smart->critical_warning & 4) >> 2))
;
798 obj_add_int(crt, "ro", (smart->critical_warning & 8) >> 3)json_object_object_add(crt, "ro", json_object_new_int((smart->
critical_warning & 8) >> 3))
;
799 obj_add_int(crt, "vmbu_failed", (smart->critical_warning & 0x10) >> 4)json_object_object_add(crt, "vmbu_failed", json_object_new_int
((smart->critical_warning & 0x10) >> 4))
;
800 obj_add_int(crt, "pmr_ro", (smart->critical_warning & 0x20) >> 5)json_object_object_add(crt, "pmr_ro", json_object_new_int((smart
->critical_warning & 0x20) >> 5))
;
801
802 obj_add_obj(r, "critical_warning", crt)json_object_object_add(r, "critical_warning", crt);
803 } else {
804 obj_add_int(r, "critical_warning", smart->critical_warning)json_object_object_add(r, "critical_warning", json_object_new_int
(smart->critical_warning))
;
805 }
806
807 obj_add_int(r, "temperature", temperature)json_object_object_add(r, "temperature", json_object_new_int(
temperature))
;
808 obj_add_int(r, "avail_spare", smart->avail_spare)json_object_object_add(r, "avail_spare", json_object_new_int(
smart->avail_spare))
;
809 obj_add_int(r, "spare_thresh", smart->spare_thresh)json_object_object_add(r, "spare_thresh", json_object_new_int
(smart->spare_thresh))
;
810 obj_add_int(r, "percent_used", smart->percent_used)json_object_object_add(r, "percent_used", json_object_new_int
(smart->percent_used))
;
811 obj_add_int(r, "endurance_grp_critical_warning_summary", smart->endu_grp_crit_warn_sumry)json_object_object_add(r, "endurance_grp_critical_warning_summary"
, json_object_new_int(smart->endu_grp_crit_warn_sumry))
;
812 obj_add_uint128(r, "data_units_read", data_units_read)json_object_object_add(r, "data_units_read", util_json_object_new_uint128
(data_units_read))
;
813 obj_add_uint128(r, "data_units_written", data_units_written)json_object_object_add(r, "data_units_written", util_json_object_new_uint128
(data_units_written))
;
814 obj_add_uint128(r, "host_read_commands", host_read_commands)json_object_object_add(r, "host_read_commands", util_json_object_new_uint128
(host_read_commands))
;
815 obj_add_uint128(r, "host_write_commands", host_write_commands)json_object_object_add(r, "host_write_commands", util_json_object_new_uint128
(host_write_commands))
;
816 obj_add_uint128(r, "controller_busy_time", controller_busy_time)json_object_object_add(r, "controller_busy_time", util_json_object_new_uint128
(controller_busy_time))
;
817 obj_add_uint128(r, "power_cycles", power_cycles)json_object_object_add(r, "power_cycles", util_json_object_new_uint128
(power_cycles))
;
818 obj_add_uint128(r, "power_on_hours", power_on_hours)json_object_object_add(r, "power_on_hours", util_json_object_new_uint128
(power_on_hours))
;
819 obj_add_uint128(r, "unsafe_shutdowns", unsafe_shutdowns)json_object_object_add(r, "unsafe_shutdowns", util_json_object_new_uint128
(unsafe_shutdowns))
;
820 obj_add_uint128(r, "media_errors", media_errors)json_object_object_add(r, "media_errors", util_json_object_new_uint128
(media_errors))
;
821 obj_add_uint128(r, "num_err_log_entries", num_err_log_entries)json_object_object_add(r, "num_err_log_entries", util_json_object_new_uint128
(num_err_log_entries))
;
822 obj_add_uint(r, "warning_temp_time", le32_to_cpu(smart->warning_temp_time))json_object_object_add(r, "warning_temp_time", json_object_new_uint64
(le32_to_cpu(smart->warning_temp_time)))
;
823 obj_add_uint(r, "critical_comp_time", le32_to_cpu(smart->critical_comp_time))json_object_object_add(r, "critical_comp_time", json_object_new_uint64
(le32_to_cpu(smart->critical_comp_time)))
;
824
825 for (c = 0; c < 8; c++) {
826 __s32 temp = le16_to_cpu(smart->temp_sensor[c]);
827
828 if (temp == 0)
829 continue;
830
831 sprintf(key, "temperature_sensor_%d", c + 1);
832 obj_add_int(r, key, temp)json_object_object_add(r, key, json_object_new_int(temp));
833 }
834
835 obj_add_uint(r, "thm_temp1_trans_count", le32_to_cpu(smart->thm_temp1_trans_count))json_object_object_add(r, "thm_temp1_trans_count", json_object_new_uint64
(le32_to_cpu(smart->thm_temp1_trans_count)))
;
836 obj_add_uint(r, "thm_temp2_trans_count", le32_to_cpu(smart->thm_temp2_trans_count))json_object_object_add(r, "thm_temp2_trans_count", json_object_new_uint64
(le32_to_cpu(smart->thm_temp2_trans_count)))
;
837 obj_add_uint(r, "thm_temp1_total_time", le32_to_cpu(smart->thm_temp1_total_time))json_object_object_add(r, "thm_temp1_total_time", json_object_new_uint64
(le32_to_cpu(smart->thm_temp1_total_time)))
;
838 obj_add_uint(r, "thm_temp2_total_time", le32_to_cpu(smart->thm_temp2_total_time))json_object_object_add(r, "thm_temp2_total_time", json_object_new_uint64
(le32_to_cpu(smart->thm_temp2_total_time)))
;
839 obj_add_uint64(r, "op_lifetime_energy_consumed", le64_to_cpu(smart->op_lifetime_energy_consumed))json_object_object_add(r, "op_lifetime_energy_consumed", json_object_new_uint64
(le64_to_cpu(smart->op_lifetime_energy_consumed)))
;
840 obj_add_uint(r, "interval_power_measurement", le32_to_cpu(smart->interval_power_measurement))json_object_object_add(r, "interval_power_measurement", json_object_new_uint64
(le32_to_cpu(smart->interval_power_measurement)))
;
841
842 json_print(r);
843}
844
845static void json_ana_log(struct nvme_ana_log *ana_log, const char *devname,
846 size_t len)
847{
848 int offset = sizeof(struct nvme_ana_log);
849 struct nvme_ana_log *hdr = ana_log;
850 struct nvme_ana_group_desc *ana_desc;
851 struct json_object *desc_list = json_create_array()json_object_new_array();
852 struct json_object *ns_list;
853 struct json_object *desc;
854 struct json_object *nsid;
855 struct json_object *r = json_create_object()json_object_new_object();
856 size_t nsid_buf_size;
857 void *base = ana_log;
858 __u32 nr_nsids;
859 int i, j;
860
861 obj_add_strjson_object_add_value_string(r, "Asymmetric Namespace Access Log for NVMe device", devname);
862 obj_add_uint64(r, "chgcnt", le64_to_cpu(hdr->chgcnt))json_object_object_add(r, "chgcnt", json_object_new_uint64(le64_to_cpu
(hdr->chgcnt)))
;
863 obj_add_uint(r, "ngrps", le16_to_cpu(hdr->ngrps))json_object_object_add(r, "ngrps", json_object_new_uint64(le16_to_cpu
(hdr->ngrps)))
;
864
865 for (i = 0; i < le16_to_cpu(ana_log->ngrps); i++) {
866 desc = json_create_object()json_object_new_object();
867 ana_desc = base + offset;
868 nr_nsids = le32_to_cpu(ana_desc->nnsids);
869 nsid_buf_size = nr_nsids * sizeof(__le32);
870
871 offset += sizeof(*ana_desc);
872 obj_add_uint(desc, "grpid", le32_to_cpu(ana_desc->grpid))json_object_object_add(desc, "grpid", json_object_new_uint64(
le32_to_cpu(ana_desc->grpid)))
;
873 obj_add_uint(desc, "nnsids", le32_to_cpu(ana_desc->nnsids))json_object_object_add(desc, "nnsids", json_object_new_uint64
(le32_to_cpu(ana_desc->nnsids)))
;
874 obj_add_uint64(desc, "chgcnt", le64_to_cpu(ana_desc->chgcnt))json_object_object_add(desc, "chgcnt", json_object_new_uint64
(le64_to_cpu(ana_desc->chgcnt)))
;
875 obj_add_strjson_object_add_value_string(desc, "state", nvme_ana_state_to_string(ana_desc->state));
876
877 ns_list = json_create_array()json_object_new_array();
878 for (j = 0; j < le32_to_cpu(ana_desc->nnsids); j++) {
879 nsid = json_create_object()json_object_new_object();
880 obj_add_uint(nsid, "nsid", le32_to_cpu(ana_desc->nsids[j]))json_object_object_add(nsid, "nsid", json_object_new_uint64(le32_to_cpu
(ana_desc->nsids[j])))
;
881 array_add_obj(ns_list, nsid)json_object_array_add(ns_list, nsid);
882 }
883 obj_add_array(desc, "NSIDS", ns_list)json_object_object_add(desc, "NSIDS", ns_list);
884 offset += nsid_buf_size;
885 array_add_obj(desc_list, desc)json_object_array_add(desc_list, desc);
886 }
887
888 obj_add_array(r, "ANA DESC LIST ", desc_list)json_object_object_add(r, "ANA DESC LIST ", desc_list);
889
890 json_print(r);
891}
892
893static void json_select_result(enum nvme_features_id fid, __u64 result)
894{
895 struct json_object *r = json_r ? json_r : json_create_object()json_object_new_object();
896 char json_str[STR_LEN100];
897 struct json_object *feature = json_create_array()json_object_new_array();
898
899 if (result & 0x1)
900 array_add_strjson_array_add_value_string(feature, "saveable");
901 if (result & 0x2)
902 array_add_strjson_array_add_value_string(feature, "per-namespace");
903 if (result & 0x4)
904 array_add_strjson_array_add_value_string(feature, "changeable");
905
906 sprintf(json_str, "Feature: %#0*x: select", fid ? 4 : 2, fid);
907 obj_add_array(r, json_str, feature)json_object_object_add(r, json_str, feature);
908
909 obj_print(r);
910}
911
912static void json_self_test_log(struct nvme_self_test_log *self_test, __u8 dst_entries,
913 __u32 size, const char *devname)
914{
915 struct json_object *valid_attrs;
916 struct json_object *r = json_create_object()json_object_new_object();
917 struct json_object *valid = json_create_array()json_object_new_array();
918 int i;
919 __u32 num_entries = min(dst_entries, NVME_LOG_ST_MAX_RESULTS)((dst_entries) > (NVME_LOG_ST_MAX_RESULTS) ? (NVME_LOG_ST_MAX_RESULTS
) : (dst_entries))
;
920
921 obj_add_int(r, "Current Device Self-Test Operation", self_test->current_operation)json_object_object_add(r, "Current Device Self-Test Operation"
, json_object_new_int(self_test->current_operation))
;
922 obj_add_int(r, "Current Device Self-Test Completion", self_test->completion)json_object_object_add(r, "Current Device Self-Test Completion"
, json_object_new_int(self_test->completion))
;
923
924 for (i = 0; i < num_entries; i++) {
925 valid_attrs = json_create_object()json_object_new_object();
926 obj_add_int(valid_attrs, "Self test result", self_test->result[i].dsts & 0xf)json_object_object_add(valid_attrs, "Self test result", json_object_new_int
(self_test->result[i].dsts & 0xf))
;
927
928 if ((self_test->result[i].dsts & 0xf) == 0xf)
929 goto add;
930
931 obj_add_int(valid_attrs, "Self test code",json_object_object_add(valid_attrs, "Self test code", json_object_new_int
(self_test->result[i].dsts >> 4))
932 self_test->result[i].dsts >> 4)json_object_object_add(valid_attrs, "Self test code", json_object_new_int
(self_test->result[i].dsts >> 4))
;
933 obj_add_int(valid_attrs, "Segment number",json_object_object_add(valid_attrs, "Segment number", json_object_new_int
(self_test->result[i].seg))
934 self_test->result[i].seg)json_object_object_add(valid_attrs, "Segment number", json_object_new_int
(self_test->result[i].seg))
;
935 obj_add_int(valid_attrs, "Valid Diagnostic Information",json_object_object_add(valid_attrs, "Valid Diagnostic Information"
, json_object_new_int(self_test->result[i].vdi))
936 self_test->result[i].vdi)json_object_object_add(valid_attrs, "Valid Diagnostic Information"
, json_object_new_int(self_test->result[i].vdi))
;
937 obj_add_uint64(valid_attrs, "Power on hours",json_object_object_add(valid_attrs, "Power on hours", json_object_new_uint64
(le64_to_cpu(self_test->result[i].poh)))
938 le64_to_cpu(self_test->result[i].poh))json_object_object_add(valid_attrs, "Power on hours", json_object_new_uint64
(le64_to_cpu(self_test->result[i].poh)))
;
939
940 if (self_test->result[i].vdi & NVME_ST_VALID_DIAG_INFO_NSID)
941 obj_add_uint(valid_attrs, "Namespace Identifier",json_object_object_add(valid_attrs, "Namespace Identifier", json_object_new_uint64
(le32_to_cpu(self_test->result[i].nsid)))
942 le32_to_cpu(self_test->result[i].nsid))json_object_object_add(valid_attrs, "Namespace Identifier", json_object_new_uint64
(le32_to_cpu(self_test->result[i].nsid)))
;
943
944 if (self_test->result[i].vdi & NVME_ST_VALID_DIAG_INFO_FLBA)
945 obj_add_uint64(valid_attrs, "Failing LBA",json_object_object_add(valid_attrs, "Failing LBA", json_object_new_uint64
(le64_to_cpu(self_test->result[i].flba)))
946 le64_to_cpu(self_test->result[i].flba))json_object_object_add(valid_attrs, "Failing LBA", json_object_new_uint64
(le64_to_cpu(self_test->result[i].flba)))
;
947
948 if (self_test->result[i].vdi & NVME_ST_VALID_DIAG_INFO_SCT)
949 obj_add_int(valid_attrs, "Status Code Type", self_test->result[i].sct)json_object_object_add(valid_attrs, "Status Code Type", json_object_new_int
(self_test->result[i].sct))
;
950
951 if (self_test->result[i].vdi & NVME_ST_VALID_DIAG_INFO_SC)
952 obj_add_int(valid_attrs, "Status Code", self_test->result[i].sc)json_object_object_add(valid_attrs, "Status Code", json_object_new_int
(self_test->result[i].sc))
;
953
954 obj_add_int(valid_attrs, "Vendor Specific",json_object_object_add(valid_attrs, "Vendor Specific", json_object_new_int
(self_test->result[i].vs[1] << 8 | self_test->result
[i].vs[0]))
955 self_test->result[i].vs[1] << 8 | self_test->result[i].vs[0])json_object_object_add(valid_attrs, "Vendor Specific", json_object_new_int
(self_test->result[i].vs[1] << 8 | self_test->result
[i].vs[0]))
;
956
957add:
958 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
959 }
960
961 obj_add_array(r, "List of Valid Reports", valid)json_object_object_add(r, "List of Valid Reports", valid);
962
963 json_print(r);
964}
965
966static void json_registers_cap(struct nvme_bar_cap *cap, struct json_object *r)
967{
968 char json_str[STR_LEN100];
969 struct json_object *cssa = json_create_array()json_object_new_array();
970 struct json_object *csso = json_create_object()json_object_new_object();
971 struct json_object *amsa = json_create_array()json_object_new_array();
972 struct json_object *amso = json_create_object()json_object_new_object();
973
974 sprintf(json_str, "%"PRIx64"l" "x""", *(uint64_t *)cap);
975 obj_add_strjson_object_add_value_string(r, "cap", json_str);
976
977 obj_add_strjson_object_add_value_string(r, "NVM Subsystem Shutdown Enhancements Supported (NSSES)",
978 cap->nsses ? "Supported" : "Not supported");
979 obj_add_strjson_object_add_value_string(r, "Controller Ready With Media Support (CRWMS)",
980 cap->crwms ? "Supported" : "Not supported");
981 obj_add_strjson_object_add_value_string(r, "Controller Ready Independent of Media Support (CRIMS)",
982 cap->crims ? "Supported" : "Not supported");
983 obj_add_strjson_object_add_value_string(r, "NVM Subsystem Shutdown Supported (NSSS)",
984 cap->nsss ? "Supported" : "Not supported");
985 obj_add_strjson_object_add_value_string(r, "Controller Memory Buffer Supported (CMBS):",
986 cap->cmbs ? "Supported" : "Not supported");
987 obj_add_strjson_object_add_value_string(r, "Persistent Memory Region Supported (PMRS)",
988 cap->pmrs ? "Supported" : "Not supported");
989
990 sprintf(json_str, "%u bytes", 1 << (12 + cap->mpsmax));
991 obj_add_strjson_object_add_value_string(r, "Memory Page Size Maximum (MPSMAX)", json_str);
992
993 sprintf(json_str, "%u bytes", 1 << (12 + cap->mpsmin));
994 obj_add_strjson_object_add_value_string(r, "Memory Page Size Minimum (MPSMIN)", json_str);
995
996 obj_add_strjson_object_add_value_string(r, "Controller Power Scope (CPS)", !cap->cps ? "Not Reported" : cap->cps == 1 ?
997 "Controller scope" : cap->cps == 2 ? "Domain scope" : "NVM subsystem scope");
998 obj_add_strjson_object_add_value_string(r, "Boot Partition Support (BPS)", cap->bps ? "Yes" : "No");
999
1000 obj_add_array(r, "Command Sets Supported (CSS)", cssa)json_object_object_add(r, "Command Sets Supported (CSS)", cssa
)
;
1001 obj_add_strjson_object_add_value_string(csso, "NVM command set", cap->css & 1 ? "Supported" : "Not supported");
1002 obj_add_strjson_object_add_value_string(csso, "One or more I/O Command Sets",
1003 cap->css & 0x40 ? "Supported" : "Not supported");
1004 obj_add_strjson_object_add_value_string(csso, cap->css & 0x80 ? "Only Admin Command Set" : "I/O Command Set",
1005 "Supported");
1006 array_add_obj(cssa, csso)json_object_array_add(cssa, csso);
1007
1008 obj_add_strjson_object_add_value_string(r, "NVM Subsystem Reset Supported (NSSRS)", cap->nssrs ? "Yes" : "No");
1009
1010 sprintf(json_str, "%u bytes", 1 << (2 + cap->dstrd));
1011 obj_add_strjson_object_add_value_string(r, "Doorbell Stride (DSTRD)", json_str);
1012
1013 sprintf(json_str, "%u ms", MS500_TO_MS(cap->to)((cap->to) * 500));
1014 obj_add_strjson_object_add_value_string(r, "Timeout (TO)", json_str);
1015
1016 obj_add_array(r, "Arbitration Mechanism Supported (AMS)", amsa)json_object_object_add(r, "Arbitration Mechanism Supported (AMS)"
, amsa)
;
1017 obj_add_strjson_object_add_value_string(amso, "Weighted Round Robin with Urgent Priority Class",
1018 cap->ams & 2 ? "Supported" : "Not supported");
1019 array_add_obj(amsa, amso)json_object_array_add(amsa, amso);
1020
1021 obj_add_strjson_object_add_value_string(r, "Contiguous Queues Required (CQR)", cap->cqr ? "Yes" : "No");
1022 obj_add_uint(r, "Maximum Queue Entries Supported (MQES)", cap->mqes + 1)json_object_object_add(r, "Maximum Queue Entries Supported (MQES)"
, json_object_new_uint64(cap->mqes + 1))
;
1023}
1024
1025static void json_registers_version(__u32 vs, struct json_object *r)
1026{
1027 char json_str[STR_LEN100];
1028
1029 sprintf(json_str, "%x", vs);
1030 obj_add_strjson_object_add_value_string(r, "Version", json_str);
1031
1032 sprintf(json_str, "%d.%d.%d", NVME_MAJOR(vs)(((vs) >> NVME_VS_MJR_SHIFT) & NVME_VS_MJR_MASK), NVME_MINOR(vs)(((vs) >> NVME_VS_MNR_SHIFT) & NVME_VS_MNR_MASK), NVME_TERTIARY(vs)(((vs) >> NVME_VS_TER_SHIFT) & NVME_VS_TER_MASK));
1033 obj_add_strjson_object_add_value_string(r, "NVMe specification", json_str);
1034}
1035
1036static void json_registers_intms(__u32 intms, struct json_object *r)
1037{
1038 obj_add_uint_x(r, "intms", intms);
1039
1040 obj_add_uint_x(r, "Interrupt Vector Mask Set (IVMS)", intms);
1041}
1042
1043static void json_registers_intmc(__u32 intmc, struct json_object *r)
1044{
1045 obj_add_uint_x(r, "intmc", intmc);
1046
1047 obj_add_uint_x(r, "Interrupt Vector Mask Set (IVMC)", intmc);
1048}
1049
1050static void json_registers_cc_ams(__u8 ams, struct json_object *r)
1051{
1052 char json_str[STR_LEN100];
1053
1054 switch (ams) {
1055 case NVME_CC_AMS_RR:
1056 sprintf(json_str, "Round Robin");
1057 break;
1058 case NVME_CC_AMS_WRRU:
1059 sprintf(json_str, "Weighted Round Robin with Urgent Priority Class");
1060 break;
1061 case NVME_CC_AMS_VS:
1062 sprintf(json_str, "Vendor Specific");
1063 break;
1064 default:
1065 sprintf(json_str, "%s", "Reserved");
1066 break;
1067 }
1068
1069 obj_add_strjson_object_add_value_string(r, "Arbitration Mechanism Selected (AMS)", json_str);
1070}
1071
1072static void json_registers_cc_shn(__u8 shn, struct json_object *r)
1073{
1074 char json_str[STR_LEN100];
1075
1076 switch (shn) {
1077 case NVME_CC_SHN_NONE:
1078 sprintf(json_str, "No notification; no effect");
1079 break;
1080 case NVME_CC_SHN_NORMAL:
1081 sprintf(json_str, "Normal shutdown notification");
1082 break;
1083 case NVME_CC_SHN_ABRUPT:
1084 sprintf(json_str, "Abrupt shutdown notification");
1085 break;
1086 default:
1087 sprintf(json_str, "%s", "Reserved");
1088 break;
1089 }
1090
1091 obj_add_strjson_object_add_value_string(r, "Shutdown Notification (SHN)", json_str);
1092}
1093
1094static void json_registers_cc(__u32 cc, struct json_object *r)
1095{
1096 char json_str[STR_LEN100];
1097
1098 sprintf(json_str, "%x", cc);
1099 obj_add_strjson_object_add_value_string(r, "cc", json_str);
1100
1101 obj_add_strjson_object_add_value_string(r, "Controller Ready Independent of Media Enable (CRIME)",
1102 NVME_CC_CRIME(cc)(((cc) >> NVME_CC_CRIME_SHIFT) & NVME_CC_CRIME_MASK
)
? "Enabled" : "Disabled");
1103
1104 sprintf(json_str, "%u bytes", POWER_OF_TWO(NVME_CC_IOCQES(cc))(1 << ((((cc) >> NVME_CC_IOCQES_SHIFT) & NVME_CC_IOCQES_MASK
)))
);
1105 obj_add_strjson_object_add_value_string(r, "I/O Completion Queue Entry Size (IOCQES): ", json_str);
1106
1107 sprintf(json_str, "%u bytes", POWER_OF_TWO(NVME_CC_IOSQES(cc))(1 << ((((cc) >> NVME_CC_IOSQES_SHIFT) & NVME_CC_IOSQES_MASK
)))
);
1108 obj_add_strjson_object_add_value_string(r, "I/O Submission Queue Entry Size (IOSQES)", json_str);
1109
1110 json_registers_cc_shn(NVME_CC_SHN(cc)(((cc) >> NVME_CC_SHN_SHIFT) & NVME_CC_SHN_MASK), r);
1111 json_registers_cc_ams(NVME_CC_AMS(cc)(((cc) >> NVME_CC_AMS_SHIFT) & NVME_CC_AMS_MASK), r);
1112
1113 sprintf(json_str, "%u bytes", POWER_OF_TWO(12 + NVME_CC_MPS(cc))(1 << (12 + (((cc) >> NVME_CC_MPS_SHIFT) & NVME_CC_MPS_MASK
)))
);
1114 obj_add_strjson_object_add_value_string(r, "Memory Page Size (MPS)", json_str);
1115
1116 obj_add_strjson_object_add_value_string(r, "I/O Command Set Selected (CSS)",
1117 NVME_CC_CSS(cc)(((cc) >> NVME_CC_CSS_SHIFT) & NVME_CC_CSS_MASK) == NVME_CC_CSS_NVM ? "NVM Command Set" :
1118 NVME_CC_CSS(cc)(((cc) >> NVME_CC_CSS_SHIFT) & NVME_CC_CSS_MASK) == NVME_CC_CSS_CSI ? "All supported I/O Command Sets" :
1119 NVME_CC_CSS(cc)(((cc) >> NVME_CC_CSS_SHIFT) & NVME_CC_CSS_MASK) == NVME_CC_CSS_ADMIN ? "Admin Command Set only" : "Reserved");
1120 obj_add_strjson_object_add_value_string(r, "Enable (EN)", NVME_CC_EN(cc)(((cc) >> NVME_CC_EN_SHIFT) & NVME_CC_EN_MASK) ? "Yes" : "No");
1121}
1122
1123static void json_registers_csts_shst(__u8 shst, struct json_object *r)
1124{
1125 char json_str[STR_LEN100];
1126
1127 switch (shst) {
1128 case NVME_CSTS_SHST_NORMAL:
1129 sprintf(json_str, "Normal operation (no shutdown has been requested)");
1130 break;
1131 case NVME_CSTS_SHST_OCCUR:
1132 sprintf(json_str, "Shutdown processing occurring");
1133 break;
1134 case NVME_CSTS_SHST_CMPLT:
1135 sprintf(json_str, "Shutdown processing complete");
1136 break;
1137 default:
1138 sprintf(json_str, "%s", "Reserved");
1139 break;
1140 }
1141
1142 obj_add_strjson_object_add_value_string(r, "Shutdown Status (SHST)", json_str);
1143}
1144
1145static void json_registers_csts(__u32 csts, struct json_object *r)
1146{
1147 obj_add_uint_x(r, "csts", csts);
1148
1149 obj_add_strjson_object_add_value_string(r, "Shutdown Type (ST)", NVME_CSTS_ST(csts)(((csts) >> NVME_CSTS_ST_SHIFT) & NVME_CSTS_ST_MASK
)
? "Subsystem" : "Controller");
1150 obj_add_strjson_object_add_value_string(r, "Processing Paused (PP)", NVME_CSTS_PP(csts)(((csts) >> NVME_CSTS_PP_SHIFT) & NVME_CSTS_PP_MASK
)
? "Yes" : "No");
1151 obj_add_strjson_object_add_value_string(r, "NVM Subsystem Reset Occurred (NSSRO)",
1152 NVME_CSTS_NSSRO(csts)(((csts) >> NVME_CSTS_NSSRO_SHIFT) & NVME_CSTS_NSSRO_MASK
)
? "Yes" : "No");
1153
1154 json_registers_csts_shst(NVME_CSTS_SHST(csts)(((csts) >> NVME_CSTS_SHST_SHIFT) & NVME_CSTS_SHST_MASK
)
, r);
1155
1156 obj_add_strjson_object_add_value_string(r, "Controller Fatal Status (CFS)", NVME_CSTS_CFS(csts)(((csts) >> NVME_CSTS_CFS_SHIFT) & NVME_CSTS_CFS_MASK
)
? "True" : "False");
1157 obj_add_strjson_object_add_value_string(r, "Ready (RDY)", NVME_CSTS_RDY(csts)(((csts) >> NVME_CSTS_RDY_SHIFT) & NVME_CSTS_RDY_MASK
)
? "Yes" : "No");
1158}
1159
1160static void json_registers_nssr(__u32 nssr, struct json_object *r)
1161{
1162 obj_add_uint_x(r, "nssr", nssr);
1163 obj_add_uint(r, "NVM Subsystem Reset Control (NSSRC)", nssr)json_object_object_add(r, "NVM Subsystem Reset Control (NSSRC)"
, json_object_new_uint64(nssr))
;
1164}
1165
1166static void json_registers_nssd(__u32 nssd, struct json_object *r)
1167{
1168 obj_add_uint_nx(r, "NVM Subsystem Shutdown Control (NSSC)", nssd);
1169}
1170
1171static void json_registers_crto(__u32 crto, struct json_object *r)
1172{
1173 obj_add_uint_x(r, "crto", crto);
1174
1175 obj_add_int_secs(r, "CRIMT", MS500_TO_SEC(NVME_CRTO_CRIMT(crto))((((((((crto) >> NVME_CRTO_CRIMT_SHIFT) & NVME_CRTO_CRIMT_MASK
)) * 500)) / 1000))
);
1176 obj_add_int_secs(r, "CRWMT", MS500_TO_SEC(NVME_CRTO_CRWMT(crto))((((((((crto) >> NVME_CRTO_CRWMT_SHIFT) & NVME_CRTO_CRWMT_MASK
)) * 500)) / 1000))
);
1177}
1178
1179static void json_registers_aqa(uint32_t aqa, struct json_object *r)
1180{
1181 obj_add_uint_x(r, "aqa", aqa);
1182 obj_add_uint(r, "Admin Completion Queue Size (ACQS)", NVME_AQA_ACQS(aqa) + 1)json_object_object_add(r, "Admin Completion Queue Size (ACQS)"
, json_object_new_uint64((((aqa) >> NVME_AQA_ACQS_SHIFT
) & NVME_AQA_ACQS_MASK) + 1))
;
1183 obj_add_uint(r, "Admin Submission Queue Size (ASQS)", NVME_AQA_ASQS(aqa) + 1)json_object_object_add(r, "Admin Submission Queue Size (ASQS)"
, json_object_new_uint64((((aqa) >> NVME_AQA_ASQS_SHIFT
) & NVME_AQA_ASQS_MASK) + 1))
;
1184}
1185
1186static void json_registers_asq(uint64_t asq, struct json_object *r)
1187{
1188 obj_add_prix64(r, "asq", asq);
1189 obj_add_prix64(r, "Admin Submission Queue Base (ASQB)", asq);
1190}
1191
1192static void json_registers_acq(uint64_t acq, struct json_object *r)
1193{
1194 obj_add_prix64(r, "acq", acq);
1195 obj_add_prix64(r, "Admin Completion Queue Base (ACQB)", acq);
1196}
1197
1198static void json_registers_cmbloc(uint32_t cmbloc, bool_Bool support, struct json_object *r)
1199{
1200 obj_add_uint_x(r, "cmbloc", cmbloc);
1201
1202 if (!support) {
1203 obj_add_result(r, "Controller Memory Buffer feature is not supported");
1204 return;
1205 }
1206
1207 obj_add_uint_0xjson_object_add_uint_0x(r, "Offset (OFST) (See cmbsz.szu for granularity)",
1208 (cmbloc & 0xfffff000) >> 12);
1209 obj_add_int(r, "CMB Queue Dword Alignment (CQDA)", (cmbloc & 0x100) >> 8)json_object_object_add(r, "CMB Queue Dword Alignment (CQDA)",
json_object_new_int((cmbloc & 0x100) >> 8))
;
1210 obj_add_strjson_object_add_value_string(r, "CMB Data Metadata Mixed Memory Support (CDMMMS)",
1211 (cmbloc & 0x00000080) >> 7 ? "Not enforced" : "Enforced");
1212 obj_add_strjson_object_add_value_string(r, "CMB Data Pointer and Command Independent Locations Support (CDPCILS)",
1213 (cmbloc & 0x00000040) >> 6 ? "Not enforced" : "Enforced");
1214 obj_add_strjson_object_add_value_string(r, "CMB Data Pointer Mixed Locations Support (CDPMLS)",
1215 (cmbloc & 0x00000020) >> 5 ? "Not enforced" : "Enforced");
1216 obj_add_strjson_object_add_value_string(r, "CMB Queue Physically Discontiguous Support (CQPDS)",
1217 (cmbloc & 0x00000010) >> 4 ? "Not enforced" : "Enforced");
1218 obj_add_strjson_object_add_value_string(r, "CMB Queue Mixed Memory Support (CQMMS)",
1219 (cmbloc & 0x00000008) >> 3 ? "Not enforced" : "Enforced");
1220 obj_add_uint_0xjson_object_add_uint_0x(r, "Base Indicator Register (BIR)", (cmbloc & 0x00000007));
1221}
1222
1223static void json_registers_cmbsz(uint32_t cmbsz, struct json_object *r)
1224{
1225 obj_add_uint_x(r, "cmbsz", cmbsz);
1226
1227 if (!cmbsz) {
1228 obj_add_result(r, "Controller Memory Buffer feature is not supported");
1229 return;
1230 }
1231
1232 obj_add_uint(r, "Size (SZ)", (cmbsz & 0xfffff000) >> 12)json_object_object_add(r, "Size (SZ)", json_object_new_uint64
((cmbsz & 0xfffff000) >> 12))
;
1233 obj_add_strjson_object_add_value_string(r, "Size Units (SZU)", nvme_register_szu_to_string((cmbsz & 0xf00) >> 8));
1234 obj_add_strjson_object_add_value_string(r, "Write Data Support (WDS)", cmbsz & 0x10 ? "Supported" : "Not supported");
1235 obj_add_strjson_object_add_value_string(r, "Read Data Support (RDS)", cmbsz & 8 ? "Supported" : "Not supported");
1236 obj_add_strjson_object_add_value_string(r, "PRP SGL List Support (LISTS)", cmbsz & 4 ? "Supported" : "Not supported");
1237 obj_add_strjson_object_add_value_string(r, "Completion Queue Support (CQS)", cmbsz & 2 ? "Supported" : "Not supported");
1238 obj_add_strjson_object_add_value_string(r, "Submission Queue Support (SQS)", cmbsz & 1 ? "Supported" : "Not supported");
1239}
1240
1241static void json_registers_bpinfo_brs(__u8 brs, struct json_object *r)
1242{
1243 char json_str[STR_LEN100];
1244
1245 switch (brs) {
1246 case 0:
1247 sprintf(json_str, "No Boot Partition read operation requested");
1248 break;
1249 case 1:
1250 sprintf(json_str, "Boot Partition read in progress");
1251 break;
1252 case 2:
1253 sprintf(json_str, "Boot Partition read completed successfully");
1254 break;
1255 case 3:
1256 sprintf(json_str, "Error completing Boot Partition read");
1257 break;
1258 default:
1259 sprintf(json_str, "%s", "Invalid");
1260 break;
1261 }
1262
1263 obj_add_strjson_object_add_value_string(r, "Boot Read Status (BRS)", json_str);
1264}
1265
1266static void json_registers_bpinfo(uint32_t bpinfo, struct json_object *r)
1267{
1268 obj_add_uint_x(r, "bpinfo", bpinfo);
1269
1270 obj_add_uint(r, "Active Boot Partition ID (ABPID)", NVME_BPINFO_ABPID(bpinfo))json_object_object_add(r, "Active Boot Partition ID (ABPID)",
json_object_new_uint64((((bpinfo) >> NVME_BPINFO_ABPID_SHIFT
) & NVME_BPINFO_ABPID_MASK)))
;
1271 json_registers_bpinfo_brs(NVME_BPINFO_BRS(bpinfo)(((bpinfo) >> NVME_BPINFO_BRS_SHIFT) & NVME_BPINFO_BRS_MASK
)
, r);
1272 obj_add_uint(r, "Boot Partition Size (BPSZ)", NVME_BPINFO_BPSZ(bpinfo))json_object_object_add(r, "Boot Partition Size (BPSZ)", json_object_new_uint64
((((bpinfo) >> NVME_BPINFO_BPSZ_SHIFT) & NVME_BPINFO_BPSZ_MASK
)))
;
1273}
1274
1275static void json_registers_bprsel(uint32_t bprsel, struct json_object *r)
1276{
1277 obj_add_uint_x(r, "bprsel", bprsel);
1278
1279 obj_add_uint(r, "Boot Partition Identifier (BPID)", NVME_BPRSEL_BPID(bprsel))json_object_object_add(r, "Boot Partition Identifier (BPID)",
json_object_new_uint64((((bprsel) >> NVME_BPRSEL_BPID_SHIFT
) & NVME_BPRSEL_BPID_MASK)))
;
1280 obj_add_uint_x(r, "Boot Partition Read Offset (BPROF)", NVME_BPRSEL_BPROF(bprsel)(((bprsel) >> NVME_BPRSEL_BPROF_SHIFT) & NVME_BPRSEL_BPROF_MASK
)
);
1281 obj_add_uint_x(r, "Boot Partition Read Size (BPRSZ)", NVME_BPRSEL_BPRSZ(bprsel)(((bprsel) >> NVME_BPRSEL_BPRSZ_SHIFT) & NVME_BPRSEL_BPRSZ_MASK
)
);
1282}
1283
1284static void json_registers_bpmbl(uint64_t bpmbl, struct json_object *r)
1285{
1286 obj_add_prix64(r, "bpmbl", bpmbl);
1287
1288 obj_add_prix64(r, "Boot Partition Memory Buffer Base Address (BMBBA)",
1289 (uint64_t)NVME_BPMBL_BMBBA(bpmbl)(((bpmbl) >> NVME_BPMBL_BMBBA_SHIFT) & NVME_BPMBL_BMBBA_MASK
)
);
1290}
1291
1292static void json_registers_cmbmsc(uint64_t cmbmsc, struct json_object *r)
1293{
1294 obj_add_prix64(r, "cmbmsc", cmbmsc);
1295
1296 obj_add_prix64(r, "Controller Base Address (CBA)", (uint64_t)NVME_CMBMSC_CBA(cmbmsc)(((cmbmsc) >> NVME_CMBMSC_CBA_SHIFT) & NVME_CMBMSC_CBA_MASK
)
);
1297 obj_add_prix64(r, "Controller Memory Space Enable (CMSE)", NVME_CMBMSC_CMSE(cmbmsc)(((cmbmsc) >> NVME_CMBMSC_CMSE_SHIFT) & NVME_CMBMSC_CMSE_MASK
)
);
1298 obj_add_strjson_object_add_value_string(r, "Capabilities Registers Enabled (CRE)",
1299 NVME_CMBMSC_CRE(cmbmsc)(((cmbmsc) >> NVME_CMBMSC_CRE_SHIFT) & NVME_CMBMSC_CRE_MASK
)
? "Enabled" : "Not enabled");
1300}
1301
1302static void json_registers_cmbsts(uint32_t cmbsts, struct json_object *r)
1303{
1304 obj_add_uint_x(r, "cmbsts", cmbsts);
1305
1306 obj_add_uint_x(r, "Controller Base Address Invalid (CBAI)", NVME_CMBSTS_CBAI(cmbsts)(((cmbsts) >> NVME_CMBSTS_CBAI_SHIFT) & NVME_CMBSTS_CBAI_MASK
)
);
1307}
1308
1309static void json_registers_cmbebs(uint32_t cmbebs, struct json_object *r)
1310{
1311 char buffer[BUF_LEN320];
1312
1313 obj_add_uint_nx(r, "cmbebs", cmbebs);
1314
1315 obj_add_uint_nx(r, "CMB Elasticity Buffer Size Base (CMBWBZ)", NVME_CMBEBS_CMBWBZ(cmbebs)(((cmbebs) >> NVME_CMBEBS_CMBWBZ_SHIFT) & NVME_CMBEBS_CMBWBZ_MASK
)
);
1316 sprintf(buffer, "%s", NVME_CMBEBS_RBB(cmbebs)(((cmbebs) >> NVME_CMBEBS_RBB_SHIFT) & NVME_CMBEBS_RBB_MASK
)
? "shall" : "may");
1317 obj_add_strjson_object_add_value_string(r, "CMB Read Bypass Behavior (CMBRBB)", buffer);
1318 obj_add_strjson_object_add_value_string(r, "CMB Elasticity Buffer Size Units (CMBSZU)",
1319 nvme_register_unit_to_string(NVME_CMBEBS_CMBSZU(cmbebs)(((cmbebs) >> NVME_CMBEBS_CMBSZU_SHIFT) & NVME_CMBEBS_CMBSZU_MASK
)
));
1320}
1321
1322static void json_registers_cmbswtp(uint32_t cmbswtp, struct json_object *r)
1323{
1324 char str[STR_LEN100];
1325
1326 obj_add_uint_nx(r, "cmbswtp", cmbswtp);
1327
1328 obj_add_uint_nx(r, "CMB Sustained Write Throughput (CMBSWTV)",
1329 NVME_CMBSWTP_CMBSWTV(cmbswtp)(((cmbswtp) >> NVME_CMBSWTP_CMBSWTV_SHIFT) & NVME_CMBSWTP_CMBSWTV_MASK
)
);
1330 sprintf(str, "%s/second", nvme_register_unit_to_string(NVME_CMBSWTP_CMBSWTU(cmbswtp)(((cmbswtp) >> NVME_CMBSWTP_CMBSWTU_SHIFT) & NVME_CMBSWTP_CMBSWTU_MASK
)
));
1331 obj_add_strjson_object_add_value_string(r, "CMB Sustained Write Throughput Units (CMBSWTU)", str);
1332}
1333
1334static void json_registers_pmrcap(uint32_t pmrcap, struct json_object *r)
1335{
1336 obj_add_uint_x(r, "pmrcap", pmrcap);
1337
1338 obj_add_strjson_object_add_value_string(r, "Controller Memory Space Supported (CMSS)",
1339 NVME_PMRCAP_CMSS(pmrcap)(((pmrcap) >> NVME_PMRCAP_CMSS_SHIFT) & NVME_PMRCAP_CMSS_MASK
)
? "Supported" : "Not supported");
1340 obj_add_uint_x(r, "Persistent Memory Region Timeout (PMRTO)", NVME_PMRCAP_PMRTO(pmrcap)(((pmrcap) >> NVME_PMRCAP_PMRTO_SHIFT) & NVME_PMRCAP_PMRTO_MASK
)
);
1341 obj_add_uint_x(r, "Persistent Memory Region Write Barrier Mechanisms (PMRWBM)",
1342 NVME_PMRCAP_PMRWBM(pmrcap)(((pmrcap) >> NVME_PMRCAP_PMRWBM_SHIFT) & NVME_PMRCAP_PMRWBM_MASK
)
);
1343 obj_add_strjson_object_add_value_string(r, "Persistent Memory Region Time Units (PMRTU)",
1344 NVME_PMRCAP_PMRTU(pmrcap)(((pmrcap) >> NVME_PMRCAP_PMRTU_SHIFT) & NVME_PMRCAP_PMRTU_MASK
)
? "minutes" : "500 milliseconds");
1345 obj_add_uint_x(r, "Base Indicator Register (BIR)", NVME_PMRCAP_BIR(pmrcap)(((pmrcap) >> NVME_PMRCAP_BIR_SHIFT) & NVME_PMRCAP_BIR_MASK
)
);
1346 obj_add_strjson_object_add_value_string(r, "Write Data Support (WDS)",
1347 NVME_PMRCAP_WDS(pmrcap)(((pmrcap) >> NVME_PMRCAP_WDS_SHIFT) & NVME_PMRCAP_WDS_MASK
)
? "Supported" : "Not supported");
1348 obj_add_strjson_object_add_value_string(r, "Read Data Support (RDS)",
1349 NVME_PMRCAP_RDS(pmrcap)(((pmrcap) >> NVME_PMRCAP_RDS_SHIFT) & NVME_PMRCAP_RDS_MASK
)
? "Supported" : "Not supported");
1350}
1351
1352static void json_registers_pmrctl(uint32_t pmrctl, struct json_object *r)
1353{
1354 obj_add_uint_x(r, "pmrctl", pmrctl);
1355
1356 obj_add_strjson_object_add_value_string(r, "Enable (EN)", NVME_PMRCTL_EN(pmrctl)(((pmrctl) >> NVME_PMRCTL_EN_SHIFT) & NVME_PMRCTL_EN_MASK
)
? "Ready" : "Disabled");
1357}
1358
1359static void json_registers_pmrsts(uint32_t pmrsts, bool_Bool ready, struct json_object *r)
1360{
1361 obj_add_uint_x(r, "pmrsts", pmrsts);
1362
1363 obj_add_uint_x(r, "Controller Base Address Invalid (CBAI)", NVME_PMRSTS_CBAI(pmrsts)(((pmrsts) >> NVME_PMRSTS_CBAI_SHIFT) & NVME_PMRSTS_CBAI_MASK
)
);
1364 obj_add_strjson_object_add_value_string(r, "Health Status (HSTS)",
1365 nvme_register_pmr_hsts_to_string(NVME_PMRSTS_HSTS(pmrsts)(((pmrsts) >> NVME_PMRSTS_HSTS_SHIFT) & NVME_PMRSTS_HSTS_MASK
)
));
1366 obj_add_strjson_object_add_value_string(r, "Not Ready (NRDY)",
1367 !NVME_PMRSTS_NRDY(pmrsts)(((pmrsts) >> NVME_PMRSTS_NRDY_SHIFT) & NVME_PMRSTS_NRDY_MASK
)
&& ready ? "Ready" : "Not ready");
1368 obj_add_uint_x(r, "Error (ERR)", NVME_PMRSTS_ERR(pmrsts)(((pmrsts) >> NVME_PMRSTS_ERR_SHIFT) & NVME_PMRSTS_ERR_MASK
)
);
1369}
1370
1371static void json_registers_pmrebs(uint32_t pmrebs, struct json_object *r)
1372{
1373 obj_add_uint_x(r, "pmrebs", pmrebs);
1374
1375 obj_add_uint_x(r, "PMR Elasticity Buffer Size Base (PMRWBZ)", NVME_PMREBS_PMRWBZ(pmrebs)(((pmrebs) >> NVME_PMREBS_PMRWBZ_SHIFT) & NVME_PMREBS_PMRWBZ_MASK
)
);
1376 obj_add_strjson_object_add_value_string(r, "Read Bypass Behavior", NVME_PMREBS_RBB(pmrebs)(((pmrebs) >> NVME_PMREBS_RBB_SHIFT) & NVME_PMREBS_RBB_MASK
)
? "Shall" : "May");
1377 obj_add_strjson_object_add_value_string(r, "PMR Elasticity Buffer Size Units (PMRSZU)",
1378 nvme_register_unit_to_string(NVME_PMREBS_PMRSZU(pmrebs)(((pmrebs) >> NVME_PMREBS_PMRSZU_SHIFT) & NVME_PMREBS_PMRSZU_MASK
)
));
1379}
1380
1381static void json_registers_pmrswtp(uint32_t pmrswtp, struct json_object *r)
1382{
1383 obj_add_uint_x(r, "pmrswtp", pmrswtp);
1384
1385 obj_add_uint_x(r, "PMR Sustained Write Throughput (PMRSWTV)",
1386 NVME_PMRSWTP_PMRSWTV(pmrswtp)(((pmrswtp) >> NVME_PMRSWTP_PMRSWTU_SHIFT) & NVME_PMRSWTP_PMRSWTU_MASK
)
);
1387 obj_add_key(r, "PMR Sustained Write Throughput Units (PMRSWTU)", "%s/second",
1388 nvme_register_unit_to_string(NVME_PMRSWTP_PMRSWTU(pmrswtp)(((pmrswtp) >> NVME_PMRSWTP_PMRSWTU_SHIFT) & NVME_PMRSWTP_PMRSWTU_MASK
)
));
1389}
1390
1391static void json_registers_pmrmscl(uint32_t pmrmscl, struct json_object *r)
1392{
1393 obj_add_uint_nx(r, "pmrmscl", pmrmscl);
1394
1395 obj_add_uint_nx(r, "Controller Base Address (CBA)", (uint32_t)NVME_PMRMSC_CBA(pmrmscl)(((pmrmscl) >> NVME_PMRMSC_CBA_SHIFT) & NVME_PMRMSC_CBA_MASK
)
);
1396 obj_add_uint_nx(r, "Controller Memory Space Enable (CMSE)", NVME_PMRMSC_CMSE(pmrmscl)(((pmrmscl) >> NVME_PMRMSC_CMSE_SHIFT) & NVME_PMRMSC_CMSE_MASK
)
);
1397}
1398
1399static void json_registers_pmrmscu(uint32_t pmrmscu, struct json_object *r)
1400{
1401 obj_add_uint_nx(r, "pmrmscu", pmrmscu);
1402
1403 obj_add_uint_nx(r, "Controller Base Address (CBA)", pmrmscu);
1404}
1405
1406static void json_registers_unknown(int offset, uint64_t value64, struct json_object *r)
1407{
1408 obj_add_uint_02xjson_object_add_uint_02x(r, "unknown property", offset);
1409 obj_add_strjson_object_add_value_string(r, "name", nvme_register_to_string(offset));
1410 obj_add_prix64(r, "value", value64);
1411}
1412
1413static void json_single_property_human(int offset, uint64_t value64, struct json_object *r)
1414{
1415 uint32_t value32 = (uint32_t)value64;
1416
1417 switch (offset) {
1418 case NVME_REG_CAP:
1419 json_registers_cap((struct nvme_bar_cap *)&value64, r);
1420 break;
1421 case NVME_REG_VS:
1422 json_registers_version(value32, r);
1423 break;
1424 case NVME_REG_CC:
1425 json_registers_cc(value32, r);
1426 break;
1427 case NVME_REG_CSTS:
1428 json_registers_csts(value32, r);
1429 break;
1430 case NVME_REG_NSSR:
1431 json_registers_nssr(value32, r);
1432 break;
1433 case NVME_REG_NSSD:
1434 json_registers_nssd(value32, r);
1435 break;
1436 case NVME_REG_CRTO:
1437 json_registers_crto(value32, r);
1438 break;
1439 default:
1440 json_registers_unknown(offset, value64, r);
1441 break;
1442 }
1443}
1444
1445static void json_single_property(int offset, uint64_t value64)
1446{
1447 struct json_object *r = json_create_object()json_object_new_object();
1448 char json_str[STR_LEN100];
1449 uint32_t value32 = (uint32_t)value64;
1450
1451 if (verbose_mode()) {
1452 json_single_property_human(offset, value64, r);
1453 } else {
1454 sprintf(json_str, "0x%02x", offset);
1455 obj_add_strjson_object_add_value_string(r, "property", json_str);
1456
1457 obj_add_strjson_object_add_value_string(r, "name", nvme_register_to_string(offset));
1458
1459 if (nvme_is_64bit_reg(offset))
1460 sprintf(json_str, "%"PRIx64"l" "x""", value64);
1461 else
1462 sprintf(json_str, "%x", value32);
1463
1464 obj_add_strjson_object_add_value_string(r, "value", json_str);
1465 }
1466
1467 json_print(r);
1468}
1469
1470struct json_object *json_effects_log(enum nvme_csi csi,
1471 struct nvme_cmd_effects_log *effects_log)
1472{
1473 struct json_object *r = json_create_object()json_object_new_object();
1474 struct json_object *acs = json_create_object()json_object_new_object();
1475 struct json_object *iocs = json_create_object()json_object_new_object();
1476 unsigned int opcode;
1477 char key[128];
1478 __u32 effect;
1479
1480 obj_add_uint(r, "command_set_identifier", csi)json_object_object_add(r, "command_set_identifier", json_object_new_uint64
(csi))
;
1481
1482 for (opcode = 0; opcode < 256; opcode++) {
1483 effect = le32_to_cpu(effects_log->acs[opcode]);
1484 if (effect & NVME_CMD_EFFECTS_CSUPP) {
1485 sprintf(key, "ACS_%u (%s)", opcode,
1486 nvme_cmd_to_string(1, opcode));
1487 obj_add_uint(acs, key, effect)json_object_object_add(acs, key, json_object_new_uint64(effect
))
;
1488 }
1489 }
1490
1491 obj_add_obj(r, "admin_cmd_set", acs)json_object_object_add(r, "admin_cmd_set", acs);
1492
1493 for (opcode = 0; opcode < 256; opcode++) {
1494 effect = le32_to_cpu(effects_log->iocs[opcode]);
1495 if (effect & NVME_CMD_EFFECTS_CSUPP) {
1496 sprintf(key, "IOCS_%u (%s)", opcode,
1497 nvme_cmd_to_string(0, opcode));
1498 obj_add_uint(iocs, key, effect)json_object_object_add(iocs, key, json_object_new_uint64(effect
))
;
1499 }
1500 }
1501
1502 obj_add_obj(r, "io_cmd_set", iocs)json_object_object_add(r, "io_cmd_set", iocs);
1503 return r;
1504}
1505
1506static void json_effects_log_list(struct list_head *list)
1507{
1508 struct json_object *r = json_create_array()json_object_new_array();
1509 nvme_effects_log_node_t *node = NULL((void*)0);
1510
1511 list_for_each(list, node, node)for ((node) = list_node_to_off_(((void)"../nvme-print-json.c"
":" "1511", (list))->n.next, (((__builtin_offsetof(typeof
(*node), node) + ((typeof(node->node) *)0 != (struct list_node
*)0))))); list_node_from_off_((void *)(node), (((__builtin_offsetof
(typeof(*node), node) + ((typeof(node->node) *)0 != (struct
list_node *)0))))) != &((list))->n; (node) = list_node_to_off_
(list_node_from_off_((void *)(node), (((__builtin_offsetof(typeof
(*node), node) + ((typeof(node->node) *)0 != (struct list_node
*)0)))))->next, (((__builtin_offsetof(typeof(*node), node
) + ((typeof(node->node) *)0 != (struct list_node *)0)))))
)
{
1512 struct json_object *json_page =
1513 json_effects_log(node->csi, &node->effects);
1514 array_add_obj(r, json_page)json_object_array_add(r, json_page);
1515 }
1516
1517 json_print(r);
1518}
1519
1520static void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log,
1521 const char *devname)
1522{
1523 struct json_object *r = json_create_object()json_object_new_object();
1524 struct json_object *dev = json_create_object()json_object_new_object();
1525 struct json_object *sstat = json_create_object()json_object_new_object();
1526 struct json_object *ssi = json_create_object()json_object_new_object();
1527 const char *status_str;
1528 __u16 status, sos;
1529 __u8 fails, sans;
1530 char str[128];
1531
1532 status = le16_to_cpu(sanitize_log->sstat);
1533
1534 obj_add_int(dev, "sprog", le16_to_cpu(sanitize_log->sprog))json_object_object_add(dev, "sprog", json_object_new_int(le16_to_cpu
(sanitize_log->sprog)))
;
1535 obj_add_int(sstat, "media_verification_canceled", NVME_GET(status, SANITIZE_SSTAT_MVCNCLD))json_object_object_add(sstat, "media_verification_canceled", json_object_new_int
((((status) >> NVME_SANITIZE_SSTAT_MVCNCLD_SHIFT) &
NVME_SANITIZE_SSTAT_MVCNCLD_MASK)))
;
1536 obj_add_int(sstat, "global_erased", NVME_GET(status, SANITIZE_SSTAT_GLOBAL_DATA_ERASED))json_object_object_add(sstat, "global_erased", json_object_new_int
((((status) >> NVME_SANITIZE_SSTAT_GLOBAL_DATA_ERASED_SHIFT
) & NVME_SANITIZE_SSTAT_GLOBAL_DATA_ERASED_MASK)))
;
1537 obj_add_int(sstat, "no_cmplted_passes", NVME_GET(status, SANITIZE_SSTAT_COMPLETED_PASSES))json_object_object_add(sstat, "no_cmplted_passes", json_object_new_int
((((status) >> NVME_SANITIZE_SSTAT_COMPLETED_PASSES_SHIFT
) & NVME_SANITIZE_SSTAT_COMPLETED_PASSES_MASK)))
;
1538
1539 sos = NVME_GET(status, SANITIZE_SSTAT_STATUS)(((status) >> NVME_SANITIZE_SSTAT_STATUS_SHIFT) & NVME_SANITIZE_SSTAT_STATUS_MASK
)
;
1540 status_str = nvme_sstat_status_to_string(status);
1541 sprintf(str, "(%d) %s", sos, status_str);
1542 obj_add_strjson_object_add_value_string(sstat, "status", str);
1543
1544 obj_add_obj(dev, "sstat", sstat)json_object_object_add(dev, "sstat", sstat);
1545 obj_add_uint(dev, "cdw10_info", le32_to_cpu(sanitize_log->scdw10))json_object_object_add(dev, "cdw10_info", json_object_new_uint64
(le32_to_cpu(sanitize_log->scdw10)))
;
1546 obj_add_uint(dev, "time_over_write", le32_to_cpu(sanitize_log->eto))json_object_object_add(dev, "time_over_write", json_object_new_uint64
(le32_to_cpu(sanitize_log->eto)))
;
1547 obj_add_uint(dev, "time_block_erase", le32_to_cpu(sanitize_log->etbe))json_object_object_add(dev, "time_block_erase", json_object_new_uint64
(le32_to_cpu(sanitize_log->etbe)))
;
1548 obj_add_uint(dev, "time_crypto_erase", le32_to_cpu(sanitize_log->etce))json_object_object_add(dev, "time_crypto_erase", json_object_new_uint64
(le32_to_cpu(sanitize_log->etce)))
;
1549 obj_add_uint(dev, "time_over_write_no_dealloc", le32_to_cpu(sanitize_log->etond))json_object_object_add(dev, "time_over_write_no_dealloc", json_object_new_uint64
(le32_to_cpu(sanitize_log->etond)))
;
1550 obj_add_uint(dev, "time_block_erase_no_dealloc", le32_to_cpu(sanitize_log->etbend))json_object_object_add(dev, "time_block_erase_no_dealloc", json_object_new_uint64
(le32_to_cpu(sanitize_log->etbend)))
;
1551 obj_add_uint(dev, "time_crypto_erase_no_dealloc", le32_to_cpu(sanitize_log->etcend))json_object_object_add(dev, "time_crypto_erase_no_dealloc", json_object_new_uint64
(le32_to_cpu(sanitize_log->etcend)))
;
1552 obj_add_uint(dev, "time_post_verification_dealloc", le32_to_cpu(sanitize_log->etpvds))json_object_object_add(dev, "time_post_verification_dealloc",
json_object_new_uint64(le32_to_cpu(sanitize_log->etpvds))
)
;
1553
1554 sans = NVME_GET(sanitize_log->ssi, SANITIZE_SSI_SANS)(((sanitize_log->ssi) >> NVME_SANITIZE_SSI_SANS_SHIFT
) & NVME_SANITIZE_SSI_SANS_MASK)
;
1555 status_str = nvme_ssi_state_to_string(sans);
1556 sprintf(str, "(%d) %s", sans, status_str);
1557 obj_add_strjson_object_add_value_string(ssi, "sanitize_state", str);
1558
1559 if (sos == NVME_SANITIZE_SSTAT_STATUS_COMPLETED_FAILED) {
1560 fails = NVME_GET(sanitize_log->ssi, SANITIZE_SSI_FAILS)(((sanitize_log->ssi) >> NVME_SANITIZE_SSI_FAILS_SHIFT
) & NVME_SANITIZE_SSI_FAILS_MASK)
;
1561 status_str = nvme_ssi_state_to_string(fails);
1562 sprintf(str, "(%d) %s", fails, status_str);
1563 obj_add_strjson_object_add_value_string(ssi, "failure_state", str);
1564 }
1565
1566 obj_add_obj(dev, "sanitize_state_information", ssi)json_object_object_add(dev, "sanitize_state_information", ssi
)
;
1567 obj_add_obj(r, devname, dev)json_object_object_add(r, devname, dev);
1568
1569 json_print(r);
1570}
1571
1572static void json_predictable_latency_per_nvmset(
1573 struct nvme_nvmset_predictable_lat_log *plpns_log,
1574 __u16 nvmset_id, const char *devname)
1575{
1576 struct json_object *r = json_create_object()json_object_new_object();
1577
1578 obj_add_uint(r, "nvmset_id", le16_to_cpu(nvmset_id))json_object_object_add(r, "nvmset_id", json_object_new_uint64
(le16_to_cpu(nvmset_id)))
;
1579 obj_add_uint(r, "status", plpns_log->status)json_object_object_add(r, "status", json_object_new_uint64(plpns_log
->status))
;
1580 obj_add_uint(r, "event_type", le16_to_cpu(plpns_log->event_type))json_object_object_add(r, "event_type", json_object_new_uint64
(le16_to_cpu(plpns_log->event_type)))
;
1581 obj_add_uint64(r, "dtwin_reads_typical", le64_to_cpu(plpns_log->dtwin_rt))json_object_object_add(r, "dtwin_reads_typical", json_object_new_uint64
(le64_to_cpu(plpns_log->dtwin_rt)))
;
1582 obj_add_uint64(r, "dtwin_writes_typical", le64_to_cpu(plpns_log->dtwin_wt))json_object_object_add(r, "dtwin_writes_typical", json_object_new_uint64
(le64_to_cpu(plpns_log->dtwin_wt)))
;
1583 obj_add_uint64(r, "dtwin_time_maximum", le64_to_cpu(plpns_log->dtwin_tmax))json_object_object_add(r, "dtwin_time_maximum", json_object_new_uint64
(le64_to_cpu(plpns_log->dtwin_tmax)))
;
1584 obj_add_uint64(r, "ndwin_time_minimum_high", le64_to_cpu(plpns_log->ndwin_tmin_hi))json_object_object_add(r, "ndwin_time_minimum_high", json_object_new_uint64
(le64_to_cpu(plpns_log->ndwin_tmin_hi)))
;
1585 obj_add_uint64(r, "ndwin_time_minimum_low", le64_to_cpu(plpns_log->ndwin_tmin_lo))json_object_object_add(r, "ndwin_time_minimum_low", json_object_new_uint64
(le64_to_cpu(plpns_log->ndwin_tmin_lo)))
;
1586 obj_add_uint64(r, "dtwin_reads_estimate", le64_to_cpu(plpns_log->dtwin_re))json_object_object_add(r, "dtwin_reads_estimate", json_object_new_uint64
(le64_to_cpu(plpns_log->dtwin_re)))
;
1587 obj_add_uint64(r, "dtwin_writes_estimate", le64_to_cpu(plpns_log->dtwin_we))json_object_object_add(r, "dtwin_writes_estimate", json_object_new_uint64
(le64_to_cpu(plpns_log->dtwin_we)))
;
1588 obj_add_uint64(r, "dtwin_time_estimate", le64_to_cpu(plpns_log->dtwin_te))json_object_object_add(r, "dtwin_time_estimate", json_object_new_uint64
(le64_to_cpu(plpns_log->dtwin_te)))
;
1589
1590 json_print(r);
1591}
1592
1593static void json_predictable_latency_event_agg_log(
1594 struct nvme_aggregate_predictable_lat_event *pea_log,
1595 __u64 log_entries, __u32 size, const char *devname)
1596{
1597 struct json_object *r = json_create_object()json_object_new_object();
1598 struct json_object *valid_attrs;
1599 struct json_object *valid = json_create_array()json_object_new_array();
1600 __u64 num_entries = le64_to_cpu(pea_log->num_entries);
1601 __u64 num_iter = min(num_entries, log_entries)((num_entries) > (log_entries) ? (log_entries) : (num_entries
))
;
1602
1603 obj_add_uint64(r, "num_entries_avail", num_entries)json_object_object_add(r, "num_entries_avail", json_object_new_uint64
(num_entries))
;
1604
1605 for (int i = 0; i < num_iter; i++) {
1606 valid_attrs = json_create_object()json_object_new_object();
1607 obj_add_uint(valid_attrs, "entry", le16_to_cpu(pea_log->entries[i]))json_object_object_add(valid_attrs, "entry", json_object_new_uint64
(le16_to_cpu(pea_log->entries[i])))
;
1608 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
1609 }
1610
1611 obj_add_array(r, "list_of_entries", valid)json_object_object_add(r, "list_of_entries", valid);
1612
1613 json_print(r);
1614}
1615
1616static void json_add_bitmap(int i, __u8 seb, struct json_object *r)
1617{
1618 char evt_str[50];
1619 char key[128];
1620
1621 for (int bit = 0; bit < CHAR_BIT8; bit++) {
1622 if (nvme_pel_event_to_string(bit + i * CHAR_BIT8)) {
1623 sprintf(key, "bitmap_%x", (bit + i * CHAR_BIT8));
1624 if ((seb >> bit) & 0x1)
1625 snprintf(evt_str, sizeof(evt_str), "Support %s",
1626 nvme_pel_event_to_string(bit + i * CHAR_BIT8));
1627 obj_add_strjson_object_add_value_string(r, key, evt_str);
1628 }
1629 }
1630}
1631
1632void nvme_json_pevent_log_head(struct nvme_persistent_event_log *pevent_log_head,
1633 struct json_object *r)
1634{
1635 int i;
1636 char sn[sizeof(pevent_log_head->sn) + 1];
1637 char mn[sizeof(pevent_log_head->mn) + 1];
1638 char subnqn[sizeof(pevent_log_head->subnqn) + 1];
1639
1640 snprintf(sn, sizeof(sn), "%-.*s", (int)sizeof(pevent_log_head->sn), pevent_log_head->sn);
1641 snprintf(mn, sizeof(mn), "%-.*s", (int)sizeof(pevent_log_head->mn), pevent_log_head->mn);
1642 snprintf(subnqn, sizeof(subnqn), "%-.*s", (int)sizeof(pevent_log_head->subnqn),
1643 pevent_log_head->subnqn);
1644
1645 obj_add_uint(r, "log_id", pevent_log_head->lid)json_object_object_add(r, "log_id", json_object_new_uint64(pevent_log_head
->lid))
;
1646 obj_add_uint(r, "total_num_of_events", le32_to_cpu(pevent_log_head->tnev))json_object_object_add(r, "total_num_of_events", json_object_new_uint64
(le32_to_cpu(pevent_log_head->tnev)))
;
1647 obj_add_uint64(r, "total_log_len", le64_to_cpu(pevent_log_head->tll))json_object_object_add(r, "total_log_len", json_object_new_uint64
(le64_to_cpu(pevent_log_head->tll)))
;
1648 obj_add_uint(r, "log_revision", pevent_log_head->rv)json_object_object_add(r, "log_revision", json_object_new_uint64
(pevent_log_head->rv))
;
1649 obj_add_uint(r, "log_header_len", le16_to_cpu(pevent_log_head->lhl))json_object_object_add(r, "log_header_len", json_object_new_uint64
(le16_to_cpu(pevent_log_head->lhl)))
;
1650 obj_add_uint64(r, "timestamp", le64_to_cpu(pevent_log_head->ts))json_object_object_add(r, "timestamp", json_object_new_uint64
(le64_to_cpu(pevent_log_head->ts)))
;
1651 obj_add_uint128(r, "power_on_hours", le128_to_cpu(pevent_log_head->poh))json_object_object_add(r, "power_on_hours", util_json_object_new_uint128
(le128_to_cpu(pevent_log_head->poh)))
;
1652 obj_add_uint64(r, "power_cycle_count", le64_to_cpu(pevent_log_head->pcc))json_object_object_add(r, "power_cycle_count", json_object_new_uint64
(le64_to_cpu(pevent_log_head->pcc)))
;
1653 obj_add_uint(r, "pci_vid", le16_to_cpu(pevent_log_head->vid))json_object_object_add(r, "pci_vid", json_object_new_uint64(le16_to_cpu
(pevent_log_head->vid)))
;
1654 obj_add_uint(r, "pci_ssvid", le16_to_cpu(pevent_log_head->ssvid))json_object_object_add(r, "pci_ssvid", json_object_new_uint64
(le16_to_cpu(pevent_log_head->ssvid)))
;
1655 obj_add_strjson_object_add_value_string(r, "sn", sn);
1656 obj_add_strjson_object_add_value_string(r, "mn", mn);
1657 obj_add_strjson_object_add_value_string(r, "subnqn", subnqn);
1658 obj_add_uint(r, "gen_number", le16_to_cpu(pevent_log_head->gen_number))json_object_object_add(r, "gen_number", json_object_new_uint64
(le16_to_cpu(pevent_log_head->gen_number)))
;
1659 obj_add_uint(r, "rci", le32_to_cpu(pevent_log_head->rci))json_object_object_add(r, "rci", json_object_new_uint64(le32_to_cpu
(pevent_log_head->rci)))
;
1660
1661 for (i = 0; i < ARRAY_SIZE(pevent_log_head->seb)(sizeof(pevent_log_head->seb) / sizeof((pevent_log_head->
seb)[0]))
; i++) {
1662 if (!pevent_log_head->seb[i])
1663 continue;
1664 json_add_bitmap(i, pevent_log_head->seb[i], r);
1665 }
1666}
1667
1668void nvme_json_pel_smart_health(void *pevent_log_info, __u32 offset,
1669 struct json_object *valid_attrs)
1670{
1671 char key[128];
1672 struct nvme_smart_log *smart_event = pevent_log_info + offset;
1673 unsigned int temperature = (smart_event->temperature[1] << 8) | smart_event->temperature[0];
1674 nvme_uint128_t data_units_read = le128_to_cpu(smart_event->data_units_read);
1675 nvme_uint128_t data_units_written = le128_to_cpu(smart_event->data_units_written);
1676 nvme_uint128_t host_read_commands = le128_to_cpu(smart_event->host_reads);
1677 nvme_uint128_t host_write_commands = le128_to_cpu(smart_event->host_writes);
1678 nvme_uint128_t controller_busy_time = le128_to_cpu(smart_event->ctrl_busy_time);
1679 nvme_uint128_t power_cycles = le128_to_cpu(smart_event->power_cycles);
1680 nvme_uint128_t power_on_hours = le128_to_cpu(smart_event->power_on_hours);
1681 nvme_uint128_t unsafe_shutdowns = le128_to_cpu(smart_event->unsafe_shutdowns);
1682 nvme_uint128_t media_errors = le128_to_cpu(smart_event->media_errors);
1683 nvme_uint128_t num_err_log_entries = le128_to_cpu(smart_event->num_err_log_entries);
1684 int c;
1685 __s32 temp;
1686
1687 obj_add_int(valid_attrs, "critical_warning", smart_event->critical_warning)json_object_object_add(valid_attrs, "critical_warning", json_object_new_int
(smart_event->critical_warning))
;
1688 obj_add_int(valid_attrs, "temperature", temperature)json_object_object_add(valid_attrs, "temperature", json_object_new_int
(temperature))
;
1689 obj_add_int(valid_attrs, "avail_spare", smart_event->avail_spare)json_object_object_add(valid_attrs, "avail_spare", json_object_new_int
(smart_event->avail_spare))
;
1690 obj_add_int(valid_attrs, "spare_thresh", smart_event->spare_thresh)json_object_object_add(valid_attrs, "spare_thresh", json_object_new_int
(smart_event->spare_thresh))
;
1691 obj_add_int(valid_attrs, "percent_used", smart_event->percent_used)json_object_object_add(valid_attrs, "percent_used", json_object_new_int
(smart_event->percent_used))
;
1692 obj_add_int(valid_attrs, "endurance_grp_critical_warning_summary",json_object_object_add(valid_attrs, "endurance_grp_critical_warning_summary"
, json_object_new_int(smart_event->endu_grp_crit_warn_sumry
))
1693 smart_event->endu_grp_crit_warn_sumry)json_object_object_add(valid_attrs, "endurance_grp_critical_warning_summary"
, json_object_new_int(smart_event->endu_grp_crit_warn_sumry
))
;
1694 obj_add_uint128(valid_attrs, "data_units_read", data_units_read)json_object_object_add(valid_attrs, "data_units_read", util_json_object_new_uint128
(data_units_read))
;
1695 obj_add_uint128(valid_attrs, "data_units_written", data_units_written)json_object_object_add(valid_attrs, "data_units_written", util_json_object_new_uint128
(data_units_written))
;
1696 obj_add_uint128(valid_attrs, "host_read_commands", host_read_commands)json_object_object_add(valid_attrs, "host_read_commands", util_json_object_new_uint128
(host_read_commands))
;
1697 obj_add_uint128(valid_attrs, "host_write_commands", host_write_commands)json_object_object_add(valid_attrs, "host_write_commands", util_json_object_new_uint128
(host_write_commands))
;
1698 obj_add_uint128(valid_attrs, "controller_busy_time", controller_busy_time)json_object_object_add(valid_attrs, "controller_busy_time", util_json_object_new_uint128
(controller_busy_time))
;
1699 obj_add_uint128(valid_attrs, "power_cycles", power_cycles)json_object_object_add(valid_attrs, "power_cycles", util_json_object_new_uint128
(power_cycles))
;
1700 obj_add_uint128(valid_attrs, "power_on_hours", power_on_hours)json_object_object_add(valid_attrs, "power_on_hours", util_json_object_new_uint128
(power_on_hours))
;
1701 obj_add_uint128(valid_attrs, "unsafe_shutdowns", unsafe_shutdowns)json_object_object_add(valid_attrs, "unsafe_shutdowns", util_json_object_new_uint128
(unsafe_shutdowns))
;
1702 obj_add_uint128(valid_attrs, "media_errors", media_errors)json_object_object_add(valid_attrs, "media_errors", util_json_object_new_uint128
(media_errors))
;
1703 obj_add_uint128(valid_attrs, "num_err_log_entries", num_err_log_entries)json_object_object_add(valid_attrs, "num_err_log_entries", util_json_object_new_uint128
(num_err_log_entries))
;
1704 obj_add_uint(valid_attrs, "warning_temp_time", le32_to_cpu(smart_event->warning_temp_time))json_object_object_add(valid_attrs, "warning_temp_time", json_object_new_uint64
(le32_to_cpu(smart_event->warning_temp_time)))
;
1705 obj_add_uint(valid_attrs, "critical_comp_time",json_object_object_add(valid_attrs, "critical_comp_time", json_object_new_uint64
(le32_to_cpu(smart_event->critical_comp_time)))
1706 le32_to_cpu(smart_event->critical_comp_time))json_object_object_add(valid_attrs, "critical_comp_time", json_object_new_uint64
(le32_to_cpu(smart_event->critical_comp_time)))
;
1707
1708 for (c = 0; c < 8; c++) {
1709 temp = le16_to_cpu(smart_event->temp_sensor[c]);
1710 if (!temp)
1711 continue;
1712 sprintf(key, "temperature_sensor_%d", c + 1);
1713 obj_add_int(valid_attrs, key, temp)json_object_object_add(valid_attrs, key, json_object_new_int(
temp))
;
1714 }
1715
1716 obj_add_uint(valid_attrs, "thm_temp1_trans_count",json_object_object_add(valid_attrs, "thm_temp1_trans_count", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp1_trans_count)))
1717 le32_to_cpu(smart_event->thm_temp1_trans_count))json_object_object_add(valid_attrs, "thm_temp1_trans_count", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp1_trans_count)))
;
1718 obj_add_uint(valid_attrs, "thm_temp2_trans_count",json_object_object_add(valid_attrs, "thm_temp2_trans_count", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp2_trans_count)))
1719 le32_to_cpu(smart_event->thm_temp2_trans_count))json_object_object_add(valid_attrs, "thm_temp2_trans_count", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp2_trans_count)))
;
1720 obj_add_uint(valid_attrs, "thm_temp1_total_time",json_object_object_add(valid_attrs, "thm_temp1_total_time", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp1_total_time)))
1721 le32_to_cpu(smart_event->thm_temp1_total_time))json_object_object_add(valid_attrs, "thm_temp1_total_time", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp1_total_time)))
;
1722 obj_add_uint(valid_attrs, "thm_temp2_total_time",json_object_object_add(valid_attrs, "thm_temp2_total_time", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp2_total_time)))
1723 le32_to_cpu(smart_event->thm_temp2_total_time))json_object_object_add(valid_attrs, "thm_temp2_total_time", json_object_new_uint64
(le32_to_cpu(smart_event->thm_temp2_total_time)))
;
1724}
1725
1726void nvme_json_pel_fw_commit(void *pevent_log_info, __u32 offset,
1727 struct json_object *valid_attrs)
1728{
1729 char fw_str[50];
1730 struct nvme_fw_commit_event *fw_commit_event = pevent_log_info + offset;
1731
1732 snprintf(fw_str, sizeof(fw_str), "%"PRIu64"l" "u"" (%s)", le64_to_cpu(fw_commit_event->old_fw_rev),
1733 util_fw_to_string((char *)&fw_commit_event->old_fw_rev));
1734 obj_add_strjson_object_add_value_string(valid_attrs, "old_fw_rev", fw_str);
1735 snprintf(fw_str, sizeof(fw_str), "%"PRIu64"l" "u"" (%s)", le64_to_cpu(fw_commit_event->new_fw_rev),
1736 util_fw_to_string((char *)&fw_commit_event->new_fw_rev));
1737 obj_add_strjson_object_add_value_string(valid_attrs, "new_fw_rev", fw_str);
1738 obj_add_uint(valid_attrs, "fw_commit_action", fw_commit_event->fw_commit_action)json_object_object_add(valid_attrs, "fw_commit_action", json_object_new_uint64
(fw_commit_event->fw_commit_action))
;
1739 obj_add_uint(valid_attrs, "fw_slot", fw_commit_event->fw_slot)json_object_object_add(valid_attrs, "fw_slot", json_object_new_uint64
(fw_commit_event->fw_slot))
;
1740 obj_add_uint(valid_attrs, "sct_fw", fw_commit_event->sct_fw)json_object_object_add(valid_attrs, "sct_fw", json_object_new_uint64
(fw_commit_event->sct_fw))
;
1741 obj_add_uint(valid_attrs, "sc_fw", fw_commit_event->sc_fw)json_object_object_add(valid_attrs, "sc_fw", json_object_new_uint64
(fw_commit_event->sc_fw))
;
1742 obj_add_uint(valid_attrs, "vu_assign_fw_commit_rc",json_object_object_add(valid_attrs, "vu_assign_fw_commit_rc",
json_object_new_uint64(le16_to_cpu(fw_commit_event->vndr_assign_fw_commit_rc
)))
1743 le16_to_cpu(fw_commit_event->vndr_assign_fw_commit_rc))json_object_object_add(valid_attrs, "vu_assign_fw_commit_rc",
json_object_new_uint64(le16_to_cpu(fw_commit_event->vndr_assign_fw_commit_rc
)))
;
1744}
1745
1746void nvme_json_pel_timestamp(void *pevent_log_info, __u32 offset,
1747 struct json_object *valid_attrs)
1748{
1749 struct nvme_time_stamp_change_event *ts_change_event = pevent_log_info + offset;
1750
1751 obj_add_uint64(valid_attrs, "prev_ts", le64_to_cpu(ts_change_event->previous_timestamp))json_object_object_add(valid_attrs, "prev_ts", json_object_new_uint64
(le64_to_cpu(ts_change_event->previous_timestamp)))
;
1752 obj_add_uint64(valid_attrs, "ml_secs_since_reset",json_object_object_add(valid_attrs, "ml_secs_since_reset", json_object_new_uint64
(le64_to_cpu(ts_change_event->ml_secs_since_reset)))
1753 le64_to_cpu(ts_change_event->ml_secs_since_reset))json_object_object_add(valid_attrs, "ml_secs_since_reset", json_object_new_uint64
(le64_to_cpu(ts_change_event->ml_secs_since_reset)))
;
1754}
1755
1756void nvme_json_pel_power_on_reset(void *pevent_log_info, __u32 offset,
1757 struct json_object *valid_attrs,
1758 __le16 vsil, __le16 el)
1759{
1760 __u64 *fw_rev;
1761 char fw_str[50];
1762 struct nvme_power_on_reset_info_list *por_event;
1763 __u32 por_info_len = le16_to_cpu(el) - le16_to_cpu(vsil) - sizeof(*fw_rev);
1764 __u32 por_info_list = por_info_len / sizeof(*por_event);
1765 int i;
1766
1767 fw_rev = pevent_log_info + offset;
1768 snprintf(fw_str, sizeof(fw_str), "%"PRIu64"l" "u"" (%s)", le64_to_cpu(*fw_rev),
1769 util_fw_to_string((char *)fw_rev));
1770 obj_add_strjson_object_add_value_string(valid_attrs, "fw_rev", fw_str);
1771
1772 for (i = 0; i < por_info_list; i++) {
1773 por_event = pevent_log_info + offset + sizeof(*fw_rev) + i * sizeof(*por_event);
1774 obj_add_uint(valid_attrs, "ctrl_id", le16_to_cpu(por_event->cid))json_object_object_add(valid_attrs, "ctrl_id", json_object_new_uint64
(le16_to_cpu(por_event->cid)))
;
1775 obj_add_uint(valid_attrs, "fw_act", por_event->fw_act)json_object_object_add(valid_attrs, "fw_act", json_object_new_uint64
(por_event->fw_act))
;
1776 obj_add_uint(valid_attrs, "op_in_prog", por_event->op_in_prog)json_object_object_add(valid_attrs, "op_in_prog", json_object_new_uint64
(por_event->op_in_prog))
;
1777 obj_add_uint(valid_attrs, "ctrl_power_cycle",json_object_object_add(valid_attrs, "ctrl_power_cycle", json_object_new_uint64
(le32_to_cpu(por_event->ctrl_power_cycle)))
1778 le32_to_cpu(por_event->ctrl_power_cycle))json_object_object_add(valid_attrs, "ctrl_power_cycle", json_object_new_uint64
(le32_to_cpu(por_event->ctrl_power_cycle)))
;
1779 obj_add_uint64(valid_attrs, "power_on_ml_secs",json_object_object_add(valid_attrs, "power_on_ml_secs", json_object_new_uint64
(le64_to_cpu(por_event->power_on_ml_seconds)))
1780 le64_to_cpu(por_event->power_on_ml_seconds))json_object_object_add(valid_attrs, "power_on_ml_secs", json_object_new_uint64
(le64_to_cpu(por_event->power_on_ml_seconds)))
;
1781 obj_add_uint64(valid_attrs, "ctrl_time_stamp",json_object_object_add(valid_attrs, "ctrl_time_stamp", json_object_new_uint64
(le64_to_cpu(por_event->ctrl_time_stamp)))
1782 le64_to_cpu(por_event->ctrl_time_stamp))json_object_object_add(valid_attrs, "ctrl_time_stamp", json_object_new_uint64
(le64_to_cpu(por_event->ctrl_time_stamp)))
;
1783 }
1784}
1785
1786void nvme_json_pel_nss_hw_error(void *pevent_log_info, __u32 offset,
1787 struct json_object *valid_attrs)
1788{
1789 struct nvme_nss_hw_err_event *nss_hw_err_event = pevent_log_info + offset;
1790
1791 obj_add_uint(valid_attrs, "nss_hw_err_code",json_object_object_add(valid_attrs, "nss_hw_err_code", json_object_new_uint64
(le16_to_cpu(nss_hw_err_event->nss_hw_err_event_code)))
1792 le16_to_cpu(nss_hw_err_event->nss_hw_err_event_code))json_object_object_add(valid_attrs, "nss_hw_err_code", json_object_new_uint64
(le16_to_cpu(nss_hw_err_event->nss_hw_err_event_code)))
;
1793}
1794
1795void nvme_json_pel_change_ns(void *pevent_log_info, __u32 offset,
1796 struct json_object *valid_attrs)
1797{
1798 struct nvme_change_ns_event *ns_event = pevent_log_info + offset;
1799
1800 obj_add_uint(valid_attrs, "nsmgt_cdw10", le32_to_cpu(ns_event->nsmgt_cdw10))json_object_object_add(valid_attrs, "nsmgt_cdw10", json_object_new_uint64
(le32_to_cpu(ns_event->nsmgt_cdw10)))
;
1801 obj_add_uint64(valid_attrs, "nsze", le64_to_cpu(ns_event->nsze))json_object_object_add(valid_attrs, "nsze", json_object_new_uint64
(le64_to_cpu(ns_event->nsze)))
;
1802 obj_add_uint64(valid_attrs, "nscap", le64_to_cpu(ns_event->nscap))json_object_object_add(valid_attrs, "nscap", json_object_new_uint64
(le64_to_cpu(ns_event->nscap)))
;
1803 obj_add_uint(valid_attrs, "flbas", ns_event->flbas)json_object_object_add(valid_attrs, "flbas", json_object_new_uint64
(ns_event->flbas))
;
1804 obj_add_uint(valid_attrs, "dps", ns_event->dps)json_object_object_add(valid_attrs, "dps", json_object_new_uint64
(ns_event->dps))
;
1805 obj_add_uint(valid_attrs, "nmic", ns_event->nmic)json_object_object_add(valid_attrs, "nmic", json_object_new_uint64
(ns_event->nmic))
;
1806 obj_add_uint(valid_attrs, "ana_grp_id", le32_to_cpu(ns_event->ana_grp_id))json_object_object_add(valid_attrs, "ana_grp_id", json_object_new_uint64
(le32_to_cpu(ns_event->ana_grp_id)))
;
1807 obj_add_uint(valid_attrs, "nvmset_id", le16_to_cpu(ns_event->nvmset_id))json_object_object_add(valid_attrs, "nvmset_id", json_object_new_uint64
(le16_to_cpu(ns_event->nvmset_id)))
;
1808 obj_add_uint(valid_attrs, "nsid", le32_to_cpu(ns_event->nsid))json_object_object_add(valid_attrs, "nsid", json_object_new_uint64
(le32_to_cpu(ns_event->nsid)))
;
1809}
1810
1811void nvme_json_pel_format_start(void *pevent_log_info, __u32 offset,
1812 struct json_object *valid_attrs)
1813{
1814 struct nvme_format_nvm_start_event *format_start_event = pevent_log_info + offset;
1815
1816 obj_add_uint(valid_attrs, "nsid", le32_to_cpu(format_start_event->nsid))json_object_object_add(valid_attrs, "nsid", json_object_new_uint64
(le32_to_cpu(format_start_event->nsid)))
;
1817 obj_add_uint(valid_attrs, "fna", format_start_event->fna)json_object_object_add(valid_attrs, "fna", json_object_new_uint64
(format_start_event->fna))
;
1818 obj_add_uint(valid_attrs, "format_nvm_cdw10",json_object_object_add(valid_attrs, "format_nvm_cdw10", json_object_new_uint64
(le32_to_cpu(format_start_event->format_nvm_cdw10)))
1819 le32_to_cpu(format_start_event->format_nvm_cdw10))json_object_object_add(valid_attrs, "format_nvm_cdw10", json_object_new_uint64
(le32_to_cpu(format_start_event->format_nvm_cdw10)))
;
1820}
1821
1822void nvme_json_pel_format_completion(void *pevent_log_info, __u32 offset,
1823 struct json_object *valid_attrs)
1824{
1825 struct nvme_format_nvm_compln_event *format_cmpln_event = pevent_log_info + offset;
1826
1827 obj_add_uint(valid_attrs, "nsid", le32_to_cpu(format_cmpln_event->nsid))json_object_object_add(valid_attrs, "nsid", json_object_new_uint64
(le32_to_cpu(format_cmpln_event->nsid)))
;
1828 obj_add_uint(valid_attrs, "smallest_fpi", format_cmpln_event->smallest_fpi)json_object_object_add(valid_attrs, "smallest_fpi", json_object_new_uint64
(format_cmpln_event->smallest_fpi))
;
1829 obj_add_uint(valid_attrs, "format_nvm_status", format_cmpln_event->format_nvm_status)json_object_object_add(valid_attrs, "format_nvm_status", json_object_new_uint64
(format_cmpln_event->format_nvm_status))
;
1830 obj_add_uint(valid_attrs, "compln_info", le16_to_cpu(format_cmpln_event->compln_info))json_object_object_add(valid_attrs, "compln_info", json_object_new_uint64
(le16_to_cpu(format_cmpln_event->compln_info)))
;
1831 obj_add_uint(valid_attrs, "status_field", le32_to_cpu(format_cmpln_event->status_field))json_object_object_add(valid_attrs, "status_field", json_object_new_uint64
(le32_to_cpu(format_cmpln_event->status_field)))
;
1832}
1833void nvme_json_pel_sanitize_start(void *pevent_log_info, __u32 offset,
1834 struct json_object *valid_attrs)
1835{
1836 struct nvme_sanitize_start_event *sanitize_start_event = pevent_log_info + offset;
1837
1838 obj_add_uint(valid_attrs, "SANICAP", le32_to_cpu(sanitize_start_event->sani_cap))json_object_object_add(valid_attrs, "SANICAP", json_object_new_uint64
(le32_to_cpu(sanitize_start_event->sani_cap)))
;
1839 obj_add_uint(valid_attrs, "sani_cdw10", le32_to_cpu(sanitize_start_event->sani_cdw10))json_object_object_add(valid_attrs, "sani_cdw10", json_object_new_uint64
(le32_to_cpu(sanitize_start_event->sani_cdw10)))
;
1840 obj_add_uint(valid_attrs, "sani_cdw11", le32_to_cpu(sanitize_start_event->sani_cdw11))json_object_object_add(valid_attrs, "sani_cdw11", json_object_new_uint64
(le32_to_cpu(sanitize_start_event->sani_cdw11)))
;
1841}
1842
1843void nvme_json_pel_sanitize_completion(void *pevent_log_info, __u32 offset,
1844 struct json_object *valid_attrs)
1845{
1846 struct nvme_sanitize_compln_event *sanitize_cmpln_event = pevent_log_info + offset;
1847
1848 obj_add_uint(valid_attrs, "sani_prog", le16_to_cpu(sanitize_cmpln_event->sani_prog))json_object_object_add(valid_attrs, "sani_prog", json_object_new_uint64
(le16_to_cpu(sanitize_cmpln_event->sani_prog)))
;
1849 obj_add_uint(valid_attrs, "sani_status", le16_to_cpu(sanitize_cmpln_event->sani_status))json_object_object_add(valid_attrs, "sani_status", json_object_new_uint64
(le16_to_cpu(sanitize_cmpln_event->sani_status)))
;
1850 obj_add_uint(valid_attrs, "cmpln_info", le16_to_cpu(sanitize_cmpln_event->cmpln_info))json_object_object_add(valid_attrs, "cmpln_info", json_object_new_uint64
(le16_to_cpu(sanitize_cmpln_event->cmpln_info)))
;
1851}
1852
1853void nvme_json_pel_set_feature(void *pevent_log_info, __u32 offset,
1854 struct json_object *valid_attrs)
1855{
1856 struct nvme_set_feature_event *set_feat_event = pevent_log_info + offset;
1857 int fid = NVME_GET(le32_to_cpu(set_feat_event->cdw_mem[0]), SET_FEATURES_CDW10_FID)(((le32_to_cpu(set_feat_event->cdw_mem[0])) >> NVME_SET_FEATURES_CDW10_FID_SHIFT
) & NVME_SET_FEATURES_CDW10_FID_MASK)
;
1858 int cdw11 = le32_to_cpu(set_feat_event->cdw_mem[1]);
1859 int dword_cnt = NVME_SET_FEAT_EVENT_DW_COUNT(set_feat_event->layout)(((set_feat_event->layout) >> NVME_SET_FEAT_EVENT_DW_COUNT_SHIFT
) & NVME_SET_FEAT_EVENT_DW_COUNT_MASK)
;
1860 unsigned char *mem_buf;
1861
1862 obj_add_uint_02xjson_object_add_uint_02x(valid_attrs, "feature", fid);
1863 obj_add_strjson_object_add_value_string(valid_attrs, "name", nvme_feature_to_string(fid));
1864 obj_add_uint_0nxjson_object_add_uint_0nx(valid_attrs, "value", cdw11, 8);
1865
1866 if (NVME_SET_FEAT_EVENT_MB_COUNT(set_feat_event->layout)(((set_feat_event->layout) >> NVME_SET_FEAT_EVENT_MB_COUNT_SHIFT
) & NVME_SET_FEAT_EVENT_MB_COUNT_MASK)
) {
1867 mem_buf = (unsigned char *)(set_feat_event + 4 + dword_cnt * 4);
1868 json_feature_show_fields(fid, cdw11, mem_buf);
1869 }
1870}
1871
1872void nvme_json_pel_telemetry_crt(void *pevent_log_info, __u32 offset,
1873 struct json_object *valid_attrs)
1874{
1875 obj_d(valid_attrs, "create", pevent_log_info + offset, 512, 16, 1);
1876}
1877
1878void nvme_json_pel_thermal_excursion(void *pevent_log_info, __u32 offset,
1879 struct json_object *valid_attrs)
1880{
1881 struct nvme_thermal_exc_event *thermal_exc_event = pevent_log_info + offset;
1882
1883 obj_add_uint(valid_attrs, "over_temp", thermal_exc_event->over_temp)json_object_object_add(valid_attrs, "over_temp", json_object_new_uint64
(thermal_exc_event->over_temp))
;
1884 obj_add_uint(valid_attrs, "threshold", thermal_exc_event->threshold)json_object_object_add(valid_attrs, "threshold", json_object_new_uint64
(thermal_exc_event->threshold))
;
1885}
1886
1887static void json_pel_vs_event_data(struct json_object *valid_attrs, void *vsed,
1888 __u8 vsedt, __u16 vsedl)
1889{
1890 struct json_object *vs_data = json_create_object()json_object_new_object();
1891 char *str;
1892
1893 switch (vsedt) {
1894 case NVME_PEL_VSEDT_EVENT_NAME:
1895 str = malloc(vsedl + 1);
1896 if (str) {
1897 memcpy(str, vsed, vsedl);
1898 str[vsedl] = '\0';
1899 obj_add_strjson_object_add_value_string(vs_data, "event_name", str);
1900 free(str);
1901 }
1902 break;
1903 case NVME_PEL_VSEDT_ASCII_STRING:
1904 str = malloc(vsedl + 1);
1905 if (str) {
1906 memcpy(str, vsed, vsedl);
1907 str[vsedl] = '\0';
1908 obj_add_strjson_object_add_value_string(vs_data, "ascii_string_data", str);
1909 free(str);
1910 }
1911 break;
1912 case NVME_PEL_VSEDT_BINARY:
1913 obj_d(vs_data, "binary_data", (unsigned char *)vsed, vsedl, 16, 1);
1914 break;
1915 case NVME_PEL_VSEDT_SIGNED_INT:
1916 obj_add_int(vs_data, "signed_integer_data", *(int64_t *)vsed)json_object_object_add(vs_data, "signed_integer_data", json_object_new_int
(*(int64_t *)vsed))
;
1917 break;
1918 default:
1919 obj_d(vs_data, "reserved_data_type_bin", (unsigned char *)vsed, vsedl, 16, 1);
1920 break;
1921 }
1922
1923 obj_add_obj(valid_attrs, "vs_event_data", vs_data)json_object_object_add(valid_attrs, "vs_event_data", vs_data);
1924}
1925
1926void nvme_json_pel_vendor_specific_event(void *pevent_log_info, __u32 offset,
1927 __u32 event_data_len,
1928 struct json_object *valid_attrs)
1929{
1930 __u32 progress = 0;
1931 __u16 vsedl;
1932 __u32 i;
1933 struct nvme_vs_event_desc *vs_desc;
1934 struct json_object *vs_events = json_create_array()json_object_new_array();
1935
1936 for (i = 0; progress < event_data_len; i++) {
1937 struct json_object *vs_event = json_create_object()json_object_new_object();
1938
1939 vs_desc = pevent_log_info + offset + progress;
1940 vsedl = le16_to_cpu(vs_desc->vsedl);
1941
1942 obj_add_uint(vs_event, "vs_event_descriptor_number", i)json_object_object_add(vs_event, "vs_event_descriptor_number"
, json_object_new_uint64(i))
;
1943 obj_add_uint(vs_event, "vs_event_code", le16_to_cpu(vs_desc->vsec))json_object_object_add(vs_event, "vs_event_code", json_object_new_uint64
(le16_to_cpu(vs_desc->vsec)))
;
1944 obj_add_uint(vs_event, "vs_event_data_type", vs_desc->vsedt)json_object_object_add(vs_event, "vs_event_data_type", json_object_new_uint64
(vs_desc->vsedt))
;
1945 obj_add_uint(vs_event, "vs_event_uuid_index", vs_desc->uidx)json_object_object_add(vs_event, "vs_event_uuid_index", json_object_new_uint64
(vs_desc->uidx))
;
1946 obj_add_uint(vs_event, "vs_event_data_len", vsedl)json_object_object_add(vs_event, "vs_event_data_len", json_object_new_uint64
(vsedl))
;
1947
1948 if (vsedl)
1949 json_pel_vs_event_data(vs_event, vs_desc + 1, vs_desc->vsedt, vsedl);
1950
1951 array_add_obj(vs_events, vs_event)json_object_array_add(vs_events, vs_event);
1952 progress += sizeof(*vs_desc) + vsedl;
1953 }
1954
1955 obj_add_array(valid_attrs, "vs_event_entry", vs_events)json_object_object_add(valid_attrs, "vs_event_entry", vs_events
)
;
1956}
1957
1958static void json_pevent_entry(void *pevent_log_info, __u8 action, __u32 size, const char *devname,
1959 __u32 offset, struct json_object *valid)
1960{
1961 int i;
1962 __u16 vsil, el;
1963 struct nvme_persistent_event_log *pevent_log_head = pevent_log_info;
1964 struct nvme_persistent_event_entry *pevent_entry_head;
1965 struct json_object *valid_attrs;
1966
1967 for (i = 0; i < le32_to_cpu(pevent_log_head->tnev); i++) {
1968 if (offset + sizeof(*pevent_entry_head) >= size)
1969 break;
1970
1971 pevent_entry_head = pevent_log_info + offset;
1972 vsil = le16_to_cpu(pevent_entry_head->vsil);
1973 el = le16_to_cpu(pevent_entry_head->el);
1974
1975 if (offset + pevent_entry_head->ehl + 3 + el >=
1976 size)
1977 break;
1978
1979 valid_attrs = json_create_object()json_object_new_object();
1980
1981 obj_add_uint(valid_attrs, "event_number", i)json_object_object_add(valid_attrs, "event_number", json_object_new_uint64
(i))
;
1982 obj_add_strjson_object_add_value_string(valid_attrs, "event_type",
1983 nvme_pel_event_to_string(pevent_entry_head->etype));
1984 obj_add_uint(valid_attrs, "event_type_rev", pevent_entry_head->etype_rev)json_object_object_add(valid_attrs, "event_type_rev", json_object_new_uint64
(pevent_entry_head->etype_rev))
;
1985 obj_add_uint(valid_attrs, "event_header_len", pevent_entry_head->ehl)json_object_object_add(valid_attrs, "event_header_len", json_object_new_uint64
(pevent_entry_head->ehl))
;
1986 obj_add_uint(valid_attrs, "event_header_additional_info", pevent_entry_head->ehai)json_object_object_add(valid_attrs, "event_header_additional_info"
, json_object_new_uint64(pevent_entry_head->ehai))
;
1987 obj_add_uint(valid_attrs, "ctrl_id", le16_to_cpu(pevent_entry_head->cntlid))json_object_object_add(valid_attrs, "ctrl_id", json_object_new_uint64
(le16_to_cpu(pevent_entry_head->cntlid)))
;
1988 obj_add_uint64(valid_attrs, "event_time_stamp",json_object_object_add(valid_attrs, "event_time_stamp", json_object_new_uint64
(le64_to_cpu(pevent_entry_head->ets)))
1989 le64_to_cpu(pevent_entry_head->ets))json_object_object_add(valid_attrs, "event_time_stamp", json_object_new_uint64
(le64_to_cpu(pevent_entry_head->ets)))
;
1990 obj_add_uint(valid_attrs, "port_id", le16_to_cpu(pevent_entry_head->pelpid))json_object_object_add(valid_attrs, "port_id", json_object_new_uint64
(le16_to_cpu(pevent_entry_head->pelpid)))
;
1991 obj_add_uint(valid_attrs, "vu_info_len", vsil)json_object_object_add(valid_attrs, "vu_info_len", json_object_new_uint64
(vsil))
;
1992 obj_add_uint(valid_attrs, "event_len", el)json_object_object_add(valid_attrs, "event_len", json_object_new_uint64
(el))
;
1993
1994 if (vsil)
1995 obj_d(valid_attrs, "vs_info_bin",
1996 (void *)pevent_entry_head + 1, vsil, 16, 1);
1997
1998 offset += pevent_entry_head->ehl + vsil + 3;
1999
2000 switch (pevent_entry_head->etype) {
2001 case NVME_PEL_SMART_HEALTH_EVENT:
2002 nvme_json_pel_smart_health(pevent_log_info, offset, valid_attrs);
2003 break;
2004 case NVME_PEL_FW_COMMIT_EVENT:
2005 nvme_json_pel_fw_commit(pevent_log_info, offset, valid_attrs);
2006 break;
2007 case NVME_PEL_TIMESTAMP_EVENT:
2008 nvme_json_pel_timestamp(pevent_log_info, offset, valid_attrs);
2009 break;
2010 case NVME_PEL_POWER_ON_RESET_EVENT:
2011 nvme_json_pel_power_on_reset(pevent_log_info, offset, valid_attrs,
2012 pevent_entry_head->vsil,
2013 pevent_entry_head->el);
2014 break;
2015 case NVME_PEL_NSS_HW_ERROR_EVENT:
2016 nvme_json_pel_nss_hw_error(pevent_log_info, offset, valid_attrs);
2017 break;
2018 case NVME_PEL_CHANGE_NS_EVENT:
2019 nvme_json_pel_change_ns(pevent_log_info, offset, valid_attrs);
2020 break;
2021 case NVME_PEL_FORMAT_START_EVENT:
2022 nvme_json_pel_format_start(pevent_log_info, offset, valid_attrs);
2023 break;
2024 case NVME_PEL_FORMAT_COMPLETION_EVENT:
2025 nvme_json_pel_format_completion(pevent_log_info, offset, valid_attrs);
2026 break;
2027 case NVME_PEL_SANITIZE_START_EVENT:
2028 nvme_json_pel_sanitize_start(pevent_log_info, offset, valid_attrs);
2029 break;
2030 case NVME_PEL_SANITIZE_COMPLETION_EVENT:
2031 nvme_json_pel_sanitize_completion(pevent_log_info, offset, valid_attrs);
2032 break;
2033 case NVME_PEL_SET_FEATURE_EVENT:
2034 nvme_json_pel_set_feature(pevent_log_info, offset, valid_attrs);
2035 break;
2036 case NVME_PEL_TELEMETRY_CRT:
2037 nvme_json_pel_telemetry_crt(pevent_log_info, offset, valid_attrs);
2038 break;
2039 case NVME_PEL_THERMAL_EXCURSION_EVENT:
2040 nvme_json_pel_thermal_excursion(pevent_log_info, offset, valid_attrs);
2041 break;
2042 case NVME_PEL_VENDOR_SPECIFIC_EVENT:
2043 nvme_json_pel_vendor_specific_event(pevent_log_info, offset, el - vsil,
2044 valid_attrs);
2045 break;
2046 default:
2047 break;
2048 }
2049
2050 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
2051 offset += le16_to_cpu(pevent_entry_head->el);
2052 }
2053}
2054
2055static void json_persistent_event_log(void *pevent_log_info, __u8 action,
2056 __u32 size, const char *devname)
2057{
2058 struct json_object *r = json_create_object()json_object_new_object();
2059 struct json_object *valid = json_create_array()json_object_new_array();
2060 __u32 offset = sizeof(struct nvme_persistent_event_log);
2061
2062 if (size >= offset) {
2063 nvme_json_pevent_log_head(pevent_log_info, r);
2064 json_pevent_entry(pevent_log_info, action, size, devname, offset, valid);
2065 obj_add_array(r, "list_of_event_entries", valid)json_object_object_add(r, "list_of_event_entries", valid);
2066 } else {
2067 obj_add_result(r, "No log data can be shown with this log len at least " \
2068 "512 bytes is required or can be 0 to read the complete "\
2069 "log page after context established");
2070 }
2071
2072 json_print(r);
2073}
2074
2075static void json_endurance_group_event_agg_log(
2076 struct nvme_aggregate_endurance_group_event *endurance_log,
2077 __u64 log_entries, __u32 size, const char *devname)
2078{
2079 struct json_object *r = json_create_object()json_object_new_object();
2080 struct json_object *valid_attrs;
2081 struct json_object *valid = json_create_array()json_object_new_array();
2082
2083 obj_add_uint64(r, "num_entries_avail", le64_to_cpu(endurance_log->num_entries))json_object_object_add(r, "num_entries_avail", json_object_new_uint64
(le64_to_cpu(endurance_log->num_entries)))
;
2084
2085 for (int i = 0; i < log_entries; i++) {
2086 valid_attrs = json_create_object()json_object_new_object();
2087 obj_add_uint(valid_attrs, "entry", le16_to_cpu(endurance_log->entries[i]))json_object_object_add(valid_attrs, "entry", json_object_new_uint64
(le16_to_cpu(endurance_log->entries[i])))
;
2088 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
2089 }
2090
2091 obj_add_array(r, "list_of_entries", valid)json_object_object_add(r, "list_of_entries", valid);
2092
2093 json_print(r);
2094}
2095
2096static void json_lba_status(struct nvme_lba_status *list,
2097 unsigned long len)
2098{
2099 struct json_object *r = json_create_object()json_object_new_object();
2100 int idx;
2101 struct nvme_lba_status_desc *e;
2102 struct json_object *lsde;
2103 char json_str[STR_LEN100];
2104
2105 obj_add_uint(r, "Number of LBA Status Descriptors (NLSD)", le32_to_cpu(list->nlsd))json_object_object_add(r, "Number of LBA Status Descriptors (NLSD)"
, json_object_new_uint64(le32_to_cpu(list->nlsd)))
;
2106 obj_add_uint(r, "Completion Condition (CMPC)", list->cmpc)json_object_object_add(r, "Completion Condition (CMPC)", json_object_new_uint64
(list->cmpc))
;
2107
2108 switch (list->cmpc) {
2109 case NVME_LBA_STATUS_CMPC_NO_CMPC:
2110 obj_add_strjson_object_add_value_string(r, "cmpc-definition", "No indication of the completion condition");
2111 break;
2112 case NVME_LBA_STATUS_CMPC_INCOMPLETE:
2113 obj_add_strjson_object_add_value_string(r, "cmpc-definition",
2114 "Completed transferring the amount of data specified in the"\
2115 "MNDW field. But, additional LBA Status Descriptor Entries are"\
2116 "available to transfer or scan did not complete (if ATYPE = 10h)");
2117 break;
2118 case NVME_LBA_STATUS_CMPC_COMPLETE:
2119 obj_add_strjson_object_add_value_string(r, "cmpc-definition",
2120 "Completed the specified action over the number of LBAs specified"\
2121 "in the Range Length field and transferred all available LBA Status"\
2122 "Descriptor Entries");
2123 break;
2124 default:
2125 break;
2126 }
2127
2128 for (idx = 0; idx < list->nlsd; idx++) {
2129 lsde = json_create_array()json_object_new_array();
2130 sprintf(json_str, "LSD entry %d", idx);
2131 obj_add_array(r, json_str, lsde)json_object_object_add(r, json_str, lsde);
2132 e = &list->descs[idx];
2133 sprintf(json_str, "0x%016"PRIx64"l" "x""", le64_to_cpu(e->dslba));
2134 obj_add_strjson_object_add_value_string(lsde, "DSLBA", json_str);
2135 sprintf(json_str, "0x%08x", le32_to_cpu(e->nlb));
2136 obj_add_strjson_object_add_value_string(lsde, "NLB", json_str);
2137 sprintf(json_str, "0x%02x", e->status);
2138 obj_add_strjson_object_add_value_string(lsde, "status", json_str);
2139 }
2140
2141 json_print(r);
2142}
2143
2144static void json_lba_status_log(void *lba_status, __u32 size, const char *devname)
2145{
2146 struct json_object *r = json_create_object()json_object_new_object();
2147 struct json_object *desc;
2148 struct json_object *element;
2149 struct json_object *desc_list;
2150 struct json_object *elements_list = json_create_array()json_object_new_array();
2151 struct nvme_lba_status_log *hdr = lba_status;
2152 struct nvme_lbas_ns_element *ns_element;
2153 struct nvme_lba_rd *range_desc;
2154 int offset = sizeof(*hdr);
2155 __u32 num_lba_desc;
2156 __u32 num_elements = le32_to_cpu(hdr->nlslne);
2157 int ele;
2158 int i;
2159
2160 obj_add_uint(r, "lslplen", le32_to_cpu(hdr->lslplen))json_object_object_add(r, "lslplen", json_object_new_uint64(le32_to_cpu
(hdr->lslplen)))
;
2161 obj_add_uint(r, "nlslne", num_elements)json_object_object_add(r, "nlslne", json_object_new_uint64(num_elements
))
;
2162 obj_add_uint(r, "estulb", le32_to_cpu(hdr->estulb))json_object_object_add(r, "estulb", json_object_new_uint64(le32_to_cpu
(hdr->estulb)))
;
2163 obj_add_uint(r, "lsgc", le16_to_cpu(hdr->lsgc))json_object_object_add(r, "lsgc", json_object_new_uint64(le16_to_cpu
(hdr->lsgc)))
;
2164
2165 for (ele = 0; ele < num_elements; ele++) {
2166 ns_element = lba_status + offset;
2167 element = json_create_object()json_object_new_object();
2168 obj_add_uint(element, "neid", le32_to_cpu(ns_element->neid))json_object_object_add(element, "neid", json_object_new_uint64
(le32_to_cpu(ns_element->neid)))
;
2169 num_lba_desc = le32_to_cpu(ns_element->nlrd);
2170 obj_add_uint(element, "nlrd", num_lba_desc)json_object_object_add(element, "nlrd", json_object_new_uint64
(num_lba_desc))
;
2171 obj_add_uint(element, "ratype", ns_element->ratype)json_object_object_add(element, "ratype", json_object_new_uint64
(ns_element->ratype))
;
2172
2173 offset += sizeof(*ns_element);
2174 desc_list = json_create_array()json_object_new_array();
2175
2176 if (num_lba_desc != 0xffffffff) {
2177 for (i = 0; i < num_lba_desc; i++) {
2178 range_desc = lba_status + offset;
2179 desc = json_create_object()json_object_new_object();
2180 obj_add_uint64(desc, "rslba", le64_to_cpu(range_desc->rslba))json_object_object_add(desc, "rslba", json_object_new_uint64(
le64_to_cpu(range_desc->rslba)))
;
2181 obj_add_uint(desc, "rnlb", le32_to_cpu(range_desc->rnlb))json_object_object_add(desc, "rnlb", json_object_new_uint64(le32_to_cpu
(range_desc->rnlb)))
;
2182
2183 offset += sizeof(*range_desc);
2184 array_add_obj(desc_list, desc)json_object_array_add(desc_list, desc);
2185 }
2186 } else {
2187 obj_add_result(r, "Number of LBA Range Descriptors (NLRD) set to %#x for NS element %d",
2188 num_lba_desc, ele);
2189 }
2190
2191 obj_add_array(element, "descs", desc_list)json_object_object_add(element, "descs", desc_list);
2192 array_add_obj(elements_list, element)json_object_array_add(elements_list, element);
2193 }
2194
2195 obj_add_array(r, "ns_elements", elements_list)json_object_object_add(r, "ns_elements", elements_list);
2196
2197 json_print(r);
2198}
2199
2200static void json_resv_notif_log(struct nvme_resv_notification_log *resv,
2201 const char *devname)
2202{
2203 struct json_object *r = json_create_object()json_object_new_object();
2204
2205 obj_add_uint64(r, "count", le64_to_cpu(resv->lpc))json_object_object_add(r, "count", json_object_new_uint64(le64_to_cpu
(resv->lpc)))
;
2206 obj_add_uint(r, "rn_log_type", resv->rnlpt)json_object_object_add(r, "rn_log_type", json_object_new_uint64
(resv->rnlpt))
;
2207 obj_add_uint(r, "num_logs", resv->nalp)json_object_object_add(r, "num_logs", json_object_new_uint64(
resv->nalp))
;
2208 obj_add_uint(r, "NSID", le32_to_cpu(resv->nsid))json_object_object_add(r, "NSID", json_object_new_uint64(le32_to_cpu
(resv->nsid)))
;
2209
2210 json_print(r);
2211}
2212
2213static void json_fid_support_effects_log(
2214 struct nvme_fid_supported_effects_log *fid_log,
2215 const char *devname)
2216{
2217 struct json_object *r = json_create_object()json_object_new_object();
2218 struct json_object *fids;
2219 struct json_object *fids_list = json_create_array()json_object_new_array();
2220 unsigned int fid;
2221 char key[128];
2222 __u32 fid_support;
2223
2224 for (fid = 0; fid < NVME_LOG_FID_SUPPORTED_EFFECTS_MAX; fid++) {
2225 fid_support = le32_to_cpu(fid_log->fid_support[fid]);
2226 if (fid_support & NVME_FID_SUPPORTED_EFFECTS_FSUPP) {
2227 fids = json_create_object()json_object_new_object();
2228 sprintf(key, "fid_%u", fid);
2229 obj_add_uint(fids, key, fid_support)json_object_object_add(fids, key, json_object_new_uint64(fid_support
))
;
2230 array_add_obj(fids_list, fids)json_object_array_add(fids_list, fids);
2231 }
2232 }
2233
2234 obj_add_obj(r, "fid_support", fids_list)json_object_object_add(r, "fid_support", fids_list);
2235
2236 json_print(r);
2237}
2238
2239static void json_mi_cmd_support_effects_log(
2240 struct nvme_mi_cmd_supported_effects_log *mi_cmd_log,
2241 const char *devname)
2242{
2243 struct json_object *r = json_create_object()json_object_new_object();
2244 struct json_object *mi_cmds;
2245 struct json_object *mi_cmds_list = json_create_array()json_object_new_array();
2246 unsigned int mi_cmd;
2247 char key[128];
2248 __u32 mi_cmd_support;
2249
2250 for (mi_cmd = 0; mi_cmd < NVME_LOG_MI_CMD_SUPPORTED_EFFECTS_MAX; mi_cmd++) {
2251 mi_cmd_support = le32_to_cpu(mi_cmd_log->mi_cmd_support[mi_cmd]);
2252 if (mi_cmd_support & NVME_MI_CMD_SUPPORTED_EFFECTS_CSUPP) {
2253 mi_cmds = json_create_object()json_object_new_object();
2254 sprintf(key, "mi_cmd_%u", mi_cmd);
2255 obj_add_uint(mi_cmds, key, mi_cmd_support)json_object_object_add(mi_cmds, key, json_object_new_uint64(mi_cmd_support
))
;
2256 array_add_obj(mi_cmds_list, mi_cmds)json_object_array_add(mi_cmds_list, mi_cmds);
2257 }
2258 }
2259
2260 obj_add_obj(r, "mi_command_support", mi_cmds_list)json_object_object_add(r, "mi_command_support", mi_cmds_list);
2261
2262 json_print(r);
2263}
2264
2265static void json_boot_part_log(void *bp_log, const char *devname,
2266 __u32 size)
2267{
2268 struct nvme_boot_partition *hdr = bp_log;
2269 struct json_object *r = json_create_object()json_object_new_object();
2270
2271 obj_add_uint(r, "count", hdr->lid)json_object_object_add(r, "count", json_object_new_uint64(hdr
->lid))
;
2272 obj_add_uint(r, "abpid", NVME_BOOT_PARTITION_INFO_ABPID(le32_to_cpu(hdr->bpinfo)))json_object_object_add(r, "abpid", json_object_new_uint64((((
le32_to_cpu(hdr->bpinfo)) >> NVME_BOOT_PARTITION_INFO_ABPID_SHIFT
) & NVME_BOOT_PARTITION_INFO_ABPID_MASK)))
;
2273 obj_add_uint(r, "bpsz", NVME_BOOT_PARTITION_INFO_BPSZ(le32_to_cpu(hdr->bpinfo)))json_object_object_add(r, "bpsz", json_object_new_uint64((((le32_to_cpu
(hdr->bpinfo)) >> NVME_BOOT_PARTITION_INFO_BPSZ_SHIFT
) & NVME_BOOT_PARTITION_INFO_BPSZ_MASK)))
;
2274
2275 json_print(r);
2276}
2277
2278/* Printable Eye string is allocated and returned, caller must free */
2279static char *json_eom_printable_eye(struct nvme_eom_lane_desc *lane,
2280 struct json_object *r)
2281{
2282 char *eye = (char *)lane->eye_desc;
2283 uint16_t nrows = le16_to_cpu(lane->nrows);
2284 uint16_t ncols = le16_to_cpu(lane->ncols);
2285 struct json_object *eye_array = NULL((void*)0);
2286 char *printable_start = NULL((void*)0);
2287 char *printable = NULL((void*)0);
2288
2289 if (nrows == 0 || ncols == 0)
12
Assuming 'nrows' is not equal to 0
13
Assuming 'ncols' is not equal to 0
14
Taking false branch
2290 return NULL((void*)0);
2291
2292 eye_array = json_create_array()json_object_new_array();
2293 if (!eye_array)
15
Assuming 'eye_array' is non-null
16
Taking false branch
2294 return NULL((void*)0);
2295
2296 /*
2297 * Allocate buffer for full printable string (with newlines)
2298 * +1 for null terminator
2299 */
2300 printable = malloc(nrows * ncols + nrows + 1);
2301 printable_start = printable;
2302
2303 if (!printable)
17
Assuming 'printable' is non-null
18
Taking false branch
2304 goto fail_free_eye_array;
2305
2306 for (int i = 0; i
18.1
'i' is < 'nrows'
< nrows
; i++) {
19
Loop condition is true. Entering loop body
25
Assuming 'i' is < 'nrows'
26
Loop condition is true. Entering loop body
2307 char *row = malloc(ncols + 1);
2308
2309 if (!row)
20
Assuming 'row' is non-null
21
Taking false branch
27
Assuming 'row' is null
28
Taking true branch
2310 goto fail_free_eye_printable;
29
Control jumps to line 2332
2311
2312 for (int j = 0; j
21.1
'j' is < 'ncols'
< ncols
; j++) {
22
Loop condition is true. Entering loop body
23
Assuming 'j' is >= 'ncols'
24
Loop condition is false. Execution continues on line 2318
2313 char ch = eye[i * ncols + j];
2314 *printable++ = ch;
2315 row[j] = ch;
2316 }
2317
2318 *printable++ = '\n';
2319 row[ncols] = '\0';
2320
2321 array_add_strjson_array_add_value_string(eye_array, row);
2322 free(row);
2323 }
2324
2325 *printable = '\0';
2326
2327 obj_add_array(r, "printable_eye", eye_array)json_object_object_add(r, "printable_eye", eye_array);
2328
2329 return printable_start;
2330
2331fail_free_eye_printable:
2332 free(printable);
30
Argument to free() is offset by 2 bytes from the start of memory allocated by malloc()
2333fail_free_eye_array:
2334 json_free_object(eye_array)json_object_put(eye_array);
2335
2336 return NULL((void*)0);
2337}
2338
2339static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
2340 struct json_object *r, char **allocated_eyes)
2341{
2342 void *p = log->descs;
2343 uint16_t num_descs = le16_to_cpu(log->nd);
2344 int i;
2345 struct json_object *descs = json_create_array()json_object_new_array();
2346
2347 obj_add_array(r, "descs", descs)json_object_object_add(r, "descs", descs);
2348
2349 for (i = 0; i < num_descs; i++) {
6
Assuming 'i' is < 'num_descs'
7
Loop condition is true. Entering loop body
2350 struct nvme_eom_lane_desc *desc = p;
2351 __cleanup_free__attribute__((cleanup(freep))) char *hexstr = NULL((void*)0);
2352 unsigned char *vsdata = NULL((void*)0);
2353 unsigned int vsdataoffset = 0;
2354 uint16_t nrows, ncols, edlen;
2355 struct json_object *jdesc;
2356 char *hexdata;
2357
2358 jdesc = json_create_object()json_object_new_object();
2359 if (!desc
7.1
'desc' is non-null
)
8
Taking false branch
2360 return;
2361
2362 nrows = le16_to_cpu(desc->nrows);
2363 ncols = le16_to_cpu(desc->ncols);
2364 edlen = le16_to_cpu(desc->edlen);
2365
2366 obj_add_uint(jdesc, "lid", desc->mstatus)json_object_object_add(jdesc, "lid", json_object_new_uint64(desc
->mstatus))
;
2367 obj_add_uint(jdesc, "lane", desc->lane)json_object_object_add(jdesc, "lane", json_object_new_uint64(
desc->lane))
;
2368 obj_add_uint(jdesc, "eye", desc->eye)json_object_object_add(jdesc, "eye", json_object_new_uint64(desc
->eye))
;
2369 obj_add_uint(jdesc, "top", le16_to_cpu(desc->top))json_object_object_add(jdesc, "top", json_object_new_uint64(le16_to_cpu
(desc->top)))
;
2370 obj_add_uint(jdesc, "bottom", le16_to_cpu(desc->bottom))json_object_object_add(jdesc, "bottom", json_object_new_uint64
(le16_to_cpu(desc->bottom)))
;
2371 obj_add_uint(jdesc, "left", le16_to_cpu(desc->left))json_object_object_add(jdesc, "left", json_object_new_uint64(
le16_to_cpu(desc->left)))
;
2372 obj_add_uint(jdesc, "right", le16_to_cpu(desc->right))json_object_object_add(jdesc, "right", json_object_new_uint64
(le16_to_cpu(desc->right)))
;
2373 obj_add_uint(jdesc, "nrows", nrows)json_object_object_add(jdesc, "nrows", json_object_new_uint64
(nrows))
;
2374 obj_add_uint(jdesc, "ncols", ncols)json_object_object_add(jdesc, "ncols", json_object_new_uint64
(ncols))
;
2375 obj_add_uint(jdesc, "edlen", edlen)json_object_object_add(jdesc, "edlen", json_object_new_uint64
(edlen))
;
2376
2377 if (NVME_EOM_ODP_PEFP(log->odp)(((log->odp) >> NVME_EOM_ODP_PEFP_SHIFT) & NVME_EOM_ODP_PEFP_MASK
)
)
9
Assuming the condition is true
10
Taking true branch
2378 allocated_eyes[i] = json_eom_printable_eye(desc, jdesc);
11
Calling 'json_eom_printable_eye'
2379
2380 if (edlen == 0)
2381 continue;
2382
2383 /* 2 hex chars + space per byte */
2384 hexstr = malloc(edlen * 3 + 1);
2385
2386 if (!hexstr) {
2387 json_free_object(jdesc)json_object_put(jdesc);
2388 return;
2389 }
2390
2391 /* Hex dump Vendor Specific Eye Data */
2392 vsdataoffset = (nrows * ncols) + sizeof(struct nvme_eom_lane_desc);
2393 vsdata = (unsigned char *)((unsigned char *)desc + vsdataoffset);
2394
2395 hexdata = hexstr;
2396
2397 for (int offset = 0; offset < edlen; offset++)
2398 hexdata += sprintf(hexdata, "%02X ", vsdata[offset]);
2399 /* remove trailing space */
2400 *(hexdata - 1) = '\0';
2401
2402 obj_add_strjson_object_add_value_string(jdesc, "vsdata_hex", hexstr);
2403
2404 array_add_obj(descs, jdesc)json_object_array_add(descs, jdesc);
2405
2406 p += log->dsize;
2407 }
2408}
2409
2410static void json_phy_rx_eom_log(struct nvme_phy_rx_eom_log *log, __u16 controller)
2411{
2412 int i;
2413 struct json_object *r = json_create_object()json_object_new_object();
2414
2415 __cleanup_free__attribute__((cleanup(freep))) char **allocated_eyes = NULL((void*)0);
2416
2417 obj_add_uint(r, "lid", log->lid)json_object_object_add(r, "lid", json_object_new_uint64(log->
lid))
;
2418 obj_add_uint(r, "eomip", log->eomip)json_object_object_add(r, "eomip", json_object_new_uint64(log
->eomip))
;
2419 obj_add_uint(r, "hsize", le16_to_cpu(log->hsize))json_object_object_add(r, "hsize", json_object_new_uint64(le16_to_cpu
(log->hsize)))
;
2420 obj_add_uint(r, "rsize", le32_to_cpu(log->rsize))json_object_object_add(r, "rsize", json_object_new_uint64(le32_to_cpu
(log->rsize)))
;
2421 obj_add_uint(r, "eomdgn", log->eomdgn)json_object_object_add(r, "eomdgn", json_object_new_uint64(log
->eomdgn))
;
2422 obj_add_uint(r, "lr", log->lr)json_object_object_add(r, "lr", json_object_new_uint64(log->
lr))
;
2423 obj_add_uint(r, "lanes", log->lanes)json_object_object_add(r, "lanes", json_object_new_uint64(log
->lanes))
;
2424 obj_add_uint(r, "epl", log->epl)json_object_object_add(r, "epl", json_object_new_uint64(log->
epl))
;
2425 obj_add_uint(r, "lspfc", log->lspfc)json_object_object_add(r, "lspfc", json_object_new_uint64(log
->lspfc))
;
2426 obj_add_uint(r, "li", log->li)json_object_object_add(r, "li", json_object_new_uint64(log->
li))
;
2427 obj_add_uint(r, "lsic", le16_to_cpu(log->lsic))json_object_object_add(r, "lsic", json_object_new_uint64(le16_to_cpu
(log->lsic)))
;
2428 obj_add_uint(r, "dsize", le32_to_cpu(log->dsize))json_object_object_add(r, "dsize", json_object_new_uint64(le32_to_cpu
(log->dsize)))
;
2429 obj_add_uint(r, "nd", le16_to_cpu(log->nd))json_object_object_add(r, "nd", json_object_new_uint64(le16_to_cpu
(log->nd)))
;
2430 obj_add_uint(r, "maxtb", le16_to_cpu(log->maxtb))json_object_object_add(r, "maxtb", json_object_new_uint64(le16_to_cpu
(log->maxtb)))
;
2431 obj_add_uint(r, "maxlr", le16_to_cpu(log->maxlr))json_object_object_add(r, "maxlr", json_object_new_uint64(le16_to_cpu
(log->maxlr)))
;
2432 obj_add_uint(r, "etgood", le16_to_cpu(log->etgood))json_object_object_add(r, "etgood", json_object_new_uint64(le16_to_cpu
(log->etgood)))
;
2433 obj_add_uint(r, "etbetter", le16_to_cpu(log->etbetter))json_object_object_add(r, "etbetter", json_object_new_uint64(
le16_to_cpu(log->etbetter)))
;
2434 obj_add_uint(r, "etbest", le16_to_cpu(log->etbest))json_object_object_add(r, "etbest", json_object_new_uint64(le16_to_cpu
(log->etbest)))
;
2435
2436 if (log->eomip == NVME_PHY_RX_EOM_COMPLETED) {
1
Assuming field 'eomip' is equal to NVME_PHY_RX_EOM_COMPLETED
2
Taking true branch
2437 /* Save Printable Eye strings allocated to free later */
2438 allocated_eyes = malloc(log->nd * sizeof(char *));
2439 if (allocated_eyes)
3
Assuming 'allocated_eyes' is non-null
4
Taking true branch
2440 json_phy_rx_eom_descs(log, r, allocated_eyes);
5
Calling 'json_phy_rx_eom_descs'
2441 }
2442
2443 if (allocated_eyes) {
2444 for (i = 0; i < log->nd; i++) {
2445 /* Free any Printable Eye strings allocated */
2446 free(allocated_eyes[i]);
2447 }
2448 }
2449
2450 json_print(r);
2451}
2452
2453static void json_media_unit_stat_log(struct nvme_media_unit_stat_log *mus)
2454{
2455 struct json_object *r = json_create_object()json_object_new_object();
2456 struct json_object *entries = json_create_array()json_object_new_array();
2457 struct json_object *entry;
2458 int i;
2459
2460 obj_add_uint(r, "nmu", le16_to_cpu(mus->nmu))json_object_object_add(r, "nmu", json_object_new_uint64(le16_to_cpu
(mus->nmu)))
;
2461 obj_add_uint(r, "cchans", le16_to_cpu(mus->cchans))json_object_object_add(r, "cchans", json_object_new_uint64(le16_to_cpu
(mus->cchans)))
;
2462 obj_add_uint(r, "sel_config", le16_to_cpu(mus->sel_config))json_object_object_add(r, "sel_config", json_object_new_uint64
(le16_to_cpu(mus->sel_config)))
;
2463
2464 for (i = 0; i < mus->nmu; i++) {
2465 entry = json_create_object()json_object_new_object();
2466 obj_add_uint(entry, "muid", le16_to_cpu(mus->mus_desc[i].muid))json_object_object_add(entry, "muid", json_object_new_uint64(
le16_to_cpu(mus->mus_desc[i].muid)))
;
2467 obj_add_uint(entry, "domainid", le16_to_cpu(mus->mus_desc[i].domainid))json_object_object_add(entry, "domainid", json_object_new_uint64
(le16_to_cpu(mus->mus_desc[i].domainid)))
;
2468 obj_add_uint(entry, "endgid", le16_to_cpu(mus->mus_desc[i].endgid))json_object_object_add(entry, "endgid", json_object_new_uint64
(le16_to_cpu(mus->mus_desc[i].endgid)))
;
2469 obj_add_uint(entry, "nvmsetid", le16_to_cpu(mus->mus_desc[i].nvmsetid))json_object_object_add(entry, "nvmsetid", json_object_new_uint64
(le16_to_cpu(mus->mus_desc[i].nvmsetid)))
;
2470 obj_add_uint(entry, "cap_adj_fctr", le16_to_cpu(mus->mus_desc[i].cap_adj_fctr))json_object_object_add(entry, "cap_adj_fctr", json_object_new_uint64
(le16_to_cpu(mus->mus_desc[i].cap_adj_fctr)))
;
2471 obj_add_uint(entry, "avl_spare", mus->mus_desc[i].avl_spare)json_object_object_add(entry, "avl_spare", json_object_new_uint64
(mus->mus_desc[i].avl_spare))
;
2472 obj_add_uint(entry, "percent_used", mus->mus_desc[i].percent_used)json_object_object_add(entry, "percent_used", json_object_new_uint64
(mus->mus_desc[i].percent_used))
;
2473 obj_add_uint(entry, "mucs", mus->mus_desc[i].mucs)json_object_object_add(entry, "mucs", json_object_new_uint64(
mus->mus_desc[i].mucs))
;
2474 obj_add_uint(entry, "cio", mus->mus_desc[i].cio)json_object_object_add(entry, "cio", json_object_new_uint64(mus
->mus_desc[i].cio))
;
2475 array_add_obj(entries, entry)json_object_array_add(entries, entry);
2476 }
2477
2478 obj_add_array(r, "mus_list", entries)json_object_object_add(r, "mus_list", entries);
2479
2480 json_print(r);
2481}
2482
2483static void json_supported_cap_config_log(
2484 struct nvme_supported_cap_config_list_log *cap_log)
2485{
2486 struct json_object *r = json_create_object()json_object_new_object();
2487 struct json_object *cap_list = json_create_array()json_object_new_array();
2488 struct json_object *capacity;
2489 struct json_object *end_list;
2490 struct json_object *set_list;
2491 struct json_object *set;
2492 struct json_object *chan_list;
2493 struct json_object *channel;
2494 struct json_object *media_list;
2495 struct json_object *media;
2496 struct json_object *endurance;
2497 struct nvme_end_grp_chan_desc *chan_desc;
2498 int i, j, k, l, m, egcn, egsets, egchans, chmus;
2499 int sccn = cap_log->sccn;
2500
2501 obj_add_uint(r, "sccn", cap_log->sccn)json_object_object_add(r, "sccn", json_object_new_uint64(cap_log
->sccn))
;
2502 for (i = 0; i < sccn; i++) {
2503 capacity = json_create_object()json_object_new_object();
2504 obj_add_uint(capacity, "cap_config_id",json_object_object_add(capacity, "cap_config_id", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].cap_config_id)))
2505 le16_to_cpu(cap_log->cap_config_desc[i].cap_config_id))json_object_object_add(capacity, "cap_config_id", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].cap_config_id)))
;
2506 obj_add_uint(capacity, "domainid",json_object_object_add(capacity, "domainid", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].domainid)))
2507 le16_to_cpu(cap_log->cap_config_desc[i].domainid))json_object_object_add(capacity, "domainid", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].domainid)))
;
2508 obj_add_uint(capacity, "egcn", le16_to_cpu(cap_log->cap_config_desc[i].egcn))json_object_object_add(capacity, "egcn", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcn)))
;
2509 end_list = json_create_array()json_object_new_array();
2510 egcn = le16_to_cpu(cap_log->cap_config_desc[i].egcn);
2511 for (j = 0; j < egcn; j++) {
2512 endurance = json_create_object()json_object_new_object();
2513 obj_add_uint(endurance, "endgid",json_object_object_add(endurance, "endgid", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].endgid)))
2514 le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].endgid))json_object_object_add(endurance, "endgid", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].endgid)))
;
2515 obj_add_uint(endurance, "cap_adj_factor",json_object_object_add(endurance, "cap_adj_factor", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].cap_adj_factor
)))
2516 le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].cap_adj_factor))json_object_object_add(endurance, "cap_adj_factor", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].cap_adj_factor
)))
;
2517 obj_add_uint128(endurance, "tegcap",json_object_object_add(endurance, "tegcap", util_json_object_new_uint128
(le128_to_cpu(cap_log->cap_config_desc[i].egcd[j].tegcap))
)
2518 le128_to_cpu(cap_log->cap_config_desc[i].egcd[j].tegcap))json_object_object_add(endurance, "tegcap", util_json_object_new_uint128
(le128_to_cpu(cap_log->cap_config_desc[i].egcd[j].tegcap))
)
;
2519 obj_add_uint128(endurance, "segcap",json_object_object_add(endurance, "segcap", util_json_object_new_uint128
(le128_to_cpu(cap_log->cap_config_desc[i].egcd[j].segcap))
)
2520 le128_to_cpu(cap_log->cap_config_desc[i].egcd[j].segcap))json_object_object_add(endurance, "segcap", util_json_object_new_uint128
(le128_to_cpu(cap_log->cap_config_desc[i].egcd[j].segcap))
)
;
2521 obj_add_uint(endurance, "egsets",json_object_object_add(endurance, "egsets", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].egsets)))
2522 le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].egsets))json_object_object_add(endurance, "egsets", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].egsets)))
;
2523 egsets = le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].egsets);
2524 set_list = json_create_array()json_object_new_array();
2525 for (k = 0; k < egsets; k++) {
2526 set = json_create_object()json_object_new_object();
2527 obj_add_uint(set, "nvmsetid",json_object_object_add(set, "nvmsetid", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].nvmsetid[
k])))
2528 le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].nvmsetid[k]))json_object_object_add(set, "nvmsetid", json_object_new_uint64
(le16_to_cpu(cap_log->cap_config_desc[i].egcd[j].nvmsetid[
k])))
;
2529 array_add_obj(set_list, set)json_object_array_add(set_list, set);
2530 }
2531 chan_desc = (struct nvme_end_grp_chan_desc *)
2532 &cap_log->cap_config_desc[i].egcd[j].nvmsetid[egsets];
2533 egchans = le16_to_cpu(chan_desc->egchans);
2534 obj_add_uint(endurance, "egchans", le16_to_cpu(chan_desc->egchans))json_object_object_add(endurance, "egchans", json_object_new_uint64
(le16_to_cpu(chan_desc->egchans)))
;
2535 chan_list = json_create_array()json_object_new_array();
2536 for (l = 0; l < egchans; l++) {
2537 channel = json_create_object()json_object_new_object();
2538 obj_add_uint(channel, "chanid",json_object_object_add(channel, "chanid", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].chanid)))
2539 le16_to_cpu(chan_desc->chan_config_desc[l].chanid))json_object_object_add(channel, "chanid", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].chanid)))
;
2540 obj_add_uint(channel, "chmus",json_object_object_add(channel, "chmus", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].chmus)))
2541 le16_to_cpu(chan_desc->chan_config_desc[l].chmus))json_object_object_add(channel, "chmus", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].chmus)))
;
2542 chmus = le16_to_cpu(chan_desc->chan_config_desc[l].chmus);
2543 media_list = json_create_array()json_object_new_array();
2544 for (m = 0; m < chmus; m++) {
2545 media = json_create_object()json_object_new_object();
2546 obj_add_uint(media, "chanid",json_object_object_add(media, "chanid", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].mu_config_desc
[m].muid)))
2547 le16_to_cpu(chan_desc->chan_config_desc[l].mu_config_desc[m].muid))json_object_object_add(media, "chanid", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].mu_config_desc
[m].muid)))
;
2548 obj_add_uint(media, "chmus",json_object_object_add(media, "chmus", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].mu_config_desc
[m].mudl)))
2549 le16_to_cpu(chan_desc->chan_config_desc[l].mu_config_desc[m].mudl))json_object_object_add(media, "chmus", json_object_new_uint64
(le16_to_cpu(chan_desc->chan_config_desc[l].mu_config_desc
[m].mudl)))
;
2550 array_add_obj(media_list, media)json_object_array_add(media_list, media);
2551 }
2552 obj_add_array(channel, "Media Descriptor", media_list)json_object_object_add(channel, "Media Descriptor", media_list
)
;
2553 array_add_obj(chan_list, channel)json_object_array_add(chan_list, channel);
2554 }
2555 obj_add_array(endurance, "Channel Descriptor", chan_list)json_object_object_add(endurance, "Channel Descriptor", chan_list
)
;
2556 obj_add_array(endurance, "NVM Set IDs", set_list)json_object_object_add(endurance, "NVM Set IDs", set_list);
2557 array_add_obj(end_list, endurance)json_object_array_add(end_list, endurance);
2558 }
2559 obj_add_array(capacity, "Endurance Descriptor", end_list)json_object_object_add(capacity, "Endurance Descriptor", end_list
)
;
2560 array_add_obj(cap_list, capacity)json_object_array_add(cap_list, capacity);
2561 }
2562
2563 obj_add_array(r, "Capacity Descriptor", cap_list)json_object_object_add(r, "Capacity Descriptor", cap_list);
2564
2565 json_print(r);
2566}
2567
2568static void json_nvme_fdp_configs(struct nvme_fdp_config_log *log, size_t len)
2569{
2570 struct json_object *r, *obj_configs;
2571 uint16_t n;
2572
2573 void *p = log->configs;
2574
2575 r = json_create_object()json_object_new_object();
2576 obj_configs = json_create_array()json_object_new_array();
2577
2578 n = le16_to_cpu(log->n);
2579
2580 obj_add_uint(r, "n", n)json_object_object_add(r, "n", json_object_new_uint64(n));
2581
2582 for (int i = 0; i < n + 1; i++) {
2583 struct nvme_fdp_config_desc *config = p;
2584
2585 struct json_object *obj_config = json_create_object()json_object_new_object();
2586 struct json_object *obj_ruhs = json_create_array()json_object_new_array();
2587
2588 obj_add_uint(obj_config, "fdpa", config->fdpa)json_object_object_add(obj_config, "fdpa", json_object_new_uint64
(config->fdpa))
;
2589 obj_add_uint(obj_config, "vss", config->vss)json_object_object_add(obj_config, "vss", json_object_new_uint64
(config->vss))
;
2590 obj_add_uint(obj_config, "nrg", le32_to_cpu(config->nrg))json_object_object_add(obj_config, "nrg", json_object_new_uint64
(le32_to_cpu(config->nrg)))
;
2591 obj_add_uint(obj_config, "nruh", le16_to_cpu(config->nruh))json_object_object_add(obj_config, "nruh", json_object_new_uint64
(le16_to_cpu(config->nruh)))
;
2592 obj_add_uint(obj_config, "nnss", le32_to_cpu(config->nnss))json_object_object_add(obj_config, "nnss", json_object_new_uint64
(le32_to_cpu(config->nnss)))
;
2593 obj_add_uint64(obj_config, "runs", le64_to_cpu(config->runs))json_object_object_add(obj_config, "runs", json_object_new_uint64
(le64_to_cpu(config->runs)))
;
2594 obj_add_uint(obj_config, "erutl", le32_to_cpu(config->erutl))json_object_object_add(obj_config, "erutl", json_object_new_uint64
(le32_to_cpu(config->erutl)))
;
2595
2596 for (int j = 0; j < le16_to_cpu(config->nruh); j++) {
2597 struct nvme_fdp_ruh_desc *ruh = &config->ruhs[j];
2598
2599 struct json_object *obj_ruh = json_create_object()json_object_new_object();
2600
2601 obj_add_uint(obj_ruh, "ruht", ruh->ruht)json_object_object_add(obj_ruh, "ruht", json_object_new_uint64
(ruh->ruht))
;
2602
2603 array_add_obj(obj_ruhs, obj_ruh)json_object_array_add(obj_ruhs, obj_ruh);
2604 }
2605
2606 array_add_obj(obj_configs, obj_config)json_object_array_add(obj_configs, obj_config);
2607
2608 p += config->size;
2609 }
2610
2611 obj_add_array(r, "configs", obj_configs)json_object_object_add(r, "configs", obj_configs);
2612
2613 json_print(r);
2614}
2615
2616static void json_nvme_fdp_usage(struct nvme_fdp_ruhu_log *log, size_t len)
2617{
2618 struct json_object *r, *obj_ruhus;
2619 uint16_t nruh;
2620
2621 r = json_create_object()json_object_new_object();
2622 obj_ruhus = json_create_array()json_object_new_array();
2623
2624 nruh = le16_to_cpu(log->nruh);
2625
2626 obj_add_uint(r, "nruh", nruh)json_object_object_add(r, "nruh", json_object_new_uint64(nruh
))
;
2627
2628 for (int i = 0; i < nruh; i++) {
2629 struct nvme_fdp_ruhu_desc *ruhu = &log->ruhus[i];
2630
2631 struct json_object *obj_ruhu = json_create_object()json_object_new_object();
2632
2633 obj_add_uint(obj_ruhu, "ruha", ruhu->ruha)json_object_object_add(obj_ruhu, "ruha", json_object_new_uint64
(ruhu->ruha))
;
2634
2635 array_add_obj(obj_ruhus, obj_ruhu)json_object_array_add(obj_ruhus, obj_ruhu);
2636 }
2637
2638 obj_add_array(r, "ruhus", obj_ruhus)json_object_object_add(r, "ruhus", obj_ruhus);
2639
2640 json_print(r);
2641}
2642
2643static void json_nvme_fdp_stats(struct nvme_fdp_stats_log *log)
2644{
2645 struct json_object *r = json_create_object()json_object_new_object();
2646
2647 obj_add_uint128(r, "hbmw", le128_to_cpu(log->hbmw))json_object_object_add(r, "hbmw", util_json_object_new_uint128
(le128_to_cpu(log->hbmw)))
;
2648 obj_add_uint128(r, "mbmw", le128_to_cpu(log->mbmw))json_object_object_add(r, "mbmw", util_json_object_new_uint128
(le128_to_cpu(log->mbmw)))
;
2649 obj_add_uint128(r, "mbe", le128_to_cpu(log->mbe))json_object_object_add(r, "mbe", util_json_object_new_uint128
(le128_to_cpu(log->mbe)))
;
2650
2651 json_print(r);
2652}
2653
2654static void json_nvme_fdp_events(struct nvme_fdp_events_log *log)
2655{
2656 struct json_object *r, *obj_events;
2657 uint32_t n;
2658
2659 r = json_create_object()json_object_new_object();
2660 obj_events = json_create_array()json_object_new_array();
2661
2662 n = le32_to_cpu(log->n);
2663
2664 obj_add_uint(r, "n", n)json_object_object_add(r, "n", json_object_new_uint64(n));
2665
2666 for (unsigned int i = 0; i < n; i++) {
2667 struct nvme_fdp_event *event = &log->events[i];
2668
2669 struct json_object *obj_event = json_create_object()json_object_new_object();
2670
2671 obj_add_uint(obj_event, "type", event->type)json_object_object_add(obj_event, "type", json_object_new_uint64
(event->type))
;
2672 obj_add_uint(obj_event, "fdpef", event->flags)json_object_object_add(obj_event, "fdpef", json_object_new_uint64
(event->flags))
;
2673 obj_add_uint(obj_event, "pid", le16_to_cpu(event->pid))json_object_object_add(obj_event, "pid", json_object_new_uint64
(le16_to_cpu(event->pid)))
;
2674 obj_add_uint64(obj_event, "timestamp", le64_to_cpu(*(uint64_t *)&event->ts))json_object_object_add(obj_event, "timestamp", json_object_new_uint64
(le64_to_cpu(*(uint64_t *)&event->ts)))
;
2675 obj_add_uint(obj_event, "nsid", le32_to_cpu(event->nsid))json_object_object_add(obj_event, "nsid", json_object_new_uint64
(le32_to_cpu(event->nsid)))
;
2676
2677 if (event->type == NVME_FDP_EVENT_REALLOC) {
2678 struct nvme_fdp_event_realloc *mr;
2679
2680 mr = (struct nvme_fdp_event_realloc *)&event->type_specific;
2681
2682 obj_add_uint(obj_event, "nlbam", le16_to_cpu(mr->nlbam))json_object_object_add(obj_event, "nlbam", json_object_new_uint64
(le16_to_cpu(mr->nlbam)))
;
2683
2684 if (mr->flags & NVME_FDP_EVENT_REALLOC_F_LBAV)
2685 obj_add_uint64(obj_event, "lba", le64_to_cpu(mr->lba))json_object_object_add(obj_event, "lba", json_object_new_uint64
(le64_to_cpu(mr->lba)))
;
2686 }
2687
2688 array_add_obj(obj_events, obj_event)json_object_array_add(obj_events, obj_event);
2689 }
2690
2691 obj_add_array(r, "events", obj_events)json_object_object_add(r, "events", obj_events);
2692
2693 json_print(r);
2694}
2695
2696static void json_nvme_fdp_ruh_status(struct nvme_fdp_ruh_status *status, size_t len)
2697{
2698 struct json_object *r, *obj_ruhss;
2699 uint16_t nruhsd;
2700
2701 r = json_create_object()json_object_new_object();
2702 obj_ruhss = json_create_array()json_object_new_array();
2703
2704 nruhsd = le16_to_cpu(status->nruhsd);
2705
2706 obj_add_uint(r, "nruhsd", nruhsd)json_object_object_add(r, "nruhsd", json_object_new_uint64(nruhsd
))
;
2707
2708 for (unsigned int i = 0; i < nruhsd; i++) {
2709 struct nvme_fdp_ruh_status_desc *ruhs = &status->ruhss[i];
2710
2711 struct json_object *obj_ruhs = json_create_object()json_object_new_object();
2712
2713 obj_add_uint(obj_ruhs, "pid", le16_to_cpu(ruhs->pid))json_object_object_add(obj_ruhs, "pid", json_object_new_uint64
(le16_to_cpu(ruhs->pid)))
;
2714 obj_add_uint(obj_ruhs, "ruhid", le16_to_cpu(ruhs->ruhid))json_object_object_add(obj_ruhs, "ruhid", json_object_new_uint64
(le16_to_cpu(ruhs->ruhid)))
;
2715 obj_add_uint(obj_ruhs, "earutr", le32_to_cpu(ruhs->earutr))json_object_object_add(obj_ruhs, "earutr", json_object_new_uint64
(le32_to_cpu(ruhs->earutr)))
;
2716 obj_add_uint64(obj_ruhs, "ruamw", le64_to_cpu(ruhs->ruamw))json_object_object_add(obj_ruhs, "ruamw", json_object_new_uint64
(le64_to_cpu(ruhs->ruamw)))
;
2717
2718 array_add_obj(obj_ruhss, obj_ruhs)json_object_array_add(obj_ruhss, obj_ruhs);
2719 }
2720
2721 obj_add_array(r, "ruhss", obj_ruhss)json_object_object_add(r, "ruhss", obj_ruhss);
2722
2723 json_print(r);
2724}
2725
2726static unsigned int json_print_nvme_subsystem_multipath(libnvme_subsystem_t s, json_object *paths)
2727{
2728 libnvme_ns_t n;
2729 libnvme_path_t p;
2730 unsigned int i = 0;
2731
2732 n = libnvme_subsystem_first_ns(s);
2733 if (!n)
2734 return 0;
2735
2736 libnvme_namespace_for_each_path(n, p)for (p = libnvme_namespace_first_path(n); p != ((void*)0); p =
libnvme_namespace_next_path(n, p))
{
2737 struct json_object *path_attrs;
2738 libnvme_ctrl_t c = libnvme_path_get_ctrl(p);
2739
2740 path_attrs = json_create_object()json_object_new_object();
2741 obj_add_strjson_object_add_value_string(path_attrs, "Name", libnvme_ctrl_get_name(c));
2742 obj_add_strjson_object_add_value_string(path_attrs, "Transport", libnvme_ctrl_get_transport(c));
2743 obj_add_strjson_object_add_value_string(path_attrs, "Address", libnvme_ctrl_get_traddr(c));
2744 obj_add_ctrl_address_details(path_attrs, "AddressDetails", c);
2745 obj_add_strjson_object_add_value_string(path_attrs, "State", libnvme_ctrl_get_state(c));
2746 obj_add_strjson_object_add_value_string(path_attrs, "ANAState", libnvme_path_get_ana_state(p));
2747 array_add_obj(paths, path_attrs)json_object_array_add(paths, path_attrs);
2748 i++;
2749 }
2750
2751 return i;
2752}
2753
2754static void json_print_nvme_subsystem_ctrls(libnvme_subsystem_t s,
2755 json_object *paths)
2756{
2757 libnvme_ctrl_t c;
2758
2759 libnvme_subsystem_for_each_ctrl(s, c)for (c = libnvme_subsystem_first_ctrl(s); c != ((void*)0); c =
libnvme_subsystem_next_ctrl(s, c))
{
2760 struct json_object *path_attrs;
2761
2762 path_attrs = json_create_object()json_object_new_object();
2763 obj_add_strjson_object_add_value_string(path_attrs, "Name", libnvme_ctrl_get_name(c));
2764 obj_add_strjson_object_add_value_string(path_attrs, "Transport", libnvme_ctrl_get_transport(c));
2765 obj_add_strjson_object_add_value_string(path_attrs, "Address", libnvme_ctrl_get_traddr(c));
2766 obj_add_ctrl_address_details(path_attrs, "AddressDetails", c);
2767 obj_add_strjson_object_add_value_string(path_attrs, "State", libnvme_ctrl_get_state(c));
2768 array_add_obj(paths, path_attrs)json_object_array_add(paths, path_attrs);
2769 }
2770}
2771
2772static void json_print_nvme_subsystem_list(struct libnvme_global_ctx *ctx,
2773 bool_Bool show_ana)
2774{
2775 struct json_object *host_attrs, *subsystem_attrs;
2776 struct json_object *subsystems, *paths;
2777 struct json_object *a = json_create_array()json_object_new_array();
2778 libnvme_host_t h;
2779
2780 libnvme_for_each_host(ctx, h)for (h = libnvme_first_host(ctx); h != ((void*)0); h = libnvme_next_host
(ctx, h))
{
2781 libnvme_subsystem_t s;
2782 const char *hostid;
2783
2784 host_attrs = json_create_object()json_object_new_object();
2785 obj_add_strjson_object_add_value_string(host_attrs, "HostNQN", libnvme_host_get_hostnqn(h));
2786 hostid = libnvme_host_get_hostid(h);
2787 if (hostid)
2788 obj_add_strjson_object_add_value_string(host_attrs, "HostID", hostid);
2789 subsystems = json_create_array()json_object_new_array();
2790 libnvme_for_each_subsystem(h, s)for (s = libnvme_first_subsystem(h); s != ((void*)0); s = libnvme_next_subsystem
(h, s))
{
2791 libnvme_ctrl_t c;
2792 bool_Bool no_ctrl = true1;
2793
2794 libnvme_subsystem_for_each_ctrl(s, c)for (c = libnvme_subsystem_first_ctrl(s); c != ((void*)0); c =
libnvme_subsystem_next_ctrl(s, c))
2795 no_ctrl = false0;
2796 if (no_ctrl)
2797 continue;
2798
2799 subsystem_attrs = json_create_object()json_object_new_object();
2800 obj_add_strjson_object_add_value_string(subsystem_attrs, "Name", libnvme_subsystem_get_name(s));
2801 obj_add_strjson_object_add_value_string(subsystem_attrs, "NQN", libnvme_subsystem_get_subsysnqn(s));
2802
2803 if (verbose_mode()) {
2804 obj_add_strjson_object_add_value_string(subsystem_attrs, "Model",
2805 libnvme_subsystem_get_model(s));
2806 obj_add_strjson_object_add_value_string(subsystem_attrs, "Serial",
2807 libnvme_subsystem_get_serial(s));
2808 obj_add_strjson_object_add_value_string(subsystem_attrs, "Firmware",
2809 libnvme_subsystem_get_firmware(s));
2810 obj_add_strjson_object_add_value_string(subsystem_attrs, "IOPolicy",
2811 libnvme_subsystem_get_iopolicy(s));
2812 obj_add_strjson_object_add_value_string(subsystem_attrs, "Type",
2813 libnvme_subsystem_get_subsystype(s));
2814 }
2815
2816 array_add_obj(subsystems, subsystem_attrs)json_object_array_add(subsystems, subsystem_attrs);
2817 paths = json_create_array()json_object_new_array();
2818
2819 if (!show_ana || !json_print_nvme_subsystem_multipath(s, paths))
2820 json_print_nvme_subsystem_ctrls(s, paths);
2821
2822 obj_add_array(subsystem_attrs, "Paths", paths)json_object_object_add(subsystem_attrs, "Paths", paths);
2823 }
2824 obj_add_array(host_attrs, "Subsystems", subsystems)json_object_object_add(host_attrs, "Subsystems", subsystems);
2825 array_add_obj(a, host_attrs)json_object_array_add(a, host_attrs);
2826 }
2827
2828 json_print(a);
2829}
2830
2831static void json_ctrl_registers_cap(void *bar, struct json_object *r)
2832{
2833 uint64_t cap = mmio_read64(bar + NVME_REG_CAP);
2834
2835 if (verbose_mode())
2836 json_registers_cap((struct nvme_bar_cap *)&cap, obj_create_array_obj(r, "cap"));
2837 else
2838 obj_add_uint64(r, "cap", cap)json_object_object_add(r, "cap", json_object_new_uint64(cap));
2839}
2840
2841static void json_ctrl_registers_vs(void *bar, struct json_object *r)
2842{
2843 uint32_t vs = mmio_read32(bar + NVME_REG_VS);
2844
2845 if (verbose_mode())
2846 json_registers_version(vs, obj_create_array_obj(r, "vs"));
2847 else
2848 obj_add_int(r, "vs", vs)json_object_object_add(r, "vs", json_object_new_int(vs));
2849}
2850
2851static void json_ctrl_registers_intms(void *bar, struct json_object *r)
2852{
2853 uint32_t intms = mmio_read32(bar + NVME_REG_INTMS);
2854
2855 if (verbose_mode())
2856 json_registers_intms(intms, obj_create_array_obj(r, "intms"));
2857 else
2858 obj_add_int(r, "intms", intms)json_object_object_add(r, "intms", json_object_new_int(intms)
)
;
2859}
2860
2861static void json_ctrl_registers_intmc(void *bar, struct json_object *r)
2862{
2863 uint32_t intmc = mmio_read32(bar + NVME_REG_INTMC);
2864
2865 if (verbose_mode())
2866 json_registers_intmc(intmc, obj_create_array_obj(r, "intmc"));
2867 else
2868 obj_add_int(r, "intmc", intmc)json_object_object_add(r, "intmc", json_object_new_int(intmc)
)
;
2869}
2870
2871static void json_ctrl_registers_cc(void *bar, struct json_object *r)
2872{
2873 uint32_t cc = mmio_read32(bar + NVME_REG_CC);
2874
2875 if (verbose_mode())
2876 json_registers_cc(cc, obj_create_array_obj(r, "cc"));
2877 else
2878 obj_add_int(r, "cc", cc)json_object_object_add(r, "cc", json_object_new_int(cc));
2879}
2880
2881static void json_ctrl_registers_csts(void *bar, struct json_object *r)
2882{
2883 uint32_t csts = mmio_read32(bar + NVME_REG_CSTS);
2884
2885 if (verbose_mode())
2886 json_registers_csts(csts, obj_create_array_obj(r, "csts"));
2887 else
2888 obj_add_int(r, "csts", csts)json_object_object_add(r, "csts", json_object_new_int(csts));
2889}
2890
2891static void json_ctrl_registers_nssr(void *bar, struct json_object *r)
2892{
2893 uint32_t nssr = mmio_read32(bar + NVME_REG_NSSR);
2894
2895 if (verbose_mode())
2896 json_registers_nssr(nssr, obj_create_array_obj(r, "nssr"));
2897 else
2898 obj_add_int(r, "nssr", nssr)json_object_object_add(r, "nssr", json_object_new_int(nssr));
2899}
2900
2901static void json_ctrl_registers_nssd(void *bar, struct json_object *r)
2902{
2903 uint32_t nssd = mmio_read32(bar + NVME_REG_NSSD);
2904
2905 if (verbose_mode())
2906 json_registers_nssd(nssd, obj_create_array_obj(r, "nssd"));
2907 else
2908 obj_add_int(r, "nssd", nssd)json_object_object_add(r, "nssd", json_object_new_int(nssd));
2909}
2910
2911static void json_ctrl_registers_crto(void *bar, struct json_object *r)
2912{
2913 uint32_t crto = mmio_read32(bar + NVME_REG_CRTO);
2914
2915 if (verbose_mode())
2916 json_registers_crto(crto, obj_create_array_obj(r, "crto"));
2917 else
2918 obj_add_int(r, "crto", crto)json_object_object_add(r, "crto", json_object_new_int(crto));
2919}
2920
2921static void json_ctrl_registers_aqa(void *bar, struct json_object *r)
2922{
2923 uint32_t aqa = mmio_read32(bar + NVME_REG_AQA);
2924
2925 if (verbose_mode())
2926 json_registers_aqa(aqa, obj_create_array_obj(r, "aqa"));
2927 else
2928 obj_add_int(r, "aqa", aqa)json_object_object_add(r, "aqa", json_object_new_int(aqa));
2929}
2930
2931static void json_ctrl_registers_asq(void *bar, struct json_object *r)
2932{
2933 uint64_t asq = mmio_read64(bar + NVME_REG_ASQ);
2934
2935 if (verbose_mode())
2936 json_registers_asq(asq, obj_create_array_obj(r, "asq"));
2937 else
2938 obj_add_uint64(r, "asq", asq)json_object_object_add(r, "asq", json_object_new_uint64(asq));
2939}
2940
2941static void json_ctrl_registers_acq(void *bar, struct json_object *r)
2942{
2943 uint64_t acq = mmio_read64(bar + NVME_REG_ACQ);
2944
2945 if (verbose_mode())
2946 json_registers_acq(acq, obj_create_array_obj(r, "acq"));
2947 else
2948 obj_add_uint64(r, "acq", acq)json_object_object_add(r, "acq", json_object_new_uint64(acq));
2949}
2950
2951static void json_ctrl_registers_cmbloc(void *bar, struct json_object *r)
2952{
2953 uint32_t cmbloc = mmio_read32(bar + NVME_REG_CMBLOC);
2954 uint32_t cmbsz;
2955 bool_Bool support;
2956
2957 if (verbose_mode()) {
2958 cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
2959 support = nvme_registers_cmbloc_support(cmbsz);
2960 json_registers_cmbloc(cmbloc, support, obj_create_array_obj(r, "cmbloc"));
2961 } else {
2962 obj_add_int(r, "cmbloc", cmbloc)json_object_object_add(r, "cmbloc", json_object_new_int(cmbloc
))
;
2963 }
2964}
2965
2966static void json_ctrl_registers_cmbsz(void *bar, struct json_object *r)
2967{
2968 uint32_t cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
2969
2970 if (verbose_mode())
2971 json_registers_cmbsz(cmbsz, obj_create_array_obj(r, "cmbsz"));
2972 else
2973 obj_add_int(r, "cmbsz", cmbsz)json_object_object_add(r, "cmbsz", json_object_new_int(cmbsz)
)
;
2974}
2975
2976static void json_ctrl_registers_bpinfo(void *bar, struct json_object *r)
2977{
2978 uint32_t bpinfo = mmio_read32(bar + NVME_REG_BPINFO);
2979
2980 if (verbose_mode())
2981 json_registers_bpinfo(bpinfo, obj_create_array_obj(r, "bpinfo"));
2982 else
2983 obj_add_int(r, "bpinfo", bpinfo)json_object_object_add(r, "bpinfo", json_object_new_int(bpinfo
))
;
2984}
2985
2986static void json_ctrl_registers_bprsel(void *bar, struct json_object *r)
2987{
2988 uint32_t bprsel = mmio_read32(bar + NVME_REG_BPRSEL);
2989
2990 if (verbose_mode())
2991 json_registers_bprsel(bprsel, obj_create_array_obj(r, "bprsel"));
2992 else
2993 obj_add_int(r, "bprsel", bprsel)json_object_object_add(r, "bprsel", json_object_new_int(bprsel
))
;
2994}
2995
2996static void json_ctrl_registers_bpmbl(void *bar, struct json_object *r)
2997{
2998 uint64_t bpmbl = mmio_read64(bar + NVME_REG_BPMBL);
2999
3000 if (verbose_mode())
3001 json_registers_bpmbl(bpmbl, obj_create_array_obj(r, "bpmbl"));
3002 else
3003 obj_add_uint64(r, "bpmbl", bpmbl)json_object_object_add(r, "bpmbl", json_object_new_uint64(bpmbl
))
;
3004}
3005
3006static void json_ctrl_registers_cmbmsc(void *bar, struct json_object *r)
3007{
3008 uint64_t cmbmsc = mmio_read64(bar + NVME_REG_CMBMSC);
3009
3010 if (verbose_mode())
3011 json_registers_cmbmsc(cmbmsc, obj_create_array_obj(r, "cmbmsc"));
3012 else
3013 obj_add_uint64(r, "cmbmsc", cmbmsc)json_object_object_add(r, "cmbmsc", json_object_new_uint64(cmbmsc
))
;
3014}
3015
3016static void json_ctrl_registers_cmbsts(void *bar, struct json_object *r)
3017{
3018 uint32_t cmbsts = mmio_read32(bar + NVME_REG_CMBSTS);
3019
3020 if (verbose_mode())
3021 json_registers_cmbsts(cmbsts, obj_create_array_obj(r, "cmbsts"));
3022 else
3023 obj_add_int(r, "cmbsts", cmbsts)json_object_object_add(r, "cmbsts", json_object_new_int(cmbsts
))
;
3024}
3025
3026static void json_ctrl_registers_cmbebs(void *bar, struct json_object *r)
3027{
3028 uint32_t cmbebs = mmio_read32(bar + NVME_REG_CMBEBS);
3029
3030 if (verbose_mode())
3031 json_registers_cmbebs(cmbebs, obj_create_array_obj(r, "cmbebs"));
3032 else
3033 obj_add_int(r, "cmbebs", cmbebs)json_object_object_add(r, "cmbebs", json_object_new_int(cmbebs
))
;
3034}
3035
3036static void json_ctrl_registers_cmbswtp(void *bar, struct json_object *r)
3037{
3038 uint32_t cmbswtp = mmio_read32(bar + NVME_REG_CMBSWTP);
3039
3040 if (verbose_mode())
3041 json_registers_cmbswtp(cmbswtp, obj_create_array_obj(r, "cmbswtp"));
3042 else
3043 obj_add_int(r, "cmbswtp", cmbswtp)json_object_object_add(r, "cmbswtp", json_object_new_int(cmbswtp
))
;
3044}
3045
3046static void json_ctrl_registers_pmrcap(void *bar, struct json_object *r)
3047{
3048 uint32_t pmrcap = mmio_read32(bar + NVME_REG_PMRCAP);
3049
3050 if (verbose_mode())
3051 json_registers_pmrcap(pmrcap, obj_create_array_obj(r, "pmrcap"));
3052 else
3053 obj_add_int(r, "pmrcap", pmrcap)json_object_object_add(r, "pmrcap", json_object_new_int(pmrcap
))
;
3054}
3055
3056static void json_ctrl_registers_pmrctl(void *bar, struct json_object *r)
3057{
3058 uint32_t pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
3059
3060 if (verbose_mode())
3061 json_registers_pmrctl(pmrctl, obj_create_array_obj(r, "pmrctl"));
3062 else
3063 obj_add_int(r, "pmrctl", pmrctl)json_object_object_add(r, "pmrctl", json_object_new_int(pmrctl
))
;
3064}
3065
3066static void json_ctrl_registers_pmrsts(void *bar, struct json_object *r)
3067{
3068 uint32_t pmrsts = mmio_read32(bar + NVME_REG_PMRSTS);
3069 uint32_t pmrctl;
3070 bool_Bool ready;
3071
3072 if (verbose_mode()) {
3073 pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
3074 ready = nvme_registers_pmrctl_ready(pmrctl);
3075 json_registers_pmrsts(pmrsts, ready, obj_create_array_obj(r, "pmrsts"));
3076 } else {
3077 obj_add_int(r, "pmrsts", pmrsts)json_object_object_add(r, "pmrsts", json_object_new_int(pmrsts
))
;
3078 }
3079}
3080
3081static void json_ctrl_registers_pmrebs(void *bar, struct json_object *r)
3082{
3083 uint32_t pmrebs = mmio_read32(bar + NVME_REG_PMREBS);
3084
3085 if (verbose_mode())
3086 json_registers_pmrebs(pmrebs, obj_create_array_obj(r, "pmrebs"));
3087 else
3088 obj_add_int(r, "pmrebs", pmrebs)json_object_object_add(r, "pmrebs", json_object_new_int(pmrebs
))
;
3089}
3090
3091static void json_ctrl_registers_pmrswtp(void *bar, struct json_object *r)
3092{
3093 uint32_t pmrswtp = mmio_read32(bar + NVME_REG_PMRSWTP);
3094
3095 if (verbose_mode())
3096 json_registers_pmrswtp(pmrswtp, obj_create_array_obj(r, "pmrswtp"));
3097 else
3098 obj_add_int(r, "pmrswtp", pmrswtp)json_object_object_add(r, "pmrswtp", json_object_new_int(pmrswtp
))
;
3099}
3100
3101static void json_ctrl_registers_pmrmscl(void *bar, struct json_object *r)
3102{
3103 uint32_t pmrmscl = mmio_read32(bar + NVME_REG_PMRMSCL);
3104
3105 if (verbose_mode())
3106 json_registers_pmrmscl(pmrmscl, obj_create_array_obj(r, "pmrmscl"));
3107 else
3108 obj_add_uint(r, "pmrmscl", pmrmscl)json_object_object_add(r, "pmrmscl", json_object_new_uint64(pmrmscl
))
;
3109}
3110
3111static void json_ctrl_registers_pmrmscu(void *bar, struct json_object *r)
3112{
3113 uint32_t pmrmscu = mmio_read32(bar + NVME_REG_PMRMSCU);
3114
3115 if (verbose_mode())
3116 json_registers_pmrmscu(pmrmscu, obj_create_array_obj(r, "pmrmscu"));
3117 else
3118 obj_add_uint(r, "pmrmscu", pmrmscu)json_object_object_add(r, "pmrmscu", json_object_new_uint64(pmrmscu
))
;
3119}
3120
3121static void json_ctrl_registers(void *bar, bool_Bool fabrics)
3122{
3123 struct json_object *r = json_create_object()json_object_new_object();
3124
3125 json_ctrl_registers_cap(bar, r);
3126 json_ctrl_registers_vs(bar, r);
3127 json_ctrl_registers_intms(bar, r);
3128 json_ctrl_registers_intmc(bar, r);
3129 json_ctrl_registers_cc(bar, r);
3130 json_ctrl_registers_csts(bar, r);
3131 json_ctrl_registers_nssr(bar, r);
3132 json_ctrl_registers_aqa(bar, r);
3133 json_ctrl_registers_asq(bar, r);
3134 json_ctrl_registers_acq(bar, r);
3135 json_ctrl_registers_cmbloc(bar, r);
3136 json_ctrl_registers_cmbsz(bar, r);
3137 json_ctrl_registers_bpinfo(bar, r);
3138 json_ctrl_registers_bprsel(bar, r);
3139 json_ctrl_registers_bpmbl(bar, r);
3140 json_ctrl_registers_cmbmsc(bar, r);
3141 json_ctrl_registers_cmbsts(bar, r);
3142 json_ctrl_registers_cmbebs(bar, r);
3143 json_ctrl_registers_cmbswtp(bar, r);
3144 json_ctrl_registers_nssd(bar, r);
3145 json_ctrl_registers_crto(bar, r);
3146 json_ctrl_registers_pmrcap(bar, r);
3147 json_ctrl_registers_pmrctl(bar, r);
3148 json_ctrl_registers_pmrsts(bar, r);
3149 json_ctrl_registers_pmrebs(bar, r);
3150 json_ctrl_registers_pmrswtp(bar, r);
3151 json_ctrl_registers_pmrmscl(bar, r);
3152 json_ctrl_registers_pmrmscu(bar, r);
3153
3154 json_print(r);
3155}
3156
3157static void json_ctrl_register_human(int offset, uint64_t value, struct json_object *r)
3158{
3159 char buffer[BUF_LEN320];
3160 struct json_object *array_obj = NULL((void*)0);
3161
3162 switch (offset) {
3163 case NVME_REG_CAP:
3164 array_obj = obj_create_array_obj(r, "cap");
3165 break;
3166 case NVME_REG_VS:
3167 array_obj = obj_create_array_obj(r, "vs");
3168 break;
3169 case NVME_REG_INTMS:
3170 obj_add_nprix64json_object_add_nprix64(r, "Interrupt Vector Mask Set (IVMS)", value);
3171 break;
3172 case NVME_REG_INTMC:
3173 obj_add_nprix64json_object_add_nprix64(r, "Interrupt Vector Mask Clear (IVMC)", value);
3174 break;
3175 case NVME_REG_CC:
3176 array_obj = obj_create_array_obj(r, "cc");
3177 break;
3178 case NVME_REG_CSTS:
3179 array_obj = obj_create_array_obj(r, "csts");
3180 break;
3181 case NVME_REG_NSSR:
3182 obj_add_uint64(r, "NVM Subsystem Reset Control (NSSRC)", value)json_object_object_add(r, "NVM Subsystem Reset Control (NSSRC)"
, json_object_new_uint64(value))
;
3183 break;
3184 case NVME_REG_AQA:
3185 json_registers_aqa(value, obj_create_array_obj(r, "aqa"));
3186 break;
3187 case NVME_REG_ASQ:
3188 obj_add_nprix64json_object_add_nprix64(r, "Admin Submission Queue Base (ASQB)", value);
3189 break;
3190 case NVME_REG_ACQ:
3191 obj_add_nprix64json_object_add_nprix64(r, "Admin Completion Queue Base (ACQB)", value);
3192 break;
3193 case NVME_REG_CMBLOC:
3194 json_registers_cmbloc(value, true1, obj_create_array_obj(r, "cmbloc"));
3195 break;
3196 case NVME_REG_CMBSZ:
3197 json_registers_cmbsz(value, obj_create_array_obj(r, "cmbsz"));
3198 break;
3199 case NVME_REG_BPINFO:
3200 json_registers_bpinfo(value, obj_create_array_obj(r, "bpinfo"));
3201 break;
3202 case NVME_REG_BPRSEL:
3203 json_registers_bprsel(value, obj_create_array_obj(r, "bprsel"));
3204 break;
3205 case NVME_REG_BPMBL:
3206 json_registers_bpmbl(value, obj_create_array_obj(r, "bpmbl"));
3207 break;
3208 case NVME_REG_CMBMSC:
3209 json_registers_cmbmsc(value, obj_create_array_obj(r, "cmbmsc"));
3210 break;
3211 case NVME_REG_CMBSTS:
3212 json_registers_cmbsts(value, obj_create_array_obj(r, "cmbsts"));
3213 break;
3214 case NVME_REG_CMBEBS:
3215 json_registers_cmbebs(value, obj_create_array_obj(r, "cmbebs"));
3216 break;
3217 case NVME_REG_CMBSWTP:
3218 json_registers_cmbswtp(value, obj_create_array_obj(r, "cmbswtp"));
3219 break;
3220 case NVME_REG_NSSD:
3221 json_registers_nssd(value, obj_create_array_obj(r, "nssd"));
3222 break;
3223 case NVME_REG_CRTO:
3224 array_obj = obj_create_array_obj(r, "crto");
3225 break;
3226 case NVME_REG_PMRCAP:
3227 json_registers_pmrcap(value, obj_create_array_obj(r, "pmrcap"));
3228 break;
3229 case NVME_REG_PMRCTL:
3230 json_registers_pmrctl(value, obj_create_array_obj(r, "pmrctl"));
3231 break;
3232 case NVME_REG_PMRSTS:
3233 json_registers_pmrsts(value, true1, obj_create_array_obj(r, "pmrsts"));
3234 break;
3235 case NVME_REG_PMREBS:
3236 json_registers_pmrebs(value, obj_create_array_obj(r, "pmrebs"));
3237 break;
3238 case NVME_REG_PMRSWTP:
3239 json_registers_pmrswtp(value, obj_create_array_obj(r, "pmrswtp"));
3240 break;
3241 case NVME_REG_PMRMSCL:
3242 json_registers_pmrmscl(value, obj_create_array_obj(r, "pmrmscl"));
3243 break;
3244 case NVME_REG_PMRMSCU:
3245 json_registers_pmrmscu(value, obj_create_array_obj(r, "pmrmscu"));
3246 break;
3247 default:
3248 sprintf(buffer, "%#04x (%s)", offset, nvme_register_to_string(offset));
3249 obj_add_strjson_object_add_value_string(r, "register", buffer);
3250 obj_add_nprix64json_object_add_nprix64(r, "value", value);
3251 break;
3252 }
3253
3254 if (array_obj)
3255 json_single_property_human(offset, value, array_obj);
3256}
3257
3258static void json_ctrl_register(int offset, uint64_t value)
3259{
3260 struct json_object *r;
3261 char json_str[STR_LEN100];
3262
3263 sprintf(json_str, "register: %#04x", offset);
3264 r = obj_create(json_str);
3265
3266 if (verbose_mode()) {
3267 obj_add_uint64(r, nvme_register_to_string(offset), value)json_object_object_add(r, nvme_register_to_string(offset), json_object_new_uint64
(value))
;
3268 json_ctrl_register_human(offset, value, r);
3269 } else {
3270 obj_add_strjson_object_add_value_string(r, "name", nvme_register_symbol_to_string(offset));
3271 obj_add_uint64(r, "value", value)json_object_object_add(r, "value", json_object_new_uint64(value
))
;
3272 }
3273}
3274
3275static void json_nvme_cmd_set_independent_id_ns(struct nvme_id_independent_id_ns *ns,
3276 unsigned int nsid)
3277{
3278 struct json_object *r = json_create_object()json_object_new_object();
3279
3280 obj_add_int(r, "nsfeat", ns->nsfeat)json_object_object_add(r, "nsfeat", json_object_new_int(ns->
nsfeat))
;
3281 obj_add_int(r, "nmic", ns->nmic)json_object_object_add(r, "nmic", json_object_new_int(ns->
nmic))
;
3282 obj_add_int(r, "rescap", ns->rescap)json_object_object_add(r, "rescap", json_object_new_int(ns->
rescap))
;
3283 obj_add_int(r, "fpi", ns->fpi)json_object_object_add(r, "fpi", json_object_new_int(ns->fpi
))
;
3284 obj_add_uint(r, "anagrpid", le32_to_cpu(ns->anagrpid))json_object_object_add(r, "anagrpid", json_object_new_uint64(
le32_to_cpu(ns->anagrpid)))
;
3285 obj_add_int(r, "nsattr", ns->nsattr)json_object_object_add(r, "nsattr", json_object_new_int(ns->
nsattr))
;
3286 obj_add_int(r, "nvmsetid", le16_to_cpu(ns->nvmsetid))json_object_object_add(r, "nvmsetid", json_object_new_int(le16_to_cpu
(ns->nvmsetid)))
;
3287 obj_add_int(r, "endgid", le16_to_cpu(ns->endgid))json_object_object_add(r, "endgid", json_object_new_int(le16_to_cpu
(ns->endgid)))
;
3288 obj_add_int(r, "nstat", ns->nstat)json_object_object_add(r, "nstat", json_object_new_int(ns->
nstat))
;
3289 obj_add_int(r, "kpios", ns->kpios)json_object_object_add(r, "kpios", json_object_new_int(ns->
kpios))
;
3290 obj_add_int(r, "maxkt", le16_to_cpu(ns->maxkt))json_object_object_add(r, "maxkt", json_object_new_int(le16_to_cpu
(ns->maxkt)))
;
3291 obj_add_int(r, "rgrpid", le32_to_cpu(ns->rgrpid))json_object_object_add(r, "rgrpid", json_object_new_int(le32_to_cpu
(ns->rgrpid)))
;
3292
3293 json_print(r);
3294}
3295
3296static void json_nvme_id_ns_descs(void *data, unsigned int nsid)
3297{
3298 /* large enough to hold uuid str (37) or nguid str (32) + zero byte */
3299 char json_str[STR_LEN100];
3300 char *json_str_p;
3301 union {
3302 __u8 eui64[NVME_NIDT_EUI64_LEN];
3303 __u8 nguid[NVME_NIDT_NGUID_LEN];
3304 __u8 uuid[NVME_UUID_LEN16];
3305 __u8 csi;
3306 } desc;
3307 struct json_object *r = json_create_object()json_object_new_object();
3308 struct json_object *json_array = NULL((void*)0);
3309 off_t off;
3310 int pos, len = 0;
3311 int i;
3312
3313 for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
3314 struct nvme_ns_id_desc *cur = data + pos;
3315 const char *nidt_name = NULL((void*)0);
3316
3317 if (cur->nidl == 0)
3318 break;
3319
3320 memset(json_str, 0, sizeof(json_str));
3321 json_str_p = json_str;
3322 off = pos + sizeof(*cur);
3323
3324 switch (cur->nidt) {
3325 case NVME_NIDT_EUI64:
3326 memcpy(desc.eui64, data + off, sizeof(desc.eui64));
3327 for (i = 0; i < sizeof(desc.eui64); i++)
3328 json_str_p += sprintf(json_str_p, "%02x", desc.eui64[i]);
3329 len = sizeof(desc.eui64);
3330 nidt_name = "eui64";
3331 break;
3332 case NVME_NIDT_NGUID:
3333 memcpy(desc.nguid, data + off, sizeof(desc.nguid));
3334 for (i = 0; i < sizeof(desc.nguid); i++)
3335 json_str_p += sprintf(json_str_p, "%02x", desc.nguid[i]);
3336 len = sizeof(desc.nguid);
3337 nidt_name = "nguid";
3338 break;
3339 case NVME_NIDT_UUID:
3340 memcpy(desc.uuid, data + off, sizeof(desc.uuid));
3341 libnvme_uuid_to_string(desc.uuid, json_str);
3342 len = sizeof(desc.uuid);
3343 nidt_name = "uuid";
3344 break;
3345 case NVME_NIDT_CSI:
3346 memcpy(&desc.csi, data + off, sizeof(desc.csi));
3347 sprintf(json_str_p, "%#x", desc.csi);
3348 len += sizeof(desc.csi);
3349 nidt_name = "csi";
3350 break;
3351 default:
3352 /* Skip unknown types */
3353 len = cur->nidl;
3354 break;
3355 }
3356
3357 if (nidt_name) {
3358 struct json_object *elem = json_create_object()json_object_new_object();
3359
3360 obj_add_int(elem, "loc", pos)json_object_object_add(elem, "loc", json_object_new_int(pos));
3361 obj_add_int(elem, "nidt", (int)cur->nidt)json_object_object_add(elem, "nidt", json_object_new_int((int
)cur->nidt))
;
3362 obj_add_int(elem, "nidl", (int)cur->nidl)json_object_object_add(elem, "nidl", json_object_new_int((int
)cur->nidl))
;
3363 obj_add_strjson_object_add_value_string(elem, "Type", nidt_name);
3364 obj_add_strjson_object_add_value_string(elem, nidt_name, json_str);
3365
3366 if (!json_array)
3367 json_array = json_create_array()json_object_new_array();
3368 array_add_obj(json_array, elem)json_object_array_add(json_array, elem);
3369 }
3370
3371 len += sizeof(*cur);
3372 }
3373
3374 if (json_array)
3375 obj_add_array(r, "ns-descs", json_array)json_object_object_add(r, "ns-descs", json_array);
3376
3377 json_print(r);
3378}
3379
3380static void json_nvme_id_ctrl_nvm(struct nvme_id_ctrl_nvm *ctrl_nvm)
3381{
3382 struct json_object *r = json_create_object()json_object_new_object();
3383
3384 obj_add_uint(r, "vsl", ctrl_nvm->vsl)json_object_object_add(r, "vsl", json_object_new_uint64(ctrl_nvm
->vsl))
;
3385 obj_add_uint(r, "wzsl", ctrl_nvm->wzsl)json_object_object_add(r, "wzsl", json_object_new_uint64(ctrl_nvm
->wzsl))
;
3386 obj_add_uint(r, "wusl", ctrl_nvm->wusl)json_object_object_add(r, "wusl", json_object_new_uint64(ctrl_nvm
->wusl))
;
3387 obj_add_uint(r, "dmrl", ctrl_nvm->dmrl)json_object_object_add(r, "dmrl", json_object_new_uint64(ctrl_nvm
->dmrl))
;
3388 obj_add_uint(r, "dmrsl", le32_to_cpu(ctrl_nvm->dmrsl))json_object_object_add(r, "dmrsl", json_object_new_uint64(le32_to_cpu
(ctrl_nvm->dmrsl)))
;
3389 obj_add_uint64(r, "dmsl", le64_to_cpu(ctrl_nvm->dmsl))json_object_object_add(r, "dmsl", json_object_new_uint64(le64_to_cpu
(ctrl_nvm->dmsl)))
;
3390 obj_add_uint(r, "kpiocap", ctrl_nvm->kpiocap)json_object_object_add(r, "kpiocap", json_object_new_uint64(ctrl_nvm
->kpiocap))
;
3391 obj_add_uint(r, "wzdsl", ctrl_nvm->wzdsl)json_object_object_add(r, "wzdsl", json_object_new_uint64(ctrl_nvm
->wzdsl))
;
3392 obj_add_uint(r, "aocs", le16_to_cpu(ctrl_nvm->aocs))json_object_object_add(r, "aocs", json_object_new_uint64(le16_to_cpu
(ctrl_nvm->aocs)))
;
3393
3394 if (verbose_mode()) {
3395 __u16 rsvd = (ctrl_nvm->aocs & 0xfffe) >> 1;
3396 __u8 ralbas = ctrl_nvm->aocs & 0x1;
3397
3398 if (rsvd)
3399 obj_add_uint(r, "[15:1]: Reserved", rsvd)json_object_object_add(r, "[15:1]: Reserved", json_object_new_uint64
(rsvd))
;
3400 obj_add_uint(r, "[0:0]: Reporting Allocated LBA Supported", ralbas)json_object_object_add(r, "[0:0]: Reporting Allocated LBA Supported"
, json_object_new_uint64(ralbas))
;
3401 }
3402
3403 obj_add_uint(r, "ver", le32_to_cpu(ctrl_nvm->ver))json_object_object_add(r, "ver", json_object_new_uint64(le32_to_cpu
(ctrl_nvm->ver)))
;
3404 obj_add_uint(r, "lbamqf", ctrl_nvm->lbamqf)json_object_object_add(r, "lbamqf", json_object_new_uint64(ctrl_nvm
->lbamqf))
;
3405
3406 json_print(r);
3407}
3408
3409static void json_nvme_nvm_id_ns(struct nvme_nvm_id_ns *nvm_ns,
3410 unsigned int nsid, struct nvme_id_ns *ns,
3411 unsigned int lba_index, bool_Bool cap_only)
3412
3413{
3414 struct json_object *r = json_create_object()json_object_new_object();
3415 struct json_object *elbafs = json_create_array()json_object_new_array();
3416 int i;
3417
3418 if (!cap_only)
3419 obj_add_uint64(r, "lbstm", le64_to_cpu(nvm_ns->lbstm))json_object_object_add(r, "lbstm", json_object_new_uint64(le64_to_cpu
(nvm_ns->lbstm)))
;
3420
3421 obj_add_int(r, "pic", nvm_ns->pic)json_object_object_add(r, "pic", json_object_new_int(nvm_ns->
pic))
;
3422 obj_add_int(r, "pifa", nvm_ns->pifa)json_object_object_add(r, "pifa", json_object_new_int(nvm_ns->
pifa))
;
3423
3424 obj_add_array(r, "elbafs", elbafs)json_object_object_add(r, "elbafs", elbafs);
3425
3426 for (i = 0; i <= ns->nlbaf + ns->nulbaf; i++) {
3427 struct json_object *elbaf = json_create_object()json_object_new_object();
3428 unsigned int elbaf_val = le32_to_cpu(nvm_ns->elbaf[i]);
3429
3430 obj_add_uint(elbaf, "sts", elbaf_val & 0x7F)json_object_object_add(elbaf, "sts", json_object_new_uint64(elbaf_val
& 0x7F))
;
3431 obj_add_uint(elbaf, "pif", (elbaf_val >> 7) & 0x3)json_object_object_add(elbaf, "pif", json_object_new_uint64((
elbaf_val >> 7) & 0x3))
;
3432 obj_add_uint(elbaf, "qpif", (elbaf_val >> 9) & 0xF)json_object_object_add(elbaf, "qpif", json_object_new_uint64(
(elbaf_val >> 9) & 0xF))
;
3433
3434 array_add_obj(elbafs, elbaf)json_object_array_add(elbafs, elbaf);
3435 }
3436 if (ns->nsfeat & 0x20)
3437 obj_add_int(r, "npdgl", le32_to_cpu(nvm_ns->npdgl))json_object_object_add(r, "npdgl", json_object_new_int(le32_to_cpu
(nvm_ns->npdgl)))
;
3438
3439 obj_add_uint(r, "nprg", le32_to_cpu(nvm_ns->nprg))json_object_object_add(r, "nprg", json_object_new_uint64(le32_to_cpu
(nvm_ns->nprg)))
;
3440 obj_add_uint(r, "npra", le32_to_cpu(nvm_ns->npra))json_object_object_add(r, "npra", json_object_new_uint64(le32_to_cpu
(nvm_ns->npra)))
;
3441 obj_add_uint(r, "nors", le32_to_cpu(nvm_ns->nors))json_object_object_add(r, "nors", json_object_new_uint64(le32_to_cpu
(nvm_ns->nors)))
;
3442 obj_add_uint(r, "npdal", le32_to_cpu(nvm_ns->npdal))json_object_object_add(r, "npdal", json_object_new_uint64(le32_to_cpu
(nvm_ns->npdal)))
;
3443 obj_add_uint(r, "lbapss", le32_to_cpu(nvm_ns->lbapss))json_object_object_add(r, "lbapss", json_object_new_uint64(le32_to_cpu
(nvm_ns->lbapss)))
;
3444 obj_add_uint(r, "tlbaag", le32_to_cpu(nvm_ns->tlbaag))json_object_object_add(r, "tlbaag", json_object_new_uint64(le32_to_cpu
(nvm_ns->tlbaag)))
;
3445
3446 json_print(r);
3447}
3448
3449static void json_nvme_zns_id_ctrl(struct nvme_zns_id_ctrl *ctrl)
3450{
3451 struct json_object *r = json_create_object()json_object_new_object();
3452
3453 obj_add_int(r, "zasl", ctrl->zasl)json_object_object_add(r, "zasl", json_object_new_int(ctrl->
zasl))
;
3454
3455 json_print(r);
3456}
3457
3458static void json_nvme_zns_id_ns(struct nvme_zns_id_ns *ns,
3459 struct nvme_id_ns *id_ns)
3460{
3461 struct json_object *r = json_create_object()json_object_new_object();
3462 struct json_object *lbafs = json_create_array()json_object_new_array();
3463 int i;
3464
3465 obj_add_int(r, "zoc", le16_to_cpu(ns->zoc))json_object_object_add(r, "zoc", json_object_new_int(le16_to_cpu
(ns->zoc)))
;
3466 obj_add_int(r, "ozcs", le16_to_cpu(ns->ozcs))json_object_object_add(r, "ozcs", json_object_new_int(le16_to_cpu
(ns->ozcs)))
;
3467 obj_add_uint(r, "mar", le32_to_cpu(ns->mar))json_object_object_add(r, "mar", json_object_new_uint64(le32_to_cpu
(ns->mar)))
;
3468 obj_add_uint(r, "mor", le32_to_cpu(ns->mor))json_object_object_add(r, "mor", json_object_new_uint64(le32_to_cpu
(ns->mor)))
;
3469 obj_add_uint(r, "rrl", le32_to_cpu(ns->rrl))json_object_object_add(r, "rrl", json_object_new_uint64(le32_to_cpu
(ns->rrl)))
;
3470 obj_add_uint(r, "frl", le32_to_cpu(ns->frl))json_object_object_add(r, "frl", json_object_new_uint64(le32_to_cpu
(ns->frl)))
;
3471 obj_add_uint(r, "rrl1", le32_to_cpu(ns->rrl1))json_object_object_add(r, "rrl1", json_object_new_uint64(le32_to_cpu
(ns->rrl1)))
;
3472 obj_add_uint(r, "rrl2", le32_to_cpu(ns->rrl2))json_object_object_add(r, "rrl2", json_object_new_uint64(le32_to_cpu
(ns->rrl2)))
;
3473 obj_add_uint(r, "rrl3", le32_to_cpu(ns->rrl3))json_object_object_add(r, "rrl3", json_object_new_uint64(le32_to_cpu
(ns->rrl3)))
;
3474 obj_add_uint(r, "frl1", le32_to_cpu(ns->frl1))json_object_object_add(r, "frl1", json_object_new_uint64(le32_to_cpu
(ns->frl1)))
;
3475 obj_add_uint(r, "frl2", le32_to_cpu(ns->frl2))json_object_object_add(r, "frl2", json_object_new_uint64(le32_to_cpu
(ns->frl2)))
;
3476 obj_add_uint(r, "frl3", le32_to_cpu(ns->frl3))json_object_object_add(r, "frl3", json_object_new_uint64(le32_to_cpu
(ns->frl3)))
;
3477 obj_add_uint(r, "numzrwa", le32_to_cpu(ns->numzrwa))json_object_object_add(r, "numzrwa", json_object_new_uint64(le32_to_cpu
(ns->numzrwa)))
;
3478 obj_add_int(r, "zrwafg", le16_to_cpu(ns->zrwafg))json_object_object_add(r, "zrwafg", json_object_new_int(le16_to_cpu
(ns->zrwafg)))
;
3479 obj_add_int(r, "zrwasz", le16_to_cpu(ns->zrwasz))json_object_object_add(r, "zrwasz", json_object_new_int(le16_to_cpu
(ns->zrwasz)))
;
3480 obj_add_int(r, "zrwacap", ns->zrwacap)json_object_object_add(r, "zrwacap", json_object_new_int(ns->
zrwacap))
;
3481
3482 obj_add_array(r, "lbafe", lbafs)json_object_object_add(r, "lbafe", lbafs);
3483
3484 for (i = 0; i <= id_ns->nlbaf; i++) {
3485 struct json_object *lbaf = json_create_object()json_object_new_object();
3486
3487 obj_add_uint64(lbaf, "zsze", le64_to_cpu(ns->lbafe[i].zsze))json_object_object_add(lbaf, "zsze", json_object_new_uint64(le64_to_cpu
(ns->lbafe[i].zsze)))
;
3488 obj_add_int(lbaf, "zdes", ns->lbafe[i].zdes)json_object_object_add(lbaf, "zdes", json_object_new_int(ns->
lbafe[i].zdes))
;
3489
3490 array_add_obj(lbafs, lbaf)json_object_array_add(lbafs, lbaf);
3491 }
3492
3493 json_print(r);
3494}
3495
3496static void json_nvme_list_ns(struct nvme_ns_list *ns_list)
3497{
3498 struct json_object *r = json_create_object()json_object_new_object();
3499 struct json_object *valid_attrs;
3500 struct json_object *valid = json_create_array()json_object_new_array();
3501 int i;
3502
3503 for (i = 0; i < 1024; i++) {
3504 if (ns_list->ns[i]) {
3505 valid_attrs = json_create_object()json_object_new_object();
3506 obj_add_uint(valid_attrs, "nsid", le32_to_cpu(ns_list->ns[i]))json_object_object_add(valid_attrs, "nsid", json_object_new_uint64
(le32_to_cpu(ns_list->ns[i])))
;
3507 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
3508 }
3509 }
3510
3511 obj_add_array(r, "nsid_list", valid)json_object_object_add(r, "nsid_list", valid);
3512
3513 json_print(r);
3514}
3515
3516static void json_zns_start_zone_list(__u64 nr_zones, struct json_object **zone_list)
3517{
3518 *zone_list = json_create_array()json_object_new_array();
3519}
3520
3521static void json_zns_changed(struct nvme_zns_changed_zone_log *log)
3522{
3523 struct json_object *r = json_create_object()json_object_new_object();
3524 char json_str[STR_LEN100];
3525 uint16_t nrzid = le16_to_cpu(log->nrzid);
3526 int i;
3527
3528 if (nrzid == 0xFFFF) {
3529 obj_add_result(r, "Too many zones have changed to fit into the log. Use report zones for changes.");
3530 } else {
3531 obj_add_uint(r, "nrzid", nrzid)json_object_object_add(r, "nrzid", json_object_new_uint64(nrzid
))
;
3532 for (i = 0; i < nrzid; i++) {
3533 sprintf(json_str, "zid %03d", i);
3534 obj_add_uint64(r, json_str, (uint64_t)le64_to_cpu(log->zid[i]))json_object_object_add(r, json_str, json_object_new_uint64((uint64_t
)le64_to_cpu(log->zid[i])))
;
3535 }
3536 }
3537
3538 json_print(r);
3539}
3540
3541static void json_zns_finish_zone_list(__u64 nr_zones,
3542 struct json_object *zone_list)
3543{
3544 struct json_object *r = json_create_object()json_object_new_object();
3545
3546 obj_add_uint(r, "nr_zones", nr_zones)json_object_object_add(r, "nr_zones", json_object_new_uint64(
nr_zones))
;
3547 obj_add_array(r, "zone_list", zone_list)json_object_object_add(r, "zone_list", zone_list);
3548
3549 json_print(r);
3550}
3551
3552static void json_nvme_zns_report_zones(void *report, __u32 descs,
3553 __u8 ext_size, __u32 report_size,
3554 struct json_object *zone_list)
3555{
3556 struct json_object *zone;
3557 struct json_object *ext_data;
3558 struct nvme_zone_report *r = report;
3559 struct nvme_zns_desc *desc;
3560 int i;
3561
3562 for (i = 0; i < descs; i++) {
3563 desc = (struct nvme_zns_desc *)
3564 (report + sizeof(*r) + i * (sizeof(*desc) + ext_size));
3565 zone = json_create_object()json_object_new_object();
3566
3567 obj_add_uint64(zone, "slba", le64_to_cpu(desc->zslba))json_object_object_add(zone, "slba", json_object_new_uint64(le64_to_cpu
(desc->zslba)))
;
3568 obj_add_uint64(zone, "wp", le64_to_cpu(desc->wp))json_object_object_add(zone, "wp", json_object_new_uint64(le64_to_cpu
(desc->wp)))
;
3569 obj_add_uint64(zone, "cap", le64_to_cpu(desc->zcap))json_object_object_add(zone, "cap", json_object_new_uint64(le64_to_cpu
(desc->zcap)))
;
3570 obj_add_strjson_object_add_value_string(zone, "state", nvme_zone_state_to_string(desc->zs >> 4));
3571 obj_add_strjson_object_add_value_string(zone, "type", nvme_zone_type_to_string(desc->zt));
3572 obj_add_uint(zone, "attrs", desc->za)json_object_object_add(zone, "attrs", json_object_new_uint64(
desc->za))
;
3573 obj_add_uint(zone, "attrs_info", desc->zai)json_object_object_add(zone, "attrs_info", json_object_new_uint64
(desc->zai))
;
3574
3575 if (ext_size) {
3576 if (desc->za & NVME_ZNS_ZA_ZDEV) {
3577 ext_data = json_create_array()json_object_new_array();
3578 d_json((unsigned char *)desc + sizeof(*desc),
3579 ext_size, 16, 1, ext_data);
3580 obj_add_array(zone, "ext_data", ext_data)json_object_object_add(zone, "ext_data", ext_data);
3581 } else {
3582 obj_add_strjson_object_add_value_string(zone, "ext_data", "Not valid");
3583 }
3584 }
3585
3586 array_add_obj(zone_list, zone)json_object_array_add(zone_list, zone);
3587 }
3588}
3589
3590static void json_feature_show_fields_arbitration(struct json_object *r, unsigned int result)
3591{
3592 char json_str[STR_LEN100];
3593
3594 obj_add_uint(r, "High Priority Weight (HPW)", ((result & 0xff000000) >> 24) + 1)json_object_object_add(r, "High Priority Weight (HPW)", json_object_new_uint64
(((result & 0xff000000) >> 24) + 1))
;
3595 obj_add_uint(r, "Medium Priority Weight (MPW)", ((result & 0xff0000) >> 16) + 1)json_object_object_add(r, "Medium Priority Weight (MPW)", json_object_new_uint64
(((result & 0xff0000) >> 16) + 1))
;
3596 obj_add_uint(r, "Low Priority Weight (LPW)", ((result & 0xff00) >> 8) + 1)json_object_object_add(r, "Low Priority Weight (LPW)", json_object_new_uint64
(((result & 0xff00) >> 8) + 1))
;
3597
3598 if ((result & 7) == 7)
3599 sprintf(json_str, "No limit");
3600 else
3601 sprintf(json_str, "%u", 1 << (result & 7));
3602
3603 obj_add_strjson_object_add_value_string(r, "Arbitration Burst (AB)", json_str);
3604}
3605
3606static void json_feature_show_fields_power_mgmt(struct json_object *r, unsigned int result)
3607{
3608 __u8 field = (result & 0xe0) >> 5;
3609
3610 obj_add_uint(r, "Workload Hint (WH)", field)json_object_object_add(r, "Workload Hint (WH)", json_object_new_uint64
(field))
;
3611 obj_add_strjson_object_add_value_string(r, "WH description", nvme_feature_wl_hints_to_string(field));
3612 obj_add_uint(r, "Power State (PS)", result & 0x1f)json_object_object_add(r, "Power State (PS)", json_object_new_uint64
(result & 0x1f))
;
3613}
3614
3615static void json_lba_range_entry(struct nvme_lba_range_type *lbrt, int nr_ranges,
3616 struct json_object *r)
3617{
3618 char json_str[STR_LEN100];
3619 struct json_object *lbare;
3620 int i;
3621 int j;
3622 struct json_object *lbara = json_create_array()json_object_new_array();
3623
3624 obj_add_array(r, "LBA Ranges", lbara)json_object_object_add(r, "LBA Ranges", lbara);
3625
3626 for (i = 0; i <= nr_ranges; i++) {
3627 lbare = json_create_object()json_object_new_object();
3628 array_add_obj(lbara, lbare)json_object_array_add(lbara, lbare);
3629
3630 obj_add_int(lbare, "LBA range", i)json_object_object_add(lbare, "LBA range", json_object_new_int
(i))
;
3631
3632 obj_add_uint_nx(lbare, "type", lbrt->entry[i].type);
3633
3634 obj_add_strjson_object_add_value_string(lbare, "type description",
3635 nvme_feature_lba_type_to_string(lbrt->entry[i].type));
3636
3637 obj_add_uint_nx(lbare, "attributes", lbrt->entry[i].attributes);
3638
3639 obj_add_strjson_object_add_value_string(lbare, "attribute[0]", lbrt->entry[i].attributes & 1 ?
3640 "LBA range may be overwritten" : "LBA range should not be overwritten");
3641
3642 obj_add_strjson_object_add_value_string(lbare, "attribute[1]", lbrt->entry[i].attributes & 2 ?
3643 "LBA range should be hidden from the OS/EFI/BIOS" :
3644 "LBA range should be visible from the OS/EFI/BIOS");
3645
3646 obj_add_nprix64json_object_add_nprix64(lbare, "slba", le64_to_cpu(lbrt->entry[i].slba));
3647
3648 obj_add_nprix64json_object_add_nprix64(lbare, "nlb", le64_to_cpu(lbrt->entry[i].nlb));
3649
3650 for (j = 0; j < ARRAY_SIZE(lbrt->entry[i].guid)(sizeof(lbrt->entry[i].guid) / sizeof((lbrt->entry[i].guid
)[0]))
; j++)
3651 sprintf(&json_str[j * 2], "%02x", lbrt->entry[i].guid[j]);
3652
3653 obj_add_strjson_object_add_value_string(lbare, "guid", json_str);
3654 }
3655}
3656
3657static void json_feature_show_fields_lba_range(struct json_object *r, __u8 field,
3658 unsigned char *buf)
3659{
3660 obj_add_uint(r, "Number of LBA Ranges (NUM)", field + 1)json_object_object_add(r, "Number of LBA Ranges (NUM)", json_object_new_uint64
(field + 1))
;
3661
3662 if (buf)
3663 json_lba_range_entry((struct nvme_lba_range_type *)buf, field, r);
3664}
3665
3666static void json_feature_show_fields_temp_thresh(struct json_object *r, unsigned int result)
3667{
3668 char json_str[STR_LEN100];
3669 __u8 field;
3670
3671 field = (result & 0x1c00000) >> 22;
3672 sprintf(json_str, "%s", nvme_degrees_string(field));
3673 obj_add_strjson_object_add_value_string(r, "Temperature Threshold Hysteresis (TMPTHH)", json_str);
3674
3675 sprintf(json_str, "%u K", field);
3676 obj_add_strjson_object_add_value_string(r, "TMPTHH kelvin", json_str);
3677
3678 field = (result & 0x300000) >> 20;
3679 obj_add_uint(r, "Threshold Type Select (THSEL)", field)json_object_object_add(r, "Threshold Type Select (THSEL)", json_object_new_uint64
(field))
;
3680 obj_add_strjson_object_add_value_string(r, "THSEL description", nvme_feature_temp_type_to_string(field));
3681
3682 field = (result & 0xf0000) >> 16;
3683
3684 obj_add_uint(r, "Threshold Temperature Select (TMPSEL)", field)json_object_object_add(r, "Threshold Temperature Select (TMPSEL)"
, json_object_new_uint64(field))
;
3685 obj_add_strjson_object_add_value_string(r, "TMPSEL description", nvme_feature_temp_sel_to_string(field));
3686
3687 sprintf(json_str, "%s", nvme_degrees_string(result & 0xffff));
3688 obj_add_strjson_object_add_value_string(r, "Temperature Threshold (TMPTH)", json_str);
3689
3690 sprintf(json_str, "%u K", result & 0xffff);
3691 obj_add_strjson_object_add_value_string(r, "TMPTH kelvin", json_str);
3692}
3693
3694static void json_feature_show_fields_err_recovery(struct json_object *r, unsigned int result)
3695{
3696 char json_str[STR_LEN100];
3697
3698 obj_add_strjson_object_add_value_string(r, "Deallocated or Unwritten Logical Block Error Enable (DULBE)",
3699 (result & 0x10000) >> 16 ? "Enabled" : "Disabled");
3700
3701 sprintf(json_str, "%u ms", (result & 0xffff) * 100);
3702 obj_add_strjson_object_add_value_string(r, "Time Limited Error Recovery (TLER)", json_str);
3703}
3704
3705static void json_feature_show_fields_volatile_wc(struct json_object *r, unsigned int result)
3706{
3707 obj_add_strjson_object_add_value_string(r, "Volatile Write Cache Enable (WCE)", result & 1 ? "Enabled" : "Disabled");
3708}
3709
3710static void json_feature_show_fields_num_queues(struct json_object *r, unsigned int result)
3711{
3712 obj_add_uint(r, "Number of IO Completion Queues Allocated (NCQA)",json_object_object_add(r, "Number of IO Completion Queues Allocated (NCQA)"
, json_object_new_uint64(((result & 0xffff0000) >> 16
) + 1))
3713 ((result & 0xffff0000) >> 16) + 1)json_object_object_add(r, "Number of IO Completion Queues Allocated (NCQA)"
, json_object_new_uint64(((result & 0xffff0000) >> 16
) + 1))
;
3714 obj_add_uint(r, "Number of IO Submission Queues Allocated (NSQA)", (result & 0xffff) + 1)json_object_object_add(r, "Number of IO Submission Queues Allocated (NSQA)"
, json_object_new_uint64((result & 0xffff) + 1))
;
3715}
3716
3717static void json_feature_show_fields_irq_coalesce(struct json_object *r, unsigned int result)
3718{
3719 char json_str[STR_LEN100];
3720
3721 sprintf(json_str, "%u usec", ((result & 0xff00) >> 8) * 100);
3722 obj_add_strjson_object_add_value_string(r, "Aggregation Time (TIME)", json_str);
3723
3724 obj_add_uint(r, "Aggregation Threshold (THR)", (result & 0xff) + 1)json_object_object_add(r, "Aggregation Threshold (THR)", json_object_new_uint64
((result & 0xff) + 1))
;
3725}
3726
3727static void json_feature_show_fields_irq_config(struct json_object *r, unsigned int result)
3728{
3729 obj_add_strjson_object_add_value_string(r, "Coalescing Disable (CD)", (result & 0x10000) >> 16 ? "True" : "False");
3730 obj_add_uint(r, "Interrupt Vector (IV)", result & 0xffff)json_object_object_add(r, "Interrupt Vector (IV)", json_object_new_uint64
(result & 0xffff))
;
3731}
3732
3733static void json_feature_show_fields_write_atomic(struct json_object *r, unsigned int result)
3734{
3735 obj_add_strjson_object_add_value_string(r, "Disable Normal (DN)", result & 1 ? "True" : "False");
3736}
3737
3738static void json_feature_show_fields_async_event(struct json_object *r, unsigned int result)
3739{
3740 const char *async = "Send async event";
3741 const char *no_async = "Do not send async event";
3742
3743 obj_add_strjson_object_add_value_string(r, "Discovery Log Page Change Notices", NVME_FEAT_AE_DLPCN(result)(((result) >> NVME_FEAT_AE_DLPCN_SHIFT) & NVME_FEAT_AE_DLPCN_MASK
)
?
3744 async : no_async);
3745 obj_add_strjson_object_add_value_string(r, "Host Discovery Log Page Change Notification", NVME_FEAT_AE_HDLPCN(result)(((result) >> NVME_FEAT_AE_HDLPCN_SHIFT) & NVME_FEAT_AE_HDLPCN_MASK
)
?
3746 async : no_async);
3747 obj_add_strjson_object_add_value_string(r, "AVE Discovery Log Page Change Notification", NVME_FEAT_AE_ADLPCN(result)(((result) >> NVME_FEAT_AE_ADLPCN_SHIFT) & NVME_FEAT_AE_ADLPCN_MASK
)
?
3748 async : no_async);
3749 obj_add_strjson_object_add_value_string(r, "Pull Model DDC Request Log Page Change Notification",
3750 NVME_FEAT_AE_PMDRLPCN(result)(((result) >> NVME_FEAT_AE_PMDRLPCN_SHIFT) & NVME_FEAT_AE_PMDRLPCN_MASK
)
? async : no_async);
3751 obj_add_strjson_object_add_value_string(r, "Zone Descriptor Changed Notices", NVME_FEAT_AE_ZDCN(result)(((result) >> NVME_FEAT_AE_ZDCN_SHIFT) & NVME_FEAT_AE_ZDCN_MASK
)
?
3752 async : no_async);
3753 obj_add_strjson_object_add_value_string(r, "Reachability Group", NVME_FEAT_AE_RGRP0(result)(((result) >> NVME_FEAT_AE_RGRP0_SHIFT) & NVME_FEAT_AE_RGRP0_MASK
)
? async : no_async);
3754 obj_add_strjson_object_add_value_string(r, "Reachability Association", NVME_FEAT_AE_RASSN(result)(((result) >> NVME_FEAT_AE_RASSN_SHIFT) & NVME_FEAT_AE_RASSN_MASK
)
? async : no_async);
3755 obj_add_strjson_object_add_value_string(r, "Normal NVM Subsystem Shutdown", NVME_FEAT_AE_NNSSHDN(result)(((result) >> NVME_FEAT_AE_NNSSHDN_SHIFT) & NVME_FEAT_AE_NNSSHDN_MASK
)
?
3756 async : no_async);
3757 obj_add_strjson_object_add_value_string(r, "Endurance Group Event Aggregate Log Change Notices",
3758 NVME_FEAT_AE_EGA(result)(((result) >> NVME_FEAT_AE_EGA_SHIFT) & NVME_FEAT_AE_EGA_MASK
)
? async : no_async);
3759 obj_add_strjson_object_add_value_string(r, "LBA Status Information Notices", NVME_FEAT_AE_LBAS(result)(((result) >> NVME_FEAT_AE_LBAS_SHIFT) & NVME_FEAT_AE_LBAS_MASK
)
?
3760 async : no_async);
3761 obj_add_strjson_object_add_value_string(r, "Predictable Latency Event Aggregate Log Change Notices",
3762 NVME_FEAT_AE_PLA(result)(((result) >> NVME_FEAT_AE_PLA_SHIFT) & NVME_FEAT_AE_PLA_MASK
)
? async : no_async);
3763 obj_add_strjson_object_add_value_string(r, "Asymmetric Namespace Access Change Notices", NVME_FEAT_AE_ANA(result)(((result) >> NVME_FEAT_AE_ANA_SHIFT) & NVME_FEAT_AE_ANA_MASK
)
?
3764 async : no_async);
3765 obj_add_strjson_object_add_value_string(r, "Telemetry Log Notices", NVME_FEAT_AE_TELEM(result)(((result) >> NVME_FEAT_AE_TELEM_SHIFT) & NVME_FEAT_AE_TELEM_MASK
)
? async : no_async);
3766 obj_add_strjson_object_add_value_string(r, "Firmware Activation Notices", NVME_FEAT_AE_FW(result)(((result) >> NVME_FEAT_AE_FW_SHIFT) & NVME_FEAT_AE_FW_MASK
)
? async : no_async);
3767 obj_add_strjson_object_add_value_string(r, "Namespace Attribute Notices", NVME_FEAT_AE_NAN(result)(((result) >> NVME_FEAT_AE_NAN_SHIFT) & NVME_FEAT_AE_NAN_MASK
)
? async : no_async);
3768 obj_add_strjson_object_add_value_string(r, "SMART / Health Critical Warnings", NVME_FEAT_AE_SMART(result)(((result) >> NVME_FEAT_AE_SMART_SHIFT) & NVME_FEAT_AE_SMART_MASK
)
?
3769 async : no_async);
3770}
3771
3772static void json_auto_pst(struct nvme_feat_auto_pst *apst, struct json_object *r)
3773{
3774 int i;
3775 __u64 value;
3776 char json_str[STR_LEN100];
3777 struct json_object *apsta = json_create_array()json_object_new_array();
3778 struct json_object *apste;
3779
3780 obj_add_array(r, "Auto PST Entries", apsta)json_object_object_add(r, "Auto PST Entries", apsta);
3781
3782 for (i = 0; i < ARRAY_SIZE(apst->apst_entry)(sizeof(apst->apst_entry) / sizeof((apst->apst_entry)[0
]))
; i++) {
3783 apste = json_create_object()json_object_new_object();
3784 array_add_obj(apsta, apste)json_object_array_add(apsta, apste);
3785 sprintf(json_str, "%2d", i);
3786 obj_add_strjson_object_add_value_string(apste, "entry", json_str);
3787 value = le64_to_cpu(apst->apst_entry[i]);
3788 sprintf(json_str, "%u ms", (__u32)NVME_GET(value, APST_ENTRY_ITPT)(((value) >> NVME_APST_ENTRY_ITPT_SHIFT) & NVME_APST_ENTRY_ITPT_MASK
)
);
3789 obj_add_strjson_object_add_value_string(apste, "Idle Time Prior to Transition (ITPT)", json_str);
3790 obj_add_uint(apste, "Idle Transition Power State (ITPS)",json_object_object_add(apste, "Idle Transition Power State (ITPS)"
, json_object_new_uint64((__u32)(((value) >> NVME_APST_ENTRY_ITPS_SHIFT
) & NVME_APST_ENTRY_ITPS_MASK)))
3791 (__u32)NVME_GET(value, APST_ENTRY_ITPS))json_object_object_add(apste, "Idle Transition Power State (ITPS)"
, json_object_new_uint64((__u32)(((value) >> NVME_APST_ENTRY_ITPS_SHIFT
) & NVME_APST_ENTRY_ITPS_MASK)))
;
3792 }
3793}
3794
3795static void json_feature_show_fields_auto_pst(struct json_object *r, unsigned int result,
3796 unsigned char *buf)
3797{
3798 obj_add_strjson_object_add_value_string(r, "Autonomous Power State Transition Enable (APSTE)", result & 1 ? "Enabled" :
3799 "Disabled");
3800
3801 if (buf)
3802 json_auto_pst((struct nvme_feat_auto_pst *)buf, r);
3803}
3804
3805static void json_host_mem_buffer(struct nvme_host_mem_buf_attrs *hmb, struct json_object *r)
3806{
3807 char json_str[STR_LEN100];
3808
3809 obj_add_uint(r, "Host Memory Descriptor List Entry Count (HMDLEC)", le32_to_cpu(hmb->hmdlec))json_object_object_add(r, "Host Memory Descriptor List Entry Count (HMDLEC)"
, json_object_new_uint64(le32_to_cpu(hmb->hmdlec)))
;
3810
3811 sprintf(json_str, "0x%x", le32_to_cpu(hmb->hmdlau));
3812 obj_add_strjson_object_add_value_string(r, "Host Memory Descriptor List Address (HMDLAU)", json_str);
3813
3814 sprintf(json_str, "0x%x", le32_to_cpu(hmb->hmdlal));
3815 obj_add_strjson_object_add_value_string(r, "Host Memory Descriptor List Address (HMDLAL)", json_str);
3816
3817 obj_add_uint(r, "Host Memory Buffer Size (HSIZE)", le32_to_cpu(hmb->hsize))json_object_object_add(r, "Host Memory Buffer Size (HSIZE)", json_object_new_uint64
(le32_to_cpu(hmb->hsize)))
;
3818}
3819
3820static void json_feature_show_fields_host_mem_buf(struct json_object *r, unsigned int result,
3821 unsigned char *buf)
3822{
3823 obj_add_strjson_object_add_value_string(r, "Enable Host Memory (EHM)", result & 1 ? "Enabled" : "Disabled");
3824 obj_add_strjson_object_add_value_string(r, "Host Memory Non-operational Access Restriction Enable (HMNARE)",
3825 (result & 0x00000004) ? "True" : "False");
3826 obj_add_strjson_object_add_value_string(r, "Host Memory Non-operational Access Restricted (HMNAR)",
3827 (result & 0x00000008) ? "True" : "False");
3828
3829 if (buf)
3830 json_host_mem_buffer((struct nvme_host_mem_buf_attrs *)buf, r);
3831}
3832
3833static void json_timestamp(struct json_object *r, struct nvme_timestamp *ts)
3834{
3835 obj_add_uint64(r, "timestamp", int48_to_long(ts->timestamp))json_object_object_add(r, "timestamp", json_object_new_uint64
(int48_to_long(ts->timestamp)))
;
3836 obj_add_strjson_object_add_value_string(r, "timestamp string", nvme_format_timestamp(ts->timestamp));
3837 obj_add_strjson_object_add_value_string(r, "timestamp origin", nvme_format_timestamp_origin(ts->attr));
3838 obj_add_strjson_object_add_value_string(r, "synch", nvme_format_timestamp_sync(ts->attr));
3839}
3840
3841static void json_feature_show_fields_timestamp(struct json_object *r, unsigned char *buf)
3842{
3843 if (buf)
3844 json_timestamp(r, (struct nvme_timestamp *)buf);
3845}
3846
3847static void json_feature_show_fields_kato(struct json_object *r, unsigned int result)
3848{
3849 obj_add_uint(r, "Keep Alive Timeout (KATO) in milliseconds", result)json_object_object_add(r, "Keep Alive Timeout (KATO) in milliseconds"
, json_object_new_uint64(result))
;
3850}
3851
3852static void json_feature_show_fields_hctm(struct json_object *r, unsigned int result)
3853{
3854 char json_str[STR_LEN100];
3855
3856 sprintf(json_str, "%u K", result >> 16);
3857 obj_add_strjson_object_add_value_string(r, "Thermal Management Temperature 1 (TMT1)", json_str);
3858
3859 sprintf(json_str, "%s", nvme_degrees_string(result >> 16));
3860 obj_add_strjson_object_add_value_string(r, "TMT1 celsius", json_str);
3861
3862 sprintf(json_str, "%u K", result & 0xffff);
3863 obj_add_strjson_object_add_value_string(r, "Thermal Management Temperature 2", json_str);
3864
3865 sprintf(json_str, "%s", nvme_degrees_string(result & 0xffff));
3866 obj_add_strjson_object_add_value_string(r, "TMT2 celsius", json_str);
3867}
3868
3869static void json_feature_show_fields_nopsc(struct json_object *r, unsigned int result)
3870{
3871 obj_add_strjson_object_add_value_string(r, "Non-Operational Power State Permissive Mode Enable (NOPPME)", result & 1 ?
3872 "True" : "False");
3873}
3874
3875static void json_feature_show_fields_rrl(struct json_object *r, unsigned int result)
3876{
3877 obj_add_uint(r, "Read Recovery Level (RRL)", result & 0xf)json_object_object_add(r, "Read Recovery Level (RRL)", json_object_new_uint64
(result & 0xf))
;
3878}
3879
3880static void json_plm_config(struct nvme_plm_config *plmcfg, struct json_object *r)
3881{
3882 char json_str[STR_LEN100];
3883
3884 sprintf(json_str, "%04x", le16_to_cpu(plmcfg->ee));
3885 obj_add_strjson_object_add_value_string(r, "Enable Event", json_str);
3886
3887 obj_add_uint64(r, "DTWIN Reads Threshold", le64_to_cpu(plmcfg->dtwinrt))json_object_object_add(r, "DTWIN Reads Threshold", json_object_new_uint64
(le64_to_cpu(plmcfg->dtwinrt)))
;
3888 obj_add_uint64(r, "DTWIN Writes Threshold", le64_to_cpu(plmcfg->dtwinwt))json_object_object_add(r, "DTWIN Writes Threshold", json_object_new_uint64
(le64_to_cpu(plmcfg->dtwinwt)))
;
3889 obj_add_uint64(r, "DTWIN Time Threshold", le64_to_cpu(plmcfg->dtwintt))json_object_object_add(r, "DTWIN Time Threshold", json_object_new_uint64
(le64_to_cpu(plmcfg->dtwintt)))
;
3890}
3891
3892static void json_feature_show_fields_plm_config(struct json_object *r, unsigned int result,
3893 unsigned char *buf)
3894{
3895 obj_add_strjson_object_add_value_string(r, "Predictable Latency Window Enabled", result & 1 ? "True" : "False");
3896
3897 if (buf)
3898 json_plm_config((struct nvme_plm_config *)buf, r);
3899}
3900
3901static void json_feature_show_fields_plm_window(struct json_object *r, unsigned int result)
3902{
3903 obj_add_strjson_object_add_value_string(r, "Window Select", nvme_plm_window_to_string(result));
3904}
3905
3906static void json_feature_show_fields_lba_sts_interval(struct json_object *r, unsigned int result)
3907{
3908 obj_add_uint(r, "LBA Status Information Poll Interval (LSIPI)", result >> 16)json_object_object_add(r, "LBA Status Information Poll Interval (LSIPI)"
, json_object_new_uint64(result >> 16))
;
3909 obj_add_uint(r, "LBA Status Information Report Interval (LSIRI)", result & 0xffff)json_object_object_add(r, "LBA Status Information Report Interval (LSIRI)"
, json_object_new_uint64(result & 0xffff))
;
3910}
3911
3912static void json_feature_show_fields_host_behavior(struct json_object *r, unsigned char *buf)
3913{
3914 if (buf) {
3915 struct nvme_feat_host_behavior *host = (struct nvme_feat_host_behavior *)buf;
3916
3917 obj_add_strjson_object_add_value_string(r, "Host Behavior Support", buf[0] & 0x1 ? "True" : "False");
3918 obj_add_strjson_object_add_value_string(r, "Advanced Command Retry Enable (ACRE)", host->acre ?
3919 "True" : "False");
3920 obj_add_strjson_object_add_value_string(r, "Extended Telemetry Data Area 4 Supported (ETDAS)", host->etdas ?
3921 "True" : "False");
3922 obj_add_strjson_object_add_value_string(r, "LBA Format Extension Enable (LBAFEE)", host->lbafee ?
3923 "True" : "False");
3924 obj_add_strjson_object_add_value_string(r, "Host Dispersed Namespace Support (HDISNS)", host->hdisns ?
3925 "Enabled" : "Disabled");
3926 obj_add_strjson_object_add_value_string(r, "Copy Descriptor Format 2h Enable (CDF2E)", host->cdfe & (1 << 2) ?
3927 "True" : "False");
3928 obj_add_strjson_object_add_value_string(r, "Copy Descriptor Format 3h Enable (CDF3E)", host->cdfe & (1 << 3) ?
3929 "True" : "False");
3930 obj_add_strjson_object_add_value_string(r, "Copy Descriptor Format 4h Enable (CDF4E)", host->cdfe & (1 << 4) ?
3931 "True" : "False");
3932 }
3933}
3934
3935static void json_feature_show_fields_sanitize(struct json_object *r, unsigned int result)
3936{
3937 obj_add_uint(r, "No-Deallocate Response Mode (NODRM)", result & 1)json_object_object_add(r, "No-Deallocate Response Mode (NODRM)"
, json_object_new_uint64(result & 1))
;
3938}
3939
3940static void json_feature_show_fields_endurance_evt_cfg(struct json_object *r, unsigned int result)
3941{
3942 obj_add_uint(r, "Endurance Group Identifier (ENDGID)", result & 0xffff)json_object_object_add(r, "Endurance Group Identifier (ENDGID)"
, json_object_new_uint64(result & 0xffff))
;
3943 obj_add_uint(r, "Endurance Group Critical Warnings", result >> 16 & 0xff)json_object_object_add(r, "Endurance Group Critical Warnings"
, json_object_new_uint64(result >> 16 & 0xff))
;
3944}
3945
3946static void json_feature_show_fields_iocs_profile(struct json_object *r, unsigned int result)
3947{
3948 obj_add_strjson_object_add_value_string(r, "I/O Command Set Profile", result & 0x1 ? "True" : "False");
3949}
3950
3951static void json_feature_show_fields_spinup_control(struct json_object *r, unsigned int result)
3952{
3953 obj_add_strjson_object_add_value_string(r, "Spinup control feature Enabled", result & 1 ? "True" : "False");
3954}
3955
3956static void json_feature_show_fields_power_loss_signal(struct json_object *r, unsigned int result)
3957{
3958 obj_add_strjson_object_add_value_string(r, "Power Loss Signaling Mode (PLSM)",
3959 nvme_pls_mode_to_string(NVME_GET(result, FEAT_PLS_MODE)(((result) >> NVME_FEAT_PLS_MODE_SHIFT) & NVME_FEAT_PLS_MODE_MASK
)
));
3960}
3961
3962static void json_feat_perfc_std(struct json_object *r, struct nvme_std_perf_attr *data)
3963{
3964 obj_add_strjson_object_add_value_string(r, "random 4 kib average read latency",
3965 nvme_feature_perfc_r4karl_to_string(data->r4karl));
3966 obj_add_uint_02xjson_object_add_uint_02x(r, "R4KARL", data->r4karl);
3967}
3968
3969static void json_feat_perfc_id_list(struct json_object *r, struct nvme_perf_attr_id_list *data)
3970{
3971 int i;
3972 int attri_vs;
3973 char json_str[STR_LEN100];
3974 struct json_object *paida = json_create_array()json_object_new_array();
3975 struct json_object *paide;
3976
3977 obj_add_strjson_object_add_value_string(r, "attribute type", nvme_feature_perfc_attrtyp_to_string(data->attrtyp));
3978 obj_add_uint_02xjson_object_add_uint_02x(r, "ATTRTYP", data->attrtyp);
3979 obj_add_int(r, "maximum saveable vendor specific performance attributes (MSVSPA)",json_object_object_add(r, "maximum saveable vendor specific performance attributes (MSVSPA)"
, json_object_new_int(data->msvspa))
3980 data->msvspa)json_object_object_add(r, "maximum saveable vendor specific performance attributes (MSVSPA)"
, json_object_new_int(data->msvspa))
;
3981 obj_add_int(r, "unused saveable vendor specific performance attributes (USVSPA)",json_object_object_add(r, "unused saveable vendor specific performance attributes (USVSPA)"
, json_object_new_int(data->usvspa))
3982 data->usvspa)json_object_object_add(r, "unused saveable vendor specific performance attributes (USVSPA)"
, json_object_new_int(data->usvspa))
;
3983
3984 obj_add_array(r, "performance attribute identifier list", paida)json_object_object_add(r, "performance attribute identifier list"
, paida)
;
3985 for (i = 0; i < ARRAY_SIZE(data->id_list)(sizeof(data->id_list) / sizeof((data->id_list)[0])); i++) {
3986 paide = json_create_object()json_object_new_object();
3987 array_add_obj(paida, paide)json_object_array_add(paida, paide);
3988 attri_vs = i + NVME_FEAT_PERFC_ATTRI_VS_MIN;
3989 sprintf(json_str, "performance attribute %02xh identifier (PA%02XHI)", attri_vs,
3990 attri_vs);
3991 obj_add_strjson_object_add_value_string(paide, json_str, util_uuid_to_string(data->id_list[i].id));
3992 }
3993}
3994
3995static void json_feat_perfc_vs(struct json_object *r, struct nvme_vs_perf_attr *data)
3996{
3997 obj_add_strjson_object_add_value_string(r, "performance attribute identifier (PAID)", util_uuid_to_string(data->paid));
3998 obj_add_uint(r, "attribute length (ATTRL)", data->attrl)json_object_object_add(r, "attribute length (ATTRL)", json_object_new_uint64
(data->attrl))
;
3999 obj_d(r, "vendor specific (VS)", (unsigned char *)data->vs, data->attrl, 16, 1);
4000}
4001
4002static void json_feat_perfc(struct json_object *r, enum nvme_features_id fid, unsigned int result,
4003 struct nvme_perf_characteristics *data)
4004{
4005 __u8 attri;
4006 bool_Bool rvspa;
4007
4008 nvme_feature_decode_perf_characteristics(result, &attri, &rvspa);
4009
4010 obj_add_strjson_object_add_value_string(r, "attribute index", nvme_feature_perfc_attri_to_string(attri));
4011 obj_add_uint_02xjson_object_add_uint_02x(r, "ATTRI", attri);
4012
4013 switch (attri) {
4014 case NVME_FEAT_PERFC_ATTRI_STD:
4015 json_feat_perfc_std(r, data->std_perf);
4016 break;
4017 case NVME_FEAT_PERFC_ATTRI_ID_LIST:
4018 json_feat_perfc_id_list(r, data->id_list);
4019 break;
4020 case NVME_FEAT_PERFC_ATTRI_VS_MIN ... NVME_FEAT_PERFC_ATTRI_VS_MAX:
4021 json_feat_perfc_vs(r, data->vs_perf);
4022 break;
4023 default:
4024 break;
4025 }
4026}
4027
4028static void json_host_metadata(struct json_object *r, enum nvme_features_id fid,
4029 struct nvme_host_metadata *data)
4030{
4031 struct nvme_metadata_element_desc *desc = &data->descs[0];
4032 int i;
4033 char val[VAL_LEN4096];
4034 __u16 len;
4035 char json_str[STR_LEN100];
4036 struct json_object *desca = json_create_array()json_object_new_array();
4037 struct json_object *desce;
4038
4039 obj_add_int(r, "Num Metadata Element Descriptors", data->ndesc)json_object_object_add(r, "Num Metadata Element Descriptors",
json_object_new_int(data->ndesc))
;
4040
4041 obj_add_array(r, "Metadata Element Descriptors", desca)json_object_object_add(r, "Metadata Element Descriptors", desca
)
;
4042
4043 for (i = 0; i < data->ndesc; i++) {
4044 desce = json_create_object()json_object_new_object();
4045 array_add_obj(desca, desce)json_object_array_add(desca, desce);
4046
4047 obj_add_int(desce, "Element", i)json_object_object_add(desce, "Element", json_object_new_int(
i))
;
4048
4049 sprintf(json_str, "0x%02x", desc->type);
4050 obj_add_strjson_object_add_value_string(desce, "Type", json_str);
4051
4052 obj_add_strjson_object_add_value_string(desce, "Type definition",
4053 nvme_host_metadata_type_to_string(fid, desc->type));
4054
4055 obj_add_int(desce, "Revision", desc->rev)json_object_object_add(desce, "Revision", json_object_new_int
(desc->rev))
;
4056
4057 len = le16_to_cpu(desc->len);
4058 obj_add_int(desce, "Length", len)json_object_object_add(desce, "Length", json_object_new_int(len
))
;
4059
4060 strncpy(val, (char *)desc->val, min(sizeof(val) - 1, len)((sizeof(val) - 1) > (len) ? (len) : (sizeof(val) - 1)));
4061 obj_add_strjson_object_add_value_string(desce, "Value", val);
4062
4063 desc = (struct nvme_metadata_element_desc *)&desc->val[desc->len];
4064 }
4065}
4066
4067static void json_feature_show_fields_ns_metadata(struct json_object *r, enum nvme_features_id fid,
4068 unsigned char *buf)
4069{
4070 if (buf)
4071 json_host_metadata(r, fid, (struct nvme_host_metadata *)buf);
4072}
4073
4074static void json_feature_show_fields_sw_progress(struct json_object *r, unsigned int result)
4075{
4076 obj_add_uint(r, "Pre-boot Software Load Count (PBSLC)", result & 0xff)json_object_object_add(r, "Pre-boot Software Load Count (PBSLC)"
, json_object_new_uint64(result & 0xff))
;
4077}
4078
4079static void json_feature_show_fields_host_id(struct json_object *r,
4080 unsigned int result, unsigned char *hostid)
4081{
4082 bool_Bool exhid;
4083
4084 if (!hostid)
4085 return;
4086
4087 nvme_feature_decode_host_id(result, &exhid);
4088
4089 if (exhid)
4090 obj_add_strjson_object_add_value_string(r, "Host Identifier (HOSTID)",
4091 uint128_t_to_l10n_string(le128_to_cpu(hostid)));
4092 else
4093 obj_add_uint64(r, "Host Identifier (HOSTID)",json_object_object_add(r, "Host Identifier (HOSTID)", json_object_new_uint64
(le64_to_cpu(*(__le64 *)hostid)))
4094 le64_to_cpu(*(__le64 *)hostid))json_object_object_add(r, "Host Identifier (HOSTID)", json_object_new_uint64
(le64_to_cpu(*(__le64 *)hostid)))
;
4095}
4096
4097static void json_feature_show_fields_resv_nf_mask(struct json_object *r, unsigned int result)
4098{
4099 obj_add_strjson_object_add_value_string(r, "Mask Reservation Preempted Notification (RESPRE)", (result & 8) >> 3 ?
4100 "True" : "False");
4101 obj_add_strjson_object_add_value_string(r, "Mask Reservation Released Notification (RESREL)", (result & 4) >> 2 ?
4102 "True" : "False");
4103 obj_add_strjson_object_add_value_string(r, "Mask Registration Preempted Notification (REGPRE)", (result & 2) >> 1 ?
4104 "True" : "False");
4105}
4106
4107static void json_feature_show_fields_resv_persist(struct json_object *r, unsigned int result)
4108{
4109 obj_add_strjson_object_add_value_string(r, "Persist Through Power Loss (PTPL)", result & 1 ? "True" : "False");
4110}
4111
4112static void json_feature_show_fields_write_protect(struct json_object *r, unsigned int result)
4113{
4114 obj_add_strjson_object_add_value_string(r, "Namespace Write Protect", nvme_ns_wp_cfg_to_string(result));
4115}
4116
4117static void json_feature_show_fields_fdp(struct json_object *r, unsigned int result)
4118{
4119 obj_add_strjson_object_add_value_string(r, "Flexible Direct Placement Enable (FDPE)", result & 1 ? "Yes" : "No");
4120 obj_add_uint(r, "Flexible Direct Placement Configuration Index", result >> 8 & 0xf)json_object_object_add(r, "Flexible Direct Placement Configuration Index"
, json_object_new_uint64(result >> 8 & 0xf))
;
4121}
4122
4123static void json_feature_show_fields_fdp_events(struct json_object *r, unsigned int result,
4124 unsigned char *buf)
4125{
4126 unsigned int i;
4127 struct nvme_fdp_supported_event_desc *d;
4128 char json_str[STR_LEN100];
4129
4130 for (i = 0; i < result; i++) {
4131 d = &((struct nvme_fdp_supported_event_desc *)buf)[i];
4132 sprintf(json_str, "%s", d->evta & 0x1 ? "Enabled" : "Not enabled");
4133 obj_add_strjson_object_add_value_string(r, nvme_fdp_event_to_string(d->evt), json_str);
4134 }
4135}
4136
4137static void json_feature_show_fields_bpwp(struct json_object *r, unsigned int result)
4138{
4139 __u8 field;
4140
4141 field = NVME_FEAT_BPWPC_BP0WPS(result)(((result) >> NVME_FEAT_BPWPC_BP0WPS_SHIFT) & NVME_FEAT_BPWPC_BP0WPS_MASK
)
;
4142 obj_add_strjson_object_add_value_string(r, "Boot Partition 0 Write Protection State", nvme_bpwps_to_string(field));
4143 field = NVME_FEAT_BPWPC_BP1WPS(result)(((result) >> NVME_FEAT_BPWPC_BP1WPS_SHIFT) & NVME_FEAT_BPWPC_BP1WPS_MASK
)
;
4144 obj_add_strjson_object_add_value_string(r, "Boot Partition 1 Write Protection State", nvme_bpwps_to_string(field));
4145}
4146
4147static char *get_power_and_scale(__u16 power, __u8 scale)
4148{
4149 char *str;
4150 int ret;
4151
4152 switch (scale) {
4153 case NVME_PSD_PS_NOT_REPORTED:
4154 /* Not reported for this power state */
4155 ret = asprintf(&str, "-");
4156 break;
4157 case NVME_PSD_PS_100_MICRO_WATT:
4158 /* Units of 0.0001W */
4159 ret = asprintf(&str, "%01u.%04uW", power / 10000,
4160 power % 10000);
4161 break;
4162 case NVME_PSD_PS_10_MILLI_WATT:
4163 /* Units of 0.01W */
4164 ret = asprintf(&str, "%01u.%02uW", power / 100, power % 100);
4165 break;
4166 default:
4167 ret = asprintf(&str, "reserved");
4168 break;
4169 }
4170
4171 if (ret > 0)
4172 return str;
4173
4174 return NULL((void*)0);
4175}
4176
4177static void json_feature_show_fields_power_limit(struct json_object *r,
4178 unsigned int result)
4179{
4180 __u8 field = NVME_FEAT_POWER_LIMIT_PLS(result)(((result) >> NVME_FEAT_POWER_LIMIT_PLS_SHIFT) & NVME_FEAT_POWER_LIMIT_PLS_MASK
)
;
4181
4182 __cleanup_free__attribute__((cleanup(freep))) char *k =
4183 get_power_and_scale(NVME_FEAT_POWER_LIMIT_PLV(result)(((result) >> NVME_FEAT_POWER_LIMIT_PLV_SHIFT) & NVME_FEAT_POWER_LIMIT_PLV_MASK
)
, field);
4184
4185 obj_add_strjson_object_add_value_string(r, "Power Limit Scale (PLS)",
4186 nvme_feature_power_limit_scale_to_string(field));
4187 obj_add_uint(r, "Power Limit Value (PLV)",json_object_object_add(r, "Power Limit Value (PLV)", json_object_new_uint64
((((result) >> NVME_FEAT_POWER_LIMIT_PLV_SHIFT) & NVME_FEAT_POWER_LIMIT_PLV_MASK
)))
4188 NVME_FEAT_POWER_LIMIT_PLV(result))json_object_object_add(r, "Power Limit Value (PLV)", json_object_new_uint64
((((result) >> NVME_FEAT_POWER_LIMIT_PLV_SHIFT) & NVME_FEAT_POWER_LIMIT_PLV_MASK
)))
;
4189 obj_add_strjson_object_add_value_string(r, "Power Limit", k);
4190}
4191
4192static void json_feature_show_fields_power_thresh(struct json_object *r,
4193 unsigned int result)
4194{
4195 __u8 field;
4196 __u16 ptv;
4197 __cleanup_free__attribute__((cleanup(freep))) char *k = NULL((void*)0);
4198
4199 field = NVME_FEAT_POWER_THRESH_EPT(result)(((result) >> NVME_FEAT_POWER_THRESH_EPT_SHIFT) & NVME_FEAT_POWER_THRESH_EPT_MASK
)
;
4200
4201 obj_add_strjson_object_add_value_string(r, "Enable Power Threshold (EPT)",
4202 field ? "Enabled" : "Disabled");
4203
4204 field = NVME_FEAT_POWER_THRESH_PMTS(result)(((result) >> NVME_FEAT_POWER_THRESH_PMTS_SHIFT) & NVME_FEAT_POWER_THRESH_PMTS_MASK
)
;
4205 obj_add_strjson_object_add_value_string(r, "Power Measurement Type Select (PMTS)",
4206 nvme_power_measurement_type_to_string(field));
4207
4208 field = NVME_FEAT_POWER_THRESH_PTS(result)(((result) >> NVME_FEAT_POWER_THRESH_PTS_SHIFT) & NVME_FEAT_POWER_THRESH_PTS_MASK
)
;
4209 obj_add_strjson_object_add_value_string(r, "Power Threshold Scale (PTS)",
4210 nvme_feature_power_limit_scale_to_string(field));
4211
4212 ptv = NVME_FEAT_POWER_THRESH_PTV(result)(((result) >> NVME_FEAT_POWER_THRESH_PTV_SHIFT) & NVME_FEAT_POWER_THRESH_PTV_MASK
)
;
4213
4214 obj_add_uint(r, "Power Threshold Value (PTV)", ptv)json_object_object_add(r, "Power Threshold Value (PTV)", json_object_new_uint64
(ptv))
;
4215
4216 k = get_power_and_scale(ptv, NVME_FEAT_POWER_THRESH_PTS(result)(((result) >> NVME_FEAT_POWER_THRESH_PTS_SHIFT) & NVME_FEAT_POWER_THRESH_PTS_MASK
)
);
4217 obj_add_strjson_object_add_value_string(r, "Power Threshold", k);
4218}
4219
4220static void json_feature_show_fields_power_meas(struct json_object *r,
4221 unsigned int result)
4222{
4223 __u8 field;
4224 __u16 smt;
4225
4226 field = NVME_FEAT_POWER_MEAS_ACT(result)(((result) >> NVME_FEAT_POWER_MEAS_ACT_SHIFT) & NVME_FEAT_POWER_MEAS_ACT_MASK
)
;
4227 obj_add_strjson_object_add_value_string(r, "Action (ACT)",
4228 nvme_power_measurement_action_to_string(field));
4229
4230 field = NVME_FEAT_POWER_MEAS_PMTS(result)(((result) >> NVME_FEAT_POWER_MEAS_PMTS_SHIFT) & NVME_FEAT_POWER_MEAS_PMTS_MASK
)
;
4231 obj_add_strjson_object_add_value_string(r, "Power Measurement Type Select (PMTS)",
4232 nvme_power_measurement_type_to_string(field));
4233
4234 smt = NVME_FEAT_POWER_MEAS_SMT(result)(((result) >> NVME_FEAT_POWER_MEAS_SMT_SHIFT) & NVME_FEAT_POWER_MEAS_SMT_MASK
)
;
4235
4236 obj_add_uint(r, "Stop Measurement Time (SMT)", smt)json_object_object_add(r, "Stop Measurement Time (SMT)", json_object_new_uint64
(smt))
;
4237}
4238
4239static void json_feature_show(enum nvme_features_id fid, int sel,
4240 unsigned int result, void *buf, __u32 data_len)
4241{
4242 struct json_object *r;
4243 char json_str[STR_LEN100];
4244
4245 sprintf(json_str, "feature: %#0*x", fid ? 4 : 2, fid);
4246 r = obj_create(json_str);
4247
4248 obj_add_strjson_object_add_value_string(r, "name", nvme_feature_to_string(fid));
4249
4250 sprintf(json_str, "%#0*x", result ? 10 : 8, result);
4251 obj_add_strjson_object_add_value_string(r, nvme_select_to_string(sel), json_str);
4252
4253 obj_print(r);
4254
4255 if (NVME_CHECK(sel, GET_FEATURES_SEL, SUPPORTED)((sel) == NVME_GET_FEATURES_SEL_SUPPORTED))
4256 json_select_result(fid, result);
4257 else
4258 json_feature_show_fields(fid, result, buf);
4259}
4260
4261static void json_feature_show_fields(enum nvme_features_id fid, unsigned int result,
4262 unsigned char *buf)
4263{
4264 struct json_object *r;
4265 char json_str[STR_LEN100];
4266
4267 sprintf(json_str, "Feature: %#0*x", fid ? 4 : 2, fid);
4268 r = obj_create(json_str);
4269
4270 switch (fid) {
4271 case NVME_FEAT_FID_ARBITRATION:
4272 json_feature_show_fields_arbitration(r, result);
4273 break;
4274 case NVME_FEAT_FID_POWER_MGMT:
4275 json_feature_show_fields_power_mgmt(r, result);
4276 break;
4277 case NVME_FEAT_FID_LBA_RANGE:
4278 json_feature_show_fields_lba_range(r, result & 0x3f, buf);
4279 break;
4280 case NVME_FEAT_FID_TEMP_THRESH:
4281 json_feature_show_fields_temp_thresh(r, result);
4282 break;
4283 case NVME_FEAT_FID_ERR_RECOVERY:
4284 json_feature_show_fields_err_recovery(r, result);
4285 break;
4286 case NVME_FEAT_FID_VOLATILE_WC:
4287 json_feature_show_fields_volatile_wc(r, result);
4288 break;
4289 case NVME_FEAT_FID_NUM_QUEUES:
4290 json_feature_show_fields_num_queues(r, result);
4291 break;
4292 case NVME_FEAT_FID_IRQ_COALESCE:
4293 json_feature_show_fields_irq_coalesce(r, result);
4294 break;
4295 case NVME_FEAT_FID_IRQ_CONFIG:
4296 json_feature_show_fields_irq_config(r, result);
4297 break;
4298 case NVME_FEAT_FID_WRITE_ATOMIC:
4299 json_feature_show_fields_write_atomic(r, result);
4300 break;
4301 case NVME_FEAT_FID_ASYNC_EVENT:
4302 json_feature_show_fields_async_event(r, result);
4303 break;
4304 case NVME_FEAT_FID_AUTO_PST:
4305 json_feature_show_fields_auto_pst(r, result, buf);
4306 break;
4307 case NVME_FEAT_FID_HOST_MEM_BUF:
4308 json_feature_show_fields_host_mem_buf(r, result, buf);
4309 break;
4310 case NVME_FEAT_FID_TIMESTAMP:
4311 json_feature_show_fields_timestamp(r, buf);
4312 break;
4313 case NVME_FEAT_FID_KATO:
4314 json_feature_show_fields_kato(r, result);
4315 break;
4316 case NVME_FEAT_FID_HCTM:
4317 json_feature_show_fields_hctm(r, result);
4318 break;
4319 case NVME_FEAT_FID_NOPSC:
4320 json_feature_show_fields_nopsc(r, result);
4321 break;
4322 case NVME_FEAT_FID_RRL:
4323 json_feature_show_fields_rrl(r, result);
4324 break;
4325 case NVME_FEAT_FID_PLM_CONFIG:
4326 json_feature_show_fields_plm_config(r, result, buf);
4327 break;
4328 case NVME_FEAT_FID_PLM_WINDOW:
4329 json_feature_show_fields_plm_window(r, result);
4330 break;
4331 case NVME_FEAT_FID_LBA_STS_INTERVAL:
4332 json_feature_show_fields_lba_sts_interval(r, result);
4333 break;
4334 case NVME_FEAT_FID_HOST_BEHAVIOR:
4335 json_feature_show_fields_host_behavior(r, buf);
4336 break;
4337 case NVME_FEAT_FID_SANITIZE:
4338 json_feature_show_fields_sanitize(r, result);
4339 break;
4340 case NVME_FEAT_FID_ENDURANCE_EVT_CFG:
4341 json_feature_show_fields_endurance_evt_cfg(r, result);
4342 break;
4343 case NVME_FEAT_FID_IOCS_PROFILE:
4344 json_feature_show_fields_iocs_profile(r, result);
4345 break;
4346 case NVME_FEAT_FID_SPINUP_CONTROL:
4347 json_feature_show_fields_spinup_control(r, result);
4348 break;
4349 case NVME_FEAT_FID_POWER_LOSS_SIGNAL:
4350 json_feature_show_fields_power_loss_signal(r, result);
4351 break;
4352 case NVME_FEAT_FID_PERF_CHARACTERISTICS:
4353 json_feat_perfc(r, fid, result, (struct nvme_perf_characteristics *)buf);
4354 break;
4355 case NVME_FEAT_FID_ENH_CTRL_METADATA:
4356 case NVME_FEAT_FID_CTRL_METADATA:
4357 case NVME_FEAT_FID_NS_METADATA:
4358 json_feature_show_fields_ns_metadata(r, fid, buf);
4359 break;
4360 case NVME_FEAT_FID_SW_PROGRESS:
4361 json_feature_show_fields_sw_progress(r, result);
4362 break;
4363 case NVME_FEAT_FID_HOST_ID:
4364 json_feature_show_fields_host_id(r, result, buf);
4365 break;
4366 case NVME_FEAT_FID_RESV_NF_MASK:
4367 json_feature_show_fields_resv_nf_mask(r, result);
4368 break;
4369 case NVME_FEAT_FID_RESV_PERSIST:
4370 json_feature_show_fields_resv_persist(r, result);
4371 break;
4372 case NVME_FEAT_FID_WRITE_PROTECT:
4373 json_feature_show_fields_write_protect(r, result);
4374 break;
4375 case NVME_FEAT_FID_FDP:
4376 json_feature_show_fields_fdp(r, result);
4377 break;
4378 case NVME_FEAT_FID_FDP_EVENTS:
4379 json_feature_show_fields_fdp_events(r, result, buf);
4380 break;
4381 case NVME_FEAT_FID_BP_WRITE_PROTECT:
4382 json_feature_show_fields_bpwp(r, result);
4383 break;
4384 case NVME_FEAT_FID_POWER_LIMIT:
4385 json_feature_show_fields_power_limit(r, result);
4386 break;
4387 case NVME_FEAT_FID_POWER_THRESH:
4388 json_feature_show_fields_power_thresh(r, result);
4389 break;
4390 case NVME_FEAT_FID_POWER_MEASUREMENT:
4391 json_feature_show_fields_power_meas(r, result);
4392 break;
4393 default:
4394 break;
4395 }
4396
4397 obj_print(r);
4398}
4399
4400void json_id_ctrl_rpmbs(__le32 ctrl_rpmbs)
4401{
4402 struct json_object *r = json_create_object()json_object_new_object();
4403 __u32 rpmbs = le32_to_cpu(ctrl_rpmbs);
4404 __u32 asz = (rpmbs & 0xFF000000) >> 24;
4405 __u32 tsz = (rpmbs & 0xFF0000) >> 16;
4406 __u32 rsvd = (rpmbs & 0xFFC0) >> 6;
4407 __u32 auth = (rpmbs & 0x38) >> 3;
4408 __u32 rpmb = rpmbs & 7;
4409
4410 obj_add_uint_nx(r, "[31:24]: Access Size", asz);
4411 obj_add_uint_nx(r, "[23:16]: Total Size", tsz);
4412
4413 if (rsvd)
4414 obj_add_uint_nx(r, "[15:6]: Reserved", rsvd);
4415
4416 obj_add_uint_nx(r, "[5:3]: Authentication Method", auth);
4417 obj_add_uint_nx(r, "[2:0]: Number of RPMB Units", rpmb);
4418
4419 json_print(r);
4420}
4421
4422static void json_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges)
4423{
4424 struct json_object *r = json_create_object()json_object_new_object();
4425
4426 json_lba_range_entry(lbrt, nr_ranges, r);
4427
4428 json_print(r);
4429}
4430
4431static void json_lba_status_info(__u64 result)
4432{
4433 struct json_object *r = json_create_object()json_object_new_object();
4434
4435 obj_add_uint(r, "LBA Status Information Poll Interval (LSIPI)", (result >> 16) & 0xffff)json_object_object_add(r, "LBA Status Information Poll Interval (LSIPI)"
, json_object_new_uint64((result >> 16) & 0xffff))
;
4436 obj_add_uint(r, "LBA Status Information Report Interval (LSIRI)", result & 0xffff)json_object_object_add(r, "LBA Status Information Report Interval (LSIRI)"
, json_object_new_uint64(result & 0xffff))
;
4437
4438 json_print(r);
4439}
4440
4441void json_d(unsigned char *buf, int len, int width, int group)
4442{
4443 struct json_object *r = json_r ? json_r : json_create_object()json_object_new_object();
4444 char json_str[STR_LEN100];
4445
4446 sprintf(json_str, "data: buf=%p len=%d width=%d group=%d", buf, len, width, group);
4447 obj_d(r, json_str, buf, len, width, group);
4448
4449 obj_print(r);
4450}
4451
4452static void json_nvme_list_ctrl(struct nvme_ctrl_list *ctrl_list)
4453{
4454 __u16 num = le16_to_cpu(ctrl_list->num);
4455 struct json_object *r = json_create_object()json_object_new_object();
4456 struct json_object *valid_attrs;
4457 struct json_object *valid = json_create_array()json_object_new_array();
4458 int i;
4459
4460 obj_add_uint(r, "num_ctrl", le16_to_cpu(ctrl_list->num))json_object_object_add(r, "num_ctrl", json_object_new_uint64(
le16_to_cpu(ctrl_list->num)))
;
4461
4462 for (i = 0; i < min(num, 2047)((num) > (2047) ? (2047) : (num)); i++) {
4463 valid_attrs = json_create_object()json_object_new_object();
4464 obj_add_uint(valid_attrs, "ctrl_id", le16_to_cpu(ctrl_list->identifier[i]))json_object_object_add(valid_attrs, "ctrl_id", json_object_new_uint64
(le16_to_cpu(ctrl_list->identifier[i])))
;
4465 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
4466 }
4467
4468 obj_add_array(r, "ctrl_list", valid)json_object_object_add(r, "ctrl_list", valid);
4469
4470 json_print(r);
4471}
4472
4473static void json_nvme_id_nvmset(struct nvme_id_nvmset_list *nvmset,
4474 unsigned int nvmeset_id)
4475{
4476 __u32 nent = nvmset->nid;
4477 struct json_object *entries = json_create_array()json_object_new_array();
4478 struct json_object *r = json_create_object()json_object_new_object();
4479 int i;
4480
4481 obj_add_int(r, "nid", nent)json_object_object_add(r, "nid", json_object_new_int(nent));
4482
4483 for (i = 0; i < nent; i++) {
4484 struct json_object *entry = json_create_object()json_object_new_object();
4485
4486 obj_add_int(entry, "nvmset_id", le16_to_cpu(nvmset->ent[i].nvmsetid))json_object_object_add(entry, "nvmset_id", json_object_new_int
(le16_to_cpu(nvmset->ent[i].nvmsetid)))
;
4487 obj_add_int(entry, "endurance_group_id", le16_to_cpu(nvmset->ent[i].endgid))json_object_object_add(entry, "endurance_group_id", json_object_new_int
(le16_to_cpu(nvmset->ent[i].endgid)))
;
4488 obj_add_uint(entry, "random_4k_read_typical", le32_to_cpu(nvmset->ent[i].rr4kt))json_object_object_add(entry, "random_4k_read_typical", json_object_new_uint64
(le32_to_cpu(nvmset->ent[i].rr4kt)))
;
4489 obj_add_uint(entry, "optimal_write_size", le32_to_cpu(nvmset->ent[i].ows))json_object_object_add(entry, "optimal_write_size", json_object_new_uint64
(le32_to_cpu(nvmset->ent[i].ows)))
;
4490 obj_add_uint128(entry, "total_nvmset_cap", le128_to_cpu(nvmset->ent[i].tnvmsetcap))json_object_object_add(entry, "total_nvmset_cap", util_json_object_new_uint128
(le128_to_cpu(nvmset->ent[i].tnvmsetcap)))
;
4491 obj_add_uint128(entry, "unalloc_nvmset_cap",json_object_object_add(entry, "unalloc_nvmset_cap", util_json_object_new_uint128
(le128_to_cpu(nvmset->ent[i].unvmsetcap)))
4492 le128_to_cpu(nvmset->ent[i].unvmsetcap))json_object_object_add(entry, "unalloc_nvmset_cap", util_json_object_new_uint128
(le128_to_cpu(nvmset->ent[i].unvmsetcap)))
;
4493 array_add_obj(entries, entry)json_object_array_add(entries, entry);
4494 }
4495
4496 obj_add_array(r, "NVMSet", entries)json_object_object_add(r, "NVMSet", entries);
4497
4498 json_print(r);
4499}
4500
4501static void json_nvme_primary_ctrl_cap(const struct nvme_primary_ctrl_cap *caps)
4502{
4503 struct json_object *r = json_create_object()json_object_new_object();
4504
4505 obj_add_uint(r, "cntlid", le16_to_cpu(caps->cntlid))json_object_object_add(r, "cntlid", json_object_new_uint64(le16_to_cpu
(caps->cntlid)))
;
4506 obj_add_uint(r, "portid", le16_to_cpu(caps->portid))json_object_object_add(r, "portid", json_object_new_uint64(le16_to_cpu
(caps->portid)))
;
4507 obj_add_uint(r, "crt", caps->crt)json_object_object_add(r, "crt", json_object_new_uint64(caps->
crt))
;
4508
4509 obj_add_uint(r, "vqfrt", le32_to_cpu(caps->vqfrt))json_object_object_add(r, "vqfrt", json_object_new_uint64(le32_to_cpu
(caps->vqfrt)))
;
4510 obj_add_uint(r, "vqrfa", le32_to_cpu(caps->vqrfa))json_object_object_add(r, "vqrfa", json_object_new_uint64(le32_to_cpu
(caps->vqrfa)))
;
4511 obj_add_int(r, "vqrfap", le16_to_cpu(caps->vqrfap))json_object_object_add(r, "vqrfap", json_object_new_int(le16_to_cpu
(caps->vqrfap)))
;
4512 obj_add_int(r, "vqprt", le16_to_cpu(caps->vqprt))json_object_object_add(r, "vqprt", json_object_new_int(le16_to_cpu
(caps->vqprt)))
;
4513 obj_add_int(r, "vqfrsm", le16_to_cpu(caps->vqfrsm))json_object_object_add(r, "vqfrsm", json_object_new_int(le16_to_cpu
(caps->vqfrsm)))
;
4514 obj_add_int(r, "vqgran", le16_to_cpu(caps->vqgran))json_object_object_add(r, "vqgran", json_object_new_int(le16_to_cpu
(caps->vqgran)))
;
4515
4516 obj_add_uint(r, "vifrt", le32_to_cpu(caps->vifrt))json_object_object_add(r, "vifrt", json_object_new_uint64(le32_to_cpu
(caps->vifrt)))
;
4517 obj_add_uint(r, "virfa", le32_to_cpu(caps->virfa))json_object_object_add(r, "virfa", json_object_new_uint64(le32_to_cpu
(caps->virfa)))
;
4518 obj_add_int(r, "virfap", le16_to_cpu(caps->virfap))json_object_object_add(r, "virfap", json_object_new_int(le16_to_cpu
(caps->virfap)))
;
4519 obj_add_int(r, "viprt", le16_to_cpu(caps->viprt))json_object_object_add(r, "viprt", json_object_new_int(le16_to_cpu
(caps->viprt)))
;
4520 obj_add_int(r, "vifrsm", le16_to_cpu(caps->vifrsm))json_object_object_add(r, "vifrsm", json_object_new_int(le16_to_cpu
(caps->vifrsm)))
;
4521 obj_add_int(r, "vigran", le16_to_cpu(caps->vigran))json_object_object_add(r, "vigran", json_object_new_int(le16_to_cpu
(caps->vigran)))
;
4522
4523 json_print(r);
4524}
4525
4526static void json_nvme_list_secondary_ctrl(const struct nvme_secondary_ctrl_list *sc_list,
4527 __u32 count)
4528{
4529 const struct nvme_secondary_ctrl *sc_entry = &sc_list->sc_entry[0];
4530 __u32 nent = min(sc_list->num, count)((sc_list->num) > (count) ? (count) : (sc_list->num)
)
;
4531 struct json_object *entries = json_create_array()json_object_new_array();
4532 struct json_object *r = json_create_object()json_object_new_object();
4533 int i;
4534
4535 obj_add_int(r, "num", nent)json_object_object_add(r, "num", json_object_new_int(nent));
4536
4537 for (i = 0; i < nent; i++) {
4538 struct json_object *entry = json_create_object()json_object_new_object();
4539
4540 obj_add_int(entry, "secondary-controller-identifier",json_object_object_add(entry, "secondary-controller-identifier"
, json_object_new_int(le16_to_cpu(sc_entry[i].scid)))
4541 le16_to_cpu(sc_entry[i].scid))json_object_object_add(entry, "secondary-controller-identifier"
, json_object_new_int(le16_to_cpu(sc_entry[i].scid)))
;
4542 obj_add_int(entry, "primary-controller-identifier", le16_to_cpu(sc_entry[i].pcid))json_object_object_add(entry, "primary-controller-identifier"
, json_object_new_int(le16_to_cpu(sc_entry[i].pcid)))
;
4543 obj_add_int(entry, "secondary-controller-state", sc_entry[i].scs)json_object_object_add(entry, "secondary-controller-state", json_object_new_int
(sc_entry[i].scs))
;
4544 obj_add_int(entry, "virtual-function-number", le16_to_cpu(sc_entry[i].vfn))json_object_object_add(entry, "virtual-function-number", json_object_new_int
(le16_to_cpu(sc_entry[i].vfn)))
;
4545 obj_add_int(entry, "num-virtual-queues", le16_to_cpu(sc_entry[i].nvq))json_object_object_add(entry, "num-virtual-queues", json_object_new_int
(le16_to_cpu(sc_entry[i].nvq)))
;
4546 obj_add_int(entry, "num-virtual-interrupts", le16_to_cpu(sc_entry[i].nvi))json_object_object_add(entry, "num-virtual-interrupts", json_object_new_int
(le16_to_cpu(sc_entry[i].nvi)))
;
4547 array_add_obj(entries, entry)json_object_array_add(entries, entry);
4548 }
4549
4550 obj_add_array(r, "secondary-controllers", entries)json_object_object_add(r, "secondary-controllers", entries);
4551
4552 json_print(r);
4553}
4554
4555static void json_nvme_id_ns_granularity_list(
4556 const struct nvme_id_ns_granularity_list *glist)
4557{
4558 int i;
4559 struct json_object *r = json_create_object()json_object_new_object();
4560 struct json_object *entries = json_create_array()json_object_new_array();
4561
4562 obj_add_int(r, "attributes", glist->attributes)json_object_object_add(r, "attributes", json_object_new_int(glist
->attributes))
;
4563 obj_add_int(r, "num-descriptors", glist->num_descriptors)json_object_object_add(r, "num-descriptors", json_object_new_int
(glist->num_descriptors))
;
4564
4565 for (i = 0; i <= glist->num_descriptors; i++) {
4566 struct json_object *entry = json_create_object()json_object_new_object();
4567
4568 obj_add_uint64(entry, "namespace-size-granularity",json_object_object_add(entry, "namespace-size-granularity", json_object_new_uint64
(le64_to_cpu(glist->entry[i].nszegran)))
4569 le64_to_cpu(glist->entry[i].nszegran))json_object_object_add(entry, "namespace-size-granularity", json_object_new_uint64
(le64_to_cpu(glist->entry[i].nszegran)))
;
4570 obj_add_uint64(entry, "namespace-capacity-granularity",json_object_object_add(entry, "namespace-capacity-granularity"
, json_object_new_uint64(le64_to_cpu(glist->entry[i].ncapgran
)))
4571 le64_to_cpu(glist->entry[i].ncapgran))json_object_object_add(entry, "namespace-capacity-granularity"
, json_object_new_uint64(le64_to_cpu(glist->entry[i].ncapgran
)))
;
4572 array_add_obj(entries, entry)json_object_array_add(entries, entry);
4573 }
4574
4575 obj_add_array(r, "namespace-granularity-list", entries)json_object_object_add(r, "namespace-granularity-list", entries
)
;
4576
4577 json_print(r);
4578}
4579
4580static void json_nvme_id_uuid_list(const struct nvme_id_uuid_list *uuid_list)
4581{
4582 struct json_object *r = json_create_object()json_object_new_object();
4583 struct json_object *entries = json_create_array()json_object_new_array();
4584 int i;
4585
4586 for (i = 0; i < NVME_ID_UUID_LIST_MAX; i++) {
4587 __u8 uuid[NVME_UUID_LEN16];
4588 struct json_object *entry = json_create_object()json_object_new_object();
4589
4590 /* The list is terminated by a zero UUID value */
4591 if (memcmp(uuid_list->entry[i].uuid, zero_uuid, sizeof(zero_uuid)) == 0)
4592 break;
4593 memcpy(&uuid, uuid_list->entry[i].uuid, sizeof(uuid));
4594 obj_add_int(entry, "association",json_object_object_add(entry, "association", json_object_new_int
(uuid_list->entry[i].header & 0x3))
4595 uuid_list->entry[i].header & 0x3)json_object_object_add(entry, "association", json_object_new_int
(uuid_list->entry[i].header & 0x3))
;
4596 obj_add_strjson_object_add_value_string(entry, "uuid",
4597 util_uuid_to_string(uuid));
4598 array_add_obj(entries, entry)json_object_array_add(entries, entry);
4599 }
4600
4601 obj_add_array(r, "UUID-list", entries)json_object_object_add(r, "UUID-list", entries);
4602
4603 json_print(r);
4604}
4605
4606static void json_id_domain_list(struct nvme_id_domain_list *id_dom)
4607{
4608 struct json_object *r = json_create_object()json_object_new_object();
4609 struct json_object *entries = json_create_array()json_object_new_array();
4610 struct json_object *entry;
4611 int i;
4612 nvme_uint128_t dom_cap, unalloc_dom_cap, max_egrp_dom_cap;
4613
4614 obj_add_uint(r, "num_dom_entries", id_dom->num)json_object_object_add(r, "num_dom_entries", json_object_new_uint64
(id_dom->num))
;
4615
4616 for (i = 0; i < id_dom->num; i++) {
4617 entry = json_create_object()json_object_new_object();
4618 dom_cap = le128_to_cpu(id_dom->domain_attr[i].dom_cap);
4619 unalloc_dom_cap = le128_to_cpu(id_dom->domain_attr[i].unalloc_dom_cap);
4620 max_egrp_dom_cap = le128_to_cpu(id_dom->domain_attr[i].max_egrp_dom_cap);
4621
4622 obj_add_uint(entry, "dom_id", le16_to_cpu(id_dom->domain_attr[i].dom_id))json_object_object_add(entry, "dom_id", json_object_new_uint64
(le16_to_cpu(id_dom->domain_attr[i].dom_id)))
;
4623 obj_add_uint128(entry, "dom_cap", dom_cap)json_object_object_add(entry, "dom_cap", util_json_object_new_uint128
(dom_cap))
;
4624 obj_add_uint128(entry, "unalloc_dom_cap", unalloc_dom_cap)json_object_object_add(entry, "unalloc_dom_cap", util_json_object_new_uint128
(unalloc_dom_cap))
;
4625 obj_add_uint128(entry, "max_egrp_dom_cap", max_egrp_dom_cap)json_object_object_add(entry, "max_egrp_dom_cap", util_json_object_new_uint128
(max_egrp_dom_cap))
;
4626
4627 array_add_obj(entries, entry)json_object_array_add(entries, entry);
4628 }
4629
4630 obj_add_array(r, "domain_list", entries)json_object_object_add(r, "domain_list", entries);
4631
4632 json_print(r);
4633}
4634
4635static void json_nvme_endurance_group_list(struct nvme_id_endurance_group_list *endgrp_list)
4636{
4637 struct json_object *r = json_create_object()json_object_new_object();
4638 struct json_object *valid_attrs;
4639 struct json_object *valid = json_create_array()json_object_new_array();
4640 int i;
4641
4642 obj_add_uint(r, "num_endgrp_id", le16_to_cpu(endgrp_list->num))json_object_object_add(r, "num_endgrp_id", json_object_new_uint64
(le16_to_cpu(endgrp_list->num)))
;
4643
4644 for (i = 0; i < min(le16_to_cpu(endgrp_list->num), 2047)((le16_to_cpu(endgrp_list->num)) > (2047) ? (2047) : (le16_to_cpu
(endgrp_list->num)))
; i++) {
4645 valid_attrs = json_create_object()json_object_new_object();
4646 obj_add_uint(valid_attrs, "endgrp_id", le16_to_cpu(endgrp_list->identifier[i]))json_object_object_add(valid_attrs, "endgrp_id", json_object_new_uint64
(le16_to_cpu(endgrp_list->identifier[i])))
;
4647 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
4648 }
4649
4650 obj_add_array(r, "endgrp_list", valid)json_object_object_add(r, "endgrp_list", valid);
4651
4652 json_print(r);
4653}
4654
4655static void json_support_log(struct nvme_supported_log_pages *support_log,
4656 const char *devname)
4657{
4658 struct json_object *r = json_create_object()json_object_new_object();
4659 struct json_object *valid = json_create_array()json_object_new_array();
4660 struct json_object *valid_attrs;
4661 unsigned int lid;
4662 char key[128];
4663 __u32 support;
4664
4665 for (lid = 0; lid < 256; lid++) {
4666 support = le32_to_cpu(support_log->lid_support[lid]);
4667 if (support & 0x1) {
4668 valid_attrs = json_create_object()json_object_new_object();
4669 sprintf(key, "lid_0x%x ", lid);
4670 obj_add_uint(valid_attrs, key, support)json_object_object_add(valid_attrs, key, json_object_new_uint64
(support))
;
4671 array_add_obj(valid, valid_attrs)json_object_array_add(valid, valid_attrs);
4672 }
4673 }
4674
4675 obj_add_array(r, "supported_logs", valid)json_object_object_add(r, "supported_logs", valid);
4676
4677 json_print(r);
4678}
4679
4680static void json_print_detail_list_multipath(libnvme_subsystem_t s,
4681 struct json_object *jss)
4682{
4683 libnvme_ns_t n;
4684 libnvme_path_t p;
4685 struct json_object *jnss = json_create_array()json_object_new_array();
4686
4687 libnvme_subsystem_for_each_ns(s, n)for (n = libnvme_subsystem_first_ns(s); n != ((void*)0); n = libnvme_subsystem_next_ns
(s, n))
{
4688 struct json_object *jns = json_create_object()json_object_new_object();
4689 struct json_object *jpaths = json_create_array()json_object_new_array();
4690
4691 int lba = libnvme_ns_get_lba_size(n);
4692 uint64_t nsze = libnvme_ns_get_lba_count(n) * lba;
4693 uint64_t nuse = libnvme_ns_get_lba_util(n) * lba;
4694
4695 obj_add_strjson_object_add_value_string(jns, "NameSpace", libnvme_ns_get_name(n));
4696 obj_add_strjson_object_add_value_string(jns, "Generic", libnvme_ns_get_generic_name(n));
4697 obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n))json_object_object_add(jns, "NSID", json_object_new_int(libnvme_ns_get_nsid
(n)))
;
4698 obj_add_uint64(jns, "UsedBytes", nuse)json_object_object_add(jns, "UsedBytes", json_object_new_uint64
(nuse))
;
4699 obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n))json_object_object_add(jns, "MaximumLBA", json_object_new_uint64
(libnvme_ns_get_lba_count(n)))
;
4700 obj_add_uint64(jns, "PhysicalSize", nsze)json_object_object_add(jns, "PhysicalSize", json_object_new_uint64
(nsze))
;
4701 obj_add_int(jns, "SectorSize", lba)json_object_object_add(jns, "SectorSize", json_object_new_int
(lba))
;
4702
4703 libnvme_namespace_for_each_path(n, p)for (p = libnvme_namespace_first_path(n); p != ((void*)0); p =
libnvme_namespace_next_path(n, p))
{
4704 libnvme_ctrl_t c;
4705 struct json_object *jpath = json_create_object()json_object_new_object();
4706
4707 obj_add_strjson_object_add_value_string(jpath, "Path", libnvme_path_get_name(p));
4708 obj_add_strjson_object_add_value_string(jpath, "ANAState", libnvme_path_get_ana_state(p));
4709
4710 /*
4711 * For multipath, each path maps to one controller.
4712 * So get the controller from the path and then add
4713 * controller attributes.
4714 */
4715 c = libnvme_path_get_ctrl(p);
4716 obj_add_strjson_object_add_value_string(jpath, "Controller", libnvme_ctrl_get_name(c));
4717 obj_add_strjson_object_add_value_string(jpath, "Cntlid", libnvme_ctrl_get_cntlid(c));
4718 obj_add_strjson_object_add_value_string(jpath, "SerialNumber", libnvme_ctrl_get_serial(c));
4719 obj_add_strjson_object_add_value_string(jpath, "ModelNumber", libnvme_ctrl_get_model(c));
4720 obj_add_strjson_object_add_value_string(jpath, "Firmware", libnvme_ctrl_get_firmware(c));
4721 obj_add_strjson_object_add_value_string(jpath, "Transport", libnvme_ctrl_get_transport(c));
4722 obj_add_strjson_object_add_value_string(jpath, "Address", libnvme_ctrl_get_traddr(c));
4723 obj_add_ctrl_address_details(jpath, "AddressDetails", c);
4724 obj_add_strjson_object_add_value_string(jpath, "Slot", libnvme_ctrl_get_phy_slot(c));
4725
4726 array_add_obj(jpaths, jpath)json_object_array_add(jpaths, jpath);
4727 }
4728
4729 obj_add_obj(jns, "Paths", jpaths)json_object_object_add(jns, "Paths", jpaths);
4730 array_add_obj(jnss, jns)json_object_array_add(jnss, jns);
4731 }
4732 obj_add_obj(jss, "Namespaces", jnss)json_object_object_add(jss, "Namespaces", jnss);
4733}
4734
4735static void json_print_detail_list(libnvme_subsystem_t s, struct json_object *jss)
4736{
4737 libnvme_ctrl_t c;
4738 libnvme_ns_t n;
4739 struct json_object *jctrls = json_create_array()json_object_new_array();
4740
4741 libnvme_subsystem_for_each_ctrl(s, c)for (c = libnvme_subsystem_first_ctrl(s); c != ((void*)0); c =
libnvme_subsystem_next_ctrl(s, c))
{
4742 struct json_object *jctrl = json_create_object()json_object_new_object();
4743 struct json_object *jnss = json_create_array()json_object_new_array();
4744
4745 obj_add_strjson_object_add_value_string(jctrl, "Controller", libnvme_ctrl_get_name(c));
4746 obj_add_strjson_object_add_value_string(jctrl, "Cntlid", libnvme_ctrl_get_cntlid(c));
4747 obj_add_strjson_object_add_value_string(jctrl, "SerialNumber", libnvme_ctrl_get_serial(c));
4748 obj_add_strjson_object_add_value_string(jctrl, "ModelNumber", libnvme_ctrl_get_model(c));
4749 obj_add_strjson_object_add_value_string(jctrl, "Firmware", libnvme_ctrl_get_firmware(c));
4750 obj_add_strjson_object_add_value_string(jctrl, "Transport", libnvme_ctrl_get_transport(c));
4751 obj_add_strjson_object_add_value_string(jctrl, "Address", libnvme_ctrl_get_traddr(c));
4752 obj_add_ctrl_address_details(jctrl, "AddressDetails", c);
4753 obj_add_strjson_object_add_value_string(jctrl, "Slot", libnvme_ctrl_get_phy_slot(c));
4754
4755 libnvme_ctrl_for_each_ns(c, n)for (n = libnvme_ctrl_first_ns(c); n != ((void*)0); n = libnvme_ctrl_next_ns
(c, n))
{
4756 struct json_object *jns = json_create_object()json_object_new_object();
4757 int lba = libnvme_ns_get_lba_size(n);
4758 uint64_t nsze = libnvme_ns_get_lba_count(n) * lba;
4759 uint64_t nuse = libnvme_ns_get_lba_util(n) * lba;
4760
4761 obj_add_strjson_object_add_value_string(jns, "NameSpace", libnvme_ns_get_name(n));
4762 obj_add_strjson_object_add_value_string(jns, "Generic", libnvme_ns_get_generic_name(n));
4763 obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n))json_object_object_add(jns, "NSID", json_object_new_int(libnvme_ns_get_nsid
(n)))
;
4764 obj_add_uint64(jns, "UsedBytes", nuse)json_object_object_add(jns, "UsedBytes", json_object_new_uint64
(nuse))
;
4765 obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n))json_object_object_add(jns, "MaximumLBA", json_object_new_uint64
(libnvme_ns_get_lba_count(n)))
;
4766 obj_add_uint64(jns, "PhysicalSize", nsze)json_object_object_add(jns, "PhysicalSize", json_object_new_uint64
(nsze))
;
4767 obj_add_int(jns, "SectorSize", lba)json_object_object_add(jns, "SectorSize", json_object_new_int
(lba))
;
4768
4769 array_add_obj(jnss, jns)json_object_array_add(jnss, jns);
4770 }
4771
4772 obj_add_obj(jctrl, "Namespaces", jnss)json_object_object_add(jctrl, "Namespaces", jnss);
4773 array_add_obj(jctrls, jctrl)json_object_array_add(jctrls, jctrl);
4774 }
4775
4776 obj_add_obj(jss, "Controllers", jctrls)json_object_object_add(jss, "Controllers", jctrls);
4777}
4778
4779static void json_detail_list_v2(struct libnvme_global_ctx *ctx)
4780{
4781 struct json_object *r = json_create_object()json_object_new_object();
4782 struct json_object *jdev = json_create_array()json_object_new_array();
4783
4784 libnvme_host_t h;
4785 libnvme_subsystem_t s;
4786
4787 libnvme_for_each_host(ctx, h)for (h = libnvme_first_host(ctx); h != ((void*)0); h = libnvme_next_host
(ctx, h))
{
4788 struct json_object *hss = json_create_object()json_object_new_object();
4789 struct json_object *jsslist = json_create_array()json_object_new_array();
4790 const char *hostid;
4791
4792 obj_add_strjson_object_add_value_string(hss, "HostNQN", libnvme_host_get_hostnqn(h));
4793 hostid = libnvme_host_get_hostid(h);
4794 if (hostid)
4795 obj_add_strjson_object_add_value_string(hss, "HostID", hostid);
4796
4797 libnvme_for_each_subsystem(h, s)for (s = libnvme_first_subsystem(h); s != ((void*)0); s = libnvme_next_subsystem
(h, s))
{
4798 struct json_object *jss = json_create_object()json_object_new_object();
4799
4800 obj_add_strjson_object_add_value_string(jss, "Subsystem", libnvme_subsystem_get_name(s));
4801 obj_add_strjson_object_add_value_string(jss, "SubsystemNQN", libnvme_subsystem_get_subsysnqn(s));
4802
4803 if (nvme_is_multipath(s))
4804 json_print_detail_list_multipath(s, jss);
4805 else
4806 json_print_detail_list(s, jss);
4807
4808 array_add_obj(jsslist, jss)json_object_array_add(jsslist, jss);
4809 }
4810
4811 obj_add_obj(hss, "Subsystems", jsslist)json_object_object_add(hss, "Subsystems", jsslist);
4812 array_add_obj(jdev, hss)json_object_array_add(jdev, hss);
4813 }
4814
4815 obj_add_array(r, "Devices", jdev)json_object_object_add(r, "Devices", jdev);
4816
4817 json_print(r);
4818}
4819
4820static void json_detail_list(struct libnvme_global_ctx *ctx)
4821{
4822 struct json_object *r = json_create_object()json_object_new_object();
4823 struct json_object *jdev = json_create_array()json_object_new_array();
4824
4825 libnvme_host_t h;
4826 libnvme_subsystem_t s;
4827 libnvme_ctrl_t c;
4828 libnvme_path_t p;
4829 libnvme_ns_t n;
4830
4831 libnvme_for_each_host(ctx, h)for (h = libnvme_first_host(ctx); h != ((void*)0); h = libnvme_next_host
(ctx, h))
{
4832 struct json_object *hss = json_create_object()json_object_new_object();
4833 struct json_object *jsslist = json_create_array()json_object_new_array();
4834 const char *hostid;
4835
4836 obj_add_strjson_object_add_value_string(hss, "HostNQN", libnvme_host_get_hostnqn(h));
4837 hostid = libnvme_host_get_hostid(h);
4838 if (hostid)
4839 obj_add_strjson_object_add_value_string(hss, "HostID", hostid);
4840
4841 libnvme_for_each_subsystem(h, s)for (s = libnvme_first_subsystem(h); s != ((void*)0); s = libnvme_next_subsystem
(h, s))
{
4842 struct json_object *jss = json_create_object()json_object_new_object();
4843 struct json_object *jctrls = json_create_array()json_object_new_array();
4844 struct json_object *jnss = json_create_array()json_object_new_array();
4845
4846 obj_add_strjson_object_add_value_string(jss, "Subsystem", libnvme_subsystem_get_name(s));
4847 obj_add_strjson_object_add_value_string(jss, "SubsystemNQN", libnvme_subsystem_get_subsysnqn(s));
4848
4849 libnvme_subsystem_for_each_ctrl(s, c)for (c = libnvme_subsystem_first_ctrl(s); c != ((void*)0); c =
libnvme_subsystem_next_ctrl(s, c))
{
4850 struct json_object *jctrl = json_create_object()json_object_new_object();
4851 struct json_object *jnss = json_create_array()json_object_new_array();
4852 struct json_object *jpaths = json_create_array()json_object_new_array();
4853
4854 obj_add_strjson_object_add_value_string(jctrl, "Controller", libnvme_ctrl_get_name(c));
4855 obj_add_strjson_object_add_value_string(jctrl, "Cntlid", libnvme_ctrl_get_cntlid(c));
4856 obj_add_strjson_object_add_value_string(jctrl, "SerialNumber", libnvme_ctrl_get_serial(c));
4857 obj_add_strjson_object_add_value_string(jctrl, "ModelNumber", libnvme_ctrl_get_model(c));
4858 obj_add_strjson_object_add_value_string(jctrl, "Firmware", libnvme_ctrl_get_firmware(c));
4859 obj_add_strjson_object_add_value_string(jctrl, "Transport", libnvme_ctrl_get_transport(c));
4860 obj_add_strjson_object_add_value_string(jctrl, "Address", libnvme_ctrl_get_traddr(c));
4861 obj_add_ctrl_address_details(jctrl, "AddressDetails", c);
4862 obj_add_strjson_object_add_value_string(jctrl, "Slot", libnvme_ctrl_get_phy_slot(c));
4863
4864 libnvme_ctrl_for_each_ns(c, n)for (n = libnvme_ctrl_first_ns(c); n != ((void*)0); n = libnvme_ctrl_next_ns
(c, n))
{
4865 struct json_object *jns = json_create_object()json_object_new_object();
4866 int lba = libnvme_ns_get_lba_size(n);
4867 uint64_t nsze = libnvme_ns_get_lba_count(n) * lba;
4868 uint64_t nuse = libnvme_ns_get_lba_util(n) * lba;
4869
4870 obj_add_strjson_object_add_value_string(jns, "NameSpace", libnvme_ns_get_name(n));
4871 obj_add_strjson_object_add_value_string(jns, "Generic", libnvme_ns_get_generic_name(n));
4872 obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n))json_object_object_add(jns, "NSID", json_object_new_int(libnvme_ns_get_nsid
(n)))
;
4873 obj_add_uint64(jns, "UsedBytes", nuse)json_object_object_add(jns, "UsedBytes", json_object_new_uint64
(nuse))
;
4874 obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n))json_object_object_add(jns, "MaximumLBA", json_object_new_uint64
(libnvme_ns_get_lba_count(n)))
;
4875 obj_add_uint64(jns, "PhysicalSize", nsze)json_object_object_add(jns, "PhysicalSize", json_object_new_uint64
(nsze))
;
4876 obj_add_int(jns, "SectorSize", lba)json_object_object_add(jns, "SectorSize", json_object_new_int
(lba))
;
4877
4878 array_add_obj(jnss, jns)json_object_array_add(jnss, jns);
4879 }
4880 obj_add_obj(jctrl, "Namespaces", jnss)json_object_object_add(jctrl, "Namespaces", jnss);
4881
4882 libnvme_ctrl_for_each_path(c, p)for (p = libnvme_ctrl_first_path(c); p != ((void*)0); p = libnvme_ctrl_next_path
(c, p))
{
4883 struct json_object *jpath = json_create_object()json_object_new_object();
4884
4885 obj_add_strjson_object_add_value_string(jpath, "Path", libnvme_path_get_name(p));
4886 obj_add_strjson_object_add_value_string(jpath, "ANAState", libnvme_path_get_ana_state(p));
4887
4888 array_add_obj(jpaths, jpath)json_object_array_add(jpaths, jpath);
4889 }
4890 obj_add_obj(jctrl, "Paths", jpaths)json_object_object_add(jctrl, "Paths", jpaths);
4891
4892 array_add_obj(jctrls, jctrl)json_object_array_add(jctrls, jctrl);
4893 }
4894 obj_add_obj(jss, "Controllers", jctrls)json_object_object_add(jss, "Controllers", jctrls);
4895
4896 libnvme_subsystem_for_each_ns(s, n)for (n = libnvme_subsystem_first_ns(s); n != ((void*)0); n = libnvme_subsystem_next_ns
(s, n))
{
4897 struct json_object *jns = json_create_object()json_object_new_object();
4898
4899 int lba = libnvme_ns_get_lba_size(n);
4900 uint64_t nsze = libnvme_ns_get_lba_count(n) * lba;
4901 uint64_t nuse = libnvme_ns_get_lba_util(n) * lba;
4902
4903 obj_add_strjson_object_add_value_string(jns, "NameSpace", libnvme_ns_get_name(n));
4904 obj_add_strjson_object_add_value_string(jns, "Generic", libnvme_ns_get_generic_name(n));
4905 obj_add_int(jns, "NSID", libnvme_ns_get_nsid(n))json_object_object_add(jns, "NSID", json_object_new_int(libnvme_ns_get_nsid
(n)))
;
4906 obj_add_uint64(jns, "UsedBytes", nuse)json_object_object_add(jns, "UsedBytes", json_object_new_uint64
(nuse))
;
4907 obj_add_uint64(jns, "MaximumLBA", libnvme_ns_get_lba_count(n))json_object_object_add(jns, "MaximumLBA", json_object_new_uint64
(libnvme_ns_get_lba_count(n)))
;
4908 obj_add_uint64(jns, "PhysicalSize", nsze)json_object_object_add(jns, "PhysicalSize", json_object_new_uint64
(nsze))
;
4909 obj_add_int(jns, "SectorSize", lba)json_object_object_add(jns, "SectorSize", json_object_new_int
(lba))
;
4910
4911 array_add_obj(jnss, jns)json_object_array_add(jnss, jns);
4912 }
4913 obj_add_obj(jss, "Namespaces", jnss)json_object_object_add(jss, "Namespaces", jnss);
4914
4915 array_add_obj(jsslist, jss)json_object_array_add(jsslist, jss);
4916 }
4917
4918 obj_add_obj(hss, "Subsystems", jsslist)json_object_object_add(hss, "Subsystems", jsslist);
4919 array_add_obj(jdev, hss)json_object_array_add(jdev, hss);
4920 }
4921
4922 obj_add_array(r, "Devices", jdev)json_object_object_add(r, "Devices", jdev);
4923
4924 json_print(r);
4925}
4926
4927static struct json_object *json_list_item_obj(libnvme_ns_t n)
4928{
4929 struct json_object *r = json_create_object()json_object_new_object();
4930 char devname[NAME_LEN128] = { 0 };
4931 char genname[NAME_LEN128] = { 0 };
4932 int lba = libnvme_ns_get_lba_size(n);
4933 uint64_t nsze = libnvme_ns_get_lba_count(n) * lba;
4934 uint64_t nuse = libnvme_ns_get_lba_util(n) * lba;
4935
4936 nvme_dev_full_path(n, devname, sizeof(devname));
4937 nvme_generic_full_path(n, genname, sizeof(genname));
4938
4939 obj_add_int(r, "NameSpace", libnvme_ns_get_nsid(n))json_object_object_add(r, "NameSpace", json_object_new_int(libnvme_ns_get_nsid
(n)))
;
4940 obj_add_strjson_object_add_value_string(r, "DevicePath", devname);
4941 obj_add_strjson_object_add_value_string(r, "GenericPath", genname);
4942 obj_add_strjson_object_add_value_string(r, "Firmware", libnvme_ns_get_firmware(n));
4943 obj_add_strjson_object_add_value_string(r, "ModelNumber", libnvme_ns_get_model(n));
4944 obj_add_strjson_object_add_value_string(r, "SerialNumber", libnvme_ns_get_serial(n));
4945 obj_add_uint64(r, "UsedBytes", nuse)json_object_object_add(r, "UsedBytes", json_object_new_uint64
(nuse))
;
4946 obj_add_uint64(r, "MaximumLBA", libnvme_ns_get_lba_count(n))json_object_object_add(r, "MaximumLBA", json_object_new_uint64
(libnvme_ns_get_lba_count(n)))
;
4947 obj_add_uint64(r, "PhysicalSize", nsze)json_object_object_add(r, "PhysicalSize", json_object_new_uint64
(nsze))
;
4948 obj_add_int(r, "SectorSize", lba)json_object_object_add(r, "SectorSize", json_object_new_int(lba
))
;
4949
4950 return r;
4951}
4952
4953static void json_simple_list(struct libnvme_global_ctx *ctx)
4954{
4955 struct json_object *r = json_create_object()json_object_new_object();
4956 struct json_object *jdevices = json_create_array()json_object_new_array();
4957
4958 libnvme_host_t h;
4959 libnvme_subsystem_t s;
4960 libnvme_ctrl_t c;
4961 libnvme_ns_t n;
4962
4963 libnvme_for_each_host(ctx, h)for (h = libnvme_first_host(ctx); h != ((void*)0); h = libnvme_next_host
(ctx, h))
{
4964 libnvme_for_each_subsystem(h, s)for (s = libnvme_first_subsystem(h); s != ((void*)0); s = libnvme_next_subsystem
(h, s))
{
4965 libnvme_subsystem_for_each_ns(s, n)for (n = libnvme_subsystem_first_ns(s); n != ((void*)0); n = libnvme_subsystem_next_ns
(s, n))
4966 array_add_obj(jdevices, json_list_item_obj(n))json_object_array_add(jdevices, json_list_item_obj(n));
4967
4968 libnvme_subsystem_for_each_ctrl(s, c)for (c = libnvme_subsystem_first_ctrl(s); c != ((void*)0); c =
libnvme_subsystem_next_ctrl(s, c))
{
4969 libnvme_ctrl_for_each_ns(c, n)for (n = libnvme_ctrl_first_ns(c); n != ((void*)0); n = libnvme_ctrl_next_ns
(c, n))
4970 array_add_obj(jdevices, json_list_item_obj(n))json_object_array_add(jdevices, json_list_item_obj(n));
4971 }
4972 }
4973 }
4974
4975 obj_add_array(r, "Devices", jdevices)json_object_object_add(r, "Devices", jdevices);
4976
4977 json_print(r);
4978}
4979
4980static void json_list_item(libnvme_ns_t n, struct table *t)
4981{
4982 struct json_object *r = json_list_item_obj(n);
4983
4984 json_print(r);
4985}
4986
4987static void json_print_list_items(struct libnvme_global_ctx *ctx)
4988{
4989 if (json_print_ops.flags & VERBOSE) {
4990 if (nvme_args.output_format_ver == 2)
4991 json_detail_list_v2(ctx);
4992 else
4993 json_detail_list(ctx);
4994 } else
4995 json_simple_list(ctx);
4996}
4997
4998static unsigned int json_subsystem_topology_multipath(libnvme_subsystem_t s,
4999 json_object *namespaces)
5000{
5001 libnvme_ns_t n;
5002 libnvme_path_t p;
5003 unsigned int i = 0;
5004 const char *iopolicy = libnvme_subsystem_get_iopolicy(s);
5005
5006 libnvme_subsystem_for_each_ns(s, n)for (n = libnvme_subsystem_first_ns(s); n != ((void*)0); n = libnvme_subsystem_next_ns
(s, n))
{
5007 struct json_object *ns_attrs;
5008 struct json_object *paths;
5009
5010 ns_attrs = json_create_object()json_object_new_object();
5011 obj_add_int(ns_attrs, "NSID", libnvme_ns_get_nsid(n))json_object_object_add(ns_attrs, "NSID", json_object_new_int(
libnvme_ns_get_nsid(n)))
;
5012 obj_add_strjson_object_add_value_string(ns_attrs, "Name", libnvme_ns_get_name(n));
5013
5014 paths = json_create_array()json_object_new_array();
5015 libnvme_namespace_for_each_path(n, p)for (p = libnvme_namespace_first_path(n); p != ((void*)0); p =
libnvme_namespace_next_path(n, p))
{
5016 struct json_object *path_attrs;
5017 struct json_object *ctrls, *ctrl_attrs;
5018 libnvme_ctrl_t c;
5019
5020 path_attrs = json_create_object()json_object_new_object();
5021 obj_add_strjson_object_add_value_string(path_attrs, "Path", libnvme_path_get_name(p));
5022 obj_add_strjson_object_add_value_string(path_attrs, "ANAState", libnvme_path_get_ana_state(p));
5023
5024 /*
5025 * For iopolicy numa exclude "Qdepth", for iopolicy
5026 * queue-depth exclude "NUMANodes" and for iopolicy
5027 * round-robin exclude both "Qdepth" and "NUMANodes".
5028 */
5029 if (!strcmp(iopolicy, "numa"))
5030 obj_add_strjson_object_add_value_string(path_attrs, "NUMANodes",
5031 libnvme_path_get_numa_nodes(p));
5032 else if (!strcmp(iopolicy, "queue-depth"))
5033 obj_add_int(path_attrs, "Qdepth",json_object_object_add(path_attrs, "Qdepth", json_object_new_int
(libnvme_path_get_queue_depth(p)))
5034 libnvme_path_get_queue_depth(p))json_object_object_add(path_attrs, "Qdepth", json_object_new_int
(libnvme_path_get_queue_depth(p)))
;
5035
5036 c = libnvme_path_get_ctrl(p);
5037 ctrls = json_create_array()json_object_new_array();
5038 ctrl_attrs = json_create_object()json_object_new_object();
5039 obj_add_strjson_object_add_value_string(ctrl_attrs, "Name", libnvme_ctrl_get_name(c));
5040 obj_add_strjson_object_add_value_string(ctrl_attrs, "Transport", libnvme_ctrl_get_transport(c));
5041 obj_add_strjson_object_add_value_string(ctrl_attrs, "Address", libnvme_ctrl_get_traddr(c));
5042 obj_add_ctrl_address_details(ctrl_attrs, "AddressDetails", c);
5043 obj_add_strjson_object_add_value_string(ctrl_attrs, "State", libnvme_ctrl_get_state(c));
5044 array_add_obj(ctrls, ctrl_attrs)json_object_array_add(ctrls, ctrl_attrs);
5045 obj_add_array(path_attrs, "Controller", ctrls)json_object_object_add(path_attrs, "Controller", ctrls);
5046
5047 array_add_obj(paths, path_attrs)json_object_array_add(paths, path_attrs);
5048 }
5049 obj_add_array(ns_attrs, "Paths", paths)json_object_object_add(ns_attrs, "Paths", paths);
5050 array_add_obj(namespaces, ns_attrs)json_object_array_add(namespaces, ns_attrs);
5051 i++;
5052 }
5053
5054 return i;
5055}
5056
5057static void json_print_nvme_subsystem_topology(libnvme_subsystem_t s,
5058 json_object *namespaces)
5059{
5060 libnvme_ctrl_t c;
5061 libnvme_ns_t n;
5062
5063 libnvme_subsystem_for_each_ctrl(s, c)for (c = libnvme_subsystem_first_ctrl(s); c != ((void*)0); c =
libnvme_subsystem_next_ctrl(s, c))
{
5064 libnvme_ctrl_for_each_ns(c, n)for (n = libnvme_ctrl_first_ns(c); n != ((void*)0); n = libnvme_ctrl_next_ns
(c, n))
{
5065 struct json_object *ctrl_attrs;
5066 struct json_object *ns_attrs;
5067 struct json_object *ctrl;
5068
5069 ns_attrs = json_create_object()json_object_new_object();
5070 obj_add_int(ns_attrs, "NSID", libnvme_ns_get_nsid(n))json_object_object_add(ns_attrs, "NSID", json_object_new_int(
libnvme_ns_get_nsid(n)))
;
5071 obj_add_strjson_object_add_value_string(ns_attrs, "Name", libnvme_ns_get_name(n));
5072
5073 ctrl = json_create_array()json_object_new_array();
5074 ctrl_attrs = json_create_object()json_object_new_object();
5075 obj_add_strjson_object_add_value_string(ctrl_attrs, "Name",
5076 libnvme_ctrl_get_name(c));
5077 obj_add_strjson_object_add_value_string(ctrl_attrs, "Transport",
5078 libnvme_ctrl_get_transport(c));
5079 obj_add_strjson_object_add_value_string(ctrl_attrs, "Address",
5080 libnvme_ctrl_get_traddr(c));
5081 obj_add_ctrl_address_details(ctrl_attrs, "AddressDetails", c);
5082 obj_add_strjson_object_add_value_string(ctrl_attrs, "State",
5083 libnvme_ctrl_get_state(c));
5084
5085 array_add_obj(ctrl, ctrl_attrs)json_object_array_add(ctrl, ctrl_attrs);
5086 obj_add_array(ns_attrs, "Controller", ctrl)json_object_object_add(ns_attrs, "Controller", ctrl);
5087 array_add_obj(namespaces, ns_attrs)json_object_array_add(namespaces, ns_attrs);
5088 }
5089 }
5090}
5091
5092static void json_simple_topology(struct libnvme_global_ctx *ctx)
5093{
5094 struct json_object *host_attrs, *subsystem_attrs;
5095 struct json_object *subsystems, *namespaces;
5096 struct json_object *a = json_create_array()json_object_new_array();
5097 libnvme_host_t h;
5098
5099 libnvme_for_each_host(ctx, h)for (h = libnvme_first_host(ctx); h != ((void*)0); h = libnvme_next_host
(ctx, h))
{
5100 libnvme_subsystem_t s;
5101 const char *hostid;
5102
5103 host_attrs = json_create_object()json_object_new_object();
5104 obj_add_strjson_object_add_value_string(host_attrs, "HostNQN", libnvme_host_get_hostnqn(h));
5105 hostid = libnvme_host_get_hostid(h);
5106 if (hostid)
5107 obj_add_strjson_object_add_value_string(host_attrs, "HostID", hostid);
5108 subsystems = json_create_array()json_object_new_array();
5109 libnvme_for_each_subsystem(h, s)for (s = libnvme_first_subsystem(h); s != ((void*)0); s = libnvme_next_subsystem
(h, s))
{
5110 subsystem_attrs = json_create_object()json_object_new_object();
5111 obj_add_strjson_object_add_value_string(subsystem_attrs, "Name", libnvme_subsystem_get_name(s));
5112 obj_add_strjson_object_add_value_string(subsystem_attrs, "NQN", libnvme_subsystem_get_subsysnqn(s));
5113 obj_add_strjson_object_add_value_string(subsystem_attrs, "IOPolicy",
5114 libnvme_subsystem_get_iopolicy(s));
5115
5116 if (verbose_mode()) {
5117 obj_add_strjson_object_add_value_string(subsystem_attrs, "Model",
5118 libnvme_subsystem_get_model(s));
5119 obj_add_strjson_object_add_value_string(subsystem_attrs, "Serial",
5120 libnvme_subsystem_get_serial(s));
5121 obj_add_strjson_object_add_value_string(subsystem_attrs, "Firmware",
5122 libnvme_subsystem_get_firmware(s));
5123 obj_add_strjson_object_add_value_string(subsystem_attrs, "Type",
5124 libnvme_subsystem_get_subsystype(s));
5125 }
5126
5127 array_add_obj(subsystems, subsystem_attrs)json_object_array_add(subsystems, subsystem_attrs);
5128 namespaces = json_create_array()json_object_new_array();
5129
5130 if (!json_subsystem_topology_multipath(s, namespaces))
5131 json_print_nvme_subsystem_topology(s, namespaces);
5132
5133 obj_add_array(subsystem_attrs, "Namespaces", namespaces)json_object_object_add(subsystem_attrs, "Namespaces", namespaces
)
;
5134 }
5135 obj_add_array(host_attrs, "Subsystems", subsystems)json_object_object_add(host_attrs, "Subsystems", subsystems);
5136 array_add_obj(a, host_attrs)json_object_array_add(a, host_attrs);
5137 }
5138
5139 json_print(a);
5140}
5141
5142static void json_directive_show_fields_identify(__u8 doper, __u8 *field, struct json_object *r)
5143{
5144 struct json_object *support;
5145 struct json_object *enabled;
5146 struct json_object *persistent;
5147
5148 switch (doper) {
5149 case NVME_DIRECTIVE_RECEIVE_IDENTIFY_DOPER_PARAM:
5150 support = json_create_array()json_object_new_array();
5151 obj_add_array(r, "Directive support", support)json_object_object_add(r, "Directive support", support);
5152 obj_add_strjson_object_add_value_string(support, "Identify Directive",
5153 *field & 0x1 ? "Supported" : "Not supported");
5154 obj_add_strjson_object_add_value_string(support, "Stream Directive",
5155 *field & 0x2 ? "Supported" : "Not supported");
5156 obj_add_strjson_object_add_value_string(support, "Data Placement Directive",
5157 *field & 0x4 ? "Supported" : "Not supported");
5158 enabled = json_create_array()json_object_new_array();
5159 obj_add_array(r, "Directive enabled", enabled)json_object_object_add(r, "Directive enabled", enabled);
5160 obj_add_strjson_object_add_value_string(enabled, "Identify Directive",
5161 *(field + 32) & 0x1 ? "Enabled" : "Disabled");
5162 obj_add_strjson_object_add_value_string(enabled, "Stream Directive",
5163 *(field + 32) & 0x2 ? "Enabled" : "Disabled");
5164 obj_add_strjson_object_add_value_string(enabled, "Data Placement Directive",
5165 *(field + 32) & 0x4 ? "Enabled" : "Disabled");
5166 persistent = json_create_array()json_object_new_array();
5167 obj_add_array(r, "Directive Persistent Across Controller Level Resets",json_object_object_add(r, "Directive Persistent Across Controller Level Resets"
, persistent)
5168 persistent)json_object_object_add(r, "Directive Persistent Across Controller Level Resets"
, persistent)
;
5169 obj_add_strjson_object_add_value_string(persistent, "Identify Directive",
5170 *(field + 64) & 0x1 ? "Enabled" : "Disabled");
5171 obj_add_strjson_object_add_value_string(persistent, "Stream Directive",
5172 *(field + 64) & 0x2 ? "Enabled" : "Disabled");
5173 obj_add_strjson_object_add_value_string(persistent, "Data Placement Directive",
5174 *(field + 64) & 0x4 ? "Enabled" : "Disabled");
5175 break;
5176 default:
5177 obj_add_strjson_object_add_value_string(r, "Error", "invalid directive operations for Identify Directives");
5178 break;
5179 }
5180}
5181
5182static void json_directive_show_fields_streams(__u8 doper, unsigned int result, __u16 *field,
5183 struct json_object *r)
5184{
5185 int count;
5186 int i;
5187 char json_str[STR_LEN100];
5188
5189 switch (doper) {
5190 case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_PARAM:
5191 obj_add_uint(r, "Max Streams Limit (MSL)", le16_to_cpu(*field))json_object_object_add(r, "Max Streams Limit (MSL)", json_object_new_uint64
(le16_to_cpu(*field)))
;
5192 obj_add_uint(r, "NVM Subsystem Streams Available (NSSA)", le16_to_cpu(*(field + 2)))json_object_object_add(r, "NVM Subsystem Streams Available (NSSA)"
, json_object_new_uint64(le16_to_cpu(*(field + 2))))
;
5193 obj_add_uint(r, "NVM Subsystem Streams Open (NSSO)", le16_to_cpu(*(field + 4)))json_object_object_add(r, "NVM Subsystem Streams Open (NSSO)"
, json_object_new_uint64(le16_to_cpu(*(field + 4))))
;
5194 obj_add_uint(r, "NVM Subsystem Stream Capability (NSSC)", le16_to_cpu(*(field + 6)))json_object_object_add(r, "NVM Subsystem Stream Capability (NSSC)"
, json_object_new_uint64(le16_to_cpu(*(field + 6))))
;
5195 obj_add_uint(r, "Stream Write Size (in unit of LB size) (SWS)",json_object_object_add(r, "Stream Write Size (in unit of LB size) (SWS)"
, json_object_new_uint64(le16_to_cpu(*(__u32 *)(field + 16)))
)
5196 le16_to_cpu(*(__u32 *)(field + 16)))json_object_object_add(r, "Stream Write Size (in unit of LB size) (SWS)"
, json_object_new_uint64(le16_to_cpu(*(__u32 *)(field + 16)))
)
;
5197 obj_add_uint(r, "Stream Granularity Size (in unit of SWS) (SGS)",json_object_object_add(r, "Stream Granularity Size (in unit of SWS) (SGS)"
, json_object_new_uint64(le16_to_cpu(*(field + 20))))
5198 le16_to_cpu(*(field + 20)))json_object_object_add(r, "Stream Granularity Size (in unit of SWS) (SGS)"
, json_object_new_uint64(le16_to_cpu(*(field + 20))))
;
5199 obj_add_uint(r, "Namespace Streams Allocated (NSA)", le16_to_cpu(*(field + 22)))json_object_object_add(r, "Namespace Streams Allocated (NSA)"
, json_object_new_uint64(le16_to_cpu(*(field + 22))))
;
5200 obj_add_uint(r, "Namespace Streams Open (NSO)", le16_to_cpu(*(field + 24)))json_object_object_add(r, "Namespace Streams Open (NSO)", json_object_new_uint64
(le16_to_cpu(*(field + 24))))
;
5201 break;
5202 case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_STATUS:
5203 count = *field;
5204 obj_add_uint(r, "Open Stream Count", le16_to_cpu(*field))json_object_object_add(r, "Open Stream Count", json_object_new_uint64
(le16_to_cpu(*field)))
;
5205 for (i = 0; i < count; i++) {
5206 sprintf(json_str, "Stream Identifier %.6u", i + 1);
5207 obj_add_uint(r, json_str, le16_to_cpu(*(field + (i + 1) * 2)))json_object_object_add(r, json_str, json_object_new_uint64(le16_to_cpu
(*(field + (i + 1) * 2))))
;
5208 }
5209 break;
5210 case NVME_DIRECTIVE_RECEIVE_STREAMS_DOPER_RESOURCE:
5211 obj_add_uint(r, "Namespace Streams Allocated (NSA)", result & 0xffff)json_object_object_add(r, "Namespace Streams Allocated (NSA)"
, json_object_new_uint64(result & 0xffff))
;
5212 break;
5213 default:
5214 obj_add_strjson_object_add_value_string(r, "Error",
5215 "invalid directive operations for Streams Directives");
5216 break;
5217 }
5218}
5219
5220static void json_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result,
5221 __u8 *field, struct json_object *r)
5222{
5223 switch (dtype) {
5224 case NVME_DIRECTIVE_DTYPE_IDENTIFY:
5225 json_directive_show_fields_identify(doper, field, r);
5226 break;
5227 case NVME_DIRECTIVE_DTYPE_STREAMS:
5228 json_directive_show_fields_streams(doper, result, (__u16 *)field, r);
5229 break;
5230 default:
5231 obj_add_strjson_object_add_value_string(r, "Error", "invalid directive type");
5232 break;
5233 }
5234}
5235
5236static void json_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u64 result,
5237 void *buf, __u32 len)
5238{
5239 struct json_object *r = json_create_object()json_object_new_object();
5240 struct json_object *data;
5241 char json_str[STR_LEN100];
5242
5243 sprintf(json_str, "%#x", type);
5244 obj_add_strjson_object_add_value_string(r, "Type", json_str);
5245 sprintf(json_str, "%#x", oper);
5246 obj_add_strjson_object_add_value_string(r, "Operation", json_str);
5247 sprintf(json_str, "%#x", spec);
5248 obj_add_strjson_object_add_value_string(r, "spec", json_str);
5249 sprintf(json_str, "%#x", nsid);
5250 obj_add_strjson_object_add_value_string(r, "NSID", json_str);
5251 sprintf(json_str, "%#"PRIx64"l" "x", (uint64_t)result);
5252 obj_add_result(r, json_str);
5253
5254 if (verbose_mode()) {
5255 json_directive_show_fields(type, oper, result, buf, r);
5256 } else if (buf) {
5257 data = json_create_array()json_object_new_array();
5258 d_json((unsigned char *)buf, len, 16, 1, data);
5259 obj_add_array(r, "data", data)json_object_object_add(r, "data", data);
5260 }
5261
5262 json_print(r);
5263}
5264
5265#ifdef CONFIG_FABRICS
5266static void json_discovery_log(struct nvmf_discovery_log *log, int numrec)
5267{
5268 struct json_object *r = json_create_object()json_object_new_object();
5269 struct json_object *entries = json_create_array()json_object_new_array();
5270 int i;
5271
5272 obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr))json_object_object_add(r, "genctr", json_object_new_uint64(le64_to_cpu
(log->genctr)))
;
5273 obj_add_array(r, "records", entries)json_object_object_add(r, "records", entries);
5274
5275 for (i = 0; i < numrec; i++) {
5276 struct nvmf_disc_log_entry *e = &log->entries[i];
5277 struct json_object *entry = json_create_object()json_object_new_object();
5278
5279 obj_add_strjson_object_add_value_string(entry, "trtype", libnvmf_trtype_str(e->trtype));
5280 obj_add_strjson_object_add_value_string(entry, "adrfam", libnvmf_adrfam_str(e->adrfam));
5281 obj_add_strjson_object_add_value_string(entry, "subtype", libnvmf_subtype_str(e->subtype));
5282 obj_add_strjson_object_add_value_string(entry, "treq", libnvmf_treq_str(e->treq));
5283 obj_add_uint(entry, "portid", le16_to_cpu(e->portid))json_object_object_add(entry, "portid", json_object_new_uint64
(le16_to_cpu(e->portid)))
;
5284 obj_add_strjson_object_add_value_string(entry, "trsvcid", e->trsvcid);
5285 obj_add_strjson_object_add_value_string(entry, "subnqn", e->subnqn);
5286 obj_add_strjson_object_add_value_string(entry, "traddr", e->traddr);
5287 obj_add_strjson_object_add_value_string(entry, "eflags", libnvmf_eflags_str(le16_to_cpu(e->eflags)));
5288
5289 switch (e->trtype) {
5290 case NVMF_TRTYPE_RDMA:
5291 obj_add_strjson_object_add_value_string(entry, "rdma_prtype", libnvmf_prtype_str(e->tsas.rdma.prtype));
5292 obj_add_strjson_object_add_value_string(entry, "rdma_qptype", libnvmf_qptype_str(e->tsas.rdma.qptype));
5293 obj_add_strjson_object_add_value_string(entry, "rdma_cms", libnvmf_cms_str(e->tsas.rdma.cms));
5294 obj_add_uint(entry, "rdma_pkey", le16_to_cpu(e->tsas.rdma.pkey))json_object_object_add(entry, "rdma_pkey", json_object_new_uint64
(le16_to_cpu(e->tsas.rdma.pkey)))
;
5295 break;
5296 case NVMF_TRTYPE_TCP:
5297 obj_add_strjson_object_add_value_string(entry, "sectype", libnvmf_sectype_str(e->tsas.tcp.sectype));
5298 break;
5299 default:
5300 break;
5301 }
5302 array_add_obj(entries, entry)json_object_array_add(entries, entry);
5303 }
5304
5305 json_print(r);
5306}
5307#else
5308static void json_discovery_log(struct nvmf_discovery_log *log, int numrec) {}
5309#endif
5310
5311static void json_connect_msg(libnvme_ctrl_t c)
5312{
5313 struct json_object *r = json_create_object()json_object_new_object();
5314
5315 obj_add_strjson_object_add_value_string(r, "device", libnvme_ctrl_get_name(c));
5316
5317 json_print(r);
5318}
5319
5320static void json_output_object(struct json_object *r)
5321{
5322 json_print(r);
5323}
5324
5325static void json_output_status(int status)
5326{
5327 struct json_object *r;
5328 char json_str[STR_LEN100];
5329 int val;
5330 int type;
5331
5332 sprintf(json_str, "status: %d", status);
5333 r = obj_create(json_str);
5334
5335 if (status < 0) {
5336 obj_add_strjson_object_add_value_string(r, "error", libnvme_strerror(errno(*__errno_location ())));
5337 obj_print(r);
5338 return;
5339 }
5340
5341 val = nvme_status_get_value(status);
5342 type = nvme_status_get_type(status);
5343
5344 switch (type) {
5345 case NVME_STATUS_TYPE_NVME:
5346 obj_add_strjson_object_add_value_string(r, "error", libnvme_status_to_string(val, false0));
5347 obj_add_strjson_object_add_value_string(r, "type", "nvme");
5348 break;
5349#ifdef CONFIG_MI
5350 case NVME_STATUS_TYPE_MI:
5351 obj_add_strjson_object_add_value_string(r, "error", libnvme_mi_status_to_string(val));
5352 obj_add_strjson_object_add_value_string(r, "type", "nvme-mi");
5353 break;
5354#endif
5355 default:
5356 obj_add_strjson_object_add_value_string(r, "type", "Unknown");
5357 break;
5358 }
5359
5360 obj_print(r);
5361}
5362
5363static void json_output_opcode_status(int status, bool_Bool admin, __u8 opcode)
5364{
5365 struct json_object *r;
5366 char json_str[STR_LEN100];
5367 int val = nvme_status_get_value(status);
5368 int type = nvme_status_get_type(status);
5369
5370 if (status >= 0 && type == NVME_STATUS_TYPE_NVME) {
5371 sprintf(json_str, "status: %d", status);
5372 r = obj_create(json_str);
5373 obj_add_strjson_object_add_value_string(r, "error",
5374 libnvme_opcode_status_to_string(val, admin, opcode));
5375 obj_add_strjson_object_add_value_string(r, "type", "nvme");
5376 obj_print(r);
5377 return;
5378 }
5379
5380 json_output_status(status);
5381}
5382
5383static void json_output_error_status(int status, const char *msg, va_list ap)
5384{
5385 struct json_object *r;
5386 char json_str[STR_LEN100];
5387 int val;
5388 int type;
5389
5390 __cleanup_free__attribute__((cleanup(freep))) char *value = NULL((void*)0);
5391
5392 if (vasprintf(&value, msg, ap) < 0)
5393 value = alloc_error;
5394
5395 sprintf(json_str, "Error: %s", value);
5396 r = obj_create(json_str);
5397
5398 if (status < 0) {
5399 obj_add_strjson_object_add_value_string(r, "error", libnvme_strerror(errno(*__errno_location ())));
5400 obj_print(r);
5401 return;
5402 }
5403
5404 val = nvme_status_get_value(status);
5405 type = nvme_status_get_type(status);
5406
5407 switch (type) {
5408 case NVME_STATUS_TYPE_NVME:
5409 obj_add_strjson_object_add_value_string(r, "status", libnvme_status_to_string(val, false0));
5410 obj_add_strjson_object_add_value_string(r, "type", "nvme");
5411 break;
5412#ifdef CONFIG_MI
5413 case NVME_STATUS_TYPE_MI:
5414 obj_add_strjson_object_add_value_string(r, "status", libnvme_mi_status_to_string(val));
5415 obj_add_strjson_object_add_value_string(r, "type", "nvme-mi");
5416 break;
5417#endif
5418 default:
5419 obj_add_strjson_object_add_value_string(r, "type", "Unknown");
5420 break;
5421 }
5422
5423 obj_add_int(r, "value", val)json_object_object_add(r, "value", json_object_new_int(val));
5424
5425 obj_print(r);
5426}
5427
5428static void json_output_message(bool_Bool error, const char *msg, va_list ap)
5429{
5430 struct json_object *r = json_r ? json_r : json_create_object()json_object_new_object();
5431
5432 __cleanup_free__attribute__((cleanup(freep))) char *value = NULL((void*)0);
5433
5434 if (vasprintf(&value, msg, ap) < 0)
5435 value = NULL((void*)0);
5436
5437 obj_add_strjson_object_add_value_string(r, error ? "error" : "result", value ? value : alloc_error);
5438
5439 obj_print(r);
5440}
5441
5442static void json_output_perror(const char *msg, va_list ap)
5443{
5444 struct json_object *r = json_create_object()json_object_new_object();
5445
5446 __cleanup_free__attribute__((cleanup(freep))) char *error = NULL((void*)0);
5447
5448 if (vasprintf(&error, msg, ap) < 0)
5449 error = NULL((void*)0);
5450
5451 obj_add_key(r, "error", "%s: %s", error ? error : alloc_error,
5452 libnvme_strerror(errno(*__errno_location ())));
5453
5454 json_output_object(r);
5455}
5456
5457static char *trim_white_space(char *str)
5458{
5459 char *end;
5460
5461 if (!str)
5462 return NULL((void*)0);
5463
5464 /* Trim leading space */
5465 while (isspace((unsigned char)*str)((*__ctype_b_loc ())[(int) (((unsigned char)*str))] & (unsigned
short int) _ISspace)
)
5466 str++;
5467
5468 /* All spaces */
5469 if (!*str)
5470 return str;
5471
5472 /* Trim trailing space */
5473 end = str + strlen(str) - 1;
5474 while (end > str && isspace((unsigned char)*end)((*__ctype_b_loc ())[(int) (((unsigned char)*end))] & (unsigned
short int) _ISspace)
)
5475 end--;
5476
5477 /* Write new null terminator character */
5478 end[1] = '\0';
5479
5480 return str;
5481}
5482
5483static void json_output_key_value(const char *key, const char *val, va_list ap)
5484{
5485 struct json_object *r = json_r ? json_r : json_create_object()json_object_new_object();
5486
5487 __cleanup_free__attribute__((cleanup(freep))) char *value = NULL((void*)0);
5488 __cleanup_free__attribute__((cleanup(freep))) char *key_trim = trim_white_space(strdup(key));
5489
5490 if (vasprintf(&value, val, ap) < 0)
5491 value = NULL((void*)0);
5492
5493 obj_add_strjson_object_add_value_string(r, key_trim ? key_trim : key, value ? value : "Could not allocate string");
5494
5495 obj_print(r);
5496}
5497
5498void json_show_init(void)
5499{
5500 json_init++;
5501
5502 if (!json_r)
5503 json_r = json_create_object()json_object_new_object();
5504}
5505
5506void json_show_finish(void)
5507{
5508 if (--json_init)
5509 return;
5510
5511 if (json_r)
5512 json_output_object(json_r);
5513
5514 json_r = NULL((void*)0);
5515}
5516
5517static void json_mgmt_addr_list_log(struct nvme_mgmt_addr_list_log *ma_list)
5518{
5519 int i;
5520 bool_Bool reserved = true1;
5521 struct json_object *r = json_create_object()json_object_new_object();
5522 struct json_object *mad;
5523 struct json_object *mat;
5524 char json_str[STR_LEN100];
5525
5526 for (i = 0; i < ARRAY_SIZE(ma_list->mad)(sizeof(ma_list->mad) / sizeof((ma_list->mad)[0])); i++) {
5527 switch (ma_list->mad[i].mat) {
5528 case 1:
5529 case 2:
5530 mad = json_create_object()json_object_new_object();
5531 mat = json_create_object()json_object_new_object();
5532 obj_add_strjson_object_add_value_string(mat, "definition", ma_list->mad[i].mat == 1 ?
5533 "NVM subsystem management agent" : "fabric interface manager");
5534 snprintf(json_str, sizeof(json_str), "type: %d", ma_list->mad[i].mat);
5535 obj_add_obj(mad, json_str, mat)json_object_object_add(mad, json_str, mat);
5536 obj_add_strjson_object_add_value_string(mad, "address", (const char *)ma_list->mad[i].madrs);
5537 snprintf(json_str, sizeof(json_str), "descriptor: %d", i);
5538 obj_add_obj(r, json_str, mad)json_object_object_add(r, json_str, mad);
5539 reserved = false0;
5540 break;
5541 case 0xff:
5542 goto out;
5543 default:
5544 break;
5545 }
5546 }
5547
5548out:
5549 if (reserved)
5550 obj_add_strjson_object_add_value_string(r, "list", "All management address descriptors reserved");
5551
5552 json_print(r);
5553}
5554
5555static void json_rotational_media_info_log(struct nvme_rotational_media_info_log *info)
5556{
5557 struct json_object *r = json_create_object()json_object_new_object();
5558
5559 obj_add_uint(r, "endgid", le16_to_cpu(info->endgid))json_object_object_add(r, "endgid", json_object_new_uint64(le16_to_cpu
(info->endgid)))
;
5560 obj_add_uint(r, "numa", le16_to_cpu(info->numa))json_object_object_add(r, "numa", json_object_new_uint64(le16_to_cpu
(info->numa)))
;
5561 obj_add_uint(r, "nrs", le16_to_cpu(info->nrs))json_object_object_add(r, "nrs", json_object_new_uint64(le16_to_cpu
(info->nrs)))
;
5562 obj_add_uint(r, "spinc", le32_to_cpu(info->spinc))json_object_object_add(r, "spinc", json_object_new_uint64(le32_to_cpu
(info->spinc)))
;
5563 obj_add_uint(r, "fspinc", le32_to_cpu(info->fspinc))json_object_object_add(r, "fspinc", json_object_new_uint64(le32_to_cpu
(info->fspinc)))
;
5564 obj_add_uint(r, "ldc", le32_to_cpu(info->ldc))json_object_object_add(r, "ldc", json_object_new_uint64(le32_to_cpu
(info->ldc)))
;
5565 obj_add_uint(r, "fldc", le32_to_cpu(info->fldc))json_object_object_add(r, "fldc", json_object_new_uint64(le32_to_cpu
(info->fldc)))
;
5566
5567 json_print(r);
5568}
5569
5570static void json_dispersed_ns_psub_log(struct nvme_dispersed_ns_participating_nss_log *log)
5571{
5572 struct json_object *r = json_create_object()json_object_new_object();
5573 __u64 numpsub = le64_to_cpu(log->numpsub);
5574 __u64 i;
5575 char json_str[STR_LEN100];
5576 char psub[NVME_NQN_LENGTH + 1];
5577
5578 obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr))json_object_object_add(r, "genctr", json_object_new_uint64(le64_to_cpu
(log->genctr)))
;
5579 obj_add_uint64(r, "numpsub", numpsub)json_object_object_add(r, "numpsub", json_object_new_uint64(numpsub
))
;
5580 for (i = 0; i < numpsub; i++) {
5581 snprintf(json_str, sizeof(json_str), "participating_nss %"PRIu64"l" "u""", (uint64_t)i);
5582 snprintf(psub, sizeof(psub), "%-.*s", NVME_NQN_LENGTH,
5583 &log->participating_nss[i * NVME_NQN_LENGTH]);
5584 obj_add_strjson_object_add_value_string(r, json_str, psub);
5585 }
5586
5587 json_print(r);
5588}
5589
5590static void json_reachability_groups_log(struct nvme_reachability_groups_log *log, __u64 len UNUSED)
5591{
5592 struct json_object *r = json_create_object()json_object_new_object();
5593 __u16 i;
5594 __u32 j;
5595 char json_str[STR_LEN100];
5596 struct json_object *rgd;
5597
5598 obj_add_uint64(r, "chngc", le64_to_cpu(log->chngc))json_object_object_add(r, "chngc", json_object_new_uint64(le64_to_cpu
(log->chngc)))
;
5599 obj_add_uint(r, "nrgd", le16_to_cpu(log->nrgd))json_object_object_add(r, "nrgd", json_object_new_uint64(le16_to_cpu
(log->nrgd)))
;
5600
5601 for (i = 0; i < le16_to_cpu(log->nrgd); i++) {
5602 snprintf(json_str, sizeof(json_str), "rgid: %u", le32_to_cpu(log->rgd[i].rgid));
5603 rgd = json_create_object()json_object_new_object();
5604 obj_add_uint(rgd, "nnid", le32_to_cpu(log->rgd[i].nnid))json_object_object_add(rgd, "nnid", json_object_new_uint64(le32_to_cpu
(log->rgd[i].nnid)))
;
5605 obj_add_uint64(rgd, "chngc", le64_to_cpu(log->rgd[i].chngc))json_object_object_add(rgd, "chngc", json_object_new_uint64(le64_to_cpu
(log->rgd[i].chngc)))
;
5606 for (j = 0; j < le32_to_cpu(log->rgd[i].nnid); j++)
5607 obj_add_uint(rgd, "nnid", le32_to_cpu(log->rgd[i].nsid[j]))json_object_object_add(rgd, "nnid", json_object_new_uint64(le32_to_cpu
(log->rgd[i].nsid[j])))
;
5608 obj_add_obj(r, json_str, rgd)json_object_object_add(r, json_str, rgd);
5609 }
5610
5611 json_print(r);
5612}
5613
5614static void json_reachability_associations_log(struct nvme_reachability_associations_log *log,
5615 __u64 len UNUSED)
5616{
5617 struct json_object *r = json_create_object()json_object_new_object();
5618 __u16 i;
5619 __u32 j;
5620 char json_str[STR_LEN100];
5621 struct json_object *rad;
5622
5623 obj_add_uint64(r, "chngc", le64_to_cpu(log->chngc))json_object_object_add(r, "chngc", json_object_new_uint64(le64_to_cpu
(log->chngc)))
;
5624 obj_add_uint(r, "nrad", le16_to_cpu(log->nrad))json_object_object_add(r, "nrad", json_object_new_uint64(le16_to_cpu
(log->nrad)))
;
5625
5626 for (i = 0; i < le16_to_cpu(log->nrad); i++) {
5627 snprintf(json_str, sizeof(json_str), "rasid: %u", le32_to_cpu(log->rad[i].rasid));
5628 rad = json_create_object()json_object_new_object();
5629 obj_add_uint(rad, "nrid", le32_to_cpu(log->rad[i].nrid))json_object_object_add(rad, "nrid", json_object_new_uint64(le32_to_cpu
(log->rad[i].nrid)))
;
5630 obj_add_uint64(rad, "chngc", le64_to_cpu(log->rad[i].chngc))json_object_object_add(rad, "chngc", json_object_new_uint64(le64_to_cpu
(log->rad[i].chngc)))
;
5631 obj_add_uint(rad, "rac", log->rad[i].rac)json_object_object_add(rad, "rac", json_object_new_uint64(log
->rad[i].rac))
;
5632 for (j = 0; j < le32_to_cpu(log->rad[i].nrid); j++)
5633 obj_add_uint(rad, "rgid", le32_to_cpu(log->rad[i].rgid[j]))json_object_object_add(rad, "rgid", json_object_new_uint64(le32_to_cpu
(log->rad[i].rgid[j])))
;
5634 obj_add_obj(r, json_str, rad)json_object_object_add(r, json_str, rad);
5635 }
5636
5637 json_print(r);
5638}
5639
5640#ifdef CONFIG_FABRICS
5641static void json_host_discovery_log(struct nvme_host_discover_log *log)
5642{
5643 struct json_object *r = json_create_object()json_object_new_object();
5644 __u32 i;
5645 __u16 j;
5646 struct nvme_host_ext_discover_log *hedlpe;
5647 struct nvmf_ext_attr *exat;
5648 __u32 thdlpl = le32_to_cpu(log->thdlpl);
5649 __u32 tel;
5650 __u16 numexat;
5651 char json_str[STR_LEN100];
5652 struct json_object *hedlpe_o;
5653 struct json_object *tsas_o;
5654 struct json_object *exat_o;
5655 int n = 0;
5656
5657 obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr))json_object_object_add(r, "genctr", json_object_new_uint64(le64_to_cpu
(log->genctr)))
;
5658 obj_add_uint64(r, "numrec", le64_to_cpu(log->numrec))json_object_object_add(r, "numrec", json_object_new_uint64(le64_to_cpu
(log->numrec)))
;
5659 obj_add_uint(r, "recfmt", le16_to_cpu(log->recfmt))json_object_object_add(r, "recfmt", json_object_new_uint64(le16_to_cpu
(log->recfmt)))
;
5660 obj_add_uint_02xjson_object_add_uint_02x(r, "hdlpf", log->hdlpf);
5661 obj_add_uint(r, "thdlpl", thdlpl)json_object_object_add(r, "thdlpl", json_object_new_uint64(thdlpl
))
;
5662
5663 for (i = sizeof(*log); i < le32_to_cpu(log->thdlpl); i += tel) {
5664 hedlpe_o = json_create_object()json_object_new_object();
5665 hedlpe = (void *)log + i;
5666 tel = le32_to_cpu(hedlpe->tel);
5667 numexat = le16_to_cpu(hedlpe->numexat);
5668 obj_add_strjson_object_add_value_string(hedlpe_o, "trtype", libnvmf_trtype_str(hedlpe->trtype));
5669 obj_add_strjson_object_add_value_string(hedlpe_o, "adrfam",
5670 strlen(hedlpe->traddr) ? libnvmf_adrfam_str(hedlpe->adrfam) : "");
5671 obj_add_strjson_object_add_value_string(hedlpe_o, "eflags", libnvmf_eflags_str(le16_to_cpu(hedlpe->eflags)));
5672 obj_add_strjson_object_add_value_string(hedlpe_o, "hostnqn", hedlpe->hostnqn);
5673 obj_add_strjson_object_add_value_string(hedlpe_o, "traddr", hedlpe->traddr);
5674 tsas_o = json_create_object()json_object_new_object();
5675 switch (hedlpe->trtype) {
5676 case NVMF_TRTYPE_RDMA:
5677 obj_add_strjson_object_add_value_string(tsas_o, "prtype", libnvmf_prtype_str(hedlpe->tsas.rdma.prtype));
5678 obj_add_strjson_object_add_value_string(tsas_o, "qptype", libnvmf_qptype_str(hedlpe->tsas.rdma.qptype));
5679 obj_add_strjson_object_add_value_string(tsas_o, "cms", libnvmf_cms_str(hedlpe->tsas.rdma.cms));
5680 obj_add_uint_0nxjson_object_add_uint_0nx(tsas_o, "pkey", le16_to_cpu(hedlpe->tsas.rdma.pkey), 4);
5681 break;
5682 case NVMF_TRTYPE_TCP:
5683 obj_add_strjson_object_add_value_string(tsas_o, "sectype", libnvmf_sectype_str(hedlpe->tsas.tcp.sectype));
5684 break;
5685 default:
5686 obj_d(tsas_o, "common", (unsigned char *)hedlpe->tsas.common,
5687 sizeof(hedlpe->tsas.common), 16, 1);
5688 break;
5689 }
5690 obj_add_obj(hedlpe_o, "tsas", tsas_o)json_object_object_add(hedlpe_o, "tsas", tsas_o);
5691 obj_add_uint(hedlpe_o, "tel", tel)json_object_object_add(hedlpe_o, "tel", json_object_new_uint64
(tel))
;
5692 obj_add_uint(hedlpe_o, "numexat", numexat)json_object_object_add(hedlpe_o, "numexat", json_object_new_uint64
(numexat))
;
5693
5694 exat = hedlpe->exat;
5695 for (j = 0; j < numexat; j++) {
5696 exat_o = json_create_object()json_object_new_object();
5697 snprintf(json_str, sizeof(json_str), "exat: %d", j);
5698 obj_add_uint(exat_o, "exattype", le16_to_cpu(exat->exattype))json_object_object_add(exat_o, "exattype", json_object_new_uint64
(le16_to_cpu(exat->exattype)))
;
5699 obj_add_uint(exat_o, "exatlen", le16_to_cpu(exat->exatlen))json_object_object_add(exat_o, "exatlen", json_object_new_uint64
(le16_to_cpu(exat->exatlen)))
;
5700 obj_d(exat_o, "exatval", (unsigned char *)exat->exatval,
5701 le16_to_cpu(exat->exatlen), 16, 1);
5702 obj_add_obj(hedlpe_o, json_str, exat_o)json_object_object_add(hedlpe_o, json_str, exat_o);
5703 exat = libnvmf_exat_ptr_next(exat);
5704 }
5705 snprintf(json_str, sizeof(json_str), "hedlpe: %d", n++);
5706 obj_add_obj(r, json_str, hedlpe_o)json_object_object_add(r, json_str, hedlpe_o);
5707 }
5708}
5709
5710static void obj_add_traddr(struct json_object *o, const char *k, __u8 adrfam, __u8 *traddr)
5711{
5712 char dst[INET6_ADDRSTRLEN46];
5713 socklen_t size;
5714 int af;
5715
5716 if (adrfam == NVMF_ADDR_FAMILY_IP4) {
5717 af = AF_INET2;
5718 size = INET_ADDRSTRLEN16;
5719 } else if (adrfam == NVMF_ADDR_FAMILY_IP6) {
5720 af = AF_INET610;
5721 size = INET6_ADDRSTRLEN46;
5722 } else {
5723 obj_add_strjson_object_add_value_string(o, k, "<invalid>");
5724 return;
5725 }
5726
5727 if (inet_ntop(af, traddr, dst, size))
5728 obj_add_strjson_object_add_value_string(o, k, dst);
5729}
5730
5731static void json_ave_discovery_log(struct nvme_ave_discover_log *log)
5732{
5733 struct json_object *r = json_create_object()json_object_new_object();
5734 __u32 i;
5735 __u8 j;
5736 struct nvme_ave_discover_log_entry *adlpe;
5737 struct nvme_ave_tr_record *atr;
5738 __u32 tadlpl = le32_to_cpu(log->tadlpl);
5739 __u32 tel;
5740 __u8 numatr;
5741 int n = 0;
5742 char json_str[STR_LEN100];
5743 struct json_object *adlpe_o;
5744 struct json_object *atr_o;
5745
5746 obj_add_uint64(r, "genctr", le64_to_cpu(log->genctr))json_object_object_add(r, "genctr", json_object_new_uint64(le64_to_cpu
(log->genctr)))
;
5747 obj_add_uint64(r, "numrec", le64_to_cpu(log->numrec))json_object_object_add(r, "numrec", json_object_new_uint64(le64_to_cpu
(log->numrec)))
;
5748 obj_add_uint(r, "recfmt", le16_to_cpu(log->recfmt))json_object_object_add(r, "recfmt", json_object_new_uint64(le16_to_cpu
(log->recfmt)))
;
5749 obj_add_uint(r, "thdlpl", tadlpl)json_object_object_add(r, "thdlpl", json_object_new_uint64(tadlpl
))
;
5750
5751 for (i = sizeof(*log); i < le32_to_cpu(log->tadlpl); i += tel) {
5752 adlpe_o = json_create_object()json_object_new_object();
5753 adlpe = (void *)log + i;
5754 tel = le32_to_cpu(adlpe->tel);
5755 numatr = adlpe->numatr;
5756 obj_add_uint(adlpe_o, "tel", tel)json_object_object_add(adlpe_o, "tel", json_object_new_uint64
(tel))
;
5757 obj_add_strjson_object_add_value_string(adlpe_o, "avenqn", adlpe->avenqn);
5758 obj_add_uint(adlpe_o, "numatr", numatr)json_object_object_add(adlpe_o, "numatr", json_object_new_uint64
(numatr))
;
5759
5760 atr = adlpe->atr;
5761 for (j = 0; j < numatr; j++) {
5762 atr_o = json_create_object()json_object_new_object();
5763 snprintf(json_str, sizeof(json_str), "atr: %d", j);
5764 obj_add_strjson_object_add_value_string(atr_o, "aveadrfam", libnvmf_adrfam_str(atr->aveadrfam));
5765 obj_add_uint(atr_o, "avetrsvcid", le16_to_cpu(atr->avetrsvcid))json_object_object_add(atr_o, "avetrsvcid", json_object_new_uint64
(le16_to_cpu(atr->avetrsvcid)))
;
5766 obj_add_traddr(atr_o, "avetraddr", atr->aveadrfam, atr->avetraddr);
5767 obj_add_obj(adlpe_o, json_str, atr_o)json_object_object_add(adlpe_o, json_str, atr_o);
5768 atr++;
5769 }
5770 snprintf(json_str, sizeof(json_str), "adlpe: %d", n++);
5771 obj_add_obj(r, json_str, adlpe_o)json_object_object_add(r, json_str, adlpe_o);
5772 }
5773}
5774#else
5775static void json_host_discovery_log(struct nvme_host_discover_log *log) {}
5776static void json_ave_discovery_log(struct nvme_ave_discover_log *log) {}
5777#endif
5778
5779static void json_pull_model_ddc_req_log(struct nvme_pull_model_ddc_req_log *log)
5780{
5781 struct json_object *r = json_create_object()json_object_new_object();
5782 __u32 tpdrpl = le32_to_cpu(log->tpdrpl);
5783 __u32 osp_len = tpdrpl - offsetof(struct nvme_pull_model_ddc_req_log, osp)__builtin_offsetof(struct nvme_pull_model_ddc_req_log, osp);
5784
5785 obj_add_uint(r, "ori", log->ori)json_object_object_add(r, "ori", json_object_new_uint64(log->
ori))
;
5786 printf("tpdrpl: %u\n", tpdrpl);
5787 obj_d(r, "osp", (unsigned char *)log->osp, osp_len, 16, 1);
5788}
5789
5790static void json_power_meas_log(struct nvme_power_meas_log *log, __u32 size UNUSED)
5791{
5792 struct json_object *r = json_create_object()json_object_new_object();
5793 struct json_object *descs;
5794 struct json_object *smts_obj;
5795 struct json_object *mipwrt_obj;
5796 __u16 nphd = le16_to_cpu(log->nphd);
5797 __u16 pma = le16_to_cpu(log->pma);
5798 __u8 pmt = NVME_GET(pma, PMA_PMT)(((pma) >> NVME_PMA_PMT_SHIFT) & NVME_PMA_PMT_MASK);
5799 __u16 i;
5800
5801 obj_add_uint(r, "ver", log->ver)json_object_object_add(r, "ver", json_object_new_uint64(log->
ver))
;
5802 obj_add_uint(r, "pmgn", log->pmgn)json_object_object_add(r, "pmgn", json_object_new_uint64(log->
pmgn))
;
5803 obj_add_uint(r, "pma", pma)json_object_object_add(r, "pma", json_object_new_uint64(pma));
5804 obj_add_uint(r, "pme", NVME_GET(pma, PMA_PME))json_object_object_add(r, "pme", json_object_new_uint64((((pma
) >> NVME_PMA_PME_SHIFT) & NVME_PMA_PME_MASK)))
;
5805 obj_add_uint(r, "ncpdf", NVME_GET(pma, PMA_NCPDF))json_object_object_add(r, "ncpdf", json_object_new_uint64((((
pma) >> NVME_PMA_NCPDF_SHIFT) & NVME_PMA_NCPDF_MASK
)))
;
5806 obj_add_uint(r, "epf", NVME_GET(pma, PMA_EPF))json_object_object_add(r, "epf", json_object_new_uint64((((pma
) >> NVME_PMA_EPF_SHIFT) & NVME_PMA_EPF_MASK)))
;
5807 obj_add_uint(r, "mipwrts", NVME_GET(pma, PMA_MIPWRTS))json_object_object_add(r, "mipwrts", json_object_new_uint64((
((pma) >> NVME_PMA_MIPWRTS_SHIFT) & NVME_PMA_MIPWRTS_MASK
)))
;
5808 obj_add_uint(r, "phdo", NVME_GET(pma, PMA_PHDO))json_object_object_add(r, "phdo", json_object_new_uint64((((pma
) >> NVME_PMA_PHDO_SHIFT) & NVME_PMA_PHDO_MASK)))
;
5809 obj_add_uint(r, "pmt", pmt)json_object_object_add(r, "pmt", json_object_new_uint64(pmt));
5810 obj_add_strjson_object_add_value_string(r, "pmt_str", nvme_power_measurement_type_to_string(pmt));
5811 obj_add_uint(r, "sze", le32_to_cpu(log->sze))json_object_object_add(r, "sze", json_object_new_uint64(le32_to_cpu
(log->sze)))
;
5812 obj_add_uint(r, "pmc", le32_to_cpu(log->pmc))json_object_object_add(r, "pmc", json_object_new_uint64(le32_to_cpu
(log->pmc)))
;
5813 obj_add_uint(r, "nphd", nphd)json_object_object_add(r, "nphd", json_object_new_uint64(nphd
))
;
5814 obj_add_uint(r, "smtr", le16_to_cpu(log->smtr))json_object_object_add(r, "smtr", json_object_new_uint64(le16_to_cpu
(log->smtr)))
;
5815
5816 smts_obj = json_create_object()json_object_new_object();
5817 json_timestamp(smts_obj, &log->smts);
5818 obj_add_obj(r, "smts", smts_obj)json_object_object_add(r, "smts", smts_obj);
5819
5820 obj_add_uint(r, "phds", le16_to_cpu(log->phds))json_object_object_add(r, "phds", json_object_new_uint64(le16_to_cpu
(log->phds)))
;
5821 obj_add_uint(r, "phbs", le16_to_cpu(log->phbs))json_object_object_add(r, "phbs", json_object_new_uint64(le16_to_cpu
(log->phbs)))
;
5822 obj_add_uint(r, "nphds", le16_to_cpu(log->nphds))json_object_object_add(r, "nphds", json_object_new_uint64(le16_to_cpu
(log->nphds)))
;
5823 obj_add_uint(r, "vss", le16_to_cpu(log->vss))json_object_object_add(r, "vss", json_object_new_uint64(le16_to_cpu
(log->vss)))
;
5824 obj_add_uint(r, "phdoc", le32_to_cpu(log->phdoc))json_object_object_add(r, "phdoc", json_object_new_uint64(le32_to_cpu
(log->phdoc)))
;
5825 obj_add_uint(r, "aipwr", le32_to_cpu(log->aipwr))json_object_object_add(r, "aipwr", json_object_new_uint64(le32_to_cpu
(log->aipwr)))
;
5826 obj_add_uint(r, "mipwr", le32_to_cpu(log->mipwr))json_object_object_add(r, "mipwr", json_object_new_uint64(le32_to_cpu
(log->mipwr)))
;
5827
5828 mipwrt_obj = json_create_object()json_object_new_object();
5829 json_timestamp(mipwrt_obj, &log->mipwrt);
5830 obj_add_obj(r, "mipwrt", mipwrt_obj)json_object_object_add(r, "mipwrt", mipwrt_obj);
5831
5832 obj_add_uint(r, "ipwrpe", log->ipwrpe)json_object_object_add(r, "ipwrpe", json_object_new_uint64(log
->ipwrpe))
;
5833
5834 descs = json_create_array()json_object_new_array();
5835 for (i = 0; i < nphd; i++) {
5836 struct json_object *desc = json_create_object()json_object_new_object();
5837
5838 obj_add_uint(desc, "phbc", le32_to_cpu(log->descs[i].phbc))json_object_object_add(desc, "phbc", json_object_new_uint64(le32_to_cpu
(log->descs[i].phbc)))
;
5839 obj_add_uint(desc, "phblt", le32_to_cpu(log->descs[i].phblt))json_object_object_add(desc, "phblt", json_object_new_uint64(
le32_to_cpu(log->descs[i].phblt)))
;
5840 json_object_array_add(descs, desc);
5841 }
5842 obj_add_obj(r, "descs", descs)json_object_object_add(r, "descs", descs);
5843
5844 json_print(r);
5845}
5846
5847static struct print_ops json_print_ops = {
5848 /* libnvme types.h print functions */
5849 .ana_log = json_ana_log,
5850 .boot_part_log = json_boot_part_log,
5851 .phy_rx_eom_log = json_phy_rx_eom_log,
5852 .ctrl_list = json_nvme_list_ctrl,
5853 .ctrl_registers = json_ctrl_registers,
5854 .ctrl_register = json_ctrl_register,
5855 .directive = json_directive_show,
5856 .discovery_log = json_discovery_log,
5857 .effects_log_list = json_effects_log_list,
5858 .endurance_group_event_agg_log = json_endurance_group_event_agg_log,
5859 .endurance_group_list = json_nvme_endurance_group_list,
5860 .endurance_log = json_endurance_log,
5861 .error_log = json_error_log,
5862 .fdp_config_log = json_nvme_fdp_configs,
5863 .fdp_event_log = json_nvme_fdp_events,
5864 .fdp_ruh_status = json_nvme_fdp_ruh_status,
5865 .fdp_stats_log = json_nvme_fdp_stats,
5866 .fdp_usage_log = json_nvme_fdp_usage,
5867 .fid_supported_effects_log = json_fid_support_effects_log,
5868 .fw_log = json_fw_log,
5869 .id_ctrl = json_nvme_id_ctrl,
5870 .id_ctrl_nvm = json_nvme_id_ctrl_nvm,
5871 .id_domain_list = json_id_domain_list,
5872 .id_independent_id_ns = json_nvme_cmd_set_independent_id_ns,
5873 .id_iocs = json_id_iocs,
5874 .id_ns = json_nvme_id_ns,
5875 .id_ns_descs = json_nvme_id_ns_descs,
5876 .id_ns_granularity_list = json_nvme_id_ns_granularity_list,
5877 .id_nvmset_list = json_nvme_id_nvmset,
5878 .id_uuid_list = json_nvme_id_uuid_list,
5879 .lba_status = json_lba_status,
5880 .lba_status_log = json_lba_status_log,
5881 .media_unit_stat_log = json_media_unit_stat_log,
5882 .mi_cmd_support_effects_log = json_mi_cmd_support_effects_log,
5883 .ns_list = json_nvme_list_ns,
5884 .ns_list_log = json_changed_ns_list_log,
5885 .nvm_id_ns = json_nvme_nvm_id_ns,
5886 .persistent_event_log = json_persistent_event_log,
5887 .predictable_latency_event_agg_log = json_predictable_latency_event_agg_log,
5888 .predictable_latency_per_nvmset = json_predictable_latency_per_nvmset,
5889 .primary_ctrl_cap = json_nvme_primary_ctrl_cap,
5890 .resv_notification_log = json_resv_notif_log,
5891 .resv_report = json_nvme_resv_report,
5892 .sanitize_log_page = json_sanitize_log,
5893 .secondary_ctrl_list = json_nvme_list_secondary_ctrl,
5894 .select_result = json_select_result,
5895 .self_test_log = json_self_test_log,
5896 .single_property = json_single_property,
5897 .smart_log = json_smart_log,
5898 .supported_cap_config_list_log = json_supported_cap_config_log,
5899 .supported_log_pages = json_support_log,
5900 .zns_start_zone_list = json_zns_start_zone_list,
5901 .zns_changed_zone_log = json_zns_changed,
5902 .zns_finish_zone_list = json_zns_finish_zone_list,
5903 .zns_id_ctrl = json_nvme_zns_id_ctrl,
5904 .zns_id_ns = json_nvme_zns_id_ns,
5905 .zns_report_zones = json_nvme_zns_report_zones,
5906 .show_feature = json_feature_show,
5907 .show_feature_fields = json_feature_show_fields,
5908 .id_ctrl_rpmbs = json_id_ctrl_rpmbs,
5909 .lba_range = json_lba_range,
5910 .lba_status_info = json_lba_status_info,
5911 .d = json_d,
5912 .show_init = json_show_init,
5913 .show_finish = json_show_finish,
5914 .mgmt_addr_list_log = json_mgmt_addr_list_log,
5915 .rotational_media_info_log = json_rotational_media_info_log,
5916 .dispersed_ns_psub_log = json_dispersed_ns_psub_log,
5917 .reachability_groups_log = json_reachability_groups_log,
5918 .reachability_associations_log = json_reachability_associations_log,
5919 .host_discovery_log = json_host_discovery_log,
5920 .ave_discovery_log = json_ave_discovery_log,
5921 .pull_model_ddc_req_log = json_pull_model_ddc_req_log,
5922 .power_meas_log = json_power_meas_log,
5923
5924 /* libnvme tree print functions */
5925 .list_item = json_list_item,
5926 .list_items = json_print_list_items,
5927 .print_nvme_subsystem_list = json_print_nvme_subsystem_list,
5928 .topology_ctrl = json_simple_topology,
5929 .topology_namespace = json_simple_topology,
5930 .topology_multipath = json_simple_topology,
5931
5932 /* status and error messages */
5933 .connect_msg = json_connect_msg,
5934 .show_message = json_output_message,
5935 .show_perror = json_output_perror,
5936 .show_status = json_output_status,
5937 .show_opcode_status = json_output_opcode_status,
5938 .show_error_status = json_output_error_status,
5939 .show_key_value = json_output_key_value,
5940};
5941
5942struct print_ops *nvme_get_json_print_ops(nvme_print_flags_t flags)
5943{
5944 json_print_ops.flags = flags;
5945 return &json_print_ops;
5946}