cio.c 24 KB

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