Home | History | Annotate | Line # | Download | only in scsipi
scsipi_all.h revision 1.9
      1 /*	$NetBSD: scsipi_all.h,v 1.9 1998/07/01 17:04:31 mjacob Exp $	*/
      2 
      3 /*
      4  * SCSI and SCSI-like general interface description
      5  */
      6 
      7 /*
      8  * Largely written by Julian Elischer (julian (at) 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 (at) tfs.com) Sept 1992
     22  */
     23 
     24 /*
     25  * SCSI-like command format and opcode
     26  */
     27 
     28 /*
     29  * Some basic, common SCSI command group definitions.
     30  */
     31 
     32 #define	CDB_GROUPID(cmd)        ((cmd >> 5) & 0x7)
     33 #define	CDB_GROUPID_0	0
     34 #define	CDB_GROUPID_1	1
     35 #define	CDB_GROUPID_2	2
     36 #define	CDB_GROUPID_3	3
     37 #define	CDB_GROUPID_4	4
     38 #define	CDB_GROUPID_5	5
     39 #define	CDB_GROUPID_6	6
     40 #define	CDB_GROUPID_7	7
     41 
     42 #define	CDB_GROUP0	6       /*  6-byte cdb's */
     43 #define	CDB_GROUP1	10      /* 10-byte cdb's */
     44 #define	CDB_GROUP2	10      /* 10-byte cdb's */
     45 #define	CDB_GROUP3	0       /* reserved */
     46 #define	CDB_GROUP4	16      /* 16-byte cdb's */
     47 #define	CDB_GROUP5	12      /* 12-byte cdb's */
     48 #define	CDB_GROUP6	0       /* vendor specific */
     49 #define	CDB_GROUP7	0       /* vendor specific */
     50 
     51 /*
     52  * Some basic, common SCSI commands
     53  */
     54 #define	TEST_UNIT_READY		0x00
     55 struct scsipi_test_unit_ready {
     56 	u_int8_t opcode;
     57 	u_int8_t byte2;
     58 	u_int8_t unused[3];
     59 	u_int8_t control;
     60 };
     61 
     62 #define	REQUEST_SENSE		0x03
     63 struct scsipi_sense {
     64 	u_int8_t opcode;
     65 	u_int8_t byte2;
     66 	u_int8_t unused[2];
     67 	u_int8_t length;
     68 	u_int8_t control;
     69 };
     70 
     71 #define	INQUIRY			0x12
     72 struct scsipi_inquiry {
     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 #define	PREVENT_ALLOW		0x1e
     81 struct scsipi_prevent {
     82 	u_int8_t opcode;
     83 	u_int8_t byte2;
     84 	u_int8_t unused[2];
     85 	u_int8_t how;
     86 	u_int8_t control;
     87 };
     88 #define	PR_PREVENT 0x01
     89 #define	PR_ALLOW   0x00
     90 
     91 /*
     92  * inquiry and sense data format
     93  */
     94 
     95 struct scsipi_sense_data {
     96 /* 1*/	u_int8_t error_code;
     97 #define	SSD_ERRCODE	0x7F
     98 #define	SSD_ERRCODE_VALID 0x80
     99 /* 2*/	u_int8_t segment;
    100 /* 3*/	u_int8_t flags;
    101 #define	SSD_KEY		0x0F
    102 #define	SSD_ILI		0x20
    103 #define	SSD_EOM		0x40
    104 #define	SSD_FILEMARK	0x80
    105 /* 7*/	u_int8_t info[4];
    106 /* 8*/	u_int8_t extra_len;
    107 /*12*/	u_int8_t cmd_spec_info[4];
    108 /*13*/	u_int8_t add_sense_code;
    109 /*14*/	u_int8_t add_sense_code_qual;
    110 /*15*/	u_int8_t fru;
    111 /*16*/	u_int8_t sense_key_spec_1;
    112 #define	SSD_SCS_VALID	0x80
    113 /*17*/	u_int8_t sense_key_spec_2;
    114 /*18*/	u_int8_t sense_key_spec_3;
    115 /*32*/	u_int8_t extra_bytes[14];
    116 };
    117 
    118 #define	SKEY_NO_SENSE		0x00
    119 #define	SKEY_RECOVERABLE_ERROR	0x01
    120 #define	SKEY_NOT_READY		0x02
    121 #define	SKEY_MEDIUM_ERROR	0x03
    122 #define	SKEY_HARDWARE_ERROR	0x04
    123 #define	SKEY_ILLEGAL_REQUEST	0x05
    124 #define	SKEY_UNIT_ATTENTION	0x06
    125 #define	SKEY_WRITE_PROTECT	0x07
    126 #define	SKEY_BLANK_CHECK	0x08
    127 #define	SKEY_VENDOR_UNIQUE	0x09
    128 #define	SKEY_COPY_ABORTED	0x0A
    129 #define	SKEY_ABORTED_COMMAND	0x0B
    130 #define	SKEY_EQUAL		0x0C
    131 #define	SKEY_VOLUME_OVERFLOW	0x0D
    132 #define	SKEY_MISCOMPARE		0x0E
    133 #define	SKEY_RESERVED		0x0F
    134 
    135 /*
    136  * Sense bytes described by the extra_len tag start at cmd_spec_info,
    137  * and can only continue up to the end of the structure we've defined
    138  * (which is too short for some cases).
    139  */
    140 #define	ADD_BYTES_LIM(sp)	\
    141 	(((int)(sp)->extra_len) < (int) sizeof(struct scsipi_sense_data) - 8)? \
    142 	((sp)->extra_len) : (sizeof (struct scsipi_sense_data) - 8)
    143 
    144 
    145 struct scsipi_sense_data_unextended {
    146 /* 1*/	u_int8_t error_code;
    147 /* 4*/	u_int8_t block[3];
    148 };
    149 
    150 #define	T_DIRECT	0x00	/* direct access device */
    151 #define	T_SEQUENTIAL	0x01	/* sequential access device */
    152 #define	T_PRINTER	0x02	/* printer device */
    153 #define	T_PROCESSOR	0x03	/* processor device */
    154 #define	T_WORM		0x04	/* write once, read many device */
    155 #define	T_CDROM		0x05	/* cd-rom device */
    156 #define	T_SCANNER 	0x06	/* scanner device */
    157 #define	T_OPTICAL 	0x07	/* optical memory device */
    158 #define	T_CHANGER	0x08	/* medium changer device */
    159 #define	T_COMM		0x09	/* communication device */
    160 #define	T_IT8_1		0x0a	/* ??? */
    161 #define	T_IT8_2		0x0b	/* ??? */
    162 #define	T_STORARRAY	0x0c	/* storage array device */
    163 #define	T_ENCLOSURE	0x0d	/* enclosure services device */
    164 #define	T_NODEVICE	0x1F
    165 
    166 #define	T_REMOV		1	/* device is removable */
    167 #define	T_FIXED		0	/* device is not removable */
    168 
    169 /*
    170  * XXX
    171  * Actually I think some SCSI driver expects this structure to be 32 bytes, so
    172  * don't change it unless you really know what you are doing
    173  */
    174 
    175 struct scsipi_inquiry_data {
    176 	u_int8_t device;
    177 #define	SID_TYPE	0x1F
    178 #define	SID_QUAL	0xE0
    179 #define	SID_QUAL_LU_OK	0x00
    180 #define	SID_QUAL_LU_OFFLINE	0x20
    181 #define	SID_QUAL_RSVD	0x40
    182 #define	SID_QUAL_BAD_LU	0x60
    183 	u_int8_t dev_qual2;
    184 #define	SID_QUAL2	0x7F
    185 #define	SID_REMOVABLE	0x80
    186 	u_int8_t version;
    187 #define	SID_ANSII	0x07
    188 #define	SID_ECMA	0x38
    189 #define	SID_ISO		0xC0
    190 	u_int8_t response_format;
    191 	u_int8_t additional_length;
    192 	u_int8_t unused[2];
    193 	u_int8_t flags;
    194 #define	SID_SftRe	0x01
    195 #define	SID_CmdQue	0x02
    196 #define	SID_Linked	0x08
    197 #define	SID_Sync	0x10
    198 #define	SID_WBus16	0x20
    199 #define	SID_WBus32	0x40
    200 #define	SID_RelAdr	0x80
    201 	char	vendor[8];
    202 	char	product[16];
    203 	char	revision[4];
    204 	u_int8_t extra[8];
    205 };
    206