sclp.c 33 KB

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