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