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_reset_pending
64 } sclp_running_state = sclp_running_state_idle;
66 /* Internal state: is a read request pending? */
67 static volatile enum sclp_reading_state_t {
68 sclp_reading_state_idle,
69 sclp_reading_state_reading
70 } sclp_reading_state = sclp_reading_state_idle;
72 /* Internal state: is the driver currently serving requests? */
73 static volatile enum sclp_activation_state_t {
74 sclp_activation_state_active,
75 sclp_activation_state_deactivating,
76 sclp_activation_state_inactive,
77 sclp_activation_state_activating
78 } sclp_activation_state = sclp_activation_state_active;
80 /* Internal state: is an init mask request pending? */
81 static volatile enum sclp_mask_state_t {
83 sclp_mask_state_initializing
84 } sclp_mask_state = sclp_mask_state_idle;
86 /* Maximum retry counts */
87 #define SCLP_INIT_RETRY 3
88 #define SCLP_MASK_RETRY 3
90 /* Timeout intervals in seconds.*/
91 #define SCLP_BUSY_INTERVAL 10
92 #define SCLP_RETRY_INTERVAL 30
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 sclp_service_call(sclp_cmdw_t command, void *sccb)
105 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
108 : "=&d" (cc) : "d" (command), "a" (__pa(sccb))
117 static inline void __sclp_make_read_req(void);
120 __sclp_queue_read_req(void)
122 if (sclp_reading_state == sclp_reading_state_idle) {
123 sclp_reading_state = sclp_reading_state_reading;
124 __sclp_make_read_req();
125 /* Add request to head of queue */
126 list_add(&sclp_read_req.list, &sclp_req_queue);
130 /* Set up request retry timer. Called while sclp_lock is locked. */
132 __sclp_set_request_timer(unsigned long time, void (*function)(unsigned long),
135 del_timer(&sclp_request_timer);
136 sclp_request_timer.function = function;
137 sclp_request_timer.data = data;
138 sclp_request_timer.expires = jiffies + time;
139 add_timer(&sclp_request_timer);
142 /* Request timeout handler. Restart the request queue. If DATA is non-zero,
143 * force restart of running request. */
145 sclp_request_timeout(unsigned long data)
149 spin_lock_irqsave(&sclp_lock, flags);
151 if (sclp_running_state == sclp_running_state_running) {
152 /* Break running state and queue NOP read event request
153 * to get a defined interface state. */
154 __sclp_queue_read_req();
155 sclp_running_state = sclp_running_state_idle;
158 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
159 sclp_request_timeout, 0);
161 spin_unlock_irqrestore(&sclp_lock, flags);
162 sclp_process_queue();
165 /* Try to start a request. Return zero if the request was successfully
166 * started or if it will be started at a later time. Return non-zero otherwise.
167 * Called while sclp_lock is locked. */
169 __sclp_start_request(struct sclp_req *req)
173 if (sclp_running_state != sclp_running_state_idle)
175 del_timer(&sclp_request_timer);
176 rc = sclp_service_call(req->command, req->sccb);
180 /* Sucessfully started request */
181 req->status = SCLP_REQ_RUNNING;
182 sclp_running_state = sclp_running_state_running;
183 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
184 sclp_request_timeout, 1);
186 } else if (rc == -EBUSY) {
187 /* Try again later */
188 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
189 sclp_request_timeout, 0);
193 req->status = SCLP_REQ_FAILED;
197 /* Try to start queued requests. */
199 sclp_process_queue(void)
201 struct sclp_req *req;
205 spin_lock_irqsave(&sclp_lock, flags);
206 if (sclp_running_state != sclp_running_state_idle) {
207 spin_unlock_irqrestore(&sclp_lock, flags);
210 del_timer(&sclp_request_timer);
211 while (!list_empty(&sclp_req_queue)) {
212 req = list_entry(sclp_req_queue.next, struct sclp_req, list);
213 rc = __sclp_start_request(req);
217 if (req->start_count > 1) {
218 /* Cannot abort already submitted request - could still
219 * be active at the SCLP */
220 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
221 sclp_request_timeout, 0);
224 /* Post-processing for aborted request */
225 list_del(&req->list);
227 spin_unlock_irqrestore(&sclp_lock, flags);
228 req->callback(req, req->callback_data);
229 spin_lock_irqsave(&sclp_lock, flags);
232 spin_unlock_irqrestore(&sclp_lock, flags);
235 /* Queue a new request. Return zero on success, non-zero otherwise. */
237 sclp_add_request(struct sclp_req *req)
242 spin_lock_irqsave(&sclp_lock, flags);
243 if ((sclp_init_state != sclp_init_state_initialized ||
244 sclp_activation_state != sclp_activation_state_active) &&
245 req != &sclp_init_req) {
246 spin_unlock_irqrestore(&sclp_lock, flags);
249 req->status = SCLP_REQ_QUEUED;
250 req->start_count = 0;
251 list_add_tail(&req->list, &sclp_req_queue);
253 /* Start if request is first in list */
254 if (sclp_running_state == sclp_running_state_idle &&
255 req->list.prev == &sclp_req_queue) {
256 rc = __sclp_start_request(req);
258 list_del(&req->list);
260 spin_unlock_irqrestore(&sclp_lock, flags);
264 EXPORT_SYMBOL(sclp_add_request);
266 /* Dispatch events found in request buffer to registered listeners. Return 0
267 * if all events were dispatched, non-zero otherwise. */
269 sclp_dispatch_evbufs(struct sccb_header *sccb)
272 struct evbuf_header *evbuf;
274 struct sclp_register *reg;
278 spin_lock_irqsave(&sclp_lock, flags);
280 for (offset = sizeof(struct sccb_header); offset < sccb->length;
281 offset += evbuf->length) {
282 /* Search for event handler */
283 evbuf = (struct evbuf_header *) ((addr_t) sccb + offset);
285 list_for_each(l, &sclp_reg_list) {
286 reg = list_entry(l, struct sclp_register, list);
287 if (reg->receive_mask & (1 << (32 - evbuf->type)))
292 if (reg && reg->receiver_fn) {
293 spin_unlock_irqrestore(&sclp_lock, flags);
294 reg->receiver_fn(evbuf);
295 spin_lock_irqsave(&sclp_lock, flags);
296 } else if (reg == NULL)
299 spin_unlock_irqrestore(&sclp_lock, flags);
303 /* Read event data request callback. */
305 sclp_read_cb(struct sclp_req *req, void *data)
308 struct sccb_header *sccb;
310 sccb = (struct sccb_header *) req->sccb;
311 if (req->status == SCLP_REQ_DONE && (sccb->response_code == 0x20 ||
312 sccb->response_code == 0x220))
313 sclp_dispatch_evbufs(sccb);
314 spin_lock_irqsave(&sclp_lock, flags);
315 sclp_reading_state = sclp_reading_state_idle;
316 spin_unlock_irqrestore(&sclp_lock, flags);
319 /* Prepare read event data request. Called while sclp_lock is locked. */
321 __sclp_make_read_req(void)
323 struct sccb_header *sccb;
325 sccb = (struct sccb_header *) sclp_read_sccb;
327 memset(&sclp_read_req, 0, sizeof(struct sclp_req));
328 sclp_read_req.command = SCLP_CMDW_READ_EVENT_DATA;
329 sclp_read_req.status = SCLP_REQ_QUEUED;
330 sclp_read_req.start_count = 0;
331 sclp_read_req.callback = sclp_read_cb;
332 sclp_read_req.sccb = sccb;
333 sccb->length = PAGE_SIZE;
334 sccb->function_code = 0;
335 sccb->control_mask[2] = 0x80;
338 /* Search request list for request with matching sccb. Return request if found,
339 * NULL otherwise. Called while sclp_lock is locked. */
340 static inline struct sclp_req *
341 __sclp_find_req(u32 sccb)
344 struct sclp_req *req;
346 list_for_each(l, &sclp_req_queue) {
347 req = list_entry(l, struct sclp_req, list);
348 if (sccb == (u32) (addr_t) req->sccb)
354 /* Handler for external interruption. Perform request post-processing.
355 * Prepare read event data request if necessary. Start processing of next
356 * request on queue. */
358 sclp_interrupt_handler(__u16 code)
360 struct sclp_req *req;
364 spin_lock(&sclp_lock);
365 finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
366 evbuf_pending = S390_lowcore.ext_params & 0x3;
368 del_timer(&sclp_request_timer);
369 sclp_running_state = sclp_running_state_reset_pending;
370 req = __sclp_find_req(finished_sccb);
372 /* Request post-processing */
373 list_del(&req->list);
374 req->status = SCLP_REQ_DONE;
376 spin_unlock(&sclp_lock);
377 req->callback(req, req->callback_data);
378 spin_lock(&sclp_lock);
381 sclp_running_state = sclp_running_state_idle;
383 if (evbuf_pending && sclp_receive_mask != 0 &&
384 sclp_activation_state == sclp_activation_state_active)
385 __sclp_queue_read_req();
386 spin_unlock(&sclp_lock);
387 sclp_process_queue();
390 /* Convert interval in jiffies to TOD ticks. */
392 sclp_tod_from_jiffies(unsigned long jiffies)
394 return (u64) (jiffies / HZ) << 32;
397 /* Wait until a currently running request finished. Note: while this function
398 * is running, no timers are served on the calling CPU. */
403 unsigned long cr0, cr0_sync;
407 /* We'll be disabling timer interrupts, so we need a custom timeout
410 if (timer_pending(&sclp_request_timer)) {
411 /* Get timeout TOD value */
412 timeout = get_clock() +
413 sclp_tod_from_jiffies(sclp_request_timer.expires -
416 local_irq_save(flags);
417 /* Prevent bottom half from executing once we force interrupts open */
418 irq_context = in_interrupt();
421 /* Enable service-signal interruption, disable timer interrupts */
423 __ctl_store(cr0, 0, 0);
425 cr0_sync |= 0x00000200;
426 cr0_sync &= 0xFFFFF3AC;
427 __ctl_load(cr0_sync, 0, 0);
428 __raw_local_irq_stosm(0x01);
429 /* Loop until driver state indicates finished request */
430 while (sclp_running_state != sclp_running_state_idle) {
431 /* Check for expired request timer */
432 if (timer_pending(&sclp_request_timer) &&
433 get_clock() > timeout &&
434 del_timer(&sclp_request_timer))
435 sclp_request_timer.function(sclp_request_timer.data);
439 __ctl_load(cr0, 0, 0);
442 local_irq_restore(flags);
445 EXPORT_SYMBOL(sclp_sync_wait);
447 /* Dispatch changes in send and receive mask to registered listeners. */
449 sclp_dispatch_state_change(void)
452 struct sclp_register *reg;
454 sccb_mask_t receive_mask;
455 sccb_mask_t send_mask;
458 spin_lock_irqsave(&sclp_lock, flags);
460 list_for_each(l, &sclp_reg_list) {
461 reg = list_entry(l, struct sclp_register, list);
462 receive_mask = reg->receive_mask & sclp_receive_mask;
463 send_mask = reg->send_mask & sclp_send_mask;
464 if (reg->sclp_receive_mask != receive_mask ||
465 reg->sclp_send_mask != send_mask) {
466 reg->sclp_receive_mask = receive_mask;
467 reg->sclp_send_mask = send_mask;
472 spin_unlock_irqrestore(&sclp_lock, flags);
473 if (reg && reg->state_change_fn)
474 reg->state_change_fn(reg);
478 struct sclp_statechangebuf {
479 struct evbuf_header header;
480 u8 validity_sclp_active_facility_mask : 1;
481 u8 validity_sclp_receive_mask : 1;
482 u8 validity_sclp_send_mask : 1;
483 u8 validity_read_data_function_mask : 1;
486 u64 sclp_active_facility_mask;
487 sccb_mask_t sclp_receive_mask;
488 sccb_mask_t sclp_send_mask;
489 u32 read_data_function_mask;
490 } __attribute__((packed));
493 /* State change event callback. Inform listeners of changes. */
495 sclp_state_change_cb(struct evbuf_header *evbuf)
498 struct sclp_statechangebuf *scbuf;
500 scbuf = (struct sclp_statechangebuf *) evbuf;
501 if (scbuf->mask_length != sizeof(sccb_mask_t))
503 spin_lock_irqsave(&sclp_lock, flags);
504 if (scbuf->validity_sclp_receive_mask)
505 sclp_receive_mask = scbuf->sclp_receive_mask;
506 if (scbuf->validity_sclp_send_mask)
507 sclp_send_mask = scbuf->sclp_send_mask;
508 spin_unlock_irqrestore(&sclp_lock, flags);
509 sclp_dispatch_state_change();
512 static struct sclp_register sclp_state_change_event = {
513 .receive_mask = EvTyp_StateChange_Mask,
514 .receiver_fn = sclp_state_change_cb
517 /* Calculate receive and send mask of currently registered listeners.
518 * Called while sclp_lock is locked. */
520 __sclp_get_mask(sccb_mask_t *receive_mask, sccb_mask_t *send_mask)
523 struct sclp_register *t;
527 list_for_each(l, &sclp_reg_list) {
528 t = list_entry(l, struct sclp_register, list);
529 *receive_mask |= t->receive_mask;
530 *send_mask |= t->send_mask;
534 /* Register event listener. Return 0 on success, non-zero otherwise. */
536 sclp_register(struct sclp_register *reg)
539 sccb_mask_t receive_mask;
540 sccb_mask_t send_mask;
546 spin_lock_irqsave(&sclp_lock, flags);
547 /* Check event mask for collisions */
548 __sclp_get_mask(&receive_mask, &send_mask);
549 if (reg->receive_mask & receive_mask || reg->send_mask & send_mask) {
550 spin_unlock_irqrestore(&sclp_lock, flags);
553 /* Trigger initial state change callback */
554 reg->sclp_receive_mask = 0;
555 reg->sclp_send_mask = 0;
556 list_add(®->list, &sclp_reg_list);
557 spin_unlock_irqrestore(&sclp_lock, flags);
558 rc = sclp_init_mask(1);
560 spin_lock_irqsave(&sclp_lock, flags);
561 list_del(®->list);
562 spin_unlock_irqrestore(&sclp_lock, flags);
567 EXPORT_SYMBOL(sclp_register);
569 /* Unregister event listener. */
571 sclp_unregister(struct sclp_register *reg)
575 spin_lock_irqsave(&sclp_lock, flags);
576 list_del(®->list);
577 spin_unlock_irqrestore(&sclp_lock, flags);
581 EXPORT_SYMBOL(sclp_unregister);
583 /* Remove event buffers which are marked processed. Return the number of
584 * remaining event buffers. */
586 sclp_remove_processed(struct sccb_header *sccb)
588 struct evbuf_header *evbuf;
592 evbuf = (struct evbuf_header *) (sccb + 1);
594 remaining = sccb->length - sizeof(struct sccb_header);
595 while (remaining > 0) {
596 remaining -= evbuf->length;
597 if (evbuf->flags & 0x80) {
598 sccb->length -= evbuf->length;
599 memcpy(evbuf, (void *) ((addr_t) evbuf + evbuf->length),
603 evbuf = (struct evbuf_header *)
604 ((addr_t) evbuf + evbuf->length);
610 EXPORT_SYMBOL(sclp_remove_processed);
613 struct sccb_header header;
616 sccb_mask_t receive_mask;
617 sccb_mask_t send_mask;
618 sccb_mask_t sclp_send_mask;
619 sccb_mask_t sclp_receive_mask;
620 } __attribute__((packed));
622 /* Prepare init mask request. Called while sclp_lock is locked. */
624 __sclp_make_init_req(u32 receive_mask, u32 send_mask)
626 struct init_sccb *sccb;
628 sccb = (struct init_sccb *) sclp_init_sccb;
630 memset(&sclp_init_req, 0, sizeof(struct sclp_req));
631 sclp_init_req.command = SCLP_CMDW_WRITE_EVENT_MASK;
632 sclp_init_req.status = SCLP_REQ_FILLED;
633 sclp_init_req.start_count = 0;
634 sclp_init_req.callback = NULL;
635 sclp_init_req.callback_data = NULL;
636 sclp_init_req.sccb = sccb;
637 sccb->header.length = sizeof(struct init_sccb);
638 sccb->mask_length = sizeof(sccb_mask_t);
639 sccb->receive_mask = receive_mask;
640 sccb->send_mask = send_mask;
641 sccb->sclp_receive_mask = 0;
642 sccb->sclp_send_mask = 0;
645 /* Start init mask request. If calculate is non-zero, calculate the mask as
646 * requested by registered listeners. Use zero mask otherwise. Return 0 on
647 * success, non-zero otherwise. */
649 sclp_init_mask(int calculate)
652 struct init_sccb *sccb = (struct init_sccb *) sclp_init_sccb;
653 sccb_mask_t receive_mask;
654 sccb_mask_t send_mask;
659 spin_lock_irqsave(&sclp_lock, flags);
660 /* Check if interface is in appropriate state */
661 if (sclp_mask_state != sclp_mask_state_idle) {
662 spin_unlock_irqrestore(&sclp_lock, flags);
665 if (sclp_activation_state == sclp_activation_state_inactive) {
666 spin_unlock_irqrestore(&sclp_lock, flags);
669 sclp_mask_state = sclp_mask_state_initializing;
672 __sclp_get_mask(&receive_mask, &send_mask);
678 for (retry = 0; retry <= SCLP_MASK_RETRY; retry++) {
679 /* Prepare request */
680 __sclp_make_init_req(receive_mask, send_mask);
681 spin_unlock_irqrestore(&sclp_lock, flags);
682 if (sclp_add_request(&sclp_init_req)) {
683 /* Try again later */
684 wait = jiffies + SCLP_BUSY_INTERVAL * HZ;
685 while (time_before(jiffies, wait))
687 spin_lock_irqsave(&sclp_lock, flags);
690 while (sclp_init_req.status != SCLP_REQ_DONE &&
691 sclp_init_req.status != SCLP_REQ_FAILED)
693 spin_lock_irqsave(&sclp_lock, flags);
694 if (sclp_init_req.status == SCLP_REQ_DONE &&
695 sccb->header.response_code == 0x20) {
696 /* Successful request */
698 sclp_receive_mask = sccb->sclp_receive_mask;
699 sclp_send_mask = sccb->sclp_send_mask;
701 sclp_receive_mask = 0;
704 spin_unlock_irqrestore(&sclp_lock, flags);
705 sclp_dispatch_state_change();
706 spin_lock_irqsave(&sclp_lock, flags);
711 sclp_mask_state = sclp_mask_state_idle;
712 spin_unlock_irqrestore(&sclp_lock, flags);
716 /* Deactivate SCLP interface. On success, new requests will be rejected,
717 * events will no longer be dispatched. Return 0 on success, non-zero
720 sclp_deactivate(void)
725 spin_lock_irqsave(&sclp_lock, flags);
726 /* Deactivate can only be called when active */
727 if (sclp_activation_state != sclp_activation_state_active) {
728 spin_unlock_irqrestore(&sclp_lock, flags);
731 sclp_activation_state = sclp_activation_state_deactivating;
732 spin_unlock_irqrestore(&sclp_lock, flags);
733 rc = sclp_init_mask(0);
734 spin_lock_irqsave(&sclp_lock, flags);
736 sclp_activation_state = sclp_activation_state_inactive;
738 sclp_activation_state = sclp_activation_state_active;
739 spin_unlock_irqrestore(&sclp_lock, flags);
743 EXPORT_SYMBOL(sclp_deactivate);
745 /* Reactivate SCLP interface after sclp_deactivate. On success, new
746 * requests will be accepted, events will be dispatched again. Return 0 on
747 * success, non-zero otherwise. */
749 sclp_reactivate(void)
754 spin_lock_irqsave(&sclp_lock, flags);
755 /* Reactivate can only be called when inactive */
756 if (sclp_activation_state != sclp_activation_state_inactive) {
757 spin_unlock_irqrestore(&sclp_lock, flags);
760 sclp_activation_state = sclp_activation_state_activating;
761 spin_unlock_irqrestore(&sclp_lock, flags);
762 rc = sclp_init_mask(1);
763 spin_lock_irqsave(&sclp_lock, flags);
765 sclp_activation_state = sclp_activation_state_active;
767 sclp_activation_state = sclp_activation_state_inactive;
768 spin_unlock_irqrestore(&sclp_lock, flags);
772 EXPORT_SYMBOL(sclp_reactivate);
774 /* Handler for external interruption used during initialization. Modify
775 * request state to done. */
777 sclp_check_handler(__u16 code)
781 finished_sccb = S390_lowcore.ext_params & 0xfffffff8;
782 /* Is this the interrupt we are waiting for? */
783 if (finished_sccb == 0)
785 if (finished_sccb != (u32) (addr_t) sclp_init_sccb) {
786 printk(KERN_WARNING SCLP_HEADER "unsolicited interrupt "
787 "for buffer at 0x%x\n", finished_sccb);
790 spin_lock(&sclp_lock);
791 if (sclp_running_state == sclp_running_state_running) {
792 sclp_init_req.status = SCLP_REQ_DONE;
793 sclp_running_state = sclp_running_state_idle;
795 spin_unlock(&sclp_lock);
798 /* Initial init mask request timed out. Modify request state to failed. */
800 sclp_check_timeout(unsigned long data)
804 spin_lock_irqsave(&sclp_lock, flags);
805 if (sclp_running_state == sclp_running_state_running) {
806 sclp_init_req.status = SCLP_REQ_FAILED;
807 sclp_running_state = sclp_running_state_idle;
809 spin_unlock_irqrestore(&sclp_lock, flags);
812 /* Perform a check of the SCLP interface. Return zero if the interface is
813 * available and there are no pending requests from a previous instance.
814 * Return non-zero otherwise. */
816 sclp_check_interface(void)
818 struct init_sccb *sccb;
823 spin_lock_irqsave(&sclp_lock, flags);
824 /* Prepare init mask command */
825 rc = register_early_external_interrupt(0x2401, sclp_check_handler,
828 spin_unlock_irqrestore(&sclp_lock, flags);
831 for (retry = 0; retry <= SCLP_INIT_RETRY; retry++) {
832 __sclp_make_init_req(0, 0);
833 sccb = (struct init_sccb *) sclp_init_req.sccb;
834 rc = sclp_service_call(sclp_init_req.command, sccb);
837 sclp_init_req.status = SCLP_REQ_RUNNING;
838 sclp_running_state = sclp_running_state_running;
839 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
840 sclp_check_timeout, 0);
841 spin_unlock_irqrestore(&sclp_lock, flags);
842 /* Enable service-signal interruption - needs to happen
843 * with IRQs enabled. */
845 /* Wait for signal from interrupt or timeout */
847 /* Disable service-signal interruption - needs to happen
848 * with IRQs enabled. */
850 spin_lock_irqsave(&sclp_lock, flags);
851 del_timer(&sclp_request_timer);
852 if (sclp_init_req.status == SCLP_REQ_DONE &&
853 sccb->header.response_code == 0x20) {
859 unregister_early_external_interrupt(0x2401, sclp_check_handler,
861 spin_unlock_irqrestore(&sclp_lock, flags);
865 /* Reboot event handler. Reset send and receive mask to prevent pending SCLP
866 * events from interfering with rebooted system. */
868 sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
874 static struct notifier_block sclp_reboot_notifier = {
875 .notifier_call = sclp_reboot_event
878 /* Initialize SCLP driver. Return zero if driver is operational, non-zero
886 if (!MACHINE_HAS_SCLP)
888 spin_lock_irqsave(&sclp_lock, flags);
889 /* Check for previous or running initialization */
890 if (sclp_init_state != sclp_init_state_uninitialized) {
891 spin_unlock_irqrestore(&sclp_lock, flags);
894 sclp_init_state = sclp_init_state_initializing;
895 /* Set up variables */
896 INIT_LIST_HEAD(&sclp_req_queue);
897 INIT_LIST_HEAD(&sclp_reg_list);
898 list_add(&sclp_state_change_event.list, &sclp_reg_list);
899 init_timer(&sclp_request_timer);
900 /* Check interface */
901 spin_unlock_irqrestore(&sclp_lock, flags);
902 rc = sclp_check_interface();
903 spin_lock_irqsave(&sclp_lock, flags);
905 sclp_init_state = sclp_init_state_uninitialized;
906 spin_unlock_irqrestore(&sclp_lock, flags);
909 /* Register reboot handler */
910 rc = register_reboot_notifier(&sclp_reboot_notifier);
912 sclp_init_state = sclp_init_state_uninitialized;
913 spin_unlock_irqrestore(&sclp_lock, flags);
916 /* Register interrupt handler */
917 rc = register_early_external_interrupt(0x2401, sclp_interrupt_handler,
920 unregister_reboot_notifier(&sclp_reboot_notifier);
921 sclp_init_state = sclp_init_state_uninitialized;
922 spin_unlock_irqrestore(&sclp_lock, flags);
925 sclp_init_state = sclp_init_state_initialized;
926 spin_unlock_irqrestore(&sclp_lock, flags);
927 /* Enable service-signal external interruption - needs to happen with