]>
Commit | Line | Data |
---|---|---|
973abc7f SH |
1 | /* |
2 | * Virtio SCSI HBA | |
3 | * | |
4 | * Copyright IBM, Corp. 2010 | |
5 | * | |
6 | * Authors: | |
7 | * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
10 | * the COPYING file in the top-level directory. | |
11 | * | |
12 | */ | |
13 | ||
2a6a4076 MA |
14 | #ifndef QEMU_VIRTIO_SCSI_H |
15 | #define QEMU_VIRTIO_SCSI_H | |
db1015e9 | 16 | #include "qom/object.h" |
973abc7f | 17 | |
03325525 MT |
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 | |
019adbd3 | 21 | #include "standard-headers/linux/virtio_scsi.h" |
0d09e41a | 22 | #include "hw/virtio/virtio.h" |
83c9f4ca | 23 | #include "hw/pci/pci.h" |
0d09e41a | 24 | #include "hw/scsi/scsi.h" |
f12c1ebd | 25 | #include "chardev/char-fe.h" |
244e2898 | 26 | #include "sysemu/iothread.h" |
973abc7f | 27 | |
292c8e50 | 28 | #define TYPE_VIRTIO_SCSI_COMMON "virtio-scsi-common" |
db1015e9 | 29 | typedef struct VirtIOSCSICommon VirtIOSCSICommon; |
8110fa1d EH |
30 | DECLARE_INSTANCE_CHECKER(VirtIOSCSICommon, VIRTIO_SCSI_COMMON, |
31 | TYPE_VIRTIO_SCSI_COMMON) | |
292c8e50 | 32 | |
f574fa8b | 33 | #define TYPE_VIRTIO_SCSI "virtio-scsi-device" |
db1015e9 | 34 | typedef struct VirtIOSCSI VirtIOSCSI; |
8110fa1d EH |
35 | DECLARE_INSTANCE_CHECKER(VirtIOSCSI, VIRTIO_SCSI, |
36 | TYPE_VIRTIO_SCSI) | |
3ab1dfdd | 37 | |
292c8e50 PB |
38 | #define VIRTIO_SCSI_MAX_CHANNEL 0 |
39 | #define VIRTIO_SCSI_MAX_TARGET 255 | |
40 | #define VIRTIO_SCSI_MAX_LUN 16383 | |
41 | ||
4e5163bd SH |
42 | /* Number of virtqueues that are always present */ |
43 | #define VIRTIO_SCSI_VQ_NUM_FIXED 2 | |
44 | ||
6a558822 SH |
45 | #define VIRTIO_SCSI_AUTO_NUM_QUEUES UINT32_MAX |
46 | ||
019adbd3 MT |
47 | typedef struct virtio_scsi_cmd_req VirtIOSCSICmdReq; |
48 | typedef struct virtio_scsi_cmd_resp VirtIOSCSICmdResp; | |
49 | typedef struct virtio_scsi_ctrl_tmf_req VirtIOSCSICtrlTMFReq; | |
50 | typedef struct virtio_scsi_ctrl_tmf_resp VirtIOSCSICtrlTMFResp; | |
51 | typedef struct virtio_scsi_ctrl_an_req VirtIOSCSICtrlANReq; | |
52 | typedef struct virtio_scsi_ctrl_an_resp VirtIOSCSICtrlANResp; | |
53 | typedef struct virtio_scsi_event VirtIOSCSIEvent; | |
54 | typedef struct virtio_scsi_config VirtIOSCSIConfig; | |
292c8e50 | 55 | |
973abc7f SH |
56 | struct VirtIOSCSIConf { |
57 | uint32_t num_queues; | |
5c0919d0 | 58 | uint32_t virtqueue_size; |
1bf8a989 | 59 | bool seg_max_adjust; |
973abc7f SH |
60 | uint32_t max_sectors; |
61 | uint32_t cmd_per_lun; | |
95615ce5 | 62 | #ifdef CONFIG_VHOST_SCSI |
5e9be92d NB |
63 | char *vhostfd; |
64 | char *wwpn; | |
95615ce5 | 65 | #endif |
f12c1ebd | 66 | CharBackend chardev; |
9143d5f0 | 67 | uint32_t boot_tpgt; |
19d339f1 | 68 | IOThread *iothread; |
973abc7f SH |
69 | }; |
70 | ||
244e2898 FZ |
71 | struct VirtIOSCSI; |
72 | ||
db1015e9 | 73 | struct VirtIOSCSICommon { |
0ac8e139 | 74 | VirtIODevice parent_obj; |
394e2e4c | 75 | VirtIOSCSIConf conf; |
f1b24e84 | 76 | |
f1b24e84 FK |
77 | uint32_t sense_size; |
78 | uint32_t cdb_size; | |
f1b24e84 FK |
79 | VirtQueue *ctrl_vq; |
80 | VirtQueue *event_vq; | |
22219527 | 81 | VirtQueue **cmd_vqs; |
db1015e9 | 82 | }; |
292c8e50 | 83 | |
db1015e9 | 84 | struct VirtIOSCSI { |
292c8e50 PB |
85 | VirtIOSCSICommon parent_obj; |
86 | ||
87 | SCSIBus bus; | |
88 | int resetting; | |
89 | bool events_dropped; | |
91cb1c9b FZ |
90 | |
91 | /* Fields for dataplane below */ | |
92 | AioContext *ctx; /* one iothread per virtio-scsi-pci for now */ | |
93 | ||
91cb1c9b FZ |
94 | bool dataplane_started; |
95 | bool dataplane_starting; | |
96 | bool dataplane_stopping; | |
4adea804 | 97 | bool dataplane_fenced; |
da2f84d1 | 98 | uint32_t host_features; |
db1015e9 | 99 | }; |
f1b24e84 | 100 | |
bf359a44 | 101 | typedef struct VirtIOSCSIReq { |
6aa46d8f PB |
102 | /* Note: |
103 | * - fields up to resp_iov are initialized by virtio_scsi_init_req; | |
104 | * - fields starting at vring are zeroed by virtio_scsi_init_req. | |
105 | * */ | |
106 | VirtQueueElement elem; | |
107 | ||
bf359a44 FZ |
108 | VirtIOSCSI *dev; |
109 | VirtQueue *vq; | |
110 | QEMUSGList qsgl; | |
111 | QEMUIOVector resp_iov; | |
112 | ||
49e7e31a FZ |
113 | union { |
114 | /* Used for two-stage request submission */ | |
115 | QTAILQ_ENTRY(VirtIOSCSIReq) next; | |
116 | ||
117 | /* Used for cancellation of request during TMFs */ | |
118 | int remaining; | |
119 | }; | |
1880ad4f | 120 | |
bf359a44 FZ |
121 | SCSIRequest *sreq; |
122 | size_t resp_size; | |
123 | enum SCSIXferMode mode; | |
124 | union { | |
125 | VirtIOSCSICmdResp cmd; | |
126 | VirtIOSCSICtrlTMFResp tmf; | |
127 | VirtIOSCSICtrlANResp an; | |
128 | VirtIOSCSIEvent event; | |
129 | } resp; | |
130 | union { | |
18bf9e2f | 131 | VirtIOSCSICmdReq cmd; |
bf359a44 FZ |
132 | VirtIOSCSICtrlTMFReq tmf; |
133 | VirtIOSCSICtrlANReq an; | |
134 | } req; | |
135 | } VirtIOSCSIReq; | |
136 | ||
3d69f821 FZ |
137 | static inline void virtio_scsi_acquire(VirtIOSCSI *s) |
138 | { | |
139 | if (s->ctx) { | |
140 | aio_context_acquire(s->ctx); | |
141 | } | |
142 | } | |
143 | ||
144 | static inline void virtio_scsi_release(VirtIOSCSI *s) | |
145 | { | |
146 | if (s->ctx) { | |
147 | aio_context_release(s->ctx); | |
148 | } | |
149 | } | |
150 | ||
bf46e67d FZ |
151 | void virtio_scsi_common_realize(DeviceState *dev, |
152 | VirtIOHandleOutput ctrl, | |
153 | VirtIOHandleOutput evt, | |
154 | VirtIOHandleOutput cmd, | |
155 | Error **errp); | |
91d670fb | 156 | |
12e1dc49 | 157 | void virtio_scsi_common_unrealize(DeviceState *dev); |
07931698 FZ |
158 | bool virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq); |
159 | bool virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq); | |
160 | bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq); | |
51b19ebe | 161 | void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req); |
aa8e8f83 | 162 | void virtio_scsi_free_req(VirtIOSCSIReq *req); |
20e6dca1 FZ |
163 | void virtio_scsi_push_event(VirtIOSCSI *s, SCSIDevice *dev, |
164 | uint32_t event, uint32_t reason); | |
292c8e50 | 165 | |
ad07cd69 PB |
166 | void virtio_scsi_dataplane_setup(VirtIOSCSI *s, Error **errp); |
167 | int virtio_scsi_dataplane_start(VirtIODevice *s); | |
168 | void virtio_scsi_dataplane_stop(VirtIODevice *s); | |
91cb1c9b | 169 | |
2a6a4076 | 170 | #endif /* QEMU_VIRTIO_SCSI_H */ |