blob: 5f8543be995ab6584ffe479558133de016649194 [file] [log] [blame]
Dave Jiang81d87cb2007-07-19 01:49:52 -07001/*
2 * edac_module.c
3 *
Doug Thompsonfb3fb202007-07-19 01:50:30 -07004 * (C) 2007 www.softwarebitmaker.com
5 *
Dave Jiang81d87cb2007-07-19 01:49:52 -07006 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 *
Doug Thompsonfb3fb202007-07-19 01:50:30 -070010 * Author: Doug Thompson <dougthompson@xmission.com>
Dave Jiang81d87cb2007-07-19 01:49:52 -070011 *
12 */
Dave Jiangc0d12172007-07-19 01:49:46 -070013#include <linux/edac.h>
Douglas Thompson7c9281d2007-07-19 01:49:33 -070014
Douglas Thompson20bcb7a2007-07-19 01:49:47 -070015#include "edac_core.h"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070016#include "edac_module.h"
17
Mauro Carvalho Chehab5156a5f2012-05-10 12:43:01 -030018#define EDAC_VERSION "Ver: 3.0.0"
Douglas Thompson7c9281d2007-07-19 01:49:33 -070019
20#ifdef CONFIG_EDAC_DEBUG
Borislav Petkov37929872012-09-10 16:50:54 +020021
22static int edac_set_debug_level(const char *buf, struct kernel_param *kp)
23{
24 unsigned long val;
25 int ret;
26
27 ret = kstrtoul(buf, 0, &val);
28 if (ret)
29 return ret;
30
Fabian Frederick6866b392014-06-09 21:20:18 +020031 if (val > 4)
Borislav Petkov37929872012-09-10 16:50:54 +020032 return -EINVAL;
33
34 return param_set_int(buf, kp);
35}
36
Douglas Thompson7c9281d2007-07-19 01:49:33 -070037/* Values of 0 to 4 will generate output */
Doug Thompson8096cfa2007-07-19 01:50:27 -070038int edac_debug_level = 2;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070039EXPORT_SYMBOL_GPL(edac_debug_level);
Borislav Petkov37929872012-09-10 16:50:54 +020040
41module_param_call(edac_debug_level, edac_set_debug_level, param_get_int,
42 &edac_debug_level, 0644);
43MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2");
Douglas Thompson7c9281d2007-07-19 01:49:33 -070044#endif
45
Douglas Thompsone27e3da2007-07-19 01:49:36 -070046/*
Douglas Thompson494d0d52007-07-19 01:50:21 -070047 * edac_op_state_to_string()
Dave Jiang91b99042007-07-19 01:49:52 -070048 */
Douglas Thompson494d0d52007-07-19 01:50:21 -070049char *edac_op_state_to_string(int opstate)
Dave Jiang91b99042007-07-19 01:49:52 -070050{
51 if (opstate == OP_RUNNING_POLL)
52 return "POLLED";
53 else if (opstate == OP_RUNNING_INTERRUPT)
54 return "INTERRUPT";
55 else if (opstate == OP_RUNNING_POLL_INTR)
56 return "POLL-INTR";
57 else if (opstate == OP_ALLOC)
58 return "ALLOC";
59 else if (opstate == OP_OFFLINE)
60 return "OFFLINE";
61
62 return "UNKNOWN";
63}
64
65/*
Borislav Petkov733476c2015-11-27 11:40:43 +010066 * sysfs object: /sys/devices/system/edac
67 * need to export to other files
68 */
Borislav Petkova97d2622015-11-30 14:15:31 +010069static struct bus_type edac_subsys = {
Borislav Petkov733476c2015-11-27 11:40:43 +010070 .name = "edac",
71 .dev_name = "edac",
72};
Borislav Petkov733476c2015-11-27 11:40:43 +010073
74static int edac_subsys_init(void)
75{
76 int err;
77
78 /* create the /sys/devices/system/edac directory */
79 err = subsys_system_register(&edac_subsys, NULL);
80 if (err)
81 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
82
83 return err;
84}
85
86static void edac_subsys_exit(void)
87{
88 bus_unregister(&edac_subsys);
89}
90
91/* return pointer to the 'edac' node in sysfs */
92struct bus_type *edac_get_sysfs_subsys(void)
93{
94 return &edac_subsys;
95}
96EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
97/*
Douglas Thompson7c9281d2007-07-19 01:49:33 -070098 * edac_init
99 * module initialization entry point
100 */
101static int __init edac_init(void)
102{
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700103 int err = 0;
104
Doug Thompsonfb3fb202007-07-19 01:50:30 -0700105 edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700106
Borislav Petkov733476c2015-11-27 11:40:43 +0100107 err = edac_subsys_init();
108 if (err)
109 return err;
110
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700111 /*
112 * Harvest and clear any boot/initialization PCI parity errors
113 *
114 * FIXME: This only clears errors logged by devices present at time of
Douglas Thompson079708b2007-07-19 01:49:58 -0700115 * module initialization. We should also do an initial clear
116 * of each newly hotplugged device.
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700117 */
118 edac_pci_clear_parity_errors();
119
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300120 err = edac_mc_sysfs_init();
Doug Thompson8096cfa2007-07-19 01:50:27 -0700121 if (err)
Alexey Khoroshilovc6b97bc2015-02-05 22:12:42 -0800122 goto err_sysfs;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700123
Rob Herringe7930ba2012-06-11 21:32:12 -0500124 edac_debugfs_init();
125
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700126 err = edac_workqueue_setup();
127 if (err) {
Alexey Khoroshilovc6b97bc2015-02-05 22:12:42 -0800128 edac_printk(KERN_ERR, EDAC_MC, "Failure initializing workqueue\n");
129 goto err_wq;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700130 }
131
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700132 return 0;
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700133
Alexey Khoroshilovc6b97bc2015-02-05 22:12:42 -0800134err_wq:
135 edac_debugfs_exit();
136 edac_mc_sysfs_exit();
137
138err_sysfs:
Borislav Petkov733476c2015-11-27 11:40:43 +0100139 edac_subsys_exit();
140
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700141 return err;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700142}
143
144/*
145 * edac_exit()
146 * module exit/termination function
147 */
148static void __exit edac_exit(void)
149{
Joe Perches956b9ba12012-04-29 17:08:39 -0300150 edac_dbg(0, "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700151
Douglas Thompson079708b2007-07-19 01:49:58 -0700152 /* tear down the various subsystems */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700153 edac_workqueue_teardown();
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300154 edac_mc_sysfs_exit();
Rob Herringe7930ba2012-06-11 21:32:12 -0500155 edac_debugfs_exit();
Borislav Petkov733476c2015-11-27 11:40:43 +0100156 edac_subsys_exit();
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700157}
158
159/*
160 * Inform the kernel of our entry and exit points
161 */
Mauro Carvalho Chehab4ab19b02013-02-15 07:57:50 -0300162subsys_initcall(edac_init);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700163module_exit(edac_exit);
164
165MODULE_LICENSE("GPL");
166MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
167MODULE_DESCRIPTION("Core library routines for EDAC reporting");