cio.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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/config.h>
  14. #include <linux/init.h>
  15. #include <linux/slab.h>
  16. #include <linux/device.h>
  17. #include <linux/kernel_stat.h>
  18. #include <linux/interrupt.h>
  19. #include <asm/cio.h>
  20. #include <asm/delay.h>
  21. #include <asm/irq.h>
  22. #include "airq.h"
  23. #include "cio.h"
  24. #include "css.h"
  25. #include "chsc.h"
  26. #include "ioasm.h"
  27. #include "blacklist.h"
  28. #include "cio_debug.h"
  29. debug_info_t *cio_debug_msg_id;
  30. debug_info_t *cio_debug_trace_id;
  31. debug_info_t *cio_debug_crw_id;
  32. int cio_show_msg;
  33. static int __init
  34. cio_setup (char *parm)
  35. {
  36. if (!strcmp (parm, "yes"))
  37. cio_show_msg = 1;
  38. else if (!strcmp (parm, "no"))
  39. cio_show_msg = 0;
  40. else
  41. printk (KERN_ERR "cio_setup : invalid cio_msg parameter '%s'",
  42. parm);
  43. return 1;
  44. }
  45. __setup ("cio_msg=", cio_setup);
  46. /*
  47. * Function: cio_debug_init
  48. * Initializes three debug logs (under /proc/s390dbf) for common I/O:
  49. * - cio_msg logs the messages which are printk'ed when CONFIG_DEBUG_IO is on
  50. * - cio_trace logs the calling of different functions
  51. * - cio_crw logs the messages which are printk'ed when CONFIG_DEBUG_CRW is on
  52. * debug levels depend on CONFIG_DEBUG_IO resp. CONFIG_DEBUG_CRW
  53. */
  54. static int __init
  55. cio_debug_init (void)
  56. {
  57. cio_debug_msg_id = debug_register ("cio_msg", 16, 4, 16*sizeof (long));
  58. if (!cio_debug_msg_id)
  59. goto out_unregister;
  60. debug_register_view (cio_debug_msg_id, &debug_sprintf_view);
  61. debug_set_level (cio_debug_msg_id, 2);
  62. cio_debug_trace_id = debug_register ("cio_trace", 16, 4, 16);
  63. if (!cio_debug_trace_id)
  64. goto out_unregister;
  65. debug_register_view (cio_debug_trace_id, &debug_hex_ascii_view);
  66. debug_set_level (cio_debug_trace_id, 2);
  67. cio_debug_crw_id = debug_register ("cio_crw", 4, 4, 16*sizeof (long));
  68. if (!cio_debug_crw_id)
  69. goto out_unregister;
  70. debug_register_view (cio_debug_crw_id, &debug_sprintf_view);
  71. debug_set_level (cio_debug_crw_id, 2);
  72. pr_debug("debugging initialized\n");
  73. return 0;
  74. out_unregister:
  75. if (cio_debug_msg_id)
  76. debug_unregister (cio_debug_msg_id);
  77. if (cio_debug_trace_id)
  78. debug_unregister (cio_debug_trace_id);
  79. if (cio_debug_crw_id)
  80. debug_unregister (cio_debug_crw_id);
  81. pr_debug("could not initialize debugging\n");
  82. return -1;
  83. }
  84. arch_initcall (cio_debug_init);
  85. int
  86. cio_set_options (struct subchannel *sch, int flags)
  87. {
  88. sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
  89. sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
  90. sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
  91. return 0;
  92. }
  93. /* FIXME: who wants to use this? */
  94. int
  95. cio_get_options (struct subchannel *sch)
  96. {
  97. int flags;
  98. flags = 0;
  99. if (sch->options.suspend)
  100. flags |= DOIO_ALLOW_SUSPEND;
  101. if (sch->options.prefetch)
  102. flags |= DOIO_DENY_PREFETCH;
  103. if (sch->options.inter)
  104. flags |= DOIO_SUPPRESS_INTER;
  105. return flags;
  106. }
  107. /*
  108. * Use tpi to get a pending interrupt, call the interrupt handler and
  109. * return a pointer to the subchannel structure.
  110. */
  111. static inline int
  112. cio_tpi(void)
  113. {
  114. struct tpi_info *tpi_info;
  115. struct subchannel *sch;
  116. struct irb *irb;
  117. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  118. if (tpi (NULL) != 1)
  119. return 0;
  120. irb = (struct irb *) __LC_IRB;
  121. /* Store interrupt response block to lowcore. */
  122. if (tsch (tpi_info->schid, irb) != 0)
  123. /* Not status pending or not operational. */
  124. return 1;
  125. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  126. if (!sch)
  127. return 1;
  128. local_bh_disable();
  129. irq_enter ();
  130. spin_lock(&sch->lock);
  131. memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
  132. if (sch->driver && sch->driver->irq)
  133. sch->driver->irq(&sch->dev);
  134. spin_unlock(&sch->lock);
  135. irq_exit ();
  136. __local_bh_enable();
  137. return 1;
  138. }
  139. static inline int
  140. cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
  141. {
  142. char dbf_text[15];
  143. if (lpm != 0)
  144. sch->lpm &= ~lpm;
  145. else
  146. sch->lpm = 0;
  147. stsch (sch->schid, &sch->schib);
  148. CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
  149. "subchannel 0.%x.%04x!\n", sch->schid.ssid,
  150. sch->schid.sch_no);
  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_64BIT
  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->schid, &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->schid);
  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->schid);
  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->schid);
  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->schid);
  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->schid, &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->schid, &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->schid, &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->schid, &sch->schib);
  380. if (sch->schib.pmcw.ena)
  381. break;
  382. }
  383. if (ret == -EBUSY) {
  384. struct irb irb;
  385. if (tsch(sch->schid, &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->schid, &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->schid, &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, struct subchannel_id schid)
  450. {
  451. char dbf_txt[15];
  452. int ccode;
  453. sprintf (dbf_txt, "valsch%x", schid.sch_no);
  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.%x.%04x", schid.ssid,
  460. schid.sch_no);
  461. /*
  462. * The first subchannel that is not-operational (ccode==3)
  463. * indicates that there aren't any more devices available.
  464. * If stsch gets an exception, it means the current subchannel set
  465. * is not valid.
  466. */
  467. ccode = stsch_err (schid, &sch->schib);
  468. if (ccode)
  469. return (ccode == 3) ? -ENXIO : ccode;
  470. sch->schid = schid;
  471. /* Copy subchannel type from path management control word. */
  472. sch->st = sch->schib.pmcw.st;
  473. /*
  474. * ... just being curious we check for non I/O subchannels
  475. */
  476. if (sch->st != 0) {
  477. CIO_DEBUG(KERN_INFO, 0,
  478. "Subchannel 0.%x.%04x reports "
  479. "non-I/O subchannel type %04X\n",
  480. sch->schid.ssid, sch->schid.sch_no, sch->st);
  481. /* We stop here for non-io subchannels. */
  482. return sch->st;
  483. }
  484. /* Initialization for io subchannels. */
  485. if (!sch->schib.pmcw.dnv)
  486. /* io subchannel but device number is invalid. */
  487. return -ENODEV;
  488. /* Devno is valid. */
  489. if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
  490. /*
  491. * This device must not be known to Linux. So we simply
  492. * say that there is no device and return ENODEV.
  493. */
  494. CIO_MSG_EVENT(0, "Blacklisted device detected "
  495. "at devno %04X, subchannel set %x\n",
  496. sch->schib.pmcw.dev, sch->schid.ssid);
  497. return -ENODEV;
  498. }
  499. sch->opm = 0xff;
  500. if (!cio_is_console(sch->schid))
  501. chsc_validate_chpids(sch);
  502. sch->lpm = sch->schib.pmcw.pim &
  503. sch->schib.pmcw.pam &
  504. sch->schib.pmcw.pom &
  505. sch->opm;
  506. CIO_DEBUG(KERN_INFO, 0,
  507. "Detected device %04x on subchannel 0.%x.%04X"
  508. " - PIM = %02X, PAM = %02X, POM = %02X\n",
  509. sch->schib.pmcw.dev, sch->schid.ssid,
  510. sch->schid.sch_no, sch->schib.pmcw.pim,
  511. sch->schib.pmcw.pam, sch->schib.pmcw.pom);
  512. /*
  513. * We now have to initially ...
  514. * ... set "interruption subclass"
  515. * ... enable "concurrent sense"
  516. * ... enable "multipath mode" if more than one
  517. * CHPID is available. This is done regardless
  518. * whether multiple paths are available for us.
  519. */
  520. sch->schib.pmcw.isc = 3; /* could be smth. else */
  521. sch->schib.pmcw.csense = 1; /* concurrent sense */
  522. sch->schib.pmcw.ena = 0;
  523. if ((sch->lpm & (sch->lpm - 1)) != 0)
  524. sch->schib.pmcw.mp = 1; /* multipath mode */
  525. return 0;
  526. }
  527. /*
  528. * do_IRQ() handles all normal I/O device IRQ's (the special
  529. * SMP cross-CPU interrupts have their own specific
  530. * handlers).
  531. *
  532. */
  533. void
  534. do_IRQ (struct pt_regs *regs)
  535. {
  536. struct tpi_info *tpi_info;
  537. struct subchannel *sch;
  538. struct irb *irb;
  539. irq_enter ();
  540. asm volatile ("mc 0,0");
  541. if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
  542. /**
  543. * Make sure that the i/o interrupt did not "overtake"
  544. * the last HZ timer interrupt.
  545. */
  546. account_ticks(regs);
  547. /*
  548. * Get interrupt information from lowcore
  549. */
  550. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  551. irb = (struct irb *) __LC_IRB;
  552. do {
  553. kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
  554. /*
  555. * Non I/O-subchannel thin interrupts are processed differently
  556. */
  557. if (tpi_info->adapter_IO == 1 &&
  558. tpi_info->int_type == IO_INTERRUPT_TYPE) {
  559. do_adapter_IO();
  560. continue;
  561. }
  562. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  563. if (sch)
  564. spin_lock(&sch->lock);
  565. /* Store interrupt response block to lowcore. */
  566. if (tsch (tpi_info->schid, irb) == 0 && sch) {
  567. /* Keep subchannel information word up to date. */
  568. memcpy (&sch->schib.scsw, &irb->scsw,
  569. sizeof (irb->scsw));
  570. /* Call interrupt handler if there is one. */
  571. if (sch->driver && sch->driver->irq)
  572. sch->driver->irq(&sch->dev);
  573. }
  574. if (sch)
  575. spin_unlock(&sch->lock);
  576. /*
  577. * Are more interrupts pending?
  578. * If so, the tpi instruction will update the lowcore
  579. * to hold the info for the next interrupt.
  580. * We don't do this for VM because a tpi drops the cpu
  581. * out of the sie which costs more cycles than it saves.
  582. */
  583. } while (!MACHINE_IS_VM && tpi (NULL) != 0);
  584. irq_exit ();
  585. }
  586. #ifdef CONFIG_CCW_CONSOLE
  587. static struct subchannel console_subchannel;
  588. static int console_subchannel_in_use;
  589. /*
  590. * busy wait for the next interrupt on the console
  591. */
  592. void
  593. wait_cons_dev (void)
  594. {
  595. unsigned long cr6 __attribute__ ((aligned (8)));
  596. unsigned long save_cr6 __attribute__ ((aligned (8)));
  597. /*
  598. * before entering the spinlock we may already have
  599. * processed the interrupt on a different CPU...
  600. */
  601. if (!console_subchannel_in_use)
  602. return;
  603. /* disable all but isc 7 (console device) */
  604. __ctl_store (save_cr6, 6, 6);
  605. cr6 = 0x01000000;
  606. __ctl_load (cr6, 6, 6);
  607. do {
  608. spin_unlock(&console_subchannel.lock);
  609. if (!cio_tpi())
  610. cpu_relax();
  611. spin_lock(&console_subchannel.lock);
  612. } while (console_subchannel.schib.scsw.actl != 0);
  613. /*
  614. * restore previous isc value
  615. */
  616. __ctl_load (save_cr6, 6, 6);
  617. }
  618. static int
  619. cio_test_for_console(struct subchannel_id schid, void *data)
  620. {
  621. if (stsch_err(schid, &console_subchannel.schib) != 0)
  622. return -ENXIO;
  623. if (console_subchannel.schib.pmcw.dnv &&
  624. console_subchannel.schib.pmcw.dev ==
  625. console_devno) {
  626. console_irq = schid.sch_no;
  627. return 1; /* found */
  628. }
  629. return 0;
  630. }
  631. static int
  632. cio_get_console_sch_no(void)
  633. {
  634. struct subchannel_id schid;
  635. init_subchannel_id(&schid);
  636. if (console_irq != -1) {
  637. /* VM provided us with the irq number of the console. */
  638. schid.sch_no = console_irq;
  639. if (stsch(schid, &console_subchannel.schib) != 0 ||
  640. !console_subchannel.schib.pmcw.dnv)
  641. return -1;
  642. console_devno = console_subchannel.schib.pmcw.dev;
  643. } else if (console_devno != -1) {
  644. /* At least the console device number is known. */
  645. for_each_subchannel(cio_test_for_console, NULL);
  646. if (console_irq == -1)
  647. return -1;
  648. } else {
  649. /* unlike in 2.4, we cannot autoprobe here, since
  650. * the channel subsystem is not fully initialized.
  651. * With some luck, the HWC console can take over */
  652. printk(KERN_WARNING "No ccw console found!\n");
  653. return -1;
  654. }
  655. return console_irq;
  656. }
  657. struct subchannel *
  658. cio_probe_console(void)
  659. {
  660. int sch_no, ret;
  661. struct subchannel_id schid;
  662. if (xchg(&console_subchannel_in_use, 1) != 0)
  663. return ERR_PTR(-EBUSY);
  664. sch_no = cio_get_console_sch_no();
  665. if (sch_no == -1) {
  666. console_subchannel_in_use = 0;
  667. return ERR_PTR(-ENODEV);
  668. }
  669. memset(&console_subchannel, 0, sizeof(struct subchannel));
  670. init_subchannel_id(&schid);
  671. schid.sch_no = sch_no;
  672. ret = cio_validate_subchannel(&console_subchannel, schid);
  673. if (ret) {
  674. console_subchannel_in_use = 0;
  675. return ERR_PTR(-ENODEV);
  676. }
  677. /*
  678. * enable console I/O-interrupt subclass 7
  679. */
  680. ctl_set_bit(6, 24);
  681. console_subchannel.schib.pmcw.isc = 7;
  682. console_subchannel.schib.pmcw.intparm =
  683. (__u32)(unsigned long)&console_subchannel;
  684. ret = cio_modify(&console_subchannel);
  685. if (ret) {
  686. console_subchannel_in_use = 0;
  687. return ERR_PTR(ret);
  688. }
  689. return &console_subchannel;
  690. }
  691. void
  692. cio_release_console(void)
  693. {
  694. console_subchannel.schib.pmcw.intparm = 0;
  695. cio_modify(&console_subchannel);
  696. ctl_clear_bit(6, 24);
  697. console_subchannel_in_use = 0;
  698. }
  699. /* Bah... hack to catch console special sausages. */
  700. int
  701. cio_is_console(struct subchannel_id schid)
  702. {
  703. if (!console_subchannel_in_use)
  704. return 0;
  705. return schid_equal(&schid, &console_subchannel.schid);
  706. }
  707. struct subchannel *
  708. cio_get_console_subchannel(void)
  709. {
  710. if (!console_subchannel_in_use)
  711. return 0;
  712. return &console_subchannel;
  713. }
  714. #endif
  715. static inline int
  716. __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
  717. {
  718. int retry, cc;
  719. cc = 0;
  720. for (retry=0;retry<3;retry++) {
  721. schib->pmcw.ena = 0;
  722. cc = msch(schid, schib);
  723. if (cc)
  724. return (cc==3?-ENODEV:-EBUSY);
  725. stsch(schid, schib);
  726. if (!schib->pmcw.ena)
  727. return 0;
  728. }
  729. return -EBUSY; /* uhm... */
  730. }
  731. static inline int
  732. __clear_subchannel_easy(struct subchannel_id schid)
  733. {
  734. int retry;
  735. if (csch(schid))
  736. return -ENODEV;
  737. for (retry=0;retry<20;retry++) {
  738. struct tpi_info ti;
  739. if (tpi(&ti)) {
  740. tsch(ti.schid, (struct irb *)__LC_IRB);
  741. if (schid_equal(&ti.schid, &schid))
  742. return 0;
  743. }
  744. udelay(100);
  745. }
  746. return -EBUSY;
  747. }
  748. extern void do_reipl(unsigned long devno);
  749. static int
  750. __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
  751. {
  752. struct schib schib;
  753. if (stsch_err(schid, &schib))
  754. return -ENXIO;
  755. if (!schib.pmcw.ena)
  756. return 0;
  757. switch(__disable_subchannel_easy(schid, &schib)) {
  758. case 0:
  759. case -ENODEV:
  760. break;
  761. default: /* -EBUSY */
  762. if (__clear_subchannel_easy(schid))
  763. break; /* give up... */
  764. stsch(schid, &schib);
  765. __disable_subchannel_easy(schid, &schib);
  766. }
  767. return 0;
  768. }
  769. void
  770. clear_all_subchannels(void)
  771. {
  772. local_irq_disable();
  773. for_each_subchannel(__shutdown_subchannel_easy, NULL);
  774. }
  775. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  776. void
  777. reipl(unsigned long devno)
  778. {
  779. clear_all_subchannels();
  780. do_reipl(devno);
  781. }