mc.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386
  1. /*
  2. * Copyright (C) 2017 NXP Semiconductors
  3. * Copyright (C) 2014 Freescale Semiconductor
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <errno.h>
  9. #include <linux/bug.h>
  10. #include <asm/io.h>
  11. #include <libfdt.h>
  12. #include <net.h>
  13. #include <fdt_support.h>
  14. #include <fsl-mc/fsl_mc.h>
  15. #include <fsl-mc/fsl_mc_sys.h>
  16. #include <fsl-mc/fsl_mc_private.h>
  17. #include <fsl-mc/fsl_dpmng.h>
  18. #include <fsl-mc/fsl_dprc.h>
  19. #include <fsl-mc/fsl_dpio.h>
  20. #include <fsl-mc/fsl_dpni.h>
  21. #include <fsl-mc/fsl_qbman_portal.h>
  22. #include <fsl-mc/ldpaa_wriop.h>
  23. #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
  24. #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
  25. #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
  26. #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
  27. #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
  28. #define MC_BOOT_ENV_VAR "mcinitcmd"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. static int mc_boot_status = -1;
  31. static int mc_dpl_applied = -1;
  32. #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
  33. static int mc_aiop_applied = -1;
  34. #endif
  35. struct fsl_mc_io *root_mc_io = NULL;
  36. struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
  37. uint16_t root_dprc_handle = 0;
  38. uint16_t dflt_dprc_handle = 0;
  39. int child_dprc_id;
  40. struct fsl_dpbp_obj *dflt_dpbp = NULL;
  41. struct fsl_dpio_obj *dflt_dpio = NULL;
  42. struct fsl_dpni_obj *dflt_dpni = NULL;
  43. static u64 mc_lazy_dpl_addr;
  44. #ifdef DEBUG
  45. void dump_ram_words(const char *title, void *addr)
  46. {
  47. int i;
  48. uint32_t *words = addr;
  49. printf("Dumping beginning of %s (%p):\n", title, addr);
  50. for (i = 0; i < 16; i++)
  51. printf("%#x ", words[i]);
  52. printf("\n");
  53. }
  54. void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
  55. {
  56. printf("MC CCSR registers:\n"
  57. "reg_gcr1 %#x\n"
  58. "reg_gsr %#x\n"
  59. "reg_sicbalr %#x\n"
  60. "reg_sicbahr %#x\n"
  61. "reg_sicapr %#x\n"
  62. "reg_mcfbalr %#x\n"
  63. "reg_mcfbahr %#x\n"
  64. "reg_mcfapr %#x\n"
  65. "reg_psr %#x\n",
  66. mc_ccsr_regs->reg_gcr1,
  67. mc_ccsr_regs->reg_gsr,
  68. mc_ccsr_regs->reg_sicbalr,
  69. mc_ccsr_regs->reg_sicbahr,
  70. mc_ccsr_regs->reg_sicapr,
  71. mc_ccsr_regs->reg_mcfbalr,
  72. mc_ccsr_regs->reg_mcfbahr,
  73. mc_ccsr_regs->reg_mcfapr,
  74. mc_ccsr_regs->reg_psr);
  75. }
  76. #else
  77. #define dump_ram_words(title, addr)
  78. #define dump_mc_ccsr_regs(mc_ccsr_regs)
  79. #endif /* DEBUG */
  80. #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
  81. /**
  82. * Copying MC firmware or DPL image to DDR
  83. */
  84. static int mc_copy_image(const char *title,
  85. u64 image_addr, u32 image_size, u64 mc_ram_addr)
  86. {
  87. debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
  88. memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
  89. flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
  90. return 0;
  91. }
  92. /**
  93. * MC firmware FIT image parser checks if the image is in FIT
  94. * format, verifies integrity of the image and calculates
  95. * raw image address and size values.
  96. * Returns 0 on success and a negative errno on error.
  97. * task fail.
  98. **/
  99. int parse_mc_firmware_fit_image(u64 mc_fw_addr,
  100. const void **raw_image_addr,
  101. size_t *raw_image_size)
  102. {
  103. int format;
  104. void *fit_hdr;
  105. int node_offset;
  106. const void *data;
  107. size_t size;
  108. const char *uname = "firmware";
  109. fit_hdr = (void *)mc_fw_addr;
  110. /* Check if Image is in FIT format */
  111. format = genimg_get_format(fit_hdr);
  112. if (format != IMAGE_FORMAT_FIT) {
  113. printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
  114. return -EINVAL;
  115. }
  116. if (!fit_check_format(fit_hdr)) {
  117. printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
  118. return -EINVAL;
  119. }
  120. node_offset = fit_image_get_node(fit_hdr, uname);
  121. if (node_offset < 0) {
  122. printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
  123. return -ENOENT;
  124. }
  125. /* Verify MC firmware image */
  126. if (!(fit_image_verify(fit_hdr, node_offset))) {
  127. printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
  128. return -EINVAL;
  129. }
  130. /* Get address and size of raw image */
  131. fit_image_get_data(fit_hdr, node_offset, &data, &size);
  132. *raw_image_addr = data;
  133. *raw_image_size = size;
  134. return 0;
  135. }
  136. #endif
  137. static int mc_fixup_dpc_mac_addr(void *blob, int noff, int dpmac_id,
  138. struct eth_device *eth_dev)
  139. {
  140. int nodeoffset, err = 0;
  141. char mac_name[10];
  142. const char link_type_mode[] = "FIXED_LINK";
  143. unsigned char env_enetaddr[6];
  144. sprintf(mac_name, "mac@%d", dpmac_id);
  145. /* node not found - create it */
  146. nodeoffset = fdt_subnode_offset(blob, noff, (const char *) mac_name);
  147. if (nodeoffset < 0) {
  148. err = fdt_increase_size(blob, 200);
  149. if (err) {
  150. printf("fdt_increase_size: err=%s\n",
  151. fdt_strerror(err));
  152. return err;
  153. }
  154. nodeoffset = fdt_add_subnode(blob, noff, mac_name);
  155. /* add default property of fixed link */
  156. err = fdt_appendprop_string(blob, nodeoffset,
  157. "link_type", link_type_mode);
  158. if (err) {
  159. printf("fdt_appendprop_string: err=%s\n",
  160. fdt_strerror(err));
  161. return err;
  162. }
  163. }
  164. /* port_mac_address property present in DPC */
  165. if (fdt_get_property(blob, nodeoffset, "port_mac_address", NULL)) {
  166. /* MAC addr randomly assigned - leave the one in DPC */
  167. eth_getenv_enetaddr_by_index("eth", eth_dev->index,
  168. env_enetaddr);
  169. if (is_zero_ethaddr(env_enetaddr))
  170. return err;
  171. /* replace DPC MAC address with u-boot env one */
  172. err = fdt_setprop(blob, nodeoffset, "port_mac_address",
  173. eth_dev->enetaddr, 6);
  174. if (err) {
  175. printf("fdt_setprop mac: err=%s\n", fdt_strerror(err));
  176. return err;
  177. }
  178. return 0;
  179. }
  180. /* append port_mac_address property to mac node in DPC */
  181. err = fdt_increase_size(blob, 80);
  182. if (err) {
  183. printf("fdt_increase_size: err=%s\n", fdt_strerror(err));
  184. return err;
  185. }
  186. err = fdt_appendprop(blob, nodeoffset,
  187. "port_mac_address", eth_dev->enetaddr, 6);
  188. if (err) {
  189. printf("fdt_appendprop: err=%s\n", fdt_strerror(err));
  190. return err;
  191. }
  192. return err;
  193. }
  194. static int mc_fixup_dpc(u64 dpc_addr)
  195. {
  196. void *blob = (void *)dpc_addr;
  197. int nodeoffset, err = 0;
  198. char ethname[10];
  199. struct eth_device *eth_dev;
  200. int i;
  201. /* delete any existing ICID pools */
  202. nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
  203. if (fdt_del_node(blob, nodeoffset) < 0)
  204. printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
  205. /* add a new pool */
  206. nodeoffset = fdt_path_offset(blob, "/resources");
  207. if (nodeoffset < 0) {
  208. printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
  209. return -EINVAL;
  210. }
  211. nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
  212. nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
  213. do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
  214. "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
  215. do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
  216. "num",
  217. FSL_DPAA2_STREAM_ID_END -
  218. FSL_DPAA2_STREAM_ID_START + 1, 1);
  219. /* fixup MAC addresses for dpmac ports */
  220. nodeoffset = fdt_path_offset(blob, "/board_info/ports");
  221. if (nodeoffset < 0)
  222. goto out;
  223. for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
  224. /* port not enabled */
  225. if ((wriop_is_enabled_dpmac(i) != 1) ||
  226. (wriop_get_phy_address(i) == -1))
  227. continue;
  228. sprintf(ethname, "DPMAC%d@%s", i,
  229. phy_interface_strings[wriop_get_enet_if(i)]);
  230. eth_dev = eth_get_dev_by_name(ethname);
  231. if (eth_dev == NULL)
  232. continue;
  233. err = mc_fixup_dpc_mac_addr(blob, nodeoffset, i, eth_dev);
  234. if (err) {
  235. printf("mc_fixup_dpc_mac_addr failed: err=%s\n",
  236. fdt_strerror(err));
  237. goto out;
  238. }
  239. }
  240. out:
  241. flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
  242. return err;
  243. }
  244. static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
  245. {
  246. u64 mc_dpc_offset;
  247. #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
  248. int error;
  249. void *dpc_fdt_hdr;
  250. int dpc_size;
  251. #endif
  252. #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
  253. BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
  254. CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
  255. mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
  256. #else
  257. #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
  258. #endif
  259. /*
  260. * Load the MC DPC blob in the MC private DRAM block:
  261. */
  262. #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
  263. printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
  264. #else
  265. /*
  266. * Get address and size of the DPC blob stored in flash:
  267. */
  268. dpc_fdt_hdr = (void *)mc_dpc_addr;
  269. error = fdt_check_header(dpc_fdt_hdr);
  270. if (error != 0) {
  271. /*
  272. * Don't return with error here, since the MC firmware can
  273. * still boot without a DPC
  274. */
  275. printf("\nfsl-mc: WARNING: No DPC image found");
  276. return 0;
  277. }
  278. dpc_size = fdt_totalsize(dpc_fdt_hdr);
  279. if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
  280. printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
  281. dpc_size);
  282. return -EINVAL;
  283. }
  284. mc_copy_image("MC DPC blob",
  285. (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
  286. #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
  287. if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
  288. return -EINVAL;
  289. dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
  290. return 0;
  291. }
  292. static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
  293. {
  294. u64 mc_dpl_offset;
  295. #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
  296. int error;
  297. void *dpl_fdt_hdr;
  298. int dpl_size;
  299. #endif
  300. #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
  301. BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
  302. CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
  303. mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
  304. #else
  305. #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
  306. #endif
  307. /*
  308. * Load the MC DPL blob in the MC private DRAM block:
  309. */
  310. #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
  311. printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
  312. #else
  313. /*
  314. * Get address and size of the DPL blob stored in flash:
  315. */
  316. dpl_fdt_hdr = (void *)mc_dpl_addr;
  317. error = fdt_check_header(dpl_fdt_hdr);
  318. if (error != 0) {
  319. printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
  320. return error;
  321. }
  322. dpl_size = fdt_totalsize(dpl_fdt_hdr);
  323. if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
  324. printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
  325. dpl_size);
  326. return -EINVAL;
  327. }
  328. mc_copy_image("MC DPL blob",
  329. (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
  330. #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
  331. dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
  332. return 0;
  333. }
  334. /**
  335. * Return the MC boot timeout value in milliseconds
  336. */
  337. static unsigned long get_mc_boot_timeout_ms(void)
  338. {
  339. unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
  340. char *timeout_ms_env_var = getenv(MC_BOOT_TIMEOUT_ENV_VAR);
  341. if (timeout_ms_env_var) {
  342. timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
  343. if (timeout_ms == 0) {
  344. printf("fsl-mc: WARNING: Invalid value for \'"
  345. MC_BOOT_TIMEOUT_ENV_VAR
  346. "\' environment variable: %lu\n",
  347. timeout_ms);
  348. timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
  349. }
  350. }
  351. return timeout_ms;
  352. }
  353. #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
  354. __weak bool soc_has_aiop(void)
  355. {
  356. return false;
  357. }
  358. static int load_mc_aiop_img(u64 aiop_fw_addr)
  359. {
  360. u64 mc_ram_addr = mc_get_dram_addr();
  361. #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
  362. void *aiop_img;
  363. #endif
  364. /* Check if AIOP is available */
  365. if (!soc_has_aiop())
  366. return -ENODEV;
  367. /*
  368. * Load the MC AIOP image in the MC private DRAM block:
  369. */
  370. #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
  371. printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
  372. CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
  373. #else
  374. aiop_img = (void *)aiop_fw_addr;
  375. mc_copy_image("MC AIOP image",
  376. (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
  377. mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
  378. #endif
  379. mc_aiop_applied = 0;
  380. return 0;
  381. }
  382. #endif
  383. static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
  384. {
  385. u32 reg_gsr;
  386. u32 mc_fw_boot_status;
  387. unsigned long timeout_ms = get_mc_boot_timeout_ms();
  388. struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
  389. dmb();
  390. assert(timeout_ms > 0);
  391. for (;;) {
  392. udelay(1000); /* throttle polling */
  393. reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
  394. mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
  395. if (mc_fw_boot_status & 0x1)
  396. break;
  397. timeout_ms--;
  398. if (timeout_ms == 0)
  399. break;
  400. }
  401. if (timeout_ms == 0) {
  402. printf("ERROR: timeout\n");
  403. /* TODO: Get an error status from an MC CCSR register */
  404. return -ETIMEDOUT;
  405. }
  406. if (mc_fw_boot_status != 0x1) {
  407. /*
  408. * TODO: Identify critical errors from the GSR register's FS
  409. * field and for those errors, set error to -ENODEV or other
  410. * appropriate errno, so that the status property is set to
  411. * failure in the fsl,dprc device tree node.
  412. */
  413. printf("WARNING: Firmware returned an error (GSR: %#x)\n",
  414. reg_gsr);
  415. } else {
  416. printf("SUCCESS\n");
  417. }
  418. *final_reg_gsr = reg_gsr;
  419. return 0;
  420. }
  421. int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
  422. {
  423. int error = 0;
  424. int portal_id = 0;
  425. struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
  426. u64 mc_ram_addr = mc_get_dram_addr();
  427. u32 reg_gsr;
  428. u32 reg_mcfbalr;
  429. #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
  430. const void *raw_image_addr;
  431. size_t raw_image_size = 0;
  432. #endif
  433. struct mc_version mc_ver_info;
  434. u8 mc_ram_num_256mb_blocks;
  435. size_t mc_ram_size = mc_get_dram_block_size();
  436. mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
  437. if (mc_ram_num_256mb_blocks < 1 || mc_ram_num_256mb_blocks > 0xff) {
  438. error = -EINVAL;
  439. printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
  440. mc_ram_size);
  441. goto out;
  442. }
  443. /*
  444. * Management Complex cores should be held at reset out of POR.
  445. * U-Boot should be the first software to touch MC. To be safe,
  446. * we reset all cores again by setting GCR1 to 0. It doesn't do
  447. * anything if they are held at reset. After we setup the firmware
  448. * we kick off MC by deasserting the reset bit for core 0, and
  449. * deasserting the reset bits for Command Portal Managers.
  450. * The stop bits are not touched here. They are used to stop the
  451. * cores when they are active. Setting stop bits doesn't stop the
  452. * cores from fetching instructions when they are released from
  453. * reset.
  454. */
  455. out_le32(&mc_ccsr_regs->reg_gcr1, 0);
  456. dmb();
  457. #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
  458. printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
  459. #else
  460. error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
  461. &raw_image_size);
  462. if (error != 0)
  463. goto out;
  464. /*
  465. * Load the MC FW at the beginning of the MC private DRAM block:
  466. */
  467. mc_copy_image("MC Firmware",
  468. (u64)raw_image_addr, raw_image_size, mc_ram_addr);
  469. #endif
  470. dump_ram_words("firmware", (void *)mc_ram_addr);
  471. error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
  472. if (error != 0)
  473. goto out;
  474. debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
  475. dump_mc_ccsr_regs(mc_ccsr_regs);
  476. /*
  477. * Tell MC what is the address range of the DRAM block assigned to it:
  478. */
  479. reg_mcfbalr = (u32)mc_ram_addr |
  480. (mc_ram_num_256mb_blocks - 1);
  481. out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
  482. out_le32(&mc_ccsr_regs->reg_mcfbahr,
  483. (u32)(mc_ram_addr >> 32));
  484. out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
  485. /*
  486. * Tell the MC that we want delayed DPL deployment.
  487. */
  488. out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
  489. printf("\nfsl-mc: Booting Management Complex ... ");
  490. /*
  491. * Deassert reset and release MC core 0 to run
  492. */
  493. out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
  494. error = wait_for_mc(true, &reg_gsr);
  495. if (error != 0)
  496. goto out;
  497. /*
  498. * TODO: need to obtain the portal_id for the root container from the
  499. * DPL
  500. */
  501. portal_id = 0;
  502. /*
  503. * Initialize the global default MC portal
  504. * And check that the MC firmware is responding portal commands:
  505. */
  506. root_mc_io = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io));
  507. if (!root_mc_io) {
  508. printf(" No memory: malloc() failed\n");
  509. return -ENOMEM;
  510. }
  511. root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
  512. debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
  513. portal_id, root_mc_io->mmio_regs);
  514. error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
  515. if (error != 0) {
  516. printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
  517. error);
  518. goto out;
  519. }
  520. printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
  521. mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
  522. reg_gsr & GSR_FS_MASK);
  523. out:
  524. if (error != 0)
  525. mc_boot_status = error;
  526. else
  527. mc_boot_status = 0;
  528. return error;
  529. }
  530. int mc_apply_dpl(u64 mc_dpl_addr)
  531. {
  532. struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
  533. int error = 0;
  534. u32 reg_gsr;
  535. u64 mc_ram_addr = mc_get_dram_addr();
  536. size_t mc_ram_size = mc_get_dram_block_size();
  537. if (!mc_dpl_addr)
  538. return -1;
  539. error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
  540. if (error != 0)
  541. return error;
  542. /*
  543. * Tell the MC to deploy the DPL:
  544. */
  545. out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
  546. printf("fsl-mc: Deploying data path layout ... ");
  547. error = wait_for_mc(false, &reg_gsr);
  548. if (!error)
  549. mc_dpl_applied = 0;
  550. return error;
  551. }
  552. int get_mc_boot_status(void)
  553. {
  554. return mc_boot_status;
  555. }
  556. #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
  557. int get_aiop_apply_status(void)
  558. {
  559. return mc_aiop_applied;
  560. }
  561. #endif
  562. int get_dpl_apply_status(void)
  563. {
  564. return mc_dpl_applied;
  565. }
  566. /**
  567. * Return the MC address of private DRAM block.
  568. */
  569. u64 mc_get_dram_addr(void)
  570. {
  571. return gd->arch.resv_ram;
  572. }
  573. /**
  574. * Return the actual size of the MC private DRAM block.
  575. */
  576. unsigned long mc_get_dram_block_size(void)
  577. {
  578. unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
  579. char *dram_block_size_env_var = getenv(MC_MEM_SIZE_ENV_VAR);
  580. if (dram_block_size_env_var) {
  581. dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
  582. 10);
  583. if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
  584. printf("fsl-mc: WARNING: Invalid value for \'"
  585. MC_MEM_SIZE_ENV_VAR
  586. "\' environment variable: %lu\n",
  587. dram_block_size);
  588. dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
  589. }
  590. }
  591. return dram_block_size;
  592. }
  593. int fsl_mc_ldpaa_init(bd_t *bis)
  594. {
  595. int i;
  596. for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
  597. if ((wriop_is_enabled_dpmac(i) == 1) &&
  598. (wriop_get_phy_address(i) != -1))
  599. ldpaa_eth_init(i, wriop_get_enet_if(i));
  600. return 0;
  601. }
  602. static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
  603. {
  604. struct dprc_attributes attr;
  605. int error;
  606. memset(&attr, 0, sizeof(struct dprc_attributes));
  607. error = dprc_get_attributes(mc_io, MC_CMD_NO_FLAGS, handle, &attr);
  608. if (error == 0) {
  609. if ((attr.version.major != DPRC_VER_MAJOR) ||
  610. (attr.version.minor != DPRC_VER_MINOR)) {
  611. printf("DPRC version mismatch found %u.%u,",
  612. attr.version.major,
  613. attr.version.minor);
  614. printf("supported version is %u.%u\n",
  615. DPRC_VER_MAJOR, DPRC_VER_MINOR);
  616. }
  617. }
  618. return error;
  619. }
  620. static int dpio_init(void)
  621. {
  622. struct qbman_swp_desc p_des;
  623. struct dpio_attr attr;
  624. struct dpio_cfg dpio_cfg;
  625. int err = 0;
  626. dflt_dpio = (struct fsl_dpio_obj *)malloc(sizeof(struct fsl_dpio_obj));
  627. if (!dflt_dpio) {
  628. printf("No memory: malloc() failed\n");
  629. err = -ENOMEM;
  630. goto err_malloc;
  631. }
  632. dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
  633. dpio_cfg.num_priorities = 8;
  634. err = dpio_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpio_cfg,
  635. &dflt_dpio->dpio_handle);
  636. if (err < 0) {
  637. printf("dpio_create() failed: %d\n", err);
  638. err = -ENODEV;
  639. goto err_create;
  640. }
  641. memset(&attr, 0, sizeof(struct dpio_attr));
  642. err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
  643. dflt_dpio->dpio_handle, &attr);
  644. if (err < 0) {
  645. printf("dpio_get_attributes() failed: %d\n", err);
  646. goto err_get_attr;
  647. }
  648. if ((attr.version.major != DPIO_VER_MAJOR) ||
  649. (attr.version.minor != DPIO_VER_MINOR)) {
  650. printf("DPIO version mismatch found %u.%u,",
  651. attr.version.major, attr.version.minor);
  652. printf("supported version is %u.%u\n",
  653. DPIO_VER_MAJOR, DPIO_VER_MINOR);
  654. }
  655. dflt_dpio->dpio_id = attr.id;
  656. #ifdef DEBUG
  657. printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
  658. #endif
  659. err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  660. if (err < 0) {
  661. printf("dpio_enable() failed %d\n", err);
  662. goto err_get_enable;
  663. }
  664. debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
  665. attr.qbman_portal_ce_offset,
  666. attr.qbman_portal_ci_offset,
  667. attr.qbman_portal_id,
  668. attr.num_priorities);
  669. p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
  670. + attr.qbman_portal_ce_offset);
  671. p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
  672. + attr.qbman_portal_ci_offset);
  673. dflt_dpio->sw_portal = qbman_swp_init(&p_des);
  674. if (dflt_dpio->sw_portal == NULL) {
  675. printf("qbman_swp_init() failed\n");
  676. goto err_get_swp_init;
  677. }
  678. return 0;
  679. err_get_swp_init:
  680. dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  681. err_get_enable:
  682. err_get_attr:
  683. dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  684. dpio_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  685. err_create:
  686. free(dflt_dpio);
  687. err_malloc:
  688. return err;
  689. }
  690. static int dpio_exit(void)
  691. {
  692. int err;
  693. err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  694. if (err < 0) {
  695. printf("dpio_disable() failed: %d\n", err);
  696. goto err;
  697. }
  698. err = dpio_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
  699. if (err < 0) {
  700. printf("dpio_destroy() failed: %d\n", err);
  701. goto err;
  702. }
  703. #ifdef DEBUG
  704. printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
  705. #endif
  706. if (dflt_dpio)
  707. free(dflt_dpio);
  708. return 0;
  709. err:
  710. return err;
  711. }
  712. static int dprc_init(void)
  713. {
  714. int err, child_portal_id, container_id;
  715. struct dprc_cfg cfg;
  716. uint64_t mc_portal_offset;
  717. /* Open root container */
  718. err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
  719. if (err < 0) {
  720. printf("dprc_get_container_id(): Root failed: %d\n", err);
  721. goto err_root_container_id;
  722. }
  723. #ifdef DEBUG
  724. printf("Root container id = %d\n", container_id);
  725. #endif
  726. err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
  727. &root_dprc_handle);
  728. if (err < 0) {
  729. printf("dprc_open(): Root Container failed: %d\n", err);
  730. goto err_root_open;
  731. }
  732. if (!root_dprc_handle) {
  733. printf("dprc_open(): Root Container Handle is not valid\n");
  734. goto err_root_open;
  735. }
  736. err = dprc_version_check(root_mc_io, root_dprc_handle);
  737. if (err < 0) {
  738. printf("dprc_version_check() failed: %d\n", err);
  739. goto err_root_open;
  740. }
  741. memset(&cfg, 0, sizeof(struct dprc_cfg));
  742. cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
  743. DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
  744. DPRC_CFG_OPT_ALLOC_ALLOWED;
  745. cfg.icid = DPRC_GET_ICID_FROM_POOL;
  746. cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
  747. err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
  748. root_dprc_handle,
  749. &cfg,
  750. &child_dprc_id,
  751. &mc_portal_offset);
  752. if (err < 0) {
  753. printf("dprc_create_container() failed: %d\n", err);
  754. goto err_create;
  755. }
  756. dflt_mc_io = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io));
  757. if (!dflt_mc_io) {
  758. err = -ENOMEM;
  759. printf(" No memory: malloc() failed\n");
  760. goto err_malloc;
  761. }
  762. child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
  763. dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
  764. #ifdef DEBUG
  765. printf("MC portal of child DPRC container: %d, physical addr %p)\n",
  766. child_dprc_id, dflt_mc_io->mmio_regs);
  767. #endif
  768. err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
  769. &dflt_dprc_handle);
  770. if (err < 0) {
  771. printf("dprc_open(): Child container failed: %d\n", err);
  772. goto err_child_open;
  773. }
  774. if (!dflt_dprc_handle) {
  775. printf("dprc_open(): Child container Handle is not valid\n");
  776. goto err_child_open;
  777. }
  778. return 0;
  779. err_child_open:
  780. free(dflt_mc_io);
  781. err_malloc:
  782. dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
  783. root_dprc_handle, child_dprc_id);
  784. err_create:
  785. dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
  786. err_root_open:
  787. err_root_container_id:
  788. return err;
  789. }
  790. static int dprc_exit(void)
  791. {
  792. int err;
  793. err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
  794. if (err < 0) {
  795. printf("dprc_close(): Child failed: %d\n", err);
  796. goto err;
  797. }
  798. err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
  799. root_dprc_handle, child_dprc_id);
  800. if (err < 0) {
  801. printf("dprc_destroy_container() failed: %d\n", err);
  802. goto err;
  803. }
  804. err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
  805. if (err < 0) {
  806. printf("dprc_close(): Root failed: %d\n", err);
  807. goto err;
  808. }
  809. if (dflt_mc_io)
  810. free(dflt_mc_io);
  811. if (root_mc_io)
  812. free(root_mc_io);
  813. return 0;
  814. err:
  815. return err;
  816. }
  817. static int dpbp_init(void)
  818. {
  819. int err;
  820. struct dpbp_attr dpbp_attr;
  821. struct dpbp_cfg dpbp_cfg;
  822. dflt_dpbp = (struct fsl_dpbp_obj *)malloc(sizeof(struct fsl_dpbp_obj));
  823. if (!dflt_dpbp) {
  824. printf("No memory: malloc() failed\n");
  825. err = -ENOMEM;
  826. goto err_malloc;
  827. }
  828. dpbp_cfg.options = 512;
  829. err = dpbp_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpbp_cfg,
  830. &dflt_dpbp->dpbp_handle);
  831. if (err < 0) {
  832. err = -ENODEV;
  833. printf("dpbp_create() failed: %d\n", err);
  834. goto err_create;
  835. }
  836. memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
  837. err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
  838. dflt_dpbp->dpbp_handle,
  839. &dpbp_attr);
  840. if (err < 0) {
  841. printf("dpbp_get_attributes() failed: %d\n", err);
  842. goto err_get_attr;
  843. }
  844. if ((dpbp_attr.version.major != DPBP_VER_MAJOR) ||
  845. (dpbp_attr.version.minor != DPBP_VER_MINOR)) {
  846. printf("DPBP version mismatch found %u.%u,",
  847. dpbp_attr.version.major, dpbp_attr.version.minor);
  848. printf("supported version is %u.%u\n",
  849. DPBP_VER_MAJOR, DPBP_VER_MINOR);
  850. }
  851. dflt_dpbp->dpbp_attr.id = dpbp_attr.id;
  852. #ifdef DEBUG
  853. printf("Init: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
  854. #endif
  855. err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
  856. if (err < 0) {
  857. printf("dpbp_close() failed: %d\n", err);
  858. goto err_close;
  859. }
  860. return 0;
  861. err_close:
  862. free(dflt_dpbp);
  863. err_get_attr:
  864. dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
  865. dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
  866. err_create:
  867. err_malloc:
  868. return err;
  869. }
  870. static int dpbp_exit(void)
  871. {
  872. int err;
  873. err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id,
  874. &dflt_dpbp->dpbp_handle);
  875. if (err < 0) {
  876. printf("dpbp_open() failed: %d\n", err);
  877. goto err;
  878. }
  879. err = dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS,
  880. dflt_dpbp->dpbp_handle);
  881. if (err < 0) {
  882. printf("dpbp_destroy() failed: %d\n", err);
  883. goto err;
  884. }
  885. #ifdef DEBUG
  886. printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
  887. #endif
  888. if (dflt_dpbp)
  889. free(dflt_dpbp);
  890. return 0;
  891. err:
  892. return err;
  893. }
  894. static int dpni_init(void)
  895. {
  896. int err;
  897. struct dpni_attr dpni_attr;
  898. uint8_t ext_cfg_buf[256] = {0};
  899. struct dpni_extended_cfg dpni_extended_cfg;
  900. struct dpni_cfg dpni_cfg;
  901. dflt_dpni = (struct fsl_dpni_obj *)malloc(sizeof(struct fsl_dpni_obj));
  902. if (!dflt_dpni) {
  903. printf("No memory: malloc() failed\n");
  904. err = -ENOMEM;
  905. goto err_malloc;
  906. }
  907. memset(&dpni_extended_cfg, 0, sizeof(dpni_extended_cfg));
  908. err = dpni_prepare_extended_cfg(&dpni_extended_cfg, &ext_cfg_buf[0]);
  909. if (err < 0) {
  910. err = -ENODEV;
  911. printf("dpni_prepare_extended_cfg() failed: %d\n", err);
  912. goto err_prepare_extended_cfg;
  913. }
  914. memset(&dpni_cfg, 0, sizeof(dpni_cfg));
  915. dpni_cfg.adv.options = DPNI_OPT_UNICAST_FILTER |
  916. DPNI_OPT_MULTICAST_FILTER;
  917. dpni_cfg.adv.ext_cfg_iova = (uint64_t)&ext_cfg_buf[0];
  918. err = dpni_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpni_cfg,
  919. &dflt_dpni->dpni_handle);
  920. if (err < 0) {
  921. err = -ENODEV;
  922. printf("dpni_create() failed: %d\n", err);
  923. goto err_create;
  924. }
  925. memset(&dpni_attr, 0, sizeof(struct dpni_attr));
  926. err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
  927. dflt_dpni->dpni_handle,
  928. &dpni_attr);
  929. if (err < 0) {
  930. printf("dpni_get_attributes() failed: %d\n", err);
  931. goto err_get_attr;
  932. }
  933. if ((dpni_attr.version.major != DPNI_VER_MAJOR) ||
  934. (dpni_attr.version.minor != DPNI_VER_MINOR)) {
  935. printf("DPNI version mismatch found %u.%u,",
  936. dpni_attr.version.major, dpni_attr.version.minor);
  937. printf("supported version is %u.%u\n",
  938. DPNI_VER_MAJOR, DPNI_VER_MINOR);
  939. }
  940. dflt_dpni->dpni_id = dpni_attr.id;
  941. #ifdef DEBUG
  942. printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
  943. #endif
  944. err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
  945. if (err < 0) {
  946. printf("dpni_close() failed: %d\n", err);
  947. goto err_close;
  948. }
  949. return 0;
  950. err_close:
  951. err_get_attr:
  952. dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
  953. dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
  954. err_create:
  955. err_prepare_extended_cfg:
  956. free(dflt_dpni);
  957. err_malloc:
  958. return err;
  959. }
  960. static int dpni_exit(void)
  961. {
  962. int err;
  963. err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id,
  964. &dflt_dpni->dpni_handle);
  965. if (err < 0) {
  966. printf("dpni_open() failed: %d\n", err);
  967. goto err;
  968. }
  969. err = dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS,
  970. dflt_dpni->dpni_handle);
  971. if (err < 0) {
  972. printf("dpni_destroy() failed: %d\n", err);
  973. goto err;
  974. }
  975. #ifdef DEBUG
  976. printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
  977. #endif
  978. if (dflt_dpni)
  979. free(dflt_dpni);
  980. return 0;
  981. err:
  982. return err;
  983. }
  984. static int mc_init_object(void)
  985. {
  986. int err = 0;
  987. err = dprc_init();
  988. if (err < 0) {
  989. printf("dprc_init() failed: %d\n", err);
  990. goto err;
  991. }
  992. err = dpbp_init();
  993. if (err < 0) {
  994. printf("dpbp_init() failed: %d\n", err);
  995. goto err;
  996. }
  997. err = dpio_init();
  998. if (err < 0) {
  999. printf("dpio_init() failed: %d\n", err);
  1000. goto err;
  1001. }
  1002. err = dpni_init();
  1003. if (err < 0) {
  1004. printf("dpni_init() failed: %d\n", err);
  1005. goto err;
  1006. }
  1007. return 0;
  1008. err:
  1009. return err;
  1010. }
  1011. int fsl_mc_ldpaa_exit(bd_t *bd)
  1012. {
  1013. int err = 0;
  1014. bool is_dpl_apply_status = false;
  1015. if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
  1016. mc_apply_dpl(mc_lazy_dpl_addr);
  1017. mc_lazy_dpl_addr = 0;
  1018. }
  1019. /* MC is not loaded intentionally, So return success. */
  1020. if (bd && get_mc_boot_status() != 0)
  1021. return 0;
  1022. /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
  1023. if (!get_dpl_apply_status())
  1024. is_dpl_apply_status = true;
  1025. /*
  1026. * For case MC is loaded but DPL is not deployed, return success and
  1027. * print message on console. Else FDT fix-up code execution hanged.
  1028. */
  1029. if (bd && !get_mc_boot_status() && !is_dpl_apply_status) {
  1030. printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
  1031. return 0;
  1032. }
  1033. err = dpbp_exit();
  1034. if (err < 0) {
  1035. printf("dpbp_exit() failed: %d\n", err);
  1036. goto err;
  1037. }
  1038. err = dpio_exit();
  1039. if (err < 0) {
  1040. printf("dpio_exit() failed: %d\n", err);
  1041. goto err;
  1042. }
  1043. err = dpni_exit();
  1044. if (err < 0) {
  1045. printf("dpni_exit() failed: %d\n", err);
  1046. goto err;
  1047. }
  1048. err = dprc_exit();
  1049. if (err < 0) {
  1050. printf("dprc_exit() failed: %d\n", err);
  1051. goto err;
  1052. }
  1053. return 0;
  1054. err:
  1055. return err;
  1056. }
  1057. static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1058. {
  1059. int err = 0;
  1060. if (argc < 3)
  1061. goto usage;
  1062. switch (argv[1][0]) {
  1063. case 's': {
  1064. char sub_cmd;
  1065. u64 mc_fw_addr, mc_dpc_addr;
  1066. #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
  1067. u64 aiop_fw_addr;
  1068. #endif
  1069. sub_cmd = argv[2][0];
  1070. switch (sub_cmd) {
  1071. case 'm':
  1072. if (argc < 5)
  1073. goto usage;
  1074. if (get_mc_boot_status() == 0) {
  1075. printf("fsl-mc: MC is already booted");
  1076. printf("\n");
  1077. return err;
  1078. }
  1079. mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
  1080. mc_dpc_addr = simple_strtoull(argv[4], NULL,
  1081. 16);
  1082. if (!mc_init(mc_fw_addr, mc_dpc_addr))
  1083. err = mc_init_object();
  1084. break;
  1085. #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
  1086. case 'a':
  1087. if (argc < 4)
  1088. goto usage;
  1089. if (get_aiop_apply_status() == 0) {
  1090. printf("fsl-mc: AIOP FW is already");
  1091. printf(" applied\n");
  1092. return err;
  1093. }
  1094. aiop_fw_addr = simple_strtoull(argv[3], NULL,
  1095. 16);
  1096. /* if SoC doesn't have AIOP, err = -ENODEV */
  1097. err = load_mc_aiop_img(aiop_fw_addr);
  1098. if (!err)
  1099. printf("fsl-mc: AIOP FW applied\n");
  1100. break;
  1101. #endif
  1102. default:
  1103. printf("Invalid option: %s\n", argv[2]);
  1104. goto usage;
  1105. break;
  1106. }
  1107. }
  1108. break;
  1109. case 'l':
  1110. case 'a': {
  1111. u64 mc_dpl_addr;
  1112. if (argc < 4)
  1113. goto usage;
  1114. if (get_dpl_apply_status() == 0) {
  1115. printf("fsl-mc: DPL already applied\n");
  1116. return err;
  1117. }
  1118. mc_dpl_addr = simple_strtoull(argv[3], NULL,
  1119. 16);
  1120. if (get_mc_boot_status() != 0) {
  1121. printf("fsl-mc: Deploying data path layout ..");
  1122. printf("ERROR (MC is not booted)\n");
  1123. return -ENODEV;
  1124. }
  1125. if (argv[1][0] == 'l') {
  1126. /*
  1127. * We will do the actual dpaa exit and dpl apply
  1128. * later from announce_and_cleanup().
  1129. */
  1130. mc_lazy_dpl_addr = mc_dpl_addr;
  1131. } else {
  1132. /* The user wants it applied now */
  1133. if (!fsl_mc_ldpaa_exit(NULL))
  1134. err = mc_apply_dpl(mc_dpl_addr);
  1135. }
  1136. break;
  1137. }
  1138. default:
  1139. printf("Invalid option: %s\n", argv[1]);
  1140. goto usage;
  1141. break;
  1142. }
  1143. return err;
  1144. usage:
  1145. return CMD_RET_USAGE;
  1146. }
  1147. U_BOOT_CMD(
  1148. fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
  1149. "DPAA2 command to manage Management Complex (MC)",
  1150. "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
  1151. "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
  1152. "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
  1153. "fsl_mc start aiop [FW_addr] - Start AIOP\n"
  1154. );
  1155. void mc_env_boot(void)
  1156. {
  1157. #if defined(CONFIG_FSL_MC_ENET)
  1158. char *mc_boot_env_var;
  1159. /* The MC may only be initialized in the reset PHY function
  1160. * because otherwise U-Boot has not yet set up all the MAC
  1161. * address info properly. Without MAC addresses, the MC code
  1162. * can not properly initialize the DPC.
  1163. */
  1164. mc_boot_env_var = getenv(MC_BOOT_ENV_VAR);
  1165. if (mc_boot_env_var)
  1166. run_command_list(mc_boot_env_var, -1, 0);
  1167. #endif /* CONFIG_FSL_MC_ENET */
  1168. }