cio.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  1. /*
  2. * drivers/s390/cio/cio.c
  3. * S/390 common I/O routines -- low level i/o calls
  4. * $Revision: 1.135 $
  5. *
  6. * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
  7. * IBM Corporation
  8. * Author(s): Ingo Adlung (adlung@de.ibm.com)
  9. * Cornelia Huck (cohuck@de.ibm.com)
  10. * Arnd Bergmann (arndb@de.ibm.com)
  11. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  12. */
  13. #include <linux/module.h>
  14. #include <linux/config.h>
  15. #include <linux/init.h>
  16. #include <linux/slab.h>
  17. #include <linux/device.h>
  18. #include <linux/kernel_stat.h>
  19. #include <linux/interrupt.h>
  20. #include <asm/cio.h>
  21. #include <asm/delay.h>
  22. #include <asm/irq.h>
  23. #include "airq.h"
  24. #include "cio.h"
  25. #include "css.h"
  26. #include "chsc.h"
  27. #include "ioasm.h"
  28. #include "blacklist.h"
  29. #include "cio_debug.h"
  30. debug_info_t *cio_debug_msg_id;
  31. debug_info_t *cio_debug_trace_id;
  32. debug_info_t *cio_debug_crw_id;
  33. int cio_show_msg;
  34. static int __init
  35. cio_setup (char *parm)
  36. {
  37. if (!strcmp (parm, "yes"))
  38. cio_show_msg = 1;
  39. else if (!strcmp (parm, "no"))
  40. cio_show_msg = 0;
  41. else
  42. printk (KERN_ERR "cio_setup : invalid cio_msg parameter '%s'",
  43. parm);
  44. return 1;
  45. }
  46. __setup ("cio_msg=", cio_setup);
  47. /*
  48. * Function: cio_debug_init
  49. * Initializes three debug logs (under /proc/s390dbf) for common I/O:
  50. * - cio_msg logs the messages which are printk'ed when CONFIG_DEBUG_IO is on
  51. * - cio_trace logs the calling of different functions
  52. * - cio_crw logs the messages which are printk'ed when CONFIG_DEBUG_CRW is on
  53. * debug levels depend on CONFIG_DEBUG_IO resp. CONFIG_DEBUG_CRW
  54. */
  55. static int __init
  56. cio_debug_init (void)
  57. {
  58. cio_debug_msg_id = debug_register ("cio_msg", 16, 4, 16*sizeof (long));
  59. if (!cio_debug_msg_id)
  60. goto out_unregister;
  61. debug_register_view (cio_debug_msg_id, &debug_sprintf_view);
  62. debug_set_level (cio_debug_msg_id, 2);
  63. cio_debug_trace_id = debug_register ("cio_trace", 16, 4, 8);
  64. if (!cio_debug_trace_id)
  65. goto out_unregister;
  66. debug_register_view (cio_debug_trace_id, &debug_hex_ascii_view);
  67. debug_set_level (cio_debug_trace_id, 2);
  68. cio_debug_crw_id = debug_register ("cio_crw", 4, 4, 16*sizeof (long));
  69. if (!cio_debug_crw_id)
  70. goto out_unregister;
  71. debug_register_view (cio_debug_crw_id, &debug_sprintf_view);
  72. debug_set_level (cio_debug_crw_id, 2);
  73. pr_debug("debugging initialized\n");
  74. return 0;
  75. out_unregister:
  76. if (cio_debug_msg_id)
  77. debug_unregister (cio_debug_msg_id);
  78. if (cio_debug_trace_id)
  79. debug_unregister (cio_debug_trace_id);
  80. if (cio_debug_crw_id)
  81. debug_unregister (cio_debug_crw_id);
  82. pr_debug("could not initialize debugging\n");
  83. return -1;
  84. }
  85. arch_initcall (cio_debug_init);
  86. int
  87. cio_set_options (struct subchannel *sch, int flags)
  88. {
  89. sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
  90. sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
  91. sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
  92. return 0;
  93. }
  94. /* FIXME: who wants to use this? */
  95. int
  96. cio_get_options (struct subchannel *sch)
  97. {
  98. int flags;
  99. flags = 0;
  100. if (sch->options.suspend)
  101. flags |= DOIO_ALLOW_SUSPEND;
  102. if (sch->options.prefetch)
  103. flags |= DOIO_DENY_PREFETCH;
  104. if (sch->options.inter)
  105. flags |= DOIO_SUPPRESS_INTER;
  106. return flags;
  107. }
  108. /*
  109. * Use tpi to get a pending interrupt, call the interrupt handler and
  110. * return a pointer to the subchannel structure.
  111. */
  112. static inline int
  113. cio_tpi(void)
  114. {
  115. struct tpi_info *tpi_info;
  116. struct subchannel *sch;
  117. struct irb *irb;
  118. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  119. if (tpi (NULL) != 1)
  120. return 0;
  121. irb = (struct irb *) __LC_IRB;
  122. /* Store interrupt response block to lowcore. */
  123. if (tsch (tpi_info->irq, irb) != 0)
  124. /* Not status pending or not operational. */
  125. return 1;
  126. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  127. if (!sch)
  128. return 1;
  129. local_bh_disable();
  130. irq_enter ();
  131. spin_lock(&sch->lock);
  132. memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
  133. if (sch->driver && sch->driver->irq)
  134. sch->driver->irq(&sch->dev);
  135. spin_unlock(&sch->lock);
  136. irq_exit ();
  137. __local_bh_enable();
  138. return 1;
  139. }
  140. static inline int
  141. cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
  142. {
  143. char dbf_text[15];
  144. if (lpm != 0)
  145. sch->lpm &= ~lpm;
  146. else
  147. sch->lpm = 0;
  148. stsch (sch->irq, &sch->schib);
  149. CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
  150. "subchannel %04x!\n", sch->irq);
  151. sprintf(dbf_text, "no%s", sch->dev.bus_id);
  152. CIO_TRACE_EVENT(0, dbf_text);
  153. CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
  154. return (sch->lpm ? -EACCES : -ENODEV);
  155. }
  156. int
  157. cio_start_key (struct subchannel *sch, /* subchannel structure */
  158. struct ccw1 * cpa, /* logical channel prog addr */
  159. __u8 lpm, /* logical path mask */
  160. __u8 key) /* storage key */
  161. {
  162. char dbf_txt[15];
  163. int ccode;
  164. CIO_TRACE_EVENT (4, "stIO");
  165. CIO_TRACE_EVENT (4, sch->dev.bus_id);
  166. /* sch is always under 2G. */
  167. sch->orb.intparm = (__u32)(unsigned long)sch;
  168. sch->orb.fmt = 1;
  169. sch->orb.pfch = sch->options.prefetch == 0;
  170. sch->orb.spnd = sch->options.suspend;
  171. sch->orb.ssic = sch->options.suspend && sch->options.inter;
  172. sch->orb.lpm = (lpm != 0) ? (lpm & sch->opm) : sch->lpm;
  173. #ifdef CONFIG_ARCH_S390X
  174. /*
  175. * for 64 bit we always support 64 bit IDAWs with 4k page size only
  176. */
  177. sch->orb.c64 = 1;
  178. sch->orb.i2k = 0;
  179. #endif
  180. sch->orb.key = key >> 4;
  181. /* issue "Start Subchannel" */
  182. sch->orb.cpa = (__u32) __pa (cpa);
  183. ccode = ssch (sch->irq, &sch->orb);
  184. /* process condition code */
  185. sprintf (dbf_txt, "ccode:%d", ccode);
  186. CIO_TRACE_EVENT (4, dbf_txt);
  187. switch (ccode) {
  188. case 0:
  189. /*
  190. * initialize device status information
  191. */
  192. sch->schib.scsw.actl |= SCSW_ACTL_START_PEND;
  193. return 0;
  194. case 1: /* status pending */
  195. case 2: /* busy */
  196. return -EBUSY;
  197. default: /* device/path not operational */
  198. return cio_start_handle_notoper(sch, lpm);
  199. }
  200. }
  201. int
  202. cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
  203. {
  204. return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
  205. }
  206. /*
  207. * resume suspended I/O operation
  208. */
  209. int
  210. cio_resume (struct subchannel *sch)
  211. {
  212. char dbf_txt[15];
  213. int ccode;
  214. CIO_TRACE_EVENT (4, "resIO");
  215. CIO_TRACE_EVENT (4, sch->dev.bus_id);
  216. ccode = rsch (sch->irq);
  217. sprintf (dbf_txt, "ccode:%d", ccode);
  218. CIO_TRACE_EVENT (4, dbf_txt);
  219. switch (ccode) {
  220. case 0:
  221. sch->schib.scsw.actl |= SCSW_ACTL_RESUME_PEND;
  222. return 0;
  223. case 1:
  224. return -EBUSY;
  225. case 2:
  226. return -EINVAL;
  227. default:
  228. /*
  229. * useless to wait for request completion
  230. * as device is no longer operational !
  231. */
  232. return -ENODEV;
  233. }
  234. }
  235. /*
  236. * halt I/O operation
  237. */
  238. int
  239. cio_halt(struct subchannel *sch)
  240. {
  241. char dbf_txt[15];
  242. int ccode;
  243. if (!sch)
  244. return -ENODEV;
  245. CIO_TRACE_EVENT (2, "haltIO");
  246. CIO_TRACE_EVENT (2, sch->dev.bus_id);
  247. /*
  248. * Issue "Halt subchannel" and process condition code
  249. */
  250. ccode = hsch (sch->irq);
  251. sprintf (dbf_txt, "ccode:%d", ccode);
  252. CIO_TRACE_EVENT (2, dbf_txt);
  253. switch (ccode) {
  254. case 0:
  255. sch->schib.scsw.actl |= SCSW_ACTL_HALT_PEND;
  256. return 0;
  257. case 1: /* status pending */
  258. case 2: /* busy */
  259. return -EBUSY;
  260. default: /* device not operational */
  261. return -ENODEV;
  262. }
  263. }
  264. /*
  265. * Clear I/O operation
  266. */
  267. int
  268. cio_clear(struct subchannel *sch)
  269. {
  270. char dbf_txt[15];
  271. int ccode;
  272. if (!sch)
  273. return -ENODEV;
  274. CIO_TRACE_EVENT (2, "clearIO");
  275. CIO_TRACE_EVENT (2, sch->dev.bus_id);
  276. /*
  277. * Issue "Clear subchannel" and process condition code
  278. */
  279. ccode = csch (sch->irq);
  280. sprintf (dbf_txt, "ccode:%d", ccode);
  281. CIO_TRACE_EVENT (2, dbf_txt);
  282. switch (ccode) {
  283. case 0:
  284. sch->schib.scsw.actl |= SCSW_ACTL_CLEAR_PEND;
  285. return 0;
  286. default: /* device not operational */
  287. return -ENODEV;
  288. }
  289. }
  290. /*
  291. * Function: cio_cancel
  292. * Issues a "Cancel Subchannel" on the specified subchannel
  293. * Note: We don't need any fancy intparms and flags here
  294. * since xsch is executed synchronously.
  295. * Only for common I/O internal use as for now.
  296. */
  297. int
  298. cio_cancel (struct subchannel *sch)
  299. {
  300. char dbf_txt[15];
  301. int ccode;
  302. if (!sch)
  303. return -ENODEV;
  304. CIO_TRACE_EVENT (2, "cancelIO");
  305. CIO_TRACE_EVENT (2, sch->dev.bus_id);
  306. ccode = xsch (sch->irq);
  307. sprintf (dbf_txt, "ccode:%d", ccode);
  308. CIO_TRACE_EVENT (2, dbf_txt);
  309. switch (ccode) {
  310. case 0: /* success */
  311. /* Update information in scsw. */
  312. stsch (sch->irq, &sch->schib);
  313. return 0;
  314. case 1: /* status pending */
  315. return -EBUSY;
  316. case 2: /* not applicable */
  317. return -EINVAL;
  318. default: /* not oper */
  319. return -ENODEV;
  320. }
  321. }
  322. /*
  323. * Function: cio_modify
  324. * Issues a "Modify Subchannel" on the specified subchannel
  325. */
  326. int
  327. cio_modify (struct subchannel *sch)
  328. {
  329. int ccode, retry, ret;
  330. ret = 0;
  331. for (retry = 0; retry < 5; retry++) {
  332. ccode = msch_err (sch->irq, &sch->schib);
  333. if (ccode < 0) /* -EIO if msch gets a program check. */
  334. return ccode;
  335. switch (ccode) {
  336. case 0: /* successfull */
  337. return 0;
  338. case 1: /* status pending */
  339. return -EBUSY;
  340. case 2: /* busy */
  341. udelay (100); /* allow for recovery */
  342. ret = -EBUSY;
  343. break;
  344. case 3: /* not operational */
  345. return -ENODEV;
  346. }
  347. }
  348. return ret;
  349. }
  350. /*
  351. * Enable subchannel.
  352. */
  353. int
  354. cio_enable_subchannel (struct subchannel *sch, unsigned int isc)
  355. {
  356. char dbf_txt[15];
  357. int ccode;
  358. int retry;
  359. int ret;
  360. CIO_TRACE_EVENT (2, "ensch");
  361. CIO_TRACE_EVENT (2, sch->dev.bus_id);
  362. ccode = stsch (sch->irq, &sch->schib);
  363. if (ccode)
  364. return -ENODEV;
  365. for (retry = 5, ret = 0; retry > 0; retry--) {
  366. sch->schib.pmcw.ena = 1;
  367. sch->schib.pmcw.isc = isc;
  368. sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
  369. ret = cio_modify(sch);
  370. if (ret == -ENODEV)
  371. break;
  372. if (ret == -EIO)
  373. /*
  374. * Got a program check in cio_modify. Try without
  375. * the concurrent sense bit the next time.
  376. */
  377. sch->schib.pmcw.csense = 0;
  378. if (ret == 0) {
  379. stsch (sch->irq, &sch->schib);
  380. if (sch->schib.pmcw.ena)
  381. break;
  382. }
  383. if (ret == -EBUSY) {
  384. struct irb irb;
  385. if (tsch(sch->irq, &irb) != 0)
  386. break;
  387. }
  388. }
  389. sprintf (dbf_txt, "ret:%d", ret);
  390. CIO_TRACE_EVENT (2, dbf_txt);
  391. return ret;
  392. }
  393. /*
  394. * Disable subchannel.
  395. */
  396. int
  397. cio_disable_subchannel (struct subchannel *sch)
  398. {
  399. char dbf_txt[15];
  400. int ccode;
  401. int retry;
  402. int ret;
  403. CIO_TRACE_EVENT (2, "dissch");
  404. CIO_TRACE_EVENT (2, sch->dev.bus_id);
  405. ccode = stsch (sch->irq, &sch->schib);
  406. if (ccode == 3) /* Not operational. */
  407. return -ENODEV;
  408. if (sch->schib.scsw.actl != 0)
  409. /*
  410. * the disable function must not be called while there are
  411. * requests pending for completion !
  412. */
  413. return -EBUSY;
  414. for (retry = 5, ret = 0; retry > 0; retry--) {
  415. sch->schib.pmcw.ena = 0;
  416. ret = cio_modify(sch);
  417. if (ret == -ENODEV)
  418. break;
  419. if (ret == -EBUSY)
  420. /*
  421. * The subchannel is busy or status pending.
  422. * We'll disable when the next interrupt was delivered
  423. * via the state machine.
  424. */
  425. break;
  426. if (ret == 0) {
  427. stsch (sch->irq, &sch->schib);
  428. if (!sch->schib.pmcw.ena)
  429. break;
  430. }
  431. }
  432. sprintf (dbf_txt, "ret:%d", ret);
  433. CIO_TRACE_EVENT (2, dbf_txt);
  434. return ret;
  435. }
  436. /*
  437. * cio_validate_subchannel()
  438. *
  439. * Find out subchannel type and initialize struct subchannel.
  440. * Return codes:
  441. * SUBCHANNEL_TYPE_IO for a normal io subchannel
  442. * SUBCHANNEL_TYPE_CHSC for a chsc subchannel
  443. * SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
  444. * SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
  445. * -ENXIO for non-defined subchannels
  446. * -ENODEV for subchannels with invalid device number or blacklisted devices
  447. */
  448. int
  449. cio_validate_subchannel (struct subchannel *sch, unsigned int irq)
  450. {
  451. char dbf_txt[15];
  452. int ccode;
  453. sprintf (dbf_txt, "valsch%x", irq);
  454. CIO_TRACE_EVENT (4, dbf_txt);
  455. /* Nuke all fields. */
  456. memset(sch, 0, sizeof(struct subchannel));
  457. spin_lock_init(&sch->lock);
  458. /* Set a name for the subchannel */
  459. snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.0.%04x", irq);
  460. /*
  461. * The first subchannel that is not-operational (ccode==3)
  462. * indicates that there aren't any more devices available.
  463. */
  464. sch->irq = irq;
  465. ccode = stsch (irq, &sch->schib);
  466. if (ccode)
  467. return -ENXIO;
  468. /* Copy subchannel type from path management control word. */
  469. sch->st = sch->schib.pmcw.st;
  470. /*
  471. * ... just being curious we check for non I/O subchannels
  472. */
  473. if (sch->st != 0) {
  474. CIO_DEBUG(KERN_INFO, 0,
  475. "Subchannel %04X reports "
  476. "non-I/O subchannel type %04X\n",
  477. sch->irq, sch->st);
  478. /* We stop here for non-io subchannels. */
  479. return sch->st;
  480. }
  481. /* Initialization for io subchannels. */
  482. if (!sch->schib.pmcw.dnv)
  483. /* io subchannel but device number is invalid. */
  484. return -ENODEV;
  485. /* Devno is valid. */
  486. if (is_blacklisted (sch->schib.pmcw.dev)) {
  487. /*
  488. * This device must not be known to Linux. So we simply
  489. * say that there is no device and return ENODEV.
  490. */
  491. CIO_MSG_EVENT(0, "Blacklisted device detected "
  492. "at devno %04X\n", sch->schib.pmcw.dev);
  493. return -ENODEV;
  494. }
  495. sch->opm = 0xff;
  496. chsc_validate_chpids(sch);
  497. sch->lpm = sch->schib.pmcw.pim &
  498. sch->schib.pmcw.pam &
  499. sch->schib.pmcw.pom &
  500. sch->opm;
  501. CIO_DEBUG(KERN_INFO, 0,
  502. "Detected device %04X on subchannel %04X"
  503. " - PIM = %02X, PAM = %02X, POM = %02X\n",
  504. sch->schib.pmcw.dev, sch->irq, sch->schib.pmcw.pim,
  505. sch->schib.pmcw.pam, sch->schib.pmcw.pom);
  506. /*
  507. * We now have to initially ...
  508. * ... set "interruption subclass"
  509. * ... enable "concurrent sense"
  510. * ... enable "multipath mode" if more than one
  511. * CHPID is available. This is done regardless
  512. * whether multiple paths are available for us.
  513. */
  514. sch->schib.pmcw.isc = 3; /* could be smth. else */
  515. sch->schib.pmcw.csense = 1; /* concurrent sense */
  516. sch->schib.pmcw.ena = 0;
  517. if ((sch->lpm & (sch->lpm - 1)) != 0)
  518. sch->schib.pmcw.mp = 1; /* multipath mode */
  519. return 0;
  520. }
  521. /*
  522. * do_IRQ() handles all normal I/O device IRQ's (the special
  523. * SMP cross-CPU interrupts have their own specific
  524. * handlers).
  525. *
  526. */
  527. void
  528. do_IRQ (struct pt_regs *regs)
  529. {
  530. struct tpi_info *tpi_info;
  531. struct subchannel *sch;
  532. struct irb *irb;
  533. irq_enter ();
  534. asm volatile ("mc 0,0");
  535. if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
  536. /**
  537. * Make sure that the i/o interrupt did not "overtake"
  538. * the last HZ timer interrupt.
  539. */
  540. account_ticks(regs);
  541. /*
  542. * Get interrupt information from lowcore
  543. */
  544. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  545. irb = (struct irb *) __LC_IRB;
  546. do {
  547. kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
  548. /*
  549. * Non I/O-subchannel thin interrupts are processed differently
  550. */
  551. if (tpi_info->adapter_IO == 1 &&
  552. tpi_info->int_type == IO_INTERRUPT_TYPE) {
  553. do_adapter_IO();
  554. continue;
  555. }
  556. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  557. if (sch)
  558. spin_lock(&sch->lock);
  559. /* Store interrupt response block to lowcore. */
  560. if (tsch (tpi_info->irq, irb) == 0 && sch) {
  561. /* Keep subchannel information word up to date. */
  562. memcpy (&sch->schib.scsw, &irb->scsw,
  563. sizeof (irb->scsw));
  564. /* Call interrupt handler if there is one. */
  565. if (sch->driver && sch->driver->irq)
  566. sch->driver->irq(&sch->dev);
  567. }
  568. if (sch)
  569. spin_unlock(&sch->lock);
  570. /*
  571. * Are more interrupts pending?
  572. * If so, the tpi instruction will update the lowcore
  573. * to hold the info for the next interrupt.
  574. * We don't do this for VM because a tpi drops the cpu
  575. * out of the sie which costs more cycles than it saves.
  576. */
  577. } while (!MACHINE_IS_VM && tpi (NULL) != 0);
  578. irq_exit ();
  579. }
  580. #ifdef CONFIG_CCW_CONSOLE
  581. static struct subchannel console_subchannel;
  582. static int console_subchannel_in_use;
  583. /*
  584. * busy wait for the next interrupt on the console
  585. */
  586. void
  587. wait_cons_dev (void)
  588. {
  589. unsigned long cr6 __attribute__ ((aligned (8)));
  590. unsigned long save_cr6 __attribute__ ((aligned (8)));
  591. /*
  592. * before entering the spinlock we may already have
  593. * processed the interrupt on a different CPU...
  594. */
  595. if (!console_subchannel_in_use)
  596. return;
  597. /* disable all but isc 7 (console device) */
  598. __ctl_store (save_cr6, 6, 6);
  599. cr6 = 0x01000000;
  600. __ctl_load (cr6, 6, 6);
  601. do {
  602. spin_unlock(&console_subchannel.lock);
  603. if (!cio_tpi())
  604. cpu_relax();
  605. spin_lock(&console_subchannel.lock);
  606. } while (console_subchannel.schib.scsw.actl != 0);
  607. /*
  608. * restore previous isc value
  609. */
  610. __ctl_load (save_cr6, 6, 6);
  611. }
  612. static int
  613. cio_console_irq(void)
  614. {
  615. int irq;
  616. if (console_irq != -1) {
  617. /* VM provided us with the irq number of the console. */
  618. if (stsch(console_irq, &console_subchannel.schib) != 0 ||
  619. !console_subchannel.schib.pmcw.dnv)
  620. return -1;
  621. console_devno = console_subchannel.schib.pmcw.dev;
  622. } else if (console_devno != -1) {
  623. /* At least the console device number is known. */
  624. for (irq = 0; irq < __MAX_SUBCHANNELS; irq++) {
  625. if (stsch(irq, &console_subchannel.schib) != 0)
  626. break;
  627. if (console_subchannel.schib.pmcw.dnv &&
  628. console_subchannel.schib.pmcw.dev ==
  629. console_devno) {
  630. console_irq = irq;
  631. break;
  632. }
  633. }
  634. if (console_irq == -1)
  635. return -1;
  636. } else {
  637. /* unlike in 2.4, we cannot autoprobe here, since
  638. * the channel subsystem is not fully initialized.
  639. * With some luck, the HWC console can take over */
  640. printk(KERN_WARNING "No ccw console found!\n");
  641. return -1;
  642. }
  643. return console_irq;
  644. }
  645. struct subchannel *
  646. cio_probe_console(void)
  647. {
  648. int irq, ret;
  649. if (xchg(&console_subchannel_in_use, 1) != 0)
  650. return ERR_PTR(-EBUSY);
  651. irq = cio_console_irq();
  652. if (irq == -1) {
  653. console_subchannel_in_use = 0;
  654. return ERR_PTR(-ENODEV);
  655. }
  656. memset(&console_subchannel, 0, sizeof(struct subchannel));
  657. ret = cio_validate_subchannel(&console_subchannel, irq);
  658. if (ret) {
  659. console_subchannel_in_use = 0;
  660. return ERR_PTR(-ENODEV);
  661. }
  662. /*
  663. * enable console I/O-interrupt subclass 7
  664. */
  665. ctl_set_bit(6, 24);
  666. console_subchannel.schib.pmcw.isc = 7;
  667. console_subchannel.schib.pmcw.intparm =
  668. (__u32)(unsigned long)&console_subchannel;
  669. ret = cio_modify(&console_subchannel);
  670. if (ret) {
  671. console_subchannel_in_use = 0;
  672. return ERR_PTR(ret);
  673. }
  674. return &console_subchannel;
  675. }
  676. void
  677. cio_release_console(void)
  678. {
  679. console_subchannel.schib.pmcw.intparm = 0;
  680. cio_modify(&console_subchannel);
  681. ctl_clear_bit(6, 24);
  682. console_subchannel_in_use = 0;
  683. }
  684. /* Bah... hack to catch console special sausages. */
  685. int
  686. cio_is_console(int irq)
  687. {
  688. if (!console_subchannel_in_use)
  689. return 0;
  690. return (irq == console_subchannel.irq);
  691. }
  692. struct subchannel *
  693. cio_get_console_subchannel(void)
  694. {
  695. if (!console_subchannel_in_use)
  696. return 0;
  697. return &console_subchannel;
  698. }
  699. #endif
  700. static inline int
  701. __disable_subchannel_easy(unsigned int schid, struct schib *schib)
  702. {
  703. int retry, cc;
  704. cc = 0;
  705. for (retry=0;retry<3;retry++) {
  706. schib->pmcw.ena = 0;
  707. cc = msch(schid, schib);
  708. if (cc)
  709. return (cc==3?-ENODEV:-EBUSY);
  710. stsch(schid, schib);
  711. if (!schib->pmcw.ena)
  712. return 0;
  713. }
  714. return -EBUSY; /* uhm... */
  715. }
  716. static inline int
  717. __clear_subchannel_easy(unsigned int schid)
  718. {
  719. int retry;
  720. if (csch(schid))
  721. return -ENODEV;
  722. for (retry=0;retry<20;retry++) {
  723. struct tpi_info ti;
  724. if (tpi(&ti)) {
  725. tsch(ti.irq, (struct irb *)__LC_IRB);
  726. if (ti.irq == schid)
  727. return 0;
  728. }
  729. udelay(100);
  730. }
  731. return -EBUSY;
  732. }
  733. extern void do_reipl(unsigned long devno);
  734. /* Clear all subchannels. */
  735. void
  736. clear_all_subchannels(void)
  737. {
  738. unsigned int schid;
  739. local_irq_disable();
  740. for (schid=0;schid<=highest_subchannel;schid++) {
  741. struct schib schib;
  742. if (stsch(schid, &schib))
  743. break; /* break out of the loop */
  744. if (!schib.pmcw.ena)
  745. continue;
  746. switch(__disable_subchannel_easy(schid, &schib)) {
  747. case 0:
  748. case -ENODEV:
  749. break;
  750. default: /* -EBUSY */
  751. if (__clear_subchannel_easy(schid))
  752. break; /* give up... jump out of switch */
  753. stsch(schid, &schib);
  754. __disable_subchannel_easy(schid, &schib);
  755. }
  756. }
  757. }
  758. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  759. void
  760. reipl(unsigned long devno)
  761. {
  762. clear_all_subchannels();
  763. do_reipl(devno);
  764. }