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/errno.h>
15 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
16 #define SRIO_PORT_ACCEPT_ALL 0x10000001
17 #define SRIO_IB_ATMU_AR 0x80f55000
18 #define SRIO_OB_ATMU_AR_MAINT 0x80077000
19 #define SRIO_OB_ATMU_AR_RW 0x80045000
20 #define SRIO_LCSBA1CSR_OFFSET 0x5c
21 #define SRIO_MAINT_WIN_SIZE 0x1000000 /* 16M */
22 #define SRIO_RW_WIN_SIZE 0x100000 /* 1M */
23 #define SRIO_LCSBA1CSR 0x60000000
26 #if defined(CONFIG_FSL_CORENET)
27 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
28 #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR3_SRIO1
29 #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR3_SRIO2
31 #define _DEVDISR_SRIO1 FSL_CORENET_DEVDISR_SRIO1
32 #define _DEVDISR_SRIO2 FSL_CORENET_DEVDISR_SRIO2
34 #define _DEVDISR_RMU FSL_CORENET_DEVDISR_RMU
35 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
36 #elif defined(CONFIG_MPC85xx)
37 #define _DEVDISR_SRIO1 MPC85xx_DEVDISR_SRIO
38 #define _DEVDISR_SRIO2 MPC85xx_DEVDISR_SRIO
39 #define _DEVDISR_RMU MPC85xx_DEVDISR_RMSG
40 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR CONFIG_SYS_MPC85xx_GUTS_ADDR
41 #elif defined(CONFIG_MPC86xx)
42 #define _DEVDISR_SRIO1 MPC86xx_DEVDISR_SRIO
43 #define _DEVDISR_SRIO2 MPC86xx_DEVDISR_SRIO
44 #define _DEVDISR_RMU MPC86xx_DEVDISR_RMSG
45 #define CONFIG_SYS_MPC8xxx_GUTS_ADDR \
46 (&((immap_t *)CONFIG_SYS_IMMR)->im_gur)
48 #error "No defines for DEVDISR_SRIO"
51 #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
55 * Description: During port initialization, the SRIO port performs
56 * lane synchronization (detecting valid symbols on a lane) and
57 * lane alignment (coordinating multiple lanes to receive valid data
58 * across lanes). Internal errors in lane synchronization and lane
59 * alignment may cause failure to achieve link initialization at
60 * the configured port width.
61 * An SRIO port configured as a 4x port may see one of these scenarios:
62 * 1. One or more lanes fails to achieve lane synchronization. Depending
63 * on which lanes fail, this may result in downtraining from 4x to 1x
64 * on lane 0, 4x to 1x on lane R (redundant lane).
65 * 2. The link may fail to achieve lane alignment as a 4x, even though
66 * all 4 lanes achieve lane synchronization, and downtrain to a 1x.
67 * An SRIO port configured as a 1x port may fail to complete port
68 * initialization (PnESCSR[PU] never deasserts) because of scenario 1.
69 * Impact: SRIO port may downtrain to 1x, or may fail to complete
70 * link initialization. Once a port completes link initialization
71 * successfully, it will operate normally.
73 static int srio_erratum_a004034(u8 port)
75 serdes_corenet_t *srds_regs;
80 unsigned long long end_tick;
81 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;
90 * Start a counter set to ~2 ms after the SERDES reset is
91 * complete (SERDES SRDSBnRSTCTL[RST_DONE]=1 for n
92 * corresponding to the SERDES bank/PLL for the SRIO port).
94 if (in_be32((void *)&srds_regs->bank[0].rstctl)
95 & SRDS_RSTCTL_RSTDONE) {
97 * Poll the port uninitialized status (SRIO PnESCSR[PO]) until
98 * PO=1 or the counter expires. If the counter expires, the
99 * port has failed initialization: go to recover steps. If PO=1
100 * and the desired port width is 1x, go to normal steps. If
101 * PO = 1 and the desired port width is 4x, go to recover steps.
103 end_tick = usec2ticks(2000) + get_ticks();
105 if (in_be32((void *)&srio_regs->lp_serial
106 .port[port].pescsr) & 0x2) {
107 if (conf_lane == 0x1)
110 if (init_lane == 0x2)
116 } while (end_tick > get_ticks());
118 /* recover at most 3 times */
119 for (i = 0; i < 3; i++) {
120 /* Set SRIO PnCCSR[PD]=1 */
121 setbits_be32((void *)&srio_regs->lp_serial
125 * Set SRIO PnPCR[OBDEN] on the host to
126 * enable the discarding of any pending packets.
128 setbits_be32((void *)&srio_regs->impl.port[port].pcr,
132 /* Run sync command */
136 first = serdes_get_first_lane(SRIO2);
138 first = serdes_get_first_lane(SRIO1);
139 if (unlikely(first < 0))
141 if (conf_lane == 0x1)
146 * Set SERDES BnGCRm0[RRST]=0 for each SRIO
149 for (idx = first; idx <= last; idx++)
150 clrbits_be32(&srds_regs->lane[idx].gcr0,
153 * Read SERDES BnGCRm0 for each SRIO
156 for (idx = first; idx <= last; idx++)
157 in_be32(&srds_regs->lane[idx].gcr0);
158 /* Run sync command */
163 * Set SERDES BnGCRm0[RRST]=1 for each SRIO
166 for (idx = first; idx <= last; idx++)
167 setbits_be32(&srds_regs->lane[idx].gcr0,
170 * Read SERDES BnGCRm0 for each SRIO
173 for (idx = first; idx <= last; idx++)
174 in_be32(&srds_regs->lane[idx].gcr0);
175 /* Run sync command */
180 /* Write 1 to clear all bits in SRIO PnSLCSR */
181 out_be32((void *)&srio_regs->impl.port[port].slcsr,
183 /* Clear SRIO PnPCR[OBDEN] on the host */
184 clrbits_be32((void *)&srio_regs->impl.port[port].pcr,
186 /* Set SRIO PnCCSR[PD]=0 */
187 clrbits_be32((void *)&srio_regs->lp_serial
192 /* Poll the state of the port again */
194 (in_be32((void *)&srio_regs->lp_serial
195 .port[port].pccsr) >> 27) & 0x7;
196 if (in_be32((void *)&srio_regs->lp_serial
197 .port[port].pescsr) & 0x2) {
198 if (conf_lane == 0x1)
201 if (init_lane == 0x2)
212 /* Poll PnESCSR[OES] on the host until it is clear */
213 end_tick = usec2ticks(1000000) + get_ticks();
215 if (!(in_be32((void *)&srio_regs->lp_serial.port[port].pescsr)
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);
224 } while (end_tick > get_ticks());
232 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC8xxx_GUTS_ADDR;
233 int srio1_used = 0, srio2_used = 0;
236 #ifdef CONFIG_SYS_FSL_QORIQ_CHASSIS2
237 devdisr = &gur->devdisr3;
239 devdisr = &gur->devdisr;
241 if (is_serdes_configured(SRIO1)) {
242 set_next_law(CONFIG_SYS_SRIO1_MEM_PHYS,
243 law_size_bits(CONFIG_SYS_SRIO1_MEM_SIZE),
246 #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
247 if (srio_erratum_a004034(0) < 0)
248 printf("SRIO1: enabled but port error\n");
251 printf("SRIO1: enabled\n");
253 printf("SRIO1: disabled\n");
257 if (is_serdes_configured(SRIO2)) {
258 set_next_law(CONFIG_SYS_SRIO2_MEM_PHYS,
259 law_size_bits(CONFIG_SYS_SRIO2_MEM_SIZE),
262 #ifdef CONFIG_SYS_FSL_ERRATUM_SRIO_A004034
263 if (srio_erratum_a004034(1) < 0)
264 printf("SRIO2: enabled but port error\n");
267 printf("SRIO2: enabled\n");
270 printf("SRIO2: disabled\n");
274 #ifdef CONFIG_FSL_CORENET
275 /* On FSL_CORENET devices we can disable individual ports */
277 setbits_be32(devdisr, _DEVDISR_SRIO1);
279 setbits_be32(devdisr, _DEVDISR_SRIO2);
282 /* neither port is used - disable everything */
283 if (!srio1_used && !srio2_used) {
284 setbits_be32(devdisr, _DEVDISR_SRIO1);
285 setbits_be32(devdisr, _DEVDISR_SRIO2);
286 setbits_be32(devdisr, _DEVDISR_RMU);
290 #ifdef CONFIG_SRIO_PCIE_BOOT_MASTER
291 void srio_boot_master(int port)
293 struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
295 /* set port accept-all */
296 out_be32((void *)&srio->impl.port[port - 1].ptaacr,
297 SRIO_PORT_ACCEPT_ALL);
299 debug("SRIOBOOT - MASTER: Master port [ %d ] for srio boot.\n", port);
300 /* configure inbound window for slave's u-boot image */
301 debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
302 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
303 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
304 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1,
305 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
306 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwtar,
307 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
308 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwbar,
309 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS1 >> 12);
310 out_be32((void *)&srio->atmu.port[port - 1].inbw[0].riwar,
312 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
314 /* configure inbound window for slave's u-boot image */
315 debug("SRIOBOOT - MASTER: Inbound window for slave's image; "
316 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
317 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS,
318 (u64)CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2,
319 CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE);
320 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwtar,
321 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_PHYS >> 12);
322 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwbar,
323 CONFIG_SRIO_PCIE_BOOT_IMAGE_MEM_BUS2 >> 12);
324 out_be32((void *)&srio->atmu.port[port - 1].inbw[1].riwar,
326 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_IMAGE_SIZE));
328 /* configure inbound window for slave's ucode and ENV */
329 debug("SRIOBOOT - MASTER: Inbound window for slave's ucode and ENV; "
330 "Local = 0x%llx, Srio = 0x%llx, Size = 0x%x\n",
331 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS,
332 (u64)CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS,
333 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE);
334 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwtar,
335 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_PHYS >> 12);
336 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwbar,
337 CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_MEM_BUS >> 12);
338 out_be32((void *)&srio->atmu.port[port - 1].inbw[2].riwar,
340 | atmu_size_mask(CONFIG_SRIO_PCIE_BOOT_UCODE_ENV_SIZE));
343 void srio_boot_master_release_slave(int port)
345 struct ccsr_rio *srio = (void *)CONFIG_SYS_FSL_SRIO_ADDR;
347 debug("SRIOBOOT - MASTER: "
348 "Check the port status and release slave core ...\n");
350 escsr = in_be32((void *)&srio->lp_serial.port[port - 1].pescsr);
352 if (escsr & 0x10100) {
353 debug("SRIOBOOT - MASTER: Port [ %d ] is error.\n",
356 debug("SRIOBOOT - MASTER: "
357 "Port [ %d ] is ready, now release slave's core ...\n",
360 * configure outbound window
361 * with maintenance attribute to set slave's LCSBA1CSR
363 out_be32((void *)&srio->atmu.port[port - 1]
364 .outbw[1].rowtar, 0);
365 out_be32((void *)&srio->atmu.port[port - 1]
366 .outbw[1].rowtear, 0);
368 out_be32((void *)&srio->atmu.port[port - 1]
370 CONFIG_SYS_SRIO2_MEM_PHYS >> 12);
372 out_be32((void *)&srio->atmu.port[port - 1]
374 CONFIG_SYS_SRIO1_MEM_PHYS >> 12);
375 out_be32((void *)&srio->atmu.port[port - 1]
377 SRIO_OB_ATMU_AR_MAINT
378 | atmu_size_mask(SRIO_MAINT_WIN_SIZE));
381 * configure outbound window
382 * with R/W attribute to set slave's BRR
384 out_be32((void *)&srio->atmu.port[port - 1]
386 SRIO_LCSBA1CSR >> 9);
387 out_be32((void *)&srio->atmu.port[port - 1]
388 .outbw[2].rowtear, 0);
390 out_be32((void *)&srio->atmu.port[port - 1]
392 (CONFIG_SYS_SRIO2_MEM_PHYS
393 + SRIO_MAINT_WIN_SIZE) >> 12);
395 out_be32((void *)&srio->atmu.port[port - 1]
397 (CONFIG_SYS_SRIO1_MEM_PHYS
398 + SRIO_MAINT_WIN_SIZE) >> 12);
399 out_be32((void *)&srio->atmu.port[port - 1]
402 | atmu_size_mask(SRIO_RW_WIN_SIZE));
405 * Set the LCSBA1CSR register in slave
406 * by the maint-outbound window
409 out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
410 + SRIO_LCSBA1CSR_OFFSET,
412 while (in_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
413 + SRIO_LCSBA1CSR_OFFSET)
417 * And then set the BRR register
418 * to release slave core
420 out_be32((void *)CONFIG_SYS_SRIO2_MEM_VIRT
421 + SRIO_MAINT_WIN_SIZE
422 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
423 CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
425 out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
426 + SRIO_LCSBA1CSR_OFFSET,
428 while (in_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
429 + SRIO_LCSBA1CSR_OFFSET)
433 * And then set the BRR register
434 * to release slave core
436 out_be32((void *)CONFIG_SYS_SRIO1_MEM_VIRT
437 + SRIO_MAINT_WIN_SIZE
438 + CONFIG_SRIO_PCIE_BOOT_BRR_OFFSET,
439 CONFIG_SRIO_PCIE_BOOT_RELEASE_MASK);
441 debug("SRIOBOOT - MASTER: "
442 "Release slave successfully! Now the slave should start up!\n");
445 debug("SRIOBOOT - MASTER: Port [ %d ] is not ready.\n", port);