cio.c 27 KB

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