xref: /freebsd/sbin/nvmecontrol/identify_ext.c (revision fba73a408314d8e32056d4a812c9a2eb5f618b5d)
1e505b7ecSWarner Losh /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3e505b7ecSWarner Losh  *
4e505b7ecSWarner Losh  * Copyright (C) 2012-2013 Intel Corporation
5e505b7ecSWarner Losh  * All rights reserved.
6a7bf63beSAlexander Motin  * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
7e505b7ecSWarner Losh  *
8e505b7ecSWarner Losh  * Redistribution and use in source and binary forms, with or without
9e505b7ecSWarner Losh  * modification, are permitted provided that the following conditions
10e505b7ecSWarner Losh  * are met:
11e505b7ecSWarner Losh  * 1. Redistributions of source code must retain the above copyright
12e505b7ecSWarner Losh  *    notice, this list of conditions and the following disclaimer.
13e505b7ecSWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
14e505b7ecSWarner Losh  *    notice, this list of conditions and the following disclaimer in the
15e505b7ecSWarner Losh  *    documentation and/or other materials provided with the distribution.
16e505b7ecSWarner Losh  *
17e505b7ecSWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18e505b7ecSWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19e505b7ecSWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20e505b7ecSWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21e505b7ecSWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22e505b7ecSWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23e505b7ecSWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24e505b7ecSWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25e505b7ecSWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26e505b7ecSWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27e505b7ecSWarner Losh  * SUCH DAMAGE.
28e505b7ecSWarner Losh  */
29e505b7ecSWarner Losh 
30e505b7ecSWarner Losh #include <sys/param.h>
31e505b7ecSWarner Losh 
32e505b7ecSWarner Losh #include <ctype.h>
33e505b7ecSWarner Losh #include <err.h>
34e505b7ecSWarner Losh #include <fcntl.h>
35e505b7ecSWarner Losh #include <stddef.h>
36e505b7ecSWarner Losh #include <stdio.h>
37e505b7ecSWarner Losh #include <stdlib.h>
38e505b7ecSWarner Losh #include <string.h>
39e505b7ecSWarner Losh #include <unistd.h>
40e505b7ecSWarner Losh 
41e505b7ecSWarner Losh #include "nvmecontrol.h"
42e505b7ecSWarner Losh #include "nvmecontrol_ext.h"
43e505b7ecSWarner Losh 
44e505b7ecSWarner Losh void
45e505b7ecSWarner Losh nvme_print_controller(struct nvme_controller_data *cdata)
46e505b7ecSWarner Losh {
47e505b7ecSWarner Losh 	uint8_t str[128];
48e505b7ecSWarner Losh 	char cbuf[UINT128_DIG + 1];
49e505b7ecSWarner Losh 	uint16_t oncs, oacs;
508de2d8c0SAlexander Motin 	uint8_t compare, write_unc, dsm, t;
51e505b7ecSWarner Losh 	uint8_t security, fmt, fw, nsmgmt;
52e505b7ecSWarner Losh 	uint8_t	fw_slot1_ro, fw_num_slots;
53e505b7ecSWarner Losh 	uint8_t ns_smart;
54e505b7ecSWarner Losh 	uint8_t sqes_max, sqes_min;
55e505b7ecSWarner Losh 	uint8_t cqes_max, cqes_min;
5616969d14SDavid Bright 	uint8_t fwug;
57e505b7ecSWarner Losh 
58e505b7ecSWarner Losh 	oncs = cdata->oncs;
59*fba73a40SJohn Baldwin 	compare = NVMEV(NVME_CTRLR_DATA_ONCS_COMPARE, oncs);
60*fba73a40SJohn Baldwin 	write_unc = NVMEV(NVME_CTRLR_DATA_ONCS_WRITE_UNC, oncs);
61*fba73a40SJohn Baldwin 	dsm = NVMEV(NVME_CTRLR_DATA_ONCS_DSM, oncs);
62e505b7ecSWarner Losh 
63e505b7ecSWarner Losh 	oacs = cdata->oacs;
64*fba73a40SJohn Baldwin 	security = NVMEV(NVME_CTRLR_DATA_OACS_SECURITY, oacs);
65*fba73a40SJohn Baldwin 	fmt = NVMEV(NVME_CTRLR_DATA_OACS_FORMAT, oacs);
66*fba73a40SJohn Baldwin 	fw = NVMEV(NVME_CTRLR_DATA_OACS_FIRMWARE, oacs);
67*fba73a40SJohn Baldwin 	nsmgmt = NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, oacs);
68e505b7ecSWarner Losh 
69*fba73a40SJohn Baldwin 	fw_num_slots = NVMEV(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, cdata->frmw);
70*fba73a40SJohn Baldwin 	fw_slot1_ro = NVMEV(NVME_CTRLR_DATA_FRMW_SLOT1_RO, cdata->frmw);
7116969d14SDavid Bright 	fwug = cdata->fwug;
72e505b7ecSWarner Losh 
73*fba73a40SJohn Baldwin 	ns_smart = NVMEV(NVME_CTRLR_DATA_LPA_NS_SMART, cdata->lpa);
74e505b7ecSWarner Losh 
75*fba73a40SJohn Baldwin 	sqes_min = NVMEV(NVME_CTRLR_DATA_SQES_MIN, cdata->sqes);
76*fba73a40SJohn Baldwin 	sqes_max = NVMEV(NVME_CTRLR_DATA_SQES_MAX, cdata->sqes);
77e505b7ecSWarner Losh 
78*fba73a40SJohn Baldwin 	cqes_min = NVMEV(NVME_CTRLR_DATA_CQES_MIN, cdata->cqes);
79*fba73a40SJohn Baldwin 	cqes_max = NVMEV(NVME_CTRLR_DATA_CQES_MAX, cdata->cqes);
80e505b7ecSWarner Losh 
81e505b7ecSWarner Losh 	printf("Controller Capabilities/Features\n");
82e505b7ecSWarner Losh 	printf("================================\n");
83e505b7ecSWarner Losh 	printf("Vendor ID:                   %04x\n", cdata->vid);
84e505b7ecSWarner Losh 	printf("Subsystem Vendor ID:         %04x\n", cdata->ssvid);
85e505b7ecSWarner Losh 	nvme_strvis(str, cdata->sn, sizeof(str), NVME_SERIAL_NUMBER_LENGTH);
86e505b7ecSWarner Losh 	printf("Serial Number:               %s\n", str);
87e505b7ecSWarner Losh 	nvme_strvis(str, cdata->mn, sizeof(str), NVME_MODEL_NUMBER_LENGTH);
88e505b7ecSWarner Losh 	printf("Model Number:                %s\n", str);
89e505b7ecSWarner Losh 	nvme_strvis(str, cdata->fr, sizeof(str), NVME_FIRMWARE_REVISION_LENGTH);
90e505b7ecSWarner Losh 	printf("Firmware Version:            %s\n", str);
91e505b7ecSWarner Losh 	printf("Recommended Arb Burst:       %d\n", cdata->rab);
92e505b7ecSWarner Losh 	printf("IEEE OUI Identifier:         %02x %02x %02x\n",
9341be508dSWanpeng Qian 		cdata->ieee[2], cdata->ieee[1], cdata->ieee[0]);
948de2d8c0SAlexander Motin 	printf("Multi-Path I/O Capabilities: %s%s%s%s%s\n",
95e505b7ecSWarner Losh 	    (cdata->mic == 0) ? "Not Supported" : "",
96*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_MIC_ANAR, cdata->mic) != 0 ?
97*fba73a40SJohn Baldwin 	    "Asymmetric, " : "",
98*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_MIC_SRIOVVF, cdata->mic) != 0 ?
99*fba73a40SJohn Baldwin 	    "SR-IOV VF, " : "",
100*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_MIC_MCTRLRS, cdata->mic) != 0 ?
101*fba73a40SJohn Baldwin 	    "Multiple controllers, " : "",
102*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_MIC_MPORTS, cdata->mic) != 0 ?
103*fba73a40SJohn Baldwin 	    "Multiple ports" : "");
104e505b7ecSWarner Losh 	/* TODO: Use CAP.MPSMIN to determine true memory page size. */
105e505b7ecSWarner Losh 	printf("Max Data Transfer Size:      ");
106e505b7ecSWarner Losh 	if (cdata->mdts == 0)
107e505b7ecSWarner Losh 		printf("Unlimited\n");
108e505b7ecSWarner Losh 	else
1094035e778SAlexander Motin 		printf("%ld bytes\n", PAGE_SIZE * (1L << cdata->mdts));
110ae5a522cSAllan Jude 	printf("Sanitize Crypto Erase:       %s\n",
111*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
112ae5a522cSAllan Jude 	    "Supported" : "Not Supported");
113ae5a522cSAllan Jude 	printf("Sanitize Block Erase:        %s\n",
114*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
115ae5a522cSAllan Jude 	    "Supported" : "Not Supported");
116ae5a522cSAllan Jude 	printf("Sanitize Overwrite:          %s\n",
117*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
118ae5a522cSAllan Jude 	    "Supported" : "Not Supported");
119ae5a522cSAllan Jude 	printf("Sanitize NDI:                %s\n",
120*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_SANICAP_NDI, cdata->sanicap) != 0 ?
121ae5a522cSAllan Jude 	    "Supported" : "Not Supported");
122ae5a522cSAllan Jude 	printf("Sanitize NODMMAS:            ");
123*fba73a40SJohn Baldwin 	switch (NVMEV(NVME_CTRLR_DATA_SANICAP_NODMMAS, cdata->sanicap)) {
124ae5a522cSAllan Jude 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_UNDEF:
125ae5a522cSAllan Jude 		printf("Undefined\n");
126ae5a522cSAllan Jude 		break;
127ae5a522cSAllan Jude 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_NO:
128ae5a522cSAllan Jude 		printf("No\n");
129ae5a522cSAllan Jude 		break;
130ae5a522cSAllan Jude 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_YES:
131ae5a522cSAllan Jude 		printf("Yes\n");
132ae5a522cSAllan Jude 		break;
133ae5a522cSAllan Jude 	default:
134ae5a522cSAllan Jude 		printf("Unknown\n");
135ae5a522cSAllan Jude 		break;
136ae5a522cSAllan Jude 	}
1373b3dd3f7SAlexander Motin 	printf("Controller ID:               0x%04x\n", cdata->ctrlr_id);
138e505b7ecSWarner Losh 	printf("Version:                     %d.%d.%d\n",
139e505b7ecSWarner Losh 	    (cdata->ver >> 16) & 0xffff, (cdata->ver >> 8) & 0xff,
140e505b7ecSWarner Losh 	    cdata->ver & 0xff);
141e505b7ecSWarner Losh 	printf("\n");
142e505b7ecSWarner Losh 
143e505b7ecSWarner Losh 	printf("Admin Command Set Attributes\n");
144e505b7ecSWarner Losh 	printf("============================\n");
145e505b7ecSWarner Losh 	printf("Security Send/Receive:       %s\n",
146e505b7ecSWarner Losh 		security ? "Supported" : "Not Supported");
147e505b7ecSWarner Losh 	printf("Format NVM:                  %s\n",
148e505b7ecSWarner Losh 		fmt ? "Supported" : "Not Supported");
149e505b7ecSWarner Losh 	printf("Firmware Activate/Download:  %s\n",
150e505b7ecSWarner Losh 		fw ? "Supported" : "Not Supported");
15195a74ab4SEdward Tomasz Napierala 	printf("Namespace Management:        %s\n",
152e505b7ecSWarner Losh 		nsmgmt ? "Supported" : "Not Supported");
153e505b7ecSWarner Losh 	printf("Device Self-test:            %sSupported\n",
154*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_OACS_SELFTEST, oacs) != 0 ? "" : "Not ");
155e505b7ecSWarner Losh 	printf("Directives:                  %sSupported\n",
156*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_OACS_DIRECTIVES, oacs) != 0 ? "" : "Not ");
157e505b7ecSWarner Losh 	printf("NVMe-MI Send/Receive:        %sSupported\n",
158*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_OACS_NVMEMI, oacs) != 0 ? "" : "Not ");
159e505b7ecSWarner Losh 	printf("Virtualization Management:   %sSupported\n",
160*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_OACS_VM, oacs) != 0 ? "" : "Not ");
1618de2d8c0SAlexander Motin 	printf("Doorbell Buffer Config:      %sSupported\n",
162*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_OACS_DBBUFFER, oacs) != 0 ? "" : "Not ");
1638de2d8c0SAlexander Motin 	printf("Get LBA Status:              %sSupported\n",
164*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_OACS_GETLBA, oacs) != 0 ? "" : "Not ");
1658de2d8c0SAlexander Motin 	printf("Sanitize:                    ");
1668de2d8c0SAlexander Motin 	if (cdata->sanicap != 0) {
1678de2d8c0SAlexander Motin 		printf("%s%s%s\n",
168*fba73a40SJohn Baldwin 		    NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
169*fba73a40SJohn Baldwin 		    "crypto, " : "",
170*fba73a40SJohn Baldwin 		    NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
171*fba73a40SJohn Baldwin 		    "block, " : "",
172*fba73a40SJohn Baldwin 		    NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
173*fba73a40SJohn Baldwin 		    "overwrite" : "");
1748de2d8c0SAlexander Motin 	} else {
1758de2d8c0SAlexander Motin 		printf("Not Supported\n");
1768de2d8c0SAlexander Motin 	}
177e505b7ecSWarner Losh 	printf("Abort Command Limit:         %d\n", cdata->acl+1);
178e505b7ecSWarner Losh 	printf("Async Event Request Limit:   %d\n", cdata->aerl+1);
1790fd43b0cSWanpeng Qian 	printf("Number of Firmware Slots:    %d\n", fw_num_slots);
1800fd43b0cSWanpeng Qian 	printf("Firmware Slot 1 Read-Only:   %s\n", fw_slot1_ro ? "Yes" : "No");
181e505b7ecSWarner Losh 	printf("Per-Namespace SMART Log:     %s\n",
182e505b7ecSWarner Losh 		ns_smart ? "Yes" : "No");
183e505b7ecSWarner Losh 	printf("Error Log Page Entries:      %d\n", cdata->elpe+1);
184e505b7ecSWarner Losh 	printf("Number of Power States:      %d\n", cdata->npss+1);
1854035e778SAlexander Motin 	if (cdata->ver >= 0x010200) {
1864035e778SAlexander Motin 		printf("Total NVM Capacity:          %s bytes\n",
1874035e778SAlexander Motin 		    uint128_to_str(to128(cdata->untncap.tnvmcap),
1884035e778SAlexander Motin 		    cbuf, sizeof(cbuf)));
1894035e778SAlexander Motin 		printf("Unallocated NVM Capacity:    %s bytes\n",
1904035e778SAlexander Motin 		    uint128_to_str(to128(cdata->untncap.unvmcap),
1914035e778SAlexander Motin 		    cbuf, sizeof(cbuf)));
1924035e778SAlexander Motin 	}
19316969d14SDavid Bright 	printf("Firmware Update Granularity: %02x ", fwug);
19416969d14SDavid Bright 	if (fwug == 0)
19516969d14SDavid Bright 		printf("(Not Reported)\n");
19616969d14SDavid Bright 	else if (fwug == 0xFF)
19716969d14SDavid Bright 		printf("(No Granularity)\n");
19816969d14SDavid Bright 	else
19916969d14SDavid Bright 		printf("(%d bytes)\n", ((uint32_t)fwug << 12));
20083018b79SAlexander Motin 	printf("Host Buffer Preferred Size:  %llu bytes\n",
20183018b79SAlexander Motin 	    (long long unsigned)cdata->hmpre * 4096);
20283018b79SAlexander Motin 	printf("Host Buffer Minimum Size:    %llu bytes\n",
20383018b79SAlexander Motin 	    (long long unsigned)cdata->hmmin * 4096);
204e505b7ecSWarner Losh 
205e505b7ecSWarner Losh 	printf("\n");
206e505b7ecSWarner Losh 	printf("NVM Command Set Attributes\n");
207e505b7ecSWarner Losh 	printf("==========================\n");
208e505b7ecSWarner Losh 	printf("Submission Queue Entry Size\n");
209e505b7ecSWarner Losh 	printf("  Max:                       %d\n", 1 << sqes_max);
210e505b7ecSWarner Losh 	printf("  Min:                       %d\n", 1 << sqes_min);
211e505b7ecSWarner Losh 	printf("Completion Queue Entry Size\n");
212e505b7ecSWarner Losh 	printf("  Max:                       %d\n", 1 << cqes_max);
213e505b7ecSWarner Losh 	printf("  Min:                       %d\n", 1 << cqes_min);
214e505b7ecSWarner Losh 	printf("Number of Namespaces:        %d\n", cdata->nn);
215e505b7ecSWarner Losh 	printf("Compare Command:             %s\n",
216e505b7ecSWarner Losh 		compare ? "Supported" : "Not Supported");
217e505b7ecSWarner Losh 	printf("Write Uncorrectable Command: %s\n",
218e505b7ecSWarner Losh 		write_unc ? "Supported" : "Not Supported");
219e505b7ecSWarner Losh 	printf("Dataset Management Command:  %s\n",
220e505b7ecSWarner Losh 		dsm ? "Supported" : "Not Supported");
221e505b7ecSWarner Losh 	printf("Write Zeroes Command:        %sSupported\n",
222*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_ONCS_WRZERO, oncs) != 0 ? "" : "Not ");
223e505b7ecSWarner Losh 	printf("Save Features:               %sSupported\n",
224*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_ONCS_SAVEFEAT, oncs) != 0 ? "" : "Not ");
225e505b7ecSWarner Losh 	printf("Reservations:                %sSupported\n",
226*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_ONCS_RESERV, oncs) != 0 ? "" : "Not ");
227e505b7ecSWarner Losh 	printf("Timestamp feature:           %sSupported\n",
228*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_ONCS_TIMESTAMP, oncs) != 0 ? "" : "Not ");
2298de2d8c0SAlexander Motin 	printf("Verify feature:              %sSupported\n",
230*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_ONCS_VERIFY, oncs) != 0 ? "" : "Not ");
231e505b7ecSWarner Losh 	printf("Fused Operation Support:     %s%s\n",
232e505b7ecSWarner Losh 	    (cdata->fuses == 0) ? "Not Supported" : "",
233*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_FUSES_CNW, cdata->fuses) != 0 ?
234*fba73a40SJohn Baldwin 	    "Compare and Write" : "");
235e505b7ecSWarner Losh 	printf("Format NVM Attributes:       %s%s Erase, %s Format\n",
236*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_FNA_CRYPTO_ERASE, cdata->fna) != 0 ?
237*fba73a40SJohn Baldwin 	    "Crypto Erase, " : "",
238*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_FNA_ERASE_ALL, cdata->fna) != 0 ?
239*fba73a40SJohn Baldwin 	    "All-NVM" : "Per-NS",
240*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_FNA_FORMAT_ALL, cdata->fna) != 0 ?
241*fba73a40SJohn Baldwin 	    "All-NVM" : "Per-NS");
242*fba73a40SJohn Baldwin 	t = NVMEV(NVME_CTRLR_DATA_VWC_ALL, cdata->vwc);
2438de2d8c0SAlexander Motin 	printf("Volatile Write Cache:        %s%s\n",
244*fba73a40SJohn Baldwin 	    NVMEV(NVME_CTRLR_DATA_VWC_PRESENT, cdata->vwc) != 0 ?
245*fba73a40SJohn Baldwin 	    "Present" : "Not Present",
2468de2d8c0SAlexander Motin 	    (t == NVME_CTRLR_DATA_VWC_ALL_NO) ? ", no flush all" :
2478de2d8c0SAlexander Motin 	    (t == NVME_CTRLR_DATA_VWC_ALL_YES) ? ", flush all" : "");
248e505b7ecSWarner Losh 
2494035e778SAlexander Motin 	if (cdata->ver >= 0x010201)
2504035e778SAlexander Motin 		printf("\nNVM Subsystem Name:          %.256s\n", cdata->subnqn);
251e505b7ecSWarner Losh }
252