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
;
386 unsigned long cr0
, cr0_sync
;
389 /* We'll be disabling timer interrupts, so we need a custom timeout
392 if (timer_pending(&sclp_request_timer
)) {
393 /* Get timeout TOD value */
394 timeout
= sclp_get_clock() +
395 sclp_tod_from_jiffies(sclp_request_timer
.expires
-
398 /* Prevent bottom half from executing once we force interrupts open */
400 /* Enable service-signal interruption, disable timer interrupts */
401 __ctl_store(cr0
, 0, 0);
403 cr0_sync
|= 0x00000200;
404 cr0_sync
&= 0xFFFFF3AC;
405 __ctl_load(cr0_sync
, 0, 0);
406 asm volatile ("STOSM 0(%1),0x01"
407 : "=m" (psw_mask
) : "a" (&psw_mask
) : "memory");
408 /* Loop until driver state indicates finished request */
409 while (sclp_running_state
!= sclp_running_state_idle
) {
410 /* Check for expired request timer */
411 if (timer_pending(&sclp_request_timer
) &&
412 sclp_get_clock() > timeout
&&
413 del_timer(&sclp_request_timer
))
414 sclp_request_timer
.function(sclp_request_timer
.data
);
418 /* Restore interrupt settings */
419 asm volatile ("SSM 0(%0)"
420 : : "a" (&psw_mask
) : "memory");
421 __ctl_load(cr0
, 0, 0);
425 EXPORT_SYMBOL(sclp_sync_wait
);
427 /* Dispatch changes in send and receive mask to registered listeners. */
429 sclp_dispatch_state_change(void)
432 struct sclp_register
*reg
;
434 sccb_mask_t receive_mask
;
435 sccb_mask_t send_mask
;
438 spin_lock_irqsave(&sclp_lock
, flags
);
440 list_for_each(l
, &sclp_reg_list
) {
441 reg
= list_entry(l
, struct sclp_register
, list
);
442 receive_mask
= reg
->receive_mask
& sclp_receive_mask
;
443 send_mask
= reg
->send_mask
& sclp_send_mask
;
444 if (reg
->sclp_receive_mask
!= receive_mask
||
445 reg
->sclp_send_mask
!= send_mask
) {
446 reg
->sclp_receive_mask
= receive_mask
;
447 reg
->sclp_send_mask
= send_mask
;
452 spin_unlock_irqrestore(&sclp_lock
, flags
);
453 if (reg
&& reg
->state_change_fn
)
454 reg
->state_change_fn(reg
);
458 struct sclp_statechangebuf
{
459 struct evbuf_header header
;
460 u8 validity_sclp_active_facility_mask
: 1;
461 u8 validity_sclp_receive_mask
: 1;
462 u8 validity_sclp_send_mask
: 1;
463 u8 validity_read_data_function_mask
: 1;
466 u64 sclp_active_facility_mask
;
467 sccb_mask_t sclp_receive_mask
;
468 sccb_mask_t sclp_send_mask
;
469 u32 read_data_function_mask
;
470 } __attribute__((packed
));
473 /* State change event callback. Inform listeners of changes. */
475 sclp_state_change_cb(struct evbuf_header
*evbuf
)
478 struct sclp_statechangebuf
*scbuf
;
480 scbuf
= (struct sclp_statechangebuf
*) evbuf
;
481 if (scbuf
->mask_length
!= sizeof(sccb_mask_t
))
483 spin_lock_irqsave(&sclp_lock
, flags
);
484 if (scbuf
->validity_sclp_receive_mask
)
485 sclp_receive_mask
= scbuf
->sclp_receive_mask
;
486 if (scbuf
->validity_sclp_send_mask
)
487 sclp_send_mask
= scbuf
->sclp_send_mask
;
488 spin_unlock_irqrestore(&sclp_lock
, flags
);
489 sclp_dispatch_state_change();
492 static struct sclp_register sclp_state_change_event
= {
493 .receive_mask
= EvTyp_StateChange_Mask
,
494 .receiver_fn
= sclp_state_change_cb
497 /* Calculate receive and send mask of currently registered listeners.
498 * Called while sclp_lock is locked. */
500 __sclp_get_mask(sccb_mask_t
*receive_mask
, sccb_mask_t
*send_mask
)
503 struct sclp_register
*t
;
507 list_for_each(l
, &sclp_reg_list
) {
508 t
= list_entry(l
, struct sclp_register
, list
);
509 *receive_mask
|= t
->receive_mask
;
510 *send_mask
|= t
->send_mask
;
514 /* Register event listener. Return 0 on success, non-zero otherwise. */
516 sclp_register(struct sclp_register
*reg
)
519 sccb_mask_t receive_mask
;
520 sccb_mask_t send_mask
;
526 spin_lock_irqsave(&sclp_lock
, flags
);
527 /* Check event mask for collisions */
528 __sclp_get_mask(&receive_mask
, &send_mask
);
529 if (reg
->receive_mask
& receive_mask
|| reg
->send_mask
& send_mask
) {
530 spin_unlock_irqrestore(&sclp_lock
, flags
);
533 /* Trigger initial state change callback */
534 reg
->sclp_receive_mask
= 0;
535 reg
->sclp_send_mask
= 0;
536 list_add(®
->list
, &sclp_reg_list
);
537 spin_unlock_irqrestore(&sclp_lock
, flags
);
538 rc
= sclp_init_mask(1);
540 spin_lock_irqsave(&sclp_lock
, flags
);
541 list_del(®
->list
);
542 spin_unlock_irqrestore(&sclp_lock
, flags
);
547 EXPORT_SYMBOL(sclp_register
);
549 /* Unregister event listener. */
551 sclp_unregister(struct sclp_register
*reg
)
555 spin_lock_irqsave(&sclp_lock
, flags
);
556 list_del(®
->list
);
557 spin_unlock_irqrestore(&sclp_lock
, flags
);
561 EXPORT_SYMBOL(sclp_unregister
);
563 /* Remove event buffers which are marked processed. Return the number of
564 * remaining event buffers. */
566 sclp_remove_processed(struct sccb_header
*sccb
)
568 struct evbuf_header
*evbuf
;
572 evbuf
= (struct evbuf_header
*) (sccb
+ 1);
574 remaining
= sccb
->length
- sizeof(struct sccb_header
);
575 while (remaining
> 0) {
576 remaining
-= evbuf
->length
;
577 if (evbuf
->flags
& 0x80) {
578 sccb
->length
-= evbuf
->length
;
579 memcpy(evbuf
, (void *) ((addr_t
) evbuf
+ evbuf
->length
),
583 evbuf
= (struct evbuf_header
*)
584 ((addr_t
) evbuf
+ evbuf
->length
);
590 EXPORT_SYMBOL(sclp_remove_processed
);
593 struct sccb_header header
;
596 sccb_mask_t receive_mask
;
597 sccb_mask_t send_mask
;
598 sccb_mask_t sclp_send_mask
;
599 sccb_mask_t sclp_receive_mask
;
600 } __attribute__((packed
));
602 /* Prepare init mask request. Called while sclp_lock is locked. */
604 __sclp_make_init_req(u32 receive_mask
, u32 send_mask
)
606 struct init_sccb
*sccb
;
608 sccb
= (struct init_sccb
*) sclp_init_sccb
;
610 memset(&sclp_init_req
, 0, sizeof(struct sclp_req
));
611 sclp_init_req
.command
= SCLP_CMDW_WRITEMASK
;
612 sclp_init_req
.status
= SCLP_REQ_FILLED
;
613 sclp_init_req
.start_count
= 0;
614 sclp_init_req
.callback
= NULL
;
615 sclp_init_req
.callback_data
= NULL
;
616 sclp_init_req
.sccb
= sccb
;
617 sccb
->header
.length
= sizeof(struct init_sccb
);
618 sccb
->mask_length
= sizeof(sccb_mask_t
);
619 sccb
->receive_mask
= receive_mask
;
620 sccb
->send_mask
= send_mask
;
621 sccb
->sclp_receive_mask
= 0;
622 sccb
->sclp_send_mask
= 0;
625 /* Start init mask request. If calculate is non-zero, calculate the mask as
626 * requested by registered listeners. Use zero mask otherwise. Return 0 on
627 * success, non-zero otherwise. */
629 sclp_init_mask(int calculate
)
632 struct init_sccb
*sccb
= (struct init_sccb
*) sclp_init_sccb
;
633 sccb_mask_t receive_mask
;
634 sccb_mask_t send_mask
;
639 spin_lock_irqsave(&sclp_lock
, flags
);
640 /* Check if interface is in appropriate state */
641 if (sclp_mask_state
!= sclp_mask_state_idle
) {
642 spin_unlock_irqrestore(&sclp_lock
, flags
);
645 if (sclp_activation_state
== sclp_activation_state_inactive
) {
646 spin_unlock_irqrestore(&sclp_lock
, flags
);
649 sclp_mask_state
= sclp_mask_state_initializing
;
652 __sclp_get_mask(&receive_mask
, &send_mask
);
658 for (retry
= 0; retry
<= SCLP_MASK_RETRY
; retry
++) {
659 /* Prepare request */
660 __sclp_make_init_req(receive_mask
, send_mask
);
661 spin_unlock_irqrestore(&sclp_lock
, flags
);
662 if (sclp_add_request(&sclp_init_req
)) {
663 /* Try again later */
664 wait
= jiffies
+ SCLP_BUSY_INTERVAL
* HZ
;
665 while (time_before(jiffies
, wait
))
667 spin_lock_irqsave(&sclp_lock
, flags
);
670 while (sclp_init_req
.status
!= SCLP_REQ_DONE
&&
671 sclp_init_req
.status
!= SCLP_REQ_FAILED
)
673 spin_lock_irqsave(&sclp_lock
, flags
);
674 if (sclp_init_req
.status
== SCLP_REQ_DONE
&&
675 sccb
->header
.response_code
== 0x20) {
676 /* Successful request */
678 sclp_receive_mask
= sccb
->sclp_receive_mask
;
679 sclp_send_mask
= sccb
->sclp_send_mask
;
681 sclp_receive_mask
= 0;
684 spin_unlock_irqrestore(&sclp_lock
, flags
);
685 sclp_dispatch_state_change();
686 spin_lock_irqsave(&sclp_lock
, flags
);
691 sclp_mask_state
= sclp_mask_state_idle
;
692 spin_unlock_irqrestore(&sclp_lock
, flags
);
696 /* Deactivate SCLP interface. On success, new requests will be rejected,
697 * events will no longer be dispatched. Return 0 on success, non-zero
700 sclp_deactivate(void)
705 spin_lock_irqsave(&sclp_lock
, flags
);
706 /* Deactivate can only be called when active */
707 if (sclp_activation_state
!= sclp_activation_state_active
) {
708 spin_unlock_irqrestore(&sclp_lock
, flags
);
711 sclp_activation_state
= sclp_activation_state_deactivating
;
712 spin_unlock_irqrestore(&sclp_lock
, flags
);
713 rc
= sclp_init_mask(0);
714 spin_lock_irqsave(&sclp_lock
, flags
);
716 sclp_activation_state
= sclp_activation_state_inactive
;
718 sclp_activation_state
= sclp_activation_state_active
;
719 spin_unlock_irqrestore(&sclp_lock
, flags
);
723 EXPORT_SYMBOL(sclp_deactivate
);
725 /* Reactivate SCLP interface after sclp_deactivate. On success, new
726 * requests will be accepted, events will be dispatched again. Return 0 on
727 * success, non-zero otherwise. */
729 sclp_reactivate(void)
734 spin_lock_irqsave(&sclp_lock
, flags
);
735 /* Reactivate can only be called when inactive */
736 if (sclp_activation_state
!= sclp_activation_state_inactive
) {
737 spin_unlock_irqrestore(&sclp_lock
, flags
);
740 sclp_activation_state
= sclp_activation_state_activating
;
741 spin_unlock_irqrestore(&sclp_lock
, flags
);
742 rc
= sclp_init_mask(1);
743 spin_lock_irqsave(&sclp_lock
, flags
);
745 sclp_activation_state
= sclp_activation_state_active
;
747 sclp_activation_state
= sclp_activation_state_inactive
;
748 spin_unlock_irqrestore(&sclp_lock
, flags
);
752 EXPORT_SYMBOL(sclp_reactivate
);
754 /* Handler for external interruption used during initialization. Modify
755 * request state to done. */
757 sclp_check_handler(struct pt_regs
*regs
, __u16 code
)
761 finished_sccb
= S390_lowcore
.ext_params
& 0xfffffff8;
762 /* Is this the interrupt we are waiting for? */
763 if (finished_sccb
== 0)
765 if (finished_sccb
!= (u32
) (addr_t
) sclp_init_sccb
) {
766 printk(KERN_WARNING SCLP_HEADER
"unsolicited interrupt "
767 "for buffer at 0x%x\n", finished_sccb
);
770 spin_lock(&sclp_lock
);
771 if (sclp_running_state
== sclp_running_state_running
) {
772 sclp_init_req
.status
= SCLP_REQ_DONE
;
773 sclp_running_state
= sclp_running_state_idle
;
775 spin_unlock(&sclp_lock
);
778 /* Initial init mask request timed out. Modify request state to failed. */
780 sclp_check_timeout(unsigned long data
)
784 spin_lock_irqsave(&sclp_lock
, flags
);
785 if (sclp_running_state
== sclp_running_state_running
) {
786 sclp_init_req
.status
= SCLP_REQ_FAILED
;
787 sclp_running_state
= sclp_running_state_idle
;
789 spin_unlock_irqrestore(&sclp_lock
, flags
);
792 /* Perform a check of the SCLP interface. Return zero if the interface is
793 * available and there are no pending requests from a previous instance.
794 * Return non-zero otherwise. */
796 sclp_check_interface(void)
798 struct init_sccb
*sccb
;
803 spin_lock_irqsave(&sclp_lock
, flags
);
804 /* Prepare init mask command */
805 rc
= register_early_external_interrupt(0x2401, sclp_check_handler
,
808 spin_unlock_irqrestore(&sclp_lock
, flags
);
811 for (retry
= 0; retry
<= SCLP_INIT_RETRY
; retry
++) {
812 __sclp_make_init_req(0, 0);
813 sccb
= (struct init_sccb
*) sclp_init_req
.sccb
;
814 rc
= service_call(sclp_init_req
.command
, sccb
);
817 sclp_init_req
.status
= SCLP_REQ_RUNNING
;
818 sclp_running_state
= sclp_running_state_running
;
819 __sclp_set_request_timer(SCLP_RETRY_INTERVAL
* HZ
,
820 sclp_check_timeout
, 0);
821 spin_unlock_irqrestore(&sclp_lock
, flags
);
822 /* Enable service-signal interruption - needs to happen
823 * with IRQs enabled. */
825 /* Wait for signal from interrupt or timeout */
827 /* Disable service-signal interruption - needs to happen
828 * with IRQs enabled. */
830 spin_lock_irqsave(&sclp_lock
, flags
);
831 del_timer(&sclp_request_timer
);
832 if (sclp_init_req
.status
== SCLP_REQ_DONE
&&
833 sccb
->header
.response_code
== 0x20) {
839 unregister_early_external_interrupt(0x2401, sclp_check_handler
,
841 spin_unlock_irqrestore(&sclp_lock
, flags
);
845 /* Reboot event handler. Reset send and receive mask to prevent pending SCLP
846 * events from interfering with rebooted system. */
848 sclp_reboot_event(struct notifier_block
*this, unsigned long event
, void *ptr
)
854 static struct notifier_block sclp_reboot_notifier
= {
855 .notifier_call
= sclp_reboot_event
858 /* Initialize SCLP driver. Return zero if driver is operational, non-zero
866 if (!MACHINE_HAS_SCLP
)
868 spin_lock_irqsave(&sclp_lock
, flags
);
869 /* Check for previous or running initialization */
870 if (sclp_init_state
!= sclp_init_state_uninitialized
) {
871 spin_unlock_irqrestore(&sclp_lock
, flags
);
874 sclp_init_state
= sclp_init_state_initializing
;
875 /* Set up variables */
876 INIT_LIST_HEAD(&sclp_req_queue
);
877 INIT_LIST_HEAD(&sclp_reg_list
);
878 list_add(&sclp_state_change_event
.list
, &sclp_reg_list
);
879 init_timer(&sclp_request_timer
);
880 /* Check interface */
881 spin_unlock_irqrestore(&sclp_lock
, flags
);
882 rc
= sclp_check_interface();
883 spin_lock_irqsave(&sclp_lock
, flags
);
885 sclp_init_state
= sclp_init_state_uninitialized
;
886 spin_unlock_irqrestore(&sclp_lock
, flags
);
889 /* Register reboot handler */
890 rc
= register_reboot_notifier(&sclp_reboot_notifier
);
892 sclp_init_state
= sclp_init_state_uninitialized
;
893 spin_unlock_irqrestore(&sclp_lock
, flags
);
896 /* Register interrupt handler */
897 rc
= register_early_external_interrupt(0x2401, sclp_interrupt_handler
,
900 unregister_reboot_notifier(&sclp_reboot_notifier
);
901 sclp_init_state
= sclp_init_state_uninitialized
;
902 spin_unlock_irqrestore(&sclp_lock
, flags
);
905 sclp_init_state
= sclp_init_state_initialized
;
906 spin_unlock_irqrestore(&sclp_lock
, flags
);
907 /* Enable service-signal external interruption - needs to happen with