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
16 #include "qom/object.h"
18 /* Override CDB/sense data size: they are dynamic (guest controlled) in QEMU */
19 #define VIRTIO_SCSI_CDB_SIZE 0
20 #define VIRTIO_SCSI_SENSE_SIZE 0
21 #include "standard-headers/linux/virtio_scsi.h"
22 #include "hw/virtio/virtio.h"
23 #include "hw/pci/pci.h"
24 #include "hw/scsi/scsi.h"
25 #include "chardev/char-fe.h"
26 #include "sysemu/iothread.h"
28 #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common"
29 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSCSICommon
, VIRTIO_SCSI_COMMON
)
31 #define TYPE_VIRTIO_SCSI "virtio-scsi-device"
32 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOSCSI
, VIRTIO_SCSI
)
34 #define VIRTIO_SCSI_MAX_CHANNEL 0
35 #define VIRTIO_SCSI_MAX_TARGET 255
36 #define VIRTIO_SCSI_MAX_LUN 16383
38 /* Number of virtqueues that are always present */
39 #define VIRTIO_SCSI_VQ_NUM_FIXED 2
41 #define VIRTIO_SCSI_AUTO_NUM_QUEUES UINT32_MAX
43 typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq
;
44 typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp
;
45 typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq
;
46 typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp
;
47 typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq
;
48 typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp
;
49 typedef struct virtio_scsi_event VirtIOSCSIEvent
;
50 typedef struct virtio_scsi_config VirtIOSCSIConfig
;
52 struct VirtIOSCSIConf
{
54 uint32_t virtqueue_size
;
58 #ifdef CONFIG_VHOST_SCSI
69 struct VirtIOSCSICommon
{
70 VirtIODevice parent_obj
;
81 VirtIOSCSICommon parent_obj
;
87 /* Fields for dataplane below */
88 AioContext
*ctx
; /* one iothread per virtio-scsi-pci for now */
90 bool dataplane_started
;
91 bool dataplane_starting
;
92 bool dataplane_stopping
;
93 bool dataplane_fenced
;
94 uint32_t host_features
;
97 typedef struct VirtIOSCSIReq
{
99 * - fields up to resp_iov are initialized by virtio_scsi_init_req;
100 * - fields starting at vring are zeroed by virtio_scsi_init_req.
102 VirtQueueElement elem
;
107 QEMUIOVector resp_iov
;
110 /* Used for two-stage request submission */
111 QTAILQ_ENTRY(VirtIOSCSIReq
) next
;
113 /* Used for cancellation of request during TMFs */
119 enum SCSIXferMode mode
;
121 VirtIOSCSICmdResp cmd
;
122 VirtIOSCSICtrlTMFResp tmf
;
123 VirtIOSCSICtrlANResp an
;
124 VirtIOSCSIEvent event
;
127 VirtIOSCSICmdReq cmd
;
128 VirtIOSCSICtrlTMFReq tmf
;
129 VirtIOSCSICtrlANReq an
;
133 static inline void virtio_scsi_acquire(VirtIOSCSI
*s
)
136 aio_context_acquire(s
->ctx
);
140 static inline void virtio_scsi_release(VirtIOSCSI
*s
)
143 aio_context_release(s
->ctx
);
147 void virtio_scsi_common_realize(DeviceState
*dev
,
148 VirtIOHandleOutput ctrl
,
149 VirtIOHandleOutput evt
,
150 VirtIOHandleOutput cmd
,
153 void virtio_scsi_common_unrealize(DeviceState
*dev
);
154 bool virtio_scsi_handle_event_vq(VirtIOSCSI
*s
, VirtQueue
*vq
);
155 bool virtio_scsi_handle_cmd_vq(VirtIOSCSI
*s
, VirtQueue
*vq
);
156 bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI
*s
, VirtQueue
*vq
);
157 void virtio_scsi_init_req(VirtIOSCSI
*s
, VirtQueue
*vq
, VirtIOSCSIReq
*req
);
158 void virtio_scsi_free_req(VirtIOSCSIReq
*req
);
159 void virtio_scsi_push_event(VirtIOSCSI
*s
, SCSIDevice
*dev
,
160 uint32_t event
, uint32_t reason
);
162 void virtio_scsi_dataplane_setup(VirtIOSCSI
*s
, Error
**errp
);
163 int virtio_scsi_dataplane_start(VirtIODevice
*s
);
164 void virtio_scsi_dataplane_stop(VirtIODevice
*s
);
166 #endif /* QEMU_VIRTIO_SCSI_H */