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