cio.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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 ret;
  416. CIO_TRACE_EVENT (2, "dissch");
  417. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  418. if (sch_is_pseudo_sch(sch))
  419. return 0;
  420. if (cio_update_schib(sch))
  421. return -ENODEV;
  422. if (scsw_actl(&sch->schib.scsw) != 0)
  423. /*
  424. * the disable function must not be called while there are
  425. * requests pending for completion !
  426. */
  427. return -EBUSY;
  428. sch->config.ena = 0;
  429. ret = cio_commit_config(sch);
  430. sprintf (dbf_txt, "ret:%d", ret);
  431. CIO_TRACE_EVENT (2, dbf_txt);
  432. return ret;
  433. }
  434. EXPORT_SYMBOL_GPL(cio_disable_subchannel);
  435. int cio_create_sch_lock(struct subchannel *sch)
  436. {
  437. sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
  438. if (!sch->lock)
  439. return -ENOMEM;
  440. spin_lock_init(sch->lock);
  441. return 0;
  442. }
  443. static int cio_check_devno_blacklisted(struct subchannel *sch)
  444. {
  445. if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) {
  446. /*
  447. * This device must not be known to Linux. So we simply
  448. * say that there is no device and return ENODEV.
  449. */
  450. CIO_MSG_EVENT(6, "Blacklisted device detected "
  451. "at devno %04X, subchannel set %x\n",
  452. sch->schib.pmcw.dev, sch->schid.ssid);
  453. return -ENODEV;
  454. }
  455. return 0;
  456. }
  457. static int cio_validate_io_subchannel(struct subchannel *sch)
  458. {
  459. /* Initialization for io subchannels. */
  460. if (!css_sch_is_valid(&sch->schib))
  461. return -ENODEV;
  462. /* Devno is valid. */
  463. return cio_check_devno_blacklisted(sch);
  464. }
  465. static int cio_validate_msg_subchannel(struct subchannel *sch)
  466. {
  467. /* Initialization for message subchannels. */
  468. if (!css_sch_is_valid(&sch->schib))
  469. return -ENODEV;
  470. /* Devno is valid. */
  471. return cio_check_devno_blacklisted(sch);
  472. }
  473. /**
  474. * cio_validate_subchannel - basic validation of subchannel
  475. * @sch: subchannel structure to be filled out
  476. * @schid: subchannel id
  477. *
  478. * Find out subchannel type and initialize struct subchannel.
  479. * Return codes:
  480. * 0 on success
  481. * -ENXIO for non-defined subchannels
  482. * -ENODEV for invalid subchannels or blacklisted devices
  483. * -EIO for subchannels in an invalid subchannel set
  484. */
  485. int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
  486. {
  487. char dbf_txt[15];
  488. int ccode;
  489. int err;
  490. sprintf(dbf_txt, "valsch%x", schid.sch_no);
  491. CIO_TRACE_EVENT(4, dbf_txt);
  492. /* Nuke all fields. */
  493. memset(sch, 0, sizeof(struct subchannel));
  494. sch->schid = schid;
  495. if (cio_is_console(schid)) {
  496. sch->lock = cio_get_console_lock();
  497. } else {
  498. err = cio_create_sch_lock(sch);
  499. if (err)
  500. goto out;
  501. }
  502. mutex_init(&sch->reg_mutex);
  503. /* Set a name for the subchannel */
  504. if (cio_is_console(schid))
  505. sch->dev.init_name = cio_get_console_sch_name(schid);
  506. else
  507. dev_set_name(&sch->dev, "0.%x.%04x", schid.ssid, schid.sch_no);
  508. /*
  509. * The first subchannel that is not-operational (ccode==3)
  510. * indicates that there aren't any more devices available.
  511. * If stsch gets an exception, it means the current subchannel set
  512. * is not valid.
  513. */
  514. ccode = stsch_err (schid, &sch->schib);
  515. if (ccode) {
  516. err = (ccode == 3) ? -ENXIO : ccode;
  517. goto out;
  518. }
  519. /* Copy subchannel type from path management control word. */
  520. sch->st = sch->schib.pmcw.st;
  521. switch (sch->st) {
  522. case SUBCHANNEL_TYPE_IO:
  523. err = cio_validate_io_subchannel(sch);
  524. break;
  525. case SUBCHANNEL_TYPE_MSG:
  526. err = cio_validate_msg_subchannel(sch);
  527. break;
  528. default:
  529. err = 0;
  530. }
  531. if (err)
  532. goto out;
  533. CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
  534. sch->schid.ssid, sch->schid.sch_no, sch->st);
  535. return 0;
  536. out:
  537. if (!cio_is_console(schid))
  538. kfree(sch->lock);
  539. sch->lock = NULL;
  540. return err;
  541. }
  542. /*
  543. * do_IRQ() handles all normal I/O device IRQ's (the special
  544. * SMP cross-CPU interrupts have their own specific
  545. * handlers).
  546. *
  547. */
  548. void
  549. do_IRQ (struct pt_regs *regs)
  550. {
  551. struct tpi_info *tpi_info;
  552. struct subchannel *sch;
  553. struct irb *irb;
  554. struct pt_regs *old_regs;
  555. old_regs = set_irq_regs(regs);
  556. s390_idle_check();
  557. irq_enter();
  558. if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
  559. /* Serve timer interrupts first. */
  560. clock_comparator_work();
  561. /*
  562. * Get interrupt information from lowcore
  563. */
  564. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  565. irb = (struct irb *) __LC_IRB;
  566. do {
  567. kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
  568. /*
  569. * Non I/O-subchannel thin interrupts are processed differently
  570. */
  571. if (tpi_info->adapter_IO == 1 &&
  572. tpi_info->int_type == IO_INTERRUPT_TYPE) {
  573. do_adapter_IO(tpi_info->isc);
  574. continue;
  575. }
  576. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  577. if (!sch) {
  578. /* Clear pending interrupt condition. */
  579. tsch(tpi_info->schid, irb);
  580. continue;
  581. }
  582. spin_lock(sch->lock);
  583. /* Store interrupt response block to lowcore. */
  584. if (tsch(tpi_info->schid, irb) == 0) {
  585. /* Keep subchannel information word up to date. */
  586. memcpy (&sch->schib.scsw, &irb->scsw,
  587. sizeof (irb->scsw));
  588. /* Call interrupt handler if there is one. */
  589. if (sch->driver && sch->driver->irq)
  590. sch->driver->irq(sch);
  591. }
  592. spin_unlock(sch->lock);
  593. /*
  594. * Are more interrupts pending?
  595. * If so, the tpi instruction will update the lowcore
  596. * to hold the info for the next interrupt.
  597. * We don't do this for VM because a tpi drops the cpu
  598. * out of the sie which costs more cycles than it saves.
  599. */
  600. } while (!MACHINE_IS_VM && tpi (NULL) != 0);
  601. irq_exit();
  602. set_irq_regs(old_regs);
  603. }
  604. #ifdef CONFIG_CCW_CONSOLE
  605. static struct subchannel console_subchannel;
  606. static char console_sch_name[10] = "0.x.xxxx";
  607. static struct io_subchannel_private console_priv;
  608. static int console_subchannel_in_use;
  609. /*
  610. * Use tpi to get a pending interrupt, call the interrupt handler and
  611. * return a pointer to the subchannel structure.
  612. */
  613. static int cio_tpi(void)
  614. {
  615. struct tpi_info *tpi_info;
  616. struct subchannel *sch;
  617. struct irb *irb;
  618. int irq_context;
  619. tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
  620. if (tpi(NULL) != 1)
  621. return 0;
  622. irb = (struct irb *) __LC_IRB;
  623. /* Store interrupt response block to lowcore. */
  624. if (tsch(tpi_info->schid, irb) != 0)
  625. /* Not status pending or not operational. */
  626. return 1;
  627. sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
  628. if (!sch)
  629. return 1;
  630. irq_context = in_interrupt();
  631. if (!irq_context)
  632. local_bh_disable();
  633. irq_enter();
  634. spin_lock(sch->lock);
  635. memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
  636. if (sch->driver && sch->driver->irq)
  637. sch->driver->irq(sch);
  638. spin_unlock(sch->lock);
  639. irq_exit();
  640. if (!irq_context)
  641. _local_bh_enable();
  642. return 1;
  643. }
  644. void *cio_get_console_priv(void)
  645. {
  646. return &console_priv;
  647. }
  648. /*
  649. * busy wait for the next interrupt on the console
  650. */
  651. void wait_cons_dev(void)
  652. __releases(console_subchannel.lock)
  653. __acquires(console_subchannel.lock)
  654. {
  655. unsigned long cr6 __attribute__ ((aligned (8)));
  656. unsigned long save_cr6 __attribute__ ((aligned (8)));
  657. /*
  658. * before entering the spinlock we may already have
  659. * processed the interrupt on a different CPU...
  660. */
  661. if (!console_subchannel_in_use)
  662. return;
  663. /* disable all but the console isc */
  664. __ctl_store (save_cr6, 6, 6);
  665. cr6 = 1UL << (31 - CONSOLE_ISC);
  666. __ctl_load (cr6, 6, 6);
  667. do {
  668. spin_unlock(console_subchannel.lock);
  669. if (!cio_tpi())
  670. cpu_relax();
  671. spin_lock(console_subchannel.lock);
  672. } while (console_subchannel.schib.scsw.cmd.actl != 0);
  673. /*
  674. * restore previous isc value
  675. */
  676. __ctl_load (save_cr6, 6, 6);
  677. }
  678. static int
  679. cio_test_for_console(struct subchannel_id schid, void *data)
  680. {
  681. if (stsch_err(schid, &console_subchannel.schib) != 0)
  682. return -ENXIO;
  683. if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
  684. console_subchannel.schib.pmcw.dnv &&
  685. (console_subchannel.schib.pmcw.dev == console_devno)) {
  686. console_irq = schid.sch_no;
  687. return 1; /* found */
  688. }
  689. return 0;
  690. }
  691. static int
  692. cio_get_console_sch_no(void)
  693. {
  694. struct subchannel_id schid;
  695. init_subchannel_id(&schid);
  696. if (console_irq != -1) {
  697. /* VM provided us with the irq number of the console. */
  698. schid.sch_no = console_irq;
  699. if (stsch(schid, &console_subchannel.schib) != 0 ||
  700. (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
  701. !console_subchannel.schib.pmcw.dnv)
  702. return -1;
  703. console_devno = console_subchannel.schib.pmcw.dev;
  704. } else if (console_devno != -1) {
  705. /* At least the console device number is known. */
  706. for_each_subchannel(cio_test_for_console, NULL);
  707. if (console_irq == -1)
  708. return -1;
  709. } else {
  710. /* unlike in 2.4, we cannot autoprobe here, since
  711. * the channel subsystem is not fully initialized.
  712. * With some luck, the HWC console can take over */
  713. return -1;
  714. }
  715. return console_irq;
  716. }
  717. struct subchannel *
  718. cio_probe_console(void)
  719. {
  720. int sch_no, ret;
  721. struct subchannel_id schid;
  722. if (xchg(&console_subchannel_in_use, 1) != 0)
  723. return ERR_PTR(-EBUSY);
  724. sch_no = cio_get_console_sch_no();
  725. if (sch_no == -1) {
  726. console_subchannel_in_use = 0;
  727. pr_warning("No CCW console was found\n");
  728. return ERR_PTR(-ENODEV);
  729. }
  730. memset(&console_subchannel, 0, sizeof(struct subchannel));
  731. init_subchannel_id(&schid);
  732. schid.sch_no = sch_no;
  733. ret = cio_validate_subchannel(&console_subchannel, schid);
  734. if (ret) {
  735. console_subchannel_in_use = 0;
  736. return ERR_PTR(-ENODEV);
  737. }
  738. /*
  739. * enable console I/O-interrupt subclass
  740. */
  741. isc_register(CONSOLE_ISC);
  742. console_subchannel.config.isc = CONSOLE_ISC;
  743. console_subchannel.config.intparm = (u32)(addr_t)&console_subchannel;
  744. ret = cio_commit_config(&console_subchannel);
  745. if (ret) {
  746. isc_unregister(CONSOLE_ISC);
  747. console_subchannel_in_use = 0;
  748. return ERR_PTR(ret);
  749. }
  750. return &console_subchannel;
  751. }
  752. void
  753. cio_release_console(void)
  754. {
  755. console_subchannel.config.intparm = 0;
  756. cio_commit_config(&console_subchannel);
  757. isc_unregister(CONSOLE_ISC);
  758. console_subchannel_in_use = 0;
  759. }
  760. /* Bah... hack to catch console special sausages. */
  761. int
  762. cio_is_console(struct subchannel_id schid)
  763. {
  764. if (!console_subchannel_in_use)
  765. return 0;
  766. return schid_equal(&schid, &console_subchannel.schid);
  767. }
  768. struct subchannel *
  769. cio_get_console_subchannel(void)
  770. {
  771. if (!console_subchannel_in_use)
  772. return NULL;
  773. return &console_subchannel;
  774. }
  775. const char *cio_get_console_sch_name(struct subchannel_id schid)
  776. {
  777. snprintf(console_sch_name, 10, "0.%x.%04x", schid.ssid, schid.sch_no);
  778. return (const char *)console_sch_name;
  779. }
  780. #endif
  781. static int
  782. __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
  783. {
  784. int retry, cc;
  785. cc = 0;
  786. for (retry=0;retry<3;retry++) {
  787. schib->pmcw.ena = 0;
  788. cc = msch(schid, schib);
  789. if (cc)
  790. return (cc==3?-ENODEV:-EBUSY);
  791. if (stsch(schid, schib) || !css_sch_is_valid(schib))
  792. return -ENODEV;
  793. if (!schib->pmcw.ena)
  794. return 0;
  795. }
  796. return -EBUSY; /* uhm... */
  797. }
  798. static int
  799. __clear_io_subchannel_easy(struct subchannel_id schid)
  800. {
  801. int retry;
  802. if (csch(schid))
  803. return -ENODEV;
  804. for (retry=0;retry<20;retry++) {
  805. struct tpi_info ti;
  806. if (tpi(&ti)) {
  807. tsch(ti.schid, (struct irb *)__LC_IRB);
  808. if (schid_equal(&ti.schid, &schid))
  809. return 0;
  810. }
  811. udelay_simple(100);
  812. }
  813. return -EBUSY;
  814. }
  815. static void __clear_chsc_subchannel_easy(void)
  816. {
  817. /* It seems we can only wait for a bit here :/ */
  818. udelay_simple(100);
  819. }
  820. static int pgm_check_occured;
  821. static void cio_reset_pgm_check_handler(void)
  822. {
  823. pgm_check_occured = 1;
  824. }
  825. static int stsch_reset(struct subchannel_id schid, struct schib *addr)
  826. {
  827. int rc;
  828. pgm_check_occured = 0;
  829. s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
  830. rc = stsch(schid, addr);
  831. s390_base_pgm_handler_fn = NULL;
  832. /* The program check handler could have changed pgm_check_occured. */
  833. barrier();
  834. if (pgm_check_occured)
  835. return -EIO;
  836. else
  837. return rc;
  838. }
  839. static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
  840. {
  841. struct schib schib;
  842. if (stsch_reset(schid, &schib))
  843. return -ENXIO;
  844. if (!schib.pmcw.ena)
  845. return 0;
  846. switch(__disable_subchannel_easy(schid, &schib)) {
  847. case 0:
  848. case -ENODEV:
  849. break;
  850. default: /* -EBUSY */
  851. switch (schib.pmcw.st) {
  852. case SUBCHANNEL_TYPE_IO:
  853. if (__clear_io_subchannel_easy(schid))
  854. goto out; /* give up... */
  855. break;
  856. case SUBCHANNEL_TYPE_CHSC:
  857. __clear_chsc_subchannel_easy();
  858. break;
  859. default:
  860. /* No default clear strategy */
  861. break;
  862. }
  863. stsch(schid, &schib);
  864. __disable_subchannel_easy(schid, &schib);
  865. }
  866. out:
  867. return 0;
  868. }
  869. static atomic_t chpid_reset_count;
  870. static void s390_reset_chpids_mcck_handler(void)
  871. {
  872. struct crw crw;
  873. struct mci *mci;
  874. /* Check for pending channel report word. */
  875. mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
  876. if (!mci->cp)
  877. return;
  878. /* Process channel report words. */
  879. while (stcrw(&crw) == 0) {
  880. /* Check for responses to RCHP. */
  881. if (crw.slct && crw.rsc == CRW_RSC_CPATH)
  882. atomic_dec(&chpid_reset_count);
  883. }
  884. }
  885. #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
  886. static void css_reset(void)
  887. {
  888. int i, ret;
  889. unsigned long long timeout;
  890. struct chp_id chpid;
  891. /* Reset subchannels. */
  892. for_each_subchannel(__shutdown_subchannel_easy, NULL);
  893. /* Reset channel paths. */
  894. s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
  895. /* Enable channel report machine checks. */
  896. __ctl_set_bit(14, 28);
  897. /* Temporarily reenable machine checks. */
  898. local_mcck_enable();
  899. chp_id_init(&chpid);
  900. for (i = 0; i <= __MAX_CHPID; i++) {
  901. chpid.id = i;
  902. ret = rchp(chpid);
  903. if ((ret == 0) || (ret == 2))
  904. /*
  905. * rchp either succeeded, or another rchp is already
  906. * in progress. In either case, we'll get a crw.
  907. */
  908. atomic_inc(&chpid_reset_count);
  909. }
  910. /* Wait for machine check for all channel paths. */
  911. timeout = get_clock() + (RCHP_TIMEOUT << 12);
  912. while (atomic_read(&chpid_reset_count) != 0) {
  913. if (get_clock() > timeout)
  914. break;
  915. cpu_relax();
  916. }
  917. /* Disable machine checks again. */
  918. local_mcck_disable();
  919. /* Disable channel report machine checks. */
  920. __ctl_clear_bit(14, 28);
  921. s390_base_mcck_handler_fn = NULL;
  922. }
  923. static struct reset_call css_reset_call = {
  924. .fn = css_reset,
  925. };
  926. static int __init init_css_reset_call(void)
  927. {
  928. atomic_set(&chpid_reset_count, 0);
  929. register_reset_call(&css_reset_call);
  930. return 0;
  931. }
  932. arch_initcall(init_css_reset_call);
  933. struct sch_match_id {
  934. struct subchannel_id schid;
  935. struct ccw_dev_id devid;
  936. int rc;
  937. };
  938. static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
  939. {
  940. struct schib schib;
  941. struct sch_match_id *match_id = data;
  942. if (stsch_reset(schid, &schib))
  943. return -ENXIO;
  944. if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
  945. (schib.pmcw.dev == match_id->devid.devno) &&
  946. (schid.ssid == match_id->devid.ssid)) {
  947. match_id->schid = schid;
  948. match_id->rc = 0;
  949. return 1;
  950. }
  951. return 0;
  952. }
  953. static int reipl_find_schid(struct ccw_dev_id *devid,
  954. struct subchannel_id *schid)
  955. {
  956. struct sch_match_id match_id;
  957. match_id.devid = *devid;
  958. match_id.rc = -ENODEV;
  959. for_each_subchannel(__reipl_subchannel_match, &match_id);
  960. if (match_id.rc == 0)
  961. *schid = match_id.schid;
  962. return match_id.rc;
  963. }
  964. extern void do_reipl_asm(__u32 schid);
  965. /* Make sure all subchannels are quiet before we re-ipl an lpar. */
  966. void reipl_ccw_dev(struct ccw_dev_id *devid)
  967. {
  968. struct subchannel_id schid;
  969. s390_reset_system();
  970. if (reipl_find_schid(devid, &schid) != 0)
  971. panic("IPL Device not found\n");
  972. do_reipl_asm(*((__u32*)&schid));
  973. }
  974. int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
  975. {
  976. struct subchannel_id schid;
  977. struct schib schib;
  978. schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
  979. if (!schid.one)
  980. return -ENODEV;
  981. if (stsch(schid, &schib))
  982. return -ENODEV;
  983. if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
  984. return -ENODEV;
  985. if (!schib.pmcw.dnv)
  986. return -ENODEV;
  987. iplinfo->devno = schib.pmcw.dev;
  988. iplinfo->is_qdio = schib.pmcw.qf;
  989. return 0;
  990. }
  991. /**
  992. * cio_tm_start_key - perform start function
  993. * @sch: subchannel on which to perform the start function
  994. * @tcw: transport-command word to be started
  995. * @lpm: mask of paths to use
  996. * @key: storage key to use for storage access
  997. *
  998. * Start the tcw on the given subchannel. Return zero on success, non-zero
  999. * otherwise.
  1000. */
  1001. int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
  1002. {
  1003. int cc;
  1004. union orb *orb = &to_io_private(sch)->orb;
  1005. memset(orb, 0, sizeof(union orb));
  1006. orb->tm.intparm = (u32) (addr_t) sch;
  1007. orb->tm.key = key >> 4;
  1008. orb->tm.b = 1;
  1009. orb->tm.lpm = lpm ? lpm : sch->lpm;
  1010. orb->tm.tcw = (u32) (addr_t) tcw;
  1011. cc = ssch(sch->schid, orb);
  1012. switch (cc) {
  1013. case 0:
  1014. return 0;
  1015. case 1:
  1016. case 2:
  1017. return -EBUSY;
  1018. default:
  1019. return cio_start_handle_notoper(sch, lpm);
  1020. }
  1021. }
  1022. /**
  1023. * cio_tm_intrg - perform interrogate function
  1024. * @sch - subchannel on which to perform the interrogate function
  1025. *
  1026. * If the specified subchannel is running in transport-mode, perform the
  1027. * interrogate function. Return zero on success, non-zero otherwie.
  1028. */
  1029. int cio_tm_intrg(struct subchannel *sch)
  1030. {
  1031. int cc;
  1032. if (!to_io_private(sch)->orb.tm.b)
  1033. return -EINVAL;
  1034. cc = xsch(sch->schid);
  1035. switch (cc) {
  1036. case 0:
  1037. case 2:
  1038. return 0;
  1039. case 1:
  1040. return -EBUSY;
  1041. default:
  1042. return -ENODEV;
  1043. }
  1044. }