crw.c 3.6 KB

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