LCOV - code coverage report
Current view: top level - lib/env_dpdk - pci_dpdk_2211.c (source / functions) Hit Total Coverage
Test: ut_cov_unit.info Lines: 0 77 0.0 %
Date: 2024-07-12 17:03:50 Functions: 0 18 0.0 %

          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           0 : pci_device_get_mem_resource_2211(struct rte_pci_device *dev, uint32_t bar)
      28             : {
      29           0 :         if (bar >= PCI_MAX_RESOURCE) {
      30           0 :                 assert(false);
      31             :                 return NULL;
      32             :         }
      33             : 
      34           0 :         return &dev->mem_resource[bar];
      35             : }
      36             : 
      37             : static const char *
      38           0 : pci_device_get_name_2211(struct rte_pci_device *rte_dev)
      39             : {
      40           0 :         return rte_dev->name;
      41             : }
      42             : 
      43             : static struct rte_devargs *
      44           0 : pci_device_get_devargs_2211(struct rte_pci_device *rte_dev)
      45             : {
      46           0 :         return rte_dev->device.devargs;
      47             : }
      48             : 
      49             : static struct rte_pci_addr *
      50           0 : pci_device_get_addr_2211(struct rte_pci_device *_dev)
      51             : {
      52           0 :         return &_dev->addr;
      53             : }
      54             : 
      55             : static struct rte_pci_id *
      56           0 : pci_device_get_id_2211(struct rte_pci_device *_dev)
      57             : {
      58           0 :         return &_dev->id;
      59             : }
      60             : 
      61             : static int
      62           0 : pci_device_get_numa_node_2211(struct rte_pci_device *_dev)
      63             : {
      64           0 :         return _dev->device.numa_node;
      65             : }
      66             : 
      67             : static int
      68           0 : pci_device_read_config_2211(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
      69             : {
      70             :         int rc;
      71             : 
      72           0 :         rc = rte_pci_read_config(dev, value, len, offset);
      73             : 
      74           0 :         return (rc > 0 && (uint32_t) rc == len) ? 0 : -1;
      75             : }
      76             : 
      77             : static int
      78           0 : pci_device_write_config_2211(struct rte_pci_device *dev, void *value, uint32_t len, uint32_t offset)
      79             : {
      80             :         int rc;
      81             : 
      82           0 :         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           0 :         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           0 : 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           0 :         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           0 :         assert(driver->id_table);
     105           0 :         while (driver->id_table[pci_id_count].vendor_id) {
     106           0 :                 pci_id_count++;
     107             :         }
     108           0 :         assert(pci_id_count > 0);
     109             : 
     110           0 :         rte_id_table = calloc(pci_id_count + 1, sizeof(*rte_id_table));
     111           0 :         if (!rte_id_table) {
     112           0 :                 return -ENOMEM;
     113             :         }
     114             : 
     115           0 :         while (pci_id_count > 0) {
     116           0 :                 struct rte_pci_id *rte_id = &rte_id_table[pci_id_count - 1];
     117           0 :                 const struct spdk_pci_id *spdk_id = &driver->id_table[pci_id_count - 1];
     118             : 
     119           0 :                 rte_id->class_id = spdk_id->class_id;
     120           0 :                 rte_id->vendor_id = spdk_id->vendor_id;
     121           0 :                 rte_id->device_id = spdk_id->device_id;
     122           0 :                 rte_id->subsystem_vendor_id = spdk_id->subvendor_id;
     123           0 :                 rte_id->subsystem_device_id = spdk_id->subdevice_id;
     124           0 :                 pci_id_count--;
     125             :         }
     126             : 
     127           0 :         assert(driver->name);
     128           0 :         rte_name_len = strlen(driver->name) + strlen("spdk_") + 1;
     129           0 :         rte_name = calloc(rte_name_len, 1);
     130           0 :         if (!rte_name) {
     131           0 :                 free(rte_id_table);
     132           0 :                 return -ENOMEM;
     133             :         }
     134             : 
     135           0 :         snprintf(rte_name, rte_name_len, "spdk_%s", driver->name);
     136           0 :         driver->driver->driver.name = rte_name;
     137           0 :         driver->driver->id_table = rte_id_table;
     138             : 
     139           0 :         rte_flags = 0;
     140           0 :         if (driver->drv_flags & SPDK_PCI_DRIVER_NEED_MAPPING) {
     141           0 :                 rte_flags |= RTE_PCI_DRV_NEED_MAPPING;
     142             :         }
     143           0 :         if (driver->drv_flags & SPDK_PCI_DRIVER_WC_ACTIVATE) {
     144           0 :                 rte_flags |= RTE_PCI_DRV_WC_ACTIVATE;
     145             :         }
     146           0 :         driver->driver->drv_flags = rte_flags;
     147             : 
     148           0 :         driver->driver->probe = probe_fn;
     149           0 :         driver->driver->remove = remove_fn;
     150             : 
     151           0 :         rte_pci_register(driver->driver);
     152           0 :         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           0 : bus_probe_2211(void)
     175             : {
     176           0 :         return rte_bus_probe();
     177             : }
     178             : 
     179             : static void
     180           0 : bus_scan_2211(void)
     181             : {
     182           0 :         rte_bus_scan();
     183           0 : }
     184             : 
     185             : static struct rte_devargs *
     186           0 : device_get_devargs_2211(struct rte_device *dev)
     187             : {
     188           0 :         return dev->devargs;
     189             : }
     190             : 
     191             : static void
     192           0 : device_set_devargs_2211(struct rte_device *dev, struct rte_devargs *devargs)
     193             : {
     194           0 :         dev->devargs = devargs;
     195           0 : }
     196             : 
     197             : static const char *
     198           0 : device_get_name_2211(struct rte_device *dev)
     199             : {
     200           0 :         return dev->name;
     201             : }
     202             : 
     203             : static bool
     204           0 : device_scan_allowed_2211(struct rte_device *dev)
     205             : {
     206           0 :         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.15