4 * Copyright IBM, Corp. 2010
7 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef QEMU_VIRTIO_SCSI_H
15 #define QEMU_VIRTIO_SCSI_H
17 /* Override CDB/sense data size: they are dynamic (guest controlled) in QEMU */
18 #define VIRTIO_SCSI_CDB_SIZE 0
19 #define VIRTIO_SCSI_SENSE_SIZE 0
20 #include "standard-headers/linux/virtio_scsi.h"
21 #include "hw/virtio/virtio.h"
22 #include "hw/pci/pci.h"
23 #include "hw/scsi/scsi.h"
24 #include "chardev/char-fe.h"
25 #include "sysemu/iothread.h"
27 #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common"
28 #define VIRTIO_SCSI_COMMON(obj) \
29 OBJECT_CHECK(VirtIOSCSICommon, (obj), TYPE_VIRTIO_SCSI_COMMON)
31 #define TYPE_VIRTIO_SCSI "virtio-scsi-device"
32 #define VIRTIO_SCSI(obj) \
33 OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
35 #define VIRTIO_SCSI_VQ_SIZE 128
36 #define VIRTIO_SCSI_MAX_CHANNEL 0
37 #define VIRTIO_SCSI_MAX_TARGET 255
38 #define VIRTIO_SCSI_MAX_LUN 16383
40 typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq
;
41 typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp
;
42 typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq
;
43 typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp
;
44 typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq
;
45 typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp
;
46 typedef struct virtio_scsi_event VirtIOSCSIEvent
;
47 typedef struct virtio_scsi_config VirtIOSCSIConfig
;
49 struct VirtIOSCSIConf
{
53 #ifdef CONFIG_VHOST_SCSI
64 typedef struct VirtIOSCSICommon
{
65 VirtIODevice parent_obj
;
75 typedef struct VirtIOSCSI
{
76 VirtIOSCSICommon parent_obj
;
82 /* Fields for dataplane below */
83 AioContext
*ctx
; /* one iothread per virtio-scsi-pci for now */
85 bool dataplane_started
;
86 bool dataplane_starting
;
87 bool dataplane_stopping
;
88 bool dataplane_fenced
;
89 uint32_t host_features
;
92 typedef struct VirtIOSCSIReq
{
94 * - fields up to resp_iov are initialized by virtio_scsi_init_req;
95 * - fields starting at vring are zeroed by virtio_scsi_init_req.
97 VirtQueueElement elem
;
102 QEMUIOVector resp_iov
;
105 /* Used for two-stage request submission */
106 QTAILQ_ENTRY(VirtIOSCSIReq
) next
;
108 /* Used for cancellation of request during TMFs */
114 enum SCSIXferMode mode
;
116 VirtIOSCSICmdResp cmd
;
117 VirtIOSCSICtrlTMFResp tmf
;
118 VirtIOSCSICtrlANResp an
;
119 VirtIOSCSIEvent event
;
122 VirtIOSCSICmdReq cmd
;
123 VirtIOSCSICtrlTMFReq tmf
;
124 VirtIOSCSICtrlANReq an
;
128 static inline void virtio_scsi_acquire(VirtIOSCSI
*s
)
131 aio_context_acquire(s
->ctx
);
135 static inline void virtio_scsi_release(VirtIOSCSI
*s
)
138 aio_context_release(s
->ctx
);
142 void virtio_scsi_common_realize(DeviceState
*dev
,
143 VirtIOHandleOutput ctrl
,
144 VirtIOHandleOutput evt
,
145 VirtIOHandleOutput cmd
,
148 void virtio_scsi_common_unrealize(DeviceState
*dev
, Error
**errp
);
149 bool virtio_scsi_handle_event_vq(VirtIOSCSI
*s
, VirtQueue
*vq
);
150 bool virtio_scsi_handle_cmd_vq(VirtIOSCSI
*s
, VirtQueue
*vq
);
151 bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI
*s
, VirtQueue
*vq
);
152 void virtio_scsi_init_req(VirtIOSCSI
*s
, VirtQueue
*vq
, VirtIOSCSIReq
*req
);
153 void virtio_scsi_free_req(VirtIOSCSIReq
*req
);
154 void virtio_scsi_push_event(VirtIOSCSI
*s
, SCSIDevice
*dev
,
155 uint32_t event
, uint32_t reason
);
157 void virtio_scsi_dataplane_setup(VirtIOSCSI
*s
, Error
**errp
);
158 int virtio_scsi_dataplane_start(VirtIODevice
*s
);
159 void virtio_scsi_dataplane_stop(VirtIODevice
*s
);
161 #endif /* QEMU_VIRTIO_SCSI_H */