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