Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/cio.c |
| 3 | * S/390 common I/O routines -- low level i/o calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 1999,2008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Author(s): Ingo Adlung (adlung@de.ibm.com) |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 7 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Arnd Bergmann (arndb@de.ibm.com) |
| 9 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/kernel_stat.h> |
| 17 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/cio.h> |
| 19 | #include <asm/delay.h> |
| 20 | #include <asm/irq.h> |
Heiko Carstens | 5a489b98 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 21 | #include <asm/irq_regs.h> |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 22 | #include <asm/setup.h> |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 23 | #include <asm/reset.h> |
Michael Holzheu | 46b05d2 | 2007-02-21 10:55:21 +0100 | [diff] [blame] | 24 | #include <asm/ipl.h> |
Peter Oberparleiter | e5854a5 | 2007-04-27 16:01:31 +0200 | [diff] [blame] | 25 | #include <asm/chpid.h> |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 26 | #include <asm/airq.h> |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 27 | #include <asm/isc.h> |
Heiko Carstens | 43ca5c3 | 2008-04-17 07:46:23 +0200 | [diff] [blame] | 28 | #include <asm/cpu.h> |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 29 | #include <asm/fcx.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "cio.h" |
| 31 | #include "css.h" |
| 32 | #include "chsc.h" |
| 33 | #include "ioasm.h" |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 34 | #include "io_sch.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "blacklist.h" |
| 36 | #include "cio_debug.h" |
Peter Oberparleiter | e6b6e10 | 2007-04-27 16:01:28 +0200 | [diff] [blame] | 37 | #include "chp.h" |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 38 | #include "../s390mach.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | debug_info_t *cio_debug_msg_id; |
| 41 | debug_info_t *cio_debug_trace_id; |
| 42 | debug_info_t *cio_debug_crw_id; |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* |
| 45 | * Function: cio_debug_init |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 46 | * Initializes three debug logs for common I/O: |
| 47 | * - cio_msg logs generic cio messages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | * - cio_trace logs the calling of different functions |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 49 | * - cio_crw logs machine check related cio messages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 51 | static int __init cio_debug_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 53 | cio_debug_msg_id = debug_register("cio_msg", 16, 1, 16 * sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | if (!cio_debug_msg_id) |
| 55 | goto out_unregister; |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 56 | debug_register_view(cio_debug_msg_id, &debug_sprintf_view); |
| 57 | debug_set_level(cio_debug_msg_id, 2); |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 58 | cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | if (!cio_debug_trace_id) |
| 60 | goto out_unregister; |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 61 | debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view); |
| 62 | debug_set_level(cio_debug_trace_id, 2); |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 63 | cio_debug_crw_id = debug_register("cio_crw", 16, 1, 16 * sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | if (!cio_debug_crw_id) |
| 65 | goto out_unregister; |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 66 | debug_register_view(cio_debug_crw_id, &debug_sprintf_view); |
| 67 | debug_set_level(cio_debug_crw_id, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | return 0; |
| 69 | |
| 70 | out_unregister: |
| 71 | if (cio_debug_msg_id) |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 72 | debug_unregister(cio_debug_msg_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | if (cio_debug_trace_id) |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 74 | debug_unregister(cio_debug_trace_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (cio_debug_crw_id) |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 76 | debug_unregister(cio_debug_crw_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return -1; |
| 78 | } |
| 79 | |
| 80 | arch_initcall (cio_debug_init); |
| 81 | |
| 82 | int |
| 83 | cio_set_options (struct subchannel *sch, int flags) |
| 84 | { |
| 85 | sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0; |
| 86 | sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0; |
| 87 | sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0; |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /* FIXME: who wants to use this? */ |
| 92 | int |
| 93 | cio_get_options (struct subchannel *sch) |
| 94 | { |
| 95 | int flags; |
| 96 | |
| 97 | flags = 0; |
| 98 | if (sch->options.suspend) |
| 99 | flags |= DOIO_ALLOW_SUSPEND; |
| 100 | if (sch->options.prefetch) |
| 101 | flags |= DOIO_DENY_PREFETCH; |
| 102 | if (sch->options.inter) |
| 103 | flags |= DOIO_SUPPRESS_INTER; |
| 104 | return flags; |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Use tpi to get a pending interrupt, call the interrupt handler and |
| 109 | * return a pointer to the subchannel structure. |
| 110 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 111 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | cio_tpi(void) |
| 113 | { |
| 114 | struct tpi_info *tpi_info; |
| 115 | struct subchannel *sch; |
| 116 | struct irb *irb; |
Heiko Carstens | b1e7661 | 2008-10-10 21:33:17 +0200 | [diff] [blame] | 117 | int irq_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID; |
| 120 | if (tpi (NULL) != 1) |
| 121 | return 0; |
| 122 | irb = (struct irb *) __LC_IRB; |
| 123 | /* Store interrupt response block to lowcore. */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 124 | if (tsch (tpi_info->schid, irb) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | /* Not status pending or not operational. */ |
| 126 | return 1; |
| 127 | sch = (struct subchannel *)(unsigned long)tpi_info->intparm; |
| 128 | if (!sch) |
| 129 | return 1; |
Heiko Carstens | b1e7661 | 2008-10-10 21:33:17 +0200 | [diff] [blame] | 130 | irq_context = in_interrupt(); |
| 131 | if (!irq_context) |
| 132 | local_bh_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | irq_enter (); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 134 | spin_lock(sch->lock); |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 135 | memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | if (sch->driver && sch->driver->irq) |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 137 | sch->driver->irq(sch); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 138 | spin_unlock(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | irq_exit (); |
Heiko Carstens | b1e7661 | 2008-10-10 21:33:17 +0200 | [diff] [blame] | 140 | if (!irq_context) |
| 141 | _local_bh_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return 1; |
| 143 | } |
| 144 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 145 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | cio_start_handle_notoper(struct subchannel *sch, __u8 lpm) |
| 147 | { |
| 148 | char dbf_text[15]; |
| 149 | |
| 150 | if (lpm != 0) |
| 151 | sch->lpm &= ~lpm; |
| 152 | else |
| 153 | sch->lpm = 0; |
| 154 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 155 | stsch (sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 157 | CIO_MSG_EVENT(2, "cio_start: 'not oper' status for " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 158 | "subchannel 0.%x.%04x!\n", sch->schid.ssid, |
| 159 | sch->schid.sch_no); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 160 | sprintf(dbf_text, "no%s", dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | CIO_TRACE_EVENT(0, dbf_text); |
| 162 | CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib)); |
| 163 | |
| 164 | return (sch->lpm ? -EACCES : -ENODEV); |
| 165 | } |
| 166 | |
| 167 | int |
| 168 | cio_start_key (struct subchannel *sch, /* subchannel structure */ |
| 169 | struct ccw1 * cpa, /* logical channel prog addr */ |
| 170 | __u8 lpm, /* logical path mask */ |
| 171 | __u8 key) /* storage key */ |
| 172 | { |
| 173 | char dbf_txt[15]; |
| 174 | int ccode; |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 175 | union orb *orb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 177 | CIO_TRACE_EVENT(4, "stIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 178 | CIO_TRACE_EVENT(4, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 180 | orb = &to_io_private(sch)->orb; |
Stefan Weinhuber | 9adb8c1 | 2008-09-16 09:32:19 -0700 | [diff] [blame] | 181 | memset(orb, 0, sizeof(union orb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | /* sch is always under 2G. */ |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 183 | orb->cmd.intparm = (u32)(addr_t)sch; |
| 184 | orb->cmd.fmt = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 186 | orb->cmd.pfch = sch->options.prefetch == 0; |
| 187 | orb->cmd.spnd = sch->options.suspend; |
| 188 | orb->cmd.ssic = sch->options.suspend && sch->options.inter; |
| 189 | orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 190 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | /* |
| 192 | * for 64 bit we always support 64 bit IDAWs with 4k page size only |
| 193 | */ |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 194 | orb->cmd.c64 = 1; |
| 195 | orb->cmd.i2k = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | #endif |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 197 | orb->cmd.key = key >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /* issue "Start Subchannel" */ |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 199 | orb->cmd.cpa = (__u32) __pa(cpa); |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 200 | ccode = ssch(sch->schid, orb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | /* process condition code */ |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 203 | sprintf(dbf_txt, "ccode:%d", ccode); |
| 204 | CIO_TRACE_EVENT(4, dbf_txt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | switch (ccode) { |
| 207 | case 0: |
| 208 | /* |
| 209 | * initialize device status information |
| 210 | */ |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 211 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | return 0; |
| 213 | case 1: /* status pending */ |
| 214 | case 2: /* busy */ |
| 215 | return -EBUSY; |
Cornelia Huck | c91ebe4 | 2008-09-09 12:38:58 +0200 | [diff] [blame] | 216 | case 3: /* device/path not operational */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return cio_start_handle_notoper(sch, lpm); |
Cornelia Huck | c91ebe4 | 2008-09-09 12:38:58 +0200 | [diff] [blame] | 218 | default: |
| 219 | return ccode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | int |
| 224 | cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm) |
| 225 | { |
Peter Oberparleiter | 0b642ed | 2005-05-01 08:58:58 -0700 | [diff] [blame] | 226 | return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* |
| 230 | * resume suspended I/O operation |
| 231 | */ |
| 232 | int |
| 233 | cio_resume (struct subchannel *sch) |
| 234 | { |
| 235 | char dbf_txt[15]; |
| 236 | int ccode; |
| 237 | |
| 238 | CIO_TRACE_EVENT (4, "resIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 239 | CIO_TRACE_EVENT(4, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 241 | ccode = rsch (sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | sprintf (dbf_txt, "ccode:%d", ccode); |
| 244 | CIO_TRACE_EVENT (4, dbf_txt); |
| 245 | |
| 246 | switch (ccode) { |
| 247 | case 0: |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 248 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return 0; |
| 250 | case 1: |
| 251 | return -EBUSY; |
| 252 | case 2: |
| 253 | return -EINVAL; |
| 254 | default: |
| 255 | /* |
| 256 | * useless to wait for request completion |
| 257 | * as device is no longer operational ! |
| 258 | */ |
| 259 | return -ENODEV; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | /* |
| 264 | * halt I/O operation |
| 265 | */ |
| 266 | int |
| 267 | cio_halt(struct subchannel *sch) |
| 268 | { |
| 269 | char dbf_txt[15]; |
| 270 | int ccode; |
| 271 | |
| 272 | if (!sch) |
| 273 | return -ENODEV; |
| 274 | |
| 275 | CIO_TRACE_EVENT (2, "haltIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 276 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* |
| 279 | * Issue "Halt subchannel" and process condition code |
| 280 | */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 281 | ccode = hsch (sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | sprintf (dbf_txt, "ccode:%d", ccode); |
| 284 | CIO_TRACE_EVENT (2, dbf_txt); |
| 285 | |
| 286 | switch (ccode) { |
| 287 | case 0: |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 288 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | return 0; |
| 290 | case 1: /* status pending */ |
| 291 | case 2: /* busy */ |
| 292 | return -EBUSY; |
| 293 | default: /* device not operational */ |
| 294 | return -ENODEV; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * Clear I/O operation |
| 300 | */ |
| 301 | int |
| 302 | cio_clear(struct subchannel *sch) |
| 303 | { |
| 304 | char dbf_txt[15]; |
| 305 | int ccode; |
| 306 | |
| 307 | if (!sch) |
| 308 | return -ENODEV; |
| 309 | |
| 310 | CIO_TRACE_EVENT (2, "clearIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 311 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | /* |
| 314 | * Issue "Clear subchannel" and process condition code |
| 315 | */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 316 | ccode = csch (sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | sprintf (dbf_txt, "ccode:%d", ccode); |
| 319 | CIO_TRACE_EVENT (2, dbf_txt); |
| 320 | |
| 321 | switch (ccode) { |
| 322 | case 0: |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 323 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return 0; |
| 325 | default: /* device not operational */ |
| 326 | return -ENODEV; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | * Function: cio_cancel |
| 332 | * Issues a "Cancel Subchannel" on the specified subchannel |
| 333 | * Note: We don't need any fancy intparms and flags here |
| 334 | * since xsch is executed synchronously. |
| 335 | * Only for common I/O internal use as for now. |
| 336 | */ |
| 337 | int |
| 338 | cio_cancel (struct subchannel *sch) |
| 339 | { |
| 340 | char dbf_txt[15]; |
| 341 | int ccode; |
| 342 | |
| 343 | if (!sch) |
| 344 | return -ENODEV; |
| 345 | |
| 346 | CIO_TRACE_EVENT (2, "cancelIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 347 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 349 | ccode = xsch (sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | sprintf (dbf_txt, "ccode:%d", ccode); |
| 352 | CIO_TRACE_EVENT (2, dbf_txt); |
| 353 | |
| 354 | switch (ccode) { |
| 355 | case 0: /* success */ |
| 356 | /* Update information in scsw. */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 357 | stsch (sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return 0; |
| 359 | case 1: /* status pending */ |
| 360 | return -EBUSY; |
| 361 | case 2: /* not applicable */ |
| 362 | return -EINVAL; |
| 363 | default: /* not oper */ |
| 364 | return -ENODEV; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Function: cio_modify |
| 370 | * Issues a "Modify Subchannel" on the specified subchannel |
| 371 | */ |
| 372 | int |
| 373 | cio_modify (struct subchannel *sch) |
| 374 | { |
| 375 | int ccode, retry, ret; |
| 376 | |
| 377 | ret = 0; |
| 378 | for (retry = 0; retry < 5; retry++) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 379 | ccode = msch_err (sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | if (ccode < 0) /* -EIO if msch gets a program check. */ |
| 381 | return ccode; |
| 382 | switch (ccode) { |
| 383 | case 0: /* successfull */ |
| 384 | return 0; |
| 385 | case 1: /* status pending */ |
| 386 | return -EBUSY; |
| 387 | case 2: /* busy */ |
| 388 | udelay (100); /* allow for recovery */ |
| 389 | ret = -EBUSY; |
| 390 | break; |
| 391 | case 3: /* not operational */ |
| 392 | return -ENODEV; |
| 393 | } |
| 394 | } |
| 395 | return ret; |
| 396 | } |
| 397 | |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 398 | /** |
| 399 | * cio_enable_subchannel - enable a subchannel. |
| 400 | * @sch: subchannel to be enabled |
| 401 | * @intparm: interruption parameter to set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | */ |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 403 | int cio_enable_subchannel(struct subchannel *sch, u32 intparm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { |
| 405 | char dbf_txt[15]; |
| 406 | int ccode; |
| 407 | int retry; |
| 408 | int ret; |
| 409 | |
| 410 | CIO_TRACE_EVENT (2, "ensch"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 411 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 413 | if (sch_is_pseudo_sch(sch)) |
| 414 | return -EINVAL; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 415 | ccode = stsch (sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | if (ccode) |
| 417 | return -ENODEV; |
| 418 | |
| 419 | for (retry = 5, ret = 0; retry > 0; retry--) { |
| 420 | sch->schib.pmcw.ena = 1; |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 421 | sch->schib.pmcw.isc = sch->isc; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 422 | sch->schib.pmcw.intparm = intparm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | ret = cio_modify(sch); |
| 424 | if (ret == -ENODEV) |
| 425 | break; |
| 426 | if (ret == -EIO) |
| 427 | /* |
| 428 | * Got a program check in cio_modify. Try without |
| 429 | * the concurrent sense bit the next time. |
| 430 | */ |
| 431 | sch->schib.pmcw.csense = 0; |
| 432 | if (ret == 0) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 433 | stsch (sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (sch->schib.pmcw.ena) |
| 435 | break; |
| 436 | } |
| 437 | if (ret == -EBUSY) { |
| 438 | struct irb irb; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 439 | if (tsch(sch->schid, &irb) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | break; |
| 441 | } |
| 442 | } |
| 443 | sprintf (dbf_txt, "ret:%d", ret); |
| 444 | CIO_TRACE_EVENT (2, dbf_txt); |
| 445 | return ret; |
| 446 | } |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 447 | EXPORT_SYMBOL_GPL(cio_enable_subchannel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 449 | /** |
| 450 | * cio_disable_subchannel - disable a subchannel. |
| 451 | * @sch: subchannel to disable |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | */ |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 453 | int cio_disable_subchannel(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
| 455 | char dbf_txt[15]; |
| 456 | int ccode; |
| 457 | int retry; |
| 458 | int ret; |
| 459 | |
| 460 | CIO_TRACE_EVENT (2, "dissch"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 461 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 463 | if (sch_is_pseudo_sch(sch)) |
| 464 | return 0; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 465 | ccode = stsch (sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | if (ccode == 3) /* Not operational. */ |
| 467 | return -ENODEV; |
| 468 | |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 469 | if (scsw_actl(&sch->schib.scsw) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | /* |
| 471 | * the disable function must not be called while there are |
| 472 | * requests pending for completion ! |
| 473 | */ |
| 474 | return -EBUSY; |
| 475 | |
| 476 | for (retry = 5, ret = 0; retry > 0; retry--) { |
| 477 | sch->schib.pmcw.ena = 0; |
| 478 | ret = cio_modify(sch); |
| 479 | if (ret == -ENODEV) |
| 480 | break; |
| 481 | if (ret == -EBUSY) |
| 482 | /* |
| 483 | * The subchannel is busy or status pending. |
| 484 | * We'll disable when the next interrupt was delivered |
| 485 | * via the state machine. |
| 486 | */ |
| 487 | break; |
| 488 | if (ret == 0) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 489 | stsch (sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if (!sch->schib.pmcw.ena) |
| 491 | break; |
| 492 | } |
| 493 | } |
| 494 | sprintf (dbf_txt, "ret:%d", ret); |
| 495 | CIO_TRACE_EVENT (2, dbf_txt); |
| 496 | return ret; |
| 497 | } |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 498 | EXPORT_SYMBOL_GPL(cio_disable_subchannel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 500 | int cio_create_sch_lock(struct subchannel *sch) |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 501 | { |
| 502 | sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL); |
| 503 | if (!sch->lock) |
| 504 | return -ENOMEM; |
| 505 | spin_lock_init(sch->lock); |
| 506 | return 0; |
| 507 | } |
| 508 | |
Cornelia Huck | b3a686f | 2008-07-14 09:58:48 +0200 | [diff] [blame] | 509 | static int cio_check_devno_blacklisted(struct subchannel *sch) |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 510 | { |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 511 | if (is_blacklisted(sch->schid.ssid, sch->schib.pmcw.dev)) { |
| 512 | /* |
| 513 | * This device must not be known to Linux. So we simply |
| 514 | * say that there is no device and return ENODEV. |
| 515 | */ |
| 516 | CIO_MSG_EVENT(6, "Blacklisted device detected " |
| 517 | "at devno %04X, subchannel set %x\n", |
| 518 | sch->schib.pmcw.dev, sch->schid.ssid); |
| 519 | return -ENODEV; |
| 520 | } |
| 521 | return 0; |
| 522 | } |
| 523 | |
Cornelia Huck | b3a686f | 2008-07-14 09:58:48 +0200 | [diff] [blame] | 524 | static int cio_validate_io_subchannel(struct subchannel *sch) |
| 525 | { |
| 526 | /* Initialization for io subchannels. */ |
| 527 | if (!css_sch_is_valid(&sch->schib)) |
| 528 | return -ENODEV; |
| 529 | |
| 530 | /* Devno is valid. */ |
| 531 | return cio_check_devno_blacklisted(sch); |
| 532 | } |
| 533 | |
| 534 | static int cio_validate_msg_subchannel(struct subchannel *sch) |
| 535 | { |
| 536 | /* Initialization for message subchannels. */ |
| 537 | if (!css_sch_is_valid(&sch->schib)) |
| 538 | return -ENODEV; |
| 539 | |
| 540 | /* Devno is valid. */ |
| 541 | return cio_check_devno_blacklisted(sch); |
| 542 | } |
| 543 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 544 | /** |
| 545 | * cio_validate_subchannel - basic validation of subchannel |
| 546 | * @sch: subchannel structure to be filled out |
| 547 | * @schid: subchannel id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | * |
| 549 | * Find out subchannel type and initialize struct subchannel. |
| 550 | * Return codes: |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 551 | * 0 on success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | * -ENXIO for non-defined subchannels |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 553 | * -ENODEV for invalid subchannels or blacklisted devices |
| 554 | * -EIO for subchannels in an invalid subchannel set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | */ |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 556 | int cio_validate_subchannel(struct subchannel *sch, struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
| 558 | char dbf_txt[15]; |
| 559 | int ccode; |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 560 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 562 | sprintf(dbf_txt, "valsch%x", schid.sch_no); |
| 563 | CIO_TRACE_EVENT(4, dbf_txt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
| 565 | /* Nuke all fields. */ |
| 566 | memset(sch, 0, sizeof(struct subchannel)); |
| 567 | |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 568 | sch->schid = schid; |
| 569 | if (cio_is_console(schid)) { |
| 570 | sch->lock = cio_get_console_lock(); |
| 571 | } else { |
| 572 | err = cio_create_sch_lock(sch); |
| 573 | if (err) |
| 574 | goto out; |
| 575 | } |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 576 | mutex_init(&sch->reg_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | /* Set a name for the subchannel */ |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 578 | if (cio_is_console(schid)) |
| 579 | sch->dev.init_name = cio_get_console_sch_name(schid); |
| 580 | else |
| 581 | dev_set_name(&sch->dev, "0.%x.%04x", schid.ssid, schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | /* |
| 584 | * The first subchannel that is not-operational (ccode==3) |
| 585 | * indicates that there aren't any more devices available. |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 586 | * If stsch gets an exception, it means the current subchannel set |
| 587 | * is not valid. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 589 | ccode = stsch_err (schid, &sch->schib); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 590 | if (ccode) { |
| 591 | err = (ccode == 3) ? -ENXIO : ccode; |
| 592 | goto out; |
| 593 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | /* Copy subchannel type from path management control word. */ |
| 595 | sch->st = sch->schib.pmcw.st; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 596 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 597 | switch (sch->st) { |
| 598 | case SUBCHANNEL_TYPE_IO: |
| 599 | err = cio_validate_io_subchannel(sch); |
| 600 | break; |
Cornelia Huck | b3a686f | 2008-07-14 09:58:48 +0200 | [diff] [blame] | 601 | case SUBCHANNEL_TYPE_MSG: |
| 602 | err = cio_validate_msg_subchannel(sch); |
| 603 | break; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 604 | default: |
| 605 | err = 0; |
| 606 | } |
| 607 | if (err) |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 608 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 610 | CIO_MSG_EVENT(4, "Subchannel 0.%x.%04x reports subchannel type %04X\n", |
| 611 | sch->schid.ssid, sch->schid.sch_no, sch->st); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | return 0; |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 613 | out: |
| 614 | if (!cio_is_console(schid)) |
| 615 | kfree(sch->lock); |
| 616 | sch->lock = NULL; |
| 617 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | /* |
| 621 | * do_IRQ() handles all normal I/O device IRQ's (the special |
| 622 | * SMP cross-CPU interrupts have their own specific |
| 623 | * handlers). |
| 624 | * |
| 625 | */ |
| 626 | void |
| 627 | do_IRQ (struct pt_regs *regs) |
| 628 | { |
| 629 | struct tpi_info *tpi_info; |
| 630 | struct subchannel *sch; |
| 631 | struct irb *irb; |
Heiko Carstens | 5a489b98 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 632 | struct pt_regs *old_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Heiko Carstens | 5a489b98 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 634 | old_regs = set_irq_regs(regs); |
Heiko Carstens | 9d0a57c | 2006-10-11 15:31:26 +0200 | [diff] [blame] | 635 | irq_enter(); |
Heiko Carstens | 43ca5c3 | 2008-04-17 07:46:23 +0200 | [diff] [blame] | 636 | s390_idle_check(); |
Heiko Carstens | 5a62b19 | 2008-04-17 07:46:25 +0200 | [diff] [blame] | 637 | if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator) |
| 638 | /* Serve timer interrupts first. */ |
| 639 | clock_comparator_work(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | /* |
| 641 | * Get interrupt information from lowcore |
| 642 | */ |
| 643 | tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID; |
| 644 | irb = (struct irb *) __LC_IRB; |
| 645 | do { |
| 646 | kstat_cpu(smp_processor_id()).irqs[IO_INTERRUPT]++; |
| 647 | /* |
| 648 | * Non I/O-subchannel thin interrupts are processed differently |
| 649 | */ |
| 650 | if (tpi_info->adapter_IO == 1 && |
| 651 | tpi_info->int_type == IO_INTERRUPT_TYPE) { |
Cornelia Huck | da7c5af | 2008-07-14 09:58:59 +0200 | [diff] [blame] | 652 | do_adapter_IO(tpi_info->isc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | continue; |
| 654 | } |
| 655 | sch = (struct subchannel *)(unsigned long)tpi_info->intparm; |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 656 | if (!sch) { |
| 657 | /* Clear pending interrupt condition. */ |
| 658 | tsch(tpi_info->schid, irb); |
| 659 | continue; |
| 660 | } |
| 661 | spin_lock(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | /* Store interrupt response block to lowcore. */ |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 663 | if (tsch(tpi_info->schid, irb) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | /* Keep subchannel information word up to date. */ |
| 665 | memcpy (&sch->schib.scsw, &irb->scsw, |
| 666 | sizeof (irb->scsw)); |
| 667 | /* Call interrupt handler if there is one. */ |
| 668 | if (sch->driver && sch->driver->irq) |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 669 | sch->driver->irq(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 671 | spin_unlock(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | /* |
| 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. |
| 678 | */ |
| 679 | } while (!MACHINE_IS_VM && tpi (NULL) != 0); |
Heiko Carstens | 9d0a57c | 2006-10-11 15:31:26 +0200 | [diff] [blame] | 680 | irq_exit(); |
Heiko Carstens | 5a489b98 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 681 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | #ifdef CONFIG_CCW_CONSOLE |
| 685 | static struct subchannel console_subchannel; |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 686 | static char console_sch_name[10] = "0.x.xxxx"; |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 687 | static struct io_subchannel_private console_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | static int console_subchannel_in_use; |
| 689 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 690 | void *cio_get_console_priv(void) |
| 691 | { |
| 692 | return &console_priv; |
| 693 | } |
| 694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | /* |
| 696 | * busy wait for the next interrupt on the console |
| 697 | */ |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 698 | void wait_cons_dev(void) |
| 699 | __releases(console_subchannel.lock) |
| 700 | __acquires(console_subchannel.lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | { |
| 702 | unsigned long cr6 __attribute__ ((aligned (8))); |
| 703 | unsigned long save_cr6 __attribute__ ((aligned (8))); |
| 704 | |
| 705 | /* |
| 706 | * before entering the spinlock we may already have |
| 707 | * processed the interrupt on a different CPU... |
| 708 | */ |
| 709 | if (!console_subchannel_in_use) |
| 710 | return; |
| 711 | |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 712 | /* disable all but the console isc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | __ctl_store (save_cr6, 6, 6); |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 714 | cr6 = 1UL << (31 - CONSOLE_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | __ctl_load (cr6, 6, 6); |
| 716 | |
| 717 | do { |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 718 | spin_unlock(console_subchannel.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | if (!cio_tpi()) |
| 720 | cpu_relax(); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 721 | spin_lock(console_subchannel.lock); |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 722 | } while (console_subchannel.schib.scsw.cmd.actl != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | /* |
| 724 | * restore previous isc value |
| 725 | */ |
| 726 | __ctl_load (save_cr6, 6, 6); |
| 727 | } |
| 728 | |
| 729 | static int |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 730 | cio_test_for_console(struct subchannel_id schid, void *data) |
| 731 | { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 732 | if (stsch_err(schid, &console_subchannel.schib) != 0) |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 733 | return -ENXIO; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 734 | if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) && |
| 735 | console_subchannel.schib.pmcw.dnv && |
| 736 | (console_subchannel.schib.pmcw.dev == console_devno)) { |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 737 | console_irq = schid.sch_no; |
| 738 | return 1; /* found */ |
| 739 | } |
| 740 | return 0; |
| 741 | } |
| 742 | |
| 743 | |
| 744 | static int |
| 745 | cio_get_console_sch_no(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 747 | struct subchannel_id schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 749 | init_subchannel_id(&schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | if (console_irq != -1) { |
| 751 | /* VM provided us with the irq number of the console. */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 752 | schid.sch_no = console_irq; |
| 753 | if (stsch(schid, &console_subchannel.schib) != 0 || |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 754 | (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | !console_subchannel.schib.pmcw.dnv) |
| 756 | return -1; |
| 757 | console_devno = console_subchannel.schib.pmcw.dev; |
| 758 | } else if (console_devno != -1) { |
| 759 | /* At least the console device number is known. */ |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 760 | for_each_subchannel(cio_test_for_console, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | if (console_irq == -1) |
| 762 | return -1; |
| 763 | } else { |
| 764 | /* unlike in 2.4, we cannot autoprobe here, since |
| 765 | * the channel subsystem is not fully initialized. |
| 766 | * With some luck, the HWC console can take over */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | return -1; |
| 768 | } |
| 769 | return console_irq; |
| 770 | } |
| 771 | |
| 772 | struct subchannel * |
| 773 | cio_probe_console(void) |
| 774 | { |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 775 | int sch_no, ret; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 776 | struct subchannel_id schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | if (xchg(&console_subchannel_in_use, 1) != 0) |
| 779 | return ERR_PTR(-EBUSY); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 780 | sch_no = cio_get_console_sch_no(); |
| 781 | if (sch_no == -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | console_subchannel_in_use = 0; |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 783 | printk(KERN_WARNING "cio: No ccw console found!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | return ERR_PTR(-ENODEV); |
| 785 | } |
| 786 | memset(&console_subchannel, 0, sizeof(struct subchannel)); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 787 | init_subchannel_id(&schid); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 788 | schid.sch_no = sch_no; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 789 | ret = cio_validate_subchannel(&console_subchannel, schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | if (ret) { |
| 791 | console_subchannel_in_use = 0; |
| 792 | return ERR_PTR(-ENODEV); |
| 793 | } |
| 794 | |
| 795 | /* |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 796 | * enable console I/O-interrupt subclass |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | */ |
Cornelia Huck | 6ef556c | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 798 | isc_register(CONSOLE_ISC); |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 799 | console_subchannel.schib.pmcw.isc = CONSOLE_ISC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | console_subchannel.schib.pmcw.intparm = |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 801 | (u32)(addr_t)&console_subchannel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | ret = cio_modify(&console_subchannel); |
| 803 | if (ret) { |
Cornelia Huck | 6ef556c | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 804 | isc_unregister(CONSOLE_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | console_subchannel_in_use = 0; |
| 806 | return ERR_PTR(ret); |
| 807 | } |
| 808 | return &console_subchannel; |
| 809 | } |
| 810 | |
| 811 | void |
| 812 | cio_release_console(void) |
| 813 | { |
| 814 | console_subchannel.schib.pmcw.intparm = 0; |
| 815 | cio_modify(&console_subchannel); |
Cornelia Huck | 6ef556c | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 816 | isc_unregister(CONSOLE_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | console_subchannel_in_use = 0; |
| 818 | } |
| 819 | |
| 820 | /* Bah... hack to catch console special sausages. */ |
| 821 | int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 822 | cio_is_console(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
| 824 | if (!console_subchannel_in_use) |
| 825 | return 0; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 826 | return schid_equal(&schid, &console_subchannel.schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | struct subchannel * |
| 830 | cio_get_console_subchannel(void) |
| 831 | { |
| 832 | if (!console_subchannel_in_use) |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 833 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | return &console_subchannel; |
| 835 | } |
| 836 | |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 837 | const char *cio_get_console_sch_name(struct subchannel_id schid) |
| 838 | { |
| 839 | snprintf(console_sch_name, 10, "0.%x.%04x", schid.ssid, schid.sch_no); |
| 840 | return (const char *)console_sch_name; |
| 841 | } |
| 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | #endif |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 844 | static int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 845 | __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | { |
| 847 | int retry, cc; |
| 848 | |
| 849 | cc = 0; |
| 850 | for (retry=0;retry<3;retry++) { |
| 851 | schib->pmcw.ena = 0; |
| 852 | cc = msch(schid, schib); |
| 853 | if (cc) |
| 854 | return (cc==3?-ENODEV:-EBUSY); |
| 855 | stsch(schid, schib); |
| 856 | if (!schib->pmcw.ena) |
| 857 | return 0; |
| 858 | } |
| 859 | return -EBUSY; /* uhm... */ |
| 860 | } |
| 861 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 862 | static int |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 863 | __clear_io_subchannel_easy(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
| 865 | int retry; |
| 866 | |
| 867 | if (csch(schid)) |
| 868 | return -ENODEV; |
| 869 | for (retry=0;retry<20;retry++) { |
| 870 | struct tpi_info ti; |
| 871 | |
| 872 | if (tpi(&ti)) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 873 | tsch(ti.schid, (struct irb *)__LC_IRB); |
| 874 | if (schid_equal(&ti.schid, &schid)) |
Cornelia Huck | 4c24da7 | 2005-09-03 15:58:01 -0700 | [diff] [blame] | 875 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
Heiko Carstens | 5a0d0e6 | 2008-10-10 21:33:22 +0200 | [diff] [blame^] | 877 | udelay_simple(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | return -EBUSY; |
| 880 | } |
| 881 | |
Cornelia Huck | 9d92a7e | 2008-07-14 09:59:05 +0200 | [diff] [blame] | 882 | static void __clear_chsc_subchannel_easy(void) |
| 883 | { |
| 884 | /* It seems we can only wait for a bit here :/ */ |
Heiko Carstens | 5a0d0e6 | 2008-10-10 21:33:22 +0200 | [diff] [blame^] | 885 | udelay_simple(100); |
Cornelia Huck | 9d92a7e | 2008-07-14 09:59:05 +0200 | [diff] [blame] | 886 | } |
| 887 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 888 | static int pgm_check_occured; |
| 889 | |
| 890 | static void cio_reset_pgm_check_handler(void) |
| 891 | { |
| 892 | pgm_check_occured = 1; |
| 893 | } |
| 894 | |
Peter Oberparleiter | f9c9fe3 | 2008-10-10 21:33:15 +0200 | [diff] [blame] | 895 | static int stsch_reset(struct subchannel_id schid, struct schib *addr) |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 896 | { |
| 897 | int rc; |
| 898 | |
| 899 | pgm_check_occured = 0; |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 900 | s390_base_pgm_handler_fn = cio_reset_pgm_check_handler; |
Heiko Carstens | 6faf444 | 2007-01-09 10:18:41 +0100 | [diff] [blame] | 901 | rc = stsch(schid, addr); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 902 | s390_base_pgm_handler_fn = NULL; |
Heiko Carstens | 6faf444 | 2007-01-09 10:18:41 +0100 | [diff] [blame] | 903 | |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 904 | /* The program check handler could have changed pgm_check_occured. */ |
Heiko Carstens | 6faf444 | 2007-01-09 10:18:41 +0100 | [diff] [blame] | 905 | barrier(); |
| 906 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 907 | if (pgm_check_occured) |
| 908 | return -EIO; |
| 909 | else |
| 910 | return rc; |
| 911 | } |
| 912 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 913 | static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data) |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 914 | { |
| 915 | struct schib schib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 917 | if (stsch_reset(schid, &schib)) |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 918 | return -ENXIO; |
| 919 | if (!schib.pmcw.ena) |
| 920 | return 0; |
| 921 | switch(__disable_subchannel_easy(schid, &schib)) { |
| 922 | case 0: |
| 923 | case -ENODEV: |
| 924 | break; |
| 925 | default: /* -EBUSY */ |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 926 | switch (schib.pmcw.st) { |
| 927 | case SUBCHANNEL_TYPE_IO: |
| 928 | if (__clear_io_subchannel_easy(schid)) |
| 929 | goto out; /* give up... */ |
| 930 | break; |
Cornelia Huck | 9d92a7e | 2008-07-14 09:59:05 +0200 | [diff] [blame] | 931 | case SUBCHANNEL_TYPE_CHSC: |
| 932 | __clear_chsc_subchannel_easy(); |
| 933 | break; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 934 | default: |
| 935 | /* No default clear strategy */ |
| 936 | break; |
| 937 | } |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 938 | stsch(schid, &schib); |
| 939 | __disable_subchannel_easy(schid, &schib); |
| 940 | } |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 941 | out: |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 942 | return 0; |
| 943 | } |
| 944 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 945 | static atomic_t chpid_reset_count; |
| 946 | |
| 947 | static void s390_reset_chpids_mcck_handler(void) |
| 948 | { |
| 949 | struct crw crw; |
| 950 | struct mci *mci; |
| 951 | |
| 952 | /* Check for pending channel report word. */ |
| 953 | mci = (struct mci *)&S390_lowcore.mcck_interruption_code; |
| 954 | if (!mci->cp) |
| 955 | return; |
| 956 | /* Process channel report words. */ |
| 957 | while (stcrw(&crw) == 0) { |
| 958 | /* Check for responses to RCHP. */ |
| 959 | if (crw.slct && crw.rsc == CRW_RSC_CPATH) |
| 960 | atomic_dec(&chpid_reset_count); |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | #define RCHP_TIMEOUT (30 * USEC_PER_SEC) |
| 965 | static void css_reset(void) |
| 966 | { |
| 967 | int i, ret; |
| 968 | unsigned long long timeout; |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 969 | struct chp_id chpid; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 970 | |
| 971 | /* Reset subchannels. */ |
| 972 | for_each_subchannel(__shutdown_subchannel_easy, NULL); |
| 973 | /* Reset channel paths. */ |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 974 | s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 975 | /* Enable channel report machine checks. */ |
| 976 | __ctl_set_bit(14, 28); |
| 977 | /* Temporarily reenable machine checks. */ |
| 978 | local_mcck_enable(); |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 979 | chp_id_init(&chpid); |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 980 | for (i = 0; i <= __MAX_CHPID; i++) { |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 981 | chpid.id = i; |
| 982 | ret = rchp(chpid); |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 983 | if ((ret == 0) || (ret == 2)) |
| 984 | /* |
| 985 | * rchp either succeeded, or another rchp is already |
| 986 | * in progress. In either case, we'll get a crw. |
| 987 | */ |
| 988 | atomic_inc(&chpid_reset_count); |
| 989 | } |
| 990 | /* Wait for machine check for all channel paths. */ |
| 991 | timeout = get_clock() + (RCHP_TIMEOUT << 12); |
| 992 | while (atomic_read(&chpid_reset_count) != 0) { |
| 993 | if (get_clock() > timeout) |
| 994 | break; |
| 995 | cpu_relax(); |
| 996 | } |
| 997 | /* Disable machine checks again. */ |
| 998 | local_mcck_disable(); |
| 999 | /* Disable channel report machine checks. */ |
| 1000 | __ctl_clear_bit(14, 28); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 1001 | s390_base_mcck_handler_fn = NULL; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | static struct reset_call css_reset_call = { |
| 1005 | .fn = css_reset, |
| 1006 | }; |
| 1007 | |
| 1008 | static int __init init_css_reset_call(void) |
| 1009 | { |
| 1010 | atomic_set(&chpid_reset_count, 0); |
| 1011 | register_reset_call(&css_reset_call); |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | arch_initcall(init_css_reset_call); |
| 1016 | |
| 1017 | struct sch_match_id { |
| 1018 | struct subchannel_id schid; |
| 1019 | struct ccw_dev_id devid; |
| 1020 | int rc; |
| 1021 | }; |
| 1022 | |
| 1023 | static int __reipl_subchannel_match(struct subchannel_id schid, void *data) |
| 1024 | { |
| 1025 | struct schib schib; |
| 1026 | struct sch_match_id *match_id = data; |
| 1027 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 1028 | if (stsch_reset(schid, &schib)) |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1029 | return -ENXIO; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 1030 | if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv && |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1031 | (schib.pmcw.dev == match_id->devid.devno) && |
| 1032 | (schid.ssid == match_id->devid.ssid)) { |
| 1033 | match_id->schid = schid; |
| 1034 | match_id->rc = 0; |
| 1035 | return 1; |
| 1036 | } |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | static int reipl_find_schid(struct ccw_dev_id *devid, |
| 1041 | struct subchannel_id *schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1043 | struct sch_match_id match_id; |
| 1044 | |
| 1045 | match_id.devid = *devid; |
| 1046 | match_id.rc = -ENODEV; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1047 | for_each_subchannel(__reipl_subchannel_match, &match_id); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1048 | if (match_id.rc == 0) |
| 1049 | *schid = match_id.schid; |
| 1050 | return match_id.rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1053 | extern void do_reipl_asm(__u32 schid); |
| 1054 | |
| 1055 | /* Make sure all subchannels are quiet before we re-ipl an lpar. */ |
| 1056 | void reipl_ccw_dev(struct ccw_dev_id *devid) |
| 1057 | { |
| 1058 | struct subchannel_id schid; |
| 1059 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1060 | s390_reset_system(); |
| 1061 | if (reipl_find_schid(devid, &schid) != 0) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1062 | panic("IPL Device not found\n"); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1063 | do_reipl_asm(*((__u32*)&schid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | } |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1065 | |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1066 | int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo) |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1067 | { |
| 1068 | struct subchannel_id schid; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1069 | struct schib schib; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1070 | |
| 1071 | schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID; |
| 1072 | if (!schid.one) |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1073 | return -ENODEV; |
| 1074 | if (stsch(schid, &schib)) |
| 1075 | return -ENODEV; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 1076 | if (schib.pmcw.st != SUBCHANNEL_TYPE_IO) |
| 1077 | return -ENODEV; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1078 | if (!schib.pmcw.dnv) |
| 1079 | return -ENODEV; |
| 1080 | iplinfo->devno = schib.pmcw.dev; |
| 1081 | iplinfo->is_qdio = schib.pmcw.qf; |
| 1082 | return 0; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1083 | } |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 1084 | |
| 1085 | /** |
| 1086 | * cio_tm_start_key - perform start function |
| 1087 | * @sch: subchannel on which to perform the start function |
| 1088 | * @tcw: transport-command word to be started |
| 1089 | * @lpm: mask of paths to use |
| 1090 | * @key: storage key to use for storage access |
| 1091 | * |
| 1092 | * Start the tcw on the given subchannel. Return zero on success, non-zero |
| 1093 | * otherwise. |
| 1094 | */ |
| 1095 | int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key) |
| 1096 | { |
| 1097 | int cc; |
| 1098 | union orb *orb = &to_io_private(sch)->orb; |
| 1099 | |
| 1100 | memset(orb, 0, sizeof(union orb)); |
| 1101 | orb->tm.intparm = (u32) (addr_t) sch; |
| 1102 | orb->tm.key = key >> 4; |
| 1103 | orb->tm.b = 1; |
| 1104 | orb->tm.lpm = lpm ? lpm : sch->lpm; |
| 1105 | orb->tm.tcw = (u32) (addr_t) tcw; |
| 1106 | cc = ssch(sch->schid, orb); |
| 1107 | switch (cc) { |
| 1108 | case 0: |
| 1109 | return 0; |
| 1110 | case 1: |
| 1111 | case 2: |
| 1112 | return -EBUSY; |
| 1113 | default: |
| 1114 | return cio_start_handle_notoper(sch, lpm); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | /** |
| 1119 | * cio_tm_intrg - perform interrogate function |
| 1120 | * @sch - subchannel on which to perform the interrogate function |
| 1121 | * |
| 1122 | * If the specified subchannel is running in transport-mode, perform the |
| 1123 | * interrogate function. Return zero on success, non-zero otherwie. |
| 1124 | */ |
| 1125 | int cio_tm_intrg(struct subchannel *sch) |
| 1126 | { |
| 1127 | int cc; |
| 1128 | |
| 1129 | if (!to_io_private(sch)->orb.tm.b) |
| 1130 | return -EINVAL; |
| 1131 | cc = xsch(sch->schid); |
| 1132 | switch (cc) { |
| 1133 | case 0: |
| 1134 | case 2: |
| 1135 | return 0; |
| 1136 | case 1: |
| 1137 | return -EBUSY; |
| 1138 | default: |
| 1139 | return -ENODEV; |
| 1140 | } |
| 1141 | } |