Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 2012 Cavium, Inc.
0007  *
0008  * Copyright (C) 2009 Wind River Systems,
0009  *   written by Ralf Baechle <ralf@linux-mips.org>
0010  */
0011 #include <linux/module.h>
0012 #include <linux/init.h>
0013 #include <linux/slab.h>
0014 #include <linux/io.h>
0015 #include <linux/edac.h>
0016 
0017 #include <asm/octeon/cvmx.h>
0018 
0019 #include "edac_module.h"
0020 
0021 #define EDAC_MOD_STR "octeon-l2c"
0022 
0023 static void octeon_l2c_poll_oct1(struct edac_device_ctl_info *l2c)
0024 {
0025     union cvmx_l2t_err l2t_err, l2t_err_reset;
0026     union cvmx_l2d_err l2d_err, l2d_err_reset;
0027 
0028     l2t_err_reset.u64 = 0;
0029     l2t_err.u64 = cvmx_read_csr(CVMX_L2T_ERR);
0030     if (l2t_err.s.sec_err) {
0031         edac_device_handle_ce(l2c, 0, 0,
0032                       "Tag Single bit error (corrected)");
0033         l2t_err_reset.s.sec_err = 1;
0034     }
0035     if (l2t_err.s.ded_err) {
0036         edac_device_handle_ue(l2c, 0, 0,
0037                       "Tag Double bit error (detected)");
0038         l2t_err_reset.s.ded_err = 1;
0039     }
0040     if (l2t_err_reset.u64)
0041         cvmx_write_csr(CVMX_L2T_ERR, l2t_err_reset.u64);
0042 
0043     l2d_err_reset.u64 = 0;
0044     l2d_err.u64 = cvmx_read_csr(CVMX_L2D_ERR);
0045     if (l2d_err.s.sec_err) {
0046         edac_device_handle_ce(l2c, 0, 1,
0047                       "Data Single bit error (corrected)");
0048         l2d_err_reset.s.sec_err = 1;
0049     }
0050     if (l2d_err.s.ded_err) {
0051         edac_device_handle_ue(l2c, 0, 1,
0052                       "Data Double bit error (detected)");
0053         l2d_err_reset.s.ded_err = 1;
0054     }
0055     if (l2d_err_reset.u64)
0056         cvmx_write_csr(CVMX_L2D_ERR, l2d_err_reset.u64);
0057 
0058 }
0059 
0060 static void _octeon_l2c_poll_oct2(struct edac_device_ctl_info *l2c, int tad)
0061 {
0062     union cvmx_l2c_err_tdtx err_tdtx, err_tdtx_reset;
0063     union cvmx_l2c_err_ttgx err_ttgx, err_ttgx_reset;
0064     char buf1[64];
0065     char buf2[80];
0066 
0067     err_tdtx_reset.u64 = 0;
0068     err_tdtx.u64 = cvmx_read_csr(CVMX_L2C_ERR_TDTX(tad));
0069     if (err_tdtx.s.dbe || err_tdtx.s.sbe ||
0070         err_tdtx.s.vdbe || err_tdtx.s.vsbe)
0071         snprintf(buf1, sizeof(buf1),
0072              "type:%d, syn:0x%x, way:%d",
0073              err_tdtx.s.type, err_tdtx.s.syn, err_tdtx.s.wayidx);
0074 
0075     if (err_tdtx.s.dbe) {
0076         snprintf(buf2, sizeof(buf2),
0077              "L2D Double bit error (detected):%s", buf1);
0078         err_tdtx_reset.s.dbe = 1;
0079         edac_device_handle_ue(l2c, tad, 1, buf2);
0080     }
0081     if (err_tdtx.s.sbe) {
0082         snprintf(buf2, sizeof(buf2),
0083              "L2D Single bit error (corrected):%s", buf1);
0084         err_tdtx_reset.s.sbe = 1;
0085         edac_device_handle_ce(l2c, tad, 1, buf2);
0086     }
0087     if (err_tdtx.s.vdbe) {
0088         snprintf(buf2, sizeof(buf2),
0089              "VBF Double bit error (detected):%s", buf1);
0090         err_tdtx_reset.s.vdbe = 1;
0091         edac_device_handle_ue(l2c, tad, 1, buf2);
0092     }
0093     if (err_tdtx.s.vsbe) {
0094         snprintf(buf2, sizeof(buf2),
0095              "VBF Single bit error (corrected):%s", buf1);
0096         err_tdtx_reset.s.vsbe = 1;
0097         edac_device_handle_ce(l2c, tad, 1, buf2);
0098     }
0099     if (err_tdtx_reset.u64)
0100         cvmx_write_csr(CVMX_L2C_ERR_TDTX(tad), err_tdtx_reset.u64);
0101 
0102     err_ttgx_reset.u64 = 0;
0103     err_ttgx.u64 = cvmx_read_csr(CVMX_L2C_ERR_TTGX(tad));
0104 
0105     if (err_ttgx.s.dbe || err_ttgx.s.sbe)
0106         snprintf(buf1, sizeof(buf1),
0107              "type:%d, syn:0x%x, way:%d",
0108              err_ttgx.s.type, err_ttgx.s.syn, err_ttgx.s.wayidx);
0109 
0110     if (err_ttgx.s.dbe) {
0111         snprintf(buf2, sizeof(buf2),
0112              "Tag Double bit error (detected):%s", buf1);
0113         err_ttgx_reset.s.dbe = 1;
0114         edac_device_handle_ue(l2c, tad, 0, buf2);
0115     }
0116     if (err_ttgx.s.sbe) {
0117         snprintf(buf2, sizeof(buf2),
0118              "Tag Single bit error (corrected):%s", buf1);
0119         err_ttgx_reset.s.sbe = 1;
0120         edac_device_handle_ce(l2c, tad, 0, buf2);
0121     }
0122     if (err_ttgx_reset.u64)
0123         cvmx_write_csr(CVMX_L2C_ERR_TTGX(tad), err_ttgx_reset.u64);
0124 }
0125 
0126 static void octeon_l2c_poll_oct2(struct edac_device_ctl_info *l2c)
0127 {
0128     int i;
0129     for (i = 0; i < l2c->nr_instances; i++)
0130         _octeon_l2c_poll_oct2(l2c, i);
0131 }
0132 
0133 static int octeon_l2c_probe(struct platform_device *pdev)
0134 {
0135     struct edac_device_ctl_info *l2c;
0136 
0137     int num_tads = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 : 1;
0138 
0139     /* 'Tags' are block 0, 'Data' is block 1*/
0140     l2c = edac_device_alloc_ctl_info(0, "l2c", num_tads, "l2c", 2, 0,
0141                      NULL, 0, edac_device_alloc_index());
0142     if (!l2c)
0143         return -ENOMEM;
0144 
0145     l2c->dev = &pdev->dev;
0146     platform_set_drvdata(pdev, l2c);
0147     l2c->dev_name = dev_name(&pdev->dev);
0148 
0149     l2c->mod_name = "octeon-l2c";
0150     l2c->ctl_name = "octeon_l2c_err";
0151 
0152 
0153     if (OCTEON_IS_OCTEON1PLUS()) {
0154         union cvmx_l2t_err l2t_err;
0155         union cvmx_l2d_err l2d_err;
0156 
0157         l2t_err.u64 = cvmx_read_csr(CVMX_L2T_ERR);
0158         l2t_err.s.sec_intena = 0;   /* We poll */
0159         l2t_err.s.ded_intena = 0;
0160         cvmx_write_csr(CVMX_L2T_ERR, l2t_err.u64);
0161 
0162         l2d_err.u64 = cvmx_read_csr(CVMX_L2D_ERR);
0163         l2d_err.s.sec_intena = 0;   /* We poll */
0164         l2d_err.s.ded_intena = 0;
0165         cvmx_write_csr(CVMX_L2T_ERR, l2d_err.u64);
0166 
0167         l2c->edac_check = octeon_l2c_poll_oct1;
0168     } else {
0169         /* OCTEON II */
0170         l2c->edac_check = octeon_l2c_poll_oct2;
0171     }
0172 
0173     if (edac_device_add_device(l2c) > 0) {
0174         pr_err("%s: edac_device_add_device() failed\n", __func__);
0175         goto err;
0176     }
0177 
0178 
0179     return 0;
0180 
0181 err:
0182     edac_device_free_ctl_info(l2c);
0183 
0184     return -ENXIO;
0185 }
0186 
0187 static int octeon_l2c_remove(struct platform_device *pdev)
0188 {
0189     struct edac_device_ctl_info *l2c = platform_get_drvdata(pdev);
0190 
0191     edac_device_del_device(&pdev->dev);
0192     edac_device_free_ctl_info(l2c);
0193 
0194     return 0;
0195 }
0196 
0197 static struct platform_driver octeon_l2c_driver = {
0198     .probe = octeon_l2c_probe,
0199     .remove = octeon_l2c_remove,
0200     .driver = {
0201            .name = "octeon_l2c_edac",
0202     }
0203 };
0204 module_platform_driver(octeon_l2c_driver);
0205 
0206 MODULE_LICENSE("GPL");
0207 MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");