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

Generated by: LCOV version 1.14