1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for USB Mass Storage compliant devices
4 * Debugging Functions Source Code File
6 * Current development and maintenance by:
7 * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
9 * Developed with the assistance of:
10 * (c) 2002 Alan Stern <stern@rowland.org>
13 * (c) 1999 Michael Gee (michael@linuxspecific.com)
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.
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.
26 * Also, for certain devices, the interrupt endpoint is used to convey
27 * status of a command.
30 #include <linux/device.h>
31 #include <linux/cdrom.h>
32 #include <linux/export.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <scsi/scsi_dbg.h>
42 void usb_stor_show_command(const struct us_data
*us
, struct scsi_cmnd
*srb
)
46 switch (srb
->cmnd
[0]) {
47 case TEST_UNIT_READY
: what
= "TEST_UNIT_READY"; break;
48 case REZERO_UNIT
: what
= "REZERO_UNIT"; break;
49 case REQUEST_SENSE
: what
= "REQUEST_SENSE"; break;
50 case FORMAT_UNIT
: what
= "FORMAT_UNIT"; break;
51 case READ_BLOCK_LIMITS
: what
= "READ_BLOCK_LIMITS"; break;
52 case REASSIGN_BLOCKS
: what
= "REASSIGN_BLOCKS"; break;
53 case READ_6
: what
= "READ_6"; break;
54 case WRITE_6
: what
= "WRITE_6"; break;
55 case SEEK_6
: what
= "SEEK_6"; break;
56 case READ_REVERSE
: what
= "READ_REVERSE"; break;
57 case WRITE_FILEMARKS
: what
= "WRITE_FILEMARKS"; break;
58 case SPACE
: what
= "SPACE"; break;
59 case INQUIRY
: what
= "INQUIRY"; break;
60 case RECOVER_BUFFERED_DATA
: what
= "RECOVER_BUFFERED_DATA"; break;
61 case MODE_SELECT
: what
= "MODE_SELECT"; break;
62 case RESERVE
: what
= "RESERVE"; break;
63 case RELEASE
: what
= "RELEASE"; break;
64 case COPY
: what
= "COPY"; break;
65 case ERASE
: what
= "ERASE"; break;
66 case MODE_SENSE
: what
= "MODE_SENSE"; break;
67 case START_STOP
: what
= "START_STOP"; break;
68 case RECEIVE_DIAGNOSTIC
: what
= "RECEIVE_DIAGNOSTIC"; break;
69 case SEND_DIAGNOSTIC
: what
= "SEND_DIAGNOSTIC"; break;
70 case ALLOW_MEDIUM_REMOVAL
: what
= "ALLOW_MEDIUM_REMOVAL"; break;
71 case SET_WINDOW
: what
= "SET_WINDOW"; break;
72 case READ_CAPACITY
: what
= "READ_CAPACITY"; break;
73 case READ_10
: what
= "READ_10"; break;
74 case WRITE_10
: what
= "WRITE_10"; break;
75 case SEEK_10
: what
= "SEEK_10"; break;
76 case WRITE_VERIFY
: what
= "WRITE_VERIFY"; break;
77 case VERIFY
: what
= "VERIFY"; break;
78 case SEARCH_HIGH
: what
= "SEARCH_HIGH"; break;
79 case SEARCH_EQUAL
: what
= "SEARCH_EQUAL"; break;
80 case SEARCH_LOW
: what
= "SEARCH_LOW"; break;
81 case SET_LIMITS
: what
= "SET_LIMITS"; break;
82 case READ_POSITION
: what
= "READ_POSITION"; break;
83 case SYNCHRONIZE_CACHE
: what
= "SYNCHRONIZE_CACHE"; break;
84 case LOCK_UNLOCK_CACHE
: what
= "LOCK_UNLOCK_CACHE"; break;
85 case READ_DEFECT_DATA
: what
= "READ_DEFECT_DATA"; break;
86 case MEDIUM_SCAN
: what
= "MEDIUM_SCAN"; break;
87 case COMPARE
: what
= "COMPARE"; break;
88 case COPY_VERIFY
: what
= "COPY_VERIFY"; break;
89 case WRITE_BUFFER
: what
= "WRITE_BUFFER"; break;
90 case READ_BUFFER
: what
= "READ_BUFFER"; break;
91 case UPDATE_BLOCK
: what
= "UPDATE_BLOCK"; break;
92 case READ_LONG
: what
= "READ_LONG"; break;
93 case WRITE_LONG
: what
= "WRITE_LONG"; break;
94 case CHANGE_DEFINITION
: what
= "CHANGE_DEFINITION"; break;
95 case WRITE_SAME
: what
= "WRITE_SAME"; break;
96 case GPCMD_READ_SUBCHANNEL
: what
= "READ SUBCHANNEL"; break;
97 case READ_TOC
: what
= "READ_TOC"; break;
98 case GPCMD_READ_HEADER
: what
= "READ HEADER"; break;
99 case GPCMD_PLAY_AUDIO_10
: what
= "PLAY AUDIO (10)"; break;
100 case GPCMD_PLAY_AUDIO_MSF
: what
= "PLAY AUDIO MSF"; break;
101 case GPCMD_GET_EVENT_STATUS_NOTIFICATION
:
102 what
= "GET EVENT/STATUS NOTIFICATION"; break;
103 case GPCMD_PAUSE_RESUME
: what
= "PAUSE/RESUME"; break;
104 case LOG_SELECT
: what
= "LOG_SELECT"; break;
105 case LOG_SENSE
: what
= "LOG_SENSE"; break;
106 case GPCMD_STOP_PLAY_SCAN
: what
= "STOP PLAY/SCAN"; break;
107 case GPCMD_READ_DISC_INFO
: what
= "READ DISC INFORMATION"; break;
108 case GPCMD_READ_TRACK_RZONE_INFO
:
109 what
= "READ TRACK INFORMATION"; break;
110 case GPCMD_RESERVE_RZONE_TRACK
: what
= "RESERVE TRACK"; break;
111 case GPCMD_SEND_OPC
: what
= "SEND OPC"; break;
112 case MODE_SELECT_10
: what
= "MODE_SELECT_10"; break;
113 case GPCMD_REPAIR_RZONE_TRACK
: what
= "REPAIR TRACK"; break;
114 case 0x59: what
= "READ MASTER CUE"; break;
115 case MODE_SENSE_10
: what
= "MODE_SENSE_10"; break;
116 case GPCMD_CLOSE_TRACK
: what
= "CLOSE TRACK/SESSION"; break;
117 case 0x5C: what
= "READ BUFFER CAPACITY"; break;
118 case 0x5D: what
= "SEND CUE SHEET"; break;
119 case GPCMD_BLANK
: what
= "BLANK"; break;
120 case REPORT_LUNS
: what
= "REPORT LUNS"; break;
121 case MOVE_MEDIUM
: what
= "MOVE_MEDIUM or PLAY AUDIO (12)"; break;
122 case READ_12
: what
= "READ_12"; break;
123 case WRITE_12
: what
= "WRITE_12"; break;
124 case WRITE_VERIFY_12
: what
= "WRITE_VERIFY_12"; break;
125 case SEARCH_HIGH_12
: what
= "SEARCH_HIGH_12"; break;
126 case SEARCH_EQUAL_12
: what
= "SEARCH_EQUAL_12"; break;
127 case SEARCH_LOW_12
: what
= "SEARCH_LOW_12"; break;
128 case SEND_VOLUME_TAG
: what
= "SEND_VOLUME_TAG"; break;
129 case READ_ELEMENT_STATUS
: what
= "READ_ELEMENT_STATUS"; break;
130 case GPCMD_READ_CD_MSF
: what
= "READ CD MSF"; break;
131 case GPCMD_SCAN
: what
= "SCAN"; break;
132 case GPCMD_SET_SPEED
: what
= "SET CD SPEED"; break;
133 case GPCMD_MECHANISM_STATUS
: what
= "MECHANISM STATUS"; break;
134 case GPCMD_READ_CD
: what
= "READ CD"; break;
135 case 0xE1: what
= "WRITE CONTINUE"; break;
136 case WRITE_LONG_2
: what
= "WRITE_LONG_2"; break;
137 default: what
= "(unknown command)"; break;
139 usb_stor_dbg(us
, "Command %s (%d bytes)\n", what
, srb
->cmd_len
);
140 usb_stor_dbg(us
, "bytes: %*ph\n", min_t(int, srb
->cmd_len
, 16),
141 (const unsigned char *)srb
->cmnd
);
144 void usb_stor_show_sense(const struct us_data
*us
,
149 const char *what
, *keystr
, *fmt
;
151 keystr
= scsi_sense_key_string(key
);
152 what
= scsi_extd_sense_format(asc
, ascq
, &fmt
);
155 keystr
= "(Unknown Key)";
157 what
= "(unknown ASC/ASCQ)";
160 usb_stor_dbg(us
, "%s: %s (%s%x)\n", keystr
, what
, fmt
, ascq
);
162 usb_stor_dbg(us
, "%s: %s\n", keystr
, what
);
165 void usb_stor_dbg(const struct us_data
*us
, const char *fmt
, ...)
171 dev_vprintk_emit(LOGLEVEL_DEBUG
, &us
->pusb_dev
->dev
, fmt
, args
);
175 EXPORT_SYMBOL_GPL(usb_stor_dbg
);