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>
32 #include <net/ldpaa_eth.h>
34 #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
35 #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
36 #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
38 #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
39 #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
40 #define MC_BOOT_ENV_VAR "mcinitcmd"
41 #define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024)
43 #define MC_BUFFER_SIZE (1024 * 1024 * 16)
44 #define MAGIC_MC 0x4d430100
45 #define MC_FW_ADDR_MASK_LOW 0xE0000000
46 #define MC_FW_ADDR_MASK_HIGH 0X1FFFF
47 #define MC_STRUCT_BUFFER_OFFSET 0x01000000
48 #define MC_OFFSET_DELTA MC_STRUCT_BUFFER_OFFSET
50 #define LOG_HEADER_FLAG_BUFFER_WRAPAROUND 0x80000000
51 #define LAST_BYTE(a) ((a) & ~(LOG_HEADER_FLAG_BUFFER_WRAPAROUND))
53 DECLARE_GLOBAL_DATA_PTR;
54 static int mc_memset_resv_ram;
55 static struct mc_version mc_ver_info;
56 static int mc_boot_status = -1;
57 static int mc_dpl_applied = -1;
58 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
59 static int mc_aiop_applied = -1;
61 struct fsl_mc_io *root_mc_io = NULL;
62 struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
63 uint16_t root_dprc_handle = 0;
64 uint16_t dflt_dprc_handle = 0;
66 struct fsl_dpbp_obj *dflt_dpbp = NULL;
67 struct fsl_dpio_obj *dflt_dpio = NULL;
68 struct fsl_dpni_obj *dflt_dpni = NULL;
69 static u64 mc_lazy_dpl_addr;
70 static u32 dpsparser_obj_id;
71 static u16 dpsparser_handle;
72 static char *mc_err_msg_apply_spb[] = MC_ERROR_MSG_APPLY_SPB;
75 void dump_ram_words(const char *title, void *addr)
78 uint32_t *words = addr;
80 printf("Dumping beginning of %s (%p):\n", title, addr);
81 for (i = 0; i < 16; i++)
82 printf("%#x ", words[i]);
87 void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
89 printf("MC CCSR registers:\n"
99 mc_ccsr_regs->reg_gcr1,
100 mc_ccsr_regs->reg_gsr,
101 mc_ccsr_regs->reg_sicbalr,
102 mc_ccsr_regs->reg_sicbahr,
103 mc_ccsr_regs->reg_sicapr,
104 mc_ccsr_regs->reg_mcfbalr,
105 mc_ccsr_regs->reg_mcfbahr,
106 mc_ccsr_regs->reg_mcfapr,
107 mc_ccsr_regs->reg_psr);
111 #define dump_ram_words(title, addr)
112 #define dump_mc_ccsr_regs(mc_ccsr_regs)
117 * Copying MC firmware or DPL image to DDR
119 static int mc_copy_image(const char *title,
120 u64 image_addr, u32 image_size, u64 mc_ram_addr)
122 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
123 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
124 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
128 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
130 * MC firmware FIT image parser checks if the image is in FIT
131 * format, verifies integrity of the image and calculates
132 * raw image address and size values.
133 * Returns 0 on success and a negative errno on error.
136 int parse_mc_firmware_fit_image(u64 mc_fw_addr,
137 const void **raw_image_addr,
138 size_t *raw_image_size)
141 void *fit_hdr = (void *)mc_fw_addr;
143 /* Check if Image is in FIT format */
144 format = genimg_get_format(fit_hdr);
146 if (format != IMAGE_FORMAT_FIT) {
147 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
151 if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
152 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
156 return fit_get_data_node(fit_hdr, "firmware", raw_image_addr,
161 #define MC_DT_INCREASE_SIZE 64
168 static int mc_fixup_mac_addr(void *blob, int nodeoffset,
169 const char *propname, struct udevice *eth_dev,
170 enum mc_fixup_type type)
172 struct eth_pdata *plat = dev_get_plat(eth_dev);
173 unsigned char *enetaddr = plat->enetaddr;
174 int eth_index = dev_seq(eth_dev);
175 int err = 0, len = 0, size, i;
176 unsigned char env_enetaddr[ARP_HLEN];
177 unsigned int enetaddr_32[ARP_HLEN];
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(enetaddr[i]);
186 len = sizeof(enetaddr_32);
194 /* MAC address property present */
195 if (fdt_get_property(blob, nodeoffset, propname, NULL)) {
196 /* u-boot MAC addr randomly assigned - leave the present one */
197 if (!eth_env_get_enetaddr_by_index("eth", eth_index,
201 size = MC_DT_INCREASE_SIZE + strlen(propname) + len;
202 /* make room for mac address property */
203 err = fdt_increase_size(blob, size);
205 printf("fdt_increase_size: err=%s\n",
211 err = fdt_setprop(blob, nodeoffset, propname, val, len);
213 printf("fdt_setprop: err=%s\n", fdt_strerror(err));
220 #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
222 const char *dpl_get_connection_endpoint(void *blob, char *endpoint)
224 int connoffset = fdt_path_offset(blob, "/connections"), off;
227 for (off = fdt_first_subnode(blob, connoffset);
229 off = fdt_next_subnode(blob, off)) {
230 s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL);
231 s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL);
236 if (strcmp(endpoint, s1) == 0)
239 if (strcmp(endpoint, s2) == 0)
246 static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id,
247 struct udevice *eth_dev)
249 int objoff = fdt_path_offset(blob, "/objects");
250 int dpmacoff = -1, dpnioff = -1;
251 const char *endpoint;
255 sprintf(mac_name, "dpmac@%d", dpmac_id);
256 dpmacoff = fdt_subnode_offset(blob, objoff, mac_name);
258 /* dpmac not defined in DPL, so skip it. */
261 err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev,
264 printf("Error fixing up dpmac mac_addr in DPL\n");
268 /* now we need to figure out if there is any
269 * DPNI connected to this MAC, so we walk the
272 endpoint = dpl_get_connection_endpoint(blob, mac_name);
273 if (!is_dpni(endpoint))
276 /* let's see if we can fixup the DPNI as well */
277 dpnioff = fdt_subnode_offset(blob, objoff, endpoint);
279 /* DPNI not defined in DPL in the objects area */
282 return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev,
286 void fdt_fixup_mc_ddr(u64 *base, u64 *size)
288 u64 mc_size = mc_get_dram_block_size();
290 if (mc_size < MC_DRAM_BLOCK_DEFAULT_SIZE) {
291 *base = mc_get_dram_addr() + mc_size;
292 *size = MC_DRAM_BLOCK_DEFAULT_SIZE - mc_size;
296 void fdt_fsl_mc_fixup_iommu_map_entry(void *blob)
299 u32 iommu_map[4], phandle;
303 /* find fsl-mc node */
304 offset = fdt_path_offset(blob, "/soc/fsl-mc");
306 offset = fdt_path_offset(blob, "/fsl-mc");
308 printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n",
313 prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp);
315 debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n",
320 iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
321 iommu_map[1] = *++prop;
322 iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
323 iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END -
324 FSL_DPAA2_STREAM_ID_START + 1);
326 fdt_setprop_inplace(blob, offset, "iommu-map",
327 iommu_map, sizeof(iommu_map));
329 /* get phandle to MSI controller */
330 prop = (u32 *)fdt_getprop(blob, offset, "msi-parent", 0);
332 debug("\n%s: ERROR: missing msi-parent\n", __func__);
335 phandle = fdt32_to_cpu(*prop);
337 /* also set msi-map property */
338 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START);
339 fdt_appendprop_u32(blob, offset, "msi-map", phandle);
340 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START);
341 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_END -
342 FSL_DPAA2_STREAM_ID_START + 1);
345 static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
346 struct udevice *eth_dev)
348 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
351 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
353 sprintf(mac_name, "mac@%d", dpmac_id);
355 /* node not found - create it */
356 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
358 err = fdt_increase_size(blob, 200);
360 printf("fdt_increase_size: err=%s\n", fdt_strerror(err));
364 noff = fdt_add_subnode(blob, nodeoffset, mac_name);
366 printf("fdt_add_subnode: err=%s\n",
371 /* add default property of fixed link */
372 err = fdt_appendprop_string(blob, noff,
373 "link_type", link_type_mode);
375 printf("fdt_appendprop_string: err=%s\n",
381 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
385 static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
387 struct udevice *eth_dev;
388 int err = 0, ret = 0;
392 uclass_get(UCLASS_ETH, &uc);
393 uclass_foreach_dev(eth_dev, uc) {
394 if (!eth_dev->driver || !eth_dev->driver->name ||
395 strcmp(eth_dev->driver->name, LDPAA_ETH_DRIVER_NAME))
398 dpmac_id = ldpaa_eth_get_dpmac_id(eth_dev);
401 err = mc_fixup_dpl_mac_addr(blob, dpmac_id, eth_dev);
404 err = mc_fixup_dpc_mac_addr(blob, dpmac_id, eth_dev);
411 printf("fsl-mc: ERROR fixing mac address for %s\n", eth_dev->name);
418 static int mc_fixup_dpc(u64 dpc_addr)
420 void *blob = (void *)dpc_addr;
421 int nodeoffset, err = 0;
423 /* delete any existing ICID pools */
424 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
425 if (fdt_del_node(blob, nodeoffset) < 0)
426 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
429 nodeoffset = fdt_path_offset(blob, "/resources");
430 if (nodeoffset < 0) {
431 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
434 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
435 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
436 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
437 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
438 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
440 FSL_DPAA2_STREAM_ID_END -
441 FSL_DPAA2_STREAM_ID_START + 1, 1);
443 /* fixup MAC addresses for dpmac ports */
444 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
445 if (nodeoffset < 0) {
446 err = fdt_increase_size(blob, 512);
448 printf("fdt_increase_size: err=%s\n",
452 nodeoffset = fdt_path_offset(blob, "/board_info");
454 nodeoffset = fdt_add_subnode(blob, 0, "board_info");
456 nodeoffset = fdt_add_subnode(blob, nodeoffset, "ports");
459 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
462 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
467 static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
470 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
476 #ifdef CFG_SYS_LS_MC_DRAM_DPC_OFFSET
477 BUILD_BUG_ON((CFG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
478 CFG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
480 mc_dpc_offset = CFG_SYS_LS_MC_DRAM_DPC_OFFSET;
482 #error "CFG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
486 * Load the MC DPC blob in the MC private DRAM block:
488 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
489 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
492 * Get address and size of the DPC blob stored in flash:
494 dpc_fdt_hdr = (void *)mc_dpc_addr;
496 error = fdt_check_header(dpc_fdt_hdr);
499 * Don't return with error here, since the MC firmware can
500 * still boot without a DPC
502 printf("\nfsl-mc: WARNING: No DPC image found");
506 dpc_size = fdt_totalsize(dpc_fdt_hdr);
507 if (dpc_size > CFG_SYS_LS_MC_DPC_MAX_LENGTH) {
508 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
513 mc_copy_image("MC DPC blob",
514 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
515 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
517 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
520 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
524 static int mc_fixup_dpl(u64 dpl_addr)
526 void *blob = (void *)dpl_addr;
527 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
530 /* The DPL fixup for mac addresses is only relevant
536 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
537 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
542 static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
545 #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
551 #ifdef CFG_SYS_LS_MC_DRAM_DPL_OFFSET
552 BUILD_BUG_ON((CFG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
553 CFG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
555 mc_dpl_offset = CFG_SYS_LS_MC_DRAM_DPL_OFFSET;
557 #error "CFG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
561 * Load the MC DPL blob in the MC private DRAM block:
563 #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
564 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
567 * Get address and size of the DPL blob stored in flash:
569 dpl_fdt_hdr = (void *)mc_dpl_addr;
571 error = fdt_check_header(dpl_fdt_hdr);
573 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
577 dpl_size = fdt_totalsize(dpl_fdt_hdr);
578 if (dpl_size > CFG_SYS_LS_MC_DPL_MAX_LENGTH) {
579 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
584 mc_copy_image("MC DPL blob",
585 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
586 #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
588 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
590 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
595 * Return the MC boot timeout value in milliseconds
597 static unsigned long get_mc_boot_timeout_ms(void)
599 unsigned long timeout_ms = CFG_SYS_LS_MC_BOOT_TIMEOUT_MS;
601 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
603 if (timeout_ms_env_var) {
604 timeout_ms = dectoul(timeout_ms_env_var, NULL);
605 if (timeout_ms == 0) {
606 printf("fsl-mc: WARNING: Invalid value for \'"
607 MC_BOOT_TIMEOUT_ENV_VAR
608 "\' environment variable: %lu\n",
611 timeout_ms = CFG_SYS_LS_MC_BOOT_TIMEOUT_MS;
618 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
620 __weak bool soc_has_aiop(void)
625 static int load_mc_aiop_img(u64 aiop_fw_addr)
627 u64 mc_ram_addr = mc_get_dram_addr();
628 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
632 /* Check if AIOP is available */
636 * Load the MC AIOP image in the MC private DRAM block:
639 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
640 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
641 CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
643 aiop_img = (void *)aiop_fw_addr;
644 mc_copy_image("MC AIOP image",
645 (u64)aiop_img, CFG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
646 mc_ram_addr + CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
654 static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
657 u32 mc_fw_boot_status;
658 unsigned long timeout_ms = get_mc_boot_timeout_ms();
659 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
662 assert(timeout_ms > 0);
664 udelay(1000); /* throttle polling */
665 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
666 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
667 if (mc_fw_boot_status & 0x1)
675 if (timeout_ms == 0) {
676 printf("ERROR: timeout\n");
678 /* TODO: Get an error status from an MC CCSR register */
682 if (mc_fw_boot_status != 0x1) {
684 * TODO: Identify critical errors from the GSR register's FS
685 * field and for those errors, set error to -ENODEV or other
686 * appropriate errno, so that the status property is set to
687 * failure in the fsl,dprc device tree node.
689 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
695 *final_reg_gsr = reg_gsr;
699 int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
703 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
704 u64 mc_ram_addr = mc_get_dram_addr();
707 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
708 const void *raw_image_addr;
709 size_t raw_image_size = 0;
711 u8 mc_ram_num_256mb_blocks;
712 size_t mc_ram_size = mc_get_dram_block_size();
714 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
716 if (mc_ram_num_256mb_blocks >= 0xff) {
718 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
724 * To support 128 MB DDR Size for MC
726 if (mc_ram_num_256mb_blocks == 0)
727 mc_ram_num_256mb_blocks = 0xFF;
730 * Management Complex cores should be held at reset out of POR.
731 * U-Boot should be the first software to touch MC. To be safe,
732 * we reset all cores again by setting GCR1 to 0. It doesn't do
733 * anything if they are held at reset. After we setup the firmware
734 * we kick off MC by deasserting the reset bit for core 0, and
735 * deasserting the reset bits for Command Portal Managers.
736 * The stop bits are not touched here. They are used to stop the
737 * cores when they are active. Setting stop bits doesn't stop the
738 * cores from fetching instructions when they are released from
741 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
744 #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
745 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
747 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
752 * Load the MC FW at the beginning of the MC private DRAM block:
754 mc_copy_image("MC Firmware",
755 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
757 dump_ram_words("firmware", (void *)mc_ram_addr);
759 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
763 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
764 dump_mc_ccsr_regs(mc_ccsr_regs);
767 * Tell MC what is the address range of the DRAM block assigned to it:
769 if (mc_ram_num_256mb_blocks < 0xFF) {
770 reg_mcfbalr = (u32)mc_ram_addr |
771 (mc_ram_num_256mb_blocks - 1);
773 reg_mcfbalr = (u32)mc_ram_addr |
774 (mc_ram_num_256mb_blocks);
777 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
778 out_le32(&mc_ccsr_regs->reg_mcfbahr,
779 (u32)(mc_ram_addr >> 32));
780 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
783 * Tell the MC that we want delayed DPL deployment.
785 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
787 printf("\nfsl-mc: Booting Management Complex ... ");
790 * Deassert reset and release MC core 0 to run
792 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
793 error = wait_for_mc(true, ®_gsr);
798 * TODO: need to obtain the portal_id for the root container from the
804 * Initialize the global default MC portal
805 * And check that the MC firmware is responding portal commands:
807 root_mc_io = calloc(sizeof(struct fsl_mc_io), 1);
809 printf(" No memory: calloc() failed\n");
813 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
814 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
815 portal_id, root_mc_io->mmio_regs);
817 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
819 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
824 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
825 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
826 reg_gsr & GSR_FS_MASK);
830 mc_boot_status = error;
837 int mc_apply_dpl(u64 mc_dpl_addr)
839 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
842 u64 mc_ram_addr = mc_get_dram_addr();
843 size_t mc_ram_size = mc_get_dram_block_size();
848 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
853 * Tell the MC to deploy the DPL:
855 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
856 printf("fsl-mc: Deploying data path layout ... ");
857 error = wait_for_mc(false, ®_gsr);
865 int get_mc_boot_status(void)
867 return mc_boot_status;
870 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
871 int get_aiop_apply_status(void)
873 return mc_aiop_applied;
877 int get_dpl_apply_status(void)
879 return mc_dpl_applied;
882 int is_lazy_dpl_addr_valid(void)
884 return !!mc_lazy_dpl_addr;
888 * Return the MC address of private DRAM block.
889 * As per MC design document, MC initial base address
890 * should be least significant 512MB address of MC private
891 * memory, i.e. address should point to end address masked
892 * with 512MB offset in private DRAM block.
894 u64 mc_get_dram_addr(void)
896 size_t mc_ram_size = mc_get_dram_block_size();
898 if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) {
899 mc_memset_resv_ram = 1;
900 memset((void *)gd->arch.resv_ram, 0, mc_ram_size);
903 return (gd->arch.resv_ram + mc_ram_size - 1) &
904 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
908 * Return the actual size of the MC private DRAM block.
910 unsigned long mc_get_dram_block_size(void)
912 unsigned long dram_block_size = CFG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
914 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
916 if (dram_block_size_env_var) {
917 dram_block_size = hextoul(dram_block_size_env_var, NULL);
919 if (dram_block_size < CFG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
920 printf("fsl-mc: WARNING: Invalid value for \'"
922 "\' environment variable: %lu\n",
925 dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE;
929 return dram_block_size;
932 int fsl_mc_ldpaa_init(struct bd_info *bis)
936 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
937 if (wriop_is_enabled_dpmac(i) == 1)
938 ldpaa_eth_init(i, wriop_get_enet_if(i));
942 static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
945 uint16_t major_ver, minor_ver;
947 error = dprc_get_api_version(mc_io, 0,
951 printf("dprc_get_api_version() failed: %d\n", error);
955 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
956 minor_ver < DPRC_VER_MINOR)) {
957 printf("DPRC version mismatch found %u.%u,",
958 major_ver, minor_ver);
959 printf("supported version is %u.%u\n",
960 DPRC_VER_MAJOR, DPRC_VER_MINOR);
966 static int dpio_init(void)
968 struct qbman_swp_desc p_des;
969 struct dpio_attr attr;
970 struct dpio_cfg dpio_cfg;
972 uint16_t major_ver, minor_ver;
974 dflt_dpio = calloc(sizeof(struct fsl_dpio_obj), 1);
976 printf("No memory: calloc() failed\n");
980 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
981 dpio_cfg.num_priorities = 8;
983 err = dpio_create(dflt_mc_io,
987 &dflt_dpio->dpio_id);
989 printf("dpio_create() failed: %d\n", err);
994 err = dpio_get_api_version(dflt_mc_io, 0,
998 printf("dpio_get_api_version() failed: %d\n", err);
999 goto err_get_api_ver;
1002 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
1003 minor_ver < DPIO_VER_MINOR)) {
1004 printf("DPRC version mismatch found %u.%u,",
1009 err = dpio_open(dflt_mc_io,
1012 &dflt_dpio->dpio_handle);
1014 printf("dpio_open() failed\n");
1018 memset(&attr, 0, sizeof(struct dpio_attr));
1019 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1020 dflt_dpio->dpio_handle, &attr);
1022 printf("dpio_get_attributes() failed: %d\n", err);
1026 if (dflt_dpio->dpio_id != attr.id) {
1027 printf("dnpi object id and attribute id are not same\n");
1028 goto err_attr_not_same;
1032 printf("Init: DPIO.%d\n", dflt_dpio->dpio_id);
1034 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1036 printf("dpio_enable() failed %d\n", err);
1037 goto err_get_enable;
1039 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
1040 attr.qbman_portal_ce_offset,
1041 attr.qbman_portal_ci_offset,
1042 attr.qbman_portal_id,
1043 attr.num_priorities);
1045 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1046 + attr.qbman_portal_ce_offset);
1047 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1048 + attr.qbman_portal_ci_offset);
1050 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
1051 if (dflt_dpio->sw_portal == NULL) {
1052 printf("qbman_swp_init() failed\n");
1053 goto err_get_swp_init;
1058 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1062 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1065 dpio_destroy(dflt_mc_io,
1068 dflt_dpio->dpio_id);
1075 static int dpio_exit(void)
1079 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1081 printf("dpio_disable() failed: %d\n", err);
1085 err = dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1087 printf("dpio_close() failed: %d\n", err);
1091 err = dpio_destroy(dflt_mc_io,
1094 dflt_dpio->dpio_id);
1096 printf("dpio_destroy() failed: %d\n", err);
1101 printf("Exit: DPIO.%d\n", dflt_dpio->dpio_id);
1112 static int dprc_init(void)
1114 int err, child_portal_id, container_id;
1115 struct dprc_cfg cfg;
1116 uint64_t mc_portal_offset;
1118 /* Open root container */
1119 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1121 printf("dprc_get_container_id(): Root failed: %d\n", err);
1122 goto err_root_container_id;
1126 printf("Root container id = %d\n", container_id);
1128 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1131 printf("dprc_open(): Root Container failed: %d\n", err);
1135 if (!root_dprc_handle) {
1136 printf("dprc_open(): Root Container Handle is not valid\n");
1140 err = dprc_version_check(root_mc_io, root_dprc_handle);
1142 printf("dprc_version_check() failed: %d\n", err);
1146 memset(&cfg, 0, sizeof(struct dprc_cfg));
1147 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1148 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1149 DPRC_CFG_OPT_ALLOC_ALLOWED;
1150 cfg.icid = DPRC_GET_ICID_FROM_POOL;
1151 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
1152 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1153 root_dprc_handle, &cfg,
1157 printf("dprc_create_container() failed: %d\n", err);
1161 dflt_mc_io = calloc(sizeof(struct fsl_mc_io), 1);
1164 printf(" No memory: calloc() failed\n");
1168 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1169 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
1172 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1173 child_dprc_id, dflt_mc_io->mmio_regs);
1176 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1179 printf("dprc_open(): Child container failed: %d\n", err);
1180 goto err_child_open;
1183 if (!dflt_dprc_handle) {
1184 printf("dprc_open(): Child container Handle is not valid\n");
1185 goto err_child_open;
1192 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1193 root_dprc_handle, child_dprc_id);
1195 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1197 err_root_container_id:
1201 static int dprc_exit(void)
1205 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1207 printf("dprc_close(): Child failed: %d\n", err);
1211 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1212 root_dprc_handle, child_dprc_id);
1214 printf("dprc_destroy_container() failed: %d\n", err);
1218 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1220 printf("dprc_close(): Root failed: %d\n", err);
1236 static int dpbp_init(void)
1239 struct dpbp_attr dpbp_attr;
1240 struct dpbp_cfg dpbp_cfg;
1241 uint16_t major_ver, minor_ver;
1243 dflt_dpbp = calloc(sizeof(struct fsl_dpbp_obj), 1);
1245 printf("No memory: calloc() failed\n");
1250 dpbp_cfg.options = 512;
1252 err = dpbp_create(dflt_mc_io,
1256 &dflt_dpbp->dpbp_id);
1260 printf("dpbp_create() failed: %d\n", err);
1264 err = dpbp_get_api_version(dflt_mc_io, 0,
1268 printf("dpbp_get_api_version() failed: %d\n", err);
1269 goto err_get_api_ver;
1272 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1273 minor_ver < DPBP_VER_MINOR)) {
1274 printf("DPBP version mismatch found %u.%u,",
1275 major_ver, minor_ver);
1276 printf("supported version is %u.%u\n",
1277 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1280 err = dpbp_open(dflt_mc_io,
1283 &dflt_dpbp->dpbp_handle);
1285 printf("dpbp_open() failed\n");
1289 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1290 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1291 dflt_dpbp->dpbp_handle,
1294 printf("dpbp_get_attributes() failed: %d\n", err);
1298 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1299 printf("dpbp object id and attribute id are not same\n");
1300 goto err_attr_not_same;
1304 printf("Init: DPBP.%d\n", dflt_dpbp->dpbp_attr.id);
1307 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1309 printf("dpbp_close() failed: %d\n", err);
1317 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1318 dpbp_destroy(dflt_mc_io,
1321 dflt_dpbp->dpbp_id);
1331 static int dpbp_exit(void)
1335 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1336 dflt_dpbp->dpbp_id);
1338 printf("dpbp_destroy() failed: %d\n", err);
1343 printf("Exit: DPBP.%d\n", dflt_dpbp->dpbp_attr.id);
1354 static int dpni_init(void)
1356 struct dpni_cfg dpni_cfg = {0};
1357 uint16_t major_ver, minor_ver;
1360 dflt_dpni = calloc(sizeof(struct fsl_dpni_obj), 1);
1362 printf("No memory: calloc() failed\n");
1367 err = dpni_create(dflt_mc_io,
1371 &dflt_dpni->dpni_id);
1374 printf("dpni create() failed: %d\n", err);
1378 err = dpni_get_api_version(dflt_mc_io, 0,
1382 printf("dpni_get_api_version() failed: %d\n", err);
1383 goto err_get_version;
1386 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1387 minor_ver < DPNI_VER_MINOR)) {
1388 printf("DPNI version mismatch found %u.%u,",
1389 major_ver, minor_ver);
1390 printf("supported version is %u.%u\n",
1391 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1394 err = dpni_open(dflt_mc_io,
1397 &dflt_dpni->dpni_handle);
1399 printf("dpni_open() failed\n");
1404 printf("Init: DPNI.%d\n", dflt_dpni->dpni_id);
1406 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1408 printf("dpni_close() failed: %d\n", err);
1415 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1418 dpni_destroy(dflt_mc_io,
1421 dflt_dpni->dpni_id);
1428 static int dpni_exit(void)
1432 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1433 dflt_dpni->dpni_id);
1435 printf("dpni_destroy() failed: %d\n", err);
1440 printf("Exit: DPNI.%d\n", dflt_dpni->dpni_id);
1451 static bool is_dpsparser_supported(void)
1453 /* dpsparser support was first introduced in MC version: 10.12.0 */
1454 if (mc_ver_info.major < 10)
1456 if (mc_ver_info.major == 10)
1457 return (mc_ver_info.minor >= 12);
1461 static int dpsparser_version_check(struct fsl_mc_io *mc_io)
1464 u16 major_ver, minor_ver;
1466 if (!is_dpsparser_supported())
1469 error = dpsparser_get_api_version(mc_io, 0,
1473 printf("dpsparser_get_api_version() failed: %d\n", error);
1477 if (major_ver < DPSPARSER_VER_MAJOR || (major_ver ==
1478 DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) {
1479 printf("DPSPARSER version mismatch found %u.%u,",
1480 major_ver, minor_ver);
1481 printf("supported version is %u.%u\n",
1482 DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR);
1488 static int dpsparser_init(void)
1492 if (!is_dpsparser_supported())
1495 err = dpsparser_create(dflt_mc_io,
1500 printf("dpsparser_create() failed\n");
1502 err = dpsparser_version_check(dflt_mc_io);
1504 printf("dpsparser_version_check() failed: %d\n", err);
1505 goto err_version_check;
1508 err = dpsparser_open(dflt_mc_io,
1512 printf("dpsparser_open() failed: %d\n", err);
1520 dpsparser_destroy(dflt_mc_io,
1522 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1527 #ifdef DPSPARSER_DESTROY
1528 /* TODO: refactoring needed in the future to allow DPSPARSER object destroy
1529 * Workaround: DO NOT destroy DPSPARSER object because it needs to be available
1532 static int dpsparser_exit(void)
1536 if (!is_dpsparser_supported())
1539 dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle);
1541 printf("dpsparser_close() failed: %d\n", err);
1545 err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle,
1546 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1548 printf("dpsparser_destroy() failed: %d\n", err);
1558 int mc_apply_spb(u64 mc_spb_addr)
1561 u16 error, err_arr_size;
1564 struct sp_blob_header *sp_blob;
1565 u64 mc_ram_addr = mc_get_dram_addr();
1567 if (!is_dpsparser_supported())
1571 printf("fsl-mc: Invalid Blob address\n");
1575 #ifdef CONFIG_MC_DRAM_SPB_OFFSET
1576 mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET;
1578 #error "CONFIG_MC_DRAM_SPB_OFFSET not defined"
1581 // Read blob header and get size of SPB blob
1582 sp_blob = (struct sp_blob_header *)mc_spb_addr;
1583 spb_size = le32_to_cpu(sp_blob->length);
1584 if (spb_size > CONFIG_MC_SPB_MAX_SIZE) {
1585 printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n",
1590 mc_copy_image("MC SP Blob", mc_spb_addr, spb_size,
1591 mc_ram_addr + mc_spb_offset);
1593 //Invoke MC command to apply SPB blob
1594 printf("fsl-mc: Applying soft parser blob... ");
1595 err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle,
1596 mc_spb_offset, &error);
1601 printf("SUCCESS\n");
1603 printf("FAILED with error code = %d:\n", error);
1604 err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb);
1606 if (error > 0 && error < err_arr_size)
1607 printf(mc_err_msg_apply_spb[error]);
1609 printf(MC_ERROR_MSG_SPB_UNKNOWN);
1615 static int mc_init_object(void)
1621 printf("dprc_init() failed: %d\n", err);
1627 printf("dpbp_init() failed: %d\n", err);
1633 printf("dpio_init() failed: %d\n", err);
1639 printf("dpni_init() failed: %d\n", err);
1643 err = dpsparser_init();
1645 printf("dpsparser_init() failed: %d\n", err);
1654 int fsl_mc_ldpaa_exit(struct bd_info *bd)
1657 bool is_dpl_apply_status = false;
1658 bool mc_boot_status = false;
1660 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
1661 err = mc_apply_dpl(mc_lazy_dpl_addr);
1663 fdt_fixup_board_enet(working_fdt);
1664 mc_lazy_dpl_addr = 0;
1667 if (!get_mc_boot_status())
1668 mc_boot_status = true;
1670 /* MC is not loaded intentionally, So return success. */
1671 if (bd && !mc_boot_status)
1674 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1675 if (!get_dpl_apply_status())
1676 is_dpl_apply_status = true;
1679 * For case MC is loaded but DPL is not deployed, return success and
1680 * print message on console. Else FDT fix-up code execution hanged.
1682 if (bd && mc_boot_status && !is_dpl_apply_status) {
1683 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
1684 goto mc_obj_cleanup;
1687 if (bd && mc_boot_status && is_dpl_apply_status)
1693 printf("dpbp_exit() failed: %d\n", err);
1699 printf("dpio_exit() failed: %d\n", err);
1705 printf("dpni_exit() failed: %d\n", err);
1711 printf("dprc_exit() failed: %d\n", err);
1720 static void print_k_bytes(const void *buf, ssize_t *size)
1723 int count = printf("%s", (char *)buf);
1730 static void mc_dump_log(void)
1732 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
1733 u64 high = in_le64(&mc_ccsr_regs->reg_mcfbahr) & MC_FW_ADDR_MASK_HIGH;
1734 u64 low = in_le64(&mc_ccsr_regs->reg_mcfbalr) & MC_FW_ADDR_MASK_LOW;
1735 u32 buf_len, wrapped, last_byte, magic, buf_start;
1736 u64 mc_addr = (high << 32) | low;
1737 struct log_header *header;
1738 ssize_t size, bytes_end;
1739 const void *end_of_data;
1740 const void *map_addr;
1741 const void *end_addr;
1742 const void *cur_ptr;
1745 map_addr = map_sysmem(mc_addr + MC_STRUCT_BUFFER_OFFSET,
1747 header = (struct log_header *)map_addr;
1748 last_byte = in_le32(&header->last_byte);
1749 buf_len = in_le32(&header->buf_length);
1750 magic = in_le32(&header->magic_word);
1751 buf_start = in_le32(&header->buf_start);
1752 buf = map_addr + buf_start - MC_OFFSET_DELTA;
1753 end_addr = buf + buf_len;
1754 wrapped = last_byte & LOG_HEADER_FLAG_BUFFER_WRAPAROUND;
1755 end_of_data = buf + LAST_BYTE(last_byte);
1757 if (magic != MAGIC_MC) {
1758 puts("Magic number is not valid\n");
1759 printf("expected = %08x, received = %08x\n", MAGIC_MC, magic);
1763 if (wrapped && end_of_data != end_addr)
1764 cur_ptr = end_of_data + 1;
1768 if (cur_ptr <= end_of_data)
1769 size = end_of_data - cur_ptr;
1771 size = (end_addr - cur_ptr) + (end_of_data - buf);
1773 bytes_end = end_addr - cur_ptr;
1774 if (size > bytes_end) {
1775 print_k_bytes(cur_ptr, &bytes_end);
1780 print_k_bytes(buf, &size);
1783 unmap_sysmem(map_addr);
1786 static int do_fsl_mc(struct cmd_tbl *cmdtp, int flag, int argc,
1793 switch (argv[1][0]) {
1796 u64 mc_fw_addr, mc_dpc_addr;
1797 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1803 sub_cmd = argv[2][0];
1810 if (get_mc_boot_status() == 0) {
1811 printf("fsl-mc: MC is already booted");
1815 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1816 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1819 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1820 err = mc_init_object();
1823 #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1827 if (get_aiop_apply_status() == 0) {
1828 printf("fsl-mc: AIOP FW is already");
1829 printf(" applied\n");
1833 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1836 /* if SoC doesn't have AIOP, err = -ENODEV */
1837 err = load_mc_aiop_img(aiop_fw_addr);
1839 printf("fsl-mc: AIOP FW applied\n");
1843 printf("Invalid option: %s\n", argv[2]);
1858 if (get_dpl_apply_status() == 0) {
1859 printf("fsl-mc: DPL already applied\n");
1863 mc_dpl_addr = simple_strtoull(argv[3], NULL, 16);
1865 if (get_mc_boot_status() != 0) {
1866 printf("fsl-mc: Deploying data path layout ..");
1867 printf("ERROR (MC is not booted)\n");
1872 * We will do the actual dpaa exit and dpl apply
1873 * later from announce_and_cleanup().
1875 mc_lazy_dpl_addr = mc_dpl_addr;
1887 sub_cmd = argv[2][0];
1892 if (get_dpl_apply_status() == 0) {
1893 printf("fsl-mc: DPL already applied\n");
1896 if (get_mc_boot_status() != 0) {
1897 printf("fsl-mc: Deploying data path layout ..");
1898 printf("ERROR (MC is not booted)\n");
1902 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1904 /* The user wants DPL applied now */
1905 if (!fsl_mc_ldpaa_exit(NULL))
1906 err = mc_apply_dpl(mc_apply_addr);
1910 if (!is_dpsparser_supported()) {
1911 printf("fsl-mc: apply spb command .. ");
1912 printf("ERROR: requires at least MC 10.12.0\n");
1915 if (get_mc_boot_status() != 0) {
1916 printf("fsl-mc: Deploying Soft Parser Blob...");
1917 printf("ERROR (MC is not booted)\n");
1921 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1923 /* Apply spb (Soft Parser Blob) */
1924 err = mc_apply_spb(mc_apply_addr);
1928 printf("Invalid option: %s\n", argv[2]);
1940 printf("Invalid option: %s\n", argv[1]);
1945 return CMD_RET_USAGE;
1949 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1950 "DPAA2 command to manage Management Complex (MC)",
1951 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1952 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
1953 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
1954 "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n"
1955 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1956 "fsl_mc dump_log - Dump MC Log\n"
1959 void mc_env_boot(void)
1961 #if defined(CONFIG_FSL_MC_ENET)
1962 char *mc_boot_env_var;
1963 /* The MC may only be initialized in the reset PHY function
1964 * because otherwise U-Boot has not yet set up all the MAC
1965 * address info properly. Without MAC addresses, the MC code
1966 * can not properly initialize the DPC.
1968 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
1969 if (mc_boot_env_var)
1970 run_command_list(mc_boot_env_var, -1, 0);
1971 #endif /* CONFIG_FSL_MC_ENET */