cio.c 26 KB

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