Path: blob/master/arch/mips/sibyte/sb1250/bus_watcher.c
15118 views
/*1* Copyright (C) 2002,2003 Broadcom Corporation2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation; either version 26* of the License, or (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.16*/1718/*19* The Bus Watcher monitors internal bus transactions and maintains20* counts of transactions with error status, logging details and21* causing one of several interrupts. This driver provides a handler22* for those interrupts which aggregates the counts (to avoid23* saturating the 8-bit counters) and provides a presence in24* /proc/bus_watcher if PROC_FS is on.25*/2627#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>3435#include <asm/sibyte/sb1250.h>36#include <asm/sibyte/sb1250_regs.h>37#include <asm/sibyte/sb1250_int.h>38#include <asm/sibyte/sb1250_scd.h>394041struct bw_stats_struct {42uint64_t status;43uint32_t l2_err;44uint32_t memio_err;45int status_printed;46unsigned long l2_cor_d;47unsigned long l2_bad_d;48unsigned long l2_cor_t;49unsigned long l2_bad_t;50unsigned long mem_cor_d;51unsigned long mem_bad_d;52unsigned long bus_error;53} bw_stats;545556static void print_summary(uint32_t status, uint32_t l2_err,57uint32_t memio_err)58{59printk("Bus watcher error counters: %08x %08x\n", l2_err, memio_err);60printk("\nLast recorded signature:\n");61printk("Request %02x from %d, answered by %d with Dcode %d\n",62(unsigned int)(G_SCD_BERR_TID(status) & 0x3f),63(int)(G_SCD_BERR_TID(status) >> 6),64(int)G_SCD_BERR_RID(status),65(int)G_SCD_BERR_DCODE(status));66}6768/*69* check_bus_watcher is exported for use in situations where we want70* to see the most recent status of the bus watcher, which might have71* already been destructively read out of the registers.72*73* notes: this is currently used by the cache error handler74* should provide locking against the interrupt handler75*/76void check_bus_watcher(void)77{78u32 status, l2_err, memio_err;7980#ifdef CONFIG_SB1_PASS_1_WORKAROUNDS81/* Destructive read, clears register and interrupt */82status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));83#else84/* Use non-destructive register */85status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS_DEBUG));86#endif87if (!(status & 0x7fffffff)) {88printk("Using last values reaped by bus watcher driver\n");89status = bw_stats.status;90l2_err = bw_stats.l2_err;91memio_err = bw_stats.memio_err;92} else {93l2_err = csr_in32(IOADDR(A_BUS_L2_ERRORS));94memio_err = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));95}96if (status & ~(1UL << 31))97print_summary(status, l2_err, memio_err);98else99printk("Bus watcher indicates no error\n");100}101102static int bw_print_buffer(char *page, struct bw_stats_struct *stats)103{104int len;105106len = sprintf(page, "SiByte Bus Watcher statistics\n");107len += sprintf(page+len, "-----------------------------\n");108len += sprintf(page+len, "L2-d-cor %8ld\nL2-d-bad %8ld\n",109stats->l2_cor_d, stats->l2_bad_d);110len += sprintf(page+len, "L2-t-cor %8ld\nL2-t-bad %8ld\n",111stats->l2_cor_t, stats->l2_bad_t);112len += sprintf(page+len, "MC-d-cor %8ld\nMC-d-bad %8ld\n",113stats->mem_cor_d, stats->mem_bad_d);114len += sprintf(page+len, "IO-err %8ld\n", stats->bus_error);115len += sprintf(page+len, "\nLast recorded signature:\n");116len += sprintf(page+len, "Request %02x from %d, answered by %d with Dcode %d\n",117(unsigned int)(G_SCD_BERR_TID(stats->status) & 0x3f),118(int)(G_SCD_BERR_TID(stats->status) >> 6),119(int)G_SCD_BERR_RID(stats->status),120(int)G_SCD_BERR_DCODE(stats->status));121/* XXXKW indicate multiple errors between printings, or stats122collection (or both)? */123if (stats->status & M_SCD_BERR_MULTERRS)124len += sprintf(page+len, "Multiple errors observed since last check.\n");125if (stats->status_printed) {126len += sprintf(page+len, "(no change since last printing)\n");127} else {128stats->status_printed = 1;129}130131return len;132}133134#ifdef CONFIG_PROC_FS135136/* For simplicity, I want to assume a single read is required each137time */138static int bw_read_proc(char *page, char **start, off_t off,139int count, int *eof, void *data)140{141int len;142143if (off == 0) {144len = bw_print_buffer(page, data);145*start = page;146} else {147len = 0;148*eof = 1;149}150return len;151}152153static void create_proc_decoder(struct bw_stats_struct *stats)154{155struct proc_dir_entry *ent;156157ent = create_proc_read_entry("bus_watcher", S_IWUSR | S_IRUGO, NULL,158bw_read_proc, stats);159if (!ent) {160printk(KERN_INFO "Unable to initialize bus_watcher /proc entry\n");161return;162}163}164165#endif /* CONFIG_PROC_FS */166167/*168* sibyte_bw_int - handle bus watcher interrupts and accumulate counts169*170* notes: possible re-entry due to multiple sources171* should check/indicate saturation172*/173static irqreturn_t sibyte_bw_int(int irq, void *data)174{175struct bw_stats_struct *stats = data;176unsigned long cntr;177#ifdef CONFIG_SIBYTE_BW_TRACE178int i;179#endif180#ifndef CONFIG_PROC_FS181char bw_buf[1024];182#endif183184#ifdef CONFIG_SIBYTE_BW_TRACE185csr_out32(M_SCD_TRACE_CFG_FREEZE, IOADDR(A_SCD_TRACE_CFG));186csr_out32(M_SCD_TRACE_CFG_START_READ, IOADDR(A_SCD_TRACE_CFG));187188for (i=0; i<256*6; i++)189printk("%016llx\n",190(long long)__raw_readq(IOADDR(A_SCD_TRACE_READ)));191192csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));193csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));194#endif195196/* Destructive read, clears register and interrupt */197stats->status = csr_in32(IOADDR(A_SCD_BUS_ERR_STATUS));198stats->status_printed = 0;199200stats->l2_err = cntr = csr_in32(IOADDR(A_BUS_L2_ERRORS));201stats->l2_cor_d += G_SCD_L2ECC_CORR_D(cntr);202stats->l2_bad_d += G_SCD_L2ECC_BAD_D(cntr);203stats->l2_cor_t += G_SCD_L2ECC_CORR_T(cntr);204stats->l2_bad_t += G_SCD_L2ECC_BAD_T(cntr);205csr_out32(0, IOADDR(A_BUS_L2_ERRORS));206207stats->memio_err = cntr = csr_in32(IOADDR(A_BUS_MEM_IO_ERRORS));208stats->mem_cor_d += G_SCD_MEM_ECC_CORR(cntr);209stats->mem_bad_d += G_SCD_MEM_ECC_BAD(cntr);210stats->bus_error += G_SCD_MEM_BUSERR(cntr);211csr_out32(0, IOADDR(A_BUS_MEM_IO_ERRORS));212213#ifndef CONFIG_PROC_FS214bw_print_buffer(bw_buf, stats);215printk(bw_buf);216#endif217218return IRQ_HANDLED;219}220221int __init sibyte_bus_watcher(void)222{223memset(&bw_stats, 0, sizeof(struct bw_stats_struct));224bw_stats.status_printed = 1;225226if (request_irq(K_INT_BAD_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {227printk("Failed to register bus watcher BAD_ECC irq\n");228return -1;229}230if (request_irq(K_INT_COR_ECC, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {231free_irq(K_INT_BAD_ECC, &bw_stats);232printk("Failed to register bus watcher COR_ECC irq\n");233return -1;234}235if (request_irq(K_INT_IO_BUS, sibyte_bw_int, 0, "Bus watcher", &bw_stats)) {236free_irq(K_INT_BAD_ECC, &bw_stats);237free_irq(K_INT_COR_ECC, &bw_stats);238printk("Failed to register bus watcher IO_BUS irq\n");239return -1;240}241242#ifdef CONFIG_PROC_FS243create_proc_decoder(&bw_stats);244#endif245246#ifdef CONFIG_SIBYTE_BW_TRACE247csr_out32((M_SCD_TRSEQ_ASAMPLE | M_SCD_TRSEQ_DSAMPLE |248K_SCD_TRSEQ_TRIGGER_ALL),249IOADDR(A_SCD_TRACE_SEQUENCE_0));250csr_out32(M_SCD_TRACE_CFG_RESET, IOADDR(A_SCD_TRACE_CFG));251csr_out32(M_SCD_TRACE_CFG_START, IOADDR(A_SCD_TRACE_CFG));252#endif253254return 0;255}256257__initcall(sibyte_bus_watcher);258259260