2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2012 Cavium, Inc.
8 * Copyright (C) 2009 Wind River Systems,
9 * written by Ralf Baechle <ralf@linux-mips.org>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
15 #include <linux/edac.h>
17 #include <asm/octeon/cvmx.h>
19 #include "edac_module.h"
21 #define EDAC_MOD_STR "octeon-l2c"
23 static void octeon_l2c_poll_oct1(struct edac_device_ctl_info
*l2c
)
25 union cvmx_l2t_err l2t_err
, l2t_err_reset
;
26 union cvmx_l2d_err l2d_err
, l2d_err_reset
;
28 l2t_err_reset
.u64
= 0;
29 l2t_err
.u64
= cvmx_read_csr(CVMX_L2T_ERR
);
30 if (l2t_err
.s
.sec_err
) {
31 edac_device_handle_ce(l2c
, 0, 0,
32 "Tag Single bit error (corrected)");
33 l2t_err_reset
.s
.sec_err
= 1;
35 if (l2t_err
.s
.ded_err
) {
36 edac_device_handle_ue(l2c
, 0, 0,
37 "Tag Double bit error (detected)");
38 l2t_err_reset
.s
.ded_err
= 1;
40 if (l2t_err_reset
.u64
)
41 cvmx_write_csr(CVMX_L2T_ERR
, l2t_err_reset
.u64
);
43 l2d_err_reset
.u64
= 0;
44 l2d_err
.u64
= cvmx_read_csr(CVMX_L2D_ERR
);
45 if (l2d_err
.s
.sec_err
) {
46 edac_device_handle_ce(l2c
, 0, 1,
47 "Data Single bit error (corrected)");
48 l2d_err_reset
.s
.sec_err
= 1;
50 if (l2d_err
.s
.ded_err
) {
51 edac_device_handle_ue(l2c
, 0, 1,
52 "Data Double bit error (detected)");
53 l2d_err_reset
.s
.ded_err
= 1;
55 if (l2d_err_reset
.u64
)
56 cvmx_write_csr(CVMX_L2D_ERR
, l2d_err_reset
.u64
);
60 static void _octeon_l2c_poll_oct2(struct edac_device_ctl_info
*l2c
, int tad
)
62 union cvmx_l2c_err_tdtx err_tdtx
, err_tdtx_reset
;
63 union cvmx_l2c_err_ttgx err_ttgx
, err_ttgx_reset
;
67 err_tdtx_reset
.u64
= 0;
68 err_tdtx
.u64
= cvmx_read_csr(CVMX_L2C_ERR_TDTX(tad
));
69 if (err_tdtx
.s
.dbe
|| err_tdtx
.s
.sbe
||
70 err_tdtx
.s
.vdbe
|| err_tdtx
.s
.vsbe
)
71 snprintf(buf1
, sizeof(buf1
),
72 "type:%d, syn:0x%x, way:%d",
73 err_tdtx
.s
.type
, err_tdtx
.s
.syn
, err_tdtx
.s
.wayidx
);
76 snprintf(buf2
, sizeof(buf2
),
77 "L2D Double bit error (detected):%s", buf1
);
78 err_tdtx_reset
.s
.dbe
= 1;
79 edac_device_handle_ue(l2c
, tad
, 1, buf2
);
82 snprintf(buf2
, sizeof(buf2
),
83 "L2D Single bit error (corrected):%s", buf1
);
84 err_tdtx_reset
.s
.sbe
= 1;
85 edac_device_handle_ce(l2c
, tad
, 1, buf2
);
87 if (err_tdtx
.s
.vdbe
) {
88 snprintf(buf2
, sizeof(buf2
),
89 "VBF Double bit error (detected):%s", buf1
);
90 err_tdtx_reset
.s
.vdbe
= 1;
91 edac_device_handle_ue(l2c
, tad
, 1, buf2
);
93 if (err_tdtx
.s
.vsbe
) {
94 snprintf(buf2
, sizeof(buf2
),
95 "VBF Single bit error (corrected):%s", buf1
);
96 err_tdtx_reset
.s
.vsbe
= 1;
97 edac_device_handle_ce(l2c
, tad
, 1, buf2
);
99 if (err_tdtx_reset
.u64
)
100 cvmx_write_csr(CVMX_L2C_ERR_TDTX(tad
), err_tdtx_reset
.u64
);
102 err_ttgx_reset
.u64
= 0;
103 err_ttgx
.u64
= cvmx_read_csr(CVMX_L2C_ERR_TTGX(tad
));
105 if (err_ttgx
.s
.dbe
|| err_ttgx
.s
.sbe
)
106 snprintf(buf1
, sizeof(buf1
),
107 "type:%d, syn:0x%x, way:%d",
108 err_ttgx
.s
.type
, err_ttgx
.s
.syn
, err_ttgx
.s
.wayidx
);
110 if (err_ttgx
.s
.dbe
) {
111 snprintf(buf2
, sizeof(buf2
),
112 "Tag Double bit error (detected):%s", buf1
);
113 err_ttgx_reset
.s
.dbe
= 1;
114 edac_device_handle_ue(l2c
, tad
, 0, buf2
);
116 if (err_ttgx
.s
.sbe
) {
117 snprintf(buf2
, sizeof(buf2
),
118 "Tag Single bit error (corrected):%s", buf1
);
119 err_ttgx_reset
.s
.sbe
= 1;
120 edac_device_handle_ce(l2c
, tad
, 0, buf2
);
122 if (err_ttgx_reset
.u64
)
123 cvmx_write_csr(CVMX_L2C_ERR_TTGX(tad
), err_ttgx_reset
.u64
);
126 static void octeon_l2c_poll_oct2(struct edac_device_ctl_info
*l2c
)
129 for (i
= 0; i
< l2c
->nr_instances
; i
++)
130 _octeon_l2c_poll_oct2(l2c
, i
);
133 static int octeon_l2c_probe(struct platform_device
*pdev
)
135 struct edac_device_ctl_info
*l2c
;
137 int num_tads
= OCTEON_IS_MODEL(OCTEON_CN68XX
) ? 4 : 1;
139 /* 'Tags' are block 0, 'Data' is block 1*/
140 l2c
= edac_device_alloc_ctl_info(0, "l2c", num_tads
, "l2c", 2, 0,
141 NULL
, 0, edac_device_alloc_index());
145 l2c
->dev
= &pdev
->dev
;
146 platform_set_drvdata(pdev
, l2c
);
147 l2c
->dev_name
= dev_name(&pdev
->dev
);
149 l2c
->mod_name
= "octeon-l2c";
150 l2c
->ctl_name
= "octeon_l2c_err";
153 if (OCTEON_IS_OCTEON1PLUS()) {
154 union cvmx_l2t_err l2t_err
;
155 union cvmx_l2d_err l2d_err
;
157 l2t_err
.u64
= cvmx_read_csr(CVMX_L2T_ERR
);
158 l2t_err
.s
.sec_intena
= 0; /* We poll */
159 l2t_err
.s
.ded_intena
= 0;
160 cvmx_write_csr(CVMX_L2T_ERR
, l2t_err
.u64
);
162 l2d_err
.u64
= cvmx_read_csr(CVMX_L2D_ERR
);
163 l2d_err
.s
.sec_intena
= 0; /* We poll */
164 l2d_err
.s
.ded_intena
= 0;
165 cvmx_write_csr(CVMX_L2T_ERR
, l2d_err
.u64
);
167 l2c
->edac_check
= octeon_l2c_poll_oct1
;
170 l2c
->edac_check
= octeon_l2c_poll_oct2
;
173 if (edac_device_add_device(l2c
) > 0) {
174 pr_err("%s: edac_device_add_device() failed\n", __func__
);
182 edac_device_free_ctl_info(l2c
);
187 static int octeon_l2c_remove(struct platform_device
*pdev
)
189 struct edac_device_ctl_info
*l2c
= platform_get_drvdata(pdev
);
191 edac_device_del_device(&pdev
->dev
);
192 edac_device_free_ctl_info(l2c
);
197 static struct platform_driver octeon_l2c_driver
= {
198 .probe
= octeon_l2c_probe
,
199 .remove
= octeon_l2c_remove
,
201 .name
= "octeon_l2c_edac",
204 module_platform_driver(octeon_l2c_driver
);
206 MODULE_LICENSE("GPL");
207 MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");