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