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