4 * Copyright(c) 2010-2016 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_NET_USER_H
35 #define _VHOST_NET_USER_H
38 #include <linux/types.h>
39 #include <linux/ioctl.h>
41 #include "../virtio_pci.h"
42 #include "../virtio_logs.h"
43 #include "../virtqueue.h"
45 #define VHOST_MEMORY_MAX_NREGIONS 8
47 struct vhost_vring_state {
52 struct vhost_vring_file {
57 struct vhost_vring_addr {
62 /* Whether log address is valid. If set enables logging. */
63 #define VHOST_VRING_F_LOG 0
65 /* Start of array of descriptors (virtually contiguous) */
66 uint64_t desc_user_addr;
67 /* Used structure address. Must be 32 bit aligned */
68 uint64_t used_user_addr;
69 /* Available structure address. Must be 16 bit aligned */
70 uint64_t avail_user_addr;
71 /* Logging support. */
72 /* Log writes to used structure, at offset calculated from specified
73 * address. Address must be 32 bit aligned.
75 uint64_t log_guest_addr;
78 enum vhost_user_request {
80 VHOST_USER_GET_FEATURES = 1,
81 VHOST_USER_SET_FEATURES = 2,
82 VHOST_USER_SET_OWNER = 3,
83 VHOST_USER_RESET_OWNER = 4,
84 VHOST_USER_SET_MEM_TABLE = 5,
85 VHOST_USER_SET_LOG_BASE = 6,
86 VHOST_USER_SET_LOG_FD = 7,
87 VHOST_USER_SET_VRING_NUM = 8,
88 VHOST_USER_SET_VRING_ADDR = 9,
89 VHOST_USER_SET_VRING_BASE = 10,
90 VHOST_USER_GET_VRING_BASE = 11,
91 VHOST_USER_SET_VRING_KICK = 12,
92 VHOST_USER_SET_VRING_CALL = 13,
93 VHOST_USER_SET_VRING_ERR = 14,
94 VHOST_USER_GET_PROTOCOL_FEATURES = 15,
95 VHOST_USER_SET_PROTOCOL_FEATURES = 16,
96 VHOST_USER_GET_QUEUE_NUM = 17,
97 VHOST_USER_SET_VRING_ENABLE = 18,
101 struct vhost_memory_region {
102 uint64_t guest_phys_addr;
103 uint64_t memory_size; /* bytes */
104 uint64_t userspace_addr;
105 uint64_t mmap_offset;
108 struct vhost_memory {
111 struct vhost_memory_region regions[VHOST_MEMORY_MAX_NREGIONS];
114 struct vhost_user_msg {
115 enum vhost_user_request request;
117 #define VHOST_USER_VERSION_MASK 0x3
118 #define VHOST_USER_REPLY_MASK (0x1 << 2)
120 uint32_t size; /* the following payload size */
122 #define VHOST_USER_VRING_IDX_MASK 0xff
123 #define VHOST_USER_VRING_NOFD_MASK (0x1 << 8)
125 struct vhost_vring_state state;
126 struct vhost_vring_addr addr;
127 struct vhost_memory memory;
129 int fds[VHOST_MEMORY_MAX_NREGIONS];
130 } __attribute((packed));
132 #define VHOST_USER_HDR_SIZE offsetof(struct vhost_user_msg, payload.u64)
133 #define VHOST_USER_PAYLOAD_SIZE \
134 (sizeof(struct vhost_user_msg) - VHOST_USER_HDR_SIZE)
136 /* The version of the protocol we support */
137 #define VHOST_USER_VERSION 0x1
139 #define VHOST_USER_F_PROTOCOL_FEATURES 30
140 #define VHOST_USER_MQ (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)
142 int vhost_user_sock(int vhostfd, enum vhost_user_request req, void *arg);
143 int vhost_user_setup(const char *path);
144 int vhost_user_enable_queue_pair(int vhostfd, uint16_t pair_idx, int enable);