blob: b76c61f824857d4ed05d3a38e9657f078098ef90 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Michael Holzheu62b749422009-06-16 10:30:40 +02002 * core function to access sclp interface
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Michael Holzheu62b749422009-06-16 10:30:40 +02004 * Copyright IBM Corp. 1999, 2009
5 *
6 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
7 * Martin Schwidefsky <schwidefsky@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Heiko Carstens052ff462011-01-05 12:47:28 +010010#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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>
Peter Oberparleiterb3d00c32007-04-27 16:01:51 +020018#include <linux/init.h>
Michael Holzheu62b749422009-06-16 10:30:40 +020019#include <linux/suspend.h>
20#include <linux/completion.h>
21#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/s390_ext.h>
Heiko Carstens052ff462011-01-05 12:47:28 +010023#include <asm/types.h>
24#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include "sclp.h"
27
28#define SCLP_HEADER "sclp: "
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/* Lock to protect internal data consistency. */
31static DEFINE_SPINLOCK(sclp_lock);
32
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +010033/* Mask of events that we can send to the sclp interface. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static sccb_mask_t sclp_receive_mask;
35
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +010036/* Mask of events that we can receive from the sclp interface. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static sccb_mask_t sclp_send_mask;
38
39/* List of registered event listeners and senders. */
40static struct list_head sclp_reg_list;
41
42/* List of queued requests. */
43static struct list_head sclp_req_queue;
44
45/* Data for read and and init requests. */
46static struct sclp_req sclp_read_req;
47static struct sclp_req sclp_init_req;
48static char sclp_read_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
49static char sclp_init_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
50
Michael Holzheu62b749422009-06-16 10:30:40 +020051/* Suspend request */
52static DECLARE_COMPLETION(sclp_request_queue_flushed);
53
54static void sclp_suspend_req_cb(struct sclp_req *req, void *data)
55{
56 complete(&sclp_request_queue_flushed);
57}
58
59static struct sclp_req sclp_suspend_req;
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/* Timer for request retries. */
62static struct timer_list sclp_request_timer;
63
64/* Internal state: is the driver initialized? */
65static volatile enum sclp_init_state_t {
66 sclp_init_state_uninitialized,
67 sclp_init_state_initializing,
68 sclp_init_state_initialized
69} sclp_init_state = sclp_init_state_uninitialized;
70
71/* Internal state: is a request active at the sclp? */
72static volatile enum sclp_running_state_t {
73 sclp_running_state_idle,
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +010074 sclp_running_state_running,
75 sclp_running_state_reset_pending
Linus Torvalds1da177e2005-04-16 15:20:36 -070076} sclp_running_state = sclp_running_state_idle;
77
78/* Internal state: is a read request pending? */
79static volatile enum sclp_reading_state_t {
80 sclp_reading_state_idle,
81 sclp_reading_state_reading
82} sclp_reading_state = sclp_reading_state_idle;
83
84/* Internal state: is the driver currently serving requests? */
85static volatile enum sclp_activation_state_t {
86 sclp_activation_state_active,
87 sclp_activation_state_deactivating,
88 sclp_activation_state_inactive,
89 sclp_activation_state_activating
90} sclp_activation_state = sclp_activation_state_active;
91
92/* Internal state: is an init mask request pending? */
93static volatile enum sclp_mask_state_t {
94 sclp_mask_state_idle,
95 sclp_mask_state_initializing
96} sclp_mask_state = sclp_mask_state_idle;
97
Michael Holzheu62b749422009-06-16 10:30:40 +020098/* Internal state: is the driver suspended? */
99static enum sclp_suspend_state_t {
100 sclp_suspend_state_running,
101 sclp_suspend_state_suspended,
102} sclp_suspend_state = sclp_suspend_state_running;
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104/* Maximum retry counts */
105#define SCLP_INIT_RETRY 3
106#define SCLP_MASK_RETRY 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108/* Timeout intervals in seconds.*/
Peter Oberparleiter25fab9e2006-02-11 17:55:59 -0800109#define SCLP_BUSY_INTERVAL 10
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100110#define SCLP_RETRY_INTERVAL 30
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112static void sclp_process_queue(void);
Heiko Carstens364c8552007-10-12 16:11:35 +0200113static void __sclp_make_read_req(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static int sclp_init_mask(int calculate);
115static int sclp_init(void);
116
117/* Perform service call. Return 0 on success, non-zero otherwise. */
Heiko Carstensab14de62007-02-05 21:18:37 +0100118int
119sclp_service_call(sclp_cmdw_t command, void *sccb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
121 int cc;
122
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200123 asm volatile(
124 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
125 " ipm %0\n"
126 " srl %0,28"
127 : "=&d" (cc) : "d" (command), "a" (__pa(sccb))
128 : "cc", "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 if (cc == 3)
130 return -EIO;
131 if (cc == 2)
132 return -EBUSY;
133 return 0;
134}
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100137static void
138__sclp_queue_read_req(void)
139{
140 if (sclp_reading_state == sclp_reading_state_idle) {
141 sclp_reading_state = sclp_reading_state_reading;
142 __sclp_make_read_req();
143 /* Add request to head of queue */
144 list_add(&sclp_read_req.list, &sclp_req_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
148/* Set up request retry timer. Called while sclp_lock is locked. */
149static inline void
150__sclp_set_request_timer(unsigned long time, void (*function)(unsigned long),
151 unsigned long data)
152{
153 del_timer(&sclp_request_timer);
154 sclp_request_timer.function = function;
155 sclp_request_timer.data = data;
156 sclp_request_timer.expires = jiffies + time;
157 add_timer(&sclp_request_timer);
158}
159
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100160/* Request timeout handler. Restart the request queue. If DATA is non-zero,
161 * force restart of running request. */
162static void
163sclp_request_timeout(unsigned long data)
164{
165 unsigned long flags;
166
167 spin_lock_irqsave(&sclp_lock, flags);
168 if (data) {
169 if (sclp_running_state == sclp_running_state_running) {
170 /* Break running state and queue NOP read event request
171 * to get a defined interface state. */
172 __sclp_queue_read_req();
173 sclp_running_state = sclp_running_state_idle;
174 }
175 } else {
176 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
177 sclp_request_timeout, 0);
178 }
179 spin_unlock_irqrestore(&sclp_lock, flags);
180 sclp_process_queue();
181}
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/* Try to start a request. Return zero if the request was successfully
184 * started or if it will be started at a later time. Return non-zero otherwise.
185 * Called while sclp_lock is locked. */
186static int
187__sclp_start_request(struct sclp_req *req)
188{
189 int rc;
190
191 if (sclp_running_state != sclp_running_state_idle)
192 return 0;
193 del_timer(&sclp_request_timer);
Heiko Carstensab14de62007-02-05 21:18:37 +0100194 rc = sclp_service_call(req->command, req->sccb);
Peter Oberparleiter25fab9e2006-02-11 17:55:59 -0800195 req->start_count++;
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 if (rc == 0) {
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800198 /* Successfully started request */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 req->status = SCLP_REQ_RUNNING;
200 sclp_running_state = sclp_running_state_running;
201 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
202 sclp_request_timeout, 1);
203 return 0;
204 } else if (rc == -EBUSY) {
205 /* Try again later */
206 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
207 sclp_request_timeout, 0);
208 return 0;
209 }
210 /* Request failed */
211 req->status = SCLP_REQ_FAILED;
212 return rc;
213}
214
215/* Try to start queued requests. */
216static void
217sclp_process_queue(void)
218{
219 struct sclp_req *req;
220 int rc;
221 unsigned long flags;
222
223 spin_lock_irqsave(&sclp_lock, flags);
224 if (sclp_running_state != sclp_running_state_idle) {
225 spin_unlock_irqrestore(&sclp_lock, flags);
226 return;
227 }
228 del_timer(&sclp_request_timer);
229 while (!list_empty(&sclp_req_queue)) {
230 req = list_entry(sclp_req_queue.next, struct sclp_req, list);
Michael Holzheu62b749422009-06-16 10:30:40 +0200231 if (!req->sccb)
232 goto do_post;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 rc = __sclp_start_request(req);
234 if (rc == 0)
235 break;
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100236 /* Request failed */
237 if (req->start_count > 1) {
238 /* Cannot abort already submitted request - could still
239 * be active at the SCLP */
240 __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ,
241 sclp_request_timeout, 0);
242 break;
243 }
Michael Holzheu62b749422009-06-16 10:30:40 +0200244do_post:
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100245 /* Post-processing for aborted request */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 list_del(&req->list);
247 if (req->callback) {
248 spin_unlock_irqrestore(&sclp_lock, flags);
249 req->callback(req, req->callback_data);
250 spin_lock_irqsave(&sclp_lock, flags);
251 }
252 }
253 spin_unlock_irqrestore(&sclp_lock, flags);
254}
255
Michael Holzheu62b749422009-06-16 10:30:40 +0200256static int __sclp_can_add_request(struct sclp_req *req)
257{
258 if (req == &sclp_suspend_req || req == &sclp_init_req)
259 return 1;
260 if (sclp_suspend_state != sclp_suspend_state_running)
261 return 0;
262 if (sclp_init_state != sclp_init_state_initialized)
263 return 0;
264 if (sclp_activation_state != sclp_activation_state_active)
265 return 0;
266 return 1;
267}
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269/* Queue a new request. Return zero on success, non-zero otherwise. */
270int
271sclp_add_request(struct sclp_req *req)
272{
273 unsigned long flags;
274 int rc;
275
276 spin_lock_irqsave(&sclp_lock, flags);
Michael Holzheu62b749422009-06-16 10:30:40 +0200277 if (!__sclp_can_add_request(req)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 spin_unlock_irqrestore(&sclp_lock, flags);
279 return -EIO;
280 }
281 req->status = SCLP_REQ_QUEUED;
282 req->start_count = 0;
283 list_add_tail(&req->list, &sclp_req_queue);
284 rc = 0;
285 /* Start if request is first in list */
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100286 if (sclp_running_state == sclp_running_state_idle &&
287 req->list.prev == &sclp_req_queue) {
Michael Holzheu62b749422009-06-16 10:30:40 +0200288 if (!req->sccb) {
289 list_del(&req->list);
290 rc = -ENODATA;
291 goto out;
292 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 rc = __sclp_start_request(req);
294 if (rc)
295 list_del(&req->list);
296 }
Michael Holzheu62b749422009-06-16 10:30:40 +0200297out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 spin_unlock_irqrestore(&sclp_lock, flags);
299 return rc;
300}
301
302EXPORT_SYMBOL(sclp_add_request);
303
304/* Dispatch events found in request buffer to registered listeners. Return 0
305 * if all events were dispatched, non-zero otherwise. */
306static int
307sclp_dispatch_evbufs(struct sccb_header *sccb)
308{
309 unsigned long flags;
310 struct evbuf_header *evbuf;
311 struct list_head *l;
312 struct sclp_register *reg;
313 int offset;
314 int rc;
315
316 spin_lock_irqsave(&sclp_lock, flags);
317 rc = 0;
318 for (offset = sizeof(struct sccb_header); offset < sccb->length;
319 offset += evbuf->length) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 evbuf = (struct evbuf_header *) ((addr_t) sccb + offset);
Peter Oberparleitere2e5a0f2009-02-19 15:18:59 +0100321 /* Check for malformed hardware response */
322 if (evbuf->length == 0)
323 break;
324 /* Search for event handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 reg = NULL;
326 list_for_each(l, &sclp_reg_list) {
327 reg = list_entry(l, struct sclp_register, list);
328 if (reg->receive_mask & (1 << (32 - evbuf->type)))
329 break;
330 else
331 reg = NULL;
332 }
333 if (reg && reg->receiver_fn) {
334 spin_unlock_irqrestore(&sclp_lock, flags);
335 reg->receiver_fn(evbuf);
336 spin_lock_irqsave(&sclp_lock, flags);
337 } else if (reg == NULL)
338 rc = -ENOSYS;
339 }
340 spin_unlock_irqrestore(&sclp_lock, flags);
341 return rc;
342}
343
344/* Read event data request callback. */
345static void
346sclp_read_cb(struct sclp_req *req, void *data)
347{
348 unsigned long flags;
349 struct sccb_header *sccb;
350
351 sccb = (struct sccb_header *) req->sccb;
352 if (req->status == SCLP_REQ_DONE && (sccb->response_code == 0x20 ||
353 sccb->response_code == 0x220))
354 sclp_dispatch_evbufs(sccb);
355 spin_lock_irqsave(&sclp_lock, flags);
356 sclp_reading_state = sclp_reading_state_idle;
357 spin_unlock_irqrestore(&sclp_lock, flags);
358}
359
360/* Prepare read event data request. Called while sclp_lock is locked. */
Heiko Carstens364c8552007-10-12 16:11:35 +0200361static void __sclp_make_read_req(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
363 struct sccb_header *sccb;
364
365 sccb = (struct sccb_header *) sclp_read_sccb;
366 clear_page(sccb);
367 memset(&sclp_read_req, 0, sizeof(struct sclp_req));
Heiko Carstensab14de62007-02-05 21:18:37 +0100368 sclp_read_req.command = SCLP_CMDW_READ_EVENT_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 sclp_read_req.status = SCLP_REQ_QUEUED;
370 sclp_read_req.start_count = 0;
371 sclp_read_req.callback = sclp_read_cb;
372 sclp_read_req.sccb = sccb;
373 sccb->length = PAGE_SIZE;
374 sccb->function_code = 0;
375 sccb->control_mask[2] = 0x80;
376}
377
378/* Search request list for request with matching sccb. Return request if found,
379 * NULL otherwise. Called while sclp_lock is locked. */
380static inline struct sclp_req *
381__sclp_find_req(u32 sccb)
382{
383 struct list_head *l;
384 struct sclp_req *req;
385
386 list_for_each(l, &sclp_req_queue) {
387 req = list_entry(l, struct sclp_req, list);
388 if (sccb == (u32) (addr_t) req->sccb)
389 return req;
390 }
391 return NULL;
392}
393
394/* Handler for external interruption. Perform request post-processing.
395 * Prepare read event data request if necessary. Start processing of next
396 * request on queue. */
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200397static void sclp_interrupt_handler(unsigned int ext_int_code,
398 unsigned int param32, unsigned long param64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
400 struct sclp_req *req;
401 u32 finished_sccb;
402 u32 evbuf_pending;
403
Heiko Carstens052ff462011-01-05 12:47:28 +0100404 kstat_cpu(smp_processor_id()).irqs[EXTINT_SCP]++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 spin_lock(&sclp_lock);
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200406 finished_sccb = param32 & 0xfffffff8;
407 evbuf_pending = param32 & 0x3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 if (finished_sccb) {
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100409 del_timer(&sclp_request_timer);
410 sclp_running_state = sclp_running_state_reset_pending;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 req = __sclp_find_req(finished_sccb);
412 if (req) {
413 /* Request post-processing */
414 list_del(&req->list);
415 req->status = SCLP_REQ_DONE;
416 if (req->callback) {
417 spin_unlock(&sclp_lock);
418 req->callback(req, req->callback_data);
419 spin_lock(&sclp_lock);
420 }
421 }
422 sclp_running_state = sclp_running_state_idle;
423 }
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +0100424 if (evbuf_pending &&
Peter Oberparleiterdbd8ae62007-02-05 21:17:00 +0100425 sclp_activation_state == sclp_activation_state_active)
426 __sclp_queue_read_req();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 spin_unlock(&sclp_lock);
428 sclp_process_queue();
429}
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431/* Convert interval in jiffies to TOD ticks. */
432static inline u64
433sclp_tod_from_jiffies(unsigned long jiffies)
434{
435 return (u64) (jiffies / HZ) << 32;
436}
437
438/* Wait until a currently running request finished. Note: while this function
439 * is running, no timers are served on the calling CPU. */
440void
441sclp_sync_wait(void)
442{
Heiko Carstens934b2852008-08-01 16:39:11 +0200443 unsigned long long old_tick;
Heiko Carstens1f194a42006-07-03 00:24:46 -0700444 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 unsigned long cr0, cr0_sync;
446 u64 timeout;
Heiko Carstensc59d7442007-02-05 21:17:16 +0100447 int irq_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 /* We'll be disabling timer interrupts, so we need a custom timeout
450 * mechanism */
451 timeout = 0;
452 if (timer_pending(&sclp_request_timer)) {
453 /* Get timeout TOD value */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200454 timeout = get_clock() +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 sclp_tod_from_jiffies(sclp_request_timer.expires -
456 jiffies);
457 }
Heiko Carstens1f194a42006-07-03 00:24:46 -0700458 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 /* Prevent bottom half from executing once we force interrupts open */
Heiko Carstensc59d7442007-02-05 21:17:16 +0100460 irq_context = in_interrupt();
461 if (!irq_context)
462 local_bh_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 /* Enable service-signal interruption, disable timer interrupts */
Heiko Carstens934b2852008-08-01 16:39:11 +0200464 old_tick = local_tick_disable();
Heiko Carstens1f194a42006-07-03 00:24:46 -0700465 trace_hardirqs_on();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 __ctl_store(cr0, 0, 0);
467 cr0_sync = cr0;
Heiko Carstens934b2852008-08-01 16:39:11 +0200468 cr0_sync &= 0xffff00a0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 cr0_sync |= 0x00000200;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 __ctl_load(cr0_sync, 0, 0);
David Howellsdf9ee292010-10-07 14:08:55 +0100471 __arch_local_irq_stosm(0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 /* Loop until driver state indicates finished request */
473 while (sclp_running_state != sclp_running_state_idle) {
474 /* Check for expired request timer */
475 if (timer_pending(&sclp_request_timer) &&
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200476 get_clock() > timeout &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 del_timer(&sclp_request_timer))
478 sclp_request_timer.function(sclp_request_timer.data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 cpu_relax();
480 }
Heiko Carstens1f194a42006-07-03 00:24:46 -0700481 local_irq_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 __ctl_load(cr0, 0, 0);
Heiko Carstensc59d7442007-02-05 21:17:16 +0100483 if (!irq_context)
484 _local_bh_enable();
Heiko Carstens934b2852008-08-01 16:39:11 +0200485 local_tick_enable(old_tick);
Heiko Carstens1f194a42006-07-03 00:24:46 -0700486 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488EXPORT_SYMBOL(sclp_sync_wait);
489
490/* Dispatch changes in send and receive mask to registered listeners. */
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100491static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492sclp_dispatch_state_change(void)
493{
494 struct list_head *l;
495 struct sclp_register *reg;
496 unsigned long flags;
497 sccb_mask_t receive_mask;
498 sccb_mask_t send_mask;
499
500 do {
501 spin_lock_irqsave(&sclp_lock, flags);
502 reg = NULL;
503 list_for_each(l, &sclp_reg_list) {
504 reg = list_entry(l, struct sclp_register, list);
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +0100505 receive_mask = reg->send_mask & sclp_receive_mask;
506 send_mask = reg->receive_mask & sclp_send_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (reg->sclp_receive_mask != receive_mask ||
508 reg->sclp_send_mask != send_mask) {
509 reg->sclp_receive_mask = receive_mask;
510 reg->sclp_send_mask = send_mask;
511 break;
512 } else
513 reg = NULL;
514 }
515 spin_unlock_irqrestore(&sclp_lock, flags);
516 if (reg && reg->state_change_fn)
517 reg->state_change_fn(reg);
518 } while (reg);
519}
520
521struct sclp_statechangebuf {
522 struct evbuf_header header;
523 u8 validity_sclp_active_facility_mask : 1;
524 u8 validity_sclp_receive_mask : 1;
525 u8 validity_sclp_send_mask : 1;
526 u8 validity_read_data_function_mask : 1;
527 u16 _zeros : 12;
528 u16 mask_length;
529 u64 sclp_active_facility_mask;
530 sccb_mask_t sclp_receive_mask;
531 sccb_mask_t sclp_send_mask;
532 u32 read_data_function_mask;
533} __attribute__((packed));
534
535
536/* State change event callback. Inform listeners of changes. */
537static void
538sclp_state_change_cb(struct evbuf_header *evbuf)
539{
540 unsigned long flags;
541 struct sclp_statechangebuf *scbuf;
542
543 scbuf = (struct sclp_statechangebuf *) evbuf;
544 if (scbuf->mask_length != sizeof(sccb_mask_t))
545 return;
546 spin_lock_irqsave(&sclp_lock, flags);
547 if (scbuf->validity_sclp_receive_mask)
548 sclp_receive_mask = scbuf->sclp_receive_mask;
549 if (scbuf->validity_sclp_send_mask)
550 sclp_send_mask = scbuf->sclp_send_mask;
551 spin_unlock_irqrestore(&sclp_lock, flags);
Heiko Carstens887d9352008-07-14 09:57:26 +0200552 if (scbuf->validity_sclp_active_facility_mask)
553 sclp_facilities = scbuf->sclp_active_facility_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 sclp_dispatch_state_change();
555}
556
557static struct sclp_register sclp_state_change_event = {
Stefan Haberland6d4740c2007-04-27 16:01:53 +0200558 .receive_mask = EVTYP_STATECHANGE_MASK,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .receiver_fn = sclp_state_change_cb
560};
561
562/* Calculate receive and send mask of currently registered listeners.
563 * Called while sclp_lock is locked. */
564static inline void
565__sclp_get_mask(sccb_mask_t *receive_mask, sccb_mask_t *send_mask)
566{
567 struct list_head *l;
568 struct sclp_register *t;
569
570 *receive_mask = 0;
571 *send_mask = 0;
572 list_for_each(l, &sclp_reg_list) {
573 t = list_entry(l, struct sclp_register, list);
574 *receive_mask |= t->receive_mask;
575 *send_mask |= t->send_mask;
576 }
577}
578
579/* Register event listener. Return 0 on success, non-zero otherwise. */
580int
581sclp_register(struct sclp_register *reg)
582{
583 unsigned long flags;
584 sccb_mask_t receive_mask;
585 sccb_mask_t send_mask;
586 int rc;
587
588 rc = sclp_init();
589 if (rc)
590 return rc;
591 spin_lock_irqsave(&sclp_lock, flags);
592 /* Check event mask for collisions */
593 __sclp_get_mask(&receive_mask, &send_mask);
594 if (reg->receive_mask & receive_mask || reg->send_mask & send_mask) {
595 spin_unlock_irqrestore(&sclp_lock, flags);
596 return -EBUSY;
597 }
598 /* Trigger initial state change callback */
599 reg->sclp_receive_mask = 0;
600 reg->sclp_send_mask = 0;
Michael Holzheu62b749422009-06-16 10:30:40 +0200601 reg->pm_event_posted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 list_add(&reg->list, &sclp_reg_list);
603 spin_unlock_irqrestore(&sclp_lock, flags);
604 rc = sclp_init_mask(1);
605 if (rc) {
606 spin_lock_irqsave(&sclp_lock, flags);
607 list_del(&reg->list);
608 spin_unlock_irqrestore(&sclp_lock, flags);
609 }
610 return rc;
611}
612
613EXPORT_SYMBOL(sclp_register);
614
615/* Unregister event listener. */
616void
617sclp_unregister(struct sclp_register *reg)
618{
619 unsigned long flags;
620
621 spin_lock_irqsave(&sclp_lock, flags);
622 list_del(&reg->list);
623 spin_unlock_irqrestore(&sclp_lock, flags);
624 sclp_init_mask(1);
625}
626
627EXPORT_SYMBOL(sclp_unregister);
628
629/* Remove event buffers which are marked processed. Return the number of
630 * remaining event buffers. */
631int
632sclp_remove_processed(struct sccb_header *sccb)
633{
634 struct evbuf_header *evbuf;
635 int unprocessed;
636 u16 remaining;
637
638 evbuf = (struct evbuf_header *) (sccb + 1);
639 unprocessed = 0;
640 remaining = sccb->length - sizeof(struct sccb_header);
641 while (remaining > 0) {
642 remaining -= evbuf->length;
643 if (evbuf->flags & 0x80) {
644 sccb->length -= evbuf->length;
645 memcpy(evbuf, (void *) ((addr_t) evbuf + evbuf->length),
646 remaining);
647 } else {
648 unprocessed++;
649 evbuf = (struct evbuf_header *)
650 ((addr_t) evbuf + evbuf->length);
651 }
652 }
653 return unprocessed;
654}
655
656EXPORT_SYMBOL(sclp_remove_processed);
657
658struct init_sccb {
659 struct sccb_header header;
660 u16 _reserved;
661 u16 mask_length;
662 sccb_mask_t receive_mask;
663 sccb_mask_t send_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 sccb_mask_t sclp_receive_mask;
Peter Oberparleiterd082d3c2008-02-19 15:29:32 +0100665 sccb_mask_t sclp_send_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666} __attribute__((packed));
667
668/* Prepare init mask request. Called while sclp_lock is locked. */
669static inline void
670__sclp_make_init_req(u32 receive_mask, u32 send_mask)
671{
672 struct init_sccb *sccb;
673
674 sccb = (struct init_sccb *) sclp_init_sccb;
675 clear_page(sccb);
676 memset(&sclp_init_req, 0, sizeof(struct sclp_req));
Heiko Carstensab14de62007-02-05 21:18:37 +0100677 sclp_init_req.command = SCLP_CMDW_WRITE_EVENT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 sclp_init_req.status = SCLP_REQ_FILLED;
679 sclp_init_req.start_count = 0;
680 sclp_init_req.callback = NULL;
681 sclp_init_req.callback_data = NULL;
682 sclp_init_req.sccb = sccb;
683 sccb->header.length = sizeof(struct init_sccb);
684 sccb->mask_length = sizeof(sccb_mask_t);
685 sccb->receive_mask = receive_mask;
686 sccb->send_mask = send_mask;
687 sccb->sclp_receive_mask = 0;
688 sccb->sclp_send_mask = 0;
689}
690
691/* Start init mask request. If calculate is non-zero, calculate the mask as
692 * requested by registered listeners. Use zero mask otherwise. Return 0 on
693 * success, non-zero otherwise. */
694static int
695sclp_init_mask(int calculate)
696{
697 unsigned long flags;
698 struct init_sccb *sccb = (struct init_sccb *) sclp_init_sccb;
699 sccb_mask_t receive_mask;
700 sccb_mask_t send_mask;
701 int retry;
702 int rc;
703 unsigned long wait;
704
705 spin_lock_irqsave(&sclp_lock, flags);
706 /* Check if interface is in appropriate state */
707 if (sclp_mask_state != sclp_mask_state_idle) {
708 spin_unlock_irqrestore(&sclp_lock, flags);
709 return -EBUSY;
710 }
711 if (sclp_activation_state == sclp_activation_state_inactive) {
712 spin_unlock_irqrestore(&sclp_lock, flags);
713 return -EINVAL;
714 }
715 sclp_mask_state = sclp_mask_state_initializing;
716 /* Determine mask */
717 if (calculate)
718 __sclp_get_mask(&receive_mask, &send_mask);
719 else {
720 receive_mask = 0;
721 send_mask = 0;
722 }
723 rc = -EIO;
724 for (retry = 0; retry <= SCLP_MASK_RETRY; retry++) {
725 /* Prepare request */
726 __sclp_make_init_req(receive_mask, send_mask);
727 spin_unlock_irqrestore(&sclp_lock, flags);
728 if (sclp_add_request(&sclp_init_req)) {
729 /* Try again later */
730 wait = jiffies + SCLP_BUSY_INTERVAL * HZ;
731 while (time_before(jiffies, wait))
732 sclp_sync_wait();
733 spin_lock_irqsave(&sclp_lock, flags);
734 continue;
735 }
736 while (sclp_init_req.status != SCLP_REQ_DONE &&
737 sclp_init_req.status != SCLP_REQ_FAILED)
738 sclp_sync_wait();
739 spin_lock_irqsave(&sclp_lock, flags);
740 if (sclp_init_req.status == SCLP_REQ_DONE &&
741 sccb->header.response_code == 0x20) {
742 /* Successful request */
743 if (calculate) {
744 sclp_receive_mask = sccb->sclp_receive_mask;
745 sclp_send_mask = sccb->sclp_send_mask;
746 } else {
747 sclp_receive_mask = 0;
748 sclp_send_mask = 0;
749 }
750 spin_unlock_irqrestore(&sclp_lock, flags);
751 sclp_dispatch_state_change();
752 spin_lock_irqsave(&sclp_lock, flags);
753 rc = 0;
754 break;
755 }
756 }
757 sclp_mask_state = sclp_mask_state_idle;
758 spin_unlock_irqrestore(&sclp_lock, flags);
759 return rc;
760}
761
762/* Deactivate SCLP interface. On success, new requests will be rejected,
763 * events will no longer be dispatched. Return 0 on success, non-zero
764 * otherwise. */
765int
766sclp_deactivate(void)
767{
768 unsigned long flags;
769 int rc;
770
771 spin_lock_irqsave(&sclp_lock, flags);
772 /* Deactivate can only be called when active */
773 if (sclp_activation_state != sclp_activation_state_active) {
774 spin_unlock_irqrestore(&sclp_lock, flags);
775 return -EINVAL;
776 }
777 sclp_activation_state = sclp_activation_state_deactivating;
778 spin_unlock_irqrestore(&sclp_lock, flags);
779 rc = sclp_init_mask(0);
780 spin_lock_irqsave(&sclp_lock, flags);
781 if (rc == 0)
782 sclp_activation_state = sclp_activation_state_inactive;
783 else
784 sclp_activation_state = sclp_activation_state_active;
785 spin_unlock_irqrestore(&sclp_lock, flags);
786 return rc;
787}
788
789EXPORT_SYMBOL(sclp_deactivate);
790
791/* Reactivate SCLP interface after sclp_deactivate. On success, new
792 * requests will be accepted, events will be dispatched again. Return 0 on
793 * success, non-zero otherwise. */
794int
795sclp_reactivate(void)
796{
797 unsigned long flags;
798 int rc;
799
800 spin_lock_irqsave(&sclp_lock, flags);
801 /* Reactivate can only be called when inactive */
802 if (sclp_activation_state != sclp_activation_state_inactive) {
803 spin_unlock_irqrestore(&sclp_lock, flags);
804 return -EINVAL;
805 }
806 sclp_activation_state = sclp_activation_state_activating;
807 spin_unlock_irqrestore(&sclp_lock, flags);
808 rc = sclp_init_mask(1);
809 spin_lock_irqsave(&sclp_lock, flags);
810 if (rc == 0)
811 sclp_activation_state = sclp_activation_state_active;
812 else
813 sclp_activation_state = sclp_activation_state_inactive;
814 spin_unlock_irqrestore(&sclp_lock, flags);
815 return rc;
816}
817
818EXPORT_SYMBOL(sclp_reactivate);
819
820/* Handler for external interruption used during initialization. Modify
821 * request state to done. */
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200822static void sclp_check_handler(unsigned int ext_int_code,
823 unsigned int param32, unsigned long param64)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
825 u32 finished_sccb;
826
Heiko Carstens052ff462011-01-05 12:47:28 +0100827 kstat_cpu(smp_processor_id()).irqs[EXTINT_SCP]++;
Martin Schwidefskyf6649a72010-10-25 16:10:38 +0200828 finished_sccb = param32 & 0xfffffff8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 /* Is this the interrupt we are waiting for? */
830 if (finished_sccb == 0)
831 return;
Martin Schwidefskya12c53f2008-07-14 09:59:28 +0200832 if (finished_sccb != (u32) (addr_t) sclp_init_sccb)
833 panic("sclp: unsolicited interrupt for buffer at 0x%x\n",
834 finished_sccb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 spin_lock(&sclp_lock);
836 if (sclp_running_state == sclp_running_state_running) {
837 sclp_init_req.status = SCLP_REQ_DONE;
838 sclp_running_state = sclp_running_state_idle;
839 }
840 spin_unlock(&sclp_lock);
841}
842
843/* Initial init mask request timed out. Modify request state to failed. */
844static void
845sclp_check_timeout(unsigned long data)
846{
847 unsigned long flags;
848
849 spin_lock_irqsave(&sclp_lock, flags);
850 if (sclp_running_state == sclp_running_state_running) {
851 sclp_init_req.status = SCLP_REQ_FAILED;
852 sclp_running_state = sclp_running_state_idle;
853 }
854 spin_unlock_irqrestore(&sclp_lock, flags);
855}
856
857/* Perform a check of the SCLP interface. Return zero if the interface is
858 * available and there are no pending requests from a previous instance.
859 * Return non-zero otherwise. */
860static int
861sclp_check_interface(void)
862{
863 struct init_sccb *sccb;
864 unsigned long flags;
865 int retry;
866 int rc;
867
868 spin_lock_irqsave(&sclp_lock, flags);
869 /* Prepare init mask command */
Heiko Carstens98b79982011-01-05 12:47:40 +0100870 rc = register_external_interrupt(0x2401, sclp_check_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (rc) {
872 spin_unlock_irqrestore(&sclp_lock, flags);
873 return rc;
874 }
875 for (retry = 0; retry <= SCLP_INIT_RETRY; retry++) {
876 __sclp_make_init_req(0, 0);
877 sccb = (struct init_sccb *) sclp_init_req.sccb;
Heiko Carstensab14de62007-02-05 21:18:37 +0100878 rc = sclp_service_call(sclp_init_req.command, sccb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (rc == -EIO)
880 break;
881 sclp_init_req.status = SCLP_REQ_RUNNING;
882 sclp_running_state = sclp_running_state_running;
883 __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ,
884 sclp_check_timeout, 0);
885 spin_unlock_irqrestore(&sclp_lock, flags);
886 /* Enable service-signal interruption - needs to happen
887 * with IRQs enabled. */
888 ctl_set_bit(0, 9);
889 /* Wait for signal from interrupt or timeout */
890 sclp_sync_wait();
891 /* Disable service-signal interruption - needs to happen
892 * with IRQs enabled. */
893 ctl_clear_bit(0,9);
894 spin_lock_irqsave(&sclp_lock, flags);
895 del_timer(&sclp_request_timer);
896 if (sclp_init_req.status == SCLP_REQ_DONE &&
897 sccb->header.response_code == 0x20) {
898 rc = 0;
899 break;
900 } else
901 rc = -EBUSY;
902 }
Heiko Carstens98b79982011-01-05 12:47:40 +0100903 unregister_external_interrupt(0x2401, sclp_check_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 spin_unlock_irqrestore(&sclp_lock, flags);
905 return rc;
906}
907
908/* Reboot event handler. Reset send and receive mask to prevent pending SCLP
909 * events from interfering with rebooted system. */
910static int
911sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr)
912{
913 sclp_deactivate();
914 return NOTIFY_DONE;
915}
916
917static struct notifier_block sclp_reboot_notifier = {
918 .notifier_call = sclp_reboot_event
919};
920
Michael Holzheu62b749422009-06-16 10:30:40 +0200921/*
922 * Suspend/resume SCLP notifier implementation
923 */
924
925static void sclp_pm_event(enum sclp_pm_event sclp_pm_event, int rollback)
926{
927 struct sclp_register *reg;
928 unsigned long flags;
929
930 if (!rollback) {
931 spin_lock_irqsave(&sclp_lock, flags);
932 list_for_each_entry(reg, &sclp_reg_list, list)
933 reg->pm_event_posted = 0;
934 spin_unlock_irqrestore(&sclp_lock, flags);
935 }
936 do {
937 spin_lock_irqsave(&sclp_lock, flags);
938 list_for_each_entry(reg, &sclp_reg_list, list) {
939 if (rollback && reg->pm_event_posted)
940 goto found;
941 if (!rollback && !reg->pm_event_posted)
942 goto found;
943 }
944 spin_unlock_irqrestore(&sclp_lock, flags);
945 return;
946found:
947 spin_unlock_irqrestore(&sclp_lock, flags);
948 if (reg->pm_event_fn)
949 reg->pm_event_fn(reg, sclp_pm_event);
950 reg->pm_event_posted = rollback ? 0 : 1;
951 } while (1);
952}
953
954/*
955 * Susend/resume callbacks for platform device
956 */
957
958static int sclp_freeze(struct device *dev)
959{
960 unsigned long flags;
961 int rc;
962
963 sclp_pm_event(SCLP_PM_EVENT_FREEZE, 0);
964
965 spin_lock_irqsave(&sclp_lock, flags);
966 sclp_suspend_state = sclp_suspend_state_suspended;
967 spin_unlock_irqrestore(&sclp_lock, flags);
968
969 /* Init supend data */
970 memset(&sclp_suspend_req, 0, sizeof(sclp_suspend_req));
971 sclp_suspend_req.callback = sclp_suspend_req_cb;
972 sclp_suspend_req.status = SCLP_REQ_FILLED;
973 init_completion(&sclp_request_queue_flushed);
974
975 rc = sclp_add_request(&sclp_suspend_req);
976 if (rc == 0)
977 wait_for_completion(&sclp_request_queue_flushed);
978 else if (rc != -ENODATA)
979 goto fail_thaw;
980
981 rc = sclp_deactivate();
982 if (rc)
983 goto fail_thaw;
984 return 0;
985
986fail_thaw:
987 spin_lock_irqsave(&sclp_lock, flags);
988 sclp_suspend_state = sclp_suspend_state_running;
989 spin_unlock_irqrestore(&sclp_lock, flags);
990 sclp_pm_event(SCLP_PM_EVENT_THAW, 1);
991 return rc;
992}
993
994static int sclp_undo_suspend(enum sclp_pm_event event)
995{
996 unsigned long flags;
997 int rc;
998
999 rc = sclp_reactivate();
1000 if (rc)
1001 return rc;
1002
1003 spin_lock_irqsave(&sclp_lock, flags);
1004 sclp_suspend_state = sclp_suspend_state_running;
1005 spin_unlock_irqrestore(&sclp_lock, flags);
1006
1007 sclp_pm_event(event, 0);
1008 return 0;
1009}
1010
1011static int sclp_thaw(struct device *dev)
1012{
1013 return sclp_undo_suspend(SCLP_PM_EVENT_THAW);
1014}
1015
1016static int sclp_restore(struct device *dev)
1017{
1018 return sclp_undo_suspend(SCLP_PM_EVENT_RESTORE);
1019}
1020
Alexey Dobriyan47145212009-12-14 18:00:08 -08001021static const struct dev_pm_ops sclp_pm_ops = {
Michael Holzheu62b749422009-06-16 10:30:40 +02001022 .freeze = sclp_freeze,
1023 .thaw = sclp_thaw,
1024 .restore = sclp_restore,
1025};
1026
1027static struct platform_driver sclp_pdrv = {
1028 .driver = {
1029 .name = "sclp",
1030 .owner = THIS_MODULE,
1031 .pm = &sclp_pm_ops,
1032 },
1033};
1034
1035static struct platform_device *sclp_pdev;
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037/* Initialize SCLP driver. Return zero if driver is operational, non-zero
1038 * otherwise. */
1039static int
1040sclp_init(void)
1041{
1042 unsigned long flags;
Michael Holzheu62b749422009-06-16 10:30:40 +02001043 int rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 spin_lock_irqsave(&sclp_lock, flags);
1046 /* Check for previous or running initialization */
Michael Holzheu62b749422009-06-16 10:30:40 +02001047 if (sclp_init_state != sclp_init_state_uninitialized)
1048 goto fail_unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 sclp_init_state = sclp_init_state_initializing;
1050 /* Set up variables */
1051 INIT_LIST_HEAD(&sclp_req_queue);
1052 INIT_LIST_HEAD(&sclp_reg_list);
1053 list_add(&sclp_state_change_event.list, &sclp_reg_list);
1054 init_timer(&sclp_request_timer);
1055 /* Check interface */
1056 spin_unlock_irqrestore(&sclp_lock, flags);
1057 rc = sclp_check_interface();
1058 spin_lock_irqsave(&sclp_lock, flags);
Michael Holzheu62b749422009-06-16 10:30:40 +02001059 if (rc)
1060 goto fail_init_state_uninitialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 /* Register reboot handler */
1062 rc = register_reboot_notifier(&sclp_reboot_notifier);
Michael Holzheu62b749422009-06-16 10:30:40 +02001063 if (rc)
1064 goto fail_init_state_uninitialized;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 /* Register interrupt handler */
Heiko Carstens98b79982011-01-05 12:47:40 +01001066 rc = register_external_interrupt(0x2401, sclp_interrupt_handler);
Michael Holzheu62b749422009-06-16 10:30:40 +02001067 if (rc)
1068 goto fail_unregister_reboot_notifier;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 sclp_init_state = sclp_init_state_initialized;
1070 spin_unlock_irqrestore(&sclp_lock, flags);
1071 /* Enable service-signal external interruption - needs to happen with
1072 * IRQs enabled. */
1073 ctl_set_bit(0, 9);
1074 sclp_init_mask(1);
1075 return 0;
Michael Holzheu62b749422009-06-16 10:30:40 +02001076
1077fail_unregister_reboot_notifier:
1078 unregister_reboot_notifier(&sclp_reboot_notifier);
1079fail_init_state_uninitialized:
1080 sclp_init_state = sclp_init_state_uninitialized;
1081fail_unlock:
1082 spin_unlock_irqrestore(&sclp_lock, flags);
1083 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
Peter Oberparleiterb3d00c32007-04-27 16:01:51 +02001085
Michael Holzheu62b749422009-06-16 10:30:40 +02001086/*
1087 * SCLP panic notifier: If we are suspended, we thaw SCLP in order to be able
1088 * to print the panic message.
1089 */
1090static int sclp_panic_notify(struct notifier_block *self,
1091 unsigned long event, void *data)
1092{
1093 if (sclp_suspend_state == sclp_suspend_state_suspended)
1094 sclp_undo_suspend(SCLP_PM_EVENT_THAW);
1095 return NOTIFY_OK;
1096}
1097
1098static struct notifier_block sclp_on_panic_nb = {
1099 .notifier_call = sclp_panic_notify,
1100 .priority = SCLP_PANIC_PRIO,
1101};
1102
Peter Oberparleiterb3d00c32007-04-27 16:01:51 +02001103static __init int sclp_initcall(void)
1104{
Michael Holzheu62b749422009-06-16 10:30:40 +02001105 int rc;
1106
1107 rc = platform_driver_register(&sclp_pdrv);
1108 if (rc)
1109 return rc;
1110 sclp_pdev = platform_device_register_simple("sclp", -1, NULL, 0);
1111 rc = IS_ERR(sclp_pdev) ? PTR_ERR(sclp_pdev) : 0;
1112 if (rc)
1113 goto fail_platform_driver_unregister;
1114 rc = atomic_notifier_chain_register(&panic_notifier_list,
1115 &sclp_on_panic_nb);
1116 if (rc)
1117 goto fail_platform_device_unregister;
1118
Peter Oberparleiterb3d00c32007-04-27 16:01:51 +02001119 return sclp_init();
Michael Holzheu62b749422009-06-16 10:30:40 +02001120
1121fail_platform_device_unregister:
1122 platform_device_unregister(sclp_pdev);
1123fail_platform_driver_unregister:
1124 platform_driver_unregister(&sclp_pdrv);
1125 return rc;
Peter Oberparleiterb3d00c32007-04-27 16:01:51 +02001126}
1127
1128arch_initcall(sclp_initcall);