1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Netronome Systems, Inc.
7 #include <rte_byteorder.h>
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)
37 /* Read memory and check if it could be a valid MIP */
39 nfp_mip_try_read(struct nfp_cpp *cpp, uint32_t cpp_id, uint64_t addr,
44 ret = nfp_cpp_read(cpp, cpp_id, addr, mip, sizeof(*mip));
45 if (ret != sizeof(*mip)) {
46 printf("Failed to read MIP data (%d, %zu)\n",
50 if (mip->signature != NFP_MIP_SIGNATURE) {
51 printf("Incorrect MIP signature (0x%08x)\n",
52 rte_le_to_cpu_32(mip->signature));
55 if (mip->mip_version != NFP_MIP_VERSION) {
56 printf("Unsupported MIP version (%d)\n",
57 rte_le_to_cpu_32(mip->mip_version));
64 /* Try to locate MIP using the resource table */
66 nfp_mip_read_resource(struct nfp_cpp *cpp, struct nfp_mip *mip)
68 struct nfp_nffw_info *nffw_info;
73 nffw_info = nfp_nffw_info_open(cpp);
77 err = nfp_nffw_info_mip_first(nffw_info, &cpp_id, &addr);
81 err = nfp_mip_try_read(cpp, cpp_id, addr, mip);
83 nfp_nffw_info_close(nffw_info);
88 * nfp_mip_open() - Get device MIP structure
89 * @cpp: NFP CPP Handle
91 * Copy MIP structure from NFP device and return it. The returned
92 * structure is handled internally by the library and should be
93 * freed by calling nfp_mip_close().
95 * Return: pointer to mip, NULL on failure.
98 nfp_mip_open(struct nfp_cpp *cpp)
103 mip = malloc(sizeof(*mip));
107 err = nfp_mip_read_resource(cpp, mip);
113 mip->name[sizeof(mip->name) - 1] = 0;
119 nfp_mip_close(struct nfp_mip *mip)
125 nfp_mip_name(const struct nfp_mip *mip)
131 * nfp_mip_symtab() - Get the address and size of the MIP symbol table
133 * @addr: Location for NFP DDR address of MIP symbol table
134 * @size: Location for size of MIP symbol table
137 nfp_mip_symtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size)
139 *addr = rte_le_to_cpu_32(mip->symtab_addr);
140 *size = rte_le_to_cpu_32(mip->symtab_size);
144 * nfp_mip_strtab() - Get the address and size of the MIP symbol name table
146 * @addr: Location for NFP DDR address of MIP symbol name table
147 * @size: Location for size of MIP symbol name table
150 nfp_mip_strtab(const struct nfp_mip *mip, uint32_t *addr, uint32_t *size)
152 *addr = rte_le_to_cpu_32(mip->strtab_addr);
153 *size = rte_le_to_cpu_32(mip->strtab_size);