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 struct vhost_vring_state {
50 struct vhost_vring_file {
55 struct vhost_vring_addr {
60 /* Whether log address is valid. If set enables logging. */
61 #define VHOST_VRING_F_LOG 0
63 /* Start of array of descriptors (virtually contiguous) */
64 uint64_t desc_user_addr;
65 /* Used structure address. Must be 32 bit aligned */
66 uint64_t used_user_addr;
67 /* Available structure address. Must be 16 bit aligned */
68 uint64_t avail_user_addr;
69 /* Logging support. */
70 /* Log writes to used structure, at offset calculated from specified
71 * address. Address must be 32 bit aligned.
73 uint64_t log_guest_addr;
76 enum vhost_user_request {
78 VHOST_USER_GET_FEATURES = 1,
79 VHOST_USER_SET_FEATURES = 2,
80 VHOST_USER_SET_OWNER = 3,
81 VHOST_USER_RESET_OWNER = 4,
82 VHOST_USER_SET_MEM_TABLE = 5,
83 VHOST_USER_SET_LOG_BASE = 6,
84 VHOST_USER_SET_LOG_FD = 7,
85 VHOST_USER_SET_VRING_NUM = 8,
86 VHOST_USER_SET_VRING_ADDR = 9,
87 VHOST_USER_SET_VRING_BASE = 10,
88 VHOST_USER_GET_VRING_BASE = 11,
89 VHOST_USER_SET_VRING_KICK = 12,
90 VHOST_USER_SET_VRING_CALL = 13,
91 VHOST_USER_SET_VRING_ERR = 14,
92 VHOST_USER_GET_PROTOCOL_FEATURES = 15,
93 VHOST_USER_SET_PROTOCOL_FEATURES = 16,
94 VHOST_USER_GET_QUEUE_NUM = 17,
95 VHOST_USER_SET_VRING_ENABLE = 18,
99 const char * const vhost_msg_strings[VHOST_USER_MAX];
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 virtio_user_dev;
110 struct virtio_user_backend_ops {
111 int (*setup)(struct virtio_user_dev *dev);
112 int (*send_request)(struct virtio_user_dev *dev,
113 enum vhost_user_request req,
115 int (*enable_qp)(struct virtio_user_dev *dev,
120 struct virtio_user_backend_ops ops_user;
121 struct virtio_user_backend_ops ops_kernel;