edac_module.c 4.4 KB

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