FD.io VPP  v18.01-8-g0eacf49
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 0x3E31F10
26 #define MEMIF_VERSION_MAJOR 1
27 #define MEMIF_VERSION_MINOR 0
28 #define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
29 
30 /*
31  * Type definitions
32  */
33 
34 typedef enum memif_msg_type
35 {
46 
47 typedef enum
48 {
52 
53 typedef enum
54 {
59 
60 typedef uint16_t memif_region_index_t;
61 typedef uint64_t memif_region_offset_t;
62 typedef uint64_t memif_region_size_t;
63 typedef uint16_t memif_ring_index_t;
64 typedef uint32_t memif_interface_id_t;
65 typedef uint16_t memif_version_t;
66 typedef uint8_t memif_log2_ring_size_t;
67 
68 /*
69  * Socket messages
70  */
71 
72 typedef struct __attribute__ ((packed))
73 {
74  uint8_t name[32];
75  memif_version_t min_version;
76  memif_version_t max_version;
77  memif_region_index_t max_region;
78  memif_ring_index_t max_m2s_ring;
79  memif_ring_index_t max_s2m_ring;
80  memif_log2_ring_size_t max_log2_ring_size;
82 
83 typedef struct __attribute__ ((packed))
84 {
85  memif_version_t version;
86  memif_interface_id_t id;
88  uint8_t secret[24];
89  uint8_t name[32];
91 
92 typedef struct __attribute__ ((packed))
93 {
94  memif_region_index_t index;
95  memif_region_size_t size;
97 
98 typedef struct __attribute__ ((packed))
99 {
100  uint16_t flags;
101 #define MEMIF_MSG_ADD_RING_FLAG_S2M (1 << 0)
102  memif_ring_index_t index;
103  memif_region_index_t region;
104  memif_region_offset_t offset;
105  memif_log2_ring_size_t log2_ring_size;
107 
108 typedef struct __attribute__ ((packed))
109 {
110  uint8_t if_name[32];
112 
113 typedef struct __attribute__ ((packed))
114 {
115  uint8_t if_name[32];
117 
118 typedef struct __attribute__ ((packed))
119 {
120  uint32_t code;
121  uint8_t string[96];
123 
124 typedef struct __attribute__ ((packed, aligned (128)))
125 {
127  union
128  {
136  };
137 } memif_msg_t;
138 
139 _Static_assert (sizeof (memif_msg_t) == 128,
140  "Size of memif_msg_t must be 128");
141 
142 /*
143  * Ring and Descriptor Layout
144  */
145 
146 typedef struct __attribute__ ((packed))
147 {
148  uint16_t flags;
149 #define MEMIF_DESC_FLAG_NEXT (1 << 0)
150  memif_region_index_t region;
151  uint32_t buffer_length;
152  uint32_t length;
153  uint8_t reserved[4];
154  memif_region_offset_t offset;
155  uint64_t metadata;
156 } memif_desc_t;
157 
158 _Static_assert (sizeof (memif_desc_t) == 32,
159  "Size of memif_dsct_t must be 32");
160 
161 #define MEMIF_CACHELINE_ALIGN_MARK(mark) \
162  uint8_t mark[0] __attribute__((aligned(MEMIF_CACHELINE_SIZE)))
163 
164 typedef struct
165 {
166  MEMIF_CACHELINE_ALIGN_MARK (cacheline0);
167  uint32_t cookie;
168  uint16_t flags;
169 #define MEMIF_RING_FLAG_MASK_INT 1
170  volatile uint16_t head;
171  MEMIF_CACHELINE_ALIGN_MARK (cacheline1);
172  volatile uint16_t tail;
173  MEMIF_CACHELINE_ALIGN_MARK (cacheline2);
174  memif_desc_t desc[0];
175 } memif_ring_t;
176 
177 #endif /* _MEMIF_H_ */
178 
179 /*
180  * fd.io coding-style-patch-verification: ON
181  *
182  * Local Variables:
183  * eval: (c-set-style "gnu")
184  * End:
185  */
memif_version_t max_version
Definition: memif.h:76
memif_msg_type
Definition: memif.h:34
uint16_t memif_ring_index_t
Definition: memif.h:63
memif_msg_add_region_t add_region
Definition: memif.h:131
memif_msg_add_ring_t add_ring
Definition: memif.h:132
memif_interface_mode_t
Definition: memif.h:53
uint16_t memif_region_index_t
Definition: memif.h:60
memif_region_index_t region
Definition: memif.h:103
memif_version_t min_version
Definition: memif.h:75
uint32_t length
Definition: memif.h:152
uint32_t buffer_length
Definition: memif.h:151
uint64_t metadata
Definition: memif.h:155
memif_interface_id_t id
Definition: memif.h:86
uint32_t cookie
Definition: memif.h:167
memif_ring_index_t max_m2s_ring
Definition: memif.h:78
uint16_t flags
Definition: memif.h:148
memif_region_offset_t offset
Definition: memif.h:104
enum memif_msg_type memif_msg_type_t
uint16_t memif_version_t
Definition: memif.h:65
memif_msg_init_t init
Definition: memif.h:130
memif_ring_index_t index
Definition: memif.h:102
memif_region_index_t region
Definition: memif.h:150
uint8_t memif_log2_ring_size_t
Definition: memif.h:66
memif_msg_disconnect_t disconnect
Definition: memif.h:135
memif_msg_hello_t hello
Definition: memif.h:129
memif_log2_ring_size_t max_log2_ring_size
Definition: memif.h:80
#define MEMIF_CACHELINE_ALIGN_MARK(mark)
Definition: memif.h:161
memif_region_index_t index
Definition: memif.h:94
uint32_t memif_interface_id_t
Definition: memif.h:64
memif_log2_ring_size_t log2_ring_size
Definition: memif.h:105
memif_version_t version
Definition: memif.h:85
memif_ring_index_t max_s2m_ring
Definition: memif.h:79
memif_msg_connect_t connect
Definition: memif.h:133
memif_region_offset_t offset
Definition: memif.h:154
uint16_t flags
Definition: memif.h:100
uint64_t memif_region_size_t
Definition: memif.h:62
memif_region_size_t size
Definition: memif.h:95
memif_region_index_t max_region
Definition: memif.h:77
memif_msg_connected_t connected
Definition: memif.h:134
uint16_t flags
Definition: memif.h:168
memif_ring_type_t
Definition: memif.h:47
volatile uint16_t head
Definition: memif.h:170
uint64_t memif_region_offset_t
Definition: memif.h:61
volatile uint16_t tail
Definition: memif.h:172