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> |
Christian Borntraeger | e95646c | 2009-09-30 11:17:21 +0200 | [diff] [blame] | 6 | #include <linux/virtio_ids.h> |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 7 | #include <linux/virtio_config.h> |
| 8 | |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 9 | /* Feature bits */ |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 10 | #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 Harper | 48e4043 | 2008-04-16 13:56:37 -0500 | [diff] [blame] | 13 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ |
Christian Borntraeger | 3ef5360 | 2008-05-16 11:17:03 +0200 | [diff] [blame] | 14 | #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ |
Christian Borntraeger | 066f4d8 | 2008-05-29 11:08:26 +0200 | [diff] [blame] | 15 | #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ |
Hannes Reinecke | 1cde26f | 2009-05-18 14:41:30 +0200 | [diff] [blame] | 16 | #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ |
Christoph Hellwig | f1b0ef06 | 2009-09-17 19:57:42 +0200 | [diff] [blame] | 17 | #define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */ |
john cooper | 1d589bb | 2009-06-09 14:41:40 +0200 | [diff] [blame] | 18 | |
Rusty Russell | 1842f23 | 2009-07-30 16:03:46 -0600 | [diff] [blame] | 19 | struct virtio_blk_config { |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 20 | /* The capacity (in 512-byte sectors). */ |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 21 | __u64 capacity; |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 22 | /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 23 | __u32 size_max; |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 24 | /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 25 | __u32 seg_max; |
Ryan Harper | 48e4043 | 2008-04-16 13:56:37 -0500 | [diff] [blame] | 26 | /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ |
| 27 | struct virtio_blk_geometry { |
Christian Borntraeger | 7757f09 | 2008-05-29 11:10:01 +0200 | [diff] [blame] | 28 | __u16 cylinders; |
Ryan Harper | 48e4043 | 2008-04-16 13:56:37 -0500 | [diff] [blame] | 29 | __u8 heads; |
| 30 | __u8 sectors; |
| 31 | } geometry; |
Christian Borntraeger | 066f4d8 | 2008-05-29 11:08:26 +0200 | [diff] [blame] | 32 | /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ |
| 33 | __u32 blk_size; |
Rusty Russell | a586d4f | 2008-02-04 23:49:56 -0500 | [diff] [blame] | 34 | } __attribute__((packed)); |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 35 | |
Christoph Hellwig | f1b0ef06 | 2009-09-17 19:57:42 +0200 | [diff] [blame] | 36 | /* |
| 37 | * Command types |
| 38 | * |
| 39 | * Usage is a bit tricky as some bits are used as flags and some are not. |
| 40 | * |
| 41 | * Rules: |
| 42 | * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or |
| 43 | * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own |
| 44 | * and may not be combined with any of the other flags. |
| 45 | */ |
| 46 | |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 47 | /* These two define direction. */ |
| 48 | #define VIRTIO_BLK_T_IN 0 |
| 49 | #define VIRTIO_BLK_T_OUT 1 |
| 50 | |
| 51 | /* This bit says it's a scsi command, not an actual read or write. */ |
| 52 | #define VIRTIO_BLK_T_SCSI_CMD 2 |
| 53 | |
Christoph Hellwig | f1b0ef06 | 2009-09-17 19:57:42 +0200 | [diff] [blame] | 54 | /* Cache flush command */ |
| 55 | #define VIRTIO_BLK_T_FLUSH 4 |
| 56 | |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 57 | /* Barrier before this op. */ |
| 58 | #define VIRTIO_BLK_T_BARRIER 0x80000000 |
| 59 | |
| 60 | /* This is the first element of the read scatter-gather list. */ |
Rusty Russell | 1842f23 | 2009-07-30 16:03:46 -0600 | [diff] [blame] | 61 | struct virtio_blk_outhdr { |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 62 | /* VIRTIO_BLK_T* */ |
| 63 | __u32 type; |
| 64 | /* io priority. */ |
| 65 | __u32 ioprio; |
| 66 | /* Sector (ie. 512 byte offset) */ |
| 67 | __u64 sector; |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 68 | }; |
| 69 | |
Hannes Reinecke | 1cde26f | 2009-05-18 14:41:30 +0200 | [diff] [blame] | 70 | struct virtio_scsi_inhdr { |
| 71 | __u32 errors; |
| 72 | __u32 data_len; |
| 73 | __u32 sense_len; |
| 74 | __u32 residual; |
| 75 | }; |
| 76 | |
Rusty Russell | cb38fa2 | 2008-05-02 21:50:45 -0500 | [diff] [blame] | 77 | /* And this is the final byte of the write scatter-gather list. */ |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 78 | #define VIRTIO_BLK_S_OK 0 |
| 79 | #define VIRTIO_BLK_S_IOERR 1 |
| 80 | #define VIRTIO_BLK_S_UNSUPP 2 |
Rusty Russell | e467cde | 2007-10-22 11:03:38 +1000 | [diff] [blame] | 81 | #endif /* _LINUX_VIRTIO_BLK_H */ |