mc.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2014 Freescale Semiconductor, Inc.
  4. * Copyright 2017-2018, 2020 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 = simple_strtoul(timeout_ms_env_var, NULL, 10);
  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 = simple_strtoul(dram_block_size_env_var, NULL,
  812. 16);
  813. if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
  814. printf("fsl-mc: WARNING: Invalid value for \'"
  815. MC_MEM_SIZE_ENV_VAR
  816. "\' environment variable: %lu\n",
  817. dram_block_size);
  818. dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE;
  819. }
  820. }
  821. return dram_block_size;
  822. }
  823. int fsl_mc_ldpaa_init(struct bd_info *bis)
  824. {
  825. int i;
  826. for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
  827. if (wriop_is_enabled_dpmac(i) == 1)
  828. ldpaa_eth_init(i, wriop_get_enet_if(i));
  829. return 0;
  830. }
  831. static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
  832. {
  833. int error;
  834. uint16_t major_ver, minor_ver;
  835. error = dprc_get_api_version(mc_io, 0,
  836. &major_ver,
  837. &minor_ver);
  838. if (error < 0) {
  839. printf("dprc_get_api_version() failed: %d\n", error);
  840. return error;
  841. }
  842. if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
  843. minor_ver < DPRC_VER_MINOR)) {
  844. printf("DPRC version mismatch found %u.%u,",
  845. major_ver, minor_ver);
  846. printf("supported version is %u.%u\n",
  847. DPRC_VER_MAJOR, DPRC_VER_MINOR);
  848. }
  849. return error;
  850. }
  851. static int dpio_init(void)
  852. {
  853. struct qbman_swp_desc p_des;
  854. struct dpio_attr attr;
  855. struct dpio_cfg dpio_cfg;
  856. int err = 0;
  857. uint16_t major_ver, minor_ver;
  858. dflt_dpio = (struct fsl_dpio_obj *)calloc(
  859. sizeof(struct fsl_dpio_obj), 1);
  860. if (!dflt_dpio) {
  861. printf("No memory: calloc() failed\n");
  862. err = -ENOMEM;
  863. goto err_calloc;
  864. }
  865. dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
  866. dpio_cfg.num_priorities = 8;
  867. err = dpio_create(dflt_mc_io,
  868. dflt_dprc_handle,
  869. MC_CMD_NO_FLAGS,
  870. &dpio_cfg,
  871. &dflt_dpio->dpio_id);
  872. if (err < 0) {
  873. printf("dpio_create() failed: %d\n", err);
  874. err = -ENODEV;
  875. goto err_create;
  876. }
  877. err = dpio_get_api_version(dflt_mc_io, 0,
  878. &major_ver,
  879. &minor_ver);
  880. if (err < 0) {
  881. printf("dpio_get_api_version() failed: %d\n", err);
  882. goto err_get_api_ver;
  883. }
  884. if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
  885. minor_ver < DPIO_VER_MINOR)) {
  886. printf("DPRC version mismatch found %u.%u,",
  887. major_ver,
  888. minor_ver);
  889. }
  890. err = dpio_open(dflt_mc_io,
  891. MC_CMD_NO_FLAGS,
  892. dflt_dpio->dpio_id,
  893. &dflt_dpio->dpio_handle);
  894. if (err) {
  895. printf("dpio_open() failed\n");
  896. goto err_open;
  897. }
  898. memset(&attr, 0, sizeof(struct dpio_attr));
  899. err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
  900. dflt_dpio->dpio_handle, &attr);
  901. if (err < 0) {
  902. printf("dpio_get_attributes() failed: %d\n", err);
  903. goto err_get_attr;
  904. }
  905. if (dflt_dpio->dpio_id != attr.id) {
  906. printf("dnpi object id and attribute id are not same\n");
  907. goto err_attr_not_same;
  908. }
  909. #ifdef DEBUG
  910. printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
  911. #endif
  912. err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  913. if (err < 0) {
  914. printf("dpio_enable() failed %d\n", err);
  915. goto err_get_enable;
  916. }
  917. debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
  918. attr.qbman_portal_ce_offset,
  919. attr.qbman_portal_ci_offset,
  920. attr.qbman_portal_id,
  921. attr.num_priorities);
  922. p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
  923. + attr.qbman_portal_ce_offset);
  924. p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
  925. + attr.qbman_portal_ci_offset);
  926. dflt_dpio->sw_portal = qbman_swp_init(&p_des);
  927. if (dflt_dpio->sw_portal == NULL) {
  928. printf("qbman_swp_init() failed\n");
  929. goto err_get_swp_init;
  930. }
  931. return 0;
  932. err_get_swp_init:
  933. dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  934. err_get_enable:
  935. err_get_attr:
  936. err_attr_not_same:
  937. dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  938. err_open:
  939. err_get_api_ver:
  940. dpio_destroy(dflt_mc_io,
  941. dflt_dprc_handle,
  942. MC_CMD_NO_FLAGS,
  943. dflt_dpio->dpio_id);
  944. err_create:
  945. free(dflt_dpio);
  946. err_calloc:
  947. return err;
  948. }
  949. static int dpio_exit(void)
  950. {
  951. int err;
  952. err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  953. if (err < 0) {
  954. printf("dpio_disable() failed: %d\n", err);
  955. goto err;
  956. }
  957. dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  958. if (err < 0) {
  959. printf("dpio_close() failed: %d\n", err);
  960. goto err;
  961. }
  962. err = dpio_destroy(dflt_mc_io,
  963. dflt_dprc_handle,
  964. MC_CMD_NO_FLAGS,
  965. dflt_dpio->dpio_id);
  966. if (err < 0) {
  967. printf("dpio_destroy() failed: %d\n", err);
  968. goto err;
  969. }
  970. #ifdef DEBUG
  971. printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
  972. #endif
  973. if (dflt_dpio)
  974. free(dflt_dpio);
  975. return 0;
  976. err:
  977. return err;
  978. }
  979. static int dprc_init(void)
  980. {
  981. int err, child_portal_id, container_id;
  982. struct dprc_cfg cfg;
  983. uint64_t mc_portal_offset;
  984. /* Open root container */
  985. err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
  986. if (err < 0) {
  987. printf("dprc_get_container_id(): Root failed: %d\n", err);
  988. goto err_root_container_id;
  989. }
  990. #ifdef DEBUG
  991. printf("Root container id = %d\n", container_id);
  992. #endif
  993. err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
  994. &root_dprc_handle);
  995. if (err < 0) {
  996. printf("dprc_open(): Root Container failed: %d\n", err);
  997. goto err_root_open;
  998. }
  999. if (!root_dprc_handle) {
  1000. printf("dprc_open(): Root Container Handle is not valid\n");
  1001. goto err_root_open;
  1002. }
  1003. err = dprc_version_check(root_mc_io, root_dprc_handle);
  1004. if (err < 0) {
  1005. printf("dprc_version_check() failed: %d\n", err);
  1006. goto err_root_open;
  1007. }
  1008. memset(&cfg, 0, sizeof(struct dprc_cfg));
  1009. cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
  1010. DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
  1011. DPRC_CFG_OPT_ALLOC_ALLOWED;
  1012. cfg.icid = DPRC_GET_ICID_FROM_POOL;
  1013. cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
  1014. err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
  1015. root_dprc_handle,
  1016. &cfg,
  1017. &child_dprc_id,
  1018. &mc_portal_offset);
  1019. if (err < 0) {
  1020. printf("dprc_create_container() failed: %d\n", err);
  1021. goto err_create;
  1022. }
  1023. dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
  1024. if (!dflt_mc_io) {
  1025. err = -ENOMEM;
  1026. printf(" No memory: calloc() failed\n");
  1027. goto err_calloc;
  1028. }
  1029. child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
  1030. dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
  1031. #ifdef DEBUG
  1032. printf("MC portal of child DPRC container: %d, physical addr %p)\n",
  1033. child_dprc_id, dflt_mc_io->mmio_regs);
  1034. #endif
  1035. err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
  1036. &dflt_dprc_handle);
  1037. if (err < 0) {
  1038. printf("dprc_open(): Child container failed: %d\n", err);
  1039. goto err_child_open;
  1040. }
  1041. if (!dflt_dprc_handle) {
  1042. printf("dprc_open(): Child container Handle is not valid\n");
  1043. goto err_child_open;
  1044. }
  1045. return 0;
  1046. err_child_open:
  1047. free(dflt_mc_io);
  1048. err_calloc:
  1049. dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
  1050. root_dprc_handle, child_dprc_id);
  1051. err_create:
  1052. dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
  1053. err_root_open:
  1054. err_root_container_id:
  1055. return err;
  1056. }
  1057. static int dprc_exit(void)
  1058. {
  1059. int err;
  1060. err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
  1061. if (err < 0) {
  1062. printf("dprc_close(): Child failed: %d\n", err);
  1063. goto err;
  1064. }
  1065. err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
  1066. root_dprc_handle, child_dprc_id);
  1067. if (err < 0) {
  1068. printf("dprc_destroy_container() failed: %d\n", err);
  1069. goto err;
  1070. }
  1071. err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
  1072. if (err < 0) {
  1073. printf("dprc_close(): Root failed: %d\n", err);
  1074. goto err;
  1075. }
  1076. if (dflt_mc_io)
  1077. free(dflt_mc_io);
  1078. if (root_mc_io)
  1079. free(root_mc_io);
  1080. return 0;
  1081. err:
  1082. return err;
  1083. }
  1084. static int dpbp_init(void)
  1085. {
  1086. int err;
  1087. struct dpbp_attr dpbp_attr;
  1088. struct dpbp_cfg dpbp_cfg;
  1089. uint16_t major_ver, minor_ver;
  1090. dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
  1091. sizeof(struct fsl_dpbp_obj), 1);
  1092. if (!dflt_dpbp) {
  1093. printf("No memory: calloc() failed\n");
  1094. err = -ENOMEM;
  1095. goto err_calloc;
  1096. }
  1097. dpbp_cfg.options = 512;
  1098. err = dpbp_create(dflt_mc_io,
  1099. dflt_dprc_handle,
  1100. MC_CMD_NO_FLAGS,
  1101. &dpbp_cfg,
  1102. &dflt_dpbp->dpbp_id);
  1103. if (err < 0) {
  1104. err = -ENODEV;
  1105. printf("dpbp_create() failed: %d\n", err);
  1106. goto err_create;
  1107. }
  1108. err = dpbp_get_api_version(dflt_mc_io, 0,
  1109. &major_ver,
  1110. &minor_ver);
  1111. if (err < 0) {
  1112. printf("dpbp_get_api_version() failed: %d\n", err);
  1113. goto err_get_api_ver;
  1114. }
  1115. if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
  1116. minor_ver < DPBP_VER_MINOR)) {
  1117. printf("DPBP version mismatch found %u.%u,",
  1118. major_ver, minor_ver);
  1119. printf("supported version is %u.%u\n",
  1120. DPBP_VER_MAJOR, DPBP_VER_MINOR);
  1121. }
  1122. err = dpbp_open(dflt_mc_io,
  1123. MC_CMD_NO_FLAGS,
  1124. dflt_dpbp->dpbp_id,
  1125. &dflt_dpbp->dpbp_handle);
  1126. if (err) {
  1127. printf("dpbp_open() failed\n");
  1128. goto err_open;
  1129. }
  1130. memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
  1131. err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
  1132. dflt_dpbp->dpbp_handle,
  1133. &dpbp_attr);
  1134. if (err < 0) {
  1135. printf("dpbp_get_attributes() failed: %d\n", err);
  1136. goto err_get_attr;
  1137. }
  1138. if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
  1139. printf("dpbp object id and attribute id are not same\n");
  1140. goto err_attr_not_same;
  1141. }
  1142. #ifdef DEBUG
  1143. printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
  1144. #endif
  1145. err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
  1146. if (err < 0) {
  1147. printf("dpbp_close() failed: %d\n", err);
  1148. goto err_close;
  1149. }
  1150. return 0;
  1151. err_get_attr:
  1152. err_attr_not_same:
  1153. dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
  1154. dpbp_destroy(dflt_mc_io,
  1155. dflt_dprc_handle,
  1156. MC_CMD_NO_FLAGS,
  1157. dflt_dpbp->dpbp_id);
  1158. err_get_api_ver:
  1159. err_close:
  1160. err_open:
  1161. err_create:
  1162. free(dflt_dpbp);
  1163. err_calloc:
  1164. return err;
  1165. }
  1166. static int dpbp_exit(void)
  1167. {
  1168. int err;
  1169. err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
  1170. dflt_dpbp->dpbp_id);
  1171. if (err < 0) {
  1172. printf("dpbp_destroy() failed: %d\n", err);
  1173. goto err;
  1174. }
  1175. #ifdef DEBUG
  1176. printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
  1177. #endif
  1178. if (dflt_dpbp)
  1179. free(dflt_dpbp);
  1180. return 0;
  1181. err:
  1182. return err;
  1183. }
  1184. static int dpni_init(void)
  1185. {
  1186. int err;
  1187. uint8_t cfg_buf[256] = {0};
  1188. struct dpni_cfg dpni_cfg;
  1189. uint16_t major_ver, minor_ver;
  1190. dflt_dpni = (struct fsl_dpni_obj *)calloc(
  1191. sizeof(struct fsl_dpni_obj), 1);
  1192. if (!dflt_dpni) {
  1193. printf("No memory: calloc() failed\n");
  1194. err = -ENOMEM;
  1195. goto err_calloc;
  1196. }
  1197. memset(&dpni_cfg, 0, sizeof(dpni_cfg));
  1198. err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
  1199. if (err < 0) {
  1200. err = -ENODEV;
  1201. printf("dpni_prepare_cfg() failed: %d\n", err);
  1202. goto err_prepare_cfg;
  1203. }
  1204. err = dpni_create(dflt_mc_io,
  1205. dflt_dprc_handle,
  1206. MC_CMD_NO_FLAGS,
  1207. &dpni_cfg,
  1208. &dflt_dpni->dpni_id);
  1209. if (err < 0) {
  1210. err = -ENODEV;
  1211. printf("dpni create() failed: %d\n", err);
  1212. goto err_create;
  1213. }
  1214. err = dpni_get_api_version(dflt_mc_io, 0,
  1215. &major_ver,
  1216. &minor_ver);
  1217. if (err < 0) {
  1218. printf("dpni_get_api_version() failed: %d\n", err);
  1219. goto err_get_version;
  1220. }
  1221. if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
  1222. minor_ver < DPNI_VER_MINOR)) {
  1223. printf("DPNI version mismatch found %u.%u,",
  1224. major_ver, minor_ver);
  1225. printf("supported version is %u.%u\n",
  1226. DPNI_VER_MAJOR, DPNI_VER_MINOR);
  1227. }
  1228. err = dpni_open(dflt_mc_io,
  1229. MC_CMD_NO_FLAGS,
  1230. dflt_dpni->dpni_id,
  1231. &dflt_dpni->dpni_handle);
  1232. if (err) {
  1233. printf("dpni_open() failed\n");
  1234. goto err_open;
  1235. }
  1236. #ifdef DEBUG
  1237. printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
  1238. #endif
  1239. err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
  1240. if (err < 0) {
  1241. printf("dpni_close() failed: %d\n", err);
  1242. goto err_close;
  1243. }
  1244. return 0;
  1245. err_close:
  1246. dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
  1247. err_open:
  1248. err_get_version:
  1249. dpni_destroy(dflt_mc_io,
  1250. dflt_dprc_handle,
  1251. MC_CMD_NO_FLAGS,
  1252. dflt_dpni->dpni_id);
  1253. err_create:
  1254. err_prepare_cfg:
  1255. free(dflt_dpni);
  1256. err_calloc:
  1257. return err;
  1258. }
  1259. static int dpni_exit(void)
  1260. {
  1261. int err;
  1262. err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
  1263. dflt_dpni->dpni_id);
  1264. if (err < 0) {
  1265. printf("dpni_destroy() failed: %d\n", err);
  1266. goto err;
  1267. }
  1268. #ifdef DEBUG
  1269. printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
  1270. #endif
  1271. if (dflt_dpni)
  1272. free(dflt_dpni);
  1273. return 0;
  1274. err:
  1275. return err;
  1276. }
  1277. static bool is_dpsparser_supported(void)
  1278. {
  1279. /* dpsparser support was first introduced in MC version: 10.12.0 */
  1280. if (mc_ver_info.major < 10)
  1281. return false;
  1282. if (mc_ver_info.major == 10)
  1283. return (mc_ver_info.minor >= 12);
  1284. return true;
  1285. }
  1286. static int dpsparser_version_check(struct fsl_mc_io *mc_io)
  1287. {
  1288. int error;
  1289. u16 major_ver, minor_ver;
  1290. if (!is_dpsparser_supported())
  1291. return 0;
  1292. error = dpsparser_get_api_version(mc_io, 0,
  1293. &major_ver,
  1294. &minor_ver);
  1295. if (error < 0) {
  1296. printf("dpsparser_get_api_version() failed: %d\n", error);
  1297. return error;
  1298. }
  1299. if (major_ver < DPSPARSER_VER_MAJOR || (major_ver ==
  1300. DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) {
  1301. printf("DPSPARSER version mismatch found %u.%u,",
  1302. major_ver, minor_ver);
  1303. printf("supported version is %u.%u\n",
  1304. DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR);
  1305. }
  1306. return error;
  1307. }
  1308. static int dpsparser_init(void)
  1309. {
  1310. int err = 0;
  1311. if (!is_dpsparser_supported())
  1312. return 0;
  1313. err = dpsparser_create(dflt_mc_io,
  1314. dflt_dprc_handle,
  1315. MC_CMD_NO_FLAGS,
  1316. &dpsparser_obj_id);
  1317. if (err)
  1318. printf("dpsparser_create() failed\n");
  1319. err = dpsparser_version_check(dflt_mc_io);
  1320. if (err < 0) {
  1321. printf("dpsparser_version_check() failed: %d\n", err);
  1322. goto err_version_check;
  1323. }
  1324. err = dpsparser_open(dflt_mc_io,
  1325. MC_CMD_NO_FLAGS,
  1326. &dpsparser_handle);
  1327. if (err < 0) {
  1328. printf("dpsparser_open() failed: %d\n", err);
  1329. goto err_open;
  1330. }
  1331. return err;
  1332. err_open:
  1333. err_version_check:
  1334. dpsparser_destroy(dflt_mc_io,
  1335. dflt_dprc_handle,
  1336. MC_CMD_NO_FLAGS, dpsparser_obj_id);
  1337. return err;
  1338. }
  1339. #ifdef DPSPARSER_DESTROY
  1340. /* TODO: refactoring needed in the future to allow DPSPARSER object destroy
  1341. * Workaround: DO NOT destroy DPSPARSER object because it needs to be available
  1342. * on Apply DPL
  1343. */
  1344. static int dpsparser_exit(void)
  1345. {
  1346. int err;
  1347. if (!is_dpsparser_supported())
  1348. return 0;
  1349. dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle);
  1350. if (err < 0) {
  1351. printf("dpsparser_close() failed: %d\n", err);
  1352. goto err;
  1353. }
  1354. err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle,
  1355. MC_CMD_NO_FLAGS, dpsparser_obj_id);
  1356. if (err < 0) {
  1357. printf("dpsparser_destroy() failed: %d\n", err);
  1358. goto err;
  1359. }
  1360. return 0;
  1361. err:
  1362. return err;
  1363. }
  1364. #endif
  1365. int mc_apply_spb(u64 mc_spb_addr)
  1366. {
  1367. int err = 0;
  1368. u16 error, err_arr_size;
  1369. u64 mc_spb_offset;
  1370. u32 spb_size;
  1371. struct sp_blob_header *sp_blob;
  1372. u64 mc_ram_addr = mc_get_dram_addr();
  1373. if (!is_dpsparser_supported())
  1374. return 0;
  1375. if (!mc_spb_addr) {
  1376. printf("fsl-mc: Invalid Blob address\n");
  1377. return -1;
  1378. }
  1379. #ifdef CONFIG_MC_DRAM_SPB_OFFSET
  1380. mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET;
  1381. #else
  1382. #error "CONFIG_MC_DRAM_SPB_OFFSET not defined"
  1383. #endif
  1384. // Read blob header and get size of SPB blob
  1385. sp_blob = (struct sp_blob_header *)mc_spb_addr;
  1386. spb_size = le32_to_cpu(sp_blob->length);
  1387. if (spb_size > CONFIG_MC_SPB_MAX_SIZE) {
  1388. printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n",
  1389. spb_size);
  1390. return -EINVAL;
  1391. }
  1392. mc_copy_image("MC SP Blob", mc_spb_addr, spb_size,
  1393. mc_ram_addr + mc_spb_offset);
  1394. //Invoke MC command to apply SPB blob
  1395. printf("fsl-mc: Applying soft parser blob... ");
  1396. err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle,
  1397. mc_spb_offset, &error);
  1398. if (err)
  1399. return err;
  1400. if (error == 0) {
  1401. printf("SUCCESS\n");
  1402. } else {
  1403. printf("FAILED with error code = %d:\n", error);
  1404. err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb);
  1405. if (error > 0 && error < err_arr_size)
  1406. printf(mc_err_msg_apply_spb[error]);
  1407. else
  1408. printf(MC_ERROR_MSG_SPB_UNKNOWN);
  1409. }
  1410. return err;
  1411. }
  1412. static int mc_init_object(void)
  1413. {
  1414. int err = 0;
  1415. err = dprc_init();
  1416. if (err < 0) {
  1417. printf("dprc_init() failed: %d\n", err);
  1418. goto err;
  1419. }
  1420. err = dpbp_init();
  1421. if (err < 0) {
  1422. printf("dpbp_init() failed: %d\n", err);
  1423. goto err;
  1424. }
  1425. err = dpio_init();
  1426. if (err < 0) {
  1427. printf("dpio_init() failed: %d\n", err);
  1428. goto err;
  1429. }
  1430. err = dpni_init();
  1431. if (err < 0) {
  1432. printf("dpni_init() failed: %d\n", err);
  1433. goto err;
  1434. }
  1435. err = dpsparser_init();
  1436. if (err < 0) {
  1437. printf("dpsparser_init() failed: %d\n", err);
  1438. goto err;
  1439. }
  1440. return 0;
  1441. err:
  1442. return err;
  1443. }
  1444. int fsl_mc_ldpaa_exit(struct bd_info *bd)
  1445. {
  1446. int err = 0;
  1447. bool is_dpl_apply_status = false;
  1448. bool mc_boot_status = false;
  1449. if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
  1450. err = mc_apply_dpl(mc_lazy_dpl_addr);
  1451. if (!err)
  1452. fdt_fixup_board_enet(working_fdt);
  1453. mc_lazy_dpl_addr = 0;
  1454. }
  1455. if (!get_mc_boot_status())
  1456. mc_boot_status = true;
  1457. /* MC is not loaded intentionally, So return success. */
  1458. if (bd && !mc_boot_status)
  1459. return 0;
  1460. /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
  1461. if (!get_dpl_apply_status())
  1462. is_dpl_apply_status = true;
  1463. /*
  1464. * For case MC is loaded but DPL is not deployed, return success and
  1465. * print message on console. Else FDT fix-up code execution hanged.
  1466. */
  1467. if (bd && mc_boot_status && !is_dpl_apply_status) {
  1468. printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
  1469. goto mc_obj_cleanup;
  1470. }
  1471. if (bd && mc_boot_status && is_dpl_apply_status)
  1472. return 0;
  1473. mc_obj_cleanup:
  1474. err = dpbp_exit();
  1475. if (err < 0) {
  1476. printf("dpbp_exit() failed: %d\n", err);
  1477. goto err;
  1478. }
  1479. err = dpio_exit();
  1480. if (err < 0) {
  1481. printf("dpio_exit() failed: %d\n", err);
  1482. goto err;
  1483. }
  1484. err = dpni_exit();
  1485. if (err < 0) {
  1486. printf("dpni_exit() failed: %d\n", err);
  1487. goto err;
  1488. }
  1489. err = dprc_exit();
  1490. if (err < 0) {
  1491. printf("dprc_exit() failed: %d\n", err);
  1492. goto err;
  1493. }
  1494. return 0;
  1495. err:
  1496. return err;
  1497. }
  1498. static int do_fsl_mc(struct cmd_tbl *cmdtp, int flag, int argc,
  1499. char *const argv[])
  1500. {
  1501. int err = 0;
  1502. if (argc < 3)
  1503. goto usage;
  1504. switch (argv[1][0]) {
  1505. case 's': {
  1506. char sub_cmd;
  1507. u64 mc_fw_addr, mc_dpc_addr;
  1508. #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
  1509. u64 aiop_fw_addr;
  1510. #endif
  1511. sub_cmd = argv[2][0];
  1512. switch (sub_cmd) {
  1513. case 'm':
  1514. if (argc < 5)
  1515. goto usage;
  1516. if (get_mc_boot_status() == 0) {
  1517. printf("fsl-mc: MC is already booted");
  1518. printf("\n");
  1519. return err;
  1520. }
  1521. mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
  1522. mc_dpc_addr = simple_strtoull(argv[4], NULL,
  1523. 16);
  1524. if (!mc_init(mc_fw_addr, mc_dpc_addr))
  1525. err = mc_init_object();
  1526. break;
  1527. #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
  1528. case 'a':
  1529. if (argc < 4)
  1530. goto usage;
  1531. if (get_aiop_apply_status() == 0) {
  1532. printf("fsl-mc: AIOP FW is already");
  1533. printf(" applied\n");
  1534. return err;
  1535. }
  1536. aiop_fw_addr = simple_strtoull(argv[3], NULL,
  1537. 16);
  1538. /* if SoC doesn't have AIOP, err = -ENODEV */
  1539. err = load_mc_aiop_img(aiop_fw_addr);
  1540. if (!err)
  1541. printf("fsl-mc: AIOP FW applied\n");
  1542. break;
  1543. #endif
  1544. default:
  1545. printf("Invalid option: %s\n", argv[2]);
  1546. goto usage;
  1547. break;
  1548. }
  1549. }
  1550. break;
  1551. case 'l': {
  1552. /* lazyapply */
  1553. u64 mc_dpl_addr;
  1554. if (argc < 4)
  1555. goto usage;
  1556. if (get_dpl_apply_status() == 0) {
  1557. printf("fsl-mc: DPL already applied\n");
  1558. return err;
  1559. }
  1560. mc_dpl_addr = simple_strtoull(argv[3], NULL, 16);
  1561. if (get_mc_boot_status() != 0) {
  1562. printf("fsl-mc: Deploying data path layout ..");
  1563. printf("ERROR (MC is not booted)\n");
  1564. return -ENODEV;
  1565. }
  1566. /*
  1567. * We will do the actual dpaa exit and dpl apply
  1568. * later from announce_and_cleanup().
  1569. */
  1570. mc_lazy_dpl_addr = mc_dpl_addr;
  1571. break;
  1572. }
  1573. case 'a': {
  1574. /* apply */
  1575. char sub_cmd;
  1576. u64 mc_apply_addr;
  1577. if (argc < 4)
  1578. goto usage;
  1579. sub_cmd = argv[2][0];
  1580. switch (sub_cmd) {
  1581. case 'd':
  1582. case 'D':
  1583. if (get_dpl_apply_status() == 0) {
  1584. printf("fsl-mc: DPL already applied\n");
  1585. return err;
  1586. }
  1587. if (get_mc_boot_status() != 0) {
  1588. printf("fsl-mc: Deploying data path layout ..");
  1589. printf("ERROR (MC is not booted)\n");
  1590. return -ENODEV;
  1591. }
  1592. mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
  1593. /* The user wants DPL applied now */
  1594. if (!fsl_mc_ldpaa_exit(NULL))
  1595. err = mc_apply_dpl(mc_apply_addr);
  1596. break;
  1597. case 's':
  1598. if (!is_dpsparser_supported()) {
  1599. printf("fsl-mc: apply spb command .. ");
  1600. printf("ERROR: requires at least MC 10.12.0\n");
  1601. return err;
  1602. }
  1603. if (get_mc_boot_status() != 0) {
  1604. printf("fsl-mc: Deploying Soft Parser Blob...");
  1605. printf("ERROR (MC is not booted)\n");
  1606. return err;
  1607. }
  1608. mc_apply_addr = simple_strtoull(argv[3], NULL, 16);
  1609. /* Apply spb (Soft Parser Blob) */
  1610. err = mc_apply_spb(mc_apply_addr);
  1611. break;
  1612. default:
  1613. printf("Invalid option: %s\n", argv[2]);
  1614. goto usage;
  1615. }
  1616. break;
  1617. }
  1618. default:
  1619. printf("Invalid option: %s\n", argv[1]);
  1620. goto usage;
  1621. break;
  1622. }
  1623. return err;
  1624. usage:
  1625. return CMD_RET_USAGE;
  1626. }
  1627. U_BOOT_CMD(
  1628. fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
  1629. "DPAA2 command to manage Management Complex (MC)",
  1630. "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
  1631. "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
  1632. "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
  1633. "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n"
  1634. "fsl_mc start aiop [FW_addr] - Start AIOP\n"
  1635. );
  1636. void mc_env_boot(void)
  1637. {
  1638. #if defined(CONFIG_FSL_MC_ENET)
  1639. char *mc_boot_env_var;
  1640. /* The MC may only be initialized in the reset PHY function
  1641. * because otherwise U-Boot has not yet set up all the MAC
  1642. * address info properly. Without MAC addresses, the MC code
  1643. * can not properly initialize the DPC.
  1644. */
  1645. mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
  1646. if (mc_boot_env_var)
  1647. run_command_list(mc_boot_env_var, -1, 0);
  1648. #endif /* CONFIG_FSL_MC_ENET */
  1649. }