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