1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2011 Freescale Semiconductor, Inc.
10 #include <asm/fsl_law.h>
11 #include <asm/fsl_serdes.h>
12 #include <asm/fsl_srio.h>
13 #include <linux/delay.h>
14 #include <linux/errno.h>
16 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
17 #define SRIO_PORT_ACCEPT_ALL 0x10000001
18 #define SRIO_IB_ATMU_AR 0x80f55000
19 #define SRIO_OB_ATMU_AR_MAINT 0x80077000
20 #define SRIO_OB_ATMU_AR_RW 0x80045000
21 #define SRIO_LCSBA1CSR_OFFSET 0x5c
22 #define SRIO_MAINT_WIN_SIZE 0x1000000 /* 16M */
23 #define SRIO_RW_WIN_SIZE 0x100000 /* 1M */
24 #define SRIO_LCSBA1CSR 0x60000000
27 #if defined(CONFIG_FSL_CORENET)
28 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
29 #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR3_SRIO1
30 #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR3_SRIO2
32 #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR_SRIO1
33 #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR_SRIO2
35 #define _DEVDISR_RMU FSL_CORENET_DEVDISR_RMU
36 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
37 #elif defined(CONFIG_MPC85xx)
38 #define _DEVDISR_SRIO1 MPC85xx_DEVDISR_SRIO
39 #define _DEVDISR_SRIO2 MPC85xx_DEVDISR_SRIO
40 #define _DEVDISR_RMU MPC85xx_DEVDISR_RMSG
41 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
42 #elif defined(CONFIG_MPC86xx)
43 #define _DEVDISR_SRIO1 MPC86xx_DEVDISR_SRIO
44 #define _DEVDISR_SRIO2 MPC86xx_DEVDISR_SRIO
45 #define _DEVDISR_RMU MPC86xx_DEVDISR_RMSG
46 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
47 (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
49 #error "No defines for DEVDISR_SRIO"
52 #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
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.
74 static int srio_erratum_a004034(u8 port)
76 serdes_corenet_t *srds_regs;
81 unsigned long long end_tick;
82 struct ccsr_rio *srio_regs = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
84 srds_regs = (void *)(CONFIG_SYS_FSL_CORENET_SERDES_ADDR);
85 conf_lane = (in_be32((void *)&srds_regs->srdspccr0)
86 >> (12 - port * 4)) & 0x3;
87 init_lane = (in_be32((void *)&srio_regs->lp_serial
88 .port[port].pccsr) >> 27) & 0x7;
91 * Start a counter set to ~2 ms after the SERDES reset is
92 * complete (SERDES SRDSBnRSTCTL[RST_DONE]=1 for n
93 * corresponding to the SERDES bank/PLL for the SRIO port).
95 if (in_be32((void *)&srds_regs->bank[0].rstctl)
96 & SRDS_RSTCTL_RSTDONE) {
98 * Poll the port uninitialized status (SRIO PnESCSR[PO]) until
99 * PO=1 or the counter expires. If the counter expires, the
100 * port has failed initialization: go to recover steps. If PO=1
101 * and the desired port width is 1x, go to normal steps. If
102 * PO = 1 and the desired port width is 4x, go to recover steps.
104 end_tick = usec2ticks(2000) + get_ticks();
106 if (in_be32((void *)&srio_regs->lp_serial
107 .port[port].pescsr) & 0x2) {
108 if (conf_lane == 0x1)
111 if (init_lane == 0x2)
117 } while (end_tick > get_ticks());
119 /* recover at most 3 times */
120 for (i = 0; i < 3; i++) {
121 /* Set SRIO PnCCSR[PD]=1 */
122 setbits_be32((void *)&srio_regs->lp_serial
126 * Set SRIO PnPCR[OBDEN] on the host to
127 * enable the discarding of any pending packets.
129 setbits_be32((void *)&srio_regs->impl.port[port].pcr,
133 /* Run sync command */
137 first = serdes_get_first_lane(SRIO2);
139 first = serdes_get_first_lane(SRIO1);
140 if (unlikely(first < 0))
142 if (conf_lane == 0x1)
147 * Set SERDES BnGCRm0[RRST]=0 for each SRIO
150 for (idx = first; idx <= last; idx++)
151 clrbits_be32(&srds_regs->lane[idx].gcr0,
154 * Read SERDES BnGCRm0 for each SRIO
157 for (idx = first; idx <= last; idx++)
158 in_be32(&srds_regs->lane[idx].gcr0);
159 /* Run sync command */
164 * Set SERDES BnGCRm0[RRST]=1 for each SRIO
167 for (idx = first; idx <= last; idx++)
168 setbits_be32(&srds_regs->lane[idx].gcr0,
171 * Read SERDES BnGCRm0 for each SRIO
174 for (idx = first; idx <= last; idx++)
175 in_be32(&srds_regs->lane[idx].gcr0);
176 /* Run sync command */
181 /* Write 1 to clear all bits in SRIO PnSLCSR */
182 out_be32((void *)&srio_regs->impl.port[port].slcsr,
184 /* Clear SRIO PnPCR[OBDEN] on the host */
185 clrbits_be32((void *)&srio_regs->impl.port[port].pcr,
187 /* Set SRIO PnCCSR[PD]=0 */
188 clrbits_be32((void *)&srio_regs->lp_serial
193 /* Poll the state of the port again */
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)
202 if (init_lane == 0x2)
213 /* Poll PnESCSR[OES] on the host until it is clear */
214 end_tick = usec2ticks(1000000) + get_ticks();
216 if (!(in_be32((void *)&srio_regs->lp_serial.port[port].pescsr)
218 out_be32(((void *)&srio_regs->lp_serial
219 .port[port].pescsr), 0xffffffff);
220 out_be32(((void *)&srio_regs->phys_err
221 .port[port].edcsr), 0);
222 out_be32(((void *)&srio_regs->logical_err.ltledcsr), 0);
225 } while (end_tick > get_ticks());
233 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
234 int srio1_used = 0, srio2_used = 0;
237 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
238 devdisr = &gur->devdisr3;
240 devdisr = &gur->devdisr;
242 if (is_serdes_configured(SRIO1)) {
243 set_next_law(CONFIG_SYS_SRIO1_MEM_PHYS,
244 law_size_bits(CONFIG_SYS_SRIO1_MEM_SIZE),
247 #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
248 if (srio_erratum_a004034(0) < 0)
249 printf("SRIO1: enabled but port error\n");
252 printf("SRIO1: enabled\n");
254 printf("SRIO1: disabled\n");
258 if (is_serdes_configured(SRIO2)) {
259 set_next_law(CONFIG_SYS_SRIO2_MEM_PHYS,
260 law_size_bits(CONFIG_SYS_SRIO2_MEM_SIZE),
263 #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
264 if (srio_erratum_a004034(1) < 0)
265 printf("SRIO2: enabled but port error\n");
268 printf("SRIO2: enabled\n");
271 printf("SRIO2: disabled\n");
275 #ifdef CONFIG_FSL_CORENET
276 /* On FSL_CORENET devices we can disable individual ports */
278 setbits_be32(devdisr, _DEVDISR_SRIO1);
280 setbits_be32(devdisr, _DEVDISR_SRIO2);
283 /* neither port is used - disable everything */
284 if (!srio1_used && !srio2_used) {
285 setbits_be32(devdisr, _DEVDISR_SRIO1);
286 setbits_be32(devdisr, _DEVDISR_SRIO2);
287 setbits_be32(devdisr, _DEVDISR_RMU);
291 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
292 void srio_boot_master(int port)
294 struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
296 /* set port accept-all */
297 out_be32((void *)&srio->impl.port[port - 1].ptaacr,
298 SRIO_PORT_ACCEPT_ALL);
300 debug("SRIOBOOT - MASTER: Master port [ %d ] for srio boot.\n", port);
301 /* configure inbound window for slave's u-boot image */
302 debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
303 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
304 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
305 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
306 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
307 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwtar,
308 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
309 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwbar,
310 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1 >> 12);
311 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwar,
313 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
315 /* configure inbound window for slave's u-boot image */
316 debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
317 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
318 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
319 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
320 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
321 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwtar,
322 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
323 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwbar,
324 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2 >> 12);
325 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwar,
327 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
329 /* configure inbound window for slave's ucode and ENV */
330 debug("SRIOBOOT - MASTER: Inbound window for slave's ucode and ENV; "
331 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
332 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
333 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
334 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
335 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwtar,
336 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS >> 12);
337 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwbar,
338 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS >> 12);
339 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwar,
341 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE));
344 void srio_boot_master_release_slave(int port)
346 struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
348 debug("SRIOBOOT - MASTER: "
349 "Check the port status and release slave core ...\n");
351 escsr = in_be32((void *)&srio->lp_serial.port[port - 1].pescsr);
353 if (escsr & 0x10100) {
354 debug("SRIOBOOT - MASTER: Port [ %d ] is error.\n",
357 debug("SRIOBOOT - MASTER: "
358 "Port [ %d ] is ready, now release slave's core ...\n",
361 * configure outbound window
362 * with maintenance attribute to set slave's LCSBA1CSR
364 out_be32((void *)&srio->atmu.port[port - 1]
365 .outbw[1].rowtar, 0);
366 out_be32((void *)&srio->atmu.port[port - 1]
367 .outbw[1].rowtear, 0);
369 out_be32((void *)&srio->atmu.port[port - 1]
371 CONFIG_SYS_SRIO2_MEM_PHYS >> 12);
373 out_be32((void *)&srio->atmu.port[port - 1]
375 CONFIG_SYS_SRIO1_MEM_PHYS >> 12);
376 out_be32((void *)&srio->atmu.port[port - 1]
378 SRIO_OB_ATMU_AR_MAINT
379 | atmu_size_mask(SRIO_MAINT_WIN_SIZE));
382 * configure outbound window
383 * with R/W attribute to set slave's BRR
385 out_be32((void *)&srio->atmu.port[port - 1]
387 SRIO_LCSBA1CSR >> 9);
388 out_be32((void *)&srio->atmu.port[port - 1]
389 .outbw[2].rowtear, 0);
391 out_be32((void *)&srio->atmu.port[port - 1]
393 (CONFIG_SYS_SRIO2_MEM_PHYS
394 + SRIO_MAINT_WIN_SIZE) >> 12);
396 out_be32((void *)&srio->atmu.port[port - 1]
398 (CONFIG_SYS_SRIO1_MEM_PHYS
399 + SRIO_MAINT_WIN_SIZE) >> 12);
400 out_be32((void *)&srio->atmu.port[port - 1]
403 | atmu_size_mask(SRIO_RW_WIN_SIZE));
406 * Set the LCSBA1CSR register in slave
407 * by the maint-outbound window
410 out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
411 + SRIO_LCSBA1CSR_OFFSET,
413 while (in_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
414 + SRIO_LCSBA1CSR_OFFSET)
418 * And then set the BRR register
419 * to release slave core
421 out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
422 + SRIO_MAINT_WIN_SIZE
423 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
424 CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
426 out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
427 + SRIO_LCSBA1CSR_OFFSET,
429 while (in_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
430 + SRIO_LCSBA1CSR_OFFSET)
434 * And then set the BRR register
435 * to release slave core
437 out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
438 + SRIO_MAINT_WIN_SIZE
439 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
440 CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
442 debug("SRIOBOOT - MASTER: "
443 "Release slave successfully! Now the slave should start up!\n");
446 debug("SRIOBOOT - MASTER: Port [ %d ] is not ready.\n", port);