Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 2 | /* |
Yogesh Gaur | 1a0c4ae | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Cosmin-Florin Aluchenesei | 971dfd3 | 2021-07-21 19:13:33 +0300 | [diff] [blame] | 4 | * Copyright 2017-2018, 2020-2021 NXP |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 5 | */ |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 10 | #include <errno.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 13 | #include <malloc.h> |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 14 | #include <mapmem.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Masahiro Yamada | 78eeb91 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 16 | #include <linux/bug.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 17 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 18 | #include <linux/delay.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 19 | #include <linux/libfdt.h> |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 20 | #include <net.h> |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 21 | #include <fdt_support.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 22 | #include <fsl-mc/fsl_mc.h> |
| 23 | #include <fsl-mc/fsl_mc_sys.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 24 | #include <fsl-mc/fsl_mc_private.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 25 | #include <fsl-mc/fsl_dpmng.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 26 | #include <fsl-mc/fsl_dprc.h> |
| 27 | #include <fsl-mc/fsl_dpio.h> |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 28 | #include <fsl-mc/fsl_dpni.h> |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 29 | #include <fsl-mc/fsl_dpsparser.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 30 | #include <fsl-mc/fsl_qbman_portal.h> |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 31 | #include <fsl-mc/ldpaa_wriop.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 32 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 33 | #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024) |
| 34 | #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1)) |
| 35 | #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024) |
| 36 | |
| 37 | #define MC_MEM_SIZE_ENV_VAR "mcmemsize" |
| 38 | #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout" |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 39 | #define MC_BOOT_ENV_VAR "mcinitcmd" |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 40 | #define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 41 | |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 42 | #define MC_BUFFER_SIZE (1024 * 1024 * 16) |
| 43 | #define MAGIC_MC 0x4d430100 |
| 44 | #define MC_FW_ADDR_MASK_LOW 0xE0000000 |
| 45 | #define MC_FW_ADDR_MASK_HIGH 0X1FFFF |
| 46 | #define MC_STRUCT_BUFFER_OFFSET 0x01000000 |
| 47 | #define MC_OFFSET_DELTA MC_STRUCT_BUFFER_OFFSET |
| 48 | |
| 49 | #define LOG_HEADER_FLAG_BUFFER_WRAPAROUND 0x80000000 |
| 50 | #define LAST_BYTE(a) ((a) & ~(LOG_HEADER_FLAG_BUFFER_WRAPAROUND)) |
| 51 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 52 | DECLARE_GLOBAL_DATA_PTR; |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 53 | static int mc_memset_resv_ram; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 54 | static struct mc_version mc_ver_info; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 55 | static int mc_boot_status = -1; |
| 56 | static int mc_dpl_applied = -1; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 57 | #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 58 | static int mc_aiop_applied = -1; |
| 59 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 60 | struct fsl_mc_io *root_mc_io = NULL; |
| 61 | struct fsl_mc_io *dflt_mc_io = NULL; /* child container */ |
| 62 | uint16_t root_dprc_handle = 0; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 63 | uint16_t dflt_dprc_handle = 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 64 | int child_dprc_id; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 65 | struct fsl_dpbp_obj *dflt_dpbp = NULL; |
| 66 | struct fsl_dpio_obj *dflt_dpio = NULL; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 67 | struct fsl_dpni_obj *dflt_dpni = NULL; |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 68 | static u64 mc_lazy_dpl_addr; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 69 | static u32 dpsparser_obj_id; |
| 70 | static u16 dpsparser_handle; |
| 71 | static char *mc_err_msg_apply_spb[] = MC_ERROR_MSG_APPLY_SPB; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 72 | |
| 73 | #ifdef DEBUG |
| 74 | void dump_ram_words(const char *title, void *addr) |
| 75 | { |
| 76 | int i; |
| 77 | uint32_t *words = addr; |
| 78 | |
| 79 | printf("Dumping beginning of %s (%p):\n", title, addr); |
| 80 | for (i = 0; i < 16; i++) |
| 81 | printf("%#x ", words[i]); |
| 82 | |
| 83 | printf("\n"); |
| 84 | } |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 85 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 86 | void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs) |
| 87 | { |
| 88 | printf("MC CCSR registers:\n" |
| 89 | "reg_gcr1 %#x\n" |
| 90 | "reg_gsr %#x\n" |
| 91 | "reg_sicbalr %#x\n" |
| 92 | "reg_sicbahr %#x\n" |
| 93 | "reg_sicapr %#x\n" |
| 94 | "reg_mcfbalr %#x\n" |
| 95 | "reg_mcfbahr %#x\n" |
| 96 | "reg_mcfapr %#x\n" |
| 97 | "reg_psr %#x\n", |
| 98 | mc_ccsr_regs->reg_gcr1, |
| 99 | mc_ccsr_regs->reg_gsr, |
| 100 | mc_ccsr_regs->reg_sicbalr, |
| 101 | mc_ccsr_regs->reg_sicbahr, |
| 102 | mc_ccsr_regs->reg_sicapr, |
| 103 | mc_ccsr_regs->reg_mcfbalr, |
| 104 | mc_ccsr_regs->reg_mcfbahr, |
| 105 | mc_ccsr_regs->reg_mcfapr, |
| 106 | mc_ccsr_regs->reg_psr); |
| 107 | } |
| 108 | #else |
| 109 | |
| 110 | #define dump_ram_words(title, addr) |
| 111 | #define dump_mc_ccsr_regs(mc_ccsr_regs) |
| 112 | |
| 113 | #endif /* DEBUG */ |
| 114 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 115 | /** |
| 116 | * Copying MC firmware or DPL image to DDR |
| 117 | */ |
| 118 | static int mc_copy_image(const char *title, |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 119 | u64 image_addr, u32 image_size, u64 mc_ram_addr) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 120 | { |
| 121 | debug("%s copied to address %p\n", title, (void *)mc_ram_addr); |
| 122 | memcpy((void *)mc_ram_addr, (void *)image_addr, image_size); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 123 | flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 124 | return 0; |
| 125 | } |
| 126 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 127 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 128 | /** |
| 129 | * MC firmware FIT image parser checks if the image is in FIT |
| 130 | * format, verifies integrity of the image and calculates |
| 131 | * raw image address and size values. |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 132 | * Returns 0 on success and a negative errno on error. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 133 | * task fail. |
| 134 | **/ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 135 | int parse_mc_firmware_fit_image(u64 mc_fw_addr, |
| 136 | const void **raw_image_addr, |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 137 | size_t *raw_image_size) |
| 138 | { |
| 139 | int format; |
Sean Anderson | 4b2c94f | 2022-08-16 11:16:06 -0400 | [diff] [blame] | 140 | void *fit_hdr = (void *)mc_fw_addr; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 141 | |
| 142 | /* Check if Image is in FIT format */ |
| 143 | format = genimg_get_format(fit_hdr); |
| 144 | |
| 145 | if (format != IMAGE_FORMAT_FIT) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 146 | printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 147 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Simon Glass | d563c25 | 2021-02-15 17:08:09 -0700 | [diff] [blame] | 150 | if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 151 | printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 152 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Sean Anderson | 4b2c94f | 2022-08-16 11:16:06 -0400 | [diff] [blame] | 155 | return fit_get_data_node(fit_hdr, "firmware", raw_image_addr, |
| 156 | raw_image_size); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 157 | } |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 158 | #endif |
| 159 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 160 | #define MC_DT_INCREASE_SIZE 64 |
| 161 | |
| 162 | enum mc_fixup_type { |
| 163 | MC_FIXUP_DPL, |
| 164 | MC_FIXUP_DPC |
| 165 | }; |
| 166 | |
| 167 | static int mc_fixup_mac_addr(void *blob, int nodeoffset, |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 168 | const char *propname, struct udevice *eth_dev, |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 169 | enum mc_fixup_type type) |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 170 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 171 | struct eth_pdata *plat = dev_get_plat(eth_dev); |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 172 | unsigned char *enetaddr = plat->enetaddr; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 173 | int eth_index = dev_seq(eth_dev); |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 174 | int err = 0, len = 0, size, i; |
| 175 | unsigned char env_enetaddr[ARP_HLEN]; |
| 176 | unsigned int enetaddr_32[ARP_HLEN]; |
| 177 | void *val = NULL; |
| 178 | |
| 179 | switch (type) { |
| 180 | case MC_FIXUP_DPL: |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 181 | /* DPL likes its addresses on 32 * ARP_HLEN bits */ |
| 182 | for (i = 0; i < ARP_HLEN; i++) |
| 183 | enetaddr_32[i] = cpu_to_fdt32(enetaddr[i]); |
| 184 | val = enetaddr_32; |
| 185 | len = sizeof(enetaddr_32); |
| 186 | break; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 187 | case MC_FIXUP_DPC: |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 188 | val = enetaddr; |
| 189 | len = ARP_HLEN; |
| 190 | break; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 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 */ |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 196 | if (!eth_env_get_enetaddr_by_index("eth", eth_index, |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 197 | env_enetaddr)) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 198 | return err; |
| 199 | } else { |
| 200 | size = MC_DT_INCREASE_SIZE + strlen(propname) + len; |
| 201 | /* make room for mac address property */ |
| 202 | err = fdt_increase_size(blob, size); |
| 203 | if (err) { |
| 204 | printf("fdt_increase_size: err=%s\n", |
| 205 | fdt_strerror(err)); |
| 206 | return err; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | err = fdt_setprop(blob, nodeoffset, propname, val, len); |
| 211 | if (err) { |
| 212 | printf("fdt_setprop: err=%s\n", fdt_strerror(err)); |
| 213 | return err; |
| 214 | } |
| 215 | |
| 216 | return err; |
| 217 | } |
| 218 | |
| 219 | #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0) |
| 220 | |
| 221 | const char *dpl_get_connection_endpoint(void *blob, char *endpoint) |
| 222 | { |
| 223 | int connoffset = fdt_path_offset(blob, "/connections"), off; |
| 224 | const char *s1, *s2; |
| 225 | |
| 226 | for (off = fdt_first_subnode(blob, connoffset); |
| 227 | off >= 0; |
| 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); |
| 231 | |
| 232 | if (!s1 || !s2) |
| 233 | continue; |
| 234 | |
| 235 | if (strcmp(endpoint, s1) == 0) |
| 236 | return s2; |
| 237 | |
| 238 | if (strcmp(endpoint, s2) == 0) |
| 239 | return s1; |
| 240 | } |
| 241 | |
| 242 | return NULL; |
| 243 | } |
| 244 | |
| 245 | static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id, |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 246 | struct udevice *eth_dev) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 247 | { |
| 248 | int objoff = fdt_path_offset(blob, "/objects"); |
| 249 | int dpmacoff = -1, dpnioff = -1; |
| 250 | const char *endpoint; |
| 251 | char mac_name[10]; |
| 252 | int err; |
| 253 | |
| 254 | sprintf(mac_name, "dpmac@%d", dpmac_id); |
| 255 | dpmacoff = fdt_subnode_offset(blob, objoff, mac_name); |
| 256 | if (dpmacoff < 0) |
| 257 | /* dpmac not defined in DPL, so skip it. */ |
| 258 | return 0; |
| 259 | |
| 260 | err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev, |
| 261 | MC_FIXUP_DPL); |
| 262 | if (err) { |
| 263 | printf("Error fixing up dpmac mac_addr in DPL\n"); |
| 264 | return err; |
| 265 | } |
| 266 | |
| 267 | /* now we need to figure out if there is any |
| 268 | * DPNI connected to this MAC, so we walk the |
| 269 | * connection list |
| 270 | */ |
| 271 | endpoint = dpl_get_connection_endpoint(blob, mac_name); |
| 272 | if (!is_dpni(endpoint)) |
| 273 | return 0; |
| 274 | |
| 275 | /* let's see if we can fixup the DPNI as well */ |
| 276 | dpnioff = fdt_subnode_offset(blob, objoff, endpoint); |
| 277 | if (dpnioff < 0) |
| 278 | /* DPNI not defined in DPL in the objects area */ |
| 279 | return 0; |
| 280 | |
| 281 | return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev, |
| 282 | MC_FIXUP_DPL); |
| 283 | } |
| 284 | |
Meenakshi Aggarwal | d67ae48 | 2019-05-23 15:13:43 +0530 | [diff] [blame] | 285 | void fdt_fixup_mc_ddr(u64 *base, u64 *size) |
| 286 | { |
| 287 | u64 mc_size = mc_get_dram_block_size(); |
| 288 | |
| 289 | if (mc_size < MC_DRAM_BLOCK_DEFAULT_SIZE) { |
| 290 | *base = mc_get_dram_addr() + mc_size; |
| 291 | *size = MC_DRAM_BLOCK_DEFAULT_SIZE - mc_size; |
| 292 | } |
| 293 | } |
| 294 | |
Nipun Gupta | d691264 | 2018-08-20 16:01:14 +0530 | [diff] [blame] | 295 | void fdt_fsl_mc_fixup_iommu_map_entry(void *blob) |
| 296 | { |
| 297 | u32 *prop; |
Laurentiu Tudor | 9e35259 | 2020-05-04 14:47:11 +0300 | [diff] [blame] | 298 | u32 iommu_map[4], phandle; |
Nipun Gupta | d691264 | 2018-08-20 16:01:14 +0530 | [diff] [blame] | 299 | int offset; |
| 300 | int lenp; |
| 301 | |
| 302 | /* find fsl-mc node */ |
| 303 | offset = fdt_path_offset(blob, "/soc/fsl-mc"); |
| 304 | if (offset < 0) |
| 305 | offset = fdt_path_offset(blob, "/fsl-mc"); |
| 306 | if (offset < 0) { |
| 307 | printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n", |
| 308 | __func__, offset); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp); |
| 313 | if (!prop) { |
| 314 | debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n", |
| 315 | __func__); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START); |
| 320 | iommu_map[1] = *++prop; |
| 321 | iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START); |
| 322 | iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END - |
| 323 | FSL_DPAA2_STREAM_ID_START + 1); |
| 324 | |
| 325 | fdt_setprop_inplace(blob, offset, "iommu-map", |
| 326 | iommu_map, sizeof(iommu_map)); |
Laurentiu Tudor | 9e35259 | 2020-05-04 14:47:11 +0300 | [diff] [blame] | 327 | |
| 328 | /* get phandle to MSI controller */ |
| 329 | prop = (u32 *)fdt_getprop(blob, offset, "msi-parent", 0); |
| 330 | if (!prop) { |
| 331 | debug("\n%s: ERROR: missing msi-parent\n", __func__); |
| 332 | return; |
| 333 | } |
| 334 | phandle = fdt32_to_cpu(*prop); |
| 335 | |
| 336 | /* also set msi-map property */ |
| 337 | fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START); |
| 338 | fdt_appendprop_u32(blob, offset, "msi-map", phandle); |
| 339 | fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START); |
| 340 | fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_END - |
| 341 | FSL_DPAA2_STREAM_ID_START + 1); |
Nipun Gupta | d691264 | 2018-08-20 16:01:14 +0530 | [diff] [blame] | 342 | } |
| 343 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 344 | static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id, |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 345 | struct udevice *eth_dev) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 346 | { |
| 347 | int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff; |
| 348 | int err = 0; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 349 | char mac_name[10]; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 350 | const char link_type_mode[] = "MAC_LINK_TYPE_FIXED"; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 351 | |
| 352 | sprintf(mac_name, "mac@%d", dpmac_id); |
| 353 | |
| 354 | /* node not found - create it */ |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 355 | noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name); |
| 356 | if (noff < 0) { |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 357 | err = fdt_increase_size(blob, 200); |
| 358 | if (err) { |
| 359 | printf("fdt_increase_size: err=%s\n", |
| 360 | fdt_strerror(err)); |
| 361 | return err; |
| 362 | } |
| 363 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 364 | noff = fdt_add_subnode(blob, nodeoffset, mac_name); |
| 365 | if (noff < 0) { |
| 366 | printf("fdt_add_subnode: err=%s\n", |
| 367 | fdt_strerror(err)); |
| 368 | return err; |
| 369 | } |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 370 | |
| 371 | /* add default property of fixed link */ |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 372 | err = fdt_appendprop_string(blob, noff, |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 373 | "link_type", link_type_mode); |
| 374 | if (err) { |
| 375 | printf("fdt_appendprop_string: err=%s\n", |
| 376 | fdt_strerror(err)); |
| 377 | return err; |
| 378 | } |
| 379 | } |
| 380 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 381 | return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev, |
| 382 | MC_FIXUP_DPC); |
| 383 | } |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 384 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 385 | static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type) |
| 386 | { |
| 387 | int i, err = 0, ret = 0; |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 388 | #define ETH_NAME_LEN 20 |
| 389 | struct udevice *eth_dev; |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 390 | char ethname[ETH_NAME_LEN]; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 391 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 392 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { |
| 393 | /* port not enabled */ |
Pankaj Bansal | 7987ab7 | 2018-10-10 14:08:33 +0530 | [diff] [blame] | 394 | if (wriop_is_enabled_dpmac(i) != 1) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 395 | continue; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 396 | |
Pankaj Bansal | 8a92170 | 2018-08-02 16:31:28 +0530 | [diff] [blame] | 397 | snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i, |
| 398 | phy_interface_strings[wriop_get_enet_if(i)]); |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 399 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 400 | eth_dev = eth_get_dev_by_name(ethname); |
| 401 | if (eth_dev == NULL) |
| 402 | continue; |
| 403 | |
| 404 | switch (type) { |
| 405 | case MC_FIXUP_DPL: |
| 406 | err = mc_fixup_dpl_mac_addr(blob, i, eth_dev); |
| 407 | break; |
| 408 | case MC_FIXUP_DPC: |
| 409 | err = mc_fixup_dpc_mac_addr(blob, i, eth_dev); |
| 410 | break; |
| 411 | default: |
| 412 | break; |
| 413 | } |
| 414 | |
| 415 | if (err) |
| 416 | printf("fsl-mc: ERROR fixing mac address for %s\n", |
| 417 | ethname); |
| 418 | ret |= err; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 421 | return ret; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 424 | static int mc_fixup_dpc(u64 dpc_addr) |
| 425 | { |
| 426 | void *blob = (void *)dpc_addr; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 427 | int nodeoffset, err = 0; |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 428 | |
| 429 | /* delete any existing ICID pools */ |
| 430 | nodeoffset = fdt_path_offset(blob, "/resources/icid_pools"); |
| 431 | if (fdt_del_node(blob, nodeoffset) < 0) |
| 432 | printf("\nfsl-mc: WARNING: could not delete ICID pool\n"); |
| 433 | |
| 434 | /* add a new pool */ |
| 435 | nodeoffset = fdt_path_offset(blob, "/resources"); |
| 436 | if (nodeoffset < 0) { |
| 437 | printf("\nfsl-mc: ERROR: DPC is missing /resources\n"); |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools"); |
| 441 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0"); |
| 442 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 443 | "base_icid", FSL_DPAA2_STREAM_ID_START, 1); |
| 444 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 445 | "num", |
| 446 | FSL_DPAA2_STREAM_ID_END - |
| 447 | FSL_DPAA2_STREAM_ID_START + 1, 1); |
| 448 | |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 449 | /* fixup MAC addresses for dpmac ports */ |
| 450 | nodeoffset = fdt_path_offset(blob, "/board_info/ports"); |
Razvan Ionut Cirjan | a3bbc3b | 2020-04-28 16:09:59 +0300 | [diff] [blame] | 451 | if (nodeoffset < 0) { |
| 452 | err = fdt_increase_size(blob, 512); |
| 453 | if (err) { |
| 454 | printf("fdt_increase_size: err=%s\n", |
| 455 | fdt_strerror(err)); |
| 456 | goto out; |
| 457 | } |
| 458 | nodeoffset = fdt_path_offset(blob, "/board_info"); |
| 459 | if (nodeoffset < 0) |
| 460 | nodeoffset = fdt_add_subnode(blob, 0, "board_info"); |
| 461 | |
| 462 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "ports"); |
| 463 | } |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 464 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 465 | err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC); |
Ioana Ciocoi Radulescu | d7697f4 | 2019-02-26 15:50:07 +0000 | [diff] [blame] | 466 | |
| 467 | out: |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 468 | flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob)); |
| 469 | |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 470 | return err; |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 471 | } |
| 472 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 473 | static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 474 | { |
| 475 | u64 mc_dpc_offset; |
| 476 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 477 | int error; |
| 478 | void *dpc_fdt_hdr; |
| 479 | int dpc_size; |
| 480 | #endif |
| 481 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 482 | #ifdef CFG_SYS_LS_MC_DRAM_DPC_OFFSET |
| 483 | BUILD_BUG_ON((CFG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 || |
| 484 | CFG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 485 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 486 | mc_dpc_offset = CFG_SYS_LS_MC_DRAM_DPC_OFFSET; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 487 | #else |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 488 | #error "CFG_SYS_LS_MC_DRAM_DPC_OFFSET not defined" |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 489 | #endif |
| 490 | |
| 491 | /* |
| 492 | * Load the MC DPC blob in the MC private DRAM block: |
| 493 | */ |
| 494 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 495 | printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset); |
| 496 | #else |
| 497 | /* |
| 498 | * Get address and size of the DPC blob stored in flash: |
| 499 | */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 500 | dpc_fdt_hdr = (void *)mc_dpc_addr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 501 | |
| 502 | error = fdt_check_header(dpc_fdt_hdr); |
| 503 | if (error != 0) { |
| 504 | /* |
| 505 | * Don't return with error here, since the MC firmware can |
| 506 | * still boot without a DPC |
| 507 | */ |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 508 | printf("\nfsl-mc: WARNING: No DPC image found"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | dpc_size = fdt_totalsize(dpc_fdt_hdr); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 513 | if (dpc_size > CFG_SYS_LS_MC_DPC_MAX_LENGTH) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 514 | printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n", |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 515 | dpc_size); |
| 516 | return -EINVAL; |
| 517 | } |
| 518 | |
| 519 | mc_copy_image("MC DPC blob", |
| 520 | (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset); |
| 521 | #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */ |
| 522 | |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 523 | if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset)) |
| 524 | return -EINVAL; |
| 525 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 526 | dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset)); |
| 527 | return 0; |
| 528 | } |
| 529 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 530 | |
| 531 | static int mc_fixup_dpl(u64 dpl_addr) |
| 532 | { |
| 533 | void *blob = (void *)dpl_addr; |
| 534 | u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0); |
| 535 | int err = 0; |
| 536 | |
| 537 | /* The DPL fixup for mac addresses is only relevant |
| 538 | * for old-style DPLs |
| 539 | */ |
| 540 | if (ver >= 10) |
| 541 | return 0; |
| 542 | |
| 543 | err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL); |
| 544 | flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob)); |
| 545 | |
| 546 | return err; |
| 547 | } |
| 548 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 549 | static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 550 | { |
| 551 | u64 mc_dpl_offset; |
| 552 | #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 553 | int error; |
| 554 | void *dpl_fdt_hdr; |
| 555 | int dpl_size; |
| 556 | #endif |
| 557 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 558 | #ifdef CFG_SYS_LS_MC_DRAM_DPL_OFFSET |
| 559 | BUILD_BUG_ON((CFG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 || |
| 560 | CFG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 561 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 562 | mc_dpl_offset = CFG_SYS_LS_MC_DRAM_DPL_OFFSET; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 563 | #else |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 564 | #error "CFG_SYS_LS_MC_DRAM_DPL_OFFSET not defined" |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 565 | #endif |
| 566 | |
| 567 | /* |
| 568 | * Load the MC DPL blob in the MC private DRAM block: |
| 569 | */ |
| 570 | #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 571 | printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset); |
| 572 | #else |
| 573 | /* |
| 574 | * Get address and size of the DPL blob stored in flash: |
| 575 | */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 576 | dpl_fdt_hdr = (void *)mc_dpl_addr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 577 | |
| 578 | error = fdt_check_header(dpl_fdt_hdr); |
| 579 | if (error != 0) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 580 | printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 581 | return error; |
| 582 | } |
| 583 | |
| 584 | dpl_size = fdt_totalsize(dpl_fdt_hdr); |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 585 | if (dpl_size > CFG_SYS_LS_MC_DPL_MAX_LENGTH) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 586 | printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n", |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 587 | dpl_size); |
| 588 | return -EINVAL; |
| 589 | } |
| 590 | |
| 591 | mc_copy_image("MC DPL blob", |
| 592 | (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset); |
| 593 | #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */ |
| 594 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 595 | if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset)) |
| 596 | return -EINVAL; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 597 | dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset)); |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Return the MC boot timeout value in milliseconds |
| 603 | */ |
| 604 | static unsigned long get_mc_boot_timeout_ms(void) |
| 605 | { |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 606 | unsigned long timeout_ms = CFG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 607 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 608 | char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 609 | |
| 610 | if (timeout_ms_env_var) { |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 611 | timeout_ms = dectoul(timeout_ms_env_var, NULL); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 612 | if (timeout_ms == 0) { |
| 613 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 614 | MC_BOOT_TIMEOUT_ENV_VAR |
| 615 | "\' environment variable: %lu\n", |
| 616 | timeout_ms); |
| 617 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 618 | timeout_ms = CFG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
| 622 | return timeout_ms; |
| 623 | } |
| 624 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 625 | #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 626 | |
| 627 | __weak bool soc_has_aiop(void) |
| 628 | { |
| 629 | return false; |
| 630 | } |
| 631 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 632 | static int load_mc_aiop_img(u64 aiop_fw_addr) |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 633 | { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 634 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 635 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 636 | void *aiop_img; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 637 | #endif |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 638 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 639 | /* Check if AIOP is available */ |
| 640 | if (!soc_has_aiop()) |
| 641 | return -ENODEV; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 642 | /* |
| 643 | * Load the MC AIOP image in the MC private DRAM block: |
| 644 | */ |
| 645 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 646 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 647 | printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr + |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 648 | CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 649 | #else |
| 650 | aiop_img = (void *)aiop_fw_addr; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 651 | mc_copy_image("MC AIOP image", |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 652 | (u64)aiop_img, CFG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH, |
| 653 | mc_ram_addr + CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 654 | #endif |
| 655 | mc_aiop_applied = 0; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | #endif |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 660 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 661 | static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr) |
| 662 | { |
| 663 | u32 reg_gsr; |
| 664 | u32 mc_fw_boot_status; |
| 665 | unsigned long timeout_ms = get_mc_boot_timeout_ms(); |
| 666 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 667 | |
| 668 | dmb(); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 669 | assert(timeout_ms > 0); |
| 670 | for (;;) { |
| 671 | udelay(1000); /* throttle polling */ |
| 672 | reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr); |
| 673 | mc_fw_boot_status = (reg_gsr & GSR_FS_MASK); |
| 674 | if (mc_fw_boot_status & 0x1) |
| 675 | break; |
| 676 | |
| 677 | timeout_ms--; |
| 678 | if (timeout_ms == 0) |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | if (timeout_ms == 0) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 683 | printf("ERROR: timeout\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 684 | |
| 685 | /* TODO: Get an error status from an MC CCSR register */ |
| 686 | return -ETIMEDOUT; |
| 687 | } |
| 688 | |
| 689 | if (mc_fw_boot_status != 0x1) { |
| 690 | /* |
| 691 | * TODO: Identify critical errors from the GSR register's FS |
| 692 | * field and for those errors, set error to -ENODEV or other |
| 693 | * appropriate errno, so that the status property is set to |
| 694 | * failure in the fsl,dprc device tree node. |
| 695 | */ |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 696 | printf("WARNING: Firmware returned an error (GSR: %#x)\n", |
| 697 | reg_gsr); |
| 698 | } else { |
| 699 | printf("SUCCESS\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 700 | } |
| 701 | |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 702 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 703 | *final_reg_gsr = reg_gsr; |
| 704 | return 0; |
| 705 | } |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 706 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 707 | int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 708 | { |
| 709 | int error = 0; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 710 | int portal_id = 0; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 711 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 712 | u64 mc_ram_addr = mc_get_dram_addr(); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 713 | u32 reg_gsr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 714 | u32 reg_mcfbalr; |
| 715 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 716 | const void *raw_image_addr; |
| 717 | size_t raw_image_size = 0; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 718 | #endif |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 719 | u8 mc_ram_num_256mb_blocks; |
| 720 | size_t mc_ram_size = mc_get_dram_block_size(); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 721 | |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 722 | mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT; |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 723 | |
| 724 | if (mc_ram_num_256mb_blocks >= 0xff) { |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 725 | error = -EINVAL; |
| 726 | printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n", |
| 727 | mc_ram_size); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 728 | goto out; |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 729 | } |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 730 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 731 | /* |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 732 | * To support 128 MB DDR Size for MC |
| 733 | */ |
| 734 | if (mc_ram_num_256mb_blocks == 0) |
| 735 | mc_ram_num_256mb_blocks = 0xFF; |
| 736 | |
| 737 | /* |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 738 | * Management Complex cores should be held at reset out of POR. |
Bin Meng | 7557405 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 739 | * U-Boot should be the first software to touch MC. To be safe, |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 740 | * we reset all cores again by setting GCR1 to 0. It doesn't do |
| 741 | * anything if they are held at reset. After we setup the firmware |
| 742 | * we kick off MC by deasserting the reset bit for core 0, and |
| 743 | * deasserting the reset bits for Command Portal Managers. |
| 744 | * The stop bits are not touched here. They are used to stop the |
| 745 | * cores when they are active. Setting stop bits doesn't stop the |
| 746 | * cores from fetching instructions when they are released from |
| 747 | * reset. |
| 748 | */ |
| 749 | out_le32(&mc_ccsr_regs->reg_gcr1, 0); |
| 750 | dmb(); |
| 751 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 752 | #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR |
| 753 | printf("MC firmware is preloaded to %#llx\n", mc_ram_addr); |
| 754 | #else |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 755 | error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr, |
| 756 | &raw_image_size); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 757 | if (error != 0) |
| 758 | goto out; |
| 759 | /* |
| 760 | * Load the MC FW at the beginning of the MC private DRAM block: |
| 761 | */ |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 762 | mc_copy_image("MC Firmware", |
| 763 | (u64)raw_image_addr, raw_image_size, mc_ram_addr); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 764 | #endif |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 765 | dump_ram_words("firmware", (void *)mc_ram_addr); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 766 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 767 | error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 768 | if (error != 0) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 769 | goto out; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 770 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 771 | debug("mc_ccsr_regs %p\n", mc_ccsr_regs); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 772 | dump_mc_ccsr_regs(mc_ccsr_regs); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 773 | |
| 774 | /* |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 775 | * Tell MC what is the address range of the DRAM block assigned to it: |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 776 | */ |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 777 | if (mc_ram_num_256mb_blocks < 0xFF) { |
| 778 | reg_mcfbalr = (u32)mc_ram_addr | |
| 779 | (mc_ram_num_256mb_blocks - 1); |
| 780 | } else { |
| 781 | reg_mcfbalr = (u32)mc_ram_addr | |
| 782 | (mc_ram_num_256mb_blocks); |
| 783 | } |
| 784 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 785 | out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr); |
| 786 | out_le32(&mc_ccsr_regs->reg_mcfbahr, |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 787 | (u32)(mc_ram_addr >> 32)); |
Stuart Yoder | d197035 | 2015-07-02 11:29:02 +0530 | [diff] [blame] | 788 | out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 789 | |
| 790 | /* |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 791 | * Tell the MC that we want delayed DPL deployment. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 792 | */ |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 793 | out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 794 | |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 795 | printf("\nfsl-mc: Booting Management Complex ... "); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 796 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 797 | /* |
| 798 | * Deassert reset and release MC core 0 to run |
| 799 | */ |
| 800 | out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 801 | error = wait_for_mc(true, ®_gsr); |
| 802 | if (error != 0) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 803 | goto out; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 804 | |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 805 | /* |
| 806 | * TODO: need to obtain the portal_id for the root container from the |
| 807 | * DPL |
| 808 | */ |
| 809 | portal_id = 0; |
| 810 | |
| 811 | /* |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 812 | * Initialize the global default MC portal |
| 813 | * And check that the MC firmware is responding portal commands: |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 814 | */ |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 815 | root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 816 | if (!root_mc_io) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 817 | printf(" No memory: calloc() failed\n"); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 818 | return -ENOMEM; |
| 819 | } |
| 820 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 821 | root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 822 | debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n", |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 823 | portal_id, root_mc_io->mmio_regs); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 824 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 825 | error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 826 | if (error != 0) { |
| 827 | printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n", |
| 828 | error); |
| 829 | goto out; |
| 830 | } |
| 831 | |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 832 | printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n", |
| 833 | mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision, |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 834 | reg_gsr & GSR_FS_MASK); |
| 835 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 836 | out: |
| 837 | if (error != 0) |
| 838 | mc_boot_status = error; |
| 839 | else |
| 840 | mc_boot_status = 0; |
| 841 | |
| 842 | return error; |
| 843 | } |
| 844 | |
| 845 | int mc_apply_dpl(u64 mc_dpl_addr) |
| 846 | { |
| 847 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 848 | int error = 0; |
| 849 | u32 reg_gsr; |
| 850 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 851 | size_t mc_ram_size = mc_get_dram_block_size(); |
| 852 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 853 | if (!mc_dpl_addr) |
| 854 | return -1; |
| 855 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 856 | error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr); |
| 857 | if (error != 0) |
| 858 | return error; |
| 859 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 860 | /* |
| 861 | * Tell the MC to deploy the DPL: |
| 862 | */ |
| 863 | out_le32(&mc_ccsr_regs->reg_gsr, 0x0); |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 864 | printf("fsl-mc: Deploying data path layout ... "); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 865 | error = wait_for_mc(false, ®_gsr); |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 866 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 867 | if (!error) |
| 868 | mc_dpl_applied = 0; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 869 | |
| 870 | return error; |
| 871 | } |
| 872 | |
| 873 | int get_mc_boot_status(void) |
| 874 | { |
| 875 | return mc_boot_status; |
| 876 | } |
| 877 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 878 | #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 879 | int get_aiop_apply_status(void) |
| 880 | { |
| 881 | return mc_aiop_applied; |
| 882 | } |
| 883 | #endif |
| 884 | |
| 885 | int get_dpl_apply_status(void) |
| 886 | { |
| 887 | return mc_dpl_applied; |
| 888 | } |
| 889 | |
Mian Yousaf Kaukab | 9712465 | 2018-12-18 14:01:17 +0100 | [diff] [blame] | 890 | int is_lazy_dpl_addr_valid(void) |
| 891 | { |
| 892 | return !!mc_lazy_dpl_addr; |
| 893 | } |
| 894 | |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 895 | /* |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 896 | * Return the MC address of private DRAM block. |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 897 | * As per MC design document, MC initial base address |
| 898 | * should be least significant 512MB address of MC private |
| 899 | * memory, i.e. address should point to end address masked |
| 900 | * with 512MB offset in private DRAM block. |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 901 | */ |
| 902 | u64 mc_get_dram_addr(void) |
| 903 | { |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 904 | size_t mc_ram_size = mc_get_dram_block_size(); |
| 905 | |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 906 | if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) { |
| 907 | mc_memset_resv_ram = 1; |
| 908 | memset((void *)gd->arch.resv_ram, 0, mc_ram_size); |
| 909 | } |
| 910 | |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 911 | return (gd->arch.resv_ram + mc_ram_size - 1) & |
| 912 | MC_RAM_BASE_ADDR_ALIGNMENT_MASK; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | /** |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 916 | * Return the actual size of the MC private DRAM block. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 917 | */ |
| 918 | unsigned long mc_get_dram_block_size(void) |
| 919 | { |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 920 | unsigned long dram_block_size = CFG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 921 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 922 | char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 923 | |
| 924 | if (dram_block_size_env_var) { |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 925 | dram_block_size = hextoul(dram_block_size_env_var, NULL); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 926 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 927 | if (dram_block_size < CFG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) { |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 928 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 929 | MC_MEM_SIZE_ENV_VAR |
| 930 | "\' environment variable: %lu\n", |
| 931 | dram_block_size); |
| 932 | |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 933 | dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 934 | } |
| 935 | } |
| 936 | |
| 937 | return dram_block_size; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 938 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 939 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 940 | int fsl_mc_ldpaa_init(struct bd_info *bis) |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 941 | { |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 942 | int i; |
| 943 | |
| 944 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) |
Pankaj Bansal | 7987ab7 | 2018-10-10 14:08:33 +0530 | [diff] [blame] | 945 | if (wriop_is_enabled_dpmac(i) == 1) |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 946 | ldpaa_eth_init(i, wriop_get_enet_if(i)); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 947 | return 0; |
| 948 | } |
| 949 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 950 | static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle) |
| 951 | { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 952 | int error; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 953 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 954 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 955 | error = dprc_get_api_version(mc_io, 0, |
| 956 | &major_ver, |
| 957 | &minor_ver); |
| 958 | if (error < 0) { |
| 959 | printf("dprc_get_api_version() failed: %d\n", error); |
| 960 | return error; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 961 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 962 | |
| 963 | if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR && |
| 964 | minor_ver < DPRC_VER_MINOR)) { |
| 965 | printf("DPRC version mismatch found %u.%u,", |
| 966 | major_ver, minor_ver); |
| 967 | printf("supported version is %u.%u\n", |
| 968 | DPRC_VER_MAJOR, DPRC_VER_MINOR); |
| 969 | } |
| 970 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 971 | return error; |
| 972 | } |
| 973 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 974 | static int dpio_init(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 975 | { |
| 976 | struct qbman_swp_desc p_des; |
| 977 | struct dpio_attr attr; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 978 | struct dpio_cfg dpio_cfg; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 979 | int err = 0; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 980 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 981 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 982 | dflt_dpio = (struct fsl_dpio_obj *)calloc( |
| 983 | sizeof(struct fsl_dpio_obj), 1); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 984 | if (!dflt_dpio) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 985 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 986 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 987 | goto err_calloc; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 988 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 989 | dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL; |
| 990 | dpio_cfg.num_priorities = 8; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 991 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 992 | err = dpio_create(dflt_mc_io, |
| 993 | dflt_dprc_handle, |
| 994 | MC_CMD_NO_FLAGS, |
| 995 | &dpio_cfg, |
| 996 | &dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 997 | if (err < 0) { |
| 998 | printf("dpio_create() failed: %d\n", err); |
| 999 | err = -ENODEV; |
| 1000 | goto err_create; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1003 | err = dpio_get_api_version(dflt_mc_io, 0, |
| 1004 | &major_ver, |
| 1005 | &minor_ver); |
| 1006 | if (err < 0) { |
| 1007 | printf("dpio_get_api_version() failed: %d\n", err); |
| 1008 | goto err_get_api_ver; |
| 1009 | } |
| 1010 | |
| 1011 | if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR && |
| 1012 | minor_ver < DPIO_VER_MINOR)) { |
| 1013 | printf("DPRC version mismatch found %u.%u,", |
| 1014 | major_ver, |
| 1015 | minor_ver); |
| 1016 | } |
| 1017 | |
| 1018 | err = dpio_open(dflt_mc_io, |
| 1019 | MC_CMD_NO_FLAGS, |
| 1020 | dflt_dpio->dpio_id, |
| 1021 | &dflt_dpio->dpio_handle); |
| 1022 | if (err) { |
| 1023 | printf("dpio_open() failed\n"); |
| 1024 | goto err_open; |
| 1025 | } |
| 1026 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1027 | memset(&attr, 0, sizeof(struct dpio_attr)); |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 1028 | err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1029 | dflt_dpio->dpio_handle, &attr); |
| 1030 | if (err < 0) { |
| 1031 | printf("dpio_get_attributes() failed: %d\n", err); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1032 | goto err_get_attr; |
| 1033 | } |
| 1034 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1035 | if (dflt_dpio->dpio_id != attr.id) { |
| 1036 | printf("dnpi object id and attribute id are not same\n"); |
| 1037 | goto err_attr_not_same; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1038 | } |
| 1039 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1040 | #ifdef DEBUG |
Ioana Ciornei | b1ba07a | 2023-01-05 17:03:17 +0200 | [diff] [blame^] | 1041 | printf("Init: DPIO.%d\n", dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1042 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1043 | err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1044 | if (err < 0) { |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1045 | printf("dpio_enable() failed %d\n", err); |
| 1046 | goto err_get_enable; |
| 1047 | } |
Prabhakar Kushwaha | fd5d127 | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 1048 | debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n", |
| 1049 | attr.qbman_portal_ce_offset, |
| 1050 | attr.qbman_portal_ci_offset, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1051 | attr.qbman_portal_id, |
| 1052 | attr.num_priorities); |
| 1053 | |
Prabhakar Kushwaha | fd5d127 | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 1054 | p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 1055 | + attr.qbman_portal_ce_offset); |
| 1056 | p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 1057 | + attr.qbman_portal_ci_offset); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1058 | |
| 1059 | dflt_dpio->sw_portal = qbman_swp_init(&p_des); |
| 1060 | if (dflt_dpio->sw_portal == NULL) { |
| 1061 | printf("qbman_swp_init() failed\n"); |
| 1062 | goto err_get_swp_init; |
| 1063 | } |
| 1064 | return 0; |
| 1065 | |
| 1066 | err_get_swp_init: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1067 | dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1068 | err_get_enable: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1069 | err_get_attr: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1070 | err_attr_not_same: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1071 | dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1072 | err_open: |
| 1073 | err_get_api_ver: |
| 1074 | dpio_destroy(dflt_mc_io, |
| 1075 | dflt_dprc_handle, |
| 1076 | MC_CMD_NO_FLAGS, |
| 1077 | dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1078 | err_create: |
Prabhakar Kushwaha | c6018bd | 2016-03-18 16:15:29 +0530 | [diff] [blame] | 1079 | free(dflt_dpio); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1080 | err_calloc: |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1081 | return err; |
| 1082 | } |
| 1083 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1084 | static int dpio_exit(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1085 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1086 | int err; |
| 1087 | |
| 1088 | err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1089 | if (err < 0) { |
| 1090 | printf("dpio_disable() failed: %d\n", err); |
| 1091 | goto err; |
| 1092 | } |
| 1093 | |
Cosmin-Florin Aluchenesei | 971dfd3 | 2021-07-21 19:13:33 +0300 | [diff] [blame] | 1094 | err = dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1095 | if (err < 0) { |
| 1096 | printf("dpio_close() failed: %d\n", err); |
| 1097 | goto err; |
| 1098 | } |
| 1099 | |
| 1100 | err = dpio_destroy(dflt_mc_io, |
| 1101 | dflt_dprc_handle, |
| 1102 | MC_CMD_NO_FLAGS, |
| 1103 | dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1104 | if (err < 0) { |
| 1105 | printf("dpio_destroy() failed: %d\n", err); |
| 1106 | goto err; |
| 1107 | } |
| 1108 | |
| 1109 | #ifdef DEBUG |
Ioana Ciornei | b1ba07a | 2023-01-05 17:03:17 +0200 | [diff] [blame^] | 1110 | printf("Exit: DPIO.%d\n", dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1111 | #endif |
| 1112 | |
| 1113 | if (dflt_dpio) |
| 1114 | free(dflt_dpio); |
| 1115 | |
| 1116 | return 0; |
| 1117 | err: |
| 1118 | return err; |
| 1119 | } |
| 1120 | |
| 1121 | static int dprc_init(void) |
| 1122 | { |
| 1123 | int err, child_portal_id, container_id; |
| 1124 | struct dprc_cfg cfg; |
| 1125 | uint64_t mc_portal_offset; |
| 1126 | |
| 1127 | /* Open root container */ |
| 1128 | err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id); |
| 1129 | if (err < 0) { |
| 1130 | printf("dprc_get_container_id(): Root failed: %d\n", err); |
| 1131 | goto err_root_container_id; |
| 1132 | } |
| 1133 | |
| 1134 | #ifdef DEBUG |
| 1135 | printf("Root container id = %d\n", container_id); |
| 1136 | #endif |
| 1137 | err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id, |
| 1138 | &root_dprc_handle); |
| 1139 | if (err < 0) { |
| 1140 | printf("dprc_open(): Root Container failed: %d\n", err); |
| 1141 | goto err_root_open; |
| 1142 | } |
| 1143 | |
| 1144 | if (!root_dprc_handle) { |
| 1145 | printf("dprc_open(): Root Container Handle is not valid\n"); |
| 1146 | goto err_root_open; |
| 1147 | } |
| 1148 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1149 | err = dprc_version_check(root_mc_io, root_dprc_handle); |
| 1150 | if (err < 0) { |
| 1151 | printf("dprc_version_check() failed: %d\n", err); |
| 1152 | goto err_root_open; |
| 1153 | } |
| 1154 | |
Prabhakar Kushwaha | 901a88e | 2016-01-20 12:04:19 +0530 | [diff] [blame] | 1155 | memset(&cfg, 0, sizeof(struct dprc_cfg)); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1156 | cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED | |
| 1157 | DPRC_CFG_OPT_OBJ_CREATE_ALLOWED | |
| 1158 | DPRC_CFG_OPT_ALLOC_ALLOWED; |
| 1159 | cfg.icid = DPRC_GET_ICID_FROM_POOL; |
Prabhakar Kushwaha | 7fd59d9 | 2015-12-24 15:33:49 +0530 | [diff] [blame] | 1160 | cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1161 | err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1162 | root_dprc_handle, |
| 1163 | &cfg, |
| 1164 | &child_dprc_id, |
| 1165 | &mc_portal_offset); |
| 1166 | if (err < 0) { |
| 1167 | printf("dprc_create_container() failed: %d\n", err); |
| 1168 | goto err_create; |
| 1169 | } |
| 1170 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1171 | dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1172 | if (!dflt_mc_io) { |
| 1173 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1174 | printf(" No memory: calloc() failed\n"); |
| 1175 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset); |
| 1179 | dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1180 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1181 | #ifdef DEBUG |
| 1182 | printf("MC portal of child DPRC container: %d, physical addr %p)\n", |
| 1183 | child_dprc_id, dflt_mc_io->mmio_regs); |
| 1184 | #endif |
| 1185 | |
| 1186 | err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id, |
| 1187 | &dflt_dprc_handle); |
| 1188 | if (err < 0) { |
| 1189 | printf("dprc_open(): Child container failed: %d\n", err); |
| 1190 | goto err_child_open; |
| 1191 | } |
| 1192 | |
| 1193 | if (!dflt_dprc_handle) { |
| 1194 | printf("dprc_open(): Child container Handle is not valid\n"); |
| 1195 | goto err_child_open; |
| 1196 | } |
| 1197 | |
| 1198 | return 0; |
| 1199 | err_child_open: |
| 1200 | free(dflt_mc_io); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1201 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1202 | dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1203 | root_dprc_handle, child_dprc_id); |
| 1204 | err_create: |
| 1205 | dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 1206 | err_root_open: |
| 1207 | err_root_container_id: |
| 1208 | return err; |
| 1209 | } |
| 1210 | |
| 1211 | static int dprc_exit(void) |
| 1212 | { |
| 1213 | int err; |
| 1214 | |
| 1215 | err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle); |
| 1216 | if (err < 0) { |
| 1217 | printf("dprc_close(): Child failed: %d\n", err); |
| 1218 | goto err; |
| 1219 | } |
| 1220 | |
| 1221 | err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1222 | root_dprc_handle, child_dprc_id); |
| 1223 | if (err < 0) { |
| 1224 | printf("dprc_destroy_container() failed: %d\n", err); |
| 1225 | goto err; |
| 1226 | } |
| 1227 | |
| 1228 | err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 1229 | if (err < 0) { |
| 1230 | printf("dprc_close(): Root failed: %d\n", err); |
| 1231 | goto err; |
| 1232 | } |
| 1233 | |
| 1234 | if (dflt_mc_io) |
| 1235 | free(dflt_mc_io); |
| 1236 | |
| 1237 | if (root_mc_io) |
| 1238 | free(root_mc_io); |
| 1239 | |
| 1240 | return 0; |
| 1241 | |
| 1242 | err: |
| 1243 | return err; |
| 1244 | } |
| 1245 | |
| 1246 | static int dpbp_init(void) |
| 1247 | { |
| 1248 | int err; |
| 1249 | struct dpbp_attr dpbp_attr; |
| 1250 | struct dpbp_cfg dpbp_cfg; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1251 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1252 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1253 | dflt_dpbp = (struct fsl_dpbp_obj *)calloc( |
| 1254 | sizeof(struct fsl_dpbp_obj), 1); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1255 | if (!dflt_dpbp) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1256 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1257 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1258 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | dpbp_cfg.options = 512; |
| 1262 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1263 | err = dpbp_create(dflt_mc_io, |
| 1264 | dflt_dprc_handle, |
| 1265 | MC_CMD_NO_FLAGS, |
| 1266 | &dpbp_cfg, |
| 1267 | &dflt_dpbp->dpbp_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1268 | |
| 1269 | if (err < 0) { |
| 1270 | err = -ENODEV; |
| 1271 | printf("dpbp_create() failed: %d\n", err); |
| 1272 | goto err_create; |
| 1273 | } |
| 1274 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1275 | err = dpbp_get_api_version(dflt_mc_io, 0, |
| 1276 | &major_ver, |
| 1277 | &minor_ver); |
| 1278 | if (err < 0) { |
| 1279 | printf("dpbp_get_api_version() failed: %d\n", err); |
| 1280 | goto err_get_api_ver; |
| 1281 | } |
| 1282 | |
| 1283 | if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR && |
| 1284 | minor_ver < DPBP_VER_MINOR)) { |
| 1285 | printf("DPBP version mismatch found %u.%u,", |
| 1286 | major_ver, minor_ver); |
| 1287 | printf("supported version is %u.%u\n", |
| 1288 | DPBP_VER_MAJOR, DPBP_VER_MINOR); |
| 1289 | } |
| 1290 | |
| 1291 | err = dpbp_open(dflt_mc_io, |
| 1292 | MC_CMD_NO_FLAGS, |
| 1293 | dflt_dpbp->dpbp_id, |
| 1294 | &dflt_dpbp->dpbp_handle); |
| 1295 | if (err) { |
| 1296 | printf("dpbp_open() failed\n"); |
| 1297 | goto err_open; |
| 1298 | } |
| 1299 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1300 | memset(&dpbp_attr, 0, sizeof(struct dpbp_attr)); |
| 1301 | err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 1302 | dflt_dpbp->dpbp_handle, |
| 1303 | &dpbp_attr); |
| 1304 | if (err < 0) { |
| 1305 | printf("dpbp_get_attributes() failed: %d\n", err); |
| 1306 | goto err_get_attr; |
| 1307 | } |
| 1308 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1309 | if (dflt_dpbp->dpbp_id != dpbp_attr.id) { |
| 1310 | printf("dpbp object id and attribute id are not same\n"); |
| 1311 | goto err_attr_not_same; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1312 | } |
| 1313 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1314 | #ifdef DEBUG |
Ioana Ciornei | b1ba07a | 2023-01-05 17:03:17 +0200 | [diff] [blame^] | 1315 | printf("Init: DPBP.%d\n", dflt_dpbp->dpbp_attr.id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1316 | #endif |
| 1317 | |
| 1318 | err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 1319 | if (err < 0) { |
| 1320 | printf("dpbp_close() failed: %d\n", err); |
| 1321 | goto err_close; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1322 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1323 | |
| 1324 | return 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1325 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1326 | err_get_attr: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1327 | err_attr_not_same: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1328 | dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1329 | dpbp_destroy(dflt_mc_io, |
| 1330 | dflt_dprc_handle, |
| 1331 | MC_CMD_NO_FLAGS, |
| 1332 | dflt_dpbp->dpbp_id); |
| 1333 | err_get_api_ver: |
| 1334 | err_close: |
| 1335 | err_open: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1336 | err_create: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1337 | free(dflt_dpbp); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1338 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1339 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1342 | static int dpbp_exit(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1343 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1344 | int err; |
| 1345 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1346 | err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, |
| 1347 | dflt_dpbp->dpbp_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1348 | if (err < 0) { |
| 1349 | printf("dpbp_destroy() failed: %d\n", err); |
| 1350 | goto err; |
| 1351 | } |
| 1352 | |
| 1353 | #ifdef DEBUG |
Ioana Ciornei | b1ba07a | 2023-01-05 17:03:17 +0200 | [diff] [blame^] | 1354 | printf("Exit: DPBP.%d\n", dflt_dpbp->dpbp_attr.id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1355 | #endif |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1356 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1357 | if (dflt_dpbp) |
| 1358 | free(dflt_dpbp); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1359 | return 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1360 | |
| 1361 | err: |
| 1362 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1365 | static int dpni_init(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1366 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1367 | int err; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1368 | uint8_t cfg_buf[256] = {0}; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1369 | struct dpni_cfg dpni_cfg; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1370 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1371 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1372 | dflt_dpni = (struct fsl_dpni_obj *)calloc( |
| 1373 | sizeof(struct fsl_dpni_obj), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1374 | if (!dflt_dpni) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1375 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1376 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1377 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1378 | } |
| 1379 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1380 | memset(&dpni_cfg, 0, sizeof(dpni_cfg)); |
| 1381 | err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]); |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1382 | if (err < 0) { |
| 1383 | err = -ENODEV; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1384 | printf("dpni_prepare_cfg() failed: %d\n", err); |
| 1385 | goto err_prepare_cfg; |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1386 | } |
| 1387 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1388 | err = dpni_create(dflt_mc_io, |
| 1389 | dflt_dprc_handle, |
| 1390 | MC_CMD_NO_FLAGS, |
| 1391 | &dpni_cfg, |
| 1392 | &dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1393 | if (err < 0) { |
| 1394 | err = -ENODEV; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1395 | printf("dpni create() failed: %d\n", err); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1396 | goto err_create; |
| 1397 | } |
| 1398 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1399 | err = dpni_get_api_version(dflt_mc_io, 0, |
| 1400 | &major_ver, |
| 1401 | &minor_ver); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1402 | if (err < 0) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1403 | printf("dpni_get_api_version() failed: %d\n", err); |
| 1404 | goto err_get_version; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1405 | } |
| 1406 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1407 | if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR && |
| 1408 | minor_ver < DPNI_VER_MINOR)) { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1409 | printf("DPNI version mismatch found %u.%u,", |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1410 | major_ver, minor_ver); |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1411 | printf("supported version is %u.%u\n", |
| 1412 | DPNI_VER_MAJOR, DPNI_VER_MINOR); |
| 1413 | } |
| 1414 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1415 | err = dpni_open(dflt_mc_io, |
| 1416 | MC_CMD_NO_FLAGS, |
| 1417 | dflt_dpni->dpni_id, |
| 1418 | &dflt_dpni->dpni_handle); |
| 1419 | if (err) { |
| 1420 | printf("dpni_open() failed\n"); |
| 1421 | goto err_open; |
| 1422 | } |
| 1423 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1424 | #ifdef DEBUG |
Ioana Ciornei | b1ba07a | 2023-01-05 17:03:17 +0200 | [diff] [blame^] | 1425 | printf("Init: DPNI.%d\n", dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1426 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1427 | err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
| 1428 | if (err < 0) { |
| 1429 | printf("dpni_close() failed: %d\n", err); |
| 1430 | goto err_close; |
| 1431 | } |
| 1432 | |
| 1433 | return 0; |
| 1434 | |
| 1435 | err_close: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1436 | dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1437 | err_open: |
| 1438 | err_get_version: |
| 1439 | dpni_destroy(dflt_mc_io, |
| 1440 | dflt_dprc_handle, |
| 1441 | MC_CMD_NO_FLAGS, |
| 1442 | dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1443 | err_create: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1444 | err_prepare_cfg: |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1445 | free(dflt_dpni); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1446 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1447 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1450 | static int dpni_exit(void) |
| 1451 | { |
| 1452 | int err; |
| 1453 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1454 | err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, |
| 1455 | dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1456 | if (err < 0) { |
| 1457 | printf("dpni_destroy() failed: %d\n", err); |
| 1458 | goto err; |
| 1459 | } |
| 1460 | |
| 1461 | #ifdef DEBUG |
Ioana Ciornei | b1ba07a | 2023-01-05 17:03:17 +0200 | [diff] [blame^] | 1462 | printf("Exit: DPNI.%d\n", dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1463 | #endif |
| 1464 | |
| 1465 | if (dflt_dpni) |
| 1466 | free(dflt_dpni); |
| 1467 | return 0; |
| 1468 | |
| 1469 | err: |
| 1470 | return err; |
| 1471 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1472 | |
| 1473 | static bool is_dpsparser_supported(void) |
| 1474 | { |
| 1475 | /* dpsparser support was first introduced in MC version: 10.12.0 */ |
| 1476 | if (mc_ver_info.major < 10) |
| 1477 | return false; |
| 1478 | if (mc_ver_info.major == 10) |
| 1479 | return (mc_ver_info.minor >= 12); |
| 1480 | return true; |
| 1481 | } |
| 1482 | |
| 1483 | static int dpsparser_version_check(struct fsl_mc_io *mc_io) |
| 1484 | { |
| 1485 | int error; |
| 1486 | u16 major_ver, minor_ver; |
| 1487 | |
| 1488 | if (!is_dpsparser_supported()) |
| 1489 | return 0; |
| 1490 | |
| 1491 | error = dpsparser_get_api_version(mc_io, 0, |
| 1492 | &major_ver, |
| 1493 | &minor_ver); |
| 1494 | if (error < 0) { |
| 1495 | printf("dpsparser_get_api_version() failed: %d\n", error); |
| 1496 | return error; |
| 1497 | } |
| 1498 | |
| 1499 | if (major_ver < DPSPARSER_VER_MAJOR || (major_ver == |
| 1500 | DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) { |
| 1501 | printf("DPSPARSER version mismatch found %u.%u,", |
| 1502 | major_ver, minor_ver); |
| 1503 | printf("supported version is %u.%u\n", |
| 1504 | DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR); |
| 1505 | } |
| 1506 | |
| 1507 | return error; |
| 1508 | } |
| 1509 | |
| 1510 | static int dpsparser_init(void) |
| 1511 | { |
| 1512 | int err = 0; |
| 1513 | |
| 1514 | if (!is_dpsparser_supported()) |
| 1515 | return 0; |
| 1516 | |
| 1517 | err = dpsparser_create(dflt_mc_io, |
| 1518 | dflt_dprc_handle, |
| 1519 | MC_CMD_NO_FLAGS, |
| 1520 | &dpsparser_obj_id); |
| 1521 | if (err) |
| 1522 | printf("dpsparser_create() failed\n"); |
| 1523 | |
| 1524 | err = dpsparser_version_check(dflt_mc_io); |
| 1525 | if (err < 0) { |
| 1526 | printf("dpsparser_version_check() failed: %d\n", err); |
| 1527 | goto err_version_check; |
| 1528 | } |
| 1529 | |
| 1530 | err = dpsparser_open(dflt_mc_io, |
| 1531 | MC_CMD_NO_FLAGS, |
| 1532 | &dpsparser_handle); |
| 1533 | if (err < 0) { |
| 1534 | printf("dpsparser_open() failed: %d\n", err); |
| 1535 | goto err_open; |
| 1536 | } |
| 1537 | |
| 1538 | return err; |
| 1539 | |
| 1540 | err_open: |
| 1541 | err_version_check: |
| 1542 | dpsparser_destroy(dflt_mc_io, |
| 1543 | dflt_dprc_handle, |
| 1544 | MC_CMD_NO_FLAGS, dpsparser_obj_id); |
| 1545 | |
| 1546 | return err; |
| 1547 | } |
| 1548 | |
| 1549 | #ifdef DPSPARSER_DESTROY |
| 1550 | /* TODO: refactoring needed in the future to allow DPSPARSER object destroy |
| 1551 | * Workaround: DO NOT destroy DPSPARSER object because it needs to be available |
| 1552 | * on Apply DPL |
| 1553 | */ |
| 1554 | static int dpsparser_exit(void) |
| 1555 | { |
| 1556 | int err; |
| 1557 | |
| 1558 | if (!is_dpsparser_supported()) |
| 1559 | return 0; |
| 1560 | |
| 1561 | dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle); |
| 1562 | if (err < 0) { |
| 1563 | printf("dpsparser_close() failed: %d\n", err); |
| 1564 | goto err; |
| 1565 | } |
| 1566 | |
| 1567 | err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle, |
| 1568 | MC_CMD_NO_FLAGS, dpsparser_obj_id); |
| 1569 | if (err < 0) { |
| 1570 | printf("dpsparser_destroy() failed: %d\n", err); |
| 1571 | goto err; |
| 1572 | } |
| 1573 | return 0; |
| 1574 | |
| 1575 | err: |
| 1576 | return err; |
| 1577 | } |
| 1578 | #endif |
| 1579 | |
| 1580 | int mc_apply_spb(u64 mc_spb_addr) |
| 1581 | { |
| 1582 | int err = 0; |
| 1583 | u16 error, err_arr_size; |
| 1584 | u64 mc_spb_offset; |
| 1585 | u32 spb_size; |
| 1586 | struct sp_blob_header *sp_blob; |
| 1587 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 1588 | |
| 1589 | if (!is_dpsparser_supported()) |
| 1590 | return 0; |
| 1591 | |
| 1592 | if (!mc_spb_addr) { |
| 1593 | printf("fsl-mc: Invalid Blob address\n"); |
| 1594 | return -1; |
| 1595 | } |
| 1596 | |
| 1597 | #ifdef CONFIG_MC_DRAM_SPB_OFFSET |
| 1598 | mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET; |
| 1599 | #else |
| 1600 | #error "CONFIG_MC_DRAM_SPB_OFFSET not defined" |
| 1601 | #endif |
| 1602 | |
| 1603 | // Read blob header and get size of SPB blob |
| 1604 | sp_blob = (struct sp_blob_header *)mc_spb_addr; |
| 1605 | spb_size = le32_to_cpu(sp_blob->length); |
| 1606 | if (spb_size > CONFIG_MC_SPB_MAX_SIZE) { |
| 1607 | printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n", |
| 1608 | spb_size); |
| 1609 | return -EINVAL; |
| 1610 | } |
| 1611 | |
| 1612 | mc_copy_image("MC SP Blob", mc_spb_addr, spb_size, |
| 1613 | mc_ram_addr + mc_spb_offset); |
| 1614 | |
| 1615 | //Invoke MC command to apply SPB blob |
| 1616 | printf("fsl-mc: Applying soft parser blob... "); |
| 1617 | err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle, |
| 1618 | mc_spb_offset, &error); |
| 1619 | if (err) |
| 1620 | return err; |
| 1621 | |
| 1622 | if (error == 0) { |
| 1623 | printf("SUCCESS\n"); |
| 1624 | } else { |
| 1625 | printf("FAILED with error code = %d:\n", error); |
| 1626 | err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb); |
| 1627 | |
| 1628 | if (error > 0 && error < err_arr_size) |
| 1629 | printf(mc_err_msg_apply_spb[error]); |
| 1630 | else |
| 1631 | printf(MC_ERROR_MSG_SPB_UNKNOWN); |
| 1632 | } |
| 1633 | |
| 1634 | return err; |
| 1635 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1636 | |
| 1637 | static int mc_init_object(void) |
| 1638 | { |
| 1639 | int err = 0; |
| 1640 | |
| 1641 | err = dprc_init(); |
| 1642 | if (err < 0) { |
| 1643 | printf("dprc_init() failed: %d\n", err); |
| 1644 | goto err; |
| 1645 | } |
| 1646 | |
| 1647 | err = dpbp_init(); |
| 1648 | if (err < 0) { |
| 1649 | printf("dpbp_init() failed: %d\n", err); |
| 1650 | goto err; |
| 1651 | } |
| 1652 | |
| 1653 | err = dpio_init(); |
| 1654 | if (err < 0) { |
| 1655 | printf("dpio_init() failed: %d\n", err); |
| 1656 | goto err; |
| 1657 | } |
| 1658 | |
| 1659 | err = dpni_init(); |
| 1660 | if (err < 0) { |
| 1661 | printf("dpni_init() failed: %d\n", err); |
| 1662 | goto err; |
| 1663 | } |
| 1664 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1665 | err = dpsparser_init(); |
| 1666 | if (err < 0) { |
| 1667 | printf("dpsparser_init() failed: %d\n", err); |
| 1668 | goto err; |
| 1669 | } |
| 1670 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1671 | return 0; |
| 1672 | err: |
| 1673 | return err; |
| 1674 | } |
| 1675 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1676 | int fsl_mc_ldpaa_exit(struct bd_info *bd) |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1677 | { |
| 1678 | int err = 0; |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1679 | bool is_dpl_apply_status = false; |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1680 | bool mc_boot_status = false; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1681 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1682 | if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) { |
Yogesh Gaur | 8dadfb4 | 2018-01-16 10:08:24 +0530 | [diff] [blame] | 1683 | err = mc_apply_dpl(mc_lazy_dpl_addr); |
| 1684 | if (!err) |
| 1685 | fdt_fixup_board_enet(working_fdt); |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1686 | mc_lazy_dpl_addr = 0; |
| 1687 | } |
| 1688 | |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1689 | if (!get_mc_boot_status()) |
| 1690 | mc_boot_status = true; |
| 1691 | |
Prabhakar Kushwaha | 878d3ec | 2016-03-21 14:19:39 +0530 | [diff] [blame] | 1692 | /* MC is not loaded intentionally, So return success. */ |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1693 | if (bd && !mc_boot_status) |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1694 | return 0; |
| 1695 | |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1696 | /* If DPL is deployed, set is_dpl_apply_status as TRUE. */ |
| 1697 | if (!get_dpl_apply_status()) |
| 1698 | is_dpl_apply_status = true; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1699 | |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1700 | /* |
| 1701 | * For case MC is loaded but DPL is not deployed, return success and |
| 1702 | * print message on console. Else FDT fix-up code execution hanged. |
| 1703 | */ |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1704 | if (bd && mc_boot_status && !is_dpl_apply_status) { |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1705 | printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n"); |
Yogesh Gaur | 82709e5 | 2017-11-28 10:11:14 +0530 | [diff] [blame] | 1706 | goto mc_obj_cleanup; |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1707 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1708 | |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1709 | if (bd && mc_boot_status && is_dpl_apply_status) |
| 1710 | return 0; |
| 1711 | |
Yogesh Gaur | 82709e5 | 2017-11-28 10:11:14 +0530 | [diff] [blame] | 1712 | mc_obj_cleanup: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1713 | err = dpbp_exit(); |
| 1714 | if (err < 0) { |
Prabhakar Kushwaha | 88ba4d6 | 2016-01-20 12:04:37 +0530 | [diff] [blame] | 1715 | printf("dpbp_exit() failed: %d\n", err); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1716 | goto err; |
| 1717 | } |
| 1718 | |
| 1719 | err = dpio_exit(); |
| 1720 | if (err < 0) { |
| 1721 | printf("dpio_exit() failed: %d\n", err); |
| 1722 | goto err; |
| 1723 | } |
| 1724 | |
| 1725 | err = dpni_exit(); |
| 1726 | if (err < 0) { |
| 1727 | printf("dpni_exit() failed: %d\n", err); |
| 1728 | goto err; |
| 1729 | } |
| 1730 | |
| 1731 | err = dprc_exit(); |
| 1732 | if (err < 0) { |
| 1733 | printf("dprc_exit() failed: %d\n", err); |
| 1734 | goto err; |
| 1735 | } |
| 1736 | |
| 1737 | return 0; |
| 1738 | err: |
| 1739 | return err; |
| 1740 | } |
| 1741 | |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 1742 | static void print_k_bytes(const void *buf, ssize_t *size) |
| 1743 | { |
| 1744 | while (*size > 0) { |
| 1745 | int count = printf("%s", (char *)buf); |
| 1746 | |
| 1747 | buf += count; |
| 1748 | *size -= count; |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | static void mc_dump_log(void) |
| 1753 | { |
| 1754 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 1755 | u64 high = in_le64(&mc_ccsr_regs->reg_mcfbahr) & MC_FW_ADDR_MASK_HIGH; |
| 1756 | u64 low = in_le64(&mc_ccsr_regs->reg_mcfbalr) & MC_FW_ADDR_MASK_LOW; |
| 1757 | u32 buf_len, wrapped, last_byte, magic, buf_start; |
| 1758 | u64 mc_addr = (high << 32) | low; |
| 1759 | struct log_header *header; |
| 1760 | ssize_t size, bytes_end; |
| 1761 | const void *end_of_data; |
| 1762 | const void *map_addr; |
| 1763 | const void *end_addr; |
| 1764 | const void *cur_ptr; |
| 1765 | const void *buf; |
| 1766 | |
| 1767 | map_addr = map_sysmem(mc_addr + MC_STRUCT_BUFFER_OFFSET, |
| 1768 | MC_BUFFER_SIZE); |
| 1769 | header = (struct log_header *)map_addr; |
| 1770 | last_byte = in_le32(&header->last_byte); |
| 1771 | buf_len = in_le32(&header->buf_length); |
| 1772 | magic = in_le32(&header->magic_word); |
| 1773 | buf_start = in_le32(&header->buf_start); |
| 1774 | buf = map_addr + buf_start - MC_OFFSET_DELTA; |
| 1775 | end_addr = buf + buf_len; |
| 1776 | wrapped = last_byte & LOG_HEADER_FLAG_BUFFER_WRAPAROUND; |
| 1777 | end_of_data = buf + LAST_BYTE(last_byte); |
| 1778 | |
| 1779 | if (magic != MAGIC_MC) { |
| 1780 | puts("Magic number is not valid\n"); |
| 1781 | printf("expected = %08x, received = %08x\n", MAGIC_MC, magic); |
| 1782 | goto err_magic; |
| 1783 | } |
| 1784 | |
| 1785 | if (wrapped && end_of_data != end_addr) |
| 1786 | cur_ptr = end_of_data + 1; |
| 1787 | else |
| 1788 | cur_ptr = buf; |
| 1789 | |
| 1790 | if (cur_ptr <= end_of_data) |
| 1791 | size = end_of_data - cur_ptr; |
| 1792 | else |
| 1793 | size = (end_addr - cur_ptr) + (end_of_data - buf); |
| 1794 | |
| 1795 | bytes_end = end_addr - cur_ptr; |
| 1796 | if (size > bytes_end) { |
| 1797 | print_k_bytes(cur_ptr, &bytes_end); |
| 1798 | |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 1799 | size -= bytes_end; |
| 1800 | } |
| 1801 | |
| 1802 | print_k_bytes(buf, &size); |
| 1803 | |
| 1804 | err_magic: |
| 1805 | unmap_sysmem(map_addr); |
| 1806 | } |
| 1807 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 1808 | static int do_fsl_mc(struct cmd_tbl *cmdtp, int flag, int argc, |
| 1809 | char *const argv[]) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1810 | { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1811 | int err = 0; |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 1812 | if (argc < 2) |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1813 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1814 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1815 | switch (argv[1][0]) { |
| 1816 | case 's': { |
| 1817 | char sub_cmd; |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 1818 | u64 mc_fw_addr, mc_dpc_addr; |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1819 | #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 1820 | u64 aiop_fw_addr; |
| 1821 | #endif |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 1822 | if (argc < 3) |
| 1823 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1824 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1825 | sub_cmd = argv[2][0]; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1826 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1827 | switch (sub_cmd) { |
| 1828 | case 'm': |
| 1829 | if (argc < 5) |
| 1830 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1831 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1832 | if (get_mc_boot_status() == 0) { |
| 1833 | printf("fsl-mc: MC is already booted"); |
| 1834 | printf("\n"); |
| 1835 | return err; |
| 1836 | } |
| 1837 | mc_fw_addr = simple_strtoull(argv[3], NULL, 16); |
| 1838 | mc_dpc_addr = simple_strtoull(argv[4], NULL, |
| 1839 | 16); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1840 | |
| 1841 | if (!mc_init(mc_fw_addr, mc_dpc_addr)) |
| 1842 | err = mc_init_object(); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1843 | break; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1844 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 1845 | #ifdef CFG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1846 | case 'a': |
| 1847 | if (argc < 4) |
| 1848 | goto usage; |
| 1849 | if (get_aiop_apply_status() == 0) { |
| 1850 | printf("fsl-mc: AIOP FW is already"); |
| 1851 | printf(" applied\n"); |
| 1852 | return err; |
| 1853 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1854 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1855 | aiop_fw_addr = simple_strtoull(argv[3], NULL, |
| 1856 | 16); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1857 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 1858 | /* if SoC doesn't have AIOP, err = -ENODEV */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1859 | err = load_mc_aiop_img(aiop_fw_addr); |
| 1860 | if (!err) |
| 1861 | printf("fsl-mc: AIOP FW applied\n"); |
| 1862 | break; |
| 1863 | #endif |
| 1864 | default: |
| 1865 | printf("Invalid option: %s\n", argv[2]); |
| 1866 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1867 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1868 | break; |
| 1869 | } |
| 1870 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1871 | break; |
| 1872 | |
| 1873 | case 'l': { |
| 1874 | /* lazyapply */ |
| 1875 | u64 mc_dpl_addr; |
| 1876 | |
| 1877 | if (argc < 4) |
| 1878 | goto usage; |
| 1879 | |
| 1880 | if (get_dpl_apply_status() == 0) { |
| 1881 | printf("fsl-mc: DPL already applied\n"); |
| 1882 | return err; |
| 1883 | } |
| 1884 | |
| 1885 | mc_dpl_addr = simple_strtoull(argv[3], NULL, 16); |
| 1886 | |
| 1887 | if (get_mc_boot_status() != 0) { |
| 1888 | printf("fsl-mc: Deploying data path layout .."); |
| 1889 | printf("ERROR (MC is not booted)\n"); |
| 1890 | return -ENODEV; |
| 1891 | } |
| 1892 | |
| 1893 | /* |
| 1894 | * We will do the actual dpaa exit and dpl apply |
| 1895 | * later from announce_and_cleanup(). |
| 1896 | */ |
| 1897 | mc_lazy_dpl_addr = mc_dpl_addr; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1898 | break; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1899 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1900 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1901 | case 'a': { |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1902 | /* apply */ |
| 1903 | char sub_cmd; |
| 1904 | u64 mc_apply_addr; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1905 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1906 | if (argc < 4) |
| 1907 | goto usage; |
| 1908 | |
| 1909 | sub_cmd = argv[2][0]; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1910 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1911 | switch (sub_cmd) { |
| 1912 | case 'd': |
| 1913 | case 'D': |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1914 | if (get_dpl_apply_status() == 0) { |
| 1915 | printf("fsl-mc: DPL already applied\n"); |
| 1916 | return err; |
| 1917 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1918 | if (get_mc_boot_status() != 0) { |
| 1919 | printf("fsl-mc: Deploying data path layout .."); |
| 1920 | printf("ERROR (MC is not booted)\n"); |
| 1921 | return -ENODEV; |
| 1922 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1923 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1924 | mc_apply_addr = simple_strtoull(argv[3], NULL, 16); |
| 1925 | |
| 1926 | /* The user wants DPL applied now */ |
| 1927 | if (!fsl_mc_ldpaa_exit(NULL)) |
| 1928 | err = mc_apply_dpl(mc_apply_addr); |
| 1929 | break; |
| 1930 | |
| 1931 | case 's': |
| 1932 | if (!is_dpsparser_supported()) { |
| 1933 | printf("fsl-mc: apply spb command .. "); |
| 1934 | printf("ERROR: requires at least MC 10.12.0\n"); |
| 1935 | return err; |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1936 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1937 | if (get_mc_boot_status() != 0) { |
| 1938 | printf("fsl-mc: Deploying Soft Parser Blob..."); |
| 1939 | printf("ERROR (MC is not booted)\n"); |
| 1940 | return err; |
| 1941 | } |
| 1942 | |
| 1943 | mc_apply_addr = simple_strtoull(argv[3], NULL, 16); |
| 1944 | |
| 1945 | /* Apply spb (Soft Parser Blob) */ |
| 1946 | err = mc_apply_spb(mc_apply_addr); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1947 | break; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1948 | |
| 1949 | default: |
| 1950 | printf("Invalid option: %s\n", argv[2]); |
| 1951 | goto usage; |
| 1952 | } |
| 1953 | break; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 1954 | } |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 1955 | case 'd': |
| 1956 | if (argc > 2) |
| 1957 | goto usage; |
| 1958 | |
| 1959 | mc_dump_log(); |
| 1960 | break; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1961 | default: |
| 1962 | printf("Invalid option: %s\n", argv[1]); |
| 1963 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1964 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1965 | return err; |
| 1966 | usage: |
| 1967 | return CMD_RET_USAGE; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1968 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1969 | |
| 1970 | U_BOOT_CMD( |
| 1971 | fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc, |
| 1972 | "DPAA2 command to manage Management Complex (MC)", |
| 1973 | "start mc [FW_addr] [DPC_addr] - Start Management Complex\n" |
| 1974 | "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n" |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1975 | "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n" |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1976 | "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n" |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1977 | "fsl_mc start aiop [FW_addr] - Start AIOP\n" |
Cosmin-Florin Aluchenesei | aa28014 | 2021-10-07 13:07:44 +0300 | [diff] [blame] | 1978 | "fsl_mc dump_log - Dump MC Log\n" |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1979 | ); |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 1980 | |
| 1981 | void mc_env_boot(void) |
| 1982 | { |
| 1983 | #if defined(CONFIG_FSL_MC_ENET) |
| 1984 | char *mc_boot_env_var; |
| 1985 | /* The MC may only be initialized in the reset PHY function |
| 1986 | * because otherwise U-Boot has not yet set up all the MAC |
| 1987 | * address info properly. Without MAC addresses, the MC code |
| 1988 | * can not properly initialize the DPC. |
| 1989 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1990 | mc_boot_env_var = env_get(MC_BOOT_ENV_VAR); |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 1991 | if (mc_boot_env_var) |
| 1992 | run_command_list(mc_boot_env_var, -1, 0); |
| 1993 | #endif /* CONFIG_FSL_MC_ENET */ |
| 1994 | } |