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