FD.io VPP  v18.01.2-1-g9b554f3
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 {
70  int ref_cnt;
72 
73  /* hash of all registered id */
75 
76  /* hash of all registered fds */
79 
80 typedef struct
81 {
82  void *shm;
84  int fd;
86 
87 typedef struct
88 {
90  int fd;
92 
93 typedef struct
94 {
95  /* ring data */
100 
103 
104  /* interrupts */
105  int int_fd;
108 
109  /* queue type */
111 } memif_queue_t;
112 
113 #define foreach_memif_if_flag \
114  _(0, ADMIN_UP, "admin-up") \
115  _(1, IS_SLAVE, "slave") \
116  _(2, CONNECTING, "connecting") \
117  _(3, CONNECTED, "connected") \
118  _(4, DELETING, "deleting")
119 
120 typedef enum
121 {
122 #define _(a, b, c) MEMIF_IF_FLAG_##b = (1 << a),
124 #undef _
126 
127 typedef struct
128 {
129  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
137 
139 
140  /* socket connection */
145 
147 
150 
151  /* remote info */
154 
155  struct
156  {
161  } cfg;
162 
163  struct
164  {
165  memif_log2_ring_size_t log2_ring_size;
166  u8 num_s2m_rings;
167  u8 num_m2s_rings;
168  u16 buffer_size;
169  } run;
170 
171  /* disconnect strings */
174 } memif_if_t;
175 
176 typedef struct
177 {
178  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
179 
180  /** API message ID base */
182 
183  /* pool of all memory interfaces */
185 
186  /* pool of all unix socket files */
189 
190  /* rx buffer cache */
192 
193 } memif_main_t;
194 
195 extern memif_main_t memif_main;
198 
199 enum
200 {
204 
205 typedef struct
206 {
215  u8 hw_addr[6];
218 
219  /* return */
222 
226 
229 {
230  u16 region = ring->desc[slot].region;
231  return mif->regions[region].shm + ring->desc[slot].offset;
232 }
233 
234 /* memif.c */
237 void memif_disconnect (memif_if_t * mif, clib_error_t * err);
238 
239 /* socket.c */
240 void memif_socket_close (clib_socket_t ** sock);
249  clib_error_t * err);
250 u8 *format_memif_device_name (u8 * s, va_list * args);
251 
252 /*
253  * fd.io coding-style-patch-verification: ON
254  *
255  * Local Variables:
256  * eval: (c-set-style "gnu")
257  * End:
258  */
memif_if_t * interfaces
Definition: private.h:184
Definition: mhash.h:46
vlib_node_registration_t memif_input_node
(constructor) VLIB_REGISTER_NODE (memif_input_node)
Definition: node.c:575
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:68
u8 * secret
Definition: private.h:144
clib_socket_t ** pending_clients
Definition: private.h:69
u8 * format_memif_device_name(u8 *s, va_list *args)
Definition: device.c:52
mhash_t socket_file_index_by_filename
Definition: private.h:188
memif_socket_file_t * socket_files
Definition: private.h:187
memif_log2_ring_size_t log2_ring_size
Definition: private.h:157
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
struct _vlib_node_registration vlib_node_registration_t
clib_error_t * memif_msg_send_disconnect(memif_if_t *mif, clib_error_t *err)
Definition: socket.c:189
struct _vnet_device_class vnet_device_class_t
u8 num_m2s_rings
Definition: private.h:159
#define static_always_inline
Definition: clib.h:93
u8 * remote_name
Definition: private.h:152
clib_error_t * memif_master_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:491
uword socket_file_index
Definition: private.h:142
u16 buffer_size
Definition: private.h:160
memif_log2_ring_size_t log2_ring_size
Definition: private.h:212
vnet_device_class_t memif_device_class
u32 per_interface_next_index
Definition: private.h:138
memif_region_offset_t offset
Definition: private.h:99
u16 msg_id_base
API message ID base.
Definition: private.h:181
unsigned long u64
Definition: types.h:89
mhash_t dev_instance_by_id
Definition: private.h:74
clib_error_t * memif_master_conn_fd_error(clib_file_t *uf)
Definition: socket.c:595
memif_region_index_t region
Definition: memif.h:150
enum @364 memif_process_event_t
u16 last_head
Definition: private.h:101
clib_error_t * memif_master_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:556
memif_desc_t desc[0]
Definition: memif.h:174
int memif_delete_if(vlib_main_t *vm, memif_if_t *mif)
Definition: memif.c:468
uword dev_instance
Definition: private.h:135
uint8_t memif_log2_ring_size_t
Definition: memif.h:66
clib_spinlock_t lockp
Definition: private.h:130
#define foreach_memif_if_flag
Definition: private.h:113
memif_interface_id_t id
Definition: private.h:207
uword int_clib_file_index
Definition: private.h:106
memif_queue_t * tx_queues
Definition: private.h:149
int memif_create_if(vlib_main_t *vm, memif_create_if_args_t *args)
Definition: memif.c:548
vlib_main_t * vm
Definition: buffer.c:283
u8 * local_disc_string
Definition: private.h:172
clib_error_t * memif_connect(memif_if_t *mif)
Definition: memif.c:175
uint32_t memif_interface_id_t
Definition: memif.h:64
u16 last_tail
Definition: private.h:102
memif_ring_type_t type
Definition: private.h:110
memif_region_t * regions
Definition: private.h:146
u32 ** rx_buffers
Definition: private.h:191
memif_main_t memif_main
Definition: memif.c:43
unsigned int u32
Definition: types.h:88
memif_msg_t msg
Definition: private.h:89
static_always_inline void * memif_get_buffer(memif_if_t *mif, memif_ring_t *ring, u16 slot)
Definition: private.h:228
u32 flags
Definition: private.h:131
memif_ring_t * ring
Definition: private.h:96
u32 hw_if_index
Definition: private.h:133
struct _socket_t clib_socket_t
clib_error_t * memif_slave_conn_fd_write_ready(clib_file_t *uf)
Definition: socket.c:573
clib_error_t * memif_slave_conn_fd_error(clib_file_t *uf)
Definition: socket.c:581
clib_error_t * memif_slave_conn_fd_read_ready(clib_file_t *uf)
Definition: socket.c:530
u64 int_count
Definition: private.h:107
u64 uword
Definition: types.h:112
memif_region_offset_t offset
Definition: memif.h:154
uword * dev_instance_by_fd
Definition: private.h:77
u8 num_s2m_rings
Definition: private.h:158
unsigned short u16
Definition: types.h:57
uint64_t memif_region_size_t
Definition: memif.h:62
unsigned char u8
Definition: types.h:56
void memif_socket_close(clib_socket_t **sock)
Definition: socket.c:43
void * shm
Definition: private.h:82
u8 * remote_if_name
Definition: private.h:153
memif_interface_id_t id
Definition: private.h:132
clib_error_t * memif_init_regions_and_queues(memif_if_t *mif)
Definition: memif.c:266
memif_log2_ring_size_t log2_ring_size
Definition: private.h:97
clib_error_t * memif_plugin_api_hookup(vlib_main_t *vm)
Definition: memif_api.c:311
u8 * remote_disc_string
Definition: private.h:173
memif_ring_type_t
Definition: memif.h:47
Definition: file.h:50
clib_socket_t * sock
Definition: private.h:141
memif_queue_t * rx_queues
Definition: private.h:148
clib_error_t * memif_conn_fd_accept_ready(clib_file_t *uf)
Definition: socket.c:633
uint64_t memif_region_offset_t
Definition: memif.h:61
memif_msg_fifo_elt_t * msg_queue
Definition: private.h:143
memif_region_index_t region
Definition: private.h:98
clib_socket_t * sock
Definition: private.h:68
u32 sw_if_index
Definition: private.h:134
memif_region_size_t region_size
Definition: private.h:83
memif_if_flag_t
Definition: private.h:120