bus_watcher.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright (C) 2002,2003 Broadcom Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. /*
  19. * The Bus Watcher monitors internal bus transactions and maintains
  20. * counts of transactions with error status, logging details and
  21. * causing one of several interrupts. This driver provides a handler
  22. * for those interrupts which aggregates the counts (to avoid
  23. * saturating the 8-bit counters) and provides a presence in
  24. * /proc/bus_watcher if PROC_FS is on.
  25. */
  26. #include <linux/config.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/sched.h>
  31. #include <linux/proc_fs.h>
  32. #include <asm/system.h>
  33. #include <asm/io.h>
  34. #include <asm/sibyte/sb1250.h>
  35. #include <asm/sibyte/sb1250_regs.h>
  36. #include <asm/sibyte/sb1250_int.h>
  37. #include <asm/sibyte/sb1250_scd.h>
  38. struct bw_stats_struct {
  39. uint64_t status;
  40. uint32_t l2_err;
  41. uint32_t memio_err;
  42. int status_printed;
  43. unsigned long l2_cor_d;
  44. unsigned long l2_bad_d;
  45. unsigned long l2_cor_t;
  46. unsigned long l2_bad_t;
  47. unsigned long mem_cor_d;
  48. unsigned long mem_bad_d;
  49. unsigned long bus_error;
  50. } bw_stats;
  51. static void print_summary(uint32_t status, uint32_t l2_err,
  52. uint32_t memio_err)
  53. {
  54. printk("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);
  55. printk("\nLast recorded signature:\n");
  56. printk("Request %02x from %d, answered by %d with Dcode %d\n",
  57. (unsigned int)(G_SCD_BERR_TID(status) & 0x3f),
  58. (int)(G_SCD_BERR_TID(status) >> 6),
  59. (int)G_SCD_BERR_RID(status),
  60. (int)G_SCD_BERR_DCODE(status));
  61. }
  62. /*
  63. * check_bus_watcher is exported for use in situations where we want
  64. * to see the most recent status of the bus watcher, which might have
  65. * already been destructively read out of the registers.
  66. *
  67. * notes: this is currently used by the cache error handler
  68. * should provide locking against the interrupt handler
  69. */
  70. void check_bus_watcher(void)
  71. {
  72. u32 status, l2_err, memio_err;
  73. #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
  74. /* Destructive read, clears register and interrupt */
  75. status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
  76. #else
  77. /* Use non-destructive register */
  78. status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS_DEBUG));
  79. #endif
  80. if (!(status & 0x7fffffff)) {
  81. printk("Using last values reaped by bus watcher driver\n");
  82. status = bw_stats.status;
  83. l2_err = bw_stats.l2_err;
  84. memio_err = bw_stats.memio_err;
  85. } else {
  86. l2_err = csr_in32(IOADDR(A_BUS_L2_ERRORS));
  87. memio_err = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
  88. }
  89. if (status & ~(1UL << 31))
  90. print_summary(status, l2_err, memio_err);
  91. else
  92. printk("Bus watcher indicates no error\n");
  93. }
  94. static int bw_print_buffer(char *page, struct bw_stats_struct *stats)
  95. {
  96. int len;
  97. len = sprintf(page, "SiByte Bus Watcher statistics\n");
  98. len += sprintf(page+len, "-----------------------------\n");
  99. len += sprintf(page+len, "L2-d-cor %8ld\nL2-d-bad %8ld\n",
  100. stats->l2_cor_d, stats->l2_bad_d);
  101. len += sprintf(page+len, "L2-t-cor %8ld\nL2-t-bad %8ld\n",
  102. stats->l2_cor_t, stats->l2_bad_t);
  103. len += sprintf(page+len, "MC-d-cor %8ld\nMC-d-bad %8ld\n",
  104. stats->mem_cor_d, stats->mem_bad_d);
  105. len += sprintf(page+len, "IO-err %8ld\n", stats->bus_error);
  106. len += sprintf(page+len, "\nLast recorded signature:\n");
  107. len += sprintf(page+len, "Request %02x from %d, answered by %d with Dcode %d\n",
  108. (unsigned int)(G_SCD_BERR_TID(stats->status) & 0x3f),
  109. (int)(G_SCD_BERR_TID(stats->status) >> 6),
  110. (int)G_SCD_BERR_RID(stats->status),
  111. (int)G_SCD_BERR_DCODE(stats->status));
  112. /* XXXKW indicate multiple errors between printings, or stats
  113. collection (or both)? */
  114. if (stats->status & M_SCD_BERR_MULTERRS)
  115. len += sprintf(page+len, "Multiple errors observed since last check.\n");
  116. if (stats->status_printed) {
  117. len += sprintf(page+len, "(no change since last printing)\n");
  118. } else {
  119. stats->status_printed = 1;
  120. }
  121. return len;
  122. }
  123. #ifdef CONFIG_PROC_FS
  124. /* For simplicity, I want to assume a single read is required each
  125. time */
  126. static int bw_read_proc(char *page, char **start, off_t off,
  127. int count, int *eof, void *data)
  128. {
  129. int len;
  130. if (off == 0) {
  131. len = bw_print_buffer(page, data);
  132. *start = page;
  133. } else {
  134. len = 0;
  135. *eof = 1;
  136. }
  137. return len;
  138. }
  139. static void create_proc_decoder(struct bw_stats_struct *stats)
  140. {
  141. struct proc_dir_entry *ent;
  142. ent = create_proc_read_entry("bus_watcher", S_IWUSR | S_IRUGO, NULL,
  143. bw_read_proc, stats);
  144. if (!ent) {
  145. printk(KERN_INFO "Unable to initialize bus_watcher /proc entry\n");
  146. return;
  147. }
  148. }
  149. #endif /* CONFIG_PROC_FS */
  150. /*
  151. * sibyte_bw_int - handle bus watcher interrupts and accumulate counts
  152. *
  153. * notes: possible re-entry due to multiple sources
  154. * should check/indicate saturation
  155. */
  156. static irqreturn_t sibyte_bw_int(int irq, void *data, struct pt_regs *regs)
  157. {
  158. struct bw_stats_struct *stats = data;
  159. unsigned long cntr;
  160. #ifdef CONFIG_SIBYTE_BW_TRACE
  161. int i;
  162. #endif
  163. #ifndef CONFIG_PROC_FS
  164. char bw_buf[1024];
  165. #endif
  166. #ifdef CONFIG_SIBYTE_BW_TRACE
  167. csr_out32(M_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));
  168. csr_out32(M_SCD_TRACE_CFG_START_READ, IOADDR(A_SCD_TRACE_CFG));
  169. for (i=0; i<256*6; i++)
  170. printk("%016llx\n",
  171. (unsigned long long)bus_readq(IOADDR(A_SCD_TRACE_READ)));
  172. csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
  173. csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
  174. #endif
  175. /* Destructive read, clears register and interrupt */
  176. stats->status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
  177. stats->status_printed = 0;
  178. stats->l2_err = cntr = csr_in32(IOADDR(A_BUS_L2_ERRORS));
  179. stats->l2_cor_d += G_SCD_L2ECC_CORR_D(cntr);
  180. stats->l2_bad_d += G_SCD_L2ECC_BAD_D(cntr);
  181. stats->l2_cor_t += G_SCD_L2ECC_CORR_T(cntr);
  182. stats->l2_bad_t += G_SCD_L2ECC_BAD_T(cntr);
  183. csr_out32(0, IOADDR(A_BUS_L2_ERRORS));
  184. stats->memio_err = cntr = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
  185. stats->mem_cor_d += G_SCD_MEM_ECC_CORR(cntr);
  186. stats->mem_bad_d += G_SCD_MEM_ECC_BAD(cntr);
  187. stats->bus_error += G_SCD_MEM_BUSERR(cntr);
  188. csr_out32(0, IOADDR(A_BUS_MEM_IO_ERRORS));
  189. #ifndef CONFIG_PROC_FS
  190. bw_print_buffer(bw_buf, stats);
  191. printk(bw_buf);
  192. #endif
  193. return IRQ_HANDLED;
  194. }
  195. int __init sibyte_bus_watcher(void)
  196. {
  197. memset(&bw_stats, 0, sizeof(struct bw_stats_struct));
  198. bw_stats.status_printed = 1;
  199. if (request_irq(K_INT_BAD_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
  200. printk("Failed to register bus watcher BAD_ECC irq\n");
  201. return -1;
  202. }
  203. if (request_irq(K_INT_COR_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
  204. free_irq(K_INT_BAD_ECC, &bw_stats);
  205. printk("Failed to register bus watcher COR_ECC irq\n");
  206. return -1;
  207. }
  208. if (request_irq(K_INT_IO_BUS, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
  209. free_irq(K_INT_BAD_ECC, &bw_stats);
  210. free_irq(K_INT_COR_ECC, &bw_stats);
  211. printk("Failed to register bus watcher IO_BUS irq\n");
  212. return -1;
  213. }
  214. #ifdef CONFIG_PROC_FS
  215. create_proc_decoder(&bw_stats);
  216. #endif
  217. #ifdef CONFIG_SIBYTE_BW_TRACE
  218. csr_out32((M_SCD_TRSEQ_ASAMPLE | M_SCD_TRSEQ_DSAMPLE |
  219. K_SCD_TRSEQ_TRIGGER_ALL),
  220. IOADDR(A_SCD_TRACE_SEQUENCE_0));
  221. csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
  222. csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
  223. #endif
  224. return 0;
  225. }
  226. __initcall(sibyte_bus_watcher);