1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 Freescale Semiconductor, Inc.
10 #include <linux/libfdt.h>
12 #include <fdt_support.h>
13 #include <fsl-mc/fsl_mc.h>
14 #include <fsl-mc/fsl_mc_sys.h>
15 #include <fsl-mc/fsl_mc_private.h>
16 #include <fsl-mc/fsl_dpmng.h>
17 #include <fsl-mc/fsl_dprc.h>
18 #include <fsl-mc/fsl_dpio.h>
19 #include <fsl-mc/fsl_dpni.h>
20 #include <fsl-mc/fsl_qbman_portal.h>
21 #include <fsl-mc/ldpaa_wriop.h>
23 #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
24 #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
25 #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
27 #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
28 #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
29 #define MC_BOOT_ENV_VAR "mcinitcmd"
31 DECLARE_GLOBAL_DATA_PTR;
32 static int mc_boot_status = -1;
33 static int mc_dpl_applied = -1;
34 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
35 static int mc_aiop_applied = -1;
37 struct fsl_mc_io *root_mc_io = NULL;
38 struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
39 uint16_t root_dprc_handle = 0;
40 uint16_t dflt_dprc_handle = 0;
42 struct fsl_dpbp_obj *dflt_dpbp = NULL;
43 struct fsl_dpio_obj *dflt_dpio = NULL;
44 struct fsl_dpni_obj *dflt_dpni = NULL;
45 static u64 mc_lazy_dpl_addr;
48 void dump_ram_words(const char *title, void *addr)
51 uint32_t *words = addr;
53 printf("Dumping beginning of %s (%p):\n", title, addr);
54 for (i = 0; i < 16; i++)
55 printf("%#x ", words[i]);
60 void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
62 printf("MC CCSR registers:\n"
72 mc_ccsr_regs->reg_gcr1,
73 mc_ccsr_regs->reg_gsr,
74 mc_ccsr_regs->reg_sicbalr,
75 mc_ccsr_regs->reg_sicbahr,
76 mc_ccsr_regs->reg_sicapr,
77 mc_ccsr_regs->reg_mcfbalr,
78 mc_ccsr_regs->reg_mcfbahr,
79 mc_ccsr_regs->reg_mcfapr,
80 mc_ccsr_regs->reg_psr);
84 #define dump_ram_words(title, addr)
85 #define dump_mc_ccsr_regs(mc_ccsr_regs)
89 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
91 * Copying MC firmware or DPL image to DDR
93 static int mc_copy_image(const char *title,
94 u64 image_addr, u32 image_size, u64 mc_ram_addr)
96 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
97 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
98 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
103 * MC firmware FIT image parser checks if the image is in FIT
104 * format, verifies integrity of the image and calculates
105 * raw image address and size values.
106 * Returns 0 on success and a negative errno on error.
109 int parse_mc_firmware_fit_image(u64 mc_fw_addr,
110 const void **raw_image_addr,
111 size_t *raw_image_size)
118 const char *uname = "firmware";
120 fit_hdr = (void *)mc_fw_addr;
122 /* Check if Image is in FIT format */
123 format = genimg_get_format(fit_hdr);
125 if (format != IMAGE_FORMAT_FIT) {
126 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
130 if (!fit_check_format(fit_hdr)) {
131 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
135 node_offset = fit_image_get_node(fit_hdr, uname);
137 if (node_offset < 0) {
138 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
142 /* Verify MC firmware image */
143 if (!(fit_image_verify(fit_hdr, node_offset))) {
144 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
148 /* Get address and size of raw image */
149 fit_image_get_data(fit_hdr, node_offset, &data, &size);
151 *raw_image_addr = data;
152 *raw_image_size = size;
158 #define MC_DT_INCREASE_SIZE 64
165 static int mc_fixup_mac_addr(void *blob, int nodeoffset,
166 const char *propname, struct eth_device *eth_dev,
167 enum mc_fixup_type type)
169 int err = 0, len = 0, size, i;
170 unsigned char env_enetaddr[ARP_HLEN];
171 unsigned int enetaddr_32[ARP_HLEN];
176 /* DPL likes its addresses on 32 * ARP_HLEN bits */
177 for (i = 0; i < ARP_HLEN; i++)
178 enetaddr_32[i] = cpu_to_fdt32(eth_dev->enetaddr[i]);
180 len = sizeof(enetaddr_32);
184 val = eth_dev->enetaddr;
189 /* MAC address property present */
190 if (fdt_get_property(blob, nodeoffset, propname, NULL)) {
191 /* u-boot MAC addr randomly assigned - leave the present one */
192 if (!eth_env_get_enetaddr_by_index("eth", eth_dev->index,
196 size = MC_DT_INCREASE_SIZE + strlen(propname) + len;
197 /* make room for mac address property */
198 err = fdt_increase_size(blob, size);
200 printf("fdt_increase_size: err=%s\n",
206 err = fdt_setprop(blob, nodeoffset, propname, val, len);
208 printf("fdt_setprop: err=%s\n", fdt_strerror(err));
215 #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
217 const char *dpl_get_connection_endpoint(void *blob, char *endpoint)
219 int connoffset = fdt_path_offset(blob, "/connections"), off;
222 for (off = fdt_first_subnode(blob, connoffset);
224 off = fdt_next_subnode(blob, off)) {
225 s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL);
226 s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL);
231 if (strcmp(endpoint, s1) == 0)
234 if (strcmp(endpoint, s2) == 0)
241 static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id,
242 struct eth_device *eth_dev)
244 int objoff = fdt_path_offset(blob, "/objects");
245 int dpmacoff = -1, dpnioff = -1;
246 const char *endpoint;
250 sprintf(mac_name, "dpmac@%d", dpmac_id);
251 dpmacoff = fdt_subnode_offset(blob, objoff, mac_name);
253 /* dpmac not defined in DPL, so skip it. */
256 err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev,
259 printf("Error fixing up dpmac mac_addr in DPL\n");
263 /* now we need to figure out if there is any
264 * DPNI connected to this MAC, so we walk the
267 endpoint = dpl_get_connection_endpoint(blob, mac_name);
268 if (!is_dpni(endpoint))
271 /* let's see if we can fixup the DPNI as well */
272 dpnioff = fdt_subnode_offset(blob, objoff, endpoint);
274 /* DPNI not defined in DPL in the objects area */
277 return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev,
281 static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
282 struct eth_device *eth_dev)
284 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
287 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
289 sprintf(mac_name, "mac@%d", dpmac_id);
291 /* node not found - create it */
292 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
294 err = fdt_increase_size(blob, 200);
296 printf("fdt_increase_size: err=%s\n",
301 noff = fdt_add_subnode(blob, nodeoffset, mac_name);
303 printf("fdt_add_subnode: err=%s\n",
308 /* add default property of fixed link */
309 err = fdt_appendprop_string(blob, noff,
310 "link_type", link_type_mode);
312 printf("fdt_appendprop_string: err=%s\n",
318 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
322 static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
324 int i, err = 0, ret = 0;
326 struct eth_device *eth_dev;
328 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
329 /* port not enabled */
330 if ((wriop_is_enabled_dpmac(i) != 1) ||
331 (wriop_get_phy_address(i) == -1))
334 sprintf(ethname, "DPMAC%d@%s", i,
335 phy_interface_strings[wriop_get_enet_if(i)]);
337 eth_dev = eth_get_dev_by_name(ethname);
343 err = mc_fixup_dpl_mac_addr(blob, i, eth_dev);
346 err = mc_fixup_dpc_mac_addr(blob, i, eth_dev);
353 printf("fsl-mc: ERROR fixing mac address for %s\n",
361 static int mc_fixup_dpc(u64 dpc_addr)
363 void *blob = (void *)dpc_addr;
364 int nodeoffset, err = 0;
366 /* delete any existing ICID pools */
367 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
368 if (fdt_del_node(blob, nodeoffset) < 0)
369 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
372 nodeoffset = fdt_path_offset(blob, "/resources");
373 if (nodeoffset < 0) {
374 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
377 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
378 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
379 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
380 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
381 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
383 FSL_DPAA2_STREAM_ID_END -
384 FSL_DPAA2_STREAM_ID_START + 1, 1);
386 /* fixup MAC addresses for dpmac ports */
387 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
391 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
392 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
397 static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
400 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
406 #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
407 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
408 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
410 mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
412 #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
416 * Load the MC DPC blob in the MC private DRAM block:
418 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
419 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
422 * Get address and size of the DPC blob stored in flash:
424 dpc_fdt_hdr = (void *)mc_dpc_addr;
426 error = fdt_check_header(dpc_fdt_hdr);
429 * Don't return with error here, since the MC firmware can
430 * still boot without a DPC
432 printf("\nfsl-mc: WARNING: No DPC image found");
436 dpc_size = fdt_totalsize(dpc_fdt_hdr);
437 if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
438 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
443 mc_copy_image("MC DPC blob",
444 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
445 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
447 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
450 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
455 static int mc_fixup_dpl(u64 dpl_addr)
457 void *blob = (void *)dpl_addr;
458 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
461 /* The DPL fixup for mac addresses is only relevant
467 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
468 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
473 static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
476 #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
482 #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
483 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
484 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
486 mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
488 #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
492 * Load the MC DPL blob in the MC private DRAM block:
494 #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
495 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
498 * Get address and size of the DPL blob stored in flash:
500 dpl_fdt_hdr = (void *)mc_dpl_addr;
502 error = fdt_check_header(dpl_fdt_hdr);
504 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
508 dpl_size = fdt_totalsize(dpl_fdt_hdr);
509 if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
510 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
515 mc_copy_image("MC DPL blob",
516 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
517 #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
519 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
521 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
526 * Return the MC boot timeout value in milliseconds
528 static unsigned long get_mc_boot_timeout_ms(void)
530 unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
532 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
534 if (timeout_ms_env_var) {
535 timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
536 if (timeout_ms == 0) {
537 printf("fsl-mc: WARNING: Invalid value for \'"
538 MC_BOOT_TIMEOUT_ENV_VAR
539 "\' environment variable: %lu\n",
542 timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
549 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
551 __weak bool soc_has_aiop(void)
556 static int load_mc_aiop_img(u64 aiop_fw_addr)
558 u64 mc_ram_addr = mc_get_dram_addr();
559 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
563 /* Check if AIOP is available */
567 * Load the MC AIOP image in the MC private DRAM block:
570 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
571 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
572 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
574 aiop_img = (void *)aiop_fw_addr;
575 mc_copy_image("MC AIOP image",
576 (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
577 mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
585 static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
588 u32 mc_fw_boot_status;
589 unsigned long timeout_ms = get_mc_boot_timeout_ms();
590 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
593 assert(timeout_ms > 0);
595 udelay(1000); /* throttle polling */
596 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
597 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
598 if (mc_fw_boot_status & 0x1)
606 if (timeout_ms == 0) {
607 printf("ERROR: timeout\n");
609 /* TODO: Get an error status from an MC CCSR register */
613 if (mc_fw_boot_status != 0x1) {
615 * TODO: Identify critical errors from the GSR register's FS
616 * field and for those errors, set error to -ENODEV or other
617 * appropriate errno, so that the status property is set to
618 * failure in the fsl,dprc device tree node.
620 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
627 *final_reg_gsr = reg_gsr;
631 int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
635 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
636 u64 mc_ram_addr = mc_get_dram_addr();
639 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
640 const void *raw_image_addr;
641 size_t raw_image_size = 0;
643 struct mc_version mc_ver_info;
644 u8 mc_ram_num_256mb_blocks;
645 size_t mc_ram_size = mc_get_dram_block_size();
647 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
648 if (mc_ram_num_256mb_blocks < 1 || mc_ram_num_256mb_blocks > 0xff) {
650 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
656 * Management Complex cores should be held at reset out of POR.
657 * U-Boot should be the first software to touch MC. To be safe,
658 * we reset all cores again by setting GCR1 to 0. It doesn't do
659 * anything if they are held at reset. After we setup the firmware
660 * we kick off MC by deasserting the reset bit for core 0, and
661 * deasserting the reset bits for Command Portal Managers.
662 * The stop bits are not touched here. They are used to stop the
663 * cores when they are active. Setting stop bits doesn't stop the
664 * cores from fetching instructions when they are released from
667 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
670 #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
671 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
673 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
678 * Load the MC FW at the beginning of the MC private DRAM block:
680 mc_copy_image("MC Firmware",
681 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
683 dump_ram_words("firmware", (void *)mc_ram_addr);
685 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
689 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
690 dump_mc_ccsr_regs(mc_ccsr_regs);
693 * Tell MC what is the address range of the DRAM block assigned to it:
695 reg_mcfbalr = (u32)mc_ram_addr |
696 (mc_ram_num_256mb_blocks - 1);
697 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
698 out_le32(&mc_ccsr_regs->reg_mcfbahr,
699 (u32)(mc_ram_addr >> 32));
700 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
703 * Tell the MC that we want delayed DPL deployment.
705 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
707 printf("\nfsl-mc: Booting Management Complex ... ");
710 * Deassert reset and release MC core 0 to run
712 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
713 error = wait_for_mc(true, ®_gsr);
718 * TODO: need to obtain the portal_id for the root container from the
724 * Initialize the global default MC portal
725 * And check that the MC firmware is responding portal commands:
727 root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
729 printf(" No memory: calloc() failed\n");
733 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
734 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
735 portal_id, root_mc_io->mmio_regs);
737 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
739 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
744 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
745 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
746 reg_gsr & GSR_FS_MASK);
750 mc_boot_status = error;
757 int mc_apply_dpl(u64 mc_dpl_addr)
759 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
762 u64 mc_ram_addr = mc_get_dram_addr();
763 size_t mc_ram_size = mc_get_dram_block_size();
768 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
773 * Tell the MC to deploy the DPL:
775 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
776 printf("fsl-mc: Deploying data path layout ... ");
777 error = wait_for_mc(false, ®_gsr);
785 int get_mc_boot_status(void)
787 return mc_boot_status;
790 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
791 int get_aiop_apply_status(void)
793 return mc_aiop_applied;
797 int get_dpl_apply_status(void)
799 return mc_dpl_applied;
803 * Return the MC address of private DRAM block.
804 * As per MC design document, MC initial base address
805 * should be least significant 512MB address of MC private
806 * memory, i.e. address should point to end address masked
807 * with 512MB offset in private DRAM block.
809 u64 mc_get_dram_addr(void)
811 size_t mc_ram_size = mc_get_dram_block_size();
813 return (gd->arch.resv_ram + mc_ram_size - 1) &
814 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
818 * Return the actual size of the MC private DRAM block.
820 unsigned long mc_get_dram_block_size(void)
822 unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
824 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
826 if (dram_block_size_env_var) {
827 dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
830 if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
831 printf("fsl-mc: WARNING: Invalid value for \'"
833 "\' environment variable: %lu\n",
836 dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
840 return dram_block_size;
843 int fsl_mc_ldpaa_init(bd_t *bis)
847 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
848 if ((wriop_is_enabled_dpmac(i) == 1) &&
849 (wriop_get_phy_address(i) != -1))
850 ldpaa_eth_init(i, wriop_get_enet_if(i));
854 static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
857 uint16_t major_ver, minor_ver;
859 error = dprc_get_api_version(mc_io, 0,
863 printf("dprc_get_api_version() failed: %d\n", error);
867 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
868 minor_ver < DPRC_VER_MINOR)) {
869 printf("DPRC version mismatch found %u.%u,",
870 major_ver, minor_ver);
871 printf("supported version is %u.%u\n",
872 DPRC_VER_MAJOR, DPRC_VER_MINOR);
878 static int dpio_init(void)
880 struct qbman_swp_desc p_des;
881 struct dpio_attr attr;
882 struct dpio_cfg dpio_cfg;
884 uint16_t major_ver, minor_ver;
886 dflt_dpio = (struct fsl_dpio_obj *)calloc(
887 sizeof(struct fsl_dpio_obj), 1);
889 printf("No memory: calloc() failed\n");
893 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
894 dpio_cfg.num_priorities = 8;
896 err = dpio_create(dflt_mc_io,
900 &dflt_dpio->dpio_id);
902 printf("dpio_create() failed: %d\n", err);
907 err = dpio_get_api_version(dflt_mc_io, 0,
911 printf("dpio_get_api_version() failed: %d\n", err);
912 goto err_get_api_ver;
915 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
916 minor_ver < DPIO_VER_MINOR)) {
917 printf("DPRC version mismatch found %u.%u,",
922 err = dpio_open(dflt_mc_io,
925 &dflt_dpio->dpio_handle);
927 printf("dpio_open() failed\n");
931 memset(&attr, 0, sizeof(struct dpio_attr));
932 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
933 dflt_dpio->dpio_handle, &attr);
935 printf("dpio_get_attributes() failed: %d\n", err);
939 if (dflt_dpio->dpio_id != attr.id) {
940 printf("dnpi object id and attribute id are not same\n");
941 goto err_attr_not_same;
945 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
947 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
949 printf("dpio_enable() failed %d\n", err);
952 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
953 attr.qbman_portal_ce_offset,
954 attr.qbman_portal_ci_offset,
955 attr.qbman_portal_id,
956 attr.num_priorities);
958 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
959 + attr.qbman_portal_ce_offset);
960 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
961 + attr.qbman_portal_ci_offset);
963 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
964 if (dflt_dpio->sw_portal == NULL) {
965 printf("qbman_swp_init() failed\n");
966 goto err_get_swp_init;
971 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
975 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
978 dpio_destroy(dflt_mc_io,
988 static int dpio_exit(void)
992 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
994 printf("dpio_disable() failed: %d\n", err);
998 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1000 printf("dpio_close() failed: %d\n", err);
1004 err = dpio_destroy(dflt_mc_io,
1007 dflt_dpio->dpio_id);
1009 printf("dpio_destroy() failed: %d\n", err);
1014 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1025 static int dprc_init(void)
1027 int err, child_portal_id, container_id;
1028 struct dprc_cfg cfg;
1029 uint64_t mc_portal_offset;
1031 /* Open root container */
1032 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1034 printf("dprc_get_container_id(): Root failed: %d\n", err);
1035 goto err_root_container_id;
1039 printf("Root container id = %d\n", container_id);
1041 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1044 printf("dprc_open(): Root Container failed: %d\n", err);
1048 if (!root_dprc_handle) {
1049 printf("dprc_open(): Root Container Handle is not valid\n");
1053 err = dprc_version_check(root_mc_io, root_dprc_handle);
1055 printf("dprc_version_check() failed: %d\n", err);
1059 memset(&cfg, 0, sizeof(struct dprc_cfg));
1060 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1061 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1062 DPRC_CFG_OPT_ALLOC_ALLOWED;
1063 cfg.icid = DPRC_GET_ICID_FROM_POOL;
1064 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
1065 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1071 printf("dprc_create_container() failed: %d\n", err);
1075 dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
1078 printf(" No memory: calloc() failed\n");
1082 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1083 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
1086 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1087 child_dprc_id, dflt_mc_io->mmio_regs);
1090 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1093 printf("dprc_open(): Child container failed: %d\n", err);
1094 goto err_child_open;
1097 if (!dflt_dprc_handle) {
1098 printf("dprc_open(): Child container Handle is not valid\n");
1099 goto err_child_open;
1106 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1107 root_dprc_handle, child_dprc_id);
1109 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1111 err_root_container_id:
1115 static int dprc_exit(void)
1119 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1121 printf("dprc_close(): Child failed: %d\n", err);
1125 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1126 root_dprc_handle, child_dprc_id);
1128 printf("dprc_destroy_container() failed: %d\n", err);
1132 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1134 printf("dprc_close(): Root failed: %d\n", err);
1150 static int dpbp_init(void)
1153 struct dpbp_attr dpbp_attr;
1154 struct dpbp_cfg dpbp_cfg;
1155 uint16_t major_ver, minor_ver;
1157 dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
1158 sizeof(struct fsl_dpbp_obj), 1);
1160 printf("No memory: calloc() failed\n");
1165 dpbp_cfg.options = 512;
1167 err = dpbp_create(dflt_mc_io,
1171 &dflt_dpbp->dpbp_id);
1175 printf("dpbp_create() failed: %d\n", err);
1179 err = dpbp_get_api_version(dflt_mc_io, 0,
1183 printf("dpbp_get_api_version() failed: %d\n", err);
1184 goto err_get_api_ver;
1187 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1188 minor_ver < DPBP_VER_MINOR)) {
1189 printf("DPBP version mismatch found %u.%u,",
1190 major_ver, minor_ver);
1191 printf("supported version is %u.%u\n",
1192 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1195 err = dpbp_open(dflt_mc_io,
1198 &dflt_dpbp->dpbp_handle);
1200 printf("dpbp_open() failed\n");
1204 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1205 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1206 dflt_dpbp->dpbp_handle,
1209 printf("dpbp_get_attributes() failed: %d\n", err);
1213 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1214 printf("dpbp object id and attribute id are not same\n");
1215 goto err_attr_not_same;
1219 printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
1222 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1224 printf("dpbp_close() failed: %d\n", err);
1232 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1233 dpbp_destroy(dflt_mc_io,
1236 dflt_dpbp->dpbp_id);
1246 static int dpbp_exit(void)
1250 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1251 dflt_dpbp->dpbp_id);
1253 printf("dpbp_destroy() failed: %d\n", err);
1258 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1269 static int dpni_init(void)
1272 uint8_t cfg_buf[256] = {0};
1273 struct dpni_cfg dpni_cfg;
1274 uint16_t major_ver, minor_ver;
1276 dflt_dpni = (struct fsl_dpni_obj *)calloc(
1277 sizeof(struct fsl_dpni_obj), 1);
1279 printf("No memory: calloc() failed\n");
1284 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1285 err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
1288 printf("dpni_prepare_cfg() failed: %d\n", err);
1289 goto err_prepare_cfg;
1292 err = dpni_create(dflt_mc_io,
1296 &dflt_dpni->dpni_id);
1299 printf("dpni create() failed: %d\n", err);
1303 err = dpni_get_api_version(dflt_mc_io, 0,
1307 printf("dpni_get_api_version() failed: %d\n", err);
1308 goto err_get_version;
1311 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1312 minor_ver < DPNI_VER_MINOR)) {
1313 printf("DPNI version mismatch found %u.%u,",
1314 major_ver, minor_ver);
1315 printf("supported version is %u.%u\n",
1316 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1319 err = dpni_open(dflt_mc_io,
1322 &dflt_dpni->dpni_handle);
1324 printf("dpni_open() failed\n");
1329 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1331 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1333 printf("dpni_close() failed: %d\n", err);
1340 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1343 dpni_destroy(dflt_mc_io,
1346 dflt_dpni->dpni_id);
1354 static int dpni_exit(void)
1358 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1359 dflt_dpni->dpni_id);
1361 printf("dpni_destroy() failed: %d\n", err);
1366 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1377 static int mc_init_object(void)
1383 printf("dprc_init() failed: %d\n", err);
1389 printf("dpbp_init() failed: %d\n", err);
1395 printf("dpio_init() failed: %d\n", err);
1401 printf("dpni_init() failed: %d\n", err);
1410 int fsl_mc_ldpaa_exit(bd_t *bd)
1413 bool is_dpl_apply_status = false;
1414 bool mc_boot_status = false;
1416 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
1417 err = mc_apply_dpl(mc_lazy_dpl_addr);
1419 fdt_fixup_board_enet(working_fdt);
1420 mc_lazy_dpl_addr = 0;
1423 if (!get_mc_boot_status())
1424 mc_boot_status = true;
1426 /* MC is not loaded intentionally, So return success. */
1427 if (bd && !mc_boot_status)
1430 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1431 if (!get_dpl_apply_status())
1432 is_dpl_apply_status = true;
1435 * For case MC is loaded but DPL is not deployed, return success and
1436 * print message on console. Else FDT fix-up code execution hanged.
1438 if (bd && mc_boot_status && !is_dpl_apply_status) {
1439 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
1440 goto mc_obj_cleanup;
1443 if (bd && mc_boot_status && is_dpl_apply_status)
1449 printf("dpbp_exit() failed: %d\n", err);
1455 printf("dpio_exit() failed: %d\n", err);
1461 printf("dpni_exit() failed: %d\n", err);
1467 printf("dprc_exit() failed: %d\n", err);
1476 static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1482 switch (argv[1][0]) {
1485 u64 mc_fw_addr, mc_dpc_addr;
1486 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1490 sub_cmd = argv[2][0];
1497 if (get_mc_boot_status() == 0) {
1498 printf("fsl-mc: MC is already booted");
1502 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1503 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1506 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1507 err = mc_init_object();
1510 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1514 if (get_aiop_apply_status() == 0) {
1515 printf("fsl-mc: AIOP FW is already");
1516 printf(" applied\n");
1520 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1523 /* if SoC doesn't have AIOP, err = -ENODEV */
1524 err = load_mc_aiop_img(aiop_fw_addr);
1526 printf("fsl-mc: AIOP FW applied\n");
1530 printf("Invalid option: %s\n", argv[2]);
1545 if (get_dpl_apply_status() == 0) {
1546 printf("fsl-mc: DPL already applied\n");
1550 mc_dpl_addr = simple_strtoull(argv[3], NULL,
1553 if (get_mc_boot_status() != 0) {
1554 printf("fsl-mc: Deploying data path layout ..");
1555 printf("ERROR (MC is not booted)\n");
1559 if (argv[1][0] == 'l') {
1561 * We will do the actual dpaa exit and dpl apply
1562 * later from announce_and_cleanup().
1564 mc_lazy_dpl_addr = mc_dpl_addr;
1566 /* The user wants it applied now */
1567 if (!fsl_mc_ldpaa_exit(NULL))
1568 err = mc_apply_dpl(mc_dpl_addr);
1573 printf("Invalid option: %s\n", argv[1]);
1579 return CMD_RET_USAGE;
1583 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1584 "DPAA2 command to manage Management Complex (MC)",
1585 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1586 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
1587 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
1588 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1591 void mc_env_boot(void)
1593 #if defined(CONFIG_FSL_MC_ENET)
1594 char *mc_boot_env_var;
1595 /* The MC may only be initialized in the reset PHY function
1596 * because otherwise U-Boot has not yet set up all the MAC
1597 * address info properly. Without MAC addresses, the MC code
1598 * can not properly initialize the DPC.
1600 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
1601 if (mc_boot_env_var)
1602 run_command_list(mc_boot_env_var, -1, 0);
1603 #endif /* CONFIG_FSL_MC_ENET */