Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 2 | * core function to access sclp interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 1999, 2009 |
| 5 | * |
| 6 | * Author(s): Martin Peschke <mpeschke@de.ibm.com> |
| 7 | * Martin Schwidefsky <schwidefsky@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Heiko Carstens | 052ff46 | 2011-01-05 12:47:28 +0100 | [diff] [blame] | 10 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/err.h> |
| 13 | #include <linux/spinlock.h> |
| 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/timer.h> |
| 16 | #include <linux/reboot.h> |
| 17 | #include <linux/jiffies.h> |
Peter Oberparleiter | b3d00c3 | 2007-04-27 16:01:51 +0200 | [diff] [blame] | 18 | #include <linux/init.h> |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 19 | #include <linux/suspend.h> |
| 20 | #include <linux/completion.h> |
| 21 | #include <linux/platform_device.h> |
Heiko Carstens | 052ff46 | 2011-01-05 12:47:28 +0100 | [diff] [blame] | 22 | #include <asm/types.h> |
| 23 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #include "sclp.h" |
| 26 | |
| 27 | #define SCLP_HEADER "sclp: " |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | /* Lock to protect internal data consistency. */ |
| 30 | static DEFINE_SPINLOCK(sclp_lock); |
| 31 | |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 32 | /* Mask of events that we can send to the sclp interface. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static sccb_mask_t sclp_receive_mask; |
| 34 | |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 35 | /* Mask of events that we can receive from the sclp interface. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static sccb_mask_t sclp_send_mask; |
| 37 | |
| 38 | /* List of registered event listeners and senders. */ |
| 39 | static struct list_head sclp_reg_list; |
| 40 | |
| 41 | /* List of queued requests. */ |
| 42 | static struct list_head sclp_req_queue; |
| 43 | |
| 44 | /* Data for read and and init requests. */ |
| 45 | static struct sclp_req sclp_read_req; |
| 46 | static struct sclp_req sclp_init_req; |
| 47 | static char sclp_read_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); |
| 48 | static char sclp_init_sccb[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE))); |
| 49 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 50 | /* Suspend request */ |
| 51 | static DECLARE_COMPLETION(sclp_request_queue_flushed); |
| 52 | |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 53 | /* Number of console pages to allocate, used by sclp_con.c and sclp_vt220.c */ |
| 54 | int sclp_console_pages = SCLP_CONSOLE_PAGES; |
| 55 | /* Flag to indicate if buffer pages are dropped on buffer full condition */ |
Peter Oberparleiter | 00fd2cb | 2015-07-02 09:06:55 +0200 | [diff] [blame] | 56 | int sclp_console_drop = 1; |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 57 | /* Number of times the console dropped buffer pages */ |
| 58 | unsigned long sclp_console_full; |
| 59 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 60 | static void sclp_suspend_req_cb(struct sclp_req *req, void *data) |
| 61 | { |
| 62 | complete(&sclp_request_queue_flushed); |
| 63 | } |
| 64 | |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 65 | static int __init sclp_setup_console_pages(char *str) |
| 66 | { |
| 67 | int pages, rc; |
| 68 | |
| 69 | rc = kstrtoint(str, 0, &pages); |
| 70 | if (!rc && pages >= SCLP_CONSOLE_PAGES) |
| 71 | sclp_console_pages = pages; |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | __setup("sclp_con_pages=", sclp_setup_console_pages); |
| 76 | |
| 77 | static int __init sclp_setup_console_drop(char *str) |
| 78 | { |
| 79 | int drop, rc; |
| 80 | |
| 81 | rc = kstrtoint(str, 0, &drop); |
Peter Oberparleiter | 00fd2cb | 2015-07-02 09:06:55 +0200 | [diff] [blame] | 82 | if (!rc) |
| 83 | sclp_console_drop = drop; |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | __setup("sclp_con_drop=", sclp_setup_console_drop); |
| 88 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 89 | static struct sclp_req sclp_suspend_req; |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Timer for request retries. */ |
| 92 | static struct timer_list sclp_request_timer; |
| 93 | |
Gerald Schaefer | 9f0128f | 2014-03-31 16:18:29 +0200 | [diff] [blame] | 94 | /* Timer for queued requests. */ |
| 95 | static struct timer_list sclp_queue_timer; |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* Internal state: is a request active at the sclp? */ |
| 98 | static volatile enum sclp_running_state_t { |
| 99 | sclp_running_state_idle, |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 100 | sclp_running_state_running, |
| 101 | sclp_running_state_reset_pending |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } sclp_running_state = sclp_running_state_idle; |
| 103 | |
| 104 | /* Internal state: is a read request pending? */ |
| 105 | static volatile enum sclp_reading_state_t { |
| 106 | sclp_reading_state_idle, |
| 107 | sclp_reading_state_reading |
| 108 | } sclp_reading_state = sclp_reading_state_idle; |
| 109 | |
| 110 | /* Internal state: is the driver currently serving requests? */ |
| 111 | static volatile enum sclp_activation_state_t { |
| 112 | sclp_activation_state_active, |
| 113 | sclp_activation_state_deactivating, |
| 114 | sclp_activation_state_inactive, |
| 115 | sclp_activation_state_activating |
| 116 | } sclp_activation_state = sclp_activation_state_active; |
| 117 | |
| 118 | /* Internal state: is an init mask request pending? */ |
| 119 | static volatile enum sclp_mask_state_t { |
| 120 | sclp_mask_state_idle, |
| 121 | sclp_mask_state_initializing |
| 122 | } sclp_mask_state = sclp_mask_state_idle; |
| 123 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 124 | /* Internal state: is the driver suspended? */ |
| 125 | static enum sclp_suspend_state_t { |
| 126 | sclp_suspend_state_running, |
| 127 | sclp_suspend_state_suspended, |
| 128 | } sclp_suspend_state = sclp_suspend_state_running; |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | /* Maximum retry counts */ |
| 131 | #define SCLP_INIT_RETRY 3 |
| 132 | #define SCLP_MASK_RETRY 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* Timeout intervals in seconds.*/ |
Peter Oberparleiter | 25fab9e | 2006-02-11 17:55:59 -0800 | [diff] [blame] | 135 | #define SCLP_BUSY_INTERVAL 10 |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 136 | #define SCLP_RETRY_INTERVAL 30 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | static void sclp_process_queue(void); |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 139 | static void __sclp_make_read_req(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | static int sclp_init_mask(int calculate); |
| 141 | static int sclp_init(void); |
| 142 | |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 143 | static void |
| 144 | __sclp_queue_read_req(void) |
| 145 | { |
| 146 | if (sclp_reading_state == sclp_reading_state_idle) { |
| 147 | sclp_reading_state = sclp_reading_state_reading; |
| 148 | __sclp_make_read_req(); |
| 149 | /* Add request to head of queue */ |
| 150 | list_add(&sclp_read_req.list, &sclp_req_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /* Set up request retry timer. Called while sclp_lock is locked. */ |
| 155 | static inline void |
| 156 | __sclp_set_request_timer(unsigned long time, void (*function)(unsigned long), |
| 157 | unsigned long data) |
| 158 | { |
| 159 | del_timer(&sclp_request_timer); |
| 160 | sclp_request_timer.function = function; |
| 161 | sclp_request_timer.data = data; |
| 162 | sclp_request_timer.expires = jiffies + time; |
| 163 | add_timer(&sclp_request_timer); |
| 164 | } |
| 165 | |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 166 | /* Request timeout handler. Restart the request queue. If DATA is non-zero, |
| 167 | * force restart of running request. */ |
| 168 | static void |
| 169 | sclp_request_timeout(unsigned long data) |
| 170 | { |
| 171 | unsigned long flags; |
| 172 | |
| 173 | spin_lock_irqsave(&sclp_lock, flags); |
| 174 | if (data) { |
| 175 | if (sclp_running_state == sclp_running_state_running) { |
| 176 | /* Break running state and queue NOP read event request |
| 177 | * to get a defined interface state. */ |
| 178 | __sclp_queue_read_req(); |
| 179 | sclp_running_state = sclp_running_state_idle; |
| 180 | } |
| 181 | } else { |
| 182 | __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ, |
| 183 | sclp_request_timeout, 0); |
| 184 | } |
| 185 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 186 | sclp_process_queue(); |
| 187 | } |
| 188 | |
Gerald Schaefer | 9f0128f | 2014-03-31 16:18:29 +0200 | [diff] [blame] | 189 | /* |
| 190 | * Returns the expire value in jiffies of the next pending request timeout, |
| 191 | * if any. Needs to be called with sclp_lock. |
| 192 | */ |
| 193 | static unsigned long __sclp_req_queue_find_next_timeout(void) |
| 194 | { |
| 195 | unsigned long expires_next = 0; |
| 196 | struct sclp_req *req; |
| 197 | |
| 198 | list_for_each_entry(req, &sclp_req_queue, list) { |
| 199 | if (!req->queue_expires) |
| 200 | continue; |
| 201 | if (!expires_next || |
| 202 | (time_before(req->queue_expires, expires_next))) |
| 203 | expires_next = req->queue_expires; |
| 204 | } |
| 205 | return expires_next; |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * Returns expired request, if any, and removes it from the list. |
| 210 | */ |
| 211 | static struct sclp_req *__sclp_req_queue_remove_expired_req(void) |
| 212 | { |
| 213 | unsigned long flags, now; |
| 214 | struct sclp_req *req; |
| 215 | |
| 216 | spin_lock_irqsave(&sclp_lock, flags); |
| 217 | now = jiffies; |
| 218 | /* Don't need list_for_each_safe because we break out after list_del */ |
| 219 | list_for_each_entry(req, &sclp_req_queue, list) { |
| 220 | if (!req->queue_expires) |
| 221 | continue; |
| 222 | if (time_before_eq(req->queue_expires, now)) { |
| 223 | if (req->status == SCLP_REQ_QUEUED) { |
| 224 | req->status = SCLP_REQ_QUEUED_TIMEOUT; |
| 225 | list_del(&req->list); |
| 226 | goto out; |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | req = NULL; |
| 231 | out: |
| 232 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 233 | return req; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Timeout handler for queued requests. Removes request from list and |
| 238 | * invokes callback. This timer can be set per request in situations where |
| 239 | * waiting too long would be harmful to the system, e.g. during SE reboot. |
| 240 | */ |
| 241 | static void sclp_req_queue_timeout(unsigned long data) |
| 242 | { |
| 243 | unsigned long flags, expires_next; |
| 244 | struct sclp_req *req; |
| 245 | |
| 246 | do { |
| 247 | req = __sclp_req_queue_remove_expired_req(); |
| 248 | if (req && req->callback) |
| 249 | req->callback(req, req->callback_data); |
| 250 | } while (req); |
| 251 | |
| 252 | spin_lock_irqsave(&sclp_lock, flags); |
| 253 | expires_next = __sclp_req_queue_find_next_timeout(); |
| 254 | if (expires_next) |
| 255 | mod_timer(&sclp_queue_timer, expires_next); |
| 256 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 257 | } |
| 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | /* Try to start a request. Return zero if the request was successfully |
| 260 | * started or if it will be started at a later time. Return non-zero otherwise. |
| 261 | * Called while sclp_lock is locked. */ |
| 262 | static int |
| 263 | __sclp_start_request(struct sclp_req *req) |
| 264 | { |
| 265 | int rc; |
| 266 | |
| 267 | if (sclp_running_state != sclp_running_state_idle) |
| 268 | return 0; |
| 269 | del_timer(&sclp_request_timer); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 270 | rc = sclp_service_call(req->command, req->sccb); |
Peter Oberparleiter | 25fab9e | 2006-02-11 17:55:59 -0800 | [diff] [blame] | 271 | req->start_count++; |
| 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (rc == 0) { |
Daniel Mack | 3ad2f3fb | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 274 | /* Successfully started request */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | req->status = SCLP_REQ_RUNNING; |
| 276 | sclp_running_state = sclp_running_state_running; |
| 277 | __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ, |
| 278 | sclp_request_timeout, 1); |
| 279 | return 0; |
| 280 | } else if (rc == -EBUSY) { |
| 281 | /* Try again later */ |
| 282 | __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ, |
| 283 | sclp_request_timeout, 0); |
| 284 | return 0; |
| 285 | } |
| 286 | /* Request failed */ |
| 287 | req->status = SCLP_REQ_FAILED; |
| 288 | return rc; |
| 289 | } |
| 290 | |
| 291 | /* Try to start queued requests. */ |
| 292 | static void |
| 293 | sclp_process_queue(void) |
| 294 | { |
| 295 | struct sclp_req *req; |
| 296 | int rc; |
| 297 | unsigned long flags; |
| 298 | |
| 299 | spin_lock_irqsave(&sclp_lock, flags); |
| 300 | if (sclp_running_state != sclp_running_state_idle) { |
| 301 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 302 | return; |
| 303 | } |
| 304 | del_timer(&sclp_request_timer); |
| 305 | while (!list_empty(&sclp_req_queue)) { |
| 306 | req = list_entry(sclp_req_queue.next, struct sclp_req, list); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 307 | if (!req->sccb) |
| 308 | goto do_post; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | rc = __sclp_start_request(req); |
| 310 | if (rc == 0) |
| 311 | break; |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 312 | /* Request failed */ |
| 313 | if (req->start_count > 1) { |
| 314 | /* Cannot abort already submitted request - could still |
| 315 | * be active at the SCLP */ |
| 316 | __sclp_set_request_timer(SCLP_BUSY_INTERVAL * HZ, |
| 317 | sclp_request_timeout, 0); |
| 318 | break; |
| 319 | } |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 320 | do_post: |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 321 | /* Post-processing for aborted request */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | list_del(&req->list); |
| 323 | if (req->callback) { |
| 324 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 325 | req->callback(req, req->callback_data); |
| 326 | spin_lock_irqsave(&sclp_lock, flags); |
| 327 | } |
| 328 | } |
| 329 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 330 | } |
| 331 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 332 | static int __sclp_can_add_request(struct sclp_req *req) |
| 333 | { |
| 334 | if (req == &sclp_suspend_req || req == &sclp_init_req) |
| 335 | return 1; |
| 336 | if (sclp_suspend_state != sclp_suspend_state_running) |
| 337 | return 0; |
| 338 | if (sclp_init_state != sclp_init_state_initialized) |
| 339 | return 0; |
| 340 | if (sclp_activation_state != sclp_activation_state_active) |
| 341 | return 0; |
| 342 | return 1; |
| 343 | } |
| 344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | /* Queue a new request. Return zero on success, non-zero otherwise. */ |
| 346 | int |
| 347 | sclp_add_request(struct sclp_req *req) |
| 348 | { |
| 349 | unsigned long flags; |
| 350 | int rc; |
| 351 | |
| 352 | spin_lock_irqsave(&sclp_lock, flags); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 353 | if (!__sclp_can_add_request(req)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 355 | return -EIO; |
| 356 | } |
| 357 | req->status = SCLP_REQ_QUEUED; |
| 358 | req->start_count = 0; |
| 359 | list_add_tail(&req->list, &sclp_req_queue); |
| 360 | rc = 0; |
Gerald Schaefer | 9f0128f | 2014-03-31 16:18:29 +0200 | [diff] [blame] | 361 | if (req->queue_timeout) { |
| 362 | req->queue_expires = jiffies + req->queue_timeout * HZ; |
| 363 | if (!timer_pending(&sclp_queue_timer) || |
| 364 | time_after(sclp_queue_timer.expires, req->queue_expires)) |
| 365 | mod_timer(&sclp_queue_timer, req->queue_expires); |
| 366 | } else |
| 367 | req->queue_expires = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* Start if request is first in list */ |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 369 | if (sclp_running_state == sclp_running_state_idle && |
| 370 | req->list.prev == &sclp_req_queue) { |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 371 | if (!req->sccb) { |
| 372 | list_del(&req->list); |
| 373 | rc = -ENODATA; |
| 374 | goto out; |
| 375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | rc = __sclp_start_request(req); |
| 377 | if (rc) |
| 378 | list_del(&req->list); |
| 379 | } |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 380 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 382 | return rc; |
| 383 | } |
| 384 | |
| 385 | EXPORT_SYMBOL(sclp_add_request); |
| 386 | |
| 387 | /* Dispatch events found in request buffer to registered listeners. Return 0 |
| 388 | * if all events were dispatched, non-zero otherwise. */ |
| 389 | static int |
| 390 | sclp_dispatch_evbufs(struct sccb_header *sccb) |
| 391 | { |
| 392 | unsigned long flags; |
| 393 | struct evbuf_header *evbuf; |
| 394 | struct list_head *l; |
| 395 | struct sclp_register *reg; |
| 396 | int offset; |
| 397 | int rc; |
| 398 | |
| 399 | spin_lock_irqsave(&sclp_lock, flags); |
| 400 | rc = 0; |
| 401 | for (offset = sizeof(struct sccb_header); offset < sccb->length; |
| 402 | offset += evbuf->length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | evbuf = (struct evbuf_header *) ((addr_t) sccb + offset); |
Peter Oberparleiter | e2e5a0f | 2009-02-19 15:18:59 +0100 | [diff] [blame] | 404 | /* Check for malformed hardware response */ |
| 405 | if (evbuf->length == 0) |
| 406 | break; |
| 407 | /* Search for event handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | reg = NULL; |
| 409 | list_for_each(l, &sclp_reg_list) { |
| 410 | reg = list_entry(l, struct sclp_register, list); |
| 411 | if (reg->receive_mask & (1 << (32 - evbuf->type))) |
| 412 | break; |
| 413 | else |
| 414 | reg = NULL; |
| 415 | } |
| 416 | if (reg && reg->receiver_fn) { |
| 417 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 418 | reg->receiver_fn(evbuf); |
| 419 | spin_lock_irqsave(&sclp_lock, flags); |
| 420 | } else if (reg == NULL) |
Heiko Carstens | d06cbda | 2012-09-06 15:00:07 +0200 | [diff] [blame] | 421 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 424 | return rc; |
| 425 | } |
| 426 | |
| 427 | /* Read event data request callback. */ |
| 428 | static void |
| 429 | sclp_read_cb(struct sclp_req *req, void *data) |
| 430 | { |
| 431 | unsigned long flags; |
| 432 | struct sccb_header *sccb; |
| 433 | |
| 434 | sccb = (struct sccb_header *) req->sccb; |
| 435 | if (req->status == SCLP_REQ_DONE && (sccb->response_code == 0x20 || |
| 436 | sccb->response_code == 0x220)) |
| 437 | sclp_dispatch_evbufs(sccb); |
| 438 | spin_lock_irqsave(&sclp_lock, flags); |
| 439 | sclp_reading_state = sclp_reading_state_idle; |
| 440 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 441 | } |
| 442 | |
| 443 | /* Prepare read event data request. Called while sclp_lock is locked. */ |
Heiko Carstens | 364c855 | 2007-10-12 16:11:35 +0200 | [diff] [blame] | 444 | static void __sclp_make_read_req(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
| 446 | struct sccb_header *sccb; |
| 447 | |
| 448 | sccb = (struct sccb_header *) sclp_read_sccb; |
| 449 | clear_page(sccb); |
| 450 | memset(&sclp_read_req, 0, sizeof(struct sclp_req)); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 451 | sclp_read_req.command = SCLP_CMDW_READ_EVENT_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | sclp_read_req.status = SCLP_REQ_QUEUED; |
| 453 | sclp_read_req.start_count = 0; |
| 454 | sclp_read_req.callback = sclp_read_cb; |
| 455 | sclp_read_req.sccb = sccb; |
| 456 | sccb->length = PAGE_SIZE; |
| 457 | sccb->function_code = 0; |
| 458 | sccb->control_mask[2] = 0x80; |
| 459 | } |
| 460 | |
| 461 | /* Search request list for request with matching sccb. Return request if found, |
| 462 | * NULL otherwise. Called while sclp_lock is locked. */ |
| 463 | static inline struct sclp_req * |
| 464 | __sclp_find_req(u32 sccb) |
| 465 | { |
| 466 | struct list_head *l; |
| 467 | struct sclp_req *req; |
| 468 | |
| 469 | list_for_each(l, &sclp_req_queue) { |
| 470 | req = list_entry(l, struct sclp_req, list); |
| 471 | if (sccb == (u32) (addr_t) req->sccb) |
| 472 | return req; |
| 473 | } |
| 474 | return NULL; |
| 475 | } |
| 476 | |
| 477 | /* Handler for external interruption. Perform request post-processing. |
| 478 | * Prepare read event data request if necessary. Start processing of next |
| 479 | * request on queue. */ |
Heiko Carstens | fde15c3 | 2012-03-11 11:59:31 -0400 | [diff] [blame] | 480 | static void sclp_interrupt_handler(struct ext_code ext_code, |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 481 | unsigned int param32, unsigned long param64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
| 483 | struct sclp_req *req; |
| 484 | u32 finished_sccb; |
| 485 | u32 evbuf_pending; |
| 486 | |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 487 | inc_irq_stat(IRQEXT_SCP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | spin_lock(&sclp_lock); |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 489 | finished_sccb = param32 & 0xfffffff8; |
| 490 | evbuf_pending = param32 & 0x3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | if (finished_sccb) { |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 492 | del_timer(&sclp_request_timer); |
| 493 | sclp_running_state = sclp_running_state_reset_pending; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | req = __sclp_find_req(finished_sccb); |
| 495 | if (req) { |
| 496 | /* Request post-processing */ |
| 497 | list_del(&req->list); |
| 498 | req->status = SCLP_REQ_DONE; |
| 499 | if (req->callback) { |
| 500 | spin_unlock(&sclp_lock); |
| 501 | req->callback(req, req->callback_data); |
| 502 | spin_lock(&sclp_lock); |
| 503 | } |
| 504 | } |
| 505 | sclp_running_state = sclp_running_state_idle; |
| 506 | } |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 507 | if (evbuf_pending && |
Peter Oberparleiter | dbd8ae6 | 2007-02-05 21:17:00 +0100 | [diff] [blame] | 508 | sclp_activation_state == sclp_activation_state_active) |
| 509 | __sclp_queue_read_req(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | spin_unlock(&sclp_lock); |
| 511 | sclp_process_queue(); |
| 512 | } |
| 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | /* Convert interval in jiffies to TOD ticks. */ |
| 515 | static inline u64 |
| 516 | sclp_tod_from_jiffies(unsigned long jiffies) |
| 517 | { |
| 518 | return (u64) (jiffies / HZ) << 32; |
| 519 | } |
| 520 | |
| 521 | /* Wait until a currently running request finished. Note: while this function |
| 522 | * is running, no timers are served on the calling CPU. */ |
| 523 | void |
| 524 | sclp_sync_wait(void) |
| 525 | { |
Heiko Carstens | 934b285 | 2008-08-01 16:39:11 +0200 | [diff] [blame] | 526 | unsigned long long old_tick; |
Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 527 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | unsigned long cr0, cr0_sync; |
| 529 | u64 timeout; |
Heiko Carstens | c59d744 | 2007-02-05 21:17:16 +0100 | [diff] [blame] | 530 | int irq_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | /* We'll be disabling timer interrupts, so we need a custom timeout |
| 533 | * mechanism */ |
| 534 | timeout = 0; |
| 535 | if (timer_pending(&sclp_request_timer)) { |
| 536 | /* Get timeout TOD value */ |
Martin Schwidefsky | 8c071b0 | 2013-10-17 12:38:17 +0200 | [diff] [blame] | 537 | timeout = get_tod_clock_fast() + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | sclp_tod_from_jiffies(sclp_request_timer.expires - |
| 539 | jiffies); |
| 540 | } |
Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 541 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* Prevent bottom half from executing once we force interrupts open */ |
Heiko Carstens | c59d744 | 2007-02-05 21:17:16 +0100 | [diff] [blame] | 543 | irq_context = in_interrupt(); |
| 544 | if (!irq_context) |
| 545 | local_bh_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | /* Enable service-signal interruption, disable timer interrupts */ |
Heiko Carstens | 934b285 | 2008-08-01 16:39:11 +0200 | [diff] [blame] | 547 | old_tick = local_tick_disable(); |
Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 548 | trace_hardirqs_on(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | __ctl_store(cr0, 0, 0); |
Heiko Carstens | c2ab728 | 2016-01-07 13:37:22 +0100 | [diff] [blame] | 550 | cr0_sync = cr0 & ~CR0_IRQ_SUBCLASS_MASK; |
| 551 | cr0_sync |= 1UL << (63 - 54); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | __ctl_load(cr0_sync, 0, 0); |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 553 | __arch_local_irq_stosm(0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | /* Loop until driver state indicates finished request */ |
| 555 | while (sclp_running_state != sclp_running_state_idle) { |
| 556 | /* Check for expired request timer */ |
| 557 | if (timer_pending(&sclp_request_timer) && |
Martin Schwidefsky | 8c071b0 | 2013-10-17 12:38:17 +0200 | [diff] [blame] | 558 | get_tod_clock_fast() > timeout && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | del_timer(&sclp_request_timer)) |
| 560 | sclp_request_timer.function(sclp_request_timer.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | cpu_relax(); |
| 562 | } |
Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 563 | local_irq_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | __ctl_load(cr0, 0, 0); |
Heiko Carstens | c59d744 | 2007-02-05 21:17:16 +0100 | [diff] [blame] | 565 | if (!irq_context) |
| 566 | _local_bh_enable(); |
Heiko Carstens | 934b285 | 2008-08-01 16:39:11 +0200 | [diff] [blame] | 567 | local_tick_enable(old_tick); |
Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 568 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | EXPORT_SYMBOL(sclp_sync_wait); |
| 571 | |
| 572 | /* Dispatch changes in send and receive mask to registered listeners. */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 573 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | sclp_dispatch_state_change(void) |
| 575 | { |
| 576 | struct list_head *l; |
| 577 | struct sclp_register *reg; |
| 578 | unsigned long flags; |
| 579 | sccb_mask_t receive_mask; |
| 580 | sccb_mask_t send_mask; |
| 581 | |
| 582 | do { |
| 583 | spin_lock_irqsave(&sclp_lock, flags); |
| 584 | reg = NULL; |
| 585 | list_for_each(l, &sclp_reg_list) { |
| 586 | reg = list_entry(l, struct sclp_register, list); |
Peter Oberparleiter | d082d3c | 2008-02-19 15:29:32 +0100 | [diff] [blame] | 587 | receive_mask = reg->send_mask & sclp_receive_mask; |
| 588 | send_mask = reg->receive_mask & sclp_send_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (reg->sclp_receive_mask != receive_mask || |
| 590 | reg->sclp_send_mask != send_mask) { |
| 591 | reg->sclp_receive_mask = receive_mask; |
| 592 | reg->sclp_send_mask = send_mask; |
| 593 | break; |
| 594 | } else |
| 595 | reg = NULL; |
| 596 | } |
| 597 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 598 | if (reg && reg->state_change_fn) |
| 599 | reg->state_change_fn(reg); |
| 600 | } while (reg); |
| 601 | } |
| 602 | |
| 603 | struct sclp_statechangebuf { |
| 604 | struct evbuf_header header; |
| 605 | u8 validity_sclp_active_facility_mask : 1; |
| 606 | u8 validity_sclp_receive_mask : 1; |
| 607 | u8 validity_sclp_send_mask : 1; |
| 608 | u8 validity_read_data_function_mask : 1; |
| 609 | u16 _zeros : 12; |
| 610 | u16 mask_length; |
| 611 | u64 sclp_active_facility_mask; |
| 612 | sccb_mask_t sclp_receive_mask; |
| 613 | sccb_mask_t sclp_send_mask; |
| 614 | u32 read_data_function_mask; |
| 615 | } __attribute__((packed)); |
| 616 | |
| 617 | |
| 618 | /* State change event callback. Inform listeners of changes. */ |
| 619 | static void |
| 620 | sclp_state_change_cb(struct evbuf_header *evbuf) |
| 621 | { |
| 622 | unsigned long flags; |
| 623 | struct sclp_statechangebuf *scbuf; |
| 624 | |
| 625 | scbuf = (struct sclp_statechangebuf *) evbuf; |
| 626 | if (scbuf->mask_length != sizeof(sccb_mask_t)) |
| 627 | return; |
| 628 | spin_lock_irqsave(&sclp_lock, flags); |
| 629 | if (scbuf->validity_sclp_receive_mask) |
| 630 | sclp_receive_mask = scbuf->sclp_receive_mask; |
| 631 | if (scbuf->validity_sclp_send_mask) |
| 632 | sclp_send_mask = scbuf->sclp_send_mask; |
| 633 | spin_unlock_irqrestore(&sclp_lock, flags); |
Heiko Carstens | 887d935 | 2008-07-14 09:57:26 +0200 | [diff] [blame] | 634 | if (scbuf->validity_sclp_active_facility_mask) |
David Hildenbrand | 78335a3 | 2015-05-06 09:17:51 +0200 | [diff] [blame] | 635 | sclp.facilities = scbuf->sclp_active_facility_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | sclp_dispatch_state_change(); |
| 637 | } |
| 638 | |
| 639 | static struct sclp_register sclp_state_change_event = { |
Stefan Haberland | 6d4740c | 2007-04-27 16:01:53 +0200 | [diff] [blame] | 640 | .receive_mask = EVTYP_STATECHANGE_MASK, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | .receiver_fn = sclp_state_change_cb |
| 642 | }; |
| 643 | |
| 644 | /* Calculate receive and send mask of currently registered listeners. |
| 645 | * Called while sclp_lock is locked. */ |
| 646 | static inline void |
| 647 | __sclp_get_mask(sccb_mask_t *receive_mask, sccb_mask_t *send_mask) |
| 648 | { |
| 649 | struct list_head *l; |
| 650 | struct sclp_register *t; |
| 651 | |
| 652 | *receive_mask = 0; |
| 653 | *send_mask = 0; |
| 654 | list_for_each(l, &sclp_reg_list) { |
| 655 | t = list_entry(l, struct sclp_register, list); |
| 656 | *receive_mask |= t->receive_mask; |
| 657 | *send_mask |= t->send_mask; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | /* Register event listener. Return 0 on success, non-zero otherwise. */ |
| 662 | int |
| 663 | sclp_register(struct sclp_register *reg) |
| 664 | { |
| 665 | unsigned long flags; |
| 666 | sccb_mask_t receive_mask; |
| 667 | sccb_mask_t send_mask; |
| 668 | int rc; |
| 669 | |
| 670 | rc = sclp_init(); |
| 671 | if (rc) |
| 672 | return rc; |
| 673 | spin_lock_irqsave(&sclp_lock, flags); |
| 674 | /* Check event mask for collisions */ |
| 675 | __sclp_get_mask(&receive_mask, &send_mask); |
| 676 | if (reg->receive_mask & receive_mask || reg->send_mask & send_mask) { |
| 677 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 678 | return -EBUSY; |
| 679 | } |
| 680 | /* Trigger initial state change callback */ |
| 681 | reg->sclp_receive_mask = 0; |
| 682 | reg->sclp_send_mask = 0; |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 683 | reg->pm_event_posted = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | list_add(®->list, &sclp_reg_list); |
| 685 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 686 | rc = sclp_init_mask(1); |
| 687 | if (rc) { |
| 688 | spin_lock_irqsave(&sclp_lock, flags); |
| 689 | list_del(®->list); |
| 690 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 691 | } |
| 692 | return rc; |
| 693 | } |
| 694 | |
| 695 | EXPORT_SYMBOL(sclp_register); |
| 696 | |
| 697 | /* Unregister event listener. */ |
| 698 | void |
| 699 | sclp_unregister(struct sclp_register *reg) |
| 700 | { |
| 701 | unsigned long flags; |
| 702 | |
| 703 | spin_lock_irqsave(&sclp_lock, flags); |
| 704 | list_del(®->list); |
| 705 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 706 | sclp_init_mask(1); |
| 707 | } |
| 708 | |
| 709 | EXPORT_SYMBOL(sclp_unregister); |
| 710 | |
| 711 | /* Remove event buffers which are marked processed. Return the number of |
| 712 | * remaining event buffers. */ |
| 713 | int |
| 714 | sclp_remove_processed(struct sccb_header *sccb) |
| 715 | { |
| 716 | struct evbuf_header *evbuf; |
| 717 | int unprocessed; |
| 718 | u16 remaining; |
| 719 | |
| 720 | evbuf = (struct evbuf_header *) (sccb + 1); |
| 721 | unprocessed = 0; |
| 722 | remaining = sccb->length - sizeof(struct sccb_header); |
| 723 | while (remaining > 0) { |
| 724 | remaining -= evbuf->length; |
| 725 | if (evbuf->flags & 0x80) { |
| 726 | sccb->length -= evbuf->length; |
| 727 | memcpy(evbuf, (void *) ((addr_t) evbuf + evbuf->length), |
| 728 | remaining); |
| 729 | } else { |
| 730 | unprocessed++; |
| 731 | evbuf = (struct evbuf_header *) |
| 732 | ((addr_t) evbuf + evbuf->length); |
| 733 | } |
| 734 | } |
| 735 | return unprocessed; |
| 736 | } |
| 737 | |
| 738 | EXPORT_SYMBOL(sclp_remove_processed); |
| 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | /* Prepare init mask request. Called while sclp_lock is locked. */ |
| 741 | static inline void |
| 742 | __sclp_make_init_req(u32 receive_mask, u32 send_mask) |
| 743 | { |
| 744 | struct init_sccb *sccb; |
| 745 | |
| 746 | sccb = (struct init_sccb *) sclp_init_sccb; |
| 747 | clear_page(sccb); |
| 748 | memset(&sclp_init_req, 0, sizeof(struct sclp_req)); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 749 | sclp_init_req.command = SCLP_CMDW_WRITE_EVENT_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | sclp_init_req.status = SCLP_REQ_FILLED; |
| 751 | sclp_init_req.start_count = 0; |
| 752 | sclp_init_req.callback = NULL; |
| 753 | sclp_init_req.callback_data = NULL; |
| 754 | sclp_init_req.sccb = sccb; |
| 755 | sccb->header.length = sizeof(struct init_sccb); |
| 756 | sccb->mask_length = sizeof(sccb_mask_t); |
| 757 | sccb->receive_mask = receive_mask; |
| 758 | sccb->send_mask = send_mask; |
| 759 | sccb->sclp_receive_mask = 0; |
| 760 | sccb->sclp_send_mask = 0; |
| 761 | } |
| 762 | |
| 763 | /* Start init mask request. If calculate is non-zero, calculate the mask as |
| 764 | * requested by registered listeners. Use zero mask otherwise. Return 0 on |
| 765 | * success, non-zero otherwise. */ |
| 766 | static int |
| 767 | sclp_init_mask(int calculate) |
| 768 | { |
| 769 | unsigned long flags; |
| 770 | struct init_sccb *sccb = (struct init_sccb *) sclp_init_sccb; |
| 771 | sccb_mask_t receive_mask; |
| 772 | sccb_mask_t send_mask; |
| 773 | int retry; |
| 774 | int rc; |
| 775 | unsigned long wait; |
| 776 | |
| 777 | spin_lock_irqsave(&sclp_lock, flags); |
| 778 | /* Check if interface is in appropriate state */ |
| 779 | if (sclp_mask_state != sclp_mask_state_idle) { |
| 780 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 781 | return -EBUSY; |
| 782 | } |
| 783 | if (sclp_activation_state == sclp_activation_state_inactive) { |
| 784 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 785 | return -EINVAL; |
| 786 | } |
| 787 | sclp_mask_state = sclp_mask_state_initializing; |
| 788 | /* Determine mask */ |
| 789 | if (calculate) |
| 790 | __sclp_get_mask(&receive_mask, &send_mask); |
| 791 | else { |
| 792 | receive_mask = 0; |
| 793 | send_mask = 0; |
| 794 | } |
| 795 | rc = -EIO; |
| 796 | for (retry = 0; retry <= SCLP_MASK_RETRY; retry++) { |
| 797 | /* Prepare request */ |
| 798 | __sclp_make_init_req(receive_mask, send_mask); |
| 799 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 800 | if (sclp_add_request(&sclp_init_req)) { |
| 801 | /* Try again later */ |
| 802 | wait = jiffies + SCLP_BUSY_INTERVAL * HZ; |
| 803 | while (time_before(jiffies, wait)) |
| 804 | sclp_sync_wait(); |
| 805 | spin_lock_irqsave(&sclp_lock, flags); |
| 806 | continue; |
| 807 | } |
| 808 | while (sclp_init_req.status != SCLP_REQ_DONE && |
| 809 | sclp_init_req.status != SCLP_REQ_FAILED) |
| 810 | sclp_sync_wait(); |
| 811 | spin_lock_irqsave(&sclp_lock, flags); |
| 812 | if (sclp_init_req.status == SCLP_REQ_DONE && |
| 813 | sccb->header.response_code == 0x20) { |
| 814 | /* Successful request */ |
| 815 | if (calculate) { |
| 816 | sclp_receive_mask = sccb->sclp_receive_mask; |
| 817 | sclp_send_mask = sccb->sclp_send_mask; |
| 818 | } else { |
| 819 | sclp_receive_mask = 0; |
| 820 | sclp_send_mask = 0; |
| 821 | } |
| 822 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 823 | sclp_dispatch_state_change(); |
| 824 | spin_lock_irqsave(&sclp_lock, flags); |
| 825 | rc = 0; |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | sclp_mask_state = sclp_mask_state_idle; |
| 830 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 831 | return rc; |
| 832 | } |
| 833 | |
| 834 | /* Deactivate SCLP interface. On success, new requests will be rejected, |
| 835 | * events will no longer be dispatched. Return 0 on success, non-zero |
| 836 | * otherwise. */ |
| 837 | int |
| 838 | sclp_deactivate(void) |
| 839 | { |
| 840 | unsigned long flags; |
| 841 | int rc; |
| 842 | |
| 843 | spin_lock_irqsave(&sclp_lock, flags); |
| 844 | /* Deactivate can only be called when active */ |
| 845 | if (sclp_activation_state != sclp_activation_state_active) { |
| 846 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 847 | return -EINVAL; |
| 848 | } |
| 849 | sclp_activation_state = sclp_activation_state_deactivating; |
| 850 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 851 | rc = sclp_init_mask(0); |
| 852 | spin_lock_irqsave(&sclp_lock, flags); |
| 853 | if (rc == 0) |
| 854 | sclp_activation_state = sclp_activation_state_inactive; |
| 855 | else |
| 856 | sclp_activation_state = sclp_activation_state_active; |
| 857 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 858 | return rc; |
| 859 | } |
| 860 | |
| 861 | EXPORT_SYMBOL(sclp_deactivate); |
| 862 | |
| 863 | /* Reactivate SCLP interface after sclp_deactivate. On success, new |
| 864 | * requests will be accepted, events will be dispatched again. Return 0 on |
| 865 | * success, non-zero otherwise. */ |
| 866 | int |
| 867 | sclp_reactivate(void) |
| 868 | { |
| 869 | unsigned long flags; |
| 870 | int rc; |
| 871 | |
| 872 | spin_lock_irqsave(&sclp_lock, flags); |
| 873 | /* Reactivate can only be called when inactive */ |
| 874 | if (sclp_activation_state != sclp_activation_state_inactive) { |
| 875 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 876 | return -EINVAL; |
| 877 | } |
| 878 | sclp_activation_state = sclp_activation_state_activating; |
| 879 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 880 | rc = sclp_init_mask(1); |
| 881 | spin_lock_irqsave(&sclp_lock, flags); |
| 882 | if (rc == 0) |
| 883 | sclp_activation_state = sclp_activation_state_active; |
| 884 | else |
| 885 | sclp_activation_state = sclp_activation_state_inactive; |
| 886 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 887 | return rc; |
| 888 | } |
| 889 | |
| 890 | EXPORT_SYMBOL(sclp_reactivate); |
| 891 | |
| 892 | /* Handler for external interruption used during initialization. Modify |
| 893 | * request state to done. */ |
Heiko Carstens | fde15c3 | 2012-03-11 11:59:31 -0400 | [diff] [blame] | 894 | static void sclp_check_handler(struct ext_code ext_code, |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 895 | unsigned int param32, unsigned long param64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
| 897 | u32 finished_sccb; |
| 898 | |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 899 | inc_irq_stat(IRQEXT_SCP); |
Martin Schwidefsky | f6649a7 | 2010-10-25 16:10:38 +0200 | [diff] [blame] | 900 | finished_sccb = param32 & 0xfffffff8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | /* Is this the interrupt we are waiting for? */ |
| 902 | if (finished_sccb == 0) |
| 903 | return; |
Martin Schwidefsky | a12c53f | 2008-07-14 09:59:28 +0200 | [diff] [blame] | 904 | if (finished_sccb != (u32) (addr_t) sclp_init_sccb) |
| 905 | panic("sclp: unsolicited interrupt for buffer at 0x%x\n", |
| 906 | finished_sccb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | spin_lock(&sclp_lock); |
| 908 | if (sclp_running_state == sclp_running_state_running) { |
| 909 | sclp_init_req.status = SCLP_REQ_DONE; |
| 910 | sclp_running_state = sclp_running_state_idle; |
| 911 | } |
| 912 | spin_unlock(&sclp_lock); |
| 913 | } |
| 914 | |
| 915 | /* Initial init mask request timed out. Modify request state to failed. */ |
| 916 | static void |
| 917 | sclp_check_timeout(unsigned long data) |
| 918 | { |
| 919 | unsigned long flags; |
| 920 | |
| 921 | spin_lock_irqsave(&sclp_lock, flags); |
| 922 | if (sclp_running_state == sclp_running_state_running) { |
| 923 | sclp_init_req.status = SCLP_REQ_FAILED; |
| 924 | sclp_running_state = sclp_running_state_idle; |
| 925 | } |
| 926 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 927 | } |
| 928 | |
| 929 | /* Perform a check of the SCLP interface. Return zero if the interface is |
| 930 | * available and there are no pending requests from a previous instance. |
| 931 | * Return non-zero otherwise. */ |
| 932 | static int |
| 933 | sclp_check_interface(void) |
| 934 | { |
| 935 | struct init_sccb *sccb; |
| 936 | unsigned long flags; |
| 937 | int retry; |
| 938 | int rc; |
| 939 | |
| 940 | spin_lock_irqsave(&sclp_lock, flags); |
| 941 | /* Prepare init mask command */ |
Thomas Huth | 1dad093 | 2014-03-31 15:24:08 +0200 | [diff] [blame] | 942 | rc = register_external_irq(EXT_IRQ_SERVICE_SIG, sclp_check_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | if (rc) { |
| 944 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 945 | return rc; |
| 946 | } |
| 947 | for (retry = 0; retry <= SCLP_INIT_RETRY; retry++) { |
| 948 | __sclp_make_init_req(0, 0); |
| 949 | sccb = (struct init_sccb *) sclp_init_req.sccb; |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 950 | rc = sclp_service_call(sclp_init_req.command, sccb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | if (rc == -EIO) |
| 952 | break; |
| 953 | sclp_init_req.status = SCLP_REQ_RUNNING; |
| 954 | sclp_running_state = sclp_running_state_running; |
| 955 | __sclp_set_request_timer(SCLP_RETRY_INTERVAL * HZ, |
| 956 | sclp_check_timeout, 0); |
| 957 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 958 | /* Enable service-signal interruption - needs to happen |
| 959 | * with IRQs enabled. */ |
Heiko Carstens | 82003c3e | 2013-09-04 13:35:45 +0200 | [diff] [blame] | 960 | irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | /* Wait for signal from interrupt or timeout */ |
| 962 | sclp_sync_wait(); |
| 963 | /* Disable service-signal interruption - needs to happen |
| 964 | * with IRQs enabled. */ |
Heiko Carstens | 82003c3e | 2013-09-04 13:35:45 +0200 | [diff] [blame] | 965 | irq_subclass_unregister(IRQ_SUBCLASS_SERVICE_SIGNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | spin_lock_irqsave(&sclp_lock, flags); |
| 967 | del_timer(&sclp_request_timer); |
| 968 | if (sclp_init_req.status == SCLP_REQ_DONE && |
| 969 | sccb->header.response_code == 0x20) { |
| 970 | rc = 0; |
| 971 | break; |
| 972 | } else |
| 973 | rc = -EBUSY; |
| 974 | } |
Thomas Huth | 1dad093 | 2014-03-31 15:24:08 +0200 | [diff] [blame] | 975 | unregister_external_irq(EXT_IRQ_SERVICE_SIG, sclp_check_handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 977 | return rc; |
| 978 | } |
| 979 | |
| 980 | /* Reboot event handler. Reset send and receive mask to prevent pending SCLP |
| 981 | * events from interfering with rebooted system. */ |
| 982 | static int |
| 983 | sclp_reboot_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 984 | { |
| 985 | sclp_deactivate(); |
| 986 | return NOTIFY_DONE; |
| 987 | } |
| 988 | |
| 989 | static struct notifier_block sclp_reboot_notifier = { |
| 990 | .notifier_call = sclp_reboot_event |
| 991 | }; |
| 992 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 993 | /* |
| 994 | * Suspend/resume SCLP notifier implementation |
| 995 | */ |
| 996 | |
| 997 | static void sclp_pm_event(enum sclp_pm_event sclp_pm_event, int rollback) |
| 998 | { |
| 999 | struct sclp_register *reg; |
| 1000 | unsigned long flags; |
| 1001 | |
| 1002 | if (!rollback) { |
| 1003 | spin_lock_irqsave(&sclp_lock, flags); |
| 1004 | list_for_each_entry(reg, &sclp_reg_list, list) |
| 1005 | reg->pm_event_posted = 0; |
| 1006 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1007 | } |
| 1008 | do { |
| 1009 | spin_lock_irqsave(&sclp_lock, flags); |
| 1010 | list_for_each_entry(reg, &sclp_reg_list, list) { |
| 1011 | if (rollback && reg->pm_event_posted) |
| 1012 | goto found; |
| 1013 | if (!rollback && !reg->pm_event_posted) |
| 1014 | goto found; |
| 1015 | } |
| 1016 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1017 | return; |
| 1018 | found: |
| 1019 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1020 | if (reg->pm_event_fn) |
| 1021 | reg->pm_event_fn(reg, sclp_pm_event); |
| 1022 | reg->pm_event_posted = rollback ? 0 : 1; |
| 1023 | } while (1); |
| 1024 | } |
| 1025 | |
| 1026 | /* |
| 1027 | * Susend/resume callbacks for platform device |
| 1028 | */ |
| 1029 | |
| 1030 | static int sclp_freeze(struct device *dev) |
| 1031 | { |
| 1032 | unsigned long flags; |
| 1033 | int rc; |
| 1034 | |
| 1035 | sclp_pm_event(SCLP_PM_EVENT_FREEZE, 0); |
| 1036 | |
| 1037 | spin_lock_irqsave(&sclp_lock, flags); |
| 1038 | sclp_suspend_state = sclp_suspend_state_suspended; |
| 1039 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1040 | |
| 1041 | /* Init supend data */ |
| 1042 | memset(&sclp_suspend_req, 0, sizeof(sclp_suspend_req)); |
| 1043 | sclp_suspend_req.callback = sclp_suspend_req_cb; |
| 1044 | sclp_suspend_req.status = SCLP_REQ_FILLED; |
| 1045 | init_completion(&sclp_request_queue_flushed); |
| 1046 | |
| 1047 | rc = sclp_add_request(&sclp_suspend_req); |
| 1048 | if (rc == 0) |
| 1049 | wait_for_completion(&sclp_request_queue_flushed); |
| 1050 | else if (rc != -ENODATA) |
| 1051 | goto fail_thaw; |
| 1052 | |
| 1053 | rc = sclp_deactivate(); |
| 1054 | if (rc) |
| 1055 | goto fail_thaw; |
| 1056 | return 0; |
| 1057 | |
| 1058 | fail_thaw: |
| 1059 | spin_lock_irqsave(&sclp_lock, flags); |
| 1060 | sclp_suspend_state = sclp_suspend_state_running; |
| 1061 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1062 | sclp_pm_event(SCLP_PM_EVENT_THAW, 1); |
| 1063 | return rc; |
| 1064 | } |
| 1065 | |
| 1066 | static int sclp_undo_suspend(enum sclp_pm_event event) |
| 1067 | { |
| 1068 | unsigned long flags; |
| 1069 | int rc; |
| 1070 | |
| 1071 | rc = sclp_reactivate(); |
| 1072 | if (rc) |
| 1073 | return rc; |
| 1074 | |
| 1075 | spin_lock_irqsave(&sclp_lock, flags); |
| 1076 | sclp_suspend_state = sclp_suspend_state_running; |
| 1077 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1078 | |
| 1079 | sclp_pm_event(event, 0); |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | static int sclp_thaw(struct device *dev) |
| 1084 | { |
| 1085 | return sclp_undo_suspend(SCLP_PM_EVENT_THAW); |
| 1086 | } |
| 1087 | |
| 1088 | static int sclp_restore(struct device *dev) |
| 1089 | { |
| 1090 | return sclp_undo_suspend(SCLP_PM_EVENT_RESTORE); |
| 1091 | } |
| 1092 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1093 | static const struct dev_pm_ops sclp_pm_ops = { |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1094 | .freeze = sclp_freeze, |
| 1095 | .thaw = sclp_thaw, |
| 1096 | .restore = sclp_restore, |
| 1097 | }; |
| 1098 | |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 1099 | static ssize_t sclp_show_console_pages(struct device_driver *dev, char *buf) |
| 1100 | { |
| 1101 | return sprintf(buf, "%i\n", sclp_console_pages); |
| 1102 | } |
| 1103 | |
| 1104 | static DRIVER_ATTR(con_pages, S_IRUSR, sclp_show_console_pages, NULL); |
| 1105 | |
| 1106 | static ssize_t sclp_show_con_drop(struct device_driver *dev, char *buf) |
| 1107 | { |
| 1108 | return sprintf(buf, "%i\n", sclp_console_drop); |
| 1109 | } |
| 1110 | |
| 1111 | static DRIVER_ATTR(con_drop, S_IRUSR, sclp_show_con_drop, NULL); |
| 1112 | |
| 1113 | static ssize_t sclp_show_console_full(struct device_driver *dev, char *buf) |
| 1114 | { |
| 1115 | return sprintf(buf, "%lu\n", sclp_console_full); |
| 1116 | } |
| 1117 | |
| 1118 | static DRIVER_ATTR(con_full, S_IRUSR, sclp_show_console_full, NULL); |
| 1119 | |
| 1120 | static struct attribute *sclp_drv_attrs[] = { |
| 1121 | &driver_attr_con_pages.attr, |
| 1122 | &driver_attr_con_drop.attr, |
| 1123 | &driver_attr_con_full.attr, |
| 1124 | NULL, |
| 1125 | }; |
| 1126 | static struct attribute_group sclp_drv_attr_group = { |
| 1127 | .attrs = sclp_drv_attrs, |
| 1128 | }; |
| 1129 | static const struct attribute_group *sclp_drv_attr_groups[] = { |
| 1130 | &sclp_drv_attr_group, |
| 1131 | NULL, |
| 1132 | }; |
| 1133 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1134 | static struct platform_driver sclp_pdrv = { |
| 1135 | .driver = { |
| 1136 | .name = "sclp", |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1137 | .pm = &sclp_pm_ops, |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 1138 | .groups = sclp_drv_attr_groups, |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1139 | }, |
| 1140 | }; |
| 1141 | |
| 1142 | static struct platform_device *sclp_pdev; |
| 1143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | /* Initialize SCLP driver. Return zero if driver is operational, non-zero |
| 1145 | * otherwise. */ |
| 1146 | static int |
| 1147 | sclp_init(void) |
| 1148 | { |
| 1149 | unsigned long flags; |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1150 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | spin_lock_irqsave(&sclp_lock, flags); |
| 1153 | /* Check for previous or running initialization */ |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1154 | if (sclp_init_state != sclp_init_state_uninitialized) |
| 1155 | goto fail_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | sclp_init_state = sclp_init_state_initializing; |
| 1157 | /* Set up variables */ |
| 1158 | INIT_LIST_HEAD(&sclp_req_queue); |
| 1159 | INIT_LIST_HEAD(&sclp_reg_list); |
| 1160 | list_add(&sclp_state_change_event.list, &sclp_reg_list); |
| 1161 | init_timer(&sclp_request_timer); |
Gerald Schaefer | 9f0128f | 2014-03-31 16:18:29 +0200 | [diff] [blame] | 1162 | init_timer(&sclp_queue_timer); |
| 1163 | sclp_queue_timer.function = sclp_req_queue_timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | /* Check interface */ |
| 1165 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1166 | rc = sclp_check_interface(); |
| 1167 | spin_lock_irqsave(&sclp_lock, flags); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1168 | if (rc) |
| 1169 | goto fail_init_state_uninitialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | /* Register reboot handler */ |
| 1171 | rc = register_reboot_notifier(&sclp_reboot_notifier); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1172 | if (rc) |
| 1173 | goto fail_init_state_uninitialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | /* Register interrupt handler */ |
Thomas Huth | 1dad093 | 2014-03-31 15:24:08 +0200 | [diff] [blame] | 1175 | rc = register_external_irq(EXT_IRQ_SERVICE_SIG, sclp_interrupt_handler); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1176 | if (rc) |
| 1177 | goto fail_unregister_reboot_notifier; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | sclp_init_state = sclp_init_state_initialized; |
| 1179 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1180 | /* Enable service-signal external interruption - needs to happen with |
| 1181 | * IRQs enabled. */ |
Heiko Carstens | 82003c3e | 2013-09-04 13:35:45 +0200 | [diff] [blame] | 1182 | irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | sclp_init_mask(1); |
| 1184 | return 0; |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1185 | |
| 1186 | fail_unregister_reboot_notifier: |
| 1187 | unregister_reboot_notifier(&sclp_reboot_notifier); |
| 1188 | fail_init_state_uninitialized: |
| 1189 | sclp_init_state = sclp_init_state_uninitialized; |
| 1190 | fail_unlock: |
| 1191 | spin_unlock_irqrestore(&sclp_lock, flags); |
| 1192 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | } |
Peter Oberparleiter | b3d00c3 | 2007-04-27 16:01:51 +0200 | [diff] [blame] | 1194 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1195 | /* |
| 1196 | * SCLP panic notifier: If we are suspended, we thaw SCLP in order to be able |
| 1197 | * to print the panic message. |
| 1198 | */ |
| 1199 | static int sclp_panic_notify(struct notifier_block *self, |
| 1200 | unsigned long event, void *data) |
| 1201 | { |
| 1202 | if (sclp_suspend_state == sclp_suspend_state_suspended) |
| 1203 | sclp_undo_suspend(SCLP_PM_EVENT_THAW); |
| 1204 | return NOTIFY_OK; |
| 1205 | } |
| 1206 | |
| 1207 | static struct notifier_block sclp_on_panic_nb = { |
| 1208 | .notifier_call = sclp_panic_notify, |
| 1209 | .priority = SCLP_PANIC_PRIO, |
| 1210 | }; |
| 1211 | |
Peter Oberparleiter | b3d00c3 | 2007-04-27 16:01:51 +0200 | [diff] [blame] | 1212 | static __init int sclp_initcall(void) |
| 1213 | { |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1214 | int rc; |
| 1215 | |
| 1216 | rc = platform_driver_register(&sclp_pdrv); |
| 1217 | if (rc) |
| 1218 | return rc; |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 1219 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1220 | sclp_pdev = platform_device_register_simple("sclp", -1, NULL, 0); |
Duan Jiong | 83d8e25 | 2014-04-11 13:39:06 +0200 | [diff] [blame] | 1221 | rc = PTR_ERR_OR_ZERO(sclp_pdev); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1222 | if (rc) |
| 1223 | goto fail_platform_driver_unregister; |
Martin Schwidefsky | 25b41a7 | 2013-05-24 12:30:03 +0200 | [diff] [blame] | 1224 | |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1225 | rc = atomic_notifier_chain_register(&panic_notifier_list, |
| 1226 | &sclp_on_panic_nb); |
| 1227 | if (rc) |
| 1228 | goto fail_platform_device_unregister; |
| 1229 | |
Peter Oberparleiter | b3d00c3 | 2007-04-27 16:01:51 +0200 | [diff] [blame] | 1230 | return sclp_init(); |
Michael Holzheu | 62b74942 | 2009-06-16 10:30:40 +0200 | [diff] [blame] | 1231 | |
| 1232 | fail_platform_device_unregister: |
| 1233 | platform_device_unregister(sclp_pdev); |
| 1234 | fail_platform_driver_unregister: |
| 1235 | platform_driver_unregister(&sclp_pdrv); |
| 1236 | return rc; |
Peter Oberparleiter | b3d00c3 | 2007-04-27 16:01:51 +0200 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | arch_initcall(sclp_initcall); |