46ef27a6d228fc9335b6defbf15b5d61d37eecc6
[dpdk.git] / drivers / crypto / qat / qat_sym.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2018 Intel Corporation
3  */
4
5 #include <openssl/evp.h>
6
7 #include <rte_mempool.h>
8 #include <rte_mbuf.h>
9 #include <rte_crypto_sym.h>
10 #include <rte_bus_pci.h>
11 #include <rte_byteorder.h>
12
13 #include "qat_sym.h"
14
15 /** Decrypt a single partial block
16  *  Depends on openssl libcrypto
17  *  Uses ECB+XOR to do CFB encryption, same result, more performant
18  */
19 static inline int
20 bpi_cipher_decrypt(uint8_t *src, uint8_t *dst,
21                 uint8_t *iv, int ivlen, int srclen,
22                 void *bpi_ctx)
23 {
24         EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX *)bpi_ctx;
25         int encrypted_ivlen;
26         uint8_t encrypted_iv[BPI_MAX_ENCR_IV_LEN];
27         uint8_t *encr = encrypted_iv;
28
29         /* ECB method: encrypt (not decrypt!) the IV, then XOR with plaintext */
30         if (EVP_EncryptUpdate(ctx, encrypted_iv, &encrypted_ivlen, iv, ivlen)
31                                                                 <= 0)
32                 goto cipher_decrypt_err;
33
34         for (; srclen != 0; --srclen, ++dst, ++src, ++encr)
35                 *dst = *src ^ *encr;
36
37         return 0;
38
39 cipher_decrypt_err:
40         QAT_DP_LOG(ERR, "libcrypto ECB cipher decrypt for BPI IV failed");
41         return -EINVAL;
42 }
43
44
45 static inline uint32_t
46 qat_bpicipher_preprocess(struct qat_sym_session *ctx,
47                                 struct rte_crypto_op *op)
48 {
49         int block_len = qat_cipher_get_block_size(ctx->qat_cipher_alg);
50         struct rte_crypto_sym_op *sym_op = op->sym;
51         uint8_t last_block_len = block_len > 0 ?
52                         sym_op->cipher.data.length % block_len : 0;
53
54         if (last_block_len &&
55                         ctx->qat_dir == ICP_QAT_HW_CIPHER_DECRYPT) {
56
57                 /* Decrypt last block */
58                 uint8_t *last_block, *dst, *iv;
59                 uint32_t last_block_offset = sym_op->cipher.data.offset +
60                                 sym_op->cipher.data.length - last_block_len;
61                 last_block = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_src,
62                                 uint8_t *, last_block_offset);
63
64                 if (unlikely(sym_op->m_dst != NULL))
65                         /* out-of-place operation (OOP) */
66                         dst = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_dst,
67                                                 uint8_t *, last_block_offset);
68                 else
69                         dst = last_block;
70
71                 if (last_block_len < sym_op->cipher.data.length)
72                         /* use previous block ciphertext as IV */
73                         iv = last_block - block_len;
74                 else
75                         /* runt block, i.e. less than one full block */
76                         iv = rte_crypto_op_ctod_offset(op, uint8_t *,
77                                         ctx->cipher_iv.offset);
78
79 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
80                 QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: src before pre-process:",
81                         last_block, last_block_len);
82                 if (sym_op->m_dst != NULL)
83                         QAT_DP_HEXDUMP_LOG(DEBUG, "BPI:dst before pre-process:",
84                         dst, last_block_len);
85 #endif
86                 bpi_cipher_decrypt(last_block, dst, iv, block_len,
87                                 last_block_len, ctx->bpi_ctx);
88 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
89                 QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: src after pre-process:",
90                         last_block, last_block_len);
91                 if (sym_op->m_dst != NULL)
92                         QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: dst after pre-process:",
93                         dst, last_block_len);
94 #endif
95         }
96
97         return sym_op->cipher.data.length - last_block_len;
98 }
99
100 static inline void
101 set_cipher_iv(uint16_t iv_length, uint16_t iv_offset,
102                 struct icp_qat_fw_la_cipher_req_params *cipher_param,
103                 struct rte_crypto_op *op,
104                 struct icp_qat_fw_la_bulk_req *qat_req)
105 {
106         /* copy IV into request if it fits */
107         if (iv_length <= sizeof(cipher_param->u.cipher_IV_array)) {
108                 rte_memcpy(cipher_param->u.cipher_IV_array,
109                                 rte_crypto_op_ctod_offset(op, uint8_t *,
110                                         iv_offset),
111                                 iv_length);
112         } else {
113                 ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(
114                                 qat_req->comn_hdr.serv_specif_flags,
115                                 ICP_QAT_FW_CIPH_IV_64BIT_PTR);
116                 cipher_param->u.s.cipher_IV_ptr =
117                                 rte_crypto_op_ctophys_offset(op,
118                                         iv_offset);
119         }
120 }
121
122 /** Set IV for CCM is special case, 0th byte is set to q-1
123  *  where q is padding of nonce in 16 byte block
124  */
125 static inline void
126 set_cipher_iv_ccm(uint16_t iv_length, uint16_t iv_offset,
127                 struct icp_qat_fw_la_cipher_req_params *cipher_param,
128                 struct rte_crypto_op *op, uint8_t q, uint8_t aad_len_field_sz)
129 {
130         rte_memcpy(((uint8_t *)cipher_param->u.cipher_IV_array) +
131                         ICP_QAT_HW_CCM_NONCE_OFFSET,
132                         rte_crypto_op_ctod_offset(op, uint8_t *,
133                                 iv_offset) + ICP_QAT_HW_CCM_NONCE_OFFSET,
134                         iv_length);
135         *(uint8_t *)&cipher_param->u.cipher_IV_array[0] =
136                         q - ICP_QAT_HW_CCM_NONCE_OFFSET;
137
138         if (aad_len_field_sz)
139                 rte_memcpy(&op->sym->aead.aad.data[ICP_QAT_HW_CCM_NONCE_OFFSET],
140                         rte_crypto_op_ctod_offset(op, uint8_t *,
141                                 iv_offset) + ICP_QAT_HW_CCM_NONCE_OFFSET,
142                         iv_length);
143 }
144
145 int
146 qat_sym_build_request(void *in_op, uint8_t *out_msg,
147                 void *op_cookie, enum qat_device_gen qat_dev_gen)
148 {
149         int ret = 0;
150         struct qat_sym_session *ctx;
151         struct icp_qat_fw_la_cipher_req_params *cipher_param;
152         struct icp_qat_fw_la_auth_req_params *auth_param;
153         register struct icp_qat_fw_la_bulk_req *qat_req;
154         uint8_t do_auth = 0, do_cipher = 0, do_aead = 0;
155         uint32_t cipher_len = 0, cipher_ofs = 0;
156         uint32_t auth_len = 0, auth_ofs = 0;
157         uint32_t min_ofs = 0;
158         uint64_t src_buf_start = 0, dst_buf_start = 0;
159         uint64_t auth_data_end = 0;
160         uint8_t do_sgl = 0;
161         uint8_t in_place = 1;
162         int alignment_adjustment = 0;
163         struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
164         struct qat_sym_op_cookie *cookie =
165                                 (struct qat_sym_op_cookie *)op_cookie;
166
167         if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
168                 QAT_DP_LOG(ERR, "QAT PMD only supports symmetric crypto "
169                                 "operation requests, op (%p) is not a "
170                                 "symmetric operation.", op);
171                 return -EINVAL;
172         }
173
174         if (unlikely(op->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
175                 QAT_DP_LOG(ERR, "QAT PMD only supports session oriented"
176                                 " requests, op (%p) is sessionless.", op);
177                 return -EINVAL;
178         }
179
180         ctx = (struct qat_sym_session *)get_sym_session_private_data(
181                         op->sym->session, cryptodev_qat_driver_id);
182
183         if (unlikely(ctx == NULL)) {
184                 QAT_DP_LOG(ERR, "Session was not created for this device");
185                 return -EINVAL;
186         }
187
188         if (unlikely(ctx->min_qat_dev_gen > qat_dev_gen)) {
189                 QAT_DP_LOG(ERR, "Session alg not supported on this device gen");
190                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
191                 return -EINVAL;
192         }
193
194         qat_req = (struct icp_qat_fw_la_bulk_req *)out_msg;
195         rte_mov128((uint8_t *)qat_req, (const uint8_t *)&(ctx->fw_req));
196         qat_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
197         cipher_param = (void *)&qat_req->serv_specif_rqpars;
198         auth_param = (void *)((uint8_t *)cipher_param + sizeof(*cipher_param));
199
200         if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_HASH_CIPHER ||
201                         ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER_HASH) {
202                 /* AES-GCM or AES-CCM */
203                 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
204                         ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64 ||
205                         (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES128
206                         && ctx->qat_mode == ICP_QAT_HW_CIPHER_CTR_MODE
207                         && ctx->qat_hash_alg ==
208                                         ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC)) {
209                         do_aead = 1;
210                 } else {
211                         do_auth = 1;
212                         do_cipher = 1;
213                 }
214         } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_AUTH) {
215                 do_auth = 1;
216                 do_cipher = 0;
217         } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER) {
218                 do_auth = 0;
219                 do_cipher = 1;
220         }
221
222         if (do_cipher) {
223
224                 if (ctx->qat_cipher_alg ==
225                                          ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 ||
226                         ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_KASUMI ||
227                         ctx->qat_cipher_alg ==
228                                 ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3) {
229
230                         if (unlikely(
231                             (op->sym->cipher.data.length % BYTE_LENGTH != 0) ||
232                             (op->sym->cipher.data.offset % BYTE_LENGTH != 0))) {
233                                 QAT_DP_LOG(ERR,
234                   "SNOW3G/KASUMI/ZUC in QAT PMD only supports byte aligned values");
235                                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
236                                 return -EINVAL;
237                         }
238                         cipher_len = op->sym->cipher.data.length >> 3;
239                         cipher_ofs = op->sym->cipher.data.offset >> 3;
240
241                 } else if (ctx->bpi_ctx) {
242                         /* DOCSIS - only send complete blocks to device
243                          * Process any partial block using CFB mode.
244                          * Even if 0 complete blocks, still send this to device
245                          * to get into rx queue for post-process and dequeuing
246                          */
247                         cipher_len = qat_bpicipher_preprocess(ctx, op);
248                         cipher_ofs = op->sym->cipher.data.offset;
249                 } else {
250                         cipher_len = op->sym->cipher.data.length;
251                         cipher_ofs = op->sym->cipher.data.offset;
252                 }
253
254                 set_cipher_iv(ctx->cipher_iv.length, ctx->cipher_iv.offset,
255                                 cipher_param, op, qat_req);
256                 min_ofs = cipher_ofs;
257         }
258
259         if (do_auth) {
260
261                 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 ||
262                         ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_KASUMI_F9 ||
263                         ctx->qat_hash_alg ==
264                                 ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3) {
265                         if (unlikely(
266                             (op->sym->auth.data.offset % BYTE_LENGTH != 0) ||
267                             (op->sym->auth.data.length % BYTE_LENGTH != 0))) {
268                                 QAT_DP_LOG(ERR,
269                 "For SNOW3G/KASUMI/ZUC, QAT PMD only supports byte aligned values");
270                                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
271                                 return -EINVAL;
272                         }
273                         auth_ofs = op->sym->auth.data.offset >> 3;
274                         auth_len = op->sym->auth.data.length >> 3;
275
276                         auth_param->u1.aad_adr =
277                                         rte_crypto_op_ctophys_offset(op,
278                                                         ctx->auth_iv.offset);
279
280                 } else if (ctx->qat_hash_alg ==
281                                         ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
282                                 ctx->qat_hash_alg ==
283                                         ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
284                         /* AES-GMAC */
285                         set_cipher_iv(ctx->auth_iv.length,
286                                 ctx->auth_iv.offset,
287                                 cipher_param, op, qat_req);
288                         auth_ofs = op->sym->auth.data.offset;
289                         auth_len = op->sym->auth.data.length;
290
291                         auth_param->u1.aad_adr = 0;
292                         auth_param->u2.aad_sz = 0;
293
294                         /*
295                          * If len(iv)==12B fw computes J0
296                          */
297                         if (ctx->auth_iv.length == 12) {
298                                 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
299                                         qat_req->comn_hdr.serv_specif_flags,
300                                         ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
301
302                         }
303                 } else {
304                         auth_ofs = op->sym->auth.data.offset;
305                         auth_len = op->sym->auth.data.length;
306
307                 }
308                 min_ofs = auth_ofs;
309
310                 if (likely(ctx->qat_hash_alg != ICP_QAT_HW_AUTH_ALGO_NULL))
311                         auth_param->auth_res_addr =
312                                         op->sym->auth.digest.phys_addr;
313
314         }
315
316         if (do_aead) {
317                 /*
318                  * This address may used for setting AAD physical pointer
319                  * into IV offset from op
320                  */
321                 rte_iova_t aad_phys_addr_aead = op->sym->aead.aad.phys_addr;
322                 if (ctx->qat_hash_alg ==
323                                 ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
324                                 ctx->qat_hash_alg ==
325                                         ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
326                         /*
327                          * If len(iv)==12B fw computes J0
328                          */
329                         if (ctx->cipher_iv.length == 12) {
330                                 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
331                                         qat_req->comn_hdr.serv_specif_flags,
332                                         ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
333                         }
334                         set_cipher_iv(ctx->cipher_iv.length,
335                                         ctx->cipher_iv.offset,
336                                         cipher_param, op, qat_req);
337
338                 } else if (ctx->qat_hash_alg ==
339                                 ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC) {
340
341                         /* In case of AES-CCM this may point to user selected
342                          * memory or iv offset in cypto_op
343                          */
344                         uint8_t *aad_data = op->sym->aead.aad.data;
345                         /* This is true AAD length, it not includes 18 bytes of
346                          * preceding data
347                          */
348                         uint8_t aad_ccm_real_len = 0;
349                         uint8_t aad_len_field_sz = 0;
350                         uint32_t msg_len_be =
351                                         rte_bswap32(op->sym->aead.data.length);
352
353                         if (ctx->aad_len > ICP_QAT_HW_CCM_AAD_DATA_OFFSET) {
354                                 aad_len_field_sz = ICP_QAT_HW_CCM_AAD_LEN_INFO;
355                                 aad_ccm_real_len = ctx->aad_len -
356                                         ICP_QAT_HW_CCM_AAD_B0_LEN -
357                                         ICP_QAT_HW_CCM_AAD_LEN_INFO;
358                         } else {
359                                 /*
360                                  * aad_len not greater than 18, so no actual aad
361                                  *  data, then use IV after op for B0 block
362                                  */
363                                 aad_data = rte_crypto_op_ctod_offset(op,
364                                                 uint8_t *,
365                                                 ctx->cipher_iv.offset);
366                                 aad_phys_addr_aead =
367                                                 rte_crypto_op_ctophys_offset(op,
368                                                         ctx->cipher_iv.offset);
369                         }
370
371                         uint8_t q = ICP_QAT_HW_CCM_NQ_CONST -
372                                                         ctx->cipher_iv.length;
373
374                         aad_data[0] = ICP_QAT_HW_CCM_BUILD_B0_FLAGS(
375                                                         aad_len_field_sz,
376                                                         ctx->digest_length, q);
377
378                         if (q > ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE) {
379                                 memcpy(aad_data + ctx->cipher_iv.length +
380                                     ICP_QAT_HW_CCM_NONCE_OFFSET +
381                                     (q - ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE),
382                                     (uint8_t *)&msg_len_be,
383                                     ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE);
384                         } else {
385                                 memcpy(aad_data + ctx->cipher_iv.length +
386                                     ICP_QAT_HW_CCM_NONCE_OFFSET,
387                                     (uint8_t *)&msg_len_be
388                                     + (ICP_QAT_HW_CCM_MSG_LEN_MAX_FIELD_SIZE
389                                     - q), q);
390                         }
391
392                         if (aad_len_field_sz > 0) {
393                                 *(uint16_t *)&aad_data[ICP_QAT_HW_CCM_AAD_B0_LEN]
394                                                 = rte_bswap16(aad_ccm_real_len);
395
396                                 if ((aad_ccm_real_len + aad_len_field_sz)
397                                                 % ICP_QAT_HW_CCM_AAD_B0_LEN) {
398                                         uint8_t pad_len = 0;
399                                         uint8_t pad_idx = 0;
400
401                                         pad_len = ICP_QAT_HW_CCM_AAD_B0_LEN -
402                                         ((aad_ccm_real_len + aad_len_field_sz) %
403                                                 ICP_QAT_HW_CCM_AAD_B0_LEN);
404                                         pad_idx = ICP_QAT_HW_CCM_AAD_B0_LEN +
405                                             aad_ccm_real_len + aad_len_field_sz;
406                                         memset(&aad_data[pad_idx],
407                                                         0, pad_len);
408                                 }
409
410                         }
411
412                         set_cipher_iv_ccm(ctx->cipher_iv.length,
413                                         ctx->cipher_iv.offset,
414                                         cipher_param, op, q,
415                                         aad_len_field_sz);
416
417                 }
418
419                 cipher_len = op->sym->aead.data.length;
420                 cipher_ofs = op->sym->aead.data.offset;
421                 auth_len = op->sym->aead.data.length;
422                 auth_ofs = op->sym->aead.data.offset;
423
424                 auth_param->u1.aad_adr = aad_phys_addr_aead;
425                 auth_param->auth_res_addr = op->sym->aead.digest.phys_addr;
426                 min_ofs = op->sym->aead.data.offset;
427         }
428
429         if (op->sym->m_src->next || (op->sym->m_dst && op->sym->m_dst->next))
430                 do_sgl = 1;
431
432         /* adjust for chain case */
433         if (do_cipher && do_auth)
434                 min_ofs = cipher_ofs < auth_ofs ? cipher_ofs : auth_ofs;
435
436         if (unlikely(min_ofs >= rte_pktmbuf_data_len(op->sym->m_src) && do_sgl))
437                 min_ofs = 0;
438
439         if (unlikely(op->sym->m_dst != NULL)) {
440                 /* Out-of-place operation (OOP)
441                  * Don't align DMA start. DMA the minimum data-set
442                  * so as not to overwrite data in dest buffer
443                  */
444                 in_place = 0;
445                 src_buf_start =
446                         rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs);
447                 dst_buf_start =
448                         rte_pktmbuf_iova_offset(op->sym->m_dst, min_ofs);
449
450         } else {
451                 /* In-place operation
452                  * Start DMA at nearest aligned address below min_ofs
453                  */
454                 src_buf_start =
455                         rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs)
456                                                 & QAT_64_BTYE_ALIGN_MASK;
457
458                 if (unlikely((rte_pktmbuf_iova(op->sym->m_src) -
459                                         rte_pktmbuf_headroom(op->sym->m_src))
460                                                         > src_buf_start)) {
461                         /* alignment has pushed addr ahead of start of mbuf
462                          * so revert and take the performance hit
463                          */
464                         src_buf_start =
465                                 rte_pktmbuf_iova_offset(op->sym->m_src,
466                                                                 min_ofs);
467                 }
468                 dst_buf_start = src_buf_start;
469
470                 /* remember any adjustment for later, note, can be +/- */
471                 alignment_adjustment = src_buf_start -
472                         rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs);
473         }
474
475         if (do_cipher || do_aead) {
476                 cipher_param->cipher_offset =
477                                 (uint32_t)rte_pktmbuf_iova_offset(
478                                 op->sym->m_src, cipher_ofs) - src_buf_start;
479                 cipher_param->cipher_length = cipher_len;
480         } else {
481                 cipher_param->cipher_offset = 0;
482                 cipher_param->cipher_length = 0;
483         }
484
485         if (do_auth || do_aead) {
486                 auth_param->auth_off = (uint32_t)rte_pktmbuf_iova_offset(
487                                 op->sym->m_src, auth_ofs) - src_buf_start;
488                 auth_param->auth_len = auth_len;
489         } else {
490                 auth_param->auth_off = 0;
491                 auth_param->auth_len = 0;
492         }
493
494         qat_req->comn_mid.dst_length =
495                 qat_req->comn_mid.src_length =
496                 (cipher_param->cipher_offset + cipher_param->cipher_length)
497                 > (auth_param->auth_off + auth_param->auth_len) ?
498                 (cipher_param->cipher_offset + cipher_param->cipher_length)
499                 : (auth_param->auth_off + auth_param->auth_len);
500
501         if (do_auth && do_cipher) {
502                 /* Handle digest-encrypted cases, i.e.
503                  * auth-gen-then-cipher-encrypt and
504                  * cipher-decrypt-then-auth-verify
505                  */
506                  /* First find the end of the data */
507                 if (do_sgl) {
508                         uint32_t remaining_off = auth_param->auth_off +
509                                 auth_param->auth_len + alignment_adjustment;
510                         struct rte_mbuf *sgl_buf =
511                                 (in_place ?
512                                         op->sym->m_src : op->sym->m_dst);
513
514                         while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
515                                         && sgl_buf->next != NULL) {
516                                 remaining_off -= rte_pktmbuf_data_len(sgl_buf);
517                                 sgl_buf = sgl_buf->next;
518                         }
519
520                         auth_data_end = (uint64_t)rte_pktmbuf_iova_offset(
521                                 sgl_buf, remaining_off);
522                 } else {
523                         auth_data_end = (in_place ?
524                                 src_buf_start : dst_buf_start) +
525                                 auth_param->auth_off + auth_param->auth_len;
526                 }
527                 /* Then check if digest-encrypted conditions are met */
528                 if ((auth_param->auth_off + auth_param->auth_len <
529                                         cipher_param->cipher_offset +
530                                         cipher_param->cipher_length) &&
531                                 (op->sym->auth.digest.phys_addr ==
532                                         auth_data_end)) {
533                         /* Handle partial digest encryption */
534                         if (cipher_param->cipher_offset +
535                                         cipher_param->cipher_length <
536                                         auth_param->auth_off +
537                                         auth_param->auth_len +
538                                         ctx->digest_length)
539                                 qat_req->comn_mid.dst_length =
540                                         qat_req->comn_mid.src_length =
541                                         auth_param->auth_off +
542                                         auth_param->auth_len +
543                                         ctx->digest_length;
544                         struct icp_qat_fw_comn_req_hdr *header =
545                                 &qat_req->comn_hdr;
546                         ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(
547                                 header->serv_specif_flags,
548                                 ICP_QAT_FW_LA_DIGEST_IN_BUFFER);
549                 }
550         }
551
552         if (do_sgl) {
553
554                 ICP_QAT_FW_COMN_PTR_TYPE_SET(qat_req->comn_hdr.comn_req_flags,
555                                 QAT_COMN_PTR_TYPE_SGL);
556                 ret = qat_sgl_fill_array(op->sym->m_src,
557                    (int64_t)(src_buf_start - rte_pktmbuf_iova(op->sym->m_src)),
558                    &cookie->qat_sgl_src,
559                    qat_req->comn_mid.src_length,
560                    QAT_SYM_SGL_MAX_NUMBER);
561
562                 if (unlikely(ret)) {
563                         QAT_DP_LOG(ERR, "QAT PMD Cannot fill sgl array");
564                         return ret;
565                 }
566
567                 if (likely(op->sym->m_dst == NULL))
568                         qat_req->comn_mid.dest_data_addr =
569                                 qat_req->comn_mid.src_data_addr =
570                                 cookie->qat_sgl_src_phys_addr;
571                 else {
572                         ret = qat_sgl_fill_array(op->sym->m_dst,
573                                 (int64_t)(dst_buf_start -
574                                           rte_pktmbuf_iova(op->sym->m_dst)),
575                                  &cookie->qat_sgl_dst,
576                                  qat_req->comn_mid.dst_length,
577                                  QAT_SYM_SGL_MAX_NUMBER);
578
579                         if (unlikely(ret)) {
580                                 QAT_DP_LOG(ERR, "QAT PMD can't fill sgl array");
581                                 return ret;
582                         }
583
584                         qat_req->comn_mid.src_data_addr =
585                                 cookie->qat_sgl_src_phys_addr;
586                         qat_req->comn_mid.dest_data_addr =
587                                         cookie->qat_sgl_dst_phys_addr;
588                 }
589                 qat_req->comn_mid.src_length = 0;
590                 qat_req->comn_mid.dst_length = 0;
591         } else {
592                 qat_req->comn_mid.src_data_addr = src_buf_start;
593                 qat_req->comn_mid.dest_data_addr = dst_buf_start;
594         }
595
596 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
597         QAT_DP_HEXDUMP_LOG(DEBUG, "qat_req:", qat_req,
598                         sizeof(struct icp_qat_fw_la_bulk_req));
599         QAT_DP_HEXDUMP_LOG(DEBUG, "src_data:",
600                         rte_pktmbuf_mtod(op->sym->m_src, uint8_t*),
601                         rte_pktmbuf_data_len(op->sym->m_src));
602         if (do_cipher) {
603                 uint8_t *cipher_iv_ptr = rte_crypto_op_ctod_offset(op,
604                                                 uint8_t *,
605                                                 ctx->cipher_iv.offset);
606                 QAT_DP_HEXDUMP_LOG(DEBUG, "cipher iv:", cipher_iv_ptr,
607                                 ctx->cipher_iv.length);
608         }
609
610         if (do_auth) {
611                 if (ctx->auth_iv.length) {
612                         uint8_t *auth_iv_ptr = rte_crypto_op_ctod_offset(op,
613                                                         uint8_t *,
614                                                         ctx->auth_iv.offset);
615                         QAT_DP_HEXDUMP_LOG(DEBUG, "auth iv:", auth_iv_ptr,
616                                                 ctx->auth_iv.length);
617                 }
618                 QAT_DP_HEXDUMP_LOG(DEBUG, "digest:", op->sym->auth.digest.data,
619                                 ctx->digest_length);
620         }
621
622         if (do_aead) {
623                 QAT_DP_HEXDUMP_LOG(DEBUG, "digest:", op->sym->aead.digest.data,
624                                 ctx->digest_length);
625                 QAT_DP_HEXDUMP_LOG(DEBUG, "aad:", op->sym->aead.aad.data,
626                                 ctx->aad_len);
627         }
628 #endif
629         return 0;
630 }