New upstream version 18.02
[deb_dpdk.git] / lib / librte_vhost / vhost_user.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef _VHOST_NET_USER_H
6 #define _VHOST_NET_USER_H
7
8 #include <stdint.h>
9 #include <linux/vhost.h>
10
11 #include "rte_vhost.h"
12
13 /* refer to hw/virtio/vhost-user.c */
14
15 #define VHOST_MEMORY_MAX_NREGIONS 8
16
17 #define VHOST_USER_PROTOCOL_F_MQ        0
18 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
19 #define VHOST_USER_PROTOCOL_F_RARP      2
20 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
21 #define VHOST_USER_PROTOCOL_F_NET_MTU 4
22 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
23
24 #define VHOST_USER_PROTOCOL_FEATURES    ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
25                                          (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
26                                          (1ULL << VHOST_USER_PROTOCOL_F_RARP) | \
27                                          (1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
28                                          (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU) | \
29                                          (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ))
30
31 typedef enum VhostUserRequest {
32         VHOST_USER_NONE = 0,
33         VHOST_USER_GET_FEATURES = 1,
34         VHOST_USER_SET_FEATURES = 2,
35         VHOST_USER_SET_OWNER = 3,
36         VHOST_USER_RESET_OWNER = 4,
37         VHOST_USER_SET_MEM_TABLE = 5,
38         VHOST_USER_SET_LOG_BASE = 6,
39         VHOST_USER_SET_LOG_FD = 7,
40         VHOST_USER_SET_VRING_NUM = 8,
41         VHOST_USER_SET_VRING_ADDR = 9,
42         VHOST_USER_SET_VRING_BASE = 10,
43         VHOST_USER_GET_VRING_BASE = 11,
44         VHOST_USER_SET_VRING_KICK = 12,
45         VHOST_USER_SET_VRING_CALL = 13,
46         VHOST_USER_SET_VRING_ERR = 14,
47         VHOST_USER_GET_PROTOCOL_FEATURES = 15,
48         VHOST_USER_SET_PROTOCOL_FEATURES = 16,
49         VHOST_USER_GET_QUEUE_NUM = 17,
50         VHOST_USER_SET_VRING_ENABLE = 18,
51         VHOST_USER_SEND_RARP = 19,
52         VHOST_USER_NET_SET_MTU = 20,
53         VHOST_USER_SET_SLAVE_REQ_FD = 21,
54         VHOST_USER_IOTLB_MSG = 22,
55         VHOST_USER_MAX
56 } VhostUserRequest;
57
58 typedef enum VhostUserSlaveRequest {
59         VHOST_USER_SLAVE_NONE = 0,
60         VHOST_USER_SLAVE_IOTLB_MSG = 1,
61         VHOST_USER_SLAVE_MAX
62 } VhostUserSlaveRequest;
63
64 typedef struct VhostUserMemoryRegion {
65         uint64_t guest_phys_addr;
66         uint64_t memory_size;
67         uint64_t userspace_addr;
68         uint64_t mmap_offset;
69 } VhostUserMemoryRegion;
70
71 typedef struct VhostUserMemory {
72         uint32_t nregions;
73         uint32_t padding;
74         VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];
75 } VhostUserMemory;
76
77 typedef struct VhostUserLog {
78         uint64_t mmap_size;
79         uint64_t mmap_offset;
80 } VhostUserLog;
81
82 typedef struct VhostUserMsg {
83         union {
84                 VhostUserRequest master;
85                 VhostUserSlaveRequest slave;
86         } request;
87
88 #define VHOST_USER_VERSION_MASK     0x3
89 #define VHOST_USER_REPLY_MASK       (0x1 << 2)
90 #define VHOST_USER_NEED_REPLY           (0x1 << 3)
91         uint32_t flags;
92         uint32_t size; /* the following payload size */
93         union {
94 #define VHOST_USER_VRING_IDX_MASK   0xff
95 #define VHOST_USER_VRING_NOFD_MASK  (0x1<<8)
96                 uint64_t u64;
97                 struct vhost_vring_state state;
98                 struct vhost_vring_addr addr;
99                 VhostUserMemory memory;
100                 VhostUserLog    log;
101                 struct vhost_iotlb_msg iotlb;
102         } payload;
103         int fds[VHOST_MEMORY_MAX_NREGIONS];
104 } __attribute((packed)) VhostUserMsg;
105
106 #define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64)
107
108 /* The version of the protocol we support */
109 #define VHOST_USER_VERSION    0x1
110
111
112 /* vhost_user.c */
113 int vhost_user_msg_handler(int vid, int fd);
114 int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
115
116 /* socket.c */
117 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
118 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
119
120 #endif