2 *------------------------------------------------------------------
3 * Copyright (c) 2016 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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
21 #define MEMIF_VERSION_MAJOR 0
22 #define MEMIF_VERSION_MINOR 1
23 #define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
25 #define MEMIF_MSG_TYPE_CONNECT_REQ 0
26 #define MEMIF_MSG_TYPE_CONNECT_RESP 1
27 #define MEMIF_MSG_TYPE_DISCONNECT 2
29 /* Connection-request parameters: */
32 #define MEMIF_DEFAULT_RING_SIZE 1024
36 #define MEMIF_DEFAULT_BUFFER_SIZE 2048
39 /* Connection-response parameters: */
43 typedef struct __attribute__ ((packed))
46 #define MEMIF_DESC_FLAG_NEXT (1 << 0)
55 STATIC_ASSERT_SIZEOF (memif_desc_t, 32);
59 u16 head __attribute__ ((aligned (128)));
60 u16 tail __attribute__ ((aligned (128)));
61 memif_desc_t desc[0] __attribute__ ((aligned (128)));
66 u32 cookie __attribute__ ((aligned (128)));
94 memif_file_t connection;
96 } memif_pending_conn_t;
100 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
103 #define MEMIF_IF_FLAG_ADMIN_UP (1 << 0)
104 #define MEMIF_IF_FLAG_IS_SLAVE (1 << 1)
105 #define MEMIF_IF_FLAG_CONNECTING (1 << 2)
106 #define MEMIF_IF_FLAG_CONNECTED (1 << 3)
107 #define MEMIF_IF_FLAG_DELETING (1 << 4)
114 u32 per_interface_next_index;
116 uword listener_index;
117 memif_file_t connection;
118 memif_file_t interrupt_line;
128 memif_ring_data_t *ring_data;
137 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
139 /** API message ID base */
142 /* pool of all memory interfaces */
143 memif_if_t *interfaces;
145 /* pool of all listeners */
146 memif_listener_t *listeners;
148 /* pool of pending connections */
149 memif_pending_conn_t *pending_conns;
151 /* bitmap of pending rx interfaces */
152 uword *pending_input_bitmap;
154 /* rx buffer cache */
157 /* hash of all registered keys */
158 mhash_t if_index_by_key;
160 /* first cpu index */
161 u32 input_cpu_first_index;
163 /* total cpu count */
167 u8 *default_socket_filename;
168 #define MEMIF_DEFAULT_SOCKET_FILENAME "/var/vpp/memif.sock"
171 extern memif_main_t memif_main;
172 extern vnet_device_class_t memif_device_class;
173 extern vlib_node_registration_t memif_input_node;
177 MEMIF_PROCESS_EVENT_START = 1,
178 MEMIF_PROCESS_EVENT_STOP = 2,
179 } memif_process_event_t;
193 } memif_create_if_args_t;
195 int memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args);
196 int memif_delete_if (vlib_main_t * vm, u64 key);
197 clib_error_t *memif_plugin_api_hookup (vlib_main_t * vm);
199 #ifndef __NR_memfd_create
200 #if defined __x86_64__
201 #define __NR_memfd_create 319
202 #elif defined __arm__
203 #define __NR_memfd_create 385
204 #elif defined __aarch64__
205 #define __NR_memfd_create 279
207 #error "__NR_memfd_create unknown for this architecture"
212 memfd_create (const char *name, unsigned int flags)
214 return syscall (__NR_memfd_create, name, flags);
223 static_always_inline memif_ring_t *
224 memif_get_ring (memif_if_t * mif, memif_ring_type_t type, u16 ring_num)
226 if (vec_len (mif->regions) == 0)
228 void *p = mif->regions[0];
230 sizeof (memif_ring_t) +
231 sizeof (memif_desc_t) * (1 << mif->log2_ring_size);
232 p += sizeof (memif_shm_t);
233 p += (ring_num + type * mif->num_s2m_rings) * ring_size;
235 return (memif_ring_t *) p;
238 static_always_inline void *
239 memif_get_buffer (memif_if_t * mif, memif_ring_t * ring, u16 slot)
241 u16 region = ring->desc[slot].region;
242 return mif->regions[region] + ring->desc[slot].offset;
245 #ifndef F_LINUX_SPECIFIC_BASE
246 #define F_LINUX_SPECIFIC_BASE 1024
248 #define MFD_ALLOW_SEALING 0x0002U
249 #define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
250 #define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
252 #define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
253 #define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
254 #define F_SEAL_GROW 0x0004 /* prevent file from growing */
255 #define F_SEAL_WRITE 0x0008 /* prevent writes */
258 * fd.io coding-style-patch-verification: ON
261 * eval: (c-set-style "gnu")