2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls
5 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
7 * Author(s): Ingo Adlung (adlung@de.ibm.com)
8 * Cornelia Huck (cornelia.huck@de.ibm.com)
9 * Arnd Bergmann (arndb@de.ibm.com)
10 * Martin Schwidefsky (schwidefsky@de.ibm.com)
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/device.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/interrupt.h>
21 #include <asm/delay.h>
29 #include "blacklist.h"
30 #include "cio_debug.h"
32 debug_info_t
*cio_debug_msg_id
;
33 debug_info_t
*cio_debug_trace_id
;
34 debug_info_t
*cio_debug_crw_id
;
39 cio_setup (char *parm
)
41 if (!strcmp (parm
, "yes"))
43 else if (!strcmp (parm
, "no"))
46 printk (KERN_ERR
"cio_setup : invalid cio_msg parameter '%s'",
51 __setup ("cio_msg=", cio_setup
);
54 * Function: cio_debug_init
55 * Initializes three debug logs (under /proc/s390dbf) for common I/O:
56 * - cio_msg logs the messages which are printk'ed when CONFIG_DEBUG_IO is on
57 * - cio_trace logs the calling of different functions
58 * - cio_crw logs the messages which are printk'ed when CONFIG_DEBUG_CRW is on
59 * debug levels depend on CONFIG_DEBUG_IO resp. CONFIG_DEBUG_CRW
64 cio_debug_msg_id
= debug_register ("cio_msg", 16, 4, 16*sizeof (long));
65 if (!cio_debug_msg_id
)
67 debug_register_view (cio_debug_msg_id
, &debug_sprintf_view
);
68 debug_set_level (cio_debug_msg_id
, 2);
69 cio_debug_trace_id
= debug_register ("cio_trace", 16, 4, 16);
70 if (!cio_debug_trace_id
)
72 debug_register_view (cio_debug_trace_id
, &debug_hex_ascii_view
);
73 debug_set_level (cio_debug_trace_id
, 2);
74 cio_debug_crw_id
= debug_register ("cio_crw", 4, 4, 16*sizeof (long));
75 if (!cio_debug_crw_id
)
77 debug_register_view (cio_debug_crw_id
, &debug_sprintf_view
);
78 debug_set_level (cio_debug_crw_id
, 2);
79 pr_debug("debugging initialized\n");
84 debug_unregister (cio_debug_msg_id
);
85 if (cio_debug_trace_id
)
86 debug_unregister (cio_debug_trace_id
);
88 debug_unregister (cio_debug_crw_id
);
89 pr_debug("could not initialize debugging\n");
93 arch_initcall (cio_debug_init
);
96 cio_set_options (struct subchannel
*sch
, int flags
)
98 sch
->options
.suspend
= (flags
& DOIO_ALLOW_SUSPEND
) != 0;
99 sch
->options
.prefetch
= (flags
& DOIO_DENY_PREFETCH
) != 0;
100 sch
->options
.inter
= (flags
& DOIO_SUPPRESS_INTER
) != 0;
104 /* FIXME: who wants to use this? */
106 cio_get_options (struct subchannel
*sch
)
111 if (sch
->options
.suspend
)
112 flags
|= DOIO_ALLOW_SUSPEND
;
113 if (sch
->options
.prefetch
)
114 flags
|= DOIO_DENY_PREFETCH
;
115 if (sch
->options
.inter
)
116 flags
|= DOIO_SUPPRESS_INTER
;
121 * Use tpi to get a pending interrupt, call the interrupt handler and
122 * return a pointer to the subchannel structure.
127 struct tpi_info
*tpi_info
;
128 struct subchannel
*sch
;
131 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
134 irb
= (struct irb
*) __LC_IRB
;
135 /* Store interrupt response block to lowcore. */
136 if (tsch (tpi_info
->schid
, irb
) != 0)
137 /* Not status pending or not operational. */
139 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
144 spin_lock(&sch
->lock
);
145 memcpy (&sch
->schib
.scsw
, &irb
->scsw
, sizeof (struct scsw
));
146 if (sch
->driver
&& sch
->driver
->irq
)
147 sch
->driver
->irq(&sch
->dev
);
148 spin_unlock(&sch
->lock
);
155 cio_start_handle_notoper(struct subchannel
*sch
, __u8 lpm
)
164 stsch (sch
->schid
, &sch
->schib
);
166 CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
167 "subchannel 0.%x.%04x!\n", sch
->schid
.ssid
,
169 sprintf(dbf_text
, "no%s", sch
->dev
.bus_id
);
170 CIO_TRACE_EVENT(0, dbf_text
);
171 CIO_HEX_EVENT(0, &sch
->schib
, sizeof (struct schib
));
173 return (sch
->lpm
? -EACCES
: -ENODEV
);
177 cio_start_key (struct subchannel
*sch
, /* subchannel structure */
178 struct ccw1
* cpa
, /* logical channel prog addr */
179 __u8 lpm
, /* logical path mask */
180 __u8 key
) /* storage key */
185 CIO_TRACE_EVENT (4, "stIO");
186 CIO_TRACE_EVENT (4, sch
->dev
.bus_id
);
188 /* sch is always under 2G. */
189 sch
->orb
.intparm
= (__u32
)(unsigned long)sch
;
192 sch
->orb
.pfch
= sch
->options
.prefetch
== 0;
193 sch
->orb
.spnd
= sch
->options
.suspend
;
194 sch
->orb
.ssic
= sch
->options
.suspend
&& sch
->options
.inter
;
195 sch
->orb
.lpm
= (lpm
!= 0) ? (lpm
& sch
->opm
) : sch
->lpm
;
198 * for 64 bit we always support 64 bit IDAWs with 4k page size only
203 sch
->orb
.key
= key
>> 4;
204 /* issue "Start Subchannel" */
205 sch
->orb
.cpa
= (__u32
) __pa (cpa
);
206 ccode
= ssch (sch
->schid
, &sch
->orb
);
208 /* process condition code */
209 sprintf (dbf_txt
, "ccode:%d", ccode
);
210 CIO_TRACE_EVENT (4, dbf_txt
);
215 * initialize device status information
217 sch
->schib
.scsw
.actl
|= SCSW_ACTL_START_PEND
;
219 case 1: /* status pending */
222 default: /* device/path not operational */
223 return cio_start_handle_notoper(sch
, lpm
);
228 cio_start (struct subchannel
*sch
, struct ccw1
*cpa
, __u8 lpm
)
230 return cio_start_key(sch
, cpa
, lpm
, PAGE_DEFAULT_KEY
);
234 * resume suspended I/O operation
237 cio_resume (struct subchannel
*sch
)
242 CIO_TRACE_EVENT (4, "resIO");
243 CIO_TRACE_EVENT (4, sch
->dev
.bus_id
);
245 ccode
= rsch (sch
->schid
);
247 sprintf (dbf_txt
, "ccode:%d", ccode
);
248 CIO_TRACE_EVENT (4, dbf_txt
);
252 sch
->schib
.scsw
.actl
|= SCSW_ACTL_RESUME_PEND
;
260 * useless to wait for request completion
261 * as device is no longer operational !
271 cio_halt(struct subchannel
*sch
)
279 CIO_TRACE_EVENT (2, "haltIO");
280 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
283 * Issue "Halt subchannel" and process condition code
285 ccode
= hsch (sch
->schid
);
287 sprintf (dbf_txt
, "ccode:%d", ccode
);
288 CIO_TRACE_EVENT (2, dbf_txt
);
292 sch
->schib
.scsw
.actl
|= SCSW_ACTL_HALT_PEND
;
294 case 1: /* status pending */
297 default: /* device not operational */
303 * Clear I/O operation
306 cio_clear(struct subchannel
*sch
)
314 CIO_TRACE_EVENT (2, "clearIO");
315 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
318 * Issue "Clear subchannel" and process condition code
320 ccode
= csch (sch
->schid
);
322 sprintf (dbf_txt
, "ccode:%d", ccode
);
323 CIO_TRACE_EVENT (2, dbf_txt
);
327 sch
->schib
.scsw
.actl
|= SCSW_ACTL_CLEAR_PEND
;
329 default: /* device not operational */
335 * Function: cio_cancel
336 * Issues a "Cancel Subchannel" on the specified subchannel
337 * Note: We don't need any fancy intparms and flags here
338 * since xsch is executed synchronously.
339 * Only for common I/O internal use as for now.
342 cio_cancel (struct subchannel
*sch
)
350 CIO_TRACE_EVENT (2, "cancelIO");
351 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
353 ccode
= xsch (sch
->schid
);
355 sprintf (dbf_txt
, "ccode:%d", ccode
);
356 CIO_TRACE_EVENT (2, dbf_txt
);
359 case 0: /* success */
360 /* Update information in scsw. */
361 stsch (sch
->schid
, &sch
->schib
);
363 case 1: /* status pending */
365 case 2: /* not applicable */
367 default: /* not oper */
373 * Function: cio_modify
374 * Issues a "Modify Subchannel" on the specified subchannel
377 cio_modify (struct subchannel
*sch
)
379 int ccode
, retry
, ret
;
382 for (retry
= 0; retry
< 5; retry
++) {
383 ccode
= msch_err (sch
->schid
, &sch
->schib
);
384 if (ccode
< 0) /* -EIO if msch gets a program check. */
387 case 0: /* successfull */
389 case 1: /* status pending */
392 udelay (100); /* allow for recovery */
395 case 3: /* not operational */
406 cio_enable_subchannel (struct subchannel
*sch
, unsigned int isc
)
413 CIO_TRACE_EVENT (2, "ensch");
414 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
416 ccode
= stsch (sch
->schid
, &sch
->schib
);
420 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
421 sch
->schib
.pmcw
.ena
= 1;
422 sch
->schib
.pmcw
.isc
= isc
;
423 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
424 ret
= cio_modify(sch
);
429 * Got a program check in cio_modify. Try without
430 * the concurrent sense bit the next time.
432 sch
->schib
.pmcw
.csense
= 0;
434 stsch (sch
->schid
, &sch
->schib
);
435 if (sch
->schib
.pmcw
.ena
)
440 if (tsch(sch
->schid
, &irb
) != 0)
444 sprintf (dbf_txt
, "ret:%d", ret
);
445 CIO_TRACE_EVENT (2, dbf_txt
);
450 * Disable subchannel.
453 cio_disable_subchannel (struct subchannel
*sch
)
460 CIO_TRACE_EVENT (2, "dissch");
461 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
463 ccode
= stsch (sch
->schid
, &sch
->schib
);
464 if (ccode
== 3) /* Not operational. */
467 if (sch
->schib
.scsw
.actl
!= 0)
469 * the disable function must not be called while there are
470 * requests pending for completion !
474 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
475 sch
->schib
.pmcw
.ena
= 0;
476 ret
= cio_modify(sch
);
481 * The subchannel is busy or status pending.
482 * We'll disable when the next interrupt was delivered
483 * via the state machine.
487 stsch (sch
->schid
, &sch
->schib
);
488 if (!sch
->schib
.pmcw
.ena
)
492 sprintf (dbf_txt
, "ret:%d", ret
);
493 CIO_TRACE_EVENT (2, dbf_txt
);
498 * cio_validate_subchannel()
500 * Find out subchannel type and initialize struct subchannel.
502 * SUBCHANNEL_TYPE_IO for a normal io subchannel
503 * SUBCHANNEL_TYPE_CHSC for a chsc subchannel
504 * SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
505 * SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
506 * -ENXIO for non-defined subchannels
507 * -ENODEV for subchannels with invalid device number or blacklisted devices
510 cio_validate_subchannel (struct subchannel
*sch
, struct subchannel_id schid
)
515 sprintf (dbf_txt
, "valsch%x", schid
.sch_no
);
516 CIO_TRACE_EVENT (4, dbf_txt
);
518 /* Nuke all fields. */
519 memset(sch
, 0, sizeof(struct subchannel
));
521 spin_lock_init(&sch
->lock
);
523 /* Set a name for the subchannel */
524 snprintf (sch
->dev
.bus_id
, BUS_ID_SIZE
, "0.%x.%04x", schid
.ssid
,
528 * The first subchannel that is not-operational (ccode==3)
529 * indicates that there aren't any more devices available.
530 * If stsch gets an exception, it means the current subchannel set
533 ccode
= stsch_err (schid
, &sch
->schib
);
535 return (ccode
== 3) ? -ENXIO
: ccode
;
538 /* Copy subchannel type from path management control word. */
539 sch
->st
= sch
->schib
.pmcw
.st
;
542 * ... just being curious we check for non I/O subchannels
545 CIO_DEBUG(KERN_INFO
, 0,
546 "Subchannel 0.%x.%04x reports "
547 "non-I/O subchannel type %04X\n",
548 sch
->schid
.ssid
, sch
->schid
.sch_no
, sch
->st
);
549 /* We stop here for non-io subchannels. */
553 /* Initialization for io subchannels. */
554 if (!sch
->schib
.pmcw
.dnv
)
555 /* io subchannel but device number is invalid. */
558 /* Devno is valid. */
559 if (is_blacklisted (sch
->schid
.ssid
, sch
->schib
.pmcw
.dev
)) {
561 * This device must not be known to Linux. So we simply
562 * say that there is no device and return ENODEV.
564 CIO_MSG_EVENT(0, "Blacklisted device detected "
565 "at devno %04X, subchannel set %x\n",
566 sch
->schib
.pmcw
.dev
, sch
->schid
.ssid
);
570 if (!cio_is_console(sch
->schid
))
571 chsc_validate_chpids(sch
);
572 sch
->lpm
= sch
->schib
.pmcw
.pim
&
573 sch
->schib
.pmcw
.pam
&
574 sch
->schib
.pmcw
.pom
&
577 CIO_DEBUG(KERN_INFO
, 0,
578 "Detected device %04x on subchannel 0.%x.%04X"
579 " - PIM = %02X, PAM = %02X, POM = %02X\n",
580 sch
->schib
.pmcw
.dev
, sch
->schid
.ssid
,
581 sch
->schid
.sch_no
, sch
->schib
.pmcw
.pim
,
582 sch
->schib
.pmcw
.pam
, sch
->schib
.pmcw
.pom
);
585 * We now have to initially ...
586 * ... set "interruption subclass"
587 * ... enable "concurrent sense"
588 * ... enable "multipath mode" if more than one
589 * CHPID is available. This is done regardless
590 * whether multiple paths are available for us.
592 sch
->schib
.pmcw
.isc
= 3; /* could be smth. else */
593 sch
->schib
.pmcw
.csense
= 1; /* concurrent sense */
594 sch
->schib
.pmcw
.ena
= 0;
595 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
596 sch
->schib
.pmcw
.mp
= 1; /* multipath mode */
601 * do_IRQ() handles all normal I/O device IRQ's (the special
602 * SMP cross-CPU interrupts have their own specific
607 do_IRQ (struct pt_regs
*regs
)
609 struct tpi_info
*tpi_info
;
610 struct subchannel
*sch
;
614 asm volatile ("mc 0,0");
615 if (S390_lowcore
.int_clock
>= S390_lowcore
.jiffy_timer
)
617 * Make sure that the i/o interrupt did not "overtake"
618 * the last HZ timer interrupt.
622 * Get interrupt information from lowcore
624 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
625 irb
= (struct irb
*) __LC_IRB
;
627 kstat_cpu(smp_processor_id()).irqs
[IO_INTERRUPT
]++;
629 * Non I/O-subchannel thin interrupts are processed differently
631 if (tpi_info
->adapter_IO
== 1 &&
632 tpi_info
->int_type
== IO_INTERRUPT_TYPE
) {
636 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
638 spin_lock(&sch
->lock
);
639 /* Store interrupt response block to lowcore. */
640 if (tsch (tpi_info
->schid
, irb
) == 0 && sch
) {
641 /* Keep subchannel information word up to date. */
642 memcpy (&sch
->schib
.scsw
, &irb
->scsw
,
644 /* Call interrupt handler if there is one. */
645 if (sch
->driver
&& sch
->driver
->irq
)
646 sch
->driver
->irq(&sch
->dev
);
649 spin_unlock(&sch
->lock
);
651 * Are more interrupts pending?
652 * If so, the tpi instruction will update the lowcore
653 * to hold the info for the next interrupt.
654 * We don't do this for VM because a tpi drops the cpu
655 * out of the sie which costs more cycles than it saves.
657 } while (!MACHINE_IS_VM
&& tpi (NULL
) != 0);
661 #ifdef CONFIG_CCW_CONSOLE
662 static struct subchannel console_subchannel
;
663 static int console_subchannel_in_use
;
666 * busy wait for the next interrupt on the console
671 unsigned long cr6
__attribute__ ((aligned (8)));
672 unsigned long save_cr6
__attribute__ ((aligned (8)));
675 * before entering the spinlock we may already have
676 * processed the interrupt on a different CPU...
678 if (!console_subchannel_in_use
)
681 /* disable all but isc 7 (console device) */
682 __ctl_store (save_cr6
, 6, 6);
684 __ctl_load (cr6
, 6, 6);
687 spin_unlock(&console_subchannel
.lock
);
690 spin_lock(&console_subchannel
.lock
);
691 } while (console_subchannel
.schib
.scsw
.actl
!= 0);
693 * restore previous isc value
695 __ctl_load (save_cr6
, 6, 6);
699 cio_test_for_console(struct subchannel_id schid
, void *data
)
701 if (stsch_err(schid
, &console_subchannel
.schib
) != 0)
703 if (console_subchannel
.schib
.pmcw
.dnv
&&
704 console_subchannel
.schib
.pmcw
.dev
==
706 console_irq
= schid
.sch_no
;
707 return 1; /* found */
714 cio_get_console_sch_no(void)
716 struct subchannel_id schid
;
718 init_subchannel_id(&schid
);
719 if (console_irq
!= -1) {
720 /* VM provided us with the irq number of the console. */
721 schid
.sch_no
= console_irq
;
722 if (stsch(schid
, &console_subchannel
.schib
) != 0 ||
723 !console_subchannel
.schib
.pmcw
.dnv
)
725 console_devno
= console_subchannel
.schib
.pmcw
.dev
;
726 } else if (console_devno
!= -1) {
727 /* At least the console device number is known. */
728 for_each_subchannel(cio_test_for_console
, NULL
);
729 if (console_irq
== -1)
732 /* unlike in 2.4, we cannot autoprobe here, since
733 * the channel subsystem is not fully initialized.
734 * With some luck, the HWC console can take over */
735 printk(KERN_WARNING
"No ccw console found!\n");
742 cio_probe_console(void)
745 struct subchannel_id schid
;
747 if (xchg(&console_subchannel_in_use
, 1) != 0)
748 return ERR_PTR(-EBUSY
);
749 sch_no
= cio_get_console_sch_no();
751 console_subchannel_in_use
= 0;
752 return ERR_PTR(-ENODEV
);
754 memset(&console_subchannel
, 0, sizeof(struct subchannel
));
755 init_subchannel_id(&schid
);
756 schid
.sch_no
= sch_no
;
757 ret
= cio_validate_subchannel(&console_subchannel
, schid
);
759 console_subchannel_in_use
= 0;
760 return ERR_PTR(-ENODEV
);
764 * enable console I/O-interrupt subclass 7
767 console_subchannel
.schib
.pmcw
.isc
= 7;
768 console_subchannel
.schib
.pmcw
.intparm
=
769 (__u32
)(unsigned long)&console_subchannel
;
770 ret
= cio_modify(&console_subchannel
);
772 console_subchannel_in_use
= 0;
775 return &console_subchannel
;
779 cio_release_console(void)
781 console_subchannel
.schib
.pmcw
.intparm
= 0;
782 cio_modify(&console_subchannel
);
783 ctl_clear_bit(6, 24);
784 console_subchannel_in_use
= 0;
787 /* Bah... hack to catch console special sausages. */
789 cio_is_console(struct subchannel_id schid
)
791 if (!console_subchannel_in_use
)
793 return schid_equal(&schid
, &console_subchannel
.schid
);
797 cio_get_console_subchannel(void)
799 if (!console_subchannel_in_use
)
801 return &console_subchannel
;
806 __disable_subchannel_easy(struct subchannel_id schid
, struct schib
*schib
)
811 for (retry
=0;retry
<3;retry
++) {
813 cc
= msch(schid
, schib
);
815 return (cc
==3?-ENODEV
:-EBUSY
);
817 if (!schib
->pmcw
.ena
)
820 return -EBUSY
; /* uhm... */
824 __clear_subchannel_easy(struct subchannel_id schid
)
830 for (retry
=0;retry
<20;retry
++) {
834 tsch(ti
.schid
, (struct irb
*)__LC_IRB
);
835 if (schid_equal(&ti
.schid
, &schid
))
843 extern void do_reipl(unsigned long devno
);
845 __shutdown_subchannel_easy(struct subchannel_id schid
, void *data
)
849 if (stsch_err(schid
, &schib
))
853 switch(__disable_subchannel_easy(schid
, &schib
)) {
857 default: /* -EBUSY */
858 if (__clear_subchannel_easy(schid
))
859 break; /* give up... */
860 stsch(schid
, &schib
);
861 __disable_subchannel_easy(schid
, &schib
);
867 clear_all_subchannels(void)
870 for_each_subchannel(__shutdown_subchannel_easy
, NULL
);
873 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
875 reipl(unsigned long devno
)
877 clear_all_subchannels();