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