blob: 32a931d0cb71ff1c262c97eb323c8894768ee423 [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
Mauro Carvalho Chehab78d88e82016-10-29 15:16:34 -020015#include "edac_mc.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
Kees Cooke4dca7b2017-10-17 19:04:42 -070022static int edac_set_debug_level(const char *buf,
23 const struct kernel_param *kp)
Borislav Petkov37929872012-09-10 16:50:54 +020024{
25 unsigned long val;
26 int ret;
27
28 ret = kstrtoul(buf, 0, &val);
29 if (ret)
30 return ret;
31
Fabian Frederick6866b392014-06-09 21:20:18 +020032 if (val > 4)
Borislav Petkov37929872012-09-10 16:50:54 +020033 return -EINVAL;
34
35 return param_set_int(buf, kp);
36}
37
Douglas Thompson7c9281d2007-07-19 01:49:33 -070038/* Values of 0 to 4 will generate output */
Doug Thompson8096cfa2007-07-19 01:50:27 -070039int edac_debug_level = 2;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070040EXPORT_SYMBOL_GPL(edac_debug_level);
Borislav Petkov37929872012-09-10 16:50:54 +020041
42module_param_call(edac_debug_level, edac_set_debug_level, param_get_int,
43 &edac_debug_level, 0644);
44MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2");
Douglas Thompson7c9281d2007-07-19 01:49:33 -070045#endif
46
Douglas Thompsone27e3da2007-07-19 01:49:36 -070047/*
Douglas Thompson494d0d52007-07-19 01:50:21 -070048 * edac_op_state_to_string()
Dave Jiang91b99042007-07-19 01:49:52 -070049 */
Douglas Thompson494d0d52007-07-19 01:50:21 -070050char *edac_op_state_to_string(int opstate)
Dave Jiang91b99042007-07-19 01:49:52 -070051{
52 if (opstate == OP_RUNNING_POLL)
53 return "POLLED";
54 else if (opstate == OP_RUNNING_INTERRUPT)
55 return "INTERRUPT";
56 else if (opstate == OP_RUNNING_POLL_INTR)
57 return "POLL-INTR";
58 else if (opstate == OP_ALLOC)
59 return "ALLOC";
60 else if (opstate == OP_OFFLINE)
61 return "OFFLINE";
62
63 return "UNKNOWN";
64}
65
66/*
Borislav Petkov733476c2015-11-27 11:40:43 +010067 * sysfs object: /sys/devices/system/edac
68 * need to export to other files
69 */
Borislav Petkova97d2622015-11-30 14:15:31 +010070static struct bus_type edac_subsys = {
Borislav Petkov733476c2015-11-27 11:40:43 +010071 .name = "edac",
72 .dev_name = "edac",
73};
Borislav Petkov733476c2015-11-27 11:40:43 +010074
75static int edac_subsys_init(void)
76{
77 int err;
78
79 /* create the /sys/devices/system/edac directory */
80 err = subsys_system_register(&edac_subsys, NULL);
81 if (err)
82 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
83
84 return err;
85}
86
87static void edac_subsys_exit(void)
88{
89 bus_unregister(&edac_subsys);
90}
91
92/* return pointer to the 'edac' node in sysfs */
93struct bus_type *edac_get_sysfs_subsys(void)
94{
95 return &edac_subsys;
96}
97EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
98/*
Douglas Thompson7c9281d2007-07-19 01:49:33 -070099 * edac_init
100 * module initialization entry point
101 */
102static int __init edac_init(void)
103{
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700104 int err = 0;
105
Doug Thompsonfb3fb202007-07-19 01:50:30 -0700106 edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700107
Borislav Petkov733476c2015-11-27 11:40:43 +0100108 err = edac_subsys_init();
109 if (err)
110 return err;
111
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700112 /*
113 * Harvest and clear any boot/initialization PCI parity errors
114 *
115 * FIXME: This only clears errors logged by devices present at time of
Douglas Thompson079708b2007-07-19 01:49:58 -0700116 * module initialization. We should also do an initial clear
117 * of each newly hotplugged device.
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700118 */
119 edac_pci_clear_parity_errors();
120
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300121 err = edac_mc_sysfs_init();
Doug Thompson8096cfa2007-07-19 01:50:27 -0700122 if (err)
Alexey Khoroshilovc6b97bc2015-02-05 22:12:42 -0800123 goto err_sysfs;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700124
Rob Herringe7930ba2012-06-11 21:32:12 -0500125 edac_debugfs_init();
126
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700127 err = edac_workqueue_setup();
128 if (err) {
Alexey Khoroshilovc6b97bc2015-02-05 22:12:42 -0800129 edac_printk(KERN_ERR, EDAC_MC, "Failure initializing workqueue\n");
130 goto err_wq;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700131 }
132
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700133 return 0;
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700134
Alexey Khoroshilovc6b97bc2015-02-05 22:12:42 -0800135err_wq:
136 edac_debugfs_exit();
137 edac_mc_sysfs_exit();
138
139err_sysfs:
Borislav Petkov733476c2015-11-27 11:40:43 +0100140 edac_subsys_exit();
141
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700142 return err;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700143}
144
145/*
146 * edac_exit()
147 * module exit/termination function
148 */
149static void __exit edac_exit(void)
150{
Joe Perches956b9ba12012-04-29 17:08:39 -0300151 edac_dbg(0, "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700152
Douglas Thompson079708b2007-07-19 01:49:58 -0700153 /* tear down the various subsystems */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700154 edac_workqueue_teardown();
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300155 edac_mc_sysfs_exit();
Rob Herringe7930ba2012-06-11 21:32:12 -0500156 edac_debugfs_exit();
Borislav Petkov733476c2015-11-27 11:40:43 +0100157 edac_subsys_exit();
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700158}
159
160/*
161 * Inform the kernel of our entry and exit points
162 */
Mauro Carvalho Chehab4ab19b02013-02-15 07:57:50 -0300163subsys_initcall(edac_init);
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700164module_exit(edac_exit);
165
166MODULE_LICENSE("GPL");
167MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
168MODULE_DESCRIPTION("Core library routines for EDAC reporting");