cio.c 24 KB

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