LCOV - code coverage report
Current view: top level - drivers/dma/cnxk - cnxk_dmadev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 655 0.2 %
Date: 2026-11-01 19:11:22 Functions: 1 32 3.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 359 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (C) 2021 Marvell International Ltd.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <errno.h>
       6                 :            : #include <stdlib.h>
       7                 :            : 
       8                 :            : #include <rte_event_dma_adapter.h>
       9                 :            : 
      10                 :            : #include <cnxk_dmadev.h>
      11                 :            : 
      12                 :            : static int cnxk_stats_reset(struct rte_dma_dev *dev, uint16_t vchan);
      13                 :            : static void cnxk_set_fp_ops(struct rte_dma_dev *dev, uint8_t enable_enq_deq);
      14                 :            : 
      15                 :            : static int
      16                 :          0 : parse_val_u16(const char *key, const char *value, void *extra_args)
      17                 :            : {
      18                 :            :         unsigned long val;
      19                 :            :         char *end;
      20                 :            : 
      21                 :            :         RTE_SET_USED(key);
      22                 :            : 
      23         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
      24                 :            :                 return -EINVAL;
      25                 :            : 
      26                 :          0 :         errno = 0;
      27                 :          0 :         val = strtoul(value, &end, 0);
      28   [ #  #  #  #  :          0 :         if (errno != 0 || end == value || *end != '\0' || val > UINT16_MAX)
             #  #  #  # ]
      29                 :            :                 return -EINVAL;
      30                 :            : 
      31                 :          0 :         *(uint16_t *)extra_args = (uint16_t)val;
      32                 :            : 
      33                 :          0 :         return 0;
      34                 :            : }
      35                 :            : 
      36                 :            : static int
      37                 :          0 : cn20k_dmadev_parse_devargs(struct rte_devargs *devargs, struct cnxk_dpi_vf_s *dpivf)
      38                 :            : {
      39                 :          0 :         uint16_t num_vchans = CN20K_DPI_DEF_VCHANS;
      40                 :          0 :         uint16_t num_lfs = num_vchans >> 1; /* Each LF has 2 rings */
      41                 :            :         struct rte_kvargs *kvlist = NULL;
      42                 :            : 
      43         [ #  # ]:          0 :         if (devargs == NULL) {
      44                 :          0 :                 dpivf->max_vchans = num_vchans;
      45                 :          0 :                 dpivf->max_lfs = num_lfs;
      46                 :          0 :                 return 0;
      47                 :            :         }
      48                 :            : 
      49                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, NULL);
      50         [ #  # ]:          0 :         if (kvlist == NULL)
      51                 :          0 :                 goto exit;
      52                 :            : 
      53         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist, CN20K_DPI_NUM_VCHANS, &parse_val_u16, &num_vchans) < 0)
      54                 :          0 :                 goto exit;
      55         [ #  # ]:          0 :         if (rte_kvargs_process(kvlist, CN20K_DPI_NUM_LFS, &parse_val_u16, &num_lfs) < 0)
      56                 :          0 :                 goto exit;
      57                 :            : 
      58   [ #  #  #  #  :          0 :         if (!num_vchans || !num_lfs || num_vchans > CN20K_DPI_MAX_VCHANS ||
             #  #  #  # ]
      59                 :            :             num_lfs > CN20K_DPI_MAX_LFS)
      60                 :          0 :                 goto exit;
      61                 :            : 
      62   [ #  #  #  # ]:          0 :         if (!rte_is_power_of_2(num_vchans) || !rte_is_power_of_2(num_lfs)) {
      63                 :          0 :                 plt_err("num_vchans or num_lfs is not a power of 2");
      64                 :          0 :                 goto exit;
      65                 :            :         }
      66                 :            : 
      67                 :          0 :         dpivf->max_vchans = num_vchans;
      68                 :          0 :         dpivf->max_lfs = num_lfs;
      69                 :            : 
      70                 :          0 :         rte_kvargs_free(kvlist);
      71                 :          0 :         return 0;
      72                 :          0 : exit:
      73                 :          0 :         rte_kvargs_free(kvlist);
      74                 :          0 :         return -EINVAL;
      75                 :            : }
      76                 :            : 
      77                 :            : static int
      78                 :          0 : cnxk_dmadev_info_get(const struct rte_dma_dev *dev, struct rte_dma_info *dev_info, uint32_t size)
      79                 :            : {
      80                 :          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
      81                 :            :         RTE_SET_USED(size);
      82                 :            : 
      83                 :          0 :         dev_info->max_vchans = CNXK_DPI_MAX_VCHANS_PER_QUEUE;
      84                 :          0 :         dev_info->nb_vchans = dpivf->num_vchans;
      85         [ #  # ]:          0 :         dev_info->dev_capa = RTE_DMA_CAPA_MEM_TO_MEM | RTE_DMA_CAPA_MEM_TO_DEV |
      86                 :            :                              RTE_DMA_CAPA_DEV_TO_MEM | RTE_DMA_CAPA_DEV_TO_DEV |
      87                 :            :                              RTE_DMA_CAPA_OPS_COPY | RTE_DMA_CAPA_OPS_COPY_SG |
      88                 :            :                              RTE_DMA_CAPA_M2D_AUTO_FREE | RTE_DMA_CAPA_OPS_ENQ_DEQ;
      89         [ #  # ]:          0 :         if (roc_feature_dpi_has_priority()) {
      90                 :          0 :                 dev_info->dev_capa |= RTE_DMA_CAPA_PRI_POLICY_SP;
      91                 :          0 :                 dev_info->nb_priorities = CN10K_DPI_MAX_PRI;
      92                 :            :         }
      93                 :            : 
      94         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
      95                 :          0 :                 const uint16_t vpr = dpivf->vchans_per_ring ? dpivf->vchans_per_ring : 1;
      96                 :            : 
      97                 :          0 :                 dev_info->max_desc = CN20K_DPI_MAX_DESC / vpr;
      98                 :          0 :                 dev_info->min_desc = CN20K_DPI_MIN_DESC;
      99                 :          0 :                 dev_info->max_sges = CN20K_DPI_MAX_POINTER;
     100                 :          0 :                 dev_info->max_vchans = dpivf->max_vchans;
     101                 :          0 :                 dev_info->dev_capa |= (RTE_DMA_CAPA_OPS_FILL | RTE_DMA_CAPA_INTER_PROCESS_DOMAIN);
     102                 :            :         } else {
     103                 :          0 :                 dev_info->max_desc = CNXK_DPI_MAX_DESC;
     104                 :          0 :                 dev_info->min_desc = CNXK_DPI_MIN_DESC;
     105                 :          0 :                 dev_info->max_sges = CNXK_DPI_MAX_POINTER;
     106                 :            :                 dev_info->max_vchans = CNXK_DPI_MAX_VCHANS_PER_QUEUE;
     107                 :            :         }
     108                 :            : 
     109                 :          0 :         return 0;
     110                 :            : }
     111                 :            : 
     112                 :            : static int
     113                 :          0 : cnxk_dmadev_vchan_free(struct cnxk_dpi_vf_s *dpivf, uint16_t vchan)
     114                 :            : {
     115                 :            :         struct cnxk_dpi_conf *dpi_conf;
     116                 :            :         uint16_t num_vchans;
     117                 :            :         int i;
     118                 :            : 
     119         [ #  # ]:          0 :         if (vchan == RTE_DMA_ALL_VCHAN) {
     120                 :          0 :                 num_vchans = dpivf->num_vchans;
     121                 :            :                 i = 0;
     122                 :            :         } else {
     123         [ #  # ]:          0 :                 if (vchan >= CNXK_DPI_MAX_VCHANS_PER_QUEUE)
     124                 :            :                         return -EINVAL;
     125                 :            : 
     126                 :          0 :                 num_vchans = vchan + 1;
     127                 :          0 :                 i = vchan;
     128                 :            :         }
     129                 :            : 
     130         [ #  # ]:          0 :         for (; i < num_vchans; i++) {
     131                 :          0 :                 dpi_conf = &dpivf->conf[i];
     132         [ #  # ]:          0 :                 if (dpi_conf->c_desc.compl_ptr) {
     133                 :          0 :                         rte_free(dpi_conf->c_desc.compl_ptr);
     134                 :          0 :                         dpi_conf->c_desc.compl_ptr = NULL;
     135                 :            :                 }
     136                 :            :         }
     137                 :            : 
     138                 :            :         return 0;
     139                 :            : }
     140                 :            : 
     141                 :            : static int
     142                 :          0 : cnxk_dmadev_chunk_pool_create(struct rte_dma_dev *dev, uint32_t nb_chunks, uint32_t chunk_sz)
     143                 :            : {
     144                 :            :         char pool_name[RTE_MEMPOOL_NAMESIZE];
     145                 :            :         struct cnxk_dpi_vf_s *dpivf = NULL;
     146                 :            :         int rc;
     147                 :            : 
     148                 :          0 :         dpivf = dev->fp_obj->dev_private;
     149                 :            :         /* Create chunk pool. */
     150                 :          0 :         snprintf(pool_name, sizeof(pool_name), "cnxk_dma_chunk_pool%d", dev->data->dev_id);
     151                 :            : 
     152                 :          0 :         nb_chunks += (CNXK_DPI_POOL_MAX_CACHE_SZ * rte_lcore_count());
     153                 :          0 :         dpivf->chunk_pool = rte_mempool_create_empty(
     154                 :          0 :                 pool_name, nb_chunks, chunk_sz, CNXK_DPI_POOL_MAX_CACHE_SZ, 0, rte_socket_id(), 0);
     155                 :            : 
     156         [ #  # ]:          0 :         if (dpivf->chunk_pool == NULL) {
     157                 :          0 :                 plt_err("Unable to create chunkpool.");
     158                 :          0 :                 return -ENOMEM;
     159                 :            :         }
     160                 :            : 
     161                 :          0 :         rc = rte_mempool_set_ops_byname(dpivf->chunk_pool, rte_mbuf_platform_mempool_ops(), NULL);
     162         [ #  # ]:          0 :         if (rc < 0) {
     163                 :          0 :                 plt_err("Unable to set chunkpool ops");
     164                 :          0 :                 goto free;
     165                 :            :         }
     166                 :            : 
     167                 :          0 :         rc = rte_mempool_populate_default(dpivf->chunk_pool);
     168         [ #  # ]:          0 :         if (rc < 0) {
     169                 :          0 :                 plt_err("Unable to set populate chunkpool.");
     170                 :          0 :                 goto free;
     171                 :            :         }
     172                 :          0 :         dpivf->aura = roc_npa_aura_handle_to_aura(dpivf->chunk_pool->pool_id);
     173                 :            : 
     174                 :          0 :         return 0;
     175                 :            : 
     176                 :          0 : free:
     177                 :          0 :         rte_mempool_free(dpivf->chunk_pool);
     178                 :          0 :         return rc;
     179                 :            : }
     180                 :            : 
     181                 :            : static int
     182                 :          0 : cnxk_dmadev_vchan_rsrc_free(struct cnxk_dpi_vf_s *dpivf)
     183                 :            : {
     184                 :          0 :         struct roc_dpi *rdpi = &dpivf->rdpi;
     185                 :            :         int rc;
     186                 :            : 
     187         [ #  # ]:          0 :         if (dpivf->ring_conf) {
     188                 :          0 :                 rte_free(dpivf->ring_conf);
     189                 :          0 :                 dpivf->ring_conf = NULL;
     190                 :            :         }
     191                 :            : 
     192         [ #  # ]:          0 :         if (rdpi->lfs == NULL)
     193                 :            :                 return 0;
     194                 :            : 
     195                 :          0 :         rc = roc_dpi_lf_chan_tbl_free(&(rdpi->lfs[0]));
     196         [ #  # ]:          0 :         if (rc < 0)
     197                 :          0 :                 plt_err("Failed to free dpi lf channel table");
     198                 :            : 
     199                 :          0 :         rc = roc_dpi_rsrc_fini(rdpi);
     200         [ #  # ]:          0 :         if (rc < 0)
     201                 :          0 :                 plt_err("Failed to free dpi lfs");
     202                 :            : 
     203                 :          0 :         dpivf->is_ring_conf_done = false;
     204                 :          0 :         return rc;
     205                 :            : }
     206                 :            : 
     207                 :            : static int
     208                 :          0 : cnxk_dmadev_configure(struct rte_dma_dev *dev, const struct rte_dma_conf *conf, uint32_t conf_sz)
     209                 :            : {
     210                 :            :         struct cnxk_dpi_vf_s *dpivf = NULL;
     211                 :            :         struct roc_dpi_lf *lf;
     212                 :            :         uint16_t num_rings;
     213                 :            :         int rc = 0;
     214                 :            : 
     215                 :            :         RTE_SET_USED(conf_sz);
     216                 :          0 :         dpivf = dev->fp_obj->dev_private;
     217                 :            : 
     218                 :            :         /* After config function, vchan setup function has to be called.
     219                 :            :          * Free up vchan memory if any, before configuring num_vchans.
     220                 :            :          */
     221                 :          0 :         cnxk_dmadev_vchan_free(dpivf, RTE_DMA_ALL_VCHAN);
     222                 :            : 
     223         [ #  # ]:          0 :         dpivf->num_vchans = conf->nb_vchans;
     224         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
     225         [ #  # ]:          0 :                 if (!rte_is_power_of_2(dpivf->num_vchans))
     226                 :          0 :                         dpivf->num_vchans = rte_align32pow2(dpivf->num_vchans);
     227                 :            : 
     228         [ #  # ]:          0 :                 if (dpivf->num_vchans > dpivf->max_vchans) {
     229                 :          0 :                         plt_info("Limiting vchans from %u to max_vchans %u",
     230                 :            :                                  dpivf->num_vchans, dpivf->max_vchans);
     231                 :          0 :                         dpivf->num_vchans = dpivf->max_vchans;
     232                 :            :                 }
     233                 :            :         }
     234         [ #  # ]:          0 :         if (roc_feature_dpi_has_priority())
     235                 :          0 :                 dpivf->rdpi.priority = conf->priority;
     236                 :            : 
     237                 :          0 :         cnxk_set_fp_ops(dev, conf->flags & RTE_DMA_CFG_FLAG_ENQ_DEQ);
     238                 :            : 
     239         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
     240                 :          0 :                 rc = cnxk_dmadev_vchan_rsrc_free(dpivf);
     241         [ #  # ]:          0 :                 if (rc < 0)
     242                 :          0 :                         goto error;
     243                 :            : 
     244                 :          0 :                 dpivf->rdpi.nr_lfs = dpivf->max_lfs;
     245                 :          0 :                 num_rings = dpivf->rdpi.nr_lfs << 1;
     246                 :            : 
     247         [ #  # ]:          0 :                 if (dpivf->num_vchans > num_rings) {
     248                 :          0 :                         dpivf->vchans_per_ring = dpivf->num_vchans / num_rings;
     249                 :            :                 } else {
     250                 :            :                         /* Each vchan has got it's own hardware ring */
     251                 :          0 :                         dpivf->vchans_per_ring = 1;
     252                 :          0 :                         dpivf->rdpi.nr_lfs = dpivf->num_vchans >> 1;
     253         [ #  # ]:          0 :                         if (!dpivf->rdpi.nr_lfs)
     254                 :          0 :                                 dpivf->rdpi.nr_lfs = 1;
     255                 :            :                 }
     256                 :            : 
     257         [ #  # ]:          0 :                 if ((CN20K_DPI_MAX_DESC / dpivf->vchans_per_ring) < CN20K_DPI_MIN_DESC) {
     258                 :            :                         rc = -EINVAL;
     259                 :          0 :                         plt_err("Very few LFs are requested than required");
     260                 :          0 :                         goto error;
     261                 :            :                 }
     262                 :            : 
     263                 :          0 :                 num_rings = dpivf->rdpi.nr_lfs << 1;
     264                 :          0 :                 dpivf->ring_conf = rte_zmalloc("dpi_ring_conf", sizeof(struct cn20k_ring_conf) *
     265                 :            :                                                num_rings, 0);
     266         [ #  # ]:          0 :                 if (dpivf->ring_conf == NULL) {
     267                 :          0 :                         plt_err("Failed to allocate memory for ring conf");
     268                 :            :                         rc = -ENOMEM;
     269                 :          0 :                         goto error;
     270                 :            :                 }
     271                 :            : 
     272                 :          0 :                 rc = roc_dpi_rsrc_init(&dpivf->rdpi);
     273         [ #  # ]:          0 :                 if (rc < 0) {
     274                 :          0 :                         plt_err("rsrc alloc failed");
     275                 :          0 :                         goto error;
     276                 :            :                 }
     277                 :            : 
     278                 :          0 :                 lf = &(dpivf->rdpi.lfs[0]);
     279                 :          0 :                 rc = roc_dpi_lf_chan_tbl_alloc(lf, dpivf->num_vchans);
     280         [ #  # ]:          0 :                 if (rc < 0) {
     281                 :          0 :                         plt_err("Failed to allocate chan tbl");
     282                 :          0 :                         goto error;
     283                 :            :                 }
     284                 :            : 
     285                 :          0 :                 dpivf->chan_tbl = lf->chan_tbl;
     286                 :          0 :                 dpivf->is_ring_conf_done = false;
     287                 :            :         }
     288                 :            : 
     289         [ #  # ]:          0 : error:
     290   [ #  #  #  # ]:          0 :         if (roc_model_is_cn20k() && rc < 0)
     291                 :          0 :                 cnxk_dmadev_vchan_rsrc_free(dpivf);
     292                 :            : 
     293                 :          0 :         return rc;
     294                 :            : }
     295                 :            : 
     296                 :            : static int
     297                 :            : dmadev_src_buf_aura_get(struct rte_mempool *sb_mp, const char *mp_ops_name)
     298                 :            : {
     299                 :            :         struct rte_mempool_ops *ops;
     300                 :            : 
     301                 :          0 :         if (sb_mp == NULL)
     302                 :            :                 return 0;
     303                 :            : 
     304                 :          0 :         ops = rte_mempool_get_ops(sb_mp->ops_index);
     305   [ #  #  #  #  :          0 :         if (strcmp(ops->name, mp_ops_name) != 0)
                   #  # ]
     306                 :            :                 return -EINVAL;
     307                 :            : 
     308                 :          0 :         return roc_npa_aura_handle_to_aura(sb_mp->pool_id);
     309                 :            : }
     310                 :            : 
     311                 :            : static int
     312                 :          0 : cn9k_dmadev_setup_hdr(union cnxk_dpi_instr_cmd *header, const struct rte_dma_vchan_conf *conf)
     313                 :            : {
     314                 :            :         int aura;
     315                 :            : 
     316                 :          0 :         header->cn9k.pt = DPI_HDR_PT_ZBW_CA;
     317                 :            : 
     318   [ #  #  #  #  :          0 :         switch (conf->direction) {
                      # ]
     319                 :          0 :         case RTE_DMA_DIR_DEV_TO_MEM:
     320                 :          0 :                 header->cn9k.xtype = DPI_XTYPE_INBOUND;
     321                 :          0 :                 header->cn9k.lport = conf->src_port.pcie.coreid;
     322                 :          0 :                 header->cn9k.fport = 0;
     323                 :          0 :                 header->cn9k.pvfe = conf->src_port.pcie.vfen;
     324         [ #  # ]:          0 :                 if (header->cn9k.pvfe) {
     325                 :          0 :                         header->cn9k.func = conf->src_port.pcie.pfid << 12;
     326                 :          0 :                         header->cn9k.func |= conf->src_port.pcie.vfid;
     327                 :            :                 }
     328                 :            :                 break;
     329                 :          0 :         case RTE_DMA_DIR_MEM_TO_DEV:
     330                 :          0 :                 header->cn9k.xtype = DPI_XTYPE_OUTBOUND;
     331                 :          0 :                 header->cn9k.lport = 0;
     332                 :          0 :                 header->cn9k.fport = conf->dst_port.pcie.coreid;
     333                 :          0 :                 header->cn9k.pvfe = conf->dst_port.pcie.vfen;
     334         [ #  # ]:          0 :                 if (header->cn9k.pvfe) {
     335                 :          0 :                         header->cn9k.func = conf->dst_port.pcie.pfid << 12;
     336                 :          0 :                         header->cn9k.func |= conf->dst_port.pcie.vfid;
     337                 :            :                 }
     338         [ #  # ]:          0 :                 aura = dmadev_src_buf_aura_get(conf->auto_free.m2d.pool, "cn9k_mempool_ops");
     339                 :            :                 if (aura < 0)
     340                 :          0 :                         return aura;
     341                 :          0 :                 header->cn9k.aura = aura;
     342                 :          0 :                 header->cn9k.ii = 1;
     343                 :          0 :                 break;
     344                 :          0 :         case RTE_DMA_DIR_MEM_TO_MEM:
     345                 :          0 :                 header->cn9k.xtype = DPI_XTYPE_INTERNAL_ONLY;
     346                 :          0 :                 header->cn9k.lport = 0;
     347                 :          0 :                 header->cn9k.fport = 0;
     348                 :          0 :                 header->cn9k.pvfe = 0;
     349                 :          0 :                 break;
     350                 :          0 :         case RTE_DMA_DIR_DEV_TO_DEV:
     351                 :          0 :                 header->cn9k.xtype = DPI_XTYPE_EXTERNAL_ONLY;
     352                 :          0 :                 header->cn9k.lport = conf->src_port.pcie.coreid;
     353                 :          0 :                 header->cn9k.fport = conf->dst_port.pcie.coreid;
     354                 :          0 :                 header->cn9k.pvfe = 0;
     355                 :            :         };
     356                 :            : 
     357                 :            :         return 0;
     358                 :            : }
     359                 :            : 
     360                 :            : static int
     361                 :          0 : cn10k_dmadev_setup_hdr(union cnxk_dpi_instr_cmd *header, const struct rte_dma_vchan_conf *conf)
     362                 :            : {
     363                 :            :         int aura;
     364                 :            : 
     365                 :          0 :         header->cn10k.pt = DPI_HDR_PT_ZBW_CA;
     366                 :            : 
     367   [ #  #  #  #  :          0 :         switch (conf->direction) {
                      # ]
     368                 :          0 :         case RTE_DMA_DIR_DEV_TO_MEM:
     369                 :          0 :                 header->cn10k.xtype = DPI_XTYPE_INBOUND;
     370                 :          0 :                 header->cn10k.lport = conf->src_port.pcie.coreid;
     371                 :          0 :                 header->cn10k.fport = 0;
     372                 :          0 :                 header->cn10k.pvfe = conf->src_port.pcie.vfen;
     373         [ #  # ]:          0 :                 if (header->cn10k.pvfe) {
     374                 :          0 :                         header->cn10k.func = conf->src_port.pcie.pfid << 12;
     375                 :          0 :                         header->cn10k.func |= conf->src_port.pcie.vfid;
     376                 :            :                 }
     377                 :            :                 break;
     378                 :          0 :         case RTE_DMA_DIR_MEM_TO_DEV:
     379                 :          0 :                 header->cn10k.xtype = DPI_XTYPE_OUTBOUND;
     380                 :          0 :                 header->cn10k.lport = 0;
     381                 :          0 :                 header->cn10k.fport = conf->dst_port.pcie.coreid;
     382                 :          0 :                 header->cn10k.pvfe = conf->dst_port.pcie.vfen;
     383         [ #  # ]:          0 :                 if (header->cn10k.pvfe) {
     384                 :          0 :                         header->cn10k.func = conf->dst_port.pcie.pfid << 12;
     385                 :          0 :                         header->cn10k.func |= conf->dst_port.pcie.vfid;
     386                 :            :                 }
     387         [ #  # ]:          0 :                 aura = dmadev_src_buf_aura_get(conf->auto_free.m2d.pool, "cn10k_mempool_ops");
     388                 :            :                 if (aura < 0)
     389                 :          0 :                         return aura;
     390                 :          0 :                 header->cn10k.aura = aura;
     391                 :          0 :                 break;
     392                 :          0 :         case RTE_DMA_DIR_MEM_TO_MEM:
     393                 :          0 :                 header->cn10k.xtype = DPI_XTYPE_INTERNAL_ONLY;
     394                 :          0 :                 header->cn10k.lport = 0;
     395                 :          0 :                 header->cn10k.fport = 0;
     396                 :          0 :                 header->cn10k.pvfe = 0;
     397                 :          0 :                 break;
     398                 :          0 :         case RTE_DMA_DIR_DEV_TO_DEV:
     399                 :          0 :                 header->cn10k.xtype = DPI_XTYPE_EXTERNAL_ONLY;
     400                 :          0 :                 header->cn10k.lport = conf->src_port.pcie.coreid;
     401                 :          0 :                 header->cn10k.fport = conf->dst_port.pcie.coreid;
     402                 :          0 :                 header->cn10k.pvfe = 0;
     403                 :            :         };
     404                 :            : 
     405                 :            :         return 0;
     406                 :            : }
     407                 :            : 
     408                 :            : static int
     409                 :          0 : cn20k_dmadev_setup(struct cnxk_dpi_vf_s *dpivf, uint16_t vchan,
     410                 :            :                     const struct rte_dma_vchan_conf *conf)
     411                 :            : {
     412                 :          0 :         struct cnxk_dpi_conf *dpi_conf = &dpivf->conf[vchan];
     413                 :          0 :         struct cn20k_ring_conf *rconf = dpivf->ring_conf;
     414                 :            :         uint16_t ridx, max_desc, num_rings;
     415                 :            :         union cnxk_dpi_instr_cmd *header;
     416                 :            :         int rc = 0;
     417                 :            :         int aura;
     418                 :            : 
     419                 :            :         header = (union cnxk_dpi_instr_cmd *)&dpi_conf->cmd.u;
     420                 :          0 :         header->cn20k.ct = DPI_HDR_PT_ZBW_CA;
     421                 :          0 :         header->cn20k.xt = 0;
     422                 :            : 
     423   [ #  #  #  #  :          0 :         switch (conf->direction) {
                      # ]
     424                 :          0 :         case RTE_DMA_DIR_DEV_TO_MEM:
     425                 :          0 :                 dpi_conf->cfg.xtype = DPI_XTYPE_INBOUND;
     426                 :          0 :                 dpi_conf->cfg.rport = conf->src_port.pcie.coreid;
     427                 :          0 :                 dpi_conf->cfg.wport = 0;
     428                 :          0 :                 dpi_conf->chan_cfg.pf_func = conf->src_port.pcie.pfid;
     429                 :          0 :                 dpi_conf->chan_cfg.vf_func = conf->src_port.pcie.vfid;
     430                 :          0 :                 dpi_conf->chan_cfg.valid = 1;
     431                 :          0 :                 break;
     432                 :          0 :         case RTE_DMA_DIR_MEM_TO_DEV:
     433                 :          0 :                 dpi_conf->cfg.xtype = DPI_XTYPE_OUTBOUND;
     434                 :          0 :                 dpi_conf->cfg.rport = 0;
     435                 :          0 :                 dpi_conf->cfg.wport = conf->dst_port.pcie.coreid;
     436                 :          0 :                 dpi_conf->chan_cfg.pf_func = conf->dst_port.pcie.pfid;
     437                 :          0 :                 dpi_conf->chan_cfg.vf_func = conf->dst_port.pcie.vfid;
     438                 :          0 :                 dpi_conf->chan_cfg.valid = 1;
     439         [ #  # ]:          0 :                 aura = dmadev_src_buf_aura_get(conf->auto_free.m2d.pool, "cn20k_mempool_ops");
     440                 :            :                 if (aura < 0)
     441                 :          0 :                         return aura;
     442                 :          0 :                 header->cn20k.aura = aura;
     443                 :          0 :                 break;
     444                 :          0 :         case RTE_DMA_DIR_MEM_TO_MEM:
     445                 :          0 :                 dpi_conf->cfg.xtype = DPI_XTYPE_INTERNAL_ONLY;
     446         [ #  # ]:          0 :                 if (conf->domain.type == RTE_DMA_INTER_PROCESS_DOMAIN) {
     447                 :          0 :                         dpi_conf->chan_cfg.type = RTE_DMA_INTER_PROCESS_DOMAIN;
     448                 :          0 :                         dpi_conf->chan_cfg.src_key = conf->domain.src_handler;
     449                 :          0 :                         dpi_conf->chan_cfg.dst_key = conf->domain.dst_handler;
     450                 :          0 :                         header->cn20k.chan = CNXK_DPI_SRC_DST_KEY(dpi_conf->chan_cfg.src_key,
     451                 :            :                                                                   dpi_conf->chan_cfg.dst_key);
     452                 :            :                 }
     453                 :          0 :                 dpi_conf->cfg.rport = 0;
     454                 :          0 :                 dpi_conf->cfg.wport = 0;
     455                 :          0 :                 break;
     456                 :          0 :         case RTE_DMA_DIR_DEV_TO_DEV:
     457                 :          0 :                 dpi_conf->cfg.xtype = DPI_XTYPE_EXTERNAL_ONLY;
     458                 :          0 :                 dpi_conf->cfg.rport = conf->src_port.pcie.coreid;
     459                 :          0 :                 dpi_conf->cfg.wport = conf->dst_port.pcie.coreid;
     460                 :            :         };
     461                 :            : 
     462                 :          0 :         max_desc = conf->nb_desc;
     463         [ #  # ]:          0 :         if (!rte_is_power_of_2(max_desc))
     464                 :          0 :                 max_desc = rte_align32pow2(max_desc);
     465                 :            : 
     466                 :          0 :         num_rings = dpivf->rdpi.nr_lfs << 1;
     467                 :            : 
     468         [ #  # ]:          0 :         for (ridx = 0; ridx < num_rings; ridx++) {
     469         [ #  # ]:          0 :                 if (!rconf[ridx].used) {
     470         [ #  # ]:          0 :                         if (!rconf[ridx].num_vchans) {
     471                 :          0 :                                 rconf[ridx].direction = conf->direction;
     472                 :          0 :                                 rconf[ridx].num_desc = max_desc;
     473         [ #  # ]:          0 :                         } else if ((rconf[ridx].direction == conf->direction) &&
     474         [ #  # ]:          0 :                                    (rconf[ridx].num_vchans < dpivf->vchans_per_ring)) {
     475                 :          0 :                                 rconf[ridx].num_desc += max_desc;
     476                 :            :                         } else {
     477                 :          0 :                                 continue;
     478                 :            :                         }
     479                 :            : 
     480                 :          0 :                         rconf[ridx].num_vchans++;
     481                 :          0 :                         dpi_conf->ridx = ridx;
     482                 :            : 
     483         [ #  # ]:          0 :                         if (rconf[ridx].num_vchans == dpivf->vchans_per_ring)
     484                 :          0 :                                 rconf[ridx].used = true;
     485                 :            : 
     486                 :            :                         break;
     487                 :            :                 }
     488                 :            :         }
     489                 :            : 
     490         [ #  # ]:          0 :         if (ridx == num_rings)
     491                 :            :                 rc = -ENODEV;
     492                 :            : 
     493                 :            :         return rc;
     494                 :            : }
     495                 :            : 
     496                 :            : static int
     497                 :          0 : cnxk_dmadev_vchan_setup(struct rte_dma_dev *dev, uint16_t vchan,
     498                 :            :                         const struct rte_dma_vchan_conf *conf, uint32_t conf_sz)
     499                 :            : {
     500                 :          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
     501                 :          0 :         struct cnxk_dpi_conf *dpi_conf = &dpivf->conf[vchan];
     502                 :            :         union cnxk_dpi_instr_cmd *header;
     503                 :            :         uint16_t max_desc;
     504                 :            :         uint32_t size;
     505                 :            :         int i, ret;
     506                 :            : 
     507                 :            :         RTE_SET_USED(conf_sz);
     508                 :            : 
     509   [ #  #  #  # ]:          0 :         if (conf->auto_free.m2d.pool != NULL && conf->direction != RTE_DMA_DIR_MEM_TO_DEV)
     510                 :            :                 return -EINVAL;
     511                 :            : 
     512         [ #  # ]:          0 :         header = (union cnxk_dpi_instr_cmd *)&dpi_conf->cmd.u;
     513                 :            : 
     514         [ #  # ]:          0 :         if (roc_model_is_cn20k())
     515                 :          0 :                 ret = cn20k_dmadev_setup(dpivf, vchan, conf);
     516         [ #  # ]:          0 :         else if (roc_model_is_cn10k())
     517                 :          0 :                 ret = cn10k_dmadev_setup_hdr(header, conf);
     518                 :            :         else
     519                 :          0 :                 ret = cn9k_dmadev_setup_hdr(header, conf);
     520                 :            : 
     521         [ #  # ]:          0 :         if (ret)
     522                 :            :                 return ret;
     523                 :            : 
     524                 :            :         /* Free up descriptor memory before allocating. */
     525                 :          0 :         cnxk_dmadev_vchan_free(dpivf, vchan);
     526                 :            : 
     527                 :          0 :         max_desc = conf->nb_desc;
     528         [ #  # ]:          0 :         if (!rte_is_power_of_2(max_desc))
     529                 :          0 :                 max_desc = rte_align32pow2(max_desc);
     530                 :            : 
     531         [ #  # ]:          0 :         if (!roc_model_is_cn20k() && (max_desc > CNXK_DPI_MAX_DESC))
     532                 :            :                 max_desc = CNXK_DPI_MAX_DESC;
     533                 :            : 
     534                 :          0 :         size = (max_desc * sizeof(uint8_t) * CNXK_DPI_COMPL_OFFSET);
     535                 :          0 :         dpi_conf->c_desc.compl_ptr = rte_zmalloc(NULL, size, 0);
     536                 :            : 
     537         [ #  # ]:          0 :         if (dpi_conf->c_desc.compl_ptr == NULL) {
     538                 :          0 :                 plt_err("Failed to allocate for comp_data");
     539                 :          0 :                 return -ENOMEM;
     540                 :            :         }
     541                 :            : 
     542                 :          0 :         size = (max_desc * sizeof(struct rte_dma_op *));
     543                 :          0 :         dpi_conf->c_desc.ops = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE);
     544         [ #  # ]:          0 :         if (dpi_conf->c_desc.ops == NULL) {
     545                 :          0 :                 plt_err("Failed to allocate for ops array");
     546                 :          0 :                 rte_free(dpi_conf->c_desc.compl_ptr);
     547                 :          0 :                 return -ENOMEM;
     548                 :            :         }
     549                 :            : 
     550         [ #  # ]:          0 :         for (i = 0; i < max_desc; i++)
     551                 :          0 :                 dpi_conf->c_desc.compl_ptr[i * CNXK_DPI_COMPL_OFFSET] = CNXK_DPI_REQ_CDATA;
     552                 :            : 
     553                 :          0 :         dpi_conf->c_desc.max_cnt = (max_desc - 1);
     554                 :          0 :         dpi_conf->cfg_done = true;
     555                 :            : 
     556                 :          0 :         return 0;
     557                 :            : }
     558                 :            : 
     559                 :            : static int
     560                 :          0 : cn20k_dmadev_queue_setup(struct cnxk_dpi_vf_s *dpivf)
     561                 :            : {
     562                 :          0 :         struct cn20k_ring_conf *rconf = dpivf->ring_conf;
     563                 :            :         struct roc_dpi *rdpi = &dpivf->rdpi;
     564                 :            :         struct cnxk_dpi_conf *dpi_conf;
     565                 :            :         struct roc_dpi_lf_que *que;
     566                 :            :         struct roc_dpi_lf_ring_cfg cfg;
     567                 :            :         struct roc_dpi_lf *lf;
     568                 :            :         uint16_t idx, qidx, ridx, vchan;
     569                 :            :         int rc = 0;
     570                 :            : 
     571         [ #  # ]:          0 :         for (idx = 0; idx < rdpi->nr_lfs; idx++) {
     572                 :          0 :                 lf = &rdpi->lfs[idx];
     573                 :          0 :                 lf->chan_tbl = dpivf->chan_tbl;
     574                 :            : 
     575         [ #  # ]:          0 :                 for (qidx = 0; qidx < 2; qidx++) {
     576                 :          0 :                         ridx = (idx << 1) + qidx;
     577                 :            : 
     578         [ #  # ]:          0 :                         if (!rconf[ridx].used)
     579                 :          0 :                                 continue;
     580                 :            : 
     581                 :          0 :                         que = &lf->queue[qidx];
     582                 :            : 
     583                 :          0 :                         que->qsize = rconf[ridx].num_desc;
     584                 :          0 :                         que->cmd_len = DPI_CMD_SIZE_128B;
     585                 :          0 :                         que->first_skip = 0;
     586                 :          0 :                         que->later_skip = 0;
     587                 :            :                         memset(&cfg, 0, sizeof(cfg));
     588                 :          0 :                         cfg.ring_idx = qidx;
     589                 :          0 :                         cfg.isize = que->cmd_len / DPI_CMD_SIZE_128B;
     590                 :          0 :                         cfg.xtype = DPI_XTYPE_INTERNAL_ONLY;
     591                 :            :                         cfg.rport = 0; /* Default is PEM:0 */
     592                 :            :                         cfg.wport = 0; /* Default is PEM:0 */
     593                 :            :                         cfg.pri = 0;   /* 0 - High Priority */
     594         [ #  # ]:          0 :                         for (vchan = 0; vchan < dpivf->num_vchans; vchan++) {
     595                 :          0 :                                 dpi_conf = &dpivf->conf[vchan];
     596                 :            : 
     597         [ #  # ]:          0 :                                 if (dpi_conf->ridx == ridx)
     598                 :          0 :                                         cfg.xtype = dpi_conf->cfg.xtype;
     599                 :            :                         }
     600                 :            : 
     601                 :          0 :                         rc = roc_dpi_lf_ring_init(que, &cfg);
     602         [ #  # ]:          0 :                         if (rc)
     603                 :          0 :                                 return rc;
     604                 :            : 
     605         [ #  # ]:          0 :                         for (vchan = 0; vchan < dpivf->num_vchans; vchan++) {
     606                 :          0 :                                 dpi_conf = &dpivf->conf[vchan];
     607                 :            : 
     608         [ #  # ]:          0 :                                 if (dpi_conf->ridx == ridx) {
     609                 :          0 :                                         dpi_conf->que = que;
     610                 :          0 :                                         dpi_conf->dbell = lf->rbase + DPI_LF_RINGX_WIDX(qidx);
     611                 :            :                                 }
     612                 :            :                         }
     613                 :            :                 }
     614                 :            : 
     615                 :          0 :                 rc = roc_dpi_lf_chan_tbl_select(lf);
     616         [ #  # ]:          0 :                 if (rc)
     617                 :          0 :                         return rc;
     618                 :            : 
     619                 :            :                 /* FIX ME */
     620                 :          0 :                 rc = roc_dpi_lf_pffunc_cfg(lf);
     621         [ #  # ]:          0 :                 if (rc)
     622                 :          0 :                         return rc;
     623                 :            :         }
     624                 :            : 
     625                 :            :         return rc;
     626                 :            : }
     627                 :            : 
     628                 :            : static int
     629                 :          0 : cn20k_dmadev_chan_tbl_setup(struct cnxk_dpi_vf_s *dpivf)
     630                 :            : {
     631                 :            :         uint16_t vchan, idx = 0, offset = 0;
     632                 :            :         struct cnxk_dpi_conf *dpi_conf;
     633                 :          0 :         uint64_t config[64] = {0};
     634                 :            :         struct roc_dpi_lf *lf;
     635                 :            :         int rc = 0;
     636                 :            : 
     637                 :          0 :         lf = &(dpivf->rdpi.lfs[0]);
     638                 :            : 
     639         [ #  # ]:          0 :         for (vchan = 0; vchan < dpivf->num_vchans; vchan++) {
     640                 :          0 :                 dpi_conf = &dpivf->conf[vchan];
     641   [ #  #  #  # ]:          0 :                 if (!dpi_conf->cfg_done || (dpi_conf->cfg.xtype == DPI_XTYPE_INTERNAL_ONLY))
     642                 :          0 :                         continue;
     643                 :            : 
     644                 :          0 :                 dpi_conf->cmd.cn20k.chan = offset + idx;
     645                 :          0 :                 config[idx++] = dpi_conf->chan_cfg.u;
     646                 :            : 
     647         [ #  # ]:          0 :                 if (idx == 64) {
     648                 :          0 :                         rc = roc_dpi_lf_chan_tbl_update(lf, config, offset, idx);
     649         [ #  # ]:          0 :                         if (rc < 0) {
     650                 :          0 :                                 plt_err("Failed to update chan tbl = %d", rc);
     651                 :          0 :                                 return rc;
     652                 :            :                         }
     653                 :          0 :                         offset += idx;
     654                 :            :                         idx = 0;
     655                 :            :                 }
     656                 :            :         }
     657                 :            : 
     658         [ #  # ]:          0 :         if (idx) {
     659                 :          0 :                 rc = roc_dpi_lf_chan_tbl_update(lf, config, offset, idx);
     660         [ #  # ]:          0 :                 if (rc < 0) {
     661                 :          0 :                         plt_err("Failed to update chan tbl = %d", rc);
     662                 :          0 :                         return rc;
     663                 :            :                 }
     664                 :            :         }
     665                 :            : 
     666                 :            :         return rc;
     667                 :            : }
     668                 :            : 
     669                 :            : static int
     670                 :          0 : cnxk_dmadev_start(struct rte_dma_dev *dev)
     671                 :            : {
     672                 :          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
     673                 :            :         struct cnxk_dpi_conf *dpi_conf;
     674                 :            :         uint32_t chunks, nb_desc = 0;
     675                 :            :         uint32_t queue_buf_sz;
     676                 :            :         int i, j, rc = 0;
     677                 :            :         void *chunk;
     678                 :            : 
     679                 :          0 :         dpivf->total_pnum_words = 0;
     680                 :            : 
     681         [ #  # ]:          0 :         for (i = 0; i < dpivf->num_vchans; i++) {
     682                 :          0 :                 dpi_conf = &dpivf->conf[i];
     683                 :          0 :                 dpi_conf->c_desc.head = 0;
     684                 :          0 :                 dpi_conf->c_desc.tail = 0;
     685                 :          0 :                 dpi_conf->desc_idx = 0;
     686                 :            : 
     687         [ #  # ]:          0 :                 if (dpi_conf->c_desc.compl_ptr == NULL)
     688                 :          0 :                         continue;
     689                 :            : 
     690         [ #  # ]:          0 :                 for (j = 0; j < dpi_conf->c_desc.max_cnt + 1; j++)
     691                 :          0 :                         dpi_conf->c_desc.compl_ptr[j * CNXK_DPI_COMPL_OFFSET] = CNXK_DPI_REQ_CDATA;
     692                 :          0 :                 nb_desc += dpi_conf->c_desc.max_cnt + 1;
     693                 :          0 :                 cnxk_stats_reset(dev, i);
     694                 :          0 :                 dpi_conf->completed_offset = 0;
     695                 :            :         }
     696                 :            : 
     697         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
     698         [ #  # ]:          0 :                 for (i = 0; i < (dpivf->rdpi.nr_lfs << 1); i++)
     699                 :          0 :                         dpivf->ring_conf[i].pending = 0;
     700                 :          0 :                 rc = roc_dpi_reset(&dpivf->rdpi);
     701         [ #  # ]:          0 :                 if (rc < 0) {
     702                 :          0 :                         plt_err("Failed to reset DPI LFs");
     703                 :          0 :                         goto error;
     704                 :            :                 }
     705                 :            : 
     706         [ #  # ]:          0 :                 if (dpivf->is_ring_conf_done)
     707                 :          0 :                         goto enable_dpi;
     708                 :            : 
     709                 :          0 :                 rc = cn20k_dmadev_queue_setup(dpivf);
     710         [ #  # ]:          0 :                 if (rc)
     711                 :          0 :                         goto error;
     712                 :            : 
     713                 :          0 :                 rc = cn20k_dmadev_chan_tbl_setup(dpivf);
     714         [ #  # ]:          0 :                 if (rc)
     715                 :          0 :                         goto error;
     716                 :            : 
     717                 :          0 :                 dpivf->is_ring_conf_done = true;
     718                 :            : 
     719                 :          0 :                 goto enable_dpi;
     720                 :            :         }
     721                 :            : 
     722                 :            :         queue_buf_sz = CNXK_DPI_QUEUE_BUF_SIZE_V2;
     723                 :            :         /* Max block size allowed by cnxk mempool driver is (128 * 1024).
     724                 :            :          * Block size = elt_size + mp->header + mp->trailer.
     725                 :            :          *
     726                 :            :          * Note from cn9k mempool driver:
     727                 :            :          * In cn9k additional padding of 128 bytes is added to mempool->trailer to
     728                 :            :          * ensure that the element size always occupies odd number of cachelines
     729                 :            :          * to ensure even distribution of elements among L1D cache sets.
     730                 :            :          */
     731         [ #  # ]:          0 :         if (!roc_model_is_cn10k())
     732                 :            :                 queue_buf_sz = CNXK_DPI_QUEUE_BUF_SIZE_V2 - 128;
     733                 :            : 
     734                 :          0 :         chunks = CNXK_DPI_CHUNKS_FROM_DESC(queue_buf_sz, nb_desc);
     735                 :          0 :         rc = cnxk_dmadev_chunk_pool_create(dev, chunks, queue_buf_sz);
     736         [ #  # ]:          0 :         if (rc < 0) {
     737                 :          0 :                 plt_err("DMA pool configure failed err = %d", rc);
     738                 :          0 :                 goto error;
     739                 :            :         }
     740                 :            : 
     741         [ #  # ]:          0 :         rc = rte_mempool_get(dpivf->chunk_pool, &chunk);
     742         [ #  # ]:          0 :         if (rc < 0) {
     743                 :          0 :                 plt_err("DMA failed to get chunk pointer err = %d", rc);
     744                 :          0 :                 rte_mempool_free(dpivf->chunk_pool);
     745                 :          0 :                 goto error;
     746                 :            :         }
     747                 :            : 
     748                 :          0 :         rc = roc_dpi_configure_v2(&dpivf->rdpi, queue_buf_sz, dpivf->aura, (uint64_t)chunk);
     749         [ #  # ]:          0 :         if (rc < 0) {
     750                 :          0 :                 plt_err("DMA configure failed err = %d", rc);
     751                 :          0 :                 rte_mempool_free(dpivf->chunk_pool);
     752                 :          0 :                 goto error;
     753                 :            :         }
     754                 :          0 :         dpivf->chunk_base = chunk;
     755                 :          0 :         dpivf->chunk_head = 0;
     756                 :          0 :         dpivf->chunk_size_m1 = (queue_buf_sz >> 3) - 2;
     757                 :            : 
     758                 :          0 : enable_dpi:
     759                 :          0 :         roc_dpi_enable(&dpivf->rdpi);
     760                 :          0 : error:
     761                 :          0 :         return rc;
     762                 :            : }
     763                 :            : 
     764                 :            : static int
     765                 :          0 : cnxk_dmadev_stop(struct rte_dma_dev *dev)
     766                 :            : {
     767         [ #  # ]:          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
     768                 :            : 
     769         [ #  # ]:          0 :         if (!roc_model_is_cn20k()) {
     770         [ #  # ]:          0 :                 if (roc_dpi_wait_queue_idle(&dpivf->rdpi))
     771                 :            :                         return -EAGAIN;
     772                 :            :         }
     773                 :            : 
     774                 :          0 :         roc_dpi_disable(&dpivf->rdpi);
     775         [ #  # ]:          0 :         if (!roc_model_is_cn20k()) {
     776                 :          0 :                 rte_mempool_free(dpivf->chunk_pool);
     777                 :          0 :                 dpivf->chunk_pool = NULL;
     778                 :          0 :                 dpivf->chunk_base = NULL;
     779                 :          0 :                 dpivf->chunk_size_m1 = 0;
     780                 :            :         }
     781                 :            : 
     782                 :            :         return 0;
     783                 :            : }
     784                 :            : 
     785                 :            : static int
     786                 :          0 : cnxk_dmadev_close(struct rte_dma_dev *dev)
     787                 :            : {
     788                 :          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
     789                 :            : 
     790                 :          0 :         roc_dpi_disable(&dpivf->rdpi);
     791                 :          0 :         cnxk_dmadev_vchan_free(dpivf, RTE_DMA_ALL_VCHAN);
     792                 :            : 
     793         [ #  # ]:          0 :         if (roc_model_is_cn20k())
     794                 :          0 :                 cnxk_dmadev_vchan_rsrc_free(dpivf);
     795                 :            : 
     796                 :          0 :         roc_dpi_dev_fini(&dpivf->rdpi);
     797                 :            : 
     798                 :            :         /* Clear all flags as we close the device. */
     799                 :          0 :         dpivf->flag = 0;
     800                 :            : 
     801                 :          0 :         return 0;
     802                 :            : }
     803                 :            : 
     804                 :            : static uint16_t
     805                 :          0 : cnxk_dmadev_completed(void *dev_private, uint16_t vchan, const uint16_t nb_cpls, uint16_t *last_idx,
     806                 :            :                       bool *has_error)
     807                 :            : {
     808                 :            :         struct cnxk_dpi_vf_s *dpivf = dev_private;
     809                 :          0 :         struct cnxk_dpi_conf *dpi_conf = &dpivf->conf[vchan];
     810                 :            :         struct cnxk_dpi_cdesc_data_s *c_desc = &dpi_conf->c_desc;
     811                 :          0 :         const uint16_t max_cnt = c_desc->max_cnt;
     812                 :            :         uint8_t status;
     813                 :            :         int cnt;
     814                 :            : 
     815         [ #  # ]:          0 :         for (cnt = 0; cnt < nb_cpls; cnt++) {
     816                 :          0 :                 status = c_desc->compl_ptr[(c_desc->head & max_cnt) * CNXK_DPI_COMPL_OFFSET];
     817         [ #  # ]:          0 :                 if (status) {
     818         [ #  # ]:          0 :                         if (status == CNXK_DPI_REQ_CDATA)
     819                 :            :                                 break;
     820                 :          0 :                         *has_error = 1;
     821                 :          0 :                         dpi_conf->stats.errors++;
     822                 :          0 :                         c_desc->compl_ptr[(c_desc->head & max_cnt) * CNXK_DPI_COMPL_OFFSET] =
     823                 :            :                                 CNXK_DPI_REQ_CDATA;
     824                 :          0 :                         c_desc->head++;
     825                 :          0 :                         break;
     826                 :            :                 }
     827                 :          0 :                 c_desc->compl_ptr[(c_desc->head & max_cnt) * CNXK_DPI_COMPL_OFFSET] =
     828                 :            :                         CNXK_DPI_REQ_CDATA;
     829                 :          0 :                 c_desc->head++;
     830                 :            :         }
     831                 :            : 
     832                 :          0 :         dpi_conf->stats.completed += cnt;
     833                 :          0 :         *last_idx = (dpi_conf->completed_offset + dpi_conf->stats.completed - 1) & 0xffff;
     834                 :            : 
     835                 :          0 :         return cnt;
     836                 :            : }
     837                 :            : 
     838                 :            : static uint16_t
     839                 :          0 : cnxk_dmadev_completed_status(void *dev_private, uint16_t vchan, const uint16_t nb_cpls,
     840                 :            :                              uint16_t *last_idx, enum rte_dma_status_code *status)
     841                 :            : {
     842                 :            :         struct cnxk_dpi_vf_s *dpivf = dev_private;
     843                 :          0 :         struct cnxk_dpi_conf *dpi_conf = &dpivf->conf[vchan];
     844                 :            :         struct cnxk_dpi_cdesc_data_s *c_desc = &dpi_conf->c_desc;
     845                 :          0 :         const uint16_t max_cnt = dpi_conf->c_desc.max_cnt;
     846                 :            :         int cnt;
     847                 :            : 
     848         [ #  # ]:          0 :         for (cnt = 0; cnt < nb_cpls; cnt++) {
     849                 :          0 :                 status[cnt] = c_desc->compl_ptr[(c_desc->head & max_cnt) * CNXK_DPI_COMPL_OFFSET];
     850         [ #  # ]:          0 :                 if (status[cnt]) {
     851         [ #  # ]:          0 :                         if (status[cnt] == CNXK_DPI_REQ_CDATA)
     852                 :            :                                 break;
     853                 :            : 
     854                 :          0 :                         dpi_conf->stats.errors++;
     855                 :            :                 }
     856                 :          0 :                 c_desc->compl_ptr[(c_desc->head & max_cnt) * CNXK_DPI_COMPL_OFFSET] =
     857                 :            :                         CNXK_DPI_REQ_CDATA;
     858                 :          0 :                 c_desc->head++;
     859                 :            :         }
     860                 :            : 
     861                 :          0 :         dpi_conf->stats.completed += cnt;
     862                 :          0 :         *last_idx = (dpi_conf->completed_offset + dpi_conf->stats.completed - 1) & 0xffff;
     863                 :            : 
     864                 :          0 :         return cnt;
     865                 :            : }
     866                 :            : 
     867                 :            : static uint16_t
     868                 :          0 : cnxk_damdev_burst_capacity(const void *dev_private, uint16_t vchan)
     869                 :            : {
     870                 :            :         const struct cnxk_dpi_vf_s *dpivf = (const struct cnxk_dpi_vf_s *)dev_private;
     871                 :          0 :         const struct cnxk_dpi_conf *dpi_conf = &dpivf->conf[vchan];
     872                 :            :         struct cn20k_ring_conf *ring_conf;
     873                 :            :         uint16_t burst_cap;
     874                 :            : 
     875                 :          0 :         burst_cap = dpi_conf->c_desc.max_cnt -
     876         [ #  # ]:          0 :                     (dpi_conf->stats.submitted - dpi_conf->stats.completed) + 1;
     877                 :            : 
     878         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
     879                 :          0 :                 ring_conf = &dpivf->ring_conf[dpi_conf->ridx];
     880                 :          0 :                 burst_cap -= ring_conf->pending;
     881                 :            :         }
     882                 :            : 
     883                 :          0 :         return burst_cap;
     884                 :            : }
     885                 :            : 
     886                 :            : static int
     887                 :          0 : cnxk_dmadev_submit(void *dev_private, uint16_t vchan)
     888                 :            : {
     889                 :            :         struct cnxk_dpi_vf_s *dpivf = dev_private;
     890                 :          0 :         uint32_t num_words = dpivf->total_pnum_words;
     891                 :            :         RTE_SET_USED(vchan);
     892                 :            : 
     893         [ #  # ]:          0 :         if (!num_words)
     894                 :            :                 return 0;
     895                 :            : 
     896                 :          0 :         rte_io_wmb();
     897                 :          0 :         plt_write64(num_words, dpivf->rdpi.rbase + DPI_VDMA_DBELL);
     898                 :            : 
     899                 :          0 :         dpivf->total_pnum_words = 0;
     900                 :            : 
     901                 :          0 :         return 0;
     902                 :            : }
     903                 :            : 
     904                 :            : static int
     905                 :          0 : cn20k_dmadev_submit(void *dev_private, uint16_t vchan)
     906                 :            : {
     907                 :            :         struct cnxk_dpi_vf_s *dpivf = dev_private;
     908                 :          0 :         struct cnxk_dpi_conf *dpi_conf = &dpivf->conf[vchan];
     909                 :          0 :         struct cn20k_ring_conf *ring_conf = &dpivf->ring_conf[dpi_conf->ridx];
     910                 :          0 :         uint16_t num_words = ring_conf->pending;
     911                 :            : 
     912         [ #  # ]:          0 :         if (!num_words)
     913                 :            :                 return 0;
     914                 :            : 
     915                 :          0 :         rte_io_wmb();
     916                 :          0 :         plt_write64(num_words, dpi_conf->dbell);
     917                 :          0 :         dpi_conf->stats.submitted += num_words;
     918                 :            : 
     919                 :          0 :         ring_conf->pending = 0;
     920                 :            : 
     921                 :          0 :         return 0;
     922                 :            : }
     923                 :            : 
     924                 :            : static int
     925                 :          0 : cnxk_stats_get(const struct rte_dma_dev *dev, uint16_t vchan, struct rte_dma_stats *rte_stats,
     926                 :            :                uint32_t size)
     927                 :            : {
     928                 :          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
     929                 :            :         struct cnxk_dpi_conf *dpi_conf;
     930                 :            :         int i;
     931                 :            : 
     932         [ #  # ]:          0 :         if (size < sizeof(rte_stats))
     933                 :            :                 return -EINVAL;
     934         [ #  # ]:          0 :         if (rte_stats == NULL)
     935                 :            :                 return -EINVAL;
     936                 :            : 
     937                 :            :         /* Stats of all vchans requested. */
     938         [ #  # ]:          0 :         if (vchan == RTE_DMA_ALL_VCHAN) {
     939         [ #  # ]:          0 :                 for (i = 0; i < dpivf->num_vchans; i++) {
     940                 :          0 :                         dpi_conf = &dpivf->conf[i];
     941                 :          0 :                         rte_stats->submitted += dpi_conf->stats.submitted;
     942                 :          0 :                         rte_stats->completed += dpi_conf->stats.completed;
     943                 :          0 :                         rte_stats->errors += dpi_conf->stats.errors;
     944                 :            :                 }
     945                 :            : 
     946                 :          0 :                 goto done;
     947                 :            :         }
     948                 :            : 
     949         [ #  # ]:          0 :         if (vchan >= CNXK_DPI_MAX_VCHANS_PER_QUEUE)
     950                 :            :                 return -EINVAL;
     951                 :            : 
     952                 :          0 :         dpi_conf = &dpivf->conf[vchan];
     953                 :          0 :         *rte_stats = dpi_conf->stats;
     954                 :            : 
     955                 :            : done:
     956                 :            :         return 0;
     957                 :            : }
     958                 :            : 
     959                 :            : static int
     960                 :          0 : cnxk_stats_reset(struct rte_dma_dev *dev, uint16_t vchan)
     961                 :            : {
     962                 :          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
     963                 :            :         struct cnxk_dpi_conf *dpi_conf;
     964                 :            :         int i;
     965                 :            : 
     966                 :            :         /* clear stats of all vchans. */
     967         [ #  # ]:          0 :         if (vchan == RTE_DMA_ALL_VCHAN) {
     968         [ #  # ]:          0 :                 for (i = 0; i < dpivf->num_vchans; i++) {
     969                 :          0 :                         dpi_conf = &dpivf->conf[i];
     970                 :          0 :                         dpi_conf->completed_offset += dpi_conf->stats.completed;
     971                 :          0 :                         dpi_conf->stats = (struct rte_dma_stats){0};
     972                 :            :                 }
     973                 :            : 
     974                 :            :                 return 0;
     975                 :            :         }
     976                 :            : 
     977         [ #  # ]:          0 :         if (vchan >= CNXK_DPI_MAX_VCHANS_PER_QUEUE)
     978                 :            :                 return -EINVAL;
     979                 :            : 
     980                 :          0 :         dpi_conf = &dpivf->conf[vchan];
     981                 :          0 :         dpi_conf->completed_offset += dpi_conf->stats.completed;
     982                 :          0 :         dpi_conf->stats = (struct rte_dma_stats){0};
     983                 :            : 
     984                 :          0 :         return 0;
     985                 :            : }
     986                 :            : 
     987                 :            : static void
     988                 :          0 : cnxk_set_fp_ops(struct rte_dma_dev *dev, uint8_t ena_enq_deq)
     989                 :            : {
     990                 :            : 
     991                 :          0 :         dev->fp_obj->copy = cnxk_dmadev_copy;
     992                 :          0 :         dev->fp_obj->copy_sg = cnxk_dmadev_copy_sg;
     993                 :          0 :         dev->fp_obj->submit = cnxk_dmadev_submit;
     994                 :          0 :         dev->fp_obj->completed = cnxk_dmadev_completed;
     995                 :          0 :         dev->fp_obj->completed_status = cnxk_dmadev_completed_status;
     996         [ #  # ]:          0 :                 dev->fp_obj->burst_capacity = cnxk_damdev_burst_capacity;
     997                 :            : 
     998         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
     999                 :          0 :                 dev->fp_obj->copy = cn10k_dmadev_copy;
    1000                 :          0 :                 dev->fp_obj->copy_sg = cn10k_dmadev_copy_sg;
    1001         [ #  # ]:          0 :         } else if (roc_model_is_cn20k()) {
    1002                 :          0 :                 dev->fp_obj->submit = cn20k_dmadev_submit;
    1003                 :          0 :                 dev->fp_obj->copy = cn20k_dmadev_copy;
    1004                 :          0 :                 dev->fp_obj->copy_sg = cn20k_dmadev_copy_sg;
    1005                 :          0 :                 dev->fp_obj->fill = cn20k_dmadev_fill;
    1006                 :            :         }
    1007                 :            : 
    1008         [ #  # ]:          0 :         if (ena_enq_deq) {
    1009                 :          0 :                 dev->fp_obj->copy = NULL;
    1010                 :          0 :                 dev->fp_obj->copy_sg = NULL;
    1011                 :          0 :                 dev->fp_obj->submit = NULL;
    1012                 :          0 :                 dev->fp_obj->completed = NULL;
    1013                 :          0 :                 dev->fp_obj->completed_status = NULL;
    1014                 :            : 
    1015                 :          0 :                 dev->fp_obj->enqueue = cnxk_dma_ops_enqueue;
    1016                 :          0 :                 dev->fp_obj->dequeue = cnxk_dma_ops_dequeue;
    1017                 :            : 
    1018         [ #  # ]:          0 :                 if (roc_model_is_cn10k())
    1019                 :          0 :                         dev->fp_obj->enqueue = cn10k_dma_ops_enqueue;
    1020                 :            : 
    1021         [ #  # ]:          0 :                 if (roc_model_is_cn20k())
    1022                 :          0 :                         dev->fp_obj->enqueue = cn20k_dma_ops_enqueue;
    1023                 :            :         }
    1024                 :          0 : }
    1025                 :            : 
    1026                 :            : static int
    1027                 :          0 : cnxk_dmadev_access_pair_group_create(const struct rte_dma_dev *dev, rte_uuid_t domain_id,
    1028                 :            :                                        rte_uuid_t token, int16_t *group_id,
    1029                 :            :                                        rte_dma_access_pair_group_event_cb_t cb)
    1030                 :            : {
    1031         [ #  # ]:          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
    1032                 :            :         struct roc_dpi_lf *lf;
    1033                 :            :         int rc;
    1034                 :            : 
    1035                 :            :         RTE_SET_USED(cb);
    1036                 :            : 
    1037         [ #  # ]:          0 :         if (!roc_model_is_cn20k())
    1038                 :            :                 return -ENOTSUP;
    1039                 :            : 
    1040   [ #  #  #  # ]:          0 :         if (dpivf->rdpi.lfs == NULL || dpivf->rdpi.nr_lfs == 0) {
    1041                 :          0 :                 plt_err("DPI LF resources are not initialized");
    1042                 :          0 :                 return -EINVAL;
    1043                 :            :         }
    1044                 :            : 
    1045                 :            :         lf = &(dpivf->rdpi.lfs[0]);
    1046                 :            : 
    1047                 :          0 :         rc = roc_dpi_access_pair_group_create(lf, domain_id, token, group_id);
    1048                 :            : 
    1049                 :          0 :         return rc;
    1050                 :            : }
    1051                 :            : 
    1052                 :            : static int
    1053                 :          0 : cnxk_dmadev_access_pair_group_destroy(const struct rte_dma_dev *dev, int16_t group_id)
    1054                 :            : {
    1055         [ #  # ]:          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
    1056                 :            :         struct roc_dpi_lf *lf;
    1057                 :            :         int rc;
    1058                 :            : 
    1059         [ #  # ]:          0 :         if (!roc_model_is_cn20k())
    1060                 :            :                 return -ENOTSUP;
    1061                 :            : 
    1062   [ #  #  #  # ]:          0 :         if (dpivf->rdpi.lfs == NULL || dpivf->rdpi.nr_lfs == 0) {
    1063                 :          0 :                 plt_err("DPI LF resources are not initialized");
    1064                 :          0 :                 return -EINVAL;
    1065                 :            :         }
    1066                 :            : 
    1067                 :            :         lf = &(dpivf->rdpi.lfs[0]);
    1068                 :            : 
    1069         [ #  # ]:          0 :         if (lf->group_id != group_id) {
    1070                 :          0 :                 plt_err("Invalid access pair group is passed");
    1071                 :          0 :                 return -EINVAL;
    1072                 :            :         }
    1073                 :            : 
    1074                 :          0 :         rc = roc_dpi_access_pair_group_destroy(lf, group_id);
    1075                 :            : 
    1076                 :          0 :         return rc;
    1077                 :            : }
    1078                 :            : 
    1079                 :            : static int
    1080                 :          0 : cnxk_dmadev_access_pair_group_join(const struct rte_dma_dev *dev, rte_uuid_t domain_id,
    1081                 :            :                                    rte_uuid_t token, int16_t group_id,
    1082                 :            :                                    rte_dma_access_pair_group_event_cb_t cb)
    1083                 :            : {
    1084         [ #  # ]:          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
    1085                 :            :         struct roc_dpi_lf *lf;
    1086                 :            :         int rc;
    1087                 :            : 
    1088                 :            :         RTE_SET_USED(cb);
    1089                 :            : 
    1090         [ #  # ]:          0 :         if (!roc_model_is_cn20k())
    1091                 :            :                 return -ENOTSUP;
    1092                 :            : 
    1093   [ #  #  #  # ]:          0 :         if (dpivf->rdpi.lfs == NULL || dpivf->rdpi.nr_lfs == 0) {
    1094                 :          0 :                 plt_err("DPI LF resources are not initialized");
    1095                 :          0 :                 return -EINVAL;
    1096                 :            :         }
    1097                 :            : 
    1098                 :            :         lf = &(dpivf->rdpi.lfs[0]);
    1099                 :            : 
    1100                 :          0 :         rc = roc_dpi_access_pair_group_join(lf, domain_id, token, group_id);
    1101                 :            : 
    1102                 :          0 :         return rc;
    1103                 :            : }
    1104                 :            : 
    1105                 :            : static int
    1106                 :          0 : cnxk_dmadev_access_pair_group_leave(const struct rte_dma_dev *dev, int16_t group_id)
    1107                 :            : {
    1108         [ #  # ]:          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
    1109                 :            :         struct roc_dpi_lf *lf;
    1110                 :            :         int rc;
    1111                 :            : 
    1112         [ #  # ]:          0 :         if (!roc_model_is_cn20k())
    1113                 :            :                 return -ENOTSUP;
    1114                 :            : 
    1115   [ #  #  #  # ]:          0 :         if (dpivf->rdpi.lfs == NULL || dpivf->rdpi.nr_lfs == 0) {
    1116                 :          0 :                 plt_err("DPI LF resources are not initialized");
    1117                 :          0 :                 return -EINVAL;
    1118                 :            :         }
    1119                 :            : 
    1120                 :            :         lf = &(dpivf->rdpi.lfs[0]);
    1121                 :            : 
    1122         [ #  # ]:          0 :         if (lf->group_id != group_id) {
    1123                 :          0 :                 plt_err("Invalid access pair group is passed");
    1124                 :          0 :                 return -EINVAL;
    1125                 :            :         }
    1126                 :            : 
    1127                 :          0 :         rc = roc_dpi_access_pair_group_leave(lf, group_id);
    1128                 :            : 
    1129                 :          0 :         return rc;
    1130                 :            : }
    1131                 :            : 
    1132                 :            : static int
    1133                 :          0 : cnxk_dmadev_access_pair_group_handler_get(const struct rte_dma_dev *dev, int16_t group_id,
    1134                 :            :                                           rte_uuid_t domain_id, uint16_t *handler)
    1135                 :            : {
    1136         [ #  # ]:          0 :         struct cnxk_dpi_vf_s *dpivf = dev->fp_obj->dev_private;
    1137                 :            :         struct roc_dpi_lf *lf;
    1138                 :            :         int rc;
    1139                 :            : 
    1140         [ #  # ]:          0 :         if (!roc_model_is_cn20k())
    1141                 :            :                 return -ENOTSUP;
    1142                 :            : 
    1143   [ #  #  #  # ]:          0 :         if (dpivf->rdpi.lfs == NULL || dpivf->rdpi.nr_lfs == 0) {
    1144                 :          0 :                 plt_err("DPI LF resources are not initialized");
    1145                 :          0 :                 return -EINVAL;
    1146                 :            :         }
    1147                 :            : 
    1148                 :            :         lf = &(dpivf->rdpi.lfs[0]);
    1149                 :            : 
    1150         [ #  # ]:          0 :         if (lf->group_id != group_id) {
    1151                 :          0 :                 plt_err("Invalid access pair group is passed");
    1152                 :          0 :                 return -EINVAL;
    1153                 :            :         }
    1154                 :            : 
    1155                 :          0 :         rc = roc_dpi_access_pair_group_handler_get(lf, group_id, domain_id, handler);
    1156                 :            : 
    1157                 :          0 :         return rc;
    1158                 :            : }
    1159                 :            : 
    1160                 :            : static const struct rte_dma_dev_ops cnxk_dmadev_ops = {
    1161                 :            :         .dev_close = cnxk_dmadev_close,
    1162                 :            :         .dev_configure = cnxk_dmadev_configure,
    1163                 :            :         .dev_info_get = cnxk_dmadev_info_get,
    1164                 :            :         .dev_start = cnxk_dmadev_start,
    1165                 :            :         .dev_stop = cnxk_dmadev_stop,
    1166                 :            :         .stats_get = cnxk_stats_get,
    1167                 :            :         .stats_reset = cnxk_stats_reset,
    1168                 :            :         .vchan_setup = cnxk_dmadev_vchan_setup,
    1169                 :            :         .access_pair_group_create = cnxk_dmadev_access_pair_group_create,
    1170                 :            :         .access_pair_group_destroy = cnxk_dmadev_access_pair_group_destroy,
    1171                 :            :         .access_pair_group_join = cnxk_dmadev_access_pair_group_join,
    1172                 :            :         .access_pair_group_leave = cnxk_dmadev_access_pair_group_leave,
    1173                 :            :         .access_pair_group_handler_get = cnxk_dmadev_access_pair_group_handler_get,
    1174                 :            : };
    1175                 :            : 
    1176                 :            : static int
    1177         [ #  # ]:          0 : cnxk_dmadev_probe(struct rte_pci_driver *pci_drv __rte_unused, struct rte_pci_device *pci_dev)
    1178                 :            : {
    1179                 :            :         struct cnxk_dpi_vf_s *dpivf = NULL;
    1180                 :            :         char name[RTE_DEV_NAME_MAX_LEN];
    1181                 :            :         struct rte_dma_dev *dmadev;
    1182                 :            :         struct roc_dpi *rdpi = NULL;
    1183                 :            :         int rc;
    1184                 :            : 
    1185         [ #  # ]:          0 :         if (!roc_model_is_cn20k()) {
    1186         [ #  # ]:          0 :                 if (!pci_dev->mem_resource[0].addr)
    1187                 :            :                         return -ENODEV;
    1188                 :            :         }
    1189                 :            : 
    1190                 :          0 :         rc = roc_plt_init();
    1191         [ #  # ]:          0 :         if (rc) {
    1192                 :          0 :                 plt_err("Failed to initialize platform model, rc=%d", rc);
    1193                 :          0 :                 return rc;
    1194                 :            :         }
    1195                 :            :         memset(name, 0, sizeof(name));
    1196                 :          0 :         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
    1197                 :            : 
    1198                 :          0 :         dmadev = rte_dma_pmd_allocate(name, pci_dev->device.numa_node, sizeof(*dpivf));
    1199         [ #  # ]:          0 :         if (dmadev == NULL) {
    1200                 :          0 :                 plt_err("dma device allocation failed for %s", name);
    1201                 :          0 :                 return -ENOMEM;
    1202                 :            :         }
    1203                 :            : 
    1204                 :          0 :         dpivf = dmadev->data->dev_private;
    1205         [ #  # ]:          0 :         dmadev->device = &pci_dev->device;
    1206                 :            : 
    1207         [ #  # ]:          0 :         if (roc_model_is_cn20k()) {
    1208                 :            :                 /* Parse devargs string */
    1209                 :          0 :                 rc = cn20k_dmadev_parse_devargs(dmadev->device->devargs, dpivf);
    1210         [ #  # ]:          0 :                 if (rc) {
    1211                 :          0 :                         plt_err("Failed to parse devargs rc=%d", rc);
    1212                 :          0 :                         goto err_out_free;
    1213                 :            :                 }
    1214                 :          0 :                 dpivf->num_vchans = dpivf->max_vchans;
    1215                 :            :         }
    1216                 :            : 
    1217                 :          0 :         dmadev->device = &pci_dev->device;
    1218                 :          0 :         dmadev->fp_obj->dev_private = dpivf;
    1219                 :          0 :         dmadev->dev_ops = &cnxk_dmadev_ops;
    1220                 :            : 
    1221                 :            :         /*
    1222                 :            :          * dev_private (and the roc_dpi it holds) lives in shared memory. Only
    1223                 :            :          * the primary owns the HW and the per-process pci_dev pointer; a
    1224                 :            :          * secondary must not run roc_dpi_dev_init nor overwrite rdpi->pci_dev,
    1225                 :            :          * otherwise the primary later dereferences the secondary's stale
    1226                 :            :          * pointer during rte_eal_cleanup() and crashes.
    1227                 :            :          */
    1228         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1229                 :            :                 return 0;
    1230                 :            : 
    1231                 :          0 :         dmadev->fp_obj->submit = cnxk_dmadev_submit;
    1232                 :          0 :         dmadev->fp_obj->completed = cnxk_dmadev_completed;
    1233                 :          0 :         dmadev->fp_obj->completed_status = cnxk_dmadev_completed_status;
    1234         [ #  # ]:          0 :         dmadev->fp_obj->burst_capacity = cnxk_damdev_burst_capacity;
    1235                 :            : 
    1236         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
    1237                 :          0 :                 dmadev->fp_obj->copy = cn10k_dmadev_copy;
    1238                 :          0 :                 dmadev->fp_obj->copy_sg = cn10k_dmadev_copy_sg;
    1239                 :          0 :                 dpivf->num_vchans = CNXK_DPI_MAX_VCHANS_PER_QUEUE;
    1240         [ #  # ]:          0 :         } else if (roc_model_is_cn20k()) {
    1241                 :          0 :                 dmadev->fp_obj->submit = cn20k_dmadev_submit;
    1242                 :          0 :                 dmadev->fp_obj->copy = cn20k_dmadev_copy;
    1243                 :          0 :                 dmadev->fp_obj->copy_sg = cn20k_dmadev_copy_sg;
    1244                 :          0 :                 dmadev->fp_obj->fill = cn20k_dmadev_fill;
    1245                 :            :         } else {
    1246                 :          0 :                 dmadev->fp_obj->copy = cnxk_dmadev_copy;
    1247                 :          0 :                 dmadev->fp_obj->copy_sg = cnxk_dmadev_copy_sg;
    1248                 :          0 :                 dpivf->num_vchans = CNXK_DPI_MAX_VCHANS_PER_QUEUE;
    1249                 :            :         }
    1250                 :            : 
    1251                 :          0 :         dpivf->conf = rte_zmalloc("dpi_vchan_conf", dpivf->num_vchans *
    1252                 :            :                                   sizeof(struct cnxk_dpi_conf), 0);
    1253         [ #  # ]:          0 :         if (dpivf->conf == NULL) {
    1254                 :          0 :                 plt_err("Failed to allocate memory for vchan conf");
    1255                 :            :                 rc = -ENOMEM;
    1256                 :          0 :                 goto err_out_free;
    1257                 :            :         }
    1258                 :            : 
    1259                 :          0 :         dpivf->mcs_lock = NULL;
    1260                 :          0 :         rdpi = &dpivf->rdpi;
    1261                 :            : 
    1262                 :          0 :         rdpi->pci_dev = pci_dev;
    1263                 :            : 
    1264                 :          0 :         rc = roc_dpi_dev_init(rdpi, offsetof(struct rte_dma_op, impl_opaque));
    1265         [ #  # ]:          0 :         if (rc < 0)
    1266                 :          0 :                 goto err_out_free;
    1267                 :            : 
    1268                 :          0 :         dmadev->state = RTE_DMA_DEV_READY;
    1269                 :            : 
    1270                 :          0 :         return 0;
    1271                 :            : 
    1272                 :          0 : err_out_free:
    1273                 :            :         if (dmadev)
    1274                 :          0 :                 rte_dma_pmd_release(name);
    1275                 :            : 
    1276                 :          0 :         return rc;
    1277                 :            : }
    1278                 :            : 
    1279                 :            : static int
    1280                 :          0 : cnxk_dmadev_remove(struct rte_pci_device *pci_dev)
    1281                 :            : {
    1282                 :            :         char name[RTE_DEV_NAME_MAX_LEN];
    1283                 :            : 
    1284                 :            :         memset(name, 0, sizeof(name));
    1285                 :          0 :         rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
    1286                 :            : 
    1287                 :          0 :         return rte_dma_pmd_release(name);
    1288                 :            : }
    1289                 :            : 
    1290                 :            : static const struct rte_pci_id cnxk_dma_pci_map[] = {
    1291                 :            :         {RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CNXK_DPI_VF)},
    1292                 :            :         {RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CN20K_DPI_PF)},
    1293                 :            :         {RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CN20K_DPI_VF)},
    1294                 :            :         {
    1295                 :            :                 .vendor_id = 0,
    1296                 :            :         },
    1297                 :            : };
    1298                 :            : 
    1299                 :            : static struct rte_pci_driver cnxk_dmadev = {
    1300                 :            :         .id_table = cnxk_dma_pci_map,
    1301                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
    1302                 :            :         .probe = cnxk_dmadev_probe,
    1303                 :            :         .remove = cnxk_dmadev_remove,
    1304                 :            : };
    1305                 :            : 
    1306                 :        305 : RTE_PMD_REGISTER_PCI(cnxk_dmadev_pci_driver, cnxk_dmadev);
    1307                 :            : RTE_PMD_REGISTER_PCI_TABLE(cnxk_dmadev_pci_driver, cnxk_dma_pci_map);
    1308                 :            : RTE_PMD_REGISTER_KMOD_DEP(cnxk_dmadev_pci_driver, "vfio-pci");

Generated by: LCOV version 1.14