4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _VHOST_SCSI_H_
35 #define _VHOST_SCSI_H_
39 #include <linux/virtio_scsi.h>
40 #include <linux/virtio_ring.h>
42 #include <rte_vhost.h>
44 struct vhost_scsi_queue {
45 struct rte_vhost_vring vq;
46 uint16_t last_avail_idx;
47 uint16_t last_used_idx;
50 #define NUM_OF_SCSI_QUEUES 3
52 struct vhost_block_dev {
53 /** ID for vhost library. */
55 /** Queues for the block device */
56 struct vhost_scsi_queue queues[NUM_OF_SCSI_QUEUES];
57 /** Unique name for this block device. */
60 /** Unique product name for this kind of block device. */
61 char product_name[256];
63 /** Size in bytes of a logical block for the backend */
66 /** Number of blocks */
69 /** write cache enabled, not used at the moment */
72 /** use memory as disk storage space */
76 struct vhost_scsi_ctrlr {
77 /** Only support 1 LUN for the example */
78 struct vhost_block_dev *bdev;
79 /** VM memory region */
80 struct rte_vhost_memory *mem;
81 } __rte_cache_aligned;
83 #define VHOST_SCSI_MAX_IOVS 128
88 SCSI_DIR_FROM_DEV = 2,
91 struct vhost_scsi_task {
95 struct virtio_scsi_cmd_req *req;
96 struct virtio_scsi_cmd_resp *resp;
97 struct iovec iovs[VHOST_SCSI_MAX_IOVS];
99 struct vring_desc *desc;
100 struct rte_vhost_vring *vq;
101 struct vhost_block_dev *bdev;
102 struct vhost_scsi_ctrlr *ctrlr;
105 int vhost_bdev_process_scsi_commands(struct vhost_block_dev *bdev,
106 struct vhost_scsi_task *task);
108 #endif /* _VHOST_SCSI_H_ */