nsp_debug.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:6k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  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.8 2001/09/07 04:32:28 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, "Reasssign 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 __FUNCTION__ " ");*/
  79. for ( i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i) {
  80. printk("%02x ", command[i]);
  81. }
  82. switch (COMMAND_SIZE(command[0])) {
  83. case 6:
  84. printk("LBA=%d len=%d",
  85.        (((unsigned int)command[1] & 0x0f) << 16) |
  86.        ( (unsigned int)command[2]         <<  8) |
  87.        ( (unsigned int)command[3]              ),
  88.        (unsigned int)command[4]
  89. );
  90. break;
  91. case 10:
  92. printk("LBA=%d len=%d",
  93.        ((unsigned int)command[2] << 24) |
  94.        ((unsigned int)command[3] << 16) |
  95.        ((unsigned int)command[4] <<  8) |
  96.        ((unsigned int)command[5]      ),
  97.        ((unsigned int)command[7] <<  8) |
  98.        ((unsigned int)command[8]      )
  99.        );
  100. break;
  101. case 12:
  102. printk("LBA=%d len=%d",
  103.        ((unsigned int)command[2] << 24) |
  104.        ((unsigned int)command[3] << 16) |
  105.        ((unsigned int)command[4] <<  8) |
  106.        ((unsigned int)command[5]      ),
  107.        ((unsigned int)command[6] << 24) |
  108.        ((unsigned int)command[7] << 16) |
  109.        ((unsigned int)command[8] <<  8) |
  110.        ((unsigned int)command[9]      )
  111.        );
  112. break;
  113. default:
  114. break;
  115. }
  116. printk("n");
  117. }
  118. static void show_command(Scsi_Cmnd *ptr)
  119. {
  120. print_commandk(ptr->cmnd);
  121. }
  122. static void show_phase(Scsi_Cmnd *SCpnt)
  123. {
  124. int i = SCpnt->SCp.phase;
  125. char *ph[] = {
  126. "PH_UNDETERMINED",
  127. "PH_ARBSTART",
  128. "PH_SELSTART",
  129. "PH_SELECTED",
  130. "PH_COMMAND",
  131. "PH_DATA",
  132. "PH_STATUS",
  133. "PH_MSG_IN",
  134. "PH_MSG_OUT",
  135. "PH_DISCONNECT",
  136. "PH_RESELECT"
  137. };
  138. if ( i < PH_UNDETERMINED || i > PH_RESELECT ) {
  139. printk(KERN_DEBUG "scsi phase: unknown(%d)n", i);
  140. return;
  141. }
  142. printk(KERN_DEBUG "scsi phase: %sn", ph[i]);
  143. return;
  144. }
  145. static void show_busphase(unsigned char stat)
  146. {
  147. switch(stat) {
  148. case BUSPHASE_COMMAND:
  149. printk(KERN_DEBUG "BUSPHASE_COMMANDn");
  150. break;
  151. case BUSPHASE_MESSAGE_IN:
  152. printk(KERN_DEBUG "BUSPHASE_MESSAGE_INn");
  153. break;
  154. case BUSPHASE_MESSAGE_OUT:
  155. printk(KERN_DEBUG "BUSPHASE_MESSAGE_OUTn");
  156. break;
  157. case BUSPHASE_DATA_IN:
  158. printk(KERN_DEBUG "BUSPHASE_DATA_INn");
  159. break;
  160. case BUSPHASE_DATA_OUT:
  161. printk(KERN_DEBUG "BUSPHASE_DATA_OUTn");
  162. break;
  163. case BUSPHASE_STATUS:
  164. printk(KERN_DEBUG "BUSPHASE_STATUSn");
  165. break;
  166. case BUSPHASE_SELECT:
  167. printk(KERN_DEBUG "BUSPHASE_SELECTn");
  168. break;
  169. default:
  170. printk(KERN_DEBUG "BUSPHASE_othern");
  171. break;
  172. }
  173. }
  174. static void show_message(nsp_hw_data *data)
  175. {
  176. int i;
  177. printk(KERN_DEBUG "msg:");
  178. for(i=0; i < data->MsgLen; i++) {
  179. printk(" %02x", data->MsgBuffer[i]);
  180. }
  181. printk("n");
  182. }
  183. /* end */