2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2013 EMC Corp.
7 * Copyright (C) 2012-2013 Intel Corporation
9 * Copyright (C) 2016-2023 Warner Losh <imp@FreeBSD.org>
10 * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include <sys/param.h>
35 #include <sys/ioccom.h>
47 #include <sys/endian.h>
49 #include "nvmecontrol.h"
51 /* Tables for command line parsing */
53 static cmd_fn_t logpage;
55 #define NONE 0xffffffffu
56 static struct options {
76 static const struct opts logpage_opts[] = {
77 #define OPT(l, s, t, opt, addr, desc) { l, s, t, &opt.addr, desc }
78 OPT("binary", 'b', arg_none, opt, binary,
79 "Dump the log page as binary"),
80 OPT("hex", 'x', arg_none, opt, hex,
81 "Dump the log page as hex"),
82 OPT("page", 'p', arg_uint32, opt, page,
84 OPT("lsp", 'f', arg_uint8, opt, lsp,
85 "Log Specific Field"),
86 OPT("lsi", 'i', arg_uint16, opt, lsi,
87 "Log Specific Identifier"),
88 OPT("rae", 'r', arg_none, opt, rae,
89 "Retain Asynchronous Event"),
90 OPT("vendor", 'v', arg_string, opt, vendor,
91 "Vendor specific formatting"),
92 { NULL, 0, arg_none, NULL, NULL }
96 static const struct args logpage_args[] = {
97 { arg_string, &opt.dev, "<controller id|namespace id>" },
98 { arg_none, NULL, NULL },
101 static struct cmd logpage_cmd = {
104 .descr = "Print logpages in human-readable form",
105 .ctx_size = sizeof(opt),
106 .opts = logpage_opts,
107 .args = logpage_args,
110 CMD_COMMAND(logpage_cmd);
112 /* End of tables for command line parsing */
114 #define MAX_FW_SLOTS (7)
116 static SLIST_HEAD(,logpage_function) logpages;
119 logpage_compare(struct logpage_function *a, struct logpage_function *b)
123 if ((a->vendor == NULL) != (b->vendor == NULL))
124 return (a->vendor == NULL ? -1 : 1);
125 if (a->vendor != NULL) {
126 c = strcmp(a->vendor, b->vendor);
130 return ((int)a->log_page - (int)b->log_page);
134 logpage_register(struct logpage_function *p)
136 struct logpage_function *l, *a;
139 l = SLIST_FIRST(&logpages);
141 if (logpage_compare(l, p) > 0)
144 l = SLIST_NEXT(l, link);
147 SLIST_INSERT_HEAD(&logpages, p, link);
149 SLIST_INSERT_AFTER(a, p, link);
153 kv_lookup(const struct kv_name *kv, size_t kv_count, uint32_t key)
158 for (i = 0; i < kv_count; i++, kv++)
161 snprintf(bad, sizeof(bad), "Attribute %#x", key);
166 print_log_hex(const struct nvme_controller_data *cdata __unused, void *data, uint32_t length)
169 print_hex(data, length);
173 print_bin(const struct nvme_controller_data *cdata __unused, void *data, uint32_t length)
176 write(STDOUT_FILENO, data, length);
180 get_log_buffer(uint32_t size)
184 if ((buf = malloc(size)) == NULL)
185 errx(EX_OSERR, "unable to malloc %u bytes", size);
187 memset(buf, 0, size);
192 read_logpage(int fd, uint8_t log_page, uint32_t nsid, uint8_t lsp,
193 uint16_t lsi, uint8_t rae, uint64_t lpo, uint8_t csi, uint8_t ot,
194 uint16_t uuid_index, void *payload, uint32_t payload_size)
196 struct nvme_pt_command pt;
199 numd = payload_size / sizeof(uint32_t) - 1;
200 memset(&pt, 0, sizeof(pt));
201 pt.cmd.opc = NVME_OPC_GET_LOG_PAGE;
202 pt.cmd.nsid = htole32(nsid);
203 pt.cmd.cdw10 = htole32(
204 (numd << 16) | /* NUMDL */
205 (rae << 15) | /* RAE */
206 (lsp << 8) | /* LSP */
208 pt.cmd.cdw11 = htole32(
209 ((uint32_t)lsi << 16) | /* LSI */
210 (numd >> 16)); /* NUMDU */
211 pt.cmd.cdw12 = htole32(lpo & 0xffffffff); /* LPOL */
212 pt.cmd.cdw13 = htole32(lpo >> 32); /* LPOU */
213 pt.cmd.cdw14 = htole32(
214 (csi << 24) | /* CSI */
215 (ot << 23) | /* OT */
216 uuid_index); /* UUID Index */
218 pt.len = payload_size;
221 if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0)
222 err(EX_IOERR, "get log page request failed");
224 if (nvme_completion_is_error(&pt.cpl))
225 errx(EX_IOERR, "get log page request returned error");
229 print_log_error(const struct nvme_controller_data *cdata __unused, void *buf, uint32_t size)
233 uint8_t p, sc, sct, m, dnr;
234 struct nvme_error_information_entry *entry = buf;
236 printf("Error Information Log\n");
237 printf("=====================\n");
239 if (letoh(entry->error_count) == 0) {
240 printf("No error entries found\n");
244 nentries = size / sizeof(struct nvme_error_information_entry);
245 for (i = 0; i < nentries; i++, entry++) {
246 if (letoh(entry->error_count) == 0)
249 status = letoh(entry->status);
251 p = NVME_STATUS_GET_P(status);
252 sc = NVME_STATUS_GET_SC(status);
253 sct = NVME_STATUS_GET_SCT(status);
254 m = NVME_STATUS_GET_M(status);
255 dnr = NVME_STATUS_GET_DNR(status);
257 printf("Entry %02d\n", i + 1);
258 printf("=========\n");
259 printf(" Error count: %ju\n", letoh(entry->error_count));
260 printf(" Submission queue ID: %u\n", letoh(entry->sqid));
261 printf(" Command ID: %u\n", letoh(entry->cid));
262 /* TODO: Export nvme_status_string structures from kernel? */
263 printf(" Status:\n");
264 printf(" Phase tag: %d\n", p);
265 printf(" Status code: %d\n", sc);
266 printf(" Status code type: %d\n", sct);
267 printf(" More: %d\n", m);
268 printf(" DNR: %d\n", dnr);
269 printf(" Error location: %u\n", letoh(entry->error_location));
270 printf(" LBA: %ju\n", letoh(entry->lba));
271 printf(" Namespace ID: %u\n", letoh(entry->nsid));
272 printf(" Vendor specific info: %u\n", letoh(entry->vendor_specific));
273 printf(" Transport type: %u\n", letoh(entry->trtype));
274 printf(" Command specific info:%ju\n", letoh(entry->csi));
275 printf(" Transport specific: %u\n", letoh(entry->ttsi));
280 print_temp_K(uint16_t t)
282 printf("%u K, %2.2f C, %3.2f F\n", t, (float)t - 273.15, (float)t * 9 / 5 - 459.67);
286 print_temp_C(uint16_t t)
288 printf("%2.2f K, %u C, %3.2f F\n", (float)t + 273.15, t, (float)t * 9 / 5 + 32);
292 print_log_health(const struct nvme_controller_data *cdata __unused, void *buf, uint32_t size __unused)
294 struct nvme_health_information_page *health = buf;
295 char cbuf[UINT128_DIG + 1];
299 warning = letoh(health->critical_warning);
301 printf("SMART/Health Information Log\n");
302 printf("============================\n");
304 printf("Critical Warning State: 0x%02x\n", warning);
305 printf(" Available spare: %d\n",
306 !!(warning & NVME_CRIT_WARN_ST_AVAILABLE_SPARE));
307 printf(" Temperature: %d\n",
308 !!(warning & NVME_CRIT_WARN_ST_TEMPERATURE));
309 printf(" Device reliability: %d\n",
310 !!(warning & NVME_CRIT_WARN_ST_DEVICE_RELIABILITY));
311 printf(" Read only: %d\n",
312 !!(warning & NVME_CRIT_WARN_ST_READ_ONLY));
313 printf(" Volatile memory backup: %d\n",
314 !!(warning & NVME_CRIT_WARN_ST_VOLATILE_MEMORY_BACKUP));
315 printf("Temperature: ");
316 print_temp_K(letoh(health->temperature));
317 printf("Available spare: %u\n",
318 letoh(health->available_spare));
319 printf("Available spare threshold: %u\n",
320 letoh(health->available_spare_threshold));
321 printf("Percentage used: %u\n",
322 letoh(health->percentage_used));
324 printf("Data units (512,000 byte) read: %s\n",
325 uint128_to_str(to128(health->data_units_read), cbuf, sizeof(cbuf)));
326 printf("Data units written: %s\n",
327 uint128_to_str(to128(health->data_units_written), cbuf, sizeof(cbuf)));
328 printf("Host read commands: %s\n",
329 uint128_to_str(to128(health->host_read_commands), cbuf, sizeof(cbuf)));
330 printf("Host write commands: %s\n",
331 uint128_to_str(to128(health->host_write_commands), cbuf, sizeof(cbuf)));
332 printf("Controller busy time (minutes): %s\n",
333 uint128_to_str(to128(health->controller_busy_time), cbuf, sizeof(cbuf)));
334 printf("Power cycles: %s\n",
335 uint128_to_str(to128(health->power_cycles), cbuf, sizeof(cbuf)));
336 printf("Power on hours: %s\n",
337 uint128_to_str(to128(health->power_on_hours), cbuf, sizeof(cbuf)));
338 printf("Unsafe shutdowns: %s\n",
339 uint128_to_str(to128(health->unsafe_shutdowns), cbuf, sizeof(cbuf)));
340 printf("Media errors: %s\n",
341 uint128_to_str(to128(health->media_errors), cbuf, sizeof(cbuf)));
342 printf("No. error info log entries: %s\n",
343 uint128_to_str(to128(health->num_error_info_log_entries), cbuf, sizeof(cbuf)));
345 printf("Warning Temp Composite Time: %d\n", letoh(health->warning_temp_time));
346 printf("Error Temp Composite Time: %d\n", letoh(health->error_temp_time));
347 for (i = 0; i < 8; i++) {
348 if (letoh(health->temp_sensor[i]) == 0)
350 printf("Temperature Sensor %d: ", i + 1);
351 print_temp_K(letoh(health->temp_sensor[i]));
353 printf("Temperature 1 Transition Count: %d\n", letoh(health->tmt1tc));
354 printf("Temperature 2 Transition Count: %d\n", letoh(health->tmt2tc));
355 printf("Total Time For Temperature 1: %d\n", letoh(health->ttftmt1));
356 printf("Total Time For Temperature 2: %d\n", letoh(health->ttftmt2));
360 print_log_firmware(const struct nvme_controller_data *cdata, void *buf, uint32_t size __unused)
364 struct nvme_firmware_page *fw = buf;
367 uint8_t fw_num_slots;
369 afi_slot = NVMEV(NVME_FIRMWARE_PAGE_AFI_SLOT, fw->afi);
371 oacs_fw = NVMEV(NVME_CTRLR_DATA_OACS_FIRMWARE, cdata->oacs);
372 fw_num_slots = NVMEV(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, cdata->frmw);
374 printf("Firmware Slot Log\n");
375 printf("=================\n");
380 slots = MIN(fw_num_slots, MAX_FW_SLOTS);
382 for (i = 0; i < slots; i++) {
383 printf("Slot %d: ", i + 1);
384 if (afi_slot == i + 1)
389 if (fw->revision[i][0] == '\0')
392 printf("[%s] %.8s\n", status, fw->revision[i]);
397 print_log_ns(const struct nvme_controller_data *cdata __unused, void *buf,
398 uint32_t size __unused)
400 struct nvme_ns_list *nsl;
403 nsl = (struct nvme_ns_list *)buf;
404 printf("Changed Namespace List\n");
405 printf("======================\n");
407 for (i = 0; i < nitems(nsl->ns) && letoh(nsl->ns[i]) != 0; i++) {
408 printf("%08x\n", letoh(nsl->ns[i]));
413 print_log_command_effects(const struct nvme_controller_data *cdata __unused,
414 void *buf, uint32_t size __unused)
416 struct nvme_command_effects_page *ce;
420 ce = (struct nvme_command_effects_page *)buf;
421 printf("Commands Supported and Effects\n");
422 printf("==============================\n");
423 printf(" Command\tLBCC\tNCC\tNIC\tCCC\tCSE\tUUID\n");
425 for (i = 0; i < 255; i++) {
426 s = letoh(ce->acs[i]);
427 if (NVMEV(NVME_CE_PAGE_CSUP, s) == 0)
429 printf("Admin\t%02x\t%s\t%s\t%s\t%s\t%u\t%s\n", i,
430 NVMEV(NVME_CE_PAGE_LBCC, s) != 0 ? "Yes" : "No",
431 NVMEV(NVME_CE_PAGE_NCC, s) != 0 ? "Yes" : "No",
432 NVMEV(NVME_CE_PAGE_NIC, s) != 0 ? "Yes" : "No",
433 NVMEV(NVME_CE_PAGE_CCC, s) != 0 ? "Yes" : "No",
434 NVMEV(NVME_CE_PAGE_CSE, s),
435 NVMEV(NVME_CE_PAGE_UUID, s) != 0 ? "Yes" : "No");
437 for (i = 0; i < 255; i++) {
438 s = letoh(ce->iocs[i]);
439 if (NVMEV(NVME_CE_PAGE_CSUP, s) == 0)
441 printf("I/O\t%02x\t%s\t%s\t%s\t%s\t%u\t%s\n", i,
442 NVMEV(NVME_CE_PAGE_LBCC, s) != 0 ? "Yes" : "No",
443 NVMEV(NVME_CE_PAGE_NCC, s) != 0 ? "Yes" : "No",
444 NVMEV(NVME_CE_PAGE_NIC, s) != 0 ? "Yes" : "No",
445 NVMEV(NVME_CE_PAGE_CCC, s) != 0 ? "Yes" : "No",
446 NVMEV(NVME_CE_PAGE_CSE, s),
447 NVMEV(NVME_CE_PAGE_UUID, s) != 0 ? "Yes" : "No");
452 print_log_res_notification(const struct nvme_controller_data *cdata __unused,
453 void *buf, uint32_t size __unused)
455 struct nvme_res_notification_page *rn;
457 rn = (struct nvme_res_notification_page *)buf;
458 printf("Reservation Notification\n");
459 printf("========================\n");
461 printf("Log Page Count: %ju\n",
462 (uintmax_t)letoh(rn->log_page_count));
463 printf("Log Page Type: ");
464 switch (letoh(rn->log_page_type)) {
466 printf("Empty Log Page\n");
469 printf("Registration Preempted\n");
472 printf("Reservation Released\n");
475 printf("Reservation Preempted\n");
478 printf("Unknown %x\n", letoh(rn->log_page_type));
481 printf("Number of Available Log Pages: %d\n", letoh(rn->available_log_pages));
482 printf("Namespace ID: 0x%x\n", letoh(rn->nsid));
486 print_log_sanitize_status(const struct nvme_controller_data *cdata __unused,
487 void *buf, uint32_t size __unused)
489 struct nvme_sanitize_status_page *ss;
491 uint16_t sprog, sstat;
493 ss = (struct nvme_sanitize_status_page *)buf;
494 printf("Sanitize Status\n");
495 printf("===============\n");
497 sprog = letoh(ss->sprog);
498 printf("Sanitize Progress: %u%% (%u/65535)\n",
499 (sprog * 100 + 32768) / 65536, sprog);
500 printf("Sanitize Status: ");
501 sstat = letoh(ss->sstat);
502 switch (NVMEV(NVME_SS_PAGE_SSTAT_STATUS, sstat)) {
503 case NVME_SS_PAGE_SSTAT_STATUS_NEVER:
504 printf("Never sanitized");
506 case NVME_SS_PAGE_SSTAT_STATUS_COMPLETED:
509 case NVME_SS_PAGE_SSTAT_STATUS_INPROG:
510 printf("In Progress");
512 case NVME_SS_PAGE_SSTAT_STATUS_FAILED:
515 case NVME_SS_PAGE_SSTAT_STATUS_COMPLETEDWD:
516 printf("Completed with deallocation");
519 printf("Unknown 0x%x", sstat);
522 p = NVMEV(NVME_SS_PAGE_SSTAT_PASSES, sstat);
524 printf(", %d passes", p);
525 if (NVMEV(NVME_SS_PAGE_SSTAT_GDE, sstat) != 0)
526 printf(", Global Data Erased");
528 printf("Sanitize Command Dword 10: 0x%x\n", letoh(ss->scdw10));
529 printf("Time For Overwrite: %u sec\n", letoh(ss->etfo));
530 printf("Time For Block Erase: %u sec\n", letoh(ss->etfbe));
531 printf("Time For Crypto Erase: %u sec\n", letoh(ss->etfce));
532 printf("Time For Overwrite No-Deallocate: %u sec\n", letoh(ss->etfownd));
533 printf("Time For Block Erase No-Deallocate: %u sec\n", letoh(ss->etfbewnd));
534 printf("Time For Crypto Erase No-Deallocate: %u sec\n", letoh(ss->etfcewnd));
539 [0] = "completed without error",
540 [1] = "aborted by a Device Self-test command",
541 [2] = "aborted by a Controller Level Reset",
542 [3] = "aborted due to namespace removal",
543 [4] = "aborted due to Format NVM command",
544 [5] = "failed due to fatal or unknown test error",
545 [6] = "completed with an unknown segment that failed",
546 [7] = "completed with one or more failed segments",
547 [8] = "aborted for unknown reason",
548 [9] = "aborted due to a sanitize operation",
550 static uint32_t self_test_res_max = nitems(self_test_res);
553 print_log_self_test_status(const struct nvme_controller_data *cdata __unused,
554 void *buf, uint32_t size __unused)
556 struct nvme_device_self_test_page *dst;
561 printf("Device Self-test Status\n");
562 printf("=======================\n");
564 printf("Current Operation: ");
565 switch (letoh(dst->curr_operation)) {
567 printf("No device self-test operation in progress\n");
570 printf("Short device self-test operation in progress\n");
573 printf("Extended device self-test operation in progress\n");
576 printf("Vendor specific\n");
579 printf("Reserved (0x%x)\n", letoh(dst->curr_operation));
582 if (letoh(dst->curr_operation) != 0)
583 printf("Current Completion: %u%%\n", letoh(dst->curr_compl) & 0x7f);
586 for (r = 0; r < 20; r++) {
587 uint64_t failing_lba;
588 uint8_t code, res, status;
590 status = letoh(dst->result[r].status);
591 code = (status >> 4) & 0xf;
600 printf("Short device self-test");
603 printf("Extended device self-test");
606 printf("Vendor specific");
609 printf("Reserved (0x%x)", code);
611 if (res < self_test_res_max)
612 printf(" %s", self_test_res[res]);
614 printf(" Reserved status 0x%x", res);
617 printf(" starting in segment %u",
618 letoh(dst->result[r].segment_num));
620 #define BIT(b) (1 << (b))
621 if (letoh(dst->result[r].valid_diag_info) & BIT(0))
622 printf(" NSID=0x%x", letoh(dst->result[r].nsid));
623 if (letoh(dst->result[r].valid_diag_info) & BIT(1)) {
624 memcpy(&failing_lba, dst->result[r].failing_lba,
625 sizeof(failing_lba));
626 printf(" FLBA=0x%jx", (uintmax_t)letoh(failing_lba));
628 if (letoh(dst->result[r].valid_diag_info) & BIT(2))
629 printf(" SCT=0x%x", letoh(dst->result[r].status_code_type));
630 if (letoh(dst->result[r].valid_diag_info) & BIT(3))
631 printf(" SC=0x%x", letoh(dst->result[r].status_code));
633 memcpy(&vs, dst->result[r].vendor_specific, sizeof(vs));
634 printf(" VENDOR_SPECIFIC=0x%x", letoh(vs));
640 * Table of log page printer / sizing.
642 * Make sure you keep all the pages of one vendor together so -v help
643 * lists all the vendors pages.
646 NVME_LOG_ERROR, NULL, "Drive Error Log",
649 NVME_LOG_HEALTH_INFORMATION, NULL, "Health/SMART Data",
650 print_log_health, sizeof(struct nvme_health_information_page));
652 NVME_LOG_FIRMWARE_SLOT, NULL, "Firmware Information",
653 print_log_firmware, sizeof(struct nvme_firmware_page));
655 NVME_LOG_CHANGED_NAMESPACE, NULL, "Changed Namespace List",
656 print_log_ns, sizeof(struct nvme_ns_list));
658 NVME_LOG_COMMAND_EFFECT, NULL, "Commands Supported and Effects",
659 print_log_command_effects, sizeof(struct nvme_command_effects_page));
661 NVME_LOG_DEVICE_SELF_TEST, NULL, "Device Self-test",
662 print_log_self_test_status, sizeof(struct nvme_device_self_test_page));
664 NVME_LOG_TELEMETRY_HOST_INITIATED, NULL, "Telemetry Host-Initiated",
667 NVME_LOG_TELEMETRY_CONTROLLER_INITIATED, NULL, "Telemetry Controller-Initiated",
670 NVME_LOG_ENDURANCE_GROUP_INFORMATION, NULL, "Endurance Group Information",
673 NVME_LOG_PREDICTABLE_LATENCY_PER_NVM_SET, NULL, "Predictable Latency Per NVM Set",
676 NVME_LOG_PREDICTABLE_LATENCY_EVENT_AGGREGATE, NULL, "Predictable Latency Event Aggregate",
679 NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS, NULL, "Asymmetric Namespace Access",
682 NVME_LOG_PERSISTENT_EVENT_LOG, NULL, "Persistent Event Log",
685 NVME_LOG_LBA_STATUS_INFORMATION, NULL, "LBA Status Information",
688 NVME_LOG_ENDURANCE_GROUP_EVENT_AGGREGATE, NULL, "Endurance Group Event Aggregate",
690 NVME_LOGPAGE(res_notification,
691 NVME_LOG_RES_NOTIFICATION, NULL, "Reservation Notification",
692 print_log_res_notification, sizeof(struct nvme_res_notification_page));
693 NVME_LOGPAGE(sanitize_status,
694 NVME_LOG_SANITIZE_STATUS, NULL, "Sanitize Status",
695 print_log_sanitize_status, sizeof(struct nvme_sanitize_status_page));
700 const struct logpage_function *f;
703 fprintf(stderr, "\n");
704 fprintf(stderr, "%-8s %-10s %s\n", "Page", "Vendor","Page Name");
705 fprintf(stderr, "-------- ---------- ----------\n");
706 SLIST_FOREACH(f, &logpages, link) {
707 v = f->vendor == NULL ? "-" : f->vendor;
708 fprintf(stderr, "0x%02x %-10s %s\n", f->log_page, v, f->name);
715 logpage(const struct cmd *f, int argc, char *argv[])
721 const struct logpage_function *lpf;
722 struct nvme_controller_data cdata;
726 if (arg_parse(argc, argv, f))
728 if (opt.hex && opt.binary) {
730 "Can't specify both binary and hex\n");
731 arg_help(argc, argv, f);
733 if (opt.vendor != NULL && strcmp(opt.vendor, "help") == 0)
735 if (opt.page == NONE) {
736 fprintf(stderr, "Missing page_id (-p).\n");
737 arg_help(argc, argv, f);
739 open_dev(opt.dev, &fd, 0, 1);
740 get_nsid(fd, &path, &nsid);
742 nsid = NVME_GLOBAL_NAMESPACE_TAG;
745 open_dev(path, &fd, 0, 1);
749 if (read_controller_data(fd, &cdata))
750 errx(EX_IOERR, "Identify request failed");
752 ns_smart = NVMEV(NVME_CTRLR_DATA_LPA_NS_SMART, cdata.lpa);
755 * The log page attributes indicate whether or not the controller
756 * supports the SMART/Health information log page on a per
759 if (nsid != NVME_GLOBAL_NAMESPACE_TAG) {
760 if (opt.page != NVME_LOG_HEALTH_INFORMATION)
761 errx(EX_USAGE, "log page %d valid only at controller level",
765 "controller does not support per namespace "
766 "smart/health information");
769 print_fn = print_log_hex;
772 print_fn = print_bin;
773 if (!opt.binary && !opt.hex) {
775 * See if there is a pretty print function for the specified log
776 * page. If one isn't found, we just revert to the default
777 * (print_hex). If there was a vendor specified by the user, and
778 * the page is vendor specific, don't match the print function
779 * unless the vendors match.
781 SLIST_FOREACH(lpf, &logpages, link) {
782 if (lpf->vendor != NULL && opt.vendor != NULL &&
783 strcmp(lpf->vendor, opt.vendor) != 0)
785 if (opt.page != lpf->log_page)
787 if (lpf->print_fn != NULL)
788 print_fn = lpf->print_fn;
794 if (opt.page == NVME_LOG_ERROR) {
795 size = sizeof(struct nvme_error_information_entry);
796 size *= (cdata.elpe + 1);
799 /* Read the log page */
800 buf = get_log_buffer(size);
801 read_logpage(fd, opt.page, nsid, opt.lsp, opt.lsi, opt.rae,
802 0, 0, 0, 0, buf, size);
803 print_fn(&cdata, buf, size);