ecc-berr.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*
  2. * Bus error event handling code for systems equipped with ECC
  3. * handling logic, i.e. DECstation/DECsystem 5000/200 (KN02),
  4. * 5000/240 (KN03), 5000/260 (KN05) and DECsystem 5900 (KN03),
  5. * 5900/260 (KN05) systems.
  6. *
  7. * Copyright (c) 2003, 2005 Maciej W. Rozycki
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/types.h>
  19. #include <asm/addrspace.h>
  20. #include <asm/bootinfo.h>
  21. #include <asm/cpu.h>
  22. #include <asm/cpu-type.h>
  23. #include <asm/irq_regs.h>
  24. #include <asm/processor.h>
  25. #include <asm/ptrace.h>
  26. #include <asm/traps.h>
  27. #include <asm/dec/ecc.h>
  28. #include <asm/dec/kn02.h>
  29. #include <asm/dec/kn03.h>
  30. #include <asm/dec/kn05.h>
  31. static volatile u32 *kn0x_erraddr;
  32. static volatile u32 *kn0x_chksyn;
  33. static inline void dec_ecc_be_ack(void)
  34. {
  35. *kn0x_erraddr = 0; /* any write clears the IRQ */
  36. iob();
  37. }
  38. static int dec_ecc_be_backend(struct pt_regs *regs, int is_fixup, int invoker)
  39. {
  40. static const char excstr[] = "exception";
  41. static const char intstr[] = "interrupt";
  42. static const char cpustr[] = "CPU";
  43. static const char dmastr[] = "DMA";
  44. static const char readstr[] = "read";
  45. static const char mreadstr[] = "memory read";
  46. static const char writestr[] = "write";
  47. static const char mwritstr[] = "partial memory write";
  48. static const char timestr[] = "timeout";
  49. static const char overstr[] = "overrun";
  50. static const char eccstr[] = "ECC error";
  51. const char *kind, *agent, *cycle, *event;
  52. const char *status = "", *xbit = "", *fmt = "";
  53. unsigned long address;
  54. u16 syn = 0, sngl;
  55. int i = 0;
  56. u32 erraddr = *kn0x_erraddr;
  57. u32 chksyn = *kn0x_chksyn;
  58. int action = MIPS_BE_FATAL;
  59. /* For non-ECC ack ASAP, so that any subsequent errors get caught. */
  60. if ((erraddr & (KN0X_EAR_VALID | KN0X_EAR_ECCERR)) == KN0X_EAR_VALID)
  61. dec_ecc_be_ack();
  62. kind = invoker ? intstr : excstr;
  63. if (!(erraddr & KN0X_EAR_VALID)) {
  64. /* No idea what happened. */
  65. printk(KERN_ALERT "Unidentified bus error %s\n", kind);
  66. return action;
  67. }
  68. agent = (erraddr & KN0X_EAR_CPU) ? cpustr : dmastr;
  69. if (erraddr & KN0X_EAR_ECCERR) {
  70. /* An ECC error on a CPU or DMA transaction. */
  71. cycle = (erraddr & KN0X_EAR_WRITE) ? mwritstr : mreadstr;
  72. event = eccstr;
  73. } else {
  74. /* A CPU timeout or a DMA overrun. */
  75. cycle = (erraddr & KN0X_EAR_WRITE) ? writestr : readstr;
  76. event = (erraddr & KN0X_EAR_CPU) ? timestr : overstr;
  77. }
  78. address = erraddr & KN0X_EAR_ADDRESS;
  79. /* For ECC errors on reads adjust for MT pipelining. */
  80. if ((erraddr & (KN0X_EAR_WRITE | KN0X_EAR_ECCERR)) == KN0X_EAR_ECCERR)
  81. address = (address & ~0xfffLL) | ((address - 5) & 0xfffLL);
  82. address <<= 2;
  83. /* Only CPU errors are fixable. */
  84. if (erraddr & KN0X_EAR_CPU && is_fixup)
  85. action = MIPS_BE_FIXUP;
  86. if (erraddr & KN0X_EAR_ECCERR) {
  87. static const u8 data_sbit[32] = {
  88. 0x4f, 0x4a, 0x52, 0x54, 0x57, 0x58, 0x5b, 0x5d,
  89. 0x23, 0x25, 0x26, 0x29, 0x2a, 0x2c, 0x31, 0x34,
  90. 0x0e, 0x0b, 0x13, 0x15, 0x16, 0x19, 0x1a, 0x1c,
  91. 0x62, 0x64, 0x67, 0x68, 0x6b, 0x6d, 0x70, 0x75,
  92. };
  93. static const u8 data_mbit[25] = {
  94. 0x07, 0x0d, 0x1f,
  95. 0x2f, 0x32, 0x37, 0x38, 0x3b, 0x3d, 0x3e,
  96. 0x43, 0x45, 0x46, 0x49, 0x4c, 0x51, 0x5e,
  97. 0x61, 0x6e, 0x73, 0x76, 0x79, 0x7a, 0x7c, 0x7f,
  98. };
  99. static const char sbestr[] = "corrected single";
  100. static const char dbestr[] = "uncorrectable double";
  101. static const char mbestr[] = "uncorrectable multiple";
  102. if (!(address & 0x4))
  103. syn = chksyn; /* Low bank. */
  104. else
  105. syn = chksyn >> 16; /* High bank. */
  106. if (!(syn & KN0X_ESR_VLDLO)) {
  107. /* Ack now, no rewrite will happen. */
  108. dec_ecc_be_ack();
  109. fmt = KERN_ALERT "%s" "invalid\n";
  110. } else {
  111. sngl = syn & KN0X_ESR_SNGLO;
  112. syn &= KN0X_ESR_SYNLO;
  113. /*
  114. * Multibit errors may be tagged incorrectly;
  115. * check the syndrome explicitly.
  116. */
  117. for (i = 0; i < 25; i++)
  118. if (syn == data_mbit[i])
  119. break;
  120. if (i < 25) {
  121. status = mbestr;
  122. } else if (!sngl) {
  123. status = dbestr;
  124. } else {
  125. volatile u32 *ptr =
  126. (void *)CKSEG1ADDR(address);
  127. *ptr = *ptr; /* Rewrite. */
  128. iob();
  129. status = sbestr;
  130. action = MIPS_BE_DISCARD;
  131. }
  132. /* Ack now, now we've rewritten (or not). */
  133. dec_ecc_be_ack();
  134. if (syn && syn == (syn & -syn)) {
  135. if (syn == 0x01) {
  136. fmt = KERN_ALERT "%s"
  137. "%#04x -- %s bit error "
  138. "at check bit C%s\n";
  139. xbit = "X";
  140. } else {
  141. fmt = KERN_ALERT "%s"
  142. "%#04x -- %s bit error "
  143. "at check bit C%s%u\n";
  144. }
  145. i = syn >> 2;
  146. } else {
  147. for (i = 0; i < 32; i++)
  148. if (syn == data_sbit[i])
  149. break;
  150. if (i < 32)
  151. fmt = KERN_ALERT "%s"
  152. "%#04x -- %s bit error "
  153. "at data bit D%s%u\n";
  154. else
  155. fmt = KERN_ALERT "%s"
  156. "%#04x -- %s bit error\n";
  157. }
  158. }
  159. }
  160. if (action != MIPS_BE_FIXUP)
  161. printk(KERN_ALERT "Bus error %s: %s %s %s at %#010lx\n",
  162. kind, agent, cycle, event, address);
  163. if (action != MIPS_BE_FIXUP && erraddr & KN0X_EAR_ECCERR)
  164. printk(fmt, " ECC syndrome ", syn, status, xbit, i);
  165. return action;
  166. }
  167. int dec_ecc_be_handler(struct pt_regs *regs, int is_fixup)
  168. {
  169. return dec_ecc_be_backend(regs, is_fixup, 0);
  170. }
  171. irqreturn_t dec_ecc_be_interrupt(int irq, void *dev_id)
  172. {
  173. struct pt_regs *regs = get_irq_regs();
  174. int action = dec_ecc_be_backend(regs, 0, 1);
  175. if (action == MIPS_BE_DISCARD)
  176. return IRQ_HANDLED;
  177. /*
  178. * FIXME: Find the affected processes and kill them, otherwise
  179. * we must die.
  180. *
  181. * The interrupt is asynchronously delivered thus EPC and RA
  182. * may be irrelevant, but are printed for a reference.
  183. */
  184. printk(KERN_ALERT "Fatal bus interrupt, epc == %08lx, ra == %08lx\n",
  185. regs->cp0_epc, regs->regs[31]);
  186. die("Unrecoverable bus error", regs);
  187. }
  188. /*
  189. * Initialization differs a bit between KN02 and KN03/KN05, so we
  190. * need two variants. Once set up, all systems can be handled the
  191. * same way.
  192. */
  193. static inline void dec_kn02_be_init(void)
  194. {
  195. volatile u32 *csr = (void *)CKSEG1ADDR(KN02_SLOT_BASE + KN02_CSR);
  196. kn0x_erraddr = (void *)CKSEG1ADDR(KN02_SLOT_BASE + KN02_ERRADDR);
  197. kn0x_chksyn = (void *)CKSEG1ADDR(KN02_SLOT_BASE + KN02_CHKSYN);
  198. /* Preset write-only bits of the Control Register cache. */
  199. cached_kn02_csr = *csr | KN02_CSR_LEDS;
  200. /* Set normal ECC detection and generation. */
  201. cached_kn02_csr &= ~(KN02_CSR_DIAGCHK | KN02_CSR_DIAGGEN);
  202. /* Enable ECC correction. */
  203. cached_kn02_csr |= KN02_CSR_CORRECT;
  204. *csr = cached_kn02_csr;
  205. iob();
  206. }
  207. static inline void dec_kn03_be_init(void)
  208. {
  209. volatile u32 *mcr = (void *)CKSEG1ADDR(KN03_SLOT_BASE + IOASIC_MCR);
  210. volatile u32 *mbcs = (void *)CKSEG1ADDR(KN4K_SLOT_BASE + KN4K_MB_CSR);
  211. kn0x_erraddr = (void *)CKSEG1ADDR(KN03_SLOT_BASE + IOASIC_ERRADDR);
  212. kn0x_chksyn = (void *)CKSEG1ADDR(KN03_SLOT_BASE + IOASIC_CHKSYN);
  213. /*
  214. * Set normal ECC detection and generation, enable ECC correction.
  215. * For KN05 we also need to make sure EE (?) is enabled in the MB.
  216. * Otherwise DBE/IBE exceptions would be masked but bus error
  217. * interrupts would still arrive, resulting in an inevitable crash
  218. * if get_dbe() triggers one.
  219. */
  220. *mcr = (*mcr & ~(KN03_MCR_DIAGCHK | KN03_MCR_DIAGGEN)) |
  221. KN03_MCR_CORRECT;
  222. if (current_cpu_type() == CPU_R4400SC)
  223. *mbcs |= KN4K_MB_CSR_EE;
  224. fast_iob();
  225. }
  226. void __init dec_ecc_be_init(void)
  227. {
  228. if (mips_machtype == MACH_DS5000_200)
  229. dec_kn02_be_init();
  230. else
  231. dec_kn03_be_init();
  232. /* Clear any leftover errors from the firmware. */
  233. dec_ecc_be_ack();
  234. }