cio.c 24 KB

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