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 SCSIDeviceInfo SCSIDeviceInfo
;
17 typedef struct SCSIRequest SCSIRequest
;
18 typedef struct SCSIReqOps SCSIReqOps
;
21 SCSI_XFER_NONE
, /* TEST_UNIT_READY, ... */
22 SCSI_XFER_FROM_DEV
, /* READ, INQUIRY, MODE_SENSE, ... */
23 SCSI_XFER_TO_DEV
, /* WRITE, MODE_SELECT, ... */
26 typedef struct SCSISense
{
32 #define SCSI_SENSE_BUF_SIZE 96
35 uint8_t buf
[SCSI_CMD_BUF_SIZE
];
39 enum SCSIXferMode mode
;
45 const SCSIReqOps
*ops
;
51 BlockDriverAIOCB
*aiocb
;
52 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
58 QTAILQ_ENTRY(SCSIRequest
) next
;
64 VMChangeStateEntry
*vmsentry
;
69 SCSISense unit_attention
;
71 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
73 QTAILQ_HEAD(, SCSIRequest
) requests
;
82 int cdrom_read_toc(int nb_sectors
, uint8_t *buf
, int msf
, int start_track
);
83 int cdrom_read_toc_raw(int nb_sectors
, uint8_t *buf
, int msf
, int session_num
);
88 void (*free_req
)(SCSIRequest
*req
);
89 int32_t (*send_command
)(SCSIRequest
*req
, uint8_t *buf
);
90 void (*read_data
)(SCSIRequest
*req
);
91 void (*write_data
)(SCSIRequest
*req
);
92 void (*cancel_io
)(SCSIRequest
*req
);
93 uint8_t *(*get_buf
)(SCSIRequest
*req
);
96 typedef int (*scsi_qdev_initfn
)(SCSIDevice
*dev
);
97 struct SCSIDeviceInfo
{
99 scsi_qdev_initfn init
;
100 void (*destroy
)(SCSIDevice
*s
);
101 SCSIRequest
*(*alloc_req
)(SCSIDevice
*s
, uint32_t tag
, uint32_t lun
,
102 uint8_t *buf
, void *hba_private
);
103 void (*unit_attention_reported
)(SCSIDevice
*s
);
108 int max_channel
, max_target
, max_lun
;
109 void (*transfer_data
)(SCSIRequest
*req
, uint32_t arg
);
110 void (*complete
)(SCSIRequest
*req
, uint32_t arg
);
111 void (*cancel
)(SCSIRequest
*req
);
118 SCSISense unit_attention
;
119 const SCSIBusInfo
*info
;
122 void scsi_bus_new(SCSIBus
*bus
, DeviceState
*host
, const SCSIBusInfo
*info
);
123 void scsi_qdev_register(SCSIDeviceInfo
*info
);
125 static inline SCSIBus
*scsi_bus_from_device(SCSIDevice
*d
)
127 return DO_UPCAST(SCSIBus
, qbus
, d
->qdev
.parent_bus
);
130 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, BlockDriverState
*bdrv
,
131 int unit
, bool removable
, int bootindex
);
132 int scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
);
135 * Predefined sense codes
138 /* No sense data available */
139 extern const struct SCSISense sense_code_NO_SENSE
;
140 /* LUN not ready, Manual intervention required */
141 extern const struct SCSISense sense_code_LUN_NOT_READY
;
142 /* LUN not ready, Medium not present */
143 extern const struct SCSISense sense_code_NO_MEDIUM
;
144 /* LUN not ready, medium removal prevented */
145 extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED
;
146 /* Hardware error, internal target failure */
147 extern const struct SCSISense sense_code_TARGET_FAILURE
;
148 /* Illegal request, invalid command operation code */
149 extern const struct SCSISense sense_code_INVALID_OPCODE
;
150 /* Illegal request, LBA out of range */
151 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE
;
152 /* Illegal request, Invalid field in CDB */
153 extern const struct SCSISense sense_code_INVALID_FIELD
;
154 /* Illegal request, LUN not supported */
155 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED
;
156 /* Illegal request, Saving parameters not supported */
157 extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED
;
158 /* Illegal request, Incompatible format */
159 extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT
;
160 /* Illegal request, medium removal prevented */
161 extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED
;
162 /* Command aborted, I/O process terminated */
163 extern const struct SCSISense sense_code_IO_ERROR
;
164 /* Command aborted, I_T Nexus loss occurred */
165 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS
;
166 /* Command aborted, Logical Unit failure */
167 extern const struct SCSISense sense_code_LUN_FAILURE
;
168 /* LUN not ready, Medium not present */
169 extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM
;
170 /* Unit attention, Power on, reset or bus device reset occurred */
171 extern const struct SCSISense sense_code_RESET
;
172 /* Unit attention, Medium may have changed*/
173 extern const struct SCSISense sense_code_MEDIUM_CHANGED
;
174 /* Unit attention, Reported LUNs data has changed */
175 extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED
;
176 /* Unit attention, Device internal reset */
177 extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET
;
179 #define SENSE_CODE(x) sense_code_ ## x
181 int scsi_sense_valid(SCSISense sense
);
182 int scsi_build_sense(uint8_t *in_buf
, int in_len
,
183 uint8_t *buf
, int len
, bool fixed
);
185 SCSIRequest
*scsi_req_alloc(const SCSIReqOps
*reqops
, SCSIDevice
*d
,
186 uint32_t tag
, uint32_t lun
, void *hba_private
);
187 SCSIRequest
*scsi_req_new(SCSIDevice
*d
, uint32_t tag
, uint32_t lun
,
188 uint8_t *buf
, void *hba_private
);
189 int32_t scsi_req_enqueue(SCSIRequest
*req
);
190 void scsi_req_free(SCSIRequest
*req
);
191 SCSIRequest
*scsi_req_ref(SCSIRequest
*req
);
192 void scsi_req_unref(SCSIRequest
*req
);
194 void scsi_req_build_sense(SCSIRequest
*req
, SCSISense sense
);
195 void scsi_req_print(SCSIRequest
*req
);
196 void scsi_req_continue(SCSIRequest
*req
);
197 void scsi_req_data(SCSIRequest
*req
, int len
);
198 void scsi_req_complete(SCSIRequest
*req
, int status
);
199 uint8_t *scsi_req_get_buf(SCSIRequest
*req
);
200 int scsi_req_get_sense(SCSIRequest
*req
, uint8_t *buf
, int len
);
201 void scsi_req_abort(SCSIRequest
*req
, int status
);
202 void scsi_req_cancel(SCSIRequest
*req
);
203 void scsi_req_retry(SCSIRequest
*req
);
204 void scsi_device_purge_requests(SCSIDevice
*sdev
, SCSISense sense
);
205 int scsi_device_get_sense(SCSIDevice
*dev
, uint8_t *buf
, int len
, bool fixed
);
206 SCSIDevice
*scsi_device_find(SCSIBus
*bus
, int channel
, int target
, int lun
);
208 /* scsi-generic.c. */
209 extern const SCSIReqOps scsi_generic_req_ops
;