smartmontools SVN Rev 5684
Utility to control and monitor storage systems with "S.M.A.R.T."
nvmeprint.cpp
Go to the documentation of this file.
1/*
2 * nvmeprint.cpp
3 *
4 * Home page of code is: https://www.smartmontools.org
5 *
6 * Copyright (C) 2016-25 Christian Franke
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11#include "config.h"
12#define __STDC_FORMAT_MACROS 1 // enable PRI* for C++
13
14#include "nvmeprint.h"
15
16const char * nvmeprint_cvsid = "$Id: nvmeprint.cpp 5683 2025-04-14 12:45:37Z chrfranke $"
18
19#include "utility.h"
20#include "dev_interface.h"
21#include "nvmecmds.h"
22#include "atacmds.h" // dont_print_serial_number
23#include "scsicmds.h" // dStrHex()
24#include "smartctl.h"
25#include "sg_unaligned.h"
26
27#include <inttypes.h>
28
29using namespace smartmontools;
30
31// Return true if 128 bit LE integer is != 0.
32static bool le128_is_non_zero(const unsigned char (& val)[16])
33{
34 for (int i = 0; i < 16; i++) {
35 if (val[i])
36 return true;
37 }
38 return false;
39}
40
41// Format 128 bit integer for printing.
42// Add value with SI prefixes if BYTES_PER_UNIT is specified.
43static const char * le128_to_str(char (& str)[64], uint64_t hi, uint64_t lo, unsigned bytes_per_unit)
44{
45 if (!hi) {
46 // Up to 64-bit, print exact value
47 format_with_thousands_sep(str, sizeof(str)-16, lo);
48
49 if (lo && bytes_per_unit && lo < 0xffffffffffffffffULL / bytes_per_unit) {
50 int i = strlen(str);
51 str[i++] = ' '; str[i++] = '[';
52 format_capacity(str+i, (int)sizeof(str)-i-1, lo * bytes_per_unit);
53 i = strlen(str);
54 str[i++] = ']'; str[i] = 0;
55 }
56 }
57 else {
58 // More than 64-bit, prepend '~' flag on low precision
59 int i = 0;
60 // cppcheck-suppress knownConditionTrueFalse
62 str[i++] = '~';
63 uint128_hilo_to_str(str + i, (int)sizeof(str) - i, hi, lo);
64 }
65
66 return str;
67}
68
69// Format 128 bit LE integer for printing.
70// Add value with SI prefixes if BYTES_PER_UNIT is specified.
71static const char * le128_to_str(char (& str)[64], const unsigned char (& val)[16],
72 unsigned bytes_per_unit = 0)
73{
74 uint64_t hi = val[15];
75 for (int i = 15-1; i >= 8; i--) {
76 hi <<= 8; hi += val[i];
77 }
78 uint64_t lo = val[7];
79 for (int i = 7-1; i >= 0; i--) {
80 lo <<= 8; lo += val[i];
81 }
82 return le128_to_str(str, hi, lo, bytes_per_unit);
83}
84
85// Format capacity specified as 64bit LBA count for printing.
86static const char * lbacap_to_str(char (& str)[64], uint64_t lba_cnt, int lba_bits)
87{
88 return le128_to_str(str, (lba_cnt >> (64 - lba_bits)), (lba_cnt << lba_bits), 1);
89}
90
91// Output capacity specified as 64bit LBA count to JSON
92static void lbacap_to_js(const json::ref & jref, uint64_t lba_cnt, int lba_bits)
93{
94 jref["blocks"].set_unsafe_uint64(lba_cnt);
95 jref["bytes"].set_unsafe_uint128((lba_cnt >> (64 - lba_bits)), (lba_cnt << lba_bits));
96}
97
98// Format a Kelvin temperature value in Celsius.
99static const char * kelvin_to_str(char (& str)[64], int k)
100{
101 if (!k) // unsupported?
102 str[0] = '-', str[1] = 0;
103 else
104 snprintf(str, sizeof(str), "%d Celsius", k - 273);
105 return str;
106}
107
108static void print_drive_info(const nvme_id_ctrl & id_ctrl, const nvme_id_ns & id_ns,
109 unsigned nsid, bool show_all)
110{
111 char buf[64];
112 jout("Model Number: %s\n", format_char_array(buf, id_ctrl.mn));
113 jglb["model_name"] = buf;
115 jout("Serial Number: %s\n", format_char_array(buf, id_ctrl.sn));
116 jglb["serial_number"] = buf;
117 }
118
119 jout("Firmware Version: %s\n", format_char_array(buf, id_ctrl.fr));
120 jglb["firmware_version"] = buf;
121
122 // Vendor and Subsystem IDs are usually equal
123 if (show_all || id_ctrl.vid != id_ctrl.ssvid) {
124 jout("PCI Vendor ID: 0x%04x\n", id_ctrl.vid);
125 jout("PCI Vendor Subsystem ID: 0x%04x\n", id_ctrl.ssvid);
126 }
127 else {
128 jout("PCI Vendor/Subsystem ID: 0x%04x\n", id_ctrl.vid);
129 }
130 jglb["nvme_pci_vendor"]["id"] = id_ctrl.vid;
131 jglb["nvme_pci_vendor"]["subsystem_id"] = id_ctrl.ssvid;
132
133 jout("IEEE OUI Identifier: 0x%02x%02x%02x\n",
134 id_ctrl.ieee[2], id_ctrl.ieee[1], id_ctrl.ieee[0]);
135 jglb["nvme_ieee_oui_identifier"] = sg_get_unaligned_le(3, id_ctrl.ieee);
136
137 // Capacity info is optional for devices without namespace management
138 if (show_all || le128_is_non_zero(id_ctrl.tnvmcap) || le128_is_non_zero(id_ctrl.unvmcap)) {
139 jout("Total NVM Capacity: %s\n", le128_to_str(buf, id_ctrl.tnvmcap, 1));
140 jglb["nvme_total_capacity"].set_unsafe_le128(id_ctrl.tnvmcap);
141 jout("Unallocated NVM Capacity: %s\n", le128_to_str(buf, id_ctrl.unvmcap, 1));
142 jglb["nvme_unallocated_capacity"].set_unsafe_le128(id_ctrl.unvmcap);
143 }
144
145 jout("Controller ID: %d\n", id_ctrl.cntlid);
146 jglb["nvme_controller_id"] = id_ctrl.cntlid;
147
148 if (id_ctrl.ver) { // NVMe 1.2
149 int i = snprintf(buf, sizeof(buf), "%u.%u", id_ctrl.ver >> 16, (id_ctrl.ver >> 8) & 0xff);
150 if (i > 0 && (id_ctrl.ver & 0xff))
151 snprintf(buf+i, sizeof(buf)-i, ".%u", id_ctrl.ver & 0xff);
152 }
153 else
154 snprintf(buf, sizeof(buf), "<1.2");
155 jout("NVMe Version: %s\n", buf);
156 jglb["nvme_version"]["string"] = buf;
157 jglb["nvme_version"]["value"] = id_ctrl.ver;
158
159 // Print namespace info if available
160 jout("Number of Namespaces: %u\n", id_ctrl.nn);
161 jglb["nvme_number_of_namespaces"] = id_ctrl.nn;
162
163 if (nsid && id_ns.nsze) {
164 const char * align = &(" "[nsid < 10 ? 0 : (nsid < 100 ? 1 : 2)]);
165 int fmt_lba_bits = id_ns.lbaf[id_ns.flbas & 0xf].ds;
166
167 json::ref jrns = jglb["nvme_namespaces"][0]; // Same as in print_drive_capabilities()
168 jrns["id"] = nsid;
169
170 // Size and Capacity are equal if thin provisioning is not supported
171 if (show_all || id_ns.ncap != id_ns.nsze || (id_ns.nsfeat & 0x01)) {
172 jout("Namespace %u Size: %s%s\n", nsid, align,
173 lbacap_to_str(buf, id_ns.nsze, fmt_lba_bits));
174 jout("Namespace %u Capacity: %s%s\n", nsid, align,
175 lbacap_to_str(buf, id_ns.ncap, fmt_lba_bits));
176 }
177 else {
178 jout("Namespace %u Size/Capacity: %s%s\n", nsid, align,
179 lbacap_to_str(buf, id_ns.nsze, fmt_lba_bits));
180 }
181 lbacap_to_js(jrns["size"], id_ns.nsze, fmt_lba_bits);
182 lbacap_to_js(jrns["capacity"], id_ns.ncap, fmt_lba_bits);
183 lbacap_to_js(jglb["user_capacity"], id_ns.ncap, fmt_lba_bits); // TODO: use nsze?
184
185 // Utilization may be always equal to Capacity if thin provisioning is not supported
186 if (show_all || id_ns.nuse != id_ns.ncap || (id_ns.nsfeat & 0x01))
187 jout("Namespace %u Utilization: %s%s\n", nsid, align,
188 lbacap_to_str(buf, id_ns.nuse, fmt_lba_bits));
189 lbacap_to_js(jrns["utilization"], id_ns.nuse, fmt_lba_bits);
190
191 jout("Namespace %u Formatted LBA Size: %s%u\n", nsid, align, (1U << fmt_lba_bits));
192 jrns["formatted_lba_size"] = (1U << fmt_lba_bits);
193 jglb["logical_block_size"] = (1U << fmt_lba_bits);
194
195 if (!dont_print_serial_number && (show_all || nonempty(id_ns.eui64, sizeof(id_ns.eui64)))) {
196 jout("Namespace %u IEEE EUI-64: %s%02x%02x%02x %02x%02x%02x%02x%02x\n",
197 nsid, align, id_ns.eui64[0], id_ns.eui64[1], id_ns.eui64[2], id_ns.eui64[3],
198 id_ns.eui64[4], id_ns.eui64[5], id_ns.eui64[6], id_ns.eui64[7]);
199 jrns["eui64"]["oui"] = sg_get_unaligned_be(3, id_ns.eui64);
200 jrns["eui64"]["ext_id"] = sg_get_unaligned_be(5, id_ns.eui64 + 3);
201 }
202 }
203
204 // SMART/Health Information is mandatory
205 jglb["smart_support"] += { {"available", true}, {"enabled", true} };
206
207 jout_startup_datetime("Local Time is: ");
208}
209
210// Format scaled power value.
211static const char * format_power(char (& str)[16], unsigned power, unsigned scale)
212{
213 switch (scale & 0x3) {
214 case 0: // not reported
215 str[0] = '-'; str[1] = ' '; str[2] = 0; break;
216 case 1: // 0.0001W
217 snprintf(str, sizeof(str), "%u.%04uW", power / 10000, power % 10000); break;
218 case 2: // 0.01W
219 snprintf(str, sizeof(str), "%u.%02uW", power / 100, power % 100); break;
220 default: // reserved
221 str[0] = '?'; str[1] = 0; break;
222 }
223 return str;
224}
225
226static void format_power(const json::ref & jref, const char * name,
227 unsigned power, unsigned scale)
228{
229 unsigned sc = scale & 0x3;
230 if (!sc)
231 return; // not reported
232 jref[name] += { { "value", power }, { "scale", sc } };
233 if (sc <= 2)
234 jref[name]["units_per_watt"] = (sc == 2 ? 100 : 10000);
235}
236
237static void print_drive_capabilities(const nvme_id_ctrl & id_ctrl, const nvme_id_ns & id_ns,
238 unsigned nsid, bool show_all)
239{
240 // Figure 112 of NVM Express Base Specification Revision 1.3d, March 20, 2019
241 // Figure 251 of NVM Express Base Specification Revision 1.4c, March 9, 2021
242 // Figure 275 of NVM Express Base Specification Revision 2.0c, October 4, 2022
243 jout("Firmware Updates (0x%02x): %d Slot%s%s%s%s%s\n", id_ctrl.frmw,
244 ((id_ctrl.frmw >> 1) & 0x7), (((id_ctrl.frmw >> 1) & 0x7) != 1 ? "s" : ""),
245 ((id_ctrl.frmw & 0x01) ? ", Slot 1 R/O" : ""),
246 ((id_ctrl.frmw & 0x10) ? ", no Reset required" : ""),
247 ((id_ctrl.frmw & 0x20) ? ", multiple detected" : ""), // NVMe 2.0
248 ((id_ctrl.frmw & ~0x3f) ? ", *Other*" : ""));
249
250 jglb["nvme_firmware_update_capabilities"] += {
251 { "value", id_ctrl.frmw },
252 { "slots", (id_ctrl.frmw >> 1) & 0x7 },
253 { "first_slot_is_read_only", !!(id_ctrl.frmw & 0x01) },
254 { "activiation_without_reset", !!(id_ctrl.frmw & 0x10) },
255 { "multiple_update_detection", !!(id_ctrl.frmw & 0x20) },
256 { "other", id_ctrl.frmw & ~0x3f }
257 };
258
259 if (show_all || id_ctrl.oacs)
260 jout("Optional Admin Commands (0x%04x): %s%s%s%s%s%s%s%s%s%s%s%s%s\n", id_ctrl.oacs,
261 (!id_ctrl.oacs ? " -" : ""),
262 ((id_ctrl.oacs & 0x0001) ? " Security" : ""),
263 ((id_ctrl.oacs & 0x0002) ? " Format" : ""),
264 ((id_ctrl.oacs & 0x0004) ? " Frmw_DL" : ""),
265 ((id_ctrl.oacs & 0x0008) ? " NS_Mngmt" : ""), // NVMe 1.2
266 ((id_ctrl.oacs & 0x0010) ? " Self_Test" : ""), // NVMe 1.3 ...
267 ((id_ctrl.oacs & 0x0020) ? " Directvs" : ""),
268 ((id_ctrl.oacs & 0x0040) ? " MI_Snd/Rec" : ""),
269 ((id_ctrl.oacs & 0x0080) ? " Vrt_Mngmt" : ""),
270 ((id_ctrl.oacs & 0x0100) ? " Drbl_Bf_Cfg" : ""),
271 ((id_ctrl.oacs & 0x0200) ? " Get_LBA_Sts" : ""), // NVMe 1.4
272 ((id_ctrl.oacs & 0x0400) ? " Lockdown" : ""), // NVMe 2.0
273 ((id_ctrl.oacs & ~0x07ff) ? " *Other*" : ""));
274
275 jglb["nvme_optional_admin_commands"] += {
276 { "value", id_ctrl.oacs },
277 { "security_send_receive", !!(id_ctrl.oacs & 0x0001) },
278 { "format_nvm", !!(id_ctrl.oacs & 0x0002) },
279 { "firmware_download", !!(id_ctrl.oacs & 0x0004) },
280 { "namespace_management", !!(id_ctrl.oacs & 0x0008) }, // NVMe 1.2
281 { "self_test", !!(id_ctrl.oacs & 0x0010) }, // NVMe 1.3 ...
282 { "directives", !!(id_ctrl.oacs & 0x0020) },
283 { "mi_send_receive", !!(id_ctrl.oacs & 0x0040) },
284 { "virtualization_management", !!(id_ctrl.oacs & 0x0080) },
285 { "doorbell_buffer_config", !!(id_ctrl.oacs & 0x0100) },
286 { "get_lba_status", !!(id_ctrl.oacs & 0x0200) }, // NVMe 1.4
287 { "command_and_feature_lockdown", !!(id_ctrl.oacs & 0x0400) }, // NVMe 2.0
288 { "other", id_ctrl.oacs & ~0x07ff }
289 };
290
291 if (show_all || id_ctrl.oncs)
292 jout("Optional NVM Commands (0x%04x): %s%s%s%s%s%s%s%s%s%s%s\n", id_ctrl.oncs,
293 (!id_ctrl.oncs ? " -" : ""),
294 ((id_ctrl.oncs & 0x0001) ? " Comp" : ""),
295 ((id_ctrl.oncs & 0x0002) ? " Wr_Unc" : ""),
296 ((id_ctrl.oncs & 0x0004) ? " DS_Mngmt" : ""),
297 ((id_ctrl.oncs & 0x0008) ? " Wr_Zero" : ""), // NVMe 1.1 ...
298 ((id_ctrl.oncs & 0x0010) ? " Sav/Sel_Feat" : ""),
299 ((id_ctrl.oncs & 0x0020) ? " Resv" : ""),
300 ((id_ctrl.oncs & 0x0040) ? " Timestmp" : ""), // NVMe 1.3
301 ((id_ctrl.oncs & 0x0080) ? " Verify" : ""), // NVMe 1.4
302 ((id_ctrl.oncs & 0x0100) ? " Copy" : ""), // NVMe 2.0
303 ((id_ctrl.oncs & ~0x01ff) ? " *Other*" : ""));
304
305 jglb["nvme_optional_nvm_commands"] += {
306 { "value", id_ctrl.oncs },
307 { "compare", !!(id_ctrl.oncs & 0x0001) },
308 { "write_uncorrectable", !!(id_ctrl.oncs & 0x0002) },
309 { "dataset_management", !!(id_ctrl.oncs & 0x0004) },
310 { "write_zeroes", !!(id_ctrl.oncs & 0x0008) }, // NVMe 1.1 ...
311 { "save_select_feature_nonzero", !!(id_ctrl.oncs & 0x0010) },
312 { "reservations", !!(id_ctrl.oncs & 0x0020) },
313 { "timestamp", !!(id_ctrl.oncs & 0x0040) }, // NVMe 1.3
314 { "verify", !!(id_ctrl.oncs & 0x0080) }, // NVMe 1.4
315 { "copy", !!(id_ctrl.oncs & 0x0100) }, // NVMe 2.0
316 { "other", id_ctrl.oncs & ~0x01ff }
317 };
318
319 if (show_all || id_ctrl.lpa)
320 jout("Log Page Attributes (0x%02x): %s%s%s%s%s%s%s%s%s\n", id_ctrl.lpa,
321 (!id_ctrl.lpa ? " -" : ""),
322 ((id_ctrl.lpa & 0x01) ? " S/H_per_NS" : ""),
323 ((id_ctrl.lpa & 0x02) ? " Cmd_Eff_Lg" : ""), // NVMe 1.2
324 ((id_ctrl.lpa & 0x04) ? " Ext_Get_Lg" : ""), // NVMe 1.2.1
325 ((id_ctrl.lpa & 0x08) ? " Telmtry_Lg" : ""), // NVMe 1.3
326 ((id_ctrl.lpa & 0x10) ? " Pers_Ev_Lg" : ""), // NVMe 1.4
327 ((id_ctrl.lpa & 0x20) ? " Log0_FISE_MI" : ""), // NVMe 2.0 ...
328 ((id_ctrl.lpa & 0x40) ? " Telmtry_Ar_4" : ""),
329 ((id_ctrl.lpa & ~0x7f) ? " *Other*" : ""));
330
331 jglb["nvme_log_page_attributes"] += {
332 { "value", id_ctrl.lpa },
333 { "smart_health_per_namespace", !!(id_ctrl.lpa & 0x01) },
334 { "commands_effects_log", !!(id_ctrl.lpa & 0x02) }, // NVMe 1.2
335 { "extended_get_log_page_cmd", !!(id_ctrl.lpa & 0x04) }, // NVMe 1.2.1
336 { "telemetry_log", !!(id_ctrl.lpa & 0x08) }, // NVMe 1.3
337 { "persistent_event_log", !!(id_ctrl.lpa & 0x10) }, // NVMe 1.4
338 { "supported_log_pages_log", !!(id_ctrl.lpa & 0x20) }, // NVMe 2.0 ...
339 { "telemetry_data_area_4", !!(id_ctrl.lpa & 0x40) },
340 { "other", id_ctrl.lpa & ~0x7f }
341 };
342
343 if (id_ctrl.mdts) {
344 jout("Maximum Data Transfer Size: %u Pages\n", (1U << id_ctrl.mdts));
345 jglb["nvme_maximum_data_transfer_pages"] = (1U << id_ctrl.mdts);
346 }
347 else if (show_all)
348 pout("Maximum Data Transfer Size: -\n");
349
350 // Temperature thresholds are optional
351 char buf[64];
352 if (show_all || id_ctrl.wctemp)
353 jout("Warning Comp. Temp. Threshold: %s\n", kelvin_to_str(buf, id_ctrl.wctemp));
354 if (show_all || id_ctrl.cctemp)
355 jout("Critical Comp. Temp. Threshold: %s\n", kelvin_to_str(buf, id_ctrl.cctemp));
356
357 if (id_ctrl.wctemp) {
358 jglb["nvme_composite_temperature_threshold"]["warning"] = id_ctrl.wctemp - 273;
359 jglb["temperature"]["op_limit_max"] = id_ctrl.wctemp - 273;
360 }
361 if (id_ctrl.cctemp) {
362 jglb["nvme_composite_temperature_threshold"]["critical"] = id_ctrl.cctemp - 273;
363 jglb["temperature"]["critical_limit_max"] = id_ctrl.cctemp - 273;
364 }
365
366 // Figure 110 of NVM Express Base Specification Revision 1.3d, March 20, 2019
367 // Figure 249 of NVM Express Base Specification Revision 1.4c, March 9, 2021
368 // Figure 97 of NVM Express NVM Command Set Specification, Revision 1.0c, October 3, 2022
369 if (nsid && (show_all || id_ns.nsfeat)) {
370 const char * align = &(" "[nsid < 10 ? 0 : (nsid < 100 ? 1 : 2)]);
371 jout("Namespace %u Features (0x%02x): %s%s%s%s%s%s%s%s\n", nsid, id_ns.nsfeat, align,
372 (!id_ns.nsfeat ? " -" : ""),
373 ((id_ns.nsfeat & 0x01) ? " Thin_Prov" : ""),
374 ((id_ns.nsfeat & 0x02) ? " NA_Fields" : ""), // NVMe 1.2 ...
375 ((id_ns.nsfeat & 0x04) ? " Dea/Unw_Error" : ""),
376 ((id_ns.nsfeat & 0x08) ? " No_ID_Reuse" : ""), // NVMe 1.3
377 ((id_ns.nsfeat & 0x10) ? " NP_Fields" : ""), // NVMe 1.4
378 ((id_ns.nsfeat & ~0x1f) ? " *Other*" : ""));
379 }
380
381 json::ref jrns = jglb["nvme_namespaces"][0]; // Same as in print_drive_info()
382 if (nsid) {
383 jrns["id"] = nsid;
384 jrns["features"] += {
385 { "value", id_ns.nsfeat },
386 { "thin_provisioning", !!(id_ns.nsfeat & 0x01) },
387 { "na_fields", !!(id_ns.nsfeat & 0x02) }, // NVMe 1.2 ...
388 { "dealloc_or_unwritten_block_error", !!(id_ns.nsfeat & 0x04) },
389 { "uid_reuse", !!(id_ns.nsfeat & 0x08) }, // NVMe 1.3
390 { "np_fields", !!(id_ns.nsfeat & 0x10) }, // NVMe 1.4
391 { "other", id_ns.nsfeat & ~0x1f }
392 };
393 }
394
395 // Print Power States
396 jout("\nSupported Power States\n");
397 jout("St Op Max Active Idle RL RT WL WT Ent_Lat Ex_Lat\n");
398
399 for (int i = 0; i <= id_ctrl.npss /* 1-based */ && i < 32; i++) {
400 char p1[16], p2[16], p3[16];
401 const nvme_id_power_state & ps = id_ctrl.psd[i];
402 jout("%2d %c %9s %8s %8s %3d %2d %2d %2d %8u %7u\n", i,
403 ((ps.flags & 0x02) ? '-' : '+'),
404 format_power(p1, ps.max_power, ((ps.flags & 0x01) ? 1 : 2)),
407 ps.read_lat & 0x1f, ps.read_tput & 0x1f,
408 ps.write_lat & 0x1f, ps.write_tput & 0x1f,
409 ps.entry_lat, ps.exit_lat);
410
411 json::ref jrefi = jglb["nvme_power_states"][i];
412 jrefi += {
413 { "non_operational_state", !!(ps.flags & 0x02) },
414 { "relative_read_latency", ps.read_lat & 0x1f },
415 { "relative_read_throughput", ps.read_tput & 0x1f },
416 { "relative_write_latency", ps.write_lat & 0x1f },
417 { "relative_write_throughput", ps.write_tput & 0x1f },
418 { "entry_latency_us", ps.entry_lat },
419 { "exit_latency_us", ps.exit_lat }
420 };
421 format_power(jrefi, "max_power", ps.max_power, ((ps.flags & 0x01) ? 1 : 2));
422 format_power(jrefi, "active_power", ps.active_power, ps.active_work_scale);
423 format_power(jrefi, "idle_power", ps.idle_power, ps.idle_scale);
424 }
425
426 // Print LBA sizes
427 if (nsid && id_ns.lbaf[0].ds) {
428 jout("\nSupported LBA Sizes (NSID 0x%x)\n", nsid);
429 jout("Id Fmt Data Metadt Rel_Perf\n");
430 jrns["id"] = nsid;
431 for (int i = 0; i <= id_ns.nlbaf /* 1-based */ && i < 16; i++) {
432 const nvme_lbaf & lba = id_ns.lbaf[i];
433 if (!lba.ds)
434 continue; // not supported or not currently available
435 bool formatted = (i == id_ns.flbas);
436 jout("%2d %c %7u %7d %9d\n", i, (formatted ? '+' : '-'),
437 (1U << lba.ds), lba.ms, lba.rp);
438 jrns["lba_formats"][i] += {
439 { "formatted", formatted },
440 { "data_bytes", 1U << lba.ds },
441 { "metadata_bytes", lba.ms },
442 { "relative_performance", lba.rp }
443 };
444 }
445 }
446}
447
448static void print_critical_warning(unsigned char w)
449{
450 jout("SMART overall-health self-assessment test result: %s\n",
451 (!w ? "PASSED" : "FAILED!"));
452 jglb["smart_status"]["passed"] = !w;
453
454 json::ref jref = jglb["smart_status"]["nvme"];
455 jref["value"] = w;
456
457 if (w) {
458 if (w & 0x01)
459 jout("- available spare has fallen below threshold\n");
460 jref["spare_below_threshold"] = !!(w & 0x01);
461 if (w & 0x02)
462 jout("- temperature is above or below threshold\n");
463 jref["temperature_above_or_below_threshold"] = !!(w & 0x02);
464 if (w & 0x04)
465 jout("- NVM subsystem reliability has been degraded\n");
466 jref["reliability_degraded"] = !!(w & 0x04);
467 if (w & 0x08)
468 jout("- media has been placed in read only mode\n");
469 jref["media_read_only"] = !!(w & 0x08);
470 if (w & 0x10)
471 jout("- volatile memory backup device has failed\n");
472 jref["volatile_memory_backup_failed"] = !!(w & 0x10);
473 if (w & 0x20)
474 jout("- persistent memory region has become read-only or unreliable\n");
475 jref["persistent_memory_region_unreliable"] = !!(w & 0x20);
476 if (w & ~0x3f)
477 jout("- unknown critical warning(s) (0x%02x)\n", w & ~0x3f);
478 jref["other"] = w & ~0x3f;
479 }
480
481 jout("\n");
482}
483
484static void print_smart_log(const nvme_smart_log & smart_log,
485 const nvme_id_ctrl & id_ctrl, unsigned nsid, bool show_all)
486{
487 json::ref jref = jglb["nvme_smart_health_information_log"];
488 char buf[64];
489 jout("SMART/Health Information (NVMe Log 0x02, NSID 0x%x)\n", nsid);
490 jout("Critical Warning: 0x%02x\n", smart_log.critical_warning);
491 jref["critical_warning"] = smart_log.critical_warning;
492
493 int k = sg_get_unaligned_le16(smart_log.temperature);
494 jout("Temperature: %s\n", kelvin_to_str(buf, k));
495 if (k) {
496 jref["temperature"] = k - 273;
497 jglb["temperature"]["current"] = k - 273;
498 }
499
500 jout("Available Spare: %u%%\n", smart_log.avail_spare);
501 jref["available_spare"] = smart_log.avail_spare;
502 jout("Available Spare Threshold: %u%%\n", smart_log.spare_thresh);
503 jref["available_spare_threshold"] = smart_log.spare_thresh;
504 jglb["spare_available"] += {
505 {"current_percent", smart_log.avail_spare},
506 {"threshold_percent", smart_log.spare_thresh}
507 };
508 jout("Percentage Used: %u%%\n", smart_log.percent_used);
509 jref["percentage_used"] = smart_log.percent_used;
510 jglb["endurance_used"]["current_percent"] = smart_log.percent_used;
511 jout("Data Units Read: %s\n", le128_to_str(buf, smart_log.data_units_read, 1000*512));
512 jref["data_units_read"].set_unsafe_le128(smart_log.data_units_read);
513 jout("Data Units Written: %s\n", le128_to_str(buf, smart_log.data_units_written, 1000*512));
514 jref["data_units_written"].set_unsafe_le128(smart_log.data_units_written);
515 jout("Host Read Commands: %s\n", le128_to_str(buf, smart_log.host_reads));
516 jref["host_reads"].set_unsafe_le128(smart_log.host_reads);
517 jout("Host Write Commands: %s\n", le128_to_str(buf, smart_log.host_writes));
518 jref["host_writes"].set_unsafe_le128(smart_log.host_writes);
519 jout("Controller Busy Time: %s\n", le128_to_str(buf, smart_log.ctrl_busy_time));
520 jref["controller_busy_time"].set_unsafe_le128(smart_log.ctrl_busy_time);
521 jout("Power Cycles: %s\n", le128_to_str(buf, smart_log.power_cycles));
522 jref["power_cycles"].set_unsafe_le128(smart_log.power_cycles);
523 jglb["power_cycle_count"].set_if_safe_le128(smart_log.power_cycles);
524 jout("Power On Hours: %s\n", le128_to_str(buf, smart_log.power_on_hours));
525 jref["power_on_hours"].set_unsafe_le128(smart_log.power_on_hours);
526 jglb["power_on_time"]["hours"].set_if_safe_le128(smart_log.power_on_hours);
527 jout("Unsafe Shutdowns: %s\n", le128_to_str(buf, smart_log.unsafe_shutdowns));
528 jref["unsafe_shutdowns"].set_unsafe_le128(smart_log.unsafe_shutdowns);
529 jout("Media and Data Integrity Errors: %s\n", le128_to_str(buf, smart_log.media_errors));
530 jref["media_errors"].set_unsafe_le128(smart_log.media_errors);
531 jout("Error Information Log Entries: %s\n", le128_to_str(buf, smart_log.num_err_log_entries));
532 jref["num_err_log_entries"].set_unsafe_le128(smart_log.num_err_log_entries);
533
534 // Temperature thresholds are optional
535 if (show_all || id_ctrl.wctemp || smart_log.warning_temp_time) {
536 jout("Warning Comp. Temperature Time: %d\n", smart_log.warning_temp_time);
537 jref["warning_temp_time"] = smart_log.warning_temp_time;
538 }
539 if (show_all || id_ctrl.cctemp || smart_log.critical_comp_time) {
540 jout("Critical Comp. Temperature Time: %d\n", smart_log.critical_comp_time);
541 jref["critical_comp_time"] = smart_log.critical_comp_time;
542 }
543
544 // Temperature sensors are optional
545 for (int i = 0; i < 8; i++) {
546 k = smart_log.temp_sensor[i];
547 if (show_all || k) {
548 jout("Temperature Sensor %d: %s\n", i + 1,
549 kelvin_to_str(buf, k));
550 if (k)
551 jref["temperature_sensors"][i] = k - 273;
552 }
553 }
554 if (show_all || smart_log.thm_temp1_trans_count)
555 pout("Thermal Temp. 1 Transition Count: %d\n", smart_log.thm_temp1_trans_count);
556 if (show_all || smart_log.thm_temp2_trans_count)
557 pout("Thermal Temp. 2 Transition Count: %d\n", smart_log.thm_temp2_trans_count);
558 if (show_all || smart_log.thm_temp1_total_time)
559 pout("Thermal Temp. 1 Total Time: %d\n", smart_log.thm_temp1_total_time);
560 if (show_all || smart_log.thm_temp2_total_time)
561 pout("Thermal Temp. 2 Total Time: %d\n", smart_log.thm_temp2_total_time);
562 pout("\n");
563}
564
565static void print_error_log(const nvme_error_log_page * error_log,
566 unsigned read_entries, unsigned max_entries)
567{
568 // Figure 93 of NVM Express Base Specification Revision 1.3d, March 20, 2019
569 // Figure 197 of NVM Express Base Specification Revision 1.4c, March 9, 2021
570 json::ref jref = jglb["nvme_error_information_log"];
571 jout("Error Information (NVMe Log 0x01, %u of %u entries)\n",
572 read_entries, max_entries);
573
574 // Search last valid entry
575 unsigned valid_entries = read_entries;
576 while (valid_entries && !error_log[valid_entries-1].error_count)
577 valid_entries--;
578
579 unsigned unread_entries = 0;
580 if (valid_entries == read_entries && read_entries < max_entries)
581 unread_entries = max_entries - read_entries;
582 jref += {
583 { "size", max_entries },
584 { "read", read_entries },
585 { "unread", unread_entries },
586 };
587
588 if (!valid_entries) {
589 jout("No Errors Logged\n\n");
590 return;
591 }
592
593 jout("Num ErrCount SQId CmdId Status PELoc LBA NSID VS Message\n");
594 int unused = 0;
595 for (unsigned i = 0; i < valid_entries; i++) {
596 const nvme_error_log_page & e = error_log[i];
597 if (!e.error_count) {
598 // unused or invalid entry
599 unused++;
600 continue;
601 }
602 if (unused) {
603 jout(" - [%d unused entr%s]\n", unused, (unused == 1 ? "y" : "ies"));
604 unused = 0;
605 }
606
607 json::ref jrefi = jref["table"][i];
608 jrefi["error_count"] = e.error_count;
609 const char * msg = "-"; char msgbuf[64]{};
610 char sq[16] = "-", cm[16] = "-", st[16] = "-", pe[16] = "-";
611 char lb[32] = "-", ns[16] = "-", vs[8] = "-";
612 if (e.sqid != 0xffff) {
613 snprintf(sq, sizeof(sq), "%d", e.sqid);
614 jrefi["submission_queue_id"] = e.sqid;
615 }
616 if (e.cmdid != 0xffff) {
617 snprintf(cm, sizeof(cm), "0x%04x", e.cmdid);
618 jrefi["command_id"] = e.cmdid;
619 }
620 if (e.status_field != 0xffff) {
621 snprintf(st, sizeof(st), "0x%04x", e.status_field);
622 uint16_t s = e.status_field >> 1;
623 msg = nvme_status_to_info_str(msgbuf, s);
624 jrefi += {
625 { "status_field", {
626 { "value", s },
627 { "do_not_retry", !!(s & 0x4000) },
628 { "status_code_type", (s >> 8) & 0x7 },
629 { "status_code" , (uint8_t)s },
630 { "string", msg }
631 }},
632 { "phase_tag", !!(e.status_field & 0x0001) }
633 };
634 }
635 if (e.parm_error_location != 0xffff) {
636 snprintf(pe, sizeof(pe), "0x%03x", e.parm_error_location);
637 jrefi["parm_error_location"] = e.parm_error_location;
638 }
639 if (e.lba != 0xffffffffffffffffULL) {
640 snprintf(lb, sizeof(lb), "%" PRIu64, e.lba);
641 jrefi["lba"]["value"].set_unsafe_uint64(e.lba);
642 }
643 if (e.nsid != nvme_broadcast_nsid) {
644 snprintf(ns, sizeof(ns), "%u", e.nsid);
645 jrefi["nsid"] = e.nsid;
646 }
647 if (e.vs != 0x00) {
648 snprintf(vs, sizeof(vs), "0x%02x", e.vs);
649 jrefi["vendor_specific"] = e.vs;
650 }
651 // TODO: TRTYPE, command/transport specific information
652
653 jout("%3u %10" PRIu64 " %5s %7s %7s %6s %12s %5s %5s %s\n",
654 i, e.error_count, sq, cm, st, pe, lb, ns, vs, msg);
655 }
656
657 if (unread_entries)
658 jout("... (%u entries not read)\n", unread_entries);
659 jout("\n");
660}
661
662static void print_self_test_log(const nvme_self_test_log & self_test_log, unsigned nsid)
663{
664 // Figure 99 of NVM Express Base Specification Revision 1.3d, March 20, 2019
665 // Figure 203 of NVM Express Base Specification Revision 1.4c, March 9, 2021
666 json::ref jref = jglb["nvme_self_test_log"];
667 jout("Self-test Log (NVMe Log 0x06, NSID 0x%x)\n", nsid);
668 jref["nsid"] = (nsid != nvme_broadcast_nsid ? (int64_t)nsid : -1);
669
670 const char * s; char buf[32];
671 switch (self_test_log.current_operation & 0xf) {
672 case 0x0: s = "No self-test in progress"; break;
673 case 0x1: s = "Short self-test in progress"; break;
674 case 0x2: s = "Extended self-test in progress"; break;
675 case 0xe: s = "Vendor specific self-test in progress"; break;
676 default: snprintf(buf, sizeof(buf), "Unknown status (0x%x)",
677 self_test_log.current_operation & 0xf);
678 s = buf; break;
679 }
680 jout("Self-test status: %s", s);
681 jref["current_self_test_operation"] += {
682 { "value", self_test_log.current_operation & 0xf },
683 { "string", s }
684 };
685 if (self_test_log.current_operation & 0xf) {
686 jout(" (%d%% completed)", self_test_log.current_completion & 0x7f);
687 jref["current_self_test_completion_percent"] = self_test_log.current_completion & 0x7f;
688 }
689 jout("\n");
690
691 int cnt = 0;
692 for (unsigned i = 0; i < 20; i++) {
693 const nvme_self_test_result & r = self_test_log.results[i];
694 uint8_t op = r.self_test_status >> 4;
695 uint8_t res = r.self_test_status & 0xf;
696 if (!op || res == 0xf)
697 continue; // unused entry
698
699 json::ref jrefi = jref["table"][i];
700 const char * t; char buf2[32];
701 switch (op) {
702 case 0x1: t = "Short"; break;
703 case 0x2: t = "Extended"; break;
704 case 0xe: t = "Vendor specific"; break;
705 default: snprintf(buf2, sizeof(buf2), "Unknown (0x%x)", op);
706 t = buf2; break;
707 }
708
709 switch (res) {
710 case 0x0: s = "Completed without error"; break;
711 case 0x1: s = "Aborted: Self-test command"; break;
712 case 0x2: s = "Aborted: Controller Reset"; break;
713 case 0x3: s = "Aborted: Namespace removed"; break;
714 case 0x4: s = "Aborted: Format NVM command"; break;
715 case 0x5: s = "Fatal or unknown test error"; break;
716 case 0x6: s = "Completed: unknown failed segment"; break;
717 case 0x7: s = "Completed: failed segments"; break;
718 case 0x8: s = "Aborted: unknown reason"; break;
719 case 0x9: s = "Aborted: sanitize operation"; break;
720 default: snprintf(buf, sizeof(buf), "Unknown result (0x%x)", res);
721 s = buf; break;
722 }
723
724 uint64_t poh = sg_get_unaligned_le64(r.power_on_hours);
725
726 jrefi += {
727 { "self_test_code", { { "value", op }, { "string", t } } },
728 { "self_test_result", { { "value", res }, { "string", s } } },
729 { "power_on_hours", poh }
730 };
731
732 char sg[8] = "-", ns[16] = "-", lb[32] = "-", st[8] = "-", sc[8] = "-";
733 if (res == 0x7) {
734 snprintf(sg, sizeof(sg), "%d", r.segment);
735 jrefi["segment"] = r.segment;
736 }
737 if (r.valid & 0x01) {
738 if (r.nsid == nvme_broadcast_nsid)
739 ns[0] = '*', ns[1] = 0;
740 else
741 snprintf(ns, sizeof(ns), "%u", r.nsid);
742 // Broadcast = -1
743 jrefi["nsid"] = (r.nsid != nvme_broadcast_nsid ? (int64_t)r.nsid : -1);
744 }
745 if (r.valid & 0x02) {
746 uint64_t lba = sg_get_unaligned_le64(r.lba);
747 snprintf(lb, sizeof(lb), "%" PRIu64, lba);
748 jrefi["lba"] = lba;
749 }
750 if (r.valid & 0x04) {
751 snprintf(st, sizeof(st), "0x%x", r.status_code_type);
752 jrefi["status_code_type"] = r.status_code_type;
753 }
754 if (r.valid & 0x08) {
755 snprintf(sc, sizeof(sc), "0x%02x", r.status_code);
756 jrefi["status_code"] = r.status_code;
757 }
758
759 if (++cnt == 1)
760 jout("Num Test_Description Status Power_on_Hours Failing_LBA NSID Seg SCT Code\n");
761 jout("%2u %-17s %-33s %9" PRIu64 " %12s %5s %3s %3s %4s\n", i, t, s, poh, lb, ns, sg, st, sc);
762 }
763
764 if (!cnt)
765 jout("No Self-tests Logged\n");
766 jout("\n");
767}
768
769int nvmePrintMain(nvme_device * device, const nvme_print_options & options)
770{
771 if (!( options.drive_info || options.drive_capabilities
772 || options.smart_check_status || options.smart_vendor_attrib
773 || options.smart_selftest_log || options.error_log_entries
774 || options.log_page_size || options.smart_selftest_type )) {
775 pout("NVMe device successfully opened\n\n"
776 "Use 'smartctl -a' (or '-x') to print SMART (and more) information\n\n");
777 return 0;
778 }
779
780 // Show unset optional values only if debugging is enabled
781 bool show_all = (nvme_debugmode > 0);
782
783 // Read Identify Controller always
784 nvme_id_ctrl id_ctrl;
785 if (!nvme_read_id_ctrl(device, id_ctrl)) {
786 jerr("Read NVMe Identify Controller failed: %s\n", device->get_errmsg());
787 return FAILID;
788 }
789
790 // Print Identify Controller/Namespace info
791 if (options.drive_info || options.drive_capabilities) {
792 pout("=== START OF INFORMATION SECTION ===\n");
793 nvme_id_ns id_ns; memset(&id_ns, 0, sizeof(id_ns));
794
795 unsigned nsid = device->get_nsid();
796 if (nsid == nvme_broadcast_nsid) {
797 // Broadcast namespace
798 if (id_ctrl.nn == 1) {
799 // No namespace management, get size from single namespace
800 nsid = 1;
801 if (!nvme_read_id_ns(device, nsid, id_ns))
802 nsid = 0;
803 }
804 }
805 else {
806 // Identify current namespace
807 if (!nvme_read_id_ns(device, nsid, id_ns)) {
808 jerr("Read NVMe Identify Namespace 0x%x failed: %s\n", nsid, device->get_errmsg());
809 return FAILID;
810 }
811 }
812
813 if (options.drive_info)
814 print_drive_info(id_ctrl, id_ns, nsid, show_all);
815 if (options.drive_capabilities)
816 print_drive_capabilities(id_ctrl, id_ns, nsid, show_all);
817 pout("\n");
818 }
819
820 if ( options.smart_check_status || options.smart_vendor_attrib
821 || options.error_log_entries || options.smart_selftest_log )
822 pout("=== START OF SMART DATA SECTION ===\n");
823
824 // Print SMART Status and SMART/Health Information
825 int retval = 0;
826 if (options.smart_check_status || options.smart_vendor_attrib) {
827 // Use individual NSID if SMART/Health Information per namespace is supported
828 unsigned smart_log_nsid = ((id_ctrl.lpa & 0x01) ? device->get_nsid()
830
831 nvme_smart_log smart_log;
832 if (!nvme_read_smart_log(device, smart_log_nsid, smart_log)) {
833 jerr("Read NVMe SMART/Health Information (NSID 0x%x) failed: %s\n\n", smart_log_nsid,
834 device->get_errmsg());
835 return FAILSMART;
836 }
837
838 if (options.smart_check_status) {
840 if (smart_log.critical_warning)
841 retval |= FAILSTATUS;
842 }
843
844 if (options.smart_vendor_attrib) {
845 print_smart_log(smart_log, id_ctrl, smart_log_nsid, show_all);
846 }
847 }
848
849 // Check for Log Page Offset support
850 bool lpo_sup = !!(id_ctrl.lpa & 0x04);
851
852 // Print Error Information Log
853 if (options.error_log_entries) {
854 unsigned max_entries = id_ctrl.elpe + 1; // 0's based value
855 unsigned want_entries = options.error_log_entries;
856 if (want_entries > max_entries)
857 want_entries = max_entries;
858 raw_buffer error_log_buf(want_entries * sizeof(nvme_error_log_page));
859 nvme_error_log_page * error_log =
860 reinterpret_cast<nvme_error_log_page *>(error_log_buf.data());
861
862 unsigned read_entries = nvme_read_error_log(device, error_log, want_entries, lpo_sup);
863 if (!read_entries) {
864 jerr("Read %u entries from Error Information Log failed: %s\n\n",
865 want_entries, device->get_errmsg());
866 return retval | FAILSMART;
867 }
868 if (read_entries < want_entries)
869 jerr("Read Error Information Log failed, %u entries missing: %s\n",
870 want_entries - read_entries, device->get_errmsg());
871
872 print_error_log(error_log, read_entries, max_entries);
873 }
874
875 // Check for self-test support
876 bool self_test_sup = !!(id_ctrl.oacs & 0x0010);
877
878 // Read and print Self-test log, check for running test
879 int self_test_completion = -1;
880 if (options.smart_selftest_log || options.smart_selftest_type) {
881 if (!self_test_sup)
882 pout("Self-tests not supported\n\n");
883 else {
884 nvme_self_test_log self_test_log;
885 unsigned self_test_log_nsid = nvme_broadcast_nsid;
886 if (!nvme_read_self_test_log(device, self_test_log_nsid, self_test_log)) {
887 jerr("Read Self-test Log failed: %s\n\n", device->get_errmsg());
888 return retval | FAILSMART;
889 }
890
891 if (options.smart_selftest_log)
892 print_self_test_log(self_test_log, self_test_log_nsid);
893
894 if (self_test_log.current_operation & 0xf)
895 self_test_completion = self_test_log.current_completion & 0x7f;
896 }
897 }
898
899 // Dump log page
900 if (options.log_page_size) {
901 // Align size to dword boundary
902 unsigned size = ((options.log_page_size + 4-1) / 4) * 4;
903 raw_buffer log_buf(size);
904
905 unsigned nsid;
906 switch (options.log_page) {
907 case 1:
908 case 2:
909 case 3:
911 break;
912 default:
913 nsid = device->get_nsid();
914 break;
915 }
916 unsigned read_bytes = nvme_read_log_page(device, nsid, options.log_page, log_buf.data(),
917 size, lpo_sup);
918 if (!read_bytes) {
919 jerr("Read NVMe Log 0x%02x (NSID 0x%x) failed: %s\n\n", options.log_page, nsid,
920 device->get_errmsg());
921 return retval | FAILSMART;
922 }
923 if (read_bytes < size)
924 jerr("Read NVMe Log 0x%02x failed, 0x%x bytes missing: %s\n",
925 options.log_page, size - read_bytes, device->get_errmsg());
926
927 pout("NVMe Log 0x%02x (NSID 0x%x, 0x%04x bytes)\n", options.log_page, nsid, read_bytes);
928 dStrHex(log_buf.data(), read_bytes, 0);
929 pout("\n");
930 }
931
932 // Start self-test
933 if (self_test_sup && options.smart_selftest_type) {
934 bool self_test_abort = (options.smart_selftest_type == 0xf);
935 if (!self_test_abort && self_test_completion >= 0) {
936 pout("Can't start self-test without aborting current test (%2d%% completed)\n"
937 "Use smartctl -X to abort test\n", self_test_completion);
938 retval |= FAILSMART;
939 }
940 else {
941 // TODO: Support NSID=0 to test controller
942 unsigned self_test_nsid = device->get_nsid();
943 if (!nvme_self_test(device, options.smart_selftest_type, self_test_nsid)) {
944 jerr("NVMe Self-test cmd with type=0x%x, nsid=0x%x failed: %s\n\n",
945 options.smart_selftest_type, self_test_nsid, device->get_errmsg());
946 return retval | FAILSMART;
947 }
948
949 if (!self_test_abort)
950 pout("Self-test has begun (NSID 0x%x)\n"
951 "Use smartctl -X to abort test\n", self_test_nsid);
952 else
953 pout("Self-test aborted! (NSID 0x%x)\n", self_test_nsid);
954 }
955 }
956
957 return retval;
958}
bool dont_print_serial_number
Definition: atacmds.cpp:37
Reference to a JSON element.
Definition: json.h:105
void set_unsafe_uint128(uint64_t value_hi, uint64_t value_lo)
Definition: json.cpp:205
void set_unsafe_le128(const void *pvalue)
Definition: json.cpp:231
void set_unsafe_uint64(uint64_t value)
Definition: json.cpp:193
NVMe device access.
unsigned get_nsid() const
Get namespace id.
unsigned char * data()
Definition: utility.h:148
const char * get_errmsg() const
Get last error message.
u32 w[3]
Definition: megaraid.h:19
u16 s[6]
Definition: megaraid.h:18
u32 size
Definition: megaraid.h:0
uint32_t nsid
bool nvme_read_self_test_log(nvme_device *device, uint32_t nsid, smartmontools::nvme_self_test_log &self_test_log)
Definition: nvmecmds.cpp:270
bool nvme_read_id_ns(nvme_device *device, unsigned nsid, nvme_id_ns &id_ns)
Definition: nvmecmds.cpp:169
bool nvme_read_id_ctrl(nvme_device *device, nvme_id_ctrl &id_ctrl)
Definition: nvmecmds.cpp:132
unsigned char nvme_debugmode
Definition: nvmecmds.cpp:27
bool nvme_self_test(nvme_device *device, uint8_t stc, uint32_t nsid)
Definition: nvmecmds.cpp:285
unsigned nvme_read_log_page(nvme_device *device, unsigned nsid, unsigned char lid, void *data, unsigned size, bool lpo_sup, unsigned offset)
Definition: nvmecmds.cpp:208
unsigned nvme_read_error_log(nvme_device *device, nvme_error_log_page *error_log, unsigned num_entries, bool lpo_sup)
Definition: nvmecmds.cpp:231
bool nvme_read_smart_log(nvme_device *device, uint32_t nsid, nvme_smart_log &smart_log)
Definition: nvmecmds.cpp:254
const char * nvme_status_to_info_str(char *buf, size_t bufsize, uint16_t status)
Definition: nvmecmds.cpp:490
constexpr uint32_t nvme_broadcast_nsid
Definition: nvmecmds.h:257
static void print_self_test_log(const nvme_self_test_log &self_test_log, unsigned nsid)
Definition: nvmeprint.cpp:662
static void print_drive_info(const nvme_id_ctrl &id_ctrl, const nvme_id_ns &id_ns, unsigned nsid, bool show_all)
Definition: nvmeprint.cpp:108
static const char * le128_to_str(char(&str)[64], uint64_t hi, uint64_t lo, unsigned bytes_per_unit)
Definition: nvmeprint.cpp:43
static void print_smart_log(const nvme_smart_log &smart_log, const nvme_id_ctrl &id_ctrl, unsigned nsid, bool show_all)
Definition: nvmeprint.cpp:484
static void print_drive_capabilities(const nvme_id_ctrl &id_ctrl, const nvme_id_ns &id_ns, unsigned nsid, bool show_all)
Definition: nvmeprint.cpp:237
int nvmePrintMain(nvme_device *device, const nvme_print_options &options)
Definition: nvmeprint.cpp:769
static const char * format_power(char(&str)[16], unsigned power, unsigned scale)
Definition: nvmeprint.cpp:211
static void lbacap_to_js(const json::ref &jref, uint64_t lba_cnt, int lba_bits)
Definition: nvmeprint.cpp:92
static const char * kelvin_to_str(char(&str)[64], int k)
Definition: nvmeprint.cpp:99
static void print_critical_warning(unsigned char w)
Definition: nvmeprint.cpp:448
static void print_error_log(const nvme_error_log_page *error_log, unsigned read_entries, unsigned max_entries)
Definition: nvmeprint.cpp:565
static const char * lbacap_to_str(char(&str)[64], uint64_t lba_cnt, int lba_bits)
Definition: nvmeprint.cpp:86
static bool le128_is_non_zero(const unsigned char(&val)[16])
Definition: nvmeprint.cpp:32
const char * nvmeprint_cvsid
Definition: nvmeprint.cpp:16
#define NVMEPRINT_H_CVSID
Definition: nvmeprint.h:14
void dStrHex(const uint8_t *up, int len, int no_ascii)
Definition: scsicmds.cpp:368
static uint64_t sg_get_unaligned_le64(const void *p)
Definition: sg_unaligned.h:303
static uint64_t sg_get_unaligned_be(int num_bytes, const void *p)
Definition: sg_unaligned.h:350
static uint16_t sg_get_unaligned_le16(const void *p)
Definition: sg_unaligned.h:292
static uint64_t sg_get_unaligned_le(int num_bytes, const void *p)
Definition: sg_unaligned.h:413
void jout_startup_datetime(const char *prefix)
Definition: smartctl.cpp:1453
json jglb
Definition: smartctl.cpp:53
#define FAILID
Definition: smartctl.h:30
#define FAILSTATUS
Definition: smartctl.h:36
#define FAILSMART
Definition: smartctl.h:33
void void void void jerr(const char *fmt,...) __attribute_format_printf(1
void jout(const char *fmt,...) __attribute_format_printf(1
void pout(const char *fmt,...)
Definition: smartd.cpp:1335
bool smart_selftest_log
Definition: nvmeprint.h:25
unsigned char smart_selftest_type
Definition: nvmeprint.h:26
unsigned char log_page
Definition: nvmeprint.h:28
unsigned log_page_size
Definition: nvmeprint.h:29
bool smart_vendor_attrib
Definition: nvmeprint.h:24
unsigned error_log_entries
Definition: nvmeprint.h:27
bool drive_capabilities
Definition: nvmeprint.h:22
bool smart_check_status
Definition: nvmeprint.h:23
unsigned short parm_error_location
Definition: nvmecmds.h:39
unsigned short wctemp
Definition: nvmecmds.h:92
unsigned short ssvid
Definition: nvmecmds.h:68
unsigned short cntlid
Definition: nvmecmds.h:76
unsigned char unvmcap[16]
Definition: nvmecmds.h:98
struct nvme_id_power_state psd[32]
Definition: nvmecmds.h:133
unsigned char ieee[3]
Definition: nvmecmds.h:73
unsigned short vid
Definition: nvmecmds.h:67
unsigned char tnvmcap[16]
Definition: nvmecmds.h:97
unsigned short oacs
Definition: nvmecmds.h:83
unsigned short cctemp
Definition: nvmecmds.h:93
struct nvme_lbaf lbaf[16]
Definition: nvmecmds.h:170
unsigned char nsfeat
Definition: nvmecmds.h:149
unsigned char nlbaf
Definition: nvmecmds.h:150
unsigned char flbas
Definition: nvmecmds.h:151
unsigned char eui64[8]
Definition: nvmecmds.h:169
unsigned short ms
Definition: nvmecmds.h:139
unsigned char ds
Definition: nvmecmds.h:140
unsigned char rp
Definition: nvmecmds.h:141
nvme_self_test_result results[20]
Definition: nvmecmds.h:248
unsigned char data_units_read[16]
Definition: nvmecmds.h:183
unsigned char spare_thresh
Definition: nvmecmds.h:180
unsigned char critical_warning
Definition: nvmecmds.h:177
unsigned char host_writes[16]
Definition: nvmecmds.h:186
unsigned char data_units_written[16]
Definition: nvmecmds.h:184
unsigned char power_on_hours[16]
Definition: nvmecmds.h:189
unsigned int thm_temp1_total_time
Definition: nvmecmds.h:198
unsigned char host_reads[16]
Definition: nvmecmds.h:185
unsigned char temperature[2]
Definition: nvmecmds.h:178
unsigned char power_cycles[16]
Definition: nvmecmds.h:188
unsigned char media_errors[16]
Definition: nvmecmds.h:191
unsigned char percent_used
Definition: nvmecmds.h:181
unsigned int critical_comp_time
Definition: nvmecmds.h:194
unsigned char num_err_log_entries[16]
Definition: nvmecmds.h:192
unsigned short temp_sensor[8]
Definition: nvmecmds.h:195
unsigned char unsafe_shutdowns[16]
Definition: nvmecmds.h:190
unsigned char ctrl_busy_time[16]
Definition: nvmecmds.h:187
unsigned int thm_temp2_total_time
Definition: nvmecmds.h:199
unsigned int thm_temp2_trans_count
Definition: nvmecmds.h:197
unsigned int warning_temp_time
Definition: nvmecmds.h:193
unsigned int thm_temp1_trans_count
Definition: nvmecmds.h:196
const char * format_char_array(char *str, int strsize, const char *chr, int chrsize)
Definition: utility.cpp:692
const char * format_capacity(char *str, int strsize, uint64_t val, const char *decimal_point)
Definition: utility.cpp:748
const char * format_with_thousands_sep(char *str, int strsize, uint64_t val, const char *thousands_sep)
Definition: utility.cpp:716
bool nonempty(const void *data, int size)
Definition: utility.cpp:682
const char * uint128_hilo_to_str(char *str, int strsize, uint64_t value_hi, uint64_t value_lo)
Definition: utility.cpp:856
int uint128_to_str_precision_bits()
Definition: utility.h:296