edac_module.c 2.8 KB

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