cio.c 27 KB

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