cio.c 20 KB

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