LCOV - code coverage report
Current view: top level - drivers/crypto/dpaa2_sec - dpaa2_sec_raw_dp.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 459 0.0 %
Date: 2024-01-22 16:26:08 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 150 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright 2021-2022 NXP
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <cryptodev_pmd.h>
       6                 :            : #include <bus_fslmc_driver.h>
       7                 :            : #include <fslmc_vfio.h>
       8                 :            : #include <dpaa2_hw_pvt.h>
       9                 :            : #include <dpaa2_hw_dpio.h>
      10                 :            : 
      11                 :            : #include "dpaa2_sec_priv.h"
      12                 :            : #include "dpaa2_sec_logs.h"
      13                 :            : 
      14                 :            : #include <desc/algo.h>
      15                 :            : 
      16                 :            : struct dpaa2_sec_raw_dp_ctx {
      17                 :            :         dpaa2_sec_session *session;
      18                 :            :         uint32_t tail;
      19                 :            :         uint32_t head;
      20                 :            :         uint16_t cached_enqueue;
      21                 :            :         uint16_t cached_dequeue;
      22                 :            : };
      23                 :            : 
      24                 :            : static int
      25                 :          0 : build_raw_dp_chain_fd(uint8_t *drv_ctx,
      26                 :            :                        struct rte_crypto_sgl *sgl,
      27                 :            :                        struct rte_crypto_sgl *dest_sgl,
      28                 :            :                        struct rte_crypto_va_iova_ptr *iv,
      29                 :            :                        struct rte_crypto_va_iova_ptr *digest,
      30                 :            :                        struct rte_crypto_va_iova_ptr *auth_iv,
      31                 :            :                        union rte_crypto_sym_ofs ofs,
      32                 :            :                        void *userdata,
      33                 :            :                        struct qbman_fd *fd)
      34                 :            : {
      35                 :            :         RTE_SET_USED(auth_iv);
      36                 :            : 
      37                 :          0 :         dpaa2_sec_session *sess =
      38                 :            :                 ((struct dpaa2_sec_raw_dp_ctx *)drv_ctx)->session;
      39                 :          0 :         struct ctxt_priv *priv = sess->ctxt;
      40                 :            :         struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
      41                 :            :         struct sec_flow_context *flc;
      42                 :            :         int data_len = 0, auth_len = 0, cipher_len = 0;
      43                 :            :         unsigned int i = 0;
      44                 :          0 :         uint16_t auth_hdr_len = ofs.ofs.cipher.head -
      45                 :            :                                 ofs.ofs.auth.head;
      46                 :            : 
      47                 :            :         uint16_t auth_tail_len;
      48                 :            :         uint32_t auth_only_len;
      49                 :          0 :         int icv_len = sess->digest_length;
      50                 :            :         uint8_t *old_icv;
      51                 :          0 :         uint8_t *iv_ptr = iv->va;
      52                 :            : 
      53         [ #  # ]:          0 :         for (i = 0; i < sgl->num; i++)
      54                 :          0 :                 data_len += sgl->vec[i].len;
      55                 :            : 
      56                 :          0 :         cipher_len = data_len - ofs.ofs.cipher.head - ofs.ofs.cipher.tail;
      57                 :          0 :         auth_len = data_len - ofs.ofs.auth.head - ofs.ofs.auth.tail;
      58                 :          0 :         auth_tail_len = auth_len - cipher_len - auth_hdr_len;
      59                 :          0 :         auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
      60                 :            :         /* first FLE entry used to store session ctxt */
      61                 :          0 :         fle = (struct qbman_fle *)rte_malloc(NULL,
      62                 :          0 :                         FLE_SG_MEM_SIZE(2 * sgl->num),
      63                 :            :                         RTE_CACHE_LINE_SIZE);
      64         [ #  # ]:          0 :         if (unlikely(!fle)) {
      65                 :          0 :                 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
      66                 :          0 :                 return -ENOMEM;
      67                 :            :         }
      68                 :          0 :         memset(fle, 0, FLE_SG_MEM_SIZE(2 * sgl->num));
      69                 :          0 :         DPAA2_SET_FLE_ADDR(fle, (size_t)userdata);
      70                 :          0 :         DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
      71                 :            : 
      72                 :          0 :         op_fle = fle + 1;
      73                 :            :         ip_fle = fle + 2;
      74                 :          0 :         sge = fle + 3;
      75                 :            : 
      76                 :            :         /* Save the shared descriptor */
      77                 :          0 :         flc = &priv->flc_desc[0].flc;
      78                 :            : 
      79                 :            :         /* Configure FD as a FRAME LIST */
      80                 :          0 :         DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
      81                 :          0 :         DPAA2_SET_FD_COMPOUND_FMT(fd);
      82                 :          0 :         DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
      83                 :            : 
      84                 :            :         /* Configure Output FLE with Scatter/Gather Entry */
      85                 :          0 :         DPAA2_SET_FLE_SG_EXT(op_fle);
      86                 :          0 :         DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
      87                 :            : 
      88         [ #  # ]:          0 :         if (auth_only_len)
      89                 :          0 :                 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
      90                 :            : 
      91                 :          0 :         op_fle->length = (sess->dir == DIR_ENC) ?
      92         [ #  # ]:          0 :                         (cipher_len + icv_len) :
      93                 :            :                         cipher_len;
      94                 :            : 
      95                 :            :         /* OOP */
      96         [ #  # ]:          0 :         if (dest_sgl) {
      97                 :            :                 /* Configure Output SGE for Encap/Decap */
      98                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[0].iova + ofs.ofs.cipher.head);
      99                 :          0 :                 sge->length = dest_sgl->vec[0].len - ofs.ofs.cipher.head;
     100                 :            : 
     101                 :            :                 /* o/p segs */
     102         [ #  # ]:          0 :                 for (i = 1; i < dest_sgl->num; i++) {
     103                 :          0 :                         sge++;
     104                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[i].iova);
     105                 :          0 :                         sge->length = dest_sgl->vec[i].len;
     106                 :            :                 }
     107                 :          0 :                 sge->length -= ofs.ofs.cipher.tail;
     108                 :            :         } else {
     109                 :            :                 /* Configure Output SGE for Encap/Decap */
     110                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova + ofs.ofs.cipher.head);
     111                 :          0 :                 sge->length = sgl->vec[0].len - ofs.ofs.cipher.head;
     112                 :            : 
     113                 :            :                 /* o/p segs */
     114         [ #  # ]:          0 :                 for (i = 1; i < sgl->num; i++) {
     115                 :          0 :                         sge++;
     116                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     117                 :          0 :                         sge->length = sgl->vec[i].len;
     118                 :            :                 }
     119                 :          0 :                 sge->length -= ofs.ofs.cipher.tail;
     120                 :            :         }
     121                 :            : 
     122         [ #  # ]:          0 :         if (sess->dir == DIR_ENC) {
     123                 :          0 :                 sge++;
     124                 :          0 :                 DPAA2_SET_FLE_ADDR(sge,
     125                 :            :                         digest->iova);
     126                 :          0 :                 sge->length = icv_len;
     127                 :            :         }
     128                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     129                 :            : 
     130                 :          0 :         sge++;
     131                 :            : 
     132                 :            :         /* Configure Input FLE with Scatter/Gather Entry */
     133                 :          0 :         DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
     134                 :          0 :         DPAA2_SET_FLE_SG_EXT(ip_fle);
     135                 :          0 :         DPAA2_SET_FLE_FIN(ip_fle);
     136                 :            : 
     137                 :          0 :         ip_fle->length = (sess->dir == DIR_ENC) ?
     138         [ #  # ]:          0 :                         (auth_len + sess->iv.length) :
     139                 :          0 :                         (auth_len + sess->iv.length +
     140                 :            :                         icv_len);
     141                 :            : 
     142                 :            :         /* Configure Input SGE for Encap/Decap */
     143                 :          0 :         DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
     144                 :          0 :         sge->length = sess->iv.length;
     145                 :            : 
     146                 :          0 :         sge++;
     147                 :          0 :         DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova + ofs.ofs.auth.head);
     148                 :          0 :         sge->length = sgl->vec[0].len - ofs.ofs.auth.head;
     149                 :            : 
     150         [ #  # ]:          0 :         for (i = 1; i < sgl->num; i++) {
     151                 :          0 :                 sge++;
     152                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     153                 :          0 :                 sge->length = sgl->vec[i].len;
     154                 :            :         }
     155                 :            : 
     156         [ #  # ]:          0 :         if (sess->dir == DIR_DEC) {
     157                 :          0 :                 sge++;
     158                 :          0 :                 old_icv = (uint8_t *)(sge + 1);
     159                 :          0 :                 memcpy(old_icv, digest->va,
     160                 :            :                         icv_len);
     161                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
     162                 :          0 :                 sge->length = icv_len;
     163                 :            :         }
     164                 :            : 
     165                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     166         [ #  # ]:          0 :         if (auth_only_len) {
     167                 :          0 :                 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
     168                 :          0 :                 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
     169                 :            :         }
     170                 :          0 :         DPAA2_SET_FD_LEN(fd, ip_fle->length);
     171                 :            : 
     172                 :          0 :         return 0;
     173                 :            : }
     174                 :            : 
     175                 :            : static int
     176                 :          0 : build_raw_dp_aead_fd(uint8_t *drv_ctx,
     177                 :            :                        struct rte_crypto_sgl *sgl,
     178                 :            :                        struct rte_crypto_sgl *dest_sgl,
     179                 :            :                        struct rte_crypto_va_iova_ptr *iv,
     180                 :            :                        struct rte_crypto_va_iova_ptr *digest,
     181                 :            :                        struct rte_crypto_va_iova_ptr *auth_iv,
     182                 :            :                        union rte_crypto_sym_ofs ofs,
     183                 :            :                        void *userdata,
     184                 :            :                        struct qbman_fd *fd)
     185                 :            : {
     186                 :          0 :         dpaa2_sec_session *sess =
     187                 :            :                 ((struct dpaa2_sec_raw_dp_ctx *)drv_ctx)->session;
     188                 :          0 :         struct ctxt_priv *priv = sess->ctxt;
     189                 :            :         struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
     190                 :            :         struct sec_flow_context *flc;
     191                 :          0 :         uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
     192                 :          0 :         int icv_len = sess->digest_length;
     193                 :            :         uint8_t *old_icv;
     194                 :          0 :         uint8_t *IV_ptr = iv->va;
     195                 :            :         unsigned int i = 0;
     196                 :            :         int data_len = 0, aead_len = 0;
     197                 :            : 
     198         [ #  # ]:          0 :         for (i = 0; i < sgl->num; i++)
     199                 :          0 :                 data_len += sgl->vec[i].len;
     200                 :            : 
     201                 :          0 :         aead_len = data_len - ofs.ofs.cipher.head - ofs.ofs.cipher.tail;
     202                 :            : 
     203                 :            :         /* first FLE entry used to store mbuf and session ctxt */
     204                 :          0 :         fle = (struct qbman_fle *)rte_malloc(NULL,
     205                 :          0 :                         FLE_SG_MEM_SIZE(2 * sgl->num),
     206                 :            :                         RTE_CACHE_LINE_SIZE);
     207         [ #  # ]:          0 :         if (unlikely(!fle)) {
     208                 :          0 :                 DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
     209                 :          0 :                 return -ENOMEM;
     210                 :            :         }
     211                 :          0 :         memset(fle, 0, FLE_SG_MEM_SIZE(2 * sgl->num));
     212                 :          0 :         DPAA2_SET_FLE_ADDR(fle, (size_t)userdata);
     213                 :          0 :         DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
     214                 :            : 
     215                 :          0 :         op_fle = fle + 1;
     216                 :            :         ip_fle = fle + 2;
     217                 :          0 :         sge = fle + 3;
     218                 :            : 
     219                 :            :         /* Save the shared descriptor */
     220                 :          0 :         flc = &priv->flc_desc[0].flc;
     221                 :            : 
     222                 :            :         /* Configure FD as a FRAME LIST */
     223                 :          0 :         DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
     224                 :          0 :         DPAA2_SET_FD_COMPOUND_FMT(fd);
     225                 :          0 :         DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
     226                 :            : 
     227                 :            :         /* Configure Output FLE with Scatter/Gather Entry */
     228                 :          0 :         DPAA2_SET_FLE_SG_EXT(op_fle);
     229                 :          0 :         DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
     230                 :            : 
     231         [ #  # ]:          0 :         if (auth_only_len)
     232                 :          0 :                 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
     233                 :            : 
     234                 :          0 :         op_fle->length = (sess->dir == DIR_ENC) ?
     235         [ #  # ]:          0 :                         (aead_len + icv_len) :
     236                 :            :                         aead_len;
     237                 :            : 
     238                 :            :         /* OOP */
     239         [ #  # ]:          0 :         if (dest_sgl) {
     240                 :            :                 /* Configure Output SGE for Encap/Decap */
     241                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[0].iova +  ofs.ofs.cipher.head);
     242                 :          0 :                 sge->length = dest_sgl->vec[0].len - ofs.ofs.cipher.head;
     243                 :            : 
     244                 :            :                 /* o/p segs */
     245         [ #  # ]:          0 :                 for (i = 1; i < dest_sgl->num; i++) {
     246                 :          0 :                         sge++;
     247                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[i].iova);
     248                 :          0 :                         sge->length = dest_sgl->vec[i].len;
     249                 :            :                 }
     250                 :            :         } else {
     251                 :            :                 /* Configure Output SGE for Encap/Decap */
     252                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova + ofs.ofs.cipher.head);
     253                 :          0 :                 sge->length = sgl->vec[0].len - ofs.ofs.cipher.head;
     254                 :            : 
     255                 :            :                 /* o/p segs */
     256         [ #  # ]:          0 :                 for (i = 1; i < sgl->num; i++) {
     257                 :          0 :                         sge++;
     258                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     259                 :          0 :                         sge->length = sgl->vec[i].len;
     260                 :            :                 }
     261                 :            :         }
     262                 :            : 
     263         [ #  # ]:          0 :         if (sess->dir == DIR_ENC) {
     264                 :          0 :                 sge++;
     265                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, digest->iova);
     266                 :          0 :                 sge->length = icv_len;
     267                 :            :         }
     268                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     269                 :            : 
     270                 :          0 :         sge++;
     271                 :            : 
     272                 :            :         /* Configure Input FLE with Scatter/Gather Entry */
     273                 :          0 :         DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
     274                 :          0 :         DPAA2_SET_FLE_SG_EXT(ip_fle);
     275                 :          0 :         DPAA2_SET_FLE_FIN(ip_fle);
     276                 :          0 :         ip_fle->length = (sess->dir == DIR_ENC) ?
     277         [ #  # ]:          0 :                 (aead_len + sess->iv.length + auth_only_len) :
     278                 :          0 :                 (aead_len + sess->iv.length + auth_only_len +
     279                 :            :                 icv_len);
     280                 :            : 
     281                 :            :         /* Configure Input SGE for Encap/Decap */
     282                 :          0 :         DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
     283                 :          0 :         sge->length = sess->iv.length;
     284                 :            : 
     285                 :          0 :         sge++;
     286         [ #  # ]:          0 :         if (auth_only_len) {
     287                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, auth_iv->iova);
     288                 :          0 :                 sge->length = auth_only_len;
     289                 :          0 :                 sge++;
     290                 :            :         }
     291                 :            : 
     292                 :          0 :         DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova + ofs.ofs.cipher.head);
     293                 :          0 :         sge->length = sgl->vec[0].len - ofs.ofs.cipher.head;
     294                 :            : 
     295                 :            :         /* i/p segs */
     296         [ #  # ]:          0 :         for (i = 1; i < sgl->num; i++) {
     297                 :          0 :                 sge++;
     298                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     299                 :          0 :                 sge->length = sgl->vec[i].len;
     300                 :            :         }
     301                 :            : 
     302         [ #  # ]:          0 :         if (sess->dir == DIR_DEC) {
     303                 :          0 :                 sge++;
     304                 :          0 :                 old_icv = (uint8_t *)(sge + 1);
     305                 :          0 :                 memcpy(old_icv,  digest->va, icv_len);
     306                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
     307                 :          0 :                 sge->length = icv_len;
     308                 :            :         }
     309                 :            : 
     310                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     311         [ #  # ]:          0 :         if (auth_only_len) {
     312                 :          0 :                 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
     313                 :          0 :                 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
     314                 :            :         }
     315                 :          0 :         DPAA2_SET_FD_LEN(fd, ip_fle->length);
     316                 :            : 
     317                 :          0 :         return 0;
     318                 :            : }
     319                 :            : 
     320                 :            : static int
     321                 :          0 : build_raw_dp_auth_fd(uint8_t *drv_ctx,
     322                 :            :                        struct rte_crypto_sgl *sgl,
     323                 :            :                        struct rte_crypto_sgl *dest_sgl,
     324                 :            :                        struct rte_crypto_va_iova_ptr *iv,
     325                 :            :                        struct rte_crypto_va_iova_ptr *digest,
     326                 :            :                        struct rte_crypto_va_iova_ptr *auth_iv,
     327                 :            :                        union rte_crypto_sym_ofs ofs,
     328                 :            :                        void *userdata,
     329                 :            :                        struct qbman_fd *fd)
     330                 :            : {
     331                 :            :         RTE_SET_USED(iv);
     332                 :            :         RTE_SET_USED(auth_iv);
     333                 :            :         RTE_SET_USED(dest_sgl);
     334                 :            : 
     335                 :          0 :         dpaa2_sec_session *sess =
     336                 :            :                 ((struct dpaa2_sec_raw_dp_ctx *)drv_ctx)->session;
     337                 :            :         struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
     338                 :            :         struct sec_flow_context *flc;
     339                 :            :         int total_len = 0, data_len = 0, data_offset;
     340                 :            :         uint8_t *old_digest;
     341                 :          0 :         struct ctxt_priv *priv = sess->ctxt;
     342                 :            :         unsigned int i;
     343                 :            : 
     344         [ #  # ]:          0 :         for (i = 0; i < sgl->num; i++)
     345                 :          0 :                 total_len += sgl->vec[i].len;
     346                 :            : 
     347                 :          0 :         data_len = total_len - ofs.ofs.auth.head - ofs.ofs.auth.tail;
     348                 :            :         data_offset = ofs.ofs.auth.head;
     349                 :            : 
     350                 :            :         /* For SNOW3G and ZUC, lengths in bits only supported */
     351                 :          0 :         fle = (struct qbman_fle *)rte_malloc(NULL,
     352                 :          0 :                 FLE_SG_MEM_SIZE(2 * sgl->num),
     353                 :            :                         RTE_CACHE_LINE_SIZE);
     354         [ #  # ]:          0 :         if (unlikely(!fle)) {
     355                 :          0 :                 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
     356                 :          0 :                 return -ENOMEM;
     357                 :            :         }
     358                 :          0 :         memset(fle, 0, FLE_SG_MEM_SIZE(2*sgl->num));
     359                 :            :         /* first FLE entry used to store mbuf and session ctxt */
     360                 :          0 :         DPAA2_SET_FLE_ADDR(fle, (size_t)userdata);
     361                 :          0 :         DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
     362                 :          0 :         op_fle = fle + 1;
     363                 :            :         ip_fle = fle + 2;
     364                 :          0 :         sge = fle + 3;
     365                 :            : 
     366                 :          0 :         flc = &priv->flc_desc[DESC_INITFINAL].flc;
     367                 :            : 
     368                 :            :         /* sg FD */
     369                 :          0 :         DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
     370                 :          0 :         DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
     371                 :          0 :         DPAA2_SET_FD_COMPOUND_FMT(fd);
     372                 :            : 
     373                 :            :         /* o/p fle */
     374                 :          0 :         DPAA2_SET_FLE_ADDR(op_fle,
     375                 :            :                         DPAA2_VADDR_TO_IOVA(digest->va));
     376                 :          0 :         op_fle->length = sess->digest_length;
     377                 :            : 
     378                 :            :         /* i/p fle */
     379                 :          0 :         DPAA2_SET_FLE_SG_EXT(ip_fle);
     380                 :          0 :         DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
     381                 :          0 :         ip_fle->length = data_len;
     382                 :            : 
     383         [ #  # ]:          0 :         if (sess->iv.length) {
     384                 :            :                 uint8_t *iv_ptr;
     385                 :            : 
     386                 :          0 :                 iv_ptr = rte_crypto_op_ctod_offset(userdata, uint8_t *,
     387                 :            :                                                 sess->iv.offset);
     388                 :            : 
     389         [ #  # ]:          0 :                 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
     390                 :            :                         iv_ptr = conv_to_snow_f9_iv(iv_ptr);
     391                 :          0 :                         sge->length = 12;
     392         [ #  # ]:          0 :                 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
     393                 :            :                         iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
     394                 :          0 :                         sge->length = 8;
     395                 :            :                 } else {
     396                 :          0 :                         sge->length = sess->iv.length;
     397                 :            :                 }
     398                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
     399                 :          0 :                 ip_fle->length += sge->length;
     400                 :          0 :                 sge++;
     401                 :            :         }
     402                 :            :         /* i/p 1st seg */
     403                 :          0 :         DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova + data_offset);
     404                 :            : 
     405         [ #  # ]:          0 :         if (data_len <= (int)(sgl->vec[0].len - data_offset)) {
     406                 :          0 :                 sge->length = data_len;
     407                 :            :                 data_len = 0;
     408                 :            :         } else {
     409                 :          0 :                 sge->length = sgl->vec[0].len - data_offset;
     410         [ #  # ]:          0 :                 for (i = 1; i < sgl->num; i++) {
     411                 :          0 :                         sge++;
     412                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     413                 :          0 :                         sge->length = sgl->vec[i].len;
     414                 :            :                 }
     415                 :            :         }
     416         [ #  # ]:          0 :         if (sess->dir == DIR_DEC) {
     417                 :            :                 /* Digest verification case */
     418                 :          0 :                 sge++;
     419                 :          0 :                 old_digest = (uint8_t *)(sge + 1);
     420                 :          0 :                 rte_memcpy(old_digest, digest->va,
     421         [ #  # ]:          0 :                         sess->digest_length);
     422                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
     423                 :          0 :                 sge->length = sess->digest_length;
     424                 :          0 :                 ip_fle->length += sess->digest_length;
     425                 :            :         }
     426                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     427                 :          0 :         DPAA2_SET_FLE_FIN(ip_fle);
     428                 :          0 :         DPAA2_SET_FD_LEN(fd, ip_fle->length);
     429                 :            : 
     430                 :          0 :         return 0;
     431                 :            : }
     432                 :            : 
     433                 :            : static int
     434                 :          0 : build_raw_dp_proto_fd(uint8_t *drv_ctx,
     435                 :            :                        struct rte_crypto_sgl *sgl,
     436                 :            :                        struct rte_crypto_sgl *dest_sgl,
     437                 :            :                        struct rte_crypto_va_iova_ptr *iv,
     438                 :            :                        struct rte_crypto_va_iova_ptr *digest,
     439                 :            :                        struct rte_crypto_va_iova_ptr *auth_iv,
     440                 :            :                        union rte_crypto_sym_ofs ofs,
     441                 :            :                        void *userdata,
     442                 :            :                        struct qbman_fd *fd)
     443                 :            : {
     444                 :            :         RTE_SET_USED(iv);
     445                 :            :         RTE_SET_USED(digest);
     446                 :            :         RTE_SET_USED(auth_iv);
     447                 :            :         RTE_SET_USED(ofs);
     448                 :            : 
     449                 :          0 :         dpaa2_sec_session *sess =
     450                 :            :                 ((struct dpaa2_sec_raw_dp_ctx *)drv_ctx)->session;
     451                 :          0 :         struct ctxt_priv *priv = sess->ctxt;
     452                 :            :         struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
     453                 :            :         struct sec_flow_context *flc;
     454                 :            :         uint32_t in_len = 0, out_len = 0, i;
     455                 :            : 
     456                 :            :         /* first FLE entry used to store mbuf and session ctxt */
     457                 :          0 :         fle = (struct qbman_fle *)rte_malloc(NULL,
     458                 :          0 :                         FLE_SG_MEM_SIZE(2 * sgl->num),
     459                 :            :                         RTE_CACHE_LINE_SIZE);
     460         [ #  # ]:          0 :         if (unlikely(!fle)) {
     461                 :          0 :                 DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
     462                 :          0 :                 return -ENOMEM;
     463                 :            :         }
     464                 :          0 :         memset(fle, 0, FLE_SG_MEM_SIZE(2 * sgl->num));
     465                 :          0 :         DPAA2_SET_FLE_ADDR(fle, (size_t)userdata);
     466                 :          0 :         DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
     467                 :            : 
     468                 :            :         /* Save the shared descriptor */
     469                 :          0 :         flc = &priv->flc_desc[0].flc;
     470                 :          0 :         op_fle = fle + 1;
     471                 :            :         ip_fle = fle + 2;
     472                 :          0 :         sge = fle + 3;
     473                 :            : 
     474                 :          0 :         DPAA2_SET_FD_IVP(fd);
     475                 :          0 :         DPAA2_SET_FLE_IVP(op_fle);
     476                 :          0 :         DPAA2_SET_FLE_IVP(ip_fle);
     477                 :            : 
     478                 :            :         /* Configure FD as a FRAME LIST */
     479                 :          0 :         DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
     480                 :          0 :         DPAA2_SET_FD_COMPOUND_FMT(fd);
     481                 :          0 :         DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
     482                 :            : 
     483                 :            :         /* Configure Output FLE with Scatter/Gather Entry */
     484                 :          0 :         DPAA2_SET_FLE_SG_EXT(op_fle);
     485                 :          0 :         DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
     486                 :            : 
     487                 :            :         /* OOP */
     488         [ #  # ]:          0 :         if (dest_sgl) {
     489                 :            :                 /* Configure Output SGE for Encap/Decap */
     490                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[0].iova);
     491                 :          0 :                 sge->length = dest_sgl->vec[0].len;
     492                 :            :                 out_len += sge->length;
     493                 :            :                 /* o/p segs */
     494         [ #  # ]:          0 :                 for (i = 1; i < dest_sgl->num; i++) {
     495                 :          0 :                         sge++;
     496                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[i].iova);
     497                 :          0 :                         sge->length = dest_sgl->vec[i].len;
     498                 :          0 :                         out_len += sge->length;
     499                 :            :                 }
     500                 :          0 :                 sge->length = dest_sgl->vec[i - 1].tot_len;
     501                 :            : 
     502                 :            :         } else {
     503                 :            :                 /* Configure Output SGE for Encap/Decap */
     504                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova);
     505                 :          0 :                 sge->length = sgl->vec[0].len;
     506                 :            :                 out_len += sge->length;
     507                 :            :                 /* o/p segs */
     508         [ #  # ]:          0 :                 for (i = 1; i < sgl->num; i++) {
     509                 :          0 :                         sge++;
     510                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     511                 :          0 :                         sge->length = sgl->vec[i].len;
     512                 :          0 :                         out_len += sge->length;
     513                 :            :                 }
     514                 :          0 :                 sge->length = sgl->vec[i - 1].tot_len;
     515                 :            :         }
     516                 :          0 :         out_len += sge->length;
     517                 :            : 
     518                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     519                 :          0 :         op_fle->length = out_len;
     520                 :            : 
     521                 :          0 :         sge++;
     522                 :            : 
     523                 :            :         /* Configure Input FLE with Scatter/Gather Entry */
     524                 :          0 :         DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
     525                 :          0 :         DPAA2_SET_FLE_SG_EXT(ip_fle);
     526                 :          0 :         DPAA2_SET_FLE_FIN(ip_fle);
     527                 :            : 
     528                 :            :         /* Configure input SGE for Encap/Decap */
     529                 :          0 :         DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova);
     530                 :          0 :         sge->length = sgl->vec[0].len;
     531                 :            :         in_len += sge->length;
     532                 :            :         /* i/p segs */
     533         [ #  # ]:          0 :         for (i = 1; i < sgl->num; i++) {
     534                 :          0 :                 sge++;
     535                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     536                 :          0 :                 sge->length = sgl->vec[i].len;
     537                 :          0 :                 in_len += sge->length;
     538                 :            :         }
     539                 :            : 
     540                 :          0 :         ip_fle->length = in_len;
     541                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     542                 :            : 
     543                 :            :         /* In case of PDCP, per packet HFN is stored in
     544                 :            :          * mbuf priv after sym_op.
     545                 :            :          */
     546   [ #  #  #  # ]:          0 :         if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
     547                 :          0 :                 uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)userdata +
     548                 :          0 :                                 sess->pdcp.hfn_ovd_offset);
     549                 :            :                 /* enable HFN override */
     550                 :          0 :                 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
     551                 :          0 :                 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
     552                 :          0 :                 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
     553                 :            :         }
     554                 :          0 :         DPAA2_SET_FD_LEN(fd, ip_fle->length);
     555                 :            : 
     556                 :          0 :         return 0;
     557                 :            : }
     558                 :            : 
     559                 :            : static int
     560                 :          0 : build_raw_dp_cipher_fd(uint8_t *drv_ctx,
     561                 :            :                        struct rte_crypto_sgl *sgl,
     562                 :            :                        struct rte_crypto_sgl *dest_sgl,
     563                 :            :                        struct rte_crypto_va_iova_ptr *iv,
     564                 :            :                        struct rte_crypto_va_iova_ptr *digest,
     565                 :            :                        struct rte_crypto_va_iova_ptr *auth_iv,
     566                 :            :                        union rte_crypto_sym_ofs ofs,
     567                 :            :                        void *userdata,
     568                 :            :                        struct qbman_fd *fd)
     569                 :            : {
     570                 :            :         RTE_SET_USED(digest);
     571                 :            :         RTE_SET_USED(auth_iv);
     572                 :            : 
     573                 :          0 :         dpaa2_sec_session *sess =
     574                 :            :                 ((struct dpaa2_sec_raw_dp_ctx *)drv_ctx)->session;
     575                 :            :         struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
     576                 :            :         int total_len = 0, data_len = 0, data_offset;
     577                 :            :         struct sec_flow_context *flc;
     578                 :          0 :         struct ctxt_priv *priv = sess->ctxt;
     579                 :            :         unsigned int i;
     580                 :            : 
     581         [ #  # ]:          0 :         for (i = 0; i < sgl->num; i++)
     582                 :          0 :                 total_len += sgl->vec[i].len;
     583                 :            : 
     584                 :          0 :         data_len = total_len - ofs.ofs.cipher.head - ofs.ofs.cipher.tail;
     585                 :            :         data_offset = ofs.ofs.cipher.head;
     586                 :            : 
     587                 :            :         /* For SNOW3G and ZUC, lengths in bits only supported */
     588                 :            :         /* first FLE entry used to store mbuf and session ctxt */
     589                 :          0 :         fle = (struct qbman_fle *)rte_malloc(NULL,
     590                 :          0 :                         FLE_SG_MEM_SIZE(2*sgl->num),
     591                 :            :                         RTE_CACHE_LINE_SIZE);
     592         [ #  # ]:          0 :         if (!fle) {
     593                 :          0 :                 DPAA2_SEC_ERR("RAW CIPHER SG: Memory alloc failed for SGE");
     594                 :          0 :                 return -ENOMEM;
     595                 :            :         }
     596                 :          0 :         memset(fle, 0, FLE_SG_MEM_SIZE(2*sgl->num));
     597                 :            :         /* first FLE entry used to store userdata and session ctxt */
     598                 :          0 :         DPAA2_SET_FLE_ADDR(fle, (size_t)userdata);
     599                 :          0 :         DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
     600                 :            : 
     601                 :          0 :         op_fle = fle + 1;
     602                 :            :         ip_fle = fle + 2;
     603                 :          0 :         sge = fle + 3;
     604                 :            : 
     605                 :          0 :         flc = &priv->flc_desc[0].flc;
     606                 :            : 
     607                 :            :         DPAA2_SEC_DP_DEBUG(
     608                 :            :                 "RAW CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d\n",
     609                 :            :                 data_offset,
     610                 :            :                 data_len,
     611                 :            :                 sess->iv.length);
     612                 :            : 
     613                 :            :         /* o/p fle */
     614                 :          0 :         DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
     615                 :          0 :         op_fle->length = data_len;
     616                 :          0 :         DPAA2_SET_FLE_SG_EXT(op_fle);
     617                 :            : 
     618                 :            :         /* OOP */
     619         [ #  # ]:          0 :         if (dest_sgl) {
     620                 :            :                 /* o/p 1st seg */
     621                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[0].iova + data_offset);
     622                 :          0 :                 sge->length = dest_sgl->vec[0].len - data_offset;
     623                 :            : 
     624                 :            :                 /* o/p segs */
     625         [ #  # ]:          0 :                 for (i = 1; i < dest_sgl->num; i++) {
     626                 :          0 :                         sge++;
     627                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, dest_sgl->vec[i].iova);
     628                 :          0 :                         sge->length = dest_sgl->vec[i].len;
     629                 :            :                 }
     630                 :            :         } else {
     631                 :            :                 /* o/p 1st seg */
     632                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova + data_offset);
     633                 :          0 :                 sge->length = sgl->vec[0].len - data_offset;
     634                 :            : 
     635                 :            :                 /* o/p segs */
     636         [ #  # ]:          0 :                 for (i = 1; i < sgl->num; i++) {
     637                 :          0 :                         sge++;
     638                 :          0 :                         DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     639                 :          0 :                         sge->length = sgl->vec[i].len;
     640                 :            :                 }
     641                 :            :         }
     642                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     643                 :            : 
     644                 :            :         DPAA2_SEC_DP_DEBUG(
     645                 :            :                 "RAW CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
     646                 :            :                 flc, fle, fle->addr_hi, fle->addr_lo,
     647                 :            :                 fle->length);
     648                 :            : 
     649                 :            :         /* i/p fle */
     650                 :          0 :         sge++;
     651                 :          0 :         DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
     652                 :          0 :         ip_fle->length = sess->iv.length + data_len;
     653                 :          0 :         DPAA2_SET_FLE_SG_EXT(ip_fle);
     654                 :            : 
     655                 :            :         /* i/p IV */
     656                 :          0 :         DPAA2_SET_FLE_ADDR(sge, iv->iova);
     657                 :          0 :         sge->length = sess->iv.length;
     658                 :            : 
     659                 :          0 :         sge++;
     660                 :            : 
     661                 :            :         /* i/p 1st seg */
     662                 :          0 :         DPAA2_SET_FLE_ADDR(sge, sgl->vec[0].iova + data_offset);
     663                 :          0 :         sge->length = sgl->vec[0].len - data_offset;
     664                 :            : 
     665                 :            :         /* i/p segs */
     666         [ #  # ]:          0 :         for (i = 1; i < sgl->num; i++) {
     667                 :          0 :                 sge++;
     668                 :          0 :                 DPAA2_SET_FLE_ADDR(sge, sgl->vec[i].iova);
     669                 :          0 :                 sge->length = sgl->vec[i].len;
     670                 :            :         }
     671                 :          0 :         DPAA2_SET_FLE_FIN(sge);
     672                 :          0 :         DPAA2_SET_FLE_FIN(ip_fle);
     673                 :            : 
     674                 :            :         /* sg fd */
     675                 :          0 :         DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
     676                 :          0 :         DPAA2_SET_FD_LEN(fd, ip_fle->length);
     677                 :          0 :         DPAA2_SET_FD_COMPOUND_FMT(fd);
     678                 :          0 :         DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
     679                 :            : 
     680                 :            :         DPAA2_SEC_DP_DEBUG(
     681                 :            :                 "RAW CIPHER SG: fdaddr =%" PRIx64 " off =%d, len =%d\n",
     682                 :            :                 DPAA2_GET_FD_ADDR(fd),
     683                 :            :                 DPAA2_GET_FD_OFFSET(fd),
     684                 :            :                 DPAA2_GET_FD_LEN(fd));
     685                 :            : 
     686                 :          0 :         return 0;
     687                 :            : }
     688                 :            : 
     689                 :            : static __rte_always_inline uint32_t
     690                 :          0 : dpaa2_sec_raw_enqueue_burst(void *qp_data, uint8_t *drv_ctx,
     691                 :            :         struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
     692                 :            :         void *user_data[], int *status)
     693                 :            : {
     694                 :            :         RTE_SET_USED(user_data);
     695                 :            :         uint32_t loop;
     696                 :            :         int32_t ret;
     697                 :            :         struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
     698                 :            :         uint32_t frames_to_send, retry_count;
     699                 :            :         struct qbman_eq_desc eqdesc;
     700                 :            :         struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp_data;
     701                 :          0 :         dpaa2_sec_session *sess =
     702                 :            :                 ((struct dpaa2_sec_raw_dp_ctx *)drv_ctx)->session;
     703                 :            :         struct qbman_swp *swp;
     704                 :            :         uint16_t num_tx = 0;
     705                 :          0 :         uint32_t flags[MAX_TX_RING_SLOTS] = {0};
     706                 :            : 
     707         [ #  # ]:          0 :         if (unlikely(vec->num == 0))
     708                 :            :                 return 0;
     709                 :            : 
     710         [ #  # ]:          0 :         if (sess == NULL) {
     711                 :          0 :                 DPAA2_SEC_ERR("sessionless raw crypto not supported");
     712                 :          0 :                 return 0;
     713                 :            :         }
     714                 :            :         /*Prepare enqueue descriptor*/
     715                 :          0 :         qbman_eq_desc_clear(&eqdesc);
     716                 :          0 :         qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
     717                 :          0 :         qbman_eq_desc_set_response(&eqdesc, 0, 0);
     718                 :          0 :         qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
     719                 :            : 
     720         [ #  # ]:          0 :         if (!DPAA2_PER_LCORE_DPIO) {
     721                 :          0 :                 ret = dpaa2_affine_qbman_swp();
     722         [ #  # ]:          0 :                 if (ret) {
     723                 :          0 :                         DPAA2_SEC_ERR(
     724                 :            :                                 "Failed to allocate IO portal, tid: %d\n",
     725                 :            :                                 rte_gettid());
     726                 :          0 :                         return 0;
     727                 :            :                 }
     728                 :            :         }
     729                 :          0 :         swp = DPAA2_PER_LCORE_PORTAL;
     730                 :            : 
     731         [ #  # ]:          0 :         while (vec->num) {
     732                 :          0 :                 frames_to_send = (vec->num > dpaa2_eqcr_size) ?
     733                 :          0 :                         dpaa2_eqcr_size : vec->num;
     734                 :            : 
     735         [ #  # ]:          0 :                 for (loop = 0; loop < frames_to_send; loop++) {
     736                 :            :                         /*Clear the unused FD fields before sending*/
     737                 :          0 :                         memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
     738                 :          0 :                         ret = sess->build_raw_dp_fd(drv_ctx,
     739                 :          0 :                                                     &vec->src_sgl[loop],
     740                 :          0 :                                                     &vec->dest_sgl[loop],
     741                 :          0 :                                                     &vec->iv[loop],
     742                 :          0 :                                                     &vec->digest[loop],
     743                 :          0 :                                                     &vec->auth_iv[loop],
     744                 :            :                                                     ofs,
     745                 :          0 :                                                     user_data[loop],
     746                 :            :                                                     &fd_arr[loop]);
     747         [ #  # ]:          0 :                         if (ret) {
     748                 :          0 :                                 DPAA2_SEC_ERR("error: Improper packet contents"
     749                 :            :                                               " for crypto operation");
     750                 :          0 :                                 goto skip_tx;
     751                 :            :                         }
     752                 :          0 :                         status[loop] = 1;
     753                 :            :                 }
     754                 :            : 
     755                 :            :                 loop = 0;
     756                 :            :                 retry_count = 0;
     757         [ #  # ]:          0 :                 while (loop < frames_to_send) {
     758                 :          0 :                         ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
     759                 :          0 :                                                          &fd_arr[loop],
     760                 :            :                                                          &flags[loop],
     761                 :          0 :                                                          frames_to_send - loop);
     762         [ #  # ]:          0 :                         if (unlikely(ret < 0)) {
     763                 :          0 :                                 retry_count++;
     764         [ #  # ]:          0 :                                 if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
     765                 :          0 :                                         num_tx += loop;
     766                 :          0 :                                         vec->num -= loop;
     767                 :          0 :                                         goto skip_tx;
     768                 :            :                                 }
     769                 :            :                         } else {
     770                 :          0 :                                 loop += ret;
     771                 :            :                                 retry_count = 0;
     772                 :            :                         }
     773                 :            :                 }
     774                 :            : 
     775                 :          0 :                 num_tx += loop;
     776                 :          0 :                 vec->num -= loop;
     777                 :            :         }
     778                 :          0 : skip_tx:
     779                 :          0 :         dpaa2_qp->tx_vq.tx_pkts += num_tx;
     780                 :          0 :         dpaa2_qp->tx_vq.err_pkts += vec->num;
     781                 :            : 
     782                 :          0 :         return num_tx;
     783                 :            : }
     784                 :            : 
     785                 :            : static __rte_always_inline int
     786                 :          0 : dpaa2_sec_raw_enqueue(void *qp_data, uint8_t *drv_ctx,
     787                 :            :         struct rte_crypto_vec *data_vec,
     788                 :            :         uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
     789                 :            :         struct rte_crypto_va_iova_ptr *iv,
     790                 :            :         struct rte_crypto_va_iova_ptr *digest,
     791                 :            :         struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
     792                 :            :         void *user_data)
     793                 :            : {
     794                 :            :         RTE_SET_USED(qp_data);
     795                 :            :         RTE_SET_USED(drv_ctx);
     796                 :            :         RTE_SET_USED(data_vec);
     797                 :            :         RTE_SET_USED(n_data_vecs);
     798                 :            :         RTE_SET_USED(ofs);
     799                 :            :         RTE_SET_USED(iv);
     800                 :            :         RTE_SET_USED(digest);
     801                 :            :         RTE_SET_USED(aad_or_auth_iv);
     802                 :            :         RTE_SET_USED(user_data);
     803                 :            : 
     804                 :          0 :         return 0;
     805                 :            : }
     806                 :            : 
     807                 :            : static inline void *
     808                 :          0 : sec_fd_to_userdata(const struct qbman_fd *fd)
     809                 :            : {
     810                 :            :         struct qbman_fle *fle;
     811                 :            :         void *userdata;
     812                 :          0 :         fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
     813                 :            : 
     814                 :            :         DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
     815                 :            :                            fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
     816                 :          0 :         userdata = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
     817                 :            :         /* free the fle memory */
     818                 :          0 :         rte_free((void *)(fle-1));
     819                 :            : 
     820                 :          0 :         return userdata;
     821                 :            : }
     822                 :            : 
     823                 :            : static __rte_always_inline uint32_t
     824                 :          0 : dpaa2_sec_raw_dequeue_burst(void *qp_data, uint8_t *drv_ctx,
     825                 :            :         rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
     826                 :            :         uint32_t max_nb_to_dequeue,
     827                 :            :         rte_cryptodev_raw_post_dequeue_t post_dequeue,
     828                 :            :         void **out_user_data, uint8_t is_user_data_array,
     829                 :            :         uint32_t *n_success, int *dequeue_status)
     830                 :            : {
     831                 :            :         RTE_SET_USED(drv_ctx);
     832                 :            :         RTE_SET_USED(get_dequeue_count);
     833                 :            : 
     834                 :            :         /* Function is responsible to receive frames for a given device and VQ*/
     835                 :            :         struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp_data;
     836                 :            :         struct qbman_result *dq_storage;
     837                 :          0 :         uint32_t fqid = dpaa2_qp->rx_vq.fqid;
     838                 :            :         int ret, num_rx = 0;
     839                 :            :         uint8_t is_last = 0, status, is_success = 0;
     840                 :            :         struct qbman_swp *swp;
     841                 :            :         const struct qbman_fd *fd;
     842                 :            :         struct qbman_pull_desc pulldesc;
     843                 :            :         void *user_data;
     844                 :            :         uint32_t nb_ops = max_nb_to_dequeue;
     845                 :            : 
     846         [ #  # ]:          0 :         if (!DPAA2_PER_LCORE_DPIO) {
     847                 :          0 :                 ret = dpaa2_affine_qbman_swp();
     848         [ #  # ]:          0 :                 if (ret) {
     849                 :          0 :                         DPAA2_SEC_ERR(
     850                 :            :                                 "Failed to allocate IO portal, tid: %d\n",
     851                 :            :                                 rte_gettid());
     852                 :          0 :                         return 0;
     853                 :            :                 }
     854                 :            :         }
     855                 :          0 :         swp = DPAA2_PER_LCORE_PORTAL;
     856                 :          0 :         dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
     857                 :            : 
     858                 :          0 :         qbman_pull_desc_clear(&pulldesc);
     859                 :          0 :         qbman_pull_desc_set_numframes(&pulldesc,
     860                 :            :                                       (nb_ops > dpaa2_dqrr_size) ?
     861                 :          0 :                                       dpaa2_dqrr_size : nb_ops);
     862                 :          0 :         qbman_pull_desc_set_fq(&pulldesc, fqid);
     863                 :          0 :         qbman_pull_desc_set_storage(&pulldesc, dq_storage,
     864                 :          0 :                                     (uint64_t)DPAA2_VADDR_TO_IOVA(dq_storage),
     865                 :            :                                     1);
     866                 :            : 
     867                 :            :         /*Issue a volatile dequeue command. */
     868                 :            :         while (1) {
     869         [ #  # ]:          0 :                 if (qbman_swp_pull(swp, &pulldesc)) {
     870                 :          0 :                         DPAA2_SEC_WARN(
     871                 :            :                                 "SEC VDQ command is not issued : QBMAN busy");
     872                 :            :                         /* Portal was busy, try again */
     873                 :            :                         continue;
     874                 :            :                 }
     875                 :            :                 break;
     876                 :            :         };
     877                 :            : 
     878                 :            :         /* Receive the packets till Last Dequeue entry is found with
     879                 :            :          * respect to the above issues PULL command.
     880                 :            :          */
     881         [ #  # ]:          0 :         while (!is_last) {
     882                 :            :                 /* Check if the previous issued command is completed.
     883                 :            :                  * Also seems like the SWP is shared between the Ethernet Driver
     884                 :            :                  * and the SEC driver.
     885                 :            :                  */
     886         [ #  # ]:          0 :                 while (!qbman_check_command_complete(dq_storage))
     887                 :            :                         ;
     888                 :            : 
     889                 :            :                 /* Loop until the dq_storage is updated with
     890                 :            :                  * new token by QBMAN
     891                 :            :                  */
     892         [ #  # ]:          0 :                 while (!qbman_check_new_result(dq_storage))
     893                 :            :                         ;
     894                 :            :                 /* Check whether Last Pull command is Expired and
     895                 :            :                  * setting Condition for Loop termination
     896                 :            :                  */
     897         [ #  # ]:          0 :                 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
     898                 :            :                         is_last = 1;
     899                 :            :                         /* Check for valid frame. */
     900                 :          0 :                         status = (uint8_t)qbman_result_DQ_flags(dq_storage);
     901         [ #  # ]:          0 :                         if (unlikely(
     902                 :            :                                 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
     903                 :            :                                 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
     904                 :          0 :                                 continue;
     905                 :            :                         }
     906                 :            :                 }
     907                 :            : 
     908                 :          0 :                 fd = qbman_result_DQ_fd(dq_storage);
     909                 :          0 :                 user_data = sec_fd_to_userdata(fd);
     910         [ #  # ]:          0 :                 if (is_user_data_array)
     911                 :          0 :                         out_user_data[num_rx] = user_data;
     912                 :            :                 else
     913                 :          0 :                         out_user_data[0] = user_data;
     914         [ #  # ]:          0 :                 if (unlikely(fd->simple.frc)) {
     915                 :            :                         /* TODO Parse SEC errors */
     916                 :          0 :                         DPAA2_SEC_ERR("SEC returned Error - %x",
     917                 :            :                                       fd->simple.frc);
     918                 :            :                         is_success = false;
     919                 :            :                 } else {
     920                 :            :                         is_success = true;
     921                 :            :                 }
     922                 :          0 :                 post_dequeue(user_data, num_rx, is_success);
     923                 :            : 
     924                 :          0 :                 num_rx++;
     925                 :          0 :                 dq_storage++;
     926                 :            :         } /* End of Packet Rx loop */
     927                 :            : 
     928                 :          0 :         dpaa2_qp->rx_vq.rx_pkts += num_rx;
     929                 :          0 :         *dequeue_status = 1;
     930                 :          0 :         *n_success = num_rx;
     931                 :            : 
     932                 :            :         DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
     933                 :            :         /*Return the total number of packets received to DPAA2 app*/
     934                 :          0 :         return num_rx;
     935                 :            : }
     936                 :            : 
     937                 :            : static __rte_always_inline void *
     938                 :          0 : dpaa2_sec_raw_dequeue(void *qp_data, uint8_t *drv_ctx, int *dequeue_status,
     939                 :            :                 enum rte_crypto_op_status *op_status)
     940                 :            : {
     941                 :            :         RTE_SET_USED(qp_data);
     942                 :            :         RTE_SET_USED(drv_ctx);
     943                 :            :         RTE_SET_USED(dequeue_status);
     944                 :            :         RTE_SET_USED(op_status);
     945                 :            : 
     946                 :          0 :         return NULL;
     947                 :            : }
     948                 :            : 
     949                 :            : static __rte_always_inline int
     950                 :          0 : dpaa2_sec_raw_enqueue_done(void *qp_data, uint8_t *drv_ctx, uint32_t n)
     951                 :            : {
     952                 :            :         RTE_SET_USED(qp_data);
     953                 :            :         RTE_SET_USED(drv_ctx);
     954                 :            :         RTE_SET_USED(n);
     955                 :            : 
     956                 :          0 :         return 0;
     957                 :            : }
     958                 :            : 
     959                 :            : static __rte_always_inline int
     960                 :          0 : dpaa2_sec_raw_dequeue_done(void *qp_data, uint8_t *drv_ctx, uint32_t n)
     961                 :            : {
     962                 :            :         RTE_SET_USED(qp_data);
     963                 :            :         RTE_SET_USED(drv_ctx);
     964                 :            :         RTE_SET_USED(n);
     965                 :            : 
     966                 :          0 :         return 0;
     967                 :            : }
     968                 :            : 
     969                 :            : int
     970                 :          0 : dpaa2_sec_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
     971                 :            :         struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
     972                 :            :         enum rte_crypto_op_sess_type sess_type,
     973                 :            :         union rte_cryptodev_session_ctx session_ctx, uint8_t is_update)
     974                 :            : {
     975                 :            :         dpaa2_sec_session *sess;
     976                 :            :         struct dpaa2_sec_raw_dp_ctx *dp_ctx;
     977                 :            :         RTE_SET_USED(qp_id);
     978                 :            : 
     979         [ #  # ]:          0 :         if (!is_update) {
     980                 :            :                 memset(raw_dp_ctx, 0, sizeof(*raw_dp_ctx));
     981                 :          0 :                 raw_dp_ctx->qp_data = dev->data->queue_pairs[qp_id];
     982                 :            :         }
     983                 :            : 
     984         [ #  # ]:          0 :         if (sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
     985                 :          0 :                 sess = SECURITY_GET_SESS_PRIV(session_ctx.sec_sess);
     986         [ #  # ]:          0 :         else if (sess_type == RTE_CRYPTO_OP_WITH_SESSION)
     987                 :          0 :                 sess = CRYPTODEV_GET_SYM_SESS_PRIV(session_ctx.crypto_sess);
     988                 :            :         else
     989                 :            :                 return -ENOTSUP;
     990                 :          0 :         raw_dp_ctx->dequeue_burst = dpaa2_sec_raw_dequeue_burst;
     991                 :          0 :         raw_dp_ctx->dequeue = dpaa2_sec_raw_dequeue;
     992                 :          0 :         raw_dp_ctx->dequeue_done = dpaa2_sec_raw_dequeue_done;
     993                 :          0 :         raw_dp_ctx->enqueue_burst = dpaa2_sec_raw_enqueue_burst;
     994                 :          0 :         raw_dp_ctx->enqueue = dpaa2_sec_raw_enqueue;
     995                 :          0 :         raw_dp_ctx->enqueue_done = dpaa2_sec_raw_enqueue_done;
     996                 :            : 
     997         [ #  # ]:          0 :         if (sess->ctxt_type == DPAA2_SEC_CIPHER_HASH)
     998                 :          0 :                 sess->build_raw_dp_fd = build_raw_dp_chain_fd;
     999         [ #  # ]:          0 :         else if (sess->ctxt_type == DPAA2_SEC_AEAD)
    1000                 :          0 :                 sess->build_raw_dp_fd = build_raw_dp_aead_fd;
    1001         [ #  # ]:          0 :         else if (sess->ctxt_type == DPAA2_SEC_AUTH)
    1002                 :          0 :                 sess->build_raw_dp_fd = build_raw_dp_auth_fd;
    1003         [ #  # ]:          0 :         else if (sess->ctxt_type == DPAA2_SEC_CIPHER)
    1004                 :          0 :                 sess->build_raw_dp_fd = build_raw_dp_cipher_fd;
    1005         [ #  # ]:          0 :         else if (sess->ctxt_type == DPAA2_SEC_IPSEC ||
    1006                 :            :                 sess->ctxt_type == DPAA2_SEC_PDCP)
    1007                 :          0 :                 sess->build_raw_dp_fd = build_raw_dp_proto_fd;
    1008                 :            :         else
    1009                 :            :                 return -ENOTSUP;
    1010                 :            :         dp_ctx = (struct dpaa2_sec_raw_dp_ctx *)raw_dp_ctx->drv_ctx_data;
    1011                 :          0 :         dp_ctx->session = sess;
    1012                 :            : 
    1013                 :          0 :         return 0;
    1014                 :            : }
    1015                 :            : 
    1016                 :            : int
    1017                 :          0 : dpaa2_sec_get_dp_ctx_size(__rte_unused struct rte_cryptodev *dev)
    1018                 :            : {
    1019                 :          0 :         return sizeof(struct dpaa2_sec_raw_dp_ctx);
    1020                 :            : }

Generated by: LCOV version 1.14