srio.c 14 KB

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