LCOV - code coverage report
Current view: top level - drivers/mempool/cnxk - cnxk_mempool_ops.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 3 71 4.2 %
Date: 2025-02-01 18:54:23 Functions: 1 9 11.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 32 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_mbuf_pool_ops.h>
       6                 :            : #include <rte_mempool.h>
       7                 :            : 
       8                 :            : #include "roc_api.h"
       9                 :            : #include "cnxk_mempool.h"
      10                 :            : 
      11                 :            : int __rte_hot
      12                 :          0 : cnxk_mempool_enq(struct rte_mempool *mp, void *const *obj_table, unsigned int n)
      13                 :            : {
      14                 :            :         unsigned int index;
      15                 :            : 
      16                 :            :         /* Ensure mbuf init changes are written before the free pointers
      17                 :            :          * are enqueued to the stack.
      18                 :            :          */
      19                 :          0 :         rte_io_wmb();
      20         [ #  # ]:          0 :         for (index = 0; index < n; index++)
      21                 :          0 :                 roc_npa_aura_op_free(mp->pool_id, 0,
      22                 :          0 :                                      (uint64_t)obj_table[index]);
      23                 :            : 
      24                 :          0 :         return 0;
      25                 :            : }
      26                 :            : 
      27                 :            : int __rte_hot
      28                 :          0 : cnxk_mempool_deq(struct rte_mempool *mp, void **obj_table, unsigned int n)
      29                 :            : {
      30                 :            :         unsigned int index;
      31                 :            :         uint64_t obj;
      32                 :            : 
      33         [ #  # ]:          0 :         for (index = 0; index < n; index++, obj_table++) {
      34                 :            :                 int retry = 4;
      35                 :            : 
      36                 :            :                 /* Retry few times before failing */
      37                 :            :                 do {
      38                 :            :                         obj = roc_npa_aura_op_alloc(mp->pool_id, 0);
      39                 :            :                 } while (retry-- && (obj == 0));
      40                 :            : 
      41                 :            :                 if (obj == 0) {
      42                 :          0 :                         cnxk_mempool_enq(mp, obj_table - index, index);
      43                 :          0 :                         return -ENOENT;
      44                 :            :                 }
      45                 :            :                 *obj_table = (void *)obj;
      46                 :            :         }
      47                 :            : 
      48                 :            :         return 0;
      49                 :            : }
      50                 :            : 
      51                 :            : unsigned int
      52                 :          0 : cnxk_mempool_get_count(const struct rte_mempool *mp)
      53                 :            : {
      54                 :          0 :         return (unsigned int)roc_npa_aura_op_available(mp->pool_id);
      55                 :            : }
      56                 :            : 
      57                 :            : ssize_t
      58                 :          0 : cnxk_mempool_calc_mem_size(const struct rte_mempool *mp, uint32_t obj_num,
      59                 :            :                            uint32_t pg_shift, size_t *min_chunk_size,
      60                 :            :                            size_t *align)
      61                 :            : {
      62                 :            :         size_t total_elt_sz;
      63                 :            : 
      64                 :            :         /* Need space for one more obj on each chunk to fulfill
      65                 :            :          * alignment requirements.
      66                 :            :          */
      67                 :          0 :         total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
      68                 :          0 :         return rte_mempool_op_calc_mem_size_helper(
      69                 :            :                 mp, obj_num, pg_shift, total_elt_sz, min_chunk_size, align);
      70                 :            : }
      71                 :            : 
      72                 :            : int
      73                 :          0 : cnxk_mempool_alloc(struct rte_mempool *mp)
      74                 :            : {
      75                 :            :         uint32_t block_count, flags, roc_flags = 0;
      76                 :          0 :         uint64_t aura_handle = 0;
      77                 :            :         struct npa_aura_s aura;
      78                 :            :         struct npa_pool_s pool;
      79                 :            :         size_t block_size;
      80                 :            :         int rc = -ERANGE;
      81                 :            : 
      82                 :          0 :         block_size = mp->elt_size + mp->header_size + mp->trailer_size;
      83                 :          0 :         block_count = mp->size;
      84         [ #  # ]:          0 :         if (mp->header_size % ROC_ALIGN != 0) {
      85                 :          0 :                 plt_err("Header size should be multiple of %dB", ROC_ALIGN);
      86                 :          0 :                 goto error;
      87                 :            :         }
      88                 :            : 
      89         [ #  # ]:          0 :         if (block_size % ROC_ALIGN != 0) {
      90                 :          0 :                 plt_err("Block size should be multiple of %dB", ROC_ALIGN);
      91                 :          0 :                 goto error;
      92                 :            :         }
      93                 :            : 
      94                 :            :         memset(&aura, 0, sizeof(struct npa_aura_s));
      95                 :            :         memset(&pool, 0, sizeof(struct npa_pool_s));
      96                 :          0 :         pool.nat_align = 1;
      97                 :          0 :         pool.buf_offset = mp->header_size / ROC_ALIGN;
      98                 :            : 
      99                 :          0 :         flags = CNXK_MEMPOOL_FLAGS(mp);
     100         [ #  # ]:          0 :         if (flags & CNXK_MEMPOOL_F_ZERO_AURA) {
     101                 :            :                 roc_flags = ROC_NPA_ZERO_AURA_F;
     102         [ #  # ]:          0 :         } else if (flags & CNXK_MEMPOOL_F_CUSTOM_AURA) {
     103                 :            :                 struct npa_aura_s *paura;
     104                 :            : 
     105                 :          0 :                 paura = CNXK_MEMPOOL_CONFIG(mp);
     106                 :            :                 memcpy(&aura, paura, sizeof(struct npa_aura_s));
     107                 :            :         }
     108                 :            : 
     109                 :          0 :         rc = roc_npa_pool_create(&aura_handle, block_size, block_count, &aura,
     110                 :            :                                  &pool, roc_flags);
     111         [ #  # ]:          0 :         if (rc) {
     112                 :          0 :                 plt_err("Failed to alloc pool or aura rc=%d", rc);
     113                 :          0 :                 goto error;
     114                 :            :         }
     115                 :            : 
     116                 :            :         /* Store aura_handle for future queue operations */
     117                 :          0 :         mp->pool_id = aura_handle;
     118                 :          0 :         plt_npa_dbg("block_sz=%lu block_count=%d aura_handle=0x%" PRIx64,
     119                 :            :                     block_size, block_count, aura_handle);
     120                 :            : 
     121                 :          0 :         return 0;
     122                 :            : error:
     123                 :            :         return rc;
     124                 :            : }
     125                 :            : 
     126                 :            : void
     127                 :          0 : cnxk_mempool_free(struct rte_mempool *mp)
     128                 :            : {
     129                 :            :         int rc = 0;
     130                 :            : 
     131                 :          0 :         plt_npa_dbg("aura_handle=0x%" PRIx64, mp->pool_id);
     132                 :            : 
     133                 :            :         /* It can happen that rte_mempool_free() is called immediately after
     134                 :            :          * rte_mempool_create_empty(). In such cases the NPA pool will not be
     135                 :            :          * allocated.
     136                 :            :          */
     137         [ #  # ]:          0 :         if (roc_npa_aura_handle_to_base(mp->pool_id) == 0)
     138                 :            :                 return;
     139                 :            : 
     140                 :          0 :         rc = roc_npa_pool_destroy(mp->pool_id);
     141         [ #  # ]:          0 :         if (rc)
     142                 :          0 :                 plt_err("Failed to free pool or aura rc=%d", rc);
     143                 :            : }
     144                 :            : 
     145                 :            : int
     146                 :          0 : cnxk_mempool_populate(struct rte_mempool *mp, unsigned int max_objs,
     147                 :            :                       void *vaddr, rte_iova_t iova, size_t len,
     148                 :            :                       rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
     149                 :            : {
     150                 :            :         size_t total_elt_sz, off;
     151                 :            :         int num_elts;
     152                 :            : 
     153         [ #  # ]:          0 :         if (iova == RTE_BAD_IOVA)
     154                 :            :                 return -EINVAL;
     155                 :            : 
     156                 :          0 :         total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
     157                 :            : 
     158                 :            :         /* Align object start address to a multiple of total_elt_sz */
     159                 :          0 :         off = total_elt_sz - ((((uintptr_t)vaddr - 1) % total_elt_sz) + 1);
     160                 :            : 
     161         [ #  # ]:          0 :         if (len < off)
     162                 :            :                 return -EINVAL;
     163                 :            : 
     164                 :          0 :         vaddr = (char *)vaddr + off;
     165                 :          0 :         iova += off;
     166                 :          0 :         len -= off;
     167                 :          0 :         num_elts = len / total_elt_sz;
     168                 :            : 
     169                 :          0 :         plt_npa_dbg("iova %" PRIx64 ", aligned iova %" PRIx64 "", iova - off,
     170                 :            :                     iova);
     171                 :          0 :         plt_npa_dbg("length %" PRIu64 ", aligned length %" PRIu64 "",
     172                 :            :                     (uint64_t)(len + off), (uint64_t)len);
     173                 :          0 :         plt_npa_dbg("element size %" PRIu64 "", (uint64_t)total_elt_sz);
     174                 :          0 :         plt_npa_dbg("requested objects %" PRIu64 ", possible objects %" PRIu64
     175                 :            :                     "", (uint64_t)max_objs, (uint64_t)num_elts);
     176                 :            : 
     177                 :          0 :         roc_npa_pool_op_range_set(mp->pool_id, iova,
     178                 :          0 :                                   iova + num_elts * total_elt_sz);
     179                 :            : 
     180         [ #  # ]:          0 :         if (roc_npa_pool_range_update_check(mp->pool_id) < 0)
     181                 :            :                 return -EBUSY;
     182                 :            : 
     183                 :          0 :         return rte_mempool_op_populate_helper(
     184                 :            :                 mp, RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ, max_objs, vaddr, iova,
     185                 :            :                 len, obj_cb, obj_cb_arg);
     186                 :            : }
     187                 :            : 
     188                 :            : static int
     189         [ #  # ]:          0 : cnxk_mempool_plt_init(void)
     190                 :            : {
     191                 :            :         int rc = 0;
     192                 :            : 
     193         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     194                 :          0 :                 rte_mbuf_set_platform_mempool_ops("cn9k_mempool_ops");
     195   [ #  #  #  # ]:          0 :         } else if (roc_model_is_cn10k() || roc_model_is_cn20k()) {
     196                 :          0 :                 rte_mbuf_set_platform_mempool_ops("cn10k_mempool_ops");
     197                 :          0 :                 rc = cn10k_mempool_plt_init();
     198                 :            :         }
     199                 :          0 :         return rc;
     200                 :            : }
     201                 :            : 
     202                 :        252 : RTE_INIT(cnxk_mempool_ops_init)
     203                 :            : {
     204                 :        252 :         roc_plt_init_cb_register(cnxk_mempool_plt_init);
     205                 :        252 : }

Generated by: LCOV version 1.14