blob: fff46da7db680f44cbc8917406347a6ce4ebb873 [file] [log] [blame]
aliguori6e02c382008-12-04 19:52:44 +00001/*
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
17#include "virtio.h"
18#include "block.h"
aliguori6e02c382008-12-04 19:52:44 +000019
20/* from Linux's linux/virtio_blk.h */
21
22/* The ID for virtio_block */
23#define VIRTIO_ID_BLOCK 2
24
25/* Feature bits */
26#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
27#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
28#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
29#define VIRTIO_BLK_F_GEOMETRY 4 /* Indicates support of legacy geometry */
Christoph Hellwig1063b8b2009-04-27 10:29:14 +020030#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
31#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
32#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
hch@lst.de37d5ddd2010-02-10 23:36:49 +010033/* #define VIRTIO_BLK_F_IDENTIFY 8 ATA IDENTIFY supported, DEPRECATED */
Christoph Hellwigaa659be2009-09-04 19:02:23 +020034#define VIRTIO_BLK_F_WCACHE 9 /* write cache enabled */
Christoph Hellwig9752c372010-02-10 23:37:25 +010035#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
john cooperbf011292009-06-22 14:26:51 -040036
aliguori6e02c382008-12-04 19:52:44 +000037struct virtio_blk_config
38{
39 uint64_t capacity;
40 uint32_t size_max;
41 uint32_t seg_max;
42 uint16_t cylinders;
43 uint8_t heads;
44 uint8_t sectors;
Christoph Hellwig8cfacf02010-03-04 14:20:17 +010045 uint32_t blk_size;
Christoph Hellwig9752c372010-02-10 23:37:25 +010046 uint8_t physical_block_exp;
47 uint8_t alignment_offset;
48 uint16_t min_io_size;
49 uint32_t opt_io_size;
aliguori6e02c382008-12-04 19:52:44 +000050} __attribute__((packed));
51
52/* These two define direction. */
53#define VIRTIO_BLK_T_IN 0
54#define VIRTIO_BLK_T_OUT 1
55
56/* This bit says it's a scsi command, not an actual read or write. */
57#define VIRTIO_BLK_T_SCSI_CMD 2
58
Christoph Hellwigaa659be2009-09-04 19:02:23 +020059/* Flush the volatile write cache */
60#define VIRTIO_BLK_T_FLUSH 4
61
john cooper2930b312010-07-02 13:44:25 -040062/* return the device ID string */
63#define VIRTIO_BLK_T_GET_ID 8
64
aliguori6e02c382008-12-04 19:52:44 +000065/* Barrier before this op. */
66#define VIRTIO_BLK_T_BARRIER 0x80000000
67
68/* This is the first element of the read scatter-gather list. */
69struct virtio_blk_outhdr
70{
71 /* VIRTIO_BLK_T* */
72 uint32_t type;
73 /* io priority. */
74 uint32_t ioprio;
75 /* Sector (ie. 512 byte offset) */
76 uint64_t sector;
77};
78
79#define VIRTIO_BLK_S_OK 0
80#define VIRTIO_BLK_S_IOERR 1
81#define VIRTIO_BLK_S_UNSUPP 2
82
Christoph Hellwig8b914082009-04-23 12:58:51 +020083/* This is the last element of the write scatter-gather list */
aliguori6e02c382008-12-04 19:52:44 +000084struct virtio_blk_inhdr
85{
86 unsigned char status;
87};
88
Christoph Hellwig1063b8b2009-04-27 10:29:14 +020089/* SCSI pass-through header */
90struct virtio_scsi_inhdr
91{
92 uint32_t errors;
93 uint32_t data_len;
94 uint32_t sense_len;
95 uint32_t residual;
96};
97
Michael S. Tsirkin81725392010-01-10 13:52:53 +020098#ifdef __linux__
99#define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
100 DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
101 DEFINE_PROP_BIT("scsi", _state, _field, VIRTIO_BLK_F_SCSI, true)
102#else
103#define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
104 DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
105#endif
aliguori6e02c382008-12-04 19:52:44 +0000106#endif