xref: /original-bsd/sys/dev/scsi/scsi.h (revision 3705696b)
1 /*
2  * Copyright (c) 1992, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This software was developed by the Computer Systems Engineering group
6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7  * contributed to Berkeley.
8  *
9  * All advertising materials mentioning features or use of this software
10  * must display the following acknowledgement:
11  *	This product includes software developed by the University of
12  *	California, Lawrence Berkeley Laboratories.
13  *
14  * %sccs.include.redist.c%
15  *
16  *	@(#)scsi.h	8.1 (Berkeley) 06/10/93
17  *
18  * from: $Header: scsi.h,v 1.5 93/02/01 19:19:15 torek Exp $ (LBL)
19  */
20 
21 /*
22  * Machine independent SCSI defintions.
23  */
24 
25 /*
26  * Mostly-generic command descriptor blocks (6 and 10 bytes).
27  * Note that no SCSI command uses the 12 byte variety, hence it
28  * is not defined here.
29  */
30 struct scsi_cdb6 {
31 	u_char	cdb_cmd,	/* command code */
32 		cdb_lun_lbah,	/* logical unit number, & lba (MSB) */
33 		cdb_lbam,	/* logical block address */
34 		cdb_lbal,	/* logical block address (LSB) */
35 		cdb_len,	/* transfer length */
36 		cdb_ctrl;	/* control byte */
37 };
38 
39 struct scsi_cdb10 {
40 	u_char	cdb_cmd,	/* command code */
41 		cdb_lun_rel,	/* logical unit number, rsvd, & reladr flag */
42 		cdb_lbah,	/* logical block address (MSB) */
43 		cdb_lbahm,	/* logical block address (high middle byte) */
44 		cdb_lbalm,	/* logical block address (low middle byte) */
45 		cdb_lbal,	/* logical block address (LSB) */
46 		cdb_xxx,	/* reserved */
47 		cdb_lenh,	/* transfer length (MSB) */
48 		cdb_lenl,	/* transfer length (LSB) */
49 		cdb_ctrl;	/* control byte */
50 };
51 
52 /*
53  * SCSI `generic' cdb.
54  * The length of the cdb is implicit in the first byte (see scsivar.h).
55  * This is 16 bytes, rather than 10 or 12, just to help out alignment.
56  */
57 struct scsi_cdb {
58 	u_char	cdb_bytes[16];	/* up to 16 bytes of command */
59 };
60 #define CDB6(cdb)	((struct scsi_cdb6 *)&(cdb)->cdb_bytes[0])
61 #define CDB10(cdb)	((struct scsi_cdb10 *)&(cdb)->cdb_bytes[0])
62 
63 /*
64  * SCSI command (cdb_cmd/cdb_bytes[0]) byte definitions.  Only those
65  * that are common across all devices are actually defined here.
66  * (The SCSI standard defines six groups of devices: direct access,
67  * sequential access, printer, processor, WORM direct access, and
68  * ROM direct access.  DADs and SADs are basically `disk' and `tape';
69  * printers and processors are obvious; and WORMs and ROMs are really
70  * just disks that are missing one or two operations.  A few commands
71  * are required of all devices; these are defined here, and the others
72  * are defined in separate headers.)
73  *
74  * Letter flags in parentheses in the comment column indicate:
75  *	M = mandatory (command is implemented on all SCSI devices)
76  *	E = extended (command implemented if SCSI device does extended SCSI)
77  *	O = optional
78  *	R = reserved to future SCSI standard
79  *	V = vendor unique
80  *	* = depends on device type
81  *
82  * Note that SCSI commands are broken into 8 `groups' given by bits 7..5.
83  * Group 0 is 6-byte commands, 1 is 10-byte commands, and 5 is 12-byte
84  * commands (of which none exist); groups 6 and 7 are vendor unique.
85  * Commands are normally just treated as a simple 8-bit number,
86  * but the size of the associated cdb is implied by the group.
87  */
88 	/* group 0 */
89 #define	CMD_TEST_UNIT_READY	0x00	/* (O) test unit ready */
90 /*				0x01	   (*) */
91 /*				0x02	   (V) */
92 #define	CMD_REQUEST_SENSE	0x03	/* (M) request sense */
93 /*				0x04..0x05 (*) */
94 /*				0x06	   (V) */
95 /*				0x07..0x08 (*) */
96 /*				0x09	   (V) */
97 /*				0x0a..0x0b (*) */
98 /*				0x0c..0x0e (V) */
99 /*				0x0f..0x11 (*) */
100 #define	CMD_INQUIRY		0x12	/* (E) inquiry */
101 /*				0x13..0x17 (*) */
102 #define	CMD_COPY		0x18	/* (O) copy */
103 /*				0x19..0x1b (*) */
104 #define	CMD_RECEIVE_DIAG	0x1c	/* (O) receive diagnostic results */
105 #define	CMD_SEND_DIAG		0x1d	/* (O) send diagnostic */
106 /*				0x1e	   (*) */
107 /*				0x1f	   (R) */
108 	/* group 1 */
109 /*				0x20..0x24 (V) */
110 /*				0x25	   (*) */
111 /*				0x26..0x27 (V) */
112 /*				0x28	   (*) */
113 /*				0x29	   (V) */
114 /*				0x2a..0x2b (*) */
115 /*				0x2c..0x2d (V) */
116 /*				0x2e..0x33 (*) */
117 /*				0x34..0x37 (R) */
118 #define	CMD_COMPARE		0x38	/* (O) compare */
119 #define	CMD_COMPARE_VERIFY	0x39	/* (O) compare and verify */
120 /*				0x3a..0x3f (R) */
121 	/* group 2 (40-5f) reserved */
122 	/* group 3 (60-7f) reserved */
123 	/* group 4 (80-9f) reserved */
124 	/* group 5 (a0-bf) reserved */
125 	/* group 6 (c0-df) vendor unique */
126 	/* group 7 (e0-ff) vendor unique */
127 
128 /*
129  * SCSI control byte.
130  * Bits 7 and 6 are vendor unique; bits 5, 4, 3, and 2 are reserved.
131  * Bit 1 may be 1 only if bit 0 is 1; if so, it tells the target to
132  * send a LINKED COMMAND COMPLETE (WITH FLAG) message.  If not, but
133  * bit 0 is set, this tells the target to send a LINKED COMMAND COMPLETE
134  * message.
135  */
136 #define	CTRL_VU_MASK		0xc0	/* vendor unique */
137 #define	CTRL_RSVD		0x3c	/* reserved, must be zero */
138 #define	CTRL_LCCF		0x02	/* send LCCF if sending LCC */
139 #define	CTRL_LINK		0x01	/* linked command */
140 
141 /*
142  * Generic sense: regular and extended.
143  * A sense operation returned an extended sense iff the error class
144  * is 7.  The format is vendor unique unless the error code is 0.
145  * The regular and extended formats are completely different; we
146  * define macros to obtain values from them.
147  */
148 struct scsi_sense {
149 	u_char	sn_vcc;		/* valid bit, error class, & error code */
150 	u_char	sn_var[7];	/* bytes 1-3, or 1-7; variant formats */
151 	u_char	sn_addl[32-8];	/* additional sense data, if extended */
152 };
153 
154 #define	SENSE_ECLASS(sn)	(((sn)->sn_vcc >> 4) & 7)
155 #define	SENSE_ECODE(sn)		((sn)->sn_vcc & 0xf)
156 #define	SENSE_ISXSENSE(sn)	(SENSE_ECLASS(sn) == 7)
157 
158 /* for non-extended sense (`r'egular or `r'estricted sense) */
159 #define	RSENSE_LVALID(sn)	((sn)->sn_vcc & 0x80)
160 #define	RSENSE_VU(sn)		((sn)->sn_var[0] >> 5)
161 #define	RSENSE_LBA(sn) \
162   ((((sn)->sn_var[0] & 0x1f) << 16) | ((sn)->sn_var[1] << 8) | (sn)->sn_var[2])
163 
164 /* for extended sense */
165 #define	XSENSE_ISSTD(sn)	(SENSE_ECODE(sn) == 0)
166 			/* if not standard, cannot interpret it at all */
167 #define	XSENSE_IVALID(sn)	((sn)->sn_vcc & 0x80)
168 #define	XSENSE_SEG(sn)		((sn)->sn_var[0])
169 #define	XSENSE_FM(sn)		((sn)->sn_var[1] & 0x80) /* filemark */
170 #define	XSENSE_EOM(sn)		((sn)->sn_var[1] & 0x40) /* end of media */
171 #define	XSENSE_ILI(sn)		((sn)->sn_var[1] & 0x20) /* incor length ind */
172 #define	XSENSE_KEY(sn)		((sn)->sn_var[1] & 0x0f) /* sense key */
173 #define	XSENSE_INFO(sn) \
174 	(((sn)->sn_var[2] << 24) | ((sn)->sn_var[3] << 16) | \
175 	 ((sn)->sn_var[4] << 8) | (sn)->sn_var[5])
176 #define	XSENSE_ADDL(sn)		((sn)->sn_var[6])	/* add'l sense len */
177 
178 /*
179  * SCSI INQUIRY data: general, and ANSI versions 1 and 2
180  * (including common command set).
181  */
182 struct scsi_inquiry {
183 	u_char	si_type;	/* peripheral device type (below) */
184 	u_char	si_qual;	/* qualifier (see below) */
185 	u_char	si_version;	/* version (see below) */
186 	u_char	si_v2info;	/* scsi version 2 stuff (see below) */
187 	u_char	si_len;		/* additional length */
188 	u_char	si_more[252-5];	/* actually si_len bytes */
189 };
190 struct scsi_inq_ansi {
191 	u_char	si_type;	/* peripheral qualifier and device type */
192 	u_char	si_qual;	/* RMB and device type qualifier */
193 	u_char	si_version;	/* ISO, ECMA and ANSI-approved versions */
194 	u_char	si_v2info;	/* ? */
195 	u_char	si_len;		/* addition length */
196 	char	si_xxx1[2];	/* reserved */
197 	char	si_flags;	/* (see below) */
198 	char	si_vendor[8];	/* vendor (blank padded) */
199 	char	si_product[16];	/* product (blank padded) */
200 	char	si_rev[4];	/* revision (blank padded) */
201 
202 	/* scsi version 2 stuff follows */
203 	char	si_vend1[20];	/* vendor specific */
204 	char	si_xxx2[40];	/* reserved */
205 	char	si_vend2[252-96]; /* vendor specific parameters */
206 };
207 
208 /* peripheral device types */
209 #define TYPE_QUAL_MASK		0xe0	/* peripheral qualifer mask */
210 #define TYPE_TYPE_MASK		0x1f	/* peripheral device type mask */
211 #define TYPE_QUAL_NORM		0x00	/* device is normal */
212 #define TYPE_QUAL_NOTCONN	0x20	/* not connected */
213 #define TYPE_QUAL_XXX		0x40	/* reserved */
214 #define TYPE_QUAL_NOLUN		0x60	/* logical unit not supported */
215 #define TYPE_QUAL_VT4		0x80	/* vendor specific type 4 */
216 #define TYPE_QUAL_VT5		0xa0	/* vendor specific type 5 */
217 #define TYPE_QUAL_VT6		0xc0	/* vendor specific type 6 */
218 #define TYPE_QUAL_VT7		0xe0	/* vendor specific type 7 */
219 
220 #define	TYPE_DAD		0x00	/* direct access device (disk) */
221 #define	TYPE_SAD		0x01	/* sequential access device (tape) */
222 #define	TYPE_PRINTER		0x02	/* printer */
223 #define	TYPE_PROCESSOR		0x03	/* processor */
224 #define	TYPE_WORM		0x04	/* WORM disk */
225 #define	TYPE_ROM		0x05	/* CD-ROM disk */
226 #define	TYPE_SCANNER		0x06	/* scanner */
227 #define	TYPE_MO			0x07	/* magneto-optical */
228 #define	TYPE_JUKEBOX		0x08	/* medium changer */
229 #define	TYPE_LAN		0x09	/* communications device */
230 #define	TYPE_NP			0x1f	/* unknown or no device */
231 
232 /* qualifiers */
233 #define	QUAL_RMB		0x80	/* removable medium bit */
234 #define	QUAL_MASK		0x7f	/* mask for `user' bits */
235 
236 /* version (shifts and masks for subfields) */
237 #define	VER_ISO_SHIFT		6	/* ISO version: top 2 bits */
238 #define	VER_ISO_MASK		3
239 #define	VER_ECMA_SHIFT		3	/* ECMA version: middle 3 bits */
240 #define	VER_ECMA_MASK		7
241 #define	VER_ANSI_SHIFT		0	/* ANSI version: bottom 3 bits */
242 #define	VER_ANSI_MASK		7
243 
244 /* v2 info */
245 #define V2INFO_AENC		0x80	/* device can accept AEN data */
246 #define V2INFO_TRMIOP		0x40	/* supports TERMINATE I/O PROC msg */
247 #define V2INFO_XXX		0x30	/* reserved */
248 #define V2INFO_RDF_MASK		0x0f	/* response data format mask */
249 #define V2INFO_RDF_SCSI1	0x00	/* SCSI-1 standard INQUIRY data */
250 #define V2INFO_RDF_CCS		0x01	/* common command set INQUIRY data */
251 #define V2INFO_RDF_SCSI2	0x02	/* SCSI-2 standard INQUIRY data */
252 
253 /* flags */
254 #define V2FLAG_RELADR		0x80	/* supports relative addressing */
255 #define V2FLAG_WBUS32		0x40	/* supports 32 bit data xfer */
256 #define V2FLAG_WBUS16		0x20	/* supports 32 bit data xfer */
257 #define V2FLAG_SYNC		0x10	/* supports synchronous data xfer */
258 #define V2FLAG_LINKED		0x08	/* supports linked commands */
259 #define V2FLAG_XXX		0x04	/* reserved */
260 #define V2FLAG_CMDQUE		0x02	/* supports tagged command queueing */
261 #define V2FLAG_SOFTRESET	0x01	/* RST causes soft reset */
262 
263 /*
264  * SCSI message codes bytes.  The `command complete' code is required;
265  * all others are optional.  `Identify' is a flag bit, not a code (thus
266  * codes are actually at most 7 bits).
267  */
268 #define	MSG_IDENTIFY		0x80	/* flag => this is an identify msg */
269 #define	MSG_IDENTIFY_DR		0x40	/* IDENTIFY: flag => discon/resel ok */
270 #define	MSG_IDENTIFY_RSVD	0x38	/* IDENTIFY: these bits are reserved */
271 #define	MSG_IDENTIFY_LUN	0x07	/* IDENTIFY: these bits give LUN */
272 
273 #define	MSG_CMD_COMPLETE	0x00	/* command complete */
274 #define	MSG_EXT_MESSAGE		0x01	/* extended message */
275 #define	MSG_SAVE_DATA_PTR	0x02	/* save data pointer */
276 #define	MSG_RESTORE_PTR		0x03	/* restore pointers */
277 #define	MSG_DISCONNECT		0x04	/* disconnect */
278 #define	MSG_INIT_DETECT_ERROR	0x05	/* initiator detected error */
279 #define	MSG_ABORT		0x06	/* abort */
280 #define	MSG_REJECT		0x07	/* message reject */
281 #define	MSG_NOOP		0x08	/* no operation */
282 #define	MSG_PARITY_ERROR	0x09	/* message parity error */
283 #define	MSG_LCC			0x0a	/* linked command complete */
284 #define	MSG_LCCF		0x0b	/* linked command complete (w/ flag) */
285 #define	MSG_BUS_DEVICE_RESET	0x0c	/* bus device reset */
286 #define	MSG_ABORT_TAG		0x0d	/* abort tagged msg */
287 #define	MSG_CLEAR_QUEUE		0x0e	/* clear queue */
288 #define	MSG_INITIATE_RECOVERY	0x0f	/* initiate recovery */
289 #define	MSG_RELEASE_RECOVERY	0x10	/* release recovery */
290 #define	MSG_TERMINATE_PROCESS	0x11	/* ? */
291 #define	MSG_SIMPLE_Q_TAG	0x20	/* ? */
292 #define	MSG_HEAD_Q_TAG		0x21	/* ? */
293 #define	MSG_ORDERED_Q_TAG	0x22	/* ? */
294 #define	MSG_IGNORE_WIDE_RESID	0x23	/* ? */
295 
296 /*
297  * SCSI extended message format.
298  */
299 struct scsi_xmsg {
300 	u_char	xm_xmsg,	/* value 1, i.e., SMSG_EXT_MESSAGE */
301 		xm_len,		/* length of this extended message */
302 		xm_code,	/* actual code */
303 		xm_args[253];	/* actualy xm_len-1 bytes */
304 };
305 
306 /*
307  * SCSI extended message codes.
308  */
309 #define	XMSG_MDP		0x00	/* modify data pointer */
310 #define	XMSG_SDTR		0x01	/* synchronous data transfer request */
311 #define	XMSG_XID		0x02	/* extended identify */
312 
313 /*
314  * SCSI status byte values.  Bits 6, 5, and 0 are Vendor Unique.
315  */
316 #define	STS_EXT			0x80	/* flag => extended status valid */
317 #define	STS_MASK		0x1e	/* mask for non-VU bits */
318 #define	STS_VU			0x61	/* mask for Vendor Unique bits */
319 
320 #define	STS_GOOD		0x00	/* success, command done */
321 #define	STS_CHECKCOND		0x02	/* check condition (do a REQ SENSE) */
322 #define	STS_CONDMET		0x04	/* condition met (search succeeded) */
323 			/*	0x06	   reserved */
324 #define	STS_BUSY		0x08	/* busy */
325 			/*	0x0a	   reserved */
326 			/*	0x0c	   reserved */
327 			/*	0x0e	   reserved */
328 #define	STS_INTERMED		0x10	/* succeeded, doing linked cmd */
329 			/*	0x12	   reserved */
330 #define	STS_INTERMED_CONDMET	0x14	/* condition met, doing linked cmd */
331 			/*	0x16	   reserved */
332 #define	STS_RESERV_CONFLICT	0x18	/* reservation conflict */
333 			/*	0x1a	   reserved */
334 			/*	0x1c	   reserved */
335 			/*	0x1e	   reserved */
336