LCOV - code coverage report
Current view: top level - drivers/crypto/cnxk - cnxk_cryptodev_ops.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 11 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 112 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef _CNXK_CRYPTODEV_OPS_H_
       6                 :            : #define _CNXK_CRYPTODEV_OPS_H_
       7                 :            : 
       8                 :            : #include <cryptodev_pmd.h>
       9                 :            : #include <rte_event_crypto_adapter.h>
      10                 :            : 
      11                 :            : #include "hw/cpt.h"
      12                 :            : 
      13                 :            : #include "roc_constants.h"
      14                 :            : #include "roc_cpt.h"
      15                 :            : #include "roc_cpt_sg.h"
      16                 :            : #include "roc_errata.h"
      17                 :            : #include "roc_se.h"
      18                 :            : 
      19                 :            : /* Space for ctrl_word(8B), IV(48B), passthrough alignment(8B) */
      20                 :            : #define CNXK_CPT_MIN_HEADROOM_REQ 64
      21                 :            : /* Tailroom required for RX-inject path.
      22                 :            :  * In RX-inject path, space is required for below entities:
      23                 :            :  * WQE header and NIX_RX_PARSE_S
      24                 :            :  * SG list format for 6 IOVA pointers
      25                 :            :  * Space for 128 byte alignment.
      26                 :            :  */
      27                 :            : #define CNXK_CPT_MIN_TAILROOM_REQ 256
      28                 :            : #define CNXK_CPT_MAX_SG_SEGS      6
      29                 :            : 
      30                 :            : /* Default command timeout in seconds */
      31                 :            : #define DEFAULT_COMMAND_TIMEOUT 4
      32                 :            : 
      33                 :            : #define MOD_INC(i, l) ((i) == (l - 1) ? (i) = 0 : (i)++)
      34                 :            : 
      35                 :            : #define CN10K_CPT_PKTS_PER_LOOP   64
      36                 :            : 
      37                 :            : /* Macros to form words in CPT instruction */
      38                 :            : #define CNXK_CPT_INST_W2(tag, tt, grp, rvu_pf_func)                            \
      39                 :            :         ((tag) | ((uint64_t)(tt) << 32) | ((uint64_t)(grp) << 34) |            \
      40                 :            :          ((uint64_t)(rvu_pf_func) << 48))
      41                 :            : #define CNXK_CPT_INST_W3(qord, wqe_ptr)                                        \
      42                 :            :         (qord | ((uintptr_t)(wqe_ptr) >> 3) << 3)
      43                 :            : 
      44                 :            : struct cpt_qp_meta_info {
      45                 :            :         struct rte_mempool *pool;
      46                 :            :         int mlen;
      47                 :            : };
      48                 :            : 
      49                 :            : #define CPT_OP_FLAGS_METABUF           (1 << 1)
      50                 :            : #define CPT_OP_FLAGS_AUTH_VERIFY       (1 << 0)
      51                 :            : #define CPT_OP_FLAGS_IPSEC_DIR_INBOUND (1 << 2)
      52                 :            : #define CPT_OP_FLAGS_IPSEC_INB_REPLAY  (1 << 3)
      53                 :            : 
      54                 :            : struct __rte_aligned(ROC_ALIGN) cpt_inflight_req {
      55                 :            :         union cpt_res_s res;
      56                 :            :         union {
      57                 :            :                 void *opaque;
      58                 :            :                 struct rte_crypto_op *cop;
      59                 :            :                 struct rte_event_vector *vec;
      60                 :            :         };
      61                 :            :         void *mdata;
      62                 :            :         uint8_t op_flags;
      63                 :            : #ifdef CPT_INST_DEBUG_ENABLE
      64                 :            :         uint8_t scatter_sz;
      65                 :            :         uint8_t opcode_major;
      66                 :            :         uint8_t is_sg_ver2;
      67                 :            :         uint8_t *dptr;
      68                 :            :         uint8_t *rptr;
      69                 :            : #endif
      70                 :            :         void *qp;
      71                 :            : };
      72                 :            : 
      73                 :            : PLT_STATIC_ASSERT(sizeof(struct cpt_inflight_req) == ROC_CACHE_LINE_SZ);
      74                 :            : 
      75                 :            : struct pending_queue {
      76                 :            :         /** Array of pending requests */
      77                 :            :         struct cpt_inflight_req *req_queue;
      78                 :            :         /** Head of the queue to be used for enqueue */
      79                 :            :         uint64_t head;
      80                 :            :         /** Tail of the queue to be used for dequeue */
      81                 :            :         uint64_t tail;
      82                 :            :         /** Pending queue mask */
      83                 :            :         uint64_t pq_mask;
      84                 :            :         /** Timeout to track h/w being unresponsive */
      85                 :            :         uint64_t time_out;
      86                 :            : };
      87                 :            : 
      88                 :            : struct crypto_adpter_info {
      89                 :            :         bool enabled;
      90                 :            :         /**< Set if queue pair is added to crypto adapter */
      91                 :            :         struct rte_mempool *req_mp;
      92                 :            :         /**< CPT inflight request mempool */
      93                 :            :         uint16_t vector_sz;
      94                 :            :         /** Maximum number of cops to combine into single vector */
      95                 :            :         struct rte_mempool *vector_mp;
      96                 :            :         /** Pool for allocating rte_event_vector */
      97                 :            : };
      98                 :            : 
      99                 :            : struct cnxk_cpt_qp {
     100                 :            :         struct roc_cpt_lf lf;
     101                 :            :         /**< Crypto LF */
     102                 :            :         struct pending_queue pend_q;
     103                 :            :         /**< Pending queue */
     104                 :            :         struct roc_cpt_lmtline lmtline;
     105                 :            :         /**< Lmtline information */
     106                 :            :         struct cpt_qp_meta_info meta_info;
     107                 :            :         /**< Metabuf info required to support operations on the queue pair */
     108                 :            :         struct crypto_adpter_info ca;
     109                 :            :         /**< Crypto adapter related info */
     110                 :            :         struct rte_mempool *sess_mp;
     111                 :            :         /**< Session mempool */
     112                 :            : };
     113                 :            : 
     114                 :            : int cnxk_cpt_asym_get_mlen(void);
     115                 :            : 
     116                 :            : int cnxk_cpt_dev_config(struct rte_cryptodev *dev,
     117                 :            :                         struct rte_cryptodev_config *conf);
     118                 :            : 
     119                 :            : int cnxk_cpt_dev_start(struct rte_cryptodev *dev);
     120                 :            : 
     121                 :            : void cnxk_cpt_dev_stop(struct rte_cryptodev *dev);
     122                 :            : 
     123                 :            : int cnxk_cpt_dev_close(struct rte_cryptodev *dev);
     124                 :            : 
     125                 :            : void cnxk_cpt_dev_info_get(struct rte_cryptodev *dev,
     126                 :            :                            struct rte_cryptodev_info *info);
     127                 :            : 
     128                 :            : int cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
     129                 :            :                               const struct rte_cryptodev_qp_conf *conf,
     130                 :            :                               int socket_id __rte_unused);
     131                 :            : 
     132                 :            : int cnxk_cpt_queue_pair_reset(struct rte_cryptodev *dev, uint16_t qp_id,
     133                 :            :                               const struct rte_cryptodev_qp_conf *conf, int socket_id);
     134                 :            : 
     135                 :            : int cnxk_cpt_queue_pair_release(struct rte_cryptodev *dev, uint16_t qp_id);
     136                 :            : 
     137                 :            : unsigned int cnxk_cpt_sym_session_get_size(struct rte_cryptodev *dev);
     138                 :            : 
     139                 :            : int cnxk_cpt_sym_session_configure(struct rte_cryptodev *dev, struct rte_crypto_sym_xform *xform,
     140                 :            :                                    struct rte_cryptodev_sym_session *sess);
     141                 :            : 
     142                 :            : int sym_session_configure(struct roc_cpt *roc_cpt, struct rte_crypto_sym_xform *xform,
     143                 :            :                           struct rte_cryptodev_sym_session *sess, bool is_session_less);
     144                 :            : 
     145                 :            : void cnxk_cpt_sym_session_clear(struct rte_cryptodev *dev, struct rte_cryptodev_sym_session *sess);
     146                 :            : 
     147                 :            : void sym_session_clear(struct rte_cryptodev_sym_session *sess, bool is_session_less);
     148                 :            : 
     149                 :            : unsigned int cnxk_ae_session_size_get(struct rte_cryptodev *dev __rte_unused);
     150                 :            : 
     151                 :            : void cnxk_ae_session_clear(struct rte_cryptodev *dev,
     152                 :            :                            struct rte_cryptodev_asym_session *sess);
     153                 :            : int cnxk_ae_session_cfg(struct rte_cryptodev *dev,
     154                 :            :                         struct rte_crypto_asym_xform *xform,
     155                 :            :                         struct rte_cryptodev_asym_session *sess);
     156                 :            : void cnxk_cpt_dump_on_err(struct cnxk_cpt_qp *qp);
     157                 :            : int cnxk_cpt_queue_pair_event_error_query(struct rte_cryptodev *dev, uint16_t qp_id);
     158                 :            : 
     159                 :            : uint32_t cnxk_cpt_qp_depth_used(void *qptr);
     160                 :            : 
     161                 :            : static __rte_always_inline void
     162                 :            : pending_queue_advance(uint64_t *index, const uint64_t mask)
     163                 :            : {
     164                 :          0 :         *index = (*index + 1) & mask;
     165                 :            : }
     166                 :            : 
     167                 :            : static __rte_always_inline void
     168                 :            : pending_queue_retreat(uint64_t *index, const uint64_t mask, uint64_t nb_entry)
     169                 :            : {
     170                 :          0 :         *index = (*index - nb_entry) & mask;
     171                 :          0 : }
     172                 :            : 
     173                 :            : static __rte_always_inline uint64_t
     174                 :            : pending_queue_infl_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
     175                 :            : {
     176                 :            :         /*
     177                 :            :          * Mask is nb_desc - 1. Add nb_desc to head and mask to account for
     178                 :            :          * cases when tail > head, which happens during wrap around.
     179                 :            :          */
     180   [ #  #  #  #  :          0 :         return ((head + mask + 1) - tail) & mask;
             #  #  #  # ]
     181                 :            : }
     182                 :            : 
     183                 :            : static __rte_always_inline uint64_t
     184                 :            : pending_queue_free_cnt(uint64_t head, uint64_t tail, const uint64_t mask)
     185                 :            : {
     186                 :            :         /* mask is nb_desc - 1 */
     187                 :            :         return mask - pending_queue_infl_cnt(head, tail, mask);
     188                 :            : }
     189                 :            : 
     190                 :            : static __rte_always_inline void *
     191                 :            : alloc_op_meta(struct roc_se_buf_ptr *buf, int32_t len, struct rte_mempool *cpt_meta_pool,
     192                 :            :               struct cpt_inflight_req *infl_req)
     193                 :            : {
     194                 :            :         uint8_t *mdata;
     195                 :            : 
     196   [ #  #  #  #  :          0 :         if (unlikely(rte_mempool_get(cpt_meta_pool, (void **)&mdata) < 0))
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     197                 :            :                 return NULL;
     198                 :            : 
     199                 :            :         if (likely(buf)) {
     200                 :          0 :                 buf->vaddr = mdata;
     201                 :          0 :                 buf->size = len;
     202                 :            :         }
     203                 :            : 
     204                 :          0 :         infl_req->mdata = mdata;
     205   [ #  #  #  #  :          0 :         infl_req->op_flags |= CPT_OP_FLAGS_METABUF;
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     206                 :            : 
     207                 :          0 :         return mdata;
     208                 :            : }
     209                 :            : 
     210                 :            : static __rte_always_inline bool
     211                 :            : hw_ctx_cache_enable(void)
     212                 :            : {
     213   [ #  #  #  #  :          0 :         return roc_errata_cpt_hang_on_mixed_ctx_val() || roc_model_is_cn10ka_b0() ||
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     214                 :            :                roc_model_is_cn10kb_a0();
     215                 :            : }
     216                 :            : #endif /* _CNXK_CRYPTODEV_OPS_H_ */

Generated by: LCOV version 1.14