1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 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 16 * distribution. 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. 20 * 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. 32 */ 33 34 #ifndef _VHOST_NET_USER_H 35 #define _VHOST_NET_USER_H 36 37 #include <stdint.h> 38 #include <linux/types.h> 39 #include <linux/ioctl.h> 40 41 #include "../virtio_pci.h" 42 #include "../virtio_logs.h" 43 #include "../virtqueue.h" 44 45 struct vhost_vring_state { 46 unsigned int index; 47 unsigned int num; 48 }; 49 50 struct vhost_vring_file { 51 unsigned int index; 52 int fd; 53 }; 54 55 struct vhost_vring_addr { 56 unsigned int index; 57 /* Option flags. */ 58 unsigned int flags; 59 /* Flag values: */ 60 /* Whether log address is valid. If set enables logging. */ 61 #define VHOST_VRING_F_LOG 0 62 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. 72 */ 73 uint64_t log_guest_addr; 74 }; 75 76 enum vhost_user_request { 77 VHOST_USER_NONE = 0, 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, 96 VHOST_USER_MAX 97 }; 98 99 const char * const vhost_msg_strings[VHOST_USER_MAX]; 100 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; 106 }; 107 108 struct virtio_user_dev; 109 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, 114 void *arg); 115 int (*enable_qp)(struct virtio_user_dev *dev, 116 uint16_t pair_idx, 117 int enable); 118 }; 119 120 struct virtio_user_backend_ops ops_user; 121 struct virtio_user_backend_ops ops_kernel; 122 123 #endif 124