7 #define MAX_SCSI_DEVS 255
9 #define SCSI_CMD_BUF_SIZE 16
11 typedef struct SCSIBus SCSIBus
;
12 typedef struct SCSIBusOps SCSIBusOps
;
13 typedef struct SCSICommand SCSICommand
;
14 typedef struct SCSIDevice SCSIDevice
;
15 typedef struct SCSIDeviceInfo SCSIDeviceInfo
;
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
;
50 BlockDriverAIOCB
*aiocb
;
51 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
55 QTAILQ_ENTRY(SCSIRequest
) next
;
64 SCSISense unit_attention
;
65 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
67 QTAILQ_HEAD(, SCSIRequest
) requests
;
74 int cdrom_read_toc(int nb_sectors
, uint8_t *buf
, int msf
, int start_track
);
75 int cdrom_read_toc_raw(int nb_sectors
, uint8_t *buf
, int msf
, int session_num
);
80 void (*free_req
)(SCSIRequest
*req
);
81 int32_t (*send_command
)(SCSIRequest
*req
, uint8_t *buf
);
82 void (*read_data
)(SCSIRequest
*req
);
83 void (*write_data
)(SCSIRequest
*req
);
84 void (*cancel_io
)(SCSIRequest
*req
);
85 uint8_t *(*get_buf
)(SCSIRequest
*req
);
88 typedef int (*scsi_qdev_initfn
)(SCSIDevice
*dev
);
89 struct SCSIDeviceInfo
{
91 scsi_qdev_initfn init
;
92 void (*destroy
)(SCSIDevice
*s
);
93 SCSIRequest
*(*alloc_req
)(SCSIDevice
*s
, uint32_t tag
, uint32_t lun
,
99 void (*transfer_data
)(SCSIRequest
*req
, uint32_t arg
);
100 void (*complete
)(SCSIRequest
*req
, uint32_t arg
);
101 void (*cancel
)(SCSIRequest
*req
);
108 SCSISense unit_attention
;
110 const SCSIBusOps
*ops
;
112 SCSIDevice
*devs
[MAX_SCSI_DEVS
];
115 void scsi_bus_new(SCSIBus
*bus
, DeviceState
*host
, int tcq
, int ndev
,
116 const SCSIBusOps
*ops
);
117 void scsi_qdev_register(SCSIDeviceInfo
*info
);
119 static inline SCSIBus
*scsi_bus_from_device(SCSIDevice
*d
)
121 return DO_UPCAST(SCSIBus
, qbus
, d
->qdev
.parent_bus
);
124 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, BlockDriverState
*bdrv
,
125 int unit
, bool removable
);
126 int scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
);
129 * Predefined sense codes
132 /* No sense data available */
133 extern const struct SCSISense sense_code_NO_SENSE
;
134 /* LUN not ready, Manual intervention required */
135 extern const struct SCSISense sense_code_LUN_NOT_READY
;
136 /* LUN not ready, Medium not present */
137 extern const struct SCSISense sense_code_NO_MEDIUM
;
138 /* LUN not ready, medium removal prevented */
139 extern const struct SCSISense sense_code_NOT_READY_REMOVAL_PREVENTED
;
140 /* Hardware error, internal target failure */
141 extern const struct SCSISense sense_code_TARGET_FAILURE
;
142 /* Illegal request, invalid command operation code */
143 extern const struct SCSISense sense_code_INVALID_OPCODE
;
144 /* Illegal request, LBA out of range */
145 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE
;
146 /* Illegal request, Invalid field in CDB */
147 extern const struct SCSISense sense_code_INVALID_FIELD
;
148 /* Illegal request, LUN not supported */
149 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED
;
150 /* Illegal request, Saving parameters not supported */
151 extern const struct SCSISense sense_code_SAVING_PARAMS_NOT_SUPPORTED
;
152 /* Illegal request, Incompatible format */
153 extern const struct SCSISense sense_code_INCOMPATIBLE_FORMAT
;
154 /* Illegal request, medium removal prevented */
155 extern const struct SCSISense sense_code_ILLEGAL_REQ_REMOVAL_PREVENTED
;
156 /* Command aborted, I/O process terminated */
157 extern const struct SCSISense sense_code_IO_ERROR
;
158 /* Command aborted, I_T Nexus loss occurred */
159 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS
;
160 /* Command aborted, Logical Unit failure */
161 extern const struct SCSISense sense_code_LUN_FAILURE
;
162 /* Unit attention, Power on, reset or bus device reset occurred */
163 extern const struct SCSISense sense_code_RESET
;
164 /* Unit attention, Medium may have changed*/
165 extern const struct SCSISense sense_code_MEDIUM_CHANGED
;
166 /* Unit attention, Reported LUNs data has changed */
167 extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED
;
168 /* Unit attention, Device internal reset */
169 extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET
;
171 #define SENSE_CODE(x) sense_code_ ## x
173 int scsi_sense_valid(SCSISense sense
);
175 SCSIRequest
*scsi_req_alloc(SCSIReqOps
*reqops
, SCSIDevice
*d
, uint32_t tag
,
176 uint32_t lun
, void *hba_private
);
177 SCSIRequest
*scsi_req_new(SCSIDevice
*d
, uint32_t tag
, uint32_t lun
,
178 uint8_t *buf
, void *hba_private
);
179 int32_t scsi_req_enqueue(SCSIRequest
*req
);
180 void scsi_req_free(SCSIRequest
*req
);
181 SCSIRequest
*scsi_req_ref(SCSIRequest
*req
);
182 void scsi_req_unref(SCSIRequest
*req
);
184 void scsi_req_build_sense(SCSIRequest
*req
, SCSISense sense
);
185 void scsi_req_print(SCSIRequest
*req
);
186 void scsi_req_continue(SCSIRequest
*req
);
187 void scsi_req_data(SCSIRequest
*req
, int len
);
188 void scsi_req_complete(SCSIRequest
*req
, int status
);
189 uint8_t *scsi_req_get_buf(SCSIRequest
*req
);
190 int scsi_req_get_sense(SCSIRequest
*req
, uint8_t *buf
, int len
);
191 void scsi_req_abort(SCSIRequest
*req
, int status
);
192 void scsi_req_cancel(SCSIRequest
*req
);
193 void scsi_device_purge_requests(SCSIDevice
*sdev
, SCSISense sense
);
194 int scsi_device_get_sense(SCSIDevice
*dev
, uint8_t *buf
, int len
, bool fixed
);