2 * Copyright (C) 2014 Freescale Semiconductor
4 * SPDX-License-Identifier: GPL-2.0+
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"
30 DECLARE_GLOBAL_DATA_PTR;
31 static int mc_boot_status = -1;
32 static int mc_dpl_applied = -1;
33 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
34 static int mc_aiop_applied = -1;
36 struct fsl_mc_io *root_mc_io = NULL;
37 struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
38 uint16_t root_dprc_handle = 0;
39 uint16_t dflt_dprc_handle = 0;
41 struct fsl_dpbp_obj *dflt_dpbp = NULL;
42 struct fsl_dpio_obj *dflt_dpio = NULL;
43 struct fsl_dpni_obj *dflt_dpni = NULL;
44 static u64 mc_lazy_dpl_addr;
47 void dump_ram_words(const char *title, void *addr)
50 uint32_t *words = addr;
52 printf("Dumping beginning of %s (%p):\n", title, addr);
53 for (i = 0; i < 16; i++)
54 printf("%#x ", words[i]);
59 void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
61 printf("MC CCSR registers:\n"
71 mc_ccsr_regs->reg_gcr1,
72 mc_ccsr_regs->reg_gsr,
73 mc_ccsr_regs->reg_sicbalr,
74 mc_ccsr_regs->reg_sicbahr,
75 mc_ccsr_regs->reg_sicapr,
76 mc_ccsr_regs->reg_mcfbalr,
77 mc_ccsr_regs->reg_mcfbahr,
78 mc_ccsr_regs->reg_mcfapr,
79 mc_ccsr_regs->reg_psr);
83 #define dump_ram_words(title, addr)
84 #define dump_mc_ccsr_regs(mc_ccsr_regs)
88 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
90 * Copying MC firmware or DPL image to DDR
92 static int mc_copy_image(const char *title,
93 u64 image_addr, u32 image_size, u64 mc_ram_addr)
95 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
96 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
97 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
102 * MC firmware FIT image parser checks if the image is in FIT
103 * format, verifies integrity of the image and calculates
104 * raw image address and size values.
105 * Returns 0 on success and a negative errno on error.
108 int parse_mc_firmware_fit_image(u64 mc_fw_addr,
109 const void **raw_image_addr,
110 size_t *raw_image_size)
117 const char *uname = "firmware";
119 fit_hdr = (void *)mc_fw_addr;
121 /* Check if Image is in FIT format */
122 format = genimg_get_format(fit_hdr);
124 if (format != IMAGE_FORMAT_FIT) {
125 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
129 if (!fit_check_format(fit_hdr)) {
130 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
134 node_offset = fit_image_get_node(fit_hdr, uname);
136 if (node_offset < 0) {
137 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
141 /* Verify MC firmware image */
142 if (!(fit_image_verify(fit_hdr, node_offset))) {
143 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
147 /* Get address and size of raw image */
148 fit_image_get_data(fit_hdr, node_offset, &data, &size);
150 *raw_image_addr = data;
151 *raw_image_size = size;
157 static int mc_fixup_dpc_mac_addr(void *blob, int noff, int dpmac_id,
158 struct eth_device *eth_dev)
160 int nodeoffset, err = 0;
162 const char link_type_mode[] = "FIXED_LINK";
163 unsigned char env_enetaddr[6];
165 sprintf(mac_name, "mac@%d", dpmac_id);
167 /* node not found - create it */
168 nodeoffset = fdt_subnode_offset(blob, noff, (const char *) mac_name);
169 if (nodeoffset < 0) {
170 err = fdt_increase_size(blob, 200);
172 printf("fdt_increase_size: err=%s\n",
177 nodeoffset = fdt_add_subnode(blob, noff, mac_name);
179 /* add default property of fixed link */
180 err = fdt_appendprop_string(blob, nodeoffset,
181 "link_type", link_type_mode);
183 printf("fdt_appendprop_string: err=%s\n",
189 /* port_mac_address property present in DPC */
190 if (fdt_get_property(blob, nodeoffset, "port_mac_address", NULL)) {
191 /* MAC addr randomly assigned - leave the one in DPC */
192 eth_getenv_enetaddr_by_index("eth", eth_dev->index,
194 if (is_zero_ethaddr(env_enetaddr))
197 /* replace DPC MAC address with u-boot env one */
198 err = fdt_setprop(blob, nodeoffset, "port_mac_address",
199 eth_dev->enetaddr, 6);
201 printf("fdt_setprop mac: err=%s\n", fdt_strerror(err));
208 /* append port_mac_address property to mac node in DPC */
209 err = fdt_increase_size(blob, 80);
211 printf("fdt_increase_size: err=%s\n", fdt_strerror(err));
215 err = fdt_appendprop(blob, nodeoffset,
216 "port_mac_address", eth_dev->enetaddr, 6);
218 printf("fdt_appendprop: err=%s\n", fdt_strerror(err));
225 static int mc_fixup_dpc(u64 dpc_addr)
227 void *blob = (void *)dpc_addr;
228 int nodeoffset, err = 0;
230 struct eth_device *eth_dev;
233 /* delete any existing ICID pools */
234 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
235 if (fdt_del_node(blob, nodeoffset) < 0)
236 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
239 nodeoffset = fdt_path_offset(blob, "/resources");
240 if (nodeoffset < 0) {
241 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
244 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
245 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
246 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
247 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
248 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
250 FSL_DPAA2_STREAM_ID_END -
251 FSL_DPAA2_STREAM_ID_START + 1, 1);
253 /* fixup MAC addresses for dpmac ports */
254 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
258 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
259 /* port not enabled */
260 if ((wriop_is_enabled_dpmac(i) != 1) ||
261 (wriop_get_phy_address(i) == -1))
264 sprintf(ethname, "DPMAC%d@%s", i,
265 phy_interface_strings[wriop_get_enet_if(i)]);
267 eth_dev = eth_get_dev_by_name(ethname);
271 err = mc_fixup_dpc_mac_addr(blob, nodeoffset, i, eth_dev);
273 printf("mc_fixup_dpc_mac_addr failed: err=%s\n",
280 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
285 static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
288 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
294 #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
295 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
296 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
298 mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
300 #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
304 * Load the MC DPC blob in the MC private DRAM block:
306 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
307 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
310 * Get address and size of the DPC blob stored in flash:
312 dpc_fdt_hdr = (void *)mc_dpc_addr;
314 error = fdt_check_header(dpc_fdt_hdr);
317 * Don't return with error here, since the MC firmware can
318 * still boot without a DPC
320 printf("\nfsl-mc: WARNING: No DPC image found");
324 dpc_size = fdt_totalsize(dpc_fdt_hdr);
325 if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
326 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
331 mc_copy_image("MC DPC blob",
332 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
333 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
335 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
338 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
342 static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
345 #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
351 #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
352 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
353 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
355 mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
357 #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
361 * Load the MC DPL blob in the MC private DRAM block:
363 #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
364 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
367 * Get address and size of the DPL blob stored in flash:
369 dpl_fdt_hdr = (void *)mc_dpl_addr;
371 error = fdt_check_header(dpl_fdt_hdr);
373 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
377 dpl_size = fdt_totalsize(dpl_fdt_hdr);
378 if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
379 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
384 mc_copy_image("MC DPL blob",
385 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
386 #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
388 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
393 * Return the MC boot timeout value in milliseconds
395 static unsigned long get_mc_boot_timeout_ms(void)
397 unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
399 char *timeout_ms_env_var = getenv(MC_BOOT_TIMEOUT_ENV_VAR);
401 if (timeout_ms_env_var) {
402 timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
403 if (timeout_ms == 0) {
404 printf("fsl-mc: WARNING: Invalid value for \'"
405 MC_BOOT_TIMEOUT_ENV_VAR
406 "\' environment variable: %lu\n",
409 timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
416 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
418 __weak bool soc_has_aiop(void)
423 static int load_mc_aiop_img(u64 aiop_fw_addr)
425 u64 mc_ram_addr = mc_get_dram_addr();
426 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
430 /* Check if AIOP is available */
434 * Load the MC AIOP image in the MC private DRAM block:
437 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
438 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
439 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
441 aiop_img = (void *)aiop_fw_addr;
442 mc_copy_image("MC AIOP image",
443 (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
444 mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
452 static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
455 u32 mc_fw_boot_status;
456 unsigned long timeout_ms = get_mc_boot_timeout_ms();
457 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
460 assert(timeout_ms > 0);
462 udelay(1000); /* throttle polling */
463 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
464 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
465 if (mc_fw_boot_status & 0x1)
473 if (timeout_ms == 0) {
474 printf("ERROR: timeout\n");
476 /* TODO: Get an error status from an MC CCSR register */
480 if (mc_fw_boot_status != 0x1) {
482 * TODO: Identify critical errors from the GSR register's FS
483 * field and for those errors, set error to -ENODEV or other
484 * appropriate errno, so that the status property is set to
485 * failure in the fsl,dprc device tree node.
487 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
494 *final_reg_gsr = reg_gsr;
498 int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
502 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
503 u64 mc_ram_addr = mc_get_dram_addr();
506 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
507 const void *raw_image_addr;
508 size_t raw_image_size = 0;
510 struct mc_version mc_ver_info;
511 u8 mc_ram_num_256mb_blocks;
512 size_t mc_ram_size = mc_get_dram_block_size();
514 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
515 if (mc_ram_num_256mb_blocks < 1 || mc_ram_num_256mb_blocks > 0xff) {
517 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
523 * Management Complex cores should be held at reset out of POR.
524 * U-Boot should be the first software to touch MC. To be safe,
525 * we reset all cores again by setting GCR1 to 0. It doesn't do
526 * anything if they are held at reset. After we setup the firmware
527 * we kick off MC by deasserting the reset bit for core 0, and
528 * deasserting the reset bits for Command Portal Managers.
529 * The stop bits are not touched here. They are used to stop the
530 * cores when they are active. Setting stop bits doesn't stop the
531 * cores from fetching instructions when they are released from
534 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
537 #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
538 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
540 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
545 * Load the MC FW at the beginning of the MC private DRAM block:
547 mc_copy_image("MC Firmware",
548 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
550 dump_ram_words("firmware", (void *)mc_ram_addr);
552 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
556 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
557 dump_mc_ccsr_regs(mc_ccsr_regs);
560 * Tell MC what is the address range of the DRAM block assigned to it:
562 reg_mcfbalr = (u32)mc_ram_addr |
563 (mc_ram_num_256mb_blocks - 1);
564 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
565 out_le32(&mc_ccsr_regs->reg_mcfbahr,
566 (u32)(mc_ram_addr >> 32));
567 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
570 * Tell the MC that we want delayed DPL deployment.
572 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
574 printf("\nfsl-mc: Booting Management Complex ... ");
577 * Deassert reset and release MC core 0 to run
579 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
580 error = wait_for_mc(true, ®_gsr);
585 * TODO: need to obtain the portal_id for the root container from the
591 * Initialize the global default MC portal
592 * And check that the MC firmware is responding portal commands:
594 root_mc_io = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io));
596 printf(" No memory: malloc() failed\n");
600 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
601 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
602 portal_id, root_mc_io->mmio_regs);
604 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
606 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
611 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
612 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
613 reg_gsr & GSR_FS_MASK);
617 mc_boot_status = error;
624 int mc_apply_dpl(u64 mc_dpl_addr)
626 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
629 u64 mc_ram_addr = mc_get_dram_addr();
630 size_t mc_ram_size = mc_get_dram_block_size();
635 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
640 * Tell the MC to deploy the DPL:
642 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
643 printf("fsl-mc: Deploying data path layout ... ");
644 error = wait_for_mc(false, ®_gsr);
652 int get_mc_boot_status(void)
654 return mc_boot_status;
657 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
658 int get_aiop_apply_status(void)
660 return mc_aiop_applied;
664 int get_dpl_apply_status(void)
666 return mc_dpl_applied;
670 * Return the MC address of private DRAM block.
672 u64 mc_get_dram_addr(void)
674 return gd->arch.resv_ram;
678 * Return the actual size of the MC private DRAM block.
680 unsigned long mc_get_dram_block_size(void)
682 unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
684 char *dram_block_size_env_var = getenv(MC_MEM_SIZE_ENV_VAR);
686 if (dram_block_size_env_var) {
687 dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
690 if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
691 printf("fsl-mc: WARNING: Invalid value for \'"
693 "\' environment variable: %lu\n",
696 dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
700 return dram_block_size;
703 int fsl_mc_ldpaa_init(bd_t *bis)
707 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
708 if ((wriop_is_enabled_dpmac(i) == 1) &&
709 (wriop_get_phy_address(i) != -1))
710 ldpaa_eth_init(i, wriop_get_enet_if(i));
714 static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
716 struct dprc_attributes attr;
719 memset(&attr, 0, sizeof(struct dprc_attributes));
720 error = dprc_get_attributes(mc_io, MC_CMD_NO_FLAGS, handle, &attr);
722 if ((attr.version.major != DPRC_VER_MAJOR) ||
723 (attr.version.minor != DPRC_VER_MINOR)) {
724 printf("DPRC version mismatch found %u.%u,",
727 printf("supported version is %u.%u\n",
728 DPRC_VER_MAJOR, DPRC_VER_MINOR);
734 static int dpio_init(void)
736 struct qbman_swp_desc p_des;
737 struct dpio_attr attr;
738 struct dpio_cfg dpio_cfg;
741 dflt_dpio = (struct fsl_dpio_obj *)malloc(sizeof(struct fsl_dpio_obj));
743 printf("No memory: malloc() failed\n");
748 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
749 dpio_cfg.num_priorities = 8;
751 err = dpio_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpio_cfg,
752 &dflt_dpio->dpio_handle);
754 printf("dpio_create() failed: %d\n", err);
759 memset(&attr, 0, sizeof(struct dpio_attr));
760 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
761 dflt_dpio->dpio_handle, &attr);
763 printf("dpio_get_attributes() failed: %d\n", err);
767 if ((attr.version.major != DPIO_VER_MAJOR) ||
768 (attr.version.minor != DPIO_VER_MINOR)) {
769 printf("DPIO version mismatch found %u.%u,",
770 attr.version.major, attr.version.minor);
771 printf("supported version is %u.%u\n",
772 DPIO_VER_MAJOR, DPIO_VER_MINOR);
775 dflt_dpio->dpio_id = attr.id;
777 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
779 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
781 printf("dpio_enable() failed %d\n", err);
784 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
785 attr.qbman_portal_ce_offset,
786 attr.qbman_portal_ci_offset,
787 attr.qbman_portal_id,
788 attr.num_priorities);
790 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
791 + attr.qbman_portal_ce_offset);
792 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
793 + attr.qbman_portal_ci_offset);
795 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
796 if (dflt_dpio->sw_portal == NULL) {
797 printf("qbman_swp_init() failed\n");
798 goto err_get_swp_init;
803 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
806 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
807 dpio_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
814 static int dpio_exit(void)
818 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
820 printf("dpio_disable() failed: %d\n", err);
824 err = dpio_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
826 printf("dpio_destroy() failed: %d\n", err);
831 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
842 static int dprc_init(void)
844 int err, child_portal_id, container_id;
846 uint64_t mc_portal_offset;
848 /* Open root container */
849 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
851 printf("dprc_get_container_id(): Root failed: %d\n", err);
852 goto err_root_container_id;
856 printf("Root container id = %d\n", container_id);
858 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
861 printf("dprc_open(): Root Container failed: %d\n", err);
865 if (!root_dprc_handle) {
866 printf("dprc_open(): Root Container Handle is not valid\n");
870 err = dprc_version_check(root_mc_io, root_dprc_handle);
872 printf("dprc_version_check() failed: %d\n", err);
876 memset(&cfg, 0, sizeof(struct dprc_cfg));
877 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
878 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
879 DPRC_CFG_OPT_ALLOC_ALLOWED;
880 cfg.icid = DPRC_GET_ICID_FROM_POOL;
881 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
882 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
888 printf("dprc_create_container() failed: %d\n", err);
892 dflt_mc_io = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io));
895 printf(" No memory: malloc() failed\n");
899 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
900 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
902 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
903 child_dprc_id, dflt_mc_io->mmio_regs);
906 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
909 printf("dprc_open(): Child container failed: %d\n", err);
913 if (!dflt_dprc_handle) {
914 printf("dprc_open(): Child container Handle is not valid\n");
922 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
923 root_dprc_handle, child_dprc_id);
925 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
927 err_root_container_id:
931 static int dprc_exit(void)
935 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
937 printf("dprc_close(): Child failed: %d\n", err);
941 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
942 root_dprc_handle, child_dprc_id);
944 printf("dprc_destroy_container() failed: %d\n", err);
948 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
950 printf("dprc_close(): Root failed: %d\n", err);
966 static int dpbp_init(void)
969 struct dpbp_attr dpbp_attr;
970 struct dpbp_cfg dpbp_cfg;
972 dflt_dpbp = (struct fsl_dpbp_obj *)malloc(sizeof(struct fsl_dpbp_obj));
974 printf("No memory: malloc() failed\n");
979 dpbp_cfg.options = 512;
981 err = dpbp_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpbp_cfg,
982 &dflt_dpbp->dpbp_handle);
986 printf("dpbp_create() failed: %d\n", err);
990 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
991 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
992 dflt_dpbp->dpbp_handle,
995 printf("dpbp_get_attributes() failed: %d\n", err);
999 if ((dpbp_attr.version.major != DPBP_VER_MAJOR) ||
1000 (dpbp_attr.version.minor != DPBP_VER_MINOR)) {
1001 printf("DPBP version mismatch found %u.%u,",
1002 dpbp_attr.version.major, dpbp_attr.version.minor);
1003 printf("supported version is %u.%u\n",
1004 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1007 dflt_dpbp->dpbp_attr.id = dpbp_attr.id;
1009 printf("Init: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1012 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1014 printf("dpbp_close() failed: %d\n", err);
1023 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1024 dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1030 static int dpbp_exit(void)
1034 err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
1035 &dflt_dpbp->dpbp_handle);
1037 printf("dpbp_open() failed: %d\n", err);
1041 err = dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS,
1042 dflt_dpbp->dpbp_handle);
1044 printf("dpbp_destroy() failed: %d\n", err);
1049 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1060 static int dpni_init(void)
1063 struct dpni_attr dpni_attr;
1064 uint8_t ext_cfg_buf[256] = {0};
1065 struct dpni_extended_cfg dpni_extended_cfg;
1066 struct dpni_cfg dpni_cfg;
1068 dflt_dpni = (struct fsl_dpni_obj *)malloc(sizeof(struct fsl_dpni_obj));
1070 printf("No memory: malloc() failed\n");
1075 memset(&dpni_extended_cfg, 0, sizeof(dpni_extended_cfg));
1076 err = dpni_prepare_extended_cfg(&dpni_extended_cfg, &ext_cfg_buf[0]);
1079 printf("dpni_prepare_extended_cfg() failed: %d\n", err);
1080 goto err_prepare_extended_cfg;
1083 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1084 dpni_cfg.adv.options = DPNI_OPT_UNICAST_FILTER |
1085 DPNI_OPT_MULTICAST_FILTER;
1087 dpni_cfg.adv.ext_cfg_iova = (uint64_t)&ext_cfg_buf[0];
1088 err = dpni_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpni_cfg,
1089 &dflt_dpni->dpni_handle);
1093 printf("dpni_create() failed: %d\n", err);
1097 memset(&dpni_attr, 0, sizeof(struct dpni_attr));
1098 err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1099 dflt_dpni->dpni_handle,
1102 printf("dpni_get_attributes() failed: %d\n", err);
1106 if ((dpni_attr.version.major != DPNI_VER_MAJOR) ||
1107 (dpni_attr.version.minor != DPNI_VER_MINOR)) {
1108 printf("DPNI version mismatch found %u.%u,",
1109 dpni_attr.version.major, dpni_attr.version.minor);
1110 printf("supported version is %u.%u\n",
1111 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1114 dflt_dpni->dpni_id = dpni_attr.id;
1116 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1119 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1121 printf("dpni_close() failed: %d\n", err);
1129 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1130 dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1132 err_prepare_extended_cfg:
1138 static int dpni_exit(void)
1142 err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
1143 &dflt_dpni->dpni_handle);
1145 printf("dpni_open() failed: %d\n", err);
1149 err = dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS,
1150 dflt_dpni->dpni_handle);
1152 printf("dpni_destroy() failed: %d\n", err);
1157 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1168 static int mc_init_object(void)
1174 printf("dprc_init() failed: %d\n", err);
1180 printf("dpbp_init() failed: %d\n", err);
1186 printf("dpio_init() failed: %d\n", err);
1192 printf("dpni_init() failed: %d\n", err);
1201 int fsl_mc_ldpaa_exit(bd_t *bd)
1205 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
1206 mc_apply_dpl(mc_lazy_dpl_addr);
1207 mc_lazy_dpl_addr = 0;
1210 /* MC is not loaded intentionally, So return success. */
1211 if (bd && get_mc_boot_status() != 0)
1214 if (bd && !get_mc_boot_status() && get_dpl_apply_status() == -1) {
1215 printf("ERROR: fsl-mc: DPL is not applied\n");
1220 if (bd && !get_mc_boot_status() && !get_dpl_apply_status())
1225 printf("dpbp_exit() failed: %d\n", err);
1231 printf("dpio_exit() failed: %d\n", err);
1237 printf("dpni_exit() failed: %d\n", err);
1243 printf("dprc_exit() failed: %d\n", err);
1252 static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1258 switch (argv[1][0]) {
1261 u64 mc_fw_addr, mc_dpc_addr;
1262 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1266 sub_cmd = argv[2][0];
1272 if (get_mc_boot_status() == 0) {
1273 printf("fsl-mc: MC is already booted");
1277 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1278 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1281 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1282 err = mc_init_object();
1285 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1289 if (get_aiop_apply_status() == 0) {
1290 printf("fsl-mc: AIOP FW is already");
1291 printf(" applied\n");
1295 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1298 /* if SoC doesn't have AIOP, err = -ENODEV */
1299 err = load_mc_aiop_img(aiop_fw_addr);
1301 printf("fsl-mc: AIOP FW applied\n");
1305 printf("Invalid option: %s\n", argv[2]);
1320 if (get_dpl_apply_status() == 0) {
1321 printf("fsl-mc: DPL already applied\n");
1325 mc_dpl_addr = simple_strtoull(argv[3], NULL,
1328 if (get_mc_boot_status() != 0) {
1329 printf("fsl-mc: Deploying data path layout ..");
1330 printf("ERROR (MC is not booted)\n");
1334 if (argv[1][0] == 'l') {
1336 * We will do the actual dpaa exit and dpl apply
1337 * later from announce_and_cleanup().
1339 mc_lazy_dpl_addr = mc_dpl_addr;
1341 /* The user wants it applied now */
1342 if (!fsl_mc_ldpaa_exit(NULL))
1343 err = mc_apply_dpl(mc_dpl_addr);
1348 printf("Invalid option: %s\n", argv[1]);
1354 return CMD_RET_USAGE;
1358 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1359 "DPAA2 command to manage Management Complex (MC)",
1360 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1361 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
1362 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
1363 "fsl_mc start aiop [FW_addr] - Start AIOP\n"