nsp_debug.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*========================================================================
  2. Debug routines for nsp_cs
  3. By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
  4. This software may be used and distributed according to the terms of
  5. the GNU General Public License.
  6. =========================================================================*/
  7. /* $Id: nsp_debug.c,v 1.3 2003/07/26 14:21:09 elca Exp $ */
  8. /*
  9. * Show the command data of a command
  10. */
  11. static const char unknown[] = "UNKNOWN";
  12. static const char * group_0_commands[] = {
  13. /* 00-03 */ "Test Unit Ready", "Rezero Unit", unknown, "Request Sense",
  14. /* 04-07 */ "Format Unit", "Read Block Limits", unknown, "Reassign Blocks",
  15. /* 08-0d */ "Read (6)", unknown, "Write (6)", "Seek (6)", unknown, unknown,
  16. /* 0e-12 */ unknown, "Read Reverse", "Write Filemarks", "Space", "Inquiry",
  17. /* 13-16 */ unknown, "Recover Buffered Data", "Mode Select", "Reserve",
  18. /* 17-1b */ "Release", "Copy", "Erase", "Mode Sense", "Start/Stop Unit",
  19. /* 1c-1d */ "Receive Diagnostic", "Send Diagnostic",
  20. /* 1e-1f */ "Prevent/Allow Medium Removal", unknown,
  21. };
  22. static const char *group_1_commands[] = {
  23. /* 20-22 */ unknown, unknown, unknown,
  24. /* 23-28 */ unknown, unknown, "Read Capacity", unknown, unknown, "Read (10)",
  25. /* 29-2d */ unknown, "Write (10)", "Seek (10)", unknown, unknown,
  26. /* 2e-31 */ "Write Verify","Verify", "Search High", "Search Equal",
  27. /* 32-34 */ "Search Low", "Set Limits", "Prefetch or Read Position",
  28. /* 35-37 */ "Synchronize Cache","Lock/Unlock Cache", "Read Defect Data",
  29. /* 38-3c */ "Medium Scan", "Compare","Copy Verify", "Write Buffer", "Read Buffer",
  30. /* 3d-3f */ "Update Block", "Read Long", "Write Long",
  31. };
  32. static const char *group_2_commands[] = {
  33. /* 40-41 */ "Change Definition", "Write Same",
  34. /* 42-48 */ "Read Sub-Ch(cd)", "Read TOC", "Read Header(cd)", "Play Audio(cd)", unknown, "Play Audio MSF(cd)", "Play Audio Track/Index(cd)",
  35. /* 49-4f */ "Play Track Relative(10)(cd)", unknown, "Pause/Resume(cd)", "Log Select", "Log Sense", unknown, unknown,
  36. /* 50-55 */ unknown, unknown, unknown, unknown, unknown, "Mode Select (10)",
  37. /* 56-5b */ unknown, unknown, unknown, unknown, "Mode Sense (10)", unknown,
  38. /* 5c-5f */ unknown, unknown, unknown,
  39. };
  40. #define group(opcode) (((opcode) >> 5) & 7)
  41. #define RESERVED_GROUP 0
  42. #define VENDOR_GROUP 1
  43. #define NOTEXT_GROUP 2
  44. static const char **commands[] = {
  45. group_0_commands, group_1_commands, group_2_commands,
  46. (const char **) RESERVED_GROUP, (const char **) RESERVED_GROUP,
  47. (const char **) NOTEXT_GROUP, (const char **) VENDOR_GROUP,
  48. (const char **) VENDOR_GROUP
  49. };
  50. static const char reserved[] = "RESERVED";
  51. static const char vendor[] = "VENDOR SPECIFIC";
  52. static void print_opcodek(unsigned char opcode)
  53. {
  54. const char **table = commands[ group(opcode) ];
  55. switch ((unsigned long) table) {
  56. case RESERVED_GROUP:
  57. printk("%s[%02x] ", reserved, opcode);
  58. break;
  59. case NOTEXT_GROUP:
  60. printk("%s(notext)[%02x] ", unknown, opcode);
  61. break;
  62. case VENDOR_GROUP:
  63. printk("%s[%02x] ", vendor, opcode);
  64. break;
  65. default:
  66. if (table[opcode & 0x1f] != unknown)
  67. printk("%s[%02x] ", table[opcode & 0x1f], opcode);
  68. else
  69. printk("%s[%02x] ", unknown, opcode);
  70. break;
  71. }
  72. }
  73. static void print_commandk (unsigned char *command)
  74. {
  75. int i, s;
  76. printk(KERN_DEBUG);
  77. print_opcodek(command[0]);
  78. /*printk(KERN_DEBUG "%s ", __func__);*/
  79. if ((command[0] >> 5) == 6 ||
  80. (command[0] >> 5) == 7 ) {
  81. s = 12; /* vender specific */
  82. } else {
  83. s = COMMAND_SIZE(command[0]);
  84. }
  85. for ( i = 1; i < s; ++i) {
  86. printk("%02x ", command[i]);
  87. }
  88. switch (s) {
  89. case 6:
  90. printk("LBA=%d len=%d",
  91. (((unsigned int)command[1] & 0x0f) << 16) |
  92. ( (unsigned int)command[2] << 8) |
  93. ( (unsigned int)command[3] ),
  94. (unsigned int)command[4]
  95. );
  96. break;
  97. case 10:
  98. printk("LBA=%d len=%d",
  99. ((unsigned int)command[2] << 24) |
  100. ((unsigned int)command[3] << 16) |
  101. ((unsigned int)command[4] << 8) |
  102. ((unsigned int)command[5] ),
  103. ((unsigned int)command[7] << 8) |
  104. ((unsigned int)command[8] )
  105. );
  106. break;
  107. case 12:
  108. printk("LBA=%d len=%d",
  109. ((unsigned int)command[2] << 24) |
  110. ((unsigned int)command[3] << 16) |
  111. ((unsigned int)command[4] << 8) |
  112. ((unsigned int)command[5] ),
  113. ((unsigned int)command[6] << 24) |
  114. ((unsigned int)command[7] << 16) |
  115. ((unsigned int)command[8] << 8) |
  116. ((unsigned int)command[9] )
  117. );
  118. break;
  119. default:
  120. break;
  121. }
  122. printk("\n");
  123. }
  124. static void show_command(struct scsi_cmnd *SCpnt)
  125. {
  126. print_commandk(SCpnt->cmnd);
  127. }
  128. static void show_phase(struct scsi_cmnd *SCpnt)
  129. {
  130. int i = SCpnt->SCp.phase;
  131. char *ph[] = {
  132. "PH_UNDETERMINED",
  133. "PH_ARBSTART",
  134. "PH_SELSTART",
  135. "PH_SELECTED",
  136. "PH_COMMAND",
  137. "PH_DATA",
  138. "PH_STATUS",
  139. "PH_MSG_IN",
  140. "PH_MSG_OUT",
  141. "PH_DISCONNECT",
  142. "PH_RESELECT"
  143. };
  144. if ( i < PH_UNDETERMINED || i > PH_RESELECT ) {
  145. printk(KERN_DEBUG "scsi phase: unknown(%d)\n", i);
  146. return;
  147. }
  148. printk(KERN_DEBUG "scsi phase: %s\n", ph[i]);
  149. return;
  150. }
  151. static void show_busphase(unsigned char stat)
  152. {
  153. switch(stat) {
  154. case BUSPHASE_COMMAND:
  155. printk(KERN_DEBUG "BUSPHASE_COMMAND\n");
  156. break;
  157. case BUSPHASE_MESSAGE_IN:
  158. printk(KERN_DEBUG "BUSPHASE_MESSAGE_IN\n");
  159. break;
  160. case BUSPHASE_MESSAGE_OUT:
  161. printk(KERN_DEBUG "BUSPHASE_MESSAGE_OUT\n");
  162. break;
  163. case BUSPHASE_DATA_IN:
  164. printk(KERN_DEBUG "BUSPHASE_DATA_IN\n");
  165. break;
  166. case BUSPHASE_DATA_OUT:
  167. printk(KERN_DEBUG "BUSPHASE_DATA_OUT\n");
  168. break;
  169. case BUSPHASE_STATUS:
  170. printk(KERN_DEBUG "BUSPHASE_STATUS\n");
  171. break;
  172. case BUSPHASE_SELECT:
  173. printk(KERN_DEBUG "BUSPHASE_SELECT\n");
  174. break;
  175. default:
  176. printk(KERN_DEBUG "BUSPHASE_other\n");
  177. break;
  178. }
  179. }
  180. static void show_message(nsp_hw_data *data)
  181. {
  182. int i;
  183. printk(KERN_DEBUG "msg:");
  184. for(i=0; i < data->MsgLen; i++) {
  185. printk(" %02x", data->MsgBuffer[i]);
  186. }
  187. printk("\n");
  188. }
  189. /* end */