1 // SPDX-License-Identifier: GPL-2.0
3 * S/390 common I/O routines -- low level i/o calls
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)
12 #define KMSG_COMPONENT "cio"
13 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/ftrace.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/device.h>
20 #include <linux/kernel_stat.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
24 #include <asm/delay.h>
26 #include <asm/irq_regs.h>
27 #include <asm/setup.h>
28 #include <asm/reset.h>
30 #include <asm/chpid.h>
33 #include <linux/sched/cputime.h>
42 #include "blacklist.h"
43 #include "cio_debug.h"
47 debug_info_t
*cio_debug_msg_id
;
48 debug_info_t
*cio_debug_trace_id
;
49 debug_info_t
*cio_debug_crw_id
;
51 DEFINE_PER_CPU_ALIGNED(struct irb
, cio_irb
);
52 EXPORT_PER_CPU_SYMBOL(cio_irb
);
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
61 static int __init
cio_debug_init(void)
63 cio_debug_msg_id
= debug_register("cio_msg", 16, 1, 11 * sizeof(long));
64 if (!cio_debug_msg_id
)
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
)
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
)
76 debug_register_view(cio_debug_crw_id
, &debug_sprintf_view
);
77 debug_set_level(cio_debug_crw_id
, 4);
81 debug_unregister(cio_debug_msg_id
);
82 debug_unregister(cio_debug_trace_id
);
83 debug_unregister(cio_debug_crw_id
);
87 arch_initcall (cio_debug_init
);
89 int cio_set_options(struct subchannel
*sch
, int flags
)
91 struct io_subchannel_private
*priv
= to_io_private(sch
);
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;
100 cio_start_handle_notoper(struct subchannel
*sch
, __u8 lpm
)
109 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
110 "subchannel 0.%x.%04x!\n", sch
->schid
.ssid
,
113 if (cio_update_schib(sch
))
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
));
120 return (sch
->lpm
? -EACCES
: -ENODEV
);
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 */
129 struct io_subchannel_private
*priv
= to_io_private(sch
);
130 union orb
*orb
= &priv
->orb
;
133 CIO_TRACE_EVENT(5, "stIO");
134 CIO_TRACE_EVENT(5, dev_name(&sch
->dev
));
136 memset(orb
, 0, sizeof(union orb
));
137 /* sch is always under 2G. */
138 orb
->cmd
.intparm
= (u32
)(addr_t
)sch
;
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
;
146 * for 64 bit we always support 64 bit IDAWs with 4k page size only
150 orb
->cmd
.key
= key
>> 4;
151 /* issue "Start Subchannel" */
152 orb
->cmd
.cpa
= (__u32
) __pa(cpa
);
153 ccode
= ssch(sch
->schid
, orb
);
155 /* process condition code */
156 CIO_HEX_EVENT(5, &ccode
, sizeof(ccode
));
161 * initialize device status information
163 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_START_PEND
;
165 case 1: /* status pending */
168 case 3: /* device/path not operational */
169 return cio_start_handle_notoper(sch
, lpm
);
174 EXPORT_SYMBOL_GPL(cio_start_key
);
177 cio_start (struct subchannel
*sch
, struct ccw1
*cpa
, __u8 lpm
)
179 return cio_start_key(sch
, cpa
, lpm
, PAGE_DEFAULT_KEY
);
181 EXPORT_SYMBOL_GPL(cio_start
);
184 * resume suspended I/O operation
187 cio_resume (struct subchannel
*sch
)
191 CIO_TRACE_EVENT(4, "resIO");
192 CIO_TRACE_EVENT(4, dev_name(&sch
->dev
));
194 ccode
= rsch (sch
->schid
);
196 CIO_HEX_EVENT(4, &ccode
, sizeof(ccode
));
200 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_RESUME_PEND
;
208 * useless to wait for request completion
209 * as device is no longer operational !
214 EXPORT_SYMBOL_GPL(cio_resume
);
220 cio_halt(struct subchannel
*sch
)
227 CIO_TRACE_EVENT(2, "haltIO");
228 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
231 * Issue "Halt subchannel" and process condition code
233 ccode
= hsch (sch
->schid
);
235 CIO_HEX_EVENT(2, &ccode
, sizeof(ccode
));
239 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_HALT_PEND
;
241 case 1: /* status pending */
244 default: /* device not operational */
248 EXPORT_SYMBOL_GPL(cio_halt
);
251 * Clear I/O operation
254 cio_clear(struct subchannel
*sch
)
261 CIO_TRACE_EVENT(2, "clearIO");
262 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
265 * Issue "Clear subchannel" and process condition code
267 ccode
= csch (sch
->schid
);
269 CIO_HEX_EVENT(2, &ccode
, sizeof(ccode
));
273 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_CLEAR_PEND
;
275 default: /* device not operational */
279 EXPORT_SYMBOL_GPL(cio_clear
);
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.
289 cio_cancel (struct subchannel
*sch
)
296 CIO_TRACE_EVENT(2, "cancelIO");
297 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
299 ccode
= xsch (sch
->schid
);
301 CIO_HEX_EVENT(2, &ccode
, sizeof(ccode
));
304 case 0: /* success */
305 /* Update information in scsw. */
306 if (cio_update_schib(sch
))
309 case 1: /* status pending */
311 case 2: /* not applicable */
313 default: /* not oper */
317 EXPORT_SYMBOL_GPL(cio_cancel
);
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
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.
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.
335 int cio_cancel_halt_clear(struct subchannel
*sch
, int *iretry
)
339 if (cio_update_schib(sch
))
341 if (!sch
->schib
.pmcw
.ena
)
342 /* Not operational -> done. */
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
);
353 * Cancel io unsuccessful or not applicable (transport mode).
354 * Continue with asynchronous instructions.
356 *iretry
= 3; /* 3 halt retries. */
358 /* Stage 2: halt io. */
359 if (!(scsw_actl(&sch
->schib
.scsw
) & SCSW_ACTL_CLEAR_PEND
)) {
364 return (ret
== 0) ? -EBUSY
: ret
;
366 /* Halt io unsuccessful. */
367 *iretry
= 255; /* 255 clear retries. */
369 /* Stage 3: clear io. */
372 ret
= cio_clear(sch
);
373 return (ret
== 0) ? -EBUSY
: ret
;
375 /* Function was unsuccessful */
378 EXPORT_SYMBOL_GPL(cio_cancel_halt_clear
);
380 static void cio_apply_config(struct subchannel
*sch
, struct schib
*schib
)
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
;
394 static int cio_check_config(struct subchannel
*sch
, struct schib
*schib
)
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
));
408 * cio_commit_config - apply configuration to the subchannel
410 int cio_commit_config(struct subchannel
*sch
)
412 int ccode
, retry
, ret
= 0;
416 if (stsch(sch
->schid
, &schib
) || !css_sch_is_valid(&schib
))
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. */
426 case 0: /* successful */
427 if (stsch(sch
->schid
, &schib
) ||
428 !css_sch_is_valid(&schib
))
430 if (cio_check_config(sch
, &schib
)) {
431 /* commit changes from local schib */
432 memcpy(&sch
->schib
, &schib
, sizeof(schib
));
437 case 1: /* status pending */
439 if (tsch(sch
->schid
, &irb
))
443 udelay(100); /* allow for recovery */
446 case 3: /* not operational */
452 EXPORT_SYMBOL_GPL(cio_commit_config
);
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.
459 int cio_update_schib(struct subchannel
*sch
)
463 if (stsch(sch
->schid
, &schib
) || !css_sch_is_valid(&schib
))
466 memcpy(&sch
->schib
, &schib
, sizeof(schib
));
469 EXPORT_SYMBOL_GPL(cio_update_schib
);
472 * cio_enable_subchannel - enable a subchannel.
473 * @sch: subchannel to be enabled
474 * @intparm: interruption parameter to set
476 int cio_enable_subchannel(struct subchannel
*sch
, u32 intparm
)
480 CIO_TRACE_EVENT(2, "ensch");
481 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
483 if (sch_is_pseudo_sch(sch
))
485 if (cio_update_schib(sch
))
489 sch
->config
.isc
= sch
->isc
;
490 sch
->config
.intparm
= intparm
;
492 ret
= cio_commit_config(sch
);
495 * Got a program check in msch. Try without
496 * the concurrent sense bit the next time.
498 sch
->config
.csense
= 0;
499 ret
= cio_commit_config(sch
);
501 CIO_HEX_EVENT(2, &ret
, sizeof(ret
));
504 EXPORT_SYMBOL_GPL(cio_enable_subchannel
);
507 * cio_disable_subchannel - disable a subchannel.
508 * @sch: subchannel to disable
510 int cio_disable_subchannel(struct subchannel
*sch
)
514 CIO_TRACE_EVENT(2, "dissch");
515 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
517 if (sch_is_pseudo_sch(sch
))
519 if (cio_update_schib(sch
))
523 ret
= cio_commit_config(sch
);
525 CIO_HEX_EVENT(2, &ret
, sizeof(ret
));
528 EXPORT_SYMBOL_GPL(cio_disable_subchannel
);
530 static int cio_check_devno_blacklisted(struct subchannel
*sch
)
532 if (is_blacklisted(sch
->schid
.ssid
, sch
->schib
.pmcw
.dev
)) {
534 * This device must not be known to Linux. So we simply
535 * say that there is no device and return ENODEV.
537 CIO_MSG_EVENT(6, "Blacklisted device detected "
538 "at devno %04X, subchannel set %x\n",
539 sch
->schib
.pmcw
.dev
, sch
->schid
.ssid
);
546 * cio_validate_subchannel - basic validation of subchannel
547 * @sch: subchannel structure to be filled out
548 * @schid: subchannel id
550 * Find out subchannel type and initialize struct subchannel.
553 * -ENXIO for non-defined subchannels
554 * -ENODEV for invalid subchannels or blacklisted devices
555 * -EIO for subchannels in an invalid subchannel set
557 int cio_validate_subchannel(struct subchannel
*sch
, struct subchannel_id schid
)
563 sprintf(dbf_txt
, "valsch%x", schid
.sch_no
);
564 CIO_TRACE_EVENT(4, dbf_txt
);
567 * The first subchannel that is not-operational (ccode==3)
568 * indicates that there aren't any more devices available.
569 * If stsch gets an exception, it means the current subchannel set
572 ccode
= stsch(schid
, &sch
->schib
);
574 err
= (ccode
== 3) ? -ENXIO
: ccode
;
577 sch
->st
= sch
->schib
.pmcw
.st
;
581 case SUBCHANNEL_TYPE_IO
:
582 case SUBCHANNEL_TYPE_MSG
:
583 if (!css_sch_is_valid(&sch
->schib
))
586 err
= cio_check_devno_blacklisted(sch
);
594 CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
595 sch
->schid
.ssid
, sch
->schid
.sch_no
, sch
->st
);
601 * do_cio_interrupt() handles all normal I/O device IRQ's
603 static irqreturn_t
do_cio_interrupt(int irq
, void *dummy
)
605 struct tpi_info
*tpi_info
;
606 struct subchannel
*sch
;
609 set_cpu_flag(CIF_NOHZ_DELAY
);
610 tpi_info
= (struct tpi_info
*) &get_irq_regs()->int_code
;
611 trace_s390_cio_interrupt(tpi_info
);
612 irb
= this_cpu_ptr(&cio_irb
);
613 sch
= (struct subchannel
*)(unsigned long) tpi_info
->intparm
;
615 /* Clear pending interrupt condition. */
616 inc_irq_stat(IRQIO_CIO
);
617 tsch(tpi_info
->schid
, irb
);
620 spin_lock(sch
->lock
);
621 /* Store interrupt response block to lowcore. */
622 if (tsch(tpi_info
->schid
, irb
) == 0) {
623 /* Keep subchannel information word up to date. */
624 memcpy (&sch
->schib
.scsw
, &irb
->scsw
, sizeof (irb
->scsw
));
625 /* Call interrupt handler if there is one. */
626 if (sch
->driver
&& sch
->driver
->irq
)
627 sch
->driver
->irq(sch
);
629 inc_irq_stat(IRQIO_CIO
);
631 inc_irq_stat(IRQIO_CIO
);
632 spin_unlock(sch
->lock
);
637 static struct irqaction io_interrupt
= {
639 .handler
= do_cio_interrupt
,
642 void __init
init_cio_interrupts(void)
644 irq_set_chip_and_handler(IO_INTERRUPT
,
645 &dummy_irq_chip
, handle_percpu_irq
);
646 setup_irq(IO_INTERRUPT
, &io_interrupt
);
649 #ifdef CONFIG_CCW_CONSOLE
650 static struct subchannel
*console_sch
;
651 static struct lock_class_key console_sch_key
;
654 * Use cio_tsch to update the subchannel status and call the interrupt handler
655 * if status had been pending. Called with the subchannel's lock held.
657 void cio_tsch(struct subchannel
*sch
)
662 irb
= this_cpu_ptr(&cio_irb
);
663 /* Store interrupt response block to lowcore. */
664 if (tsch(sch
->schid
, irb
) != 0)
665 /* Not status pending or not operational. */
667 memcpy(&sch
->schib
.scsw
, &irb
->scsw
, sizeof(union scsw
));
668 /* Call interrupt handler with updated status. */
669 irq_context
= in_interrupt();
674 kstat_incr_irq_this_cpu(IO_INTERRUPT
);
675 if (sch
->driver
&& sch
->driver
->irq
)
676 sch
->driver
->irq(sch
);
678 inc_irq_stat(IRQIO_CIO
);
685 static int cio_test_for_console(struct subchannel_id schid
, void *data
)
689 if (stsch(schid
, &schib
) != 0)
691 if ((schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) && schib
.pmcw
.dnv
&&
692 (schib
.pmcw
.dev
== console_devno
)) {
693 console_irq
= schid
.sch_no
;
694 return 1; /* found */
699 static int cio_get_console_sch_no(void)
701 struct subchannel_id schid
;
704 init_subchannel_id(&schid
);
705 if (console_irq
!= -1) {
706 /* VM provided us with the irq number of the console. */
707 schid
.sch_no
= console_irq
;
708 if (stsch(schid
, &schib
) != 0 ||
709 (schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
) || !schib
.pmcw
.dnv
)
711 console_devno
= schib
.pmcw
.dev
;
712 } else if (console_devno
!= -1) {
713 /* At least the console device number is known. */
714 for_each_subchannel(cio_test_for_console
, NULL
);
719 struct subchannel
*cio_probe_console(void)
721 struct subchannel_id schid
;
722 struct subchannel
*sch
;
725 sch_no
= cio_get_console_sch_no();
727 pr_warn("No CCW console was found\n");
728 return ERR_PTR(-ENODEV
);
730 init_subchannel_id(&schid
);
731 schid
.sch_no
= sch_no
;
732 sch
= css_alloc_subchannel(schid
);
736 lockdep_set_class(sch
->lock
, &console_sch_key
);
737 isc_register(CONSOLE_ISC
);
738 sch
->config
.isc
= CONSOLE_ISC
;
739 sch
->config
.intparm
= (u32
)(addr_t
)sch
;
740 ret
= cio_commit_config(sch
);
742 isc_unregister(CONSOLE_ISC
);
743 put_device(&sch
->dev
);
750 int cio_is_console(struct subchannel_id schid
)
754 return schid_equal(&schid
, &console_sch
->schid
);
757 void cio_register_early_subchannels(void)
764 ret
= css_register_subchannel(console_sch
);
766 put_device(&console_sch
->dev
);
768 #endif /* CONFIG_CCW_CONSOLE */
771 __disable_subchannel_easy(struct subchannel_id schid
, struct schib
*schib
)
776 for (retry
=0;retry
<3;retry
++) {
778 cc
= msch(schid
, schib
);
780 return (cc
==3?-ENODEV
:-EBUSY
);
781 if (stsch(schid
, schib
) || !css_sch_is_valid(schib
))
783 if (!schib
->pmcw
.ena
)
786 return -EBUSY
; /* uhm... */
790 __clear_io_subchannel_easy(struct subchannel_id schid
)
796 for (retry
=0;retry
<20;retry
++) {
800 tsch(ti
.schid
, this_cpu_ptr(&cio_irb
));
801 if (schid_equal(&ti
.schid
, &schid
))
809 static void __clear_chsc_subchannel_easy(void)
811 /* It seems we can only wait for a bit here :/ */
815 static int pgm_check_occured
;
817 static void cio_reset_pgm_check_handler(void)
819 pgm_check_occured
= 1;
822 static int stsch_reset(struct subchannel_id schid
, struct schib
*addr
)
826 pgm_check_occured
= 0;
827 s390_base_pgm_handler_fn
= cio_reset_pgm_check_handler
;
828 rc
= stsch(schid
, addr
);
829 s390_base_pgm_handler_fn
= NULL
;
831 /* The program check handler could have changed pgm_check_occured. */
834 if (pgm_check_occured
)
840 static int __shutdown_subchannel_easy(struct subchannel_id schid
, void *data
)
844 if (stsch_reset(schid
, &schib
))
848 switch(__disable_subchannel_easy(schid
, &schib
)) {
852 default: /* -EBUSY */
853 switch (schib
.pmcw
.st
) {
854 case SUBCHANNEL_TYPE_IO
:
855 if (__clear_io_subchannel_easy(schid
))
856 goto out
; /* give up... */
858 case SUBCHANNEL_TYPE_CHSC
:
859 __clear_chsc_subchannel_easy();
862 /* No default clear strategy */
865 stsch(schid
, &schib
);
866 __disable_subchannel_easy(schid
, &schib
);
872 static atomic_t chpid_reset_count
;
874 static void s390_reset_chpids_mcck_handler(void)
879 /* Check for pending channel report word. */
880 mci
.val
= S390_lowcore
.mcck_interruption_code
;
883 /* Process channel report words. */
884 while (stcrw(&crw
) == 0) {
885 /* Check for responses to RCHP. */
886 if (crw
.slct
&& crw
.rsc
== CRW_RSC_CPATH
)
887 atomic_dec(&chpid_reset_count
);
891 #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
892 static void css_reset(void)
895 unsigned long long timeout
;
898 /* Reset subchannels. */
899 for_each_subchannel(__shutdown_subchannel_easy
, NULL
);
900 /* Reset channel paths. */
901 s390_base_mcck_handler_fn
= s390_reset_chpids_mcck_handler
;
902 /* Enable channel report machine checks. */
903 __ctl_set_bit(14, 28);
904 /* Temporarily reenable machine checks. */
907 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
910 if ((ret
== 0) || (ret
== 2))
912 * rchp either succeeded, or another rchp is already
913 * in progress. In either case, we'll get a crw.
915 atomic_inc(&chpid_reset_count
);
917 /* Wait for machine check for all channel paths. */
918 timeout
= get_tod_clock_fast() + (RCHP_TIMEOUT
<< 12);
919 while (atomic_read(&chpid_reset_count
) != 0) {
920 if (get_tod_clock_fast() > timeout
)
924 /* Disable machine checks again. */
925 local_mcck_disable();
926 /* Disable channel report machine checks. */
927 __ctl_clear_bit(14, 28);
928 s390_base_mcck_handler_fn
= NULL
;
931 static struct reset_call css_reset_call
= {
935 static int __init
init_css_reset_call(void)
937 atomic_set(&chpid_reset_count
, 0);
938 register_reset_call(&css_reset_call
);
942 arch_initcall(init_css_reset_call
);
944 struct sch_match_id
{
945 struct subchannel_id schid
;
946 struct ccw_dev_id devid
;
950 static int __reipl_subchannel_match(struct subchannel_id schid
, void *data
)
953 struct sch_match_id
*match_id
= data
;
955 if (stsch_reset(schid
, &schib
))
957 if ((schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) && schib
.pmcw
.dnv
&&
958 (schib
.pmcw
.dev
== match_id
->devid
.devno
) &&
959 (schid
.ssid
== match_id
->devid
.ssid
)) {
960 match_id
->schid
= schid
;
967 static int reipl_find_schid(struct ccw_dev_id
*devid
,
968 struct subchannel_id
*schid
)
970 struct sch_match_id match_id
;
972 match_id
.devid
= *devid
;
973 match_id
.rc
= -ENODEV
;
974 for_each_subchannel(__reipl_subchannel_match
, &match_id
);
975 if (match_id
.rc
== 0)
976 *schid
= match_id
.schid
;
980 extern void do_reipl_asm(__u32 schid
);
982 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
983 void reipl_ccw_dev(struct ccw_dev_id
*devid
)
985 struct subchannel_id
uninitialized_var(schid
);
988 if (reipl_find_schid(devid
, &schid
) != 0)
989 panic("IPL Device not found\n");
990 do_reipl_asm(*((__u32
*)&schid
));
993 int __init
cio_get_iplinfo(struct cio_iplinfo
*iplinfo
)
995 static struct chsc_sda_area sda_area __initdata
;
996 struct subchannel_id schid
;
999 schid
= *(struct subchannel_id
*)&S390_lowcore
.subchannel_id
;
1005 * Firmware should have already enabled MSS but whoever started
1006 * the kernel might have initiated a channel subsystem reset.
1007 * Ensure that MSS is enabled.
1009 memset(&sda_area
, 0, sizeof(sda_area
));
1010 if (__chsc_enable_facility(&sda_area
, CHSC_SDA_OC_MSS
))
1013 if (stsch(schid
, &schib
))
1015 if (schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
)
1017 if (!schib
.pmcw
.dnv
)
1020 iplinfo
->ssid
= schid
.ssid
;
1021 iplinfo
->devno
= schib
.pmcw
.dev
;
1022 iplinfo
->is_qdio
= schib
.pmcw
.qf
;
1027 * cio_tm_start_key - perform start function
1028 * @sch: subchannel on which to perform the start function
1029 * @tcw: transport-command word to be started
1030 * @lpm: mask of paths to use
1031 * @key: storage key to use for storage access
1033 * Start the tcw on the given subchannel. Return zero on success, non-zero
1036 int cio_tm_start_key(struct subchannel
*sch
, struct tcw
*tcw
, u8 lpm
, u8 key
)
1039 union orb
*orb
= &to_io_private(sch
)->orb
;
1041 memset(orb
, 0, sizeof(union orb
));
1042 orb
->tm
.intparm
= (u32
) (addr_t
) sch
;
1043 orb
->tm
.key
= key
>> 4;
1045 orb
->tm
.lpm
= lpm
? lpm
: sch
->lpm
;
1046 orb
->tm
.tcw
= (u32
) (addr_t
) tcw
;
1047 cc
= ssch(sch
->schid
, orb
);
1055 return cio_start_handle_notoper(sch
, lpm
);
1058 EXPORT_SYMBOL_GPL(cio_tm_start_key
);
1061 * cio_tm_intrg - perform interrogate function
1062 * @sch - subchannel on which to perform the interrogate function
1064 * If the specified subchannel is running in transport-mode, perform the
1065 * interrogate function. Return zero on success, non-zero otherwie.
1067 int cio_tm_intrg(struct subchannel
*sch
)
1071 if (!to_io_private(sch
)->orb
.tm
.b
)
1073 cc
= xsch(sch
->schid
);
1084 EXPORT_SYMBOL_GPL(cio_tm_intrg
);