LCOV - code coverage report
Current view: top level - drivers/crypto/cnxk - cn20k_cryptodev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 61 3.3 %
Date: 2025-07-01 21:32:37 Functions: 2 4 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 24 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2025 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <bus_pci_driver.h>
       6                 :            : #include <cryptodev_pmd.h>
       7                 :            : #include <dev_driver.h>
       8                 :            : #include <rte_common.h>
       9                 :            : #include <rte_crypto.h>
      10                 :            : #include <rte_cryptodev.h>
      11                 :            : #include <rte_pci.h>
      12                 :            : 
      13                 :            : #include "cn20k_cryptodev.h"
      14                 :            : #include "cn20k_cryptodev_ops.h"
      15                 :            : #include "cn20k_cryptodev_sec.h"
      16                 :            : #include "cnxk_cryptodev.h"
      17                 :            : #include "cnxk_cryptodev_capabilities.h"
      18                 :            : #include "cnxk_cryptodev_ops.h"
      19                 :            : #include "cnxk_cryptodev_sec.h"
      20                 :            : 
      21                 :            : #include "roc_api.h"
      22                 :            : 
      23                 :            : uint8_t cn20k_cryptodev_driver_id;
      24                 :            : 
      25                 :            : static struct rte_pci_id pci_id_cpt_table[] = {
      26                 :            :         CNXK_PCI_ID(PCI_SUBSYSTEM_DEVID_CN20KA, PCI_DEVID_CN20K_RVU_CPT_VF),
      27                 :            :         {.vendor_id = 0},
      28                 :            : };
      29                 :            : 
      30                 :            : static int
      31                 :          0 : cn20k_cpt_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, struct rte_pci_device *pci_dev)
      32                 :            : {
      33                 :          0 :         struct rte_cryptodev_pmd_init_params init_params = {.name = "",
      34                 :          0 :                                                             .socket_id = rte_socket_id(),
      35                 :            :                                                             .private_data_size =
      36                 :            :                                                                     sizeof(struct cnxk_cpt_vf)};
      37                 :            :         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
      38                 :            :         struct rte_cryptodev *dev;
      39                 :            :         struct roc_cpt *roc_cpt;
      40                 :            :         struct cnxk_cpt_vf *vf;
      41                 :            :         int rc;
      42                 :            : 
      43                 :          0 :         rc = roc_plt_init();
      44         [ #  # ]:          0 :         if (rc < 0) {
      45                 :          0 :                 plt_err("Failed to initialize platform model");
      46                 :          0 :                 return rc;
      47                 :            :         }
      48                 :            : 
      49                 :          0 :         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
      50                 :            : 
      51                 :          0 :         dev = rte_cryptodev_pmd_create(name, &pci_dev->device, &init_params);
      52         [ #  # ]:          0 :         if (dev == NULL) {
      53                 :            :                 rc = -ENODEV;
      54                 :          0 :                 goto exit;
      55                 :            :         }
      56                 :            : 
      57                 :            :         /* Get private data space allocated */
      58                 :          0 :         vf = dev->data->dev_private;
      59                 :            : 
      60                 :          0 :         roc_cpt = &vf->cpt;
      61                 :            : 
      62         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
      63                 :          0 :                 roc_cpt->pci_dev = pci_dev;
      64                 :            : 
      65                 :          0 :                 rc = cnxk_cpt_parse_devargs(dev->device->devargs, vf);
      66         [ #  # ]:          0 :                 if (rc) {
      67                 :          0 :                         plt_err("Failed to parse devargs rc=%d", rc);
      68                 :          0 :                         goto pmd_destroy;
      69                 :            :                 }
      70                 :            : 
      71                 :          0 :                 rc = roc_cpt_dev_init(roc_cpt);
      72         [ #  # ]:          0 :                 if (rc) {
      73                 :          0 :                         plt_err("Failed to initialize roc cpt rc=%d", rc);
      74                 :          0 :                         goto pmd_destroy;
      75                 :            :                 }
      76                 :            : 
      77                 :          0 :                 rc = cnxk_cpt_eng_grp_add(roc_cpt);
      78         [ #  # ]:          0 :                 if (rc) {
      79                 :          0 :                         plt_err("Failed to add engine group rc=%d", rc);
      80                 :          0 :                         goto dev_fini;
      81                 :            :                 }
      82                 :            : 
      83                 :            :                 /* Create security context */
      84                 :          0 :                 rc = cnxk_crypto_sec_ctx_create(dev);
      85         [ #  # ]:          0 :                 if (rc)
      86                 :          0 :                         goto dev_fini;
      87                 :            :         }
      88                 :            : 
      89                 :          0 :         cnxk_cpt_caps_populate(vf);
      90                 :            : 
      91                 :          0 :         dev->dev_ops = &cn20k_cpt_ops;
      92                 :          0 :         dev->driver_id = cn20k_cryptodev_driver_id;
      93                 :          0 :         dev->feature_flags = cnxk_cpt_default_ff_get();
      94                 :            : 
      95                 :          0 :         dev->qp_depth_used = cnxk_cpt_qp_depth_used;
      96                 :          0 :         cn20k_cpt_set_enqdeq_fns(dev);
      97                 :          0 :         cn20k_sec_ops_override();
      98                 :            : 
      99                 :          0 :         rte_cryptodev_pmd_probing_finish(dev);
     100                 :            : 
     101                 :          0 :         return 0;
     102                 :            : 
     103                 :          0 : dev_fini:
     104         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
     105                 :          0 :                 roc_cpt_dev_fini(roc_cpt);
     106                 :          0 : pmd_destroy:
     107                 :          0 :         rte_cryptodev_pmd_destroy(dev);
     108                 :          0 : exit:
     109                 :          0 :         plt_err("Could not create device (vendor_id: 0x%x device_id: 0x%x)", pci_dev->id.vendor_id,
     110                 :            :                 pci_dev->id.device_id);
     111                 :          0 :         return rc;
     112                 :            : }
     113                 :            : 
     114                 :            : static int
     115                 :          0 : cn20k_cpt_pci_remove(struct rte_pci_device *pci_dev)
     116                 :            : {
     117                 :            :         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
     118                 :            :         struct rte_cryptodev *dev;
     119                 :            :         struct cnxk_cpt_vf *vf;
     120                 :            :         int ret;
     121                 :            : 
     122         [ #  # ]:          0 :         if (pci_dev == NULL)
     123                 :            :                 return -EINVAL;
     124                 :            : 
     125                 :          0 :         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
     126                 :            : 
     127                 :          0 :         dev = rte_cryptodev_pmd_get_named_dev(name);
     128         [ #  # ]:          0 :         if (dev == NULL)
     129                 :            :                 return -ENODEV;
     130                 :            : 
     131                 :            :         /* Destroy security context */
     132                 :          0 :         cnxk_crypto_sec_ctx_destroy(dev);
     133                 :            : 
     134         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
     135                 :          0 :                 dev->dev_ops = NULL;
     136                 :          0 :                 vf = dev->data->dev_private;
     137                 :          0 :                 ret = roc_cpt_dev_fini(&vf->cpt);
     138         [ #  # ]:          0 :                 if (ret)
     139                 :            :                         return ret;
     140                 :            :         }
     141                 :            : 
     142                 :          0 :         return rte_cryptodev_pmd_destroy(dev);
     143                 :            : }
     144                 :            : 
     145                 :            : static struct rte_pci_driver cn20k_cryptodev_pmd = {
     146                 :            :         .id_table = pci_id_cpt_table,
     147                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
     148                 :            :         .probe = cn20k_cpt_pci_probe,
     149                 :            :         .remove = cn20k_cpt_pci_remove,
     150                 :            : };
     151                 :            : 
     152                 :            : static struct cryptodev_driver cn20k_cryptodev_drv;
     153                 :            : 
     154                 :        254 : RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_CN20K_PMD, cn20k_cryptodev_pmd);
     155                 :            : RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_CN20K_PMD, pci_id_cpt_table);
     156                 :            : RTE_PMD_REGISTER_KMOD_DEP(CRYPTODEV_NAME_CN20K_PMD, "vfio-pci");
     157                 :        254 : RTE_PMD_REGISTER_CRYPTO_DRIVER(cn20k_cryptodev_drv, cn20k_cryptodev_pmd.driver,
     158                 :            :                                cn20k_cryptodev_driver_id);

Generated by: LCOV version 1.14