cio.c 24 KB

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