8 #define MAX_SCSI_DEVS 255
10 #define SCSI_CMD_BUF_SIZE 16
12 typedef struct SCSIBus SCSIBus
;
13 typedef struct SCSIBusOps SCSIBusOps
;
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
;
51 BlockDriverAIOCB
*aiocb
;
52 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
56 QTAILQ_ENTRY(SCSIRequest
) next
;
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
);
109 const SCSIBusOps
*ops
;
111 SCSIDevice
*devs
[MAX_SCSI_DEVS
];
114 void scsi_bus_new(SCSIBus
*bus
, DeviceState
*host
, int tcq
, int ndev
,
115 const SCSIBusOps
*ops
);
116 void scsi_qdev_register(SCSIDeviceInfo
*info
);
118 static inline SCSIBus
*scsi_bus_from_device(SCSIDevice
*d
)
120 return DO_UPCAST(SCSIBus
, qbus
, d
->qdev
.parent_bus
);
123 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, BlockDriverState
*bdrv
,
124 int unit
, bool removable
);
125 int scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
);
128 * Predefined sense codes
131 /* No sense data available */
132 extern const struct SCSISense sense_code_NO_SENSE
;
133 /* LUN not ready, Manual intervention required */
134 extern const struct SCSISense sense_code_LUN_NOT_READY
;
135 /* LUN not ready, Medium not present */
136 extern const struct SCSISense sense_code_NO_MEDIUM
;
137 /* Hardware error, internal target failure */
138 extern const struct SCSISense sense_code_TARGET_FAILURE
;
139 /* Illegal request, invalid command operation code */
140 extern const struct SCSISense sense_code_INVALID_OPCODE
;
141 /* Illegal request, LBA out of range */
142 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE
;
143 /* Illegal request, Invalid field in CDB */
144 extern const struct SCSISense sense_code_INVALID_FIELD
;
145 /* Illegal request, LUN not supported */
146 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED
;
147 /* Command aborted, I/O process terminated */
148 extern const struct SCSISense sense_code_IO_ERROR
;
149 /* Command aborted, I_T Nexus loss occurred */
150 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS
;
151 /* Command aborted, Logical Unit failure */
152 extern const struct SCSISense sense_code_LUN_FAILURE
;
154 #define SENSE_CODE(x) sense_code_ ## x
156 int scsi_sense_valid(SCSISense sense
);
158 SCSIRequest
*scsi_req_alloc(SCSIReqOps
*reqops
, SCSIDevice
*d
, uint32_t tag
,
159 uint32_t lun
, void *hba_private
);
160 SCSIRequest
*scsi_req_new(SCSIDevice
*d
, uint32_t tag
, uint32_t lun
,
161 uint8_t *buf
, void *hba_private
);
162 int32_t scsi_req_enqueue(SCSIRequest
*req
);
163 void scsi_req_free(SCSIRequest
*req
);
164 SCSIRequest
*scsi_req_ref(SCSIRequest
*req
);
165 void scsi_req_unref(SCSIRequest
*req
);
167 void scsi_req_build_sense(SCSIRequest
*req
, SCSISense sense
);
168 void scsi_req_print(SCSIRequest
*req
);
169 void scsi_req_continue(SCSIRequest
*req
);
170 void scsi_req_data(SCSIRequest
*req
, int len
);
171 void scsi_req_complete(SCSIRequest
*req
, int status
);
172 uint8_t *scsi_req_get_buf(SCSIRequest
*req
);
173 int scsi_req_get_sense(SCSIRequest
*req
, uint8_t *buf
, int len
);
174 void scsi_req_abort(SCSIRequest
*req
, int status
);
175 void scsi_req_cancel(SCSIRequest
*req
);
176 void scsi_device_purge_requests(SCSIDevice
*sdev
);
177 int scsi_device_get_sense(SCSIDevice
*dev
, uint8_t *buf
, int len
, bool fixed
);