2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2013 EMC Corp.
7 * Copyright (C) 2012-2013 Intel Corporation
9 * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/ioccom.h>
49 #include <sys/endian.h>
51 #include "nvmecontrol.h"
53 /* Tables for command line parsing */
55 static cmd_fn_t logpage;
57 #define NONE 0xffffffffu
58 static struct options {
78 static const struct opts logpage_opts[] = {
79 #define OPT(l, s, t, opt, addr, desc) { l, s, t, &opt.addr, desc }
80 OPT("binary", 'b', arg_none, opt, binary,
81 "Dump the log page as binary"),
82 OPT("hex", 'x', arg_none, opt, hex,
83 "Dump the log page as hex"),
84 OPT("page", 'p', arg_uint32, opt, page,
86 OPT("lsp", 'f', arg_uint8, opt, lsp,
87 "Log Specific Field"),
88 OPT("lsi", 'i', arg_uint16, opt, lsi,
89 "Log Specific Identifier"),
90 OPT("rae", 'r', arg_none, opt, rae,
91 "Retain Asynchronous Event"),
92 OPT("vendor", 'v', arg_string, opt, vendor,
93 "Vendor specific formatting"),
94 { NULL, 0, arg_none, NULL, NULL }
98 static const struct args logpage_args[] = {
99 { arg_string, &opt.dev, "<controller id|namespace id>" },
100 { arg_none, NULL, NULL },
103 static struct cmd logpage_cmd = {
106 .descr = "Print logpages in human-readable form",
107 .ctx_size = sizeof(opt),
108 .opts = logpage_opts,
109 .args = logpage_args,
112 CMD_COMMAND(logpage_cmd);
114 /* End of tables for command line parsing */
116 #define MAX_FW_SLOTS (7)
118 static SLIST_HEAD(,logpage_function) logpages;
121 logpage_compare(struct logpage_function *a, struct logpage_function *b)
125 if ((a->vendor == NULL) != (b->vendor == NULL))
126 return (a->vendor == NULL ? -1 : 1);
127 if (a->vendor != NULL) {
128 c = strcmp(a->vendor, b->vendor);
132 return ((int)a->log_page - (int)b->log_page);
136 logpage_register(struct logpage_function *p)
138 struct logpage_function *l, *a;
141 l = SLIST_FIRST(&logpages);
143 if (logpage_compare(l, p) > 0)
146 l = SLIST_NEXT(l, link);
149 SLIST_INSERT_HEAD(&logpages, p, link);
151 SLIST_INSERT_AFTER(a, p, link);
155 kv_lookup(const struct kv_name *kv, size_t kv_count, uint32_t key)
160 for (i = 0; i < kv_count; i++, kv++)
163 snprintf(bad, sizeof(bad), "Attribute %#x", key);
168 print_log_hex(const struct nvme_controller_data *cdata __unused, void *data, uint32_t length)
171 print_hex(data, length);
175 print_bin(const struct nvme_controller_data *cdata __unused, void *data, uint32_t length)
178 write(STDOUT_FILENO, data, length);
182 get_log_buffer(uint32_t size)
186 if ((buf = malloc(size)) == NULL)
187 errx(EX_OSERR, "unable to malloc %u bytes", size);
189 memset(buf, 0, size);
194 read_logpage(int fd, uint8_t log_page, uint32_t nsid, uint8_t lsp,
195 uint16_t lsi, uint8_t rae, void *payload, uint32_t payload_size)
197 struct nvme_pt_command pt;
198 struct nvme_error_information_entry *err_entry;
199 u_int i, err_pages, numd;
201 numd = payload_size / sizeof(uint32_t) - 1;
202 memset(&pt, 0, sizeof(pt));
203 pt.cmd.opc = NVME_OPC_GET_LOG_PAGE;
204 pt.cmd.nsid = htole32(nsid);
205 pt.cmd.cdw10 = htole32(
206 (numd << 16) | /* NUMDL */
207 (rae << 15) | /* RAE */
208 (lsp << 8) | /* LSP */
210 pt.cmd.cdw11 = htole32(
211 ((uint32_t)lsi << 16) | /* LSI */
212 (numd >> 16)); /* NUMDU */
213 pt.cmd.cdw12 = 0; /* LPOL */
214 pt.cmd.cdw13 = 0; /* LPOU */
215 pt.cmd.cdw14 = 0; /* UUID Index */
217 pt.len = payload_size;
220 if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0)
221 err(EX_IOERR, "get log page request failed");
223 /* Convert data to host endian */
226 err_entry = (struct nvme_error_information_entry *)payload;
227 err_pages = payload_size / sizeof(struct nvme_error_information_entry);
228 for (i = 0; i < err_pages; i++)
229 nvme_error_information_entry_swapbytes(err_entry++);
231 case NVME_LOG_HEALTH_INFORMATION:
232 nvme_health_information_page_swapbytes(
233 (struct nvme_health_information_page *)payload);
235 case NVME_LOG_FIRMWARE_SLOT:
236 nvme_firmware_page_swapbytes(
237 (struct nvme_firmware_page *)payload);
239 case NVME_LOG_CHANGED_NAMESPACE:
240 nvme_ns_list_swapbytes((struct nvme_ns_list *)payload);
242 case NVME_LOG_DEVICE_SELF_TEST:
243 nvme_device_self_test_swapbytes(
244 (struct nvme_device_self_test_page *)payload);
246 case NVME_LOG_COMMAND_EFFECT:
247 nvme_command_effects_page_swapbytes(
248 (struct nvme_command_effects_page *)payload);
250 case NVME_LOG_RES_NOTIFICATION:
251 nvme_res_notification_page_swapbytes(
252 (struct nvme_res_notification_page *)payload);
254 case NVME_LOG_SANITIZE_STATUS:
255 nvme_sanitize_status_page_swapbytes(
256 (struct nvme_sanitize_status_page *)payload);
258 case INTEL_LOG_TEMP_STATS:
259 intel_log_temp_stats_swapbytes(
260 (struct intel_log_temp_stats *)payload);
266 if (nvme_completion_is_error(&pt.cpl))
267 errx(EX_IOERR, "get log page request returned error");
271 print_log_error(const struct nvme_controller_data *cdata __unused, void *buf, uint32_t size)
275 uint8_t p, sc, sct, m, dnr;
276 struct nvme_error_information_entry *entry = buf;
278 printf("Error Information Log\n");
279 printf("=====================\n");
281 if (entry->error_count == 0) {
282 printf("No error entries found\n");
286 nentries = size/sizeof(struct nvme_error_information_entry);
287 for (i = 0; i < nentries; i++, entry++) {
288 if (entry->error_count == 0)
291 status = entry->status;
293 p = NVME_STATUS_GET_P(status);
294 sc = NVME_STATUS_GET_SC(status);
295 sct = NVME_STATUS_GET_SCT(status);
296 m = NVME_STATUS_GET_M(status);
297 dnr = NVME_STATUS_GET_DNR(status);
299 printf("Entry %02d\n", i + 1);
300 printf("=========\n");
301 printf(" Error count: %ju\n", entry->error_count);
302 printf(" Submission queue ID: %u\n", entry->sqid);
303 printf(" Command ID: %u\n", entry->cid);
304 /* TODO: Export nvme_status_string structures from kernel? */
305 printf(" Status:\n");
306 printf(" Phase tag: %d\n", p);
307 printf(" Status code: %d\n", sc);
308 printf(" Status code type: %d\n", sct);
309 printf(" More: %d\n", m);
310 printf(" DNR: %d\n", dnr);
311 printf(" Error location: %u\n", entry->error_location);
312 printf(" LBA: %ju\n", entry->lba);
313 printf(" Namespace ID: %u\n", entry->nsid);
314 printf(" Vendor specific info: %u\n", entry->vendor_specific);
315 printf(" Transport type: %u\n", entry->trtype);
316 printf(" Command specific info:%ju\n", entry->csi);
317 printf(" Transport specific: %u\n", entry->ttsi);
322 print_temp(uint16_t t)
324 printf("%u K, %2.2f C, %3.2f F\n", t, (float)t - 273.15, (float)t * 9 / 5 - 459.67);
329 print_log_health(const struct nvme_controller_data *cdata __unused, void *buf, uint32_t size __unused)
331 struct nvme_health_information_page *health = buf;
332 char cbuf[UINT128_DIG + 1];
336 warning = health->critical_warning;
338 printf("SMART/Health Information Log\n");
339 printf("============================\n");
341 printf("Critical Warning State: 0x%02x\n", warning);
342 printf(" Available spare: %d\n",
343 !!(warning & NVME_CRIT_WARN_ST_AVAILABLE_SPARE));
344 printf(" Temperature: %d\n",
345 !!(warning & NVME_CRIT_WARN_ST_TEMPERATURE));
346 printf(" Device reliability: %d\n",
347 !!(warning & NVME_CRIT_WARN_ST_DEVICE_RELIABILITY));
348 printf(" Read only: %d\n",
349 !!(warning & NVME_CRIT_WARN_ST_READ_ONLY));
350 printf(" Volatile memory backup: %d\n",
351 !!(warning & NVME_CRIT_WARN_ST_VOLATILE_MEMORY_BACKUP));
352 printf("Temperature: ");
353 print_temp(health->temperature);
354 printf("Available spare: %u\n",
355 health->available_spare);
356 printf("Available spare threshold: %u\n",
357 health->available_spare_threshold);
358 printf("Percentage used: %u\n",
359 health->percentage_used);
361 printf("Data units (512,000 byte) read: %s\n",
362 uint128_to_str(to128(health->data_units_read), cbuf, sizeof(cbuf)));
363 printf("Data units written: %s\n",
364 uint128_to_str(to128(health->data_units_written), cbuf, sizeof(cbuf)));
365 printf("Host read commands: %s\n",
366 uint128_to_str(to128(health->host_read_commands), cbuf, sizeof(cbuf)));
367 printf("Host write commands: %s\n",
368 uint128_to_str(to128(health->host_write_commands), cbuf, sizeof(cbuf)));
369 printf("Controller busy time (minutes): %s\n",
370 uint128_to_str(to128(health->controller_busy_time), cbuf, sizeof(cbuf)));
371 printf("Power cycles: %s\n",
372 uint128_to_str(to128(health->power_cycles), cbuf, sizeof(cbuf)));
373 printf("Power on hours: %s\n",
374 uint128_to_str(to128(health->power_on_hours), cbuf, sizeof(cbuf)));
375 printf("Unsafe shutdowns: %s\n",
376 uint128_to_str(to128(health->unsafe_shutdowns), cbuf, sizeof(cbuf)));
377 printf("Media errors: %s\n",
378 uint128_to_str(to128(health->media_errors), cbuf, sizeof(cbuf)));
379 printf("No. error info log entries: %s\n",
380 uint128_to_str(to128(health->num_error_info_log_entries), cbuf, sizeof(cbuf)));
382 printf("Warning Temp Composite Time: %d\n", health->warning_temp_time);
383 printf("Error Temp Composite Time: %d\n", health->error_temp_time);
384 for (i = 0; i < 8; i++) {
385 if (health->temp_sensor[i] == 0)
387 printf("Temperature Sensor %d: ", i + 1);
388 print_temp(health->temp_sensor[i]);
390 printf("Temperature 1 Transition Count: %d\n", health->tmt1tc);
391 printf("Temperature 2 Transition Count: %d\n", health->tmt2tc);
392 printf("Total Time For Temperature 1: %d\n", health->ttftmt1);
393 printf("Total Time For Temperature 2: %d\n", health->ttftmt2);
397 print_log_firmware(const struct nvme_controller_data *cdata, void *buf, uint32_t size __unused)
401 struct nvme_firmware_page *fw = buf;
404 uint8_t fw_num_slots;
406 afi_slot = fw->afi >> NVME_FIRMWARE_PAGE_AFI_SLOT_SHIFT;
407 afi_slot &= NVME_FIRMWARE_PAGE_AFI_SLOT_MASK;
409 oacs_fw = (cdata->oacs >> NVME_CTRLR_DATA_OACS_FIRMWARE_SHIFT) &
410 NVME_CTRLR_DATA_OACS_FIRMWARE_MASK;
411 fw_num_slots = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_NUM_SLOTS_SHIFT) &
412 NVME_CTRLR_DATA_FRMW_NUM_SLOTS_MASK;
414 printf("Firmware Slot Log\n");
415 printf("=================\n");
420 slots = MIN(fw_num_slots, MAX_FW_SLOTS);
422 for (i = 0; i < slots; i++) {
423 printf("Slot %d: ", i + 1);
424 if (afi_slot == i + 1)
429 if (fw->revision[i] == 0LLU)
432 if (isprint(*(char *)&fw->revision[i]))
433 printf("[%s] %.8s\n", status,
434 (char *)&fw->revision[i]);
436 printf("[%s] %016jx\n", status,
442 print_log_ns(const struct nvme_controller_data *cdata __unused, void *buf,
443 uint32_t size __unused)
445 struct nvme_ns_list *nsl;
448 nsl = (struct nvme_ns_list *)buf;
449 printf("Changed Namespace List\n");
450 printf("======================\n");
452 for (i = 0; i < nitems(nsl->ns) && nsl->ns[i] != 0; i++) {
453 printf("%08x\n", nsl->ns[i]);
458 print_log_command_effects(const struct nvme_controller_data *cdata __unused,
459 void *buf, uint32_t size __unused)
461 struct nvme_command_effects_page *ce;
465 ce = (struct nvme_command_effects_page *)buf;
466 printf("Commands Supported and Effects\n");
467 printf("==============================\n");
468 printf(" Command\tLBCC\tNCC\tNIC\tCCC\tCSE\tUUID\n");
470 for (i = 0; i < 255; i++) {
472 if (((s >> NVME_CE_PAGE_CSUP_SHIFT) &
473 NVME_CE_PAGE_CSUP_MASK) == 0)
475 printf("Admin\t%02x\t%s\t%s\t%s\t%s\t%u\t%s\n", i,
476 ((s >> NVME_CE_PAGE_LBCC_SHIFT) &
477 NVME_CE_PAGE_LBCC_MASK) ? "Yes" : "No",
478 ((s >> NVME_CE_PAGE_NCC_SHIFT) &
479 NVME_CE_PAGE_NCC_MASK) ? "Yes" : "No",
480 ((s >> NVME_CE_PAGE_NIC_SHIFT) &
481 NVME_CE_PAGE_NIC_MASK) ? "Yes" : "No",
482 ((s >> NVME_CE_PAGE_CCC_SHIFT) &
483 NVME_CE_PAGE_CCC_MASK) ? "Yes" : "No",
484 ((s >> NVME_CE_PAGE_CSE_SHIFT) &
485 NVME_CE_PAGE_CSE_MASK),
486 ((s >> NVME_CE_PAGE_UUID_SHIFT) &
487 NVME_CE_PAGE_UUID_MASK) ? "Yes" : "No");
489 for (i = 0; i < 255; i++) {
491 if (((s >> NVME_CE_PAGE_CSUP_SHIFT) &
492 NVME_CE_PAGE_CSUP_MASK) == 0)
494 printf("I/O\t%02x\t%s\t%s\t%s\t%s\t%u\t%s\n", i,
495 ((s >> NVME_CE_PAGE_LBCC_SHIFT) &
496 NVME_CE_PAGE_LBCC_MASK) ? "Yes" : "No",
497 ((s >> NVME_CE_PAGE_NCC_SHIFT) &
498 NVME_CE_PAGE_NCC_MASK) ? "Yes" : "No",
499 ((s >> NVME_CE_PAGE_NIC_SHIFT) &
500 NVME_CE_PAGE_NIC_MASK) ? "Yes" : "No",
501 ((s >> NVME_CE_PAGE_CCC_SHIFT) &
502 NVME_CE_PAGE_CCC_MASK) ? "Yes" : "No",
503 ((s >> NVME_CE_PAGE_CSE_SHIFT) &
504 NVME_CE_PAGE_CSE_MASK),
505 ((s >> NVME_CE_PAGE_UUID_SHIFT) &
506 NVME_CE_PAGE_UUID_MASK) ? "Yes" : "No");
511 print_log_res_notification(const struct nvme_controller_data *cdata __unused,
512 void *buf, uint32_t size __unused)
514 struct nvme_res_notification_page *rn;
516 rn = (struct nvme_res_notification_page *)buf;
517 printf("Reservation Notification\n");
518 printf("========================\n");
520 printf("Log Page Count: %ju\n", rn->log_page_count);
521 printf("Log Page Type: ");
522 switch (rn->log_page_type) {
524 printf("Empty Log Page\n");
527 printf("Registration Preempted\n");
530 printf("Reservation Released\n");
533 printf("Reservation Preempted\n");
536 printf("Unknown %x\n", rn->log_page_type);
539 printf("Number of Available Log Pages: %d\n", rn->available_log_pages);
540 printf("Namespace ID: 0x%x\n", rn->nsid);
544 print_log_sanitize_status(const struct nvme_controller_data *cdata __unused,
545 void *buf, uint32_t size __unused)
547 struct nvme_sanitize_status_page *ss;
550 ss = (struct nvme_sanitize_status_page *)buf;
551 printf("Sanitize Status\n");
552 printf("===============\n");
554 printf("Sanitize Progress: %u%% (%u/65535)\n",
555 (ss->sprog * 100 + 32768) / 65536, ss->sprog);
556 printf("Sanitize Status: ");
557 switch ((ss->sstat >> NVME_SS_PAGE_SSTAT_STATUS_SHIFT) &
558 NVME_SS_PAGE_SSTAT_STATUS_MASK) {
559 case NVME_SS_PAGE_SSTAT_STATUS_NEVER:
560 printf("Never sanitized");
562 case NVME_SS_PAGE_SSTAT_STATUS_COMPLETED:
565 case NVME_SS_PAGE_SSTAT_STATUS_INPROG:
566 printf("In Progress");
568 case NVME_SS_PAGE_SSTAT_STATUS_FAILED:
571 case NVME_SS_PAGE_SSTAT_STATUS_COMPLETEDWD:
572 printf("Completed with deallocation");
578 p = (ss->sstat >> NVME_SS_PAGE_SSTAT_PASSES_SHIFT) &
579 NVME_SS_PAGE_SSTAT_PASSES_MASK;
581 printf(", %d passes", p);
582 if ((ss->sstat >> NVME_SS_PAGE_SSTAT_GDE_SHIFT) &
583 NVME_SS_PAGE_SSTAT_GDE_MASK)
584 printf(", Global Data Erased");
586 printf("Sanitize Command Dword 10: 0x%x\n", ss->scdw10);
587 printf("Time For Overwrite: %u sec\n", ss->etfo);
588 printf("Time For Block Erase: %u sec\n", ss->etfbe);
589 printf("Time For Crypto Erase: %u sec\n", ss->etfce);
590 printf("Time For Overwrite No-Deallocate: %u sec\n", ss->etfownd);
591 printf("Time For Block Erase No-Deallocate: %u sec\n", ss->etfbewnd);
592 printf("Time For Crypto Erase No-Deallocate: %u sec\n", ss->etfcewnd);
597 [0] = "completed without error",
598 [1] = "aborted by a Device Self-test command",
599 [2] = "aborted by a Controller Level Reset",
600 [3] = "aborted due to namespace removal",
601 [4] = "aborted due to Format NVM command",
602 [5] = "failed due to fatal or unknown test error",
603 [6] = "completed with an unknown segment that failed",
604 [7] = "completed with one or more failed segments",
605 [8] = "aborted for unknown reason",
606 [9] = "aborted due to a sanitize operation",
608 static uint32_t self_test_res_max = nitems(self_test_res);
611 print_log_self_test_status(const struct nvme_controller_data *cdata __unused,
612 void *buf, uint32_t size __unused)
614 struct nvme_device_self_test_page *dst;
618 printf("Device Self-test Status\n");
619 printf("=======================\n");
621 printf("Current Operation: ");
622 switch (dst->curr_operation) {
624 printf("No device self-test operation in progress\n");
627 printf("Short device self-test operation in progress\n");
630 printf("Extended device self-test operation in progress\n");
633 printf("Vendor specific\n");
636 printf("Reserved (0x%x)\n", dst->curr_operation);
639 if (dst->curr_operation != 0)
640 printf("Current Completion: %u%%\n", dst->curr_compl & 0x7f);
643 for (r = 0; r < 20; r++) {
644 uint64_t failing_lba;
647 code = (dst->result[r].status >> 4) & 0xf;
648 res = dst->result[r].status & 0xf;
656 printf("Short device self-test");
659 printf("Extended device self-test");
662 printf("Vendor specific");
665 printf("Reserved (0x%x)", code);
667 if (res < self_test_res_max)
668 printf(" %s", self_test_res[res]);
670 printf(" Reserved status 0x%x", res);
673 printf(" starting in segment %u", dst->result[r].segment_num);
675 #define BIT(b) (1 << (b))
676 if (dst->result[r].valid_diag_info & BIT(0))
677 printf(" NSID=0x%x", dst->result[r].nsid);
678 if (dst->result[r].valid_diag_info & BIT(1)) {
679 memcpy(&failing_lba, dst->result[r].failing_lba,
680 sizeof(failing_lba));
681 printf(" FLBA=0x%jx", failing_lba);
683 if (dst->result[r].valid_diag_info & BIT(2))
684 printf(" SCT=0x%x", dst->result[r].status_code_type);
685 if (dst->result[r].valid_diag_info & BIT(3))
686 printf(" SC=0x%x", dst->result[r].status_code);
693 * Table of log page printer / sizing.
695 * Make sure you keep all the pages of one vendor together so -v help
696 * lists all the vendors pages.
699 NVME_LOG_ERROR, NULL, "Drive Error Log",
702 NVME_LOG_HEALTH_INFORMATION, NULL, "Health/SMART Data",
703 print_log_health, sizeof(struct nvme_health_information_page));
705 NVME_LOG_FIRMWARE_SLOT, NULL, "Firmware Information",
706 print_log_firmware, sizeof(struct nvme_firmware_page));
708 NVME_LOG_CHANGED_NAMESPACE, NULL, "Changed Namespace List",
709 print_log_ns, sizeof(struct nvme_ns_list));
711 NVME_LOG_COMMAND_EFFECT, NULL, "Commands Supported and Effects",
712 print_log_command_effects, sizeof(struct nvme_command_effects_page));
714 NVME_LOG_DEVICE_SELF_TEST, NULL, "Device Self-test",
715 print_log_self_test_status, sizeof(struct nvme_device_self_test_page));
717 NVME_LOG_TELEMETRY_HOST_INITIATED, NULL, "Telemetry Host-Initiated",
720 NVME_LOG_TELEMETRY_CONTROLLER_INITIATED, NULL, "Telemetry Controller-Initiated",
723 NVME_LOG_ENDURANCE_GROUP_INFORMATION, NULL, "Endurance Group Information",
726 NVME_LOG_PREDICTABLE_LATENCY_PER_NVM_SET, NULL, "Predictable Latency Per NVM Set",
729 NVME_LOG_PREDICTABLE_LATENCY_EVENT_AGGREGATE, NULL, "Predictable Latency Event Aggregate",
732 NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS, NULL, "Asymmetric Namespace Access",
735 NVME_LOG_PERSISTENT_EVENT_LOG, NULL, "Persistent Event Log",
738 NVME_LOG_LBA_STATUS_INFORMATION, NULL, "LBA Status Information",
741 NVME_LOG_ENDURANCE_GROUP_EVENT_AGGREGATE, NULL, "Endurance Group Event Aggregate",
743 NVME_LOGPAGE(res_notification,
744 NVME_LOG_RES_NOTIFICATION, NULL, "Reservation Notification",
745 print_log_res_notification, sizeof(struct nvme_res_notification_page));
746 NVME_LOGPAGE(sanitize_status,
747 NVME_LOG_SANITIZE_STATUS, NULL, "Sanitize Status",
748 print_log_sanitize_status, sizeof(struct nvme_sanitize_status_page));
753 const struct logpage_function *f;
756 fprintf(stderr, "\n");
757 fprintf(stderr, "%-8s %-10s %s\n", "Page", "Vendor","Page Name");
758 fprintf(stderr, "-------- ---------- ----------\n");
759 SLIST_FOREACH(f, &logpages, link) {
760 v = f->vendor == NULL ? "-" : f->vendor;
761 fprintf(stderr, "0x%02x %-10s %s\n", f->log_page, v, f->name);
768 logpage(const struct cmd *f, int argc, char *argv[])
774 const struct logpage_function *lpf;
775 struct nvme_controller_data cdata;
779 if (arg_parse(argc, argv, f))
781 if (opt.hex && opt.binary) {
783 "Can't specify both binary and hex\n");
784 arg_help(argc, argv, f);
786 if (opt.vendor != NULL && strcmp(opt.vendor, "help") == 0)
788 if (opt.page == NONE) {
789 fprintf(stderr, "Missing page_id (-p).\n");
790 arg_help(argc, argv, f);
792 open_dev(opt.dev, &fd, 0, 1);
793 get_nsid(fd, &path, &nsid);
795 nsid = NVME_GLOBAL_NAMESPACE_TAG;
798 open_dev(path, &fd, 0, 1);
802 if (read_controller_data(fd, &cdata))
803 errx(EX_IOERR, "Identify request failed");
805 ns_smart = (cdata.lpa >> NVME_CTRLR_DATA_LPA_NS_SMART_SHIFT) &
806 NVME_CTRLR_DATA_LPA_NS_SMART_MASK;
809 * The log page attribtues indicate whether or not the controller
810 * supports the SMART/Health information log page on a per
813 if (nsid != NVME_GLOBAL_NAMESPACE_TAG) {
814 if (opt.page != NVME_LOG_HEALTH_INFORMATION)
815 errx(EX_USAGE, "log page %d valid only at controller level",
819 "controller does not support per namespace "
820 "smart/health information");
823 print_fn = print_log_hex;
826 print_fn = print_bin;
827 if (!opt.binary && !opt.hex) {
829 * See if there is a pretty print function for the specified log
830 * page. If one isn't found, we just revert to the default
831 * (print_hex). If there was a vendor specified by the user, and
832 * the page is vendor specific, don't match the print function
833 * unless the vendors match.
835 SLIST_FOREACH(lpf, &logpages, link) {
836 if (lpf->vendor != NULL && opt.vendor != NULL &&
837 strcmp(lpf->vendor, opt.vendor) != 0)
839 if (opt.page != lpf->log_page)
841 if (lpf->print_fn != NULL)
842 print_fn = lpf->print_fn;
848 if (opt.page == NVME_LOG_ERROR) {
849 size = sizeof(struct nvme_error_information_entry);
850 size *= (cdata.elpe + 1);
853 /* Read the log page */
854 buf = get_log_buffer(size);
855 read_logpage(fd, opt.page, nsid, opt.lsp, opt.lsi, opt.rae, buf, size);
856 print_fn(&cdata, buf, size);