2 * drivers/s390/cio/cio.c
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>
23 #include <asm/delay.h>
25 #include <asm/irq_regs.h>
26 #include <asm/setup.h>
27 #include <asm/reset.h>
29 #include <asm/chpid.h>
32 #include <asm/cputime.h>
41 #include "blacklist.h"
42 #include "cio_debug.h"
45 debug_info_t
*cio_debug_msg_id
;
46 debug_info_t
*cio_debug_trace_id
;
47 debug_info_t
*cio_debug_crw_id
;
50 * Function: cio_debug_init
51 * Initializes three debug logs for common I/O:
52 * - cio_msg logs generic cio messages
53 * - cio_trace logs the calling of different functions
54 * - cio_crw logs machine check related cio messages
56 static int __init
cio_debug_init(void)
58 cio_debug_msg_id
= debug_register("cio_msg", 16, 1, 16 * sizeof(long));
59 if (!cio_debug_msg_id
)
61 debug_register_view(cio_debug_msg_id
, &debug_sprintf_view
);
62 debug_set_level(cio_debug_msg_id
, 2);
63 cio_debug_trace_id
= debug_register("cio_trace", 16, 1, 16);
64 if (!cio_debug_trace_id
)
66 debug_register_view(cio_debug_trace_id
, &debug_hex_ascii_view
);
67 debug_set_level(cio_debug_trace_id
, 2);
68 cio_debug_crw_id
= debug_register("cio_crw", 16, 1, 16 * sizeof(long));
69 if (!cio_debug_crw_id
)
71 debug_register_view(cio_debug_crw_id
, &debug_sprintf_view
);
72 debug_set_level(cio_debug_crw_id
, 4);
77 debug_unregister(cio_debug_msg_id
);
78 if (cio_debug_trace_id
)
79 debug_unregister(cio_debug_trace_id
);
81 debug_unregister(cio_debug_crw_id
);
85 arch_initcall (cio_debug_init
);
87 int cio_set_options(struct subchannel
*sch
, int flags
)
89 struct io_subchannel_private
*priv
= to_io_private(sch
);
91 priv
->options
.suspend
= (flags
& DOIO_ALLOW_SUSPEND
) != 0;
92 priv
->options
.prefetch
= (flags
& DOIO_DENY_PREFETCH
) != 0;
93 priv
->options
.inter
= (flags
& DOIO_SUPPRESS_INTER
) != 0;
98 cio_start_handle_notoper(struct subchannel
*sch
, __u8 lpm
)
107 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
108 "subchannel 0.%x.%04x!\n", sch
->schid
.ssid
,
111 if (cio_update_schib(sch
))
114 sprintf(dbf_text
, "no%s", dev_name(&sch
->dev
));
115 CIO_TRACE_EVENT(0, dbf_text
);
116 CIO_HEX_EVENT(0, &sch
->schib
, sizeof (struct schib
));
118 return (sch
->lpm
? -EACCES
: -ENODEV
);
122 cio_start_key (struct subchannel
*sch
, /* subchannel structure */
123 struct ccw1
* cpa
, /* logical channel prog addr */
124 __u8 lpm
, /* logical path mask */
125 __u8 key
) /* storage key */
127 struct io_subchannel_private
*priv
= to_io_private(sch
);
128 union orb
*orb
= &priv
->orb
;
131 CIO_TRACE_EVENT(5, "stIO");
132 CIO_TRACE_EVENT(5, dev_name(&sch
->dev
));
134 memset(orb
, 0, sizeof(union orb
));
135 /* sch is always under 2G. */
136 orb
->cmd
.intparm
= (u32
)(addr_t
)sch
;
139 orb
->cmd
.pfch
= priv
->options
.prefetch
== 0;
140 orb
->cmd
.spnd
= priv
->options
.suspend
;
141 orb
->cmd
.ssic
= priv
->options
.suspend
&& priv
->options
.inter
;
142 orb
->cmd
.lpm
= (lpm
!= 0) ? lpm
: sch
->lpm
;
145 * 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
);
176 cio_start (struct subchannel
*sch
, struct ccw1
*cpa
, __u8 lpm
)
178 return cio_start_key(sch
, cpa
, lpm
, PAGE_DEFAULT_KEY
);
182 * resume suspended I/O operation
185 cio_resume (struct subchannel
*sch
)
189 CIO_TRACE_EVENT(4, "resIO");
190 CIO_TRACE_EVENT(4, dev_name(&sch
->dev
));
192 ccode
= rsch (sch
->schid
);
194 CIO_HEX_EVENT(4, &ccode
, sizeof(ccode
));
198 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_RESUME_PEND
;
206 * useless to wait for request completion
207 * as device is no longer operational !
217 cio_halt(struct subchannel
*sch
)
224 CIO_TRACE_EVENT(2, "haltIO");
225 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
228 * Issue "Halt subchannel" and process condition code
230 ccode
= hsch (sch
->schid
);
232 CIO_HEX_EVENT(2, &ccode
, sizeof(ccode
));
236 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_HALT_PEND
;
238 case 1: /* status pending */
241 default: /* device not operational */
247 * Clear I/O operation
250 cio_clear(struct subchannel
*sch
)
257 CIO_TRACE_EVENT(2, "clearIO");
258 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
261 * Issue "Clear subchannel" and process condition code
263 ccode
= csch (sch
->schid
);
265 CIO_HEX_EVENT(2, &ccode
, sizeof(ccode
));
269 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_CLEAR_PEND
;
271 default: /* device not operational */
277 * Function: cio_cancel
278 * Issues a "Cancel Subchannel" on the specified subchannel
279 * Note: We don't need any fancy intparms and flags here
280 * since xsch is executed synchronously.
281 * Only for common I/O internal use as for now.
284 cio_cancel (struct subchannel
*sch
)
291 CIO_TRACE_EVENT(2, "cancelIO");
292 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
294 ccode
= xsch (sch
->schid
);
296 CIO_HEX_EVENT(2, &ccode
, sizeof(ccode
));
299 case 0: /* success */
300 /* Update information in scsw. */
301 if (cio_update_schib(sch
))
304 case 1: /* status pending */
306 case 2: /* not applicable */
308 default: /* not oper */
314 static void cio_apply_config(struct subchannel
*sch
, struct schib
*schib
)
316 schib
->pmcw
.intparm
= sch
->config
.intparm
;
317 schib
->pmcw
.mbi
= sch
->config
.mbi
;
318 schib
->pmcw
.isc
= sch
->config
.isc
;
319 schib
->pmcw
.ena
= sch
->config
.ena
;
320 schib
->pmcw
.mme
= sch
->config
.mme
;
321 schib
->pmcw
.mp
= sch
->config
.mp
;
322 schib
->pmcw
.csense
= sch
->config
.csense
;
323 schib
->pmcw
.mbfc
= sch
->config
.mbfc
;
324 if (sch
->config
.mbfc
)
325 schib
->mba
= sch
->config
.mba
;
328 static int cio_check_config(struct subchannel
*sch
, struct schib
*schib
)
330 return (schib
->pmcw
.intparm
== sch
->config
.intparm
) &&
331 (schib
->pmcw
.mbi
== sch
->config
.mbi
) &&
332 (schib
->pmcw
.isc
== sch
->config
.isc
) &&
333 (schib
->pmcw
.ena
== sch
->config
.ena
) &&
334 (schib
->pmcw
.mme
== sch
->config
.mme
) &&
335 (schib
->pmcw
.mp
== sch
->config
.mp
) &&
336 (schib
->pmcw
.csense
== sch
->config
.csense
) &&
337 (schib
->pmcw
.mbfc
== sch
->config
.mbfc
) &&
338 (!sch
->config
.mbfc
|| (schib
->mba
== sch
->config
.mba
));
342 * cio_commit_config - apply configuration to the subchannel
344 int cio_commit_config(struct subchannel
*sch
)
347 int ccode
, retry
, ret
= 0;
349 if (stsch_err(sch
->schid
, &schib
) || !css_sch_is_valid(&schib
))
352 for (retry
= 0; retry
< 5; retry
++) {
353 /* copy desired changes to local schib */
354 cio_apply_config(sch
, &schib
);
355 ccode
= msch_err(sch
->schid
, &schib
);
356 if (ccode
< 0) /* -EIO if msch gets a program check. */
359 case 0: /* successful */
360 if (stsch_err(sch
->schid
, &schib
) ||
361 !css_sch_is_valid(&schib
))
363 if (cio_check_config(sch
, &schib
)) {
364 /* commit changes from local schib */
365 memcpy(&sch
->schib
, &schib
, sizeof(schib
));
370 case 1: /* status pending */
373 udelay(100); /* allow for recovery */
376 case 3: /* not operational */
384 * cio_update_schib - Perform stsch and update schib if subchannel is valid.
385 * @sch: subchannel on which to perform stsch
386 * Return zero on success, -ENODEV otherwise.
388 int cio_update_schib(struct subchannel
*sch
)
392 if (stsch_err(sch
->schid
, &schib
) || !css_sch_is_valid(&schib
))
395 memcpy(&sch
->schib
, &schib
, sizeof(schib
));
398 EXPORT_SYMBOL_GPL(cio_update_schib
);
401 * cio_enable_subchannel - enable a subchannel.
402 * @sch: subchannel to be enabled
403 * @intparm: interruption parameter to set
405 int cio_enable_subchannel(struct subchannel
*sch
, u32 intparm
)
410 CIO_TRACE_EVENT(2, "ensch");
411 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
413 if (sch_is_pseudo_sch(sch
))
415 if (cio_update_schib(sch
))
419 sch
->config
.isc
= sch
->isc
;
420 sch
->config
.intparm
= intparm
;
422 for (retry
= 0; retry
< 3; retry
++) {
423 ret
= cio_commit_config(sch
);
426 * Got a program check in msch. Try without
427 * the concurrent sense bit the next time.
429 sch
->config
.csense
= 0;
430 } else if (ret
== -EBUSY
) {
432 if (tsch(sch
->schid
, &irb
) != 0)
437 CIO_HEX_EVENT(2, &ret
, sizeof(ret
));
440 EXPORT_SYMBOL_GPL(cio_enable_subchannel
);
443 * cio_disable_subchannel - disable a subchannel.
444 * @sch: subchannel to disable
446 int cio_disable_subchannel(struct subchannel
*sch
)
451 CIO_TRACE_EVENT(2, "dissch");
452 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
454 if (sch_is_pseudo_sch(sch
))
456 if (cio_update_schib(sch
))
461 for (retry
= 0; retry
< 3; retry
++) {
462 ret
= cio_commit_config(sch
);
465 if (tsch(sch
->schid
, &irb
) != 0)
470 CIO_HEX_EVENT(2, &ret
, sizeof(ret
));
473 EXPORT_SYMBOL_GPL(cio_disable_subchannel
);
475 int cio_create_sch_lock(struct subchannel
*sch
)
477 sch
->lock
= kmalloc(sizeof(spinlock_t
), GFP_KERNEL
);
480 spin_lock_init(sch
->lock
);
484 static int cio_check_devno_blacklisted(struct subchannel
*sch
)
486 if (is_blacklisted(sch
->schid
.ssid
, sch
->schib
.pmcw
.dev
)) {
488 * This device must not be known to Linux. So we simply
489 * say that there is no device and return ENODEV.
491 CIO_MSG_EVENT(6, "Blacklisted device detected "
492 "at devno %04X, subchannel set %x\n",
493 sch
->schib
.pmcw
.dev
, sch
->schid
.ssid
);
499 static int cio_validate_io_subchannel(struct subchannel
*sch
)
501 /* Initialization for io subchannels. */
502 if (!css_sch_is_valid(&sch
->schib
))
505 /* Devno is valid. */
506 return cio_check_devno_blacklisted(sch
);
509 static int cio_validate_msg_subchannel(struct subchannel
*sch
)
511 /* Initialization for message subchannels. */
512 if (!css_sch_is_valid(&sch
->schib
))
515 /* Devno is valid. */
516 return cio_check_devno_blacklisted(sch
);
520 * cio_validate_subchannel - basic validation of subchannel
521 * @sch: subchannel structure to be filled out
522 * @schid: subchannel id
524 * Find out subchannel type and initialize struct subchannel.
527 * -ENXIO for non-defined subchannels
528 * -ENODEV for invalid subchannels or blacklisted devices
529 * -EIO for subchannels in an invalid subchannel set
531 int cio_validate_subchannel(struct subchannel
*sch
, struct subchannel_id schid
)
537 sprintf(dbf_txt
, "valsch%x", schid
.sch_no
);
538 CIO_TRACE_EVENT(4, dbf_txt
);
540 /* Nuke all fields. */
541 memset(sch
, 0, sizeof(struct subchannel
));
544 if (cio_is_console(schid
)) {
545 sch
->lock
= cio_get_console_lock();
547 err
= cio_create_sch_lock(sch
);
551 mutex_init(&sch
->reg_mutex
);
554 * The first subchannel that is not-operational (ccode==3)
555 * indicates that there aren't any more devices available.
556 * If stsch gets an exception, it means the current subchannel set
559 ccode
= stsch_err (schid
, &sch
->schib
);
561 err
= (ccode
== 3) ? -ENXIO
: ccode
;
564 /* Copy subchannel type from path management control word. */
565 sch
->st
= sch
->schib
.pmcw
.st
;
568 case SUBCHANNEL_TYPE_IO
:
569 err
= cio_validate_io_subchannel(sch
);
571 case SUBCHANNEL_TYPE_MSG
:
572 err
= cio_validate_msg_subchannel(sch
);
580 CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
581 sch
->schid
.ssid
, sch
->schid
.sch_no
, sch
->st
);
584 if (!cio_is_console(schid
))
591 * do_IRQ() handles all normal I/O device IRQ's (the special
592 * SMP cross-CPU interrupts have their own specific
596 void __irq_entry
do_IRQ(struct pt_regs
*regs
)
598 struct tpi_info
*tpi_info
;
599 struct subchannel
*sch
;
601 struct pt_regs
*old_regs
;
603 old_regs
= set_irq_regs(regs
);
604 s390_idle_check(regs
, S390_lowcore
.int_clock
,
605 S390_lowcore
.async_enter_timer
);
607 __this_cpu_write(s390_idle
.nohz_delay
, 1);
608 if (S390_lowcore
.int_clock
>= S390_lowcore
.clock_comparator
)
609 /* Serve timer interrupts first. */
610 clock_comparator_work();
612 * Get interrupt information from lowcore
614 tpi_info
= (struct tpi_info
*)&S390_lowcore
.subchannel_id
;
615 irb
= (struct irb
*)&S390_lowcore
.irb
;
617 kstat_cpu(smp_processor_id()).irqs
[IO_INTERRUPT
]++;
618 if (tpi_info
->adapter_IO
) {
619 do_adapter_IO(tpi_info
->isc
);
622 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
624 /* Clear pending interrupt condition. */
625 kstat_cpu(smp_processor_id()).irqs
[IOINT_CIO
]++;
626 tsch(tpi_info
->schid
, irb
);
629 spin_lock(sch
->lock
);
630 /* Store interrupt response block to lowcore. */
631 if (tsch(tpi_info
->schid
, irb
) == 0) {
632 /* Keep subchannel information word up to date. */
633 memcpy (&sch
->schib
.scsw
, &irb
->scsw
,
635 /* Call interrupt handler if there is one. */
636 if (sch
->driver
&& sch
->driver
->irq
)
637 sch
->driver
->irq(sch
);
639 kstat_cpu(smp_processor_id()).irqs
[IOINT_CIO
]++;
641 kstat_cpu(smp_processor_id()).irqs
[IOINT_CIO
]++;
642 spin_unlock(sch
->lock
);
644 * Are more interrupts pending?
645 * If so, the tpi instruction will update the lowcore
646 * to hold the info for the next interrupt.
647 * We don't do this for VM because a tpi drops the cpu
648 * out of the sie which costs more cycles than it saves.
650 } while (MACHINE_IS_LPAR
&& tpi(NULL
) != 0);
652 set_irq_regs(old_regs
);
655 #ifdef CONFIG_CCW_CONSOLE
656 static struct subchannel console_subchannel
;
657 static struct io_subchannel_private console_priv
;
658 static int console_subchannel_in_use
;
661 * Use cio_tpi to get a pending interrupt and call the interrupt handler.
662 * Return non-zero if an interrupt was processed, zero otherwise.
664 static int cio_tpi(void)
666 struct tpi_info
*tpi_info
;
667 struct subchannel
*sch
;
671 tpi_info
= (struct tpi_info
*)&S390_lowcore
.subchannel_id
;
674 kstat_cpu(smp_processor_id()).irqs
[IO_INTERRUPT
]++;
675 if (tpi_info
->adapter_IO
) {
676 do_adapter_IO(tpi_info
->isc
);
679 irb
= (struct irb
*)&S390_lowcore
.irb
;
680 /* Store interrupt response block to lowcore. */
681 if (tsch(tpi_info
->schid
, irb
) != 0) {
682 /* Not status pending or not operational. */
683 kstat_cpu(smp_processor_id()).irqs
[IOINT_CIO
]++;
686 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
688 kstat_cpu(smp_processor_id()).irqs
[IOINT_CIO
]++;
691 irq_context
= in_interrupt();
695 spin_lock(sch
->lock
);
696 memcpy(&sch
->schib
.scsw
, &irb
->scsw
, sizeof(union scsw
));
697 if (sch
->driver
&& sch
->driver
->irq
)
698 sch
->driver
->irq(sch
);
700 kstat_cpu(smp_processor_id()).irqs
[IOINT_CIO
]++;
701 spin_unlock(sch
->lock
);
708 void *cio_get_console_priv(void)
710 return &console_priv
;
714 * busy wait for the next interrupt on the console
716 void wait_cons_dev(void)
717 __releases(console_subchannel
.lock
)
718 __acquires(console_subchannel
.lock
)
720 unsigned long cr6
__attribute__ ((aligned (8)));
721 unsigned long save_cr6
__attribute__ ((aligned (8)));
724 * before entering the spinlock we may already have
725 * processed the interrupt on a different CPU...
727 if (!console_subchannel_in_use
)
730 /* disable all but the console isc */
731 __ctl_store (save_cr6
, 6, 6);
732 cr6
= 1UL << (31 - CONSOLE_ISC
);
733 __ctl_load (cr6
, 6, 6);
736 spin_unlock(console_subchannel
.lock
);
739 spin_lock(console_subchannel
.lock
);
740 } while (console_subchannel
.schib
.scsw
.cmd
.actl
!= 0);
742 * restore previous isc value
744 __ctl_load (save_cr6
, 6, 6);
748 cio_test_for_console(struct subchannel_id schid
, void *data
)
750 if (stsch_err(schid
, &console_subchannel
.schib
) != 0)
752 if ((console_subchannel
.schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) &&
753 console_subchannel
.schib
.pmcw
.dnv
&&
754 (console_subchannel
.schib
.pmcw
.dev
== console_devno
)) {
755 console_irq
= schid
.sch_no
;
756 return 1; /* found */
763 cio_get_console_sch_no(void)
765 struct subchannel_id schid
;
767 init_subchannel_id(&schid
);
768 if (console_irq
!= -1) {
769 /* VM provided us with the irq number of the console. */
770 schid
.sch_no
= console_irq
;
771 if (stsch_err(schid
, &console_subchannel
.schib
) != 0 ||
772 (console_subchannel
.schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
) ||
773 !console_subchannel
.schib
.pmcw
.dnv
)
775 console_devno
= console_subchannel
.schib
.pmcw
.dev
;
776 } else if (console_devno
!= -1) {
777 /* At least the console device number is known. */
778 for_each_subchannel(cio_test_for_console
, NULL
);
779 if (console_irq
== -1)
782 /* unlike in 2.4, we cannot autoprobe here, since
783 * the channel subsystem is not fully initialized.
784 * With some luck, the HWC console can take over */
791 cio_probe_console(void)
794 struct subchannel_id schid
;
796 if (xchg(&console_subchannel_in_use
, 1) != 0)
797 return ERR_PTR(-EBUSY
);
798 sch_no
= cio_get_console_sch_no();
800 console_subchannel_in_use
= 0;
801 pr_warning("No CCW console was found\n");
802 return ERR_PTR(-ENODEV
);
804 memset(&console_subchannel
, 0, sizeof(struct subchannel
));
805 init_subchannel_id(&schid
);
806 schid
.sch_no
= sch_no
;
807 ret
= cio_validate_subchannel(&console_subchannel
, schid
);
809 console_subchannel_in_use
= 0;
810 return ERR_PTR(-ENODEV
);
814 * enable console I/O-interrupt subclass
816 isc_register(CONSOLE_ISC
);
817 console_subchannel
.config
.isc
= CONSOLE_ISC
;
818 console_subchannel
.config
.intparm
= (u32
)(addr_t
)&console_subchannel
;
819 ret
= cio_commit_config(&console_subchannel
);
821 isc_unregister(CONSOLE_ISC
);
822 console_subchannel_in_use
= 0;
825 return &console_subchannel
;
829 cio_release_console(void)
831 console_subchannel
.config
.intparm
= 0;
832 cio_commit_config(&console_subchannel
);
833 isc_unregister(CONSOLE_ISC
);
834 console_subchannel_in_use
= 0;
837 /* Bah... hack to catch console special sausages. */
839 cio_is_console(struct subchannel_id schid
)
841 if (!console_subchannel_in_use
)
843 return schid_equal(&schid
, &console_subchannel
.schid
);
847 cio_get_console_subchannel(void)
849 if (!console_subchannel_in_use
)
851 return &console_subchannel
;
856 __disable_subchannel_easy(struct subchannel_id schid
, struct schib
*schib
)
861 for (retry
=0;retry
<3;retry
++) {
863 cc
= msch_err(schid
, schib
);
865 return (cc
==3?-ENODEV
:-EBUSY
);
866 if (stsch_err(schid
, schib
) || !css_sch_is_valid(schib
))
868 if (!schib
->pmcw
.ena
)
871 return -EBUSY
; /* uhm... */
875 __clear_io_subchannel_easy(struct subchannel_id schid
)
881 for (retry
=0;retry
<20;retry
++) {
885 tsch(ti
.schid
, (struct irb
*)&S390_lowcore
.irb
);
886 if (schid_equal(&ti
.schid
, &schid
))
894 static void __clear_chsc_subchannel_easy(void)
896 /* It seems we can only wait for a bit here :/ */
900 static int pgm_check_occured
;
902 static void cio_reset_pgm_check_handler(void)
904 pgm_check_occured
= 1;
907 static int stsch_reset(struct subchannel_id schid
, struct schib
*addr
)
911 pgm_check_occured
= 0;
912 s390_base_pgm_handler_fn
= cio_reset_pgm_check_handler
;
913 rc
= stsch_err(schid
, addr
);
914 s390_base_pgm_handler_fn
= NULL
;
916 /* The program check handler could have changed pgm_check_occured. */
919 if (pgm_check_occured
)
925 static int __shutdown_subchannel_easy(struct subchannel_id schid
, void *data
)
929 if (stsch_reset(schid
, &schib
))
933 switch(__disable_subchannel_easy(schid
, &schib
)) {
937 default: /* -EBUSY */
938 switch (schib
.pmcw
.st
) {
939 case SUBCHANNEL_TYPE_IO
:
940 if (__clear_io_subchannel_easy(schid
))
941 goto out
; /* give up... */
943 case SUBCHANNEL_TYPE_CHSC
:
944 __clear_chsc_subchannel_easy();
947 /* No default clear strategy */
950 stsch_err(schid
, &schib
);
951 __disable_subchannel_easy(schid
, &schib
);
957 static atomic_t chpid_reset_count
;
959 static void s390_reset_chpids_mcck_handler(void)
964 /* Check for pending channel report word. */
965 mci
= (struct mci
*)&S390_lowcore
.mcck_interruption_code
;
968 /* Process channel report words. */
969 while (stcrw(&crw
) == 0) {
970 /* Check for responses to RCHP. */
971 if (crw
.slct
&& crw
.rsc
== CRW_RSC_CPATH
)
972 atomic_dec(&chpid_reset_count
);
976 #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
977 static void css_reset(void)
980 unsigned long long timeout
;
983 /* Reset subchannels. */
984 for_each_subchannel(__shutdown_subchannel_easy
, NULL
);
985 /* Reset channel paths. */
986 s390_base_mcck_handler_fn
= s390_reset_chpids_mcck_handler
;
987 /* Enable channel report machine checks. */
988 __ctl_set_bit(14, 28);
989 /* Temporarily reenable machine checks. */
992 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
995 if ((ret
== 0) || (ret
== 2))
997 * rchp either succeeded, or another rchp is already
998 * in progress. In either case, we'll get a crw.
1000 atomic_inc(&chpid_reset_count
);
1002 /* Wait for machine check for all channel paths. */
1003 timeout
= get_clock() + (RCHP_TIMEOUT
<< 12);
1004 while (atomic_read(&chpid_reset_count
) != 0) {
1005 if (get_clock() > timeout
)
1009 /* Disable machine checks again. */
1010 local_mcck_disable();
1011 /* Disable channel report machine checks. */
1012 __ctl_clear_bit(14, 28);
1013 s390_base_mcck_handler_fn
= NULL
;
1016 static struct reset_call css_reset_call
= {
1020 static int __init
init_css_reset_call(void)
1022 atomic_set(&chpid_reset_count
, 0);
1023 register_reset_call(&css_reset_call
);
1027 arch_initcall(init_css_reset_call
);
1029 struct sch_match_id
{
1030 struct subchannel_id schid
;
1031 struct ccw_dev_id devid
;
1035 static int __reipl_subchannel_match(struct subchannel_id schid
, void *data
)
1038 struct sch_match_id
*match_id
= data
;
1040 if (stsch_reset(schid
, &schib
))
1042 if ((schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) && schib
.pmcw
.dnv
&&
1043 (schib
.pmcw
.dev
== match_id
->devid
.devno
) &&
1044 (schid
.ssid
== match_id
->devid
.ssid
)) {
1045 match_id
->schid
= schid
;
1052 static int reipl_find_schid(struct ccw_dev_id
*devid
,
1053 struct subchannel_id
*schid
)
1055 struct sch_match_id match_id
;
1057 match_id
.devid
= *devid
;
1058 match_id
.rc
= -ENODEV
;
1059 for_each_subchannel(__reipl_subchannel_match
, &match_id
);
1060 if (match_id
.rc
== 0)
1061 *schid
= match_id
.schid
;
1065 extern void do_reipl_asm(__u32 schid
);
1067 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
1068 void reipl_ccw_dev(struct ccw_dev_id
*devid
)
1070 struct subchannel_id schid
;
1072 s390_reset_system(NULL
, NULL
);
1073 if (reipl_find_schid(devid
, &schid
) != 0)
1074 panic("IPL Device not found\n");
1075 do_reipl_asm(*((__u32
*)&schid
));
1078 int __init
cio_get_iplinfo(struct cio_iplinfo
*iplinfo
)
1080 struct subchannel_id schid
;
1083 schid
= *(struct subchannel_id
*)&S390_lowcore
.subchannel_id
;
1086 if (stsch_err(schid
, &schib
))
1088 if (schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
)
1090 if (!schib
.pmcw
.dnv
)
1092 iplinfo
->devno
= schib
.pmcw
.dev
;
1093 iplinfo
->is_qdio
= schib
.pmcw
.qf
;
1098 * cio_tm_start_key - perform start function
1099 * @sch: subchannel on which to perform the start function
1100 * @tcw: transport-command word to be started
1101 * @lpm: mask of paths to use
1102 * @key: storage key to use for storage access
1104 * Start the tcw on the given subchannel. Return zero on success, non-zero
1107 int cio_tm_start_key(struct subchannel
*sch
, struct tcw
*tcw
, u8 lpm
, u8 key
)
1110 union orb
*orb
= &to_io_private(sch
)->orb
;
1112 memset(orb
, 0, sizeof(union orb
));
1113 orb
->tm
.intparm
= (u32
) (addr_t
) sch
;
1114 orb
->tm
.key
= key
>> 4;
1116 orb
->tm
.lpm
= lpm
? lpm
: sch
->lpm
;
1117 orb
->tm
.tcw
= (u32
) (addr_t
) tcw
;
1118 cc
= ssch(sch
->schid
, orb
);
1126 return cio_start_handle_notoper(sch
, lpm
);
1131 * cio_tm_intrg - perform interrogate function
1132 * @sch - subchannel on which to perform the interrogate function
1134 * If the specified subchannel is running in transport-mode, perform the
1135 * interrogate function. Return zero on success, non-zero otherwie.
1137 int cio_tm_intrg(struct subchannel
*sch
)
1141 if (!to_io_private(sch
)->orb
.tm
.b
)
1143 cc
= xsch(sch
->schid
);