LCOV - code coverage report
Current view: top level - drivers/common/nitrox - nitrox_device.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 4 44 9.1 %
Date: 2025-05-01 17:49:45 Functions: 2 7 28.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 26 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 <eal_export.h>
       6                 :            : #include <rte_malloc.h>
       7                 :            : 
       8                 :            : #include "nitrox_device.h"
       9                 :            : #include "nitrox_hal.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                 :            : TAILQ_HEAD(ndrv_list, nitrox_driver);
      66                 :            : static struct ndrv_list ndrv_list = TAILQ_HEAD_INITIALIZER(ndrv_list);
      67                 :            : 
      68                 :            : RTE_EXPORT_INTERNAL_SYMBOL(nitrox_register_driver)
      69                 :            : void
      70                 :        504 : nitrox_register_driver(struct nitrox_driver *ndrv)
      71                 :            : {
      72                 :        504 :         TAILQ_INSERT_TAIL(&ndrv_list, ndrv, next);
      73                 :        504 : }
      74                 :            : 
      75                 :            : static int
      76                 :          0 : nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
      77                 :            :                 struct rte_pci_device *pdev)
      78                 :            : {
      79                 :            :         struct nitrox_device *ndev;
      80                 :            :         struct nitrox_driver *ndrv;
      81                 :            :         int err = -1;
      82                 :            : 
      83                 :            :         /* Nitrox CSR space */
      84         [ #  # ]:          0 :         if (!pdev->mem_resource[0].addr)
      85                 :            :                 return -EINVAL;
      86                 :            : 
      87                 :          0 :         ndev = ndev_allocate(pdev);
      88         [ #  # ]:          0 :         if (!ndev)
      89                 :            :                 return -ENOMEM;
      90                 :            : 
      91                 :          0 :         ndev_init(ndev, pdev);
      92         [ #  # ]:          0 :         TAILQ_FOREACH(ndrv, &ndrv_list, next) {
      93                 :          0 :                 err = ndrv->create(ndev);
      94         [ #  # ]:          0 :                 if (err)
      95                 :          0 :                         goto drv_err;
      96                 :            :         }
      97                 :            : 
      98                 :            :         return 0;
      99                 :            : 
     100                 :            : drv_err:
     101                 :          0 :         ndrv = TAILQ_PREV(ndrv, ndrv_list, next);
     102         [ #  # ]:          0 :         while (ndrv != NULL) {
     103                 :          0 :                 ndrv->destroy(ndev);
     104                 :          0 :                 ndrv = TAILQ_PREV(ndrv, ndrv_list, next);
     105                 :            :         }
     106                 :            : 
     107                 :          0 :         ndev_release(ndev);
     108                 :          0 :         return err;
     109                 :            : }
     110                 :            : 
     111                 :            : static int
     112                 :          0 : nitrox_pci_remove(struct rte_pci_device *pdev)
     113                 :            : {
     114                 :            :         struct nitrox_device *ndev;
     115                 :            :         struct nitrox_driver *ndrv;
     116                 :            :         int err;
     117                 :            : 
     118                 :            :         ndev = find_ndev(pdev);
     119         [ #  # ]:          0 :         if (!ndev)
     120                 :            :                 return -ENODEV;
     121                 :            : 
     122         [ #  # ]:          0 :         TAILQ_FOREACH(ndrv, &ndrv_list, next) {
     123                 :          0 :                 err = ndrv->destroy(ndev);
     124         [ #  # ]:          0 :                 if (err)
     125                 :          0 :                         return err;
     126                 :            :         }
     127                 :            : 
     128                 :          0 :         ndev_release(ndev);
     129                 :          0 :         return 0;
     130                 :            : }
     131                 :            : 
     132                 :            : static struct rte_pci_id pci_id_nitrox_map[] = {
     133                 :            :         {
     134                 :            :                 /* Nitrox 5 VF */
     135                 :            :                 RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, NITROX_V_PCI_VF_DEV_ID)
     136                 :            :         },
     137                 :            :         {.device_id = 0},
     138                 :            : };
     139                 :            : 
     140                 :            : static struct rte_pci_driver nitrox_pmd = {
     141                 :            :         .id_table       = pci_id_nitrox_map,
     142                 :            :         .drv_flags      = RTE_PCI_DRV_NEED_MAPPING,
     143                 :            :         .probe          = nitrox_pci_probe,
     144                 :            :         .remove         = nitrox_pci_remove,
     145                 :            : };
     146                 :            : 
     147                 :        252 : RTE_PMD_REGISTER_PCI(nitrox, nitrox_pmd);
     148                 :            : RTE_PMD_REGISTER_PCI_TABLE(nitrox, pci_id_nitrox_map);

Generated by: LCOV version 1.14