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 | |
Mauro Carvalho Chehab | 5156a5f | 2012-05-10 12:43:01 -0300 | [diff] [blame] | 18 | #define EDAC_VERSION "Ver: 3.0.0" |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 19 | |
| 20 | #ifdef CONFIG_EDAC_DEBUG |
Borislav Petkov | 3792987 | 2012-09-10 16:50:54 +0200 | [diff] [blame] | 21 | |
| 22 | static int edac_set_debug_level(const char *buf, struct kernel_param *kp) |
| 23 | { |
| 24 | unsigned long val; |
| 25 | int ret; |
| 26 | |
| 27 | ret = kstrtoul(buf, 0, &val); |
| 28 | if (ret) |
| 29 | return ret; |
| 30 | |
Fabian Frederick | 6866b39 | 2014-06-09 21:20:18 +0200 | [diff] [blame^] | 31 | if (val > 4) |
Borislav Petkov | 3792987 | 2012-09-10 16:50:54 +0200 | [diff] [blame] | 32 | return -EINVAL; |
| 33 | |
| 34 | return param_set_int(buf, kp); |
| 35 | } |
| 36 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 37 | /* Values of 0 to 4 will generate output */ |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 38 | int edac_debug_level = 2; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 39 | EXPORT_SYMBOL_GPL(edac_debug_level); |
Borislav Petkov | 3792987 | 2012-09-10 16:50:54 +0200 | [diff] [blame] | 40 | |
| 41 | module_param_call(edac_debug_level, edac_set_debug_level, param_get_int, |
| 42 | &edac_debug_level, 0644); |
| 43 | MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2"); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 44 | #endif |
| 45 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 46 | /* scope is to module level only */ |
| 47 | struct workqueue_struct *edac_workqueue; |
| 48 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 49 | /* |
Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 50 | * edac_op_state_to_string() |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 51 | */ |
Douglas Thompson | 494d0d5 | 2007-07-19 01:50:21 -0700 | [diff] [blame] | 52 | char *edac_op_state_to_string(int opstate) |
Dave Jiang | 91b9904 | 2007-07-19 01:49:52 -0700 | [diff] [blame] | 53 | { |
| 54 | if (opstate == OP_RUNNING_POLL) |
| 55 | return "POLLED"; |
| 56 | else if (opstate == OP_RUNNING_INTERRUPT) |
| 57 | return "INTERRUPT"; |
| 58 | else if (opstate == OP_RUNNING_POLL_INTR) |
| 59 | return "POLL-INTR"; |
| 60 | else if (opstate == OP_ALLOC) |
| 61 | return "ALLOC"; |
| 62 | else if (opstate == OP_OFFLINE) |
| 63 | return "OFFLINE"; |
| 64 | |
| 65 | return "UNKNOWN"; |
| 66 | } |
| 67 | |
| 68 | /* |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 69 | * edac_workqueue_setup |
| 70 | * initialize the edac work queue for polling operations |
| 71 | */ |
| 72 | static int edac_workqueue_setup(void) |
| 73 | { |
| 74 | edac_workqueue = create_singlethread_workqueue("edac-poller"); |
| 75 | if (edac_workqueue == NULL) |
| 76 | return -ENODEV; |
| 77 | else |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * edac_workqueue_teardown |
| 83 | * teardown the edac workqueue |
| 84 | */ |
| 85 | static void edac_workqueue_teardown(void) |
| 86 | { |
| 87 | if (edac_workqueue) { |
| 88 | flush_workqueue(edac_workqueue); |
| 89 | destroy_workqueue(edac_workqueue); |
| 90 | edac_workqueue = NULL; |
| 91 | } |
| 92 | } |
| 93 | |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 94 | /* |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 95 | * edac_init |
| 96 | * module initialization entry point |
| 97 | */ |
| 98 | static int __init edac_init(void) |
| 99 | { |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 100 | int err = 0; |
| 101 | |
Doug Thompson | fb3fb20 | 2007-07-19 01:50:30 -0700 | [diff] [blame] | 102 | edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n"); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 103 | |
| 104 | /* |
| 105 | * Harvest and clear any boot/initialization PCI parity errors |
| 106 | * |
| 107 | * FIXME: This only clears errors logged by devices present at time of |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 108 | * module initialization. We should also do an initial clear |
| 109 | * of each newly hotplugged device. |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 110 | */ |
| 111 | edac_pci_clear_parity_errors(); |
| 112 | |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 113 | err = edac_mc_sysfs_init(); |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 114 | if (err) |
Borislav Petkov | 30e1f7a | 2010-09-02 17:26:48 +0200 | [diff] [blame] | 115 | goto error; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 116 | |
Rob Herring | e7930ba | 2012-06-11 21:32:12 -0500 | [diff] [blame] | 117 | edac_debugfs_init(); |
| 118 | |
Doug Thompson | 8096cfa | 2007-07-19 01:50:27 -0700 | [diff] [blame] | 119 | /* Setup/Initialize the workq for this core */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 120 | err = edac_workqueue_setup(); |
| 121 | if (err) { |
| 122 | edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n"); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 123 | goto error; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 126 | return 0; |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 127 | |
Douglas Thompson | 052dfb4 | 2007-07-19 01:50:13 -0700 | [diff] [blame] | 128 | error: |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 129 | return err; |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /* |
| 133 | * edac_exit() |
| 134 | * module exit/termination function |
| 135 | */ |
| 136 | static void __exit edac_exit(void) |
| 137 | { |
Joe Perches | 956b9ba1 | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 138 | edac_dbg(0, "\n"); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 139 | |
Douglas Thompson | 079708b | 2007-07-19 01:49:58 -0700 | [diff] [blame] | 140 | /* tear down the various subsystems */ |
Douglas Thompson | e27e3da | 2007-07-19 01:49:36 -0700 | [diff] [blame] | 141 | edac_workqueue_teardown(); |
Mauro Carvalho Chehab | 7a623c0 | 2012-04-16 16:41:11 -0300 | [diff] [blame] | 142 | edac_mc_sysfs_exit(); |
Rob Herring | e7930ba | 2012-06-11 21:32:12 -0500 | [diff] [blame] | 143 | edac_debugfs_exit(); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Inform the kernel of our entry and exit points |
| 148 | */ |
Mauro Carvalho Chehab | 4ab19b0 | 2013-02-15 07:57:50 -0300 | [diff] [blame] | 149 | subsys_initcall(edac_init); |
Douglas Thompson | 7c9281d | 2007-07-19 01:49:33 -0700 | [diff] [blame] | 150 | module_exit(edac_exit); |
| 151 | |
| 152 | MODULE_LICENSE("GPL"); |
| 153 | MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al"); |
| 154 | MODULE_DESCRIPTION("Core library routines for EDAC reporting"); |