LCOV - code coverage report
Current view: top level - drivers/crypto/nitrox - nitrox_device.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 33 3.0 %
Date: 2024-01-22 16:13:49 Functions: 1 6 16.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 20 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2019 Marvell International Ltd.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_malloc.h>
       6                 :            : 
       7                 :            : #include "nitrox_device.h"
       8                 :            : #include "nitrox_hal.h"
       9                 :            : #include "nitrox_sym.h"
      10                 :            : 
      11                 :            : #define PCI_VENDOR_ID_CAVIUM    0x177d
      12                 :            : #define NITROX_V_PCI_VF_DEV_ID  0x13
      13                 :            : 
      14                 :            : TAILQ_HEAD(ndev_list, nitrox_device);
      15                 :            : static struct ndev_list ndev_list = TAILQ_HEAD_INITIALIZER(ndev_list);
      16                 :            : 
      17                 :            : static struct nitrox_device *
      18                 :          0 : ndev_allocate(struct rte_pci_device *pdev)
      19                 :            : {
      20                 :            :         struct nitrox_device *ndev;
      21                 :            : 
      22                 :          0 :         ndev = rte_zmalloc_socket("nitrox device", sizeof(*ndev),
      23                 :            :                                    RTE_CACHE_LINE_SIZE,
      24                 :            :                                    pdev->device.numa_node);
      25         [ #  # ]:          0 :         if (!ndev)
      26                 :            :                 return NULL;
      27                 :            : 
      28                 :          0 :         TAILQ_INSERT_TAIL(&ndev_list, ndev, next);
      29                 :          0 :         return ndev;
      30                 :            : }
      31                 :            : 
      32                 :            : static void
      33                 :          0 : ndev_init(struct nitrox_device *ndev, struct rte_pci_device *pdev)
      34                 :            : {
      35                 :            :         enum nitrox_vf_mode vf_mode;
      36                 :            : 
      37                 :          0 :         ndev->pdev = pdev;
      38                 :          0 :         ndev->bar_addr = pdev->mem_resource[0].addr;
      39                 :          0 :         vf_mode = vf_get_vf_config_mode(ndev->bar_addr);
      40                 :          0 :         ndev->nr_queues = vf_config_mode_to_nr_queues(vf_mode);
      41                 :          0 : }
      42                 :            : 
      43                 :            : static struct nitrox_device *
      44                 :            : find_ndev(struct rte_pci_device *pdev)
      45                 :            : {
      46                 :            :         struct nitrox_device *ndev;
      47                 :            : 
      48         [ #  # ]:          0 :         TAILQ_FOREACH(ndev, &ndev_list, next)
      49         [ #  # ]:          0 :                 if (ndev->pdev == pdev)
      50                 :            :                         return ndev;
      51                 :            : 
      52                 :            :         return NULL;
      53                 :            : }
      54                 :            : 
      55                 :            : static void
      56                 :          0 : ndev_release(struct nitrox_device *ndev)
      57                 :            : {
      58         [ #  # ]:          0 :         if (!ndev)
      59                 :            :                 return;
      60                 :            : 
      61         [ #  # ]:          0 :         TAILQ_REMOVE(&ndev_list, ndev, next);
      62                 :          0 :         rte_free(ndev);
      63                 :            : }
      64                 :            : 
      65                 :            : static int
      66                 :          0 : nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
      67                 :            :                 struct rte_pci_device *pdev)
      68                 :            : {
      69                 :            :         struct nitrox_device *ndev;
      70                 :            :         int err;
      71                 :            : 
      72                 :            :         /* Nitrox CSR space */
      73         [ #  # ]:          0 :         if (!pdev->mem_resource[0].addr)
      74                 :            :                 return -EINVAL;
      75                 :            : 
      76                 :          0 :         ndev = ndev_allocate(pdev);
      77         [ #  # ]:          0 :         if (!ndev)
      78                 :            :                 return -ENOMEM;
      79                 :            : 
      80                 :          0 :         ndev_init(ndev, pdev);
      81                 :          0 :         err = nitrox_sym_pmd_create(ndev);
      82         [ #  # ]:          0 :         if (err) {
      83                 :          0 :                 ndev_release(ndev);
      84                 :          0 :                 return err;
      85                 :            :         }
      86                 :            : 
      87                 :            :         return 0;
      88                 :            : }
      89                 :            : 
      90                 :            : static int
      91                 :          0 : nitrox_pci_remove(struct rte_pci_device *pdev)
      92                 :            : {
      93                 :            :         struct nitrox_device *ndev;
      94                 :            :         int err;
      95                 :            : 
      96                 :            :         ndev = find_ndev(pdev);
      97         [ #  # ]:          0 :         if (!ndev)
      98                 :            :                 return -ENODEV;
      99                 :            : 
     100                 :          0 :         err = nitrox_sym_pmd_destroy(ndev);
     101         [ #  # ]:          0 :         if (err)
     102                 :            :                 return err;
     103                 :            : 
     104                 :          0 :         ndev_release(ndev);
     105                 :          0 :         return 0;
     106                 :            : }
     107                 :            : 
     108                 :            : static struct rte_pci_id pci_id_nitrox_map[] = {
     109                 :            :         {
     110                 :            :                 /* Nitrox 5 VF */
     111                 :            :                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, NITROX_V_PCI_VF_DEV_ID)
     112                 :            :         },
     113                 :            :         {.device_id = 0},
     114                 :            : };
     115                 :            : 
     116                 :            : static struct rte_pci_driver nitrox_pmd = {
     117                 :            :         .id_table       = pci_id_nitrox_map,
     118                 :            :         .drv_flags      = RTE_PCI_DRV_NEED_MAPPING,
     119                 :            :         .probe          = nitrox_pci_probe,
     120                 :            :         .remove         = nitrox_pci_remove,
     121                 :            : };
     122                 :            : 
     123                 :        235 : RTE_PMD_REGISTER_PCI(nitrox, nitrox_pmd);
     124                 :            : RTE_PMD_REGISTER_PCI_TABLE(nitrox, pci_id_nitrox_map);

Generated by: LCOV version 1.14