mc.c 45 KB

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