LCOV - code coverage report
Current view: top level - drivers/net/bnxt/tf_core - tf_global_cfg.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 51 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 4 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 28 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2019-2023 Broadcom
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <rte_common.h>
       7                 :            : 
       8                 :            : #include "tf_global_cfg.h"
       9                 :            : #include "tf_common.h"
      10                 :            : #include "tf_util.h"
      11                 :            : #include "tf_msg.h"
      12                 :            : #include "tfp.h"
      13                 :            : 
      14                 :            : struct tf;
      15                 :            : 
      16                 :            : /**
      17                 :            :  * Global cfg database
      18                 :            :  */
      19                 :            : struct tf_global_cfg_db {
      20                 :            :         struct tf_global_cfg_cfg *global_cfg_db[TF_DIR_MAX];
      21                 :            : };
      22                 :            : 
      23                 :            : /**
      24                 :            :  * Get HCAPI type parameters for a single element
      25                 :            :  */
      26                 :            : struct tf_global_cfg_get_hcapi_parms {
      27                 :            :         /**
      28                 :            :          * [in] Global Cfg DB Handle
      29                 :            :          */
      30                 :            :         void *global_cfg_db;
      31                 :            :         /**
      32                 :            :          * [in] DB Index, indicates which DB entry to perform the
      33                 :            :          * action on.
      34                 :            :          */
      35                 :            :         uint16_t db_index;
      36                 :            :         /**
      37                 :            :          * [out] Pointer to the hcapi type for the specified db_index
      38                 :            :          */
      39                 :            :         uint16_t *hcapi_type;
      40                 :            : };
      41                 :            : 
      42                 :            : /**
      43                 :            :  * Check global_cfg_type and return hwrm type.
      44                 :            :  *
      45                 :            :  * [in] global_cfg_type
      46                 :            :  *   Global Cfg type
      47                 :            :  *
      48                 :            :  * [out] hwrm_type
      49                 :            :  *   HWRM device data type
      50                 :            :  *
      51                 :            :  * Returns:
      52                 :            :  *    0          - Success
      53                 :            :  *   -EOPNOTSUPP - Type not supported
      54                 :            :  */
      55                 :            : static int
      56                 :            : tf_global_cfg_get_hcapi_type(struct tf_global_cfg_get_hcapi_parms *parms)
      57                 :            : {
      58                 :            :         struct tf_global_cfg_cfg *global_cfg;
      59                 :            :         enum tf_global_cfg_cfg_type cfg_type;
      60                 :            : 
      61                 :            :         global_cfg = (struct tf_global_cfg_cfg *)parms->global_cfg_db;
      62                 :          0 :         cfg_type = global_cfg[parms->db_index].cfg_type;
      63                 :            : 
      64                 :          0 :         if (cfg_type != TF_GLOBAL_CFG_CFG_HCAPI)
      65                 :            :                 return -ENOTSUP;
      66                 :            : 
      67                 :          0 :         *parms->hcapi_type = global_cfg[parms->db_index].hcapi_type;
      68                 :            : 
      69                 :            :         return 0;
      70                 :            : }
      71                 :            : 
      72                 :            : int
      73                 :          0 : tf_global_cfg_bind(struct tf *tfp,
      74                 :            :                    struct tf_global_cfg_cfg_parms *parms)
      75                 :            : {
      76                 :            :         struct tfp_calloc_parms cparms;
      77                 :            :         struct tf_global_cfg_db *global_cfg_db;
      78                 :            : 
      79         [ #  # ]:          0 :         TF_CHECK_PARMS2(tfp, parms);
      80                 :            : 
      81                 :          0 :         cparms.nitems = 1;
      82                 :          0 :         cparms.size = sizeof(struct tf_global_cfg_db);
      83                 :          0 :         cparms.alignment = 0;
      84         [ #  # ]:          0 :         if (tfp_calloc(&cparms) != 0) {
      85                 :          0 :                 TFP_DRV_LOG(ERR, "global_rm_db alloc error %s\n",
      86                 :            :                             strerror(ENOMEM));
      87                 :          0 :                 return -ENOMEM;
      88                 :            :         }
      89                 :            : 
      90                 :          0 :         global_cfg_db = cparms.mem_va;
      91                 :          0 :         global_cfg_db->global_cfg_db[TF_DIR_RX] = parms->cfg;
      92                 :          0 :         global_cfg_db->global_cfg_db[TF_DIR_TX] = parms->cfg;
      93                 :          0 :         tf_session_set_global_db(tfp, (void *)global_cfg_db);
      94                 :            : 
      95                 :          0 :         TFP_DRV_LOG(INFO, "Global Cfg - initialized\n");
      96                 :          0 :         return 0;
      97                 :            : }
      98                 :            : 
      99                 :            : int
     100                 :          0 : tf_global_cfg_unbind(struct tf *tfp)
     101                 :            : {
     102                 :            :         int rc;
     103                 :            :         struct tf_global_cfg_db *global_cfg_db_ptr;
     104                 :            : 
     105         [ #  # ]:          0 :         TF_CHECK_PARMS1(tfp);
     106                 :            : 
     107                 :          0 :         rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
     108         [ #  # ]:          0 :         if (rc) {
     109                 :          0 :                 TFP_DRV_LOG(INFO, "global_cfg_db is not initialized\n");
     110                 :          0 :                 return 0;
     111                 :            :         }
     112                 :            : 
     113                 :          0 :         tfp_free((void *)global_cfg_db_ptr);
     114                 :          0 :         return 0;
     115                 :            : }
     116                 :            : 
     117                 :            : int
     118                 :          0 : tf_global_cfg_set(struct tf *tfp,
     119                 :            :                   struct tf_global_cfg_parms *parms)
     120                 :            : {
     121                 :            :         int rc;
     122                 :            :         struct tf_global_cfg_get_hcapi_parms hparms;
     123                 :            :         struct tf_global_cfg_db *global_cfg_db_ptr;
     124                 :            :         uint16_t hcapi_type;
     125                 :            : 
     126   [ #  #  #  # ]:          0 :         TF_CHECK_PARMS3(tfp, parms, parms->config);
     127                 :            : 
     128                 :          0 :         rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
     129         [ #  # ]:          0 :         if (rc) {
     130                 :          0 :                 TFP_DRV_LOG(INFO, "No global cfg DBs initialized\n");
     131                 :          0 :                 return 0;
     132                 :            :         }
     133                 :            : 
     134                 :            :         /* Convert TF type to HCAPI type */
     135                 :          0 :         hparms.global_cfg_db = global_cfg_db_ptr->global_cfg_db[parms->dir];
     136         [ #  # ]:          0 :         hparms.db_index = parms->type;
     137                 :            :         hparms.hcapi_type = &hcapi_type;
     138                 :            :         rc = tf_global_cfg_get_hcapi_type(&hparms);
     139                 :            :         if (rc) {
     140                 :          0 :                 TFP_DRV_LOG(ERR,
     141                 :            :                             "%s, Failed type lookup, type:%d, rc:%s\n",
     142                 :            :                             tf_dir_2_str(parms->dir),
     143                 :            :                             parms->type,
     144                 :            :                             strerror(-rc));
     145                 :          0 :                 return rc;
     146                 :            :         }
     147                 :            : 
     148                 :          0 :         rc = tf_msg_set_global_cfg(tfp, parms);
     149         [ #  # ]:          0 :         if (rc) {
     150                 :          0 :                 TFP_DRV_LOG(ERR,
     151                 :            :                             "%s, Set failed, type:%d, rc:%s\n",
     152                 :            :                             tf_dir_2_str(parms->dir),
     153                 :            :                             parms->type,
     154                 :            :                             strerror(-rc));
     155                 :            :         }
     156                 :            : 
     157                 :            :         return 0;
     158                 :            : }
     159                 :            : 
     160                 :            : int
     161                 :          0 : tf_global_cfg_get(struct tf *tfp,
     162                 :            :                   struct tf_global_cfg_parms *parms)
     163                 :            : 
     164                 :            : {
     165                 :            :         int rc;
     166                 :            :         struct tf_global_cfg_get_hcapi_parms hparms;
     167                 :            :         struct tf_global_cfg_db *global_cfg_db_ptr;
     168                 :            :         uint16_t hcapi_type;
     169                 :            : 
     170   [ #  #  #  # ]:          0 :         TF_CHECK_PARMS3(tfp, parms, parms->config);
     171                 :            : 
     172                 :          0 :         rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
     173         [ #  # ]:          0 :         if (rc) {
     174                 :          0 :                 TFP_DRV_LOG(INFO, "No Global cfg DBs initialized\n");
     175                 :          0 :                 return 0;
     176                 :            :         }
     177                 :            : 
     178                 :            :         /* Convert TF type to HCAPI type */
     179                 :          0 :         hparms.global_cfg_db = global_cfg_db_ptr->global_cfg_db[parms->dir];
     180         [ #  # ]:          0 :         hparms.db_index = parms->type;
     181                 :            :         hparms.hcapi_type = &hcapi_type;
     182                 :            :         rc = tf_global_cfg_get_hcapi_type(&hparms);
     183                 :            :         if (rc) {
     184                 :          0 :                 TFP_DRV_LOG(ERR,
     185                 :            :                             "%s, Failed type lookup, type:%d, rc:%s\n",
     186                 :            :                             tf_dir_2_str(parms->dir),
     187                 :            :                             parms->type,
     188                 :            :                             strerror(-rc));
     189                 :          0 :                 return rc;
     190                 :            :         }
     191                 :            : 
     192                 :            :         /* Get the entry */
     193                 :          0 :         rc = tf_msg_get_global_cfg(tfp, parms);
     194         [ #  # ]:          0 :         if (rc) {
     195                 :          0 :                 TFP_DRV_LOG(ERR,
     196                 :            :                             "%s, Get failed, type:%d, rc:%s\n",
     197                 :            :                             tf_dir_2_str(parms->dir),
     198                 :            :                             parms->type,
     199                 :            :                             strerror(-rc));
     200                 :            :         }
     201                 :            : 
     202                 :            :         return 0;
     203                 :            : }

Generated by: LCOV version 1.14