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