4 * Copyright IBM, Corp. 2010
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"
26 #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common"
27 #define VIRTIO_SCSI_COMMON(obj) \
28 OBJECT_CHECK(VirtIOSCSICommon, (obj), TYPE_VIRTIO_SCSI_COMMON)
30 #define TYPE_VIRTIO_SCSI "virtio-scsi-device"
31 #define VIRTIO_SCSI(obj) \
32 OBJECT_CHECK(VirtIOSCSI, (obj), TYPE_VIRTIO_SCSI)
34 #define VIRTIO_SCSI_VQ_SIZE 128
35 #define VIRTIO_SCSI_MAX_CHANNEL 0
36 #define VIRTIO_SCSI_MAX_TARGET 255
37 #define VIRTIO_SCSI_MAX_LUN 16383
39 typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq;
40 typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp;
41 typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq;
42 typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp;
43 typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq;
44 typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp;
45 typedef struct virtio_scsi_event VirtIOSCSIEvent;
46 typedef struct virtio_scsi_config VirtIOSCSIConfig;
48 struct VirtIOSCSIConf {
60 typedef struct VirtIOSCSICommon {
61 VirtIODevice parent_obj;
71 typedef struct VirtIOSCSIBlkChangeNotifier {
75 QTAILQ_ENTRY(VirtIOSCSIBlkChangeNotifier) next;
76 } VirtIOSCSIBlkChangeNotifier;
78 typedef struct VirtIOSCSI {
79 VirtIOSCSICommon parent_obj;
85 /* Fields for dataplane below */
86 AioContext *ctx; /* one iothread per virtio-scsi-pci for now */
88 QTAILQ_HEAD(, VirtIOSCSIBlkChangeNotifier) insert_notifiers;
89 QTAILQ_HEAD(, VirtIOSCSIBlkChangeNotifier) remove_notifiers;
91 bool dataplane_started;
92 bool dataplane_starting;
93 bool dataplane_stopping;
94 bool dataplane_fenced;
96 uint32_t host_features;
99 typedef struct VirtIOSCSIReq {
101 * - fields up to resp_iov are initialized by virtio_scsi_init_req;
102 * - fields starting at vring are zeroed by virtio_scsi_init_req.
104 VirtQueueElement elem;
109 QEMUIOVector resp_iov;
112 /* Used for two-stage request submission */
113 QTAILQ_ENTRY(VirtIOSCSIReq) next;
115 /* Used for cancellation of request during TMFs */
121 enum SCSIXferMode mode;
123 VirtIOSCSICmdResp cmd;
124 VirtIOSCSICtrlTMFResp tmf;
125 VirtIOSCSICtrlANResp an;
126 VirtIOSCSIEvent event;
129 VirtIOSCSICmdReq cmd;
130 VirtIOSCSICtrlTMFReq tmf;
131 VirtIOSCSICtrlANReq an;
135 typedef void (*HandleOutput)(VirtIODevice *, VirtQueue *);
137 void virtio_scsi_common_realize(DeviceState *dev, Error **errp,
138 HandleOutput ctrl, HandleOutput evt,
141 void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp);
142 void virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq);
143 void virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq);
144 void virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq);
145 void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req);
146 void virtio_scsi_free_req(VirtIOSCSIReq *req);
147 void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
148 uint32_t event, uint32_t reason);
150 void virtio_scsi_set_iothread(VirtIOSCSI *s, IOThread *iothread);
151 void virtio_scsi_dataplane_start(VirtIOSCSI *s);
152 void virtio_scsi_dataplane_stop(VirtIOSCSI *s);
153 void virtio_scsi_dataplane_notify(VirtIODevice *vdev, VirtIOSCSIReq *req);
155 #endif /* _QEMU_VIRTIO_SCSI_H */