16bbf9c9dSJérôme Duval /*- 26bbf9c9dSJérôme Duval * This header is BSD licensed so anyone can use the definitions to implement 36bbf9c9dSJérôme Duval * compatible drivers/servers. 46bbf9c9dSJérôme Duval * 56bbf9c9dSJérôme Duval * Redistribution and use in source and binary forms, with or without 66bbf9c9dSJérôme Duval * modification, are permitted provided that the following conditions 76bbf9c9dSJérôme Duval * are met: 86bbf9c9dSJérôme Duval * 1. Redistributions of source code must retain the above copyright 96bbf9c9dSJérôme Duval * notice, this list of conditions and the following disclaimer. 106bbf9c9dSJérôme Duval * 2. Redistributions in binary form must reproduce the above copyright 116bbf9c9dSJérôme Duval * notice, this list of conditions and the following disclaimer in the 126bbf9c9dSJérôme Duval * documentation and/or other materials provided with the distribution. 136bbf9c9dSJérôme Duval * 3. Neither the name of IBM nor the names of its contributors 146bbf9c9dSJérôme Duval * may be used to endorse or promote products derived from this software 156bbf9c9dSJérôme Duval * without specific prior written permission. 166bbf9c9dSJérôme Duval * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176bbf9c9dSJérôme Duval * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 186bbf9c9dSJérôme Duval * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 196bbf9c9dSJérôme Duval * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 206bbf9c9dSJérôme Duval * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 216bbf9c9dSJérôme Duval * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 226bbf9c9dSJérôme Duval * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 236bbf9c9dSJérôme Duval * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 246bbf9c9dSJérôme Duval * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 256bbf9c9dSJérôme Duval * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 266bbf9c9dSJérôme Duval * SUCH DAMAGE. 276bbf9c9dSJérôme Duval * 286bbf9c9dSJérôme Duval * $FreeBSD$ 296bbf9c9dSJérôme Duval */ 306bbf9c9dSJérôme Duval 316bbf9c9dSJérôme Duval #ifndef _VIRTIO_BLK_H 326bbf9c9dSJérôme Duval #define _VIRTIO_BLK_H 336bbf9c9dSJérôme Duval 346bbf9c9dSJérôme Duval /* Feature bits */ 356bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_BARRIER 0x0001 /* Does host support barriers? */ 366bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_SIZE_MAX 0x0002 /* Indicates maximum segment size */ 376bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_SEG_MAX 0x0004 /* Indicates maximum # of segments */ 386bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_GEOMETRY 0x0010 /* Legacy geometry available */ 396bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_RO 0x0020 /* Disk is read-only */ 406bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_BLK_SIZE 0x0040 /* Block size of disk is available*/ 416bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_SCSI 0x0080 /* Supports scsi command passthru */ 42*ca6d474aSJérôme Duval #define VIRTIO_BLK_F_FLUSH 0x0200 /* Flush command supported */ 436bbf9c9dSJérôme Duval #define VIRTIO_BLK_F_TOPOLOGY 0x0400 /* Topology information is available */ 44*ca6d474aSJérôme Duval #define VIRTIO_BLK_F_CONFIG_WCE 0x0800 /* Writeback mode available in config */ 456bbf9c9dSJérôme Duval 466bbf9c9dSJérôme Duval #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ 476bbf9c9dSJérôme Duval 486bbf9c9dSJérôme Duval struct virtio_blk_config { 496bbf9c9dSJérôme Duval /* The capacity (in 512-byte sectors). */ 506bbf9c9dSJérôme Duval uint64_t capacity; 516bbf9c9dSJérôme Duval /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ 526bbf9c9dSJérôme Duval uint32_t size_max; 536bbf9c9dSJérôme Duval /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ 546bbf9c9dSJérôme Duval uint32_t seg_max; 55*ca6d474aSJérôme Duval /* Geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */ 566bbf9c9dSJérôme Duval struct virtio_blk_geometry { 576bbf9c9dSJérôme Duval uint16_t cylinders; 586bbf9c9dSJérôme Duval uint8_t heads; 596bbf9c9dSJérôme Duval uint8_t sectors; 606bbf9c9dSJérôme Duval } geometry; 616bbf9c9dSJérôme Duval 62*ca6d474aSJérôme Duval /* Block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ 636bbf9c9dSJérôme Duval uint32_t blk_size; 64*ca6d474aSJérôme Duval 65*ca6d474aSJérôme Duval /* Topology of the device (if VIRTIO_BLK_F_TOPOLOGY) */ 66*ca6d474aSJérôme Duval struct virtio_blk_topology { 67*ca6d474aSJérôme Duval uint8_t physical_block_exp; 68*ca6d474aSJérôme Duval uint8_t alignment_offset; 69*ca6d474aSJérôme Duval uint16_t min_io_size; 70*ca6d474aSJérôme Duval uint32_t opt_io_size; 71*ca6d474aSJérôme Duval } topology; 72*ca6d474aSJérôme Duval 73*ca6d474aSJérôme Duval /* Writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */ 74*ca6d474aSJérôme Duval uint8_t writeback; 75*ca6d474aSJérôme Duval 76*ca6d474aSJérôme Duval } __packed; 776bbf9c9dSJérôme Duval 786bbf9c9dSJérôme Duval /* 796bbf9c9dSJérôme Duval * Command types 806bbf9c9dSJérôme Duval * 816bbf9c9dSJérôme Duval * Usage is a bit tricky as some bits are used as flags and some are not. 826bbf9c9dSJérôme Duval * 836bbf9c9dSJérôme Duval * Rules: 846bbf9c9dSJérôme Duval * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or 856bbf9c9dSJérôme Duval * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own 866bbf9c9dSJérôme Duval * and may not be combined with any of the other flags. 876bbf9c9dSJérôme Duval */ 886bbf9c9dSJérôme Duval 896bbf9c9dSJérôme Duval /* These two define direction. */ 906bbf9c9dSJérôme Duval #define VIRTIO_BLK_T_IN 0 916bbf9c9dSJérôme Duval #define VIRTIO_BLK_T_OUT 1 926bbf9c9dSJérôme Duval 936bbf9c9dSJérôme Duval /* This bit says it's a scsi command, not an actual read or write. */ 946bbf9c9dSJérôme Duval #define VIRTIO_BLK_T_SCSI_CMD 2 956bbf9c9dSJérôme Duval 966bbf9c9dSJérôme Duval /* Cache flush command */ 976bbf9c9dSJérôme Duval #define VIRTIO_BLK_T_FLUSH 4 986bbf9c9dSJérôme Duval 996bbf9c9dSJérôme Duval /* Get device ID command */ 1006bbf9c9dSJérôme Duval #define VIRTIO_BLK_T_GET_ID 8 1016bbf9c9dSJérôme Duval 1026bbf9c9dSJérôme Duval /* Barrier before this op. */ 1036bbf9c9dSJérôme Duval #define VIRTIO_BLK_T_BARRIER 0x80000000 1046bbf9c9dSJérôme Duval 1056bbf9c9dSJérôme Duval /* ID string length */ 1066bbf9c9dSJérôme Duval #define VIRTIO_BLK_ID_BYTES 20 1076bbf9c9dSJérôme Duval 1086bbf9c9dSJérôme Duval /* This is the first element of the read scatter-gather list. */ 1096bbf9c9dSJérôme Duval struct virtio_blk_outhdr { 1106bbf9c9dSJérôme Duval /* VIRTIO_BLK_T* */ 1116bbf9c9dSJérôme Duval uint32_t type; 1126bbf9c9dSJérôme Duval /* io priority. */ 1136bbf9c9dSJérôme Duval uint32_t ioprio; 1146bbf9c9dSJérôme Duval /* Sector (ie. 512 byte offset) */ 1156bbf9c9dSJérôme Duval uint64_t sector; 1166bbf9c9dSJérôme Duval }; 1176bbf9c9dSJérôme Duval 1186bbf9c9dSJérôme Duval struct virtio_scsi_inhdr { 1196bbf9c9dSJérôme Duval uint32_t errors; 1206bbf9c9dSJérôme Duval uint32_t data_len; 1216bbf9c9dSJérôme Duval uint32_t sense_len; 1226bbf9c9dSJérôme Duval uint32_t residual; 1236bbf9c9dSJérôme Duval }; 1246bbf9c9dSJérôme Duval 1256bbf9c9dSJérôme Duval /* And this is the final byte of the write scatter-gather list. */ 1266bbf9c9dSJérôme Duval #define VIRTIO_BLK_S_OK 0 1276bbf9c9dSJérôme Duval #define VIRTIO_BLK_S_IOERR 1 1286bbf9c9dSJérôme Duval #define VIRTIO_BLK_S_UNSUPP 2 1296bbf9c9dSJérôme Duval 1306bbf9c9dSJérôme Duval #endif /* _VIRTIO_BLK_H */ 131