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