edac_module.c 5.5 KB

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