sense.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include "scsireq.h"
  5. static
  6. char* key[16] =
  7. {
  8. "no sense",
  9. "recovered error",
  10. "not ready",
  11. "medium error",
  12. "hardware error",
  13. "illegal request",
  14. "unit attention",
  15. "data protect",
  16. "blank check",
  17. "vendor specific",
  18. "copy aborted",
  19. "aborted command",
  20. "equal",
  21. "volume overflow",
  22. "miscompare",
  23. "reserved",
  24. };
  25. static
  26. struct
  27. {
  28. uchar asc;
  29. uchar ascq;
  30. char* diag;
  31. } code[] =
  32. {
  33. 0x03,0x00, "tray out",
  34. 0x04,0x00, "drive not ready",
  35. 0x08,0x00, "communication failure",
  36. 0x09,0x00, "track following error",
  37. 0x11,0x00, "unrecovered read error",
  38. 0x15,0x00, "positioning error",
  39. 0x17,0x00, "recovered read data with retries",
  40. 0x18,0x00, "recovered read with ecc correction",
  41. 0x1A,0x00, "parameter list length error",
  42. 0x20,0x00, "invalid command",
  43. 0x21,0x00, "invalid block address",
  44. 0x24,0x00, "illegal field in command list",
  45. 0x25,0x00, "invalid lun",
  46. 0x26,0x00, "invalid field parameter list",
  47. 0x28,0x00, "medium changed",
  48. 0x29,0x00, "power-on reset or bus reset occurred",
  49. 0x2C,0x00, "command sequence error",
  50. 0x31,0x00, "medium format corrupted",
  51. 0x33,0x00, "monitor atip error",
  52. 0x34,0x00, "absorption control error",
  53. 0x3A,0x00, "medium not present",
  54. 0x3D,0x00, "invalid bits in identify message",
  55. 0x40,0x00, "diagnostic failure",
  56. 0x42,0x00, "power-on or self test failure",
  57. 0x44,0x00, "internal controller error",
  58. 0x47,0x00, "scsi parity error",
  59. 0x50,0x00, "write append error",
  60. 0x53,0x00, "medium load or eject failed",
  61. 0x57,0x00, "unable to read toc, pma or subcode",
  62. 0x5A,0x00, "operator medium removal request",
  63. 0x63,0x00, "end of user area encountered on this track",
  64. 0x64,0x00, "illegal mode for this track",
  65. 0x65,0x00, "verify failed",
  66. 0x6f,0x01, "copy protection key exchange failure - key not present",
  67. 0x6f,0x02, "copy protection key exchange failure - key not established",
  68. 0x6f,0x03, "read of scrambled sector without authentication",
  69. 0x6f,0x04, "media region code is mismatched to logical unit region",
  70. 0x6f,0x05, "drive region must be permanent/region reset count error",
  71. 0x6f,0x00, "copy protection key exchange failure",
  72. 0x81,0x00, "illegal track",
  73. 0x82,0x00, "command now not valid",
  74. 0x83,0x00, "medium removal is prevented",
  75. 0xA0,0x00, "stopped on non-data block",
  76. 0xA1,0x00, "invalid start address",
  77. 0xA2,0x00, "attempt to cross track boundary",
  78. 0xA3,0x00, "illegal medium",
  79. 0xA4,0x00, "disc write-protected",
  80. 0xA5,0x00, "application code conflict",
  81. 0xA6,0x00, "illegal block-size for command",
  82. 0xA7,0x00, "block-size conflict",
  83. 0xA8,0x00, "illegal transfer-length",
  84. 0xA9,0x00, "request for fixation failed",
  85. 0xAA,0x00, "end of medium reached",
  86. 0xAB,0x00, "illegal track number",
  87. 0xAC,0x00, "data track length error",
  88. 0xAD,0x00, "buffer underrun",
  89. 0xAE,0x00, "illegal track mode",
  90. 0xAF,0x00, "optimum power calibration error",
  91. 0xB0,0x00, "calibration area almost full",
  92. 0xB1,0x00, "current programme area empty",
  93. 0xB2,0x00, "no efm at search address",
  94. 0xB3,0x00, "link area encountered",
  95. 0xB4,0x00, "calibration area full",
  96. 0xB5,0x00, "dummy blocks added",
  97. 0xB6,0x00, "block size format conflict",
  98. 0xB7,0x00, "current command aborted",
  99. 0xD0,0x00, "recovery needed",
  100. 0xD1,0x00, "can't recover from track",
  101. 0xD2,0x00, "can't recover from program memory area",
  102. 0xD3,0x00, "can't recover from leadin area",
  103. 0xD4,0x00, "can't recover from leadout area",
  104. 0xD5,0x00, "can't recover from optical power calibration area",
  105. 0xD6,0x00, "eeprom failure",
  106. };
  107. extern Biobuf bout;
  108. void
  109. makesense(ScsiReq *rp)
  110. {
  111. int i;
  112. Bprint(&bout, "sense data: %s", key[rp->sense[2] & 0x0F]);
  113. for(i=0; i<nelem(code); i++)
  114. if(code[i].asc == rp->sense[0x0C])
  115. if(code[i].ascq == 0 || code[i].ascq == rp->sense[0x0D])
  116. break;
  117. if(rp->sense[7] >= 5 && i < nelem(code))
  118. Bprint(&bout, ": %s", code[i].diag);
  119. Bprint(&bout, "\n\t");
  120. for(i = 0; i < 8+rp->sense[7]; i++)
  121. Bprint(&bout, " %2.2ux", rp->sense[i]);
  122. Bprint(&bout, "\n");
  123. }