cio.c 24 KB

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