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 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/device.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/interrupt.h>
19 #include <asm/delay.h>
21 #include <asm/irq_regs.h>
22 #include <asm/setup.h>
23 #include <asm/reset.h>
25 #include <asm/chpid.h>
35 #include "blacklist.h"
36 #include "cio_debug.h"
38 #include "../s390mach.h"
40 debug_info_t
*cio_debug_msg_id
;
41 debug_info_t
*cio_debug_trace_id
;
42 debug_info_t
*cio_debug_crw_id
;
45 * Function: cio_debug_init
46 * Initializes three debug logs for common I/O:
47 * - cio_msg logs generic cio messages
48 * - cio_trace logs the calling of different functions
49 * - cio_crw logs machine check related cio messages
51 static int __init
cio_debug_init(void)
53 cio_debug_msg_id
= debug_register("cio_msg", 16, 1, 16 * sizeof(long));
54 if (!cio_debug_msg_id
)
56 debug_register_view(cio_debug_msg_id
, &debug_sprintf_view
);
57 debug_set_level(cio_debug_msg_id
, 2);
58 cio_debug_trace_id
= debug_register("cio_trace", 16, 1, 16);
59 if (!cio_debug_trace_id
)
61 debug_register_view(cio_debug_trace_id
, &debug_hex_ascii_view
);
62 debug_set_level(cio_debug_trace_id
, 2);
63 cio_debug_crw_id
= debug_register("cio_crw", 16, 1, 16 * sizeof(long));
64 if (!cio_debug_crw_id
)
66 debug_register_view(cio_debug_crw_id
, &debug_sprintf_view
);
67 debug_set_level(cio_debug_crw_id
, 4);
72 debug_unregister(cio_debug_msg_id
);
73 if (cio_debug_trace_id
)
74 debug_unregister(cio_debug_trace_id
);
76 debug_unregister(cio_debug_crw_id
);
80 arch_initcall (cio_debug_init
);
83 cio_set_options (struct subchannel
*sch
, int flags
)
85 sch
->options
.suspend
= (flags
& DOIO_ALLOW_SUSPEND
) != 0;
86 sch
->options
.prefetch
= (flags
& DOIO_DENY_PREFETCH
) != 0;
87 sch
->options
.inter
= (flags
& DOIO_SUPPRESS_INTER
) != 0;
91 /* FIXME: who wants to use this? */
93 cio_get_options (struct subchannel
*sch
)
98 if (sch
->options
.suspend
)
99 flags
|= DOIO_ALLOW_SUSPEND
;
100 if (sch
->options
.prefetch
)
101 flags
|= DOIO_DENY_PREFETCH
;
102 if (sch
->options
.inter
)
103 flags
|= DOIO_SUPPRESS_INTER
;
108 * Use tpi to get a pending interrupt, call the interrupt handler and
109 * return a pointer to the subchannel structure.
114 struct tpi_info
*tpi_info
;
115 struct subchannel
*sch
;
119 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
122 irb
= (struct irb
*) __LC_IRB
;
123 /* Store interrupt response block to lowcore. */
124 if (tsch (tpi_info
->schid
, irb
) != 0)
125 /* Not status pending or not operational. */
127 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
130 irq_context
= in_interrupt();
134 spin_lock(sch
->lock
);
135 memcpy(&sch
->schib
.scsw
, &irb
->scsw
, sizeof(union scsw
));
136 if (sch
->driver
&& sch
->driver
->irq
)
137 sch
->driver
->irq(sch
);
138 spin_unlock(sch
->lock
);
146 cio_start_handle_notoper(struct subchannel
*sch
, __u8 lpm
)
155 stsch (sch
->schid
, &sch
->schib
);
157 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
158 "subchannel 0.%x.%04x!\n", sch
->schid
.ssid
,
160 sprintf(dbf_text
, "no%s", dev_name(&sch
->dev
));
161 CIO_TRACE_EVENT(0, dbf_text
);
162 CIO_HEX_EVENT(0, &sch
->schib
, sizeof (struct schib
));
164 return (sch
->lpm
? -EACCES
: -ENODEV
);
168 cio_start_key (struct subchannel
*sch
, /* subchannel structure */
169 struct ccw1
* cpa
, /* logical channel prog addr */
170 __u8 lpm
, /* logical path mask */
171 __u8 key
) /* storage key */
177 CIO_TRACE_EVENT(4, "stIO");
178 CIO_TRACE_EVENT(4, dev_name(&sch
->dev
));
180 orb
= &to_io_private(sch
)->orb
;
181 memset(orb
, 0, sizeof(union orb
));
182 /* sch is always under 2G. */
183 orb
->cmd
.intparm
= (u32
)(addr_t
)sch
;
186 orb
->cmd
.pfch
= sch
->options
.prefetch
== 0;
187 orb
->cmd
.spnd
= sch
->options
.suspend
;
188 orb
->cmd
.ssic
= sch
->options
.suspend
&& sch
->options
.inter
;
189 orb
->cmd
.lpm
= (lpm
!= 0) ? lpm
: sch
->lpm
;
192 * for 64 bit we always support 64 bit IDAWs with 4k page size only
197 orb
->cmd
.key
= key
>> 4;
198 /* issue "Start Subchannel" */
199 orb
->cmd
.cpa
= (__u32
) __pa(cpa
);
200 ccode
= ssch(sch
->schid
, orb
);
202 /* process condition code */
203 sprintf(dbf_txt
, "ccode:%d", ccode
);
204 CIO_TRACE_EVENT(4, dbf_txt
);
209 * initialize device status information
211 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_START_PEND
;
213 case 1: /* status pending */
216 case 3: /* device/path not operational */
217 return cio_start_handle_notoper(sch
, lpm
);
224 cio_start (struct subchannel
*sch
, struct ccw1
*cpa
, __u8 lpm
)
226 return cio_start_key(sch
, cpa
, lpm
, PAGE_DEFAULT_KEY
);
230 * resume suspended I/O operation
233 cio_resume (struct subchannel
*sch
)
238 CIO_TRACE_EVENT (4, "resIO");
239 CIO_TRACE_EVENT(4, dev_name(&sch
->dev
));
241 ccode
= rsch (sch
->schid
);
243 sprintf (dbf_txt
, "ccode:%d", ccode
);
244 CIO_TRACE_EVENT (4, dbf_txt
);
248 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_RESUME_PEND
;
256 * useless to wait for request completion
257 * as device is no longer operational !
267 cio_halt(struct subchannel
*sch
)
275 CIO_TRACE_EVENT (2, "haltIO");
276 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
279 * Issue "Halt subchannel" and process condition code
281 ccode
= hsch (sch
->schid
);
283 sprintf (dbf_txt
, "ccode:%d", ccode
);
284 CIO_TRACE_EVENT (2, dbf_txt
);
288 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_HALT_PEND
;
290 case 1: /* status pending */
293 default: /* device not operational */
299 * Clear I/O operation
302 cio_clear(struct subchannel
*sch
)
310 CIO_TRACE_EVENT (2, "clearIO");
311 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
314 * Issue "Clear subchannel" and process condition code
316 ccode
= csch (sch
->schid
);
318 sprintf (dbf_txt
, "ccode:%d", ccode
);
319 CIO_TRACE_EVENT (2, dbf_txt
);
323 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_CLEAR_PEND
;
325 default: /* device not operational */
331 * Function: cio_cancel
332 * Issues a "Cancel Subchannel" on the specified subchannel
333 * Note: We don't need any fancy intparms and flags here
334 * since xsch is executed synchronously.
335 * Only for common I/O internal use as for now.
338 cio_cancel (struct subchannel
*sch
)
346 CIO_TRACE_EVENT (2, "cancelIO");
347 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
349 ccode
= xsch (sch
->schid
);
351 sprintf (dbf_txt
, "ccode:%d", ccode
);
352 CIO_TRACE_EVENT (2, dbf_txt
);
355 case 0: /* success */
356 /* Update information in scsw. */
357 stsch (sch
->schid
, &sch
->schib
);
359 case 1: /* status pending */
361 case 2: /* not applicable */
363 default: /* not oper */
369 * Function: cio_modify
370 * Issues a "Modify Subchannel" on the specified subchannel
373 cio_modify (struct subchannel
*sch
)
375 int ccode
, retry
, ret
;
378 for (retry
= 0; retry
< 5; retry
++) {
379 ccode
= msch_err (sch
->schid
, &sch
->schib
);
380 if (ccode
< 0) /* -EIO if msch gets a program check. */
383 case 0: /* successfull */
385 case 1: /* status pending */
388 udelay (100); /* allow for recovery */
391 case 3: /* not operational */
399 * cio_enable_subchannel - enable a subchannel.
400 * @sch: subchannel to be enabled
401 * @intparm: interruption parameter to set
403 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 ccode
= stsch (sch
->schid
, &sch
->schib
);
419 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
420 sch
->schib
.pmcw
.ena
= 1;
421 sch
->schib
.pmcw
.isc
= sch
->isc
;
422 sch
->schib
.pmcw
.intparm
= intparm
;
423 ret
= cio_modify(sch
);
428 * Got a program check in cio_modify. Try without
429 * the concurrent sense bit the next time.
431 sch
->schib
.pmcw
.csense
= 0;
433 stsch (sch
->schid
, &sch
->schib
);
434 if (sch
->schib
.pmcw
.ena
)
439 if (tsch(sch
->schid
, &irb
) != 0)
443 sprintf (dbf_txt
, "ret:%d", ret
);
444 CIO_TRACE_EVENT (2, dbf_txt
);
447 EXPORT_SYMBOL_GPL(cio_enable_subchannel
);
450 * cio_disable_subchannel - disable a subchannel.
451 * @sch: subchannel to disable
453 int cio_disable_subchannel(struct subchannel
*sch
)
460 CIO_TRACE_EVENT (2, "dissch");
461 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
463 if (sch_is_pseudo_sch(sch
))
465 ccode
= stsch (sch
->schid
, &sch
->schib
);
466 if (ccode
== 3) /* Not operational. */
469 if (scsw_actl(&sch
->schib
.scsw
) != 0)
471 * the disable function must not be called while there are
472 * requests pending for completion !
476 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
477 sch
->schib
.pmcw
.ena
= 0;
478 ret
= cio_modify(sch
);
483 * The subchannel is busy or status pending.
484 * We'll disable when the next interrupt was delivered
485 * via the state machine.
489 stsch (sch
->schid
, &sch
->schib
);
490 if (!sch
->schib
.pmcw
.ena
)
494 sprintf (dbf_txt
, "ret:%d", ret
);
495 CIO_TRACE_EVENT (2, dbf_txt
);
498 EXPORT_SYMBOL_GPL(cio_disable_subchannel
);
500 int cio_create_sch_lock(struct subchannel
*sch
)
502 sch
->lock
= kmalloc(sizeof(spinlock_t
), GFP_KERNEL
);
505 spin_lock_init(sch
->lock
);
509 static int cio_check_devno_blacklisted(struct subchannel
*sch
)
511 if (is_blacklisted(sch
->schid
.ssid
, sch
->schib
.pmcw
.dev
)) {
513 * This device must not be known to Linux. So we simply
514 * say that there is no device and return ENODEV.
516 CIO_MSG_EVENT(6, "Blacklisted device detected "
517 "at devno %04X, subchannel set %x\n",
518 sch
->schib
.pmcw
.dev
, sch
->schid
.ssid
);
524 static int cio_validate_io_subchannel(struct subchannel
*sch
)
526 /* Initialization for io subchannels. */
527 if (!css_sch_is_valid(&sch
->schib
))
530 /* Devno is valid. */
531 return cio_check_devno_blacklisted(sch
);
534 static int cio_validate_msg_subchannel(struct subchannel
*sch
)
536 /* Initialization for message subchannels. */
537 if (!css_sch_is_valid(&sch
->schib
))
540 /* Devno is valid. */
541 return cio_check_devno_blacklisted(sch
);
545 * cio_validate_subchannel - basic validation of subchannel
546 * @sch: subchannel structure to be filled out
547 * @schid: subchannel id
549 * Find out subchannel type and initialize struct subchannel.
552 * -ENXIO for non-defined subchannels
553 * -ENODEV for invalid subchannels or blacklisted devices
554 * -EIO for subchannels in an invalid subchannel set
556 int cio_validate_subchannel(struct subchannel
*sch
, struct subchannel_id schid
)
562 sprintf(dbf_txt
, "valsch%x", schid
.sch_no
);
563 CIO_TRACE_EVENT(4, dbf_txt
);
565 /* Nuke all fields. */
566 memset(sch
, 0, sizeof(struct subchannel
));
569 if (cio_is_console(schid
)) {
570 sch
->lock
= cio_get_console_lock();
572 err
= cio_create_sch_lock(sch
);
576 mutex_init(&sch
->reg_mutex
);
577 /* Set a name for the subchannel */
578 if (cio_is_console(schid
))
579 sch
->dev
.init_name
= cio_get_console_sch_name(schid
);
581 dev_set_name(&sch
->dev
, "0.%x.%04x", schid
.ssid
, schid
.sch_no
);
584 * The first subchannel that is not-operational (ccode==3)
585 * indicates that there aren't any more devices available.
586 * If stsch gets an exception, it means the current subchannel set
589 ccode
= stsch_err (schid
, &sch
->schib
);
591 err
= (ccode
== 3) ? -ENXIO
: ccode
;
594 /* Copy subchannel type from path management control word. */
595 sch
->st
= sch
->schib
.pmcw
.st
;
598 case SUBCHANNEL_TYPE_IO
:
599 err
= cio_validate_io_subchannel(sch
);
601 case SUBCHANNEL_TYPE_MSG
:
602 err
= cio_validate_msg_subchannel(sch
);
610 CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
611 sch
->schid
.ssid
, sch
->schid
.sch_no
, sch
->st
);
614 if (!cio_is_console(schid
))
621 * do_IRQ() handles all normal I/O device IRQ's (the special
622 * SMP cross-CPU interrupts have their own specific
627 do_IRQ (struct pt_regs
*regs
)
629 struct tpi_info
*tpi_info
;
630 struct subchannel
*sch
;
632 struct pt_regs
*old_regs
;
634 old_regs
= set_irq_regs(regs
);
637 if (S390_lowcore
.int_clock
>= S390_lowcore
.clock_comparator
)
638 /* Serve timer interrupts first. */
639 clock_comparator_work();
641 * Get interrupt information from lowcore
643 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
644 irb
= (struct irb
*) __LC_IRB
;
646 kstat_cpu(smp_processor_id()).irqs
[IO_INTERRUPT
]++;
648 * Non I/O-subchannel thin interrupts are processed differently
650 if (tpi_info
->adapter_IO
== 1 &&
651 tpi_info
->int_type
== IO_INTERRUPT_TYPE
) {
652 do_adapter_IO(tpi_info
->isc
);
655 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
657 /* Clear pending interrupt condition. */
658 tsch(tpi_info
->schid
, irb
);
661 spin_lock(sch
->lock
);
662 /* Store interrupt response block to lowcore. */
663 if (tsch(tpi_info
->schid
, irb
) == 0) {
664 /* Keep subchannel information word up to date. */
665 memcpy (&sch
->schib
.scsw
, &irb
->scsw
,
667 /* Call interrupt handler if there is one. */
668 if (sch
->driver
&& sch
->driver
->irq
)
669 sch
->driver
->irq(sch
);
671 spin_unlock(sch
->lock
);
673 * Are more interrupts pending?
674 * If so, the tpi instruction will update the lowcore
675 * to hold the info for the next interrupt.
676 * We don't do this for VM because a tpi drops the cpu
677 * out of the sie which costs more cycles than it saves.
679 } while (!MACHINE_IS_VM
&& tpi (NULL
) != 0);
681 set_irq_regs(old_regs
);
684 #ifdef CONFIG_CCW_CONSOLE
685 static struct subchannel console_subchannel
;
686 static char console_sch_name
[10] = "0.x.xxxx";
687 static struct io_subchannel_private console_priv
;
688 static int console_subchannel_in_use
;
690 void *cio_get_console_priv(void)
692 return &console_priv
;
696 * busy wait for the next interrupt on the console
698 void wait_cons_dev(void)
699 __releases(console_subchannel
.lock
)
700 __acquires(console_subchannel
.lock
)
702 unsigned long cr6
__attribute__ ((aligned (8)));
703 unsigned long save_cr6
__attribute__ ((aligned (8)));
706 * before entering the spinlock we may already have
707 * processed the interrupt on a different CPU...
709 if (!console_subchannel_in_use
)
712 /* disable all but the console isc */
713 __ctl_store (save_cr6
, 6, 6);
714 cr6
= 1UL << (31 - CONSOLE_ISC
);
715 __ctl_load (cr6
, 6, 6);
718 spin_unlock(console_subchannel
.lock
);
721 spin_lock(console_subchannel
.lock
);
722 } while (console_subchannel
.schib
.scsw
.cmd
.actl
!= 0);
724 * restore previous isc value
726 __ctl_load (save_cr6
, 6, 6);
730 cio_test_for_console(struct subchannel_id schid
, void *data
)
732 if (stsch_err(schid
, &console_subchannel
.schib
) != 0)
734 if ((console_subchannel
.schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) &&
735 console_subchannel
.schib
.pmcw
.dnv
&&
736 (console_subchannel
.schib
.pmcw
.dev
== console_devno
)) {
737 console_irq
= schid
.sch_no
;
738 return 1; /* found */
745 cio_get_console_sch_no(void)
747 struct subchannel_id schid
;
749 init_subchannel_id(&schid
);
750 if (console_irq
!= -1) {
751 /* VM provided us with the irq number of the console. */
752 schid
.sch_no
= console_irq
;
753 if (stsch(schid
, &console_subchannel
.schib
) != 0 ||
754 (console_subchannel
.schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
) ||
755 !console_subchannel
.schib
.pmcw
.dnv
)
757 console_devno
= console_subchannel
.schib
.pmcw
.dev
;
758 } else if (console_devno
!= -1) {
759 /* At least the console device number is known. */
760 for_each_subchannel(cio_test_for_console
, NULL
);
761 if (console_irq
== -1)
764 /* unlike in 2.4, we cannot autoprobe here, since
765 * the channel subsystem is not fully initialized.
766 * With some luck, the HWC console can take over */
773 cio_probe_console(void)
776 struct subchannel_id schid
;
778 if (xchg(&console_subchannel_in_use
, 1) != 0)
779 return ERR_PTR(-EBUSY
);
780 sch_no
= cio_get_console_sch_no();
782 console_subchannel_in_use
= 0;
783 printk(KERN_WARNING
"cio: No ccw console found!\n");
784 return ERR_PTR(-ENODEV
);
786 memset(&console_subchannel
, 0, sizeof(struct subchannel
));
787 init_subchannel_id(&schid
);
788 schid
.sch_no
= sch_no
;
789 ret
= cio_validate_subchannel(&console_subchannel
, schid
);
791 console_subchannel_in_use
= 0;
792 return ERR_PTR(-ENODEV
);
796 * enable console I/O-interrupt subclass
798 isc_register(CONSOLE_ISC
);
799 console_subchannel
.schib
.pmcw
.isc
= CONSOLE_ISC
;
800 console_subchannel
.schib
.pmcw
.intparm
=
801 (u32
)(addr_t
)&console_subchannel
;
802 ret
= cio_modify(&console_subchannel
);
804 isc_unregister(CONSOLE_ISC
);
805 console_subchannel_in_use
= 0;
808 return &console_subchannel
;
812 cio_release_console(void)
814 console_subchannel
.schib
.pmcw
.intparm
= 0;
815 cio_modify(&console_subchannel
);
816 isc_unregister(CONSOLE_ISC
);
817 console_subchannel_in_use
= 0;
820 /* Bah... hack to catch console special sausages. */
822 cio_is_console(struct subchannel_id schid
)
824 if (!console_subchannel_in_use
)
826 return schid_equal(&schid
, &console_subchannel
.schid
);
830 cio_get_console_subchannel(void)
832 if (!console_subchannel_in_use
)
834 return &console_subchannel
;
837 const char *cio_get_console_sch_name(struct subchannel_id schid
)
839 snprintf(console_sch_name
, 10, "0.%x.%04x", schid
.ssid
, schid
.sch_no
);
840 return (const char *)console_sch_name
;
845 __disable_subchannel_easy(struct subchannel_id schid
, struct schib
*schib
)
850 for (retry
=0;retry
<3;retry
++) {
852 cc
= msch(schid
, schib
);
854 return (cc
==3?-ENODEV
:-EBUSY
);
856 if (!schib
->pmcw
.ena
)
859 return -EBUSY
; /* uhm... */
863 __clear_io_subchannel_easy(struct subchannel_id schid
)
869 for (retry
=0;retry
<20;retry
++) {
873 tsch(ti
.schid
, (struct irb
*)__LC_IRB
);
874 if (schid_equal(&ti
.schid
, &schid
))
882 static void __clear_chsc_subchannel_easy(void)
884 /* It seems we can only wait for a bit here :/ */
888 static int pgm_check_occured
;
890 static void cio_reset_pgm_check_handler(void)
892 pgm_check_occured
= 1;
895 static int stsch_reset(struct subchannel_id schid
, struct schib
*addr
)
899 pgm_check_occured
= 0;
900 s390_base_pgm_handler_fn
= cio_reset_pgm_check_handler
;
901 rc
= stsch(schid
, addr
);
902 s390_base_pgm_handler_fn
= NULL
;
904 /* The program check handler could have changed pgm_check_occured. */
907 if (pgm_check_occured
)
913 static int __shutdown_subchannel_easy(struct subchannel_id schid
, void *data
)
917 if (stsch_reset(schid
, &schib
))
921 switch(__disable_subchannel_easy(schid
, &schib
)) {
925 default: /* -EBUSY */
926 switch (schib
.pmcw
.st
) {
927 case SUBCHANNEL_TYPE_IO
:
928 if (__clear_io_subchannel_easy(schid
))
929 goto out
; /* give up... */
931 case SUBCHANNEL_TYPE_CHSC
:
932 __clear_chsc_subchannel_easy();
935 /* No default clear strategy */
938 stsch(schid
, &schib
);
939 __disable_subchannel_easy(schid
, &schib
);
945 static atomic_t chpid_reset_count
;
947 static void s390_reset_chpids_mcck_handler(void)
952 /* Check for pending channel report word. */
953 mci
= (struct mci
*)&S390_lowcore
.mcck_interruption_code
;
956 /* Process channel report words. */
957 while (stcrw(&crw
) == 0) {
958 /* Check for responses to RCHP. */
959 if (crw
.slct
&& crw
.rsc
== CRW_RSC_CPATH
)
960 atomic_dec(&chpid_reset_count
);
964 #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
965 static void css_reset(void)
968 unsigned long long timeout
;
971 /* Reset subchannels. */
972 for_each_subchannel(__shutdown_subchannel_easy
, NULL
);
973 /* Reset channel paths. */
974 s390_base_mcck_handler_fn
= s390_reset_chpids_mcck_handler
;
975 /* Enable channel report machine checks. */
976 __ctl_set_bit(14, 28);
977 /* Temporarily reenable machine checks. */
980 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
983 if ((ret
== 0) || (ret
== 2))
985 * rchp either succeeded, or another rchp is already
986 * in progress. In either case, we'll get a crw.
988 atomic_inc(&chpid_reset_count
);
990 /* Wait for machine check for all channel paths. */
991 timeout
= get_clock() + (RCHP_TIMEOUT
<< 12);
992 while (atomic_read(&chpid_reset_count
) != 0) {
993 if (get_clock() > timeout
)
997 /* Disable machine checks again. */
998 local_mcck_disable();
999 /* Disable channel report machine checks. */
1000 __ctl_clear_bit(14, 28);
1001 s390_base_mcck_handler_fn
= NULL
;
1004 static struct reset_call css_reset_call
= {
1008 static int __init
init_css_reset_call(void)
1010 atomic_set(&chpid_reset_count
, 0);
1011 register_reset_call(&css_reset_call
);
1015 arch_initcall(init_css_reset_call
);
1017 struct sch_match_id
{
1018 struct subchannel_id schid
;
1019 struct ccw_dev_id devid
;
1023 static int __reipl_subchannel_match(struct subchannel_id schid
, void *data
)
1026 struct sch_match_id
*match_id
= data
;
1028 if (stsch_reset(schid
, &schib
))
1030 if ((schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) && schib
.pmcw
.dnv
&&
1031 (schib
.pmcw
.dev
== match_id
->devid
.devno
) &&
1032 (schid
.ssid
== match_id
->devid
.ssid
)) {
1033 match_id
->schid
= schid
;
1040 static int reipl_find_schid(struct ccw_dev_id
*devid
,
1041 struct subchannel_id
*schid
)
1043 struct sch_match_id match_id
;
1045 match_id
.devid
= *devid
;
1046 match_id
.rc
= -ENODEV
;
1047 for_each_subchannel(__reipl_subchannel_match
, &match_id
);
1048 if (match_id
.rc
== 0)
1049 *schid
= match_id
.schid
;
1053 extern void do_reipl_asm(__u32 schid
);
1055 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
1056 void reipl_ccw_dev(struct ccw_dev_id
*devid
)
1058 struct subchannel_id schid
;
1060 s390_reset_system();
1061 if (reipl_find_schid(devid
, &schid
) != 0)
1062 panic("IPL Device not found\n");
1063 do_reipl_asm(*((__u32
*)&schid
));
1066 int __init
cio_get_iplinfo(struct cio_iplinfo
*iplinfo
)
1068 struct subchannel_id schid
;
1071 schid
= *(struct subchannel_id
*)__LC_SUBCHANNEL_ID
;
1074 if (stsch(schid
, &schib
))
1076 if (schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
)
1078 if (!schib
.pmcw
.dnv
)
1080 iplinfo
->devno
= schib
.pmcw
.dev
;
1081 iplinfo
->is_qdio
= schib
.pmcw
.qf
;
1086 * cio_tm_start_key - perform start function
1087 * @sch: subchannel on which to perform the start function
1088 * @tcw: transport-command word to be started
1089 * @lpm: mask of paths to use
1090 * @key: storage key to use for storage access
1092 * Start the tcw on the given subchannel. Return zero on success, non-zero
1095 int cio_tm_start_key(struct subchannel
*sch
, struct tcw
*tcw
, u8 lpm
, u8 key
)
1098 union orb
*orb
= &to_io_private(sch
)->orb
;
1100 memset(orb
, 0, sizeof(union orb
));
1101 orb
->tm
.intparm
= (u32
) (addr_t
) sch
;
1102 orb
->tm
.key
= key
>> 4;
1104 orb
->tm
.lpm
= lpm
? lpm
: sch
->lpm
;
1105 orb
->tm
.tcw
= (u32
) (addr_t
) tcw
;
1106 cc
= ssch(sch
->schid
, orb
);
1114 return cio_start_handle_notoper(sch
, lpm
);
1119 * cio_tm_intrg - perform interrogate function
1120 * @sch - subchannel on which to perform the interrogate function
1122 * If the specified subchannel is running in transport-mode, perform the
1123 * interrogate function. Return zero on success, non-zero otherwie.
1125 int cio_tm_intrg(struct subchannel
*sch
)
1129 if (!to_io_private(sch
)->orb
.tm
.b
)
1131 cc
= xsch(sch
->schid
);