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 | |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 12 | #define KMSG_COMPONENT "cio" |
| 13 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/cio.h> |
| 22 | #include <asm/delay.h> |
| 23 | #include <asm/irq.h> |
Heiko Carstens | 5a489b98 | 2006-10-06 16:38:35 +0200 | [diff] [blame] | 24 | #include <asm/irq_regs.h> |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 25 | #include <asm/setup.h> |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 26 | #include <asm/reset.h> |
Michael Holzheu | 46b05d2 | 2007-02-21 10:55:21 +0100 | [diff] [blame] | 27 | #include <asm/ipl.h> |
Peter Oberparleiter | e5854a5 | 2007-04-27 16:01:31 +0200 | [diff] [blame] | 28 | #include <asm/chpid.h> |
Peter Oberparleiter | 4e8e56c | 2008-01-26 14:10:44 +0100 | [diff] [blame] | 29 | #include <asm/airq.h> |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 30 | #include <asm/isc.h> |
Heiko Carstens | 43ca5c3 | 2008-04-17 07:46:23 +0200 | [diff] [blame] | 31 | #include <asm/cpu.h> |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 32 | #include <asm/fcx.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "cio.h" |
| 34 | #include "css.h" |
| 35 | #include "chsc.h" |
| 36 | #include "ioasm.h" |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 37 | #include "io_sch.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include "blacklist.h" |
| 39 | #include "cio_debug.h" |
Peter Oberparleiter | e6b6e10 | 2007-04-27 16:01:28 +0200 | [diff] [blame] | 40 | #include "chp.h" |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 41 | #include "../s390mach.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | debug_info_t *cio_debug_msg_id; |
| 44 | debug_info_t *cio_debug_trace_id; |
| 45 | debug_info_t *cio_debug_crw_id; |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /* |
| 48 | * Function: cio_debug_init |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 49 | * Initializes three debug logs for common I/O: |
| 50 | * - cio_msg logs generic cio messages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | * - cio_trace logs the calling of different functions |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 52 | * - cio_crw logs machine check related cio messages |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | */ |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 54 | static int __init cio_debug_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 56 | 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] | 57 | if (!cio_debug_msg_id) |
| 58 | goto out_unregister; |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 59 | debug_register_view(cio_debug_msg_id, &debug_sprintf_view); |
| 60 | debug_set_level(cio_debug_msg_id, 2); |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 61 | cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | if (!cio_debug_trace_id) |
| 63 | goto out_unregister; |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 64 | debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view); |
| 65 | debug_set_level(cio_debug_trace_id, 2); |
Peter Tiedemann | 361f494 | 2008-01-26 14:11:30 +0100 | [diff] [blame] | 66 | 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] | 67 | if (!cio_debug_crw_id) |
| 68 | goto out_unregister; |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 69 | debug_register_view(cio_debug_crw_id, &debug_sprintf_view); |
| 70 | debug_set_level(cio_debug_crw_id, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return 0; |
| 72 | |
| 73 | out_unregister: |
| 74 | if (cio_debug_msg_id) |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 75 | debug_unregister(cio_debug_msg_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | if (cio_debug_trace_id) |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 77 | debug_unregister(cio_debug_trace_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | if (cio_debug_crw_id) |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 79 | debug_unregister(cio_debug_crw_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | arch_initcall (cio_debug_init); |
| 84 | |
| 85 | int |
| 86 | cio_set_options (struct subchannel *sch, int flags) |
| 87 | { |
| 88 | sch->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0; |
| 89 | sch->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0; |
| 90 | sch->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0; |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | /* FIXME: who wants to use this? */ |
| 95 | int |
| 96 | cio_get_options (struct subchannel *sch) |
| 97 | { |
| 98 | int flags; |
| 99 | |
| 100 | flags = 0; |
| 101 | if (sch->options.suspend) |
| 102 | flags |= DOIO_ALLOW_SUSPEND; |
| 103 | if (sch->options.prefetch) |
| 104 | flags |= DOIO_DENY_PREFETCH; |
| 105 | if (sch->options.inter) |
| 106 | flags |= DOIO_SUPPRESS_INTER; |
| 107 | return flags; |
| 108 | } |
| 109 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 110 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | cio_start_handle_notoper(struct subchannel *sch, __u8 lpm) |
| 112 | { |
| 113 | char dbf_text[15]; |
| 114 | |
| 115 | if (lpm != 0) |
| 116 | sch->lpm &= ~lpm; |
| 117 | else |
| 118 | sch->lpm = 0; |
| 119 | |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 120 | CIO_MSG_EVENT(2, "cio_start: 'not oper' status for " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 121 | "subchannel 0.%x.%04x!\n", sch->schid.ssid, |
| 122 | sch->schid.sch_no); |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 123 | |
| 124 | if (cio_update_schib(sch)) |
| 125 | return -ENODEV; |
| 126 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 127 | sprintf(dbf_text, "no%s", dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | CIO_TRACE_EVENT(0, dbf_text); |
| 129 | CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib)); |
| 130 | |
| 131 | return (sch->lpm ? -EACCES : -ENODEV); |
| 132 | } |
| 133 | |
| 134 | int |
| 135 | cio_start_key (struct subchannel *sch, /* subchannel structure */ |
| 136 | struct ccw1 * cpa, /* logical channel prog addr */ |
| 137 | __u8 lpm, /* logical path mask */ |
| 138 | __u8 key) /* storage key */ |
| 139 | { |
| 140 | char dbf_txt[15]; |
| 141 | int ccode; |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 142 | union orb *orb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 144 | CIO_TRACE_EVENT(4, "stIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 145 | CIO_TRACE_EVENT(4, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 147 | orb = &to_io_private(sch)->orb; |
Stefan Weinhuber | 9adb8c1 | 2008-09-16 09:32:19 -0700 | [diff] [blame] | 148 | memset(orb, 0, sizeof(union orb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | /* sch is always under 2G. */ |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 150 | orb->cmd.intparm = (u32)(addr_t)sch; |
| 151 | orb->cmd.fmt = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 153 | orb->cmd.pfch = sch->options.prefetch == 0; |
| 154 | orb->cmd.spnd = sch->options.suspend; |
| 155 | orb->cmd.ssic = sch->options.suspend && sch->options.inter; |
| 156 | orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm; |
Martin Schwidefsky | 347a8dc | 2006-01-06 00:19:28 -0800 | [diff] [blame] | 157 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | /* |
| 159 | * for 64 bit we always support 64 bit IDAWs with 4k page size only |
| 160 | */ |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 161 | orb->cmd.c64 = 1; |
| 162 | orb->cmd.i2k = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | #endif |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 164 | orb->cmd.key = key >> 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /* issue "Start Subchannel" */ |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 166 | orb->cmd.cpa = (__u32) __pa(cpa); |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 167 | ccode = ssch(sch->schid, orb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | /* process condition code */ |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 170 | sprintf(dbf_txt, "ccode:%d", ccode); |
| 171 | CIO_TRACE_EVENT(4, dbf_txt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | switch (ccode) { |
| 174 | case 0: |
| 175 | /* |
| 176 | * initialize device status information |
| 177 | */ |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 178 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return 0; |
| 180 | case 1: /* status pending */ |
| 181 | case 2: /* busy */ |
| 182 | return -EBUSY; |
Cornelia Huck | c91ebe4 | 2008-09-09 12:38:58 +0200 | [diff] [blame] | 183 | case 3: /* device/path not operational */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return cio_start_handle_notoper(sch, lpm); |
Cornelia Huck | c91ebe4 | 2008-09-09 12:38:58 +0200 | [diff] [blame] | 185 | default: |
| 186 | return ccode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | int |
| 191 | cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm) |
| 192 | { |
Peter Oberparleiter | 0b642ed | 2005-05-01 08:58:58 -0700 | [diff] [blame] | 193 | return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | * resume suspended I/O operation |
| 198 | */ |
| 199 | int |
| 200 | cio_resume (struct subchannel *sch) |
| 201 | { |
| 202 | char dbf_txt[15]; |
| 203 | int ccode; |
| 204 | |
| 205 | CIO_TRACE_EVENT (4, "resIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 206 | CIO_TRACE_EVENT(4, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 208 | ccode = rsch (sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | sprintf (dbf_txt, "ccode:%d", ccode); |
| 211 | CIO_TRACE_EVENT (4, dbf_txt); |
| 212 | |
| 213 | switch (ccode) { |
| 214 | case 0: |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 215 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return 0; |
| 217 | case 1: |
| 218 | return -EBUSY; |
| 219 | case 2: |
| 220 | return -EINVAL; |
| 221 | default: |
| 222 | /* |
| 223 | * useless to wait for request completion |
| 224 | * as device is no longer operational ! |
| 225 | */ |
| 226 | return -ENODEV; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * halt I/O operation |
| 232 | */ |
| 233 | int |
| 234 | cio_halt(struct subchannel *sch) |
| 235 | { |
| 236 | char dbf_txt[15]; |
| 237 | int ccode; |
| 238 | |
| 239 | if (!sch) |
| 240 | return -ENODEV; |
| 241 | |
| 242 | CIO_TRACE_EVENT (2, "haltIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 243 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Issue "Halt subchannel" and process condition code |
| 247 | */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 248 | ccode = hsch (sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
| 250 | sprintf (dbf_txt, "ccode:%d", ccode); |
| 251 | CIO_TRACE_EVENT (2, dbf_txt); |
| 252 | |
| 253 | switch (ccode) { |
| 254 | case 0: |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 255 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return 0; |
| 257 | case 1: /* status pending */ |
| 258 | case 2: /* busy */ |
| 259 | return -EBUSY; |
| 260 | default: /* device not operational */ |
| 261 | return -ENODEV; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Clear I/O operation |
| 267 | */ |
| 268 | int |
| 269 | cio_clear(struct subchannel *sch) |
| 270 | { |
| 271 | char dbf_txt[15]; |
| 272 | int ccode; |
| 273 | |
| 274 | if (!sch) |
| 275 | return -ENODEV; |
| 276 | |
| 277 | CIO_TRACE_EVENT (2, "clearIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 278 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | /* |
| 281 | * Issue "Clear subchannel" and process condition code |
| 282 | */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 283 | ccode = csch (sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | sprintf (dbf_txt, "ccode:%d", ccode); |
| 286 | CIO_TRACE_EVENT (2, dbf_txt); |
| 287 | |
| 288 | switch (ccode) { |
| 289 | case 0: |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 290 | sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return 0; |
| 292 | default: /* device not operational */ |
| 293 | return -ENODEV; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Function: cio_cancel |
| 299 | * Issues a "Cancel Subchannel" on the specified subchannel |
| 300 | * Note: We don't need any fancy intparms and flags here |
| 301 | * since xsch is executed synchronously. |
| 302 | * Only for common I/O internal use as for now. |
| 303 | */ |
| 304 | int |
| 305 | cio_cancel (struct subchannel *sch) |
| 306 | { |
| 307 | char dbf_txt[15]; |
| 308 | int ccode; |
| 309 | |
| 310 | if (!sch) |
| 311 | return -ENODEV; |
| 312 | |
| 313 | CIO_TRACE_EVENT (2, "cancelIO"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 314 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 316 | ccode = xsch (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: /* success */ |
| 323 | /* Update information in scsw. */ |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 324 | if (cio_update_schib(sch)) |
| 325 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return 0; |
| 327 | case 1: /* status pending */ |
| 328 | return -EBUSY; |
| 329 | case 2: /* not applicable */ |
| 330 | return -EINVAL; |
| 331 | default: /* not oper */ |
| 332 | return -ENODEV; |
| 333 | } |
| 334 | } |
| 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 337 | static void cio_apply_config(struct subchannel *sch, struct schib *schib) |
| 338 | { |
| 339 | schib->pmcw.intparm = sch->config.intparm; |
| 340 | schib->pmcw.mbi = sch->config.mbi; |
| 341 | schib->pmcw.isc = sch->config.isc; |
| 342 | schib->pmcw.ena = sch->config.ena; |
| 343 | schib->pmcw.mme = sch->config.mme; |
| 344 | schib->pmcw.mp = sch->config.mp; |
| 345 | schib->pmcw.csense = sch->config.csense; |
| 346 | schib->pmcw.mbfc = sch->config.mbfc; |
| 347 | if (sch->config.mbfc) |
| 348 | schib->mba = sch->config.mba; |
| 349 | } |
| 350 | |
| 351 | static int cio_check_config(struct subchannel *sch, struct schib *schib) |
| 352 | { |
| 353 | return (schib->pmcw.intparm == sch->config.intparm) && |
| 354 | (schib->pmcw.mbi == sch->config.mbi) && |
| 355 | (schib->pmcw.isc == sch->config.isc) && |
| 356 | (schib->pmcw.ena == sch->config.ena) && |
| 357 | (schib->pmcw.mme == sch->config.mme) && |
| 358 | (schib->pmcw.mp == sch->config.mp) && |
| 359 | (schib->pmcw.csense == sch->config.csense) && |
| 360 | (schib->pmcw.mbfc == sch->config.mbfc) && |
| 361 | (!sch->config.mbfc || (schib->mba == sch->config.mba)); |
| 362 | } |
| 363 | |
| 364 | /* |
| 365 | * cio_commit_config - apply configuration to the subchannel |
| 366 | */ |
| 367 | int cio_commit_config(struct subchannel *sch) |
| 368 | { |
| 369 | struct schib schib; |
| 370 | int ccode, retry, ret = 0; |
| 371 | |
| 372 | if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib)) |
| 373 | return -ENODEV; |
| 374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | for (retry = 0; retry < 5; retry++) { |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 376 | /* copy desired changes to local schib */ |
| 377 | cio_apply_config(sch, &schib); |
| 378 | ccode = msch_err(sch->schid, &schib); |
| 379 | if (ccode < 0) /* -EIO if msch gets a program check. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | return ccode; |
| 381 | switch (ccode) { |
Coly Li | 73ac36e | 2009-01-07 18:09:16 -0800 | [diff] [blame^] | 382 | case 0: /* successful */ |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 383 | if (stsch(sch->schid, &schib) || |
| 384 | !css_sch_is_valid(&schib)) |
| 385 | return -ENODEV; |
| 386 | if (cio_check_config(sch, &schib)) { |
| 387 | /* commit changes from local schib */ |
| 388 | memcpy(&sch->schib, &schib, sizeof(schib)); |
| 389 | return 0; |
| 390 | } |
| 391 | ret = -EAGAIN; |
| 392 | break; |
| 393 | case 1: /* status pending */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | return -EBUSY; |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 395 | case 2: /* busy */ |
| 396 | udelay(100); /* allow for recovery */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | ret = -EBUSY; |
| 398 | break; |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 399 | case 3: /* not operational */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return -ENODEV; |
| 401 | } |
| 402 | } |
| 403 | return ret; |
| 404 | } |
| 405 | |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 406 | /** |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 407 | * cio_update_schib - Perform stsch and update schib if subchannel is valid. |
| 408 | * @sch: subchannel on which to perform stsch |
| 409 | * Return zero on success, -ENODEV otherwise. |
| 410 | */ |
| 411 | int cio_update_schib(struct subchannel *sch) |
| 412 | { |
| 413 | struct schib schib; |
| 414 | |
| 415 | if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib)) |
| 416 | return -ENODEV; |
| 417 | |
| 418 | memcpy(&sch->schib, &schib, sizeof(schib)); |
| 419 | return 0; |
| 420 | } |
| 421 | EXPORT_SYMBOL_GPL(cio_update_schib); |
| 422 | |
| 423 | /** |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 424 | * cio_enable_subchannel - enable a subchannel. |
| 425 | * @sch: subchannel to be enabled |
| 426 | * @intparm: interruption parameter to set |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | */ |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 428 | int cio_enable_subchannel(struct subchannel *sch, u32 intparm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | { |
| 430 | char dbf_txt[15]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | int retry; |
| 432 | int ret; |
| 433 | |
| 434 | CIO_TRACE_EVENT (2, "ensch"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 435 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 437 | if (sch_is_pseudo_sch(sch)) |
| 438 | return -EINVAL; |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 439 | if (cio_update_schib(sch)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | return -ENODEV; |
| 441 | |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 442 | sch->config.ena = 1; |
| 443 | sch->config.isc = sch->isc; |
| 444 | sch->config.intparm = intparm; |
| 445 | |
| 446 | for (retry = 0; retry < 3; retry++) { |
| 447 | ret = cio_commit_config(sch); |
| 448 | if (ret == -EIO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 450 | * Got a program check in msch. Try without |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | * the concurrent sense bit the next time. |
| 452 | */ |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 453 | sch->config.csense = 0; |
| 454 | } else if (ret == -EBUSY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | struct irb irb; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 456 | if (tsch(sch->schid, &irb) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | break; |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 458 | } else |
| 459 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 461 | sprintf (dbf_txt, "ret:%d", ret); |
| 462 | CIO_TRACE_EVENT (2, dbf_txt); |
| 463 | return ret; |
| 464 | } |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 465 | EXPORT_SYMBOL_GPL(cio_enable_subchannel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 467 | /** |
| 468 | * cio_disable_subchannel - disable a subchannel. |
| 469 | * @sch: subchannel to disable |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | */ |
Cornelia Huck | 44a1c19 | 2008-07-14 09:58:47 +0200 | [diff] [blame] | 471 | int cio_disable_subchannel(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | { |
| 473 | char dbf_txt[15]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | int ret; |
| 475 | |
| 476 | CIO_TRACE_EVENT (2, "dissch"); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 477 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 479 | if (sch_is_pseudo_sch(sch)) |
| 480 | return 0; |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 481 | if (cio_update_schib(sch)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return -ENODEV; |
| 483 | |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 484 | if (scsw_actl(&sch->schib.scsw) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | /* |
| 486 | * the disable function must not be called while there are |
| 487 | * requests pending for completion ! |
| 488 | */ |
| 489 | return -EBUSY; |
| 490 | |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 491 | sch->config.ena = 0; |
| 492 | ret = cio_commit_config(sch); |
| 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 43ca5c3 | 2008-04-17 07:46:23 +0200 | [diff] [blame] | 635 | s390_idle_check(); |
Martin Schwidefsky | 9cfb9b3 | 2008-12-31 15:11:41 +0100 | [diff] [blame] | 636 | irq_enter(); |
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 | |
Heiko Carstens | 191fd44 | 2008-12-25 13:39:01 +0100 | [diff] [blame] | 690 | /* |
| 691 | * Use tpi to get a pending interrupt, call the interrupt handler and |
| 692 | * return a pointer to the subchannel structure. |
| 693 | */ |
| 694 | static int cio_tpi(void) |
| 695 | { |
| 696 | struct tpi_info *tpi_info; |
| 697 | struct subchannel *sch; |
| 698 | struct irb *irb; |
| 699 | int irq_context; |
| 700 | |
| 701 | tpi_info = (struct tpi_info *) __LC_SUBCHANNEL_ID; |
| 702 | if (tpi(NULL) != 1) |
| 703 | return 0; |
| 704 | irb = (struct irb *) __LC_IRB; |
| 705 | /* Store interrupt response block to lowcore. */ |
| 706 | if (tsch(tpi_info->schid, irb) != 0) |
| 707 | /* Not status pending or not operational. */ |
| 708 | return 1; |
| 709 | sch = (struct subchannel *)(unsigned long)tpi_info->intparm; |
| 710 | if (!sch) |
| 711 | return 1; |
| 712 | irq_context = in_interrupt(); |
| 713 | if (!irq_context) |
| 714 | local_bh_disable(); |
| 715 | irq_enter(); |
| 716 | spin_lock(sch->lock); |
| 717 | memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw)); |
| 718 | if (sch->driver && sch->driver->irq) |
| 719 | sch->driver->irq(sch); |
| 720 | spin_unlock(sch->lock); |
| 721 | irq_exit(); |
| 722 | if (!irq_context) |
| 723 | _local_bh_enable(); |
| 724 | return 1; |
| 725 | } |
| 726 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 727 | void *cio_get_console_priv(void) |
| 728 | { |
| 729 | return &console_priv; |
| 730 | } |
| 731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | /* |
| 733 | * busy wait for the next interrupt on the console |
| 734 | */ |
Heiko Carstens | a806170 | 2008-04-17 07:46:26 +0200 | [diff] [blame] | 735 | void wait_cons_dev(void) |
| 736 | __releases(console_subchannel.lock) |
| 737 | __acquires(console_subchannel.lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
| 739 | unsigned long cr6 __attribute__ ((aligned (8))); |
| 740 | unsigned long save_cr6 __attribute__ ((aligned (8))); |
| 741 | |
| 742 | /* |
| 743 | * before entering the spinlock we may already have |
| 744 | * processed the interrupt on a different CPU... |
| 745 | */ |
| 746 | if (!console_subchannel_in_use) |
| 747 | return; |
| 748 | |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 749 | /* disable all but the console isc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | __ctl_store (save_cr6, 6, 6); |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 751 | cr6 = 1UL << (31 - CONSOLE_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | __ctl_load (cr6, 6, 6); |
| 753 | |
| 754 | do { |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 755 | spin_unlock(console_subchannel.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | if (!cio_tpi()) |
| 757 | cpu_relax(); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 758 | spin_lock(console_subchannel.lock); |
Peter Oberparleiter | 23d805b6 | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 759 | } while (console_subchannel.schib.scsw.cmd.actl != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | /* |
| 761 | * restore previous isc value |
| 762 | */ |
| 763 | __ctl_load (save_cr6, 6, 6); |
| 764 | } |
| 765 | |
| 766 | static int |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 767 | cio_test_for_console(struct subchannel_id schid, void *data) |
| 768 | { |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 769 | if (stsch_err(schid, &console_subchannel.schib) != 0) |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 770 | return -ENXIO; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 771 | if ((console_subchannel.schib.pmcw.st == SUBCHANNEL_TYPE_IO) && |
| 772 | console_subchannel.schib.pmcw.dnv && |
| 773 | (console_subchannel.schib.pmcw.dev == console_devno)) { |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 774 | console_irq = schid.sch_no; |
| 775 | return 1; /* found */ |
| 776 | } |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | |
| 781 | static int |
| 782 | cio_get_console_sch_no(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 784 | struct subchannel_id schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 786 | init_subchannel_id(&schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | if (console_irq != -1) { |
| 788 | /* VM provided us with the irq number of the console. */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 789 | schid.sch_no = console_irq; |
| 790 | if (stsch(schid, &console_subchannel.schib) != 0 || |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 791 | (console_subchannel.schib.pmcw.st != SUBCHANNEL_TYPE_IO) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | !console_subchannel.schib.pmcw.dnv) |
| 793 | return -1; |
| 794 | console_devno = console_subchannel.schib.pmcw.dev; |
| 795 | } else if (console_devno != -1) { |
| 796 | /* At least the console device number is known. */ |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 797 | for_each_subchannel(cio_test_for_console, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (console_irq == -1) |
| 799 | return -1; |
| 800 | } else { |
| 801 | /* unlike in 2.4, we cannot autoprobe here, since |
| 802 | * the channel subsystem is not fully initialized. |
| 803 | * With some luck, the HWC console can take over */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return -1; |
| 805 | } |
| 806 | return console_irq; |
| 807 | } |
| 808 | |
| 809 | struct subchannel * |
| 810 | cio_probe_console(void) |
| 811 | { |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 812 | int sch_no, ret; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 813 | struct subchannel_id schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | if (xchg(&console_subchannel_in_use, 1) != 0) |
| 816 | return ERR_PTR(-EBUSY); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 817 | sch_no = cio_get_console_sch_no(); |
| 818 | if (sch_no == -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | console_subchannel_in_use = 0; |
Michael Ernst | e6d5a42 | 2008-12-25 13:39:36 +0100 | [diff] [blame] | 820 | pr_warning("No CCW console was found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | return ERR_PTR(-ENODEV); |
| 822 | } |
| 823 | memset(&console_subchannel, 0, sizeof(struct subchannel)); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 824 | init_subchannel_id(&schid); |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 825 | schid.sch_no = sch_no; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 826 | ret = cio_validate_subchannel(&console_subchannel, schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | if (ret) { |
| 828 | console_subchannel_in_use = 0; |
| 829 | return ERR_PTR(-ENODEV); |
| 830 | } |
| 831 | |
| 832 | /* |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 833 | * enable console I/O-interrupt subclass |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | */ |
Cornelia Huck | 6ef556c | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 835 | isc_register(CONSOLE_ISC); |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 836 | console_subchannel.config.isc = CONSOLE_ISC; |
| 837 | console_subchannel.config.intparm = (u32)(addr_t)&console_subchannel; |
| 838 | ret = cio_commit_config(&console_subchannel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | if (ret) { |
Cornelia Huck | 6ef556c | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 840 | isc_unregister(CONSOLE_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | console_subchannel_in_use = 0; |
| 842 | return ERR_PTR(ret); |
| 843 | } |
| 844 | return &console_subchannel; |
| 845 | } |
| 846 | |
| 847 | void |
| 848 | cio_release_console(void) |
| 849 | { |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 850 | console_subchannel.config.intparm = 0; |
| 851 | cio_commit_config(&console_subchannel); |
Cornelia Huck | 6ef556c | 2008-07-14 09:59:01 +0200 | [diff] [blame] | 852 | isc_unregister(CONSOLE_ISC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | console_subchannel_in_use = 0; |
| 854 | } |
| 855 | |
| 856 | /* Bah... hack to catch console special sausages. */ |
| 857 | int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 858 | cio_is_console(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | { |
| 860 | if (!console_subchannel_in_use) |
| 861 | return 0; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 862 | return schid_equal(&schid, &console_subchannel.schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | struct subchannel * |
| 866 | cio_get_console_subchannel(void) |
| 867 | { |
| 868 | if (!console_subchannel_in_use) |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 869 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | return &console_subchannel; |
| 871 | } |
| 872 | |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 873 | const char *cio_get_console_sch_name(struct subchannel_id schid) |
| 874 | { |
| 875 | snprintf(console_sch_name, 10, "0.%x.%04x", schid.ssid, schid.sch_no); |
| 876 | return (const char *)console_sch_name; |
| 877 | } |
| 878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | #endif |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 880 | static int |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 881 | __disable_subchannel_easy(struct subchannel_id schid, struct schib *schib) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | { |
| 883 | int retry, cc; |
| 884 | |
| 885 | cc = 0; |
| 886 | for (retry=0;retry<3;retry++) { |
| 887 | schib->pmcw.ena = 0; |
| 888 | cc = msch(schid, schib); |
| 889 | if (cc) |
| 890 | return (cc==3?-ENODEV:-EBUSY); |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 891 | if (stsch(schid, schib) || !css_sch_is_valid(schib)) |
| 892 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | if (!schib->pmcw.ena) |
| 894 | return 0; |
| 895 | } |
| 896 | return -EBUSY; /* uhm... */ |
| 897 | } |
| 898 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 899 | static int |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 900 | __clear_io_subchannel_easy(struct subchannel_id schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { |
| 902 | int retry; |
| 903 | |
| 904 | if (csch(schid)) |
| 905 | return -ENODEV; |
| 906 | for (retry=0;retry<20;retry++) { |
| 907 | struct tpi_info ti; |
| 908 | |
| 909 | if (tpi(&ti)) { |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 910 | tsch(ti.schid, (struct irb *)__LC_IRB); |
| 911 | if (schid_equal(&ti.schid, &schid)) |
Cornelia Huck | 4c24da7 | 2005-09-03 15:58:01 -0700 | [diff] [blame] | 912 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
Heiko Carstens | 5a0d0e6 | 2008-10-10 21:33:22 +0200 | [diff] [blame] | 914 | udelay_simple(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | } |
| 916 | return -EBUSY; |
| 917 | } |
| 918 | |
Cornelia Huck | 9d92a7e | 2008-07-14 09:59:05 +0200 | [diff] [blame] | 919 | static void __clear_chsc_subchannel_easy(void) |
| 920 | { |
| 921 | /* It seems we can only wait for a bit here :/ */ |
Heiko Carstens | 5a0d0e6 | 2008-10-10 21:33:22 +0200 | [diff] [blame] | 922 | udelay_simple(100); |
Cornelia Huck | 9d92a7e | 2008-07-14 09:59:05 +0200 | [diff] [blame] | 923 | } |
| 924 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 925 | static int pgm_check_occured; |
| 926 | |
| 927 | static void cio_reset_pgm_check_handler(void) |
| 928 | { |
| 929 | pgm_check_occured = 1; |
| 930 | } |
| 931 | |
Peter Oberparleiter | f9c9fe3 | 2008-10-10 21:33:15 +0200 | [diff] [blame] | 932 | static int stsch_reset(struct subchannel_id schid, struct schib *addr) |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 933 | { |
| 934 | int rc; |
| 935 | |
| 936 | pgm_check_occured = 0; |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 937 | s390_base_pgm_handler_fn = cio_reset_pgm_check_handler; |
Heiko Carstens | 6faf444 | 2007-01-09 10:18:41 +0100 | [diff] [blame] | 938 | rc = stsch(schid, addr); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 939 | s390_base_pgm_handler_fn = NULL; |
Heiko Carstens | 6faf444 | 2007-01-09 10:18:41 +0100 | [diff] [blame] | 940 | |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 941 | /* The program check handler could have changed pgm_check_occured. */ |
Heiko Carstens | 6faf444 | 2007-01-09 10:18:41 +0100 | [diff] [blame] | 942 | barrier(); |
| 943 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 944 | if (pgm_check_occured) |
| 945 | return -EIO; |
| 946 | else |
| 947 | return rc; |
| 948 | } |
| 949 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 950 | static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data) |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 951 | { |
| 952 | struct schib schib; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 954 | if (stsch_reset(schid, &schib)) |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 955 | return -ENXIO; |
| 956 | if (!schib.pmcw.ena) |
| 957 | return 0; |
| 958 | switch(__disable_subchannel_easy(schid, &schib)) { |
| 959 | case 0: |
| 960 | case -ENODEV: |
| 961 | break; |
| 962 | default: /* -EBUSY */ |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 963 | switch (schib.pmcw.st) { |
| 964 | case SUBCHANNEL_TYPE_IO: |
| 965 | if (__clear_io_subchannel_easy(schid)) |
| 966 | goto out; /* give up... */ |
| 967 | break; |
Cornelia Huck | 9d92a7e | 2008-07-14 09:59:05 +0200 | [diff] [blame] | 968 | case SUBCHANNEL_TYPE_CHSC: |
| 969 | __clear_chsc_subchannel_easy(); |
| 970 | break; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 971 | default: |
| 972 | /* No default clear strategy */ |
| 973 | break; |
| 974 | } |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 975 | stsch(schid, &schib); |
| 976 | __disable_subchannel_easy(schid, &schib); |
| 977 | } |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 978 | out: |
Cornelia Huck | f97a56f | 2006-01-06 00:19:22 -0800 | [diff] [blame] | 979 | return 0; |
| 980 | } |
| 981 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 982 | static atomic_t chpid_reset_count; |
| 983 | |
| 984 | static void s390_reset_chpids_mcck_handler(void) |
| 985 | { |
| 986 | struct crw crw; |
| 987 | struct mci *mci; |
| 988 | |
| 989 | /* Check for pending channel report word. */ |
| 990 | mci = (struct mci *)&S390_lowcore.mcck_interruption_code; |
| 991 | if (!mci->cp) |
| 992 | return; |
| 993 | /* Process channel report words. */ |
| 994 | while (stcrw(&crw) == 0) { |
| 995 | /* Check for responses to RCHP. */ |
| 996 | if (crw.slct && crw.rsc == CRW_RSC_CPATH) |
| 997 | atomic_dec(&chpid_reset_count); |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | #define RCHP_TIMEOUT (30 * USEC_PER_SEC) |
| 1002 | static void css_reset(void) |
| 1003 | { |
| 1004 | int i, ret; |
| 1005 | unsigned long long timeout; |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 1006 | struct chp_id chpid; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1007 | |
| 1008 | /* Reset subchannels. */ |
| 1009 | for_each_subchannel(__shutdown_subchannel_easy, NULL); |
| 1010 | /* Reset channel paths. */ |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 1011 | s390_base_mcck_handler_fn = s390_reset_chpids_mcck_handler; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1012 | /* Enable channel report machine checks. */ |
| 1013 | __ctl_set_bit(14, 28); |
| 1014 | /* Temporarily reenable machine checks. */ |
| 1015 | local_mcck_enable(); |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 1016 | chp_id_init(&chpid); |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1017 | for (i = 0; i <= __MAX_CHPID; i++) { |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 1018 | chpid.id = i; |
| 1019 | ret = rchp(chpid); |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1020 | if ((ret == 0) || (ret == 2)) |
| 1021 | /* |
| 1022 | * rchp either succeeded, or another rchp is already |
| 1023 | * in progress. In either case, we'll get a crw. |
| 1024 | */ |
| 1025 | atomic_inc(&chpid_reset_count); |
| 1026 | } |
| 1027 | /* Wait for machine check for all channel paths. */ |
| 1028 | timeout = get_clock() + (RCHP_TIMEOUT << 12); |
| 1029 | while (atomic_read(&chpid_reset_count) != 0) { |
| 1030 | if (get_clock() > timeout) |
| 1031 | break; |
| 1032 | cpu_relax(); |
| 1033 | } |
| 1034 | /* Disable machine checks again. */ |
| 1035 | local_mcck_disable(); |
| 1036 | /* Disable channel report machine checks. */ |
| 1037 | __ctl_clear_bit(14, 28); |
Heiko Carstens | ab14de6 | 2007-02-05 21:18:37 +0100 | [diff] [blame] | 1038 | s390_base_mcck_handler_fn = NULL; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | static struct reset_call css_reset_call = { |
| 1042 | .fn = css_reset, |
| 1043 | }; |
| 1044 | |
| 1045 | static int __init init_css_reset_call(void) |
| 1046 | { |
| 1047 | atomic_set(&chpid_reset_count, 0); |
| 1048 | register_reset_call(&css_reset_call); |
| 1049 | return 0; |
| 1050 | } |
| 1051 | |
| 1052 | arch_initcall(init_css_reset_call); |
| 1053 | |
| 1054 | struct sch_match_id { |
| 1055 | struct subchannel_id schid; |
| 1056 | struct ccw_dev_id devid; |
| 1057 | int rc; |
| 1058 | }; |
| 1059 | |
| 1060 | static int __reipl_subchannel_match(struct subchannel_id schid, void *data) |
| 1061 | { |
| 1062 | struct schib schib; |
| 1063 | struct sch_match_id *match_id = data; |
| 1064 | |
Michael Holzheu | a45e141 | 2006-12-15 17:18:22 +0100 | [diff] [blame] | 1065 | if (stsch_reset(schid, &schib)) |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1066 | return -ENXIO; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 1067 | if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv && |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1068 | (schib.pmcw.dev == match_id->devid.devno) && |
| 1069 | (schid.ssid == match_id->devid.ssid)) { |
| 1070 | match_id->schid = schid; |
| 1071 | match_id->rc = 0; |
| 1072 | return 1; |
| 1073 | } |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
| 1077 | static int reipl_find_schid(struct ccw_dev_id *devid, |
| 1078 | struct subchannel_id *schid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | { |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1080 | struct sch_match_id match_id; |
| 1081 | |
| 1082 | match_id.devid = *devid; |
| 1083 | match_id.rc = -ENODEV; |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1084 | for_each_subchannel(__reipl_subchannel_match, &match_id); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1085 | if (match_id.rc == 0) |
| 1086 | *schid = match_id.schid; |
| 1087 | return match_id.rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1090 | extern void do_reipl_asm(__u32 schid); |
| 1091 | |
| 1092 | /* Make sure all subchannels are quiet before we re-ipl an lpar. */ |
| 1093 | void reipl_ccw_dev(struct ccw_dev_id *devid) |
| 1094 | { |
| 1095 | struct subchannel_id schid; |
| 1096 | |
Heiko Carstens | 15e9b58 | 2006-12-04 15:40:26 +0100 | [diff] [blame] | 1097 | s390_reset_system(); |
| 1098 | if (reipl_find_schid(devid, &schid) != 0) |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1099 | panic("IPL Device not found\n"); |
Michael Holzheu | ff6b8ea | 2006-09-20 15:58:49 +0200 | [diff] [blame] | 1100 | do_reipl_asm(*((__u32*)&schid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | } |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1102 | |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1103 | int __init cio_get_iplinfo(struct cio_iplinfo *iplinfo) |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1104 | { |
| 1105 | struct subchannel_id schid; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1106 | struct schib schib; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1107 | |
| 1108 | schid = *(struct subchannel_id *)__LC_SUBCHANNEL_ID; |
| 1109 | if (!schid.one) |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1110 | return -ENODEV; |
| 1111 | if (stsch(schid, &schib)) |
| 1112 | return -ENODEV; |
Cornelia Huck | b279a4f | 2008-01-26 14:10:45 +0100 | [diff] [blame] | 1113 | if (schib.pmcw.st != SUBCHANNEL_TYPE_IO) |
| 1114 | return -ENODEV; |
Heiko Carstens | 6fc321f | 2007-04-27 16:01:25 +0200 | [diff] [blame] | 1115 | if (!schib.pmcw.dnv) |
| 1116 | return -ENODEV; |
| 1117 | iplinfo->devno = schib.pmcw.dev; |
| 1118 | iplinfo->is_qdio = schib.pmcw.qf; |
| 1119 | return 0; |
Heiko Carstens | e87bfe5 | 2006-09-20 15:59:15 +0200 | [diff] [blame] | 1120 | } |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 1121 | |
| 1122 | /** |
| 1123 | * cio_tm_start_key - perform start function |
| 1124 | * @sch: subchannel on which to perform the start function |
| 1125 | * @tcw: transport-command word to be started |
| 1126 | * @lpm: mask of paths to use |
| 1127 | * @key: storage key to use for storage access |
| 1128 | * |
| 1129 | * Start the tcw on the given subchannel. Return zero on success, non-zero |
| 1130 | * otherwise. |
| 1131 | */ |
| 1132 | int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key) |
| 1133 | { |
| 1134 | int cc; |
| 1135 | union orb *orb = &to_io_private(sch)->orb; |
| 1136 | |
| 1137 | memset(orb, 0, sizeof(union orb)); |
| 1138 | orb->tm.intparm = (u32) (addr_t) sch; |
| 1139 | orb->tm.key = key >> 4; |
| 1140 | orb->tm.b = 1; |
| 1141 | orb->tm.lpm = lpm ? lpm : sch->lpm; |
| 1142 | orb->tm.tcw = (u32) (addr_t) tcw; |
| 1143 | cc = ssch(sch->schid, orb); |
| 1144 | switch (cc) { |
| 1145 | case 0: |
| 1146 | return 0; |
| 1147 | case 1: |
| 1148 | case 2: |
| 1149 | return -EBUSY; |
| 1150 | default: |
| 1151 | return cio_start_handle_notoper(sch, lpm); |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * cio_tm_intrg - perform interrogate function |
| 1157 | * @sch - subchannel on which to perform the interrogate function |
| 1158 | * |
| 1159 | * If the specified subchannel is running in transport-mode, perform the |
| 1160 | * interrogate function. Return zero on success, non-zero otherwie. |
| 1161 | */ |
| 1162 | int cio_tm_intrg(struct subchannel *sch) |
| 1163 | { |
| 1164 | int cc; |
| 1165 | |
| 1166 | if (!to_io_private(sch)->orb.tm.b) |
| 1167 | return -EINVAL; |
| 1168 | cc = xsch(sch->schid); |
| 1169 | switch (cc) { |
| 1170 | case 0: |
| 1171 | case 2: |
| 1172 | return 0; |
| 1173 | case 1: |
| 1174 | return -EBUSY; |
| 1175 | default: |
| 1176 | return -ENODEV; |
| 1177 | } |
| 1178 | } |