Home | History | Annotate | Line # | Download | only in scsipi
scsipi_all.h revision 1.15.6.3
      1  1.15.6.3  nathanw /*	$NetBSD: scsipi_all.h,v 1.15.6.3 2002/01/08 00:31:50 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.15.6.3  nathanw 
    145  1.15.6.3  nathanw #define START_STOP		0x1b
    146  1.15.6.3  nathanw struct scsipi_start_stop {
    147  1.15.6.3  nathanw 	u_int8_t opcode;
    148  1.15.6.3  nathanw 	u_int8_t byte2;
    149  1.15.6.3  nathanw 	u_int8_t unused[2];
    150  1.15.6.3  nathanw 	u_int8_t how;
    151  1.15.6.3  nathanw #define SSS_STOP		0x00
    152  1.15.6.3  nathanw #define SSS_START		0x01
    153  1.15.6.3  nathanw #define SSS_LOEJ		0x02
    154  1.15.6.3  nathanw 	u_int8_t control;
    155  1.15.6.3  nathanw };
    156       1.2   bouyer 
    157       1.3    enami #define	PREVENT_ALLOW		0x1e
    158       1.2   bouyer struct scsipi_prevent {
    159       1.2   bouyer 	u_int8_t opcode;
    160       1.2   bouyer 	u_int8_t byte2;
    161       1.2   bouyer 	u_int8_t unused[2];
    162       1.2   bouyer 	u_int8_t how;
    163       1.2   bouyer 	u_int8_t control;
    164  1.15.6.1  nathanw } __attribute__((packed));
    165       1.2   bouyer #define	PR_PREVENT 0x01
    166       1.3    enami #define	PR_ALLOW   0x00
    167       1.2   bouyer 
    168       1.2   bouyer /*
    169       1.2   bouyer  * inquiry and sense data format
    170       1.2   bouyer  */
    171       1.2   bouyer 
    172       1.2   bouyer struct scsipi_sense_data {
    173       1.3    enami /* 1*/	u_int8_t error_code;
    174       1.3    enami #define	SSD_ERRCODE	0x7F
    175       1.3    enami #define	SSD_ERRCODE_VALID 0x80
    176       1.3    enami /* 2*/	u_int8_t segment;
    177       1.3    enami /* 3*/	u_int8_t flags;
    178       1.3    enami #define	SSD_KEY		0x0F
    179       1.3    enami #define	SSD_ILI		0x20
    180       1.3    enami #define	SSD_EOM		0x40
    181       1.3    enami #define	SSD_FILEMARK	0x80
    182       1.3    enami /* 7*/	u_int8_t info[4];
    183       1.3    enami /* 8*/	u_int8_t extra_len;
    184       1.3    enami /*12*/	u_int8_t cmd_spec_info[4];
    185       1.3    enami /*13*/	u_int8_t add_sense_code;
    186       1.3    enami /*14*/	u_int8_t add_sense_code_qual;
    187       1.3    enami /*15*/	u_int8_t fru;
    188       1.3    enami /*16*/	u_int8_t sense_key_spec_1;
    189       1.3    enami #define	SSD_SCS_VALID	0x80
    190       1.3    enami /*17*/	u_int8_t sense_key_spec_2;
    191       1.3    enami /*18*/	u_int8_t sense_key_spec_3;
    192       1.3    enami /*32*/	u_int8_t extra_bytes[14];
    193  1.15.6.1  nathanw } __attribute__((packed));
    194       1.9   mjacob 
    195       1.9   mjacob #define	SKEY_NO_SENSE		0x00
    196      1.10   mjacob #define	SKEY_RECOVERED_ERROR	0x01
    197       1.9   mjacob #define	SKEY_NOT_READY		0x02
    198       1.9   mjacob #define	SKEY_MEDIUM_ERROR	0x03
    199       1.9   mjacob #define	SKEY_HARDWARE_ERROR	0x04
    200       1.9   mjacob #define	SKEY_ILLEGAL_REQUEST	0x05
    201       1.9   mjacob #define	SKEY_UNIT_ATTENTION	0x06
    202       1.9   mjacob #define	SKEY_WRITE_PROTECT	0x07
    203       1.9   mjacob #define	SKEY_BLANK_CHECK	0x08
    204       1.9   mjacob #define	SKEY_VENDOR_UNIQUE	0x09
    205       1.9   mjacob #define	SKEY_COPY_ABORTED	0x0A
    206       1.9   mjacob #define	SKEY_ABORTED_COMMAND	0x0B
    207       1.9   mjacob #define	SKEY_EQUAL		0x0C
    208       1.9   mjacob #define	SKEY_VOLUME_OVERFLOW	0x0D
    209       1.9   mjacob #define	SKEY_MISCOMPARE		0x0E
    210       1.9   mjacob #define	SKEY_RESERVED		0x0F
    211       1.9   mjacob 
    212       1.4   mjacob /*
    213       1.4   mjacob  * Sense bytes described by the extra_len tag start at cmd_spec_info,
    214       1.4   mjacob  * and can only continue up to the end of the structure we've defined
    215       1.4   mjacob  * (which is too short for some cases).
    216       1.4   mjacob  */
    217       1.4   mjacob #define	ADD_BYTES_LIM(sp)	\
    218      1.12      dbj 	((((int)(sp)->extra_len) < (int) sizeof(struct scsipi_sense_data) - 8)? \
    219      1.12      dbj 	((sp)->extra_len) : (sizeof (struct scsipi_sense_data) - 8))
    220       1.4   mjacob 
    221       1.2   bouyer 
    222       1.2   bouyer struct scsipi_sense_data_unextended {
    223       1.5  thorpej /* 1*/	u_int8_t error_code;
    224       1.3    enami /* 4*/	u_int8_t block[3];
    225  1.15.6.1  nathanw } __attribute__((packed));
    226       1.2   bouyer 
    227       1.5  thorpej #define	T_REMOV		1	/* device is removable */
    228       1.5  thorpej #define	T_FIXED		0	/* device is not removable */
    229       1.2   bouyer 
    230       1.2   bouyer /*
    231      1.13    dante  * According to SPC-2r16, in order to know if a U3W device support PPR,
    232  1.15.6.1  nathanw  * Inquiry Data structure should be at least 57 Bytes
    233       1.2   bouyer  */
    234       1.2   bouyer 
    235       1.2   bouyer struct scsipi_inquiry_data {
    236      1.13    dante /* 1*/	u_int8_t device;
    237  1.15.6.1  nathanw #define	SID_TYPE		0x1f	/* device type mask */
    238  1.15.6.1  nathanw #define	SID_QUAL		0xe0	/* device qualifier mask */
    239  1.15.6.1  nathanw #define	SID_QUAL_LU_PRESENT	0x00	/* logical unit present */
    240  1.15.6.1  nathanw #define	SID_QUAL_LU_NOTPRESENT	0x20	/* logical unit not present */
    241  1.15.6.1  nathanw #define	SID_QUAL_reserved	0x40
    242  1.15.6.1  nathanw #define	SID_QUAL_LU_NOT_SUPP	0x60	/* logical unit not supported */
    243  1.15.6.1  nathanw 
    244  1.15.6.1  nathanw #define	T_DIRECT		0x00	/* direct access device */
    245  1.15.6.1  nathanw #define	T_SEQUENTIAL		0x01	/* sequential access device */
    246  1.15.6.1  nathanw #define	T_PRINTER		0x02	/* printer device */
    247  1.15.6.1  nathanw #define	T_PROCESSOR		0x03	/* processor device */
    248  1.15.6.1  nathanw #define	T_WORM			0x04	/* write once, read many device */
    249  1.15.6.1  nathanw #define	T_CDROM			0x05	/* cd-rom device */
    250  1.15.6.1  nathanw #define	T_SCANNER 		0x06	/* scanner device */
    251  1.15.6.1  nathanw #define	T_OPTICAL 		0x07	/* optical memory device */
    252  1.15.6.1  nathanw #define	T_CHANGER		0x08	/* medium changer device */
    253  1.15.6.1  nathanw #define	T_COMM			0x09	/* communication device */
    254  1.15.6.1  nathanw #define	T_IT8_1			0x0a	/* Defined by ASC IT8... */
    255  1.15.6.1  nathanw #define	T_IT8_2			0x0b	/* ...(Graphic arts pre-press devices) */
    256  1.15.6.1  nathanw #define	T_STORARRAY		0x0c	/* storage array device */
    257  1.15.6.1  nathanw #define	T_ENCLOSURE		0x0d	/* enclosure services device */
    258  1.15.6.1  nathanw #define	T_SIMPLE_DIRECT		0x0E	/* Simplified direct-access device */
    259  1.15.6.1  nathanw #define	T_OPTIC_CARD_RW		0x0F	/* Optical card reader/writer device */
    260  1.15.6.1  nathanw #define	T_OBJECT_STORED		0x11	/* Object-based Storage Device */
    261  1.15.6.1  nathanw #define	T_NODEVICE		0x1f
    262  1.15.6.1  nathanw 
    263  1.15.6.1  nathanw 	u_int8_t dev_qual2;
    264  1.15.6.1  nathanw #define	SID_QUAL2		0x7F
    265  1.15.6.1  nathanw #define	SID_REMOVABLE		0x80
    266  1.15.6.1  nathanw 
    267      1.13    dante /* 3*/	u_int8_t version;
    268       1.3    enami #define	SID_ANSII	0x07
    269       1.3    enami #define	SID_ECMA	0x38
    270       1.3    enami #define	SID_ISO		0xC0
    271  1.15.6.1  nathanw 
    272      1.13    dante /* 4*/	u_int8_t response_format;
    273      1.13    dante #define	SID_RespDataFmt	0x0F
    274  1.15.6.1  nathanw #define	SID_FORMAT_SCSI1	0x00	/* SCSI-1 format */
    275  1.15.6.1  nathanw #define	SID_FORMAT_CCS		0x01	/* SCSI CCS format */
    276  1.15.6.1  nathanw #define	SID_FORMAT_ISO		0x02	/* ISO format */
    277  1.15.6.1  nathanw 
    278      1.13    dante /* 5*/	u_int8_t additional_length;	/* n-4 */
    279      1.13    dante /* 6*/	u_int8_t flags1;
    280      1.13    dante #define	SID_SCC		0x80
    281      1.13    dante /* 7*/	u_int8_t flags2;
    282      1.13    dante #define	SID_Addr16	0x01
    283  1.15.6.1  nathanw #define SID_MChngr	0x08
    284      1.13    dante #define	SID_MultiPort	0x10
    285      1.13    dante #define	SID_EncServ	0x40
    286      1.13    dante #define	SID_BasQue	0x80
    287      1.13    dante /* 8*/	u_int8_t flags3;
    288       1.2   bouyer #define	SID_SftRe	0x01
    289       1.2   bouyer #define	SID_CmdQue	0x02
    290       1.2   bouyer #define	SID_Linked	0x08
    291       1.2   bouyer #define	SID_Sync	0x10
    292       1.2   bouyer #define	SID_WBus16	0x20
    293       1.2   bouyer #define	SID_WBus32	0x40
    294       1.2   bouyer #define	SID_RelAdr	0x80
    295  1.15.6.1  nathanw /* 9*/	char    vendor[8];
    296  1.15.6.1  nathanw /*17*/	char    product[16];
    297  1.15.6.1  nathanw /*33*/	char    revision[4];
    298      1.13    dante /*37*/	u_int8_t vendor_specific[20];
    299      1.13    dante /*57*/	u_int8_t flags4;
    300  1.15.6.1  nathanw #define        SID_IUS         0x01
    301  1.15.6.1  nathanw #define        SID_QAS         0x02
    302  1.15.6.1  nathanw #define        SID_Clocking    0x0C
    303  1.15.6.1  nathanw #define	SID_CLOCKING_ST_ONLY  0x00
    304  1.15.6.1  nathanw #define	SID_CLOCKING_DT_ONLY  0x04
    305  1.15.6.1  nathanw #define	SID_CLOCKING_SD_DT    0x0C
    306      1.13    dante /*58*/	u_int8_t reserved;
    307  1.15.6.1  nathanw /*59*/	char    version_descriptor[8][2];
    308  1.15.6.1  nathanw } __attribute__((packed)); /* 74 Bytes */
    309  1.15.6.1  nathanw 
    310  1.15.6.1  nathanw /* Data structures for mode select/mode sense */
    311  1.15.6.1  nathanw struct scsipi_mode_header {
    312  1.15.6.1  nathanw 	u_int8_t data_length;	/* Sense data length */
    313  1.15.6.1  nathanw 	u_int8_t medium_type;
    314  1.15.6.1  nathanw 	u_int8_t dev_spec;
    315  1.15.6.1  nathanw 	u_int8_t blk_desc_len;	/* unused on ATAPI */
    316  1.15.6.1  nathanw } __attribute__((packed));
    317  1.15.6.1  nathanw 
    318  1.15.6.1  nathanw struct scsipi_mode_header_big {
    319  1.15.6.1  nathanw 	u_int8_t data_length[2];	/* Sense data length */
    320  1.15.6.1  nathanw 	u_int8_t medium_type;
    321  1.15.6.1  nathanw 	u_int8_t dev_spec;
    322  1.15.6.1  nathanw 	u_int8_t unused[2];		/* unused on ATAPI */
    323  1.15.6.1  nathanw 	u_int8_t blk_desc_len[2];	/* unused on ATAPI */
    324  1.15.6.1  nathanw } __attribute__((packed));
    325  1.15.6.1  nathanw 
    326  1.15.6.2  nathanw /*
    327  1.15.6.2  nathanw  * This part is common to all mode pages.
    328  1.15.6.2  nathanw  */
    329  1.15.6.2  nathanw struct scsipi_mode_page_header {
    330  1.15.6.2  nathanw 	u_int8_t pg_code;		/* page code */
    331  1.15.6.2  nathanw #define	PGCODE_MASK	0x3f		/* page code mask */
    332  1.15.6.2  nathanw #define	PGCODE_PS	0x80		/* page is savable */
    333  1.15.6.2  nathanw 	u_int8_t pg_length;		/* page length (not including hdr) */
    334  1.15.6.2  nathanw } __attribute__((__packed__));
    335      1.11  thorpej 
    336      1.11  thorpej #endif /* _DEV_SCSIPI_SCSIPI_ALL_H_ */
    337