LCOV - code coverage report
Current view: top level - spdk/lib/env_dpdk - pci_dpdk_2207.c (source / functions) Hit Total Coverage
Test: Combined Lines: 0 77 0.0 %
Date: 2024-07-12 11:58:45 Functions: 0 18 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 30 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2022 Intel Corporation.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <rte_config.h>
       7                 :            : #include <rte_version.h>
       8                 :            : #include "pci_dpdk.h"
       9                 :            : #include "22.07/rte_dev.h"
      10                 :            : #include "22.07/rte_bus.h"
      11                 :            : #include "22.07/rte_bus_pci.h"
      12                 :            : #include "spdk/assert.h"
      13                 :            : 
      14                 :            : SPDK_STATIC_ASSERT(offsetof(struct spdk_pci_driver, driver_buf) == 0, "driver_buf must be first");
      15                 :            : SPDK_STATIC_ASSERT(offsetof(struct spdk_pci_driver, driver) >= sizeof(struct rte_pci_driver),
      16                 :            :                    "driver_buf not big enough");
      17                 :            : 
      18                 :            : static struct rte_mem_resource *
      19                 :          0 : pci_device_get_mem_resource_2207(struct rte_pci_device *dev, uint32_t bar)
      20                 :            : {
      21         [ #  # ]:          0 :         if (bar >= PCI_MAX_RESOURCE) {
      22                 :          0 :                 assert(false);
      23                 :            :                 return NULL;
      24                 :            :         }
      25                 :            : 
      26                 :          0 :         return &dev->mem_resource[bar];
      27                 :            : }
      28                 :            : 
      29                 :            : static const char *
      30                 :          0 : pci_device_get_name_2207(struct rte_pci_device *rte_dev)
      31                 :            : {
      32                 :          0 :         return rte_dev->name;
      33                 :            : }
      34                 :            : 
      35                 :            : static struct rte_devargs *
      36                 :          0 : pci_device_get_devargs_2207(struct rte_pci_device *rte_dev)
      37                 :            : {
      38                 :          0 :         return rte_dev->device.devargs;
      39                 :            : }
      40                 :            : 
      41                 :            : static struct rte_pci_addr *
      42                 :          0 : pci_device_get_addr_2207(struct rte_pci_device *_dev)
      43                 :            : {
      44                 :          0 :         return &_dev->addr;
      45                 :            : }
      46                 :            : 
      47                 :            : static struct rte_pci_id *
      48                 :          0 : pci_device_get_id_2207(struct rte_pci_device *_dev)
      49                 :            : {
      50                 :          0 :         return &_dev->id;
      51                 :            : }
      52                 :            : 
      53                 :            : static int
      54                 :          0 : pci_device_get_numa_node_2207(struct rte_pci_device *_dev)
      55                 :            : {
      56                 :          0 :         return _dev->device.numa_node;
      57                 :            : }
      58                 :            : 
      59                 :            : static int
      60                 :          0 : pci_device_read_config_2207(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
      61                 :            : {
      62                 :            :         int rc;
      63                 :            : 
      64                 :          0 :         rc = rte_pci_read_config(dev, value, len, offset);
      65                 :            : 
      66   [ #  #  #  # ]:          0 :         return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
      67                 :            : }
      68                 :            : 
      69                 :            : static int
      70                 :          0 : pci_device_write_config_2207(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
      71                 :            : {
      72                 :            :         int rc;
      73                 :            : 
      74                 :          0 :         rc = rte_pci_write_config(dev, value, len, offset);
      75                 :            : 
      76                 :            : #ifdef __FreeBSD__
      77                 :            :         /* DPDK returns 0 on success and -1 on failure */
      78                 :            :         return rc;
      79                 :            : #endif
      80   [ #  #  #  # ]:          0 :         return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
      81                 :            : }
      82                 :            : 
      83                 :            : /* translate spdk_pci_driver to an rte_pci_driver and register it to dpdk */
      84                 :            : static int
      85                 :          0 : pci_driver_register_2207(struct spdk_pci_driver *driver,
      86                 :            :                          int (*probe_fn)(struct rte_pci_driver *driver, struct rte_pci_device *device),
      87                 :            :                          int (*remove_fn)(struct rte_pci_device *device))
      88                 :            : 
      89                 :            : {
      90                 :          0 :         unsigned pci_id_count = 0;
      91                 :            :         struct rte_pci_id *rte_id_table;
      92                 :            :         char *rte_name;
      93                 :            :         size_t rte_name_len;
      94                 :            :         uint32_t rte_flags;
      95                 :            : 
      96         [ #  # ]:          0 :         assert(driver->id_table);
      97         [ #  # ]:          0 :         while (driver->id_table[pci_id_count].vendor_id) {
      98                 :          0 :                 pci_id_count++;
      99                 :            :         }
     100         [ #  # ]:          0 :         assert(pci_id_count > 0);
     101                 :            : 
     102                 :          0 :         rte_id_table = calloc(pci_id_count + 1, sizeof(*rte_id_table));
     103         [ #  # ]:          0 :         if (!rte_id_table) {
     104                 :          0 :                 return -ENOMEM;
     105                 :            :         }
     106                 :            : 
     107         [ #  # ]:          0 :         while (pci_id_count > 0) {
     108                 :          0 :                 struct rte_pci_id *rte_id = &rte_id_table[pci_id_count - 1];
     109                 :          0 :                 const struct spdk_pci_id *spdk_id = &driver->id_table[pci_id_count - 1];
     110                 :            : 
     111                 :          0 :                 rte_id->class_id = spdk_id->class_id;
     112                 :          0 :                 rte_id->vendor_id = spdk_id->vendor_id;
     113                 :          0 :                 rte_id->device_id = spdk_id->device_id;
     114                 :          0 :                 rte_id->subsystem_vendor_id = spdk_id->subvendor_id;
     115                 :          0 :                 rte_id->subsystem_device_id = spdk_id->subdevice_id;
     116                 :          0 :                 pci_id_count--;
     117                 :            :         }
     118                 :            : 
     119         [ #  # ]:          0 :         assert(driver->name);
     120         [ #  # ]:          0 :         rte_name_len = strlen(driver->name) + strlen("spdk_") + 1;
     121                 :          0 :         rte_name = calloc(rte_name_len, 1);
     122         [ #  # ]:          0 :         if (!rte_name) {
     123                 :          0 :                 free(rte_id_table);
     124                 :          0 :                 return -ENOMEM;
     125                 :            :         }
     126                 :            : 
     127                 :          0 :         snprintf(rte_name, rte_name_len, "spdk_%s", driver->name);
     128                 :          0 :         driver->driver->driver.name = rte_name;
     129                 :          0 :         driver->driver->id_table = rte_id_table;
     130                 :            : 
     131                 :          0 :         rte_flags = 0;
     132         [ #  # ]:          0 :         if (driver->drv_flags & SPDK_PCI_DRIVER_NEED_MAPPING) {
     133                 :          0 :                 rte_flags |= RTE_PCI_DRV_NEED_MAPPING;
     134                 :            :         }
     135         [ #  # ]:          0 :         if (driver->drv_flags & SPDK_PCI_DRIVER_WC_ACTIVATE) {
     136                 :          0 :                 rte_flags |= RTE_PCI_DRV_WC_ACTIVATE;
     137                 :            :         }
     138                 :          0 :         driver->driver->drv_flags = rte_flags;
     139                 :            : 
     140                 :          0 :         driver->driver->probe = probe_fn;
     141                 :          0 :         driver->driver->remove = remove_fn;
     142                 :            : 
     143                 :          0 :         rte_pci_register(driver->driver);
     144                 :          0 :         return 0;
     145                 :            : }
     146                 :            : 
     147                 :            : static int
     148                 :          0 : pci_device_enable_interrupt_2207(struct rte_pci_device *rte_dev)
     149                 :            : {
     150                 :          0 :         return rte_intr_enable(rte_dev->intr_handle);
     151                 :            : }
     152                 :            : 
     153                 :            : static int
     154                 :          0 : pci_device_disable_interrupt_2207(struct rte_pci_device *rte_dev)
     155                 :            : {
     156                 :          0 :         return rte_intr_disable(rte_dev->intr_handle);
     157                 :            : }
     158                 :            : 
     159                 :            : static int
     160                 :          0 : pci_device_get_interrupt_efd_2207(struct rte_pci_device *rte_dev)
     161                 :            : {
     162                 :          0 :         return rte_intr_fd_get(rte_dev->intr_handle);
     163                 :            : }
     164                 :            : 
     165                 :            : static int
     166                 :          0 : bus_probe_2207(void)
     167                 :            : {
     168                 :          0 :         return rte_bus_probe();
     169                 :            : }
     170                 :            : 
     171                 :            : static void
     172                 :          0 : bus_scan_2207(void)
     173                 :            : {
     174                 :          0 :         rte_bus_scan();
     175                 :          0 : }
     176                 :            : 
     177                 :            : static struct rte_devargs *
     178                 :          0 : device_get_devargs_2207(struct rte_device *dev)
     179                 :            : {
     180                 :          0 :         return dev->devargs;
     181                 :            : }
     182                 :            : 
     183                 :            : static void
     184                 :          0 : device_set_devargs_2207(struct rte_device *dev, struct rte_devargs *devargs)
     185                 :            : {
     186                 :          0 :         dev->devargs = devargs;
     187                 :          0 : }
     188                 :            : 
     189                 :            : static const char *
     190                 :          0 : device_get_name_2207(struct rte_device *dev)
     191                 :            : {
     192                 :          0 :         return dev->name;
     193                 :            : }
     194                 :            : 
     195                 :            : static bool
     196                 :          0 : device_scan_allowed_2207(struct rte_device *dev)
     197                 :            : {
     198                 :          0 :         return dev->bus->conf.scan_mode == RTE_BUS_SCAN_ALLOWLIST;
     199                 :            : }
     200                 :            : 
     201                 :            : struct dpdk_fn_table fn_table_2207 = {
     202                 :            :         .pci_device_get_mem_resource    = pci_device_get_mem_resource_2207,
     203                 :            :         .pci_device_get_name            = pci_device_get_name_2207,
     204                 :            :         .pci_device_get_devargs         = pci_device_get_devargs_2207,
     205                 :            :         .pci_device_get_addr            = pci_device_get_addr_2207,
     206                 :            :         .pci_device_get_id              = pci_device_get_id_2207,
     207                 :            :         .pci_device_get_numa_node       = pci_device_get_numa_node_2207,
     208                 :            :         .pci_device_read_config         = pci_device_read_config_2207,
     209                 :            :         .pci_device_write_config        = pci_device_write_config_2207,
     210                 :            :         .pci_driver_register            = pci_driver_register_2207,
     211                 :            :         .pci_device_enable_interrupt    = pci_device_enable_interrupt_2207,
     212                 :            :         .pci_device_disable_interrupt   = pci_device_disable_interrupt_2207,
     213                 :            :         .pci_device_get_interrupt_efd   = pci_device_get_interrupt_efd_2207,
     214                 :            :         .bus_scan                       = bus_scan_2207,
     215                 :            :         .bus_probe                      = bus_probe_2207,
     216                 :            :         .device_get_devargs             = device_get_devargs_2207,
     217                 :            :         .device_set_devargs             = device_set_devargs_2207,
     218                 :            :         .device_get_name                = device_get_name_2207,
     219                 :            :         .device_scan_allowed            = device_scan_allowed_2207,
     220                 :            : };

Generated by: LCOV version 1.14