Dr Andrew Scott G7VAV

My photo
 
June 2025
Mo Tu We Th Fr Sa Su
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6


virtio_blk.h
001: #ifndef _LINUX_VIRTIO_BLK_H
002: #define _LINUX_VIRTIO_BLK_H
003: /* This header is BSD licensed so anyone can use the definitions to implement
004:  * compatible drivers/servers.
005:  *
006:  * Redistribution and use in source and binary forms, with or without
007:  * modification, are permitted provided that the following conditions
008:  * are met:
009:  * 1. Redistributions of source code must retain the above copyright
010:  *    notice, this list of conditions and the following disclaimer.
011:  * 2. Redistributions in binary form must reproduce the above copyright
012:  *    notice, this list of conditions and the following disclaimer in the
013:  *    documentation and/or other materials provided with the distribution.
014:  * 3. Neither the name of IBM nor the names of its contributors
015:  *    may be used to endorse or promote products derived from this software
016:  *    without specific prior written permission.
017:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
018:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
020:  * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
021:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
022:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
023:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
024:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
025:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
026:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
027:  * SUCH DAMAGE. */
028: #include <linux/types.h>
029: #include <linux/virtio_ids.h>
030: #include <linux/virtio_config.h>
031: 
032: /* Feature bits */
033: #define VIRTIO_BLK_F_BARRIER    0       /* Does host support barriers? */
034: #define VIRTIO_BLK_F_SIZE_MAX   1       /* Indicates maximum segment size */
035: #define VIRTIO_BLK_F_SEG_MAX    2       /* Indicates maximum # of segments */
036: #define VIRTIO_BLK_F_GEOMETRY   4       /* Legacy geometry available  */
037: #define VIRTIO_BLK_F_RO         5       /* Disk is read-only */
038: #define VIRTIO_BLK_F_BLK_SIZE   6       /* Block size of disk is available*/
039: #define VIRTIO_BLK_F_SCSI       7       /* Supports scsi command passthru */
040: #define VIRTIO_BLK_F_FLUSH      9       /* Cache flush command support */
041: #define VIRTIO_BLK_F_TOPOLOGY   10      /* Topology information is available */
042: 
043: #define VIRTIO_BLK_ID_BYTES     20      /* ID string length */
044: 
045: struct virtio_blk_config {
046:         /* The capacity (in 512-byte sectors). */
047:         __u64 capacity;
048:         /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
049:         __u32 size_max;
050:         /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
051:         __u32 seg_max;
052:         /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
053:         struct virtio_blk_geometry {
054:                 __u16 cylinders;
055:                 __u8 heads;
056:                 __u8 sectors;
057:         } geometry;
058: 
059:         /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
060:         __u32 blk_size;
061: 
062:         /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY  */
063:         /* exponent for physical block per logical block. */
064:         __u8 physical_block_exp;
065:         /* alignment offset in logical blocks. */
066:         __u8 alignment_offset;
067:         /* minimum I/O size without performance penalty in logical blocks. */
068:         __u16 min_io_size;
069:         /* optimal sustained I/O size in logical blocks. */
070:         __u32 opt_io_size;
071: 
072: } __attribute__((packed));
073: 
074: /*
075:  * Command types
076:  *
077:  * Usage is a bit tricky as some bits are used as flags and some are not.
078:  *
079:  * Rules:
080:  *   VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
081:  *   VIRTIO_BLK_T_BARRIER.  VIRTIO_BLK_T_FLUSH is a command of its own
082:  *   and may not be combined with any of the other flags.
083:  */
084: 
085: /* These two define direction. */
086: #define VIRTIO_BLK_T_IN         0
087: #define VIRTIO_BLK_T_OUT        1
088: 
089: /* This bit says it's a scsi command, not an actual read or write. */
090: #define VIRTIO_BLK_T_SCSI_CMD   2
091: 
092: /* Cache flush command */
093: #define VIRTIO_BLK_T_FLUSH      4
094: 
095: /* Get device ID command */
096: #define VIRTIO_BLK_T_GET_ID    8
097: 
098: /* Barrier before this op. */
099: #define VIRTIO_BLK_T_BARRIER    0x80000000
100: 
101: /* This is the first element of the read scatter-gather list. */
102: struct virtio_blk_outhdr {
103:         /* VIRTIO_BLK_T* */
104:         __u32 type;
105:         /* io priority. */
106:         __u32 ioprio;
107:         /* Sector (ie. 512 byte offset) */
108:         __u64 sector;
109: };
110: 
111: struct virtio_scsi_inhdr {
112:         __u32 errors;
113:         __u32 data_len;
114:         __u32 sense_len;
115:         __u32 residual;
116: };
117: 
118: /* And this is the final byte of the write scatter-gather list. */
119: #define VIRTIO_BLK_S_OK         0
120: #define VIRTIO_BLK_S_IOERR      1
121: #define VIRTIO_BLK_S_UNSUPP     2
122: #endif /* _LINUX_VIRTIO_BLK_H */
123: 


for client (none)
© Andrew Scott 2006 - 2025,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/