edac_module.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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: 3.0.0"
  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. * edac_op_state_to_string()
  26. */
  27. char *edac_op_state_to_string(int opstate)
  28. {
  29. if (opstate == OP_RUNNING_POLL)
  30. return "POLLED";
  31. else if (opstate == OP_RUNNING_INTERRUPT)
  32. return "INTERRUPT";
  33. else if (opstate == OP_RUNNING_POLL_INTR)
  34. return "POLL-INTR";
  35. else if (opstate == OP_ALLOC)
  36. return "ALLOC";
  37. else if (opstate == OP_OFFLINE)
  38. return "OFFLINE";
  39. return "UNKNOWN";
  40. }
  41. /*
  42. * edac_workqueue_setup
  43. * initialize the edac work queue for polling operations
  44. */
  45. static int edac_workqueue_setup(void)
  46. {
  47. edac_workqueue = create_singlethread_workqueue("edac-poller");
  48. if (edac_workqueue == NULL)
  49. return -ENODEV;
  50. else
  51. return 0;
  52. }
  53. /*
  54. * edac_workqueue_teardown
  55. * teardown the edac workqueue
  56. */
  57. static void edac_workqueue_teardown(void)
  58. {
  59. if (edac_workqueue) {
  60. flush_workqueue(edac_workqueue);
  61. destroy_workqueue(edac_workqueue);
  62. edac_workqueue = NULL;
  63. }
  64. }
  65. /*
  66. * edac_init
  67. * module initialization entry point
  68. */
  69. static int __init edac_init(void)
  70. {
  71. int err = 0;
  72. edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
  73. /*
  74. * Harvest and clear any boot/initialization PCI parity errors
  75. *
  76. * FIXME: This only clears errors logged by devices present at time of
  77. * module initialization. We should also do an initial clear
  78. * of each newly hotplugged device.
  79. */
  80. edac_pci_clear_parity_errors();
  81. err = edac_mc_sysfs_init();
  82. if (err)
  83. goto error;
  84. edac_debugfs_init();
  85. /* Setup/Initialize the workq for this core */
  86. err = edac_workqueue_setup();
  87. if (err) {
  88. edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
  89. goto error;
  90. }
  91. return 0;
  92. error:
  93. return err;
  94. }
  95. /*
  96. * edac_exit()
  97. * module exit/termination function
  98. */
  99. static void __exit edac_exit(void)
  100. {
  101. edac_dbg(0, "\n");
  102. /* tear down the various subsystems */
  103. edac_workqueue_teardown();
  104. edac_mc_sysfs_exit();
  105. edac_debugfs_exit();
  106. }
  107. /*
  108. * Inform the kernel of our entry and exit points
  109. */
  110. module_init(edac_init);
  111. module_exit(edac_exit);
  112. MODULE_LICENSE("GPL");
  113. MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
  114. MODULE_DESCRIPTION("Core library routines for EDAC reporting");
  115. /* refer to *_sysfs.c files for parameters that are exported via sysfs */
  116. #ifdef CONFIG_EDAC_DEBUG
  117. module_param(edac_debug_level, int, 0644);
  118. MODULE_PARM_DESC(edac_debug_level, "Debug level");
  119. #endif