cio.c 24 KB

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