LCOV - code coverage report
Current view: top level - drivers/crypto/null - null_crypto_pmd.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 25 86 29.1 %
Date: 2025-03-01 20:23:48 Functions: 6 11 54.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 80 7.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2016-2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_common.h>
       6                 :            : #include <cryptodev_pmd.h>
       7                 :            : #include <bus_vdev_driver.h>
       8                 :            : #include <rte_malloc.h>
       9                 :            : 
      10                 :            : #include "null_crypto_pmd_private.h"
      11                 :            : 
      12                 :            : static uint8_t cryptodev_driver_id;
      13                 :            : 
      14                 :            : /** verify and set session parameters */
      15                 :            : int
      16                 :          0 : null_crypto_set_session_parameters(
      17                 :            :                 struct null_crypto_session *sess __rte_unused,
      18                 :            :                 const struct rte_crypto_sym_xform *xform)
      19                 :            : {
      20         [ #  # ]:          0 :         if (xform == NULL) {
      21                 :            :                 return -EINVAL;
      22         [ #  # ]:          0 :         } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
      23         [ #  # ]:          0 :                         xform->next == NULL) {
      24                 :            :                 /* Authentication Only */
      25         [ #  # ]:          0 :                 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
      26                 :          0 :                         return 0;
      27         [ #  # ]:          0 :         } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
      28         [ #  # ]:          0 :                         xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
      29                 :            :                 /* Authentication then Cipher */
      30         [ #  # ]:          0 :                 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL &&
      31         [ #  # ]:          0 :                         xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
      32                 :          0 :                         return 0;
      33         [ #  # ]:          0 :         } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
      34         [ #  # ]:          0 :                         xform->next == NULL) {
      35                 :            :                 /* Cipher Only */
      36         [ #  # ]:          0 :                 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
      37                 :          0 :                         return 0;
      38         [ #  # ]:          0 :         } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
      39         [ #  # ]:          0 :                         xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
      40                 :            :                 /* Cipher then Authentication */
      41         [ #  # ]:          0 :                 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL &&
      42         [ #  # ]:          0 :                         xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
      43                 :          0 :                         return 0;
      44                 :            :         }
      45                 :            : 
      46                 :            :         return -ENOTSUP;
      47                 :            : }
      48                 :            : 
      49                 :            : /** Process crypto operation for mbuf */
      50                 :            : static int
      51                 :          0 : process_op(const struct null_crypto_qp *qp, struct rte_crypto_op *op,
      52                 :            :                 struct null_crypto_session *sess __rte_unused)
      53                 :            : {
      54                 :            :         /* set status as successful by default */
      55                 :          0 :         op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
      56                 :            : 
      57                 :            :         /* Free session if a session-less crypto op. */
      58         [ #  # ]:          0 :         if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
      59   [ #  #  #  # ]:          0 :                 memset(op->sym->session, 0,
      60                 :            :                                 sizeof(struct null_crypto_session));
      61         [ #  # ]:          0 :                 rte_mempool_put(qp->sess_mp, (void *)op->sym->session);
      62                 :          0 :                 op->sym->session = NULL;
      63                 :            :         }
      64                 :            : 
      65                 :            :         /*
      66                 :            :          * if crypto session and operation are valid just enqueue the packet
      67                 :            :          * in the processed ring
      68                 :            :          */
      69   [ #  #  #  #  :          0 :         return rte_ring_enqueue(qp->processed_pkts, (void *)op);
                      # ]
      70                 :            : }
      71                 :            : 
      72                 :            : static struct null_crypto_session *
      73                 :          0 : get_session(struct null_crypto_qp *qp, struct rte_crypto_op *op)
      74                 :            : {
      75                 :            :         struct null_crypto_session *sess = NULL;
      76                 :            :         struct rte_crypto_sym_op *sym_op = op->sym;
      77                 :            : 
      78         [ #  # ]:          0 :         if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
      79         [ #  # ]:          0 :                 if (likely(sym_op->session != NULL))
      80                 :          0 :                         sess = CRYPTODEV_GET_SYM_SESS_PRIV(sym_op->session);
      81                 :            :         } else {
      82                 :          0 :                 struct rte_cryptodev_sym_session *_sess = NULL;
      83                 :            : 
      84   [ #  #  #  # ]:          0 :                 if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
      85                 :          0 :                         return NULL;
      86                 :            : 
      87                 :          0 :                 sess = (struct null_crypto_session *)_sess->driver_priv_data;
      88                 :            : 
      89         [ #  # ]:          0 :                 if (unlikely(null_crypto_set_session_parameters(sess,
      90                 :            :                                 sym_op->xform) != 0)) {
      91         [ #  # ]:          0 :                         rte_mempool_put(qp->sess_mp, _sess);
      92                 :            :                         sess = NULL;
      93                 :            :                 }
      94                 :          0 :                 sym_op->session = _sess;
      95                 :            :         }
      96                 :            : 
      97                 :            :         return sess;
      98                 :            : }
      99                 :            : 
     100                 :            : /** Enqueue burst */
     101                 :            : static uint16_t
     102                 :          0 : null_crypto_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
     103                 :            :                 uint16_t nb_ops)
     104                 :            : {
     105                 :            :         struct null_crypto_session *sess;
     106                 :            :         struct null_crypto_qp *qp = queue_pair;
     107                 :            : 
     108                 :            :         int i, retval;
     109                 :            : 
     110         [ #  # ]:          0 :         for (i = 0; i < nb_ops; i++) {
     111                 :          0 :                 sess = get_session(qp, ops[i]);
     112         [ #  # ]:          0 :                 if (unlikely(sess == NULL))
     113                 :          0 :                         goto enqueue_err;
     114                 :            : 
     115                 :          0 :                 retval = process_op(qp, ops[i], sess);
     116         [ #  # ]:          0 :                 if (unlikely(retval < 0))
     117                 :          0 :                         goto enqueue_err;
     118                 :            :         }
     119                 :            : 
     120                 :          0 :         qp->qp_stats.enqueued_count += i;
     121                 :          0 :         return i;
     122                 :            : 
     123                 :          0 : enqueue_err:
     124         [ #  # ]:          0 :         if (ops[i])
     125                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
     126                 :            : 
     127                 :          0 :         qp->qp_stats.enqueue_err_count++;
     128                 :          0 :         return i;
     129                 :            : }
     130                 :            : 
     131                 :            : /** Dequeue burst */
     132                 :            : static uint16_t
     133                 :          0 : null_crypto_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
     134                 :            :                 uint16_t nb_ops)
     135                 :            : {
     136                 :            :         struct null_crypto_qp *qp = queue_pair;
     137                 :            : 
     138                 :            :         unsigned nb_dequeued;
     139                 :            : 
     140   [ #  #  #  #  :          0 :         nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts,
                      # ]
     141                 :            :                         (void **)ops, nb_ops, NULL);
     142                 :          0 :         qp->qp_stats.dequeued_count += nb_dequeued;
     143                 :            : 
     144                 :          0 :         return nb_dequeued;
     145                 :            : }
     146                 :            : 
     147                 :            : /** Create crypto device */
     148                 :            : static int
     149                 :          1 : cryptodev_null_create(const char *name,
     150                 :            :                 struct rte_vdev_device *vdev,
     151                 :            :                 struct rte_cryptodev_pmd_init_params *init_params)
     152                 :            : {
     153                 :            :         struct rte_cryptodev *dev;
     154                 :            :         struct null_crypto_private *internals;
     155                 :          1 :         dev = rte_cryptodev_pmd_create(name, &vdev->device, init_params);
     156         [ -  + ]:          1 :         if (dev == NULL) {
     157                 :          0 :                 NULL_LOG(ERR, "failed to create cryptodev vdev");
     158                 :          0 :                 return -EFAULT;
     159                 :            :         }
     160                 :            : 
     161                 :          1 :         dev->driver_id = cryptodev_driver_id;
     162                 :          1 :         dev->dev_ops = null_crypto_pmd_ops;
     163                 :            : 
     164                 :            :         /* register rx/tx burst functions for data path */
     165                 :          1 :         dev->dequeue_burst = null_crypto_pmd_dequeue_burst;
     166                 :          1 :         dev->enqueue_burst = null_crypto_pmd_enqueue_burst;
     167                 :            : 
     168                 :          1 :         dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
     169                 :            :                         RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
     170                 :            :                         RTE_CRYPTODEV_FF_IN_PLACE_SGL |
     171                 :            :                         RTE_CRYPTODEV_FF_SYM_SESSIONLESS;
     172                 :            : 
     173                 :          1 :         internals = dev->data->dev_private;
     174                 :            : 
     175                 :          1 :         internals->max_nb_qpairs = init_params->max_nb_queue_pairs;
     176                 :            : 
     177                 :          1 :         rte_cryptodev_pmd_probing_finish(dev);
     178                 :            : 
     179                 :          1 :         return 0;
     180                 :            : }
     181                 :            : 
     182                 :            : /** Initialise null crypto device */
     183                 :            : static int
     184                 :          1 : cryptodev_null_probe(struct rte_vdev_device *dev)
     185                 :            : {
     186                 :          2 :         struct rte_cryptodev_pmd_init_params init_params = {
     187                 :            :                 "",
     188                 :            :                 sizeof(struct null_crypto_private),
     189         [ +  - ]:          1 :                 rte_socket_id(),
     190                 :            :                 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS
     191                 :            :         };
     192                 :            :         const char *name, *args;
     193                 :            :         int retval;
     194                 :            : 
     195                 :            :         name = rte_vdev_device_name(dev);
     196                 :            :         if (name == NULL)
     197                 :            :                 return -EINVAL;
     198                 :            : 
     199                 :            :         args = rte_vdev_device_args(dev);
     200                 :            : 
     201                 :          1 :         retval = rte_cryptodev_pmd_parse_input_args(&init_params, args);
     202         [ -  + ]:          1 :         if (retval) {
     203                 :          0 :                 NULL_LOG(ERR,
     204                 :            :                                 "Failed to parse initialisation arguments[%s]",
     205                 :            :                                 args);
     206                 :          0 :                 return -EINVAL;
     207                 :            :         }
     208                 :            : 
     209                 :          1 :         return cryptodev_null_create(name, dev, &init_params);
     210                 :            : }
     211                 :            : 
     212                 :            : static int
     213         [ +  - ]:          1 : cryptodev_null_remove_dev(struct rte_vdev_device *vdev)
     214                 :            : {
     215                 :            :         struct rte_cryptodev *cryptodev;
     216                 :            :         const char *name;
     217                 :            : 
     218                 :            :         name = rte_vdev_device_name(vdev);
     219                 :            :         if (name == NULL)
     220                 :            :                 return -EINVAL;
     221                 :            : 
     222                 :          1 :         cryptodev = rte_cryptodev_pmd_get_named_dev(name);
     223         [ +  - ]:          1 :         if (cryptodev == NULL)
     224                 :            :                 return -ENODEV;
     225                 :            : 
     226                 :          1 :         return rte_cryptodev_pmd_destroy(cryptodev);
     227                 :            : }
     228                 :            : 
     229                 :            : static struct rte_vdev_driver cryptodev_null_pmd_drv = {
     230                 :            :         .probe = cryptodev_null_probe,
     231                 :            :         .remove = cryptodev_null_remove_dev,
     232                 :            : };
     233                 :            : 
     234                 :            : static struct cryptodev_driver null_crypto_drv;
     235                 :            : 
     236                 :        252 : RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd_drv);
     237                 :            : RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd);
     238                 :            : RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_NULL_PMD,
     239                 :            :         "max_nb_queue_pairs=<int> "
     240                 :            :         "socket_id=<int>");
     241                 :        252 : RTE_PMD_REGISTER_CRYPTO_DRIVER(null_crypto_drv, cryptodev_null_pmd_drv.driver,
     242                 :            :                 cryptodev_driver_id);
     243         [ -  + ]:        252 : RTE_LOG_REGISTER_DEFAULT(null_logtype_driver, INFO);

Generated by: LCOV version 1.14