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/module.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/device.h>
19 #include <linux/kernel_stat.h>
20 #include <linux/interrupt.h>
22 #include <asm/delay.h>
24 #include <asm/irq_regs.h>
25 #include <asm/setup.h>
26 #include <asm/reset.h>
28 #include <asm/chpid.h>
38 #include "blacklist.h"
39 #include "cio_debug.h"
41 #include "../s390mach.h"
43 debug_info_t
*cio_debug_msg_id
;
44 debug_info_t
*cio_debug_trace_id
;
45 debug_info_t
*cio_debug_crw_id
;
48 * Function: cio_debug_init
49 * Initializes three debug logs for common I/O:
50 * - cio_msg logs generic cio messages
51 * - cio_trace logs the calling of different functions
52 * - cio_crw logs machine check related cio messages
54 static int __init
cio_debug_init(void)
56 cio_debug_msg_id
= debug_register("cio_msg", 16, 1, 16 * sizeof(long));
57 if (!cio_debug_msg_id
)
59 debug_register_view(cio_debug_msg_id
, &debug_sprintf_view
);
60 debug_set_level(cio_debug_msg_id
, 2);
61 cio_debug_trace_id
= debug_register("cio_trace", 16, 1, 16);
62 if (!cio_debug_trace_id
)
64 debug_register_view(cio_debug_trace_id
, &debug_hex_ascii_view
);
65 debug_set_level(cio_debug_trace_id
, 2);
66 cio_debug_crw_id
= debug_register("cio_crw", 16, 1, 16 * sizeof(long));
67 if (!cio_debug_crw_id
)
69 debug_register_view(cio_debug_crw_id
, &debug_sprintf_view
);
70 debug_set_level(cio_debug_crw_id
, 4);
75 debug_unregister(cio_debug_msg_id
);
76 if (cio_debug_trace_id
)
77 debug_unregister(cio_debug_trace_id
);
79 debug_unregister(cio_debug_crw_id
);
83 arch_initcall (cio_debug_init
);
86 cio_set_options (struct subchannel
*sch
, int flags
)
88 sch
->options
.suspend
= (flags
& DOIO_ALLOW_SUSPEND
) != 0;
89 sch
->options
.prefetch
= (flags
& DOIO_DENY_PREFETCH
) != 0;
90 sch
->options
.inter
= (flags
& DOIO_SUPPRESS_INTER
) != 0;
94 /* FIXME: who wants to use this? */
96 cio_get_options (struct subchannel
*sch
)
101 if (sch
->options
.suspend
)
102 flags
|= DOIO_ALLOW_SUSPEND
;
103 if (sch
->options
.prefetch
)
104 flags
|= DOIO_DENY_PREFETCH
;
105 if (sch
->options
.inter
)
106 flags
|= DOIO_SUPPRESS_INTER
;
111 cio_start_handle_notoper(struct subchannel
*sch
, __u8 lpm
)
120 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
121 "subchannel 0.%x.%04x!\n", sch
->schid
.ssid
,
124 if (cio_update_schib(sch
))
127 sprintf(dbf_text
, "no%s", dev_name(&sch
->dev
));
128 CIO_TRACE_EVENT(0, dbf_text
);
129 CIO_HEX_EVENT(0, &sch
->schib
, sizeof (struct schib
));
131 return (sch
->lpm
? -EACCES
: -ENODEV
);
135 cio_start_key (struct subchannel
*sch
, /* subchannel structure */
136 struct ccw1
* cpa
, /* logical channel prog addr */
137 __u8 lpm
, /* logical path mask */
138 __u8 key
) /* storage key */
144 CIO_TRACE_EVENT(4, "stIO");
145 CIO_TRACE_EVENT(4, dev_name(&sch
->dev
));
147 orb
= &to_io_private(sch
)->orb
;
148 memset(orb
, 0, sizeof(union orb
));
149 /* sch is always under 2G. */
150 orb
->cmd
.intparm
= (u32
)(addr_t
)sch
;
153 orb
->cmd
.pfch
= sch
->options
.prefetch
== 0;
154 orb
->cmd
.spnd
= sch
->options
.suspend
;
155 orb
->cmd
.ssic
= sch
->options
.suspend
&& sch
->options
.inter
;
156 orb
->cmd
.lpm
= (lpm
!= 0) ? lpm
: sch
->lpm
;
159 * for 64 bit we always support 64 bit IDAWs with 4k page size only
164 orb
->cmd
.key
= key
>> 4;
165 /* issue "Start Subchannel" */
166 orb
->cmd
.cpa
= (__u32
) __pa(cpa
);
167 ccode
= ssch(sch
->schid
, orb
);
169 /* process condition code */
170 sprintf(dbf_txt
, "ccode:%d", ccode
);
171 CIO_TRACE_EVENT(4, dbf_txt
);
176 * initialize device status information
178 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_START_PEND
;
180 case 1: /* status pending */
183 case 3: /* device/path not operational */
184 return cio_start_handle_notoper(sch
, lpm
);
191 cio_start (struct subchannel
*sch
, struct ccw1
*cpa
, __u8 lpm
)
193 return cio_start_key(sch
, cpa
, lpm
, PAGE_DEFAULT_KEY
);
197 * resume suspended I/O operation
200 cio_resume (struct subchannel
*sch
)
205 CIO_TRACE_EVENT (4, "resIO");
206 CIO_TRACE_EVENT(4, dev_name(&sch
->dev
));
208 ccode
= rsch (sch
->schid
);
210 sprintf (dbf_txt
, "ccode:%d", ccode
);
211 CIO_TRACE_EVENT (4, dbf_txt
);
215 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_RESUME_PEND
;
223 * useless to wait for request completion
224 * as device is no longer operational !
234 cio_halt(struct subchannel
*sch
)
242 CIO_TRACE_EVENT (2, "haltIO");
243 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
246 * Issue "Halt subchannel" and process condition code
248 ccode
= hsch (sch
->schid
);
250 sprintf (dbf_txt
, "ccode:%d", ccode
);
251 CIO_TRACE_EVENT (2, dbf_txt
);
255 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_HALT_PEND
;
257 case 1: /* status pending */
260 default: /* device not operational */
266 * Clear I/O operation
269 cio_clear(struct subchannel
*sch
)
277 CIO_TRACE_EVENT (2, "clearIO");
278 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
281 * Issue "Clear subchannel" and process condition code
283 ccode
= csch (sch
->schid
);
285 sprintf (dbf_txt
, "ccode:%d", ccode
);
286 CIO_TRACE_EVENT (2, dbf_txt
);
290 sch
->schib
.scsw
.cmd
.actl
|= SCSW_ACTL_CLEAR_PEND
;
292 default: /* device not operational */
298 * Function: cio_cancel
299 * Issues a "Cancel Subchannel" on the specified subchannel
300 * Note: We don't need any fancy intparms and flags here
301 * since xsch is executed synchronously.
302 * Only for common I/O internal use as for now.
305 cio_cancel (struct subchannel
*sch
)
313 CIO_TRACE_EVENT (2, "cancelIO");
314 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
316 ccode
= xsch (sch
->schid
);
318 sprintf (dbf_txt
, "ccode:%d", ccode
);
319 CIO_TRACE_EVENT (2, dbf_txt
);
322 case 0: /* success */
323 /* Update information in scsw. */
324 if (cio_update_schib(sch
))
327 case 1: /* status pending */
329 case 2: /* not applicable */
331 default: /* not oper */
337 static void cio_apply_config(struct subchannel
*sch
, struct schib
*schib
)
339 schib
->pmcw
.intparm
= sch
->config
.intparm
;
340 schib
->pmcw
.mbi
= sch
->config
.mbi
;
341 schib
->pmcw
.isc
= sch
->config
.isc
;
342 schib
->pmcw
.ena
= sch
->config
.ena
;
343 schib
->pmcw
.mme
= sch
->config
.mme
;
344 schib
->pmcw
.mp
= sch
->config
.mp
;
345 schib
->pmcw
.csense
= sch
->config
.csense
;
346 schib
->pmcw
.mbfc
= sch
->config
.mbfc
;
347 if (sch
->config
.mbfc
)
348 schib
->mba
= sch
->config
.mba
;
351 static int cio_check_config(struct subchannel
*sch
, struct schib
*schib
)
353 return (schib
->pmcw
.intparm
== sch
->config
.intparm
) &&
354 (schib
->pmcw
.mbi
== sch
->config
.mbi
) &&
355 (schib
->pmcw
.isc
== sch
->config
.isc
) &&
356 (schib
->pmcw
.ena
== sch
->config
.ena
) &&
357 (schib
->pmcw
.mme
== sch
->config
.mme
) &&
358 (schib
->pmcw
.mp
== sch
->config
.mp
) &&
359 (schib
->pmcw
.csense
== sch
->config
.csense
) &&
360 (schib
->pmcw
.mbfc
== sch
->config
.mbfc
) &&
361 (!sch
->config
.mbfc
|| (schib
->mba
== sch
->config
.mba
));
365 * cio_commit_config - apply configuration to the subchannel
367 int cio_commit_config(struct subchannel
*sch
)
370 int ccode
, retry
, ret
= 0;
372 if (stsch(sch
->schid
, &schib
) || !css_sch_is_valid(&schib
))
375 for (retry
= 0; retry
< 5; retry
++) {
376 /* copy desired changes to local schib */
377 cio_apply_config(sch
, &schib
);
378 ccode
= msch_err(sch
->schid
, &schib
);
379 if (ccode
< 0) /* -EIO if msch gets a program check. */
382 case 0: /* successfull */
383 if (stsch(sch
->schid
, &schib
) ||
384 !css_sch_is_valid(&schib
))
386 if (cio_check_config(sch
, &schib
)) {
387 /* commit changes from local schib */
388 memcpy(&sch
->schib
, &schib
, sizeof(schib
));
393 case 1: /* status pending */
396 udelay(100); /* allow for recovery */
399 case 3: /* not operational */
407 * cio_update_schib - Perform stsch and update schib if subchannel is valid.
408 * @sch: subchannel on which to perform stsch
409 * Return zero on success, -ENODEV otherwise.
411 int cio_update_schib(struct subchannel
*sch
)
415 if (stsch(sch
->schid
, &schib
) || !css_sch_is_valid(&schib
))
418 memcpy(&sch
->schib
, &schib
, sizeof(schib
));
421 EXPORT_SYMBOL_GPL(cio_update_schib
);
424 * cio_enable_subchannel - enable a subchannel.
425 * @sch: subchannel to be enabled
426 * @intparm: interruption parameter to set
428 int cio_enable_subchannel(struct subchannel
*sch
, u32 intparm
)
434 CIO_TRACE_EVENT (2, "ensch");
435 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
437 if (sch_is_pseudo_sch(sch
))
439 if (cio_update_schib(sch
))
443 sch
->config
.isc
= sch
->isc
;
444 sch
->config
.intparm
= intparm
;
446 for (retry
= 0; retry
< 3; retry
++) {
447 ret
= cio_commit_config(sch
);
450 * Got a program check in msch. Try without
451 * the concurrent sense bit the next time.
453 sch
->config
.csense
= 0;
454 } else if (ret
== -EBUSY
) {
456 if (tsch(sch
->schid
, &irb
) != 0)
461 sprintf (dbf_txt
, "ret:%d", ret
);
462 CIO_TRACE_EVENT (2, dbf_txt
);
465 EXPORT_SYMBOL_GPL(cio_enable_subchannel
);
468 * cio_disable_subchannel - disable a subchannel.
469 * @sch: subchannel to disable
471 int cio_disable_subchannel(struct subchannel
*sch
)
476 CIO_TRACE_EVENT (2, "dissch");
477 CIO_TRACE_EVENT(2, dev_name(&sch
->dev
));
479 if (sch_is_pseudo_sch(sch
))
481 if (cio_update_schib(sch
))
484 if (scsw_actl(&sch
->schib
.scsw
) != 0)
486 * the disable function must not be called while there are
487 * requests pending for completion !
492 ret
= cio_commit_config(sch
);
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
;
691 * Use tpi to get a pending interrupt, call the interrupt handler and
692 * return a pointer to the subchannel structure.
694 static int cio_tpi(void)
696 struct tpi_info
*tpi_info
;
697 struct subchannel
*sch
;
701 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
704 irb
= (struct irb
*) __LC_IRB
;
705 /* Store interrupt response block to lowcore. */
706 if (tsch(tpi_info
->schid
, irb
) != 0)
707 /* Not status pending or not operational. */
709 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
712 irq_context
= in_interrupt();
716 spin_lock(sch
->lock
);
717 memcpy(&sch
->schib
.scsw
, &irb
->scsw
, sizeof(union scsw
));
718 if (sch
->driver
&& sch
->driver
->irq
)
719 sch
->driver
->irq(sch
);
720 spin_unlock(sch
->lock
);
727 void *cio_get_console_priv(void)
729 return &console_priv
;
733 * busy wait for the next interrupt on the console
735 void wait_cons_dev(void)
736 __releases(console_subchannel
.lock
)
737 __acquires(console_subchannel
.lock
)
739 unsigned long cr6
__attribute__ ((aligned (8)));
740 unsigned long save_cr6
__attribute__ ((aligned (8)));
743 * before entering the spinlock we may already have
744 * processed the interrupt on a different CPU...
746 if (!console_subchannel_in_use
)
749 /* disable all but the console isc */
750 __ctl_store (save_cr6
, 6, 6);
751 cr6
= 1UL << (31 - CONSOLE_ISC
);
752 __ctl_load (cr6
, 6, 6);
755 spin_unlock(console_subchannel
.lock
);
758 spin_lock(console_subchannel
.lock
);
759 } while (console_subchannel
.schib
.scsw
.cmd
.actl
!= 0);
761 * restore previous isc value
763 __ctl_load (save_cr6
, 6, 6);
767 cio_test_for_console(struct subchannel_id schid
, void *data
)
769 if (stsch_err(schid
, &console_subchannel
.schib
) != 0)
771 if ((console_subchannel
.schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) &&
772 console_subchannel
.schib
.pmcw
.dnv
&&
773 (console_subchannel
.schib
.pmcw
.dev
== console_devno
)) {
774 console_irq
= schid
.sch_no
;
775 return 1; /* found */
782 cio_get_console_sch_no(void)
784 struct subchannel_id schid
;
786 init_subchannel_id(&schid
);
787 if (console_irq
!= -1) {
788 /* VM provided us with the irq number of the console. */
789 schid
.sch_no
= console_irq
;
790 if (stsch(schid
, &console_subchannel
.schib
) != 0 ||
791 (console_subchannel
.schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
) ||
792 !console_subchannel
.schib
.pmcw
.dnv
)
794 console_devno
= console_subchannel
.schib
.pmcw
.dev
;
795 } else if (console_devno
!= -1) {
796 /* At least the console device number is known. */
797 for_each_subchannel(cio_test_for_console
, NULL
);
798 if (console_irq
== -1)
801 /* unlike in 2.4, we cannot autoprobe here, since
802 * the channel subsystem is not fully initialized.
803 * With some luck, the HWC console can take over */
810 cio_probe_console(void)
813 struct subchannel_id schid
;
815 if (xchg(&console_subchannel_in_use
, 1) != 0)
816 return ERR_PTR(-EBUSY
);
817 sch_no
= cio_get_console_sch_no();
819 console_subchannel_in_use
= 0;
820 pr_warning("No CCW console was found\n");
821 return ERR_PTR(-ENODEV
);
823 memset(&console_subchannel
, 0, sizeof(struct subchannel
));
824 init_subchannel_id(&schid
);
825 schid
.sch_no
= sch_no
;
826 ret
= cio_validate_subchannel(&console_subchannel
, schid
);
828 console_subchannel_in_use
= 0;
829 return ERR_PTR(-ENODEV
);
833 * enable console I/O-interrupt subclass
835 isc_register(CONSOLE_ISC
);
836 console_subchannel
.config
.isc
= CONSOLE_ISC
;
837 console_subchannel
.config
.intparm
= (u32
)(addr_t
)&console_subchannel
;
838 ret
= cio_commit_config(&console_subchannel
);
840 isc_unregister(CONSOLE_ISC
);
841 console_subchannel_in_use
= 0;
844 return &console_subchannel
;
848 cio_release_console(void)
850 console_subchannel
.config
.intparm
= 0;
851 cio_commit_config(&console_subchannel
);
852 isc_unregister(CONSOLE_ISC
);
853 console_subchannel_in_use
= 0;
856 /* Bah... hack to catch console special sausages. */
858 cio_is_console(struct subchannel_id schid
)
860 if (!console_subchannel_in_use
)
862 return schid_equal(&schid
, &console_subchannel
.schid
);
866 cio_get_console_subchannel(void)
868 if (!console_subchannel_in_use
)
870 return &console_subchannel
;
873 const char *cio_get_console_sch_name(struct subchannel_id schid
)
875 snprintf(console_sch_name
, 10, "0.%x.%04x", schid
.ssid
, schid
.sch_no
);
876 return (const char *)console_sch_name
;
881 __disable_subchannel_easy(struct subchannel_id schid
, struct schib
*schib
)
886 for (retry
=0;retry
<3;retry
++) {
888 cc
= msch(schid
, schib
);
890 return (cc
==3?-ENODEV
:-EBUSY
);
891 if (stsch(schid
, schib
) || !css_sch_is_valid(schib
))
893 if (!schib
->pmcw
.ena
)
896 return -EBUSY
; /* uhm... */
900 __clear_io_subchannel_easy(struct subchannel_id schid
)
906 for (retry
=0;retry
<20;retry
++) {
910 tsch(ti
.schid
, (struct irb
*)__LC_IRB
);
911 if (schid_equal(&ti
.schid
, &schid
))
919 static void __clear_chsc_subchannel_easy(void)
921 /* It seems we can only wait for a bit here :/ */
925 static int pgm_check_occured
;
927 static void cio_reset_pgm_check_handler(void)
929 pgm_check_occured
= 1;
932 static int stsch_reset(struct subchannel_id schid
, struct schib
*addr
)
936 pgm_check_occured
= 0;
937 s390_base_pgm_handler_fn
= cio_reset_pgm_check_handler
;
938 rc
= stsch(schid
, addr
);
939 s390_base_pgm_handler_fn
= NULL
;
941 /* The program check handler could have changed pgm_check_occured. */
944 if (pgm_check_occured
)
950 static int __shutdown_subchannel_easy(struct subchannel_id schid
, void *data
)
954 if (stsch_reset(schid
, &schib
))
958 switch(__disable_subchannel_easy(schid
, &schib
)) {
962 default: /* -EBUSY */
963 switch (schib
.pmcw
.st
) {
964 case SUBCHANNEL_TYPE_IO
:
965 if (__clear_io_subchannel_easy(schid
))
966 goto out
; /* give up... */
968 case SUBCHANNEL_TYPE_CHSC
:
969 __clear_chsc_subchannel_easy();
972 /* No default clear strategy */
975 stsch(schid
, &schib
);
976 __disable_subchannel_easy(schid
, &schib
);
982 static atomic_t chpid_reset_count
;
984 static void s390_reset_chpids_mcck_handler(void)
989 /* Check for pending channel report word. */
990 mci
= (struct mci
*)&S390_lowcore
.mcck_interruption_code
;
993 /* Process channel report words. */
994 while (stcrw(&crw
) == 0) {
995 /* Check for responses to RCHP. */
996 if (crw
.slct
&& crw
.rsc
== CRW_RSC_CPATH
)
997 atomic_dec(&chpid_reset_count
);
1001 #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
1002 static void css_reset(void)
1005 unsigned long long timeout
;
1006 struct chp_id chpid
;
1008 /* Reset subchannels. */
1009 for_each_subchannel(__shutdown_subchannel_easy
, NULL
);
1010 /* Reset channel paths. */
1011 s390_base_mcck_handler_fn
= s390_reset_chpids_mcck_handler
;
1012 /* Enable channel report machine checks. */
1013 __ctl_set_bit(14, 28);
1014 /* Temporarily reenable machine checks. */
1015 local_mcck_enable();
1016 chp_id_init(&chpid
);
1017 for (i
= 0; i
<= __MAX_CHPID
; i
++) {
1020 if ((ret
== 0) || (ret
== 2))
1022 * rchp either succeeded, or another rchp is already
1023 * in progress. In either case, we'll get a crw.
1025 atomic_inc(&chpid_reset_count
);
1027 /* Wait for machine check for all channel paths. */
1028 timeout
= get_clock() + (RCHP_TIMEOUT
<< 12);
1029 while (atomic_read(&chpid_reset_count
) != 0) {
1030 if (get_clock() > timeout
)
1034 /* Disable machine checks again. */
1035 local_mcck_disable();
1036 /* Disable channel report machine checks. */
1037 __ctl_clear_bit(14, 28);
1038 s390_base_mcck_handler_fn
= NULL
;
1041 static struct reset_call css_reset_call
= {
1045 static int __init
init_css_reset_call(void)
1047 atomic_set(&chpid_reset_count
, 0);
1048 register_reset_call(&css_reset_call
);
1052 arch_initcall(init_css_reset_call
);
1054 struct sch_match_id
{
1055 struct subchannel_id schid
;
1056 struct ccw_dev_id devid
;
1060 static int __reipl_subchannel_match(struct subchannel_id schid
, void *data
)
1063 struct sch_match_id
*match_id
= data
;
1065 if (stsch_reset(schid
, &schib
))
1067 if ((schib
.pmcw
.st
== SUBCHANNEL_TYPE_IO
) && schib
.pmcw
.dnv
&&
1068 (schib
.pmcw
.dev
== match_id
->devid
.devno
) &&
1069 (schid
.ssid
== match_id
->devid
.ssid
)) {
1070 match_id
->schid
= schid
;
1077 static int reipl_find_schid(struct ccw_dev_id
*devid
,
1078 struct subchannel_id
*schid
)
1080 struct sch_match_id match_id
;
1082 match_id
.devid
= *devid
;
1083 match_id
.rc
= -ENODEV
;
1084 for_each_subchannel(__reipl_subchannel_match
, &match_id
);
1085 if (match_id
.rc
== 0)
1086 *schid
= match_id
.schid
;
1090 extern void do_reipl_asm(__u32 schid
);
1092 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
1093 void reipl_ccw_dev(struct ccw_dev_id
*devid
)
1095 struct subchannel_id schid
;
1097 s390_reset_system();
1098 if (reipl_find_schid(devid
, &schid
) != 0)
1099 panic("IPL Device not found\n");
1100 do_reipl_asm(*((__u32
*)&schid
));
1103 int __init
cio_get_iplinfo(struct cio_iplinfo
*iplinfo
)
1105 struct subchannel_id schid
;
1108 schid
= *(struct subchannel_id
*)__LC_SUBCHANNEL_ID
;
1111 if (stsch(schid
, &schib
))
1113 if (schib
.pmcw
.st
!= SUBCHANNEL_TYPE_IO
)
1115 if (!schib
.pmcw
.dnv
)
1117 iplinfo
->devno
= schib
.pmcw
.dev
;
1118 iplinfo
->is_qdio
= schib
.pmcw
.qf
;
1123 * cio_tm_start_key - perform start function
1124 * @sch: subchannel on which to perform the start function
1125 * @tcw: transport-command word to be started
1126 * @lpm: mask of paths to use
1127 * @key: storage key to use for storage access
1129 * Start the tcw on the given subchannel. Return zero on success, non-zero
1132 int cio_tm_start_key(struct subchannel
*sch
, struct tcw
*tcw
, u8 lpm
, u8 key
)
1135 union orb
*orb
= &to_io_private(sch
)->orb
;
1137 memset(orb
, 0, sizeof(union orb
));
1138 orb
->tm
.intparm
= (u32
) (addr_t
) sch
;
1139 orb
->tm
.key
= key
>> 4;
1141 orb
->tm
.lpm
= lpm
? lpm
: sch
->lpm
;
1142 orb
->tm
.tcw
= (u32
) (addr_t
) tcw
;
1143 cc
= ssch(sch
->schid
, orb
);
1151 return cio_start_handle_notoper(sch
, lpm
);
1156 * cio_tm_intrg - perform interrogate function
1157 * @sch - subchannel on which to perform the interrogate function
1159 * If the specified subchannel is running in transport-mode, perform the
1160 * interrogate function. Return zero on success, non-zero otherwie.
1162 int cio_tm_intrg(struct subchannel
*sch
)
1166 if (!to_io_private(sch
)->orb
.tm
.b
)
1168 cc
= xsch(sch
->schid
);