cio.c 24 KB

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