2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2012-2013 Intel Corporation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
43 #include "nvmecontrol.h"
46 print_controller(struct nvme_controller_data *cdata)
49 char cbuf[UINT128_DIG + 1];
51 printf("Controller Capabilities/Features\n");
52 printf("================================\n");
53 printf("Vendor ID: %04x\n", cdata->vid);
54 printf("Subsystem Vendor ID: %04x\n", cdata->ssvid);
55 nvme_strvis(str, cdata->sn, sizeof(str), NVME_SERIAL_NUMBER_LENGTH);
56 printf("Serial Number: %s\n", str);
57 nvme_strvis(str, cdata->mn, sizeof(str), NVME_MODEL_NUMBER_LENGTH);
58 printf("Model Number: %s\n", str);
59 nvme_strvis(str, cdata->fr, sizeof(str), NVME_FIRMWARE_REVISION_LENGTH);
60 printf("Firmware Version: %s\n", str);
61 printf("Recommended Arb Burst: %d\n", cdata->rab);
62 printf("IEEE OUI Identifier: %02x %02x %02x\n",
63 cdata->ieee[0], cdata->ieee[1], cdata->ieee[2]);
64 printf("Multi-Interface Cap: %02x\n", cdata->mic);
65 /* TODO: Use CAP.MPSMIN to determine true memory page size. */
66 printf("Max Data Transfer Size: ");
68 printf("Unlimited\n");
70 printf("%d\n", PAGE_SIZE * (1 << cdata->mdts));
71 printf("Controller ID: 0x%02x\n", cdata->ctrlr_id);
74 printf("Admin Command Set Attributes\n");
75 printf("============================\n");
76 printf("Security Send/Receive: %s\n",
77 cdata->oacs.security ? "Supported" : "Not Supported");
78 printf("Format NVM: %s\n",
79 cdata->oacs.format ? "Supported" : "Not Supported");
80 printf("Firmware Activate/Download: %s\n",
81 cdata->oacs.firmware ? "Supported" : "Not Supported");
82 printf("Namespace Managment: %s\n",
83 cdata->oacs.nsmgmt ? "Supported" : "Not Supported");
84 printf("Abort Command Limit: %d\n", cdata->acl+1);
85 printf("Async Event Request Limit: %d\n", cdata->aerl+1);
86 printf("Number of Firmware Slots: ");
87 if (cdata->oacs.firmware != 0)
88 printf("%d\n", cdata->frmw.num_slots);
91 printf("Firmware Slot 1 Read-Only: ");
92 if (cdata->oacs.firmware != 0)
93 printf("%s\n", cdata->frmw.slot1_ro ? "Yes" : "No");
96 printf("Per-Namespace SMART Log: %s\n",
97 cdata->lpa.ns_smart ? "Yes" : "No");
98 printf("Error Log Page Entries: %d\n", cdata->elpe+1);
99 printf("Number of Power States: %d\n", cdata->npss+1);
102 printf("NVM Command Set Attributes\n");
103 printf("==========================\n");
104 printf("Submission Queue Entry Size\n");
105 printf(" Max: %d\n", 1 << cdata->sqes.max);
106 printf(" Min: %d\n", 1 << cdata->sqes.min);
107 printf("Completion Queue Entry Size\n");
108 printf(" Max: %d\n", 1 << cdata->cqes.max);
109 printf(" Min: %d\n", 1 << cdata->cqes.min);
110 printf("Number of Namespaces: %d\n", cdata->nn);
111 printf("Compare Command: %s\n",
112 cdata->oncs.compare ? "Supported" : "Not Supported");
113 printf("Write Uncorrectable Command: %s\n",
114 cdata->oncs.write_unc ? "Supported" : "Not Supported");
115 printf("Dataset Management Command: %s\n",
116 cdata->oncs.dsm ? "Supported" : "Not Supported");
117 printf("Volatile Write Cache: %s\n",
118 cdata->vwc.present ? "Present" : "Not Present");
120 if (cdata->oacs.nsmgmt) {
122 printf("Namespace Drive Attributes\n");
123 printf("==========================\n");
124 printf("NVM total cap: %s\n",
125 uint128_to_str(to128(cdata->untncap.tnvmcap), cbuf, sizeof(cbuf)));
126 printf("NVM unallocated cap: %s\n",
127 uint128_to_str(to128(cdata->untncap.unvmcap), cbuf, sizeof(cbuf)));
132 print_namespace(struct nvme_namespace_data *nsdata)
136 printf("Size (in LBAs): %lld (%lldM)\n",
137 (long long)nsdata->nsze,
138 (long long)nsdata->nsze / 1024 / 1024);
139 printf("Capacity (in LBAs): %lld (%lldM)\n",
140 (long long)nsdata->ncap,
141 (long long)nsdata->ncap / 1024 / 1024);
142 printf("Utilization (in LBAs): %lld (%lldM)\n",
143 (long long)nsdata->nuse,
144 (long long)nsdata->nuse / 1024 / 1024);
145 printf("Thin Provisioning: %s\n",
146 nsdata->nsfeat.thin_prov ? "Supported" : "Not Supported");
147 printf("Number of LBA Formats: %d\n", nsdata->nlbaf+1);
148 printf("Current LBA Format: LBA Format #%02d\n",
149 nsdata->flbas.format);
150 for (i = 0; i <= nsdata->nlbaf; i++)
151 printf("LBA Format #%02d: Data Size: %5d Metadata Size: %5d\n",
152 i, 1 << nsdata->lbaf[i].lbads, nsdata->lbaf[i].ms);
158 fprintf(stderr, "usage:\n");
159 fprintf(stderr, IDENTIFY_USAGE);
164 identify_ctrlr(int argc, char *argv[])
166 struct nvme_controller_data cdata;
167 int ch, fd, hexflag = 0, hexlength;
170 while ((ch = getopt(argc, argv, "vx")) != -1) {
183 /* Check that a controller was specified. */
187 open_dev(argv[optind], &fd, 1, 1);
188 read_controller_data(fd, &cdata);
192 if (verboseflag == 1)
193 hexlength = sizeof(struct nvme_controller_data);
195 hexlength = offsetof(struct nvme_controller_data,
197 print_hex(&cdata, hexlength);
201 if (verboseflag == 1) {
202 fprintf(stderr, "-v not currently supported without -x\n");
206 print_controller(&cdata);
211 identify_ns(int argc, char *argv[])
213 struct nvme_namespace_data nsdata;
215 int ch, fd, hexflag = 0, hexlength, nsid;
218 while ((ch = getopt(argc, argv, "vx")) != -1) {
231 /* Check that a namespace was specified. */
236 * Check if the specified device node exists before continuing.
237 * This is a cleaner check for cases where the correct controller
238 * is specified, but an invalid namespace on that controller.
240 open_dev(argv[optind], &fd, 1, 1);
244 * We send IDENTIFY commands to the controller, not the namespace,
245 * since it is an admin cmd. The namespace ID will be specified in
246 * the IDENTIFY command itself. So parse the namespace's device node
247 * string to get the controller substring and namespace ID.
249 parse_ns_str(argv[optind], path, &nsid);
250 open_dev(path, &fd, 1, 1);
251 read_namespace_data(fd, nsid, &nsdata);
255 if (verboseflag == 1)
256 hexlength = sizeof(struct nvme_namespace_data);
258 hexlength = offsetof(struct nvme_namespace_data,
260 print_hex(&nsdata, hexlength);
264 if (verboseflag == 1) {
265 fprintf(stderr, "-v not currently supported without -x\n");
269 print_namespace(&nsdata);
274 identify(int argc, char *argv[])
281 while (getopt(argc, argv, "vx") != -1) ;
283 /* Check that a controller or namespace was specified. */
287 target = argv[optind];
293 * If device node contains "ns", we consider it a namespace,
294 * otherwise, consider it a controller.
296 if (strstr(target, NVME_NS_PREFIX) == NULL)
297 identify_ctrlr(argc, argv);
299 identify_ns(argc, argv);