]>
Commit | Line | Data |
---|---|---|
973abc7f SH |
1 | /* |
2 | * Virtio SCSI HBA | |
3 | * | |
4 | * Copyright IBM, Corp. 2010 | |
5 | * Copyright Red Hat, Inc. 2011 | |
6 | * | |
7 | * Authors: | |
8 | * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | |
9 | * Paolo Bonzini <pbonzini@redhat.com> | |
10 | * | |
11 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
12 | * See the COPYING file in the top-level directory. | |
13 | * | |
14 | */ | |
15 | ||
0d09e41a | 16 | #include "hw/virtio/virtio-scsi.h" |
b4a42f81 | 17 | #include "qemu/error-report.h" |
36b15c79 | 18 | #include "qemu/iov.h" |
0d09e41a PB |
19 | #include <hw/scsi/scsi.h> |
20 | #include <block/scsi.h> | |
21 | #include <hw/virtio/virtio-bus.h> | |
8c085dbe | 22 | #include "hw/virtio/virtio-access.h" |
dfb37cf7 | 23 | #include "migration/migration.h" |
973abc7f | 24 | |
2ccdcd8d PB |
25 | static inline int virtio_scsi_get_lun(uint8_t *lun) |
26 | { | |
27 | return ((lun[2] << 8) | lun[3]) & 0x3FFF; | |
28 | } | |
29 | ||
30 | static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *lun) | |
31 | { | |
32 | if (lun[0] != 1) { | |
33 | return NULL; | |
34 | } | |
35 | if (lun[2] != 0 && !(lun[2] >= 0x40 && lun[2] < 0x80)) { | |
36 | return NULL; | |
37 | } | |
38 | return scsi_device_find(&s->bus, 0, lun[1], virtio_scsi_get_lun(lun)); | |
39 | } | |
40 | ||
c505333d | 41 | VirtIOSCSIReq *virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq) |
36b15c79 PB |
42 | { |
43 | VirtIOSCSIReq *req; | |
faf1e1fb FZ |
44 | VirtIOSCSICommon *vs = (VirtIOSCSICommon *)s; |
45 | const size_t zero_skip = offsetof(VirtIOSCSIReq, elem) | |
46 | + sizeof(VirtQueueElement); | |
36b15c79 | 47 | |
faf1e1fb | 48 | req = g_slice_alloc(sizeof(*req) + vs->cdb_size); |
36b15c79 PB |
49 | req->vq = vq; |
50 | req->dev = s; | |
36b15c79 | 51 | qemu_sglist_init(&req->qsgl, DEVICE(s), 8, &address_space_memory); |
3eff1f46 | 52 | qemu_iovec_init(&req->resp_iov, 1); |
faf1e1fb | 53 | memset((uint8_t *)req + zero_skip, 0, sizeof(*req) - zero_skip); |
36b15c79 PB |
54 | return req; |
55 | } | |
56 | ||
aa8e8f83 | 57 | void virtio_scsi_free_req(VirtIOSCSIReq *req) |
36b15c79 | 58 | { |
faf1e1fb FZ |
59 | VirtIOSCSICommon *vs = (VirtIOSCSICommon *)req->dev; |
60 | ||
3eff1f46 | 61 | qemu_iovec_destroy(&req->resp_iov); |
36b15c79 | 62 | qemu_sglist_destroy(&req->qsgl); |
faf1e1fb | 63 | g_slice_free1(sizeof(*req) + vs->cdb_size, req); |
36b15c79 PB |
64 | } |
65 | ||
326799c0 SH |
66 | static void virtio_scsi_complete_req(VirtIOSCSIReq *req) |
67 | { | |
68 | VirtIOSCSI *s = req->dev; | |
69 | VirtQueue *vq = req->vq; | |
0ac8e139 | 70 | VirtIODevice *vdev = VIRTIO_DEVICE(s); |
3eff1f46 PB |
71 | |
72 | qemu_iovec_from_buf(&req->resp_iov, 0, &req->resp, req->resp_size); | |
63c7e542 FZ |
73 | if (req->vring) { |
74 | assert(req->vq == NULL); | |
75 | virtio_scsi_vring_push_notify(req); | |
76 | } else { | |
77 | virtqueue_push(vq, &req->elem, req->qsgl.size + req->resp_iov.size); | |
78 | virtio_notify(vdev, vq); | |
79 | } | |
80 | ||
326799c0 SH |
81 | if (req->sreq) { |
82 | req->sreq->hba_private = NULL; | |
83 | scsi_req_unref(req->sreq); | |
84 | } | |
36b15c79 | 85 | virtio_scsi_free_req(req); |
326799c0 SH |
86 | } |
87 | ||
88 | static void virtio_scsi_bad_req(void) | |
89 | { | |
90 | error_report("wrong size for virtio-scsi headers"); | |
91 | exit(1); | |
92 | } | |
93 | ||
57fbae6e PB |
94 | static size_t qemu_sgl_concat(VirtIOSCSIReq *req, struct iovec *iov, |
95 | hwaddr *addr, int num, size_t skip) | |
326799c0 | 96 | { |
f487b677 | 97 | QEMUSGList *qsgl = &req->qsgl; |
57fbae6e PB |
98 | size_t copied = 0; |
99 | ||
100 | while (num) { | |
101 | if (skip >= iov->iov_len) { | |
102 | skip -= iov->iov_len; | |
103 | } else { | |
104 | qemu_sglist_add(qsgl, *addr + skip, iov->iov_len - skip); | |
105 | copied += iov->iov_len - skip; | |
106 | skip = 0; | |
107 | } | |
108 | iov++; | |
109 | addr++; | |
110 | num--; | |
326799c0 | 111 | } |
57fbae6e PB |
112 | |
113 | assert(skip == 0); | |
114 | return copied; | |
326799c0 SH |
115 | } |
116 | ||
36b15c79 PB |
117 | static int virtio_scsi_parse_req(VirtIOSCSIReq *req, |
118 | unsigned req_size, unsigned resp_size) | |
326799c0 | 119 | { |
3eff1f46 | 120 | size_t in_size, out_size; |
36b15c79 | 121 | |
3eff1f46 PB |
122 | if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0, |
123 | &req->req, req_size) < req_size) { | |
36b15c79 PB |
124 | return -EINVAL; |
125 | } | |
36b15c79 | 126 | |
3eff1f46 PB |
127 | if (qemu_iovec_concat_iov(&req->resp_iov, |
128 | req->elem.in_sg, req->elem.in_num, 0, | |
129 | resp_size) < resp_size) { | |
36b15c79 PB |
130 | return -EINVAL; |
131 | } | |
489c7901 | 132 | req->resp_size = resp_size; |
326799c0 | 133 | |
3eff1f46 PB |
134 | out_size = qemu_sgl_concat(req, req->elem.out_sg, |
135 | &req->elem.out_addr[0], req->elem.out_num, | |
136 | req_size); | |
137 | in_size = qemu_sgl_concat(req, req->elem.in_sg, | |
138 | &req->elem.in_addr[0], req->elem.in_num, | |
139 | resp_size); | |
140 | ||
141 | if (out_size && in_size) { | |
142 | return -ENOTSUP; | |
143 | } | |
144 | ||
145 | if (out_size) { | |
146 | req->mode = SCSI_XFER_TO_DEV; | |
147 | } else if (in_size) { | |
148 | req->mode = SCSI_XFER_FROM_DEV; | |
326799c0 | 149 | } |
36b15c79 PB |
150 | |
151 | return 0; | |
326799c0 SH |
152 | } |
153 | ||
154 | static VirtIOSCSIReq *virtio_scsi_pop_req(VirtIOSCSI *s, VirtQueue *vq) | |
155 | { | |
36b15c79 | 156 | VirtIOSCSIReq *req = virtio_scsi_init_req(s, vq); |
326799c0 | 157 | if (!virtqueue_pop(vq, &req->elem)) { |
36b15c79 | 158 | virtio_scsi_free_req(req); |
326799c0 SH |
159 | return NULL; |
160 | } | |
326799c0 SH |
161 | return req; |
162 | } | |
163 | ||
5db1764c PB |
164 | static void virtio_scsi_save_request(QEMUFile *f, SCSIRequest *sreq) |
165 | { | |
166 | VirtIOSCSIReq *req = sreq->hba_private; | |
292c8e50 | 167 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(req->dev); |
d2ad7dd4 | 168 | uint32_t n = virtio_queue_get_id(req->vq) - 2; |
5db1764c | 169 | |
292c8e50 | 170 | assert(n < vs->conf.num_queues); |
fcf104a7 | 171 | qemu_put_be32s(f, &n); |
5db1764c PB |
172 | qemu_put_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem)); |
173 | } | |
174 | ||
175 | static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq) | |
176 | { | |
177 | SCSIBus *bus = sreq->bus; | |
178 | VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus); | |
292c8e50 | 179 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); |
5db1764c | 180 | VirtIOSCSIReq *req; |
fcf104a7 | 181 | uint32_t n; |
5db1764c | 182 | |
fcf104a7 | 183 | qemu_get_be32s(f, &n); |
292c8e50 | 184 | assert(n < vs->conf.num_queues); |
36b15c79 | 185 | req = virtio_scsi_init_req(s, vs->cmd_vqs[n]); |
5db1764c | 186 | qemu_get_buffer(f, (unsigned char *)&req->elem, sizeof(req->elem)); |
3c3ce981 MT |
187 | /* TODO: add a way for SCSIBusInfo's load_request to fail, |
188 | * and fail migration instead of asserting here. | |
189 | * When we do, we might be able to re-enable NDEBUG below. | |
190 | */ | |
191 | #ifdef NDEBUG | |
192 | #error building with NDEBUG is not supported | |
193 | #endif | |
194 | assert(req->elem.in_num <= ARRAY_SIZE(req->elem.in_sg)); | |
195 | assert(req->elem.out_num <= ARRAY_SIZE(req->elem.out_sg)); | |
36b15c79 PB |
196 | |
197 | if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size, | |
198 | sizeof(VirtIOSCSICmdResp) + vs->sense_size) < 0) { | |
199 | error_report("invalid SCSI request migration data"); | |
200 | exit(1); | |
201 | } | |
5db1764c PB |
202 | |
203 | scsi_req_ref(sreq); | |
204 | req->sreq = sreq; | |
205 | if (req->sreq->cmd.mode != SCSI_XFER_NONE) { | |
3eff1f46 | 206 | assert(req->sreq->cmd.mode == req->mode); |
5db1764c PB |
207 | } |
208 | return req; | |
209 | } | |
210 | ||
06114d72 | 211 | static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) |
326799c0 | 212 | { |
3eff1f46 | 213 | SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf.lun); |
06114d72 | 214 | SCSIRequest *r, *next; |
0866aca1 | 215 | BusChild *kid; |
06114d72 PB |
216 | int target; |
217 | ||
63c7e542 FZ |
218 | if (s->dataplane_started && bdrv_get_aio_context(d->conf.bs) != s->ctx) { |
219 | aio_context_acquire(s->ctx); | |
220 | bdrv_set_aio_context(d->conf.bs, s->ctx); | |
221 | aio_context_release(s->ctx); | |
222 | } | |
06114d72 | 223 | /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */ |
3eff1f46 | 224 | req->resp.tmf.response = VIRTIO_SCSI_S_OK; |
06114d72 | 225 | |
8c085dbe | 226 | virtio_tswap32s(VIRTIO_DEVICE(s), &req->req.tmf.subtype); |
3eff1f46 | 227 | switch (req->req.tmf.subtype) { |
06114d72 PB |
228 | case VIRTIO_SCSI_T_TMF_ABORT_TASK: |
229 | case VIRTIO_SCSI_T_TMF_QUERY_TASK: | |
230 | if (!d) { | |
231 | goto fail; | |
232 | } | |
3eff1f46 | 233 | if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { |
06114d72 PB |
234 | goto incorrect_lun; |
235 | } | |
236 | QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) { | |
4dd7c82c | 237 | VirtIOSCSIReq *cmd_req = r->hba_private; |
3eff1f46 | 238 | if (cmd_req && cmd_req->req.cmd.tag == req->req.tmf.tag) { |
06114d72 PB |
239 | break; |
240 | } | |
241 | } | |
4dd7c82c PB |
242 | if (r) { |
243 | /* | |
244 | * Assert that the request has not been completed yet, we | |
245 | * check for it in the loop above. | |
246 | */ | |
247 | assert(r->hba_private); | |
3eff1f46 | 248 | if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK) { |
06114d72 PB |
249 | /* "If the specified command is present in the task set, then |
250 | * return a service response set to FUNCTION SUCCEEDED". | |
251 | */ | |
3eff1f46 | 252 | req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; |
06114d72 PB |
253 | } else { |
254 | scsi_req_cancel(r); | |
255 | } | |
256 | } | |
257 | break; | |
258 | ||
259 | case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET: | |
260 | if (!d) { | |
261 | goto fail; | |
262 | } | |
3eff1f46 | 263 | if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { |
06114d72 PB |
264 | goto incorrect_lun; |
265 | } | |
266 | s->resetting++; | |
267 | qdev_reset_all(&d->qdev); | |
268 | s->resetting--; | |
269 | break; | |
270 | ||
271 | case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET: | |
272 | case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET: | |
273 | case VIRTIO_SCSI_T_TMF_QUERY_TASK_SET: | |
274 | if (!d) { | |
275 | goto fail; | |
276 | } | |
3eff1f46 | 277 | if (d->lun != virtio_scsi_get_lun(req->req.tmf.lun)) { |
06114d72 PB |
278 | goto incorrect_lun; |
279 | } | |
280 | QTAILQ_FOREACH_SAFE(r, &d->requests, next, next) { | |
281 | if (r->hba_private) { | |
3eff1f46 | 282 | if (req->req.tmf.subtype == VIRTIO_SCSI_T_TMF_QUERY_TASK_SET) { |
06114d72 PB |
283 | /* "If there is any command present in the task set, then |
284 | * return a service response set to FUNCTION SUCCEEDED". | |
285 | */ | |
3eff1f46 | 286 | req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_SUCCEEDED; |
06114d72 PB |
287 | break; |
288 | } else { | |
289 | scsi_req_cancel(r); | |
290 | } | |
291 | } | |
292 | } | |
293 | break; | |
294 | ||
295 | case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: | |
3eff1f46 | 296 | target = req->req.tmf.lun[1]; |
06114d72 | 297 | s->resetting++; |
0866aca1 AL |
298 | QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) { |
299 | d = DO_UPCAST(SCSIDevice, qdev, kid->child); | |
06114d72 PB |
300 | if (d->channel == 0 && d->id == target) { |
301 | qdev_reset_all(&d->qdev); | |
302 | } | |
303 | } | |
304 | s->resetting--; | |
305 | break; | |
306 | ||
307 | case VIRTIO_SCSI_T_TMF_CLEAR_ACA: | |
308 | default: | |
3eff1f46 | 309 | req->resp.tmf.response = VIRTIO_SCSI_S_FUNCTION_REJECTED; |
06114d72 | 310 | break; |
326799c0 SH |
311 | } |
312 | ||
06114d72 PB |
313 | return; |
314 | ||
315 | incorrect_lun: | |
3eff1f46 | 316 | req->resp.tmf.response = VIRTIO_SCSI_S_INCORRECT_LUN; |
06114d72 PB |
317 | return; |
318 | ||
319 | fail: | |
3eff1f46 | 320 | req->resp.tmf.response = VIRTIO_SCSI_S_BAD_TARGET; |
326799c0 SH |
321 | } |
322 | ||
dc56b7c4 | 323 | void virtio_scsi_handle_ctrl_req(VirtIOSCSI *s, VirtIOSCSIReq *req) |
973abc7f | 324 | { |
dc56b7c4 FZ |
325 | VirtIODevice *vdev = (VirtIODevice *)s; |
326 | int type; | |
326799c0 | 327 | |
dc56b7c4 FZ |
328 | if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0, |
329 | &type, sizeof(type)) < sizeof(type)) { | |
330 | virtio_scsi_bad_req(); | |
331 | return; | |
332 | } | |
36b15c79 | 333 | |
dc56b7c4 FZ |
334 | virtio_tswap32s(vdev, &req->req.tmf.type); |
335 | if (req->req.tmf.type == VIRTIO_SCSI_T_TMF) { | |
336 | if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlTMFReq), | |
337 | sizeof(VirtIOSCSICtrlTMFResp)) < 0) { | |
06114d72 | 338 | virtio_scsi_bad_req(); |
dc56b7c4 FZ |
339 | } else { |
340 | virtio_scsi_do_tmf(s, req); | |
b0b4ea17 | 341 | } |
06114d72 | 342 | |
dc56b7c4 FZ |
343 | } else if (req->req.tmf.type == VIRTIO_SCSI_T_AN_QUERY || |
344 | req->req.tmf.type == VIRTIO_SCSI_T_AN_SUBSCRIBE) { | |
345 | if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlANReq), | |
346 | sizeof(VirtIOSCSICtrlANResp)) < 0) { | |
347 | virtio_scsi_bad_req(); | |
348 | } else { | |
349 | req->resp.an.event_actual = 0; | |
350 | req->resp.an.response = VIRTIO_SCSI_S_OK; | |
06114d72 | 351 | } |
dc56b7c4 FZ |
352 | } |
353 | virtio_scsi_complete_req(req); | |
354 | } | |
355 | ||
356 | static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) | |
357 | { | |
358 | VirtIOSCSI *s = (VirtIOSCSI *)vdev; | |
359 | VirtIOSCSIReq *req; | |
360 | ||
dfb37cf7 | 361 | if (s->ctx && !s->dataplane_disabled) { |
63c7e542 FZ |
362 | virtio_scsi_dataplane_start(s); |
363 | return; | |
364 | } | |
dc56b7c4 FZ |
365 | while ((req = virtio_scsi_pop_req(s, vq))) { |
366 | virtio_scsi_handle_ctrl_req(s, req); | |
326799c0 SH |
367 | } |
368 | } | |
369 | ||
a3de269c PB |
370 | static void virtio_scsi_complete_cmd_req(VirtIOSCSIReq *req) |
371 | { | |
3eff1f46 PB |
372 | /* Sense data is not in req->resp and is copied separately |
373 | * in virtio_scsi_command_complete. | |
374 | */ | |
375 | req->resp_size = sizeof(VirtIOSCSICmdResp); | |
a3de269c PB |
376 | virtio_scsi_complete_req(req); |
377 | } | |
378 | ||
2ccdcd8d PB |
379 | static void virtio_scsi_command_complete(SCSIRequest *r, uint32_t status, |
380 | size_t resid) | |
381 | { | |
382 | VirtIOSCSIReq *req = r->hba_private; | |
489c7901 | 383 | uint8_t sense[SCSI_SENSE_BUF_SIZE]; |
474ee55a | 384 | uint32_t sense_len; |
8c085dbe | 385 | VirtIODevice *vdev = VIRTIO_DEVICE(req->dev); |
2ccdcd8d | 386 | |
e9c0f0f5 EF |
387 | if (r->io_canceled) { |
388 | return; | |
389 | } | |
390 | ||
3eff1f46 PB |
391 | req->resp.cmd.response = VIRTIO_SCSI_S_OK; |
392 | req->resp.cmd.status = status; | |
393 | if (req->resp.cmd.status == GOOD) { | |
8c085dbe | 394 | req->resp.cmd.resid = virtio_tswap32(vdev, resid); |
2ccdcd8d | 395 | } else { |
3eff1f46 | 396 | req->resp.cmd.resid = 0; |
489c7901 | 397 | sense_len = scsi_req_get_sense(r, sense, sizeof(sense)); |
3eff1f46 PB |
398 | sense_len = MIN(sense_len, req->resp_iov.size - sizeof(req->resp.cmd)); |
399 | qemu_iovec_from_buf(&req->resp_iov, sizeof(req->resp.cmd), | |
400 | &req->resp, sense_len); | |
8c085dbe | 401 | req->resp.cmd.sense_len = virtio_tswap32(vdev, sense_len); |
2ccdcd8d | 402 | } |
a3de269c | 403 | virtio_scsi_complete_cmd_req(req); |
2ccdcd8d PB |
404 | } |
405 | ||
33cbb2c5 PB |
406 | static int virtio_scsi_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, |
407 | uint8_t *buf, void *hba_private) | |
408 | { | |
409 | VirtIOSCSIReq *req = hba_private; | |
410 | ||
411 | if (cmd->len == 0) { | |
412 | cmd->len = MIN(VIRTIO_SCSI_CDB_SIZE, SCSI_CMD_BUF_SIZE); | |
413 | memcpy(cmd->buf, buf, cmd->len); | |
414 | } | |
415 | ||
416 | /* Extract the direction and mode directly from the request, for | |
417 | * host device passthrough. | |
418 | */ | |
419 | cmd->xfer = req->qsgl.size; | |
9df7bfdd | 420 | cmd->mode = req->mode; |
33cbb2c5 PB |
421 | return 0; |
422 | } | |
423 | ||
2ccdcd8d PB |
424 | static QEMUSGList *virtio_scsi_get_sg_list(SCSIRequest *r) |
425 | { | |
426 | VirtIOSCSIReq *req = r->hba_private; | |
427 | ||
428 | return &req->qsgl; | |
429 | } | |
430 | ||
431 | static void virtio_scsi_request_cancelled(SCSIRequest *r) | |
432 | { | |
433 | VirtIOSCSIReq *req = r->hba_private; | |
434 | ||
435 | if (!req) { | |
436 | return; | |
437 | } | |
06114d72 | 438 | if (req->dev->resetting) { |
3eff1f46 | 439 | req->resp.cmd.response = VIRTIO_SCSI_S_RESET; |
06114d72 | 440 | } else { |
3eff1f46 | 441 | req->resp.cmd.response = VIRTIO_SCSI_S_ABORTED; |
06114d72 | 442 | } |
a3de269c | 443 | virtio_scsi_complete_cmd_req(req); |
2ccdcd8d PB |
444 | } |
445 | ||
446 | static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *req) | |
326799c0 | 447 | { |
3eff1f46 | 448 | req->resp.cmd.response = VIRTIO_SCSI_S_FAILURE; |
a3de269c | 449 | virtio_scsi_complete_cmd_req(req); |
973abc7f SH |
450 | } |
451 | ||
359eea71 | 452 | bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq *req) |
bf359a44 FZ |
453 | { |
454 | VirtIOSCSICommon *vs = &s->parent_obj; | |
bf359a44 FZ |
455 | SCSIDevice *d; |
456 | int rc; | |
457 | ||
458 | rc = virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_size, | |
459 | sizeof(VirtIOSCSICmdResp) + vs->sense_size); | |
460 | if (rc < 0) { | |
461 | if (rc == -ENOTSUP) { | |
462 | virtio_scsi_fail_cmd_req(req); | |
463 | } else { | |
464 | virtio_scsi_bad_req(); | |
465 | } | |
359eea71 | 466 | return false; |
bf359a44 FZ |
467 | } |
468 | ||
469 | d = virtio_scsi_device_find(s, req->req.cmd.lun); | |
470 | if (!d) { | |
471 | req->resp.cmd.response = VIRTIO_SCSI_S_BAD_TARGET; | |
472 | virtio_scsi_complete_cmd_req(req); | |
359eea71 | 473 | return false; |
bf359a44 | 474 | } |
63c7e542 FZ |
475 | if (s->dataplane_started && bdrv_get_aio_context(d->conf.bs) != s->ctx) { |
476 | aio_context_acquire(s->ctx); | |
477 | bdrv_set_aio_context(d->conf.bs, s->ctx); | |
478 | aio_context_release(s->ctx); | |
479 | } | |
bf359a44 FZ |
480 | req->sreq = scsi_req_new(d, req->req.cmd.tag, |
481 | virtio_scsi_get_lun(req->req.cmd.lun), | |
482 | req->req.cdb, req); | |
483 | ||
484 | if (req->sreq->cmd.mode != SCSI_XFER_NONE | |
485 | && (req->sreq->cmd.mode != req->mode || | |
486 | req->sreq->cmd.xfer > req->qsgl.size)) { | |
487 | req->resp.cmd.response = VIRTIO_SCSI_S_OVERRUN; | |
488 | virtio_scsi_complete_cmd_req(req); | |
359eea71 | 489 | return false; |
bf359a44 | 490 | } |
5170f40b FZ |
491 | scsi_req_ref(req->sreq); |
492 | bdrv_io_plug(d->conf.bs); | |
359eea71 FZ |
493 | return true; |
494 | } | |
bf359a44 | 495 | |
359eea71 FZ |
496 | void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI *s, VirtIOSCSIReq *req) |
497 | { | |
498 | if (scsi_req_enqueue(req->sreq)) { | |
bf359a44 FZ |
499 | scsi_req_continue(req->sreq); |
500 | } | |
5170f40b FZ |
501 | bdrv_io_unplug(req->sreq->dev->conf.bs); |
502 | scsi_req_unref(req->sreq); | |
bf359a44 FZ |
503 | } |
504 | ||
973abc7f SH |
505 | static void virtio_scsi_handle_cmd(VirtIODevice *vdev, VirtQueue *vq) |
506 | { | |
292c8e50 | 507 | /* use non-QOM casts in the data path */ |
326799c0 | 508 | VirtIOSCSI *s = (VirtIOSCSI *)vdev; |
1880ad4f FZ |
509 | VirtIOSCSIReq *req, *next; |
510 | QTAILQ_HEAD(, VirtIOSCSIReq) reqs = QTAILQ_HEAD_INITIALIZER(reqs); | |
326799c0 | 511 | |
dfb37cf7 | 512 | if (s->ctx && !s->dataplane_disabled) { |
63c7e542 FZ |
513 | virtio_scsi_dataplane_start(s); |
514 | return; | |
515 | } | |
326799c0 | 516 | while ((req = virtio_scsi_pop_req(s, vq))) { |
359eea71 | 517 | if (virtio_scsi_handle_cmd_req_prepare(s, req)) { |
1880ad4f | 518 | QTAILQ_INSERT_TAIL(&reqs, req, next); |
359eea71 | 519 | } |
326799c0 | 520 | } |
1880ad4f FZ |
521 | |
522 | QTAILQ_FOREACH_SAFE(req, &reqs, next, next) { | |
523 | virtio_scsi_handle_cmd_req_submit(s, req); | |
524 | } | |
973abc7f SH |
525 | } |
526 | ||
527 | static void virtio_scsi_get_config(VirtIODevice *vdev, | |
528 | uint8_t *config) | |
529 | { | |
530 | VirtIOSCSIConfig *scsiconf = (VirtIOSCSIConfig *)config; | |
292c8e50 | 531 | VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(vdev); |
973abc7f | 532 | |
8c085dbe RR |
533 | virtio_stl_p(vdev, &scsiconf->num_queues, s->conf.num_queues); |
534 | virtio_stl_p(vdev, &scsiconf->seg_max, 128 - 2); | |
535 | virtio_stl_p(vdev, &scsiconf->max_sectors, s->conf.max_sectors); | |
536 | virtio_stl_p(vdev, &scsiconf->cmd_per_lun, s->conf.cmd_per_lun); | |
537 | virtio_stl_p(vdev, &scsiconf->event_info_size, sizeof(VirtIOSCSIEvent)); | |
538 | virtio_stl_p(vdev, &scsiconf->sense_size, s->sense_size); | |
539 | virtio_stl_p(vdev, &scsiconf->cdb_size, s->cdb_size); | |
540 | virtio_stw_p(vdev, &scsiconf->max_channel, VIRTIO_SCSI_MAX_CHANNEL); | |
541 | virtio_stw_p(vdev, &scsiconf->max_target, VIRTIO_SCSI_MAX_TARGET); | |
542 | virtio_stl_p(vdev, &scsiconf->max_lun, VIRTIO_SCSI_MAX_LUN); | |
973abc7f SH |
543 | } |
544 | ||
545 | static void virtio_scsi_set_config(VirtIODevice *vdev, | |
546 | const uint8_t *config) | |
547 | { | |
548 | VirtIOSCSIConfig *scsiconf = (VirtIOSCSIConfig *)config; | |
292c8e50 | 549 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); |
973abc7f | 550 | |
8c085dbe RR |
551 | if ((uint32_t) virtio_ldl_p(vdev, &scsiconf->sense_size) >= 65536 || |
552 | (uint32_t) virtio_ldl_p(vdev, &scsiconf->cdb_size) >= 256) { | |
973abc7f SH |
553 | error_report("bad data written to virtio-scsi configuration space"); |
554 | exit(1); | |
555 | } | |
556 | ||
8c085dbe RR |
557 | vs->sense_size = virtio_ldl_p(vdev, &scsiconf->sense_size); |
558 | vs->cdb_size = virtio_ldl_p(vdev, &scsiconf->cdb_size); | |
973abc7f SH |
559 | } |
560 | ||
561 | static uint32_t virtio_scsi_get_features(VirtIODevice *vdev, | |
562 | uint32_t requested_features) | |
563 | { | |
564 | return requested_features; | |
565 | } | |
566 | ||
567 | static void virtio_scsi_reset(VirtIODevice *vdev) | |
568 | { | |
292c8e50 PB |
569 | VirtIOSCSI *s = VIRTIO_SCSI(vdev); |
570 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); | |
973abc7f | 571 | |
63c7e542 FZ |
572 | if (s->ctx) { |
573 | virtio_scsi_dataplane_stop(s); | |
574 | } | |
47a150a4 PB |
575 | s->resetting++; |
576 | qbus_reset_all(&s->bus.qbus); | |
577 | s->resetting--; | |
578 | ||
292c8e50 PB |
579 | vs->sense_size = VIRTIO_SCSI_SENSE_SIZE; |
580 | vs->cdb_size = VIRTIO_SCSI_CDB_SIZE; | |
2baa1beb | 581 | s->events_dropped = false; |
973abc7f SH |
582 | } |
583 | ||
5db1764c PB |
584 | /* The device does not have anything to save beyond the virtio data. |
585 | * Request data is saved with callbacks from SCSI devices. | |
586 | */ | |
587 | static void virtio_scsi_save(QEMUFile *f, void *opaque) | |
588 | { | |
0ac8e139 FK |
589 | VirtIODevice *vdev = VIRTIO_DEVICE(opaque); |
590 | virtio_save(vdev, f); | |
5db1764c PB |
591 | } |
592 | ||
593 | static int virtio_scsi_load(QEMUFile *f, void *opaque, int version_id) | |
594 | { | |
0ac8e139 | 595 | VirtIODevice *vdev = VIRTIO_DEVICE(opaque); |
2a633c46 OW |
596 | int ret; |
597 | ||
1b5fc0de | 598 | ret = virtio_load(vdev, f, version_id); |
2a633c46 OW |
599 | if (ret) { |
600 | return ret; | |
601 | } | |
5db1764c PB |
602 | return 0; |
603 | } | |
604 | ||
20e6dca1 FZ |
605 | void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, |
606 | uint32_t event, uint32_t reason) | |
b6866fee | 607 | { |
292c8e50 | 608 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s); |
91e7fcca | 609 | VirtIOSCSIReq *req; |
b6866fee | 610 | VirtIOSCSIEvent *evt; |
0ac8e139 | 611 | VirtIODevice *vdev = VIRTIO_DEVICE(s); |
b6866fee | 612 | |
0ac8e139 | 613 | if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)) { |
cd41a671 PB |
614 | return; |
615 | } | |
616 | ||
63c7e542 FZ |
617 | if (s->dataplane_started) { |
618 | assert(s->ctx); | |
619 | aio_context_acquire(s->ctx); | |
620 | } | |
621 | ||
622 | if (s->dataplane_started) { | |
623 | req = virtio_scsi_pop_req_vring(s, s->event_vring); | |
624 | } else { | |
625 | req = virtio_scsi_pop_req(s, vs->event_vq); | |
626 | } | |
64f64855 PB |
627 | if (!req) { |
628 | s->events_dropped = true; | |
63c7e542 | 629 | goto out; |
64f64855 | 630 | } |
b6866fee | 631 | |
64f64855 PB |
632 | if (s->events_dropped) { |
633 | event |= VIRTIO_SCSI_T_EVENTS_MISSED; | |
634 | s->events_dropped = false; | |
635 | } | |
636 | ||
dfecbb95 | 637 | if (virtio_scsi_parse_req(req, 0, sizeof(VirtIOSCSIEvent))) { |
64f64855 PB |
638 | virtio_scsi_bad_req(); |
639 | } | |
640 | ||
3eff1f46 | 641 | evt = &req->resp.event; |
64f64855 | 642 | memset(evt, 0, sizeof(VirtIOSCSIEvent)); |
424baff5 CLG |
643 | evt->event = virtio_tswap32(vdev, event); |
644 | evt->reason = virtio_tswap32(vdev, reason); | |
64f64855 | 645 | if (!dev) { |
49fb65c7 | 646 | assert(event == VIRTIO_SCSI_T_EVENTS_MISSED); |
64f64855 | 647 | } else { |
b6866fee CM |
648 | evt->lun[0] = 1; |
649 | evt->lun[1] = dev->id; | |
650 | ||
651 | /* Linux wants us to keep the same encoding we use for REPORT LUNS. */ | |
652 | if (dev->lun >= 256) { | |
653 | evt->lun[2] = (dev->lun >> 8) | 0x40; | |
654 | } | |
655 | evt->lun[3] = dev->lun & 0xFF; | |
64f64855 PB |
656 | } |
657 | virtio_scsi_complete_req(req); | |
63c7e542 FZ |
658 | out: |
659 | if (s->dataplane_started) { | |
660 | aio_context_release(s->ctx); | |
661 | } | |
64f64855 PB |
662 | } |
663 | ||
664 | static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq) | |
665 | { | |
0ac8e139 | 666 | VirtIOSCSI *s = VIRTIO_SCSI(vdev); |
64f64855 | 667 | |
dfb37cf7 | 668 | if (s->ctx && !s->dataplane_disabled) { |
63c7e542 FZ |
669 | virtio_scsi_dataplane_start(s); |
670 | return; | |
671 | } | |
64f64855 PB |
672 | if (s->events_dropped) { |
673 | virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); | |
b6866fee CM |
674 | } |
675 | } | |
676 | ||
feda01e4 PB |
677 | static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense) |
678 | { | |
679 | VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus); | |
0ac8e139 | 680 | VirtIODevice *vdev = VIRTIO_DEVICE(s); |
feda01e4 | 681 | |
0ac8e139 | 682 | if (((vdev->guest_features >> VIRTIO_SCSI_F_CHANGE) & 1) && |
feda01e4 PB |
683 | dev->type != TYPE_ROM) { |
684 | virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE, | |
685 | sense.asc | (sense.ascq << 8)); | |
686 | } | |
687 | } | |
688 | ||
b6866fee CM |
689 | static void virtio_scsi_hotplug(SCSIBus *bus, SCSIDevice *dev) |
690 | { | |
691 | VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus); | |
0ac8e139 | 692 | VirtIODevice *vdev = VIRTIO_DEVICE(s); |
b6866fee | 693 | |
0ac8e139 | 694 | if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) { |
b6866fee CM |
695 | virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_TRANSPORT_RESET, |
696 | VIRTIO_SCSI_EVT_RESET_RESCAN); | |
697 | } | |
698 | } | |
699 | ||
700 | static void virtio_scsi_hot_unplug(SCSIBus *bus, SCSIDevice *dev) | |
701 | { | |
702 | VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus); | |
0ac8e139 | 703 | VirtIODevice *vdev = VIRTIO_DEVICE(s); |
b6866fee | 704 | |
0ac8e139 | 705 | if ((vdev->guest_features >> VIRTIO_SCSI_F_HOTPLUG) & 1) { |
b6866fee CM |
706 | virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_TRANSPORT_RESET, |
707 | VIRTIO_SCSI_EVT_RESET_REMOVED); | |
708 | } | |
709 | } | |
710 | ||
2ccdcd8d PB |
711 | static struct SCSIBusInfo virtio_scsi_scsi_info = { |
712 | .tcq = true, | |
713 | .max_channel = VIRTIO_SCSI_MAX_CHANNEL, | |
714 | .max_target = VIRTIO_SCSI_MAX_TARGET, | |
715 | .max_lun = VIRTIO_SCSI_MAX_LUN, | |
716 | ||
717 | .complete = virtio_scsi_command_complete, | |
718 | .cancel = virtio_scsi_request_cancelled, | |
feda01e4 | 719 | .change = virtio_scsi_change, |
b6866fee CM |
720 | .hotplug = virtio_scsi_hotplug, |
721 | .hot_unplug = virtio_scsi_hot_unplug, | |
33cbb2c5 | 722 | .parse_cdb = virtio_scsi_parse_cdb, |
2ccdcd8d | 723 | .get_sg_list = virtio_scsi_get_sg_list, |
5db1764c PB |
724 | .save_request = virtio_scsi_save_request, |
725 | .load_request = virtio_scsi_load_request, | |
2ccdcd8d PB |
726 | }; |
727 | ||
91d670fb ML |
728 | void virtio_scsi_common_realize(DeviceState *dev, Error **errp, |
729 | HandleOutput ctrl, HandleOutput evt, | |
730 | HandleOutput cmd) | |
973abc7f | 731 | { |
71a6520b AF |
732 | VirtIODevice *vdev = VIRTIO_DEVICE(dev); |
733 | VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(dev); | |
d2ad7dd4 | 734 | int i; |
973abc7f | 735 | |
7598f0f3 | 736 | virtio_init(vdev, "virtio-scsi", VIRTIO_ID_SCSI, |
763684be | 737 | sizeof(VirtIOSCSIConfig)); |
3ab1dfdd | 738 | |
c9f65528 FZ |
739 | if (s->conf.num_queues <= 0 || s->conf.num_queues > VIRTIO_PCI_QUEUE_MAX) { |
740 | error_setg(errp, "Invalid number of queues (= %" PRId32 "), " | |
741 | "must be a positive integer less than %d.", | |
742 | s->conf.num_queues, VIRTIO_PCI_QUEUE_MAX); | |
743 | return; | |
744 | } | |
763684be | 745 | s->cmd_vqs = g_malloc0(s->conf.num_queues * sizeof(VirtQueue *)); |
292c8e50 PB |
746 | s->sense_size = VIRTIO_SCSI_SENSE_SIZE; |
747 | s->cdb_size = VIRTIO_SCSI_CDB_SIZE; | |
3ab1dfdd | 748 | |
0ac8e139 | 749 | s->ctrl_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, |
91d670fb | 750 | ctrl); |
0ac8e139 | 751 | s->event_vq = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, |
91d670fb | 752 | evt); |
394e2e4c | 753 | for (i = 0; i < s->conf.num_queues; i++) { |
0ac8e139 | 754 | s->cmd_vqs[i] = virtio_add_queue(vdev, VIRTIO_SCSI_VQ_SIZE, |
91d670fb | 755 | cmd); |
d2ad7dd4 | 756 | } |
9786b592 FZ |
757 | |
758 | if (s->conf.iothread) { | |
759 | virtio_scsi_set_iothread(VIRTIO_SCSI(s), s->conf.iothread); | |
760 | } | |
292c8e50 PB |
761 | } |
762 | ||
dfb37cf7 FZ |
763 | /* Disable dataplane thread during live migration since it does not |
764 | * update the dirty memory bitmap yet. | |
765 | */ | |
766 | static void virtio_scsi_migration_state_changed(Notifier *notifier, void *data) | |
767 | { | |
768 | VirtIOSCSI *s = container_of(notifier, VirtIOSCSI, | |
769 | migration_state_notifier); | |
770 | MigrationState *mig = data; | |
771 | ||
772 | if (migration_in_setup(mig)) { | |
773 | if (!s->dataplane_started) { | |
774 | return; | |
775 | } | |
776 | virtio_scsi_dataplane_stop(s); | |
777 | s->dataplane_disabled = true; | |
778 | } else if (migration_has_finished(mig) || | |
779 | migration_has_failed(mig)) { | |
780 | if (s->dataplane_started) { | |
781 | return; | |
782 | } | |
783 | bdrv_drain_all(); /* complete in-flight non-dataplane requests */ | |
784 | s->dataplane_disabled = false; | |
785 | } | |
786 | } | |
787 | ||
71a6520b | 788 | static void virtio_scsi_device_realize(DeviceState *dev, Error **errp) |
292c8e50 | 789 | { |
71a6520b | 790 | VirtIODevice *vdev = VIRTIO_DEVICE(dev); |
7598f0f3 | 791 | VirtIOSCSI *s = VIRTIO_SCSI(dev); |
292c8e50 | 792 | static int virtio_scsi_id; |
caad4eb3 | 793 | Error *err = NULL; |
292c8e50 | 794 | |
91d670fb ML |
795 | virtio_scsi_common_realize(dev, &err, virtio_scsi_handle_ctrl, |
796 | virtio_scsi_handle_event, | |
797 | virtio_scsi_handle_cmd); | |
71a6520b AF |
798 | if (err != NULL) { |
799 | error_propagate(errp, err); | |
800 | return; | |
292c8e50 PB |
801 | } |
802 | ||
7598f0f3 | 803 | scsi_bus_new(&s->bus, sizeof(s->bus), dev, |
b1187b51 | 804 | &virtio_scsi_scsi_info, vdev->bus_name); |
6f32a6b4 | 805 | |
7598f0f3 | 806 | if (!dev->hotplugged) { |
caad4eb3 AF |
807 | scsi_bus_legacy_handle_cmdline(&s->bus, &err); |
808 | if (err != NULL) { | |
71a6520b AF |
809 | error_propagate(errp, err); |
810 | return; | |
caad4eb3 | 811 | } |
2ccdcd8d PB |
812 | } |
813 | ||
7598f0f3 | 814 | register_savevm(dev, "virtio-scsi", virtio_scsi_id++, 1, |
5db1764c | 815 | virtio_scsi_save, virtio_scsi_load, s); |
dfb37cf7 FZ |
816 | s->migration_state_notifier.notify = virtio_scsi_migration_state_changed; |
817 | add_migration_state_change_notifier(&s->migration_state_notifier); | |
3ab1dfdd FK |
818 | } |
819 | ||
19d339f1 FZ |
820 | static void virtio_scsi_instance_init(Object *obj) |
821 | { | |
822 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(obj); | |
823 | ||
824 | object_property_add_link(obj, "iothread", TYPE_IOTHREAD, | |
825 | (Object **)&vs->conf.iothread, | |
826 | qdev_prop_allow_set_link_before_realize, | |
827 | OBJ_PROP_LINK_UNREF_ON_RELEASE, &error_abort); | |
828 | } | |
829 | ||
306ec6c3 | 830 | void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp) |
292c8e50 | 831 | { |
306ec6c3 AF |
832 | VirtIODevice *vdev = VIRTIO_DEVICE(dev); |
833 | VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(dev); | |
292c8e50 PB |
834 | |
835 | g_free(vs->cmd_vqs); | |
6a1a8cc7 | 836 | virtio_cleanup(vdev); |
292c8e50 PB |
837 | } |
838 | ||
306ec6c3 | 839 | static void virtio_scsi_device_unrealize(DeviceState *dev, Error **errp) |
3ab1dfdd | 840 | { |
306ec6c3 AF |
841 | VirtIOSCSI *s = VIRTIO_SCSI(dev); |
842 | ||
843 | unregister_savevm(dev, "virtio-scsi", s); | |
dfb37cf7 | 844 | remove_migration_state_change_notifier(&s->migration_state_notifier); |
3ab1dfdd | 845 | |
306ec6c3 | 846 | virtio_scsi_common_unrealize(dev, errp); |
3ab1dfdd FK |
847 | } |
848 | ||
849 | static Property virtio_scsi_properties[] = { | |
292c8e50 | 850 | DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOSCSI, parent_obj.conf), |
3ab1dfdd FK |
851 | DEFINE_PROP_END_OF_LIST(), |
852 | }; | |
853 | ||
292c8e50 PB |
854 | static void virtio_scsi_common_class_init(ObjectClass *klass, void *data) |
855 | { | |
856 | VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); | |
125ee0ed | 857 | DeviceClass *dc = DEVICE_CLASS(klass); |
292c8e50 PB |
858 | |
859 | vdc->get_config = virtio_scsi_get_config; | |
125ee0ed | 860 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); |
292c8e50 PB |
861 | } |
862 | ||
3ab1dfdd FK |
863 | static void virtio_scsi_class_init(ObjectClass *klass, void *data) |
864 | { | |
865 | DeviceClass *dc = DEVICE_CLASS(klass); | |
866 | VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); | |
71a6520b | 867 | |
3ab1dfdd | 868 | dc->props = virtio_scsi_properties; |
125ee0ed | 869 | set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); |
71a6520b | 870 | vdc->realize = virtio_scsi_device_realize; |
306ec6c3 | 871 | vdc->unrealize = virtio_scsi_device_unrealize; |
3ab1dfdd FK |
872 | vdc->set_config = virtio_scsi_set_config; |
873 | vdc->get_features = virtio_scsi_get_features; | |
874 | vdc->reset = virtio_scsi_reset; | |
875 | } | |
876 | ||
292c8e50 PB |
877 | static const TypeInfo virtio_scsi_common_info = { |
878 | .name = TYPE_VIRTIO_SCSI_COMMON, | |
879 | .parent = TYPE_VIRTIO_DEVICE, | |
880 | .instance_size = sizeof(VirtIOSCSICommon), | |
a27292b5 | 881 | .abstract = true, |
292c8e50 PB |
882 | .class_init = virtio_scsi_common_class_init, |
883 | }; | |
884 | ||
3ab1dfdd FK |
885 | static const TypeInfo virtio_scsi_info = { |
886 | .name = TYPE_VIRTIO_SCSI, | |
292c8e50 | 887 | .parent = TYPE_VIRTIO_SCSI_COMMON, |
3ab1dfdd | 888 | .instance_size = sizeof(VirtIOSCSI), |
19d339f1 | 889 | .instance_init = virtio_scsi_instance_init, |
3ab1dfdd FK |
890 | .class_init = virtio_scsi_class_init, |
891 | }; | |
892 | ||
893 | static void virtio_register_types(void) | |
894 | { | |
292c8e50 | 895 | type_register_static(&virtio_scsi_common_info); |
3ab1dfdd FK |
896 | type_register_static(&virtio_scsi_info); |
897 | } | |
898 | ||
899 | type_init(virtio_register_types) |