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