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