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