Commit | Line | Data |
---|---|---|
e467cde2 RR |
1 | #ifndef _LINUX_VIRTIO_BLK_H |
2 | #define _LINUX_VIRTIO_BLK_H | |
674bfc23 RR |
3 | /* This header is BSD licensed so anyone can use the definitions to implement |
4 | * compatible drivers/servers. */ | |
982f8184 | 5 | #include <linux/types.h> |
e95646c3 | 6 | #include <linux/virtio_ids.h> |
e467cde2 RR |
7 | #include <linux/virtio_config.h> |
8 | ||
e467cde2 | 9 | /* Feature bits */ |
a586d4f6 RR |
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 */ | |
48e4043d | 13 | #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ |
3ef53609 | 14 | #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ |
066f4d82 | 15 | #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ |
1cde26f9 | 16 | #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ |
f1b0ef06 | 17 | #define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */ |
1d589bb1 | 18 | |
1842f23c | 19 | struct virtio_blk_config { |
a586d4f6 | 20 | /* The capacity (in 512-byte sectors). */ |
7757f09c | 21 | __u64 capacity; |
a586d4f6 | 22 | /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ |
7757f09c | 23 | __u32 size_max; |
a586d4f6 | 24 | /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ |
7757f09c | 25 | __u32 seg_max; |
48e4043d RH |
26 | /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ |
27 | struct virtio_blk_geometry { | |
7757f09c | 28 | __u16 cylinders; |
48e4043d RH |
29 | __u8 heads; |
30 | __u8 sectors; | |
31 | } geometry; | |
066f4d82 CB |
32 | /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ |
33 | __u32 blk_size; | |
a586d4f6 | 34 | } __attribute__((packed)); |
e467cde2 | 35 | |
f1b0ef06 CH |
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 | ||
e467cde2 RR |
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 | ||
f1b0ef06 CH |
54 | /* Cache flush command */ |
55 | #define VIRTIO_BLK_T_FLUSH 4 | |
56 | ||
e467cde2 RR |
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. */ | |
1842f23c | 61 | struct virtio_blk_outhdr { |
e467cde2 RR |
62 | /* VIRTIO_BLK_T* */ |
63 | __u32 type; | |
64 | /* io priority. */ | |
65 | __u32 ioprio; | |
66 | /* Sector (ie. 512 byte offset) */ | |
67 | __u64 sector; | |
e467cde2 RR |
68 | }; |
69 | ||
1cde26f9 HR |
70 | struct virtio_scsi_inhdr { |
71 | __u32 errors; | |
72 | __u32 data_len; | |
73 | __u32 sense_len; | |
74 | __u32 residual; | |
75 | }; | |
76 | ||
cb38fa23 | 77 | /* And this is the final byte of the write scatter-gather list. */ |
e467cde2 RR |
78 | #define VIRTIO_BLK_S_OK 0 |
79 | #define VIRTIO_BLK_S_IOERR 1 | |
80 | #define VIRTIO_BLK_S_UNSUPP 2 | |
e467cde2 | 81 | #endif /* _LINUX_VIRTIO_BLK_H */ |