cio.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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. return -ENODEV;
  515. /* Devno is valid. */
  516. if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
  517. /*
  518. * This device must not be known to Linux. So we simply
  519. * say that there is no device and return ENODEV.
  520. */
  521. CIO_MSG_EVENT(4, "Blacklisted device detected "
  522. "at devno %04X, subchannel set %x\n",
  523. sch->schib.pmcw.dev, sch->schid.ssid);
  524. err = -ENODEV;
  525. goto out;
  526. }
  527. if (cio_is_console(sch->schid))
  528. sch->opm = 0xff;
  529. else
  530. sch->opm = chp_get_sch_opm(sch);
  531. sch->lpm = sch->schib.pmcw.pam & sch->opm;
  532. CIO_DEBUG(KERN_INFO, 0,
  533. "Detected device %04x on subchannel 0.%x.%04X"
  534. " - PIM = %02X, PAM = %02X, POM = %02X\n",
  535. sch->schib.pmcw.dev, sch->schid.ssid,
  536. sch->schid.sch_no, sch->schib.pmcw.pim,
  537. sch->schib.pmcw.pam, sch->schib.pmcw.pom);
  538. /*
  539. * We now have to initially ...
  540. * ... set "interruption subclass"
  541. * ... enable "concurrent sense"
  542. * ... enable "multipath mode" if more than one
  543. * CHPID is available. This is done regardless
  544. * whether multiple paths are available for us.
  545. */
  546. sch->schib.pmcw.isc = 3; /* could be smth. else */
  547. sch->schib.pmcw.csense = 1; /* concurrent sense */
  548. sch->schib.pmcw.ena = 0;
  549. if ((sch->lpm & (sch->lpm - 1)) != 0)
  550. sch->schib.pmcw.mp = 1; /* multipath mode */
  551. /* clean up possible residual cmf stuff */
  552. sch->schib.pmcw.mme = 0;
  553. sch->schib.pmcw.mbfc = 0;
  554. sch->schib.pmcw.mbi = 0;
  555. sch->schib.mba = 0;
  556. return 0;
  557. out:
  558. if (!cio_is_console(schid))
  559. kfree(sch->lock);
  560. sch->lock = NULL;
  561. return err;
  562. }
  563. /*
  564. * do_IRQ() handles all normal I/O device IRQ's (the special
  565. * SMP cross-CPU interrupts have their own specific
  566. * handlers).
  567. *
  568. */
  569. void
  570. do_IRQ (struct pt_regs *regs)
  571. {
  572. struct tpi_info *tpi_info;
  573. struct subchannel *sch;
  574. struct irb *irb;
  575. struct pt_regs *old_regs;
  576. old_regs = set_irq_regs(regs);
  577. irq_enter();
  578. asm volatile ("mc 0,0");
  579. if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
  580. /**
  581. * Make sure that the i/o interrupt did not "overtake"
  582. * the last HZ timer interrupt.
  583. */
  584. account_ticks(S390_lowcore.int_clock);
  585. /*
  586. * Get interrupt information from lowcore
  587. */
  588. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  589. irb = (struct irb *) __LC_IRB;
  590. do {
  591. kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
  592. /*
  593. * Non I/O-subchannel thin interrupts are processed differently
  594. */
  595. if (tpi_info->adapter_IO == 1 &&
  596. tpi_info->int_type == IO_INTERRUPT_TYPE) {
  597. do_adapter_IO();
  598. continue;
  599. }
  600. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  601. if (sch)
  602. spin_lock(sch->lock);
  603. /* Store interrupt response block to lowcore. */
  604. if (tsch (tpi_info->schid, irb) == 0 && sch) {
  605. /* Keep subchannel information word up to date. */
  606. memcpy (&sch->schib.scsw, &irb->scsw,
  607. sizeof (irb->scsw));
  608. /* Call interrupt handler if there is one. */
  609. if (sch->driver && sch->driver->irq)
  610. sch->driver->irq(sch);
  611. }
  612. if (sch)
  613. spin_unlock(sch->lock);
  614. /*
  615. * Are more interrupts pending?
  616. * If so, the tpi instruction will update the lowcore
  617. * to hold the info for the next interrupt.
  618. * We don't do this for VM because a tpi drops the cpu
  619. * out of the sie which costs more cycles than it saves.
  620. */
  621. } while (!MACHINE_IS_VM && tpi (NULL) != 0);
  622. irq_exit();
  623. set_irq_regs(old_regs);
  624. }
  625. #ifdef CONFIG_CCW_CONSOLE
  626. static struct subchannel console_subchannel;
  627. static struct io_subchannel_private console_priv;
  628. static int console_subchannel_in_use;
  629. void *cio_get_console_priv(void)
  630. {
  631. return &console_priv;
  632. }
  633. /*
  634. * busy wait for the next interrupt on the console
  635. */
  636. void
  637. wait_cons_dev (void)
  638. {
  639. unsigned long cr6 __attribute__ ((aligned (8)));
  640. unsigned long save_cr6 __attribute__ ((aligned (8)));
  641. /*
  642. * before entering the spinlock we may already have
  643. * processed the interrupt on a different CPU...
  644. */
  645. if (!console_subchannel_in_use)
  646. return;
  647. /* disable all but isc 7 (console device) */
  648. __ctl_store (save_cr6, 6, 6);
  649. cr6 = 0x01000000;
  650. __ctl_load (cr6, 6, 6);
  651. do {
  652. spin_unlock(console_subchannel.lock);
  653. if (!cio_tpi())
  654. cpu_relax();
  655. spin_lock(console_subchannel.lock);
  656. } while (console_subchannel.schib.scsw.actl != 0);
  657. /*
  658. * restore previous isc value
  659. */
  660. __ctl_load (save_cr6, 6, 6);
  661. }
  662. static int
  663. cio_test_for_console(struct subchannel_id schid, void *data)
  664. {
  665. if (stsch_err(schid, &console_subchannel.schib) != 0)
  666. return -ENXIO;
  667. if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
  668. console_subchannel.schib.pmcw.dnv &&
  669. (console_subchannel.schib.pmcw.dev == console_devno)) {
  670. console_irq = schid.sch_no;
  671. return 1; /* found */
  672. }
  673. return 0;
  674. }
  675. static int
  676. cio_get_console_sch_no(void)
  677. {
  678. struct subchannel_id schid;
  679. init_subchannel_id(&schid);
  680. if (console_irq != -1) {
  681. /* VM provided us with the irq number of the console. */
  682. schid.sch_no = console_irq;
  683. if (stsch(schid, &console_subchannel.schib) != 0 ||
  684. (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
  685. !console_subchannel.schib.pmcw.dnv)
  686. return -1;
  687. console_devno = console_subchannel.schib.pmcw.dev;
  688. } else if (console_devno != -1) {
  689. /* At least the console device number is known. */
  690. for_each_subchannel(cio_test_for_console, NULL);
  691. if (console_irq == -1)
  692. return -1;
  693. } else {
  694. /* unlike in 2.4, we cannot autoprobe here, since
  695. * the channel subsystem is not fully initialized.
  696. * With some luck, the HWC console can take over */
  697. printk(KERN_WARNING "cio: No ccw console found!\n");
  698. return -1;
  699. }
  700. return console_irq;
  701. }
  702. struct subchannel *
  703. cio_probe_console(void)
  704. {
  705. int sch_no, ret;
  706. struct subchannel_id schid;
  707. if (xchg(&console_subchannel_in_use, 1) != 0)
  708. return ERR_PTR(-EBUSY);
  709. sch_no = cio_get_console_sch_no();
  710. if (sch_no == -1) {
  711. console_subchannel_in_use = 0;
  712. return ERR_PTR(-ENODEV);
  713. }
  714. memset(&console_subchannel, 0, sizeof(struct subchannel));
  715. init_subchannel_id(&schid);
  716. schid.sch_no = sch_no;
  717. ret = cio_validate_subchannel(&console_subchannel, schid);
  718. if (ret) {
  719. console_subchannel_in_use = 0;
  720. return ERR_PTR(-ENODEV);
  721. }
  722. /*
  723. * enable console I/O-interrupt subclass 7
  724. */
  725. ctl_set_bit(6, 24);
  726. console_subchannel.schib.pmcw.isc = 7;
  727. console_subchannel.schib.pmcw.intparm =
  728. (u32)(addr_t)&console_subchannel;
  729. ret = cio_modify(&console_subchannel);
  730. if (ret) {
  731. console_subchannel_in_use = 0;
  732. return ERR_PTR(ret);
  733. }
  734. return &console_subchannel;
  735. }
  736. void
  737. cio_release_console(void)
  738. {
  739. console_subchannel.schib.pmcw.intparm = 0;
  740. cio_modify(&console_subchannel);
  741. ctl_clear_bit(6, 24);
  742. console_subchannel_in_use = 0;
  743. }
  744. /* Bah... hack to catch console special sausages. */
  745. int
  746. cio_is_console(struct subchannel_id schid)
  747. {
  748. if (!console_subchannel_in_use)
  749. return 0;
  750. return schid_equal(&schid, &console_subchannel.schid);
  751. }
  752. struct subchannel *
  753. cio_get_console_subchannel(void)
  754. {
  755. if (!console_subchannel_in_use)
  756. return NULL;
  757. return &console_subchannel;
  758. }
  759. #endif
  760. static int
  761. __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
  762. {
  763. int retry, cc;
  764. cc = 0;
  765. for (retry=0;retry<3;retry++) {
  766. schib->pmcw.ena = 0;
  767. cc = msch(schid, schib);
  768. if (cc)
  769. return (cc==3?-ENODEV:-EBUSY);
  770. stsch(schid, schib);
  771. if (!schib->pmcw.ena)
  772. return 0;
  773. }
  774. return -EBUSY; /* uhm... */
  775. }
  776. /* we can't use the normal udelay here, since it enables external interrupts */
  777. static void udelay_reset(unsigned long usecs)
  778. {
  779. uint64_t start_cc, end_cc;
  780. asm volatile ("STCK %0" : "=m" (start_cc));
  781. do {
  782. cpu_relax();
  783. asm volatile ("STCK %0" : "=m" (end_cc));
  784. } while (((end_cc - start_cc)/4096) < usecs);
  785. }
  786. static int
  787. __clear_subchannel_easy(struct subchannel_id schid)
  788. {
  789. int retry;
  790. if (csch(schid))
  791. return -ENODEV;
  792. for (retry=0;retry<20;retry++) {
  793. struct tpi_info ti;
  794. if (tpi(&ti)) {
  795. tsch(ti.schid, (struct irb *)__LC_IRB);
  796. if (schid_equal(&ti.schid, &schid))
  797. return 0;
  798. }
  799. udelay_reset(100);
  800. }
  801. return -EBUSY;
  802. }
  803. static int pgm_check_occured;
  804. static void cio_reset_pgm_check_handler(void)
  805. {
  806. pgm_check_occured = 1;
  807. }
  808. static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
  809. {
  810. int rc;
  811. pgm_check_occured = 0;
  812. s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
  813. rc = stsch(schid, addr);
  814. s390_base_pgm_handler_fn = NULL;
  815. /* The program check handler could have changed pgm_check_occured. */
  816. barrier();
  817. if (pgm_check_occured)
  818. return -EIO;
  819. else
  820. return rc;
  821. }
  822. static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
  823. {
  824. struct schib schib;
  825. if (stsch_reset(schid, &schib))
  826. return -ENXIO;
  827. if (!schib.pmcw.ena)
  828. return 0;
  829. switch(__disable_subchannel_easy(schid, &schib)) {
  830. case 0:
  831. case -ENODEV:
  832. break;
  833. default: /* -EBUSY */
  834. if (__clear_subchannel_easy(schid))
  835. break; /* give up... */
  836. stsch(schid, &schib);
  837. __disable_subchannel_easy(schid, &schib);
  838. }
  839. return 0;
  840. }
  841. static atomic_t chpid_reset_count;
  842. static void s390_reset_chpids_mcck_handler(void)
  843. {
  844. struct crw crw;
  845. struct mci *mci;
  846. /* Check for pending channel report word. */
  847. mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
  848. if (!mci->cp)
  849. return;
  850. /* Process channel report words. */
  851. while (stcrw(&crw) == 0) {
  852. /* Check for responses to RCHP. */
  853. if (crw.slct && crw.rsc == CRW_RSC_CPATH)
  854. atomic_dec(&chpid_reset_count);
  855. }
  856. }
  857. #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
  858. static void css_reset(void)
  859. {
  860. int i, ret;
  861. unsigned long long timeout;
  862. struct chp_id chpid;
  863. /* Reset subchannels. */
  864. for_each_subchannel(__shutdown_subchannel_easy, NULL);
  865. /* Reset channel paths. */
  866. s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
  867. /* Enable channel report machine checks. */
  868. __ctl_set_bit(14, 28);
  869. /* Temporarily reenable machine checks. */
  870. local_mcck_enable();
  871. chp_id_init(&chpid);
  872. for (i = 0; i <= __MAX_CHPID; i++) {
  873. chpid.id = i;
  874. ret = rchp(chpid);
  875. if ((ret == 0) || (ret == 2))
  876. /*
  877. * rchp either succeeded, or another rchp is already
  878. * in progress. In either case, we'll get a crw.
  879. */
  880. atomic_inc(&chpid_reset_count);
  881. }
  882. /* Wait for machine check for all channel paths. */
  883. timeout = get_clock() + (RCHP_TIMEOUT << 12);
  884. while (atomic_read(&chpid_reset_count) != 0) {
  885. if (get_clock() > timeout)
  886. break;
  887. cpu_relax();
  888. }
  889. /* Disable machine checks again. */
  890. local_mcck_disable();
  891. /* Disable channel report machine checks. */
  892. __ctl_clear_bit(14, 28);
  893. s390_base_mcck_handler_fn = NULL;
  894. }
  895. static struct reset_call css_reset_call = {
  896. .fn = css_reset,
  897. };
  898. static int __init init_css_reset_call(void)
  899. {
  900. atomic_set(&chpid_reset_count, 0);
  901. register_reset_call(&css_reset_call);
  902. return 0;
  903. }
  904. arch_initcall(init_css_reset_call);
  905. struct sch_match_id {
  906. struct subchannel_id schid;
  907. struct ccw_dev_id devid;
  908. int rc;
  909. };
  910. static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
  911. {
  912. struct schib schib;
  913. struct sch_match_id *match_id = data;
  914. if (stsch_reset(schid, &schib))
  915. return -ENXIO;
  916. if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
  917. (schib.pmcw.dev == match_id->devid.devno) &&
  918. (schid.ssid == match_id->devid.ssid)) {
  919. match_id->schid = schid;
  920. match_id->rc = 0;
  921. return 1;
  922. }
  923. return 0;
  924. }
  925. static int reipl_find_schid(struct ccw_dev_id *devid,
  926. struct subchannel_id *schid)
  927. {
  928. struct sch_match_id match_id;
  929. match_id.devid = *devid;
  930. match_id.rc = -ENODEV;
  931. for_each_subchannel(__reipl_subchannel_match, &match_id);
  932. if (match_id.rc == 0)
  933. *schid = match_id.schid;
  934. return match_id.rc;
  935. }
  936. extern void do_reipl_asm(__u32 schid);
  937. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  938. void reipl_ccw_dev(struct ccw_dev_id *devid)
  939. {
  940. struct subchannel_id schid;
  941. s390_reset_system();
  942. if (reipl_find_schid(devid, &schid) != 0)
  943. panic("IPL Device not found\n");
  944. do_reipl_asm(*((__u32*)&schid));
  945. }
  946. int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
  947. {
  948. struct subchannel_id schid;
  949. struct schib schib;
  950. schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
  951. if (!schid.one)
  952. return -ENODEV;
  953. if (stsch(schid, &schib))
  954. return -ENODEV;
  955. if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
  956. return -ENODEV;
  957. if (!schib.pmcw.dnv)
  958. return -ENODEV;
  959. iplinfo->devno = schib.pmcw.dev;
  960. iplinfo->is_qdio = schib.pmcw.qf;
  961. return 0;
  962. }