Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 1 | #ifndef _LINUX_VIRTIO_BLK_H |
| 2 | #define _LINUX_VIRTIO_BLK_H |
Rusty Russell | 674bfc2 | 2008-07-25 12:06:03 -0500 | [diff] [blame] | 3 | /* This header is BSD licensed so anyone can use the definitions to implement |
| 4 | * compatible drivers/servers. */ |
Jaswinder Singh Rajput | 982f818 | 2009-01-30 22:27:58 +0530 | [diff] [blame] | 5 | #include <linux/types.h> |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 6 | #include <linux/virtio_config.h> |
| 7 | |
| 8 | /* The ID for virtio_block */ |
| 9 | #define VIRTIO_ID_BLOCK 2 |
| 10 | |
| 11 | /* Feature bits */ |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 12 | #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 Harper | 48e4043 | 2008-04-16 13:56:37 -0500 | [diff] [blame] | 15 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ |
Christian Borntraeger | 3ef5360 | 2008-05-16 11:17:03 +0200 | [diff] [blame] | 16 | #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ |
Christian Borntraeger | 066f4d8 | 2008-05-29 11:08:26 +0200 | [diff] [blame] | 17 | #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 18 | |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 19 | struct virtio_blk_config |
| 20 | { |
| 21 | /* The capacity (in 512-byte sectors). */ |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 22 | __u64 capacity; |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 23 | /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 24 | __u32 size_max; |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 25 | /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 26 | __u32 seg_max; |
Ryan Harper | 48e4043 | 2008-04-16 13:56:37 -0500 | [diff] [blame] | 27 | /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ |
| 28 | struct virtio_blk_geometry { |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 29 | __u16 cylinders; |
Ryan Harper | 48e4043 | 2008-04-16 13:56:37 -0500 | [diff] [blame] | 30 | __u8 heads; |
| 31 | __u8 sectors; |
| 32 | } geometry; |
Christian Borntraeger | 066f4d8 | 2008-05-29 11:08:26 +0200 | [diff] [blame] | 33 | /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ |
| 34 | __u32 blk_size; |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 35 | } __attribute__((packed)); |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 36 | |
| 37 | /* These two define direction. */ |
| 38 | #define VIRTIO_BLK_T_IN 0 |
| 39 | #define VIRTIO_BLK_T_OUT 1 |
| 40 | |
| 41 | /* This bit says it's a scsi command, not an actual read or write. */ |
| 42 | #define VIRTIO_BLK_T_SCSI_CMD 2 |
| 43 | |
| 44 | /* Barrier before this op. */ |
| 45 | #define VIRTIO_BLK_T_BARRIER 0x80000000 |
| 46 | |
| 47 | /* This is the first element of the read scatter-gather list. */ |
| 48 | struct virtio_blk_outhdr |
| 49 | { |
| 50 | /* VIRTIO_BLK_T* */ |
| 51 | __u32 type; |
| 52 | /* io priority. */ |
| 53 | __u32 ioprio; |
| 54 | /* Sector (ie. 512 byte offset) */ |
| 55 | __u64 sector; |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 56 | }; |
| 57 | |
Rusty Russell | cb38fa2 | 2008-05-02 21:50:45 -0500 | [diff] [blame] | 58 | /* And this is the final byte of the write scatter-gather list. */ |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 59 | #define VIRTIO_BLK_S_OK 0 |
| 60 | #define VIRTIO_BLK_S_IOERR 1 |
| 61 | #define VIRTIO_BLK_S_UNSUPP 2 |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 62 | #endif /* _LINUX_VIRTIO_BLK_H */ |