s390mach.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * drivers/s390/s390mach.c
  3. * S/390 machine check handler
  4. *
  5. * S390 version
  6. * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  7. * Author(s): Ingo Adlung (adlung@de.ibm.com)
  8. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  9. */
  10. #include <linux/config.h>
  11. #include <linux/init.h>
  12. #include <linux/sched.h>
  13. #include <linux/errno.h>
  14. #include <linux/workqueue.h>
  15. #include <asm/lowcore.h>
  16. #include "s390mach.h"
  17. #define DBG printk
  18. // #define DBG(args,...) do {} while (0);
  19. static struct semaphore m_sem;
  20. extern int css_process_crw(int);
  21. extern int chsc_process_crw(void);
  22. extern int chp_process_crw(int, int);
  23. extern void css_reiterate_subchannels(void);
  24. extern struct workqueue_struct *slow_path_wq;
  25. extern struct work_struct slow_path_work;
  26. static void
  27. s390_handle_damage(char *msg)
  28. {
  29. printk(KERN_EMERG "%s\n", msg);
  30. #ifdef CONFIG_SMP
  31. smp_send_stop();
  32. #endif
  33. disabled_wait((unsigned long) __builtin_return_address(0));
  34. }
  35. /*
  36. * Retrieve CRWs and call function to handle event.
  37. *
  38. * Note : we currently process CRWs for io and chsc subchannels only
  39. */
  40. static int
  41. s390_collect_crw_info(void *param)
  42. {
  43. struct crw crw;
  44. int ccode, ret, slow;
  45. struct semaphore *sem;
  46. sem = (struct semaphore *)param;
  47. /* Set a nice name. */
  48. daemonize("kmcheck");
  49. repeat:
  50. down_interruptible(sem);
  51. slow = 0;
  52. while (1) {
  53. ccode = stcrw(&crw);
  54. if (ccode != 0)
  55. break;
  56. DBG(KERN_DEBUG "crw_info : CRW reports slct=%d, oflw=%d, "
  57. "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n",
  58. crw.slct, crw.oflw, crw.chn, crw.rsc, crw.anc,
  59. crw.erc, crw.rsid);
  60. /* Check for overflows. */
  61. if (crw.oflw) {
  62. pr_debug("%s: crw overflow detected!\n", __FUNCTION__);
  63. css_reiterate_subchannels();
  64. slow = 1;
  65. continue;
  66. }
  67. switch (crw.rsc) {
  68. case CRW_RSC_SCH:
  69. pr_debug("source is subchannel %04X\n", crw.rsid);
  70. ret = css_process_crw (crw.rsid);
  71. if (ret == -EAGAIN)
  72. slow = 1;
  73. break;
  74. case CRW_RSC_MONITOR:
  75. pr_debug("source is monitoring facility\n");
  76. break;
  77. case CRW_RSC_CPATH:
  78. pr_debug("source is channel path %02X\n", crw.rsid);
  79. switch (crw.erc) {
  80. case CRW_ERC_IPARM: /* Path has come. */
  81. ret = chp_process_crw(crw.rsid, 1);
  82. break;
  83. case CRW_ERC_PERRI: /* Path has gone. */
  84. case CRW_ERC_PERRN:
  85. ret = chp_process_crw(crw.rsid, 0);
  86. break;
  87. default:
  88. pr_debug("Don't know how to handle erc=%x\n",
  89. crw.erc);
  90. ret = 0;
  91. }
  92. if (ret == -EAGAIN)
  93. slow = 1;
  94. break;
  95. case CRW_RSC_CONFIG:
  96. pr_debug("source is configuration-alert facility\n");
  97. break;
  98. case CRW_RSC_CSS:
  99. pr_debug("source is channel subsystem\n");
  100. ret = chsc_process_crw();
  101. if (ret == -EAGAIN)
  102. slow = 1;
  103. break;
  104. default:
  105. pr_debug("unknown source\n");
  106. break;
  107. }
  108. }
  109. if (slow)
  110. queue_work(slow_path_wq, &slow_path_work);
  111. goto repeat;
  112. return 0;
  113. }
  114. /*
  115. * machine check handler.
  116. */
  117. void
  118. s390_do_machine_check(void)
  119. {
  120. struct mci *mci;
  121. mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
  122. if (mci->sd) /* system damage */
  123. s390_handle_damage("received system damage machine check\n");
  124. if (mci->pd) /* instruction processing damage */
  125. s390_handle_damage("received instruction processing "
  126. "damage machine check\n");
  127. if (mci->se) /* storage error uncorrected */
  128. s390_handle_damage("received storage error uncorrected "
  129. "machine check\n");
  130. if (mci->sc) /* storage error corrected */
  131. printk(KERN_WARNING
  132. "received storage error corrected machine check\n");
  133. if (mci->ke) /* storage key-error uncorrected */
  134. s390_handle_damage("received storage key-error uncorrected "
  135. "machine check\n");
  136. if (mci->ds && mci->fa) /* storage degradation */
  137. s390_handle_damage("received storage degradation machine "
  138. "check\n");
  139. if (mci->cp) /* channel report word pending */
  140. up(&m_sem);
  141. #ifdef CONFIG_MACHCHK_WARNING
  142. /*
  143. * The warning may remain for a prolonged period on the bare iron.
  144. * (actually till the machine is powered off, or until the problem is gone)
  145. * So we just stop listening for the WARNING MCH and prevent continuously
  146. * being interrupted. One caveat is however, that we must do this per
  147. * processor and cannot use the smp version of ctl_clear_bit().
  148. * On VM we only get one interrupt per virtally presented machinecheck.
  149. * Though one suffices, we may get one interrupt per (virtual) processor.
  150. */
  151. if (mci->w) { /* WARNING pending ? */
  152. static int mchchk_wng_posted = 0;
  153. /*
  154. * Use single machine clear, as we cannot handle smp right now
  155. */
  156. __ctl_clear_bit(14, 24); /* Disable WARNING MCH */
  157. if (xchg(&mchchk_wng_posted, 1) == 0)
  158. kill_proc(1, SIGPWR, 1);
  159. }
  160. #endif
  161. }
  162. /*
  163. * s390_init_machine_check
  164. *
  165. * initialize machine check handling
  166. */
  167. static int
  168. machine_check_init(void)
  169. {
  170. init_MUTEX_LOCKED(&m_sem);
  171. ctl_clear_bit(14, 25); /* disable damage MCH */
  172. ctl_set_bit(14, 26); /* enable degradation MCH */
  173. ctl_set_bit(14, 27); /* enable system recovery MCH */
  174. #ifdef CONFIG_MACHCHK_WARNING
  175. ctl_set_bit(14, 24); /* enable warning MCH */
  176. #endif
  177. return 0;
  178. }
  179. /*
  180. * Initialize the machine check handler really early to be able to
  181. * catch all machine checks that happen during boot
  182. */
  183. arch_initcall(machine_check_init);
  184. /*
  185. * Machine checks for the channel subsystem must be enabled
  186. * after the channel subsystem is initialized
  187. */
  188. static int __init
  189. machine_check_crw_init (void)
  190. {
  191. kernel_thread(s390_collect_crw_info, &m_sem, CLONE_FS|CLONE_FILES);
  192. ctl_set_bit(14, 28); /* enable channel report MCH */
  193. return 0;
  194. }
  195. device_initcall (machine_check_crw_init);