LCOV - code coverage report
Current view: top level - drivers/crypto/octeontx - otx_cryptodev_ops.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 371 0.0 %
Date: 2025-05-01 17:49:45 Functions: 0 25 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 322 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Cavium, Inc
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <eal_export.h>
       6                 :            : #include <rte_alarm.h>
       7                 :            : #include <bus_pci_driver.h>
       8                 :            : #include <rte_cryptodev.h>
       9                 :            : #include <cryptodev_pmd.h>
      10                 :            : #include <rte_eventdev.h>
      11                 :            : #include <rte_event_crypto_adapter.h>
      12                 :            : #include <rte_errno.h>
      13                 :            : #include <rte_malloc.h>
      14                 :            : #include <rte_mempool.h>
      15                 :            : 
      16                 :            : #include "otx_cryptodev.h"
      17                 :            : #include "otx_cryptodev_capabilities.h"
      18                 :            : #include "otx_cryptodev_hw_access.h"
      19                 :            : #include "otx_cryptodev_mbox.h"
      20                 :            : #include "otx_cryptodev_ops.h"
      21                 :            : 
      22                 :            : #include "cpt_pmd_logs.h"
      23                 :            : #include "cpt_pmd_ops_helper.h"
      24                 :            : #include "cpt_ucode.h"
      25                 :            : #include "cpt_ucode_asym.h"
      26                 :            : 
      27                 :            : #include "ssovf_worker.h"
      28                 :            : 
      29                 :            : static uint64_t otx_fpm_iova[CPT_EC_ID_PMAX];
      30                 :            : 
      31                 :            : /* Forward declarations */
      32                 :            : 
      33                 :            : static int
      34                 :            : otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id);
      35                 :            : 
      36                 :            : /* Alarm routines */
      37                 :            : 
      38                 :            : static void
      39                 :          0 : otx_cpt_alarm_cb(void *arg)
      40                 :            : {
      41                 :            :         struct cpt_vf *cptvf = arg;
      42                 :          0 :         otx_cpt_poll_misc(cptvf);
      43                 :          0 :         rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
      44                 :            :                           otx_cpt_alarm_cb, cptvf);
      45                 :          0 : }
      46                 :            : 
      47                 :            : static int
      48                 :            : otx_cpt_periodic_alarm_start(void *arg)
      49                 :            : {
      50                 :          0 :         return rte_eal_alarm_set(CPT_INTR_POLL_INTERVAL_MS * 1000,
      51                 :            :                                  otx_cpt_alarm_cb, arg);
      52                 :            : }
      53                 :            : 
      54                 :            : static int
      55                 :            : otx_cpt_periodic_alarm_stop(void *arg)
      56                 :            : {
      57                 :          0 :         return rte_eal_alarm_cancel(otx_cpt_alarm_cb, arg);
      58                 :            : }
      59                 :            : 
      60                 :            : /* PMD ops */
      61                 :            : 
      62                 :            : static int
      63                 :          0 : otx_cpt_dev_config(struct rte_cryptodev *dev,
      64                 :            :                    struct rte_cryptodev_config *config __rte_unused)
      65                 :            : {
      66                 :            :         int ret = 0;
      67                 :            : 
      68                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
      69                 :            : 
      70         [ #  # ]:          0 :         if (dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
      71                 :            :                 /* Initialize shared FPM table */
      72                 :          0 :                 ret = cpt_fpm_init(otx_fpm_iova);
      73                 :            : 
      74                 :          0 :         return ret;
      75                 :            : }
      76                 :            : 
      77                 :            : static int
      78                 :          0 : otx_cpt_dev_start(struct rte_cryptodev *c_dev)
      79                 :            : {
      80                 :          0 :         void *cptvf = c_dev->data->dev_private;
      81                 :            : 
      82                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
      83                 :            : 
      84                 :          0 :         return otx_cpt_start_device(cptvf);
      85                 :            : }
      86                 :            : 
      87                 :            : static void
      88                 :          0 : otx_cpt_dev_stop(struct rte_cryptodev *c_dev)
      89                 :            : {
      90                 :          0 :         void *cptvf = c_dev->data->dev_private;
      91                 :            : 
      92                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
      93                 :            : 
      94         [ #  # ]:          0 :         if (c_dev->feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)
      95                 :          0 :                 cpt_fpm_clear();
      96                 :            : 
      97                 :          0 :         otx_cpt_stop_device(cptvf);
      98                 :          0 : }
      99                 :            : 
     100                 :            : static int
     101                 :          0 : otx_cpt_dev_close(struct rte_cryptodev *c_dev)
     102                 :            : {
     103                 :          0 :         void *cptvf = c_dev->data->dev_private;
     104                 :            :         int i, ret;
     105                 :            : 
     106                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     107                 :            : 
     108         [ #  # ]:          0 :         for (i = 0; i < c_dev->data->nb_queue_pairs; i++) {
     109                 :          0 :                 ret = otx_cpt_que_pair_release(c_dev, i);
     110         [ #  # ]:          0 :                 if (ret)
     111                 :          0 :                         return ret;
     112                 :            :         }
     113                 :            : 
     114                 :            :         otx_cpt_periodic_alarm_stop(cptvf);
     115                 :          0 :         otx_cpt_deinit_device(cptvf);
     116                 :            : 
     117                 :          0 :         return 0;
     118                 :            : }
     119                 :            : 
     120                 :            : static void
     121                 :          0 : otx_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info)
     122                 :            : {
     123                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     124         [ #  # ]:          0 :         if (info != NULL) {
     125                 :          0 :                 info->max_nb_queue_pairs = CPT_NUM_QS_PER_VF;
     126                 :          0 :                 info->feature_flags = dev->feature_flags;
     127                 :          0 :                 info->capabilities = otx_get_capabilities(info->feature_flags);
     128                 :          0 :                 info->sym.max_nb_sessions = 0;
     129                 :          0 :                 info->driver_id = otx_cryptodev_driver_id;
     130                 :          0 :                 info->min_mbuf_headroom_req = OTX_CPT_MIN_HEADROOM_REQ;
     131                 :          0 :                 info->min_mbuf_tailroom_req = OTX_CPT_MIN_TAILROOM_REQ;
     132                 :            :         }
     133                 :          0 : }
     134                 :            : 
     135                 :            : static int
     136                 :          0 : otx_cpt_que_pair_setup(struct rte_cryptodev *dev,
     137                 :            :                        uint16_t que_pair_id,
     138                 :            :                        const struct rte_cryptodev_qp_conf *qp_conf,
     139                 :            :                        int socket_id __rte_unused)
     140                 :            : {
     141                 :          0 :         struct cpt_instance *instance = NULL;
     142                 :            :         struct rte_pci_device *pci_dev;
     143                 :            :         int ret = -1;
     144                 :            : 
     145                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     146                 :            : 
     147         [ #  # ]:          0 :         if (dev->data->queue_pairs[que_pair_id] != NULL) {
     148                 :          0 :                 ret = otx_cpt_que_pair_release(dev, que_pair_id);
     149         [ #  # ]:          0 :                 if (ret)
     150                 :            :                         return ret;
     151                 :            :         }
     152                 :            : 
     153         [ #  # ]:          0 :         if (qp_conf->nb_descriptors > DEFAULT_CMD_QLEN) {
     154                 :          0 :                 CPT_LOG_INFO("Number of descriptors too big %d, using default "
     155                 :            :                              "queue length of %d", qp_conf->nb_descriptors,
     156                 :            :                              DEFAULT_CMD_QLEN);
     157                 :            :         }
     158                 :            : 
     159                 :          0 :         pci_dev = RTE_DEV_TO_PCI(dev->device);
     160                 :            : 
     161         [ #  # ]:          0 :         if (pci_dev->mem_resource[0].addr == NULL) {
     162                 :          0 :                 CPT_LOG_ERR("PCI mem address null");
     163                 :          0 :                 return -EIO;
     164                 :            :         }
     165                 :            : 
     166                 :          0 :         ret = otx_cpt_get_resource(dev, 0, &instance, que_pair_id);
     167   [ #  #  #  # ]:          0 :         if (ret != 0 || instance == NULL) {
     168                 :          0 :                 CPT_LOG_ERR("Error getting instance handle from device %s : "
     169                 :            :                             "ret = %d", dev->data->name, ret);
     170                 :          0 :                 return ret;
     171                 :            :         }
     172                 :            : 
     173                 :          0 :         instance->queue_id = que_pair_id;
     174                 :          0 :         instance->sess_mp = qp_conf->mp_session;
     175                 :          0 :         dev->data->queue_pairs[que_pair_id] = instance;
     176                 :            : 
     177                 :          0 :         return 0;
     178                 :            : }
     179                 :            : 
     180                 :            : static int
     181                 :          0 : otx_cpt_que_pair_release(struct rte_cryptodev *dev, uint16_t que_pair_id)
     182                 :            : {
     183                 :          0 :         struct cpt_instance *instance = dev->data->queue_pairs[que_pair_id];
     184                 :            :         int ret;
     185                 :            : 
     186                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     187                 :            : 
     188                 :          0 :         ret = otx_cpt_put_resource(instance);
     189         [ #  # ]:          0 :         if (ret != 0) {
     190                 :          0 :                 CPT_LOG_ERR("Error putting instance handle of device %s : "
     191                 :            :                             "ret = %d", dev->data->name, ret);
     192                 :          0 :                 return ret;
     193                 :            :         }
     194                 :            : 
     195                 :          0 :         dev->data->queue_pairs[que_pair_id] = NULL;
     196                 :            : 
     197                 :          0 :         return 0;
     198                 :            : }
     199                 :            : 
     200                 :            : static unsigned int
     201                 :          0 : otx_cpt_get_session_size(struct rte_cryptodev *dev __rte_unused)
     202                 :            : {
     203                 :          0 :         return cpt_get_session_size();
     204                 :            : }
     205                 :            : 
     206                 :            : static int
     207                 :          0 : sym_xform_verify(struct rte_crypto_sym_xform *xform)
     208                 :            : {
     209         [ #  # ]:          0 :         if (xform->next) {
     210         [ #  # ]:          0 :                 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
     211         [ #  # ]:          0 :                     xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
     212         [ #  # ]:          0 :                     xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
     213         [ #  # ]:          0 :                     (xform->auth.algo != RTE_CRYPTO_AUTH_SHA1_HMAC ||
     214         [ #  # ]:          0 :                      xform->next->cipher.algo != RTE_CRYPTO_CIPHER_AES_CBC))
     215                 :            :                         return -ENOTSUP;
     216                 :            : 
     217         [ #  # ]:          0 :                 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
     218         [ #  # ]:          0 :                     xform->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
     219         [ #  # ]:          0 :                     xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
     220         [ #  # ]:          0 :                     (xform->cipher.algo != RTE_CRYPTO_CIPHER_AES_CBC ||
     221         [ #  # ]:          0 :                      xform->next->auth.algo != RTE_CRYPTO_AUTH_SHA1_HMAC))
     222                 :            :                         return -ENOTSUP;
     223                 :            : 
     224         [ #  # ]:          0 :                 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
     225         [ #  # ]:          0 :                     xform->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC &&
     226         [ #  # ]:          0 :                     xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
     227         [ #  # ]:          0 :                     xform->next->auth.algo == RTE_CRYPTO_AUTH_SHA1)
     228                 :            :                         return -ENOTSUP;
     229                 :            : 
     230         [ #  # ]:          0 :                 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
     231         [ #  # ]:          0 :                     xform->auth.algo == RTE_CRYPTO_AUTH_SHA1 &&
     232         [ #  # ]:          0 :                     xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
     233         [ #  # ]:          0 :                     xform->next->cipher.algo == RTE_CRYPTO_CIPHER_3DES_CBC)
     234                 :          0 :                         return -ENOTSUP;
     235                 :            : 
     236                 :            :         } else {
     237         [ #  # ]:          0 :                 if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
     238         [ #  # ]:          0 :                     xform->auth.algo == RTE_CRYPTO_AUTH_NULL &&
     239                 :            :                     xform->auth.op == RTE_CRYPTO_AUTH_OP_VERIFY)
     240                 :          0 :                         return -ENOTSUP;
     241                 :            :         }
     242                 :            :         return 0;
     243                 :            : }
     244                 :            : 
     245                 :            : static int
     246                 :          0 : sym_session_configure(struct rte_crypto_sym_xform *xform,
     247                 :            :                       struct rte_cryptodev_sym_session *sess)
     248                 :            : {
     249                 :            :         struct rte_crypto_sym_xform *temp_xform = xform;
     250                 :            :         struct cpt_sess_misc *misc;
     251                 :            :         vq_cmd_word3_t vq_cmd_w3;
     252                 :          0 :         void *priv = CRYPTODEV_GET_SYM_SESS_PRIV(sess);
     253                 :            :         int ret;
     254                 :            : 
     255                 :          0 :         ret = sym_xform_verify(xform);
     256         [ #  # ]:          0 :         if (unlikely(ret))
     257                 :            :                 return ret;
     258                 :            : 
     259                 :            :         memset(priv, 0, sizeof(struct cpt_sess_misc) +
     260                 :            :                         offsetof(struct cpt_ctx, mc_ctx));
     261                 :            : 
     262                 :            :         misc = priv;
     263                 :            : 
     264         [ #  # ]:          0 :         for ( ; xform != NULL; xform = xform->next) {
     265   [ #  #  #  # ]:          0 :                 switch (xform->type) {
     266                 :            :                 case RTE_CRYPTO_SYM_XFORM_AEAD:
     267                 :            :                         ret = fill_sess_aead(xform, misc);
     268                 :            :                         break;
     269                 :            :                 case RTE_CRYPTO_SYM_XFORM_CIPHER:
     270                 :            :                         ret = fill_sess_cipher(xform, misc);
     271                 :            :                         break;
     272                 :          0 :                 case RTE_CRYPTO_SYM_XFORM_AUTH:
     273         [ #  # ]:          0 :                         if (xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC)
     274                 :            :                                 ret = fill_sess_gmac(xform, misc);
     275                 :            :                         else
     276                 :            :                                 ret = fill_sess_auth(xform, misc);
     277                 :            :                         break;
     278                 :            :                 default:
     279                 :            :                         ret = -1;
     280                 :            :                 }
     281                 :            : 
     282                 :            :                 if (ret)
     283                 :          0 :                         goto priv_put;
     284                 :            :         }
     285                 :            : 
     286         [ #  # ]:          0 :         if ((GET_SESS_FC_TYPE(misc) == HASH_HMAC) &&
     287                 :            :                         cpt_mac_len_verify(&temp_xform->auth)) {
     288                 :          0 :                 CPT_LOG_ERR("MAC length is not supported");
     289                 :            :                 struct cpt_ctx *ctx = SESS_PRIV(misc);
     290         [ #  # ]:          0 :                 if (ctx->auth_key != NULL) {
     291                 :          0 :                         rte_free(ctx->auth_key);
     292                 :          0 :                         ctx->auth_key = NULL;
     293                 :            :                 }
     294                 :            :                 ret = -ENOTSUP;
     295                 :          0 :                 goto priv_put;
     296                 :            :         }
     297                 :            : 
     298                 :          0 :         misc->ctx_dma_addr = CRYPTODEV_GET_SYM_SESS_PRIV_IOVA(sess) +
     299                 :            :                              sizeof(struct cpt_sess_misc);
     300                 :            : 
     301                 :          0 :         vq_cmd_w3.u64 = 0;
     302                 :            :         vq_cmd_w3.s.grp = 0;
     303                 :          0 :         vq_cmd_w3.s.cptr = misc->ctx_dma_addr + offsetof(struct cpt_ctx,
     304                 :            :                                                          mc_ctx);
     305                 :            : 
     306                 :          0 :         misc->cpt_inst_w7 = vq_cmd_w3.u64;
     307                 :            : 
     308                 :          0 :         return 0;
     309                 :            : 
     310                 :            : priv_put:
     311                 :            :         return -ENOTSUP;
     312                 :            : }
     313                 :            : 
     314                 :            : static void
     315                 :            : sym_session_clear(struct rte_cryptodev_sym_session *sess)
     316                 :            : {
     317                 :            :         void *priv = CRYPTODEV_GET_SYM_SESS_PRIV(sess);
     318                 :            :         struct cpt_sess_misc *misc;
     319                 :            :         struct cpt_ctx *ctx;
     320                 :            : 
     321                 :            :         if (priv == NULL)
     322                 :            :                 return;
     323                 :            : 
     324                 :            :         misc = priv;
     325                 :            :         ctx = SESS_PRIV(misc);
     326                 :            : 
     327                 :          0 :         rte_free(ctx->auth_key);
     328                 :            : }
     329                 :            : 
     330                 :            : static int
     331                 :          0 : otx_cpt_session_cfg(struct rte_cryptodev *dev __rte_unused,
     332                 :            :                     struct rte_crypto_sym_xform *xform,
     333                 :            :                     struct rte_cryptodev_sym_session *sess)
     334                 :            : {
     335                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     336                 :            : 
     337                 :          0 :         return sym_session_configure(xform, sess);
     338                 :            : }
     339                 :            : 
     340                 :            : 
     341                 :            : static void
     342                 :          0 : otx_cpt_session_clear(struct rte_cryptodev *dev __rte_unused,
     343                 :            :                   struct rte_cryptodev_sym_session *sess)
     344                 :            : {
     345                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     346                 :            : 
     347                 :          0 :         return sym_session_clear(sess);
     348                 :            : }
     349                 :            : 
     350                 :            : static unsigned int
     351                 :          0 : otx_cpt_asym_session_size_get(struct rte_cryptodev *dev __rte_unused)
     352                 :            : {
     353                 :          0 :         return sizeof(struct cpt_asym_sess_misc);
     354                 :            : }
     355                 :            : 
     356                 :            : static int
     357                 :          0 : otx_cpt_asym_session_cfg(struct rte_cryptodev *dev __rte_unused,
     358                 :            :                          struct rte_crypto_asym_xform *xform __rte_unused,
     359                 :            :                          struct rte_cryptodev_asym_session *sess)
     360                 :            : {
     361                 :            :         struct cpt_asym_sess_misc *priv = (struct cpt_asym_sess_misc *)
     362                 :            :                         sess->sess_private_data;
     363                 :            :         int ret;
     364                 :            : 
     365                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     366                 :            : 
     367                 :            :         ret = cpt_fill_asym_session_parameters(priv, xform);
     368                 :            :         if (ret) {
     369                 :          0 :                 CPT_LOG_ERR("Could not configure session parameters");
     370                 :          0 :                 return ret;
     371                 :            :         }
     372                 :            : 
     373                 :          0 :         priv->cpt_inst_w7 = 0;
     374                 :            : 
     375                 :          0 :         return 0;
     376                 :            : }
     377                 :            : 
     378                 :            : static void
     379                 :          0 : otx_cpt_asym_session_clear(struct rte_cryptodev *dev,
     380                 :            :                            struct rte_cryptodev_asym_session *sess)
     381                 :            : {
     382                 :            :         struct cpt_asym_sess_misc *priv;
     383                 :            : 
     384                 :          0 :         CPT_PMD_INIT_FUNC_TRACE();
     385                 :            : 
     386   [ #  #  #  # ]:          0 :         priv = (struct cpt_asym_sess_misc *) sess->sess_private_data;
     387                 :            : 
     388                 :            :         if (priv == NULL)
     389                 :            :                 return;
     390                 :            : 
     391                 :            :         /* Free resources allocated during session configure */
     392                 :            :         cpt_free_asym_session_parameters(priv);
     393                 :            :         memset(priv, 0, otx_cpt_asym_session_size_get(dev));
     394                 :            : }
     395                 :            : 
     396                 :            : static __rte_always_inline void * __rte_hot
     397                 :            : otx_cpt_request_enqueue(struct cpt_instance *instance,
     398                 :            :                         void *req, uint64_t cpt_inst_w7)
     399                 :            : {
     400                 :            :         struct cpt_request_info *user_req = (struct cpt_request_info *)req;
     401                 :            : 
     402                 :            :         fill_cpt_inst(instance, req, cpt_inst_w7);
     403                 :            : 
     404                 :            :         CPT_LOG_DP_DEBUG("req: %p op: %p ", req, user_req->op);
     405                 :            : 
     406                 :            :         /* Fill time_out cycles */
     407                 :          0 :         user_req->time_out = rte_get_timer_cycles() +
     408                 :          0 :                         DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
     409   [ #  #  #  #  :          0 :         user_req->extra_time = 0;
          #  #  #  #  #  
                #  #  # ]
     410                 :            : 
     411                 :            :         /* Default mode of software queue */
     412                 :            :         mark_cpt_inst(instance);
     413                 :            : 
     414                 :            :         CPT_LOG_DP_DEBUG("Submitted NB cmd with request: %p "
     415                 :            :                          "op: %p", user_req, user_req->op);
     416                 :            :         return req;
     417                 :            : }
     418                 :            : 
     419                 :            : static __rte_always_inline void * __rte_hot
     420                 :            : otx_cpt_enq_single_asym(struct cpt_instance *instance,
     421                 :            :                         struct rte_crypto_op *op)
     422                 :            : {
     423                 :            :         struct cpt_qp_meta_info *minfo = &instance->meta_info;
     424                 :            :         struct rte_crypto_asym_op *asym_op = op->asym;
     425                 :            :         struct asym_op_params params = {0};
     426                 :            :         struct cpt_asym_sess_misc *sess;
     427                 :            :         uintptr_t *cop;
     428                 :            :         void *mdata;
     429                 :            :         void *req;
     430                 :            :         int ret;
     431                 :            : 
     432   [ #  #  #  #  :          0 :         if (unlikely(rte_mempool_get(minfo->pool, &mdata) < 0)) {
             #  #  #  # ]
     433                 :          0 :                 CPT_LOG_DP_ERR("Could not allocate meta buffer for request");
     434                 :          0 :                 rte_errno = ENOMEM;
     435                 :          0 :                 return NULL;
     436                 :            :         }
     437                 :            : 
     438                 :            :         sess = (struct cpt_asym_sess_misc *)
     439                 :          0 :                         asym_op->session->sess_private_data;
     440                 :            : 
     441                 :            :         /* Store phys_addr of the mdata to meta_buf */
     442                 :          0 :         params.meta_buf = rte_mempool_virt2iova(mdata);
     443                 :            : 
     444                 :            :         cop = mdata;
     445                 :          0 :         cop[0] = (uintptr_t)mdata;
     446                 :          0 :         cop[1] = (uintptr_t)op;
     447                 :          0 :         cop[2] = cop[3] = 0ULL;
     448                 :            : 
     449                 :          0 :         params.req = RTE_PTR_ADD(cop, 4 * sizeof(uintptr_t));
     450                 :          0 :         params.req->op = cop;
     451                 :            : 
     452                 :            :         /* Adjust meta_buf by crypto_op data  and request_info struct */
     453                 :          0 :         params.meta_buf += (4 * sizeof(uintptr_t)) +
     454                 :            :                            sizeof(struct cpt_request_info);
     455                 :            : 
     456   [ #  #  #  #  :          0 :         switch (sess->xfrm_type) {
          #  #  #  #  #  
                      # ]
     457   [ #  #  #  # ]:          0 :         case RTE_CRYPTO_ASYM_XFORM_MODEX:
     458                 :            :                 ret = cpt_modex_prep(&params, &sess->mod_ctx);
     459   [ #  #  #  # ]:          0 :                 if (unlikely(ret))
     460                 :          0 :                         goto req_fail;
     461                 :            :                 break;
     462                 :            :         case RTE_CRYPTO_ASYM_XFORM_RSA:
     463                 :            :                 ret = cpt_enqueue_rsa_op(op, &params, sess);
     464   [ #  #  #  # ]:          0 :                 if (unlikely(ret))
     465                 :          0 :                         goto req_fail;
     466                 :            :                 break;
     467                 :            :         case RTE_CRYPTO_ASYM_XFORM_ECDSA:
     468                 :            :                 ret = cpt_enqueue_ecdsa_op(op, &params, sess, otx_fpm_iova);
     469   [ #  #  #  # ]:          0 :                 if (unlikely(ret))
     470                 :          0 :                         goto req_fail;
     471                 :            :                 break;
     472                 :          0 :         case RTE_CRYPTO_ASYM_XFORM_ECPM:
     473                 :          0 :                 ret = cpt_ecpm_prep(&asym_op->ecpm, &params,
     474                 :          0 :                                     sess->ec_ctx.curveid);
     475                 :            :                 if (unlikely(ret))
     476                 :            :                         goto req_fail;
     477                 :            :                 break;
     478                 :            : 
     479                 :          0 :         default:
     480                 :          0 :                 op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
     481                 :          0 :                 rte_errno = EINVAL;
     482                 :          0 :                 goto req_fail;
     483                 :            :         }
     484                 :            : 
     485                 :          0 :         req = otx_cpt_request_enqueue(instance, params.req, sess->cpt_inst_w7);
     486                 :            :         if (unlikely(req == NULL)) {
     487                 :            :                 CPT_LOG_DP_ERR("Could not enqueue crypto req");
     488                 :            :                 goto req_fail;
     489                 :            :         }
     490                 :            : 
     491                 :            :         return req;
     492                 :            : 
     493                 :          0 : req_fail:
     494   [ #  #  #  # ]:          0 :         free_op_meta(mdata, minfo->pool);
     495                 :            : 
     496                 :            :         return NULL;
     497                 :            : }
     498                 :            : 
     499                 :            : static __rte_always_inline void * __rte_hot
     500                 :            : otx_cpt_enq_single_sym(struct cpt_instance *instance,
     501                 :            :                        struct rte_crypto_op *op)
     502                 :            : {
     503                 :            :         struct cpt_sess_misc *sess;
     504                 :            :         struct rte_crypto_sym_op *sym_op = op->sym;
     505                 :            :         struct cpt_request_info *prep_req;
     506                 :            :         void *mdata = NULL;
     507                 :            :         int ret = 0;
     508                 :            :         void *req;
     509                 :            :         uint64_t cpt_op;
     510                 :            : 
     511                 :          0 :         sess = CRYPTODEV_GET_SYM_SESS_PRIV(sym_op->session);
     512                 :          0 :         cpt_op = sess->cpt_op;
     513                 :            : 
     514   [ #  #  #  # ]:          0 :         if (likely(cpt_op & CPT_OP_CIPHER_MASK))
     515                 :            :                 ret = fill_fc_params(op, sess, &instance->meta_info, &mdata,
     516                 :            :                                      (void **)&prep_req);
     517                 :            :         else
     518                 :            :                 ret = fill_digest_params(op, sess, &instance->meta_info,
     519                 :            :                                          &mdata, (void **)&prep_req);
     520                 :            : 
     521   [ #  #  #  #  :          0 :         if (unlikely(ret)) {
             #  #  #  # ]
     522                 :          0 :                 CPT_LOG_DP_ERR("prep crypto req : op %p, cpt_op 0x%x "
     523                 :            :                                "ret 0x%x", op, (unsigned int)cpt_op, ret);
     524                 :          0 :                 return NULL;
     525                 :            :         }
     526                 :            : 
     527                 :            :         /* Enqueue prepared instruction to h/w */
     528                 :          0 :         req = otx_cpt_request_enqueue(instance, prep_req, sess->cpt_inst_w7);
     529                 :            :         if (unlikely(req == NULL))
     530                 :            :                 /* Buffer allocated for request preparation need to be freed */
     531                 :            :                 free_op_meta(mdata, instance->meta_info.pool);
     532                 :            : 
     533                 :            :         return req;
     534                 :            : }
     535                 :            : 
     536                 :            : static __rte_always_inline void * __rte_hot
     537                 :            : otx_cpt_enq_single_sym_sessless(struct cpt_instance *instance,
     538                 :            :                                 struct rte_crypto_op *op)
     539                 :            : {
     540                 :            :         struct rte_crypto_sym_op *sym_op = op->sym;
     541                 :            :         struct rte_cryptodev_sym_session *sess;
     542                 :            :         void *req;
     543                 :            :         int ret;
     544                 :            : 
     545                 :            :         /* Create temporary session */
     546   [ #  #  #  #  :          0 :         if (rte_mempool_get(instance->sess_mp, (void **)&sess) < 0) {
             #  #  #  # ]
     547                 :          0 :                 rte_errno = ENOMEM;
     548                 :          0 :                 return NULL;
     549                 :            :         }
     550                 :            : 
     551                 :          0 :         ret = sym_session_configure(sym_op->xform, sess);
     552   [ #  #  #  # ]:          0 :         if (ret)
     553                 :          0 :                 goto sess_put;
     554                 :            : 
     555   [ #  #  #  # ]:          0 :         sym_op->session = sess;
     556                 :            : 
     557                 :            :         /* Enqueue op with the tmp session set */
     558                 :            :         req = otx_cpt_enq_single_sym(instance, op);
     559   [ #  #  #  # ]:          0 :         if (unlikely(req == NULL))
     560                 :          0 :                 goto sess_put;
     561                 :            : 
     562                 :            :         return req;
     563                 :            : 
     564                 :          0 : sess_put:
     565   [ #  #  #  # ]:          0 :         rte_mempool_put(instance->sess_mp, sess);
     566                 :          0 :         return NULL;
     567                 :            : }
     568                 :            : 
     569                 :            : #define OP_TYPE_SYM             0
     570                 :            : #define OP_TYPE_ASYM            1
     571                 :            : 
     572                 :            : static __rte_always_inline void *__rte_hot
     573                 :            : otx_cpt_enq_single(struct cpt_instance *inst,
     574                 :            :                    struct rte_crypto_op *op,
     575                 :            :                    const uint8_t op_type)
     576                 :            : {
     577                 :            :         /* Check for the type */
     578                 :            : 
     579                 :          0 :         if (op_type == OP_TYPE_SYM) {
     580         [ #  # ]:          0 :                 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
     581                 :            :                         return otx_cpt_enq_single_sym(inst, op);
     582                 :            :                 else
     583                 :          0 :                         return otx_cpt_enq_single_sym_sessless(inst, op);
     584                 :            :         }
     585                 :            : 
     586                 :            :         if (op_type == OP_TYPE_ASYM) {
     587         [ #  # ]:          0 :                 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
     588                 :          0 :                         return otx_cpt_enq_single_asym(inst, op);
     589                 :            :         }
     590                 :            : 
     591                 :            :         /* Should not reach here */
     592                 :          0 :         rte_errno = ENOTSUP;
     593                 :          0 :         return NULL;
     594                 :            : }
     595                 :            : 
     596                 :            : static  __rte_always_inline uint16_t __rte_hot
     597                 :            : otx_cpt_pkt_enqueue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
     598                 :            :                     const uint8_t op_type)
     599                 :            : {
     600                 :            :         struct cpt_instance *instance = (struct cpt_instance *)qptr;
     601                 :            :         uint16_t count, free_slots;
     602                 :            :         void *req;
     603                 :            :         struct cpt_vf *cptvf = (struct cpt_vf *)instance;
     604                 :            :         struct pending_queue *pqueue = &cptvf->pqueue;
     605                 :            : 
     606                 :          0 :         free_slots = pending_queue_free_slots(pqueue, DEFAULT_CMD_QLEN,
     607                 :            :                                 DEFAULT_CMD_QRSVD_SLOTS);
     608                 :            :         if (nb_ops > free_slots)
     609                 :            :                 nb_ops = free_slots;
     610                 :            : 
     611                 :            :         count = 0;
     612   [ #  #  #  # ]:          0 :         while (likely(count < nb_ops)) {
     613                 :            : 
     614                 :            :                 /* Enqueue single op */
     615   [ #  #  #  # ]:          0 :                 req = otx_cpt_enq_single(instance, ops[count], op_type);
     616                 :            : 
     617   [ #  #  #  # ]:          0 :                 if (unlikely(req == NULL))
     618                 :            :                         break;
     619                 :            : 
     620                 :          0 :                 pending_queue_push(pqueue, req, count, DEFAULT_CMD_QLEN);
     621                 :          0 :                 count++;
     622                 :            :         }
     623                 :            : 
     624   [ #  #  #  # ]:          0 :         if (likely(count)) {
     625                 :          0 :                 pending_queue_commit(pqueue, count, DEFAULT_CMD_QLEN);
     626                 :            :                 otx_cpt_ring_dbell(instance, count);
     627                 :            :         }
     628                 :            :         return count;
     629                 :            : }
     630                 :            : 
     631                 :            : static uint16_t
     632         [ #  # ]:          0 : otx_cpt_enqueue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
     633                 :            : {
     634                 :          0 :         return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_ASYM);
     635                 :            : }
     636                 :            : 
     637                 :            : static uint16_t
     638         [ #  # ]:          0 : otx_cpt_enqueue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
     639                 :            : {
     640                 :          0 :         return otx_cpt_pkt_enqueue(qptr, ops, nb_ops, OP_TYPE_SYM);
     641                 :            : }
     642                 :            : 
     643                 :            : static __rte_always_inline void
     644                 :            : submit_request_to_sso(struct ssows *ws, uintptr_t req,
     645                 :            :                       struct rte_event *rsp_info)
     646                 :            : {
     647                 :            :         uint64_t add_work;
     648                 :            : 
     649                 :          0 :         add_work = rsp_info->flow_id | (RTE_EVENT_TYPE_CRYPTODEV << 28) |
     650                 :          0 :                    (rsp_info->sub_event_type << 20) |
     651                 :          0 :                    ((uint64_t)(rsp_info->sched_type) << 32);
     652                 :            : 
     653                 :          0 :         if (!rsp_info->sched_type)
     654                 :            :                 ssows_head_wait(ws);
     655                 :            : 
     656                 :            :         rte_atomic_thread_fence(rte_memory_order_release);
     657                 :          0 :         ssovf_store_pair(add_work, req, ws->grps[rsp_info->queue_id]);
     658                 :            : }
     659                 :            : 
     660                 :            : RTE_EXPORT_INTERNAL_SYMBOL(otx_crypto_adapter_enqueue)
     661                 :            : uint16_t __rte_hot
     662                 :          0 : otx_crypto_adapter_enqueue(void *port, struct rte_crypto_op *op)
     663                 :            : {
     664                 :            :         union rte_event_crypto_metadata *ec_mdata;
     665                 :            :         struct cpt_instance *instance;
     666                 :            :         struct cpt_request_info *req;
     667                 :            :         struct rte_event *rsp_info;
     668                 :            :         uint8_t op_type, cdev_id;
     669                 :            :         uint16_t qp_id;
     670                 :            : 
     671                 :          0 :         ec_mdata = rte_cryptodev_session_event_mdata_get(op);
     672         [ #  # ]:          0 :         if (unlikely(ec_mdata == NULL)) {
     673                 :          0 :                 rte_errno = EINVAL;
     674                 :          0 :                 return 0;
     675                 :            :         }
     676                 :            : 
     677                 :          0 :         cdev_id = ec_mdata->request_info.cdev_id;
     678                 :          0 :         qp_id = ec_mdata->request_info.queue_pair_id;
     679                 :            :         rsp_info = &ec_mdata->response_info;
     680                 :          0 :         instance = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
     681                 :            : 
     682         [ #  # ]:          0 :         if (unlikely(!instance->ca_enabled)) {
     683                 :          0 :                 rte_errno = EINVAL;
     684                 :          0 :                 return 0;
     685                 :            :         }
     686                 :            : 
     687         [ #  # ]:          0 :         op_type = op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC ? OP_TYPE_SYM :
     688                 :            :                                                              OP_TYPE_ASYM;
     689                 :            :         req = otx_cpt_enq_single(instance, op, op_type);
     690         [ #  # ]:          0 :         if (unlikely(req == NULL))
     691                 :            :                 return 0;
     692                 :            : 
     693                 :            :         otx_cpt_ring_dbell(instance, 1);
     694                 :          0 :         req->qp = instance;
     695         [ #  # ]:          0 :         submit_request_to_sso(port, (uintptr_t)req, rsp_info);
     696                 :            : 
     697                 :          0 :         return 1;
     698                 :            : }
     699                 :            : 
     700                 :            : static inline void
     701                 :          0 : otx_cpt_asym_rsa_op(struct rte_crypto_op *cop, struct cpt_request_info *req,
     702                 :            :                     struct rte_crypto_rsa_xform *rsa_ctx)
     703                 :            : 
     704                 :            : {
     705                 :            :         struct rte_crypto_rsa_op_param *rsa = &cop->asym->rsa;
     706                 :            : 
     707   [ #  #  #  #  :          0 :         switch (rsa->op_type) {
                      # ]
     708                 :          0 :         case RTE_CRYPTO_ASYM_OP_ENCRYPT:
     709                 :          0 :                 rsa->cipher.length = rsa_ctx->n.length;
     710                 :          0 :                 memcpy(rsa->cipher.data, req->rptr, rsa->cipher.length);
     711                 :            :                 break;
     712                 :          0 :         case RTE_CRYPTO_ASYM_OP_DECRYPT:
     713         [ #  # ]:          0 :                 if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
     714                 :          0 :                         rsa->message.length = rsa_ctx->n.length;
     715                 :            :                 else {
     716                 :            :                         /* Get length of decrypted output */
     717         [ #  # ]:          0 :                         rsa->message.length = rte_cpu_to_be_16
     718                 :            :                                         (*((uint16_t *)req->rptr));
     719                 :            : 
     720                 :            :                         /* Offset data pointer by length fields */
     721                 :          0 :                         req->rptr += 2;
     722                 :            :                 }
     723                 :          0 :                 memcpy(rsa->message.data, req->rptr, rsa->message.length);
     724                 :            :                 break;
     725                 :          0 :         case RTE_CRYPTO_ASYM_OP_SIGN:
     726                 :          0 :                 rsa->sign.length = rsa_ctx->n.length;
     727                 :          0 :                 memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
     728                 :            :                 break;
     729                 :          0 :         case RTE_CRYPTO_ASYM_OP_VERIFY:
     730         [ #  # ]:          0 :                 if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE)
     731                 :          0 :                         rsa->sign.length = rsa_ctx->n.length;
     732                 :            :                 else {
     733                 :            :                         /* Get length of decrypted output */
     734         [ #  # ]:          0 :                         rsa->sign.length = rte_cpu_to_be_16
     735                 :            :                                         (*((uint16_t *)req->rptr));
     736                 :            : 
     737                 :            :                         /* Offset data pointer by length fields */
     738                 :          0 :                         req->rptr += 2;
     739                 :            :                 }
     740         [ #  # ]:          0 :                 memcpy(rsa->sign.data, req->rptr, rsa->sign.length);
     741                 :            : 
     742         [ #  # ]:          0 :                 if (memcmp(rsa->sign.data, rsa->message.data,
     743                 :            :                            rsa->message.length)) {
     744                 :          0 :                         CPT_LOG_DP_ERR("RSA verification failed");
     745                 :          0 :                         cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
     746                 :            :                 }
     747                 :            :                 break;
     748                 :          0 :         default:
     749                 :            :                 CPT_LOG_DP_DEBUG("Invalid RSA operation type");
     750                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
     751                 :          0 :                 break;
     752                 :            :         }
     753                 :          0 : }
     754                 :            : 
     755                 :            : static __rte_always_inline void
     756                 :            : otx_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa,
     757                 :            :                             struct cpt_request_info *req,
     758                 :            :                             struct cpt_asym_ec_ctx *ec)
     759                 :            : 
     760                 :            : {
     761                 :          0 :         int prime_len = ec_grp[ec->curveid].prime.length;
     762                 :            : 
     763                 :          0 :         if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
     764                 :            :                 return;
     765                 :            : 
     766                 :            :         /* Separate out sign r and s components */
     767                 :          0 :         memcpy(ecdsa->r.data, req->rptr, prime_len);
     768                 :          0 :         memcpy(ecdsa->s.data, req->rptr + RTE_ALIGN_CEIL(prime_len, 8),
     769                 :            :                prime_len);
     770                 :          0 :         ecdsa->r.length = prime_len;
     771                 :          0 :         ecdsa->s.length = prime_len;
     772                 :            : }
     773                 :            : 
     774                 :            : static __rte_always_inline void
     775                 :            : otx_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm,
     776                 :            :                              struct cpt_request_info *req,
     777                 :            :                              struct cpt_asym_ec_ctx *ec)
     778                 :            : {
     779                 :          0 :         int prime_len = ec_grp[ec->curveid].prime.length;
     780                 :            : 
     781                 :          0 :         memcpy(ecpm->r.x.data, req->rptr, prime_len);
     782                 :          0 :         memcpy(ecpm->r.y.data, req->rptr + RTE_ALIGN_CEIL(prime_len, 8),
     783                 :            :                prime_len);
     784                 :          0 :         ecpm->r.x.length = prime_len;
     785                 :          0 :         ecpm->r.y.length = prime_len;
     786                 :          0 : }
     787                 :            : 
     788                 :            : static __rte_always_inline void __rte_hot
     789                 :            : otx_cpt_asym_post_process(struct rte_crypto_op *cop,
     790                 :            :                           struct cpt_request_info *req)
     791                 :            : {
     792                 :            :         struct rte_crypto_asym_op *op = cop->asym;
     793                 :            :         struct cpt_asym_sess_misc *sess;
     794                 :            : 
     795                 :          0 :         sess = (struct cpt_asym_sess_misc *) op->session->sess_private_data;
     796                 :            : 
     797                 :          0 :         switch (sess->xfrm_type) {
     798                 :          0 :         case RTE_CRYPTO_ASYM_XFORM_RSA:
     799                 :          0 :                 otx_cpt_asym_rsa_op(cop, req, &sess->rsa_ctx);
     800                 :          0 :                 break;
     801                 :          0 :         case RTE_CRYPTO_ASYM_XFORM_MODEX:
     802                 :          0 :                 op->modex.result.length = sess->mod_ctx.modulus.length;
     803                 :          0 :                 memcpy(op->modex.result.data, req->rptr,
     804                 :            :                        op->modex.result.length);
     805                 :            :                 break;
     806   [ #  #  #  # ]:          0 :         case RTE_CRYPTO_ASYM_XFORM_ECDSA:
     807                 :            :                 otx_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx);
     808                 :            :                 break;
     809                 :          0 :         case RTE_CRYPTO_ASYM_XFORM_ECPM:
     810                 :            :                 otx_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx);
     811                 :            :                 break;
     812                 :          0 :         default:
     813                 :            :                 CPT_LOG_DP_DEBUG("Invalid crypto xform type");
     814                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
     815                 :          0 :                 break;
     816                 :            :         }
     817                 :            : }
     818                 :            : 
     819                 :            : static __rte_always_inline void __rte_hot
     820                 :            : otx_cpt_dequeue_post_process(struct rte_crypto_op *cop, uintptr_t *rsp,
     821                 :            :                              const uint8_t op_type)
     822                 :            : {
     823                 :            :         /* H/w has returned success */
     824                 :          0 :         cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
     825                 :            : 
     826                 :            :         /* Perform further post processing */
     827                 :            : 
     828         [ #  # ]:          0 :         if ((op_type == OP_TYPE_SYM) &&
     829   [ #  #  #  # ]:          0 :             (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC)) {
     830                 :            :                 /* Check if auth verify need to be completed */
     831   [ #  #  #  # ]:          0 :                 if (unlikely(rsp[2]))
     832   [ #  #  #  # ]:          0 :                         compl_auth_verify(cop, (uint8_t *)rsp[2], rsp[3]);
     833                 :            :                 return;
     834                 :            :         }
     835                 :            : 
     836         [ #  # ]:          0 :         if ((op_type == OP_TYPE_ASYM) &&
     837   [ #  #  #  # ]:          0 :             (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC)) {
     838   [ #  #  #  #  :          0 :                 rsp = RTE_PTR_ADD(rsp, 4 * sizeof(uintptr_t));
          #  #  #  #  #  
                      # ]
     839                 :            :                 otx_cpt_asym_post_process(cop, (struct cpt_request_info *)rsp);
     840                 :            :         }
     841                 :            : 
     842                 :            :         return;
     843                 :            : }
     844                 :            : 
     845                 :            : static inline void
     846                 :          0 : free_sym_session_data(const struct cpt_instance *instance,
     847                 :            :                       struct rte_crypto_op *cop)
     848                 :            : {
     849         [ #  # ]:          0 :         void *sess_private_data_t = CRYPTODEV_GET_SYM_SESS_PRIV(cop->sym->session);
     850                 :            : 
     851                 :            :         memset(sess_private_data_t, 0, cpt_get_session_size());
     852         [ #  # ]:          0 :         rte_mempool_put(instance->sess_mp, cop->sym->session);
     853                 :          0 :         cop->sym->session = NULL;
     854                 :          0 : }
     855                 :            : 
     856                 :            : static __rte_always_inline struct rte_crypto_op *
     857                 :            : otx_cpt_process_response(const struct cpt_instance *instance, uintptr_t *rsp,
     858                 :            :                          uint8_t cc, const uint8_t op_type)
     859                 :            : {
     860                 :            :         struct rte_crypto_op *cop;
     861                 :            :         void *metabuf;
     862                 :            : 
     863                 :          0 :         metabuf = (void *)rsp[0];
     864                 :          0 :         cop = (void *)rsp[1];
     865                 :            : 
     866                 :            :         /* Check completion code */
     867                 :          0 :         if (likely(cc == 0)) {
     868                 :            :                 /* H/w success pkt. Post process */
     869                 :            :                 otx_cpt_dequeue_post_process(cop, rsp, op_type);
     870   [ #  #  #  #  :          0 :         } else if (cc == ERR_GC_ICV_MISCOMPARE) {
                   #  # ]
     871                 :            :                 /* auth data mismatch */
     872                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
     873                 :            :         } else {
     874                 :            :                 /* Error */
     875                 :          0 :                 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
     876                 :            :         }
     877                 :            : 
     878   [ #  #  #  #  :          0 :         if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS))
                   #  # ]
     879                 :          0 :                 free_sym_session_data(instance, cop);
     880   [ #  #  #  #  :          0 :         free_op_meta(metabuf, instance->meta_info.pool);
                   #  # ]
     881                 :            : 
     882                 :            :         return cop;
     883                 :            : }
     884                 :            : 
     885                 :            : static __rte_always_inline uint16_t __rte_hot
     886                 :            : otx_cpt_pkt_dequeue(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops,
     887                 :            :                     const uint8_t op_type)
     888                 :          0 : {
     889                 :            :         struct cpt_instance *instance = (struct cpt_instance *)qptr;
     890                 :            :         struct cpt_request_info *user_req;
     891                 :            :         struct cpt_vf *cptvf = (struct cpt_vf *)instance;
     892                 :          0 :         uint8_t cc[nb_ops];
     893                 :            :         int i, count, pcount;
     894                 :            :         uint8_t ret;
     895                 :            :         int nb_completed;
     896                 :            :         struct pending_queue *pqueue = &cptvf->pqueue;
     897                 :            : 
     898                 :          0 :         pcount = pending_queue_level(pqueue, DEFAULT_CMD_QLEN);
     899                 :            : 
     900                 :            :         /* Ensure pcount isn't read before data lands */
     901                 :            :         rte_atomic_thread_fence(rte_memory_order_acquire);
     902                 :            : 
     903                 :          0 :         count = (nb_ops > pcount) ? pcount : nb_ops;
     904                 :            : 
     905   [ #  #  #  # ]:          0 :         for (i = 0; i < count; i++) {
     906                 :          0 :                 pending_queue_peek(pqueue, (void **) &user_req,
     907   [ #  #  #  # ]:          0 :                         DEFAULT_CMD_QLEN, i + 1 < count);
     908                 :            : 
     909                 :            :                 ret = check_nb_command_id(user_req, instance);
     910                 :            : 
     911   [ #  #  #  # ]:          0 :                 if (unlikely(ret == ERR_REQ_PENDING)) {
     912                 :            :                         /* Stop checking for completions */
     913                 :            :                         break;
     914                 :            :                 }
     915                 :            : 
     916                 :            :                 /* Return completion code and op handle */
     917                 :          0 :                 cc[i] = ret;
     918                 :          0 :                 ops[i] = user_req->op;
     919                 :            : 
     920                 :            :                 CPT_LOG_DP_DEBUG("Request %p Op %p completed with code %d",
     921                 :            :                                  user_req, user_req->op, ret);
     922                 :            : 
     923                 :            :                 pending_queue_pop(pqueue, DEFAULT_CMD_QLEN);
     924                 :            :         }
     925                 :            : 
     926                 :            :         nb_completed = i;
     927                 :            : 
     928   [ #  #  #  # ]:          0 :         for (i = 0; i < nb_completed; i++) {
     929   [ #  #  #  # ]:          0 :                 if (likely((i + 1) < nb_completed))
     930                 :          0 :                         rte_prefetch0(ops[i+1]);
     931                 :            : 
     932                 :          0 :                 ops[i] = otx_cpt_process_response(instance, (void *)ops[i],
     933   [ #  #  #  # ]:          0 :                                                   cc[i], op_type);
     934                 :            :         }
     935                 :            : 
     936                 :          0 :         return nb_completed;
     937                 :            : }
     938                 :            : 
     939                 :            : static uint16_t
     940                 :          0 : otx_cpt_dequeue_asym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
     941                 :            : {
     942                 :          0 :         return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_ASYM);
     943                 :            : }
     944                 :            : 
     945                 :            : static uint16_t
     946                 :          0 : otx_cpt_dequeue_sym(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
     947                 :            : {
     948                 :          0 :         return otx_cpt_pkt_dequeue(qptr, ops, nb_ops, OP_TYPE_SYM);
     949                 :            : }
     950                 :            : 
     951                 :            : RTE_EXPORT_INTERNAL_SYMBOL(otx_crypto_adapter_dequeue)
     952                 :            : uintptr_t __rte_hot
     953                 :          0 : otx_crypto_adapter_dequeue(uintptr_t get_work1)
     954                 :            : {
     955                 :            :         const struct cpt_instance *instance;
     956                 :            :         struct cpt_request_info *req;
     957                 :            :         struct rte_crypto_op *cop;
     958                 :            :         uint8_t cc, op_type;
     959                 :            :         uintptr_t *rsp;
     960                 :            : 
     961                 :          0 :         req = (struct cpt_request_info *)get_work1;
     962                 :          0 :         instance = req->qp;
     963                 :          0 :         rsp = req->op;
     964                 :          0 :         cop = (void *)rsp[1];
     965                 :          0 :         op_type = cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC ? OP_TYPE_SYM :
     966                 :            :                                                               OP_TYPE_ASYM;
     967                 :            : 
     968                 :            :         do {
     969                 :            :                 cc = check_nb_command_id(
     970                 :            :                         req, (struct cpt_instance *)(uintptr_t)instance);
     971         [ #  # ]:          0 :         } while (cc == ERR_REQ_PENDING);
     972                 :            : 
     973         [ #  # ]:          0 :         cop = otx_cpt_process_response(instance, (void *)req->op, cc, op_type);
     974                 :            : 
     975                 :          0 :         return (uintptr_t)(cop);
     976                 :            : }
     977                 :            : 
     978                 :            : static struct rte_cryptodev_ops cptvf_ops = {
     979                 :            :         /* Device related operations */
     980                 :            :         .dev_configure = otx_cpt_dev_config,
     981                 :            :         .dev_start = otx_cpt_dev_start,
     982                 :            :         .dev_stop = otx_cpt_dev_stop,
     983                 :            :         .dev_close = otx_cpt_dev_close,
     984                 :            :         .dev_infos_get = otx_cpt_dev_info_get,
     985                 :            : 
     986                 :            :         .stats_get = NULL,
     987                 :            :         .stats_reset = NULL,
     988                 :            :         .queue_pair_setup = otx_cpt_que_pair_setup,
     989                 :            :         .queue_pair_release = otx_cpt_que_pair_release,
     990                 :            : 
     991                 :            :         /* Crypto related operations */
     992                 :            :         .sym_session_get_size = otx_cpt_get_session_size,
     993                 :            :         .sym_session_configure = otx_cpt_session_cfg,
     994                 :            :         .sym_session_clear = otx_cpt_session_clear,
     995                 :            : 
     996                 :            :         .asym_session_get_size = otx_cpt_asym_session_size_get,
     997                 :            :         .asym_session_configure = otx_cpt_asym_session_cfg,
     998                 :            :         .asym_session_clear = otx_cpt_asym_session_clear,
     999                 :            : };
    1000                 :            : 
    1001                 :            : int
    1002                 :          0 : otx_cpt_dev_create(struct rte_cryptodev *c_dev)
    1003                 :            : {
    1004                 :          0 :         struct rte_pci_device *pdev = RTE_DEV_TO_PCI(c_dev->device);
    1005                 :            :         struct cpt_vf *cptvf = NULL;
    1006                 :            :         void *reg_base;
    1007                 :            :         char dev_name[32];
    1008                 :            :         int ret;
    1009                 :            : 
    1010         [ #  # ]:          0 :         if (pdev->mem_resource[0].phys_addr == 0ULL)
    1011                 :            :                 return -EIO;
    1012                 :            : 
    1013                 :            :         /* for secondary processes, we don't initialise any further as primary
    1014                 :            :          * has already done this work.
    1015                 :            :          */
    1016         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1017                 :            :                 return 0;
    1018                 :            : 
    1019                 :          0 :         cptvf = rte_zmalloc_socket("otx_cryptodev_private_mem",
    1020                 :            :                         sizeof(struct cpt_vf), RTE_CACHE_LINE_SIZE,
    1021                 :          0 :                         rte_socket_id());
    1022                 :            : 
    1023         [ #  # ]:          0 :         if (cptvf == NULL) {
    1024                 :          0 :                 CPT_LOG_ERR("Cannot allocate memory for device private data");
    1025                 :          0 :                 return -ENOMEM;
    1026                 :            :         }
    1027                 :            : 
    1028                 :          0 :         snprintf(dev_name, 32, "%02x:%02x.%x",
    1029         [ #  # ]:          0 :                         pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
    1030                 :            : 
    1031                 :          0 :         reg_base = pdev->mem_resource[0].addr;
    1032         [ #  # ]:          0 :         if (!reg_base) {
    1033                 :          0 :                 CPT_LOG_ERR("Failed to map BAR0 of %s", dev_name);
    1034                 :            :                 ret = -ENODEV;
    1035                 :          0 :                 goto fail;
    1036                 :            :         }
    1037                 :            : 
    1038                 :          0 :         ret = otx_cpt_hw_init(cptvf, pdev, reg_base, dev_name);
    1039         [ #  # ]:          0 :         if (ret) {
    1040                 :          0 :                 CPT_LOG_ERR("Failed to init cptvf %s", dev_name);
    1041                 :            :                 ret = -EIO;
    1042                 :          0 :                 goto fail;
    1043                 :            :         }
    1044                 :            : 
    1045      [ #  #  # ]:          0 :         switch (cptvf->vftype) {
    1046                 :          0 :         case OTX_CPT_VF_TYPE_AE:
    1047                 :            :                 /* Set asymmetric cpt feature flags */
    1048                 :          0 :                 c_dev->feature_flags = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO |
    1049                 :            :                                 RTE_CRYPTODEV_FF_HW_ACCELERATED |
    1050                 :            :                                 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT;
    1051                 :          0 :                 break;
    1052                 :          0 :         case OTX_CPT_VF_TYPE_SE:
    1053                 :            :                 /* Set symmetric cpt feature flags */
    1054                 :          0 :                 c_dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
    1055                 :            :                                 RTE_CRYPTODEV_FF_HW_ACCELERATED |
    1056                 :            :                                 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
    1057                 :            :                                 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
    1058                 :            :                                 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT |
    1059                 :            :                                 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
    1060                 :            :                                 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
    1061                 :            :                                 RTE_CRYPTODEV_FF_SYM_SESSIONLESS |
    1062                 :            :                                 RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED;
    1063                 :          0 :                 break;
    1064                 :          0 :         default:
    1065                 :            :                 /* Feature not supported. Abort */
    1066                 :          0 :                 CPT_LOG_ERR("VF type not supported by %s", dev_name);
    1067                 :            :                 ret = -EIO;
    1068                 :          0 :                 goto deinit_dev;
    1069                 :            :         }
    1070                 :            : 
    1071                 :            :         /* Start off timer for mailbox interrupts */
    1072                 :            :         otx_cpt_periodic_alarm_start(cptvf);
    1073                 :            : 
    1074                 :          0 :         c_dev->dev_ops = &cptvf_ops;
    1075                 :            : 
    1076         [ #  # ]:          0 :         if (c_dev->feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) {
    1077                 :          0 :                 c_dev->enqueue_burst = otx_cpt_enqueue_sym;
    1078                 :          0 :                 c_dev->dequeue_burst = otx_cpt_dequeue_sym;
    1079                 :            :         } else {
    1080                 :          0 :                 c_dev->enqueue_burst = otx_cpt_enqueue_asym;
    1081                 :          0 :                 c_dev->dequeue_burst = otx_cpt_dequeue_asym;
    1082                 :            :         }
    1083                 :            : 
    1084                 :            :         /* Save dev private data */
    1085                 :          0 :         c_dev->data->dev_private = cptvf;
    1086                 :            : 
    1087                 :          0 :         return 0;
    1088                 :            : 
    1089                 :            : deinit_dev:
    1090                 :          0 :         otx_cpt_deinit_device(cptvf);
    1091                 :            : 
    1092                 :          0 : fail:
    1093                 :            :         if (cptvf) {
    1094                 :            :                 /* Free private data allocated */
    1095                 :          0 :                 rte_free(cptvf);
    1096                 :            :         }
    1097                 :            : 
    1098                 :          0 :         return ret;
    1099                 :            : }

Generated by: LCOV version 1.14