2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls
6 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH,
8 * Author(s): Ingo Adlung (adlung@de.ibm.com)
9 * Cornelia Huck (cohuck@de.ibm.com)
10 * Arnd Bergmann (arndb@de.ibm.com)
11 * Martin Schwidefsky (schwidefsky@de.ibm.com)
14 #include <linux/module.h>
15 #include <linux/config.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>
23 #include <asm/delay.h>
31 #include "blacklist.h"
32 #include "cio_debug.h"
34 debug_info_t
*cio_debug_msg_id
;
35 debug_info_t
*cio_debug_trace_id
;
36 debug_info_t
*cio_debug_crw_id
;
41 cio_setup (char *parm
)
43 if (!strcmp (parm
, "yes"))
45 else if (!strcmp (parm
, "no"))
48 printk (KERN_ERR
"cio_setup : invalid cio_msg parameter '%s'",
53 __setup ("cio_msg=", cio_setup
);
56 * Function: cio_debug_init
57 * Initializes three debug logs (under /proc/s390dbf) for common I/O:
58 * - cio_msg logs the messages which are printk'ed when CONFIG_DEBUG_IO is on
59 * - cio_trace logs the calling of different functions
60 * - cio_crw logs the messages which are printk'ed when CONFIG_DEBUG_CRW is on
61 * debug levels depend on CONFIG_DEBUG_IO resp. CONFIG_DEBUG_CRW
66 cio_debug_msg_id
= debug_register ("cio_msg", 16, 4, 16*sizeof (long));
67 if (!cio_debug_msg_id
)
69 debug_register_view (cio_debug_msg_id
, &debug_sprintf_view
);
70 debug_set_level (cio_debug_msg_id
, 2);
71 cio_debug_trace_id
= debug_register ("cio_trace", 16, 4, 8);
72 if (!cio_debug_trace_id
)
74 debug_register_view (cio_debug_trace_id
, &debug_hex_ascii_view
);
75 debug_set_level (cio_debug_trace_id
, 2);
76 cio_debug_crw_id
= debug_register ("cio_crw", 4, 4, 16*sizeof (long));
77 if (!cio_debug_crw_id
)
79 debug_register_view (cio_debug_crw_id
, &debug_sprintf_view
);
80 debug_set_level (cio_debug_crw_id
, 2);
81 pr_debug("debugging initialized\n");
86 debug_unregister (cio_debug_msg_id
);
87 if (cio_debug_trace_id
)
88 debug_unregister (cio_debug_trace_id
);
90 debug_unregister (cio_debug_crw_id
);
91 pr_debug("could not initialize debugging\n");
95 arch_initcall (cio_debug_init
);
98 cio_set_options (struct subchannel
*sch
, int flags
)
100 sch
->options
.suspend
= (flags
& DOIO_ALLOW_SUSPEND
) != 0;
101 sch
->options
.prefetch
= (flags
& DOIO_DENY_PREFETCH
) != 0;
102 sch
->options
.inter
= (flags
& DOIO_SUPPRESS_INTER
) != 0;
106 /* FIXME: who wants to use this? */
108 cio_get_options (struct subchannel
*sch
)
113 if (sch
->options
.suspend
)
114 flags
|= DOIO_ALLOW_SUSPEND
;
115 if (sch
->options
.prefetch
)
116 flags
|= DOIO_DENY_PREFETCH
;
117 if (sch
->options
.inter
)
118 flags
|= DOIO_SUPPRESS_INTER
;
123 * Use tpi to get a pending interrupt, call the interrupt handler and
124 * return a pointer to the subchannel structure.
129 struct tpi_info
*tpi_info
;
130 struct subchannel
*sch
;
133 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
136 irb
= (struct irb
*) __LC_IRB
;
137 /* Store interrupt response block to lowcore. */
138 if (tsch (tpi_info
->irq
, irb
) != 0)
139 /* Not status pending or not operational. */
141 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
146 spin_lock(&sch
->lock
);
147 memcpy (&sch
->schib
.scsw
, &irb
->scsw
, sizeof (struct scsw
));
148 if (sch
->driver
&& sch
->driver
->irq
)
149 sch
->driver
->irq(&sch
->dev
);
150 spin_unlock(&sch
->lock
);
157 cio_start_handle_notoper(struct subchannel
*sch
, __u8 lpm
)
166 stsch (sch
->irq
, &sch
->schib
);
168 CIO_MSG_EVENT(0, "cio_start: 'not oper' status for "
169 "subchannel %04x!\n", sch
->irq
);
170 sprintf(dbf_text
, "no%s", sch
->dev
.bus_id
);
171 CIO_TRACE_EVENT(0, dbf_text
);
172 CIO_HEX_EVENT(0, &sch
->schib
, sizeof (struct schib
));
174 return (sch
->lpm
? -EACCES
: -ENODEV
);
178 cio_start_key (struct subchannel
*sch
, /* subchannel structure */
179 struct ccw1
* cpa
, /* logical channel prog addr */
180 __u8 lpm
, /* logical path mask */
181 __u8 key
) /* storage key */
186 CIO_TRACE_EVENT (4, "stIO");
187 CIO_TRACE_EVENT (4, sch
->dev
.bus_id
);
189 /* sch is always under 2G. */
190 sch
->orb
.intparm
= (__u32
)(unsigned long)sch
;
193 sch
->orb
.pfch
= sch
->options
.prefetch
== 0;
194 sch
->orb
.spnd
= sch
->options
.suspend
;
195 sch
->orb
.ssic
= sch
->options
.suspend
&& sch
->options
.inter
;
196 sch
->orb
.lpm
= (lpm
!= 0) ? (lpm
& sch
->opm
) : sch
->lpm
;
197 #ifdef CONFIG_ARCH_S390X
199 * for 64 bit we always support 64 bit IDAWs with 4k page size only
204 sch
->orb
.key
= key
>> 4;
205 /* issue "Start Subchannel" */
206 sch
->orb
.cpa
= (__u32
) __pa (cpa
);
207 ccode
= ssch (sch
->irq
, &sch
->orb
);
209 /* process condition code */
210 sprintf (dbf_txt
, "ccode:%d", ccode
);
211 CIO_TRACE_EVENT (4, dbf_txt
);
216 * initialize device status information
218 sch
->schib
.scsw
.actl
|= SCSW_ACTL_START_PEND
;
220 case 1: /* status pending */
223 default: /* device/path not operational */
224 return cio_start_handle_notoper(sch
, lpm
);
229 cio_start (struct subchannel
*sch
, struct ccw1
*cpa
, __u8 lpm
)
231 return cio_start_key(sch
, cpa
, lpm
, PAGE_DEFAULT_KEY
);
235 * resume suspended I/O operation
238 cio_resume (struct subchannel
*sch
)
243 CIO_TRACE_EVENT (4, "resIO");
244 CIO_TRACE_EVENT (4, sch
->dev
.bus_id
);
246 ccode
= rsch (sch
->irq
);
248 sprintf (dbf_txt
, "ccode:%d", ccode
);
249 CIO_TRACE_EVENT (4, dbf_txt
);
253 sch
->schib
.scsw
.actl
|= SCSW_ACTL_RESUME_PEND
;
261 * useless to wait for request completion
262 * as device is no longer operational !
272 cio_halt(struct subchannel
*sch
)
280 CIO_TRACE_EVENT (2, "haltIO");
281 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
284 * Issue "Halt subchannel" and process condition code
286 ccode
= hsch (sch
->irq
);
288 sprintf (dbf_txt
, "ccode:%d", ccode
);
289 CIO_TRACE_EVENT (2, dbf_txt
);
293 sch
->schib
.scsw
.actl
|= SCSW_ACTL_HALT_PEND
;
295 case 1: /* status pending */
298 default: /* device not operational */
304 * Clear I/O operation
307 cio_clear(struct subchannel
*sch
)
315 CIO_TRACE_EVENT (2, "clearIO");
316 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
319 * Issue "Clear subchannel" and process condition code
321 ccode
= csch (sch
->irq
);
323 sprintf (dbf_txt
, "ccode:%d", ccode
);
324 CIO_TRACE_EVENT (2, dbf_txt
);
328 sch
->schib
.scsw
.actl
|= SCSW_ACTL_CLEAR_PEND
;
330 default: /* device not operational */
336 * Function: cio_cancel
337 * Issues a "Cancel Subchannel" on the specified subchannel
338 * Note: We don't need any fancy intparms and flags here
339 * since xsch is executed synchronously.
340 * Only for common I/O internal use as for now.
343 cio_cancel (struct subchannel
*sch
)
351 CIO_TRACE_EVENT (2, "cancelIO");
352 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
354 ccode
= xsch (sch
->irq
);
356 sprintf (dbf_txt
, "ccode:%d", ccode
);
357 CIO_TRACE_EVENT (2, dbf_txt
);
360 case 0: /* success */
361 /* Update information in scsw. */
362 stsch (sch
->irq
, &sch
->schib
);
364 case 1: /* status pending */
366 case 2: /* not applicable */
368 default: /* not oper */
374 * Function: cio_modify
375 * Issues a "Modify Subchannel" on the specified subchannel
378 cio_modify (struct subchannel
*sch
)
380 int ccode
, retry
, ret
;
383 for (retry
= 0; retry
< 5; retry
++) {
384 ccode
= msch_err (sch
->irq
, &sch
->schib
);
385 if (ccode
< 0) /* -EIO if msch gets a program check. */
388 case 0: /* successfull */
390 case 1: /* status pending */
393 udelay (100); /* allow for recovery */
396 case 3: /* not operational */
407 cio_enable_subchannel (struct subchannel
*sch
, unsigned int isc
)
414 CIO_TRACE_EVENT (2, "ensch");
415 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
417 ccode
= stsch (sch
->irq
, &sch
->schib
);
421 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
422 sch
->schib
.pmcw
.ena
= 1;
423 sch
->schib
.pmcw
.isc
= isc
;
424 sch
->schib
.pmcw
.intparm
= (__u32
)(unsigned long)sch
;
425 ret
= cio_modify(sch
);
430 * Got a program check in cio_modify. Try without
431 * the concurrent sense bit the next time.
433 sch
->schib
.pmcw
.csense
= 0;
435 stsch (sch
->irq
, &sch
->schib
);
436 if (sch
->schib
.pmcw
.ena
)
441 if (tsch(sch
->irq
, &irb
) != 0)
445 sprintf (dbf_txt
, "ret:%d", ret
);
446 CIO_TRACE_EVENT (2, dbf_txt
);
451 * Disable subchannel.
454 cio_disable_subchannel (struct subchannel
*sch
)
461 CIO_TRACE_EVENT (2, "dissch");
462 CIO_TRACE_EVENT (2, sch
->dev
.bus_id
);
464 ccode
= stsch (sch
->irq
, &sch
->schib
);
465 if (ccode
== 3) /* Not operational. */
468 if (sch
->schib
.scsw
.actl
!= 0)
470 * the disable function must not be called while there are
471 * requests pending for completion !
475 for (retry
= 5, ret
= 0; retry
> 0; retry
--) {
476 sch
->schib
.pmcw
.ena
= 0;
477 ret
= cio_modify(sch
);
482 * The subchannel is busy or status pending.
483 * We'll disable when the next interrupt was delivered
484 * via the state machine.
488 stsch (sch
->irq
, &sch
->schib
);
489 if (!sch
->schib
.pmcw
.ena
)
493 sprintf (dbf_txt
, "ret:%d", ret
);
494 CIO_TRACE_EVENT (2, dbf_txt
);
499 * cio_validate_subchannel()
501 * Find out subchannel type and initialize struct subchannel.
503 * SUBCHANNEL_TYPE_IO for a normal io subchannel
504 * SUBCHANNEL_TYPE_CHSC for a chsc subchannel
505 * SUBCHANNEL_TYPE_MESSAGE for a messaging subchannel
506 * SUBCHANNEL_TYPE_ADM for a adm(?) subchannel
507 * -ENXIO for non-defined subchannels
508 * -ENODEV for subchannels with invalid device number or blacklisted devices
511 cio_validate_subchannel (struct subchannel
*sch
, unsigned int irq
)
516 sprintf (dbf_txt
, "valsch%x", irq
);
517 CIO_TRACE_EVENT (4, dbf_txt
);
519 /* Nuke all fields. */
520 memset(sch
, 0, sizeof(struct subchannel
));
522 spin_lock_init(&sch
->lock
);
524 /* Set a name for the subchannel */
525 snprintf (sch
->dev
.bus_id
, BUS_ID_SIZE
, "0.0.%04x", irq
);
528 * The first subchannel that is not-operational (ccode==3)
529 * indicates that there aren't any more devices available.
532 ccode
= stsch (irq
, &sch
->schib
);
536 /* Copy subchannel type from path management control word. */
537 sch
->st
= sch
->schib
.pmcw
.st
;
540 * ... just being curious we check for non I/O subchannels
543 CIO_DEBUG(KERN_INFO
, 0,
544 "Subchannel %04X reports "
545 "non-I/O subchannel type %04X\n",
547 /* We stop here for non-io subchannels. */
551 /* Initialization for io subchannels. */
552 if (!sch
->schib
.pmcw
.dnv
)
553 /* io subchannel but device number is invalid. */
556 /* Devno is valid. */
557 if (is_blacklisted (sch
->schib
.pmcw
.dev
)) {
559 * This device must not be known to Linux. So we simply
560 * say that there is no device and return ENODEV.
562 CIO_MSG_EVENT(0, "Blacklisted device detected "
563 "at devno %04X\n", sch
->schib
.pmcw
.dev
);
567 chsc_validate_chpids(sch
);
568 sch
->lpm
= sch
->schib
.pmcw
.pim
&
569 sch
->schib
.pmcw
.pam
&
570 sch
->schib
.pmcw
.pom
&
573 CIO_DEBUG(KERN_INFO
, 0,
574 "Detected device %04X on subchannel %04X"
575 " - PIM = %02X, PAM = %02X, POM = %02X\n",
576 sch
->schib
.pmcw
.dev
, sch
->irq
, sch
->schib
.pmcw
.pim
,
577 sch
->schib
.pmcw
.pam
, sch
->schib
.pmcw
.pom
);
580 * We now have to initially ...
581 * ... set "interruption subclass"
582 * ... enable "concurrent sense"
583 * ... enable "multipath mode" if more than one
584 * CHPID is available. This is done regardless
585 * whether multiple paths are available for us.
587 sch
->schib
.pmcw
.isc
= 3; /* could be smth. else */
588 sch
->schib
.pmcw
.csense
= 1; /* concurrent sense */
589 sch
->schib
.pmcw
.ena
= 0;
590 if ((sch
->lpm
& (sch
->lpm
- 1)) != 0)
591 sch
->schib
.pmcw
.mp
= 1; /* multipath mode */
596 * do_IRQ() handles all normal I/O device IRQ's (the special
597 * SMP cross-CPU interrupts have their own specific
602 do_IRQ (struct pt_regs
*regs
)
604 struct tpi_info
*tpi_info
;
605 struct subchannel
*sch
;
609 asm volatile ("mc 0,0");
610 if (S390_lowcore
.int_clock
>= S390_lowcore
.jiffy_timer
)
612 * Make sure that the i/o interrupt did not "overtake"
613 * the last HZ timer interrupt.
617 * Get interrupt information from lowcore
619 tpi_info
= (struct tpi_info
*) __LC_SUBCHANNEL_ID
;
620 irb
= (struct irb
*) __LC_IRB
;
622 kstat_cpu(smp_processor_id()).irqs
[IO_INTERRUPT
]++;
624 * Non I/O-subchannel thin interrupts are processed differently
626 if (tpi_info
->adapter_IO
== 1 &&
627 tpi_info
->int_type
== IO_INTERRUPT_TYPE
) {
631 sch
= (struct subchannel
*)(unsigned long)tpi_info
->intparm
;
633 spin_lock(&sch
->lock
);
634 /* Store interrupt response block to lowcore. */
635 if (tsch (tpi_info
->irq
, irb
) == 0 && sch
) {
636 /* Keep subchannel information word up to date. */
637 memcpy (&sch
->schib
.scsw
, &irb
->scsw
,
639 /* Call interrupt handler if there is one. */
640 if (sch
->driver
&& sch
->driver
->irq
)
641 sch
->driver
->irq(&sch
->dev
);
644 spin_unlock(&sch
->lock
);
646 * Are more interrupts pending?
647 * If so, the tpi instruction will update the lowcore
648 * to hold the info for the next interrupt.
649 * We don't do this for VM because a tpi drops the cpu
650 * out of the sie which costs more cycles than it saves.
652 } while (!MACHINE_IS_VM
&& tpi (NULL
) != 0);
656 #ifdef CONFIG_CCW_CONSOLE
657 static struct subchannel console_subchannel
;
658 static int console_subchannel_in_use
;
661 * busy wait for the next interrupt on the console
666 unsigned long cr6
__attribute__ ((aligned (8)));
667 unsigned long save_cr6
__attribute__ ((aligned (8)));
670 * before entering the spinlock we may already have
671 * processed the interrupt on a different CPU...
673 if (!console_subchannel_in_use
)
676 /* disable all but isc 7 (console device) */
677 __ctl_store (save_cr6
, 6, 6);
679 __ctl_load (cr6
, 6, 6);
682 spin_unlock(&console_subchannel
.lock
);
685 spin_lock(&console_subchannel
.lock
);
686 } while (console_subchannel
.schib
.scsw
.actl
!= 0);
688 * restore previous isc value
690 __ctl_load (save_cr6
, 6, 6);
694 cio_console_irq(void)
698 if (console_irq
!= -1) {
699 /* VM provided us with the irq number of the console. */
700 if (stsch(console_irq
, &console_subchannel
.schib
) != 0 ||
701 !console_subchannel
.schib
.pmcw
.dnv
)
703 console_devno
= console_subchannel
.schib
.pmcw
.dev
;
704 } else if (console_devno
!= -1) {
705 /* At least the console device number is known. */
706 for (irq
= 0; irq
< __MAX_SUBCHANNELS
; irq
++) {
707 if (stsch(irq
, &console_subchannel
.schib
) != 0)
709 if (console_subchannel
.schib
.pmcw
.dnv
&&
710 console_subchannel
.schib
.pmcw
.dev
==
716 if (console_irq
== -1)
719 /* unlike in 2.4, we cannot autoprobe here, since
720 * the channel subsystem is not fully initialized.
721 * With some luck, the HWC console can take over */
722 printk(KERN_WARNING
"No ccw console found!\n");
729 cio_probe_console(void)
733 if (xchg(&console_subchannel_in_use
, 1) != 0)
734 return ERR_PTR(-EBUSY
);
735 irq
= cio_console_irq();
737 console_subchannel_in_use
= 0;
738 return ERR_PTR(-ENODEV
);
740 memset(&console_subchannel
, 0, sizeof(struct subchannel
));
741 ret
= cio_validate_subchannel(&console_subchannel
, irq
);
743 console_subchannel_in_use
= 0;
744 return ERR_PTR(-ENODEV
);
748 * enable console I/O-interrupt subclass 7
751 console_subchannel
.schib
.pmcw
.isc
= 7;
752 console_subchannel
.schib
.pmcw
.intparm
=
753 (__u32
)(unsigned long)&console_subchannel
;
754 ret
= cio_modify(&console_subchannel
);
756 console_subchannel_in_use
= 0;
759 return &console_subchannel
;
763 cio_release_console(void)
765 console_subchannel
.schib
.pmcw
.intparm
= 0;
766 cio_modify(&console_subchannel
);
767 ctl_clear_bit(6, 24);
768 console_subchannel_in_use
= 0;
771 /* Bah... hack to catch console special sausages. */
773 cio_is_console(int irq
)
775 if (!console_subchannel_in_use
)
777 return (irq
== console_subchannel
.irq
);
781 cio_get_console_subchannel(void)
783 if (!console_subchannel_in_use
)
785 return &console_subchannel
;
790 __disable_subchannel_easy(unsigned int schid
, struct schib
*schib
)
795 for (retry
=0;retry
<3;retry
++) {
797 cc
= msch(schid
, schib
);
799 return (cc
==3?-ENODEV
:-EBUSY
);
801 if (!schib
->pmcw
.ena
)
804 return -EBUSY
; /* uhm... */
808 __clear_subchannel_easy(unsigned int schid
)
814 for (retry
=0;retry
<20;retry
++) {
818 tsch(ti
.irq
, (struct irb
*)__LC_IRB
);
827 extern void do_reipl(unsigned long devno
);
829 /* Clear all subchannels. */
831 clear_all_subchannels(void)
836 for (schid
=0;schid
<=highest_subchannel
;schid
++) {
838 if (stsch(schid
, &schib
))
839 break; /* break out of the loop */
842 switch(__disable_subchannel_easy(schid
, &schib
)) {
846 default: /* -EBUSY */
847 if (__clear_subchannel_easy(schid
))
848 break; /* give up... jump out of switch */
849 stsch(schid
, &schib
);
850 __disable_subchannel_easy(schid
, &schib
);
855 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
857 reipl(unsigned long devno
)
859 clear_all_subchannels();