xref: /freebsd/sbin/nvmecontrol/identify_ext.c (revision 9f44a47fd07924afc035991af15d84e6585dea4f)
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/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 
33 #include <sys/param.h>
34 
35 #include <ctype.h>
36 #include <err.h>
37 #include <fcntl.h>
38 #include <stddef.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <unistd.h>
43 
44 #include "nvmecontrol.h"
45 #include "nvmecontrol_ext.h"
46 
47 void
48 nvme_print_controller(struct nvme_controller_data *cdata)
49 {
50 	uint8_t str[128];
51 	char cbuf[UINT128_DIG + 1];
52 	uint16_t oncs, oacs;
53 	uint8_t compare, write_unc, dsm, t;
54 	uint8_t security, fmt, fw, nsmgmt;
55 	uint8_t	fw_slot1_ro, fw_num_slots;
56 	uint8_t ns_smart;
57 	uint8_t sqes_max, sqes_min;
58 	uint8_t cqes_max, cqes_min;
59 	uint8_t fwug;
60 
61 	oncs = cdata->oncs;
62 	compare = (oncs >> NVME_CTRLR_DATA_ONCS_COMPARE_SHIFT) &
63 		NVME_CTRLR_DATA_ONCS_COMPARE_MASK;
64 	write_unc = (oncs >> NVME_CTRLR_DATA_ONCS_WRITE_UNC_SHIFT) &
65 		NVME_CTRLR_DATA_ONCS_WRITE_UNC_MASK;
66 	dsm = (oncs >> NVME_CTRLR_DATA_ONCS_DSM_SHIFT) &
67 		NVME_CTRLR_DATA_ONCS_DSM_MASK;
68 
69 	oacs = cdata->oacs;
70 	security = (oacs >> NVME_CTRLR_DATA_OACS_SECURITY_SHIFT) &
71 		NVME_CTRLR_DATA_OACS_SECURITY_MASK;
72 	fmt = (oacs >> NVME_CTRLR_DATA_OACS_FORMAT_SHIFT) &
73 		NVME_CTRLR_DATA_OACS_FORMAT_MASK;
74 	fw = (oacs >> NVME_CTRLR_DATA_OACS_FIRMWARE_SHIFT) &
75 		NVME_CTRLR_DATA_OACS_FIRMWARE_MASK;
76 	nsmgmt = (oacs >> NVME_CTRLR_DATA_OACS_NSMGMT_SHIFT) &
77 		NVME_CTRLR_DATA_OACS_NSMGMT_MASK;
78 
79 	fw_num_slots = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_NUM_SLOTS_SHIFT) &
80 		NVME_CTRLR_DATA_FRMW_NUM_SLOTS_MASK;
81 	fw_slot1_ro = (cdata->frmw >> NVME_CTRLR_DATA_FRMW_SLOT1_RO_SHIFT) &
82 		NVME_CTRLR_DATA_FRMW_SLOT1_RO_MASK;
83 	fwug = cdata->fwug;
84 
85 	ns_smart = (cdata->lpa >> NVME_CTRLR_DATA_LPA_NS_SMART_SHIFT) &
86 		NVME_CTRLR_DATA_LPA_NS_SMART_MASK;
87 
88 	sqes_min = (cdata->sqes >> NVME_CTRLR_DATA_SQES_MIN_SHIFT) &
89 		NVME_CTRLR_DATA_SQES_MIN_MASK;
90 	sqes_max = (cdata->sqes >> NVME_CTRLR_DATA_SQES_MAX_SHIFT) &
91 		NVME_CTRLR_DATA_SQES_MAX_MASK;
92 
93 	cqes_min = (cdata->cqes >> NVME_CTRLR_DATA_CQES_MIN_SHIFT) &
94 		NVME_CTRLR_DATA_CQES_MIN_MASK;
95 	cqes_max = (cdata->cqes >> NVME_CTRLR_DATA_CQES_MAX_SHIFT) &
96 		NVME_CTRLR_DATA_CQES_MAX_MASK;
97 
98 	printf("Controller Capabilities/Features\n");
99 	printf("================================\n");
100 	printf("Vendor ID:                   %04x\n", cdata->vid);
101 	printf("Subsystem Vendor ID:         %04x\n", cdata->ssvid);
102 	nvme_strvis(str, cdata->sn, sizeof(str), NVME_SERIAL_NUMBER_LENGTH);
103 	printf("Serial Number:               %s\n", str);
104 	nvme_strvis(str, cdata->mn, sizeof(str), NVME_MODEL_NUMBER_LENGTH);
105 	printf("Model Number:                %s\n", str);
106 	nvme_strvis(str, cdata->fr, sizeof(str), NVME_FIRMWARE_REVISION_LENGTH);
107 	printf("Firmware Version:            %s\n", str);
108 	printf("Recommended Arb Burst:       %d\n", cdata->rab);
109 	printf("IEEE OUI Identifier:         %02x %02x %02x\n",
110 		cdata->ieee[2], cdata->ieee[1], cdata->ieee[0]);
111 	printf("Multi-Path I/O Capabilities: %s%s%s%s%s\n",
112 	    (cdata->mic == 0) ? "Not Supported" : "",
113 	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_ANAR_SHIFT) &
114 	     NVME_CTRLR_DATA_MIC_SRIOVVF_MASK) ? "Asymmetric, " : "",
115 	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_SRIOVVF_SHIFT) &
116 	     NVME_CTRLR_DATA_MIC_SRIOVVF_MASK) ? "SR-IOV VF, " : "",
117 	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_MCTRLRS_SHIFT) &
118 	     NVME_CTRLR_DATA_MIC_MCTRLRS_MASK) ? "Multiple controllers, " : "",
119 	    ((cdata->mic >> NVME_CTRLR_DATA_MIC_MPORTS_SHIFT) &
120 	     NVME_CTRLR_DATA_MIC_MPORTS_MASK) ? "Multiple ports" : "");
121 	/* TODO: Use CAP.MPSMIN to determine true memory page size. */
122 	printf("Max Data Transfer Size:      ");
123 	if (cdata->mdts == 0)
124 		printf("Unlimited\n");
125 	else
126 		printf("%ld bytes\n", PAGE_SIZE * (1L << cdata->mdts));
127 	printf("Sanitize Crypto Erase:       %s\n",
128 		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_CES_SHIFT) &
129 		    NVME_CTRLR_DATA_SANICAP_CES_MASK) ?
130 		    "Supported" : "Not Supported");
131 	printf("Sanitize Block Erase:        %s\n",
132 		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_BES_SHIFT) &
133 		    NVME_CTRLR_DATA_SANICAP_BES_MASK) ?
134 		    "Supported" : "Not Supported");
135 	printf("Sanitize Overwrite:          %s\n",
136 		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_OWS_SHIFT) &
137 		    NVME_CTRLR_DATA_SANICAP_OWS_MASK) ?
138 		    "Supported" : "Not Supported");
139 	printf("Sanitize NDI:                %s\n",
140 		((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_NDI_SHIFT) &
141 		    NVME_CTRLR_DATA_SANICAP_NDI_MASK) ?
142 		    "Supported" : "Not Supported");
143 	printf("Sanitize NODMMAS:            ");
144 	switch (((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_NODMMAS_SHIFT) &
145 	    NVME_CTRLR_DATA_SANICAP_NODMMAS_MASK)) {
146 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_UNDEF:
147 		printf("Undefined\n");
148 		break;
149 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_NO:
150 		printf("No\n");
151 		break;
152 	case NVME_CTRLR_DATA_SANICAP_NODMMAS_YES:
153 		printf("Yes\n");
154 		break;
155 	default:
156 		printf("Unknown\n");
157 		break;
158 	}
159 	printf("Controller ID:               0x%04x\n", cdata->ctrlr_id);
160 	printf("Version:                     %d.%d.%d\n",
161 	    (cdata->ver >> 16) & 0xffff, (cdata->ver >> 8) & 0xff,
162 	    cdata->ver & 0xff);
163 	printf("\n");
164 
165 	printf("Admin Command Set Attributes\n");
166 	printf("============================\n");
167 	printf("Security Send/Receive:       %s\n",
168 		security ? "Supported" : "Not Supported");
169 	printf("Format NVM:                  %s\n",
170 		fmt ? "Supported" : "Not Supported");
171 	printf("Firmware Activate/Download:  %s\n",
172 		fw ? "Supported" : "Not Supported");
173 	printf("Namespace Management:        %s\n",
174 		nsmgmt ? "Supported" : "Not Supported");
175 	printf("Device Self-test:            %sSupported\n",
176 	    ((oacs >> NVME_CTRLR_DATA_OACS_SELFTEST_SHIFT) &
177 	     NVME_CTRLR_DATA_OACS_SELFTEST_MASK) ? "" : "Not ");
178 	printf("Directives:                  %sSupported\n",
179 	    ((oacs >> NVME_CTRLR_DATA_OACS_DIRECTIVES_SHIFT) &
180 	     NVME_CTRLR_DATA_OACS_DIRECTIVES_MASK) ? "" : "Not ");
181 	printf("NVMe-MI Send/Receive:        %sSupported\n",
182 	    ((oacs >> NVME_CTRLR_DATA_OACS_NVMEMI_SHIFT) &
183 	     NVME_CTRLR_DATA_OACS_NVMEMI_MASK) ? "" : "Not ");
184 	printf("Virtualization Management:   %sSupported\n",
185 	    ((oacs >> NVME_CTRLR_DATA_OACS_VM_SHIFT) &
186 	     NVME_CTRLR_DATA_OACS_VM_MASK) ? "" : "Not ");
187 	printf("Doorbell Buffer Config:      %sSupported\n",
188 	    ((oacs >> NVME_CTRLR_DATA_OACS_DBBUFFER_SHIFT) &
189 	     NVME_CTRLR_DATA_OACS_DBBUFFER_MASK) ? "" : "Not ");
190 	printf("Get LBA Status:              %sSupported\n",
191 	    ((oacs >> NVME_CTRLR_DATA_OACS_GETLBA_SHIFT) &
192 	     NVME_CTRLR_DATA_OACS_GETLBA_MASK) ? "" : "Not ");
193 	printf("Sanitize:                    ");
194 	if (cdata->sanicap != 0) {
195 		printf("%s%s%s\n",
196 		    ((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_CES_SHIFT) &
197 		     NVME_CTRLR_DATA_SANICAP_CES_MASK) ? "crypto, " : "",
198 		    ((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_BES_SHIFT) &
199 		     NVME_CTRLR_DATA_SANICAP_BES_MASK) ? "block, " : "",
200 		    ((cdata->sanicap >> NVME_CTRLR_DATA_SANICAP_OWS_SHIFT) &
201 		     NVME_CTRLR_DATA_SANICAP_OWS_MASK) ? "overwrite" : "");
202 	} else {
203 		printf("Not Supported\n");
204 	}
205 	printf("Abort Command Limit:         %d\n", cdata->acl+1);
206 	printf("Async Event Request Limit:   %d\n", cdata->aerl+1);
207 	printf("Number of Firmware Slots:    %d\n", fw_num_slots);
208 	printf("Firmware Slot 1 Read-Only:   %s\n", fw_slot1_ro ? "Yes" : "No");
209 	printf("Per-Namespace SMART Log:     %s\n",
210 		ns_smart ? "Yes" : "No");
211 	printf("Error Log Page Entries:      %d\n", cdata->elpe+1);
212 	printf("Number of Power States:      %d\n", cdata->npss+1);
213 	if (cdata->ver >= 0x010200) {
214 		printf("Total NVM Capacity:          %s bytes\n",
215 		    uint128_to_str(to128(cdata->untncap.tnvmcap),
216 		    cbuf, sizeof(cbuf)));
217 		printf("Unallocated NVM Capacity:    %s bytes\n",
218 		    uint128_to_str(to128(cdata->untncap.unvmcap),
219 		    cbuf, sizeof(cbuf)));
220 	}
221 	printf("Firmware Update Granularity: %02x ", fwug);
222 	if (fwug == 0)
223 		printf("(Not Reported)\n");
224 	else if (fwug == 0xFF)
225 		printf("(No Granularity)\n");
226 	else
227 		printf("(%d bytes)\n", ((uint32_t)fwug << 12));
228 	printf("Host Buffer Preferred Size:  %llu bytes\n",
229 	    (long long unsigned)cdata->hmpre * 4096);
230 	printf("Host Buffer Minimum Size:    %llu bytes\n",
231 	    (long long unsigned)cdata->hmmin * 4096);
232 
233 	printf("\n");
234 	printf("NVM Command Set Attributes\n");
235 	printf("==========================\n");
236 	printf("Submission Queue Entry Size\n");
237 	printf("  Max:                       %d\n", 1 << sqes_max);
238 	printf("  Min:                       %d\n", 1 << sqes_min);
239 	printf("Completion Queue Entry Size\n");
240 	printf("  Max:                       %d\n", 1 << cqes_max);
241 	printf("  Min:                       %d\n", 1 << cqes_min);
242 	printf("Number of Namespaces:        %d\n", cdata->nn);
243 	printf("Compare Command:             %s\n",
244 		compare ? "Supported" : "Not Supported");
245 	printf("Write Uncorrectable Command: %s\n",
246 		write_unc ? "Supported" : "Not Supported");
247 	printf("Dataset Management Command:  %s\n",
248 		dsm ? "Supported" : "Not Supported");
249 	printf("Write Zeroes Command:        %sSupported\n",
250 	    ((oncs >> NVME_CTRLR_DATA_ONCS_WRZERO_SHIFT) &
251 	     NVME_CTRLR_DATA_ONCS_WRZERO_MASK) ? "" : "Not ");
252 	printf("Save Features:               %sSupported\n",
253 	    ((oncs >> NVME_CTRLR_DATA_ONCS_SAVEFEAT_SHIFT) &
254 	     NVME_CTRLR_DATA_ONCS_SAVEFEAT_MASK) ? "" : "Not ");
255 	printf("Reservations:                %sSupported\n",
256 	    ((oncs >> NVME_CTRLR_DATA_ONCS_RESERV_SHIFT) &
257 	     NVME_CTRLR_DATA_ONCS_RESERV_MASK) ? "" : "Not ");
258 	printf("Timestamp feature:           %sSupported\n",
259 	    ((oncs >> NVME_CTRLR_DATA_ONCS_TIMESTAMP_SHIFT) &
260 	     NVME_CTRLR_DATA_ONCS_TIMESTAMP_MASK) ? "" : "Not ");
261 	printf("Verify feature:              %sSupported\n",
262 	    ((oncs >> NVME_CTRLR_DATA_ONCS_VERIFY_SHIFT) &
263 	     NVME_CTRLR_DATA_ONCS_VERIFY_MASK) ? "" : "Not ");
264 	printf("Fused Operation Support:     %s%s\n",
265 	    (cdata->fuses == 0) ? "Not Supported" : "",
266 	    ((cdata->fuses >> NVME_CTRLR_DATA_FUSES_CNW_SHIFT) &
267 	     NVME_CTRLR_DATA_FUSES_CNW_MASK) ? "Compare and Write" : "");
268 	printf("Format NVM Attributes:       %s%s Erase, %s Format\n",
269 	    ((cdata->fna >> NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_SHIFT) &
270 	     NVME_CTRLR_DATA_FNA_CRYPTO_ERASE_MASK) ? "Crypto Erase, " : "",
271 	    ((cdata->fna >> NVME_CTRLR_DATA_FNA_ERASE_ALL_SHIFT) &
272 	     NVME_CTRLR_DATA_FNA_ERASE_ALL_MASK) ? "All-NVM" : "Per-NS",
273 	    ((cdata->fna >> NVME_CTRLR_DATA_FNA_FORMAT_ALL_SHIFT) &
274 	     NVME_CTRLR_DATA_FNA_FORMAT_ALL_MASK) ? "All-NVM" : "Per-NS");
275 	t = (cdata->vwc >> NVME_CTRLR_DATA_VWC_ALL_SHIFT) &
276 	    NVME_CTRLR_DATA_VWC_ALL_MASK;
277 	printf("Volatile Write Cache:        %s%s\n",
278 	    ((cdata->vwc >> NVME_CTRLR_DATA_VWC_PRESENT_SHIFT) &
279 	     NVME_CTRLR_DATA_VWC_PRESENT_MASK) ? "Present" : "Not Present",
280 	    (t == NVME_CTRLR_DATA_VWC_ALL_NO) ? ", no flush all" :
281 	    (t == NVME_CTRLR_DATA_VWC_ALL_YES) ? ", flush all" : "");
282 
283 	if (cdata->ver >= 0x010201)
284 		printf("\nNVM Subsystem Name:          %.256s\n", cdata->subnqn);
285 }
286