sense.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include "scsireq.h"
  5. static char* key[16] = {
  6. "no sense",
  7. "recovered error",
  8. "not ready",
  9. "medium error",
  10. "hardware error",
  11. "illegal request",
  12. "unit attention",
  13. "data protect",
  14. "blank check",
  15. "vendor specific",
  16. "copy aborted",
  17. "aborted command",
  18. "equal",
  19. "volume overflow",
  20. "miscompare",
  21. "reserved",
  22. };
  23. static struct {
  24. uchar asc;
  25. uchar ascq;
  26. char* diag;
  27. } code[] = { /* see /sys/lib/scsicodes */
  28. 0x00,0x01, "filemark detected",
  29. 0x00,0x17, "cleaning requested",
  30. 0x01,0x00, "no index/sector signal",
  31. 0x02,0x00, "no seek complete",
  32. 0x03,0x00, "peripheral device write fault",
  33. 0x04,0x00, "drive not ready",
  34. 0x04,0x01, "drive becoming ready",
  35. 0x04,0x01, "drive need initializing cmd",
  36. 0x05,0x00, "logical unit does not respond to selection",
  37. 0x08,0x00, "logical unit communication failure",
  38. 0x09,0x00, "track-following error",
  39. 0x0c,0x00, "write error",
  40. 0x0c,0x01, "write error - recovered with auto reallocation",
  41. 0x0c,0x02, "write error - auto reallocation failed",
  42. 0x0c,0x03, "write error - recommend reassignment",
  43. 0x11,0x00, "unrecovered read error",
  44. 0x15,0x00, "positioning error",
  45. 0x17,0x00, "recovered read data with retries",
  46. 0x18,0x00, "recovered read with ecc correction",
  47. 0x1A,0x00, "parameter list length error",
  48. 0x1B,0x00, "synchronous data transfer error",
  49. 0x20,0x00, "invalid command",
  50. 0x21,0x00, "invalid block address",
  51. 0x22,0x00, "illegal function (use 20 00, 24 00, or 26 00)",
  52. 0x24,0x00, "illegal field in command list",
  53. 0x25,0x00, "invalid lun",
  54. 0x26,0x00, "invalid field in parameter list",
  55. 0x27,0x00, "write protected",
  56. 0x28,0x00, "medium changed",
  57. 0x29,0x00, "power-on reset or bus reset occurred",
  58. 0x2C,0x00, "command sequence error",
  59. 0x30,0x00, "incompatible medium installed",
  60. 0x31,0x00, "medium format corrupted",
  61. 0x33,0x00, "tape length error / monitor atip error",
  62. 0x34,0x00, "enclosure failure / absorption control error",
  63. 0x3A,0x00, "medium not present",
  64. 0x3B,0x00, "sequential positioning error",
  65. 0x3B,0x01, "tape position error at beginning-of-medium",
  66. 0x3B,0x02, "tape position error at end-of-medium",
  67. 0x3B,0x08, "reposition error",
  68. 0x3B,0x09, "read past end of medium",
  69. 0x3B,0x0A, "read past beginning of medium",
  70. 0x3B,0x0B, "position past end of medium",
  71. 0x3B,0x0C, "position past beginning of medium",
  72. 0x3B,0x0D, "medium destination element full",
  73. 0x3B,0x0E, "medium source element empty",
  74. 0x3B,0x0F, "end of medium reached",
  75. 0x3B,0x16, "mechanical positioning or changer error",
  76. 0x3D,0x00, "invalid bits in identify message",
  77. 0x3E,0x00, "logical unit has not self-configured yet",
  78. 0x40,0x00, "diagnostic failure",
  79. 0x42,0x00, "power-on or self test failure",
  80. 0x44,0x00, "internal controller error",
  81. 0x47,0x00, "scsi parity error",
  82. 0x50,0x00, "write append error",
  83. 0x51,0x00, "erase failure",
  84. 0x53,0x00, "medium load or eject failed",
  85. 0x54,0x00, "scsi to host system interface failure",
  86. 0x55,0x00, "system resource failure",
  87. 0x57,0x00, "unable to read toc, pma or subcode",
  88. 0x5A,0x00, "operator medium removal request",
  89. 0x5D,0x00, "failure prediction threshold exceeded",
  90. /* cd/dvd? */
  91. 0x63,0x00, "end of user area encountered on this track",
  92. 0x64,0x00, "illegal mode for this track",
  93. 0x65,0x00, "verify failed",
  94. 0x67,0x00, "configuration failure",
  95. 0x68,0x00, "logical unit not configured",
  96. 0x69,0x00, "data loss on logical unit",
  97. 0x6f,0x01, "copy protection key exchange failure - key not present",
  98. 0x6f,0x02, "copy protection key exchange failure - key not established",
  99. 0x6f,0x03, "read of scrambled sector without authentication",
  100. 0x6f,0x04, "media region code is mismatched to logical unit region",
  101. 0x6f,0x05, "drive region must be permanent/region reset count error",
  102. 0x6f,0x00, "copy protection key exchange failure",
  103. 0x72,0x00, "session fixation error",
  104. 0x73,0x00, "cd control error",
  105. 0x74,0x00, "security error",
  106. /* vendor specific */
  107. 0x81,0x00, "illegal track",
  108. 0x82,0x00, "command now not valid",
  109. 0x83,0x00, "medium removal is prevented",
  110. 0xA0,0x00, "stopped on non-data block",
  111. 0xA1,0x00, "invalid start address",
  112. 0xA2,0x00, "attempt to cross track boundary",
  113. 0xA3,0x00, "illegal medium",
  114. 0xA4,0x00, "disc write-protected",
  115. 0xA5,0x00, "application code conflict",
  116. 0xA6,0x00, "illegal block-size for command",
  117. 0xA7,0x00, "block-size conflict",
  118. 0xA8,0x00, "illegal transfer-length",
  119. 0xA9,0x00, "request for fixation failed",
  120. 0xAA,0x00, "end of medium reached",
  121. 0xAB,0x00, "illegal track number",
  122. 0xAC,0x00, "data track length error",
  123. 0xAD,0x00, "buffer underrun",
  124. 0xAE,0x00, "illegal track mode",
  125. 0xAF,0x00, "optimum power calibration error",
  126. 0xB0,0x00, "calibration area almost full",
  127. 0xB1,0x00, "current programme area empty",
  128. 0xB2,0x00, "no efm at search address",
  129. 0xB3,0x00, "link area encountered",
  130. 0xB4,0x00, "calibration area full",
  131. 0xB5,0x00, "dummy blocks added",
  132. 0xB6,0x00, "block size format conflict",
  133. 0xB7,0x00, "current command aborted",
  134. /* cd/dvd burning? */
  135. 0xD0,0x00, "recovery needed",
  136. 0xD1,0x00, "can't recover from track",
  137. 0xD2,0x00, "can't recover from program memory area",
  138. 0xD3,0x00, "can't recover from leadin area",
  139. 0xD4,0x00, "can't recover from leadout area",
  140. 0xD5,0x00, "can't recover from optical power calibration area",
  141. 0xD6,0x00, "eeprom failure",
  142. };
  143. extern Biobuf bout;
  144. void
  145. makesense(ScsiReq *rp)
  146. {
  147. int i;
  148. Bprint(&bout, "sense data: %s", key[rp->sense[2] & 0x0F]);
  149. for(i=0; i<nelem(code); i++)
  150. if(code[i].asc == rp->sense[0x0C])
  151. if(code[i].ascq == 0 || code[i].ascq == rp->sense[0x0D])
  152. break;
  153. if(rp->sense[7] >= 5 && i < nelem(code))
  154. Bprint(&bout, ": %s", code[i].diag);
  155. Bprint(&bout, "\n\t");
  156. for(i = 0; i < 8+rp->sense[7]; i++)
  157. Bprint(&bout, " %2.2ux", rp->sense[i]);
  158. Bprint(&bout, "\n");
  159. }