edac_module.c 4.4 KB

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