srio.c 14 KB

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