xref: /openbmc/linux/drivers/s390/char/sclp.c (revision 09138ba68c1487a42c400485e999386a74911dbc)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * core function to access sclp interface
41da177e4SLinus Torvalds  *
562b74942SMichael Holzheu  * Copyright IBM Corp. 1999, 2009
662b74942SMichael Holzheu  *
71da177e4SLinus Torvalds  * Author(s): Martin Peschke <mpeschke@de.ibm.com>
81da177e4SLinus Torvalds  *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
91da177e4SLinus Torvalds  */
101da177e4SLinus Torvalds 
11052ff461SHeiko Carstens #include <linux/kernel_stat.h>
121da177e4SLinus Torvalds #include <linux/module.h>
131da177e4SLinus Torvalds #include <linux/err.h>
14f39650deSAndy Shevchenko #include <linux/panic_notifier.h>
151da177e4SLinus Torvalds #include <linux/spinlock.h>
161da177e4SLinus Torvalds #include <linux/interrupt.h>
171da177e4SLinus Torvalds #include <linux/timer.h>
181da177e4SLinus Torvalds #include <linux/reboot.h>
191da177e4SLinus Torvalds #include <linux/jiffies.h>
20b3d00c3bSPeter Oberparleiter #include <linux/init.h>
2162b74942SMichael Holzheu #include <linux/platform_device.h>
22052ff461SHeiko Carstens #include <asm/types.h>
23052ff461SHeiko Carstens #include <asm/irq.h>
2470aa5d39SPeter Oberparleiter #include <asm/debug.h>
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include "sclp.h"
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #define SCLP_HEADER		"sclp: "
291da177e4SLinus Torvalds 
3070aa5d39SPeter Oberparleiter struct sclp_trace_entry {
31ff8a58b0SHeiko Carstens 	char id[4] __nonstring;
3270aa5d39SPeter Oberparleiter 	u32 a;
3370aa5d39SPeter Oberparleiter 	u64 b;
3470aa5d39SPeter Oberparleiter };
3570aa5d39SPeter Oberparleiter 
3670aa5d39SPeter Oberparleiter #define SCLP_TRACE_ENTRY_SIZE		sizeof(struct sclp_trace_entry)
3770aa5d39SPeter Oberparleiter #define SCLP_TRACE_MAX_SIZE		128
3870aa5d39SPeter Oberparleiter #define SCLP_TRACE_EVENT_MAX_SIZE	64
3970aa5d39SPeter Oberparleiter 
4070aa5d39SPeter Oberparleiter /* Debug trace area intended for all entries in abbreviated form. */
4170aa5d39SPeter Oberparleiter DEFINE_STATIC_DEBUG_INFO(sclp_debug, "sclp", 8, 1, SCLP_TRACE_ENTRY_SIZE,
4270aa5d39SPeter Oberparleiter 			 &debug_hex_ascii_view);
4370aa5d39SPeter Oberparleiter 
4470aa5d39SPeter Oberparleiter /* Error trace area intended for full entries relating to failed requests. */
4570aa5d39SPeter Oberparleiter DEFINE_STATIC_DEBUG_INFO(sclp_debug_err, "sclp_err", 4, 1,
4670aa5d39SPeter Oberparleiter 			 SCLP_TRACE_ENTRY_SIZE, &debug_hex_ascii_view);
4770aa5d39SPeter Oberparleiter 
481da177e4SLinus Torvalds /* Lock to protect internal data consistency. */
491da177e4SLinus Torvalds static DEFINE_SPINLOCK(sclp_lock);
501da177e4SLinus Torvalds 
51d082d3ceSPeter Oberparleiter /* Mask of events that we can send to the sclp interface. */
521da177e4SLinus Torvalds static sccb_mask_t sclp_receive_mask;
531da177e4SLinus Torvalds 
54d082d3ceSPeter Oberparleiter /* Mask of events that we can receive from the sclp interface. */
551da177e4SLinus Torvalds static sccb_mask_t sclp_send_mask;
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds /* List of registered event listeners and senders. */
588bc00c04SVineeth Vijayan static LIST_HEAD(sclp_reg_list);
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds /* List of queued requests. */
618bc00c04SVineeth Vijayan static LIST_HEAD(sclp_req_queue);
621da177e4SLinus Torvalds 
63d608f45eSJiang Jian /* Data for read and init requests. */
641da177e4SLinus Torvalds static struct sclp_req sclp_read_req;
651da177e4SLinus Torvalds static struct sclp_req sclp_init_req;
66087c4d74SGerald Schaefer static void *sclp_read_sccb;
67087c4d74SGerald Schaefer static struct init_sccb *sclp_init_sccb;
681da177e4SLinus Torvalds 
6925b41a7bSMartin Schwidefsky /* Number of console pages to allocate, used by sclp_con.c and sclp_vt220.c */
7025b41a7bSMartin Schwidefsky int sclp_console_pages = SCLP_CONSOLE_PAGES;
7125b41a7bSMartin Schwidefsky /* Flag to indicate if buffer pages are dropped on buffer full condition */
722473be45SHeiko Carstens bool sclp_console_drop = true;
7325b41a7bSMartin Schwidefsky /* Number of times the console dropped buffer pages */
7425b41a7bSMartin Schwidefsky unsigned long sclp_console_full;
7525b41a7bSMartin Schwidefsky 
7670aa5d39SPeter Oberparleiter /* The currently active SCLP command word. */
7770aa5d39SPeter Oberparleiter static sclp_cmdw_t active_cmd;
7870aa5d39SPeter Oberparleiter 
sclp_trace(int prio,char * id,u32 a,u64 b,bool err)7970aa5d39SPeter Oberparleiter static inline void sclp_trace(int prio, char *id, u32 a, u64 b, bool err)
8070aa5d39SPeter Oberparleiter {
8170aa5d39SPeter Oberparleiter 	struct sclp_trace_entry e;
8270aa5d39SPeter Oberparleiter 
8370aa5d39SPeter Oberparleiter 	memset(&e, 0, sizeof(e));
8470aa5d39SPeter Oberparleiter 	strncpy(e.id, id, sizeof(e.id));
8570aa5d39SPeter Oberparleiter 	e.a = a;
8670aa5d39SPeter Oberparleiter 	e.b = b;
8770aa5d39SPeter Oberparleiter 	debug_event(&sclp_debug, prio, &e, sizeof(e));
8870aa5d39SPeter Oberparleiter 	if (err)
8970aa5d39SPeter Oberparleiter 		debug_event(&sclp_debug_err, 0, &e, sizeof(e));
9070aa5d39SPeter Oberparleiter }
9170aa5d39SPeter Oberparleiter 
no_zeroes_len(void * data,int len)9270aa5d39SPeter Oberparleiter static inline int no_zeroes_len(void *data, int len)
9370aa5d39SPeter Oberparleiter {
9470aa5d39SPeter Oberparleiter 	char *d = data;
9570aa5d39SPeter Oberparleiter 
9670aa5d39SPeter Oberparleiter 	/* Minimize trace area usage by not tracing trailing zeroes. */
9770aa5d39SPeter Oberparleiter 	while (len > SCLP_TRACE_ENTRY_SIZE && d[len - 1] == 0)
9870aa5d39SPeter Oberparleiter 		len--;
9970aa5d39SPeter Oberparleiter 
10070aa5d39SPeter Oberparleiter 	return len;
10170aa5d39SPeter Oberparleiter }
10270aa5d39SPeter Oberparleiter 
sclp_trace_bin(int prio,void * d,int len,int errlen)10370aa5d39SPeter Oberparleiter static inline void sclp_trace_bin(int prio, void *d, int len, int errlen)
10470aa5d39SPeter Oberparleiter {
10570aa5d39SPeter Oberparleiter 	debug_event(&sclp_debug, prio, d, no_zeroes_len(d, len));
10670aa5d39SPeter Oberparleiter 	if (errlen)
10770aa5d39SPeter Oberparleiter 		debug_event(&sclp_debug_err, 0, d, no_zeroes_len(d, errlen));
10870aa5d39SPeter Oberparleiter }
10970aa5d39SPeter Oberparleiter 
abbrev_len(sclp_cmdw_t cmd,struct sccb_header * sccb)11070aa5d39SPeter Oberparleiter static inline int abbrev_len(sclp_cmdw_t cmd, struct sccb_header *sccb)
11170aa5d39SPeter Oberparleiter {
11270aa5d39SPeter Oberparleiter 	struct evbuf_header *evbuf = (struct evbuf_header *)(sccb + 1);
11370aa5d39SPeter Oberparleiter 	int len = sccb->length, limit = SCLP_TRACE_MAX_SIZE;
11470aa5d39SPeter Oberparleiter 
11570aa5d39SPeter Oberparleiter 	/* Full SCCB tracing if debug level is set to max. */
11670aa5d39SPeter Oberparleiter 	if (sclp_debug.level == DEBUG_MAX_LEVEL)
11770aa5d39SPeter Oberparleiter 		return len;
11870aa5d39SPeter Oberparleiter 
11970aa5d39SPeter Oberparleiter 	/* Minimal tracing for console writes. */
12070aa5d39SPeter Oberparleiter 	if (cmd == SCLP_CMDW_WRITE_EVENT_DATA &&
12170aa5d39SPeter Oberparleiter 	    (evbuf->type == EVTYP_MSG  || evbuf->type == EVTYP_VT220MSG))
12270aa5d39SPeter Oberparleiter 		limit = SCLP_TRACE_ENTRY_SIZE;
12370aa5d39SPeter Oberparleiter 
12470aa5d39SPeter Oberparleiter 	return min(len, limit);
12570aa5d39SPeter Oberparleiter }
12670aa5d39SPeter Oberparleiter 
sclp_trace_sccb(int prio,char * id,u32 a,u64 b,sclp_cmdw_t cmd,struct sccb_header * sccb,bool err)12770aa5d39SPeter Oberparleiter static inline void sclp_trace_sccb(int prio, char *id, u32 a, u64 b,
12870aa5d39SPeter Oberparleiter 				   sclp_cmdw_t cmd, struct sccb_header *sccb,
12970aa5d39SPeter Oberparleiter 				   bool err)
13070aa5d39SPeter Oberparleiter {
13170aa5d39SPeter Oberparleiter 	sclp_trace(prio, id, a, b, err);
13270aa5d39SPeter Oberparleiter 	if (sccb) {
13370aa5d39SPeter Oberparleiter 		sclp_trace_bin(prio + 1, sccb, abbrev_len(cmd, sccb),
13470aa5d39SPeter Oberparleiter 			       err ? sccb->length : 0);
13570aa5d39SPeter Oberparleiter 	}
13670aa5d39SPeter Oberparleiter }
13770aa5d39SPeter Oberparleiter 
sclp_trace_evbuf(int prio,char * id,u32 a,u64 b,struct evbuf_header * evbuf,bool err)13870aa5d39SPeter Oberparleiter static inline void sclp_trace_evbuf(int prio, char *id, u32 a, u64 b,
13970aa5d39SPeter Oberparleiter 				    struct evbuf_header *evbuf, bool err)
14070aa5d39SPeter Oberparleiter {
14170aa5d39SPeter Oberparleiter 	sclp_trace(prio, id, a, b, err);
14270aa5d39SPeter Oberparleiter 	sclp_trace_bin(prio + 1, evbuf,
14370aa5d39SPeter Oberparleiter 		       min((int)evbuf->length, (int)SCLP_TRACE_EVENT_MAX_SIZE),
14470aa5d39SPeter Oberparleiter 		       err ? evbuf->length : 0);
14570aa5d39SPeter Oberparleiter }
14670aa5d39SPeter Oberparleiter 
sclp_trace_req(int prio,char * id,struct sclp_req * req,bool err)14770aa5d39SPeter Oberparleiter static inline void sclp_trace_req(int prio, char *id, struct sclp_req *req,
14870aa5d39SPeter Oberparleiter 				  bool err)
14970aa5d39SPeter Oberparleiter {
15070aa5d39SPeter Oberparleiter 	struct sccb_header *sccb = req->sccb;
15170aa5d39SPeter Oberparleiter 	union {
15270aa5d39SPeter Oberparleiter 		struct {
15370aa5d39SPeter Oberparleiter 			u16 status;
15470aa5d39SPeter Oberparleiter 			u16 response;
15570aa5d39SPeter Oberparleiter 			u16 timeout;
15670aa5d39SPeter Oberparleiter 			u16 start_count;
15770aa5d39SPeter Oberparleiter 		};
15870aa5d39SPeter Oberparleiter 		u64 b;
15970aa5d39SPeter Oberparleiter 	} summary;
16070aa5d39SPeter Oberparleiter 
16170aa5d39SPeter Oberparleiter 	summary.status = req->status;
16270aa5d39SPeter Oberparleiter 	summary.response = sccb ? sccb->response_code : 0;
16370aa5d39SPeter Oberparleiter 	summary.timeout = (u16)req->queue_timeout;
16470aa5d39SPeter Oberparleiter 	summary.start_count = (u16)req->start_count;
16570aa5d39SPeter Oberparleiter 
166ada1da31SAlexander Gordeev 	sclp_trace(prio, id, __pa(sccb), summary.b, err);
16770aa5d39SPeter Oberparleiter }
16870aa5d39SPeter Oberparleiter 
sclp_trace_register(int prio,char * id,u32 a,u64 b,struct sclp_register * reg)16970aa5d39SPeter Oberparleiter static inline void sclp_trace_register(int prio, char *id, u32 a, u64 b,
17070aa5d39SPeter Oberparleiter 				       struct sclp_register *reg)
17170aa5d39SPeter Oberparleiter {
17270aa5d39SPeter Oberparleiter 	struct {
17370aa5d39SPeter Oberparleiter 		u64 receive;
17470aa5d39SPeter Oberparleiter 		u64 send;
17570aa5d39SPeter Oberparleiter 	} d;
17670aa5d39SPeter Oberparleiter 
17770aa5d39SPeter Oberparleiter 	d.receive = reg->receive_mask;
17870aa5d39SPeter Oberparleiter 	d.send = reg->send_mask;
17970aa5d39SPeter Oberparleiter 
18070aa5d39SPeter Oberparleiter 	sclp_trace(prio, id, a, b, false);
18170aa5d39SPeter Oberparleiter 	sclp_trace_bin(prio, &d, sizeof(d), 0);
18270aa5d39SPeter Oberparleiter }
18370aa5d39SPeter Oberparleiter 
sclp_setup_console_pages(char * str)18425b41a7bSMartin Schwidefsky static int __init sclp_setup_console_pages(char *str)
18525b41a7bSMartin Schwidefsky {
18625b41a7bSMartin Schwidefsky 	int pages, rc;
18725b41a7bSMartin Schwidefsky 
18825b41a7bSMartin Schwidefsky 	rc = kstrtoint(str, 0, &pages);
18925b41a7bSMartin Schwidefsky 	if (!rc && pages >= SCLP_CONSOLE_PAGES)
19025b41a7bSMartin Schwidefsky 		sclp_console_pages = pages;
19125b41a7bSMartin Schwidefsky 	return 1;
19225b41a7bSMartin Schwidefsky }
19325b41a7bSMartin Schwidefsky 
19425b41a7bSMartin Schwidefsky __setup("sclp_con_pages=", sclp_setup_console_pages);
19525b41a7bSMartin Schwidefsky 
sclp_setup_console_drop(char * str)19625b41a7bSMartin Schwidefsky static int __init sclp_setup_console_drop(char *str)
19725b41a7bSMartin Schwidefsky {
1982473be45SHeiko Carstens 	return kstrtobool(str, &sclp_console_drop) == 0;
19925b41a7bSMartin Schwidefsky }
20025b41a7bSMartin Schwidefsky 
20125b41a7bSMartin Schwidefsky __setup("sclp_con_drop=", sclp_setup_console_drop);
20225b41a7bSMartin Schwidefsky 
2031da177e4SLinus Torvalds /* Timer for request retries. */
2041da177e4SLinus Torvalds static struct timer_list sclp_request_timer;
2051da177e4SLinus Torvalds 
2069f0128f9SGerald Schaefer /* Timer for queued requests. */
2079f0128f9SGerald Schaefer static struct timer_list sclp_queue_timer;
2089f0128f9SGerald Schaefer 
2091da177e4SLinus Torvalds /* Internal state: is a request active at the sclp? */
2101da177e4SLinus Torvalds static volatile enum sclp_running_state_t {
2111da177e4SLinus Torvalds 	sclp_running_state_idle,
212dbd8ae63SPeter Oberparleiter 	sclp_running_state_running,
213dbd8ae63SPeter Oberparleiter 	sclp_running_state_reset_pending
2141da177e4SLinus Torvalds } sclp_running_state = sclp_running_state_idle;
2151da177e4SLinus Torvalds 
2161da177e4SLinus Torvalds /* Internal state: is a read request pending? */
2171da177e4SLinus Torvalds static volatile enum sclp_reading_state_t {
2181da177e4SLinus Torvalds 	sclp_reading_state_idle,
2191da177e4SLinus Torvalds 	sclp_reading_state_reading
2201da177e4SLinus Torvalds } sclp_reading_state = sclp_reading_state_idle;
2211da177e4SLinus Torvalds 
2221da177e4SLinus Torvalds /* Internal state: is the driver currently serving requests? */
2231da177e4SLinus Torvalds static volatile enum sclp_activation_state_t {
2241da177e4SLinus Torvalds 	sclp_activation_state_active,
2251da177e4SLinus Torvalds 	sclp_activation_state_deactivating,
2261da177e4SLinus Torvalds 	sclp_activation_state_inactive,
2271da177e4SLinus Torvalds 	sclp_activation_state_activating
2281da177e4SLinus Torvalds } sclp_activation_state = sclp_activation_state_active;
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds /* Internal state: is an init mask request pending? */
2311da177e4SLinus Torvalds static volatile enum sclp_mask_state_t {
2321da177e4SLinus Torvalds 	sclp_mask_state_idle,
2331da177e4SLinus Torvalds 	sclp_mask_state_initializing
2341da177e4SLinus Torvalds } sclp_mask_state = sclp_mask_state_idle;
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds /* Maximum retry counts */
2371da177e4SLinus Torvalds #define SCLP_INIT_RETRY		3
2381da177e4SLinus Torvalds #define SCLP_MASK_RETRY		3
2391da177e4SLinus Torvalds 
2401da177e4SLinus Torvalds /* Timeout intervals in seconds.*/
24125fab9ebSPeter Oberparleiter #define SCLP_BUSY_INTERVAL	10
242dbd8ae63SPeter Oberparleiter #define SCLP_RETRY_INTERVAL	30
2431da177e4SLinus Torvalds 
244c9602ee7SKees Cook static void sclp_request_timeout(bool force_restart);
2451da177e4SLinus Torvalds static void sclp_process_queue(void);
246364c8558SHeiko Carstens static void __sclp_make_read_req(void);
2471da177e4SLinus Torvalds static int sclp_init_mask(int calculate);
2481da177e4SLinus Torvalds static int sclp_init(void);
2491da177e4SLinus Torvalds 
250dbd8ae63SPeter Oberparleiter static void
__sclp_queue_read_req(void)251dbd8ae63SPeter Oberparleiter __sclp_queue_read_req(void)
252dbd8ae63SPeter Oberparleiter {
253dbd8ae63SPeter Oberparleiter 	if (sclp_reading_state == sclp_reading_state_idle) {
254dbd8ae63SPeter Oberparleiter 		sclp_reading_state = sclp_reading_state_reading;
255dbd8ae63SPeter Oberparleiter 		__sclp_make_read_req();
256dbd8ae63SPeter Oberparleiter 		/* Add request to head of queue */
257dbd8ae63SPeter Oberparleiter 		list_add(&sclp_read_req.list, &sclp_req_queue);
2581da177e4SLinus Torvalds 	}
2591da177e4SLinus Torvalds }
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds /* Set up request retry timer. Called while sclp_lock is locked. */
2621da177e4SLinus Torvalds static inline void
__sclp_set_request_timer(unsigned long time,void (* cb)(struct timer_list *))263c9602ee7SKees Cook __sclp_set_request_timer(unsigned long time, void (*cb)(struct timer_list *))
2641da177e4SLinus Torvalds {
2651da177e4SLinus Torvalds 	del_timer(&sclp_request_timer);
266841b86f3SKees Cook 	sclp_request_timer.function = cb;
2671da177e4SLinus Torvalds 	sclp_request_timer.expires = jiffies + time;
2681da177e4SLinus Torvalds 	add_timer(&sclp_request_timer);
2691da177e4SLinus Torvalds }
2701da177e4SLinus Torvalds 
sclp_request_timeout_restart(struct timer_list * unused)271c9602ee7SKees Cook static void sclp_request_timeout_restart(struct timer_list *unused)
272c9602ee7SKees Cook {
273c9602ee7SKees Cook 	sclp_request_timeout(true);
274c9602ee7SKees Cook }
275c9602ee7SKees Cook 
sclp_request_timeout_normal(struct timer_list * unused)276c9602ee7SKees Cook static void sclp_request_timeout_normal(struct timer_list *unused)
277c9602ee7SKees Cook {
278c9602ee7SKees Cook 	sclp_request_timeout(false);
279c9602ee7SKees Cook }
280c9602ee7SKees Cook 
281c9602ee7SKees Cook /* Request timeout handler. Restart the request queue. If force_restart,
282dbd8ae63SPeter Oberparleiter  * force restart of running request. */
sclp_request_timeout(bool force_restart)283c9602ee7SKees Cook static void sclp_request_timeout(bool force_restart)
284dbd8ae63SPeter Oberparleiter {
285dbd8ae63SPeter Oberparleiter 	unsigned long flags;
286dbd8ae63SPeter Oberparleiter 
28770aa5d39SPeter Oberparleiter 	/* TMO: A timeout occurred (a=force_restart) */
28870aa5d39SPeter Oberparleiter 	sclp_trace(2, "TMO", force_restart, 0, true);
28970aa5d39SPeter Oberparleiter 
290dbd8ae63SPeter Oberparleiter 	spin_lock_irqsave(&sclp_lock, flags);
291c9602ee7SKees Cook 	if (force_restart) {
292dbd8ae63SPeter Oberparleiter 		if (sclp_running_state == sclp_running_state_running) {
293dbd8ae63SPeter Oberparleiter 			/* Break running state and queue NOP read event request
294dbd8ae63SPeter Oberparleiter 			 * to get a defined interface state. */
295dbd8ae63SPeter Oberparleiter 			__sclp_queue_read_req();
296dbd8ae63SPeter Oberparleiter 			sclp_running_state = sclp_running_state_idle;
297dbd8ae63SPeter Oberparleiter 		}
298dbd8ae63SPeter Oberparleiter 	} else {
299dbd8ae63SPeter Oberparleiter 		__sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
300c9602ee7SKees Cook 					 sclp_request_timeout_normal);
301dbd8ae63SPeter Oberparleiter 	}
302dbd8ae63SPeter Oberparleiter 	spin_unlock_irqrestore(&sclp_lock, flags);
303dbd8ae63SPeter Oberparleiter 	sclp_process_queue();
304dbd8ae63SPeter Oberparleiter }
305dbd8ae63SPeter Oberparleiter 
3069f0128f9SGerald Schaefer /*
3079f0128f9SGerald Schaefer  * Returns the expire value in jiffies of the next pending request timeout,
3089f0128f9SGerald Schaefer  * if any. Needs to be called with sclp_lock.
3099f0128f9SGerald Schaefer  */
__sclp_req_queue_find_next_timeout(void)3109f0128f9SGerald Schaefer static unsigned long __sclp_req_queue_find_next_timeout(void)
3119f0128f9SGerald Schaefer {
3129f0128f9SGerald Schaefer 	unsigned long expires_next = 0;
3139f0128f9SGerald Schaefer 	struct sclp_req *req;
3149f0128f9SGerald Schaefer 
3159f0128f9SGerald Schaefer 	list_for_each_entry(req, &sclp_req_queue, list) {
3169f0128f9SGerald Schaefer 		if (!req->queue_expires)
3179f0128f9SGerald Schaefer 			continue;
3189f0128f9SGerald Schaefer 		if (!expires_next ||
3199f0128f9SGerald Schaefer 		   (time_before(req->queue_expires, expires_next)))
3209f0128f9SGerald Schaefer 				expires_next = req->queue_expires;
3219f0128f9SGerald Schaefer 	}
3229f0128f9SGerald Schaefer 	return expires_next;
3239f0128f9SGerald Schaefer }
3249f0128f9SGerald Schaefer 
3259f0128f9SGerald Schaefer /*
3269f0128f9SGerald Schaefer  * Returns expired request, if any, and removes it from the list.
3279f0128f9SGerald Schaefer  */
__sclp_req_queue_remove_expired_req(void)3289f0128f9SGerald Schaefer static struct sclp_req *__sclp_req_queue_remove_expired_req(void)
3299f0128f9SGerald Schaefer {
3309f0128f9SGerald Schaefer 	unsigned long flags, now;
3319f0128f9SGerald Schaefer 	struct sclp_req *req;
3329f0128f9SGerald Schaefer 
3339f0128f9SGerald Schaefer 	spin_lock_irqsave(&sclp_lock, flags);
3349f0128f9SGerald Schaefer 	now = jiffies;
3359f0128f9SGerald Schaefer 	/* Don't need list_for_each_safe because we break out after list_del */
3369f0128f9SGerald Schaefer 	list_for_each_entry(req, &sclp_req_queue, list) {
3379f0128f9SGerald Schaefer 		if (!req->queue_expires)
3389f0128f9SGerald Schaefer 			continue;
3399f0128f9SGerald Schaefer 		if (time_before_eq(req->queue_expires, now)) {
3409f0128f9SGerald Schaefer 			if (req->status == SCLP_REQ_QUEUED) {
3419f0128f9SGerald Schaefer 				req->status = SCLP_REQ_QUEUED_TIMEOUT;
3429f0128f9SGerald Schaefer 				list_del(&req->list);
3439f0128f9SGerald Schaefer 				goto out;
3449f0128f9SGerald Schaefer 			}
3459f0128f9SGerald Schaefer 		}
3469f0128f9SGerald Schaefer 	}
3479f0128f9SGerald Schaefer 	req = NULL;
3489f0128f9SGerald Schaefer out:
3499f0128f9SGerald Schaefer 	spin_unlock_irqrestore(&sclp_lock, flags);
3509f0128f9SGerald Schaefer 	return req;
3519f0128f9SGerald Schaefer }
3529f0128f9SGerald Schaefer 
3539f0128f9SGerald Schaefer /*
3549f0128f9SGerald Schaefer  * Timeout handler for queued requests. Removes request from list and
3559f0128f9SGerald Schaefer  * invokes callback. This timer can be set per request in situations where
3569f0128f9SGerald Schaefer  * waiting too long would be harmful to the system, e.g. during SE reboot.
3579f0128f9SGerald Schaefer  */
sclp_req_queue_timeout(struct timer_list * unused)358c9602ee7SKees Cook static void sclp_req_queue_timeout(struct timer_list *unused)
3599f0128f9SGerald Schaefer {
3609f0128f9SGerald Schaefer 	unsigned long flags, expires_next;
3619f0128f9SGerald Schaefer 	struct sclp_req *req;
3629f0128f9SGerald Schaefer 
3639f0128f9SGerald Schaefer 	do {
3649f0128f9SGerald Schaefer 		req = __sclp_req_queue_remove_expired_req();
36570aa5d39SPeter Oberparleiter 
36670aa5d39SPeter Oberparleiter 		if (req) {
36770aa5d39SPeter Oberparleiter 			/* RQTM: Request timed out (a=sccb, b=summary) */
36870aa5d39SPeter Oberparleiter 			sclp_trace_req(2, "RQTM", req, true);
36970aa5d39SPeter Oberparleiter 		}
37070aa5d39SPeter Oberparleiter 
3719f0128f9SGerald Schaefer 		if (req && req->callback)
3729f0128f9SGerald Schaefer 			req->callback(req, req->callback_data);
3739f0128f9SGerald Schaefer 	} while (req);
3749f0128f9SGerald Schaefer 
3759f0128f9SGerald Schaefer 	spin_lock_irqsave(&sclp_lock, flags);
3769f0128f9SGerald Schaefer 	expires_next = __sclp_req_queue_find_next_timeout();
3779f0128f9SGerald Schaefer 	if (expires_next)
3789f0128f9SGerald Schaefer 		mod_timer(&sclp_queue_timer, expires_next);
3799f0128f9SGerald Schaefer 	spin_unlock_irqrestore(&sclp_lock, flags);
3809f0128f9SGerald Schaefer }
3819f0128f9SGerald Schaefer 
sclp_service_call_trace(sclp_cmdw_t command,void * sccb)38270aa5d39SPeter Oberparleiter static int sclp_service_call_trace(sclp_cmdw_t command, void *sccb)
38370aa5d39SPeter Oberparleiter {
38470aa5d39SPeter Oberparleiter 	static u64 srvc_count;
38570aa5d39SPeter Oberparleiter 	int rc;
38670aa5d39SPeter Oberparleiter 
38770aa5d39SPeter Oberparleiter 	/* SRV1: Service call about to be issued (a=command, b=sccb address) */
38870aa5d39SPeter Oberparleiter 	sclp_trace_sccb(0, "SRV1", command, (u64)sccb, command, sccb, false);
38970aa5d39SPeter Oberparleiter 
39070aa5d39SPeter Oberparleiter 	rc = sclp_service_call(command, sccb);
39170aa5d39SPeter Oberparleiter 
39270aa5d39SPeter Oberparleiter 	/* SRV2: Service call was issued (a=rc, b=SRVC sequence number) */
39370aa5d39SPeter Oberparleiter 	sclp_trace(0, "SRV2", -rc, ++srvc_count, rc != 0);
39470aa5d39SPeter Oberparleiter 
39570aa5d39SPeter Oberparleiter 	if (rc == 0)
39670aa5d39SPeter Oberparleiter 		active_cmd = command;
39770aa5d39SPeter Oberparleiter 
39870aa5d39SPeter Oberparleiter 	return rc;
39970aa5d39SPeter Oberparleiter }
40070aa5d39SPeter Oberparleiter 
4011da177e4SLinus Torvalds /* Try to start a request. Return zero if the request was successfully
4021da177e4SLinus Torvalds  * started or if it will be started at a later time. Return non-zero otherwise.
4031da177e4SLinus Torvalds  * Called while sclp_lock is locked. */
4041da177e4SLinus Torvalds static int
__sclp_start_request(struct sclp_req * req)4051da177e4SLinus Torvalds __sclp_start_request(struct sclp_req *req)
4061da177e4SLinus Torvalds {
4071da177e4SLinus Torvalds 	int rc;
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds 	if (sclp_running_state != sclp_running_state_idle)
4101da177e4SLinus Torvalds 		return 0;
4111da177e4SLinus Torvalds 	del_timer(&sclp_request_timer);
41270aa5d39SPeter Oberparleiter 	rc = sclp_service_call_trace(req->command, req->sccb);
4131da177e4SLinus Torvalds 	req->start_count++;
41425fab9ebSPeter Oberparleiter 
4151da177e4SLinus Torvalds 	if (rc == 0) {
4163ad2f3fbSDaniel Mack 		/* Successfully started request */
4171da177e4SLinus Torvalds 		req->status = SCLP_REQ_RUNNING;
4181da177e4SLinus Torvalds 		sclp_running_state = sclp_running_state_running;
4191da177e4SLinus Torvalds 		__sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
420c9602ee7SKees Cook 					 sclp_request_timeout_restart);
4211da177e4SLinus Torvalds 		return 0;
4221da177e4SLinus Torvalds 	} else if (rc == -EBUSY) {
4231da177e4SLinus Torvalds 		/* Try again later */
4241da177e4SLinus Torvalds 		__sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
425c9602ee7SKees Cook 					 sclp_request_timeout_normal);
4261da177e4SLinus Torvalds 		return 0;
4271da177e4SLinus Torvalds 	}
4281da177e4SLinus Torvalds 	/* Request failed */
4291da177e4SLinus Torvalds 	req->status = SCLP_REQ_FAILED;
4301da177e4SLinus Torvalds 	return rc;
4311da177e4SLinus Torvalds }
4321da177e4SLinus Torvalds 
4331da177e4SLinus Torvalds /* Try to start queued requests. */
4341da177e4SLinus Torvalds static void
sclp_process_queue(void)4351da177e4SLinus Torvalds sclp_process_queue(void)
4361da177e4SLinus Torvalds {
4371da177e4SLinus Torvalds 	struct sclp_req *req;
4381da177e4SLinus Torvalds 	int rc;
4391da177e4SLinus Torvalds 	unsigned long flags;
4401da177e4SLinus Torvalds 
4411da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
4421da177e4SLinus Torvalds 	if (sclp_running_state != sclp_running_state_idle) {
4431da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
4441da177e4SLinus Torvalds 		return;
4451da177e4SLinus Torvalds 	}
4461da177e4SLinus Torvalds 	del_timer(&sclp_request_timer);
4471da177e4SLinus Torvalds 	while (!list_empty(&sclp_req_queue)) {
4481da177e4SLinus Torvalds 		req = list_entry(sclp_req_queue.next, struct sclp_req, list);
4491da177e4SLinus Torvalds 		rc = __sclp_start_request(req);
4501da177e4SLinus Torvalds 		if (rc == 0)
4511da177e4SLinus Torvalds 			break;
452dbd8ae63SPeter Oberparleiter 		/* Request failed */
453dbd8ae63SPeter Oberparleiter 		if (req->start_count > 1) {
454dbd8ae63SPeter Oberparleiter 			/* Cannot abort already submitted request - could still
455dbd8ae63SPeter Oberparleiter 			 * be active at the SCLP */
456dbd8ae63SPeter Oberparleiter 			__sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
457c9602ee7SKees Cook 						 sclp_request_timeout_normal);
458dbd8ae63SPeter Oberparleiter 			break;
459dbd8ae63SPeter Oberparleiter 		}
460dbd8ae63SPeter Oberparleiter 		/* Post-processing for aborted request */
4611da177e4SLinus Torvalds 		list_del(&req->list);
46270aa5d39SPeter Oberparleiter 
46370aa5d39SPeter Oberparleiter 		/* RQAB: Request aborted (a=sccb, b=summary) */
46470aa5d39SPeter Oberparleiter 		sclp_trace_req(2, "RQAB", req, true);
46570aa5d39SPeter Oberparleiter 
4661da177e4SLinus Torvalds 		if (req->callback) {
4671da177e4SLinus Torvalds 			spin_unlock_irqrestore(&sclp_lock, flags);
4681da177e4SLinus Torvalds 			req->callback(req, req->callback_data);
4691da177e4SLinus Torvalds 			spin_lock_irqsave(&sclp_lock, flags);
4701da177e4SLinus Torvalds 		}
4711da177e4SLinus Torvalds 	}
4721da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
4731da177e4SLinus Torvalds }
4741da177e4SLinus Torvalds 
__sclp_can_add_request(struct sclp_req * req)47562b74942SMichael Holzheu static int __sclp_can_add_request(struct sclp_req *req)
47662b74942SMichael Holzheu {
4772f7e5208SPeter Oberparleiter 	if (req == &sclp_init_req)
47862b74942SMichael Holzheu 		return 1;
47962b74942SMichael Holzheu 	if (sclp_init_state != sclp_init_state_initialized)
48062b74942SMichael Holzheu 		return 0;
48162b74942SMichael Holzheu 	if (sclp_activation_state != sclp_activation_state_active)
48262b74942SMichael Holzheu 		return 0;
48362b74942SMichael Holzheu 	return 1;
48462b74942SMichael Holzheu }
48562b74942SMichael Holzheu 
4861da177e4SLinus Torvalds /* Queue a new request. Return zero on success, non-zero otherwise. */
4871da177e4SLinus Torvalds int
sclp_add_request(struct sclp_req * req)4881da177e4SLinus Torvalds sclp_add_request(struct sclp_req *req)
4891da177e4SLinus Torvalds {
4901da177e4SLinus Torvalds 	unsigned long flags;
4911da177e4SLinus Torvalds 	int rc;
4921da177e4SLinus Torvalds 
4931da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
49462b74942SMichael Holzheu 	if (!__sclp_can_add_request(req)) {
4951da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
4961da177e4SLinus Torvalds 		return -EIO;
4971da177e4SLinus Torvalds 	}
49870aa5d39SPeter Oberparleiter 
49970aa5d39SPeter Oberparleiter 	/* RQAD: Request was added (a=sccb, b=caller) */
500ada1da31SAlexander Gordeev 	sclp_trace(2, "RQAD", __pa(req->sccb), _RET_IP_, false);
50170aa5d39SPeter Oberparleiter 
5021da177e4SLinus Torvalds 	req->status = SCLP_REQ_QUEUED;
5031da177e4SLinus Torvalds 	req->start_count = 0;
5041da177e4SLinus Torvalds 	list_add_tail(&req->list, &sclp_req_queue);
5051da177e4SLinus Torvalds 	rc = 0;
5069f0128f9SGerald Schaefer 	if (req->queue_timeout) {
5079f0128f9SGerald Schaefer 		req->queue_expires = jiffies + req->queue_timeout * HZ;
5089f0128f9SGerald Schaefer 		if (!timer_pending(&sclp_queue_timer) ||
5099f0128f9SGerald Schaefer 		    time_after(sclp_queue_timer.expires, req->queue_expires))
5109f0128f9SGerald Schaefer 			mod_timer(&sclp_queue_timer, req->queue_expires);
5119f0128f9SGerald Schaefer 	} else
5129f0128f9SGerald Schaefer 		req->queue_expires = 0;
5131da177e4SLinus Torvalds 	/* Start if request is first in list */
514dbd8ae63SPeter Oberparleiter 	if (sclp_running_state == sclp_running_state_idle &&
515dbd8ae63SPeter Oberparleiter 	    req->list.prev == &sclp_req_queue) {
5161da177e4SLinus Torvalds 		rc = __sclp_start_request(req);
5171da177e4SLinus Torvalds 		if (rc)
5181da177e4SLinus Torvalds 			list_del(&req->list);
5191da177e4SLinus Torvalds 	}
5201da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
5211da177e4SLinus Torvalds 	return rc;
5221da177e4SLinus Torvalds }
5231da177e4SLinus Torvalds 
5241da177e4SLinus Torvalds EXPORT_SYMBOL(sclp_add_request);
5251da177e4SLinus Torvalds 
5261da177e4SLinus Torvalds /* Dispatch events found in request buffer to registered listeners. Return 0
5271da177e4SLinus Torvalds  * if all events were dispatched, non-zero otherwise. */
5281da177e4SLinus Torvalds static int
sclp_dispatch_evbufs(struct sccb_header * sccb)5291da177e4SLinus Torvalds sclp_dispatch_evbufs(struct sccb_header *sccb)
5301da177e4SLinus Torvalds {
5311da177e4SLinus Torvalds 	unsigned long flags;
5321da177e4SLinus Torvalds 	struct evbuf_header *evbuf;
5331da177e4SLinus Torvalds 	struct list_head *l;
5341da177e4SLinus Torvalds 	struct sclp_register *reg;
5351da177e4SLinus Torvalds 	int offset;
5361da177e4SLinus Torvalds 	int rc;
5371da177e4SLinus Torvalds 
5381da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
5391da177e4SLinus Torvalds 	rc = 0;
5401da177e4SLinus Torvalds 	for (offset = sizeof(struct sccb_header); offset < sccb->length;
5411da177e4SLinus Torvalds 	     offset += evbuf->length) {
5421da177e4SLinus Torvalds 		evbuf = (struct evbuf_header *) ((addr_t) sccb + offset);
543e2e5a0f2SPeter Oberparleiter 		/* Check for malformed hardware response */
544e2e5a0f2SPeter Oberparleiter 		if (evbuf->length == 0)
545e2e5a0f2SPeter Oberparleiter 			break;
546e2e5a0f2SPeter Oberparleiter 		/* Search for event handler */
5471da177e4SLinus Torvalds 		reg = NULL;
5481da177e4SLinus Torvalds 		list_for_each(l, &sclp_reg_list) {
5491da177e4SLinus Torvalds 			reg = list_entry(l, struct sclp_register, list);
5500ee5f8dcSClaudio Imbrenda 			if (reg->receive_mask & SCLP_EVTYP_MASK(evbuf->type))
5511da177e4SLinus Torvalds 				break;
5521da177e4SLinus Torvalds 			else
5531da177e4SLinus Torvalds 				reg = NULL;
5541da177e4SLinus Torvalds 		}
55570aa5d39SPeter Oberparleiter 
55670aa5d39SPeter Oberparleiter 		/* EVNT: Event callback (b=receiver) */
55770aa5d39SPeter Oberparleiter 		sclp_trace_evbuf(2, "EVNT", 0, reg ? (u64)reg->receiver_fn : 0,
55870aa5d39SPeter Oberparleiter 				 evbuf, !reg);
55970aa5d39SPeter Oberparleiter 
5601da177e4SLinus Torvalds 		if (reg && reg->receiver_fn) {
5611da177e4SLinus Torvalds 			spin_unlock_irqrestore(&sclp_lock, flags);
5621da177e4SLinus Torvalds 			reg->receiver_fn(evbuf);
5631da177e4SLinus Torvalds 			spin_lock_irqsave(&sclp_lock, flags);
5641da177e4SLinus Torvalds 		} else if (reg == NULL)
565d06cbda6SHeiko Carstens 			rc = -EOPNOTSUPP;
5661da177e4SLinus Torvalds 	}
5671da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
5681da177e4SLinus Torvalds 	return rc;
5691da177e4SLinus Torvalds }
5701da177e4SLinus Torvalds 
5711da177e4SLinus Torvalds /* Read event data request callback. */
5721da177e4SLinus Torvalds static void
sclp_read_cb(struct sclp_req * req,void * data)5731da177e4SLinus Torvalds sclp_read_cb(struct sclp_req *req, void *data)
5741da177e4SLinus Torvalds {
5751da177e4SLinus Torvalds 	unsigned long flags;
5761da177e4SLinus Torvalds 	struct sccb_header *sccb;
5771da177e4SLinus Torvalds 
5781da177e4SLinus Torvalds 	sccb = (struct sccb_header *) req->sccb;
5791da177e4SLinus Torvalds 	if (req->status == SCLP_REQ_DONE && (sccb->response_code == 0x20 ||
5801da177e4SLinus Torvalds 	    sccb->response_code == 0x220))
5811da177e4SLinus Torvalds 		sclp_dispatch_evbufs(sccb);
5821da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
5831da177e4SLinus Torvalds 	sclp_reading_state = sclp_reading_state_idle;
5841da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
5851da177e4SLinus Torvalds }
5861da177e4SLinus Torvalds 
5871da177e4SLinus Torvalds /* Prepare read event data request. Called while sclp_lock is locked. */
__sclp_make_read_req(void)588364c8558SHeiko Carstens static void __sclp_make_read_req(void)
5891da177e4SLinus Torvalds {
5901da177e4SLinus Torvalds 	struct sccb_header *sccb;
5911da177e4SLinus Torvalds 
5921da177e4SLinus Torvalds 	sccb = (struct sccb_header *) sclp_read_sccb;
5931da177e4SLinus Torvalds 	clear_page(sccb);
5941da177e4SLinus Torvalds 	memset(&sclp_read_req, 0, sizeof(struct sclp_req));
595ab14de6cSHeiko Carstens 	sclp_read_req.command = SCLP_CMDW_READ_EVENT_DATA;
5961da177e4SLinus Torvalds 	sclp_read_req.status = SCLP_REQ_QUEUED;
5971da177e4SLinus Torvalds 	sclp_read_req.start_count = 0;
5981da177e4SLinus Torvalds 	sclp_read_req.callback = sclp_read_cb;
5991da177e4SLinus Torvalds 	sclp_read_req.sccb = sccb;
6001da177e4SLinus Torvalds 	sccb->length = PAGE_SIZE;
6011da177e4SLinus Torvalds 	sccb->function_code = 0;
6021da177e4SLinus Torvalds 	sccb->control_mask[2] = 0x80;
6031da177e4SLinus Torvalds }
6041da177e4SLinus Torvalds 
6051da177e4SLinus Torvalds /* Search request list for request with matching sccb. Return request if found,
6061da177e4SLinus Torvalds  * NULL otherwise. Called while sclp_lock is locked. */
6071da177e4SLinus Torvalds static inline struct sclp_req *
__sclp_find_req(u32 sccb)6081da177e4SLinus Torvalds __sclp_find_req(u32 sccb)
6091da177e4SLinus Torvalds {
6101da177e4SLinus Torvalds 	struct list_head *l;
6111da177e4SLinus Torvalds 	struct sclp_req *req;
6121da177e4SLinus Torvalds 
6131da177e4SLinus Torvalds 	list_for_each(l, &sclp_req_queue) {
6141da177e4SLinus Torvalds 		req = list_entry(l, struct sclp_req, list);
615ada1da31SAlexander Gordeev 		if (sccb == __pa(req->sccb))
6161da177e4SLinus Torvalds 			return req;
6171da177e4SLinus Torvalds 	}
6181da177e4SLinus Torvalds 	return NULL;
6191da177e4SLinus Torvalds }
6201da177e4SLinus Torvalds 
ok_response(u32 sccb_int,sclp_cmdw_t cmd)62170aa5d39SPeter Oberparleiter static bool ok_response(u32 sccb_int, sclp_cmdw_t cmd)
62270aa5d39SPeter Oberparleiter {
623ada1da31SAlexander Gordeev 	struct sccb_header *sccb = (struct sccb_header *)__va(sccb_int);
62470aa5d39SPeter Oberparleiter 	struct evbuf_header *evbuf;
62570aa5d39SPeter Oberparleiter 	u16 response;
62670aa5d39SPeter Oberparleiter 
62770aa5d39SPeter Oberparleiter 	if (!sccb)
62870aa5d39SPeter Oberparleiter 		return true;
62970aa5d39SPeter Oberparleiter 
63070aa5d39SPeter Oberparleiter 	/* Check SCCB response. */
63170aa5d39SPeter Oberparleiter 	response = sccb->response_code & 0xff;
63270aa5d39SPeter Oberparleiter 	if (response != 0x10 && response != 0x20)
63370aa5d39SPeter Oberparleiter 		return false;
63470aa5d39SPeter Oberparleiter 
63570aa5d39SPeter Oberparleiter 	/* Check event-processed flag on outgoing events. */
63670aa5d39SPeter Oberparleiter 	if (cmd == SCLP_CMDW_WRITE_EVENT_DATA) {
63770aa5d39SPeter Oberparleiter 		evbuf = (struct evbuf_header *)(sccb + 1);
63870aa5d39SPeter Oberparleiter 		if (!(evbuf->flags & 0x80))
63970aa5d39SPeter Oberparleiter 			return false;
64070aa5d39SPeter Oberparleiter 	}
64170aa5d39SPeter Oberparleiter 
64270aa5d39SPeter Oberparleiter 	return true;
64370aa5d39SPeter Oberparleiter }
64470aa5d39SPeter Oberparleiter 
6451da177e4SLinus Torvalds /* Handler for external interruption. Perform request post-processing.
6461da177e4SLinus Torvalds  * Prepare read event data request if necessary. Start processing of next
6471da177e4SLinus Torvalds  * request on queue. */
sclp_interrupt_handler(struct ext_code ext_code,unsigned int param32,unsigned long param64)648fde15c3aSHeiko Carstens static void sclp_interrupt_handler(struct ext_code ext_code,
649f6649a7eSMartin Schwidefsky 				   unsigned int param32, unsigned long param64)
6501da177e4SLinus Torvalds {
6511da177e4SLinus Torvalds 	struct sclp_req *req;
6521da177e4SLinus Torvalds 	u32 finished_sccb;
6531da177e4SLinus Torvalds 	u32 evbuf_pending;
6541da177e4SLinus Torvalds 
655420f42ecSHeiko Carstens 	inc_irq_stat(IRQEXT_SCP);
6561da177e4SLinus Torvalds 	spin_lock(&sclp_lock);
657f6649a7eSMartin Schwidefsky 	finished_sccb = param32 & 0xfffffff8;
658f6649a7eSMartin Schwidefsky 	evbuf_pending = param32 & 0x3;
65970aa5d39SPeter Oberparleiter 
66070aa5d39SPeter Oberparleiter 	/* INT: Interrupt received (a=intparm, b=cmd) */
66170aa5d39SPeter Oberparleiter 	sclp_trace_sccb(0, "INT", param32, active_cmd, active_cmd,
662ada1da31SAlexander Gordeev 			(struct sccb_header *)__va(finished_sccb),
66370aa5d39SPeter Oberparleiter 			!ok_response(finished_sccb, active_cmd));
66470aa5d39SPeter Oberparleiter 
6651da177e4SLinus Torvalds 	if (finished_sccb) {
666dbd8ae63SPeter Oberparleiter 		del_timer(&sclp_request_timer);
667dbd8ae63SPeter Oberparleiter 		sclp_running_state = sclp_running_state_reset_pending;
6681da177e4SLinus Torvalds 		req = __sclp_find_req(finished_sccb);
6691da177e4SLinus Torvalds 		if (req) {
6701da177e4SLinus Torvalds 			/* Request post-processing */
6711da177e4SLinus Torvalds 			list_del(&req->list);
6721da177e4SLinus Torvalds 			req->status = SCLP_REQ_DONE;
67370aa5d39SPeter Oberparleiter 
67470aa5d39SPeter Oberparleiter 			/* RQOK: Request success (a=sccb, b=summary) */
67570aa5d39SPeter Oberparleiter 			sclp_trace_req(2, "RQOK", req, false);
67670aa5d39SPeter Oberparleiter 
6771da177e4SLinus Torvalds 			if (req->callback) {
6781da177e4SLinus Torvalds 				spin_unlock(&sclp_lock);
6791da177e4SLinus Torvalds 				req->callback(req, req->callback_data);
6801da177e4SLinus Torvalds 				spin_lock(&sclp_lock);
6811da177e4SLinus Torvalds 			}
68270aa5d39SPeter Oberparleiter 		} else {
68370aa5d39SPeter Oberparleiter 			/* UNEX: Unexpected SCCB completion (a=sccb address) */
68470aa5d39SPeter Oberparleiter 			sclp_trace(0, "UNEX", finished_sccb, 0, true);
6851da177e4SLinus Torvalds 		}
6861da177e4SLinus Torvalds 		sclp_running_state = sclp_running_state_idle;
68770aa5d39SPeter Oberparleiter 		active_cmd = 0;
6881da177e4SLinus Torvalds 	}
689d082d3ceSPeter Oberparleiter 	if (evbuf_pending &&
690dbd8ae63SPeter Oberparleiter 	    sclp_activation_state == sclp_activation_state_active)
691dbd8ae63SPeter Oberparleiter 		__sclp_queue_read_req();
6921da177e4SLinus Torvalds 	spin_unlock(&sclp_lock);
6931da177e4SLinus Torvalds 	sclp_process_queue();
6941da177e4SLinus Torvalds }
6951da177e4SLinus Torvalds 
6961da177e4SLinus Torvalds /* Convert interval in jiffies to TOD ticks. */
6971da177e4SLinus Torvalds static inline u64
sclp_tod_from_jiffies(unsigned long jiffies)6981da177e4SLinus Torvalds sclp_tod_from_jiffies(unsigned long jiffies)
6991da177e4SLinus Torvalds {
7001da177e4SLinus Torvalds 	return (u64) (jiffies / HZ) << 32;
7011da177e4SLinus Torvalds }
7021da177e4SLinus Torvalds 
7031da177e4SLinus Torvalds /* Wait until a currently running request finished. Note: while this function
7041da177e4SLinus Torvalds  * is running, no timers are served on the calling CPU. */
7051da177e4SLinus Torvalds void
sclp_sync_wait(void)7061da177e4SLinus Torvalds sclp_sync_wait(void)
7071da177e4SLinus Torvalds {
708934b2857SHeiko Carstens 	unsigned long long old_tick;
7091f194a4cSHeiko Carstens 	unsigned long flags;
7101da177e4SLinus Torvalds 	unsigned long cr0, cr0_sync;
71170aa5d39SPeter Oberparleiter 	static u64 sync_count;
7121da177e4SLinus Torvalds 	u64 timeout;
713c59d744bSHeiko Carstens 	int irq_context;
7141da177e4SLinus Torvalds 
71570aa5d39SPeter Oberparleiter 	/* SYN1: Synchronous wait start (a=runstate, b=sync count) */
71670aa5d39SPeter Oberparleiter 	sclp_trace(4, "SYN1", sclp_running_state, ++sync_count, false);
71770aa5d39SPeter Oberparleiter 
7181da177e4SLinus Torvalds 	/* We'll be disabling timer interrupts, so we need a custom timeout
7191da177e4SLinus Torvalds 	 * mechanism */
7201da177e4SLinus Torvalds 	timeout = 0;
7211da177e4SLinus Torvalds 	if (timer_pending(&sclp_request_timer)) {
7221da177e4SLinus Torvalds 		/* Get timeout TOD value */
7238c071b0fSMartin Schwidefsky 		timeout = get_tod_clock_fast() +
7241da177e4SLinus Torvalds 			  sclp_tod_from_jiffies(sclp_request_timer.expires -
7251da177e4SLinus Torvalds 						jiffies);
7261da177e4SLinus Torvalds 	}
7271f194a4cSHeiko Carstens 	local_irq_save(flags);
7281da177e4SLinus Torvalds 	/* Prevent bottom half from executing once we force interrupts open */
729c59d744bSHeiko Carstens 	irq_context = in_interrupt();
730c59d744bSHeiko Carstens 	if (!irq_context)
7311da177e4SLinus Torvalds 		local_bh_disable();
7321da177e4SLinus Torvalds 	/* Enable service-signal interruption, disable timer interrupts */
733934b2857SHeiko Carstens 	old_tick = local_tick_disable();
7341f194a4cSHeiko Carstens 	trace_hardirqs_on();
7351da177e4SLinus Torvalds 	__ctl_store(cr0, 0, 0);
736c2ab7282SHeiko Carstens 	cr0_sync = cr0 & ~CR0_IRQ_SUBCLASS_MASK;
737c2ab7282SHeiko Carstens 	cr0_sync |= 1UL << (63 - 54);
7381da177e4SLinus Torvalds 	__ctl_load(cr0_sync, 0, 0);
739df9ee292SDavid Howells 	__arch_local_irq_stosm(0x01);
7401da177e4SLinus Torvalds 	/* Loop until driver state indicates finished request */
7411da177e4SLinus Torvalds 	while (sclp_running_state != sclp_running_state_idle) {
7421da177e4SLinus Torvalds 		/* Check for expired request timer */
7434f45c37fSYu Liao 		if (get_tod_clock_fast() > timeout && del_timer(&sclp_request_timer))
744841b86f3SKees Cook 			sclp_request_timer.function(&sclp_request_timer);
7451da177e4SLinus Torvalds 		cpu_relax();
7461da177e4SLinus Torvalds 	}
7471f194a4cSHeiko Carstens 	local_irq_disable();
7481da177e4SLinus Torvalds 	__ctl_load(cr0, 0, 0);
749c59d744bSHeiko Carstens 	if (!irq_context)
7501f194a4cSHeiko Carstens 		_local_bh_enable();
751934b2857SHeiko Carstens 	local_tick_enable(old_tick);
7521f194a4cSHeiko Carstens 	local_irq_restore(flags);
75370aa5d39SPeter Oberparleiter 
75470aa5d39SPeter Oberparleiter 	/* SYN2: Synchronous wait end (a=runstate, b=sync_count) */
75570aa5d39SPeter Oberparleiter 	sclp_trace(4, "SYN2", sclp_running_state, sync_count, false);
7561da177e4SLinus Torvalds }
7571da177e4SLinus Torvalds EXPORT_SYMBOL(sclp_sync_wait);
7581da177e4SLinus Torvalds 
7591da177e4SLinus Torvalds /* Dispatch changes in send and receive mask to registered listeners. */
7604d284cacSHeiko Carstens static void
sclp_dispatch_state_change(void)7611da177e4SLinus Torvalds sclp_dispatch_state_change(void)
7621da177e4SLinus Torvalds {
7631da177e4SLinus Torvalds 	struct list_head *l;
7641da177e4SLinus Torvalds 	struct sclp_register *reg;
7651da177e4SLinus Torvalds 	unsigned long flags;
7661da177e4SLinus Torvalds 	sccb_mask_t receive_mask;
7671da177e4SLinus Torvalds 	sccb_mask_t send_mask;
7681da177e4SLinus Torvalds 
7691da177e4SLinus Torvalds 	do {
7701da177e4SLinus Torvalds 		spin_lock_irqsave(&sclp_lock, flags);
7711da177e4SLinus Torvalds 		reg = NULL;
7721da177e4SLinus Torvalds 		list_for_each(l, &sclp_reg_list) {
7731da177e4SLinus Torvalds 			reg = list_entry(l, struct sclp_register, list);
774d082d3ceSPeter Oberparleiter 			receive_mask = reg->send_mask & sclp_receive_mask;
775d082d3ceSPeter Oberparleiter 			send_mask = reg->receive_mask & sclp_send_mask;
7761da177e4SLinus Torvalds 			if (reg->sclp_receive_mask != receive_mask ||
7771da177e4SLinus Torvalds 			    reg->sclp_send_mask != send_mask) {
7781da177e4SLinus Torvalds 				reg->sclp_receive_mask = receive_mask;
7791da177e4SLinus Torvalds 				reg->sclp_send_mask = send_mask;
7801da177e4SLinus Torvalds 				break;
7811da177e4SLinus Torvalds 			} else
7821da177e4SLinus Torvalds 				reg = NULL;
7831da177e4SLinus Torvalds 		}
7841da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
78570aa5d39SPeter Oberparleiter 		if (reg && reg->state_change_fn) {
78670aa5d39SPeter Oberparleiter 			/* STCG: State-change callback (b=callback) */
78770aa5d39SPeter Oberparleiter 			sclp_trace(2, "STCG", 0, (u64)reg->state_change_fn,
78870aa5d39SPeter Oberparleiter 				   false);
78970aa5d39SPeter Oberparleiter 
7901da177e4SLinus Torvalds 			reg->state_change_fn(reg);
79170aa5d39SPeter Oberparleiter 		}
7921da177e4SLinus Torvalds 	} while (reg);
7931da177e4SLinus Torvalds }
7941da177e4SLinus Torvalds 
7951da177e4SLinus Torvalds struct sclp_statechangebuf {
7961da177e4SLinus Torvalds 	struct evbuf_header	header;
7971da177e4SLinus Torvalds 	u8		validity_sclp_active_facility_mask : 1;
7981da177e4SLinus Torvalds 	u8		validity_sclp_receive_mask : 1;
7991da177e4SLinus Torvalds 	u8		validity_sclp_send_mask : 1;
8001da177e4SLinus Torvalds 	u8		validity_read_data_function_mask : 1;
8011da177e4SLinus Torvalds 	u16		_zeros : 12;
8021da177e4SLinus Torvalds 	u16		mask_length;
8031da177e4SLinus Torvalds 	u64		sclp_active_facility_mask;
804b8435635SClaudio Imbrenda 	u8		masks[2 * 1021 + 4];	/* variable length */
805b8435635SClaudio Imbrenda 	/*
806b8435635SClaudio Imbrenda 	 * u8		sclp_receive_mask[mask_length];
807b8435635SClaudio Imbrenda 	 * u8		sclp_send_mask[mask_length];
808b8435635SClaudio Imbrenda 	 * u32		read_data_function_mask;
809b8435635SClaudio Imbrenda 	 */
8101da177e4SLinus Torvalds } __attribute__((packed));
8111da177e4SLinus Torvalds 
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds /* State change event callback. Inform listeners of changes. */
8141da177e4SLinus Torvalds static void
sclp_state_change_cb(struct evbuf_header * evbuf)8151da177e4SLinus Torvalds sclp_state_change_cb(struct evbuf_header *evbuf)
8161da177e4SLinus Torvalds {
8171da177e4SLinus Torvalds 	unsigned long flags;
8181da177e4SLinus Torvalds 	struct sclp_statechangebuf *scbuf;
8191da177e4SLinus Torvalds 
820b8435635SClaudio Imbrenda 	BUILD_BUG_ON(sizeof(struct sclp_statechangebuf) > PAGE_SIZE);
821b8435635SClaudio Imbrenda 
8221da177e4SLinus Torvalds 	scbuf = (struct sclp_statechangebuf *) evbuf;
8231da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
8241da177e4SLinus Torvalds 	if (scbuf->validity_sclp_receive_mask)
825b8435635SClaudio Imbrenda 		sclp_receive_mask = sccb_get_recv_mask(scbuf);
8261da177e4SLinus Torvalds 	if (scbuf->validity_sclp_send_mask)
827b8435635SClaudio Imbrenda 		sclp_send_mask = sccb_get_send_mask(scbuf);
8281da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
829887d935aSHeiko Carstens 	if (scbuf->validity_sclp_active_facility_mask)
83078335a30SDavid Hildenbrand 		sclp.facilities = scbuf->sclp_active_facility_mask;
8311da177e4SLinus Torvalds 	sclp_dispatch_state_change();
8321da177e4SLinus Torvalds }
8331da177e4SLinus Torvalds 
8341da177e4SLinus Torvalds static struct sclp_register sclp_state_change_event = {
8356d4740c8SStefan Haberland 	.receive_mask = EVTYP_STATECHANGE_MASK,
8361da177e4SLinus Torvalds 	.receiver_fn = sclp_state_change_cb
8371da177e4SLinus Torvalds };
8381da177e4SLinus Torvalds 
8391da177e4SLinus Torvalds /* Calculate receive and send mask of currently registered listeners.
8401da177e4SLinus Torvalds  * Called while sclp_lock is locked. */
8411da177e4SLinus Torvalds static inline void
__sclp_get_mask(sccb_mask_t * receive_mask,sccb_mask_t * send_mask)8421da177e4SLinus Torvalds __sclp_get_mask(sccb_mask_t *receive_mask, sccb_mask_t *send_mask)
8431da177e4SLinus Torvalds {
8441da177e4SLinus Torvalds 	struct list_head *l;
8451da177e4SLinus Torvalds 	struct sclp_register *t;
8461da177e4SLinus Torvalds 
8471da177e4SLinus Torvalds 	*receive_mask = 0;
8481da177e4SLinus Torvalds 	*send_mask = 0;
8491da177e4SLinus Torvalds 	list_for_each(l, &sclp_reg_list) {
8501da177e4SLinus Torvalds 		t = list_entry(l, struct sclp_register, list);
8511da177e4SLinus Torvalds 		*receive_mask |= t->receive_mask;
8521da177e4SLinus Torvalds 		*send_mask |= t->send_mask;
8531da177e4SLinus Torvalds 	}
8541da177e4SLinus Torvalds }
8551da177e4SLinus Torvalds 
8561da177e4SLinus Torvalds /* Register event listener. Return 0 on success, non-zero otherwise. */
8571da177e4SLinus Torvalds int
sclp_register(struct sclp_register * reg)8581da177e4SLinus Torvalds sclp_register(struct sclp_register *reg)
8591da177e4SLinus Torvalds {
8601da177e4SLinus Torvalds 	unsigned long flags;
8611da177e4SLinus Torvalds 	sccb_mask_t receive_mask;
8621da177e4SLinus Torvalds 	sccb_mask_t send_mask;
8631da177e4SLinus Torvalds 	int rc;
8641da177e4SLinus Torvalds 
86570aa5d39SPeter Oberparleiter 	/* REG: Event listener registered (b=caller) */
86670aa5d39SPeter Oberparleiter 	sclp_trace_register(2, "REG", 0, _RET_IP_, reg);
86770aa5d39SPeter Oberparleiter 
8681da177e4SLinus Torvalds 	rc = sclp_init();
8691da177e4SLinus Torvalds 	if (rc)
8701da177e4SLinus Torvalds 		return rc;
8711da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
8721da177e4SLinus Torvalds 	/* Check event mask for collisions */
8731da177e4SLinus Torvalds 	__sclp_get_mask(&receive_mask, &send_mask);
8741da177e4SLinus Torvalds 	if (reg->receive_mask & receive_mask || reg->send_mask & send_mask) {
8751da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
8761da177e4SLinus Torvalds 		return -EBUSY;
8771da177e4SLinus Torvalds 	}
8781da177e4SLinus Torvalds 	/* Trigger initial state change callback */
8791da177e4SLinus Torvalds 	reg->sclp_receive_mask = 0;
8801da177e4SLinus Torvalds 	reg->sclp_send_mask = 0;
8811da177e4SLinus Torvalds 	list_add(&reg->list, &sclp_reg_list);
8821da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
8831da177e4SLinus Torvalds 	rc = sclp_init_mask(1);
8841da177e4SLinus Torvalds 	if (rc) {
8851da177e4SLinus Torvalds 		spin_lock_irqsave(&sclp_lock, flags);
8861da177e4SLinus Torvalds 		list_del(&reg->list);
8871da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
8881da177e4SLinus Torvalds 	}
8891da177e4SLinus Torvalds 	return rc;
8901da177e4SLinus Torvalds }
8911da177e4SLinus Torvalds 
8921da177e4SLinus Torvalds EXPORT_SYMBOL(sclp_register);
8931da177e4SLinus Torvalds 
8941da177e4SLinus Torvalds /* Unregister event listener. */
8951da177e4SLinus Torvalds void
sclp_unregister(struct sclp_register * reg)8961da177e4SLinus Torvalds sclp_unregister(struct sclp_register *reg)
8971da177e4SLinus Torvalds {
8981da177e4SLinus Torvalds 	unsigned long flags;
8991da177e4SLinus Torvalds 
90070aa5d39SPeter Oberparleiter 	/* UREG: Event listener unregistered (b=caller) */
90170aa5d39SPeter Oberparleiter 	sclp_trace_register(2, "UREG", 0, _RET_IP_, reg);
90270aa5d39SPeter Oberparleiter 
9031da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
9041da177e4SLinus Torvalds 	list_del(&reg->list);
9051da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
9061da177e4SLinus Torvalds 	sclp_init_mask(1);
9071da177e4SLinus Torvalds }
9081da177e4SLinus Torvalds 
9091da177e4SLinus Torvalds EXPORT_SYMBOL(sclp_unregister);
9101da177e4SLinus Torvalds 
9111da177e4SLinus Torvalds /* Remove event buffers which are marked processed. Return the number of
9121da177e4SLinus Torvalds  * remaining event buffers. */
9131da177e4SLinus Torvalds int
sclp_remove_processed(struct sccb_header * sccb)9141da177e4SLinus Torvalds sclp_remove_processed(struct sccb_header *sccb)
9151da177e4SLinus Torvalds {
9161da177e4SLinus Torvalds 	struct evbuf_header *evbuf;
9171da177e4SLinus Torvalds 	int unprocessed;
9181da177e4SLinus Torvalds 	u16 remaining;
9191da177e4SLinus Torvalds 
9201da177e4SLinus Torvalds 	evbuf = (struct evbuf_header *) (sccb + 1);
9211da177e4SLinus Torvalds 	unprocessed = 0;
9221da177e4SLinus Torvalds 	remaining = sccb->length - sizeof(struct sccb_header);
9231da177e4SLinus Torvalds 	while (remaining > 0) {
9241da177e4SLinus Torvalds 		remaining -= evbuf->length;
9251da177e4SLinus Torvalds 		if (evbuf->flags & 0x80) {
9261da177e4SLinus Torvalds 			sccb->length -= evbuf->length;
9271da177e4SLinus Torvalds 			memcpy(evbuf, (void *) ((addr_t) evbuf + evbuf->length),
9281da177e4SLinus Torvalds 			       remaining);
9291da177e4SLinus Torvalds 		} else {
9301da177e4SLinus Torvalds 			unprocessed++;
9311da177e4SLinus Torvalds 			evbuf = (struct evbuf_header *)
9321da177e4SLinus Torvalds 					((addr_t) evbuf + evbuf->length);
9331da177e4SLinus Torvalds 		}
9341da177e4SLinus Torvalds 	}
9351da177e4SLinus Torvalds 	return unprocessed;
9361da177e4SLinus Torvalds }
9371da177e4SLinus Torvalds 
9381da177e4SLinus Torvalds EXPORT_SYMBOL(sclp_remove_processed);
9391da177e4SLinus Torvalds 
9401da177e4SLinus Torvalds /* Prepare init mask request. Called while sclp_lock is locked. */
9411da177e4SLinus Torvalds static inline void
__sclp_make_init_req(sccb_mask_t receive_mask,sccb_mask_t send_mask)9420ee5f8dcSClaudio Imbrenda __sclp_make_init_req(sccb_mask_t receive_mask, sccb_mask_t send_mask)
9431da177e4SLinus Torvalds {
944087c4d74SGerald Schaefer 	struct init_sccb *sccb = sclp_init_sccb;
9451da177e4SLinus Torvalds 
9461da177e4SLinus Torvalds 	clear_page(sccb);
9471da177e4SLinus Torvalds 	memset(&sclp_init_req, 0, sizeof(struct sclp_req));
948ab14de6cSHeiko Carstens 	sclp_init_req.command = SCLP_CMDW_WRITE_EVENT_MASK;
9491da177e4SLinus Torvalds 	sclp_init_req.status = SCLP_REQ_FILLED;
9501da177e4SLinus Torvalds 	sclp_init_req.start_count = 0;
9511da177e4SLinus Torvalds 	sclp_init_req.callback = NULL;
9521da177e4SLinus Torvalds 	sclp_init_req.callback_data = NULL;
9531da177e4SLinus Torvalds 	sclp_init_req.sccb = sccb;
9540ee5f8dcSClaudio Imbrenda 	sccb->header.length = sizeof(*sccb);
9550b0d1173SClaudio Imbrenda 	if (sclp_mask_compat_mode)
9560b0d1173SClaudio Imbrenda 		sccb->mask_length = SCLP_MASK_SIZE_COMPAT;
9570b0d1173SClaudio Imbrenda 	else
9581da177e4SLinus Torvalds 		sccb->mask_length = sizeof(sccb_mask_t);
959b8435635SClaudio Imbrenda 	sccb_set_recv_mask(sccb, receive_mask);
960b8435635SClaudio Imbrenda 	sccb_set_send_mask(sccb, send_mask);
961b8435635SClaudio Imbrenda 	sccb_set_sclp_recv_mask(sccb, 0);
962b8435635SClaudio Imbrenda 	sccb_set_sclp_send_mask(sccb, 0);
9631da177e4SLinus Torvalds }
9641da177e4SLinus Torvalds 
9651da177e4SLinus Torvalds /* Start init mask request. If calculate is non-zero, calculate the mask as
9661da177e4SLinus Torvalds  * requested by registered listeners. Use zero mask otherwise. Return 0 on
9671da177e4SLinus Torvalds  * success, non-zero otherwise. */
9681da177e4SLinus Torvalds static int
sclp_init_mask(int calculate)9691da177e4SLinus Torvalds sclp_init_mask(int calculate)
9701da177e4SLinus Torvalds {
9711da177e4SLinus Torvalds 	unsigned long flags;
972087c4d74SGerald Schaefer 	struct init_sccb *sccb = sclp_init_sccb;
9731da177e4SLinus Torvalds 	sccb_mask_t receive_mask;
9741da177e4SLinus Torvalds 	sccb_mask_t send_mask;
9751da177e4SLinus Torvalds 	int retry;
9761da177e4SLinus Torvalds 	int rc;
9771da177e4SLinus Torvalds 	unsigned long wait;
9781da177e4SLinus Torvalds 
9791da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
9801da177e4SLinus Torvalds 	/* Check if interface is in appropriate state */
9811da177e4SLinus Torvalds 	if (sclp_mask_state != sclp_mask_state_idle) {
9821da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
9831da177e4SLinus Torvalds 		return -EBUSY;
9841da177e4SLinus Torvalds 	}
9851da177e4SLinus Torvalds 	if (sclp_activation_state == sclp_activation_state_inactive) {
9861da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
9871da177e4SLinus Torvalds 		return -EINVAL;
9881da177e4SLinus Torvalds 	}
9891da177e4SLinus Torvalds 	sclp_mask_state = sclp_mask_state_initializing;
9901da177e4SLinus Torvalds 	/* Determine mask */
9911da177e4SLinus Torvalds 	if (calculate)
9921da177e4SLinus Torvalds 		__sclp_get_mask(&receive_mask, &send_mask);
9931da177e4SLinus Torvalds 	else {
9941da177e4SLinus Torvalds 		receive_mask = 0;
9951da177e4SLinus Torvalds 		send_mask = 0;
9961da177e4SLinus Torvalds 	}
9971da177e4SLinus Torvalds 	rc = -EIO;
9981da177e4SLinus Torvalds 	for (retry = 0; retry <= SCLP_MASK_RETRY; retry++) {
9991da177e4SLinus Torvalds 		/* Prepare request */
10001da177e4SLinus Torvalds 		__sclp_make_init_req(receive_mask, send_mask);
10011da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
10021da177e4SLinus Torvalds 		if (sclp_add_request(&sclp_init_req)) {
10031da177e4SLinus Torvalds 			/* Try again later */
10041da177e4SLinus Torvalds 			wait = jiffies + SCLP_BUSY_INTERVAL * HZ;
10051da177e4SLinus Torvalds 			while (time_before(jiffies, wait))
10061da177e4SLinus Torvalds 				sclp_sync_wait();
10071da177e4SLinus Torvalds 			spin_lock_irqsave(&sclp_lock, flags);
10081da177e4SLinus Torvalds 			continue;
10091da177e4SLinus Torvalds 		}
10101da177e4SLinus Torvalds 		while (sclp_init_req.status != SCLP_REQ_DONE &&
10111da177e4SLinus Torvalds 		       sclp_init_req.status != SCLP_REQ_FAILED)
10121da177e4SLinus Torvalds 			sclp_sync_wait();
10131da177e4SLinus Torvalds 		spin_lock_irqsave(&sclp_lock, flags);
10141da177e4SLinus Torvalds 		if (sclp_init_req.status == SCLP_REQ_DONE &&
10151da177e4SLinus Torvalds 		    sccb->header.response_code == 0x20) {
10161da177e4SLinus Torvalds 			/* Successful request */
10171da177e4SLinus Torvalds 			if (calculate) {
1018b8435635SClaudio Imbrenda 				sclp_receive_mask = sccb_get_sclp_recv_mask(sccb);
1019b8435635SClaudio Imbrenda 				sclp_send_mask = sccb_get_sclp_send_mask(sccb);
10201da177e4SLinus Torvalds 			} else {
10211da177e4SLinus Torvalds 				sclp_receive_mask = 0;
10221da177e4SLinus Torvalds 				sclp_send_mask = 0;
10231da177e4SLinus Torvalds 			}
10241da177e4SLinus Torvalds 			spin_unlock_irqrestore(&sclp_lock, flags);
10251da177e4SLinus Torvalds 			sclp_dispatch_state_change();
10261da177e4SLinus Torvalds 			spin_lock_irqsave(&sclp_lock, flags);
10271da177e4SLinus Torvalds 			rc = 0;
10281da177e4SLinus Torvalds 			break;
10291da177e4SLinus Torvalds 		}
10301da177e4SLinus Torvalds 	}
10311da177e4SLinus Torvalds 	sclp_mask_state = sclp_mask_state_idle;
10321da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
10331da177e4SLinus Torvalds 	return rc;
10341da177e4SLinus Torvalds }
10351da177e4SLinus Torvalds 
10361da177e4SLinus Torvalds /* Deactivate SCLP interface. On success, new requests will be rejected,
10371da177e4SLinus Torvalds  * events will no longer be dispatched. Return 0 on success, non-zero
10381da177e4SLinus Torvalds  * otherwise. */
10391da177e4SLinus Torvalds int
sclp_deactivate(void)10401da177e4SLinus Torvalds sclp_deactivate(void)
10411da177e4SLinus Torvalds {
10421da177e4SLinus Torvalds 	unsigned long flags;
10431da177e4SLinus Torvalds 	int rc;
10441da177e4SLinus Torvalds 
10451da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
10461da177e4SLinus Torvalds 	/* Deactivate can only be called when active */
10471da177e4SLinus Torvalds 	if (sclp_activation_state != sclp_activation_state_active) {
10481da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
10491da177e4SLinus Torvalds 		return -EINVAL;
10501da177e4SLinus Torvalds 	}
10511da177e4SLinus Torvalds 	sclp_activation_state = sclp_activation_state_deactivating;
10521da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
10531da177e4SLinus Torvalds 	rc = sclp_init_mask(0);
10541da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
10551da177e4SLinus Torvalds 	if (rc == 0)
10561da177e4SLinus Torvalds 		sclp_activation_state = sclp_activation_state_inactive;
10571da177e4SLinus Torvalds 	else
10581da177e4SLinus Torvalds 		sclp_activation_state = sclp_activation_state_active;
10591da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
10601da177e4SLinus Torvalds 	return rc;
10611da177e4SLinus Torvalds }
10621da177e4SLinus Torvalds 
10631da177e4SLinus Torvalds EXPORT_SYMBOL(sclp_deactivate);
10641da177e4SLinus Torvalds 
10651da177e4SLinus Torvalds /* Reactivate SCLP interface after sclp_deactivate. On success, new
10661da177e4SLinus Torvalds  * requests will be accepted, events will be dispatched again. Return 0 on
10671da177e4SLinus Torvalds  * success, non-zero otherwise. */
10681da177e4SLinus Torvalds int
sclp_reactivate(void)10691da177e4SLinus Torvalds sclp_reactivate(void)
10701da177e4SLinus Torvalds {
10711da177e4SLinus Torvalds 	unsigned long flags;
10721da177e4SLinus Torvalds 	int rc;
10731da177e4SLinus Torvalds 
10741da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
10751da177e4SLinus Torvalds 	/* Reactivate can only be called when inactive */
10761da177e4SLinus Torvalds 	if (sclp_activation_state != sclp_activation_state_inactive) {
10771da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
10781da177e4SLinus Torvalds 		return -EINVAL;
10791da177e4SLinus Torvalds 	}
10801da177e4SLinus Torvalds 	sclp_activation_state = sclp_activation_state_activating;
10811da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
10821da177e4SLinus Torvalds 	rc = sclp_init_mask(1);
10831da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
10841da177e4SLinus Torvalds 	if (rc == 0)
10851da177e4SLinus Torvalds 		sclp_activation_state = sclp_activation_state_active;
10861da177e4SLinus Torvalds 	else
10871da177e4SLinus Torvalds 		sclp_activation_state = sclp_activation_state_inactive;
10881da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
10891da177e4SLinus Torvalds 	return rc;
10901da177e4SLinus Torvalds }
10911da177e4SLinus Torvalds 
10921da177e4SLinus Torvalds EXPORT_SYMBOL(sclp_reactivate);
10931da177e4SLinus Torvalds 
10941da177e4SLinus Torvalds /* Handler for external interruption used during initialization. Modify
10951da177e4SLinus Torvalds  * request state to done. */
sclp_check_handler(struct ext_code ext_code,unsigned int param32,unsigned long param64)1096fde15c3aSHeiko Carstens static void sclp_check_handler(struct ext_code ext_code,
1097f6649a7eSMartin Schwidefsky 			       unsigned int param32, unsigned long param64)
10981da177e4SLinus Torvalds {
10991da177e4SLinus Torvalds 	u32 finished_sccb;
11001da177e4SLinus Torvalds 
1101420f42ecSHeiko Carstens 	inc_irq_stat(IRQEXT_SCP);
1102f6649a7eSMartin Schwidefsky 	finished_sccb = param32 & 0xfffffff8;
11031da177e4SLinus Torvalds 	/* Is this the interrupt we are waiting for? */
11041da177e4SLinus Torvalds 	if (finished_sccb == 0)
11051da177e4SLinus Torvalds 		return;
1106ada1da31SAlexander Gordeev 	if (finished_sccb != __pa(sclp_init_sccb))
1107a12c53f4SMartin Schwidefsky 		panic("sclp: unsolicited interrupt for buffer at 0x%x\n",
1108a12c53f4SMartin Schwidefsky 		      finished_sccb);
11091da177e4SLinus Torvalds 	spin_lock(&sclp_lock);
11101da177e4SLinus Torvalds 	if (sclp_running_state == sclp_running_state_running) {
11111da177e4SLinus Torvalds 		sclp_init_req.status = SCLP_REQ_DONE;
11121da177e4SLinus Torvalds 		sclp_running_state = sclp_running_state_idle;
11131da177e4SLinus Torvalds 	}
11141da177e4SLinus Torvalds 	spin_unlock(&sclp_lock);
11151da177e4SLinus Torvalds }
11161da177e4SLinus Torvalds 
11171da177e4SLinus Torvalds /* Initial init mask request timed out. Modify request state to failed. */
11181da177e4SLinus Torvalds static void
sclp_check_timeout(struct timer_list * unused)1119c9602ee7SKees Cook sclp_check_timeout(struct timer_list *unused)
11201da177e4SLinus Torvalds {
11211da177e4SLinus Torvalds 	unsigned long flags;
11221da177e4SLinus Torvalds 
11231da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
11241da177e4SLinus Torvalds 	if (sclp_running_state == sclp_running_state_running) {
11251da177e4SLinus Torvalds 		sclp_init_req.status = SCLP_REQ_FAILED;
11261da177e4SLinus Torvalds 		sclp_running_state = sclp_running_state_idle;
11271da177e4SLinus Torvalds 	}
11281da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
11291da177e4SLinus Torvalds }
11301da177e4SLinus Torvalds 
11311da177e4SLinus Torvalds /* Perform a check of the SCLP interface. Return zero if the interface is
11321da177e4SLinus Torvalds  * available and there are no pending requests from a previous instance.
11331da177e4SLinus Torvalds  * Return non-zero otherwise. */
11341da177e4SLinus Torvalds static int
sclp_check_interface(void)11351da177e4SLinus Torvalds sclp_check_interface(void)
11361da177e4SLinus Torvalds {
11371da177e4SLinus Torvalds 	struct init_sccb *sccb;
11381da177e4SLinus Torvalds 	unsigned long flags;
11391da177e4SLinus Torvalds 	int retry;
11401da177e4SLinus Torvalds 	int rc;
11411da177e4SLinus Torvalds 
11421da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
11431da177e4SLinus Torvalds 	/* Prepare init mask command */
11441dad093bSThomas Huth 	rc = register_external_irq(EXT_IRQ_SERVICE_SIG, sclp_check_handler);
11451da177e4SLinus Torvalds 	if (rc) {
11461da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
11471da177e4SLinus Torvalds 		return rc;
11481da177e4SLinus Torvalds 	}
11491da177e4SLinus Torvalds 	for (retry = 0; retry <= SCLP_INIT_RETRY; retry++) {
11501da177e4SLinus Torvalds 		__sclp_make_init_req(0, 0);
11511da177e4SLinus Torvalds 		sccb = (struct init_sccb *) sclp_init_req.sccb;
115270aa5d39SPeter Oberparleiter 		rc = sclp_service_call_trace(sclp_init_req.command, sccb);
11531da177e4SLinus Torvalds 		if (rc == -EIO)
11541da177e4SLinus Torvalds 			break;
11551da177e4SLinus Torvalds 		sclp_init_req.status = SCLP_REQ_RUNNING;
11561da177e4SLinus Torvalds 		sclp_running_state = sclp_running_state_running;
11571da177e4SLinus Torvalds 		__sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
1158c9602ee7SKees Cook 					 sclp_check_timeout);
11591da177e4SLinus Torvalds 		spin_unlock_irqrestore(&sclp_lock, flags);
11601da177e4SLinus Torvalds 		/* Enable service-signal interruption - needs to happen
11611da177e4SLinus Torvalds 		 * with IRQs enabled. */
116282003c3eSHeiko Carstens 		irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL);
11631da177e4SLinus Torvalds 		/* Wait for signal from interrupt or timeout */
11641da177e4SLinus Torvalds 		sclp_sync_wait();
11651da177e4SLinus Torvalds 		/* Disable service-signal interruption - needs to happen
11661da177e4SLinus Torvalds 		 * with IRQs enabled. */
116782003c3eSHeiko Carstens 		irq_subclass_unregister(IRQ_SUBCLASS_SERVICE_SIGNAL);
11681da177e4SLinus Torvalds 		spin_lock_irqsave(&sclp_lock, flags);
11691da177e4SLinus Torvalds 		del_timer(&sclp_request_timer);
11700b0d1173SClaudio Imbrenda 		rc = -EBUSY;
11710b0d1173SClaudio Imbrenda 		if (sclp_init_req.status == SCLP_REQ_DONE) {
11720b0d1173SClaudio Imbrenda 			if (sccb->header.response_code == 0x20) {
11731da177e4SLinus Torvalds 				rc = 0;
11741da177e4SLinus Torvalds 				break;
11750b0d1173SClaudio Imbrenda 			} else if (sccb->header.response_code == 0x74f0) {
11760b0d1173SClaudio Imbrenda 				if (!sclp_mask_compat_mode) {
11770b0d1173SClaudio Imbrenda 					sclp_mask_compat_mode = true;
11780b0d1173SClaudio Imbrenda 					retry = 0;
11790b0d1173SClaudio Imbrenda 				}
11800b0d1173SClaudio Imbrenda 			}
11810b0d1173SClaudio Imbrenda 		}
11821da177e4SLinus Torvalds 	}
11831dad093bSThomas Huth 	unregister_external_irq(EXT_IRQ_SERVICE_SIG, sclp_check_handler);
11841da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
11851da177e4SLinus Torvalds 	return rc;
11861da177e4SLinus Torvalds }
11871da177e4SLinus Torvalds 
11881da177e4SLinus Torvalds /* Reboot event handler. Reset send and receive mask to prevent pending SCLP
11891da177e4SLinus Torvalds  * events from interfering with rebooted system. */
11901da177e4SLinus Torvalds static int
sclp_reboot_event(struct notifier_block * this,unsigned long event,void * ptr)11911da177e4SLinus Torvalds sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
11921da177e4SLinus Torvalds {
11931da177e4SLinus Torvalds 	sclp_deactivate();
11941da177e4SLinus Torvalds 	return NOTIFY_DONE;
11951da177e4SLinus Torvalds }
11961da177e4SLinus Torvalds 
11971da177e4SLinus Torvalds static struct notifier_block sclp_reboot_notifier = {
1198*ccea29b1SThomas Weißschuh 	.notifier_call = sclp_reboot_event,
1199*ccea29b1SThomas Weißschuh 	.priority      = INT_MIN,
12001da177e4SLinus Torvalds };
12011da177e4SLinus Torvalds 
con_pages_show(struct device_driver * dev,char * buf)120236369569SGreg Kroah-Hartman static ssize_t con_pages_show(struct device_driver *dev, char *buf)
120325b41a7bSMartin Schwidefsky {
1204a086c53dSHeiko Carstens 	return sysfs_emit(buf, "%i\n", sclp_console_pages);
120525b41a7bSMartin Schwidefsky }
120625b41a7bSMartin Schwidefsky 
120736369569SGreg Kroah-Hartman static DRIVER_ATTR_RO(con_pages);
120825b41a7bSMartin Schwidefsky 
con_drop_store(struct device_driver * dev,const char * buf,size_t count)12091143f6f5SHeiko Carstens static ssize_t con_drop_store(struct device_driver *dev, const char *buf, size_t count)
12101143f6f5SHeiko Carstens {
12111143f6f5SHeiko Carstens 	int rc;
12121143f6f5SHeiko Carstens 
12131143f6f5SHeiko Carstens 	rc = kstrtobool(buf, &sclp_console_drop);
12141143f6f5SHeiko Carstens 	return rc ?: count;
12151143f6f5SHeiko Carstens }
12161143f6f5SHeiko Carstens 
con_drop_show(struct device_driver * dev,char * buf)121736369569SGreg Kroah-Hartman static ssize_t con_drop_show(struct device_driver *dev, char *buf)
121825b41a7bSMartin Schwidefsky {
1219a086c53dSHeiko Carstens 	return sysfs_emit(buf, "%i\n", sclp_console_drop);
122025b41a7bSMartin Schwidefsky }
122125b41a7bSMartin Schwidefsky 
12221143f6f5SHeiko Carstens static DRIVER_ATTR_RW(con_drop);
122325b41a7bSMartin Schwidefsky 
con_full_show(struct device_driver * dev,char * buf)122436369569SGreg Kroah-Hartman static ssize_t con_full_show(struct device_driver *dev, char *buf)
122525b41a7bSMartin Schwidefsky {
1226a086c53dSHeiko Carstens 	return sysfs_emit(buf, "%lu\n", sclp_console_full);
122725b41a7bSMartin Schwidefsky }
122825b41a7bSMartin Schwidefsky 
122936369569SGreg Kroah-Hartman static DRIVER_ATTR_RO(con_full);
123025b41a7bSMartin Schwidefsky 
123125b41a7bSMartin Schwidefsky static struct attribute *sclp_drv_attrs[] = {
123225b41a7bSMartin Schwidefsky 	&driver_attr_con_pages.attr,
123325b41a7bSMartin Schwidefsky 	&driver_attr_con_drop.attr,
123425b41a7bSMartin Schwidefsky 	&driver_attr_con_full.attr,
123525b41a7bSMartin Schwidefsky 	NULL,
123625b41a7bSMartin Schwidefsky };
123725b41a7bSMartin Schwidefsky static struct attribute_group sclp_drv_attr_group = {
123825b41a7bSMartin Schwidefsky 	.attrs = sclp_drv_attrs,
123925b41a7bSMartin Schwidefsky };
124025b41a7bSMartin Schwidefsky static const struct attribute_group *sclp_drv_attr_groups[] = {
124125b41a7bSMartin Schwidefsky 	&sclp_drv_attr_group,
124225b41a7bSMartin Schwidefsky 	NULL,
124325b41a7bSMartin Schwidefsky };
124425b41a7bSMartin Schwidefsky 
124562b74942SMichael Holzheu static struct platform_driver sclp_pdrv = {
124662b74942SMichael Holzheu 	.driver = {
124762b74942SMichael Holzheu 		.name	= "sclp",
124825b41a7bSMartin Schwidefsky 		.groups = sclp_drv_attr_groups,
124962b74942SMichael Holzheu 	},
125062b74942SMichael Holzheu };
125162b74942SMichael Holzheu 
12521da177e4SLinus Torvalds /* Initialize SCLP driver. Return zero if driver is operational, non-zero
12531da177e4SLinus Torvalds  * otherwise. */
12541da177e4SLinus Torvalds static int
sclp_init(void)12551da177e4SLinus Torvalds sclp_init(void)
12561da177e4SLinus Torvalds {
12571da177e4SLinus Torvalds 	unsigned long flags;
125862b74942SMichael Holzheu 	int rc = 0;
12591da177e4SLinus Torvalds 
12601da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
12611da177e4SLinus Torvalds 	/* Check for previous or running initialization */
126262b74942SMichael Holzheu 	if (sclp_init_state != sclp_init_state_uninitialized)
126362b74942SMichael Holzheu 		goto fail_unlock;
12641da177e4SLinus Torvalds 	sclp_init_state = sclp_init_state_initializing;
1265087c4d74SGerald Schaefer 	sclp_read_sccb = (void *) __get_free_page(GFP_ATOMIC | GFP_DMA);
1266087c4d74SGerald Schaefer 	sclp_init_sccb = (void *) __get_free_page(GFP_ATOMIC | GFP_DMA);
1267087c4d74SGerald Schaefer 	BUG_ON(!sclp_read_sccb || !sclp_init_sccb);
12681da177e4SLinus Torvalds 	/* Set up variables */
12691da177e4SLinus Torvalds 	list_add(&sclp_state_change_event.list, &sclp_reg_list);
1270c9602ee7SKees Cook 	timer_setup(&sclp_request_timer, NULL, 0);
1271c9602ee7SKees Cook 	timer_setup(&sclp_queue_timer, sclp_req_queue_timeout, 0);
12721da177e4SLinus Torvalds 	/* Check interface */
12731da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
12741da177e4SLinus Torvalds 	rc = sclp_check_interface();
12751da177e4SLinus Torvalds 	spin_lock_irqsave(&sclp_lock, flags);
127662b74942SMichael Holzheu 	if (rc)
127762b74942SMichael Holzheu 		goto fail_init_state_uninitialized;
12781da177e4SLinus Torvalds 	/* Register reboot handler */
12791da177e4SLinus Torvalds 	rc = register_reboot_notifier(&sclp_reboot_notifier);
128062b74942SMichael Holzheu 	if (rc)
128162b74942SMichael Holzheu 		goto fail_init_state_uninitialized;
12821da177e4SLinus Torvalds 	/* Register interrupt handler */
12831dad093bSThomas Huth 	rc = register_external_irq(EXT_IRQ_SERVICE_SIG, sclp_interrupt_handler);
128462b74942SMichael Holzheu 	if (rc)
128562b74942SMichael Holzheu 		goto fail_unregister_reboot_notifier;
12861da177e4SLinus Torvalds 	sclp_init_state = sclp_init_state_initialized;
12871da177e4SLinus Torvalds 	spin_unlock_irqrestore(&sclp_lock, flags);
12881da177e4SLinus Torvalds 	/* Enable service-signal external interruption - needs to happen with
12891da177e4SLinus Torvalds 	 * IRQs enabled. */
129082003c3eSHeiko Carstens 	irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL);
12911da177e4SLinus Torvalds 	sclp_init_mask(1);
12921da177e4SLinus Torvalds 	return 0;
129362b74942SMichael Holzheu 
129462b74942SMichael Holzheu fail_unregister_reboot_notifier:
129562b74942SMichael Holzheu 	unregister_reboot_notifier(&sclp_reboot_notifier);
129662b74942SMichael Holzheu fail_init_state_uninitialized:
12970a31b3fdSHeiko Carstens 	list_del(&sclp_state_change_event.list);
129862b74942SMichael Holzheu 	sclp_init_state = sclp_init_state_uninitialized;
1299087c4d74SGerald Schaefer 	free_page((unsigned long) sclp_read_sccb);
1300087c4d74SGerald Schaefer 	free_page((unsigned long) sclp_init_sccb);
130162b74942SMichael Holzheu fail_unlock:
130262b74942SMichael Holzheu 	spin_unlock_irqrestore(&sclp_lock, flags);
130362b74942SMichael Holzheu 	return rc;
13041da177e4SLinus Torvalds }
1305b3d00c3bSPeter Oberparleiter 
sclp_initcall(void)1306b3d00c3bSPeter Oberparleiter static __init int sclp_initcall(void)
1307b3d00c3bSPeter Oberparleiter {
130862b74942SMichael Holzheu 	int rc;
130962b74942SMichael Holzheu 
131062b74942SMichael Holzheu 	rc = platform_driver_register(&sclp_pdrv);
131162b74942SMichael Holzheu 	if (rc)
131262b74942SMichael Holzheu 		return rc;
131325b41a7bSMartin Schwidefsky 
1314b3d00c3bSPeter Oberparleiter 	return sclp_init();
1315b3d00c3bSPeter Oberparleiter }
1316b3d00c3bSPeter Oberparleiter 
1317b3d00c3bSPeter Oberparleiter arch_initcall(sclp_initcall);
1318