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