blob: 8dab9f2b8832db74569f668a70edfd853274414c [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>
Rusty Russelle467cde2007-10-22 11:03:38 +10006#include <linux/virtio_config.h>
7
8/* The ID for virtio_block */
9#define VIRTIO_ID_BLOCK 2
10
11/* Feature bits */
Rusty Russella586d4f2008-02-04 23:49:56 -050012#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
13#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
14#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
Ryan Harper48e40432008-04-16 13:56:37 -050015#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
Christian Borntraeger3ef53602008-05-16 11:17:03 +020016#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
Christian Borntraeger066f4d82008-05-29 11:08:26 +020017#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
Hannes Reinecke1cde26f2009-05-18 14:41:30 +020018#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
john cooper1d589bb2009-06-09 14:41:40 +020019#define VIRTIO_BLK_F_IDENTIFY 8 /* ATA IDENTIFY supported */
20
21#define VIRTIO_BLK_ID_BYTES (sizeof(__u16[256])) /* IDENTIFY DATA */
Rusty Russelle467cde2007-10-22 11:03:38 +100022
Rusty Russell1842f232009-07-30 16:03:46 -060023struct virtio_blk_config {
Rusty Russella586d4f2008-02-04 23:49:56 -050024 /* The capacity (in 512-byte sectors). */
Christian Borntraeger7757f092008-05-29 11:10:01 +020025 __u64 capacity;
Rusty Russella586d4f2008-02-04 23:49:56 -050026 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
Christian Borntraeger7757f092008-05-29 11:10:01 +020027 __u32 size_max;
Rusty Russella586d4f2008-02-04 23:49:56 -050028 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
Christian Borntraeger7757f092008-05-29 11:10:01 +020029 __u32 seg_max;
Ryan Harper48e40432008-04-16 13:56:37 -050030 /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
31 struct virtio_blk_geometry {
Christian Borntraeger7757f092008-05-29 11:10:01 +020032 __u16 cylinders;
Ryan Harper48e40432008-04-16 13:56:37 -050033 __u8 heads;
34 __u8 sectors;
35 } geometry;
Christian Borntraeger066f4d82008-05-29 11:08:26 +020036 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
37 __u32 blk_size;
john cooper1d589bb2009-06-09 14:41:40 +020038 __u8 identify[VIRTIO_BLK_ID_BYTES];
Rusty Russella586d4f2008-02-04 23:49:56 -050039} __attribute__((packed));
Rusty Russelle467cde2007-10-22 11:03:38 +100040
41/* These two define direction. */
42#define VIRTIO_BLK_T_IN 0
43#define VIRTIO_BLK_T_OUT 1
44
45/* This bit says it's a scsi command, not an actual read or write. */
46#define VIRTIO_BLK_T_SCSI_CMD 2
47
48/* Barrier before this op. */
49#define VIRTIO_BLK_T_BARRIER 0x80000000
50
51/* This is the first element of the read scatter-gather list. */
Rusty Russell1842f232009-07-30 16:03:46 -060052struct virtio_blk_outhdr {
Rusty Russelle467cde2007-10-22 11:03:38 +100053 /* VIRTIO_BLK_T* */
54 __u32 type;
55 /* io priority. */
56 __u32 ioprio;
57 /* Sector (ie. 512 byte offset) */
58 __u64 sector;
Rusty Russelle467cde2007-10-22 11:03:38 +100059};
60
Hannes Reinecke1cde26f2009-05-18 14:41:30 +020061struct virtio_scsi_inhdr {
62 __u32 errors;
63 __u32 data_len;
64 __u32 sense_len;
65 __u32 residual;
66};
67
Rusty Russellcb38fa22008-05-02 21:50:45 -050068/* And this is the final byte of the write scatter-gather list. */
Rusty Russelle467cde2007-10-22 11:03:38 +100069#define VIRTIO_BLK_S_OK 0
70#define VIRTIO_BLK_S_IOERR 1
71#define VIRTIO_BLK_S_UNSUPP 2
Rusty Russelle467cde2007-10-22 11:03:38 +100072#endif /* _LINUX_VIRTIO_BLK_H */