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/ftrace.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/slab.h>
19 #include <linux/device.h>
20 #include <linux/kernel_stat.h>
21 #include <linux/interrupt.h>
23 #include <asm/delay.h>
25 #include <asm/irq_regs.h>
26 #include <asm/setup.h>
27 #include <asm/reset.h>
29 #include <asm/chpid.h>
32 #include <asm/cputime.h>
41 #include "blacklist.h"
42 #include "cio_debug.h"
45 debug_info_t *cio_debug_msg_id;
46 debug_info_t *cio_debug_trace_id;
47 debug_info_t *cio_debug_crw_id;
50 * Function: cio_debug_init
51 * Initializes three debug logs for common I/O:
52 * - cio_msg logs generic cio messages
53 * - cio_trace logs the calling of different functions
54 * - cio_crw logs machine check related cio messages
56 static int __init cio_debug_init(void)
58 cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long));
59 if (!cio_debug_msg_id)
61 debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
62 debug_set_level(cio_debug_msg_id, 2);
63 cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
64 if (!cio_debug_trace_id)
66 debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
67 debug_set_level(cio_debug_trace_id, 2);
68 cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long));
69 if (!cio_debug_crw_id)
71 debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
72 debug_set_level(cio_debug_crw_id, 4);
77 debug_unregister(cio_debug_msg_id);
78 if (cio_debug_trace_id)
79 debug_unregister(cio_debug_trace_id);
81 debug_unregister(cio_debug_crw_id);
85 arch_initcall (cio_debug_init);
88 cio_set_options (struct subchannel *sch, int flags)
90 sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
91 sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
92 sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
96 /* FIXME: who wants to use this? */
98 cio_get_options (struct subchannel *sch)
103 if (sch->options.suspend)
104 flags |= DOIO_ALLOW_SUSPEND;
105 if (sch->options.prefetch)
106 flags |= DOIO_DENY_PREFETCH;
107 if (sch->options.inter)
108 flags |= DOIO_SUPPRESS_INTER;
113 cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
122 CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
123 "subchannel 0.%x.%04x!\n", sch->schid.ssid,
126 if (cio_update_schib(sch))
129 sprintf(dbf_text, "no%s", dev_name(&sch->dev));
130 CIO_TRACE_EVENT(0, dbf_text);
131 CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
133 return (sch->lpm ? -EACCES : -ENODEV);
137 cio_start_key (struct subchannel *sch, /* subchannel structure */
138 struct ccw1 * cpa, /* logical channel prog addr */
139 __u8 lpm, /* logical path mask */
140 __u8 key) /* storage key */
146 CIO_TRACE_EVENT(4, "stIO");
147 CIO_TRACE_EVENT(4, dev_name(&sch->dev));
149 orb = &to_io_private(sch)->orb;
150 memset(orb, 0, sizeof(union orb));
151 /* sch is always under 2G. */
152 orb->cmd.intparm = (u32)(addr_t)sch;
155 orb->cmd.pfch = sch->options.prefetch == 0;
156 orb->cmd.spnd = sch->options.suspend;
157 orb->cmd.ssic = sch->options.suspend && sch->options.inter;
158 orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm;
161 * for 64 bit we always support 64 bit IDAWs with 4k page size only
166 orb->cmd.key = key >> 4;
167 /* issue "Start Subchannel" */
168 orb->cmd.cpa = (__u32) __pa(cpa);
169 ccode = ssch(sch->schid, orb);
171 /* process condition code */
172 sprintf(dbf_txt, "ccode:%d", ccode);
173 CIO_TRACE_EVENT(4, dbf_txt);
178 * initialize device status information
180 sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
182 case 1: /* status pending */
185 case 3: /* device/path not operational */
186 return cio_start_handle_notoper(sch, lpm);
193 cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
195 return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
199 * resume suspended I/O operation
202 cio_resume (struct subchannel *sch)
207 CIO_TRACE_EVENT (4, "resIO");
208 CIO_TRACE_EVENT(4, dev_name(&sch->dev));
210 ccode = rsch (sch->schid);
212 sprintf (dbf_txt, "ccode:%d", ccode);
213 CIO_TRACE_EVENT (4, dbf_txt);
217 sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND;
225 * useless to wait for request completion
226 * as device is no longer operational !
236 cio_halt(struct subchannel *sch)
244 CIO_TRACE_EVENT (2, "haltIO");
245 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
248 * Issue "Halt subchannel" and process condition code
250 ccode = hsch (sch->schid);
252 sprintf (dbf_txt, "ccode:%d", ccode);
253 CIO_TRACE_EVENT (2, dbf_txt);
257 sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND;
259 case 1: /* status pending */
262 default: /* device not operational */
268 * Clear I/O operation
271 cio_clear(struct subchannel *sch)
279 CIO_TRACE_EVENT (2, "clearIO");
280 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
283 * Issue "Clear subchannel" and process condition code
285 ccode = csch (sch->schid);
287 sprintf (dbf_txt, "ccode:%d", ccode);
288 CIO_TRACE_EVENT (2, dbf_txt);
292 sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND;
294 default: /* device not operational */
300 * Function: cio_cancel
301 * Issues a "Cancel Subchannel" on the specified subchannel
302 * Note: We don't need any fancy intparms and flags here
303 * since xsch is executed synchronously.
304 * Only for common I/O internal use as for now.
307 cio_cancel (struct subchannel *sch)
315 CIO_TRACE_EVENT (2, "cancelIO");
316 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
318 ccode = xsch (sch->schid);
320 sprintf (dbf_txt, "ccode:%d", ccode);
321 CIO_TRACE_EVENT (2, dbf_txt);
324 case 0: /* success */
325 /* Update information in scsw. */
326 if (cio_update_schib(sch))
329 case 1: /* status pending */
331 case 2: /* not applicable */
333 default: /* not oper */
339 static void cio_apply_config(struct subchannel *sch, struct schib *schib)
341 schib->pmcw.intparm = sch->config.intparm;
342 schib->pmcw.mbi = sch->config.mbi;
343 schib->pmcw.isc = sch->config.isc;
344 schib->pmcw.ena = sch->config.ena;
345 schib->pmcw.mme = sch->config.mme;
346 schib->pmcw.mp = sch->config.mp;
347 schib->pmcw.csense = sch->config.csense;
348 schib->pmcw.mbfc = sch->config.mbfc;
349 if (sch->config.mbfc)
350 schib->mba = sch->config.mba;
353 static int cio_check_config(struct subchannel *sch, struct schib *schib)
355 return (schib->pmcw.intparm == sch->config.intparm) &&
356 (schib->pmcw.mbi == sch->config.mbi) &&
357 (schib->pmcw.isc == sch->config.isc) &&
358 (schib->pmcw.ena == sch->config.ena) &&
359 (schib->pmcw.mme == sch->config.mme) &&
360 (schib->pmcw.mp == sch->config.mp) &&
361 (schib->pmcw.csense == sch->config.csense) &&
362 (schib->pmcw.mbfc == sch->config.mbfc) &&
363 (!sch->config.mbfc || (schib->mba == sch->config.mba));
367 * cio_commit_config - apply configuration to the subchannel
369 int cio_commit_config(struct subchannel *sch)
372 int ccode, retry, ret = 0;
374 if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
377 for (retry = 0; retry < 5; retry++) {
378 /* copy desired changes to local schib */
379 cio_apply_config(sch, &schib);
380 ccode = msch_err(sch->schid, &schib);
381 if (ccode < 0) /* -EIO if msch gets a program check. */
384 case 0: /* successful */
385 if (stsch(sch->schid, &schib) ||
386 !css_sch_is_valid(&schib))
388 if (cio_check_config(sch, &schib)) {
389 /* commit changes from local schib */
390 memcpy(&sch->schib, &schib, sizeof(schib));
395 case 1: /* status pending */
398 udelay(100); /* allow for recovery */
401 case 3: /* not operational */
409 * cio_update_schib - Perform stsch and update schib if subchannel is valid.
410 * @sch: subchannel on which to perform stsch
411 * Return zero on success, -ENODEV otherwise.
413 int cio_update_schib(struct subchannel *sch)
417 if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
420 memcpy(&sch->schib, &schib, sizeof(schib));
423 EXPORT_SYMBOL_GPL(cio_update_schib);
426 * cio_enable_subchannel - enable a subchannel.
427 * @sch: subchannel to be enabled
428 * @intparm: interruption parameter to set
430 int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
436 CIO_TRACE_EVENT (2, "ensch");
437 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
439 if (sch_is_pseudo_sch(sch))
441 if (cio_update_schib(sch))
445 sch->config.isc = sch->isc;
446 sch->config.intparm = intparm;
448 for (retry = 0; retry < 3; retry++) {
449 ret = cio_commit_config(sch);
452 * Got a program check in msch. Try without
453 * the concurrent sense bit the next time.
455 sch->config.csense = 0;
456 } else if (ret == -EBUSY) {
458 if (tsch(sch->schid, &irb) != 0)
463 sprintf (dbf_txt, "ret:%d", ret);
464 CIO_TRACE_EVENT (2, dbf_txt);
467 EXPORT_SYMBOL_GPL(cio_enable_subchannel);
470 * cio_disable_subchannel - disable a subchannel.
471 * @sch: subchannel to disable
473 int cio_disable_subchannel(struct subchannel *sch)
479 CIO_TRACE_EVENT (2, "dissch");
480 CIO_TRACE_EVENT(2, dev_name(&sch->dev));
482 if (sch_is_pseudo_sch(sch))
484 if (cio_update_schib(sch))
489 for (retry = 0; retry < 3; retry++) {
490 ret = cio_commit_config(sch);
493 if (tsch(sch->schid, &irb) != 0)
498 sprintf (dbf_txt, "ret:%d", ret);
499 CIO_TRACE_EVENT (2, dbf_txt);
502 EXPORT_SYMBOL_GPL(cio_disable_subchannel);
504 int cio_create_sch_lock(struct subchannel *sch)
506 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
509 spin_lock_init(sch->lock);
513 static int cio_check_devno_blacklisted(struct subchannel *sch)
515 if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) {
517 * This device must not be known to Linux. So we simply
518 * say that there is no device and return ENODEV.
520 CIO_MSG_EVENT(6, "Blacklisted device detected "
521 "at devno %04X, subchannel set %x\n",
522 sch->schib.pmcw.dev, sch->schid.ssid);
528 static int cio_validate_io_subchannel(struct subchannel *sch)
530 /* Initialization for io subchannels. */
531 if (!css_sch_is_valid(&sch->schib))
534 /* Devno is valid. */
535 return cio_check_devno_blacklisted(sch);
538 static int cio_validate_msg_subchannel(struct subchannel *sch)
540 /* Initialization for message subchannels. */
541 if (!css_sch_is_valid(&sch->schib))
544 /* Devno is valid. */
545 return cio_check_devno_blacklisted(sch);
549 * cio_validate_subchannel - basic validation of subchannel
550 * @sch: subchannel structure to be filled out
551 * @schid: subchannel id
553 * Find out subchannel type and initialize struct subchannel.
556 * -ENXIO for non-defined subchannels
557 * -ENODEV for invalid subchannels or blacklisted devices
558 * -EIO for subchannels in an invalid subchannel set
560 int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid)
566 sprintf(dbf_txt, "valsch%x", schid.sch_no);
567 CIO_TRACE_EVENT(4, dbf_txt);
569 /* Nuke all fields. */
570 memset(sch, 0, sizeof(struct subchannel));
573 if (cio_is_console(schid)) {
574 sch->lock = cio_get_console_lock();
576 err = cio_create_sch_lock(sch);
580 mutex_init(&sch->reg_mutex);
581 /* Set a name for the subchannel */
582 if (cio_is_console(schid))
583 sch->dev.init_name = cio_get_console_sch_name(schid);
585 dev_set_name(&sch->dev, "0.%x.%04x", schid.ssid, schid.sch_no);
588 * The first subchannel that is not-operational (ccode==3)
589 * indicates that there aren't any more devices available.
590 * If stsch gets an exception, it means the current subchannel set
593 ccode = stsch_err (schid, &sch->schib);
595 err = (ccode == 3) ? -ENXIO : ccode;
598 /* Copy subchannel type from path management control word. */
599 sch->st = sch->schib.pmcw.st;
602 case SUBCHANNEL_TYPE_IO:
603 err = cio_validate_io_subchannel(sch);
605 case SUBCHANNEL_TYPE_MSG:
606 err = cio_validate_msg_subchannel(sch);
614 CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n",
615 sch->schid.ssid, sch->schid.sch_no, sch->st);
618 if (!cio_is_console(schid))
625 * do_IRQ() handles all normal I/O device IRQ's (the special
626 * SMP cross-CPU interrupts have their own specific
630 void __irq_entry do_IRQ(struct pt_regs *regs)
632 struct tpi_info *tpi_info;
633 struct subchannel *sch;
635 struct pt_regs *old_regs;
637 old_regs = set_irq_regs(regs);
640 if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
641 /* Serve timer interrupts first. */
642 clock_comparator_work();
644 * Get interrupt information from lowcore
646 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
647 irb = (struct irb *) __LC_IRB;
649 kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++;
651 * Non I/O-subchannel thin interrupts are processed differently
653 if (tpi_info->adapter_IO == 1 &&
654 tpi_info->int_type == IO_INTERRUPT_TYPE) {
655 do_adapter_IO(tpi_info->isc);
658 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
660 /* Clear pending interrupt condition. */
661 tsch(tpi_info->schid, irb);
664 spin_lock(sch->lock);
665 /* Store interrupt response block to lowcore. */
666 if (tsch(tpi_info->schid, irb) == 0) {
667 /* Keep subchannel information word up to date. */
668 memcpy (&sch->schib.scsw, &irb->scsw,
670 /* Call interrupt handler if there is one. */
671 if (sch->driver && sch->driver->irq)
672 sch->driver->irq(sch);
674 spin_unlock(sch->lock);
676 * Are more interrupts pending?
677 * If so, the tpi instruction will update the lowcore
678 * to hold the info for the next interrupt.
679 * We don't do this for VM because a tpi drops the cpu
680 * out of the sie which costs more cycles than it saves.
682 } while (!MACHINE_IS_VM && tpi (NULL) != 0);
684 set_irq_regs(old_regs);
687 #ifdef CONFIG_CCW_CONSOLE
688 static struct subchannel console_subchannel;
689 static char console_sch_name[10] = "0.x.xxxx";
690 static struct io_subchannel_private console_priv;
691 static int console_subchannel_in_use;
694 * Use tpi to get a pending interrupt, call the interrupt handler and
695 * return a pointer to the subchannel structure.
697 static int cio_tpi(void)
699 struct tpi_info *tpi_info;
700 struct subchannel *sch;
704 tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID;
707 irb = (struct irb *) __LC_IRB;
708 /* Store interrupt response block to lowcore. */
709 if (tsch(tpi_info->schid, irb) != 0)
710 /* Not status pending or not operational. */
712 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
715 irq_context = in_interrupt();
719 spin_lock(sch->lock);
720 memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
721 if (sch->driver && sch->driver->irq)
722 sch->driver->irq(sch);
723 spin_unlock(sch->lock);
730 void *cio_get_console_priv(void)
732 return &console_priv;
736 * busy wait for the next interrupt on the console
738 void wait_cons_dev(void)
739 __releases(console_subchannel.lock)
740 __acquires(console_subchannel.lock)
742 unsigned long cr6 __attribute__ ((aligned (8)));
743 unsigned long save_cr6 __attribute__ ((aligned (8)));
746 * before entering the spinlock we may already have
747 * processed the interrupt on a different CPU...
749 if (!console_subchannel_in_use)
752 /* disable all but the console isc */
753 __ctl_store (save_cr6, 6, 6);
754 cr6 = 1UL << (31 - CONSOLE_ISC);
755 __ctl_load (cr6, 6, 6);
758 spin_unlock(console_subchannel.lock);
761 spin_lock(console_subchannel.lock);
762 } while (console_subchannel.schib.scsw.cmd.actl != 0);
764 * restore previous isc value
766 __ctl_load (save_cr6, 6, 6);
770 cio_test_for_console(struct subchannel_id schid, void *data)
772 if (stsch_err(schid, &console_subchannel.schib) != 0)
774 if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) &&
775 console_subchannel.schib.pmcw.dnv &&
776 (console_subchannel.schib.pmcw.dev == console_devno)) {
777 console_irq = schid.sch_no;
778 return 1; /* found */
785 cio_get_console_sch_no(void)
787 struct subchannel_id schid;
789 init_subchannel_id(&schid);
790 if (console_irq != -1) {
791 /* VM provided us with the irq number of the console. */
792 schid.sch_no = console_irq;
793 if (stsch(schid, &console_subchannel.schib) != 0 ||
794 (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) ||
795 !console_subchannel.schib.pmcw.dnv)
797 console_devno = console_subchannel.schib.pmcw.dev;
798 } else if (console_devno != -1) {
799 /* At least the console device number is known. */
800 for_each_subchannel(cio_test_for_console, NULL);
801 if (console_irq == -1)
804 /* unlike in 2.4, we cannot autoprobe here, since
805 * the channel subsystem is not fully initialized.
806 * With some luck, the HWC console can take over */
813 cio_probe_console(void)
816 struct subchannel_id schid;
818 if (xchg(&console_subchannel_in_use, 1) != 0)
819 return ERR_PTR(-EBUSY);
820 sch_no = cio_get_console_sch_no();
822 console_subchannel_in_use = 0;
823 pr_warning("No CCW console was found\n");
824 return ERR_PTR(-ENODEV);
826 memset(&console_subchannel, 0, sizeof(struct subchannel));
827 init_subchannel_id(&schid);
828 schid.sch_no = sch_no;
829 ret = cio_validate_subchannel(&console_subchannel, schid);
831 console_subchannel_in_use = 0;
832 return ERR_PTR(-ENODEV);
836 * enable console I/O-interrupt subclass
838 isc_register(CONSOLE_ISC);
839 console_subchannel.config.isc = CONSOLE_ISC;
840 console_subchannel.config.intparm = (u32)(addr_t)&console_subchannel;
841 ret = cio_commit_config(&console_subchannel);
843 isc_unregister(CONSOLE_ISC);
844 console_subchannel_in_use = 0;
847 return &console_subchannel;
851 cio_release_console(void)
853 console_subchannel.config.intparm = 0;
854 cio_commit_config(&console_subchannel);
855 isc_unregister(CONSOLE_ISC);
856 console_subchannel_in_use = 0;
859 /* Bah... hack to catch console special sausages. */
861 cio_is_console(struct subchannel_id schid)
863 if (!console_subchannel_in_use)
865 return schid_equal(&schid, &console_subchannel.schid);
869 cio_get_console_subchannel(void)
871 if (!console_subchannel_in_use)
873 return &console_subchannel;
876 const char *cio_get_console_sch_name(struct subchannel_id schid)
878 snprintf(console_sch_name, 10, "0.%x.%04x", schid.ssid, schid.sch_no);
879 return (const char *)console_sch_name;
884 __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib)
889 for (retry=0;retry<3;retry++) {
891 cc = msch(schid, schib);
893 return (cc==3?-ENODEV:-EBUSY);
894 if (stsch(schid, schib) || !css_sch_is_valid(schib))
896 if (!schib->pmcw.ena)
899 return -EBUSY; /* uhm... */
903 __clear_io_subchannel_easy(struct subchannel_id schid)
909 for (retry=0;retry<20;retry++) {
913 tsch(ti.schid, (struct irb *)__LC_IRB);
914 if (schid_equal(&ti.schid, &schid))
922 static void __clear_chsc_subchannel_easy(void)
924 /* It seems we can only wait for a bit here :/ */
928 static int pgm_check_occured;
930 static void cio_reset_pgm_check_handler(void)
932 pgm_check_occured = 1;
935 static int stsch_reset(struct subchannel_id schid, struct schib *addr)
939 pgm_check_occured = 0;
940 s390_base_pgm_handler_fn = cio_reset_pgm_check_handler;
941 rc = stsch(schid, addr);
942 s390_base_pgm_handler_fn = NULL;
944 /* The program check handler could have changed pgm_check_occured. */
947 if (pgm_check_occured)
953 static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
957 if (stsch_reset(schid, &schib))
961 switch(__disable_subchannel_easy(schid, &schib)) {
965 default: /* -EBUSY */
966 switch (schib.pmcw.st) {
967 case SUBCHANNEL_TYPE_IO:
968 if (__clear_io_subchannel_easy(schid))
969 goto out; /* give up... */
971 case SUBCHANNEL_TYPE_CHSC:
972 __clear_chsc_subchannel_easy();
975 /* No default clear strategy */
978 stsch(schid, &schib);
979 __disable_subchannel_easy(schid, &schib);
985 static atomic_t chpid_reset_count;
987 static void s390_reset_chpids_mcck_handler(void)
992 /* Check for pending channel report word. */
993 mci = (struct mci *)&S390_lowcore.mcck_interruption_code;
996 /* Process channel report words. */
997 while (stcrw(&crw) == 0) {
998 /* Check for responses to RCHP. */
999 if (crw.slct && crw.rsc == CRW_RSC_CPATH)
1000 atomic_dec(&chpid_reset_count);
1004 #define RCHP_TIMEOUT (30 * USEC_PER_SEC)
1005 static void css_reset(void)
1008 unsigned long long timeout;
1009 struct chp_id chpid;
1011 /* Reset subchannels. */
1012 for_each_subchannel(__shutdown_subchannel_easy, NULL);
1013 /* Reset channel paths. */
1014 s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler;
1015 /* Enable channel report machine checks. */
1016 __ctl_set_bit(14, 28);
1017 /* Temporarily reenable machine checks. */
1018 local_mcck_enable();
1019 chp_id_init(&chpid);
1020 for (i = 0; i <= __MAX_CHPID; i++) {
1023 if ((ret == 0) || (ret == 2))
1025 * rchp either succeeded, or another rchp is already
1026 * in progress. In either case, we'll get a crw.
1028 atomic_inc(&chpid_reset_count);
1030 /* Wait for machine check for all channel paths. */
1031 timeout = get_clock() + (RCHP_TIMEOUT << 12);
1032 while (atomic_read(&chpid_reset_count) != 0) {
1033 if (get_clock() > timeout)
1037 /* Disable machine checks again. */
1038 local_mcck_disable();
1039 /* Disable channel report machine checks. */
1040 __ctl_clear_bit(14, 28);
1041 s390_base_mcck_handler_fn = NULL;
1044 static struct reset_call css_reset_call = {
1048 static int __init init_css_reset_call(void)
1050 atomic_set(&chpid_reset_count, 0);
1051 register_reset_call(&css_reset_call);
1055 arch_initcall(init_css_reset_call);
1057 struct sch_match_id {
1058 struct subchannel_id schid;
1059 struct ccw_dev_id devid;
1063 static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
1066 struct sch_match_id *match_id = data;
1068 if (stsch_reset(schid, &schib))
1070 if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
1071 (schib.pmcw.dev == match_id->devid.devno) &&
1072 (schid.ssid == match_id->devid.ssid)) {
1073 match_id->schid = schid;
1080 static int reipl_find_schid(struct ccw_dev_id *devid,
1081 struct subchannel_id *schid)
1083 struct sch_match_id match_id;
1085 match_id.devid = *devid;
1086 match_id.rc = -ENODEV;
1087 for_each_subchannel(__reipl_subchannel_match, &match_id);
1088 if (match_id.rc == 0)
1089 *schid = match_id.schid;
1093 extern void do_reipl_asm(__u32 schid);
1095 /* Make sure all subchannels are quiet before we re-ipl an lpar. */
1096 void reipl_ccw_dev(struct ccw_dev_id *devid)
1098 struct subchannel_id schid;
1100 s390_reset_system();
1101 if (reipl_find_schid(devid, &schid) != 0)
1102 panic("IPL Device not found\n");
1103 do_reipl_asm(*((__u32*)&schid));
1106 int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo)
1108 struct subchannel_id schid;
1111 schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID;
1114 if (stsch(schid, &schib))
1116 if (schib.pmcw.st != SUBCHANNEL_TYPE_IO)
1118 if (!schib.pmcw.dnv)
1120 iplinfo->devno = schib.pmcw.dev;
1121 iplinfo->is_qdio = schib.pmcw.qf;
1126 * cio_tm_start_key - perform start function
1127 * @sch: subchannel on which to perform the start function
1128 * @tcw: transport-command word to be started
1129 * @lpm: mask of paths to use
1130 * @key: storage key to use for storage access
1132 * Start the tcw on the given subchannel. Return zero on success, non-zero
1135 int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
1138 union orb *orb = &to_io_private(sch)->orb;
1140 memset(orb, 0, sizeof(union orb));
1141 orb->tm.intparm = (u32) (addr_t) sch;
1142 orb->tm.key = key >> 4;
1144 orb->tm.lpm = lpm ? lpm : sch->lpm;
1145 orb->tm.tcw = (u32) (addr_t) tcw;
1146 cc = ssch(sch->schid, orb);
1154 return cio_start_handle_notoper(sch, lpm);
1159 * cio_tm_intrg - perform interrogate function
1160 * @sch - subchannel on which to perform the interrogate function
1162 * If the specified subchannel is running in transport-mode, perform the
1163 * interrogate function. Return zero on success, non-zero otherwie.
1165 int cio_tm_intrg(struct subchannel *sch)
1169 if (!to_io_private(sch)->orb.tm.b)
1171 cc = xsch(sch->schid);