LCOV - code coverage report
Current view: top level - drivers/mempool/dpaa - dpaa_mempool.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 6 184 3.3 %
Date: 2026-12-01 19:01:22 Functions: 3 12 25.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 102 3.9 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *
       3                 :            :  *   Copyright 2017,2019,2023-2026 NXP
       4                 :            :  *
       5                 :            :  */
       6                 :            : 
       7                 :            : /* System headers */
       8                 :            : #include <stdio.h>
       9                 :            : #include <inttypes.h>
      10                 :            : #include <unistd.h>
      11                 :            : #include <limits.h>
      12                 :            : #include <sched.h>
      13                 :            : #include <signal.h>
      14                 :            : #include <pthread.h>
      15                 :            : #include <sys/types.h>
      16                 :            : #include <sys/syscall.h>
      17                 :            : 
      18                 :            : #include <eal_export.h>
      19                 :            : #include <rte_byteorder.h>
      20                 :            : #include <rte_common.h>
      21                 :            : #include <rte_log.h>
      22                 :            : #include <rte_debug.h>
      23                 :            : #include <rte_memory.h>
      24                 :            : #include <rte_tailq.h>
      25                 :            : #include <rte_eal.h>
      26                 :            : #include <rte_malloc.h>
      27                 :            : #include <rte_ring.h>
      28                 :            : 
      29                 :            : #include <dpaa_mempool.h>
      30                 :            : #include <dpaax_iova_table.h>
      31                 :            : 
      32                 :            : struct dpaa_bpid_flag {
      33                 :            :         uint32_t flags;
      34                 :            :         bool used;
      35                 :            : };
      36                 :            : 
      37                 :            : /* Process-local record of allocated BPIDs, still valid in the destructor
      38                 :            :  * when the bman_pool object in EAL memory may already be detached.
      39                 :            :  */
      40                 :            : static struct dpaa_bpid_flag s_dpaa_bpid_allocated_flag[DPAA_MAX_BPOOLS];
      41                 :            : 
      42                 :            : #define FMAN_ERRATA_BOUNDARY ((uint64_t)4096)
      43                 :            : #define FMAN_ERRATA_BOUNDARY_MASK (~(FMAN_ERRATA_BOUNDARY - 1))
      44                 :            : 
      45                 :            : /* List of all the memseg information locally maintained in dpaa driver. This
      46                 :            :  * is to optimize the PA_to_VA searches until a better mechanism (algo) is
      47                 :            :  * available.
      48                 :            :  */
      49                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_memsegs)
      50                 :            : struct dpaa_memseg_list rte_dpaa_memsegs
      51                 :            :         = TAILQ_HEAD_INITIALIZER(rte_dpaa_memsegs);
      52                 :            : 
      53                 :            : RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_bpid_info)
      54                 :            : struct dpaa_bp_info *rte_dpaa_bpid_info;
      55                 :            : 
      56         [ -  + ]:        306 : RTE_LOG_REGISTER_DEFAULT(dpaa_logtype_mempool, NOTICE);
      57                 :            : #define RTE_LOGTYPE_DPAA_MEMPOOL dpaa_logtype_mempool
      58                 :            : 
      59                 :            : static int
      60                 :          0 : dpaa_mbuf_create_pool(struct rte_mempool *mp)
      61                 :            : {
      62                 :            :         struct bman_pool *bp;
      63                 :            :         struct bm_buffer bufs[FSL_BM_BURST_MAX];
      64                 :            :         struct dpaa_bp_info *bp_info;
      65                 :            :         uint8_t bpid;
      66                 :            :         int num_bufs = 0, ret = 0;
      67                 :            :         uint16_t elem_max_size;
      68                 :          0 :         struct bman_pool_params params = {
      69                 :            :                 .flags = BMAN_POOL_FLAG_DYNAMIC_BPID
      70                 :            :         };
      71                 :            : 
      72                 :          0 :         MEMPOOL_INIT_FUNC_TRACE();
      73                 :            : 
      74         [ #  # ]:          0 :         if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
      75                 :          0 :                 ret = rte_dpaa_portal_init((void *)0);
      76         [ #  # ]:          0 :                 if (ret) {
      77                 :          0 :                         DPAA_MEMPOOL_ERR(
      78                 :            :                                 "rte_dpaa_portal_init failed with ret: %d",
      79                 :            :                                  ret);
      80                 :          0 :                         return -1;
      81                 :            :                 }
      82                 :            :         }
      83                 :          0 :         bp = bman_new_pool(&params);
      84         [ #  # ]:          0 :         if (!bp) {
      85                 :          0 :                 DPAA_MEMPOOL_ERR("bman_new_pool() failed");
      86                 :          0 :                 return -ENODEV;
      87                 :            :         }
      88                 :          0 :         bpid = bman_get_params(bp)->bpid;
      89                 :            : 
      90                 :            :         /* Drain the pool of anything already in it. */
      91                 :            :         do {
      92                 :            :                 /* Acquire is all-or-nothing, so we drain in 8s,
      93                 :            :                  * then in 1s for the remainder.
      94                 :            :                  */
      95         [ #  # ]:          0 :                 if (ret != 1)
      96                 :          0 :                         ret = bman_acquire(bp, bufs, FSL_BM_BURST_MAX, 0);
      97         [ #  # ]:          0 :                 if (ret < FSL_BM_BURST_MAX)
      98                 :          0 :                         ret = bman_acquire(bp, bufs, 1, 0);
      99         [ #  # ]:          0 :                 if (ret > 0)
     100                 :          0 :                         num_bufs += ret;
     101         [ #  # ]:          0 :         } while (ret > 0);
     102         [ #  # ]:          0 :         if (num_bufs)
     103                 :          0 :                 DPAA_MEMPOOL_WARN("drained %u bufs from BPID %d",
     104                 :            :                                   num_bufs, bpid);
     105                 :            : 
     106         [ #  # ]:          0 :         if (rte_dpaa_bpid_info == NULL) {
     107                 :          0 :                 rte_dpaa_bpid_info = (struct dpaa_bp_info *)rte_zmalloc(NULL,
     108                 :            :                                 sizeof(struct dpaa_bp_info) * DPAA_MAX_BPOOLS,
     109                 :            :                                 RTE_CACHE_LINE_SIZE);
     110         [ #  # ]:          0 :                 if (rte_dpaa_bpid_info == NULL) {
     111                 :          0 :                         bman_free_pool(bp);
     112                 :          0 :                         return -ENOMEM;
     113                 :            :                 }
     114                 :            :         }
     115                 :            : 
     116                 :            :         elem_max_size = rte_pktmbuf_data_room_size(mp);
     117                 :            : 
     118                 :          0 :         rte_dpaa_bpid_info[bpid].mp = mp;
     119                 :          0 :         rte_dpaa_bpid_info[bpid].bpid = bpid;
     120                 :          0 :         rte_dpaa_bpid_info[bpid].size = elem_max_size;
     121                 :          0 :         rte_dpaa_bpid_info[bpid].bp = bp;
     122                 :          0 :         rte_dpaa_bpid_info[bpid].meta_data_size =
     123                 :          0 :                 sizeof(struct rte_mbuf) + rte_pktmbuf_priv_size(mp);
     124                 :          0 :         rte_dpaa_bpid_info[bpid].dpaa_ops_index = mp->ops_index;
     125                 :          0 :         rte_dpaa_bpid_info[bpid].ptov_off = 0;
     126                 :          0 :         rte_dpaa_bpid_info[bpid].flags = 0;
     127                 :            : 
     128                 :          0 :         bp_info = rte_zmalloc(NULL,
     129                 :            :                              sizeof(struct dpaa_bp_info),
     130                 :            :                              RTE_CACHE_LINE_SIZE);
     131         [ #  # ]:          0 :         if (!bp_info) {
     132                 :          0 :                 DPAA_MEMPOOL_WARN("Memory allocation failed for bp_info");
     133                 :          0 :                 bman_free_pool(bp);
     134                 :          0 :                 return -ENOMEM;
     135                 :            :         }
     136                 :            : 
     137                 :          0 :         rte_memcpy(bp_info, (void *)&rte_dpaa_bpid_info[bpid],
     138                 :            :                    sizeof(struct dpaa_bp_info));
     139                 :          0 :         mp->pool_data = (void *)bp_info;
     140                 :          0 :         s_dpaa_bpid_allocated_flag[bpid].flags = params.flags;
     141                 :          0 :         s_dpaa_bpid_allocated_flag[bpid].used = true;
     142                 :            : 
     143                 :          0 :         DPAA_MEMPOOL_INFO("BMAN pool created for bpid =%d", bpid);
     144                 :          0 :         return 0;
     145                 :            : }
     146                 :            : 
     147                 :            : static void
     148                 :          0 : dpaa_mbuf_free_pool(struct rte_mempool *mp)
     149                 :            : {
     150                 :          0 :         struct dpaa_bp_info *bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
     151                 :            : 
     152                 :          0 :         MEMPOOL_INIT_FUNC_TRACE();
     153                 :            : 
     154         [ #  # ]:          0 :         if (bp_info) {
     155                 :          0 :                 bman_free_pool(bp_info->bp);
     156                 :          0 :                 DPAA_MEMPOOL_INFO("BMAN pool freed for bpid =%d",
     157                 :            :                                   bp_info->bpid);
     158         [ #  # ]:          0 :                 if (rte_dpaa_bpid_info != NULL) {
     159                 :          0 :                         rte_dpaa_bpid_info[bp_info->bpid].mp = NULL;
     160                 :          0 :                         rte_dpaa_bpid_info[bp_info->bpid].bp = NULL;
     161                 :            :                 }
     162                 :          0 :                 s_dpaa_bpid_allocated_flag[bp_info->bpid].used = false;
     163                 :          0 :                 rte_free(bp_info);
     164                 :          0 :                 mp->pool_data = NULL;
     165                 :            :         }
     166                 :            : 
     167                 :            :         /* rte_dpaa_bpid_info is left to process teardown: Rx queues still
     168                 :            :          * reference it via fq->bp_array.
     169                 :            :          */
     170                 :          0 : }
     171                 :            : 
     172                 :            : static int
     173                 :          0 : dpaa_mbuf_free_bulk(struct rte_mempool *pool,
     174                 :            :                     void *const *obj_table,
     175                 :            :                     unsigned int count)
     176                 :            : {
     177                 :          0 :         struct dpaa_bp_info *bp_info = DPAA_MEMPOOL_TO_POOL_INFO(pool);
     178                 :            :         int ret;
     179                 :            :         uint32_t n = 0, i, left;
     180                 :            :         uint64_t phys[DPAA_MBUF_MAX_ACQ_REL];
     181                 :            : 
     182                 :            :         DPAA_MEMPOOL_DPDEBUG("Request to free %d buffers in bpid = %d",
     183                 :            :                              count, bp_info->bpid);
     184                 :            : 
     185         [ #  # ]:          0 :         if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
     186                 :          0 :                 ret = rte_dpaa_portal_init((void *)0);
     187         [ #  # ]:          0 :                 if (ret) {
     188                 :          0 :                         DPAA_MEMPOOL_ERR("rte_dpaa_portal_init failed with ret: %d",
     189                 :            :                                          ret);
     190                 :          0 :                         return ret;
     191                 :            :                 }
     192                 :            :         }
     193                 :            : 
     194         [ #  # ]:          0 :         while (n < count) {
     195                 :            :                 /* Acquire is all-or-nothing, so we drain in 7s,
     196                 :            :                  * then the remainder.
     197                 :            :                  */
     198                 :          0 :                 if ((count - n) > DPAA_MBUF_MAX_ACQ_REL)
     199                 :            :                         left = DPAA_MBUF_MAX_ACQ_REL;
     200                 :            :                 else
     201                 :            :                         left = count - n;
     202                 :            : 
     203         [ #  # ]:          0 :                 for (i = 0; i < left; i++) {
     204         [ #  # ]:          0 :                         phys[i] = rte_mempool_virt2iova(obj_table[n]);
     205                 :          0 :                         phys[i] += bp_info->meta_data_size;
     206                 :          0 :                         n++;
     207                 :            :                 }
     208                 :          0 : release_again:
     209                 :          0 :                 ret = bman_release_fast(bp_info->bp, phys, left);
     210         [ #  # ]:          0 :                 if (unlikely(ret))
     211                 :          0 :                         goto release_again;
     212                 :            :         }
     213                 :            : 
     214                 :            :         DPAA_MEMPOOL_DPDEBUG("freed %d buffers in bpid =%d",
     215                 :            :                              n, bp_info->bpid);
     216                 :            : 
     217                 :            :         return 0;
     218                 :            : }
     219                 :            : 
     220                 :            : static int
     221                 :          0 : dpaa_mbuf_alloc_bulk(struct rte_mempool *pool,
     222                 :            :                      void **obj_table,
     223                 :            :                      unsigned int count)
     224                 :            : {
     225                 :            :         struct rte_mbuf **m = (struct rte_mbuf **)obj_table;
     226                 :            :         uint64_t bufs[DPAA_MBUF_MAX_ACQ_REL];
     227                 :            :         struct dpaa_bp_info *bp_info;
     228                 :            :         uint8_t *bufaddr;
     229                 :            :         int i, ret;
     230                 :            :         unsigned int n = 0;
     231                 :            : 
     232                 :          0 :         bp_info = DPAA_MEMPOOL_TO_POOL_INFO(pool);
     233                 :            : 
     234                 :            :         DPAA_MEMPOOL_DPDEBUG("Request to alloc %d buffers in bpid = %d",
     235                 :            :                              count, bp_info->bpid);
     236                 :            : 
     237         [ #  # ]:          0 :         if (unlikely(count >= (RTE_MEMPOOL_CACHE_MAX_SIZE * 2))) {
     238                 :          0 :                 DPAA_MEMPOOL_ERR("Unable to allocate requested (%u) buffers",
     239                 :            :                                  count);
     240                 :          0 :                 return -EINVAL;
     241                 :            :         }
     242                 :            : 
     243         [ #  # ]:          0 :         if (unlikely(!DPAA_PER_LCORE_PORTAL)) {
     244                 :          0 :                 ret = rte_dpaa_portal_init((void *)0);
     245         [ #  # ]:          0 :                 if (ret) {
     246                 :          0 :                         DPAA_MEMPOOL_ERR("rte_dpaa_portal_init failed with ret: %d",
     247                 :            :                                          ret);
     248                 :          0 :                         return ret;
     249                 :            :                 }
     250                 :            :         }
     251                 :            : 
     252         [ #  # ]:          0 :         while (n < count) {
     253                 :            :                 /* Acquire is all-or-nothing, so we drain in 7s,
     254                 :            :                  * then the remainder.
     255                 :            :                  */
     256         [ #  # ]:          0 :                 if ((count - n) > DPAA_MBUF_MAX_ACQ_REL) {
     257                 :          0 :                         ret = bman_acquire_fast(bp_info->bp, bufs,
     258                 :            :                                 DPAA_MBUF_MAX_ACQ_REL);
     259                 :            :                 } else {
     260                 :          0 :                         ret = bman_acquire_fast(bp_info->bp, bufs,
     261                 :          0 :                                 count - n);
     262                 :            :                 }
     263                 :            :                 /* In case of less than requested number of buffers available
     264                 :            :                  * in pool, qbman_swp_acquire returns 0
     265                 :            :                  */
     266         [ #  # ]:          0 :                 if (ret <= 0) {
     267                 :            :                         DPAA_MEMPOOL_DPDEBUG("Buffer acquire failed (%d)",
     268                 :            :                                              ret);
     269                 :            :                         /* The API expect the exact number of requested
     270                 :            :                          * buffers. Releasing all buffers allocated
     271                 :            :                          */
     272                 :          0 :                         dpaa_mbuf_free_bulk(pool, obj_table, n);
     273                 :          0 :                         return -ENOBUFS;
     274                 :            :                 }
     275                 :            :                 /* assigning mbuf from the acquired objects */
     276   [ #  #  #  # ]:          0 :                 for (i = 0; (i < ret) && bufs[i]; i++) {
     277                 :            :                         /* TODO-errata - observed that bufs may be null
     278                 :            :                          * i.e. first buffer is valid, remaining 6 buffers
     279                 :            :                          * may be null.
     280                 :            :                          */
     281                 :            :                         bufaddr = DPAA_MEMPOOL_PTOV(bp_info, bufs[i]);
     282                 :          0 :                         m[n] = (void *)(bufaddr - bp_info->meta_data_size);
     283                 :            :                         DPAA_MEMPOOL_DPDEBUG("Vaddr(%p), mbuf(%p) from BMAN",
     284                 :            :                                 bufaddr, m[n]);
     285                 :          0 :                         n++;
     286                 :            :                 }
     287                 :            :         }
     288                 :            : 
     289                 :            :         DPAA_MEMPOOL_DPDEBUG("Allocated %d buffers from bpid=%d",
     290                 :            :                              n, bp_info->bpid);
     291                 :            :         return 0;
     292                 :            : }
     293                 :            : 
     294                 :            : static unsigned int
     295                 :          0 : dpaa_mbuf_get_count(const struct rte_mempool *mp)
     296                 :            : {
     297                 :            :         struct dpaa_bp_info *bp_info;
     298                 :            : 
     299                 :          0 :         MEMPOOL_INIT_FUNC_TRACE();
     300                 :            : 
     301   [ #  #  #  # ]:          0 :         if (!mp || !mp->pool_data) {
     302                 :          0 :                 DPAA_MEMPOOL_ERR("Invalid mempool provided");
     303                 :          0 :                 return 0;
     304                 :            :         }
     305                 :            : 
     306                 :            :         bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
     307                 :            : 
     308                 :          0 :         return bman_query_free_buffers(bp_info->bp);
     309                 :            : }
     310                 :            : 
     311                 :            : static int
     312                 :            : dpaa_check_obj_bounds(char *obj, size_t pg_sz, size_t elt_sz)
     313                 :            : {
     314                 :          0 :         if (!pg_sz || elt_sz > pg_sz)
     315                 :            :                 return true;
     316                 :            : 
     317                 :          0 :         if (RTE_PTR_ALIGN(obj, pg_sz) !=
     318         [ #  # ]:          0 :                 RTE_PTR_ALIGN(obj + elt_sz - 1, pg_sz))
     319                 :            :                 return false;
     320                 :            :         return true;
     321                 :            : }
     322                 :            : 
     323                 :            : static void
     324                 :          0 : dpaa_adjust_obj_bounds(char *va, size_t *offset,
     325                 :            :         size_t pg_sz, size_t total, uint32_t flags)
     326                 :            : {
     327                 :          0 :         size_t off = *offset;
     328                 :            : 
     329         [ #  # ]:          0 :         if (dpaa_check_obj_bounds(va + off, pg_sz, total) == false) {
     330                 :          0 :                 off += RTE_PTR_ALIGN_CEIL(va + off, pg_sz) - (va + off);
     331         [ #  # ]:          0 :                 if (flags & RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)
     332                 :          0 :                         off += total - ((((size_t)va + off - 1) % total) + 1);
     333                 :            :         }
     334                 :            : 
     335                 :          0 :         *offset = off;
     336                 :          0 : }
     337                 :            : 
     338                 :            : static int
     339                 :          0 : dpaa_mbuf_ls1043a_errata_obj_adjust(uint8_t **pobj,
     340                 :            :         uint32_t header_size, size_t *poff, size_t data_room)
     341                 :            : {
     342                 :          0 :         uint8_t *obj = *pobj;
     343                 :          0 :         size_t off = *poff, buf_addr, end;
     344                 :            : 
     345                 :            :         if (RTE_PKTMBUF_HEADROOM % FMAN_ERRATA_BUF_START_ALIGN) {
     346                 :            :                 DPAA_MEMPOOL_ERR("RTE_PKTMBUF_HEADROOM(%d) NOT aligned to %d",
     347                 :            :                         RTE_PKTMBUF_HEADROOM,
     348                 :            :                         FMAN_ERRATA_BUF_START_ALIGN);
     349                 :            :                 return -1;
     350                 :            :         }
     351         [ #  # ]:          0 :         if (header_size % FMAN_ERRATA_BUF_START_ALIGN) {
     352                 :          0 :                 DPAA_MEMPOOL_ERR("Header size(%d) NOT aligned to %d",
     353                 :            :                         header_size,
     354                 :            :                         FMAN_ERRATA_BUF_START_ALIGN);
     355                 :          0 :                 return -1;
     356                 :            :         }
     357                 :            : 
     358                 :            :         /** All FMAN DMA start addresses (for example, BMAN buffer
     359                 :            :          * address, FD[address] + FD[offset]) are 16B aligned.
     360                 :            :          */
     361                 :          0 :         buf_addr = (size_t)obj + header_size;
     362         [ #  # ]:          0 :         while (!rte_is_aligned((void *)buf_addr,
     363                 :            :                 FMAN_ERRATA_BUF_START_ALIGN)) {
     364                 :          0 :                 off++;
     365                 :          0 :                 obj++;
     366                 :          0 :                 buf_addr = (size_t)obj + header_size;
     367                 :            :         }
     368                 :            : 
     369                 :            :         /** Frame buffers must not span a 4KB address boundary,
     370                 :            :          * unless the frame start address is 256 byte aligned.
     371                 :            :          */
     372                 :          0 :         end = buf_addr + data_room;
     373                 :          0 :         if (((buf_addr + RTE_PKTMBUF_HEADROOM) &
     374         [ #  # ]:          0 :                 FMAN_ERRATA_BOUNDARY_MASK) ==
     375                 :            :                 (end & FMAN_ERRATA_BOUNDARY_MASK))
     376                 :          0 :                 goto quit;
     377                 :            : 
     378         [ #  # ]:          0 :         while (!rte_is_aligned((void *)(buf_addr + RTE_PKTMBUF_HEADROOM),
     379                 :            :                 FMAN_ERRATA_4K_SPAN_ADDR_ALIGN)) {
     380                 :          0 :                 off++;
     381                 :          0 :                 obj++;
     382                 :          0 :                 buf_addr = (size_t)obj + header_size;
     383                 :            :         }
     384                 :          0 : quit:
     385                 :          0 :         *pobj = obj;
     386                 :          0 :         *poff = off;
     387                 :            : 
     388                 :          0 :         return 0;
     389                 :            : }
     390                 :            : 
     391                 :            : static int
     392                 :          0 : dpaa_mbuf_op_pop_helper(struct rte_mempool *mp, uint32_t flags,
     393                 :            :         uint32_t max_objs, void *vaddr, rte_iova_t iova,
     394                 :            :         size_t len, struct dpaa_bp_info *bp_info,
     395                 :            :         rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
     396                 :            : {
     397                 :            :         char *va = vaddr;
     398                 :            :         size_t total_elt_sz, pg_sz, off;
     399                 :            :         uint32_t i;
     400                 :            :         void *obj;
     401                 :            :         int ret;
     402                 :            :         uint16_t data_room = rte_pktmbuf_data_room_size(mp);
     403                 :            : 
     404                 :          0 :         ret = rte_mempool_get_page_size(mp, &pg_sz);
     405         [ #  # ]:          0 :         if (ret < 0)
     406                 :            :                 return ret;
     407                 :            : 
     408                 :          0 :         total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
     409                 :            : 
     410         [ #  # ]:          0 :         if (flags & RTE_MEMPOOL_POPULATE_F_ALIGN_OBJ)
     411                 :          0 :                 off = total_elt_sz - (((uintptr_t)(va - 1) % total_elt_sz) + 1);
     412                 :            :         else
     413                 :          0 :                 off = 0;
     414         [ #  # ]:          0 :         for (i = 0; i < max_objs; i++) {
     415                 :            :                 /* avoid objects to cross page boundaries */
     416                 :          0 :                 dpaa_adjust_obj_bounds(va, &off, pg_sz, total_elt_sz, flags);
     417         [ #  # ]:          0 :                 if (off + total_elt_sz > len)
     418                 :            :                         break;
     419                 :            : 
     420                 :          0 :                 off += mp->header_size;
     421                 :          0 :                 obj = va + off;
     422         [ #  # ]:          0 :                 if (dpaa_soc_ver() == SVR_LS1043A_FAMILY) {
     423                 :          0 :                         dpaa_mbuf_ls1043a_errata_obj_adjust((uint8_t **)&obj,
     424                 :            :                                 bp_info->meta_data_size, &off, data_room);
     425                 :            :                 }
     426         [ #  # ]:          0 :                 obj_cb(mp, obj_cb_arg, obj,
     427                 :          0 :                         (iova == RTE_BAD_IOVA) ? RTE_BAD_IOVA : (iova + off));
     428                 :            :                 rte_mempool_ops_enqueue_bulk(mp, &obj, 1);
     429                 :          0 :                 off += mp->elt_size + mp->trailer_size;
     430                 :            :         }
     431                 :            : 
     432                 :          0 :         return i;
     433                 :            : }
     434                 :            : 
     435                 :            : static int
     436                 :          0 : dpaa_populate(struct rte_mempool *mp, unsigned int max_objs,
     437                 :            :               void *vaddr, rte_iova_t paddr, size_t len,
     438                 :            :               rte_mempool_populate_obj_cb_t *obj_cb, void *obj_cb_arg)
     439                 :            : {
     440                 :            :         struct dpaa_bp_info *bp_info;
     441                 :            :         unsigned int total_elt_sz;
     442                 :            :         struct dpaa_memseg *ms;
     443                 :            : 
     444   [ #  #  #  # ]:          0 :         if (!mp || !mp->pool_data) {
     445                 :          0 :                 DPAA_MEMPOOL_ERR("Invalid mempool provided");
     446         [ #  # ]:          0 :                 if (dpaa_soc_ver() == SVR_LS1043A_FAMILY) {
     447                 :            :                         /** populate must be successful for LS1043A*/
     448                 :            :                         return -EINVAL;
     449                 :            :                 }
     450                 :          0 :                 return 0;
     451                 :            :         }
     452                 :            : 
     453                 :            :         /* Update the PA-VA Table */
     454                 :          0 :         dpaax_iova_table_update(paddr, vaddr, len);
     455                 :            : 
     456                 :          0 :         bp_info = DPAA_MEMPOOL_TO_POOL_INFO(mp);
     457                 :          0 :         total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
     458                 :            : 
     459                 :            :         DPAA_MEMPOOL_DPDEBUG("Req size %" PRIx64 " vs Available %u\n",
     460                 :            :                            (uint64_t)len, total_elt_sz * mp->size);
     461                 :            : 
     462                 :            :         /* Detect pool area has sufficient space for elements in this memzone */
     463         [ #  # ]:          0 :         if (len >= total_elt_sz * mp->size)
     464                 :          0 :                 bp_info->flags |= DPAA_MPOOL_SINGLE_SEGMENT;
     465                 :            : 
     466                 :            :         /* For each memory chunk pinned to the Mempool, a linked list of the
     467                 :            :          * contained memsegs is created for searching when PA to VA
     468                 :            :          * conversion is required.
     469                 :            :          */
     470                 :          0 :         ms = rte_zmalloc(NULL, sizeof(struct dpaa_memseg), 0);
     471         [ #  # ]:          0 :         if (!ms) {
     472                 :          0 :                 DPAA_MEMPOOL_ERR("Unable to allocate internal memory.");
     473                 :          0 :                 DPAA_MEMPOOL_WARN("Fast Physical to Virtual Addr translation would not be available.");
     474                 :            :                 /* If the element is not added, it would only lead to failure
     475                 :            :                  * in searching for the element and the logic would Fallback
     476                 :            :                  * to traditional DPDK memseg traversal code. So, this is not
     477                 :            :                  * a blocking error - but, error would be printed on screen.
     478                 :            :                  */
     479                 :          0 :                 return 0;
     480                 :            :         }
     481                 :            : 
     482                 :          0 :         ms->vaddr = vaddr;
     483                 :          0 :         ms->iova = paddr;
     484                 :          0 :         ms->len = len;
     485                 :            :         /* Head insertions are generally faster than tail insertions as the
     486                 :            :          * buffers pinned are picked from rear end.
     487                 :            :          */
     488         [ #  # ]:          0 :         TAILQ_INSERT_HEAD(&rte_dpaa_memsegs, ms, next);
     489                 :            : 
     490                 :          0 :         return dpaa_mbuf_op_pop_helper(mp, 0, max_objs, vaddr, paddr,
     491                 :            :                         len, bp_info, obj_cb, obj_cb_arg);
     492                 :            : }
     493                 :            : 
     494                 :            : static const struct rte_mempool_ops dpaa_mpool_ops = {
     495                 :            :         .name = DPAA_MEMPOOL_OPS_NAME,
     496                 :            :         .alloc = dpaa_mbuf_create_pool,
     497                 :            :         .free = dpaa_mbuf_free_pool,
     498                 :            :         .enqueue = dpaa_mbuf_free_bulk,
     499                 :            :         .dequeue = dpaa_mbuf_alloc_bulk,
     500                 :            :         .get_count = dpaa_mbuf_get_count,
     501                 :            :         .populate = dpaa_populate,
     502                 :            : };
     503                 :            : 
     504                 :            : /* RTE_FINI_PRIO() pastes this onto RTE_PRIORITY_; EAL only defines the
     505                 :            :  * named priorities, so declare the numeric one used below.
     506                 :            :  */
     507                 :            : #define RTE_PRIORITY_104 104
     508                 :            : 
     509                 :        306 : RTE_FINI_PRIO(dpaa_mpool_finish, 104)
     510                 :            : {
     511                 :            :         uint16_t bpid;
     512                 :            : 
     513         [ +  + ]:      78642 :         for (bpid = 0; bpid < DPAA_MAX_BPOOLS; bpid++) {
     514         [ -  + ]:      78336 :                 if (s_dpaa_bpid_allocated_flag[bpid].used) {
     515                 :          0 :                         bman_free_bpid(bpid, s_dpaa_bpid_allocated_flag[bpid].flags);
     516                 :          0 :                         s_dpaa_bpid_allocated_flag[bpid].used = false;
     517                 :            :                 }
     518                 :            :         }
     519                 :            : 
     520                 :        306 : }
     521                 :            : 
     522                 :        306 : RTE_MEMPOOL_REGISTER_OPS(dpaa_mpool_ops);

Generated by: LCOV version 1.14