]> Git Repo - linux.git/blame - drivers/edac/edac_module.c
drivers/edac-new-i82443bxgz-mc-driver: mark as broken
[linux.git] / drivers / edac / edac_module.c
CommitLineData
7c9281d7
DT
1
2#include <linux/freezer.h>
3#include <linux/kthread.h>
4
5#include "edac_mc.h"
6#include "edac_module.h"
7
8#define EDAC_MC_VERSION "Ver: 2.0.3" __DATE__
9
10#ifdef CONFIG_EDAC_DEBUG
11/* Values of 0 to 4 will generate output */
12int edac_debug_level = 1;
13EXPORT_SYMBOL_GPL(edac_debug_level);
14#endif
15
e27e3dac
DT
16/* scope is to module level only */
17struct workqueue_struct *edac_workqueue;
18
19/* private to this file */
7c9281d7
DT
20static struct task_struct *edac_thread;
21
e27e3dac
DT
22
23/*
24 * sysfs object: /sys/devices/system/edac
25 * need to export to other files in this modules
26 */
27static struct sysdev_class edac_class = {
28 set_kset_name("edac"),
29};
30static int edac_class_valid = 0;
31
32/*
33 * edac_get_edac_class()
34 *
35 * return pointer to the edac class of 'edac'
36 */
37struct sysdev_class *edac_get_edac_class(void)
38{
39 struct sysdev_class *classptr=NULL;
40
41 if (edac_class_valid)
42 classptr = &edac_class;
43
44 return classptr;
45}
46
47/*
48 * edac_register_sysfs_edac_name()
49 *
50 * register the 'edac' into /sys/devices/system
51 *
52 * return:
53 * 0 success
54 * !0 error
55 */
56static int edac_register_sysfs_edac_name(void)
57{
58 int err;
59
60 /* create the /sys/devices/system/edac directory */
61 err = sysdev_class_register(&edac_class);
62
63 if (err) {
64 debugf1("%s() error=%d\n", __func__, err);
65 return err;
66 }
67
68 edac_class_valid = 1;
69 return 0;
70}
71
72/*
73 * sysdev_class_unregister()
74 *
75 * unregister the 'edac' from /sys/devices/system
76 */
77static void edac_unregister_sysfs_edac_name(void)
78{
79 /* only if currently registered, then unregister it */
80 if (edac_class_valid)
81 sysdev_class_unregister(&edac_class);
82
83 edac_class_valid = 0;
84}
85
86
7c9281d7
DT
87/*
88 * Check MC status every edac_get_poll_msec().
89 * Check PCI status every edac_get_poll_msec() as well.
90 *
91 * This where the work gets done for edac.
92 *
93 * SMP safe, doesn't use NMI, and auto-rate-limits.
94 */
95static void do_edac_check(void)
96{
97 debugf3("%s()\n", __func__);
98
99 /* perform the poll activities */
100 edac_check_mc_devices();
101 edac_pci_do_parity_check();
102}
103
104/*
105 * Action thread for EDAC to perform the POLL operations
106 */
107static int edac_kernel_thread(void *arg)
108{
109 int msec;
110
111 while (!kthread_should_stop()) {
112
113 do_edac_check();
114
115 /* goto sleep for the interval */
116 msec = (HZ * edac_get_poll_msec()) / 1000;
117 schedule_timeout_interruptible(msec);
118 try_to_freeze();
119 }
120
121 return 0;
122}
123
e27e3dac
DT
124/*
125 * edac_workqueue_setup
126 * initialize the edac work queue for polling operations
127 */
128static int edac_workqueue_setup(void)
129{
130 edac_workqueue = create_singlethread_workqueue("edac-poller");
131 if (edac_workqueue == NULL)
132 return -ENODEV;
133 else
134 return 0;
135}
136
137/*
138 * edac_workqueue_teardown
139 * teardown the edac workqueue
140 */
141static void edac_workqueue_teardown(void)
142{
143 if (edac_workqueue) {
144 flush_workqueue(edac_workqueue);
145 destroy_workqueue(edac_workqueue);
146 edac_workqueue = NULL;
147 }
148}
149
150
7c9281d7
DT
151/*
152 * edac_init
153 * module initialization entry point
154 */
155static int __init edac_init(void)
156{
e27e3dac
DT
157 int err = 0;
158
7c9281d7
DT
159 edac_printk(KERN_INFO, EDAC_MC, EDAC_MC_VERSION "\n");
160
161 /*
162 * Harvest and clear any boot/initialization PCI parity errors
163 *
164 * FIXME: This only clears errors logged by devices present at time of
165 * module initialization. We should also do an initial clear
166 * of each newly hotplugged device.
167 */
168 edac_pci_clear_parity_errors();
169
e27e3dac
DT
170 /*
171 * perform the registration of the /sys/devices/system/edac object
172 */
173 if (edac_register_sysfs_edac_name()) {
174 edac_printk(KERN_ERR, EDAC_MC,
175 "Error initializing 'edac' kobject\n");
176 err = -ENODEV;
177 goto error;
178 }
179
180 /* Create the MC sysfs entries, must be first
181 */
7c9281d7
DT
182 if (edac_sysfs_memctrl_setup()) {
183 edac_printk(KERN_ERR, EDAC_MC,
184 "Error initializing sysfs code\n");
e27e3dac
DT
185 err = -ENODEV;
186 goto error_sysfs;
7c9281d7
DT
187 }
188
189 /* Create the PCI parity sysfs entries */
190 if (edac_sysfs_pci_setup()) {
7c9281d7
DT
191 edac_printk(KERN_ERR, EDAC_MC,
192 "PCI: Error initializing sysfs code\n");
e27e3dac
DT
193 err = -ENODEV;
194 goto error_mem;
195 }
196
197 /* Setup/Initialize the edac_device system */
198 err = edac_workqueue_setup();
199 if (err) {
200 edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
201 goto error_pci;
7c9281d7
DT
202 }
203
204 /* create our kernel thread */
205 edac_thread = kthread_run(edac_kernel_thread, NULL, "kedac");
206
207 if (IS_ERR(edac_thread)) {
e27e3dac
DT
208 err = PTR_ERR(edac_thread);
209 goto error_work;
7c9281d7
DT
210 }
211
212 return 0;
e27e3dac
DT
213
214 /* Error teardown stack */
215error_work:
216 edac_workqueue_teardown();
217error_pci:
218 edac_sysfs_pci_teardown();
219error_mem:
220 edac_sysfs_memctrl_teardown();
221error_sysfs:
222 edac_unregister_sysfs_edac_name();
223error:
224 return err;
7c9281d7
DT
225}
226
227/*
228 * edac_exit()
229 * module exit/termination function
230 */
231static void __exit edac_exit(void)
232{
233 debugf0("%s()\n", __func__);
234 kthread_stop(edac_thread);
235
e27e3dac
DT
236 /* tear down the various subsystems*/
237 edac_workqueue_teardown();
7c9281d7
DT
238 edac_sysfs_memctrl_teardown();
239 edac_sysfs_pci_teardown();
e27e3dac 240 edac_unregister_sysfs_edac_name();
7c9281d7
DT
241}
242
243/*
244 * Inform the kernel of our entry and exit points
245 */
246module_init(edac_init);
247module_exit(edac_exit);
248
249MODULE_LICENSE("GPL");
250MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
251MODULE_DESCRIPTION("Core library routines for EDAC reporting");
252
253/* refer to *_sysfs.c files for parameters that are exported via sysfs */
254
255#ifdef CONFIG_EDAC_DEBUG
256module_param(edac_debug_level, int, 0644);
257MODULE_PARM_DESC(edac_debug_level, "Debug level");
258#endif
259
This page took 0.058564 seconds and 4 git commands to generate.