crw.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Channel report handling code
  3. *
  4. * Copyright IBM Corp. 2000,2009
  5. * Author(s): Ingo Adlung <adlung@de.ibm.com>,
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>,
  7. * Cornelia Huck <cornelia.huck@de.ibm.com>,
  8. * Heiko Carstens <heiko.carstens@de.ibm.com>,
  9. */
  10. #include <linux/semaphore.h>
  11. #include <linux/mutex.h>
  12. #include <linux/kthread.h>
  13. #include <linux/init.h>
  14. #include <asm/crw.h>
  15. static struct semaphore crw_semaphore;
  16. static DEFINE_MUTEX(crw_handler_mutex);
  17. static crw_handler_t crw_handlers[NR_RSCS];
  18. /**
  19. * crw_register_handler() - register a channel report word handler
  20. * @rsc: reporting source code to handle
  21. * @handler: handler to be registered
  22. *
  23. * Returns %0 on success and a negative error value otherwise.
  24. */
  25. int crw_register_handler(int rsc, crw_handler_t handler)
  26. {
  27. int rc = 0;
  28. if ((rsc < 0) || (rsc >= NR_RSCS))
  29. return -EINVAL;
  30. mutex_lock(&crw_handler_mutex);
  31. if (crw_handlers[rsc])
  32. rc = -EBUSY;
  33. else
  34. crw_handlers[rsc] = handler;
  35. mutex_unlock(&crw_handler_mutex);
  36. return rc;
  37. }
  38. /**
  39. * crw_unregister_handler() - unregister a channel report word handler
  40. * @rsc: reporting source code to handle
  41. */
  42. void crw_unregister_handler(int rsc)
  43. {
  44. if ((rsc < 0) || (rsc >= NR_RSCS))
  45. return;
  46. mutex_lock(&crw_handler_mutex);
  47. crw_handlers[rsc] = NULL;
  48. mutex_unlock(&crw_handler_mutex);
  49. }
  50. /*
  51. * Retrieve CRWs and call function to handle event.
  52. */
  53. static int crw_collect_info(void *unused)
  54. {
  55. struct crw crw[2];
  56. int ccode;
  57. unsigned int chain;
  58. int ignore;
  59. repeat:
  60. ignore = down_interruptible(&crw_semaphore);
  61. chain = 0;
  62. while (1) {
  63. crw_handler_t handler;
  64. if (unlikely(chain > 1)) {
  65. struct crw tmp_crw;
  66. printk(KERN_WARNING"%s: Code does not support more "
  67. "than two chained crws; please report to "
  68. "linux390@de.ibm.com!\n", __func__);
  69. ccode = stcrw(&tmp_crw);
  70. printk(KERN_WARNING"%s: crw reports slct=%d, oflw=%d, "
  71. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  72. __func__, tmp_crw.slct, tmp_crw.oflw,
  73. tmp_crw.chn, tmp_crw.rsc, tmp_crw.anc,
  74. tmp_crw.erc, tmp_crw.rsid);
  75. printk(KERN_WARNING"%s: This was crw number %x in the "
  76. "chain\n", __func__, chain);
  77. if (ccode != 0)
  78. break;
  79. chain = tmp_crw.chn ? chain + 1 : 0;
  80. continue;
  81. }
  82. ccode = stcrw(&crw[chain]);
  83. if (ccode != 0)
  84. break;
  85. printk(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
  86. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  87. crw[chain].slct, crw[chain].oflw, crw[chain].chn,
  88. crw[chain].rsc, crw[chain].anc, crw[chain].erc,
  89. crw[chain].rsid);
  90. /* Check for overflows. */
  91. if (crw[chain].oflw) {
  92. int i;
  93. pr_debug("%s: crw overflow detected!\n", __func__);
  94. mutex_lock(&crw_handler_mutex);
  95. for (i = 0; i < NR_RSCS; i++) {
  96. if (crw_handlers[i])
  97. crw_handlers[i](NULL, NULL, 1);
  98. }
  99. mutex_unlock(&crw_handler_mutex);
  100. chain = 0;
  101. continue;
  102. }
  103. if (crw[0].chn && !chain) {
  104. chain++;
  105. continue;
  106. }
  107. mutex_lock(&crw_handler_mutex);
  108. handler = crw_handlers[crw[chain].rsc];
  109. if (handler)
  110. handler(&crw[0], chain ? &crw[1] : NULL, 0);
  111. mutex_unlock(&crw_handler_mutex);
  112. /* chain is always 0 or 1 here. */
  113. chain = crw[chain].chn ? chain + 1 : 0;
  114. }
  115. goto repeat;
  116. return 0;
  117. }
  118. void crw_handle_channel_report(void)
  119. {
  120. up(&crw_semaphore);
  121. }
  122. /*
  123. * Separate initcall needed for semaphore initialization since
  124. * crw_handle_channel_report might be called before crw_machine_check_init.
  125. */
  126. static int __init crw_init_semaphore(void)
  127. {
  128. init_MUTEX_LOCKED(&crw_semaphore);
  129. return 0;
  130. }
  131. pure_initcall(crw_init_semaphore);
  132. /*
  133. * Machine checks for the channel subsystem must be enabled
  134. * after the channel subsystem is initialized
  135. */
  136. static int __init crw_machine_check_init(void)
  137. {
  138. struct task_struct *task;
  139. task = kthread_run(crw_collect_info, NULL, "kmcheck");
  140. if (IS_ERR(task))
  141. return PTR_ERR(task);
  142. ctl_set_bit(14, 28); /* enable channel report MCH */
  143. return 0;
  144. }
  145. device_initcall(crw_machine_check_init);