| Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * edac_module.c | 
 | 3 |  * | 
| Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 4 |  * (C) 2007 www.softwarebitmaker.com | 
 | 5 |  * | 
| Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 6 |  * 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 Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 10 |  * Author: Doug Thompson <dougthompson@xmission.com> | 
| Dave Jiang | 81d87cb | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 11 |  * | 
 | 12 |  */ | 
| Dave Jiang | c0d1217 | 2007-07-19 01:49:46 -0700 | [diff] [blame] | 13 | #include <linux/edac.h> | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 14 |  | 
| Douglas Thompson | 20bcb7a | 2007-07-19 01:49:47 -0700 | [diff] [blame] | 15 | #include "edac_core.h" | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 16 | #include "edac_module.h" | 
 | 17 |  | 
| Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 18 | #define EDAC_VERSION "Ver: 2.1.0 " __DATE__ | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 19 |  | 
 | 20 | #ifdef CONFIG_EDAC_DEBUG | 
 | 21 | /* Values of 0 to 4 will generate output */ | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 22 | int edac_debug_level = 2; | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 23 | EXPORT_SYMBOL_GPL(edac_debug_level); | 
 | 24 | #endif | 
 | 25 |  | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 26 | /* scope is to module level only */ | 
 | 27 | struct workqueue_struct *edac_workqueue; | 
 | 28 |  | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 29 | /* | 
 | 30 |  * sysfs object: /sys/devices/system/edac | 
 | 31 |  *	need to export to other files in this modules | 
 | 32 |  */ | 
 | 33 | static struct sysdev_class edac_class = { | 
| Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 34 | 	.name = "edac", | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 35 | }; | 
| Douglas Thompson | f044091 | 2007-07-19 01:50:19 -0700 | [diff] [blame] | 36 | static int edac_class_valid; | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 37 |  | 
 | 38 | /* | 
| Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 39 |  * edac_op_state_to_string() | 
| Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 40 |  */ | 
| Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 41 | char *edac_op_state_to_string(int opstate) | 
| Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 42 | { | 
 | 43 | 	if (opstate == OP_RUNNING_POLL) | 
 | 44 | 		return "POLLED"; | 
 | 45 | 	else if (opstate == OP_RUNNING_INTERRUPT) | 
 | 46 | 		return "INTERRUPT"; | 
 | 47 | 	else if (opstate == OP_RUNNING_POLL_INTR) | 
 | 48 | 		return "POLL-INTR"; | 
 | 49 | 	else if (opstate == OP_ALLOC) | 
 | 50 | 		return "ALLOC"; | 
 | 51 | 	else if (opstate == OP_OFFLINE) | 
 | 52 | 		return "OFFLINE"; | 
 | 53 |  | 
 | 54 | 	return "UNKNOWN"; | 
 | 55 | } | 
 | 56 |  | 
 | 57 | /* | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 58 |  * edac_get_edac_class() | 
 | 59 |  * | 
 | 60 |  *	return pointer to the edac class of 'edac' | 
 | 61 |  */ | 
 | 62 | struct sysdev_class *edac_get_edac_class(void) | 
 | 63 | { | 
| Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 64 | 	struct sysdev_class *classptr = NULL; | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 65 |  | 
 | 66 | 	if (edac_class_valid) | 
 | 67 | 		classptr = &edac_class; | 
 | 68 |  | 
 | 69 | 	return classptr; | 
 | 70 | } | 
 | 71 |  | 
 | 72 | /* | 
 | 73 |  * edac_register_sysfs_edac_name() | 
 | 74 |  * | 
 | 75 |  *	register the 'edac' into /sys/devices/system | 
 | 76 |  * | 
 | 77 |  * return: | 
 | 78 |  *	0  success | 
 | 79 |  *	!0 error | 
 | 80 |  */ | 
 | 81 | static int edac_register_sysfs_edac_name(void) | 
 | 82 | { | 
 | 83 | 	int err; | 
 | 84 |  | 
 | 85 | 	/* create the /sys/devices/system/edac directory */ | 
 | 86 | 	err = sysdev_class_register(&edac_class); | 
 | 87 |  | 
 | 88 | 	if (err) { | 
 | 89 | 		debugf1("%s() error=%d\n", __func__, err); | 
 | 90 | 		return err; | 
 | 91 | 	} | 
 | 92 |  | 
 | 93 | 	edac_class_valid = 1; | 
 | 94 | 	return 0; | 
 | 95 | } | 
 | 96 |  | 
 | 97 | /* | 
 | 98 |  * sysdev_class_unregister() | 
 | 99 |  * | 
 | 100 |  *	unregister the 'edac' from /sys/devices/system | 
 | 101 |  */ | 
 | 102 | static void edac_unregister_sysfs_edac_name(void) | 
 | 103 | { | 
 | 104 | 	/* only if currently registered, then unregister it */ | 
 | 105 | 	if (edac_class_valid) | 
 | 106 | 		sysdev_class_unregister(&edac_class); | 
 | 107 |  | 
 | 108 | 	edac_class_valid = 0; | 
 | 109 | } | 
 | 110 |  | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 111 | /* | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 112 |  * edac_workqueue_setup | 
 | 113 |  *	initialize the edac work queue for polling operations | 
 | 114 |  */ | 
 | 115 | static int edac_workqueue_setup(void) | 
 | 116 | { | 
 | 117 | 	edac_workqueue = create_singlethread_workqueue("edac-poller"); | 
 | 118 | 	if (edac_workqueue == NULL) | 
 | 119 | 		return -ENODEV; | 
 | 120 | 	else | 
 | 121 | 		return 0; | 
 | 122 | } | 
 | 123 |  | 
 | 124 | /* | 
 | 125 |  * edac_workqueue_teardown | 
 | 126 |  *	teardown the edac workqueue | 
 | 127 |  */ | 
 | 128 | static void edac_workqueue_teardown(void) | 
 | 129 | { | 
 | 130 | 	if (edac_workqueue) { | 
 | 131 | 		flush_workqueue(edac_workqueue); | 
 | 132 | 		destroy_workqueue(edac_workqueue); | 
 | 133 | 		edac_workqueue = NULL; | 
 | 134 | 	} | 
 | 135 | } | 
 | 136 |  | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 137 | /* | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 138 |  * edac_init | 
 | 139 |  *      module initialization entry point | 
 | 140 |  */ | 
 | 141 | static int __init edac_init(void) | 
 | 142 | { | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 143 | 	int err = 0; | 
 | 144 |  | 
| Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 145 | 	edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n"); | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 146 |  | 
 | 147 | 	/* | 
 | 148 | 	 * Harvest and clear any boot/initialization PCI parity errors | 
 | 149 | 	 * | 
 | 150 | 	 * FIXME: This only clears errors logged by devices present at time of | 
| Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 151 | 	 *      module initialization.  We should also do an initial clear | 
 | 152 | 	 *      of each newly hotplugged device. | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 153 | 	 */ | 
 | 154 | 	edac_pci_clear_parity_errors(); | 
 | 155 |  | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 156 | 	/* | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 157 | 	 * perform the registration of the /sys/devices/system/edac class object | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 158 | 	 */ | 
 | 159 | 	if (edac_register_sysfs_edac_name()) { | 
 | 160 | 		edac_printk(KERN_ERR, EDAC_MC, | 
| Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 161 | 			"Error initializing 'edac' kobject\n"); | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 162 | 		err = -ENODEV; | 
 | 163 | 		goto error; | 
 | 164 | 	} | 
 | 165 |  | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 166 | 	/* | 
 | 167 | 	 * now set up the mc_kset under the edac class object | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 168 | 	 */ | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 169 | 	err = edac_sysfs_setup_mc_kset(); | 
 | 170 | 	if (err) | 
 | 171 | 		goto sysfs_setup_fail; | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 172 |  | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 173 | 	/* Setup/Initialize the workq for this core */ | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 174 | 	err = edac_workqueue_setup(); | 
 | 175 | 	if (err) { | 
 | 176 | 		edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n"); | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 177 | 		goto workq_fail; | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 178 | 	} | 
 | 179 |  | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 180 | 	return 0; | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 181 |  | 
 | 182 | 	/* Error teardown stack */ | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 183 | workq_fail: | 
 | 184 | 	edac_sysfs_teardown_mc_kset(); | 
 | 185 |  | 
 | 186 | sysfs_setup_fail: | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 187 | 	edac_unregister_sysfs_edac_name(); | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 188 |  | 
| Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 189 | error: | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 190 | 	return err; | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 191 | } | 
 | 192 |  | 
 | 193 | /* | 
 | 194 |  * edac_exit() | 
 | 195 |  *      module exit/termination function | 
 | 196 |  */ | 
 | 197 | static void __exit edac_exit(void) | 
 | 198 | { | 
 | 199 | 	debugf0("%s()\n", __func__); | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 200 |  | 
| Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 201 | 	/* tear down the various subsystems */ | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 202 | 	edac_workqueue_teardown(); | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 203 | 	edac_sysfs_teardown_mc_kset(); | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 204 | 	edac_unregister_sysfs_edac_name(); | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 205 | } | 
 | 206 |  | 
 | 207 | /* | 
 | 208 |  * Inform the kernel of our entry and exit points | 
 | 209 |  */ | 
 | 210 | module_init(edac_init); | 
 | 211 | module_exit(edac_exit); | 
 | 212 |  | 
 | 213 | MODULE_LICENSE("GPL"); | 
 | 214 | MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al"); | 
 | 215 | MODULE_DESCRIPTION("Core library routines for EDAC reporting"); | 
 | 216 |  | 
 | 217 | /* refer to *_sysfs.c files for parameters that are exported via sysfs */ | 
 | 218 |  | 
 | 219 | #ifdef CONFIG_EDAC_DEBUG | 
 | 220 | module_param(edac_debug_level, int, 0644); | 
 | 221 | MODULE_PARM_DESC(edac_debug_level, "Debug level"); | 
 | 222 | #endif |