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 vring;
34 struct rte_vhost_ring_inflight inflight_ring;
36 uint16_t last_avail_idx;
37 uint16_t last_used_idx;
40 bool avail_wrap_counter;
41 bool used_wrap_counter;
44 struct vhost_blk_task *tasks;
47 #define NUM_OF_BLK_QUEUES 1
49 struct vhost_block_dev {
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 {
71 /** ID for vhost library. */
73 /** Queues for the block device */
74 struct vhost_blk_queue queues[NUM_OF_BLK_QUEUES];
75 /** Only support 1 LUN for the example */
76 struct vhost_block_dev *bdev;
77 /** VM memory region */
78 struct rte_vhost_memory *mem;
79 } __rte_cache_aligned;
81 #define VHOST_BLK_MAX_IOVS 128
89 struct vhost_blk_task {
92 uint16_t inflight_idx;
97 struct virtio_blk_outhdr *req;
98 volatile uint8_t *status;
99 struct iovec iovs[VHOST_BLK_MAX_IOVS];
102 struct vhost_blk_queue *vq;
103 struct vhost_blk_ctrlr *ctrlr;
106 extern struct vhost_blk_ctrlr *g_vhost_ctrlr;
107 extern struct vhost_device_ops vhost_blk_device_ops;
109 int vhost_bdev_process_blk_commands(struct vhost_block_dev *bdev,
110 struct vhost_blk_task *task);
112 void vhost_session_install_rte_compat_hooks(uint32_t vid);
114 void vhost_dev_install_rte_compat_hooks(const char *path);
116 struct vhost_blk_ctrlr *vhost_blk_ctrlr_find(const char *ctrlr_name);
118 #endif /* _VHOST_blk_H_ */