Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 1 | /* |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017 Intel and/or its affiliates. |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 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: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 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. |
| 14 | */ |
| 15 | #ifndef __DPDK_IPSEC_H__ |
| 16 | #define __DPDK_IPSEC_H__ |
| 17 | |
| 18 | #include <vnet/vnet.h> |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 19 | #include <vppinfra/cache.h> |
| 20 | #include <vnet/ipsec/ipsec.h> |
Fan Zhang | 6c8533d | 2021-02-25 12:53:36 +0000 | [diff] [blame] | 21 | #include <vnet/ipsec/ipsec_sa.h> |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 22 | |
| 23 | #undef always_inline |
Gabriel Ganne | 794813f | 2017-03-07 17:04:02 +0100 | [diff] [blame] | 24 | #include <rte_config.h> |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 25 | #include <rte_crypto.h> |
| 26 | #include <rte_cryptodev.h> |
| 27 | |
| 28 | #if CLIB_DEBUG > 0 |
| 29 | #define always_inline static inline |
| 30 | #else |
| 31 | #define always_inline static inline __attribute__ ((__always_inline__)) |
| 32 | #endif |
| 33 | |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 34 | #define DPDK_CRYPTO_N_QUEUE_DESC 2048 |
| 35 | #define DPDK_CRYPTO_NB_SESS_OBJS 20000 |
| 36 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 37 | #define foreach_dpdk_crypto_input_next \ |
| 38 | _(DROP, "error-drop") \ |
| 39 | _(IP4_LOOKUP, "ip4-lookup") \ |
| 40 | _(IP6_LOOKUP, "ip6-lookup") \ |
| 41 | _(INTERFACE_OUTPUT, "interface-output") \ |
Neale Ranns | 7ec120e | 2020-01-21 04:58:02 +0000 | [diff] [blame] | 42 | _(MIDCHAIN, "adj-midchain-tx") \ |
Klement Sekera | 7334393 | 2018-10-22 13:17:19 +0200 | [diff] [blame] | 43 | _(DECRYPT4_POST, "dpdk-esp4-decrypt-post") \ |
| 44 | _(DECRYPT6_POST, "dpdk-esp6-decrypt-post") |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 45 | |
| 46 | typedef enum |
| 47 | { |
| 48 | #define _(f,s) DPDK_CRYPTO_INPUT_NEXT_##f, |
| 49 | foreach_dpdk_crypto_input_next |
| 50 | #undef _ |
| 51 | DPDK_CRYPTO_INPUT_N_NEXT, |
| 52 | } dpdk_crypto_input_next_t; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 53 | |
| 54 | #define MAX_QP_PER_LCORE 16 |
| 55 | |
| 56 | typedef struct |
| 57 | { |
Radu Nicolau | 6929ea9 | 2016-11-29 11:00:30 +0000 | [diff] [blame] | 58 | u32 salt; |
| 59 | u32 iv[2]; |
| 60 | u32 cnt; |
| 61 | } dpdk_gcm_cnt_blk; |
| 62 | |
| 63 | typedef struct |
| 64 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 65 | u32 next; |
Kingwel Xie | 3b3464e | 2019-02-13 02:48:41 -0500 | [diff] [blame] | 66 | u32 bi; |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 67 | u8 encrypt; |
| 68 | CLIB_ALIGN_MARK (mark0, 16); |
| 69 | dpdk_gcm_cnt_blk cb; |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 70 | u8 aad[16]; |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 71 | u8 icv[32]; /* XXX last 16B in next cache line */ |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 72 | } dpdk_op_priv_t; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 73 | |
| 74 | typedef struct |
| 75 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 76 | u16 *resource_idx; |
Sergio Gonzalez Monroy | df36f21 | 2017-10-31 15:58:57 +0000 | [diff] [blame] | 77 | struct rte_crypto_op **ops; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 78 | u16 cipher_resource_idx[IPSEC_CRYPTO_N_ALG]; |
| 79 | u16 auth_resource_idx[IPSEC_INTEG_N_ALG]; |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 80 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 81 | } crypto_worker_main_t; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 82 | |
| 83 | typedef struct |
| 84 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 85 | CLIB_ALIGN_MARK (pad, 8); /* align up to 8 bytes for 32bit builds */ |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 86 | char *name; |
| 87 | enum rte_crypto_sym_xform_type type; |
| 88 | u32 alg; |
| 89 | u8 key_len; |
| 90 | u8 iv_len; |
| 91 | u8 trunc_size; |
| 92 | u8 boundary; |
| 93 | u8 disabled; |
| 94 | u8 resources; |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 95 | } crypto_alg_t; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 96 | |
| 97 | typedef struct |
| 98 | { |
| 99 | u16 *free_resources; |
| 100 | u16 *used_resources; |
| 101 | u8 cipher_support[IPSEC_CRYPTO_N_ALG]; |
| 102 | u8 auth_support[IPSEC_INTEG_N_ALG]; |
| 103 | u8 drv_id; |
| 104 | u8 numa; |
| 105 | u16 id; |
Damjan Marion | ffe9d21 | 2018-05-30 09:26:11 +0200 | [diff] [blame] | 106 | const char *name; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 107 | u32 max_qp; |
| 108 | u64 features; |
| 109 | } crypto_dev_t; |
| 110 | |
| 111 | typedef struct |
| 112 | { |
Damjan Marion | ffe9d21 | 2018-05-30 09:26:11 +0200 | [diff] [blame] | 113 | const char *name; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 114 | u16 *devs; |
| 115 | } crypto_drv_t; |
| 116 | |
| 117 | typedef struct |
| 118 | { |
| 119 | u16 thread_idx; |
| 120 | u8 remove; |
| 121 | u8 drv_id; |
| 122 | u8 dev_id; |
| 123 | u8 numa; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 124 | u16 qp_id; |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 125 | u16 inflights[2]; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 126 | u16 n_ops; |
| 127 | u16 __unused; |
| 128 | struct rte_crypto_op *ops[VLIB_FRAME_SIZE]; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 129 | u32 bi[VLIB_FRAME_SIZE]; |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 130 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 131 | } crypto_resource_t; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 132 | |
| 133 | typedef struct |
| 134 | { |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 135 | u64 ts; |
| 136 | struct rte_cryptodev_sym_session *session; |
| 137 | } crypto_session_disposal_t; |
| 138 | |
| 139 | typedef struct |
| 140 | { |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 141 | struct rte_cryptodev_sym_session *session; |
| 142 | u64 dev_mask; |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 143 | CLIB_ALIGN_MARK (pad, 16); /* align up to 16 bytes for 32bit builds */ |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 144 | } crypto_session_by_drv_t; |
| 145 | |
| 146 | typedef struct |
| 147 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 148 | struct rte_mempool *crypto_op; |
| 149 | struct rte_mempool *session_h; |
| 150 | struct rte_mempool **session_drv; |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 151 | crypto_session_disposal_t *session_disposal; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 152 | uword *session_by_sa_index; |
| 153 | u64 crypto_op_get_failed; |
| 154 | u64 session_h_failed; |
| 155 | u64 *session_drv_failed; |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 156 | crypto_session_by_drv_t *session_by_drv_id_and_sa_index; |
Radu Nicolau | 5aaea11 | 2018-04-06 12:12:21 +0100 | [diff] [blame] | 157 | clib_spinlock_t lockp; |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 158 | /* Required for vec_validate_aligned */ |
| 159 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 160 | } crypto_data_t; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 161 | |
| 162 | typedef struct |
| 163 | { |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 164 | crypto_worker_main_t *workers_main; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 165 | crypto_dev_t *dev; |
| 166 | crypto_resource_t *resource; |
| 167 | crypto_alg_t *cipher_algs; |
| 168 | crypto_alg_t *auth_algs; |
| 169 | crypto_data_t *data; |
| 170 | crypto_drv_t *drv; |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 171 | u64 session_timeout; /* nsec */ |
Sergio Gonzalez Monroy | 63c7e14 | 2017-03-22 16:11:06 +0000 | [diff] [blame] | 172 | u8 enabled; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 173 | } dpdk_crypto_main_t; |
| 174 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 175 | extern dpdk_crypto_main_t dpdk_crypto_main; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 176 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 177 | static const u8 pad_data[] = |
| 178 | { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 }; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 179 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 180 | void crypto_auto_placement (void); |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 181 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 182 | clib_error_t *create_sym_session (struct rte_cryptodev_sym_session **session, |
| 183 | u32 sa_idx, crypto_resource_t * res, |
| 184 | crypto_worker_main_t * cwm, u8 is_outbound); |
| 185 | |
| 186 | static_always_inline u32 |
| 187 | crypto_op_len (void) |
| 188 | { |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 189 | const u32 align = 4; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 190 | u32 op_size = |
| 191 | sizeof (struct rte_crypto_op) + sizeof (struct rte_crypto_sym_op); |
| 192 | |
| 193 | return ((op_size + align - 1) & ~(align - 1)) + sizeof (dpdk_op_priv_t); |
| 194 | } |
| 195 | |
| 196 | static_always_inline u32 |
| 197 | crypto_op_get_priv_offset (void) |
| 198 | { |
| 199 | const u32 align = 16; |
| 200 | u32 offset; |
| 201 | |
| 202 | offset = sizeof (struct rte_crypto_op) + sizeof (struct rte_crypto_sym_op); |
| 203 | offset = (offset + align - 1) & ~(align - 1); |
| 204 | |
| 205 | return offset; |
| 206 | } |
| 207 | |
| 208 | static_always_inline dpdk_op_priv_t * |
| 209 | crypto_op_get_priv (struct rte_crypto_op * op) |
| 210 | { |
| 211 | return (dpdk_op_priv_t *) (((u8 *) op) + crypto_op_get_priv_offset ()); |
| 212 | } |
| 213 | |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 214 | |
| 215 | static_always_inline void |
| 216 | add_session_by_drv_and_sa_idx (struct rte_cryptodev_sym_session *session, |
| 217 | crypto_data_t * data, u32 drv_id, u32 sa_idx) |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 218 | { |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 219 | crypto_session_by_drv_t *sbd; |
| 220 | vec_validate_aligned (data->session_by_drv_id_and_sa_index, sa_idx, |
| 221 | CLIB_CACHE_LINE_BYTES); |
| 222 | sbd = vec_elt_at_index (data->session_by_drv_id_and_sa_index, sa_idx); |
| 223 | sbd->dev_mask |= 1L << drv_id; |
| 224 | sbd->session = session; |
| 225 | } |
| 226 | |
| 227 | static_always_inline struct rte_cryptodev_sym_session * |
| 228 | get_session_by_drv_and_sa_idx (crypto_data_t * data, u32 drv_id, u32 sa_idx) |
| 229 | { |
| 230 | crypto_session_by_drv_t *sess_by_sa; |
| 231 | if (_vec_len (data->session_by_drv_id_and_sa_index) <= sa_idx) |
| 232 | return NULL; |
| 233 | sess_by_sa = |
| 234 | vec_elt_at_index (data->session_by_drv_id_and_sa_index, sa_idx); |
| 235 | return (sess_by_sa->dev_mask & (1L << drv_id)) ? sess_by_sa->session : NULL; |
| 236 | } |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 237 | |
| 238 | static_always_inline clib_error_t * |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 239 | crypto_get_session (struct rte_cryptodev_sym_session ** session, |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 240 | u32 sa_idx, |
| 241 | crypto_resource_t * res, |
| 242 | crypto_worker_main_t * cwm, u8 is_outbound) |
| 243 | { |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 244 | dpdk_crypto_main_t *dcm = &dpdk_crypto_main; |
| 245 | crypto_data_t *data; |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 246 | struct rte_cryptodev_sym_session *sess; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 247 | |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 248 | data = vec_elt_at_index (dcm->data, res->numa); |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 249 | sess = get_session_by_drv_and_sa_idx (data, res->drv_id, sa_idx); |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 250 | |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 251 | if (PREDICT_FALSE (!sess)) |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 252 | return create_sym_session (session, sa_idx, res, cwm, is_outbound); |
| 253 | |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 254 | session[0] = sess; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 255 | |
| 256 | return NULL; |
| 257 | } |
| 258 | |
| 259 | static_always_inline u16 |
| 260 | get_resource (crypto_worker_main_t * cwm, ipsec_sa_t * sa) |
| 261 | { |
| 262 | u16 cipher_res = cwm->cipher_resource_idx[sa->crypto_alg]; |
| 263 | u16 auth_res = cwm->auth_resource_idx[sa->integ_alg]; |
| 264 | u8 is_aead; |
| 265 | |
| 266 | /* Not allowed to setup SA with no-aead-cipher/NULL or NULL/NULL */ |
| 267 | |
Radu Nicolau | de412ce | 2018-03-12 13:52:41 +0000 | [diff] [blame] | 268 | is_aead = ((sa->crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_128) || |
| 269 | (sa->crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_192) || |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 270 | (sa->crypto_alg == IPSEC_CRYPTO_ALG_AES_GCM_256)); |
| 271 | |
| 272 | if (sa->crypto_alg == IPSEC_CRYPTO_ALG_NONE) |
| 273 | return auth_res; |
| 274 | |
| 275 | if (cipher_res == auth_res) |
| 276 | return cipher_res; |
| 277 | |
| 278 | if (is_aead) |
| 279 | return cipher_res; |
| 280 | |
| 281 | return (u16) ~ 0; |
| 282 | } |
| 283 | |
| 284 | static_always_inline i32 |
| 285 | crypto_alloc_ops (u8 numa, struct rte_crypto_op ** ops, u32 n) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 286 | { |
| 287 | dpdk_crypto_main_t *dcm = &dpdk_crypto_main; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 288 | crypto_data_t *data = vec_elt_at_index (dcm->data, numa); |
| 289 | i32 ret; |
| 290 | |
| 291 | ret = rte_mempool_get_bulk (data->crypto_op, (void **) ops, n); |
| 292 | |
Damjan Marion | 45b4850 | 2017-11-17 09:46:41 +0100 | [diff] [blame] | 293 | /* *INDENT-OFF* */ |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 294 | data->crypto_op_get_failed += ! !ret; |
Damjan Marion | 45b4850 | 2017-11-17 09:46:41 +0100 | [diff] [blame] | 295 | /* *INDENT-ON* */ |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 296 | |
| 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | static_always_inline void |
| 301 | crypto_free_ops (u8 numa, struct rte_crypto_op **ops, u32 n) |
| 302 | { |
| 303 | dpdk_crypto_main_t *dcm = &dpdk_crypto_main; |
| 304 | crypto_data_t *data = vec_elt_at_index (dcm->data, numa); |
| 305 | |
| 306 | if (!n) |
| 307 | return; |
| 308 | |
| 309 | rte_mempool_put_bulk (data->crypto_op, (void **) ops, n); |
| 310 | } |
| 311 | |
| 312 | static_always_inline void |
Sergio Gonzalez Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 313 | crypto_enqueue_ops (vlib_main_t * vm, crypto_worker_main_t * cwm, |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 314 | u32 node_index, u32 error, u8 numa, u8 encrypt) |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 315 | { |
| 316 | dpdk_crypto_main_t *dcm = &dpdk_crypto_main; |
| 317 | crypto_resource_t *res; |
| 318 | u16 *res_idx; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 319 | |
| 320 | /* *INDENT-OFF* */ |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 321 | vec_foreach (res_idx, cwm->resource_idx) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 322 | { |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 323 | u16 enq, n_ops; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 324 | res = vec_elt_at_index (dcm->resource, res_idx[0]); |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 325 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 326 | if (!res->n_ops) |
| 327 | continue; |
| 328 | |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 329 | n_ops = (DPDK_CRYPTO_N_QUEUE_DESC / 2) - res->inflights[encrypt]; |
| 330 | n_ops = res->n_ops < n_ops ? res->n_ops : n_ops; |
Sergio Gonzalez Monroy | 35467f1 | 2019-01-30 11:26:00 +0100 | [diff] [blame] | 331 | enq = rte_cryptodev_enqueue_burst (res->dev_id, res->qp_id, |
Sergio Gonzalez Monroy | d8a34a5 | 2019-05-06 22:44:14 +0200 | [diff] [blame] | 332 | res->ops, n_ops); |
| 333 | ASSERT (n_ops == enq); |
| 334 | res->inflights[encrypt] += enq; |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 335 | |
| 336 | if (PREDICT_FALSE (enq < res->n_ops)) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 337 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 338 | crypto_free_ops (numa, &res->ops[enq], res->n_ops - enq); |
| 339 | vlib_buffer_free (vm, &res->bi[enq], res->n_ops - enq); |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 340 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 341 | vlib_node_increment_counter (vm, node_index, error, |
| 342 | res->n_ops - enq); |
| 343 | } |
| 344 | res->n_ops = 0; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 345 | } |
| 346 | /* *INDENT-ON* */ |
| 347 | } |
| 348 | |
| 349 | static_always_inline void |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 350 | crypto_set_icb (dpdk_gcm_cnt_blk * icb, u32 salt, u32 seq, u32 seq_hi) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 351 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 352 | icb->salt = salt; |
| 353 | icb->iv[0] = seq; |
| 354 | icb->iv[1] = seq_hi; |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 357 | static_always_inline void |
| 358 | crypto_op_setup (u8 is_aead, struct rte_mbuf *mb0, |
| 359 | struct rte_crypto_op *op, void *session, |
| 360 | u32 cipher_off, u32 cipher_len, |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 361 | u32 auth_off, u32 auth_len, |
Sergio Gonzalez Monroy | 99214ce | 2017-11-26 15:25:43 +0000 | [diff] [blame] | 362 | u8 * aad, u8 * digest, u64 digest_paddr) |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 363 | { |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 364 | struct rte_crypto_sym_op *sym_op; |
| 365 | |
| 366 | sym_op = (struct rte_crypto_sym_op *) (op + 1); |
| 367 | |
| 368 | sym_op->m_src = mb0; |
| 369 | sym_op->session = session; |
| 370 | |
Sergio Gonzalez Monroy | db93cd9 | 2017-08-26 15:22:05 +0100 | [diff] [blame] | 371 | if (is_aead) |
| 372 | { |
| 373 | sym_op->aead.data.offset = cipher_off; |
| 374 | sym_op->aead.data.length = cipher_len; |
| 375 | |
| 376 | sym_op->aead.aad.data = aad; |
| 377 | sym_op->aead.aad.phys_addr = |
| 378 | op->phys_addr + (uintptr_t) aad - (uintptr_t) op; |
| 379 | |
| 380 | sym_op->aead.digest.data = digest; |
| 381 | sym_op->aead.digest.phys_addr = digest_paddr; |
| 382 | } |
| 383 | else |
| 384 | { |
| 385 | sym_op->cipher.data.offset = cipher_off; |
| 386 | sym_op->cipher.data.length = cipher_len; |
| 387 | |
| 388 | sym_op->auth.data.offset = auth_off; |
| 389 | sym_op->auth.data.length = auth_len; |
| 390 | |
| 391 | sym_op->auth.digest.data = digest; |
| 392 | sym_op->auth.digest.phys_addr = digest_paddr; |
| 393 | } |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 396 | #endif /* __DPDK_IPSEC_H__ */ |
| 397 | |
| 398 | /* |
| 399 | * fd.io coding-style-patch-verification: ON |
| 400 | * |
| 401 | * Local Variables: |
| 402 | * eval: (c-set-style "gnu") |
| 403 | * End: |
| 404 | */ |