aboutsummaryrefslogtreecommitdiffstats
path: root/examples/vhost_scsi/vhost_scsi.h
blob: 7f98d8d10a744165e83078908bfe0cac893e9120 (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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2017 Intel Corporation
 */

#ifndef _VHOST_SCSI_H_
#define _VHOST_SCSI_H_

#include <sys/uio.h>
#include <stdint.h>
#include <linux/virtio_scsi.h>
#include <linux/virtio_ring.h>

#include <rte_vhost.h>

struct vhost_scsi_queue {
	struct rte_vhost_vring vq;
	uint16_t last_avail_idx;
	uint16_t last_used_idx;
};

#define NUM_OF_SCSI_QUEUES 3

struct vhost_block_dev {
	/** ID for vhost library. */
	int vid;
	/** Queues for the block device */
	struct vhost_scsi_queue queues[NUM_OF_SCSI_QUEUES];
	/** Unique name for this block device. */
	char name[64];

	/** Unique product name for this kind of block device. */
	char product_name[256];

	/** Size in bytes of a logical block for the backend */
	uint32_t blocklen;

	/** Number of blocks */
	uint64_t blockcnt;

	/** write cache enabled, not used at the moment */
	int write_cache;

	/** use memory as disk storage space */
	uint8_t *data;
};

struct vhost_scsi_ctrlr {
	/** Only support 1 LUN for the example */
	struct vhost_block_dev *bdev;
	/** VM memory region */
	struct rte_vhost_memory *mem;
} __rte_cache_aligned;

#define VHOST_SCSI_MAX_IOVS 128

enum scsi_data_dir {
	SCSI_DIR_NONE = 0,
	SCSI_DIR_TO_DEV = 1,
	SCSI_DIR_FROM_DEV = 2,
};

struct vhost_scsi_task {
	int req_idx;
	uint32_t dxfer_dir;
	uint32_t data_len;
	struct virtio_scsi_cmd_req *req;
	struct virtio_scsi_cmd_resp *resp;
	struct iovec iovs[VHOST_SCSI_MAX_IOVS];
	uint32_t iovs_cnt;
	struct vring_desc *desc;
	struct rte_vhost_vring *vq;
	struct vhost_block_dev *bdev;
	struct vhost_scsi_ctrlr *ctrlr;
};

int vhost_bdev_process_scsi_commands(struct vhost_block_dev *bdev,
				     struct vhost_scsi_task *task);

#endif /* _VHOST_SCSI_H_ */