cio.c 25 KB

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