2 * drivers/s390/char/sclp.c
3 * core function to access sclp interface
6 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
11 #include <linux/module.h>
12 #include <linux/err.h>
13 #include <linux/spinlock.h>
14 #include <linux/interrupt.h>
15 #include <linux/timer.h>
16 #include <linux/reboot.h>
17 #include <linux/jiffies.h>
18 #include <asm/types.h>
19 #include <asm/s390_ext.h>
23 #define SCLP_HEADER "sclp: "
25 /* Structure for register_early_external_interrupt. */
26 static ext_int_info_t ext_int_info_hwc;
28 /* Lock to protect internal data consistency. */
29 static DEFINE_SPINLOCK(sclp_lock);
31 /* Mask of events that we can receive from the sclp interface. */
32 static sccb_mask_t sclp_receive_mask;
34 /* Mask of events that we can send to the sclp interface. */
35 static sccb_mask_t sclp_send_mask;
37 /* List of registered event listeners and senders. */
38 static struct list_head sclp_reg_list;
40 /* List of queued requests. */
41 static struct list_head sclp_req_queue;
43 /* Data for read and and init requests. */
44 static struct sclp_req sclp_read_req;
45 static struct sclp_req sclp_init_req;
46 static char sclp_read_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
47 static char sclp_init_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
49 /* Timer for request retries. */
50 static struct timer_list sclp_request_timer;
52 /* Internal state: is the driver initialized? */
53 static volatile enum sclp_init_state_t {
54 sclp_init_state_uninitialized,
55 sclp_init_state_initializing,
56 sclp_init_state_initialized
57 } sclp_init_state = sclp_init_state_uninitialized;
59 /* Internal state: is a request active at the sclp? */
60 static volatile enum sclp_running_state_t {
61 sclp_running_state_idle,
62 sclp_running_state_running
63 } sclp_running_state = sclp_running_state_idle;
65 /* Internal state: is a read request pending? */
66 static volatile enum sclp_reading_state_t {
67 sclp_reading_state_idle,
68 sclp_reading_state_reading
69 } sclp_reading_state = sclp_reading_state_idle;
71 /* Internal state: is the driver currently serving requests? */
72 static volatile enum sclp_activation_state_t {
73 sclp_activation_state_active,
74 sclp_activation_state_deactivating,
75 sclp_activation_state_inactive,
76 sclp_activation_state_activating
77 } sclp_activation_state = sclp_activation_state_active;
79 /* Internal state: is an init mask request pending? */
80 static volatile enum sclp_mask_state_t {
82 sclp_mask_state_initializing
83 } sclp_mask_state = sclp_mask_state_idle;
85 /* Maximum retry counts */
86 #define SCLP_INIT_RETRY 3
87 #define SCLP_MASK_RETRY 3
89 /* Timeout intervals in seconds.*/
90 #define SCLP_BUSY_INTERVAL 10
91 #define SCLP_RETRY_INTERVAL 15
93 static void sclp_process_queue(void);
94 static int sclp_init_mask(int calculate);
95 static int sclp_init(void);
97 /* Perform service call. Return 0 on success, non-zero otherwise. */
99 service_call(sclp_cmdw_t command, void *sccb)
103 __asm__ __volatile__(
104 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
108 : "d" (command), "a" (__pa(sccb))
117 /* Request timeout handler. Restart the request queue. If DATA is non-zero,
118 * force restart of running request. */
120 sclp_request_timeout(unsigned long data)
125 spin_lock_irqsave(&sclp_lock, flags);
126 sclp_running_state = sclp_running_state_idle;
127 spin_unlock_irqrestore(&sclp_lock, flags);
129 sclp_process_queue();
132 /* Set up request retry timer. Called while sclp_lock is locked. */
134 __sclp_set_request_timer(unsigned long time, void (*function)(unsigned long),
137 del_timer(&sclp_request_timer);
138 sclp_request_timer.function = function;
139 sclp_request_timer.data = data;
140 sclp_request_timer.expires = jiffies + time;
141 add_timer(&sclp_request_timer);
144 /* Try to start a request. Return zero if the request was successfully
145 * started or if it will be started at a later time. Return non-zero otherwise.
146 * Called while sclp_lock is locked. */
148 __sclp_start_request(struct sclp_req *req)
152 if (sclp_running_state != sclp_running_state_idle)
154 del_timer(&sclp_request_timer);
155 rc = service_call(req->command, req->sccb);
159 /* Sucessfully started request */
160 req->status = SCLP_REQ_RUNNING;
161 sclp_running_state = sclp_running_state_running;
162 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
163 sclp_request_timeout, 1);
165 } else if (rc == -EBUSY) {
166 /* Try again later */
167 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
168 sclp_request_timeout, 0);
172 req->status = SCLP_REQ_FAILED;
176 /* Try to start queued requests. */
178 sclp_process_queue(void)
180 struct sclp_req *req;
184 spin_lock_irqsave(&sclp_lock, flags);
185 if (sclp_running_state != sclp_running_state_idle) {
186 spin_unlock_irqrestore(&sclp_lock, flags);
189 del_timer(&sclp_request_timer);
190 while (!list_empty(&sclp_req_queue)) {
191 req = list_entry(sclp_req_queue.next, struct sclp_req, list);
192 rc = __sclp_start_request(req);
195 /* Request failed. */
196 list_del(&req->list);
198 spin_unlock_irqrestore(&sclp_lock, flags);
199 req->callback(req, req->callback_data);
200 spin_lock_irqsave(&sclp_lock, flags);
203 spin_unlock_irqrestore(&sclp_lock, flags);
206 /* Queue a new request. Return zero on success, non-zero otherwise. */
208 sclp_add_request(struct sclp_req *req)
213 spin_lock_irqsave(&sclp_lock, flags);
214 if ((sclp_init_state != sclp_init_state_initialized ||
215 sclp_activation_state != sclp_activation_state_active) &&
216 req != &sclp_init_req) {
217 spin_unlock_irqrestore(&sclp_lock, flags);
220 req->status = SCLP_REQ_QUEUED;
221 req->start_count = 0;
222 list_add_tail(&req->list, &sclp_req_queue);
224 /* Start if request is first in list */
225 if (req->list.prev == &sclp_req_queue) {
226 rc = __sclp_start_request(req);
228 list_del(&req->list);
230 spin_unlock_irqrestore(&sclp_lock, flags);
234 EXPORT_SYMBOL(sclp_add_request);
236 /* Dispatch events found in request buffer to registered listeners. Return 0
237 * if all events were dispatched, non-zero otherwise. */
239 sclp_dispatch_evbufs(struct sccb_header *sccb)
242 struct evbuf_header *evbuf;
244 struct sclp_register *reg;
248 spin_lock_irqsave(&sclp_lock, flags);
250 for (offset = sizeof(struct sccb_header); offset < sccb->length;
251 offset += evbuf->length) {
252 /* Search for event handler */
253 evbuf = (struct evbuf_header *) ((addr_t) sccb + offset);
255 list_for_each(l, &sclp_reg_list) {
256 reg = list_entry(l, struct sclp_register, list);
257 if (reg->receive_mask & (1 << (32 - evbuf->type)))
262 if (reg && reg->receiver_fn) {
263 spin_unlock_irqrestore(&sclp_lock, flags);
264 reg->receiver_fn(evbuf);
265 spin_lock_irqsave(&sclp_lock, flags);
266 } else if (reg == NULL)
269 spin_unlock_irqrestore(&sclp_lock, flags);
273 /* Read event data request callback. */
275 sclp_read_cb(struct sclp_req *req, void *data)
278 struct sccb_header *sccb;
280 sccb = (struct sccb_header *) req->sccb;
281 if (req->status == SCLP_REQ_DONE && (sccb->response_code == 0x20 ||
282 sccb->response_code == 0x220))
283 sclp_dispatch_evbufs(sccb);
284 spin_lock_irqsave(&sclp_lock, flags);
285 sclp_reading_state = sclp_reading_state_idle;
286 spin_unlock_irqrestore(&sclp_lock, flags);
289 /* Prepare read event data request. Called while sclp_lock is locked. */
291 __sclp_make_read_req(void)
293 struct sccb_header *sccb;
295 sccb = (struct sccb_header *) sclp_read_sccb;
297 memset(&sclp_read_req, 0, sizeof(struct sclp_req));
298 sclp_read_req.command = SCLP_CMDW_READDATA;
299 sclp_read_req.status = SCLP_REQ_QUEUED;
300 sclp_read_req.start_count = 0;
301 sclp_read_req.callback = sclp_read_cb;
302 sclp_read_req.sccb = sccb;
303 sccb->length = PAGE_SIZE;
304 sccb->function_code = 0;
305 sccb->control_mask[2] = 0x80;
308 /* Search request list for request with matching sccb. Return request if found,
309 * NULL otherwise. Called while sclp_lock is locked. */
310 static inline struct sclp_req *
311 __sclp_find_req(u32 sccb)
314 struct sclp_req *req;
316 list_for_each(l, &sclp_req_queue) {
317 req = list_entry(l, struct sclp_req, list);
318 if (sccb == (u32) (addr_t) req->sccb)
324 /* Handler for external interruption. Perform request post-processing.
325 * Prepare read event data request if necessary. Start processing of next
326 * request on queue. */
328 sclp_interrupt_handler(struct pt_regs *regs, __u16 code)
330 struct sclp_req *req;
334 spin_lock(&sclp_lock);
335 finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
336 evbuf_pending = S390_lowcore.ext_params & 0x3;
338 req = __sclp_find_req(finished_sccb);
340 /* Request post-processing */
341 list_del(&req->list);
342 req->status = SCLP_REQ_DONE;
344 spin_unlock(&sclp_lock);
345 req->callback(req, req->callback_data);
346 spin_lock(&sclp_lock);
349 sclp_running_state = sclp_running_state_idle;
351 if (evbuf_pending && sclp_receive_mask != 0 &&
352 sclp_reading_state == sclp_reading_state_idle &&
353 sclp_activation_state == sclp_activation_state_active ) {
354 sclp_reading_state = sclp_reading_state_reading;
355 __sclp_make_read_req();
356 /* Add request to head of queue */
357 list_add(&sclp_read_req.list, &sclp_req_queue);
359 spin_unlock(&sclp_lock);
360 sclp_process_queue();
363 /* Return current Time-Of-Day clock. */
369 asm volatile ("STCK 0(%1)" : "=m" (result) : "a" (&(result)) : "cc");
373 /* Convert interval in jiffies to TOD ticks. */
375 sclp_tod_from_jiffies(unsigned long jiffies)
377 return (u64) (jiffies / HZ) << 32;
380 /* Wait until a currently running request finished. Note: while this function
381 * is running, no timers are served on the calling CPU. */
385 unsigned long psw_mask;
387 unsigned long cr0, cr0_sync;
390 /* We'll be disabling timer interrupts, so we need a custom timeout
393 if (timer_pending(&sclp_request_timer)) {
394 /* Get timeout TOD value */
395 timeout = sclp_get_clock() +
396 sclp_tod_from_jiffies(sclp_request_timer.expires -
399 local_irq_save(flags);
400 /* Prevent bottom half from executing once we force interrupts open */
402 /* Enable service-signal interruption, disable timer interrupts */
404 __ctl_store(cr0, 0, 0);
406 cr0_sync |= 0x00000200;
407 cr0_sync &= 0xFFFFF3AC;
408 __ctl_load(cr0_sync, 0, 0);
409 asm volatile ("STOSM 0(%1),0x01"
410 : "=m" (psw_mask) : "a" (&psw_mask) : "memory");
411 /* Loop until driver state indicates finished request */
412 while (sclp_running_state != sclp_running_state_idle) {
413 /* Check for expired request timer */
414 if (timer_pending(&sclp_request_timer) &&
415 sclp_get_clock() > timeout &&
416 del_timer(&sclp_request_timer))
417 sclp_request_timer.function(sclp_request_timer.data);
422 __ctl_load(cr0, 0, 0);
424 local_irq_restore(flags);
427 EXPORT_SYMBOL(sclp_sync_wait);
429 /* Dispatch changes in send and receive mask to registered listeners. */
431 sclp_dispatch_state_change(void)
434 struct sclp_register *reg;
436 sccb_mask_t receive_mask;
437 sccb_mask_t send_mask;
440 spin_lock_irqsave(&sclp_lock, flags);
442 list_for_each(l, &sclp_reg_list) {
443 reg = list_entry(l, struct sclp_register, list);
444 receive_mask = reg->receive_mask & sclp_receive_mask;
445 send_mask = reg->send_mask & sclp_send_mask;
446 if (reg->sclp_receive_mask != receive_mask ||
447 reg->sclp_send_mask != send_mask) {
448 reg->sclp_receive_mask = receive_mask;
449 reg->sclp_send_mask = send_mask;
454 spin_unlock_irqrestore(&sclp_lock, flags);
455 if (reg && reg->state_change_fn)
456 reg->state_change_fn(reg);
460 struct sclp_statechangebuf {
461 struct evbuf_header header;
462 u8 validity_sclp_active_facility_mask : 1;
463 u8 validity_sclp_receive_mask : 1;
464 u8 validity_sclp_send_mask : 1;
465 u8 validity_read_data_function_mask : 1;
468 u64 sclp_active_facility_mask;
469 sccb_mask_t sclp_receive_mask;
470 sccb_mask_t sclp_send_mask;
471 u32 read_data_function_mask;
472 } __attribute__((packed));
475 /* State change event callback. Inform listeners of changes. */
477 sclp_state_change_cb(struct evbuf_header *evbuf)
480 struct sclp_statechangebuf *scbuf;
482 scbuf = (struct sclp_statechangebuf *) evbuf;
483 if (scbuf->mask_length != sizeof(sccb_mask_t))
485 spin_lock_irqsave(&sclp_lock, flags);
486 if (scbuf->validity_sclp_receive_mask)
487 sclp_receive_mask = scbuf->sclp_receive_mask;
488 if (scbuf->validity_sclp_send_mask)
489 sclp_send_mask = scbuf->sclp_send_mask;
490 spin_unlock_irqrestore(&sclp_lock, flags);
491 sclp_dispatch_state_change();
494 static struct sclp_register sclp_state_change_event = {
495 .receive_mask = EvTyp_StateChange_Mask,
496 .receiver_fn = sclp_state_change_cb
499 /* Calculate receive and send mask of currently registered listeners.
500 * Called while sclp_lock is locked. */
502 __sclp_get_mask(sccb_mask_t *receive_mask, sccb_mask_t *send_mask)
505 struct sclp_register *t;
509 list_for_each(l, &sclp_reg_list) {
510 t = list_entry(l, struct sclp_register, list);
511 *receive_mask |= t->receive_mask;
512 *send_mask |= t->send_mask;
516 /* Register event listener. Return 0 on success, non-zero otherwise. */
518 sclp_register(struct sclp_register *reg)
521 sccb_mask_t receive_mask;
522 sccb_mask_t send_mask;
528 spin_lock_irqsave(&sclp_lock, flags);
529 /* Check event mask for collisions */
530 __sclp_get_mask(&receive_mask, &send_mask);
531 if (reg->receive_mask & receive_mask || reg->send_mask & send_mask) {
532 spin_unlock_irqrestore(&sclp_lock, flags);
535 /* Trigger initial state change callback */
536 reg->sclp_receive_mask = 0;
537 reg->sclp_send_mask = 0;
538 list_add(®->list, &sclp_reg_list);
539 spin_unlock_irqrestore(&sclp_lock, flags);
540 rc = sclp_init_mask(1);
542 spin_lock_irqsave(&sclp_lock, flags);
543 list_del(®->list);
544 spin_unlock_irqrestore(&sclp_lock, flags);
549 EXPORT_SYMBOL(sclp_register);
551 /* Unregister event listener. */
553 sclp_unregister(struct sclp_register *reg)
557 spin_lock_irqsave(&sclp_lock, flags);
558 list_del(®->list);
559 spin_unlock_irqrestore(&sclp_lock, flags);
563 EXPORT_SYMBOL(sclp_unregister);
565 /* Remove event buffers which are marked processed. Return the number of
566 * remaining event buffers. */
568 sclp_remove_processed(struct sccb_header *sccb)
570 struct evbuf_header *evbuf;
574 evbuf = (struct evbuf_header *) (sccb + 1);
576 remaining = sccb->length - sizeof(struct sccb_header);
577 while (remaining > 0) {
578 remaining -= evbuf->length;
579 if (evbuf->flags & 0x80) {
580 sccb->length -= evbuf->length;
581 memcpy(evbuf, (void *) ((addr_t) evbuf + evbuf->length),
585 evbuf = (struct evbuf_header *)
586 ((addr_t) evbuf + evbuf->length);
592 EXPORT_SYMBOL(sclp_remove_processed);
595 struct sccb_header header;
598 sccb_mask_t receive_mask;
599 sccb_mask_t send_mask;
600 sccb_mask_t sclp_send_mask;
601 sccb_mask_t sclp_receive_mask;
602 } __attribute__((packed));
604 /* Prepare init mask request. Called while sclp_lock is locked. */
606 __sclp_make_init_req(u32 receive_mask, u32 send_mask)
608 struct init_sccb *sccb;
610 sccb = (struct init_sccb *) sclp_init_sccb;
612 memset(&sclp_init_req, 0, sizeof(struct sclp_req));
613 sclp_init_req.command = SCLP_CMDW_WRITEMASK;
614 sclp_init_req.status = SCLP_REQ_FILLED;
615 sclp_init_req.start_count = 0;
616 sclp_init_req.callback = NULL;
617 sclp_init_req.callback_data = NULL;
618 sclp_init_req.sccb = sccb;
619 sccb->header.length = sizeof(struct init_sccb);
620 sccb->mask_length = sizeof(sccb_mask_t);
621 sccb->receive_mask = receive_mask;
622 sccb->send_mask = send_mask;
623 sccb->sclp_receive_mask = 0;
624 sccb->sclp_send_mask = 0;
627 /* Start init mask request. If calculate is non-zero, calculate the mask as
628 * requested by registered listeners. Use zero mask otherwise. Return 0 on
629 * success, non-zero otherwise. */
631 sclp_init_mask(int calculate)
634 struct init_sccb *sccb = (struct init_sccb *) sclp_init_sccb;
635 sccb_mask_t receive_mask;
636 sccb_mask_t send_mask;
641 spin_lock_irqsave(&sclp_lock, flags);
642 /* Check if interface is in appropriate state */
643 if (sclp_mask_state != sclp_mask_state_idle) {
644 spin_unlock_irqrestore(&sclp_lock, flags);
647 if (sclp_activation_state == sclp_activation_state_inactive) {
648 spin_unlock_irqrestore(&sclp_lock, flags);
651 sclp_mask_state = sclp_mask_state_initializing;
654 __sclp_get_mask(&receive_mask, &send_mask);
660 for (retry = 0; retry <= SCLP_MASK_RETRY; retry++) {
661 /* Prepare request */
662 __sclp_make_init_req(receive_mask, send_mask);
663 spin_unlock_irqrestore(&sclp_lock, flags);
664 if (sclp_add_request(&sclp_init_req)) {
665 /* Try again later */
666 wait = jiffies + SCLP_BUSY_INTERVAL * HZ;
667 while (time_before(jiffies, wait))
669 spin_lock_irqsave(&sclp_lock, flags);
672 while (sclp_init_req.status != SCLP_REQ_DONE &&
673 sclp_init_req.status != SCLP_REQ_FAILED)
675 spin_lock_irqsave(&sclp_lock, flags);
676 if (sclp_init_req.status == SCLP_REQ_DONE &&
677 sccb->header.response_code == 0x20) {
678 /* Successful request */
680 sclp_receive_mask = sccb->sclp_receive_mask;
681 sclp_send_mask = sccb->sclp_send_mask;
683 sclp_receive_mask = 0;
686 spin_unlock_irqrestore(&sclp_lock, flags);
687 sclp_dispatch_state_change();
688 spin_lock_irqsave(&sclp_lock, flags);
693 sclp_mask_state = sclp_mask_state_idle;
694 spin_unlock_irqrestore(&sclp_lock, flags);
698 /* Deactivate SCLP interface. On success, new requests will be rejected,
699 * events will no longer be dispatched. Return 0 on success, non-zero
702 sclp_deactivate(void)
707 spin_lock_irqsave(&sclp_lock, flags);
708 /* Deactivate can only be called when active */
709 if (sclp_activation_state != sclp_activation_state_active) {
710 spin_unlock_irqrestore(&sclp_lock, flags);
713 sclp_activation_state = sclp_activation_state_deactivating;
714 spin_unlock_irqrestore(&sclp_lock, flags);
715 rc = sclp_init_mask(0);
716 spin_lock_irqsave(&sclp_lock, flags);
718 sclp_activation_state = sclp_activation_state_inactive;
720 sclp_activation_state = sclp_activation_state_active;
721 spin_unlock_irqrestore(&sclp_lock, flags);
725 EXPORT_SYMBOL(sclp_deactivate);
727 /* Reactivate SCLP interface after sclp_deactivate. On success, new
728 * requests will be accepted, events will be dispatched again. Return 0 on
729 * success, non-zero otherwise. */
731 sclp_reactivate(void)
736 spin_lock_irqsave(&sclp_lock, flags);
737 /* Reactivate can only be called when inactive */
738 if (sclp_activation_state != sclp_activation_state_inactive) {
739 spin_unlock_irqrestore(&sclp_lock, flags);
742 sclp_activation_state = sclp_activation_state_activating;
743 spin_unlock_irqrestore(&sclp_lock, flags);
744 rc = sclp_init_mask(1);
745 spin_lock_irqsave(&sclp_lock, flags);
747 sclp_activation_state = sclp_activation_state_active;
749 sclp_activation_state = sclp_activation_state_inactive;
750 spin_unlock_irqrestore(&sclp_lock, flags);
754 EXPORT_SYMBOL(sclp_reactivate);
756 /* Handler for external interruption used during initialization. Modify
757 * request state to done. */
759 sclp_check_handler(struct pt_regs *regs, __u16 code)
763 finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
764 /* Is this the interrupt we are waiting for? */
765 if (finished_sccb == 0)
767 if (finished_sccb != (u32) (addr_t) sclp_init_sccb) {
768 printk(KERN_WARNING SCLP_HEADER "unsolicited interrupt "
769 "for buffer at 0x%x\n", finished_sccb);
772 spin_lock(&sclp_lock);
773 if (sclp_running_state == sclp_running_state_running) {
774 sclp_init_req.status = SCLP_REQ_DONE;
775 sclp_running_state = sclp_running_state_idle;
777 spin_unlock(&sclp_lock);
780 /* Initial init mask request timed out. Modify request state to failed. */
782 sclp_check_timeout(unsigned long data)
786 spin_lock_irqsave(&sclp_lock, flags);
787 if (sclp_running_state == sclp_running_state_running) {
788 sclp_init_req.status = SCLP_REQ_FAILED;
789 sclp_running_state = sclp_running_state_idle;
791 spin_unlock_irqrestore(&sclp_lock, flags);
794 /* Perform a check of the SCLP interface. Return zero if the interface is
795 * available and there are no pending requests from a previous instance.
796 * Return non-zero otherwise. */
798 sclp_check_interface(void)
800 struct init_sccb *sccb;
805 spin_lock_irqsave(&sclp_lock, flags);
806 /* Prepare init mask command */
807 rc = register_early_external_interrupt(0x2401, sclp_check_handler,
810 spin_unlock_irqrestore(&sclp_lock, flags);
813 for (retry = 0; retry <= SCLP_INIT_RETRY; retry++) {
814 __sclp_make_init_req(0, 0);
815 sccb = (struct init_sccb *) sclp_init_req.sccb;
816 rc = service_call(sclp_init_req.command, sccb);
819 sclp_init_req.status = SCLP_REQ_RUNNING;
820 sclp_running_state = sclp_running_state_running;
821 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
822 sclp_check_timeout, 0);
823 spin_unlock_irqrestore(&sclp_lock, flags);
824 /* Enable service-signal interruption - needs to happen
825 * with IRQs enabled. */
827 /* Wait for signal from interrupt or timeout */
829 /* Disable service-signal interruption - needs to happen
830 * with IRQs enabled. */
832 spin_lock_irqsave(&sclp_lock, flags);
833 del_timer(&sclp_request_timer);
834 if (sclp_init_req.status == SCLP_REQ_DONE &&
835 sccb->header.response_code == 0x20) {
841 unregister_early_external_interrupt(0x2401, sclp_check_handler,
843 spin_unlock_irqrestore(&sclp_lock, flags);
847 /* Reboot event handler. Reset send and receive mask to prevent pending SCLP
848 * events from interfering with rebooted system. */
850 sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
856 static struct notifier_block sclp_reboot_notifier = {
857 .notifier_call = sclp_reboot_event
860 /* Initialize SCLP driver. Return zero if driver is operational, non-zero
868 if (!MACHINE_HAS_SCLP)
870 spin_lock_irqsave(&sclp_lock, flags);
871 /* Check for previous or running initialization */
872 if (sclp_init_state != sclp_init_state_uninitialized) {
873 spin_unlock_irqrestore(&sclp_lock, flags);
876 sclp_init_state = sclp_init_state_initializing;
877 /* Set up variables */
878 INIT_LIST_HEAD(&sclp_req_queue);
879 INIT_LIST_HEAD(&sclp_reg_list);
880 list_add(&sclp_state_change_event.list, &sclp_reg_list);
881 init_timer(&sclp_request_timer);
882 /* Check interface */
883 spin_unlock_irqrestore(&sclp_lock, flags);
884 rc = sclp_check_interface();
885 spin_lock_irqsave(&sclp_lock, flags);
887 sclp_init_state = sclp_init_state_uninitialized;
888 spin_unlock_irqrestore(&sclp_lock, flags);
891 /* Register reboot handler */
892 rc = register_reboot_notifier(&sclp_reboot_notifier);
894 sclp_init_state = sclp_init_state_uninitialized;
895 spin_unlock_irqrestore(&sclp_lock, flags);
898 /* Register interrupt handler */
899 rc = register_early_external_interrupt(0x2401, sclp_interrupt_handler,
902 unregister_reboot_notifier(&sclp_reboot_notifier);
903 sclp_init_state = sclp_init_state_uninitialized;
904 spin_unlock_irqrestore(&sclp_lock, flags);
907 sclp_init_state = sclp_init_state_initialized;
908 spin_unlock_irqrestore(&sclp_lock, flags);
909 /* Enable service-signal external interruption - needs to happen with