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 "sysemu/iothread.h"
25 #include "hw/virtio/dataplane/vring.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
{
62 struct VirtIOSCSI
*parent
;
64 EventNotifier host_notifier
;
65 EventNotifier guest_notifier
;
68 typedef struct VirtIOSCSICommon
{
69 VirtIODevice parent_obj
;
79 typedef struct VirtIOSCSIBlkChangeNotifier
{
83 QTAILQ_ENTRY(VirtIOSCSIBlkChangeNotifier
) next
;
84 } VirtIOSCSIBlkChangeNotifier
;
86 typedef struct VirtIOSCSI
{
87 VirtIOSCSICommon parent_obj
;
93 /* Fields for dataplane below */
94 AioContext
*ctx
; /* one iothread per virtio-scsi-pci for now */
96 QTAILQ_HEAD(, VirtIOSCSIBlkChangeNotifier
) insert_notifiers
;
97 QTAILQ_HEAD(, VirtIOSCSIBlkChangeNotifier
) remove_notifiers
;
99 /* Vring is used instead of vq in dataplane code, because of the underlying
100 * memory layer thread safety */
101 VirtIOSCSIVring
*ctrl_vring
;
102 VirtIOSCSIVring
*event_vring
;
103 VirtIOSCSIVring
**cmd_vrings
;
104 bool dataplane_started
;
105 bool dataplane_starting
;
106 bool dataplane_stopping
;
107 bool dataplane_disabled
;
108 bool dataplane_fenced
;
110 Notifier migration_state_notifier
;
111 uint32_t host_features
;
114 typedef struct VirtIOSCSIReq
{
116 * - fields up to resp_iov are initialized by virtio_scsi_init_req;
117 * - fields starting at vring are zeroed by virtio_scsi_init_req.
119 VirtQueueElement elem
;
124 QEMUIOVector resp_iov
;
126 /* Set by dataplane code. */
127 VirtIOSCSIVring
*vring
;
130 /* Used for two-stage request submission */
131 QTAILQ_ENTRY(VirtIOSCSIReq
) next
;
133 /* Used for cancellation of request during TMFs */
139 enum SCSIXferMode mode
;
141 VirtIOSCSICmdResp cmd
;
142 VirtIOSCSICtrlTMFResp tmf
;
143 VirtIOSCSICtrlANResp an
;
144 VirtIOSCSIEvent event
;
147 VirtIOSCSICmdReq cmd
;
148 VirtIOSCSICtrlTMFReq tmf
;
149 VirtIOSCSICtrlANReq an
;
153 typedef void (*HandleOutput
)(VirtIODevice
*, VirtQueue
*);
155 void virtio_scsi_common_realize(DeviceState
*dev
, Error
**errp
,
156 HandleOutput ctrl
, HandleOutput evt
,
159 void virtio_scsi_common_unrealize(DeviceState
*dev
, Error
**errp
);
160 void virtio_scsi_handle_ctrl_req(VirtIOSCSI
*s
, VirtIOSCSIReq
*req
);
161 bool virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI
*s
, VirtIOSCSIReq
*req
);
162 void virtio_scsi_handle_cmd_req_submit(VirtIOSCSI
*s
, VirtIOSCSIReq
*req
);
163 void virtio_scsi_init_req(VirtIOSCSI
*s
, VirtQueue
*vq
, VirtIOSCSIReq
*req
);
164 void virtio_scsi_free_req(VirtIOSCSIReq
*req
);
165 void virtio_scsi_push_event(VirtIOSCSI
*s
, SCSIDevice
*dev
,
166 uint32_t event
, uint32_t reason
);
168 void virtio_scsi_set_iothread(VirtIOSCSI
*s
, IOThread
*iothread
);
169 void virtio_scsi_dataplane_start(VirtIOSCSI
*s
);
170 void virtio_scsi_dataplane_stop(VirtIOSCSI
*s
);
171 void virtio_scsi_vring_push_notify(VirtIOSCSIReq
*req
);
172 VirtIOSCSIReq
*virtio_scsi_pop_req_vring(VirtIOSCSI
*s
,
173 VirtIOSCSIVring
*vring
);
175 #endif /* _QEMU_VIRTIO_SCSI_H */