cio.c 20 KB

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