srio.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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. #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR_SRIO1
  35. #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR_SRIO2
  36. #define _DEVDISR_RMU FSL_CORENET_DEVDISR_RMU
  37. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  38. #elif defined(CONFIG_MPC85xx)
  39. #define _DEVDISR_SRIO1 MPC85xx_DEVDISR_SRIO
  40. #define _DEVDISR_SRIO2 MPC85xx_DEVDISR_SRIO
  41. #define _DEVDISR_RMU MPC85xx_DEVDISR_RMSG
  42. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
  43. #elif defined(CONFIG_MPC86xx)
  44. #define _DEVDISR_SRIO1 MPC86xx_DEVDISR_SRIO
  45. #define _DEVDISR_SRIO2 MPC86xx_DEVDISR_SRIO
  46. #define _DEVDISR_RMU MPC86xx_DEVDISR_RMSG
  47. #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
  48. (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
  49. #else
  50. #error "No defines for DEVDISR_SRIO"
  51. #endif
  52. #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
  53. /*
  54. * Erratum A-004034
  55. * Affects: SRIO
  56. * Description: During port initialization, the SRIO port performs
  57. * lane synchronization (detecting valid symbols on a lane) and
  58. * lane alignment (coordinating multiple lanes to receive valid data
  59. * across lanes). Internal errors in lane synchronization and lane
  60. * alignment may cause failure to achieve link initialization at
  61. * the configured port width.
  62. * An SRIO port configured as a 4x port may see one of these scenarios:
  63. * 1. One or more lanes fails to achieve lane synchronization. Depending
  64. * on which lanes fail, this may result in downtraining from 4x to 1x
  65. * on lane 0, 4x to 1x on lane R (redundant lane).
  66. * 2. The link may fail to achieve lane alignment as a 4x, even though
  67. * all 4 lanes achieve lane synchronization, and downtrain to a 1x.
  68. * An SRIO port configured as a 1x port may fail to complete port
  69. * initialization (PnESCSR[PU] never deasserts) because of scenario 1.
  70. * Impact: SRIO port may downtrain to 1x, or may fail to complete
  71. * link initialization. Once a port completes link initialization
  72. * successfully, it will operate normally.
  73. */
  74. static int srio_erratum_a004034(u8 port)
  75. {
  76. serdes_corenet_t *srds_regs;
  77. u32 conf_lane;
  78. u32 init_lane;
  79. int idx, first, last;
  80. u32 i;
  81. unsigned long long end_tick;
  82. struct ccsr_rio *srio_regs = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
  83. srds_regs = (void *)(CONFIG_SYS_FSL_CORENET_SERDES_ADDR);
  84. conf_lane = (in_be32((void *)&srds_regs->srdspccr0)
  85. >> (12 - port * 4)) & 0x3;
  86. init_lane = (in_be32((void *)&srio_regs->lp_serial
  87. .port[port].pccsr) >> 27) & 0x7;
  88. /*
  89. * Start a counter set to ~2 ms after the SERDES reset is
  90. * complete (SERDES SRDSBnRSTCTL[RST_DONE]=1 for n
  91. * corresponding to the SERDES bank/PLL for the SRIO port).
  92. */
  93. if (in_be32((void *)&srds_regs->bank[0].rstctl)
  94. & SRDS_RSTCTL_RSTDONE) {
  95. /*
  96. * Poll the port uninitialized status (SRIO PnESCSR[PO]) until
  97. * PO=1 or the counter expires. If the counter expires, the
  98. * port has failed initialization: go to recover steps. If PO=1
  99. * and the desired port width is 1x, go to normal steps. If
  100. * PO = 1 and the desired port width is 4x, go to recover steps.
  101. */
  102. end_tick = usec2ticks(2000) + get_ticks();
  103. do {
  104. if (in_be32((void *)&srio_regs->lp_serial
  105. .port[port].pescsr) & 0x2) {
  106. if (conf_lane == 0x1)
  107. goto host_ok;
  108. else {
  109. if (init_lane == 0x2)
  110. goto host_ok;
  111. else
  112. break;
  113. }
  114. }
  115. } while (end_tick > get_ticks());
  116. /* recover at most 3 times */
  117. for (i = 0; i < 3; i++) {
  118. /* Set SRIO PnCCSR[PD]=1 */
  119. setbits_be32((void *)&srio_regs->lp_serial
  120. .port[port].pccsr,
  121. 0x800000);
  122. /*
  123. * Set SRIO PnPCR[OBDEN] on the host to
  124. * enable the discarding of any pending packets.
  125. */
  126. setbits_be32((void *)&srio_regs->impl.port[port].pcr,
  127. 0x04);
  128. /* Wait 50 us */
  129. udelay(50);
  130. /* Run sync command */
  131. isync();
  132. if (port)
  133. first = serdes_get_first_lane(SRIO2);
  134. else
  135. first = serdes_get_first_lane(SRIO1);
  136. if (unlikely(first < 0))
  137. return -ENODEV;
  138. if (conf_lane == 0x1)
  139. last = first;
  140. else
  141. last = first + 3;
  142. /*
  143. * Set SERDES BnGCRm0[RRST]=0 for each SRIO
  144. * bank n and lane m.
  145. */
  146. for (idx = first; idx <= last; idx++)
  147. clrbits_be32(&srds_regs->lane[idx].gcr0,
  148. SRDS_GCR0_RRST);
  149. /*
  150. * Read SERDES BnGCRm0 for each SRIO
  151. * bank n and lane m
  152. */
  153. for (idx = first; idx <= last; idx++)
  154. in_be32(&srds_regs->lane[idx].gcr0);
  155. /* Run sync command */
  156. isync();
  157. /* Wait >= 100 ns */
  158. udelay(1);
  159. /*
  160. * Set SERDES BnGCRm0[RRST]=1 for each SRIO
  161. * bank n and lane m.
  162. */
  163. for (idx = first; idx <= last; idx++)
  164. setbits_be32(&srds_regs->lane[idx].gcr0,
  165. SRDS_GCR0_RRST);
  166. /*
  167. * Read SERDES BnGCRm0 for each SRIO
  168. * bank n and lane m
  169. */
  170. for (idx = first; idx <= last; idx++)
  171. in_be32(&srds_regs->lane[idx].gcr0);
  172. /* Run sync command */
  173. isync();
  174. /* Wait >= 300 ns */
  175. udelay(1);
  176. /* Write 1 to clear all bits in SRIO PnSLCSR */
  177. out_be32((void *)&srio_regs->impl.port[port].slcsr,
  178. 0xffffffff);
  179. /* Clear SRIO PnPCR[OBDEN] on the host */
  180. clrbits_be32((void *)&srio_regs->impl.port[port].pcr,
  181. 0x04);
  182. /* Set SRIO PnCCSR[PD]=0 */
  183. clrbits_be32((void *)&srio_regs->lp_serial
  184. .port[port].pccsr,
  185. 0x800000);
  186. /* Wait >= 24 ms */
  187. udelay(24000);
  188. /* Poll the state of the port again */
  189. init_lane =
  190. (in_be32((void *)&srio_regs->lp_serial
  191. .port[port].pccsr) >> 27) & 0x7;
  192. if (in_be32((void *)&srio_regs->lp_serial
  193. .port[port].pescsr) & 0x2) {
  194. if (conf_lane == 0x1)
  195. goto host_ok;
  196. else {
  197. if (init_lane == 0x2)
  198. goto host_ok;
  199. }
  200. }
  201. if (i == 2)
  202. return -ENODEV;
  203. }
  204. } else
  205. return -ENODEV;
  206. host_ok:
  207. /* Poll PnESCSR[OES] on the host until it is clear */
  208. end_tick = usec2ticks(1000000) + get_ticks();
  209. do {
  210. if (!(in_be32((void *)&srio_regs->lp_serial.port[port].pescsr)
  211. & 0x10000)) {
  212. out_be32(((void *)&srio_regs->lp_serial
  213. .port[port].pescsr), 0xffffffff);
  214. out_be32(((void *)&srio_regs->phys_err
  215. .port[port].edcsr), 0);
  216. out_be32(((void *)&srio_regs->logical_err.ltledcsr), 0);
  217. return 0;
  218. }
  219. } while (end_tick > get_ticks());
  220. return -ENODEV;
  221. }
  222. #endif
  223. void srio_init(void)
  224. {
  225. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
  226. int srio1_used = 0, srio2_used = 0;
  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(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO1);
  261. if (!srio2_used)
  262. setbits_be32(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO2);
  263. #endif
  264. /* neither port is used - disable everything */
  265. if (!srio1_used && !srio2_used) {
  266. setbits_be32(&gur->devdisr, _DEVDISR_SRIO1);
  267. setbits_be32(&gur->devdisr, _DEVDISR_SRIO2);
  268. setbits_be32(&gur->devdisr, _DEVDISR_RMU);
  269. }
  270. }
  271. #ifdef CONFIG_FSL_CORENET
  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