blob: 167720d695ed00bb94b9174381de80f13fd6d009 [file] [log] [blame]
Rusty Russelle467cde2007-10-22 11:03:38 +10001#ifndef _LINUX_VIRTIO_BLK_H
2#define _LINUX_VIRTIO_BLK_H
Rusty Russell674bfc22008-07-25 12:06:03 -05003/* This header is BSD licensed so anyone can use the definitions to implement
4 * compatible drivers/servers. */
Jaswinder Singh Rajput982f8182009-01-30 22:27:58 +05305#include <linux/types.h>
Christian Borntraegere95646c2009-09-30 11:17:21 +02006#include <linux/virtio_ids.h>
Rusty Russelle467cde2007-10-22 11:03:38 +10007#include <linux/virtio_config.h>
8
Rusty Russelle467cde2007-10-22 11:03:38 +10009/* Feature bits */
Rusty Russella586d4f2008-02-04 23:49:56 -050010#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
11#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
12#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
Ryan Harper48e40432008-04-16 13:56:37 -050013#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
Christian Borntraeger3ef53602008-05-16 11:17:03 +020014#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
Christian Borntraeger066f4d82008-05-29 11:08:26 +020015#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
Hannes Reinecke1cde26f2009-05-18 14:41:30 +020016#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
Christoph Hellwigf1b0ef062009-09-17 19:57:42 +020017#define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */
Christoph Hellwig69740c82010-02-24 14:22:25 -060018#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
john cooper1d589bb2009-06-09 14:41:40 +020019
john cooper4cb2ea22010-03-25 01:33:33 -040020#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
21
Rusty Russell1842f232009-07-30 16:03:46 -060022struct virtio_blk_config {
Rusty Russella586d4f2008-02-04 23:49:56 -050023 /* The capacity (in 512-byte sectors). */
Christian Borntraeger7757f092008-05-29 11:10:01 +020024 __u64 capacity;
Rusty Russella586d4f2008-02-04 23:49:56 -050025 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
Christian Borntraeger7757f092008-05-29 11:10:01 +020026 __u32 size_max;
Rusty Russella586d4f2008-02-04 23:49:56 -050027 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
Christian Borntraeger7757f092008-05-29 11:10:01 +020028 __u32 seg_max;
Ryan Harper48e40432008-04-16 13:56:37 -050029 /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
30 struct virtio_blk_geometry {
Christian Borntraeger7757f092008-05-29 11:10:01 +020031 __u16 cylinders;
Ryan Harper48e40432008-04-16 13:56:37 -050032 __u8 heads;
33 __u8 sectors;
34 } geometry;
Christoph Hellwig69740c82010-02-24 14:22:25 -060035
Christian Borntraeger066f4d82008-05-29 11:08:26 +020036 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
37 __u32 blk_size;
Christoph Hellwig69740c82010-02-24 14:22:25 -060038
39 /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */
40 /* exponent for physical block per logical block. */
41 __u8 physical_block_exp;
42 /* alignment offset in logical blocks. */
43 __u8 alignment_offset;
44 /* minimum I/O size without performance penalty in logical blocks. */
45 __u16 min_io_size;
46 /* optimal sustained I/O size in logical blocks. */
47 __u32 opt_io_size;
48
Rusty Russella586d4f2008-02-04 23:49:56 -050049} __attribute__((packed));
Rusty Russelle467cde2007-10-22 11:03:38 +100050
Christoph Hellwigf1b0ef062009-09-17 19:57:42 +020051/*
52 * Command types
53 *
54 * Usage is a bit tricky as some bits are used as flags and some are not.
55 *
56 * Rules:
57 * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
58 * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own
59 * and may not be combined with any of the other flags.
60 */
61
Rusty Russelle467cde2007-10-22 11:03:38 +100062/* These two define direction. */
63#define VIRTIO_BLK_T_IN 0
64#define VIRTIO_BLK_T_OUT 1
65
66/* This bit says it's a scsi command, not an actual read or write. */
67#define VIRTIO_BLK_T_SCSI_CMD 2
68
Christoph Hellwigf1b0ef062009-09-17 19:57:42 +020069/* Cache flush command */
70#define VIRTIO_BLK_T_FLUSH 4
71
john cooper4cb2ea22010-03-25 01:33:33 -040072/* Get device ID command */
73#define VIRTIO_BLK_T_GET_ID 8
74
Rusty Russelle467cde2007-10-22 11:03:38 +100075/* Barrier before this op. */
76#define VIRTIO_BLK_T_BARRIER 0x80000000
77
78/* This is the first element of the read scatter-gather list. */
Rusty Russell1842f232009-07-30 16:03:46 -060079struct virtio_blk_outhdr {
Rusty Russelle467cde2007-10-22 11:03:38 +100080 /* VIRTIO_BLK_T* */
81 __u32 type;
82 /* io priority. */
83 __u32 ioprio;
84 /* Sector (ie. 512 byte offset) */
85 __u64 sector;
Rusty Russelle467cde2007-10-22 11:03:38 +100086};
87
Hannes Reinecke1cde26f2009-05-18 14:41:30 +020088struct virtio_scsi_inhdr {
89 __u32 errors;
90 __u32 data_len;
91 __u32 sense_len;
92 __u32 residual;
93};
94
Rusty Russellcb38fa22008-05-02 21:50:45 -050095/* And this is the final byte of the write scatter-gather list. */
Rusty Russelle467cde2007-10-22 11:03:38 +100096#define VIRTIO_BLK_S_OK 0
97#define VIRTIO_BLK_S_IOERR 1
98#define VIRTIO_BLK_S_UNSUPP 2
Rusty Russelle467cde2007-10-22 11:03:38 +100099#endif /* _LINUX_VIRTIO_BLK_H */