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