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
88 #define SCLP_REQUEST_RETRY 3
90 /* Timeout intervals in seconds.*/
91 #define SCLP_BUSY_INTERVAL 2
92 #define SCLP_RETRY_INTERVAL 5
94 static void sclp_process_queue(void);
95 static int sclp_init_mask(int calculate);
96 static int sclp_init(void);
98 /* Perform service call. Return 0 on success, non-zero otherwise. */
100 service_call(sclp_cmdw_t command, void *sccb)
104 __asm__ __volatile__(
105 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
109 : "d" (command), "a" (__pa(sccb))
118 /* Request timeout handler. Restart the request queue. If DATA is non-zero,
119 * force restart of running request. */
121 sclp_request_timeout(unsigned long data)
126 spin_lock_irqsave(&sclp_lock, flags);
127 sclp_running_state = sclp_running_state_idle;
128 spin_unlock_irqrestore(&sclp_lock, flags);
130 sclp_process_queue();
133 /* Set up request retry timer. Called while sclp_lock is locked. */
135 __sclp_set_request_timer(unsigned long time, void (*function)(unsigned long),
138 del_timer(&sclp_request_timer);
139 sclp_request_timer.function = function;
140 sclp_request_timer.data = data;
141 sclp_request_timer.expires = jiffies + time;
142 add_timer(&sclp_request_timer);
145 /* Try to start a request. Return zero if the request was successfully
146 * started or if it will be started at a later time. Return non-zero otherwise.
147 * Called while sclp_lock is locked. */
149 __sclp_start_request(struct sclp_req *req)
153 if (sclp_running_state != sclp_running_state_idle)
155 del_timer(&sclp_request_timer);
156 if (req->start_count <= SCLP_REQUEST_RETRY) {
157 rc = service_call(req->command, req->sccb);
162 /* Sucessfully started request */
163 req->status = SCLP_REQ_RUNNING;
164 sclp_running_state = sclp_running_state_running;
165 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
166 sclp_request_timeout, 1);
168 } else if (rc == -EBUSY) {
169 /* Try again later */
170 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
171 sclp_request_timeout, 0);
175 req->status = SCLP_REQ_FAILED;
179 /* Try to start queued requests. */
181 sclp_process_queue(void)
183 struct sclp_req *req;
187 spin_lock_irqsave(&sclp_lock, flags);
188 if (sclp_running_state != sclp_running_state_idle) {
189 spin_unlock_irqrestore(&sclp_lock, flags);
192 del_timer(&sclp_request_timer);
193 while (!list_empty(&sclp_req_queue)) {
194 req = list_entry(sclp_req_queue.next, struct sclp_req, list);
195 rc = __sclp_start_request(req);
198 /* Request failed. */
199 list_del(&req->list);
201 spin_unlock_irqrestore(&sclp_lock, flags);
202 req->callback(req, req->callback_data);
203 spin_lock_irqsave(&sclp_lock, flags);
206 spin_unlock_irqrestore(&sclp_lock, flags);
209 /* Queue a new request. Return zero on success, non-zero otherwise. */
211 sclp_add_request(struct sclp_req *req)
216 spin_lock_irqsave(&sclp_lock, flags);
217 if ((sclp_init_state != sclp_init_state_initialized ||
218 sclp_activation_state != sclp_activation_state_active) &&
219 req != &sclp_init_req) {
220 spin_unlock_irqrestore(&sclp_lock, flags);
223 req->status = SCLP_REQ_QUEUED;
224 req->start_count = 0;
225 list_add_tail(&req->list, &sclp_req_queue);
227 /* Start if request is first in list */
228 if (req->list.prev == &sclp_req_queue) {
229 rc = __sclp_start_request(req);
231 list_del(&req->list);
233 spin_unlock_irqrestore(&sclp_lock, flags);
237 EXPORT_SYMBOL(sclp_add_request);
239 /* Dispatch events found in request buffer to registered listeners. Return 0
240 * if all events were dispatched, non-zero otherwise. */
242 sclp_dispatch_evbufs(struct sccb_header *sccb)
245 struct evbuf_header *evbuf;
247 struct sclp_register *reg;
251 spin_lock_irqsave(&sclp_lock, flags);
253 for (offset = sizeof(struct sccb_header); offset < sccb->length;
254 offset += evbuf->length) {
255 /* Search for event handler */
256 evbuf = (struct evbuf_header *) ((addr_t) sccb + offset);
258 list_for_each(l, &sclp_reg_list) {
259 reg = list_entry(l, struct sclp_register, list);
260 if (reg->receive_mask & (1 << (32 - evbuf->type)))
265 if (reg && reg->receiver_fn) {
266 spin_unlock_irqrestore(&sclp_lock, flags);
267 reg->receiver_fn(evbuf);
268 spin_lock_irqsave(&sclp_lock, flags);
269 } else if (reg == NULL)
272 spin_unlock_irqrestore(&sclp_lock, flags);
276 /* Read event data request callback. */
278 sclp_read_cb(struct sclp_req *req, void *data)
281 struct sccb_header *sccb;
283 sccb = (struct sccb_header *) req->sccb;
284 if (req->status == SCLP_REQ_DONE && (sccb->response_code == 0x20 ||
285 sccb->response_code == 0x220))
286 sclp_dispatch_evbufs(sccb);
287 spin_lock_irqsave(&sclp_lock, flags);
288 sclp_reading_state = sclp_reading_state_idle;
289 spin_unlock_irqrestore(&sclp_lock, flags);
292 /* Prepare read event data request. Called while sclp_lock is locked. */
294 __sclp_make_read_req(void)
296 struct sccb_header *sccb;
298 sccb = (struct sccb_header *) sclp_read_sccb;
300 memset(&sclp_read_req, 0, sizeof(struct sclp_req));
301 sclp_read_req.command = SCLP_CMDW_READDATA;
302 sclp_read_req.status = SCLP_REQ_QUEUED;
303 sclp_read_req.start_count = 0;
304 sclp_read_req.callback = sclp_read_cb;
305 sclp_read_req.sccb = sccb;
306 sccb->length = PAGE_SIZE;
307 sccb->function_code = 0;
308 sccb->control_mask[2] = 0x80;
311 /* Search request list for request with matching sccb. Return request if found,
312 * NULL otherwise. Called while sclp_lock is locked. */
313 static inline struct sclp_req *
314 __sclp_find_req(u32 sccb)
317 struct sclp_req *req;
319 list_for_each(l, &sclp_req_queue) {
320 req = list_entry(l, struct sclp_req, list);
321 if (sccb == (u32) (addr_t) req->sccb)
327 /* Handler for external interruption. Perform request post-processing.
328 * Prepare read event data request if necessary. Start processing of next
329 * request on queue. */
331 sclp_interrupt_handler(struct pt_regs *regs, __u16 code)
333 struct sclp_req *req;
337 spin_lock(&sclp_lock);
338 finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
339 evbuf_pending = S390_lowcore.ext_params & 0x3;
341 req = __sclp_find_req(finished_sccb);
343 /* Request post-processing */
344 list_del(&req->list);
345 req->status = SCLP_REQ_DONE;
347 spin_unlock(&sclp_lock);
348 req->callback(req, req->callback_data);
349 spin_lock(&sclp_lock);
352 sclp_running_state = sclp_running_state_idle;
354 if (evbuf_pending && sclp_receive_mask != 0 &&
355 sclp_reading_state == sclp_reading_state_idle &&
356 sclp_activation_state == sclp_activation_state_active ) {
357 sclp_reading_state = sclp_reading_state_reading;
358 __sclp_make_read_req();
359 /* Add request to head of queue */
360 list_add(&sclp_read_req.list, &sclp_req_queue);
362 spin_unlock(&sclp_lock);
363 sclp_process_queue();
366 /* Return current Time-Of-Day clock. */
372 asm volatile ("STCK 0(%1)" : "=m" (result) : "a" (&(result)) : "cc");
376 /* Convert interval in jiffies to TOD ticks. */
378 sclp_tod_from_jiffies(unsigned long jiffies)
380 return (u64) (jiffies / HZ) << 32;
383 /* Wait until a currently running request finished. Note: while this function
384 * is running, no timers are served on the calling CPU. */
388 unsigned long psw_mask;
389 unsigned long cr0, cr0_sync;
392 /* We'll be disabling timer interrupts, so we need a custom timeout
395 if (timer_pending(&sclp_request_timer)) {
396 /* Get timeout TOD value */
397 timeout = sclp_get_clock() +
398 sclp_tod_from_jiffies(sclp_request_timer.expires -
401 /* Prevent bottom half from executing once we force interrupts open */
403 /* 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);
421 /* Restore interrupt settings */
422 asm volatile ("SSM 0(%0)"
423 : : "a" (&psw_mask) : "memory");
424 __ctl_load(cr0, 0, 0);
428 EXPORT_SYMBOL(sclp_sync_wait);
430 /* Dispatch changes in send and receive mask to registered listeners. */
432 sclp_dispatch_state_change(void)
435 struct sclp_register *reg;
437 sccb_mask_t receive_mask;
438 sccb_mask_t send_mask;
441 spin_lock_irqsave(&sclp_lock, flags);
443 list_for_each(l, &sclp_reg_list) {
444 reg = list_entry(l, struct sclp_register, list);
445 receive_mask = reg->receive_mask & sclp_receive_mask;
446 send_mask = reg->send_mask & sclp_send_mask;
447 if (reg->sclp_receive_mask != receive_mask ||
448 reg->sclp_send_mask != send_mask) {
449 reg->sclp_receive_mask = receive_mask;
450 reg->sclp_send_mask = send_mask;
455 spin_unlock_irqrestore(&sclp_lock, flags);
456 if (reg && reg->state_change_fn)
457 reg->state_change_fn(reg);
461 struct sclp_statechangebuf {
462 struct evbuf_header header;
463 u8 validity_sclp_active_facility_mask : 1;
464 u8 validity_sclp_receive_mask : 1;
465 u8 validity_sclp_send_mask : 1;
466 u8 validity_read_data_function_mask : 1;
469 u64 sclp_active_facility_mask;
470 sccb_mask_t sclp_receive_mask;
471 sccb_mask_t sclp_send_mask;
472 u32 read_data_function_mask;
473 } __attribute__((packed));
476 /* State change event callback. Inform listeners of changes. */
478 sclp_state_change_cb(struct evbuf_header *evbuf)
481 struct sclp_statechangebuf *scbuf;
483 scbuf = (struct sclp_statechangebuf *) evbuf;
484 if (scbuf->mask_length != sizeof(sccb_mask_t))
486 spin_lock_irqsave(&sclp_lock, flags);
487 if (scbuf->validity_sclp_receive_mask)
488 sclp_receive_mask = scbuf->sclp_receive_mask;
489 if (scbuf->validity_sclp_send_mask)
490 sclp_send_mask = scbuf->sclp_send_mask;
491 spin_unlock_irqrestore(&sclp_lock, flags);
492 sclp_dispatch_state_change();
495 static struct sclp_register sclp_state_change_event = {
496 .receive_mask = EvTyp_StateChange_Mask,
497 .receiver_fn = sclp_state_change_cb
500 /* Calculate receive and send mask of currently registered listeners.
501 * Called while sclp_lock is locked. */
503 __sclp_get_mask(sccb_mask_t *receive_mask, sccb_mask_t *send_mask)
506 struct sclp_register *t;
510 list_for_each(l, &sclp_reg_list) {
511 t = list_entry(l, struct sclp_register, list);
512 *receive_mask |= t->receive_mask;
513 *send_mask |= t->send_mask;
517 /* Register event listener. Return 0 on success, non-zero otherwise. */
519 sclp_register(struct sclp_register *reg)
522 sccb_mask_t receive_mask;
523 sccb_mask_t send_mask;
529 spin_lock_irqsave(&sclp_lock, flags);
530 /* Check event mask for collisions */
531 __sclp_get_mask(&receive_mask, &send_mask);
532 if (reg->receive_mask & receive_mask || reg->send_mask & send_mask) {
533 spin_unlock_irqrestore(&sclp_lock, flags);
536 /* Trigger initial state change callback */
537 reg->sclp_receive_mask = 0;
538 reg->sclp_send_mask = 0;
539 list_add(®->list, &sclp_reg_list);
540 spin_unlock_irqrestore(&sclp_lock, flags);
541 rc = sclp_init_mask(1);
543 spin_lock_irqsave(&sclp_lock, flags);
544 list_del(®->list);
545 spin_unlock_irqrestore(&sclp_lock, flags);
550 EXPORT_SYMBOL(sclp_register);
552 /* Unregister event listener. */
554 sclp_unregister(struct sclp_register *reg)
558 spin_lock_irqsave(&sclp_lock, flags);
559 list_del(®->list);
560 spin_unlock_irqrestore(&sclp_lock, flags);
564 EXPORT_SYMBOL(sclp_unregister);
566 /* Remove event buffers which are marked processed. Return the number of
567 * remaining event buffers. */
569 sclp_remove_processed(struct sccb_header *sccb)
571 struct evbuf_header *evbuf;
575 evbuf = (struct evbuf_header *) (sccb + 1);
577 remaining = sccb->length - sizeof(struct sccb_header);
578 while (remaining > 0) {
579 remaining -= evbuf->length;
580 if (evbuf->flags & 0x80) {
581 sccb->length -= evbuf->length;
582 memcpy(evbuf, (void *) ((addr_t) evbuf + evbuf->length),
586 evbuf = (struct evbuf_header *)
587 ((addr_t) evbuf + evbuf->length);
593 EXPORT_SYMBOL(sclp_remove_processed);
596 struct sccb_header header;
599 sccb_mask_t receive_mask;
600 sccb_mask_t send_mask;
601 sccb_mask_t sclp_send_mask;
602 sccb_mask_t sclp_receive_mask;
603 } __attribute__((packed));
605 /* Prepare init mask request. Called while sclp_lock is locked. */
607 __sclp_make_init_req(u32 receive_mask, u32 send_mask)
609 struct init_sccb *sccb;
611 sccb = (struct init_sccb *) sclp_init_sccb;
613 memset(&sclp_init_req, 0, sizeof(struct sclp_req));
614 sclp_init_req.command = SCLP_CMDW_WRITEMASK;
615 sclp_init_req.status = SCLP_REQ_FILLED;
616 sclp_init_req.start_count = 0;
617 sclp_init_req.callback = NULL;
618 sclp_init_req.callback_data = NULL;
619 sclp_init_req.sccb = sccb;
620 sccb->header.length = sizeof(struct init_sccb);
621 sccb->mask_length = sizeof(sccb_mask_t);
622 sccb->receive_mask = receive_mask;
623 sccb->send_mask = send_mask;
624 sccb->sclp_receive_mask = 0;
625 sccb->sclp_send_mask = 0;
628 /* Start init mask request. If calculate is non-zero, calculate the mask as
629 * requested by registered listeners. Use zero mask otherwise. Return 0 on
630 * success, non-zero otherwise. */
632 sclp_init_mask(int calculate)
635 struct init_sccb *sccb = (struct init_sccb *) sclp_init_sccb;
636 sccb_mask_t receive_mask;
637 sccb_mask_t send_mask;
642 spin_lock_irqsave(&sclp_lock, flags);
643 /* Check if interface is in appropriate state */
644 if (sclp_mask_state != sclp_mask_state_idle) {
645 spin_unlock_irqrestore(&sclp_lock, flags);
648 if (sclp_activation_state == sclp_activation_state_inactive) {
649 spin_unlock_irqrestore(&sclp_lock, flags);
652 sclp_mask_state = sclp_mask_state_initializing;
655 __sclp_get_mask(&receive_mask, &send_mask);
661 for (retry = 0; retry <= SCLP_MASK_RETRY; retry++) {
662 /* Prepare request */
663 __sclp_make_init_req(receive_mask, send_mask);
664 spin_unlock_irqrestore(&sclp_lock, flags);
665 if (sclp_add_request(&sclp_init_req)) {
666 /* Try again later */
667 wait = jiffies + SCLP_BUSY_INTERVAL * HZ;
668 while (time_before(jiffies, wait))
670 spin_lock_irqsave(&sclp_lock, flags);
673 while (sclp_init_req.status != SCLP_REQ_DONE &&
674 sclp_init_req.status != SCLP_REQ_FAILED)
676 spin_lock_irqsave(&sclp_lock, flags);
677 if (sclp_init_req.status == SCLP_REQ_DONE &&
678 sccb->header.response_code == 0x20) {
679 /* Successful request */
681 sclp_receive_mask = sccb->sclp_receive_mask;
682 sclp_send_mask = sccb->sclp_send_mask;
684 sclp_receive_mask = 0;
687 spin_unlock_irqrestore(&sclp_lock, flags);
688 sclp_dispatch_state_change();
689 spin_lock_irqsave(&sclp_lock, flags);
694 sclp_mask_state = sclp_mask_state_idle;
695 spin_unlock_irqrestore(&sclp_lock, flags);
699 /* Deactivate SCLP interface. On success, new requests will be rejected,
700 * events will no longer be dispatched. Return 0 on success, non-zero
703 sclp_deactivate(void)
708 spin_lock_irqsave(&sclp_lock, flags);
709 /* Deactivate can only be called when active */
710 if (sclp_activation_state != sclp_activation_state_active) {
711 spin_unlock_irqrestore(&sclp_lock, flags);
714 sclp_activation_state = sclp_activation_state_deactivating;
715 spin_unlock_irqrestore(&sclp_lock, flags);
716 rc = sclp_init_mask(0);
717 spin_lock_irqsave(&sclp_lock, flags);
719 sclp_activation_state = sclp_activation_state_inactive;
721 sclp_activation_state = sclp_activation_state_active;
722 spin_unlock_irqrestore(&sclp_lock, flags);
726 EXPORT_SYMBOL(sclp_deactivate);
728 /* Reactivate SCLP interface after sclp_deactivate. On success, new
729 * requests will be accepted, events will be dispatched again. Return 0 on
730 * success, non-zero otherwise. */
732 sclp_reactivate(void)
737 spin_lock_irqsave(&sclp_lock, flags);
738 /* Reactivate can only be called when inactive */
739 if (sclp_activation_state != sclp_activation_state_inactive) {
740 spin_unlock_irqrestore(&sclp_lock, flags);
743 sclp_activation_state = sclp_activation_state_activating;
744 spin_unlock_irqrestore(&sclp_lock, flags);
745 rc = sclp_init_mask(1);
746 spin_lock_irqsave(&sclp_lock, flags);
748 sclp_activation_state = sclp_activation_state_active;
750 sclp_activation_state = sclp_activation_state_inactive;
751 spin_unlock_irqrestore(&sclp_lock, flags);
755 EXPORT_SYMBOL(sclp_reactivate);
757 /* Handler for external interruption used during initialization. Modify
758 * request state to done. */
760 sclp_check_handler(struct pt_regs *regs, __u16 code)
764 finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
765 /* Is this the interrupt we are waiting for? */
766 if (finished_sccb == 0)
768 if (finished_sccb != (u32) (addr_t) sclp_init_sccb) {
769 printk(KERN_WARNING SCLP_HEADER "unsolicited interrupt "
770 "for buffer at 0x%x\n", finished_sccb);
773 spin_lock(&sclp_lock);
774 if (sclp_running_state == sclp_running_state_running) {
775 sclp_init_req.status = SCLP_REQ_DONE;
776 sclp_running_state = sclp_running_state_idle;
778 spin_unlock(&sclp_lock);
781 /* Initial init mask request timed out. Modify request state to failed. */
783 sclp_check_timeout(unsigned long data)
787 spin_lock_irqsave(&sclp_lock, flags);
788 if (sclp_running_state == sclp_running_state_running) {
789 sclp_init_req.status = SCLP_REQ_FAILED;
790 sclp_running_state = sclp_running_state_idle;
792 spin_unlock_irqrestore(&sclp_lock, flags);
795 /* Perform a check of the SCLP interface. Return zero if the interface is
796 * available and there are no pending requests from a previous instance.
797 * Return non-zero otherwise. */
799 sclp_check_interface(void)
801 struct init_sccb *sccb;
806 spin_lock_irqsave(&sclp_lock, flags);
807 /* Prepare init mask command */
808 rc = register_early_external_interrupt(0x2401, sclp_check_handler,
811 spin_unlock_irqrestore(&sclp_lock, flags);
814 for (retry = 0; retry <= SCLP_INIT_RETRY; retry++) {
815 __sclp_make_init_req(0, 0);
816 sccb = (struct init_sccb *) sclp_init_req.sccb;
817 rc = service_call(sclp_init_req.command, sccb);
820 sclp_init_req.status = SCLP_REQ_RUNNING;
821 sclp_running_state = sclp_running_state_running;
822 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
823 sclp_check_timeout, 0);
824 spin_unlock_irqrestore(&sclp_lock, flags);
825 /* Enable service-signal interruption - needs to happen
826 * with IRQs enabled. */
828 /* Wait for signal from interrupt or timeout */
830 /* Disable service-signal interruption - needs to happen
831 * with IRQs enabled. */
833 spin_lock_irqsave(&sclp_lock, flags);
834 del_timer(&sclp_request_timer);
835 if (sclp_init_req.status == SCLP_REQ_DONE &&
836 sccb->header.response_code == 0x20) {
842 unregister_early_external_interrupt(0x2401, sclp_check_handler,
844 spin_unlock_irqrestore(&sclp_lock, flags);
848 /* Reboot event handler. Reset send and receive mask to prevent pending SCLP
849 * events from interfering with rebooted system. */
851 sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
857 static struct notifier_block sclp_reboot_notifier = {
858 .notifier_call = sclp_reboot_event
861 /* Initialize SCLP driver. Return zero if driver is operational, non-zero
869 if (!MACHINE_HAS_SCLP)
871 spin_lock_irqsave(&sclp_lock, flags);
872 /* Check for previous or running initialization */
873 if (sclp_init_state != sclp_init_state_uninitialized) {
874 spin_unlock_irqrestore(&sclp_lock, flags);
877 sclp_init_state = sclp_init_state_initializing;
878 /* Set up variables */
879 INIT_LIST_HEAD(&sclp_req_queue);
880 INIT_LIST_HEAD(&sclp_reg_list);
881 list_add(&sclp_state_change_event.list, &sclp_reg_list);
882 init_timer(&sclp_request_timer);
883 /* Check interface */
884 spin_unlock_irqrestore(&sclp_lock, flags);
885 rc = sclp_check_interface();
886 spin_lock_irqsave(&sclp_lock, flags);
888 sclp_init_state = sclp_init_state_uninitialized;
889 spin_unlock_irqrestore(&sclp_lock, flags);
892 /* Register reboot handler */
893 rc = register_reboot_notifier(&sclp_reboot_notifier);
895 sclp_init_state = sclp_init_state_uninitialized;
896 spin_unlock_irqrestore(&sclp_lock, flags);
899 /* Register interrupt handler */
900 rc = register_early_external_interrupt(0x2401, sclp_interrupt_handler,
903 unregister_reboot_notifier(&sclp_reboot_notifier);
904 sclp_init_state = sclp_init_state_uninitialized;
905 spin_unlock_irqrestore(&sclp_lock, flags);
908 sclp_init_state = sclp_init_state_initialized;
909 spin_unlock_irqrestore(&sclp_lock, flags);
910 /* Enable service-signal external interruption - needs to happen with