cio.c 27 KB

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