xref: /haiku/src/add-ons/kernel/busses/scsi/usb/scsi_commands.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2  * Copyright 2004-2007, Haiku, Inc. All RightsReserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Author:
6  *		Siarzhuk Zharski <imker@gmx.li>
7  */
8 #ifndef _SCSI_COMMANDS_H_
9 #define _SCSI_COMMANDS_H_
10 
11 /*!	Definitions for SCSI commands, structures etc. */
12 
13 #include <lendian_bitfield.h>
14 
15 /* References:
16  * http://www.t10.org/ftp/t10/drafts/rbc/rbc-r10a.pdf
17  * http://www.t10.org/ftp/t10/drafts/rbc/rbc-a101.pdf
18  * http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf
19  * http://www.t10.org/ftp/t10/drafts/cam/cam-r12b.pdf
20  * http://www.qic.org/html/standards/15x.x/qic157d.pdf
21  *
22  * http://www.usb.org/developers/data/devclass/usbmass-ufi10.pdf
23  */
24 
25 #define CAM_DIR_MASK (CAM_DIR_IN | CAM_DIR_OUT | CAM_DIR_NONE )
26 
27 /* SCSI status defines */
28 #define SCSI_STATUS_OK				0x00
29 #define SCSI_STATUS_CHECK_CONDITION	0x02
30 
31 /* SCSI command opcodes */
32 #define READ_6			0x08
33 #define WRITE_6			0x0a
34 #define READ_10			0x28
35 #define WRITE_10		0x2a
36 #define MODE_SELECT_6	0x15
37 #define MODE_SENSE_6	0x1a
38 #define MODE_SELECT_10	0x55
39 #define MODE_SENSE_10	0x5a
40 #define READ_CAPACITY	0x25
41 #define TEST_UNIT_READY	0x00
42 #define START_STOP_UNIT	0x1b
43 
44 /* come from UFI specs */
45 #define FORMAT_UNIT			0x04
46 #define INQUIRY				0x12
47 /*#define START_STOP_UNIT	0x1b
48 #define MODE_SELECT		 	0x55
49 #define MODE_SENSE			0x5a */
50 #define PREVENT_ALLOW_MEDIA_REMOVAL 0x1e
51 #define READ_10				0x28
52 #define READ_12				0xa8
53 /*#define READ_CAPACITY	 0x25*/
54 #define READ_FORMAT_CAPACITY	0x23
55 #define REQUEST_SENSE	 		0x03
56 #define REZERO_UNIT		 		0x01
57 #define SEEK_10				 	0x2b
58 #define SEND_DIAGNOSTICS		0x1d
59 /*#define TEST_UNIT_READY	 0x00*/
60 #define VERIFY					0x2f
61 #define WRITE_10				0x2a
62 #define WRITE_12				0xaa
63 #define WRITE_AND_VERIFY		0x2e
64 /* end of UFI commands*/
65 
66 /* come from ATAPI specs*/
67 /*#define FORMAT_UNIT	 0x04
68 #define INQUIRY			 0x12
69 #define MODE_SELECT	 0x55
70 #define MODE_SENSE		0x5a
71 #define PREVENT_ALLOW_MEDIUM_REMOVAL	0x1e
72 #define READ_10			 0x28
73 #define READ_12			 0xa8
74 #define READ_CAPACITY 0x25
75 #define READ_FORMAT_CAPACITIES	0x23
76 #define REQUEST_SENSE 0x03
77 #define SEEK					0x2b
78 #define START_STOP_UNIT	0x1b
79 #define TEST_UNIT_READY	0x00
80 #define VERIFY				0x2f
81 #define WRITE_10			0x2a
82 #define WRITE_12			0xaa
83 #define WRITE_AND_VEIRIFY 0x2e */
84 #define PAUSE_RESUME		0x4b
85 #define PLAY_AUDIO			0x45
86 #define PLAY_AUDIO_MSF 		0x47
87 #define REWIND				0x01
88 #define PLAY_AUDIO_TRACK 	0x48
89 
90 /* end of ATAPI commands*/
91 
92 /* come from MMC2 specs */
93 #define READ_BUFFER			0x3c
94 #define READ_SUBCHANNEL		0x42
95 #define READ_TOC			0x43
96 #define READ_HEADER			0x44
97 #define READ_DISK_INFO		0x51
98 #define READ_TRACK_INFO		0x52
99 #define SEND_OPC			0x54
100 #define READ_MASTER_CUE		0x59
101 #define CLOSE_TR_SESSION	0x5b
102 #define READ_BUFFER_CAP		0x5c
103 #define SEND_CUE_SHEET		0x5d
104 #define BLANK				0xa1
105 #define EXCHANGE_MEDIUM		0xa6
106 #define READ_DVD_STRUCTURE	0xad
107 #define DVD_REPORT_KEY		0xa4
108 #define DVD_SEND_KEY		0xa3
109 #define SET_CD_SPEED		0xbb
110 #define GET_CONFIGURATION	0x46
111 /* end of MMC2 specs */
112 
113 /* come from RBC specs */
114 /*#define FORMAT_UNIT				0x04
115 #define INQUIRY						0x12
116 #define MODE_SELECT_6			0x15
117 #define MODE_SENSE_6			 0x1a*/
118 #define PERSISTENT_RESERVE_IN		0x5e
119 #define PERSISTENT_RESERVE_OUT		0x5f
120 /*#define PREVENT_ALLOW_MEDIUM_REMOVAL	0x1e
121 #define READ_10						0x28
122 #define READ_CAPACITY			0x25*/
123 #define RELEASE_6					0x17
124 /*#define REQUEST_SENSE			0x03*/
125 #define RESERVE_6					0x16
126 /*#define START_STOP_UNIT		0x1b*/
127 #define SYNCHRONIZE_CACHE			0x35
128 /*#define TEST_UNIT_READY		0x00
129 #define VERIFY_10					0x2f
130 #define WRITE_10					 0x2a*/
131 #define WRITE_BUFFER			 	0x3b
132 /* end of RBC commands */
133 
134 /* come from QIC-157 specvs */
135 #define ERASE			0x19
136 /*#define INQUIRY			0x12*/
137 #define LOAD_UNLOAD		0x1b
138 #define LOCATE			0x2b
139 #define LOG_SELECT	 	0x4c
140 #define LOG_SENSE		0x4d
141 /*#define MODE_SELECT	0x15
142 #define MODE_SENSE	 0x1a
143 #define READ				 0x08*/
144 #define READ_POSITION	0x34
145 /*#define REQUEST_SENSE	 0x03*/
146 #define REWIND			0x01
147 #define SPACE			0x11
148 /*#define TEST_UNIT_READY 0x00
149 #define WRITE					 0x0a*/
150 #define WRITE_FILEMARK	0x10
151 /* end of QIC-157 */
152 
153 /* SCSI commands layout*/
154 /* generic commands layout*/
155 typedef struct{
156 	uint8 opcode;
157 	uint8 bytes[11];
158 }scsi_cmd_generic;
159 /* six-bytes command*/
160 typedef struct{
161 	uint8 opcode;
162 	uint8 addr[3];
163 #define CMD_GEN_6_ADDR	0x1f /* mask used for addr field*/
164 #define	CMD_LUN			0xE0 /* mask used for LUN	*/
165 #define	CMD_LUN_SHIFT	0x05 /* shift for LUN */
166 	uint8 len;
167 	uint8 ctrl;
168 }scsi_cmd_generic_6;
169 /* ten-bytes command*/
170 typedef struct{
171 	uint8 opcode;
172 	uint8 byte2;
173 	uint8 addr[4];
174 	uint8 reserved;
175 	uint8 len[2];
176 	uint8 ctrl;
177 }scsi_cmd_generic_10;
178 /* twelve-bytes command*/
179 typedef struct{
180 	uint8 opcode;
181 	uint8 byte2;
182 	uint8 addr[4];
183 	uint8 len[4];
184 	uint8 reserved;
185 	uint8 ctrl;
186 }scsi_cmd_generic_12;
187 /* READ_6 / WRITE_6 */
188 typedef scsi_cmd_generic_6 scsi_cmd_rw_6;
189 
190 /* READ_10 / WRITE_10 */
191 typedef struct {
192 	uint8 opcode;
193 	LBITFIELD8_5(
194 		relative_address : 1,		// relative address
195 		_res1_1 : 2,
196 		force_unit_access : 1,		// force unit access (1 = safe, cacheless access)
197 		disable_page_out : 1,		// disable page out (1 = not worth caching)
198 		lun : 3
199 	);
200 	uint32 lba;			// big endian
201 	uint8 _reserved;
202 	uint16 length;		// big endian
203 	uint8 control;
204 } scsi_cmd_rw_10;
205 
206 /* MODE_SELECT_6 */
207 typedef struct{
208 	uint8 opcode;
209 	uint8 byte2;
210 #define CMD_MSEL_6_SP	0x01
211 #define CMD_MSEL_6_PF	0x10
212 	uint8 reserved[2];
213 	uint8 len;
214 	uint8 ctrl;
215 }scsi_cmd_mode_select_6;
216 /* MODE_SELECT_10 */
217 typedef struct{
218 	uint8 opcode;
219 	uint8 byte2;
220 #define CMD_MSEL_10_SP	0x01
221 #define CMD_MSEL_10_PF	0x10
222 	uint8 reserved[5];
223 	uint8 len[2];
224 	uint8 ctrl;
225 }scsi_cmd_mode_select_10;
226 /* MODE_SENSE_6 */
227 typedef struct{
228 	uint8 opcode;
229 	uint8 byte2;
230 #define CMD_MSENSE_6_DBD	0x08
231 	uint8 byte3;
232 #define CMD_MSENSE_6_PC		0x0c
233 	uint8 reserved;
234 	uint8 len;
235 	uint8 ctrl;
236 }scsi_cmd_mode_sense_6;
237 typedef struct{
238 	uint8 mode_data_len;
239 	uint8 medium_type;
240 	uint8 device_spec_params;
241 	uint8 block_descr_len;
242 }scsi_mode_param_header_6;
243 /* MODE_SENSE_10 */
244 typedef struct{
245 	uint8 opcode;
246 	uint8 byte2;
247 #define CMD_MSENSE_10_DBD	0x08
248 	uint8 byte3;
249 #define CMD_MSENSE_10_PC	0x0c
250 	uint8 reserved[4];
251 	uint8 len[2];
252 	uint8 ctrl;
253 }scsi_cmd_mode_sense_10;
254 typedef struct{
255 	uint8 mode_data_len[2];
256 	uint8 medium_type;
257 	uint8 device_spec_params;
258 	uint8 reserved1;
259 	uint8 reserved2;
260 	uint8 block_descr_len[2];
261 }scsi_mode_param_header_10;
262 /* TEST_UNIT_READY */
263 typedef struct{
264 	uint8 opcode;
265 	uint8 byte2;
266 	uint8 reserved[3];
267 	uint8 ctrl;
268 }scsi_cmd_test_unit_ready;
269 /* START_STOP_UNIT */
270 typedef struct{
271 	uint8 opcode;
272 	uint8 byte2;
273 #define CMD_SSU_IMMED	0x01
274 	uint8 reserved[2];
275 	uint8 start_loej;
276 #define CMD_SSU_LOEJ	0x02
277 #define CMD_SSU_START	0x01
278 	uint8 ctrl;
279 }scsi_cmd_start_stop_unit;
280 
281 /* SCSI REQUEST SENSE data. See 8.2.14*/
282 typedef struct _scsi_sense_data{
283 	uint8 error_code;
284 #define SSD_ERRCODE			0x7F
285 #define	SSD_CURRENT_ERROR	0x70
286 #define	SSD_DEFERRED_ERROR	0x71
287 #define	SSD_ERRCODE_VALID	0x80
288 	uint8 segment;
289 	uint8 flags;
290 #define SSD_KEY					0x0F
291 #define	SSD_KEY_NO_SENSE		0x00
292 #define	SSD_KEY_RECOVERED_ERROR 0x01
293 #define	SSD_KEY_NOT_READY		0x02
294 #define	SSD_KEY_MEDIUM_ERROR	0x03
295 #define	SSD_KEY_HARDWARE_ERROR	0x04
296 #define	SSD_KEY_ILLEGAL_REQUEST 0x05
297 #define	SSD_KEY_UNIT_ATTENTION	0x06
298 #define	SSD_KEY_DATA_PROTECT	0x07
299 #define	SSD_KEY_BLANK_CHECK		0x08
300 #define	SSD_KEY_Vendor_Specific 0x09
301 #define	SSD_KEY_COPY_ABORTED	0x0a
302 #define	SSD_KEY_ABORTED_COMMAND 0x0b
303 #define	SSD_KEY_EQUAL			0x0c
304 #define	SSD_KEY_VOLUME_OVERFLOW 0x0d
305 #define	SSD_KEY_MISCOMPARE		0x0e
306 #define	SSD_KEY_RESERVED		0x0f
307 #define SSD_ILI					0x20
308 #define SSD_EOM					0x40
309 #define SSD_FILEMARK			0x80
310 	uint8 info[4];
311 	uint8 extra_len;
312 	uint8 cmd_spec_info[4];
313 	uint8 add_sense_code;
314 	uint8 add_sense_code_qual;
315 	uint8 fru;
316 	uint8 sense_key_spec[3];
317 #define SSD_SCS_VALID		0x80
318 #define SSD_FIELDPTR_CMD	0x40
319 #define SSD_BITPTR_VALID	0x08
320 #define SSD_BITPTR_VALUE	0x07
321 #define SSD_MIN_SIZE		18
322 	uint8 extra_bytes[14];
323 #define SSD_FULL_SIZE sizeof(struct _scsi_sense_data)
324 }scsi_sense_data;
325 
326 #endif /*_SCSI_COMMANDS_H_*/
327 
328