blob: cb1e3cb37d703da3b06ebba3c7cc8da7fd035742 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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.
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070013 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * 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
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070019/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * The Bus Watcher monitors internal bus transactions and maintains
21 * counts of transactions with error status, logging details and
22 * causing one of several interrupts. This driver provides a handler
23 * for those interrupts which aggregates the counts (to avoid
24 * saturating the 8-bit counters) and provides a presence in
25 * /proc/bus_watcher if PROC_FS is on.
26 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/init.h>
29#include <linux/kernel.h>
30#include <linux/interrupt.h>
31#include <linux/sched.h>
32#include <linux/proc_fs.h>
David Howells24270152013-04-11 00:21:15 +010033#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/io.h>
35
36#include <asm/sibyte/sb1250.h>
37#include <asm/sibyte/sb1250_regs.h>
38#include <asm/sibyte/sb1250_int.h>
39#include <asm/sibyte/sb1250_scd.h>
40
41
42struct bw_stats_struct {
43 uint64_t status;
44 uint32_t l2_err;
45 uint32_t memio_err;
46 int status_printed;
47 unsigned long l2_cor_d;
48 unsigned long l2_bad_d;
49 unsigned long l2_cor_t;
50 unsigned long l2_bad_t;
51 unsigned long mem_cor_d;
52 unsigned long mem_bad_d;
53 unsigned long bus_error;
54} bw_stats;
55
56
57static void print_summary(uint32_t status, uint32_t l2_err,
58 uint32_t memio_err)
59{
60 printk("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);
61 printk("\nLast recorded signature:\n");
62 printk("Request %02x from %d, answered by %d with Dcode %d\n",
63 (unsigned int)(G_SCD_BERR_TID(status) & 0x3f),
64 (int)(G_SCD_BERR_TID(status) >> 6),
65 (int)G_SCD_BERR_RID(status),
66 (int)G_SCD_BERR_DCODE(status));
67}
68
69/*
70 * check_bus_watcher is exported for use in situations where we want
71 * to see the most recent status of the bus watcher, which might have
72 * already been destructively read out of the registers.
73 *
74 * notes: this is currently used by the cache error handler
Ralf Baechle70342282013-01-22 12:59:30 +010075 * should provide locking against the interrupt handler
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 */
77void check_bus_watcher(void)
78{
79 u32 status, l2_err, memio_err;
80
81#ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
82 /* Destructive read, clears register and interrupt */
83 status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
84#else
85 /* Use non-destructive register */
86 status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS_DEBUG));
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#ifdef CONFIG_PROC_FS
104
105/* For simplicity, I want to assume a single read is required each
106 time */
David Howells24270152013-04-11 00:21:15 +0100107static int bw_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
David Howells24270152013-04-11 00:21:15 +0100109 struct bw_stats_struct *stats = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
David Howells24270152013-04-11 00:21:15 +0100111 seq_puts(m, "SiByte Bus Watcher statistics\n");
112 seq_puts(m, "-----------------------------\n");
113 seq_printf(m, "L2-d-cor %8ld\nL2-d-bad %8ld\n",
114 stats->l2_cor_d, stats->l2_bad_d);
115 seq_printf(m, "L2-t-cor %8ld\nL2-t-bad %8ld\n",
116 stats->l2_cor_t, stats->l2_bad_t);
117 seq_printf(m, "MC-d-cor %8ld\nMC-d-bad %8ld\n",
118 stats->mem_cor_d, stats->mem_bad_d);
119 seq_printf(m, "IO-err %8ld\n", stats->bus_error);
120 seq_puts(m, "\nLast recorded signature:\n");
121 seq_printf(m, "Request %02x from %d, answered by %d with Dcode %d\n",
122 (unsigned int)(G_SCD_BERR_TID(stats->status) & 0x3f),
123 (int)(G_SCD_BERR_TID(stats->status) >> 6),
124 (int)G_SCD_BERR_RID(stats->status),
125 (int)G_SCD_BERR_DCODE(stats->status));
126 /* XXXKW indicate multiple errors between printings, or stats
127 collection (or both)? */
128 if (stats->status & M_SCD_BERR_MULTERRS)
129 seq_puts(m, "Multiple errors observed since last check.\n");
130 if (stats->status_printed) {
131 seq_puts(m, "(no change since last printing)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 } else {
David Howells24270152013-04-11 00:21:15 +0100133 stats->status_printed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
David Howells24270152013-04-11 00:21:15 +0100135
136 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
David Howells24270152013-04-11 00:21:15 +0100139static int bw_proc_open(struct inode *inode, struct file *file)
140{
141 return single_open(file, bw_proc_show, PDE_DATA(inode));
142}
143
144static const struct file_operations bw_proc_fops = {
145 .open = bw_proc_open,
146 .read = seq_read,
147 .llseek = seq_lseek,
148 .release = seq_release,
149};
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static void create_proc_decoder(struct bw_stats_struct *stats)
152{
153 struct proc_dir_entry *ent;
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700154
David Howells24270152013-04-11 00:21:15 +0100155 ent = proc_create_data("bus_watcher", S_IWUSR | S_IRUGO, NULL,
156 &bw_proc_fops, stats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 if (!ent) {
158 printk(KERN_INFO "Unable to initialize bus_watcher /proc entry\n");
159 return;
160 }
161}
162
163#endif /* CONFIG_PROC_FS */
164
165/*
166 * sibyte_bw_int - handle bus watcher interrupts and accumulate counts
167 *
168 * notes: possible re-entry due to multiple sources
Ralf Baechle70342282013-01-22 12:59:30 +0100169 * should check/indicate saturation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 */
Ralf Baechle36d98e72006-10-15 09:19:58 +0100171static irqreturn_t sibyte_bw_int(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
173 struct bw_stats_struct *stats = data;
174 unsigned long cntr;
175#ifdef CONFIG_SIBYTE_BW_TRACE
176 int i;
177#endif
178#ifndef CONFIG_PROC_FS
179 char bw_buf[1024];
180#endif
181
182#ifdef CONFIG_SIBYTE_BW_TRACE
183 csr_out32(M_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));
184 csr_out32(M_SCD_TRACE_CFG_START_READ, IOADDR(A_SCD_TRACE_CFG));
185
186 for (i=0; i<256*6; i++)
187 printk("%016llx\n",
Maciej W. Rozycki65bda1a2005-02-22 21:51:30 +0000188 (long long)__raw_readq(IOADDR(A_SCD_TRACE_READ)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
191 csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
192#endif
193
194 /* Destructive read, clears register and interrupt */
195 stats->status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
196 stats->status_printed = 0;
197
198 stats->l2_err = cntr = csr_in32(IOADDR(A_BUS_L2_ERRORS));
199 stats->l2_cor_d += G_SCD_L2ECC_CORR_D(cntr);
200 stats->l2_bad_d += G_SCD_L2ECC_BAD_D(cntr);
201 stats->l2_cor_t += G_SCD_L2ECC_CORR_T(cntr);
202 stats->l2_bad_t += G_SCD_L2ECC_BAD_T(cntr);
203 csr_out32(0, IOADDR(A_BUS_L2_ERRORS));
204
205 stats->memio_err = cntr = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
206 stats->mem_cor_d += G_SCD_MEM_ECC_CORR(cntr);
207 stats->mem_bad_d += G_SCD_MEM_ECC_BAD(cntr);
208 stats->bus_error += G_SCD_MEM_BUSERR(cntr);
209 csr_out32(0, IOADDR(A_BUS_MEM_IO_ERRORS));
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return IRQ_HANDLED;
212}
213
214int __init sibyte_bus_watcher(void)
215{
216 memset(&bw_stats, 0, sizeof(struct bw_stats_struct));
217 bw_stats.status_printed = 1;
218
219 if (request_irq(K_INT_BAD_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
220 printk("Failed to register bus watcher BAD_ECC irq\n");
221 return -1;
222 }
223 if (request_irq(K_INT_COR_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
224 free_irq(K_INT_BAD_ECC, &bw_stats);
225 printk("Failed to register bus watcher COR_ECC irq\n");
226 return -1;
227 }
228 if (request_irq(K_INT_IO_BUS, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
229 free_irq(K_INT_BAD_ECC, &bw_stats);
230 free_irq(K_INT_COR_ECC, &bw_stats);
231 printk("Failed to register bus watcher IO_BUS irq\n");
232 return -1;
233 }
234
235#ifdef CONFIG_PROC_FS
236 create_proc_decoder(&bw_stats);
237#endif
238
239#ifdef CONFIG_SIBYTE_BW_TRACE
240 csr_out32((M_SCD_TRSEQ_ASAMPLE | M_SCD_TRSEQ_DSAMPLE |
241 K_SCD_TRSEQ_TRIGGER_ALL),
242 IOADDR(A_SCD_TRACE_SEQUENCE_0));
243 csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
244 csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
245#endif
246
247 return 0;
248}
249
250__initcall(sibyte_bus_watcher);