1 /* SPDX-License-Identifier: BSD-3-Clause */
3 * Copyright (C) 2018, Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
4 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
6 * From Linux kernel include/uapi/linux/virtio_blk.h
9 #ifndef _LINUX_VIRTIO_BLK_H
10 #define _LINUX_VIRTIO_BLK_H
13 #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
14 #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
15 #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
16 #define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
17 #define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available */
18 #define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
19 #define VIRTIO_BLK_F_MQ 12 /* Support more than one vq */
21 /* Legacy feature bits */
22 #ifndef VIRTIO_BLK_NO_LEGACY
23 #define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
24 #define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
25 #define VIRTIO_BLK_F_FLUSH 9 /* Flush command supported */
26 #define VIRTIO_BLK_F_CONFIG_WCE 11 /* Writeback mode available in config */
28 /* Old (deprecated) name for VIRTIO_BLK_F_FLUSH */
29 #define VIRTIO_BLK_F_WCE VIRTIO_BLK_F_FLUSH
31 #endif /* !VIRTIO_BLK_NO_LEGACY */
33 #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
35 struct __packed virtio_blk_config {
36 /* The capacity (in 512-byte sectors) */
38 /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
40 /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
42 /* geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */
43 struct virtio_blk_geometry {
49 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
52 /* the next 4 entries are guarded by VIRTIO_BLK_F_TOPOLOGY */
53 /* exponent for physical block per logical block */
54 __u8 physical_block_exp;
55 /* alignment offset in logical blocks */
56 __u8 alignment_offset;
57 /* minimum I/O size without performance penalty in logical blocks */
59 /* optimal sustained I/O size in logical blocks */
62 /* writeback mode (if VIRTIO_BLK_F_CONFIG_WCE) */
66 /* number of vqs, only available when VIRTIO_BLK_F_MQ is set */
73 * Usage is a bit tricky as some bits are used as flags and some are not.
76 * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or
77 * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own
78 * and may not be combined with any of the other flags.
81 /* These two define direction */
82 #define VIRTIO_BLK_T_IN 0
83 #define VIRTIO_BLK_T_OUT 1
85 #ifndef VIRTIO_BLK_NO_LEGACY
86 /* This bit says it's a scsi command, not an actual read or write */
87 #define VIRTIO_BLK_T_SCSI_CMD 2
88 #endif /* VIRTIO_BLK_NO_LEGACY */
90 /* Cache flush command */
91 #define VIRTIO_BLK_T_FLUSH 4
93 /* Get device ID command */
94 #define VIRTIO_BLK_T_GET_ID 8
96 #ifndef VIRTIO_BLK_NO_LEGACY
97 /* Barrier before this op */
98 #define VIRTIO_BLK_T_BARRIER 0x80000000
99 #endif /* !VIRTIO_BLK_NO_LEGACY */
102 * This comes first in the read scatter-gather list.
103 * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated,
104 * this is the first element of the read scatter-gather list.
106 struct virtio_blk_outhdr {
111 /* Sector (ie. 512 byte offset) */
115 #ifndef VIRTIO_BLK_NO_LEGACY
116 struct virtio_scsi_inhdr {
119 __virtio32 sense_len;
122 #endif /* !VIRTIO_BLK_NO_LEGACY */
124 /* And this is the final byte of the write scatter-gather list */
125 #define VIRTIO_BLK_S_OK 0
126 #define VIRTIO_BLK_S_IOERR 1
127 #define VIRTIO_BLK_S_UNSUPP 2
129 #endif /* _LINUX_VIRTIO_BLK_H */