LCOV - code coverage report
Current view: top level - drivers/event/dlb2/pf - dlb2_main.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 238 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 128 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2016-2020 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdint.h>
       6                 :            : #include <stdbool.h>
       7                 :            : #include <stdio.h>
       8                 :            : #include <errno.h>
       9                 :            : #include <assert.h>
      10                 :            : #include <unistd.h>
      11                 :            : #include <string.h>
      12                 :            : 
      13                 :            : #include <rte_malloc.h>
      14                 :            : #include <rte_errno.h>
      15                 :            : 
      16                 :            : #include "base/dlb2_regs.h"
      17                 :            : #include "base/dlb2_hw_types.h"
      18                 :            : #include "base/dlb2_resource.h"
      19                 :            : #include "base/dlb2_osdep.h"
      20                 :            : #include "dlb2_main.h"
      21                 :            : #include "../dlb2_user.h"
      22                 :            : #include "../dlb2_priv.h"
      23                 :            : #include "../dlb2_iface.h"
      24                 :            : #include "../dlb2_inline_fns.h"
      25                 :            : 
      26                 :            : #define PF_ID_ZERO 0    /* PF ONLY! */
      27                 :            : #define NO_OWNER_VF 0   /* PF ONLY! */
      28                 :            : #define NOT_VF_REQ false /* PF ONLY! */
      29                 :            : #define DLB2_PCI_PASID_CAP_OFFSET        0x148   /* PASID capability offset */
      30                 :            : 
      31                 :            : static int
      32                 :            : dlb2_pf_init_driver_state(struct dlb2_dev *dlb2_dev)
      33                 :            : {
      34                 :            :         rte_spinlock_init(&dlb2_dev->resource_mutex);
      35                 :            : 
      36                 :            :         return 0;
      37                 :            : }
      38                 :            : 
      39                 :            : static void dlb2_pf_enable_pm(struct dlb2_dev *dlb2_dev)
      40                 :            : {
      41                 :            :         int version;
      42                 :          0 :         version = DLB2_HW_DEVICE_FROM_PCI_ID(dlb2_dev->pdev);
      43                 :            : 
      44                 :          0 :         dlb2_clr_pmcsr_disable(&dlb2_dev->hw, version);
      45                 :            : }
      46                 :            : 
      47                 :            : #define DLB2_READY_RETRY_LIMIT 1000
      48                 :          0 : static int dlb2_pf_wait_for_device_ready(struct dlb2_dev *dlb2_dev,
      49                 :            :                                          int dlb_version)
      50                 :            : {
      51                 :            :         u32 retries = 0;
      52                 :            : 
      53                 :            :         /* Allow at least 1s for the device to become active after power-on */
      54         [ #  # ]:          0 :         for (retries = 0; retries < DLB2_READY_RETRY_LIMIT; retries++) {
      55                 :            :                 u32 idle_val;
      56                 :            :                 u32 idle_dlb_func_idle;
      57                 :            :                 u32 pm_st_val;
      58                 :            :                 u32 pm_st_pmsm;
      59                 :            :                 u32 addr;
      60                 :            : 
      61         [ #  # ]:          0 :                 addr = DLB2_CM_CFG_PM_STATUS(dlb_version);
      62                 :          0 :                 pm_st_val = DLB2_CSR_RD(&dlb2_dev->hw, addr);
      63         [ #  # ]:          0 :                 addr = DLB2_CM_CFG_DIAGNOSTIC_IDLE_STATUS(dlb_version);
      64                 :          0 :                 idle_val = DLB2_CSR_RD(&dlb2_dev->hw, addr);
      65                 :            :                 idle_dlb_func_idle = idle_val &
      66                 :            :                         DLB2_CM_CFG_DIAGNOSTIC_IDLE_STATUS_DLB_FUNC_IDLE;
      67                 :          0 :                 pm_st_pmsm = pm_st_val & DLB2_CM_CFG_PM_STATUS_PMSM;
      68         [ #  # ]:          0 :                 if (pm_st_pmsm && idle_dlb_func_idle)
      69                 :            :                         break;
      70                 :            : 
      71                 :            :                 rte_delay_ms(1);
      72                 :            :         };
      73                 :            : 
      74         [ #  # ]:          0 :         if (retries == DLB2_READY_RETRY_LIMIT) {
      75                 :          0 :                 DLB2_LOG_ERR("[%s()] wait for device ready timed out",
      76                 :            :                        __func__);
      77                 :          0 :                 return -1;
      78                 :            :         }
      79                 :            : 
      80                 :            :         return 0;
      81                 :            : }
      82                 :            : 
      83                 :            : struct dlb2_dev *
      84                 :          0 : dlb2_probe(struct rte_pci_device *pdev, const void *probe_args)
      85                 :            : {
      86                 :            :         struct dlb2_dev *dlb2_dev;
      87                 :            :         int ret = 0;
      88                 :            :         int dlb_version = 0;
      89                 :            : 
      90                 :          0 :         DLB2_INFO(dlb2_dev, "probe\n");
      91                 :            : 
      92                 :          0 :         dlb2_dev = rte_malloc("DLB2_PF", sizeof(struct dlb2_dev),
      93                 :            :                               RTE_CACHE_LINE_SIZE);
      94                 :            : 
      95         [ #  # ]:          0 :         if (dlb2_dev == NULL) {
      96                 :            :                 ret = -ENOMEM;
      97                 :          0 :                 goto dlb2_dev_malloc_fail;
      98                 :            :         }
      99                 :            : 
     100                 :          0 :         dlb_version = DLB2_HW_DEVICE_FROM_PCI_ID(pdev);
     101                 :            : 
     102                 :            :         /* PCI Bus driver has already mapped bar space into process.
     103                 :            :          * Save off our IO register and FUNC addresses.
     104                 :            :          */
     105                 :            : 
     106                 :            :         /* BAR 0 */
     107         [ #  # ]:          0 :         if (pdev->mem_resource[0].addr == NULL) {
     108                 :          0 :                 DLB2_ERR(dlb2_dev, "probe: BAR 0 addr (csr_kva) is NULL\n");
     109                 :            :                 ret = -EINVAL;
     110                 :          0 :                 goto pci_mmap_bad_addr;
     111                 :            :         }
     112                 :          0 :         dlb2_dev->hw.func_kva = (void *)(uintptr_t)pdev->mem_resource[0].addr;
     113                 :          0 :         dlb2_dev->hw.func_phys_addr = pdev->mem_resource[0].phys_addr;
     114                 :            : 
     115                 :          0 :         DLB2_INFO(dlb2_dev, "DLB2 FUNC VA=%p, PA=%p, len=%p\n",
     116                 :            :                   (void *)dlb2_dev->hw.func_kva,
     117                 :            :                   (void *)dlb2_dev->hw.func_phys_addr,
     118                 :            :                   (void *)(pdev->mem_resource[0].len));
     119                 :            : 
     120                 :            :         /* BAR 2 */
     121         [ #  # ]:          0 :         if (pdev->mem_resource[2].addr == NULL) {
     122                 :          0 :                 DLB2_ERR(dlb2_dev, "probe: BAR 2 addr (func_kva) is NULL\n");
     123                 :            :                 ret = -EINVAL;
     124                 :          0 :                 goto pci_mmap_bad_addr;
     125                 :            :         }
     126                 :          0 :         dlb2_dev->hw.csr_kva = (void *)(uintptr_t)pdev->mem_resource[2].addr;
     127                 :          0 :         dlb2_dev->hw.csr_phys_addr = pdev->mem_resource[2].phys_addr;
     128                 :            : 
     129                 :          0 :         DLB2_INFO(dlb2_dev, "DLB2 CSR VA=%p, PA=%p, len=%p\n",
     130                 :            :                   (void *)dlb2_dev->hw.csr_kva,
     131                 :            :                   (void *)dlb2_dev->hw.csr_phys_addr,
     132                 :            :                   (void *)(pdev->mem_resource[2].len));
     133                 :            : 
     134                 :          0 :         dlb2_dev->pdev = pdev;
     135                 :            : 
     136                 :            :         /* PM enable must be done before any other MMIO accesses, and this
     137                 :            :          * setting is persistent across device reset.
     138                 :            :          */
     139                 :            :         dlb2_pf_enable_pm(dlb2_dev);
     140                 :            : 
     141                 :          0 :         ret = dlb2_pf_wait_for_device_ready(dlb2_dev, dlb_version);
     142         [ #  # ]:          0 :         if (ret)
     143                 :          0 :                 goto wait_for_device_ready_fail;
     144                 :            : 
     145                 :          0 :         ret = dlb2_resource_probe(&dlb2_dev->hw, probe_args);
     146         [ #  # ]:          0 :         if (ret)
     147                 :          0 :                 goto resource_probe_fail;
     148                 :            : 
     149                 :          0 :         ret = dlb2_pf_reset(dlb2_dev);
     150         [ #  # ]:          0 :         if (ret)
     151                 :          0 :                 goto dlb2_reset_fail;
     152                 :            : 
     153                 :            :         ret = dlb2_pf_init_driver_state(dlb2_dev);
     154                 :            :         if (ret)
     155                 :            :                 goto init_driver_state_fail;
     156                 :            : 
     157                 :          0 :         ret = dlb2_resource_init(&dlb2_dev->hw, dlb_version, probe_args);
     158         [ #  # ]:          0 :         if (ret)
     159                 :          0 :                 goto resource_init_fail;
     160                 :            : 
     161                 :            :         return dlb2_dev;
     162                 :            : 
     163                 :            : resource_init_fail:
     164                 :          0 :         dlb2_resource_free(&dlb2_dev->hw);
     165                 :          0 : init_driver_state_fail:
     166                 :          0 : dlb2_reset_fail:
     167                 :          0 : pci_mmap_bad_addr:
     168                 :          0 : resource_probe_fail:
     169                 :          0 : wait_for_device_ready_fail:
     170                 :          0 :         rte_free(dlb2_dev);
     171                 :          0 : dlb2_dev_malloc_fail:
     172                 :          0 :         rte_errno = ret;
     173                 :          0 :         return NULL;
     174                 :            : }
     175                 :            : 
     176                 :            : int
     177                 :          0 : dlb2_pf_reset(struct dlb2_dev *dlb2_dev)
     178                 :            : {
     179                 :            :         int ret = 0;
     180                 :            :         int i = 0;
     181                 :            :         uint32_t dword[16];
     182                 :            :         uint16_t cmd;
     183                 :            :         off_t off;
     184                 :            : 
     185                 :            :         uint16_t dev_ctl_word;
     186                 :            :         uint16_t dev_ctl2_word;
     187                 :            :         uint16_t lnk_word;
     188                 :            :         uint16_t lnk_word2;
     189                 :            :         uint16_t slt_word;
     190                 :            :         uint16_t slt_word2;
     191                 :            :         uint16_t rt_ctl_word;
     192                 :            :         uint32_t pri_reqs_dword;
     193                 :            :         uint16_t pri_ctrl_word;
     194                 :            : 
     195                 :            :         off_t pcie_cap_offset;
     196                 :            :         int pri_cap_offset;
     197                 :            :         off_t msix_cap_offset;
     198                 :            :         int err_cap_offset;
     199                 :            :         int acs_cap_offset;
     200                 :            :         int wait_count;
     201                 :            : 
     202                 :            :         uint16_t devsta_busy_word;
     203                 :            :         uint16_t devctl_word;
     204                 :            : 
     205                 :          0 :         struct rte_pci_device *pdev = dlb2_dev->pdev;
     206                 :            : 
     207                 :            :         /* Save PCI config state */
     208                 :            : 
     209         [ #  # ]:          0 :         for (i = 0; i < 16; i++) {
     210         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &dword[i], 4, i * 4) != 4)
     211                 :            :                         return ret;
     212                 :            :         }
     213                 :            : 
     214                 :          0 :         pcie_cap_offset = rte_pci_find_capability(pdev, RTE_PCI_CAP_ID_EXP);
     215                 :            : 
     216         [ #  # ]:          0 :         if (pcie_cap_offset < 0) {
     217                 :          0 :                 DLB2_LOG_ERR("[%s()] failed to find the pcie capability",
     218                 :            :                        __func__);
     219                 :          0 :                 return pcie_cap_offset;
     220                 :            :         }
     221                 :            : 
     222                 :          0 :         off = pcie_cap_offset + RTE_PCI_EXP_DEVCTL;
     223         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &dev_ctl_word, 2, off) != 2)
     224                 :          0 :                 dev_ctl_word = 0;
     225                 :            : 
     226                 :          0 :         off = pcie_cap_offset + RTE_PCI_EXP_LNKCTL;
     227         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &lnk_word, 2, off) != 2)
     228                 :          0 :                 lnk_word = 0;
     229                 :            : 
     230                 :          0 :         off = pcie_cap_offset + RTE_PCI_EXP_SLTCTL;
     231         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &slt_word, 2, off) != 2)
     232                 :          0 :                 slt_word = 0;
     233                 :            : 
     234                 :          0 :         off = pcie_cap_offset + RTE_PCI_EXP_RTCTL;
     235         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &rt_ctl_word, 2, off) != 2)
     236                 :          0 :                 rt_ctl_word = 0;
     237                 :            : 
     238                 :          0 :         off = pcie_cap_offset + RTE_PCI_EXP_DEVCTL2;
     239         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &dev_ctl2_word, 2, off) != 2)
     240                 :          0 :                 dev_ctl2_word = 0;
     241                 :            : 
     242                 :          0 :         off = pcie_cap_offset + RTE_PCI_EXP_LNKCTL2;
     243         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &lnk_word2, 2, off) != 2)
     244                 :          0 :                 lnk_word2 = 0;
     245                 :            : 
     246                 :          0 :         off = pcie_cap_offset + RTE_PCI_EXP_SLTCTL2;
     247         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &slt_word2, 2, off) != 2)
     248                 :          0 :                 slt_word2 = 0;
     249                 :            : 
     250                 :            :         off = RTE_PCI_EXT_CAP_ID_PRI;
     251                 :          0 :         pri_cap_offset = rte_pci_find_ext_capability(pdev, off);
     252                 :            : 
     253         [ #  # ]:          0 :         if (pri_cap_offset >= 0) {
     254                 :          0 :                 off = pri_cap_offset + RTE_PCI_PRI_ALLOC_REQ;
     255         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &pri_reqs_dword, 4, off) != 4)
     256                 :          0 :                         pri_reqs_dword = 0;
     257                 :            :         }
     258                 :            : 
     259                 :            :         /* clear the PCI command register before issuing the FLR */
     260                 :            : 
     261                 :            :         off = RTE_PCI_COMMAND;
     262                 :          0 :         cmd = 0;
     263         [ #  # ]:          0 :         if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
     264                 :          0 :                 DLB2_LOG_ERR("[%s()] failed to write the pci command",
     265                 :            :                        __func__);
     266                 :          0 :                 return ret;
     267                 :            :         }
     268                 :            : 
     269                 :            :         /* issue the FLR */
     270         [ #  # ]:          0 :         for (wait_count = 0; wait_count < 4; wait_count++) {
     271                 :            :                 int sleep_time;
     272                 :            : 
     273                 :          0 :                 off = pcie_cap_offset + RTE_PCI_EXP_DEVSTA;
     274                 :          0 :                 ret = rte_pci_read_config(pdev, &devsta_busy_word, 2, off);
     275         [ #  # ]:          0 :                 if (ret != 2) {
     276                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to read the pci device status",
     277                 :            :                                __func__);
     278                 :          0 :                         return ret;
     279                 :            :                 }
     280                 :            : 
     281         [ #  # ]:          0 :                 if (!(devsta_busy_word & RTE_PCI_EXP_DEVSTA_TRPND))
     282                 :            :                         break;
     283                 :            : 
     284                 :          0 :                 sleep_time = (1 << (wait_count)) * 100;
     285                 :          0 :                 rte_delay_ms(sleep_time);
     286                 :            :         }
     287                 :            : 
     288         [ #  # ]:          0 :         if (wait_count == 4) {
     289                 :          0 :                 DLB2_LOG_ERR("[%s()] wait for pci pending transactions timed out",
     290                 :            :                        __func__);
     291                 :          0 :                 return -1;
     292                 :            :         }
     293                 :            : 
     294                 :            :         off = pcie_cap_offset + RTE_PCI_EXP_DEVCTL;
     295                 :          0 :         ret = rte_pci_read_config(pdev, &devctl_word, 2, off);
     296         [ #  # ]:          0 :         if (ret != 2) {
     297                 :          0 :                 DLB2_LOG_ERR("[%s()] failed to read the pcie device control",
     298                 :            :                        __func__);
     299                 :          0 :                 return ret;
     300                 :            :         }
     301                 :            : 
     302                 :          0 :         devctl_word |= RTE_PCI_EXP_DEVCTL_BCR_FLR;
     303                 :            : 
     304                 :          0 :         ret = rte_pci_write_config(pdev, &devctl_word, 2, off);
     305         [ #  # ]:          0 :         if (ret != 2) {
     306                 :          0 :                 DLB2_LOG_ERR("[%s()] failed to write the pcie device control",
     307                 :            :                        __func__);
     308                 :          0 :                 return ret;
     309                 :            :         }
     310                 :            : 
     311                 :            :         rte_delay_ms(100);
     312                 :            : 
     313                 :            :         /* Restore PCI config state */
     314                 :            : 
     315                 :            :         if (pcie_cap_offset >= 0) {
     316                 :            :                 off = pcie_cap_offset + RTE_PCI_EXP_DEVCTL;
     317                 :          0 :                 ret = rte_pci_write_config(pdev, &dev_ctl_word, 2, off);
     318         [ #  # ]:          0 :                 if (ret != 2) {
     319                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie device control at offset %d",
     320                 :            :                                 __func__, (int)off);
     321                 :          0 :                         return ret;
     322                 :            :                 }
     323                 :            : 
     324                 :            :                 off = pcie_cap_offset + RTE_PCI_EXP_LNKCTL;
     325                 :          0 :                 ret = rte_pci_write_config(pdev, &lnk_word, 2, off);
     326         [ #  # ]:          0 :                 if (ret != 2) {
     327                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     328                 :            :                                 __func__, (int)off);
     329                 :          0 :                         return ret;
     330                 :            :                 }
     331                 :            : 
     332                 :            :                 off = pcie_cap_offset + RTE_PCI_EXP_SLTCTL;
     333                 :          0 :                 ret = rte_pci_write_config(pdev, &slt_word, 2, off);
     334         [ #  # ]:          0 :                 if (ret != 2) {
     335                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     336                 :            :                                 __func__, (int)off);
     337                 :          0 :                         return ret;
     338                 :            :                 }
     339                 :            : 
     340                 :            :                 off = pcie_cap_offset + RTE_PCI_EXP_RTCTL;
     341                 :          0 :                 ret = rte_pci_write_config(pdev, &rt_ctl_word, 2, off);
     342         [ #  # ]:          0 :                 if (ret != 2) {
     343                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     344                 :            :                                 __func__, (int)off);
     345                 :          0 :                         return ret;
     346                 :            :                 }
     347                 :            : 
     348                 :            :                 off = pcie_cap_offset + RTE_PCI_EXP_DEVCTL2;
     349                 :          0 :                 ret = rte_pci_write_config(pdev, &dev_ctl2_word, 2, off);
     350         [ #  # ]:          0 :                 if (ret != 2) {
     351                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     352                 :            :                                 __func__, (int)off);
     353                 :          0 :                         return ret;
     354                 :            :                 }
     355                 :            : 
     356                 :            :                 off = pcie_cap_offset + RTE_PCI_EXP_LNKCTL2;
     357                 :          0 :                 ret = rte_pci_write_config(pdev, &lnk_word2, 2, off);
     358         [ #  # ]:          0 :                 if (ret != 2) {
     359                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     360                 :            :                                 __func__, (int)off);
     361                 :          0 :                         return ret;
     362                 :            :                 }
     363                 :            : 
     364                 :            :                 off = pcie_cap_offset + RTE_PCI_EXP_SLTCTL2;
     365                 :          0 :                 ret = rte_pci_write_config(pdev, &slt_word2, 2, off);
     366         [ #  # ]:          0 :                 if (ret != 2) {
     367                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     368                 :            :                                 __func__, (int)off);
     369                 :          0 :                         return ret;
     370                 :            :                 }
     371                 :            :         }
     372                 :            : 
     373         [ #  # ]:          0 :         if (pri_cap_offset >= 0) {
     374                 :          0 :                 pri_ctrl_word = RTE_PCI_PRI_CTRL_ENABLE;
     375                 :            : 
     376                 :          0 :                 off = pri_cap_offset + RTE_PCI_PRI_ALLOC_REQ;
     377                 :          0 :                 ret = rte_pci_write_config(pdev, &pri_reqs_dword, 4, off);
     378         [ #  # ]:          0 :                 if (ret != 4) {
     379                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     380                 :            :                                 __func__, (int)off);
     381                 :          0 :                         return ret;
     382                 :            :                 }
     383                 :            : 
     384                 :          0 :                 off = pri_cap_offset + RTE_PCI_PRI_CTRL;
     385                 :          0 :                 ret = rte_pci_write_config(pdev, &pri_ctrl_word, 2, off);
     386         [ #  # ]:          0 :                 if (ret != 2) {
     387                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     388                 :            :                                 __func__, (int)off);
     389                 :          0 :                         return ret;
     390                 :            :                 }
     391                 :            :         }
     392                 :            : 
     393                 :            :         off = RTE_PCI_EXT_CAP_ID_ERR;
     394                 :          0 :         err_cap_offset = rte_pci_find_ext_capability(pdev, off);
     395                 :            : 
     396         [ #  # ]:          0 :         if (err_cap_offset >= 0) {
     397                 :            :                 uint32_t tmp;
     398                 :            : 
     399                 :          0 :                 off = err_cap_offset + RTE_PCI_ERR_ROOT_STATUS;
     400         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &tmp, 4, off) != 4)
     401                 :          0 :                         tmp = 0;
     402                 :            : 
     403                 :          0 :                 ret = rte_pci_write_config(pdev, &tmp, 4, off);
     404         [ #  # ]:          0 :                 if (ret != 4) {
     405                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     406                 :            :                                 __func__, (int)off);
     407                 :          0 :                         return ret;
     408                 :            :                 }
     409                 :            : 
     410                 :          0 :                 off = err_cap_offset + RTE_PCI_ERR_COR_STATUS;
     411         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &tmp, 4, off) != 4)
     412                 :          0 :                         tmp = 0;
     413                 :            : 
     414                 :          0 :                 ret = rte_pci_write_config(pdev, &tmp, 4, off);
     415         [ #  # ]:          0 :                 if (ret != 4) {
     416                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     417                 :            :                                 __func__, (int)off);
     418                 :          0 :                         return ret;
     419                 :            :                 }
     420                 :            : 
     421                 :          0 :                 off = err_cap_offset + RTE_PCI_ERR_UNCOR_STATUS;
     422         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &tmp, 4, off) != 4)
     423                 :          0 :                         tmp = 0;
     424                 :            : 
     425                 :          0 :                 ret = rte_pci_write_config(pdev, &tmp, 4, off);
     426         [ #  # ]:          0 :                 if (ret != 4) {
     427                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     428                 :            :                                 __func__, (int)off);
     429                 :          0 :                         return ret;
     430                 :            :                 }
     431                 :            :         }
     432                 :            : 
     433         [ #  # ]:          0 :         for (i = 16; i > 0; i--) {
     434                 :          0 :                 off = (i - 1) * 4;
     435                 :          0 :                 ret = rte_pci_write_config(pdev, &dword[i - 1], 4, off);
     436         [ #  # ]:          0 :                 if (ret != 4) {
     437                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     438                 :            :                                 __func__, (int)off);
     439                 :          0 :                         return ret;
     440                 :            :                 }
     441                 :            :         }
     442                 :            : 
     443                 :            :         off = RTE_PCI_COMMAND;
     444         [ #  # ]:          0 :         if (rte_pci_read_config(pdev, &cmd, 2, off) == 2) {
     445                 :          0 :                 cmd &= ~RTE_PCI_COMMAND_INTX_DISABLE;
     446         [ #  # ]:          0 :                 if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
     447                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pci command",
     448                 :            :                                __func__);
     449                 :          0 :                         return ret;
     450                 :            :                 }
     451                 :            :         }
     452                 :            : 
     453                 :          0 :         msix_cap_offset = rte_pci_find_capability(pdev, RTE_PCI_CAP_ID_MSIX);
     454         [ #  # ]:          0 :         if (msix_cap_offset >= 0) {
     455                 :          0 :                 off = msix_cap_offset + RTE_PCI_MSIX_FLAGS;
     456         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &cmd, 2, off) == 2) {
     457                 :          0 :                         cmd |= RTE_PCI_MSIX_FLAGS_ENABLE;
     458                 :          0 :                         cmd |= RTE_PCI_MSIX_FLAGS_MASKALL;
     459         [ #  # ]:          0 :                         if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
     460                 :          0 :                                 DLB2_LOG_ERR("[%s()] failed to write msix flags",
     461                 :            :                                        __func__);
     462                 :          0 :                                 return ret;
     463                 :            :                         }
     464                 :            :                 }
     465                 :            : 
     466                 :            :                 off = msix_cap_offset + RTE_PCI_MSIX_FLAGS;
     467         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &cmd, 2, off) == 2) {
     468                 :          0 :                         cmd &= ~RTE_PCI_MSIX_FLAGS_MASKALL;
     469         [ #  # ]:          0 :                         if (rte_pci_write_config(pdev, &cmd, 2, off) != 2) {
     470                 :          0 :                                 DLB2_LOG_ERR("[%s()] failed to write msix flags",
     471                 :            :                                        __func__);
     472                 :          0 :                                 return ret;
     473                 :            :                         }
     474                 :            :                 }
     475                 :            :         }
     476                 :            : 
     477                 :            :         off = RTE_PCI_EXT_CAP_ID_ACS;
     478                 :          0 :         acs_cap_offset = rte_pci_find_ext_capability(pdev, off);
     479                 :            : 
     480         [ #  # ]:          0 :         if (acs_cap_offset >= 0) {
     481                 :            :                 uint16_t acs_cap, acs_ctrl, acs_mask;
     482                 :          0 :                 off = acs_cap_offset + RTE_PCI_ACS_CAP;
     483         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &acs_cap, 2, off) != 2)
     484                 :          0 :                         acs_cap = 0;
     485                 :            : 
     486                 :          0 :                 off = acs_cap_offset + RTE_PCI_ACS_CTRL;
     487         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &acs_ctrl, 2, off) != 2)
     488                 :          0 :                         acs_ctrl = 0;
     489                 :            : 
     490                 :            :                 acs_mask = RTE_PCI_ACS_SV | RTE_PCI_ACS_RR;
     491                 :            :                 acs_mask |= (RTE_PCI_ACS_CR | RTE_PCI_ACS_UF);
     492                 :          0 :                 acs_ctrl |= (acs_cap & acs_mask);
     493                 :            : 
     494                 :          0 :                 ret = rte_pci_write_config(pdev, &acs_ctrl, 2, off);
     495         [ #  # ]:          0 :                 if (ret != 2) {
     496                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     497                 :            :                                 __func__, (int)off);
     498                 :          0 :                         return ret;
     499                 :            :                 }
     500                 :            : 
     501                 :            :                 off = acs_cap_offset + RTE_PCI_ACS_CTRL;
     502         [ #  # ]:          0 :                 if (rte_pci_read_config(pdev, &acs_ctrl, 2, off) != 2)
     503                 :          0 :                         acs_ctrl = 0;
     504                 :            : 
     505                 :            :                 acs_mask = RTE_PCI_ACS_RR | RTE_PCI_ACS_CR;
     506                 :            :                 acs_mask |= RTE_PCI_ACS_EC;
     507                 :          0 :                 acs_ctrl &= ~acs_mask;
     508                 :            : 
     509                 :            :                 off = acs_cap_offset + RTE_PCI_ACS_CTRL;
     510                 :          0 :                 ret = rte_pci_write_config(pdev, &acs_ctrl, 2, off);
     511         [ #  # ]:          0 :                 if (ret != 2) {
     512                 :          0 :                         DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     513                 :            :                                 __func__, (int)off);
     514                 :          0 :                         return ret;
     515                 :            :                 }
     516                 :            :         }
     517                 :            : 
     518                 :            :         /* Disable PASID if it is enabled by default, which
     519                 :            :          * breaks the DLB if enabled.
     520                 :            :          */
     521                 :            :         off = DLB2_PCI_PASID_CAP_OFFSET;
     522         [ #  # ]:          0 :         if (rte_pci_pasid_set_state(pdev, off, false) < 0) {
     523                 :          0 :                 DLB2_LOG_ERR("[%s()] failed to write the pcie config space at offset %d",
     524                 :            :                                 __func__, (int)off);
     525                 :          0 :                 return -1;
     526                 :            :         }
     527                 :            : 
     528                 :            :         return 0;
     529                 :            : }
     530                 :            : 
     531                 :            : int
     532                 :          0 : dlb2_pf_create_sched_domain(struct dlb2_hw *hw,
     533                 :            :                             struct dlb2_create_sched_domain_args *args,
     534                 :            :                             struct dlb2_cmd_response *resp)
     535                 :            : {
     536                 :          0 :         return dlb2_hw_create_sched_domain(hw, args, resp, NOT_VF_REQ,
     537                 :            :                                            PF_ID_ZERO);
     538                 :            : }
     539                 :            : 
     540                 :            : int
     541                 :          0 : dlb2_pf_reset_domain(struct dlb2_hw *hw, u32 id)
     542                 :            : {
     543                 :          0 :         return dlb2_reset_domain(hw, id, NOT_VF_REQ, PF_ID_ZERO);
     544                 :            : }
     545                 :            : 
     546                 :            : int
     547                 :          0 : dlb2_pf_create_ldb_queue(struct dlb2_hw *hw,
     548                 :            :                          u32 id,
     549                 :            :                          struct dlb2_create_ldb_queue_args *args,
     550                 :            :                          struct dlb2_cmd_response *resp)
     551                 :            : {
     552                 :          0 :         return dlb2_hw_create_ldb_queue(hw, id, args, resp, NOT_VF_REQ,
     553                 :            :                                         PF_ID_ZERO);
     554                 :            : }
     555                 :            : 
     556                 :            : int
     557                 :          0 : dlb2_pf_create_ldb_port(struct dlb2_hw *hw,
     558                 :            :                         u32 id,
     559                 :            :                         struct dlb2_create_ldb_port_args *args,
     560                 :            :                         uintptr_t cq_dma_base,
     561                 :            :                         struct dlb2_cmd_response *resp)
     562                 :            : {
     563                 :          0 :         return dlb2_hw_create_ldb_port(hw, id, args,
     564                 :            :                                        cq_dma_base,
     565                 :            :                                        resp,
     566                 :            :                                        NOT_VF_REQ,
     567                 :            :                                        PF_ID_ZERO);
     568                 :            : }
     569                 :            : 
     570                 :            : int
     571                 :          0 : dlb2_pf_create_dir_port(struct dlb2_hw *hw,
     572                 :            :                         u32 id,
     573                 :            :                         struct dlb2_create_dir_port_args *args,
     574                 :            :                         uintptr_t cq_dma_base,
     575                 :            :                         struct dlb2_cmd_response *resp)
     576                 :            : {
     577                 :          0 :         return dlb2_hw_create_dir_port(hw, id, args,
     578                 :            :                                        cq_dma_base,
     579                 :            :                                        resp,
     580                 :            :                                        NOT_VF_REQ,
     581                 :            :                                        PF_ID_ZERO);
     582                 :            : }
     583                 :            : 
     584                 :            : int
     585                 :          0 : dlb2_pf_create_dir_queue(struct dlb2_hw *hw,
     586                 :            :                          u32 id,
     587                 :            :                          struct dlb2_create_dir_queue_args *args,
     588                 :            :                          struct dlb2_cmd_response *resp)
     589                 :            : {
     590                 :          0 :         return dlb2_hw_create_dir_queue(hw, id, args, resp, NOT_VF_REQ,
     591                 :            :                                         PF_ID_ZERO);
     592                 :            : }
     593                 :            : 
     594                 :            : int
     595                 :          0 : dlb2_pf_start_domain(struct dlb2_hw *hw,
     596                 :            :                      u32 id,
     597                 :            :                      struct dlb2_start_domain_args *args,
     598                 :            :                      struct dlb2_cmd_response *resp)
     599                 :            : {
     600                 :          0 :         return dlb2_hw_start_domain(hw, id, args, resp, NOT_VF_REQ,
     601                 :            :                                     PF_ID_ZERO);
     602                 :            : }

Generated by: LCOV version 1.14