scsi.h
Go to the documentation of this file.00001 #ifndef _GPXE_SCSI_H
00002 #define _GPXE_SCSI_H
00003
00004 #include <stdint.h>
00005 #include <gpxe/blockdev.h>
00006 #include <gpxe/uaccess.h>
00007 #include <gpxe/refcnt.h>
00008
00009
00010
00011
00012
00013
00014
00015 FILE_LICENCE ( GPL2_OR_LATER );
00016
00017
00018
00019
00020
00021
00022 #define SCSI_OPCODE_READ_10 0x28
00023 #define SCSI_OPCODE_READ_16 0x88
00024 #define SCSI_OPCODE_WRITE_10 0x2a
00025 #define SCSI_OPCODE_WRITE_16 0x8a
00026 #define SCSI_OPCODE_READ_CAPACITY_10 0x25
00027 #define SCSI_OPCODE_SERVICE_ACTION_IN 0x9e
00028 #define SCSI_SERVICE_ACTION_READ_CAPACITY_16 0x10
00029
00030
00031
00032
00033
00034
00035
00036
00037 #define SCSI_FL_FUA_NV 0x02
00038 #define SCSI_FL_FUA 0x08
00039 #define SCSI_FL_DPO 0x10
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 struct scsi_cdb_read_10 {
00050
00051 uint8_t opcode;
00052
00053 uint8_t flags;
00054
00055
00056
00057
00058 uint32_t lba;
00059
00060 uint8_t group;
00061
00062
00063
00064
00065 uint16_t len;
00066
00067 uint8_t control;
00068 } __attribute__ (( packed ));
00069
00070
00071 struct scsi_cdb_read_16 {
00072
00073 uint8_t opcode;
00074
00075 uint8_t flags;
00076
00077
00078
00079
00080 uint64_t lba;
00081
00082
00083
00084
00085 uint32_t len;
00086
00087 uint8_t group;
00088
00089 uint8_t control;
00090 } __attribute__ (( packed ));
00091
00092
00093 struct scsi_cdb_write_10 {
00094
00095 uint8_t opcode;
00096
00097 uint8_t flags;
00098
00099
00100
00101
00102 uint32_t lba;
00103
00104 uint8_t group;
00105
00106
00107
00108
00109 uint16_t len;
00110
00111 uint8_t control;
00112 } __attribute__ (( packed ));
00113
00114
00115 struct scsi_cdb_write_16 {
00116
00117 uint8_t opcode;
00118
00119 uint8_t flags;
00120
00121
00122
00123
00124 uint64_t lba;
00125
00126
00127
00128
00129 uint32_t len;
00130
00131 uint8_t group;
00132
00133 uint8_t control;
00134 } __attribute__ (( packed ));
00135
00136
00137 struct scsi_cdb_read_capacity_10 {
00138
00139 uint8_t opcode;
00140
00141 uint8_t reserved_a;
00142
00143
00144
00145
00146 uint32_t lba;
00147
00148 uint8_t reserved_b[3];
00149
00150 uint8_t control;
00151 } __attribute__ (( packed ));
00152
00153
00154 struct scsi_capacity_10 {
00155
00156 uint32_t lba;
00157
00158 uint32_t blksize;
00159 } __attribute__ (( packed ));
00160
00161
00162 struct scsi_cdb_read_capacity_16 {
00163
00164 uint8_t opcode;
00165
00166 uint8_t service_action;
00167
00168
00169
00170
00171 uint64_t lba;
00172
00173
00174
00175
00176 uint32_t len;
00177
00178 uint8_t reserved;
00179
00180 uint8_t control;
00181 } __attribute__ (( packed ));
00182
00183
00184 struct scsi_capacity_16 {
00185
00186 uint64_t lba;
00187
00188 uint32_t blksize;
00189
00190 uint8_t reserved[20];
00191 } __attribute__ (( packed ));
00192
00193
00194 union scsi_cdb {
00195 struct scsi_cdb_read_10 read10;
00196 struct scsi_cdb_read_16 read16;
00197 struct scsi_cdb_write_10 write10;
00198 struct scsi_cdb_write_16 write16;
00199 struct scsi_cdb_read_capacity_10 readcap10;
00200 struct scsi_cdb_read_capacity_16 readcap16;
00201 unsigned char bytes[16];
00202 };
00203
00204
00205 #define SCSI_CDB_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" \
00206 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
00207
00208
00209 #define SCSI_CDB_DATA(cdb) \
00210 (cdb).bytes[0], (cdb).bytes[1], (cdb).bytes[2], (cdb).bytes[3], \
00211 (cdb).bytes[4], (cdb).bytes[5], (cdb).bytes[6], (cdb).bytes[7], \
00212 (cdb).bytes[8], (cdb).bytes[9], (cdb).bytes[10], (cdb).bytes[11], \
00213 (cdb).bytes[12], (cdb).bytes[13], (cdb).bytes[14], (cdb).bytes[15]
00214
00215
00216
00217
00218 struct scsi_command {
00219
00220 union scsi_cdb cdb;
00221
00222 userptr_t data_out;
00223
00224
00225
00226
00227 size_t data_out_len;
00228
00229 userptr_t data_in;
00230
00231
00232
00233
00234 size_t data_in_len;
00235
00236 uint8_t status;
00237
00238 uint8_t sense_response;
00239
00240 int rc;
00241 };
00242
00243
00244
00245
00246
00247
00248 struct scsi_lun {
00249 uint16_t u16[4];
00250 } __attribute__ (( packed ));
00251
00252
00253 struct scsi_device {
00254
00255 struct block_device blockdev;
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 int ( * command ) ( struct scsi_device *scsi,
00271 struct scsi_command *command );
00272
00273 struct refcnt *backend;
00274 };
00275
00276 extern int scsi_detached_command ( struct scsi_device *scsi,
00277 struct scsi_command *command );
00278 extern int init_scsidev ( struct scsi_device *scsi );
00279 extern int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun );
00280
00281 #endif