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