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 <[email protected]>
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
nvme_print_controller(struct nvme_controller_data * cdata)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 = NVMEV(NVME_CTRLR_DATA_ONCS_COMPARE, oncs);
61 write_unc = NVMEV(NVME_CTRLR_DATA_ONCS_WRITE_UNC, oncs);
62 dsm = NVMEV(NVME_CTRLR_DATA_ONCS_DSM, oncs);
63
64 oacs = cdata->oacs;
65 security = NVMEV(NVME_CTRLR_DATA_OACS_SECURITY, oacs);
66 fmt = NVMEV(NVME_CTRLR_DATA_OACS_FORMAT, oacs);
67 fw = NVMEV(NVME_CTRLR_DATA_OACS_FIRMWARE, oacs);
68 nsmgmt = NVMEV(NVME_CTRLR_DATA_OACS_NSMGMT, oacs);
69
70 fw_num_slots = NVMEV(NVME_CTRLR_DATA_FRMW_NUM_SLOTS, cdata->frmw);
71 fw_slot1_ro = NVMEV(NVME_CTRLR_DATA_FRMW_SLOT1_RO, cdata->frmw);
72 fwug = cdata->fwug;
73
74 ns_smart = NVMEV(NVME_CTRLR_DATA_LPA_NS_SMART, cdata->lpa);
75
76 sqes_min = NVMEV(NVME_CTRLR_DATA_SQES_MIN, cdata->sqes);
77 sqes_max = NVMEV(NVME_CTRLR_DATA_SQES_MAX, cdata->sqes);
78
79 cqes_min = NVMEV(NVME_CTRLR_DATA_CQES_MIN, cdata->cqes);
80 cqes_max = NVMEV(NVME_CTRLR_DATA_CQES_MAX, cdata->cqes);
81
82 printf("Controller Capabilities/Features\n");
83 printf("================================\n");
84 printf("Vendor ID: %04x\n", cdata->vid);
85 printf("Subsystem Vendor ID: %04x\n", cdata->ssvid);
86 nvme_strvis(str, cdata->sn, sizeof(str), NVME_SERIAL_NUMBER_LENGTH);
87 printf("Serial Number: %s\n", str);
88 nvme_strvis(str, cdata->mn, sizeof(str), NVME_MODEL_NUMBER_LENGTH);
89 printf("Model Number: %s\n", str);
90 nvme_strvis(str, cdata->fr, sizeof(str), NVME_FIRMWARE_REVISION_LENGTH);
91 printf("Firmware Version: %s\n", str);
92 printf("Recommended Arb Burst: %d\n", cdata->rab);
93 printf("IEEE OUI Identifier: %02x %02x %02x\n",
94 cdata->ieee[2], cdata->ieee[1], cdata->ieee[0]);
95 printf("Multi-Path I/O Capabilities: %s%s%s%s%s\n",
96 (cdata->mic == 0) ? "Not Supported" : "",
97 NVMEV(NVME_CTRLR_DATA_MIC_ANAR, cdata->mic) != 0 ?
98 "Asymmetric, " : "",
99 NVMEV(NVME_CTRLR_DATA_MIC_SRIOVVF, cdata->mic) != 0 ?
100 "SR-IOV VF, " : "",
101 NVMEV(NVME_CTRLR_DATA_MIC_MCTRLRS, cdata->mic) != 0 ?
102 "Multiple controllers, " : "",
103 NVMEV(NVME_CTRLR_DATA_MIC_MPORTS, cdata->mic) != 0 ?
104 "Multiple ports" : "");
105 /* TODO: Use CAP.MPSMIN to determine true memory page size. */
106 printf("Max Data Transfer Size: ");
107 if (cdata->mdts == 0)
108 printf("Unlimited\n");
109 else
110 printf("%ld bytes\n", PAGE_SIZE * (1L << cdata->mdts));
111 printf("Sanitize Crypto Erase: %s\n",
112 NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
113 "Supported" : "Not Supported");
114 printf("Sanitize Block Erase: %s\n",
115 NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
116 "Supported" : "Not Supported");
117 printf("Sanitize Overwrite: %s\n",
118 NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
119 "Supported" : "Not Supported");
120 printf("Sanitize NDI: %s\n",
121 NVMEV(NVME_CTRLR_DATA_SANICAP_NDI, cdata->sanicap) != 0 ?
122 "Supported" : "Not Supported");
123 printf("Sanitize NODMMAS: ");
124 switch (NVMEV(NVME_CTRLR_DATA_SANICAP_NODMMAS, cdata->sanicap)) {
125 case NVME_CTRLR_DATA_SANICAP_NODMMAS_UNDEF:
126 printf("Undefined\n");
127 break;
128 case NVME_CTRLR_DATA_SANICAP_NODMMAS_NO:
129 printf("No\n");
130 break;
131 case NVME_CTRLR_DATA_SANICAP_NODMMAS_YES:
132 printf("Yes\n");
133 break;
134 default:
135 printf("Unknown\n");
136 break;
137 }
138 printf("Controller ID: 0x%04x\n", cdata->ctrlr_id);
139 printf("Version: %d.%d.%d\n",
140 (cdata->ver >> 16) & 0xffff, (cdata->ver >> 8) & 0xff,
141 cdata->ver & 0xff);
142 printf("Traffic Based Keep Alive: %sSupported\n",
143 NVMEV(NVME_CTRLR_DATA_CTRATT_TBKAS, cdata->ctratt) ? "" : "Not ");
144 printf("Controller Type: ");
145 switch (cdata->cntrltype) {
146 case 0:
147 printf("Not Reported\n");
148 break;
149 case 1:
150 printf("I/O Controller\n");
151 break;
152 case 2:
153 printf("Discovery Controller\n");
154 break;
155 case 3:
156 printf("Administrative Controller\n");
157 break;
158 default:
159 printf("%d (Reserved)\n", cdata->cntrltype);
160 break;
161 }
162 printf("Keep Alive Timer ");
163 if (cdata->kas == 0)
164 printf("Not Supported\n");
165 else
166 printf("%u ms granularity\n", cdata->kas * 100);
167 printf("Maximum Outstanding Commands ");
168 if (cdata->maxcmd == 0)
169 printf("Not Specified\n");
170 else
171 printf("%u\n", cdata->maxcmd);
172 printf("\n");
173
174 printf("Admin Command Set Attributes\n");
175 printf("============================\n");
176 printf("Security Send/Receive: %s\n",
177 security ? "Supported" : "Not Supported");
178 printf("Format NVM: %s\n",
179 fmt ? "Supported" : "Not Supported");
180 printf("Firmware Activate/Download: %s\n",
181 fw ? "Supported" : "Not Supported");
182 printf("Namespace Management: %s\n",
183 nsmgmt ? "Supported" : "Not Supported");
184 printf("Device Self-test: %sSupported\n",
185 NVMEV(NVME_CTRLR_DATA_OACS_SELFTEST, oacs) != 0 ? "" : "Not ");
186 printf("Directives: %sSupported\n",
187 NVMEV(NVME_CTRLR_DATA_OACS_DIRECTIVES, oacs) != 0 ? "" : "Not ");
188 printf("NVMe-MI Send/Receive: %sSupported\n",
189 NVMEV(NVME_CTRLR_DATA_OACS_NVMEMI, oacs) != 0 ? "" : "Not ");
190 printf("Virtualization Management: %sSupported\n",
191 NVMEV(NVME_CTRLR_DATA_OACS_VM, oacs) != 0 ? "" : "Not ");
192 printf("Doorbell Buffer Config: %sSupported\n",
193 NVMEV(NVME_CTRLR_DATA_OACS_DBBUFFER, oacs) != 0 ? "" : "Not ");
194 printf("Get LBA Status: %sSupported\n",
195 NVMEV(NVME_CTRLR_DATA_OACS_GETLBA, oacs) != 0 ? "" : "Not ");
196 printf("Sanitize: ");
197 if (cdata->sanicap != 0) {
198 printf("%s%s%s\n",
199 NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
200 "crypto, " : "",
201 NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
202 "block, " : "",
203 NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
204 "overwrite" : "");
205 } else {
206 printf("Not Supported\n");
207 }
208 printf("Abort Command Limit: %d\n", cdata->acl+1);
209 printf("Async Event Request Limit: %d\n", cdata->aerl+1);
210 printf("Number of Firmware Slots: %d\n", fw_num_slots);
211 printf("Firmware Slot 1 Read-Only: %s\n", fw_slot1_ro ? "Yes" : "No");
212 printf("Per-Namespace SMART Log: %s\n",
213 ns_smart ? "Yes" : "No");
214 printf("Error Log Page Entries: %d\n", cdata->elpe+1);
215 printf("Number of Power States: %d\n", cdata->npss+1);
216 if (cdata->ver >= 0x010200) {
217 printf("Total NVM Capacity: %s bytes\n",
218 uint128_to_str(to128(cdata->untncap.tnvmcap),
219 cbuf, sizeof(cbuf)));
220 printf("Unallocated NVM Capacity: %s bytes\n",
221 uint128_to_str(to128(cdata->untncap.unvmcap),
222 cbuf, sizeof(cbuf)));
223 }
224 printf("Firmware Update Granularity: %02x ", fwug);
225 if (fwug == 0)
226 printf("(Not Reported)\n");
227 else if (fwug == 0xFF)
228 printf("(No Granularity)\n");
229 else
230 printf("(%d bytes)\n", ((uint32_t)fwug << 12));
231 printf("Host Buffer Preferred Size: %llu bytes\n",
232 (long long unsigned)cdata->hmpre * 4096);
233 printf("Host Buffer Minimum Size: %llu bytes\n",
234 (long long unsigned)cdata->hmmin * 4096);
235
236 printf("\n");
237 printf("NVM Command Set Attributes\n");
238 printf("==========================\n");
239 printf("Submission Queue Entry Size\n");
240 printf(" Max: %d\n", 1 << sqes_max);
241 printf(" Min: %d\n", 1 << sqes_min);
242 printf("Completion Queue Entry Size\n");
243 printf(" Max: %d\n", 1 << cqes_max);
244 printf(" Min: %d\n", 1 << cqes_min);
245 printf("Number of Namespaces: %d\n", cdata->nn);
246 printf("Compare Command: %s\n",
247 compare ? "Supported" : "Not Supported");
248 printf("Write Uncorrectable Command: %s\n",
249 write_unc ? "Supported" : "Not Supported");
250 printf("Dataset Management Command: %s\n",
251 dsm ? "Supported" : "Not Supported");
252 printf("Write Zeroes Command: %sSupported\n",
253 NVMEV(NVME_CTRLR_DATA_ONCS_WRZERO, oncs) != 0 ? "" : "Not ");
254 printf("Save Features: %sSupported\n",
255 NVMEV(NVME_CTRLR_DATA_ONCS_SAVEFEAT, oncs) != 0 ? "" : "Not ");
256 printf("Reservations: %sSupported\n",
257 NVMEV(NVME_CTRLR_DATA_ONCS_RESERV, oncs) != 0 ? "" : "Not ");
258 printf("Timestamp feature: %sSupported\n",
259 NVMEV(NVME_CTRLR_DATA_ONCS_TIMESTAMP, oncs) != 0 ? "" : "Not ");
260 printf("Verify feature: %sSupported\n",
261 NVMEV(NVME_CTRLR_DATA_ONCS_VERIFY, oncs) != 0 ? "" : "Not ");
262 printf("Fused Operation Support: %s%s\n",
263 (cdata->fuses == 0) ? "Not Supported" : "",
264 NVMEV(NVME_CTRLR_DATA_FUSES_CNW, cdata->fuses) != 0 ?
265 "Compare and Write" : "");
266 printf("Format NVM Attributes: %s%s Erase, %s Format\n",
267 NVMEV(NVME_CTRLR_DATA_FNA_CRYPTO_ERASE, cdata->fna) != 0 ?
268 "Crypto Erase, " : "",
269 NVMEV(NVME_CTRLR_DATA_FNA_ERASE_ALL, cdata->fna) != 0 ?
270 "All-NVM" : "Per-NS",
271 NVMEV(NVME_CTRLR_DATA_FNA_FORMAT_ALL, cdata->fna) != 0 ?
272 "All-NVM" : "Per-NS");
273 t = NVMEV(NVME_CTRLR_DATA_VWC_ALL, cdata->vwc);
274 printf("Volatile Write Cache: %s%s\n",
275 NVMEV(NVME_CTRLR_DATA_VWC_PRESENT, cdata->vwc) != 0 ?
276 "Present" : "Not Present",
277 (t == NVME_CTRLR_DATA_VWC_ALL_NO) ? ", no flush all" :
278 (t == NVME_CTRLR_DATA_VWC_ALL_YES) ? ", flush all" : "");
279
280 if (cdata->ver >= 0x010201)
281 printf("\nNVM Subsystem Name: %.256s\n", cdata->subnqn);
282
283 if (cdata->ioccsz != 0) {
284 printf("\n");
285 printf("Fabrics Attributes\n");
286 printf("==================\n");
287 printf("I/O Command Capsule Size: %d bytes\n",
288 cdata->ioccsz * 16);
289 printf("I/O Response Capsule Size: %d bytes\n",
290 cdata->iorcsz * 16);
291 printf("In Capsule Data Offset: %d bytes\n",
292 cdata->icdoff * 16);
293 printf("Controller Model: %s\n",
294 (cdata->fcatt & 1) == 0 ? "Dynamic" : "Static");
295 printf("Max SGL Descriptors: ");
296 if (cdata->msdbd == 0)
297 printf("Unlimited\n");
298 else
299 printf("%d\n", cdata->msdbd);
300 printf("Disconnect of I/O Queues: %sSupported\n",
301 (cdata->ofcs & 1) == 1 ? "" : "Not ");
302 }
303 }
304