Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #ifndef __VIRTIO_VHOST_USER_H__ |
| 16 | #define __VIRTIO_VHOST_USER_H__ |
Mohsin Kazmi | a7a2281 | 2020-08-31 17:17:16 +0200 | [diff] [blame] | 17 | |
| 18 | #include <vnet/devices/virtio/virtio_std.h> |
| 19 | #include <vnet/devices/virtio/vhost_std.h> |
| 20 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | /* vhost-user data structures */ |
| 22 | |
| 23 | #define VHOST_MEMORY_MAX_NREGIONS 8 |
| 24 | #define VHOST_USER_MSG_HDR_SZ 12 |
Steven Luong | 2c1084a | 2020-12-10 20:44:22 -0800 | [diff] [blame] | 25 | #define VHOST_VRING_INIT_MQ_PAIR_SZ 8 //8TX + 8RX |
| 26 | |
| 27 | /* |
| 28 | * qid is one byte in size in the spec. Please see VHOST_USER_SET_VRING_CALL, |
| 29 | * VHOST_USER_SET_VRING_KICK, and VHOST_USER_SET_VRING_ERR. |
| 30 | * The max number for q pair is naturally 128. |
| 31 | */ |
| 32 | #define VHOST_VRING_MAX_MQ_PAIR_SZ 128 |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 33 | #define VHOST_VRING_IDX_RX(qid) (2*qid) |
| 34 | #define VHOST_VRING_IDX_TX(qid) (2*qid + 1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 35 | |
Steven | 49a04b9 | 2017-07-29 08:56:08 -0700 | [diff] [blame] | 36 | #define VHOST_USER_VRING_NOFD_MASK 0x100 |
Shesha Sreenivasamurthy | b8f45b3 | 2016-02-03 09:38:36 -0800 | [diff] [blame] | 37 | |
Yoann Desmouceaux | 4667c22 | 2016-02-24 22:51:00 +0100 | [diff] [blame] | 38 | #define VHOST_USER_PROTOCOL_F_MQ 0 |
| 39 | #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 |
Yoann Desmouceaux | fe2da0e | 2016-03-08 14:54:28 +0100 | [diff] [blame] | 40 | #define VHOST_VRING_F_LOG 0 |
Yoann Desmouceaux | 4667c22 | 2016-02-24 22:51:00 +0100 | [diff] [blame] | 41 | |
Shesha Sreenivasamurthy | 0666dc4 | 2016-04-18 16:38:20 -0400 | [diff] [blame] | 42 | #define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \ |
| 43 | (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD)) |
Shesha Sreenivasamurthy | b8f45b3 | 2016-02-03 09:38:36 -0800 | [diff] [blame] | 44 | |
Jerome Tollet | 2f54c27 | 2018-10-02 11:41:11 +0200 | [diff] [blame] | 45 | #define vu_log_debug(dev, f, ...) \ |
| 46 | { \ |
| 47 | vlib_log(VLIB_LOG_LEVEL_DEBUG, vhost_user_main.log_default, "%U: " f, \ |
| 48 | format_vnet_hw_if_index_name, vnet_get_main(), \ |
| 49 | dev->hw_if_index, ##__VA_ARGS__); \ |
| 50 | }; |
Mohsin Kazmi | e7cde31 | 2018-06-26 17:20:11 +0200 | [diff] [blame] | 51 | |
Jerome Tollet | 2f54c27 | 2018-10-02 11:41:11 +0200 | [diff] [blame] | 52 | #define vu_log_warn(dev, f, ...) \ |
| 53 | { \ |
| 54 | vlib_log(VLIB_LOG_LEVEL_WARNING, vhost_user_main.log_default, "%U: " f, \ |
| 55 | format_vnet_hw_if_index_name, vnet_get_main(), \ |
| 56 | dev->hw_if_index, ##__VA_ARGS__); \ |
| 57 | }; |
| 58 | #define vu_log_err(dev, f, ...) \ |
| 59 | { \ |
| 60 | vlib_log(VLIB_LOG_LEVEL_ERR, vhost_user_main.log_default, "%U: " f, \ |
| 61 | format_vnet_hw_if_index_name, vnet_get_main(), \ |
| 62 | dev->hw_if_index, ##__VA_ARGS__); \ |
| 63 | }; |
Mohsin Kazmi | e7cde31 | 2018-06-26 17:20:11 +0200 | [diff] [blame] | 64 | |
| 65 | #define UNIX_GET_FD(unixfd_idx) ({ \ |
| 66 | typeof(unixfd_idx) __unixfd_idx = (unixfd_idx); \ |
| 67 | (__unixfd_idx != ~0) ? \ |
| 68 | pool_elt_at_index (file_main.file_pool, \ |
| 69 | __unixfd_idx)->file_descriptor : -1; }) |
| 70 | |
| 71 | #define foreach_virtio_trace_flags \ |
| 72 | _ (SIMPLE_CHAINED, 0, "Simple descriptor chaining") \ |
| 73 | _ (SINGLE_DESC, 1, "Single descriptor packet") \ |
| 74 | _ (INDIRECT, 2, "Indirect descriptor") \ |
| 75 | _ (MAP_ERROR, 4, "Memory mapping error") |
| 76 | |
| 77 | typedef enum |
| 78 | { |
| 79 | #define _(n,i,s) VIRTIO_TRACE_F_##n, |
| 80 | foreach_virtio_trace_flags |
| 81 | #undef _ |
| 82 | } virtio_trace_flag_t; |
| 83 | |
Steven Luong | 4208a4c | 2019-05-06 08:51:56 -0700 | [diff] [blame] | 84 | #define FEATURE_VIRTIO_NET_F_HOST_TSO_FEATURE_BITS \ |
Mohsin Kazmi | a7a2281 | 2020-08-31 17:17:16 +0200 | [diff] [blame] | 85 | (VIRTIO_FEATURE (VIRTIO_NET_F_CSUM) | \ |
| 86 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_UFO) | \ |
| 87 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO4) | \ |
| 88 | VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO6)) |
Steven Luong | 4208a4c | 2019-05-06 08:51:56 -0700 | [diff] [blame] | 89 | |
| 90 | #define FEATURE_VIRTIO_NET_F_GUEST_TSO_FEATURE_BITS \ |
Mohsin Kazmi | a7a2281 | 2020-08-31 17:17:16 +0200 | [diff] [blame] | 91 | (VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM) | \ |
| 92 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO) | \ |
| 93 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4) | \ |
| 94 | VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6)) |
Steven Luong | 4208a4c | 2019-05-06 08:51:56 -0700 | [diff] [blame] | 95 | |
| 96 | #define FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS \ |
| 97 | (FEATURE_VIRTIO_NET_F_HOST_TSO_FEATURE_BITS | \ |
| 98 | FEATURE_VIRTIO_NET_F_GUEST_TSO_FEATURE_BITS) |
| 99 | |
Steven Luong | 27ba500 | 2020-11-17 13:30:44 -0800 | [diff] [blame^] | 100 | |
| 101 | typedef struct |
| 102 | { |
| 103 | char *sock_filename; |
| 104 | u64 feature_mask; |
| 105 | u32 custom_dev_instance; |
| 106 | u8 hwaddr[6]; |
| 107 | u8 renumber; |
| 108 | u8 is_server; |
| 109 | u8 enable_gso; |
| 110 | u8 enable_packed; |
| 111 | u8 enable_event_idx; |
| 112 | |
| 113 | /* return */ |
| 114 | u32 sw_if_index; |
| 115 | } vhost_user_create_if_args_t; |
| 116 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 117 | int vhost_user_create_if (vnet_main_t * vnm, vlib_main_t * vm, |
Steven Luong | 27ba500 | 2020-11-17 13:30:44 -0800 | [diff] [blame^] | 118 | vhost_user_create_if_args_t * args); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 119 | int vhost_user_modify_if (vnet_main_t * vnm, vlib_main_t * vm, |
Steven Luong | 27ba500 | 2020-11-17 13:30:44 -0800 | [diff] [blame^] | 120 | vhost_user_create_if_args_t * args); |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 121 | int vhost_user_delete_if (vnet_main_t * vnm, vlib_main_t * vm, |
| 122 | u32 sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 124 | /* *INDENT-OFF* */ |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 125 | typedef struct vhost_user_memory_region |
| 126 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | u64 guest_phys_addr; |
| 128 | u64 memory_size; |
| 129 | u64 userspace_addr; |
| 130 | u64 mmap_offset; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 131 | } __attribute ((packed)) vhost_user_memory_region_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 132 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 133 | typedef struct vhost_user_memory |
| 134 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | u32 nregions; |
| 136 | u32 padding; |
| 137 | vhost_user_memory_region_t regions[VHOST_MEMORY_MAX_NREGIONS]; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 138 | } __attribute ((packed)) vhost_user_memory_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 139 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 140 | typedef enum vhost_user_req |
| 141 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | VHOST_USER_NONE = 0, |
| 143 | VHOST_USER_GET_FEATURES = 1, |
| 144 | VHOST_USER_SET_FEATURES = 2, |
| 145 | VHOST_USER_SET_OWNER = 3, |
| 146 | VHOST_USER_RESET_OWNER = 4, |
| 147 | VHOST_USER_SET_MEM_TABLE = 5, |
| 148 | VHOST_USER_SET_LOG_BASE = 6, |
| 149 | VHOST_USER_SET_LOG_FD = 7, |
| 150 | VHOST_USER_SET_VRING_NUM = 8, |
| 151 | VHOST_USER_SET_VRING_ADDR = 9, |
| 152 | VHOST_USER_SET_VRING_BASE = 10, |
| 153 | VHOST_USER_GET_VRING_BASE = 11, |
| 154 | VHOST_USER_SET_VRING_KICK = 12, |
| 155 | VHOST_USER_SET_VRING_CALL = 13, |
| 156 | VHOST_USER_SET_VRING_ERR = 14, |
Shesha Sreenivasamurthy | b8f45b3 | 2016-02-03 09:38:36 -0800 | [diff] [blame] | 157 | VHOST_USER_GET_PROTOCOL_FEATURES = 15, |
| 158 | VHOST_USER_SET_PROTOCOL_FEATURES = 16, |
| 159 | VHOST_USER_GET_QUEUE_NUM = 17, |
Yoann Desmouceaux | 4667c22 | 2016-02-24 22:51:00 +0100 | [diff] [blame] | 160 | VHOST_USER_SET_VRING_ENABLE = 18, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | VHOST_USER_MAX |
| 162 | } vhost_user_req_t; |
| 163 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 164 | typedef struct vhost_user_msg { |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 165 | vhost_user_req_t request; |
| 166 | u32 flags; |
| 167 | u32 size; |
| 168 | union |
| 169 | { |
| 170 | u64 u64; |
| 171 | vhost_vring_state_t state; |
| 172 | vhost_vring_addr_t addr; |
| 173 | vhost_user_memory_t memory; |
| 174 | vhost_user_log_t log; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | }; |
| 176 | } __attribute ((packed)) vhost_user_msg_t; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 177 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 179 | typedef struct |
| 180 | { |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 181 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Steven | 9787889 | 2017-08-29 09:23:26 -0700 | [diff] [blame] | 182 | u16 qsz_mask; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 183 | u16 last_avail_idx; |
| 184 | u16 last_used_idx; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 185 | u16 n_since_last_int; |
Steven Luong | bc0d9ff | 2020-03-23 09:34:59 -0700 | [diff] [blame] | 186 | union |
| 187 | { |
| 188 | vring_desc_t *desc; |
| 189 | vring_packed_desc_t *packed_desc; |
| 190 | }; |
| 191 | union |
| 192 | { |
| 193 | vring_avail_t *avail; |
| 194 | vring_desc_event_t *avail_event; |
| 195 | }; |
| 196 | union |
| 197 | { |
| 198 | vring_used_t *used; |
| 199 | vring_desc_event_t *used_event; |
| 200 | }; |
Steven Luong | 4442f7c | 2019-10-02 07:33:48 -0700 | [diff] [blame] | 201 | uword desc_user_addr; |
| 202 | uword used_user_addr; |
| 203 | uword avail_user_addr; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 204 | f64 int_deadline; |
| 205 | u8 started; |
| 206 | u8 enabled; |
| 207 | u8 log_used; |
Steven Luong | 2c1084a | 2020-12-10 20:44:22 -0800 | [diff] [blame] | 208 | clib_spinlock_t vring_lock; |
| 209 | |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 210 | //Put non-runtime in a different cache line |
| 211 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | int errfd; |
| 213 | u32 callfd_idx; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 214 | u32 kickfd_idx; |
| 215 | u64 log_guest_addr; |
Steven | f3b5364 | 2017-05-01 14:03:02 -0700 | [diff] [blame] | 216 | |
| 217 | /* The rx queue policy (interrupt/adaptive/polling) for this queue */ |
| 218 | u32 mode; |
Steven Luong | 67f935e | 2019-02-01 10:23:56 -0800 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * It contains the device queue number. -1 if it does not. The idea is |
| 222 | * to not invoke vnet_hw_interface_assign_rx_thread and |
| 223 | * vnet_hw_interface_unassign_rx_thread more than once for the duration of |
| 224 | * the interface even if it is disconnected and reconnected. |
| 225 | */ |
| 226 | i16 qid; |
Steven Luong | bc0d9ff | 2020-03-23 09:34:59 -0700 | [diff] [blame] | 227 | |
| 228 | u16 used_wrap_counter; |
| 229 | u16 avail_wrap_counter; |
Steven Luong | 27ba500 | 2020-11-17 13:30:44 -0800 | [diff] [blame^] | 230 | |
| 231 | u16 last_kick; |
| 232 | u8 first_kick; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | } vhost_user_vring_t; |
| 234 | |
Steven | 7312cc7 | 2017-03-15 21:18:55 -0700 | [diff] [blame] | 235 | #define VHOST_USER_EVENT_START_TIMER 1 |
Steven | f3b5364 | 2017-05-01 14:03:02 -0700 | [diff] [blame] | 236 | #define VHOST_USER_EVENT_STOP_TIMER 2 |
Steven | 7312cc7 | 2017-03-15 21:18:55 -0700 | [diff] [blame] | 237 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 238 | typedef struct |
| 239 | { |
| 240 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Juraj Sloboda | b192feb | 2018-10-01 12:42:07 +0200 | [diff] [blame] | 241 | u32 is_ready; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | u32 admin_up; |
Pierre Pfister | dbb3c25 | 2016-11-22 10:33:34 +0000 | [diff] [blame] | 243 | u32 unix_server_index; |
Damjan Marion | 56dd543 | 2017-09-08 19:52:02 +0200 | [diff] [blame] | 244 | u32 clib_file_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | char sock_filename[256]; |
| 246 | int sock_errno; |
Steven | 5445f5f | 2017-04-25 16:16:00 -0700 | [diff] [blame] | 247 | uword if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 248 | u32 hw_if_index, sw_if_index; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 249 | |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 250 | //Feature negotiation |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 251 | u64 features; |
| 252 | u64 feature_mask; |
Yoann Desmouceaux | 4667c22 | 2016-02-24 22:51:00 +0100 | [diff] [blame] | 253 | u64 protocol_features; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 254 | |
| 255 | //Memory region information |
| 256 | u32 nregions; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | vhost_user_memory_region_t regions[VHOST_MEMORY_MAX_NREGIONS]; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 258 | void *region_mmap_addr[VHOST_MEMORY_MAX_NREGIONS]; |
Damjan Marion | 3762370 | 2016-09-20 11:25:27 +0200 | [diff] [blame] | 259 | u64 region_guest_addr_lo[VHOST_MEMORY_MAX_NREGIONS]; |
| 260 | u64 region_guest_addr_hi[VHOST_MEMORY_MAX_NREGIONS]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 261 | u32 region_mmap_fd[VHOST_MEMORY_MAX_NREGIONS]; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 262 | |
| 263 | //Virtual rings |
Steven Luong | 2c1084a | 2020-12-10 20:44:22 -0800 | [diff] [blame] | 264 | vhost_user_vring_t *vrings; |
| 265 | |
| 266 | /* |
| 267 | * vrings is a dynamic array. It may have more elements than it is |
| 268 | * currently used. num_qid indicates the current total qid's in the |
| 269 | * vrings. For example, vec_len(vrings) = 64, num_qid = 60, so the |
| 270 | * current valid/used qid is (0, 59) in the vrings array. |
| 271 | */ |
| 272 | u32 num_qid; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 273 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 274 | int virtio_net_hdr_sz; |
| 275 | int is_any_layout; |
Yoann Desmouceaux | 4667c22 | 2016-02-24 22:51:00 +0100 | [diff] [blame] | 276 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 277 | void *log_base_addr; |
Yoann Desmouceaux | 4667c22 | 2016-02-24 22:51:00 +0100 | [diff] [blame] | 278 | u64 log_size; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 279 | |
| 280 | /* Whether to use spinlock or per_cpu_tx_qid assignment */ |
| 281 | u8 use_tx_spinlock; |
| 282 | u16 *per_cpu_tx_qid; |
Steven Luong | 4208a4c | 2019-05-06 08:51:56 -0700 | [diff] [blame] | 283 | |
| 284 | u8 enable_gso; |
Steven Luong | bc0d9ff | 2020-03-23 09:34:59 -0700 | [diff] [blame] | 285 | |
| 286 | /* Packed ring configured */ |
| 287 | u8 enable_packed; |
| 288 | |
Steven Luong | 27ba500 | 2020-11-17 13:30:44 -0800 | [diff] [blame^] | 289 | u8 enable_event_idx; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 290 | } vhost_user_intf_t; |
| 291 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 292 | typedef struct |
| 293 | { |
Pierre Pfister | d3eb90e | 2016-11-29 15:36:14 +0000 | [diff] [blame] | 294 | uword dst; |
| 295 | uword src; |
| 296 | u32 len; |
| 297 | } vhost_copy_t; |
| 298 | |
| 299 | typedef struct |
| 300 | { |
| 301 | u16 qid; /** The interface queue index (Not the virtio vring idx) */ |
| 302 | u16 device_index; /** The device index */ |
| 303 | u32 virtio_ring_flags; /** Runtime queue flags **/ |
| 304 | u16 first_desc_len; /** Length of the first data descriptor **/ |
| 305 | virtio_net_hdr_mrg_rxbuf_t hdr; /** Virtio header **/ |
| 306 | } vhost_trace_t; |
| 307 | |
Pierre Pfister | d3eb90e | 2016-11-29 15:36:14 +0000 | [diff] [blame] | 308 | #define VHOST_USER_RX_BUFFERS_N (2 * VLIB_FRAME_SIZE + 2) |
| 309 | #define VHOST_USER_COPY_ARRAY_N (4 * VLIB_FRAME_SIZE) |
| 310 | |
| 311 | typedef struct |
| 312 | { |
Pierre Pfister | d3eb90e | 2016-11-29 15:36:14 +0000 | [diff] [blame] | 313 | u32 rx_buffers_len; |
| 314 | u32 rx_buffers[VHOST_USER_RX_BUFFERS_N]; |
| 315 | |
| 316 | virtio_net_hdr_mrg_rxbuf_t tx_headers[VLIB_FRAME_SIZE]; |
| 317 | vhost_copy_t copy[VHOST_USER_COPY_ARRAY_N]; |
| 318 | |
| 319 | /* This is here so it doesn't end-up |
| 320 | * using stack or registers. */ |
| 321 | vhost_trace_t *current_trace; |
Steven Luong | bc0d9ff | 2020-03-23 09:34:59 -0700 | [diff] [blame] | 322 | |
| 323 | u32 *to_next_list; |
| 324 | vlib_buffer_t **rx_buffers_pdesc; |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 325 | } vhost_cpu_t; |
| 326 | |
| 327 | typedef struct |
| 328 | { |
Steven | 5445f5f | 2017-04-25 16:16:00 -0700 | [diff] [blame] | 329 | mhash_t if_index_by_sock_name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 330 | u32 mtu_bytes; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 331 | vhost_user_intf_t *vhost_user_interfaces; |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 332 | u32 *show_dev_instance_by_real_dev_instance; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 333 | u32 coalesce_frames; |
| 334 | f64 coalesce_time; |
| 335 | int dont_dump_vhost_user_memory; |
Damjan Marion | 0dafaa7 | 2016-09-20 23:21:02 +0200 | [diff] [blame] | 336 | |
Pierre Pfister | e21c528 | 2016-09-21 08:04:59 +0100 | [diff] [blame] | 337 | /** Per-CPU data for vhost-user */ |
| 338 | vhost_cpu_t *cpus; |
Pierre Pfister | dbb3c25 | 2016-11-22 10:33:34 +0000 | [diff] [blame] | 339 | |
| 340 | /** Pseudo random iterator */ |
| 341 | u32 random; |
Steven | 7312cc7 | 2017-03-15 21:18:55 -0700 | [diff] [blame] | 342 | |
Steven | f3b5364 | 2017-05-01 14:03:02 -0700 | [diff] [blame] | 343 | /* The number of rx interface/queue pairs in interrupt mode */ |
| 344 | u32 ifq_count; |
Steven | 388e51a | 2017-06-01 12:49:23 -0700 | [diff] [blame] | 345 | |
Jerome Tollet | 2f54c27 | 2018-10-02 11:41:11 +0200 | [diff] [blame] | 346 | /* logging */ |
| 347 | vlib_log_class_t log_default; |
Steven Luong | 4208a4c | 2019-05-06 08:51:56 -0700 | [diff] [blame] | 348 | |
| 349 | /* gso interface count */ |
| 350 | u32 gso_count; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | } vhost_user_main_t; |
| 352 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 353 | typedef struct |
| 354 | { |
| 355 | u8 if_name[64]; |
| 356 | u32 sw_if_index; |
| 357 | u32 virtio_net_hdr_sz; |
| 358 | u64 features; |
| 359 | u8 is_server; |
| 360 | u8 sock_filename[256]; |
| 361 | u32 num_regions; |
| 362 | int sock_errno; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 363 | } vhost_user_intf_details_t; |
| 364 | |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 365 | int vhost_user_dump_ifs (vnet_main_t * vnm, vlib_main_t * vm, |
| 366 | vhost_user_intf_details_t ** out_vuids); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | |
Mohsin Kazmi | e7cde31 | 2018-06-26 17:20:11 +0200 | [diff] [blame] | 368 | extern vlib_node_registration_t vhost_user_send_interrupt_node; |
| 369 | extern vnet_device_class_t vhost_user_device_class; |
| 370 | extern vlib_node_registration_t vhost_user_input_node; |
| 371 | extern vhost_user_main_t vhost_user_main; |
| 372 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 373 | #endif |
Damjan Marion | 00a9dca | 2016-08-17 17:05:46 +0200 | [diff] [blame] | 374 | |
| 375 | /* |
| 376 | * fd.io coding-style-patch-verification: ON |
| 377 | * |
| 378 | * Local Variables: |
| 379 | * eval: (c-set-style "gnu") |
| 380 | * End: |
| 381 | */ |