srio.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2011 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <config.h>
  7. #include <asm/fsl_law.h>
  8. #include <asm/fsl_serdes.h>
  9. #include <asm/fsl_srio.h>
  10. #include <linux/errno.h>
  11. #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
  12. #define SRIO_PORT_ACCEPT_ALL 0x10000001
  13. #define SRIO_IB_ATMU_AR 0x80f55000
  14. #define SRIO_OB_ATMU_AR_MAINT 0x80077000
  15. #define SRIO_OB_ATMU_AR_RW 0x80045000
  16. #define SRIO_LCSBA1CSR_OFFSET 0x5c
  17. #define SRIO_MAINT_WIN_SIZE 0x1000000 /* 16M */
  18. #define SRIO_RW_WIN_SIZE 0x100000 /* 1M */
  19. #define SRIO_LCSBA1CSR 0x60000000
  20. #endif
  21. #if defined(CONFIG_FSL_CORENET)
  22. #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
  23. #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR3_SRIO1
  24. #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR3_SRIO2
  25. #else
  26. #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR_SRIO1
  27. #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR_SRIO2
  28. #endif
  29. #define _DEVDISR_RMU FSL_CORENET_DEVDISR_RMU
  30. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  31. #elif defined(CONFIG_MPC85xx)
  32. #define _DEVDISR_SRIO1 MPC85xx_DEVDISR_SRIO
  33. #define _DEVDISR_SRIO2 MPC85xx_DEVDISR_SRIO
  34. #define _DEVDISR_RMU MPC85xx_DEVDISR_RMSG
  35. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  36. #elif defined(CONFIG_MPC86xx)
  37. #define _DEVDISR_SRIO1 MPC86xx_DEVDISR_SRIO
  38. #define _DEVDISR_SRIO2 MPC86xx_DEVDISR_SRIO
  39. #define _DEVDISR_RMU MPC86xx_DEVDISR_RMSG
  40. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
  41. (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
  42. #else
  43. #error "No defines for DEVDISR_SRIO"
  44. #endif
  45. #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
  46. /*
  47. * Erratum A-004034
  48. * Affects: SRIO
  49. * Description: During port initialization, the SRIO port performs
  50. * lane synchronization (detecting valid symbols on a lane) and
  51. * lane alignment (coordinating multiple lanes to receive valid data
  52. * across lanes). Internal errors in lane synchronization and lane
  53. * alignment may cause failure to achieve link initialization at
  54. * the configured port width.
  55. * An SRIO port configured as a 4x port may see one of these scenarios:
  56. * 1. One or more lanes fails to achieve lane synchronization. Depending
  57. * on which lanes fail, this may result in downtraining from 4x to 1x
  58. * on lane 0, 4x to 1x on lane R (redundant lane).
  59. * 2. The link may fail to achieve lane alignment as a 4x, even though
  60. * all 4 lanes achieve lane synchronization, and downtrain to a 1x.
  61. * An SRIO port configured as a 1x port may fail to complete port
  62. * initialization (PnESCSR[PU] never deasserts) because of scenario 1.
  63. * Impact: SRIO port may downtrain to 1x, or may fail to complete
  64. * link initialization. Once a port completes link initialization
  65. * successfully, it will operate normally.
  66. */
  67. static int srio_erratum_a004034(u8 port)
  68. {
  69. serdes_corenet_t *srds_regs;
  70. u32 conf_lane;
  71. u32 init_lane;
  72. int idx, first, last;
  73. u32 i;
  74. unsigned long long end_tick;
  75. struct ccsr_rio *srio_regs = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
  76. srds_regs = (void *)(CONFIG_SYS_FSL_CORENET_SERDES_ADDR);
  77. conf_lane = (in_be32((void *)&srds_regs->srdspccr0)
  78. >> (12 - port * 4)) & 0x3;
  79. init_lane = (in_be32((void *)&srio_regs->lp_serial
  80. .port[port].pccsr) >> 27) & 0x7;
  81. /*
  82. * Start a counter set to ~2 ms after the SERDES reset is
  83. * complete (SERDES SRDSBnRSTCTL[RST_DONE]=1 for n
  84. * corresponding to the SERDES bank/PLL for the SRIO port).
  85. */
  86. if (in_be32((void *)&srds_regs->bank[0].rstctl)
  87. & SRDS_RSTCTL_RSTDONE) {
  88. /*
  89. * Poll the port uninitialized status (SRIO PnESCSR[PO]) until
  90. * PO=1 or the counter expires. If the counter expires, the
  91. * port has failed initialization: go to recover steps. If PO=1
  92. * and the desired port width is 1x, go to normal steps. If
  93. * PO = 1 and the desired port width is 4x, go to recover steps.
  94. */
  95. end_tick = usec2ticks(2000) + get_ticks();
  96. do {
  97. if (in_be32((void *)&srio_regs->lp_serial
  98. .port[port].pescsr) & 0x2) {
  99. if (conf_lane == 0x1)
  100. goto host_ok;
  101. else {
  102. if (init_lane == 0x2)
  103. goto host_ok;
  104. else
  105. break;
  106. }
  107. }
  108. } while (end_tick > get_ticks());
  109. /* recover at most 3 times */
  110. for (i = 0; i < 3; i++) {
  111. /* Set SRIO PnCCSR[PD]=1 */
  112. setbits_be32((void *)&srio_regs->lp_serial
  113. .port[port].pccsr,
  114. 0x800000);
  115. /*
  116. * Set SRIO PnPCR[OBDEN] on the host to
  117. * enable the discarding of any pending packets.
  118. */
  119. setbits_be32((void *)&srio_regs->impl.port[port].pcr,
  120. 0x04);
  121. /* Wait 50 us */
  122. udelay(50);
  123. /* Run sync command */
  124. isync();
  125. if (port)
  126. first = serdes_get_first_lane(SRIO2);
  127. else
  128. first = serdes_get_first_lane(SRIO1);
  129. if (unlikely(first < 0))
  130. return -ENODEV;
  131. if (conf_lane == 0x1)
  132. last = first;
  133. else
  134. last = first + 3;
  135. /*
  136. * Set SERDES BnGCRm0[RRST]=0 for each SRIO
  137. * bank n and lane m.
  138. */
  139. for (idx = first; idx <= last; idx++)
  140. clrbits_be32(&srds_regs->lane[idx].gcr0,
  141. SRDS_GCR0_RRST);
  142. /*
  143. * Read SERDES BnGCRm0 for each SRIO
  144. * bank n and lane m
  145. */
  146. for (idx = first; idx <= last; idx++)
  147. in_be32(&srds_regs->lane[idx].gcr0);
  148. /* Run sync command */
  149. isync();
  150. /* Wait >= 100 ns */
  151. udelay(1);
  152. /*
  153. * Set SERDES BnGCRm0[RRST]=1 for each SRIO
  154. * bank n and lane m.
  155. */
  156. for (idx = first; idx <= last; idx++)
  157. setbits_be32(&srds_regs->lane[idx].gcr0,
  158. SRDS_GCR0_RRST);
  159. /*
  160. * Read SERDES BnGCRm0 for each SRIO
  161. * bank n and lane m
  162. */
  163. for (idx = first; idx <= last; idx++)
  164. in_be32(&srds_regs->lane[idx].gcr0);
  165. /* Run sync command */
  166. isync();
  167. /* Wait >= 300 ns */
  168. udelay(1);
  169. /* Write 1 to clear all bits in SRIO PnSLCSR */
  170. out_be32((void *)&srio_regs->impl.port[port].slcsr,
  171. 0xffffffff);
  172. /* Clear SRIO PnPCR[OBDEN] on the host */
  173. clrbits_be32((void *)&srio_regs->impl.port[port].pcr,
  174. 0x04);
  175. /* Set SRIO PnCCSR[PD]=0 */
  176. clrbits_be32((void *)&srio_regs->lp_serial
  177. .port[port].pccsr,
  178. 0x800000);
  179. /* Wait >= 24 ms */
  180. udelay(24000);
  181. /* Poll the state of the port again */
  182. init_lane =
  183. (in_be32((void *)&srio_regs->lp_serial
  184. .port[port].pccsr) >> 27) & 0x7;
  185. if (in_be32((void *)&srio_regs->lp_serial
  186. .port[port].pescsr) & 0x2) {
  187. if (conf_lane == 0x1)
  188. goto host_ok;
  189. else {
  190. if (init_lane == 0x2)
  191. goto host_ok;
  192. }
  193. }
  194. if (i == 2)
  195. return -ENODEV;
  196. }
  197. } else
  198. return -ENODEV;
  199. host_ok:
  200. /* Poll PnESCSR[OES] on the host until it is clear */
  201. end_tick = usec2ticks(1000000) + get_ticks();
  202. do {
  203. if (!(in_be32((void *)&srio_regs->lp_serial.port[port].pescsr)
  204. & 0x10000)) {
  205. out_be32(((void *)&srio_regs->lp_serial
  206. .port[port].pescsr), 0xffffffff);
  207. out_be32(((void *)&srio_regs->phys_err
  208. .port[port].edcsr), 0);
  209. out_be32(((void *)&srio_regs->logical_err.ltledcsr), 0);
  210. return 0;
  211. }
  212. } while (end_tick > get_ticks());
  213. return -ENODEV;
  214. }
  215. #endif
  216. void srio_init(void)
  217. {
  218. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
  219. int srio1_used = 0, srio2_used = 0;
  220. u32 *devdisr;
  221. #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
  222. devdisr = &gur->devdisr3;
  223. #else
  224. devdisr = &gur->devdisr;
  225. #endif
  226. if (is_serdes_configured(SRIO1)) {
  227. set_next_law(CONFIG_SYS_SRIO1_MEM_PHYS,
  228. law_size_bits(CONFIG_SYS_SRIO1_MEM_SIZE),
  229. LAW_TRGT_IF_RIO_1);
  230. srio1_used = 1;
  231. #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
  232. if (srio_erratum_a004034(0) < 0)
  233. printf("SRIO1: enabled but port error\n");
  234. else
  235. #endif
  236. printf("SRIO1: enabled\n");
  237. } else {
  238. printf("SRIO1: disabled\n");
  239. }
  240. #ifdef CONFIG_SRIO2
  241. if (is_serdes_configured(SRIO2)) {
  242. set_next_law(CONFIG_SYS_SRIO2_MEM_PHYS,
  243. law_size_bits(CONFIG_SYS_SRIO2_MEM_SIZE),
  244. LAW_TRGT_IF_RIO_2);
  245. srio2_used = 1;
  246. #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
  247. if (srio_erratum_a004034(1) < 0)
  248. printf("SRIO2: enabled but port error\n");
  249. else
  250. #endif
  251. printf("SRIO2: enabled\n");
  252. } else {
  253. printf("SRIO2: disabled\n");
  254. }
  255. #endif
  256. #ifdef CONFIG_FSL_CORENET
  257. /* On FSL_CORENET devices we can disable individual ports */
  258. if (!srio1_used)
  259. setbits_be32(devdisr, _DEVDISR_SRIO1);
  260. if (!srio2_used)
  261. setbits_be32(devdisr, _DEVDISR_SRIO2);
  262. #endif
  263. /* neither port is used - disable everything */
  264. if (!srio1_used && !srio2_used) {
  265. setbits_be32(devdisr, _DEVDISR_SRIO1);
  266. setbits_be32(devdisr, _DEVDISR_SRIO2);
  267. setbits_be32(devdisr, _DEVDISR_RMU);
  268. }
  269. }
  270. #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
  271. void srio_boot_master(int port)
  272. {
  273. struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
  274. /* set port accept-all */
  275. out_be32((void *)&srio->impl.port[port - 1].ptaacr,
  276. SRIO_PORT_ACCEPT_ALL);
  277. debug("SRIOBOOT - MASTER: Master port [ %d ] for srio boot.\n", port);
  278. /* configure inbound window for slave's u-boot image */
  279. debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
  280. "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
  281. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
  282. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
  283. CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
  284. out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwtar,
  285. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
  286. out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwbar,
  287. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1 >> 12);
  288. out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwar,
  289. SRIO_IB_ATMU_AR
  290. | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
  291. /* configure inbound window for slave's u-boot image */
  292. debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
  293. "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
  294. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
  295. (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
  296. CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
  297. out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwtar,
  298. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
  299. out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwbar,
  300. CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2 >> 12);
  301. out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwar,
  302. SRIO_IB_ATMU_AR
  303. | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
  304. /* configure inbound window for slave's ucode and ENV */
  305. debug("SRIOBOOT - MASTER: Inbound window for slave's ucode and ENV; "
  306. "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
  307. (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
  308. (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
  309. CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
  310. out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwtar,
  311. CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS >> 12);
  312. out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwbar,
  313. CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS >> 12);
  314. out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwar,
  315. SRIO_IB_ATMU_AR
  316. | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE));
  317. }
  318. void srio_boot_master_release_slave(int port)
  319. {
  320. struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
  321. u32 escsr;
  322. debug("SRIOBOOT - MASTER: "
  323. "Check the port status and release slave core ...\n");
  324. escsr = in_be32((void *)&srio->lp_serial.port[port - 1].pescsr);
  325. if (escsr & 0x2) {
  326. if (escsr & 0x10100) {
  327. debug("SRIOBOOT - MASTER: Port [ %d ] is error.\n",
  328. port);
  329. } else {
  330. debug("SRIOBOOT - MASTER: "
  331. "Port [ %d ] is ready, now release slave's core ...\n",
  332. port);
  333. /*
  334. * configure outbound window
  335. * with maintenance attribute to set slave's LCSBA1CSR
  336. */
  337. out_be32((void *)&srio->atmu.port[port - 1]
  338. .outbw[1].rowtar, 0);
  339. out_be32((void *)&srio->atmu.port[port - 1]
  340. .outbw[1].rowtear, 0);
  341. if (port - 1)
  342. out_be32((void *)&srio->atmu.port[port - 1]
  343. .outbw[1].rowbar,
  344. CONFIG_SYS_SRIO2_MEM_PHYS >> 12);
  345. else
  346. out_be32((void *)&srio->atmu.port[port - 1]
  347. .outbw[1].rowbar,
  348. CONFIG_SYS_SRIO1_MEM_PHYS >> 12);
  349. out_be32((void *)&srio->atmu.port[port - 1]
  350. .outbw[1].rowar,
  351. SRIO_OB_ATMU_AR_MAINT
  352. | atmu_size_mask(SRIO_MAINT_WIN_SIZE));
  353. /*
  354. * configure outbound window
  355. * with R/W attribute to set slave's BRR
  356. */
  357. out_be32((void *)&srio->atmu.port[port - 1]
  358. .outbw[2].rowtar,
  359. SRIO_LCSBA1CSR >> 9);
  360. out_be32((void *)&srio->atmu.port[port - 1]
  361. .outbw[2].rowtear, 0);
  362. if (port - 1)
  363. out_be32((void *)&srio->atmu.port[port - 1]
  364. .outbw[2].rowbar,
  365. (CONFIG_SYS_SRIO2_MEM_PHYS
  366. + SRIO_MAINT_WIN_SIZE) >> 12);
  367. else
  368. out_be32((void *)&srio->atmu.port[port - 1]
  369. .outbw[2].rowbar,
  370. (CONFIG_SYS_SRIO1_MEM_PHYS
  371. + SRIO_MAINT_WIN_SIZE) >> 12);
  372. out_be32((void *)&srio->atmu.port[port - 1]
  373. .outbw[2].rowar,
  374. SRIO_OB_ATMU_AR_RW
  375. | atmu_size_mask(SRIO_RW_WIN_SIZE));
  376. /*
  377. * Set the LCSBA1CSR register in slave
  378. * by the maint-outbound window
  379. */
  380. if (port - 1) {
  381. out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
  382. + SRIO_LCSBA1CSR_OFFSET,
  383. SRIO_LCSBA1CSR);
  384. while (in_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
  385. + SRIO_LCSBA1CSR_OFFSET)
  386. != SRIO_LCSBA1CSR)
  387. ;
  388. /*
  389. * And then set the BRR register
  390. * to release slave core
  391. */
  392. out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
  393. + SRIO_MAINT_WIN_SIZE
  394. + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
  395. CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
  396. } else {
  397. out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
  398. + SRIO_LCSBA1CSR_OFFSET,
  399. SRIO_LCSBA1CSR);
  400. while (in_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
  401. + SRIO_LCSBA1CSR_OFFSET)
  402. != SRIO_LCSBA1CSR)
  403. ;
  404. /*
  405. * And then set the BRR register
  406. * to release slave core
  407. */
  408. out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
  409. + SRIO_MAINT_WIN_SIZE
  410. + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
  411. CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
  412. }
  413. debug("SRIOBOOT - MASTER: "
  414. "Release slave successfully! Now the slave should start up!\n");
  415. }
  416. } else
  417. debug("SRIOBOOT - MASTER: Port [ %d ] is not ready.\n", port);
  418. }
  419. #endif