cio.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  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 <asm/setup.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->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. mutex_init(&sch->reg_mutex);
  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.pam & sch->opm;
  504. CIO_DEBUG(KERN_INFO, 0,
  505. "Detected device %04x on subchannel 0.%x.%04X"
  506. " - PIM = %02X, PAM = %02X, POM = %02X\n",
  507. sch->schib.pmcw.dev, sch->schid.ssid,
  508. sch->schid.sch_no, sch->schib.pmcw.pim,
  509. sch->schib.pmcw.pam, sch->schib.pmcw.pom);
  510. /*
  511. * We now have to initially ...
  512. * ... set "interruption subclass"
  513. * ... enable "concurrent sense"
  514. * ... enable "multipath mode" if more than one
  515. * CHPID is available. This is done regardless
  516. * whether multiple paths are available for us.
  517. */
  518. sch->schib.pmcw.isc = 3; /* could be smth. else */
  519. sch->schib.pmcw.csense = 1; /* concurrent sense */
  520. sch->schib.pmcw.ena = 0;
  521. if ((sch->lpm & (sch->lpm - 1)) != 0)
  522. sch->schib.pmcw.mp = 1; /* multipath mode */
  523. return 0;
  524. }
  525. /*
  526. * do_IRQ() handles all normal I/O device IRQ's (the special
  527. * SMP cross-CPU interrupts have their own specific
  528. * handlers).
  529. *
  530. */
  531. void
  532. do_IRQ (struct pt_regs *regs)
  533. {
  534. struct tpi_info *tpi_info;
  535. struct subchannel *sch;
  536. struct irb *irb;
  537. irq_enter ();
  538. asm volatile ("mc 0,0");
  539. if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
  540. /**
  541. * Make sure that the i/o interrupt did not "overtake"
  542. * the last HZ timer interrupt.
  543. */
  544. account_ticks(regs);
  545. /*
  546. * Get interrupt information from lowcore
  547. */
  548. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  549. irb = (struct irb *) __LC_IRB;
  550. do {
  551. kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
  552. /*
  553. * Non I/O-subchannel thin interrupts are processed differently
  554. */
  555. if (tpi_info->adapter_IO == 1 &&
  556. tpi_info->int_type == IO_INTERRUPT_TYPE) {
  557. do_adapter_IO();
  558. continue;
  559. }
  560. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  561. if (sch)
  562. spin_lock(&sch->lock);
  563. /* Store interrupt response block to lowcore. */
  564. if (tsch (tpi_info->schid, irb) == 0 && sch) {
  565. /* Keep subchannel information word up to date. */
  566. memcpy (&sch->schib.scsw, &irb->scsw,
  567. sizeof (irb->scsw));
  568. /* Call interrupt handler if there is one. */
  569. if (sch->driver && sch->driver->irq)
  570. sch->driver->irq(&sch->dev);
  571. }
  572. if (sch)
  573. spin_unlock(&sch->lock);
  574. /*
  575. * Are more interrupts pending?
  576. * If so, the tpi instruction will update the lowcore
  577. * to hold the info for the next interrupt.
  578. * We don't do this for VM because a tpi drops the cpu
  579. * out of the sie which costs more cycles than it saves.
  580. */
  581. } while (!MACHINE_IS_VM && tpi (NULL) != 0);
  582. irq_exit ();
  583. }
  584. #ifdef CONFIG_CCW_CONSOLE
  585. static struct subchannel console_subchannel;
  586. static int console_subchannel_in_use;
  587. /*
  588. * busy wait for the next interrupt on the console
  589. */
  590. void
  591. wait_cons_dev (void)
  592. {
  593. unsigned long cr6 __attribute__ ((aligned (8)));
  594. unsigned long save_cr6 __attribute__ ((aligned (8)));
  595. /*
  596. * before entering the spinlock we may already have
  597. * processed the interrupt on a different CPU...
  598. */
  599. if (!console_subchannel_in_use)
  600. return;
  601. /* disable all but isc 7 (console device) */
  602. __ctl_store (save_cr6, 6, 6);
  603. cr6 = 0x01000000;
  604. __ctl_load (cr6, 6, 6);
  605. do {
  606. spin_unlock(&console_subchannel.lock);
  607. if (!cio_tpi())
  608. cpu_relax();
  609. spin_lock(&console_subchannel.lock);
  610. } while (console_subchannel.schib.scsw.actl != 0);
  611. /*
  612. * restore previous isc value
  613. */
  614. __ctl_load (save_cr6, 6, 6);
  615. }
  616. static int
  617. cio_test_for_console(struct subchannel_id schid, void *data)
  618. {
  619. if (stsch_err(schid, &console_subchannel.schib) != 0)
  620. return -ENXIO;
  621. if (console_subchannel.schib.pmcw.dnv &&
  622. console_subchannel.schib.pmcw.dev ==
  623. console_devno) {
  624. console_irq = schid.sch_no;
  625. return 1; /* found */
  626. }
  627. return 0;
  628. }
  629. static int
  630. cio_get_console_sch_no(void)
  631. {
  632. struct subchannel_id schid;
  633. init_subchannel_id(&schid);
  634. if (console_irq != -1) {
  635. /* VM provided us with the irq number of the console. */
  636. schid.sch_no = console_irq;
  637. if (stsch(schid, &console_subchannel.schib) != 0 ||
  638. !console_subchannel.schib.pmcw.dnv)
  639. return -1;
  640. console_devno = console_subchannel.schib.pmcw.dev;
  641. } else if (console_devno != -1) {
  642. /* At least the console device number is known. */
  643. for_each_subchannel(cio_test_for_console, NULL);
  644. if (console_irq == -1)
  645. return -1;
  646. } else {
  647. /* unlike in 2.4, we cannot autoprobe here, since
  648. * the channel subsystem is not fully initialized.
  649. * With some luck, the HWC console can take over */
  650. printk(KERN_WARNING "No ccw console found!\n");
  651. return -1;
  652. }
  653. return console_irq;
  654. }
  655. struct subchannel *
  656. cio_probe_console(void)
  657. {
  658. int sch_no, ret;
  659. struct subchannel_id schid;
  660. if (xchg(&console_subchannel_in_use, 1) != 0)
  661. return ERR_PTR(-EBUSY);
  662. sch_no = cio_get_console_sch_no();
  663. if (sch_no == -1) {
  664. console_subchannel_in_use = 0;
  665. return ERR_PTR(-ENODEV);
  666. }
  667. memset(&console_subchannel, 0, sizeof(struct subchannel));
  668. init_subchannel_id(&schid);
  669. schid.sch_no = sch_no;
  670. ret = cio_validate_subchannel(&console_subchannel, schid);
  671. if (ret) {
  672. console_subchannel_in_use = 0;
  673. return ERR_PTR(-ENODEV);
  674. }
  675. /*
  676. * enable console I/O-interrupt subclass 7
  677. */
  678. ctl_set_bit(6, 24);
  679. console_subchannel.schib.pmcw.isc = 7;
  680. console_subchannel.schib.pmcw.intparm =
  681. (__u32)(unsigned long)&console_subchannel;
  682. ret = cio_modify(&console_subchannel);
  683. if (ret) {
  684. console_subchannel_in_use = 0;
  685. return ERR_PTR(ret);
  686. }
  687. return &console_subchannel;
  688. }
  689. void
  690. cio_release_console(void)
  691. {
  692. console_subchannel.schib.pmcw.intparm = 0;
  693. cio_modify(&console_subchannel);
  694. ctl_clear_bit(6, 24);
  695. console_subchannel_in_use = 0;
  696. }
  697. /* Bah... hack to catch console special sausages. */
  698. int
  699. cio_is_console(struct subchannel_id schid)
  700. {
  701. if (!console_subchannel_in_use)
  702. return 0;
  703. return schid_equal(&schid, &console_subchannel.schid);
  704. }
  705. struct subchannel *
  706. cio_get_console_subchannel(void)
  707. {
  708. if (!console_subchannel_in_use)
  709. return NULL;
  710. return &console_subchannel;
  711. }
  712. #endif
  713. static inline int
  714. __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
  715. {
  716. int retry, cc;
  717. cc = 0;
  718. for (retry=0;retry<3;retry++) {
  719. schib->pmcw.ena = 0;
  720. cc = msch(schid, schib);
  721. if (cc)
  722. return (cc==3?-ENODEV:-EBUSY);
  723. stsch(schid, schib);
  724. if (!schib->pmcw.ena)
  725. return 0;
  726. }
  727. return -EBUSY; /* uhm... */
  728. }
  729. static inline int
  730. __clear_subchannel_easy(struct subchannel_id schid)
  731. {
  732. int retry;
  733. if (csch(schid))
  734. return -ENODEV;
  735. for (retry=0;retry<20;retry++) {
  736. struct tpi_info ti;
  737. if (tpi(&ti)) {
  738. tsch(ti.schid, (struct irb *)__LC_IRB);
  739. if (schid_equal(&ti.schid, &schid))
  740. return 0;
  741. }
  742. udelay(100);
  743. }
  744. return -EBUSY;
  745. }
  746. struct sch_match_id {
  747. struct subchannel_id schid;
  748. struct ccw_dev_id devid;
  749. int rc;
  750. };
  751. static int __shutdown_subchannel_easy_and_match(struct subchannel_id schid,
  752. void *data)
  753. {
  754. struct schib schib;
  755. struct sch_match_id *match_id = data;
  756. if (stsch_err(schid, &schib))
  757. return -ENXIO;
  758. if (match_id && schib.pmcw.dnv &&
  759. (schib.pmcw.dev == match_id->devid.devno) &&
  760. (schid.ssid == match_id->devid.ssid)) {
  761. match_id->schid = schid;
  762. match_id->rc = 0;
  763. }
  764. if (!schib.pmcw.ena)
  765. return 0;
  766. switch(__disable_subchannel_easy(schid, &schib)) {
  767. case 0:
  768. case -ENODEV:
  769. break;
  770. default: /* -EBUSY */
  771. if (__clear_subchannel_easy(schid))
  772. break; /* give up... */
  773. stsch(schid, &schib);
  774. __disable_subchannel_easy(schid, &schib);
  775. }
  776. return 0;
  777. }
  778. static int clear_all_subchannels_and_match(struct ccw_dev_id *devid,
  779. struct subchannel_id *schid)
  780. {
  781. struct sch_match_id match_id;
  782. match_id.devid = *devid;
  783. match_id.rc = -ENODEV;
  784. local_irq_disable();
  785. for_each_subchannel(__shutdown_subchannel_easy_and_match, &match_id);
  786. if (match_id.rc == 0)
  787. *schid = match_id.schid;
  788. return match_id.rc;
  789. }
  790. void clear_all_subchannels(void)
  791. {
  792. local_irq_disable();
  793. for_each_subchannel(__shutdown_subchannel_easy_and_match, NULL);
  794. }
  795. extern void do_reipl_asm(__u32 schid);
  796. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  797. void reipl_ccw_dev(struct ccw_dev_id *devid)
  798. {
  799. struct subchannel_id schid;
  800. if (clear_all_subchannels_and_match(devid, &schid))
  801. panic("IPL Device not found\n");
  802. cio_reset_channel_paths();
  803. do_reipl_asm(*((__u32*)&schid));
  804. }
  805. extern struct schib ipl_schib;
  806. /*
  807. * ipl_save_parameters gets called very early. It is not allowed to access
  808. * anything in the bss section at all. The bss section is not cleared yet,
  809. * but may contain some ipl parameters written by the firmware.
  810. * These parameters (if present) are copied to 0x2000.
  811. * To avoid corruption of the ipl parameters, all variables used by this
  812. * function must reside on the stack or in the data section.
  813. */
  814. void ipl_save_parameters(void)
  815. {
  816. struct subchannel_id schid;
  817. unsigned int *ipl_ptr;
  818. void *src, *dst;
  819. schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
  820. if (!schid.one)
  821. return;
  822. if (stsch(schid, &ipl_schib))
  823. return;
  824. if (!ipl_schib.pmcw.dnv)
  825. return;
  826. ipl_devno = ipl_schib.pmcw.dev;
  827. ipl_flags |= IPL_DEVNO_VALID;
  828. if (!ipl_schib.pmcw.qf)
  829. return;
  830. ipl_flags |= IPL_PARMBLOCK_VALID;
  831. ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
  832. src = (void *)(unsigned long)*ipl_ptr;
  833. dst = (void *)IPL_PARMBLOCK_ORIGIN;
  834. memmove(dst, src, PAGE_SIZE);
  835. *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
  836. }