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