bus_watcher.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/init.h>
  27. #include <linux/kernel.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/sched.h>
  30. #include <linux/proc_fs.h>
  31. #include <linux/seq_file.h>
  32. #include <asm/io.h>
  33. #include <asm/sibyte/sb1250.h>
  34. #include <asm/sibyte/sb1250_regs.h>
  35. #include <asm/sibyte/sb1250_int.h>
  36. #include <asm/sibyte/sb1250_scd.h>
  37. #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
  38. #include <asm/sibyte/bcm1480_regs.h>
  39. #endif
  40. struct bw_stats_struct {
  41. uint64_t status;
  42. uint32_t l2_err;
  43. uint32_t memio_err;
  44. int status_printed;
  45. unsigned long l2_cor_d;
  46. unsigned long l2_bad_d;
  47. unsigned long l2_cor_t;
  48. unsigned long l2_bad_t;
  49. unsigned long mem_cor_d;
  50. unsigned long mem_bad_d;
  51. unsigned long bus_error;
  52. } bw_stats;
  53. static void print_summary(uint32_t status, uint32_t l2_err,
  54. uint32_t memio_err)
  55. {
  56. printk("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);
  57. printk("\nLast recorded signature:\n");
  58. printk("Request %02x from %d, answered by %d with Dcode %d\n",
  59. (unsigned int)(G_SCD_BERR_TID(status) & 0x3f),
  60. (int)(G_SCD_BERR_TID(status) >> 6),
  61. (int)G_SCD_BERR_RID(status),
  62. (int)G_SCD_BERR_DCODE(status));
  63. }
  64. /*
  65. * check_bus_watcher is exported for use in situations where we want
  66. * to see the most recent status of the bus watcher, which might have
  67. * already been destructively read out of the registers.
  68. *
  69. * notes: this is currently used by the cache error handler
  70. * should provide locking against the interrupt handler
  71. */
  72. void check_bus_watcher(void)
  73. {
  74. u32 status, l2_err, memio_err;
  75. #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
  76. /* Destructive read, clears register and interrupt */
  77. status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
  78. #elif defined(CONFIG_SIBYTE_BCM112X) || defined(CONFIG_SIBYTE_SB1250)
  79. /* Use non-destructive register */
  80. status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS_DEBUG));
  81. #elif defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80)
  82. /* Use non-destructive register */
  83. /* Same as 1250 except BUS_ERR_STATUS_DEBUG is in a different place. */
  84. status = csr_in32(IOADDR(A_BCM1480_BUS_ERR_STATUS_DEBUG));
  85. #else
  86. #error bus watcher being built for unknown Sibyte SOC!
  87. #endif
  88. if (!(status & 0x7fffffff)) {
  89. printk("Using last values reaped by bus watcher driver\n");
  90. status = bw_stats.status;
  91. l2_err = bw_stats.l2_err;
  92. memio_err = bw_stats.memio_err;
  93. } else {
  94. l2_err = csr_in32(IOADDR(A_BUS_L2_ERRORS));
  95. memio_err = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
  96. }
  97. if (status & ~(1UL << 31))
  98. print_summary(status, l2_err, memio_err);
  99. else
  100. printk("Bus watcher indicates no error\n");
  101. }
  102. #ifdef CONFIG_PROC_FS
  103. /* For simplicity, I want to assume a single read is required each
  104. time */
  105. static int bw_proc_show(struct seq_file *m, void *v)
  106. {
  107. struct bw_stats_struct *stats = m->private;
  108. seq_puts(m, "SiByte Bus Watcher statistics\n");
  109. seq_puts(m, "-----------------------------\n");
  110. seq_printf(m, "L2-d-cor %8ld\nL2-d-bad %8ld\n",
  111. stats->l2_cor_d, stats->l2_bad_d);
  112. seq_printf(m, "L2-t-cor %8ld\nL2-t-bad %8ld\n",
  113. stats->l2_cor_t, stats->l2_bad_t);
  114. seq_printf(m, "MC-d-cor %8ld\nMC-d-bad %8ld\n",
  115. stats->mem_cor_d, stats->mem_bad_d);
  116. seq_printf(m, "IO-err %8ld\n", stats->bus_error);
  117. seq_puts(m, "\nLast recorded signature:\n");
  118. seq_printf(m, "Request %02x from %d, answered by %d with Dcode %d\n",
  119. (unsigned int)(G_SCD_BERR_TID(stats->status) & 0x3f),
  120. (int)(G_SCD_BERR_TID(stats->status) >> 6),
  121. (int)G_SCD_BERR_RID(stats->status),
  122. (int)G_SCD_BERR_DCODE(stats->status));
  123. /* XXXKW indicate multiple errors between printings, or stats
  124. collection (or both)? */
  125. if (stats->status & M_SCD_BERR_MULTERRS)
  126. seq_puts(m, "Multiple errors observed since last check.\n");
  127. if (stats->status_printed) {
  128. seq_puts(m, "(no change since last printing)\n");
  129. } else {
  130. stats->status_printed = 1;
  131. }
  132. return 0;
  133. }
  134. static int bw_proc_open(struct inode *inode, struct file *file)
  135. {
  136. return single_open(file, bw_proc_show, PDE_DATA(inode));
  137. }
  138. static const struct file_operations bw_proc_fops = {
  139. .open = bw_proc_open,
  140. .read = seq_read,
  141. .llseek = seq_lseek,
  142. .release = single_release,
  143. };
  144. static void create_proc_decoder(struct bw_stats_struct *stats)
  145. {
  146. struct proc_dir_entry *ent;
  147. ent = proc_create_data("bus_watcher", S_IWUSR | S_IRUGO, NULL,
  148. &bw_proc_fops, stats);
  149. if (!ent) {
  150. printk(KERN_INFO "Unable to initialize bus_watcher /proc entry\n");
  151. return;
  152. }
  153. }
  154. #endif /* CONFIG_PROC_FS */
  155. /*
  156. * sibyte_bw_int - handle bus watcher interrupts and accumulate counts
  157. *
  158. * notes: possible re-entry due to multiple sources
  159. * should check/indicate saturation
  160. */
  161. static irqreturn_t sibyte_bw_int(int irq, void *data)
  162. {
  163. struct bw_stats_struct *stats = data;
  164. unsigned long cntr;
  165. #ifdef CONFIG_SIBYTE_BW_TRACE
  166. int i;
  167. #endif
  168. #ifdef CONFIG_SIBYTE_BW_TRACE
  169. csr_out32(M_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));
  170. csr_out32(M_SCD_TRACE_CFG_START_READ, IOADDR(A_SCD_TRACE_CFG));
  171. for (i=0; i<256*6; i++)
  172. printk("%016llx\n",
  173. (long long)__raw_readq(IOADDR(A_SCD_TRACE_READ)));
  174. csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
  175. csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
  176. #endif
  177. /* Destructive read, clears register and interrupt */
  178. stats->status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
  179. stats->status_printed = 0;
  180. stats->l2_err = cntr = csr_in32(IOADDR(A_BUS_L2_ERRORS));
  181. stats->l2_cor_d += G_SCD_L2ECC_CORR_D(cntr);
  182. stats->l2_bad_d += G_SCD_L2ECC_BAD_D(cntr);
  183. stats->l2_cor_t += G_SCD_L2ECC_CORR_T(cntr);
  184. stats->l2_bad_t += G_SCD_L2ECC_BAD_T(cntr);
  185. csr_out32(0, IOADDR(A_BUS_L2_ERRORS));
  186. stats->memio_err = cntr = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
  187. stats->mem_cor_d += G_SCD_MEM_ECC_CORR(cntr);
  188. stats->mem_bad_d += G_SCD_MEM_ECC_BAD(cntr);
  189. stats->bus_error += G_SCD_MEM_BUSERR(cntr);
  190. csr_out32(0, IOADDR(A_BUS_MEM_IO_ERRORS));
  191. return IRQ_HANDLED;
  192. }
  193. int __init sibyte_bus_watcher(void)
  194. {
  195. memset(&bw_stats, 0, sizeof(struct bw_stats_struct));
  196. bw_stats.status_printed = 1;
  197. if (request_irq(K_INT_BAD_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
  198. printk("Failed to register bus watcher BAD_ECC irq\n");
  199. return -1;
  200. }
  201. if (request_irq(K_INT_COR_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
  202. free_irq(K_INT_BAD_ECC, &bw_stats);
  203. printk("Failed to register bus watcher COR_ECC irq\n");
  204. return -1;
  205. }
  206. if (request_irq(K_INT_IO_BUS, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
  207. free_irq(K_INT_BAD_ECC, &bw_stats);
  208. free_irq(K_INT_COR_ECC, &bw_stats);
  209. printk("Failed to register bus watcher IO_BUS irq\n");
  210. return -1;
  211. }
  212. #ifdef CONFIG_PROC_FS
  213. create_proc_decoder(&bw_stats);
  214. #endif
  215. #ifdef CONFIG_SIBYTE_BW_TRACE
  216. csr_out32((M_SCD_TRSEQ_ASAMPLE | M_SCD_TRSEQ_DSAMPLE |
  217. K_SCD_TRSEQ_TRIGGER_ALL),
  218. IOADDR(A_SCD_TRACE_SEQUENCE_0));
  219. csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
  220. csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
  221. #endif
  222. return 0;
  223. }
  224. __initcall(sibyte_bus_watcher);