blob: 8ff43a91c7620c15cc3b6d7d536fdbc51b572da7 [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>
Masahiro Yamada84b8bf62016-01-24 23:27:48 +090011#include <linux/bug.h>
J. German Riverab940ca62014-06-23 15:15:55 -070012#include <asm/io.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +000014#include <net.h>
Stuart Yoder21c69872015-07-02 11:29:03 +053015#include <fdt_support.h>
J. German Rivera7b3bd9a2015-01-06 13:19:02 -080016#include <fsl-mc/fsl_mc.h>
17#include <fsl-mc/fsl_mc_sys.h>
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070018#include <fsl-mc/fsl_mc_private.h>
J. German Rivera7b3bd9a2015-01-06 13:19:02 -080019#include <fsl-mc/fsl_dpmng.h>
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070020#include <fsl-mc/fsl_dprc.h>
21#include <fsl-mc/fsl_dpio.h>
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +053022#include <fsl-mc/fsl_dpni.h>
Florinel Iordache1990cc72019-11-19 10:28:17 +000023#include <fsl-mc/fsl_dpsparser.h>
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070024#include <fsl-mc/fsl_qbman_portal.h>
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +053025#include <fsl-mc/ldpaa_wriop.h>
J. German Riverab940ca62014-06-23 15:15:55 -070026
J. German Rivera125e2bc2015-03-20 19:28:18 -070027#define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
28#define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
29#define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
30
31#define MC_MEM_SIZE_ENV_VAR "mcmemsize"
32#define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
Bogdan Purcareata33a89912017-05-24 16:40:21 +000033#define MC_BOOT_ENV_VAR "mcinitcmd"
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +053034#define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024)
J. German Rivera125e2bc2015-03-20 19:28:18 -070035
J. German Riverab940ca62014-06-23 15:15:55 -070036DECLARE_GLOBAL_DATA_PTR;
Prabhakar Kushwaha87519a92018-08-27 12:58:52 +053037static int mc_memset_resv_ram;
Florinel Iordache1990cc72019-11-19 10:28:17 +000038static struct mc_version mc_ver_info;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +053039static int mc_boot_status = -1;
40static int mc_dpl_applied = -1;
41#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
42static int mc_aiop_applied = -1;
43#endif
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +053044struct fsl_mc_io *root_mc_io = NULL;
45struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
46uint16_t root_dprc_handle = 0;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070047uint16_t dflt_dprc_handle = 0;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +053048int child_dprc_id;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -070049struct fsl_dpbp_obj *dflt_dpbp = NULL;
50struct fsl_dpio_obj *dflt_dpio = NULL;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +053051struct fsl_dpni_obj *dflt_dpni = NULL;
Alexander Grafb7b84102016-11-17 01:02:57 +010052static u64 mc_lazy_dpl_addr;
Florinel Iordache1990cc72019-11-19 10:28:17 +000053static u32 dpsparser_obj_id;
54static u16 dpsparser_handle;
55static char *mc_err_msg_apply_spb[] = MC_ERROR_MSG_APPLY_SPB;
J. German Riverab940ca62014-06-23 15:15:55 -070056
J. German Rivera125e2bc2015-03-20 19:28:18 -070057#ifdef DEBUG
58void dump_ram_words(const char *title, void *addr)
59{
60 int i;
61 uint32_t *words = addr;
62
63 printf("Dumping beginning of %s (%p):\n", title, addr);
64 for (i = 0; i < 16; i++)
65 printf("%#x ", words[i]);
66
67 printf("\n");
68}
69
70void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
71{
72 printf("MC CCSR registers:\n"
73 "reg_gcr1 %#x\n"
74 "reg_gsr %#x\n"
75 "reg_sicbalr %#x\n"
76 "reg_sicbahr %#x\n"
77 "reg_sicapr %#x\n"
78 "reg_mcfbalr %#x\n"
79 "reg_mcfbahr %#x\n"
80 "reg_mcfapr %#x\n"
81 "reg_psr %#x\n",
82 mc_ccsr_regs->reg_gcr1,
83 mc_ccsr_regs->reg_gsr,
84 mc_ccsr_regs->reg_sicbalr,
85 mc_ccsr_regs->reg_sicbahr,
86 mc_ccsr_regs->reg_sicapr,
87 mc_ccsr_regs->reg_mcfbalr,
88 mc_ccsr_regs->reg_mcfbahr,
89 mc_ccsr_regs->reg_mcfapr,
90 mc_ccsr_regs->reg_psr);
91}
92#else
93
94#define dump_ram_words(title, addr)
95#define dump_mc_ccsr_regs(mc_ccsr_regs)
96
97#endif /* DEBUG */
98
J. German Riverab940ca62014-06-23 15:15:55 -070099/**
100 * Copying MC firmware or DPL image to DDR
101 */
102static int mc_copy_image(const char *title,
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800103 u64 image_addr, u32 image_size, u64 mc_ram_addr)
J. German Riverab940ca62014-06-23 15:15:55 -0700104{
105 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
106 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700107 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
J. German Riverab940ca62014-06-23 15:15:55 -0700108 return 0;
109}
110
Florinel Iordache1990cc72019-11-19 10:28:17 +0000111#ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
J. German Riverab940ca62014-06-23 15:15:55 -0700112/**
113 * MC firmware FIT image parser checks if the image is in FIT
114 * format, verifies integrity of the image and calculates
115 * raw image address and size values.
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800116 * Returns 0 on success and a negative errno on error.
J. German Riverab940ca62014-06-23 15:15:55 -0700117 * task fail.
118 **/
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530119int parse_mc_firmware_fit_image(u64 mc_fw_addr,
120 const void **raw_image_addr,
J. German Riverab940ca62014-06-23 15:15:55 -0700121 size_t *raw_image_size)
122{
123 int format;
124 void *fit_hdr;
125 int node_offset;
126 const void *data;
127 size_t size;
128 const char *uname = "firmware";
129
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530130 fit_hdr = (void *)mc_fw_addr;
J. German Riverab940ca62014-06-23 15:15:55 -0700131
132 /* Check if Image is in FIT format */
133 format = genimg_get_format(fit_hdr);
134
135 if (format != IMAGE_FORMAT_FIT) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530136 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800137 return -EINVAL;
J. German Riverab940ca62014-06-23 15:15:55 -0700138 }
139
140 if (!fit_check_format(fit_hdr)) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530141 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800142 return -EINVAL;
J. German Riverab940ca62014-06-23 15:15:55 -0700143 }
144
145 node_offset = fit_image_get_node(fit_hdr, uname);
146
147 if (node_offset < 0) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530148 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800149 return -ENOENT;
J. German Riverab940ca62014-06-23 15:15:55 -0700150 }
151
152 /* Verify MC firmware image */
153 if (!(fit_image_verify(fit_hdr, node_offset))) {
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530154 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800155 return -EINVAL;
J. German Riverab940ca62014-06-23 15:15:55 -0700156 }
157
158 /* Get address and size of raw image */
159 fit_image_get_data(fit_hdr, node_offset, &data, &size);
160
161 *raw_image_addr = data;
162 *raw_image_size = size;
163
164 return 0;
165}
J. German Rivera125e2bc2015-03-20 19:28:18 -0700166#endif
167
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000168#define MC_DT_INCREASE_SIZE 64
169
170enum mc_fixup_type {
171 MC_FIXUP_DPL,
172 MC_FIXUP_DPC
173};
174
175static int mc_fixup_mac_addr(void *blob, int nodeoffset,
176 const char *propname, struct eth_device *eth_dev,
177 enum mc_fixup_type type)
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000178{
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000179 int err = 0, len = 0, size, i;
180 unsigned char env_enetaddr[ARP_HLEN];
181 unsigned int enetaddr_32[ARP_HLEN];
182 void *val = NULL;
183
184 switch (type) {
185 case MC_FIXUP_DPL:
186 /* DPL likes its addresses on 32 * ARP_HLEN bits */
187 for (i = 0; i < ARP_HLEN; i++)
188 enetaddr_32[i] = cpu_to_fdt32(eth_dev->enetaddr[i]);
189 val = enetaddr_32;
190 len = sizeof(enetaddr_32);
191 break;
192
193 case MC_FIXUP_DPC:
194 val = eth_dev->enetaddr;
195 len = ARP_HLEN;
196 break;
197 }
198
199 /* MAC address property present */
200 if (fdt_get_property(blob, nodeoffset, propname, NULL)) {
201 /* u-boot MAC addr randomly assigned - leave the present one */
Simon Glass35affd72017-08-03 12:22:14 -0600202 if (!eth_env_get_enetaddr_by_index("eth", eth_dev->index,
203 env_enetaddr))
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000204 return err;
205 } else {
206 size = MC_DT_INCREASE_SIZE + strlen(propname) + len;
207 /* make room for mac address property */
208 err = fdt_increase_size(blob, size);
209 if (err) {
210 printf("fdt_increase_size: err=%s\n",
211 fdt_strerror(err));
212 return err;
213 }
214 }
215
216 err = fdt_setprop(blob, nodeoffset, propname, val, len);
217 if (err) {
218 printf("fdt_setprop: err=%s\n", fdt_strerror(err));
219 return err;
220 }
221
222 return err;
223}
224
225#define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
226
227const char *dpl_get_connection_endpoint(void *blob, char *endpoint)
228{
229 int connoffset = fdt_path_offset(blob, "/connections"), off;
230 const char *s1, *s2;
231
232 for (off = fdt_first_subnode(blob, connoffset);
233 off >= 0;
234 off = fdt_next_subnode(blob, off)) {
235 s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL);
236 s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL);
237
238 if (!s1 || !s2)
239 continue;
240
241 if (strcmp(endpoint, s1) == 0)
242 return s2;
243
244 if (strcmp(endpoint, s2) == 0)
245 return s1;
246 }
247
248 return NULL;
249}
250
251static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id,
252 struct eth_device *eth_dev)
253{
254 int objoff = fdt_path_offset(blob, "/objects");
255 int dpmacoff = -1, dpnioff = -1;
256 const char *endpoint;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000257 char mac_name[10];
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000258 int err;
259
260 sprintf(mac_name, "dpmac@%d", dpmac_id);
261 dpmacoff = fdt_subnode_offset(blob, objoff, mac_name);
262 if (dpmacoff < 0)
263 /* dpmac not defined in DPL, so skip it. */
264 return 0;
265
266 err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev,
267 MC_FIXUP_DPL);
268 if (err) {
269 printf("Error fixing up dpmac mac_addr in DPL\n");
270 return err;
271 }
272
273 /* now we need to figure out if there is any
274 * DPNI connected to this MAC, so we walk the
275 * connection list
276 */
277 endpoint = dpl_get_connection_endpoint(blob, mac_name);
278 if (!is_dpni(endpoint))
279 return 0;
280
281 /* let's see if we can fixup the DPNI as well */
282 dpnioff = fdt_subnode_offset(blob, objoff, endpoint);
283 if (dpnioff < 0)
284 /* DPNI not defined in DPL in the objects area */
285 return 0;
286
287 return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev,
288 MC_FIXUP_DPL);
289}
290
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530291void fdt_fixup_mc_ddr(u64 *base, u64 *size)
292{
293 u64 mc_size = mc_get_dram_block_size();
294
295 if (mc_size < MC_DRAM_BLOCK_DEFAULT_SIZE) {
296 *base = mc_get_dram_addr() + mc_size;
297 *size = MC_DRAM_BLOCK_DEFAULT_SIZE - mc_size;
298 }
299}
300
Nipun Guptaa78df402018-08-20 16:01:14 +0530301void fdt_fsl_mc_fixup_iommu_map_entry(void *blob)
302{
303 u32 *prop;
304 u32 iommu_map[4];
305 int offset;
306 int lenp;
307
308 /* find fsl-mc node */
309 offset = fdt_path_offset(blob, "/soc/fsl-mc");
310 if (offset < 0)
311 offset = fdt_path_offset(blob, "/fsl-mc");
312 if (offset < 0) {
313 printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n",
314 __func__, offset);
315 return;
316 }
317
318 prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp);
319 if (!prop) {
320 debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n",
321 __func__);
322 return;
323 }
324
325 iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
326 iommu_map[1] = *++prop;
327 iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
328 iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END -
329 FSL_DPAA2_STREAM_ID_START + 1);
330
331 fdt_setprop_inplace(blob, offset, "iommu-map",
332 iommu_map, sizeof(iommu_map));
333}
334
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000335static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
336 struct eth_device *eth_dev)
337{
338 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
339 int err = 0;
340 char mac_name[10];
341 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000342
343 sprintf(mac_name, "mac@%d", dpmac_id);
344
345 /* node not found - create it */
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000346 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
347 if (noff < 0) {
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000348 err = fdt_increase_size(blob, 200);
349 if (err) {
350 printf("fdt_increase_size: err=%s\n",
351 fdt_strerror(err));
352 return err;
353 }
354
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000355 noff = fdt_add_subnode(blob, nodeoffset, mac_name);
356 if (noff < 0) {
357 printf("fdt_add_subnode: err=%s\n",
358 fdt_strerror(err));
359 return err;
360 }
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000361
362 /* add default property of fixed link */
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000363 err = fdt_appendprop_string(blob, noff,
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000364 "link_type", link_type_mode);
365 if (err) {
366 printf("fdt_appendprop_string: err=%s\n",
367 fdt_strerror(err));
368 return err;
369 }
370 }
371
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000372 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
373 MC_FIXUP_DPC);
374}
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000375
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000376static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
377{
378 int i, err = 0, ret = 0;
Pankaj Bansalc022ec02018-08-02 16:31:28 +0530379 char ethname[ETH_NAME_LEN];
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000380 struct eth_device *eth_dev;
381
382 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
383 /* port not enabled */
Pankaj Bansal1ed19a12018-10-10 14:08:33 +0530384 if (wriop_is_enabled_dpmac(i) != 1)
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000385 continue;
386
Pankaj Bansalc022ec02018-08-02 16:31:28 +0530387 snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
388 phy_interface_strings[wriop_get_enet_if(i)]);
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000389
390 eth_dev = eth_get_dev_by_name(ethname);
391 if (eth_dev == NULL)
392 continue;
393
394 switch (type) {
395 case MC_FIXUP_DPL:
396 err = mc_fixup_dpl_mac_addr(blob, i, eth_dev);
397 break;
398 case MC_FIXUP_DPC:
399 err = mc_fixup_dpc_mac_addr(blob, i, eth_dev);
400 break;
401 default:
402 break;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000403 }
404
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000405 if (err)
406 printf("fsl-mc: ERROR fixing mac address for %s\n",
407 ethname);
408 ret |= err;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000409 }
410
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000411 return ret;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000412}
413
Stuart Yoder21c69872015-07-02 11:29:03 +0530414static int mc_fixup_dpc(u64 dpc_addr)
415{
416 void *blob = (void *)dpc_addr;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000417 int nodeoffset, err = 0;
Stuart Yoder21c69872015-07-02 11:29:03 +0530418
419 /* delete any existing ICID pools */
420 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
421 if (fdt_del_node(blob, nodeoffset) < 0)
422 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
423
424 /* add a new pool */
425 nodeoffset = fdt_path_offset(blob, "/resources");
426 if (nodeoffset < 0) {
427 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
428 return -EINVAL;
429 }
430 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
431 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
432 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
433 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
434 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
435 "num",
436 FSL_DPAA2_STREAM_ID_END -
437 FSL_DPAA2_STREAM_ID_START + 1, 1);
438
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000439 /* fixup MAC addresses for dpmac ports */
440 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
441 if (nodeoffset < 0)
Ioana Ciocoi Radulescu2e9f1bf2019-02-26 15:50:07 +0000442 goto out;
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000443
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000444 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
Ioana Ciocoi Radulescu2e9f1bf2019-02-26 15:50:07 +0000445
446out:
Stuart Yoder21c69872015-07-02 11:29:03 +0530447 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
448
Bogdan Purcareata5707dfb2017-01-11 15:58:36 +0000449 return err;
Stuart Yoder21c69872015-07-02 11:29:03 +0530450}
451
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530452static 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 -0700453{
454 u64 mc_dpc_offset;
455#ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
456 int error;
457 void *dpc_fdt_hdr;
458 int dpc_size;
459#endif
460
461#ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
462 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
463 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
464
465 mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
466#else
467#error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
468#endif
469
470 /*
471 * Load the MC DPC blob in the MC private DRAM block:
472 */
473#ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
474 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
475#else
476 /*
477 * Get address and size of the DPC blob stored in flash:
478 */
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530479 dpc_fdt_hdr = (void *)mc_dpc_addr;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700480
481 error = fdt_check_header(dpc_fdt_hdr);
482 if (error != 0) {
483 /*
484 * Don't return with error here, since the MC firmware can
485 * still boot without a DPC
486 */
J. German Riveracc088c32015-07-02 11:28:56 +0530487 printf("\nfsl-mc: WARNING: No DPC image found");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700488 return 0;
489 }
490
491 dpc_size = fdt_totalsize(dpc_fdt_hdr);
492 if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
J. German Riveracc088c32015-07-02 11:28:56 +0530493 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
J. German Rivera125e2bc2015-03-20 19:28:18 -0700494 dpc_size);
495 return -EINVAL;
496 }
497
498 mc_copy_image("MC DPC blob",
499 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
500#endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
501
Stuart Yoder21c69872015-07-02 11:29:03 +0530502 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
503 return -EINVAL;
504
J. German Rivera125e2bc2015-03-20 19:28:18 -0700505 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
506 return 0;
507}
508
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000509
510static int mc_fixup_dpl(u64 dpl_addr)
511{
512 void *blob = (void *)dpl_addr;
513 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
514 int err = 0;
515
516 /* The DPL fixup for mac addresses is only relevant
517 * for old-style DPLs
518 */
519 if (ver >= 10)
520 return 0;
521
522 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
523 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
524
525 return err;
526}
527
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530528static 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 -0700529{
530 u64 mc_dpl_offset;
531#ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
532 int error;
533 void *dpl_fdt_hdr;
534 int dpl_size;
535#endif
536
537#ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
538 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
539 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
540
541 mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
542#else
543#error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
544#endif
545
546 /*
547 * Load the MC DPL blob in the MC private DRAM block:
548 */
549#ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
550 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
551#else
552 /*
553 * Get address and size of the DPL blob stored in flash:
554 */
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530555 dpl_fdt_hdr = (void *)mc_dpl_addr;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700556
557 error = fdt_check_header(dpl_fdt_hdr);
558 if (error != 0) {
J. German Riveracc088c32015-07-02 11:28:56 +0530559 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700560 return error;
561 }
562
563 dpl_size = fdt_totalsize(dpl_fdt_hdr);
564 if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
J. German Riveracc088c32015-07-02 11:28:56 +0530565 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
J. German Rivera125e2bc2015-03-20 19:28:18 -0700566 dpl_size);
567 return -EINVAL;
568 }
569
570 mc_copy_image("MC DPL blob",
571 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
572#endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
573
Bogdan Purcareata1161dbc2017-05-24 16:40:22 +0000574 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
575 return -EINVAL;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700576 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
577 return 0;
578}
579
580/**
581 * Return the MC boot timeout value in milliseconds
582 */
583static unsigned long get_mc_boot_timeout_ms(void)
584{
585 unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
586
Simon Glass00caae62017-08-03 12:22:12 -0600587 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700588
589 if (timeout_ms_env_var) {
590 timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
591 if (timeout_ms == 0) {
592 printf("fsl-mc: WARNING: Invalid value for \'"
593 MC_BOOT_TIMEOUT_ENV_VAR
594 "\' environment variable: %lu\n",
595 timeout_ms);
596
597 timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
598 }
599 }
600
601 return timeout_ms;
602}
603
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530604#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
York Sun3c1d2182016-04-04 11:41:26 -0700605
606__weak bool soc_has_aiop(void)
607{
608 return false;
609}
610
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530611static int load_mc_aiop_img(u64 aiop_fw_addr)
J. German Riverac1000c12015-07-02 11:28:58 +0530612{
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530613 u64 mc_ram_addr = mc_get_dram_addr();
614#ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
J. German Riverac1000c12015-07-02 11:28:58 +0530615 void *aiop_img;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530616#endif
J. German Riverac1000c12015-07-02 11:28:58 +0530617
York Sun3c1d2182016-04-04 11:41:26 -0700618 /* Check if AIOP is available */
619 if (!soc_has_aiop())
620 return -ENODEV;
J. German Riverac1000c12015-07-02 11:28:58 +0530621 /*
622 * Load the MC AIOP image in the MC private DRAM block:
623 */
624
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530625#ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
626 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
627 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
628#else
629 aiop_img = (void *)aiop_fw_addr;
J. German Riverac1000c12015-07-02 11:28:58 +0530630 mc_copy_image("MC AIOP image",
631 (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
632 mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530633#endif
634 mc_aiop_applied = 0;
J. German Riverac1000c12015-07-02 11:28:58 +0530635
636 return 0;
637}
638#endif
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530639
J. German Rivera125e2bc2015-03-20 19:28:18 -0700640static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
641{
642 u32 reg_gsr;
643 u32 mc_fw_boot_status;
644 unsigned long timeout_ms = get_mc_boot_timeout_ms();
645 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
646
647 dmb();
J. German Rivera125e2bc2015-03-20 19:28:18 -0700648 assert(timeout_ms > 0);
649 for (;;) {
650 udelay(1000); /* throttle polling */
651 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
652 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
653 if (mc_fw_boot_status & 0x1)
654 break;
655
656 timeout_ms--;
657 if (timeout_ms == 0)
658 break;
659 }
660
661 if (timeout_ms == 0) {
J. German Riveracc088c32015-07-02 11:28:56 +0530662 printf("ERROR: timeout\n");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700663
664 /* TODO: Get an error status from an MC CCSR register */
665 return -ETIMEDOUT;
666 }
667
668 if (mc_fw_boot_status != 0x1) {
669 /*
670 * TODO: Identify critical errors from the GSR register's FS
671 * field and for those errors, set error to -ENODEV or other
672 * appropriate errno, so that the status property is set to
673 * failure in the fsl,dprc device tree node.
674 */
J. German Riveracc088c32015-07-02 11:28:56 +0530675 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
676 reg_gsr);
677 } else {
678 printf("SUCCESS\n");
J. German Rivera125e2bc2015-03-20 19:28:18 -0700679 }
680
J. German Riveracc088c32015-07-02 11:28:56 +0530681
J. German Rivera125e2bc2015-03-20 19:28:18 -0700682 *final_reg_gsr = reg_gsr;
683 return 0;
684}
J. German Riverab940ca62014-06-23 15:15:55 -0700685
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530686int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
J. German Riverab940ca62014-06-23 15:15:55 -0700687{
688 int error = 0;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700689 int portal_id = 0;
J. German Riverab940ca62014-06-23 15:15:55 -0700690 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530691 u64 mc_ram_addr = mc_get_dram_addr();
J. German Riverab940ca62014-06-23 15:15:55 -0700692 u32 reg_gsr;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700693 u32 reg_mcfbalr;
694#ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
J. German Riverab940ca62014-06-23 15:15:55 -0700695 const void *raw_image_addr;
696 size_t raw_image_size = 0;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700697#endif
J. German Rivera125e2bc2015-03-20 19:28:18 -0700698 u8 mc_ram_num_256mb_blocks;
699 size_t mc_ram_size = mc_get_dram_block_size();
J. German Riverab940ca62014-06-23 15:15:55 -0700700
York Sun437858b62017-03-06 09:02:29 -0800701 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530702
703 if (mc_ram_num_256mb_blocks >= 0xff) {
York Sun437858b62017-03-06 09:02:29 -0800704 error = -EINVAL;
705 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
706 mc_ram_size);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700707 goto out;
York Sun437858b62017-03-06 09:02:29 -0800708 }
J. German Rivera125e2bc2015-03-20 19:28:18 -0700709
J. German Riverab940ca62014-06-23 15:15:55 -0700710 /*
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530711 * To support 128 MB DDR Size for MC
712 */
713 if (mc_ram_num_256mb_blocks == 0)
714 mc_ram_num_256mb_blocks = 0xFF;
715
716 /*
J. German Riverab940ca62014-06-23 15:15:55 -0700717 * Management Complex cores should be held at reset out of POR.
Bin Menga1875592016-02-05 19:30:11 -0800718 * U-Boot should be the first software to touch MC. To be safe,
J. German Riverab940ca62014-06-23 15:15:55 -0700719 * we reset all cores again by setting GCR1 to 0. It doesn't do
720 * anything if they are held at reset. After we setup the firmware
721 * we kick off MC by deasserting the reset bit for core 0, and
722 * deasserting the reset bits for Command Portal Managers.
723 * The stop bits are not touched here. They are used to stop the
724 * cores when they are active. Setting stop bits doesn't stop the
725 * cores from fetching instructions when they are released from
726 * reset.
727 */
728 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
729 dmb();
730
J. German Rivera125e2bc2015-03-20 19:28:18 -0700731#ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
732 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
733#else
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530734 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
735 &raw_image_size);
J. German Riverab940ca62014-06-23 15:15:55 -0700736 if (error != 0)
737 goto out;
738 /*
739 * Load the MC FW at the beginning of the MC private DRAM block:
740 */
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800741 mc_copy_image("MC Firmware",
742 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800743#endif
J. German Rivera125e2bc2015-03-20 19:28:18 -0700744 dump_ram_words("firmware", (void *)mc_ram_addr);
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800745
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530746 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700747 if (error != 0)
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800748 goto out;
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800749
J. German Riverab940ca62014-06-23 15:15:55 -0700750 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700751 dump_mc_ccsr_regs(mc_ccsr_regs);
J. German Riverab940ca62014-06-23 15:15:55 -0700752
753 /*
J. German Rivera125e2bc2015-03-20 19:28:18 -0700754 * Tell MC what is the address range of the DRAM block assigned to it:
J. German Riverab940ca62014-06-23 15:15:55 -0700755 */
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530756 if (mc_ram_num_256mb_blocks < 0xFF) {
757 reg_mcfbalr = (u32)mc_ram_addr |
758 (mc_ram_num_256mb_blocks - 1);
759 } else {
760 reg_mcfbalr = (u32)mc_ram_addr |
761 (mc_ram_num_256mb_blocks);
762 }
763
J. German Rivera125e2bc2015-03-20 19:28:18 -0700764 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
765 out_le32(&mc_ccsr_regs->reg_mcfbahr,
York Sun437858b62017-03-06 09:02:29 -0800766 (u32)(mc_ram_addr >> 32));
Stuart Yoder39da6442015-07-02 11:29:02 +0530767 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
J. German Riverab940ca62014-06-23 15:15:55 -0700768
769 /*
J. German Rivera125e2bc2015-03-20 19:28:18 -0700770 * Tell the MC that we want delayed DPL deployment.
J. German Riverab940ca62014-06-23 15:15:55 -0700771 */
J. German Rivera125e2bc2015-03-20 19:28:18 -0700772 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
J. German Riverab940ca62014-06-23 15:15:55 -0700773
J. German Riveracc088c32015-07-02 11:28:56 +0530774 printf("\nfsl-mc: Booting Management Complex ... ");
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800775
J. German Riverab940ca62014-06-23 15:15:55 -0700776 /*
777 * Deassert reset and release MC core 0 to run
778 */
779 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700780 error = wait_for_mc(true, &reg_gsr);
781 if (error != 0)
J. German Riverab940ca62014-06-23 15:15:55 -0700782 goto out;
J. German Riverab940ca62014-06-23 15:15:55 -0700783
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800784 /*
785 * TODO: need to obtain the portal_id for the root container from the
786 * DPL
787 */
788 portal_id = 0;
789
790 /*
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700791 * Initialize the global default MC portal
792 * And check that the MC firmware is responding portal commands:
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800793 */
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +0530794 root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530795 if (!root_mc_io) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +0530796 printf(" No memory: calloc() failed\n");
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700797 return -ENOMEM;
798 }
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800799
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530800 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700801 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 +0530802 portal_id, root_mc_io->mmio_regs);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700803
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530804 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800805 if (error != 0) {
806 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
807 error);
808 goto out;
809 }
810
J. German Rivera7b3bd9a2015-01-06 13:19:02 -0800811 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
812 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
J. German Rivera125e2bc2015-03-20 19:28:18 -0700813 reg_gsr & GSR_FS_MASK);
814
J. German Riverab940ca62014-06-23 15:15:55 -0700815out:
816 if (error != 0)
Prabhakar Kushwaha2b7c4a12015-07-02 11:29:01 +0530817 mc_boot_status = error;
J. German Riverab940ca62014-06-23 15:15:55 -0700818 else
819 mc_boot_status = 0;
820
821 return error;
822}
823
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530824int mc_apply_dpl(u64 mc_dpl_addr)
825{
826 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
827 int error = 0;
828 u32 reg_gsr;
829 u64 mc_ram_addr = mc_get_dram_addr();
830 size_t mc_ram_size = mc_get_dram_block_size();
831
Alexander Grafb7b84102016-11-17 01:02:57 +0100832 if (!mc_dpl_addr)
833 return -1;
834
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530835 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
836 if (error != 0)
837 return error;
838
839 /*
840 * Tell the MC to deploy the DPL:
841 */
842 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
843 printf("fsl-mc: Deploying data path layout ... ");
844 error = wait_for_mc(false, &reg_gsr);
845
846 if (!error)
847 mc_dpl_applied = 0;
848
849 return error;
850}
851
J. German Riverab940ca62014-06-23 15:15:55 -0700852int get_mc_boot_status(void)
853{
854 return mc_boot_status;
855}
856
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530857#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
858int get_aiop_apply_status(void)
859{
860 return mc_aiop_applied;
861}
862#endif
863
864int get_dpl_apply_status(void)
865{
866 return mc_dpl_applied;
867}
868
Mian Yousaf Kaukab7e968042018-12-18 14:01:17 +0100869int is_lazy_dpl_addr_valid(void)
870{
871 return !!mc_lazy_dpl_addr;
872}
873
Priyanka Jain033c5382017-08-24 16:42:43 +0530874/*
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530875 * Return the MC address of private DRAM block.
Priyanka Jain033c5382017-08-24 16:42:43 +0530876 * As per MC design document, MC initial base address
877 * should be least significant 512MB address of MC private
878 * memory, i.e. address should point to end address masked
879 * with 512MB offset in private DRAM block.
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530880 */
881u64 mc_get_dram_addr(void)
882{
Priyanka Jain033c5382017-08-24 16:42:43 +0530883 size_t mc_ram_size = mc_get_dram_block_size();
884
Prabhakar Kushwaha87519a92018-08-27 12:58:52 +0530885 if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) {
886 mc_memset_resv_ram = 1;
887 memset((void *)gd->arch.resv_ram, 0, mc_ram_size);
888 }
889
Priyanka Jain033c5382017-08-24 16:42:43 +0530890 return (gd->arch.resv_ram + mc_ram_size - 1) &
891 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +0530892}
893
J. German Riverab940ca62014-06-23 15:15:55 -0700894/**
895 * Return the actual size of the MC private DRAM block.
J. German Riverab940ca62014-06-23 15:15:55 -0700896 */
897unsigned long mc_get_dram_block_size(void)
898{
J. German Rivera125e2bc2015-03-20 19:28:18 -0700899 unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
900
Simon Glass00caae62017-08-03 12:22:12 -0600901 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700902
903 if (dram_block_size_env_var) {
904 dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
Prabhakar Kushwahaf53e12d2017-11-09 14:45:41 +0530905 16);
J. German Rivera125e2bc2015-03-20 19:28:18 -0700906
907 if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
908 printf("fsl-mc: WARNING: Invalid value for \'"
909 MC_MEM_SIZE_ENV_VAR
910 "\' environment variable: %lu\n",
911 dram_block_size);
912
Meenakshi Aggarwal43ad41e2019-02-27 14:41:02 +0530913 dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE;
J. German Rivera125e2bc2015-03-20 19:28:18 -0700914 }
915 }
916
917 return dram_block_size;
J. German Riverab940ca62014-06-23 15:15:55 -0700918}
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700919
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530920int fsl_mc_ldpaa_init(bd_t *bis)
921{
Prabhakar Kushwahac919ab92015-11-04 12:26:00 +0530922 int i;
923
924 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
Pankaj Bansal1ed19a12018-10-10 14:08:33 +0530925 if (wriop_is_enabled_dpmac(i) == 1)
Prabhakar Kushwahac919ab92015-11-04 12:26:00 +0530926 ldpaa_eth_init(i, wriop_get_enet_if(i));
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530927 return 0;
928}
929
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530930static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
931{
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530932 int error;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530933 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530934
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530935 error = dprc_get_api_version(mc_io, 0,
936 &major_ver,
937 &minor_ver);
938 if (error < 0) {
939 printf("dprc_get_api_version() failed: %d\n", error);
940 return error;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530941 }
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530942
943 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
944 minor_ver < DPRC_VER_MINOR)) {
945 printf("DPRC version mismatch found %u.%u,",
946 major_ver, minor_ver);
947 printf("supported version is %u.%u\n",
948 DPRC_VER_MAJOR, DPRC_VER_MINOR);
949 }
950
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +0530951 return error;
952}
953
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530954static int dpio_init(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700955{
956 struct qbman_swp_desc p_des;
957 struct dpio_attr attr;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530958 struct dpio_cfg dpio_cfg;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700959 int err = 0;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530960 uint16_t major_ver, minor_ver;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700961
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +0530962 dflt_dpio = (struct fsl_dpio_obj *)calloc(
963 sizeof(struct fsl_dpio_obj), 1);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700964 if (!dflt_dpio) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +0530965 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530966 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +0530967 goto err_calloc;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700968 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530969 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
970 dpio_cfg.num_priorities = 8;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700971
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530972 err = dpio_create(dflt_mc_io,
973 dflt_dprc_handle,
974 MC_CMD_NO_FLAGS,
975 &dpio_cfg,
976 &dflt_dpio->dpio_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +0530977 if (err < 0) {
978 printf("dpio_create() failed: %d\n", err);
979 err = -ENODEV;
980 goto err_create;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -0700981 }
982
Yogesh Gaur2557c5a2017-11-15 11:59:31 +0530983 err = dpio_get_api_version(dflt_mc_io, 0,
984 &major_ver,
985 &minor_ver);
986 if (err < 0) {
987 printf("dpio_get_api_version() failed: %d\n", err);
988 goto err_get_api_ver;
989 }
990
991 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
992 minor_ver < DPIO_VER_MINOR)) {
993 printf("DPRC version mismatch found %u.%u,",
994 major_ver,
995 minor_ver);
996 }
997
998 err = dpio_open(dflt_mc_io,
999 MC_CMD_NO_FLAGS,
1000 dflt_dpio->dpio_id,
1001 &dflt_dpio->dpio_handle);
1002 if (err) {
1003 printf("dpio_open() failed\n");
1004 goto err_open;
1005 }
1006
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301007 memset(&attr, 0, sizeof(struct dpio_attr));
Prabhakar Kushwaha87457d12015-07-07 15:40:06 +05301008 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301009 dflt_dpio->dpio_handle, &attr);
1010 if (err < 0) {
1011 printf("dpio_get_attributes() failed: %d\n", err);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001012 goto err_get_attr;
1013 }
1014
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301015 if (dflt_dpio->dpio_id != attr.id) {
1016 printf("dnpi object id and attribute id are not same\n");
1017 goto err_attr_not_same;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301018 }
1019
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301020#ifdef DEBUG
1021 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1022#endif
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301023 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1024 if (err < 0) {
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001025 printf("dpio_enable() failed %d\n", err);
1026 goto err_get_enable;
1027 }
Prabhakar Kushwaha1f1c25c2015-07-02 11:28:59 +05301028 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
1029 attr.qbman_portal_ce_offset,
1030 attr.qbman_portal_ci_offset,
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001031 attr.qbman_portal_id,
1032 attr.num_priorities);
1033
Prabhakar Kushwaha1f1c25c2015-07-02 11:28:59 +05301034 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1035 + attr.qbman_portal_ce_offset);
1036 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1037 + attr.qbman_portal_ci_offset);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001038
1039 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
1040 if (dflt_dpio->sw_portal == NULL) {
1041 printf("qbman_swp_init() failed\n");
1042 goto err_get_swp_init;
1043 }
1044 return 0;
1045
1046err_get_swp_init:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301047 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001048err_get_enable:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301049err_get_attr:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301050err_attr_not_same:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301051 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301052err_open:
1053err_get_api_ver:
1054 dpio_destroy(dflt_mc_io,
1055 dflt_dprc_handle,
1056 MC_CMD_NO_FLAGS,
1057 dflt_dpio->dpio_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301058err_create:
Prabhakar Kushwahacd7b3fb2016-03-18 16:15:29 +05301059 free(dflt_dpio);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301060err_calloc:
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001061 return err;
1062}
1063
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301064static int dpio_exit(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001065{
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301066 int err;
1067
1068 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1069 if (err < 0) {
1070 printf("dpio_disable() failed: %d\n", err);
1071 goto err;
1072 }
1073
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301074 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1075 if (err < 0) {
1076 printf("dpio_close() failed: %d\n", err);
1077 goto err;
1078 }
1079
1080 err = dpio_destroy(dflt_mc_io,
1081 dflt_dprc_handle,
1082 MC_CMD_NO_FLAGS,
1083 dflt_dpio->dpio_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301084 if (err < 0) {
1085 printf("dpio_destroy() failed: %d\n", err);
1086 goto err;
1087 }
1088
1089#ifdef DEBUG
1090 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1091#endif
1092
1093 if (dflt_dpio)
1094 free(dflt_dpio);
1095
1096 return 0;
1097err:
1098 return err;
1099}
1100
1101static int dprc_init(void)
1102{
1103 int err, child_portal_id, container_id;
1104 struct dprc_cfg cfg;
1105 uint64_t mc_portal_offset;
1106
1107 /* Open root container */
1108 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1109 if (err < 0) {
1110 printf("dprc_get_container_id(): Root failed: %d\n", err);
1111 goto err_root_container_id;
1112 }
1113
1114#ifdef DEBUG
1115 printf("Root container id = %d\n", container_id);
1116#endif
1117 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1118 &root_dprc_handle);
1119 if (err < 0) {
1120 printf("dprc_open(): Root Container failed: %d\n", err);
1121 goto err_root_open;
1122 }
1123
1124 if (!root_dprc_handle) {
1125 printf("dprc_open(): Root Container Handle is not valid\n");
1126 goto err_root_open;
1127 }
1128
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301129 err = dprc_version_check(root_mc_io, root_dprc_handle);
1130 if (err < 0) {
1131 printf("dprc_version_check() failed: %d\n", err);
1132 goto err_root_open;
1133 }
1134
Prabhakar Kushwaha5373b202016-01-20 12:04:19 +05301135 memset(&cfg, 0, sizeof(struct dprc_cfg));
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301136 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1137 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1138 DPRC_CFG_OPT_ALLOC_ALLOWED;
1139 cfg.icid = DPRC_GET_ICID_FROM_POOL;
Prabhakar Kushwaha335b1932015-12-24 15:33:49 +05301140 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301141 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1142 root_dprc_handle,
1143 &cfg,
1144 &child_dprc_id,
1145 &mc_portal_offset);
1146 if (err < 0) {
1147 printf("dprc_create_container() failed: %d\n", err);
1148 goto err_create;
1149 }
1150
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301151 dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301152 if (!dflt_mc_io) {
1153 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301154 printf(" No memory: calloc() failed\n");
1155 goto err_calloc;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301156 }
1157
1158 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1159 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301160
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301161#ifdef DEBUG
1162 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1163 child_dprc_id, dflt_mc_io->mmio_regs);
1164#endif
1165
1166 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1167 &dflt_dprc_handle);
1168 if (err < 0) {
1169 printf("dprc_open(): Child container failed: %d\n", err);
1170 goto err_child_open;
1171 }
1172
1173 if (!dflt_dprc_handle) {
1174 printf("dprc_open(): Child container Handle is not valid\n");
1175 goto err_child_open;
1176 }
1177
1178 return 0;
1179err_child_open:
1180 free(dflt_mc_io);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301181err_calloc:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301182 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1183 root_dprc_handle, child_dprc_id);
1184err_create:
1185 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1186err_root_open:
1187err_root_container_id:
1188 return err;
1189}
1190
1191static int dprc_exit(void)
1192{
1193 int err;
1194
1195 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1196 if (err < 0) {
1197 printf("dprc_close(): Child failed: %d\n", err);
1198 goto err;
1199 }
1200
1201 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1202 root_dprc_handle, child_dprc_id);
1203 if (err < 0) {
1204 printf("dprc_destroy_container() failed: %d\n", err);
1205 goto err;
1206 }
1207
1208 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1209 if (err < 0) {
1210 printf("dprc_close(): Root failed: %d\n", err);
1211 goto err;
1212 }
1213
1214 if (dflt_mc_io)
1215 free(dflt_mc_io);
1216
1217 if (root_mc_io)
1218 free(root_mc_io);
1219
1220 return 0;
1221
1222err:
1223 return err;
1224}
1225
1226static int dpbp_init(void)
1227{
1228 int err;
1229 struct dpbp_attr dpbp_attr;
1230 struct dpbp_cfg dpbp_cfg;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301231 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301232
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301233 dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
1234 sizeof(struct fsl_dpbp_obj), 1);
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001235 if (!dflt_dpbp) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301236 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301237 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301238 goto err_calloc;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001239 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301240
1241 dpbp_cfg.options = 512;
1242
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301243 err = dpbp_create(dflt_mc_io,
1244 dflt_dprc_handle,
1245 MC_CMD_NO_FLAGS,
1246 &dpbp_cfg,
1247 &dflt_dpbp->dpbp_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301248
1249 if (err < 0) {
1250 err = -ENODEV;
1251 printf("dpbp_create() failed: %d\n", err);
1252 goto err_create;
1253 }
1254
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301255 err = dpbp_get_api_version(dflt_mc_io, 0,
1256 &major_ver,
1257 &minor_ver);
1258 if (err < 0) {
1259 printf("dpbp_get_api_version() failed: %d\n", err);
1260 goto err_get_api_ver;
1261 }
1262
1263 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1264 minor_ver < DPBP_VER_MINOR)) {
1265 printf("DPBP version mismatch found %u.%u,",
1266 major_ver, minor_ver);
1267 printf("supported version is %u.%u\n",
1268 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1269 }
1270
1271 err = dpbp_open(dflt_mc_io,
1272 MC_CMD_NO_FLAGS,
1273 dflt_dpbp->dpbp_id,
1274 &dflt_dpbp->dpbp_handle);
1275 if (err) {
1276 printf("dpbp_open() failed\n");
1277 goto err_open;
1278 }
1279
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301280 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1281 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1282 dflt_dpbp->dpbp_handle,
1283 &dpbp_attr);
1284 if (err < 0) {
1285 printf("dpbp_get_attributes() failed: %d\n", err);
1286 goto err_get_attr;
1287 }
1288
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301289 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1290 printf("dpbp object id and attribute id are not same\n");
1291 goto err_attr_not_same;
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301292 }
1293
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301294#ifdef DEBUG
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301295 printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301296#endif
1297
1298 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1299 if (err < 0) {
1300 printf("dpbp_close() failed: %d\n", err);
1301 goto err_close;
1302 }
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001303
1304 return 0;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301305
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301306err_get_attr:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301307err_attr_not_same:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301308 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301309 dpbp_destroy(dflt_mc_io,
1310 dflt_dprc_handle,
1311 MC_CMD_NO_FLAGS,
1312 dflt_dpbp->dpbp_id);
1313err_get_api_ver:
1314err_close:
1315err_open:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301316err_create:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301317 free(dflt_dpbp);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301318err_calloc:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301319 return err;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001320}
1321
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301322static int dpbp_exit(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001323{
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301324 int err;
1325
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301326 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1327 dflt_dpbp->dpbp_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301328 if (err < 0) {
1329 printf("dpbp_destroy() failed: %d\n", err);
1330 goto err;
1331 }
1332
1333#ifdef DEBUG
1334 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1335#endif
1336
1337 if (dflt_dpbp)
1338 free(dflt_dpbp);
1339 return 0;
1340
1341err:
1342 return err;
1343}
1344
1345static int dpni_init(void)
1346{
1347 int err;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301348 uint8_t cfg_buf[256] = {0};
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301349 struct dpni_cfg dpni_cfg;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301350 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301351
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301352 dflt_dpni = (struct fsl_dpni_obj *)calloc(
1353 sizeof(struct fsl_dpni_obj), 1);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301354 if (!dflt_dpni) {
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301355 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301356 err = -ENOMEM;
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301357 goto err_calloc;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301358 }
1359
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301360 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1361 err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
Prabhakar Kushwaha879a59a2015-12-24 15:33:01 +05301362 if (err < 0) {
1363 err = -ENODEV;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301364 printf("dpni_prepare_cfg() failed: %d\n", err);
1365 goto err_prepare_cfg;
Prabhakar Kushwaha879a59a2015-12-24 15:33:01 +05301366 }
1367
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301368 err = dpni_create(dflt_mc_io,
1369 dflt_dprc_handle,
1370 MC_CMD_NO_FLAGS,
1371 &dpni_cfg,
1372 &dflt_dpni->dpni_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301373 if (err < 0) {
1374 err = -ENODEV;
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301375 printf("dpni create() failed: %d\n", err);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301376 goto err_create;
1377 }
1378
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301379 err = dpni_get_api_version(dflt_mc_io, 0,
1380 &major_ver,
1381 &minor_ver);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301382 if (err < 0) {
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301383 printf("dpni_get_api_version() failed: %d\n", err);
1384 goto err_get_version;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301385 }
1386
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301387 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1388 minor_ver < DPNI_VER_MINOR)) {
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301389 printf("DPNI version mismatch found %u.%u,",
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301390 major_ver, minor_ver);
Prabhakar Kushwaha9a696f52015-12-24 15:32:37 +05301391 printf("supported version is %u.%u\n",
1392 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1393 }
1394
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301395 err = dpni_open(dflt_mc_io,
1396 MC_CMD_NO_FLAGS,
1397 dflt_dpni->dpni_id,
1398 &dflt_dpni->dpni_handle);
1399 if (err) {
1400 printf("dpni_open() failed\n");
1401 goto err_open;
1402 }
1403
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301404#ifdef DEBUG
1405 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1406#endif
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301407 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1408 if (err < 0) {
1409 printf("dpni_close() failed: %d\n", err);
1410 goto err_close;
1411 }
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001412
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301413 return 0;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301414
1415err_close:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301416 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301417err_open:
1418err_get_version:
1419 dpni_destroy(dflt_mc_io,
1420 dflt_dprc_handle,
1421 MC_CMD_NO_FLAGS,
1422 dflt_dpni->dpni_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301423err_create:
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301424err_prepare_cfg:
Prabhakar Kushwaha879a59a2015-12-24 15:33:01 +05301425 free(dflt_dpni);
Prabhakar Kushwahaa572fb62017-10-11 08:51:18 +05301426err_calloc:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301427 return err;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001428}
1429
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301430static int dpni_exit(void)
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001431{
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301432 int err;
1433
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301434 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1435 dflt_dpni->dpni_id);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301436 if (err < 0) {
1437 printf("dpni_destroy() failed: %d\n", err);
1438 goto err;
1439 }
1440
1441#ifdef DEBUG
1442 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1443#endif
1444
1445 if (dflt_dpni)
1446 free(dflt_dpni);
1447 return 0;
1448
1449err:
1450 return err;
1451}
1452
Florinel Iordache1990cc72019-11-19 10:28:17 +00001453static bool is_dpsparser_supported(void)
1454{
1455 /* dpsparser support was first introduced in MC version: 10.12.0 */
1456 if (mc_ver_info.major < 10)
1457 return false;
1458 if (mc_ver_info.major == 10)
1459 return (mc_ver_info.minor >= 12);
1460 return true;
1461}
1462
1463static int dpsparser_version_check(struct fsl_mc_io *mc_io)
1464{
1465 int error;
1466 u16 major_ver, minor_ver;
1467
1468 if (!is_dpsparser_supported())
1469 return 0;
1470
1471 error = dpsparser_get_api_version(mc_io, 0,
1472 &major_ver,
1473 &minor_ver);
1474 if (error < 0) {
1475 printf("dpsparser_get_api_version() failed: %d\n", error);
1476 return error;
1477 }
1478
1479 if (major_ver < DPSPARSER_VER_MAJOR || (major_ver ==
1480 DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) {
1481 printf("DPSPARSER version mismatch found %u.%u,",
1482 major_ver, minor_ver);
1483 printf("supported version is %u.%u\n",
1484 DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR);
1485 }
1486
1487 return error;
1488}
1489
1490static int dpsparser_init(void)
1491{
1492 int err = 0;
1493
1494 if (!is_dpsparser_supported())
1495 return 0;
1496
1497 err = dpsparser_create(dflt_mc_io,
1498 dflt_dprc_handle,
1499 MC_CMD_NO_FLAGS,
1500 &dpsparser_obj_id);
1501 if (err)
1502 printf("dpsparser_create() failed\n");
1503
1504 err = dpsparser_version_check(dflt_mc_io);
1505 if (err < 0) {
1506 printf("dpsparser_version_check() failed: %d\n", err);
1507 goto err_version_check;
1508 }
1509
1510 err = dpsparser_open(dflt_mc_io,
1511 MC_CMD_NO_FLAGS,
1512 &dpsparser_handle);
1513 if (err < 0) {
1514 printf("dpsparser_open() failed: %d\n", err);
1515 goto err_open;
1516 }
1517
1518 return err;
1519
1520err_open:
1521err_version_check:
1522 dpsparser_destroy(dflt_mc_io,
1523 dflt_dprc_handle,
1524 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1525
1526 return err;
1527}
1528
1529#ifdef DPSPARSER_DESTROY
1530/* TODO: refactoring needed in the future to allow DPSPARSER object destroy
1531 * Workaround: DO NOT destroy DPSPARSER object because it needs to be available
1532 * on Apply DPL
1533 */
1534static int dpsparser_exit(void)
1535{
1536 int err;
1537
1538 if (!is_dpsparser_supported())
1539 return 0;
1540
1541 dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle);
1542 if (err < 0) {
1543 printf("dpsparser_close() failed: %d\n", err);
1544 goto err;
1545 }
1546
1547 err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle,
1548 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1549 if (err < 0) {
1550 printf("dpsparser_destroy() failed: %d\n", err);
1551 goto err;
1552 }
1553 return 0;
1554
1555err:
1556 return err;
1557}
1558#endif
1559
1560int mc_apply_spb(u64 mc_spb_addr)
1561{
1562 int err = 0;
1563 u16 error, err_arr_size;
1564 u64 mc_spb_offset;
1565 u32 spb_size;
1566 struct sp_blob_header *sp_blob;
1567 u64 mc_ram_addr = mc_get_dram_addr();
1568
1569 if (!is_dpsparser_supported())
1570 return 0;
1571
1572 if (!mc_spb_addr) {
1573 printf("fsl-mc: Invalid Blob address\n");
1574 return -1;
1575 }
1576
1577#ifdef CONFIG_MC_DRAM_SPB_OFFSET
1578 mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET;
1579#else
1580#error "CONFIG_MC_DRAM_SPB_OFFSET not defined"
1581#endif
1582
1583 // Read blob header and get size of SPB blob
1584 sp_blob = (struct sp_blob_header *)mc_spb_addr;
1585 spb_size = le32_to_cpu(sp_blob->length);
1586 if (spb_size > CONFIG_MC_SPB_MAX_SIZE) {
1587 printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n",
1588 spb_size);
1589 return -EINVAL;
1590 }
1591
1592 mc_copy_image("MC SP Blob", mc_spb_addr, spb_size,
1593 mc_ram_addr + mc_spb_offset);
1594
1595 //Invoke MC command to apply SPB blob
1596 printf("fsl-mc: Applying soft parser blob... ");
1597 err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle,
1598 mc_spb_offset, &error);
1599 if (err)
1600 return err;
1601
1602 if (error == 0) {
1603 printf("SUCCESS\n");
1604 } else {
1605 printf("FAILED with error code = %d:\n", error);
1606 err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb);
1607
1608 if (error > 0 && error < err_arr_size)
1609 printf(mc_err_msg_apply_spb[error]);
1610 else
1611 printf(MC_ERROR_MSG_SPB_UNKNOWN);
1612 }
1613
1614 return err;
1615}
1616
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301617static int mc_init_object(void)
1618{
1619 int err = 0;
1620
1621 err = dprc_init();
1622 if (err < 0) {
1623 printf("dprc_init() failed: %d\n", err);
1624 goto err;
1625 }
1626
1627 err = dpbp_init();
1628 if (err < 0) {
1629 printf("dpbp_init() failed: %d\n", err);
1630 goto err;
1631 }
1632
1633 err = dpio_init();
1634 if (err < 0) {
1635 printf("dpio_init() failed: %d\n", err);
1636 goto err;
1637 }
1638
1639 err = dpni_init();
1640 if (err < 0) {
1641 printf("dpni_init() failed: %d\n", err);
1642 goto err;
1643 }
1644
Florinel Iordache1990cc72019-11-19 10:28:17 +00001645 err = dpsparser_init();
1646 if (err < 0) {
1647 printf("dpsparser_init() failed: %d\n", err);
1648 goto err;
1649 }
1650
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301651 return 0;
1652err:
1653 return err;
1654}
1655
1656int fsl_mc_ldpaa_exit(bd_t *bd)
1657{
1658 int err = 0;
Yogesh Gaur42e81792017-04-27 10:14:16 +05301659 bool is_dpl_apply_status = false;
Santan Kumar06651b92017-06-29 11:19:34 +05301660 bool mc_boot_status = false;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301661
Alexander Grafb7b84102016-11-17 01:02:57 +01001662 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
Yogesh Gaurf9747a52018-01-16 10:08:24 +05301663 err = mc_apply_dpl(mc_lazy_dpl_addr);
1664 if (!err)
1665 fdt_fixup_board_enet(working_fdt);
Alexander Grafb7b84102016-11-17 01:02:57 +01001666 mc_lazy_dpl_addr = 0;
1667 }
1668
Santan Kumar06651b92017-06-29 11:19:34 +05301669 if (!get_mc_boot_status())
1670 mc_boot_status = true;
1671
Prabhakar Kushwaha6dedced2016-03-21 14:19:39 +05301672 /* MC is not loaded intentionally, So return success. */
Santan Kumar06651b92017-06-29 11:19:34 +05301673 if (bd && !mc_boot_status)
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301674 return 0;
1675
Yogesh Gaur42e81792017-04-27 10:14:16 +05301676 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1677 if (!get_dpl_apply_status())
1678 is_dpl_apply_status = true;
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301679
Yogesh Gaur42e81792017-04-27 10:14:16 +05301680 /*
1681 * For case MC is loaded but DPL is not deployed, return success and
1682 * print message on console. Else FDT fix-up code execution hanged.
1683 */
Santan Kumar06651b92017-06-29 11:19:34 +05301684 if (bd && mc_boot_status && !is_dpl_apply_status) {
Yogesh Gaur42e81792017-04-27 10:14:16 +05301685 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
Yogesh Gaur73fa2062017-11-28 10:11:14 +05301686 goto mc_obj_cleanup;
Yogesh Gaur42e81792017-04-27 10:14:16 +05301687 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301688
Santan Kumar06651b92017-06-29 11:19:34 +05301689 if (bd && mc_boot_status && is_dpl_apply_status)
1690 return 0;
1691
Yogesh Gaur73fa2062017-11-28 10:11:14 +05301692mc_obj_cleanup:
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301693 err = dpbp_exit();
1694 if (err < 0) {
Prabhakar Kushwahaa2a4dc52016-01-20 12:04:37 +05301695 printf("dpbp_exit() failed: %d\n", err);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301696 goto err;
1697 }
1698
1699 err = dpio_exit();
1700 if (err < 0) {
1701 printf("dpio_exit() failed: %d\n", err);
1702 goto err;
1703 }
1704
1705 err = dpni_exit();
1706 if (err < 0) {
1707 printf("dpni_exit() failed: %d\n", err);
1708 goto err;
1709 }
1710
1711 err = dprc_exit();
1712 if (err < 0) {
1713 printf("dprc_exit() failed: %d\n", err);
1714 goto err;
1715 }
1716
1717 return 0;
1718err:
1719 return err;
Prabhakar Kushwahaa2a55e52015-03-19 09:20:45 -07001720}
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301721
1722static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1723{
1724 int err = 0;
1725 if (argc < 3)
1726 goto usage;
1727
1728 switch (argv[1][0]) {
1729 case 's': {
1730 char sub_cmd;
Prabhakar Kushwaha44937212015-11-09 16:42:07 +05301731 u64 mc_fw_addr, mc_dpc_addr;
1732#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1733 u64 aiop_fw_addr;
1734#endif
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301735
1736 sub_cmd = argv[2][0];
Yogesh Gaur2557c5a2017-11-15 11:59:31 +05301737
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301738 switch (sub_cmd) {
1739 case 'm':
1740 if (argc < 5)
1741 goto usage;
1742
1743 if (get_mc_boot_status() == 0) {
1744 printf("fsl-mc: MC is already booted");
1745 printf("\n");
1746 return err;
1747 }
1748 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1749 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1750 16);
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301751
1752 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1753 err = mc_init_object();
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301754 break;
1755
1756#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1757 case 'a':
1758 if (argc < 4)
1759 goto usage;
1760 if (get_aiop_apply_status() == 0) {
1761 printf("fsl-mc: AIOP FW is already");
1762 printf(" applied\n");
1763 return err;
1764 }
1765
1766 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1767 16);
1768
York Sun3c1d2182016-04-04 11:41:26 -07001769 /* if SoC doesn't have AIOP, err = -ENODEV */
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301770 err = load_mc_aiop_img(aiop_fw_addr);
1771 if (!err)
1772 printf("fsl-mc: AIOP FW applied\n");
1773 break;
1774#endif
1775 default:
1776 printf("Invalid option: %s\n", argv[2]);
1777 goto usage;
1778
1779 break;
1780 }
1781 }
1782 break;
1783
Florinel Iordache1990cc72019-11-19 10:28:17 +00001784 case 'l': {
1785 /* lazyapply */
1786 u64 mc_dpl_addr;
1787
1788 if (argc < 4)
1789 goto usage;
1790
1791 if (get_dpl_apply_status() == 0) {
1792 printf("fsl-mc: DPL already applied\n");
1793 return err;
1794 }
1795
1796 mc_dpl_addr = simple_strtoull(argv[3], NULL, 16);
1797
1798 if (get_mc_boot_status() != 0) {
1799 printf("fsl-mc: Deploying data path layout ..");
1800 printf("ERROR (MC is not booted)\n");
1801 return -ENODEV;
1802 }
1803
1804 /*
1805 * We will do the actual dpaa exit and dpl apply
1806 * later from announce_and_cleanup().
1807 */
1808 mc_lazy_dpl_addr = mc_dpl_addr;
1809 break;
1810 }
1811
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301812 case 'a': {
Florinel Iordache1990cc72019-11-19 10:28:17 +00001813 /* apply */
1814 char sub_cmd;
1815 u64 mc_apply_addr;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301816
Florinel Iordache1990cc72019-11-19 10:28:17 +00001817 if (argc < 4)
1818 goto usage;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301819
Florinel Iordache1990cc72019-11-19 10:28:17 +00001820 sub_cmd = argv[2][0];
1821
1822 switch (sub_cmd) {
1823 case 'd':
1824 case 'D':
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301825 if (get_dpl_apply_status() == 0) {
1826 printf("fsl-mc: DPL already applied\n");
1827 return err;
1828 }
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301829 if (get_mc_boot_status() != 0) {
1830 printf("fsl-mc: Deploying data path layout ..");
1831 printf("ERROR (MC is not booted)\n");
1832 return -ENODEV;
1833 }
Prabhakar Kushwaha1730a172015-11-04 12:25:59 +05301834
Florinel Iordache1990cc72019-11-19 10:28:17 +00001835 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1836
1837 /* The user wants DPL applied now */
1838 if (!fsl_mc_ldpaa_exit(NULL))
1839 err = mc_apply_dpl(mc_apply_addr);
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301840 break;
Florinel Iordache1990cc72019-11-19 10:28:17 +00001841
1842 case 's':
1843 if (!is_dpsparser_supported()) {
1844 printf("fsl-mc: apply spb command .. ");
1845 printf("ERROR: requires at least MC 10.12.0\n");
1846 return err;
1847 }
1848 if (get_mc_boot_status() != 0) {
1849 printf("fsl-mc: Deploying Soft Parser Blob...");
1850 printf("ERROR (MC is not booted)\n");
1851 return err;
1852 }
1853
1854 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1855
1856 /* Apply spb (Soft Parser Blob) */
1857 err = mc_apply_spb(mc_apply_addr);
1858 break;
1859
1860 default:
1861 printf("Invalid option: %s\n", argv[2]);
1862 goto usage;
1863 }
1864 break;
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301865 }
1866 default:
1867 printf("Invalid option: %s\n", argv[1]);
1868 goto usage;
1869 break;
1870 }
1871 return err;
1872 usage:
1873 return CMD_RET_USAGE;
1874}
1875
1876U_BOOT_CMD(
1877 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1878 "DPAA2 command to manage Management Complex (MC)",
1879 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1880 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
Alexander Grafb7b84102016-11-17 01:02:57 +01001881 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
Florinel Iordache1990cc72019-11-19 10:28:17 +00001882 "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n"
Prabhakar Kushwahafb4a87a2015-11-04 12:25:58 +05301883 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1884);
Bogdan Purcareata33a89912017-05-24 16:40:21 +00001885
1886void mc_env_boot(void)
1887{
1888#if defined(CONFIG_FSL_MC_ENET)
1889 char *mc_boot_env_var;
1890 /* The MC may only be initialized in the reset PHY function
1891 * because otherwise U-Boot has not yet set up all the MAC
1892 * address info properly. Without MAC addresses, the MC code
1893 * can not properly initialize the DPC.
1894 */
Simon Glass00caae62017-08-03 12:22:12 -06001895 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
Bogdan Purcareata33a89912017-05-24 16:40:21 +00001896 if (mc_boot_env_var)
1897 run_command_list(mc_boot_env_var, -1, 0);
1898#endif /* CONFIG_FSL_MC_ENET */
1899}