LCOV - code coverage report
Current view: top level - drivers/net/nfp/nfpcore - nfp_mip.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 46 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 14 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Netronome Systems, Inc.
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "nfp_mip.h"
       7                 :            : 
       8                 :            : #include <rte_byteorder.h>
       9                 :            : 
      10                 :            : #include "nfp_logs.h"
      11                 :            : #include "nfp_nffw.h"
      12                 :            : 
      13                 :            : /* Read memory and check if it could be a valid MIP */
      14                 :            : static int
      15                 :          0 : nfp_mip_try_read(struct nfp_cpp *cpp,
      16                 :            :                 uint32_t cpp_id,
      17                 :            :                 uint64_t addr,
      18                 :            :                 struct nfp_mip *mip)
      19                 :            : {
      20                 :            :         int ret;
      21                 :            : 
      22                 :          0 :         ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip));
      23         [ #  # ]:          0 :         if (ret != sizeof(*mip)) {
      24                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to read MIP data");
      25                 :          0 :                 return -EIO;
      26                 :            :         }
      27                 :            : 
      28         [ #  # ]:          0 :         if (mip->signature != NFP_MIP_SIGNATURE) {
      29                 :          0 :                 PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x",
      30                 :            :                                 rte_le_to_cpu_32(mip->signature));
      31                 :          0 :                 return -EINVAL;
      32                 :            :         }
      33                 :            : 
      34         [ #  # ]:          0 :         if (mip->mip_version != NFP_MIP_VERSION) {
      35                 :          0 :                 PMD_DRV_LOG(ERR, "Unsupported MIP version %d",
      36                 :            :                                 rte_le_to_cpu_32(mip->mip_version));
      37                 :          0 :                 return -EINVAL;
      38                 :            :         }
      39                 :            : 
      40                 :            :         return 0;
      41                 :            : }
      42                 :            : 
      43                 :            : /* Try to locate MIP using the resource table */
      44                 :            : static int
      45                 :          0 : nfp_mip_read_resource(struct nfp_cpp *cpp,
      46                 :            :                 struct nfp_mip *mip)
      47                 :            : {
      48                 :            :         int err;
      49                 :            :         uint64_t addr;
      50                 :            :         uint32_t cpp_id;
      51                 :            :         struct nfp_nffw_info *nffw_info;
      52                 :            : 
      53                 :          0 :         nffw_info = nfp_nffw_info_open(cpp);
      54         [ #  # ]:          0 :         if (nffw_info == NULL)
      55                 :            :                 return -ENODEV;
      56                 :            : 
      57                 :          0 :         err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr);
      58         [ #  # ]:          0 :         if (err != 0)
      59                 :          0 :                 goto exit_close_nffw;
      60                 :            : 
      61                 :          0 :         err = nfp_mip_try_read(cpp, cpp_id, addr, mip);
      62                 :            : 
      63                 :          0 : exit_close_nffw:
      64                 :          0 :         nfp_nffw_info_close(nffw_info);
      65                 :          0 :         return err;
      66                 :            : }
      67                 :            : 
      68                 :            : /**
      69                 :            :  * Copy MIP structure from NFP device and return it. The returned
      70                 :            :  * structure is handled internally by the library and should be
      71                 :            :  * freed by calling @nfp_mip_close().
      72                 :            :  *
      73                 :            :  * @param cpp
      74                 :            :  *   NFP CPP Handle
      75                 :            :  *
      76                 :            :  * @return
      77                 :            :  *   Pointer to MIP, NULL on failure.
      78                 :            :  */
      79                 :            : struct nfp_mip *
      80                 :          0 : nfp_mip_open(struct nfp_cpp *cpp)
      81                 :            : {
      82                 :            :         int err;
      83                 :            :         struct nfp_mip *mip;
      84                 :            : 
      85                 :          0 :         mip = malloc(sizeof(*mip));
      86         [ #  # ]:          0 :         if (mip == NULL)
      87                 :            :                 return NULL;
      88                 :            : 
      89                 :          0 :         err = nfp_mip_read_resource(cpp, mip);
      90         [ #  # ]:          0 :         if (err != 0) {
      91                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to read MIP resource");
      92                 :          0 :                 free(mip);
      93                 :          0 :                 return NULL;
      94                 :            :         }
      95                 :            : 
      96                 :          0 :         mip->name[sizeof(mip->name) - 1] = 0;
      97                 :            : 
      98                 :          0 :         return mip;
      99                 :            : }
     100                 :            : 
     101                 :            : void
     102                 :          0 : nfp_mip_close(struct nfp_mip *mip)
     103                 :            : {
     104                 :          0 :         free(mip);
     105                 :          0 : }
     106                 :            : 
     107                 :            : const char *
     108                 :          0 : nfp_mip_name(const struct nfp_mip *mip)
     109                 :            : {
     110                 :          0 :         return mip->name;
     111                 :            : }
     112                 :            : 
     113                 :            : uint32_t
     114                 :          0 : nfp_mip_fw_version(const struct nfp_mip *mip)
     115                 :            : {
     116                 :          0 :         return rte_le_to_cpu_32(mip->version);
     117                 :            : }
     118                 :            : 
     119                 :            : /**
     120                 :            :  * Get the address and size of the MIP symbol table.
     121                 :            :  *
     122                 :            :  * @param mip
     123                 :            :  *   MIP handle
     124                 :            :  * @param addr
     125                 :            :  *   Location for NFP DDR address of MIP symbol table
     126                 :            :  * @param size
     127                 :            :  *   Location for size of MIP symbol table
     128                 :            :  */
     129                 :            : void
     130                 :          0 : nfp_mip_symtab(const struct nfp_mip *mip,
     131                 :            :                 uint32_t *addr,
     132                 :            :                 uint32_t *size)
     133                 :            : {
     134                 :          0 :         *addr = rte_le_to_cpu_32(mip->symtab_addr);
     135                 :          0 :         *size = rte_le_to_cpu_32(mip->symtab_size);
     136                 :          0 : }
     137                 :            : 
     138                 :            : /**
     139                 :            :  * Get the address and size of the MIP symbol name table.
     140                 :            :  *
     141                 :            :  * @param mip
     142                 :            :  *   MIP handle
     143                 :            :  * @param addr
     144                 :            :  *   Location for NFP DDR address of MIP symbol name table
     145                 :            :  * @param size
     146                 :            :  *   Location for size of MIP symbol name table
     147                 :            :  */
     148                 :            : void
     149                 :          0 : nfp_mip_strtab(const struct nfp_mip *mip,
     150                 :            :                 uint32_t *addr,
     151                 :            :                 uint32_t *size)
     152                 :            : {
     153                 :          0 :         *addr = rte_le_to_cpu_32(mip->strtab_addr);
     154                 :          0 :         *size = rte_le_to_cpu_32(mip->strtab_size);
     155                 :          0 : }

Generated by: LCOV version 1.14