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