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 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
42 uint8_t buf
[SCSI_CMD_BUF_SIZE
];
46 enum SCSIXferMode mode
;
48 BlockDriverAIOCB
*aiocb
;
49 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
53 QTAILQ_ENTRY(SCSIRequest
) next
;
62 uint8_t sense
[SCSI_SENSE_BUF_SIZE
];
64 QTAILQ_HEAD(, SCSIRequest
) requests
;
70 int cdrom_read_toc(int nb_sectors
, uint8_t *buf
, int msf
, int start_track
);
71 int cdrom_read_toc_raw(int nb_sectors
, uint8_t *buf
, int msf
, int session_num
);
76 void (*free_req
)(SCSIRequest
*req
);
77 int32_t (*send_command
)(SCSIRequest
*req
, uint8_t *buf
);
78 void (*read_data
)(SCSIRequest
*req
);
79 void (*write_data
)(SCSIRequest
*req
);
80 void (*cancel_io
)(SCSIRequest
*req
);
81 uint8_t *(*get_buf
)(SCSIRequest
*req
);
84 typedef int (*scsi_qdev_initfn
)(SCSIDevice
*dev
);
85 struct SCSIDeviceInfo
{
87 scsi_qdev_initfn init
;
88 void (*destroy
)(SCSIDevice
*s
);
89 SCSIRequest
*(*alloc_req
)(SCSIDevice
*s
, uint32_t tag
, uint32_t lun
,
95 void (*transfer_data
)(SCSIRequest
*req
, uint32_t arg
);
96 void (*complete
)(SCSIRequest
*req
, uint32_t arg
);
97 void (*cancel
)(SCSIRequest
*req
);
105 const SCSIBusOps
*ops
;
107 SCSIDevice
*devs
[MAX_SCSI_DEVS
];
110 void scsi_bus_new(SCSIBus
*bus
, DeviceState
*host
, int tcq
, int ndev
,
111 const SCSIBusOps
*ops
);
112 void scsi_qdev_register(SCSIDeviceInfo
*info
);
114 static inline SCSIBus
*scsi_bus_from_device(SCSIDevice
*d
)
116 return DO_UPCAST(SCSIBus
, qbus
, d
->qdev
.parent_bus
);
119 SCSIDevice
*scsi_bus_legacy_add_drive(SCSIBus
*bus
, BlockDriverState
*bdrv
,
120 int unit
, bool removable
);
121 int scsi_bus_legacy_handle_cmdline(SCSIBus
*bus
);
124 * Predefined sense codes
127 /* No sense data available */
128 extern const struct SCSISense sense_code_NO_SENSE
;
129 /* LUN not ready, Manual intervention required */
130 extern const struct SCSISense sense_code_LUN_NOT_READY
;
131 /* LUN not ready, Medium not present */
132 extern const struct SCSISense sense_code_NO_MEDIUM
;
133 /* Hardware error, internal target failure */
134 extern const struct SCSISense sense_code_TARGET_FAILURE
;
135 /* Illegal request, invalid command operation code */
136 extern const struct SCSISense sense_code_INVALID_OPCODE
;
137 /* Illegal request, LBA out of range */
138 extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE
;
139 /* Illegal request, Invalid field in CDB */
140 extern const struct SCSISense sense_code_INVALID_FIELD
;
141 /* Illegal request, LUN not supported */
142 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED
;
143 /* Command aborted, I/O process terminated */
144 extern const struct SCSISense sense_code_IO_ERROR
;
145 /* Command aborted, I_T Nexus loss occurred */
146 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS
;
147 /* Command aborted, Logical Unit failure */
148 extern const struct SCSISense sense_code_LUN_FAILURE
;
150 #define SENSE_CODE(x) sense_code_ ## x
152 int scsi_sense_valid(SCSISense sense
);
154 SCSIRequest
*scsi_req_alloc(SCSIReqOps
*reqops
, SCSIDevice
*d
, uint32_t tag
,
155 uint32_t lun
, void *hba_private
);
156 SCSIRequest
*scsi_req_new(SCSIDevice
*d
, uint32_t tag
, uint32_t lun
,
157 uint8_t *buf
, void *hba_private
);
158 int32_t scsi_req_enqueue(SCSIRequest
*req
);
159 void scsi_req_free(SCSIRequest
*req
);
160 SCSIRequest
*scsi_req_ref(SCSIRequest
*req
);
161 void scsi_req_unref(SCSIRequest
*req
);
163 void scsi_req_build_sense(SCSIRequest
*req
, SCSISense sense
);
164 int scsi_req_parse(SCSIRequest
*req
, uint8_t *buf
);
165 void scsi_req_print(SCSIRequest
*req
);
166 void scsi_req_continue(SCSIRequest
*req
);
167 void scsi_req_data(SCSIRequest
*req
, int len
);
168 void scsi_req_complete(SCSIRequest
*req
, int status
);
169 uint8_t *scsi_req_get_buf(SCSIRequest
*req
);
170 int scsi_req_get_sense(SCSIRequest
*req
, uint8_t *buf
, int len
);
171 void scsi_req_abort(SCSIRequest
*req
, int status
);
172 void scsi_req_cancel(SCSIRequest
*req
);
173 void scsi_device_purge_requests(SCSIDevice
*sdev
);
174 int scsi_device_get_sense(SCSIDevice
*dev
, uint8_t *buf
, int len
, bool fixed
);