FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
memif.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 #ifndef _MEMIF_H_
19 #define _MEMIF_H_
20 
21 #ifndef MEMIF_CACHELINE_SIZE
22 #define MEMIF_CACHELINE_SIZE 64
23 #endif
24 
25 #define MEMIF_COOKIE 0x3E31F20
26 #define MEMIF_VERSION_MAJOR 2
27 #define MEMIF_VERSION_MINOR 0
28 #define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
29 
30 #define MEMIF_SECRET_SIZE 24
31 
32 /*
33  * Type definitions
34  */
35 
36 typedef enum memif_msg_type
37 {
48 
49 typedef enum
50 {
54 
55 typedef enum
56 {
61 
62 typedef uint16_t memif_region_index_t;
63 typedef uint32_t memif_region_offset_t;
64 typedef uint64_t memif_region_size_t;
65 typedef uint16_t memif_ring_index_t;
66 typedef uint32_t memif_interface_id_t;
67 typedef uint16_t memif_version_t;
68 typedef uint8_t memif_log2_ring_size_t;
69 
70 /*
71  * Socket messages
72  */
73 
74 typedef struct __attribute__ ((packed))
75 {
76  uint8_t name[32];
84 
85 typedef struct __attribute__ ((packed))
86 {
90  uint8_t secret[MEMIF_SECRET_SIZE];
91  uint8_t name[32];
93 
94 typedef struct __attribute__ ((packed))
95 {
99 
100 typedef struct __attribute__ ((packed))
101 {
102  uint16_t flags;
103 #define MEMIF_MSG_ADD_RING_FLAG_S2M (1 << 0)
108  uint16_t private_hdr_size; /* used for private metadata */
110 
111 typedef struct __attribute__ ((packed))
112 {
113  uint8_t if_name[32];
115 
116 typedef struct __attribute__ ((packed))
117 {
118  uint8_t if_name[32];
120 
121 typedef struct __attribute__ ((packed))
122 {
123  uint32_t code;
124  uint8_t string[96];
126 
127 typedef struct __attribute__ ((packed, aligned (128)))
128 {
130  union
131  {
139  };
140 } memif_msg_t;
141 
142 _Static_assert (sizeof (memif_msg_t) == 128,
143  "Size of memif_msg_t must be 128");
144 
145 /*
146  * Ring and Descriptor Layout
147  */
148 
149 typedef struct __attribute__ ((packed))
150 {
151  uint16_t flags;
152 #define MEMIF_DESC_FLAG_NEXT (1 << 0)
154  uint32_t length;
156  uint32_t metadata;
157 } memif_desc_t;
158 
159 _Static_assert (sizeof (memif_desc_t) == 16,
160  "Size of memif_dsct_t must be 16 bytes");
161 
162 #define MEMIF_CACHELINE_ALIGN_MARK(mark) \
163  uint8_t mark[0] __attribute__((aligned(MEMIF_CACHELINE_SIZE)))
164 
165 typedef struct
166 {
167  MEMIF_CACHELINE_ALIGN_MARK (cacheline0);
168  uint32_t cookie;
169  uint16_t flags;
170 #define MEMIF_RING_FLAG_MASK_INT 1
171  volatile uint16_t head;
172  MEMIF_CACHELINE_ALIGN_MARK (cacheline1);
173  volatile uint16_t tail;
174  MEMIF_CACHELINE_ALIGN_MARK (cacheline2);
175  memif_desc_t desc[];
176 } memif_ring_t;
177 
178 #endif /* _MEMIF_H_ */
179 
180 /*
181  * fd.io coding-style-patch-verification: ON
182  *
183  * Local Variables:
184  * eval: (c-set-style "gnu")
185  * End:
186  */
MEMIF_MSG_TYPE_DISCONNECT
@ MEMIF_MSG_TYPE_DISCONNECT
Definition: memif.h:46
memif_msg_disconnect_t::code
uint32_t code
Definition: memif.h:123
MEMIF_RING_S2M
@ MEMIF_RING_S2M
Definition: memif.h:51
memif_msg_add_ring_t::offset
memif_region_offset_t offset
Definition: memif.h:106
MEMIF_MSG_TYPE_NONE
@ MEMIF_MSG_TYPE_NONE
Definition: memif.h:38
memif_msg_hello_t::max_log2_ring_size
memif_log2_ring_size_t max_log2_ring_size
Definition: memif.h:82
memif_msg_t::add_ring
memif_msg_add_ring_t add_ring
Definition: memif.h:135
name
string name[64]
Definition: fib.api:25
memif_msg_hello_t::max_region
memif_region_index_t max_region
Definition: memif.h:79
MEMIF_MSG_TYPE_INIT
@ MEMIF_MSG_TYPE_INIT
Definition: memif.h:41
memif_msg_init_t::id
memif_interface_id_t id
Definition: memif.h:88
memif_ring_t::cookie
uint32_t cookie
Definition: memif.h:168
MEMIF_INTERFACE_MODE_IP
@ MEMIF_INTERFACE_MODE_IP
Definition: memif.h:58
memif_region_offset_t
uint32_t memif_region_offset_t
Definition: memif.h:63
memif_msg_t::connect
memif_msg_connect_t connect
Definition: memif.h:136
memif_ring_t::flags
uint16_t flags
Definition: memif.h:169
memif_ring_t::tail
volatile uint16_t tail
Definition: memif.h:173
MEMIF_SECRET_SIZE
#define MEMIF_SECRET_SIZE
Definition: memif.h:30
MEMIF_MSG_TYPE_CONNECTED
@ MEMIF_MSG_TYPE_CONNECTED
Definition: memif.h:45
MEMIF_MSG_TYPE_HELLO
@ MEMIF_MSG_TYPE_HELLO
Definition: memif.h:40
MEMIF_MSG_TYPE_ADD_RING
@ MEMIF_MSG_TYPE_ADD_RING
Definition: memif.h:43
MEMIF_CACHELINE_ALIGN_MARK
#define MEMIF_CACHELINE_ALIGN_MARK(mark)
Definition: memif.h:162
memif_desc_t::region
memif_region_index_t region
Definition: memif.h:153
memif_msg_hello_t::max_s2m_ring
memif_ring_index_t max_s2m_ring
Definition: memif.h:81
memif_msg_hello_t
Definition: memif.h:74
MEMIF_INTERFACE_MODE_PUNT_INJECT
@ MEMIF_INTERFACE_MODE_PUNT_INJECT
Definition: memif.h:59
memif_msg_t::type
memif_msg_type_t type
Definition: memif.h:129
MEMIF_MSG_TYPE_ADD_REGION
@ MEMIF_MSG_TYPE_ADD_REGION
Definition: memif.h:42
memif_ring_type_t
memif_ring_type_t
Definition: memif.h:49
memif_msg_add_ring_t::region
memif_region_index_t region
Definition: memif.h:105
memif_msg_type
memif_msg_type
Definition: memif.h:36
memif_interface_id_t
uint32_t memif_interface_id_t
Definition: memif.h:66
memif_msg_type_t
enum memif_msg_type memif_msg_type_t
memif_msg_hello_t::min_version
memif_version_t min_version
Definition: memif.h:77
memif_msg_add_ring_t::private_hdr_size
uint16_t private_hdr_size
Definition: memif.h:108
memif_msg_t::init
memif_msg_init_t init
Definition: memif.h:133
memif_msg_connected_t
Definition: memif.h:116
memif_region_index_t
uint16_t memif_region_index_t
Definition: memif.h:62
memif_msg_add_ring_t::flags
uint16_t flags
Definition: memif.h:102
memif_desc_t::flags
uint16_t flags
Definition: memif.h:151
memif_msg_t::hello
memif_msg_hello_t hello
Definition: memif.h:132
memif_msg_add_region_t
Definition: memif.h:94
memif_msg_disconnect_t
Definition: memif.h:121
MEMIF_RING_M2S
@ MEMIF_RING_M2S
Definition: memif.h:52
memif_log2_ring_size_t
uint8_t memif_log2_ring_size_t
Definition: memif.h:68
memif_desc_t
Definition: memif.h:149
memif_msg_t
Definition: memif.h:127
memif_ring_index_t
uint16_t memif_ring_index_t
Definition: memif.h:65
memif_msg_init_t::version
memif_version_t version
Definition: memif.h:87
memif_region_size_t
uint64_t memif_region_size_t
Definition: memif.h:64
memif_msg_hello_t::max_version
memif_version_t max_version
Definition: memif.h:78
memif_msg_add_ring_t
Definition: memif.h:100
memif_msg_t::add_region
memif_msg_add_region_t add_region
Definition: memif.h:134
memif_msg_add_ring_t::index
memif_ring_index_t index
Definition: memif.h:104
memif_msg_t::connected
memif_msg_connected_t connected
Definition: memif.h:137
memif_msg_connect_t
Definition: memif.h:111
memif_interface_mode_t
memif_interface_mode_t
Definition: memif.h:55
memif_msg_init_t
Definition: memif.h:85
memif_msg_hello_t::max_m2s_ring
memif_ring_index_t max_m2s_ring
Definition: memif.h:80
memif_desc_t::length
uint32_t length
Definition: memif.h:154
MEMIF_INTERFACE_MODE_ETHERNET
@ MEMIF_INTERFACE_MODE_ETHERNET
Definition: memif.h:57
MEMIF_MSG_TYPE_ACK
@ MEMIF_MSG_TYPE_ACK
Definition: memif.h:39
memif_msg_t::disconnect
memif_msg_disconnect_t disconnect
Definition: memif.h:138
memif_msg_add_ring_t::log2_ring_size
memif_log2_ring_size_t log2_ring_size
Definition: memif.h:107
MEMIF_MSG_TYPE_CONNECT
@ MEMIF_MSG_TYPE_CONNECT
Definition: memif.h:44
memif_msg_init_t::mode
memif_interface_mode_t mode
Definition: memif.h:89
memif_version_t
uint16_t memif_version_t
Definition: memif.h:67
memif_desc_t::offset
memif_region_offset_t offset
Definition: memif.h:155
memif_ring_t
Definition: memif.h:165
memif_msg_add_region_t::index
memif_region_index_t index
Definition: memif.h:96
memif_ring_t::head
volatile uint16_t head
Definition: memif.h:171
memif_msg_add_region_t::size
memif_region_size_t size
Definition: memif.h:97
memif_desc_t::metadata
uint32_t metadata
Definition: memif.h:156