File: /usr/src/linux/drivers/usb/storage/debug.c

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