xref: /netbsd-src/sys/dev/scsipi/scsi_all.h (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: scsi_all.h,v 1.10 1996/09/12 01:57:17 thorpej Exp $	*/
2 
3 /*
4  * SCSI general  interface description
5  */
6 
7 /*
8  * Largely written by Julian Elischer (julian@tfs.com)
9  * for TRW Financial Systems.
10  *
11  * TRW Financial Systems, in accordance with their agreement with Carnegie
12  * Mellon University, makes this software available to CMU to distribute
13  * or use in any manner that they see fit as long as this message is kept with
14  * the software. For this reason TFS also grants any other persons or
15  * organisations permission to use or modify this software.
16  *
17  * TFS supplies this software to be publicly redistributed
18  * on the understanding that TFS is not responsible for the correct
19  * functioning of this software in any circumstances.
20  *
21  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
22  */
23 
24 #ifndef	_SCSI_SCSI_ALL_H
25 #define _SCSI_SCSI_ALL_H 1
26 
27 /*
28  * SCSI command format
29  */
30 
31 /*
32  * Define dome bits that are in ALL (or a lot of) scsi commands
33  */
34 #define SCSI_CTL_LINK		0x01
35 #define SCSI_CTL_FLAG		0x02
36 #define SCSI_CTL_VENDOR		0xC0
37 
38 
39 /*
40  * Some old SCSI devices need the LUN to be set in the top 3 bits of the
41  * second byte of the CDB.
42  */
43 #define	SCSI_CMD_LUN_MASK	0xe0
44 #define	SCSI_CMD_LUN_SHIFT	5
45 
46 
47 struct scsi_generic {
48 	u_int8_t opcode;
49 	u_int8_t bytes[11];
50 };
51 
52 struct scsi_test_unit_ready {
53 	u_int8_t opcode;
54 	u_int8_t byte2;
55 	u_int8_t unused[3];
56 	u_int8_t control;
57 };
58 
59 struct scsi_send_diag {
60 	u_int8_t opcode;
61 	u_int8_t byte2;
62 #define	SSD_UOL		0x01
63 #define	SSD_DOL		0x02
64 #define	SSD_SELFTEST	0x04
65 #define	SSD_PF		0x10
66 	u_int8_t unused[1];
67 	u_int8_t paramlen[2];
68 	u_int8_t control;
69 };
70 
71 struct scsi_sense {
72 	u_int8_t opcode;
73 	u_int8_t byte2;
74 	u_int8_t unused[2];
75 	u_int8_t length;
76 	u_int8_t control;
77 };
78 
79 struct scsi_inquiry {
80 	u_int8_t opcode;
81 	u_int8_t byte2;
82 	u_int8_t unused[2];
83 	u_int8_t length;
84 	u_int8_t control;
85 };
86 
87 struct scsi_mode_sense {
88 	u_int8_t opcode;
89 	u_int8_t byte2;
90 #define	SMS_DBD				0x08
91 	u_int8_t page;
92 #define	SMS_PAGE_CODE 			0x3F
93 #define	SMS_PAGE_CTRL 			0xC0
94 #define	SMS_PAGE_CTRL_CURRENT 		0x00
95 #define	SMS_PAGE_CTRL_CHANGEABLE 	0x40
96 #define	SMS_PAGE_CTRL_DEFAULT 		0x80
97 #define	SMS_PAGE_CTRL_SAVED 		0xC0
98 	u_int8_t unused;
99 	u_int8_t length;
100 	u_int8_t control;
101 };
102 
103 struct scsi_mode_sense_big {
104 	u_int8_t opcode;
105 	u_int8_t byte2;		/* same bits as small version */
106 	u_int8_t page; 		/* same bits as small version */
107 	u_int8_t unused[4];
108 	u_int8_t length[2];
109 	u_int8_t control;
110 };
111 
112 struct scsi_mode_select {
113 	u_int8_t opcode;
114 	u_int8_t byte2;
115 #define	SMS_SP	0x01
116 #define	SMS_PF	0x10
117 	u_int8_t unused[2];
118 	u_int8_t length;
119 	u_int8_t control;
120 };
121 
122 struct scsi_mode_select_big {
123 	u_int8_t opcode;
124 	u_int8_t byte2;		/* same bits as small version */
125 	u_int8_t unused[5];
126 	u_int8_t length[2];
127 	u_int8_t control;
128 };
129 
130 struct scsi_reserve {
131 	u_int8_t opcode;
132 	u_int8_t byte2;
133 	u_int8_t unused[2];
134 	u_int8_t length;
135 	u_int8_t control;
136 };
137 
138 struct scsi_release {
139 	u_int8_t opcode;
140 	u_int8_t byte2;
141 	u_int8_t unused[2];
142 	u_int8_t length;
143 	u_int8_t control;
144 };
145 
146 struct scsi_prevent {
147 	u_int8_t opcode;
148 	u_int8_t byte2;
149 	u_int8_t unused[2];
150 	u_int8_t how;
151 	u_int8_t control;
152 };
153 #define	PR_PREVENT 0x01
154 #define PR_ALLOW   0x00
155 
156 struct scsi_changedef {
157 	u_int8_t opcode;
158 	u_int8_t byte2;
159 	u_int8_t unused1;
160 	u_int8_t how;
161 	u_int8_t unused[4];
162 	u_int8_t datalen;
163 	u_int8_t control;
164 };
165 #define SC_SCSI_1 0x01
166 #define SC_SCSI_2 0x03
167 
168 /*
169  * Opcodes
170  */
171 #define	TEST_UNIT_READY		0x00
172 #define REQUEST_SENSE		0x03
173 #define INQUIRY			0x12
174 #define MODE_SELECT		0x15
175 #define MODE_SENSE		0x1a
176 #define START_STOP		0x1b
177 #define RESERVE      		0x16
178 #define RELEASE      		0x17
179 #define PREVENT_ALLOW		0x1e
180 #define POSITION_TO_ELEMENT	0x2b
181 #define	CHANGE_DEFINITION	0x40
182 #define	MODE_SENSE_BIG		0x54
183 #define	MODE_SELECT_BIG		0x55
184 
185 /*
186  * sense data format
187  */
188 #define T_DIRECT	0
189 #define T_SEQUENTIAL	1
190 #define T_PRINTER	2
191 #define T_PROCESSOR	3
192 #define T_WORM		4
193 #define T_CDROM		5
194 #define T_SCANNER 	6
195 #define T_OPTICAL 	7
196 #define T_NODEVICE	0x1F
197 
198 #define T_CHANGER	8
199 #define T_COMM		9
200 
201 #define T_REMOV		1
202 #define	T_FIXED		0
203 
204 struct scsi_inquiry_data {
205 	u_int8_t device;
206 #define	SID_TYPE	0x1F
207 #define	SID_QUAL	0xE0
208 #define	SID_QUAL_LU_OK	0x00
209 #define	SID_QUAL_LU_OFFLINE	0x20
210 #define	SID_QUAL_RSVD	0x40
211 #define	SID_QUAL_BAD_LU	0x60
212 	u_int8_t dev_qual2;
213 #define	SID_QUAL2	0x7F
214 #define	SID_REMOVABLE	0x80
215 	u_int8_t version;
216 #define SID_ANSII	0x07
217 #define SID_ECMA	0x38
218 #define SID_ISO		0xC0
219 	u_int8_t response_format;
220 	u_int8_t additional_length;
221 	u_int8_t unused[2];
222 	u_int8_t flags;
223 #define	SID_SftRe	0x01
224 #define	SID_CmdQue	0x02
225 #define	SID_Linked	0x08
226 #define	SID_Sync	0x10
227 #define	SID_WBus16	0x20
228 #define	SID_WBus32	0x40
229 #define	SID_RelAdr	0x80
230 	char	vendor[8];
231 	char	product[16];
232 	char	revision[4];
233 	u_int8_t extra[8];
234 };
235 
236 struct scsi_sense_data_unextended {
237 /* 1*/	u_int8_t error_code;
238 /* 4*/	u_int8_t block[3];
239 };
240 
241 struct scsi_sense_data {
242 /* 1*/	u_int8_t error_code;
243 #define	SSD_ERRCODE		0x7F
244 #define	SSD_ERRCODE_VALID	0x80
245 /* 2*/	u_int8_t segment;
246 /* 3*/	u_int8_t flags;
247 #define	SSD_KEY		0x0F
248 #define	SSD_ILI		0x20
249 #define	SSD_EOM		0x40
250 #define	SSD_FILEMARK	0x80
251 /* 7*/	u_int8_t info[4];
252 /* 8*/	u_int8_t extra_len;
253 /*12*/	u_int8_t cmd_spec_info[4];
254 /*13*/	u_int8_t add_sense_code;
255 /*14*/	u_int8_t add_sense_code_qual;
256 /*15*/	u_int8_t fru;
257 /*16*/	u_int8_t sense_key_spec_1;
258 #define	SSD_SCS_VALID	0x80
259 /*17*/	u_int8_t sense_key_spec_2;
260 /*18*/	u_int8_t sense_key_spec_3;
261 /*32*/	u_int8_t extra_bytes[14];
262 };
263 
264 struct scsi_blk_desc {
265 	u_int8_t density;
266 	u_int8_t nblocks[3];
267 	u_int8_t reserved;
268 	u_int8_t blklen[3];
269 };
270 
271 struct scsi_mode_header {
272 	u_int8_t data_length;	/* Sense data length */
273 	u_int8_t medium_type;
274 	u_int8_t dev_spec;
275 	u_int8_t blk_desc_len;
276 };
277 
278 struct scsi_mode_header_big {
279 	u_int8_t data_length[2];	/* Sense data length */
280 	u_int8_t medium_type;
281 	u_int8_t dev_spec;
282 	u_int8_t unused[2];
283 	u_int8_t blk_desc_len[2];
284 };
285 
286 
287 /*
288  * Status Byte
289  */
290 #define	SCSI_OK		0x00
291 #define	SCSI_CHECK	0x02
292 #define	SCSI_BUSY	0x08
293 #define SCSI_INTERM	0x10
294 #define SCSI_QUEUE_FULL		0x28
295 
296 #endif /* _SCSI_SCSI_ALL_H */
297