FD.io VPP  v18.04-17-g3a0d853
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 
20 #define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
21 #define MEMIF_DEFAULT_RING_SIZE 1024
22 #define MEMIF_DEFAULT_RX_QUEUES 1
23 #define MEMIF_DEFAULT_TX_QUEUES 1
24 #define MEMIF_DEFAULT_BUFFER_SIZE 2048
25 
26 #define MEMIF_MAX_M2S_RING (vec_len (vlib_mains) - 1)
27 #define MEMIF_MAX_S2M_RING (vec_len (vlib_mains) - 1)
28 #define MEMIF_MAX_REGION 255
29 #define MEMIF_MAX_LOG2_RING_SIZE 14
30 
31 #define MEMIF_DEBUG 0
32 
33 #if MEMIF_DEBUG == 1
34 #define DBG(...) clib_warning(__VA_ARGS__)
35 #define DBG_UNIX_LOG(...) clib_unix_warning(__VA_ARGS__)
36 #else
37 #define DBG(...)
38 #define DBG_UNIX_LOG(...)
39 #endif
40 
41 #if MEMIF_DEBUG == 1
42 #define memif_file_add(a, b) do { \
43  *a = clib_file_add (&file_main, b); \
44  clib_warning ("clib_file_add fd %d private_data %u idx %u", \
45  (b)->file_descriptor, (b)->private_data, *a); \
46 } while (0)
47 
48 #define memif_file_del(a) do { \
49  clib_warning ("clib_file_del idx %u",a - file_main.file_pool); \
50  clib_file_del (&file_main, a); \
51 } while (0)
52 
53 #define memif_file_del_by_index(a) do { \
54  clib_warning ("clib_file_del idx %u", a); \
55  clib_file_del_by_index (&file_main, a); \
56 } while (0)
57 #else
58 #define memif_file_add(a, b) do { \
59  *a = clib_file_add (&file_main, b); \
60 } while (0)
61 #define memif_file_del(a) clib_file_del(&file_main, a)
62 #define memif_file_del_by_index(a) clib_file_del_by_index(&file_main, a)
63 #endif
64 
65 typedef struct
66 {
71  int ref_cnt;
73 
74  /* hash of all registered id */
76 
77  /* hash of all registered fds */
80 
81 typedef struct
82 {
83  /* Required for vec_validate_aligned */
84  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
85  void *shm;
87  int fd;
90 
91 typedef struct
92 {
94  int fd;
96 
97 typedef struct
98 {
99  /* ring data */
104 
108 
109  /* interrupts */
110  int int_fd;
113 
114  /* queue type */
116 } memif_queue_t;
117 
118 #define foreach_memif_if_flag \
119  _(0, ADMIN_UP, "admin-up") \
120  _(1, IS_SLAVE, "slave") \
121  _(2, CONNECTING, "connecting") \
122  _(3, CONNECTED, "connected") \
123  _(4, DELETING, "deleting") \
124  _(5, ZERO_COPY, "zero-copy") \
125  _(6, ERROR, "error")
126 
127 typedef enum
128 {
129 #define _(a, b, c) MEMIF_IF_FLAG_##b = (1 << a),
131 #undef _
133 
134 typedef struct
135 {
136  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
144 
146 
147  /* socket connection */
152 
154 
157 
158  /* remote info */
161 
162  struct
163  {
168  } cfg;
169 
170  struct
171  {
172  memif_log2_ring_size_t log2_ring_size;
173  u8 num_s2m_rings;
174  u8 num_m2s_rings;
175  u16 buffer_size;
176  } run;
177 
178  /* disconnect strings */
181 } memif_if_t;
182 
183 typedef struct
184 {
188 
189 typedef struct
190 {
191  void *data;
196 
197 #define MEMIF_RX_VECTOR_SZ VLIB_FRAME_SIZE
198 
199 typedef struct
200 {
201  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
202 
203  /* copy vector */
207 
208  /* buffer template */
212 
213 typedef struct
214 {
215  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
216 
217  /** API message ID base */
219 
220  /* pool of all memory interfaces */
222 
223  /* pool of all unix socket files */
225  uword *socket_file_index_by_sock_id; /* map user socket id to pool idx */
226 
227  /* per thread data */
229 
230 } memif_main_t;
231 
232 extern memif_main_t memif_main;
235 
236 enum
237 {
241 
242 typedef struct
243 {
253  u8 hw_addr[6];
256 
257  /* return */
260 
261 int memif_socket_filename_add_del (u8 is_add, u32 sock_id,
262  u8 * sock_filename);
266 
269 {
270  u16 region = ring->desc[slot].region;
271  return mif->regions[region].shm + ring->desc[slot].offset;
272 }
273 
274 /* memif.c */
277 void memif_disconnect (memif_if_t * mif, clib_error_t * err);
278 
279 /* socket.c */
280 void memif_socket_close (clib_socket_t ** sock);
289  clib_error_t * err);
290 u8 *format_memif_device_name (u8 * s, va_list * args);
291 
292 /*
293  * fd.io coding-style-patch-verification: ON
294  *
295  * Local Variables:
296  * eval: (c-set-style "gnu")
297  * End:
298  */
memif_if_t * interfaces
Definition: private.h:221
Definition: mhash.h:46
vlib_node_registration_t memif_input_node
(constructor) VLIB_REGISTER_NODE (memif_input_node)
Definition: node.c:915
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
u8 * secret
Definition: private.h:151
clib_socket_t ** pending_clients
Definition: private.h:70
u8 * format_memif_device_name(u8 *s, va_list *args)
Definition: device.c:51
memif_socket_file_t * socket_files
Definition: private.h:224
memif_log2_ring_size_t log2_ring_size
Definition: private.h:164
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
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: socket.c:190
int memif_socket_filename_add_del(u8 is_add, u32 sock_id, u8 *sock_filename)
Definition: memif.c:590
u16 first_buffer_vec_index
Definition: private.h:186
u32 * buffers
Definition: private.h:107
struct _vnet_device_class vnet_device_class_t
u8 num_m2s_rings
Definition: private.h:166
#define static_always_inline
Definition: clib.h:93
u8 * remote_name
Definition: private.h:159
clib_error_t * memif_master_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:501
uword socket_file_index
Definition: private.h:149
u16 buffer_size
Definition: private.h:167
memif_log2_ring_size_t log2_ring_size
Definition: private.h:250
vnet_device_class_t memif_device_class
u32 per_interface_next_index
Definition: private.h:145
memif_region_offset_t offset
Definition: private.h:103
u16 msg_id_base
API message ID base.
Definition: private.h:218
unsigned long u64
Definition: types.h:89
mhash_t dev_instance_by_id
Definition: private.h:75
clib_error_t * memif_master_conn_fd_error(clib_file_t *uf)
Definition: socket.c:605
memif_region_index_t region
Definition: memif.h:151
u16 last_head
Definition: private.h:105
memif_copy_op_t * copy_ops
Definition: private.h:205
clib_error_t * memif_master_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:566
memif_desc_t desc[0]
Definition: memif.h:173
int memif_delete_if(vlib_main_t *vm, memif_if_t *mif)
Definition: memif.c:629
enum @422 memif_process_event_t
uword dev_instance
Definition: private.h:142
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:137
void * data
Definition: private.h:191
#define foreach_memif_if_flag
Definition: private.h:118
memif_interface_id_t id
Definition: private.h:244
uword int_clib_file_index
Definition: private.h:111
u8 is_external
Definition: private.h:88
memif_queue_t * tx_queues
Definition: private.h:156
int memif_create_if(vlib_main_t *vm, memif_create_if_args_t *args)
Definition: memif.c:706
vlib_main_t * vm
Definition: buffer.c:294
u8 * local_disc_string
Definition: private.h:179
u16 buffer_vec_index
Definition: private.h:194
clib_error_t * memif_connect(memif_if_t *mif)
Definition: memif.c:181
uint32_t memif_interface_id_t
Definition: memif.h:64
u16 last_tail
Definition: private.h:106
i16 buffer_offset
Definition: private.h:193
memif_ring_type_t type
Definition: private.h:115
memif_region_t * regions
Definition: private.h:153
memif_main_t memif_main
Definition: memif.c:43
unsigned int u32
Definition: types.h:88
memif_msg_t msg
Definition: private.h:93
static_always_inline void * memif_get_buffer(memif_if_t *mif, memif_ring_t *ring, u16 slot)
Definition: private.h:268
u32 flags
Definition: private.h:138
memif_ring_t * ring
Definition: private.h:100
vlib_buffer_t buffer_template
Definition: private.h:209
u32 hw_if_index
Definition: private.h:140
struct _socket_t clib_socket_t
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:583
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
Definition: socket.c:591
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:540
u64 int_count
Definition: private.h:112
u64 uword
Definition: types.h:112
memif_region_offset_t offset
Definition: memif.h:153
uword * dev_instance_by_fd
Definition: private.h:78
u8 num_s2m_rings
Definition: private.h:165
struct _vlib_node_registration vlib_node_registration_t
unsigned short u16
Definition: types.h:57
uint64_t memif_region_size_t
Definition: memif.h:62
#define MEMIF_RX_VECTOR_SZ
Definition: private.h:197
unsigned char u8
Definition: types.h:56
void memif_socket_close(clib_socket_t **sock)
Definition: socket.c:43
void * shm
Definition: private.h:85
u8 * remote_if_name
Definition: private.h:160
memif_interface_id_t id
Definition: private.h:139
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
Definition: memif.c:281
memif_log2_ring_size_t log2_ring_size
Definition: private.h:101
clib_error_t * memif_plugin_api_hookup(vlib_main_t *vm)
Definition: memif_api.c:408
short i16
Definition: types.h:46
memif_per_thread_data_t * per_thread_data
Definition: private.h:228
u8 * remote_disc_string
Definition: private.h:180
memif_ring_type_t
Definition: memif.h:47
Definition: file.h:51
clib_socket_t * sock
Definition: private.h:148
memif_queue_t * rx_queues
Definition: private.h:155
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:643
memif_desc_t desc_template
Definition: private.h:210
uword * socket_file_index_by_sock_id
Definition: private.h:225
memif_msg_fifo_elt_t * msg_queue
Definition: private.h:150
memif_region_index_t region
Definition: private.h:102
clib_socket_t * sock
Definition: private.h:69
u32 sw_if_index
Definition: private.h:141
memif_region_size_t region_size
Definition: private.h:86
memif_if_flag_t
Definition: private.h:127