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