1 /* 2 * This header is BSD licensed so anyone can use the definitions to implement 3 * compatible drivers/servers. 4 * 5 * $FreeBSD$ 6 */ 7 8 #ifndef _VIRTIO_BLK_H 9 #define _VIRTIO_BLK_H 10 11 #include <sys/types.h> 12 13 /* Feature bits */ 14 #define VIRTIO_BLK_F_BARRIER 0x0001 /* Does host support barriers? */ 15 #define VIRTIO_BLK_F_SIZE_MAX 0x0002 /* Indicates maximum segment size */ 16 #define VIRTIO_BLK_F_SEG_MAX 0x0004 /* Indicates maximum # of segments */ 17 #define VIRTIO_BLK_F_GEOMETRY 0x0010 /* Legacy geometry available */ 18 #define VIRTIO_BLK_F_RO 0x0020 /* Disk is read-only */ 19 #define VIRTIO_BLK_F_BLK_SIZE 0x0040 /* Block size of disk is available*/ 20 #define VIRTIO_BLK_F_SCSI 0x0080 /* Supports scsi command passthru */ 21 #define VIRTIO_BLK_F_FLUSH 0x0200 /* Cache flush command support */ 22 #define VIRTIO_BLK_F_TOPOLOGY 0x0400 /* Topology information is available */ 23 24 #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ 25 26 struct virtio_blk_config { 27 /* The capacity (in 512-byte sectors). */ 28 uint64_t capacity; 29 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ 30 uint32_t size_max; 31 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ 32 uint32_t seg_max; 33 /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */ 34 struct virtio_blk_geometry { 35 uint16_t cylinders; 36 uint8_t heads; 37 uint8_t sectors; 38 } geometry; 39 40 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ 41 uint32_t blk_size; 42 43 /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */ 44 /* exponent for physical block per logical block. */ 45 uint8_t physical_block_exp; 46 /* alignment offset in logical blocks. */ 47 uint8_t alignment_offset; 48 /* minimum I/O size without performance penalty in logical blocks. */ 49 uint16_t min_io_size; 50 /* optimal sustained I/O size in logical blocks. */ 51 uint32_t opt_io_size; 52 } __packed; 53 54 /* 55 * Command types 56 * 57 * Usage is a bit tricky as some bits are used as flags and some are not. 58 * 59 * Rules: 60 * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or 61 * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own 62 * and may not be combined with any of the other flags. 63 */ 64 65 /* These two define direction. */ 66 #define VIRTIO_BLK_T_IN 0 67 #define VIRTIO_BLK_T_OUT 1 68 69 /* This bit says it's a scsi command, not an actual read or write. */ 70 #define VIRTIO_BLK_T_SCSI_CMD 2 71 72 /* Cache flush command */ 73 #define VIRTIO_BLK_T_FLUSH 4 74 75 /* Get device ID command */ 76 #define VIRTIO_BLK_T_GET_ID 8 77 78 /* Barrier before this op. */ 79 #define VIRTIO_BLK_T_BARRIER 0x80000000 80 81 /* ID string length */ 82 #define VIRTIO_BLK_ID_BYTES 20 83 84 /* This is the first element of the read scatter-gather list. */ 85 struct virtio_blk_outhdr { 86 /* VIRTIO_BLK_T* */ 87 uint32_t type; 88 /* io priority. */ 89 uint32_t ioprio; 90 /* Sector (ie. 512 byte offset) */ 91 uint64_t sector; 92 }; 93 94 struct virtio_scsi_inhdr { 95 uint32_t errors; 96 uint32_t data_len; 97 uint32_t sense_len; 98 uint32_t residual; 99 }; 100 101 /* And this is the final byte of the write scatter-gather list. */ 102 #define VIRTIO_BLK_S_OK 0 103 #define VIRTIO_BLK_S_IOERR 1 104 #define VIRTIO_BLK_S_UNSUPP 2 105 106 #endif /* _VIRTIO_BLK_H */ 107