FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
private.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vppinfra/lock.h>
19 #include <vlib/log.h>
20 
21 #define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
22 #define MEMIF_DEFAULT_RING_SIZE 1024
23 #define MEMIF_DEFAULT_RX_QUEUES 1
24 #define MEMIF_DEFAULT_TX_QUEUES 1
25 #define MEMIF_DEFAULT_BUFFER_SIZE 2048
26 
27 #define MEMIF_MAX_M2S_RING (vec_len (vlib_mains))
28 #define MEMIF_MAX_S2M_RING 256
29 #define MEMIF_MAX_REGION 256
30 #define MEMIF_MAX_LOG2_RING_SIZE 14
31 
32 
33 #define memif_log_debug(dev, f, ...) do { \
34  memif_if_t *_dev = (memif_if_t *) dev; \
35  if (_dev) \
36  vlib_log(VLIB_LOG_LEVEL_DEBUG, memif_main.log_class, "%U: " f, \
37  format_vnet_hw_if_index_name, vnet_get_main(), \
38  _dev->hw_if_index, ##__VA_ARGS__); \
39  else \
40  vlib_log(VLIB_LOG_LEVEL_DEBUG, memif_main.log_class, f, \
41  ##__VA_ARGS__); \
42 } while (0)
43 
44 #define memif_log_warn(dev, f, ...) do { \
45  memif_if_t *_dev = (memif_if_t *) dev; \
46  if (_dev) \
47  vlib_log(VLIB_LOG_LEVEL_WARNING, memif_main.log_class, "%U: " f, \
48  format_vnet_hw_if_index_name, vnet_get_main(), \
49  _dev->hw_if_index, ##__VA_ARGS__); \
50  else \
51  vlib_log(VLIB_LOG_LEVEL_WARNING, memif_main.log_class, f, \
52  ##__VA_ARGS__); \
53 } while (0)
54 
55 #define memif_log_err(dev, f, ...) do { \
56  memif_if_t *_dev = (memif_if_t *) dev; \
57  if (_dev) \
58  vlib_log(VLIB_LOG_LEVEL_ERR, memif_main.log_class, "%U: " f, \
59  format_vnet_hw_if_index_name, vnet_get_main(), \
60  _dev->hw_if_index, ##__VA_ARGS__); \
61  else \
62  vlib_log(VLIB_LOG_LEVEL_ERR, memif_main.log_class, f, \
63  ##__VA_ARGS__); \
64 } while (0)
65 
66 #define memif_file_add(a, b) do { \
67  *a = clib_file_add (&file_main, b); \
68  memif_log_warn (0, "clib_file_add fd %d private_data %u idx %u", \
69  (b)->file_descriptor, (b)->private_data, *a); \
70 } while (0)
71 
72 #define memif_file_del(a) do { \
73  memif_log_warn (0, "clib_file_del idx %u", a - file_main.file_pool); \
74  clib_file_del (&file_main, a); \
75 } while (0)
76 
77 #define memif_file_del_by_index(a) do { \
78  memif_log_warn (0, "clib_file_del idx %u", a); \
79  clib_file_del_by_index (&file_main, a); \
80 } while (0)
81 
82 typedef struct
83 {
88  int ref_cnt;
90 
91  /* hash of all registered id */
93 
94  /* hash of all registered fds */
97 
98 typedef struct
99 {
100  /* Required for vec_validate_aligned */
101  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
102  void *shm;
104  int fd;
107 
108 typedef struct
109 {
111  int fd;
113 
114 typedef struct
115 {
116  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
117  /* ring data */
122 
126 
127  /* interrupts */
128  int int_fd;
131 
132  /* queue type */
134 } memif_queue_t;
135 
136 #define foreach_memif_if_flag \
137  _(0, ADMIN_UP, "admin-up") \
138  _(1, IS_SLAVE, "slave") \
139  _(2, CONNECTING, "connecting") \
140  _(3, CONNECTED, "connected") \
141  _(4, DELETING, "deleting") \
142  _(5, ZERO_COPY, "zero-copy") \
143  _(6, ERROR, "error")
144 
145 typedef enum
146 {
147 #define _(a, b, c) MEMIF_IF_FLAG_##b = (1 << a),
149 #undef _
151 
152 typedef struct
153 {
154  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
162 
164 
165  /* socket connection */
170 
172 
175 
176  /* remote info */
179 
180  struct
181  {
186  } cfg;
187 
188  struct
189  {
190  memif_log2_ring_size_t log2_ring_size;
191  u8 num_s2m_rings;
192  u8 num_m2s_rings;
193  u16 buffer_size;
194  } run;
195 
196  /* disconnect strings */
199 } memif_if_t;
200 
201 typedef struct
202 {
206 
207 typedef struct
208 {
209  CLIB_ALIGN_MARK (pad, 16); /* align up to 16 bytes for 32bit builds */
210  void *data;
215 
216 #define MEMIF_RX_VECTOR_SZ VLIB_FRAME_SIZE
217 
218 typedef struct
219 {
220  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
221 
222  /* copy vector */
226 
227  /* buffer template */
231 
232 typedef struct
233 {
234  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
235 
236  /** API message ID base */
238 
239  /* pool of all memory interfaces */
241 
242  /* pool of all unix socket files */
244  uword *socket_file_index_by_sock_id; /* map user socket id to pool idx */
245 
246  /* per thread data */
248 
250 
251 } memif_main_t;
252 
253 extern memif_main_t memif_main;
256 
257 enum
258 {
262 
263 typedef struct
264 {
274  u8 hw_addr[6];
277 
278  /* return */
281 
282 int memif_socket_filename_add_del (u8 is_add, u32 sock_id,
283  u8 * sock_filename);
287 
290 {
291  u16 region = ring->desc[slot].region;
292  return mif->regions[region].shm + ring->desc[slot].offset;
293 }
294 
295 /* memif.c */
298 void memif_disconnect (memif_if_t * mif, clib_error_t * err);
299 
300 /* socket.c */
301 void memif_socket_close (clib_socket_t ** sock);
310  clib_error_t * err);
311 u8 *format_memif_device_name (u8 * s, va_list * args);
312 
313 
314 /*
315  * fd.io coding-style-patch-verification: ON
316  *
317  * Local Variables:
318  * eval: (c-set-style "gnu")
319  * End:
320  */
memif_if_t * interfaces
Definition: private.h:240
vlib_log_class_t log_class
Definition: private.h:249
Definition: mhash.h:46
u32 vlib_log_class_t
Definition: log.h:21
u8 pad[3]
log2 (size of the packing page block)
Definition: bihash_doc.h:61
vlib_node_registration_t memif_input_node
(constructor) VLIB_REGISTER_NODE (memif_input_node)
Definition: node.c:913
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
u8 * secret
Definition: private.h:169
clib_socket_t ** pending_clients
Definition: private.h:87
u8 * format_memif_device_name(u8 *s, va_list *args)
Definition: device.c:51
memif_socket_file_t * socket_files
Definition: private.h:243
unsigned long u64
Definition: types.h:89
memif_log2_ring_size_t log2_ring_size
Definition: private.h:182
void memif_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: memif.c:69
memif_interface_mode_t
Definition: memif.h:53
uint16_t memif_region_index_t
Definition: memif.h:60
enum @496 memif_process_event_t
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: socket.c:190
memif_interface_mode_t mode
Definition: private.h:270
int memif_socket_filename_add_del(u8 is_add, u32 sock_id, u8 *sock_filename)
Definition: memif.c:619
u16 first_buffer_vec_index
Definition: private.h:204
u32 * buffers
Definition: private.h:125
struct _vnet_device_class vnet_device_class_t
u8 num_m2s_rings
Definition: private.h:184
unsigned char u8
Definition: types.h:56
#define static_always_inline
Definition: clib.h:99
u8 * remote_name
Definition: private.h:177
clib_error_t * memif_master_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:506
uword socket_file_index
Definition: private.h:167
u16 buffer_size
Definition: private.h:185
memif_log2_ring_size_t log2_ring_size
Definition: private.h:271
vnet_device_class_t memif_device_class
u32 per_interface_next_index
Definition: private.h:163
memif_region_offset_t offset
Definition: private.h:121
u16 msg_id_base
API message ID base.
Definition: private.h:237
unsigned int u32
Definition: types.h:88
void * shm
Definition: private.h:102
mhash_t dev_instance_by_id
Definition: private.h:92
clib_error_t * memif_master_conn_fd_error(clib_file_t *uf)
Definition: socket.c:610
memif_region_index_t region
Definition: memif.h:151
u16 last_head
Definition: private.h:123
memif_copy_op_t * copy_ops
Definition: private.h:224
clib_error_t * memif_master_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:571
memif_desc_t desc[0]
Definition: memif.h:173
int memif_delete_if(vlib_main_t *vm, memif_if_t *mif)
Definition: memif.c:698
uword dev_instance
Definition: private.h:160
uint32_t memif_region_offset_t
Definition: memif.h:61
uint8_t memif_log2_ring_size_t
Definition: memif.h:66
clib_spinlock_t lockp
Definition: private.h:155
unsigned short u16
Definition: types.h:57
void * data
Definition: private.h:210
#define foreach_memif_if_flag
Definition: private.h:136
memif_interface_id_t id
Definition: private.h:265
uword int_clib_file_index
Definition: private.h:129
memif_queue_t * tx_queues
Definition: private.h:174
int memif_create_if(vlib_main_t *vm, memif_create_if_args_t *args)
Definition: memif.c:778
vlib_main_t * vm
Definition: buffer.c:301
u8 * local_disc_string
Definition: private.h:197
u16 buffer_vec_index
Definition: private.h:213
clib_error_t * memif_connect(memif_if_t *mif)
Definition: memif.c:186
uint32_t memif_interface_id_t
Definition: memif.h:64
u16 last_tail
Definition: private.h:124
i16 buffer_offset
Definition: private.h:212
memif_ring_type_t type
Definition: private.h:133
memif_region_t * regions
Definition: private.h:171
memif_main_t memif_main
Definition: memif.c:43
memif_msg_t msg
Definition: private.h:110
static_always_inline void * memif_get_buffer(memif_if_t *mif, memif_ring_t *ring, u16 slot)
Definition: private.h:289
u32 flags
Definition: private.h:156
memif_ring_t * ring
Definition: private.h:118
vlib_buffer_t buffer_template
Definition: private.h:228
u32 hw_if_index
Definition: private.h:158
struct _socket_t clib_socket_t
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:588
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
Definition: socket.c:596
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:545
u64 int_count
Definition: private.h:130
memif_region_offset_t offset
Definition: memif.h:153
uword * dev_instance_by_fd
Definition: private.h:95
u8 num_s2m_rings
Definition: private.h:183
struct _vlib_node_registration vlib_node_registration_t
#define CLIB_ALIGN_MARK(name, alignment)
Definition: clib.h:85
uint64_t memif_region_size_t
Definition: memif.h:62
#define MEMIF_RX_VECTOR_SZ
Definition: private.h:216
u64 uword
Definition: types.h:112
void memif_socket_close(clib_socket_t **sock)
Definition: socket.c:43
u8 * remote_if_name
Definition: private.h:178
memif_interface_id_t id
Definition: private.h:157
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
Definition: memif.c:303
memif_log2_ring_size_t log2_ring_size
Definition: private.h:119
clib_error_t * memif_plugin_api_hookup(vlib_main_t *vm)
Definition: memif_api.c:374
memif_per_thread_data_t * per_thread_data
Definition: private.h:247
u8 * remote_disc_string
Definition: private.h:198
memif_ring_type_t
Definition: memif.h:47
Definition: file.h:51
clib_socket_t * sock
Definition: private.h:166
memif_queue_t * rx_queues
Definition: private.h:173
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:649
memif_desc_t desc_template
Definition: private.h:229
uword * socket_file_index_by_sock_id
Definition: private.h:244
memif_msg_fifo_elt_t * msg_queue
Definition: private.h:168
memif_region_index_t region
Definition: private.h:120
clib_socket_t * sock
Definition: private.h:86
u32 sw_if_index
Definition: private.h:159
memif_interface_mode_t mode
Definition: private.h:161
memif_region_size_t region_size
Definition: private.h:103
signed short i16
Definition: types.h:46
memif_if_flag_t
Definition: private.h:145