2 * Copyright (c) 2016 Intel and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
15 #ifndef __DPDK_IPSEC_H__
16 #define __DPDK_IPSEC_H__
18 #include <vnet/vnet.h>
21 #include <rte_config.h>
22 #include <rte_crypto.h>
23 #include <rte_cryptodev.h>
26 #define always_inline static inline
28 #define always_inline static inline __attribute__ ((__always_inline__))
32 #define MAX_QP_PER_LCORE 16
56 } crypto_worker_qp_key_t;
64 u32 bi[VLIB_FRAME_SIZE];
65 struct rte_crypto_op *cops[VLIB_FRAME_SIZE];
66 struct rte_crypto_op **free_cops;
73 } crypto_sa_session_t;
77 crypto_sa_session_t *sa_sess_d[2];
78 crypto_qp_data_t *qp_data;
80 } crypto_worker_main_t;
84 struct rte_mempool **cop_pools;
85 crypto_worker_main_t *workers_main;
88 dpdk_crypto_main_t dpdk_crypto_main;
90 extern vlib_node_registration_t dpdk_crypto_input_node;
92 #define CRYPTO_N_FREE_COPS (VLIB_FRAME_SIZE * 3)
94 static_always_inline void
97 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
98 u32 thread_index = vlib_get_thread_index ();
99 crypto_worker_main_t *cwm = &dcm->workers_main[thread_index];
100 unsigned socket_id = rte_socket_id ();
101 crypto_qp_data_t *qpd;
104 vec_foreach (qpd, cwm->qp_data)
106 u32 l = vec_len (qpd->free_cops);
108 if (PREDICT_FALSE (l < VLIB_FRAME_SIZE))
112 if (PREDICT_FALSE (!qpd->free_cops))
113 vec_alloc (qpd->free_cops, CRYPTO_N_FREE_COPS);
115 n_alloc = rte_crypto_op_bulk_alloc (dcm->cop_pools[socket_id],
116 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
118 CRYPTO_N_FREE_COPS - l - 1);
120 _vec_len (qpd->free_cops) = l + n_alloc;
126 static_always_inline void
127 crypto_free_cop (crypto_qp_data_t * qpd, struct rte_crypto_op **cops, u32 n)
129 u32 l = vec_len (qpd->free_cops);
131 if (l + n >= CRYPTO_N_FREE_COPS)
133 l -= VLIB_FRAME_SIZE;
134 rte_mempool_put_bulk (cops[0]->mempool,
135 (void **) &qpd->free_cops[l], VLIB_FRAME_SIZE);
137 clib_memcpy (&qpd->free_cops[l], cops, sizeof (*cops) * n);
139 _vec_len (qpd->free_cops) = l + n;
142 static_always_inline int
143 check_algo_is_supported (const struct rte_cryptodev_capabilities *cap,
149 enum rte_crypto_sym_xform_type type;
152 enum rte_crypto_auth_algorithm auth;
153 enum rte_crypto_cipher_algorithm cipher;
159 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
160 RTE_CRYPTO_CIPHER_NULL,.name = "NULL"},
162 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
163 RTE_CRYPTO_CIPHER_AES_CBC,.name = "AES_CBC"},
165 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
166 RTE_CRYPTO_CIPHER_AES_CTR,.name = "AES_CTR"},
168 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
169 RTE_CRYPTO_CIPHER_3DES_CBC,.name = "3DES-CBC"},
171 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
172 RTE_CRYPTO_CIPHER_AES_GCM,.name = "AES-GCM"},
174 .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
175 RTE_CRYPTO_AUTH_SHA1_HMAC,.name = "HMAC-SHA1"},
177 .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
178 RTE_CRYPTO_AUTH_SHA256_HMAC,.name = "HMAC-SHA256"},
180 .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
181 RTE_CRYPTO_AUTH_SHA384_HMAC,.name = "HMAC-SHA384"},
183 .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
184 RTE_CRYPTO_AUTH_SHA512_HMAC,.name = "HMAC-SHA512"},
186 .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
187 RTE_CRYPTO_AUTH_AES_XCBC_MAC,.name = "AES-XCBC-MAC"},
189 .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
190 RTE_CRYPTO_AUTH_AES_GCM,.name = "AES-GCM"},
193 .type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED},};
196 if (cap->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC)
199 while (supported_algo[i].type != RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED)
201 if (cap->sym.xform_type == supported_algo[i].type)
203 if ((cap->sym.xform_type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
204 cap->sym.cipher.algo == supported_algo[i].cipher) ||
205 (cap->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH &&
206 cap->sym.auth.algo == supported_algo[i].auth))
209 strcpy (name, supported_algo[i].name);
220 #endif /* __DPDK_IPSEC_H__ */
223 * fd.io coding-style-patch-verification: ON
226 * eval: (c-set-style "gnu")