cio.c 23 KB

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