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