cio.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * S/390 common I/O routines -- low level i/o calls
  4. *
  5. * Copyright IBM Corp. 1999, 2008
  6. * Author(s): Ingo Adlung ([email protected])
  7. * Cornelia Huck ([email protected])
  8. * Arnd Bergmann ([email protected])
  9. * Martin Schwidefsky ([email protected])
  10. */
  11. #define KMSG_COMPONENT "cio"
  12. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  13. #include <linux/ftrace.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/slab.h>
  17. #include <linux/device.h>
  18. #include <linux/kernel_stat.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/irq.h>
  21. #include <asm/cio.h>
  22. #include <asm/delay.h>
  23. #include <asm/irq.h>
  24. #include <asm/irq_regs.h>
  25. #include <asm/setup.h>
  26. #include <asm/ipl.h>
  27. #include <asm/chpid.h>
  28. #include <asm/airq.h>
  29. #include <asm/isc.h>
  30. #include <linux/sched/cputime.h>
  31. #include <asm/fcx.h>
  32. #include <asm/nmi.h>
  33. #include <asm/crw.h>
  34. #include "cio.h"
  35. #include "css.h"
  36. #include "chsc.h"
  37. #include "ioasm.h"
  38. #include "io_sch.h"
  39. #include "blacklist.h"
  40. #include "cio_debug.h"
  41. #include "chp.h"
  42. #include "trace.h"
  43. debug_info_t *cio_debug_msg_id;
  44. debug_info_t *cio_debug_trace_id;
  45. debug_info_t *cio_debug_crw_id;
  46. DEFINE_PER_CPU_ALIGNED(struct irb, cio_irb);
  47. EXPORT_PER_CPU_SYMBOL(cio_irb);
  48. /*
  49. * Function: cio_debug_init
  50. * Initializes three debug logs for common I/O:
  51. * - cio_msg logs generic cio messages
  52. * - cio_trace logs the calling of different functions
  53. * - cio_crw logs machine check related cio messages
  54. */
  55. static int __init cio_debug_init(void)
  56. {
  57. cio_debug_msg_id = debug_register("cio_msg", 16, 1, 11 * sizeof(long));
  58. if (!cio_debug_msg_id)
  59. goto out_unregister;
  60. debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
  61. debug_set_level(cio_debug_msg_id, 2);
  62. cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
  63. if (!cio_debug_trace_id)
  64. goto out_unregister;
  65. debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
  66. debug_set_level(cio_debug_trace_id, 2);
  67. cio_debug_crw_id = debug_register("cio_crw", 8, 1, 8 * sizeof(long));
  68. if (!cio_debug_crw_id)
  69. goto out_unregister;
  70. debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
  71. debug_set_level(cio_debug_crw_id, 4);
  72. return 0;
  73. out_unregister:
  74. debug_unregister(cio_debug_msg_id);
  75. debug_unregister(cio_debug_trace_id);
  76. debug_unregister(cio_debug_crw_id);
  77. return -1;
  78. }
  79. arch_initcall (cio_debug_init);
  80. int cio_set_options(struct subchannel *sch, int flags)
  81. {
  82. struct io_subchannel_private *priv = to_io_private(sch);
  83. priv->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
  84. priv->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
  85. priv->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
  86. return 0;
  87. }
  88. static int
  89. cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
  90. {
  91. char dbf_text[15];
  92. if (lpm != 0)
  93. sch->lpm &= ~lpm;
  94. else
  95. sch->lpm = 0;
  96. CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
  97. "subchannel 0.%x.%04x!\n", sch->schid.ssid,
  98. sch->schid.sch_no);
  99. if (cio_update_schib(sch))
  100. return -ENODEV;
  101. sprintf(dbf_text, "no%s", dev_name(&sch->dev));
  102. CIO_TRACE_EVENT(0, dbf_text);
  103. CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
  104. return (sch->lpm ? -EACCES : -ENODEV);
  105. }
  106. int
  107. cio_start_key (struct subchannel *sch, /* subchannel structure */
  108. struct ccw1 * cpa, /* logical channel prog addr */
  109. __u8 lpm, /* logical path mask */
  110. __u8 key) /* storage key */
  111. {
  112. struct io_subchannel_private *priv = to_io_private(sch);
  113. union orb *orb = &priv->orb;
  114. int ccode;
  115. CIO_TRACE_EVENT(5, "stIO");
  116. CIO_TRACE_EVENT(5, dev_name(&sch->dev));
  117. memset(orb, 0, sizeof(union orb));
  118. /* sch is always under 2G. */
  119. orb->cmd.intparm = (u32)(addr_t)sch;
  120. orb->cmd.fmt = 1;
  121. orb->cmd.pfch = priv->options.prefetch == 0;
  122. orb->cmd.spnd = priv->options.suspend;
  123. orb->cmd.ssic = priv->options.suspend && priv->options.inter;
  124. orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm;
  125. /*
  126. * for 64 bit we always support 64 bit IDAWs with 4k page size only
  127. */
  128. orb->cmd.c64 = 1;
  129. orb->cmd.i2k = 0;
  130. orb->cmd.key = key >> 4;
  131. /* issue "Start Subchannel" */
  132. orb->cmd.cpa = (__u32) __pa(cpa);
  133. ccode = ssch(sch->schid, orb);
  134. /* process condition code */
  135. CIO_HEX_EVENT(5, &ccode, sizeof(ccode));
  136. switch (ccode) {
  137. case 0:
  138. /*
  139. * initialize device status information
  140. */
  141. sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
  142. return 0;
  143. case 1: /* status pending */
  144. case 2: /* busy */
  145. return -EBUSY;
  146. case 3: /* device/path not operational */
  147. return cio_start_handle_notoper(sch, lpm);
  148. default:
  149. return ccode;
  150. }
  151. }
  152. EXPORT_SYMBOL_GPL(cio_start_key);
  153. int
  154. cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
  155. {
  156. return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
  157. }
  158. EXPORT_SYMBOL_GPL(cio_start);
  159. /*
  160. * resume suspended I/O operation
  161. */
  162. int
  163. cio_resume (struct subchannel *sch)
  164. {
  165. int ccode;
  166. CIO_TRACE_EVENT(4, "resIO");
  167. CIO_TRACE_EVENT(4, dev_name(&sch->dev));
  168. ccode = rsch (sch->schid);
  169. CIO_HEX_EVENT(4, &ccode, sizeof(ccode));
  170. switch (ccode) {
  171. case 0:
  172. sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND;
  173. return 0;
  174. case 1:
  175. return -EBUSY;
  176. case 2:
  177. return -EINVAL;
  178. default:
  179. /*
  180. * useless to wait for request completion
  181. * as device is no longer operational !
  182. */
  183. return -ENODEV;
  184. }
  185. }
  186. EXPORT_SYMBOL_GPL(cio_resume);
  187. /*
  188. * halt I/O operation
  189. */
  190. int
  191. cio_halt(struct subchannel *sch)
  192. {
  193. int ccode;
  194. if (!sch)
  195. return -ENODEV;
  196. CIO_TRACE_EVENT(2, "haltIO");
  197. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  198. /*
  199. * Issue "Halt subchannel" and process condition code
  200. */
  201. ccode = hsch (sch->schid);
  202. CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
  203. switch (ccode) {
  204. case 0:
  205. sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND;
  206. return 0;
  207. case 1: /* status pending */
  208. case 2: /* busy */
  209. return -EBUSY;
  210. default: /* device not operational */
  211. return -ENODEV;
  212. }
  213. }
  214. EXPORT_SYMBOL_GPL(cio_halt);
  215. /*
  216. * Clear I/O operation
  217. */
  218. int
  219. cio_clear(struct subchannel *sch)
  220. {
  221. int ccode;
  222. if (!sch)
  223. return -ENODEV;
  224. CIO_TRACE_EVENT(2, "clearIO");
  225. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  226. /*
  227. * Issue "Clear subchannel" and process condition code
  228. */
  229. ccode = csch (sch->schid);
  230. CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
  231. switch (ccode) {
  232. case 0:
  233. sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND;
  234. return 0;
  235. default: /* device not operational */
  236. return -ENODEV;
  237. }
  238. }
  239. EXPORT_SYMBOL_GPL(cio_clear);
  240. /*
  241. * Function: cio_cancel
  242. * Issues a "Cancel Subchannel" on the specified subchannel
  243. * Note: We don't need any fancy intparms and flags here
  244. * since xsch is executed synchronously.
  245. * Only for common I/O internal use as for now.
  246. */
  247. int
  248. cio_cancel (struct subchannel *sch)
  249. {
  250. int ccode;
  251. if (!sch)
  252. return -ENODEV;
  253. CIO_TRACE_EVENT(2, "cancelIO");
  254. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  255. ccode = xsch (sch->schid);
  256. CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
  257. switch (ccode) {
  258. case 0: /* success */
  259. /* Update information in scsw. */
  260. if (cio_update_schib(sch))
  261. return -ENODEV;
  262. return 0;
  263. case 1: /* status pending */
  264. return -EBUSY;
  265. case 2: /* not applicable */
  266. return -EINVAL;
  267. default: /* not oper */
  268. return -ENODEV;
  269. }
  270. }
  271. EXPORT_SYMBOL_GPL(cio_cancel);
  272. /**
  273. * cio_cancel_halt_clear - Cancel running I/O by performing cancel, halt
  274. * and clear ordinally if subchannel is valid.
  275. * @sch: subchannel on which to perform the cancel_halt_clear operation
  276. * @iretry: the number of the times remained to retry the next operation
  277. *
  278. * This should be called repeatedly since halt/clear are asynchronous
  279. * operations. We do one try with cio_cancel, three tries with cio_halt,
  280. * 255 tries with cio_clear. The caller should initialize @iretry with
  281. * the value 255 for its first call to this, and keep using the same
  282. * @iretry in the subsequent calls until it gets a non -EBUSY return.
  283. *
  284. * Returns 0 if device now idle, -ENODEV for device not operational,
  285. * -EBUSY if an interrupt is expected (either from halt/clear or from a
  286. * status pending), and -EIO if out of retries.
  287. */
  288. int cio_cancel_halt_clear(struct subchannel *sch, int *iretry)
  289. {
  290. int ret;
  291. if (cio_update_schib(sch))
  292. return -ENODEV;
  293. if (!sch->schib.pmcw.ena)
  294. /* Not operational -> done. */
  295. return 0;
  296. /* Stage 1: cancel io. */
  297. if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_HALT_PEND) &&
  298. !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
  299. if (!scsw_is_tm(&sch->schib.scsw)) {
  300. ret = cio_cancel(sch);
  301. if (ret != -EINVAL)
  302. return ret;
  303. }
  304. /*
  305. * Cancel io unsuccessful or not applicable (transport mode).
  306. * Continue with asynchronous instructions.
  307. */
  308. *iretry = 3; /* 3 halt retries. */
  309. }
  310. /* Stage 2: halt io. */
  311. if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
  312. if (*iretry) {
  313. *iretry -= 1;
  314. ret = cio_halt(sch);
  315. if (ret != -EBUSY)
  316. return (ret == 0) ? -EBUSY : ret;
  317. }
  318. /* Halt io unsuccessful. */
  319. *iretry = 255; /* 255 clear retries. */
  320. }
  321. /* Stage 3: clear io. */
  322. if (*iretry) {
  323. *iretry -= 1;
  324. ret = cio_clear(sch);
  325. return (ret == 0) ? -EBUSY : ret;
  326. }
  327. /* Function was unsuccessful */
  328. return -EIO;
  329. }
  330. EXPORT_SYMBOL_GPL(cio_cancel_halt_clear);
  331. static void cio_apply_config(struct subchannel *sch, struct schib *schib)
  332. {
  333. schib->pmcw.intparm = sch->config.intparm;
  334. schib->pmcw.mbi = sch->config.mbi;
  335. schib->pmcw.isc = sch->config.isc;
  336. schib->pmcw.ena = sch->config.ena;
  337. schib->pmcw.mme = sch->config.mme;
  338. schib->pmcw.mp = sch->config.mp;
  339. schib->pmcw.csense = sch->config.csense;
  340. schib->pmcw.mbfc = sch->config.mbfc;
  341. if (sch->config.mbfc)
  342. schib->mba = sch->config.mba;
  343. }
  344. static int cio_check_config(struct subchannel *sch, struct schib *schib)
  345. {
  346. return (schib->pmcw.intparm == sch->config.intparm) &&
  347. (schib->pmcw.mbi == sch->config.mbi) &&
  348. (schib->pmcw.isc == sch->config.isc) &&
  349. (schib->pmcw.ena == sch->config.ena) &&
  350. (schib->pmcw.mme == sch->config.mme) &&
  351. (schib->pmcw.mp == sch->config.mp) &&
  352. (schib->pmcw.csense == sch->config.csense) &&
  353. (schib->pmcw.mbfc == sch->config.mbfc) &&
  354. (!sch->config.mbfc || (schib->mba == sch->config.mba));
  355. }
  356. /*
  357. * cio_commit_config - apply configuration to the subchannel
  358. */
  359. int cio_commit_config(struct subchannel *sch)
  360. {
  361. int ccode, retry, ret = 0;
  362. struct schib schib;
  363. struct irb irb;
  364. if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
  365. return -ENODEV;
  366. for (retry = 0; retry < 5; retry++) {
  367. /* copy desired changes to local schib */
  368. cio_apply_config(sch, &schib);
  369. ccode = msch(sch->schid, &schib);
  370. if (ccode < 0) /* -EIO if msch gets a program check. */
  371. return ccode;
  372. switch (ccode) {
  373. case 0: /* successful */
  374. if (stsch(sch->schid, &schib) ||
  375. !css_sch_is_valid(&schib))
  376. return -ENODEV;
  377. if (cio_check_config(sch, &schib)) {
  378. /* commit changes from local schib */
  379. memcpy(&sch->schib, &schib, sizeof(schib));
  380. return 0;
  381. }
  382. ret = -EAGAIN;
  383. break;
  384. case 1: /* status pending */
  385. ret = -EBUSY;
  386. if (tsch(sch->schid, &irb))
  387. return ret;
  388. break;
  389. case 2: /* busy */
  390. udelay(100); /* allow for recovery */
  391. ret = -EBUSY;
  392. break;
  393. case 3: /* not operational */
  394. return -ENODEV;
  395. }
  396. }
  397. return ret;
  398. }
  399. EXPORT_SYMBOL_GPL(cio_commit_config);
  400. /**
  401. * cio_update_schib - Perform stsch and update schib if subchannel is valid.
  402. * @sch: subchannel on which to perform stsch
  403. * Return zero on success, -ENODEV otherwise.
  404. */
  405. int cio_update_schib(struct subchannel *sch)
  406. {
  407. struct schib schib;
  408. if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
  409. return -ENODEV;
  410. memcpy(&sch->schib, &schib, sizeof(schib));
  411. return 0;
  412. }
  413. EXPORT_SYMBOL_GPL(cio_update_schib);
  414. /**
  415. * cio_enable_subchannel - enable a subchannel.
  416. * @sch: subchannel to be enabled
  417. * @intparm: interruption parameter to set
  418. */
  419. int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
  420. {
  421. int ret;
  422. CIO_TRACE_EVENT(2, "ensch");
  423. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  424. if (sch_is_pseudo_sch(sch))
  425. return -EINVAL;
  426. if (cio_update_schib(sch))
  427. return -ENODEV;
  428. sch->config.ena = 1;
  429. sch->config.isc = sch->isc;
  430. sch->config.intparm = intparm;
  431. ret = cio_commit_config(sch);
  432. if (ret == -EIO) {
  433. /*
  434. * Got a program check in msch. Try without
  435. * the concurrent sense bit the next time.
  436. */
  437. sch->config.csense = 0;
  438. ret = cio_commit_config(sch);
  439. }
  440. CIO_HEX_EVENT(2, &ret, sizeof(ret));
  441. return ret;
  442. }
  443. EXPORT_SYMBOL_GPL(cio_enable_subchannel);
  444. /**
  445. * cio_disable_subchannel - disable a subchannel.
  446. * @sch: subchannel to disable
  447. */
  448. int cio_disable_subchannel(struct subchannel *sch)
  449. {
  450. int ret;
  451. CIO_TRACE_EVENT(2, "dissch");
  452. CIO_TRACE_EVENT(2, dev_name(&sch->dev));
  453. if (sch_is_pseudo_sch(sch))
  454. return 0;
  455. if (cio_update_schib(sch))
  456. return -ENODEV;
  457. sch->config.ena = 0;
  458. ret = cio_commit_config(sch);
  459. CIO_HEX_EVENT(2, &ret, sizeof(ret));
  460. return ret;
  461. }
  462. EXPORT_SYMBOL_GPL(cio_disable_subchannel);
  463. /*
  464. * do_cio_interrupt() handles all normal I/O device IRQ's
  465. */
  466. static irqreturn_t do_cio_interrupt(int irq, void *dummy)
  467. {
  468. struct tpi_info *tpi_info;
  469. struct subchannel *sch;
  470. struct irb *irb;
  471. set_cpu_flag(CIF_NOHZ_DELAY);
  472. tpi_info = &get_irq_regs()->tpi_info;
  473. trace_s390_cio_interrupt(tpi_info);
  474. irb = this_cpu_ptr(&cio_irb);
  475. sch = (struct subchannel *)(unsigned long) tpi_info->intparm;
  476. if (!sch) {
  477. /* Clear pending interrupt condition. */
  478. inc_irq_stat(IRQIO_CIO);
  479. tsch(tpi_info->schid, irb);
  480. return IRQ_HANDLED;
  481. }
  482. spin_lock(sch->lock);
  483. /* Store interrupt response block to lowcore. */
  484. if (tsch(tpi_info->schid, irb) == 0) {
  485. /* Keep subchannel information word up to date. */
  486. memcpy (&sch->schib.scsw, &irb->scsw, sizeof (irb->scsw));
  487. /* Call interrupt handler if there is one. */
  488. if (sch->driver && sch->driver->irq)
  489. sch->driver->irq(sch);
  490. else
  491. inc_irq_stat(IRQIO_CIO);
  492. } else
  493. inc_irq_stat(IRQIO_CIO);
  494. spin_unlock(sch->lock);
  495. return IRQ_HANDLED;
  496. }
  497. void __init init_cio_interrupts(void)
  498. {
  499. irq_set_chip_and_handler(IO_INTERRUPT,
  500. &dummy_irq_chip, handle_percpu_irq);
  501. if (request_irq(IO_INTERRUPT, do_cio_interrupt, 0, "I/O", NULL))
  502. panic("Failed to register I/O interrupt\n");
  503. }
  504. #ifdef CONFIG_CCW_CONSOLE
  505. static struct subchannel *console_sch;
  506. static struct lock_class_key console_sch_key;
  507. /*
  508. * Use cio_tsch to update the subchannel status and call the interrupt handler
  509. * if status had been pending. Called with the subchannel's lock held.
  510. */
  511. void cio_tsch(struct subchannel *sch)
  512. {
  513. struct irb *irb;
  514. int irq_context;
  515. irb = this_cpu_ptr(&cio_irb);
  516. /* Store interrupt response block to lowcore. */
  517. if (tsch(sch->schid, irb) != 0)
  518. /* Not status pending or not operational. */
  519. return;
  520. memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
  521. /* Call interrupt handler with updated status. */
  522. irq_context = in_interrupt();
  523. if (!irq_context) {
  524. local_bh_disable();
  525. irq_enter();
  526. }
  527. kstat_incr_irq_this_cpu(IO_INTERRUPT);
  528. if (sch->driver && sch->driver->irq)
  529. sch->driver->irq(sch);
  530. else
  531. inc_irq_stat(IRQIO_CIO);
  532. if (!irq_context) {
  533. irq_exit();
  534. _local_bh_enable();
  535. }
  536. }
  537. static int cio_test_for_console(struct subchannel_id schid, void *data)
  538. {
  539. struct schib schib;
  540. if (stsch(schid, &schib) != 0)
  541. return -ENXIO;
  542. if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
  543. (schib.pmcw.dev == console_devno)) {
  544. console_irq = schid.sch_no;
  545. return 1; /* found */
  546. }
  547. return 0;
  548. }
  549. static int cio_get_console_sch_no(void)
  550. {
  551. struct subchannel_id schid;
  552. struct schib schib;
  553. init_subchannel_id(&schid);
  554. if (console_irq != -1) {
  555. /* VM provided us with the irq number of the console. */
  556. schid.sch_no = console_irq;
  557. if (stsch(schid, &schib) != 0 ||
  558. (schib.pmcw.st != SUBCHANNEL_TYPE_IO) || !schib.pmcw.dnv)
  559. return -1;
  560. console_devno = schib.pmcw.dev;
  561. } else if (console_devno != -1) {
  562. /* At least the console device number is known. */
  563. for_each_subchannel(cio_test_for_console, NULL);
  564. }
  565. return console_irq;
  566. }
  567. struct subchannel *cio_probe_console(void)
  568. {
  569. struct subchannel_id schid;
  570. struct subchannel *sch;
  571. struct schib schib;
  572. int sch_no, ret;
  573. sch_no = cio_get_console_sch_no();
  574. if (sch_no == -1) {
  575. pr_warn("No CCW console was found\n");
  576. return ERR_PTR(-ENODEV);
  577. }
  578. init_subchannel_id(&schid);
  579. schid.sch_no = sch_no;
  580. ret = stsch(schid, &schib);
  581. if (ret)
  582. return ERR_PTR(-ENODEV);
  583. sch = css_alloc_subchannel(schid, &schib);
  584. if (IS_ERR(sch))
  585. return sch;
  586. lockdep_set_class(sch->lock, &console_sch_key);
  587. isc_register(CONSOLE_ISC);
  588. sch->config.isc = CONSOLE_ISC;
  589. sch->config.intparm = (u32)(addr_t)sch;
  590. ret = cio_commit_config(sch);
  591. if (ret) {
  592. isc_unregister(CONSOLE_ISC);
  593. put_device(&sch->dev);
  594. return ERR_PTR(ret);
  595. }
  596. console_sch = sch;
  597. return sch;
  598. }
  599. int cio_is_console(struct subchannel_id schid)
  600. {
  601. if (!console_sch)
  602. return 0;
  603. return schid_equal(&schid, &console_sch->schid);
  604. }
  605. void cio_register_early_subchannels(void)
  606. {
  607. int ret;
  608. if (!console_sch)
  609. return;
  610. ret = css_register_subchannel(console_sch);
  611. if (ret)
  612. put_device(&console_sch->dev);
  613. }
  614. #endif /* CONFIG_CCW_CONSOLE */
  615. /**
  616. * cio_tm_start_key - perform start function
  617. * @sch: subchannel on which to perform the start function
  618. * @tcw: transport-command word to be started
  619. * @lpm: mask of paths to use
  620. * @key: storage key to use for storage access
  621. *
  622. * Start the tcw on the given subchannel. Return zero on success, non-zero
  623. * otherwise.
  624. */
  625. int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
  626. {
  627. int cc;
  628. union orb *orb = &to_io_private(sch)->orb;
  629. memset(orb, 0, sizeof(union orb));
  630. orb->tm.intparm = (u32) (addr_t) sch;
  631. orb->tm.key = key >> 4;
  632. orb->tm.b = 1;
  633. orb->tm.lpm = lpm ? lpm : sch->lpm;
  634. orb->tm.tcw = (u32) (addr_t) tcw;
  635. cc = ssch(sch->schid, orb);
  636. switch (cc) {
  637. case 0:
  638. return 0;
  639. case 1:
  640. case 2:
  641. return -EBUSY;
  642. default:
  643. return cio_start_handle_notoper(sch, lpm);
  644. }
  645. }
  646. EXPORT_SYMBOL_GPL(cio_tm_start_key);
  647. /**
  648. * cio_tm_intrg - perform interrogate function
  649. * @sch: subchannel on which to perform the interrogate function
  650. *
  651. * If the specified subchannel is running in transport-mode, perform the
  652. * interrogate function. Return zero on success, non-zero otherwie.
  653. */
  654. int cio_tm_intrg(struct subchannel *sch)
  655. {
  656. int cc;
  657. if (!to_io_private(sch)->orb.tm.b)
  658. return -EINVAL;
  659. cc = xsch(sch->schid);
  660. switch (cc) {
  661. case 0:
  662. case 2:
  663. return 0;
  664. case 1:
  665. return -EBUSY;
  666. default:
  667. return -ENODEV;
  668. }
  669. }
  670. EXPORT_SYMBOL_GPL(cio_tm_intrg);