1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
12 #include <linux/virtio_blk.h>
13 #include <linux/virtio_ring.h>
15 #include <rte_vhost.h>
17 #ifndef VIRTIO_F_RING_PACKED
18 #define VIRTIO_F_RING_PACKED 34
20 struct vring_packed_desc {
27 /* The flags depending on descriptor type. */
32 struct vhost_blk_queue {
33 struct rte_vhost_vring vq;
34 struct rte_vhost_ring_inflight inflight_vq;
35 uint16_t last_avail_idx;
36 uint16_t last_used_idx;
37 bool avail_wrap_counter;
38 bool used_wrap_counter;
41 #define NUM_OF_BLK_QUEUES 1
43 #define min(a, b) (((a) < (b)) ? (a) : (b))
45 struct vhost_block_dev {
46 /** ID for vhost library. */
48 /** Queues for the block device */
49 struct vhost_blk_queue queues[NUM_OF_BLK_QUEUES];
50 /** Unique name for this block device. */
53 /** Unique product name for this kind of block device. */
54 char product_name[256];
56 /** Size in bytes of a logical block for the backend */
59 /** Number of blocks */
62 /** write cache enabled, not used at the moment */
65 /** use memory as disk storage space */
69 struct vhost_blk_ctrlr {
73 /** Only support 1 LUN for the example */
74 struct vhost_block_dev *bdev;
75 /** VM memory region */
76 struct rte_vhost_memory *mem;
77 } __rte_cache_aligned;
79 #define VHOST_BLK_MAX_IOVS 128
87 struct vhost_blk_task {
92 uint16_t inflight_idx;
96 struct virtio_blk_outhdr *req;
98 volatile uint8_t *status;
100 struct iovec iovs[VHOST_BLK_MAX_IOVS];
102 struct vring_packed_desc *desc_packed;
103 struct vring_desc *desc_split;
104 struct rte_vhost_vring *vq;
105 struct vhost_block_dev *bdev;
106 struct vhost_blk_ctrlr *ctrlr;
109 struct inflight_blk_task {
110 struct vhost_blk_task blk_task;
111 struct rte_vhost_inflight_desc_packed *inflight_desc;
112 struct rte_vhost_inflight_info_packed *inflight_packed;
115 extern struct vhost_blk_ctrlr *g_vhost_ctrlr;
116 extern struct vhost_device_ops vhost_blk_device_ops;
118 int vhost_bdev_process_blk_commands(struct vhost_block_dev *bdev,
119 struct vhost_blk_task *task);
121 void vhost_session_install_rte_compat_hooks(uint32_t vid);
123 void vhost_dev_install_rte_compat_hooks(const char *path);
125 struct vhost_blk_ctrlr *vhost_blk_ctrlr_find(const char *ctrlr_name);
127 #endif /* _VHOST_blk_H_ */