CNDP  22.08.0
memif.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2018-2021 Cisco Systems, Inc. All rights reserved.
3  */
4 
5 #ifndef _MEMIF_H_
6 #define _MEMIF_H_
7 
8 #define CNE_MEMIF_COOKIE 0x3E31F20
9 #define CNE_MEMIF_VERSION_MAJOR 2
10 #define CNE_MEMIF_VERSION_MINOR 0
11 #define CNE_MEMIF_VERSION ((CNE_MEMIF_VERSION_MAJOR << 8) | CNE_MEMIF_VERSION_MINOR)
12 #define CNE_MEMIF_NAME_SZ 32
13 
14 /*
15  * C2S: direction client -> server
16  * S2C: direction server -> client
17  */
18 
19 /*
20  * Type definitions
21  */
22 
23 typedef enum cne_memif_msg_type {
24  CNE_MEMIF_MSG_TYPE_NONE,
25  CNE_MEMIF_MSG_TYPE_ACK,
26  CNE_MEMIF_MSG_TYPE_HELLO,
27  CNE_MEMIF_MSG_TYPE_INIT,
28  CNE_MEMIF_MSG_TYPE_ADD_REGION,
29  CNE_MEMIF_MSG_TYPE_ADD_RING,
30  CNE_MEMIF_MSG_TYPE_CONNECT,
31  CNE_MEMIF_MSG_TYPE_CONNECTED,
32  CNE_MEMIF_MSG_TYPE_DISCONNECT,
33 } cne_memif_msg_type_t;
34 
35 typedef enum {
36  CNE_MEMIF_RING_C2S,
37  CNE_MEMIF_RING_S2C,
38 } cne_memif_ring_type_t;
39 
40 typedef enum {
41  CNE_MEMIF_INTERFACE_MODE_ETHERNET,
42  CNE_MEMIF_INTERFACE_MODE_IP,
43  CNE_MEMIF_INTERFACE_MODE_PUNT_INJECT,
44 } cne_memif_interface_mode_t;
45 
46 typedef uint16_t cne_memif_region_index_t;
47 typedef uint32_t cne_memif_region_offset_t;
48 typedef uint64_t cne_memif_region_size_t;
49 typedef uint16_t cne_memif_ring_index_t;
50 typedef uint32_t cne_memif_interface_id_t;
51 typedef uint16_t cne_memif_version_t;
52 typedef uint8_t cne_memif_log2_ring_size_t;
53 
54 /*
55  * Socket messages
56  */
57 
62 typedef struct __cne_packed {
63  uint8_t name[CNE_MEMIF_NAME_SZ];
64  cne_memif_version_t min_version;
65  cne_memif_version_t max_version;
66  cne_memif_region_index_t max_region;
67  cne_memif_ring_index_t max_s2c_ring;
68  cne_memif_ring_index_t max_c2s_ring;
69  cne_memif_log2_ring_size_t max_log2_ring_size;
71 
77 typedef struct __cne_packed {
78  cne_memif_version_t version;
79  cne_memif_interface_id_t id;
80  cne_memif_interface_mode_t mode : 8;
81  uint8_t secret[24];
82  uint8_t name[CNE_MEMIF_NAME_SZ];
84 
90 typedef struct __cne_packed {
91  cne_memif_region_index_t index;
92  cne_memif_region_size_t size;
94 
99 typedef struct __cne_packed {
100  uint16_t flags;
101 #define CNE_MEMIF_MSG_ADD_RING_FLAG_C2S 1
102  cne_memif_ring_index_t index;
103  cne_memif_region_index_t region;
104  cne_memif_region_offset_t offset;
105  cne_memif_log2_ring_size_t log2_ring_size;
106  uint16_t private_hdr_size;
108 
113 typedef struct __cne_packed {
114  uint8_t if_name[CNE_MEMIF_NAME_SZ];
116 
121 typedef struct __cne_packed {
122  uint8_t if_name[CNE_MEMIF_NAME_SZ];
124 
129 typedef struct __cne_packed {
130  uint32_t code;
131  uint8_t string[96];
133 
134 typedef struct __cne_packed __cne_aligned(128)
135 {
136  cne_memif_msg_type_t type : 16;
137  union {
138  cne_memif_msg_hello_t hello;
140  cne_memif_msg_add_region_t add_region;
141  cne_memif_msg_add_ring_t add_ring;
142  cne_memif_msg_connect_t connect;
143  cne_memif_msg_connected_t connected;
144  cne_memif_msg_disconnect_t disconnect;
145  };
146 }
147 cne_memif_msg_t;
148 
149 /*
150  * Ring and Descriptor Layout
151  */
152 
156 typedef struct __cne_packed {
157  uint16_t flags;
158 #define CNE_MEMIF_DESC_FLAG_NEXT 1
159  cne_memif_region_index_t region;
160  uint32_t length;
161  cne_memif_region_offset_t offset;
162  uint32_t metadata;
164 
165 #define CNE_MEMIF_CACHELINE_ALIGN_MARK(mark) CNE_MARKER mark __cne_cache_aligned;
166 
167 typedef struct {
168  CNE_MEMIF_CACHELINE_ALIGN_MARK(cacheline0);
169  uint32_t cookie;
170  uint16_t flags;
171 #define CNE_MEMIF_RING_FLAG_MASK_INT 1
172  uint16_t head;
173  CNE_MEMIF_CACHELINE_ALIGN_MARK(cacheline1);
174  uint16_t tail;
175  CNE_MEMIF_CACHELINE_ALIGN_MARK(cacheline2);
176  cne_memif_desc_t desc[0];
177 } cne_memif_ring_t;
178 
179 #endif /* _MEMIF_H_ */
#define __cne_aligned(a)
Definition: cne_common.h:124
cne_memif_interface_id_t id
Definition: memif.h:79
cne_memif_version_t max_version
Definition: memif.h:65
cne_memif_ring_index_t max_s2c_ring
Definition: memif.h:67
uint16_t flags
Definition: memif.h:100
cne_memif_version_t min_version
Definition: memif.h:64
cne_memif_ring_index_t index
Definition: memif.h:102
uint8_t secret[24]
Definition: memif.h:81
cne_memif_region_size_t size
Definition: memif.h:92
uint8_t if_name[CNE_MEMIF_NAME_SZ]
Definition: memif.h:114
cne_memif_region_index_t region
Definition: memif.h:103
uint16_t private_hdr_size
Definition: memif.h:106
uint8_t name[CNE_MEMIF_NAME_SZ]
Definition: memif.h:63
cne_memif_log2_ring_size_t max_log2_ring_size
Definition: memif.h:69
cne_memif_ring_index_t max_c2s_ring
Definition: memif.h:68
cne_memif_region_offset_t offset
Definition: memif.h:104
cne_memif_region_index_t index
Definition: memif.h:91
cne_memif_interface_mode_t mode
Definition: memif.h:80
cne_memif_log2_ring_size_t log2_ring_size
Definition: memif.h:105
cne_memif_version_t version
Definition: memif.h:78
cne_memif_region_index_t max_region
Definition: memif.h:66
uint32_t length
Definition: memif.h:160
uint32_t code
Definition: memif.h:130