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>
40 #include "blacklist.h"
41 #include "cio_debug.h"
44 debug_info_t *cio_debug_msg_id;
45 debug_info_t *cio_debug_trace_id;
46 debug_info_t *cio_debug_crw_id;
49 * Function: cio_debug_init
50 * Initializes three debug logs for common I/O:
51 * - cio_msg logs generic cio messages
52 * - cio_trace logs the calling of different functions
53 * - cio_crw logs machine check related cio messages
55 static int __init cio_debug_init(void)
57 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long));
58 if (!cio_debug_msg_id)
60 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
61 debug_set_level(cio_debug_msg_id, 2);
62 cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
63 if (!cio_debug_trace_id)
65 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
66 debug_set_level(cio_debug_trace_id, 2);
67 cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long));
68 if (!cio_debug_crw_id)
70 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
71 debug_set_level(cio_debug_crw_id, 4);
76 debug_unregister(cio_debug_msg_id);
77 if (cio_debug_trace_id)
78 debug_unregister(cio_debug_trace_id);
80 debug_unregister(cio_debug_crw_id);
84 arch_initcall (cio_debug_init);
87 cio_set_options (struct subchannel *sch, int flags)
89 sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
90 sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
91 sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
95 /* FIXME: who wants to use this? */
97 cio_get_options (struct subchannel *sch)
102 if (sch->options.suspend)
103 flags |= DOIO_ALLOW_SUSPEND;
104 if (sch->options.prefetch)
105 flags |= DOIO_DENY_PREFETCH;
106 if (sch->options.inter)
107 flags |= DOIO_SUPPRESS_INTER;
112 cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
121 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
122 "subchannel 0.%x.%04x!\n", sch->schid.ssid,
125 if (cio_update_schib(sch))
128 sprintf(dbf_text, "no%s", dev_name(&sch->dev));
129 CIO_TRACE_EVENT(0, dbf_text);
130 CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
132 return (sch->lpm ? -EACCES : -ENODEV);
136 cio_start_key (struct subchannel *sch, /* subchannel structure */
137 struct ccw1 * cpa, /* logical channel prog addr */
138 __u8 lpm, /* logical path mask */
139 __u8 key) /* storage key */
145 CIO_TRACE_EVENT(4, "stIO");
146 CIO_TRACE_EVENT(4, dev_name(&sch->dev));
148 orb = &to_io_private(sch)->orb;
149 memset(orb, 0, sizeof(union orb));
150 /* sch is always under 2G. */
151 orb->cmd.intparm = (u32)(addr_t)sch;
154 orb->cmd.pfch = sch->options.prefetch == 0;
155 orb->cmd.spnd = sch->options.suspend;
156 orb->cmd.ssic = sch->options.suspend && sch->options.inter;
157 orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm;
160 * for 64 bit we always support 64 bit IDAWs with 4k page size only
165 orb->cmd.key = key >> 4;
166 /* issue "Start Subchannel" */
167 orb->cmd.cpa = (__u32) __pa(cpa);
168 ccode = ssch(sch->schid, orb);
170 /* process condition code */
171 sprintf(dbf_txt, "ccode:%d", ccode);
172 CIO_TRACE_EVENT(4, dbf_txt);
177 * initialize device status information
179 sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
181 case 1: /* status pending */
184 case 3: /* device/path not operational */
185 return cio_start_handle_notoper(sch, lpm);
192 cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
194 return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
198 * resume suspended I/O operation
201 cio_resume (struct subchannel *sch)
206 CIO_TRACE_EVENT (4, "resIO");
207 CIO_TRACE_EVENT(4, dev_name(&sch->dev));
209 ccode = rsch (sch->schid);
211 sprintf (dbf_txt, "ccode:%d", ccode);
212 CIO_TRACE_EVENT (4, dbf_txt);
216 sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND;
224 * useless to wait for request completion
225 * as device is no longer operational !
235 cio_halt(struct subchannel *sch)
243 CIO_TRACE_EVENT (2, "haltIO");
244 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
247 * Issue "Halt subchannel" and process condition code
249 ccode = hsch (sch->schid);
251 sprintf (dbf_txt, "ccode:%d", ccode);
252 CIO_TRACE_EVENT (2, dbf_txt);
256 sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND;
258 case 1: /* status pending */
261 default: /* device not operational */
267 * Clear I/O operation
270 cio_clear(struct subchannel *sch)
278 CIO_TRACE_EVENT (2, "clearIO");
279 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
282 * Issue "Clear subchannel" and process condition code
284 ccode = csch (sch->schid);
286 sprintf (dbf_txt, "ccode:%d", ccode);
287 CIO_TRACE_EVENT (2, dbf_txt);
291 sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND;
293 default: /* device not operational */
299 * Function: cio_cancel
300 * Issues a "Cancel Subchannel" on the specified subchannel
301 * Note: We don't need any fancy intparms and flags here
302 * since xsch is executed synchronously.
303 * Only for common I/O internal use as for now.
306 cio_cancel (struct subchannel *sch)
314 CIO_TRACE_EVENT (2, "cancelIO");
315 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
317 ccode = xsch (sch->schid);
319 sprintf (dbf_txt, "ccode:%d", ccode);
320 CIO_TRACE_EVENT (2, dbf_txt);
323 case 0: /* success */
324 /* Update information in scsw. */
325 if (cio_update_schib(sch))
328 case 1: /* status pending */
330 case 2: /* not applicable */
332 default: /* not oper */
338 static void cio_apply_config(struct subchannel *sch, struct schib *schib)
340 schib->pmcw.intparm = sch->config.intparm;
341 schib->pmcw.mbi = sch->config.mbi;
342 schib->pmcw.isc = sch->config.isc;
343 schib->pmcw.ena = sch->config.ena;
344 schib->pmcw.mme = sch->config.mme;
345 schib->pmcw.mp = sch->config.mp;
346 schib->pmcw.csense = sch->config.csense;
347 schib->pmcw.mbfc = sch->config.mbfc;
348 if (sch->config.mbfc)
349 schib->mba = sch->config.mba;
352 static int cio_check_config(struct subchannel *sch, struct schib *schib)
354 return (schib->pmcw.intparm == sch->config.intparm) &&
355 (schib->pmcw.mbi == sch->config.mbi) &&
356 (schib->pmcw.isc == sch->config.isc) &&
357 (schib->pmcw.ena == sch->config.ena) &&
358 (schib->pmcw.mme == sch->config.mme) &&
359 (schib->pmcw.mp == sch->config.mp) &&
360 (schib->pmcw.csense == sch->config.csense) &&
361 (schib->pmcw.mbfc == sch->config.mbfc) &&
362 (!sch->config.mbfc || (schib->mba == sch->config.mba));
366 * cio_commit_config - apply configuration to the subchannel
368 int cio_commit_config(struct subchannel *sch)
371 int ccode, retry, ret = 0;
373 if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
376 for (retry = 0; retry < 5; retry++) {
377 /* copy desired changes to local schib */
378 cio_apply_config(sch, &schib);
379 ccode = msch_err(sch->schid, &schib);
380 if (ccode < 0) /* -EIO if msch gets a program check. */
383 case 0: /* successful */
384 if (stsch(sch->schid, &schib) ||
385 !css_sch_is_valid(&schib))
387 if (cio_check_config(sch, &schib)) {
388 /* commit changes from local schib */
389 memcpy(&sch->schib, &schib, sizeof(schib));
394 case 1: /* status pending */
397 udelay(100); /* allow for recovery */
400 case 3: /* not operational */
408 * cio_update_schib - Perform stsch and update schib if subchannel is valid.
409 * @sch: subchannel on which to perform stsch
410 * Return zero on success, -ENODEV otherwise.
412 int cio_update_schib(struct subchannel *sch)
416 if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
419 memcpy(&sch->schib, &schib, sizeof(schib));
422 EXPORT_SYMBOL_GPL(cio_update_schib);
425 * cio_enable_subchannel - enable a subchannel.
426 * @sch: subchannel to be enabled
427 * @intparm: interruption parameter to set
429 int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
435 CIO_TRACE_EVENT (2, "ensch");
436 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
438 if (sch_is_pseudo_sch(sch))
440 if (cio_update_schib(sch))
444 sch->config.isc = sch->isc;
445 sch->config.intparm = intparm;
447 for (retry = 0; retry < 3; retry++) {
448 ret = cio_commit_config(sch);
451 * Got a program check in msch. Try without
452 * the concurrent sense bit the next time.
454 sch->config.csense = 0;
455 } else if (ret == -EBUSY) {
457 if (tsch(sch->schid, &irb) != 0)
462 sprintf (dbf_txt, "ret:%d", ret);
463 CIO_TRACE_EVENT (2, dbf_txt);
466 EXPORT_SYMBOL_GPL(cio_enable_subchannel);
469 * cio_disable_subchannel - disable a subchannel.
470 * @sch: subchannel to disable
472 int cio_disable_subchannel(struct subchannel *sch)
477 CIO_TRACE_EVENT (2, "dissch");
478 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
480 if (sch_is_pseudo_sch(sch))
482 if (cio_update_schib(sch))
485 if (scsw_actl(&sch->schib.scsw) != 0)
487 * the disable function must not be called while there are
488 * requests pending for completion !
493 ret = cio_commit_config(sch);
495 sprintf (dbf_txt, "ret:%d", ret);
496 CIO_TRACE_EVENT (2, dbf_txt);
499 EXPORT_SYMBOL_GPL(cio_disable_subchannel);
501 int cio_create_sch_lock(struct subchannel *sch)
503 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
506 spin_lock_init(sch->lock);
510 static int cio_check_devno_blacklisted(struct subchannel *sch)
512 if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) {
514 * This device must not be known to Linux. So we simply
515 * say that there is no device and return ENODEV.
517 CIO_MSG_EVENT(6, "Blacklisted device detected "
518 "at devno %04X, subchannel set %x\n",
519 sch->schib.pmcw.dev, sch->schid.ssid);
525 static int cio_validate_io_subchannel(struct subchannel *sch)
527 /* Initialization for io subchannels. */
528 if (!css_sch_is_valid(&sch->schib))
531 /* Devno is valid. */
532 return cio_check_devno_blacklisted(sch);
535 static int cio_validate_msg_subchannel(struct subchannel *sch)
537 /* Initialization for message subchannels. */
538 if (!css_sch_is_valid(&sch->schib))
541 /* Devno is valid. */
542 return cio_check_devno_blacklisted(sch);
546 * cio_validate_subchannel - basic validation of subchannel
547 * @sch: subchannel structure to be filled out
548 * @schid: subchannel id
550 * Find out subchannel type and initialize struct subchannel.
553 * -ENXIO for non-defined subchannels
554 * -ENODEV for invalid subchannels or blacklisted devices
555 * -EIO for subchannels in an invalid subchannel set
557 int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
563 sprintf(dbf_txt, "valsch%x", schid.sch_no);
564 CIO_TRACE_EVENT(4, dbf_txt);
566 /* Nuke all fields. */
567 memset(sch, 0, sizeof(struct subchannel));
570 if (cio_is_console(schid)) {
571 sch->lock = cio_get_console_lock();
573 err = cio_create_sch_lock(sch);
577 mutex_init(&sch->reg_mutex);
578 /* Set a name for the subchannel */
579 if (cio_is_console(schid))
580 sch->dev.init_name = cio_get_console_sch_name(schid);
582 dev_set_name(&sch->dev, "0.%x.%04x", schid.ssid, schid.sch_no);
585 * The first subchannel that is not-operational (ccode==3)
586 * indicates that there aren't any more devices available.
587 * If stsch gets an exception, it means the current subchannel set
590 ccode = stsch_err (schid, &sch->schib);
592 err = (ccode == 3) ? -ENXIO : ccode;
595 /* Copy subchannel type from path management control word. */
596 sch->st = sch->schib.pmcw.st;
599 case SUBCHANNEL_TYPE_IO:
600 err = cio_validate_io_subchannel(sch);
602 case SUBCHANNEL_TYPE_MSG:
603 err = cio_validate_msg_subchannel(sch);
611 CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
612 sch->schid.ssid, sch->schid.sch_no, sch->st);
615 if (!cio_is_console(schid))
622 * do_IRQ() handles all normal I/O device IRQ's (the special
623 * SMP cross-CPU interrupts have their own specific
628 do_IRQ (struct pt_regs *regs)
630 struct tpi_info *tpi_info;
631 struct subchannel *sch;
633 struct pt_regs *old_regs;
635 old_regs = set_irq_regs(regs);
638 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
639 /* Serve timer interrupts first. */
640 clock_comparator_work();
642 * Get interrupt information from lowcore
644 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
645 irb = (struct irb *) __LC_IRB;
647 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
649 * Non I/O-subchannel thin interrupts are processed differently
651 if (tpi_info->adapter_IO == 1 &&
652 tpi_info->int_type == IO_INTERRUPT_TYPE) {
653 do_adapter_IO(tpi_info->isc);
656 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
658 /* Clear pending interrupt condition. */
659 tsch(tpi_info->schid, irb);
662 spin_lock(sch->lock);
663 /* Store interrupt response block to lowcore. */
664 if (tsch(tpi_info->schid, irb) == 0) {
665 /* Keep subchannel information word up to date. */
666 memcpy (&sch->schib.scsw, &irb->scsw,
668 /* Call interrupt handler if there is one. */
669 if (sch->driver && sch->driver->irq)
670 sch->driver->irq(sch);
672 spin_unlock(sch->lock);
674 * Are more interrupts pending?
675 * If so, the tpi instruction will update the lowcore
676 * to hold the info for the next interrupt.
677 * We don't do this for VM because a tpi drops the cpu
678 * out of the sie which costs more cycles than it saves.
680 } while (!MACHINE_IS_VM && tpi (NULL) != 0);
682 set_irq_regs(old_regs);
685 #ifdef CONFIG_CCW_CONSOLE
686 static struct subchannel console_subchannel;
687 static char console_sch_name[10] = "0.x.xxxx";
688 static struct io_subchannel_private console_priv;
689 static int console_subchannel_in_use;
692 * Use tpi to get a pending interrupt, call the interrupt handler and
693 * return a pointer to the subchannel structure.
695 static int cio_tpi(void)
697 struct tpi_info *tpi_info;
698 struct subchannel *sch;
702 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
705 irb = (struct irb *) __LC_IRB;
706 /* Store interrupt response block to lowcore. */
707 if (tsch(tpi_info->schid, irb) != 0)
708 /* Not status pending or not operational. */
710 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
713 irq_context = in_interrupt();
717 spin_lock(sch->lock);
718 memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
719 if (sch->driver && sch->driver->irq)
720 sch->driver->irq(sch);
721 spin_unlock(sch->lock);
728 void *cio_get_console_priv(void)
730 return &console_priv;
734 * busy wait for the next interrupt on the console
736 void wait_cons_dev(void)
737 __releases(console_subchannel.lock)
738 __acquires(console_subchannel.lock)
740 unsigned long cr6 __attribute__ ((aligned (8)));
741 unsigned long save_cr6 __attribute__ ((aligned (8)));
744 * before entering the spinlock we may already have
745 * processed the interrupt on a different CPU...
747 if (!console_subchannel_in_use)
750 /* disable all but the console isc */
751 __ctl_store (save_cr6, 6, 6);
752 cr6 = 1UL << (31 - CONSOLE_ISC);
753 __ctl_load (cr6, 6, 6);
756 spin_unlock(console_subchannel.lock);
759 spin_lock(console_subchannel.lock);
760 } while (console_subchannel.schib.scsw.cmd.actl != 0);
762 * restore previous isc value
764 __ctl_load (save_cr6, 6, 6);
768 cio_test_for_console(struct subchannel_id schid, void *data)
770 if (stsch_err(schid, &console_subchannel.schib) != 0)
772 if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
773 console_subchannel.schib.pmcw.dnv &&
774 (console_subchannel.schib.pmcw.dev == console_devno)) {
775 console_irq = schid.sch_no;
776 return 1; /* found */
783 cio_get_console_sch_no(void)
785 struct subchannel_id schid;
787 init_subchannel_id(&schid);
788 if (console_irq != -1) {
789 /* VM provided us with the irq number of the console. */
790 schid.sch_no = console_irq;
791 if (stsch(schid, &console_subchannel.schib) != 0 ||
792 (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
793 !console_subchannel.schib.pmcw.dnv)
795 console_devno = console_subchannel.schib.pmcw.dev;
796 } else if (console_devno != -1) {
797 /* At least the console device number is known. */
798 for_each_subchannel(cio_test_for_console, NULL);
799 if (console_irq == -1)
802 /* unlike in 2.4, we cannot autoprobe here, since
803 * the channel subsystem is not fully initialized.
804 * With some luck, the HWC console can take over */
811 cio_probe_console(void)
814 struct subchannel_id schid;
816 if (xchg(&console_subchannel_in_use, 1) != 0)
817 return ERR_PTR(-EBUSY);
818 sch_no = cio_get_console_sch_no();
820 console_subchannel_in_use = 0;
821 pr_warning("No CCW console was found\n");
822 return ERR_PTR(-ENODEV);
824 memset(&console_subchannel, 0, sizeof(struct subchannel));
825 init_subchannel_id(&schid);
826 schid.sch_no = sch_no;
827 ret = cio_validate_subchannel(&console_subchannel, schid);
829 console_subchannel_in_use = 0;
830 return ERR_PTR(-ENODEV);
834 * enable console I/O-interrupt subclass
836 isc_register(CONSOLE_ISC);
837 console_subchannel.config.isc = CONSOLE_ISC;
838 console_subchannel.config.intparm = (u32)(addr_t)&console_subchannel;
839 ret = cio_commit_config(&console_subchannel);
841 isc_unregister(CONSOLE_ISC);
842 console_subchannel_in_use = 0;
845 return &console_subchannel;
849 cio_release_console(void)
851 console_subchannel.config.intparm = 0;
852 cio_commit_config(&console_subchannel);
853 isc_unregister(CONSOLE_ISC);
854 console_subchannel_in_use = 0;
857 /* Bah... hack to catch console special sausages. */
859 cio_is_console(struct subchannel_id schid)
861 if (!console_subchannel_in_use)
863 return schid_equal(&schid, &console_subchannel.schid);
867 cio_get_console_subchannel(void)
869 if (!console_subchannel_in_use)
871 return &console_subchannel;
874 const char *cio_get_console_sch_name(struct subchannel_id schid)
876 snprintf(console_sch_name, 10, "0.%x.%04x", schid.ssid, schid.sch_no);
877 return (const char *)console_sch_name;
882 __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
887 for (retry=0;retry<3;retry++) {
889 cc = msch(schid, schib);
891 return (cc==3?-ENODEV:-EBUSY);
892 if (stsch(schid, schib) || !css_sch_is_valid(schib))
894 if (!schib->pmcw.ena)
897 return -EBUSY; /* uhm... */
901 __clear_io_subchannel_easy(struct subchannel_id schid)
907 for (retry=0;retry<20;retry++) {
911 tsch(ti.schid, (struct irb *)__LC_IRB);
912 if (schid_equal(&ti.schid, &schid))
920 static void __clear_chsc_subchannel_easy(void)
922 /* It seems we can only wait for a bit here :/ */
926 static int pgm_check_occured;
928 static void cio_reset_pgm_check_handler(void)
930 pgm_check_occured = 1;
933 static int stsch_reset(struct subchannel_id schid, struct schib *addr)
937 pgm_check_occured = 0;
938 s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
939 rc = stsch(schid, addr);
940 s390_base_pgm_handler_fn = NULL;
942 /* The program check handler could have changed pgm_check_occured. */
945 if (pgm_check_occured)
951 static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
955 if (stsch_reset(schid, &schib))
959 switch(__disable_subchannel_easy(schid, &schib)) {
963 default: /* -EBUSY */
964 switch (schib.pmcw.st) {
965 case SUBCHANNEL_TYPE_IO:
966 if (__clear_io_subchannel_easy(schid))
967 goto out; /* give up... */
969 case SUBCHANNEL_TYPE_CHSC:
970 __clear_chsc_subchannel_easy();
973 /* No default clear strategy */
976 stsch(schid, &schib);
977 __disable_subchannel_easy(schid, &schib);
983 static atomic_t chpid_reset_count;
985 static void s390_reset_chpids_mcck_handler(void)
990 /* Check for pending channel report word. */
991 mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
994 /* Process channel report words. */
995 while (stcrw(&crw) == 0) {
996 /* Check for responses to RCHP. */
997 if (crw.slct && crw.rsc == CRW_RSC_CPATH)
998 atomic_dec(&chpid_reset_count);
1002 #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
1003 static void css_reset(void)
1006 unsigned long long timeout;
1007 struct chp_id chpid;
1009 /* Reset subchannels. */
1010 for_each_subchannel(__shutdown_subchannel_easy, NULL);
1011 /* Reset channel paths. */
1012 s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
1013 /* Enable channel report machine checks. */
1014 __ctl_set_bit(14, 28);
1015 /* Temporarily reenable machine checks. */
1016 local_mcck_enable();
1017 chp_id_init(&chpid);
1018 for (i = 0; i <= __MAX_CHPID; i++) {
1021 if ((ret == 0) || (ret == 2))
1023 * rchp either succeeded, or another rchp is already
1024 * in progress. In either case, we'll get a crw.
1026 atomic_inc(&chpid_reset_count);
1028 /* Wait for machine check for all channel paths. */
1029 timeout = get_clock() + (RCHP_TIMEOUT << 12);
1030 while (atomic_read(&chpid_reset_count) != 0) {
1031 if (get_clock() > timeout)
1035 /* Disable machine checks again. */
1036 local_mcck_disable();
1037 /* Disable channel report machine checks. */
1038 __ctl_clear_bit(14, 28);
1039 s390_base_mcck_handler_fn = NULL;
1042 static struct reset_call css_reset_call = {
1046 static int __init init_css_reset_call(void)
1048 atomic_set(&chpid_reset_count, 0);
1049 register_reset_call(&css_reset_call);
1053 arch_initcall(init_css_reset_call);
1055 struct sch_match_id {
1056 struct subchannel_id schid;
1057 struct ccw_dev_id devid;
1061 static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
1064 struct sch_match_id *match_id = data;
1066 if (stsch_reset(schid, &schib))
1068 if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
1069 (schib.pmcw.dev == match_id->devid.devno) &&
1070 (schid.ssid == match_id->devid.ssid)) {
1071 match_id->schid = schid;
1078 static int reipl_find_schid(struct ccw_dev_id *devid,
1079 struct subchannel_id *schid)
1081 struct sch_match_id match_id;
1083 match_id.devid = *devid;
1084 match_id.rc = -ENODEV;
1085 for_each_subchannel(__reipl_subchannel_match, &match_id);
1086 if (match_id.rc == 0)
1087 *schid = match_id.schid;
1091 extern void do_reipl_asm(__u32 schid);
1093 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
1094 void reipl_ccw_dev(struct ccw_dev_id *devid)
1096 struct subchannel_id schid;
1098 s390_reset_system();
1099 if (reipl_find_schid(devid, &schid) != 0)
1100 panic("IPL Device not found\n");
1101 do_reipl_asm(*((__u32*)&schid));
1104 int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
1106 struct subchannel_id schid;
1109 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
1112 if (stsch(schid, &schib))
1114 if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
1116 if (!schib.pmcw.dnv)
1118 iplinfo->devno = schib.pmcw.dev;
1119 iplinfo->is_qdio = schib.pmcw.qf;
1124 * cio_tm_start_key - perform start function
1125 * @sch: subchannel on which to perform the start function
1126 * @tcw: transport-command word to be started
1127 * @lpm: mask of paths to use
1128 * @key: storage key to use for storage access
1130 * Start the tcw on the given subchannel. Return zero on success, non-zero
1133 int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
1136 union orb *orb = &to_io_private(sch)->orb;
1138 memset(orb, 0, sizeof(union orb));
1139 orb->tm.intparm = (u32) (addr_t) sch;
1140 orb->tm.key = key >> 4;
1142 orb->tm.lpm = lpm ? lpm : sch->lpm;
1143 orb->tm.tcw = (u32) (addr_t) tcw;
1144 cc = ssch(sch->schid, orb);
1152 return cio_start_handle_notoper(sch, lpm);
1157 * cio_tm_intrg - perform interrogate function
1158 * @sch - subchannel on which to perform the interrogate function
1160 * If the specified subchannel is running in transport-mode, perform the
1161 * interrogate function. Return zero on success, non-zero otherwie.
1163 int cio_tm_intrg(struct subchannel *sch)
1167 if (!to_io_private(sch)->orb.tm.b)
1169 cc = xsch(sch->schid);