scsipi_all.h revision 1.15.6.2 1 1.15.6.2 nathanw /* $NetBSD: scsipi_all.h,v 1.15.6.2 2001/09/21 22:36:13 nathanw Exp $ */
2 1.2 bouyer
3 1.2 bouyer /*
4 1.2 bouyer * SCSI and SCSI-like general interface description
5 1.2 bouyer */
6 1.2 bouyer
7 1.2 bouyer /*
8 1.2 bouyer * Largely written by Julian Elischer (julian (at) tfs.com)
9 1.2 bouyer * for TRW Financial Systems.
10 1.2 bouyer *
11 1.2 bouyer * TRW Financial Systems, in accordance with their agreement with Carnegie
12 1.2 bouyer * Mellon University, makes this software available to CMU to distribute
13 1.3 enami * or use in any manner that they see fit as long as this message is kept with
14 1.2 bouyer * the software. For this reason TFS also grants any other persons or
15 1.2 bouyer * organisations permission to use or modify this software.
16 1.2 bouyer *
17 1.2 bouyer * TFS supplies this software to be publicly redistributed
18 1.2 bouyer * on the understanding that TFS is not responsible for the correct
19 1.2 bouyer * functioning of this software in any circumstances.
20 1.2 bouyer *
21 1.2 bouyer * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
22 1.2 bouyer */
23 1.2 bouyer
24 1.11 thorpej #ifndef _DEV_SCSIPI_SCSIPI_ALL_H_
25 1.11 thorpej #define _DEV_SCSIPI_SCSIPI_ALL_H_
26 1.11 thorpej
27 1.2 bouyer /*
28 1.2 bouyer * SCSI-like command format and opcode
29 1.2 bouyer */
30 1.2 bouyer
31 1.8 mjacob /*
32 1.8 mjacob * Some basic, common SCSI command group definitions.
33 1.8 mjacob */
34 1.8 mjacob
35 1.8 mjacob #define CDB_GROUPID(cmd) ((cmd >> 5) & 0x7)
36 1.8 mjacob #define CDB_GROUPID_0 0
37 1.8 mjacob #define CDB_GROUPID_1 1
38 1.8 mjacob #define CDB_GROUPID_2 2
39 1.8 mjacob #define CDB_GROUPID_3 3
40 1.8 mjacob #define CDB_GROUPID_4 4
41 1.8 mjacob #define CDB_GROUPID_5 5
42 1.8 mjacob #define CDB_GROUPID_6 6
43 1.8 mjacob #define CDB_GROUPID_7 7
44 1.8 mjacob
45 1.8 mjacob #define CDB_GROUP0 6 /* 6-byte cdb's */
46 1.8 mjacob #define CDB_GROUP1 10 /* 10-byte cdb's */
47 1.8 mjacob #define CDB_GROUP2 10 /* 10-byte cdb's */
48 1.8 mjacob #define CDB_GROUP3 0 /* reserved */
49 1.8 mjacob #define CDB_GROUP4 16 /* 16-byte cdb's */
50 1.8 mjacob #define CDB_GROUP5 12 /* 12-byte cdb's */
51 1.8 mjacob #define CDB_GROUP6 0 /* vendor specific */
52 1.8 mjacob #define CDB_GROUP7 0 /* vendor specific */
53 1.8 mjacob
54 1.8 mjacob /*
55 1.8 mjacob * Some basic, common SCSI commands
56 1.8 mjacob */
57 1.2 bouyer #define TEST_UNIT_READY 0x00
58 1.2 bouyer struct scsipi_test_unit_ready {
59 1.2 bouyer u_int8_t opcode;
60 1.2 bouyer u_int8_t byte2;
61 1.2 bouyer u_int8_t unused[3];
62 1.2 bouyer u_int8_t control;
63 1.2 bouyer };
64 1.2 bouyer
65 1.3 enami #define REQUEST_SENSE 0x03
66 1.2 bouyer struct scsipi_sense {
67 1.2 bouyer u_int8_t opcode;
68 1.2 bouyer u_int8_t byte2;
69 1.2 bouyer u_int8_t unused[2];
70 1.2 bouyer u_int8_t length;
71 1.2 bouyer u_int8_t control;
72 1.2 bouyer };
73 1.2 bouyer
74 1.15.6.1 nathanw #define MODE_SENSE 0x1a
75 1.15.6.1 nathanw struct scsipi_mode_sense {
76 1.15.6.1 nathanw u_int8_t opcode;
77 1.15.6.1 nathanw u_int8_t byte2;
78 1.15.6.1 nathanw #define SMS_DBD 0x08 /* disable block descriptors */
79 1.15.6.1 nathanw u_int8_t page;
80 1.15.6.1 nathanw #define SMS_PAGE_CODE 0x3F
81 1.15.6.1 nathanw #define SMS_PAGE_CTRL 0xC0
82 1.15.6.1 nathanw #define SMS_PAGE_CTRL_CURRENT 0x00
83 1.15.6.1 nathanw #define SMS_PAGE_CTRL_CHANGEABLE 0x40
84 1.15.6.1 nathanw #define SMS_PAGE_CTRL_DEFAULT 0x80
85 1.15.6.1 nathanw #define SMS_PAGE_CTRL_SAVED 0xC0
86 1.15.6.1 nathanw union {
87 1.15.6.1 nathanw struct {
88 1.15.6.1 nathanw u_int8_t unused;
89 1.15.6.1 nathanw u_int8_t length;
90 1.15.6.1 nathanw } scsi __attribute__((packed));
91 1.15.6.1 nathanw struct {
92 1.15.6.1 nathanw u_int8_t length[2];
93 1.15.6.1 nathanw } atapi __attribute__((packed));
94 1.15.6.1 nathanw } u_len;
95 1.15.6.1 nathanw u_int8_t control;
96 1.15.6.1 nathanw } __attribute__((packed));
97 1.15.6.1 nathanw
98 1.15.6.1 nathanw #define MODE_SENSE_BIG 0x5A
99 1.15.6.1 nathanw struct scsipi_mode_sense_big {
100 1.15.6.1 nathanw u_int8_t opcode;
101 1.15.6.1 nathanw u_int8_t byte2; /* same bits as small version */
102 1.15.6.1 nathanw u_int8_t page; /* same bits as small version */
103 1.15.6.1 nathanw u_int8_t unused[4];
104 1.15.6.1 nathanw u_int8_t length[2];
105 1.15.6.1 nathanw u_int8_t control;
106 1.15.6.1 nathanw } __attribute__((packed));
107 1.15.6.1 nathanw
108 1.15.6.1 nathanw #define MODE_SELECT 0x15
109 1.15.6.1 nathanw struct scsipi_mode_select {
110 1.15.6.1 nathanw u_int8_t opcode;
111 1.15.6.1 nathanw u_int8_t byte2;
112 1.15.6.1 nathanw #define SMS_SP 0x01 /* save page */
113 1.15.6.2 nathanw #define SMS_PF 0x10 /* page format (0 = SCSI-1, 1 = SCSI-2) */
114 1.15.6.1 nathanw u_int8_t unused;
115 1.15.6.1 nathanw union {
116 1.15.6.1 nathanw struct {
117 1.15.6.1 nathanw u_int8_t unused;
118 1.15.6.1 nathanw u_int8_t length;
119 1.15.6.1 nathanw } scsi __attribute__((packed));
120 1.15.6.1 nathanw struct {
121 1.15.6.1 nathanw u_int8_t length[2];
122 1.15.6.1 nathanw } atapi __attribute__((packed));
123 1.15.6.1 nathanw } u_len;
124 1.15.6.1 nathanw u_int8_t control;
125 1.15.6.1 nathanw } __attribute__((packed));
126 1.15.6.1 nathanw
127 1.15.6.1 nathanw #define MODE_SELECT_BIG 0x55
128 1.15.6.1 nathanw struct scsipi_mode_select_big {
129 1.15.6.1 nathanw u_int8_t opcode;
130 1.15.6.1 nathanw u_int8_t byte2; /* same bits as small version */
131 1.15.6.1 nathanw u_int8_t unused[5];
132 1.15.6.1 nathanw u_int8_t length[2];
133 1.15.6.1 nathanw u_int8_t control;
134 1.15.6.1 nathanw } __attribute__((packed));
135 1.15.6.1 nathanw
136 1.3 enami #define INQUIRY 0x12
137 1.2 bouyer struct scsipi_inquiry {
138 1.2 bouyer u_int8_t opcode;
139 1.2 bouyer u_int8_t byte2;
140 1.2 bouyer u_int8_t unused[2];
141 1.2 bouyer u_int8_t length;
142 1.2 bouyer u_int8_t control;
143 1.15.6.1 nathanw } __attribute__((packed));
144 1.2 bouyer
145 1.3 enami #define PREVENT_ALLOW 0x1e
146 1.2 bouyer struct scsipi_prevent {
147 1.2 bouyer u_int8_t opcode;
148 1.2 bouyer u_int8_t byte2;
149 1.2 bouyer u_int8_t unused[2];
150 1.2 bouyer u_int8_t how;
151 1.2 bouyer u_int8_t control;
152 1.15.6.1 nathanw } __attribute__((packed));
153 1.2 bouyer #define PR_PREVENT 0x01
154 1.3 enami #define PR_ALLOW 0x00
155 1.2 bouyer
156 1.2 bouyer /*
157 1.2 bouyer * inquiry and sense data format
158 1.2 bouyer */
159 1.2 bouyer
160 1.2 bouyer struct scsipi_sense_data {
161 1.3 enami /* 1*/ u_int8_t error_code;
162 1.3 enami #define SSD_ERRCODE 0x7F
163 1.3 enami #define SSD_ERRCODE_VALID 0x80
164 1.3 enami /* 2*/ u_int8_t segment;
165 1.3 enami /* 3*/ u_int8_t flags;
166 1.3 enami #define SSD_KEY 0x0F
167 1.3 enami #define SSD_ILI 0x20
168 1.3 enami #define SSD_EOM 0x40
169 1.3 enami #define SSD_FILEMARK 0x80
170 1.3 enami /* 7*/ u_int8_t info[4];
171 1.3 enami /* 8*/ u_int8_t extra_len;
172 1.3 enami /*12*/ u_int8_t cmd_spec_info[4];
173 1.3 enami /*13*/ u_int8_t add_sense_code;
174 1.3 enami /*14*/ u_int8_t add_sense_code_qual;
175 1.3 enami /*15*/ u_int8_t fru;
176 1.3 enami /*16*/ u_int8_t sense_key_spec_1;
177 1.3 enami #define SSD_SCS_VALID 0x80
178 1.3 enami /*17*/ u_int8_t sense_key_spec_2;
179 1.3 enami /*18*/ u_int8_t sense_key_spec_3;
180 1.3 enami /*32*/ u_int8_t extra_bytes[14];
181 1.15.6.1 nathanw } __attribute__((packed));
182 1.9 mjacob
183 1.9 mjacob #define SKEY_NO_SENSE 0x00
184 1.10 mjacob #define SKEY_RECOVERED_ERROR 0x01
185 1.9 mjacob #define SKEY_NOT_READY 0x02
186 1.9 mjacob #define SKEY_MEDIUM_ERROR 0x03
187 1.9 mjacob #define SKEY_HARDWARE_ERROR 0x04
188 1.9 mjacob #define SKEY_ILLEGAL_REQUEST 0x05
189 1.9 mjacob #define SKEY_UNIT_ATTENTION 0x06
190 1.9 mjacob #define SKEY_WRITE_PROTECT 0x07
191 1.9 mjacob #define SKEY_BLANK_CHECK 0x08
192 1.9 mjacob #define SKEY_VENDOR_UNIQUE 0x09
193 1.9 mjacob #define SKEY_COPY_ABORTED 0x0A
194 1.9 mjacob #define SKEY_ABORTED_COMMAND 0x0B
195 1.9 mjacob #define SKEY_EQUAL 0x0C
196 1.9 mjacob #define SKEY_VOLUME_OVERFLOW 0x0D
197 1.9 mjacob #define SKEY_MISCOMPARE 0x0E
198 1.9 mjacob #define SKEY_RESERVED 0x0F
199 1.9 mjacob
200 1.4 mjacob /*
201 1.4 mjacob * Sense bytes described by the extra_len tag start at cmd_spec_info,
202 1.4 mjacob * and can only continue up to the end of the structure we've defined
203 1.4 mjacob * (which is too short for some cases).
204 1.4 mjacob */
205 1.4 mjacob #define ADD_BYTES_LIM(sp) \
206 1.12 dbj ((((int)(sp)->extra_len) < (int) sizeof(struct scsipi_sense_data) - 8)? \
207 1.12 dbj ((sp)->extra_len) : (sizeof (struct scsipi_sense_data) - 8))
208 1.4 mjacob
209 1.2 bouyer
210 1.2 bouyer struct scsipi_sense_data_unextended {
211 1.5 thorpej /* 1*/ u_int8_t error_code;
212 1.3 enami /* 4*/ u_int8_t block[3];
213 1.15.6.1 nathanw } __attribute__((packed));
214 1.2 bouyer
215 1.5 thorpej #define T_REMOV 1 /* device is removable */
216 1.5 thorpej #define T_FIXED 0 /* device is not removable */
217 1.2 bouyer
218 1.2 bouyer /*
219 1.13 dante * According to SPC-2r16, in order to know if a U3W device support PPR,
220 1.15.6.1 nathanw * Inquiry Data structure should be at least 57 Bytes
221 1.2 bouyer */
222 1.2 bouyer
223 1.2 bouyer struct scsipi_inquiry_data {
224 1.13 dante /* 1*/ u_int8_t device;
225 1.15.6.1 nathanw #define SID_TYPE 0x1f /* device type mask */
226 1.15.6.1 nathanw #define SID_QUAL 0xe0 /* device qualifier mask */
227 1.15.6.1 nathanw #define SID_QUAL_LU_PRESENT 0x00 /* logical unit present */
228 1.15.6.1 nathanw #define SID_QUAL_LU_NOTPRESENT 0x20 /* logical unit not present */
229 1.15.6.1 nathanw #define SID_QUAL_reserved 0x40
230 1.15.6.1 nathanw #define SID_QUAL_LU_NOT_SUPP 0x60 /* logical unit not supported */
231 1.15.6.1 nathanw
232 1.15.6.1 nathanw #define T_DIRECT 0x00 /* direct access device */
233 1.15.6.1 nathanw #define T_SEQUENTIAL 0x01 /* sequential access device */
234 1.15.6.1 nathanw #define T_PRINTER 0x02 /* printer device */
235 1.15.6.1 nathanw #define T_PROCESSOR 0x03 /* processor device */
236 1.15.6.1 nathanw #define T_WORM 0x04 /* write once, read many device */
237 1.15.6.1 nathanw #define T_CDROM 0x05 /* cd-rom device */
238 1.15.6.1 nathanw #define T_SCANNER 0x06 /* scanner device */
239 1.15.6.1 nathanw #define T_OPTICAL 0x07 /* optical memory device */
240 1.15.6.1 nathanw #define T_CHANGER 0x08 /* medium changer device */
241 1.15.6.1 nathanw #define T_COMM 0x09 /* communication device */
242 1.15.6.1 nathanw #define T_IT8_1 0x0a /* Defined by ASC IT8... */
243 1.15.6.1 nathanw #define T_IT8_2 0x0b /* ...(Graphic arts pre-press devices) */
244 1.15.6.1 nathanw #define T_STORARRAY 0x0c /* storage array device */
245 1.15.6.1 nathanw #define T_ENCLOSURE 0x0d /* enclosure services device */
246 1.15.6.1 nathanw #define T_SIMPLE_DIRECT 0x0E /* Simplified direct-access device */
247 1.15.6.1 nathanw #define T_OPTIC_CARD_RW 0x0F /* Optical card reader/writer device */
248 1.15.6.1 nathanw #define T_OBJECT_STORED 0x11 /* Object-based Storage Device */
249 1.15.6.1 nathanw #define T_NODEVICE 0x1f
250 1.15.6.1 nathanw
251 1.15.6.1 nathanw u_int8_t dev_qual2;
252 1.15.6.1 nathanw #define SID_QUAL2 0x7F
253 1.15.6.1 nathanw #define SID_REMOVABLE 0x80
254 1.15.6.1 nathanw
255 1.13 dante /* 3*/ u_int8_t version;
256 1.3 enami #define SID_ANSII 0x07
257 1.3 enami #define SID_ECMA 0x38
258 1.3 enami #define SID_ISO 0xC0
259 1.15.6.1 nathanw
260 1.13 dante /* 4*/ u_int8_t response_format;
261 1.13 dante #define SID_RespDataFmt 0x0F
262 1.15.6.1 nathanw #define SID_FORMAT_SCSI1 0x00 /* SCSI-1 format */
263 1.15.6.1 nathanw #define SID_FORMAT_CCS 0x01 /* SCSI CCS format */
264 1.15.6.1 nathanw #define SID_FORMAT_ISO 0x02 /* ISO format */
265 1.15.6.1 nathanw
266 1.13 dante /* 5*/ u_int8_t additional_length; /* n-4 */
267 1.13 dante /* 6*/ u_int8_t flags1;
268 1.13 dante #define SID_SCC 0x80
269 1.13 dante /* 7*/ u_int8_t flags2;
270 1.13 dante #define SID_Addr16 0x01
271 1.15.6.1 nathanw #define SID_MChngr 0x08
272 1.13 dante #define SID_MultiPort 0x10
273 1.13 dante #define SID_EncServ 0x40
274 1.13 dante #define SID_BasQue 0x80
275 1.13 dante /* 8*/ u_int8_t flags3;
276 1.2 bouyer #define SID_SftRe 0x01
277 1.2 bouyer #define SID_CmdQue 0x02
278 1.2 bouyer #define SID_Linked 0x08
279 1.2 bouyer #define SID_Sync 0x10
280 1.2 bouyer #define SID_WBus16 0x20
281 1.2 bouyer #define SID_WBus32 0x40
282 1.2 bouyer #define SID_RelAdr 0x80
283 1.15.6.1 nathanw /* 9*/ char vendor[8];
284 1.15.6.1 nathanw /*17*/ char product[16];
285 1.15.6.1 nathanw /*33*/ char revision[4];
286 1.13 dante /*37*/ u_int8_t vendor_specific[20];
287 1.13 dante /*57*/ u_int8_t flags4;
288 1.15.6.1 nathanw #define SID_IUS 0x01
289 1.15.6.1 nathanw #define SID_QAS 0x02
290 1.15.6.1 nathanw #define SID_Clocking 0x0C
291 1.15.6.1 nathanw #define SID_CLOCKING_ST_ONLY 0x00
292 1.15.6.1 nathanw #define SID_CLOCKING_DT_ONLY 0x04
293 1.15.6.1 nathanw #define SID_CLOCKING_SD_DT 0x0C
294 1.13 dante /*58*/ u_int8_t reserved;
295 1.15.6.1 nathanw /*59*/ char version_descriptor[8][2];
296 1.15.6.1 nathanw } __attribute__((packed)); /* 74 Bytes */
297 1.15.6.1 nathanw
298 1.15.6.1 nathanw /* Data structures for mode select/mode sense */
299 1.15.6.1 nathanw struct scsipi_mode_header {
300 1.15.6.1 nathanw u_int8_t data_length; /* Sense data length */
301 1.15.6.1 nathanw u_int8_t medium_type;
302 1.15.6.1 nathanw u_int8_t dev_spec;
303 1.15.6.1 nathanw u_int8_t blk_desc_len; /* unused on ATAPI */
304 1.15.6.1 nathanw } __attribute__((packed));
305 1.15.6.1 nathanw
306 1.15.6.1 nathanw struct scsipi_mode_header_big {
307 1.15.6.1 nathanw u_int8_t data_length[2]; /* Sense data length */
308 1.15.6.1 nathanw u_int8_t medium_type;
309 1.15.6.1 nathanw u_int8_t dev_spec;
310 1.15.6.1 nathanw u_int8_t unused[2]; /* unused on ATAPI */
311 1.15.6.1 nathanw u_int8_t blk_desc_len[2]; /* unused on ATAPI */
312 1.15.6.1 nathanw } __attribute__((packed));
313 1.15.6.1 nathanw
314 1.15.6.2 nathanw /*
315 1.15.6.2 nathanw * This part is common to all mode pages.
316 1.15.6.2 nathanw */
317 1.15.6.2 nathanw struct scsipi_mode_page_header {
318 1.15.6.2 nathanw u_int8_t pg_code; /* page code */
319 1.15.6.2 nathanw #define PGCODE_MASK 0x3f /* page code mask */
320 1.15.6.2 nathanw #define PGCODE_PS 0x80 /* page is savable */
321 1.15.6.2 nathanw u_int8_t pg_length; /* page length (not including hdr) */
322 1.15.6.2 nathanw } __attribute__((__packed__));
323 1.11 thorpej
324 1.11 thorpej #endif /* _DEV_SCSIPI_SCSIPI_ALL_H_ */
325