1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 Freescale Semiconductor, Inc.
4 * Copyright 2017-2018, 2020-2021 NXP
15 #include <asm/global_data.h>
16 #include <linux/bug.h>
18 #include <linux/delay.h>
19 #include <linux/libfdt.h>
21 #include <fdt_support.h>
22 #include <fsl-mc/fsl_mc.h>
23 #include <fsl-mc/fsl_mc_sys.h>
24 #include <fsl-mc/fsl_mc_private.h>
25 #include <fsl-mc/fsl_dpmng.h>
26 #include <fsl-mc/fsl_dprc.h>
27 #include <fsl-mc/fsl_dpio.h>
28 #include <fsl-mc/fsl_dpni.h>
29 #include <fsl-mc/fsl_dpsparser.h>
30 #include <fsl-mc/fsl_qbman_portal.h>
31 #include <fsl-mc/ldpaa_wriop.h>
33 #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
34 #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
35 #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
37 #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
38 #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
39 #define MC_BOOT_ENV_VAR "mcinitcmd"
40 #define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024)
42 #define MC_BUFFER_SIZE (1024 * 1024 * 16)
43 #define MAGIC_MC 0x4d430100
44 #define MC_FW_ADDR_MASK_LOW 0xE0000000
45 #define MC_FW_ADDR_MASK_HIGH 0X1FFFF
46 #define MC_STRUCT_BUFFER_OFFSET 0x01000000
47 #define MC_OFFSET_DELTA MC_STRUCT_BUFFER_OFFSET
49 #define LOG_HEADER_FLAG_BUFFER_WRAPAROUND 0x80000000
50 #define LAST_BYTE(a) ((a) & ~(LOG_HEADER_FLAG_BUFFER_WRAPAROUND))
52 DECLARE_GLOBAL_DATA_PTR;
53 static int mc_memset_resv_ram;
54 static struct mc_version mc_ver_info;
55 static int mc_boot_status = -1;
56 static int mc_dpl_applied = -1;
57 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
58 static int mc_aiop_applied = -1;
60 struct fsl_mc_io *root_mc_io = NULL;
61 struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
62 uint16_t root_dprc_handle = 0;
63 uint16_t dflt_dprc_handle = 0;
65 struct fsl_dpbp_obj *dflt_dpbp = NULL;
66 struct fsl_dpio_obj *dflt_dpio = NULL;
67 struct fsl_dpni_obj *dflt_dpni = NULL;
68 static u64 mc_lazy_dpl_addr;
69 static u32 dpsparser_obj_id;
70 static u16 dpsparser_handle;
71 static char *mc_err_msg_apply_spb[] = MC_ERROR_MSG_APPLY_SPB;
74 void dump_ram_words(const char *title, void *addr)
77 uint32_t *words = addr;
79 printf("Dumping beginning of %s (%p):\n", title, addr);
80 for (i = 0; i < 16; i++)
81 printf("%#x ", words[i]);
86 void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
88 printf("MC CCSR registers:\n"
98 mc_ccsr_regs->reg_gcr1,
99 mc_ccsr_regs->reg_gsr,
100 mc_ccsr_regs->reg_sicbalr,
101 mc_ccsr_regs->reg_sicbahr,
102 mc_ccsr_regs->reg_sicapr,
103 mc_ccsr_regs->reg_mcfbalr,
104 mc_ccsr_regs->reg_mcfbahr,
105 mc_ccsr_regs->reg_mcfapr,
106 mc_ccsr_regs->reg_psr);
110 #define dump_ram_words(title, addr)
111 #define dump_mc_ccsr_regs(mc_ccsr_regs)
116 * Copying MC firmware or DPL image to DDR
118 static int mc_copy_image(const char *title,
119 u64 image_addr, u32 image_size, u64 mc_ram_addr)
121 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
122 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
123 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
127 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
129 * MC firmware FIT image parser checks if the image is in FIT
130 * format, verifies integrity of the image and calculates
131 * raw image address and size values.
132 * Returns 0 on success and a negative errno on error.
135 int parse_mc_firmware_fit_image(u64 mc_fw_addr,
136 const void **raw_image_addr,
137 size_t *raw_image_size)
140 void *fit_hdr = (void *)mc_fw_addr;
142 /* Check if Image is in FIT format */
143 format = genimg_get_format(fit_hdr);
145 if (format != IMAGE_FORMAT_FIT) {
146 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
150 if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
151 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
155 return fit_get_data_node(fit_hdr, "firmware", raw_image_addr,
160 #define MC_DT_INCREASE_SIZE 64
167 static int mc_fixup_mac_addr(void *blob, int nodeoffset,
169 const char *propname, struct udevice *eth_dev,
171 const char *propname, struct eth_device *eth_dev,
173 enum mc_fixup_type type)
176 struct eth_pdata *plat = dev_get_plat(eth_dev);
177 unsigned char *enetaddr = plat->enetaddr;
178 int eth_index = dev_seq(eth_dev);
180 unsigned char *enetaddr = eth_dev->enetaddr;
181 int eth_index = eth_dev->index;
183 int err = 0, len = 0, size, i;
184 unsigned char env_enetaddr[ARP_HLEN];
185 unsigned int enetaddr_32[ARP_HLEN];
190 /* DPL likes its addresses on 32 * ARP_HLEN bits */
191 for (i = 0; i < ARP_HLEN; i++)
192 enetaddr_32[i] = cpu_to_fdt32(enetaddr[i]);
194 len = sizeof(enetaddr_32);
202 /* MAC address property present */
203 if (fdt_get_property(blob, nodeoffset, propname, NULL)) {
204 /* u-boot MAC addr randomly assigned - leave the present one */
205 if (!eth_env_get_enetaddr_by_index("eth", eth_index,
209 size = MC_DT_INCREASE_SIZE + strlen(propname) + len;
210 /* make room for mac address property */
211 err = fdt_increase_size(blob, size);
213 printf("fdt_increase_size: err=%s\n",
219 err = fdt_setprop(blob, nodeoffset, propname, val, len);
221 printf("fdt_setprop: err=%s\n", fdt_strerror(err));
228 #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
230 const char *dpl_get_connection_endpoint(void *blob, char *endpoint)
232 int connoffset = fdt_path_offset(blob, "/connections"), off;
235 for (off = fdt_first_subnode(blob, connoffset);
237 off = fdt_next_subnode(blob, off)) {
238 s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL);
239 s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL);
244 if (strcmp(endpoint, s1) == 0)
247 if (strcmp(endpoint, s2) == 0)
254 static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id,
256 struct udevice *eth_dev)
258 struct eth_device *eth_dev)
261 int objoff = fdt_path_offset(blob, "/objects");
262 int dpmacoff = -1, dpnioff = -1;
263 const char *endpoint;
267 sprintf(mac_name, "dpmac@%d", dpmac_id);
268 dpmacoff = fdt_subnode_offset(blob, objoff, mac_name);
270 /* dpmac not defined in DPL, so skip it. */
273 err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev,
276 printf("Error fixing up dpmac mac_addr in DPL\n");
280 /* now we need to figure out if there is any
281 * DPNI connected to this MAC, so we walk the
284 endpoint = dpl_get_connection_endpoint(blob, mac_name);
285 if (!is_dpni(endpoint))
288 /* let's see if we can fixup the DPNI as well */
289 dpnioff = fdt_subnode_offset(blob, objoff, endpoint);
291 /* DPNI not defined in DPL in the objects area */
294 return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev,
298 void fdt_fixup_mc_ddr(u64 *base, u64 *size)
300 u64 mc_size = mc_get_dram_block_size();
302 if (mc_size < MC_DRAM_BLOCK_DEFAULT_SIZE) {
303 *base = mc_get_dram_addr() + mc_size;
304 *size = MC_DRAM_BLOCK_DEFAULT_SIZE - mc_size;
308 void fdt_fsl_mc_fixup_iommu_map_entry(void *blob)
311 u32 iommu_map[4], phandle;
315 /* find fsl-mc node */
316 offset = fdt_path_offset(blob, "/soc/fsl-mc");
318 offset = fdt_path_offset(blob, "/fsl-mc");
320 printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n",
325 prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp);
327 debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n",
332 iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
333 iommu_map[1] = *++prop;
334 iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
335 iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END -
336 FSL_DPAA2_STREAM_ID_START + 1);
338 fdt_setprop_inplace(blob, offset, "iommu-map",
339 iommu_map, sizeof(iommu_map));
341 /* get phandle to MSI controller */
342 prop = (u32 *)fdt_getprop(blob, offset, "msi-parent", 0);
344 debug("\n%s: ERROR: missing msi-parent\n", __func__);
347 phandle = fdt32_to_cpu(*prop);
349 /* also set msi-map property */
350 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START);
351 fdt_appendprop_u32(blob, offset, "msi-map", phandle);
352 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START);
353 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_END -
354 FSL_DPAA2_STREAM_ID_START + 1);
357 static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
359 struct udevice *eth_dev)
361 struct eth_device *eth_dev)
364 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
367 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
369 sprintf(mac_name, "mac@%d", dpmac_id);
371 /* node not found - create it */
372 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
374 err = fdt_increase_size(blob, 200);
376 printf("fdt_increase_size: err=%s\n",
381 noff = fdt_add_subnode(blob, nodeoffset, mac_name);
383 printf("fdt_add_subnode: err=%s\n",
388 /* add default property of fixed link */
389 err = fdt_appendprop_string(blob, noff,
390 "link_type", link_type_mode);
392 printf("fdt_appendprop_string: err=%s\n",
398 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
402 static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
404 int i, err = 0, ret = 0;
406 #define ETH_NAME_LEN 20
407 struct udevice *eth_dev;
409 struct eth_device *eth_dev;
411 char ethname[ETH_NAME_LEN];
413 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
414 /* port not enabled */
415 if (wriop_is_enabled_dpmac(i) != 1)
418 snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
419 phy_interface_strings[wriop_get_enet_if(i)]);
421 eth_dev = eth_get_dev_by_name(ethname);
427 err = mc_fixup_dpl_mac_addr(blob, i, eth_dev);
430 err = mc_fixup_dpc_mac_addr(blob, i, eth_dev);
437 printf("fsl-mc: ERROR fixing mac address for %s\n",
445 static int mc_fixup_dpc(u64 dpc_addr)
447 void *blob = (void *)dpc_addr;
448 int nodeoffset, err = 0;
450 /* delete any existing ICID pools */
451 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
452 if (fdt_del_node(blob, nodeoffset) < 0)
453 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
456 nodeoffset = fdt_path_offset(blob, "/resources");
457 if (nodeoffset < 0) {
458 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
461 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
462 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
463 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
464 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
465 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
467 FSL_DPAA2_STREAM_ID_END -
468 FSL_DPAA2_STREAM_ID_START + 1, 1);
470 /* fixup MAC addresses for dpmac ports */
471 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
472 if (nodeoffset < 0) {
473 err = fdt_increase_size(blob, 512);
475 printf("fdt_increase_size: err=%s\n",
479 nodeoffset = fdt_path_offset(blob, "/board_info");
481 nodeoffset = fdt_add_subnode(blob, 0, "board_info");
483 nodeoffset = fdt_add_subnode(blob, nodeoffset, "ports");
486 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
489 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
494 static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
497 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
503 #ifdef CFG_SYS_LS_MC_DRAM_DPC_OFFSET
504 BUILD_BUG_ON((CFG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
505 CFG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
507 mc_dpc_offset = CFG_SYS_LS_MC_DRAM_DPC_OFFSET;
509 #error "CFG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
513 * Load the MC DPC blob in the MC private DRAM block:
515 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
516 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
519 * Get address and size of the DPC blob stored in flash:
521 dpc_fdt_hdr = (void *)mc_dpc_addr;
523 error = fdt_check_header(dpc_fdt_hdr);
526 * Don't return with error here, since the MC firmware can
527 * still boot without a DPC
529 printf("\nfsl-mc: WARNING: No DPC image found");
533 dpc_size = fdt_totalsize(dpc_fdt_hdr);
534 if (dpc_size > CFG_SYS_LS_MC_DPC_MAX_LENGTH) {
535 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
540 mc_copy_image("MC DPC blob",
541 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
542 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
544 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
547 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
552 static int mc_fixup_dpl(u64 dpl_addr)
554 void *blob = (void *)dpl_addr;
555 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
558 /* The DPL fixup for mac addresses is only relevant
564 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
565 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
570 static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
573 #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
579 #ifdef CFG_SYS_LS_MC_DRAM_DPL_OFFSET
580 BUILD_BUG_ON((CFG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
581 CFG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
583 mc_dpl_offset = CFG_SYS_LS_MC_DRAM_DPL_OFFSET;
585 #error "CFG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
589 * Load the MC DPL blob in the MC private DRAM block:
591 #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
592 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
595 * Get address and size of the DPL blob stored in flash:
597 dpl_fdt_hdr = (void *)mc_dpl_addr;
599 error = fdt_check_header(dpl_fdt_hdr);
601 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
605 dpl_size = fdt_totalsize(dpl_fdt_hdr);
606 if (dpl_size > CFG_SYS_LS_MC_DPL_MAX_LENGTH) {
607 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
612 mc_copy_image("MC DPL blob",
613 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
614 #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
616 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
618 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
623 * Return the MC boot timeout value in milliseconds
625 static unsigned long get_mc_boot_timeout_ms(void)
627 unsigned long timeout_ms = CFG_SYS_LS_MC_BOOT_TIMEOUT_MS;
629 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
631 if (timeout_ms_env_var) {
632 timeout_ms = dectoul(timeout_ms_env_var, NULL);
633 if (timeout_ms == 0) {
634 printf("fsl-mc: WARNING: Invalid value for \'"
635 MC_BOOT_TIMEOUT_ENV_VAR
636 "\' environment variable: %lu\n",
639 timeout_ms = CFG_SYS_LS_MC_BOOT_TIMEOUT_MS;
646 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
648 __weak bool soc_has_aiop(void)
653 static int load_mc_aiop_img(u64 aiop_fw_addr)
655 u64 mc_ram_addr = mc_get_dram_addr();
656 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
660 /* Check if AIOP is available */
664 * Load the MC AIOP image in the MC private DRAM block:
667 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
668 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
669 CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
671 aiop_img = (void *)aiop_fw_addr;
672 mc_copy_image("MC AIOP image",
673 (u64)aiop_img, CFG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
674 mc_ram_addr + CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
682 static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
685 u32 mc_fw_boot_status;
686 unsigned long timeout_ms = get_mc_boot_timeout_ms();
687 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
690 assert(timeout_ms > 0);
692 udelay(1000); /* throttle polling */
693 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
694 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
695 if (mc_fw_boot_status & 0x1)
703 if (timeout_ms == 0) {
704 printf("ERROR: timeout\n");
706 /* TODO: Get an error status from an MC CCSR register */
710 if (mc_fw_boot_status != 0x1) {
712 * TODO: Identify critical errors from the GSR register's FS
713 * field and for those errors, set error to -ENODEV or other
714 * appropriate errno, so that the status property is set to
715 * failure in the fsl,dprc device tree node.
717 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
724 *final_reg_gsr = reg_gsr;
728 int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
732 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
733 u64 mc_ram_addr = mc_get_dram_addr();
736 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
737 const void *raw_image_addr;
738 size_t raw_image_size = 0;
740 u8 mc_ram_num_256mb_blocks;
741 size_t mc_ram_size = mc_get_dram_block_size();
743 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
745 if (mc_ram_num_256mb_blocks >= 0xff) {
747 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
753 * To support 128 MB DDR Size for MC
755 if (mc_ram_num_256mb_blocks == 0)
756 mc_ram_num_256mb_blocks = 0xFF;
759 * Management Complex cores should be held at reset out of POR.
760 * U-Boot should be the first software to touch MC. To be safe,
761 * we reset all cores again by setting GCR1 to 0. It doesn't do
762 * anything if they are held at reset. After we setup the firmware
763 * we kick off MC by deasserting the reset bit for core 0, and
764 * deasserting the reset bits for Command Portal Managers.
765 * The stop bits are not touched here. They are used to stop the
766 * cores when they are active. Setting stop bits doesn't stop the
767 * cores from fetching instructions when they are released from
770 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
773 #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
774 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
776 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
781 * Load the MC FW at the beginning of the MC private DRAM block:
783 mc_copy_image("MC Firmware",
784 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
786 dump_ram_words("firmware", (void *)mc_ram_addr);
788 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
792 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
793 dump_mc_ccsr_regs(mc_ccsr_regs);
796 * Tell MC what is the address range of the DRAM block assigned to it:
798 if (mc_ram_num_256mb_blocks < 0xFF) {
799 reg_mcfbalr = (u32)mc_ram_addr |
800 (mc_ram_num_256mb_blocks - 1);
802 reg_mcfbalr = (u32)mc_ram_addr |
803 (mc_ram_num_256mb_blocks);
806 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
807 out_le32(&mc_ccsr_regs->reg_mcfbahr,
808 (u32)(mc_ram_addr >> 32));
809 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
812 * Tell the MC that we want delayed DPL deployment.
814 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
816 printf("\nfsl-mc: Booting Management Complex ... ");
819 * Deassert reset and release MC core 0 to run
821 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
822 error = wait_for_mc(true, ®_gsr);
827 * TODO: need to obtain the portal_id for the root container from the
833 * Initialize the global default MC portal
834 * And check that the MC firmware is responding portal commands:
836 root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
838 printf(" No memory: calloc() failed\n");
842 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
843 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
844 portal_id, root_mc_io->mmio_regs);
846 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
848 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
853 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
854 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
855 reg_gsr & GSR_FS_MASK);
859 mc_boot_status = error;
866 int mc_apply_dpl(u64 mc_dpl_addr)
868 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
871 u64 mc_ram_addr = mc_get_dram_addr();
872 size_t mc_ram_size = mc_get_dram_block_size();
877 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
882 * Tell the MC to deploy the DPL:
884 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
885 printf("fsl-mc: Deploying data path layout ... ");
886 error = wait_for_mc(false, ®_gsr);
894 int get_mc_boot_status(void)
896 return mc_boot_status;
899 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
900 int get_aiop_apply_status(void)
902 return mc_aiop_applied;
906 int get_dpl_apply_status(void)
908 return mc_dpl_applied;
911 int is_lazy_dpl_addr_valid(void)
913 return !!mc_lazy_dpl_addr;
917 * Return the MC address of private DRAM block.
918 * As per MC design document, MC initial base address
919 * should be least significant 512MB address of MC private
920 * memory, i.e. address should point to end address masked
921 * with 512MB offset in private DRAM block.
923 u64 mc_get_dram_addr(void)
925 size_t mc_ram_size = mc_get_dram_block_size();
927 if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) {
928 mc_memset_resv_ram = 1;
929 memset((void *)gd->arch.resv_ram, 0, mc_ram_size);
932 return (gd->arch.resv_ram + mc_ram_size - 1) &
933 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
937 * Return the actual size of the MC private DRAM block.
939 unsigned long mc_get_dram_block_size(void)
941 unsigned long dram_block_size = CFG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
943 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
945 if (dram_block_size_env_var) {
946 dram_block_size = hextoul(dram_block_size_env_var, NULL);
948 if (dram_block_size < CFG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
949 printf("fsl-mc: WARNING: Invalid value for \'"
951 "\' environment variable: %lu\n",
954 dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE;
958 return dram_block_size;
961 int fsl_mc_ldpaa_init(struct bd_info *bis)
965 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
966 if (wriop_is_enabled_dpmac(i) == 1)
967 ldpaa_eth_init(i, wriop_get_enet_if(i));
971 static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
974 uint16_t major_ver, minor_ver;
976 error = dprc_get_api_version(mc_io, 0,
980 printf("dprc_get_api_version() failed: %d\n", error);
984 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
985 minor_ver < DPRC_VER_MINOR)) {
986 printf("DPRC version mismatch found %u.%u,",
987 major_ver, minor_ver);
988 printf("supported version is %u.%u\n",
989 DPRC_VER_MAJOR, DPRC_VER_MINOR);
995 static int dpio_init(void)
997 struct qbman_swp_desc p_des;
998 struct dpio_attr attr;
999 struct dpio_cfg dpio_cfg;
1001 uint16_t major_ver, minor_ver;
1003 dflt_dpio = (struct fsl_dpio_obj *)calloc(
1004 sizeof(struct fsl_dpio_obj), 1);
1006 printf("No memory: calloc() failed\n");
1010 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
1011 dpio_cfg.num_priorities = 8;
1013 err = dpio_create(dflt_mc_io,
1017 &dflt_dpio->dpio_id);
1019 printf("dpio_create() failed: %d\n", err);
1024 err = dpio_get_api_version(dflt_mc_io, 0,
1028 printf("dpio_get_api_version() failed: %d\n", err);
1029 goto err_get_api_ver;
1032 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
1033 minor_ver < DPIO_VER_MINOR)) {
1034 printf("DPRC version mismatch found %u.%u,",
1039 err = dpio_open(dflt_mc_io,
1042 &dflt_dpio->dpio_handle);
1044 printf("dpio_open() failed\n");
1048 memset(&attr, 0, sizeof(struct dpio_attr));
1049 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1050 dflt_dpio->dpio_handle, &attr);
1052 printf("dpio_get_attributes() failed: %d\n", err);
1056 if (dflt_dpio->dpio_id != attr.id) {
1057 printf("dnpi object id and attribute id are not same\n");
1058 goto err_attr_not_same;
1062 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1064 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1066 printf("dpio_enable() failed %d\n", err);
1067 goto err_get_enable;
1069 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
1070 attr.qbman_portal_ce_offset,
1071 attr.qbman_portal_ci_offset,
1072 attr.qbman_portal_id,
1073 attr.num_priorities);
1075 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1076 + attr.qbman_portal_ce_offset);
1077 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1078 + attr.qbman_portal_ci_offset);
1080 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
1081 if (dflt_dpio->sw_portal == NULL) {
1082 printf("qbman_swp_init() failed\n");
1083 goto err_get_swp_init;
1088 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1092 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1095 dpio_destroy(dflt_mc_io,
1098 dflt_dpio->dpio_id);
1105 static int dpio_exit(void)
1109 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1111 printf("dpio_disable() failed: %d\n", err);
1115 err = dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1117 printf("dpio_close() failed: %d\n", err);
1121 err = dpio_destroy(dflt_mc_io,
1124 dflt_dpio->dpio_id);
1126 printf("dpio_destroy() failed: %d\n", err);
1131 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1142 static int dprc_init(void)
1144 int err, child_portal_id, container_id;
1145 struct dprc_cfg cfg;
1146 uint64_t mc_portal_offset;
1148 /* Open root container */
1149 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1151 printf("dprc_get_container_id(): Root failed: %d\n", err);
1152 goto err_root_container_id;
1156 printf("Root container id = %d\n", container_id);
1158 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1161 printf("dprc_open(): Root Container failed: %d\n", err);
1165 if (!root_dprc_handle) {
1166 printf("dprc_open(): Root Container Handle is not valid\n");
1170 err = dprc_version_check(root_mc_io, root_dprc_handle);
1172 printf("dprc_version_check() failed: %d\n", err);
1176 memset(&cfg, 0, sizeof(struct dprc_cfg));
1177 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1178 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1179 DPRC_CFG_OPT_ALLOC_ALLOWED;
1180 cfg.icid = DPRC_GET_ICID_FROM_POOL;
1181 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
1182 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1188 printf("dprc_create_container() failed: %d\n", err);
1192 dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
1195 printf(" No memory: calloc() failed\n");
1199 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1200 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
1203 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1204 child_dprc_id, dflt_mc_io->mmio_regs);
1207 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1210 printf("dprc_open(): Child container failed: %d\n", err);
1211 goto err_child_open;
1214 if (!dflt_dprc_handle) {
1215 printf("dprc_open(): Child container Handle is not valid\n");
1216 goto err_child_open;
1223 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1224 root_dprc_handle, child_dprc_id);
1226 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1228 err_root_container_id:
1232 static int dprc_exit(void)
1236 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1238 printf("dprc_close(): Child failed: %d\n", err);
1242 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1243 root_dprc_handle, child_dprc_id);
1245 printf("dprc_destroy_container() failed: %d\n", err);
1249 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1251 printf("dprc_close(): Root failed: %d\n", err);
1267 static int dpbp_init(void)
1270 struct dpbp_attr dpbp_attr;
1271 struct dpbp_cfg dpbp_cfg;
1272 uint16_t major_ver, minor_ver;
1274 dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
1275 sizeof(struct fsl_dpbp_obj), 1);
1277 printf("No memory: calloc() failed\n");
1282 dpbp_cfg.options = 512;
1284 err = dpbp_create(dflt_mc_io,
1288 &dflt_dpbp->dpbp_id);
1292 printf("dpbp_create() failed: %d\n", err);
1296 err = dpbp_get_api_version(dflt_mc_io, 0,
1300 printf("dpbp_get_api_version() failed: %d\n", err);
1301 goto err_get_api_ver;
1304 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1305 minor_ver < DPBP_VER_MINOR)) {
1306 printf("DPBP version mismatch found %u.%u,",
1307 major_ver, minor_ver);
1308 printf("supported version is %u.%u\n",
1309 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1312 err = dpbp_open(dflt_mc_io,
1315 &dflt_dpbp->dpbp_handle);
1317 printf("dpbp_open() failed\n");
1321 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1322 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1323 dflt_dpbp->dpbp_handle,
1326 printf("dpbp_get_attributes() failed: %d\n", err);
1330 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1331 printf("dpbp object id and attribute id are not same\n");
1332 goto err_attr_not_same;
1336 printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
1339 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1341 printf("dpbp_close() failed: %d\n", err);
1349 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1350 dpbp_destroy(dflt_mc_io,
1353 dflt_dpbp->dpbp_id);
1363 static int dpbp_exit(void)
1367 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1368 dflt_dpbp->dpbp_id);
1370 printf("dpbp_destroy() failed: %d\n", err);
1375 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1386 static int dpni_init(void)
1389 uint8_t cfg_buf[256] = {0};
1390 struct dpni_cfg dpni_cfg;
1391 uint16_t major_ver, minor_ver;
1393 dflt_dpni = (struct fsl_dpni_obj *)calloc(
1394 sizeof(struct fsl_dpni_obj), 1);
1396 printf("No memory: calloc() failed\n");
1401 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1402 err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
1405 printf("dpni_prepare_cfg() failed: %d\n", err);
1406 goto err_prepare_cfg;
1409 err = dpni_create(dflt_mc_io,
1413 &dflt_dpni->dpni_id);
1416 printf("dpni create() failed: %d\n", err);
1420 err = dpni_get_api_version(dflt_mc_io, 0,
1424 printf("dpni_get_api_version() failed: %d\n", err);
1425 goto err_get_version;
1428 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1429 minor_ver < DPNI_VER_MINOR)) {
1430 printf("DPNI version mismatch found %u.%u,",
1431 major_ver, minor_ver);
1432 printf("supported version is %u.%u\n",
1433 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1436 err = dpni_open(dflt_mc_io,
1439 &dflt_dpni->dpni_handle);
1441 printf("dpni_open() failed\n");
1446 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1448 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1450 printf("dpni_close() failed: %d\n", err);
1457 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1460 dpni_destroy(dflt_mc_io,
1463 dflt_dpni->dpni_id);
1471 static int dpni_exit(void)
1475 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1476 dflt_dpni->dpni_id);
1478 printf("dpni_destroy() failed: %d\n", err);
1483 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1494 static bool is_dpsparser_supported(void)
1496 /* dpsparser support was first introduced in MC version: 10.12.0 */
1497 if (mc_ver_info.major < 10)
1499 if (mc_ver_info.major == 10)
1500 return (mc_ver_info.minor >= 12);
1504 static int dpsparser_version_check(struct fsl_mc_io *mc_io)
1507 u16 major_ver, minor_ver;
1509 if (!is_dpsparser_supported())
1512 error = dpsparser_get_api_version(mc_io, 0,
1516 printf("dpsparser_get_api_version() failed: %d\n", error);
1520 if (major_ver < DPSPARSER_VER_MAJOR || (major_ver ==
1521 DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) {
1522 printf("DPSPARSER version mismatch found %u.%u,",
1523 major_ver, minor_ver);
1524 printf("supported version is %u.%u\n",
1525 DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR);
1531 static int dpsparser_init(void)
1535 if (!is_dpsparser_supported())
1538 err = dpsparser_create(dflt_mc_io,
1543 printf("dpsparser_create() failed\n");
1545 err = dpsparser_version_check(dflt_mc_io);
1547 printf("dpsparser_version_check() failed: %d\n", err);
1548 goto err_version_check;
1551 err = dpsparser_open(dflt_mc_io,
1555 printf("dpsparser_open() failed: %d\n", err);
1563 dpsparser_destroy(dflt_mc_io,
1565 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1570 #ifdef DPSPARSER_DESTROY
1571 /* TODO: refactoring needed in the future to allow DPSPARSER object destroy
1572 * Workaround: DO NOT destroy DPSPARSER object because it needs to be available
1575 static int dpsparser_exit(void)
1579 if (!is_dpsparser_supported())
1582 dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle);
1584 printf("dpsparser_close() failed: %d\n", err);
1588 err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle,
1589 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1591 printf("dpsparser_destroy() failed: %d\n", err);
1601 int mc_apply_spb(u64 mc_spb_addr)
1604 u16 error, err_arr_size;
1607 struct sp_blob_header *sp_blob;
1608 u64 mc_ram_addr = mc_get_dram_addr();
1610 if (!is_dpsparser_supported())
1614 printf("fsl-mc: Invalid Blob address\n");
1618 #ifdef CONFIG_MC_DRAM_SPB_OFFSET
1619 mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET;
1621 #error "CONFIG_MC_DRAM_SPB_OFFSET not defined"
1624 // Read blob header and get size of SPB blob
1625 sp_blob = (struct sp_blob_header *)mc_spb_addr;
1626 spb_size = le32_to_cpu(sp_blob->length);
1627 if (spb_size > CONFIG_MC_SPB_MAX_SIZE) {
1628 printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n",
1633 mc_copy_image("MC SP Blob", mc_spb_addr, spb_size,
1634 mc_ram_addr + mc_spb_offset);
1636 //Invoke MC command to apply SPB blob
1637 printf("fsl-mc: Applying soft parser blob... ");
1638 err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle,
1639 mc_spb_offset, &error);
1644 printf("SUCCESS\n");
1646 printf("FAILED with error code = %d:\n", error);
1647 err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb);
1649 if (error > 0 && error < err_arr_size)
1650 printf(mc_err_msg_apply_spb[error]);
1652 printf(MC_ERROR_MSG_SPB_UNKNOWN);
1658 static int mc_init_object(void)
1664 printf("dprc_init() failed: %d\n", err);
1670 printf("dpbp_init() failed: %d\n", err);
1676 printf("dpio_init() failed: %d\n", err);
1682 printf("dpni_init() failed: %d\n", err);
1686 err = dpsparser_init();
1688 printf("dpsparser_init() failed: %d\n", err);
1697 int fsl_mc_ldpaa_exit(struct bd_info *bd)
1700 bool is_dpl_apply_status = false;
1701 bool mc_boot_status = false;
1703 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
1704 err = mc_apply_dpl(mc_lazy_dpl_addr);
1706 fdt_fixup_board_enet(working_fdt);
1707 mc_lazy_dpl_addr = 0;
1710 if (!get_mc_boot_status())
1711 mc_boot_status = true;
1713 /* MC is not loaded intentionally, So return success. */
1714 if (bd && !mc_boot_status)
1717 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1718 if (!get_dpl_apply_status())
1719 is_dpl_apply_status = true;
1722 * For case MC is loaded but DPL is not deployed, return success and
1723 * print message on console. Else FDT fix-up code execution hanged.
1725 if (bd && mc_boot_status && !is_dpl_apply_status) {
1726 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
1727 goto mc_obj_cleanup;
1730 if (bd && mc_boot_status && is_dpl_apply_status)
1736 printf("dpbp_exit() failed: %d\n", err);
1742 printf("dpio_exit() failed: %d\n", err);
1748 printf("dpni_exit() failed: %d\n", err);
1754 printf("dprc_exit() failed: %d\n", err);
1763 static void print_k_bytes(const void *buf, ssize_t *size)
1766 int count = printf("%s", (char *)buf);
1773 static void mc_dump_log(void)
1775 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
1776 u64 high = in_le64(&mc_ccsr_regs->reg_mcfbahr) & MC_FW_ADDR_MASK_HIGH;
1777 u64 low = in_le64(&mc_ccsr_regs->reg_mcfbalr) & MC_FW_ADDR_MASK_LOW;
1778 u32 buf_len, wrapped, last_byte, magic, buf_start;
1779 u64 mc_addr = (high << 32) | low;
1780 struct log_header *header;
1781 ssize_t size, bytes_end;
1782 const void *end_of_data;
1783 const void *map_addr;
1784 const void *end_addr;
1785 const void *cur_ptr;
1788 map_addr = map_sysmem(mc_addr + MC_STRUCT_BUFFER_OFFSET,
1790 header = (struct log_header *)map_addr;
1791 last_byte = in_le32(&header->last_byte);
1792 buf_len = in_le32(&header->buf_length);
1793 magic = in_le32(&header->magic_word);
1794 buf_start = in_le32(&header->buf_start);
1795 buf = map_addr + buf_start - MC_OFFSET_DELTA;
1796 end_addr = buf + buf_len;
1797 wrapped = last_byte & LOG_HEADER_FLAG_BUFFER_WRAPAROUND;
1798 end_of_data = buf + LAST_BYTE(last_byte);
1800 if (magic != MAGIC_MC) {
1801 puts("Magic number is not valid\n");
1802 printf("expected = %08x, received = %08x\n", MAGIC_MC, magic);
1806 if (wrapped && end_of_data != end_addr)
1807 cur_ptr = end_of_data + 1;
1811 if (cur_ptr <= end_of_data)
1812 size = end_of_data - cur_ptr;
1814 size = (end_addr - cur_ptr) + (end_of_data - buf);
1816 bytes_end = end_addr - cur_ptr;
1817 if (size > bytes_end) {
1818 print_k_bytes(cur_ptr, &bytes_end);
1824 print_k_bytes(buf, &size);
1827 unmap_sysmem(map_addr);
1830 static int do_fsl_mc(struct cmd_tbl *cmdtp, int flag, int argc,
1837 switch (argv[1][0]) {
1840 u64 mc_fw_addr, mc_dpc_addr;
1841 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1847 sub_cmd = argv[2][0];
1854 if (get_mc_boot_status() == 0) {
1855 printf("fsl-mc: MC is already booted");
1859 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1860 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1863 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1864 err = mc_init_object();
1867 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1871 if (get_aiop_apply_status() == 0) {
1872 printf("fsl-mc: AIOP FW is already");
1873 printf(" applied\n");
1877 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1880 /* if SoC doesn't have AIOP, err = -ENODEV */
1881 err = load_mc_aiop_img(aiop_fw_addr);
1883 printf("fsl-mc: AIOP FW applied\n");
1887 printf("Invalid option: %s\n", argv[2]);
1902 if (get_dpl_apply_status() == 0) {
1903 printf("fsl-mc: DPL already applied\n");
1907 mc_dpl_addr = simple_strtoull(argv[3], NULL, 16);
1909 if (get_mc_boot_status() != 0) {
1910 printf("fsl-mc: Deploying data path layout ..");
1911 printf("ERROR (MC is not booted)\n");
1916 * We will do the actual dpaa exit and dpl apply
1917 * later from announce_and_cleanup().
1919 mc_lazy_dpl_addr = mc_dpl_addr;
1931 sub_cmd = argv[2][0];
1936 if (get_dpl_apply_status() == 0) {
1937 printf("fsl-mc: DPL already applied\n");
1940 if (get_mc_boot_status() != 0) {
1941 printf("fsl-mc: Deploying data path layout ..");
1942 printf("ERROR (MC is not booted)\n");
1946 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1948 /* The user wants DPL applied now */
1949 if (!fsl_mc_ldpaa_exit(NULL))
1950 err = mc_apply_dpl(mc_apply_addr);
1954 if (!is_dpsparser_supported()) {
1955 printf("fsl-mc: apply spb command .. ");
1956 printf("ERROR: requires at least MC 10.12.0\n");
1959 if (get_mc_boot_status() != 0) {
1960 printf("fsl-mc: Deploying Soft Parser Blob...");
1961 printf("ERROR (MC is not booted)\n");
1965 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1967 /* Apply spb (Soft Parser Blob) */
1968 err = mc_apply_spb(mc_apply_addr);
1972 printf("Invalid option: %s\n", argv[2]);
1984 printf("Invalid option: %s\n", argv[1]);
1990 return CMD_RET_USAGE;
1994 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1995 "DPAA2 command to manage Management Complex (MC)",
1996 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1997 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
1998 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
1999 "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n"
2000 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
2001 "fsl_mc dump_log - Dump MC Log\n"
2004 void mc_env_boot(void)
2006 #if defined(CONFIG_FSL_MC_ENET)
2007 char *mc_boot_env_var;
2008 /* The MC may only be initialized in the reset PHY function
2009 * because otherwise U-Boot has not yet set up all the MAC
2010 * address info properly. Without MAC addresses, the MC code
2011 * can not properly initialize the DPC.
2013 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
2014 if (mc_boot_env_var)
2015 run_command_list(mc_boot_env_var, -1, 0);
2016 #endif /* CONFIG_FSL_MC_ENET */