summaryrefslogtreecommitdiff
path: root/components/drivers/virtio/virtio_config/virtio-blk.h
blob: 045aa780874de857c5e2e14e8e48c1044dace4a3 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-9-16      GuEe-GUI     the first version
 * 2021-11-11     GuEe-GUI     using virtio common interface
 * 2023-02-25     GuEe-GUI     using virtio dm
 */

#ifndef __VIRTIO_BLK_H__
#define __VIRTIO_BLK_H__

#include <drivers/core/dm.h>

#define VIRTIO_BLK_F_SIZE_MAX       1   /* Indicates maximum segment size */
#define VIRTIO_BLK_F_SEG_MAX        2   /* Indicates maximum # of segments */
#define VIRTIO_BLK_F_GEOMETRY       4   /* Legacy geometry available  */
#define VIRTIO_BLK_F_RO             5   /* Disk is read-only */
#define VIRTIO_BLK_F_BLK_SIZE       6   /* Block size of disk is available*/
#define VIRTIO_BLK_F_SCSI           7   /* Supports scsi command passthru */
#define VIRTIO_BLK_F_FLUSH          9   /* Flush command supported */
#define VIRTIO_BLK_F_TOPOLOGY       10  /* Topology information is available */
#define VIRTIO_BLK_F_CONFIG_WCE     11  /* Writeback mode available in config */
#define VIRTIO_BLK_F_MQ             12  /* Support more than one vq */
#define VIRTIO_BLK_F_DISCARD        13  /* DISCARD is supported */
#define VIRTIO_BLK_F_WRITE_ZEROES   14  /* WRITE ZEROES is supported */
#define VIRTIO_BLK_F_SECURE_ERASE   16  /* Secure Erase is supported */

#define VIRTIO_BLK_T_IN             0   /* Read the blk */
#define VIRTIO_BLK_T_OUT            1   /* Write the blk */
#define VIRTIO_BLK_T_SCSI_CMD       2
#define VIRTIO_BLK_T_SCSI_CMD_OUT   3
#define VIRTIO_BLK_T_FLUSH          4
#define VIRTIO_BLK_T_FLUSH_OUT      5
#define VIRTIO_BLK_T_GET_ID         8   /* Get device ID command */
#define VIRTIO_BLK_T_DISCARD        11  /* Discard command */
#define VIRTIO_BLK_T_WRITE_ZEROES   13  /* Write zeroes command */
#define VIRTIO_BLK_T_SECURE_ERASE   14  /* Secure erase command */
#define VIRTIO_BLK_T_ZONE_APPEND    15  /* Zone append command */
#define VIRTIO_BLK_T_ZONE_REPORT    16  /* Report zones command */
#define VIRTIO_BLK_T_ZONE_OPEN      18  /* Open zone command */
#define VIRTIO_BLK_T_ZONE_CLOSE     20  /* Close zone command */
#define VIRTIO_BLK_T_ZONE_FINISH    22  /* Finish zone command */
#define VIRTIO_BLK_T_ZONE_RESET     24  /* Reset zone command */
#define VIRTIO_BLK_T_ZONE_RESET_ALL 26  /* Reset All zones command */

struct virtio_blk_req
{
    rt_le32_t type;
    rt_le32_t ioprio;
    rt_le64_t sector;

#define VIRTIO_BLK_S_OK                     0
#define VIRTIO_BLK_S_IOERR                  1
#define VIRTIO_BLK_S_UNSUPP                 2
#define VIRTIO_BLK_S_ZONE_INVALID_CMD       3
#define VIRTIO_BLK_S_ZONE_UNALIGNED_WP      4
#define VIRTIO_BLK_S_ZONE_OPEN_RESOURCE     5
#define VIRTIO_BLK_S_ZONE_ACTIVE_RESOURCE   6
    /*
     * next:
     * rt_uint8_t data[];
     * rt_uint8_t status;
     */
};

struct virtio_blk_discard_write_zeroes
{
    rt_le64_t sector;
    rt_le32_t num_sectors;

    /*
     * unmap:1
     * reserved:31
     */
    rt_le32_t flags;
};

rt_packed(struct virtio_blk_config
{
    /* The capacity (in 512-byte sectors). */
    rt_le64_t capacity;
    /* The maximum segment size (if VIRTIO_BLK_F_SIZE_MAX) */
    rt_le32_t size_max;
    /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
    rt_le32_t seg_max;

    /* Geometry of the device (if VIRTIO_BLK_F_GEOMETRY) */
    struct virtio_blk_geometry
    {
        rt_le16_t cylinders;
        rt_uint8_t heads;
        rt_uint8_t sectors;
    } geometry;

    /* Block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
    rt_le32_t blk_size;

    struct virtio_blk_topology
    {
        /* # Of logical blocks per physical block (log2) */
        rt_uint8_t physical_block_exp;
        /* Offset of first aligned logical block */
        rt_uint8_t alignment_offset;
        /* Suggested minimum I/O size in blocks */
        rt_le16_t min_io_size;
        /* Optimal (suggested maximum) I/O size in blocks */
        rt_le32_t opt_io_size;
    } topology;

    rt_uint8_t writeback;
    rt_uint8_t unused0;
    rt_uint16_t num_queues;
    rt_le32_t max_discard_sectors;
    rt_le32_t max_discard_seg;
    rt_le32_t discard_sector_alignment;
    rt_le32_t max_write_zeroes_sectors;
    rt_le32_t max_write_zeroes_seg;
    rt_uint8_t write_zeroes_may_unmap;
    rt_uint8_t unused1[3];
    rt_le32_t max_secure_erase_sectors;
    rt_le32_t max_secure_erase_seg;
    rt_le32_t secure_erase_sector_alignment;
});

#endif /* __VIRTIO_BLK_H__ */