sclp.c 35 KB

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