Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2017-2022 Intel Corporation
3 : : */
4 : :
5 : : #ifndef _QAT_CRYPTO_PMD_GENS_H_
6 : : #define _QAT_CRYPTO_PMD_GENS_H_
7 : :
8 : : #include <rte_cryptodev.h>
9 : : #include "qat_crypto.h"
10 : : #include "qat_sym_session.h"
11 : : #include "qat_sym.h"
12 : :
13 : : #define AES_OR_3DES_MISALIGNED (ctx->qat_mode == ICP_QAT_HW_CIPHER_CBC_MODE && \
14 : : ((((ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES128) || \
15 : : (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES192) || \
16 : : (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES256)) && \
17 : : (cipher_param->cipher_length % ICP_QAT_HW_AES_BLK_SZ)) || \
18 : : ((ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_3DES) && \
19 : : (cipher_param->cipher_length % ICP_QAT_HW_3DES_BLK_SZ))))
20 : : #define QAT_SYM_DP_GET_MAX_ENQ(q, c, n) \
21 : : RTE_MIN((q->max_inflights - q->enqueued + q->dequeued - c), n)
22 : :
23 : : #define QAT_SYM_DP_IS_RESP_SUCCESS(resp) \
24 : : (ICP_QAT_FW_COMN_STATUS_FLAG_OK == \
25 : : ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(resp->comn_hdr.comn_status))
26 : :
27 : : #ifdef RTE_QAT_OPENSSL
28 : : static __rte_always_inline int
29 : : op_bpi_cipher_decrypt(uint8_t *src, uint8_t *dst,
30 : : uint8_t *iv, int ivlen, int srclen,
31 : : void *bpi_ctx)
32 : : {
33 : : EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX *)bpi_ctx;
34 : : int encrypted_ivlen;
35 : : uint8_t encrypted_iv[BPI_MAX_ENCR_IV_LEN];
36 : : uint8_t *encr = encrypted_iv;
37 : :
38 : : /* ECB method: encrypt (not decrypt!) the IV, then XOR with plaintext */
39 [ # # # # ]: 0 : if (EVP_EncryptUpdate(ctx, encrypted_iv, &encrypted_ivlen, iv, ivlen)
40 : : <= 0)
41 : 0 : goto cipher_decrypt_err;
42 : :
43 [ # # # # ]: 0 : for (; srclen != 0; --srclen, ++dst, ++src, ++encr)
44 : 0 : *dst = *src ^ *encr;
45 : :
46 : : return 0;
47 : :
48 : : cipher_decrypt_err:
49 : 0 : QAT_DP_LOG(ERR, "libcrypto ECB cipher decrypt for BPI IV failed");
50 : 0 : return -EINVAL;
51 : : }
52 : : #endif
53 : :
54 : : static __rte_always_inline uint32_t
55 : : qat_bpicipher_preprocess(struct qat_sym_session *ctx,
56 : : struct rte_crypto_op *op)
57 : : {
58 : 0 : int block_len = qat_cipher_get_block_size(ctx->qat_cipher_alg);
59 : : struct rte_crypto_sym_op *sym_op = op->sym;
60 [ # # # # ]: 0 : uint8_t last_block_len = block_len > 0 ?
61 : 0 : sym_op->cipher.data.length % block_len : 0;
62 : :
63 [ # # # # : 0 : if (last_block_len && ctx->qat_dir == ICP_QAT_HW_CIPHER_DECRYPT) {
# # # # ]
64 : : /* Decrypt last block */
65 : : uint8_t *last_block, *dst, *iv;
66 : 0 : uint32_t last_block_offset = sym_op->cipher.data.offset +
67 : : sym_op->cipher.data.length - last_block_len;
68 : 0 : last_block = rte_pktmbuf_mtod_offset(sym_op->m_src, uint8_t *,
69 : : last_block_offset);
70 : :
71 [ # # # # : 0 : if (unlikely((sym_op->m_dst != NULL)
# # # # ]
72 : : && (sym_op->m_dst != sym_op->m_src)))
73 : : /* out-of-place operation (OOP) */
74 : 0 : dst = rte_pktmbuf_mtod_offset(sym_op->m_dst,
75 : : uint8_t *,
76 : : last_block_offset);
77 : : else
78 : : dst = last_block;
79 : :
80 [ # # # # ]: 0 : if (last_block_len < sym_op->cipher.data.length)
81 : : /* use previous block ciphertext as IV */
82 : 0 : iv = last_block - block_len;
83 : : else
84 : : /* runt block, i.e. less than one full block */
85 : 0 : iv = rte_crypto_op_ctod_offset(op, uint8_t *,
86 : : ctx->cipher_iv.offset);
87 : :
88 : : #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
89 : : QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: src before pre-process:",
90 : : last_block, last_block_len);
91 : : if (sym_op->m_dst != NULL)
92 : : QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: dst before pre-process:",
93 : : dst, last_block_len);
94 : : #endif
95 : : #ifdef RTE_QAT_OPENSSL
96 : 0 : op_bpi_cipher_decrypt(last_block, dst, iv, block_len,
97 : : last_block_len, ctx->bpi_ctx);
98 : : #else
99 : : bpi_cipher_ipsec(last_block, dst, iv, last_block_len, ctx->expkey,
100 : : ctx->mb_mgr, ctx->docsis_key_len);
101 : : #endif
102 : : #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
103 : : QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: src after pre-process:",
104 : : last_block, last_block_len);
105 : : if (sym_op->m_dst != NULL)
106 : : QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: dst after pre-process:",
107 : : dst, last_block_len);
108 : : #endif
109 : : }
110 : :
111 : 0 : return sym_op->cipher.data.length - last_block_len;
112 : : }
113 : :
114 : : static __rte_always_inline int
115 : : qat_auth_is_len_in_bits(struct qat_sym_session *ctx,
116 : : struct rte_crypto_op *op)
117 : : {
118 : 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 ||
119 [ # # # # ]: 0 : ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_KASUMI_F9 ||
120 : : ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3) {
121 [ # # # # ]: 0 : if (unlikely((op->sym->auth.data.offset % BYTE_LENGTH != 0) ||
122 : : (op->sym->auth.data.length % BYTE_LENGTH != 0)))
123 : : return -EINVAL;
124 : : return 1;
125 : : }
126 : : return 0;
127 : : }
128 : :
129 : : static __rte_always_inline int
130 : : qat_cipher_is_len_in_bits(struct qat_sym_session *ctx,
131 : : struct rte_crypto_op *op)
132 : : {
133 : 0 : if (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 ||
134 [ # # # # ]: 0 : ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_KASUMI ||
135 : : ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3) {
136 [ # # # # ]: 0 : if (unlikely((op->sym->cipher.data.length % BYTE_LENGTH != 0) ||
137 : : ((op->sym->cipher.data.offset %
138 : : BYTE_LENGTH) != 0)))
139 : : return -EINVAL;
140 : : return 1;
141 : : }
142 : : return 0;
143 : : }
144 : :
145 : : static __rte_always_inline int32_t
146 : : qat_sym_build_req_set_data(struct icp_qat_fw_la_bulk_req *req,
147 : : void *opaque, struct qat_sym_op_cookie *cookie,
148 : : struct rte_crypto_vec *src_vec, uint16_t n_src,
149 : : struct rte_crypto_vec *dst_vec, uint16_t n_dst)
150 : : {
151 : : struct qat_sgl *list;
152 : : uint32_t i;
153 : : uint32_t tl_src = 0, total_len_src, total_len_dst;
154 : : uint64_t src_data_start = 0, dst_data_start = 0;
155 : 0 : int is_sgl = n_src > 1 || n_dst > 1;
156 : :
157 [ # # # # : 0 : if (unlikely(n_src < 1 || n_src > QAT_SYM_SGL_MAX_NUMBER ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
158 : : n_dst > QAT_SYM_SGL_MAX_NUMBER))
159 : : return -1;
160 : :
161 [ # # # # : 0 : if (likely(!is_sgl)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
162 : 0 : src_data_start = src_vec[0].iova;
163 : 0 : tl_src = total_len_src =
164 : : src_vec[0].len;
165 [ # # # # : 0 : if (unlikely(n_dst)) { /* oop */
# # # # #
# # # # #
# # ]
166 : 0 : total_len_dst = dst_vec[0].len;
167 : :
168 : 0 : dst_data_start = dst_vec[0].iova;
169 [ # # # # : 0 : if (unlikely(total_len_src != total_len_dst))
# # # # #
# # # # #
# # ]
170 : : return -EINVAL;
171 : : } else {
172 : : dst_data_start = src_data_start;
173 : : total_len_dst = tl_src;
174 : : }
175 : : } else { /* sgl */
176 : : total_len_dst = total_len_src = 0;
177 : :
178 : 0 : ICP_QAT_FW_COMN_PTR_TYPE_SET(req->comn_hdr.comn_req_flags,
179 : : QAT_COMN_PTR_TYPE_SGL);
180 : :
181 : : list = (struct qat_sgl *)&cookie->qat_sgl_src;
182 [ # # # # : 0 : for (i = 0; i < n_src; i++) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
183 : 0 : list->buffers[i].len = src_vec[i].len;
184 : 0 : list->buffers[i].resrvd = 0;
185 : 0 : list->buffers[i].addr = src_vec[i].iova;
186 : : if (tl_src + src_vec[i].len > UINT32_MAX) {
187 : : QAT_DP_LOG(ERR, "Message too long");
188 : : return -1;
189 : : }
190 : 0 : tl_src += src_vec[i].len;
191 : : }
192 : :
193 : 0 : list->num_bufs = i;
194 : 0 : src_data_start = cookie->qat_sgl_src_phys_addr;
195 : :
196 [ # # # # : 0 : if (unlikely(n_dst > 0)) { /* oop sgl */
# # # # #
# # # # #
# # ]
197 : : uint32_t tl_dst = 0;
198 : :
199 : : list = (struct qat_sgl *)&cookie->qat_sgl_dst;
200 : :
201 [ # # # # : 0 : for (i = 0; i < n_dst; i++) {
# # # # #
# # # # #
# # ]
202 : 0 : list->buffers[i].len = dst_vec[i].len;
203 : 0 : list->buffers[i].resrvd = 0;
204 : 0 : list->buffers[i].addr = dst_vec[i].iova;
205 : : if (tl_dst + dst_vec[i].len > UINT32_MAX) {
206 : : QAT_DP_LOG(ERR, "Message too long");
207 : : return -ENOTSUP;
208 : : }
209 : :
210 : 0 : tl_dst += dst_vec[i].len;
211 : : }
212 : :
213 [ # # # # : 0 : if (tl_src != tl_dst)
# # # # #
# # # # #
# # ]
214 : : return -EINVAL;
215 : 0 : list->num_bufs = i;
216 : 0 : dst_data_start = cookie->qat_sgl_dst_phys_addr;
217 : : } else
218 : : dst_data_start = src_data_start;
219 : : }
220 : :
221 : 0 : req->comn_mid.src_data_addr = src_data_start;
222 : 0 : req->comn_mid.dest_data_addr = dst_data_start;
223 : 0 : req->comn_mid.src_length = total_len_src;
224 : 0 : req->comn_mid.dst_length = total_len_dst;
225 : 0 : req->comn_mid.opaque_data = (uintptr_t)opaque;
226 : :
227 : 0 : return tl_src;
228 : : }
229 : :
230 : : static __rte_always_inline uint64_t
231 : : qat_sym_convert_op_to_vec_cipher(struct rte_crypto_op *op,
232 : : struct qat_sym_session *ctx,
233 : : struct rte_crypto_sgl *in_sgl, struct rte_crypto_sgl *out_sgl,
234 : : struct rte_crypto_va_iova_ptr *cipher_iv,
235 : : struct rte_crypto_va_iova_ptr *auth_iv_or_aad __rte_unused,
236 : : struct rte_crypto_va_iova_ptr *digest __rte_unused)
237 : : {
238 : : uint32_t cipher_len = 0, cipher_ofs = 0;
239 : : int n_src = 0;
240 : : int ret;
241 : :
242 : : ret = qat_cipher_is_len_in_bits(ctx, op);
243 : : switch (ret) {
244 : : case 1:
245 : 0 : cipher_len = op->sym->cipher.data.length >> 3;
246 : 0 : cipher_ofs = op->sym->cipher.data.offset >> 3;
247 : 0 : break;
248 : : case 0:
249 : :
250 : : #ifdef RTE_QAT_OPENSSL
251 [ # # ]: 0 : if (ctx->bpi_ctx) {
252 : : #else
253 : : if (ctx->mb_mgr) {
254 : : #endif
255 : : /* DOCSIS - only send complete blocks to device.
256 : : * Process any partial block using CFB mode.
257 : : * Even if 0 complete blocks, still send this to device
258 : : * to get into rx queue for post-process and dequeuing
259 : : */
260 : : cipher_len = qat_bpicipher_preprocess(ctx, op);
261 : 0 : cipher_ofs = op->sym->cipher.data.offset;
262 : : } else {
263 : 0 : cipher_len = op->sym->cipher.data.length;
264 : 0 : cipher_ofs = op->sym->cipher.data.offset;
265 : : }
266 : : break;
267 : : default:
268 : 0 : QAT_DP_LOG(ERR,
269 : : "SNOW3G/KASUMI/ZUC in QAT PMD only supports byte aligned values");
270 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
271 : 0 : return UINT64_MAX;
272 : : }
273 : :
274 : 0 : cipher_iv->va = rte_crypto_op_ctod_offset(op, void *,
275 : : ctx->cipher_iv.offset);
276 : 0 : cipher_iv->iova = rte_crypto_op_ctophys_offset(op,
277 : : ctx->cipher_iv.offset);
278 : :
279 : 0 : n_src = rte_crypto_mbuf_to_vec(op->sym->m_src, cipher_ofs,
280 : : cipher_len, in_sgl->vec, QAT_SYM_SGL_MAX_NUMBER);
281 [ # # # # ]: 0 : if (n_src < 0 || n_src > op->sym->m_src->nb_segs) {
282 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
283 : 0 : return UINT64_MAX;
284 : : }
285 : :
286 : 0 : in_sgl->num = n_src;
287 : :
288 : : /* Out-Of-Place operation */
289 [ # # # # ]: 0 : if (unlikely((op->sym->m_dst != NULL) &&
290 : 0 : (op->sym->m_dst != op->sym->m_src))) {
291 : 0 : int n_dst = rte_crypto_mbuf_to_vec(op->sym->m_dst, cipher_ofs,
292 : : cipher_len, out_sgl->vec,
293 : : QAT_SYM_SGL_MAX_NUMBER);
294 : :
295 [ # # # # ]: 0 : if ((n_dst < 0) || (n_dst > op->sym->m_dst->nb_segs)) {
296 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
297 : 0 : return UINT64_MAX;
298 : : }
299 : :
300 : 0 : out_sgl->num = n_dst;
301 : : } else
302 : : out_sgl->num = 0;
303 : :
304 : : return 0;
305 : : }
306 : :
307 : : static __rte_always_inline uint64_t
308 : : qat_sym_convert_op_to_vec_auth(struct rte_crypto_op *op,
309 : : struct qat_sym_session *ctx,
310 : : struct rte_crypto_sgl *in_sgl, struct rte_crypto_sgl *out_sgl,
311 : : struct rte_crypto_va_iova_ptr *cipher_iv __rte_unused,
312 : : struct rte_crypto_va_iova_ptr *auth_iv,
313 : : struct rte_crypto_va_iova_ptr *digest,
314 : : struct qat_sym_op_cookie *cookie)
315 : : {
316 : : uint32_t auth_ofs = 0, auth_len = 0;
317 : : int n_src, ret;
318 : :
319 : : ret = qat_auth_is_len_in_bits(ctx, op);
320 : : switch (ret) {
321 : : case 1:
322 : 0 : auth_ofs = op->sym->auth.data.offset >> 3;
323 : 0 : auth_len = op->sym->auth.data.length >> 3;
324 : 0 : auth_iv->va = rte_crypto_op_ctod_offset(op, void *,
325 : : ctx->auth_iv.offset);
326 : 0 : auth_iv->iova = rte_crypto_op_ctophys_offset(op,
327 : : ctx->auth_iv.offset);
328 : 0 : break;
329 : : case 0:
330 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
331 : : ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
332 : : /* AES-GMAC */
333 : 0 : auth_ofs = op->sym->auth.data.offset;
334 : 0 : auth_len = op->sym->auth.data.length;
335 : 0 : auth_iv->va = rte_crypto_op_ctod_offset(op, void *,
336 : : ctx->auth_iv.offset);
337 : 0 : auth_iv->iova = rte_crypto_op_ctophys_offset(op,
338 : : ctx->auth_iv.offset);
339 : : } else {
340 : 0 : auth_ofs = op->sym->auth.data.offset;
341 : 0 : auth_len = op->sym->auth.data.length;
342 : : auth_iv->va = NULL;
343 : : auth_iv->iova = 0;
344 : : }
345 : : break;
346 : : default:
347 : 0 : QAT_DP_LOG(ERR,
348 : : "For SNOW3G/KASUMI/ZUC, QAT PMD only supports byte aligned values");
349 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
350 : 0 : return UINT64_MAX;
351 : : }
352 : :
353 : 0 : n_src = rte_crypto_mbuf_to_vec(op->sym->m_src, auth_ofs,
354 : : auth_len, in_sgl->vec,
355 : : QAT_SYM_SGL_MAX_NUMBER);
356 [ # # # # ]: 0 : if (n_src < 0 || n_src > op->sym->m_src->nb_segs) {
357 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
358 : 0 : return UINT64_MAX;
359 : : }
360 : :
361 : 0 : in_sgl->num = n_src;
362 : :
363 : : /* Out-Of-Place operation */
364 [ # # # # ]: 0 : if (unlikely((op->sym->m_dst != NULL) &&
365 : 0 : (op->sym->m_dst != op->sym->m_src))) {
366 : 0 : int n_dst = rte_crypto_mbuf_to_vec(op->sym->m_dst, auth_ofs,
367 : : auth_len, out_sgl->vec,
368 : : QAT_SYM_SGL_MAX_NUMBER);
369 : :
370 [ # # # # ]: 0 : if ((n_dst < 0) || (n_dst > op->sym->m_dst->nb_segs)) {
371 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
372 : 0 : return UINT64_MAX;
373 : : }
374 : 0 : out_sgl->num = n_dst;
375 : : } else
376 : : out_sgl->num = 0;
377 : :
378 : : digest->va = (void *)op->sym->auth.digest.data;
379 : :
380 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_NULL)
381 : 0 : digest->iova = cookie->digest_null_phys_addr;
382 : : else
383 : 0 : digest->iova = op->sym->auth.digest.phys_addr;
384 : :
385 : : return 0;
386 : : }
387 : :
388 : : static __rte_always_inline uint64_t
389 : : qat_sym_convert_op_to_vec_chain(struct rte_crypto_op *op,
390 : : struct qat_sym_session *ctx,
391 : : struct rte_crypto_sgl *in_sgl, struct rte_crypto_sgl *out_sgl,
392 : : struct rte_crypto_va_iova_ptr *cipher_iv,
393 : : struct rte_crypto_va_iova_ptr *auth_iv_or_aad,
394 : : struct rte_crypto_va_iova_ptr *digest,
395 : : struct qat_sym_op_cookie *cookie)
396 : : {
397 : : union rte_crypto_sym_ofs ofs;
398 : : uint32_t max_len = 0;
399 : : uint32_t cipher_len = 0, cipher_ofs = 0;
400 : : uint32_t auth_len = 0, auth_ofs = 0;
401 [ # # ]: 0 : int is_oop = (op->sym->m_dst != NULL) &&
402 [ # # ]: 0 : (op->sym->m_dst != op->sym->m_src);
403 : 0 : int is_sgl = op->sym->m_src->nb_segs > 1;
404 : : int is_bpi = 0;
405 : : int n_src;
406 : : int ret;
407 : :
408 [ # # ]: 0 : if (unlikely(is_oop))
409 : 0 : is_sgl |= op->sym->m_dst->nb_segs > 1;
410 : :
411 : 0 : cipher_iv->va = rte_crypto_op_ctod_offset(op, void *,
412 : : ctx->cipher_iv.offset);
413 : 0 : cipher_iv->iova = rte_crypto_op_ctophys_offset(op,
414 : : ctx->cipher_iv.offset);
415 : 0 : auth_iv_or_aad->va = rte_crypto_op_ctod_offset(op, void *,
416 : : ctx->auth_iv.offset);
417 : 0 : auth_iv_or_aad->iova = rte_crypto_op_ctophys_offset(op,
418 : : ctx->auth_iv.offset);
419 : : digest->va = (void *)op->sym->auth.digest.data;
420 : :
421 [ # # ]: 0 : if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_NULL)
422 : 0 : digest->iova = cookie->digest_null_phys_addr;
423 : : else
424 : 0 : digest->iova = op->sym->auth.digest.phys_addr;
425 : :
426 : : ret = qat_cipher_is_len_in_bits(ctx, op);
427 : : switch (ret) {
428 : : case 1:
429 : 0 : cipher_len = op->sym->cipher.data.length >> 3;
430 : 0 : cipher_ofs = op->sym->cipher.data.offset >> 3;
431 : 0 : break;
432 : : case 0:
433 : : #ifdef RTE_QAT_OPENSSL
434 [ # # ]: 0 : if (ctx->bpi_ctx) {
435 : : #else
436 : : if (ctx->mb_mgr) {
437 : : #endif
438 : : cipher_len = qat_bpicipher_preprocess(ctx, op);
439 : 0 : cipher_ofs = op->sym->cipher.data.offset;
440 : : is_bpi = 1;
441 : : } else {
442 : 0 : cipher_len = op->sym->cipher.data.length;
443 : 0 : cipher_ofs = op->sym->cipher.data.offset;
444 : : }
445 : : break;
446 : : default:
447 : 0 : QAT_DP_LOG(ERR,
448 : : "For SNOW3G/KASUMI/ZUC, QAT PMD only supports byte aligned values");
449 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
450 : 0 : return -EINVAL;
451 : : }
452 : :
453 : : ret = qat_auth_is_len_in_bits(ctx, op);
454 : : switch (ret) {
455 : : case 1:
456 : 0 : auth_len = op->sym->auth.data.length >> 3;
457 : 0 : auth_ofs = op->sym->auth.data.offset >> 3;
458 : 0 : break;
459 : : case 0:
460 : 0 : auth_len = op->sym->auth.data.length;
461 : 0 : auth_ofs = op->sym->auth.data.offset;
462 : 0 : break;
463 : : default:
464 : 0 : QAT_DP_LOG(ERR,
465 : : "For SNOW3G/KASUMI/ZUC, QAT PMD only supports byte aligned values");
466 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
467 : 0 : return -EINVAL;
468 : : }
469 : :
470 : 0 : max_len = RTE_MAX(cipher_ofs + cipher_len, auth_ofs + auth_len);
471 : :
472 : : /* digest in buffer check. Needed only for wireless algos
473 : : * or combined cipher-crc operations
474 : : */
475 [ # # ]: 0 : if (ret == 1 || is_bpi) {
476 : : /* Handle digest-encrypted cases, i.e.
477 : : * auth-gen-then-cipher-encrypt and
478 : : * cipher-decrypt-then-auth-verify
479 : : */
480 : : uint64_t auth_end_iova;
481 : :
482 [ # # ]: 0 : if (unlikely(is_sgl)) {
483 : : uint32_t remaining_off = auth_ofs + auth_len;
484 [ # # ]: 0 : struct rte_mbuf *sgl_buf = (is_oop ? op->sym->m_dst :
485 : : op->sym->m_src);
486 : :
487 : 0 : while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
488 [ # # # # ]: 0 : && sgl_buf->next != NULL) {
489 : 0 : remaining_off -= rte_pktmbuf_data_len(sgl_buf);
490 : : sgl_buf = sgl_buf->next;
491 : : }
492 : :
493 : 0 : auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
494 : : sgl_buf, remaining_off);
495 : : } else
496 : 0 : auth_end_iova = (is_oop ?
497 [ # # ]: 0 : rte_pktmbuf_iova(op->sym->m_dst) :
498 : 0 : rte_pktmbuf_iova(op->sym->m_src)) + auth_ofs +
499 : : auth_len;
500 : :
501 : : /* Then check if digest-encrypted conditions are met */
502 [ # # # # ]: 0 : if (((auth_ofs + auth_len < cipher_ofs + cipher_len) &&
503 : 0 : (digest->iova == auth_end_iova)) ||
504 : : #ifdef RTE_QAT_OPENSSL
505 [ # # ]: 0 : ctx->bpi_ctx)
506 : : #else
507 : : ctx->mb_mgr)
508 : : #endif
509 : 0 : max_len = RTE_MAX(max_len, auth_ofs + auth_len +
510 : : ctx->digest_length);
511 : : }
512 : :
513 : : /* Passing 0 as cipher & auth offsets are assigned into ofs later */
514 : 0 : n_src = rte_crypto_mbuf_to_vec(op->sym->m_src, 0, max_len,
515 : : in_sgl->vec, QAT_SYM_SGL_MAX_NUMBER);
516 [ # # # # ]: 0 : if (unlikely(n_src < 0 || n_src > op->sym->m_src->nb_segs)) {
517 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
518 : 0 : return -1;
519 : : }
520 : 0 : in_sgl->num = n_src;
521 : :
522 [ # # # # ]: 0 : if (unlikely((op->sym->m_dst != NULL) &&
523 : 0 : (op->sym->m_dst != op->sym->m_src))) {
524 : 0 : int n_dst = rte_crypto_mbuf_to_vec(op->sym->m_dst, 0,
525 : : max_len, out_sgl->vec, QAT_SYM_SGL_MAX_NUMBER);
526 : :
527 [ # # # # ]: 0 : if (n_dst < 0 || n_dst > op->sym->m_dst->nb_segs) {
528 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
529 : 0 : return -1;
530 : : }
531 : 0 : out_sgl->num = n_dst;
532 : : } else
533 : : out_sgl->num = 0;
534 : :
535 : 0 : ofs.ofs.cipher.head = cipher_ofs;
536 : 0 : ofs.ofs.cipher.tail = max_len - cipher_ofs - cipher_len;
537 : 0 : ofs.ofs.auth.head = auth_ofs;
538 : 0 : ofs.ofs.auth.tail = max_len - auth_ofs - auth_len;
539 : :
540 : 0 : return ofs.raw;
541 : : }
542 : :
543 : : static __rte_always_inline uint64_t
544 : : qat_sym_convert_op_to_vec_aead(struct rte_crypto_op *op,
545 : : struct qat_sym_session *ctx,
546 : : struct rte_crypto_sgl *in_sgl, struct rte_crypto_sgl *out_sgl,
547 : : struct rte_crypto_va_iova_ptr *cipher_iv,
548 : : struct rte_crypto_va_iova_ptr *auth_iv_or_aad,
549 : : struct rte_crypto_va_iova_ptr *digest)
550 : : {
551 : : uint32_t cipher_len = 0, cipher_ofs = 0;
552 : : int32_t n_src = 0;
553 : :
554 : 0 : cipher_iv->va = rte_crypto_op_ctod_offset(op, void *,
555 : : ctx->cipher_iv.offset);
556 : 0 : cipher_iv->iova = rte_crypto_op_ctophys_offset(op,
557 : : ctx->cipher_iv.offset);
558 : 0 : auth_iv_or_aad->va = (void *)op->sym->aead.aad.data;
559 : 0 : auth_iv_or_aad->iova = op->sym->aead.aad.phys_addr;
560 : : digest->va = (void *)op->sym->aead.digest.data;
561 : 0 : digest->iova = op->sym->aead.digest.phys_addr;
562 : :
563 : 0 : cipher_len = op->sym->aead.data.length;
564 : 0 : cipher_ofs = op->sym->aead.data.offset;
565 : :
566 : 0 : n_src = rte_crypto_mbuf_to_vec(op->sym->m_src, cipher_ofs, cipher_len,
567 : : in_sgl->vec, QAT_SYM_SGL_MAX_NUMBER);
568 [ # # # # ]: 0 : if (n_src < 0 || n_src > op->sym->m_src->nb_segs) {
569 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
570 : 0 : return UINT64_MAX;
571 : : }
572 : 0 : in_sgl->num = n_src;
573 : :
574 : : /* Out-Of-Place operation */
575 [ # # # # ]: 0 : if (unlikely((op->sym->m_dst != NULL) &&
576 : 0 : (op->sym->m_dst != op->sym->m_src))) {
577 : 0 : int n_dst = rte_crypto_mbuf_to_vec(op->sym->m_dst, cipher_ofs,
578 : : cipher_len, out_sgl->vec,
579 : : QAT_SYM_SGL_MAX_NUMBER);
580 [ # # # # ]: 0 : if (n_dst < 0 || n_dst > op->sym->m_dst->nb_segs) {
581 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
582 : 0 : return UINT64_MAX;
583 : : }
584 : :
585 : 0 : out_sgl->num = n_dst;
586 : : } else
587 : : out_sgl->num = 0;
588 : :
589 : : return 0;
590 : : }
591 : :
592 : : static __rte_always_inline void
593 : : qat_set_cipher_iv(struct icp_qat_fw_la_cipher_req_params *cipher_param,
594 : : struct rte_crypto_va_iova_ptr *iv_ptr, uint32_t iv_len,
595 : : struct icp_qat_fw_la_bulk_req *qat_req)
596 : : {
597 : : /* copy IV into request if it fits */
598 [ # # # # : 0 : if (iv_len <= sizeof(cipher_param->u.cipher_IV_array))
# # # # #
# # # ]
599 [ # # # # : 0 : rte_memcpy(cipher_param->u.cipher_IV_array, iv_ptr->va,
# # # # #
# # # ]
600 : : iv_len);
601 : : else {
602 : 0 : ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(
603 : : qat_req->comn_hdr.serv_specif_flags,
604 : : ICP_QAT_FW_CIPH_IV_64BIT_PTR);
605 : 0 : cipher_param->u.s.cipher_IV_ptr = iv_ptr->iova;
606 : : }
607 : : }
608 : :
609 : : static __rte_always_inline void
610 : : qat_sym_dp_fill_vec_status(int32_t *sta, int status, uint32_t n)
611 : : {
612 : : uint32_t i;
613 : :
614 [ # # # # : 0 : for (i = 0; i < n; i++)
# # # # #
# # # # #
# # ]
615 : 0 : sta[i] = status;
616 : : }
617 : :
618 : : static __rte_always_inline void
619 : : enqueue_one_cipher_job_gen1(struct qat_sym_session *ctx,
620 : : struct icp_qat_fw_la_bulk_req *req,
621 : : struct rte_crypto_va_iova_ptr *iv,
622 : : union rte_crypto_sym_ofs ofs, uint32_t data_len,
623 : : struct qat_sym_op_cookie *cookie)
624 : : {
625 : : struct icp_qat_fw_la_cipher_req_params *cipher_param;
626 : :
627 : : cipher_param = (void *)&req->serv_specif_rqpars;
628 : :
629 : : /* cipher IV */
630 [ # # # # : 0 : qat_set_cipher_iv(cipher_param, iv, ctx->cipher_iv.length, req);
# # ]
631 : 0 : cipher_param->cipher_offset = ofs.ofs.cipher.head;
632 : 0 : cipher_param->cipher_length = data_len - ofs.ofs.cipher.head -
633 : 0 : ofs.ofs.cipher.tail;
634 : :
635 [ # # # # : 0 : if (AES_OR_3DES_MISALIGNED) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
636 : 0 : QAT_LOG(DEBUG,
637 : : "Input cipher buffer misalignment detected and change job as NULL operation");
638 : : struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr;
639 : 0 : header->service_type = ICP_QAT_FW_COMN_REQ_NULL;
640 : 0 : header->service_cmd_id = ICP_QAT_FW_NULL_REQ_SERV_ID;
641 : 0 : cookie->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
642 : : }
643 : : }
644 : :
645 : : static __rte_always_inline void
646 : : enqueue_one_auth_job_gen1(struct qat_sym_session *ctx,
647 : : struct icp_qat_fw_la_bulk_req *req,
648 : : struct rte_crypto_va_iova_ptr *digest,
649 : : struct rte_crypto_va_iova_ptr *auth_iv,
650 : : union rte_crypto_sym_ofs ofs, uint32_t data_len)
651 : : {
652 : : struct icp_qat_fw_la_cipher_req_params *cipher_param;
653 : : struct icp_qat_fw_la_auth_req_params *auth_param;
654 : :
655 : : cipher_param = (void *)&req->serv_specif_rqpars;
656 : : auth_param = (void *)((uint8_t *)cipher_param +
657 : : ICP_QAT_FW_HASH_REQUEST_PARAMETERS_OFFSET);
658 : :
659 : 0 : auth_param->auth_off = ofs.ofs.auth.head;
660 : 0 : auth_param->auth_len = data_len - ofs.ofs.auth.head -
661 : 0 : ofs.ofs.auth.tail;
662 : 0 : auth_param->auth_res_addr = digest->iova;
663 : :
664 [ # # # # : 0 : switch (ctx->qat_hash_alg) {
# # # # #
# # # ]
665 : 0 : case ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2:
666 : : case ICP_QAT_HW_AUTH_ALGO_KASUMI_F9:
667 : : case ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3:
668 : 0 : auth_param->u1.aad_adr = auth_iv->iova;
669 : 0 : break;
670 : 0 : case ICP_QAT_HW_AUTH_ALGO_GALOIS_128:
671 : : case ICP_QAT_HW_AUTH_ALGO_GALOIS_64:
672 : 0 : ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
673 : : req->comn_hdr.serv_specif_flags,
674 : : ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
675 : 0 : rte_memcpy(cipher_param->u.cipher_IV_array, auth_iv->va,
676 [ # # # # : 0 : ctx->auth_iv.length);
# # ]
677 : : break;
678 : 0 : case ICP_QAT_HW_AUTH_ALGO_SM3:
679 [ # # # # : 0 : if (ctx->auth_mode == ICP_QAT_HW_AUTH_MODE0)
# # ]
680 : 0 : auth_param->u1.aad_adr = 0;
681 : : else
682 : 0 : auth_param->u1.aad_adr = ctx->prefix_paddr;
683 : : break;
684 : : default:
685 : : break;
686 : : }
687 : : }
688 : :
689 : : static __rte_always_inline int
690 : : enqueue_one_chain_job_gen1(struct qat_sym_session *ctx,
691 : : struct icp_qat_fw_la_bulk_req *req,
692 : : struct rte_crypto_vec *src_vec,
693 : : uint16_t n_src_vecs,
694 : : struct rte_crypto_vec *dst_vec,
695 : : uint16_t n_dst_vecs,
696 : : struct rte_crypto_va_iova_ptr *cipher_iv,
697 : : struct rte_crypto_va_iova_ptr *digest,
698 : : struct rte_crypto_va_iova_ptr *auth_iv,
699 : : union rte_crypto_sym_ofs ofs, uint32_t data_len,
700 : : struct qat_sym_op_cookie *cookie)
701 : : {
702 : : struct icp_qat_fw_la_cipher_req_params *cipher_param;
703 : : struct icp_qat_fw_la_auth_req_params *auth_param;
704 : : struct rte_crypto_vec *cvec = n_dst_vecs > 0 ?
705 [ # # ]: 0 : dst_vec : src_vec;
706 : : rte_iova_t auth_iova_end;
707 : : int cipher_len, auth_len;
708 : 0 : int is_sgl = n_src_vecs > 1 || n_dst_vecs > 1;
709 : :
710 : : cipher_param = (void *)&req->serv_specif_rqpars;
711 : : auth_param = (void *)((uint8_t *)cipher_param +
712 : : ICP_QAT_FW_HASH_REQUEST_PARAMETERS_OFFSET);
713 : :
714 : 0 : cipher_len = data_len - ofs.ofs.cipher.head -
715 : 0 : ofs.ofs.cipher.tail;
716 : 0 : auth_len = data_len - ofs.ofs.auth.head - ofs.ofs.auth.tail;
717 : :
718 [ # # # # : 0 : if (unlikely(cipher_len < 0 || auth_len < 0))
# # ]
719 : : return -1;
720 : :
721 : 0 : cipher_param->cipher_offset = ofs.ofs.cipher.head;
722 : 0 : cipher_param->cipher_length = cipher_len;
723 [ # # # # : 0 : qat_set_cipher_iv(cipher_param, cipher_iv, ctx->cipher_iv.length, req);
# # ]
724 : :
725 : 0 : auth_param->auth_off = ofs.ofs.auth.head;
726 : 0 : auth_param->auth_len = auth_len;
727 : 0 : auth_param->auth_res_addr = digest->iova;
728 : : /* Input cipher length alignment requirement for 3DES-CBC and AES-CBC.
729 : : * For 3DES-CBC cipher algo, ESP Payload size requires 8 Byte aligned.
730 : : * For AES-CBC cipher algo, ESP Payload size requires 16 Byte aligned.
731 : : * The alignment should be guaranteed by the ESP package padding field
732 : : * according to the RFC4303. Under this condition, QAT will pass through
733 : : * chain job as NULL cipher and NULL auth operation and report misalignment
734 : : * error detected.
735 : : */
736 [ # # # # : 0 : if (AES_OR_3DES_MISALIGNED) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
737 : 0 : QAT_LOG(DEBUG,
738 : : "Input cipher buffer misalignment detected and change job as NULL operation");
739 : : struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr;
740 : 0 : header->service_type = ICP_QAT_FW_COMN_REQ_NULL;
741 : 0 : header->service_cmd_id = ICP_QAT_FW_NULL_REQ_SERV_ID;
742 : 0 : cookie->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
743 : 0 : return -1;
744 : : }
745 : :
746 [ # # # # : 0 : switch (ctx->qat_hash_alg) {
# # # #
# ]
747 : 0 : case ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2:
748 : : case ICP_QAT_HW_AUTH_ALGO_KASUMI_F9:
749 : : case ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3:
750 : 0 : auth_param->u1.aad_adr = auth_iv->iova;
751 : 0 : break;
752 : : case ICP_QAT_HW_AUTH_ALGO_GALOIS_128:
753 : : case ICP_QAT_HW_AUTH_ALGO_GALOIS_64:
754 : : break;
755 : 0 : case ICP_QAT_HW_AUTH_ALGO_SM3:
756 [ # # # # : 0 : if (ctx->auth_mode == ICP_QAT_HW_AUTH_MODE0)
# # ]
757 : 0 : auth_param->u1.aad_adr = 0;
758 : : else
759 : 0 : auth_param->u1.aad_adr = ctx->prefix_paddr;
760 : : break;
761 : : default:
762 : : break;
763 : : }
764 : :
765 [ # # # # : 0 : if (unlikely(is_sgl)) {
# # ]
766 : : /* sgl */
767 [ # # ]: 0 : int i = n_dst_vecs ? n_dst_vecs : n_src_vecs;
768 : 0 : uint32_t remaining_off = data_len - ofs.ofs.auth.tail;
769 : :
770 [ # # # # : 0 : while (remaining_off >= cvec->len && i >= 1) {
# # # # #
# # # ]
771 : 0 : i--;
772 : 0 : remaining_off -= cvec->len;
773 [ # # # # : 0 : if (i)
# # ]
774 : 0 : cvec++;
775 : : }
776 : :
777 : 0 : auth_iova_end = cvec->iova + remaining_off;
778 : : } else
779 : 0 : auth_iova_end = cvec[0].iova + auth_param->auth_off +
780 : 0 : auth_param->auth_len;
781 : :
782 : : /* Then check if digest-encrypted conditions are met */
783 : 0 : if (((auth_param->auth_off + auth_param->auth_len <
784 [ # # # # : 0 : cipher_param->cipher_offset + cipher_param->cipher_length) &&
# # # # #
# # # ]
785 : 0 : (digest->iova == auth_iova_end)) ||
786 : : #ifdef RTE_QAT_OPENSSL
787 [ # # # # : 0 : ctx->bpi_ctx) {
# # ]
788 : : #else
789 : : ctx->mb_mgr) {
790 : : #endif
791 : : /* Handle partial digest encryption */
792 : 0 : if (cipher_param->cipher_offset + cipher_param->cipher_length <
793 : 0 : auth_param->auth_off + auth_param->auth_len +
794 [ # # # # : 0 : ctx->digest_length && !is_sgl)
# # # # #
# # # ]
795 : 0 : req->comn_mid.dst_length = req->comn_mid.src_length =
796 : : auth_param->auth_off + auth_param->auth_len +
797 : : ctx->digest_length;
798 : : struct icp_qat_fw_comn_req_hdr *header = &req->comn_hdr;
799 : 0 : ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(header->serv_specif_flags,
800 : : ICP_QAT_FW_LA_DIGEST_IN_BUFFER);
801 : : }
802 : :
803 : : return 0;
804 : : }
805 : :
806 : : static __rte_always_inline void
807 : : enqueue_one_aead_job_gen1(struct qat_sym_session *ctx,
808 : : struct icp_qat_fw_la_bulk_req *req,
809 : : struct rte_crypto_va_iova_ptr *iv,
810 : : struct rte_crypto_va_iova_ptr *digest,
811 : : struct rte_crypto_va_iova_ptr *aad,
812 : : union rte_crypto_sym_ofs ofs, uint32_t data_len)
813 : : {
814 : : struct icp_qat_fw_la_cipher_req_params *cipher_param =
815 : : (void *)&req->serv_specif_rqpars;
816 : : struct icp_qat_fw_la_auth_req_params *auth_param =
817 : : (void *)((uint8_t *)&req->serv_specif_rqpars +
818 : : ICP_QAT_FW_HASH_REQUEST_PARAMETERS_OFFSET);
819 : : uint8_t *aad_data;
820 : : uint8_t aad_ccm_real_len;
821 : : uint8_t aad_len_field_sz;
822 : : uint32_t msg_len_be;
823 : : rte_iova_t aad_iova = 0;
824 : : uint8_t q;
825 : :
826 [ # # # # : 0 : switch (ctx->qat_hash_alg) {
# # # #
# ]
827 : 0 : case ICP_QAT_HW_AUTH_ALGO_GALOIS_128:
828 : : case ICP_QAT_HW_AUTH_ALGO_GALOIS_64:
829 : 0 : ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
830 : : req->comn_hdr.serv_specif_flags,
831 : : ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
832 : 0 : rte_memcpy(cipher_param->u.cipher_IV_array, iv->va,
833 [ # # # # : 0 : ctx->cipher_iv.length);
# # ]
834 : 0 : aad_iova = aad->iova;
835 : 0 : break;
836 : 0 : case ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC:
837 : 0 : aad_data = aad->va;
838 : 0 : aad_iova = aad->iova;
839 : : aad_ccm_real_len = 0;
840 : : aad_len_field_sz = 0;
841 [ # # # # : 0 : msg_len_be = rte_bswap32((uint32_t)data_len -
# # ]
842 : : ofs.ofs.cipher.head);
843 : :
844 [ # # # # : 0 : if (ctx->aad_len > ICP_QAT_HW_CCM_AAD_DATA_OFFSET) {
# # ]
845 : : aad_len_field_sz = ICP_QAT_HW_CCM_AAD_LEN_INFO;
846 : 0 : aad_ccm_real_len = ctx->aad_len -
847 : : ICP_QAT_HW_CCM_AAD_B0_LEN -
848 : : ICP_QAT_HW_CCM_AAD_LEN_INFO;
849 : : } else {
850 : 0 : aad_data = iv->va;
851 : 0 : aad_iova = iv->iova;
852 : : }
853 : :
854 : 0 : q = ICP_QAT_HW_CCM_NQ_CONST - ctx->cipher_iv.length;
855 [ # # # # : 0 : aad_data[0] = ICP_QAT_HW_CCM_BUILD_B0_FLAGS(
# # ]
856 : : aad_len_field_sz, ctx->digest_length, q);
857 [ # # # # : 0 : if (q > ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE) {
# # ]
858 : 0 : memcpy(aad_data + ctx->cipher_iv.length +
859 : 0 : ICP_QAT_HW_CCM_NONCE_OFFSET + (q -
860 : : ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE),
861 : : (uint8_t *)&msg_len_be,
862 : : ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE);
863 : : } else {
864 : 0 : memcpy(aad_data + ctx->cipher_iv.length +
865 : : ICP_QAT_HW_CCM_NONCE_OFFSET,
866 : : (uint8_t *)&msg_len_be +
867 : : (ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE
868 : 0 : - q), q);
869 : : }
870 : :
871 [ # # # # : 0 : if (aad_len_field_sz > 0) {
# # ]
872 : 0 : *(uint16_t *)&aad_data[ICP_QAT_HW_CCM_AAD_B0_LEN] =
873 [ # # # # : 0 : rte_bswap16(aad_ccm_real_len);
# # ]
874 : :
875 : 0 : if ((aad_ccm_real_len + aad_len_field_sz)
876 [ # # # # : 0 : % ICP_QAT_HW_CCM_AAD_B0_LEN) {
# # ]
877 : : uint8_t pad_len = 0;
878 : : uint8_t pad_idx = 0;
879 : :
880 : 0 : pad_len = ICP_QAT_HW_CCM_AAD_B0_LEN -
881 : : ((aad_ccm_real_len +
882 : : aad_len_field_sz) %
883 : : ICP_QAT_HW_CCM_AAD_B0_LEN);
884 : 0 : pad_idx = ICP_QAT_HW_CCM_AAD_B0_LEN +
885 : : aad_ccm_real_len +
886 : : aad_len_field_sz;
887 : 0 : memset(&aad_data[pad_idx], 0, pad_len);
888 : : }
889 : : }
890 : :
891 : 0 : rte_memcpy(((uint8_t *)cipher_param->u.cipher_IV_array)
892 : : + ICP_QAT_HW_CCM_NONCE_OFFSET,
893 : 0 : (uint8_t *)iv->va +
894 [ # # # # : 0 : ICP_QAT_HW_CCM_NONCE_OFFSET, ctx->cipher_iv.length);
# # ]
895 : 0 : *(uint8_t *)&cipher_param->u.cipher_IV_array[0] =
896 : : q - ICP_QAT_HW_CCM_NONCE_OFFSET;
897 : :
898 : 0 : rte_memcpy((uint8_t *)aad->va +
899 : : ICP_QAT_HW_CCM_NONCE_OFFSET,
900 : 0 : (uint8_t *)iv->va + ICP_QAT_HW_CCM_NONCE_OFFSET,
901 [ # # # # : 0 : ctx->cipher_iv.length);
# # ]
902 : : break;
903 : : default:
904 : : break;
905 : : }
906 : :
907 : 0 : cipher_param->cipher_offset = ofs.ofs.cipher.head;
908 : 0 : cipher_param->cipher_length = data_len - ofs.ofs.cipher.head -
909 : 0 : ofs.ofs.cipher.tail;
910 : 0 : auth_param->auth_off = ofs.ofs.cipher.head;
911 : 0 : auth_param->auth_len = cipher_param->cipher_length;
912 : 0 : auth_param->auth_res_addr = digest->iova;
913 : 0 : auth_param->u1.aad_adr = aad_iova;
914 : : }
915 : :
916 : : extern struct rte_cryptodev_ops qat_sym_crypto_ops_gen1;
917 : : extern struct rte_cryptodev_ops qat_asym_crypto_ops_gen1;
918 : :
919 : : /* -----------------GEN 1 sym crypto op data path APIs ---------------- */
920 : : int
921 : : qat_sym_build_op_cipher_gen1(void *in_op, struct qat_sym_session *ctx,
922 : : uint8_t *out_msg, void *op_cookie);
923 : :
924 : : int
925 : : qat_sym_build_op_auth_gen1(void *in_op, struct qat_sym_session *ctx,
926 : : uint8_t *out_msg, void *op_cookie);
927 : :
928 : : int
929 : : qat_sym_build_op_aead_gen1(void *in_op, struct qat_sym_session *ctx,
930 : : uint8_t *out_msg, void *op_cookie);
931 : :
932 : : int
933 : : qat_sym_build_op_chain_gen1(void *in_op, struct qat_sym_session *ctx,
934 : : uint8_t *out_msg, void *op_cookie);
935 : :
936 : : /* -----------------GEN 1 sym crypto raw data path APIs ---------------- */
937 : : int
938 : : qat_sym_dp_enqueue_single_cipher_gen1(void *qp_data, uint8_t *drv_ctx,
939 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
940 : : union rte_crypto_sym_ofs ofs,
941 : : struct rte_crypto_va_iova_ptr *iv,
942 : : struct rte_crypto_va_iova_ptr *digest __rte_unused,
943 : : struct rte_crypto_va_iova_ptr *aad __rte_unused,
944 : : void *user_data);
945 : :
946 : : uint32_t
947 : : qat_sym_dp_enqueue_cipher_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
948 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
949 : : void *user_data[], int *status);
950 : :
951 : : int
952 : : qat_sym_dp_enqueue_single_auth_gen1(void *qp_data, uint8_t *drv_ctx,
953 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
954 : : union rte_crypto_sym_ofs ofs,
955 : : struct rte_crypto_va_iova_ptr *iv __rte_unused,
956 : : struct rte_crypto_va_iova_ptr *digest,
957 : : struct rte_crypto_va_iova_ptr *auth_iv,
958 : : void *user_data);
959 : :
960 : : uint32_t
961 : : qat_sym_dp_enqueue_auth_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
962 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
963 : : void *user_data[], int *status);
964 : :
965 : : int
966 : : qat_sym_dp_enqueue_single_chain_gen1(void *qp_data, uint8_t *drv_ctx,
967 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
968 : : union rte_crypto_sym_ofs ofs,
969 : : struct rte_crypto_va_iova_ptr *cipher_iv,
970 : : struct rte_crypto_va_iova_ptr *digest,
971 : : struct rte_crypto_va_iova_ptr *auth_iv,
972 : : void *user_data);
973 : :
974 : : uint32_t
975 : : qat_sym_dp_enqueue_chain_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
976 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
977 : : void *user_data[], int *status);
978 : :
979 : : int
980 : : qat_sym_dp_enqueue_single_aead_gen1(void *qp_data, uint8_t *drv_ctx,
981 : : struct rte_crypto_vec *data, uint16_t n_data_vecs,
982 : : union rte_crypto_sym_ofs ofs,
983 : : struct rte_crypto_va_iova_ptr *iv,
984 : : struct rte_crypto_va_iova_ptr *digest,
985 : : struct rte_crypto_va_iova_ptr *aad,
986 : : void *user_data);
987 : :
988 : : uint32_t
989 : : qat_sym_dp_enqueue_aead_jobs_gen1(void *qp_data, uint8_t *drv_ctx,
990 : : struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
991 : : void *user_data[], int *status);
992 : :
993 : : void *
994 : : qat_sym_dp_dequeue_single_gen1(void *qp_data, uint8_t *drv_ctx,
995 : : int *dequeue_status, enum rte_crypto_op_status *op_status);
996 : :
997 : : uint32_t
998 : : qat_sym_dp_dequeue_burst_gen1(void *qp_data, uint8_t *drv_ctx,
999 : : rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1000 : : uint32_t max_nb_to_dequeue,
1001 : : rte_cryptodev_raw_post_dequeue_t post_dequeue,
1002 : : void **out_user_data, uint8_t is_user_data_array,
1003 : : uint32_t *n_success_jobs, int *return_status);
1004 : :
1005 : : int
1006 : : qat_sym_dp_enqueue_done_gen1(void *qp_data, uint8_t *drv_ctx, uint32_t n);
1007 : :
1008 : : int
1009 : : qat_sym_dp_dequeue_done_gen1(void *qp_data, uint8_t *drv_ctx, uint32_t n);
1010 : :
1011 : : int
1012 : : qat_sym_configure_raw_dp_ctx_gen1(void *_raw_dp_ctx, void *_ctx);
1013 : :
1014 : : /* -----------------GENx control path APIs ---------------- */
1015 : : uint64_t
1016 : : qat_sym_crypto_feature_flags_get_gen1(struct qat_pci_device *qat_dev);
1017 : :
1018 : : int
1019 : : qat_sym_crypto_set_session_gen1(void *cryptodev, void *session);
1020 : :
1021 : : void
1022 : : qat_sym_session_set_ext_hash_flags_gen2(struct qat_sym_session *session,
1023 : : uint8_t hash_flag);
1024 : :
1025 : : int
1026 : : qat_asym_crypto_cap_get_gen1(struct qat_cryptodev_private *internals,
1027 : : const char *capa_memz_name, const uint16_t slice_map);
1028 : :
1029 : : uint64_t
1030 : : qat_asym_crypto_feature_flags_get_gen1(struct qat_pci_device *qat_dev);
1031 : :
1032 : : int
1033 : : qat_asym_crypto_set_session_gen1(void *cryptodev, void *session);
1034 : :
1035 : : extern struct rte_security_ops security_qat_ops_gen1;
1036 : :
1037 : : void *
1038 : : qat_sym_create_security_gen1(void *cryptodev);
1039 : :
1040 : : #endif
|