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