![]() |
|
|||
0001 #ifndef _LINUX_VIRTIO_BLK_H 0002 #define _LINUX_VIRTIO_BLK_H 0003 /* This header is BSD licensed so anyone can use the definitions to implement 0004 * compatible drivers/servers. 0005 * 0006 * Redistribution and use in source and binary forms, with or without 0007 * modification, are permitted provided that the following conditions 0008 * are met: 0009 * 1. Redistributions of source code must retain the above copyright 0010 * notice, this list of conditions and the following disclaimer. 0011 * 2. Redistributions in binary form must reproduce the above copyright 0012 * notice, this list of conditions and the following disclaimer in the 0013 * documentation and/or other materials provided with the distribution. 0014 * 3. Neither the name of IBM nor the names of its contributors 0015 * may be used to endorse or promote products derived from this software 0016 * without specific prior written permission. 0017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 0018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0020 * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 0021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 0022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 0023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 0024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 0025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 0026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 0027 * SUCH DAMAGE. */ 0028 #include <linux/types.h> 0029 #include <linux/virtio_ids.h> 0030 #include <linux/virtio_config.h> 0031 #include <linux/virtio_types.h> 0032 0033 /* Feature bits */ 0034 #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ 0035 #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ 0036 #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ 0037 #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ 0038 #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ 0039 #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */ 0040 #define VIRTIO_BLK_F_MQ 12 /* support more than one vq */ 0041 #define VIRTIO_BLK_F_DISCARD 13 /* DISCARD is supported */ 0042 #define VIRTIO_BLK_F_WRITE_ZEROES 14 /* WRITE ZEROES is supported */ 0043 0044 /* Legacy feature bits */ 0045 #ifndef VIRTIO_BLK_NO_LEGACY 0046 #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */ 0047 #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */ 0048 #define VIRTIO_BLK_F_FLUSH 9 /* Flush command supported */ 0049 #define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */ 0050 #ifndef __KERNEL__ 0051 /* Old (deprecated) name for VIRTIO_BLK_F_FLUSH. */ 0052 #define VIRTIO_BLK_F_WCE VIRTIO_BLK_F_FLUSH 0053 #endif 0054 #endif /* !VIRTIO_BLK_NO_LEGACY */ 0055 0056 #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ 0057 0058 struct virtio_blk_config { 0059 /* The capacity (in 512-byte sectors). */ 0060 __virtio64 capacity; 0061 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */ 0062 __virtio32 size_max; 0063 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */ 0064 __virtio32 seg_max; 0065 /* geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */ 0066 struct virtio_blk_geometry { 0067 __virtio16 cylinders; 0068 __u8 heads; 0069 __u8 sectors; 0070 } geometry; 0071 0072 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ 0073 __virtio32 blk_size; 0074 0075 /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */ 0076 /* exponent for physical block per logical block. */ 0077 __u8 physical_block_exp; 0078 /* alignment offset in logical blocks. */ 0079 __u8 alignment_offset; 0080 /* minimum I/O size without performance penalty in logical blocks. */ 0081 __virtio16 min_io_size; 0082 /* optimal sustained I/O size in logical blocks. */ 0083 __virtio32 opt_io_size; 0084 0085 /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */ 0086 __u8 wce; 0087 __u8 unused; 0088 0089 /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */ 0090 __virtio16 num_queues; 0091 0092 /* the next 3 entries are guarded by VIRTIO_BLK_F_DISCARD */ 0093 /* 0094 * The maximum discard sectors (in 512-byte sectors) for 0095 * one segment. 0096 */ 0097 __virtio32 max_discard_sectors; 0098 /* 0099 * The maximum number of discard segments in a 0100 * discard command. 0101 */ 0102 __virtio32 max_discard_seg; 0103 /* Discard commands must be aligned to this number of sectors. */ 0104 __virtio32 discard_sector_alignment; 0105 0106 /* the next 3 entries are guarded by VIRTIO_BLK_F_WRITE_ZEROES */ 0107 /* 0108 * The maximum number of write zeroes sectors (in 512-byte sectors) in 0109 * one segment. 0110 */ 0111 __virtio32 max_write_zeroes_sectors; 0112 /* 0113 * The maximum number of segments in a write zeroes 0114 * command. 0115 */ 0116 __virtio32 max_write_zeroes_seg; 0117 /* 0118 * Set if a VIRTIO_BLK_T_WRITE_ZEROES request may result in the 0119 * deallocation of one or more of the sectors. 0120 */ 0121 __u8 write_zeroes_may_unmap; 0122 0123 __u8 unused1[3]; 0124 } __attribute__((packed)); 0125 0126 /* 0127 * Command types 0128 * 0129 * Usage is a bit tricky as some bits are used as flags and some are not. 0130 * 0131 * Rules: 0132 * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or 0133 * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own 0134 * and may not be combined with any of the other flags. 0135 */ 0136 0137 /* These two define direction. */ 0138 #define VIRTIO_BLK_T_IN 0 0139 #define VIRTIO_BLK_T_OUT 1 0140 0141 #ifndef VIRTIO_BLK_NO_LEGACY 0142 /* This bit says it's a scsi command, not an actual read or write. */ 0143 #define VIRTIO_BLK_T_SCSI_CMD 2 0144 #endif /* VIRTIO_BLK_NO_LEGACY */ 0145 0146 /* Cache flush command */ 0147 #define VIRTIO_BLK_T_FLUSH 4 0148 0149 /* Get device ID command */ 0150 #define VIRTIO_BLK_T_GET_ID 8 0151 0152 /* Discard command */ 0153 #define VIRTIO_BLK_T_DISCARD 11 0154 0155 /* Write zeroes command */ 0156 #define VIRTIO_BLK_T_WRITE_ZEROES 13 0157 0158 #ifndef VIRTIO_BLK_NO_LEGACY 0159 /* Barrier before this op. */ 0160 #define VIRTIO_BLK_T_BARRIER 0x80000000 0161 #endif /* !VIRTIO_BLK_NO_LEGACY */ 0162 0163 /* 0164 * This comes first in the read scatter-gather list. 0165 * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, 0166 * this is the first element of the read scatter-gather list. 0167 */ 0168 struct virtio_blk_outhdr { 0169 /* VIRTIO_BLK_T* */ 0170 __virtio32 type; 0171 /* io priority. */ 0172 __virtio32 ioprio; 0173 /* Sector (ie. 512 byte offset) */ 0174 __virtio64 sector; 0175 }; 0176 0177 /* Unmap this range (only valid for write zeroes command) */ 0178 #define VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP 0x00000001 0179 0180 /* Discard/write zeroes range for each request. */ 0181 struct virtio_blk_discard_write_zeroes { 0182 /* discard/write zeroes start sector */ 0183 __le64 sector; 0184 /* number of discard/write zeroes sectors */ 0185 __le32 num_sectors; 0186 /* flags for this range */ 0187 __le32 flags; 0188 }; 0189 0190 #ifndef VIRTIO_BLK_NO_LEGACY 0191 struct virtio_scsi_inhdr { 0192 __virtio32 errors; 0193 __virtio32 data_len; 0194 __virtio32 sense_len; 0195 __virtio32 residual; 0196 }; 0197 #endif /* !VIRTIO_BLK_NO_LEGACY */ 0198 0199 /* And this is the final byte of the write scatter-gather list. */ 0200 #define VIRTIO_BLK_S_OK 0 0201 #define VIRTIO_BLK_S_IOERR 1 0202 #define VIRTIO_BLK_S_UNSUPP 2 0203 #endif /* _LINUX_VIRTIO_BLK_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |