LCOV - code coverage report
Current view: top level - drivers/crypto/qat/dev - qat_crypto_pmd_gens.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 314 0.0 %
Date: 2024-01-22 15:35:40 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 606 0.0 %

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

Generated by: LCOV version 1.14