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

Generated by: LCOV version 1.14