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