Blame view

drivers/scsi/constants.c 15.4 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
2
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
6
7
   * ASCII values for a number of symbolic constants, printing functions,
   * etc.
   * Additions for SCSI 2 and Linux 2.2.x by D. Gilbert (990422)
   * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002)
   *   by D. Gilbert and aeb (20020609)
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
8
   * Updated to SPC-4 T10/1713-D Rev 36g, D. Gilbert 20130701
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
12
13
14
  #include <linux/blkdev.h>
  #include <linux/module.h>
  #include <linux/kernel.h>
  
  #include <scsi/scsi.h>
beb404875   Christoph Hellwig   [SCSI] remove scs...
15
  #include <scsi/scsi_cmnd.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
  #include <scsi/scsi_device.h>
  #include <scsi/scsi_host.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  #include <scsi/scsi_eh.h>
de540a53f   Adrian Bunk   [SCSI] drivers/sc...
19
  #include <scsi/scsi_dbg.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  /* Commands with service actions that change the command name */
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
22
23
  #define THIRD_PARTY_COPY_OUT 0x83
  #define THIRD_PARTY_COPY_IN 0x84
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24

234d67781   Hannes Reinecke   scsi: merge print...
25
26
27
28
29
30
31
32
33
34
  struct sa_name_list {
  	int opcode;
  	const struct value_name_pair *arr;
  	int arr_sz;
  };
  
  struct value_name_pair {
  	int value;
  	const char * name;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
37
38
  static const char * cdb_byte0_names[] = {
  /* 00-03 */ "Test Unit Ready", "Rezero Unit/Rewind", NULL, "Request Sense",
  /* 04-07 */ "Format Unit/Medium", "Read Block Limits", NULL,
70f23fd66   Justin P. Mattock   treewide: fix a f...
39
  	    "Reassign Blocks",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
40
  /* 08-0d */ "Read(6)", NULL, "Write(6)", "Seek(6)", NULL, NULL,
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
41
  /* 0e-12 */ NULL, "Read Reverse", "Write Filemarks", "Space", "Inquiry",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
42
43
44
  /* 13-16 */ "Verify(6)", "Recover Buffered Data", "Mode Select(6)",
  	    "Reserve(6)",
  /* 17-1a */ "Release(6)", "Copy", "Erase", "Mode Sense(6)",
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
45
  /* 1b-1d */ "Start/Stop Unit", "Receive Diagnostic", "Send Diagnostic",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
  /* 1e-1f */ "Prevent/Allow Medium Removal", NULL,
  /* 20-22 */  NULL, NULL, NULL,
  /* 23-28 */ "Read Format Capacities", "Set Window",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
49
50
51
52
  	    "Read Capacity(10)", NULL, NULL, "Read(10)",
  /* 29-2d */ "Read Generation", "Write(10)", "Seek(10)", "Erase(10)",
              "Read updated block",
  /* 2e-31 */ "Write Verify(10)", "Verify(10)", "Search High", "Search Equal",
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
53
  /* 32-34 */ "Search Low", "Set Limits", "Prefetch/Read Position",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
54
  /* 35-37 */ "Synchronize Cache(10)", "Lock/Unlock Cache(10)",
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
55
56
57
  	    "Read Defect Data(10)",
  /* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer",
  	    "Read Buffer",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
58
59
  /* 3d-3f */ "Update Block", "Read Long(10)",  "Write Long(10)",
  /* 40-41 */ "Change Definition", "Write Same(10)",
b4567ca63   Douglas Gilbert   [SCSI] update scs...
60
61
  /* 42-48 */ "Unmap/Read sub-channel", "Read TOC/PMA/ATIP",
  	    "Read density support", "Play audio(10)", "Get configuration",
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
62
  	    "Play audio msf", "Sanitize/Play audio track/index",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
63
  /* 49-4f */ "Play track relative(10)", "Get event status notification",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
66
              "Pause/resume", "Log Select", "Log Sense", "Stop play/scan",
              NULL,
  /* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
67
68
69
              "Reserve track", "Send OPC info", "Mode Select(10)",
  /* 56-5b */ "Reserve(10)", "Release(10)", "Repair track", "Read master cue",
              "Mode Sense(10)", "Close track/session",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
72
73
74
  /* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in",
              "Persistent reserve out",
  /* 60-67 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  /* 68-6f */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  /* 70-77 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
b4567ca63   Douglas Gilbert   [SCSI] update scs...
75
76
  /* 78-7f */ NULL, NULL, NULL, NULL, NULL, NULL, "Extended CDB",
  	    "Variable length",
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
77
78
  /* 80-84 */ "Xdwrite(16)", "Rebuild(16)", "Regenerate(16)",
  	    "Third party copy out", "Third party copy in",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
79
  /* 85-89 */ "ATA command pass through(16)", "Access control in",
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
80
  	    "Access control out", "Read(16)", "Compare and Write",
b4567ca63   Douglas Gilbert   [SCSI] update scs...
81
  /* 8a-8f */ "Write(16)", "ORWrite", "Read attributes", "Write attributes",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
82
83
84
              "Write and verify(16)", "Verify(16)",
  /* 90-94 */ "Pre-fetch(16)", "Synchronize cache(16)",
              "Lock/unlock cache(16)", "Write same(16)", NULL,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  /* 95-99 */ NULL, NULL, NULL, NULL, NULL,
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
86
87
  /* 9a-9f */ NULL, NULL, NULL, "Service action bidirectional",
  	    "Service action in(16)", "Service action out(16)",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
88
89
90
  /* a0-a5 */ "Report luns", "ATA command pass through(12)/Blank",
              "Security protocol in", "Maintenance in", "Maintenance out",
  	    "Move medium/play audio(12)",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
92
93
94
95
96
97
  /* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)",
              "Play track relative(12)",
  /* aa-ae */ "Write(12)", NULL, "Erase(12), Get Performance",
              "Read DVD structure", "Write and verify(12)",
  /* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)",
  /* b2-b4 */ "Search data low(12)", "Set limits(12)",
              "Read element status attached",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
98
  /* b5-b6 */ "Security protocol out", "Send volume tag, set streaming",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
100
  /* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf",
  /* ba-bc */ "Redundancy group (in), Scan",
a507c6a2d   Douglas Gilbert   [SCSI] update add...
101
102
103
              "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd",
  /* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd",
              "Volume set (out), Send DVD structure",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
  static const struct value_name_pair maint_in_arr[] = {
b4567ca63   Douglas Gilbert   [SCSI] update scs...
106
  	{0x5, "Report identifying information"},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
109
110
111
  	{0xa, "Report target port groups"},
  	{0xb, "Report aliases"},
  	{0xc, "Report supported operation codes"},
  	{0xd, "Report supported task management functions"},
  	{0xe, "Report priority"},
a507c6a2d   Douglas Gilbert   [SCSI] update add...
112
  	{0xf, "Report timestamp"},
b4567ca63   Douglas Gilbert   [SCSI] update scs...
113
  	{0x10, "Management protocol in"},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
  };
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
115
  #define MAINT_IN_SZ ARRAY_SIZE(maint_in_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116
117
  
  static const struct value_name_pair maint_out_arr[] = {
b4567ca63   Douglas Gilbert   [SCSI] update scs...
118
  	{0x6, "Set identifying information"},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
  	{0xa, "Set target port groups"},
  	{0xb, "Change aliases"},
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
121
  	{0xc, "Remove I_T nexus"},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
  	{0xe, "Set priority"},
b4567ca63   Douglas Gilbert   [SCSI] update scs...
123
124
  	{0xf, "Set timestamp"},
  	{0x10, "Management protocol out"},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
  };
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
126
  #define MAINT_OUT_SZ ARRAY_SIZE(maint_out_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
128
129
130
  
  static const struct value_name_pair serv_in12_arr[] = {
  	{0x1, "Read media serial number"},
  };
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
131
  #define SERV_IN12_SZ ARRAY_SIZE(serv_in12_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
133
134
135
  
  static const struct value_name_pair serv_out12_arr[] = {
  	{-1, "dummy entry"},
  };
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
136
  #define SERV_OUT12_SZ ARRAY_SIZE(serv_out12_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137

655ee63cf   Douglas Gilbert   [SCSI] scsi const...
138
139
140
141
  static const struct value_name_pair serv_bidi_arr[] = {
  	{-1, "dummy entry"},
  };
  #define SERV_BIDI_SZ ARRAY_SIZE(serv_bidi_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
143
144
  static const struct value_name_pair serv_in16_arr[] = {
  	{0x10, "Read capacity(16)"},
  	{0x11, "Read long(16)"},
f57e4502c   Martin K. Petersen   [SCSI] scsi: Add ...
145
  	{0x12, "Get LBA status"},
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
146
  	{0x13, "Report referrals"},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
147
  };
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
148
  #define SERV_IN16_SZ ARRAY_SIZE(serv_in16_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
149
150
151
152
153
  
  static const struct value_name_pair serv_out16_arr[] = {
  	{0x11, "Write long(16)"},
  	{0x1f, "Notify data transfer device(16)"},
  };
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
154
  #define SERV_OUT16_SZ ARRAY_SIZE(serv_out16_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155

655ee63cf   Douglas Gilbert   [SCSI] scsi const...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  static const struct value_name_pair pr_in_arr[] = {
  	{0x0, "Persistent reserve in, read keys"},
  	{0x1, "Persistent reserve in, read reservation"},
  	{0x2, "Persistent reserve in, report capabilities"},
  	{0x3, "Persistent reserve in, read full status"},
  };
  #define PR_IN_SZ ARRAY_SIZE(pr_in_arr)
  
  static const struct value_name_pair pr_out_arr[] = {
  	{0x0, "Persistent reserve out, register"},
  	{0x1, "Persistent reserve out, reserve"},
  	{0x2, "Persistent reserve out, release"},
  	{0x3, "Persistent reserve out, clear"},
  	{0x4, "Persistent reserve out, preempt"},
  	{0x5, "Persistent reserve out, preempt and abort"},
  	{0x6, "Persistent reserve out, register and ignore existing key"},
  	{0x7, "Persistent reserve out, register and move"},
  };
  #define PR_OUT_SZ ARRAY_SIZE(pr_out_arr)
  
  /* SPC-4 rev 34 renamed the Extended Copy opcode to Third Party Copy Out.
     LID1 (List Identifier length: 1 byte) is the Extended Copy found in SPC-2
     and SPC-3 */
  static const struct value_name_pair tpc_out_arr[] = {
  	{0x0, "Extended copy(LID1)"},
  	{0x1, "Extended copy(LID4)"},
  	{0x10, "Populate token"},
  	{0x11, "Write using token"},
  	{0x1c, "Copy operation abort"},
  };
  #define TPC_OUT_SZ ARRAY_SIZE(tpc_out_arr)
  
  static const struct value_name_pair tpc_in_arr[] = {
  	{0x0, "Receive copy status(LID1)"},
  	{0x1, "Receive copy data(LID1)"},
  	{0x3, "Receive copy operating parameters"},
  	{0x4, "Receive copy failure details(LID1)"},
  	{0x5, "Receive copy status(LID4)"},
  	{0x6, "Receive copy data(LID4)"},
  	{0x7, "Receive ROD token information"},
  	{0x8, "Report all ROD tokens"},
  };
  #define TPC_IN_SZ ARRAY_SIZE(tpc_in_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  static const struct value_name_pair variable_length_arr[] = {
  	{0x1, "Rebuild(32)"},
  	{0x2, "Regenerate(32)"},
  	{0x3, "Xdread(32)"},
  	{0x4, "Xdwrite(32)"},
  	{0x5, "Xdwrite extended(32)"},
  	{0x6, "Xpwrite(32)"},
  	{0x7, "Xdwriteread(32)"},
  	{0x8, "Xdwrite extended(64)"},
  	{0x9, "Read(32)"},
  	{0xa, "Verify(32)"},
  	{0xb, "Write(32)"},
  	{0xc, "Write an verify(32)"},
  	{0xd, "Write same(32)"},
  	{0x8801, "Format OSD"},
  	{0x8802, "Create (osd)"},
  	{0x8803, "List (osd)"},
  	{0x8805, "Read (osd)"},
  	{0x8806, "Write (osd)"},
  	{0x8807, "Append (osd)"},
  	{0x8808, "Flush (osd)"},
  	{0x880a, "Remove (osd)"},
  	{0x880b, "Create partition (osd)"},
  	{0x880c, "Remove partition (osd)"},
  	{0x880e, "Get attributes (osd)"},
  	{0x880f, "Set attributes (osd)"},
  	{0x8812, "Create and write (osd)"},
  	{0x8815, "Create collection (osd)"},
  	{0x8816, "Remove collection (osd)"},
  	{0x8817, "List collection (osd)"},
  	{0x8818, "Set key (osd)"},
  	{0x8819, "Set master key (osd)"},
  	{0x881a, "Flush collection (osd)"},
  	{0x881b, "Flush partition (osd)"},
  	{0x881c, "Flush OSD"},
  	{0x8f7e, "Perform SCSI command (osd)"},
  	{0x8f7f, "Perform task management function (osd)"},
  };
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
237
  #define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238

6033f9791   Hannes Reinecke   scsi: implement s...
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  static struct sa_name_list sa_names_arr[] = {
  	{VARIABLE_LENGTH_CMD, variable_length_arr, VARIABLE_LENGTH_SZ},
  	{MAINTENANCE_IN, maint_in_arr, MAINT_IN_SZ},
  	{MAINTENANCE_OUT, maint_out_arr, MAINT_OUT_SZ},
  	{PERSISTENT_RESERVE_IN, pr_in_arr, PR_IN_SZ},
  	{PERSISTENT_RESERVE_OUT, pr_out_arr, PR_OUT_SZ},
  	{SERVICE_ACTION_IN_12, serv_in12_arr, SERV_IN12_SZ},
  	{SERVICE_ACTION_OUT_12, serv_out12_arr, SERV_OUT12_SZ},
  	{SERVICE_ACTION_BIDIRECTIONAL, serv_bidi_arr, SERV_BIDI_SZ},
  	{SERVICE_ACTION_IN_16, serv_in16_arr, SERV_IN16_SZ},
  	{SERVICE_ACTION_OUT_16, serv_out16_arr, SERV_OUT16_SZ},
  	{THIRD_PARTY_COPY_IN, tpc_in_arr, TPC_IN_SZ},
  	{THIRD_PARTY_COPY_OUT, tpc_out_arr, TPC_OUT_SZ},
  	{0, NULL, 0},
  };
9e5ed2a5b   Hannes Reinecke   scsi: use externa...
254
255
  bool scsi_opcode_sa_name(int opcode, int service_action,
  			 const char **cdb_name, const char **sa_name)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
  {
6033f9791   Hannes Reinecke   scsi: implement s...
257
258
259
  	struct sa_name_list *sa_name_ptr;
  	const struct value_name_pair *arr = NULL;
  	int arr_sz, k;
2478a736a   Hannes Reinecke   scsi: consolidate...
260
261
262
263
264
265
  	*cdb_name = NULL;
  	if (opcode >= VENDOR_SPECIFIC_CDB)
  		return false;
  
  	if (opcode < ARRAY_SIZE(cdb_byte0_names))
  		*cdb_name = cdb_byte0_names[opcode];
6033f9791   Hannes Reinecke   scsi: implement s...
266
267
268
269
270
271
272
273
274
  	for (sa_name_ptr = sa_names_arr; sa_name_ptr->arr; ++sa_name_ptr) {
  		if (sa_name_ptr->opcode == opcode) {
  			arr = sa_name_ptr->arr;
  			arr_sz = sa_name_ptr->arr_sz;
  			break;
  		}
  	}
  	if (!arr)
  		return false;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
275
276
277
278
279
  
  	for (k = 0; k < arr_sz; ++k, ++arr) {
  		if (service_action == arr->value)
  			break;
  	}
6033f9791   Hannes Reinecke   scsi: implement s...
280
281
282
283
  	if (k < arr_sz)
  		*sa_name = arr->name;
  
  	return true;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
285
286
  struct error_info {
  	unsigned short code12;	/* 0x0302 looks better than 0x03,0x02 */
e1f0bce3a   Rasmus Villemoes   scsi: reduce CONF...
287
  	unsigned short size;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
  };
e1f0bce3a   Rasmus Villemoes   scsi: reduce CONF...
289
290
291
292
293
294
295
296
  /*
   * There are 700+ entries in this table. To save space, we don't store
   * (code, pointer) pairs, which would make sizeof(struct
   * error_info)==16 on 64 bits. Rather, the second element just stores
   * the size (including \0) of the corresponding string, and we use the
   * sum of these to get the appropriate offset into additional_text
   * defined below. This approach saves 12 bytes per entry.
   */
62d42a627   Martin K. Petersen   [SCSI] constants....
297
  static const struct error_info additional[] =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
  {
e1f0bce3a   Rasmus Villemoes   scsi: reduce CONF...
299
  #define SENSE_CODE(c, s) {c, sizeof(s)},
9d99a2e33   Rasmus Villemoes   scsi: move Additi...
300
301
  #include "sense_codes.h"
  #undef SENSE_CODE
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
  };
e1f0bce3a   Rasmus Villemoes   scsi: reduce CONF...
303
304
305
306
307
  static const char *additional_text =
  #define SENSE_CODE(c, s) s "\0"
  #include "sense_codes.h"
  #undef SENSE_CODE
  	;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
308
309
  struct error_info2 {
  	unsigned char code1, code2_min, code2_max;
d811b848e   Hannes Reinecke   scsi: use sdev as...
310
  	const char * str;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
312
  	const char * fmt;
  };
0ad78200b   Arjan van de Ven   [SCSI] Mark some ...
313
  static const struct error_info2 additional2[] =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
314
  {
d811b848e   Hannes Reinecke   scsi: use sdev as...
315
316
317
318
319
320
321
  	{0x40, 0x00, 0x7f, "Ram failure", ""},
  	{0x40, 0x80, 0xff, "Diagnostic failure on component", ""},
  	{0x41, 0x00, 0xff, "Data path failure", ""},
  	{0x42, 0x00, 0xff, "Power-on or self-test failure", ""},
  	{0x4D, 0x00, 0xff, "Tagged overlapped commands", "task tag "},
  	{0x70, 0x00, 0xff, "Decompression exception", "short algorithm id of "},
  	{0, 0, 0, NULL, NULL}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
323
324
  };
  
  /* description of the sense key values */
0ad78200b   Arjan van de Ven   [SCSI] Mark some ...
325
  static const char * const snstext[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
  	"No Sense",	    /* 0: There is no sense information */
  	"Recovered Error",  /* 1: The last command completed successfully
  				  but used error correction */
  	"Not Ready",	    /* 2: The addressed target is not ready */
  	"Medium Error",	    /* 3: Data error detected on the medium */
  	"Hardware Error",   /* 4: Controller or device failure */
  	"Illegal Request",  /* 5: Error in request */
  	"Unit Attention",   /* 6: Removable medium was changed, or
  				  the target has been reset, or ... */
  	"Data Protect",	    /* 7: Access to the data is blocked */
  	"Blank Check",	    /* 8: Reached unexpected written or unwritten
  				  region of the medium */
  	"Vendor Specific(9)",
  	"Copy Aborted",	    /* A: COPY or COMPARE was aborted */
  	"Aborted Command",  /* B: The target aborted the command */
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
341
342
  	"Equal",	    /* C: A SEARCH DATA command found data equal,
  				  reserved in SPC-4 rev 36 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
344
345
  	"Volume Overflow",  /* D: Medium full with still data to be written */
  	"Miscompare",	    /* E: Source data and data on the medium
  				  do not agree */
655ee63cf   Douglas Gilbert   [SCSI] scsi const...
346
347
  	"Completed",	    /* F: command completed sense data reported,
  				  may occur for successful command */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
348
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
349
350
351
  
  /* Get sense key string or NULL if not available */
  const char *
a87eeb900   Tyrel Datwyler   scsi: fix upper b...
352
353
354
  scsi_sense_key_string(unsigned char key)
  {
  	if (key < ARRAY_SIZE(snstext))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
  		return snstext[key];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
356
357
358
359
360
361
362
363
364
  	return NULL;
  }
  EXPORT_SYMBOL(scsi_sense_key_string);
  
  /*
   * Get additional sense code string or NULL if not available.
   * This string may contain a "%x" and should be printed with ascq as arg.
   */
  const char *
d811b848e   Hannes Reinecke   scsi: use sdev as...
365
366
  scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
367
368
  	int i;
  	unsigned short code = ((asc << 8) | ascq);
e1f0bce3a   Rasmus Villemoes   scsi: reduce CONF...
369
  	unsigned offset = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
370

249b15ba6   Dan Carpenter   scsi: set fmt to ...
371
  	*fmt = NULL;
e1f0bce3a   Rasmus Villemoes   scsi: reduce CONF...
372
  	for (i = 0; i < ARRAY_SIZE(additional); i++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
  		if (additional[i].code12 == code)
e1f0bce3a   Rasmus Villemoes   scsi: reduce CONF...
374
375
376
  			return additional_text + offset;
  		offset += additional[i].size;
  	}
b4567ca63   Douglas Gilbert   [SCSI] update scs...
377
  	for (i = 0; additional2[i].fmt; i++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
378
  		if (additional2[i].code1 == asc &&
b4567ca63   Douglas Gilbert   [SCSI] update scs...
379
  		    ascq >= additional2[i].code2_min &&
d811b848e   Hannes Reinecke   scsi: use sdev as...
380
381
382
383
  		    ascq <= additional2[i].code2_max) {
  			*fmt = additional2[i].fmt;
  			return additional2[i].str;
  		}
b4567ca63   Douglas Gilbert   [SCSI] update scs...
384
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
385
386
387
  	return NULL;
  }
  EXPORT_SYMBOL(scsi_extd_sense_format);
0ad78200b   Arjan van de Ven   [SCSI] Mark some ...
388
  static const char * const hostbyte_table[]={
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
389
  "DID_OK", "DID_NO_CONNECT", "DID_BUS_BUSY", "DID_TIME_OUT", "DID_BAD_TARGET",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
  "DID_ABORT", "DID_PARITY", "DID_ERROR", "DID_RESET", "DID_BAD_INTR",
a4dfaa6f2   Mike Christie   [SCSI] scsi: add ...
391
  "DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE",
f1ba8a4fe   Moger, Babu   [SCSI] add DID_TA...
392
  "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE",
1b55940b9   Nikhil Kshirsagar   scsi: core: Add D...
393
  "DID_NEXUS_FAILURE", "DID_ALLOC_FAILURE", "DID_MEDIUM_ERROR" };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
394

0ad78200b   Arjan van de Ven   [SCSI] Mark some ...
395
  static const char * const driverbyte_table[]={
6391a1137   Tobias Klauser   [SCSI] drivers/sc...
396
  "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
  "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398

3cc958cc1   Hannes Reinecke   scsi: separate ou...
399
  const char *scsi_hostbyte_string(int result)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
  {
3cc958cc1   Hannes Reinecke   scsi: separate ou...
401
  	const char *hb_string = NULL;
684b7fe97   Martin K. Petersen   [SCSI] constants....
402
  	int hb = host_byte(result);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403

3cc958cc1   Hannes Reinecke   scsi: separate ou...
404
405
  	if (hb < ARRAY_SIZE(hostbyte_table))
  		hb_string = hostbyte_table[hb];
3cc958cc1   Hannes Reinecke   scsi: separate ou...
406
  	return hb_string;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
407
  }
3cc958cc1   Hannes Reinecke   scsi: separate ou...
408
  EXPORT_SYMBOL(scsi_hostbyte_string);
684b7fe97   Martin K. Petersen   [SCSI] constants....
409

3cc958cc1   Hannes Reinecke   scsi: separate ou...
410
411
412
  const char *scsi_driverbyte_string(int result)
  {
  	const char *db_string = NULL;
3cc958cc1   Hannes Reinecke   scsi: separate ou...
413
414
415
416
  	int db = driver_byte(result);
  
  	if (db < ARRAY_SIZE(driverbyte_table))
  		db_string = driverbyte_table[db];
3cc958cc1   Hannes Reinecke   scsi: separate ou...
417
418
419
  	return db_string;
  }
  EXPORT_SYMBOL(scsi_driverbyte_string);
684b7fe97   Martin K. Petersen   [SCSI] constants....
420

c11c004b1   Hannes Reinecke   scsi: simplify sc...
421
422
423
424
425
426
427
428
429
430
431
432
  #define scsi_mlreturn_name(result)	{ result, #result }
  static const struct value_name_pair scsi_mlreturn_arr[] = {
  	scsi_mlreturn_name(NEEDS_RETRY),
  	scsi_mlreturn_name(SUCCESS),
  	scsi_mlreturn_name(FAILED),
  	scsi_mlreturn_name(QUEUED),
  	scsi_mlreturn_name(SOFT_ERROR),
  	scsi_mlreturn_name(ADD_TO_MLQUEUE),
  	scsi_mlreturn_name(TIMEOUT_ERROR),
  	scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED),
  	scsi_mlreturn_name(FAST_IO_FAIL)
  };
c11c004b1   Hannes Reinecke   scsi: simplify sc...
433
434
435
  
  const char *scsi_mlreturn_string(int result)
  {
c11c004b1   Hannes Reinecke   scsi: simplify sc...
436
437
438
439
440
441
442
  	const struct value_name_pair *arr = scsi_mlreturn_arr;
  	int k;
  
  	for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) {
  		if (result == arr->value)
  			return arr->name;
  	}
c11c004b1   Hannes Reinecke   scsi: simplify sc...
443
444
445
  	return NULL;
  }
  EXPORT_SYMBOL(scsi_mlreturn_string);