1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2018-2019 Cisco Systems, Inc. All rights reserved.
8 #define MEMIF_COOKIE 0x3E31F20
9 #define MEMIF_VERSION_MAJOR 2
10 #define MEMIF_VERSION_MINOR 0
11 #define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
12 #define MEMIF_NAME_SZ 32
15 * C2S: direction client -> server
16 * S2C: direction server -> client
23 typedef enum memif_msg_type {
28 MEMIF_MSG_TYPE_ADD_REGION,
29 MEMIF_MSG_TYPE_ADD_RING,
30 MEMIF_MSG_TYPE_CONNECT,
31 MEMIF_MSG_TYPE_CONNECTED,
32 MEMIF_MSG_TYPE_DISCONNECT,
36 MEMIF_RING_C2S, /**< buffer ring in direction client -> server */
37 MEMIF_RING_S2C, /**< buffer ring in direction server -> client */
41 MEMIF_INTERFACE_MODE_ETHERNET,
42 MEMIF_INTERFACE_MODE_IP,
43 MEMIF_INTERFACE_MODE_PUNT_INJECT,
44 } memif_interface_mode_t;
46 typedef uint16_t memif_region_index_t;
47 typedef uint32_t memif_region_offset_t;
48 typedef uint64_t memif_region_size_t;
49 typedef uint16_t memif_ring_index_t;
50 typedef uint32_t memif_interface_id_t;
51 typedef uint16_t memif_version_t;
52 typedef uint8_t memif_log2_ring_size_t;
60 * Contains server interfaces configuration.
62 typedef struct __rte_packed {
63 uint8_t name[MEMIF_NAME_SZ]; /**< Client app name. In this case DPDK version */
64 memif_version_t min_version; /**< lowest supported memif version */
65 memif_version_t max_version; /**< highest supported memif version */
66 memif_region_index_t max_region; /**< maximum num of regions */
67 memif_ring_index_t max_s2c_ring; /**< maximum num of S2C ring */
68 memif_ring_index_t max_c2s_ring; /**< maximum num of C2S rings */
69 memif_log2_ring_size_t max_log2_ring_size; /**< maximum ring size (as log2) */
74 * Contains information required to identify interface
75 * to which the client wants to connect.
77 typedef struct __rte_packed {
78 memif_version_t version; /**< memif version */
79 memif_interface_id_t id; /**< interface id */
80 memif_interface_mode_t mode:8; /**< interface mode */
81 uint8_t secret[24]; /**< optional security parameter */
82 uint8_t name[MEMIF_NAME_SZ]; /**< Client app name. In this case DPDK version */
87 * Request server to add new shared memory region to server interface.
88 * Shared files file descriptor is passed in cmsghdr.
90 typedef struct __rte_packed {
91 memif_region_index_t index; /**< shm regions index */
92 memif_region_size_t size; /**< shm region size */
93 } memif_msg_add_region_t;
97 * Request server to add new ring to server interface.
99 typedef struct __rte_packed {
100 uint16_t flags; /**< flags */
101 #define MEMIF_MSG_ADD_RING_FLAG_C2S 1 /**< ring is in C2S direction */
102 memif_ring_index_t index; /**< ring index */
103 memif_region_index_t region; /**< region index on which this ring is located */
104 memif_region_offset_t offset; /**< buffer start offset */
105 memif_log2_ring_size_t log2_ring_size; /**< ring size (log2) */
106 uint16_t private_hdr_size; /**< used for private metadata */
107 } memif_msg_add_ring_t;
111 * Finalize connection establishment.
113 typedef struct __rte_packed {
114 uint8_t if_name[MEMIF_NAME_SZ]; /**< client interface name */
115 } memif_msg_connect_t;
119 * Finalize connection establishment.
121 typedef struct __rte_packed {
122 uint8_t if_name[MEMIF_NAME_SZ]; /**< server interface name */
123 } memif_msg_connected_t;
127 * Disconnect interfaces.
129 typedef struct __rte_packed {
130 uint32_t code; /**< error code */
131 uint8_t string[96]; /**< disconnect reason */
132 } memif_msg_disconnect_t;
134 typedef struct __rte_packed __rte_aligned(128)
136 memif_msg_type_t type:16;
138 memif_msg_hello_t hello;
139 memif_msg_init_t init;
140 memif_msg_add_region_t add_region;
141 memif_msg_add_ring_t add_ring;
142 memif_msg_connect_t connect;
143 memif_msg_connected_t connected;
144 memif_msg_disconnect_t disconnect;
149 * Ring and Descriptor Layout
155 typedef struct __rte_packed {
156 uint16_t flags; /**< flags */
157 #define MEMIF_DESC_FLAG_NEXT 1 /**< is chained buffer */
158 memif_region_index_t region; /**< region index on which the buffer is located */
159 uint32_t length; /**< buffer length */
160 memif_region_offset_t offset; /**< buffer offset */
164 #define MEMIF_CACHELINE_ALIGN_MARK(mark) \
165 RTE_MARKER mark __rte_cache_aligned;
168 MEMIF_CACHELINE_ALIGN_MARK(cacheline0);
169 uint32_t cookie; /**< MEMIF_COOKIE */
170 uint16_t flags; /**< flags */
171 #define MEMIF_RING_FLAG_MASK_INT 1 /**< disable interrupt mode */
172 uint16_t head; /**< pointer to ring buffer head */
173 MEMIF_CACHELINE_ALIGN_MARK(cacheline1);
174 uint16_t tail; /**< pointer to ring buffer tail */
175 MEMIF_CACHELINE_ALIGN_MARK(cacheline2);
176 memif_desc_t desc[0]; /**< buffer descriptors */
179 #endif /* _MEMIF_H_ */