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