Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 2 | /* |
Yogesh Gaur | 1a0c4ae | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 4 | * Copyright 2017-2018 NXP |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 5 | */ |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 10 | #include <errno.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Masahiro Yamada | 78eeb91 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 12 | #include <linux/bug.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 14 | #include <linux/libfdt.h> |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 15 | #include <net.h> |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 16 | #include <fdt_support.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 17 | #include <fsl-mc/fsl_mc.h> |
| 18 | #include <fsl-mc/fsl_mc_sys.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 19 | #include <fsl-mc/fsl_mc_private.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 20 | #include <fsl-mc/fsl_dpmng.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 21 | #include <fsl-mc/fsl_dprc.h> |
| 22 | #include <fsl-mc/fsl_dpio.h> |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 23 | #include <fsl-mc/fsl_dpni.h> |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 24 | #include <fsl-mc/fsl_dpsparser.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 25 | #include <fsl-mc/fsl_qbman_portal.h> |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 26 | #include <fsl-mc/ldpaa_wriop.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 27 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 28 | #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024) |
| 29 | #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1)) |
| 30 | #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024) |
| 31 | |
| 32 | #define MC_MEM_SIZE_ENV_VAR "mcmemsize" |
| 33 | #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout" |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 34 | #define MC_BOOT_ENV_VAR "mcinitcmd" |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 35 | #define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 36 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 37 | DECLARE_GLOBAL_DATA_PTR; |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 38 | static int mc_memset_resv_ram; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 39 | static struct mc_version mc_ver_info; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 40 | static int mc_boot_status = -1; |
| 41 | static int mc_dpl_applied = -1; |
| 42 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 43 | static int mc_aiop_applied = -1; |
| 44 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 45 | struct fsl_mc_io *root_mc_io = NULL; |
| 46 | struct fsl_mc_io *dflt_mc_io = NULL; /* child container */ |
| 47 | uint16_t root_dprc_handle = 0; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 48 | uint16_t dflt_dprc_handle = 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 49 | int child_dprc_id; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 50 | struct fsl_dpbp_obj *dflt_dpbp = NULL; |
| 51 | struct fsl_dpio_obj *dflt_dpio = NULL; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 52 | struct fsl_dpni_obj *dflt_dpni = NULL; |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 53 | static u64 mc_lazy_dpl_addr; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 54 | static u32 dpsparser_obj_id; |
| 55 | static u16 dpsparser_handle; |
| 56 | static char *mc_err_msg_apply_spb[] = MC_ERROR_MSG_APPLY_SPB; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 57 | |
| 58 | #ifdef DEBUG |
| 59 | void dump_ram_words(const char *title, void *addr) |
| 60 | { |
| 61 | int i; |
| 62 | uint32_t *words = addr; |
| 63 | |
| 64 | printf("Dumping beginning of %s (%p):\n", title, addr); |
| 65 | for (i = 0; i < 16; i++) |
| 66 | printf("%#x ", words[i]); |
| 67 | |
| 68 | printf("\n"); |
| 69 | } |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 70 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 71 | void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs) |
| 72 | { |
| 73 | printf("MC CCSR registers:\n" |
| 74 | "reg_gcr1 %#x\n" |
| 75 | "reg_gsr %#x\n" |
| 76 | "reg_sicbalr %#x\n" |
| 77 | "reg_sicbahr %#x\n" |
| 78 | "reg_sicapr %#x\n" |
| 79 | "reg_mcfbalr %#x\n" |
| 80 | "reg_mcfbahr %#x\n" |
| 81 | "reg_mcfapr %#x\n" |
| 82 | "reg_psr %#x\n", |
| 83 | mc_ccsr_regs->reg_gcr1, |
| 84 | mc_ccsr_regs->reg_gsr, |
| 85 | mc_ccsr_regs->reg_sicbalr, |
| 86 | mc_ccsr_regs->reg_sicbahr, |
| 87 | mc_ccsr_regs->reg_sicapr, |
| 88 | mc_ccsr_regs->reg_mcfbalr, |
| 89 | mc_ccsr_regs->reg_mcfbahr, |
| 90 | mc_ccsr_regs->reg_mcfapr, |
| 91 | mc_ccsr_regs->reg_psr); |
| 92 | } |
| 93 | #else |
| 94 | |
| 95 | #define dump_ram_words(title, addr) |
| 96 | #define dump_mc_ccsr_regs(mc_ccsr_regs) |
| 97 | |
| 98 | #endif /* DEBUG */ |
| 99 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Copying MC firmware or DPL image to DDR |
| 102 | */ |
| 103 | static int mc_copy_image(const char *title, |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 104 | u64 image_addr, u32 image_size, u64 mc_ram_addr) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 105 | { |
| 106 | debug("%s copied to address %p\n", title, (void *)mc_ram_addr); |
| 107 | memcpy((void *)mc_ram_addr, (void *)image_addr, image_size); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 108 | flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 112 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 113 | /** |
| 114 | * MC firmware FIT image parser checks if the image is in FIT |
| 115 | * format, verifies integrity of the image and calculates |
| 116 | * raw image address and size values. |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 117 | * Returns 0 on success and a negative errno on error. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 118 | * task fail. |
| 119 | **/ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 120 | int parse_mc_firmware_fit_image(u64 mc_fw_addr, |
| 121 | const void **raw_image_addr, |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 122 | size_t *raw_image_size) |
| 123 | { |
| 124 | int format; |
| 125 | void *fit_hdr; |
| 126 | int node_offset; |
| 127 | const void *data; |
| 128 | size_t size; |
| 129 | const char *uname = "firmware"; |
| 130 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 131 | fit_hdr = (void *)mc_fw_addr; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 132 | |
| 133 | /* Check if Image is in FIT format */ |
| 134 | format = genimg_get_format(fit_hdr); |
| 135 | |
| 136 | if (format != IMAGE_FORMAT_FIT) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 137 | printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 138 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | if (!fit_check_format(fit_hdr)) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 142 | printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 143 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | node_offset = fit_image_get_node(fit_hdr, uname); |
| 147 | |
| 148 | if (node_offset < 0) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 149 | printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 150 | return -ENOENT; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* Verify MC firmware image */ |
| 154 | if (!(fit_image_verify(fit_hdr, node_offset))) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 155 | printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 156 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* Get address and size of raw image */ |
| 160 | fit_image_get_data(fit_hdr, node_offset, &data, &size); |
| 161 | |
| 162 | *raw_image_addr = data; |
| 163 | *raw_image_size = size; |
| 164 | |
| 165 | return 0; |
| 166 | } |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 167 | #endif |
| 168 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 169 | #define MC_DT_INCREASE_SIZE 64 |
| 170 | |
| 171 | enum mc_fixup_type { |
| 172 | MC_FIXUP_DPL, |
| 173 | MC_FIXUP_DPC |
| 174 | }; |
| 175 | |
| 176 | static int mc_fixup_mac_addr(void *blob, int nodeoffset, |
| 177 | const char *propname, struct eth_device *eth_dev, |
| 178 | enum mc_fixup_type type) |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 179 | { |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 180 | int err = 0, len = 0, size, i; |
| 181 | unsigned char env_enetaddr[ARP_HLEN]; |
| 182 | unsigned int enetaddr_32[ARP_HLEN]; |
| 183 | void *val = NULL; |
| 184 | |
| 185 | switch (type) { |
| 186 | case MC_FIXUP_DPL: |
| 187 | /* DPL likes its addresses on 32 * ARP_HLEN bits */ |
| 188 | for (i = 0; i < ARP_HLEN; i++) |
| 189 | enetaddr_32[i] = cpu_to_fdt32(eth_dev->enetaddr[i]); |
| 190 | val = enetaddr_32; |
| 191 | len = sizeof(enetaddr_32); |
| 192 | break; |
| 193 | |
| 194 | case MC_FIXUP_DPC: |
| 195 | val = eth_dev->enetaddr; |
| 196 | len = ARP_HLEN; |
| 197 | break; |
| 198 | } |
| 199 | |
| 200 | /* MAC address property present */ |
| 201 | if (fdt_get_property(blob, nodeoffset, propname, NULL)) { |
| 202 | /* u-boot MAC addr randomly assigned - leave the present one */ |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 203 | if (!eth_env_get_enetaddr_by_index("eth", eth_dev->index, |
| 204 | env_enetaddr)) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 205 | return err; |
| 206 | } else { |
| 207 | size = MC_DT_INCREASE_SIZE + strlen(propname) + len; |
| 208 | /* make room for mac address property */ |
| 209 | err = fdt_increase_size(blob, size); |
| 210 | if (err) { |
| 211 | printf("fdt_increase_size: err=%s\n", |
| 212 | fdt_strerror(err)); |
| 213 | return err; |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | err = fdt_setprop(blob, nodeoffset, propname, val, len); |
| 218 | if (err) { |
| 219 | printf("fdt_setprop: err=%s\n", fdt_strerror(err)); |
| 220 | return err; |
| 221 | } |
| 222 | |
| 223 | return err; |
| 224 | } |
| 225 | |
| 226 | #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0) |
| 227 | |
| 228 | const char *dpl_get_connection_endpoint(void *blob, char *endpoint) |
| 229 | { |
| 230 | int connoffset = fdt_path_offset(blob, "/connections"), off; |
| 231 | const char *s1, *s2; |
| 232 | |
| 233 | for (off = fdt_first_subnode(blob, connoffset); |
| 234 | off >= 0; |
| 235 | off = fdt_next_subnode(blob, off)) { |
| 236 | s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL); |
| 237 | s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL); |
| 238 | |
| 239 | if (!s1 || !s2) |
| 240 | continue; |
| 241 | |
| 242 | if (strcmp(endpoint, s1) == 0) |
| 243 | return s2; |
| 244 | |
| 245 | if (strcmp(endpoint, s2) == 0) |
| 246 | return s1; |
| 247 | } |
| 248 | |
| 249 | return NULL; |
| 250 | } |
| 251 | |
| 252 | static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id, |
| 253 | struct eth_device *eth_dev) |
| 254 | { |
| 255 | int objoff = fdt_path_offset(blob, "/objects"); |
| 256 | int dpmacoff = -1, dpnioff = -1; |
| 257 | const char *endpoint; |
| 258 | char mac_name[10]; |
| 259 | int err; |
| 260 | |
| 261 | sprintf(mac_name, "dpmac@%d", dpmac_id); |
| 262 | dpmacoff = fdt_subnode_offset(blob, objoff, mac_name); |
| 263 | if (dpmacoff < 0) |
| 264 | /* dpmac not defined in DPL, so skip it. */ |
| 265 | return 0; |
| 266 | |
| 267 | err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev, |
| 268 | MC_FIXUP_DPL); |
| 269 | if (err) { |
| 270 | printf("Error fixing up dpmac mac_addr in DPL\n"); |
| 271 | return err; |
| 272 | } |
| 273 | |
| 274 | /* now we need to figure out if there is any |
| 275 | * DPNI connected to this MAC, so we walk the |
| 276 | * connection list |
| 277 | */ |
| 278 | endpoint = dpl_get_connection_endpoint(blob, mac_name); |
| 279 | if (!is_dpni(endpoint)) |
| 280 | return 0; |
| 281 | |
| 282 | /* let's see if we can fixup the DPNI as well */ |
| 283 | dpnioff = fdt_subnode_offset(blob, objoff, endpoint); |
| 284 | if (dpnioff < 0) |
| 285 | /* DPNI not defined in DPL in the objects area */ |
| 286 | return 0; |
| 287 | |
| 288 | return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev, |
| 289 | MC_FIXUP_DPL); |
| 290 | } |
| 291 | |
Meenakshi Aggarwal | d67ae48 | 2019-05-23 15:13:43 +0530 | [diff] [blame] | 292 | void fdt_fixup_mc_ddr(u64 *base, u64 *size) |
| 293 | { |
| 294 | u64 mc_size = mc_get_dram_block_size(); |
| 295 | |
| 296 | if (mc_size < MC_DRAM_BLOCK_DEFAULT_SIZE) { |
| 297 | *base = mc_get_dram_addr() + mc_size; |
| 298 | *size = MC_DRAM_BLOCK_DEFAULT_SIZE - mc_size; |
| 299 | } |
| 300 | } |
| 301 | |
Nipun Gupta | d691264 | 2018-08-20 16:01:14 +0530 | [diff] [blame] | 302 | void fdt_fsl_mc_fixup_iommu_map_entry(void *blob) |
| 303 | { |
| 304 | u32 *prop; |
| 305 | u32 iommu_map[4]; |
| 306 | int offset; |
| 307 | int lenp; |
| 308 | |
| 309 | /* find fsl-mc node */ |
| 310 | offset = fdt_path_offset(blob, "/soc/fsl-mc"); |
| 311 | if (offset < 0) |
| 312 | offset = fdt_path_offset(blob, "/fsl-mc"); |
| 313 | if (offset < 0) { |
| 314 | printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n", |
| 315 | __func__, offset); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp); |
| 320 | if (!prop) { |
| 321 | debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n", |
| 322 | __func__); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START); |
| 327 | iommu_map[1] = *++prop; |
| 328 | iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START); |
| 329 | iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END - |
| 330 | FSL_DPAA2_STREAM_ID_START + 1); |
| 331 | |
| 332 | fdt_setprop_inplace(blob, offset, "iommu-map", |
| 333 | iommu_map, sizeof(iommu_map)); |
| 334 | } |
| 335 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 336 | static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id, |
| 337 | struct eth_device *eth_dev) |
| 338 | { |
| 339 | int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff; |
| 340 | int err = 0; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 341 | char mac_name[10]; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 342 | const char link_type_mode[] = "MAC_LINK_TYPE_FIXED"; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 343 | |
| 344 | sprintf(mac_name, "mac@%d", dpmac_id); |
| 345 | |
| 346 | /* node not found - create it */ |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 347 | noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name); |
| 348 | if (noff < 0) { |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 349 | err = fdt_increase_size(blob, 200); |
| 350 | if (err) { |
| 351 | printf("fdt_increase_size: err=%s\n", |
| 352 | fdt_strerror(err)); |
| 353 | return err; |
| 354 | } |
| 355 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 356 | noff = fdt_add_subnode(blob, nodeoffset, mac_name); |
| 357 | if (noff < 0) { |
| 358 | printf("fdt_add_subnode: err=%s\n", |
| 359 | fdt_strerror(err)); |
| 360 | return err; |
| 361 | } |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 362 | |
| 363 | /* add default property of fixed link */ |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 364 | err = fdt_appendprop_string(blob, noff, |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 365 | "link_type", link_type_mode); |
| 366 | if (err) { |
| 367 | printf("fdt_appendprop_string: err=%s\n", |
| 368 | fdt_strerror(err)); |
| 369 | return err; |
| 370 | } |
| 371 | } |
| 372 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 373 | return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev, |
| 374 | MC_FIXUP_DPC); |
| 375 | } |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 376 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 377 | static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type) |
| 378 | { |
| 379 | int i, err = 0, ret = 0; |
Pankaj Bansal | 8a92170 | 2018-08-02 16:31:28 +0530 | [diff] [blame] | 380 | char ethname[ETH_NAME_LEN]; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 381 | struct eth_device *eth_dev; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 382 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 383 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { |
| 384 | /* port not enabled */ |
Pankaj Bansal | 7987ab7 | 2018-10-10 14:08:33 +0530 | [diff] [blame] | 385 | if (wriop_is_enabled_dpmac(i) != 1) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 386 | continue; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 387 | |
Pankaj Bansal | 8a92170 | 2018-08-02 16:31:28 +0530 | [diff] [blame] | 388 | snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i, |
| 389 | phy_interface_strings[wriop_get_enet_if(i)]); |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 390 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 391 | eth_dev = eth_get_dev_by_name(ethname); |
| 392 | if (eth_dev == NULL) |
| 393 | continue; |
| 394 | |
| 395 | switch (type) { |
| 396 | case MC_FIXUP_DPL: |
| 397 | err = mc_fixup_dpl_mac_addr(blob, i, eth_dev); |
| 398 | break; |
| 399 | case MC_FIXUP_DPC: |
| 400 | err = mc_fixup_dpc_mac_addr(blob, i, eth_dev); |
| 401 | break; |
| 402 | default: |
| 403 | break; |
| 404 | } |
| 405 | |
| 406 | if (err) |
| 407 | printf("fsl-mc: ERROR fixing mac address for %s\n", |
| 408 | ethname); |
| 409 | ret |= err; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 410 | } |
| 411 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 412 | return ret; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 415 | static int mc_fixup_dpc(u64 dpc_addr) |
| 416 | { |
| 417 | void *blob = (void *)dpc_addr; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 418 | int nodeoffset, err = 0; |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 419 | |
| 420 | /* delete any existing ICID pools */ |
| 421 | nodeoffset = fdt_path_offset(blob, "/resources/icid_pools"); |
| 422 | if (fdt_del_node(blob, nodeoffset) < 0) |
| 423 | printf("\nfsl-mc: WARNING: could not delete ICID pool\n"); |
| 424 | |
| 425 | /* add a new pool */ |
| 426 | nodeoffset = fdt_path_offset(blob, "/resources"); |
| 427 | if (nodeoffset < 0) { |
| 428 | printf("\nfsl-mc: ERROR: DPC is missing /resources\n"); |
| 429 | return -EINVAL; |
| 430 | } |
| 431 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools"); |
| 432 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0"); |
| 433 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 434 | "base_icid", FSL_DPAA2_STREAM_ID_START, 1); |
| 435 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 436 | "num", |
| 437 | FSL_DPAA2_STREAM_ID_END - |
| 438 | FSL_DPAA2_STREAM_ID_START + 1, 1); |
| 439 | |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 440 | /* fixup MAC addresses for dpmac ports */ |
| 441 | nodeoffset = fdt_path_offset(blob, "/board_info/ports"); |
| 442 | if (nodeoffset < 0) |
Ioana Ciocoi Radulescu | d7697f4 | 2019-02-26 15:50:07 +0000 | [diff] [blame] | 443 | goto out; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 444 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 445 | err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC); |
Ioana Ciocoi Radulescu | d7697f4 | 2019-02-26 15:50:07 +0000 | [diff] [blame] | 446 | |
| 447 | out: |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 448 | flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob)); |
| 449 | |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 450 | return err; |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 451 | } |
| 452 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 453 | static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 454 | { |
| 455 | u64 mc_dpc_offset; |
| 456 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 457 | int error; |
| 458 | void *dpc_fdt_hdr; |
| 459 | int dpc_size; |
| 460 | #endif |
| 461 | |
| 462 | #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET |
| 463 | BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 || |
| 464 | CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff); |
| 465 | |
| 466 | mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET; |
| 467 | #else |
| 468 | #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined" |
| 469 | #endif |
| 470 | |
| 471 | /* |
| 472 | * Load the MC DPC blob in the MC private DRAM block: |
| 473 | */ |
| 474 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 475 | printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset); |
| 476 | #else |
| 477 | /* |
| 478 | * Get address and size of the DPC blob stored in flash: |
| 479 | */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 480 | dpc_fdt_hdr = (void *)mc_dpc_addr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 481 | |
| 482 | error = fdt_check_header(dpc_fdt_hdr); |
| 483 | if (error != 0) { |
| 484 | /* |
| 485 | * Don't return with error here, since the MC firmware can |
| 486 | * still boot without a DPC |
| 487 | */ |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 488 | printf("\nfsl-mc: WARNING: No DPC image found"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | dpc_size = fdt_totalsize(dpc_fdt_hdr); |
| 493 | if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 494 | printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n", |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 495 | dpc_size); |
| 496 | return -EINVAL; |
| 497 | } |
| 498 | |
| 499 | mc_copy_image("MC DPC blob", |
| 500 | (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset); |
| 501 | #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */ |
| 502 | |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 503 | if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset)) |
| 504 | return -EINVAL; |
| 505 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 506 | dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset)); |
| 507 | return 0; |
| 508 | } |
| 509 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 510 | |
| 511 | static int mc_fixup_dpl(u64 dpl_addr) |
| 512 | { |
| 513 | void *blob = (void *)dpl_addr; |
| 514 | u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0); |
| 515 | int err = 0; |
| 516 | |
| 517 | /* The DPL fixup for mac addresses is only relevant |
| 518 | * for old-style DPLs |
| 519 | */ |
| 520 | if (ver >= 10) |
| 521 | return 0; |
| 522 | |
| 523 | err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL); |
| 524 | flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob)); |
| 525 | |
| 526 | return err; |
| 527 | } |
| 528 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 529 | static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 530 | { |
| 531 | u64 mc_dpl_offset; |
| 532 | #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 533 | int error; |
| 534 | void *dpl_fdt_hdr; |
| 535 | int dpl_size; |
| 536 | #endif |
| 537 | |
| 538 | #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET |
| 539 | BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 || |
| 540 | CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff); |
| 541 | |
| 542 | mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET; |
| 543 | #else |
| 544 | #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined" |
| 545 | #endif |
| 546 | |
| 547 | /* |
| 548 | * Load the MC DPL blob in the MC private DRAM block: |
| 549 | */ |
| 550 | #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 551 | printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset); |
| 552 | #else |
| 553 | /* |
| 554 | * Get address and size of the DPL blob stored in flash: |
| 555 | */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 556 | dpl_fdt_hdr = (void *)mc_dpl_addr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 557 | |
| 558 | error = fdt_check_header(dpl_fdt_hdr); |
| 559 | if (error != 0) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 560 | printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 561 | return error; |
| 562 | } |
| 563 | |
| 564 | dpl_size = fdt_totalsize(dpl_fdt_hdr); |
| 565 | if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 566 | printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n", |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 567 | dpl_size); |
| 568 | return -EINVAL; |
| 569 | } |
| 570 | |
| 571 | mc_copy_image("MC DPL blob", |
| 572 | (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset); |
| 573 | #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */ |
| 574 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 575 | if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset)) |
| 576 | return -EINVAL; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 577 | dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset)); |
| 578 | return 0; |
| 579 | } |
| 580 | |
| 581 | /** |
| 582 | * Return the MC boot timeout value in milliseconds |
| 583 | */ |
| 584 | static unsigned long get_mc_boot_timeout_ms(void) |
| 585 | { |
| 586 | unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
| 587 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 588 | char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 589 | |
| 590 | if (timeout_ms_env_var) { |
| 591 | timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10); |
| 592 | if (timeout_ms == 0) { |
| 593 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 594 | MC_BOOT_TIMEOUT_ENV_VAR |
| 595 | "\' environment variable: %lu\n", |
| 596 | timeout_ms); |
| 597 | |
| 598 | timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | return timeout_ms; |
| 603 | } |
| 604 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 605 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 606 | |
| 607 | __weak bool soc_has_aiop(void) |
| 608 | { |
| 609 | return false; |
| 610 | } |
| 611 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 612 | static int load_mc_aiop_img(u64 aiop_fw_addr) |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 613 | { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 614 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 615 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 616 | void *aiop_img; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 617 | #endif |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 618 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 619 | /* Check if AIOP is available */ |
| 620 | if (!soc_has_aiop()) |
| 621 | return -ENODEV; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 622 | /* |
| 623 | * Load the MC AIOP image in the MC private DRAM block: |
| 624 | */ |
| 625 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 626 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 627 | printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr + |
| 628 | CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
| 629 | #else |
| 630 | aiop_img = (void *)aiop_fw_addr; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 631 | mc_copy_image("MC AIOP image", |
| 632 | (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH, |
| 633 | mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 634 | #endif |
| 635 | mc_aiop_applied = 0; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | #endif |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 640 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 641 | static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr) |
| 642 | { |
| 643 | u32 reg_gsr; |
| 644 | u32 mc_fw_boot_status; |
| 645 | unsigned long timeout_ms = get_mc_boot_timeout_ms(); |
| 646 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 647 | |
| 648 | dmb(); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 649 | assert(timeout_ms > 0); |
| 650 | for (;;) { |
| 651 | udelay(1000); /* throttle polling */ |
| 652 | reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr); |
| 653 | mc_fw_boot_status = (reg_gsr & GSR_FS_MASK); |
| 654 | if (mc_fw_boot_status & 0x1) |
| 655 | break; |
| 656 | |
| 657 | timeout_ms--; |
| 658 | if (timeout_ms == 0) |
| 659 | break; |
| 660 | } |
| 661 | |
| 662 | if (timeout_ms == 0) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 663 | printf("ERROR: timeout\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 664 | |
| 665 | /* TODO: Get an error status from an MC CCSR register */ |
| 666 | return -ETIMEDOUT; |
| 667 | } |
| 668 | |
| 669 | if (mc_fw_boot_status != 0x1) { |
| 670 | /* |
| 671 | * TODO: Identify critical errors from the GSR register's FS |
| 672 | * field and for those errors, set error to -ENODEV or other |
| 673 | * appropriate errno, so that the status property is set to |
| 674 | * failure in the fsl,dprc device tree node. |
| 675 | */ |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 676 | printf("WARNING: Firmware returned an error (GSR: %#x)\n", |
| 677 | reg_gsr); |
| 678 | } else { |
| 679 | printf("SUCCESS\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 680 | } |
| 681 | |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 682 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 683 | *final_reg_gsr = reg_gsr; |
| 684 | return 0; |
| 685 | } |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 686 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 687 | int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 688 | { |
| 689 | int error = 0; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 690 | int portal_id = 0; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 691 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 692 | u64 mc_ram_addr = mc_get_dram_addr(); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 693 | u32 reg_gsr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 694 | u32 reg_mcfbalr; |
| 695 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 696 | const void *raw_image_addr; |
| 697 | size_t raw_image_size = 0; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 698 | #endif |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 699 | u8 mc_ram_num_256mb_blocks; |
| 700 | size_t mc_ram_size = mc_get_dram_block_size(); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 701 | |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 702 | mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT; |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 703 | |
| 704 | if (mc_ram_num_256mb_blocks >= 0xff) { |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 705 | error = -EINVAL; |
| 706 | printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n", |
| 707 | mc_ram_size); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 708 | goto out; |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 709 | } |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 710 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 711 | /* |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 712 | * To support 128 MB DDR Size for MC |
| 713 | */ |
| 714 | if (mc_ram_num_256mb_blocks == 0) |
| 715 | mc_ram_num_256mb_blocks = 0xFF; |
| 716 | |
| 717 | /* |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 718 | * Management Complex cores should be held at reset out of POR. |
Bin Meng | 7557405 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 719 | * U-Boot should be the first software to touch MC. To be safe, |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 720 | * we reset all cores again by setting GCR1 to 0. It doesn't do |
| 721 | * anything if they are held at reset. After we setup the firmware |
| 722 | * we kick off MC by deasserting the reset bit for core 0, and |
| 723 | * deasserting the reset bits for Command Portal Managers. |
| 724 | * The stop bits are not touched here. They are used to stop the |
| 725 | * cores when they are active. Setting stop bits doesn't stop the |
| 726 | * cores from fetching instructions when they are released from |
| 727 | * reset. |
| 728 | */ |
| 729 | out_le32(&mc_ccsr_regs->reg_gcr1, 0); |
| 730 | dmb(); |
| 731 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 732 | #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR |
| 733 | printf("MC firmware is preloaded to %#llx\n", mc_ram_addr); |
| 734 | #else |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 735 | error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr, |
| 736 | &raw_image_size); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 737 | if (error != 0) |
| 738 | goto out; |
| 739 | /* |
| 740 | * Load the MC FW at the beginning of the MC private DRAM block: |
| 741 | */ |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 742 | mc_copy_image("MC Firmware", |
| 743 | (u64)raw_image_addr, raw_image_size, mc_ram_addr); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 744 | #endif |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 745 | dump_ram_words("firmware", (void *)mc_ram_addr); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 746 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 747 | error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 748 | if (error != 0) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 749 | goto out; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 750 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 751 | debug("mc_ccsr_regs %p\n", mc_ccsr_regs); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 752 | dump_mc_ccsr_regs(mc_ccsr_regs); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 753 | |
| 754 | /* |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 755 | * Tell MC what is the address range of the DRAM block assigned to it: |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 756 | */ |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 757 | if (mc_ram_num_256mb_blocks < 0xFF) { |
| 758 | reg_mcfbalr = (u32)mc_ram_addr | |
| 759 | (mc_ram_num_256mb_blocks - 1); |
| 760 | } else { |
| 761 | reg_mcfbalr = (u32)mc_ram_addr | |
| 762 | (mc_ram_num_256mb_blocks); |
| 763 | } |
| 764 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 765 | out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr); |
| 766 | out_le32(&mc_ccsr_regs->reg_mcfbahr, |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 767 | (u32)(mc_ram_addr >> 32)); |
Stuart Yoder | d197035 | 2015-07-02 11:29:02 +0530 | [diff] [blame] | 768 | out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 769 | |
| 770 | /* |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 771 | * Tell the MC that we want delayed DPL deployment. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 772 | */ |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 773 | out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 774 | |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 775 | printf("\nfsl-mc: Booting Management Complex ... "); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 776 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 777 | /* |
| 778 | * Deassert reset and release MC core 0 to run |
| 779 | */ |
| 780 | out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 781 | error = wait_for_mc(true, ®_gsr); |
| 782 | if (error != 0) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 783 | goto out; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 784 | |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 785 | /* |
| 786 | * TODO: need to obtain the portal_id for the root container from the |
| 787 | * DPL |
| 788 | */ |
| 789 | portal_id = 0; |
| 790 | |
| 791 | /* |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 792 | * Initialize the global default MC portal |
| 793 | * And check that the MC firmware is responding portal commands: |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 794 | */ |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 795 | root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 796 | if (!root_mc_io) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 797 | printf(" No memory: calloc() failed\n"); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 798 | return -ENOMEM; |
| 799 | } |
| 800 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 801 | root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 802 | debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n", |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 803 | portal_id, root_mc_io->mmio_regs); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 804 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 805 | error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 806 | if (error != 0) { |
| 807 | printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n", |
| 808 | error); |
| 809 | goto out; |
| 810 | } |
| 811 | |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 812 | printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n", |
| 813 | mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision, |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 814 | reg_gsr & GSR_FS_MASK); |
| 815 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 816 | out: |
| 817 | if (error != 0) |
| 818 | mc_boot_status = error; |
| 819 | else |
| 820 | mc_boot_status = 0; |
| 821 | |
| 822 | return error; |
| 823 | } |
| 824 | |
| 825 | int mc_apply_dpl(u64 mc_dpl_addr) |
| 826 | { |
| 827 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 828 | int error = 0; |
| 829 | u32 reg_gsr; |
| 830 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 831 | size_t mc_ram_size = mc_get_dram_block_size(); |
| 832 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 833 | if (!mc_dpl_addr) |
| 834 | return -1; |
| 835 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 836 | error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr); |
| 837 | if (error != 0) |
| 838 | return error; |
| 839 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 840 | /* |
| 841 | * Tell the MC to deploy the DPL: |
| 842 | */ |
| 843 | out_le32(&mc_ccsr_regs->reg_gsr, 0x0); |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 844 | printf("fsl-mc: Deploying data path layout ... "); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 845 | error = wait_for_mc(false, ®_gsr); |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 846 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 847 | if (!error) |
| 848 | mc_dpl_applied = 0; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 849 | |
| 850 | return error; |
| 851 | } |
| 852 | |
| 853 | int get_mc_boot_status(void) |
| 854 | { |
| 855 | return mc_boot_status; |
| 856 | } |
| 857 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 858 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 859 | int get_aiop_apply_status(void) |
| 860 | { |
| 861 | return mc_aiop_applied; |
| 862 | } |
| 863 | #endif |
| 864 | |
| 865 | int get_dpl_apply_status(void) |
| 866 | { |
| 867 | return mc_dpl_applied; |
| 868 | } |
| 869 | |
Mian Yousaf Kaukab | 9712465 | 2018-12-18 14:01:17 +0100 | [diff] [blame] | 870 | int is_lazy_dpl_addr_valid(void) |
| 871 | { |
| 872 | return !!mc_lazy_dpl_addr; |
| 873 | } |
| 874 | |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 875 | /* |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 876 | * Return the MC address of private DRAM block. |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 877 | * As per MC design document, MC initial base address |
| 878 | * should be least significant 512MB address of MC private |
| 879 | * memory, i.e. address should point to end address masked |
| 880 | * with 512MB offset in private DRAM block. |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 881 | */ |
| 882 | u64 mc_get_dram_addr(void) |
| 883 | { |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 884 | size_t mc_ram_size = mc_get_dram_block_size(); |
| 885 | |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 886 | if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) { |
| 887 | mc_memset_resv_ram = 1; |
| 888 | memset((void *)gd->arch.resv_ram, 0, mc_ram_size); |
| 889 | } |
| 890 | |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 891 | return (gd->arch.resv_ram + mc_ram_size - 1) & |
| 892 | MC_RAM_BASE_ADDR_ALIGNMENT_MASK; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | /** |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 896 | * Return the actual size of the MC private DRAM block. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 897 | */ |
| 898 | unsigned long mc_get_dram_block_size(void) |
| 899 | { |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 900 | unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE; |
| 901 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 902 | char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 903 | |
| 904 | if (dram_block_size_env_var) { |
| 905 | dram_block_size = simple_strtoul(dram_block_size_env_var, NULL, |
Prabhakar Kushwaha | b166d6a | 2017-11-09 14:45:41 +0530 | [diff] [blame] | 906 | 16); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 907 | |
| 908 | if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) { |
| 909 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 910 | MC_MEM_SIZE_ENV_VAR |
| 911 | "\' environment variable: %lu\n", |
| 912 | dram_block_size); |
| 913 | |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 914 | dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 915 | } |
| 916 | } |
| 917 | |
| 918 | return dram_block_size; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 919 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 920 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 921 | int fsl_mc_ldpaa_init(bd_t *bis) |
| 922 | { |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 923 | int i; |
| 924 | |
| 925 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) |
Pankaj Bansal | 7987ab7 | 2018-10-10 14:08:33 +0530 | [diff] [blame] | 926 | if (wriop_is_enabled_dpmac(i) == 1) |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 927 | ldpaa_eth_init(i, wriop_get_enet_if(i)); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 928 | return 0; |
| 929 | } |
| 930 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 931 | static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle) |
| 932 | { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 933 | int error; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 934 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 935 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 936 | error = dprc_get_api_version(mc_io, 0, |
| 937 | &major_ver, |
| 938 | &minor_ver); |
| 939 | if (error < 0) { |
| 940 | printf("dprc_get_api_version() failed: %d\n", error); |
| 941 | return error; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 942 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 943 | |
| 944 | if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR && |
| 945 | minor_ver < DPRC_VER_MINOR)) { |
| 946 | printf("DPRC version mismatch found %u.%u,", |
| 947 | major_ver, minor_ver); |
| 948 | printf("supported version is %u.%u\n", |
| 949 | DPRC_VER_MAJOR, DPRC_VER_MINOR); |
| 950 | } |
| 951 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 952 | return error; |
| 953 | } |
| 954 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 955 | static int dpio_init(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 956 | { |
| 957 | struct qbman_swp_desc p_des; |
| 958 | struct dpio_attr attr; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 959 | struct dpio_cfg dpio_cfg; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 960 | int err = 0; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 961 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 962 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 963 | dflt_dpio = (struct fsl_dpio_obj *)calloc( |
| 964 | sizeof(struct fsl_dpio_obj), 1); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 965 | if (!dflt_dpio) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 966 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 967 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 968 | goto err_calloc; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 969 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 970 | dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL; |
| 971 | dpio_cfg.num_priorities = 8; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 972 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 973 | err = dpio_create(dflt_mc_io, |
| 974 | dflt_dprc_handle, |
| 975 | MC_CMD_NO_FLAGS, |
| 976 | &dpio_cfg, |
| 977 | &dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 978 | if (err < 0) { |
| 979 | printf("dpio_create() failed: %d\n", err); |
| 980 | err = -ENODEV; |
| 981 | goto err_create; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 984 | err = dpio_get_api_version(dflt_mc_io, 0, |
| 985 | &major_ver, |
| 986 | &minor_ver); |
| 987 | if (err < 0) { |
| 988 | printf("dpio_get_api_version() failed: %d\n", err); |
| 989 | goto err_get_api_ver; |
| 990 | } |
| 991 | |
| 992 | if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR && |
| 993 | minor_ver < DPIO_VER_MINOR)) { |
| 994 | printf("DPRC version mismatch found %u.%u,", |
| 995 | major_ver, |
| 996 | minor_ver); |
| 997 | } |
| 998 | |
| 999 | err = dpio_open(dflt_mc_io, |
| 1000 | MC_CMD_NO_FLAGS, |
| 1001 | dflt_dpio->dpio_id, |
| 1002 | &dflt_dpio->dpio_handle); |
| 1003 | if (err) { |
| 1004 | printf("dpio_open() failed\n"); |
| 1005 | goto err_open; |
| 1006 | } |
| 1007 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1008 | memset(&attr, 0, sizeof(struct dpio_attr)); |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 1009 | err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1010 | dflt_dpio->dpio_handle, &attr); |
| 1011 | if (err < 0) { |
| 1012 | printf("dpio_get_attributes() failed: %d\n", err); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1013 | goto err_get_attr; |
| 1014 | } |
| 1015 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1016 | if (dflt_dpio->dpio_id != attr.id) { |
| 1017 | printf("dnpi object id and attribute id are not same\n"); |
| 1018 | goto err_attr_not_same; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1019 | } |
| 1020 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1021 | #ifdef DEBUG |
| 1022 | printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id); |
| 1023 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1024 | err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1025 | if (err < 0) { |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1026 | printf("dpio_enable() failed %d\n", err); |
| 1027 | goto err_get_enable; |
| 1028 | } |
Prabhakar Kushwaha | fd5d127 | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 1029 | debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n", |
| 1030 | attr.qbman_portal_ce_offset, |
| 1031 | attr.qbman_portal_ci_offset, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1032 | attr.qbman_portal_id, |
| 1033 | attr.num_priorities); |
| 1034 | |
Prabhakar Kushwaha | fd5d127 | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 1035 | p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 1036 | + attr.qbman_portal_ce_offset); |
| 1037 | p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 1038 | + attr.qbman_portal_ci_offset); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1039 | |
| 1040 | dflt_dpio->sw_portal = qbman_swp_init(&p_des); |
| 1041 | if (dflt_dpio->sw_portal == NULL) { |
| 1042 | printf("qbman_swp_init() failed\n"); |
| 1043 | goto err_get_swp_init; |
| 1044 | } |
| 1045 | return 0; |
| 1046 | |
| 1047 | err_get_swp_init: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1048 | dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1049 | err_get_enable: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1050 | err_get_attr: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1051 | err_attr_not_same: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1052 | dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1053 | err_open: |
| 1054 | err_get_api_ver: |
| 1055 | dpio_destroy(dflt_mc_io, |
| 1056 | dflt_dprc_handle, |
| 1057 | MC_CMD_NO_FLAGS, |
| 1058 | dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1059 | err_create: |
Prabhakar Kushwaha | c6018bd | 2016-03-18 16:15:29 +0530 | [diff] [blame] | 1060 | free(dflt_dpio); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1061 | err_calloc: |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1062 | return err; |
| 1063 | } |
| 1064 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1065 | static int dpio_exit(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1066 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1067 | int err; |
| 1068 | |
| 1069 | err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1070 | if (err < 0) { |
| 1071 | printf("dpio_disable() failed: %d\n", err); |
| 1072 | goto err; |
| 1073 | } |
| 1074 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1075 | dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1076 | if (err < 0) { |
| 1077 | printf("dpio_close() failed: %d\n", err); |
| 1078 | goto err; |
| 1079 | } |
| 1080 | |
| 1081 | err = dpio_destroy(dflt_mc_io, |
| 1082 | dflt_dprc_handle, |
| 1083 | MC_CMD_NO_FLAGS, |
| 1084 | dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1085 | if (err < 0) { |
| 1086 | printf("dpio_destroy() failed: %d\n", err); |
| 1087 | goto err; |
| 1088 | } |
| 1089 | |
| 1090 | #ifdef DEBUG |
| 1091 | printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id); |
| 1092 | #endif |
| 1093 | |
| 1094 | if (dflt_dpio) |
| 1095 | free(dflt_dpio); |
| 1096 | |
| 1097 | return 0; |
| 1098 | err: |
| 1099 | return err; |
| 1100 | } |
| 1101 | |
| 1102 | static int dprc_init(void) |
| 1103 | { |
| 1104 | int err, child_portal_id, container_id; |
| 1105 | struct dprc_cfg cfg; |
| 1106 | uint64_t mc_portal_offset; |
| 1107 | |
| 1108 | /* Open root container */ |
| 1109 | err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id); |
| 1110 | if (err < 0) { |
| 1111 | printf("dprc_get_container_id(): Root failed: %d\n", err); |
| 1112 | goto err_root_container_id; |
| 1113 | } |
| 1114 | |
| 1115 | #ifdef DEBUG |
| 1116 | printf("Root container id = %d\n", container_id); |
| 1117 | #endif |
| 1118 | err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id, |
| 1119 | &root_dprc_handle); |
| 1120 | if (err < 0) { |
| 1121 | printf("dprc_open(): Root Container failed: %d\n", err); |
| 1122 | goto err_root_open; |
| 1123 | } |
| 1124 | |
| 1125 | if (!root_dprc_handle) { |
| 1126 | printf("dprc_open(): Root Container Handle is not valid\n"); |
| 1127 | goto err_root_open; |
| 1128 | } |
| 1129 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1130 | err = dprc_version_check(root_mc_io, root_dprc_handle); |
| 1131 | if (err < 0) { |
| 1132 | printf("dprc_version_check() failed: %d\n", err); |
| 1133 | goto err_root_open; |
| 1134 | } |
| 1135 | |
Prabhakar Kushwaha | 901a88e | 2016-01-20 12:04:19 +0530 | [diff] [blame] | 1136 | memset(&cfg, 0, sizeof(struct dprc_cfg)); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1137 | cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED | |
| 1138 | DPRC_CFG_OPT_OBJ_CREATE_ALLOWED | |
| 1139 | DPRC_CFG_OPT_ALLOC_ALLOWED; |
| 1140 | cfg.icid = DPRC_GET_ICID_FROM_POOL; |
Prabhakar Kushwaha | 7fd59d9 | 2015-12-24 15:33:49 +0530 | [diff] [blame] | 1141 | cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1142 | err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1143 | root_dprc_handle, |
| 1144 | &cfg, |
| 1145 | &child_dprc_id, |
| 1146 | &mc_portal_offset); |
| 1147 | if (err < 0) { |
| 1148 | printf("dprc_create_container() failed: %d\n", err); |
| 1149 | goto err_create; |
| 1150 | } |
| 1151 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1152 | dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1153 | if (!dflt_mc_io) { |
| 1154 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1155 | printf(" No memory: calloc() failed\n"); |
| 1156 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset); |
| 1160 | dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1161 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1162 | #ifdef DEBUG |
| 1163 | printf("MC portal of child DPRC container: %d, physical addr %p)\n", |
| 1164 | child_dprc_id, dflt_mc_io->mmio_regs); |
| 1165 | #endif |
| 1166 | |
| 1167 | err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id, |
| 1168 | &dflt_dprc_handle); |
| 1169 | if (err < 0) { |
| 1170 | printf("dprc_open(): Child container failed: %d\n", err); |
| 1171 | goto err_child_open; |
| 1172 | } |
| 1173 | |
| 1174 | if (!dflt_dprc_handle) { |
| 1175 | printf("dprc_open(): Child container Handle is not valid\n"); |
| 1176 | goto err_child_open; |
| 1177 | } |
| 1178 | |
| 1179 | return 0; |
| 1180 | err_child_open: |
| 1181 | free(dflt_mc_io); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1182 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1183 | dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1184 | root_dprc_handle, child_dprc_id); |
| 1185 | err_create: |
| 1186 | dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 1187 | err_root_open: |
| 1188 | err_root_container_id: |
| 1189 | return err; |
| 1190 | } |
| 1191 | |
| 1192 | static int dprc_exit(void) |
| 1193 | { |
| 1194 | int err; |
| 1195 | |
| 1196 | err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle); |
| 1197 | if (err < 0) { |
| 1198 | printf("dprc_close(): Child failed: %d\n", err); |
| 1199 | goto err; |
| 1200 | } |
| 1201 | |
| 1202 | err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1203 | root_dprc_handle, child_dprc_id); |
| 1204 | if (err < 0) { |
| 1205 | printf("dprc_destroy_container() failed: %d\n", err); |
| 1206 | goto err; |
| 1207 | } |
| 1208 | |
| 1209 | err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 1210 | if (err < 0) { |
| 1211 | printf("dprc_close(): Root failed: %d\n", err); |
| 1212 | goto err; |
| 1213 | } |
| 1214 | |
| 1215 | if (dflt_mc_io) |
| 1216 | free(dflt_mc_io); |
| 1217 | |
| 1218 | if (root_mc_io) |
| 1219 | free(root_mc_io); |
| 1220 | |
| 1221 | return 0; |
| 1222 | |
| 1223 | err: |
| 1224 | return err; |
| 1225 | } |
| 1226 | |
| 1227 | static int dpbp_init(void) |
| 1228 | { |
| 1229 | int err; |
| 1230 | struct dpbp_attr dpbp_attr; |
| 1231 | struct dpbp_cfg dpbp_cfg; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1232 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1233 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1234 | dflt_dpbp = (struct fsl_dpbp_obj *)calloc( |
| 1235 | sizeof(struct fsl_dpbp_obj), 1); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1236 | if (!dflt_dpbp) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1237 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1238 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1239 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | dpbp_cfg.options = 512; |
| 1243 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1244 | err = dpbp_create(dflt_mc_io, |
| 1245 | dflt_dprc_handle, |
| 1246 | MC_CMD_NO_FLAGS, |
| 1247 | &dpbp_cfg, |
| 1248 | &dflt_dpbp->dpbp_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1249 | |
| 1250 | if (err < 0) { |
| 1251 | err = -ENODEV; |
| 1252 | printf("dpbp_create() failed: %d\n", err); |
| 1253 | goto err_create; |
| 1254 | } |
| 1255 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1256 | err = dpbp_get_api_version(dflt_mc_io, 0, |
| 1257 | &major_ver, |
| 1258 | &minor_ver); |
| 1259 | if (err < 0) { |
| 1260 | printf("dpbp_get_api_version() failed: %d\n", err); |
| 1261 | goto err_get_api_ver; |
| 1262 | } |
| 1263 | |
| 1264 | if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR && |
| 1265 | minor_ver < DPBP_VER_MINOR)) { |
| 1266 | printf("DPBP version mismatch found %u.%u,", |
| 1267 | major_ver, minor_ver); |
| 1268 | printf("supported version is %u.%u\n", |
| 1269 | DPBP_VER_MAJOR, DPBP_VER_MINOR); |
| 1270 | } |
| 1271 | |
| 1272 | err = dpbp_open(dflt_mc_io, |
| 1273 | MC_CMD_NO_FLAGS, |
| 1274 | dflt_dpbp->dpbp_id, |
| 1275 | &dflt_dpbp->dpbp_handle); |
| 1276 | if (err) { |
| 1277 | printf("dpbp_open() failed\n"); |
| 1278 | goto err_open; |
| 1279 | } |
| 1280 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1281 | memset(&dpbp_attr, 0, sizeof(struct dpbp_attr)); |
| 1282 | err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 1283 | dflt_dpbp->dpbp_handle, |
| 1284 | &dpbp_attr); |
| 1285 | if (err < 0) { |
| 1286 | printf("dpbp_get_attributes() failed: %d\n", err); |
| 1287 | goto err_get_attr; |
| 1288 | } |
| 1289 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1290 | if (dflt_dpbp->dpbp_id != dpbp_attr.id) { |
| 1291 | printf("dpbp object id and attribute id are not same\n"); |
| 1292 | goto err_attr_not_same; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1293 | } |
| 1294 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1295 | #ifdef DEBUG |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1296 | printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1297 | #endif |
| 1298 | |
| 1299 | err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 1300 | if (err < 0) { |
| 1301 | printf("dpbp_close() failed: %d\n", err); |
| 1302 | goto err_close; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1303 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1304 | |
| 1305 | return 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1306 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1307 | err_get_attr: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1308 | err_attr_not_same: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1309 | dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1310 | dpbp_destroy(dflt_mc_io, |
| 1311 | dflt_dprc_handle, |
| 1312 | MC_CMD_NO_FLAGS, |
| 1313 | dflt_dpbp->dpbp_id); |
| 1314 | err_get_api_ver: |
| 1315 | err_close: |
| 1316 | err_open: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1317 | err_create: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1318 | free(dflt_dpbp); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1319 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1320 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1323 | static int dpbp_exit(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1324 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1325 | int err; |
| 1326 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1327 | err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, |
| 1328 | dflt_dpbp->dpbp_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1329 | if (err < 0) { |
| 1330 | printf("dpbp_destroy() failed: %d\n", err); |
| 1331 | goto err; |
| 1332 | } |
| 1333 | |
| 1334 | #ifdef DEBUG |
| 1335 | printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id); |
| 1336 | #endif |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1337 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1338 | if (dflt_dpbp) |
| 1339 | free(dflt_dpbp); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1340 | return 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1341 | |
| 1342 | err: |
| 1343 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1346 | static int dpni_init(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1347 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1348 | int err; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1349 | uint8_t cfg_buf[256] = {0}; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1350 | struct dpni_cfg dpni_cfg; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1351 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1352 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1353 | dflt_dpni = (struct fsl_dpni_obj *)calloc( |
| 1354 | sizeof(struct fsl_dpni_obj), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1355 | if (!dflt_dpni) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1356 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1357 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1358 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1359 | } |
| 1360 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1361 | memset(&dpni_cfg, 0, sizeof(dpni_cfg)); |
| 1362 | err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]); |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1363 | if (err < 0) { |
| 1364 | err = -ENODEV; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1365 | printf("dpni_prepare_cfg() failed: %d\n", err); |
| 1366 | goto err_prepare_cfg; |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1367 | } |
| 1368 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1369 | err = dpni_create(dflt_mc_io, |
| 1370 | dflt_dprc_handle, |
| 1371 | MC_CMD_NO_FLAGS, |
| 1372 | &dpni_cfg, |
| 1373 | &dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1374 | if (err < 0) { |
| 1375 | err = -ENODEV; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1376 | printf("dpni create() failed: %d\n", err); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1377 | goto err_create; |
| 1378 | } |
| 1379 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1380 | err = dpni_get_api_version(dflt_mc_io, 0, |
| 1381 | &major_ver, |
| 1382 | &minor_ver); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1383 | if (err < 0) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1384 | printf("dpni_get_api_version() failed: %d\n", err); |
| 1385 | goto err_get_version; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1386 | } |
| 1387 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1388 | if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR && |
| 1389 | minor_ver < DPNI_VER_MINOR)) { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1390 | printf("DPNI version mismatch found %u.%u,", |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1391 | major_ver, minor_ver); |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1392 | printf("supported version is %u.%u\n", |
| 1393 | DPNI_VER_MAJOR, DPNI_VER_MINOR); |
| 1394 | } |
| 1395 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1396 | err = dpni_open(dflt_mc_io, |
| 1397 | MC_CMD_NO_FLAGS, |
| 1398 | dflt_dpni->dpni_id, |
| 1399 | &dflt_dpni->dpni_handle); |
| 1400 | if (err) { |
| 1401 | printf("dpni_open() failed\n"); |
| 1402 | goto err_open; |
| 1403 | } |
| 1404 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1405 | #ifdef DEBUG |
| 1406 | printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id); |
| 1407 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1408 | err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
| 1409 | if (err < 0) { |
| 1410 | printf("dpni_close() failed: %d\n", err); |
| 1411 | goto err_close; |
| 1412 | } |
| 1413 | |
| 1414 | return 0; |
| 1415 | |
| 1416 | err_close: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1417 | dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1418 | err_open: |
| 1419 | err_get_version: |
| 1420 | dpni_destroy(dflt_mc_io, |
| 1421 | dflt_dprc_handle, |
| 1422 | MC_CMD_NO_FLAGS, |
| 1423 | dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1424 | err_create: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1425 | err_prepare_cfg: |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1426 | free(dflt_dpni); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1427 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1428 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1429 | } |
| 1430 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1431 | static int dpni_exit(void) |
| 1432 | { |
| 1433 | int err; |
| 1434 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1435 | err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, |
| 1436 | dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1437 | if (err < 0) { |
| 1438 | printf("dpni_destroy() failed: %d\n", err); |
| 1439 | goto err; |
| 1440 | } |
| 1441 | |
| 1442 | #ifdef DEBUG |
| 1443 | printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id); |
| 1444 | #endif |
| 1445 | |
| 1446 | if (dflt_dpni) |
| 1447 | free(dflt_dpni); |
| 1448 | return 0; |
| 1449 | |
| 1450 | err: |
| 1451 | return err; |
| 1452 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1453 | |
| 1454 | static bool is_dpsparser_supported(void) |
| 1455 | { |
| 1456 | /* dpsparser support was first introduced in MC version: 10.12.0 */ |
| 1457 | if (mc_ver_info.major < 10) |
| 1458 | return false; |
| 1459 | if (mc_ver_info.major == 10) |
| 1460 | return (mc_ver_info.minor >= 12); |
| 1461 | return true; |
| 1462 | } |
| 1463 | |
| 1464 | static int dpsparser_version_check(struct fsl_mc_io *mc_io) |
| 1465 | { |
| 1466 | int error; |
| 1467 | u16 major_ver, minor_ver; |
| 1468 | |
| 1469 | if (!is_dpsparser_supported()) |
| 1470 | return 0; |
| 1471 | |
| 1472 | error = dpsparser_get_api_version(mc_io, 0, |
| 1473 | &major_ver, |
| 1474 | &minor_ver); |
| 1475 | if (error < 0) { |
| 1476 | printf("dpsparser_get_api_version() failed: %d\n", error); |
| 1477 | return error; |
| 1478 | } |
| 1479 | |
| 1480 | if (major_ver < DPSPARSER_VER_MAJOR || (major_ver == |
| 1481 | DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) { |
| 1482 | printf("DPSPARSER version mismatch found %u.%u,", |
| 1483 | major_ver, minor_ver); |
| 1484 | printf("supported version is %u.%u\n", |
| 1485 | DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR); |
| 1486 | } |
| 1487 | |
| 1488 | return error; |
| 1489 | } |
| 1490 | |
| 1491 | static int dpsparser_init(void) |
| 1492 | { |
| 1493 | int err = 0; |
| 1494 | |
| 1495 | if (!is_dpsparser_supported()) |
| 1496 | return 0; |
| 1497 | |
| 1498 | err = dpsparser_create(dflt_mc_io, |
| 1499 | dflt_dprc_handle, |
| 1500 | MC_CMD_NO_FLAGS, |
| 1501 | &dpsparser_obj_id); |
| 1502 | if (err) |
| 1503 | printf("dpsparser_create() failed\n"); |
| 1504 | |
| 1505 | err = dpsparser_version_check(dflt_mc_io); |
| 1506 | if (err < 0) { |
| 1507 | printf("dpsparser_version_check() failed: %d\n", err); |
| 1508 | goto err_version_check; |
| 1509 | } |
| 1510 | |
| 1511 | err = dpsparser_open(dflt_mc_io, |
| 1512 | MC_CMD_NO_FLAGS, |
| 1513 | &dpsparser_handle); |
| 1514 | if (err < 0) { |
| 1515 | printf("dpsparser_open() failed: %d\n", err); |
| 1516 | goto err_open; |
| 1517 | } |
| 1518 | |
| 1519 | return err; |
| 1520 | |
| 1521 | err_open: |
| 1522 | err_version_check: |
| 1523 | dpsparser_destroy(dflt_mc_io, |
| 1524 | dflt_dprc_handle, |
| 1525 | MC_CMD_NO_FLAGS, dpsparser_obj_id); |
| 1526 | |
| 1527 | return err; |
| 1528 | } |
| 1529 | |
| 1530 | #ifdef DPSPARSER_DESTROY |
| 1531 | /* TODO: refactoring needed in the future to allow DPSPARSER object destroy |
| 1532 | * Workaround: DO NOT destroy DPSPARSER object because it needs to be available |
| 1533 | * on Apply DPL |
| 1534 | */ |
| 1535 | static int dpsparser_exit(void) |
| 1536 | { |
| 1537 | int err; |
| 1538 | |
| 1539 | if (!is_dpsparser_supported()) |
| 1540 | return 0; |
| 1541 | |
| 1542 | dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle); |
| 1543 | if (err < 0) { |
| 1544 | printf("dpsparser_close() failed: %d\n", err); |
| 1545 | goto err; |
| 1546 | } |
| 1547 | |
| 1548 | err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle, |
| 1549 | MC_CMD_NO_FLAGS, dpsparser_obj_id); |
| 1550 | if (err < 0) { |
| 1551 | printf("dpsparser_destroy() failed: %d\n", err); |
| 1552 | goto err; |
| 1553 | } |
| 1554 | return 0; |
| 1555 | |
| 1556 | err: |
| 1557 | return err; |
| 1558 | } |
| 1559 | #endif |
| 1560 | |
| 1561 | int mc_apply_spb(u64 mc_spb_addr) |
| 1562 | { |
| 1563 | int err = 0; |
| 1564 | u16 error, err_arr_size; |
| 1565 | u64 mc_spb_offset; |
| 1566 | u32 spb_size; |
| 1567 | struct sp_blob_header *sp_blob; |
| 1568 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 1569 | |
| 1570 | if (!is_dpsparser_supported()) |
| 1571 | return 0; |
| 1572 | |
| 1573 | if (!mc_spb_addr) { |
| 1574 | printf("fsl-mc: Invalid Blob address\n"); |
| 1575 | return -1; |
| 1576 | } |
| 1577 | |
| 1578 | #ifdef CONFIG_MC_DRAM_SPB_OFFSET |
| 1579 | mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET; |
| 1580 | #else |
| 1581 | #error "CONFIG_MC_DRAM_SPB_OFFSET not defined" |
| 1582 | #endif |
| 1583 | |
| 1584 | // Read blob header and get size of SPB blob |
| 1585 | sp_blob = (struct sp_blob_header *)mc_spb_addr; |
| 1586 | spb_size = le32_to_cpu(sp_blob->length); |
| 1587 | if (spb_size > CONFIG_MC_SPB_MAX_SIZE) { |
| 1588 | printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n", |
| 1589 | spb_size); |
| 1590 | return -EINVAL; |
| 1591 | } |
| 1592 | |
| 1593 | mc_copy_image("MC SP Blob", mc_spb_addr, spb_size, |
| 1594 | mc_ram_addr + mc_spb_offset); |
| 1595 | |
| 1596 | //Invoke MC command to apply SPB blob |
| 1597 | printf("fsl-mc: Applying soft parser blob... "); |
| 1598 | err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle, |
| 1599 | mc_spb_offset, &error); |
| 1600 | if (err) |
| 1601 | return err; |
| 1602 | |
| 1603 | if (error == 0) { |
| 1604 | printf("SUCCESS\n"); |
| 1605 | } else { |
| 1606 | printf("FAILED with error code = %d:\n", error); |
| 1607 | err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb); |
| 1608 | |
| 1609 | if (error > 0 && error < err_arr_size) |
| 1610 | printf(mc_err_msg_apply_spb[error]); |
| 1611 | else |
| 1612 | printf(MC_ERROR_MSG_SPB_UNKNOWN); |
| 1613 | } |
| 1614 | |
| 1615 | return err; |
| 1616 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1617 | |
| 1618 | static int mc_init_object(void) |
| 1619 | { |
| 1620 | int err = 0; |
| 1621 | |
| 1622 | err = dprc_init(); |
| 1623 | if (err < 0) { |
| 1624 | printf("dprc_init() failed: %d\n", err); |
| 1625 | goto err; |
| 1626 | } |
| 1627 | |
| 1628 | err = dpbp_init(); |
| 1629 | if (err < 0) { |
| 1630 | printf("dpbp_init() failed: %d\n", err); |
| 1631 | goto err; |
| 1632 | } |
| 1633 | |
| 1634 | err = dpio_init(); |
| 1635 | if (err < 0) { |
| 1636 | printf("dpio_init() failed: %d\n", err); |
| 1637 | goto err; |
| 1638 | } |
| 1639 | |
| 1640 | err = dpni_init(); |
| 1641 | if (err < 0) { |
| 1642 | printf("dpni_init() failed: %d\n", err); |
| 1643 | goto err; |
| 1644 | } |
| 1645 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1646 | err = dpsparser_init(); |
| 1647 | if (err < 0) { |
| 1648 | printf("dpsparser_init() failed: %d\n", err); |
| 1649 | goto err; |
| 1650 | } |
| 1651 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1652 | return 0; |
| 1653 | err: |
| 1654 | return err; |
| 1655 | } |
| 1656 | |
| 1657 | int fsl_mc_ldpaa_exit(bd_t *bd) |
| 1658 | { |
| 1659 | int err = 0; |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1660 | bool is_dpl_apply_status = false; |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1661 | bool mc_boot_status = false; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1662 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1663 | if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) { |
Yogesh Gaur | 8dadfb4 | 2018-01-16 10:08:24 +0530 | [diff] [blame] | 1664 | err = mc_apply_dpl(mc_lazy_dpl_addr); |
| 1665 | if (!err) |
| 1666 | fdt_fixup_board_enet(working_fdt); |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1667 | mc_lazy_dpl_addr = 0; |
| 1668 | } |
| 1669 | |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1670 | if (!get_mc_boot_status()) |
| 1671 | mc_boot_status = true; |
| 1672 | |
Prabhakar Kushwaha | 878d3ec | 2016-03-21 14:19:39 +0530 | [diff] [blame] | 1673 | /* MC is not loaded intentionally, So return success. */ |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1674 | if (bd && !mc_boot_status) |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1675 | return 0; |
| 1676 | |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1677 | /* If DPL is deployed, set is_dpl_apply_status as TRUE. */ |
| 1678 | if (!get_dpl_apply_status()) |
| 1679 | is_dpl_apply_status = true; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1680 | |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1681 | /* |
| 1682 | * For case MC is loaded but DPL is not deployed, return success and |
| 1683 | * print message on console. Else FDT fix-up code execution hanged. |
| 1684 | */ |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1685 | if (bd && mc_boot_status && !is_dpl_apply_status) { |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1686 | printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n"); |
Yogesh Gaur | 82709e5 | 2017-11-28 10:11:14 +0530 | [diff] [blame] | 1687 | goto mc_obj_cleanup; |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1688 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1689 | |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1690 | if (bd && mc_boot_status && is_dpl_apply_status) |
| 1691 | return 0; |
| 1692 | |
Yogesh Gaur | 82709e5 | 2017-11-28 10:11:14 +0530 | [diff] [blame] | 1693 | mc_obj_cleanup: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1694 | err = dpbp_exit(); |
| 1695 | if (err < 0) { |
Prabhakar Kushwaha | 88ba4d6 | 2016-01-20 12:04:37 +0530 | [diff] [blame] | 1696 | printf("dpbp_exit() failed: %d\n", err); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1697 | goto err; |
| 1698 | } |
| 1699 | |
| 1700 | err = dpio_exit(); |
| 1701 | if (err < 0) { |
| 1702 | printf("dpio_exit() failed: %d\n", err); |
| 1703 | goto err; |
| 1704 | } |
| 1705 | |
| 1706 | err = dpni_exit(); |
| 1707 | if (err < 0) { |
| 1708 | printf("dpni_exit() failed: %d\n", err); |
| 1709 | goto err; |
| 1710 | } |
| 1711 | |
| 1712 | err = dprc_exit(); |
| 1713 | if (err < 0) { |
| 1714 | printf("dprc_exit() failed: %d\n", err); |
| 1715 | goto err; |
| 1716 | } |
| 1717 | |
| 1718 | return 0; |
| 1719 | err: |
| 1720 | return err; |
| 1721 | } |
| 1722 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1723 | static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1724 | { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1725 | int err = 0; |
| 1726 | if (argc < 3) |
| 1727 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1728 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1729 | switch (argv[1][0]) { |
| 1730 | case 's': { |
| 1731 | char sub_cmd; |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 1732 | u64 mc_fw_addr, mc_dpc_addr; |
| 1733 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 1734 | u64 aiop_fw_addr; |
| 1735 | #endif |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1736 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1737 | sub_cmd = argv[2][0]; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1738 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1739 | switch (sub_cmd) { |
| 1740 | case 'm': |
| 1741 | if (argc < 5) |
| 1742 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1743 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1744 | if (get_mc_boot_status() == 0) { |
| 1745 | printf("fsl-mc: MC is already booted"); |
| 1746 | printf("\n"); |
| 1747 | return err; |
| 1748 | } |
| 1749 | mc_fw_addr = simple_strtoull(argv[3], NULL, 16); |
| 1750 | mc_dpc_addr = simple_strtoull(argv[4], NULL, |
| 1751 | 16); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1752 | |
| 1753 | if (!mc_init(mc_fw_addr, mc_dpc_addr)) |
| 1754 | err = mc_init_object(); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1755 | break; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1756 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1757 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 1758 | case 'a': |
| 1759 | if (argc < 4) |
| 1760 | goto usage; |
| 1761 | if (get_aiop_apply_status() == 0) { |
| 1762 | printf("fsl-mc: AIOP FW is already"); |
| 1763 | printf(" applied\n"); |
| 1764 | return err; |
| 1765 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1766 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1767 | aiop_fw_addr = simple_strtoull(argv[3], NULL, |
| 1768 | 16); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1769 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 1770 | /* if SoC doesn't have AIOP, err = -ENODEV */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1771 | err = load_mc_aiop_img(aiop_fw_addr); |
| 1772 | if (!err) |
| 1773 | printf("fsl-mc: AIOP FW applied\n"); |
| 1774 | break; |
| 1775 | #endif |
| 1776 | default: |
| 1777 | printf("Invalid option: %s\n", argv[2]); |
| 1778 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1779 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1780 | break; |
| 1781 | } |
| 1782 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1783 | break; |
| 1784 | |
| 1785 | case 'l': { |
| 1786 | /* lazyapply */ |
| 1787 | u64 mc_dpl_addr; |
| 1788 | |
| 1789 | if (argc < 4) |
| 1790 | goto usage; |
| 1791 | |
| 1792 | if (get_dpl_apply_status() == 0) { |
| 1793 | printf("fsl-mc: DPL already applied\n"); |
| 1794 | return err; |
| 1795 | } |
| 1796 | |
| 1797 | mc_dpl_addr = simple_strtoull(argv[3], NULL, 16); |
| 1798 | |
| 1799 | if (get_mc_boot_status() != 0) { |
| 1800 | printf("fsl-mc: Deploying data path layout .."); |
| 1801 | printf("ERROR (MC is not booted)\n"); |
| 1802 | return -ENODEV; |
| 1803 | } |
| 1804 | |
| 1805 | /* |
| 1806 | * We will do the actual dpaa exit and dpl apply |
| 1807 | * later from announce_and_cleanup(). |
| 1808 | */ |
| 1809 | mc_lazy_dpl_addr = mc_dpl_addr; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1810 | break; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1811 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1812 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1813 | case 'a': { |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1814 | /* apply */ |
| 1815 | char sub_cmd; |
| 1816 | u64 mc_apply_addr; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1817 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1818 | if (argc < 4) |
| 1819 | goto usage; |
| 1820 | |
| 1821 | sub_cmd = argv[2][0]; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1822 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1823 | switch (sub_cmd) { |
| 1824 | case 'd': |
| 1825 | case 'D': |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1826 | if (get_dpl_apply_status() == 0) { |
| 1827 | printf("fsl-mc: DPL already applied\n"); |
| 1828 | return err; |
| 1829 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1830 | if (get_mc_boot_status() != 0) { |
| 1831 | printf("fsl-mc: Deploying data path layout .."); |
| 1832 | printf("ERROR (MC is not booted)\n"); |
| 1833 | return -ENODEV; |
| 1834 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1835 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1836 | mc_apply_addr = simple_strtoull(argv[3], NULL, 16); |
| 1837 | |
| 1838 | /* The user wants DPL applied now */ |
| 1839 | if (!fsl_mc_ldpaa_exit(NULL)) |
| 1840 | err = mc_apply_dpl(mc_apply_addr); |
| 1841 | break; |
| 1842 | |
| 1843 | case 's': |
| 1844 | if (!is_dpsparser_supported()) { |
| 1845 | printf("fsl-mc: apply spb command .. "); |
| 1846 | printf("ERROR: requires at least MC 10.12.0\n"); |
| 1847 | return err; |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1848 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1849 | if (get_mc_boot_status() != 0) { |
| 1850 | printf("fsl-mc: Deploying Soft Parser Blob..."); |
| 1851 | printf("ERROR (MC is not booted)\n"); |
| 1852 | return err; |
| 1853 | } |
| 1854 | |
| 1855 | mc_apply_addr = simple_strtoull(argv[3], NULL, 16); |
| 1856 | |
| 1857 | /* Apply spb (Soft Parser Blob) */ |
| 1858 | err = mc_apply_spb(mc_apply_addr); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1859 | break; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1860 | |
| 1861 | default: |
| 1862 | printf("Invalid option: %s\n", argv[2]); |
| 1863 | goto usage; |
| 1864 | } |
| 1865 | break; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 1866 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1867 | default: |
| 1868 | printf("Invalid option: %s\n", argv[1]); |
| 1869 | goto usage; |
| 1870 | break; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1871 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1872 | return err; |
| 1873 | usage: |
| 1874 | return CMD_RET_USAGE; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1875 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1876 | |
| 1877 | U_BOOT_CMD( |
| 1878 | fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc, |
| 1879 | "DPAA2 command to manage Management Complex (MC)", |
| 1880 | "start mc [FW_addr] [DPC_addr] - Start Management Complex\n" |
| 1881 | "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n" |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1882 | "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n" |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1883 | "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n" |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1884 | "fsl_mc start aiop [FW_addr] - Start AIOP\n" |
| 1885 | ); |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 1886 | |
| 1887 | void mc_env_boot(void) |
| 1888 | { |
| 1889 | #if defined(CONFIG_FSL_MC_ENET) |
| 1890 | char *mc_boot_env_var; |
| 1891 | /* The MC may only be initialized in the reset PHY function |
| 1892 | * because otherwise U-Boot has not yet set up all the MAC |
| 1893 | * address info properly. Without MAC addresses, the MC code |
| 1894 | * can not properly initialize the DPC. |
| 1895 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1896 | mc_boot_env_var = env_get(MC_BOOT_ENV_VAR); |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 1897 | if (mc_boot_env_var) |
| 1898 | run_command_list(mc_boot_env_var, -1, 0); |
| 1899 | #endif /* CONFIG_FSL_MC_ENET */ |
| 1900 | } |