]>
Commit | Line | Data |
---|---|---|
1e37607b GH |
1 | #ifndef QEMU_HW_SCSI_H |
2 | #define QEMU_HW_SCSI_H | |
43b443b6 | 3 | |
83c9f4ca | 4 | #include "hw/qdev.h" |
db725815 | 5 | #include "block/aio.h" |
0d09e41a | 6 | #include "hw/block/block.h" |
9c17d615 | 7 | #include "sysemu/sysemu.h" |
e5b5728c | 8 | #include "scsi/utils.h" |
8e0a9320 | 9 | #include "qemu/notify.h" |
43b443b6 | 10 | |
27d6bf40 MA |
11 | #define MAX_SCSI_DEVS 255 |
12 | ||
43b443b6 | 13 | typedef struct SCSIBus SCSIBus; |
afd4030c | 14 | typedef struct SCSIBusInfo SCSIBusInfo; |
43b443b6 | 15 | typedef struct SCSIDevice SCSIDevice; |
5c6c0e51 | 16 | typedef struct SCSIRequest SCSIRequest; |
8dbd4574 | 17 | typedef struct SCSIReqOps SCSIReqOps; |
43b443b6 | 18 | |
2e323f03 | 19 | #define SCSI_SENSE_BUF_SIZE_OLD 96 |
c5f52875 | 20 | #define SCSI_SENSE_BUF_SIZE 252 |
b45ef674 | 21 | |
5c6c0e51 | 22 | struct SCSIRequest { |
4c41d2ef GH |
23 | SCSIBus *bus; |
24 | SCSIDevice *dev; | |
adcf2754 | 25 | const SCSIReqOps *ops; |
ad2d30f7 | 26 | uint32_t refcount; |
4c41d2ef | 27 | uint32_t tag; |
89b08ae1 | 28 | uint32_t lun; |
ed3a34a3 | 29 | uint32_t status; |
61e68b3f | 30 | void *hba_private; |
01e95455 | 31 | size_t resid; |
2599aece | 32 | SCSICommand cmd; |
8e0a9320 | 33 | NotifierList cancel_notifiers; |
61e68b3f FZ |
34 | |
35 | /* Note: | |
36 | * - fields before sense are initialized by scsi_req_alloc; | |
37 | * - sense[] is uninitialized; | |
38 | * - fields after sense are memset to 0 by scsi_req_alloc. | |
39 | * */ | |
40 | ||
41 | uint8_t sense[SCSI_SENSE_BUF_SIZE]; | |
42 | uint32_t sense_len; | |
43 | bool enqueued; | |
44 | bool io_canceled; | |
45 | bool retry; | |
46 | bool dma_started; | |
7c84b1b8 | 47 | BlockAIOCB *aiocb; |
3d5aba97 | 48 | QEMUSGList *sg; |
9af99d98 | 49 | QTAILQ_ENTRY(SCSIRequest) next; |
5c6c0e51 | 50 | }; |
4c41d2ef | 51 | |
b9eea3e6 AL |
52 | #define TYPE_SCSI_DEVICE "scsi-device" |
53 | #define SCSI_DEVICE(obj) \ | |
54 | OBJECT_CHECK(SCSIDevice, (obj), TYPE_SCSI_DEVICE) | |
55 | #define SCSI_DEVICE_CLASS(klass) \ | |
56 | OBJECT_CLASS_CHECK(SCSIDeviceClass, (klass), TYPE_SCSI_DEVICE) | |
57 | #define SCSI_DEVICE_GET_CLASS(obj) \ | |
58 | OBJECT_GET_CLASS(SCSIDeviceClass, (obj), TYPE_SCSI_DEVICE) | |
59 | ||
60 | typedef struct SCSIDeviceClass { | |
61 | DeviceClass parent_class; | |
a818a4b6 | 62 | void (*realize)(SCSIDevice *dev, Error **errp); |
ff34c32c PB |
63 | int (*parse_cdb)(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf, |
64 | void *hba_private); | |
b9eea3e6 AL |
65 | SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun, |
66 | uint8_t *buf, void *hba_private); | |
67 | void (*unit_attention_reported)(SCSIDevice *s); | |
68 | } SCSIDeviceClass; | |
69 | ||
43b443b6 GH |
70 | struct SCSIDevice |
71 | { | |
72 | DeviceState qdev; | |
71544d30 PB |
73 | VMChangeStateEntry *vmsentry; |
74 | QEMUBH *bh; | |
43b443b6 | 75 | uint32_t id; |
428c149b | 76 | BlockConf conf; |
6dc06f08 | 77 | SCSISense unit_attention; |
3653d8c4 | 78 | bool sense_is_ua; |
b45ef674 PB |
79 | uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
80 | uint32_t sense_len; | |
9af99d98 | 81 | QTAILQ_HEAD(, SCSIRequest) requests; |
0d3545e7 | 82 | uint32_t channel; |
87dcd1b2 | 83 | uint32_t lun; |
b07995e3 | 84 | int blocksize; |
91376656 | 85 | int type; |
7877903a | 86 | uint64_t max_lba; |
2ecab408 PB |
87 | uint64_t wwn; |
88 | uint64_t port_wwn; | |
2343be0d PB |
89 | int scsi_version; |
90 | int default_scsi_version; | |
a71c775b | 91 | bool needs_vpd_bl_emulation; |
4f71fb43 | 92 | bool hba_supports_iothread; |
43b443b6 GH |
93 | }; |
94 | ||
63f740dd PB |
95 | extern const VMStateDescription vmstate_scsi_device; |
96 | ||
97 | #define VMSTATE_SCSI_DEVICE(_field, _state) { \ | |
98 | .name = (stringify(_field)), \ | |
99 | .size = sizeof(SCSIDevice), \ | |
100 | .vmsd = &vmstate_scsi_device, \ | |
101 | .flags = VMS_STRUCT, \ | |
102 | .offset = vmstate_offset_value(_state, _field, SCSIDevice), \ | |
103 | } | |
104 | ||
43b443b6 GH |
105 | /* cdrom.c */ |
106 | int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int start_track); | |
107 | int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, int session_num); | |
108 | ||
109 | /* scsi-bus.c */ | |
8dbd4574 PB |
110 | struct SCSIReqOps { |
111 | size_t size; | |
12010e7b PB |
112 | void (*free_req)(SCSIRequest *req); |
113 | int32_t (*send_command)(SCSIRequest *req, uint8_t *buf); | |
114 | void (*read_data)(SCSIRequest *req); | |
115 | void (*write_data)(SCSIRequest *req); | |
12010e7b | 116 | uint8_t *(*get_buf)(SCSIRequest *req); |
63f740dd PB |
117 | |
118 | void (*save_request)(QEMUFile *f, SCSIRequest *req); | |
119 | void (*load_request)(QEMUFile *f, SCSIRequest *req); | |
8dbd4574 PB |
120 | }; |
121 | ||
afd4030c | 122 | struct SCSIBusInfo { |
7e0380b9 | 123 | int tcq; |
0d3545e7 | 124 | int max_channel, max_target, max_lun; |
ff34c32c PB |
125 | int (*parse_cdb)(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf, |
126 | void *hba_private); | |
c6df7102 | 127 | void (*transfer_data)(SCSIRequest *req, uint32_t arg); |
01e95455 | 128 | void (*complete)(SCSIRequest *req, uint32_t arg, size_t resid); |
94d3f98a | 129 | void (*cancel)(SCSIRequest *req); |
53200fad | 130 | void (*change)(SCSIBus *bus, SCSIDevice *dev, SCSISense sense); |
3d5aba97 | 131 | QEMUSGList *(*get_sg_list)(SCSIRequest *req); |
63f740dd PB |
132 | |
133 | void (*save_request)(QEMUFile *f, SCSIRequest *req); | |
134 | void *(*load_request)(QEMUFile *f, SCSIRequest *req); | |
8e86b93c | 135 | void (*free_request)(SCSIBus *bus, void *priv); |
cfdc1bb0 PB |
136 | }; |
137 | ||
0d936928 AL |
138 | #define TYPE_SCSI_BUS "SCSI" |
139 | #define SCSI_BUS(obj) OBJECT_CHECK(SCSIBus, (obj), TYPE_SCSI_BUS) | |
140 | ||
43b443b6 GH |
141 | struct SCSIBus { |
142 | BusState qbus; | |
143 | int busnr; | |
144 | ||
6dc06f08 | 145 | SCSISense unit_attention; |
afd4030c | 146 | const SCSIBusInfo *info; |
43b443b6 GH |
147 | }; |
148 | ||
b1187b51 AF |
149 | void scsi_bus_new(SCSIBus *bus, size_t bus_size, DeviceState *host, |
150 | const SCSIBusInfo *info, const char *bus_name); | |
43b443b6 GH |
151 | |
152 | static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) | |
153 | { | |
154 | return DO_UPCAST(SCSIBus, qbus, d->qdev.parent_bus); | |
155 | } | |
156 | ||
4be74634 | 157 | SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, |
76534da7 | 158 | int unit, bool removable, int bootindex, |
395b9539 | 159 | bool share_rw, |
b8efb36b KW |
160 | BlockdevOnError rerror, |
161 | BlockdevOnError werror, | |
caad4eb3 | 162 | const char *serial, Error **errp); |
14545097 | 163 | void scsi_bus_legacy_handle_cmdline(SCSIBus *bus); |
fb8b660e | 164 | void scsi_legacy_handle_cmdline(void); |
43b443b6 | 165 | |
adcf2754 PB |
166 | SCSIRequest *scsi_req_alloc(const SCSIReqOps *reqops, SCSIDevice *d, |
167 | uint32_t tag, uint32_t lun, void *hba_private); | |
c5bf71a9 | 168 | SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, |
c39ce112 PB |
169 | uint8_t *buf, void *hba_private); |
170 | int32_t scsi_req_enqueue(SCSIRequest *req); | |
ad2d30f7 PB |
171 | SCSIRequest *scsi_req_ref(SCSIRequest *req); |
172 | void scsi_req_unref(SCSIRequest *req); | |
37659e51 | 173 | |
ff34c32c PB |
174 | int scsi_bus_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf, |
175 | void *hba_private); | |
3e7e180a | 176 | int scsi_req_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf); |
b45ef674 | 177 | void scsi_req_build_sense(SCSIRequest *req, SCSISense sense); |
ec766865 | 178 | void scsi_req_print(SCSIRequest *req); |
ad3376cc | 179 | void scsi_req_continue(SCSIRequest *req); |
ab9adc88 | 180 | void scsi_req_data(SCSIRequest *req, int len); |
682a9b21 | 181 | void scsi_req_complete(SCSIRequest *req, int status); |
0c34459b | 182 | uint8_t *scsi_req_get_buf(SCSIRequest *req); |
74382217 | 183 | int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len); |
d5776465 | 184 | void scsi_req_cancel_complete(SCSIRequest *req); |
94d3f98a | 185 | void scsi_req_cancel(SCSIRequest *req); |
8e0a9320 | 186 | void scsi_req_cancel_async(SCSIRequest *req, Notifier *notifier); |
71544d30 | 187 | void scsi_req_retry(SCSIRequest *req); |
c7b48872 | 188 | void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense); |
e48e84ea | 189 | void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense); |
53200fad | 190 | void scsi_device_report_change(SCSIDevice *dev, SCSISense sense); |
8d72db68 | 191 | void scsi_device_unit_attention_reported(SCSIDevice *dev); |
a71c775b | 192 | void scsi_generic_read_device_inquiry(SCSIDevice *dev); |
b45ef674 | 193 | int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed); |
a0c7e35b DHB |
194 | int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size, |
195 | uint8_t *buf, uint8_t buf_size); | |
0d3545e7 | 196 | SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun); |
89b08ae1 | 197 | |
765d1525 PB |
198 | /* scsi-generic.c. */ |
199 | extern const SCSIReqOps scsi_generic_req_ops; | |
200 | ||
43b443b6 | 201 | #endif |