scsi: Make errp the last parameter of virtio_scsi_common_realize
[qemu/ar7.git] / include / hw / virtio / virtio-scsi.h
blob8c8453cf1929c8ba8c6248d9047b2729842d8250
1 /*
2 * Virtio SCSI HBA
4 * Copyright IBM, Corp. 2010
6 * Authors:
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"
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 {
49 uint32_t num_queues;
50 uint32_t max_sectors;
51 uint32_t cmd_per_lun;
52 char *vhostfd;
53 char *wwpn;
54 uint32_t boot_tpgt;
55 IOThread *iothread;
58 struct VirtIOSCSI;
60 typedef struct VirtIOSCSICommon {
61 VirtIODevice parent_obj;
62 VirtIOSCSIConf conf;
64 uint32_t sense_size;
65 uint32_t cdb_size;
66 VirtQueue *ctrl_vq;
67 VirtQueue *event_vq;
68 VirtQueue **cmd_vqs;
69 } VirtIOSCSICommon;
71 typedef struct VirtIOSCSI {
72 VirtIOSCSICommon parent_obj;
74 SCSIBus bus;
75 int resetting;
76 bool events_dropped;
78 /* Fields for dataplane below */
79 AioContext *ctx; /* one iothread per virtio-scsi-pci for now */
81 bool dataplane_started;
82 bool dataplane_starting;
83 bool dataplane_stopping;
84 bool dataplane_fenced;
85 uint32_t host_features;
86 } VirtIOSCSI;
88 typedef struct VirtIOSCSIReq {
89 /* Note:
90 * - fields up to resp_iov are initialized by virtio_scsi_init_req;
91 * - fields starting at vring are zeroed by virtio_scsi_init_req.
92 * */
93 VirtQueueElement elem;
95 VirtIOSCSI *dev;
96 VirtQueue *vq;
97 QEMUSGList qsgl;
98 QEMUIOVector resp_iov;
100 union {
101 /* Used for two-stage request submission */
102 QTAILQ_ENTRY(VirtIOSCSIReq) next;
104 /* Used for cancellation of request during TMFs */
105 int remaining;
108 SCSIRequest *sreq;
109 size_t resp_size;
110 enum SCSIXferMode mode;
111 union {
112 VirtIOSCSICmdResp cmd;
113 VirtIOSCSICtrlTMFResp tmf;
114 VirtIOSCSICtrlANResp an;
115 VirtIOSCSIEvent event;
116 } resp;
117 union {
118 VirtIOSCSICmdReq cmd;
119 VirtIOSCSICtrlTMFReq tmf;
120 VirtIOSCSICtrlANReq an;
121 } req;
122 } VirtIOSCSIReq;
124 static inline void virtio_scsi_acquire(VirtIOSCSI *s)
126 if (s->ctx) {
127 aio_context_acquire(s->ctx);
131 static inline void virtio_scsi_release(VirtIOSCSI *s)
133 if (s->ctx) {
134 aio_context_release(s->ctx);
138 void virtio_scsi_common_realize(DeviceState *dev,
139 VirtIOHandleOutput ctrl,
140 VirtIOHandleOutput evt,
141 VirtIOHandleOutput cmd,
142 Error **errp);
144 void virtio_scsi_common_unrealize(DeviceState *dev, Error **errp);
145 bool virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq);
146 bool virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq);
147 bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq);
148 void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req);
149 void virtio_scsi_free_req(VirtIOSCSIReq *req);
150 void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev,
151 uint32_t event, uint32_t reason);
153 void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp);
154 int virtio_scsi_dataplane_start(VirtIODevice *s);
155 void virtio_scsi_dataplane_stop(VirtIODevice *s);
157 #endif /* QEMU_VIRTIO_SCSI_H */