1 /* Driver for USB Mass Storage compliant devices
2 * Debugging Functions Source Code File
3 *
4 * $Id: debug.c,v 1.8 2002/02/25 00:40:13 mdharm Exp $
5 *
6 * Current development and maintenance by:
7 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
8 *
9 * Developed with the assistance of:
10 * (c) 2002 Alan Stern <stern@rowland.org>
11 *
12 * Initial work by:
13 * (c) 1999 Michael Gee (michael@linuxspecific.com)
14 *
15 * This driver is based on the 'USB Mass Storage Class' document. This
16 * describes in detail the protocol used to communicate with such
17 * devices. Clearly, the designers had SCSI and ATAPI commands in
18 * mind when they created this document. The commands are all very
19 * similar to commands in the SCSI-II and ATAPI specifications.
20 *
21 * It is important to note that in a number of cases this class
22 * exhibits class-specific exemptions from the USB specification.
23 * Notably the usage of NAK, STALL and ACK differs from the norm, in
24 * that they are used to communicate wait, failed and OK on commands.
25 *
26 * Also, for certain devices, the interrupt endpoint is used to convey
27 * status of a command.
28 *
29 * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
30 * information about this driver.
31 *
32 * This program is free software; you can redistribute it and/or modify it
33 * under the terms of the GNU General Public License as published by the
34 * Free Software Foundation; either version 2, or (at your option) any
35 * later version.
36 *
37 * This program is distributed in the hope that it will be useful, but
38 * WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
40 * General Public License for more details.
41 *
42 * You should have received a copy of the GNU General Public License along
43 * with this program; if not, write to the Free Software Foundation, Inc.,
44 * 675 Mass Ave, Cambridge, MA 02139, USA.
45 */
46
47 #include "debug.h"
48
usb_stor_show_command(Scsi_Cmnd * srb)49 void usb_stor_show_command(Scsi_Cmnd *srb)
50 {
51 char *what = NULL;
52
53 switch (srb->cmnd[0]) {
54 case TEST_UNIT_READY: what = "TEST_UNIT_READY"; break;
55 case REZERO_UNIT: what = "REZERO_UNIT"; break;
56 case REQUEST_SENSE: what = "REQUEST_SENSE"; break;
57 case FORMAT_UNIT: what = "FORMAT_UNIT"; break;
58 case READ_BLOCK_LIMITS: what = "READ_BLOCK_LIMITS"; break;
59 case REASSIGN_BLOCKS: what = "REASSIGN_BLOCKS"; break;
60 case READ_6: what = "READ_6"; break;
61 case WRITE_6: what = "WRITE_6"; break;
62 case SEEK_6: what = "SEEK_6"; break;
63 case READ_REVERSE: what = "READ_REVERSE"; break;
64 case WRITE_FILEMARKS: what = "WRITE_FILEMARKS"; break;
65 case SPACE: what = "SPACE"; break;
66 case INQUIRY: what = "INQUIRY"; break;
67 case RECOVER_BUFFERED_DATA: what = "RECOVER_BUFFERED_DATA"; break;
68 case MODE_SELECT: what = "MODE_SELECT"; break;
69 case RESERVE: what = "RESERVE"; break;
70 case RELEASE: what = "RELEASE"; break;
71 case COPY: what = "COPY"; break;
72 case ERASE: what = "ERASE"; break;
73 case MODE_SENSE: what = "MODE_SENSE"; break;
74 case START_STOP: what = "START_STOP"; break;
75 case RECEIVE_DIAGNOSTIC: what = "RECEIVE_DIAGNOSTIC"; break;
76 case SEND_DIAGNOSTIC: what = "SEND_DIAGNOSTIC"; break;
77 case ALLOW_MEDIUM_REMOVAL: what = "ALLOW_MEDIUM_REMOVAL"; break;
78 case SET_WINDOW: what = "SET_WINDOW"; break;
79 case READ_CAPACITY: what = "READ_CAPACITY"; break;
80 case READ_10: what = "READ_10"; break;
81 case WRITE_10: what = "WRITE_10"; break;
82 case SEEK_10: what = "SEEK_10"; break;
83 case WRITE_VERIFY: what = "WRITE_VERIFY"; break;
84 case VERIFY: what = "VERIFY"; break;
85 case SEARCH_HIGH: what = "SEARCH_HIGH"; break;
86 case SEARCH_EQUAL: what = "SEARCH_EQUAL"; break;
87 case SEARCH_LOW: what = "SEARCH_LOW"; break;
88 case SET_LIMITS: what = "SET_LIMITS"; break;
89 case READ_POSITION: what = "READ_POSITION"; break;
90 case SYNCHRONIZE_CACHE: what = "SYNCHRONIZE_CACHE"; break;
91 case LOCK_UNLOCK_CACHE: what = "LOCK_UNLOCK_CACHE"; break;
92 case READ_DEFECT_DATA: what = "READ_DEFECT_DATA"; break;
93 case MEDIUM_SCAN: what = "MEDIUM_SCAN"; break;
94 case COMPARE: what = "COMPARE"; break;
95 case COPY_VERIFY: what = "COPY_VERIFY"; break;
96 case WRITE_BUFFER: what = "WRITE_BUFFER"; break;
97 case READ_BUFFER: what = "READ_BUFFER"; break;
98 case UPDATE_BLOCK: what = "UPDATE_BLOCK"; break;
99 case READ_LONG: what = "READ_LONG"; break;
100 case WRITE_LONG: what = "WRITE_LONG"; break;
101 case CHANGE_DEFINITION: what = "CHANGE_DEFINITION"; break;
102 case WRITE_SAME: what = "WRITE_SAME"; break;
103 case GPCMD_READ_SUBCHANNEL: what = "READ SUBCHANNEL"; break;
104 case READ_TOC: what = "READ_TOC"; break;
105 case GPCMD_READ_HEADER: what = "READ HEADER"; break;
106 case GPCMD_PLAY_AUDIO_10: what = "PLAY AUDIO (10)"; break;
107 case GPCMD_PLAY_AUDIO_MSF: what = "PLAY AUDIO MSF"; break;
108 case GPCMD_GET_EVENT_STATUS_NOTIFICATION:
109 what = "GET EVENT/STATUS NOTIFICATION"; break;
110 case GPCMD_PAUSE_RESUME: what = "PAUSE/RESUME"; break;
111 case LOG_SELECT: what = "LOG_SELECT"; break;
112 case LOG_SENSE: what = "LOG_SENSE"; break;
113 case GPCMD_STOP_PLAY_SCAN: what = "STOP PLAY/SCAN"; break;
114 case GPCMD_READ_DISC_INFO: what = "READ DISC INFORMATION"; break;
115 case GPCMD_READ_TRACK_RZONE_INFO:
116 what = "READ TRACK INFORMATION"; break;
117 case GPCMD_RESERVE_RZONE_TRACK: what = "RESERVE TRACK"; break;
118 case GPCMD_SEND_OPC: what = "SEND OPC"; break;
119 case MODE_SELECT_10: what = "MODE_SELECT_10"; break;
120 case GPCMD_REPAIR_RZONE_TRACK: what = "REPAIR TRACK"; break;
121 case 0x59: what = "READ MASTER CUE"; break;
122 case MODE_SENSE_10: what = "MODE_SENSE_10"; break;
123 case GPCMD_CLOSE_TRACK: what = "CLOSE TRACK/SESSION"; break;
124 case 0x5C: what = "READ BUFFER CAPACITY"; break;
125 case 0x5D: what = "SEND CUE SHEET"; break;
126 case GPCMD_BLANK: what = "BLANK"; break;
127 case MOVE_MEDIUM: what = "MOVE_MEDIUM or PLAY AUDIO (12)"; break;
128 case READ_12: what = "READ_12"; break;
129 case WRITE_12: what = "WRITE_12"; break;
130 case WRITE_VERIFY_12: what = "WRITE_VERIFY_12"; break;
131 case SEARCH_HIGH_12: what = "SEARCH_HIGH_12"; break;
132 case SEARCH_EQUAL_12: what = "SEARCH_EQUAL_12"; break;
133 case SEARCH_LOW_12: what = "SEARCH_LOW_12"; break;
134 case SEND_VOLUME_TAG: what = "SEND_VOLUME_TAG"; break;
135 case READ_ELEMENT_STATUS: what = "READ_ELEMENT_STATUS"; break;
136 case GPCMD_READ_CD_MSF: what = "READ CD MSF"; break;
137 case GPCMD_SCAN: what = "SCAN"; break;
138 case GPCMD_SET_SPEED: what = "SET CD SPEED"; break;
139 case GPCMD_MECHANISM_STATUS: what = "MECHANISM STATUS"; break;
140 case GPCMD_READ_CD: what = "READ CD"; break;
141 case 0xE1: what = "WRITE CONTINUE"; break;
142 case WRITE_LONG_2: what = "WRITE_LONG_2"; break;
143 default: what = "(unknown command)"; break;
144 }
145 US_DEBUGP("Command %s (%d bytes)\n", what, srb->cmd_len);
146 US_DEBUGP("%02x %02x %02x %02x "
147 "%02x %02x %02x %02x "
148 "%02x %02x %02x %02x\n",
149 srb->cmnd[0], srb->cmnd[1], srb->cmnd[2], srb->cmnd[3],
150 srb->cmnd[4], srb->cmnd[5], srb->cmnd[6], srb->cmnd[7],
151 srb->cmnd[8], srb->cmnd[9], srb->cmnd[10],
152 srb->cmnd[11]);
153 }
154
usb_stor_print_Scsi_Cmnd(Scsi_Cmnd * cmd)155 void usb_stor_print_Scsi_Cmnd( Scsi_Cmnd* cmd )
156 {
157 int i=0, bufferSize = cmd->request_bufflen;
158 u8* buffer = cmd->request_buffer;
159 struct scatterlist* sg = (struct scatterlist*)cmd->request_buffer;
160
161 US_DEBUGP("Dumping information about %p.\n", cmd );
162 US_DEBUGP("cmd->cmnd[0] value is %d.\n", cmd->cmnd[0] );
163 US_DEBUGP("(MODE_SENSE is %d and MODE_SENSE_10 is %d)\n",
164 MODE_SENSE, MODE_SENSE_10 );
165
166 US_DEBUGP("buffer is %p with length %d.\n", buffer, bufferSize );
167 for ( i=0; i<bufferSize; i+=16 )
168 {
169 US_DEBUGP("%02x %02x %02x %02x %02x %02x %02x %02x\n"
170 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
171 buffer[i],
172 buffer[i+1],
173 buffer[i+2],
174 buffer[i+3],
175 buffer[i+4],
176 buffer[i+5],
177 buffer[i+6],
178 buffer[i+7],
179 buffer[i+8],
180 buffer[i+9],
181 buffer[i+10],
182 buffer[i+11],
183 buffer[i+12],
184 buffer[i+13],
185 buffer[i+14],
186 buffer[i+15] );
187 }
188
189 US_DEBUGP("Buffer has %d scatterlists.\n", cmd->use_sg );
190 for ( i=0; i<cmd->use_sg; i++ )
191 {
192 US_DEBUGP("Length of scatterlist %d is %d.\n",i,sg[i].length);
193 US_DEBUGP("%02x %02x %02x %02x %02x %02x %02x %02x\n"
194 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
195 sg[i].address[0],
196 sg[i].address[1],
197 sg[i].address[2],
198 sg[i].address[3],
199 sg[i].address[4],
200 sg[i].address[5],
201 sg[i].address[6],
202 sg[i].address[7],
203 sg[i].address[8],
204 sg[i].address[9],
205 sg[i].address[10],
206 sg[i].address[11],
207 sg[i].address[12],
208 sg[i].address[13],
209 sg[i].address[14],
210 sg[i].address[15]);
211 }
212 }
213
usb_stor_show_sense(unsigned char key,unsigned char asc,unsigned char ascq)214 void usb_stor_show_sense(
215 unsigned char key,
216 unsigned char asc,
217 unsigned char ascq) {
218
219 char *keys[] = {
220 "No Sense",
221 "Recovered Error",
222 "Not Ready",
223 "Medium Error",
224 "Hardware Error",
225 "Illegal Request",
226 "Unit Attention",
227 "Data Protect",
228 "Blank Check",
229 "Vendor Specific",
230 "Copy Aborted",
231 "Aborted Command",
232 "(Obsolete)",
233 "Volume Overflow",
234 "Miscompare"
235 };
236
237 unsigned short qual = asc;
238
239 char *what = 0;
240 char *keystr = 0;
241
242 qual <<= 8;
243 qual |= ascq;
244
245 if (key>0x0E)
246 keystr = "(Unknown Key)";
247 else
248 keystr = keys[key];
249
250 switch (qual) {
251
252 case 0x0000: what="no additional sense information"; break;
253 case 0x0001: what="filemark detected"; break;
254 case 0x0002: what="end of partition/medium detected"; break;
255 case 0x0003: what="setmark detected"; break;
256 case 0x0004: what="beginning of partition/medium detected"; break;
257 case 0x0005: what="end of data detected"; break;
258 case 0x0006: what="I/O process terminated"; break;
259 case 0x0011: what="audio play operation in progress"; break;
260 case 0x0012: what="audio play operation paused"; break;
261 case 0x0013: what="audio play operation stopped due to error"; break;
262 case 0x0014: what="audio play operation successfully completed"; break;
263 case 0x0015: what="no current audio status to return"; break;
264 case 0x0016: what="operation in progress"; break;
265 case 0x0017: what="cleaning requested"; break;
266 case 0x0100: what="no index/sector signal"; break;
267 case 0x0200: what="no seek complete"; break;
268 case 0x0300: what="peripheral device write fault"; break;
269 case 0x0301: what="no write current"; break;
270 case 0x0302: what="excessive write errors"; break;
271 case 0x0400: what="LUN not ready, cause not reportable"; break;
272 case 0x0401: what="LUN in process of becoming ready"; break;
273 case 0x0402: what="LUN not ready, initializing cmd. required"; break;
274 case 0x0403: what="LUN not ready, manual intervention required"; break;
275 case 0x0404: what="LUN not ready, format in progress"; break;
276 case 0x0405: what="LUN not ready, rebuild in progress"; break;
277 case 0x0406: what="LUN not ready, recalculation in progress"; break;
278 case 0x0407: what="LUN not ready, operation in progress"; break;
279 case 0x0408: what="LUN not ready, long write in progress"; break;
280 case 0x0500: what="LUN doesn't respond to selection"; break;
281 case 0x0A00: what="error log overflow"; break;
282 case 0x0C04: what="compression check miscompare error"; break;
283 case 0x0C05: what="data expansion occurred during compression"; break;
284 case 0x0C06: what="block not compressible"; break;
285 case 0x1102: what="error too long to correct"; break;
286 case 0x1106: what="CIRC unrecovered error"; break;
287 case 0x1107: what="data resynchronization error"; break;
288 case 0x110D: what="decompression CRC error"; break;
289 case 0x110E: what="can't decompress using declared algorithm"; break;
290 case 0x110F: what="error reading UPC/EAN number"; break;
291 case 0x1110: what="error reading ISRC number"; break;
292 case 0x1200: what="address mark not found for ID field"; break;
293 case 0x1300: what="address mark not found for data field"; break;
294 case 0x1403: what="end of data not found"; break;
295 case 0x1404: what="block sequence error"; break;
296 case 0x1600: what="data sync mark error"; break;
297 case 0x1601: what="data sync error: data rewritten"; break;
298 case 0x1602: what="data sync error: recommend rewrite"; break;
299 case 0x1603: what="data sync error: data auto-reallocated"; break;
300 case 0x1604: what="data sync error: recommend reassignment"; break;
301 case 0x1900: what="defect list error"; break;
302 case 0x1901: what="defect list not available"; break;
303 case 0x1902: what="defect list error in primary list"; break;
304 case 0x1903: what="defect list error in grown list"; break;
305 case 0x1C00: what="defect list not found"; break;
306 case 0x2000: what="invalid command operation code"; break;
307 case 0x2400: what="invalid field in CDB"; break;
308 case 0x2703: what="associated write protect"; break;
309 case 0x2800: what="not ready to ready transition"; break;
310 case 0x2900: what="device reset occurred"; break;
311 case 0x2903: what="bus device reset function occurred"; break;
312 case 0x2904: what="device internal reset"; break;
313 case 0x2B00: what="copy can't execute / host can't disconnect"; break;
314 case 0x2C00: what="command sequence error"; break;
315 case 0x2C03: what="current program area is not empty"; break;
316 case 0x2C04: what="current program area is empty"; break;
317 case 0x2F00: what="commands cleared by another initiator"; break;
318 case 0x3001: what="can't read medium: unknown format"; break;
319 case 0x3002: what="can't read medium: incompatible format"; break;
320 case 0x3003: what="cleaning cartridge installed"; break;
321 case 0x3004: what="can't write medium: unknown format"; break;
322 case 0x3005: what="can't write medium: incompatible format"; break;
323 case 0x3006: what="can't format medium: incompatible medium"; break;
324 case 0x3007: what="cleaning failure"; break;
325 case 0x3008: what="can't write: application code mismatch"; break;
326 case 0x3009: what="current session not fixated for append"; break;
327 case 0x3201: what="defect list update failure"; break;
328 case 0x3400: what="enclosure failure"; break;
329 case 0x3500: what="enclosure services failure"; break;
330 case 0x3502: what="enclosure services unavailable"; break;
331 case 0x3503: what="enclosure services transfer failure"; break;
332 case 0x3504: what="enclosure services transfer refused"; break;
333 case 0x3A00: what="media not present"; break;
334 case 0x3B0F: what="end of medium reached"; break;
335 case 0x3F02: what="changed operating definition"; break;
336 case 0x4100: what="data path failure (should use 40 NN)"; break;
337 case 0x4A00: what="command phase error"; break;
338 case 0x4B00: what="data phase error"; break;
339 case 0x5100: what="erase failure"; break;
340 case 0x5200: what="cartridge fault"; break;
341 case 0x6300: what="end of user area encountered on this track"; break;
342 case 0x6600: what="automatic document feeder cover up"; break;
343 case 0x6601: what="automatic document feeder lift up"; break;
344 case 0x6602: what="document jam in auto doc feeder"; break;
345 case 0x6603: what="document miss feed auto in doc feeder"; break;
346 case 0x6700: what="configuration failure"; break;
347 case 0x6701: what="configuration of incapable LUN's failed"; break;
348 case 0x6702: what="add logical unit failed"; break;
349 case 0x6706: what="attachment of logical unit failed"; break;
350 case 0x6707: what="creation of logical unit failed"; break;
351 case 0x6900: what="data loss on logical unit"; break;
352 case 0x6E00: what="command to logical unit failed"; break;
353 case 0x7100: what="decompression exception long algorithm ID"; break;
354 case 0x7204: what="empty or partially written reserved track"; break;
355 case 0x7300: what="CD control error"; break;
356
357 default:
358 if (asc==0x40) {
359 US_DEBUGP("%s: diagnostic failure on component"
360 " %02X\n", keystr, ascq);
361 return;
362 }
363 if (asc==0x70) {
364 US_DEBUGP("%s: decompression exception short"
365 " algorithm ID of %02X\n", keystr, ascq);
366 return;
367 }
368 what = "(unknown ASC/ASCQ)";
369 }
370
371 US_DEBUGP("%s: %s\n", keystr, what);
372 }
373
374