xref: /openbsd/sys/scsi/scsi_all.h (revision 09467b48)
1 /*	$OpenBSD: scsi_all.h,v 1.61 2019/11/25 17:02:56 krw Exp $	*/
2 /*	$NetBSD: scsi_all.h,v 1.10 1996/09/12 01:57:17 thorpej Exp $	*/
3 
4 /*
5  * SCSI general  interface description
6  */
7 
8 /*
9  * Largely written by Julian Elischer (julian@tfs.com)
10  * for TRW Financial Systems.
11  *
12  * TRW Financial Systems, in accordance with their agreement with Carnegie
13  * Mellon University, makes this software available to CMU to distribute
14  * or use in any manner that they see fit as long as this message is kept with
15  * the software. For this reason TFS also grants any other persons or
16  * organisations permission to use or modify this software.
17  *
18  * TFS supplies this software to be publicly redistributed
19  * on the understanding that TFS is not responsible for the correct
20  * functioning of this software in any circumstances.
21  *
22  * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
23  */
24 
25 #ifndef	_SCSI_SCSI_ALL_H
26 #define _SCSI_SCSI_ALL_H
27 
28 /*
29  * SCSI command format
30  */
31 
32 /*
33  * Define some bits that are in ALL (or a lot of) scsi commands
34  */
35 #define SCSI_CTL_LINK		0x01
36 #define SCSI_CTL_FLAG		0x02
37 #define SCSI_CTL_VENDOR		0xC0
38 
39 
40 /*
41  * Some old SCSI devices need the LUN to be set in the top 3 bits of the
42  * second byte of the CDB.
43  */
44 #define	SCSI_CMD_LUN_MASK	0xe0
45 #define	SCSI_CMD_LUN_SHIFT	5
46 
47 
48 struct scsi_generic {
49 	u_int8_t opcode;
50 	u_int8_t bytes[15];
51 };
52 
53 struct scsi_test_unit_ready {
54 	u_int8_t opcode;
55 	u_int8_t byte2;
56 	u_int8_t unused[3];
57 	u_int8_t control;
58 };
59 
60 struct scsi_send_diag {
61 	u_int8_t opcode;
62 	u_int8_t byte2;
63 #define	SSD_UOL		0x01
64 #define	SSD_DOL		0x02
65 #define	SSD_SELFTEST	0x04
66 #define	SSD_PF		0x10
67 	u_int8_t unused[1];
68 	u_int8_t paramlen[2];
69 	u_int8_t control;
70 };
71 
72 struct scsi_sense {
73 	u_int8_t opcode;
74 	u_int8_t byte2;
75 	u_int8_t unused[2];
76 	u_int8_t length;
77 	u_int8_t control;
78 };
79 
80 struct scsi_inquiry {
81 	u_int8_t opcode;
82 	u_int8_t flags;
83 #define SI_EVPD		0x01
84 	u_int8_t pagecode;
85 #define SI_PG_SUPPORTED	0x00
86 #define SI_PG_SERIAL	0x80
87 #define SI_PG_DEVID	0x83
88 #define SI_PG_ATA	0x89
89 	u_int8_t length[2];
90 	u_int8_t control;
91 };
92 
93 struct scsi_mode_sense {
94 	u_int8_t opcode;
95 	u_int8_t byte2;
96 #define	SMS_DBD				0x08	/* Disable Block Descriptors */
97 	u_int8_t page;
98 #define	SMS_PAGE_CODE			0x3F
99 #define	SMS_PAGE_CTRL			0xC0
100 #define	SMS_PAGE_CTRL_CURRENT		0x00
101 #define	SMS_PAGE_CTRL_CHANGEABLE	0x40
102 #define	SMS_PAGE_CTRL_DEFAULT		0x80
103 #define	SMS_PAGE_CTRL_SAVED		0xC0
104 	u_int8_t unused;
105 	u_int8_t length;
106 	u_int8_t control;
107 };
108 
109 struct scsi_mode_sense_big {
110 	u_int8_t opcode;
111 	u_int8_t byte2;				/* same bits as small version */
112 #define SMS_LLBAA			0x10	/*    plus: Long LBA Accepted */
113 	u_int8_t page;				/* same bits as small version */
114 	u_int8_t unused[4];
115 	u_int8_t length[2];
116 	u_int8_t control;
117 };
118 
119 struct scsi_mode_select {
120 	u_int8_t opcode;
121 	u_int8_t byte2;
122 #define	SMS_SP	0x01
123 #define	SMS_PF	0x10
124 	u_int8_t unused[2];
125 	u_int8_t length;
126 	u_int8_t control;
127 };
128 
129 struct scsi_mode_select_big {
130 	u_int8_t opcode;
131 	u_int8_t byte2;		/* same bits as small version */
132 	u_int8_t unused[5];
133 	u_int8_t length[2];
134 	u_int8_t control;
135 };
136 
137 struct scsi_reserve {
138 	u_int8_t opcode;
139 	u_int8_t byte2;
140 	u_int8_t unused[2];
141 	u_int8_t length;
142 	u_int8_t control;
143 };
144 
145 struct scsi_release {
146 	u_int8_t opcode;
147 	u_int8_t byte2;
148 	u_int8_t unused[2];
149 	u_int8_t length;
150 	u_int8_t control;
151 };
152 
153 struct scsi_prevent {
154 	u_int8_t opcode;
155 	u_int8_t byte2;
156 	u_int8_t unused[2];
157 	u_int8_t how;
158 	u_int8_t control;
159 };
160 #define	PR_PREVENT 0x01
161 #define PR_ALLOW   0x00
162 
163 struct scsi_report_luns {
164 	u_int8_t opcode;
165 	u_int8_t unused;
166 	u_int8_t selectreport;
167 #define	REPORT_NORMAL		0x00
168 #define	REPORT_WELLKNOWN	0x01
169 #define	REPORT_ALL		0x02
170 	u_int8_t unused2[3];
171 	u_int8_t length[4];
172 	u_int8_t unused4;
173 	u_int8_t control;
174 };
175 
176 /*
177  * Opcodes
178  */
179 #define	TEST_UNIT_READY		0x00
180 #define REQUEST_SENSE		0x03
181 #define INQUIRY			0x12
182 #define MODE_SELECT		0x15
183 #define RESERVE			0x16
184 #define RELEASE			0x17
185 #define MODE_SENSE		0x1a
186 #define START_STOP		0x1b
187 #define RECEIVE_DIAGNOSTIC	0x1c
188 #define SEND_DIAGNOSTIC		0x1d
189 #define PREVENT_ALLOW		0x1e
190 #define POSITION_TO_ELEMENT	0x2b
191 #define WRITE_BUFFER		0x3b
192 #define READ_BUFFER		0x3c
193 #define	CHANGE_DEFINITION	0x40
194 #define	MODE_SELECT_BIG		0x55
195 #define	MODE_SENSE_BIG		0x5a
196 #define	REPORT_LUNS		0xa0
197 
198 /*
199  * Sort of an extra one, for SCSI_RESET.
200  */
201 #define GENRETRY		1
202 
203 /*
204  * Device Types
205  */
206 #define T_DIRECT	0x00	/* Direct access block device (SBC-4) */
207 #define T_SEQUENTIAL	0x01	/* Sequential access device (SSC-3) */
208 #define T_PRINTER	0x02	/* Printer device (SSC) */
209 #define T_PROCESSOR	0x03	/* Processor device (SPC-2) */
210 #define T_WORM		0x04	/* Write once device (SBC) */
211 #define T_CDROM		0x05	/* CD/DVD device (MMC-5) */
212 #define T_SCANNER	0x06	/* Scanner device (Obsolete) */
213 #define T_OPTICAL	0x07	/* Optical memory device (SBC) */
214 #define T_CHANGER	0x08	/* Media changer device (SMC-3) */
215 #define T_COMM		0x09	/* Communications device (Obsolete) */
216 #define T_ASC0		0x0a	/* Obsolete */
217 #define T_ASC1		0x0b	/* Obsolete */
218 #define T_STORARRAY	0x0c	/* Storage Array controller device (RAID) */
219 #define T_ENCLOSURE	0x0d	/* Enclosure services device (SES) */
220 #define T_RDIRECT	0x0e	/* Simplified direct access device (RBC) */
221 #define T_OCRW		0x0f	/* Optical card reader/writer (OCRW) */
222 #define T_BCC		0x10	/* Bridge Controller Commands (BCC) */
223 #define T_OSD		0x11	/* Object-based Storage device (OSD) */
224 #define T_ADC		0x12	/* Automation/Drive Interface (ADC-2) */
225 /* 0x13 - 0x1d RESERVED */
226 #define T_WELL_KNOWN_LU	0x1e	/* Well known logial unut */
227 #define T_NODEVICE	0x1F	/* Unknown or no device type */
228 
229 #define T_REMOV		1
230 #define	T_FIXED		0
231 
232 struct scsi_inquiry_data {
233 	u_int8_t device;
234 #define	SID_TYPE		0x1f
235 #define	SID_QUAL		0xe0
236 #define		SID_QUAL_LU_OK		0x00
237 #define		SID_QUAL_LU_OFFLINE	0x20
238 #define		SID_QUAL_RSVD		0x40
239 #define		SID_QUAL_BAD_LU		0x60
240 	u_int8_t dev_qual2;
241 #define	SID_QUAL2		0x7f
242 #define	SID_REMOVABLE		0x80
243 	u_int8_t version;
244 #define SID_ANSII		0x07
245 #define SID_ECMA		0x38
246 #define SID_ISO			0xc0
247 	u_int8_t response_format;
248 #define SID_RESPONSE_DATA_FMT	0x0f	/* < 2 == obsolete, > 2 reserved! */
249 #define SID_HiSup		0x10	/* Hierarchical LUNs */
250 #define SID_NormACA		0x20	/* Normal ACA bit in CCB supported */
251 #define SID_TrmIOP		0x40	/* obsolete */
252 #define SID_AENC		0x80	/* obsolete */
253 	u_int8_t additional_length;
254 #define SID_INQUIRY_HDR	5	/* Bytes up to & including additional_length */
255 #define SID_SCSI2_ALEN	31	/* Additional bytes of basic SCSI2 info */
256 	u_int8_t spc3_flags;
257 #define SPC3_SID_PROTECT	0x01	/* 0 == Type 0, 1 == Type 1, 2 or 3 */
258 #define SPC3_SID_RESERVED	0x06
259 #define SPC3_SID_3PC		0x08	/* 3rd party copy */
260 #define SPC3_SID_TPGS_IMPLICIT	0x10	/* Implicit asymmetric LU access */
261 #define SPC3_SID_TPGS_EXPLICIT	0x20	/* Explicit asymmetric LU access */
262 #define SPC3_SID_ACC		0x40	/* Access controls controller */
263 #define SPC3_SID_SCCS		0x80	/* Embedded storage array controller */
264 	u_int8_t spc2_flags;
265 #define SPC2_SID_ADDR16		0x01	/* obsolete */
266 #define SPC2_RESERVED		0x06
267 #define SPC2_SID_NChngr		0x08	/* obsolete */
268 #define SPC2_SID_MultiP		0x10	/* multi-port target */
269 #define SPC2_VS			0x20	/* ??? */
270 #define SPC2_SID_EncServ	0x40	/* Embedded enclosure services */
271 #define SPC2_SID_BQueue		0x80	/* obsolete */
272 	u_int8_t flags;
273 #define	SID_VS			0x01	/* ??? */
274 #define	SID_CmdQue		0x02	/* Task manageent mode supported */
275 #define	SID_Linked		0x08	/* obsolete */
276 #define	SID_Sync		0x10	/* obsolete */
277 #define	SID_WBus16		0x20	/* obsolete */
278 #define	SID_WBus32		0x40	/* obsolete */
279 #define	SID_RelAdr		0x80	/* obsolete */
280 	char	vendor[8];
281 	char	product[16];
282 	char	revision[4];
283 	u_int8_t extra[20];
284 	u_int8_t reserved[2];
285 	u_int8_t version_descriptor0[2];
286 	u_int8_t version_descriptor1[2];
287 	u_int8_t version_descriptor2[2];
288 	u_int8_t version_descriptor3[2];
289 	u_int8_t version_descriptor4[2];
290 	u_int8_t version_descriptor5[2];
291 	u_int8_t version_descriptor6[2];
292 	u_int8_t version_descriptor7[2];
293 	u_int8_t reserved2[22];
294 };
295 
296 struct scsi_vpd_hdr {
297 	u_int8_t device;
298 	u_int8_t page_code;
299 	u_int8_t page_length[2];
300 };
301 
302 struct scsi_vpd_serial {
303 	struct scsi_vpd_hdr hdr;
304 	char serial[32];
305 };
306 
307 #define VPD_PROTO_ID_FC		0x0 /* Fibre Channel */
308 #define VPD_PROTO_ID_SPI	0x1 /* Parallel SCSI */
309 #define VPD_PROTO_ID_SSA	0x2
310 #define VPD_PROTO_ID_IEEE1394	0x3
311 #define VPD_PROTO_ID_SRP	0x4 /* SCSI RDMA Protocol */
312 #define VPD_PROTO_ID_ISCSI	0x5 /* Internet SCSI (iSCSI) */
313 #define VPD_PROTO_ID_SAS	0x6 /* Serial Attached SCSI */
314 #define VPD_PROTO_ID_ADT	0x7 /* Automation/Drive Interface Transport */
315 #define VPD_PROTO_ID_ATA	0x7 /* ATA/ATAPI */
316 #define VPD_PROTO_ID_NONE	0xf
317 
318 struct scsi_vpd_devid_hdr {
319 	u_int8_t pi_code;
320 #define VPD_DEVID_PI(_f)	(((_f) >> 4) & 0x0f)
321 #define VPD_DEVID_CODE(_f)	(((_f) >> 0) & 0x0f)
322 #define VPD_DEVID_CODE_BINARY		0x1
323 #define VPD_DEVID_CODE_ASCII		0x2
324 #define VPD_DEVID_CODE_UTF8		0x3
325 	u_int8_t flags;
326 #define VPD_DEVID_PIV		0x80
327 #define VPD_DEVID_ASSOC(_f)	((_f) & 0x30)
328 #define VPD_DEVID_ASSOC_LU		0x00
329 #define VPD_DEVID_ASSOC_PORT		0x10
330 #define VPD_DEVID_ASSOC_TARG		0x20
331 #define VPD_DEVID_TYPE(_f)	((_f) & 0x0f)
332 #define VPD_DEVID_TYPE_VENDOR		0x0
333 #define VPD_DEVID_TYPE_T10		0x1
334 #define VPD_DEVID_TYPE_EUI64		0x2
335 #define VPD_DEVID_TYPE_NAA		0x3
336 #define VPD_DEVID_TYPE_RELATIVE		0x4
337 #define VPD_DEVID_TYPE_PORT		0x5
338 #define VPD_DEVID_TYPE_LU		0x6
339 #define VPD_DEVID_TYPE_MD5		0x7
340 #define VPD_DEVID_TYPE_NAME		0x8
341 	u_int8_t reserved;
342 	u_int8_t len;
343 };
344 
345 struct scsi_vpd_ata {
346 	struct scsi_vpd_hdr hdr;
347 
348 	u_int8_t _reserved1[4];
349 	u_int8_t sat_vendor[8];
350 	u_int8_t sat_product[16];
351 	u_int8_t sat_revision[4];
352 	u_int8_t device_signature[20];
353 	u_int8_t command_code;
354 #define VPD_ATA_COMMAND_CODE_ATA	0xec
355 #define VPD_ATA_COMMAND_CODE_ATAPI	0xa1
356 	u_int8_t _reserved2[3];
357 	u_int8_t identify[512];
358 };
359 
360 struct scsi_read_cap_data {
361 	u_int8_t addr[4];
362 	u_int8_t length[4];
363 };
364 
365 struct scsi_read_cap_data_16 {
366 	u_int8_t addr[8];
367 	u_int8_t length[4];
368 	u_int8_t p_type_prot;
369 #define RC16_PROT_EN		0x01	/* Protection type is 0 when 0 */
370 #define RC16_PROT_P_TYPE	0x0e
371 #define		RC16_P_TYPE_1		0x00	/* Protection type 1 */
372 #define		RC16_P_TYPE_2		0x02	/* Protection type 2 */
373 #define		RC16_P_TYPE_3		0x04	/* Protection type 3 */
374 #define RC16_BASIS		0x30	/* Meaning of addr */
375 #define		RC16_BASIS_HIGH		0x00	/* highest LBA of zone */
376 #define		RC16_BASIS_LAST		0x10	/* last LBA on unit */
377 	u_int8_t logical_per_phys;	/* Logical Blks Per Physical Blk Exp */
378 #define RC16_LBPPB_EXPONENT	0x0f	/* 2**N LB per PB, 0 means unknown */
379 #define RC16_PIIPLB_EXPONENT	0xf0	/* 2**N Prot info intervals per LB */
380 	u_int8_t lowest_aligned[2];
381 #define RC16_LALBA		0x3fff	/* lowest aligned LBA */
382 #define RC16_LBPRZ		0x4000	/* unmapped LBA returns all zeros */
383 #define READ_CAP_16_TPRZ	0x4000	/* XXX old name used in driver(s) */
384 #define RC16_LBPME		0x8000	/* LB provisioning management enabled */
385 #define READ_CAP_16_TPE		0x8000	/* XXX old name used in driver(s) */
386 	u_int8_t reserved[16];
387 };
388 
389 struct scsi_sense_data_unextended {
390 /* 1*/	u_int8_t error_code;
391 /* 4*/	u_int8_t block[3];
392 };
393 
394 struct scsi_sense_data {
395 /* 1*/	u_int8_t error_code;
396 #define	SSD_ERRCODE_CURRENT	0x70
397 #define	SSD_ERRCODE_DEFERRED	0x71
398 #define	SSD_ERRCODE		0x7F
399 #define	SSD_ERRCODE_VALID	0x80
400 /* 2*/	u_int8_t segment;
401 /* 3*/	u_int8_t flags;
402 #define	SSD_KEY		0x0F
403 #define	SSD_ILI		0x20
404 #define	SSD_EOM		0x40
405 #define	SSD_FILEMARK	0x80
406 /* 7*/	u_int8_t info[4];
407 /* 8*/	u_int8_t extra_len;
408 /*12*/	u_int8_t cmd_spec_info[4];
409 /*13*/	u_int8_t add_sense_code;
410 /*14*/	u_int8_t add_sense_code_qual;
411 /*15*/	u_int8_t fru;
412 /*16*/	u_int8_t sense_key_spec_1;
413 #define	SSD_SCS_VALID		0x80
414 #define SSD_SCS_CDB_ERROR	0x40
415 #define SSD_SCS_SEGMENT_DESC	0x20
416 #define SSD_SCS_VALID_BIT_INDEX	0x08
417 #define SSD_SCS_BIT_INDEX	0x07
418 /*17*/	u_int8_t sense_key_spec_2;
419 /*18*/	u_int8_t sense_key_spec_3;
420 };
421 
422 #define SKEY_NO_SENSE		0x00
423 #define SKEY_RECOVERED_ERROR	0x01
424 #define SKEY_NOT_READY		0x02
425 #define SKEY_MEDIUM_ERROR	0x03
426 #define SKEY_HARDWARE_ERROR	0x04
427 #define SKEY_ILLEGAL_REQUEST	0x05
428 #define SKEY_UNIT_ATTENTION	0x06
429 #define SKEY_WRITE_PROTECT	0x07
430 #define SKEY_BLANK_CHECK	0x08
431 #define SKEY_VENDOR_UNIQUE	0x09
432 #define SKEY_COPY_ABORTED	0x0A
433 #define SKEY_ABORTED_COMMAND	0x0B
434 #define SKEY_EQUAL		0x0C
435 #define SKEY_VOLUME_OVERFLOW	0x0D
436 #define SKEY_MISCOMPARE		0x0E
437 #define SKEY_RESERVED		0x0F
438 
439 
440 /* Additional sense code info */
441 #define ASC_ASCQ(ssd)	((ssd->add_sense_code << 8) | ssd->add_sense_code_qual)
442 
443 #define SENSE_FILEMARK_DETECTED			0x0001
444 #define SENSE_END_OF_MEDIUM_DETECTED		0x0002
445 #define SENSE_SETMARK_DETECTED			0x0003
446 #define SENSE_BEGINNING_OF_MEDIUM_DETECTED	0x0004
447 #define SENSE_END_OF_DATA_DETECTED		0x0005
448 #define SENSE_NOT_READY_BECOMING_READY		0x0401
449 #define SENSE_NOT_READY_INIT_REQUIRED		0x0402
450 #define SENSE_NOT_READY_FORMAT			0x0404
451 #define SENSE_NOT_READY_REBUILD			0x0405
452 #define SENSE_NOT_READY_RECALC			0x0406
453 #define SENSE_NOT_READY_INPROGRESS		0x0407
454 #define SENSE_NOT_READY_LONGWRITE		0x0408
455 #define SENSE_NOT_READY_SELFTEST		0x0409
456 #define SENSE_POWER_RESET_OR_BUS		0x2900
457 #define SENSE_POWER_ON				0x2901
458 #define SENSE_BUS_RESET				0x2902
459 #define SENSE_BUS_DEVICE_RESET			0x2903
460 #define SENSE_DEVICE_INTERNAL_RESET		0x2904
461 #define SENSE_TSC_CHANGE_SE			0x2905
462 #define SENSE_TSC_CHANGE_LVD			0x2906
463 #define SENSE_IT_NEXUS_LOSS			0x2907
464 #define SENSE_BAD_MEDIUM			0x3000
465 #define SENSE_NR_MEDIUM_UNKNOWN_FORMAT		0x3001
466 #define SENSE_NR_MEDIUM_INCOMPATIBLE_FORMAT	0x3002
467 #define SENSE_NW_MEDIUM_UNKNOWN_FORMAT		0x3004
468 #define SENSE_NW_MEDIUM_INCOMPATIBLE_FORMAT	0x3005
469 #define SENSE_NF_MEDIUM_INCOMPATIBLE_FORMAT	0x3006
470 #define SENSE_NW_MEDIUM_AC_MISMATCH		0x3008
471 #define SENSE_NOMEDIUM				0x3A00
472 #define SENSE_NOMEDIUM_TCLOSED			0x3A01
473 #define SENSE_NOMEDIUM_TOPEN			0x3A02
474 #define SENSE_NOMEDIUM_LOADABLE			0x3A03
475 #define SENSE_NOMEDIUM_AUXMEM			0x3A04
476 #define SENSE_CARTRIDGE_FAULT			0x5200
477 #define SENSE_MEDIUM_REMOVAL_PREVENTED		0x5302
478 
479 struct scsi_blk_desc {
480 	u_int8_t density;
481 	u_int8_t nblocks[3];
482 	u_int8_t reserved;
483 	u_int8_t blklen[3];
484 };
485 
486 struct scsi_direct_blk_desc {
487 	u_int8_t nblocks[4];
488 	u_int8_t density;
489 	u_int8_t blklen[3];
490 };
491 
492 struct scsi_blk_desc_big {
493 	u_int8_t nblocks[8];
494 	u_int8_t density;
495 	u_int8_t reserved[3];
496 	u_int8_t blklen[4];
497 };
498 
499 struct scsi_mode_header {
500 	u_int8_t data_length;		/* Sense data length */
501 	u_int8_t medium_type;
502 	u_int8_t dev_spec;
503 	u_int8_t blk_desc_len;
504 };
505 
506 struct scsi_mode_header_big {
507 	u_int8_t data_length[2];	/* Sense data length */
508 	u_int8_t medium_type;
509 	u_int8_t dev_spec;
510 	u_int8_t reserved;
511 #define LONGLBA	0x01
512 	u_int8_t reserved2;
513 	u_int8_t blk_desc_len[2];
514 };
515 
516 /* Both disks and tapes use dev_spec to report READONLY status. */
517 #define	SMH_DSP_WRITE_PROT	0x80
518 
519 union scsi_mode_sense_buf {
520 	struct scsi_mode_header hdr;
521 	struct scsi_mode_header_big hdr_big;
522 	u_char buf[254];	/* 255 & 256 bytes breaks some devices. */
523 				/* ahci doesn't like 255, various don't like */
524 				/* 256 because length must fit in 8 bits. */
525 } __packed;			/* Ensure sizeof() is 254! */
526 
527 struct scsi_report_luns_data {
528 	u_int8_t length[4];	/* length of LUN inventory, in bytes */
529 	u_int8_t reserved[4];	/* unused */
530 	/*
531 	 * LUN inventory- we only support the type zero form for now.
532 	 */
533 #define RPL_LUNDATA_SIZE 8	/* Bytes per lun */
534 	struct {
535 		u_int8_t lundata[RPL_LUNDATA_SIZE];
536 	} luns[256];		/* scsi_link->luns is u_int8_t. */
537 };
538 #define	RPL_LUNDATA_T0LUN	1	/* Type 0 LUN is in lundata[1] */
539 
540 struct scsi_lun_array {
541 	uint8_t	luns[256];
542 	int	count;
543 	int	dumbscan;
544 };
545 
546 /*
547  * ATA PASS-THROUGH as per SAT2
548  */
549 
550 #define ATA_PASSTHRU_12		0xa1
551 #define ATA_PASSTHRU_16		0x85
552 
553 #define ATA_PASSTHRU_PROTO_MASK		0x1e
554 #define ATA_PASSTHRU_PROTO_HW_RESET	0x00
555 #define ATA_PASSTHRU_PROTO_SW_RESET	0x02
556 #define ATA_PASSTHRU_PROTO_NON_DATA	0x06
557 #define ATA_PASSTHRU_PROTO_PIO_DATAIN	0x08
558 #define ATA_PASSTHRU_PROTO_PIO_DATAOUT	0x0a
559 #define ATA_PASSTHRU_PROTO_DMA		0x0c
560 #define ATA_PASSTHRU_PROTO_DMA_QUEUED	0x0e
561 #define ATA_PASSTHRU_PROTO_EXEC_DIAG	0x10
562 #define ATA_PASSTHRU_PROTO_NON_DATA_RST	0x12
563 #define ATA_PASSTHRU_PROTO_UDMA_DATAIN	0x14
564 #define ATA_PASSTHRU_PROTO_UDMA_DATAOUT	0x16
565 #define ATA_PASSTHRU_PROTO_FPDMA	0x18
566 #define ATA_PASSTHRU_PROTO_RESPONSE	0x1e
567 
568 #define ATA_PASSTHRU_T_DIR_MASK		0x08
569 #define ATA_PASSTHRU_T_DIR_READ		0x08
570 #define ATA_PASSTHRU_T_DIR_WRITE	0x00
571 
572 #define ATA_PASSTHRU_T_LEN_MASK		0x03
573 #define ATA_PASSTHRU_T_LEN_NONE		0x00
574 #define ATA_PASSTHRU_T_LEN_FEATURES	0x01
575 #define ATA_PASSTHRU_T_LEN_SECTOR_COUNT	0x02
576 #define ATA_PASSTHRU_T_LEN_TPSIU	0x03
577 
578 struct scsi_ata_passthru_12 {
579 	u_int8_t opcode;
580 	u_int8_t count_proto;
581 	u_int8_t flags;
582 	u_int8_t features;
583 	u_int8_t sector_count;
584 	u_int8_t lba_low;
585 	u_int8_t lba_mid;
586 	u_int8_t lba_high;
587 	u_int8_t device;
588 	u_int8_t command;
589 	u_int8_t _reserved;
590 	u_int8_t control;
591 };
592 
593 struct scsi_ata_passthru_16 {
594 	u_int8_t opcode;
595 	u_int8_t count_proto;
596 	u_int8_t flags;
597 	u_int8_t features[2];
598 	u_int8_t sector_count[2];
599 	u_int8_t lba_low[2];
600 	u_int8_t lba_mid[2];
601 	u_int8_t lba_high[2];
602 	u_int8_t device;
603 	u_int8_t command;
604 	u_int8_t control;
605 };
606 
607 /*
608  * SPI status information unit. See section 14.3.5 of SPI-3.
609  */
610 struct scsi_status_iu_header {
611 /* 2*/	u_int8_t reserved[2];
612 /* 3*/	u_int8_t flags;
613 #define	SIU_SNSVALID 0x2
614 #define	SIU_RSPVALID 0x1
615 /* 4*/	u_int8_t status;
616 /* 8*/	u_int8_t sense_length[4];
617 /*12*/	u_int8_t pkt_failures_length[4];
618 	u_int8_t data[1]; /* <pkt failure list><sense data> OR <sense_data> */
619 };
620 
621 #define SIU_PKTFAIL_CODE(siu)	((siu)->data[3])
622 #define		SIU_PFC_NONE			0x00
623 #define		SIU_PFC_CIU_FIELDS_INVALID	0x02
624 #define		SIU_PFC_TMF_NOT_SUPPORTED	0x04
625 #define		SIU_PFC_TMF_FAILED		0x05
626 #define		SIU_PFC_INVALID_TYPE_CODE	0x06
627 #define		SIU_PFC_ILLEGAL_REQUEST		0x07
628 
629 #define SIU_SENSE_LENGTH(siu)	(_4btol((siu)->sense_length))
630 #define SIU_SENSE_DATA(siu)	(((siu)->flags & SIU_RSPVALID) ?	\
631    &(siu)->data[_4btol((siu)->pkt_failures_length)] : &(siu)->data[0])
632 
633 /*
634  * Values for 'Task Management Flags' field of SPI command information unit.
635  * See section 14.3.1 of SPI-3.
636  */
637 #define	SIU_TASKMGMT_NONE		0x00
638 #define	SIU_TASKMGMT_ABORT_TASK		0x01
639 #define	SIU_TASKMGMT_ABORT_TASK_SET	0x02
640 #define	SIU_TASKMGMT_CLEAR_TASK_SET	0x04
641 #define	SIU_TASKMGMT_LUN_RESET		0x08
642 #define	SIU_TASKMGMT_TARGET_RESET	0x20
643 #define	SIU_TASKMGMT_CLEAR_ACA		0x40
644 
645 /*
646  * Status Byte
647  */
648 #define SCSI_OK			0x00
649 #define SCSI_CHECK		0x02
650 #define SCSI_COND_MET		0x04
651 #define SCSI_BUSY		0x08
652 #define SCSI_INTERM		0x10
653 #define SCSI_INTERM_COND_MET	0x14
654 #define SCSI_RESV_CONFLICT	0x18
655 #define SCSI_TERMINATED		0x22
656 #define SCSI_QUEUE_FULL		0x28	/* Old (Pre SCSI-3) name */
657 #define SCSI_TASKSET_FULL	0x28	/* New (SCSI-3)     name */
658 #define SCSI_ACA_ACTIVE		0x30
659 
660 #endif /* _SCSI_SCSI_ALL_H */
661