blob: 9ab5ea313d3a98a36c9919abc3e83fc4250d5c6f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dave Liua2c2ceb2007-08-01 15:00:15 +08002/*
York Sune12ce982011-08-26 11:32:44 -07003 * Copyright (C) 2007-2011 Freescale Semiconductor, Inc.
Dave Liua2c2ceb2007-08-01 15:00:15 +08004 *
5 * Dave Liu <daveliu@freescale.com>
6 * based on the contribution of Marian Balakowicz <m8@semihalf.com>
Dave Liua2c2ceb2007-08-01 15:00:15 +08007 */
8
Simon Glass8f3f7612019-11-14 12:57:42 -07009#include <irq_func.h>
Dave Liua2c2ceb2007-08-01 15:00:15 +080010#include <mpc83xx.h>
11#include <command.h>
12
Dave Liua2c2ceb2007-08-01 15:00:15 +080013void ecc_print_status(void)
14{
York Sune12ce982011-08-26 11:32:44 -070015 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Sunf0626592013-09-30 09:22:09 -070016#ifdef CONFIG_SYS_FSL_DDR2
York Suna21803d2013-11-18 10:29:32 -080017 struct ccsr_ddr __iomem *ddr = &immap->ddr;
York Sune12ce982011-08-26 11:32:44 -070018#else
19 ddr83xx_t *ddr = &immap->ddr;
20#endif
Dave Liua2c2ceb2007-08-01 15:00:15 +080021
22 printf("\nECC mode: %s\n\n",
23 (ddr->sdram_cfg & SDRAM_CFG_ECC_EN) ? "ON" : "OFF");
24
25 /* Interrupts */
26 printf("Memory Error Interrupt Enable:\n");
27 printf(" Multiple-Bit Error Interrupt Enable: %d\n",
28 (ddr->err_int_en & ECC_ERR_INT_EN_MBEE) ? 1 : 0);
29 printf(" Single-Bit Error Interrupt Enable: %d\n",
30 (ddr->err_int_en & ECC_ERR_INT_EN_SBEE) ? 1 : 0);
31 printf(" Memory Select Error Interrupt Enable: %d\n\n",
32 (ddr->err_int_en & ECC_ERR_INT_EN_MSEE) ? 1 : 0);
33
34 /* Error disable */
35 printf("Memory Error Disable:\n");
36 printf(" Multiple-Bit Error Disable: %d\n",
37 (ddr->err_disable & ECC_ERROR_DISABLE_MBED) ? 1 : 0);
Robert P. J. Daycbd618f2015-12-16 12:25:42 -050038 printf(" Single-Bit Error Disable: %d\n",
Dave Liua2c2ceb2007-08-01 15:00:15 +080039 (ddr->err_disable & ECC_ERROR_DISABLE_SBED) ? 1 : 0);
40 printf(" Memory Select Error Disable: %d\n\n",
41 (ddr->err_disable & ECC_ERROR_DISABLE_MSED) ? 1 : 0);
42
43 /* Error injection */
Kim Phillipsf91aa8d2008-07-10 14:00:15 -050044 printf("Memory Data Path Error Injection Mask High/Low: %08x %08x\n",
Dave Liua2c2ceb2007-08-01 15:00:15 +080045 ddr->data_err_inject_hi, ddr->data_err_inject_lo);
46
47 printf("Memory Data Path Error Injection Mask ECC:\n");
48 printf(" ECC Mirror Byte: %d\n",
49 (ddr->ecc_err_inject & ECC_ERR_INJECT_EMB) ? 1 : 0);
50 printf(" ECC Injection Enable: %d\n",
51 (ddr->ecc_err_inject & ECC_ERR_INJECT_EIEN) ? 1 : 0);
52 printf(" ECC Error Injection Mask: 0x%02x\n\n",
53 ddr->ecc_err_inject & ECC_ERR_INJECT_EEIM);
54
55 /* SBE counter/threshold */
56 printf("Memory Single-Bit Error Management (0..255):\n");
57 printf(" Single-Bit Error Threshold: %d\n",
58 (ddr->err_sbe & ECC_ERROR_MAN_SBET) >> ECC_ERROR_MAN_SBET_SHIFT);
59 printf(" Single-Bit Error Counter: %d\n\n",
60 (ddr->err_sbe & ECC_ERROR_MAN_SBEC) >> ECC_ERROR_MAN_SBEC_SHIFT);
61
62 /* Error detect */
63 printf("Memory Error Detect:\n");
64 printf(" Multiple Memory Errors: %d\n",
65 (ddr->err_detect & ECC_ERROR_DETECT_MME) ? 1 : 0);
66 printf(" Multiple-Bit Error: %d\n",
67 (ddr->err_detect & ECC_ERROR_DETECT_MBE) ? 1 : 0);
68 printf(" Single-Bit Error: %d\n",
69 (ddr->err_detect & ECC_ERROR_DETECT_SBE) ? 1 : 0);
70 printf(" Memory Select Error: %d\n\n",
71 (ddr->err_detect & ECC_ERROR_DETECT_MSE) ? 1 : 0);
72
73 /* Capture data */
Kim Phillipsf91aa8d2008-07-10 14:00:15 -050074 printf("Memory Error Address Capture: 0x%08x\n", ddr->capture_address);
75 printf("Memory Data Path Read Capture High/Low: %08x %08x\n",
Dave Liua2c2ceb2007-08-01 15:00:15 +080076 ddr->capture_data_hi, ddr->capture_data_lo);
77 printf("Memory Data Path Read Capture ECC: 0x%02x\n\n",
78 ddr->capture_ecc & CAPTURE_ECC_ECE);
79
80 printf("Memory Error Attributes Capture:\n");
81 printf(" Data Beat Number: %d\n",
82 (ddr->capture_attributes & ECC_CAPT_ATTR_BNUM) >>
83 ECC_CAPT_ATTR_BNUM_SHIFT);
84 printf(" Transaction Size: %d\n",
85 (ddr->capture_attributes & ECC_CAPT_ATTR_TSIZ) >>
86 ECC_CAPT_ATTR_TSIZ_SHIFT);
87 printf(" Transaction Source: %d\n",
88 (ddr->capture_attributes & ECC_CAPT_ATTR_TSRC) >>
89 ECC_CAPT_ATTR_TSRC_SHIFT);
90 printf(" Transaction Type: %d\n",
91 (ddr->capture_attributes & ECC_CAPT_ATTR_TTYP) >>
92 ECC_CAPT_ATTR_TTYP_SHIFT);
93 printf(" Error Information Valid: %d\n\n",
94 ddr->capture_attributes & ECC_CAPT_ATTR_VLD);
95}
96
Simon Glassed38aef2020-05-10 11:40:03 -060097int do_ecc(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Dave Liua2c2ceb2007-08-01 15:00:15 +080098{
York Sune12ce982011-08-26 11:32:44 -070099 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
York Sunf0626592013-09-30 09:22:09 -0700100#ifdef CONFIG_SYS_FSL_DDR2
York Suna21803d2013-11-18 10:29:32 -0800101 struct ccsr_ddr __iomem *ddr = &immap->ddr;
York Sune12ce982011-08-26 11:32:44 -0700102#else
103 ddr83xx_t *ddr = &immap->ddr;
104#endif
Dave Liua2c2ceb2007-08-01 15:00:15 +0800105 volatile u32 val;
106 u64 *addr;
107 u32 count;
108 register u64 *i;
109 u32 ret[2];
110 u32 pattern[2];
111 u32 writeback[2];
112
113 /* The pattern is written into memory to generate error */
114 pattern[0] = 0xfedcba98UL;
115 pattern[1] = 0x76543210UL;
116
117 /* After injecting error, re-initialize the memory with the value */
118 writeback[0] = 0x01234567UL;
119 writeback[1] = 0x89abcdefUL;
120
Wolfgang Denk3b683112010-07-17 01:06:04 +0200121 if (argc > 4)
122 return cmd_usage(cmdtp);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800123
124 if (argc == 2) {
125 if (strcmp(argv[1], "status") == 0) {
126 ecc_print_status();
127 return 0;
128 } else if (strcmp(argv[1], "captureclear") == 0) {
129 ddr->capture_address = 0;
130 ddr->capture_data_hi = 0;
131 ddr->capture_data_lo = 0;
132 ddr->capture_ecc = 0;
133 ddr->capture_attributes = 0;
134 return 0;
135 }
136 }
137 if (argc == 3) {
138 if (strcmp(argv[1], "sbecnt") == 0) {
Simon Glassff9b9032021-07-24 09:03:30 -0600139 val = dectoul(argv[2], NULL);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800140 if (val > 255) {
141 printf("Incorrect Counter value, "
142 "should be 0..255\n");
143 return 1;
144 }
145
146 val = (val << ECC_ERROR_MAN_SBEC_SHIFT);
147 val |= (ddr->err_sbe & ECC_ERROR_MAN_SBET);
148
149 ddr->err_sbe = val;
150 return 0;
151 } else if (strcmp(argv[1], "sbethr") == 0) {
Simon Glassff9b9032021-07-24 09:03:30 -0600152 val = dectoul(argv[2], NULL);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800153 if (val > 255) {
154 printf("Incorrect Counter value, "
155 "should be 0..255\n");
156 return 1;
157 }
158
159 val = (val << ECC_ERROR_MAN_SBET_SHIFT);
160 val |= (ddr->err_sbe & ECC_ERROR_MAN_SBEC);
161
162 ddr->err_sbe = val;
163 return 0;
164 } else if (strcmp(argv[1], "errdisable") == 0) {
165 val = ddr->err_disable;
166
167 if (strcmp(argv[2], "+sbe") == 0) {
168 val |= ECC_ERROR_DISABLE_SBED;
169 } else if (strcmp(argv[2], "+mbe") == 0) {
170 val |= ECC_ERROR_DISABLE_MBED;
171 } else if (strcmp(argv[2], "+mse") == 0) {
172 val |= ECC_ERROR_DISABLE_MSED;
173 } else if (strcmp(argv[2], "+all") == 0) {
174 val |= (ECC_ERROR_DISABLE_SBED |
175 ECC_ERROR_DISABLE_MBED |
176 ECC_ERROR_DISABLE_MSED);
177 } else if (strcmp(argv[2], "-sbe") == 0) {
178 val &= ~ECC_ERROR_DISABLE_SBED;
179 } else if (strcmp(argv[2], "-mbe") == 0) {
180 val &= ~ECC_ERROR_DISABLE_MBED;
181 } else if (strcmp(argv[2], "-mse") == 0) {
182 val &= ~ECC_ERROR_DISABLE_MSED;
183 } else if (strcmp(argv[2], "-all") == 0) {
184 val &= ~(ECC_ERROR_DISABLE_SBED |
185 ECC_ERROR_DISABLE_MBED |
186 ECC_ERROR_DISABLE_MSED);
187 } else {
188 printf("Incorrect err_disable field\n");
189 return 1;
190 }
191
192 ddr->err_disable = val;
Mario Sixc463b6d2019-01-21 09:18:21 +0100193 sync();
194 isync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800195 return 0;
196 } else if (strcmp(argv[1], "errdetectclr") == 0) {
197 val = ddr->err_detect;
198
199 if (strcmp(argv[2], "mme") == 0) {
200 val |= ECC_ERROR_DETECT_MME;
201 } else if (strcmp(argv[2], "sbe") == 0) {
202 val |= ECC_ERROR_DETECT_SBE;
203 } else if (strcmp(argv[2], "mbe") == 0) {
204 val |= ECC_ERROR_DETECT_MBE;
205 } else if (strcmp(argv[2], "mse") == 0) {
206 val |= ECC_ERROR_DETECT_MSE;
207 } else if (strcmp(argv[2], "all") == 0) {
208 val |= (ECC_ERROR_DETECT_MME |
209 ECC_ERROR_DETECT_MBE |
210 ECC_ERROR_DETECT_SBE |
211 ECC_ERROR_DETECT_MSE);
212 } else {
213 printf("Incorrect err_detect field\n");
214 return 1;
215 }
216
217 ddr->err_detect = val;
218 return 0;
219 } else if (strcmp(argv[1], "injectdatahi") == 0) {
Simon Glass3ff49ec2021-07-24 09:03:29 -0600220 val = hextoul(argv[2], NULL);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800221
222 ddr->data_err_inject_hi = val;
223 return 0;
224 } else if (strcmp(argv[1], "injectdatalo") == 0) {
Simon Glass3ff49ec2021-07-24 09:03:29 -0600225 val = hextoul(argv[2], NULL);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800226
227 ddr->data_err_inject_lo = val;
228 return 0;
229 } else if (strcmp(argv[1], "injectecc") == 0) {
Simon Glass3ff49ec2021-07-24 09:03:29 -0600230 val = hextoul(argv[2], NULL);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800231 if (val > 0xff) {
232 printf("Incorrect ECC inject mask, "
233 "should be 0x00..0xff\n");
234 return 1;
235 }
236 val |= (ddr->ecc_err_inject & ~ECC_ERR_INJECT_EEIM);
237
238 ddr->ecc_err_inject = val;
239 return 0;
240 } else if (strcmp(argv[1], "inject") == 0) {
241 val = ddr->ecc_err_inject;
242
243 if (strcmp(argv[2], "en") == 0)
244 val |= ECC_ERR_INJECT_EIEN;
245 else if (strcmp(argv[2], "dis") == 0)
246 val &= ~ECC_ERR_INJECT_EIEN;
247 else
248 printf("Incorrect command\n");
249
250 ddr->ecc_err_inject = val;
Mario Sixc463b6d2019-01-21 09:18:21 +0100251 sync();
252 isync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800253 return 0;
254 } else if (strcmp(argv[1], "mirror") == 0) {
255 val = ddr->ecc_err_inject;
256
257 if (strcmp(argv[2], "en") == 0)
258 val |= ECC_ERR_INJECT_EMB;
259 else if (strcmp(argv[2], "dis") == 0)
260 val &= ~ECC_ERR_INJECT_EMB;
261 else
262 printf("Incorrect command\n");
263
264 ddr->ecc_err_inject = val;
265 return 0;
266 }
267 }
268 if (argc == 4) {
269 if (strcmp(argv[1], "testdw") == 0) {
Simon Glass3ff49ec2021-07-24 09:03:29 -0600270 addr = (u64 *)hextoul(argv[2], NULL);
271 count = hextoul(argv[3], NULL);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800272
273 if ((u32) addr % 8) {
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500274 printf("Address not aligned on "
Dave Liua2c2ceb2007-08-01 15:00:15 +0800275 "double word boundary\n");
276 return 1;
277 }
278 disable_interrupts();
279
280 for (i = addr; i < addr + count; i++) {
281
282 /* enable injects */
283 ddr->ecc_err_inject |= ECC_ERR_INJECT_EIEN;
Mario Sixc463b6d2019-01-21 09:18:21 +0100284 sync();
285 isync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800286
287 /* write memory location injecting errors */
288 ppcDWstore((u32 *) i, pattern);
Mario Sixc463b6d2019-01-21 09:18:21 +0100289 sync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800290
291 /* disable injects */
292 ddr->ecc_err_inject &= ~ECC_ERR_INJECT_EIEN;
Mario Sixc463b6d2019-01-21 09:18:21 +0100293 sync();
294 isync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800295
296 /* read data, this generates ECC error */
297 ppcDWload((u32 *) i, ret);
Mario Sixc463b6d2019-01-21 09:18:21 +0100298 sync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800299
300 /* re-initialize memory, double word write the location again,
301 * generates new ECC code this time */
302 ppcDWstore((u32 *) i, writeback);
Mario Sixc463b6d2019-01-21 09:18:21 +0100303 sync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800304 }
305 enable_interrupts();
306 return 0;
307 }
308 if (strcmp(argv[1], "testword") == 0) {
Simon Glass3ff49ec2021-07-24 09:03:29 -0600309 addr = (u64 *)hextoul(argv[2], NULL);
310 count = hextoul(argv[3], NULL);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800311
312 if ((u32) addr % 8) {
Robert P. J. Daycbd618f2015-12-16 12:25:42 -0500313 printf("Address not aligned on "
Dave Liua2c2ceb2007-08-01 15:00:15 +0800314 "double word boundary\n");
315 return 1;
316 }
317 disable_interrupts();
318
319 for (i = addr; i < addr + count; i++) {
320
321 /* enable injects */
322 ddr->ecc_err_inject |= ECC_ERR_INJECT_EIEN;
Mario Sixc463b6d2019-01-21 09:18:21 +0100323 sync();
324 isync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800325
326 /* write memory location injecting errors */
327 *(u32 *) i = 0xfedcba98UL;
Mario Sixc463b6d2019-01-21 09:18:21 +0100328 sync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800329
330 /* sub double word write,
331 * bus will read-modify-write,
332 * generates ECC error */
333 *((u32 *) i + 1) = 0x76543210UL;
Mario Sixc463b6d2019-01-21 09:18:21 +0100334 sync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800335
336 /* disable injects */
337 ddr->ecc_err_inject &= ~ECC_ERR_INJECT_EIEN;
Mario Sixc463b6d2019-01-21 09:18:21 +0100338 sync();
339 isync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800340
341 /* re-initialize memory,
342 * double word write the location again,
343 * generates new ECC code this time */
344 ppcDWstore((u32 *) i, writeback);
Mario Sixc463b6d2019-01-21 09:18:21 +0100345 sync();
Dave Liua2c2ceb2007-08-01 15:00:15 +0800346 }
347 enable_interrupts();
348 return 0;
349 }
350 }
Wolfgang Denk3b683112010-07-17 01:06:04 +0200351 return cmd_usage(cmdtp);
Dave Liua2c2ceb2007-08-01 15:00:15 +0800352}
353
354U_BOOT_CMD(ecc, 4, 0, do_ecc,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600355 "support for DDR ECC features",
Dave Liua2c2ceb2007-08-01 15:00:15 +0800356 "status - print out status info\n"
357 "ecc captureclear - clear capture regs data\n"
358 "ecc sbecnt <val> - set Single-Bit Error counter\n"
359 "ecc sbethr <val> - set Single-Bit Threshold\n"
360 "ecc errdisable <flag> - clear/set disable Memory Error Disable, flag:\n"
361 " [-|+]sbe - Single-Bit Error\n"
362 " [-|+]mbe - Multiple-Bit Error\n"
363 " [-|+]mse - Memory Select Error\n"
364 " [-|+]all - all errors\n"
365 "ecc errdetectclr <flag> - clear Memory Error Detect, flag:\n"
366 " mme - Multiple Memory Errors\n"
367 " sbe - Single-Bit Error\n"
368 " mbe - Multiple-Bit Error\n"
369 " mse - Memory Select Error\n"
370 " all - all errors\n"
371 "ecc injectdatahi <hi> - set Memory Data Path Error Injection Mask High\n"
372 "ecc injectdatalo <lo> - set Memory Data Path Error Injection Mask Low\n"
373 "ecc injectecc <ecc> - set ECC Error Injection Mask\n"
374 "ecc inject <en|dis> - enable/disable error injection\n"
375 "ecc mirror <en|dis> - enable/disable mirror byte\n"
376 "ecc testdw <addr> <cnt> - test mem region with double word access:\n"
377 " - enables injects\n"
378 " - writes pattern injecting errors with double word access\n"
379 " - disables injects\n"
380 " - reads pattern back with double word access, generates error\n"
381 " - re-inits memory\n"
382 "ecc testword <addr> <cnt> - test mem region with word access:\n"
383 " - enables injects\n"
384 " - writes pattern injecting errors with word access\n"
385 " - writes pattern with word access, generates error\n"
386 " - disables injects\n" " - re-inits memory");