edac_module.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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"
  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. /*
  82. * now set up the mc_kset under the edac class object
  83. */
  84. err = edac_sysfs_setup_mc_kset();
  85. if (err)
  86. goto error;
  87. /* Setup/Initialize the workq for this core */
  88. err = edac_workqueue_setup();
  89. if (err) {
  90. edac_printk(KERN_ERR, EDAC_MC, "init WorkQueue failure\n");
  91. goto workq_fail;
  92. }
  93. return 0;
  94. /* Error teardown stack */
  95. workq_fail:
  96. edac_sysfs_teardown_mc_kset();
  97. error:
  98. return err;
  99. }
  100. /*
  101. * edac_exit()
  102. * module exit/termination function
  103. */
  104. static void __exit edac_exit(void)
  105. {
  106. debugf0("%s()\n", __func__);
  107. /* tear down the various subsystems */
  108. edac_workqueue_teardown();
  109. edac_sysfs_teardown_mc_kset();
  110. }
  111. /*
  112. * Inform the kernel of our entry and exit points
  113. */
  114. module_init(edac_init);
  115. module_exit(edac_exit);
  116. MODULE_LICENSE("GPL");
  117. MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
  118. MODULE_DESCRIPTION("Core library routines for EDAC reporting");
  119. /* refer to *_sysfs.c files for parameters that are exported via sysfs */
  120. #ifdef CONFIG_EDAC_DEBUG
  121. module_param(edac_debug_level, int, 0644);
  122. MODULE_PARM_DESC(edac_debug_level, "Debug level");
  123. #endif