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