cio.c 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. * drivers/s390/cio/cio.c
  3. * S/390 common I/O routines -- low level i/o calls
  4. *
  5. * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
  6. * IBM Corporation
  7. * Author(s): Ingo Adlung (adlung@de.ibm.com)
  8. * Cornelia Huck (cornelia.huck@de.ibm.com)
  9. * Arnd Bergmann (arndb@de.ibm.com)
  10. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/slab.h>
  15. #include <linux/device.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/interrupt.h>
  18. #include <asm/cio.h>
  19. #include <asm/delay.h>
  20. #include <asm/irq.h>
  21. #include <asm/irq_regs.h>
  22. #include <asm/setup.h>
  23. #include <asm/reset.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 inline 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 inline 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. ccode = stsch (sch->schid, &sch->schib);
  366. if (ccode)
  367. return -ENODEV;
  368. for (retry = 5, ret = 0; retry > 0; retry--) {
  369. sch->schib.pmcw.ena = 1;
  370. sch->schib.pmcw.isc = isc;
  371. sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
  372. ret = cio_modify(sch);
  373. if (ret == -ENODEV)
  374. break;
  375. if (ret == -EIO)
  376. /*
  377. * Got a program check in cio_modify. Try without
  378. * the concurrent sense bit the next time.
  379. */
  380. sch->schib.pmcw.csense = 0;
  381. if (ret == 0) {
  382. stsch (sch->schid, &sch->schib);
  383. if (sch->schib.pmcw.ena)
  384. break;
  385. }
  386. if (ret == -EBUSY) {
  387. struct irb irb;
  388. if (tsch(sch->schid, &irb) != 0)
  389. break;
  390. }
  391. }
  392. sprintf (dbf_txt, "ret:%d", ret);
  393. CIO_TRACE_EVENT (2, dbf_txt);
  394. return ret;
  395. }
  396. /*
  397. * Disable subchannel.
  398. */
  399. int
  400. cio_disable_subchannel (struct subchannel *sch)
  401. {
  402. char dbf_txt[15];
  403. int ccode;
  404. int retry;
  405. int ret;
  406. CIO_TRACE_EVENT (2, "dissch");
  407. CIO_TRACE_EVENT (2, sch->dev.bus_id);
  408. ccode = stsch (sch->schid, &sch->schib);
  409. if (ccode == 3) /* Not operational. */
  410. return -ENODEV;
  411. if (sch->schib.scsw.actl != 0)
  412. /*
  413. * the disable function must not be called while there are
  414. * requests pending for completion !
  415. */
  416. return -EBUSY;
  417. for (retry = 5, ret = 0; retry > 0; retry--) {
  418. sch->schib.pmcw.ena = 0;
  419. ret = cio_modify(sch);
  420. if (ret == -ENODEV)
  421. break;
  422. if (ret == -EBUSY)
  423. /*
  424. * The subchannel is busy or status pending.
  425. * We'll disable when the next interrupt was delivered
  426. * via the state machine.
  427. */
  428. break;
  429. if (ret == 0) {
  430. stsch (sch->schid, &sch->schib);
  431. if (!sch->schib.pmcw.ena)
  432. break;
  433. }
  434. }
  435. sprintf (dbf_txt, "ret:%d", ret);
  436. CIO_TRACE_EVENT (2, dbf_txt);
  437. return ret;
  438. }
  439. /*
  440. * cio_validate_subchannel()
  441. *
  442. * Find out subchannel type and initialize struct subchannel.
  443. * Return codes:
  444. * SUBCHANNEL_TYPE_IO for a normal io subchannel
  445. * SUBCHANNEL_TYPE_CHSC for a chsc subchannel
  446. * SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
  447. * SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
  448. * -ENXIO for non-defined subchannels
  449. * -ENODEV for subchannels with invalid device number or blacklisted devices
  450. */
  451. int
  452. cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
  453. {
  454. char dbf_txt[15];
  455. int ccode;
  456. sprintf (dbf_txt, "valsch%x", schid.sch_no);
  457. CIO_TRACE_EVENT (4, dbf_txt);
  458. /* Nuke all fields. */
  459. memset(sch, 0, sizeof(struct subchannel));
  460. spin_lock_init(&sch->lock);
  461. mutex_init(&sch->reg_mutex);
  462. /* Set a name for the subchannel */
  463. snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
  464. schid.sch_no);
  465. /*
  466. * The first subchannel that is not-operational (ccode==3)
  467. * indicates that there aren't any more devices available.
  468. * If stsch gets an exception, it means the current subchannel set
  469. * is not valid.
  470. */
  471. ccode = stsch_err (schid, &sch->schib);
  472. if (ccode)
  473. return (ccode == 3) ? -ENXIO : ccode;
  474. sch->schid = schid;
  475. /* Copy subchannel type from path management control word. */
  476. sch->st = sch->schib.pmcw.st;
  477. /*
  478. * ... just being curious we check for non I/O subchannels
  479. */
  480. if (sch->st != 0) {
  481. CIO_DEBUG(KERN_INFO, 0,
  482. "Subchannel 0.%x.%04x reports "
  483. "non-I/O subchannel type %04X\n",
  484. sch->schid.ssid, sch->schid.sch_no, sch->st);
  485. /* We stop here for non-io subchannels. */
  486. return sch->st;
  487. }
  488. /* Initialization for io subchannels. */
  489. if (!sch->schib.pmcw.dnv)
  490. /* io subchannel but device number is invalid. */
  491. return -ENODEV;
  492. /* Devno is valid. */
  493. if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
  494. /*
  495. * This device must not be known to Linux. So we simply
  496. * say that there is no device and return ENODEV.
  497. */
  498. CIO_MSG_EVENT(0, "Blacklisted device detected "
  499. "at devno %04X, subchannel set %x\n",
  500. sch->schib.pmcw.dev, sch->schid.ssid);
  501. return -ENODEV;
  502. }
  503. sch->opm = 0xff;
  504. if (!cio_is_console(sch->schid))
  505. chsc_validate_chpids(sch);
  506. sch->lpm = sch->schib.pmcw.pam & sch->opm;
  507. CIO_DEBUG(KERN_INFO, 0,
  508. "Detected device %04x on subchannel 0.%x.%04X"
  509. " - PIM = %02X, PAM = %02X, POM = %02X\n",
  510. sch->schib.pmcw.dev, sch->schid.ssid,
  511. sch->schid.sch_no, sch->schib.pmcw.pim,
  512. sch->schib.pmcw.pam, sch->schib.pmcw.pom);
  513. /*
  514. * We now have to initially ...
  515. * ... set "interruption subclass"
  516. * ... enable "concurrent sense"
  517. * ... enable "multipath mode" if more than one
  518. * CHPID is available. This is done regardless
  519. * whether multiple paths are available for us.
  520. */
  521. sch->schib.pmcw.isc = 3; /* could be smth. else */
  522. sch->schib.pmcw.csense = 1; /* concurrent sense */
  523. sch->schib.pmcw.ena = 0;
  524. if ((sch->lpm & (sch->lpm - 1)) != 0)
  525. sch->schib.pmcw.mp = 1; /* multipath mode */
  526. return 0;
  527. }
  528. /*
  529. * do_IRQ() handles all normal I/O device IRQ's (the special
  530. * SMP cross-CPU interrupts have their own specific
  531. * handlers).
  532. *
  533. */
  534. void
  535. do_IRQ (struct pt_regs *regs)
  536. {
  537. struct tpi_info *tpi_info;
  538. struct subchannel *sch;
  539. struct irb *irb;
  540. struct pt_regs *old_regs;
  541. old_regs = set_irq_regs(regs);
  542. irq_enter();
  543. asm volatile ("mc 0,0");
  544. if (S390_lowcore.int_clock >= S390_lowcore.jiffy_timer)
  545. /**
  546. * Make sure that the i/o interrupt did not "overtake"
  547. * the last HZ timer interrupt.
  548. */
  549. account_ticks();
  550. /*
  551. * Get interrupt information from lowcore
  552. */
  553. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  554. irb = (struct irb *) __LC_IRB;
  555. do {
  556. kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
  557. /*
  558. * Non I/O-subchannel thin interrupts are processed differently
  559. */
  560. if (tpi_info->adapter_IO == 1 &&
  561. tpi_info->int_type == IO_INTERRUPT_TYPE) {
  562. do_adapter_IO();
  563. continue;
  564. }
  565. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  566. if (sch)
  567. spin_lock(&sch->lock);
  568. /* Store interrupt response block to lowcore. */
  569. if (tsch (tpi_info->schid, irb) == 0 && sch) {
  570. /* Keep subchannel information word up to date. */
  571. memcpy (&sch->schib.scsw, &irb->scsw,
  572. sizeof (irb->scsw));
  573. /* Call interrupt handler if there is one. */
  574. if (sch->driver && sch->driver->irq)
  575. sch->driver->irq(&sch->dev);
  576. }
  577. if (sch)
  578. spin_unlock(&sch->lock);
  579. /*
  580. * Are more interrupts pending?
  581. * If so, the tpi instruction will update the lowcore
  582. * to hold the info for the next interrupt.
  583. * We don't do this for VM because a tpi drops the cpu
  584. * out of the sie which costs more cycles than it saves.
  585. */
  586. } while (!MACHINE_IS_VM && tpi (NULL) != 0);
  587. irq_exit();
  588. set_irq_regs(old_regs);
  589. }
  590. #ifdef CONFIG_CCW_CONSOLE
  591. static struct subchannel console_subchannel;
  592. static int console_subchannel_in_use;
  593. /*
  594. * busy wait for the next interrupt on the console
  595. */
  596. void
  597. wait_cons_dev (void)
  598. {
  599. unsigned long cr6 __attribute__ ((aligned (8)));
  600. unsigned long save_cr6 __attribute__ ((aligned (8)));
  601. /*
  602. * before entering the spinlock we may already have
  603. * processed the interrupt on a different CPU...
  604. */
  605. if (!console_subchannel_in_use)
  606. return;
  607. /* disable all but isc 7 (console device) */
  608. __ctl_store (save_cr6, 6, 6);
  609. cr6 = 0x01000000;
  610. __ctl_load (cr6, 6, 6);
  611. do {
  612. spin_unlock(&console_subchannel.lock);
  613. if (!cio_tpi())
  614. cpu_relax();
  615. spin_lock(&console_subchannel.lock);
  616. } while (console_subchannel.schib.scsw.actl != 0);
  617. /*
  618. * restore previous isc value
  619. */
  620. __ctl_load (save_cr6, 6, 6);
  621. }
  622. static int
  623. cio_test_for_console(struct subchannel_id schid, void *data)
  624. {
  625. if (stsch_err(schid, &console_subchannel.schib) != 0)
  626. return -ENXIO;
  627. if (console_subchannel.schib.pmcw.dnv &&
  628. console_subchannel.schib.pmcw.dev ==
  629. console_devno) {
  630. console_irq = schid.sch_no;
  631. return 1; /* found */
  632. }
  633. return 0;
  634. }
  635. static int
  636. cio_get_console_sch_no(void)
  637. {
  638. struct subchannel_id schid;
  639. init_subchannel_id(&schid);
  640. if (console_irq != -1) {
  641. /* VM provided us with the irq number of the console. */
  642. schid.sch_no = console_irq;
  643. if (stsch(schid, &console_subchannel.schib) != 0 ||
  644. !console_subchannel.schib.pmcw.dnv)
  645. return -1;
  646. console_devno = console_subchannel.schib.pmcw.dev;
  647. } else if (console_devno != -1) {
  648. /* At least the console device number is known. */
  649. for_each_subchannel(cio_test_for_console, NULL);
  650. if (console_irq == -1)
  651. return -1;
  652. } else {
  653. /* unlike in 2.4, we cannot autoprobe here, since
  654. * the channel subsystem is not fully initialized.
  655. * With some luck, the HWC console can take over */
  656. printk(KERN_WARNING "No ccw console found!\n");
  657. return -1;
  658. }
  659. return console_irq;
  660. }
  661. struct subchannel *
  662. cio_probe_console(void)
  663. {
  664. int sch_no, ret;
  665. struct subchannel_id schid;
  666. if (xchg(&console_subchannel_in_use, 1) != 0)
  667. return ERR_PTR(-EBUSY);
  668. sch_no = cio_get_console_sch_no();
  669. if (sch_no == -1) {
  670. console_subchannel_in_use = 0;
  671. return ERR_PTR(-ENODEV);
  672. }
  673. memset(&console_subchannel, 0, sizeof(struct subchannel));
  674. init_subchannel_id(&schid);
  675. schid.sch_no = sch_no;
  676. ret = cio_validate_subchannel(&console_subchannel, schid);
  677. if (ret) {
  678. console_subchannel_in_use = 0;
  679. return ERR_PTR(-ENODEV);
  680. }
  681. /*
  682. * enable console I/O-interrupt subclass 7
  683. */
  684. ctl_set_bit(6, 24);
  685. console_subchannel.schib.pmcw.isc = 7;
  686. console_subchannel.schib.pmcw.intparm =
  687. (__u32)(unsigned long)&console_subchannel;
  688. ret = cio_modify(&console_subchannel);
  689. if (ret) {
  690. console_subchannel_in_use = 0;
  691. return ERR_PTR(ret);
  692. }
  693. return &console_subchannel;
  694. }
  695. void
  696. cio_release_console(void)
  697. {
  698. console_subchannel.schib.pmcw.intparm = 0;
  699. cio_modify(&console_subchannel);
  700. ctl_clear_bit(6, 24);
  701. console_subchannel_in_use = 0;
  702. }
  703. /* Bah... hack to catch console special sausages. */
  704. int
  705. cio_is_console(struct subchannel_id schid)
  706. {
  707. if (!console_subchannel_in_use)
  708. return 0;
  709. return schid_equal(&schid, &console_subchannel.schid);
  710. }
  711. struct subchannel *
  712. cio_get_console_subchannel(void)
  713. {
  714. if (!console_subchannel_in_use)
  715. return NULL;
  716. return &console_subchannel;
  717. }
  718. #endif
  719. static inline int
  720. __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
  721. {
  722. int retry, cc;
  723. cc = 0;
  724. for (retry=0;retry<3;retry++) {
  725. schib->pmcw.ena = 0;
  726. cc = msch(schid, schib);
  727. if (cc)
  728. return (cc==3?-ENODEV:-EBUSY);
  729. stsch(schid, schib);
  730. if (!schib->pmcw.ena)
  731. return 0;
  732. }
  733. return -EBUSY; /* uhm... */
  734. }
  735. static inline int
  736. __clear_subchannel_easy(struct subchannel_id schid)
  737. {
  738. int retry;
  739. if (csch(schid))
  740. return -ENODEV;
  741. for (retry=0;retry<20;retry++) {
  742. struct tpi_info ti;
  743. if (tpi(&ti)) {
  744. tsch(ti.schid, (struct irb *)__LC_IRB);
  745. if (schid_equal(&ti.schid, &schid))
  746. return 0;
  747. }
  748. udelay(100);
  749. }
  750. return -EBUSY;
  751. }
  752. static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
  753. {
  754. struct schib schib;
  755. if (stsch_err(schid, &schib))
  756. return -ENXIO;
  757. if (!schib.pmcw.ena)
  758. return 0;
  759. switch(__disable_subchannel_easy(schid, &schib)) {
  760. case 0:
  761. case -ENODEV:
  762. break;
  763. default: /* -EBUSY */
  764. if (__clear_subchannel_easy(schid))
  765. break; /* give up... */
  766. stsch(schid, &schib);
  767. __disable_subchannel_easy(schid, &schib);
  768. }
  769. return 0;
  770. }
  771. static atomic_t chpid_reset_count;
  772. static void s390_reset_chpids_mcck_handler(void)
  773. {
  774. struct crw crw;
  775. struct mci *mci;
  776. /* Check for pending channel report word. */
  777. mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
  778. if (!mci->cp)
  779. return;
  780. /* Process channel report words. */
  781. while (stcrw(&crw) == 0) {
  782. /* Check for responses to RCHP. */
  783. if (crw.slct && crw.rsc == CRW_RSC_CPATH)
  784. atomic_dec(&chpid_reset_count);
  785. }
  786. }
  787. #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
  788. static void css_reset(void)
  789. {
  790. int i, ret;
  791. unsigned long long timeout;
  792. /* Reset subchannels. */
  793. for_each_subchannel(__shutdown_subchannel_easy, NULL);
  794. /* Reset channel paths. */
  795. s390_reset_mcck_handler = s390_reset_chpids_mcck_handler;
  796. /* Enable channel report machine checks. */
  797. __ctl_set_bit(14, 28);
  798. /* Temporarily reenable machine checks. */
  799. local_mcck_enable();
  800. for (i = 0; i <= __MAX_CHPID; i++) {
  801. ret = rchp(i);
  802. if ((ret == 0) || (ret == 2))
  803. /*
  804. * rchp either succeeded, or another rchp is already
  805. * in progress. In either case, we'll get a crw.
  806. */
  807. atomic_inc(&chpid_reset_count);
  808. }
  809. /* Wait for machine check for all channel paths. */
  810. timeout = get_clock() + (RCHP_TIMEOUT << 12);
  811. while (atomic_read(&chpid_reset_count) != 0) {
  812. if (get_clock() > timeout)
  813. break;
  814. cpu_relax();
  815. }
  816. /* Disable machine checks again. */
  817. local_mcck_disable();
  818. /* Disable channel report machine checks. */
  819. __ctl_clear_bit(14, 28);
  820. s390_reset_mcck_handler = NULL;
  821. }
  822. static struct reset_call css_reset_call = {
  823. .fn = css_reset,
  824. };
  825. static int __init init_css_reset_call(void)
  826. {
  827. atomic_set(&chpid_reset_count, 0);
  828. register_reset_call(&css_reset_call);
  829. return 0;
  830. }
  831. arch_initcall(init_css_reset_call);
  832. struct sch_match_id {
  833. struct subchannel_id schid;
  834. struct ccw_dev_id devid;
  835. int rc;
  836. };
  837. static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
  838. {
  839. struct schib schib;
  840. struct sch_match_id *match_id = data;
  841. if (stsch_err(schid, &schib))
  842. return -ENXIO;
  843. if (schib.pmcw.dnv &&
  844. (schib.pmcw.dev == match_id->devid.devno) &&
  845. (schid.ssid == match_id->devid.ssid)) {
  846. match_id->schid = schid;
  847. match_id->rc = 0;
  848. return 1;
  849. }
  850. return 0;
  851. }
  852. static int reipl_find_schid(struct ccw_dev_id *devid,
  853. struct subchannel_id *schid)
  854. {
  855. struct sch_match_id match_id;
  856. match_id.devid = *devid;
  857. match_id.rc = -ENODEV;
  858. for_each_subchannel(__reipl_subchannel_match, &match_id);
  859. if (match_id.rc == 0)
  860. *schid = match_id.schid;
  861. return match_id.rc;
  862. }
  863. extern void do_reipl_asm(__u32 schid);
  864. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  865. void reipl_ccw_dev(struct ccw_dev_id *devid)
  866. {
  867. struct subchannel_id schid;
  868. s390_reset_system();
  869. if (reipl_find_schid(devid, &schid) != 0)
  870. panic("IPL Device not found\n");
  871. do_reipl_asm(*((__u32*)&schid));
  872. }
  873. extern struct schib ipl_schib;
  874. /*
  875. * ipl_save_parameters gets called very early. It is not allowed to access
  876. * anything in the bss section at all. The bss section is not cleared yet,
  877. * but may contain some ipl parameters written by the firmware.
  878. * These parameters (if present) are copied to 0x2000.
  879. * To avoid corruption of the ipl parameters, all variables used by this
  880. * function must reside on the stack or in the data section.
  881. */
  882. void ipl_save_parameters(void)
  883. {
  884. struct subchannel_id schid;
  885. unsigned int *ipl_ptr;
  886. void *src, *dst;
  887. schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
  888. if (!schid.one)
  889. return;
  890. if (stsch(schid, &ipl_schib))
  891. return;
  892. if (!ipl_schib.pmcw.dnv)
  893. return;
  894. ipl_devno = ipl_schib.pmcw.dev;
  895. ipl_flags |= IPL_DEVNO_VALID;
  896. if (!ipl_schib.pmcw.qf)
  897. return;
  898. ipl_flags |= IPL_PARMBLOCK_VALID;
  899. ipl_ptr = (unsigned int *)__LC_IPL_PARMBLOCK_PTR;
  900. src = (void *)(unsigned long)*ipl_ptr;
  901. dst = (void *)IPL_PARMBLOCK_ORIGIN;
  902. memmove(dst, src, PAGE_SIZE);
  903. *ipl_ptr = IPL_PARMBLOCK_ORIGIN;
  904. }