1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 Freescale Semiconductor, Inc.
5 * Copyright 2017-2018 NXP
11 #include <linux/libfdt.h>
13 #include <fdt_support.h>
14 #include <fsl-mc/fsl_mc.h>
15 #include <fsl-mc/fsl_mc_sys.h>
16 #include <fsl-mc/fsl_mc_private.h>
17 #include <fsl-mc/fsl_dpmng.h>
18 #include <fsl-mc/fsl_dprc.h>
19 #include <fsl-mc/fsl_dpio.h>
20 #include <fsl-mc/fsl_dpni.h>
21 #include <fsl-mc/fsl_qbman_portal.h>
22 #include <fsl-mc/ldpaa_wriop.h>
24 #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
25 #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
26 #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
28 #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
29 #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
30 #define MC_BOOT_ENV_VAR "mcinitcmd"
31 #define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024)
33 DECLARE_GLOBAL_DATA_PTR;
34 static int mc_memset_resv_ram;
35 static int mc_boot_status = -1;
36 static int mc_dpl_applied = -1;
37 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
38 static int mc_aiop_applied = -1;
40 struct fsl_mc_io *root_mc_io = NULL;
41 struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
42 uint16_t root_dprc_handle = 0;
43 uint16_t dflt_dprc_handle = 0;
45 struct fsl_dpbp_obj *dflt_dpbp = NULL;
46 struct fsl_dpio_obj *dflt_dpio = NULL;
47 struct fsl_dpni_obj *dflt_dpni = NULL;
48 static u64 mc_lazy_dpl_addr;
51 void dump_ram_words(const char *title, void *addr)
54 uint32_t *words = addr;
56 printf("Dumping beginning of %s (%p):\n", title, addr);
57 for (i = 0; i < 16; i++)
58 printf("%#x ", words[i]);
63 void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
65 printf("MC CCSR registers:\n"
75 mc_ccsr_regs->reg_gcr1,
76 mc_ccsr_regs->reg_gsr,
77 mc_ccsr_regs->reg_sicbalr,
78 mc_ccsr_regs->reg_sicbahr,
79 mc_ccsr_regs->reg_sicapr,
80 mc_ccsr_regs->reg_mcfbalr,
81 mc_ccsr_regs->reg_mcfbahr,
82 mc_ccsr_regs->reg_mcfapr,
83 mc_ccsr_regs->reg_psr);
87 #define dump_ram_words(title, addr)
88 #define dump_mc_ccsr_regs(mc_ccsr_regs)
92 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
94 * Copying MC firmware or DPL image to DDR
96 static int mc_copy_image(const char *title,
97 u64 image_addr, u32 image_size, u64 mc_ram_addr)
99 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
100 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
101 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
106 * MC firmware FIT image parser checks if the image is in FIT
107 * format, verifies integrity of the image and calculates
108 * raw image address and size values.
109 * Returns 0 on success and a negative errno on error.
112 int parse_mc_firmware_fit_image(u64 mc_fw_addr,
113 const void **raw_image_addr,
114 size_t *raw_image_size)
121 const char *uname = "firmware";
123 fit_hdr = (void *)mc_fw_addr;
125 /* Check if Image is in FIT format */
126 format = genimg_get_format(fit_hdr);
128 if (format != IMAGE_FORMAT_FIT) {
129 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
133 if (!fit_check_format(fit_hdr)) {
134 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
138 node_offset = fit_image_get_node(fit_hdr, uname);
140 if (node_offset < 0) {
141 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
145 /* Verify MC firmware image */
146 if (!(fit_image_verify(fit_hdr, node_offset))) {
147 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
151 /* Get address and size of raw image */
152 fit_image_get_data(fit_hdr, node_offset, &data, &size);
154 *raw_image_addr = data;
155 *raw_image_size = size;
161 #define MC_DT_INCREASE_SIZE 64
168 static int mc_fixup_mac_addr(void *blob, int nodeoffset,
169 const char *propname, struct eth_device *eth_dev,
170 enum mc_fixup_type type)
172 int err = 0, len = 0, size, i;
173 unsigned char env_enetaddr[ARP_HLEN];
174 unsigned int enetaddr_32[ARP_HLEN];
179 /* DPL likes its addresses on 32 * ARP_HLEN bits */
180 for (i = 0; i < ARP_HLEN; i++)
181 enetaddr_32[i] = cpu_to_fdt32(eth_dev->enetaddr[i]);
183 len = sizeof(enetaddr_32);
187 val = eth_dev->enetaddr;
192 /* MAC address property present */
193 if (fdt_get_property(blob, nodeoffset, propname, NULL)) {
194 /* u-boot MAC addr randomly assigned - leave the present one */
195 if (!eth_env_get_enetaddr_by_index("eth", eth_dev->index,
199 size = MC_DT_INCREASE_SIZE + strlen(propname) + len;
200 /* make room for mac address property */
201 err = fdt_increase_size(blob, size);
203 printf("fdt_increase_size: err=%s\n",
209 err = fdt_setprop(blob, nodeoffset, propname, val, len);
211 printf("fdt_setprop: err=%s\n", fdt_strerror(err));
218 #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
220 const char *dpl_get_connection_endpoint(void *blob, char *endpoint)
222 int connoffset = fdt_path_offset(blob, "/connections"), off;
225 for (off = fdt_first_subnode(blob, connoffset);
227 off = fdt_next_subnode(blob, off)) {
228 s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL);
229 s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL);
234 if (strcmp(endpoint, s1) == 0)
237 if (strcmp(endpoint, s2) == 0)
244 static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id,
245 struct eth_device *eth_dev)
247 int objoff = fdt_path_offset(blob, "/objects");
248 int dpmacoff = -1, dpnioff = -1;
249 const char *endpoint;
253 sprintf(mac_name, "dpmac@%d", dpmac_id);
254 dpmacoff = fdt_subnode_offset(blob, objoff, mac_name);
256 /* dpmac not defined in DPL, so skip it. */
259 err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev,
262 printf("Error fixing up dpmac mac_addr in DPL\n");
266 /* now we need to figure out if there is any
267 * DPNI connected to this MAC, so we walk the
270 endpoint = dpl_get_connection_endpoint(blob, mac_name);
271 if (!is_dpni(endpoint))
274 /* let's see if we can fixup the DPNI as well */
275 dpnioff = fdt_subnode_offset(blob, objoff, endpoint);
277 /* DPNI not defined in DPL in the objects area */
280 return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev,
284 void fdt_fsl_mc_fixup_iommu_map_entry(void *blob)
291 /* find fsl-mc node */
292 offset = fdt_path_offset(blob, "/soc/fsl-mc");
294 offset = fdt_path_offset(blob, "/fsl-mc");
296 printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n",
301 prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp);
303 debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n",
308 iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
309 iommu_map[1] = *++prop;
310 iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
311 iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END -
312 FSL_DPAA2_STREAM_ID_START + 1);
314 fdt_setprop_inplace(blob, offset, "iommu-map",
315 iommu_map, sizeof(iommu_map));
318 static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
319 struct eth_device *eth_dev)
321 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
324 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
326 sprintf(mac_name, "mac@%d", dpmac_id);
328 /* node not found - create it */
329 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
331 err = fdt_increase_size(blob, 200);
333 printf("fdt_increase_size: err=%s\n",
338 noff = fdt_add_subnode(blob, nodeoffset, mac_name);
340 printf("fdt_add_subnode: err=%s\n",
345 /* add default property of fixed link */
346 err = fdt_appendprop_string(blob, noff,
347 "link_type", link_type_mode);
349 printf("fdt_appendprop_string: err=%s\n",
355 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
359 static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
361 int i, err = 0, ret = 0;
362 char ethname[ETH_NAME_LEN];
363 struct eth_device *eth_dev;
365 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
366 /* port not enabled */
367 if (wriop_is_enabled_dpmac(i) != 1)
370 snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
371 phy_interface_strings[wriop_get_enet_if(i)]);
373 eth_dev = eth_get_dev_by_name(ethname);
379 err = mc_fixup_dpl_mac_addr(blob, i, eth_dev);
382 err = mc_fixup_dpc_mac_addr(blob, i, eth_dev);
389 printf("fsl-mc: ERROR fixing mac address for %s\n",
397 static int mc_fixup_dpc(u64 dpc_addr)
399 void *blob = (void *)dpc_addr;
400 int nodeoffset, err = 0;
402 /* delete any existing ICID pools */
403 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
404 if (fdt_del_node(blob, nodeoffset) < 0)
405 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
408 nodeoffset = fdt_path_offset(blob, "/resources");
409 if (nodeoffset < 0) {
410 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
413 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
414 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
415 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
416 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
417 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
419 FSL_DPAA2_STREAM_ID_END -
420 FSL_DPAA2_STREAM_ID_START + 1, 1);
422 /* fixup MAC addresses for dpmac ports */
423 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
427 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
430 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
435 static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
438 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
444 #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
445 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
446 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
448 mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
450 #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
454 * Load the MC DPC blob in the MC private DRAM block:
456 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
457 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
460 * Get address and size of the DPC blob stored in flash:
462 dpc_fdt_hdr = (void *)mc_dpc_addr;
464 error = fdt_check_header(dpc_fdt_hdr);
467 * Don't return with error here, since the MC firmware can
468 * still boot without a DPC
470 printf("\nfsl-mc: WARNING: No DPC image found");
474 dpc_size = fdt_totalsize(dpc_fdt_hdr);
475 if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
476 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
481 mc_copy_image("MC DPC blob",
482 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
483 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
485 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
488 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
493 static int mc_fixup_dpl(u64 dpl_addr)
495 void *blob = (void *)dpl_addr;
496 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
499 /* The DPL fixup for mac addresses is only relevant
505 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
506 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
511 static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
514 #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
520 #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
521 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
522 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
524 mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
526 #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
530 * Load the MC DPL blob in the MC private DRAM block:
532 #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
533 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
536 * Get address and size of the DPL blob stored in flash:
538 dpl_fdt_hdr = (void *)mc_dpl_addr;
540 error = fdt_check_header(dpl_fdt_hdr);
542 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
546 dpl_size = fdt_totalsize(dpl_fdt_hdr);
547 if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
548 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
553 mc_copy_image("MC DPL blob",
554 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
555 #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
557 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
559 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
564 * Return the MC boot timeout value in milliseconds
566 static unsigned long get_mc_boot_timeout_ms(void)
568 unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
570 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
572 if (timeout_ms_env_var) {
573 timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
574 if (timeout_ms == 0) {
575 printf("fsl-mc: WARNING: Invalid value for \'"
576 MC_BOOT_TIMEOUT_ENV_VAR
577 "\' environment variable: %lu\n",
580 timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
587 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
589 __weak bool soc_has_aiop(void)
594 static int load_mc_aiop_img(u64 aiop_fw_addr)
596 u64 mc_ram_addr = mc_get_dram_addr();
597 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
601 /* Check if AIOP is available */
605 * Load the MC AIOP image in the MC private DRAM block:
608 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
609 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
610 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
612 aiop_img = (void *)aiop_fw_addr;
613 mc_copy_image("MC AIOP image",
614 (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
615 mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
623 static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
626 u32 mc_fw_boot_status;
627 unsigned long timeout_ms = get_mc_boot_timeout_ms();
628 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
631 assert(timeout_ms > 0);
633 udelay(1000); /* throttle polling */
634 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
635 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
636 if (mc_fw_boot_status & 0x1)
644 if (timeout_ms == 0) {
645 printf("ERROR: timeout\n");
647 /* TODO: Get an error status from an MC CCSR register */
651 if (mc_fw_boot_status != 0x1) {
653 * TODO: Identify critical errors from the GSR register's FS
654 * field and for those errors, set error to -ENODEV or other
655 * appropriate errno, so that the status property is set to
656 * failure in the fsl,dprc device tree node.
658 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
665 *final_reg_gsr = reg_gsr;
669 int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
673 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
674 u64 mc_ram_addr = mc_get_dram_addr();
677 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
678 const void *raw_image_addr;
679 size_t raw_image_size = 0;
681 struct mc_version mc_ver_info;
682 u8 mc_ram_num_256mb_blocks;
683 size_t mc_ram_size = mc_get_dram_block_size();
685 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
687 if (mc_ram_num_256mb_blocks >= 0xff) {
689 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
695 * To support 128 MB DDR Size for MC
697 if (mc_ram_num_256mb_blocks == 0)
698 mc_ram_num_256mb_blocks = 0xFF;
701 * Management Complex cores should be held at reset out of POR.
702 * U-Boot should be the first software to touch MC. To be safe,
703 * we reset all cores again by setting GCR1 to 0. It doesn't do
704 * anything if they are held at reset. After we setup the firmware
705 * we kick off MC by deasserting the reset bit for core 0, and
706 * deasserting the reset bits for Command Portal Managers.
707 * The stop bits are not touched here. They are used to stop the
708 * cores when they are active. Setting stop bits doesn't stop the
709 * cores from fetching instructions when they are released from
712 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
715 #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
716 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
718 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
723 * Load the MC FW at the beginning of the MC private DRAM block:
725 mc_copy_image("MC Firmware",
726 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
728 dump_ram_words("firmware", (void *)mc_ram_addr);
730 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
734 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
735 dump_mc_ccsr_regs(mc_ccsr_regs);
738 * Tell MC what is the address range of the DRAM block assigned to it:
740 if (mc_ram_num_256mb_blocks < 0xFF) {
741 reg_mcfbalr = (u32)mc_ram_addr |
742 (mc_ram_num_256mb_blocks - 1);
744 reg_mcfbalr = (u32)mc_ram_addr |
745 (mc_ram_num_256mb_blocks);
748 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
749 out_le32(&mc_ccsr_regs->reg_mcfbahr,
750 (u32)(mc_ram_addr >> 32));
751 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
754 * Tell the MC that we want delayed DPL deployment.
756 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
758 printf("\nfsl-mc: Booting Management Complex ... ");
761 * Deassert reset and release MC core 0 to run
763 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
764 error = wait_for_mc(true, ®_gsr);
769 * TODO: need to obtain the portal_id for the root container from the
775 * Initialize the global default MC portal
776 * And check that the MC firmware is responding portal commands:
778 root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
780 printf(" No memory: calloc() failed\n");
784 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
785 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
786 portal_id, root_mc_io->mmio_regs);
788 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
790 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
795 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
796 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
797 reg_gsr & GSR_FS_MASK);
801 mc_boot_status = error;
808 int mc_apply_dpl(u64 mc_dpl_addr)
810 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
813 u64 mc_ram_addr = mc_get_dram_addr();
814 size_t mc_ram_size = mc_get_dram_block_size();
819 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
824 * Tell the MC to deploy the DPL:
826 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
827 printf("fsl-mc: Deploying data path layout ... ");
828 error = wait_for_mc(false, ®_gsr);
836 int get_mc_boot_status(void)
838 return mc_boot_status;
841 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
842 int get_aiop_apply_status(void)
844 return mc_aiop_applied;
848 int get_dpl_apply_status(void)
850 return mc_dpl_applied;
853 int is_lazy_dpl_addr_valid(void)
855 return !!mc_lazy_dpl_addr;
859 * Return the MC address of private DRAM block.
860 * As per MC design document, MC initial base address
861 * should be least significant 512MB address of MC private
862 * memory, i.e. address should point to end address masked
863 * with 512MB offset in private DRAM block.
865 u64 mc_get_dram_addr(void)
867 size_t mc_ram_size = mc_get_dram_block_size();
869 if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) {
870 mc_memset_resv_ram = 1;
871 memset((void *)gd->arch.resv_ram, 0, mc_ram_size);
874 return (gd->arch.resv_ram + mc_ram_size - 1) &
875 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
879 * Return the actual size of the MC private DRAM block.
881 unsigned long mc_get_dram_block_size(void)
883 unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
885 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
887 if (dram_block_size_env_var) {
888 dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
891 if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
892 printf("fsl-mc: WARNING: Invalid value for \'"
894 "\' environment variable: %lu\n",
897 dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE;
901 return dram_block_size;
904 int fsl_mc_ldpaa_init(bd_t *bis)
908 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
909 if (wriop_is_enabled_dpmac(i) == 1)
910 ldpaa_eth_init(i, wriop_get_enet_if(i));
914 static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
917 uint16_t major_ver, minor_ver;
919 error = dprc_get_api_version(mc_io, 0,
923 printf("dprc_get_api_version() failed: %d\n", error);
927 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
928 minor_ver < DPRC_VER_MINOR)) {
929 printf("DPRC version mismatch found %u.%u,",
930 major_ver, minor_ver);
931 printf("supported version is %u.%u\n",
932 DPRC_VER_MAJOR, DPRC_VER_MINOR);
938 static int dpio_init(void)
940 struct qbman_swp_desc p_des;
941 struct dpio_attr attr;
942 struct dpio_cfg dpio_cfg;
944 uint16_t major_ver, minor_ver;
946 dflt_dpio = (struct fsl_dpio_obj *)calloc(
947 sizeof(struct fsl_dpio_obj), 1);
949 printf("No memory: calloc() failed\n");
953 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
954 dpio_cfg.num_priorities = 8;
956 err = dpio_create(dflt_mc_io,
960 &dflt_dpio->dpio_id);
962 printf("dpio_create() failed: %d\n", err);
967 err = dpio_get_api_version(dflt_mc_io, 0,
971 printf("dpio_get_api_version() failed: %d\n", err);
972 goto err_get_api_ver;
975 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
976 minor_ver < DPIO_VER_MINOR)) {
977 printf("DPRC version mismatch found %u.%u,",
982 err = dpio_open(dflt_mc_io,
985 &dflt_dpio->dpio_handle);
987 printf("dpio_open() failed\n");
991 memset(&attr, 0, sizeof(struct dpio_attr));
992 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
993 dflt_dpio->dpio_handle, &attr);
995 printf("dpio_get_attributes() failed: %d\n", err);
999 if (dflt_dpio->dpio_id != attr.id) {
1000 printf("dnpi object id and attribute id are not same\n");
1001 goto err_attr_not_same;
1005 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1007 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1009 printf("dpio_enable() failed %d\n", err);
1010 goto err_get_enable;
1012 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
1013 attr.qbman_portal_ce_offset,
1014 attr.qbman_portal_ci_offset,
1015 attr.qbman_portal_id,
1016 attr.num_priorities);
1018 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1019 + attr.qbman_portal_ce_offset);
1020 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1021 + attr.qbman_portal_ci_offset);
1023 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
1024 if (dflt_dpio->sw_portal == NULL) {
1025 printf("qbman_swp_init() failed\n");
1026 goto err_get_swp_init;
1031 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1035 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1038 dpio_destroy(dflt_mc_io,
1041 dflt_dpio->dpio_id);
1048 static int dpio_exit(void)
1052 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1054 printf("dpio_disable() failed: %d\n", err);
1058 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1060 printf("dpio_close() failed: %d\n", err);
1064 err = dpio_destroy(dflt_mc_io,
1067 dflt_dpio->dpio_id);
1069 printf("dpio_destroy() failed: %d\n", err);
1074 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1085 static int dprc_init(void)
1087 int err, child_portal_id, container_id;
1088 struct dprc_cfg cfg;
1089 uint64_t mc_portal_offset;
1091 /* Open root container */
1092 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1094 printf("dprc_get_container_id(): Root failed: %d\n", err);
1095 goto err_root_container_id;
1099 printf("Root container id = %d\n", container_id);
1101 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1104 printf("dprc_open(): Root Container failed: %d\n", err);
1108 if (!root_dprc_handle) {
1109 printf("dprc_open(): Root Container Handle is not valid\n");
1113 err = dprc_version_check(root_mc_io, root_dprc_handle);
1115 printf("dprc_version_check() failed: %d\n", err);
1119 memset(&cfg, 0, sizeof(struct dprc_cfg));
1120 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1121 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1122 DPRC_CFG_OPT_ALLOC_ALLOWED;
1123 cfg.icid = DPRC_GET_ICID_FROM_POOL;
1124 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
1125 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1131 printf("dprc_create_container() failed: %d\n", err);
1135 dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
1138 printf(" No memory: calloc() failed\n");
1142 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1143 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
1146 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1147 child_dprc_id, dflt_mc_io->mmio_regs);
1150 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1153 printf("dprc_open(): Child container failed: %d\n", err);
1154 goto err_child_open;
1157 if (!dflt_dprc_handle) {
1158 printf("dprc_open(): Child container Handle is not valid\n");
1159 goto err_child_open;
1166 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1167 root_dprc_handle, child_dprc_id);
1169 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1171 err_root_container_id:
1175 static int dprc_exit(void)
1179 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1181 printf("dprc_close(): Child failed: %d\n", err);
1185 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1186 root_dprc_handle, child_dprc_id);
1188 printf("dprc_destroy_container() failed: %d\n", err);
1192 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1194 printf("dprc_close(): Root failed: %d\n", err);
1210 static int dpbp_init(void)
1213 struct dpbp_attr dpbp_attr;
1214 struct dpbp_cfg dpbp_cfg;
1215 uint16_t major_ver, minor_ver;
1217 dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
1218 sizeof(struct fsl_dpbp_obj), 1);
1220 printf("No memory: calloc() failed\n");
1225 dpbp_cfg.options = 512;
1227 err = dpbp_create(dflt_mc_io,
1231 &dflt_dpbp->dpbp_id);
1235 printf("dpbp_create() failed: %d\n", err);
1239 err = dpbp_get_api_version(dflt_mc_io, 0,
1243 printf("dpbp_get_api_version() failed: %d\n", err);
1244 goto err_get_api_ver;
1247 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1248 minor_ver < DPBP_VER_MINOR)) {
1249 printf("DPBP version mismatch found %u.%u,",
1250 major_ver, minor_ver);
1251 printf("supported version is %u.%u\n",
1252 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1255 err = dpbp_open(dflt_mc_io,
1258 &dflt_dpbp->dpbp_handle);
1260 printf("dpbp_open() failed\n");
1264 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1265 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1266 dflt_dpbp->dpbp_handle,
1269 printf("dpbp_get_attributes() failed: %d\n", err);
1273 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1274 printf("dpbp object id and attribute id are not same\n");
1275 goto err_attr_not_same;
1279 printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
1282 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1284 printf("dpbp_close() failed: %d\n", err);
1292 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1293 dpbp_destroy(dflt_mc_io,
1296 dflt_dpbp->dpbp_id);
1306 static int dpbp_exit(void)
1310 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1311 dflt_dpbp->dpbp_id);
1313 printf("dpbp_destroy() failed: %d\n", err);
1318 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1329 static int dpni_init(void)
1332 uint8_t cfg_buf[256] = {0};
1333 struct dpni_cfg dpni_cfg;
1334 uint16_t major_ver, minor_ver;
1336 dflt_dpni = (struct fsl_dpni_obj *)calloc(
1337 sizeof(struct fsl_dpni_obj), 1);
1339 printf("No memory: calloc() failed\n");
1344 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1345 err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
1348 printf("dpni_prepare_cfg() failed: %d\n", err);
1349 goto err_prepare_cfg;
1352 err = dpni_create(dflt_mc_io,
1356 &dflt_dpni->dpni_id);
1359 printf("dpni create() failed: %d\n", err);
1363 err = dpni_get_api_version(dflt_mc_io, 0,
1367 printf("dpni_get_api_version() failed: %d\n", err);
1368 goto err_get_version;
1371 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1372 minor_ver < DPNI_VER_MINOR)) {
1373 printf("DPNI version mismatch found %u.%u,",
1374 major_ver, minor_ver);
1375 printf("supported version is %u.%u\n",
1376 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1379 err = dpni_open(dflt_mc_io,
1382 &dflt_dpni->dpni_handle);
1384 printf("dpni_open() failed\n");
1389 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1391 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1393 printf("dpni_close() failed: %d\n", err);
1400 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1403 dpni_destroy(dflt_mc_io,
1406 dflt_dpni->dpni_id);
1414 static int dpni_exit(void)
1418 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1419 dflt_dpni->dpni_id);
1421 printf("dpni_destroy() failed: %d\n", err);
1426 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1437 static int mc_init_object(void)
1443 printf("dprc_init() failed: %d\n", err);
1449 printf("dpbp_init() failed: %d\n", err);
1455 printf("dpio_init() failed: %d\n", err);
1461 printf("dpni_init() failed: %d\n", err);
1470 int fsl_mc_ldpaa_exit(bd_t *bd)
1473 bool is_dpl_apply_status = false;
1474 bool mc_boot_status = false;
1476 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
1477 err = mc_apply_dpl(mc_lazy_dpl_addr);
1479 fdt_fixup_board_enet(working_fdt);
1480 mc_lazy_dpl_addr = 0;
1483 if (!get_mc_boot_status())
1484 mc_boot_status = true;
1486 /* MC is not loaded intentionally, So return success. */
1487 if (bd && !mc_boot_status)
1490 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1491 if (!get_dpl_apply_status())
1492 is_dpl_apply_status = true;
1495 * For case MC is loaded but DPL is not deployed, return success and
1496 * print message on console. Else FDT fix-up code execution hanged.
1498 if (bd && mc_boot_status && !is_dpl_apply_status) {
1499 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
1500 goto mc_obj_cleanup;
1503 if (bd && mc_boot_status && is_dpl_apply_status)
1509 printf("dpbp_exit() failed: %d\n", err);
1515 printf("dpio_exit() failed: %d\n", err);
1521 printf("dpni_exit() failed: %d\n", err);
1527 printf("dprc_exit() failed: %d\n", err);
1536 static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1542 switch (argv[1][0]) {
1545 u64 mc_fw_addr, mc_dpc_addr;
1546 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1550 sub_cmd = argv[2][0];
1557 if (get_mc_boot_status() == 0) {
1558 printf("fsl-mc: MC is already booted");
1562 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1563 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1566 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1567 err = mc_init_object();
1570 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1574 if (get_aiop_apply_status() == 0) {
1575 printf("fsl-mc: AIOP FW is already");
1576 printf(" applied\n");
1580 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1583 /* if SoC doesn't have AIOP, err = -ENODEV */
1584 err = load_mc_aiop_img(aiop_fw_addr);
1586 printf("fsl-mc: AIOP FW applied\n");
1590 printf("Invalid option: %s\n", argv[2]);
1605 if (get_dpl_apply_status() == 0) {
1606 printf("fsl-mc: DPL already applied\n");
1610 mc_dpl_addr = simple_strtoull(argv[3], NULL,
1613 if (get_mc_boot_status() != 0) {
1614 printf("fsl-mc: Deploying data path layout ..");
1615 printf("ERROR (MC is not booted)\n");
1619 if (argv[1][0] == 'l') {
1621 * We will do the actual dpaa exit and dpl apply
1622 * later from announce_and_cleanup().
1624 mc_lazy_dpl_addr = mc_dpl_addr;
1626 /* The user wants it applied now */
1627 if (!fsl_mc_ldpaa_exit(NULL))
1628 err = mc_apply_dpl(mc_dpl_addr);
1633 printf("Invalid option: %s\n", argv[1]);
1639 return CMD_RET_USAGE;
1643 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1644 "DPAA2 command to manage Management Complex (MC)",
1645 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1646 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
1647 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
1648 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1651 void mc_env_boot(void)
1653 #if defined(CONFIG_FSL_MC_ENET)
1654 char *mc_boot_env_var;
1655 /* The MC may only be initialized in the reset PHY function
1656 * because otherwise U-Boot has not yet set up all the MAC
1657 * address info properly. Without MAC addresses, the MC code
1658 * can not properly initialize the DPC.
1660 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
1661 if (mc_boot_env_var)
1662 run_command_list(mc_boot_env_var, -1, 0);
1663 #endif /* CONFIG_FSL_MC_ENET */