2 * Copyright (C) 2012-2013 Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
42 #include "nvmecontrol.h"
45 print_controller(struct nvme_controller_data *cdata)
47 printf("Controller Capabilities/Features\n");
48 printf("================================\n");
49 printf("Vendor ID: %04x\n", cdata->vid);
50 printf("Subsystem Vendor ID: %04x\n", cdata->ssvid);
51 printf("Serial Number: %s\n", cdata->sn);
52 printf("Model Number: %s\n", cdata->mn);
53 printf("Firmware Version: %s\n", cdata->fr);
54 printf("Recommended Arb Burst: %d\n", cdata->rab);
55 printf("IEEE OUI Identifier: %02x %02x %02x\n",
56 cdata->ieee[0], cdata->ieee[1], cdata->ieee[2]);
57 printf("Multi-Interface Cap: %02x\n", cdata->mic);
58 /* TODO: Use CAP.MPSMIN to determine true memory page size. */
59 printf("Max Data Transfer Size: ");
61 printf("Unlimited\n");
63 printf("%d\n", PAGE_SIZE * (1 << cdata->mdts));
66 printf("Admin Command Set Attributes\n");
67 printf("============================\n");
68 printf("Security Send/Receive: %s\n",
69 cdata->oacs.security ? "Supported" : "Not Supported");
70 printf("Format NVM: %s\n",
71 cdata->oacs.format ? "Supported" : "Not Supported");
72 printf("Firmware Activate/Download: %s\n",
73 cdata->oacs.firmware ? "Supported" : "Not Supported");
74 printf("Abort Command Limit: %d\n", cdata->acl+1);
75 printf("Async Event Request Limit: %d\n", cdata->aerl+1);
76 printf("Number of Firmware Slots: ");
77 if (cdata->oacs.firmware != 0)
78 printf("%d\n", cdata->frmw.num_slots);
81 printf("Firmware Slot 1 Read-Only: ");
82 if (cdata->oacs.firmware != 0)
83 printf("%s\n", cdata->frmw.slot1_ro ? "Yes" : "No");
86 printf("Per-Namespace SMART Log: %s\n",
87 cdata->lpa.ns_smart ? "Yes" : "No");
88 printf("Error Log Page Entries: %d\n", cdata->elpe+1);
89 printf("Number of Power States: %d\n", cdata->npss+1);
92 printf("NVM Command Set Attributes\n");
93 printf("==========================\n");
94 printf("Submission Queue Entry Size\n");
95 printf(" Max: %d\n", 1 << cdata->sqes.max);
96 printf(" Min: %d\n", 1 << cdata->sqes.min);
97 printf("Completion Queue Entry Size\n");
98 printf(" Max: %d\n", 1 << cdata->cqes.max);
99 printf(" Min: %d\n", 1 << cdata->cqes.min);
100 printf("Number of Namespaces: %d\n", cdata->nn);
101 printf("Compare Command: %s\n",
102 cdata->oncs.compare ? "Supported" : "Not Supported");
103 printf("Write Uncorrectable Command: %s\n",
104 cdata->oncs.write_unc ? "Supported" : "Not Supported");
105 printf("Dataset Management Command: %s\n",
106 cdata->oncs.dsm ? "Supported" : "Not Supported");
107 printf("Volatile Write Cache: %s\n",
108 cdata->vwc.present ? "Present" : "Not Present");
112 print_namespace(struct nvme_namespace_data *nsdata)
116 printf("Size (in LBAs): %lld (%lldM)\n",
117 (long long)nsdata->nsze,
118 (long long)nsdata->nsze / 1024 / 1024);
119 printf("Capacity (in LBAs): %lld (%lldM)\n",
120 (long long)nsdata->ncap,
121 (long long)nsdata->ncap / 1024 / 1024);
122 printf("Utilization (in LBAs): %lld (%lldM)\n",
123 (long long)nsdata->nuse,
124 (long long)nsdata->nuse / 1024 / 1024);
125 printf("Thin Provisioning: %s\n",
126 nsdata->nsfeat.thin_prov ? "Supported" : "Not Supported");
127 printf("Number of LBA Formats: %d\n", nsdata->nlbaf+1);
128 printf("Current LBA Format: LBA Format #%d\n",
129 nsdata->flbas.format);
130 for (i = 0; i <= nsdata->nlbaf; i++) {
131 printf("LBA Format #%d:\n", i);
132 printf(" LBA Data Size: %d\n",
133 1 << nsdata->lbaf[i].lbads);
140 fprintf(stderr, "usage:\n");
141 fprintf(stderr, IDENTIFY_USAGE);
146 identify_ctrlr(int argc, char *argv[])
148 struct nvme_controller_data cdata;
149 int ch, fd, hexflag = 0, hexlength;
152 while ((ch = getopt(argc, argv, "vx")) != -1) {
165 /* Check that a controller was specified. */
169 open_dev(argv[optind], &fd, 1, 1);
170 read_controller_data(fd, &cdata);
174 if (verboseflag == 1)
175 hexlength = sizeof(struct nvme_controller_data);
177 hexlength = offsetof(struct nvme_controller_data,
179 print_hex(&cdata, hexlength);
183 if (verboseflag == 1) {
184 fprintf(stderr, "-v not currently supported without -x\n");
188 print_controller(&cdata);
193 identify_ns(int argc, char *argv[])
195 struct nvme_namespace_data nsdata;
198 int ch, fd, hexflag = 0, hexlength, nsid;
201 while ((ch = getopt(argc, argv, "vx")) != -1) {
214 /* Check that a namespace was specified. */
219 * Check if the specified device node exists before continuing.
220 * This is a cleaner check for cases where the correct controller
221 * is specified, but an invalid namespace on that controller.
223 open_dev(argv[optind], &fd, 1, 1);
227 * Pull the namespace id from the string. +2 skips past the "ns" part
228 * of the string. Don't search past 10 characters into the string,
229 * otherwise we know it is malformed.
231 nsloc = strnstr(argv[optind], NVME_NS_PREFIX, 10);
233 nsid = strtol(nsloc + 2, NULL, 10);
234 if (nsloc == NULL || (nsid == 0 && errno != 0))
235 errx(1, "invalid namespace ID '%s'", argv[optind]);
238 * We send IDENTIFY commands to the controller, not the namespace,
239 * since it is an admin cmd. So the path should only include the
240 * nvmeX part of the nvmeXnsY string.
242 snprintf(path, nsloc - argv[optind] + 1, "%s", argv[optind]);
243 open_dev(path, &fd, 1, 1);
244 read_namespace_data(fd, nsid, &nsdata);
248 if (verboseflag == 1)
249 hexlength = sizeof(struct nvme_namespace_data);
251 hexlength = offsetof(struct nvme_namespace_data,
253 print_hex(&nsdata, hexlength);
257 if (verboseflag == 1) {
258 fprintf(stderr, "-v not currently supported without -x\n");
262 print_namespace(&nsdata);
267 identify(int argc, char *argv[])
274 while (getopt(argc, argv, "vx") != -1) ;
276 target = argv[optind];
282 * If device node contains "ns", we consider it a namespace,
283 * otherwise, consider it a controller.
285 if (strstr(target, NVME_NS_PREFIX) == NULL)
286 identify_ctrlr(argc, argv);
288 identify_ns(argc, argv);