Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Driver for USB Mass Storage compliant devices
  4 * Debugging Functions Source Code File
  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
 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>
 36
 37#include "usb.h"
 38#include "debug.h"
 
 39
 40
 41void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
 42{
 43	char *what = NULL;
 44
 45	switch (srb->cmnd[0]) {
 46	case TEST_UNIT_READY: what = "TEST_UNIT_READY"; break;
 47	case REZERO_UNIT: what = "REZERO_UNIT"; break;
 48	case REQUEST_SENSE: what = "REQUEST_SENSE"; break;
 49	case FORMAT_UNIT: what = "FORMAT_UNIT"; break;
 50	case READ_BLOCK_LIMITS: what = "READ_BLOCK_LIMITS"; break;
 51	case REASSIGN_BLOCKS: what = "REASSIGN_BLOCKS"; break;
 52	case READ_6: what = "READ_6"; break;
 53	case WRITE_6: what = "WRITE_6"; break;
 54	case SEEK_6: what = "SEEK_6"; break;
 55	case READ_REVERSE: what = "READ_REVERSE"; break;
 56	case WRITE_FILEMARKS: what = "WRITE_FILEMARKS"; break;
 57	case SPACE: what = "SPACE"; break;
 58	case INQUIRY: what = "INQUIRY"; break;
 59	case RECOVER_BUFFERED_DATA: what = "RECOVER_BUFFERED_DATA"; break;
 60	case MODE_SELECT: what = "MODE_SELECT"; break;
 61	case RESERVE: what = "RESERVE"; break;
 62	case RELEASE: what = "RELEASE"; break;
 63	case COPY: what = "COPY"; break;
 64	case ERASE: what = "ERASE"; break;
 65	case MODE_SENSE: what = "MODE_SENSE"; break;
 66	case START_STOP: what = "START_STOP"; break;
 67	case RECEIVE_DIAGNOSTIC: what = "RECEIVE_DIAGNOSTIC"; break;
 68	case SEND_DIAGNOSTIC: what = "SEND_DIAGNOSTIC"; break;
 69	case ALLOW_MEDIUM_REMOVAL: what = "ALLOW_MEDIUM_REMOVAL"; break;
 70	case SET_WINDOW: what = "SET_WINDOW"; break;
 71	case READ_CAPACITY: what = "READ_CAPACITY"; break;
 72	case READ_10: what = "READ_10"; break;
 73	case WRITE_10: what = "WRITE_10"; break;
 74	case SEEK_10: what = "SEEK_10"; break;
 75	case WRITE_VERIFY: what = "WRITE_VERIFY"; break;
 76	case VERIFY: what = "VERIFY"; break;
 77	case SEARCH_HIGH: what = "SEARCH_HIGH"; break;
 78	case SEARCH_EQUAL: what = "SEARCH_EQUAL"; break;
 79	case SEARCH_LOW: what = "SEARCH_LOW"; break;
 80	case SET_LIMITS: what = "SET_LIMITS"; break;
 81	case READ_POSITION: what = "READ_POSITION"; break;
 82	case SYNCHRONIZE_CACHE: what = "SYNCHRONIZE_CACHE"; break;
 83	case LOCK_UNLOCK_CACHE: what = "LOCK_UNLOCK_CACHE"; break;
 84	case READ_DEFECT_DATA: what = "READ_DEFECT_DATA"; break;
 85	case MEDIUM_SCAN: what = "MEDIUM_SCAN"; break;
 86	case COMPARE: what = "COMPARE"; break;
 87	case COPY_VERIFY: what = "COPY_VERIFY"; break;
 88	case WRITE_BUFFER: what = "WRITE_BUFFER"; break;
 89	case READ_BUFFER: what = "READ_BUFFER"; break;
 90	case UPDATE_BLOCK: what = "UPDATE_BLOCK"; break;
 91	case READ_LONG: what = "READ_LONG"; break;
 92	case WRITE_LONG: what = "WRITE_LONG"; break;
 93	case CHANGE_DEFINITION: what = "CHANGE_DEFINITION"; break;
 94	case WRITE_SAME: what = "WRITE_SAME"; break;
 95	case GPCMD_READ_SUBCHANNEL: what = "READ SUBCHANNEL"; break;
 96	case READ_TOC: what = "READ_TOC"; break;
 97	case GPCMD_READ_HEADER: what = "READ HEADER"; break;
 98	case GPCMD_PLAY_AUDIO_10: what = "PLAY AUDIO (10)"; break;
 99	case GPCMD_PLAY_AUDIO_MSF: what = "PLAY AUDIO MSF"; break;
100	case GPCMD_GET_EVENT_STATUS_NOTIFICATION:
101		what = "GET EVENT/STATUS NOTIFICATION"; break;
102	case GPCMD_PAUSE_RESUME: what = "PAUSE/RESUME"; break;
103	case LOG_SELECT: what = "LOG_SELECT"; break;
104	case LOG_SENSE: what = "LOG_SENSE"; break;
105	case GPCMD_STOP_PLAY_SCAN: what = "STOP PLAY/SCAN"; break;
106	case GPCMD_READ_DISC_INFO: what = "READ DISC INFORMATION"; break;
107	case GPCMD_READ_TRACK_RZONE_INFO:
108		what = "READ TRACK INFORMATION"; break;
109	case GPCMD_RESERVE_RZONE_TRACK: what = "RESERVE TRACK"; break;
110	case GPCMD_SEND_OPC: what = "SEND OPC"; break;
111	case MODE_SELECT_10: what = "MODE_SELECT_10"; break;
112	case GPCMD_REPAIR_RZONE_TRACK: what = "REPAIR TRACK"; break;
113	case 0x59: what = "READ MASTER CUE"; break;
114	case MODE_SENSE_10: what = "MODE_SENSE_10"; break;
115	case GPCMD_CLOSE_TRACK: what = "CLOSE TRACK/SESSION"; break;
116	case 0x5C: what = "READ BUFFER CAPACITY"; break;
117	case 0x5D: what = "SEND CUE SHEET"; break;
118	case GPCMD_BLANK: what = "BLANK"; break;
119	case REPORT_LUNS: what = "REPORT LUNS"; break;
120	case MOVE_MEDIUM: what = "MOVE_MEDIUM or PLAY AUDIO (12)"; break;
121	case READ_12: what = "READ_12"; break;
122	case WRITE_12: what = "WRITE_12"; break;
123	case WRITE_VERIFY_12: what = "WRITE_VERIFY_12"; break;
124	case SEARCH_HIGH_12: what = "SEARCH_HIGH_12"; break;
125	case SEARCH_EQUAL_12: what = "SEARCH_EQUAL_12"; break;
126	case SEARCH_LOW_12: what = "SEARCH_LOW_12"; break;
127	case SEND_VOLUME_TAG: what = "SEND_VOLUME_TAG"; break;
128	case READ_ELEMENT_STATUS: what = "READ_ELEMENT_STATUS"; break;
129	case GPCMD_READ_CD_MSF: what = "READ CD MSF"; break;
130	case GPCMD_SCAN: what = "SCAN"; break;
131	case GPCMD_SET_SPEED: what = "SET CD SPEED"; break;
132	case GPCMD_MECHANISM_STATUS: what = "MECHANISM STATUS"; break;
133	case GPCMD_READ_CD: what = "READ CD"; break;
134	case 0xE1: what = "WRITE CONTINUE"; break;
135	case WRITE_LONG_2: what = "WRITE_LONG_2"; break;
136	default: what = "(unknown command)"; break;
137	}
138	usb_stor_dbg(us, "Command %s (%d bytes)\n", what, srb->cmd_len);
139	usb_stor_dbg(us, "bytes: %*ph\n", min_t(int, srb->cmd_len, 16),
140		     (const unsigned char *)srb->cmnd);
141}
142
143void usb_stor_show_sense(const struct us_data *us,
144			 unsigned char key,
145			 unsigned char asc,
146			 unsigned char ascq)
147{
148	const char *what, *keystr, *fmt;
149
150	keystr = scsi_sense_key_string(key);
151	what = scsi_extd_sense_format(asc, ascq, &fmt);
152
153	if (keystr == NULL)
154		keystr = "(Unknown Key)";
155	if (what == NULL)
156		what = "(unknown ASC/ASCQ)";
157
158	if (fmt)
159		usb_stor_dbg(us, "%s: %s (%s%x)\n", keystr, what, fmt, ascq);
160	else
161		usb_stor_dbg(us, "%s: %s\n", keystr, what);
162}
163
164void usb_stor_dbg(const struct us_data *us, const char *fmt, ...)
165{
166	va_list args;
167
168	va_start(args, fmt);
169
170	dev_vprintk_emit(LOGLEVEL_DEBUG, &us->pusb_dev->dev, fmt, args);
171
172	va_end(args);
173}
174EXPORT_SYMBOL_GPL(usb_stor_dbg);
v4.6
  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
 45#include <linux/device.h>
 46#include <linux/cdrom.h>
 47#include <linux/export.h>
 48#include <scsi/scsi.h>
 49#include <scsi/scsi_cmnd.h>
 50#include <scsi/scsi_dbg.h>
 51
 52#include "usb.h"
 53#include "debug.h"
 54#include "scsi.h"
 55
 56
 57void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
 58{
 59	char *what = NULL;
 60
 61	switch (srb->cmnd[0]) {
 62	case TEST_UNIT_READY: what = "TEST_UNIT_READY"; break;
 63	case REZERO_UNIT: what = "REZERO_UNIT"; break;
 64	case REQUEST_SENSE: what = "REQUEST_SENSE"; break;
 65	case FORMAT_UNIT: what = "FORMAT_UNIT"; break;
 66	case READ_BLOCK_LIMITS: what = "READ_BLOCK_LIMITS"; break;
 67	case REASSIGN_BLOCKS: what = "REASSIGN_BLOCKS"; break;
 68	case READ_6: what = "READ_6"; break;
 69	case WRITE_6: what = "WRITE_6"; break;
 70	case SEEK_6: what = "SEEK_6"; break;
 71	case READ_REVERSE: what = "READ_REVERSE"; break;
 72	case WRITE_FILEMARKS: what = "WRITE_FILEMARKS"; break;
 73	case SPACE: what = "SPACE"; break;
 74	case INQUIRY: what = "INQUIRY"; break;
 75	case RECOVER_BUFFERED_DATA: what = "RECOVER_BUFFERED_DATA"; break;
 76	case MODE_SELECT: what = "MODE_SELECT"; break;
 77	case RESERVE: what = "RESERVE"; break;
 78	case RELEASE: what = "RELEASE"; break;
 79	case COPY: what = "COPY"; break;
 80	case ERASE: what = "ERASE"; break;
 81	case MODE_SENSE: what = "MODE_SENSE"; break;
 82	case START_STOP: what = "START_STOP"; break;
 83	case RECEIVE_DIAGNOSTIC: what = "RECEIVE_DIAGNOSTIC"; break;
 84	case SEND_DIAGNOSTIC: what = "SEND_DIAGNOSTIC"; break;
 85	case ALLOW_MEDIUM_REMOVAL: what = "ALLOW_MEDIUM_REMOVAL"; break;
 86	case SET_WINDOW: what = "SET_WINDOW"; break;
 87	case READ_CAPACITY: what = "READ_CAPACITY"; break;
 88	case READ_10: what = "READ_10"; break;
 89	case WRITE_10: what = "WRITE_10"; break;
 90	case SEEK_10: what = "SEEK_10"; break;
 91	case WRITE_VERIFY: what = "WRITE_VERIFY"; break;
 92	case VERIFY: what = "VERIFY"; break;
 93	case SEARCH_HIGH: what = "SEARCH_HIGH"; break;
 94	case SEARCH_EQUAL: what = "SEARCH_EQUAL"; break;
 95	case SEARCH_LOW: what = "SEARCH_LOW"; break;
 96	case SET_LIMITS: what = "SET_LIMITS"; break;
 97	case READ_POSITION: what = "READ_POSITION"; break;
 98	case SYNCHRONIZE_CACHE: what = "SYNCHRONIZE_CACHE"; break;
 99	case LOCK_UNLOCK_CACHE: what = "LOCK_UNLOCK_CACHE"; break;
100	case READ_DEFECT_DATA: what = "READ_DEFECT_DATA"; break;
101	case MEDIUM_SCAN: what = "MEDIUM_SCAN"; break;
102	case COMPARE: what = "COMPARE"; break;
103	case COPY_VERIFY: what = "COPY_VERIFY"; break;
104	case WRITE_BUFFER: what = "WRITE_BUFFER"; break;
105	case READ_BUFFER: what = "READ_BUFFER"; break;
106	case UPDATE_BLOCK: what = "UPDATE_BLOCK"; break;
107	case READ_LONG: what = "READ_LONG"; break;
108	case WRITE_LONG: what = "WRITE_LONG"; break;
109	case CHANGE_DEFINITION: what = "CHANGE_DEFINITION"; break;
110	case WRITE_SAME: what = "WRITE_SAME"; break;
111	case GPCMD_READ_SUBCHANNEL: what = "READ SUBCHANNEL"; break;
112	case READ_TOC: what = "READ_TOC"; break;
113	case GPCMD_READ_HEADER: what = "READ HEADER"; break;
114	case GPCMD_PLAY_AUDIO_10: what = "PLAY AUDIO (10)"; break;
115	case GPCMD_PLAY_AUDIO_MSF: what = "PLAY AUDIO MSF"; break;
116	case GPCMD_GET_EVENT_STATUS_NOTIFICATION:
117		what = "GET EVENT/STATUS NOTIFICATION"; break;
118	case GPCMD_PAUSE_RESUME: what = "PAUSE/RESUME"; break;
119	case LOG_SELECT: what = "LOG_SELECT"; break;
120	case LOG_SENSE: what = "LOG_SENSE"; break;
121	case GPCMD_STOP_PLAY_SCAN: what = "STOP PLAY/SCAN"; break;
122	case GPCMD_READ_DISC_INFO: what = "READ DISC INFORMATION"; break;
123	case GPCMD_READ_TRACK_RZONE_INFO:
124		what = "READ TRACK INFORMATION"; break;
125	case GPCMD_RESERVE_RZONE_TRACK: what = "RESERVE TRACK"; break;
126	case GPCMD_SEND_OPC: what = "SEND OPC"; break;
127	case MODE_SELECT_10: what = "MODE_SELECT_10"; break;
128	case GPCMD_REPAIR_RZONE_TRACK: what = "REPAIR TRACK"; break;
129	case 0x59: what = "READ MASTER CUE"; break;
130	case MODE_SENSE_10: what = "MODE_SENSE_10"; break;
131	case GPCMD_CLOSE_TRACK: what = "CLOSE TRACK/SESSION"; break;
132	case 0x5C: what = "READ BUFFER CAPACITY"; break;
133	case 0x5D: what = "SEND CUE SHEET"; break;
134	case GPCMD_BLANK: what = "BLANK"; break;
135	case REPORT_LUNS: what = "REPORT LUNS"; break;
136	case MOVE_MEDIUM: what = "MOVE_MEDIUM or PLAY AUDIO (12)"; break;
137	case READ_12: what = "READ_12"; break;
138	case WRITE_12: what = "WRITE_12"; break;
139	case WRITE_VERIFY_12: what = "WRITE_VERIFY_12"; break;
140	case SEARCH_HIGH_12: what = "SEARCH_HIGH_12"; break;
141	case SEARCH_EQUAL_12: what = "SEARCH_EQUAL_12"; break;
142	case SEARCH_LOW_12: what = "SEARCH_LOW_12"; break;
143	case SEND_VOLUME_TAG: what = "SEND_VOLUME_TAG"; break;
144	case READ_ELEMENT_STATUS: what = "READ_ELEMENT_STATUS"; break;
145	case GPCMD_READ_CD_MSF: what = "READ CD MSF"; break;
146	case GPCMD_SCAN: what = "SCAN"; break;
147	case GPCMD_SET_SPEED: what = "SET CD SPEED"; break;
148	case GPCMD_MECHANISM_STATUS: what = "MECHANISM STATUS"; break;
149	case GPCMD_READ_CD: what = "READ CD"; break;
150	case 0xE1: what = "WRITE CONTINUE"; break;
151	case WRITE_LONG_2: what = "WRITE_LONG_2"; break;
152	default: what = "(unknown command)"; break;
153	}
154	usb_stor_dbg(us, "Command %s (%d bytes)\n", what, srb->cmd_len);
155	usb_stor_dbg(us, "bytes: %*ph\n", min_t(int, srb->cmd_len, 16),
156		     (const unsigned char *)srb->cmnd);
157}
158
159void usb_stor_show_sense(const struct us_data *us,
160			 unsigned char key,
161			 unsigned char asc,
162			 unsigned char ascq)
163{
164	const char *what, *keystr, *fmt;
165
166	keystr = scsi_sense_key_string(key);
167	what = scsi_extd_sense_format(asc, ascq, &fmt);
168
169	if (keystr == NULL)
170		keystr = "(Unknown Key)";
171	if (what == NULL)
172		what = "(unknown ASC/ASCQ)";
173
174	if (fmt)
175		usb_stor_dbg(us, "%s: %s (%s%x)\n", keystr, what, fmt, ascq);
176	else
177		usb_stor_dbg(us, "%s: %s\n", keystr, what);
178}
179
180void usb_stor_dbg(const struct us_data *us, const char *fmt, ...)
181{
182	va_list args;
183
184	va_start(args, fmt);
185
186	dev_vprintk_emit(LOGLEVEL_DEBUG, &us->pusb_dev->dev, fmt, args);
187
188	va_end(args);
189}
190EXPORT_SYMBOL_GPL(usb_stor_dbg);