ecc-berr.c 7.6 KB

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