1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 Freescale Semiconductor, Inc.
5 * Copyright 2017-2018 NXP
10 #include <linux/bug.h>
12 #include <linux/libfdt.h>
14 #include <fdt_support.h>
15 #include <fsl-mc/fsl_mc.h>
16 #include <fsl-mc/fsl_mc_sys.h>
17 #include <fsl-mc/fsl_mc_private.h>
18 #include <fsl-mc/fsl_dpmng.h>
19 #include <fsl-mc/fsl_dprc.h>
20 #include <fsl-mc/fsl_dpio.h>
21 #include <fsl-mc/fsl_dpni.h>
22 #include <fsl-mc/fsl_qbman_portal.h>
23 #include <fsl-mc/ldpaa_wriop.h>
25 #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
26 #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
27 #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
29 #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
30 #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
31 #define MC_BOOT_ENV_VAR "mcinitcmd"
32 #define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024)
34 DECLARE_GLOBAL_DATA_PTR
;
35 static int mc_memset_resv_ram
;
36 static int mc_boot_status
= -1;
37 static int mc_dpl_applied
= -1;
38 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
39 static int mc_aiop_applied
= -1;
41 struct fsl_mc_io
*root_mc_io
= NULL
;
42 struct fsl_mc_io
*dflt_mc_io
= NULL
; /* child container */
43 uint16_t root_dprc_handle
= 0;
44 uint16_t dflt_dprc_handle
= 0;
46 struct fsl_dpbp_obj
*dflt_dpbp
= NULL
;
47 struct fsl_dpio_obj
*dflt_dpio
= NULL
;
48 struct fsl_dpni_obj
*dflt_dpni
= NULL
;
49 static u64 mc_lazy_dpl_addr
;
52 void dump_ram_words(const char *title
, void *addr
)
55 uint32_t *words
= addr
;
57 printf("Dumping beginning of %s (%p):\n", title
, addr
);
58 for (i
= 0; i
< 16; i
++)
59 printf("%#x ", words
[i
]);
64 void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem
*mc_ccsr_regs
)
66 printf("MC CCSR registers:\n"
76 mc_ccsr_regs
->reg_gcr1
,
77 mc_ccsr_regs
->reg_gsr
,
78 mc_ccsr_regs
->reg_sicbalr
,
79 mc_ccsr_regs
->reg_sicbahr
,
80 mc_ccsr_regs
->reg_sicapr
,
81 mc_ccsr_regs
->reg_mcfbalr
,
82 mc_ccsr_regs
->reg_mcfbahr
,
83 mc_ccsr_regs
->reg_mcfapr
,
84 mc_ccsr_regs
->reg_psr
);
88 #define dump_ram_words(title, addr)
89 #define dump_mc_ccsr_regs(mc_ccsr_regs)
93 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
95 * Copying MC firmware or DPL image to DDR
97 static int mc_copy_image(const char *title
,
98 u64 image_addr
, u32 image_size
, u64 mc_ram_addr
)
100 debug("%s copied to address %p\n", title
, (void *)mc_ram_addr
);
101 memcpy((void *)mc_ram_addr
, (void *)image_addr
, image_size
);
102 flush_dcache_range(mc_ram_addr
, mc_ram_addr
+ image_size
);
107 * MC firmware FIT image parser checks if the image is in FIT
108 * format, verifies integrity of the image and calculates
109 * raw image address and size values.
110 * Returns 0 on success and a negative errno on error.
113 int parse_mc_firmware_fit_image(u64 mc_fw_addr
,
114 const void **raw_image_addr
,
115 size_t *raw_image_size
)
122 const char *uname
= "firmware";
124 fit_hdr
= (void *)mc_fw_addr
;
126 /* Check if Image is in FIT format */
127 format
= genimg_get_format(fit_hdr
);
129 if (format
!= IMAGE_FORMAT_FIT
) {
130 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
134 if (!fit_check_format(fit_hdr
)) {
135 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
139 node_offset
= fit_image_get_node(fit_hdr
, uname
);
141 if (node_offset
< 0) {
142 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
146 /* Verify MC firmware image */
147 if (!(fit_image_verify(fit_hdr
, node_offset
))) {
148 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
152 /* Get address and size of raw image */
153 fit_image_get_data(fit_hdr
, node_offset
, &data
, &size
);
155 *raw_image_addr
= data
;
156 *raw_image_size
= size
;
162 #define MC_DT_INCREASE_SIZE 64
169 static int mc_fixup_mac_addr(void *blob
, int nodeoffset
,
170 const char *propname
, struct eth_device
*eth_dev
,
171 enum mc_fixup_type type
)
173 int err
= 0, len
= 0, size
, i
;
174 unsigned char env_enetaddr
[ARP_HLEN
];
175 unsigned int enetaddr_32
[ARP_HLEN
];
180 /* DPL likes its addresses on 32 * ARP_HLEN bits */
181 for (i
= 0; i
< ARP_HLEN
; i
++)
182 enetaddr_32
[i
] = cpu_to_fdt32(eth_dev
->enetaddr
[i
]);
184 len
= sizeof(enetaddr_32
);
188 val
= eth_dev
->enetaddr
;
193 /* MAC address property present */
194 if (fdt_get_property(blob
, nodeoffset
, propname
, NULL
)) {
195 /* u-boot MAC addr randomly assigned - leave the present one */
196 if (!eth_env_get_enetaddr_by_index("eth", eth_dev
->index
,
200 size
= MC_DT_INCREASE_SIZE
+ strlen(propname
) + len
;
201 /* make room for mac address property */
202 err
= fdt_increase_size(blob
, size
);
204 printf("fdt_increase_size: err=%s\n",
210 err
= fdt_setprop(blob
, nodeoffset
, propname
, val
, len
);
212 printf("fdt_setprop: err=%s\n", fdt_strerror(err
));
219 #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
221 const char *dpl_get_connection_endpoint(void *blob
, char *endpoint
)
223 int connoffset
= fdt_path_offset(blob
, "/connections"), off
;
226 for (off
= fdt_first_subnode(blob
, connoffset
);
228 off
= fdt_next_subnode(blob
, off
)) {
229 s1
= fdt_stringlist_get(blob
, off
, "endpoint1", 0, NULL
);
230 s2
= fdt_stringlist_get(blob
, off
, "endpoint2", 0, NULL
);
235 if (strcmp(endpoint
, s1
) == 0)
238 if (strcmp(endpoint
, s2
) == 0)
245 static int mc_fixup_dpl_mac_addr(void *blob
, int dpmac_id
,
246 struct eth_device
*eth_dev
)
248 int objoff
= fdt_path_offset(blob
, "/objects");
249 int dpmacoff
= -1, dpnioff
= -1;
250 const char *endpoint
;
254 sprintf(mac_name
, "dpmac@%d", dpmac_id
);
255 dpmacoff
= fdt_subnode_offset(blob
, objoff
, mac_name
);
257 /* dpmac not defined in DPL, so skip it. */
260 err
= mc_fixup_mac_addr(blob
, dpmacoff
, "mac_addr", eth_dev
,
263 printf("Error fixing up dpmac mac_addr in DPL\n");
267 /* now we need to figure out if there is any
268 * DPNI connected to this MAC, so we walk the
271 endpoint
= dpl_get_connection_endpoint(blob
, mac_name
);
272 if (!is_dpni(endpoint
))
275 /* let's see if we can fixup the DPNI as well */
276 dpnioff
= fdt_subnode_offset(blob
, objoff
, endpoint
);
278 /* DPNI not defined in DPL in the objects area */
281 return mc_fixup_mac_addr(blob
, dpnioff
, "mac_addr", eth_dev
,
285 void fdt_fsl_mc_fixup_iommu_map_entry(void *blob
)
292 /* find fsl-mc node */
293 offset
= fdt_path_offset(blob
, "/soc/fsl-mc");
295 offset
= fdt_path_offset(blob
, "/fsl-mc");
297 printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n",
302 prop
= fdt_getprop_w(blob
, offset
, "iommu-map", &lenp
);
304 debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n",
309 iommu_map
[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START
);
310 iommu_map
[1] = *++prop
;
311 iommu_map
[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START
);
312 iommu_map
[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END
-
313 FSL_DPAA2_STREAM_ID_START
+ 1);
315 fdt_setprop_inplace(blob
, offset
, "iommu-map",
316 iommu_map
, sizeof(iommu_map
));
319 static int mc_fixup_dpc_mac_addr(void *blob
, int dpmac_id
,
320 struct eth_device
*eth_dev
)
322 int nodeoffset
= fdt_path_offset(blob
, "/board_info/ports"), noff
;
325 const char link_type_mode
[] = "MAC_LINK_TYPE_FIXED";
327 sprintf(mac_name
, "mac@%d", dpmac_id
);
329 /* node not found - create it */
330 noff
= fdt_subnode_offset(blob
, nodeoffset
, (const char *)mac_name
);
332 err
= fdt_increase_size(blob
, 200);
334 printf("fdt_increase_size: err=%s\n",
339 noff
= fdt_add_subnode(blob
, nodeoffset
, mac_name
);
341 printf("fdt_add_subnode: err=%s\n",
346 /* add default property of fixed link */
347 err
= fdt_appendprop_string(blob
, noff
,
348 "link_type", link_type_mode
);
350 printf("fdt_appendprop_string: err=%s\n",
356 return mc_fixup_mac_addr(blob
, noff
, "port_mac_address", eth_dev
,
360 static int mc_fixup_mac_addrs(void *blob
, enum mc_fixup_type type
)
362 int i
, err
= 0, ret
= 0;
363 char ethname
[ETH_NAME_LEN
];
364 struct eth_device
*eth_dev
;
366 for (i
= WRIOP1_DPMAC1
; i
< NUM_WRIOP_PORTS
; i
++) {
367 /* port not enabled */
368 if (wriop_is_enabled_dpmac(i
) != 1)
371 snprintf(ethname
, ETH_NAME_LEN
, "DPMAC%d@%s", i
,
372 phy_interface_strings
[wriop_get_enet_if(i
)]);
374 eth_dev
= eth_get_dev_by_name(ethname
);
380 err
= mc_fixup_dpl_mac_addr(blob
, i
, eth_dev
);
383 err
= mc_fixup_dpc_mac_addr(blob
, i
, eth_dev
);
390 printf("fsl-mc: ERROR fixing mac address for %s\n",
398 static int mc_fixup_dpc(u64 dpc_addr
)
400 void *blob
= (void *)dpc_addr
;
401 int nodeoffset
, err
= 0;
403 /* delete any existing ICID pools */
404 nodeoffset
= fdt_path_offset(blob
, "/resources/icid_pools");
405 if (fdt_del_node(blob
, nodeoffset
) < 0)
406 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
409 nodeoffset
= fdt_path_offset(blob
, "/resources");
410 if (nodeoffset
< 0) {
411 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
414 nodeoffset
= fdt_add_subnode(blob
, nodeoffset
, "icid_pools");
415 nodeoffset
= fdt_add_subnode(blob
, nodeoffset
, "icid_pool@0");
416 do_fixup_by_path_u32(blob
, "/resources/icid_pools/icid_pool@0",
417 "base_icid", FSL_DPAA2_STREAM_ID_START
, 1);
418 do_fixup_by_path_u32(blob
, "/resources/icid_pools/icid_pool@0",
420 FSL_DPAA2_STREAM_ID_END
-
421 FSL_DPAA2_STREAM_ID_START
+ 1, 1);
423 /* fixup MAC addresses for dpmac ports */
424 nodeoffset
= fdt_path_offset(blob
, "/board_info/ports");
428 err
= mc_fixup_mac_addrs(blob
, MC_FIXUP_DPC
);
431 flush_dcache_range(dpc_addr
, dpc_addr
+ fdt_totalsize(blob
));
436 static int load_mc_dpc(u64 mc_ram_addr
, size_t mc_ram_size
, u64 mc_dpc_addr
)
439 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
445 #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
446 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
& 0x3) != 0 ||
447 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
> 0xffffffff);
449 mc_dpc_offset
= CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
;
451 #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
455 * Load the MC DPC blob in the MC private DRAM block:
457 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
458 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr
+ mc_dpc_offset
);
461 * Get address and size of the DPC blob stored in flash:
463 dpc_fdt_hdr
= (void *)mc_dpc_addr
;
465 error
= fdt_check_header(dpc_fdt_hdr
);
468 * Don't return with error here, since the MC firmware can
469 * still boot without a DPC
471 printf("\nfsl-mc: WARNING: No DPC image found");
475 dpc_size
= fdt_totalsize(dpc_fdt_hdr
);
476 if (dpc_size
> CONFIG_SYS_LS_MC_DPC_MAX_LENGTH
) {
477 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
482 mc_copy_image("MC DPC blob",
483 (u64
)dpc_fdt_hdr
, dpc_size
, mc_ram_addr
+ mc_dpc_offset
);
484 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
486 if (mc_fixup_dpc(mc_ram_addr
+ mc_dpc_offset
))
489 dump_ram_words("DPC", (void *)(mc_ram_addr
+ mc_dpc_offset
));
494 static int mc_fixup_dpl(u64 dpl_addr
)
496 void *blob
= (void *)dpl_addr
;
497 u32 ver
= fdt_getprop_u32_default(blob
, "/", "dpl-version", 0);
500 /* The DPL fixup for mac addresses is only relevant
506 err
= mc_fixup_mac_addrs(blob
, MC_FIXUP_DPL
);
507 flush_dcache_range(dpl_addr
, dpl_addr
+ fdt_totalsize(blob
));
512 static int load_mc_dpl(u64 mc_ram_addr
, size_t mc_ram_size
, u64 mc_dpl_addr
)
515 #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
521 #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
522 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
& 0x3) != 0 ||
523 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
> 0xffffffff);
525 mc_dpl_offset
= CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
;
527 #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
531 * Load the MC DPL blob in the MC private DRAM block:
533 #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
534 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr
+ mc_dpl_offset
);
537 * Get address and size of the DPL blob stored in flash:
539 dpl_fdt_hdr
= (void *)mc_dpl_addr
;
541 error
= fdt_check_header(dpl_fdt_hdr
);
543 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
547 dpl_size
= fdt_totalsize(dpl_fdt_hdr
);
548 if (dpl_size
> CONFIG_SYS_LS_MC_DPL_MAX_LENGTH
) {
549 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
554 mc_copy_image("MC DPL blob",
555 (u64
)dpl_fdt_hdr
, dpl_size
, mc_ram_addr
+ mc_dpl_offset
);
556 #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
558 if (mc_fixup_dpl(mc_ram_addr
+ mc_dpl_offset
))
560 dump_ram_words("DPL", (void *)(mc_ram_addr
+ mc_dpl_offset
));
565 * Return the MC boot timeout value in milliseconds
567 static unsigned long get_mc_boot_timeout_ms(void)
569 unsigned long timeout_ms
= CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS
;
571 char *timeout_ms_env_var
= env_get(MC_BOOT_TIMEOUT_ENV_VAR
);
573 if (timeout_ms_env_var
) {
574 timeout_ms
= simple_strtoul(timeout_ms_env_var
, NULL
, 10);
575 if (timeout_ms
== 0) {
576 printf("fsl-mc: WARNING: Invalid value for \'"
577 MC_BOOT_TIMEOUT_ENV_VAR
578 "\' environment variable: %lu\n",
581 timeout_ms
= CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS
;
588 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
590 __weak
bool soc_has_aiop(void)
595 static int load_mc_aiop_img(u64 aiop_fw_addr
)
597 u64 mc_ram_addr
= mc_get_dram_addr();
598 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
602 /* Check if AIOP is available */
606 * Load the MC AIOP image in the MC private DRAM block:
609 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
610 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr
+
611 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
);
613 aiop_img
= (void *)aiop_fw_addr
;
614 mc_copy_image("MC AIOP image",
615 (u64
)aiop_img
, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH
,
616 mc_ram_addr
+ CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
);
624 static int wait_for_mc(bool booting_mc
, u32
*final_reg_gsr
)
627 u32 mc_fw_boot_status
;
628 unsigned long timeout_ms
= get_mc_boot_timeout_ms();
629 struct mc_ccsr_registers __iomem
*mc_ccsr_regs
= MC_CCSR_BASE_ADDR
;
632 assert(timeout_ms
> 0);
634 udelay(1000); /* throttle polling */
635 reg_gsr
= in_le32(&mc_ccsr_regs
->reg_gsr
);
636 mc_fw_boot_status
= (reg_gsr
& GSR_FS_MASK
);
637 if (mc_fw_boot_status
& 0x1)
645 if (timeout_ms
== 0) {
646 printf("ERROR: timeout\n");
648 /* TODO: Get an error status from an MC CCSR register */
652 if (mc_fw_boot_status
!= 0x1) {
654 * TODO: Identify critical errors from the GSR register's FS
655 * field and for those errors, set error to -ENODEV or other
656 * appropriate errno, so that the status property is set to
657 * failure in the fsl,dprc device tree node.
659 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
666 *final_reg_gsr
= reg_gsr
;
670 int mc_init(u64 mc_fw_addr
, u64 mc_dpc_addr
)
674 struct mc_ccsr_registers __iomem
*mc_ccsr_regs
= MC_CCSR_BASE_ADDR
;
675 u64 mc_ram_addr
= mc_get_dram_addr();
678 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
679 const void *raw_image_addr
;
680 size_t raw_image_size
= 0;
682 struct mc_version mc_ver_info
;
683 u8 mc_ram_num_256mb_blocks
;
684 size_t mc_ram_size
= mc_get_dram_block_size();
686 mc_ram_num_256mb_blocks
= mc_ram_size
/ MC_RAM_SIZE_ALIGNMENT
;
688 if (mc_ram_num_256mb_blocks
>= 0xff) {
690 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
696 * To support 128 MB DDR Size for MC
698 if (mc_ram_num_256mb_blocks
== 0)
699 mc_ram_num_256mb_blocks
= 0xFF;
702 * Management Complex cores should be held at reset out of POR.
703 * U-Boot should be the first software to touch MC. To be safe,
704 * we reset all cores again by setting GCR1 to 0. It doesn't do
705 * anything if they are held at reset. After we setup the firmware
706 * we kick off MC by deasserting the reset bit for core 0, and
707 * deasserting the reset bits for Command Portal Managers.
708 * The stop bits are not touched here. They are used to stop the
709 * cores when they are active. Setting stop bits doesn't stop the
710 * cores from fetching instructions when they are released from
713 out_le32(&mc_ccsr_regs
->reg_gcr1
, 0);
716 #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
717 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr
);
719 error
= parse_mc_firmware_fit_image(mc_fw_addr
, &raw_image_addr
,
724 * Load the MC FW at the beginning of the MC private DRAM block:
726 mc_copy_image("MC Firmware",
727 (u64
)raw_image_addr
, raw_image_size
, mc_ram_addr
);
729 dump_ram_words("firmware", (void *)mc_ram_addr
);
731 error
= load_mc_dpc(mc_ram_addr
, mc_ram_size
, mc_dpc_addr
);
735 debug("mc_ccsr_regs %p\n", mc_ccsr_regs
);
736 dump_mc_ccsr_regs(mc_ccsr_regs
);
739 * Tell MC what is the address range of the DRAM block assigned to it:
741 if (mc_ram_num_256mb_blocks
< 0xFF) {
742 reg_mcfbalr
= (u32
)mc_ram_addr
|
743 (mc_ram_num_256mb_blocks
- 1);
745 reg_mcfbalr
= (u32
)mc_ram_addr
|
746 (mc_ram_num_256mb_blocks
);
749 out_le32(&mc_ccsr_regs
->reg_mcfbalr
, reg_mcfbalr
);
750 out_le32(&mc_ccsr_regs
->reg_mcfbahr
,
751 (u32
)(mc_ram_addr
>> 32));
752 out_le32(&mc_ccsr_regs
->reg_mcfapr
, FSL_BYPASS_AMQ
);
755 * Tell the MC that we want delayed DPL deployment.
757 out_le32(&mc_ccsr_regs
->reg_gsr
, 0xDD00);
759 printf("\nfsl-mc: Booting Management Complex ... ");
762 * Deassert reset and release MC core 0 to run
764 out_le32(&mc_ccsr_regs
->reg_gcr1
, GCR1_P1_DE_RST
| GCR1_M_ALL_DE_RST
);
765 error
= wait_for_mc(true, ®_gsr
);
770 * TODO: need to obtain the portal_id for the root container from the
776 * Initialize the global default MC portal
777 * And check that the MC firmware is responding portal commands:
779 root_mc_io
= (struct fsl_mc_io
*)calloc(sizeof(struct fsl_mc_io
), 1);
781 printf(" No memory: calloc() failed\n");
785 root_mc_io
->mmio_regs
= SOC_MC_PORTAL_ADDR(portal_id
);
786 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
787 portal_id
, root_mc_io
->mmio_regs
);
789 error
= mc_get_version(root_mc_io
, MC_CMD_NO_FLAGS
, &mc_ver_info
);
791 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
796 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
797 mc_ver_info
.major
, mc_ver_info
.minor
, mc_ver_info
.revision
,
798 reg_gsr
& GSR_FS_MASK
);
802 mc_boot_status
= error
;
809 int mc_apply_dpl(u64 mc_dpl_addr
)
811 struct mc_ccsr_registers __iomem
*mc_ccsr_regs
= MC_CCSR_BASE_ADDR
;
814 u64 mc_ram_addr
= mc_get_dram_addr();
815 size_t mc_ram_size
= mc_get_dram_block_size();
820 error
= load_mc_dpl(mc_ram_addr
, mc_ram_size
, mc_dpl_addr
);
825 * Tell the MC to deploy the DPL:
827 out_le32(&mc_ccsr_regs
->reg_gsr
, 0x0);
828 printf("fsl-mc: Deploying data path layout ... ");
829 error
= wait_for_mc(false, ®_gsr
);
837 int get_mc_boot_status(void)
839 return mc_boot_status
;
842 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
843 int get_aiop_apply_status(void)
845 return mc_aiop_applied
;
849 int get_dpl_apply_status(void)
851 return mc_dpl_applied
;
854 int is_lazy_dpl_addr_valid(void)
856 return !!mc_lazy_dpl_addr
;
860 * Return the MC address of private DRAM block.
861 * As per MC design document, MC initial base address
862 * should be least significant 512MB address of MC private
863 * memory, i.e. address should point to end address masked
864 * with 512MB offset in private DRAM block.
866 u64
mc_get_dram_addr(void)
868 size_t mc_ram_size
= mc_get_dram_block_size();
870 if (!mc_memset_resv_ram
|| (get_mc_boot_status() < 0)) {
871 mc_memset_resv_ram
= 1;
872 memset((void *)gd
->arch
.resv_ram
, 0, mc_ram_size
);
875 return (gd
->arch
.resv_ram
+ mc_ram_size
- 1) &
876 MC_RAM_BASE_ADDR_ALIGNMENT_MASK
;
880 * Return the actual size of the MC private DRAM block.
882 unsigned long mc_get_dram_block_size(void)
884 unsigned long dram_block_size
= CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE
;
886 char *dram_block_size_env_var
= env_get(MC_MEM_SIZE_ENV_VAR
);
888 if (dram_block_size_env_var
) {
889 dram_block_size
= simple_strtoul(dram_block_size_env_var
, NULL
,
892 if (dram_block_size
< CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE
) {
893 printf("fsl-mc: WARNING: Invalid value for \'"
895 "\' environment variable: %lu\n",
898 dram_block_size
= MC_DRAM_BLOCK_DEFAULT_SIZE
;
902 return dram_block_size
;
905 int fsl_mc_ldpaa_init(bd_t
*bis
)
909 for (i
= WRIOP1_DPMAC1
; i
< NUM_WRIOP_PORTS
; i
++)
910 if (wriop_is_enabled_dpmac(i
) == 1)
911 ldpaa_eth_init(i
, wriop_get_enet_if(i
));
915 static int dprc_version_check(struct fsl_mc_io
*mc_io
, uint16_t handle
)
918 uint16_t major_ver
, minor_ver
;
920 error
= dprc_get_api_version(mc_io
, 0,
924 printf("dprc_get_api_version() failed: %d\n", error
);
928 if (major_ver
< DPRC_VER_MAJOR
|| (major_ver
== DPRC_VER_MAJOR
&&
929 minor_ver
< DPRC_VER_MINOR
)) {
930 printf("DPRC version mismatch found %u.%u,",
931 major_ver
, minor_ver
);
932 printf("supported version is %u.%u\n",
933 DPRC_VER_MAJOR
, DPRC_VER_MINOR
);
939 static int dpio_init(void)
941 struct qbman_swp_desc p_des
;
942 struct dpio_attr attr
;
943 struct dpio_cfg dpio_cfg
;
945 uint16_t major_ver
, minor_ver
;
947 dflt_dpio
= (struct fsl_dpio_obj
*)calloc(
948 sizeof(struct fsl_dpio_obj
), 1);
950 printf("No memory: calloc() failed\n");
954 dpio_cfg
.channel_mode
= DPIO_LOCAL_CHANNEL
;
955 dpio_cfg
.num_priorities
= 8;
957 err
= dpio_create(dflt_mc_io
,
961 &dflt_dpio
->dpio_id
);
963 printf("dpio_create() failed: %d\n", err
);
968 err
= dpio_get_api_version(dflt_mc_io
, 0,
972 printf("dpio_get_api_version() failed: %d\n", err
);
973 goto err_get_api_ver
;
976 if (major_ver
< DPIO_VER_MAJOR
|| (major_ver
== DPIO_VER_MAJOR
&&
977 minor_ver
< DPIO_VER_MINOR
)) {
978 printf("DPRC version mismatch found %u.%u,",
983 err
= dpio_open(dflt_mc_io
,
986 &dflt_dpio
->dpio_handle
);
988 printf("dpio_open() failed\n");
992 memset(&attr
, 0, sizeof(struct dpio_attr
));
993 err
= dpio_get_attributes(dflt_mc_io
, MC_CMD_NO_FLAGS
,
994 dflt_dpio
->dpio_handle
, &attr
);
996 printf("dpio_get_attributes() failed: %d\n", err
);
1000 if (dflt_dpio
->dpio_id
!= attr
.id
) {
1001 printf("dnpi object id and attribute id are not same\n");
1002 goto err_attr_not_same
;
1006 printf("Init: DPIO id=0x%d\n", dflt_dpio
->dpio_id
);
1008 err
= dpio_enable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpio
->dpio_handle
);
1010 printf("dpio_enable() failed %d\n", err
);
1011 goto err_get_enable
;
1013 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
1014 attr
.qbman_portal_ce_offset
,
1015 attr
.qbman_portal_ci_offset
,
1016 attr
.qbman_portal_id
,
1017 attr
.num_priorities
);
1019 p_des
.cena_bar
= (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1020 + attr
.qbman_portal_ce_offset
);
1021 p_des
.cinh_bar
= (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1022 + attr
.qbman_portal_ci_offset
);
1024 dflt_dpio
->sw_portal
= qbman_swp_init(&p_des
);
1025 if (dflt_dpio
->sw_portal
== NULL
) {
1026 printf("qbman_swp_init() failed\n");
1027 goto err_get_swp_init
;
1032 dpio_disable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpio
->dpio_handle
);
1036 dpio_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpio
->dpio_handle
);
1039 dpio_destroy(dflt_mc_io
,
1042 dflt_dpio
->dpio_id
);
1049 static int dpio_exit(void)
1053 err
= dpio_disable(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpio
->dpio_handle
);
1055 printf("dpio_disable() failed: %d\n", err
);
1059 dpio_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpio
->dpio_handle
);
1061 printf("dpio_close() failed: %d\n", err
);
1065 err
= dpio_destroy(dflt_mc_io
,
1068 dflt_dpio
->dpio_id
);
1070 printf("dpio_destroy() failed: %d\n", err
);
1075 printf("Exit: DPIO id=0x%d\n", dflt_dpio
->dpio_id
);
1086 static int dprc_init(void)
1088 int err
, child_portal_id
, container_id
;
1089 struct dprc_cfg cfg
;
1090 uint64_t mc_portal_offset
;
1092 /* Open root container */
1093 err
= dprc_get_container_id(root_mc_io
, MC_CMD_NO_FLAGS
, &container_id
);
1095 printf("dprc_get_container_id(): Root failed: %d\n", err
);
1096 goto err_root_container_id
;
1100 printf("Root container id = %d\n", container_id
);
1102 err
= dprc_open(root_mc_io
, MC_CMD_NO_FLAGS
, container_id
,
1105 printf("dprc_open(): Root Container failed: %d\n", err
);
1109 if (!root_dprc_handle
) {
1110 printf("dprc_open(): Root Container Handle is not valid\n");
1114 err
= dprc_version_check(root_mc_io
, root_dprc_handle
);
1116 printf("dprc_version_check() failed: %d\n", err
);
1120 memset(&cfg
, 0, sizeof(struct dprc_cfg
));
1121 cfg
.options
= DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED
|
1122 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED
|
1123 DPRC_CFG_OPT_ALLOC_ALLOWED
;
1124 cfg
.icid
= DPRC_GET_ICID_FROM_POOL
;
1125 cfg
.portal_id
= DPRC_GET_PORTAL_ID_FROM_POOL
;
1126 err
= dprc_create_container(root_mc_io
, MC_CMD_NO_FLAGS
,
1132 printf("dprc_create_container() failed: %d\n", err
);
1136 dflt_mc_io
= (struct fsl_mc_io
*)calloc(sizeof(struct fsl_mc_io
), 1);
1139 printf(" No memory: calloc() failed\n");
1143 child_portal_id
= MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset
);
1144 dflt_mc_io
->mmio_regs
= SOC_MC_PORTAL_ADDR(child_portal_id
);
1147 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1148 child_dprc_id
, dflt_mc_io
->mmio_regs
);
1151 err
= dprc_open(dflt_mc_io
, MC_CMD_NO_FLAGS
, child_dprc_id
,
1154 printf("dprc_open(): Child container failed: %d\n", err
);
1155 goto err_child_open
;
1158 if (!dflt_dprc_handle
) {
1159 printf("dprc_open(): Child container Handle is not valid\n");
1160 goto err_child_open
;
1167 dprc_destroy_container(root_mc_io
, MC_CMD_NO_FLAGS
,
1168 root_dprc_handle
, child_dprc_id
);
1170 dprc_close(root_mc_io
, MC_CMD_NO_FLAGS
, root_dprc_handle
);
1172 err_root_container_id
:
1176 static int dprc_exit(void)
1180 err
= dprc_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dprc_handle
);
1182 printf("dprc_close(): Child failed: %d\n", err
);
1186 err
= dprc_destroy_container(root_mc_io
, MC_CMD_NO_FLAGS
,
1187 root_dprc_handle
, child_dprc_id
);
1189 printf("dprc_destroy_container() failed: %d\n", err
);
1193 err
= dprc_close(root_mc_io
, MC_CMD_NO_FLAGS
, root_dprc_handle
);
1195 printf("dprc_close(): Root failed: %d\n", err
);
1211 static int dpbp_init(void)
1214 struct dpbp_attr dpbp_attr
;
1215 struct dpbp_cfg dpbp_cfg
;
1216 uint16_t major_ver
, minor_ver
;
1218 dflt_dpbp
= (struct fsl_dpbp_obj
*)calloc(
1219 sizeof(struct fsl_dpbp_obj
), 1);
1221 printf("No memory: calloc() failed\n");
1226 dpbp_cfg
.options
= 512;
1228 err
= dpbp_create(dflt_mc_io
,
1232 &dflt_dpbp
->dpbp_id
);
1236 printf("dpbp_create() failed: %d\n", err
);
1240 err
= dpbp_get_api_version(dflt_mc_io
, 0,
1244 printf("dpbp_get_api_version() failed: %d\n", err
);
1245 goto err_get_api_ver
;
1248 if (major_ver
< DPBP_VER_MAJOR
|| (major_ver
== DPBP_VER_MAJOR
&&
1249 minor_ver
< DPBP_VER_MINOR
)) {
1250 printf("DPBP version mismatch found %u.%u,",
1251 major_ver
, minor_ver
);
1252 printf("supported version is %u.%u\n",
1253 DPBP_VER_MAJOR
, DPBP_VER_MINOR
);
1256 err
= dpbp_open(dflt_mc_io
,
1259 &dflt_dpbp
->dpbp_handle
);
1261 printf("dpbp_open() failed\n");
1265 memset(&dpbp_attr
, 0, sizeof(struct dpbp_attr
));
1266 err
= dpbp_get_attributes(dflt_mc_io
, MC_CMD_NO_FLAGS
,
1267 dflt_dpbp
->dpbp_handle
,
1270 printf("dpbp_get_attributes() failed: %d\n", err
);
1274 if (dflt_dpbp
->dpbp_id
!= dpbp_attr
.id
) {
1275 printf("dpbp object id and attribute id are not same\n");
1276 goto err_attr_not_same
;
1280 printf("Init: DPBP id=0x%x\n", dflt_dpbp
->dpbp_attr
.id
);
1283 err
= dpbp_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
1285 printf("dpbp_close() failed: %d\n", err
);
1293 dpbp_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpbp
->dpbp_handle
);
1294 dpbp_destroy(dflt_mc_io
,
1297 dflt_dpbp
->dpbp_id
);
1307 static int dpbp_exit(void)
1311 err
= dpbp_destroy(dflt_mc_io
, dflt_dprc_handle
, MC_CMD_NO_FLAGS
,
1312 dflt_dpbp
->dpbp_id
);
1314 printf("dpbp_destroy() failed: %d\n", err
);
1319 printf("Exit: DPBP id=0x%d\n", dflt_dpbp
->dpbp_attr
.id
);
1330 static int dpni_init(void)
1333 uint8_t cfg_buf
[256] = {0};
1334 struct dpni_cfg dpni_cfg
;
1335 uint16_t major_ver
, minor_ver
;
1337 dflt_dpni
= (struct fsl_dpni_obj
*)calloc(
1338 sizeof(struct fsl_dpni_obj
), 1);
1340 printf("No memory: calloc() failed\n");
1345 memset(&dpni_cfg
, 0, sizeof(dpni_cfg
));
1346 err
= dpni_prepare_cfg(&dpni_cfg
, &cfg_buf
[0]);
1349 printf("dpni_prepare_cfg() failed: %d\n", err
);
1350 goto err_prepare_cfg
;
1353 err
= dpni_create(dflt_mc_io
,
1357 &dflt_dpni
->dpni_id
);
1360 printf("dpni create() failed: %d\n", err
);
1364 err
= dpni_get_api_version(dflt_mc_io
, 0,
1368 printf("dpni_get_api_version() failed: %d\n", err
);
1369 goto err_get_version
;
1372 if (major_ver
< DPNI_VER_MAJOR
|| (major_ver
== DPNI_VER_MAJOR
&&
1373 minor_ver
< DPNI_VER_MINOR
)) {
1374 printf("DPNI version mismatch found %u.%u,",
1375 major_ver
, minor_ver
);
1376 printf("supported version is %u.%u\n",
1377 DPNI_VER_MAJOR
, DPNI_VER_MINOR
);
1380 err
= dpni_open(dflt_mc_io
,
1383 &dflt_dpni
->dpni_handle
);
1385 printf("dpni_open() failed\n");
1390 printf("Init: DPNI id=0x%d\n", dflt_dpni
->dpni_id
);
1392 err
= dpni_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
1394 printf("dpni_close() failed: %d\n", err
);
1401 dpni_close(dflt_mc_io
, MC_CMD_NO_FLAGS
, dflt_dpni
->dpni_handle
);
1404 dpni_destroy(dflt_mc_io
,
1407 dflt_dpni
->dpni_id
);
1415 static int dpni_exit(void)
1419 err
= dpni_destroy(dflt_mc_io
, dflt_dprc_handle
, MC_CMD_NO_FLAGS
,
1420 dflt_dpni
->dpni_id
);
1422 printf("dpni_destroy() failed: %d\n", err
);
1427 printf("Exit: DPNI id=0x%d\n", dflt_dpni
->dpni_id
);
1438 static int mc_init_object(void)
1444 printf("dprc_init() failed: %d\n", err
);
1450 printf("dpbp_init() failed: %d\n", err
);
1456 printf("dpio_init() failed: %d\n", err
);
1462 printf("dpni_init() failed: %d\n", err
);
1471 int fsl_mc_ldpaa_exit(bd_t
*bd
)
1474 bool is_dpl_apply_status
= false;
1475 bool mc_boot_status
= false;
1477 if (bd
&& mc_lazy_dpl_addr
&& !fsl_mc_ldpaa_exit(NULL
)) {
1478 err
= mc_apply_dpl(mc_lazy_dpl_addr
);
1480 fdt_fixup_board_enet(working_fdt
);
1481 mc_lazy_dpl_addr
= 0;
1484 if (!get_mc_boot_status())
1485 mc_boot_status
= true;
1487 /* MC is not loaded intentionally, So return success. */
1488 if (bd
&& !mc_boot_status
)
1491 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1492 if (!get_dpl_apply_status())
1493 is_dpl_apply_status
= true;
1496 * For case MC is loaded but DPL is not deployed, return success and
1497 * print message on console. Else FDT fix-up code execution hanged.
1499 if (bd
&& mc_boot_status
&& !is_dpl_apply_status
) {
1500 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
1501 goto mc_obj_cleanup
;
1504 if (bd
&& mc_boot_status
&& is_dpl_apply_status
)
1510 printf("dpbp_exit() failed: %d\n", err
);
1516 printf("dpio_exit() failed: %d\n", err
);
1522 printf("dpni_exit() failed: %d\n", err
);
1528 printf("dprc_exit() failed: %d\n", err
);
1537 static int do_fsl_mc(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1543 switch (argv
[1][0]) {
1546 u64 mc_fw_addr
, mc_dpc_addr
;
1547 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1551 sub_cmd
= argv
[2][0];
1558 if (get_mc_boot_status() == 0) {
1559 printf("fsl-mc: MC is already booted");
1563 mc_fw_addr
= simple_strtoull(argv
[3], NULL
, 16);
1564 mc_dpc_addr
= simple_strtoull(argv
[4], NULL
,
1567 if (!mc_init(mc_fw_addr
, mc_dpc_addr
))
1568 err
= mc_init_object();
1571 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1575 if (get_aiop_apply_status() == 0) {
1576 printf("fsl-mc: AIOP FW is already");
1577 printf(" applied\n");
1581 aiop_fw_addr
= simple_strtoull(argv
[3], NULL
,
1584 /* if SoC doesn't have AIOP, err = -ENODEV */
1585 err
= load_mc_aiop_img(aiop_fw_addr
);
1587 printf("fsl-mc: AIOP FW applied\n");
1591 printf("Invalid option: %s\n", argv
[2]);
1606 if (get_dpl_apply_status() == 0) {
1607 printf("fsl-mc: DPL already applied\n");
1611 mc_dpl_addr
= simple_strtoull(argv
[3], NULL
,
1614 if (get_mc_boot_status() != 0) {
1615 printf("fsl-mc: Deploying data path layout ..");
1616 printf("ERROR (MC is not booted)\n");
1620 if (argv
[1][0] == 'l') {
1622 * We will do the actual dpaa exit and dpl apply
1623 * later from announce_and_cleanup().
1625 mc_lazy_dpl_addr
= mc_dpl_addr
;
1627 /* The user wants it applied now */
1628 if (!fsl_mc_ldpaa_exit(NULL
))
1629 err
= mc_apply_dpl(mc_dpl_addr
);
1634 printf("Invalid option: %s\n", argv
[1]);
1640 return CMD_RET_USAGE
;
1644 fsl_mc
, CONFIG_SYS_MAXARGS
, 1, do_fsl_mc
,
1645 "DPAA2 command to manage Management Complex (MC)",
1646 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1647 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
1648 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
1649 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1652 void mc_env_boot(void)
1654 #if defined(CONFIG_FSL_MC_ENET)
1655 char *mc_boot_env_var
;
1656 /* The MC may only be initialized in the reset PHY function
1657 * because otherwise U-Boot has not yet set up all the MAC
1658 * address info properly. Without MAC addresses, the MC code
1659 * can not properly initialize the DPC.
1661 mc_boot_env_var
= env_get(MC_BOOT_ENV_VAR
);
1662 if (mc_boot_env_var
)
1663 run_command_list(mc_boot_env_var
, -1, 0);
1664 #endif /* CONFIG_FSL_MC_ENET */