5 #include <gpxe/blockdev.h>
6 #include <gpxe/uaccess.h>
7 #include <gpxe/refcnt.h>
15 FILE_LICENCE ( GPL2_OR_LATER
);
18 * @defgroup scsiops SCSI operation codes
22 #define SCSI_OPCODE_READ_10 0x28 /**< READ (10) */
23 #define SCSI_OPCODE_READ_16 0x88 /**< READ (16) */
24 #define SCSI_OPCODE_WRITE_10 0x2a /**< WRITE (10) */
25 #define SCSI_OPCODE_WRITE_16 0x8a /**< WRITE (16) */
26 #define SCSI_OPCODE_READ_CAPACITY_10 0x25 /**< READ CAPACITY (10) */
27 #define SCSI_OPCODE_SERVICE_ACTION_IN 0x9e /**< SERVICE ACTION IN */
28 #define SCSI_SERVICE_ACTION_READ_CAPACITY_16 0x10 /**< READ CAPACITY (16) */
33 * @defgroup scsiflags SCSI flags
37 #define SCSI_FL_FUA_NV 0x02 /**< Force unit access to NVS */
38 #define SCSI_FL_FUA 0x08 /**< Force unit access */
39 #define SCSI_FL_DPO 0x10 /**< Disable cache page out */
44 * @defgroup scsicdbs SCSI command data blocks
48 /** A SCSI "READ (10)" CDB */
49 struct scsi_cdb_read_10
{
56 * This is a logical block number, in big-endian order.
63 * This is a logical block count, in big-endian order.
68 } __attribute__ (( packed
));
70 /** A SCSI "READ (16)" CDB */
71 struct scsi_cdb_read_16
{
78 * This is a logical block number, in big-endian order.
83 * This is a logical block count, in big-endian order.
90 } __attribute__ (( packed
));
92 /** A SCSI "WRITE (10)" CDB */
93 struct scsi_cdb_write_10
{
100 * This is a logical block number, in big-endian order.
107 * This is a logical block count, in big-endian order.
112 } __attribute__ (( packed
));
114 /** A SCSI "WRITE (16)" CDB */
115 struct scsi_cdb_write_16
{
122 * This is a logical block number, in big-endian order.
127 * This is a logical block count, in big-endian order.
134 } __attribute__ (( packed
));
136 /** A SCSI "READ CAPACITY (10)" CDB */
137 struct scsi_cdb_read_capacity_10
{
142 /** Logical block address
144 * Applicable only if the PMI bit is set.
148 uint8_t reserved_b
[3];
151 } __attribute__ (( packed
));
153 /** SCSI "READ CAPACITY (10)" parameter data */
154 struct scsi_capacity_10
{
155 /** Maximum logical block number */
157 /** Block length in bytes */
159 } __attribute__ (( packed
));
161 /** A SCSI "READ CAPACITY (16)" CDB */
162 struct scsi_cdb_read_capacity_16
{
165 /** Service action */
166 uint8_t service_action
;
167 /** Logical block address
169 * Applicable only if the PMI bit is set.
174 * This is the size of the data-in buffer, in bytes.
181 } __attribute__ (( packed
));
183 /** SCSI "READ CAPACITY (16)" parameter data */
184 struct scsi_capacity_16
{
185 /** Maximum logical block number */
187 /** Block length in bytes */
190 uint8_t reserved
[20];
191 } __attribute__ (( packed
));
193 /** A SCSI Command Data Block */
195 struct scsi_cdb_read_10 read10
;
196 struct scsi_cdb_read_16 read16
;
197 struct scsi_cdb_write_10 write10
;
198 struct scsi_cdb_write_16 write16
;
199 struct scsi_cdb_read_capacity_10 readcap10
;
200 struct scsi_cdb_read_capacity_16 readcap16
;
201 unsigned char bytes
[16];
204 /** printf() format for dumping a scsi_cdb */
205 #define SCSI_CDB_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" \
206 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
208 /** printf() parameters for dumping a scsi_cdb */
209 #define SCSI_CDB_DATA(cdb) \
210 (cdb).bytes[0], (cdb).bytes[1], (cdb).bytes[2], (cdb).bytes[3], \
211 (cdb).bytes[4], (cdb).bytes[5], (cdb).bytes[6], (cdb).bytes[7], \
212 (cdb).bytes[8], (cdb).bytes[9], (cdb).bytes[10], (cdb).bytes[11], \
213 (cdb).bytes[12], (cdb).bytes[13], (cdb).bytes[14], (cdb).bytes[15]
217 /** A SCSI command */
218 struct scsi_command
{
219 /** CDB for this command */
221 /** Data-out buffer (may be NULL) */
223 /** Data-out buffer length
225 * Must be zero if @c data_out is NULL
228 /** Data-in buffer (may be NULL) */
230 /** Data-in buffer length
232 * Must be zero if @c data_in is NULL
235 /** SCSI status code */
237 /** SCSI sense response code */
238 uint8_t sense_response
;
239 /** Command status code */
245 * This is a four-level LUN as specified by SAM-2, in big-endian
250 } __attribute__ (( packed
));
254 /** Block device interface */
255 struct block_device blockdev
;
259 * @v scsi SCSI device
260 * @v command SCSI command
261 * @ret rc Return status code
263 * Note that a successful return status code indicates only
264 * that the SCSI command was issued. The caller must check
265 * the status field in the command structure to see when the
266 * command completes and whether, for example, the device
267 * returned CHECK CONDITION or some other non-success status
270 int ( * command
) ( struct scsi_device
*scsi
,
271 struct scsi_command
*command
);
272 /** Backing device */
273 struct refcnt
*backend
;
276 extern int scsi_detached_command ( struct scsi_device
*scsi
,
277 struct scsi_command
*command
);
278 extern int init_scsidev ( struct scsi_device
*scsi
);
279 extern int scsi_parse_lun ( const char *lun_string
, struct scsi_lun
*lun
);
281 #endif /* _GPXE_SCSI_H */