2 // Copyright (c) 2010-2020 Intel Corporation
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.
16 #ifndef _PROX_COMPAT_H_
17 #define _PROX_COMPAT_H_
18 #include <rte_common.h>
19 #include <rte_table_hash.h>
20 #include <rte_ethdev.h>
21 #include <rte_hash_crc.h>
22 #include <rte_cryptodev.h>
24 #include "hash_utils.h"
27 /* This is a copy of the rte_table_hash_params from DPDK 17.11 *
28 * So if DPDK decides to change the structure the modifications *
29 * to PROX code should mainly be limited to this file *
31 struct prox_rte_table_params {
38 rte_table_hash_op_hash f_hash;
42 #if RTE_VERSION < RTE_VERSION_NUM(16,4,0,0)
43 typedef uint8_t prox_next_hop_index_type;
45 typedef uint32_t prox_next_hop_index_type;
48 #if RTE_VERSION < RTE_VERSION_NUM(16,7,0,0)
49 static void rte_mempool_free(struct rte_mempool *mp)
51 plog_warn("rte_mempool_free not supported in this DPDK - upgrade DPDK to avoid memory leaks\n");
55 #if RTE_VERSION < RTE_VERSION_NUM(17,11,0,0)
57 static void *prox_rte_table_create(struct prox_rte_table_params *params, int socket_id, uint32_t entry_size)
59 if (params->key_size == 8) {
60 struct rte_table_hash_key8_ext_params dpdk17_08_params;
61 dpdk17_08_params.n_entries = params->n_keys;
62 dpdk17_08_params.n_entries_ext = params->n_keys >> 2;
63 dpdk17_08_params.f_hash = (rte_table_hash_op_hash)rte_hash_crc;
64 dpdk17_08_params.seed = params->seed;
65 dpdk17_08_params.signature_offset = HASH_METADATA_OFFSET(8); // Ignored for dosig
66 dpdk17_08_params.key_offset = HASH_METADATA_OFFSET(0);
67 dpdk17_08_params.key_mask = params->key_mask;
68 return rte_table_hash_key8_ext_dosig_ops.f_create(&dpdk17_08_params, socket_id, entry_size);
70 struct rte_table_hash_ext_params dpdk17_08_params;
71 dpdk17_08_params.key_size = params->key_size;
72 dpdk17_08_params.n_keys = params->n_keys;
73 dpdk17_08_params.n_buckets = params->n_buckets;
74 dpdk17_08_params.n_buckets_ext = params->n_buckets >> 1;
75 dpdk17_08_params.seed = params->seed;
76 dpdk17_08_params.f_hash = (rte_table_hash_op_hash)rte_hash_crc;
77 dpdk17_08_params.signature_offset = HASH_METADATA_OFFSET(0);
78 dpdk17_08_params.key_offset = HASH_METADATA_OFFSET(0);
79 return rte_table_hash_ext_dosig_ops.f_create(&dpdk17_08_params, socket_id, entry_size);
83 static inline int prox_rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
85 #if RTE_VERSION < RTE_VERSION_NUM(16,7,0,0)
86 plog_err("Not supported in DPDK version <= 16.04 by lack of rte_eth_dev_get_port_by_name support\n");
89 return rte_eth_dev_get_port_by_name(name, (uint8_t *)port_id);
93 #define prox_rte_table_free rte_table_hash_ext_dosig_ops.f_free
94 #define prox_rte_table_add rte_table_hash_ext_dosig_ops.f_add
95 #define prox_rte_table_delete rte_table_hash_ext_dosig_ops.f_delete
96 #define prox_rte_table_add_bulk rte_table_hash_ext_dosig_ops.f_add_bulk
97 #define prox_rte_table_delete_bulk rte_table_hash_ext_dosig_ops.f_delete_bulk
98 #define prox_rte_table_lookup rte_table_hash_ext_dosig_ops.f_lookup
99 #define prox_rte_table_stats rte_table_hash_ext_dosig_ops.f_stats
101 #define prox_rte_table_key8_free rte_table_hash_key8_ext_dosig_ops.f_free
102 #define prox_rte_table_key8_add rte_table_hash_key8_ext_dosig_ops.f_add
103 #define prox_rte_table_key8_delete rte_table_hash_key8_ext_dosig_ops.f_delete
104 #define prox_rte_table_key8_add_bulk rte_table_hash_key8_ext_dosig_ops.f_add_bulk
105 #define prox_rte_table_key8_delete_bulk rte_table_hash_key8_ext_dosig_ops.f_delete_bulk
106 #define prox_rte_table_key8_lookup rte_table_hash_key8_ext_dosig_ops.f_lookup
107 #define prox_rte_table_key8_stats rte_table_hash_key8_ext_dosig_ops.f_stats
109 #define rte_log_set_global_level rte_set_log_level
113 static void *prox_rte_table_create(struct prox_rte_table_params *params, int socket_id, uint32_t entry_size)
115 struct rte_table_hash_params dpdk_17_11_params;
116 dpdk_17_11_params.name = params->name;
117 dpdk_17_11_params.key_size = params->key_size;
118 dpdk_17_11_params.key_offset = params->key_offset;
119 dpdk_17_11_params.key_mask = params->key_mask;
120 dpdk_17_11_params.n_keys = params->n_keys;
121 dpdk_17_11_params.n_buckets = rte_align32pow2(params->n_buckets);
122 dpdk_17_11_params.f_hash = params->f_hash;
123 dpdk_17_11_params.seed = params->seed;
125 if (params->key_size == 8) {
126 return rte_table_hash_key8_ext_ops.f_create(&dpdk_17_11_params, socket_id, entry_size);
128 return rte_table_hash_ext_ops.f_create(&dpdk_17_11_params, socket_id, entry_size);
132 #define prox_rte_eth_dev_get_port_by_name rte_eth_dev_get_port_by_name
134 #define prox_rte_table_free rte_table_hash_ext_ops.f_free
135 #define prox_rte_table_add rte_table_hash_ext_ops.f_add
136 #define prox_rte_table_delete rte_table_hash_ext_ops.f_delete
137 #define prox_rte_table_add_bulk rte_table_hash_ext_ops.f_add_bulk
138 #define prox_rte_table_delete_bulk rte_table_hash_ext_ops.f_delete_bulk
139 #define prox_rte_table_lookup rte_table_hash_ext_ops.f_lookup
140 #define prox_rte_table_stats rte_table_hash_ext_ops.f_stats
142 #define prox_rte_table_key8_free rte_table_hash_key8_ext_ops.f_free
143 #define prox_rte_table_key8_add rte_table_hash_key8_ext_ops.f_add
144 #define prox_rte_table_key8_delete rte_table_hash_key8_ext_ops.f_delete
145 #define prox_rte_table_key8_add_bulk rte_table_hash_key8_ext_ops.f_add_bulk
146 #define prox_rte_table_key8_delete_bulk rte_table_hash_key8_ext_ops.f_delete_bulk
147 #define prox_rte_table_key8_lookup rte_table_hash_key8_ext_ops.f_lookup
148 #define prox_rte_table_key8_stats rte_table_hash_key8_ext_ops.f_stats
152 #if RTE_VERSION < RTE_VERSION_NUM(18,8,0,0)
153 #define rte_cryptodev_sym_get_private_session_size rte_cryptodev_get_private_session_size
156 #ifndef DEV_RX_OFFLOAD_JUMBO_FRAME
157 #define DEV_RX_OFFLOAD_JUMBO_FRAME 0x00000800
160 #ifndef DEV_RX_OFFLOAD_KEEP_CRC
161 #ifndef DEV_RX_OFFLOAD_CRC_STRIP
162 #define DEV_RX_OFFLOAD_CRC_STRIP 0x00001000
166 #if RTE_VERSION < RTE_VERSION_NUM(19,2,0,0)
167 #define RTE_COLOR_GREEN e_RTE_METER_GREEN
168 #define RTE_COLOR_YELLOW e_RTE_METER_YELLOW
169 #define RTE_COLOR_RED e_RTE_METER_RED
170 #define prox_rte_color rte_meter_color
171 #define prox_rte_sched_port_pkt_read_tree_path(A,B,C,D,E,F) rte_sched_port_pkt_read_tree_path(B,C,D,E,F)
172 #define prox_rte_sched_port_pkt_write(A,B,C,D,E,F,G) rte_sched_port_pkt_write(B,C,D,E,F,G);
174 #define prox_rte_color rte_color
175 #define prox_rte_sched_port_pkt_read_tree_path(A,B,C,D,E,F) rte_sched_port_pkt_read_tree_path(A,B,C,D,E,F)
176 #define prox_rte_sched_port_pkt_write(A,B,C,D,E,F,G) rte_sched_port_pkt_write(A,B,C,D,E,F,G);
179 #if RTE_VERSION < RTE_VERSION_NUM(19,8,0,0)
180 #if RTE_VERSION >= RTE_VERSION_NUM(18,5,0,0)
181 typedef struct vxlan_gpe_hdr prox_rte_vxlan_gpe_hdr;
183 #define PROX_RTE_ETHER_CRC_LEN ETHER_CRC_LEN
184 #define PROX_RTE_ETHER_MIN_LEN ETHER_MIN_LEN
185 #define PROX_RTE_ETHER_MAX_LEN ETHER_MAX_LEN
186 #define PROX_RTE_ETHER_HDR_LEN ETHER_HDR_LEN
187 #define PROX_RTE_TCP_SYN_FLAG TCP_SYN_FLAG
188 #define PROX_RTE_TCP_FIN_FLAG TCP_FIN_FLAG
189 #define PROX_RTE_TCP_RST_FLAG TCP_RST_FLAG
190 #define PROX_RTE_TCP_ACK_FLAG TCP_ACK_FLAG
191 #define PROX_RTE_IP_ICMP_ECHO_REPLY IP_ICMP_ECHO_REPLY
192 #define PROX_RTE_IP_ICMP_ECHO_REQUEST IP_ICMP_ECHO_REQUEST
194 #define prox_rte_ether_addr_copy ether_addr_copy
195 #define prox_rte_eth_random_addr eth_random_addr
197 typedef struct ipv6_hdr prox_rte_ipv6_hdr;
198 typedef struct ipv4_hdr prox_rte_ipv4_hdr;
199 typedef struct ether_addr prox_rte_ether_addr;
200 typedef struct ether_hdr prox_rte_ether_hdr;
201 typedef struct vlan_hdr prox_rte_vlan_hdr;
202 typedef struct udp_hdr prox_rte_udp_hdr;
203 typedef struct tcp_hdr prox_rte_tcp_hdr;
204 typedef struct icmp_hdr prox_rte_icmp_hdr;
206 #ifndef RTE_SCHED_BE_QUEUES_PER_PIPE
207 #define RTE_SCHED_BE_QUEUES_PER_PIPE RTE_SCHED_QUEUES_PER_PIPE
210 #define PROX_RTE_IS_IPV4_MCAST IS_IPV4_MCAST
211 #define prox_rte_is_same_ether_addr is_same_ether_addr
212 #define prox_rte_is_zero_ether_addr is_zero_ether_addr
215 #define PROX_RTE_ETHER_CRC_LEN RTE_ETHER_CRC_LEN
216 #define PROX_RTE_ETHER_MIN_LEN RTE_ETHER_MIN_LEN
217 #define PROX_RTE_ETHER_MAX_LEN RTE_ETHER_MAX_LEN
218 #define PROX_RTE_ETHER_HDR_LEN RTE_ETHER_HDR_LEN
219 #define PROX_RTE_TCP_SYN_FLAG RTE_TCP_SYN_FLAG
220 #define PROX_RTE_TCP_FIN_FLAG RTE_TCP_FIN_FLAG
221 #define PROX_RTE_TCP_RST_FLAG RTE_TCP_RST_FLAG
222 #define PROX_RTE_TCP_ACK_FLAG RTE_TCP_ACK_FLAG
223 #define PROX_RTE_IP_ICMP_ECHO_REPLY RTE_IP_ICMP_ECHO_REPLY
224 #define PROX_RTE_IP_ICMP_ECHO_REQUEST RTE_IP_ICMP_ECHO_REQUEST
226 #define prox_rte_ether_addr_copy rte_ether_addr_copy
227 #define prox_rte_eth_random_addr rte_eth_random_addr
229 typedef struct rte_ipv6_hdr prox_rte_ipv6_hdr;
230 typedef struct rte_ipv4_hdr prox_rte_ipv4_hdr;
231 typedef struct rte_ether_addr prox_rte_ether_addr;
232 typedef struct rte_ether_hdr prox_rte_ether_hdr;
233 typedef struct rte_vlan_hdr prox_rte_vlan_hdr;
234 typedef struct rte_vxlan_gpe_hdr prox_rte_vxlan_gpe_hdr;
235 typedef struct rte_udp_hdr prox_rte_udp_hdr;
236 typedef struct rte_tcp_hdr prox_rte_tcp_hdr;
237 typedef struct rte_icmp_hdr prox_rte_icmp_hdr;
239 #define PROX_RTE_IS_IPV4_MCAST RTE_IS_IPV4_MCAST
240 #define prox_rte_is_same_ether_addr rte_is_same_ether_addr
241 #define prox_rte_is_zero_ether_addr rte_is_zero_ether_addr
245 char *prox_strncpy(char * dest, const char * src, size_t count);
247 #ifdef RTE_LIBRTE_PMD_AESNI_MB
248 #if RTE_VERSION < RTE_VERSION_NUM(19,5,0,0)
250 struct prox_esp_hdr {
254 struct prox_rte_cryptodev_qp_conf {
255 uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
256 struct rte_mempool * mp_session;
257 struct rte_mempool * mp_session_private;
260 static int prox_rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, struct prox_rte_cryptodev_qp_conf *qp_conf, int socket_id)
262 struct rte_mempool *session_pool = qp_conf->mp_session;
263 return rte_cryptodev_queue_pair_setup(dev_id, queue_pair_id, (struct rte_cryptodev_qp_conf *)qp_conf, socket_id, session_pool);
267 #define prox_rte_cryptodev_qp_conf rte_cryptodev_qp_conf
268 static int prox_rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, struct prox_rte_cryptodev_qp_conf *qp_conf, int socket_id)
270 return rte_cryptodev_queue_pair_setup(dev_id, queue_pair_id, (struct rte_cryptodev_qp_conf *)qp_conf, socket_id);
273 #if RTE_VERSION < RTE_VERSION_NUM(19,8,0,0)
274 #define prox_esp_hdr esp_hdr
276 #else // From DPDK 19.08
277 #define prox_esp_hdr rte_esp_hdr
281 #endif // CONFIG_RTE_LIBRTE_PMD_AESNI_MB
283 #if RTE_VERSION < RTE_VERSION_NUM(19,11,0,0)
284 #define prox_rte_eth_dev_count_avail() rte_eth_dev_count()
286 #define prox_rte_eth_dev_count_avail() rte_eth_dev_count_avail()
289 #endif // _PROX_COMPAT_H