edac_module.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. static int edac_set_debug_level(const char *buf, struct kernel_param *kp)
  19. {
  20. unsigned long val;
  21. int ret;
  22. ret = kstrtoul(buf, 0, &val);
  23. if (ret)
  24. return ret;
  25. if (val > 4)
  26. return -EINVAL;
  27. return param_set_int(buf, kp);
  28. }
  29. /* Values of 0 to 4 will generate output */
  30. int edac_debug_level = 2;
  31. EXPORT_SYMBOL_GPL(edac_debug_level);
  32. module_param_call(edac_debug_level, edac_set_debug_level, param_get_int,
  33. &edac_debug_level, 0644);
  34. MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2");
  35. #endif
  36. /* scope is to module level only */
  37. struct workqueue_struct *edac_workqueue;
  38. /*
  39. * edac_op_state_to_string()
  40. */
  41. char *edac_op_state_to_string(int opstate)
  42. {
  43. if (opstate == OP_RUNNING_POLL)
  44. return "POLLED";
  45. else if (opstate == OP_RUNNING_INTERRUPT)
  46. return "INTERRUPT";
  47. else if (opstate == OP_RUNNING_POLL_INTR)
  48. return "POLL-INTR";
  49. else if (opstate == OP_ALLOC)
  50. return "ALLOC";
  51. else if (opstate == OP_OFFLINE)
  52. return "OFFLINE";
  53. return "UNKNOWN";
  54. }
  55. /*
  56. * edac_workqueue_setup
  57. * initialize the edac work queue for polling operations
  58. */
  59. static int edac_workqueue_setup(void)
  60. {
  61. edac_workqueue = create_singlethread_workqueue("edac-poller");
  62. if (edac_workqueue == NULL)
  63. return -ENODEV;
  64. else
  65. return 0;
  66. }
  67. /*
  68. * edac_workqueue_teardown
  69. * teardown the edac workqueue
  70. */
  71. static void edac_workqueue_teardown(void)
  72. {
  73. if (edac_workqueue) {
  74. flush_workqueue(edac_workqueue);
  75. destroy_workqueue(edac_workqueue);
  76. edac_workqueue = NULL;
  77. }
  78. }
  79. /*
  80. * edac_init
  81. * module initialization entry point
  82. */
  83. static int __init edac_init(void)
  84. {
  85. int err = 0;
  86. edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
  87. /*
  88. * Harvest and clear any boot/initialization PCI parity errors
  89. *
  90. * FIXME: This only clears errors logged by devices present at time of
  91. * module initialization. We should also do an initial clear
  92. * of each newly hotplugged device.
  93. */
  94. edac_pci_clear_parity_errors();
  95. err = edac_mc_sysfs_init();
  96. if (err)
  97. goto err_sysfs;
  98. edac_debugfs_init();
  99. err = edac_workqueue_setup();
  100. if (err) {
  101. edac_printk(KERN_ERR, EDAC_MC, "Failure initializing workqueue\n");
  102. goto err_wq;
  103. }
  104. return 0;
  105. err_wq:
  106. edac_debugfs_exit();
  107. edac_mc_sysfs_exit();
  108. err_sysfs:
  109. return err;
  110. }
  111. /*
  112. * edac_exit()
  113. * module exit/termination function
  114. */
  115. static void __exit edac_exit(void)
  116. {
  117. edac_dbg(0, "\n");
  118. /* tear down the various subsystems */
  119. edac_workqueue_teardown();
  120. edac_mc_sysfs_exit();
  121. edac_debugfs_exit();
  122. }
  123. /*
  124. * Inform the kernel of our entry and exit points
  125. */
  126. subsys_initcall(edac_init);
  127. module_exit(edac_exit);
  128. MODULE_LICENSE("GPL");
  129. MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
  130. MODULE_DESCRIPTION("Core library routines for EDAC reporting");