| 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 | /* | 
| Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 30 |  * edac_op_state_to_string() | 
| Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 31 |  */ | 
| Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 32 | char *edac_op_state_to_string(int opstate) | 
| Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 33 | { | 
 | 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 Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 49 |  * edac_workqueue_setup | 
 | 50 |  *	initialize the edac work queue for polling operations | 
 | 51 |  */ | 
 | 52 | static 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 |  */ | 
 | 65 | static 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 Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 74 | /* | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 75 |  * edac_init | 
 | 76 |  *      module initialization entry point | 
 | 77 |  */ | 
 | 78 | static int __init edac_init(void) | 
 | 79 | { | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 80 | 	int err = 0; | 
 | 81 |  | 
| Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 82 | 	edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n"); | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 83 |  | 
 | 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 Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 88 | 	 *      module initialization.  We should also do an initial clear | 
 | 89 | 	 *      of each newly hotplugged device. | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 90 | 	 */ | 
 | 91 | 	edac_pci_clear_parity_errors(); | 
 | 92 |  | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 93 | 	/* | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 94 | 	 * now set up the mc_kset under the edac class object | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 95 | 	 */ | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 96 | 	err = edac_sysfs_setup_mc_kset(); | 
 | 97 | 	if (err) | 
| Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 98 | 		goto error; | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 99 |  | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 100 | 	/* Setup/Initialize the workq for this core */ | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 101 | 	err = edac_workqueue_setup(); | 
 | 102 | 	if (err) { | 
 | 103 | 		edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n"); | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 104 | 		goto workq_fail; | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 105 | 	} | 
 | 106 |  | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 107 | 	return 0; | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 108 |  | 
 | 109 | 	/* Error teardown stack */ | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 110 | workq_fail: | 
 | 111 | 	edac_sysfs_teardown_mc_kset(); | 
 | 112 |  | 
| Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 113 | error: | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 114 | 	return err; | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 115 | } | 
 | 116 |  | 
 | 117 | /* | 
 | 118 |  * edac_exit() | 
 | 119 |  *      module exit/termination function | 
 | 120 |  */ | 
 | 121 | static void __exit edac_exit(void) | 
 | 122 | { | 
 | 123 | 	debugf0("%s()\n", __func__); | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 124 |  | 
| Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 125 | 	/* tear down the various subsystems */ | 
| Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 126 | 	edac_workqueue_teardown(); | 
| Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 127 | 	edac_sysfs_teardown_mc_kset(); | 
| Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 128 | } | 
 | 129 |  | 
 | 130 | /* | 
 | 131 |  * Inform the kernel of our entry and exit points | 
 | 132 |  */ | 
 | 133 | module_init(edac_init); | 
 | 134 | module_exit(edac_exit); | 
 | 135 |  | 
 | 136 | MODULE_LICENSE("GPL"); | 
 | 137 | MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al"); | 
 | 138 | MODULE_DESCRIPTION("Core library routines for EDAC reporting"); | 
 | 139 |  | 
 | 140 | /* refer to *_sysfs.c files for parameters that are exported via sysfs */ | 
 | 141 |  | 
 | 142 | #ifdef CONFIG_EDAC_DEBUG | 
 | 143 | module_param(edac_debug_level, int, 0644); | 
 | 144 | MODULE_PARM_DESC(edac_debug_level, "Debug level"); | 
 | 145 | #endif |