1228301Sgrehan/*- 2227652Sgrehan * This header is BSD licensed so anyone can use the definitions to implement 3227652Sgrehan * compatible drivers/servers. 4227652Sgrehan * 5228301Sgrehan * Redistribution and use in source and binary forms, with or without 6228301Sgrehan * modification, are permitted provided that the following conditions 7228301Sgrehan * are met: 8228301Sgrehan * 1. Redistributions of source code must retain the above copyright 9228301Sgrehan * notice, this list of conditions and the following disclaimer. 10228301Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 11228301Sgrehan * notice, this list of conditions and the following disclaimer in the 12228301Sgrehan * documentation and/or other materials provided with the distribution. 13228301Sgrehan * 3. Neither the name of IBM nor the names of its contributors 14228301Sgrehan * may be used to endorse or promote products derived from this software 15228301Sgrehan * without specific prior written permission. 16228301Sgrehan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17228301Sgrehan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18228301Sgrehan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19228301Sgrehan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 20228301Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21228301Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22228301Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23228301Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24228301Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25228301Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26228301Sgrehan * SUCH DAMAGE. 27228301Sgrehan * 28227652Sgrehan * $FreeBSD: releng/11.0/sys/dev/virtio/block/virtio_blk.h 279651 2015-03-05 10:29:46Z mav $ 29227652Sgrehan */ 30227652Sgrehan 31227652Sgrehan#ifndef _VIRTIO_BLK_H 32227652Sgrehan#define _VIRTIO_BLK_H 33227652Sgrehan 34227652Sgrehan/* Feature bits */ 35227652Sgrehan#define VIRTIO_BLK_F_BARRIER 0x0001 /* Does host support barriers? */ 36227652Sgrehan#define VIRTIO_BLK_F_SIZE_MAX 0x0002 /* Indicates maximum segment size */ 37227652Sgrehan#define VIRTIO_BLK_F_SEG_MAX 0x0004 /* Indicates maximum # of segments */ 38227652Sgrehan#define VIRTIO_BLK_F_GEOMETRY 0x0010 /* Legacy geometry available */ 39227652Sgrehan#define VIRTIO_BLK_F_RO 0x0020 /* Disk is read-only */ 40227652Sgrehan#define VIRTIO_BLK_F_BLK_SIZE 0x0040 /* Block size of disk is available*/ 41227652Sgrehan#define VIRTIO_BLK_F_SCSI 0x0080 /* Supports scsi command passthru */ 42252703Sbryanv#define VIRTIO_BLK_F_WCE 0x0200 /* Writeback mode enabled after reset */ 43227652Sgrehan#define VIRTIO_BLK_F_TOPOLOGY 0x0400 /* Topology information is available */ 44252703Sbryanv#define VIRTIO_BLK_F_CONFIG_WCE 0x0800 /* Writeback mode available in config */ 45227652Sgrehan 46227652Sgrehan#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ 47227652Sgrehan 48227652Sgrehanstruct virtio_blk_config { 49227652Sgrehan /* The capacity (in 512-byte sectors). */ 50227652Sgrehan uint64_t capacity; 51227652Sgrehan /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ 52227652Sgrehan uint32_t size_max; 53227652Sgrehan /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ 54227652Sgrehan uint32_t seg_max; 55252703Sbryanv /* Geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */ 56227652Sgrehan struct virtio_blk_geometry { 57227652Sgrehan uint16_t cylinders; 58227652Sgrehan uint8_t heads; 59227652Sgrehan uint8_t sectors; 60227652Sgrehan } geometry; 61227652Sgrehan 62252703Sbryanv /* Block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ 63227652Sgrehan uint32_t blk_size; 64252703Sbryanv 65252703Sbryanv /* Topology of the device (if VIRTIO_BLK_F_TOPOLOGY) */ 66252703Sbryanv struct virtio_blk_topology { 67252703Sbryanv uint8_t physical_block_exp; 68252703Sbryanv uint8_t alignment_offset; 69252703Sbryanv uint16_t min_io_size; 70279651Smav uint32_t opt_io_size; 71252703Sbryanv } topology; 72252703Sbryanv 73252703Sbryanv /* Writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */ 74252703Sbryanv uint8_t writeback; 75252703Sbryanv 76227652Sgrehan} __packed; 77227652Sgrehan 78227652Sgrehan/* 79227652Sgrehan * Command types 80227652Sgrehan * 81227652Sgrehan * Usage is a bit tricky as some bits are used as flags and some are not. 82227652Sgrehan * 83227652Sgrehan * Rules: 84227652Sgrehan * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or 85227652Sgrehan * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own 86227652Sgrehan * and may not be combined with any of the other flags. 87227652Sgrehan */ 88227652Sgrehan 89227652Sgrehan/* These two define direction. */ 90227652Sgrehan#define VIRTIO_BLK_T_IN 0 91227652Sgrehan#define VIRTIO_BLK_T_OUT 1 92227652Sgrehan 93227652Sgrehan/* This bit says it's a scsi command, not an actual read or write. */ 94227652Sgrehan#define VIRTIO_BLK_T_SCSI_CMD 2 95227652Sgrehan 96227652Sgrehan/* Cache flush command */ 97227652Sgrehan#define VIRTIO_BLK_T_FLUSH 4 98227652Sgrehan 99227652Sgrehan/* Get device ID command */ 100227652Sgrehan#define VIRTIO_BLK_T_GET_ID 8 101227652Sgrehan 102227652Sgrehan/* Barrier before this op. */ 103227652Sgrehan#define VIRTIO_BLK_T_BARRIER 0x80000000 104227652Sgrehan 105227652Sgrehan/* ID string length */ 106227652Sgrehan#define VIRTIO_BLK_ID_BYTES 20 107227652Sgrehan 108227652Sgrehan/* This is the first element of the read scatter-gather list. */ 109227652Sgrehanstruct virtio_blk_outhdr { 110227652Sgrehan /* VIRTIO_BLK_T* */ 111227652Sgrehan uint32_t type; 112227652Sgrehan /* io priority. */ 113227652Sgrehan uint32_t ioprio; 114227652Sgrehan /* Sector (ie. 512 byte offset) */ 115227652Sgrehan uint64_t sector; 116227652Sgrehan}; 117227652Sgrehan 118227652Sgrehanstruct virtio_scsi_inhdr { 119227652Sgrehan uint32_t errors; 120227652Sgrehan uint32_t data_len; 121227652Sgrehan uint32_t sense_len; 122227652Sgrehan uint32_t residual; 123227652Sgrehan}; 124227652Sgrehan 125227652Sgrehan/* And this is the final byte of the write scatter-gather list. */ 126227652Sgrehan#define VIRTIO_BLK_S_OK 0 127227652Sgrehan#define VIRTIO_BLK_S_IOERR 1 128227652Sgrehan#define VIRTIO_BLK_S_UNSUPP 2 129227652Sgrehan 130227652Sgrehan#endif /* _VIRTIO_BLK_H */ 131