8 #define MAX_SCSI_DEVS 255
10 #define SCSI_CMD_BUF_SIZE 16
12 typedef struct SCSIBus SCSIBus
;
13 typedef struct SCSIBusInfo SCSIBusInfo
;
14 typedef struct SCSICommand SCSICommand
;
15 typedef struct SCSIDevice SCSIDevice
;
16 typedef struct SCSIRequest SCSIRequest
;
17 typedef struct SCSIReqOps SCSIReqOps
;
20 SCSI_XFER_NONE
, /* TEST_UNIT_READY, ... */
21 SCSI_XFER_FROM_DEV
, /* READ, INQUIRY, MODE_SENSE, ... */
22 SCSI_XFER_TO_DEV
, /* WRITE, MODE_SELECT, ... */
25 typedef struct SCSISense
{
31 #define SCSI_SENSE_BUF_SIZE 96
34 uint8_t buf
[SCSI_CMD_BUF_SIZE
];
38 enum SCSIXferMode mode
;
44 const SCSIReqOps
*ops
;
51 BlockDriverAIOCB
*aiocb
;
54 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
60 QTAILQ_ENTRY(SCSIRequest
) next
;
63 #define TYPE_SCSI_DEVICE "scsi-device"
64 #define SCSI_DEVICE(obj) \
65 OBJECT_CHECK(SCSIDevice, (obj), TYPE_SCSI_DEVICE)
66 #define SCSI_DEVICE_CLASS(klass) \
67 OBJECT_CLASS_CHECK(SCSIDeviceClass, (klass), TYPE_SCSI_DEVICE)
68 #define SCSI_DEVICE_GET_CLASS(obj) \
69 OBJECT_GET_CLASS(SCSIDeviceClass, (obj), TYPE_SCSI_DEVICE)
71 typedef struct SCSIDeviceClass
{
72 DeviceClass parent_class
;
73 int (*init
)(SCSIDevice
*dev
);
74 void (*destroy
)(SCSIDevice
*s
);
75 SCSIRequest
*(*alloc_req
)(SCSIDevice
*s
, uint32_t tag
, uint32_t lun
,
76 uint8_t *buf
, void *hba_private
);
77 void (*unit_attention_reported
)(SCSIDevice
*s
);
83 VMChangeStateEntry
*vmsentry
;
87 SCSISense unit_attention
;
89 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
91 QTAILQ_HEAD(, SCSIRequest
) requests
;
99 extern const VMStateDescription vmstate_scsi_device
;
101 #define VMSTATE_SCSI_DEVICE(_field, _state) { \
102 .name = (stringify(_field)), \
103 .size = sizeof(SCSIDevice), \
104 .vmsd = &vmstate_scsi_device, \
105 .flags = VMS_STRUCT, \
106 .offset = vmstate_offset_value(_state, _field, SCSIDevice), \
110 int cdrom_read_toc(int nb_sectors
, uint8_t *buf
, int msf
, int start_track
);
111 int cdrom_read_toc_raw(int nb_sectors
, uint8_t *buf
, int msf
, int session_num
);
116 void (*free_req
)(SCSIRequest
*req
);
117 int32_t (*send_command
)(SCSIRequest
*req
, uint8_t *buf
);
118 void (*read_data
)(SCSIRequest
*req
);
119 void (*write_data
)(SCSIRequest
*req
);
120 void (*cancel_io
)(SCSIRequest
*req
);
121 uint8_t *(*get_buf
)(SCSIRequest
*req
);
123 void (*save_request
)(QEMUFile
*f
, SCSIRequest
*req
);
124 void (*load_request
)(QEMUFile
*f
, SCSIRequest
*req
);
129 int max_channel
, max_target
, max_lun
;
130 void (*transfer_data
)(SCSIRequest
*req
, uint32_t arg
);
131 void (*complete
)(SCSIRequest
*req
, uint32_t arg
, size_t resid
);
132 void (*cancel
)(SCSIRequest
*req
);
133 QEMUSGList
*(*get_sg_list
)(SCSIRequest
*req
);
135 void (*save_request
)(QEMUFile
*f
, SCSIRequest
*req
);
136 void *(*load_request
)(QEMUFile
*f
, SCSIRequest
*req
);
139 #define TYPE_SCSI_BUS "SCSI"
140 #define SCSI_BUS(obj) OBJECT_CHECK(SCSIBus, (obj), TYPE_SCSI_BUS)
146 SCSISense unit_attention
;
147 const SCSIBusInfo
*info
;
150 void scsi_bus_new(SCSIBus
*bus
, DeviceState
*host
, const SCSIBusInfo
*info
);
152 static inline SCSIBus
*scsi_bus_from_device(SCSIDevice
*d
)
154 return DO_UPCAST(SCSIBus
, qbus
, d
->qdev
.parent_bus
);
157 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, BlockDriverState
*bdrv
,
158 int unit
, bool removable
, int bootindex
);
159 int scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
);
162 * Predefined sense codes
165 /* No sense data available */
166 extern const struct SCSISense sense_code_NO_SENSE
;
167 /* LUN not ready, Manual intervention required */
168 extern const struct SCSISense sense_code_LUN_NOT_READY
;
169 /* LUN not ready, Medium not present */
170 extern const struct SCSISense sense_code_NO_MEDIUM
;
171 /* LUN not ready, medium removal prevented */
172 extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED
;
173 /* Hardware error, internal target failure */
174 extern const struct SCSISense sense_code_TARGET_FAILURE
;
175 /* Illegal request, invalid command operation code */
176 extern const struct SCSISense sense_code_INVALID_OPCODE
;
177 /* Illegal request, LBA out of range */
178 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE
;
179 /* Illegal request, Invalid field in CDB */
180 extern const struct SCSISense sense_code_INVALID_FIELD
;
181 /* Illegal request, LUN not supported */
182 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED
;
183 /* Illegal request, Saving parameters not supported */
184 extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED
;
185 /* Illegal request, Incompatible format */
186 extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT
;
187 /* Illegal request, medium removal prevented */
188 extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED
;
189 /* Command aborted, I/O process terminated */
190 extern const struct SCSISense sense_code_IO_ERROR
;
191 /* Command aborted, I_T Nexus loss occurred */
192 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS
;
193 /* Command aborted, Logical Unit failure */
194 extern const struct SCSISense sense_code_LUN_FAILURE
;
195 /* LUN not ready, Medium not present */
196 extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM
;
197 /* Unit attention, Power on, reset or bus device reset occurred */
198 extern const struct SCSISense sense_code_RESET
;
199 /* Unit attention, Medium may have changed*/
200 extern const struct SCSISense sense_code_MEDIUM_CHANGED
;
201 /* Unit attention, Reported LUNs data has changed */
202 extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED
;
203 /* Unit attention, Device internal reset */
204 extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET
;
206 #define SENSE_CODE(x) sense_code_ ## x
208 int scsi_sense_valid(SCSISense sense
);
209 int scsi_build_sense(uint8_t *in_buf
, int in_len
,
210 uint8_t *buf
, int len
, bool fixed
);
212 SCSIRequest
*scsi_req_alloc(const SCSIReqOps
*reqops
, SCSIDevice
*d
,
213 uint32_t tag
, uint32_t lun
, void *hba_private
);
214 SCSIRequest
*scsi_req_new(SCSIDevice
*d
, uint32_t tag
, uint32_t lun
,
215 uint8_t *buf
, void *hba_private
);
216 int32_t scsi_req_enqueue(SCSIRequest
*req
);
217 void scsi_req_free(SCSIRequest
*req
);
218 SCSIRequest
*scsi_req_ref(SCSIRequest
*req
);
219 void scsi_req_unref(SCSIRequest
*req
);
221 void scsi_req_build_sense(SCSIRequest
*req
, SCSISense sense
);
222 void scsi_req_print(SCSIRequest
*req
);
223 void scsi_req_continue(SCSIRequest
*req
);
224 void scsi_req_data(SCSIRequest
*req
, int len
);
225 void scsi_req_complete(SCSIRequest
*req
, int status
);
226 uint8_t *scsi_req_get_buf(SCSIRequest
*req
);
227 int scsi_req_get_sense(SCSIRequest
*req
, uint8_t *buf
, int len
);
228 void scsi_req_abort(SCSIRequest
*req
, int status
);
229 void scsi_req_cancel(SCSIRequest
*req
);
230 void scsi_req_retry(SCSIRequest
*req
);
231 void scsi_device_purge_requests(SCSIDevice
*sdev
, SCSISense sense
);
232 int scsi_device_get_sense(SCSIDevice
*dev
, uint8_t *buf
, int len
, bool fixed
);
233 SCSIDevice
*scsi_device_find(SCSIBus
*bus
, int channel
, int target
, int lun
);
235 /* scsi-generic.c. */
236 extern const SCSIReqOps scsi_generic_req_ops
;