FD.io VPP  v18.07-34-g55fbdb9
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_file_add(a, b) do { \
34  *a = clib_file_add (&file_main, b); \
35  vlib_log_warn ((&memif_main)->log_class, \
36  "clib_file_add fd %d private_data %u idx %u", \
37  (b)->file_descriptor, (b)->private_data, *a); \
38 } while (0)
39 
40 #define memif_file_del(a) do { \
41  vlib_log_warn ((&memif_main)->log_class, \
42  "clib_file_del idx %u",a - file_main.file_pool); \
43  clib_file_del (&file_main, a); \
44 } while (0)
45 
46 #define memif_file_del_by_index(a) do { \
47  vlib_log_warn ((&memif_main)->log_class, "clib_file_del idx %u", a); \
48  clib_file_del_by_index (&file_main, a); \
49 } while (0)
50 
51 typedef struct
52 {
57  int ref_cnt;
59 
60  /* hash of all registered id */
62 
63  /* hash of all registered fds */
66 
67 typedef struct
68 {
69  /* Required for vec_validate_aligned */
70  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
71  void *shm;
73  int fd;
76 
77 typedef struct
78 {
80  int fd;
82 
83 typedef struct
84 {
85  /* ring data */
90 
94 
95  /* interrupts */
96  int int_fd;
99 
100  /* queue type */
102 } memif_queue_t;
103 
104 #define foreach_memif_if_flag \
105  _(0, ADMIN_UP, "admin-up") \
106  _(1, IS_SLAVE, "slave") \
107  _(2, CONNECTING, "connecting") \
108  _(3, CONNECTED, "connected") \
109  _(4, DELETING, "deleting") \
110  _(5, ZERO_COPY, "zero-copy") \
111  _(6, ERROR, "error")
112 
113 typedef enum
114 {
115 #define _(a, b, c) MEMIF_IF_FLAG_##b = (1 << a),
117 #undef _
119 
120 typedef struct
121 {
122  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
130 
132 
133  /* socket connection */
138 
140 
143 
144  /* remote info */
147 
148  struct
149  {
154  } cfg;
155 
156  struct
157  {
158  memif_log2_ring_size_t log2_ring_size;
159  u8 num_s2m_rings;
160  u8 num_m2s_rings;
161  u16 buffer_size;
162  } run;
163 
164  /* disconnect strings */
167 } memif_if_t;
168 
169 typedef struct
170 {
174 
175 typedef struct
176 {
177  void *data;
182 
183 #define MEMIF_RX_VECTOR_SZ VLIB_FRAME_SIZE
184 
185 typedef struct
186 {
187  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
188 
189  /* copy vector */
193 
194  /* buffer template */
198 
199 typedef struct
200 {
201  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
202 
203  /** API message ID base */
205 
206  /* pool of all memory interfaces */
208 
209  /* pool of all unix socket files */
211  uword *socket_file_index_by_sock_id; /* map user socket id to pool idx */
212 
213  /* per thread data */
215 
217 
218 } memif_main_t;
219 
220 extern memif_main_t memif_main;
223 
224 enum
225 {
229 
230 typedef struct
231 {
241  u8 hw_addr[6];
244 
245  /* return */
248 
249 int memif_socket_filename_add_del (u8 is_add, u32 sock_id,
250  u8 * sock_filename);
254 
257 {
258  u16 region = ring->desc[slot].region;
259  return mif->regions[region].shm + ring->desc[slot].offset;
260 }
261 
262 /* memif.c */
265 void memif_disconnect (memif_if_t * mif, clib_error_t * err);
266 
267 /* socket.c */
268 void memif_socket_close (clib_socket_t ** sock);
277  clib_error_t * err);
278 u8 *format_memif_device_name (u8 * s, va_list * args);
279 
280 /*
281  * fd.io coding-style-patch-verification: ON
282  *
283  * Local Variables:
284  * eval: (c-set-style "gnu")
285  * End:
286  */
memif_if_t * interfaces
Definition: private.h:207
vlib_log_class_t log_class
Definition: private.h:216
Definition: mhash.h:46
u32 vlib_log_class_t
Definition: log.h:21
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:63
u8 * secret
Definition: private.h:137
clib_socket_t ** pending_clients
Definition: private.h:56
u8 * format_memif_device_name(u8 *s, va_list *args)
Definition: device.c:51
memif_socket_file_t * socket_files
Definition: private.h:210
unsigned long u64
Definition: types.h:89
memif_log2_ring_size_t log2_ring_size
Definition: private.h:150
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:621
u16 first_buffer_vec_index
Definition: private.h:172
u32 * buffers
Definition: private.h:93
struct _vnet_device_class vnet_device_class_t
u8 num_m2s_rings
Definition: private.h:152
unsigned char u8
Definition: types.h:56
#define static_always_inline
Definition: clib.h:93
u8 * remote_name
Definition: private.h:145
clib_error_t * memif_master_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:507
uword socket_file_index
Definition: private.h:135
u16 buffer_size
Definition: private.h:153
memif_log2_ring_size_t log2_ring_size
Definition: private.h:238
vnet_device_class_t memif_device_class
u32 per_interface_next_index
Definition: private.h:131
memif_region_offset_t offset
Definition: private.h:89
u16 msg_id_base
API message ID base.
Definition: private.h:204
unsigned int u32
Definition: types.h:88
mhash_t dev_instance_by_id
Definition: private.h:61
clib_error_t * memif_master_conn_fd_error(clib_file_t *uf)
Definition: socket.c:611
memif_region_index_t region
Definition: memif.h:151
u16 last_head
Definition: private.h:91
int int_fd
Definition: private.h:96
memif_copy_op_t * copy_ops
Definition: private.h:191
clib_error_t * memif_master_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:572
memif_desc_t desc[0]
Definition: memif.h:173
int memif_delete_if(vlib_main_t *vm, memif_if_t *mif)
Definition: memif.c:660
uword dev_instance
Definition: private.h:128
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:123
unsigned short u16
Definition: types.h:57
void * data
Definition: private.h:177
#define foreach_memif_if_flag
Definition: private.h:104
memif_interface_id_t id
Definition: private.h:232
uword int_clib_file_index
Definition: private.h:97
u8 is_external
Definition: private.h:74
memif_queue_t * tx_queues
Definition: private.h:142
int memif_create_if(vlib_main_t *vm, memif_create_if_args_t *args)
Definition: memif.c:740
vlib_main_t * vm
Definition: buffer.c:294
u8 * local_disc_string
Definition: private.h:165
u16 buffer_vec_index
Definition: private.h:180
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:92
i16 buffer_offset
Definition: private.h:179
memif_ring_type_t type
Definition: private.h:101
memif_region_t * regions
Definition: private.h:139
memif_main_t memif_main
Definition: memif.c:43
memif_msg_t msg
Definition: private.h:79
static_always_inline void * memif_get_buffer(memif_if_t *mif, memif_ring_t *ring, u16 slot)
Definition: private.h:256
u32 flags
Definition: private.h:124
memif_ring_t * ring
Definition: private.h:86
vlib_buffer_t buffer_template
Definition: private.h:195
u32 hw_if_index
Definition: private.h:126
struct _socket_t clib_socket_t
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:589
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
Definition: socket.c:597
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:546
u64 int_count
Definition: private.h:98
memif_region_offset_t offset
Definition: memif.h:153
uword * dev_instance_by_fd
Definition: private.h:64
u8 num_s2m_rings
Definition: private.h:151
struct _vlib_node_registration vlib_node_registration_t
uint64_t memif_region_size_t
Definition: memif.h:62
#define MEMIF_RX_VECTOR_SZ
Definition: private.h:183
u64 uword
Definition: types.h:112
void memif_socket_close(clib_socket_t **sock)
Definition: socket.c:43
void * shm
Definition: private.h:71
u8 * remote_if_name
Definition: private.h:146
memif_interface_id_t id
Definition: private.h:125
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
Definition: memif.c:304
memif_log2_ring_size_t log2_ring_size
Definition: private.h:87
clib_error_t * memif_plugin_api_hookup(vlib_main_t *vm)
Definition: memif_api.c:408
memif_per_thread_data_t * per_thread_data
Definition: private.h:214
u8 * remote_disc_string
Definition: private.h:166
memif_ring_type_t
Definition: memif.h:47
Definition: file.h:51
clib_socket_t * sock
Definition: private.h:134
memif_queue_t * rx_queues
Definition: private.h:141
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:650
memif_desc_t desc_template
Definition: private.h:196
uword * socket_file_index_by_sock_id
Definition: private.h:211
memif_msg_fifo_elt_t * msg_queue
Definition: private.h:136
memif_region_index_t region
Definition: private.h:88
clib_socket_t * sock
Definition: private.h:55
u32 sw_if_index
Definition: private.h:127
enum @456 memif_process_event_t
memif_region_size_t region_size
Definition: private.h:72
signed short i16
Definition: types.h:46
memif_if_flag_t
Definition: private.h:113