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