cio.c 27 KB

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