2 * arch/s390/kernel/s390mach.c
3 * S/390 machine check handler,
4 * currently only channel-reports are supported
7 * Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
8 * Author(s): Ingo Adlung (adlung@de.ibm.com)
11 #include <linux/config.h>
12 #include <linux/spinlock.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
16 #include <linux/smp.h>
20 #include <asm/lowcore.h>
21 #include <asm/semaphore.h>
22 #include <asm/s390io.h>
23 #include <asm/s390dyn.h>
24 #include <asm/s390mach.h>
25 #ifdef CONFIG_MACHCHK_WARNING
26 #include <asm/signal.h>
29 extern void ctrl_alt_del(void);
31 #define S390_MACHCHK_DEBUG
33 static int s390_machine_check_handler( void * parm );
34 static void s390_enqueue_mchchk( mache_t *mchchk );
35 static mache_t *s390_dequeue_mchchk( void );
36 static void s390_enqueue_free_mchchk( mache_t *mchchk );
37 static mache_t *s390_dequeue_free_mchchk( void );
38 static int s390_collect_crw_info( void );
39 #ifdef CONFIG_MACHCHK_WARNING
40 static int s390_post_warning( void );
43 static mache_t *mchchk_queue_head = NULL;
44 static mache_t *mchchk_queue_tail = NULL;
45 static mache_t *mchchk_queue_free = NULL;
46 static crwe_t *crw_buffer_anchor = NULL;
47 static spinlock_t mchchk_queue_lock = SPIN_LOCK_UNLOCKED;
48 static spinlock_t crw_queue_lock = SPIN_LOCK_UNLOCKED;
50 static struct semaphore s_sem;
52 #ifdef CONFIG_MACHCHK_WARNING
53 static int mchchk_wng_posted = 0;
57 * s390_init_machine_check
59 * initialize machine check handling
61 void s390_init_machine_check( void )
63 crwe_t *pcrwe; /* CRW buffer element pointer */
64 mache_t *pmache; /* machine check element pointer */
66 init_MUTEX_LOCKED( &s_sem );
68 pcrwe = kmalloc( MAX_CRW_PENDING * sizeof( crwe_t), GFP_KERNEL);
74 crw_buffer_anchor = pcrwe;
76 for ( i=0; i < MAX_CRW_PENDING-1; i++)
78 pcrwe->crwe_next = (crwe_t *)((unsigned long)pcrwe + sizeof(crwe_t));
79 pcrwe = pcrwe->crwe_next;
83 pcrwe->crwe_next = NULL;
88 panic( "s390_init_machine_check : unable to obtain memory\n");
92 pmache = kmalloc( MAX_MACH_PENDING * sizeof( mache_t), GFP_KERNEL);
98 for ( i=0; i < MAX_MACH_PENDING; i++)
100 s390_enqueue_free_mchchk( pmache );
101 pmache = (mache_t *)((unsigned long)pmache + sizeof(mache_t));
107 panic( "s390_init_machine_check : unable to obtain memory\n");
111 #ifdef S390_MACHCHK_DEBUG
112 printk( KERN_NOTICE "init_mach : starting machine check handler\n");
115 kernel_thread( s390_machine_check_handler, &s_sem, CLONE_FS | CLONE_FILES);
117 ctl_clear_bit( 14, 25 ); // disable damage MCH
119 ctl_set_bit( 14, 26 ); /* enable degradation MCH */
120 ctl_set_bit( 14, 27 ); /* enable system recovery MCH */
122 ctl_set_bit( 14, 28 ); // enable channel report MCH
124 #ifdef CONFIG_MACHCK_WARNING
125 ctl_set_bit( 14, 24); /* enable warning MCH */
128 #ifdef S390_MACHCHK_DEBUG
129 printk( KERN_DEBUG "init_mach : machine check buffer : head = %08X\n",
130 (unsigned)&mchchk_queue_head);
131 printk( KERN_DEBUG "init_mach : machine check buffer : tail = %08X\n",
132 (unsigned)&mchchk_queue_tail);
133 printk( KERN_DEBUG "init_mach : machine check buffer : free = %08X\n",
134 (unsigned)&mchchk_queue_free);
135 printk( KERN_DEBUG "init_mach : CRW entry buffer anchor = %08X\n",
136 (unsigned)&crw_buffer_anchor);
137 printk( KERN_DEBUG "init_mach : machine check handler ready\n");
143 static void s390_handle_damage(char * msg){
145 unsigned long caller = (unsigned long) __builtin_return_address(0);
147 printk(KERN_EMERG "%s\n", msg);
151 disabled_wait(caller);
157 * s390_do_machine_check
159 * mchine check pre-processor, collecting the machine check info,
160 * queueing it and posting the machine check handler for processing.
162 void s390_do_machine_check( void )
167 #ifdef S390_MACHCHK_DEBUG
168 printk( KERN_INFO "s390_do_machine_check : starting ...\n");
172 &S390_lowcore.mcck_interruption_code,
175 if (mcic.mcc.mcd.sd) /* system damage */
176 s390_handle_damage("received system damage machine check\n");
178 if (mcic.mcc.mcd.pd) /* instruction processing damage */
179 s390_handle_damage("received instruction processing damage machine check\n");
181 if (mcic.mcc.mcd.se) /* storage error uncorrected */
182 s390_handle_damage("received storage error uncorrected machine check\n");
184 if (mcic.mcc.mcd.sc) /* storage error corrected */
185 printk(KERN_WARNING "received storage error corrected machine check\n");
187 if (mcic.mcc.mcd.ke) /* storage key-error uncorrected */
188 s390_handle_damage("received storage key-error uncorrected machine check\n");
190 if (mcic.mcc.mcd.ds && mcic.mcc.mcd.fa) /* storage degradation */
191 s390_handle_damage("received storage degradation machine check\n");
193 if ( mcic.mcc.mcd.cp ) // CRW pending ?
195 crw_count = s390_collect_crw_info();
204 #ifdef CONFIG_MACHCHK_WARNING
206 * The warning may remain for a prolonged period on the bare iron.
207 * (actually till the machine is powered off, or until the problem is gone)
208 * So we just stop listening for the WARNING MCH and prevent continuously
209 * being interrupted. One caveat is however, that we must do this per
210 * processor and cannot use the smp version of ctl_clear_bit().
211 * On VM we only get one interrupt per virtally presented machinecheck.
212 * Though one suffices, we may get one interrupt per (virtual) processor.
214 if ( mcic.mcc.mcd.w ) // WARNING pending ?
216 // Use single machine clear, as we cannot handle smp right now
217 __ctl_clear_bit( 14, 24 ); // Disable WARNING MCH
219 if ( ! mchchk_wng_posted )
221 mchchk_wng_posted = s390_post_warning();
223 if ( mchchk_wng_posted )
234 #ifdef S390_MACHCHK_DEBUG
235 printk( KERN_INFO "s390_do_machine_check : done \n");
242 * s390_machine_check_handler
244 * machine check handler, dequeueing machine check entries
245 * and processing them
247 static int s390_machine_check_handler( void *parm)
249 struct semaphore *sem = parm;
255 /* set name to something sensible */
256 strcpy (current->comm, "kmcheck");
259 /* block all signals */
260 sigfillset(¤t->blocked);
262 #ifdef S390_MACHCHK_DEBUG
263 printk( KERN_NOTICE "mach_handler : ready\n");
268 #ifdef S390_MACHCHK_DEBUG
269 printk( KERN_NOTICE "mach_handler : waiting for wakeup\n");
272 down_interruptible( sem );
274 #ifdef S390_MACHCHK_DEBUG
275 printk( KERN_NOTICE "\nmach_handler : wakeup ... \n");
277 found = 0; /* init ... */
279 __save_flags( flags );
284 pmache = s390_dequeue_mchchk();
290 if ( pmache->mcic.mcc.mcd.cp )
295 s390_do_crw_pending( pmache->mc.crwe );
297 pcrwe_h = pmache->mc.crwe;
298 pcrwe_n = pmache->mc.crwe->crwe_next;
300 pmache->mcic.mcc.mcd.cp = 0;
301 pmache->mc.crwe = NULL;
303 spin_lock( &crw_queue_lock);
307 pcrwe_h->crwe_next = crw_buffer_anchor;
308 crw_buffer_anchor = pcrwe_h;
311 if ( pcrwe_h != NULL )
312 pcrwe_n = pcrwe_h->crwe_next;
316 spin_unlock( &crw_queue_lock);
320 #ifdef CONFIG_MACHCHK_WARNING
321 if ( pmache->mcic.mcc.mcd.w )
323 ctrl_alt_del(); // shutdown NOW!
324 #ifdef S390_MACHCHK_DEBUG
325 printk( KERN_DEBUG "mach_handler : kill -SIGPWR init\n");
330 s390_enqueue_free_mchchk( pmache );
335 // unconditional surrender ...
336 #ifdef S390_MACHCHK_DEBUG
337 printk( KERN_DEBUG "mach_handler : nothing to do, sleeping\n");
344 __restore_flags( flags );
352 * s390_dequeue_mchchk
354 * Dequeue an entry from the machine check queue
356 * Note : The queue elements provide for a double linked list.
357 * We dequeue entries from the tail, and enqueue entries to
361 static mache_t *s390_dequeue_mchchk( void )
365 spin_lock( &mchchk_queue_lock );
367 qe = mchchk_queue_tail;
371 mchchk_queue_tail = qe->prev;
373 if ( mchchk_queue_tail != NULL )
375 mchchk_queue_tail->next = NULL;
379 mchchk_queue_head = NULL;
385 spin_unlock( &mchchk_queue_lock );
391 * s390_enqueue_mchchk
393 * Enqueue an entry to the machine check queue.
395 * Note : The queue elements provide for a double linked list.
396 * We enqueue entries to the head, and dequeue entries from
400 static void s390_enqueue_mchchk( mache_t *pmache )
402 spin_lock( &mchchk_queue_lock );
404 if ( pmache != NULL )
407 if ( mchchk_queue_head == NULL ) /* first element */
412 mchchk_queue_head = pmache;
413 mchchk_queue_tail = pmache;
418 pmache->next = mchchk_queue_head;
420 mchchk_queue_head->prev = pmache;
421 mchchk_queue_head = pmache;
427 spin_unlock( &mchchk_queue_lock );
434 * s390_enqueue_free_mchchk
436 * Enqueue a free entry to the free queue.
438 * Note : While the queue elements provide for a double linked list,
439 * the free queue entries are only concatenated by means of a
440 * single linked list (forward concatenation).
443 static void s390_enqueue_free_mchchk( mache_t *pmache )
447 memset( pmache, '\0', sizeof( mache_t ));
449 spin_lock( &mchchk_queue_lock );
451 pmache->next = mchchk_queue_free;
453 mchchk_queue_free = pmache;
455 spin_unlock( &mchchk_queue_lock );
463 * s390_dequeue_free_mchchk
465 * Dequeue an entry from the free queue.
467 * Note : While the queue elements provide for a double linked list,
468 * the free queue entries are only concatenated by means of a
469 * single linked list (forward concatenation).
472 static mache_t *s390_dequeue_free_mchchk( void )
476 spin_lock( &mchchk_queue_lock );
478 qe = mchchk_queue_free;
482 mchchk_queue_free = qe->next;
486 spin_unlock( &mchchk_queue_lock );
492 * s390_collect_crw_info
494 * Retrieve CRWs. If a CRW was found a machine check element
495 * is dequeued from the free chain, filled and enqueued to
498 * The function returns the number of CRWs found.
500 * Note : We must always be called disabled ...
502 static int s390_collect_crw_info( void )
504 crw_t tcrw; /* temporarily holds a CRW */
505 int ccode; /* condition code from stcrw() */
506 crwe_t *pcrwe; /* pointer to CRW buffer entry */
508 mache_t *pmache = NULL; /* ptr to mchchk entry */
509 int chain = 0; /* indicate chaining */
510 crwe_t *pccrw = NULL; /* ptr to current CRW buffer entry */
511 int count = 0; /* CRW count */
513 #ifdef S390_MACHCHK_DEBUG
514 printk( KERN_DEBUG "crw_info : looking for CRWs ...\n");
519 ccode = stcrw( (__u32 *)&tcrw);
525 #ifdef S390_MACHCHK_DEBUG
526 printk( KERN_DEBUG "crw_info : CRW reports "
527 "slct=%d, oflw=%d, chn=%d, "
528 "rsc=%X, anc=%d, erc=%X, "
540 * Dequeue a CRW entry from the free chain
543 spin_lock( &crw_queue_lock );
545 pcrwe = crw_buffer_anchor;
549 spin_unlock( &crw_queue_lock );
550 printk( KERN_CRIT"crw_info : "
551 "no CRW buffer entries available\n");
556 crw_buffer_anchor = pcrwe->crwe_next;
557 pcrwe->crwe_next = NULL;
559 spin_unlock( &crw_queue_lock );
561 memcpy( &(pcrwe->crw), &tcrw, sizeof(crw_t));
564 * If it is the first CRW, chain it to the mchchk
565 * buffer entry, otherwise to the last CRW entry.
569 pmache = s390_dequeue_free_mchchk();
571 if ( pmache != NULL )
573 memset( pmache, '\0', sizeof(mache_t));
575 pmache->mcic.mcc.mcd.cp = 1;
576 pmache->mc.crwe = pcrwe;
584 "free mchchk buffer");
590 pccrw->crwe_next = pcrwe;
595 if ( pccrw->crw.chn )
597 #ifdef S390_MACHCHK_DEBUG
598 printk( KERN_DEBUG "crw_info : "
599 "chained CRWs pending ...\n\n");
608 * We can enqueue the mchchk buffer if
609 * there aren't more CRWs chained.
611 s390_enqueue_mchchk( pmache);
617 } while ( ccode == 0 );
622 #ifdef CONFIG_MACHCHK_WARNING
626 * Post a warning type machine check
628 * The function returns 1 when succesfull (panics otherwise)
630 static int s390_post_warning( void )
632 mache_t *pmache = NULL; /* ptr to mchchk entry */
634 pmache = s390_dequeue_free_mchchk();
636 if ( pmache != NULL )
638 memset( pmache, '\0', sizeof(mache_t) );
640 pmache->mcic.mcc.mcd.w = 1;
642 s390_enqueue_mchchk( pmache );
646 panic( "post_warning : "
648 "free mchchk buffer" );
651 #ifdef S390_MACHCHK_DEBUG
652 printk( KERN_DEBUG "post_warning : 1 warning machine check posted\n");