usb-ehci: Use PCI DMA stub functions
[qemu.git] / hw / scsi.h
blobff8fdd09625e45d4e4b9ab5eb5ce8a0ef56e6231
1 #ifndef QEMU_HW_SCSI_H
2 #define QEMU_HW_SCSI_H
4 #include "qdev.h"
5 #include "block.h"
6 #include "sysemu.h"
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;
20 enum SCSIXferMode {
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 {
27 uint8_t key;
28 uint8_t asc;
29 uint8_t ascq;
30 } SCSISense;
32 #define SCSI_SENSE_BUF_SIZE 96
34 struct SCSICommand {
35 uint8_t buf[SCSI_CMD_BUF_SIZE];
36 int len;
37 size_t xfer;
38 uint64_t lba;
39 enum SCSIXferMode mode;
42 struct SCSIRequest {
43 SCSIBus *bus;
44 SCSIDevice *dev;
45 const SCSIReqOps *ops;
46 uint32_t refcount;
47 uint32_t tag;
48 uint32_t lun;
49 uint32_t status;
50 SCSICommand cmd;
51 BlockDriverAIOCB *aiocb;
52 uint8_t sense[SCSI_SENSE_BUF_SIZE];
53 uint32_t sense_len;
54 bool enqueued;
55 bool io_canceled;
56 bool retry;
57 void *hba_private;
58 QTAILQ_ENTRY(SCSIRequest) next;
61 struct SCSIDevice
63 DeviceState qdev;
64 VMChangeStateEntry *vmsentry;
65 QEMUBH *bh;
66 uint32_t id;
67 BlockConf conf;
68 SCSIDeviceInfo *info;
69 SCSISense unit_attention;
70 bool sense_is_ua;
71 uint8_t sense[SCSI_SENSE_BUF_SIZE];
72 uint32_t sense_len;
73 QTAILQ_HEAD(, SCSIRequest) requests;
74 uint32_t channel;
75 uint32_t lun;
76 int blocksize;
77 int type;
78 uint64_t max_lba;
81 /* cdrom.c */
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);
85 /* scsi-bus.c */
86 struct SCSIReqOps {
87 size_t size;
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 {
98 DeviceInfo qdev;
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);
106 struct SCSIBusInfo {
107 int tcq;
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);
114 struct SCSIBus {
115 BusState qbus;
116 int busnr;
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);
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);
183 SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d,
184 uint32_t tag, uint32_t lun, void *hba_private);
185 SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
186 uint8_t *buf, void *hba_private);
187 int32_t scsi_req_enqueue(SCSIRequest *req);
188 void scsi_req_free(SCSIRequest *req);
189 SCSIRequest *scsi_req_ref(SCSIRequest *req);
190 void scsi_req_unref(SCSIRequest *req);
192 void scsi_req_build_sense(SCSIRequest *req, SCSISense sense);
193 void scsi_req_print(SCSIRequest *req);
194 void scsi_req_continue(SCSIRequest *req);
195 void scsi_req_data(SCSIRequest *req, int len);
196 void scsi_req_complete(SCSIRequest *req, int status);
197 uint8_t *scsi_req_get_buf(SCSIRequest *req);
198 int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len);
199 void scsi_req_abort(SCSIRequest *req, int status);
200 void scsi_req_cancel(SCSIRequest *req);
201 void scsi_req_retry(SCSIRequest *req);
202 void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
203 int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
204 SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun);
206 /* scsi-generic.c. */
207 extern const SCSIReqOps scsi_generic_req_ops;
209 #endif