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

Generated by: LCOV version 1.14