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 44 0.0 %
Date: 2024-01-22 16:26:08 Functions: 0 7 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                 :            : #define NFP_MIP_SIGNATURE        rte_cpu_to_le_32(0x0050494d)  /* "MIP\0" */
      14                 :            : #define NFP_MIP_VERSION          rte_cpu_to_le_32(1)
      15                 :            : #define NFP_MIP_MAX_OFFSET       (256 * 1024)
      16                 :            : 
      17                 :            : struct nfp_mip {
      18                 :            :         uint32_t signature;
      19                 :            :         uint32_t mip_version;
      20                 :            :         uint32_t mip_size;
      21                 :            :         uint32_t first_entry;
      22                 :            : 
      23                 :            :         uint32_t version;
      24                 :            :         uint32_t buildnum;
      25                 :            :         uint32_t buildtime;
      26                 :            :         uint32_t loadtime;
      27                 :            : 
      28                 :            :         uint32_t symtab_addr;
      29                 :            :         uint32_t symtab_size;
      30                 :            :         uint32_t strtab_addr;
      31                 :            :         uint32_t strtab_size;
      32                 :            : 
      33                 :            :         char name[16];
      34                 :            :         char toolchain[32];
      35                 :            : };
      36                 :            : 
      37                 :            : /* Read memory and check if it could be a valid MIP */
      38                 :            : static int
      39                 :          0 : nfp_mip_try_read(struct nfp_cpp *cpp,
      40                 :            :                 uint32_t cpp_id,
      41                 :            :                 uint64_t addr,
      42                 :            :                 struct nfp_mip *mip)
      43                 :            : {
      44                 :            :         int ret;
      45                 :            : 
      46                 :          0 :         ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip));
      47         [ #  # ]:          0 :         if (ret != sizeof(*mip)) {
      48                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to read MIP data");
      49                 :          0 :                 return -EIO;
      50                 :            :         }
      51                 :            : 
      52         [ #  # ]:          0 :         if (mip->signature != NFP_MIP_SIGNATURE) {
      53                 :          0 :                 PMD_DRV_LOG(ERR, "Incorrect MIP signature %#08x",
      54                 :            :                                 rte_le_to_cpu_32(mip->signature));
      55                 :          0 :                 return -EINVAL;
      56                 :            :         }
      57                 :            : 
      58         [ #  # ]:          0 :         if (mip->mip_version != NFP_MIP_VERSION) {
      59                 :          0 :                 PMD_DRV_LOG(ERR, "Unsupported MIP version %d",
      60                 :            :                                 rte_le_to_cpu_32(mip->mip_version));
      61                 :          0 :                 return -EINVAL;
      62                 :            :         }
      63                 :            : 
      64                 :            :         return 0;
      65                 :            : }
      66                 :            : 
      67                 :            : /* Try to locate MIP using the resource table */
      68                 :            : static int
      69                 :          0 : nfp_mip_read_resource(struct nfp_cpp *cpp,
      70                 :            :                 struct nfp_mip *mip)
      71                 :            : {
      72                 :            :         int err;
      73                 :            :         uint64_t addr;
      74                 :            :         uint32_t cpp_id;
      75                 :            :         struct nfp_nffw_info *nffw_info;
      76                 :            : 
      77                 :          0 :         nffw_info = nfp_nffw_info_open(cpp);
      78         [ #  # ]:          0 :         if (nffw_info == NULL)
      79                 :            :                 return -ENODEV;
      80                 :            : 
      81                 :          0 :         err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr);
      82         [ #  # ]:          0 :         if (err != 0)
      83                 :          0 :                 goto exit_close_nffw;
      84                 :            : 
      85                 :          0 :         err = nfp_mip_try_read(cpp, cpp_id, addr, mip);
      86                 :            : 
      87                 :          0 : exit_close_nffw:
      88                 :          0 :         nfp_nffw_info_close(nffw_info);
      89                 :          0 :         return err;
      90                 :            : }
      91                 :            : 
      92                 :            : /**
      93                 :            :  * Copy MIP structure from NFP device and return it. The returned
      94                 :            :  * structure is handled internally by the library and should be
      95                 :            :  * freed by calling @nfp_mip_close().
      96                 :            :  *
      97                 :            :  * @param cpp
      98                 :            :  *   NFP CPP Handle
      99                 :            :  *
     100                 :            :  * @return
     101                 :            :  *   Pointer to MIP, NULL on failure.
     102                 :            :  */
     103                 :            : struct nfp_mip *
     104                 :          0 : nfp_mip_open(struct nfp_cpp *cpp)
     105                 :            : {
     106                 :            :         int err;
     107                 :            :         struct nfp_mip *mip;
     108                 :            : 
     109                 :          0 :         mip = malloc(sizeof(*mip));
     110         [ #  # ]:          0 :         if (mip == NULL)
     111                 :            :                 return NULL;
     112                 :            : 
     113                 :          0 :         err = nfp_mip_read_resource(cpp, mip);
     114         [ #  # ]:          0 :         if (err != 0) {
     115                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to read MIP resource");
     116                 :          0 :                 free(mip);
     117                 :          0 :                 return NULL;
     118                 :            :         }
     119                 :            : 
     120                 :          0 :         mip->name[sizeof(mip->name) - 1] = 0;
     121                 :            : 
     122                 :          0 :         return mip;
     123                 :            : }
     124                 :            : 
     125                 :            : void
     126                 :          0 : nfp_mip_close(struct nfp_mip *mip)
     127                 :            : {
     128                 :          0 :         free(mip);
     129                 :          0 : }
     130                 :            : 
     131                 :            : const char *
     132                 :          0 : nfp_mip_name(const struct nfp_mip *mip)
     133                 :            : {
     134                 :          0 :         return mip->name;
     135                 :            : }
     136                 :            : 
     137                 :            : /**
     138                 :            :  * Get the address and size of the MIP symbol table.
     139                 :            :  *
     140                 :            :  * @param mip
     141                 :            :  *   MIP handle
     142                 :            :  * @param addr
     143                 :            :  *   Location for NFP DDR address of MIP symbol table
     144                 :            :  * @param size
     145                 :            :  *   Location for size of MIP symbol table
     146                 :            :  */
     147                 :            : void
     148                 :          0 : nfp_mip_symtab(const struct nfp_mip *mip,
     149                 :            :                 uint32_t *addr,
     150                 :            :                 uint32_t *size)
     151                 :            : {
     152                 :          0 :         *addr = rte_le_to_cpu_32(mip->symtab_addr);
     153                 :          0 :         *size = rte_le_to_cpu_32(mip->symtab_size);
     154                 :          0 : }
     155                 :            : 
     156                 :            : /**
     157                 :            :  * Get the address and size of the MIP symbol name table.
     158                 :            :  *
     159                 :            :  * @param mip
     160                 :            :  *   MIP handle
     161                 :            :  * @param addr
     162                 :            :  *   Location for NFP DDR address of MIP symbol name table
     163                 :            :  * @param size
     164                 :            :  *   Location for size of MIP symbol name table
     165                 :            :  */
     166                 :            : void
     167                 :          0 : nfp_mip_strtab(const struct nfp_mip *mip,
     168                 :            :                 uint32_t *addr,
     169                 :            :                 uint32_t *size)
     170                 :            : {
     171                 :          0 :         *addr = rte_le_to_cpu_32(mip->strtab_addr);
     172                 :          0 :         *size = rte_le_to_cpu_32(mip->strtab_size);
     173                 :          0 : }

Generated by: LCOV version 1.14