home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.2 / LINUX-1.2 / LINUX-1 / linux / drivers / scsi / constants.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-29  |  20.6 KB  |  558 lines

  1. /* 
  2.  * ASCII values for a number of symbolic constants, printing functions,
  3.  * etc.
  4.  */
  5.  
  6. #include <linux/config.h>
  7. #include "../block/blk.h"
  8. #include <linux/kernel.h>
  9. #include "scsi.h"
  10. #include "hosts.h"
  11.  
  12. #define CONST_COMMAND     0x01
  13. #define CONST_STATUS     0x02
  14. #define CONST_SENSE     0x04
  15. #define CONST_XSENSE     0x08
  16. #define CONST_CMND    0x10
  17. #define CONST_MSG    0x20
  18.  
  19. static const char unknown[] = "UNKNOWN";
  20.  
  21. #ifdef CONFIG_SCSI_CONSTANTS
  22. #ifdef CONSTANTS
  23. #undef CONSTANTS
  24. #endif
  25. #define CONSTANTS (CONST_COMMAND | CONST_STATUS | CONST_SENSE | CONST_XSENSE | CONST_CMND | CONST_MSG)
  26. #endif
  27.  
  28. #if (CONSTANTS & CONST_COMMAND)
  29. static const char * group_0_commands[] = {
  30. /* 00-03 */ "Test Unit Ready", "Rezero Unit", unknown, "Request Sense",
  31. /* 04-07 */ "Format Unit", "Read Block Limits", unknown, "Reasssign Blocks",
  32. /* 08-0d */ "Read (6)", unknown, "Write (6)", "Seek (6)", unknown, unknown,
  33. /* 0e-12 */ unknown, "Read Reverse", "Write Filemarks", "Space", "Inquiry",  
  34. /* 13-16 */ unknown, "Recover Buffered Data", "Mode Select", "Reserve",
  35. /* 17-1b */ "Release", "Copy", "Erase", "Mode Sense", "Start/Stop Unit",
  36. /* 1c-1d */ "Receive Diagnostic", "Send Diagnostic", 
  37. /* 1e-1f */ "Prevent/Allow Medium Removal", unknown,
  38. };
  39.  
  40.  
  41. static const char *group_1_commands[] = {
  42. /* 20-22 */  unknown, unknown, unknown,
  43. /* 23-28 */ unknown, unknown, "Read Capacity", unknown, unknown, "Read (10)", 
  44. /* 29-2d */ unknown, "Write (10)", "Seek (10)", unknown, unknown, 
  45. /* 2e-31 */ "Write Verify","Verify", "Search High", "Search Equal", 
  46. /* 32-34 */ "Search Low", "Set Limits", "Prefetch or Read Position", 
  47. /* 35-37 */ "Synchronize Cache","Lock/Unlock Cache", "Read Defect Data", 
  48. /* 38-3c */ unknown, "Compare","Copy Verify", "Write Buffer", "Read Buffer", 
  49. /* 3d-39 */ unknown, "Read Long",  unknown,
  50. };
  51.  
  52.  
  53. static const char *group_2_commands[] = {
  54. /* 40-41 */ "Change Definition", unknown, 
  55. /* 42-48 */ unknown, unknown, unknown, unknown, unknown, unknown, unknown,
  56. /* 49-4f */ unknown, unknown, unknown, "Log Select", "Log Sense", unknown,
  57. /* 50-55 */ unknown, unknown, unknown, unknown, unknown, "Mode Select (10)",
  58. /* 56-5b */ unknown, unknown, unknown, unknown, "Mode Sense (10)", unknown,
  59. /* 5c-5f */ unknown, unknown, unknown,
  60. };
  61.  
  62.  
  63.  
  64. #define group(opcode) (((opcode) >> 5) & 7)
  65.  
  66. #define RESERVED_GROUP  0
  67. #define VENDOR_GROUP     1
  68. #define NOTEXT_GROUP    2
  69.  
  70. static const char **commands[] = {
  71. group_0_commands, group_1_commands, group_2_commands, 
  72. (const char **) RESERVED_GROUP, (const char **) RESERVED_GROUP, 
  73. (const char **) NOTEXT_GROUP, (const char **) VENDOR_GROUP, 
  74. (const char **) VENDOR_GROUP};
  75.  
  76. static const char reserved[] = "RESERVED";
  77. static const char vendor[] = "VENDOR SPECIFIC";
  78.  
  79. static void print_opcode(int opcode) {
  80.   const char **table = commands[ group(opcode) ];
  81.   switch ((unsigned long) table) {
  82.   case RESERVED_GROUP:
  83.       printk("%s(0x%02x) ", reserved, opcode); 
  84.       break;
  85.   case NOTEXT_GROUP:
  86.       printk("%s(0x%02x) ", unknown, opcode); 
  87.       break;
  88.   case VENDOR_GROUP:
  89.       printk("%s(0x%02x) ", vendor, opcode); 
  90.       break;
  91.   default:
  92.       printk("%s ",table[opcode & 0x1f]);
  93.   }
  94. }
  95. #else /* CONST & CONST_COMMAND */
  96. static void print_opcode(int opcode) {
  97.   printk("0x%02x ", opcode);
  98. }
  99. #endif  
  100.  
  101. void print_command (unsigned char *command) {
  102.   int i,s;
  103.   print_opcode(command[0]);
  104.   for ( i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i) 
  105.       printk("%02x ", command[i]);
  106.   printk("\n");
  107. }
  108.  
  109. #if (CONSTANTS & CONST_STATUS)
  110. static const char * statuses[] = {
  111. /* 0-4 */ "Good", "Check Condition", "Condition Good", unknown, "Busy", 
  112. /* 5-9 */ unknown, unknown, unknown, "Intermediate Good", unknown, 
  113. /* a-d */ "Intermediate Good", unknown, "Reservation Conflict", unknown,
  114. /* e-f */ unknown, unknown,
  115. };
  116. #endif
  117.  
  118. void print_status (int status) {
  119.   status = (status >> 1) & 0xf;
  120. #if (CONSTANTS & CONST_STATUS)
  121.   printk("%s ",statuses[status]);
  122. #else
  123.   printk("0x%0x ", status); 
  124. #endif 
  125. }
  126.  
  127. #if (CONSTANTS & CONST_XSENSE)
  128. #define D 0x001  /* DIRECT ACCESS DEVICE (disk) */
  129. #define T 0x002  /* SEQUENTIAL ACCESS DEVICE (tape) */
  130. #define L 0x004  /* PRINTER DEVICE */
  131. #define P 0x008  /* PROCESSOR DEVICE */
  132. #define W 0x010  /* WRITE ONCE READ MULTIPLE DEVICE */
  133. #define R 0x020  /* READ ONLY (CD-ROM) DEVICE */
  134. #define S 0x040  /* SCANNER DEVICE */
  135. #define O 0x080  /* OPTICAL MEMORY DEVICE */
  136. #define M 0x100  /* MEDIA CHANGER DEVICE */
  137. #define C 0x200  /* COMMUNICATION DEVICE */
  138.  
  139. struct error_info{
  140.   unsigned char code1, code2;
  141.   unsigned short int devices;
  142.   char * text;
  143. };
  144.  
  145. struct error_info2{
  146.   unsigned char code1, code2_min, code2_max;
  147.   unsigned short int devices;
  148.   char * text;
  149. };
  150.  
  151. static struct error_info2 additional2[] =
  152. {
  153.   {0x40,0x00,0x7f,D,"Ram failure (%x)"},
  154.   {0x40,0x80,0xff,D|T|L|P|W|R|S|O|M|C,"Diagnostic failure on component (%x)"},
  155.   {0x41,0x00,0xff,D,"Data path failure (%x)"},
  156.   {0x42,0x00,0xff,D,"Power-on or self-test failure (%x)"},
  157.   {0, 0, 0, 0, NULL}
  158. };
  159.  
  160. static struct error_info additional[] =
  161. {
  162.   {0x00,0x01,T,"Filemark detected"},
  163.   {0x00,0x02,T|S,"End-of-partition/medium detected"},
  164.   {0x00,0x03,T,"Setmark detected"},
  165.   {0x00,0x04,T|S,"Beginning-of-partition/medium detected"},
  166.   {0x00,0x05,T|S,"End-of-data detected"},
  167.   {0x00,0x06,D|T|L|P|W|R|S|O|M|C,"I/O process terminated"},
  168.   {0x00,0x11,R,"Audio play operation in progress"},
  169.   {0x00,0x12,R,"Audio play operation paused"},
  170.   {0x00,0x13,R,"Audio play operation successfully completed"},
  171.   {0x00,0x14,R,"Audio play operation stopped due to error"},
  172.   {0x00,0x15,R,"No current audio status to return"},
  173.   {0x01,0x00,D|W|O,"No index/sector signal"},
  174.   {0x02,0x00,D|W|R|O|M,"No seek complete"},
  175.   {0x03,0x00,D|T|L|W|S|O,"Peripheral device write fault"},
  176.   {0x03,0x01,T,"No write current"},
  177.   {0x03,0x02,T,"Excessive write errors"},
  178.   {0x04,0x00,D|T|L|P|W|R|S|O|M|C,
  179.      "Logical unit not ready, cause not reportable"},
  180.   {0x04,0x01,D|T|L|P|W|R|S|O|M|C,
  181.      "Logical unit is in process of becoming ready"},
  182.   {0x04,0x02,D|T|L|P|W|R|S|O|M|C,
  183.      "Logical unit not ready, initializing command required"},
  184.   {0x04,0x03,D|T|L|P|W|R|S|O|M|C,
  185.      "Logical unit not ready, manual intervention required"},
  186.   {0x04,0x04,D|T|L|O,"Logical unit not ready, format in progress"},
  187.   {0x05,0x00,D|T|L|W|R|S|O|M|C,"Logical unit does not respond to selection"},
  188.   {0x06,0x00,D|W|R|O|M,"No reference position found"},
  189.   {0x07,0x00,D|T|L|W|R|S|O|M,"Multiple peripheral devices selected"},
  190.   {0x08,0x00,D|T|L|W|R|S|O|M|C,"Logical unit communication failure"},
  191.   {0x08,0x01,D|T|L|W|R|S|O|M|C,"Logical unit communication time-out"},
  192.   {0x08,0x02,D|T|L|W|R|S|O|M|C,"Logical unit communication parity error"},
  193.   {0x09,0x00,D|T|W|R|O,"Track following error"},
  194.   {0x09,0x01,W|R|O,"Tracking servo failure"},
  195.   {0x09,0x02,W|R|O,"Focus servo failure"},
  196.   {0x09,0x03,W|R|O,"Spindle servo failure"},
  197.   {0x0A,0x00,D|T|L|P|W|R|S|O|M|C,"Error log overflow"},
  198.   {0x0C,0x00,T|S,"Write error"},
  199.   {0x0C,0x01,D|W|O,"Write error recovered with auto reallocation"},
  200.   {0x0C,0x02,D|W|O,"Write error - auto reallocation failed"},
  201.   {0x10,0x00,D|W|O,"Id crc or ecc error"},
  202.   {0x11,0x00,D|T|W|R|S|O,"Unrecovered read error"},
  203.   {0x11,0x01,D|T|W|S|O,"Read retries exhausted"},
  204.   {0x11,0x02,D|T|W|S|O,"Error too long to correct"},
  205.   {0x11,0x03,D|T|W|S|O,"Multiple read errors"},
  206.   {0x11,0x04,D|W|O,"Unrecovered read error - auto reallocate failed"},
  207.   {0x11,0x05,W|R|O,"L-ec uncorrectable error"},
  208.   {0x11,0x06,W|R|O,"Circ unrecovered error"},
  209.   {0x11,0x07,W|O,"Data resynchronization error"},
  210.   {0x11,0x08,T,"Incomplete block read"},
  211.   {0x11,0x09,T,"No gap found"},
  212.   {0x11,0x0A,D|T|O,"Miscorrected error"},
  213.   {0x11,0x0B,D|W|O,"Unrecovered read error - recommend reassignment"},
  214.   {0x11,0x0C,D|W|O,"Unrecovered read error - recommend rewrite the data"},
  215.   {0x12,0x00,D|W|O,"Address mark not found for id field"},
  216.   {0x13,0x00,D|W|O,"Address mark not found for data field"},
  217.   {0x14,0x00,D|T|L|W|R|S|O,"Recorded entity not found"},
  218.   {0x14,0x01,D|T|W|R|O,"Record not found"},
  219.   {0x14,0x02,T,"Filemark or setmark not found"},
  220.   {0x14,0x03,T,"End-of-data not found"},
  221.   {0x14,0x04,T,"Block sequence error"},
  222.   {0x15,0x00,D|T|L|W|R|S|O|M,"Random positioning error"},
  223.   {0x15,0x01,D|T|L|W|R|S|O|M,"Mechanical positioning error"},
  224.   {0x15,0x02,D|T|W|R|O,"Positioning error detected by read of medium"},
  225.   {0x16,0x00,D|W|O,"Data synchronization mark error"},
  226.   {0x17,0x00,D|T|W|R|S|O,"Recovered data with no error correction applied"},
  227.   {0x17,0x01,D|T|W|R|S|O,"Recovered data with retries"},
  228.   {0x17,0x02,D|T|W|R|O,"Recovered data with positive head offset"},
  229.   {0x17,0x03,D|T|W|R|O,"Recovered data with negative head offset"},
  230.   {0x17,0x04,W|R|O,"Recovered data with retries and/or circ applied"},
  231.   {0x17,0x05,D|W|R|O,"Recovered data using previous sector id"},
  232.   {0x17,0x06,D|W|O,"Recovered data without ecc - data auto-reallocated"},
  233.   {0x17,0x07,D|W|O,"Recovered data without ecc - recommend reassignment"},
  234.   {0x18,0x00,D|T|W|R|O,"Recovered data with error correction applied"},
  235.   {0x18,0x01,D|W|R|O,"Recovered data with error correction and retries applied"},
  236.   {0x18,0x02,D|W|R|O,"Recovered data - data auto-reallocated"},
  237.   {0x18,0x03,R,"Recovered data with circ"},
  238.   {0x18,0x04,R,"Recovered data with lec"},
  239.   {0x18,0x05,D|W|R|O,"Recovered data - recommend reassignment"},
  240.   {0x19,0x00,D|O,"Defect list error"},
  241.   {0x19,0x01,D|O,"Defect list not available"},
  242.   {0x19,0x02,D|O,"Defect list error in primary list"},
  243.   {0x19,0x03,D|O,"Defect list error in grown list"},
  244.   {0x1A,0x00,D|T|L|P|W|R|S|O|M|C,"Parameter list length error"},
  245.   {0x1B,0x00,D|T|L|P|W|R|S|O|M|C,"Synchronous data transfer error"},
  246.   {0x1C,0x00,D|O,"Defect list not found"},
  247.   {0x1C,0x01,D|O,"Primary defect list not found"},
  248.   {0x1C,0x02,D|O,"Grown defect list not found"},
  249.   {0x1D,0x00,D|W|O,"Miscompare during verify operation"},
  250.   {0x1E,0x00,D|W|O,"Recovered id with ecc correction"},
  251.   {0x20,0x00,D|T|L|P|W|R|S|O|M|C,"Invalid command operation code"},
  252.   {0x21,0x00,D|T|W|R|O|M,"Logical block address out of range"},
  253.   {0x21,0x01,M,"Invalid element address"},
  254.   {0x22,0x00,D,"Illegal function (should use 20 00, 24 00, or 26 00)"},
  255.   {0x24,0x00,D|T|L|P|W|R|S|O|M|C,"Invalid field in cdb"},
  256.   {0x25,0x00,D|T|L|P|W|R|S|O|M|C,"Logical unit not supported"},
  257.   {0x26,0x00,D|T|L|P|W|R|S|O|M|C,"Invalid field in parameter list"},
  258.   {0x26,0x01,D|T|L|P|W|R|S|O|M|C,"Parameter not supported"},
  259.   {0x26,0x02,D|T|L|P|W|R|S|O|M|C,"Parameter value invalid"},
  260.   {0x26,0x03,D|T|L|P|W|R|S|O|M|C,"Threshold parameters not supported"},
  261.   {0x27,0x00,D|T|W|O,"Write protected"},
  262.   {0x28,0x00,D|T|L|P|W|R|S|O|M|C,"Not ready to ready transition (medium may have changed)"},
  263.   {0x28,0x01,M,"Import or export element accessed"},
  264.   {0x29,0x00,D|T|L|P|W|R|S|O|M|C,"Power on, reset, or bus device reset occurred"},
  265.   {0x2A,0x00,D|T|L|W|R|S|O|M|C,"Parameters changed"},
  266.   {0x2A,0x01,D|T|L|W|R|S|O|M|C,"Mode parameters changed"},
  267.   {0x2A,0x02,D|T|L|W|R|S|O|M|C,"Log parameters changed"},
  268.   {0x2B,0x00,D|T|L|P|W|R|S|O|C,"Copy cannot execute since host cannot disconnect"},
  269.   {0x2C,0x00,D|T|L|P|W|R|S|O|M|C,"Command sequence error"},
  270.   {0x2C,0x01,S,"Too many windows specified"},
  271.   {0x2C,0x02,S,"Invalid combination of windows specified"},
  272.   {0x2D,0x00,T,"Overwrite error on update in place"},
  273.   {0x2F,0x00,D|T|L|P|W|R|S|O|M|C,"Commands cleared by another initiator"},
  274.   {0x30,0x00,D|T|W|R|O|M,"Incompatible medium installed"},
  275.   {0x30,0x01,D|T|W|R|O,"Cannot read medium - unknown format"},
  276.   {0x30,0x02,D|T|W|R|O,"Cannot read medium - incompatible format"},
  277.   {0x30,0x03,D|T,"Cleaning cartridge installed"},
  278.   {0x31,0x00,D|T|W|O,"Medium format corrupted"},
  279.   {0x31,0x01,D|L|O,"Format command failed"},
  280.   {0x32,0x00,D|W|O,"No defect spare location available"},
  281.   {0x32,0x01,D|W|O,"Defect list update failure"},
  282.   {0x33,0x00,T,"Tape length error"},
  283.   {0x36,0x00,L,"Ribbon, ink, or toner failure"},
  284.   {0x37,0x00,D|T|L|W|R|S|O|M|C,"Rounded parameter"},
  285.   {0x39,0x00,D|T|L|W|R|S|O|M|C,"Saving parameters not supported"},
  286.   {0x3A,0x00,D|T|L|W|R|S|O|M,"Medium not present"},
  287.   {0x3B,0x00,T|L,"Sequential positioning error"},
  288.   {0x3B,0x01,T,"Tape position error at beginning-of-medium"},
  289.   {0x3B,0x02,T,"Tape position error at end-of-medium"},
  290.   {0x3B,0x03,L,"Tape or electronic vertical forms unit not ready"},
  291.   {0x3B,0x04,L,"Slew failure"},
  292.   {0x3B,0x05,L,"Paper jam"},
  293.   {0x3B,0x06,L,"Failed to sense top-of-form"},
  294.   {0x3B,0x07,L,"Failed to sense bottom-of-form"},
  295.   {0x3B,0x08,T,"Reposition error"},
  296.   {0x3B,0x09,S,"Read past end of medium"},
  297.   {0x3B,0x0A,S,"Read past beginning of medium"},
  298.   {0x3B,0x0B,S,"Position past end of medium"},
  299.   {0x3B,0x0C,S,"Position past beginning of medium"},
  300.   {0x3B,0x0D,M,"Medium destination element full"},
  301.   {0x3B,0x0E,M,"Medium source element empty"},
  302.   {0x3D,0x00,D|T|L|P|W|R|S|O|M|C,"Invalid bits in identify message"},
  303.   {0x3E,0x00,D|T|L|P|W|R|S|O|M|C,"Logical unit has not self-configured yet"},
  304.   {0x3F,0x00,D|T|L|P|W|R|S|O|M|C,"Target operating conditions have changed"},
  305.   {0x3F,0x01,D|T|L|P|W|R|S|O|M|C,"Microcode has been changed"},
  306.   {0x3F,0x02,D|T|L|P|W|R|S|O|M|C,"Changed operating definition"},
  307.   {0x3F,0x03,D|T|L|P|W|R|S|O|M|C,"Inquiry data has changed"},
  308.   {0x43,0x00,D|T|L|P|W|R|S|O|M|C,"Message error"},
  309.   {0x44,0x00,D|T|L|P|W|R|S|O|M|C,"Internal target failure"},
  310.   {0x45,0x00,D|T|L|P|W|R|S|O|M|C,"Select or reselect failure"},
  311.   {0x46,0x00,D|T|L|P|W|R|S|O|M|C,"Unsuccessful soft reset"},
  312.   {0x47,0x00,D|T|L|P|W|R|S|O|M|C,"Scsi parity error"},
  313.   {0x48,0x00,D|T|L|P|W|R|S|O|M|C,"Initiator detected error message received"},
  314.   {0x49,0x00,D|T|L|P|W|R|S|O|M|C,"Invalid message error"},
  315.   {0x4A,0x00,D|T|L|P|W|R|S|O|M|C,"Command phase error"},
  316.   {0x4B,0x00,D|T|L|P|W|R|S|O|M|C,"Data phase error"},
  317.   {0x4C,0x00,D|T|L|P|W|R|S|O|M|C,"Logical unit failed self-configuration"},
  318.   {0x4E,0x00,D|T|L|P|W|R|S|O|M|C,"Overlapped commands attempted"},
  319.   {0x50,0x00,T,"Write append error"},
  320.   {0x50,0x01,T,"Write append position error"},
  321.   {0x50,0x02,T,"Position error related to timing"},
  322.   {0x51,0x00,T|O,"Erase failure"},
  323.   {0x52,0x00,T,"Cartridge fault"},
  324.   {0x53,0x00,D|T|L|W|R|S|O|M,"Media load or eject failed"},
  325.   {0x53,0x01,T,"Unload tape failure"},
  326.   {0x53,0x02,D|T|W|R|O|M,"Medium removal prevented"},
  327.   {0x54,0x00,P,"Scsi to host system interface failure"},
  328.   {0x55,0x00,P,"System resource failure"},
  329.   {0x57,0x00,R,"Unable to recover table-of-contents"},
  330.   {0x58,0x00,O,"Generation does not exist"},
  331.   {0x59,0x00,O,"Updated block read"},
  332.   {0x5A,0x00,D|T|L|P|W|R|S|O|M,"Operator request or state change input (unspecified)"},
  333.   {0x5A,0x01,D|T|W|R|O|M,"Operator medium removal request"},
  334.   {0x5A,0x02,D|T|W|O,"Operator selected write protect"},
  335.   {0x5A,0x03,D|T|W|O,"Operator selected write permit"},
  336.   {0x5B,0x00,D|T|L|P|W|R|S|O|M,"Log exception"},
  337.   {0x5B,0x01,D|T|L|P|W|R|S|O|M,"Threshold condition met"},
  338.   {0x5B,0x02,D|T|L|P|W|R|S|O|M,"Log counter at maximum"},
  339.   {0x5B,0x03,D|T|L|P|W|R|S|O|M,"Log list codes exhausted"},
  340.   {0x5C,0x00,D|O,"Rpl status change"},
  341.   {0x5C,0x01,D|O,"Spindles synchronized"},
  342.   {0x5C,0x02,D|O,"Spindles not synchronized"},
  343.   {0x60,0x00,S,"Lamp failure"},
  344.   {0x61,0x00,S,"Video acquisition error"},
  345.   {0x61,0x01,S,"Unable to acquire video"},
  346.   {0x61,0x02,S,"Out of focus"},
  347.   {0x62,0x00,S,"Scan head positioning error"},
  348.   {0x63,0x00,R,"End of user area encountered on this track"},
  349.   {0x64,0x00,R,"Illegal mode for this track"},
  350.   {0, 0, 0, NULL}
  351. };
  352. #endif
  353.  
  354. #if (CONSTANTS & CONST_SENSE)
  355. static char *snstext[] = {
  356.     "None","Recovered Error","Not Ready","Medium Error","Hardware Error",
  357.     "Illegal Request","Unit Attention","Data Protect","Blank Check",
  358.     "Key=9","Copy Aborted","Aborted Command","End-Of-Medium",
  359.     "Volume Overflow", "Miscompare", "Key=15"};
  360. #endif
  361.  
  362.  
  363. /* Print sense information */
  364. void print_sense(char * devclass, Scsi_Cmnd * SCpnt)
  365. {
  366.     int i, s;
  367.     int sense_class, valid, code;
  368.     unsigned char * sense_buffer = SCpnt->sense_buffer;
  369.     char * error = NULL;
  370.     int dev = SCpnt->request.dev;
  371.  
  372.     sense_class = (sense_buffer[0] >> 4) & 0x07;
  373.     code = sense_buffer[0] & 0xf;
  374.     valid = sense_buffer[0] & 0x80;
  375.  
  376.     if (sense_class == 7) { 
  377.       s = sense_buffer[7] + 8;
  378.       if(s > sizeof(SCpnt->sense_buffer)) s = sizeof(SCpnt->sense_buffer);
  379.  
  380.       if (!valid)
  381.         printk("extra data not valid ");
  382.       
  383.       if (sense_buffer[2] & 0x80) printk( "FMK ");
  384.       if (sense_buffer[2] & 0x40) printk( "EOM ");
  385.       if (sense_buffer[2] & 0x20) printk( "ILI ");
  386.  
  387.       switch (code) {
  388.       case 0x0:
  389.         error = "Current";
  390.         break;
  391.       case 0x1:
  392.         error = "Deferred";
  393.         break;
  394.       default:
  395.         error = "Invalid";
  396.       }
  397.       
  398.       printk("%s error ", error);
  399.       
  400. #if (CONSTANTS & CONST_SENSE)
  401.       printk( "%s%x: sense key %s\n", devclass, dev, snstext[sense_buffer[2] & 0x0f]);
  402. #else
  403.       printk("%s%x: sns = %2x %2x\n", devclass, dev, sense_buffer[0], sense_buffer[2]);
  404. #endif
  405.     
  406.     /* Check to see if additional sense information is available */
  407.     if(sense_buffer[7] + 7 < 13 ||
  408.        (sense_buffer[12] == 0  && sense_buffer[13] ==  0)) goto done;
  409.     
  410. #if (CONSTANTS & CONST_XSENSE)
  411.     for(i=0; additional[i].text; i++)
  412.         if(additional[i].code1 == sense_buffer[12] &&
  413.            additional[i].code2 == sense_buffer[13])
  414.             printk("Additional sense indicates %s\n", additional[i].text);
  415.     
  416.     for(i=0; additional2[i].text; i++)
  417.         if(additional2[i].code1 == sense_buffer[12] &&
  418.            additional2[i].code2_min >= sense_buffer[13]  &&
  419.            additional2[i].code2_max <= sense_buffer[13]) {
  420.             printk("Additional sense indicates ");
  421.             printk(additional2[i].text, sense_buffer[13]);
  422.             printk("\n");
  423.         };
  424. #else
  425.     printk("ASC=%2x ASCQ=%2x\n", sense_buffer[12], sense_buffer[13]);
  426. #endif
  427.     } else { 
  428.  
  429. #if (CONSTANTS & CONST_SENSE)
  430.       if (sense_buffer[0] < 15)
  431.         printk("%s%x: old sense key %s\n", devclass, dev, snstext[sense_buffer[0] & 0x0f]);
  432.       else
  433. #endif
  434.         printk("%s%x: sns = %2x %2x\n", devclass, dev, sense_buffer[0], sense_buffer[2]);
  435.  
  436.       printk("Non-extended sense class %d code 0x%0x ", sense_class, code);
  437.       s = 4;
  438.     }
  439.     
  440.       done:
  441. #if !(CONSTANTS & CONST_SENSE)
  442.     printk("Raw sense data:");
  443.     for (i = 0; i < s; ++i) 
  444.       printk("0x%02x ", sense_buffer[i]);
  445.     printk("\n");
  446. #endif
  447.     return;
  448. }
  449.  
  450. #if (CONSTANTS & CONST_MSG) 
  451. static const char *one_byte_msgs[] = {
  452. /* 0x00 */ "Command Complete", NULL, "Save Pointers",
  453. /* 0x03 */ "Restore Pointers", "Disconnect", "Initiator Error", 
  454. /* 0x06 */ "Abort", "Message Reject", "Nop", "Message Parity Error",
  455. /* 0x0a */ "Linked Command Complete", "Linked Command Complete w/flag",
  456. /* 0x0c */ "Bus device reset", "Abort Tag", "Clear Queue", 
  457. /* 0x0f */ "Initiate Recovery", "Release Recovery"
  458. };
  459.  
  460. #define NO_ONE_BYTE_MSGS (sizeof(one_byte_msgs)  / sizeof (const char *))
  461.  
  462. static const char *two_byte_msgs[] = {
  463. /* 0x20 */ "Simple Queue Tag", "Head of Queue Tag", "Ordered Queue Tag"
  464. /* 0x23 */ "Ignore Wide Residue"
  465. };
  466.  
  467. #define NO_TWO_BYTE_MSGS (sizeof(two_byte_msgs)  / sizeof (const char *))
  468.  
  469. static const char *extended_msgs[] = {
  470. /* 0x00 */ "Modify Data Pointer", "Synchronous Data Transfer Request",
  471. /* 0x02 */ "SCSI-I Extended Identify", "Wide Data Transfer Request"
  472. };
  473.  
  474. #define NO_EXTENDED_MSGS (sizeof(two_byte_msgs)  / sizeof (const char *))
  475. #endif /* (CONSTANTS & CONST_MSG) */
  476.  
  477. int print_msg (const unsigned char *msg) {
  478.     int len = 0, i;
  479.     if (msg[0] == EXTENDED_MESSAGE) {
  480.     len = 3 + msg[1];
  481. #if (CONSTANTS & CONST_MSG)
  482.     if (msg[2] < NO_EXTENDED_MSGS)
  483.         printk ("%s ", extended_msgs[msg[2]]); 
  484.     else 
  485.         printk ("Extended Message, reserved code (0x%02x) ", (int) msg[2]);
  486.     switch (msg[2]) {
  487.     case EXTENDED_MODIFY_DATA_POINTER:
  488.         printk("pointer = %d", (int) (msg[3] << 24) | (msg[4] << 16) | 
  489.         (msg[5] << 8) | msg[6]);
  490.         break;
  491.     case EXTENDED_SDTR:
  492.         printk("period = %d ns, offset = %d", (int) msg[3] * 4, (int) 
  493.         msg[4]);
  494.         break;
  495.     case EXTENDED_WDTR:
  496.         printk("width = 2^%d bytes", msg[3]);
  497.         break;
  498.     default:
  499.         for (i = 2; i < len; ++i) 
  500.         printk("%02x ", msg[i]);
  501.     }
  502. #else
  503.     for (i = 0; i < len; ++i)
  504.         printk("%02x ", msg[i]);
  505. #endif
  506.     /* Identify */
  507.     } else if (msg[0] & 0x80) {
  508. #if (CONSTANTS & CONST_MSG)
  509.     printk("Identify disconnect %sallowed %s %d ",
  510.         (msg[0] & 0x40) ? "" : "not ",
  511.         (msg[0] & 0x20) ? "target routine" : "lun",
  512.         msg[0] & 0x7);
  513. #else
  514.     printk("%02x ", msg[0]);
  515. #endif
  516.     len = 1;
  517.     /* Normal One byte */
  518.     } else if (msg[0] < 0x1f) {
  519. #if (CONSTANTS & CONST_MSG)
  520.     if (msg[0] < NO_ONE_BYTE_MSGS)
  521.         printk(one_byte_msgs[msg[0]]);
  522.     else
  523.         printk("reserved (%02x) ", msg[0]);
  524. #else
  525.     printk("%02x ", msg[0]);
  526. #endif
  527.     len = 1;
  528.     /* Two byte */
  529.     } else if (msg[0] <= 0x2f) {
  530. #if (CONSTANTS & CONST_MSG)
  531.     if ((msg[0] - 0x20) < NO_TWO_BYTE_MSGS)
  532.         printk("%s %02x ", two_byte_msgs[msg[0] - 0x20], 
  533.         msg[1]);
  534.     else 
  535.         printk("reserved two byte (%02x %02x) ", 
  536.         msg[0], msg[1]);
  537. #else
  538.     printk("%02x %02x", msg[0], msg[1]);
  539. #endif
  540.     len = 2;
  541.     } else 
  542. #if (CONSTANTS & CONST_MSG)
  543.     printk(reserved);
  544. #else
  545.     printk("%02x ", msg[0]);
  546. #endif
  547.     return len;
  548. }
  549.  
  550. void print_Scsi_Cmnd (Scsi_Cmnd *cmd) {
  551.     printk("scsi%d : destination target %d, lun %d\n", 
  552.     cmd->host->host_no, 
  553.     cmd->target, 
  554.     cmd->lun);
  555.     printk("        command = ");
  556.     print_command (cmd->cmnd);
  557. }
  558.