cio.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. /*
  2. * drivers/s390/cio/cio.c
  3. * S/390 common I/O routines -- low level i/o calls
  4. *
  5. * Copyright IBM Corp. 1999,2008
  6. * Author(s): Ingo Adlung (adlung@de.ibm.com)
  7. * Cornelia Huck (cornelia.huck@de.ibm.com)
  8. * Arnd Bergmann (arndb@de.ibm.com)
  9. * Martin Schwidefsky (schwidefsky@de.ibm.com)
  10. */
  11. #define KMSG_COMPONENT "cio"
  12. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  13. #include <linux/ftrace.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/slab.h>
  17. #include <linux/device.h>
  18. #include <linux/kernel_stat.h>
  19. #include <linux/interrupt.h>
  20. #include <asm/cio.h>
  21. #include <asm/delay.h>
  22. #include <asm/irq.h>
  23. #include <asm/irq_regs.h>
  24. #include <asm/setup.h>
  25. #include <asm/reset.h>
  26. #include <asm/ipl.h>
  27. #include <asm/chpid.h>
  28. #include <asm/airq.h>
  29. #include <asm/isc.h>
  30. #include <asm/cputime.h>
  31. #include <asm/fcx.h>
  32. #include <asm/nmi.h>
  33. #include <asm/crw.h>
  34. #include "cio.h"
  35. #include "css.h"
  36. #include "chsc.h"
  37. #include "ioasm.h"
  38. #include "io_sch.h"
  39. #include "blacklist.h"
  40. #include "cio_debug.h"
  41. #include "chp.h"
  42. debug_info_t *cio_debug_msg_id;
  43. debug_info_t *cio_debug_trace_id;
  44. debug_info_t *cio_debug_crw_id;
  45. /*
  46. * Function: cio_debug_init
  47. * Initializes three debug logs for common I/O:
  48. * - cio_msg logs generic cio messages
  49. * - cio_trace logs the calling of different functions
  50. * - cio_crw logs machine check related cio messages
  51. */
  52. static int __init cio_debug_init(void)
  53. {
  54. cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long));
  55. if (!cio_debug_msg_id)
  56. goto out_unregister;
  57. debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
  58. debug_set_level(cio_debug_msg_id, 2);
  59. cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
  60. if (!cio_debug_trace_id)
  61. goto out_unregister;
  62. debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
  63. debug_set_level(cio_debug_trace_id, 2);
  64. cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long));
  65. if (!cio_debug_crw_id)
  66. goto out_unregister;
  67. debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
  68. debug_set_level(cio_debug_crw_id, 4);
  69. return 0;
  70. out_unregister:
  71. if (cio_debug_msg_id)
  72. debug_unregister(cio_debug_msg_id);
  73. if (cio_debug_trace_id)
  74. debug_unregister(cio_debug_trace_id);
  75. if (cio_debug_crw_id)
  76. debug_unregister(cio_debug_crw_id);
  77. return -1;
  78. }
  79. arch_initcall (cio_debug_init);
  80. int
  81. cio_set_options (struct subchannel *sch, int flags)
  82. {
  83. sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
  84. sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
  85. sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
  86. return 0;
  87. }
  88. /* FIXME: who wants to use this? */
  89. int
  90. cio_get_options (struct subchannel *sch)
  91. {
  92. int flags;
  93. flags = 0;
  94. if (sch->options.suspend)
  95. flags |= DOIO_ALLOW_SUSPEND;
  96. if (sch->options.prefetch)
  97. flags |= DOIO_DENY_PREFETCH;
  98. if (sch->options.inter)
  99. flags |= DOIO_SUPPRESS_INTER;
  100. return flags;
  101. }
  102. static int
  103. cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
  104. {
  105. char dbf_text[15];
  106. if (lpm != 0)
  107. sch->lpm &= ~lpm;
  108. else
  109. sch->lpm = 0;
  110. CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
  111. "subchannel 0.%x.%04x!\n", sch->schid.ssid,
  112. sch->schid.sch_no);
  113. if (cio_update_schib(sch))
  114. return -ENODEV;
  115. sprintf(dbf_text, "no%s", dev_name(&sch->dev));
  116. CIO_TRACE_EVENT(0, dbf_text);
  117. CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
  118. return (sch->lpm ? -EACCES : -ENODEV);
  119. }
  120. int
  121. cio_start_key (struct subchannel *sch, /* subchannel structure */
  122. struct ccw1 * cpa, /* logical channel prog addr */
  123. __u8 lpm, /* logical path mask */
  124. __u8 key) /* storage key */
  125. {
  126. int ccode;
  127. union orb *orb;
  128. CIO_TRACE_EVENT(5, "stIO");
  129. CIO_TRACE_EVENT(5, dev_name(&sch->dev));
  130. orb = &to_io_private(sch)->orb;
  131. memset(orb, 0, sizeof(union orb));
  132. /* sch is always under 2G. */
  133. orb->cmd.intparm = (u32)(addr_t)sch;
  134. orb->cmd.fmt = 1;
  135. orb->cmd.pfch = sch->options.prefetch == 0;
  136. orb->cmd.spnd = sch->options.suspend;
  137. orb->cmd.ssic = sch->options.suspend && sch->options.inter;
  138. orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm;
  139. #ifdef CONFIG_64BIT
  140. /*
  141. * for 64 bit we always support 64 bit IDAWs with 4k page size only
  142. */
  143. orb->cmd.c64 = 1;
  144. orb->cmd.i2k = 0;
  145. #endif
  146. orb->cmd.key = key >> 4;
  147. /* issue "Start Subchannel" */
  148. orb->cmd.cpa = (__u32) __pa(cpa);
  149. ccode = ssch(sch->schid, orb);
  150. /* process condition code */
  151. CIO_HEX_EVENT(5, &ccode, sizeof(ccode));
  152. switch (ccode) {
  153. case 0:
  154. /*
  155. * initialize device status information
  156. */
  157. sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
  158. return 0;
  159. case 1: /* status pending */
  160. case 2: /* busy */
  161. return -EBUSY;
  162. case 3: /* device/path not operational */
  163. return cio_start_handle_notoper(sch, lpm);
  164. default:
  165. return ccode;
  166. }
  167. }
  168. int
  169. cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
  170. {
  171. return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
  172. }
  173. /*
  174. * resume suspended I/O operation
  175. */
  176. int
  177. cio_resume (struct subchannel *sch)
  178. {
  179. int ccode;
  180. CIO_TRACE_EVENT(4, "resIO");
  181. CIO_TRACE_EVENT(4, dev_name(&sch->dev));
  182. ccode = rsch (sch->schid);
  183. CIO_HEX_EVENT(4, &ccode, sizeof(ccode));
  184. switch (ccode) {
  185. case 0:
  186. sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND;
  187. return 0;
  188. case 1:
  189. return -EBUSY;
  190. case 2:
  191. return -EINVAL;
  192. default:
  193. /*
  194. * useless to wait for request completion
  195. * as device is no longer operational !
  196. */
  197. return -ENODEV;
  198. }
  199. }
  200. /*
  201. * halt I/O operation
  202. */
  203. int
  204. cio_halt(struct subchannel *sch)
  205. {
  206. int ccode;
  207. if (!sch)
  208. return -ENODEV;
  209. CIO_TRACE_EVENT(2, "haltIO");
  210. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  211. /*
  212. * Issue "Halt subchannel" and process condition code
  213. */
  214. ccode = hsch (sch->schid);
  215. CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
  216. switch (ccode) {
  217. case 0:
  218. sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND;
  219. return 0;
  220. case 1: /* status pending */
  221. case 2: /* busy */
  222. return -EBUSY;
  223. default: /* device not operational */
  224. return -ENODEV;
  225. }
  226. }
  227. /*
  228. * Clear I/O operation
  229. */
  230. int
  231. cio_clear(struct subchannel *sch)
  232. {
  233. int ccode;
  234. if (!sch)
  235. return -ENODEV;
  236. CIO_TRACE_EVENT(2, "clearIO");
  237. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  238. /*
  239. * Issue "Clear subchannel" and process condition code
  240. */
  241. ccode = csch (sch->schid);
  242. CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
  243. switch (ccode) {
  244. case 0:
  245. sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND;
  246. return 0;
  247. default: /* device not operational */
  248. return -ENODEV;
  249. }
  250. }
  251. /*
  252. * Function: cio_cancel
  253. * Issues a "Cancel Subchannel" on the specified subchannel
  254. * Note: We don't need any fancy intparms and flags here
  255. * since xsch is executed synchronously.
  256. * Only for common I/O internal use as for now.
  257. */
  258. int
  259. cio_cancel (struct subchannel *sch)
  260. {
  261. int ccode;
  262. if (!sch)
  263. return -ENODEV;
  264. CIO_TRACE_EVENT(2, "cancelIO");
  265. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  266. ccode = xsch (sch->schid);
  267. CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
  268. switch (ccode) {
  269. case 0: /* success */
  270. /* Update information in scsw. */
  271. if (cio_update_schib(sch))
  272. return -ENODEV;
  273. return 0;
  274. case 1: /* status pending */
  275. return -EBUSY;
  276. case 2: /* not applicable */
  277. return -EINVAL;
  278. default: /* not oper */
  279. return -ENODEV;
  280. }
  281. }
  282. static void cio_apply_config(struct subchannel *sch, struct schib *schib)
  283. {
  284. schib->pmcw.intparm = sch->config.intparm;
  285. schib->pmcw.mbi = sch->config.mbi;
  286. schib->pmcw.isc = sch->config.isc;
  287. schib->pmcw.ena = sch->config.ena;
  288. schib->pmcw.mme = sch->config.mme;
  289. schib->pmcw.mp = sch->config.mp;
  290. schib->pmcw.csense = sch->config.csense;
  291. schib->pmcw.mbfc = sch->config.mbfc;
  292. if (sch->config.mbfc)
  293. schib->mba = sch->config.mba;
  294. }
  295. static int cio_check_config(struct subchannel *sch, struct schib *schib)
  296. {
  297. return (schib->pmcw.intparm == sch->config.intparm) &&
  298. (schib->pmcw.mbi == sch->config.mbi) &&
  299. (schib->pmcw.isc == sch->config.isc) &&
  300. (schib->pmcw.ena == sch->config.ena) &&
  301. (schib->pmcw.mme == sch->config.mme) &&
  302. (schib->pmcw.mp == sch->config.mp) &&
  303. (schib->pmcw.csense == sch->config.csense) &&
  304. (schib->pmcw.mbfc == sch->config.mbfc) &&
  305. (!sch->config.mbfc || (schib->mba == sch->config.mba));
  306. }
  307. /*
  308. * cio_commit_config - apply configuration to the subchannel
  309. */
  310. int cio_commit_config(struct subchannel *sch)
  311. {
  312. struct schib schib;
  313. int ccode, retry, ret = 0;
  314. if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
  315. return -ENODEV;
  316. for (retry = 0; retry < 5; retry++) {
  317. /* copy desired changes to local schib */
  318. cio_apply_config(sch, &schib);
  319. ccode = msch_err(sch->schid, &schib);
  320. if (ccode < 0) /* -EIO if msch gets a program check. */
  321. return ccode;
  322. switch (ccode) {
  323. case 0: /* successful */
  324. if (stsch(sch->schid, &schib) ||
  325. !css_sch_is_valid(&schib))
  326. return -ENODEV;
  327. if (cio_check_config(sch, &schib)) {
  328. /* commit changes from local schib */
  329. memcpy(&sch->schib, &schib, sizeof(schib));
  330. return 0;
  331. }
  332. ret = -EAGAIN;
  333. break;
  334. case 1: /* status pending */
  335. return -EBUSY;
  336. case 2: /* busy */
  337. udelay(100); /* allow for recovery */
  338. ret = -EBUSY;
  339. break;
  340. case 3: /* not operational */
  341. return -ENODEV;
  342. }
  343. }
  344. return ret;
  345. }
  346. /**
  347. * cio_update_schib - Perform stsch and update schib if subchannel is valid.
  348. * @sch: subchannel on which to perform stsch
  349. * Return zero on success, -ENODEV otherwise.
  350. */
  351. int cio_update_schib(struct subchannel *sch)
  352. {
  353. struct schib schib;
  354. if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
  355. return -ENODEV;
  356. memcpy(&sch->schib, &schib, sizeof(schib));
  357. return 0;
  358. }
  359. EXPORT_SYMBOL_GPL(cio_update_schib);
  360. /**
  361. * cio_enable_subchannel - enable a subchannel.
  362. * @sch: subchannel to be enabled
  363. * @intparm: interruption parameter to set
  364. */
  365. int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
  366. {
  367. int retry;
  368. int ret;
  369. CIO_TRACE_EVENT(2, "ensch");
  370. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  371. if (sch_is_pseudo_sch(sch))
  372. return -EINVAL;
  373. if (cio_update_schib(sch))
  374. return -ENODEV;
  375. sch->config.ena = 1;
  376. sch->config.isc = sch->isc;
  377. sch->config.intparm = intparm;
  378. for (retry = 0; retry < 3; retry++) {
  379. ret = cio_commit_config(sch);
  380. if (ret == -EIO) {
  381. /*
  382. * Got a program check in msch. Try without
  383. * the concurrent sense bit the next time.
  384. */
  385. sch->config.csense = 0;
  386. } else if (ret == -EBUSY) {
  387. struct irb irb;
  388. if (tsch(sch->schid, &irb) != 0)
  389. break;
  390. } else
  391. break;
  392. }
  393. CIO_HEX_EVENT(2, &ret, sizeof(ret));
  394. return ret;
  395. }
  396. EXPORT_SYMBOL_GPL(cio_enable_subchannel);
  397. /**
  398. * cio_disable_subchannel - disable a subchannel.
  399. * @sch: subchannel to disable
  400. */
  401. int cio_disable_subchannel(struct subchannel *sch)
  402. {
  403. int retry;
  404. int ret;
  405. CIO_TRACE_EVENT(2, "dissch");
  406. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  407. if (sch_is_pseudo_sch(sch))
  408. return 0;
  409. if (cio_update_schib(sch))
  410. return -ENODEV;
  411. sch->config.ena = 0;
  412. for (retry = 0; retry < 3; retry++) {
  413. ret = cio_commit_config(sch);
  414. if (ret == -EBUSY) {
  415. struct irb irb;
  416. if (tsch(sch->schid, &irb) != 0)
  417. break;
  418. } else
  419. break;
  420. }
  421. CIO_HEX_EVENT(2, &ret, sizeof(ret));
  422. return ret;
  423. }
  424. EXPORT_SYMBOL_GPL(cio_disable_subchannel);
  425. int cio_create_sch_lock(struct subchannel *sch)
  426. {
  427. sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
  428. if (!sch->lock)
  429. return -ENOMEM;
  430. spin_lock_init(sch->lock);
  431. return 0;
  432. }
  433. static int cio_check_devno_blacklisted(struct subchannel *sch)
  434. {
  435. if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) {
  436. /*
  437. * This device must not be known to Linux. So we simply
  438. * say that there is no device and return ENODEV.
  439. */
  440. CIO_MSG_EVENT(6, "Blacklisted device detected "
  441. "at devno %04X, subchannel set %x\n",
  442. sch->schib.pmcw.dev, sch->schid.ssid);
  443. return -ENODEV;
  444. }
  445. return 0;
  446. }
  447. static int cio_validate_io_subchannel(struct subchannel *sch)
  448. {
  449. /* Initialization for io subchannels. */
  450. if (!css_sch_is_valid(&sch->schib))
  451. return -ENODEV;
  452. /* Devno is valid. */
  453. return cio_check_devno_blacklisted(sch);
  454. }
  455. static int cio_validate_msg_subchannel(struct subchannel *sch)
  456. {
  457. /* Initialization for message subchannels. */
  458. if (!css_sch_is_valid(&sch->schib))
  459. return -ENODEV;
  460. /* Devno is valid. */
  461. return cio_check_devno_blacklisted(sch);
  462. }
  463. /**
  464. * cio_validate_subchannel - basic validation of subchannel
  465. * @sch: subchannel structure to be filled out
  466. * @schid: subchannel id
  467. *
  468. * Find out subchannel type and initialize struct subchannel.
  469. * Return codes:
  470. * 0 on success
  471. * -ENXIO for non-defined subchannels
  472. * -ENODEV for invalid subchannels or blacklisted devices
  473. * -EIO for subchannels in an invalid subchannel set
  474. */
  475. int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
  476. {
  477. char dbf_txt[15];
  478. int ccode;
  479. int err;
  480. sprintf(dbf_txt, "valsch%x", schid.sch_no);
  481. CIO_TRACE_EVENT(4, dbf_txt);
  482. /* Nuke all fields. */
  483. memset(sch, 0, sizeof(struct subchannel));
  484. sch->schid = schid;
  485. if (cio_is_console(schid)) {
  486. sch->lock = cio_get_console_lock();
  487. } else {
  488. err = cio_create_sch_lock(sch);
  489. if (err)
  490. goto out;
  491. }
  492. mutex_init(&sch->reg_mutex);
  493. /*
  494. * The first subchannel that is not-operational (ccode==3)
  495. * indicates that there aren't any more devices available.
  496. * If stsch gets an exception, it means the current subchannel set
  497. * is not valid.
  498. */
  499. ccode = stsch_err (schid, &sch->schib);
  500. if (ccode) {
  501. err = (ccode == 3) ? -ENXIO : ccode;
  502. goto out;
  503. }
  504. /* Copy subchannel type from path management control word. */
  505. sch->st = sch->schib.pmcw.st;
  506. switch (sch->st) {
  507. case SUBCHANNEL_TYPE_IO:
  508. err = cio_validate_io_subchannel(sch);
  509. break;
  510. case SUBCHANNEL_TYPE_MSG:
  511. err = cio_validate_msg_subchannel(sch);
  512. break;
  513. default:
  514. err = 0;
  515. }
  516. if (err)
  517. goto out;
  518. CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
  519. sch->schid.ssid, sch->schid.sch_no, sch->st);
  520. return 0;
  521. out:
  522. if (!cio_is_console(schid))
  523. kfree(sch->lock);
  524. sch->lock = NULL;
  525. return err;
  526. }
  527. /*
  528. * do_IRQ() handles all normal I/O device IRQ's (the special
  529. * SMP cross-CPU interrupts have their own specific
  530. * handlers).
  531. *
  532. */
  533. void __irq_entry do_IRQ(struct pt_regs *regs)
  534. {
  535. struct tpi_info *tpi_info;
  536. struct subchannel *sch;
  537. struct irb *irb;
  538. struct pt_regs *old_regs;
  539. old_regs = set_irq_regs(regs);
  540. s390_idle_check();
  541. irq_enter();
  542. __get_cpu_var(s390_idle).nohz_delay = 1;
  543. if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
  544. /* Serve timer interrupts first. */
  545. clock_comparator_work();
  546. /*
  547. * Get interrupt information from lowcore
  548. */
  549. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  550. irb = (struct irb *) __LC_IRB;
  551. do {
  552. kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
  553. /*
  554. * Non I/O-subchannel thin interrupts are processed differently
  555. */
  556. if (tpi_info->adapter_IO == 1 &&
  557. tpi_info->int_type == IO_INTERRUPT_TYPE) {
  558. do_adapter_IO(tpi_info->isc);
  559. continue;
  560. }
  561. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  562. if (!sch) {
  563. /* Clear pending interrupt condition. */
  564. tsch(tpi_info->schid, irb);
  565. continue;
  566. }
  567. spin_lock(sch->lock);
  568. /* Store interrupt response block to lowcore. */
  569. if (tsch(tpi_info->schid, irb) == 0) {
  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);
  576. }
  577. spin_unlock(sch->lock);
  578. /*
  579. * Are more interrupts pending?
  580. * If so, the tpi instruction will update the lowcore
  581. * to hold the info for the next interrupt.
  582. * We don't do this for VM because a tpi drops the cpu
  583. * out of the sie which costs more cycles than it saves.
  584. */
  585. } while (!MACHINE_IS_VM && tpi (NULL) != 0);
  586. irq_exit();
  587. set_irq_regs(old_regs);
  588. }
  589. #ifdef CONFIG_CCW_CONSOLE
  590. static struct subchannel console_subchannel;
  591. static struct io_subchannel_private console_priv;
  592. static int console_subchannel_in_use;
  593. /*
  594. * Use tpi to get a pending interrupt, call the interrupt handler and
  595. * return a pointer to the subchannel structure.
  596. */
  597. static int cio_tpi(void)
  598. {
  599. struct tpi_info *tpi_info;
  600. struct subchannel *sch;
  601. struct irb *irb;
  602. int irq_context;
  603. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  604. if (tpi(NULL) != 1)
  605. return 0;
  606. irb = (struct irb *) __LC_IRB;
  607. /* Store interrupt response block to lowcore. */
  608. if (tsch(tpi_info->schid, irb) != 0)
  609. /* Not status pending or not operational. */
  610. return 1;
  611. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  612. if (!sch)
  613. return 1;
  614. irq_context = in_interrupt();
  615. if (!irq_context)
  616. local_bh_disable();
  617. irq_enter();
  618. spin_lock(sch->lock);
  619. memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
  620. if (sch->driver && sch->driver->irq)
  621. sch->driver->irq(sch);
  622. spin_unlock(sch->lock);
  623. irq_exit();
  624. if (!irq_context)
  625. _local_bh_enable();
  626. return 1;
  627. }
  628. void *cio_get_console_priv(void)
  629. {
  630. return &console_priv;
  631. }
  632. /*
  633. * busy wait for the next interrupt on the console
  634. */
  635. void wait_cons_dev(void)
  636. __releases(console_subchannel.lock)
  637. __acquires(console_subchannel.lock)
  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 the console isc */
  648. __ctl_store (save_cr6, 6, 6);
  649. cr6 = 1UL << (31 - CONSOLE_ISC);
  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.cmd.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. return -1;
  698. }
  699. return console_irq;
  700. }
  701. struct subchannel *
  702. cio_probe_console(void)
  703. {
  704. int sch_no, ret;
  705. struct subchannel_id schid;
  706. if (xchg(&console_subchannel_in_use, 1) != 0)
  707. return ERR_PTR(-EBUSY);
  708. sch_no = cio_get_console_sch_no();
  709. if (sch_no == -1) {
  710. console_subchannel_in_use = 0;
  711. pr_warning("No CCW console was found\n");
  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
  724. */
  725. isc_register(CONSOLE_ISC);
  726. console_subchannel.config.isc = CONSOLE_ISC;
  727. console_subchannel.config.intparm = (u32)(addr_t)&console_subchannel;
  728. ret = cio_commit_config(&console_subchannel);
  729. if (ret) {
  730. isc_unregister(CONSOLE_ISC);
  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.config.intparm = 0;
  740. cio_commit_config(&console_subchannel);
  741. isc_unregister(CONSOLE_ISC);
  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. if (stsch(schid, schib) || !css_sch_is_valid(schib))
  771. return -ENODEV;
  772. if (!schib->pmcw.ena)
  773. return 0;
  774. }
  775. return -EBUSY; /* uhm... */
  776. }
  777. static int
  778. __clear_io_subchannel_easy(struct subchannel_id schid)
  779. {
  780. int retry;
  781. if (csch(schid))
  782. return -ENODEV;
  783. for (retry=0;retry<20;retry++) {
  784. struct tpi_info ti;
  785. if (tpi(&ti)) {
  786. tsch(ti.schid, (struct irb *)__LC_IRB);
  787. if (schid_equal(&ti.schid, &schid))
  788. return 0;
  789. }
  790. udelay_simple(100);
  791. }
  792. return -EBUSY;
  793. }
  794. static void __clear_chsc_subchannel_easy(void)
  795. {
  796. /* It seems we can only wait for a bit here :/ */
  797. udelay_simple(100);
  798. }
  799. static int pgm_check_occured;
  800. static void cio_reset_pgm_check_handler(void)
  801. {
  802. pgm_check_occured = 1;
  803. }
  804. static int stsch_reset(struct subchannel_id schid, struct schib *addr)
  805. {
  806. int rc;
  807. pgm_check_occured = 0;
  808. s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
  809. rc = stsch(schid, addr);
  810. s390_base_pgm_handler_fn = NULL;
  811. /* The program check handler could have changed pgm_check_occured. */
  812. barrier();
  813. if (pgm_check_occured)
  814. return -EIO;
  815. else
  816. return rc;
  817. }
  818. static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
  819. {
  820. struct schib schib;
  821. if (stsch_reset(schid, &schib))
  822. return -ENXIO;
  823. if (!schib.pmcw.ena)
  824. return 0;
  825. switch(__disable_subchannel_easy(schid, &schib)) {
  826. case 0:
  827. case -ENODEV:
  828. break;
  829. default: /* -EBUSY */
  830. switch (schib.pmcw.st) {
  831. case SUBCHANNEL_TYPE_IO:
  832. if (__clear_io_subchannel_easy(schid))
  833. goto out; /* give up... */
  834. break;
  835. case SUBCHANNEL_TYPE_CHSC:
  836. __clear_chsc_subchannel_easy();
  837. break;
  838. default:
  839. /* No default clear strategy */
  840. break;
  841. }
  842. stsch(schid, &schib);
  843. __disable_subchannel_easy(schid, &schib);
  844. }
  845. out:
  846. return 0;
  847. }
  848. static atomic_t chpid_reset_count;
  849. static void s390_reset_chpids_mcck_handler(void)
  850. {
  851. struct crw crw;
  852. struct mci *mci;
  853. /* Check for pending channel report word. */
  854. mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
  855. if (!mci->cp)
  856. return;
  857. /* Process channel report words. */
  858. while (stcrw(&crw) == 0) {
  859. /* Check for responses to RCHP. */
  860. if (crw.slct && crw.rsc == CRW_RSC_CPATH)
  861. atomic_dec(&chpid_reset_count);
  862. }
  863. }
  864. #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
  865. static void css_reset(void)
  866. {
  867. int i, ret;
  868. unsigned long long timeout;
  869. struct chp_id chpid;
  870. /* Reset subchannels. */
  871. for_each_subchannel(__shutdown_subchannel_easy, NULL);
  872. /* Reset channel paths. */
  873. s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
  874. /* Enable channel report machine checks. */
  875. __ctl_set_bit(14, 28);
  876. /* Temporarily reenable machine checks. */
  877. local_mcck_enable();
  878. chp_id_init(&chpid);
  879. for (i = 0; i <= __MAX_CHPID; i++) {
  880. chpid.id = i;
  881. ret = rchp(chpid);
  882. if ((ret == 0) || (ret == 2))
  883. /*
  884. * rchp either succeeded, or another rchp is already
  885. * in progress. In either case, we'll get a crw.
  886. */
  887. atomic_inc(&chpid_reset_count);
  888. }
  889. /* Wait for machine check for all channel paths. */
  890. timeout = get_clock() + (RCHP_TIMEOUT << 12);
  891. while (atomic_read(&chpid_reset_count) != 0) {
  892. if (get_clock() > timeout)
  893. break;
  894. cpu_relax();
  895. }
  896. /* Disable machine checks again. */
  897. local_mcck_disable();
  898. /* Disable channel report machine checks. */
  899. __ctl_clear_bit(14, 28);
  900. s390_base_mcck_handler_fn = NULL;
  901. }
  902. static struct reset_call css_reset_call = {
  903. .fn = css_reset,
  904. };
  905. static int __init init_css_reset_call(void)
  906. {
  907. atomic_set(&chpid_reset_count, 0);
  908. register_reset_call(&css_reset_call);
  909. return 0;
  910. }
  911. arch_initcall(init_css_reset_call);
  912. struct sch_match_id {
  913. struct subchannel_id schid;
  914. struct ccw_dev_id devid;
  915. int rc;
  916. };
  917. static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
  918. {
  919. struct schib schib;
  920. struct sch_match_id *match_id = data;
  921. if (stsch_reset(schid, &schib))
  922. return -ENXIO;
  923. if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
  924. (schib.pmcw.dev == match_id->devid.devno) &&
  925. (schid.ssid == match_id->devid.ssid)) {
  926. match_id->schid = schid;
  927. match_id->rc = 0;
  928. return 1;
  929. }
  930. return 0;
  931. }
  932. static int reipl_find_schid(struct ccw_dev_id *devid,
  933. struct subchannel_id *schid)
  934. {
  935. struct sch_match_id match_id;
  936. match_id.devid = *devid;
  937. match_id.rc = -ENODEV;
  938. for_each_subchannel(__reipl_subchannel_match, &match_id);
  939. if (match_id.rc == 0)
  940. *schid = match_id.schid;
  941. return match_id.rc;
  942. }
  943. extern void do_reipl_asm(__u32 schid);
  944. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  945. void reipl_ccw_dev(struct ccw_dev_id *devid)
  946. {
  947. struct subchannel_id schid;
  948. s390_reset_system();
  949. if (reipl_find_schid(devid, &schid) != 0)
  950. panic("IPL Device not found\n");
  951. do_reipl_asm(*((__u32*)&schid));
  952. }
  953. int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
  954. {
  955. struct subchannel_id schid;
  956. struct schib schib;
  957. schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
  958. if (!schid.one)
  959. return -ENODEV;
  960. if (stsch(schid, &schib))
  961. return -ENODEV;
  962. if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
  963. return -ENODEV;
  964. if (!schib.pmcw.dnv)
  965. return -ENODEV;
  966. iplinfo->devno = schib.pmcw.dev;
  967. iplinfo->is_qdio = schib.pmcw.qf;
  968. return 0;
  969. }
  970. /**
  971. * cio_tm_start_key - perform start function
  972. * @sch: subchannel on which to perform the start function
  973. * @tcw: transport-command word to be started
  974. * @lpm: mask of paths to use
  975. * @key: storage key to use for storage access
  976. *
  977. * Start the tcw on the given subchannel. Return zero on success, non-zero
  978. * otherwise.
  979. */
  980. int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
  981. {
  982. int cc;
  983. union orb *orb = &to_io_private(sch)->orb;
  984. memset(orb, 0, sizeof(union orb));
  985. orb->tm.intparm = (u32) (addr_t) sch;
  986. orb->tm.key = key >> 4;
  987. orb->tm.b = 1;
  988. orb->tm.lpm = lpm ? lpm : sch->lpm;
  989. orb->tm.tcw = (u32) (addr_t) tcw;
  990. cc = ssch(sch->schid, orb);
  991. switch (cc) {
  992. case 0:
  993. return 0;
  994. case 1:
  995. case 2:
  996. return -EBUSY;
  997. default:
  998. return cio_start_handle_notoper(sch, lpm);
  999. }
  1000. }
  1001. /**
  1002. * cio_tm_intrg - perform interrogate function
  1003. * @sch - subchannel on which to perform the interrogate function
  1004. *
  1005. * If the specified subchannel is running in transport-mode, perform the
  1006. * interrogate function. Return zero on success, non-zero otherwie.
  1007. */
  1008. int cio_tm_intrg(struct subchannel *sch)
  1009. {
  1010. int cc;
  1011. if (!to_io_private(sch)->orb.tm.b)
  1012. return -EINVAL;
  1013. cc = xsch(sch->schid);
  1014. switch (cc) {
  1015. case 0:
  1016. case 2:
  1017. return 0;
  1018. case 1:
  1019. return -EBUSY;
  1020. default:
  1021. return -ENODEV;
  1022. }
  1023. }