cio.c 26 KB

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