cio.c 25 KB

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