VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / scsi / constants.c
1 /* 
2  * ASCII values for a number of symbolic constants, printing functions,
3  * etc.
4  * Additions for SCSI 2 and Linux 2.2.x by D. Gilbert (990422)
5  * Additions for SCSI 3+ (SPC-3 T10/1416-D Rev 07 3 May 2002)
6  *   by D. Gilbert and aeb (20020609)
7  */
8
9 #include <linux/config.h>
10 #include <linux/blkdev.h>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13
14 #include <scsi/scsi.h>
15 #include <scsi/scsi_device.h>
16 #include <scsi/scsi_host.h>
17 #include <scsi/scsi_request.h>
18
19
20 #define CONST_COMMAND   0x01
21 #define CONST_STATUS    0x02
22 #define CONST_SENSE     0x04
23 #define CONST_XSENSE    0x08
24 #define CONST_CMND      0x10
25 #define CONST_MSG       0x20
26 #define CONST_HOST      0x40
27 #define CONST_DRIVER    0x80
28
29 static const char unknown[] = "UNKNOWN";
30
31 #ifdef CONFIG_SCSI_CONSTANTS
32 #ifdef CONSTANTS
33 #undef CONSTANTS
34 #endif
35 #define CONSTANTS (CONST_COMMAND | CONST_STATUS | CONST_SENSE | CONST_XSENSE \
36                    | CONST_CMND | CONST_MSG | CONST_HOST | CONST_DRIVER)
37 #else
38 #define CONSTANTS 0
39 #endif
40
41 #if (CONSTANTS & CONST_COMMAND)
42 static const char * group_0_commands[] = {
43 /* 00-03 */ "Test Unit Ready", "Rezero Unit", unknown, "Request Sense",
44 /* 04-07 */ "Format Unit", "Read Block Limits", unknown, "Reasssign Blocks",
45 /* 08-0d */ "Read (6)", unknown, "Write (6)", "Seek (6)", unknown, unknown,
46 /* 0e-12 */ unknown, "Read Reverse", "Write Filemarks", "Space", "Inquiry",  
47 /* 13-16 */ "Verify", "Recover Buffered Data", "Mode Select", "Reserve",
48 /* 17-1b */ "Release", "Copy", "Erase", "Mode Sense", "Start/Stop Unit",
49 /* 1c-1d */ "Receive Diagnostic", "Send Diagnostic", 
50 /* 1e-1f */ "Prevent/Allow Medium Removal", unknown,
51 };
52
53
54 static const char *group_1_commands[] = {
55 /* 20-22 */  unknown, unknown, unknown,
56 /* 23-28 */ unknown, "Define window parameters", "Read Capacity", 
57             unknown, unknown, "Read (10)", 
58 /* 29-2d */ "Read Generation", "Write (10)", "Seek (10)", "Erase", 
59             "Read updated block", 
60 /* 2e-31 */ "Write Verify","Verify", "Search High", "Search Equal", 
61 /* 32-34 */ "Search Low", "Set Limits", "Prefetch or Read Position", 
62 /* 35-37 */ "Synchronize Cache","Lock/Unlock Cache", "Read Defect Data", 
63 /* 38-3c */ "Medium Scan", "Compare", "Copy Verify", "Write Buffer", 
64             "Read Buffer", 
65 /* 3d-3f */ "Update Block", "Read Long",  "Write Long",
66 };
67
68
69 static const char *group_2_commands[] = {
70 /* 40-41 */ "Change Definition", "Write Same",
71 /* 42-48 */ "Read sub-channel", "Read TOC", "Read header",
72             "Play audio (10)", "Get configuration", "Play audio msf",
73             "Play audio track/index",
74 /* 49-4f */ "Play track relative (10)", "Get event status notification",
75             "Pause/resume", "Log Select", "Log Sense", "Stop play/scan",
76             unknown,
77 /* 50-55 */ "Xdwrite", "Xpwrite, Read disk info", "Xdread, Read track info",
78             "Reserve track", "Send OPC onfo", "Mode Select (10)",
79 /* 56-5b */ "Reserve (10)", "Release (10)", "Repair track", "Read master cue",
80             "Mode Sense (10)", "Close track/session",
81 /* 5c-5f */ "Read buffer capacity", "Send cue sheet", "Persistent reserve in",
82             "Persistent reserve out",
83 };
84
85
86 /* The following are 16 byte commands in group 4 */
87 static const char *group_4_commands[] = {
88 /* 80-84 */ "Xdwrite (16)", "Rebuild (16)", "Regenerate (16)", "Extended copy",
89             "Receive copy results",
90 /* 85-89 */ "Memory Export In (16)", "Access control in", "Access control out",
91             "Read (16)", "Memory Export Out (16)",
92 /* 8a-8f */ "Write (16)", unknown, "Read attributes", "Write attributes",
93             "Write and verify (16)", "Verify (16)",
94 /* 90-94 */ "Pre-fetch (16)", "Synchronize cache (16)",
95             "Lock/unlock cache (16)", "Write same (16)", unknown,
96 /* 95-99 */ unknown, unknown, unknown, unknown, unknown,
97 /* 9a-9f */ unknown, unknown, unknown, unknown, "Service action in",
98             "Service action out",
99 };
100
101 /* The following are 12 byte commands in group 5 */
102 static const char *group_5_commands[] = {
103 /* a0-a5 */ "Report luns", "Blank", "Send event", "Maintenance (in)",
104             "Maintenance (out)", "Move medium/play audio(12)",
105 /* a6-a9 */ "Exchange medium", "Move medium attached", "Read(12)",
106             "Play track relative(12)",
107 /* aa-ae */ "Write(12)", unknown, "Erase(12), Get Performance",
108             "Read DVD structure", "Write and verify(12)",
109 /* af-b1 */ "Verify(12)", "Search data high(12)", "Search data equal(12)",
110 /* b2-b4 */ "Search data low(12)", "Set limits(12)",
111             "Read element status attached",
112 /* b5-b6 */ "Request volume element address", "Send volume tag, set streaming",
113 /* b7-b9 */ "Read defect data(12)", "Read element status", "Read CD msf",
114 /* ba-bc */ "Redundancy group (in), Scan",
115             "Redundancy group (out), Set cd-rom speed", "Spare (in), Play cd",
116 /* bd-bf */ "Spare (out), Mechanism status", "Volume set (in), Read cd",
117             "Volume set (out), Send DVD structure",
118 };
119
120
121
122 #define group(opcode) (((opcode) >> 5) & 7)
123
124 #define RESERVED_GROUP  0
125 #define VENDOR_GROUP    1
126
127 static const char **commands[] = {
128     group_0_commands, group_1_commands, group_2_commands, 
129     (const char **) RESERVED_GROUP, group_4_commands, 
130     group_5_commands, (const char **) VENDOR_GROUP, 
131     (const char **) VENDOR_GROUP
132 };
133
134 static const char reserved[] = "RESERVED";
135 static const char vendor[] = "VENDOR SPECIFIC";
136
137 static void print_opcode(int opcode) {
138     const char **table = commands[ group(opcode) ];
139     switch ((unsigned long) table) {
140     case RESERVED_GROUP:
141         printk("%s(0x%02x) ", reserved, opcode); 
142         break;
143     case VENDOR_GROUP:
144         printk("%s(0x%02x) ", vendor, opcode); 
145         break;
146     default:
147         if (table[opcode & 0x1f] != unknown)
148             printk("%s ",table[opcode & 0x1f]);
149         else
150             printk("%s(0x%02x) ", unknown, opcode);
151         break;
152     }
153 }
154 #else /* CONST & CONST_COMMAND */
155 static void print_opcode(int opcode) {
156     printk("0x%02x ", opcode);
157 }
158 #endif  
159
160 void __scsi_print_command (unsigned char *command) {
161     int i,s;
162     print_opcode(command[0]);
163     for ( i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i) 
164         printk("%02x ", command[i]);
165     printk("\n");
166 }
167
168 /**
169  *
170  *      print_status - print scsi status description
171  *      @scsi_status: scsi status value
172  *
173  *      If the status is recognized, the description is printed.
174  *      Otherwise "Unknown status" is output. No trailing space.
175  *      If CONFIG_SCSI_CONSTANTS is not set, then print status in hex
176  *      (e.g. "0x2" for Check Condition).
177  **/
178 void
179 scsi_print_status(unsigned char scsi_status) {
180 #if (CONSTANTS & CONST_STATUS)
181         const char * ccp;
182
183         switch (scsi_status) {
184         case 0:    ccp = "Good"; break;
185         case 0x2:  ccp = "Check Condition"; break;
186         case 0x4:  ccp = "Condition Met"; break;
187         case 0x8:  ccp = "Busy"; break;
188         case 0x10: ccp = "Intermediate"; break;
189         case 0x14: ccp = "Intermediate-Condition Met"; break;
190         case 0x18: ccp = "Reservation Conflict"; break;
191         case 0x22: ccp = "Command Terminated"; break;   /* obsolete */
192         case 0x28: ccp = "Task set Full"; break;        /* was: Queue Full */
193         case 0x30: ccp = "ACA Active"; break;
194         case 0x40: ccp = "Task Aborted"; break;
195         default:   ccp = "Unknown status";
196         }
197         printk("%s", ccp);
198 #else
199         printk("0x%0x", scsi_status);
200 #endif
201 }
202
203 #if (CONSTANTS & CONST_XSENSE)
204
205 struct error_info {
206         unsigned short code12;  /* 0x0302 looks better than 0x03,0x02 */
207         const char * text;
208 };
209
210 static struct error_info additional[] =
211 {
212         {0x0000, "No additional sense information"},
213         {0x0001, "Filemark detected"},
214         {0x0002, "End-of-partition/medium detected"},
215         {0x0003, "Setmark detected"},
216         {0x0004, "Beginning-of-partition/medium detected"},
217         {0x0005, "End-of-data detected"},
218         {0x0006, "I/O process terminated"},
219         {0x0011, "Audio play operation in progress"},
220         {0x0012, "Audio play operation paused"},
221         {0x0013, "Audio play operation successfully completed"},
222         {0x0014, "Audio play operation stopped due to error"},
223         {0x0015, "No current audio status to return"},
224         {0x0016, "Operation in progress"},
225         {0x0017, "Cleaning requested"},
226         {0x0018, "Erase operation in progress"},
227         {0x0019, "Locate operation in progress"},
228         {0x001A, "Rewind operation in progress"},
229         {0x001B, "Set capacity operation in progress"},
230         {0x001C, "Verify operation in progress"},
231
232         {0x0100, "No index/sector signal"},
233
234         {0x0200, "No seek complete"},
235
236         {0x0300, "Peripheral device write fault"},
237         {0x0301, "No write current"},
238         {0x0302, "Excessive write errors"},
239
240         {0x0400, "Logical unit not ready, cause not reportable"},
241         {0x0401, "Logical unit is in process of becoming ready"},
242         {0x0402, "Logical unit not ready, initializing cmd. required"},
243         {0x0403, "Logical unit not ready, manual intervention required"},
244         {0x0404, "Logical unit not ready, format in progress"},
245         {0x0405, "Logical unit not ready, rebuild in progress"},
246         {0x0406, "Logical unit not ready, recalculation in progress"},
247         {0x0407, "Logical unit not ready, operation in progress"},
248         {0x0408, "Logical unit not ready, long write in progress"},
249         {0x0409, "Logical unit not ready, self-test in progress"},
250         {0x040A, "Logical unit not accessible, asymmetric access state "
251          "transition"},
252         {0x040B, "Logical unit not accessible, target port in standby state"},
253         {0x040C, "Logical unit not accessible, target port in unavailable "
254          "state"},
255         {0x0410, "Logical unit not ready, auxiliary memory not accessible"},
256
257         {0x0500, "Logical unit does not respond to selection"},
258
259         {0x0600, "No reference position found"},
260
261         {0x0700, "Multiple peripheral devices selected"},
262
263         {0x0800, "Logical unit communication failure"},
264         {0x0801, "Logical unit communication time-out"},
265         {0x0802, "Logical unit communication parity error"},
266         {0x0803, "Logical unit communication CRC error (Ultra-DMA/32)"},
267         {0x0804, "Unreachable copy target"},
268
269         {0x0900, "Track following error"},
270         {0x0901, "Tracking servo failure"},
271         {0x0902, "Focus servo failure"},
272         {0x0903, "Spindle servo failure"},
273         {0x0904, "Head select fault"},
274
275         {0x0A00, "Error log overflow"},
276
277         {0x0B00, "Warning"},
278         {0x0B01, "Warning - specified temperature exceeded"},
279         {0x0B02, "Warning - enclosure degraded"},
280
281         {0x0C00, "Write error"},
282         {0x0C01, "Write error - recovered with auto reallocation"},
283         {0x0C02, "Write error - auto reallocation failed"},
284         {0x0C03, "Write error - recommend reassignment"},
285         {0x0C04, "Compression check miscompare error"},
286         {0x0C05, "Data expansion occurred during compression"},
287         {0x0C06, "Block not compressible"},
288         {0x0C07, "Write error - recovery needed"},
289         {0x0C08, "Write error - recovery failed"},
290         {0x0C09, "Write error - loss of streaming"},
291         {0x0C0A, "Write error - padding blocks added"},
292         {0x0C0B, "Auxiliary memory write error"},
293         {0x0C0C, "Write error - unexpected unsolicited data"},
294         {0x0C0D, "Write error - not enough unsolicited data"},
295
296         {0x0D00, "Error detected by third party temporary initiator"},
297         {0x0D01, "Third party device failure"},
298         {0x0D02, "Copy target device not reachable"},
299         {0x0D03, "Incorrect copy target device type"},
300         {0x0D04, "Copy target device data underrun"},
301         {0x0D05, "Copy target device data overrun"},
302
303         {0x1000, "Id CRC or ECC error"},
304
305         {0x1100, "Unrecovered read error"},
306         {0x1101, "Read retries exhausted"},
307         {0x1102, "Error too long to correct"},
308         {0x1103, "Multiple read errors"},
309         {0x1104, "Unrecovered read error - auto reallocate failed"},
310         {0x1105, "L-EC uncorrectable error"},
311         {0x1106, "CIRC unrecovered error"},
312         {0x1107, "Data re-synchronization error"},
313         {0x1108, "Incomplete block read"},
314         {0x1109, "No gap found"},
315         {0x110A, "Miscorrected error"},
316         {0x110B, "Unrecovered read error - recommend reassignment"},
317         {0x110C, "Unrecovered read error - recommend rewrite the data"},
318         {0x110D, "De-compression CRC error"},
319         {0x110E, "Cannot decompress using declared algorithm"},
320         {0x110F, "Error reading UPC/EAN number"},
321         {0x1110, "Error reading ISRC number"},
322         {0x1111, "Read error - loss of streaming"},
323         {0x1112, "Auxiliary memory read error"},
324         {0x1113, "Read error - failed retransmission request"},
325
326         {0x1200, "Address mark not found for id field"},
327
328         {0x1300, "Address mark not found for data field"},
329
330         {0x1400, "Recorded entity not found"},
331         {0x1401, "Record not found"},
332         {0x1402, "Filemark or setmark not found"},
333         {0x1403, "End-of-data not found"},
334         {0x1404, "Block sequence error"},
335         {0x1405, "Record not found - recommend reassignment"},
336         {0x1406, "Record not found - data auto-reallocated"},
337         {0x1407, "Locate operation failure"},
338
339         {0x1500, "Random positioning error"},
340         {0x1501, "Mechanical positioning error"},
341         {0x1502, "Positioning error detected by read of medium"},
342
343         {0x1600, "Data synchronization mark error"},
344         {0x1601, "Data sync error - data rewritten"},
345         {0x1602, "Data sync error - recommend rewrite"},
346         {0x1603, "Data sync error - data auto-reallocated"},
347         {0x1604, "Data sync error - recommend reassignment"},
348
349         {0x1700, "Recovered data with no error correction applied"},
350         {0x1701, "Recovered data with retries"},
351         {0x1702, "Recovered data with positive head offset"},
352         {0x1703, "Recovered data with negative head offset"},
353         {0x1704, "Recovered data with retries and/or circ applied"},
354         {0x1705, "Recovered data using previous sector id"},
355         {0x1706, "Recovered data without ECC - data auto-reallocated"},
356         {0x1707, "Recovered data without ECC - recommend reassignment"},
357         {0x1708, "Recovered data without ECC - recommend rewrite"},
358         {0x1709, "Recovered data without ECC - data rewritten"},
359
360         {0x1800, "Recovered data with error correction applied"},
361         {0x1801, "Recovered data with error corr. & retries applied"},
362         {0x1802, "Recovered data - data auto-reallocated"},
363         {0x1803, "Recovered data with CIRC"},
364         {0x1804, "Recovered data with L-EC"},
365         {0x1805, "Recovered data - recommend reassignment"},
366         {0x1806, "Recovered data - recommend rewrite"},
367         {0x1807, "Recovered data with ECC - data rewritten"},
368         {0x1808, "Recovered data with linking"},
369
370         {0x1900, "Defect list error"},
371         {0x1901, "Defect list not available"},
372         {0x1902, "Defect list error in primary list"},
373         {0x1903, "Defect list error in grown list"},
374
375         {0x1A00, "Parameter list length error"},
376
377         {0x1B00, "Synchronous data transfer error"},
378
379         {0x1C00, "Defect list not found"},
380         {0x1C01, "Primary defect list not found"},
381         {0x1C02, "Grown defect list not found"},
382
383         {0x1D00, "Miscompare during verify operation"},
384
385         {0x1E00, "Recovered id with ECC correction"},
386
387         {0x1F00, "Partial defect list transfer"},
388
389         {0x2000, "Invalid command operation code"},
390         {0x2001, "Access denied - initiator pending-enrolled"},
391         {0x2002, "Access denied - no access rights"},
392         {0x2003, "Access denied - invalid mgmt id key"},
393         {0x2004, "Illegal command while in write capable state"},
394         {0x2005, "Obsolete"},
395         {0x2006, "Illegal command while in explicit address mode"},
396         {0x2007, "Illegal command while in implicit address mode"},
397         {0x2008, "Access denied - enrollment conflict"},
398         {0x2009, "Access denied - invalid LU identifier"},
399         {0x200A, "Access denied - invalid proxy token"},
400         {0x200B, "Access denied - ACL LUN conflict"},
401
402         {0x2100, "Logical block address out of range"},
403         {0x2101, "Invalid element address"},
404         {0x2102, "Invalid address for write"},
405
406         {0x2200, "Illegal function (use 20 00, 24 00, or 26 00)"},
407
408         {0x2400, "Invalid field in cdb"},
409         {0x2401, "CDB decryption error"},
410         {0x2402, "Obsolete"},
411         {0x2403, "Obsolete"},
412
413         {0x2500, "Logical unit not supported"},
414
415         {0x2600, "Invalid field in parameter list"},
416         {0x2601, "Parameter not supported"},
417         {0x2602, "Parameter value invalid"},
418         {0x2603, "Threshold parameters not supported"},
419         {0x2604, "Invalid release of persistent reservation"},
420         {0x2605, "Data decryption error"},
421         {0x2606, "Too many target descriptors"},
422         {0x2607, "Unsupported target descriptor type code"},
423         {0x2608, "Too many segment descriptors"},
424         {0x2609, "Unsupported segment descriptor type code"},
425         {0x260A, "Unexpected inexact segment"},
426         {0x260B, "Inline data length exceeded"},
427         {0x260C, "Invalid operation for copy source or destination"},
428         {0x260D, "Copy segment granularity violation"},
429
430         {0x2700, "Write protected"},
431         {0x2701, "Hardware write protected"},
432         {0x2702, "Logical unit software write protected"},
433         {0x2703, "Associated write protect"},
434         {0x2704, "Persistent write protect"},
435         {0x2705, "Permanent write protect"},
436         {0x2706, "Conditional write protect"},
437
438         {0x2800, "Not ready to ready change, medium may have changed"},
439         {0x2801, "Import or export element accessed"},
440
441         {0x2900, "Power on, reset, or bus device reset occurred"},
442         {0x2901, "Power on occurred"},
443         {0x2902, "Scsi bus reset occurred"},
444         {0x2903, "Bus device reset function occurred"},
445         {0x2904, "Device internal reset"},
446         {0x2905, "Transceiver mode changed to single-ended"},
447         {0x2906, "Transceiver mode changed to lvd"},
448         {0x2907, "I_T nexus loss occurred"},
449
450         {0x2A00, "Parameters changed"},
451         {0x2A01, "Mode parameters changed"},
452         {0x2A02, "Log parameters changed"},
453         {0x2A03, "Reservations preempted"},
454         {0x2A04, "Reservations released"},
455         {0x2A05, "Registrations preempted"},
456         {0x2A06, "Asymmetric access state changed"},
457         {0x2A07, "Implicit asymmetric access state transition failed"},
458
459         {0x2B00, "Copy cannot execute since host cannot disconnect"},
460
461         {0x2C00, "Command sequence error"},
462         {0x2C01, "Too many windows specified"},
463         {0x2C02, "Invalid combination of windows specified"},
464         {0x2C03, "Current program area is not empty"},
465         {0x2C04, "Current program area is empty"},
466         {0x2C05, "Illegal power condition request"},
467         {0x2C06, "Persistent prevent conflict"},
468         {0x2C07, "Previous busy status"},
469         {0x2C08, "Previous task set full status"},
470         {0x2C09, "Previous reservation conflict status"},
471
472         {0x2D00, "Overwrite error on update in place"},
473
474         {0x2E00, "Insufficient time for operation"},
475
476         {0x2F00, "Commands cleared by another initiator"},
477
478         {0x3000, "Incompatible medium installed"},
479         {0x3001, "Cannot read medium - unknown format"},
480         {0x3002, "Cannot read medium - incompatible format"},
481         {0x3003, "Cleaning cartridge installed"},
482         {0x3004, "Cannot write medium - unknown format"},
483         {0x3005, "Cannot write medium - incompatible format"},
484         {0x3006, "Cannot format medium - incompatible medium"},
485         {0x3007, "Cleaning failure"},
486         {0x3008, "Cannot write - application code mismatch"},
487         {0x3009, "Current session not fixated for append"},
488         {0x3010, "Medium not formatted"},
489
490         {0x3100, "Medium format corrupted"},
491         {0x3101, "Format command failed"},
492         {0x3102, "Zoned formatting failed due to spare linking"},
493
494         {0x3200, "No defect spare location available"},
495         {0x3201, "Defect list update failure"},
496
497         {0x3300, "Tape length error"},
498
499         {0x3400, "Enclosure failure"},
500
501         {0x3500, "Enclosure services failure"},
502         {0x3501, "Unsupported enclosure function"},
503         {0x3502, "Enclosure services unavailable"},
504         {0x3503, "Enclosure services transfer failure"},
505         {0x3504, "Enclosure services transfer refused"},
506
507         {0x3600, "Ribbon, ink, or toner failure"},
508
509         {0x3700, "Rounded parameter"},
510
511         {0x3800, "Event status notification"},
512         {0x3802, "Esn - power management class event"},
513         {0x3804, "Esn - media class event"},
514         {0x3806, "Esn - device busy class event"},
515
516         {0x3900, "Saving parameters not supported"},
517
518         {0x3A00, "Medium not present"},
519         {0x3A01, "Medium not present - tray closed"},
520         {0x3A02, "Medium not present - tray open"},
521         {0x3A03, "Medium not present - loadable"},
522         {0x3A04, "Medium not present - medium auxiliary memory accessible"},
523
524         {0x3B00, "Sequential positioning error"},
525         {0x3B01, "Tape position error at beginning-of-medium"},
526         {0x3B02, "Tape position error at end-of-medium"},
527         {0x3B03, "Tape or electronic vertical forms unit not ready"},
528         {0x3B04, "Slew failure"},
529         {0x3B05, "Paper jam"},
530         {0x3B06, "Failed to sense top-of-form"},
531         {0x3B07, "Failed to sense bottom-of-form"},
532         {0x3B08, "Reposition error"},
533         {0x3B09, "Read past end of medium"},
534         {0x3B0A, "Read past beginning of medium"},
535         {0x3B0B, "Position past end of medium"},
536         {0x3B0C, "Position past beginning of medium"},
537         {0x3B0D, "Medium destination element full"},
538         {0x3B0E, "Medium source element empty"},
539         {0x3B0F, "End of medium reached"},
540         {0x3B11, "Medium magazine not accessible"},
541         {0x3B12, "Medium magazine removed"},
542         {0x3B13, "Medium magazine inserted"},
543         {0x3B14, "Medium magazine locked"},
544         {0x3B15, "Medium magazine unlocked"},
545         {0x3B16, "Mechanical positioning or changer error"},
546
547         {0x3D00, "Invalid bits in identify message"},
548
549         {0x3E00, "Logical unit has not self-configured yet"},
550         {0x3E01, "Logical unit failure"},
551         {0x3E02, "Timeout on logical unit"},
552         {0x3E03, "Logical unit failed self-test"},
553         {0x3E04, "Logical unit unable to update self-test log"},
554
555         {0x3F00, "Target operating conditions have changed"},
556         {0x3F01, "Microcode has been changed"},
557         {0x3F02, "Changed operating definition"},
558         {0x3F03, "Inquiry data has changed"},
559         {0x3F04, "Component device attached"},
560         {0x3F05, "Device identifier changed"},
561         {0x3F06, "Redundancy group created or modified"},
562         {0x3F07, "Redundancy group deleted"},
563         {0x3F08, "Spare created or modified"},
564         {0x3F09, "Spare deleted"},
565         {0x3F0A, "Volume set created or modified"},
566         {0x3F0B, "Volume set deleted"},
567         {0x3F0C, "Volume set deassigned"},
568         {0x3F0D, "Volume set reassigned"},
569         {0x3F0E, "Reported luns data has changed"},
570         {0x3F0F, "Echo buffer overwritten"},
571         {0x3F10, "Medium loadable"},
572         {0x3F11, "Medium auxiliary memory accessible"},
573
574 #if 0
575         {0x40NN, "Ram failure"},
576         {0x40NN, "Diagnostic failure on component nn"},
577         {0x41NN, "Data path failure"},
578         {0x42NN, "Power-on or self-test failure"},
579 #endif
580
581         {0x4300, "Message error"},
582
583         {0x4400, "Internal target failure"},
584
585         {0x4500, "Select or reselect failure"},
586
587         {0x4600, "Unsuccessful soft reset"},
588
589         {0x4700, "Scsi parity error"},
590         {0x4701, "Data phase CRC error detected"},
591         {0x4702, "Scsi parity error detected during st data phase"},
592         {0x4703, "Information unit CRC error detected"},
593         {0x4704, "Asynchronous information protection error detected"},
594         {0x4705, "Protocol service CRC error"},
595
596         {0x4800, "Initiator detected error message received"},
597
598         {0x4900, "Invalid message error"},
599
600         {0x4A00, "Command phase error"},
601
602         {0x4B00, "Data phase error"},
603
604         {0x4C00, "Logical unit failed self-configuration"},
605
606 #if 0
607         {0x4DNN, "Tagged overlapped commands (nn = queue tag)"},
608 #endif
609
610         {0x4E00, "Overlapped commands attempted"},
611
612         {0x5000, "Write append error"},
613         {0x5001, "Write append position error"},
614         {0x5002, "Position error related to timing"},
615
616         {0x5100, "Erase failure"},
617         {0x5101, "Erase failure - incomplete erase operation detected"},
618
619         {0x5200, "Cartridge fault"},
620
621         {0x5300, "Media load or eject failed"},
622         {0x5301, "Unload tape failure"},
623         {0x5302, "Medium removal prevented"},
624
625         {0x5400, "Scsi to host system interface failure"},
626
627         {0x5500, "System resource failure"},
628         {0x5501, "System buffer full"},
629         {0x5502, "Insufficient reservation resources"},
630         {0x5503, "Insufficient resources"},
631         {0x5504, "Insufficient registration resources"},
632         {0x5505, "Insufficient access control resources"},
633         {0x5506, "Auxiliary memory out of space"},
634
635         {0x5700, "Unable to recover table-of-contents"},
636
637         {0x5800, "Generation does not exist"},
638
639         {0x5900, "Updated block read"},
640
641         {0x5A00, "Operator request or state change input"},
642         {0x5A01, "Operator medium removal request"},
643         {0x5A02, "Operator selected write protect"},
644         {0x5A03, "Operator selected write permit"},
645
646         {0x5B00, "Log exception"},
647         {0x5B01, "Threshold condition met"},
648         {0x5B02, "Log counter at maximum"},
649         {0x5B03, "Log list codes exhausted"},
650
651         {0x5C00, "Rpl status change"},
652         {0x5C01, "Spindles synchronized"},
653         {0x5C02, "Spindles not synchronized"},
654
655         {0x5D00, "Failure prediction threshold exceeded"},
656         {0x5D01, "Media failure prediction threshold exceeded"},
657         {0x5D02, "Logical unit failure prediction threshold exceeded"},
658         {0x5D03, "Spare area exhaustion prediction threshold exceeded"},
659         {0x5D10, "Hardware impending failure general hard drive failure"},
660         {0x5D11, "Hardware impending failure drive error rate too high"},
661         {0x5D12, "Hardware impending failure data error rate too high"},
662         {0x5D13, "Hardware impending failure seek error rate too high"},
663         {0x5D14, "Hardware impending failure too many block reassigns"},
664         {0x5D15, "Hardware impending failure access times too high"},
665         {0x5D16, "Hardware impending failure start unit times too high"},
666         {0x5D17, "Hardware impending failure channel parametrics"},
667         {0x5D18, "Hardware impending failure controller detected"},
668         {0x5D19, "Hardware impending failure throughput performance"},
669         {0x5D1A, "Hardware impending failure seek time performance"},
670         {0x5D1B, "Hardware impending failure spin-up retry count"},
671         {0x5D1C, "Hardware impending failure drive calibration retry count"},
672         {0x5D20, "Controller impending failure general hard drive failure"},
673         {0x5D21, "Controller impending failure drive error rate too high"},
674         {0x5D22, "Controller impending failure data error rate too high"},
675         {0x5D23, "Controller impending failure seek error rate too high"},
676         {0x5D24, "Controller impending failure too many block reassigns"},
677         {0x5D25, "Controller impending failure access times too high"},
678         {0x5D26, "Controller impending failure start unit times too high"},
679         {0x5D27, "Controller impending failure channel parametrics"},
680         {0x5D28, "Controller impending failure controller detected"},
681         {0x5D29, "Controller impending failure throughput performance"},
682         {0x5D2A, "Controller impending failure seek time performance"},
683         {0x5D2B, "Controller impending failure spin-up retry count"},
684         {0x5D2C, "Controller impending failure drive calibration retry count"},
685         {0x5D30, "Data channel impending failure general hard drive failure"},
686         {0x5D31, "Data channel impending failure drive error rate too high"},
687         {0x5D32, "Data channel impending failure data error rate too high"},
688         {0x5D33, "Data channel impending failure seek error rate too high"},
689         {0x5D34, "Data channel impending failure too many block reassigns"},
690         {0x5D35, "Data channel impending failure access times too high"},
691         {0x5D36, "Data channel impending failure start unit times too high"},
692         {0x5D37, "Data channel impending failure channel parametrics"},
693         {0x5D38, "Data channel impending failure controller detected"},
694         {0x5D39, "Data channel impending failure throughput performance"},
695         {0x5D3A, "Data channel impending failure seek time performance"},
696         {0x5D3B, "Data channel impending failure spin-up retry count"},
697         {0x5D3C, "Data channel impending failure drive calibration retry "
698          "count"},
699         {0x5D40, "Servo impending failure general hard drive failure"},
700         {0x5D41, "Servo impending failure drive error rate too high"},
701         {0x5D42, "Servo impending failure data error rate too high"},
702         {0x5D43, "Servo impending failure seek error rate too high"},
703         {0x5D44, "Servo impending failure too many block reassigns"},
704         {0x5D45, "Servo impending failure access times too high"},
705         {0x5D46, "Servo impending failure start unit times too high"},
706         {0x5D47, "Servo impending failure channel parametrics"},
707         {0x5D48, "Servo impending failure controller detected"},
708         {0x5D49, "Servo impending failure throughput performance"},
709         {0x5D4A, "Servo impending failure seek time performance"},
710         {0x5D4B, "Servo impending failure spin-up retry count"},
711         {0x5D4C, "Servo impending failure drive calibration retry count"},
712         {0x5D50, "Spindle impending failure general hard drive failure"},
713         {0x5D51, "Spindle impending failure drive error rate too high"},
714         {0x5D52, "Spindle impending failure data error rate too high"},
715         {0x5D53, "Spindle impending failure seek error rate too high"},
716         {0x5D54, "Spindle impending failure too many block reassigns"},
717         {0x5D55, "Spindle impending failure access times too high"},
718         {0x5D56, "Spindle impending failure start unit times too high"},
719         {0x5D57, "Spindle impending failure channel parametrics"},
720         {0x5D58, "Spindle impending failure controller detected"},
721         {0x5D59, "Spindle impending failure throughput performance"},
722         {0x5D5A, "Spindle impending failure seek time performance"},
723         {0x5D5B, "Spindle impending failure spin-up retry count"},
724         {0x5D5C, "Spindle impending failure drive calibration retry count"},
725         {0x5D60, "Firmware impending failure general hard drive failure"},
726         {0x5D61, "Firmware impending failure drive error rate too high"},
727         {0x5D62, "Firmware impending failure data error rate too high"},
728         {0x5D63, "Firmware impending failure seek error rate too high"},
729         {0x5D64, "Firmware impending failure too many block reassigns"},
730         {0x5D65, "Firmware impending failure access times too high"},
731         {0x5D66, "Firmware impending failure start unit times too high"},
732         {0x5D67, "Firmware impending failure channel parametrics"},
733         {0x5D68, "Firmware impending failure controller detected"},
734         {0x5D69, "Firmware impending failure throughput performance"},
735         {0x5D6A, "Firmware impending failure seek time performance"},
736         {0x5D6B, "Firmware impending failure spin-up retry count"},
737         {0x5D6C, "Firmware impending failure drive calibration retry count"},
738         {0x5DFF, "Failure prediction threshold exceeded (false)"},
739
740         {0x5E00, "Low power condition on"},
741         {0x5E01, "Idle condition activated by timer"},
742         {0x5E02, "Standby condition activated by timer"},
743         {0x5E03, "Idle condition activated by command"},
744         {0x5E04, "Standby condition activated by command"},
745         {0x5E41, "Power state change to active"},
746         {0x5E42, "Power state change to idle"},
747         {0x5E43, "Power state change to standby"},
748         {0x5E45, "Power state change to sleep"},
749         {0x5E47, "Power state change to device control"},
750
751         {0x6000, "Lamp failure"},
752
753         {0x6100, "Video acquisition error"},
754         {0x6101, "Unable to acquire video"},
755         {0x6102, "Out of focus"},
756
757         {0x6200, "Scan head positioning error"},
758
759         {0x6300, "End of user area encountered on this track"},
760         {0x6301, "Packet does not fit in available space"},
761
762         {0x6400, "Illegal mode for this track"},
763         {0x6401, "Invalid packet size"},
764
765         {0x6500, "Voltage fault"},
766
767         {0x6600, "Automatic document feeder cover up"},
768         {0x6601, "Automatic document feeder lift up"},
769         {0x6602, "Document jam in automatic document feeder"},
770         {0x6603, "Document miss feed automatic in document feeder"},
771
772         {0x6700, "Configuration failure"},
773         {0x6701, "Configuration of incapable logical units failed"},
774         {0x6702, "Add logical unit failed"},
775         {0x6703, "Modification of logical unit failed"},
776         {0x6704, "Exchange of logical unit failed"},
777         {0x6705, "Remove of logical unit failed"},
778         {0x6706, "Attachment of logical unit failed"},
779         {0x6707, "Creation of logical unit failed"},
780         {0x6708, "Assign failure occurred"},
781         {0x6709, "Multiply assigned logical unit"},
782         {0x670A, "Set target port groups command failed"},
783
784         {0x6800, "Logical unit not configured"},
785
786         {0x6900, "Data loss on logical unit"},
787         {0x6901, "Multiple logical unit failures"},
788         {0x6902, "Parity/data mismatch"},
789
790         {0x6A00, "Informational, refer to log"},
791
792         {0x6B00, "State change has occurred"},
793         {0x6B01, "Redundancy level got better"},
794         {0x6B02, "Redundancy level got worse"},
795
796         {0x6C00, "Rebuild failure occurred"},
797
798         {0x6D00, "Recalculate failure occurred"},
799
800         {0x6E00, "Command to logical unit failed"},
801
802         {0x6F00, "Copy protection key exchange failure - authentication "
803          "failure"},
804         {0x6F01, "Copy protection key exchange failure - key not present"},
805         {0x6F02, "Copy protection key exchange failure - key not established"},
806         {0x6F03, "Read of scrambled sector without authentication"},
807         {0x6F04, "Media region code is mismatched to logical unit region"},
808         {0x6F05, "Drive region must be permanent/region reset count error"},
809
810 #if 0
811         {0x70NN, "Decompression exception short algorithm id of nn"},
812 #endif
813
814         {0x7100, "Decompression exception long algorithm id"},
815
816         {0x7200, "Session fixation error"},
817         {0x7201, "Session fixation error writing lead-in"},
818         {0x7202, "Session fixation error writing lead-out"},
819         {0x7203, "Session fixation error - incomplete track in session"},
820         {0x7204, "Empty or partially written reserved track"},
821         {0x7205, "No more track reservations allowed"},
822
823         {0x7300, "Cd control error"},
824         {0x7301, "Power calibration area almost full"},
825         {0x7302, "Power calibration area is full"},
826         {0x7303, "Power calibration area error"},
827         {0x7304, "Program memory area update failure"},
828         {0x7305, "Program memory area is full"},
829         {0x7306, "RMA/PMA is almost full"},
830         {0, NULL}
831 };
832
833 struct error_info2 {
834         unsigned char code1, code2_min, code2_max;
835         const char * fmt;
836 };
837
838 static struct error_info2 additional2[] =
839 {
840         {0x40,0x00,0x7f,"Ram failure (%x)"},
841         {0x40,0x80,0xff,"Diagnostic failure on component (%x)"},
842         {0x41,0x00,0xff,"Data path failure (%x)"},
843         {0x42,0x00,0xff,"Power-on or self-test failure (%x)"},
844         {0x4D,0x00,0xff,"Tagged overlapped commands (queue tag %x)"},
845         {0x70,0x00,0xff,"Decompression exception short algorithm id of %x"},
846         {0, 0, 0, NULL}
847 };
848 #endif
849
850 #if (CONSTANTS & CONST_SENSE)
851 /* description of the sense key values */
852 static const char *snstext[] = {
853         "No Sense",         /* 0: There is no sense information */
854         "Recovered Error",  /* 1: The last command completed successfully
855                                   but used error correction */
856         "Not Ready",        /* 2: The addressed target is not ready */
857         "Medium Error",     /* 3: Data error detected on the medium */
858         "Hardware Error",   /* 4: Controller or device failure */
859         "Illegal Request",  /* 5: Error in request */
860         "Unit Attention",   /* 6: Removable medium was changed, or
861                                   the target has been reset */
862         "Data Protect",     /* 7: Access to the data is blocked */
863         "Blank Check",      /* 8: Reached unexpected written or unwritten
864                                   region of the medium */
865         "Vendor Specific",  /* 9: Vendor specific */
866         "Copy Aborted",     /* A: COPY or COMPARE was aborted */
867         "Aborted Command",  /* B: The target aborted the command */
868         "Equal",            /* C: A SEARCH DATA command found data equal */
869         "Volume Overflow",  /* D: Medium full with still data to be written */
870         "Miscompare",       /* E: Source data and data on the medium
871                                   do not agree */
872 };
873 #endif
874
875 /* Get sense key string or NULL if not available */
876 const char *
877 scsi_sense_key_string(unsigned char key) {
878 #if (CONSTANTS & CONST_SENSE)
879         if (key <= 0xE)
880                 return snstext[key];
881 #endif
882         return NULL;
883 }
884
885 /*
886  * Get extended sense key string or NULL if not available.
887  * This string may contain a %x and must be printed with ascq as arg.
888  */
889 const char *
890 scsi_extd_sense_format(unsigned char asc, unsigned char ascq) {
891 #if (CONSTANTS & CONST_XSENSE)
892         int i;
893         unsigned short code = ((asc << 8) | ascq);
894
895         for (i=0; additional[i].text; i++)
896                 if (additional[i].code12 == code)
897                         return additional[i].text;
898         for (i=0; additional2[i].fmt; i++)
899                 if (additional2[i].code1 == asc &&
900                     additional2[i].code2_min >= ascq &&
901                     additional2[i].code2_max <= ascq)
902                         return additional2[i].fmt;
903 #endif
904         return NULL;
905 }
906
907 /* Print extended sense information */
908 static void
909 scsi_show_extd_sense(unsigned char asc, unsigned char ascq) {
910         const char *extd_sense_fmt = scsi_extd_sense_format(asc, ascq);
911
912         if (extd_sense_fmt) {
913                 printk("Additional sense: ");
914                 printk(extd_sense_fmt, ascq);
915                 printk("\n");
916         } else {
917                 printk("ASC=%2x ASCQ=%2x\n", asc, ascq);
918         }
919 }
920
921 /* Print sense information */
922 static void
923 print_sense_internal(const char *devclass, 
924                      const unsigned char *sense_buffer,
925                      struct request *req)
926 {
927         int s, sense_class, valid, code, info;
928         const char *error = NULL;
929         unsigned char asc, ascq;
930         const char *sense_txt;
931         const char *name = req->rq_disk ? req->rq_disk->disk_name : devclass;
932     
933         sense_class = (sense_buffer[0] >> 4) & 0x07;
934         code = sense_buffer[0] & 0xf;
935         valid = sense_buffer[0] & 0x80;
936     
937         if (sense_class == 7) { /* extended sense data */
938                 s = sense_buffer[7] + 8;
939                 if (s > SCSI_SENSE_BUFFERSIZE)
940                         s = SCSI_SENSE_BUFFERSIZE;
941         
942                 info = ((sense_buffer[3] << 24) | (sense_buffer[4] << 16) |
943                         (sense_buffer[5] << 8) | sense_buffer[6]);
944                 if (info || valid) {
945                         printk("Info fld=0x%x", info);
946                         if (!valid)     /* info data not according to standard */
947                                 printk(" (nonstd)");
948                         printk(", ");
949                 }
950                 if (sense_buffer[2] & 0x80)
951                         printk( "FMK ");        /* current command has read a filemark */
952                 if (sense_buffer[2] & 0x40)
953                         printk( "EOM ");        /* end-of-medium condition exists */
954                 if (sense_buffer[2] & 0x20)
955                         printk( "ILI ");        /* incorrect block length requested */
956         
957                 switch (code) {
958                 case 0x0:
959                         error = "Current";      /* error concerns current command */
960                         break;
961                 case 0x1:
962                         error = "Deferred";     /* error concerns some earlier command */
963                         /* e.g., an earlier write to disk cache succeeded, but
964                            now the disk discovers that it cannot write the data */
965                         break;
966                 default:
967                         error = "Invalid";
968                 }
969
970                 printk("%s ", error);
971
972                 sense_txt = scsi_sense_key_string(sense_buffer[2]);
973                 if (sense_txt)
974                         printk("%s: sense key %s\n", name, sense_txt);
975                 else
976                         printk("%s: sense = %2x %2x\n", name,
977                                sense_buffer[0], sense_buffer[2]);
978
979                 asc = ascq = 0;
980                 if (sense_buffer[7] + 7 >= 13) {
981                         asc = sense_buffer[12];
982                         ascq = sense_buffer[13];
983                 }
984                 if (asc || ascq)
985                         scsi_show_extd_sense(asc, ascq);
986
987         } else {        /* non-extended sense data */
988
989                 /*
990                  * Standard says:
991                  *    sense_buffer[0] & 0200 : address valid
992                  *    sense_buffer[0] & 0177 : vendor-specific error code
993                  *    sense_buffer[1] & 0340 : vendor-specific
994                  *    sense_buffer[1..3] : 21-bit logical block address
995                  */
996
997                 sense_txt = scsi_sense_key_string(sense_buffer[0]);
998                 if (sense_txt)
999                         printk("%s: old sense key %s\n", name, sense_txt);
1000                 else
1001                         printk("%s: sense = %2x %2x\n", name,
1002                                sense_buffer[0], sense_buffer[2]);
1003
1004                 printk("Non-extended sense class %d code 0x%0x\n",
1005                        sense_class, code);
1006                 s = 4;
1007         }
1008     
1009 #if !(CONSTANTS & CONST_SENSE)
1010         {
1011                 int i;
1012         printk("Raw sense data:");
1013         for (i = 0; i < s; ++i) 
1014                 printk("0x%02x ", sense_buffer[i]);
1015         printk("\n");
1016         }
1017 #endif
1018 }
1019
1020 void scsi_print_sense(const char *devclass, struct scsi_cmnd *cmd)
1021 {
1022         print_sense_internal(devclass, cmd->sense_buffer, cmd->request);
1023 }
1024
1025 void scsi_print_req_sense(const char *devclass, struct scsi_request *sreq)
1026 {
1027         print_sense_internal(devclass, sreq->sr_sense_buffer, sreq->sr_request);
1028 }
1029
1030 #if (CONSTANTS & CONST_MSG) 
1031 static const char *one_byte_msgs[] = {
1032 /* 0x00 */ "Command Complete", NULL, "Save Pointers",
1033 /* 0x03 */ "Restore Pointers", "Disconnect", "Initiator Error", 
1034 /* 0x06 */ "Abort", "Message Reject", "Nop", "Message Parity Error",
1035 /* 0x0a */ "Linked Command Complete", "Linked Command Complete w/flag",
1036 /* 0x0c */ "Bus device reset", "Abort Tag", "Clear Queue", 
1037 /* 0x0f */ "Initiate Recovery", "Release Recovery"
1038 };
1039
1040 #define NO_ONE_BYTE_MSGS (sizeof(one_byte_msgs)  / sizeof (const char *))
1041
1042 static const char *two_byte_msgs[] = {
1043 /* 0x20 */ "Simple Queue Tag", "Head of Queue Tag", "Ordered Queue Tag"
1044 /* 0x23 */ "Ignore Wide Residue"
1045 };
1046
1047 #define NO_TWO_BYTE_MSGS (sizeof(two_byte_msgs)  / sizeof (const char *))
1048
1049 static const char *extended_msgs[] = {
1050 /* 0x00 */ "Modify Data Pointer", "Synchronous Data Transfer Request",
1051 /* 0x02 */ "SCSI-I Extended Identify", "Wide Data Transfer Request"
1052 };
1053
1054 #define NO_EXTENDED_MSGS (sizeof(two_byte_msgs)  / sizeof (const char *))
1055 #endif /* (CONSTANTS & CONST_MSG) */
1056
1057 int scsi_print_msg (const unsigned char *msg) {
1058     int len = 0, i;
1059     if (msg[0] == EXTENDED_MESSAGE) {
1060         len = 3 + msg[1];
1061 #if (CONSTANTS & CONST_MSG)
1062         if (msg[2] < NO_EXTENDED_MSGS)
1063             printk ("%s ", extended_msgs[msg[2]]); 
1064         else 
1065             printk ("Extended Message, reserved code (0x%02x) ", (int) msg[2]);
1066         switch (msg[2]) {
1067         case EXTENDED_MODIFY_DATA_POINTER:
1068             printk("pointer = %d", (int) (msg[3] << 24) | (msg[4] << 16) | 
1069                    (msg[5] << 8) | msg[6]);
1070             break;
1071         case EXTENDED_SDTR:
1072             printk("period = %d ns, offset = %d", (int) msg[3] * 4, (int) 
1073                    msg[4]);
1074             break;
1075         case EXTENDED_WDTR:
1076             printk("width = 2^%d bytes", msg[3]);
1077             break;
1078         default:
1079             for (i = 2; i < len; ++i) 
1080                 printk("%02x ", msg[i]);
1081         }
1082 #else
1083         for (i = 0; i < len; ++i)
1084             printk("%02x ", msg[i]);
1085 #endif
1086         /* Identify */
1087     } else if (msg[0] & 0x80) {
1088 #if (CONSTANTS & CONST_MSG)
1089         printk("Identify disconnect %sallowed %s %d ",
1090                (msg[0] & 0x40) ? "" : "not ",
1091                (msg[0] & 0x20) ? "target routine" : "lun",
1092                msg[0] & 0x7);
1093 #else
1094         printk("%02x ", msg[0]);
1095 #endif
1096         len = 1;
1097         /* Normal One byte */
1098     } else if (msg[0] < 0x1f) {
1099 #if (CONSTANTS & CONST_MSG)
1100         if (msg[0] < NO_ONE_BYTE_MSGS)
1101             printk(one_byte_msgs[msg[0]]);
1102         else
1103             printk("reserved (%02x) ", msg[0]);
1104 #else
1105         printk("%02x ", msg[0]);
1106 #endif
1107         len = 1;
1108         /* Two byte */
1109     } else if (msg[0] <= 0x2f) {
1110 #if (CONSTANTS & CONST_MSG)
1111         if ((msg[0] - 0x20) < NO_TWO_BYTE_MSGS)
1112             printk("%s %02x ", two_byte_msgs[msg[0] - 0x20], 
1113                    msg[1]);
1114         else 
1115             printk("reserved two byte (%02x %02x) ", 
1116                    msg[0], msg[1]);
1117 #else
1118         printk("%02x %02x", msg[0], msg[1]);
1119 #endif
1120         len = 2;
1121     } else 
1122 #if (CONSTANTS & CONST_MSG)
1123         printk(reserved);
1124 #else
1125     printk("%02x ", msg[0]);
1126 #endif
1127     return len;
1128 }
1129
1130 void scsi_print_command(struct scsi_cmnd *cmd) {
1131     printk("scsi%d : destination target %d, lun %d\n", 
1132            cmd->device->host->host_no, 
1133            cmd->device->id, 
1134            cmd->device->lun);
1135     printk("        command = ");
1136     __scsi_print_command(cmd->cmnd);
1137 }
1138
1139 #if (CONSTANTS & CONST_HOST)
1140 static const char * hostbyte_table[]={
1141 "DID_OK", "DID_NO_CONNECT", "DID_BUS_BUSY", "DID_TIME_OUT", "DID_BAD_TARGET", 
1142 "DID_ABORT", "DID_PARITY", "DID_ERROR", "DID_RESET", "DID_BAD_INTR",
1143 "DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", NULL};
1144
1145 void scsi_print_hostbyte(int scsiresult)
1146 {   static int maxcode=0;
1147     int i;
1148    
1149     if(!maxcode) {
1150         for(i=0;hostbyte_table[i];i++) ;
1151         maxcode=i-1;
1152     }
1153     printk("Hostbyte=0x%02x",host_byte(scsiresult));
1154     if(host_byte(scsiresult)>maxcode) {
1155         printk("is invalid "); 
1156         return;
1157     }
1158     printk("(%s) ",hostbyte_table[host_byte(scsiresult)]);
1159 }
1160 #else
1161 void scsi_print_hostbyte(int scsiresult)
1162 {   printk("Hostbyte=0x%02x ",host_byte(scsiresult));
1163 }
1164 #endif
1165
1166 #if (CONSTANTS & CONST_DRIVER)
1167 static const char * driverbyte_table[]={
1168 "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR", 
1169 "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD",NULL };
1170
1171 static const char * driversuggest_table[]={"SUGGEST_OK",
1172 "SUGGEST_RETRY", "SUGGEST_ABORT", "SUGGEST_REMAP", "SUGGEST_DIE",
1173 unknown,unknown,unknown, "SUGGEST_SENSE",NULL};
1174
1175
1176 void scsi_print_driverbyte(int scsiresult)
1177 {   static int driver_max=0,suggest_max=0;
1178     int i,dr=driver_byte(scsiresult)&DRIVER_MASK, 
1179         su=(driver_byte(scsiresult)&SUGGEST_MASK)>>4;
1180
1181     if(!driver_max) {
1182         for(i=0;driverbyte_table[i];i++) ;
1183         driver_max=i;
1184         for(i=0;driversuggest_table[i];i++) ;
1185         suggest_max=i;
1186     }
1187     printk("Driverbyte=0x%02x",driver_byte(scsiresult));
1188     printk("(%s,%s) ",
1189         dr<driver_max  ? driverbyte_table[dr]:"invalid",
1190         su<suggest_max ? driversuggest_table[su]:"invalid");
1191 }
1192 #else
1193 void scsi_print_driverbyte(int scsiresult)
1194 {   printk("Driverbyte=0x%02x ",driver_byte(scsiresult));
1195 }
1196 #endif