debug.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* Driver for USB Mass Storage compliant devices
  2. * Debugging Functions Source Code File
  3. *
  4. * Current development and maintenance by:
  5. * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
  6. *
  7. * Developed with the assistance of:
  8. * (c) 2002 Alan Stern <stern@rowland.org>
  9. *
  10. * Initial work by:
  11. * (c) 1999 Michael Gee (michael@linuxspecific.com)
  12. *
  13. * This driver is based on the 'USB Mass Storage Class' document. This
  14. * describes in detail the protocol used to communicate with such
  15. * devices. Clearly, the designers had SCSI and ATAPI commands in
  16. * mind when they created this document. The commands are all very
  17. * similar to commands in the SCSI-II and ATAPI specifications.
  18. *
  19. * It is important to note that in a number of cases this class
  20. * exhibits class-specific exemptions from the USB specification.
  21. * Notably the usage of NAK, STALL and ACK differs from the norm, in
  22. * that they are used to communicate wait, failed and OK on commands.
  23. *
  24. * Also, for certain devices, the interrupt endpoint is used to convey
  25. * status of a command.
  26. *
  27. * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
  28. * information about this driver.
  29. *
  30. * This program is free software; you can redistribute it and/or modify it
  31. * under the terms of the GNU General Public License as published by the
  32. * Free Software Foundation; either version 2, or (at your option) any
  33. * later version.
  34. *
  35. * This program is distributed in the hope that it will be useful, but
  36. * WITHOUT ANY WARRANTY; without even the implied warranty of
  37. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  38. * General Public License for more details.
  39. *
  40. * You should have received a copy of the GNU General Public License along
  41. * with this program; if not, write to the Free Software Foundation, Inc.,
  42. * 675 Mass Ave, Cambridge, MA 02139, USA.
  43. */
  44. #include <linux/device.h>
  45. #include <linux/cdrom.h>
  46. #include <linux/export.h>
  47. #include <scsi/scsi.h>
  48. #include <scsi/scsi_cmnd.h>
  49. #include <scsi/scsi_dbg.h>
  50. #include "usb.h"
  51. #include "debug.h"
  52. #include "scsi.h"
  53. void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
  54. {
  55. char *what = NULL;
  56. int i;
  57. switch (srb->cmnd[0]) {
  58. case TEST_UNIT_READY: what = "TEST_UNIT_READY"; break;
  59. case REZERO_UNIT: what = "REZERO_UNIT"; break;
  60. case REQUEST_SENSE: what = "REQUEST_SENSE"; break;
  61. case FORMAT_UNIT: what = "FORMAT_UNIT"; break;
  62. case READ_BLOCK_LIMITS: what = "READ_BLOCK_LIMITS"; break;
  63. case REASSIGN_BLOCKS: what = "REASSIGN_BLOCKS"; break;
  64. case READ_6: what = "READ_6"; break;
  65. case WRITE_6: what = "WRITE_6"; break;
  66. case SEEK_6: what = "SEEK_6"; break;
  67. case READ_REVERSE: what = "READ_REVERSE"; break;
  68. case WRITE_FILEMARKS: what = "WRITE_FILEMARKS"; break;
  69. case SPACE: what = "SPACE"; break;
  70. case INQUIRY: what = "INQUIRY"; break;
  71. case RECOVER_BUFFERED_DATA: what = "RECOVER_BUFFERED_DATA"; break;
  72. case MODE_SELECT: what = "MODE_SELECT"; break;
  73. case RESERVE: what = "RESERVE"; break;
  74. case RELEASE: what = "RELEASE"; break;
  75. case COPY: what = "COPY"; break;
  76. case ERASE: what = "ERASE"; break;
  77. case MODE_SENSE: what = "MODE_SENSE"; break;
  78. case START_STOP: what = "START_STOP"; break;
  79. case RECEIVE_DIAGNOSTIC: what = "RECEIVE_DIAGNOSTIC"; break;
  80. case SEND_DIAGNOSTIC: what = "SEND_DIAGNOSTIC"; break;
  81. case ALLOW_MEDIUM_REMOVAL: what = "ALLOW_MEDIUM_REMOVAL"; break;
  82. case SET_WINDOW: what = "SET_WINDOW"; break;
  83. case READ_CAPACITY: what = "READ_CAPACITY"; break;
  84. case READ_10: what = "READ_10"; break;
  85. case WRITE_10: what = "WRITE_10"; break;
  86. case SEEK_10: what = "SEEK_10"; break;
  87. case WRITE_VERIFY: what = "WRITE_VERIFY"; break;
  88. case VERIFY: what = "VERIFY"; break;
  89. case SEARCH_HIGH: what = "SEARCH_HIGH"; break;
  90. case SEARCH_EQUAL: what = "SEARCH_EQUAL"; break;
  91. case SEARCH_LOW: what = "SEARCH_LOW"; break;
  92. case SET_LIMITS: what = "SET_LIMITS"; break;
  93. case READ_POSITION: what = "READ_POSITION"; break;
  94. case SYNCHRONIZE_CACHE: what = "SYNCHRONIZE_CACHE"; break;
  95. case LOCK_UNLOCK_CACHE: what = "LOCK_UNLOCK_CACHE"; break;
  96. case READ_DEFECT_DATA: what = "READ_DEFECT_DATA"; break;
  97. case MEDIUM_SCAN: what = "MEDIUM_SCAN"; break;
  98. case COMPARE: what = "COMPARE"; break;
  99. case COPY_VERIFY: what = "COPY_VERIFY"; break;
  100. case WRITE_BUFFER: what = "WRITE_BUFFER"; break;
  101. case READ_BUFFER: what = "READ_BUFFER"; break;
  102. case UPDATE_BLOCK: what = "UPDATE_BLOCK"; break;
  103. case READ_LONG: what = "READ_LONG"; break;
  104. case WRITE_LONG: what = "WRITE_LONG"; break;
  105. case CHANGE_DEFINITION: what = "CHANGE_DEFINITION"; break;
  106. case WRITE_SAME: what = "WRITE_SAME"; break;
  107. case GPCMD_READ_SUBCHANNEL: what = "READ SUBCHANNEL"; break;
  108. case READ_TOC: what = "READ_TOC"; break;
  109. case GPCMD_READ_HEADER: what = "READ HEADER"; break;
  110. case GPCMD_PLAY_AUDIO_10: what = "PLAY AUDIO (10)"; break;
  111. case GPCMD_PLAY_AUDIO_MSF: what = "PLAY AUDIO MSF"; break;
  112. case GPCMD_GET_EVENT_STATUS_NOTIFICATION:
  113. what = "GET EVENT/STATUS NOTIFICATION"; break;
  114. case GPCMD_PAUSE_RESUME: what = "PAUSE/RESUME"; break;
  115. case LOG_SELECT: what = "LOG_SELECT"; break;
  116. case LOG_SENSE: what = "LOG_SENSE"; break;
  117. case GPCMD_STOP_PLAY_SCAN: what = "STOP PLAY/SCAN"; break;
  118. case GPCMD_READ_DISC_INFO: what = "READ DISC INFORMATION"; break;
  119. case GPCMD_READ_TRACK_RZONE_INFO:
  120. what = "READ TRACK INFORMATION"; break;
  121. case GPCMD_RESERVE_RZONE_TRACK: what = "RESERVE TRACK"; break;
  122. case GPCMD_SEND_OPC: what = "SEND OPC"; break;
  123. case MODE_SELECT_10: what = "MODE_SELECT_10"; break;
  124. case GPCMD_REPAIR_RZONE_TRACK: what = "REPAIR TRACK"; break;
  125. case 0x59: what = "READ MASTER CUE"; break;
  126. case MODE_SENSE_10: what = "MODE_SENSE_10"; break;
  127. case GPCMD_CLOSE_TRACK: what = "CLOSE TRACK/SESSION"; break;
  128. case 0x5C: what = "READ BUFFER CAPACITY"; break;
  129. case 0x5D: what = "SEND CUE SHEET"; break;
  130. case GPCMD_BLANK: what = "BLANK"; break;
  131. case REPORT_LUNS: what = "REPORT LUNS"; break;
  132. case MOVE_MEDIUM: what = "MOVE_MEDIUM or PLAY AUDIO (12)"; break;
  133. case READ_12: what = "READ_12"; break;
  134. case WRITE_12: what = "WRITE_12"; break;
  135. case WRITE_VERIFY_12: what = "WRITE_VERIFY_12"; break;
  136. case SEARCH_HIGH_12: what = "SEARCH_HIGH_12"; break;
  137. case SEARCH_EQUAL_12: what = "SEARCH_EQUAL_12"; break;
  138. case SEARCH_LOW_12: what = "SEARCH_LOW_12"; break;
  139. case SEND_VOLUME_TAG: what = "SEND_VOLUME_TAG"; break;
  140. case READ_ELEMENT_STATUS: what = "READ_ELEMENT_STATUS"; break;
  141. case GPCMD_READ_CD_MSF: what = "READ CD MSF"; break;
  142. case GPCMD_SCAN: what = "SCAN"; break;
  143. case GPCMD_SET_SPEED: what = "SET CD SPEED"; break;
  144. case GPCMD_MECHANISM_STATUS: what = "MECHANISM STATUS"; break;
  145. case GPCMD_READ_CD: what = "READ CD"; break;
  146. case 0xE1: what = "WRITE CONTINUE"; break;
  147. case WRITE_LONG_2: what = "WRITE_LONG_2"; break;
  148. default: what = "(unknown command)"; break;
  149. }
  150. usb_stor_dbg(us, "Command %s (%d bytes)\n", what, srb->cmd_len);
  151. usb_stor_dbg(us, "bytes: ");
  152. for (i = 0; i < srb->cmd_len && i < 16; i++)
  153. US_DEBUGPX(" %02x", srb->cmnd[i]);
  154. US_DEBUGPX("\n");
  155. }
  156. void usb_stor_show_sense(const struct us_data *us,
  157. unsigned char key,
  158. unsigned char asc,
  159. unsigned char ascq)
  160. {
  161. const char *what, *keystr, *fmt;
  162. keystr = scsi_sense_key_string(key);
  163. what = scsi_extd_sense_format(asc, ascq, &fmt);
  164. if (keystr == NULL)
  165. keystr = "(Unknown Key)";
  166. if (what == NULL)
  167. what = "(unknown ASC/ASCQ)";
  168. usb_stor_dbg(us, "%s: ", keystr);
  169. if (fmt)
  170. US_DEBUGPX("%s (%s%x)\n", what, fmt, ascq);
  171. else
  172. US_DEBUGPX("%s\n", what);
  173. }
  174. void usb_stor_dbg(const struct us_data *us, const char *fmt, ...)
  175. {
  176. va_list args;
  177. va_start(args, fmt);
  178. dev_vprintk_emit(LOGLEVEL_DEBUG, &us->pusb_dev->dev, fmt, args);
  179. va_end(args);
  180. }
  181. EXPORT_SYMBOL_GPL(usb_stor_dbg);