4 * Copyright IBM, Corp. 2010
5 * Copyright Red Hat, Inc. 2011
8 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
9 * Paolo Bonzini <pbonzini@redhat.com>
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.
16 #include "virtio-scsi.h"
18 #include <hw/scsi-defs.h>
20 #define VIRTIO_SCSI_VQ_SIZE 128
21 #define VIRTIO_SCSI_CDB_SIZE 32
22 #define VIRTIO_SCSI_SENSE_SIZE 96
23 #define VIRTIO_SCSI_MAX_CHANNEL 0
24 #define VIRTIO_SCSI_MAX_TARGET 255
25 #define VIRTIO_SCSI_MAX_LUN 16383
28 #define VIRTIO_SCSI_F_INOUT 0
29 #define VIRTIO_SCSI_F_HOTPLUG 1
32 #define VIRTIO_SCSI_S_OK 0
33 #define VIRTIO_SCSI_S_OVERRUN 1
34 #define VIRTIO_SCSI_S_ABORTED 2
35 #define VIRTIO_SCSI_S_BAD_TARGET 3
36 #define VIRTIO_SCSI_S_RESET 4
37 #define VIRTIO_SCSI_S_BUSY 5
38 #define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
39 #define VIRTIO_SCSI_S_TARGET_FAILURE 7
40 #define VIRTIO_SCSI_S_NEXUS_FAILURE 8
41 #define VIRTIO_SCSI_S_FAILURE 9
42 #define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
43 #define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
44 #define VIRTIO_SCSI_S_INCORRECT_LUN 12
46 /* Controlq type codes. */
47 #define VIRTIO_SCSI_T_TMF 0
48 #define VIRTIO_SCSI_T_AN_QUERY 1
49 #define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
51 /* Valid TMF subtypes. */
52 #define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
53 #define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
54 #define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
55 #define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
56 #define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
57 #define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
58 #define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
59 #define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
62 #define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
63 #define VIRTIO_SCSI_T_NO_EVENT 0
64 #define VIRTIO_SCSI_T_TRANSPORT_RESET 1
65 #define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
67 /* Reasons for transport reset event */
68 #define VIRTIO_SCSI_EVT_RESET_HARD 0
69 #define VIRTIO_SCSI_EVT_RESET_RESCAN 1
70 #define VIRTIO_SCSI_EVT_RESET_REMOVED 2
72 /* SCSI command request, followed by data-out */
74 uint8_t lun
[8]; /* Logical Unit Number */
75 uint64_t tag
; /* Command identifier */
76 uint8_t task_attr
; /* Task attribute */
80 } QEMU_PACKED VirtIOSCSICmdReq
;
82 /* Response, followed by sense data and data-in */
84 uint32_t sense_len
; /* Sense data length */
85 uint32_t resid
; /* Residual bytes in data buffer */
86 uint16_t status_qualifier
; /* Status qualifier */
87 uint8_t status
; /* Command completion status */
88 uint8_t response
; /* Response values */
90 } QEMU_PACKED VirtIOSCSICmdResp
;
92 /* Task Management Request */
98 } QEMU_PACKED VirtIOSCSICtrlTMFReq
;
102 } QEMU_PACKED VirtIOSCSICtrlTMFResp
;
104 /* Asynchronous notification query/subscription */
108 uint32_t event_requested
;
109 } QEMU_PACKED VirtIOSCSICtrlANReq
;
112 uint32_t event_actual
;
114 } QEMU_PACKED VirtIOSCSICtrlANResp
;
120 } QEMU_PACKED VirtIOSCSIEvent
;
125 uint32_t max_sectors
;
126 uint32_t cmd_per_lun
;
127 uint32_t event_info_size
;
130 uint16_t max_channel
;
133 } QEMU_PACKED VirtIOSCSIConfig
;
138 VirtIOSCSIConf
*conf
;
147 VirtQueue
*cmd_vqs
[0];
150 typedef struct VirtIOSCSIReq
{
153 VirtQueueElement elem
;
158 VirtIOSCSICmdReq
*cmd
;
159 VirtIOSCSICtrlTMFReq
*tmf
;
160 VirtIOSCSICtrlANReq
*an
;
164 VirtIOSCSICmdResp
*cmd
;
165 VirtIOSCSICtrlTMFResp
*tmf
;
166 VirtIOSCSICtrlANResp
*an
;
167 VirtIOSCSIEvent
*event
;
171 static inline int virtio_scsi_get_lun(uint8_t *lun
)
173 return ((lun
[2] << 8) | lun
[3]) & 0x3FFF;
176 static inline SCSIDevice
*virtio_scsi_device_find(VirtIOSCSI
*s
, uint8_t *lun
)
181 if (lun
[2] != 0 && !(lun
[2] >= 0x40 && lun
[2] < 0x80)) {
184 return scsi_device_find(&s
->bus
, 0, lun
[1], virtio_scsi_get_lun(lun
));
187 static void virtio_scsi_complete_req(VirtIOSCSIReq
*req
)
189 VirtIOSCSI
*s
= req
->dev
;
190 VirtQueue
*vq
= req
->vq
;
191 virtqueue_push(vq
, &req
->elem
, req
->qsgl
.size
+ req
->elem
.in_sg
[0].iov_len
);
192 qemu_sglist_destroy(&req
->qsgl
);
194 req
->sreq
->hba_private
= NULL
;
195 scsi_req_unref(req
->sreq
);
198 virtio_notify(&s
->vdev
, vq
);
201 static void virtio_scsi_bad_req(void)
203 error_report("wrong size for virtio-scsi headers");
207 static void qemu_sgl_init_external(QEMUSGList
*qsgl
, struct iovec
*sg
,
208 target_phys_addr_t
*addr
, int num
)
210 memset(qsgl
, 0, sizeof(*qsgl
));
212 qemu_sglist_add(qsgl
, *(addr
++), (sg
++)->iov_len
);
216 static void virtio_scsi_parse_req(VirtIOSCSI
*s
, VirtQueue
*vq
,
219 assert(req
->elem
.in_num
);
223 if (req
->elem
.out_num
) {
224 req
->req
.buf
= req
->elem
.out_sg
[0].iov_base
;
226 req
->resp
.buf
= req
->elem
.in_sg
[0].iov_base
;
228 if (req
->elem
.out_num
> 1) {
229 qemu_sgl_init_external(&req
->qsgl
, &req
->elem
.out_sg
[1],
230 &req
->elem
.out_addr
[1],
231 req
->elem
.out_num
- 1);
233 qemu_sgl_init_external(&req
->qsgl
, &req
->elem
.in_sg
[1],
234 &req
->elem
.in_addr
[1],
235 req
->elem
.in_num
- 1);
239 static VirtIOSCSIReq
*virtio_scsi_pop_req(VirtIOSCSI
*s
, VirtQueue
*vq
)
242 req
= g_malloc(sizeof(*req
));
243 if (!virtqueue_pop(vq
, &req
->elem
)) {
248 virtio_scsi_parse_req(s
, vq
, req
);
252 static void virtio_scsi_save_request(QEMUFile
*f
, SCSIRequest
*sreq
)
254 VirtIOSCSIReq
*req
= sreq
->hba_private
;
255 uint32_t n
= virtio_queue_get_id(req
->vq
) - 2;
257 assert(n
< req
->dev
->conf
->num_queues
);
258 qemu_put_be32s(f
, &n
);
259 qemu_put_buffer(f
, (unsigned char *)&req
->elem
, sizeof(req
->elem
));
262 static void *virtio_scsi_load_request(QEMUFile
*f
, SCSIRequest
*sreq
)
264 SCSIBus
*bus
= sreq
->bus
;
265 VirtIOSCSI
*s
= container_of(bus
, VirtIOSCSI
, bus
);
269 req
= g_malloc(sizeof(*req
));
270 qemu_get_be32s(f
, &n
);
271 assert(n
< s
->conf
->num_queues
);
272 qemu_get_buffer(f
, (unsigned char *)&req
->elem
, sizeof(req
->elem
));
273 virtio_scsi_parse_req(s
, s
->cmd_vqs
[n
], req
);
277 if (req
->sreq
->cmd
.mode
!= SCSI_XFER_NONE
) {
279 (req
->elem
.in_num
> 1 ? SCSI_XFER_FROM_DEV
: SCSI_XFER_TO_DEV
);
281 assert(req
->sreq
->cmd
.mode
== req_mode
);
286 static void virtio_scsi_do_tmf(VirtIOSCSI
*s
, VirtIOSCSIReq
*req
)
288 SCSIDevice
*d
= virtio_scsi_device_find(s
, req
->req
.tmf
->lun
);
289 SCSIRequest
*r
, *next
;
293 /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE". */
294 req
->resp
.tmf
->response
= VIRTIO_SCSI_S_OK
;
296 switch (req
->req
.tmf
->subtype
) {
297 case VIRTIO_SCSI_T_TMF_ABORT_TASK
:
298 case VIRTIO_SCSI_T_TMF_QUERY_TASK
:
302 if (d
->lun
!= virtio_scsi_get_lun(req
->req
.tmf
->lun
)) {
305 QTAILQ_FOREACH_SAFE(r
, &d
->requests
, next
, next
) {
306 if (r
->tag
== req
->req
.tmf
->tag
) {
310 if (r
&& r
->hba_private
) {
311 if (req
->req
.tmf
->subtype
== VIRTIO_SCSI_T_TMF_QUERY_TASK
) {
312 /* "If the specified command is present in the task set, then
313 * return a service response set to FUNCTION SUCCEEDED".
315 req
->resp
.tmf
->response
= VIRTIO_SCSI_S_FUNCTION_SUCCEEDED
;
322 case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET
:
326 if (d
->lun
!= virtio_scsi_get_lun(req
->req
.tmf
->lun
)) {
330 qdev_reset_all(&d
->qdev
);
334 case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET
:
335 case VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET
:
336 case VIRTIO_SCSI_T_TMF_QUERY_TASK_SET
:
340 if (d
->lun
!= virtio_scsi_get_lun(req
->req
.tmf
->lun
)) {
343 QTAILQ_FOREACH_SAFE(r
, &d
->requests
, next
, next
) {
344 if (r
->hba_private
) {
345 if (req
->req
.tmf
->subtype
== VIRTIO_SCSI_T_TMF_QUERY_TASK_SET
) {
346 /* "If there is any command present in the task set, then
347 * return a service response set to FUNCTION SUCCEEDED".
349 req
->resp
.tmf
->response
= VIRTIO_SCSI_S_FUNCTION_SUCCEEDED
;
358 case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET
:
359 target
= req
->req
.tmf
->lun
[1];
361 QTAILQ_FOREACH(kid
, &s
->bus
.qbus
.children
, sibling
) {
362 d
= DO_UPCAST(SCSIDevice
, qdev
, kid
->child
);
363 if (d
->channel
== 0 && d
->id
== target
) {
364 qdev_reset_all(&d
->qdev
);
370 case VIRTIO_SCSI_T_TMF_CLEAR_ACA
:
372 req
->resp
.tmf
->response
= VIRTIO_SCSI_S_FUNCTION_REJECTED
;
379 req
->resp
.tmf
->response
= VIRTIO_SCSI_S_INCORRECT_LUN
;
383 req
->resp
.tmf
->response
= VIRTIO_SCSI_S_BAD_TARGET
;
386 static void virtio_scsi_handle_ctrl(VirtIODevice
*vdev
, VirtQueue
*vq
)
388 VirtIOSCSI
*s
= (VirtIOSCSI
*)vdev
;
391 while ((req
= virtio_scsi_pop_req(s
, vq
))) {
392 int out_size
, in_size
;
393 if (req
->elem
.out_num
< 1 || req
->elem
.in_num
< 1) {
394 virtio_scsi_bad_req();
398 out_size
= req
->elem
.out_sg
[0].iov_len
;
399 in_size
= req
->elem
.in_sg
[0].iov_len
;
400 if (req
->req
.tmf
->type
== VIRTIO_SCSI_T_TMF
) {
401 if (out_size
< sizeof(VirtIOSCSICtrlTMFReq
) ||
402 in_size
< sizeof(VirtIOSCSICtrlTMFResp
)) {
403 virtio_scsi_bad_req();
405 virtio_scsi_do_tmf(s
, req
);
407 } else if (req
->req
.tmf
->type
== VIRTIO_SCSI_T_AN_QUERY
||
408 req
->req
.tmf
->type
== VIRTIO_SCSI_T_AN_SUBSCRIBE
) {
409 if (out_size
< sizeof(VirtIOSCSICtrlANReq
) ||
410 in_size
< sizeof(VirtIOSCSICtrlANResp
)) {
411 virtio_scsi_bad_req();
413 req
->resp
.an
->event_actual
= 0;
414 req
->resp
.an
->response
= VIRTIO_SCSI_S_OK
;
416 virtio_scsi_complete_req(req
);
420 static void virtio_scsi_command_complete(SCSIRequest
*r
, uint32_t status
,
423 VirtIOSCSIReq
*req
= r
->hba_private
;
425 req
->resp
.cmd
->response
= VIRTIO_SCSI_S_OK
;
426 req
->resp
.cmd
->status
= status
;
427 if (req
->resp
.cmd
->status
== GOOD
) {
428 req
->resp
.cmd
->resid
= resid
;
430 req
->resp
.cmd
->resid
= 0;
431 req
->resp
.cmd
->sense_len
=
432 scsi_req_get_sense(r
, req
->resp
.cmd
->sense
, VIRTIO_SCSI_SENSE_SIZE
);
434 virtio_scsi_complete_req(req
);
437 static QEMUSGList
*virtio_scsi_get_sg_list(SCSIRequest
*r
)
439 VirtIOSCSIReq
*req
= r
->hba_private
;
444 static void virtio_scsi_request_cancelled(SCSIRequest
*r
)
446 VirtIOSCSIReq
*req
= r
->hba_private
;
451 if (req
->dev
->resetting
) {
452 req
->resp
.cmd
->response
= VIRTIO_SCSI_S_RESET
;
454 req
->resp
.cmd
->response
= VIRTIO_SCSI_S_ABORTED
;
456 virtio_scsi_complete_req(req
);
459 static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq
*req
)
461 req
->resp
.cmd
->response
= VIRTIO_SCSI_S_FAILURE
;
462 virtio_scsi_complete_req(req
);
465 static void virtio_scsi_handle_cmd(VirtIODevice
*vdev
, VirtQueue
*vq
)
467 VirtIOSCSI
*s
= (VirtIOSCSI
*)vdev
;
471 while ((req
= virtio_scsi_pop_req(s
, vq
))) {
473 int out_size
, in_size
;
474 if (req
->elem
.out_num
< 1 || req
->elem
.in_num
< 1) {
475 virtio_scsi_bad_req();
478 out_size
= req
->elem
.out_sg
[0].iov_len
;
479 in_size
= req
->elem
.in_sg
[0].iov_len
;
480 if (out_size
< sizeof(VirtIOSCSICmdReq
) + s
->cdb_size
||
481 in_size
< sizeof(VirtIOSCSICmdResp
) + s
->sense_size
) {
482 virtio_scsi_bad_req();
485 if (req
->elem
.out_num
> 1 && req
->elem
.in_num
> 1) {
486 virtio_scsi_fail_cmd_req(req
);
490 d
= virtio_scsi_device_find(s
, req
->req
.cmd
->lun
);
492 req
->resp
.cmd
->response
= VIRTIO_SCSI_S_BAD_TARGET
;
493 virtio_scsi_complete_req(req
);
496 req
->sreq
= scsi_req_new(d
, req
->req
.cmd
->tag
,
497 virtio_scsi_get_lun(req
->req
.cmd
->lun
),
498 req
->req
.cmd
->cdb
, req
);
500 if (req
->sreq
->cmd
.mode
!= SCSI_XFER_NONE
) {
502 (req
->elem
.in_num
> 1 ? SCSI_XFER_FROM_DEV
: SCSI_XFER_TO_DEV
);
504 if (req
->sreq
->cmd
.mode
!= req_mode
||
505 req
->sreq
->cmd
.xfer
> req
->qsgl
.size
) {
506 req
->resp
.cmd
->response
= VIRTIO_SCSI_S_OVERRUN
;
507 virtio_scsi_complete_req(req
);
512 n
= scsi_req_enqueue(req
->sreq
);
514 scsi_req_continue(req
->sreq
);
519 static void virtio_scsi_get_config(VirtIODevice
*vdev
,
522 VirtIOSCSIConfig
*scsiconf
= (VirtIOSCSIConfig
*)config
;
523 VirtIOSCSI
*s
= (VirtIOSCSI
*)vdev
;
525 stl_raw(&scsiconf
->num_queues
, s
->conf
->num_queues
);
526 stl_raw(&scsiconf
->seg_max
, 128 - 2);
527 stl_raw(&scsiconf
->max_sectors
, s
->conf
->max_sectors
);
528 stl_raw(&scsiconf
->cmd_per_lun
, s
->conf
->cmd_per_lun
);
529 stl_raw(&scsiconf
->event_info_size
, sizeof(VirtIOSCSIEvent
));
530 stl_raw(&scsiconf
->sense_size
, s
->sense_size
);
531 stl_raw(&scsiconf
->cdb_size
, s
->cdb_size
);
532 stl_raw(&scsiconf
->max_channel
, VIRTIO_SCSI_MAX_CHANNEL
);
533 stl_raw(&scsiconf
->max_target
, VIRTIO_SCSI_MAX_TARGET
);
534 stl_raw(&scsiconf
->max_lun
, VIRTIO_SCSI_MAX_LUN
);
537 static void virtio_scsi_set_config(VirtIODevice
*vdev
,
538 const uint8_t *config
)
540 VirtIOSCSIConfig
*scsiconf
= (VirtIOSCSIConfig
*)config
;
541 VirtIOSCSI
*s
= (VirtIOSCSI
*)vdev
;
543 if ((uint32_t) ldl_raw(&scsiconf
->sense_size
) >= 65536 ||
544 (uint32_t) ldl_raw(&scsiconf
->cdb_size
) >= 256) {
545 error_report("bad data written to virtio-scsi configuration space");
549 s
->sense_size
= ldl_raw(&scsiconf
->sense_size
);
550 s
->cdb_size
= ldl_raw(&scsiconf
->cdb_size
);
553 static uint32_t virtio_scsi_get_features(VirtIODevice
*vdev
,
554 uint32_t requested_features
)
556 requested_features
|= (1UL << VIRTIO_SCSI_F_HOTPLUG
);
557 return requested_features
;
560 static void virtio_scsi_reset(VirtIODevice
*vdev
)
562 VirtIOSCSI
*s
= (VirtIOSCSI
*)vdev
;
564 s
->sense_size
= VIRTIO_SCSI_SENSE_SIZE
;
565 s
->cdb_size
= VIRTIO_SCSI_CDB_SIZE
;
566 s
->events_dropped
= false;
569 /* The device does not have anything to save beyond the virtio data.
570 * Request data is saved with callbacks from SCSI devices.
572 static void virtio_scsi_save(QEMUFile
*f
, void *opaque
)
574 VirtIOSCSI
*s
= opaque
;
575 virtio_save(&s
->vdev
, f
);
578 static int virtio_scsi_load(QEMUFile
*f
, void *opaque
, int version_id
)
580 VirtIOSCSI
*s
= opaque
;
583 ret
= virtio_load(&s
->vdev
, f
);
590 static void virtio_scsi_push_event(VirtIOSCSI
*s
, SCSIDevice
*dev
,
591 uint32_t event
, uint32_t reason
)
593 VirtIOSCSIReq
*req
= virtio_scsi_pop_req(s
, s
->event_vq
);
594 VirtIOSCSIEvent
*evt
;
598 s
->events_dropped
= true;
602 if (req
->elem
.out_num
|| req
->elem
.in_num
!= 1) {
603 virtio_scsi_bad_req();
606 if (s
->events_dropped
) {
607 event
|= VIRTIO_SCSI_T_EVENTS_MISSED
;
608 s
->events_dropped
= false;
611 in_size
= req
->elem
.in_sg
[0].iov_len
;
612 if (in_size
< sizeof(VirtIOSCSIEvent
)) {
613 virtio_scsi_bad_req();
616 evt
= req
->resp
.event
;
617 memset(evt
, 0, sizeof(VirtIOSCSIEvent
));
619 evt
->reason
= reason
;
621 assert(event
== VIRTIO_SCSI_T_NO_EVENT
);
624 evt
->lun
[1] = dev
->id
;
626 /* Linux wants us to keep the same encoding we use for REPORT LUNS. */
627 if (dev
->lun
>= 256) {
628 evt
->lun
[2] = (dev
->lun
>> 8) | 0x40;
630 evt
->lun
[3] = dev
->lun
& 0xFF;
632 virtio_scsi_complete_req(req
);
635 static void virtio_scsi_handle_event(VirtIODevice
*vdev
, VirtQueue
*vq
)
637 VirtIOSCSI
*s
= (VirtIOSCSI
*)vdev
;
639 if (s
->events_dropped
) {
640 virtio_scsi_push_event(s
, NULL
, VIRTIO_SCSI_T_NO_EVENT
, 0);
644 static void virtio_scsi_hotplug(SCSIBus
*bus
, SCSIDevice
*dev
)
646 VirtIOSCSI
*s
= container_of(bus
, VirtIOSCSI
, bus
);
648 if (((s
->vdev
.guest_features
>> VIRTIO_SCSI_F_HOTPLUG
) & 1) &&
649 (s
->vdev
.status
& VIRTIO_CONFIG_S_DRIVER_OK
)) {
650 virtio_scsi_push_event(s
, dev
, VIRTIO_SCSI_T_TRANSPORT_RESET
,
651 VIRTIO_SCSI_EVT_RESET_RESCAN
);
655 static void virtio_scsi_hot_unplug(SCSIBus
*bus
, SCSIDevice
*dev
)
657 VirtIOSCSI
*s
= container_of(bus
, VirtIOSCSI
, bus
);
659 if ((s
->vdev
.guest_features
>> VIRTIO_SCSI_F_HOTPLUG
) & 1) {
660 virtio_scsi_push_event(s
, dev
, VIRTIO_SCSI_T_TRANSPORT_RESET
,
661 VIRTIO_SCSI_EVT_RESET_REMOVED
);
665 static struct SCSIBusInfo virtio_scsi_scsi_info
= {
667 .max_channel
= VIRTIO_SCSI_MAX_CHANNEL
,
668 .max_target
= VIRTIO_SCSI_MAX_TARGET
,
669 .max_lun
= VIRTIO_SCSI_MAX_LUN
,
671 .complete
= virtio_scsi_command_complete
,
672 .cancel
= virtio_scsi_request_cancelled
,
673 .hotplug
= virtio_scsi_hotplug
,
674 .hot_unplug
= virtio_scsi_hot_unplug
,
675 .get_sg_list
= virtio_scsi_get_sg_list
,
676 .save_request
= virtio_scsi_save_request
,
677 .load_request
= virtio_scsi_load_request
,
680 VirtIODevice
*virtio_scsi_init(DeviceState
*dev
, VirtIOSCSIConf
*proxyconf
)
683 static int virtio_scsi_id
;
687 sz
= sizeof(VirtIOSCSI
) + proxyconf
->num_queues
* sizeof(VirtQueue
*);
688 s
= (VirtIOSCSI
*)virtio_common_init("virtio-scsi", VIRTIO_ID_SCSI
,
689 sizeof(VirtIOSCSIConfig
), sz
);
694 /* TODO set up vdev function pointers */
695 s
->vdev
.get_config
= virtio_scsi_get_config
;
696 s
->vdev
.set_config
= virtio_scsi_set_config
;
697 s
->vdev
.get_features
= virtio_scsi_get_features
;
698 s
->vdev
.reset
= virtio_scsi_reset
;
700 s
->ctrl_vq
= virtio_add_queue(&s
->vdev
, VIRTIO_SCSI_VQ_SIZE
,
701 virtio_scsi_handle_ctrl
);
702 s
->event_vq
= virtio_add_queue(&s
->vdev
, VIRTIO_SCSI_VQ_SIZE
,
703 virtio_scsi_handle_event
);
704 for (i
= 0; i
< s
->conf
->num_queues
; i
++) {
705 s
->cmd_vqs
[i
] = virtio_add_queue(&s
->vdev
, VIRTIO_SCSI_VQ_SIZE
,
706 virtio_scsi_handle_cmd
);
709 scsi_bus_new(&s
->bus
, dev
, &virtio_scsi_scsi_info
);
710 if (!dev
->hotplugged
) {
711 scsi_bus_legacy_handle_cmdline(&s
->bus
);
714 register_savevm(dev
, "virtio-scsi", virtio_scsi_id
++, 1,
715 virtio_scsi_save
, virtio_scsi_load
, s
);
720 void virtio_scsi_exit(VirtIODevice
*vdev
)
722 VirtIOSCSI
*s
= (VirtIOSCSI
*)vdev
;
723 unregister_savevm(s
->qdev
, "virtio-scsi", s
);
724 virtio_cleanup(vdev
);