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