xref: /netbsd-src/sys/dev/scsipi/scsi_all.h (revision d9158b13b5dfe46201430699a3f7a235ecf28df3)
1 /*
2  * SCSI general  interface description
3  */
4 
5 /*
6  * Largely written by Julian Elischer (julian@tfs.com)
7  * for TRW Financial Systems.
8  *
9  * TRW Financial Systems, in accordance with their agreement with Carnegie
10  * Mellon University, makes this software available to CMU to distribute
11  * or use in any manner that they see fit as long as this message is kept with
12  * the software. For this reason TFS also grants any other persons or
13  * organisations permission to use or modify this software.
14  *
15  * TFS supplies this software to be publicly redistributed
16  * on the understanding that TFS is not responsible for the correct
17  * functioning of this software in any circumstances.
18  *
19  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
20  *
21  *	$Id: scsi_all.h,v 1.4 1994/05/09 07:40:50 chopps Exp $
22  */
23 
24 #ifndef	_SCSI_SCSI_ALL_H
25 #define _SCSI_SCSI_ALL_H 1
26 /*
27  * SCSI command format
28  */
29 
30 /*
31  * Define dome bits that are in ALL (or a lot of) scsi commands
32  */
33 #define SCSI_CTL_LINK		0x01
34 #define SCSI_CTL_FLAG		0x02
35 #define SCSI_CTL_VENDOR		0xC0
36 #define	SCSI_CMD_LUN		0xA0	/* these two should not be needed */
37 #define	SCSI_CMD_LUN_SHIFT	5	/* LUN in the cmd is no longer SCSI */
38 
39 
40 struct scsi_generic
41 {
42 	u_char	opcode;
43 	u_char	bytes[11];
44 };
45 
46 struct scsi_test_unit_ready
47 {
48 	u_char	op_code;
49 	u_char	byte2;
50 	u_char	unused[3];
51 	u_char	control;
52 };
53 
54 struct scsi_send_diag
55 {
56 	u_char	op_code;
57 	u_char	byte2;
58 #define	SSD_UOL		0x01
59 #define	SSD_DOL		0x02
60 #define	SSD_SELFTEST	0x04
61 #define	SSD_PF		0x10
62 	u_char	unused[1];
63 	u_char	paramlen[2];
64 	u_char	control;
65 };
66 
67 struct scsi_sense
68 {
69 	u_char	op_code;
70 	u_char	byte2;
71 	u_char	unused[2];
72 	u_char	length;
73 	u_char	control;
74 };
75 
76 struct scsi_inquiry
77 {
78 	u_char	op_code;
79 	u_char	byte2;
80 	u_char	unused[2];
81 	u_char	length;
82 	u_char	control;
83 };
84 
85 struct scsi_mode_sense
86 {
87 	u_char	op_code;
88 	u_char	byte2;
89 #define	SMS_DBD				0x08
90 	u_char	page;
91 #define	SMS_PAGE_CODE 			0x3F
92 #define	SMS_PAGE_CTRL 			0xC0
93 #define	SMS_PAGE_CTRL_CURRENT 		0x00
94 #define	SMS_PAGE_CTRL_CHANGEABLE 	0x40
95 #define	SMS_PAGE_CTRL_DEFAULT 		0x80
96 #define	SMS_PAGE_CTRL_SAVED 		0xC0
97 	u_char	unused;
98 	u_char	length;
99 	u_char	control;
100 };
101 
102 struct scsi_mode_sense_big
103 {
104 	u_char	op_code;
105 	u_char	byte2; 		/* same bits as small version */
106 	u_char	page; 		/* same bits as small version */
107 	u_char	unused[4];
108 	u_char	length[2];
109 	u_char	control;
110 };
111 
112 struct scsi_mode_select
113 {
114 	u_char	op_code;
115 	u_char	byte2;
116 #define	SMS_SP	0x01
117 #define	SMS_PF	0x10
118 	u_char	unused[2];
119 	u_char	length;
120 	u_char	control;
121 };
122 
123 struct scsi_mode_select_big
124 {
125 	u_char	op_code;
126 	u_char	byte2;		/* same bits as small version */
127 	u_char	unused[5];
128 	u_char	length[2];
129 	u_char	control;
130 };
131 
132 struct scsi_reserve
133 {
134 	u_char	op_code;
135 	u_char	byte2;
136 	u_char	unused[2];
137 	u_char	length;
138 	u_char	control;
139 };
140 
141 struct scsi_release
142 {
143 	u_char	op_code;
144 	u_char	byte2;
145 	u_char	unused[2];
146 	u_char	length;
147 	u_char	control;
148 };
149 
150 struct scsi_prevent
151 {
152 	u_char	op_code;
153 	u_char	byte2;
154 	u_char	unused[2];
155 	u_char	how;
156 	u_char	control;
157 };
158 #define	PR_PREVENT 0x01
159 #define PR_ALLOW   0x00
160 
161 struct scsi_changedef
162 {
163 	u_char	op_code;
164 	u_char	byte2;
165 	u_char	unused1;
166 	u_char	how;
167 	u_char	unused[4];
168 	u_char	datalen;
169 	u_char	control;
170 };
171 #define SC_SCSI_1 0x01
172 #define SC_SCSI_2 0x03
173 
174 /*
175  * Opcodes
176  */
177 
178 #define	TEST_UNIT_READY		0x00
179 #define REQUEST_SENSE		0x03
180 #define INQUIRY			0x12
181 #define MODE_SELECT		0x15
182 #define MODE_SENSE		0x1a
183 #define START_STOP		0x1b
184 #define RESERVE      		0x16
185 #define RELEASE      		0x17
186 #define PREVENT_ALLOW		0x1e
187 #define POSITION_TO_ELEMENT	0x2b
188 #define	CHANGE_DEFINITION	0x40
189 #define	MODE_SENSE_BIG		0x54
190 #define	MODE_SELECT_BIG		0x55
191 #define MOVE_MEDIUM     	0xa5
192 #define READ_ELEMENT_STATUS	0xb8
193 
194 
195 /*
196  * sense data format
197  */
198 #define T_DIRECT	0
199 #define T_SEQUENTIAL	1
200 #define T_PRINTER	2
201 #define T_PROCESSOR	3
202 #define T_WORM		4
203 #define T_READONLY	5
204 #define T_SCANNER 	6
205 #define T_OPTICAL 	7
206 #define T_NODEVICE	0x1F
207 
208 #define T_CHANGER	8
209 #define T_COMM		9
210 
211 #define T_REMOV		1
212 #define	T_FIXED		0
213 
214 struct scsi_inquiry_data
215 {
216 	u_char	device;
217 #define	SID_TYPE	0x1F
218 #define	SID_QUAL	0xE0
219 #define	SID_QUAL_LU_OK	0x00
220 #define	SID_QUAL_LU_OFFLINE	0x20
221 #define	SID_QUAL_RSVD	0x40
222 #define	SID_QUAL_BAD_LU	0x60
223 	u_char	dev_qual2;
224 #define	SID_QUAL2	0x7F
225 #define	SID_REMOVABLE	0x80
226 	u_char	version;
227 #define SID_ANSII	0x07
228 #define SID_ECMA	0x38
229 #define SID_ISO		0xC0
230 	u_char	response_format;
231 	u_char	additional_length;
232 	u_char	unused[2];
233 	u_char	flags;
234 #define	SID_SftRe	0x01
235 #define	SID_CmdQue	0x02
236 #define	SID_Linked	0x08
237 #define	SID_Sync	0x10
238 #define	SID_WBus16	0x20
239 #define	SID_WBus32	0x40
240 #define	SID_RelAdr	0x80
241 	char	vendor[8];
242 	char	product[16];
243 	char	revision[4];
244 	u_char	extra[8];
245 };
246 
247 /*
248  * The union had to die.  It caused a padding problem with
249  * m68k gcc, specifically `ext.extended.segment' was being
250  * read at byte 2 not 1.
251  */
252 struct	scsi_sense_data_old	/* XXXX The union had to die. */
253 {
254 /* 1*/	u_char	error_code;	/* same bits as new version */
255 	union
256 	{
257 		struct
258 		{
259 /* 2*/			u_char	blockhi;
260 /* 3*/			u_char	blockmed;
261 /* 4*/			u_char	blocklow;
262 		} unextended;
263 		struct
264 		{
265 /* 2*/			u_char	segment;
266 /* 3*/			u_char	flags;	/* same bits as new version */
267 /* 7*/			u_char	info[4];
268 /* 8*/			u_char	extra_len;
269 			/* allocate enough room to hold new stuff
270 			( by increasing 16 to 24 below) */
271 /*32*/			u_char	extra_bytes[24];
272 		} extended;
273 	}ext;
274 };	/* total of 32 bytes */
275 
276 /*
277  * This looks bad, and it is.  However it fixes padding problems
278  * caused by using unions.  This *needs* to be an array, if this code
279  * is to work on any architecture.
280  */
281 struct	scsi_sense_data
282 {
283 /* 1*/	u_char	error_code;	/* same bits as new version */
284 #define XXX_unextended_blockhi	extended_segment
285 #define XXX_unextended_blockmed	extended_flags
286 #define XXX_unextended_blocklow	extended_info[0]
287 /* 2*/	u_char	extended_segment;
288 /* 3*/	u_char	extended_flags;		/* same bits as new version */
289 /* 7*/	u_char	extended_info[4];
290 /* 8*/	u_char	extended_extra_len;
291 	/*
292 	 * allocate enough room to hold new stuff
293 	 * (by increasing 16 to 24 below)
294 	 */
295 /*32*/	u_char	extended_extra_bytes[24];
296 };	/* total of 32 bytes */
297 
298 struct	scsi_sense_data_new
299 {
300 /* 1*/	u_char	error_code;
301 #define	SSD_ERRCODE		0x7F
302 #define	SSD_ERRCODE_VALID	0x80
303 	union
304 	{
305 		struct	/* this is deprecated, the standard says "DON'T"*/
306 		{
307 /* 2*/			u_char	blockhi;
308 /* 3*/			u_char	blockmed;
309 /* 4*/			u_char	blocklow;
310 		} unextended;
311 		struct
312 		{
313 /* 2*/			u_char	segment;
314 /* 3*/			u_char	flags;
315 #define	SSD_KEY		0x0F
316 #define	SSD_ILI		0x20
317 #define	SSD_EOM		0x40
318 #define	SSD_FILEMARK	0x80
319 /* 7*/			u_char	info[4];
320 /* 8*/			u_char	extra_len;
321 /*12*/			u_char	cmd_spec_info[4];
322 /*13*/			u_char	add_sense_code;
323 /*14*/			u_char	add_sense_code_qual;
324 /*15*/			u_char	fru;
325 /*16*/			u_char	sense_key_spec_1;
326 #define	SSD_SCS_VALID		0x80
327 /*17*/			u_char	sense_key_spec_2;
328 /*18*/			u_char	sense_key_spec_3;
329 /*32*/			u_char	extra_bytes[14];
330 		} extended;
331 	}ext;
332 }; /* total of 32 bytes */
333 
334 struct	blk_desc
335 {
336 	u_char	density;
337 	u_char	nblocks[3];
338 	u_char	reserved;
339 	u_char	blklen[3];
340 };
341 
342 struct scsi_mode_header
343 {
344 	u_char	data_length;	/* Sense data length */
345 	u_char	medium_type;
346 	u_char	dev_spec;
347 	u_char	blk_desc_len;
348 };
349 
350 struct scsi_mode_header_big
351 {
352 	u_char	data_length[2];	/* Sense data length */
353 	u_char	medium_type;
354 	u_char	dev_spec;
355 	u_char	unused[2];
356 	u_char	blk_desc_len[2];
357 };
358 
359 
360 /*
361  * Status Byte
362  */
363 #define	SCSI_OK		0x00
364 #define	SCSI_CHECK		0x02
365 #define	SCSI_BUSY		0x08
366 #define SCSI_INTERM		0x10
367 #endif /*_SCSI_SCSI_ALL_H*/
368