2 * Copyright (c) 2017 Netflix, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 #include <sys/cdefs.h>
27 __FBSDID("$FreeBSD$");
29 #include <sys/param.h>
30 #include <sys/ioccom.h>
31 #include <sys/endian.h>
44 #include "nvmecontrol.h"
46 /* Tables for command line parsing */
49 static cmd_fn_t wdc_cap_diag;
51 #define NONE 0xffffffffu
52 #define NONE64 0xffffffffffffffffull
53 #define OPT(l, s, t, opt, addr, desc) { l, s, t, &opt.addr, desc }
54 #define OPT_END { NULL, 0, arg_none, NULL, NULL }
56 static struct cmd wdc_cmd = {
57 .name = "wdc", .fn = wdc, .descr = "wdc vendor specific commands", .ctx_size = 0, .opts = NULL, .args = NULL,
73 static const struct opts opts[] = {
74 OPT("template", 'o', arg_string, opt, template,
75 "Template for paths to use for different logs"),
76 OPT("data-area", 'd', arg_uint8, opt, data_area,
77 "Data-area to retrieve up to"),
81 static const struct args args[] = {
82 { arg_string, &opt.dev, "controller-id" },
83 { arg_none, NULL, NULL },
86 static struct cmd cap_diag_cmd = {
89 .descr = "Retrieve the cap-diag logs from the drive",
90 .ctx_size = sizeof(struct options),
95 CMD_SUBCOMMAND(wdc_cmd, cap_diag_cmd);
97 #define WDC_NVME_VID 0x1c58
98 #define WDC_NVME_VID_2 0x1b96
99 #define WDC_NVME_VID_3 0x15b7
101 #define WDC_NVME_TOC_SIZE 0x8
102 #define WDC_NVME_LOG_SIZE_HDR_LEN 0x8
103 #define WDC_NVME_CAP_DIAG_OPCODE_E6 0xe6
104 #define WDC_NVME_CAP_DIAG_CMD 0x0000
105 #define WDC_NVME_CAP_DIAG_OPCODE_FA 0xfa
106 #define WDC_NVME_DUI_MAX_SECTIONS_V0 0x3c
107 #define WDC_NVME_DUI_MAX_SECTIONS_V1 0x3a
108 #define WDC_NVME_DUI_MAX_SECTIONS_V2 0x26
109 #define WDC_NVME_DUI_MAX_SECTIONS_V3 0x23
111 typedef enum wdc_dui_header {
112 WDC_DUI_HEADER_VER_0 = 0,
113 WDC_DUI_HEADER_VER_1,
114 WDC_DUI_HEADER_VER_2,
115 WDC_DUI_HEADER_VER_3,
119 wdc_append_serial_name(int fd, char *buf, size_t len, const char *suffix)
121 struct nvme_controller_data cdata;
122 char sn[NVME_SERIAL_NUMBER_LENGTH + 1];
127 if (read_controller_data(fd, &cdata))
128 errx(EX_IOERR, "Identify request failed");
129 memcpy(sn, cdata.sn, NVME_SERIAL_NUMBER_LENGTH);
130 walker = sn + NVME_SERIAL_NUMBER_LENGTH - 1;
131 while (walker > sn && *walker == ' ')
134 snprintf(buf, len, "_%s_%s.bin", sn, suffix);
138 wdc_get_data(int fd, uint32_t opcode, uint32_t len, uint32_t off, uint32_t cmd,
139 uint8_t *buffer, size_t buflen, bool e6lg_flag)
141 struct nvme_pt_command pt;
143 memset(&pt, 0, sizeof(pt));
145 pt.cmd.cdw10 = htole32(len / sizeof(uint32_t));
146 pt.cmd.cdw12 = htole32(cmd);
148 pt.cmd.cdw11 = htole32(off / sizeof(uint32_t));
150 pt.cmd.cdw13 = htole32(off / sizeof(uint32_t));
155 if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0)
156 err(EX_IOERR, "wdc_get_data request failed");
157 if (nvme_completion_is_error(&pt.cpl))
158 errx(EX_IOERR, "wdc_get_data request returned error");
162 wdc_do_dump_e6(int fd, char *tmpl, const char *suffix, uint32_t opcode,
163 uint32_t cmd, int len_off)
168 uint64_t max_xfer_size;
169 uint32_t len, offset;
171 bool e6lg_flag = false;
173 wdc_append_serial_name(fd, tmpl, MAXPATHLEN, suffix);
175 /* Read Log Dump header */
176 len = WDC_NVME_LOG_SIZE_HDR_LEN;
180 errx(EX_OSERR, "Can't get buffer to read dump");
181 wdc_get_data(fd, opcode, len, offset, cmd, hdr, len, false);
182 if (memcmp("E6LG", hdr, 4) == 0) {
186 /* XXX overwrite protection? */
187 fd2 = open(tmpl, O_WRONLY | O_CREAT | O_TRUNC, 0644);
189 err(EX_CANTCREAT, "open %s", tmpl);
190 if (ioctl(fd, NVME_GET_MAX_XFER_SIZE, &max_xfer_size) < 0)
191 err(EX_IOERR, "query max transfer size failed");
192 buf = aligned_alloc(PAGE_SIZE, max_xfer_size);
194 errx(EX_OSERR, "Can't get buffer to read dump");
200 resid = MIN(len, max_xfer_size);
201 wdc_get_data(fd, opcode, resid, offset, cmd, buf, resid, e6lg_flag);
204 len = be32dec(buf + len_off);
206 errx(EX_PROTOCOL, "No data for %s", suffix);
208 printf("Dumping %d bytes of version %d.%d log to %s\n", len,
209 buf[8], buf[9], tmpl);
211 * Adjust amount to dump if total dump < 1MB,
212 * though it likely doesn't matter to the WDC
219 if (write(fd2, buf, resid) != (ssize_t)resid)
220 err(EX_IOERR, "write");
230 wdc_get_data_dui(int fd, uint32_t opcode, uint32_t len, uint64_t off,
231 uint8_t *buffer, size_t buflen)
233 struct nvme_pt_command pt;
235 memset(&pt, 0, sizeof(pt));
238 pt.cmd.cdw10 = htole32((len / sizeof(uint32_t)) - 1) ;
239 pt.cmd.cdw12 = htole32(off & 0xFFFFFFFFu);
240 pt.cmd.cdw13 = htole32(off >> 32);
245 if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0)
246 err(EX_IOERR, "wdc_get_data_dui request failed");
247 if (nvme_completion_is_error(&pt.cpl))
248 errx(EX_IOERR, "wdc_get_data_dui request returned error");
252 wdc_get_dui_max_sections(uint16_t header_ver)
254 switch (header_ver) {
255 case WDC_DUI_HEADER_VER_0:
256 return WDC_NVME_DUI_MAX_SECTIONS_V0;
257 case WDC_DUI_HEADER_VER_1:
258 return WDC_NVME_DUI_MAX_SECTIONS_V1;
259 case WDC_DUI_HEADER_VER_2:
260 return WDC_NVME_DUI_MAX_SECTIONS_V2;
261 case WDC_DUI_HEADER_VER_3:
262 return WDC_NVME_DUI_MAX_SECTIONS_V3;
268 wdc_get_dui_log_size(int fd, uint32_t opcode, uint8_t data_area,
269 uint64_t *log_size, int len_off)
272 uint8_t max_sections;
280 hdr = (uint8_t*)malloc(len);
282 errx(EX_OSERR, "Can't get buffer to read header");
283 wdc_get_data_dui(fd, opcode, len, 0, hdr, len);
286 hdr_ver = ((*hdr & 0xF) != 0)? *hdr : le16dec(hdr);
287 max_sections = wdc_get_dui_max_sections(hdr_ver);
289 if (hdr_ver == 0 || hdr_ver == 1) {
290 dui_size = (uint64_t)le32dec(hdr + 4);
293 for (i = 0, j = 0; i < (int)max_sections; i++, j+=8)
294 dui_size += (uint64_t)le32dec(hdr + j + 4);
296 } else if (hdr_ver == 2 || hdr_ver == 3) {
297 if (data_area == 0) {
298 dui_size = le64dec(hdr + 4);
301 for (i = 0, j = 0 ; i < (int)max_sections; i++, j+=12)
302 dui_size += le64dec(hdr + j + 4);
306 for (i = 0, j = 0; i < (int)max_sections; i++, j+=12) {
307 if (le16dec(hdr + j + 2) <= data_area)
308 dui_size += le64dec(hdr + j + 4);
315 errx(EX_PROTOCOL, "ERROR : No valid header ");
317 *log_size = dui_size;
322 wdc_do_dump_dui(int fd, char *tmpl, uint8_t data_area,
323 const char *suffix, uint32_t opcode, int len_off)
327 uint64_t max_xfer_size;
329 uint64_t log_len, offset;
332 wdc_append_serial_name(fd, tmpl, MAXPATHLEN, suffix);
333 wdc_get_dui_log_size(fd, opcode, data_area, &log_len, len_off);
335 errx(EX_PROTOCOL, "No data for %s", suffix);
336 fd2 = open(tmpl, O_WRONLY | O_CREAT | O_TRUNC, 0644);
338 err(EX_CANTCREAT, "open %s", tmpl);
339 if (ioctl(fd, NVME_GET_MAX_XFER_SIZE, &max_xfer_size) < 0)
340 err(EX_IOERR, "query max transfer size failed");
341 buf = aligned_alloc(PAGE_SIZE, max_xfer_size);
343 errx(EX_OSERR, "Can't get buffer to read dump");
347 while (log_len > 0) {
348 resid = MIN(log_len, max_xfer_size);
349 wdc_get_data_dui(fd, opcode, resid, offset, buf, resid);
351 hdr_ver = ((buf[len_off] & 0xF) != 0) ?
352 (buf[len_off]) : (le16dec(buf + len_off));
353 printf("Dumping %jd bytes of version %d log to %s\n",
354 (uintmax_t)log_len, hdr_ver, tmpl);
357 if (write(fd2, buf, resid) != (ssize_t)resid)
358 err(EX_IOERR, "write");
368 wdc_cap_diag(const struct cmd *f, int argc, char *argv[])
370 char tmpl[MAXPATHLEN];
372 struct nvme_controller_data cdata;
375 if (arg_parse(argc, argv, f))
377 if (opt.template == NULL) {
378 fprintf(stderr, "Missing template arg.\n");
379 arg_help(argc, argv, f);
381 if (opt.data_area > 4) {
382 fprintf(stderr, "Data area range 1-4, supplied %d.\n", opt.data_area);
383 arg_help(argc, argv, f);
385 strlcpy(tmpl, opt.template, sizeof(tmpl));
386 open_dev(opt.dev, &fd, 1, 1);
387 if (read_controller_data(fd, &cdata))
388 errx(EX_IOERR, "Identify request failed");
393 case WDC_NVME_VID_2 :
394 wdc_do_dump_e6(fd, tmpl, "cap_diag", WDC_NVME_CAP_DIAG_OPCODE_E6,
395 WDC_NVME_CAP_DIAG_CMD, 4);
397 case WDC_NVME_VID_3 :
398 wdc_do_dump_dui(fd, tmpl, opt.data_area, "cap_diag",
399 WDC_NVME_CAP_DIAG_OPCODE_FA, 512);
402 errx(EX_UNAVAILABLE, "ERROR : WDC: unsupported device (%#x) for this command", vid);
409 wdc(const struct cmd *nf __unused, int argc, char *argv[])
412 cmd_dispatch(argc, argv, &wdc_cmd);
416 * HGST's 0xc1 page. This is a grab bag of additional data. Please see
417 * https://www.hgst.com/sites/default/files/resources/US_SN150_ProdManual.pdf
418 * https://www.hgst.com/sites/default/files/resources/US_SN100_ProdManual.pdf
419 * Appendix A for details
422 typedef void (*subprint_fn_t)(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
430 static void print_hgst_info_write_errors(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
431 static void print_hgst_info_read_errors(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
432 static void print_hgst_info_verify_errors(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
433 static void print_hgst_info_self_test(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
434 static void print_hgst_info_background_scan(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
435 static void print_hgst_info_erase_errors(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
436 static void print_hgst_info_erase_counts(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
437 static void print_hgst_info_temp_history(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
438 static void print_hgst_info_ssd_perf(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
439 static void print_hgst_info_firmware_load(void *buf, uint16_t subtype, uint8_t res, uint32_t size);
441 static struct subpage_print hgst_subpage[] = {
442 { 0x02, print_hgst_info_write_errors },
443 { 0x03, print_hgst_info_read_errors },
444 { 0x05, print_hgst_info_verify_errors },
445 { 0x10, print_hgst_info_self_test },
446 { 0x15, print_hgst_info_background_scan },
447 { 0x30, print_hgst_info_erase_errors },
448 { 0x31, print_hgst_info_erase_counts },
449 { 0x32, print_hgst_info_temp_history },
450 { 0x37, print_hgst_info_ssd_perf },
451 { 0x38, print_hgst_info_firmware_load },
454 /* Print a subpage that is basically just key value pairs */
456 print_hgst_info_subpage_gen(void *buf, uint16_t subtype __unused, uint32_t size,
457 const struct kv_name *kv, size_t kv_count)
468 ptype = le16dec(wsp);
470 wsp++; /* Flags, just ignore */
473 for (i = 0; i < plen && wsp < esp; i++)
474 param |= (uint64_t)*wsp++ << (i * 8);
475 printf(" %-30s: %jd\n", kv_lookup(kv, kv_count, ptype), (uintmax_t)param);
480 print_hgst_info_write_errors(void *buf, uint16_t subtype, uint8_t res __unused, uint32_t size)
482 static struct kv_name kv[] =
484 { 0x0000, "Corrected Without Delay" },
485 { 0x0001, "Corrected Maybe Delayed" },
486 { 0x0002, "Re-Writes" },
487 { 0x0003, "Errors Corrected" },
488 { 0x0004, "Correct Algorithm Used" },
489 { 0x0005, "Bytes Processed" },
490 { 0x0006, "Uncorrected Errors" },
491 { 0x8000, "Flash Write Commands" },
492 { 0x8001, "HGST Special" },
495 printf("Write Errors Subpage:\n");
496 print_hgst_info_subpage_gen(buf, subtype, size, kv, nitems(kv));
500 print_hgst_info_read_errors(void *buf, uint16_t subtype, uint8_t res __unused, uint32_t size)
502 static struct kv_name kv[] =
504 { 0x0000, "Corrected Without Delay" },
505 { 0x0001, "Corrected Maybe Delayed" },
506 { 0x0002, "Re-Reads" },
507 { 0x0003, "Errors Corrected" },
508 { 0x0004, "Correct Algorithm Used" },
509 { 0x0005, "Bytes Processed" },
510 { 0x0006, "Uncorrected Errors" },
511 { 0x8000, "Flash Read Commands" },
512 { 0x8001, "XOR Recovered" },
513 { 0x8002, "Total Corrected Bits" },
516 printf("Read Errors Subpage:\n");
517 print_hgst_info_subpage_gen(buf, subtype, size, kv, nitems(kv));
521 print_hgst_info_verify_errors(void *buf, uint16_t subtype, uint8_t res __unused, uint32_t size)
523 static struct kv_name kv[] =
525 { 0x0000, "Corrected Without Delay" },
526 { 0x0001, "Corrected Maybe Delayed" },
527 { 0x0002, "Re-Reads" },
528 { 0x0003, "Errors Corrected" },
529 { 0x0004, "Correct Algorithm Used" },
530 { 0x0005, "Bytes Processed" },
531 { 0x0006, "Uncorrected Errors" },
532 { 0x8000, "Commands Processed" },
535 printf("Verify Errors Subpage:\n");
536 print_hgst_info_subpage_gen(buf, subtype, size, kv, nitems(kv));
540 print_hgst_info_self_test(void *buf, uint16_t subtype __unused, uint8_t res __unused, uint32_t size)
543 uint8_t *walker = buf;
547 printf("Self Test Subpage:\n");
548 for (i = 0; i < size / 20; i++) { /* Each entry is 20 bytes */
549 code = le16dec(walker);
551 walker++; /* Ignore fixed flags */
552 if (*walker == 0) /* Last entry is zero length */
554 if (*walker++ != 0x10) {
555 printf("Bad length for self test report\n");
558 printf(" %-30s: %d\n", "Recent Test", code);
559 printf(" %-28s: %#x\n", "Self-Test Results", *walker & 0xf);
560 printf(" %-28s: %#x\n", "Self-Test Code", (*walker >> 5) & 0x7);
562 printf(" %-28s: %#x\n", "Self-Test Number", *walker++);
563 hrs = le16dec(walker);
565 lba = le32dec(walker);
567 printf(" %-28s: %u\n", "Total Power On Hrs", hrs);
568 printf(" %-28s: %#jx (%jd)\n", "LBA", (uintmax_t)lba, (uintmax_t)lba);
569 printf(" %-28s: %#x\n", "Sense Key", *walker++ & 0xf);
570 printf(" %-28s: %#x\n", "Additional Sense Code", *walker++);
571 printf(" %-28s: %#x\n", "Additional Sense Qualifier", *walker++);
572 printf(" %-28s: %#x\n", "Vendor Specific Detail", *walker++);
577 print_hgst_info_background_scan(void *buf, uint16_t subtype __unused, uint8_t res __unused, uint32_t size)
579 uint8_t *walker = buf;
581 uint16_t code, nscan, progress;
584 printf("Background Media Scan Subpage:\n");
585 /* Decode the header */
586 code = le16dec(walker);
588 walker++; /* Ignore fixed flags */
589 if (*walker++ != 0x10) {
590 printf("Bad length for background scan header\n");
594 printf("Expceted code 0, found code %#x\n", code);
597 pom = le32dec(walker);
599 walker++; /* Reserved */
601 nscan = le16dec(walker);
603 progress = le16dec(walker);
605 walker += 6; /* Reserved */
606 printf(" %-30s: %d\n", "Power On Minutes", pom);
607 printf(" %-30s: %x (%s)\n", "BMS Status", status,
608 status == 0 ? "idle" : (status == 1 ? "active" : (status == 8 ? "suspended" : "unknown")));
609 printf(" %-30s: %d\n", "Number of BMS", nscan);
610 printf(" %-30s: %d\n", "Progress Current BMS", progress);
611 /* Report retirements */
612 if (walker - (uint8_t *)buf != 20) {
613 printf("Coding error, offset not 20\n");
617 printf(" %-30s: %d\n", "BMS retirements", size / 0x18);
619 code = le16dec(walker);
622 if (*walker++ != 0x14) {
623 printf("Bad length parameter\n");
626 pom = le32dec(walker);
629 * Spec sheet says the following are hard coded, if true, just
630 * print the NAND retirement.
632 if (walker[0] == 0x41 &&
641 walker += 4; /* Skip reserved */
642 nand = le32dec(walker);
644 printf(" %-30s: %d\n", "Retirement number", code);
645 printf(" %-28s: %#x\n", "NAND (C/T)BBBPPP", nand);
647 printf("Parameter %#x entry corrupt\n", code);
654 print_hgst_info_erase_errors(void *buf, uint16_t subtype __unused, uint8_t res __unused, uint32_t size)
656 static struct kv_name kv[] =
658 { 0x0000, "Corrected Without Delay" },
659 { 0x0001, "Corrected Maybe Delayed" },
660 { 0x0002, "Re-Erase" },
661 { 0x0003, "Errors Corrected" },
662 { 0x0004, "Correct Algorithm Used" },
663 { 0x0005, "Bytes Processed" },
664 { 0x0006, "Uncorrected Errors" },
665 { 0x8000, "Flash Erase Commands" },
666 { 0x8001, "Mfg Defect Count" },
667 { 0x8002, "Grown Defect Count" },
668 { 0x8003, "Erase Count -- User" },
669 { 0x8004, "Erase Count -- System" },
672 printf("Erase Errors Subpage:\n");
673 print_hgst_info_subpage_gen(buf, subtype, size, kv, nitems(kv));
677 print_hgst_info_erase_counts(void *buf, uint16_t subtype, uint8_t res __unused, uint32_t size)
679 /* My drive doesn't export this -- so not coding up */
680 printf("XXX: Erase counts subpage: %p, %#x %d\n", buf, subtype, size);
684 print_hgst_info_temp_history(void *buf, uint16_t subtype __unused, uint8_t res __unused, uint32_t size __unused)
686 uint8_t *walker = buf;
689 printf("Temperature History:\n");
690 printf(" %-30s: %d C\n", "Current Temperature", *walker++);
691 printf(" %-30s: %d C\n", "Reference Temperature", *walker++);
692 printf(" %-30s: %d C\n", "Maximum Temperature", *walker++);
693 printf(" %-30s: %d C\n", "Minimum Temperature", *walker++);
694 min = le32dec(walker);
696 printf(" %-30s: %d:%02d:00\n", "Max Temperature Time", min / 60, min % 60);
697 min = le32dec(walker);
699 printf(" %-30s: %d:%02d:00\n", "Over Temperature Duration", min / 60, min % 60);
700 min = le32dec(walker);
702 printf(" %-30s: %d:%02d:00\n", "Min Temperature Time", min / 60, min % 60);
706 print_hgst_info_ssd_perf(void *buf, uint16_t subtype __unused, uint8_t res, uint32_t size __unused)
708 uint8_t *walker = buf;
711 printf("SSD Performance Subpage Type %d:\n", res);
712 val = le64dec(walker);
714 printf(" %-30s: %ju\n", "Host Read Commands", val);
715 val = le64dec(walker);
717 printf(" %-30s: %ju\n", "Host Read Blocks", val);
718 val = le64dec(walker);
720 printf(" %-30s: %ju\n", "Host Cache Read Hits Commands", val);
721 val = le64dec(walker);
723 printf(" %-30s: %ju\n", "Host Cache Read Hits Blocks", val);
724 val = le64dec(walker);
726 printf(" %-30s: %ju\n", "Host Read Commands Stalled", val);
727 val = le64dec(walker);
729 printf(" %-30s: %ju\n", "Host Write Commands", val);
730 val = le64dec(walker);
732 printf(" %-30s: %ju\n", "Host Write Blocks", val);
733 val = le64dec(walker);
735 printf(" %-30s: %ju\n", "Host Write Odd Start Commands", val);
736 val = le64dec(walker);
738 printf(" %-30s: %ju\n", "Host Write Odd End Commands", val);
739 val = le64dec(walker);
741 printf(" %-30s: %ju\n", "Host Write Commands Stalled", val);
742 val = le64dec(walker);
744 printf(" %-30s: %ju\n", "NAND Read Commands", val);
745 val = le64dec(walker);
747 printf(" %-30s: %ju\n", "NAND Read Blocks", val);
748 val = le64dec(walker);
750 printf(" %-30s: %ju\n", "NAND Write Commands", val);
751 val = le64dec(walker);
753 printf(" %-30s: %ju\n", "NAND Write Blocks", val);
754 val = le64dec(walker);
756 printf(" %-30s: %ju\n", "NAND Read Before Writes", val);
760 print_hgst_info_firmware_load(void *buf, uint16_t subtype __unused, uint8_t res __unused, uint32_t size __unused)
762 uint8_t *walker = buf;
764 printf("Firmware Load Subpage:\n");
765 printf(" %-30s: %d\n", "Firmware Downloads", le32dec(walker));
769 kv_indirect(void *buf, uint32_t subtype, uint8_t res, uint32_t size, struct subpage_print *sp, size_t nsp)
773 for (i = 0; i < nsp; i++, sp++) {
774 if (sp->key == subtype) {
775 sp->fn(buf, subtype, res, size);
779 printf("No handler for page type %x\n", subtype);
783 print_hgst_info_log(const struct nvme_controller_data *cdata __unused, void *buf, uint32_t size __unused)
785 uint8_t *walker, *end, *subpage;
788 uint8_t subtype, res;
790 printf("HGST Extra Info Log\n");
791 printf("===================\n");
796 len = le16dec(walker);
798 end = walker + len; /* Length is exclusive of this header */
800 while (walker < end) {
801 subpage = walker + 4;
802 subtype = *walker++ & 0x3f; /* subtype */
803 res = *walker++; /* Reserved */
804 len = le16dec(walker);
805 walker += len + 2; /* Length, not incl header */
807 printf("Ooops! Off the end of the list\n");
810 kv_indirect(subpage, subtype, res, len, hgst_subpage, nitems(hgst_subpage));
814 NVME_LOGPAGE(hgst_info,
815 HGST_INFO_LOG, "hgst", "Detailed Health/SMART",
816 print_hgst_info_log, DEFAULT_SIZE);
817 NVME_LOGPAGE(wdc_info,
818 HGST_INFO_LOG, "wdc", "Detailed Health/SMART",
819 print_hgst_info_log, DEFAULT_SIZE);