LCOV - code coverage report
Current view: top level - spdk/lib/env_dpdk - pci_dpdk_2211.c (source / functions) Hit Total Coverage
Test: Combined Lines: 67 77 87.0 %
Date: 2024-07-12 21:20:59 Functions: 15 18 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 18 30 60.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                 :            : #define ALLOW_INTERNAL_API
       7                 :            : #include <rte_config.h>
       8                 :            : #include <rte_version.h>
       9                 :            : #include "pci_dpdk.h"
      10                 :            : #include "22.11/bus_pci_driver.h"
      11                 :            : #include "22.11/bus_driver.h"
      12                 :            : #include "22.11/rte_bus_pci.h"
      13                 :            : #include "spdk/assert.h"
      14                 :            : 
      15                 :            : SPDK_STATIC_ASSERT(offsetof(struct spdk_pci_driver, driver_buf) == 0, "driver_buf must be first");
      16                 :            : SPDK_STATIC_ASSERT(offsetof(struct spdk_pci_driver, driver) >= sizeof(struct rte_pci_driver),
      17                 :            :                    "driver_buf not big enough");
      18                 :            : 
      19                 :            : /* Following API was added in versions later than DPDK 22.11.
      20                 :            :  * It is unused right now, if this changes a new pci_dpdk_* should be added.
      21                 :            :  */
      22                 :            : #define rte_pci_mmio_read(...) SPDK_STATIC_ASSERT(false, "rte_pci_mmio_read requires new pci_dpdk_2307 compat layer")
      23                 :            : #define rte_pci_mmio_write(...) SPDK_STATIC_ASSERT(false, "rte_pci_mmio_write requires new pci_dpdk_2307 compat layer")
      24                 :            : #define rte_pci_pasid_set_state(...) SPDK_STATIC_ASSERT(false, "rte_pci_pasid_set_state requires new pci_dpdk_2307 compat layer")
      25                 :            : 
      26                 :            : static struct rte_mem_resource *
      27                 :      19810 : pci_device_get_mem_resource_2211(struct rte_pci_device *dev, uint32_t bar)
      28                 :            : {
      29         [ -  + ]:      19810 :         if (bar >= PCI_MAX_RESOURCE) {
      30                 :          0 :                 assert(false);
      31                 :            :                 return NULL;
      32                 :            :         }
      33                 :            : 
      34                 :      19810 :         return &dev->mem_resource[bar];
      35                 :            : }
      36                 :            : 
      37                 :            : static const char *
      38                 :       1137 : pci_device_get_name_2211(struct rte_pci_device *rte_dev)
      39                 :            : {
      40                 :       1137 :         return rte_dev->name;
      41                 :            : }
      42                 :            : 
      43                 :            : static struct rte_devargs *
      44                 :       4021 : pci_device_get_devargs_2211(struct rte_pci_device *rte_dev)
      45                 :            : {
      46                 :       4021 :         return rte_dev->device.devargs;
      47                 :            : }
      48                 :            : 
      49                 :            : static struct rte_pci_addr *
      50                 :       1921 : pci_device_get_addr_2211(struct rte_pci_device *_dev)
      51                 :            : {
      52                 :       1921 :         return &_dev->addr;
      53                 :            : }
      54                 :            : 
      55                 :            : static struct rte_pci_id *
      56                 :       1921 : pci_device_get_id_2211(struct rte_pci_device *_dev)
      57                 :            : {
      58                 :       1921 :         return &_dev->id;
      59                 :            : }
      60                 :            : 
      61                 :            : static int
      62                 :       1921 : pci_device_get_numa_node_2211(struct rte_pci_device *_dev)
      63                 :            : {
      64                 :       1921 :         return _dev->device.numa_node;
      65                 :            : }
      66                 :            : 
      67                 :            : static int
      68                 :       1188 : pci_device_read_config_2211(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
      69                 :            : {
      70                 :            :         int rc;
      71                 :            : 
      72                 :       1188 :         rc = rte_pci_read_config(dev, value, len, offset);
      73                 :            : 
      74   [ +  -  +  - ]:       1188 :         return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
      75                 :            : }
      76                 :            : 
      77                 :            : static int
      78                 :       1164 : pci_device_write_config_2211(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
      79                 :            : {
      80                 :            :         int rc;
      81                 :            : 
      82                 :       1164 :         rc = rte_pci_write_config(dev, value, len, offset);
      83                 :            : 
      84                 :            : #ifdef __FreeBSD__
      85                 :            :         /* DPDK returns 0 on success and -1 on failure */
      86                 :            :         return rc;
      87                 :            : #endif
      88   [ +  -  +  - ]:       1164 :         return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
      89                 :            : }
      90                 :            : 
      91                 :            : /* translate spdk_pci_driver to an rte_pci_driver and register it to dpdk */
      92                 :            : static int
      93                 :      16527 : pci_driver_register_2211(struct spdk_pci_driver *driver,
      94                 :            :                          int (*probe_fn)(struct rte_pci_driver *driver, struct rte_pci_device *device),
      95                 :            :                          int (*remove_fn)(struct rte_pci_device *device))
      96                 :            : 
      97                 :            : {
      98                 :      16527 :         unsigned pci_id_count = 0;
      99                 :            :         struct rte_pci_id *rte_id_table;
     100                 :            :         char *rte_name;
     101                 :            :         size_t rte_name_len;
     102                 :            :         uint32_t rte_flags;
     103                 :            : 
     104         [ -  + ]:      16527 :         assert(driver->id_table);
     105         [ +  + ]:     214970 :         while (driver->id_table[pci_id_count].vendor_id) {
     106                 :     198443 :                 pci_id_count++;
     107                 :            :         }
     108         [ -  + ]:      16527 :         assert(pci_id_count > 0);
     109                 :            : 
     110                 :      16527 :         rte_id_table = calloc(pci_id_count + 1, sizeof(*rte_id_table));
     111         [ -  + ]:      16527 :         if (!rte_id_table) {
     112                 :          0 :                 return -ENOMEM;
     113                 :            :         }
     114                 :            : 
     115         [ +  + ]:     214970 :         while (pci_id_count > 0) {
     116                 :     198443 :                 struct rte_pci_id *rte_id = &rte_id_table[pci_id_count - 1];
     117                 :     198443 :                 const struct spdk_pci_id *spdk_id = &driver->id_table[pci_id_count - 1];
     118                 :            : 
     119                 :     198443 :                 rte_id->class_id = spdk_id->class_id;
     120                 :     198443 :                 rte_id->vendor_id = spdk_id->vendor_id;
     121                 :     198443 :                 rte_id->device_id = spdk_id->device_id;
     122                 :     198443 :                 rte_id->subsystem_vendor_id = spdk_id->subvendor_id;
     123                 :     198443 :                 rte_id->subsystem_device_id = spdk_id->subdevice_id;
     124                 :     198443 :                 pci_id_count--;
     125                 :            :         }
     126                 :            : 
     127         [ -  + ]:      16527 :         assert(driver->name);
     128         [ -  + ]:      16527 :         rte_name_len = strlen(driver->name) + strlen("spdk_") + 1;
     129                 :      16527 :         rte_name = calloc(rte_name_len, 1);
     130         [ -  + ]:      16527 :         if (!rte_name) {
     131                 :          0 :                 free(rte_id_table);
     132                 :          0 :                 return -ENOMEM;
     133                 :            :         }
     134                 :            : 
     135                 :      16527 :         snprintf(rte_name, rte_name_len, "spdk_%s", driver->name);
     136                 :      16527 :         driver->driver->driver.name = rte_name;
     137                 :      16527 :         driver->driver->id_table = rte_id_table;
     138                 :            : 
     139                 :      16527 :         rte_flags = 0;
     140         [ +  - ]:      16527 :         if (driver->drv_flags & SPDK_PCI_DRIVER_NEED_MAPPING) {
     141                 :      16527 :                 rte_flags |= RTE_PCI_DRV_NEED_MAPPING;
     142                 :            :         }
     143         [ +  + ]:      16527 :         if (driver->drv_flags & SPDK_PCI_DRIVER_WC_ACTIVATE) {
     144                 :       9653 :                 rte_flags |= RTE_PCI_DRV_WC_ACTIVATE;
     145                 :            :         }
     146                 :      16527 :         driver->driver->drv_flags = rte_flags;
     147                 :            : 
     148                 :      16527 :         driver->driver->probe = probe_fn;
     149                 :      16527 :         driver->driver->remove = remove_fn;
     150                 :            : 
     151                 :      16527 :         rte_pci_register(driver->driver);
     152                 :      16527 :         return 0;
     153                 :            : }
     154                 :            : 
     155                 :            : static int
     156                 :          0 : pci_device_enable_interrupt_2211(struct rte_pci_device *rte_dev)
     157                 :            : {
     158                 :          0 :         return rte_intr_enable(rte_dev->intr_handle);
     159                 :            : }
     160                 :            : 
     161                 :            : static int
     162                 :          0 : pci_device_disable_interrupt_2211(struct rte_pci_device *rte_dev)
     163                 :            : {
     164                 :          0 :         return rte_intr_disable(rte_dev->intr_handle);
     165                 :            : }
     166                 :            : 
     167                 :            : static int
     168                 :          0 : pci_device_get_interrupt_efd_2211(struct rte_pci_device *rte_dev)
     169                 :            : {
     170                 :          0 :         return rte_intr_fd_get(rte_dev->intr_handle);
     171                 :            : }
     172                 :            : 
     173                 :            : static int
     174                 :      77661 : bus_probe_2211(void)
     175                 :            : {
     176                 :      77661 :         return rte_bus_probe();
     177                 :            : }
     178                 :            : 
     179                 :            : static void
     180                 :      81270 : bus_scan_2211(void)
     181                 :            : {
     182                 :      81270 :         rte_bus_scan();
     183                 :      81270 : }
     184                 :            : 
     185                 :            : static struct rte_devargs *
     186                 :     864581 : device_get_devargs_2211(struct rte_device *dev)
     187                 :            : {
     188                 :     864581 :         return dev->devargs;
     189                 :            : }
     190                 :            : 
     191                 :            : static void
     192                 :     118460 : device_set_devargs_2211(struct rte_device *dev, struct rte_devargs *devargs)
     193                 :            : {
     194                 :     118460 :         dev->devargs = devargs;
     195                 :     118460 : }
     196                 :            : 
     197                 :            : static const char *
     198                 :     118460 : device_get_name_2211(struct rte_device *dev)
     199                 :            : {
     200                 :     118460 :         return dev->name;
     201                 :            : }
     202                 :            : 
     203                 :            : static bool
     204                 :     118460 : device_scan_allowed_2211(struct rte_device *dev)
     205                 :            : {
     206                 :     118460 :         return dev->bus->conf.scan_mode == RTE_BUS_SCAN_ALLOWLIST;
     207                 :            : }
     208                 :            : 
     209                 :            : struct dpdk_fn_table fn_table_2211 = {
     210                 :            :         .pci_device_get_mem_resource    = pci_device_get_mem_resource_2211,
     211                 :            :         .pci_device_get_name            = pci_device_get_name_2211,
     212                 :            :         .pci_device_get_devargs         = pci_device_get_devargs_2211,
     213                 :            :         .pci_device_get_addr            = pci_device_get_addr_2211,
     214                 :            :         .pci_device_get_id              = pci_device_get_id_2211,
     215                 :            :         .pci_device_get_numa_node       = pci_device_get_numa_node_2211,
     216                 :            :         .pci_device_read_config         = pci_device_read_config_2211,
     217                 :            :         .pci_device_write_config        = pci_device_write_config_2211,
     218                 :            :         .pci_driver_register            = pci_driver_register_2211,
     219                 :            :         .pci_device_enable_interrupt    = pci_device_enable_interrupt_2211,
     220                 :            :         .pci_device_disable_interrupt   = pci_device_disable_interrupt_2211,
     221                 :            :         .pci_device_get_interrupt_efd   = pci_device_get_interrupt_efd_2211,
     222                 :            :         .bus_scan                       = bus_scan_2211,
     223                 :            :         .bus_probe                      = bus_probe_2211,
     224                 :            :         .device_get_devargs             = device_get_devargs_2211,
     225                 :            :         .device_set_devargs             = device_set_devargs_2211,
     226                 :            :         .device_get_name                = device_get_name_2211,
     227                 :            :         .device_scan_allowed            = device_scan_allowed_2211,
     228                 :            : };

Generated by: LCOV version 1.14