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