build: align variable names between drivers and libs
[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                         /* out-of-place operation (OOP) */
67                         dst = (uint8_t *) rte_pktmbuf_mtod_offset(sym_op->m_dst,
68                                                 uint8_t *, last_block_offset);
69                 else
70                         dst = last_block;
71
72                 if (last_block_len < sym_op->cipher.data.length)
73                         /* use previous block ciphertext as IV */
74                         iv = last_block - block_len;
75                 else
76                         /* runt block, i.e. less than one full block */
77                         iv = rte_crypto_op_ctod_offset(op, uint8_t *,
78                                         ctx->cipher_iv.offset);
79
80 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
81                 QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: src before pre-process:",
82                         last_block, last_block_len);
83                 if (sym_op->m_dst != NULL)
84                         QAT_DP_HEXDUMP_LOG(DEBUG, "BPI:dst before pre-process:",
85                         dst, last_block_len);
86 #endif
87                 bpi_cipher_decrypt(last_block, dst, iv, block_len,
88                                 last_block_len, ctx->bpi_ctx);
89 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
90                 QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: src after pre-process:",
91                         last_block, last_block_len);
92                 if (sym_op->m_dst != NULL)
93                         QAT_DP_HEXDUMP_LOG(DEBUG, "BPI: dst after pre-process:",
94                         dst, last_block_len);
95 #endif
96         }
97
98         return sym_op->cipher.data.length - last_block_len;
99 }
100
101 static inline void
102 set_cipher_iv(uint16_t iv_length, uint16_t iv_offset,
103                 struct icp_qat_fw_la_cipher_req_params *cipher_param,
104                 struct rte_crypto_op *op,
105                 struct icp_qat_fw_la_bulk_req *qat_req)
106 {
107         /* copy IV into request if it fits */
108         if (iv_length <= sizeof(cipher_param->u.cipher_IV_array)) {
109                 rte_memcpy(cipher_param->u.cipher_IV_array,
110                                 rte_crypto_op_ctod_offset(op, uint8_t *,
111                                         iv_offset),
112                                 iv_length);
113         } else {
114                 ICP_QAT_FW_LA_CIPH_IV_FLD_FLAG_SET(
115                                 qat_req->comn_hdr.serv_specif_flags,
116                                 ICP_QAT_FW_CIPH_IV_64BIT_PTR);
117                 cipher_param->u.s.cipher_IV_ptr =
118                                 rte_crypto_op_ctophys_offset(op,
119                                         iv_offset);
120         }
121 }
122
123 /** Set IV for CCM is special case, 0th byte is set to q-1
124  *  where q is padding of nonce in 16 byte block
125  */
126 static inline void
127 set_cipher_iv_ccm(uint16_t iv_length, uint16_t iv_offset,
128                 struct icp_qat_fw_la_cipher_req_params *cipher_param,
129                 struct rte_crypto_op *op, uint8_t q, uint8_t aad_len_field_sz)
130 {
131         rte_memcpy(((uint8_t *)cipher_param->u.cipher_IV_array) +
132                         ICP_QAT_HW_CCM_NONCE_OFFSET,
133                         rte_crypto_op_ctod_offset(op, uint8_t *,
134                                 iv_offset) + ICP_QAT_HW_CCM_NONCE_OFFSET,
135                         iv_length);
136         *(uint8_t *)&cipher_param->u.cipher_IV_array[0] =
137                         q - ICP_QAT_HW_CCM_NONCE_OFFSET;
138
139         if (aad_len_field_sz)
140                 rte_memcpy(&op->sym->aead.aad.data[ICP_QAT_HW_CCM_NONCE_OFFSET],
141                         rte_crypto_op_ctod_offset(op, uint8_t *,
142                                 iv_offset) + ICP_QAT_HW_CCM_NONCE_OFFSET,
143                         iv_length);
144 }
145
146 int
147 qat_sym_build_request(void *in_op, uint8_t *out_msg,
148                 void *op_cookie, enum qat_device_gen qat_dev_gen)
149 {
150         int ret = 0;
151         struct qat_sym_session *ctx;
152         struct icp_qat_fw_la_cipher_req_params *cipher_param;
153         struct icp_qat_fw_la_auth_req_params *auth_param;
154         register struct icp_qat_fw_la_bulk_req *qat_req;
155         uint8_t do_auth = 0, do_cipher = 0, do_aead = 0;
156         uint32_t cipher_len = 0, cipher_ofs = 0;
157         uint32_t auth_len = 0, auth_ofs = 0;
158         uint32_t min_ofs = 0;
159         uint64_t src_buf_start = 0, dst_buf_start = 0;
160         uint64_t auth_data_end = 0;
161         uint8_t do_sgl = 0;
162         uint8_t in_place = 1;
163         int alignment_adjustment = 0;
164         struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
165         struct qat_sym_op_cookie *cookie =
166                                 (struct qat_sym_op_cookie *)op_cookie;
167
168         if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
169                 QAT_DP_LOG(ERR, "QAT PMD only supports symmetric crypto "
170                                 "operation requests, op (%p) is not a "
171                                 "symmetric operation.", op);
172                 return -EINVAL;
173         }
174
175         if (unlikely(op->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
176                 QAT_DP_LOG(ERR, "QAT PMD only supports session oriented"
177                                 " requests, op (%p) is sessionless.", op);
178                 return -EINVAL;
179         }
180
181         ctx = (struct qat_sym_session *)get_sym_session_private_data(
182                         op->sym->session, cryptodev_qat_driver_id);
183
184         if (unlikely(ctx == NULL)) {
185                 QAT_DP_LOG(ERR, "Session was not created for this device");
186                 return -EINVAL;
187         }
188
189         if (unlikely(ctx->min_qat_dev_gen > qat_dev_gen)) {
190                 QAT_DP_LOG(ERR, "Session alg not supported on this device gen");
191                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
192                 return -EINVAL;
193         }
194
195         qat_req = (struct icp_qat_fw_la_bulk_req *)out_msg;
196         rte_mov128((uint8_t *)qat_req, (const uint8_t *)&(ctx->fw_req));
197         qat_req->comn_mid.opaque_data = (uint64_t)(uintptr_t)op;
198         cipher_param = (void *)&qat_req->serv_specif_rqpars;
199         auth_param = (void *)((uint8_t *)cipher_param +
200                         ICP_QAT_FW_HASH_REQUEST_PARAMETERS_OFFSET);
201
202         if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_HASH_CIPHER ||
203                         ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER_HASH) {
204                 /* AES-GCM or AES-CCM */
205                 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
206                         ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_GALOIS_64 ||
207                         (ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_AES128
208                         && ctx->qat_mode == ICP_QAT_HW_CIPHER_CTR_MODE
209                         && ctx->qat_hash_alg ==
210                                         ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC)) {
211                         do_aead = 1;
212                 } else {
213                         do_auth = 1;
214                         do_cipher = 1;
215                 }
216         } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_AUTH) {
217                 do_auth = 1;
218                 do_cipher = 0;
219         } else if (ctx->qat_cmd == ICP_QAT_FW_LA_CMD_CIPHER) {
220                 do_auth = 0;
221                 do_cipher = 1;
222         }
223
224         if (do_cipher) {
225
226                 if (ctx->qat_cipher_alg ==
227                                          ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 ||
228                         ctx->qat_cipher_alg == ICP_QAT_HW_CIPHER_ALGO_KASUMI ||
229                         ctx->qat_cipher_alg ==
230                                 ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3) {
231
232                         if (unlikely(
233                             (op->sym->cipher.data.length % BYTE_LENGTH != 0) ||
234                             (op->sym->cipher.data.offset % BYTE_LENGTH != 0))) {
235                                 QAT_DP_LOG(ERR,
236                   "SNOW3G/KASUMI/ZUC in QAT PMD only supports byte aligned values");
237                                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
238                                 return -EINVAL;
239                         }
240                         cipher_len = op->sym->cipher.data.length >> 3;
241                         cipher_ofs = op->sym->cipher.data.offset >> 3;
242
243                 } else if (ctx->bpi_ctx) {
244                         /* DOCSIS - only send complete blocks to device
245                          * Process any partial block using CFB mode.
246                          * Even if 0 complete blocks, still send this to device
247                          * to get into rx queue for post-process and dequeuing
248                          */
249                         cipher_len = qat_bpicipher_preprocess(ctx, op);
250                         cipher_ofs = op->sym->cipher.data.offset;
251                 } else {
252                         cipher_len = op->sym->cipher.data.length;
253                         cipher_ofs = op->sym->cipher.data.offset;
254                 }
255
256                 set_cipher_iv(ctx->cipher_iv.length, ctx->cipher_iv.offset,
257                                 cipher_param, op, qat_req);
258                 min_ofs = cipher_ofs;
259         }
260
261         if (do_auth) {
262
263                 if (ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 ||
264                         ctx->qat_hash_alg == ICP_QAT_HW_AUTH_ALGO_KASUMI_F9 ||
265                         ctx->qat_hash_alg ==
266                                 ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3) {
267                         if (unlikely(
268                             (op->sym->auth.data.offset % BYTE_LENGTH != 0) ||
269                             (op->sym->auth.data.length % BYTE_LENGTH != 0))) {
270                                 QAT_DP_LOG(ERR,
271                 "For SNOW3G/KASUMI/ZUC, QAT PMD only supports byte aligned values");
272                                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
273                                 return -EINVAL;
274                         }
275                         auth_ofs = op->sym->auth.data.offset >> 3;
276                         auth_len = op->sym->auth.data.length >> 3;
277
278                         auth_param->u1.aad_adr =
279                                         rte_crypto_op_ctophys_offset(op,
280                                                         ctx->auth_iv.offset);
281
282                 } else if (ctx->qat_hash_alg ==
283                                         ICP_QAT_HW_AUTH_ALGO_GALOIS_128 ||
284                                 ctx->qat_hash_alg ==
285                                         ICP_QAT_HW_AUTH_ALGO_GALOIS_64) {
286                         /* AES-GMAC */
287                         set_cipher_iv(ctx->auth_iv.length,
288                                 ctx->auth_iv.offset,
289                                 cipher_param, op, qat_req);
290                         auth_ofs = op->sym->auth.data.offset;
291                         auth_len = op->sym->auth.data.length;
292
293                         auth_param->u1.aad_adr = 0;
294                         auth_param->u2.aad_sz = 0;
295
296                         /*
297                          * If len(iv)==12B fw computes J0
298                          */
299                         if (ctx->auth_iv.length == 12) {
300                                 ICP_QAT_FW_LA_GCM_IV_LEN_FLAG_SET(
301                                         qat_req->comn_hdr.serv_specif_flags,
302                                         ICP_QAT_FW_LA_GCM_IV_LEN_12_OCTETS);
303
304                         }
305                 } else {
306                         auth_ofs = op->sym->auth.data.offset;
307                         auth_len = op->sym->auth.data.length;
308
309                 }
310                 min_ofs = auth_ofs;
311
312                 if (likely(ctx->qat_hash_alg != ICP_QAT_HW_AUTH_ALGO_NULL))
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                 /* Out-of-place operation (OOP)
443                  * Don't align DMA start. DMA the minimum data-set
444                  * so as not to overwrite data in dest buffer
445                  */
446                 in_place = 0;
447                 src_buf_start =
448                         rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs);
449                 dst_buf_start =
450                         rte_pktmbuf_iova_offset(op->sym->m_dst, min_ofs);
451
452         } else {
453                 /* In-place operation
454                  * Start DMA at nearest aligned address below min_ofs
455                  */
456                 src_buf_start =
457                         rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs)
458                                                 & QAT_64_BTYE_ALIGN_MASK;
459
460                 if (unlikely((rte_pktmbuf_iova(op->sym->m_src) -
461                                         rte_pktmbuf_headroom(op->sym->m_src))
462                                                         > src_buf_start)) {
463                         /* alignment has pushed addr ahead of start of mbuf
464                          * so revert and take the performance hit
465                          */
466                         src_buf_start =
467                                 rte_pktmbuf_iova_offset(op->sym->m_src,
468                                                                 min_ofs);
469                 }
470                 dst_buf_start = src_buf_start;
471
472                 /* remember any adjustment for later, note, can be +/- */
473                 alignment_adjustment = src_buf_start -
474                         rte_pktmbuf_iova_offset(op->sym->m_src, min_ofs);
475         }
476
477         if (do_cipher || do_aead) {
478                 cipher_param->cipher_offset =
479                                 (uint32_t)rte_pktmbuf_iova_offset(
480                                 op->sym->m_src, cipher_ofs) - src_buf_start;
481                 cipher_param->cipher_length = cipher_len;
482         } else {
483                 cipher_param->cipher_offset = 0;
484                 cipher_param->cipher_length = 0;
485         }
486
487         if (do_auth || do_aead) {
488                 auth_param->auth_off = (uint32_t)rte_pktmbuf_iova_offset(
489                                 op->sym->m_src, auth_ofs) - src_buf_start;
490                 auth_param->auth_len = auth_len;
491         } else {
492                 auth_param->auth_off = 0;
493                 auth_param->auth_len = 0;
494         }
495
496         qat_req->comn_mid.dst_length =
497                 qat_req->comn_mid.src_length =
498                 (cipher_param->cipher_offset + cipher_param->cipher_length)
499                 > (auth_param->auth_off + auth_param->auth_len) ?
500                 (cipher_param->cipher_offset + cipher_param->cipher_length)
501                 : (auth_param->auth_off + auth_param->auth_len);
502
503         if (do_auth && do_cipher) {
504                 /* Handle digest-encrypted cases, i.e.
505                  * auth-gen-then-cipher-encrypt and
506                  * cipher-decrypt-then-auth-verify
507                  */
508                  /* First find the end of the data */
509                 if (do_sgl) {
510                         uint32_t remaining_off = auth_param->auth_off +
511                                 auth_param->auth_len + alignment_adjustment;
512                         struct rte_mbuf *sgl_buf =
513                                 (in_place ?
514                                         op->sym->m_src : op->sym->m_dst);
515
516                         while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
517                                         && sgl_buf->next != NULL) {
518                                 remaining_off -= rte_pktmbuf_data_len(sgl_buf);
519                                 sgl_buf = sgl_buf->next;
520                         }
521
522                         auth_data_end = (uint64_t)rte_pktmbuf_iova_offset(
523                                 sgl_buf, remaining_off);
524                 } else {
525                         auth_data_end = (in_place ?
526                                 src_buf_start : dst_buf_start) +
527                                 auth_param->auth_off + auth_param->auth_len;
528                 }
529                 /* Then check if digest-encrypted conditions are met */
530                 if ((auth_param->auth_off + auth_param->auth_len <
531                                         cipher_param->cipher_offset +
532                                         cipher_param->cipher_length) &&
533                                 (op->sym->auth.digest.phys_addr ==
534                                         auth_data_end)) {
535                         /* Handle partial digest encryption */
536                         if (cipher_param->cipher_offset +
537                                         cipher_param->cipher_length <
538                                         auth_param->auth_off +
539                                         auth_param->auth_len +
540                                         ctx->digest_length)
541                                 qat_req->comn_mid.dst_length =
542                                         qat_req->comn_mid.src_length =
543                                         auth_param->auth_off +
544                                         auth_param->auth_len +
545                                         ctx->digest_length;
546                         struct icp_qat_fw_comn_req_hdr *header =
547                                 &qat_req->comn_hdr;
548                         ICP_QAT_FW_LA_DIGEST_IN_BUFFER_SET(
549                                 header->serv_specif_flags,
550                                 ICP_QAT_FW_LA_DIGEST_IN_BUFFER);
551                 }
552         }
553
554         if (do_sgl) {
555
556                 ICP_QAT_FW_COMN_PTR_TYPE_SET(qat_req->comn_hdr.comn_req_flags,
557                                 QAT_COMN_PTR_TYPE_SGL);
558                 ret = qat_sgl_fill_array(op->sym->m_src,
559                    (int64_t)(src_buf_start - rte_pktmbuf_iova(op->sym->m_src)),
560                    &cookie->qat_sgl_src,
561                    qat_req->comn_mid.src_length,
562                    QAT_SYM_SGL_MAX_NUMBER);
563
564                 if (unlikely(ret)) {
565                         QAT_DP_LOG(ERR, "QAT PMD Cannot fill sgl array");
566                         return ret;
567                 }
568
569                 if (likely(op->sym->m_dst == NULL))
570                         qat_req->comn_mid.dest_data_addr =
571                                 qat_req->comn_mid.src_data_addr =
572                                 cookie->qat_sgl_src_phys_addr;
573                 else {
574                         ret = qat_sgl_fill_array(op->sym->m_dst,
575                                 (int64_t)(dst_buf_start -
576                                           rte_pktmbuf_iova(op->sym->m_dst)),
577                                  &cookie->qat_sgl_dst,
578                                  qat_req->comn_mid.dst_length,
579                                  QAT_SYM_SGL_MAX_NUMBER);
580
581                         if (unlikely(ret)) {
582                                 QAT_DP_LOG(ERR, "QAT PMD can't fill sgl array");
583                                 return ret;
584                         }
585
586                         qat_req->comn_mid.src_data_addr =
587                                 cookie->qat_sgl_src_phys_addr;
588                         qat_req->comn_mid.dest_data_addr =
589                                         cookie->qat_sgl_dst_phys_addr;
590                 }
591                 qat_req->comn_mid.src_length = 0;
592                 qat_req->comn_mid.dst_length = 0;
593         } else {
594                 qat_req->comn_mid.src_data_addr = src_buf_start;
595                 qat_req->comn_mid.dest_data_addr = dst_buf_start;
596         }
597
598         /* Handle Single-Pass GCM */
599         if (ctx->is_single_pass) {
600                 cipher_param->spc_aad_addr = op->sym->aead.aad.phys_addr;
601                 cipher_param->spc_auth_res_addr =
602                                 op->sym->aead.digest.phys_addr;
603         }
604
605 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
606         QAT_DP_HEXDUMP_LOG(DEBUG, "qat_req:", qat_req,
607                         sizeof(struct icp_qat_fw_la_bulk_req));
608         QAT_DP_HEXDUMP_LOG(DEBUG, "src_data:",
609                         rte_pktmbuf_mtod(op->sym->m_src, uint8_t*),
610                         rte_pktmbuf_data_len(op->sym->m_src));
611         if (do_cipher) {
612                 uint8_t *cipher_iv_ptr = rte_crypto_op_ctod_offset(op,
613                                                 uint8_t *,
614                                                 ctx->cipher_iv.offset);
615                 QAT_DP_HEXDUMP_LOG(DEBUG, "cipher iv:", cipher_iv_ptr,
616                                 ctx->cipher_iv.length);
617         }
618
619         if (do_auth) {
620                 if (ctx->auth_iv.length) {
621                         uint8_t *auth_iv_ptr = rte_crypto_op_ctod_offset(op,
622                                                         uint8_t *,
623                                                         ctx->auth_iv.offset);
624                         QAT_DP_HEXDUMP_LOG(DEBUG, "auth iv:", auth_iv_ptr,
625                                                 ctx->auth_iv.length);
626                 }
627                 QAT_DP_HEXDUMP_LOG(DEBUG, "digest:", op->sym->auth.digest.data,
628                                 ctx->digest_length);
629         }
630
631         if (do_aead) {
632                 QAT_DP_HEXDUMP_LOG(DEBUG, "digest:", op->sym->aead.digest.data,
633                                 ctx->digest_length);
634                 QAT_DP_HEXDUMP_LOG(DEBUG, "aad:", op->sym->aead.aad.data,
635                                 ctx->aad_len);
636         }
637 #endif
638         return 0;
639 }