LCOV - code coverage report
Current view: top level - drivers/crypto/cnxk - cnxk_cryptodev_ops.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 565 0.0 %
Date: 2026-07-01 18:02:41 Functions: 0 36 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 342 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <eal_export.h>
       6                 :            : #include <rte_atomic.h>
       7                 :            : #include <rte_cryptodev.h>
       8                 :            : #include <cryptodev_pmd.h>
       9                 :            : #include <rte_errno.h>
      10                 :            : #ifdef CPT_INST_DEBUG_ENABLE
      11                 :            : #include <rte_hexdump.h>
      12                 :            : #endif
      13                 :            : #include <rte_security_driver.h>
      14                 :            : 
      15                 :            : #include "roc_ae.h"
      16                 :            : #include "roc_ae_fpm_tables.h"
      17                 :            : #include "roc_cpt.h"
      18                 :            : #include "roc_errata.h"
      19                 :            : #include "roc_idev.h"
      20                 :            : #include "roc_ie_on.h"
      21                 :            : #if defined(__aarch64__)
      22                 :            : #include "roc_io.h"
      23                 :            : #else
      24                 :            : #include "roc_io_generic.h"
      25                 :            : #endif
      26                 :            : #include "roc_re_ml_tables.h"
      27                 :            : 
      28                 :            : #include "cnxk_ae.h"
      29                 :            : #include "cnxk_cryptodev.h"
      30                 :            : #include "cnxk_cryptodev_capabilities.h"
      31                 :            : #include "cnxk_cryptodev_ops.h"
      32                 :            : #include "cnxk_se.h"
      33                 :            : 
      34                 :            : #include "cn10k_cryptodev_ops.h"
      35                 :            : #include "cn10k_cryptodev_sec.h"
      36                 :            : #include "cn20k_cryptodev_ops.h"
      37                 :            : #include "cn20k_cryptodev_sec.h"
      38                 :            : #include "cn9k_cryptodev_ops.h"
      39                 :            : #include "cn9k_ipsec.h"
      40                 :            : 
      41                 :            : #include "rte_pmd_cnxk_crypto.h"
      42                 :            : 
      43                 :            : #define CNXK_CPT_MAX_ASYM_OP_NUM_PARAMS  5
      44                 :            : #define CNXK_CPT_MAX_ASYM_OP_MOD_LEN     1024
      45                 :            : 
      46                 :            : /*
      47                 :            :  * PQC requests currently use a shared metabuf region for concatenated input
      48                 :            :  * and output. ML-DSA-87 SIGN requires at least 9523 bytes for private key
      49                 :            :  * input plus signature output, along with additional space for message and
      50                 :            :  * context parameters, so set it for the possible max.
      51                 :            :  */
      52                 :            : #define CNXK_CPT_MAX_ASYM_OP_PQC_LEN     16384
      53                 :            : #define CNXK_CPT_META_BUF_MAX_CACHE_SIZE 128
      54                 :            : 
      55                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P192 == (uint16_t)ROC_AE_EC_ID_P192,
      56                 :            :               "Enum value mismatch");
      57                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P224 == (uint16_t)ROC_AE_EC_ID_P224,
      58                 :            :               "Enum value mismatch");
      59                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P256 == (uint16_t)ROC_AE_EC_ID_P256,
      60                 :            :               "Enum value mismatch");
      61                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P384 == (uint16_t)ROC_AE_EC_ID_P384,
      62                 :            :               "Enum value mismatch");
      63                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P521 == (uint16_t)ROC_AE_EC_ID_P521,
      64                 :            :               "Enum value mismatch");
      65                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P160 == (uint16_t)ROC_AE_EC_ID_P160,
      66                 :            :               "Enum value mismatch");
      67                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P320 == (uint16_t)ROC_AE_EC_ID_P320,
      68                 :            :               "Enum value mismatch");
      69                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_P512 == (uint16_t)ROC_AE_EC_ID_P512,
      70                 :            :               "Enum value mismatch");
      71                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_SM2 == (uint16_t)ROC_AE_EC_ID_SM2,
      72                 :            :               "Enum value mismatch");
      73                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_ED25519 == (uint16_t)ROC_AE_EC_ID_ED25519,
      74                 :            :               "Enum value mismatch");
      75                 :            : static_assert((uint16_t)RTE_PMD_CNXK_AE_EC_ID_ED448 == (uint16_t)ROC_AE_EC_ID_ED448,
      76                 :            :               "Enum value mismatch");
      77                 :            : 
      78                 :            : static int
      79                 :            : cnxk_cpt_get_mlen(void)
      80                 :            : {
      81                 :            :         uint32_t len;
      82                 :            : 
      83                 :            :         /* For MAC */
      84                 :            :         len = 2 * sizeof(uint64_t);
      85                 :            :         len += ROC_SE_MAX_MAC_LEN * sizeof(uint8_t);
      86                 :            : 
      87                 :            :         /* For PDCP_CHAIN passthrough alignment */
      88                 :            :         len += 8;
      89                 :            :         len += ROC_SE_OFF_CTRL_LEN + ROC_CPT_AES_CBC_IV_LEN;
      90                 :            :         len += RTE_ALIGN_CEIL((ROC_SG_LIST_HDR_SIZE +
      91                 :            :                                (RTE_ALIGN_CEIL(ROC_MAX_SG_IN_OUT_CNT, 4) >> 2) * ROC_SG_ENTRY_SIZE),
      92                 :            :                               8);
      93                 :            : 
      94                 :            :         /* Space for discarding AAD bytes from output stream in GCM OOP */
      95                 :            :         len += ROC_SE_MAX_AAD_SIZE;
      96                 :            : 
      97                 :            :         return len;
      98                 :            : }
      99                 :            : 
     100                 :            : static int
     101                 :            : cnxk_cpt_sec_get_mlen(void)
     102                 :            : {
     103                 :            :         uint32_t len;
     104                 :            : 
     105                 :            :         len = ROC_IE_ON_OUTB_DPTR_HDR + ROC_IE_ON_MAX_IV_LEN;
     106                 :            :         len += RTE_ALIGN_CEIL((ROC_SG_LIST_HDR_SIZE +
     107                 :            :                                (RTE_ALIGN_CEIL(ROC_MAX_SG_IN_OUT_CNT, 4) >> 2) * ROC_SG_ENTRY_SIZE),
     108                 :            :                               8);
     109                 :            : 
     110                 :            :         return len;
     111                 :            : }
     112                 :            : 
     113                 :            : int
     114         [ #  # ]:          0 : cnxk_cpt_asym_get_mlen(void)
     115                 :            : {
     116                 :            :         uint32_t len;
     117                 :            : 
     118                 :            :         /* To hold RPTR */
     119                 :            :         len = sizeof(uint64_t);
     120                 :            : 
     121                 :            :         /* Get meta len for asymmetric operations */
     122         [ #  # ]:          0 :         if (roc_model_is_cn20k())
     123                 :            :                 len += CNXK_CPT_MAX_ASYM_OP_PQC_LEN;
     124                 :            :         else
     125                 :            :                 len += CNXK_CPT_MAX_ASYM_OP_NUM_PARAMS * CNXK_CPT_MAX_ASYM_OP_MOD_LEN;
     126                 :            : 
     127                 :          0 :         return len;
     128                 :            : }
     129                 :            : 
     130                 :            : static int
     131                 :          0 : cnxk_cpt_dev_clear(struct rte_cryptodev *dev)
     132                 :            : {
     133                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     134                 :            :         int ret;
     135                 :            : 
     136         [ #  # ]:          0 :         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
     137                 :          0 :                 roc_ae_fpm_put();
     138                 :          0 :                 roc_ae_ec_grp_put();
     139         [ #  # ]:          0 :                 if (roc_model_is_cn20k())
     140                 :          0 :                         roc_re_ml_zeta_put();
     141                 :            :         }
     142                 :            : 
     143                 :          0 :         ret = roc_cpt_int_misc_cb_unregister(cnxk_cpt_int_misc_cb, NULL);
     144         [ #  # ]:          0 :         if (ret < 0) {
     145                 :          0 :                 plt_err("Could not unregister CPT_MISC_INT cb");
     146                 :          0 :                 return ret;
     147                 :            :         }
     148                 :            : 
     149                 :          0 :         roc_cpt_dev_clear(&vf->cpt);
     150                 :            : 
     151                 :          0 :         return 0;
     152                 :            : }
     153                 :            : 
     154                 :            : int
     155                 :          0 : cnxk_cpt_dev_config(struct rte_cryptodev *dev, struct rte_cryptodev_config *conf)
     156                 :            : {
     157                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     158                 :          0 :         struct roc_cpt *roc_cpt = &vf->cpt;
     159                 :            :         uint16_t nb_lf_avail, nb_lf;
     160                 :            :         bool rxc_ena = false;
     161                 :            :         int ret;
     162                 :            : 
     163                 :            :         /* If this is a reconfigure attempt, clear the device and configure again */
     164         [ #  # ]:          0 :         if (roc_cpt->nb_lf > 0) {
     165                 :          0 :                 cnxk_cpt_dev_clear(dev);
     166                 :          0 :                 roc_cpt->opaque = NULL;
     167                 :            :         }
     168                 :            : 
     169                 :          0 :         dev->feature_flags = cnxk_cpt_default_ff_get() & ~conf->ff_disable;
     170                 :            : 
     171                 :          0 :         nb_lf_avail = roc_cpt->nb_lf_avail;
     172                 :          0 :         nb_lf = conf->nb_queue_pairs;
     173                 :            : 
     174         [ #  # ]:          0 :         if (nb_lf > nb_lf_avail)
     175                 :            :                 return -ENOTSUP;
     176                 :            : 
     177         [ #  # ]:          0 :         if (dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT) {
     178         [ #  # ]:          0 :                 if (rte_security_dynfield_register() < 0)
     179                 :            :                         return -ENOTSUP;
     180                 :            :                 rxc_ena = true;
     181                 :          0 :                 vf->rx_chan_base = roc_idev_nix_rx_chan_base_get();
     182                 :            :         }
     183                 :            : 
     184                 :          0 :         ret = roc_cpt_dev_configure(roc_cpt, nb_lf, rxc_ena, vf->rx_inject_qp);
     185         [ #  # ]:          0 :         if (ret) {
     186                 :          0 :                 plt_err("Could not configure device");
     187                 :          0 :                 return ret;
     188                 :            :         }
     189                 :            : 
     190         [ #  # ]:          0 :         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
     191                 :            :                 /* Initialize shared FPM table */
     192                 :          0 :                 ret = roc_ae_fpm_get(vf->cnxk_fpm_iova);
     193         [ #  # ]:          0 :                 if (ret) {
     194                 :          0 :                         plt_err("Could not get FPM table");
     195                 :          0 :                         return ret;
     196                 :            :                 }
     197                 :            : 
     198                 :            :                 /* Init EC grp table */
     199                 :          0 :                 ret = roc_ae_ec_grp_get(vf->ec_grp);
     200         [ #  # ]:          0 :                 if (ret) {
     201                 :          0 :                         plt_err("Could not get EC grp table");
     202                 :          0 :                         goto fpm_put;
     203                 :            :                 }
     204                 :            : 
     205         [ #  # ]:          0 :                 if (roc_model_is_cn20k()) {
     206                 :          0 :                         ret = roc_re_ml_zeta_get(vf->cnxk_ml_iova);
     207         [ #  # ]:          0 :                         if (ret) {
     208                 :          0 :                                 plt_err("Could not initialize RE ML lookup table");
     209                 :          0 :                                 goto ec_grp_put;
     210                 :            :                         }
     211                 :            :                 }
     212                 :            :         }
     213                 :          0 :         roc_cpt->opaque = dev;
     214                 :            :         /* Register callback to handle CPT_MISC_INT */
     215                 :          0 :         roc_cpt_int_misc_cb_register(cnxk_cpt_int_misc_cb, NULL);
     216                 :            : 
     217                 :          0 :         return 0;
     218                 :            : 
     219                 :            : ec_grp_put:
     220                 :          0 :         roc_ae_ec_grp_put();
     221                 :          0 : fpm_put:
     222                 :          0 :         roc_ae_fpm_put();
     223                 :          0 :         return ret;
     224                 :            : }
     225                 :            : 
     226                 :            : int
     227                 :          0 : cnxk_cpt_dev_start(struct rte_cryptodev *dev)
     228                 :            : {
     229                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     230                 :            :         struct roc_cpt *roc_cpt = &vf->cpt;
     231                 :          0 :         uint16_t nb_lf = roc_cpt->nb_lf;
     232                 :            :         struct roc_cpt_lf *lf;
     233                 :            :         uint16_t qp_id;
     234                 :            : 
     235         [ #  # ]:          0 :         for (qp_id = 0; qp_id < nb_lf; qp_id++) {
     236                 :          0 :                 lf = vf->cpt.lf[qp_id];
     237                 :            : 
     238                 :            :                 /* Application may not setup all queue pair */
     239         [ #  # ]:          0 :                 if (lf == NULL)
     240                 :          0 :                         continue;
     241                 :            : 
     242                 :          0 :                 roc_cpt_iq_enable(lf);
     243         [ #  # ]:          0 :                 if (lf->cpt_cq_ena)
     244                 :          0 :                         roc_cpt_cq_enable(lf);
     245                 :            :         }
     246                 :            : 
     247                 :          0 :         return 0;
     248                 :            : }
     249                 :            : 
     250                 :            : void
     251                 :          0 : cnxk_cpt_dev_stop(struct rte_cryptodev *dev)
     252                 :            : {
     253                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     254                 :            :         struct roc_cpt *roc_cpt = &vf->cpt;
     255                 :          0 :         uint16_t nb_lf = roc_cpt->nb_lf;
     256                 :            :         struct roc_cpt_lf *lf;
     257                 :            :         uint16_t qp_id;
     258                 :            : 
     259         [ #  # ]:          0 :         for (qp_id = 0; qp_id < nb_lf; qp_id++) {
     260                 :          0 :                 lf = vf->cpt.lf[qp_id];
     261         [ #  # ]:          0 :                 if (lf == NULL)
     262                 :          0 :                         continue;
     263                 :            : 
     264                 :          0 :                 roc_cpt_iq_disable(roc_cpt->lf[qp_id]);
     265         [ #  # ]:          0 :                 if (lf->cpt_cq_ena)
     266                 :          0 :                         roc_cpt_cq_disable(lf);
     267                 :            :         }
     268                 :          0 : }
     269                 :            : 
     270                 :            : int
     271                 :          0 : cnxk_cpt_dev_close(struct rte_cryptodev *dev)
     272                 :            : {
     273                 :            :         uint16_t i;
     274                 :            :         int ret;
     275                 :            : 
     276         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_queue_pairs; i++) {
     277                 :          0 :                 ret = cnxk_cpt_queue_pair_release(dev, i);
     278         [ #  # ]:          0 :                 if (ret < 0) {
     279                 :          0 :                         plt_err("Could not release queue pair %u", i);
     280                 :          0 :                         return ret;
     281                 :            :                 }
     282                 :            :         }
     283                 :            : 
     284                 :          0 :         return cnxk_cpt_dev_clear(dev);
     285                 :            : }
     286                 :            : 
     287                 :            : void
     288                 :          0 : cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
     289                 :            :                       struct rte_cryptodev_info *info)
     290                 :            : {
     291                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     292                 :            :         struct roc_cpt *roc_cpt = &vf->cpt;
     293                 :            : 
     294                 :          0 :         info->max_nb_queue_pairs =
     295                 :          0 :                 RTE_MIN(roc_cpt->nb_lf_avail, vf->max_qps_limit);
     296                 :          0 :         plt_cpt_dbg("max_nb_queue_pairs %u", info->max_nb_queue_pairs);
     297                 :            : 
     298                 :          0 :         info->feature_flags = cnxk_cpt_default_ff_get();
     299                 :          0 :         info->capabilities = cnxk_crypto_capabilities_get(vf);
     300                 :          0 :         info->sym.max_nb_sessions = 0;
     301                 :          0 :         info->min_mbuf_headroom_req = CNXK_CPT_MIN_HEADROOM_REQ;
     302                 :          0 :         info->min_mbuf_tailroom_req = CNXK_CPT_MIN_TAILROOM_REQ;
     303                 :            : 
     304                 :            :         /* If the LF ID for RX Inject is less than the available lfs. */
     305         [ #  # ]:          0 :         if (vf->rx_inject_qp > info->max_nb_queue_pairs)
     306                 :          0 :                 info->feature_flags &= ~RTE_CRYPTODEV_FF_SECURITY_RX_INJECT;
     307                 :          0 : }
     308                 :            : 
     309                 :            : static void
     310                 :            : qp_memzone_name_get(char *name, int size, int dev_id, int qp_id)
     311                 :            : {
     312                 :            :         snprintf(name, size, "cnxk_cpt_pq_mem_%u:%u", dev_id, qp_id);
     313                 :            : }
     314                 :            : 
     315                 :            : static int
     316                 :          0 : cnxk_cpt_metabuf_mempool_create(const struct rte_cryptodev *dev,
     317                 :            :                                 struct cnxk_cpt_qp *qp, uint8_t qp_id,
     318                 :            :                                 uint32_t nb_elements)
     319                 :            : {
     320                 :            :         char mempool_name[RTE_MEMPOOL_NAMESIZE];
     321                 :            :         struct cpt_qp_meta_info *meta_info;
     322                 :          0 :         int lcore_cnt = rte_lcore_count();
     323                 :            :         struct rte_mempool *pool;
     324                 :            :         int mb_pool_sz, mlen = 8;
     325                 :            :         uint32_t cache_sz;
     326                 :            : 
     327         [ #  # ]:          0 :         if (dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
     328                 :            :                 /* Get meta len */
     329                 :            :                 mlen = cnxk_cpt_get_mlen();
     330                 :            :         }
     331                 :            : 
     332         [ #  # ]:          0 :         if (dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY) {
     333                 :            :                 /* Get meta len for security operations */
     334                 :            :                 mlen = cnxk_cpt_sec_get_mlen();
     335                 :            :         }
     336                 :            : 
     337         [ #  # ]:          0 :         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
     338                 :            : 
     339                 :            :                 /* Get meta len required for asymmetric operations */
     340                 :          0 :                 mlen = RTE_MAX(mlen, cnxk_cpt_asym_get_mlen());
     341                 :            :         }
     342                 :            : 
     343                 :            :         mb_pool_sz = nb_elements;
     344         [ #  # ]:          0 :         cache_sz = RTE_MIN(CNXK_CPT_META_BUF_MAX_CACHE_SIZE, nb_elements / 1.5);
     345                 :            : 
     346                 :            :         /* For poll mode, core that enqueues and core that dequeues can be
     347                 :            :          * different. For event mode, all cores are allowed to use same crypto
     348                 :            :          * queue pair.
     349                 :            :          */
     350                 :            : 
     351                 :          0 :         mb_pool_sz += (RTE_MAX(2, lcore_cnt) * cache_sz);
     352                 :            : 
     353                 :            :         /* Allocate mempool */
     354                 :            : 
     355                 :          0 :         snprintf(mempool_name, RTE_MEMPOOL_NAMESIZE, "cnxk_cpt_mb_%u:%u",
     356                 :          0 :                  dev->data->dev_id, qp_id);
     357                 :            : 
     358                 :          0 :         pool = rte_mempool_create(mempool_name, mb_pool_sz, mlen, cache_sz, 0,
     359                 :          0 :                                   NULL, NULL, NULL, NULL, rte_socket_id(), 0);
     360                 :            : 
     361         [ #  # ]:          0 :         if (pool == NULL) {
     362                 :          0 :                 plt_err("Could not create mempool for metabuf");
     363                 :          0 :                 return rte_errno;
     364                 :            :         }
     365                 :            : 
     366                 :            :         meta_info = &qp->meta_info;
     367                 :            : 
     368                 :          0 :         meta_info->pool = pool;
     369                 :          0 :         meta_info->mlen = mlen;
     370                 :            : 
     371                 :          0 :         return 0;
     372                 :            : }
     373                 :            : 
     374                 :            : static void
     375                 :            : cnxk_cpt_metabuf_mempool_destroy(struct cnxk_cpt_qp *qp)
     376                 :            : {
     377                 :            :         struct cpt_qp_meta_info *meta_info = &qp->meta_info;
     378                 :            : 
     379                 :          0 :         rte_mempool_free(meta_info->pool);
     380                 :            : 
     381                 :          0 :         meta_info->pool = NULL;
     382         [ #  # ]:          0 :         meta_info->mlen = 0;
     383                 :            : }
     384                 :            : 
     385                 :            : static struct cnxk_cpt_qp *
     386                 :          0 : cnxk_cpt_qp_create(const struct rte_cryptodev *dev, uint16_t qp_id,
     387                 :            :                    uint32_t iq_len)
     388                 :            : {
     389                 :            :         const struct rte_memzone *pq_mem = NULL;
     390                 :            :         char name[RTE_MEMZONE_NAMESIZE];
     391                 :            :         struct cnxk_cpt_qp *qp;
     392                 :            :         uint32_t len;
     393                 :            :         uint8_t *va;
     394                 :            :         int ret;
     395                 :            : 
     396                 :            :         /* Allocate queue pair */
     397                 :          0 :         qp = rte_zmalloc_socket("CNXK Crypto PMD Queue Pair", sizeof(*qp),
     398                 :            :                                 ROC_ALIGN, 0);
     399         [ #  # ]:          0 :         if (qp == NULL) {
     400                 :          0 :                 plt_err("Could not allocate queue pair");
     401                 :          0 :                 return NULL;
     402                 :            :         }
     403                 :            : 
     404                 :            :         /* For pending queue */
     405         [ #  # ]:          0 :         if (!roc_model_is_cn20k()) {
     406                 :          0 :                 len = iq_len * sizeof(struct cpt_inflight_req);
     407                 :            : 
     408                 :          0 :                 qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id, qp_id);
     409                 :            : 
     410                 :          0 :                 pq_mem = rte_memzone_reserve_aligned(name, len, rte_socket_id(),
     411                 :            :                                                      RTE_MEMZONE_SIZE_HINT_ONLY | RTE_MEMZONE_256MB,
     412                 :            :                                                      RTE_CACHE_LINE_SIZE);
     413         [ #  # ]:          0 :                 if (pq_mem == NULL) {
     414                 :          0 :                         plt_err("Could not allocate reserved memzone");
     415                 :          0 :                         goto qp_free;
     416                 :            :                 }
     417                 :            : 
     418                 :          0 :                 va = pq_mem->addr;
     419                 :            : 
     420                 :            :                 memset(va, 0, len);
     421                 :            : 
     422                 :          0 :                 qp->pend_q.req_queue = pq_mem->addr;
     423                 :            :         }
     424                 :            : 
     425                 :          0 :         ret = cnxk_cpt_metabuf_mempool_create(dev, qp, qp_id, iq_len);
     426         [ #  # ]:          0 :         if (ret) {
     427                 :          0 :                 plt_err("Could not create mempool for metabuf");
     428         [ #  # ]:          0 :                 goto pq_mem_free;
     429                 :            :         }
     430                 :            : 
     431                 :            :         /* Initialize pending queue */
     432                 :          0 :         qp->pend_q.head = 0;
     433                 :          0 :         qp->pend_q.tail = 0;
     434                 :            : 
     435                 :          0 :         return qp;
     436                 :            : 
     437                 :            : pq_mem_free:
     438         [ #  # ]:          0 :         if (!roc_model_is_cn20k())
     439                 :          0 :                 rte_memzone_free(pq_mem);
     440                 :          0 : qp_free:
     441                 :          0 :         rte_free(qp);
     442                 :          0 :         return NULL;
     443                 :            : }
     444                 :            : 
     445                 :            : static int
     446                 :          0 : cnxk_cpt_qp_destroy(const struct rte_cryptodev *dev, struct cnxk_cpt_qp *qp)
     447                 :            : {
     448                 :            :         const struct rte_memzone *pq_mem;
     449                 :            :         char name[RTE_MEMZONE_NAMESIZE];
     450                 :            :         int ret;
     451                 :            : 
     452                 :            :         cnxk_cpt_metabuf_mempool_destroy(qp);
     453                 :            : 
     454         [ #  # ]:          0 :         if (!roc_model_is_cn20k()) {
     455                 :          0 :                 qp_memzone_name_get(name, RTE_MEMZONE_NAMESIZE, dev->data->dev_id, qp->lf.lf_id);
     456                 :            : 
     457                 :          0 :                 pq_mem = rte_memzone_lookup(name);
     458                 :            : 
     459                 :          0 :                 ret = rte_memzone_free(pq_mem);
     460         [ #  # ]:          0 :                 if (ret)
     461                 :            :                         return ret;
     462                 :            :         }
     463                 :            : 
     464                 :          0 :         rte_free(qp);
     465                 :            : 
     466                 :          0 :         return 0;
     467                 :            : }
     468                 :            : 
     469                 :            : int
     470                 :          0 : cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id)
     471                 :            : {
     472                 :          0 :         struct cnxk_cpt_qp *qp = dev->data->queue_pairs[qp_id];
     473                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     474                 :            :         struct roc_cpt *roc_cpt = &vf->cpt;
     475                 :            :         struct roc_cpt_lf *lf;
     476                 :            :         int ret;
     477                 :            : 
     478         [ #  # ]:          0 :         if (qp == NULL)
     479                 :            :                 return -EINVAL;
     480                 :            : 
     481                 :          0 :         lf = roc_cpt->lf[qp_id];
     482         [ #  # ]:          0 :         if (lf == NULL)
     483                 :            :                 return -ENOTSUP;
     484                 :            : 
     485                 :          0 :         roc_cpt_lf_fini(lf);
     486                 :            : 
     487                 :          0 :         ret = cnxk_cpt_qp_destroy(dev, qp);
     488         [ #  # ]:          0 :         if (ret) {
     489                 :          0 :                 plt_err("Could not destroy queue pair %d", qp_id);
     490                 :          0 :                 return ret;
     491                 :            :         }
     492                 :            : 
     493                 :          0 :         roc_cpt->lf[qp_id] = NULL;
     494                 :          0 :         dev->data->queue_pairs[qp_id] = NULL;
     495                 :            : 
     496                 :          0 :         return 0;
     497                 :            : }
     498                 :            : 
     499                 :            : int
     500                 :          0 : cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
     501                 :            :                           const struct rte_cryptodev_qp_conf *conf,
     502                 :            :                           int socket_id __rte_unused)
     503                 :            : {
     504                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     505                 :          0 :         struct roc_cpt *roc_cpt = &vf->cpt;
     506                 :            :         struct rte_pci_device *pci_dev;
     507                 :            :         struct cnxk_cpt_qp *qp;
     508                 :            :         uint32_t nb_desc;
     509                 :            :         int ret;
     510                 :            : 
     511         [ #  # ]:          0 :         if (dev->data->queue_pairs[qp_id] != NULL)
     512                 :          0 :                 cnxk_cpt_queue_pair_release(dev, qp_id);
     513                 :            : 
     514                 :          0 :         pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
     515                 :            : 
     516         [ #  # ]:          0 :         if (pci_dev->mem_resource[2].addr == NULL) {
     517                 :          0 :                 plt_err("Invalid PCI mem address");
     518                 :          0 :                 return -EIO;
     519                 :            :         }
     520                 :            : 
     521                 :            :         /* Update nb_desc to next power of 2 to aid in pending queue checks */
     522                 :          0 :         nb_desc = plt_align32pow2(conf->nb_descriptors);
     523                 :            : 
     524                 :          0 :         qp = cnxk_cpt_qp_create(dev, qp_id, nb_desc);
     525         [ #  # ]:          0 :         if (qp == NULL) {
     526                 :          0 :                 plt_err("Could not create queue pair %d", qp_id);
     527                 :          0 :                 return -ENOMEM;
     528                 :            :         }
     529                 :            : 
     530                 :          0 :         qp->lf.lf_id = qp_id;
     531         [ #  # ]:          0 :         qp->lf.nb_desc = nb_desc;
     532         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
     533                 :          0 :                 qp->lf.cpt_cq_ena = true;
     534                 :          0 :                 qp->lf.dq_ack_ena = false;
     535                 :            :                 /* CQ entry size is 128B(32 << 2) */
     536                 :          0 :                 qp->lf.cq_entry_size = 2;
     537                 :          0 :                 qp->lf.cq_size = nb_desc;
     538                 :            :         }
     539                 :            : 
     540                 :          0 :         ret = roc_cpt_lf_init(roc_cpt, &qp->lf);
     541         [ #  # ]:          0 :         if (ret < 0) {
     542                 :          0 :                 plt_err("Could not initialize queue pair %d", qp_id);
     543                 :            :                 ret = -EINVAL;
     544                 :          0 :                 goto exit;
     545                 :            :         }
     546                 :            : 
     547         [ #  # ]:          0 :         qp->pend_q.pq_mask = qp->lf.nb_desc - 1;
     548                 :            : 
     549         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
     550         [ #  # ]:          0 :                 if (qp->lf.cq_vaddr == NULL) {
     551                 :          0 :                         plt_err("Could not initialize completion queue");
     552                 :            :                         ret = -EINVAL;
     553                 :          0 :                         goto exit;
     554                 :            :                 }
     555                 :            : 
     556                 :          0 :                 qp->pend_q.req_queue = PLT_PTR_ADD(
     557                 :            :                         qp->lf.cq_vaddr, ROC_CPT_CQ_ENTRY_SIZE_UNIT << qp->lf.cq_entry_size);
     558                 :            :         }
     559                 :            : 
     560                 :          0 :         roc_cpt->lf[qp_id] = &qp->lf;
     561                 :            : 
     562                 :          0 :         ret = roc_cpt_lmtline_init(roc_cpt, &qp->lmtline, qp_id, true);
     563         [ #  # ]:          0 :         if (ret < 0) {
     564                 :          0 :                 roc_cpt->lf[qp_id] = NULL;
     565                 :          0 :                 plt_err("Could not init lmtline for queue pair %d", qp_id);
     566                 :          0 :                 goto exit;
     567                 :            :         }
     568                 :            : 
     569                 :          0 :         qp->sess_mp = conf->mp_session;
     570                 :          0 :         dev->data->queue_pairs[qp_id] = qp;
     571                 :            : 
     572         [ #  # ]:          0 :         if (qp_id == vf->rx_inject_qp) {
     573                 :          0 :                 ret = roc_cpt_lmtline_init(roc_cpt, &vf->rx_inj_lmtline, vf->rx_inject_qp, true);
     574         [ #  # ]:          0 :                 if (ret) {
     575                 :          0 :                         plt_err("Could not init lmtline Rx inject");
     576                 :          0 :                         goto exit;
     577                 :            :                 }
     578                 :            : 
     579                 :          0 :                 vf->rx_inj_sso_pf_func = roc_idev_nix_inl_dev_pffunc_get();
     580                 :            : 
     581                 :            :                 /* Block the queue for other submissions */
     582                 :          0 :                 qp->pend_q.pq_mask = 0;
     583                 :            :         }
     584                 :            : 
     585                 :            :         return 0;
     586                 :            : 
     587                 :          0 : exit:
     588                 :          0 :         cnxk_cpt_qp_destroy(dev, qp);
     589                 :          0 :         return ret;
     590                 :            : }
     591                 :            : 
     592                 :            : int
     593                 :          0 : cnxk_cpt_queue_pair_reset(struct rte_cryptodev *dev, uint16_t qp_id,
     594                 :            :                           const struct rte_cryptodev_qp_conf *conf, int socket_id)
     595                 :            : {
     596         [ #  # ]:          0 :         if (conf == NULL) {
     597                 :          0 :                 struct cnxk_cpt_vf *vf = dev->data->dev_private;
     598                 :            :                 struct roc_cpt_lf *lf;
     599                 :            : 
     600         [ #  # ]:          0 :                 if (vf == NULL)
     601                 :            :                         return -ENOTSUP;
     602                 :            : 
     603                 :          0 :                 lf = vf->cpt.lf[qp_id];
     604                 :          0 :                 roc_cpt_lf_reset(lf);
     605                 :          0 :                 roc_cpt_iq_enable(lf);
     606                 :            : 
     607         [ #  # ]:          0 :                 if (lf->cpt_cq_ena)
     608                 :          0 :                         roc_cpt_cq_enable(lf);
     609                 :            : 
     610                 :          0 :                 return 0;
     611                 :            :         }
     612                 :            : 
     613                 :          0 :         return cnxk_cpt_queue_pair_setup(dev, qp_id, conf, socket_id);
     614                 :            : }
     615                 :            : 
     616                 :            : uint32_t
     617                 :          0 : cnxk_cpt_qp_depth_used(void *qptr)
     618                 :            : {
     619                 :            :         struct cnxk_cpt_qp *qp = qptr;
     620                 :            :         struct pending_queue *pend_q;
     621                 :            :         union cpt_fc_write_s fc;
     622                 :            : 
     623                 :            :         pend_q = &qp->pend_q;
     624                 :            : 
     625                 :          0 :         fc.u64[0] = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t)*)(qp->lmtline.fc_addr),
     626                 :            :                         rte_memory_order_relaxed);
     627                 :            : 
     628                 :          0 :         return RTE_MAX(pending_queue_infl_cnt(pend_q->head, pend_q->tail, pend_q->pq_mask),
     629                 :            :                        fc.s.qsize);
     630                 :            : }
     631                 :            : 
     632                 :            : unsigned int
     633                 :          0 : cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
     634                 :            : {
     635                 :          0 :         return sizeof(struct cnxk_se_sess);
     636                 :            : }
     637                 :            : 
     638                 :            : static bool
     639                 :            : is_valid_pdcp_cipher_alg(struct rte_crypto_sym_xform *c_xfrm,
     640                 :            :                          struct cnxk_se_sess *sess)
     641                 :            : {
     642   [ #  #  #  #  :          0 :         switch (c_xfrm->cipher.algo) {
                   #  # ]
     643                 :            :         case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
     644                 :            :         case RTE_CRYPTO_CIPHER_SNOW5G_NEA4:
     645                 :            :         case RTE_CRYPTO_CIPHER_ZUC_EEA3:
     646                 :            :                 break;
     647                 :          0 :         case RTE_CRYPTO_CIPHER_AES_CTR:
     648                 :          0 :                 sess->aes_ctr_eea2 = 1;
     649                 :            :                 break;
     650                 :            :         default:
     651                 :            :                 return false;
     652                 :            :         }
     653                 :            : 
     654                 :            :         return true;
     655                 :            : }
     656                 :            : 
     657                 :            : static int
     658         [ #  # ]:          0 : cnxk_sess_fill(struct roc_cpt *roc_cpt, struct rte_crypto_sym_xform *xform,
     659                 :            :                struct cnxk_se_sess *sess)
     660                 :            : {
     661                 :            :         struct rte_crypto_sym_xform *aead_xfrm = NULL;
     662                 :            :         struct rte_crypto_sym_xform *c_xfrm = NULL;
     663                 :            :         struct rte_crypto_sym_xform *a_xfrm = NULL;
     664                 :            :         bool ciph_then_auth = false;
     665                 :            : 
     666         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
     667                 :          0 :                 sess->roc_se_ctx->pdcp_iv_len = 40;
     668                 :          0 :                 sess->roc_se_ctx->pdcp_iv_offset = 16;
     669         [ #  # ]:          0 :         } else if (roc_cpt->hw_caps[CPT_ENG_TYPE_SE].pdcp_chain_zuc256) {
     670                 :          0 :                 sess->roc_se_ctx->pdcp_iv_offset = 24;
     671                 :          0 :                 sess->roc_se_ctx->pdcp_iv_len = 48;
     672                 :            :         } else {
     673                 :          0 :                 sess->roc_se_ctx->pdcp_iv_offset = 16;
     674                 :          0 :                 sess->roc_se_ctx->pdcp_iv_len = 32;
     675                 :            :         }
     676                 :            : 
     677         [ #  # ]:          0 :         if (xform == NULL)
     678                 :            :                 return -EINVAL;
     679                 :            : 
     680         [ #  # ]:          0 :         if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
     681                 :            :                 c_xfrm = xform;
     682                 :          0 :                 a_xfrm = xform->next;
     683                 :            :                 ciph_then_auth = true;
     684         [ #  # ]:          0 :         } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
     685                 :          0 :                 c_xfrm = xform->next;
     686                 :            :                 a_xfrm = xform;
     687                 :            :                 ciph_then_auth = false;
     688                 :            :         } else {
     689                 :            :                 aead_xfrm = xform;
     690                 :            :         }
     691                 :            : 
     692   [ #  #  #  # ]:          0 :         if (c_xfrm != NULL && c_xfrm->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
     693                 :          0 :                 plt_dp_err("Invalid type in cipher xform");
     694                 :          0 :                 return -EINVAL;
     695                 :            :         }
     696                 :            : 
     697   [ #  #  #  # ]:          0 :         if (a_xfrm != NULL && a_xfrm->type != RTE_CRYPTO_SYM_XFORM_AUTH) {
     698                 :          0 :                 plt_dp_err("Invalid type in auth xform");
     699                 :          0 :                 return -EINVAL;
     700                 :            :         }
     701                 :            : 
     702   [ #  #  #  # ]:          0 :         if (aead_xfrm != NULL && aead_xfrm->type != RTE_CRYPTO_SYM_XFORM_AEAD) {
     703                 :          0 :                 plt_dp_err("Invalid type in AEAD xform");
     704                 :          0 :                 return -EINVAL;
     705                 :            :         }
     706                 :            : 
     707   [ #  #  #  # ]:          0 :         if ((aead_xfrm == NULL) &&
     708   [ #  #  #  # ]:          0 :             (c_xfrm == NULL || c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_NULL) &&
     709         [ #  # ]:          0 :             (a_xfrm == NULL || a_xfrm->auth.algo == RTE_CRYPTO_AUTH_NULL))
     710                 :          0 :                 sess->passthrough = 1;
     711                 :            : 
     712                 :            :         /* Cipher only */
     713   [ #  #  #  #  :          0 :         if (c_xfrm != NULL && (a_xfrm == NULL || a_xfrm->auth.algo == RTE_CRYPTO_AUTH_NULL)) {
                   #  # ]
     714                 :            :                 if (fill_sess_cipher(c_xfrm, sess))
     715                 :          0 :                         return -ENOTSUP;
     716                 :            :                 else
     717                 :          0 :                         return 0;
     718                 :            :         }
     719                 :            : 
     720                 :            :         /* Auth only */
     721   [ #  #  #  # ]:          0 :         if (a_xfrm != NULL &&
     722         [ #  # ]:          0 :             (c_xfrm == NULL || c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_NULL)) {
     723                 :            :                 if (fill_sess_auth(a_xfrm, sess))
     724                 :          0 :                         return -ENOTSUP;
     725                 :            :                 else
     726                 :          0 :                         return 0;
     727                 :            :         }
     728                 :            : 
     729                 :            :         /* AEAD */
     730         [ #  # ]:          0 :         if (aead_xfrm != NULL) {
     731                 :            :                 if (fill_sess_aead(aead_xfrm, sess))
     732                 :          0 :                         return -ENOTSUP;
     733                 :            :                 else
     734                 :          0 :                         return 0;
     735                 :            :         }
     736                 :            : 
     737                 :            :         /* Chained ops */
     738         [ #  # ]:          0 :         if (c_xfrm == NULL || a_xfrm == NULL) {
     739                 :          0 :                 plt_dp_err("Invalid xforms");
     740                 :          0 :                 return -EINVAL;
     741                 :            :         }
     742                 :            : 
     743         [ #  # ]:          0 :         if (c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_AES_XTS) {
     744                 :          0 :                 plt_err("AES XTS with auth algorithm is not supported");
     745                 :          0 :                 return -ENOTSUP;
     746                 :            :         }
     747                 :            : 
     748         [ #  # ]:          0 :         if (c_xfrm->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC &&
     749         [ #  # ]:          0 :             a_xfrm->auth.algo == RTE_CRYPTO_AUTH_SHA1) {
     750                 :          0 :                 plt_dp_err("3DES-CBC + SHA1 is not supported");
     751                 :          0 :                 return -ENOTSUP;
     752                 :            :         }
     753                 :            : 
     754                 :            :         /* Cipher then auth */
     755         [ #  # ]:          0 :         if (ciph_then_auth) {
     756         [ #  # ]:          0 :                 if (c_xfrm->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
     757         [ #  # ]:          0 :                         if (a_xfrm->auth.op != RTE_CRYPTO_AUTH_OP_VERIFY)
     758                 :            :                                 return -EINVAL;
     759                 :          0 :                         sess->auth_first = 1;
     760      [ #  #  # ]:          0 :                         switch (a_xfrm->auth.algo) {
     761         [ #  # ]:          0 :                         case RTE_CRYPTO_AUTH_SHA1_HMAC:
     762                 :            :                                 switch (c_xfrm->cipher.algo) {
     763                 :            :                                 case RTE_CRYPTO_CIPHER_AES_CBC:
     764                 :            :                                         break;
     765                 :            :                                 default:
     766                 :            :                                         return -ENOTSUP;
     767                 :            :                                 }
     768                 :            :                                 break;
     769                 :            :                         case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
     770                 :            :                         case RTE_CRYPTO_AUTH_SNOW5G_NIA4:
     771                 :            :                         case RTE_CRYPTO_AUTH_ZUC_EIA3:
     772                 :            :                         case RTE_CRYPTO_AUTH_AES_CMAC:
     773                 :            :                                 if (!is_valid_pdcp_cipher_alg(c_xfrm, sess))
     774                 :            :                                         return -ENOTSUP;
     775                 :            :                                 break;
     776                 :            :                         default:
     777                 :            :                                 return -ENOTSUP;
     778                 :            :                         }
     779                 :            :                 }
     780                 :          0 :                 sess->roc_se_ctx->ciph_then_auth = 1;
     781         [ #  # ]:          0 :                 sess->chained_op = 1;
     782                 :            :                 if (fill_sess_cipher(c_xfrm, sess))
     783                 :          0 :                         return -ENOTSUP;
     784                 :            :                 if (fill_sess_auth(a_xfrm, sess))
     785                 :          0 :                         return -ENOTSUP;
     786                 :            :                 else
     787                 :          0 :                         return 0;
     788                 :            :         }
     789                 :            : 
     790                 :            :         /* else */
     791                 :            : 
     792         [ #  # ]:          0 :         if (c_xfrm->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
     793         [ #  # ]:          0 :                 if (a_xfrm->auth.op != RTE_CRYPTO_AUTH_OP_GENERATE)
     794                 :            :                         return -EINVAL;
     795                 :          0 :                 sess->auth_first = 1;
     796      [ #  #  # ]:          0 :                 switch (a_xfrm->auth.algo) {
     797         [ #  # ]:          0 :                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
     798                 :            :                         switch (c_xfrm->cipher.algo) {
     799                 :            :                         case RTE_CRYPTO_CIPHER_AES_CBC:
     800                 :            :                                 break;
     801                 :            :                         default:
     802                 :            :                                 return -ENOTSUP;
     803                 :            :                         }
     804                 :            :                         break;
     805                 :            :                 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
     806                 :            :                 case RTE_CRYPTO_AUTH_SNOW5G_NIA4:
     807                 :            :                 case RTE_CRYPTO_AUTH_ZUC_EIA3:
     808                 :            :                 case RTE_CRYPTO_AUTH_AES_CMAC:
     809                 :            :                         if (!is_valid_pdcp_cipher_alg(c_xfrm, sess))
     810                 :            :                                 return -ENOTSUP;
     811                 :            :                         break;
     812                 :            :                 default:
     813                 :            :                         return -ENOTSUP;
     814                 :            :                 }
     815                 :            :         }
     816                 :            : 
     817                 :          0 :         sess->roc_se_ctx->auth_then_ciph = 1;
     818         [ #  # ]:          0 :         sess->chained_op = 1;
     819                 :            :         if (fill_sess_auth(a_xfrm, sess))
     820                 :          0 :                 return -ENOTSUP;
     821                 :            :         if (fill_sess_cipher(c_xfrm, sess))
     822                 :          0 :                 return -ENOTSUP;
     823                 :            :         else
     824                 :          0 :                 return 0;
     825                 :            : }
     826                 :            : 
     827                 :            : static uint64_t
     828                 :          0 : cnxk_cpt_inst_w7_get(struct cnxk_se_sess *sess, struct roc_cpt *roc_cpt)
     829                 :            : {
     830                 :            :         union cpt_inst_w7 inst_w7;
     831                 :            : 
     832         [ #  # ]:          0 :         if (sess->roc_se_ctx == NULL) {
     833                 :          0 :                 plt_err("Invalid se context");
     834                 :          0 :                 return 0;
     835                 :            :         }
     836                 :            : 
     837         [ #  # ]:          0 :         inst_w7.s.cptr = (uint64_t)&sess->roc_se_ctx->se_ctx;
     838                 :            : 
     839         [ #  # ]:          0 :         if (hw_ctx_cache_enable())
     840                 :          0 :                 inst_w7.s.ctx_val = 1;
     841                 :            :         else
     842                 :          0 :                 inst_w7.s.cptr += 8;
     843                 :            : 
     844                 :            :         /* Set the engine group */
     845         [ #  # ]:          0 :         if (roc_model_is_cn20k())
     846                 :          0 :                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
     847                 :          0 :         else if (sess->zsk_flag || sess->aes_ctr_eea2 || sess->is_sha3 || sess->is_sm3 ||
     848         [ #  # ]:          0 :                  sess->passthrough || sess->is_sm4)
     849                 :          0 :                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_SE];
     850                 :            :         else
     851                 :          0 :                 inst_w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_IE];
     852                 :            : 
     853                 :          0 :         return inst_w7.u64;
     854                 :            : }
     855                 :            : 
     856                 :            : int
     857                 :          0 : sym_session_configure(struct roc_cpt *roc_cpt, struct rte_crypto_sym_xform *xform,
     858                 :            :                       struct rte_cryptodev_sym_session *sess, bool is_session_less)
     859                 :            : {
     860                 :            :         enum cpt_dp_thread_type thr_type;
     861                 :            :         struct cnxk_se_sess *sess_priv = (struct cnxk_se_sess *)sess;
     862                 :            :         int ret;
     863                 :            : 
     864         [ #  # ]:          0 :         if (is_session_less)
     865                 :            :                 memset(sess_priv, 0, sizeof(struct cnxk_se_sess));
     866                 :            : 
     867                 :          0 :         sess_priv->roc_se_ctx =
     868                 :          0 :                 rte_zmalloc("roc_se_ctx", sizeof(struct roc_se_ctx), ROC_CPTR_ALIGN);
     869         [ #  # ]:          0 :         if (sess_priv->roc_se_ctx == NULL) {
     870                 :          0 :                 plt_err("Couldn't allocate memory for se context");
     871                 :          0 :                 return -ENOMEM;
     872                 :            :         }
     873                 :            : 
     874                 :          0 :         ret = cnxk_sess_fill(roc_cpt, xform, sess_priv);
     875         [ #  # ]:          0 :         if (ret)
     876                 :          0 :                 goto priv_put;
     877                 :            : 
     878                 :          0 :         sess_priv->lf = roc_cpt->lf[0];
     879                 :            : 
     880         [ #  # ]:          0 :         if (sess_priv->passthrough)
     881                 :            :                 thr_type = CPT_DP_THREAD_TYPE_PT;
     882         [ #  # ]:          0 :         else if (sess_priv->cpt_op & ROC_SE_OP_CIPHER_MASK) {
     883   [ #  #  #  #  :          0 :                 switch (sess_priv->roc_se_ctx->fc_type) {
                   #  # ]
     884                 :          0 :                 case ROC_SE_FC_GEN:
     885         [ #  # ]:          0 :                         if (sess_priv->aes_gcm || sess_priv->aes_ccm || sess_priv->chacha_poly)
     886                 :            :                                 thr_type = CPT_DP_THREAD_TYPE_FC_AEAD;
     887                 :            :                         else
     888                 :            :                                 thr_type = CPT_DP_THREAD_TYPE_FC_CHAIN;
     889                 :            :                         break;
     890                 :            :                 case ROC_SE_PDCP:
     891                 :            :                         thr_type = CPT_DP_THREAD_TYPE_PDCP;
     892                 :            :                         break;
     893                 :          0 :                 case ROC_SE_KASUMI:
     894                 :            :                         thr_type = CPT_DP_THREAD_TYPE_KASUMI;
     895                 :          0 :                         break;
     896                 :          0 :                 case ROC_SE_PDCP_CHAIN:
     897                 :            :                         thr_type = CPT_DP_THREAD_TYPE_PDCP_CHAIN;
     898                 :          0 :                         break;
     899                 :          0 :                 case ROC_SE_SM:
     900                 :            :                         thr_type = CPT_DP_THREAD_TYPE_SM;
     901                 :          0 :                         break;
     902                 :          0 :                 default:
     903                 :          0 :                         plt_err("Invalid op type");
     904                 :            :                         ret = -ENOTSUP;
     905                 :          0 :                         goto priv_put;
     906                 :            :                 }
     907                 :            :         } else {
     908                 :            :                 thr_type = CPT_DP_THREAD_AUTH_ONLY;
     909                 :            :         }
     910                 :            : 
     911                 :          0 :         sess_priv->dp_thr_type = thr_type;
     912                 :            : 
     913         [ #  # ]:          0 :         if ((sess_priv->roc_se_ctx->fc_type == ROC_SE_HASH_HMAC) &&
     914                 :            :             cpt_mac_len_verify(&xform->auth)) {
     915                 :          0 :                 plt_dp_err("MAC length is not supported");
     916         [ #  # ]:          0 :                 if (sess_priv->roc_se_ctx->auth_key != NULL) {
     917                 :          0 :                         plt_free(sess_priv->roc_se_ctx->auth_key);
     918                 :          0 :                         sess_priv->roc_se_ctx->auth_key = NULL;
     919                 :            :                 }
     920                 :            : 
     921                 :            :                 ret = -ENOTSUP;
     922                 :          0 :                 goto priv_put;
     923                 :            :         }
     924                 :            : 
     925         [ #  # ]:          0 :         sess_priv->cpt_inst_w7 = cnxk_cpt_inst_w7_get(sess_priv, roc_cpt);
     926                 :            : 
     927         [ #  # ]:          0 :         if (hw_ctx_cache_enable())
     928                 :          0 :                 roc_se_ctx_init(sess_priv->roc_se_ctx);
     929                 :            : 
     930         [ #  # ]:          0 :         if (sess_priv->roc_se_ctx->se_ctx.w0.s.ctx_size < roc_cpt->ctx_ilen)
     931                 :          0 :                 sess_priv->roc_se_ctx->se_ctx.w0.s.ctx_size = roc_cpt->ctx_ilen;
     932                 :            : 
     933                 :            :         return 0;
     934                 :            : 
     935                 :          0 : priv_put:
     936         [ #  # ]:          0 :         if (sess_priv->roc_se_ctx != NULL) {
     937                 :          0 :                 rte_free(sess_priv->roc_se_ctx);
     938                 :          0 :                 sess_priv->roc_se_ctx = NULL;
     939                 :            :         }
     940                 :            :         return ret;
     941                 :            : }
     942                 :            : 
     943                 :            : int
     944                 :          0 : cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev,
     945                 :            :                                struct rte_crypto_sym_xform *xform,
     946                 :            :                                struct rte_cryptodev_sym_session *sess)
     947                 :            : {
     948                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
     949                 :          0 :         struct roc_cpt *roc_cpt = &vf->cpt;
     950                 :            : 
     951                 :          0 :         return sym_session_configure(roc_cpt, xform, sess, false);
     952                 :            : }
     953                 :            : 
     954                 :            : void
     955                 :          0 : sym_session_clear(struct rte_cryptodev_sym_session *sess, bool is_session_less)
     956                 :            : {
     957                 :            :         struct cnxk_se_sess *sess_priv = (struct cnxk_se_sess *)sess;
     958                 :            : 
     959         [ #  # ]:          0 :         if (sess_priv->roc_se_ctx == NULL)
     960                 :            :                 return;
     961                 :            : 
     962                 :            :         /* Trigger CTX flush + invalidate to remove from CTX_CACHE */
     963         [ #  # ]:          0 :         if (hw_ctx_cache_enable())
     964                 :          0 :                 roc_cpt_lf_ctx_flush(sess_priv->lf, &sess_priv->roc_se_ctx->se_ctx, true);
     965                 :            : 
     966         [ #  # ]:          0 :         if (sess_priv->roc_se_ctx->auth_key != NULL)
     967                 :          0 :                 plt_free(sess_priv->roc_se_ctx->auth_key);
     968                 :            : 
     969                 :            :         /* Free the allocated roc_se_ctx memory */
     970                 :          0 :         rte_free(sess_priv->roc_se_ctx);
     971                 :          0 :         sess_priv->roc_se_ctx = NULL;
     972                 :            : 
     973         [ #  # ]:          0 :         if (is_session_less)
     974                 :          0 :                 memset(sess_priv, 0, cnxk_cpt_sym_session_get_size(NULL));
     975                 :            : }
     976                 :            : 
     977                 :            : void
     978                 :          0 : cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev __rte_unused,
     979                 :            :                            struct rte_cryptodev_sym_session *sess)
     980                 :            : {
     981                 :          0 :         return sym_session_clear(sess, false);
     982                 :            : }
     983                 :            : 
     984                 :            : unsigned int
     985                 :          0 : cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused)
     986                 :            : {
     987                 :          0 :         return sizeof(struct cnxk_ae_sess);
     988                 :            : }
     989                 :            : 
     990                 :            : void
     991         [ #  # ]:          0 : cnxk_ae_session_clear(struct rte_cryptodev *dev __rte_unused,
     992                 :            :                       struct rte_cryptodev_asym_session *sess)
     993                 :            : {
     994                 :            :         struct cnxk_ae_sess *priv = (struct cnxk_ae_sess *)sess;
     995                 :            : 
     996                 :            :         /* Trigger CTX flush + invalidate to remove from CTX_CACHE */
     997         [ #  # ]:          0 :         if (roc_errata_cpt_hang_on_mixed_ctx_val())
     998                 :          0 :                 roc_cpt_lf_ctx_flush(priv->lf, &priv->hw_ctx, true);
     999                 :            : 
    1000                 :            :         /* Free resources allocated in session_cfg */
    1001                 :          0 :         cnxk_ae_free_session_parameters(priv);
    1002                 :            : 
    1003                 :            :         /* Reset and free object back to pool */
    1004                 :            :         memset(priv, 0, sizeof(struct cnxk_ae_sess));
    1005                 :          0 : }
    1006                 :            : 
    1007                 :            : int
    1008                 :          0 : cnxk_ae_session_cfg(struct rte_cryptodev *dev, struct rte_crypto_asym_xform *xform,
    1009                 :            :                     struct rte_cryptodev_asym_session *sess)
    1010                 :            : {
    1011                 :            :         struct cnxk_ae_sess *priv = (struct cnxk_ae_sess *)sess;
    1012                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
    1013                 :            :         struct roc_cpt *roc_cpt = &vf->cpt;
    1014                 :            :         union cpt_inst_w7 w7;
    1015                 :            :         struct hw_ctx_s *hwc;
    1016                 :            :         int ret;
    1017                 :            : 
    1018                 :            :         ret = cnxk_ae_fill_session_parameters(priv, xform);
    1019                 :            :         if (ret)
    1020                 :          0 :                 return ret;
    1021                 :            : 
    1022                 :          0 :         priv->lf = roc_cpt->lf[0];
    1023                 :            : 
    1024                 :          0 :         w7.u64 = 0;
    1025         [ #  # ]:          0 :         if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_ML_KEM) {
    1026                 :          0 :                 w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_RE];
    1027         [ #  # ]:          0 :                 w7.s.cptr = rte_cpu_to_be_64(vf->cnxk_ml_iova[ROC_RE_ML_ZETA_IDX_KEM]);
    1028         [ #  # ]:          0 :         } else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_ML_DSA) {
    1029                 :          0 :                 w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_RE];
    1030         [ #  # ]:          0 :                 w7.s.cptr = rte_cpu_to_be_64(vf->cnxk_ml_iova[ROC_RE_ML_ZETA_IDX_DSA]);
    1031                 :            :         } else {
    1032                 :          0 :                 w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
    1033                 :            :                 w7.s.cptr = 0;
    1034                 :            :         }
    1035                 :            : 
    1036         [ #  # ]:          0 :         if (roc_errata_cpt_hang_on_mixed_ctx_val()) {
    1037                 :          0 :                 hwc = &priv->hw_ctx;
    1038                 :          0 :                 hwc->w0.s.aop_valid = 1;
    1039                 :          0 :                 hwc->w0.s.ctx_hdr_size = 0;
    1040                 :          0 :                 hwc->w0.s.ctx_size = 1;
    1041                 :          0 :                 hwc->w0.s.ctx_push_size = 1;
    1042                 :            : 
    1043                 :          0 :                 w7.s.cptr = (uint64_t)hwc;
    1044                 :          0 :                 w7.s.ctx_val = 1;
    1045                 :            :         }
    1046                 :            : 
    1047                 :          0 :         priv->cpt_inst_w7 = w7.u64;
    1048                 :          0 :         priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
    1049                 :          0 :         priv->cnxk_ml_iova = vf->cnxk_ml_iova;
    1050                 :          0 :         priv->ec_grp = vf->ec_grp;
    1051                 :            : 
    1052                 :          0 :         return 0;
    1053                 :            : }
    1054                 :            : 
    1055                 :            : void
    1056                 :          0 : cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp)
    1057                 :            : {
    1058                 :            :         struct pending_queue *pend_q = &qp->pend_q;
    1059                 :            :         uint64_t inflight, enq_ptr, deq_ptr, insts;
    1060                 :            :         union cpt_lf_q_inst_ptr inst_ptr;
    1061                 :            :         union cpt_lf_inprog lf_inprog;
    1062                 :            : 
    1063                 :          0 :         plt_print("Lcore ID: %d, LF/QP ID: %d", rte_lcore_id(), qp->lf.lf_id);
    1064                 :          0 :         plt_print("");
    1065                 :          0 :         plt_print("S/w pending queue:");
    1066                 :          0 :         plt_print("\tHead: %"PRIu64"", pend_q->head);
    1067                 :          0 :         plt_print("\tTail: %"PRIu64"", pend_q->tail);
    1068                 :          0 :         plt_print("\tMask: 0x%"PRIx64"", pend_q->pq_mask);
    1069                 :          0 :         plt_print("\tInflight count: %"PRIu64"",
    1070                 :            :                   pending_queue_infl_cnt(pend_q->head, pend_q->tail,
    1071                 :            :                                          pend_q->pq_mask));
    1072                 :            : 
    1073                 :          0 :         plt_print("");
    1074                 :          0 :         plt_print("H/w pending queue:");
    1075                 :            : 
    1076                 :          0 :         lf_inprog.u = plt_read64(qp->lf.rbase + CPT_LF_INPROG);
    1077                 :          0 :         inflight = lf_inprog.s.inflight;
    1078                 :          0 :         plt_print("\tInflight in engines: %"PRIu64"", inflight);
    1079                 :            : 
    1080         [ #  # ]:          0 :         inst_ptr.u = plt_read64(qp->lf.rbase + CPT_LF_Q_INST_PTR);
    1081                 :            : 
    1082                 :          0 :         enq_ptr = inst_ptr.s.nq_ptr;
    1083                 :          0 :         deq_ptr = inst_ptr.s.dq_ptr;
    1084                 :            : 
    1085         [ #  # ]:          0 :         if (enq_ptr >= deq_ptr)
    1086                 :          0 :                 insts = enq_ptr - deq_ptr;
    1087                 :            :         else
    1088                 :          0 :                 insts = (enq_ptr + pend_q->pq_mask + 1 + 320 + 40) - deq_ptr;
    1089                 :            : 
    1090                 :          0 :         plt_print("\tNQ ptr: 0x%"PRIx64"", enq_ptr);
    1091                 :          0 :         plt_print("\tDQ ptr: 0x%"PRIx64"", deq_ptr);
    1092                 :          0 :         plt_print("Insts waiting in CPT: %"PRIu64"", insts);
    1093                 :            : 
    1094                 :          0 :         plt_print("");
    1095                 :          0 :         roc_cpt_afs_print(qp->lf.roc_cpt);
    1096                 :          0 :         roc_cpt_lfs_print(qp->lf.roc_cpt);
    1097                 :          0 : }
    1098                 :            : 
    1099                 :            : int
    1100                 :          0 : cnxk_cpt_queue_pair_event_error_query(struct rte_cryptodev *dev, uint16_t qp_id)
    1101                 :            : {
    1102                 :          0 :         struct cnxk_cpt_vf *vf = dev->data->dev_private;
    1103                 :            :         struct roc_cpt *roc_cpt = &vf->cpt;
    1104                 :            :         struct roc_cpt_lf *lf;
    1105                 :            : 
    1106                 :          0 :         lf = roc_cpt->lf[qp_id];
    1107   [ #  #  #  # ]:          0 :         if (lf && lf->error_event_pending) {
    1108                 :          0 :                 lf->error_event_pending = 0;
    1109                 :          0 :                 return 1;
    1110                 :            :         }
    1111                 :            :         return 0;
    1112                 :            : }
    1113                 :            : 
    1114                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_qptr_get, 24.03)
    1115                 :            : struct rte_pmd_cnxk_crypto_qptr *
    1116                 :          0 : rte_pmd_cnxk_crypto_qptr_get(uint8_t dev_id, uint16_t qp_id)
    1117                 :            : {
    1118                 :            :         const struct rte_crypto_fp_ops *fp_ops;
    1119                 :            :         void *qptr;
    1120                 :            : 
    1121                 :          0 :         fp_ops = &rte_crypto_fp_ops[dev_id];
    1122                 :          0 :         qptr = fp_ops->qp.data[qp_id];
    1123                 :            : 
    1124                 :          0 :         return qptr;
    1125                 :            : }
    1126                 :            : 
    1127                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_ae_fpm_table_get, 25.07)
    1128                 :            : const uint64_t *
    1129                 :          0 : rte_pmd_cnxk_ae_fpm_table_get(uint8_t dev_id)
    1130                 :            : {
    1131                 :            :         struct rte_cryptodev *dev;
    1132                 :            :         struct cnxk_cpt_vf *vf;
    1133                 :            : 
    1134                 :          0 :         dev = rte_cryptodev_pmd_get_dev(dev_id);
    1135         [ #  # ]:          0 :         if (dev == NULL) {
    1136                 :          0 :                 plt_err("Invalid dev_id %u", dev_id);
    1137                 :          0 :                 return NULL;
    1138                 :            :         }
    1139                 :            : 
    1140                 :          0 :         vf = dev->data->dev_private;
    1141         [ #  # ]:          0 :         if (vf == NULL) {
    1142                 :          0 :                 plt_err("VF is not initialized");
    1143                 :          0 :                 return NULL;
    1144                 :            :         }
    1145                 :            : 
    1146                 :          0 :         return vf->cnxk_fpm_iova;
    1147                 :            : }
    1148                 :            : 
    1149                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_ae_ec_grp_table_get, 25.07)
    1150                 :            : const struct rte_pmd_cnxk_crypto_ae_ec_group_params **
    1151                 :          0 : rte_pmd_cnxk_ae_ec_grp_table_get(uint8_t dev_id, uint16_t *nb_max_entries)
    1152                 :            : {
    1153                 :            :         struct rte_cryptodev *dev;
    1154                 :            :         struct cnxk_cpt_vf *vf;
    1155                 :            : 
    1156                 :          0 :         dev = rte_cryptodev_pmd_get_dev(dev_id);
    1157         [ #  # ]:          0 :         if (dev == NULL) {
    1158                 :          0 :                 plt_err("Invalid dev_id %u", dev_id);
    1159                 :          0 :                 return NULL;
    1160                 :            :         }
    1161                 :            : 
    1162                 :          0 :         vf = dev->data->dev_private;
    1163         [ #  # ]:          0 :         if (vf == NULL) {
    1164                 :          0 :                 plt_err("VF is not initialized");
    1165                 :          0 :                 return NULL;
    1166                 :            :         }
    1167                 :            : 
    1168                 :          0 :         *nb_max_entries = ROC_AE_EC_ID_PMAX;
    1169                 :            : 
    1170                 :          0 :         return (const struct rte_pmd_cnxk_crypto_ae_ec_group_params **)(void *)vf->ec_grp;
    1171                 :            : }
    1172                 :            : 
    1173                 :            : static inline void
    1174                 :          0 : cnxk_crypto_cn10k_submit(struct rte_pmd_cnxk_crypto_qptr *qptr, void *inst, uint16_t nb_inst)
    1175                 :            : {
    1176                 :            :         struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
    1177                 :            :         uint64_t lmt_base, io_addr;
    1178                 :            :         uint16_t lmt_id;
    1179                 :            :         void *lmt_dst;
    1180                 :            :         int i;
    1181                 :            : 
    1182                 :          0 :         lmt_base = qp->lmtline.lmt_base;
    1183                 :            :         io_addr = qp->lmtline.io_addr;
    1184                 :            : 
    1185                 :            :         ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
    1186                 :            : 
    1187                 :          0 :         lmt_dst = PLT_PTR_CAST(lmt_base);
    1188                 :          0 : again:
    1189                 :          0 :         i = RTE_MIN(nb_inst, CN10K_CPT_PKTS_PER_LOOP);
    1190                 :            : 
    1191         [ #  # ]:          0 :         memcpy(lmt_dst, inst, i * sizeof(struct cpt_inst_s));
    1192                 :            : 
    1193                 :            :         cn10k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
    1194                 :            : 
    1195         [ #  # ]:          0 :         if (nb_inst - i > 0) {
    1196                 :          0 :                 nb_inst -= CN10K_CPT_PKTS_PER_LOOP;
    1197                 :          0 :                 inst = RTE_PTR_ADD(inst, CN10K_CPT_PKTS_PER_LOOP * sizeof(struct cpt_inst_s));
    1198                 :          0 :                 goto again;
    1199                 :            :         }
    1200                 :          0 : }
    1201                 :            : 
    1202                 :            : static inline void
    1203                 :            : cnxk_crypto_cn9k_submit(struct rte_pmd_cnxk_crypto_qptr *qptr, void *inst, uint16_t nb_inst)
    1204                 :            : {
    1205                 :            :         struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
    1206                 :            : 
    1207                 :            :         const uint64_t lmt_base = qp->lf.lmt_base;
    1208                 :            :         const uint64_t io_addr = qp->lf.io_addr;
    1209                 :            : 
    1210         [ #  # ]:          0 :         if (unlikely(nb_inst & 1)) {
    1211                 :            :                 cn9k_cpt_inst_submit(inst, lmt_base, io_addr);
    1212                 :            :                 inst = RTE_PTR_ADD(inst, sizeof(struct cpt_inst_s));
    1213                 :            :                 nb_inst -= 1;
    1214                 :            :         }
    1215                 :            : 
    1216         [ #  # ]:          0 :         while (nb_inst > 0) {
    1217                 :            :                 cn9k_cpt_inst_submit_dual(inst, lmt_base, io_addr);
    1218                 :            :                 inst = RTE_PTR_ADD(inst, 2 * sizeof(struct cpt_inst_s));
    1219                 :            :                 nb_inst -= 2;
    1220                 :            :         }
    1221                 :            : }
    1222                 :            : 
    1223                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_submit, 24.03)
    1224                 :            : void
    1225         [ #  # ]:          0 : rte_pmd_cnxk_crypto_submit(struct rte_pmd_cnxk_crypto_qptr *qptr, void *inst, uint16_t nb_inst)
    1226                 :            : {
    1227   [ #  #  #  # ]:          0 :         if (roc_model_is_cn10k() || roc_model_is_cn20k())
    1228                 :          0 :                 return cnxk_crypto_cn10k_submit(qptr, inst, nb_inst);
    1229         [ #  # ]:          0 :         else if (roc_model_is_cn9k())
    1230                 :            :                 return cnxk_crypto_cn9k_submit(qptr, inst, nb_inst);
    1231                 :            : 
    1232                 :          0 :         plt_err("Invalid cnxk model");
    1233                 :            : }
    1234                 :            : 
    1235                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_flush, 24.07)
    1236                 :            : int
    1237                 :          0 : rte_pmd_cnxk_crypto_cptr_flush(struct rte_pmd_cnxk_crypto_qptr *qptr,
    1238                 :            :                                struct rte_pmd_cnxk_crypto_cptr *cptr, bool invalidate)
    1239                 :            : {
    1240                 :            :         struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
    1241                 :            : 
    1242         [ #  # ]:          0 :         if (unlikely(qptr == NULL)) {
    1243                 :          0 :                 plt_err("Invalid queue pair pointer");
    1244                 :          0 :                 return -EINVAL;
    1245                 :            :         }
    1246                 :            : 
    1247         [ #  # ]:          0 :         if (unlikely(cptr == NULL)) {
    1248                 :          0 :                 plt_err("Invalid CPTR pointer");
    1249                 :          0 :                 return -EINVAL;
    1250                 :            :         }
    1251                 :            : 
    1252         [ #  # ]:          0 :         if (unlikely(roc_model_is_cn9k())) {
    1253                 :          0 :                 plt_err("Invalid cnxk model");
    1254                 :          0 :                 return -EINVAL;
    1255                 :            :         }
    1256                 :            : 
    1257                 :          0 :         return roc_cpt_lf_ctx_flush(&qp->lf, cptr, invalidate);
    1258                 :            : }
    1259                 :            : 
    1260                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_get, 24.07)
    1261                 :            : struct rte_pmd_cnxk_crypto_cptr *
    1262                 :          0 : rte_pmd_cnxk_crypto_cptr_get(struct rte_pmd_cnxk_crypto_sess *rte_sess)
    1263                 :            : {
    1264         [ #  # ]:          0 :         if (rte_sess == NULL) {
    1265                 :          0 :                 plt_err("Invalid session pointer");
    1266                 :          0 :                 return NULL;
    1267                 :            :         }
    1268                 :            : 
    1269         [ #  # ]:          0 :         if (rte_sess->sec_sess == NULL) {
    1270                 :          0 :                 plt_err("Invalid RTE session pointer");
    1271                 :          0 :                 return NULL;
    1272                 :            :         }
    1273                 :            : 
    1274         [ #  # ]:          0 :         if (rte_sess->op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
    1275                 :            :                 struct cnxk_ae_sess *ae_sess = PLT_PTR_CAST(rte_sess->crypto_asym_sess);
    1276                 :          0 :                 return PLT_PTR_CAST(&ae_sess->hw_ctx);
    1277                 :            :         }
    1278                 :            : 
    1279         [ #  # ]:          0 :         if (rte_sess->op_type != RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
    1280                 :          0 :                 plt_err("Invalid crypto operation type");
    1281                 :          0 :                 return NULL;
    1282                 :            :         }
    1283                 :            : 
    1284         [ #  # ]:          0 :         if (rte_sess->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
    1285                 :            :                 struct cnxk_se_sess *se_sess = PLT_PTR_CAST(rte_sess->crypto_sym_sess);
    1286         [ #  # ]:          0 :                 if (se_sess->roc_se_ctx == NULL) {
    1287                 :          0 :                         plt_err("Invalid roc_se_ctx pointer");
    1288                 :          0 :                         return NULL;
    1289                 :            :                 }
    1290                 :          0 :                 return PLT_PTR_CAST(&se_sess->roc_se_ctx->se_ctx);
    1291                 :            :         }
    1292                 :            : 
    1293         [ #  # ]:          0 :         if (rte_sess->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
    1294         [ #  # ]:          0 :                 if (roc_model_is_cn20k()) {
    1295                 :            :                         struct cn20k_sec_session *sec_sess = PLT_PTR_CAST(rte_sess->sec_sess);
    1296                 :            : 
    1297                 :          0 :                         return PLT_PTR_CAST(&sec_sess->sa);
    1298                 :            :                 }
    1299                 :            : 
    1300         [ #  # ]:          0 :                 if (roc_model_is_cn10k()) {
    1301                 :            :                         struct cn10k_sec_session *sec_sess = PLT_PTR_CAST(rte_sess->sec_sess);
    1302                 :          0 :                         return PLT_PTR_CAST(&sec_sess->sa);
    1303                 :            :                 }
    1304                 :            : 
    1305         [ #  # ]:          0 :                 if (roc_model_is_cn9k()) {
    1306                 :            :                         struct cn9k_sec_session *sec_sess = PLT_PTR_CAST(rte_sess->sec_sess);
    1307                 :          0 :                         return PLT_PTR_CAST(&sec_sess->sa);
    1308                 :            :                 }
    1309                 :            : 
    1310                 :          0 :                 plt_err("Invalid cnxk model");
    1311                 :          0 :                 return NULL;
    1312                 :            :         }
    1313                 :            : 
    1314                 :          0 :         plt_err("Invalid session type");
    1315                 :          0 :         return NULL;
    1316                 :            : }
    1317                 :            : 
    1318                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_read, 24.07)
    1319                 :            : int
    1320                 :          0 : rte_pmd_cnxk_crypto_cptr_read(struct rte_pmd_cnxk_crypto_qptr *qptr,
    1321                 :            :                               struct rte_pmd_cnxk_crypto_cptr *cptr, void *data, uint32_t len)
    1322                 :            : {
    1323                 :            :         struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
    1324                 :            :         int ret;
    1325                 :            : 
    1326         [ #  # ]:          0 :         if (unlikely(qptr == NULL)) {
    1327                 :          0 :                 plt_err("Invalid queue pair pointer");
    1328                 :          0 :                 return -EINVAL;
    1329                 :            :         }
    1330                 :            : 
    1331         [ #  # ]:          0 :         if (unlikely(cptr == NULL)) {
    1332                 :          0 :                 plt_err("Invalid CPTR pointer");
    1333                 :          0 :                 return -EINVAL;
    1334                 :            :         }
    1335                 :            : 
    1336         [ #  # ]:          0 :         if (unlikely(data == NULL)) {
    1337                 :          0 :                 plt_err("Invalid data pointer");
    1338                 :          0 :                 return -EINVAL;
    1339                 :            :         }
    1340                 :            : 
    1341                 :          0 :         ret = roc_cpt_lf_ctx_flush(&qp->lf, cptr, false);
    1342         [ #  # ]:          0 :         if (ret)
    1343                 :            :                 return ret;
    1344                 :            : 
    1345                 :            :         /* Wait for the flush to complete. */
    1346                 :            :         rte_delay_ms(1);
    1347                 :            : 
    1348                 :          0 :         memcpy(data, cptr, len);
    1349                 :          0 :         return 0;
    1350                 :            : }
    1351                 :            : 
    1352                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_cptr_write, 24.07)
    1353                 :            : int
    1354                 :          0 : rte_pmd_cnxk_crypto_cptr_write(struct rte_pmd_cnxk_crypto_qptr *qptr,
    1355                 :            :                                struct rte_pmd_cnxk_crypto_cptr *cptr, void *data, uint32_t len)
    1356                 :            : {
    1357                 :            :         struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
    1358                 :            :         int ret;
    1359                 :            : 
    1360         [ #  # ]:          0 :         if (unlikely(qptr == NULL)) {
    1361                 :          0 :                 plt_err("Invalid queue pair pointer");
    1362                 :          0 :                 return -EINVAL;
    1363                 :            :         }
    1364                 :            : 
    1365         [ #  # ]:          0 :         if (unlikely(cptr == NULL)) {
    1366                 :          0 :                 plt_err("Invalid CPTR pointer");
    1367                 :          0 :                 return -EINVAL;
    1368                 :            :         }
    1369                 :            : 
    1370         [ #  # ]:          0 :         if (unlikely(data == NULL)) {
    1371                 :          0 :                 plt_err("Invalid data pointer");
    1372                 :          0 :                 return -EINVAL;
    1373                 :            :         }
    1374                 :            : 
    1375                 :          0 :         ret = roc_cpt_ctx_write(&qp->lf, data, cptr, len);
    1376         [ #  # ]:          0 :         if (ret) {
    1377                 :          0 :                 plt_err("Could not write to CPTR");
    1378                 :          0 :                 return ret;
    1379                 :            :         }
    1380                 :            : 
    1381                 :          0 :         ret = roc_cpt_lf_ctx_flush(&qp->lf, cptr, false);
    1382         [ #  # ]:          0 :         if (ret)
    1383                 :            :                 return ret;
    1384                 :            : 
    1385                 :            :         rte_atomic_thread_fence(rte_memory_order_seq_cst);
    1386                 :            : 
    1387                 :          0 :         return 0;
    1388                 :            : }
    1389                 :            : 
    1390                 :            : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_crypto_qp_stats_get, 24.07)
    1391                 :            : int
    1392                 :          0 : rte_pmd_cnxk_crypto_qp_stats_get(struct rte_pmd_cnxk_crypto_qptr *qptr,
    1393                 :            :                                  struct rte_pmd_cnxk_crypto_qp_stats *stats)
    1394                 :            : {
    1395                 :            :         struct cnxk_cpt_qp *qp = PLT_PTR_CAST(qptr);
    1396                 :            :         struct roc_cpt_lf *lf;
    1397                 :            : 
    1398         [ #  # ]:          0 :         if (unlikely(qptr == NULL)) {
    1399                 :          0 :                 plt_err("Invalid queue pair pointer");
    1400                 :          0 :                 return -EINVAL;
    1401                 :            :         }
    1402                 :            : 
    1403         [ #  # ]:          0 :         if (unlikely(stats == NULL)) {
    1404                 :          0 :                 plt_err("Invalid stats pointer");
    1405                 :          0 :                 return -EINVAL;
    1406                 :            :         }
    1407                 :            : 
    1408         [ #  # ]:          0 :         if (unlikely(roc_model_is_cn9k())) {
    1409                 :          0 :                 plt_err("Invalid cnxk model");
    1410                 :          0 :                 return -EINVAL;
    1411                 :            :         }
    1412                 :            : 
    1413                 :            :         lf = &qp->lf;
    1414                 :            : 
    1415                 :          0 :         stats->ctx_enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
    1416                 :          0 :         stats->ctx_enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
    1417                 :          0 :         stats->ctx_dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
    1418                 :          0 :         stats->ctx_dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
    1419                 :            : 
    1420                 :          0 :         return 0;
    1421                 :            : }
    1422                 :            : 
    1423                 :            : #ifdef CPT_INST_DEBUG_ENABLE
    1424                 :            : void
    1425                 :            : cnxk_cpt_request_data_sgv2_mode_dump(uint8_t *in_buffer, bool glist, uint16_t components)
    1426                 :            : {
    1427                 :            :         struct roc_se_buf_ptr list_ptr[ROC_MAX_SG_CNT];
    1428                 :            :         const char *list = glist ? "glist" : "slist";
    1429                 :            :         struct roc_sg2list_comp *sg_ptr = NULL;
    1430                 :            :         uint16_t list_cnt = 0;
    1431                 :            :         char suffix[64];
    1432                 :            :         int i, j;
    1433                 :            : 
    1434                 :            :         sg_ptr = (void *)in_buffer;
    1435                 :            :         for (i = 0; i < components; i++) {
    1436                 :            :                 for (j = 0; j < sg_ptr->u.s.valid_segs; j++) {
    1437                 :            :                         list_ptr[i * 3 + j].size = sg_ptr->u.s.len[j];
    1438                 :            :                         list_ptr[i * 3 + j].vaddr = (void *)sg_ptr->ptr[j];
    1439                 :            :                         list_ptr[i * 3 + j].vaddr = list_ptr[i * 3 + j].vaddr;
    1440                 :            :                         list_cnt++;
    1441                 :            :                 }
    1442                 :            :                 sg_ptr++;
    1443                 :            :         }
    1444                 :            : 
    1445                 :            :         plt_err("Current %s: %u", list, list_cnt);
    1446                 :            : 
    1447                 :            :         for (i = 0; i < list_cnt; i++) {
    1448                 :            :                 snprintf(suffix, sizeof(suffix), "%s[%d]: vaddr 0x%" PRIx64 ", vaddr %p len %u",
    1449                 :            :                          list, i, (uint64_t)list_ptr[i].vaddr, list_ptr[i].vaddr, list_ptr[i].size);
    1450                 :            :                 rte_hexdump(rte_log_get_stream(), suffix, list_ptr[i].vaddr, list_ptr[i].size);
    1451                 :            :         }
    1452                 :            : }
    1453                 :            : 
    1454                 :            : void
    1455                 :            : cnxk_cpt_request_data_sg_mode_dump(uint8_t *in_buffer, bool glist)
    1456                 :            : {
    1457                 :            :         struct roc_se_buf_ptr list_ptr[ROC_MAX_SG_CNT];
    1458                 :            :         const char *list = glist ? "glist" : "slist";
    1459                 :            :         struct roc_sglist_comp *sg_ptr = NULL;
    1460                 :            :         uint16_t list_cnt, components;
    1461                 :            :         char suffix[64];
    1462                 :            :         int i;
    1463                 :            : 
    1464                 :            :         sg_ptr = (void *)(in_buffer + 8);
    1465                 :            :         list_cnt = rte_be_to_cpu_16((((uint16_t *)in_buffer)[2]));
    1466                 :            :         if (!glist) {
    1467                 :            :                 components = list_cnt / 4;
    1468                 :            :                 if (list_cnt % 4)
    1469                 :            :                         components++;
    1470                 :            :                 sg_ptr += components;
    1471                 :            :                 list_cnt = rte_be_to_cpu_16((((uint16_t *)in_buffer)[3]));
    1472                 :            :         }
    1473                 :            : 
    1474                 :            :         plt_err("Current %s: %u", list, list_cnt);
    1475                 :            :         components = list_cnt / 4;
    1476                 :            :         for (i = 0; i < components; i++) {
    1477                 :            :                 list_ptr[i * 4 + 0].size = rte_be_to_cpu_16(sg_ptr->u.s.len[0]);
    1478                 :            :                 list_ptr[i * 4 + 1].size = rte_be_to_cpu_16(sg_ptr->u.s.len[1]);
    1479                 :            :                 list_ptr[i * 4 + 2].size = rte_be_to_cpu_16(sg_ptr->u.s.len[2]);
    1480                 :            :                 list_ptr[i * 4 + 3].size = rte_be_to_cpu_16(sg_ptr->u.s.len[3]);
    1481                 :            :                 list_ptr[i * 4 + 0].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[0]);
    1482                 :            :                 list_ptr[i * 4 + 1].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[1]);
    1483                 :            :                 list_ptr[i * 4 + 2].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[2]);
    1484                 :            :                 list_ptr[i * 4 + 3].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[3]);
    1485                 :            :                 list_ptr[i * 4 + 0].vaddr = list_ptr[i * 4 + 0].vaddr;
    1486                 :            :                 list_ptr[i * 4 + 1].vaddr = list_ptr[i * 4 + 1].vaddr;
    1487                 :            :                 list_ptr[i * 4 + 2].vaddr = list_ptr[i * 4 + 2].vaddr;
    1488                 :            :                 list_ptr[i * 4 + 3].vaddr = list_ptr[i * 4 + 3].vaddr;
    1489                 :            :                 sg_ptr++;
    1490                 :            :         }
    1491                 :            : 
    1492                 :            :         components = list_cnt % 4;
    1493                 :            :         switch (components) {
    1494                 :            :         case 3:
    1495                 :            :                 list_ptr[i * 4 + 2].size = rte_be_to_cpu_16(sg_ptr->u.s.len[2]);
    1496                 :            :                 list_ptr[i * 4 + 2].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[2]);
    1497                 :            :                 list_ptr[i * 4 + 2].vaddr = list_ptr[i * 4 + 2].vaddr;
    1498                 :            :                 [[fallthrough]];
    1499                 :            :         case 2:
    1500                 :            :                 list_ptr[i * 4 + 1].size = rte_be_to_cpu_16(sg_ptr->u.s.len[1]);
    1501                 :            :                 list_ptr[i * 4 + 1].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[1]);
    1502                 :            :                 list_ptr[i * 4 + 1].vaddr = list_ptr[i * 4 + 1].vaddr;
    1503                 :            :                 [[fallthrough]];
    1504                 :            :         case 1:
    1505                 :            :                 list_ptr[i * 4 + 0].size = rte_be_to_cpu_16(sg_ptr->u.s.len[0]);
    1506                 :            :                 list_ptr[i * 4 + 0].vaddr = (void *)rte_be_to_cpu_64(sg_ptr->ptr[0]);
    1507                 :            :                 list_ptr[i * 4 + 0].vaddr = list_ptr[i * 4 + 0].vaddr;
    1508                 :            :                 break;
    1509                 :            :         default:
    1510                 :            :                 break;
    1511                 :            :         }
    1512                 :            : 
    1513                 :            :         for (i = 0; i < list_cnt; i++) {
    1514                 :            :                 snprintf(suffix, sizeof(suffix), "%s[%d]: vaddr 0x%" PRIx64 ", vaddr %p len %u",
    1515                 :            :                          list, i, (uint64_t)list_ptr[i].vaddr, list_ptr[i].vaddr, list_ptr[i].size);
    1516                 :            :                 rte_hexdump(rte_log_get_stream(), suffix, list_ptr[i].vaddr, list_ptr[i].size);
    1517                 :            :         }
    1518                 :            : }
    1519                 :            : #endif

Generated by: LCOV version 1.14