xref: /freebsd/sbin/nvmecontrol/identify_ext.c (revision a91a246563dffa876a52f53a98de4af9fa364c52)
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", PAGE_SIZE * (1L << cdata->mdts));
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("\n");
142 
143 	printf("Admin Command Set Attributes\n");
144 	printf("============================\n");
145 	printf("Security Send/Receive:       %s\n",
146 		security ? "Supported" : "Not Supported");
147 	printf("Format NVM:                  %s\n",
148 		fmt ? "Supported" : "Not Supported");
149 	printf("Firmware Activate/Download:  %s\n",
150 		fw ? "Supported" : "Not Supported");
151 	printf("Namespace Management:        %s\n",
152 		nsmgmt ? "Supported" : "Not Supported");
153 	printf("Device Self-test:            %sSupported\n",
154 	    NVMEV(NVME_CTRLR_DATA_OACS_SELFTEST, oacs) != 0 ? "" : "Not ");
155 	printf("Directives:                  %sSupported\n",
156 	    NVMEV(NVME_CTRLR_DATA_OACS_DIRECTIVES, oacs) != 0 ? "" : "Not ");
157 	printf("NVMe-MI Send/Receive:        %sSupported\n",
158 	    NVMEV(NVME_CTRLR_DATA_OACS_NVMEMI, oacs) != 0 ? "" : "Not ");
159 	printf("Virtualization Management:   %sSupported\n",
160 	    NVMEV(NVME_CTRLR_DATA_OACS_VM, oacs) != 0 ? "" : "Not ");
161 	printf("Doorbell Buffer Config:      %sSupported\n",
162 	    NVMEV(NVME_CTRLR_DATA_OACS_DBBUFFER, oacs) != 0 ? "" : "Not ");
163 	printf("Get LBA Status:              %sSupported\n",
164 	    NVMEV(NVME_CTRLR_DATA_OACS_GETLBA, oacs) != 0 ? "" : "Not ");
165 	printf("Sanitize:                    ");
166 	if (cdata->sanicap != 0) {
167 		printf("%s%s%s\n",
168 		    NVMEV(NVME_CTRLR_DATA_SANICAP_CES, cdata->sanicap) != 0 ?
169 		    "crypto, " : "",
170 		    NVMEV(NVME_CTRLR_DATA_SANICAP_BES, cdata->sanicap) != 0 ?
171 		    "block, " : "",
172 		    NVMEV(NVME_CTRLR_DATA_SANICAP_OWS, cdata->sanicap) != 0 ?
173 		    "overwrite" : "");
174 	} else {
175 		printf("Not Supported\n");
176 	}
177 	printf("Abort Command Limit:         %d\n", cdata->acl+1);
178 	printf("Async Event Request Limit:   %d\n", cdata->aerl+1);
179 	printf("Number of Firmware Slots:    %d\n", fw_num_slots);
180 	printf("Firmware Slot 1 Read-Only:   %s\n", fw_slot1_ro ? "Yes" : "No");
181 	printf("Per-Namespace SMART Log:     %s\n",
182 		ns_smart ? "Yes" : "No");
183 	printf("Error Log Page Entries:      %d\n", cdata->elpe+1);
184 	printf("Number of Power States:      %d\n", cdata->npss+1);
185 	if (cdata->ver >= 0x010200) {
186 		printf("Total NVM Capacity:          %s bytes\n",
187 		    uint128_to_str(to128(cdata->untncap.tnvmcap),
188 		    cbuf, sizeof(cbuf)));
189 		printf("Unallocated NVM Capacity:    %s bytes\n",
190 		    uint128_to_str(to128(cdata->untncap.unvmcap),
191 		    cbuf, sizeof(cbuf)));
192 	}
193 	printf("Firmware Update Granularity: %02x ", fwug);
194 	if (fwug == 0)
195 		printf("(Not Reported)\n");
196 	else if (fwug == 0xFF)
197 		printf("(No Granularity)\n");
198 	else
199 		printf("(%d bytes)\n", ((uint32_t)fwug << 12));
200 	printf("Host Buffer Preferred Size:  %llu bytes\n",
201 	    (long long unsigned)cdata->hmpre * 4096);
202 	printf("Host Buffer Minimum Size:    %llu bytes\n",
203 	    (long long unsigned)cdata->hmmin * 4096);
204 
205 	printf("\n");
206 	printf("NVM Command Set Attributes\n");
207 	printf("==========================\n");
208 	printf("Submission Queue Entry Size\n");
209 	printf("  Max:                       %d\n", 1 << sqes_max);
210 	printf("  Min:                       %d\n", 1 << sqes_min);
211 	printf("Completion Queue Entry Size\n");
212 	printf("  Max:                       %d\n", 1 << cqes_max);
213 	printf("  Min:                       %d\n", 1 << cqes_min);
214 	printf("Number of Namespaces:        %d\n", cdata->nn);
215 	printf("Compare Command:             %s\n",
216 		compare ? "Supported" : "Not Supported");
217 	printf("Write Uncorrectable Command: %s\n",
218 		write_unc ? "Supported" : "Not Supported");
219 	printf("Dataset Management Command:  %s\n",
220 		dsm ? "Supported" : "Not Supported");
221 	printf("Write Zeroes Command:        %sSupported\n",
222 	    NVMEV(NVME_CTRLR_DATA_ONCS_WRZERO, oncs) != 0 ? "" : "Not ");
223 	printf("Save Features:               %sSupported\n",
224 	    NVMEV(NVME_CTRLR_DATA_ONCS_SAVEFEAT, oncs) != 0 ? "" : "Not ");
225 	printf("Reservations:                %sSupported\n",
226 	    NVMEV(NVME_CTRLR_DATA_ONCS_RESERV, oncs) != 0 ? "" : "Not ");
227 	printf("Timestamp feature:           %sSupported\n",
228 	    NVMEV(NVME_CTRLR_DATA_ONCS_TIMESTAMP, oncs) != 0 ? "" : "Not ");
229 	printf("Verify feature:              %sSupported\n",
230 	    NVMEV(NVME_CTRLR_DATA_ONCS_VERIFY, oncs) != 0 ? "" : "Not ");
231 	printf("Fused Operation Support:     %s%s\n",
232 	    (cdata->fuses == 0) ? "Not Supported" : "",
233 	    NVMEV(NVME_CTRLR_DATA_FUSES_CNW, cdata->fuses) != 0 ?
234 	    "Compare and Write" : "");
235 	printf("Format NVM Attributes:       %s%s Erase, %s Format\n",
236 	    NVMEV(NVME_CTRLR_DATA_FNA_CRYPTO_ERASE, cdata->fna) != 0 ?
237 	    "Crypto Erase, " : "",
238 	    NVMEV(NVME_CTRLR_DATA_FNA_ERASE_ALL, cdata->fna) != 0 ?
239 	    "All-NVM" : "Per-NS",
240 	    NVMEV(NVME_CTRLR_DATA_FNA_FORMAT_ALL, cdata->fna) != 0 ?
241 	    "All-NVM" : "Per-NS");
242 	t = NVMEV(NVME_CTRLR_DATA_VWC_ALL, cdata->vwc);
243 	printf("Volatile Write Cache:        %s%s\n",
244 	    NVMEV(NVME_CTRLR_DATA_VWC_PRESENT, cdata->vwc) != 0 ?
245 	    "Present" : "Not Present",
246 	    (t == NVME_CTRLR_DATA_VWC_ALL_NO) ? ", no flush all" :
247 	    (t == NVME_CTRLR_DATA_VWC_ALL_YES) ? ", flush all" : "");
248 
249 	if (cdata->ver >= 0x010201)
250 		printf("\nNVM Subsystem Name:          %.256s\n", cdata->subnqn);
251 }
252