blob: 9c4ba7dbda690a89248e2939ee10a269f4fbe87b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
J. German Riverab940ca62014-06-23 15:15:55 -07002/*
Yogesh Gaura6f2a6e2018-05-09 10:52:17 +05303 * Copyright 2014 Freescale Semiconductor, Inc.
Prabhakar Kushwaha87519a92018-08-27 12:58:52 +05304 * Copyright 2017-2018 NXP
J. German Riverab940ca62014-06-23 15:15:55 -07005 */
Stuart Yoder21c69872015-07-02 11:29:03 +05306#include <common.h>
Simon Glass288b29e2019-11-14 12:57:43 -07007#include <command.h>
Simon Glass1eb69ae2019-11-14 12:57:39 -07008#include <cpu_func.h>
Simon Glass7b51b572019-08-01 09:46:52 -06009#include <env.h>
J. German Riverab940ca62014-06-23 15:15:55 -070010#include <errno.h>
Simon Glass336d4612020-02-03 07:36:16 -070011#include <malloc.h>
Masahiro Yamada84b8bf62016-01-24 23:27:48 +090012#include <linux/bug.h>
J. German Riverab940ca62014-06-23 15:15:55 -070013#include <asm/io.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +000015#include <net.h>
Stuart Yoder21c69872015-07-02 11:29:03 +053016#include <fdt_support.h>
J. German Rivera7b3bd9a2015-01-06 13:19:02 -080017#include <fsl-mc/fsl_mc.h>
18#include <fsl-mc/fsl_mc_sys.h>
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070019#include <fsl-mc/fsl_mc_private.h>
J. German Rivera7b3bd9a2015-01-06 13:19:02 -080020#include <fsl-mc/fsl_dpmng.h>
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070021#include <fsl-mc/fsl_dprc.h>
22#include <fsl-mc/fsl_dpio.h>
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +053023#include <fsl-mc/fsl_dpni.h>
Florinel Iordache1990cc72019-11-19 10:28:17 +000024#include <fsl-mc/fsl_dpsparser.h>
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070025#include <fsl-mc/fsl_qbman_portal.h>
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +053026#include <fsl-mc/ldpaa_wriop.h>
J. German Riverab940ca62014-06-23 15:15:55 -070027
J. German Rivera125e2bc2015-03-20 19:28:18 -070028#define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
29#define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
30#define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
31
32#define MC_MEM_SIZE_ENV_VAR "mcmemsize"
33#define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
Bogdan Purcareata33a89912017-05-24 16:40:21 +000034#define MC_BOOT_ENV_VAR "mcinitcmd"
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +053035#define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024)
J. German Rivera125e2bc2015-03-20 19:28:18 -070036
J. German Riverab940ca62014-06-23 15:15:55 -070037DECLARE_GLOBAL_DATA_PTR;
Prabhakar Kushwaha87519a92018-08-27 12:58:52 +053038static int mc_memset_resv_ram;
Florinel Iordache1990cc72019-11-19 10:28:17 +000039static struct mc_version mc_ver_info;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +053040static int mc_boot_status = -1;
41static int mc_dpl_applied = -1;
42#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
43static int mc_aiop_applied = -1;
44#endif
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +053045struct fsl_mc_io *root_mc_io = NULL;
46struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
47uint16_t root_dprc_handle = 0;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070048uint16_t dflt_dprc_handle = 0;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +053049int child_dprc_id;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070050struct fsl_dpbp_obj *dflt_dpbp = NULL;
51struct fsl_dpio_obj *dflt_dpio = NULL;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +053052struct fsl_dpni_obj *dflt_dpni = NULL;
Alexander Grafb7b84102016-11-17 01:02:57 +010053static u64 mc_lazy_dpl_addr;
Florinel Iordache1990cc72019-11-19 10:28:17 +000054static u32 dpsparser_obj_id;
55static u16 dpsparser_handle;
56static char *mc_err_msg_apply_spb[] = MC_ERROR_MSG_APPLY_SPB;
J. German Riverab940ca62014-06-23 15:15:55 -070057
J. German Rivera125e2bc2015-03-20 19:28:18 -070058#ifdef DEBUG
59void dump_ram_words(const char *title, void *addr)
60{
61 int i;
62 uint32_t *words = addr;
63
64 printf("Dumping beginning of %s (%p):\n", title, addr);
65 for (i = 0; i < 16; i++)
66 printf("%#x ", words[i]);
67
68 printf("\n");
69}
70
71void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
72{
73 printf("MC CCSR registers:\n"
74 "reg_gcr1 %#x\n"
75 "reg_gsr %#x\n"
76 "reg_sicbalr %#x\n"
77 "reg_sicbahr %#x\n"
78 "reg_sicapr %#x\n"
79 "reg_mcfbalr %#x\n"
80 "reg_mcfbahr %#x\n"
81 "reg_mcfapr %#x\n"
82 "reg_psr %#x\n",
83 mc_ccsr_regs->reg_gcr1,
84 mc_ccsr_regs->reg_gsr,
85 mc_ccsr_regs->reg_sicbalr,
86 mc_ccsr_regs->reg_sicbahr,
87 mc_ccsr_regs->reg_sicapr,
88 mc_ccsr_regs->reg_mcfbalr,
89 mc_ccsr_regs->reg_mcfbahr,
90 mc_ccsr_regs->reg_mcfapr,
91 mc_ccsr_regs->reg_psr);
92}
93#else
94
95#define dump_ram_words(title, addr)
96#define dump_mc_ccsr_regs(mc_ccsr_regs)
97
98#endif /* DEBUG */
99
J. German Riverab940ca62014-06-23 15:15:55 -0700100/**
101 * Copying MC firmware or DPL image to DDR
102 */
103static int mc_copy_image(const char *title,
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800104 u64 image_addr, u32 image_size, u64 mc_ram_addr)
J. German Riverab940ca62014-06-23 15:15:55 -0700105{
106 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
107 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700108 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
J. German Riverab940ca62014-06-23 15:15:55 -0700109 return 0;
110}
111
Florinel Iordache1990cc72019-11-19 10:28:17 +0000112#ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
J. German Riverab940ca62014-06-23 15:15:55 -0700113/**
114 * MC firmware FIT image parser checks if the image is in FIT
115 * format, verifies integrity of the image and calculates
116 * raw image address and size values.
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800117 * Returns 0 on success and a negative errno on error.
J. German Riverab940ca62014-06-23 15:15:55 -0700118 * task fail.
119 **/
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530120int parse_mc_firmware_fit_image(u64 mc_fw_addr,
121 const void **raw_image_addr,
J. German Riverab940ca62014-06-23 15:15:55 -0700122 size_t *raw_image_size)
123{
124 int format;
125 void *fit_hdr;
126 int node_offset;
127 const void *data;
128 size_t size;
129 const char *uname = "firmware";
130
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530131 fit_hdr = (void *)mc_fw_addr;
J. German Riverab940ca62014-06-23 15:15:55 -0700132
133 /* Check if Image is in FIT format */
134 format = genimg_get_format(fit_hdr);
135
136 if (format != IMAGE_FORMAT_FIT) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530137 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800138 return -EINVAL;
J. German Riverab940ca62014-06-23 15:15:55 -0700139 }
140
141 if (!fit_check_format(fit_hdr)) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530142 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800143 return -EINVAL;
J. German Riverab940ca62014-06-23 15:15:55 -0700144 }
145
146 node_offset = fit_image_get_node(fit_hdr, uname);
147
148 if (node_offset < 0) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530149 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800150 return -ENOENT;
J. German Riverab940ca62014-06-23 15:15:55 -0700151 }
152
153 /* Verify MC firmware image */
154 if (!(fit_image_verify(fit_hdr, node_offset))) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530155 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800156 return -EINVAL;
J. German Riverab940ca62014-06-23 15:15:55 -0700157 }
158
159 /* Get address and size of raw image */
160 fit_image_get_data(fit_hdr, node_offset, &data, &size);
161
162 *raw_image_addr = data;
163 *raw_image_size = size;
164
165 return 0;
166}
J. German Rivera125e2bc2015-03-20 19:28:18 -0700167#endif
168
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000169#define MC_DT_INCREASE_SIZE 64
170
171enum mc_fixup_type {
172 MC_FIXUP_DPL,
173 MC_FIXUP_DPC
174};
175
176static int mc_fixup_mac_addr(void *blob, int nodeoffset,
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200177#ifdef CONFIG_DM_ETH
178 const char *propname, struct udevice *eth_dev,
179#else
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000180 const char *propname, struct eth_device *eth_dev,
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200181#endif
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000182 enum mc_fixup_type type)
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000183{
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200184#ifdef CONFIG_DM_ETH
185 struct eth_pdata *plat = dev_get_platdata(eth_dev);
186 unsigned char *enetaddr = plat->enetaddr;
187 int eth_index = eth_dev->seq;
188#else
189 unsigned char *enetaddr = eth_dev->enetaddr;
190 int eth_index = eth_dev->index;
191#endif
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000192 int err = 0, len = 0, size, i;
193 unsigned char env_enetaddr[ARP_HLEN];
194 unsigned int enetaddr_32[ARP_HLEN];
195 void *val = NULL;
196
197 switch (type) {
198 case MC_FIXUP_DPL:
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200199 /* DPL likes its addresses on 32 * ARP_HLEN bits */
200 for (i = 0; i < ARP_HLEN; i++)
201 enetaddr_32[i] = cpu_to_fdt32(enetaddr[i]);
202 val = enetaddr_32;
203 len = sizeof(enetaddr_32);
204 break;
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000205 case MC_FIXUP_DPC:
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200206 val = enetaddr;
207 len = ARP_HLEN;
208 break;
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000209 }
210
211 /* MAC address property present */
212 if (fdt_get_property(blob, nodeoffset, propname, NULL)) {
213 /* u-boot MAC addr randomly assigned - leave the present one */
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200214 if (!eth_env_get_enetaddr_by_index("eth", eth_index,
Simon Glass35affd72017-08-03 12:22:14 -0600215 env_enetaddr))
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000216 return err;
217 } else {
218 size = MC_DT_INCREASE_SIZE + strlen(propname) + len;
219 /* make room for mac address property */
220 err = fdt_increase_size(blob, size);
221 if (err) {
222 printf("fdt_increase_size: err=%s\n",
223 fdt_strerror(err));
224 return err;
225 }
226 }
227
228 err = fdt_setprop(blob, nodeoffset, propname, val, len);
229 if (err) {
230 printf("fdt_setprop: err=%s\n", fdt_strerror(err));
231 return err;
232 }
233
234 return err;
235}
236
237#define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
238
239const char *dpl_get_connection_endpoint(void *blob, char *endpoint)
240{
241 int connoffset = fdt_path_offset(blob, "/connections"), off;
242 const char *s1, *s2;
243
244 for (off = fdt_first_subnode(blob, connoffset);
245 off >= 0;
246 off = fdt_next_subnode(blob, off)) {
247 s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL);
248 s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL);
249
250 if (!s1 || !s2)
251 continue;
252
253 if (strcmp(endpoint, s1) == 0)
254 return s2;
255
256 if (strcmp(endpoint, s2) == 0)
257 return s1;
258 }
259
260 return NULL;
261}
262
263static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id,
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200264#ifdef CONFIG_DM_ETH
265 struct udevice *eth_dev)
266#else
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000267 struct eth_device *eth_dev)
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200268#endif
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000269{
270 int objoff = fdt_path_offset(blob, "/objects");
271 int dpmacoff = -1, dpnioff = -1;
272 const char *endpoint;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000273 char mac_name[10];
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000274 int err;
275
276 sprintf(mac_name, "dpmac@%d", dpmac_id);
277 dpmacoff = fdt_subnode_offset(blob, objoff, mac_name);
278 if (dpmacoff < 0)
279 /* dpmac not defined in DPL, so skip it. */
280 return 0;
281
282 err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev,
283 MC_FIXUP_DPL);
284 if (err) {
285 printf("Error fixing up dpmac mac_addr in DPL\n");
286 return err;
287 }
288
289 /* now we need to figure out if there is any
290 * DPNI connected to this MAC, so we walk the
291 * connection list
292 */
293 endpoint = dpl_get_connection_endpoint(blob, mac_name);
294 if (!is_dpni(endpoint))
295 return 0;
296
297 /* let's see if we can fixup the DPNI as well */
298 dpnioff = fdt_subnode_offset(blob, objoff, endpoint);
299 if (dpnioff < 0)
300 /* DPNI not defined in DPL in the objects area */
301 return 0;
302
303 return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev,
304 MC_FIXUP_DPL);
305}
306
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530307void fdt_fixup_mc_ddr(u64 *base, u64 *size)
308{
309 u64 mc_size = mc_get_dram_block_size();
310
311 if (mc_size < MC_DRAM_BLOCK_DEFAULT_SIZE) {
312 *base = mc_get_dram_addr() + mc_size;
313 *size = MC_DRAM_BLOCK_DEFAULT_SIZE - mc_size;
314 }
315}
316
Nipun Guptaa78df402018-08-20 16:01:14 +0530317void fdt_fsl_mc_fixup_iommu_map_entry(void *blob)
318{
319 u32 *prop;
Laurentiu Tudor21a00d12020-05-04 14:47:11 +0300320 u32 iommu_map[4], phandle;
Nipun Guptaa78df402018-08-20 16:01:14 +0530321 int offset;
322 int lenp;
323
324 /* find fsl-mc node */
325 offset = fdt_path_offset(blob, "/soc/fsl-mc");
326 if (offset < 0)
327 offset = fdt_path_offset(blob, "/fsl-mc");
328 if (offset < 0) {
329 printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n",
330 __func__, offset);
331 return;
332 }
333
334 prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp);
335 if (!prop) {
336 debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n",
337 __func__);
338 return;
339 }
340
341 iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
342 iommu_map[1] = *++prop;
343 iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
344 iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END -
345 FSL_DPAA2_STREAM_ID_START + 1);
346
347 fdt_setprop_inplace(blob, offset, "iommu-map",
348 iommu_map, sizeof(iommu_map));
Laurentiu Tudor21a00d12020-05-04 14:47:11 +0300349
350 /* get phandle to MSI controller */
351 prop = (u32 *)fdt_getprop(blob, offset, "msi-parent", 0);
352 if (!prop) {
353 debug("\n%s: ERROR: missing msi-parent\n", __func__);
354 return;
355 }
356 phandle = fdt32_to_cpu(*prop);
357
358 /* also set msi-map property */
359 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START);
360 fdt_appendprop_u32(blob, offset, "msi-map", phandle);
361 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_START);
362 fdt_appendprop_u32(blob, offset, "msi-map", FSL_DPAA2_STREAM_ID_END -
363 FSL_DPAA2_STREAM_ID_START + 1);
Nipun Guptaa78df402018-08-20 16:01:14 +0530364}
365
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000366static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200367#ifdef CONFIG_DM_ETH
368 struct udevice *eth_dev)
369#else
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000370 struct eth_device *eth_dev)
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200371#endif
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000372{
373 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
374 int err = 0;
375 char mac_name[10];
376 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000377
378 sprintf(mac_name, "mac@%d", dpmac_id);
379
380 /* node not found - create it */
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000381 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
382 if (noff < 0) {
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000383 err = fdt_increase_size(blob, 200);
384 if (err) {
385 printf("fdt_increase_size: err=%s\n",
386 fdt_strerror(err));
387 return err;
388 }
389
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000390 noff = fdt_add_subnode(blob, nodeoffset, mac_name);
391 if (noff < 0) {
392 printf("fdt_add_subnode: err=%s\n",
393 fdt_strerror(err));
394 return err;
395 }
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000396
397 /* add default property of fixed link */
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000398 err = fdt_appendprop_string(blob, noff,
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000399 "link_type", link_type_mode);
400 if (err) {
401 printf("fdt_appendprop_string: err=%s\n",
402 fdt_strerror(err));
403 return err;
404 }
405 }
406
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000407 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
408 MC_FIXUP_DPC);
409}
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000410
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000411static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
412{
413 int i, err = 0, ret = 0;
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200414#ifdef CONFIG_DM_ETH
415#define ETH_NAME_LEN 20
416 struct udevice *eth_dev;
417#else
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000418 struct eth_device *eth_dev;
Ioana Ciornei988e33f2020-03-18 16:47:38 +0200419#endif
420 char ethname[ETH_NAME_LEN];
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000421
422 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
423 /* port not enabled */
Pankaj Bansal1ed19a12018-10-10 14:08:33 +0530424 if (wriop_is_enabled_dpmac(i) != 1)
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000425 continue;
426
Pankaj Bansalc022ec02018-08-02 16:31:28 +0530427 snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
428 phy_interface_strings[wriop_get_enet_if(i)]);
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000429
430 eth_dev = eth_get_dev_by_name(ethname);
431 if (eth_dev == NULL)
432 continue;
433
434 switch (type) {
435 case MC_FIXUP_DPL:
436 err = mc_fixup_dpl_mac_addr(blob, i, eth_dev);
437 break;
438 case MC_FIXUP_DPC:
439 err = mc_fixup_dpc_mac_addr(blob, i, eth_dev);
440 break;
441 default:
442 break;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000443 }
444
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000445 if (err)
446 printf("fsl-mc: ERROR fixing mac address for %s\n",
447 ethname);
448 ret |= err;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000449 }
450
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000451 return ret;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000452}
453
Stuart Yoder21c69872015-07-02 11:29:03 +0530454static int mc_fixup_dpc(u64 dpc_addr)
455{
456 void *blob = (void *)dpc_addr;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000457 int nodeoffset, err = 0;
Stuart Yoder21c69872015-07-02 11:29:03 +0530458
459 /* delete any existing ICID pools */
460 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
461 if (fdt_del_node(blob, nodeoffset) < 0)
462 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
463
464 /* add a new pool */
465 nodeoffset = fdt_path_offset(blob, "/resources");
466 if (nodeoffset < 0) {
467 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
468 return -EINVAL;
469 }
470 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
471 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
472 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
473 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
474 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
475 "num",
476 FSL_DPAA2_STREAM_ID_END -
477 FSL_DPAA2_STREAM_ID_START + 1, 1);
478
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000479 /* fixup MAC addresses for dpmac ports */
480 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
481 if (nodeoffset < 0)
Ioana Ciocoi Radulescu2e9f1bf2019-02-26 15:50:07 +0000482 goto out;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000483
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000484 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
Ioana Ciocoi Radulescu2e9f1bf2019-02-26 15:50:07 +0000485
486out:
Stuart Yoder21c69872015-07-02 11:29:03 +0530487 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
488
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000489 return err;
Stuart Yoder21c69872015-07-02 11:29:03 +0530490}
491
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530492static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
J. German Rivera125e2bc2015-03-20 19:28:18 -0700493{
494 u64 mc_dpc_offset;
495#ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
496 int error;
497 void *dpc_fdt_hdr;
498 int dpc_size;
499#endif
500
501#ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
502 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
503 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
504
505 mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
506#else
507#error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
508#endif
509
510 /*
511 * Load the MC DPC blob in the MC private DRAM block:
512 */
513#ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
514 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
515#else
516 /*
517 * Get address and size of the DPC blob stored in flash:
518 */
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530519 dpc_fdt_hdr = (void *)mc_dpc_addr;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700520
521 error = fdt_check_header(dpc_fdt_hdr);
522 if (error != 0) {
523 /*
524 * Don't return with error here, since the MC firmware can
525 * still boot without a DPC
526 */
J. German Riveracc088c32015-07-02 11:28:56 +0530527 printf("\nfsl-mc: WARNING: No DPC image found");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700528 return 0;
529 }
530
531 dpc_size = fdt_totalsize(dpc_fdt_hdr);
532 if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
J. German Riveracc088c32015-07-02 11:28:56 +0530533 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
J. German Rivera125e2bc2015-03-20 19:28:18 -0700534 dpc_size);
535 return -EINVAL;
536 }
537
538 mc_copy_image("MC DPC blob",
539 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
540#endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
541
Stuart Yoder21c69872015-07-02 11:29:03 +0530542 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
543 return -EINVAL;
544
J. German Rivera125e2bc2015-03-20 19:28:18 -0700545 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
546 return 0;
547}
548
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000549
550static int mc_fixup_dpl(u64 dpl_addr)
551{
552 void *blob = (void *)dpl_addr;
553 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
554 int err = 0;
555
556 /* The DPL fixup for mac addresses is only relevant
557 * for old-style DPLs
558 */
559 if (ver >= 10)
560 return 0;
561
562 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
563 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
564
565 return err;
566}
567
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530568static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
J. German Rivera125e2bc2015-03-20 19:28:18 -0700569{
570 u64 mc_dpl_offset;
571#ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
572 int error;
573 void *dpl_fdt_hdr;
574 int dpl_size;
575#endif
576
577#ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
578 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
579 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
580
581 mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
582#else
583#error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
584#endif
585
586 /*
587 * Load the MC DPL blob in the MC private DRAM block:
588 */
589#ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
590 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
591#else
592 /*
593 * Get address and size of the DPL blob stored in flash:
594 */
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530595 dpl_fdt_hdr = (void *)mc_dpl_addr;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700596
597 error = fdt_check_header(dpl_fdt_hdr);
598 if (error != 0) {
J. German Riveracc088c32015-07-02 11:28:56 +0530599 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700600 return error;
601 }
602
603 dpl_size = fdt_totalsize(dpl_fdt_hdr);
604 if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
J. German Riveracc088c32015-07-02 11:28:56 +0530605 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
J. German Rivera125e2bc2015-03-20 19:28:18 -0700606 dpl_size);
607 return -EINVAL;
608 }
609
610 mc_copy_image("MC DPL blob",
611 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
612#endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
613
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000614 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
615 return -EINVAL;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700616 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
617 return 0;
618}
619
620/**
621 * Return the MC boot timeout value in milliseconds
622 */
623static unsigned long get_mc_boot_timeout_ms(void)
624{
625 unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
626
Simon Glass00caae62017-08-03 12:22:12 -0600627 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700628
629 if (timeout_ms_env_var) {
630 timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
631 if (timeout_ms == 0) {
632 printf("fsl-mc: WARNING: Invalid value for \'"
633 MC_BOOT_TIMEOUT_ENV_VAR
634 "\' environment variable: %lu\n",
635 timeout_ms);
636
637 timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
638 }
639 }
640
641 return timeout_ms;
642}
643
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530644#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
York Sun3c1d2182016-04-04 11:41:26 -0700645
646__weak bool soc_has_aiop(void)
647{
648 return false;
649}
650
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530651static int load_mc_aiop_img(u64 aiop_fw_addr)
J. German Riverac1000c12015-07-02 11:28:58 +0530652{
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530653 u64 mc_ram_addr = mc_get_dram_addr();
654#ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
J. German Riverac1000c12015-07-02 11:28:58 +0530655 void *aiop_img;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530656#endif
J. German Riverac1000c12015-07-02 11:28:58 +0530657
York Sun3c1d2182016-04-04 11:41:26 -0700658 /* Check if AIOP is available */
659 if (!soc_has_aiop())
660 return -ENODEV;
J. German Riverac1000c12015-07-02 11:28:58 +0530661 /*
662 * Load the MC AIOP image in the MC private DRAM block:
663 */
664
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530665#ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
666 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
667 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
668#else
669 aiop_img = (void *)aiop_fw_addr;
J. German Riverac1000c12015-07-02 11:28:58 +0530670 mc_copy_image("MC AIOP image",
671 (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
672 mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530673#endif
674 mc_aiop_applied = 0;
J. German Riverac1000c12015-07-02 11:28:58 +0530675
676 return 0;
677}
678#endif
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530679
J. German Rivera125e2bc2015-03-20 19:28:18 -0700680static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
681{
682 u32 reg_gsr;
683 u32 mc_fw_boot_status;
684 unsigned long timeout_ms = get_mc_boot_timeout_ms();
685 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
686
687 dmb();
J. German Rivera125e2bc2015-03-20 19:28:18 -0700688 assert(timeout_ms > 0);
689 for (;;) {
690 udelay(1000); /* throttle polling */
691 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
692 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
693 if (mc_fw_boot_status & 0x1)
694 break;
695
696 timeout_ms--;
697 if (timeout_ms == 0)
698 break;
699 }
700
701 if (timeout_ms == 0) {
J. German Riveracc088c32015-07-02 11:28:56 +0530702 printf("ERROR: timeout\n");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700703
704 /* TODO: Get an error status from an MC CCSR register */
705 return -ETIMEDOUT;
706 }
707
708 if (mc_fw_boot_status != 0x1) {
709 /*
710 * TODO: Identify critical errors from the GSR register's FS
711 * field and for those errors, set error to -ENODEV or other
712 * appropriate errno, so that the status property is set to
713 * failure in the fsl,dprc device tree node.
714 */
J. German Riveracc088c32015-07-02 11:28:56 +0530715 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
716 reg_gsr);
717 } else {
718 printf("SUCCESS\n");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700719 }
720
J. German Riveracc088c32015-07-02 11:28:56 +0530721
J. German Rivera125e2bc2015-03-20 19:28:18 -0700722 *final_reg_gsr = reg_gsr;
723 return 0;
724}
J. German Riverab940ca62014-06-23 15:15:55 -0700725
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530726int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
J. German Riverab940ca62014-06-23 15:15:55 -0700727{
728 int error = 0;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700729 int portal_id = 0;
J. German Riverab940ca62014-06-23 15:15:55 -0700730 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530731 u64 mc_ram_addr = mc_get_dram_addr();
J. German Riverab940ca62014-06-23 15:15:55 -0700732 u32 reg_gsr;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700733 u32 reg_mcfbalr;
734#ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
J. German Riverab940ca62014-06-23 15:15:55 -0700735 const void *raw_image_addr;
736 size_t raw_image_size = 0;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700737#endif
J. German Rivera125e2bc2015-03-20 19:28:18 -0700738 u8 mc_ram_num_256mb_blocks;
739 size_t mc_ram_size = mc_get_dram_block_size();
J. German Riverab940ca62014-06-23 15:15:55 -0700740
York Sun437858b62017-03-06 09:02:29 -0800741 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530742
743 if (mc_ram_num_256mb_blocks >= 0xff) {
York Sun437858b62017-03-06 09:02:29 -0800744 error = -EINVAL;
745 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
746 mc_ram_size);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700747 goto out;
York Sun437858b62017-03-06 09:02:29 -0800748 }
J. German Rivera125e2bc2015-03-20 19:28:18 -0700749
J. German Riverab940ca62014-06-23 15:15:55 -0700750 /*
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530751 * To support 128 MB DDR Size for MC
752 */
753 if (mc_ram_num_256mb_blocks == 0)
754 mc_ram_num_256mb_blocks = 0xFF;
755
756 /*
J. German Riverab940ca62014-06-23 15:15:55 -0700757 * Management Complex cores should be held at reset out of POR.
Bin Menga1875592016-02-05 19:30:11 -0800758 * U-Boot should be the first software to touch MC. To be safe,
J. German Riverab940ca62014-06-23 15:15:55 -0700759 * we reset all cores again by setting GCR1 to 0. It doesn't do
760 * anything if they are held at reset. After we setup the firmware
761 * we kick off MC by deasserting the reset bit for core 0, and
762 * deasserting the reset bits for Command Portal Managers.
763 * The stop bits are not touched here. They are used to stop the
764 * cores when they are active. Setting stop bits doesn't stop the
765 * cores from fetching instructions when they are released from
766 * reset.
767 */
768 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
769 dmb();
770
J. German Rivera125e2bc2015-03-20 19:28:18 -0700771#ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
772 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
773#else
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530774 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
775 &raw_image_size);
J. German Riverab940ca62014-06-23 15:15:55 -0700776 if (error != 0)
777 goto out;
778 /*
779 * Load the MC FW at the beginning of the MC private DRAM block:
780 */
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800781 mc_copy_image("MC Firmware",
782 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800783#endif
J. German Rivera125e2bc2015-03-20 19:28:18 -0700784 dump_ram_words("firmware", (void *)mc_ram_addr);
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800785
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530786 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700787 if (error != 0)
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800788 goto out;
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800789
J. German Riverab940ca62014-06-23 15:15:55 -0700790 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700791 dump_mc_ccsr_regs(mc_ccsr_regs);
J. German Riverab940ca62014-06-23 15:15:55 -0700792
793 /*
J. German Rivera125e2bc2015-03-20 19:28:18 -0700794 * Tell MC what is the address range of the DRAM block assigned to it:
J. German Riverab940ca62014-06-23 15:15:55 -0700795 */
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530796 if (mc_ram_num_256mb_blocks < 0xFF) {
797 reg_mcfbalr = (u32)mc_ram_addr |
798 (mc_ram_num_256mb_blocks - 1);
799 } else {
800 reg_mcfbalr = (u32)mc_ram_addr |
801 (mc_ram_num_256mb_blocks);
802 }
803
J. German Rivera125e2bc2015-03-20 19:28:18 -0700804 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
805 out_le32(&mc_ccsr_regs->reg_mcfbahr,
York Sun437858b62017-03-06 09:02:29 -0800806 (u32)(mc_ram_addr >> 32));
Stuart Yoder39da6442015-07-02 11:29:02 +0530807 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
J. German Riverab940ca62014-06-23 15:15:55 -0700808
809 /*
J. German Rivera125e2bc2015-03-20 19:28:18 -0700810 * Tell the MC that we want delayed DPL deployment.
J. German Riverab940ca62014-06-23 15:15:55 -0700811 */
J. German Rivera125e2bc2015-03-20 19:28:18 -0700812 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
J. German Riverab940ca62014-06-23 15:15:55 -0700813
J. German Riveracc088c32015-07-02 11:28:56 +0530814 printf("\nfsl-mc: Booting Management Complex ... ");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800815
J. German Riverab940ca62014-06-23 15:15:55 -0700816 /*
817 * Deassert reset and release MC core 0 to run
818 */
819 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700820 error = wait_for_mc(true, &reg_gsr);
821 if (error != 0)
J. German Riverab940ca62014-06-23 15:15:55 -0700822 goto out;
J. German Riverab940ca62014-06-23 15:15:55 -0700823
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800824 /*
825 * TODO: need to obtain the portal_id for the root container from the
826 * DPL
827 */
828 portal_id = 0;
829
830 /*
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700831 * Initialize the global default MC portal
832 * And check that the MC firmware is responding portal commands:
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800833 */
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +0530834 root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530835 if (!root_mc_io) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +0530836 printf(" No memory: calloc() failed\n");
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700837 return -ENOMEM;
838 }
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800839
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530840 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700841 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530842 portal_id, root_mc_io->mmio_regs);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700843
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530844 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800845 if (error != 0) {
846 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
847 error);
848 goto out;
849 }
850
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800851 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
852 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
J. German Rivera125e2bc2015-03-20 19:28:18 -0700853 reg_gsr & GSR_FS_MASK);
854
J. German Riverab940ca62014-06-23 15:15:55 -0700855out:
856 if (error != 0)
Prabhakar Kushwaha2b7c4a12015-07-02 11:29:01 +0530857 mc_boot_status = error;
J. German Riverab940ca62014-06-23 15:15:55 -0700858 else
859 mc_boot_status = 0;
860
861 return error;
862}
863
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530864int mc_apply_dpl(u64 mc_dpl_addr)
865{
866 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
867 int error = 0;
868 u32 reg_gsr;
869 u64 mc_ram_addr = mc_get_dram_addr();
870 size_t mc_ram_size = mc_get_dram_block_size();
871
Alexander Grafb7b84102016-11-17 01:02:57 +0100872 if (!mc_dpl_addr)
873 return -1;
874
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530875 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
876 if (error != 0)
877 return error;
878
879 /*
880 * Tell the MC to deploy the DPL:
881 */
882 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
883 printf("fsl-mc: Deploying data path layout ... ");
884 error = wait_for_mc(false, &reg_gsr);
885
886 if (!error)
887 mc_dpl_applied = 0;
888
889 return error;
890}
891
J. German Riverab940ca62014-06-23 15:15:55 -0700892int get_mc_boot_status(void)
893{
894 return mc_boot_status;
895}
896
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530897#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
898int get_aiop_apply_status(void)
899{
900 return mc_aiop_applied;
901}
902#endif
903
904int get_dpl_apply_status(void)
905{
906 return mc_dpl_applied;
907}
908
Mian Yousaf Kaukab7e968042018-12-18 14:01:17 +0100909int is_lazy_dpl_addr_valid(void)
910{
911 return !!mc_lazy_dpl_addr;
912}
913
Priyanka Jain033c5382017-08-24 16:42:43 +0530914/*
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530915 * Return the MC address of private DRAM block.
Priyanka Jain033c5382017-08-24 16:42:43 +0530916 * As per MC design document, MC initial base address
917 * should be least significant 512MB address of MC private
918 * memory, i.e. address should point to end address masked
919 * with 512MB offset in private DRAM block.
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530920 */
921u64 mc_get_dram_addr(void)
922{
Priyanka Jain033c5382017-08-24 16:42:43 +0530923 size_t mc_ram_size = mc_get_dram_block_size();
924
Prabhakar Kushwaha87519a92018-08-27 12:58:52 +0530925 if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) {
926 mc_memset_resv_ram = 1;
927 memset((void *)gd->arch.resv_ram, 0, mc_ram_size);
928 }
929
Priyanka Jain033c5382017-08-24 16:42:43 +0530930 return (gd->arch.resv_ram + mc_ram_size - 1) &
931 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530932}
933
J. German Riverab940ca62014-06-23 15:15:55 -0700934/**
935 * Return the actual size of the MC private DRAM block.
J. German Riverab940ca62014-06-23 15:15:55 -0700936 */
937unsigned long mc_get_dram_block_size(void)
938{
J. German Rivera125e2bc2015-03-20 19:28:18 -0700939 unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
940
Simon Glass00caae62017-08-03 12:22:12 -0600941 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700942
943 if (dram_block_size_env_var) {
944 dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
Prabhakar Kushwahaf53e12d2017-11-09 14:45:41 +0530945 16);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700946
947 if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
948 printf("fsl-mc: WARNING: Invalid value for \'"
949 MC_MEM_SIZE_ENV_VAR
950 "\' environment variable: %lu\n",
951 dram_block_size);
952
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530953 dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700954 }
955 }
956
957 return dram_block_size;
J. German Riverab940ca62014-06-23 15:15:55 -0700958}
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700959
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530960int fsl_mc_ldpaa_init(bd_t *bis)
961{
Prabhakar Kushwahac919ab92015-11-04 12:26:00 +0530962 int i;
963
964 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
Pankaj Bansal1ed19a12018-10-10 14:08:33 +0530965 if (wriop_is_enabled_dpmac(i) == 1)
Prabhakar Kushwahac919ab92015-11-04 12:26:00 +0530966 ldpaa_eth_init(i, wriop_get_enet_if(i));
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530967 return 0;
968}
969
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530970static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
971{
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530972 int error;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530973 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530974
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530975 error = dprc_get_api_version(mc_io, 0,
976 &major_ver,
977 &minor_ver);
978 if (error < 0) {
979 printf("dprc_get_api_version() failed: %d\n", error);
980 return error;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530981 }
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530982
983 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
984 minor_ver < DPRC_VER_MINOR)) {
985 printf("DPRC version mismatch found %u.%u,",
986 major_ver, minor_ver);
987 printf("supported version is %u.%u\n",
988 DPRC_VER_MAJOR, DPRC_VER_MINOR);
989 }
990
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530991 return error;
992}
993
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530994static int dpio_init(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700995{
996 struct qbman_swp_desc p_des;
997 struct dpio_attr attr;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530998 struct dpio_cfg dpio_cfg;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700999 int err = 0;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301000 uint16_t major_ver, minor_ver;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001001
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301002 dflt_dpio = (struct fsl_dpio_obj *)calloc(
1003 sizeof(struct fsl_dpio_obj), 1);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001004 if (!dflt_dpio) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301005 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301006 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301007 goto err_calloc;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001008 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301009 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
1010 dpio_cfg.num_priorities = 8;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001011
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301012 err = dpio_create(dflt_mc_io,
1013 dflt_dprc_handle,
1014 MC_CMD_NO_FLAGS,
1015 &dpio_cfg,
1016 &dflt_dpio->dpio_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301017 if (err < 0) {
1018 printf("dpio_create() failed: %d\n", err);
1019 err = -ENODEV;
1020 goto err_create;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001021 }
1022
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301023 err = dpio_get_api_version(dflt_mc_io, 0,
1024 &major_ver,
1025 &minor_ver);
1026 if (err < 0) {
1027 printf("dpio_get_api_version() failed: %d\n", err);
1028 goto err_get_api_ver;
1029 }
1030
1031 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
1032 minor_ver < DPIO_VER_MINOR)) {
1033 printf("DPRC version mismatch found %u.%u,",
1034 major_ver,
1035 minor_ver);
1036 }
1037
1038 err = dpio_open(dflt_mc_io,
1039 MC_CMD_NO_FLAGS,
1040 dflt_dpio->dpio_id,
1041 &dflt_dpio->dpio_handle);
1042 if (err) {
1043 printf("dpio_open() failed\n");
1044 goto err_open;
1045 }
1046
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301047 memset(&attr, 0, sizeof(struct dpio_attr));
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +05301048 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301049 dflt_dpio->dpio_handle, &attr);
1050 if (err < 0) {
1051 printf("dpio_get_attributes() failed: %d\n", err);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001052 goto err_get_attr;
1053 }
1054
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301055 if (dflt_dpio->dpio_id != attr.id) {
1056 printf("dnpi object id and attribute id are not same\n");
1057 goto err_attr_not_same;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301058 }
1059
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301060#ifdef DEBUG
1061 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1062#endif
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301063 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1064 if (err < 0) {
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001065 printf("dpio_enable() failed %d\n", err);
1066 goto err_get_enable;
1067 }
Prabhakar Kushwaha1f1c25c2015-07-02 11:28:59 +05301068 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
1069 attr.qbman_portal_ce_offset,
1070 attr.qbman_portal_ci_offset,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001071 attr.qbman_portal_id,
1072 attr.num_priorities);
1073
Prabhakar Kushwaha1f1c25c2015-07-02 11:28:59 +05301074 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1075 + attr.qbman_portal_ce_offset);
1076 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1077 + attr.qbman_portal_ci_offset);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001078
1079 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
1080 if (dflt_dpio->sw_portal == NULL) {
1081 printf("qbman_swp_init() failed\n");
1082 goto err_get_swp_init;
1083 }
1084 return 0;
1085
1086err_get_swp_init:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301087 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001088err_get_enable:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301089err_get_attr:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301090err_attr_not_same:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301091 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301092err_open:
1093err_get_api_ver:
1094 dpio_destroy(dflt_mc_io,
1095 dflt_dprc_handle,
1096 MC_CMD_NO_FLAGS,
1097 dflt_dpio->dpio_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301098err_create:
Prabhakar Kushwahacd7b3fb2016-03-18 16:15:29 +05301099 free(dflt_dpio);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301100err_calloc:
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001101 return err;
1102}
1103
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301104static int dpio_exit(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001105{
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301106 int err;
1107
1108 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1109 if (err < 0) {
1110 printf("dpio_disable() failed: %d\n", err);
1111 goto err;
1112 }
1113
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301114 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1115 if (err < 0) {
1116 printf("dpio_close() failed: %d\n", err);
1117 goto err;
1118 }
1119
1120 err = dpio_destroy(dflt_mc_io,
1121 dflt_dprc_handle,
1122 MC_CMD_NO_FLAGS,
1123 dflt_dpio->dpio_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301124 if (err < 0) {
1125 printf("dpio_destroy() failed: %d\n", err);
1126 goto err;
1127 }
1128
1129#ifdef DEBUG
1130 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1131#endif
1132
1133 if (dflt_dpio)
1134 free(dflt_dpio);
1135
1136 return 0;
1137err:
1138 return err;
1139}
1140
1141static int dprc_init(void)
1142{
1143 int err, child_portal_id, container_id;
1144 struct dprc_cfg cfg;
1145 uint64_t mc_portal_offset;
1146
1147 /* Open root container */
1148 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1149 if (err < 0) {
1150 printf("dprc_get_container_id(): Root failed: %d\n", err);
1151 goto err_root_container_id;
1152 }
1153
1154#ifdef DEBUG
1155 printf("Root container id = %d\n", container_id);
1156#endif
1157 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1158 &root_dprc_handle);
1159 if (err < 0) {
1160 printf("dprc_open(): Root Container failed: %d\n", err);
1161 goto err_root_open;
1162 }
1163
1164 if (!root_dprc_handle) {
1165 printf("dprc_open(): Root Container Handle is not valid\n");
1166 goto err_root_open;
1167 }
1168
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301169 err = dprc_version_check(root_mc_io, root_dprc_handle);
1170 if (err < 0) {
1171 printf("dprc_version_check() failed: %d\n", err);
1172 goto err_root_open;
1173 }
1174
Prabhakar Kushwaha5373b202016-01-20 12:04:19 +05301175 memset(&cfg, 0, sizeof(struct dprc_cfg));
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301176 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1177 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1178 DPRC_CFG_OPT_ALLOC_ALLOWED;
1179 cfg.icid = DPRC_GET_ICID_FROM_POOL;
Prabhakar Kushwaha335b1932015-12-24 15:33:49 +05301180 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301181 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1182 root_dprc_handle,
1183 &cfg,
1184 &child_dprc_id,
1185 &mc_portal_offset);
1186 if (err < 0) {
1187 printf("dprc_create_container() failed: %d\n", err);
1188 goto err_create;
1189 }
1190
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301191 dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301192 if (!dflt_mc_io) {
1193 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301194 printf(" No memory: calloc() failed\n");
1195 goto err_calloc;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301196 }
1197
1198 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1199 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301200
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301201#ifdef DEBUG
1202 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1203 child_dprc_id, dflt_mc_io->mmio_regs);
1204#endif
1205
1206 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1207 &dflt_dprc_handle);
1208 if (err < 0) {
1209 printf("dprc_open(): Child container failed: %d\n", err);
1210 goto err_child_open;
1211 }
1212
1213 if (!dflt_dprc_handle) {
1214 printf("dprc_open(): Child container Handle is not valid\n");
1215 goto err_child_open;
1216 }
1217
1218 return 0;
1219err_child_open:
1220 free(dflt_mc_io);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301221err_calloc:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301222 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1223 root_dprc_handle, child_dprc_id);
1224err_create:
1225 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1226err_root_open:
1227err_root_container_id:
1228 return err;
1229}
1230
1231static int dprc_exit(void)
1232{
1233 int err;
1234
1235 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1236 if (err < 0) {
1237 printf("dprc_close(): Child failed: %d\n", err);
1238 goto err;
1239 }
1240
1241 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1242 root_dprc_handle, child_dprc_id);
1243 if (err < 0) {
1244 printf("dprc_destroy_container() failed: %d\n", err);
1245 goto err;
1246 }
1247
1248 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1249 if (err < 0) {
1250 printf("dprc_close(): Root failed: %d\n", err);
1251 goto err;
1252 }
1253
1254 if (dflt_mc_io)
1255 free(dflt_mc_io);
1256
1257 if (root_mc_io)
1258 free(root_mc_io);
1259
1260 return 0;
1261
1262err:
1263 return err;
1264}
1265
1266static int dpbp_init(void)
1267{
1268 int err;
1269 struct dpbp_attr dpbp_attr;
1270 struct dpbp_cfg dpbp_cfg;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301271 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301272
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301273 dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
1274 sizeof(struct fsl_dpbp_obj), 1);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001275 if (!dflt_dpbp) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301276 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301277 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301278 goto err_calloc;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001279 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301280
1281 dpbp_cfg.options = 512;
1282
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301283 err = dpbp_create(dflt_mc_io,
1284 dflt_dprc_handle,
1285 MC_CMD_NO_FLAGS,
1286 &dpbp_cfg,
1287 &dflt_dpbp->dpbp_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301288
1289 if (err < 0) {
1290 err = -ENODEV;
1291 printf("dpbp_create() failed: %d\n", err);
1292 goto err_create;
1293 }
1294
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301295 err = dpbp_get_api_version(dflt_mc_io, 0,
1296 &major_ver,
1297 &minor_ver);
1298 if (err < 0) {
1299 printf("dpbp_get_api_version() failed: %d\n", err);
1300 goto err_get_api_ver;
1301 }
1302
1303 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1304 minor_ver < DPBP_VER_MINOR)) {
1305 printf("DPBP version mismatch found %u.%u,",
1306 major_ver, minor_ver);
1307 printf("supported version is %u.%u\n",
1308 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1309 }
1310
1311 err = dpbp_open(dflt_mc_io,
1312 MC_CMD_NO_FLAGS,
1313 dflt_dpbp->dpbp_id,
1314 &dflt_dpbp->dpbp_handle);
1315 if (err) {
1316 printf("dpbp_open() failed\n");
1317 goto err_open;
1318 }
1319
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301320 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1321 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1322 dflt_dpbp->dpbp_handle,
1323 &dpbp_attr);
1324 if (err < 0) {
1325 printf("dpbp_get_attributes() failed: %d\n", err);
1326 goto err_get_attr;
1327 }
1328
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301329 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1330 printf("dpbp object id and attribute id are not same\n");
1331 goto err_attr_not_same;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301332 }
1333
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301334#ifdef DEBUG
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301335 printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301336#endif
1337
1338 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1339 if (err < 0) {
1340 printf("dpbp_close() failed: %d\n", err);
1341 goto err_close;
1342 }
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001343
1344 return 0;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301345
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301346err_get_attr:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301347err_attr_not_same:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301348 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301349 dpbp_destroy(dflt_mc_io,
1350 dflt_dprc_handle,
1351 MC_CMD_NO_FLAGS,
1352 dflt_dpbp->dpbp_id);
1353err_get_api_ver:
1354err_close:
1355err_open:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301356err_create:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301357 free(dflt_dpbp);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301358err_calloc:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301359 return err;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001360}
1361
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301362static int dpbp_exit(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001363{
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301364 int err;
1365
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301366 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1367 dflt_dpbp->dpbp_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301368 if (err < 0) {
1369 printf("dpbp_destroy() failed: %d\n", err);
1370 goto err;
1371 }
1372
1373#ifdef DEBUG
1374 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1375#endif
1376
1377 if (dflt_dpbp)
1378 free(dflt_dpbp);
1379 return 0;
1380
1381err:
1382 return err;
1383}
1384
1385static int dpni_init(void)
1386{
1387 int err;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301388 uint8_t cfg_buf[256] = {0};
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301389 struct dpni_cfg dpni_cfg;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301390 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301391
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301392 dflt_dpni = (struct fsl_dpni_obj *)calloc(
1393 sizeof(struct fsl_dpni_obj), 1);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301394 if (!dflt_dpni) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301395 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301396 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301397 goto err_calloc;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301398 }
1399
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301400 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1401 err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
Prabhakar Kushwaha879a59a2015-12-24 15:33:01 +05301402 if (err < 0) {
1403 err = -ENODEV;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301404 printf("dpni_prepare_cfg() failed: %d\n", err);
1405 goto err_prepare_cfg;
Prabhakar Kushwaha879a59a2015-12-24 15:33:01 +05301406 }
1407
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301408 err = dpni_create(dflt_mc_io,
1409 dflt_dprc_handle,
1410 MC_CMD_NO_FLAGS,
1411 &dpni_cfg,
1412 &dflt_dpni->dpni_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301413 if (err < 0) {
1414 err = -ENODEV;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301415 printf("dpni create() failed: %d\n", err);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301416 goto err_create;
1417 }
1418
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301419 err = dpni_get_api_version(dflt_mc_io, 0,
1420 &major_ver,
1421 &minor_ver);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301422 if (err < 0) {
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301423 printf("dpni_get_api_version() failed: %d\n", err);
1424 goto err_get_version;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301425 }
1426
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301427 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1428 minor_ver < DPNI_VER_MINOR)) {
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301429 printf("DPNI version mismatch found %u.%u,",
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301430 major_ver, minor_ver);
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301431 printf("supported version is %u.%u\n",
1432 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1433 }
1434
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301435 err = dpni_open(dflt_mc_io,
1436 MC_CMD_NO_FLAGS,
1437 dflt_dpni->dpni_id,
1438 &dflt_dpni->dpni_handle);
1439 if (err) {
1440 printf("dpni_open() failed\n");
1441 goto err_open;
1442 }
1443
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301444#ifdef DEBUG
1445 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1446#endif
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301447 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1448 if (err < 0) {
1449 printf("dpni_close() failed: %d\n", err);
1450 goto err_close;
1451 }
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001452
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301453 return 0;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301454
1455err_close:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301456 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301457err_open:
1458err_get_version:
1459 dpni_destroy(dflt_mc_io,
1460 dflt_dprc_handle,
1461 MC_CMD_NO_FLAGS,
1462 dflt_dpni->dpni_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301463err_create:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301464err_prepare_cfg:
Prabhakar Kushwaha879a59a2015-12-24 15:33:01 +05301465 free(dflt_dpni);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301466err_calloc:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301467 return err;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001468}
1469
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301470static int dpni_exit(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001471{
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301472 int err;
1473
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301474 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1475 dflt_dpni->dpni_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301476 if (err < 0) {
1477 printf("dpni_destroy() failed: %d\n", err);
1478 goto err;
1479 }
1480
1481#ifdef DEBUG
1482 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1483#endif
1484
1485 if (dflt_dpni)
1486 free(dflt_dpni);
1487 return 0;
1488
1489err:
1490 return err;
1491}
1492
Florinel Iordache1990cc72019-11-19 10:28:17 +00001493static bool is_dpsparser_supported(void)
1494{
1495 /* dpsparser support was first introduced in MC version: 10.12.0 */
1496 if (mc_ver_info.major < 10)
1497 return false;
1498 if (mc_ver_info.major == 10)
1499 return (mc_ver_info.minor >= 12);
1500 return true;
1501}
1502
1503static int dpsparser_version_check(struct fsl_mc_io *mc_io)
1504{
1505 int error;
1506 u16 major_ver, minor_ver;
1507
1508 if (!is_dpsparser_supported())
1509 return 0;
1510
1511 error = dpsparser_get_api_version(mc_io, 0,
1512 &major_ver,
1513 &minor_ver);
1514 if (error < 0) {
1515 printf("dpsparser_get_api_version() failed: %d\n", error);
1516 return error;
1517 }
1518
1519 if (major_ver < DPSPARSER_VER_MAJOR || (major_ver ==
1520 DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) {
1521 printf("DPSPARSER version mismatch found %u.%u,",
1522 major_ver, minor_ver);
1523 printf("supported version is %u.%u\n",
1524 DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR);
1525 }
1526
1527 return error;
1528}
1529
1530static int dpsparser_init(void)
1531{
1532 int err = 0;
1533
1534 if (!is_dpsparser_supported())
1535 return 0;
1536
1537 err = dpsparser_create(dflt_mc_io,
1538 dflt_dprc_handle,
1539 MC_CMD_NO_FLAGS,
1540 &dpsparser_obj_id);
1541 if (err)
1542 printf("dpsparser_create() failed\n");
1543
1544 err = dpsparser_version_check(dflt_mc_io);
1545 if (err < 0) {
1546 printf("dpsparser_version_check() failed: %d\n", err);
1547 goto err_version_check;
1548 }
1549
1550 err = dpsparser_open(dflt_mc_io,
1551 MC_CMD_NO_FLAGS,
1552 &dpsparser_handle);
1553 if (err < 0) {
1554 printf("dpsparser_open() failed: %d\n", err);
1555 goto err_open;
1556 }
1557
1558 return err;
1559
1560err_open:
1561err_version_check:
1562 dpsparser_destroy(dflt_mc_io,
1563 dflt_dprc_handle,
1564 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1565
1566 return err;
1567}
1568
1569#ifdef DPSPARSER_DESTROY
1570/* TODO: refactoring needed in the future to allow DPSPARSER object destroy
1571 * Workaround: DO NOT destroy DPSPARSER object because it needs to be available
1572 * on Apply DPL
1573 */
1574static int dpsparser_exit(void)
1575{
1576 int err;
1577
1578 if (!is_dpsparser_supported())
1579 return 0;
1580
1581 dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle);
1582 if (err < 0) {
1583 printf("dpsparser_close() failed: %d\n", err);
1584 goto err;
1585 }
1586
1587 err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle,
1588 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1589 if (err < 0) {
1590 printf("dpsparser_destroy() failed: %d\n", err);
1591 goto err;
1592 }
1593 return 0;
1594
1595err:
1596 return err;
1597}
1598#endif
1599
1600int mc_apply_spb(u64 mc_spb_addr)
1601{
1602 int err = 0;
1603 u16 error, err_arr_size;
1604 u64 mc_spb_offset;
1605 u32 spb_size;
1606 struct sp_blob_header *sp_blob;
1607 u64 mc_ram_addr = mc_get_dram_addr();
1608
1609 if (!is_dpsparser_supported())
1610 return 0;
1611
1612 if (!mc_spb_addr) {
1613 printf("fsl-mc: Invalid Blob address\n");
1614 return -1;
1615 }
1616
1617#ifdef CONFIG_MC_DRAM_SPB_OFFSET
1618 mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET;
1619#else
1620#error "CONFIG_MC_DRAM_SPB_OFFSET not defined"
1621#endif
1622
1623 // Read blob header and get size of SPB blob
1624 sp_blob = (struct sp_blob_header *)mc_spb_addr;
1625 spb_size = le32_to_cpu(sp_blob->length);
1626 if (spb_size > CONFIG_MC_SPB_MAX_SIZE) {
1627 printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n",
1628 spb_size);
1629 return -EINVAL;
1630 }
1631
1632 mc_copy_image("MC SP Blob", mc_spb_addr, spb_size,
1633 mc_ram_addr + mc_spb_offset);
1634
1635 //Invoke MC command to apply SPB blob
1636 printf("fsl-mc: Applying soft parser blob... ");
1637 err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle,
1638 mc_spb_offset, &error);
1639 if (err)
1640 return err;
1641
1642 if (error == 0) {
1643 printf("SUCCESS\n");
1644 } else {
1645 printf("FAILED with error code = %d:\n", error);
1646 err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb);
1647
1648 if (error > 0 && error < err_arr_size)
1649 printf(mc_err_msg_apply_spb[error]);
1650 else
1651 printf(MC_ERROR_MSG_SPB_UNKNOWN);
1652 }
1653
1654 return err;
1655}
1656
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301657static int mc_init_object(void)
1658{
1659 int err = 0;
1660
1661 err = dprc_init();
1662 if (err < 0) {
1663 printf("dprc_init() failed: %d\n", err);
1664 goto err;
1665 }
1666
1667 err = dpbp_init();
1668 if (err < 0) {
1669 printf("dpbp_init() failed: %d\n", err);
1670 goto err;
1671 }
1672
1673 err = dpio_init();
1674 if (err < 0) {
1675 printf("dpio_init() failed: %d\n", err);
1676 goto err;
1677 }
1678
1679 err = dpni_init();
1680 if (err < 0) {
1681 printf("dpni_init() failed: %d\n", err);
1682 goto err;
1683 }
1684
Florinel Iordache1990cc72019-11-19 10:28:17 +00001685 err = dpsparser_init();
1686 if (err < 0) {
1687 printf("dpsparser_init() failed: %d\n", err);
1688 goto err;
1689 }
1690
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301691 return 0;
1692err:
1693 return err;
1694}
1695
1696int fsl_mc_ldpaa_exit(bd_t *bd)
1697{
1698 int err = 0;
Yogesh Gaur42e81792017-04-27 10:14:16 +05301699 bool is_dpl_apply_status = false;
Santan Kumar06651b92017-06-29 11:19:34 +05301700 bool mc_boot_status = false;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301701
Alexander Grafb7b84102016-11-17 01:02:57 +01001702 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
Yogesh Gaurf9747a52018-01-16 10:08:24 +05301703 err = mc_apply_dpl(mc_lazy_dpl_addr);
1704 if (!err)
1705 fdt_fixup_board_enet(working_fdt);
Alexander Grafb7b84102016-11-17 01:02:57 +01001706 mc_lazy_dpl_addr = 0;
1707 }
1708
Santan Kumar06651b92017-06-29 11:19:34 +05301709 if (!get_mc_boot_status())
1710 mc_boot_status = true;
1711
Prabhakar Kushwaha6dedced2016-03-21 14:19:39 +05301712 /* MC is not loaded intentionally, So return success. */
Santan Kumar06651b92017-06-29 11:19:34 +05301713 if (bd && !mc_boot_status)
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301714 return 0;
1715
Yogesh Gaur42e81792017-04-27 10:14:16 +05301716 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1717 if (!get_dpl_apply_status())
1718 is_dpl_apply_status = true;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301719
Yogesh Gaur42e81792017-04-27 10:14:16 +05301720 /*
1721 * For case MC is loaded but DPL is not deployed, return success and
1722 * print message on console. Else FDT fix-up code execution hanged.
1723 */
Santan Kumar06651b92017-06-29 11:19:34 +05301724 if (bd && mc_boot_status && !is_dpl_apply_status) {
Yogesh Gaur42e81792017-04-27 10:14:16 +05301725 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
Yogesh Gaur73fa2062017-11-28 10:11:14 +05301726 goto mc_obj_cleanup;
Yogesh Gaur42e81792017-04-27 10:14:16 +05301727 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301728
Santan Kumar06651b92017-06-29 11:19:34 +05301729 if (bd && mc_boot_status && is_dpl_apply_status)
1730 return 0;
1731
Yogesh Gaur73fa2062017-11-28 10:11:14 +05301732mc_obj_cleanup:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301733 err = dpbp_exit();
1734 if (err < 0) {
Prabhakar Kushwahaa2a4dc52016-01-20 12:04:37 +05301735 printf("dpbp_exit() failed: %d\n", err);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301736 goto err;
1737 }
1738
1739 err = dpio_exit();
1740 if (err < 0) {
1741 printf("dpio_exit() failed: %d\n", err);
1742 goto err;
1743 }
1744
1745 err = dpni_exit();
1746 if (err < 0) {
1747 printf("dpni_exit() failed: %d\n", err);
1748 goto err;
1749 }
1750
1751 err = dprc_exit();
1752 if (err < 0) {
1753 printf("dprc_exit() failed: %d\n", err);
1754 goto err;
1755 }
1756
1757 return 0;
1758err:
1759 return err;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001760}
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301761
1762static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1763{
1764 int err = 0;
1765 if (argc < 3)
1766 goto usage;
1767
1768 switch (argv[1][0]) {
1769 case 's': {
1770 char sub_cmd;
Prabhakar Kushwaha44937212015-11-09 16:42:07 +05301771 u64 mc_fw_addr, mc_dpc_addr;
1772#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1773 u64 aiop_fw_addr;
1774#endif
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301775
1776 sub_cmd = argv[2][0];
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301777
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301778 switch (sub_cmd) {
1779 case 'm':
1780 if (argc < 5)
1781 goto usage;
1782
1783 if (get_mc_boot_status() == 0) {
1784 printf("fsl-mc: MC is already booted");
1785 printf("\n");
1786 return err;
1787 }
1788 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1789 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1790 16);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301791
1792 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1793 err = mc_init_object();
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301794 break;
1795
1796#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1797 case 'a':
1798 if (argc < 4)
1799 goto usage;
1800 if (get_aiop_apply_status() == 0) {
1801 printf("fsl-mc: AIOP FW is already");
1802 printf(" applied\n");
1803 return err;
1804 }
1805
1806 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1807 16);
1808
York Sun3c1d2182016-04-04 11:41:26 -07001809 /* if SoC doesn't have AIOP, err = -ENODEV */
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301810 err = load_mc_aiop_img(aiop_fw_addr);
1811 if (!err)
1812 printf("fsl-mc: AIOP FW applied\n");
1813 break;
1814#endif
1815 default:
1816 printf("Invalid option: %s\n", argv[2]);
1817 goto usage;
1818
1819 break;
1820 }
1821 }
1822 break;
1823
Florinel Iordache1990cc72019-11-19 10:28:17 +00001824 case 'l': {
1825 /* lazyapply */
1826 u64 mc_dpl_addr;
1827
1828 if (argc < 4)
1829 goto usage;
1830
1831 if (get_dpl_apply_status() == 0) {
1832 printf("fsl-mc: DPL already applied\n");
1833 return err;
1834 }
1835
1836 mc_dpl_addr = simple_strtoull(argv[3], NULL, 16);
1837
1838 if (get_mc_boot_status() != 0) {
1839 printf("fsl-mc: Deploying data path layout ..");
1840 printf("ERROR (MC is not booted)\n");
1841 return -ENODEV;
1842 }
1843
1844 /*
1845 * We will do the actual dpaa exit and dpl apply
1846 * later from announce_and_cleanup().
1847 */
1848 mc_lazy_dpl_addr = mc_dpl_addr;
1849 break;
1850 }
1851
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301852 case 'a': {
Florinel Iordache1990cc72019-11-19 10:28:17 +00001853 /* apply */
1854 char sub_cmd;
1855 u64 mc_apply_addr;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301856
Florinel Iordache1990cc72019-11-19 10:28:17 +00001857 if (argc < 4)
1858 goto usage;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301859
Florinel Iordache1990cc72019-11-19 10:28:17 +00001860 sub_cmd = argv[2][0];
1861
1862 switch (sub_cmd) {
1863 case 'd':
1864 case 'D':
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301865 if (get_dpl_apply_status() == 0) {
1866 printf("fsl-mc: DPL already applied\n");
1867 return err;
1868 }
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301869 if (get_mc_boot_status() != 0) {
1870 printf("fsl-mc: Deploying data path layout ..");
1871 printf("ERROR (MC is not booted)\n");
1872 return -ENODEV;
1873 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301874
Florinel Iordache1990cc72019-11-19 10:28:17 +00001875 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1876
1877 /* The user wants DPL applied now */
1878 if (!fsl_mc_ldpaa_exit(NULL))
1879 err = mc_apply_dpl(mc_apply_addr);
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301880 break;
Florinel Iordache1990cc72019-11-19 10:28:17 +00001881
1882 case 's':
1883 if (!is_dpsparser_supported()) {
1884 printf("fsl-mc: apply spb command .. ");
1885 printf("ERROR: requires at least MC 10.12.0\n");
1886 return err;
1887 }
1888 if (get_mc_boot_status() != 0) {
1889 printf("fsl-mc: Deploying Soft Parser Blob...");
1890 printf("ERROR (MC is not booted)\n");
1891 return err;
1892 }
1893
1894 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1895
1896 /* Apply spb (Soft Parser Blob) */
1897 err = mc_apply_spb(mc_apply_addr);
1898 break;
1899
1900 default:
1901 printf("Invalid option: %s\n", argv[2]);
1902 goto usage;
1903 }
1904 break;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301905 }
1906 default:
1907 printf("Invalid option: %s\n", argv[1]);
1908 goto usage;
1909 break;
1910 }
1911 return err;
1912 usage:
1913 return CMD_RET_USAGE;
1914}
1915
1916U_BOOT_CMD(
1917 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1918 "DPAA2 command to manage Management Complex (MC)",
1919 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1920 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
Alexander Grafb7b84102016-11-17 01:02:57 +01001921 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
Florinel Iordache1990cc72019-11-19 10:28:17 +00001922 "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n"
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301923 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1924);
Bogdan Purcareata33a89912017-05-24 16:40:21 +00001925
1926void mc_env_boot(void)
1927{
1928#if defined(CONFIG_FSL_MC_ENET)
1929 char *mc_boot_env_var;
1930 /* The MC may only be initialized in the reset PHY function
1931 * because otherwise U-Boot has not yet set up all the MAC
1932 * address info properly. Without MAC addresses, the MC code
1933 * can not properly initialize the DPC.
1934 */
Simon Glass00caae62017-08-03 12:22:12 -06001935 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
Bogdan Purcareata33a89912017-05-24 16:40:21 +00001936 if (mc_boot_env_var)
1937 run_command_list(mc_boot_env_var, -1, 0);
1938#endif /* CONFIG_FSL_MC_ENET */
1939}