blob: 58a28d838f37bfef26450bacdf11c8a338f6dcc7 [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
21/* Values of 0 to 4 will generate output */
Doug Thompson8096cfa2007-07-19 01:50:27 -070022int edac_debug_level = 2;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070023EXPORT_SYMBOL_GPL(edac_debug_level);
24#endif
25
Douglas Thompsone27e3da2007-07-19 01:49:36 -070026/* scope is to module level only */
27struct workqueue_struct *edac_workqueue;
28
Douglas Thompsone27e3da2007-07-19 01:49:36 -070029/*
Douglas Thompson494d0d52007-07-19 01:50:21 -070030 * edac_op_state_to_string()
Dave Jiang91b99042007-07-19 01:49:52 -070031 */
Douglas Thompson494d0d52007-07-19 01:50:21 -070032char *edac_op_state_to_string(int opstate)
Dave Jiang91b99042007-07-19 01:49:52 -070033{
34 if (opstate == OP_RUNNING_POLL)
35 return "POLLED";
36 else if (opstate == OP_RUNNING_INTERRUPT)
37 return "INTERRUPT";
38 else if (opstate == OP_RUNNING_POLL_INTR)
39 return "POLL-INTR";
40 else if (opstate == OP_ALLOC)
41 return "ALLOC";
42 else if (opstate == OP_OFFLINE)
43 return "OFFLINE";
44
45 return "UNKNOWN";
46}
47
48/*
Douglas Thompsone27e3da2007-07-19 01:49:36 -070049 * edac_workqueue_setup
50 * initialize the edac work queue for polling operations
51 */
52static int edac_workqueue_setup(void)
53{
54 edac_workqueue = create_singlethread_workqueue("edac-poller");
55 if (edac_workqueue == NULL)
56 return -ENODEV;
57 else
58 return 0;
59}
60
61/*
62 * edac_workqueue_teardown
63 * teardown the edac workqueue
64 */
65static void edac_workqueue_teardown(void)
66{
67 if (edac_workqueue) {
68 flush_workqueue(edac_workqueue);
69 destroy_workqueue(edac_workqueue);
70 edac_workqueue = NULL;
71 }
72}
73
Douglas Thompsone27e3da2007-07-19 01:49:36 -070074/*
Douglas Thompson7c9281d2007-07-19 01:49:33 -070075 * edac_init
76 * module initialization entry point
77 */
78static int __init edac_init(void)
79{
Douglas Thompsone27e3da2007-07-19 01:49:36 -070080 int err = 0;
81
Doug Thompsonfb3fb202007-07-19 01:50:30 -070082 edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -070083
84 /*
85 * Harvest and clear any boot/initialization PCI parity errors
86 *
87 * FIXME: This only clears errors logged by devices present at time of
Douglas Thompson079708b2007-07-19 01:49:58 -070088 * module initialization. We should also do an initial clear
89 * of each newly hotplugged device.
Douglas Thompson7c9281d2007-07-19 01:49:33 -070090 */
91 edac_pci_clear_parity_errors();
92
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -030093 err = edac_mc_sysfs_init();
Doug Thompson8096cfa2007-07-19 01:50:27 -070094 if (err)
Borislav Petkov30e1f7a2010-09-02 17:26:48 +020095 goto error;
Douglas Thompson7c9281d2007-07-19 01:49:33 -070096
Rob Herringe7930ba2012-06-11 21:32:12 -050097 edac_debugfs_init();
98
Doug Thompson8096cfa2007-07-19 01:50:27 -070099 /* Setup/Initialize the workq for this core */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700100 err = edac_workqueue_setup();
101 if (err) {
102 edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300103 goto error;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700104 }
105
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700106 return 0;
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700107
Douglas Thompson052dfb42007-07-19 01:50:13 -0700108error:
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700109 return err;
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700110}
111
112/*
113 * edac_exit()
114 * module exit/termination function
115 */
116static void __exit edac_exit(void)
117{
Joe Perches956b9ba2012-04-29 17:08:39 -0300118 edac_dbg(0, "\n");
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700119
Douglas Thompson079708b2007-07-19 01:49:58 -0700120 /* tear down the various subsystems */
Douglas Thompsone27e3da2007-07-19 01:49:36 -0700121 edac_workqueue_teardown();
Mauro Carvalho Chehab7a623c02012-04-16 16:41:11 -0300122 edac_mc_sysfs_exit();
Rob Herringe7930ba2012-06-11 21:32:12 -0500123 edac_debugfs_exit();
Douglas Thompson7c9281d2007-07-19 01:49:33 -0700124}
125
126/*
127 * Inform the kernel of our entry and exit points
128 */
129module_init(edac_init);
130module_exit(edac_exit);
131
132MODULE_LICENSE("GPL");
133MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
134MODULE_DESCRIPTION("Core library routines for EDAC reporting");
135
136/* refer to *_sysfs.c files for parameters that are exported via sysfs */
137
138#ifdef CONFIG_EDAC_DEBUG
139module_param(edac_debug_level, int, 0644);
140MODULE_PARM_DESC(edac_debug_level, "Debug level");
141#endif