17aa4eb96SMatthew Dillon /*
27aa4eb96SMatthew Dillon * Copyright (c) 2016 The DragonFly Project. All rights reserved.
37aa4eb96SMatthew Dillon *
47aa4eb96SMatthew Dillon * This code is derived from software contributed to The DragonFly Project
57aa4eb96SMatthew Dillon * by Matthew Dillon <dillon@backplane.com>
67aa4eb96SMatthew Dillon *
77aa4eb96SMatthew Dillon * Redistribution and use in source and binary forms, with or without
87aa4eb96SMatthew Dillon * modification, are permitted provided that the following conditions
97aa4eb96SMatthew Dillon * are met:
107aa4eb96SMatthew Dillon *
117aa4eb96SMatthew Dillon * 1. Redistributions of source code must retain the above copyright
127aa4eb96SMatthew Dillon * notice, this list of conditions and the following disclaimer.
137aa4eb96SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
147aa4eb96SMatthew Dillon * notice, this list of conditions and the following disclaimer in
157aa4eb96SMatthew Dillon * the documentation and/or other materials provided with the
167aa4eb96SMatthew Dillon * distribution.
177aa4eb96SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its
187aa4eb96SMatthew Dillon * contributors may be used to endorse or promote products derived
197aa4eb96SMatthew Dillon * from this software without specific, prior written permission.
207aa4eb96SMatthew Dillon *
217aa4eb96SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
227aa4eb96SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
237aa4eb96SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
247aa4eb96SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
257aa4eb96SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
267aa4eb96SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
277aa4eb96SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
287aa4eb96SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
297aa4eb96SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
307aa4eb96SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
317aa4eb96SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
327aa4eb96SMatthew Dillon * SUCH DAMAGE.
337aa4eb96SMatthew Dillon */
347aa4eb96SMatthew Dillon
357aa4eb96SMatthew Dillon #include "nvmectl.h"
367aa4eb96SMatthew Dillon
377aa4eb96SMatthew Dillon const char *
format_number(uint64_t value)387aa4eb96SMatthew Dillon format_number(uint64_t value)
397aa4eb96SMatthew Dillon {
407aa4eb96SMatthew Dillon static char buf[8];
417aa4eb96SMatthew Dillon
427aa4eb96SMatthew Dillon humanize_number(buf, sizeof(buf), value, "",
437aa4eb96SMatthew Dillon HN_AUTOSCALE, HN_DIVISOR_1000 | HN_NOSPACE);
447aa4eb96SMatthew Dillon
457aa4eb96SMatthew Dillon return buf;
467aa4eb96SMatthew Dillon }
47*1cdf60d5SMatthew Dillon
48*1cdf60d5SMatthew Dillon const char *
status_to_str(uint16_t status)49*1cdf60d5SMatthew Dillon status_to_str(uint16_t status)
50*1cdf60d5SMatthew Dillon {
51*1cdf60d5SMatthew Dillon static char buf[64];
52*1cdf60d5SMatthew Dillon int code = NVME_COMQ_STATUS_CODE_GET(status);
53*1cdf60d5SMatthew Dillon const char *msg = NULL;
54*1cdf60d5SMatthew Dillon
55*1cdf60d5SMatthew Dillon switch(NVME_COMQ_STATUS_TYPE_GET(status)) {
56*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_GENERIC:
57*1cdf60d5SMatthew Dillon switch(code) {
58*1cdf60d5SMatthew Dillon case NVME_CODE_SUCCESS:
59*1cdf60d5SMatthew Dillon msg = "SUCCESS";
60*1cdf60d5SMatthew Dillon break;
61*1cdf60d5SMatthew Dillon case NVME_CODE_BADOP:
62*1cdf60d5SMatthew Dillon msg = "Bad Op";
63*1cdf60d5SMatthew Dillon break;
64*1cdf60d5SMatthew Dillon case NVME_CODE_BADFIELD:
65*1cdf60d5SMatthew Dillon msg = "Bad Field";
66*1cdf60d5SMatthew Dillon break;
67*1cdf60d5SMatthew Dillon case NVME_CODE_IDCONFLICT:
68*1cdf60d5SMatthew Dillon msg = "ID Conflict";
69*1cdf60d5SMatthew Dillon break;
70*1cdf60d5SMatthew Dillon case NVME_CODE_BADXFER:
71*1cdf60d5SMatthew Dillon msg = "Bad XFer";
72*1cdf60d5SMatthew Dillon break;
73*1cdf60d5SMatthew Dillon case NVME_CODE_ABORTED_PWRLOSS:
74*1cdf60d5SMatthew Dillon msg = "Abort on Power Loss";
75*1cdf60d5SMatthew Dillon break;
76*1cdf60d5SMatthew Dillon case NVME_CODE_INTERNAL:
77*1cdf60d5SMatthew Dillon msg = "Internal Error";
78*1cdf60d5SMatthew Dillon break;
79*1cdf60d5SMatthew Dillon case NVME_CODE_ABORTED_ONREQ:
80*1cdf60d5SMatthew Dillon msg = "Abort on Request";
81*1cdf60d5SMatthew Dillon break;
82*1cdf60d5SMatthew Dillon case NVME_CODE_ABORTED_SQDEL:
83*1cdf60d5SMatthew Dillon msg = "Abort on SubQ Deletion";
84*1cdf60d5SMatthew Dillon break;
85*1cdf60d5SMatthew Dillon case NVME_CODE_ABORTED_FUSEFAIL:
86*1cdf60d5SMatthew Dillon msg = "Abort on Fuse Failed";
87*1cdf60d5SMatthew Dillon break;
88*1cdf60d5SMatthew Dillon case NVME_CODE_ABORTED_FUSEMISSING:
89*1cdf60d5SMatthew Dillon msg = "Abort on Fuse Missing";
90*1cdf60d5SMatthew Dillon break;
91*1cdf60d5SMatthew Dillon case NVME_CODE_BADNAMESPACE:
92*1cdf60d5SMatthew Dillon msg = "Bad Namespace";
93*1cdf60d5SMatthew Dillon break;
94*1cdf60d5SMatthew Dillon case NVME_CODE_SEQERROR:
95*1cdf60d5SMatthew Dillon msg = "Seq Error";
96*1cdf60d5SMatthew Dillon break;
97*1cdf60d5SMatthew Dillon case NVME_CODE_BADSGLSEG:
98*1cdf60d5SMatthew Dillon msg = "Bad SGL Segment";
99*1cdf60d5SMatthew Dillon break;
100*1cdf60d5SMatthew Dillon case NVME_CODE_BADSGLCNT:
101*1cdf60d5SMatthew Dillon msg = "Bad SGL Count";
102*1cdf60d5SMatthew Dillon break;
103*1cdf60d5SMatthew Dillon case NVME_CODE_BADSGLLEN:
104*1cdf60d5SMatthew Dillon msg = "Bad SGL Length";
105*1cdf60d5SMatthew Dillon break;
106*1cdf60d5SMatthew Dillon case NVME_CODE_BADSGLMLEN:
107*1cdf60d5SMatthew Dillon msg = "Bad SGL MLength";
108*1cdf60d5SMatthew Dillon break;
109*1cdf60d5SMatthew Dillon case NVME_CODE_BADSGLTYPE:
110*1cdf60d5SMatthew Dillon msg = "Bad SGL Type";
111*1cdf60d5SMatthew Dillon break;
112*1cdf60d5SMatthew Dillon case NVME_CODE_BADMEMBUFUSE:
113*1cdf60d5SMatthew Dillon msg = "Bad Memory Buffer Usage";
114*1cdf60d5SMatthew Dillon break;
115*1cdf60d5SMatthew Dillon case NVME_CODE_BADPRPOFF:
116*1cdf60d5SMatthew Dillon msg = "Bad PRP Offset";
117*1cdf60d5SMatthew Dillon break;
118*1cdf60d5SMatthew Dillon case NVME_CODE_ATOMICWUOVFL:
119*1cdf60d5SMatthew Dillon msg = "Atomic Write Overflow";
120*1cdf60d5SMatthew Dillon break;
121*1cdf60d5SMatthew Dillon case NVME_CODE_LBA_RANGE:
122*1cdf60d5SMatthew Dillon msg = "LBA Out of Range";
123*1cdf60d5SMatthew Dillon break;
124*1cdf60d5SMatthew Dillon case NVME_CODE_CAP_EXCEEDED:
125*1cdf60d5SMatthew Dillon msg = "Capacity Exceeded";
126*1cdf60d5SMatthew Dillon break;
127*1cdf60d5SMatthew Dillon case NVME_CODE_NAM_NOT_READY:
128*1cdf60d5SMatthew Dillon msg = "Namespace not Ready";
129*1cdf60d5SMatthew Dillon break;
130*1cdf60d5SMatthew Dillon case NVME_CODE_RSV_CONFLICT:
131*1cdf60d5SMatthew Dillon msg = "Reservation Conflict";
132*1cdf60d5SMatthew Dillon break;
133*1cdf60d5SMatthew Dillon case NVME_CODE_FMT_IN_PROG:
134*1cdf60d5SMatthew Dillon msg = "Format in Progress";
135*1cdf60d5SMatthew Dillon break;
136*1cdf60d5SMatthew Dillon default:
137*1cdf60d5SMatthew Dillon snprintf(buf, sizeof(buf), "generic(0x%02x)", code);
138*1cdf60d5SMatthew Dillon break;
139*1cdf60d5SMatthew Dillon }
140*1cdf60d5SMatthew Dillon break;
141*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_SPECIFIC:
142*1cdf60d5SMatthew Dillon switch(code) {
143*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADCOMQ:
144*1cdf60d5SMatthew Dillon msg = "Bad Completion Queue";
145*1cdf60d5SMatthew Dillon break;
146*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADQID:
147*1cdf60d5SMatthew Dillon msg = "Bad Queue ID";
148*1cdf60d5SMatthew Dillon break;
149*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADQSIZE:
150*1cdf60d5SMatthew Dillon msg = "Bad Queue Size";
151*1cdf60d5SMatthew Dillon break;
152*1cdf60d5SMatthew Dillon case NVME_CSSCODE_ABORTLIM:
153*1cdf60d5SMatthew Dillon msg = "Too many Aborts";
154*1cdf60d5SMatthew Dillon break;
155*1cdf60d5SMatthew Dillon case NVME_CSSCODE_RESERVED04:
156*1cdf60d5SMatthew Dillon msg = "reserved04";
157*1cdf60d5SMatthew Dillon break;
158*1cdf60d5SMatthew Dillon case NVME_CSSCODE_ASYNCEVENTLIM:
159*1cdf60d5SMatthew Dillon msg = "Too many Async Events";
160*1cdf60d5SMatthew Dillon break;
161*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADFWSLOT:
162*1cdf60d5SMatthew Dillon msg = "Bad Firmware Slot";
163*1cdf60d5SMatthew Dillon break;
164*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADFWIMAGE:
165*1cdf60d5SMatthew Dillon msg = "Bad Firmware Image";
166*1cdf60d5SMatthew Dillon break;
167*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADINTRVECT:
168*1cdf60d5SMatthew Dillon msg = "Bad Interrupt Vector";
169*1cdf60d5SMatthew Dillon break;
170*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADLOGPAGE:
171*1cdf60d5SMatthew Dillon msg = "Unsupported Log Page";
172*1cdf60d5SMatthew Dillon break;
173*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADFORMAT:
174*1cdf60d5SMatthew Dillon msg = "Bad Format Command";
175*1cdf60d5SMatthew Dillon break;
176*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FW_NEEDSCONVRESET:
177*1cdf60d5SMatthew Dillon msg = "Firmware Activation Needs Conventional Reset";
178*1cdf60d5SMatthew Dillon break;
179*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADQDELETE:
180*1cdf60d5SMatthew Dillon msg = "Bad Queue Delete";
181*1cdf60d5SMatthew Dillon break;
182*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FEAT_NOT_SAVEABLE:
183*1cdf60d5SMatthew Dillon msg = "Feature not Saveable";
184*1cdf60d5SMatthew Dillon break;
185*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FEAT_NOT_CHGABLE:
186*1cdf60d5SMatthew Dillon msg = "Feature not Changeable";
187*1cdf60d5SMatthew Dillon break;
188*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FEAT_NOT_NSSPEC:
189*1cdf60d5SMatthew Dillon msg = "Feature not Namespace-Specific";
190*1cdf60d5SMatthew Dillon break;
191*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FW_NEEDSSUBRESET:
192*1cdf60d5SMatthew Dillon msg = "Firmware Activation Needs Subsystem Reset";
193*1cdf60d5SMatthew Dillon break;
194*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FW_NEEDSRESET:
195*1cdf60d5SMatthew Dillon msg = "Firmware Activation Needs Reset";
196*1cdf60d5SMatthew Dillon break;
197*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FW_NEEDSMAXTVIOLATE:
198*1cdf60d5SMatthew Dillon msg = "Firmware Activation Requires "
199*1cdf60d5SMatthew Dillon "Maximum Time Violation";
200*1cdf60d5SMatthew Dillon break;
201*1cdf60d5SMatthew Dillon case NVME_CSSCODE_FW_PROHIBITED:
202*1cdf60d5SMatthew Dillon msg = "Firmware Activation Prohibited";
203*1cdf60d5SMatthew Dillon break;
204*1cdf60d5SMatthew Dillon case NVME_CSSCODE_RANGE_OVERLAP:
205*1cdf60d5SMatthew Dillon msg = "Overlapping Range";
206*1cdf60d5SMatthew Dillon break;
207*1cdf60d5SMatthew Dillon case NVME_CSSCODE_NAM_INSUFF_CAP:
208*1cdf60d5SMatthew Dillon msg = "Insufficient Capacity";
209*1cdf60d5SMatthew Dillon break;
210*1cdf60d5SMatthew Dillon case NVME_CSSCODE_NAM_ID_UNAVAIL:
211*1cdf60d5SMatthew Dillon msg = "NSID is not Available";
212*1cdf60d5SMatthew Dillon break;
213*1cdf60d5SMatthew Dillon case NVME_CSSCODE_RESERVED17:
214*1cdf60d5SMatthew Dillon msg = "reserved17";
215*1cdf60d5SMatthew Dillon break;
216*1cdf60d5SMatthew Dillon case NVME_CSSCODE_NAM_ALREADY_ATT:
217*1cdf60d5SMatthew Dillon msg = "NSID Already Attached";
218*1cdf60d5SMatthew Dillon break;
219*1cdf60d5SMatthew Dillon case NVME_CSSCODE_NAM_IS_PRIVATE:
220*1cdf60d5SMatthew Dillon msg = "NSID is Private";
221*1cdf60d5SMatthew Dillon break;
222*1cdf60d5SMatthew Dillon case NVME_CSSCODE_NAM_NOT_ATT:
223*1cdf60d5SMatthew Dillon msg = "NSID Not Attached";
224*1cdf60d5SMatthew Dillon break;
225*1cdf60d5SMatthew Dillon case NVME_CSSCODE_NO_THIN_PROVISION:
226*1cdf60d5SMatthew Dillon msg = "This Provisioning not Supported";
227*1cdf60d5SMatthew Dillon break;
228*1cdf60d5SMatthew Dillon case NVME_CSSCODE_CTLR_LIST_INVALID:
229*1cdf60d5SMatthew Dillon msg = "Controller List Invalid";
230*1cdf60d5SMatthew Dillon break;
231*1cdf60d5SMatthew Dillon case NVME_CSSCODE_ATTR_CONFLICT:
232*1cdf60d5SMatthew Dillon msg = "Conflicting Attributes";
233*1cdf60d5SMatthew Dillon break;
234*1cdf60d5SMatthew Dillon case NVME_CSSCODE_BADPROTINFO:
235*1cdf60d5SMatthew Dillon msg = "Invalid Prortection Information";
236*1cdf60d5SMatthew Dillon break;
237*1cdf60d5SMatthew Dillon case NVME_CSSCODE_WRITE_TO_RDONLY:
238*1cdf60d5SMatthew Dillon msg = "Attempted Write to Read Only Range";
239*1cdf60d5SMatthew Dillon break;
240*1cdf60d5SMatthew Dillon default:
241*1cdf60d5SMatthew Dillon snprintf(buf, sizeof(buf), "specific(0x%02x)", code);
242*1cdf60d5SMatthew Dillon break;
243*1cdf60d5SMatthew Dillon }
244*1cdf60d5SMatthew Dillon break;
245*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_MEDIA:
246*1cdf60d5SMatthew Dillon switch(code) {
247*1cdf60d5SMatthew Dillon case NVME_MEDCODE_WRITE_FAULT:
248*1cdf60d5SMatthew Dillon msg = "Write Fault";
249*1cdf60d5SMatthew Dillon break;
250*1cdf60d5SMatthew Dillon case NVME_MEDCODE_UNRECOV_READ_ERROR:
251*1cdf60d5SMatthew Dillon msg = "Unrecoverable Read Error";
252*1cdf60d5SMatthew Dillon break;
253*1cdf60d5SMatthew Dillon case NVME_MEDCODE_ETOE_GUARD_CHK:
254*1cdf60d5SMatthew Dillon msg = "End-to-End Guard Check Fail";
255*1cdf60d5SMatthew Dillon break;
256*1cdf60d5SMatthew Dillon case NVME_MEDCODE_ETOE_APPTAG_CHK:
257*1cdf60d5SMatthew Dillon msg = "End-to-End Application Tag Check Error";
258*1cdf60d5SMatthew Dillon break;
259*1cdf60d5SMatthew Dillon case NVME_MEDCODE_ETOE_REFTAG_CHK:
260*1cdf60d5SMatthew Dillon msg = "End-to-End Reference Tag Check Error";
261*1cdf60d5SMatthew Dillon break;
262*1cdf60d5SMatthew Dillon case NVME_MEDCODE_COMPARE_FAILURE:
263*1cdf60d5SMatthew Dillon msg = "Compare Failure";
264*1cdf60d5SMatthew Dillon break;
265*1cdf60d5SMatthew Dillon case NVME_MEDCODE_ACCESS_DENIED:
266*1cdf60d5SMatthew Dillon msg = "Access Denied";
267*1cdf60d5SMatthew Dillon break;
268*1cdf60d5SMatthew Dillon case NVME_MEDCODE_UNALLOCATED:
269*1cdf60d5SMatthew Dillon msg = "Deallocated or Unwritten Logical Block";
270*1cdf60d5SMatthew Dillon break;
271*1cdf60d5SMatthew Dillon default:
272*1cdf60d5SMatthew Dillon snprintf(buf, sizeof(buf), "media(0x%02x)", code);
273*1cdf60d5SMatthew Dillon break;
274*1cdf60d5SMatthew Dillon }
275*1cdf60d5SMatthew Dillon break;
276*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_3:
277*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_4:
278*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_5:
279*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_6:
280*1cdf60d5SMatthew Dillon buf[0] = 0;
281*1cdf60d5SMatthew Dillon break;
282*1cdf60d5SMatthew Dillon case NVME_STATUS_TYPE_VENDOR:
283*1cdf60d5SMatthew Dillon snprintf(buf, sizeof(buf), "vendor(0x%02x)", code);
284*1cdf60d5SMatthew Dillon break;
285*1cdf60d5SMatthew Dillon }
286*1cdf60d5SMatthew Dillon if (msg)
287*1cdf60d5SMatthew Dillon snprintf(buf, sizeof(buf), "%s", msg);
288*1cdf60d5SMatthew Dillon
289*1cdf60d5SMatthew Dillon return buf;
290*1cdf60d5SMatthew Dillon }
291