blob: 36218420165d3710da45dcdf82bc87bbc96e802f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
J. German Rivera8ff14b72014-06-23 15:15:55 -07002/*
Yogesh Gaur1a0c4ae2018-05-09 10:52:17 +05303 * Copyright 2014 Freescale Semiconductor, Inc.
Razvan Ionut Cirjana3bbc3b2020-04-28 16:09:59 +03004 * Copyright 2017-2018, 2020 NXP
J. German Rivera8ff14b72014-06-23 15:15:55 -07005 */
Stuart Yodera2bdb772015-07-02 11:29:03 +05306#include <common.h>
Simon Glassadaaa482019-11-14 12:57:43 -07007#include <command.h>
Simon Glass63334482019-11-14 12:57:39 -07008#include <cpu_func.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
J. German Rivera8ff14b72014-06-23 15:15:55 -070010#include <errno.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
Masahiro Yamada78eeb912016-01-24 23:27:48 +090012#include <linux/bug.h>
J. German Rivera8ff14b72014-06-23 15:15:55 -070013#include <asm/io.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +000015#include <net.h>
Stuart Yodera2bdb772015-07-02 11:29:03 +053016#include <fdt_support.h>
J. German Rivera43e4ae32015-01-06 13:19:02 -080017#include <fsl-mc/fsl_mc.h>
18#include <fsl-mc/fsl_mc_sys.h>
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070019#include <fsl-mc/fsl_mc_private.h>
J. German Rivera43e4ae32015-01-06 13:19:02 -080020#include <fsl-mc/fsl_dpmng.h>
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070021#include <fsl-mc/fsl_dprc.h>
22#include <fsl-mc/fsl_dpio.h>
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +053023#include <fsl-mc/fsl_dpni.h>
Florinel Iordacheae6d8522019-11-19 10:28:17 +000024#include <fsl-mc/fsl_dpsparser.h>
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070025#include <fsl-mc/fsl_qbman_portal.h>
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +053026#include <fsl-mc/ldpaa_wriop.h>
J. German Rivera8ff14b72014-06-23 15:15:55 -070027
J. German Riveraf4fed4b2015-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 Purcareata08bc0142017-05-24 16:40:21 +000034#define MC_BOOT_ENV_VAR "mcinitcmd"
Meenakshi Aggarwal67f195c2019-02-27 14:41:02 +053035#define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024)
J. German Riveraf4fed4b2015-03-20 19:28:18 -070036
J. German Rivera8ff14b72014-06-23 15:15:55 -070037DECLARE_GLOBAL_DATA_PTR;
Prabhakar Kushwaha145e4cd2018-08-27 12:58:52 +053038static int mc_memset_resv_ram;
Florinel Iordacheae6d8522019-11-19 10:28:17 +000039static struct mc_version mc_ver_info;
Prabhakar Kushwaha29a63e42015-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 Kushwaha316b71c2015-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 Kushwahacfd9fbf2015-03-19 09:20:45 -070048uint16_t dflt_dprc_handle = 0;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +053049int child_dprc_id;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -070050struct fsl_dpbp_obj *dflt_dpbp = NULL;
51struct fsl_dpio_obj *dflt_dpio = NULL;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +053052struct fsl_dpni_obj *dflt_dpni = NULL;
Alexander Graf2ebeb442016-11-17 01:02:57 +010053static u64 mc_lazy_dpl_addr;
Florinel Iordacheae6d8522019-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 Riveraf4fed4b2015-03-20 19:28:18 -070057
58#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}
J. German Rivera8ff14b72014-06-23 15:15:55 -070070
J. German Riveraf4fed4b2015-03-20 19:28:18 -070071void 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 Rivera8ff14b72014-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 Rivera43e4ae32015-01-06 13:19:02 -0800104 u64 image_addr, u32 image_size, u64 mc_ram_addr)
J. German Rivera8ff14b72014-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 Riveraf4fed4b2015-03-20 19:28:18 -0700108 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
J. German Rivera8ff14b72014-06-23 15:15:55 -0700109 return 0;
110}
111
Florinel Iordacheae6d8522019-11-19 10:28:17 +0000112#ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
J. German Rivera8ff14b72014-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 Rivera43e4ae32015-01-06 13:19:02 -0800117 * Returns 0 on success and a negative errno on error.
J. German Rivera8ff14b72014-06-23 15:15:55 -0700118 * task fail.
119 **/
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530120int parse_mc_firmware_fit_image(u64 mc_fw_addr,
121 const void **raw_image_addr,
J. German Rivera8ff14b72014-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 Kushwaha29a63e42015-11-04 12:25:58 +0530131 fit_hdr = (void *)mc_fw_addr;
J. German Rivera8ff14b72014-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 Kushwaha29a63e42015-11-04 12:25:58 +0530137 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
J. German Rivera43e4ae32015-01-06 13:19:02 -0800138 return -EINVAL;
J. German Rivera8ff14b72014-06-23 15:15:55 -0700139 }
140
141 if (!fit_check_format(fit_hdr)) {
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530142 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
J. German Rivera43e4ae32015-01-06 13:19:02 -0800143 return -EINVAL;
J. German Rivera8ff14b72014-06-23 15:15:55 -0700144 }
145
146 node_offset = fit_image_get_node(fit_hdr, uname);
147
148 if (node_offset < 0) {
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530149 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
J. German Rivera43e4ae32015-01-06 13:19:02 -0800150 return -ENOENT;
J. German Rivera8ff14b72014-06-23 15:15:55 -0700151 }
152
153 /* Verify MC firmware image */
154 if (!(fit_image_verify(fit_hdr, node_offset))) {
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530155 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
J. German Rivera43e4ae32015-01-06 13:19:02 -0800156 return -EINVAL;
J. German Rivera8ff14b72014-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 Riveraf4fed4b2015-03-20 19:28:18 -0700167#endif
168
Bogdan Purcareata72669142017-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 Ciornei25f7cf72020-03-18 16:47:38 +0200177#ifdef CONFIG_DM_ETH
178 const char *propname, struct udevice *eth_dev,
179#else
Bogdan Purcareata72669142017-05-24 16:40:22 +0000180 const char *propname, struct eth_device *eth_dev,
Ioana Ciornei25f7cf72020-03-18 16:47:38 +0200181#endif
Bogdan Purcareata72669142017-05-24 16:40:22 +0000182 enum mc_fixup_type type)
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000183{
Ioana Ciornei25f7cf72020-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 Purcareata72669142017-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 Ciornei25f7cf72020-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 Purcareata72669142017-05-24 16:40:22 +0000205 case MC_FIXUP_DPC:
Ioana Ciornei25f7cf72020-03-18 16:47:38 +0200206 val = enetaddr;
207 len = ARP_HLEN;
208 break;
Bogdan Purcareata72669142017-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 Ciornei25f7cf72020-03-18 16:47:38 +0200214 if (!eth_env_get_enetaddr_by_index("eth", eth_index,
Simon Glass399a9ce2017-08-03 12:22:14 -0600215 env_enetaddr))
Bogdan Purcareata72669142017-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 Ciornei25f7cf72020-03-18 16:47:38 +0200264#ifdef CONFIG_DM_ETH
265 struct udevice *eth_dev)
266#else
Bogdan Purcareata72669142017-05-24 16:40:22 +0000267 struct eth_device *eth_dev)
Ioana Ciornei25f7cf72020-03-18 16:47:38 +0200268#endif
Bogdan Purcareata72669142017-05-24 16:40:22 +0000269{
270 int objoff = fdt_path_offset(blob, "/objects");
271 int dpmacoff = -1, dpnioff = -1;
272 const char *endpoint;
273 char mac_name[10];
274 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 Aggarwald67ae482019-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 Guptad6912642018-08-20 16:01:14 +0530317void fdt_fsl_mc_fixup_iommu_map_entry(void *blob)
318{
319 u32 *prop;
Laurentiu Tudor9e352592020-05-04 14:47:11 +0300320 u32 iommu_map[4], phandle;
Nipun Guptad6912642018-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 Tudor9e352592020-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 Guptad6912642018-08-20 16:01:14 +0530364}
365
Bogdan Purcareata72669142017-05-24 16:40:22 +0000366static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
Ioana Ciornei25f7cf72020-03-18 16:47:38 +0200367#ifdef CONFIG_DM_ETH
368 struct udevice *eth_dev)
369#else
Bogdan Purcareata72669142017-05-24 16:40:22 +0000370 struct eth_device *eth_dev)
Ioana Ciornei25f7cf72020-03-18 16:47:38 +0200371#endif
Bogdan Purcareata72669142017-05-24 16:40:22 +0000372{
373 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
374 int err = 0;
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000375 char mac_name[10];
Bogdan Purcareata72669142017-05-24 16:40:22 +0000376 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000377
378 sprintf(mac_name, "mac@%d", dpmac_id);
379
380 /* node not found - create it */
Bogdan Purcareata72669142017-05-24 16:40:22 +0000381 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
382 if (noff < 0) {
Bogdan Purcareatabea8abd2017-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 Purcareata72669142017-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 Purcareatabea8abd2017-01-11 15:58:36 +0000396
397 /* add default property of fixed link */
Bogdan Purcareata72669142017-05-24 16:40:22 +0000398 err = fdt_appendprop_string(blob, noff,
Bogdan Purcareatabea8abd2017-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 Purcareata72669142017-05-24 16:40:22 +0000407 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
408 MC_FIXUP_DPC);
409}
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000410
Bogdan Purcareata72669142017-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 Ciornei25f7cf72020-03-18 16:47:38 +0200414#ifdef CONFIG_DM_ETH
415#define ETH_NAME_LEN 20
416 struct udevice *eth_dev;
417#else
Bogdan Purcareata72669142017-05-24 16:40:22 +0000418 struct eth_device *eth_dev;
Ioana Ciornei25f7cf72020-03-18 16:47:38 +0200419#endif
420 char ethname[ETH_NAME_LEN];
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000421
Bogdan Purcareata72669142017-05-24 16:40:22 +0000422 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
423 /* port not enabled */
Pankaj Bansal7987ab72018-10-10 14:08:33 +0530424 if (wriop_is_enabled_dpmac(i) != 1)
Bogdan Purcareata72669142017-05-24 16:40:22 +0000425 continue;
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000426
Pankaj Bansal8a921702018-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 Purcareatabea8abd2017-01-11 15:58:36 +0000429
Bogdan Purcareata72669142017-05-24 16:40:22 +0000430 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;
443 }
444
445 if (err)
446 printf("fsl-mc: ERROR fixing mac address for %s\n",
447 ethname);
448 ret |= err;
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000449 }
450
Bogdan Purcareata72669142017-05-24 16:40:22 +0000451 return ret;
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000452}
453
Stuart Yodera2bdb772015-07-02 11:29:03 +0530454static int mc_fixup_dpc(u64 dpc_addr)
455{
456 void *blob = (void *)dpc_addr;
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000457 int nodeoffset, err = 0;
Stuart Yodera2bdb772015-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 Purcareatabea8abd2017-01-11 15:58:36 +0000479 /* fixup MAC addresses for dpmac ports */
480 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
Razvan Ionut Cirjana3bbc3b2020-04-28 16:09:59 +0300481 if (nodeoffset < 0) {
482 err = fdt_increase_size(blob, 512);
483 if (err) {
484 printf("fdt_increase_size: err=%s\n",
485 fdt_strerror(err));
486 goto out;
487 }
488 nodeoffset = fdt_path_offset(blob, "/board_info");
489 if (nodeoffset < 0)
490 nodeoffset = fdt_add_subnode(blob, 0, "board_info");
491
492 nodeoffset = fdt_add_subnode(blob, nodeoffset, "ports");
493 }
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000494
Bogdan Purcareata72669142017-05-24 16:40:22 +0000495 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
Ioana Ciocoi Radulescud7697f42019-02-26 15:50:07 +0000496
497out:
Stuart Yodera2bdb772015-07-02 11:29:03 +0530498 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
499
Bogdan Purcareatabea8abd2017-01-11 15:58:36 +0000500 return err;
Stuart Yodera2bdb772015-07-02 11:29:03 +0530501}
502
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530503static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700504{
505 u64 mc_dpc_offset;
506#ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
507 int error;
508 void *dpc_fdt_hdr;
509 int dpc_size;
510#endif
511
512#ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
513 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
514 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
515
516 mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
517#else
518#error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
519#endif
520
521 /*
522 * Load the MC DPC blob in the MC private DRAM block:
523 */
524#ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
525 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
526#else
527 /*
528 * Get address and size of the DPC blob stored in flash:
529 */
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530530 dpc_fdt_hdr = (void *)mc_dpc_addr;
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700531
532 error = fdt_check_header(dpc_fdt_hdr);
533 if (error != 0) {
534 /*
535 * Don't return with error here, since the MC firmware can
536 * still boot without a DPC
537 */
J. German Rivera75d7ace2015-07-02 11:28:56 +0530538 printf("\nfsl-mc: WARNING: No DPC image found");
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700539 return 0;
540 }
541
542 dpc_size = fdt_totalsize(dpc_fdt_hdr);
543 if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
J. German Rivera75d7ace2015-07-02 11:28:56 +0530544 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700545 dpc_size);
546 return -EINVAL;
547 }
548
549 mc_copy_image("MC DPC blob",
550 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
551#endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
552
Stuart Yodera2bdb772015-07-02 11:29:03 +0530553 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
554 return -EINVAL;
555
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700556 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
557 return 0;
558}
559
Bogdan Purcareata72669142017-05-24 16:40:22 +0000560
561static int mc_fixup_dpl(u64 dpl_addr)
562{
563 void *blob = (void *)dpl_addr;
564 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
565 int err = 0;
566
567 /* The DPL fixup for mac addresses is only relevant
568 * for old-style DPLs
569 */
570 if (ver >= 10)
571 return 0;
572
573 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
574 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
575
576 return err;
577}
578
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530579static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700580{
581 u64 mc_dpl_offset;
582#ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
583 int error;
584 void *dpl_fdt_hdr;
585 int dpl_size;
586#endif
587
588#ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
589 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
590 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
591
592 mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
593#else
594#error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
595#endif
596
597 /*
598 * Load the MC DPL blob in the MC private DRAM block:
599 */
600#ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
601 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
602#else
603 /*
604 * Get address and size of the DPL blob stored in flash:
605 */
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530606 dpl_fdt_hdr = (void *)mc_dpl_addr;
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700607
608 error = fdt_check_header(dpl_fdt_hdr);
609 if (error != 0) {
J. German Rivera75d7ace2015-07-02 11:28:56 +0530610 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700611 return error;
612 }
613
614 dpl_size = fdt_totalsize(dpl_fdt_hdr);
615 if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
J. German Rivera75d7ace2015-07-02 11:28:56 +0530616 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700617 dpl_size);
618 return -EINVAL;
619 }
620
621 mc_copy_image("MC DPL blob",
622 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
623#endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
624
Bogdan Purcareata72669142017-05-24 16:40:22 +0000625 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
626 return -EINVAL;
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700627 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
628 return 0;
629}
630
631/**
632 * Return the MC boot timeout value in milliseconds
633 */
634static unsigned long get_mc_boot_timeout_ms(void)
635{
636 unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
637
Simon Glass64b723f2017-08-03 12:22:12 -0600638 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700639
640 if (timeout_ms_env_var) {
641 timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
642 if (timeout_ms == 0) {
643 printf("fsl-mc: WARNING: Invalid value for \'"
644 MC_BOOT_TIMEOUT_ENV_VAR
645 "\' environment variable: %lu\n",
646 timeout_ms);
647
648 timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
649 }
650 }
651
652 return timeout_ms;
653}
654
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530655#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
York Suncbe8e1c2016-04-04 11:41:26 -0700656
657__weak bool soc_has_aiop(void)
658{
659 return false;
660}
661
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530662static int load_mc_aiop_img(u64 aiop_fw_addr)
J. German Riverac3b505f2015-07-02 11:28:58 +0530663{
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530664 u64 mc_ram_addr = mc_get_dram_addr();
665#ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
J. German Riverac3b505f2015-07-02 11:28:58 +0530666 void *aiop_img;
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530667#endif
J. German Riverac3b505f2015-07-02 11:28:58 +0530668
York Suncbe8e1c2016-04-04 11:41:26 -0700669 /* Check if AIOP is available */
670 if (!soc_has_aiop())
671 return -ENODEV;
J. German Riverac3b505f2015-07-02 11:28:58 +0530672 /*
673 * Load the MC AIOP image in the MC private DRAM block:
674 */
675
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530676#ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
677 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
678 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
679#else
680 aiop_img = (void *)aiop_fw_addr;
J. German Riverac3b505f2015-07-02 11:28:58 +0530681 mc_copy_image("MC AIOP image",
682 (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
683 mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530684#endif
685 mc_aiop_applied = 0;
J. German Riverac3b505f2015-07-02 11:28:58 +0530686
687 return 0;
688}
689#endif
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530690
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700691static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
692{
693 u32 reg_gsr;
694 u32 mc_fw_boot_status;
695 unsigned long timeout_ms = get_mc_boot_timeout_ms();
696 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
697
698 dmb();
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700699 assert(timeout_ms > 0);
700 for (;;) {
701 udelay(1000); /* throttle polling */
702 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
703 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
704 if (mc_fw_boot_status & 0x1)
705 break;
706
707 timeout_ms--;
708 if (timeout_ms == 0)
709 break;
710 }
711
712 if (timeout_ms == 0) {
J. German Rivera75d7ace2015-07-02 11:28:56 +0530713 printf("ERROR: timeout\n");
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700714
715 /* TODO: Get an error status from an MC CCSR register */
716 return -ETIMEDOUT;
717 }
718
719 if (mc_fw_boot_status != 0x1) {
720 /*
721 * TODO: Identify critical errors from the GSR register's FS
722 * field and for those errors, set error to -ENODEV or other
723 * appropriate errno, so that the status property is set to
724 * failure in the fsl,dprc device tree node.
725 */
J. German Rivera75d7ace2015-07-02 11:28:56 +0530726 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
727 reg_gsr);
728 } else {
729 printf("SUCCESS\n");
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700730 }
731
J. German Rivera75d7ace2015-07-02 11:28:56 +0530732
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700733 *final_reg_gsr = reg_gsr;
734 return 0;
735}
J. German Rivera8ff14b72014-06-23 15:15:55 -0700736
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530737int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
J. German Rivera8ff14b72014-06-23 15:15:55 -0700738{
739 int error = 0;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700740 int portal_id = 0;
J. German Rivera8ff14b72014-06-23 15:15:55 -0700741 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530742 u64 mc_ram_addr = mc_get_dram_addr();
J. German Rivera8ff14b72014-06-23 15:15:55 -0700743 u32 reg_gsr;
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700744 u32 reg_mcfbalr;
745#ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
J. German Rivera8ff14b72014-06-23 15:15:55 -0700746 const void *raw_image_addr;
747 size_t raw_image_size = 0;
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700748#endif
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700749 u8 mc_ram_num_256mb_blocks;
750 size_t mc_ram_size = mc_get_dram_block_size();
J. German Rivera8ff14b72014-06-23 15:15:55 -0700751
York Sunc55d7312017-03-06 09:02:29 -0800752 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
Meenakshi Aggarwal67f195c2019-02-27 14:41:02 +0530753
754 if (mc_ram_num_256mb_blocks >= 0xff) {
York Sunc55d7312017-03-06 09:02:29 -0800755 error = -EINVAL;
756 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
757 mc_ram_size);
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700758 goto out;
York Sunc55d7312017-03-06 09:02:29 -0800759 }
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700760
J. German Rivera8ff14b72014-06-23 15:15:55 -0700761 /*
Meenakshi Aggarwal67f195c2019-02-27 14:41:02 +0530762 * To support 128 MB DDR Size for MC
763 */
764 if (mc_ram_num_256mb_blocks == 0)
765 mc_ram_num_256mb_blocks = 0xFF;
766
767 /*
J. German Rivera8ff14b72014-06-23 15:15:55 -0700768 * Management Complex cores should be held at reset out of POR.
Bin Meng75574052016-02-05 19:30:11 -0800769 * U-Boot should be the first software to touch MC. To be safe,
J. German Rivera8ff14b72014-06-23 15:15:55 -0700770 * we reset all cores again by setting GCR1 to 0. It doesn't do
771 * anything if they are held at reset. After we setup the firmware
772 * we kick off MC by deasserting the reset bit for core 0, and
773 * deasserting the reset bits for Command Portal Managers.
774 * The stop bits are not touched here. They are used to stop the
775 * cores when they are active. Setting stop bits doesn't stop the
776 * cores from fetching instructions when they are released from
777 * reset.
778 */
779 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
780 dmb();
781
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700782#ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
783 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
784#else
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530785 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
786 &raw_image_size);
J. German Rivera8ff14b72014-06-23 15:15:55 -0700787 if (error != 0)
788 goto out;
789 /*
790 * Load the MC FW at the beginning of the MC private DRAM block:
791 */
J. German Rivera43e4ae32015-01-06 13:19:02 -0800792 mc_copy_image("MC Firmware",
793 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
J. German Rivera43e4ae32015-01-06 13:19:02 -0800794#endif
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700795 dump_ram_words("firmware", (void *)mc_ram_addr);
J. German Rivera43e4ae32015-01-06 13:19:02 -0800796
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530797 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700798 if (error != 0)
J. German Rivera8ff14b72014-06-23 15:15:55 -0700799 goto out;
J. German Riverac3b505f2015-07-02 11:28:58 +0530800
J. German Rivera8ff14b72014-06-23 15:15:55 -0700801 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700802 dump_mc_ccsr_regs(mc_ccsr_regs);
J. German Rivera8ff14b72014-06-23 15:15:55 -0700803
804 /*
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700805 * Tell MC what is the address range of the DRAM block assigned to it:
J. German Rivera8ff14b72014-06-23 15:15:55 -0700806 */
Meenakshi Aggarwal67f195c2019-02-27 14:41:02 +0530807 if (mc_ram_num_256mb_blocks < 0xFF) {
808 reg_mcfbalr = (u32)mc_ram_addr |
809 (mc_ram_num_256mb_blocks - 1);
810 } else {
811 reg_mcfbalr = (u32)mc_ram_addr |
812 (mc_ram_num_256mb_blocks);
813 }
814
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700815 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
816 out_le32(&mc_ccsr_regs->reg_mcfbahr,
York Sunc55d7312017-03-06 09:02:29 -0800817 (u32)(mc_ram_addr >> 32));
Stuart Yoderd1970352015-07-02 11:29:02 +0530818 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
J. German Rivera8ff14b72014-06-23 15:15:55 -0700819
820 /*
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700821 * Tell the MC that we want delayed DPL deployment.
J. German Rivera8ff14b72014-06-23 15:15:55 -0700822 */
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700823 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
J. German Rivera8ff14b72014-06-23 15:15:55 -0700824
J. German Rivera75d7ace2015-07-02 11:28:56 +0530825 printf("\nfsl-mc: Booting Management Complex ... ");
J. German Rivera43e4ae32015-01-06 13:19:02 -0800826
J. German Rivera8ff14b72014-06-23 15:15:55 -0700827 /*
828 * Deassert reset and release MC core 0 to run
829 */
830 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700831 error = wait_for_mc(true, &reg_gsr);
832 if (error != 0)
J. German Rivera8ff14b72014-06-23 15:15:55 -0700833 goto out;
J. German Rivera8ff14b72014-06-23 15:15:55 -0700834
J. German Rivera43e4ae32015-01-06 13:19:02 -0800835 /*
836 * TODO: need to obtain the portal_id for the root container from the
837 * DPL
838 */
839 portal_id = 0;
840
841 /*
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700842 * Initialize the global default MC portal
843 * And check that the MC firmware is responding portal commands:
J. German Rivera43e4ae32015-01-06 13:19:02 -0800844 */
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +0530845 root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530846 if (!root_mc_io) {
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +0530847 printf(" No memory: calloc() failed\n");
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700848 return -ENOMEM;
849 }
850
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530851 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
J. German Rivera43e4ae32015-01-06 13:19:02 -0800852 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530853 portal_id, root_mc_io->mmio_regs);
J. German Rivera43e4ae32015-01-06 13:19:02 -0800854
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530855 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
J. German Rivera43e4ae32015-01-06 13:19:02 -0800856 if (error != 0) {
857 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
858 error);
859 goto out;
860 }
861
J. German Rivera43e4ae32015-01-06 13:19:02 -0800862 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
863 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700864 reg_gsr & GSR_FS_MASK);
865
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530866out:
867 if (error != 0)
868 mc_boot_status = error;
869 else
870 mc_boot_status = 0;
871
872 return error;
873}
874
875int mc_apply_dpl(u64 mc_dpl_addr)
876{
877 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
878 int error = 0;
879 u32 reg_gsr;
880 u64 mc_ram_addr = mc_get_dram_addr();
881 size_t mc_ram_size = mc_get_dram_block_size();
882
Alexander Graf2ebeb442016-11-17 01:02:57 +0100883 if (!mc_dpl_addr)
884 return -1;
885
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530886 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
887 if (error != 0)
888 return error;
889
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700890 /*
891 * Tell the MC to deploy the DPL:
892 */
893 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
J. German Rivera75d7ace2015-07-02 11:28:56 +0530894 printf("fsl-mc: Deploying data path layout ... ");
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700895 error = wait_for_mc(false, &reg_gsr);
J. German Rivera75d7ace2015-07-02 11:28:56 +0530896
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530897 if (!error)
898 mc_dpl_applied = 0;
J. German Rivera8ff14b72014-06-23 15:15:55 -0700899
900 return error;
901}
902
903int get_mc_boot_status(void)
904{
905 return mc_boot_status;
906}
907
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530908#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
909int get_aiop_apply_status(void)
910{
911 return mc_aiop_applied;
912}
913#endif
914
915int get_dpl_apply_status(void)
916{
917 return mc_dpl_applied;
918}
919
Mian Yousaf Kaukab97124652018-12-18 14:01:17 +0100920int is_lazy_dpl_addr_valid(void)
921{
922 return !!mc_lazy_dpl_addr;
923}
924
Priyanka Jaine0e0be52017-08-24 16:42:43 +0530925/*
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530926 * Return the MC address of private DRAM block.
Priyanka Jaine0e0be52017-08-24 16:42:43 +0530927 * As per MC design document, MC initial base address
928 * should be least significant 512MB address of MC private
929 * memory, i.e. address should point to end address masked
930 * with 512MB offset in private DRAM block.
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530931 */
932u64 mc_get_dram_addr(void)
933{
Priyanka Jaine0e0be52017-08-24 16:42:43 +0530934 size_t mc_ram_size = mc_get_dram_block_size();
935
Prabhakar Kushwaha145e4cd2018-08-27 12:58:52 +0530936 if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) {
937 mc_memset_resv_ram = 1;
938 memset((void *)gd->arch.resv_ram, 0, mc_ram_size);
939 }
940
Priyanka Jaine0e0be52017-08-24 16:42:43 +0530941 return (gd->arch.resv_ram + mc_ram_size - 1) &
942 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +0530943}
944
945/**
J. German Rivera8ff14b72014-06-23 15:15:55 -0700946 * Return the actual size of the MC private DRAM block.
J. German Rivera8ff14b72014-06-23 15:15:55 -0700947 */
948unsigned long mc_get_dram_block_size(void)
949{
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700950 unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
951
Simon Glass64b723f2017-08-03 12:22:12 -0600952 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700953
954 if (dram_block_size_env_var) {
955 dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
Prabhakar Kushwahab166d6a2017-11-09 14:45:41 +0530956 16);
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700957
958 if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
959 printf("fsl-mc: WARNING: Invalid value for \'"
960 MC_MEM_SIZE_ENV_VAR
961 "\' environment variable: %lu\n",
962 dram_block_size);
963
Meenakshi Aggarwal67f195c2019-02-27 14:41:02 +0530964 dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE;
J. German Riveraf4fed4b2015-03-20 19:28:18 -0700965 }
966 }
967
968 return dram_block_size;
J. German Rivera8ff14b72014-06-23 15:15:55 -0700969}
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -0700970
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530971int fsl_mc_ldpaa_init(bd_t *bis)
972{
Prabhakar Kushwaha52d2e2c2015-11-04 12:26:00 +0530973 int i;
974
975 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
Pankaj Bansal7987ab72018-10-10 14:08:33 +0530976 if (wriop_is_enabled_dpmac(i) == 1)
Prabhakar Kushwaha52d2e2c2015-11-04 12:26:00 +0530977 ldpaa_eth_init(i, wriop_get_enet_if(i));
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530978 return 0;
979}
980
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +0530981static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
982{
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +0530983 int error;
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530984 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +0530985
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530986 error = dprc_get_api_version(mc_io, 0,
987 &major_ver,
988 &minor_ver);
989 if (error < 0) {
990 printf("dprc_get_api_version() failed: %d\n", error);
991 return error;
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +0530992 }
Yogesh Gaur318c32f2017-11-15 11:59:31 +0530993
994 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
995 minor_ver < DPRC_VER_MINOR)) {
996 printf("DPRC version mismatch found %u.%u,",
997 major_ver, minor_ver);
998 printf("supported version is %u.%u\n",
999 DPRC_VER_MAJOR, DPRC_VER_MINOR);
1000 }
1001
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +05301002 return error;
1003}
1004
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301005static int dpio_init(void)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001006{
1007 struct qbman_swp_desc p_des;
1008 struct dpio_attr attr;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301009 struct dpio_cfg dpio_cfg;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001010 int err = 0;
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301011 uint16_t major_ver, minor_ver;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001012
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301013 dflt_dpio = (struct fsl_dpio_obj *)calloc(
1014 sizeof(struct fsl_dpio_obj), 1);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001015 if (!dflt_dpio) {
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301016 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301017 err = -ENOMEM;
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301018 goto err_calloc;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001019 }
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301020 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
1021 dpio_cfg.num_priorities = 8;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001022
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301023 err = dpio_create(dflt_mc_io,
1024 dflt_dprc_handle,
1025 MC_CMD_NO_FLAGS,
1026 &dpio_cfg,
1027 &dflt_dpio->dpio_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301028 if (err < 0) {
1029 printf("dpio_create() failed: %d\n", err);
1030 err = -ENODEV;
1031 goto err_create;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001032 }
1033
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301034 err = dpio_get_api_version(dflt_mc_io, 0,
1035 &major_ver,
1036 &minor_ver);
1037 if (err < 0) {
1038 printf("dpio_get_api_version() failed: %d\n", err);
1039 goto err_get_api_ver;
1040 }
1041
1042 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
1043 minor_ver < DPIO_VER_MINOR)) {
1044 printf("DPRC version mismatch found %u.%u,",
1045 major_ver,
1046 minor_ver);
1047 }
1048
1049 err = dpio_open(dflt_mc_io,
1050 MC_CMD_NO_FLAGS,
1051 dflt_dpio->dpio_id,
1052 &dflt_dpio->dpio_handle);
1053 if (err) {
1054 printf("dpio_open() failed\n");
1055 goto err_open;
1056 }
1057
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301058 memset(&attr, 0, sizeof(struct dpio_attr));
Prabhakar Kushwaha9564df62015-07-07 15:40:06 +05301059 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301060 dflt_dpio->dpio_handle, &attr);
1061 if (err < 0) {
1062 printf("dpio_get_attributes() failed: %d\n", err);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001063 goto err_get_attr;
1064 }
1065
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301066 if (dflt_dpio->dpio_id != attr.id) {
1067 printf("dnpi object id and attribute id are not same\n");
1068 goto err_attr_not_same;
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +05301069 }
1070
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301071#ifdef DEBUG
1072 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1073#endif
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301074 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1075 if (err < 0) {
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001076 printf("dpio_enable() failed %d\n", err);
1077 goto err_get_enable;
1078 }
Prabhakar Kushwahafd5d1272015-07-02 11:28:59 +05301079 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
1080 attr.qbman_portal_ce_offset,
1081 attr.qbman_portal_ci_offset,
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001082 attr.qbman_portal_id,
1083 attr.num_priorities);
1084
Prabhakar Kushwahafd5d1272015-07-02 11:28:59 +05301085 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1086 + attr.qbman_portal_ce_offset);
1087 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1088 + attr.qbman_portal_ci_offset);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001089
1090 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
1091 if (dflt_dpio->sw_portal == NULL) {
1092 printf("qbman_swp_init() failed\n");
1093 goto err_get_swp_init;
1094 }
1095 return 0;
1096
1097err_get_swp_init:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301098 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001099err_get_enable:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301100err_get_attr:
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301101err_attr_not_same:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301102 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301103err_open:
1104err_get_api_ver:
1105 dpio_destroy(dflt_mc_io,
1106 dflt_dprc_handle,
1107 MC_CMD_NO_FLAGS,
1108 dflt_dpio->dpio_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301109err_create:
Prabhakar Kushwahac6018bd2016-03-18 16:15:29 +05301110 free(dflt_dpio);
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301111err_calloc:
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001112 return err;
1113}
1114
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301115static int dpio_exit(void)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001116{
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301117 int err;
1118
1119 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1120 if (err < 0) {
1121 printf("dpio_disable() failed: %d\n", err);
1122 goto err;
1123 }
1124
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301125 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1126 if (err < 0) {
1127 printf("dpio_close() failed: %d\n", err);
1128 goto err;
1129 }
1130
1131 err = dpio_destroy(dflt_mc_io,
1132 dflt_dprc_handle,
1133 MC_CMD_NO_FLAGS,
1134 dflt_dpio->dpio_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301135 if (err < 0) {
1136 printf("dpio_destroy() failed: %d\n", err);
1137 goto err;
1138 }
1139
1140#ifdef DEBUG
1141 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1142#endif
1143
1144 if (dflt_dpio)
1145 free(dflt_dpio);
1146
1147 return 0;
1148err:
1149 return err;
1150}
1151
1152static int dprc_init(void)
1153{
1154 int err, child_portal_id, container_id;
1155 struct dprc_cfg cfg;
1156 uint64_t mc_portal_offset;
1157
1158 /* Open root container */
1159 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1160 if (err < 0) {
1161 printf("dprc_get_container_id(): Root failed: %d\n", err);
1162 goto err_root_container_id;
1163 }
1164
1165#ifdef DEBUG
1166 printf("Root container id = %d\n", container_id);
1167#endif
1168 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1169 &root_dprc_handle);
1170 if (err < 0) {
1171 printf("dprc_open(): Root Container failed: %d\n", err);
1172 goto err_root_open;
1173 }
1174
1175 if (!root_dprc_handle) {
1176 printf("dprc_open(): Root Container Handle is not valid\n");
1177 goto err_root_open;
1178 }
1179
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +05301180 err = dprc_version_check(root_mc_io, root_dprc_handle);
1181 if (err < 0) {
1182 printf("dprc_version_check() failed: %d\n", err);
1183 goto err_root_open;
1184 }
1185
Prabhakar Kushwaha901a88e2016-01-20 12:04:19 +05301186 memset(&cfg, 0, sizeof(struct dprc_cfg));
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301187 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1188 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1189 DPRC_CFG_OPT_ALLOC_ALLOWED;
1190 cfg.icid = DPRC_GET_ICID_FROM_POOL;
Prabhakar Kushwaha7fd59d92015-12-24 15:33:49 +05301191 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301192 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1193 root_dprc_handle,
1194 &cfg,
1195 &child_dprc_id,
1196 &mc_portal_offset);
1197 if (err < 0) {
1198 printf("dprc_create_container() failed: %d\n", err);
1199 goto err_create;
1200 }
1201
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301202 dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301203 if (!dflt_mc_io) {
1204 err = -ENOMEM;
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301205 printf(" No memory: calloc() failed\n");
1206 goto err_calloc;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301207 }
1208
1209 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1210 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301211
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301212#ifdef DEBUG
1213 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1214 child_dprc_id, dflt_mc_io->mmio_regs);
1215#endif
1216
1217 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1218 &dflt_dprc_handle);
1219 if (err < 0) {
1220 printf("dprc_open(): Child container failed: %d\n", err);
1221 goto err_child_open;
1222 }
1223
1224 if (!dflt_dprc_handle) {
1225 printf("dprc_open(): Child container Handle is not valid\n");
1226 goto err_child_open;
1227 }
1228
1229 return 0;
1230err_child_open:
1231 free(dflt_mc_io);
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301232err_calloc:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301233 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1234 root_dprc_handle, child_dprc_id);
1235err_create:
1236 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1237err_root_open:
1238err_root_container_id:
1239 return err;
1240}
1241
1242static int dprc_exit(void)
1243{
1244 int err;
1245
1246 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1247 if (err < 0) {
1248 printf("dprc_close(): Child failed: %d\n", err);
1249 goto err;
1250 }
1251
1252 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1253 root_dprc_handle, child_dprc_id);
1254 if (err < 0) {
1255 printf("dprc_destroy_container() failed: %d\n", err);
1256 goto err;
1257 }
1258
1259 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1260 if (err < 0) {
1261 printf("dprc_close(): Root failed: %d\n", err);
1262 goto err;
1263 }
1264
1265 if (dflt_mc_io)
1266 free(dflt_mc_io);
1267
1268 if (root_mc_io)
1269 free(root_mc_io);
1270
1271 return 0;
1272
1273err:
1274 return err;
1275}
1276
1277static int dpbp_init(void)
1278{
1279 int err;
1280 struct dpbp_attr dpbp_attr;
1281 struct dpbp_cfg dpbp_cfg;
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301282 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301283
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301284 dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
1285 sizeof(struct fsl_dpbp_obj), 1);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001286 if (!dflt_dpbp) {
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301287 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301288 err = -ENOMEM;
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301289 goto err_calloc;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301290 }
1291
1292 dpbp_cfg.options = 512;
1293
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301294 err = dpbp_create(dflt_mc_io,
1295 dflt_dprc_handle,
1296 MC_CMD_NO_FLAGS,
1297 &dpbp_cfg,
1298 &dflt_dpbp->dpbp_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301299
1300 if (err < 0) {
1301 err = -ENODEV;
1302 printf("dpbp_create() failed: %d\n", err);
1303 goto err_create;
1304 }
1305
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301306 err = dpbp_get_api_version(dflt_mc_io, 0,
1307 &major_ver,
1308 &minor_ver);
1309 if (err < 0) {
1310 printf("dpbp_get_api_version() failed: %d\n", err);
1311 goto err_get_api_ver;
1312 }
1313
1314 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1315 minor_ver < DPBP_VER_MINOR)) {
1316 printf("DPBP version mismatch found %u.%u,",
1317 major_ver, minor_ver);
1318 printf("supported version is %u.%u\n",
1319 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1320 }
1321
1322 err = dpbp_open(dflt_mc_io,
1323 MC_CMD_NO_FLAGS,
1324 dflt_dpbp->dpbp_id,
1325 &dflt_dpbp->dpbp_handle);
1326 if (err) {
1327 printf("dpbp_open() failed\n");
1328 goto err_open;
1329 }
1330
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301331 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1332 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1333 dflt_dpbp->dpbp_handle,
1334 &dpbp_attr);
1335 if (err < 0) {
1336 printf("dpbp_get_attributes() failed: %d\n", err);
1337 goto err_get_attr;
1338 }
1339
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301340 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1341 printf("dpbp object id and attribute id are not same\n");
1342 goto err_attr_not_same;
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +05301343 }
1344
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301345#ifdef DEBUG
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301346 printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301347#endif
1348
1349 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1350 if (err < 0) {
1351 printf("dpbp_close() failed: %d\n", err);
1352 goto err_close;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001353 }
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001354
1355 return 0;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301356
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301357err_get_attr:
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301358err_attr_not_same:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301359 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301360 dpbp_destroy(dflt_mc_io,
1361 dflt_dprc_handle,
1362 MC_CMD_NO_FLAGS,
1363 dflt_dpbp->dpbp_id);
1364err_get_api_ver:
1365err_close:
1366err_open:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301367err_create:
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301368 free(dflt_dpbp);
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301369err_calloc:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301370 return err;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001371}
1372
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301373static int dpbp_exit(void)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001374{
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301375 int err;
1376
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301377 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1378 dflt_dpbp->dpbp_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301379 if (err < 0) {
1380 printf("dpbp_destroy() failed: %d\n", err);
1381 goto err;
1382 }
1383
1384#ifdef DEBUG
1385 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1386#endif
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001387
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301388 if (dflt_dpbp)
1389 free(dflt_dpbp);
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301390 return 0;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301391
1392err:
1393 return err;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001394}
1395
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301396static int dpni_init(void)
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001397{
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301398 int err;
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301399 uint8_t cfg_buf[256] = {0};
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301400 struct dpni_cfg dpni_cfg;
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301401 uint16_t major_ver, minor_ver;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301402
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301403 dflt_dpni = (struct fsl_dpni_obj *)calloc(
1404 sizeof(struct fsl_dpni_obj), 1);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301405 if (!dflt_dpni) {
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301406 printf("No memory: calloc() failed\n");
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301407 err = -ENOMEM;
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301408 goto err_calloc;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301409 }
1410
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301411 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1412 err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
Prabhakar Kushwahae26e2852015-12-24 15:33:01 +05301413 if (err < 0) {
1414 err = -ENODEV;
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301415 printf("dpni_prepare_cfg() failed: %d\n", err);
1416 goto err_prepare_cfg;
Prabhakar Kushwahae26e2852015-12-24 15:33:01 +05301417 }
1418
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301419 err = dpni_create(dflt_mc_io,
1420 dflt_dprc_handle,
1421 MC_CMD_NO_FLAGS,
1422 &dpni_cfg,
1423 &dflt_dpni->dpni_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301424 if (err < 0) {
1425 err = -ENODEV;
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301426 printf("dpni create() failed: %d\n", err);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301427 goto err_create;
1428 }
1429
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301430 err = dpni_get_api_version(dflt_mc_io, 0,
1431 &major_ver,
1432 &minor_ver);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301433 if (err < 0) {
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301434 printf("dpni_get_api_version() failed: %d\n", err);
1435 goto err_get_version;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301436 }
1437
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301438 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1439 minor_ver < DPNI_VER_MINOR)) {
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +05301440 printf("DPNI version mismatch found %u.%u,",
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301441 major_ver, minor_ver);
Prabhakar Kushwaha0a4156c2015-12-24 15:32:37 +05301442 printf("supported version is %u.%u\n",
1443 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1444 }
1445
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301446 err = dpni_open(dflt_mc_io,
1447 MC_CMD_NO_FLAGS,
1448 dflt_dpni->dpni_id,
1449 &dflt_dpni->dpni_handle);
1450 if (err) {
1451 printf("dpni_open() failed\n");
1452 goto err_open;
1453 }
1454
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301455#ifdef DEBUG
1456 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1457#endif
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301458 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1459 if (err < 0) {
1460 printf("dpni_close() failed: %d\n", err);
1461 goto err_close;
1462 }
1463
1464 return 0;
1465
1466err_close:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301467 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301468err_open:
1469err_get_version:
1470 dpni_destroy(dflt_mc_io,
1471 dflt_dprc_handle,
1472 MC_CMD_NO_FLAGS,
1473 dflt_dpni->dpni_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301474err_create:
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301475err_prepare_cfg:
Prabhakar Kushwahae26e2852015-12-24 15:33:01 +05301476 free(dflt_dpni);
Prabhakar Kushwaha790c1a42017-10-11 08:51:18 +05301477err_calloc:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301478 return err;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001479}
1480
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301481static int dpni_exit(void)
1482{
1483 int err;
1484
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301485 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1486 dflt_dpni->dpni_id);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301487 if (err < 0) {
1488 printf("dpni_destroy() failed: %d\n", err);
1489 goto err;
1490 }
1491
1492#ifdef DEBUG
1493 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1494#endif
1495
1496 if (dflt_dpni)
1497 free(dflt_dpni);
1498 return 0;
1499
1500err:
1501 return err;
1502}
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001503
1504static bool is_dpsparser_supported(void)
1505{
1506 /* dpsparser support was first introduced in MC version: 10.12.0 */
1507 if (mc_ver_info.major < 10)
1508 return false;
1509 if (mc_ver_info.major == 10)
1510 return (mc_ver_info.minor >= 12);
1511 return true;
1512}
1513
1514static int dpsparser_version_check(struct fsl_mc_io *mc_io)
1515{
1516 int error;
1517 u16 major_ver, minor_ver;
1518
1519 if (!is_dpsparser_supported())
1520 return 0;
1521
1522 error = dpsparser_get_api_version(mc_io, 0,
1523 &major_ver,
1524 &minor_ver);
1525 if (error < 0) {
1526 printf("dpsparser_get_api_version() failed: %d\n", error);
1527 return error;
1528 }
1529
1530 if (major_ver < DPSPARSER_VER_MAJOR || (major_ver ==
1531 DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) {
1532 printf("DPSPARSER version mismatch found %u.%u,",
1533 major_ver, minor_ver);
1534 printf("supported version is %u.%u\n",
1535 DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR);
1536 }
1537
1538 return error;
1539}
1540
1541static int dpsparser_init(void)
1542{
1543 int err = 0;
1544
1545 if (!is_dpsparser_supported())
1546 return 0;
1547
1548 err = dpsparser_create(dflt_mc_io,
1549 dflt_dprc_handle,
1550 MC_CMD_NO_FLAGS,
1551 &dpsparser_obj_id);
1552 if (err)
1553 printf("dpsparser_create() failed\n");
1554
1555 err = dpsparser_version_check(dflt_mc_io);
1556 if (err < 0) {
1557 printf("dpsparser_version_check() failed: %d\n", err);
1558 goto err_version_check;
1559 }
1560
1561 err = dpsparser_open(dflt_mc_io,
1562 MC_CMD_NO_FLAGS,
1563 &dpsparser_handle);
1564 if (err < 0) {
1565 printf("dpsparser_open() failed: %d\n", err);
1566 goto err_open;
1567 }
1568
1569 return err;
1570
1571err_open:
1572err_version_check:
1573 dpsparser_destroy(dflt_mc_io,
1574 dflt_dprc_handle,
1575 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1576
1577 return err;
1578}
1579
1580#ifdef DPSPARSER_DESTROY
1581/* TODO: refactoring needed in the future to allow DPSPARSER object destroy
1582 * Workaround: DO NOT destroy DPSPARSER object because it needs to be available
1583 * on Apply DPL
1584 */
1585static int dpsparser_exit(void)
1586{
1587 int err;
1588
1589 if (!is_dpsparser_supported())
1590 return 0;
1591
1592 dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle);
1593 if (err < 0) {
1594 printf("dpsparser_close() failed: %d\n", err);
1595 goto err;
1596 }
1597
1598 err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle,
1599 MC_CMD_NO_FLAGS, dpsparser_obj_id);
1600 if (err < 0) {
1601 printf("dpsparser_destroy() failed: %d\n", err);
1602 goto err;
1603 }
1604 return 0;
1605
1606err:
1607 return err;
1608}
1609#endif
1610
1611int mc_apply_spb(u64 mc_spb_addr)
1612{
1613 int err = 0;
1614 u16 error, err_arr_size;
1615 u64 mc_spb_offset;
1616 u32 spb_size;
1617 struct sp_blob_header *sp_blob;
1618 u64 mc_ram_addr = mc_get_dram_addr();
1619
1620 if (!is_dpsparser_supported())
1621 return 0;
1622
1623 if (!mc_spb_addr) {
1624 printf("fsl-mc: Invalid Blob address\n");
1625 return -1;
1626 }
1627
1628#ifdef CONFIG_MC_DRAM_SPB_OFFSET
1629 mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET;
1630#else
1631#error "CONFIG_MC_DRAM_SPB_OFFSET not defined"
1632#endif
1633
1634 // Read blob header and get size of SPB blob
1635 sp_blob = (struct sp_blob_header *)mc_spb_addr;
1636 spb_size = le32_to_cpu(sp_blob->length);
1637 if (spb_size > CONFIG_MC_SPB_MAX_SIZE) {
1638 printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n",
1639 spb_size);
1640 return -EINVAL;
1641 }
1642
1643 mc_copy_image("MC SP Blob", mc_spb_addr, spb_size,
1644 mc_ram_addr + mc_spb_offset);
1645
1646 //Invoke MC command to apply SPB blob
1647 printf("fsl-mc: Applying soft parser blob... ");
1648 err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle,
1649 mc_spb_offset, &error);
1650 if (err)
1651 return err;
1652
1653 if (error == 0) {
1654 printf("SUCCESS\n");
1655 } else {
1656 printf("FAILED with error code = %d:\n", error);
1657 err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb);
1658
1659 if (error > 0 && error < err_arr_size)
1660 printf(mc_err_msg_apply_spb[error]);
1661 else
1662 printf(MC_ERROR_MSG_SPB_UNKNOWN);
1663 }
1664
1665 return err;
1666}
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301667
1668static int mc_init_object(void)
1669{
1670 int err = 0;
1671
1672 err = dprc_init();
1673 if (err < 0) {
1674 printf("dprc_init() failed: %d\n", err);
1675 goto err;
1676 }
1677
1678 err = dpbp_init();
1679 if (err < 0) {
1680 printf("dpbp_init() failed: %d\n", err);
1681 goto err;
1682 }
1683
1684 err = dpio_init();
1685 if (err < 0) {
1686 printf("dpio_init() failed: %d\n", err);
1687 goto err;
1688 }
1689
1690 err = dpni_init();
1691 if (err < 0) {
1692 printf("dpni_init() failed: %d\n", err);
1693 goto err;
1694 }
1695
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001696 err = dpsparser_init();
1697 if (err < 0) {
1698 printf("dpsparser_init() failed: %d\n", err);
1699 goto err;
1700 }
1701
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301702 return 0;
1703err:
1704 return err;
1705}
1706
1707int fsl_mc_ldpaa_exit(bd_t *bd)
1708{
1709 int err = 0;
Yogesh Gaur4a81bbe2017-04-27 10:14:16 +05301710 bool is_dpl_apply_status = false;
Santan Kumar0a6e5ba2017-06-29 11:19:34 +05301711 bool mc_boot_status = false;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301712
Alexander Graf2ebeb442016-11-17 01:02:57 +01001713 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
Yogesh Gaur8dadfb42018-01-16 10:08:24 +05301714 err = mc_apply_dpl(mc_lazy_dpl_addr);
1715 if (!err)
1716 fdt_fixup_board_enet(working_fdt);
Alexander Graf2ebeb442016-11-17 01:02:57 +01001717 mc_lazy_dpl_addr = 0;
1718 }
1719
Santan Kumar0a6e5ba2017-06-29 11:19:34 +05301720 if (!get_mc_boot_status())
1721 mc_boot_status = true;
1722
Prabhakar Kushwaha878d3ec2016-03-21 14:19:39 +05301723 /* MC is not loaded intentionally, So return success. */
Santan Kumar0a6e5ba2017-06-29 11:19:34 +05301724 if (bd && !mc_boot_status)
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301725 return 0;
1726
Yogesh Gaur4a81bbe2017-04-27 10:14:16 +05301727 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1728 if (!get_dpl_apply_status())
1729 is_dpl_apply_status = true;
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301730
Yogesh Gaur4a81bbe2017-04-27 10:14:16 +05301731 /*
1732 * For case MC is loaded but DPL is not deployed, return success and
1733 * print message on console. Else FDT fix-up code execution hanged.
1734 */
Santan Kumar0a6e5ba2017-06-29 11:19:34 +05301735 if (bd && mc_boot_status && !is_dpl_apply_status) {
Yogesh Gaur4a81bbe2017-04-27 10:14:16 +05301736 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
Yogesh Gaur82709e52017-11-28 10:11:14 +05301737 goto mc_obj_cleanup;
Yogesh Gaur4a81bbe2017-04-27 10:14:16 +05301738 }
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301739
Santan Kumar0a6e5ba2017-06-29 11:19:34 +05301740 if (bd && mc_boot_status && is_dpl_apply_status)
1741 return 0;
1742
Yogesh Gaur82709e52017-11-28 10:11:14 +05301743mc_obj_cleanup:
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301744 err = dpbp_exit();
1745 if (err < 0) {
Prabhakar Kushwaha88ba4d62016-01-20 12:04:37 +05301746 printf("dpbp_exit() failed: %d\n", err);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301747 goto err;
1748 }
1749
1750 err = dpio_exit();
1751 if (err < 0) {
1752 printf("dpio_exit() failed: %d\n", err);
1753 goto err;
1754 }
1755
1756 err = dpni_exit();
1757 if (err < 0) {
1758 printf("dpni_exit() failed: %d\n", err);
1759 goto err;
1760 }
1761
1762 err = dprc_exit();
1763 if (err < 0) {
1764 printf("dprc_exit() failed: %d\n", err);
1765 goto err;
1766 }
1767
1768 return 0;
1769err:
1770 return err;
1771}
1772
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301773static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001774{
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301775 int err = 0;
1776 if (argc < 3)
1777 goto usage;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001778
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301779 switch (argv[1][0]) {
1780 case 's': {
1781 char sub_cmd;
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +05301782 u64 mc_fw_addr, mc_dpc_addr;
1783#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1784 u64 aiop_fw_addr;
1785#endif
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001786
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301787 sub_cmd = argv[2][0];
Yogesh Gaur318c32f2017-11-15 11:59:31 +05301788
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301789 switch (sub_cmd) {
1790 case 'm':
1791 if (argc < 5)
1792 goto usage;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001793
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301794 if (get_mc_boot_status() == 0) {
1795 printf("fsl-mc: MC is already booted");
1796 printf("\n");
1797 return err;
1798 }
1799 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1800 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1801 16);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301802
1803 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1804 err = mc_init_object();
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301805 break;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001806
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301807#ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1808 case 'a':
1809 if (argc < 4)
1810 goto usage;
1811 if (get_aiop_apply_status() == 0) {
1812 printf("fsl-mc: AIOP FW is already");
1813 printf(" applied\n");
1814 return err;
1815 }
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001816
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301817 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1818 16);
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001819
York Suncbe8e1c2016-04-04 11:41:26 -07001820 /* if SoC doesn't have AIOP, err = -ENODEV */
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301821 err = load_mc_aiop_img(aiop_fw_addr);
1822 if (!err)
1823 printf("fsl-mc: AIOP FW applied\n");
1824 break;
1825#endif
1826 default:
1827 printf("Invalid option: %s\n", argv[2]);
1828 goto usage;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001829
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301830 break;
1831 }
1832 }
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001833 break;
1834
1835 case 'l': {
1836 /* lazyapply */
1837 u64 mc_dpl_addr;
1838
1839 if (argc < 4)
1840 goto usage;
1841
1842 if (get_dpl_apply_status() == 0) {
1843 printf("fsl-mc: DPL already applied\n");
1844 return err;
1845 }
1846
1847 mc_dpl_addr = simple_strtoull(argv[3], NULL, 16);
1848
1849 if (get_mc_boot_status() != 0) {
1850 printf("fsl-mc: Deploying data path layout ..");
1851 printf("ERROR (MC is not booted)\n");
1852 return -ENODEV;
1853 }
1854
1855 /*
1856 * We will do the actual dpaa exit and dpl apply
1857 * later from announce_and_cleanup().
1858 */
1859 mc_lazy_dpl_addr = mc_dpl_addr;
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301860 break;
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001861 }
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001862
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301863 case 'a': {
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001864 /* apply */
1865 char sub_cmd;
1866 u64 mc_apply_addr;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001867
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001868 if (argc < 4)
1869 goto usage;
1870
1871 sub_cmd = argv[2][0];
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001872
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001873 switch (sub_cmd) {
1874 case 'd':
1875 case 'D':
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301876 if (get_dpl_apply_status() == 0) {
1877 printf("fsl-mc: DPL already applied\n");
1878 return err;
1879 }
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301880 if (get_mc_boot_status() != 0) {
1881 printf("fsl-mc: Deploying data path layout ..");
1882 printf("ERROR (MC is not booted)\n");
1883 return -ENODEV;
1884 }
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +05301885
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001886 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1887
1888 /* The user wants DPL applied now */
1889 if (!fsl_mc_ldpaa_exit(NULL))
1890 err = mc_apply_dpl(mc_apply_addr);
1891 break;
1892
1893 case 's':
1894 if (!is_dpsparser_supported()) {
1895 printf("fsl-mc: apply spb command .. ");
1896 printf("ERROR: requires at least MC 10.12.0\n");
1897 return err;
Alexander Graf2ebeb442016-11-17 01:02:57 +01001898 }
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001899 if (get_mc_boot_status() != 0) {
1900 printf("fsl-mc: Deploying Soft Parser Blob...");
1901 printf("ERROR (MC is not booted)\n");
1902 return err;
1903 }
1904
1905 mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
1906
1907 /* Apply spb (Soft Parser Blob) */
1908 err = mc_apply_spb(mc_apply_addr);
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301909 break;
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001910
1911 default:
1912 printf("Invalid option: %s\n", argv[2]);
1913 goto usage;
1914 }
1915 break;
J. German Riveraf4fed4b2015-03-20 19:28:18 -07001916 }
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301917 default:
1918 printf("Invalid option: %s\n", argv[1]);
1919 goto usage;
1920 break;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001921 }
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301922 return err;
1923 usage:
1924 return CMD_RET_USAGE;
Prabhakar Kushwahacfd9fbf2015-03-19 09:20:45 -07001925}
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301926
1927U_BOOT_CMD(
1928 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1929 "DPAA2 command to manage Management Complex (MC)",
1930 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1931 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
Alexander Graf2ebeb442016-11-17 01:02:57 +01001932 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
Florinel Iordacheae6d8522019-11-19 10:28:17 +00001933 "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n"
Prabhakar Kushwaha29a63e42015-11-04 12:25:58 +05301934 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1935);
Bogdan Purcareata08bc0142017-05-24 16:40:21 +00001936
1937void mc_env_boot(void)
1938{
1939#if defined(CONFIG_FSL_MC_ENET)
1940 char *mc_boot_env_var;
1941 /* The MC may only be initialized in the reset PHY function
1942 * because otherwise U-Boot has not yet set up all the MAC
1943 * address info properly. Without MAC addresses, the MC code
1944 * can not properly initialize the DPC.
1945 */
Simon Glass64b723f2017-08-03 12:22:12 -06001946 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
Bogdan Purcareata08bc0142017-05-24 16:40:21 +00001947 if (mc_boot_env_var)
1948 run_command_list(mc_boot_env_var, -1, 0);
1949#endif /* CONFIG_FSL_MC_ENET */
1950}