srio.c 13 KB

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