xref: /openbmc/linux/drivers/edac/octeon_edac-pc.c (revision 78d88e8a)
1f65aad41SRalf Baechle /*
2f65aad41SRalf Baechle  * This file is subject to the terms and conditions of the GNU General Public
3f65aad41SRalf Baechle  * License.  See the file "COPYING" in the main directory of this archive
4f65aad41SRalf Baechle  * for more details.
5f65aad41SRalf Baechle  *
6e1ced097SDavid Daney  * Copyright (C) 2012 Cavium, Inc.
7e1ced097SDavid Daney  *
8f65aad41SRalf Baechle  * Copyright (C) 2009 Wind River Systems,
9f65aad41SRalf Baechle  *   written by Ralf Baechle <ralf@linux-mips.org>
10f65aad41SRalf Baechle  */
11f65aad41SRalf Baechle #include <linux/module.h>
12f65aad41SRalf Baechle #include <linux/init.h>
13f65aad41SRalf Baechle #include <linux/slab.h>
14f65aad41SRalf Baechle #include <linux/interrupt.h>
15f65aad41SRalf Baechle #include <linux/io.h>
16f65aad41SRalf Baechle #include <linux/edac.h>
17f65aad41SRalf Baechle 
18f65aad41SRalf Baechle #include "edac_module.h"
19f65aad41SRalf Baechle 
20f65aad41SRalf Baechle #include <asm/octeon/cvmx.h>
21f65aad41SRalf Baechle #include <asm/mipsregs.h>
22f65aad41SRalf Baechle 
23f65aad41SRalf Baechle extern int register_co_cache_error_notifier(struct notifier_block *nb);
24f65aad41SRalf Baechle extern int unregister_co_cache_error_notifier(struct notifier_block *nb);
25f65aad41SRalf Baechle 
26f65aad41SRalf Baechle extern unsigned long long cache_err_dcache[NR_CPUS];
27f65aad41SRalf Baechle 
28e1ced097SDavid Daney struct co_cache_error {
29e1ced097SDavid Daney 	struct notifier_block notifier;
30e1ced097SDavid Daney 	struct edac_device_ctl_info *ed;
31e1ced097SDavid Daney };
32f65aad41SRalf Baechle 
33e1ced097SDavid Daney /**
34f65aad41SRalf Baechle  * EDAC CPU cache error callback
35f65aad41SRalf Baechle  *
36e1ced097SDavid Daney  * @event: non-zero if unrecoverable.
37f65aad41SRalf Baechle  */
co_cache_error_event(struct notifier_block * this,unsigned long event,void * ptr)38f65aad41SRalf Baechle static int  co_cache_error_event(struct notifier_block *this,
39f65aad41SRalf Baechle 	unsigned long event, void *ptr)
40f65aad41SRalf Baechle {
41e1ced097SDavid Daney 	struct co_cache_error *p = container_of(this, struct co_cache_error,
42e1ced097SDavid Daney 						notifier);
43e1ced097SDavid Daney 
44f65aad41SRalf Baechle 	unsigned int core = cvmx_get_core_num();
45f65aad41SRalf Baechle 	unsigned int cpu = smp_processor_id();
46e1ced097SDavid Daney 	u64 icache_err = read_octeon_c0_icacheerr();
47e1ced097SDavid Daney 	u64 dcache_err;
48f65aad41SRalf Baechle 
49e1ced097SDavid Daney 	if (event) {
50e1ced097SDavid Daney 		dcache_err = cache_err_dcache[core];
51f65aad41SRalf Baechle 		cache_err_dcache[core] = 0;
52e1ced097SDavid Daney 	} else {
53e1ced097SDavid Daney 		dcache_err = read_octeon_c0_dcacheerr();
54f65aad41SRalf Baechle 	}
55f65aad41SRalf Baechle 
56e1ced097SDavid Daney 	if (icache_err & 1) {
57e1ced097SDavid Daney 		edac_device_printk(p->ed, KERN_ERR,
58e1ced097SDavid Daney 				   "CacheErr (Icache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
59e1ced097SDavid Daney 				   (unsigned long long)icache_err, core, cpu,
60e1ced097SDavid Daney 				   read_c0_errorepc());
61e1ced097SDavid Daney 		write_octeon_c0_icacheerr(0);
62e1ced097SDavid Daney 		edac_device_handle_ce(p->ed, cpu, 1, "icache");
63e1ced097SDavid Daney 	}
64e1ced097SDavid Daney 	if (dcache_err & 1) {
65e1ced097SDavid Daney 		edac_device_printk(p->ed, KERN_ERR,
66e1ced097SDavid Daney 				   "CacheErr (Dcache):%llx, core %d/cpu %d, cp0_errorepc == %lx\n",
67e1ced097SDavid Daney 				   (unsigned long long)dcache_err, core, cpu,
68e1ced097SDavid Daney 				   read_c0_errorepc());
69e1ced097SDavid Daney 		if (event)
70e1ced097SDavid Daney 			edac_device_handle_ue(p->ed, cpu, 0, "dcache");
71e1ced097SDavid Daney 		else
72e1ced097SDavid Daney 			edac_device_handle_ce(p->ed, cpu, 0, "dcache");
73e1ced097SDavid Daney 
74e1ced097SDavid Daney 		/* Clear the error indication */
7575a15a78SAaro Koskinen 		if (OCTEON_IS_OCTEON2())
76e1ced097SDavid Daney 			write_octeon_c0_dcacheerr(1);
77e1ced097SDavid Daney 		else
78e1ced097SDavid Daney 			write_octeon_c0_dcacheerr(0);
79f65aad41SRalf Baechle 	}
80f65aad41SRalf Baechle 
81e1ced097SDavid Daney 	return NOTIFY_STOP;
82e1ced097SDavid Daney }
83f65aad41SRalf Baechle 
co_cache_error_probe(struct platform_device * pdev)849b3c6e85SGreg Kroah-Hartman static int co_cache_error_probe(struct platform_device *pdev)
85f65aad41SRalf Baechle {
86e1ced097SDavid Daney 	struct co_cache_error *p = devm_kzalloc(&pdev->dev, sizeof(*p),
87e1ced097SDavid Daney 						GFP_KERNEL);
88e1ced097SDavid Daney 	if (!p)
89e1ced097SDavid Daney 		return -ENOMEM;
90f65aad41SRalf Baechle 
91e1ced097SDavid Daney 	p->notifier.notifier_call = co_cache_error_event;
92e1ced097SDavid Daney 	platform_set_drvdata(pdev, p);
93e1ced097SDavid Daney 
94e1ced097SDavid Daney 	p->ed = edac_device_alloc_ctl_info(0, "cpu", num_possible_cpus(),
95e1ced097SDavid Daney 					   "cache", 2, 0, NULL, 0,
96f65aad41SRalf Baechle 					   edac_device_alloc_index());
97e1ced097SDavid Daney 	if (!p->ed)
98f65aad41SRalf Baechle 		goto err;
99e1ced097SDavid Daney 
100e1ced097SDavid Daney 	p->ed->dev = &pdev->dev;
101e1ced097SDavid Daney 
102e1ced097SDavid Daney 	p->ed->dev_name = dev_name(&pdev->dev);
103e1ced097SDavid Daney 
104e1ced097SDavid Daney 	p->ed->mod_name = "octeon-cpu";
105e1ced097SDavid Daney 	p->ed->ctl_name = "cache";
106e1ced097SDavid Daney 
107e1ced097SDavid Daney 	if (edac_device_add_device(p->ed)) {
108e1ced097SDavid Daney 		pr_err("%s: edac_device_add_device() failed\n", __func__);
109e1ced097SDavid Daney 		goto err1;
110f65aad41SRalf Baechle 	}
111f65aad41SRalf Baechle 
112e1ced097SDavid Daney 	register_co_cache_error_notifier(&p->notifier);
113f65aad41SRalf Baechle 
114f65aad41SRalf Baechle 	return 0;
115f65aad41SRalf Baechle 
116e1ced097SDavid Daney err1:
117e1ced097SDavid Daney 	edac_device_free_ctl_info(p->ed);
118f65aad41SRalf Baechle err:
119e1ced097SDavid Daney 	return -ENXIO;
120f65aad41SRalf Baechle }
121f65aad41SRalf Baechle 
co_cache_error_remove(struct platform_device * pdev)122f65aad41SRalf Baechle static int co_cache_error_remove(struct platform_device *pdev)
123f65aad41SRalf Baechle {
124e1ced097SDavid Daney 	struct co_cache_error *p = platform_get_drvdata(pdev);
125f65aad41SRalf Baechle 
126e1ced097SDavid Daney 	unregister_co_cache_error_notifier(&p->notifier);
127f65aad41SRalf Baechle 	edac_device_del_device(&pdev->dev);
128e1ced097SDavid Daney 	edac_device_free_ctl_info(p->ed);
129f65aad41SRalf Baechle 	return 0;
130f65aad41SRalf Baechle }
131f65aad41SRalf Baechle 
132f65aad41SRalf Baechle static struct platform_driver co_cache_error_driver = {
133f65aad41SRalf Baechle 	.probe = co_cache_error_probe,
134f65aad41SRalf Baechle 	.remove = co_cache_error_remove,
135f65aad41SRalf Baechle 	.driver = {
136e1ced097SDavid Daney 		   .name = "octeon_pc_edac",
137f65aad41SRalf Baechle 	}
138f65aad41SRalf Baechle };
139e1ced097SDavid Daney module_platform_driver(co_cache_error_driver);
140f65aad41SRalf Baechle 
141f65aad41SRalf Baechle MODULE_LICENSE("GPL");
142f65aad41SRalf Baechle MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
143