ecc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. * Copyright (C) 2007-2011 Freescale Semiconductor, Inc.
  3. *
  4. * Dave Liu <daveliu@freescale.com>
  5. * based on the contribution of Marian Balakowicz <m8@semihalf.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. */
  15. #include <common.h>
  16. #include <mpc83xx.h>
  17. #include <command.h>
  18. #if defined(CONFIG_DDR_ECC) && defined(CONFIG_DDR_ECC_CMD)
  19. void ecc_print_status(void)
  20. {
  21. immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  22. #ifdef CONFIG_FSL_DDR2
  23. ccsr_ddr_t *ddr = &immap->ddr;
  24. #else
  25. ddr83xx_t *ddr = &immap->ddr;
  26. #endif
  27. printf("\nECC mode: %s\n\n",
  28. (ddr->sdram_cfg & SDRAM_CFG_ECC_EN) ? "ON" : "OFF");
  29. /* Interrupts */
  30. printf("Memory Error Interrupt Enable:\n");
  31. printf(" Multiple-Bit Error Interrupt Enable: %d\n",
  32. (ddr->err_int_en & ECC_ERR_INT_EN_MBEE) ? 1 : 0);
  33. printf(" Single-Bit Error Interrupt Enable: %d\n",
  34. (ddr->err_int_en & ECC_ERR_INT_EN_SBEE) ? 1 : 0);
  35. printf(" Memory Select Error Interrupt Enable: %d\n\n",
  36. (ddr->err_int_en & ECC_ERR_INT_EN_MSEE) ? 1 : 0);
  37. /* Error disable */
  38. printf("Memory Error Disable:\n");
  39. printf(" Multiple-Bit Error Disable: %d\n",
  40. (ddr->err_disable & ECC_ERROR_DISABLE_MBED) ? 1 : 0);
  41. printf(" Sinle-Bit Error Disable: %d\n",
  42. (ddr->err_disable & ECC_ERROR_DISABLE_SBED) ? 1 : 0);
  43. printf(" Memory Select Error Disable: %d\n\n",
  44. (ddr->err_disable & ECC_ERROR_DISABLE_MSED) ? 1 : 0);
  45. /* Error injection */
  46. printf("Memory Data Path Error Injection Mask High/Low: %08x %08x\n",
  47. ddr->data_err_inject_hi, ddr->data_err_inject_lo);
  48. printf("Memory Data Path Error Injection Mask ECC:\n");
  49. printf(" ECC Mirror Byte: %d\n",
  50. (ddr->ecc_err_inject & ECC_ERR_INJECT_EMB) ? 1 : 0);
  51. printf(" ECC Injection Enable: %d\n",
  52. (ddr->ecc_err_inject & ECC_ERR_INJECT_EIEN) ? 1 : 0);
  53. printf(" ECC Error Injection Mask: 0x%02x\n\n",
  54. ddr->ecc_err_inject & ECC_ERR_INJECT_EEIM);
  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. /* Error detect */
  62. printf("Memory Error Detect:\n");
  63. printf(" Multiple Memory Errors: %d\n",
  64. (ddr->err_detect & ECC_ERROR_DETECT_MME) ? 1 : 0);
  65. printf(" Multiple-Bit Error: %d\n",
  66. (ddr->err_detect & ECC_ERROR_DETECT_MBE) ? 1 : 0);
  67. printf(" Single-Bit Error: %d\n",
  68. (ddr->err_detect & ECC_ERROR_DETECT_SBE) ? 1 : 0);
  69. printf(" Memory Select Error: %d\n\n",
  70. (ddr->err_detect & ECC_ERROR_DETECT_MSE) ? 1 : 0);
  71. /* Capture data */
  72. printf("Memory Error Address Capture: 0x%08x\n", ddr->capture_address);
  73. printf("Memory Data Path Read Capture High/Low: %08x %08x\n",
  74. ddr->capture_data_hi, ddr->capture_data_lo);
  75. printf("Memory Data Path Read Capture ECC: 0x%02x\n\n",
  76. ddr->capture_ecc & CAPTURE_ECC_ECE);
  77. printf("Memory Error Attributes Capture:\n");
  78. printf(" Data Beat Number: %d\n",
  79. (ddr->capture_attributes & ECC_CAPT_ATTR_BNUM) >>
  80. ECC_CAPT_ATTR_BNUM_SHIFT);
  81. printf(" Transaction Size: %d\n",
  82. (ddr->capture_attributes & ECC_CAPT_ATTR_TSIZ) >>
  83. ECC_CAPT_ATTR_TSIZ_SHIFT);
  84. printf(" Transaction Source: %d\n",
  85. (ddr->capture_attributes & ECC_CAPT_ATTR_TSRC) >>
  86. ECC_CAPT_ATTR_TSRC_SHIFT);
  87. printf(" Transaction Type: %d\n",
  88. (ddr->capture_attributes & ECC_CAPT_ATTR_TTYP) >>
  89. ECC_CAPT_ATTR_TTYP_SHIFT);
  90. printf(" Error Information Valid: %d\n\n",
  91. ddr->capture_attributes & ECC_CAPT_ATTR_VLD);
  92. }
  93. int do_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  94. {
  95. immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  96. #ifdef CONFIG_FSL_DDR2
  97. ccsr_ddr_t *ddr = &immap->ddr;
  98. #else
  99. ddr83xx_t *ddr = &immap->ddr;
  100. #endif
  101. volatile u32 val;
  102. u64 *addr;
  103. u32 count;
  104. register u64 *i;
  105. u32 ret[2];
  106. u32 pattern[2];
  107. u32 writeback[2];
  108. /* The pattern is written into memory to generate error */
  109. pattern[0] = 0xfedcba98UL;
  110. pattern[1] = 0x76543210UL;
  111. /* After injecting error, re-initialize the memory with the value */
  112. writeback[0] = 0x01234567UL;
  113. writeback[1] = 0x89abcdefUL;
  114. if (argc > 4)
  115. return cmd_usage(cmdtp);
  116. if (argc == 2) {
  117. if (strcmp(argv[1], "status") == 0) {
  118. ecc_print_status();
  119. return 0;
  120. } else if (strcmp(argv[1], "captureclear") == 0) {
  121. ddr->capture_address = 0;
  122. ddr->capture_data_hi = 0;
  123. ddr->capture_data_lo = 0;
  124. ddr->capture_ecc = 0;
  125. ddr->capture_attributes = 0;
  126. return 0;
  127. }
  128. }
  129. if (argc == 3) {
  130. if (strcmp(argv[1], "sbecnt") == 0) {
  131. val = simple_strtoul(argv[2], NULL, 10);
  132. if (val > 255) {
  133. printf("Incorrect Counter value, "
  134. "should be 0..255\n");
  135. return 1;
  136. }
  137. val = (val << ECC_ERROR_MAN_SBEC_SHIFT);
  138. val |= (ddr->err_sbe & ECC_ERROR_MAN_SBET);
  139. ddr->err_sbe = val;
  140. return 0;
  141. } else if (strcmp(argv[1], "sbethr") == 0) {
  142. val = simple_strtoul(argv[2], NULL, 10);
  143. if (val > 255) {
  144. printf("Incorrect Counter value, "
  145. "should be 0..255\n");
  146. return 1;
  147. }
  148. val = (val << ECC_ERROR_MAN_SBET_SHIFT);
  149. val |= (ddr->err_sbe & ECC_ERROR_MAN_SBEC);
  150. ddr->err_sbe = val;
  151. return 0;
  152. } else if (strcmp(argv[1], "errdisable") == 0) {
  153. val = ddr->err_disable;
  154. if (strcmp(argv[2], "+sbe") == 0) {
  155. val |= ECC_ERROR_DISABLE_SBED;
  156. } else if (strcmp(argv[2], "+mbe") == 0) {
  157. val |= ECC_ERROR_DISABLE_MBED;
  158. } else if (strcmp(argv[2], "+mse") == 0) {
  159. val |= ECC_ERROR_DISABLE_MSED;
  160. } else if (strcmp(argv[2], "+all") == 0) {
  161. val |= (ECC_ERROR_DISABLE_SBED |
  162. ECC_ERROR_DISABLE_MBED |
  163. ECC_ERROR_DISABLE_MSED);
  164. } else if (strcmp(argv[2], "-sbe") == 0) {
  165. val &= ~ECC_ERROR_DISABLE_SBED;
  166. } else if (strcmp(argv[2], "-mbe") == 0) {
  167. val &= ~ECC_ERROR_DISABLE_MBED;
  168. } else if (strcmp(argv[2], "-mse") == 0) {
  169. val &= ~ECC_ERROR_DISABLE_MSED;
  170. } else if (strcmp(argv[2], "-all") == 0) {
  171. val &= ~(ECC_ERROR_DISABLE_SBED |
  172. ECC_ERROR_DISABLE_MBED |
  173. ECC_ERROR_DISABLE_MSED);
  174. } else {
  175. printf("Incorrect err_disable field\n");
  176. return 1;
  177. }
  178. ddr->err_disable = val;
  179. __asm__ __volatile__("sync");
  180. __asm__ __volatile__("isync");
  181. return 0;
  182. } else if (strcmp(argv[1], "errdetectclr") == 0) {
  183. val = ddr->err_detect;
  184. if (strcmp(argv[2], "mme") == 0) {
  185. val |= ECC_ERROR_DETECT_MME;
  186. } else if (strcmp(argv[2], "sbe") == 0) {
  187. val |= ECC_ERROR_DETECT_SBE;
  188. } else if (strcmp(argv[2], "mbe") == 0) {
  189. val |= ECC_ERROR_DETECT_MBE;
  190. } else if (strcmp(argv[2], "mse") == 0) {
  191. val |= ECC_ERROR_DETECT_MSE;
  192. } else if (strcmp(argv[2], "all") == 0) {
  193. val |= (ECC_ERROR_DETECT_MME |
  194. ECC_ERROR_DETECT_MBE |
  195. ECC_ERROR_DETECT_SBE |
  196. ECC_ERROR_DETECT_MSE);
  197. } else {
  198. printf("Incorrect err_detect field\n");
  199. return 1;
  200. }
  201. ddr->err_detect = val;
  202. return 0;
  203. } else if (strcmp(argv[1], "injectdatahi") == 0) {
  204. val = simple_strtoul(argv[2], NULL, 16);
  205. ddr->data_err_inject_hi = val;
  206. return 0;
  207. } else if (strcmp(argv[1], "injectdatalo") == 0) {
  208. val = simple_strtoul(argv[2], NULL, 16);
  209. ddr->data_err_inject_lo = val;
  210. return 0;
  211. } else if (strcmp(argv[1], "injectecc") == 0) {
  212. val = simple_strtoul(argv[2], NULL, 16);
  213. if (val > 0xff) {
  214. printf("Incorrect ECC inject mask, "
  215. "should be 0x00..0xff\n");
  216. return 1;
  217. }
  218. val |= (ddr->ecc_err_inject & ~ECC_ERR_INJECT_EEIM);
  219. ddr->ecc_err_inject = val;
  220. return 0;
  221. } else if (strcmp(argv[1], "inject") == 0) {
  222. val = ddr->ecc_err_inject;
  223. if (strcmp(argv[2], "en") == 0)
  224. val |= ECC_ERR_INJECT_EIEN;
  225. else if (strcmp(argv[2], "dis") == 0)
  226. val &= ~ECC_ERR_INJECT_EIEN;
  227. else
  228. printf("Incorrect command\n");
  229. ddr->ecc_err_inject = val;
  230. __asm__ __volatile__("sync");
  231. __asm__ __volatile__("isync");
  232. return 0;
  233. } else if (strcmp(argv[1], "mirror") == 0) {
  234. val = ddr->ecc_err_inject;
  235. if (strcmp(argv[2], "en") == 0)
  236. val |= ECC_ERR_INJECT_EMB;
  237. else if (strcmp(argv[2], "dis") == 0)
  238. val &= ~ECC_ERR_INJECT_EMB;
  239. else
  240. printf("Incorrect command\n");
  241. ddr->ecc_err_inject = val;
  242. return 0;
  243. }
  244. }
  245. if (argc == 4) {
  246. if (strcmp(argv[1], "testdw") == 0) {
  247. addr = (u64 *) simple_strtoul(argv[2], NULL, 16);
  248. count = simple_strtoul(argv[3], NULL, 16);
  249. if ((u32) addr % 8) {
  250. printf("Address not alligned on "
  251. "double word boundary\n");
  252. return 1;
  253. }
  254. disable_interrupts();
  255. for (i = addr; i < addr + count; i++) {
  256. /* enable injects */
  257. ddr->ecc_err_inject |= ECC_ERR_INJECT_EIEN;
  258. __asm__ __volatile__("sync");
  259. __asm__ __volatile__("isync");
  260. /* write memory location injecting errors */
  261. ppcDWstore((u32 *) i, pattern);
  262. __asm__ __volatile__("sync");
  263. /* disable injects */
  264. ddr->ecc_err_inject &= ~ECC_ERR_INJECT_EIEN;
  265. __asm__ __volatile__("sync");
  266. __asm__ __volatile__("isync");
  267. /* read data, this generates ECC error */
  268. ppcDWload((u32 *) i, ret);
  269. __asm__ __volatile__("sync");
  270. /* re-initialize memory, double word write the location again,
  271. * generates new ECC code this time */
  272. ppcDWstore((u32 *) i, writeback);
  273. __asm__ __volatile__("sync");
  274. }
  275. enable_interrupts();
  276. return 0;
  277. }
  278. if (strcmp(argv[1], "testword") == 0) {
  279. addr = (u64 *) simple_strtoul(argv[2], NULL, 16);
  280. count = simple_strtoul(argv[3], NULL, 16);
  281. if ((u32) addr % 8) {
  282. printf("Address not alligned on "
  283. "double word boundary\n");
  284. return 1;
  285. }
  286. disable_interrupts();
  287. for (i = addr; i < addr + count; i++) {
  288. /* enable injects */
  289. ddr->ecc_err_inject |= ECC_ERR_INJECT_EIEN;
  290. __asm__ __volatile__("sync");
  291. __asm__ __volatile__("isync");
  292. /* write memory location injecting errors */
  293. *(u32 *) i = 0xfedcba98UL;
  294. __asm__ __volatile__("sync");
  295. /* sub double word write,
  296. * bus will read-modify-write,
  297. * generates ECC error */
  298. *((u32 *) i + 1) = 0x76543210UL;
  299. __asm__ __volatile__("sync");
  300. /* disable injects */
  301. ddr->ecc_err_inject &= ~ECC_ERR_INJECT_EIEN;
  302. __asm__ __volatile__("sync");
  303. __asm__ __volatile__("isync");
  304. /* re-initialize memory,
  305. * double word write the location again,
  306. * generates new ECC code this time */
  307. ppcDWstore((u32 *) i, writeback);
  308. __asm__ __volatile__("sync");
  309. }
  310. enable_interrupts();
  311. return 0;
  312. }
  313. }
  314. return cmd_usage(cmdtp);
  315. }
  316. U_BOOT_CMD(ecc, 4, 0, do_ecc,
  317. "support for DDR ECC features",
  318. "status - print out status info\n"
  319. "ecc captureclear - clear capture regs data\n"
  320. "ecc sbecnt <val> - set Single-Bit Error counter\n"
  321. "ecc sbethr <val> - set Single-Bit Threshold\n"
  322. "ecc errdisable <flag> - clear/set disable Memory Error Disable, flag:\n"
  323. " [-|+]sbe - Single-Bit Error\n"
  324. " [-|+]mbe - Multiple-Bit Error\n"
  325. " [-|+]mse - Memory Select Error\n"
  326. " [-|+]all - all errors\n"
  327. "ecc errdetectclr <flag> - clear Memory Error Detect, flag:\n"
  328. " mme - Multiple Memory Errors\n"
  329. " sbe - Single-Bit Error\n"
  330. " mbe - Multiple-Bit Error\n"
  331. " mse - Memory Select Error\n"
  332. " all - all errors\n"
  333. "ecc injectdatahi <hi> - set Memory Data Path Error Injection Mask High\n"
  334. "ecc injectdatalo <lo> - set Memory Data Path Error Injection Mask Low\n"
  335. "ecc injectecc <ecc> - set ECC Error Injection Mask\n"
  336. "ecc inject <en|dis> - enable/disable error injection\n"
  337. "ecc mirror <en|dis> - enable/disable mirror byte\n"
  338. "ecc testdw <addr> <cnt> - test mem region with double word access:\n"
  339. " - enables injects\n"
  340. " - writes pattern injecting errors with double word access\n"
  341. " - disables injects\n"
  342. " - reads pattern back with double word access, generates error\n"
  343. " - re-inits memory\n"
  344. "ecc testword <addr> <cnt> - test mem region with word access:\n"
  345. " - enables injects\n"
  346. " - writes pattern injecting errors with word access\n"
  347. " - writes pattern with word access, generates error\n"
  348. " - disables injects\n" " - re-inits memory");
  349. #endif