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