LCOV - code coverage report
Current view: top level - drivers/bus/fslmc/portal - dpaa2_hw_dpbp.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 35 2.9 %
Date: 2024-01-22 15:35:40 Functions: 1 5 20.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 20 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *
       3                 :            :  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
       4                 :            :  *   Copyright 2016 NXP
       5                 :            :  *
       6                 :            :  */
       7                 :            : 
       8                 :            : #include <unistd.h>
       9                 :            : #include <stdio.h>
      10                 :            : #include <sys/types.h>
      11                 :            : #include <string.h>
      12                 :            : #include <stdlib.h>
      13                 :            : #include <fcntl.h>
      14                 :            : #include <errno.h>
      15                 :            : 
      16                 :            : #include <rte_malloc.h>
      17                 :            : #include <rte_memcpy.h>
      18                 :            : #include <rte_string_fns.h>
      19                 :            : #include <rte_cycles.h>
      20                 :            : #include <rte_kvargs.h>
      21                 :            : #include <dev_driver.h>
      22                 :            : #include <ethdev_driver.h>
      23                 :            : #include <rte_mbuf_pool_ops.h>
      24                 :            : 
      25                 :            : #include <fslmc_logs.h>
      26                 :            : #include <bus_fslmc_driver.h>
      27                 :            : #include <mc/fsl_dpbp.h>
      28                 :            : #include "portal/dpaa2_hw_pvt.h"
      29                 :            : #include "portal/dpaa2_hw_dpio.h"
      30                 :            : 
      31                 :            : 
      32                 :            : TAILQ_HEAD(dpbp_dev_list, dpaa2_dpbp_dev);
      33                 :            : static struct dpbp_dev_list dpbp_dev_list
      34                 :            :         = TAILQ_HEAD_INITIALIZER(dpbp_dev_list); /*!< DPBP device list */
      35                 :            : 
      36                 :            : static int
      37                 :          0 : dpaa2_create_dpbp_device(int vdev_fd __rte_unused,
      38                 :            :                          struct vfio_device_info *obj_info __rte_unused,
      39                 :            :                          int dpbp_id)
      40                 :            : {
      41                 :            :         struct dpaa2_dpbp_dev *dpbp_node;
      42                 :            :         int ret;
      43                 :            :         static int register_once;
      44                 :            : 
      45                 :            :         /* Allocate DPAA2 dpbp handle */
      46                 :          0 :         dpbp_node = rte_malloc(NULL, sizeof(struct dpaa2_dpbp_dev), 0);
      47         [ #  # ]:          0 :         if (!dpbp_node) {
      48                 :          0 :                 DPAA2_BUS_ERR("Memory allocation failed for DPBP Device");
      49                 :          0 :                 return -1;
      50                 :            :         }
      51                 :            : 
      52                 :            :         /* Open the dpbp object */
      53                 :          0 :         dpbp_node->dpbp.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
      54                 :          0 :         ret = dpbp_open(&dpbp_node->dpbp,
      55                 :            :                         CMD_PRI_LOW, dpbp_id, &dpbp_node->token);
      56         [ #  # ]:          0 :         if (ret) {
      57                 :          0 :                 DPAA2_BUS_ERR("Unable to open buffer pool object: err(%d)",
      58                 :            :                               ret);
      59                 :          0 :                 rte_free(dpbp_node);
      60                 :          0 :                 return -1;
      61                 :            :         }
      62                 :            : 
      63                 :            :         /* Clean the device first */
      64                 :          0 :         ret = dpbp_reset(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
      65         [ #  # ]:          0 :         if (ret) {
      66                 :          0 :                 DPAA2_BUS_ERR("Unable to reset buffer pool device. err(%d)",
      67                 :            :                               ret);
      68                 :          0 :                 dpbp_close(&dpbp_node->dpbp, CMD_PRI_LOW, dpbp_node->token);
      69                 :          0 :                 rte_free(dpbp_node);
      70                 :          0 :                 return -1;
      71                 :            :         }
      72                 :            : 
      73         [ #  # ]:          0 :         dpbp_node->dpbp_id = dpbp_id;
      74                 :            :         rte_atomic16_init(&dpbp_node->in_use);
      75                 :            : 
      76                 :          0 :         TAILQ_INSERT_TAIL(&dpbp_dev_list, dpbp_node, next);
      77                 :            : 
      78         [ #  # ]:          0 :         if (!register_once) {
      79                 :          0 :                 rte_mbuf_set_platform_mempool_ops(DPAA2_MEMPOOL_OPS_NAME);
      80                 :          0 :                 register_once = 1;
      81                 :            :         }
      82                 :            : 
      83                 :            :         return 0;
      84                 :            : }
      85                 :            : 
      86                 :          0 : struct dpaa2_dpbp_dev *dpaa2_alloc_dpbp_dev(void)
      87                 :            : {
      88                 :            :         struct dpaa2_dpbp_dev *dpbp_dev = NULL;
      89                 :            : 
      90                 :            :         /* Get DPBP dev handle from list using index */
      91         [ #  # ]:          0 :         TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
      92         [ #  # ]:          0 :                 if (dpbp_dev && rte_atomic16_test_and_set(&dpbp_dev->in_use))
      93                 :            :                         break;
      94                 :            :         }
      95                 :            : 
      96                 :          0 :         return dpbp_dev;
      97                 :            : }
      98                 :            : 
      99                 :          0 : void dpaa2_free_dpbp_dev(struct dpaa2_dpbp_dev *dpbp)
     100                 :            : {
     101                 :            :         struct dpaa2_dpbp_dev *dpbp_dev = NULL;
     102                 :            : 
     103                 :            :         /* Match DPBP handle and mark it free */
     104         [ #  # ]:          0 :         TAILQ_FOREACH(dpbp_dev, &dpbp_dev_list, next) {
     105         [ #  # ]:          0 :                 if (dpbp_dev == dpbp) {
     106                 :          0 :                         rte_atomic16_dec(&dpbp_dev->in_use);
     107                 :          0 :                         return;
     108                 :            :                 }
     109                 :            :         }
     110                 :            : }
     111                 :            : 
     112                 :          0 : int dpaa2_dpbp_supported(void)
     113                 :            : {
     114         [ #  # ]:          0 :         if (TAILQ_EMPTY(&dpbp_dev_list))
     115                 :          0 :                 return -1;
     116                 :            :         return 0;
     117                 :            : }
     118                 :            : 
     119                 :            : static struct rte_dpaa2_object rte_dpaa2_dpbp_obj = {
     120                 :            :         .dev_type = DPAA2_BPOOL,
     121                 :            :         .create = dpaa2_create_dpbp_device,
     122                 :            : };
     123                 :            : 
     124                 :        235 : RTE_PMD_REGISTER_DPAA2_OBJECT(dpbp, rte_dpaa2_dpbp_obj);

Generated by: LCOV version 1.14