cio.c 24 KB

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