blob: d4c2a2e4c5d4415e86fa049e36fab7a8940ea6d0 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Douglas Gilbert655ee632013-07-02 00:17:34 -04002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * ASCII values for a number of symbolic constants, printing functions,
4 * etc.
5 * Additions for SCSI 2 and Linux 2.2.x by D. Gilbert (990422)
6 * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002)
7 * by D. Gilbert and aeb (20020609)
Douglas Gilbert655ee632013-07-02 00:17:34 -04008 * Updated to SPC-4 T10/1713-D Rev 36g, D. Gilbert 20130701
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/blkdev.h>
12#include <linux/module.h>
13#include <linux/kernel.h>
14
15#include <scsi/scsi.h>
Christoph Hellwigbeb40482006-06-10 18:01:03 +020016#include <scsi/scsi_cmnd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <scsi/scsi_device.h>
18#include <scsi/scsi_host.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <scsi/scsi_eh.h>
Adrian Bunkde540a52005-08-20 21:27:27 +020020#include <scsi/scsi_dbg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/* Commands with service actions that change the command name */
Douglas Gilbert655ee632013-07-02 00:17:34 -040023#define THIRD_PARTY_COPY_OUT 0x83
24#define THIRD_PARTY_COPY_IN 0x84
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Hannes Reinecke234d6772014-10-24 14:26:55 +020026struct sa_name_list {
27 int opcode;
28 const struct value_name_pair *arr;
29 int arr_sz;
30};
31
32struct value_name_pair {
33 int value;
34 const char * name;
35};
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static const char * cdb_byte0_names[] = {
38/* 00-03 */ "Test Unit Ready", "Rezero Unit/Rewind", NULL, "Request Sense",
39/* 04-07 */ "Format Unit/Medium", "Read Block Limits", NULL,
Justin P. Mattock70f23fd2011-05-10 10:16:21 +020040 "Reassign Blocks",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040041/* 08-0d */ "Read(6)", NULL, "Write(6)", "Seek(6)", NULL, NULL,
Douglas Gilbert655ee632013-07-02 00:17:34 -040042/* 0e-12 */ NULL, "Read Reverse", "Write Filemarks", "Space", "Inquiry",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040043/* 13-16 */ "Verify(6)", "Recover Buffered Data", "Mode Select(6)",
44 "Reserve(6)",
45/* 17-1a */ "Release(6)", "Copy", "Erase", "Mode Sense(6)",
Douglas Gilbert655ee632013-07-02 00:17:34 -040046/* 1b-1d */ "Start/Stop Unit", "Receive Diagnostic", "Send Diagnostic",
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/* 1e-1f */ "Prevent/Allow Medium Removal", NULL,
48/* 20-22 */ NULL, NULL, NULL,
49/* 23-28 */ "Read Format Capacities", "Set Window",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040050 "Read Capacity(10)", NULL, NULL, "Read(10)",
51/* 29-2d */ "Read Generation", "Write(10)", "Seek(10)", "Erase(10)",
52 "Read updated block",
53/* 2e-31 */ "Write Verify(10)", "Verify(10)", "Search High", "Search Equal",
Douglas Gilbert655ee632013-07-02 00:17:34 -040054/* 32-34 */ "Search Low", "Set Limits", "Prefetch/Read Position",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040055/* 35-37 */ "Synchronize Cache(10)", "Lock/Unlock Cache(10)",
Douglas Gilbert655ee632013-07-02 00:17:34 -040056 "Read Defect Data(10)",
57/* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer",
58 "Read Buffer",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040059/* 3d-3f */ "Update Block", "Read Long(10)", "Write Long(10)",
60/* 40-41 */ "Change Definition", "Write Same(10)",
Douglas Gilbertb4567ca2009-06-25 15:43:02 -040061/* 42-48 */ "Unmap/Read sub-channel", "Read TOC/PMA/ATIP",
62 "Read density support", "Play audio(10)", "Get configuration",
Douglas Gilbert655ee632013-07-02 00:17:34 -040063 "Play audio msf", "Sanitize/Play audio track/index",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040064/* 49-4f */ "Play track relative(10)", "Get event status notification",
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 "Pause/resume", "Log Select", "Log Sense", "Stop play/scan",
66 NULL,
67/* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040068 "Reserve track", "Send OPC info", "Mode Select(10)",
69/* 56-5b */ "Reserve(10)", "Release(10)", "Repair track", "Read master cue",
70 "Mode Sense(10)", "Close track/session",
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in",
72 "Persistent reserve out",
73/* 60-67 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
74/* 68-6f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
75/* 70-77 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
Douglas Gilbertb4567ca2009-06-25 15:43:02 -040076/* 78-7f */ NULL, NULL, NULL, NULL, NULL, NULL, "Extended CDB",
77 "Variable length",
Douglas Gilbert655ee632013-07-02 00:17:34 -040078/* 80-84 */ "Xdwrite(16)", "Rebuild(16)", "Regenerate(16)",
79 "Third party copy out", "Third party copy in",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040080/* 85-89 */ "ATA command pass through(16)", "Access control in",
Douglas Gilbert655ee632013-07-02 00:17:34 -040081 "Access control out", "Read(16)", "Compare and Write",
Douglas Gilbertb4567ca2009-06-25 15:43:02 -040082/* 8a-8f */ "Write(16)", "ORWrite", "Read attributes", "Write attributes",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040083 "Write and verify(16)", "Verify(16)",
84/* 90-94 */ "Pre-fetch(16)", "Synchronize cache(16)",
85 "Lock/unlock cache(16)", "Write same(16)", NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086/* 95-99 */ NULL, NULL, NULL, NULL, NULL,
Douglas Gilbert655ee632013-07-02 00:17:34 -040087/* 9a-9f */ NULL, NULL, NULL, "Service action bidirectional",
88 "Service action in(16)", "Service action out(16)",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040089/* a0-a5 */ "Report luns", "ATA command pass through(12)/Blank",
90 "Security protocol in", "Maintenance in", "Maintenance out",
91 "Move medium/play audio(12)",
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)",
93 "Play track relative(12)",
94/* aa-ae */ "Write(12)", NULL, "Erase(12), Get Performance",
95 "Read DVD structure", "Write and verify(12)",
96/* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)",
97/* b2-b4 */ "Search data low(12)", "Set limits(12)",
98 "Read element status attached",
Douglas Gilberta507c6a2006-07-02 13:48:10 -040099/* b5-b6 */ "Security protocol out", "Send volume tag, set streaming",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf",
101/* ba-bc */ "Redundancy group (in), Scan",
Douglas Gilberta507c6a2006-07-02 13:48:10 -0400102 "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd",
103/* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd",
104 "Volume set (out), Send DVD structure",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107static const struct value_name_pair maint_in_arr[] = {
Douglas Gilbertb4567ca2009-06-25 15:43:02 -0400108 {0x5, "Report identifying information"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 {0xa, "Report target port groups"},
110 {0xb, "Report aliases"},
111 {0xc, "Report supported operation codes"},
112 {0xd, "Report supported task management functions"},
113 {0xe, "Report priority"},
Douglas Gilberta507c6a2006-07-02 13:48:10 -0400114 {0xf, "Report timestamp"},
Douglas Gilbertb4567ca2009-06-25 15:43:02 -0400115 {0x10, "Management protocol in"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116};
Tobias Klauser6391a112006-06-08 22:23:48 -0700117#define MAINT_IN_SZ ARRAY_SIZE(maint_in_arr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119static const struct value_name_pair maint_out_arr[] = {
Douglas Gilbertb4567ca2009-06-25 15:43:02 -0400120 {0x6, "Set identifying information"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 {0xa, "Set target port groups"},
122 {0xb, "Change aliases"},
Douglas Gilbert655ee632013-07-02 00:17:34 -0400123 {0xc, "Remove I_T nexus"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 {0xe, "Set priority"},
Douglas Gilbertb4567ca2009-06-25 15:43:02 -0400125 {0xf, "Set timestamp"},
126 {0x10, "Management protocol out"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
Tobias Klauser6391a112006-06-08 22:23:48 -0700128#define MAINT_OUT_SZ ARRAY_SIZE(maint_out_arr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130static const struct value_name_pair serv_in12_arr[] = {
131 {0x1, "Read media serial number"},
132};
Tobias Klauser6391a112006-06-08 22:23:48 -0700133#define SERV_IN12_SZ ARRAY_SIZE(serv_in12_arr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135static const struct value_name_pair serv_out12_arr[] = {
136 {-1, "dummy entry"},
137};
Tobias Klauser6391a112006-06-08 22:23:48 -0700138#define SERV_OUT12_SZ ARRAY_SIZE(serv_out12_arr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Douglas Gilbert655ee632013-07-02 00:17:34 -0400140static const struct value_name_pair serv_bidi_arr[] = {
141 {-1, "dummy entry"},
142};
143#define SERV_BIDI_SZ ARRAY_SIZE(serv_bidi_arr)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static const struct value_name_pair serv_in16_arr[] = {
146 {0x10, "Read capacity(16)"},
147 {0x11, "Read long(16)"},
Martin K. Petersenf57e4502009-10-15 14:43:23 -0400148 {0x12, "Get LBA status"},
Douglas Gilbert655ee632013-07-02 00:17:34 -0400149 {0x13, "Report referrals"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
Tobias Klauser6391a112006-06-08 22:23:48 -0700151#define SERV_IN16_SZ ARRAY_SIZE(serv_in16_arr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153static const struct value_name_pair serv_out16_arr[] = {
154 {0x11, "Write long(16)"},
155 {0x1f, "Notify data transfer device(16)"},
156};
Tobias Klauser6391a112006-06-08 22:23:48 -0700157#define SERV_OUT16_SZ ARRAY_SIZE(serv_out16_arr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Douglas Gilbert655ee632013-07-02 00:17:34 -0400159static const struct value_name_pair pr_in_arr[] = {
160 {0x0, "Persistent reserve in, read keys"},
161 {0x1, "Persistent reserve in, read reservation"},
162 {0x2, "Persistent reserve in, report capabilities"},
163 {0x3, "Persistent reserve in, read full status"},
164};
165#define PR_IN_SZ ARRAY_SIZE(pr_in_arr)
166
167static const struct value_name_pair pr_out_arr[] = {
168 {0x0, "Persistent reserve out, register"},
169 {0x1, "Persistent reserve out, reserve"},
170 {0x2, "Persistent reserve out, release"},
171 {0x3, "Persistent reserve out, clear"},
172 {0x4, "Persistent reserve out, preempt"},
173 {0x5, "Persistent reserve out, preempt and abort"},
174 {0x6, "Persistent reserve out, register and ignore existing key"},
175 {0x7, "Persistent reserve out, register and move"},
176};
177#define PR_OUT_SZ ARRAY_SIZE(pr_out_arr)
178
179/* SPC-4 rev 34 renamed the Extended Copy opcode to Third Party Copy Out.
180 LID1 (List Identifier length: 1 byte) is the Extended Copy found in SPC-2
181 and SPC-3 */
182static const struct value_name_pair tpc_out_arr[] = {
183 {0x0, "Extended copy(LID1)"},
184 {0x1, "Extended copy(LID4)"},
185 {0x10, "Populate token"},
186 {0x11, "Write using token"},
187 {0x1c, "Copy operation abort"},
188};
189#define TPC_OUT_SZ ARRAY_SIZE(tpc_out_arr)
190
191static const struct value_name_pair tpc_in_arr[] = {
192 {0x0, "Receive copy status(LID1)"},
193 {0x1, "Receive copy data(LID1)"},
194 {0x3, "Receive copy operating parameters"},
195 {0x4, "Receive copy failure details(LID1)"},
196 {0x5, "Receive copy status(LID4)"},
197 {0x6, "Receive copy data(LID4)"},
198 {0x7, "Receive ROD token information"},
199 {0x8, "Report all ROD tokens"},
200};
201#define TPC_IN_SZ ARRAY_SIZE(tpc_in_arr)
202
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static const struct value_name_pair variable_length_arr[] = {
205 {0x1, "Rebuild(32)"},
206 {0x2, "Regenerate(32)"},
207 {0x3, "Xdread(32)"},
208 {0x4, "Xdwrite(32)"},
209 {0x5, "Xdwrite extended(32)"},
210 {0x6, "Xpwrite(32)"},
211 {0x7, "Xdwriteread(32)"},
212 {0x8, "Xdwrite extended(64)"},
213 {0x9, "Read(32)"},
214 {0xa, "Verify(32)"},
215 {0xb, "Write(32)"},
216 {0xc, "Write an verify(32)"},
217 {0xd, "Write same(32)"},
218 {0x8801, "Format OSD"},
219 {0x8802, "Create (osd)"},
220 {0x8803, "List (osd)"},
221 {0x8805, "Read (osd)"},
222 {0x8806, "Write (osd)"},
223 {0x8807, "Append (osd)"},
224 {0x8808, "Flush (osd)"},
225 {0x880a, "Remove (osd)"},
226 {0x880b, "Create partition (osd)"},
227 {0x880c, "Remove partition (osd)"},
228 {0x880e, "Get attributes (osd)"},
229 {0x880f, "Set attributes (osd)"},
230 {0x8812, "Create and write (osd)"},
231 {0x8815, "Create collection (osd)"},
232 {0x8816, "Remove collection (osd)"},
233 {0x8817, "List collection (osd)"},
234 {0x8818, "Set key (osd)"},
235 {0x8819, "Set master key (osd)"},
236 {0x881a, "Flush collection (osd)"},
237 {0x881b, "Flush partition (osd)"},
238 {0x881c, "Flush OSD"},
239 {0x8f7e, "Perform SCSI command (osd)"},
240 {0x8f7f, "Perform task management function (osd)"},
241};
Tobias Klauser6391a112006-06-08 22:23:48 -0700242#define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Hannes Reinecke6033f972014-10-24 14:26:54 +0200244static struct sa_name_list sa_names_arr[] = {
245 {VARIABLE_LENGTH_CMD, variable_length_arr, VARIABLE_LENGTH_SZ},
246 {MAINTENANCE_IN, maint_in_arr, MAINT_IN_SZ},
247 {MAINTENANCE_OUT, maint_out_arr, MAINT_OUT_SZ},
248 {PERSISTENT_RESERVE_IN, pr_in_arr, PR_IN_SZ},
249 {PERSISTENT_RESERVE_OUT, pr_out_arr, PR_OUT_SZ},
250 {SERVICE_ACTION_IN_12, serv_in12_arr, SERV_IN12_SZ},
251 {SERVICE_ACTION_OUT_12, serv_out12_arr, SERV_OUT12_SZ},
252 {SERVICE_ACTION_BIDIRECTIONAL, serv_bidi_arr, SERV_BIDI_SZ},
253 {SERVICE_ACTION_IN_16, serv_in16_arr, SERV_IN16_SZ},
254 {SERVICE_ACTION_OUT_16, serv_out16_arr, SERV_OUT16_SZ},
255 {THIRD_PARTY_COPY_IN, tpc_in_arr, TPC_IN_SZ},
256 {THIRD_PARTY_COPY_OUT, tpc_out_arr, TPC_OUT_SZ},
257 {0, NULL, 0},
258};
259
Hannes Reinecke9e5ed2a2015-01-08 07:43:44 +0100260bool scsi_opcode_sa_name(int opcode, int service_action,
261 const char **cdb_name, const char **sa_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Hannes Reinecke6033f972014-10-24 14:26:54 +0200263 struct sa_name_list *sa_name_ptr;
264 const struct value_name_pair *arr = NULL;
265 int arr_sz, k;
266
Hannes Reinecke2478a732014-10-24 14:26:56 +0200267 *cdb_name = NULL;
268 if (opcode >= VENDOR_SPECIFIC_CDB)
269 return false;
270
271 if (opcode < ARRAY_SIZE(cdb_byte0_names))
272 *cdb_name = cdb_byte0_names[opcode];
273
Hannes Reinecke6033f972014-10-24 14:26:54 +0200274 for (sa_name_ptr = sa_names_arr; sa_name_ptr->arr; ++sa_name_ptr) {
275 if (sa_name_ptr->opcode == opcode) {
276 arr = sa_name_ptr->arr;
277 arr_sz = sa_name_ptr->arr_sz;
278 break;
279 }
280 }
281 if (!arr)
282 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 for (k = 0; k < arr_sz; ++k, ++arr) {
285 if (service_action == arr->value)
286 break;
287 }
Hannes Reinecke6033f972014-10-24 14:26:54 +0200288 if (k < arr_sz)
289 *sa_name = arr->name;
290
291 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294struct error_info {
295 unsigned short code12; /* 0x0302 looks better than 0x03,0x02 */
Rasmus Villemoese1f0bce2016-03-22 20:32:05 +0100296 unsigned short size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297};
298
Rasmus Villemoese1f0bce2016-03-22 20:32:05 +0100299/*
300 * There are 700+ entries in this table. To save space, we don't store
301 * (code, pointer) pairs, which would make sizeof(struct
302 * error_info)==16 on 64 bits. Rather, the second element just stores
303 * the size (including \0) of the corresponding string, and we use the
304 * sum of these to get the appropriate offset into additional_text
305 * defined below. This approach saves 12 bytes per entry.
306 */
Martin K. Petersen62d42a62007-02-28 12:37:06 -0500307static const struct error_info additional[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
Rasmus Villemoese1f0bce2016-03-22 20:32:05 +0100309#define SENSE_CODE(c, s) {c, sizeof(s)},
Rasmus Villemoes9d99a2e2016-03-22 20:32:04 +0100310#include "sense_codes.h"
311#undef SENSE_CODE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312};
313
Rasmus Villemoese1f0bce2016-03-22 20:32:05 +0100314static const char *additional_text =
315#define SENSE_CODE(c, s) s "\0"
316#include "sense_codes.h"
317#undef SENSE_CODE
318 ;
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320struct error_info2 {
321 unsigned char code1, code2_min, code2_max;
Hannes Reinecked811b842014-10-24 14:26:45 +0200322 const char * str;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 const char * fmt;
324};
325
Arjan van de Ven0ad78202005-11-28 16:22:25 +0100326static const struct error_info2 additional2[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Hannes Reinecked811b842014-10-24 14:26:45 +0200328 {0x40, 0x00, 0x7f, "Ram failure", ""},
329 {0x40, 0x80, 0xff, "Diagnostic failure on component", ""},
330 {0x41, 0x00, 0xff, "Data path failure", ""},
331 {0x42, 0x00, 0xff, "Power-on or self-test failure", ""},
332 {0x4D, 0x00, 0xff, "Tagged overlapped commands", "task tag "},
333 {0x70, 0x00, 0xff, "Decompression exception", "short algorithm id of "},
334 {0, 0, 0, NULL, NULL}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335};
336
337/* description of the sense key values */
Arjan van de Ven0ad78202005-11-28 16:22:25 +0100338static const char * const snstext[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 "No Sense", /* 0: There is no sense information */
340 "Recovered Error", /* 1: The last command completed successfully
341 but used error correction */
342 "Not Ready", /* 2: The addressed target is not ready */
343 "Medium Error", /* 3: Data error detected on the medium */
344 "Hardware Error", /* 4: Controller or device failure */
345 "Illegal Request", /* 5: Error in request */
346 "Unit Attention", /* 6: Removable medium was changed, or
347 the target has been reset, or ... */
348 "Data Protect", /* 7: Access to the data is blocked */
349 "Blank Check", /* 8: Reached unexpected written or unwritten
350 region of the medium */
351 "Vendor Specific(9)",
352 "Copy Aborted", /* A: COPY or COMPARE was aborted */
353 "Aborted Command", /* B: The target aborted the command */
Douglas Gilbert655ee632013-07-02 00:17:34 -0400354 "Equal", /* C: A SEARCH DATA command found data equal,
355 reserved in SPC-4 rev 36 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 "Volume Overflow", /* D: Medium full with still data to be written */
357 "Miscompare", /* E: Source data and data on the medium
358 do not agree */
Douglas Gilbert655ee632013-07-02 00:17:34 -0400359 "Completed", /* F: command completed sense data reported,
360 may occur for successful command */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363/* Get sense key string or NULL if not available */
364const char *
Tyrel Datwylera87eeb92016-08-12 17:20:07 -0500365scsi_sense_key_string(unsigned char key)
366{
367 if (key < ARRAY_SIZE(snstext))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 return snstext[key];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return NULL;
370}
371EXPORT_SYMBOL(scsi_sense_key_string);
372
373/*
374 * Get additional sense code string or NULL if not available.
375 * This string may contain a "%x" and should be printed with ascq as arg.
376 */
377const char *
Hannes Reinecked811b842014-10-24 14:26:45 +0200378scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
379{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 int i;
381 unsigned short code = ((asc << 8) | ascq);
Rasmus Villemoese1f0bce2016-03-22 20:32:05 +0100382 unsigned offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Dan Carpenter249b15b2014-12-02 14:07:30 +0300384 *fmt = NULL;
Rasmus Villemoese1f0bce2016-03-22 20:32:05 +0100385 for (i = 0; i < ARRAY_SIZE(additional); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 if (additional[i].code12 == code)
Rasmus Villemoese1f0bce2016-03-22 20:32:05 +0100387 return additional_text + offset;
388 offset += additional[i].size;
389 }
Douglas Gilbertb4567ca2009-06-25 15:43:02 -0400390 for (i = 0; additional2[i].fmt; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (additional2[i].code1 == asc &&
Douglas Gilbertb4567ca2009-06-25 15:43:02 -0400392 ascq >= additional2[i].code2_min &&
Hannes Reinecked811b842014-10-24 14:26:45 +0200393 ascq <= additional2[i].code2_max) {
394 *fmt = additional2[i].fmt;
395 return additional2[i].str;
396 }
Douglas Gilbertb4567ca2009-06-25 15:43:02 -0400397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return NULL;
399}
400EXPORT_SYMBOL(scsi_extd_sense_format);
401
Arjan van de Ven0ad78202005-11-28 16:22:25 +0100402static const char * const hostbyte_table[]={
Tobias Klauser6391a112006-06-08 22:23:48 -0700403"DID_OK", "DID_NO_CONNECT", "DID_BUS_BUSY", "DID_TIME_OUT", "DID_BAD_TARGET",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404"DID_ABORT", "DID_PARITY", "DID_ERROR", "DID_RESET", "DID_BAD_INTR",
Mike Christiea4dfaa62008-08-19 18:45:25 -0500405"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE",
Moger, Babuf1ba8a42012-07-27 17:28:40 +0000406"DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE",
407"DID_NEXUS_FAILURE" };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Arjan van de Ven0ad78202005-11-28 16:22:25 +0100409static const char * const driverbyte_table[]={
Tobias Klauser6391a112006-06-08 22:23:48 -0700410"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
Martin K. Petersen684b7fe2007-02-27 22:39:44 -0500412
Hannes Reinecke3cc958c2014-10-24 14:26:59 +0200413const char *scsi_hostbyte_string(int result)
414{
415 const char *hb_string = NULL;
Hannes Reinecke3cc958c2014-10-24 14:26:59 +0200416 int hb = host_byte(result);
417
418 if (hb < ARRAY_SIZE(hostbyte_table))
419 hb_string = hostbyte_table[hb];
Hannes Reinecke3cc958c2014-10-24 14:26:59 +0200420 return hb_string;
421}
422EXPORT_SYMBOL(scsi_hostbyte_string);
423
424const char *scsi_driverbyte_string(int result)
425{
426 const char *db_string = NULL;
Hannes Reinecke3cc958c2014-10-24 14:26:59 +0200427 int db = driver_byte(result);
428
429 if (db < ARRAY_SIZE(driverbyte_table))
430 db_string = driverbyte_table[db];
Hannes Reinecke3cc958c2014-10-24 14:26:59 +0200431 return db_string;
432}
433EXPORT_SYMBOL(scsi_driverbyte_string);
434
Hannes Reineckec11c0042014-10-24 14:27:01 +0200435#define scsi_mlreturn_name(result) { result, #result }
436static const struct value_name_pair scsi_mlreturn_arr[] = {
437 scsi_mlreturn_name(NEEDS_RETRY),
438 scsi_mlreturn_name(SUCCESS),
439 scsi_mlreturn_name(FAILED),
440 scsi_mlreturn_name(QUEUED),
441 scsi_mlreturn_name(SOFT_ERROR),
442 scsi_mlreturn_name(ADD_TO_MLQUEUE),
443 scsi_mlreturn_name(TIMEOUT_ERROR),
444 scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED),
445 scsi_mlreturn_name(FAST_IO_FAIL)
446};
Hannes Reineckec11c0042014-10-24 14:27:01 +0200447
448const char *scsi_mlreturn_string(int result)
Martin K. Petersen684b7fe2007-02-27 22:39:44 -0500449{
Hannes Reineckec11c0042014-10-24 14:27:01 +0200450 const struct value_name_pair *arr = scsi_mlreturn_arr;
451 int k;
452
453 for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) {
454 if (result == arr->value)
455 return arr->name;
456 }
Hannes Reineckec11c0042014-10-24 14:27:01 +0200457 return NULL;
458}
459EXPORT_SYMBOL(scsi_mlreturn_string);