]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/mips/sibyte/sb1250/bus_watcher.c
Linux-2.6.12-rc2
[mirror_ubuntu-bionic-kernel.git] / arch / mips / sibyte / sb1250 / bus_watcher.c
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 /*
20 * 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
28 #include <linux/config.h>
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/interrupt.h>
32 #include <linux/sched.h>
33 #include <linux/proc_fs.h>
34 #include <asm/system.h>
35 #include <asm/io.h>
36
37 #include <asm/sibyte/sb1250.h>
38 #include <asm/sibyte/sb1250_regs.h>
39 #include <asm/sibyte/sb1250_int.h>
40 #include <asm/sibyte/sb1250_scd.h>
41
42
43 struct bw_stats_struct {
44 uint64_t status;
45 uint32_t l2_err;
46 uint32_t memio_err;
47 int status_printed;
48 unsigned long l2_cor_d;
49 unsigned long l2_bad_d;
50 unsigned long l2_cor_t;
51 unsigned long l2_bad_t;
52 unsigned long mem_cor_d;
53 unsigned long mem_bad_d;
54 unsigned long bus_error;
55 } bw_stats;
56
57
58 static void print_summary(uint32_t status, uint32_t l2_err,
59 uint32_t memio_err)
60 {
61 printk("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);
62 printk("\nLast recorded signature:\n");
63 printk("Request %02x from %d, answered by %d with Dcode %d\n",
64 (unsigned int)(G_SCD_BERR_TID(status) & 0x3f),
65 (int)(G_SCD_BERR_TID(status) >> 6),
66 (int)G_SCD_BERR_RID(status),
67 (int)G_SCD_BERR_DCODE(status));
68 }
69
70 /*
71 * check_bus_watcher is exported for use in situations where we want
72 * to see the most recent status of the bus watcher, which might have
73 * already been destructively read out of the registers.
74 *
75 * notes: this is currently used by the cache error handler
76 * should provide locking against the interrupt handler
77 */
78 void check_bus_watcher(void)
79 {
80 u32 status, l2_err, memio_err;
81
82 #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
83 /* Destructive read, clears register and interrupt */
84 status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
85 #else
86 /* Use non-destructive register */
87 status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS_DEBUG));
88 #endif
89 if (!(status & 0x7fffffff)) {
90 printk("Using last values reaped by bus watcher driver\n");
91 status = bw_stats.status;
92 l2_err = bw_stats.l2_err;
93 memio_err = bw_stats.memio_err;
94 } else {
95 l2_err = csr_in32(IOADDR(A_BUS_L2_ERRORS));
96 memio_err = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
97 }
98 if (status & ~(1UL << 31))
99 print_summary(status, l2_err, memio_err);
100 else
101 printk("Bus watcher indicates no error\n");
102 }
103
104 static int bw_print_buffer(char *page, struct bw_stats_struct *stats)
105 {
106 int len;
107
108 len = sprintf(page, "SiByte Bus Watcher statistics\n");
109 len += sprintf(page+len, "-----------------------------\n");
110 len += sprintf(page+len, "L2-d-cor %8ld\nL2-d-bad %8ld\n",
111 stats->l2_cor_d, stats->l2_bad_d);
112 len += sprintf(page+len, "L2-t-cor %8ld\nL2-t-bad %8ld\n",
113 stats->l2_cor_t, stats->l2_bad_t);
114 len += sprintf(page+len, "MC-d-cor %8ld\nMC-d-bad %8ld\n",
115 stats->mem_cor_d, stats->mem_bad_d);
116 len += sprintf(page+len, "IO-err %8ld\n", stats->bus_error);
117 len += sprintf(page+len, "\nLast recorded signature:\n");
118 len += sprintf(page+len, "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 len += sprintf(page+len, "Multiple errors observed since last check.\n");
127 if (stats->status_printed) {
128 len += sprintf(page+len, "(no change since last printing)\n");
129 } else {
130 stats->status_printed = 1;
131 }
132
133 return len;
134 }
135
136 #ifdef CONFIG_PROC_FS
137
138 /* For simplicity, I want to assume a single read is required each
139 time */
140 static int bw_read_proc(char *page, char **start, off_t off,
141 int count, int *eof, void *data)
142 {
143 int len;
144
145 if (off == 0) {
146 len = bw_print_buffer(page, data);
147 *start = page;
148 } else {
149 len = 0;
150 *eof = 1;
151 }
152 return len;
153 }
154
155 static void create_proc_decoder(struct bw_stats_struct *stats)
156 {
157 struct proc_dir_entry *ent;
158
159 ent = create_proc_read_entry("bus_watcher", S_IWUSR | S_IRUGO, NULL,
160 bw_read_proc, stats);
161 if (!ent) {
162 printk(KERN_INFO "Unable to initialize bus_watcher /proc entry\n");
163 return;
164 }
165 }
166
167 #endif /* CONFIG_PROC_FS */
168
169 /*
170 * sibyte_bw_int - handle bus watcher interrupts and accumulate counts
171 *
172 * notes: possible re-entry due to multiple sources
173 * should check/indicate saturation
174 */
175 static irqreturn_t sibyte_bw_int(int irq, void *data, struct pt_regs *regs)
176 {
177 struct bw_stats_struct *stats = data;
178 unsigned long cntr;
179 #ifdef CONFIG_SIBYTE_BW_TRACE
180 int i;
181 #endif
182 #ifndef CONFIG_PROC_FS
183 char bw_buf[1024];
184 #endif
185
186 #ifdef CONFIG_SIBYTE_BW_TRACE
187 csr_out32(M_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));
188 csr_out32(M_SCD_TRACE_CFG_START_READ, IOADDR(A_SCD_TRACE_CFG));
189
190 for (i=0; i<256*6; i++)
191 printk("%016llx\n",
192 (unsigned long long)bus_readq(IOADDR(A_SCD_TRACE_READ)));
193
194 csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
195 csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
196 #endif
197
198 /* Destructive read, clears register and interrupt */
199 stats->status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));
200 stats->status_printed = 0;
201
202 stats->l2_err = cntr = csr_in32(IOADDR(A_BUS_L2_ERRORS));
203 stats->l2_cor_d += G_SCD_L2ECC_CORR_D(cntr);
204 stats->l2_bad_d += G_SCD_L2ECC_BAD_D(cntr);
205 stats->l2_cor_t += G_SCD_L2ECC_CORR_T(cntr);
206 stats->l2_bad_t += G_SCD_L2ECC_BAD_T(cntr);
207 csr_out32(0, IOADDR(A_BUS_L2_ERRORS));
208
209 stats->memio_err = cntr = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));
210 stats->mem_cor_d += G_SCD_MEM_ECC_CORR(cntr);
211 stats->mem_bad_d += G_SCD_MEM_ECC_BAD(cntr);
212 stats->bus_error += G_SCD_MEM_BUSERR(cntr);
213 csr_out32(0, IOADDR(A_BUS_MEM_IO_ERRORS));
214
215 #ifndef CONFIG_PROC_FS
216 bw_print_buffer(bw_buf, stats);
217 printk(bw_buf);
218 #endif
219
220 return IRQ_HANDLED;
221 }
222
223 int __init sibyte_bus_watcher(void)
224 {
225 memset(&bw_stats, 0, sizeof(struct bw_stats_struct));
226 bw_stats.status_printed = 1;
227
228 if (request_irq(K_INT_BAD_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
229 printk("Failed to register bus watcher BAD_ECC irq\n");
230 return -1;
231 }
232 if (request_irq(K_INT_COR_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
233 free_irq(K_INT_BAD_ECC, &bw_stats);
234 printk("Failed to register bus watcher COR_ECC irq\n");
235 return -1;
236 }
237 if (request_irq(K_INT_IO_BUS, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {
238 free_irq(K_INT_BAD_ECC, &bw_stats);
239 free_irq(K_INT_COR_ECC, &bw_stats);
240 printk("Failed to register bus watcher IO_BUS irq\n");
241 return -1;
242 }
243
244 #ifdef CONFIG_PROC_FS
245 create_proc_decoder(&bw_stats);
246 #endif
247
248 #ifdef CONFIG_SIBYTE_BW_TRACE
249 csr_out32((M_SCD_TRSEQ_ASAMPLE | M_SCD_TRSEQ_DSAMPLE |
250 K_SCD_TRSEQ_TRIGGER_ALL),
251 IOADDR(A_SCD_TRACE_SEQUENCE_0));
252 csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));
253 csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));
254 #endif
255
256 return 0;
257 }
258
259 __initcall(sibyte_bus_watcher);