]>
Commit | Line | Data |
---|---|---|
6e02c38d AL |
1 | /* |
2 | * Virtio Block Device | |
3 | * | |
4 | * Copyright IBM, Corp. 2007 | |
5 | * | |
6 | * Authors: | |
7 | * Anthony Liguori <aliguori@us.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 | ||
14 | #ifndef _QEMU_VIRTIO_BLK_H | |
15 | #define _QEMU_VIRTIO_BLK_H | |
16 | ||
0d09e41a PB |
17 | #include "hw/virtio/virtio.h" |
18 | #include "hw/block/block.h" | |
48ff2692 | 19 | #include "sysemu/iothread.h" |
09f64587 | 20 | #include "block/block.h" |
5e5a94b6 | 21 | #include "block/accounting.h" |
6e02c38d | 22 | |
f574fa8b | 23 | #define TYPE_VIRTIO_BLK "virtio-blk-device" |
1c028ddf FK |
24 | #define VIRTIO_BLK(obj) \ |
25 | OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK) | |
26 | ||
6e02c38d AL |
27 | /* from Linux's linux/virtio_blk.h */ |
28 | ||
29 | /* The ID for virtio_block */ | |
30 | #define VIRTIO_ID_BLOCK 2 | |
31 | ||
32 | /* Feature bits */ | |
33 | #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */ | |
34 | #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ | |
35 | #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ | |
36 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */ | |
1063b8b1 CH |
37 | #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ |
38 | #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ | |
39 | #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ | |
37d5ddd6 | 40 | /* #define VIRTIO_BLK_F_IDENTIFY 8 ATA IDENTIFY supported, DEPRECATED */ |
13e3dce0 | 41 | #define VIRTIO_BLK_F_WCE 9 /* write cache enabled */ |
9752c371 | 42 | #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */ |
13e3dce0 | 43 | #define VIRTIO_BLK_F_CONFIG_WCE 11 /* write cache configurable */ |
bf011293 | 44 | |
a8686a9b MA |
45 | #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ |
46 | ||
6e02c38d AL |
47 | struct virtio_blk_config |
48 | { | |
49 | uint64_t capacity; | |
50 | uint32_t size_max; | |
51 | uint32_t seg_max; | |
52 | uint16_t cylinders; | |
53 | uint8_t heads; | |
54 | uint8_t sectors; | |
8cfacf07 | 55 | uint32_t blk_size; |
9752c371 CH |
56 | uint8_t physical_block_exp; |
57 | uint8_t alignment_offset; | |
58 | uint16_t min_io_size; | |
59 | uint32_t opt_io_size; | |
13e3dce0 | 60 | uint8_t wce; |
541dc0d4 | 61 | } QEMU_PACKED; |
6e02c38d AL |
62 | |
63 | /* These two define direction. */ | |
64 | #define VIRTIO_BLK_T_IN 0 | |
65 | #define VIRTIO_BLK_T_OUT 1 | |
66 | ||
67 | /* This bit says it's a scsi command, not an actual read or write. */ | |
68 | #define VIRTIO_BLK_T_SCSI_CMD 2 | |
69 | ||
aa659be3 CH |
70 | /* Flush the volatile write cache */ |
71 | #define VIRTIO_BLK_T_FLUSH 4 | |
72 | ||
2930b313 | 73 | /* return the device ID string */ |
74 | #define VIRTIO_BLK_T_GET_ID 8 | |
75 | ||
6e02c38d AL |
76 | /* Barrier before this op. */ |
77 | #define VIRTIO_BLK_T_BARRIER 0x80000000 | |
78 | ||
79 | /* This is the first element of the read scatter-gather list. */ | |
80 | struct virtio_blk_outhdr | |
81 | { | |
82 | /* VIRTIO_BLK_T* */ | |
83 | uint32_t type; | |
84 | /* io priority. */ | |
85 | uint32_t ioprio; | |
86 | /* Sector (ie. 512 byte offset) */ | |
87 | uint64_t sector; | |
88 | }; | |
89 | ||
90 | #define VIRTIO_BLK_S_OK 0 | |
91 | #define VIRTIO_BLK_S_IOERR 1 | |
92 | #define VIRTIO_BLK_S_UNSUPP 2 | |
93 | ||
8b91408b | 94 | /* This is the last element of the write scatter-gather list */ |
6e02c38d AL |
95 | struct virtio_blk_inhdr |
96 | { | |
97 | unsigned char status; | |
98 | }; | |
99 | ||
1063b8b1 CH |
100 | /* SCSI pass-through header */ |
101 | struct virtio_scsi_inhdr | |
102 | { | |
103 | uint32_t errors; | |
104 | uint32_t data_len; | |
105 | uint32_t sense_len; | |
106 | uint32_t residual; | |
107 | }; | |
108 | ||
12c5674b PB |
109 | struct VirtIOBlkConf |
110 | { | |
111 | BlockConf conf; | |
48ff2692 | 112 | IOThread *iothread; |
12c5674b | 113 | char *serial; |
a6c5c84a | 114 | uint32_t scsi; |
8a873ba7 | 115 | uint32_t config_wce; |
e72f66a0 | 116 | uint32_t data_plane; |
12c5674b PB |
117 | }; |
118 | ||
0d09e41a PB |
119 | struct VirtIOBlockDataPlane; |
120 | ||
bf4bd461 | 121 | struct VirtIOBlockReq; |
f1b24e84 | 122 | typedef struct VirtIOBlock { |
1cc91b7d | 123 | VirtIODevice parent_obj; |
f1b24e84 FK |
124 | BlockDriverState *bs; |
125 | VirtQueue *vq; | |
126 | void *rq; | |
127 | QEMUBH *bh; | |
da3dcefa | 128 | VirtIOBlkConf blk; |
f1b24e84 | 129 | unsigned short sector_mask; |
ef5bc962 | 130 | bool original_wce; |
f1b24e84 | 131 | VMChangeStateEntry *change; |
bf4bd461 FZ |
132 | /* Function to push to vq and notify guest */ |
133 | void (*complete_request)(struct VirtIOBlockReq *req, unsigned char status); | |
84db52d0 | 134 | Notifier migration_state_notifier; |
0d09e41a | 135 | struct VirtIOBlockDataPlane *dataplane; |
f1b24e84 FK |
136 | } VirtIOBlock; |
137 | ||
fee65db7 FZ |
138 | typedef struct MultiReqBuffer { |
139 | BlockRequest blkreq[32]; | |
140 | unsigned int num_writes; | |
141 | } MultiReqBuffer; | |
142 | ||
09f64587 FZ |
143 | typedef struct VirtIOBlockReq { |
144 | VirtIOBlock *dev; | |
f897bf75 | 145 | VirtQueueElement elem; |
09f64587 | 146 | struct virtio_blk_inhdr *in; |
827805a2 | 147 | struct virtio_blk_outhdr out; |
09f64587 FZ |
148 | QEMUIOVector qiov; |
149 | struct VirtIOBlockReq *next; | |
150 | BlockAcctCookie acct; | |
151 | } VirtIOBlockReq; | |
152 | ||
f897bf75 SH |
153 | VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s); |
154 | ||
155 | void virtio_blk_free_request(VirtIOBlockReq *req); | |
156 | ||
5a05cbee FZ |
157 | int virtio_blk_handle_scsi_req(VirtIOBlock *blk, |
158 | VirtQueueElement *elem); | |
159 | ||
fee65db7 FZ |
160 | void virtio_blk_handle_request(VirtIOBlockReq *req, MultiReqBuffer *mrb); |
161 | ||
162 | void virtio_submit_multiwrite(BlockDriverState *bs, MultiReqBuffer *mrb); | |
163 | ||
6e02c38d | 164 | #endif |