iPXE
scsi.h
Go to the documentation of this file.
1#ifndef _IPXE_SCSI_H
2#define _IPXE_SCSI_H
4#include <stdint.h>
6
7/** @file
8 *
9 * SCSI devices
10 *
11 */
12
13FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
14FILE_SECBOOT ( PERMITTED );
16/** Maximum block for READ/WRITE (10) commands */
17#define SCSI_MAX_BLOCK_10 0xffffffffULL
18
19/**
20 * @defgroup scsiops SCSI operation codes
21 * @{
22 */
23
24#define SCSI_OPCODE_READ_10 0x28 /**< READ (10) */
25#define SCSI_OPCODE_READ_16 0x88 /**< READ (16) */
26#define SCSI_OPCODE_WRITE_10 0x2a /**< WRITE (10) */
27#define SCSI_OPCODE_WRITE_16 0x8a /**< WRITE (16) */
28#define SCSI_OPCODE_READ_CAPACITY_10 0x25 /**< READ CAPACITY (10) */
29#define SCSI_OPCODE_SERVICE_ACTION_IN 0x9e /**< SERVICE ACTION IN */
30#define SCSI_SERVICE_ACTION_READ_CAPACITY_16 0x10 /**< READ CAPACITY (16) */
31#define SCSI_OPCODE_TEST_UNIT_READY 0x00 /**< TEST UNIT READY */
32
33/** @} */
34
35/**
36 * @defgroup scsiflags SCSI flags
37 * @{
38 */
39
40#define SCSI_FL_FUA_NV 0x02 /**< Force unit access to NVS */
41#define SCSI_FL_FUA 0x08 /**< Force unit access */
42#define SCSI_FL_DPO 0x10 /**< Disable cache page out */
43
44/** @} */
45
46/**
47 * @defgroup scsicdbs SCSI command data blocks
48 * @{
49 */
50
51/** A SCSI "READ (10)" CDB */
53 /** Opcode (0x28) */
55 /** Flags */
57 /** Start address
58 *
59 * This is a logical block number, in big-endian order.
60 */
62 /** Group number */
64 /** Transfer length
65 *
66 * This is a logical block count, in big-endian order.
67 */
69 /** Control byte */
71} __attribute__ (( packed ));
72
73/** A SCSI "READ (16)" CDB */
75 /** Opcode (0x88) */
77 /** Flags */
79 /** Start address
80 *
81 * This is a logical block number, in big-endian order.
82 */
84 /** Transfer length
85 *
86 * This is a logical block count, in big-endian order.
87 */
89 /** Group number */
91 /** Control byte */
93} __attribute__ (( packed ));
94
95/** A SCSI "WRITE (10)" CDB */
97 /** Opcode (0x2a) */
99 /** Flags */
101 /** Start address
102 *
103 * This is a logical block number, in big-endian order.
104 */
106 /** Group number */
108 /** Transfer length
109 *
110 * This is a logical block count, in big-endian order.
111 */
113 /** Control byte */
115} __attribute__ (( packed ));
116
117/** A SCSI "WRITE (16)" CDB */
119 /** Opcode (0x8a) */
121 /** Flags */
123 /** Start address
124 *
125 * This is a logical block number, in big-endian order.
126 */
128 /** Transfer length
129 *
130 * This is a logical block count, in big-endian order.
131 */
133 /** Group number */
135 /** Control byte */
137} __attribute__ (( packed ));
138
139/** A SCSI "READ CAPACITY (10)" CDB */
141 /** Opcode (0x25) */
143 /** Reserved */
145 /** Logical block address
146 *
147 * Applicable only if the PMI bit is set.
148 */
150 /** Reserved */
152 /** Control byte */
154} __attribute__ (( packed ));
155
156/** SCSI "READ CAPACITY (10)" parameter data */
158 /** Maximum logical block number */
160 /** Block length in bytes */
162} __attribute__ (( packed ));
163
164/** A SCSI "READ CAPACITY (16)" CDB */
166 /** Opcode (0x9e) */
168 /** Service action */
170 /** Logical block address
171 *
172 * Applicable only if the PMI bit is set.
173 */
175 /** Transfer length
176 *
177 * This is the size of the data-in buffer, in bytes.
178 */
180 /** Reserved */
182 /** Control byte */
184} __attribute__ (( packed ));
185
186/** SCSI "READ CAPACITY (16)" parameter data */
188 /** Maximum logical block number */
190 /** Block length in bytes */
192 /** Reserved */
194} __attribute__ (( packed ));
195
196/** A SCSI "TEST UNIT READY" CDB */
198 /** Opcode (0x00) */
200 /** Reserved */
202 /** Control byte */
204} __attribute__ (( packed ));
205
206/** A SCSI Command Data Block */
217
218/** printf() format for dumping a scsi_cdb */
219#define SCSI_CDB_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" \
220 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
221
222/** printf() parameters for dumping a scsi_cdb */
223#define SCSI_CDB_DATA(cdb) \
224 (cdb).bytes[0], (cdb).bytes[1], (cdb).bytes[2], (cdb).bytes[3], \
225 (cdb).bytes[4], (cdb).bytes[5], (cdb).bytes[6], (cdb).bytes[7], \
226 (cdb).bytes[8], (cdb).bytes[9], (cdb).bytes[10], (cdb).bytes[11], \
227 (cdb).bytes[12], (cdb).bytes[13], (cdb).bytes[14], (cdb).bytes[15]
228
229/** @} */
230
231/** A SCSI LUN
232 *
233 * This is a four-level LUN as specified by SAM-2, in big-endian
234 * order.
235 */
236struct scsi_lun {
238} __attribute__ (( packed ));
239
240/** printf() format for dumping a scsi_lun */
241#define SCSI_LUN_FORMAT "%04x-%04x-%04x-%04x"
242
243/** printf() parameters for dumping a scsi_lun */
244#define SCSI_LUN_DATA(lun) \
245 ntohs ( (lun).u16[0] ), ntohs ( (lun).u16[1] ), \
246 ntohs ( (lun).u16[2] ), ntohs ( (lun).u16[3] )
247
248/** A SCSI command information unit */
249struct scsi_cmd {
250 /** LUN */
251 struct scsi_lun lun;
252 /** CDB for this command */
254 /** Data-out buffer (may be NULL) */
255 void *data_out;
256 /** Data-out buffer length
257 *
258 * Must be zero if @c data_out is NULL
259 */
261 /** Data-in buffer (may be NULL) */
262 void *data_in;
263 /** Data-in buffer length
264 *
265 * Must be zero if @c data_in is NULL
266 */
268};
269
270/** SCSI fixed-format sense data */
272 /** Response code */
274 /** Reserved */
276 /** Sense key */
278 /** Information */
280 /** Additional sense length */
282 /** Command-specific information */
284 /** Additional sense code and qualifier */
286} __attribute__ (( packed ));
287
288/** SCSI descriptor-format sense data */
290 /** Response code */
292 /** Sense key */
294 /** Additional sense code and qualifier */
296} __attribute__ (( packed ));
297
298/** SCSI sense data */
299union scsi_sns {
300 /** Response code */
302 /** Fixed-format sense data */
304 /** Descriptor-format sense data */
306};
307
308/** SCSI sense response code mask */
309#define SCSI_SENSE_CODE_MASK 0x7f
310
311/** Test if SCSI sense data is in fixed format
312 *
313 * @v code Response code
314 * @ret is_fixed Sense data is in fixed format
315 */
316#define SCSI_SENSE_FIXED( code ) ( ( (code) & 0x7e ) == 0x70 )
317
318/** SCSI sense key mask */
319#define SCSI_SENSE_KEY_MASK 0x0f
320
321/** A SCSI response information unit */
322struct scsi_rsp {
323 /** SCSI status code */
325 /** Data overrun (or negative underrun) */
327 /** Autosense data (if any)
328 *
329 * To minimise code size, this is stored as the first four
330 * bytes of a descriptor-format sense data block (even if the
331 * response code indicates fixed-format sense data).
332 */
334};
335
336extern int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun );
337extern void scsi_parse_sense ( const void *data, size_t len,
338 struct scsi_sns_descriptor *sense );
339
340extern int scsi_command ( struct interface *control, struct interface *data,
341 struct scsi_cmd *command );
342#define scsi_command_TYPE( object_type ) \
343 typeof ( int ( object_type, struct interface *data, \
344 struct scsi_cmd *command ) )
345
346extern void scsi_response ( struct interface *intf, struct scsi_rsp *response );
347#define scsi_response_TYPE( object_type ) \
348 typeof ( void ( object_type, struct scsi_rsp *response ) )
349
350extern int scsi_open ( struct interface *block, struct interface *scsi,
351 struct scsi_lun *lun );
352
353#endif /* _IPXE_SCSI_H */
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
signed long ssize_t
Definition stdint.h:7
ring len
Length.
Definition dwmac.h:226
uint8_t lun
Logical Unit Number.
Definition edd.h:3
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
union scsi_cdb __attribute__
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Object interfaces.
uint8_t block[3][8]
DES-encrypted blocks.
Definition mschapv2.h:1
uint32_t control
Control.
Definition myson.h:3
int scsi_open(struct interface *block, struct interface *scsi, struct scsi_lun *lun)
Open SCSI device.
Definition scsi.c:985
int scsi_command(struct interface *control, struct interface *data, struct scsi_cmd *command)
Issue SCSI command.
Definition scsi.c:182
void scsi_response(struct interface *intf, struct scsi_rsp *response)
Report SCSI response.
Definition scsi.c:207
void scsi_parse_sense(const void *data, size_t len, struct scsi_sns_descriptor *sense)
Parse SCSI sense data.
Definition scsi.c:147
int scsi_parse_lun(const char *lun_string, struct scsi_lun *lun)
Parse SCSI LUN.
Definition scsi.c:118
A command-line command.
Definition command.h:10
An object interface.
Definition interface.h:125
SCSI "READ CAPACITY (10)" parameter data.
Definition scsi.h:157
uint32_t lba
Maximum logical block number.
Definition scsi.h:159
uint32_t blksize
Block length in bytes.
Definition scsi.h:161
SCSI "READ CAPACITY (16)" parameter data.
Definition scsi.h:187
uint32_t blksize
Block length in bytes.
Definition scsi.h:191
uint64_t lba
Maximum logical block number.
Definition scsi.h:189
uint8_t reserved[20]
Reserved.
Definition scsi.h:193
A SCSI "READ (10)" CDB.
Definition scsi.h:52
uint8_t flags
Flags.
Definition scsi.h:56
uint16_t len
Transfer length.
Definition scsi.h:68
uint8_t group
Group number.
Definition scsi.h:63
uint32_t lba
Start address.
Definition scsi.h:61
uint8_t control
Control byte.
Definition scsi.h:70
uint8_t opcode
Opcode (0x28)
Definition scsi.h:54
A SCSI "READ (16)" CDB.
Definition scsi.h:74
uint8_t flags
Flags.
Definition scsi.h:78
uint8_t control
Control byte.
Definition scsi.h:92
uint8_t group
Group number.
Definition scsi.h:90
uint8_t opcode
Opcode (0x88)
Definition scsi.h:76
uint64_t lba
Start address.
Definition scsi.h:83
uint32_t len
Transfer length.
Definition scsi.h:88
A SCSI "READ CAPACITY (10)" CDB.
Definition scsi.h:140
uint8_t reserved_a
Reserved.
Definition scsi.h:144
uint32_t lba
Logical block address.
Definition scsi.h:149
uint8_t control
Control byte.
Definition scsi.h:153
uint8_t opcode
Opcode (0x25)
Definition scsi.h:142
uint8_t reserved_b[3]
Reserved.
Definition scsi.h:151
A SCSI "READ CAPACITY (16)" CDB.
Definition scsi.h:165
uint8_t service_action
Service action.
Definition scsi.h:169
uint8_t control
Control byte.
Definition scsi.h:183
uint8_t reserved
Reserved.
Definition scsi.h:181
uint8_t opcode
Opcode (0x9e)
Definition scsi.h:167
uint64_t lba
Logical block address.
Definition scsi.h:174
uint32_t len
Transfer length.
Definition scsi.h:179
A SCSI "TEST UNIT READY" CDB.
Definition scsi.h:197
uint8_t control
Control byte.
Definition scsi.h:203
uint8_t reserved[4]
Reserved.
Definition scsi.h:201
uint8_t opcode
Opcode (0x00)
Definition scsi.h:199
A SCSI "WRITE (10)" CDB.
Definition scsi.h:96
uint32_t lba
Start address.
Definition scsi.h:105
uint8_t opcode
Opcode (0x2a)
Definition scsi.h:98
uint8_t flags
Flags.
Definition scsi.h:100
uint8_t control
Control byte.
Definition scsi.h:114
uint8_t group
Group number.
Definition scsi.h:107
uint16_t len
Transfer length.
Definition scsi.h:112
A SCSI "WRITE (16)" CDB.
Definition scsi.h:118
uint64_t lba
Start address.
Definition scsi.h:127
uint8_t flags
Flags.
Definition scsi.h:122
uint8_t control
Control byte.
Definition scsi.h:136
uint8_t group
Group number.
Definition scsi.h:134
uint8_t opcode
Opcode (0x8a)
Definition scsi.h:120
uint32_t len
Transfer length.
Definition scsi.h:132
A SCSI command information unit.
Definition scsi.h:249
struct scsi_lun lun
LUN.
Definition scsi.h:251
size_t data_out_len
Data-out buffer length.
Definition scsi.h:260
size_t data_in_len
Data-in buffer length.
Definition scsi.h:267
void * data_out
Data-out buffer (may be NULL)
Definition scsi.h:255
void * data_in
Data-in buffer (may be NULL)
Definition scsi.h:262
union scsi_cdb cdb
CDB for this command.
Definition scsi.h:253
A SCSI LUN.
Definition scsi.h:236
uint16_t u16[4]
Definition scsi.h:237
A SCSI response information unit.
Definition scsi.h:322
struct scsi_sns_descriptor sense
Autosense data (if any)
Definition scsi.h:333
uint8_t status
SCSI status code.
Definition scsi.h:324
ssize_t overrun
Data overrun (or negative underrun)
Definition scsi.h:326
SCSI descriptor-format sense data.
Definition scsi.h:289
uint8_t code
Response code.
Definition scsi.h:291
uint8_t key
Sense key.
Definition scsi.h:293
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:295
SCSI fixed-format sense data.
Definition scsi.h:271
uint16_t additional
Additional sense code and qualifier.
Definition scsi.h:285
uint32_t info
Information.
Definition scsi.h:279
uint8_t code
Response code.
Definition scsi.h:273
uint32_t cs_info
Command-specific information.
Definition scsi.h:283
uint8_t reserved
Reserved.
Definition scsi.h:275
uint8_t len
Additional sense length.
Definition scsi.h:281
uint8_t key
Sense key.
Definition scsi.h:277
A SCSI Command Data Block.
Definition scsi.h:207
struct scsi_cdb_test_unit_ready testready
Definition scsi.h:214
struct scsi_cdb_read_10 read10
Definition scsi.h:208
struct scsi_cdb_read_capacity_10 readcap10
Definition scsi.h:212
struct scsi_cdb_write_16 write16
Definition scsi.h:211
struct scsi_cdb_read_capacity_16 readcap16
Definition scsi.h:213
struct scsi_cdb_read_16 read16
Definition scsi.h:209
unsigned char bytes[16]
Definition scsi.h:215
struct scsi_cdb_write_10 write10
Definition scsi.h:210
SCSI sense data.
Definition scsi.h:299
struct scsi_sns_fixed fixed
Fixed-format sense data.
Definition scsi.h:303
uint8_t code
Response code.
Definition scsi.h:301
struct scsi_sns_descriptor desc
Descriptor-format sense data.
Definition scsi.h:305