2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls
5 * Copyright (C) IBM Corp. 1999,2006
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>
31 #include "blacklist.h"
32 #include "cio_debug.h"
34 #include "../s390mach.h"
36 debug_info_t
*cio_debug_msg_id
;
37 debug_info_t
*cio_debug_trace_id
;
38 debug_info_t
*cio_debug_crw_id
;
43 cio_setup (char *parm
)
45 if (!strcmp (parm
, "yes"))
47 else if (!strcmp (parm
, "no"))
50 printk(KERN_ERR
"cio: cio_setup: "
51 "invalid cio_msg parameter '%s'", parm
);
55 __setup ("cio_msg=", cio_setup
);
58 * Function: cio_debug_init
59 * Initializes three debug logs (under /proc/s390dbf) for common I/O:
60 * - cio_msg logs the messages which are printk'ed when CONFIG_DEBUG_IO is on
61 * - cio_trace logs the calling of different functions
62 * - cio_crw logs the messages which are printk'ed when CONFIG_DEBUG_CRW is on
63 * debug levels depend on CONFIG_DEBUG_IO resp. CONFIG_DEBUG_CRW
68 cio_debug_msg_id
= debug_register ("cio_msg", 16, 4, 16*sizeof (long));
69 if (!cio_debug_msg_id
)
71 debug_register_view (cio_debug_msg_id
, &debug_sprintf_view
);
72 debug_set_level (cio_debug_msg_id
, 2);
73 cio_debug_trace_id
= debug_register ("cio_trace", 16, 4, 16);
74 if (!cio_debug_trace_id
)
76 debug_register_view (cio_debug_trace_id
, &debug_hex_ascii_view
);
77 debug_set_level (cio_debug_trace_id
, 2);
78 cio_debug_crw_id
= debug_register ("cio_crw", 4, 4, 16*sizeof (long));
79 if (!cio_debug_crw_id
)
81 debug_register_view (cio_debug_crw_id
, &debug_sprintf_view
);
82 debug_set_level (cio_debug_crw_id
, 2);
87 debug_unregister (cio_debug_msg_id
);
88 if (cio_debug_trace_id
)
89 debug_unregister (cio_debug_trace_id
);
91 debug_unregister (cio_debug_crw_id
);
92 printk(KERN_WARNING
"cio: could not initialize debugging\n");
96 arch_initcall (cio_debug_init
);
99 cio_set_options (struct subchannel
*sch
, int flags
)
101 sch
->options
.suspend
= (flags
& DOIO_ALLOW_SUSPEND
) != 0;
102 sch
->options
.prefetch
= (flags
& DOIO_DENY_PREFETCH
) != 0;
103 sch
->options
.inter
= (flags
& DOIO_SUPPRESS_INTER
) != 0;
107 /* FIXME: who wants to use this? */
109 cio_get_options (struct subchannel
*sch
)
114 if (sch
->options
.suspend
)
115 flags
|= DOIO_ALLOW_SUSPEND
;
116 if (sch
->options
.prefetch
)
117 flags
|= DOIO_DENY_PREFETCH
;
118 if (sch
->options
.inter
)
119 flags
|= DOIO_SUPPRESS_INTER
;
124 * Use tpi to get a pending interrupt, call the interrupt handler and
125 * return a pointer to the subchannel structure.
130 struct tpi_info
*tpi_info
;
131 struct subchannel
*sch
;
134 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
137 irb
= (struct irb
*) __LC_IRB
;
138 /* Store interrupt response block to lowcore. */
139 if (tsch (tpi_info
->schid
, irb
) != 0)
140 /* Not status pending or not operational. */
142 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
147 spin_lock(sch
->lock
);
148 memcpy (&sch
->schib
.scsw
, &irb
->scsw
, sizeof (struct scsw
));
149 if (sch
->driver
&& sch
->driver
->irq
)
150 sch
->driver
->irq(&sch
->dev
);
151 spin_unlock(sch
->lock
);
158 cio_start_handle_notoper(struct subchannel
*sch
, __u8 lpm
)
167 stsch (sch
->schid
, &sch
->schib
);
169 CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
170 "subchannel 0.%x.%04x!\n", sch
->schid
.ssid
,
172 sprintf(dbf_text
, "no%s", sch
->dev
.bus_id
);
173 CIO_TRACE_EVENT(0, dbf_text
);
174 CIO_HEX_EVENT(0, &sch
->schib
, sizeof (struct schib
));
176 return (sch
->lpm
? -EACCES
: -ENODEV
);
180 cio_start_key (struct subchannel
*sch
, /* subchannel structure */
181 struct ccw1
* cpa
, /* logical channel prog addr */
182 __u8 lpm
, /* logical path mask */
183 __u8 key
) /* storage key */
188 CIO_TRACE_EVENT (4, "stIO");
189 CIO_TRACE_EVENT (4, sch
->dev
.bus_id
);
191 /* sch is always under 2G. */
192 sch
->orb
.intparm
= (__u32
)(unsigned long)sch
;
195 sch
->orb
.pfch
= sch
->options
.prefetch
== 0;
196 sch
->orb
.spnd
= sch
->options
.suspend
;
197 sch
->orb
.ssic
= sch
->options
.suspend
&& sch
->options
.inter
;
198 sch
->orb
.lpm
= (lpm
!= 0) ? lpm
: sch
->lpm
;
201 * for 64 bit we always support 64 bit IDAWs with 4k page size only
206 sch
->orb
.key
= key
>> 4;
207 /* issue "Start Subchannel" */
208 sch
->orb
.cpa
= (__u32
) __pa (cpa
);
209 ccode
= ssch (sch
->schid
, &sch
->orb
);
211 /* process condition code */
212 sprintf (dbf_txt
, "ccode:%d", ccode
);
213 CIO_TRACE_EVENT (4, dbf_txt
);
218 * initialize device status information
220 sch
->schib
.scsw
.actl
|= SCSW_ACTL_START_PEND
;
222 case 1: /* status pending */
225 default: /* device/path not operational */
226 return cio_start_handle_notoper(sch
, lpm
);
231 cio_start (struct subchannel
*sch
, struct ccw1
*cpa
, __u8 lpm
)
233 return cio_start_key(sch
, cpa
, lpm
, PAGE_DEFAULT_KEY
);
237 * resume suspended I/O operation
240 cio_resume (struct subchannel
*sch
)
245 CIO_TRACE_EVENT (4, "resIO");
246 CIO_TRACE_EVENT (4, sch
->dev
.bus_id
);
248 ccode
= rsch (sch
->schid
);
250 sprintf (dbf_txt
, "ccode:%d", ccode
);
251 CIO_TRACE_EVENT (4, dbf_txt
);
255 sch
->schib
.scsw
.actl
|= SCSW_ACTL_RESUME_PEND
;
263 * useless to wait for request completion
264 * as device is no longer operational !
274 cio_halt(struct subchannel
*sch
)
282 CIO_TRACE_EVENT (2, "haltIO");
283 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
286 * Issue "Halt subchannel" and process condition code
288 ccode
= hsch (sch
->schid
);
290 sprintf (dbf_txt
, "ccode:%d", ccode
);
291 CIO_TRACE_EVENT (2, dbf_txt
);
295 sch
->schib
.scsw
.actl
|= SCSW_ACTL_HALT_PEND
;
297 case 1: /* status pending */
300 default: /* device not operational */
306 * Clear I/O operation
309 cio_clear(struct subchannel
*sch
)
317 CIO_TRACE_EVENT (2, "clearIO");
318 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
321 * Issue "Clear subchannel" and process condition code
323 ccode
= csch (sch
->schid
);
325 sprintf (dbf_txt
, "ccode:%d", ccode
);
326 CIO_TRACE_EVENT (2, dbf_txt
);
330 sch
->schib
.scsw
.actl
|= SCSW_ACTL_CLEAR_PEND
;
332 default: /* device not operational */
338 * Function: cio_cancel
339 * Issues a "Cancel Subchannel" on the specified subchannel
340 * Note: We don't need any fancy intparms and flags here
341 * since xsch is executed synchronously.
342 * Only for common I/O internal use as for now.
345 cio_cancel (struct subchannel
*sch
)
353 CIO_TRACE_EVENT (2, "cancelIO");
354 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
356 ccode
= xsch (sch
->schid
);
358 sprintf (dbf_txt
, "ccode:%d", ccode
);
359 CIO_TRACE_EVENT (2, dbf_txt
);
362 case 0: /* success */
363 /* Update information in scsw. */
364 stsch (sch
->schid
, &sch
->schib
);
366 case 1: /* status pending */
368 case 2: /* not applicable */
370 default: /* not oper */
376 * Function: cio_modify
377 * Issues a "Modify Subchannel" on the specified subchannel
380 cio_modify (struct subchannel
*sch
)
382 int ccode
, retry
, ret
;
385 for (retry
= 0; retry
< 5; retry
++) {
386 ccode
= msch_err (sch
->schid
, &sch
->schib
);
387 if (ccode
< 0) /* -EIO if msch gets a program check. */
390 case 0: /* successfull */
392 case 1: /* status pending */
395 udelay (100); /* allow for recovery */
398 case 3: /* not operational */
409 cio_enable_subchannel (struct subchannel
*sch
, unsigned int isc
)
416 CIO_TRACE_EVENT (2, "ensch");
417 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
419 if (sch_is_pseudo_sch(sch
))
421 ccode
= stsch (sch
->schid
, &sch
->schib
);
425 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
426 sch
->schib
.pmcw
.ena
= 1;
427 sch
->schib
.pmcw
.isc
= isc
;
428 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
429 ret
= cio_modify(sch
);
434 * Got a program check in cio_modify. Try without
435 * the concurrent sense bit the next time.
437 sch
->schib
.pmcw
.csense
= 0;
439 stsch (sch
->schid
, &sch
->schib
);
440 if (sch
->schib
.pmcw
.ena
)
445 if (tsch(sch
->schid
, &irb
) != 0)
449 sprintf (dbf_txt
, "ret:%d", ret
);
450 CIO_TRACE_EVENT (2, dbf_txt
);
455 * Disable subchannel.
458 cio_disable_subchannel (struct subchannel
*sch
)
465 CIO_TRACE_EVENT (2, "dissch");
466 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
468 if (sch_is_pseudo_sch(sch
))
470 ccode
= stsch (sch
->schid
, &sch
->schib
);
471 if (ccode
== 3) /* Not operational. */
474 if (sch
->schib
.scsw
.actl
!= 0)
476 * the disable function must not be called while there are
477 * requests pending for completion !
481 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
482 sch
->schib
.pmcw
.ena
= 0;
483 ret
= cio_modify(sch
);
488 * The subchannel is busy or status pending.
489 * We'll disable when the next interrupt was delivered
490 * via the state machine.
494 stsch (sch
->schid
, &sch
->schib
);
495 if (!sch
->schib
.pmcw
.ena
)
499 sprintf (dbf_txt
, "ret:%d", ret
);
500 CIO_TRACE_EVENT (2, dbf_txt
);
504 int cio_create_sch_lock(struct subchannel
*sch
)
506 sch
->lock
= kmalloc(sizeof(spinlock_t
), GFP_KERNEL
);
509 spin_lock_init(sch
->lock
);
514 * cio_validate_subchannel()
516 * Find out subchannel type and initialize struct subchannel.
518 * SUBCHANNEL_TYPE_IO for a normal io subchannel
519 * SUBCHANNEL_TYPE_CHSC for a chsc subchannel
520 * SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
521 * SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
522 * -ENXIO for non-defined subchannels
523 * -ENODEV for subchannels with invalid device number or blacklisted devices
526 cio_validate_subchannel (struct subchannel
*sch
, struct subchannel_id schid
)
532 sprintf (dbf_txt
, "valsch%x", schid
.sch_no
);
533 CIO_TRACE_EVENT (4, dbf_txt
);
535 /* Nuke all fields. */
536 memset(sch
, 0, sizeof(struct subchannel
));
539 if (cio_is_console(schid
)) {
540 sch
->lock
= cio_get_console_lock();
542 err
= cio_create_sch_lock(sch
);
546 mutex_init(&sch
->reg_mutex
);
547 /* Set a name for the subchannel */
548 snprintf (sch
->dev
.bus_id
, BUS_ID_SIZE
, "0.%x.%04x", schid
.ssid
,
552 * The first subchannel that is not-operational (ccode==3)
553 * indicates that there aren't any more devices available.
554 * If stsch gets an exception, it means the current subchannel set
557 ccode
= stsch_err (schid
, &sch
->schib
);
559 err
= (ccode
== 3) ? -ENXIO
: ccode
;
562 /* Copy subchannel type from path management control word. */
563 sch
->st
= sch
->schib
.pmcw
.st
;
566 * ... just being curious we check for non I/O subchannels
569 CIO_DEBUG(KERN_INFO
, 0,
570 "cio: Subchannel 0.%x.%04x reports "
571 "non-I/O subchannel type %04X\n",
572 sch
->schid
.ssid
, sch
->schid
.sch_no
, sch
->st
);
573 /* We stop here for non-io subchannels. */
578 /* Initialization for io subchannels. */
579 if (!sch
->schib
.pmcw
.dnv
) {
580 /* io subchannel but device number is invalid. */
584 /* Devno is valid. */
585 if (is_blacklisted (sch
->schid
.ssid
, sch
->schib
.pmcw
.dev
)) {
587 * This device must not be known to Linux. So we simply
588 * say that there is no device and return ENODEV.
590 CIO_MSG_EVENT(4, "Blacklisted device detected "
591 "at devno %04X, subchannel set %x\n",
592 sch
->schib
.pmcw
.dev
, sch
->schid
.ssid
);
596 if (cio_is_console(sch
->schid
))
599 sch
->opm
= chp_get_sch_opm(sch
);
600 sch
->lpm
= sch
->schib
.pmcw
.pam
& sch
->opm
;
602 CIO_DEBUG(KERN_INFO
, 0,
603 "cio: Detected device %04x on subchannel 0.%x.%04X"
604 " - PIM = %02X, PAM = %02X, POM = %02X\n",
605 sch
->schib
.pmcw
.dev
, sch
->schid
.ssid
,
606 sch
->schid
.sch_no
, sch
->schib
.pmcw
.pim
,
607 sch
->schib
.pmcw
.pam
, sch
->schib
.pmcw
.pom
);
610 * We now have to initially ...
611 * ... set "interruption subclass"
612 * ... enable "concurrent sense"
613 * ... enable "multipath mode" if more than one
614 * CHPID is available. This is done regardless
615 * whether multiple paths are available for us.
617 sch
->schib
.pmcw
.isc
= 3; /* could be smth. else */
618 sch
->schib
.pmcw
.csense
= 1; /* concurrent sense */
619 sch
->schib
.pmcw
.ena
= 0;
620 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
621 sch
->schib
.pmcw
.mp
= 1; /* multipath mode */
622 /* clean up possible residual cmf stuff */
623 sch
->schib
.pmcw
.mme
= 0;
624 sch
->schib
.pmcw
.mbfc
= 0;
625 sch
->schib
.pmcw
.mbi
= 0;
629 if (!cio_is_console(schid
))
636 * do_IRQ() handles all normal I/O device IRQ's (the special
637 * SMP cross-CPU interrupts have their own specific
642 do_IRQ (struct pt_regs
*regs
)
644 struct tpi_info
*tpi_info
;
645 struct subchannel
*sch
;
647 struct pt_regs
*old_regs
;
649 old_regs
= set_irq_regs(regs
);
651 asm volatile ("mc 0,0");
652 if (S390_lowcore
.int_clock
>= S390_lowcore
.jiffy_timer
)
654 * Make sure that the i/o interrupt did not "overtake"
655 * the last HZ timer interrupt.
657 account_ticks(S390_lowcore
.int_clock
);
659 * Get interrupt information from lowcore
661 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
662 irb
= (struct irb
*) __LC_IRB
;
664 kstat_cpu(smp_processor_id()).irqs
[IO_INTERRUPT
]++;
666 * Non I/O-subchannel thin interrupts are processed differently
668 if (tpi_info
->adapter_IO
== 1 &&
669 tpi_info
->int_type
== IO_INTERRUPT_TYPE
) {
673 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
675 spin_lock(sch
->lock
);
676 /* Store interrupt response block to lowcore. */
677 if (tsch (tpi_info
->schid
, irb
) == 0 && sch
) {
678 /* Keep subchannel information word up to date. */
679 memcpy (&sch
->schib
.scsw
, &irb
->scsw
,
681 /* Call interrupt handler if there is one. */
682 if (sch
->driver
&& sch
->driver
->irq
)
683 sch
->driver
->irq(&sch
->dev
);
686 spin_unlock(sch
->lock
);
688 * Are more interrupts pending?
689 * If so, the tpi instruction will update the lowcore
690 * to hold the info for the next interrupt.
691 * We don't do this for VM because a tpi drops the cpu
692 * out of the sie which costs more cycles than it saves.
694 } while (!MACHINE_IS_VM
&& tpi (NULL
) != 0);
696 set_irq_regs(old_regs
);
699 #ifdef CONFIG_CCW_CONSOLE
700 static struct subchannel console_subchannel
;
701 static int console_subchannel_in_use
;
704 * busy wait for the next interrupt on the console
709 unsigned long cr6
__attribute__ ((aligned (8)));
710 unsigned long save_cr6
__attribute__ ((aligned (8)));
713 * before entering the spinlock we may already have
714 * processed the interrupt on a different CPU...
716 if (!console_subchannel_in_use
)
719 /* disable all but isc 7 (console device) */
720 __ctl_store (save_cr6
, 6, 6);
722 __ctl_load (cr6
, 6, 6);
725 spin_unlock(console_subchannel
.lock
);
728 spin_lock(console_subchannel
.lock
);
729 } while (console_subchannel
.schib
.scsw
.actl
!= 0);
731 * restore previous isc value
733 __ctl_load (save_cr6
, 6, 6);
737 cio_test_for_console(struct subchannel_id schid
, void *data
)
739 if (stsch_err(schid
, &console_subchannel
.schib
) != 0)
741 if (console_subchannel
.schib
.pmcw
.dnv
&&
742 console_subchannel
.schib
.pmcw
.dev
==
744 console_irq
= schid
.sch_no
;
745 return 1; /* found */
752 cio_get_console_sch_no(void)
754 struct subchannel_id schid
;
756 init_subchannel_id(&schid
);
757 if (console_irq
!= -1) {
758 /* VM provided us with the irq number of the console. */
759 schid
.sch_no
= console_irq
;
760 if (stsch(schid
, &console_subchannel
.schib
) != 0 ||
761 !console_subchannel
.schib
.pmcw
.dnv
)
763 console_devno
= console_subchannel
.schib
.pmcw
.dev
;
764 } else if (console_devno
!= -1) {
765 /* At least the console device number is known. */
766 for_each_subchannel(cio_test_for_console
, NULL
);
767 if (console_irq
== -1)
770 /* unlike in 2.4, we cannot autoprobe here, since
771 * the channel subsystem is not fully initialized.
772 * With some luck, the HWC console can take over */
773 printk(KERN_WARNING
"cio: No ccw console found!\n");
780 cio_probe_console(void)
783 struct subchannel_id schid
;
785 if (xchg(&console_subchannel_in_use
, 1) != 0)
786 return ERR_PTR(-EBUSY
);
787 sch_no
= cio_get_console_sch_no();
789 console_subchannel_in_use
= 0;
790 return ERR_PTR(-ENODEV
);
792 memset(&console_subchannel
, 0, sizeof(struct subchannel
));
793 init_subchannel_id(&schid
);
794 schid
.sch_no
= sch_no
;
795 ret
= cio_validate_subchannel(&console_subchannel
, schid
);
797 console_subchannel_in_use
= 0;
798 return ERR_PTR(-ENODEV
);
802 * enable console I/O-interrupt subclass 7
805 console_subchannel
.schib
.pmcw
.isc
= 7;
806 console_subchannel
.schib
.pmcw
.intparm
=
807 (__u32
)(unsigned long)&console_subchannel
;
808 ret
= cio_modify(&console_subchannel
);
810 console_subchannel_in_use
= 0;
813 return &console_subchannel
;
817 cio_release_console(void)
819 console_subchannel
.schib
.pmcw
.intparm
= 0;
820 cio_modify(&console_subchannel
);
821 ctl_clear_bit(6, 24);
822 console_subchannel_in_use
= 0;
825 /* Bah... hack to catch console special sausages. */
827 cio_is_console(struct subchannel_id schid
)
829 if (!console_subchannel_in_use
)
831 return schid_equal(&schid
, &console_subchannel
.schid
);
835 cio_get_console_subchannel(void)
837 if (!console_subchannel_in_use
)
839 return &console_subchannel
;
844 __disable_subchannel_easy(struct subchannel_id schid
, struct schib
*schib
)
849 for (retry
=0;retry
<3;retry
++) {
851 cc
= msch(schid
, schib
);
853 return (cc
==3?-ENODEV
:-EBUSY
);
855 if (!schib
->pmcw
.ena
)
858 return -EBUSY
; /* uhm... */
861 /* we can't use the normal udelay here, since it enables external interrupts */
863 static void udelay_reset(unsigned long usecs
)
865 uint64_t start_cc
, end_cc
;
867 asm volatile ("STCK %0" : "=m" (start_cc
));
870 asm volatile ("STCK %0" : "=m" (end_cc
));
871 } while (((end_cc
- start_cc
)/4096) < usecs
);
875 __clear_subchannel_easy(struct subchannel_id schid
)
881 for (retry
=0;retry
<20;retry
++) {
885 tsch(ti
.schid
, (struct irb
*)__LC_IRB
);
886 if (schid_equal(&ti
.schid
, &schid
))
894 static int pgm_check_occured
;
896 static void cio_reset_pgm_check_handler(void)
898 pgm_check_occured
= 1;
901 static int stsch_reset(struct subchannel_id schid
, volatile struct schib
*addr
)
905 pgm_check_occured
= 0;
906 s390_base_pgm_handler_fn
= cio_reset_pgm_check_handler
;
907 rc
= stsch(schid
, addr
);
908 s390_base_pgm_handler_fn
= NULL
;
910 /* The program check handler could have changed pgm_check_occured. */
913 if (pgm_check_occured
)
919 static int __shutdown_subchannel_easy(struct subchannel_id schid
, void *data
)
923 if (stsch_reset(schid
, &schib
))
927 switch(__disable_subchannel_easy(schid
, &schib
)) {
931 default: /* -EBUSY */
932 if (__clear_subchannel_easy(schid
))
933 break; /* give up... */
934 stsch(schid
, &schib
);
935 __disable_subchannel_easy(schid
, &schib
);
940 static atomic_t chpid_reset_count
;
942 static void s390_reset_chpids_mcck_handler(void)
947 /* Check for pending channel report word. */
948 mci
= (struct mci
*)&S390_lowcore
.mcck_interruption_code
;
951 /* Process channel report words. */
952 while (stcrw(&crw
) == 0) {
953 /* Check for responses to RCHP. */
954 if (crw
.slct
&& crw
.rsc
== CRW_RSC_CPATH
)
955 atomic_dec(&chpid_reset_count
);
959 #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
960 static void css_reset(void)
963 unsigned long long timeout
;
966 /* Reset subchannels. */
967 for_each_subchannel(__shutdown_subchannel_easy
, NULL
);
968 /* Reset channel paths. */
969 s390_base_mcck_handler_fn
= s390_reset_chpids_mcck_handler
;
970 /* Enable channel report machine checks. */
971 __ctl_set_bit(14, 28);
972 /* Temporarily reenable machine checks. */
975 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
978 if ((ret
== 0) || (ret
== 2))
980 * rchp either succeeded, or another rchp is already
981 * in progress. In either case, we'll get a crw.
983 atomic_inc(&chpid_reset_count
);
985 /* Wait for machine check for all channel paths. */
986 timeout
= get_clock() + (RCHP_TIMEOUT
<< 12);
987 while (atomic_read(&chpid_reset_count
) != 0) {
988 if (get_clock() > timeout
)
992 /* Disable machine checks again. */
993 local_mcck_disable();
994 /* Disable channel report machine checks. */
995 __ctl_clear_bit(14, 28);
996 s390_base_mcck_handler_fn
= NULL
;
999 static struct reset_call css_reset_call
= {
1003 static int __init
init_css_reset_call(void)
1005 atomic_set(&chpid_reset_count
, 0);
1006 register_reset_call(&css_reset_call
);
1010 arch_initcall(init_css_reset_call
);
1012 struct sch_match_id
{
1013 struct subchannel_id schid
;
1014 struct ccw_dev_id devid
;
1018 static int __reipl_subchannel_match(struct subchannel_id schid
, void *data
)
1021 struct sch_match_id
*match_id
= data
;
1023 if (stsch_reset(schid
, &schib
))
1025 if (schib
.pmcw
.dnv
&&
1026 (schib
.pmcw
.dev
== match_id
->devid
.devno
) &&
1027 (schid
.ssid
== match_id
->devid
.ssid
)) {
1028 match_id
->schid
= schid
;
1035 static int reipl_find_schid(struct ccw_dev_id
*devid
,
1036 struct subchannel_id
*schid
)
1038 struct sch_match_id match_id
;
1040 match_id
.devid
= *devid
;
1041 match_id
.rc
= -ENODEV
;
1042 for_each_subchannel(__reipl_subchannel_match
, &match_id
);
1043 if (match_id
.rc
== 0)
1044 *schid
= match_id
.schid
;
1048 extern void do_reipl_asm(__u32 schid
);
1050 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
1051 void reipl_ccw_dev(struct ccw_dev_id
*devid
)
1053 struct subchannel_id schid
;
1055 s390_reset_system();
1056 if (reipl_find_schid(devid
, &schid
) != 0)
1057 panic("IPL Device not found\n");
1058 do_reipl_asm(*((__u32
*)&schid
));
1061 int __init
cio_get_iplinfo(struct cio_iplinfo
*iplinfo
)
1063 struct subchannel_id schid
;
1066 schid
= *(struct subchannel_id
*)__LC_SUBCHANNEL_ID
;
1069 if (stsch(schid
, &schib
))
1071 if (!schib
.pmcw
.dnv
)
1073 iplinfo
->devno
= schib
.pmcw
.dev
;
1074 iplinfo
->is_qdio
= schib
.pmcw
.qf
;