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

Generated by: LCOV version 1.14