LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_dpi.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 58 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 20 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <fcntl.h>
       6                 :            : #include <sys/stat.h>
       7                 :            : #include <sys/types.h>
       8                 :            : #include <unistd.h>
       9                 :            : 
      10                 :            : #include "roc_api.h"
      11                 :            : #include "roc_priv.h"
      12                 :            : 
      13                 :            : #define DPI_PF_MBOX_SYSFS_ENTRY "dpi_device_config"
      14                 :            : 
      15                 :            : static inline int
      16                 :          0 : send_msg_to_pf(struct plt_pci_addr *pci_addr, const char *value, int size)
      17                 :            : {
      18                 :          0 :         char buf[255] = {0};
      19                 :            :         int res, fd;
      20                 :            : 
      21                 :          0 :         res = snprintf(
      22                 :            :                 buf, sizeof(buf), "/sys/bus/pci/devices/" PCI_PRI_FMT "/%s",
      23         [ #  # ]:          0 :                 pci_addr->domain, pci_addr->bus, DPI_PF_DBDF_DEVICE & 0x7,
      24                 :            :                 DPI_PF_DBDF_FUNCTION & 0x7, DPI_PF_MBOX_SYSFS_ENTRY);
      25                 :            : 
      26         [ #  # ]:          0 :         if ((res < 0) || ((size_t)res > sizeof(buf)))
      27                 :            :                 return -ERANGE;
      28                 :            : 
      29                 :            :         fd = open(buf, O_WRONLY);
      30         [ #  # ]:          0 :         if (fd < 0)
      31                 :            :                 return -EACCES;
      32                 :            : 
      33                 :          0 :         res = write(fd, value, size);
      34                 :          0 :         close(fd);
      35         [ #  # ]:          0 :         if (res < 0)
      36                 :          0 :                 return -EACCES;
      37                 :            : 
      38                 :            :         return 0;
      39                 :            : }
      40                 :            : 
      41                 :            : int
      42                 :          0 : roc_dpi_enable(struct roc_dpi *dpi)
      43                 :            : {
      44                 :          0 :         plt_write64(0x1, dpi->rbase + DPI_VDMA_EN);
      45                 :          0 :         return 0;
      46                 :            : }
      47                 :            : 
      48                 :            : int
      49                 :          0 : roc_dpi_disable(struct roc_dpi *dpi)
      50                 :            : {
      51                 :          0 :         plt_write64(0x0, dpi->rbase + DPI_VDMA_EN);
      52                 :          0 :         return 0;
      53                 :            : }
      54                 :            : 
      55                 :            : int
      56                 :          0 : roc_dpi_configure(struct roc_dpi *roc_dpi, uint32_t chunk_sz, uint64_t aura, uint64_t chunk_base)
      57                 :            : {
      58                 :            :         struct plt_pci_device *pci_dev;
      59                 :            :         dpi_mbox_msg_t mbox_msg;
      60                 :            :         uint64_t reg;
      61                 :            :         int rc;
      62                 :            : 
      63         [ #  # ]:          0 :         if (!roc_dpi) {
      64                 :          0 :                 plt_err("roc_dpi is NULL");
      65                 :          0 :                 return -EINVAL;
      66                 :            :         }
      67                 :            : 
      68                 :          0 :         pci_dev = roc_dpi->pci_dev;
      69                 :            : 
      70                 :          0 :         roc_dpi_disable(roc_dpi);
      71                 :          0 :         reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR);
      72         [ #  # ]:          0 :         while (!(reg & BIT_ULL(63)))
      73                 :            :                 reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR);
      74                 :            : 
      75                 :            :         plt_write64(0x0, roc_dpi->rbase + DPI_VDMA_REQQ_CTL);
      76                 :            :         plt_write64(chunk_base, roc_dpi->rbase + DPI_VDMA_SADDR);
      77                 :          0 :         mbox_msg.u[0] = 0;
      78                 :          0 :         mbox_msg.u[1] = 0;
      79                 :            :         /* DPI PF driver expects vfid starts from index 0 */
      80                 :          0 :         mbox_msg.s.vfid = roc_dpi->vfid;
      81                 :          0 :         mbox_msg.s.cmd = DPI_QUEUE_OPEN;
      82                 :          0 :         mbox_msg.s.csize = chunk_sz;
      83                 :          0 :         mbox_msg.s.aura = aura;
      84                 :          0 :         mbox_msg.s.sso_pf_func = idev_sso_pffunc_get();
      85                 :          0 :         mbox_msg.s.npa_pf_func = idev_npa_pffunc_get();
      86                 :          0 :         mbox_msg.s.wqecsoff = idev_dma_cs_offset_get();
      87         [ #  # ]:          0 :         if (mbox_msg.s.wqecsoff)
      88                 :          0 :                 mbox_msg.s.wqecs = 1;
      89                 :            : 
      90                 :          0 :         rc = send_msg_to_pf(&pci_dev->addr, (const char *)&mbox_msg,
      91                 :            :                             sizeof(dpi_mbox_msg_t));
      92         [ #  # ]:          0 :         if (rc < 0)
      93                 :          0 :                 plt_err("Failed to send mbox message %d to DPI PF, err %d",
      94                 :            :                         mbox_msg.s.cmd, rc);
      95                 :            : 
      96                 :            :         return rc;
      97                 :            : }
      98                 :            : 
      99                 :            : int
     100                 :          0 : roc_dpi_dev_init(struct roc_dpi *roc_dpi, uint8_t offset)
     101                 :            : {
     102                 :          0 :         struct plt_pci_device *pci_dev = roc_dpi->pci_dev;
     103                 :            :         uint16_t vfid;
     104                 :            : 
     105                 :          0 :         roc_dpi->rbase = pci_dev->mem_resource[0].addr;
     106                 :          0 :         vfid = ((pci_dev->addr.devid & 0x1F) << 3) | (pci_dev->addr.function & 0x7);
     107                 :          0 :         vfid -= 1;
     108                 :          0 :         roc_dpi->vfid = vfid;
     109                 :          0 :         idev_dma_cs_offset_set(offset);
     110                 :            : 
     111                 :          0 :         return 0;
     112                 :            : }
     113                 :            : 
     114                 :            : int
     115                 :          0 : roc_dpi_dev_fini(struct roc_dpi *roc_dpi)
     116                 :            : {
     117                 :          0 :         struct plt_pci_device *pci_dev = roc_dpi->pci_dev;
     118                 :            :         dpi_mbox_msg_t mbox_msg;
     119                 :            :         uint64_t reg;
     120                 :            :         int rc;
     121                 :            : 
     122                 :            :         /* Wait for SADDR to become idle */
     123                 :          0 :         reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR);
     124         [ #  # ]:          0 :         while (!(reg & BIT_ULL(63)))
     125                 :            :                 reg = plt_read64(roc_dpi->rbase + DPI_VDMA_SADDR);
     126                 :            : 
     127                 :          0 :         mbox_msg.u[0] = 0;
     128                 :          0 :         mbox_msg.u[1] = 0;
     129                 :          0 :         mbox_msg.s.vfid = roc_dpi->vfid;
     130                 :          0 :         mbox_msg.s.cmd = DPI_QUEUE_CLOSE;
     131                 :            : 
     132                 :          0 :         rc = send_msg_to_pf(&pci_dev->addr, (const char *)&mbox_msg, sizeof(dpi_mbox_msg_t));
     133         [ #  # ]:          0 :         if (rc < 0)
     134                 :          0 :                 plt_err("Failed to send mbox message %d to DPI PF, err %d", mbox_msg.s.cmd, rc);
     135                 :            : 
     136                 :          0 :         return rc;
     137                 :            : }

Generated by: LCOV version 1.14