xref: /freebsd/sbin/nvmecontrol/identify_ext.c (revision 22039031a15238c69497bbd9d8dea3cd97ee6bc6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (C) 2012-2013 Intel Corporation
5  * All rights reserved.
6  * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #include <sys/param.h>
31 
32 #include <ctype.h>
33 #include <err.h>
34 #include <fcntl.h>
35 #include <stddef.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <unistd.h>
40 
41 #include "nvmecontrol.h"
42 #include "nvmecontrol_ext.h"
43 
44 void
45 nvme_print_controller(struct nvme_controller_data *cdata)
46 {
47 	uint8_t str[128];
48 	char cbuf[UINT128_DIG + 1];
49 	uint16_t oncs, oacs;
50 	uint8_t compare, write_unc, dsm, t;
51 	uint8_t security, fmt, fw, nsmgmt;
52 	uint8_t	fw_slot1_ro, fw_num_slots;
53 	uint8_t ns_smart;
54 	uint8_t sqes_max, sqes_min;
55 	uint8_t cqes_max, cqes_min;
56 	uint8_t fwug;
57 
58 	oncs = cdata->oncs;
59 	compare = NVMEV(NVME_CTRLR_DATA_ONCS_COMPARE, oncs);
60 	write_unc = NVMEV(NVME_CTRLR_DATA_ONCS_WRITE_UNC, oncs);
61 	dsm = NVMEV(NVME_CTRLR_DATA_ONCS_DSM, oncs);
62 
63 	oacs = cdata->oacs;
64 	security = NVMEV(NVME_CTRLR_DATA_OACS_SECURITY, oacs);
65 	fmt = NVMEV(NVME_CTRLR_DATA_OACS_FORMAT, oacs);
66 	fw = NVMEV(NVME_CTRLR_DATA_OACS_FIRMWARE, oacs);
67 	nsmgmt = NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, oacs);
68 
69 	fw_num_slots = NVMEV(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, cdata->frmw);
70 	fw_slot1_ro = NVMEV(NVME_CTRLR_DATA_FRMW_SLOT1_RO, cdata->frmw);
71 	fwug = cdata->fwug;
72 
73 	ns_smart = NVMEV(NVME_CTRLR_DATA_LPA_NS_SMART, cdata->lpa);
74 
75 	sqes_min = NVMEV(NVME_CTRLR_DATA_SQES_MIN, cdata->sqes);
76 	sqes_max = NVMEV(NVME_CTRLR_DATA_SQES_MAX, cdata->sqes);
77 
78 	cqes_min = NVMEV(NVME_CTRLR_DATA_CQES_MIN, cdata->cqes);
79 	cqes_max = NVMEV(NVME_CTRLR_DATA_CQES_MAX, cdata->cqes);
80 
81 	printf("Controller Capabilities/Features\n");
82 	printf("================================\n");
83 	printf("Vendor ID:                   %04x\n", cdata->vid);
84 	printf("Subsystem Vendor ID:         %04x\n", cdata->ssvid);
85 	nvme_strvis(str, cdata->sn, sizeof(str), NVME_SERIAL_NUMBER_LENGTH);
86 	printf("Serial Number:               %s\n", str);
87 	nvme_strvis(str, cdata->mn, sizeof(str), NVME_MODEL_NUMBER_LENGTH);
88 	printf("Model Number:                %s\n", str);
89 	nvme_strvis(str, cdata->fr, sizeof(str), NVME_FIRMWARE_REVISION_LENGTH);
90 	printf("Firmware Version:            %s\n", str);
91 	printf("Recommended Arb Burst:       %d\n", cdata->rab);
92 	printf("IEEE OUI Identifier:         %02x %02x %02x\n",
93 		cdata->ieee[2], cdata->ieee[1], cdata->ieee[0]);
94 	printf("Multi-Path I/O Capabilities: %s%s%s%s%s\n",
95 	    (cdata->mic == 0) ? "Not Supported" : "",
96 	    NVMEV(NVME_CTRLR_DATA_MIC_ANAR, cdata->mic) != 0 ?
97 	    "Asymmetric, " : "",
98 	    NVMEV(NVME_CTRLR_DATA_MIC_SRIOVVF, cdata->mic) != 0 ?
99 	    "SR-IOV VF, " : "",
100 	    NVMEV(NVME_CTRLR_DATA_MIC_MCTRLRS, cdata->mic) != 0 ?
101 	    "Multiple controllers, " : "",
102 	    NVMEV(NVME_CTRLR_DATA_MIC_MPORTS, cdata->mic) != 0 ?
103 	    "Multiple ports" : "");
104 	/* TODO: Use CAP.MPSMIN to determine true memory page size. */
105 	printf("Max Data Transfer Size:      ");
106 	if (cdata->mdts == 0)
107 		printf("Unlimited\n");
108 	else
109 		printf("%ld bytes\n", 1L << (cdata->mdts + NVME_MPS_SHIFT));
110 	printf("Sanitize Crypto Erase:       %s\n",
111 	    NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
112 	    "Supported" : "Not Supported");
113 	printf("Sanitize Block Erase:        %s\n",
114 	    NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
115 	    "Supported" : "Not Supported");
116 	printf("Sanitize Overwrite:          %s\n",
117 	    NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
118 	    "Supported" : "Not Supported");
119 	printf("Sanitize NDI:                %s\n",
120 	    NVMEV(NVME_CTRLR_DATA_SANICAP_NDI, cdata->sanicap) != 0 ?
121 	    "Supported" : "Not Supported");
122 	printf("Sanitize NODMMAS:            ");
123 	switch (NVMEV(NVME_CTRLR_DATA_SANICAP_NODMMAS, cdata->sanicap)) {
124 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_UNDEF:
125 		printf("Undefined\n");
126 		break;
127 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_NO:
128 		printf("No\n");
129 		break;
130 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_YES:
131 		printf("Yes\n");
132 		break;
133 	default:
134 		printf("Unknown\n");
135 		break;
136 	}
137 	printf("Controller ID:               0x%04x\n", cdata->ctrlr_id);
138 	printf("Version:                     %d.%d.%d\n",
139 	    (cdata->ver >> 16) & 0xffff, (cdata->ver >> 8) & 0xff,
140 	    cdata->ver & 0xff);
141 	printf("Traffic Based Keep Alive:    %sSupported\n",
142 	    NVMEV(NVME_CTRLR_DATA_CTRATT_TBKAS, cdata->ctratt) ? "" : "Not ");
143 	printf("CXL HDM:                     %sSupported\n",
144 	    NVMEV(NVME_CTRLR_DATA_CHSI_CHS, cdata->chsi) ? "" : "Not ");
145 	printf("NVMSS Shutdown Latency:      ");
146 	if (cdata->nssl == 0)
147 		printf("Not Reported\n");
148 	else
149 		printf("%u us\n", cdata->nssl);
150 	printf("PLS Emergency Power Fail:    %sSupported\n",
151 	    NVMEV(NVME_CTRLR_DATA_PLSI_PLSEPF, cdata->plsi) ? "" : "Not ");
152 	printf("PLS Forced Quiescence:       %sSupported\n",
153 	    NVMEV(NVME_CTRLR_DATA_PLSI_PLSFQ, cdata->plsi) ? "" : "Not ");
154 	printf("Controller Type:             ");
155 	switch (cdata->cntrltype) {
156 	case 0:
157 		printf("Not Reported\n");
158 		break;
159 	case 1:
160 		printf("I/O Controller\n");
161 		break;
162 	case 2:
163 		printf("Discovery Controller\n");
164 		break;
165 	case 3:
166 		printf("Administrative Controller\n");
167 		break;
168 	default:
169 		printf("%d (Reserved)\n", cdata->cntrltype);
170 		break;
171 	}
172 	printf("Keep Alive Timer             ");
173 	if (cdata->kas == 0)
174 		printf("Not Supported\n");
175 	else
176 		printf("%u ms granularity\n", cdata->kas * 100);
177 	printf("Maximum Outstanding Commands ");
178 	if (cdata->maxcmd == 0)
179 		printf("Not Specified\n");
180 	else
181 		printf("%u\n", cdata->maxcmd);
182 	printf("\n");
183 
184 	printf("Admin Command Set Attributes\n");
185 	printf("============================\n");
186 	printf("Security Send/Receive:       %s\n",
187 		security ? "Supported" : "Not Supported");
188 	printf("Format NVM:                  %s\n",
189 		fmt ? "Supported" : "Not Supported");
190 	printf("Firmware Activate/Download:  %s\n",
191 		fw ? "Supported" : "Not Supported");
192 	printf("Namespace Management:        %s\n",
193 		nsmgmt ? "Supported" : "Not Supported");
194 	printf("Device Self-test:            %sSupported\n",
195 	    NVMEV(NVME_CTRLR_DATA_OACS_SELFTEST, oacs) != 0 ? "" : "Not ");
196 	printf("Directives:                  %sSupported\n",
197 	    NVMEV(NVME_CTRLR_DATA_OACS_DIRECTIVES, oacs) != 0 ? "" : "Not ");
198 	printf("NVMe-MI Send/Receive:        %sSupported\n",
199 	    NVMEV(NVME_CTRLR_DATA_OACS_NVMEMI, oacs) != 0 ? "" : "Not ");
200 	printf("Virtualization Management:   %sSupported\n",
201 	    NVMEV(NVME_CTRLR_DATA_OACS_VM, oacs) != 0 ? "" : "Not ");
202 	printf("Doorbell Buffer Config:      %sSupported\n",
203 	    NVMEV(NVME_CTRLR_DATA_OACS_DBBUFFER, oacs) != 0 ? "" : "Not ");
204 	printf("Get LBA Status:              %sSupported\n",
205 	    NVMEV(NVME_CTRLR_DATA_OACS_GETLBA, oacs) != 0 ? "" : "Not ");
206 	printf("Sanitize:                    ");
207 	if (cdata->sanicap != 0) {
208 		printf("%s%s%s\n",
209 		    NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
210 		    "crypto, " : "",
211 		    NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
212 		    "block, " : "",
213 		    NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
214 		    "overwrite" : "");
215 	} else {
216 		printf("Not Supported\n");
217 	}
218 	printf("Abort Command Limit:         %d\n", cdata->acl+1);
219 	printf("Async Event Request Limit:   %d\n", cdata->aerl+1);
220 	printf("Number of Firmware Slots:    %d\n", fw_num_slots);
221 	printf("Firmware Slot 1 Read-Only:   %s\n", fw_slot1_ro ? "Yes" : "No");
222 	printf("Per-Namespace SMART Log:     %s\n",
223 		ns_smart ? "Yes" : "No");
224 	printf("Error Log Page Entries:      %d\n", cdata->elpe+1);
225 	printf("Number of Power States:      %d\n", cdata->npss+1);
226 	if (cdata->ver >= 0x010200) {
227 		printf("Total NVM Capacity:          %s bytes\n",
228 		    uint128_to_str(to128(cdata->untncap.tnvmcap),
229 		    cbuf, sizeof(cbuf)));
230 		printf("Unallocated NVM Capacity:    %s bytes\n",
231 		    uint128_to_str(to128(cdata->untncap.unvmcap),
232 		    cbuf, sizeof(cbuf)));
233 	}
234 	printf("Firmware Update Granularity: %02x ", fwug);
235 	if (fwug == 0)
236 		printf("(Not Reported)\n");
237 	else if (fwug == 0xFF)
238 		printf("(No Granularity)\n");
239 	else
240 		printf("(%d bytes)\n", ((uint32_t)fwug << 12));
241 	printf("Host Buffer Preferred Size:  %llu bytes\n",
242 	    (long long unsigned)cdata->hmpre * 4096);
243 	printf("Host Buffer Minimum Size:    %llu bytes\n",
244 	    (long long unsigned)cdata->hmmin * 4096);
245 
246 	printf("\n");
247 	printf("NVM Command Set Attributes\n");
248 	printf("==========================\n");
249 	printf("Submission Queue Entry Size\n");
250 	printf("  Max:                       %d\n", 1 << sqes_max);
251 	printf("  Min:                       %d\n", 1 << sqes_min);
252 	printf("Completion Queue Entry Size\n");
253 	printf("  Max:                       %d\n", 1 << cqes_max);
254 	printf("  Min:                       %d\n", 1 << cqes_min);
255 	printf("Number of Namespaces:        %d\n", cdata->nn);
256 	printf("Compare Command:             %s\n",
257 		compare ? "Supported" : "Not Supported");
258 	printf("Write Uncorrectable Command: %s\n",
259 		write_unc ? "Supported" : "Not Supported");
260 	printf("Dataset Management Command:  %s\n",
261 		dsm ? "Supported" : "Not Supported");
262 	printf("Write Zeroes Command:        %sSupported\n",
263 	    NVMEV(NVME_CTRLR_DATA_ONCS_WRZERO, oncs) != 0 ? "" : "Not ");
264 	printf("Save Features:               %sSupported\n",
265 	    NVMEV(NVME_CTRLR_DATA_ONCS_SAVEFEAT, oncs) != 0 ? "" : "Not ");
266 	printf("Reservations:                %sSupported\n",
267 	    NVMEV(NVME_CTRLR_DATA_ONCS_RESERV, oncs) != 0 ? "" : "Not ");
268 	printf("Timestamp feature:           %sSupported\n",
269 	    NVMEV(NVME_CTRLR_DATA_ONCS_TIMESTAMP, oncs) != 0 ? "" : "Not ");
270 	printf("Verify feature:              %sSupported\n",
271 	    NVMEV(NVME_CTRLR_DATA_ONCS_VERIFY, oncs) != 0 ? "" : "Not ");
272 	printf("Fused Operation Support:     %s%s\n",
273 	    (cdata->fuses == 0) ? "Not Supported" : "",
274 	    NVMEV(NVME_CTRLR_DATA_FUSES_CNW, cdata->fuses) != 0 ?
275 	    "Compare and Write" : "");
276 	printf("Format NVM Attributes:       %s%s Erase, %s Format\n",
277 	    NVMEV(NVME_CTRLR_DATA_FNA_CRYPTO_ERASE, cdata->fna) != 0 ?
278 	    "Crypto Erase, " : "",
279 	    NVMEV(NVME_CTRLR_DATA_FNA_ERASE_ALL, cdata->fna) != 0 ?
280 	    "All-NVM" : "Per-NS",
281 	    NVMEV(NVME_CTRLR_DATA_FNA_FORMAT_ALL, cdata->fna) != 0 ?
282 	    "All-NVM" : "Per-NS");
283 	t = NVMEV(NVME_CTRLR_DATA_VWC_ALL, cdata->vwc);
284 	printf("Volatile Write Cache:        %s%s\n",
285 	    NVMEV(NVME_CTRLR_DATA_VWC_PRESENT, cdata->vwc) != 0 ?
286 	    "Present" : "Not Present",
287 	    (t == NVME_CTRLR_DATA_VWC_ALL_NO) ? ", no flush all" :
288 	    (t == NVME_CTRLR_DATA_VWC_ALL_YES) ? ", flush all" : "");
289 
290 	if (cdata->ver >= 0x010201)
291 		printf("\nNVM Subsystem Name:          %.256s\n", cdata->subnqn);
292 
293 	if (cdata->ioccsz != 0) {
294 		printf("\n");
295 		printf("Fabrics Attributes\n");
296 		printf("==================\n");
297 		printf("I/O Command Capsule Size:    %d bytes\n",
298 		    cdata->ioccsz * 16);
299 		printf("I/O Response Capsule Size:   %d bytes\n",
300 		    cdata->iorcsz * 16);
301 		printf("In Capsule Data Offset:      %d bytes\n",
302 		    cdata->icdoff * 16);
303 		printf("Controller Model:            %s\n",
304 		    (cdata->fcatt & 1) == 0 ? "Dynamic" : "Static");
305 		printf("Max SGL Descriptors:         ");
306 		if (cdata->msdbd == 0)
307 			printf("Unlimited\n");
308 		else
309 			printf("%d\n", cdata->msdbd);
310 		printf("Disconnect of I/O Queues:    %sSupported\n",
311 		    (cdata->ofcs & 1) == 1 ? "" : "Not ");
312 	}
313 }
314