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

Generated by: LCOV version 1.14