cio.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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/irq_regs.h>
  22. #include <asm/setup.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, 16);
  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->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. mutex_init(&sch->reg_mutex);
  460. /* Set a name for the subchannel */
  461. snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
  462. schid.sch_no);
  463. /*
  464. * The first subchannel that is not-operational (ccode==3)
  465. * indicates that there aren't any more devices available.
  466. * If stsch gets an exception, it means the current subchannel set
  467. * is not valid.
  468. */
  469. ccode = stsch_err (schid, &sch->schib);
  470. if (ccode)
  471. return (ccode == 3) ? -ENXIO : ccode;
  472. sch->schid = schid;
  473. /* Copy subchannel type from path management control word. */
  474. sch->st = sch->schib.pmcw.st;
  475. /*
  476. * ... just being curious we check for non I/O subchannels
  477. */
  478. if (sch->st != 0) {
  479. CIO_DEBUG(KERN_INFO, 0,
  480. "Subchannel 0.%x.%04x reports "
  481. "non-I/O subchannel type %04X\n",
  482. sch->schid.ssid, sch->schid.sch_no, sch->st);
  483. /* We stop here for non-io subchannels. */
  484. return sch->st;
  485. }
  486. /* Initialization for io subchannels. */
  487. if (!sch->schib.pmcw.dnv)
  488. /* io subchannel but device number is invalid. */
  489. return -ENODEV;
  490. /* Devno is valid. */
  491. if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
  492. /*
  493. * This device must not be known to Linux. So we simply
  494. * say that there is no device and return ENODEV.
  495. */
  496. CIO_MSG_EVENT(0, "Blacklisted device detected "
  497. "at devno %04X, subchannel set %x\n",
  498. sch->schib.pmcw.dev, sch->schid.ssid);
  499. return -ENODEV;
  500. }
  501. sch->opm = 0xff;
  502. if (!cio_is_console(sch->schid))
  503. chsc_validate_chpids(sch);
  504. sch->lpm = sch->schib.pmcw.pam & 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. struct pt_regs *old_regs;
  539. old_regs = set_irq_regs(regs);
  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();
  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. set_irq_regs(old_regs);
  587. }
  588. #ifdef CONFIG_CCW_CONSOLE
  589. static struct subchannel console_subchannel;
  590. static int console_subchannel_in_use;
  591. /*
  592. * busy wait for the next interrupt on the console
  593. */
  594. void
  595. wait_cons_dev (void)
  596. {
  597. unsigned long cr6 __attribute__ ((aligned (8)));
  598. unsigned long save_cr6 __attribute__ ((aligned (8)));
  599. /*
  600. * before entering the spinlock we may already have
  601. * processed the interrupt on a different CPU...
  602. */
  603. if (!console_subchannel_in_use)
  604. return;
  605. /* disable all but isc 7 (console device) */
  606. __ctl_store (save_cr6, 6, 6);
  607. cr6 = 0x01000000;
  608. __ctl_load (cr6, 6, 6);
  609. do {
  610. spin_unlock(&console_subchannel.lock);
  611. if (!cio_tpi())
  612. cpu_relax();
  613. spin_lock(&console_subchannel.lock);
  614. } while (console_subchannel.schib.scsw.actl != 0);
  615. /*
  616. * restore previous isc value
  617. */
  618. __ctl_load (save_cr6, 6, 6);
  619. }
  620. static int
  621. cio_test_for_console(struct subchannel_id schid, void *data)
  622. {
  623. if (stsch_err(schid, &console_subchannel.schib) != 0)
  624. return -ENXIO;
  625. if (console_subchannel.schib.pmcw.dnv &&
  626. console_subchannel.schib.pmcw.dev ==
  627. console_devno) {
  628. console_irq = schid.sch_no;
  629. return 1; /* found */
  630. }
  631. return 0;
  632. }
  633. static int
  634. cio_get_console_sch_no(void)
  635. {
  636. struct subchannel_id schid;
  637. init_subchannel_id(&schid);
  638. if (console_irq != -1) {
  639. /* VM provided us with the irq number of the console. */
  640. schid.sch_no = console_irq;
  641. if (stsch(schid, &console_subchannel.schib) != 0 ||
  642. !console_subchannel.schib.pmcw.dnv)
  643. return -1;
  644. console_devno = console_subchannel.schib.pmcw.dev;
  645. } else if (console_devno != -1) {
  646. /* At least the console device number is known. */
  647. for_each_subchannel(cio_test_for_console, NULL);
  648. if (console_irq == -1)
  649. return -1;
  650. } else {
  651. /* unlike in 2.4, we cannot autoprobe here, since
  652. * the channel subsystem is not fully initialized.
  653. * With some luck, the HWC console can take over */
  654. printk(KERN_WARNING "No ccw console found!\n");
  655. return -1;
  656. }
  657. return console_irq;
  658. }
  659. struct subchannel *
  660. cio_probe_console(void)
  661. {
  662. int sch_no, ret;
  663. struct subchannel_id schid;
  664. if (xchg(&console_subchannel_in_use, 1) != 0)
  665. return ERR_PTR(-EBUSY);
  666. sch_no = cio_get_console_sch_no();
  667. if (sch_no == -1) {
  668. console_subchannel_in_use = 0;
  669. return ERR_PTR(-ENODEV);
  670. }
  671. memset(&console_subchannel, 0, sizeof(struct subchannel));
  672. init_subchannel_id(&schid);
  673. schid.sch_no = sch_no;
  674. ret = cio_validate_subchannel(&console_subchannel, schid);
  675. if (ret) {
  676. console_subchannel_in_use = 0;
  677. return ERR_PTR(-ENODEV);
  678. }
  679. /*
  680. * enable console I/O-interrupt subclass 7
  681. */
  682. ctl_set_bit(6, 24);
  683. console_subchannel.schib.pmcw.isc = 7;
  684. console_subchannel.schib.pmcw.intparm =
  685. (__u32)(unsigned long)&console_subchannel;
  686. ret = cio_modify(&console_subchannel);
  687. if (ret) {
  688. console_subchannel_in_use = 0;
  689. return ERR_PTR(ret);
  690. }
  691. return &console_subchannel;
  692. }
  693. void
  694. cio_release_console(void)
  695. {
  696. console_subchannel.schib.pmcw.intparm = 0;
  697. cio_modify(&console_subchannel);
  698. ctl_clear_bit(6, 24);
  699. console_subchannel_in_use = 0;
  700. }
  701. /* Bah... hack to catch console special sausages. */
  702. int
  703. cio_is_console(struct subchannel_id schid)
  704. {
  705. if (!console_subchannel_in_use)
  706. return 0;
  707. return schid_equal(&schid, &console_subchannel.schid);
  708. }
  709. struct subchannel *
  710. cio_get_console_subchannel(void)
  711. {
  712. if (!console_subchannel_in_use)
  713. return NULL;
  714. return &console_subchannel;
  715. }
  716. #endif
  717. static inline int
  718. __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
  719. {
  720. int retry, cc;
  721. cc = 0;
  722. for (retry=0;retry<3;retry++) {
  723. schib->pmcw.ena = 0;
  724. cc = msch(schid, schib);
  725. if (cc)
  726. return (cc==3?-ENODEV:-EBUSY);
  727. stsch(schid, schib);
  728. if (!schib->pmcw.ena)
  729. return 0;
  730. }
  731. return -EBUSY; /* uhm... */
  732. }
  733. static inline int
  734. __clear_subchannel_easy(struct subchannel_id schid)
  735. {
  736. int retry;
  737. if (csch(schid))
  738. return -ENODEV;
  739. for (retry=0;retry<20;retry++) {
  740. struct tpi_info ti;
  741. if (tpi(&ti)) {
  742. tsch(ti.schid, (struct irb *)__LC_IRB);
  743. if (schid_equal(&ti.schid, &schid))
  744. return 0;
  745. }
  746. udelay(100);
  747. }
  748. return -EBUSY;
  749. }
  750. struct sch_match_id {
  751. struct subchannel_id schid;
  752. struct ccw_dev_id devid;
  753. int rc;
  754. };
  755. static int __shutdown_subchannel_easy_and_match(struct subchannel_id schid,
  756. void *data)
  757. {
  758. struct schib schib;
  759. struct sch_match_id *match_id = data;
  760. if (stsch_err(schid, &schib))
  761. return -ENXIO;
  762. if (match_id && schib.pmcw.dnv &&
  763. (schib.pmcw.dev == match_id->devid.devno) &&
  764. (schid.ssid == match_id->devid.ssid)) {
  765. match_id->schid = schid;
  766. match_id->rc = 0;
  767. }
  768. if (!schib.pmcw.ena)
  769. return 0;
  770. switch(__disable_subchannel_easy(schid, &schib)) {
  771. case 0:
  772. case -ENODEV:
  773. break;
  774. default: /* -EBUSY */
  775. if (__clear_subchannel_easy(schid))
  776. break; /* give up... */
  777. stsch(schid, &schib);
  778. __disable_subchannel_easy(schid, &schib);
  779. }
  780. return 0;
  781. }
  782. static int clear_all_subchannels_and_match(struct ccw_dev_id *devid,
  783. struct subchannel_id *schid)
  784. {
  785. struct sch_match_id match_id;
  786. match_id.devid = *devid;
  787. match_id.rc = -ENODEV;
  788. local_irq_disable();
  789. for_each_subchannel(__shutdown_subchannel_easy_and_match, &match_id);
  790. if (match_id.rc == 0)
  791. *schid = match_id.schid;
  792. return match_id.rc;
  793. }
  794. void clear_all_subchannels(void)
  795. {
  796. local_irq_disable();
  797. for_each_subchannel(__shutdown_subchannel_easy_and_match, NULL);
  798. }
  799. extern void do_reipl_asm(__u32 schid);
  800. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  801. void reipl_ccw_dev(struct ccw_dev_id *devid)
  802. {
  803. struct subchannel_id schid;
  804. if (clear_all_subchannels_and_match(devid, &schid))
  805. panic("IPL Device not found\n");
  806. cio_reset_channel_paths();
  807. do_reipl_asm(*((__u32*)&schid));
  808. }
  809. extern struct schib ipl_schib;
  810. /*
  811. * ipl_save_parameters gets called very early. It is not allowed to access
  812. * anything in the bss section at all. The bss section is not cleared yet,
  813. * but may contain some ipl parameters written by the firmware.
  814. * These parameters (if present) are copied to 0x2000.
  815. * To avoid corruption of the ipl parameters, all variables used by this
  816. * function must reside on the stack or in the data section.
  817. */
  818. void ipl_save_parameters(void)
  819. {
  820. struct subchannel_id schid;
  821. unsigned int *ipl_ptr;
  822. void *src, *dst;
  823. schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
  824. if (!schid.one)
  825. return;
  826. if (stsch(schid, &ipl_schib))
  827. return;
  828. if (!ipl_schib.pmcw.dnv)
  829. return;
  830. ipl_devno = ipl_schib.pmcw.dev;
  831. ipl_flags |= IPL_DEVNO_VALID;
  832. if (!ipl_schib.pmcw.qf)
  833. return;
  834. ipl_flags |= IPL_PARMBLOCK_VALID;
  835. ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
  836. src = (void *)(unsigned long)*ipl_ptr;
  837. dst = (void *)IPL_PARMBLOCK_ORIGIN;
  838. memmove(dst, src, PAGE_SIZE);
  839. *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
  840. }