Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/device_fsm.c |
| 3 | * finite state machine for device handling |
| 4 | * |
| 5 | * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, |
| 6 | * IBM Corporation |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 7 | * Author(s): Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 13 | #include <linux/jiffies.h> |
| 14 | #include <linux/string.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include <asm/ccwdev.h> |
Cornelia Huck | 4c24da7 | 2005-09-03 15:58:01 -0700 | [diff] [blame] | 17 | #include <asm/cio.h> |
Peter Oberparleiter | e5854a5 | 2007-04-27 16:01:31 +0200 | [diff] [blame] | 18 | #include <asm/chpid.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include "cio.h" |
| 21 | #include "cio_debug.h" |
| 22 | #include "css.h" |
| 23 | #include "device.h" |
| 24 | #include "chsc.h" |
| 25 | #include "ioasm.h" |
Peter Oberparleiter | e6b6e10 | 2007-04-27 16:01:28 +0200 | [diff] [blame] | 26 | #include "chp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 28 | static int timeout_log_enabled; |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | int |
| 31 | device_is_online(struct subchannel *sch) |
| 32 | { |
| 33 | struct ccw_device *cdev; |
| 34 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 35 | cdev = sch_get_cdev(sch); |
| 36 | if (!cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | return (cdev->private->state == DEV_STATE_ONLINE); |
| 39 | } |
| 40 | |
| 41 | int |
| 42 | device_is_disconnected(struct subchannel *sch) |
| 43 | { |
| 44 | struct ccw_device *cdev; |
| 45 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 46 | cdev = sch_get_cdev(sch); |
| 47 | if (!cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | return (cdev->private->state == DEV_STATE_DISCONNECTED || |
| 50 | cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID); |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | device_set_disconnected(struct subchannel *sch) |
| 55 | { |
| 56 | struct ccw_device *cdev; |
| 57 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 58 | cdev = sch_get_cdev(sch); |
| 59 | if (!cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | ccw_device_set_timeout(cdev, 0); |
| 62 | cdev->private->flags.fake_irb = 0; |
| 63 | cdev->private->state = DEV_STATE_DISCONNECTED; |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 64 | if (cdev->online) |
| 65 | ccw_device_schedule_recovery(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame] | 68 | void device_set_intretry(struct subchannel *sch) |
| 69 | { |
| 70 | struct ccw_device *cdev; |
| 71 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 72 | cdev = sch_get_cdev(sch); |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame] | 73 | if (!cdev) |
| 74 | return; |
| 75 | cdev->private->flags.intretry = 1; |
| 76 | } |
| 77 | |
Cornelia Huck | 24cb5b4 | 2006-12-04 15:41:01 +0100 | [diff] [blame] | 78 | int device_trigger_verify(struct subchannel *sch) |
| 79 | { |
| 80 | struct ccw_device *cdev; |
| 81 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 82 | cdev = sch_get_cdev(sch); |
Cornelia Huck | 24cb5b4 | 2006-12-04 15:41:01 +0100 | [diff] [blame] | 83 | if (!cdev || !cdev->online) |
| 84 | return -EINVAL; |
| 85 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 86 | return 0; |
| 87 | } |
| 88 | |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 89 | static int __init ccw_timeout_log_setup(char *unused) |
| 90 | { |
| 91 | timeout_log_enabled = 1; |
| 92 | return 1; |
| 93 | } |
| 94 | |
| 95 | __setup("ccw_timeout_log", ccw_timeout_log_setup); |
| 96 | |
| 97 | static void ccw_timeout_log(struct ccw_device *cdev) |
| 98 | { |
| 99 | struct schib schib; |
| 100 | struct subchannel *sch; |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 101 | struct io_subchannel_private *private; |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 102 | int cc; |
| 103 | |
| 104 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 105 | private = to_io_private(sch); |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 106 | cc = stsch(sch->schid, &schib); |
| 107 | |
| 108 | printk(KERN_WARNING "cio: ccw device timeout occurred at %llx, " |
| 109 | "device information:\n", get_clock()); |
| 110 | printk(KERN_WARNING "cio: orb:\n"); |
| 111 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 112 | &private->orb, sizeof(private->orb), 0); |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 113 | printk(KERN_WARNING "cio: ccw device bus id: %s\n", cdev->dev.bus_id); |
| 114 | printk(KERN_WARNING "cio: subchannel bus id: %s\n", sch->dev.bus_id); |
| 115 | printk(KERN_WARNING "cio: subchannel lpm: %02x, opm: %02x, " |
| 116 | "vpm: %02x\n", sch->lpm, sch->opm, sch->vpm); |
| 117 | |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 118 | if ((void *)(addr_t)private->orb.cpa == &private->sense_ccw || |
| 119 | (void *)(addr_t)private->orb.cpa == cdev->private->iccws) |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 120 | printk(KERN_WARNING "cio: last channel program (intern):\n"); |
| 121 | else |
| 122 | printk(KERN_WARNING "cio: last channel program:\n"); |
| 123 | |
| 124 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 125 | (void *)(addr_t)private->orb.cpa, |
| 126 | sizeof(struct ccw1), 0); |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 127 | printk(KERN_WARNING "cio: ccw device state: %d\n", |
| 128 | cdev->private->state); |
| 129 | printk(KERN_WARNING "cio: store subchannel returned: cc=%d\n", cc); |
| 130 | printk(KERN_WARNING "cio: schib:\n"); |
| 131 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
| 132 | &schib, sizeof(schib), 0); |
| 133 | printk(KERN_WARNING "cio: ccw device flags:\n"); |
| 134 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
| 135 | &cdev->private->flags, sizeof(cdev->private->flags), 0); |
| 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* |
| 139 | * Timeout function. It just triggers a DEV_EVENT_TIMEOUT. |
| 140 | */ |
| 141 | static void |
| 142 | ccw_device_timeout(unsigned long data) |
| 143 | { |
| 144 | struct ccw_device *cdev; |
| 145 | |
| 146 | cdev = (struct ccw_device *) data; |
| 147 | spin_lock_irq(cdev->ccwlock); |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 148 | if (timeout_log_enabled) |
| 149 | ccw_timeout_log(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | dev_fsm_event(cdev, DEV_EVENT_TIMEOUT); |
| 151 | spin_unlock_irq(cdev->ccwlock); |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Set timeout |
| 156 | */ |
| 157 | void |
| 158 | ccw_device_set_timeout(struct ccw_device *cdev, int expires) |
| 159 | { |
| 160 | if (expires == 0) { |
| 161 | del_timer(&cdev->private->timer); |
| 162 | return; |
| 163 | } |
| 164 | if (timer_pending(&cdev->private->timer)) { |
| 165 | if (mod_timer(&cdev->private->timer, jiffies + expires)) |
| 166 | return; |
| 167 | } |
| 168 | cdev->private->timer.function = ccw_device_timeout; |
| 169 | cdev->private->timer.data = (unsigned long) cdev; |
| 170 | cdev->private->timer.expires = jiffies + expires; |
| 171 | add_timer(&cdev->private->timer); |
| 172 | } |
| 173 | |
| 174 | /* Kill any pending timers after machine check. */ |
| 175 | void |
| 176 | device_kill_pending_timer(struct subchannel *sch) |
| 177 | { |
| 178 | struct ccw_device *cdev; |
| 179 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 180 | cdev = sch_get_cdev(sch); |
| 181 | if (!cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | ccw_device_set_timeout(cdev, 0); |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * Cancel running i/o. This is called repeatedly since halt/clear are |
| 188 | * asynchronous operations. We do one try with cio_cancel, two tries |
| 189 | * with cio_halt, 255 tries with cio_clear. If everythings fails panic. |
| 190 | * Returns 0 if device now idle, -ENODEV for device not operational and |
| 191 | * -EBUSY if an interrupt is expected (either from halt/clear or from a |
| 192 | * status pending). |
| 193 | */ |
| 194 | int |
| 195 | ccw_device_cancel_halt_clear(struct ccw_device *cdev) |
| 196 | { |
| 197 | struct subchannel *sch; |
| 198 | int ret; |
| 199 | |
| 200 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 201 | ret = stsch(sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | if (ret || !sch->schib.pmcw.dnv) |
| 203 | return -ENODEV; |
Cornelia Huck | 2470b64 | 2007-03-05 23:36:02 +0100 | [diff] [blame] | 204 | if (!sch->schib.pmcw.ena) |
| 205 | /* Not operational -> done. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return 0; |
| 207 | /* Stage 1: cancel io. */ |
| 208 | if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) && |
| 209 | !(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) { |
| 210 | ret = cio_cancel(sch); |
| 211 | if (ret != -EINVAL) |
| 212 | return ret; |
| 213 | /* cancel io unsuccessful. From now on it is asynchronous. */ |
| 214 | cdev->private->iretry = 3; /* 3 halt retries. */ |
| 215 | } |
| 216 | if (!(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) { |
| 217 | /* Stage 2: halt io. */ |
| 218 | if (cdev->private->iretry) { |
| 219 | cdev->private->iretry--; |
| 220 | ret = cio_halt(sch); |
Peter Oberparleiter | ba4ba8a | 2006-07-27 14:00:23 +0200 | [diff] [blame] | 221 | if (ret != -EBUSY) |
| 222 | return (ret == 0) ? -EBUSY : ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | /* halt io unsuccessful. */ |
| 225 | cdev->private->iretry = 255; /* 255 clear retries. */ |
| 226 | } |
| 227 | /* Stage 3: clear io. */ |
| 228 | if (cdev->private->iretry) { |
| 229 | cdev->private->iretry--; |
| 230 | ret = cio_clear (sch); |
| 231 | return (ret == 0) ? -EBUSY : ret; |
| 232 | } |
| 233 | panic("Can't stop i/o on subchannel.\n"); |
| 234 | } |
| 235 | |
| 236 | static int |
| 237 | ccw_device_handle_oper(struct ccw_device *cdev) |
| 238 | { |
| 239 | struct subchannel *sch; |
| 240 | |
| 241 | sch = to_subchannel(cdev->dev.parent); |
| 242 | cdev->private->flags.recog_done = 1; |
| 243 | /* |
| 244 | * Check if cu type and device type still match. If |
| 245 | * not, it is certainly another device and we have to |
Cornelia Huck | d7b5a4c | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 246 | * de- and re-register. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | */ |
| 248 | if (cdev->id.cu_type != cdev->private->senseid.cu_type || |
| 249 | cdev->id.cu_model != cdev->private->senseid.cu_model || |
| 250 | cdev->id.dev_type != cdev->private->senseid.dev_type || |
Cornelia Huck | d7b5a4c | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 251 | cdev->id.dev_model != cdev->private->senseid.dev_model) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 253 | ccw_device_do_unreg_rereg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | queue_work(ccw_device_work, &cdev->private->kick_work); |
| 255 | return 0; |
| 256 | } |
| 257 | cdev->private->flags.donotify = 1; |
| 258 | return 1; |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * The machine won't give us any notification by machine check if a chpid has |
| 263 | * been varied online on the SE so we have to find out by magic (i. e. driving |
| 264 | * the channel subsystem to device selection and updating our path masks). |
| 265 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 266 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | __recover_lost_chpids(struct subchannel *sch, int old_lpm) |
| 268 | { |
| 269 | int mask, i; |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 270 | struct chp_id chpid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 272 | chp_id_init(&chpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | for (i = 0; i<8; i++) { |
| 274 | mask = 0x80 >> i; |
| 275 | if (!(sch->lpm & mask)) |
| 276 | continue; |
| 277 | if (old_lpm & mask) |
| 278 | continue; |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 279 | chpid.id = sch->schib.pmcw.chpid[i]; |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 280 | if (!chp_is_registered(chpid)) |
| 281 | css_schedule_eval_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * Stop device recognition. |
| 287 | */ |
| 288 | static void |
| 289 | ccw_device_recog_done(struct ccw_device *cdev, int state) |
| 290 | { |
| 291 | struct subchannel *sch; |
| 292 | int notify, old_lpm, same_dev; |
| 293 | |
| 294 | sch = to_subchannel(cdev->dev.parent); |
| 295 | |
| 296 | ccw_device_set_timeout(cdev, 0); |
| 297 | cio_disable_subchannel(sch); |
| 298 | /* |
| 299 | * Now that we tried recognition, we have performed device selection |
| 300 | * through ssch() and the path information is up to date. |
| 301 | */ |
| 302 | old_lpm = sch->lpm; |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 303 | stsch(sch->schid, &sch->schib); |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 304 | sch->lpm = sch->schib.pmcw.pam & sch->opm; |
Cornelia Huck | 4ffa923 | 2005-07-29 14:03:37 -0700 | [diff] [blame] | 305 | /* Check since device may again have become not operational. */ |
| 306 | if (!sch->schib.pmcw.dnv) |
| 307 | state = DEV_STATE_NOT_OPER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) |
| 309 | /* Force reprobe on all chpids. */ |
| 310 | old_lpm = 0; |
| 311 | if (sch->lpm != old_lpm) |
| 312 | __recover_lost_chpids(sch, old_lpm); |
| 313 | if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) { |
| 314 | if (state == DEV_STATE_NOT_OPER) { |
| 315 | cdev->private->flags.recog_done = 1; |
| 316 | cdev->private->state = DEV_STATE_DISCONNECTED; |
| 317 | return; |
| 318 | } |
| 319 | /* Boxed devices don't need extra treatment. */ |
| 320 | } |
| 321 | notify = 0; |
| 322 | same_dev = 0; /* Keep the compiler quiet... */ |
| 323 | switch (state) { |
| 324 | case DEV_STATE_NOT_OPER: |
| 325 | CIO_DEBUG(KERN_WARNING, 2, |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 326 | "SenseID : unknown device %04x on subchannel " |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 327 | "0.%x.%04x\n", cdev->private->dev_id.devno, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 328 | sch->schid.ssid, sch->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | break; |
| 330 | case DEV_STATE_OFFLINE: |
| 331 | if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) { |
| 332 | same_dev = ccw_device_handle_oper(cdev); |
| 333 | notify = 1; |
| 334 | } |
| 335 | /* fill out sense information */ |
Heiko Carstens | 81388d2 | 2006-09-20 15:59:17 +0200 | [diff] [blame] | 336 | memset(&cdev->id, 0, sizeof(cdev->id)); |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 337 | cdev->id.cu_type = cdev->private->senseid.cu_type; |
| 338 | cdev->id.cu_model = cdev->private->senseid.cu_model; |
| 339 | cdev->id.dev_type = cdev->private->senseid.dev_type; |
| 340 | cdev->id.dev_model = cdev->private->senseid.dev_model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (notify) { |
| 342 | cdev->private->state = DEV_STATE_OFFLINE; |
| 343 | if (same_dev) { |
| 344 | /* Get device online again. */ |
| 345 | ccw_device_online(cdev); |
| 346 | wake_up(&cdev->private->wait_q); |
| 347 | } |
| 348 | return; |
| 349 | } |
| 350 | /* Issue device info message. */ |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 351 | CIO_DEBUG(KERN_INFO, 2, |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 352 | "SenseID : device 0.%x.%04x reports: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | "CU Type/Mod = %04X/%02X, Dev Type/Mod = " |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 354 | "%04X/%02X\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 355 | cdev->private->dev_id.ssid, |
| 356 | cdev->private->dev_id.devno, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | cdev->id.cu_type, cdev->id.cu_model, |
| 358 | cdev->id.dev_type, cdev->id.dev_model); |
| 359 | break; |
| 360 | case DEV_STATE_BOXED: |
| 361 | CIO_DEBUG(KERN_WARNING, 2, |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 362 | "SenseID : boxed device %04x on subchannel " |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 363 | "0.%x.%04x\n", cdev->private->dev_id.devno, |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 364 | sch->schid.ssid, sch->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | break; |
| 366 | } |
| 367 | cdev->private->state = state; |
| 368 | io_subchannel_recog_done(cdev); |
| 369 | if (state != DEV_STATE_NOT_OPER) |
| 370 | wake_up(&cdev->private->wait_q); |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Function called from device_id.c after sense id has completed. |
| 375 | */ |
| 376 | void |
| 377 | ccw_device_sense_id_done(struct ccw_device *cdev, int err) |
| 378 | { |
| 379 | switch (err) { |
| 380 | case 0: |
| 381 | ccw_device_recog_done(cdev, DEV_STATE_OFFLINE); |
| 382 | break; |
| 383 | case -ETIME: /* Sense id stopped by timeout. */ |
| 384 | ccw_device_recog_done(cdev, DEV_STATE_BOXED); |
| 385 | break; |
| 386 | default: |
| 387 | ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER); |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 393 | ccw_device_oper_notify(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 395 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | struct ccw_device *cdev; |
| 397 | struct subchannel *sch; |
| 398 | int ret; |
Cornelia Huck | ee04bbc | 2007-03-05 23:35:56 +0100 | [diff] [blame] | 399 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 401 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 402 | cdev = priv->cdev; |
Cornelia Huck | ee04bbc | 2007-03-05 23:35:56 +0100 | [diff] [blame] | 403 | spin_lock_irqsave(cdev->ccwlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | ee04bbc | 2007-03-05 23:35:56 +0100 | [diff] [blame] | 405 | if (sch->driver && sch->driver->notify) { |
| 406 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 407 | ret = sch->driver->notify(sch, CIO_OPER); |
Cornelia Huck | ee04bbc | 2007-03-05 23:35:56 +0100 | [diff] [blame] | 408 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 409 | } else |
| 410 | ret = 0; |
| 411 | if (ret) { |
| 412 | /* Reenable channel measurements, if needed. */ |
| 413 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 414 | cmf_reenable(cdev); |
| 415 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 416 | wake_up(&cdev->private->wait_q); |
| 417 | } |
| 418 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | if (!ret) |
| 420 | /* Driver doesn't want device back. */ |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 421 | ccw_device_do_unreg_rereg(work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* |
| 425 | * Finished with online/offline processing. |
| 426 | */ |
| 427 | static void |
| 428 | ccw_device_done(struct ccw_device *cdev, int state) |
| 429 | { |
| 430 | struct subchannel *sch; |
| 431 | |
| 432 | sch = to_subchannel(cdev->dev.parent); |
| 433 | |
Cornelia Huck | f1ee328 | 2006-10-04 20:02:02 +0200 | [diff] [blame] | 434 | ccw_device_set_timeout(cdev, 0); |
| 435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | if (state != DEV_STATE_ONLINE) |
| 437 | cio_disable_subchannel(sch); |
| 438 | |
| 439 | /* Reset device status. */ |
| 440 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 441 | |
| 442 | cdev->private->state = state; |
| 443 | |
| 444 | |
| 445 | if (state == DEV_STATE_BOXED) |
| 446 | CIO_DEBUG(KERN_WARNING, 2, |
Cornelia Huck | bc698bc | 2008-01-26 14:10:42 +0100 | [diff] [blame] | 447 | "Boxed device %04x on subchannel %04x\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 448 | cdev->private->dev_id.devno, sch->schid.sch_no); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | if (cdev->private->flags.donotify) { |
| 451 | cdev->private->flags.donotify = 0; |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 452 | PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | queue_work(ccw_device_notify_work, &cdev->private->kick_work); |
| 454 | } |
| 455 | wake_up(&cdev->private->wait_q); |
| 456 | |
| 457 | if (css_init_done && state != DEV_STATE_ONLINE) |
| 458 | put_device (&cdev->dev); |
| 459 | } |
| 460 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 461 | static int cmp_pgid(struct pgid *p1, struct pgid *p2) |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 462 | { |
| 463 | char *c1; |
| 464 | char *c2; |
| 465 | |
| 466 | c1 = (char *)p1; |
| 467 | c2 = (char *)p2; |
| 468 | |
| 469 | return memcmp(c1 + 1, c2 + 1, sizeof(struct pgid) - 1); |
| 470 | } |
| 471 | |
| 472 | static void __ccw_device_get_common_pgid(struct ccw_device *cdev) |
| 473 | { |
| 474 | int i; |
| 475 | int last; |
| 476 | |
| 477 | last = 0; |
| 478 | for (i = 0; i < 8; i++) { |
| 479 | if (cdev->private->pgid[i].inf.ps.state1 == SNID_STATE1_RESET) |
| 480 | /* No PGID yet */ |
| 481 | continue; |
| 482 | if (cdev->private->pgid[last].inf.ps.state1 == |
| 483 | SNID_STATE1_RESET) { |
| 484 | /* First non-zero PGID */ |
| 485 | last = i; |
| 486 | continue; |
| 487 | } |
| 488 | if (cmp_pgid(&cdev->private->pgid[i], |
| 489 | &cdev->private->pgid[last]) == 0) |
| 490 | /* Non-conflicting PGIDs */ |
| 491 | continue; |
| 492 | |
| 493 | /* PGID mismatch, can't pathgroup. */ |
| 494 | CIO_MSG_EVENT(0, "SNID - pgid mismatch for device " |
| 495 | "0.%x.%04x, can't pathgroup\n", |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 496 | cdev->private->dev_id.ssid, |
| 497 | cdev->private->dev_id.devno); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 498 | cdev->private->options.pgroup = 0; |
| 499 | return; |
| 500 | } |
| 501 | if (cdev->private->pgid[last].inf.ps.state1 == |
| 502 | SNID_STATE1_RESET) |
| 503 | /* No previous pgid found */ |
Cornelia Huck | 7c9f4e3 | 2007-10-12 16:11:13 +0200 | [diff] [blame] | 504 | memcpy(&cdev->private->pgid[0], |
| 505 | &channel_subsystems[0]->global_pgid, |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 506 | sizeof(struct pgid)); |
| 507 | else |
| 508 | /* Use existing pgid */ |
| 509 | memcpy(&cdev->private->pgid[0], &cdev->private->pgid[last], |
| 510 | sizeof(struct pgid)); |
| 511 | } |
| 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | /* |
| 514 | * Function called from device_pgid.c after sense path ground has completed. |
| 515 | */ |
| 516 | void |
| 517 | ccw_device_sense_pgid_done(struct ccw_device *cdev, int err) |
| 518 | { |
| 519 | struct subchannel *sch; |
| 520 | |
| 521 | sch = to_subchannel(cdev->dev.parent); |
| 522 | switch (err) { |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 523 | case -EOPNOTSUPP: /* path grouping not supported, use nop instead. */ |
| 524 | cdev->private->options.pgroup = 0; |
| 525 | break; |
| 526 | case 0: /* success */ |
| 527 | case -EACCES: /* partial success, some paths not operational */ |
| 528 | /* Check if all pgids are equal or 0. */ |
| 529 | __ccw_device_get_common_pgid(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | break; |
| 531 | case -ETIME: /* Sense path group id stopped by timeout. */ |
| 532 | case -EUSERS: /* device is reserved for someone else. */ |
| 533 | ccw_device_done(cdev, DEV_STATE_BOXED); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 534 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | default: |
| 536 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 537 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 539 | /* Start Path Group verification. */ |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 540 | cdev->private->state = DEV_STATE_VERIFY; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 541 | cdev->private->flags.doverify = 0; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 542 | ccw_device_verify_start(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /* |
| 546 | * Start device recognition. |
| 547 | */ |
| 548 | int |
| 549 | ccw_device_recognition(struct ccw_device *cdev) |
| 550 | { |
| 551 | struct subchannel *sch; |
| 552 | int ret; |
| 553 | |
| 554 | if ((cdev->private->state != DEV_STATE_NOT_OPER) && |
| 555 | (cdev->private->state != DEV_STATE_BOXED)) |
| 556 | return -EINVAL; |
| 557 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 558 | ret = cio_enable_subchannel(sch, (u32)(addr_t)sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | if (ret != 0) |
| 560 | /* Couldn't enable the subchannel for i/o. Sick device. */ |
| 561 | return ret; |
| 562 | |
| 563 | /* After 60s the device recognition is considered to have failed. */ |
| 564 | ccw_device_set_timeout(cdev, 60*HZ); |
| 565 | |
| 566 | /* |
| 567 | * We used to start here with a sense pgid to find out whether a device |
| 568 | * is locked by someone else. Unfortunately, the sense pgid command |
| 569 | * code has other meanings on devices predating the path grouping |
| 570 | * algorithm, so we start with sense id and box the device after an |
| 571 | * timeout (or if sense pgid during path verification detects the device |
| 572 | * is locked, as may happen on newer devices). |
| 573 | */ |
| 574 | cdev->private->flags.recog_done = 0; |
| 575 | cdev->private->state = DEV_STATE_SENSE_ID; |
| 576 | ccw_device_sense_id_start(cdev); |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | * Handle timeout in device recognition. |
| 582 | */ |
| 583 | static void |
| 584 | ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 585 | { |
| 586 | int ret; |
| 587 | |
| 588 | ret = ccw_device_cancel_halt_clear(cdev); |
| 589 | switch (ret) { |
| 590 | case 0: |
| 591 | ccw_device_recog_done(cdev, DEV_STATE_BOXED); |
| 592 | break; |
| 593 | case -ENODEV: |
| 594 | ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER); |
| 595 | break; |
| 596 | default: |
| 597 | ccw_device_set_timeout(cdev, 3*HZ); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | void |
| 603 | ccw_device_verify_done(struct ccw_device *cdev, int err) |
| 604 | { |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 605 | struct subchannel *sch; |
| 606 | |
| 607 | sch = to_subchannel(cdev->dev.parent); |
| 608 | /* Update schib - pom may have changed. */ |
| 609 | stsch(sch->schid, &sch->schib); |
| 610 | /* Update lpm with verified path mask. */ |
| 611 | sch->lpm = sch->vpm; |
| 612 | /* Repeat path verification? */ |
| 613 | if (cdev->private->flags.doverify) { |
| 614 | cdev->private->flags.doverify = 0; |
| 615 | ccw_device_verify_start(cdev); |
| 616 | return; |
| 617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | switch (err) { |
| 619 | case -EOPNOTSUPP: /* path grouping not supported, just set online. */ |
| 620 | cdev->private->options.pgroup = 0; |
| 621 | case 0: |
| 622 | ccw_device_done(cdev, DEV_STATE_ONLINE); |
| 623 | /* Deliver fake irb to device driver, if needed. */ |
| 624 | if (cdev->private->flags.fake_irb) { |
| 625 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 626 | cdev->private->irb.scsw.cc = 1; |
| 627 | cdev->private->irb.scsw.fctl = SCSW_FCTL_START_FUNC; |
| 628 | cdev->private->irb.scsw.actl = SCSW_ACTL_START_PEND; |
| 629 | cdev->private->irb.scsw.stctl = SCSW_STCTL_STATUS_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | cdev->private->flags.fake_irb = 0; |
| 631 | if (cdev->handler) |
| 632 | cdev->handler(cdev, cdev->private->intparm, |
| 633 | &cdev->private->irb); |
| 634 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 635 | } |
| 636 | break; |
| 637 | case -ETIME: |
Peter Oberparleiter | 8b42f5c | 2006-10-18 18:30:43 +0200 | [diff] [blame] | 638 | /* Reset oper notify indication after verify error. */ |
| 639 | cdev->private->flags.donotify = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | ccw_device_done(cdev, DEV_STATE_BOXED); |
| 641 | break; |
| 642 | default: |
Peter Oberparleiter | 8b42f5c | 2006-10-18 18:30:43 +0200 | [diff] [blame] | 643 | /* Reset oper notify indication after verify error. */ |
| 644 | cdev->private->flags.donotify = 0; |
Cornelia Huck | 46258ab | 2008-01-26 14:10:49 +0100 | [diff] [blame] | 645 | if (cdev->online) { |
| 646 | ccw_device_set_timeout(cdev, 0); |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 647 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
Cornelia Huck | 46258ab | 2008-01-26 14:10:49 +0100 | [diff] [blame] | 648 | } else |
Cornelia Huck | ee04bbc | 2007-03-05 23:35:56 +0100 | [diff] [blame] | 649 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | break; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /* |
| 655 | * Get device online. |
| 656 | */ |
| 657 | int |
| 658 | ccw_device_online(struct ccw_device *cdev) |
| 659 | { |
| 660 | struct subchannel *sch; |
| 661 | int ret; |
| 662 | |
| 663 | if ((cdev->private->state != DEV_STATE_OFFLINE) && |
| 664 | (cdev->private->state != DEV_STATE_BOXED)) |
| 665 | return -EINVAL; |
| 666 | sch = to_subchannel(cdev->dev.parent); |
| 667 | if (css_init_done && !get_device(&cdev->dev)) |
| 668 | return -ENODEV; |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 669 | ret = cio_enable_subchannel(sch, (u32)(addr_t)sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | if (ret != 0) { |
| 671 | /* Couldn't enable the subchannel for i/o. Sick device. */ |
| 672 | if (ret == -ENODEV) |
| 673 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 674 | return ret; |
| 675 | } |
| 676 | /* Do we want to do path grouping? */ |
| 677 | if (!cdev->private->options.pgroup) { |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 678 | /* Start initial path verification. */ |
| 679 | cdev->private->state = DEV_STATE_VERIFY; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 680 | cdev->private->flags.doverify = 0; |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 681 | ccw_device_verify_start(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | return 0; |
| 683 | } |
| 684 | /* Do a SensePGID first. */ |
| 685 | cdev->private->state = DEV_STATE_SENSE_PGID; |
| 686 | ccw_device_sense_pgid_start(cdev); |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | void |
| 691 | ccw_device_disband_done(struct ccw_device *cdev, int err) |
| 692 | { |
| 693 | switch (err) { |
| 694 | case 0: |
| 695 | ccw_device_done(cdev, DEV_STATE_OFFLINE); |
| 696 | break; |
| 697 | case -ETIME: |
| 698 | ccw_device_done(cdev, DEV_STATE_BOXED); |
| 699 | break; |
| 700 | default: |
Peter Oberparleiter | 3ecb0a5 | 2007-05-31 17:38:07 +0200 | [diff] [blame] | 701 | cdev->private->flags.donotify = 0; |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 702 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
| 704 | break; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | /* |
| 709 | * Shutdown device. |
| 710 | */ |
| 711 | int |
| 712 | ccw_device_offline(struct ccw_device *cdev) |
| 713 | { |
| 714 | struct subchannel *sch; |
| 715 | |
Cornelia Huck | d7b5a4c | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 716 | if (ccw_device_is_orphan(cdev)) { |
| 717 | ccw_device_done(cdev, DEV_STATE_OFFLINE); |
| 718 | return 0; |
| 719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 721 | if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | return -ENODEV; |
| 723 | if (cdev->private->state != DEV_STATE_ONLINE) { |
| 724 | if (sch->schib.scsw.actl != 0) |
| 725 | return -EBUSY; |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | if (sch->schib.scsw.actl != 0) |
| 729 | return -EBUSY; |
| 730 | /* Are we doing path grouping? */ |
| 731 | if (!cdev->private->options.pgroup) { |
| 732 | /* No, set state offline immediately. */ |
| 733 | ccw_device_done(cdev, DEV_STATE_OFFLINE); |
| 734 | return 0; |
| 735 | } |
| 736 | /* Start Set Path Group commands. */ |
| 737 | cdev->private->state = DEV_STATE_DISBAND_PGID; |
| 738 | ccw_device_disband_start(cdev); |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | /* |
| 743 | * Handle timeout in device online/offline process. |
| 744 | */ |
| 745 | static void |
| 746 | ccw_device_onoff_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 747 | { |
| 748 | int ret; |
| 749 | |
| 750 | ret = ccw_device_cancel_halt_clear(cdev); |
| 751 | switch (ret) { |
| 752 | case 0: |
| 753 | ccw_device_done(cdev, DEV_STATE_BOXED); |
| 754 | break; |
| 755 | case -ENODEV: |
| 756 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
| 757 | break; |
| 758 | default: |
| 759 | ccw_device_set_timeout(cdev, 3*HZ); |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | * Handle not oper event in device recognition. |
| 765 | */ |
| 766 | static void |
| 767 | ccw_device_recog_notoper(struct ccw_device *cdev, enum dev_event dev_event) |
| 768 | { |
| 769 | ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER); |
| 770 | } |
| 771 | |
| 772 | /* |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 773 | * Handle not operational event in non-special state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | */ |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 775 | static void ccw_device_generic_notoper(struct ccw_device *cdev, |
| 776 | enum dev_event dev_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
| 778 | struct subchannel *sch; |
| 779 | |
| 780 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 781 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 782 | css_schedule_eval(sch->schid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | /* |
| 786 | * Handle path verification event. |
| 787 | */ |
| 788 | static void |
| 789 | ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event) |
| 790 | { |
| 791 | struct subchannel *sch; |
| 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | if (cdev->private->state == DEV_STATE_W4SENSE) { |
| 794 | cdev->private->flags.doverify = 1; |
| 795 | return; |
| 796 | } |
| 797 | sch = to_subchannel(cdev->dev.parent); |
| 798 | /* |
| 799 | * Since we might not just be coming from an interrupt from the |
| 800 | * subchannel we have to update the schib. |
| 801 | */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 802 | stsch(sch->schid, &sch->schib); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | if (sch->schib.scsw.actl != 0 || |
Peter Oberparleiter | 65200c2 | 2006-08-07 17:00:33 +0200 | [diff] [blame] | 805 | (sch->schib.scsw.stctl & SCSW_STCTL_STATUS_PEND) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | (cdev->private->irb.scsw.stctl & SCSW_STCTL_STATUS_PEND)) { |
| 807 | /* |
| 808 | * No final status yet or final status not yet delivered |
| 809 | * to the device driver. Can't do path verfication now, |
| 810 | * delay until final status was delivered. |
| 811 | */ |
| 812 | cdev->private->flags.doverify = 1; |
| 813 | return; |
| 814 | } |
| 815 | /* Device is idle, we can do the path verification. */ |
| 816 | cdev->private->state = DEV_STATE_VERIFY; |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 817 | cdev->private->flags.doverify = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | ccw_device_verify_start(cdev); |
| 819 | } |
| 820 | |
| 821 | /* |
| 822 | * Got an interrupt for a normal io (state online). |
| 823 | */ |
| 824 | static void |
| 825 | ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 826 | { |
| 827 | struct irb *irb; |
| 828 | |
| 829 | irb = (struct irb *) __LC_IRB; |
| 830 | /* Check for unsolicited interrupt. */ |
| 831 | if ((irb->scsw.stctl == |
| 832 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) |
| 833 | && (!irb->scsw.cc)) { |
| 834 | if ((irb->scsw.dstat & DEV_STAT_UNIT_CHECK) && |
| 835 | !irb->esw.esw0.erw.cons) { |
| 836 | /* Unit check but no sense data. Need basic sense. */ |
| 837 | if (ccw_device_do_sense(cdev, irb) != 0) |
| 838 | goto call_handler_unsol; |
Cornelia Huck | e0ec574 | 2006-06-04 02:51:27 -0700 | [diff] [blame] | 839 | memcpy(&cdev->private->irb, irb, sizeof(struct irb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | cdev->private->state = DEV_STATE_W4SENSE; |
| 841 | cdev->private->intparm = 0; |
| 842 | return; |
| 843 | } |
| 844 | call_handler_unsol: |
| 845 | if (cdev->handler) |
| 846 | cdev->handler (cdev, 0, irb); |
Cornelia Huck | 18374d3 | 2007-02-05 21:17:09 +0100 | [diff] [blame] | 847 | if (cdev->private->flags.doverify) |
| 848 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | return; |
| 850 | } |
| 851 | /* Accumulate status and find out if a basic sense is needed. */ |
| 852 | ccw_device_accumulate_irb(cdev, irb); |
| 853 | if (cdev->private->flags.dosense) { |
| 854 | if (ccw_device_do_sense(cdev, irb) == 0) { |
| 855 | cdev->private->state = DEV_STATE_W4SENSE; |
| 856 | } |
| 857 | return; |
| 858 | } |
| 859 | /* Call the handler. */ |
| 860 | if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify) |
| 861 | /* Start delayed path verification. */ |
| 862 | ccw_device_online_verify(cdev, 0); |
| 863 | } |
| 864 | |
| 865 | /* |
| 866 | * Got an timeout in online state. |
| 867 | */ |
| 868 | static void |
| 869 | ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 870 | { |
| 871 | int ret; |
| 872 | |
| 873 | ccw_device_set_timeout(cdev, 0); |
| 874 | ret = ccw_device_cancel_halt_clear(cdev); |
| 875 | if (ret == -EBUSY) { |
| 876 | ccw_device_set_timeout(cdev, 3*HZ); |
| 877 | cdev->private->state = DEV_STATE_TIMEOUT_KILL; |
| 878 | return; |
| 879 | } |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 880 | if (ret == -ENODEV) |
| 881 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 882 | else if (cdev->handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | cdev->handler(cdev, cdev->private->intparm, |
| 884 | ERR_PTR(-ETIMEDOUT)); |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | * Got an interrupt for a basic sense. |
| 889 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 890 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event) |
| 892 | { |
| 893 | struct irb *irb; |
| 894 | |
| 895 | irb = (struct irb *) __LC_IRB; |
| 896 | /* Check for unsolicited interrupt. */ |
| 897 | if (irb->scsw.stctl == |
| 898 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { |
| 899 | if (irb->scsw.cc == 1) |
| 900 | /* Basic sense hasn't started. Try again. */ |
| 901 | ccw_device_do_sense(cdev, irb); |
| 902 | else { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 903 | CIO_MSG_EVENT(2, "Huh? 0.%x.%04x: unsolicited " |
| 904 | "interrupt during w4sense...\n", |
| 905 | cdev->private->dev_id.ssid, |
| 906 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | if (cdev->handler) |
| 908 | cdev->handler (cdev, 0, irb); |
| 909 | } |
| 910 | return; |
| 911 | } |
Cornelia Huck | 3ba1998 | 2006-03-24 03:15:12 -0800 | [diff] [blame] | 912 | /* |
| 913 | * Check if a halt or clear has been issued in the meanwhile. If yes, |
| 914 | * only deliver the halt/clear interrupt to the device driver as if it |
| 915 | * had killed the original request. |
| 916 | */ |
| 917 | if (irb->scsw.fctl & (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) { |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame] | 918 | /* Retry Basic Sense if requested. */ |
| 919 | if (cdev->private->flags.intretry) { |
| 920 | cdev->private->flags.intretry = 0; |
| 921 | ccw_device_do_sense(cdev, irb); |
| 922 | return; |
| 923 | } |
Cornelia Huck | 3ba1998 | 2006-03-24 03:15:12 -0800 | [diff] [blame] | 924 | cdev->private->flags.dosense = 0; |
| 925 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 926 | ccw_device_accumulate_irb(cdev, irb); |
| 927 | goto call_handler; |
| 928 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | /* Add basic sense info to irb. */ |
| 930 | ccw_device_accumulate_basic_sense(cdev, irb); |
| 931 | if (cdev->private->flags.dosense) { |
| 932 | /* Another basic sense is needed. */ |
| 933 | ccw_device_do_sense(cdev, irb); |
| 934 | return; |
| 935 | } |
Cornelia Huck | 3ba1998 | 2006-03-24 03:15:12 -0800 | [diff] [blame] | 936 | call_handler: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | cdev->private->state = DEV_STATE_ONLINE; |
| 938 | /* Call the handler. */ |
| 939 | if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify) |
| 940 | /* Start delayed path verification. */ |
| 941 | ccw_device_online_verify(cdev, 0); |
| 942 | } |
| 943 | |
| 944 | static void |
| 945 | ccw_device_clear_verify(struct ccw_device *cdev, enum dev_event dev_event) |
| 946 | { |
| 947 | struct irb *irb; |
| 948 | |
| 949 | irb = (struct irb *) __LC_IRB; |
| 950 | /* Accumulate status. We don't do basic sense. */ |
| 951 | ccw_device_accumulate_irb(cdev, irb); |
Cornelia Huck | b4f7b1e | 2006-06-29 15:03:35 +0200 | [diff] [blame] | 952 | /* Remember to clear irb to avoid residuals. */ |
| 953 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | /* Try to start delayed device verification. */ |
| 955 | ccw_device_online_verify(cdev, 0); |
| 956 | /* Note: Don't call handler for cio initiated clear! */ |
| 957 | } |
| 958 | |
| 959 | static void |
| 960 | ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 961 | { |
| 962 | struct subchannel *sch; |
| 963 | |
| 964 | sch = to_subchannel(cdev->dev.parent); |
| 965 | ccw_device_set_timeout(cdev, 0); |
Cornelia Huck | 7c8427c | 2007-03-05 23:35:59 +0100 | [diff] [blame] | 966 | /* Start delayed path verification. */ |
| 967 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | /* OK, i/o is dead now. Call interrupt handler. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | if (cdev->handler) |
| 970 | cdev->handler(cdev, cdev->private->intparm, |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 971 | ERR_PTR(-EIO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | static void |
| 975 | ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 976 | { |
| 977 | int ret; |
| 978 | |
| 979 | ret = ccw_device_cancel_halt_clear(cdev); |
| 980 | if (ret == -EBUSY) { |
| 981 | ccw_device_set_timeout(cdev, 3*HZ); |
| 982 | return; |
| 983 | } |
Cornelia Huck | 7c8427c | 2007-03-05 23:35:59 +0100 | [diff] [blame] | 984 | /* Start delayed path verification. */ |
| 985 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | if (cdev->handler) |
| 987 | cdev->handler(cdev, cdev->private->intparm, |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 988 | ERR_PTR(-EIO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
| 990 | |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 991 | void device_kill_io(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | { |
| 993 | int ret; |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 994 | struct ccw_device *cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 996 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | ret = ccw_device_cancel_halt_clear(cdev); |
| 998 | if (ret == -EBUSY) { |
| 999 | ccw_device_set_timeout(cdev, 3*HZ); |
| 1000 | cdev->private->state = DEV_STATE_TIMEOUT_KILL; |
| 1001 | return; |
| 1002 | } |
Cornelia Huck | 7c8427c | 2007-03-05 23:35:59 +0100 | [diff] [blame] | 1003 | /* Start delayed path verification. */ |
| 1004 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | if (cdev->handler) |
| 1006 | cdev->handler(cdev, cdev->private->intparm, |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 1007 | ERR_PTR(-EIO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | static void |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 1011 | ccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | { |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 1013 | /* Start verification after current task finished. */ |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 1014 | cdev->private->flags.doverify = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static void |
| 1018 | ccw_device_stlck_done(struct ccw_device *cdev, enum dev_event dev_event) |
| 1019 | { |
| 1020 | struct irb *irb; |
| 1021 | |
| 1022 | switch (dev_event) { |
| 1023 | case DEV_EVENT_INTERRUPT: |
| 1024 | irb = (struct irb *) __LC_IRB; |
| 1025 | /* Check for unsolicited interrupt. */ |
| 1026 | if ((irb->scsw.stctl == |
| 1027 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) && |
| 1028 | (!irb->scsw.cc)) |
| 1029 | /* FIXME: we should restart stlck here, but this |
| 1030 | * is extremely unlikely ... */ |
| 1031 | goto out_wakeup; |
| 1032 | |
| 1033 | ccw_device_accumulate_irb(cdev, irb); |
| 1034 | /* We don't care about basic sense etc. */ |
| 1035 | break; |
| 1036 | default: /* timeout */ |
| 1037 | break; |
| 1038 | } |
| 1039 | out_wakeup: |
| 1040 | wake_up(&cdev->private->wait_q); |
| 1041 | } |
| 1042 | |
| 1043 | static void |
| 1044 | ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event) |
| 1045 | { |
| 1046 | struct subchannel *sch; |
| 1047 | |
| 1048 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 1049 | if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | /* Couldn't enable the subchannel for i/o. Sick device. */ |
| 1051 | return; |
| 1052 | |
| 1053 | /* After 60s the device recognition is considered to have failed. */ |
| 1054 | ccw_device_set_timeout(cdev, 60*HZ); |
| 1055 | |
| 1056 | cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID; |
| 1057 | ccw_device_sense_id_start(cdev); |
| 1058 | } |
| 1059 | |
| 1060 | void |
| 1061 | device_trigger_reprobe(struct subchannel *sch) |
| 1062 | { |
| 1063 | struct ccw_device *cdev; |
| 1064 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1065 | cdev = sch_get_cdev(sch); |
| 1066 | if (!cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | if (cdev->private->state != DEV_STATE_DISCONNECTED) |
| 1069 | return; |
| 1070 | |
| 1071 | /* Update some values. */ |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1072 | if (stsch(sch->schid, &sch->schib)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | return; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 1074 | if (!sch->schib.pmcw.dnv) |
| 1075 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | /* |
| 1077 | * The pim, pam, pom values may not be accurate, but they are the best |
| 1078 | * we have before performing device selection :/ |
| 1079 | */ |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 1080 | sch->lpm = sch->schib.pmcw.pam & sch->opm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | /* Re-set some bits in the pmcw that were lost. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | sch->schib.pmcw.csense = 1; |
| 1083 | sch->schib.pmcw.ena = 0; |
| 1084 | if ((sch->lpm & (sch->lpm - 1)) != 0) |
| 1085 | sch->schib.pmcw.mp = 1; |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1086 | sch->schib.pmcw.intparm = (u32)(addr_t)sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | /* We should also udate ssd info, but this has to wait. */ |
Cornelia Huck | d7b5a4c | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1088 | /* Check if this is another device which appeared on the same sch. */ |
| 1089 | if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { |
| 1090 | PREPARE_WORK(&cdev->private->kick_work, |
| 1091 | ccw_device_move_to_orphanage); |
Cornelia Huck | c5d4a99 | 2007-11-20 11:13:41 +0100 | [diff] [blame] | 1092 | queue_work(slow_path_wq, &cdev->private->kick_work); |
Cornelia Huck | d7b5a4c | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1093 | } else |
| 1094 | ccw_device_start_id(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | static void |
| 1098 | ccw_device_offline_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 1099 | { |
| 1100 | struct subchannel *sch; |
| 1101 | |
| 1102 | sch = to_subchannel(cdev->dev.parent); |
| 1103 | /* |
| 1104 | * An interrupt in state offline means a previous disable was not |
| 1105 | * successful. Try again. |
| 1106 | */ |
| 1107 | cio_disable_subchannel(sch); |
| 1108 | } |
| 1109 | |
| 1110 | static void |
| 1111 | ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event) |
| 1112 | { |
| 1113 | retry_set_schib(cdev); |
| 1114 | cdev->private->state = DEV_STATE_ONLINE; |
| 1115 | dev_fsm_event(cdev, dev_event); |
| 1116 | } |
| 1117 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1118 | static void ccw_device_update_cmfblock(struct ccw_device *cdev, |
| 1119 | enum dev_event dev_event) |
| 1120 | { |
| 1121 | cmf_retry_copy_block(cdev); |
| 1122 | cdev->private->state = DEV_STATE_ONLINE; |
| 1123 | dev_fsm_event(cdev, dev_event); |
| 1124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
| 1126 | static void |
| 1127 | ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event) |
| 1128 | { |
| 1129 | ccw_device_set_timeout(cdev, 0); |
| 1130 | if (dev_event == DEV_EVENT_NOTOPER) |
| 1131 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1132 | else |
| 1133 | cdev->private->state = DEV_STATE_OFFLINE; |
| 1134 | wake_up(&cdev->private->wait_q); |
| 1135 | } |
| 1136 | |
| 1137 | static void |
| 1138 | ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 1139 | { |
| 1140 | int ret; |
| 1141 | |
| 1142 | ret = ccw_device_cancel_halt_clear(cdev); |
| 1143 | switch (ret) { |
| 1144 | case 0: |
| 1145 | cdev->private->state = DEV_STATE_OFFLINE; |
| 1146 | wake_up(&cdev->private->wait_q); |
| 1147 | break; |
| 1148 | case -ENODEV: |
| 1149 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1150 | wake_up(&cdev->private->wait_q); |
| 1151 | break; |
| 1152 | default: |
| 1153 | ccw_device_set_timeout(cdev, HZ/10); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | /* |
| 1158 | * No operation action. This is used e.g. to ignore a timeout event in |
| 1159 | * state offline. |
| 1160 | */ |
| 1161 | static void |
| 1162 | ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event) |
| 1163 | { |
| 1164 | } |
| 1165 | |
| 1166 | /* |
| 1167 | * Bug operation action. |
| 1168 | */ |
| 1169 | static void |
| 1170 | ccw_device_bug(struct ccw_device *cdev, enum dev_event dev_event) |
| 1171 | { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 1172 | CIO_MSG_EVENT(0, "dev_jumptable[%i][%i] == NULL\n", |
| 1173 | cdev->private->state, dev_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | BUG(); |
| 1175 | } |
| 1176 | |
| 1177 | /* |
| 1178 | * device statemachine |
| 1179 | */ |
| 1180 | fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = { |
| 1181 | [DEV_STATE_NOT_OPER] = { |
| 1182 | [DEV_EVENT_NOTOPER] = ccw_device_nop, |
| 1183 | [DEV_EVENT_INTERRUPT] = ccw_device_bug, |
| 1184 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
| 1185 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1186 | }, |
| 1187 | [DEV_STATE_SENSE_PGID] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1188 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | [DEV_EVENT_INTERRUPT] = ccw_device_sense_pgid_irq, |
| 1190 | [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout, |
| 1191 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1192 | }, |
| 1193 | [DEV_STATE_SENSE_ID] = { |
| 1194 | [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper, |
| 1195 | [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq, |
| 1196 | [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout, |
| 1197 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1198 | }, |
| 1199 | [DEV_STATE_OFFLINE] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1200 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | [DEV_EVENT_INTERRUPT] = ccw_device_offline_irq, |
| 1202 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
| 1203 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1204 | }, |
| 1205 | [DEV_STATE_VERIFY] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1206 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | [DEV_EVENT_INTERRUPT] = ccw_device_verify_irq, |
| 1208 | [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout, |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 1209 | [DEV_EVENT_VERIFY] = ccw_device_delay_verify, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | }, |
| 1211 | [DEV_STATE_ONLINE] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1212 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | [DEV_EVENT_INTERRUPT] = ccw_device_irq, |
| 1214 | [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout, |
| 1215 | [DEV_EVENT_VERIFY] = ccw_device_online_verify, |
| 1216 | }, |
| 1217 | [DEV_STATE_W4SENSE] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1218 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | [DEV_EVENT_INTERRUPT] = ccw_device_w4sense, |
| 1220 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
| 1221 | [DEV_EVENT_VERIFY] = ccw_device_online_verify, |
| 1222 | }, |
| 1223 | [DEV_STATE_DISBAND_PGID] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1224 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | [DEV_EVENT_INTERRUPT] = ccw_device_disband_irq, |
| 1226 | [DEV_EVENT_TIMEOUT] = ccw_device_onoff_timeout, |
| 1227 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1228 | }, |
| 1229 | [DEV_STATE_BOXED] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1230 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | [DEV_EVENT_INTERRUPT] = ccw_device_stlck_done, |
| 1232 | [DEV_EVENT_TIMEOUT] = ccw_device_stlck_done, |
| 1233 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1234 | }, |
| 1235 | /* states to wait for i/o completion before doing something */ |
| 1236 | [DEV_STATE_CLEAR_VERIFY] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1237 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | [DEV_EVENT_INTERRUPT] = ccw_device_clear_verify, |
| 1239 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
| 1240 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1241 | }, |
| 1242 | [DEV_STATE_TIMEOUT_KILL] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1243 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq, |
| 1245 | [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout, |
| 1246 | [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME |
| 1247 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | [DEV_STATE_QUIESCE] = { |
| 1249 | [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done, |
| 1250 | [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done, |
| 1251 | [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout, |
| 1252 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1253 | }, |
| 1254 | /* special states for devices gone not operational */ |
| 1255 | [DEV_STATE_DISCONNECTED] = { |
| 1256 | [DEV_EVENT_NOTOPER] = ccw_device_nop, |
| 1257 | [DEV_EVENT_INTERRUPT] = ccw_device_start_id, |
| 1258 | [DEV_EVENT_TIMEOUT] = ccw_device_bug, |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 1259 | [DEV_EVENT_VERIFY] = ccw_device_start_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | }, |
| 1261 | [DEV_STATE_DISCONNECTED_SENSE_ID] = { |
| 1262 | [DEV_EVENT_NOTOPER] = ccw_device_recog_notoper, |
| 1263 | [DEV_EVENT_INTERRUPT] = ccw_device_sense_id_irq, |
| 1264 | [DEV_EVENT_TIMEOUT] = ccw_device_recog_timeout, |
| 1265 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1266 | }, |
| 1267 | [DEV_STATE_CMFCHANGE] = { |
| 1268 | [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate, |
| 1269 | [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate, |
| 1270 | [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate, |
| 1271 | [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate, |
| 1272 | }, |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1273 | [DEV_STATE_CMFUPDATE] = { |
| 1274 | [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock, |
| 1275 | [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock, |
| 1276 | [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock, |
| 1277 | [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock, |
| 1278 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | }; |
| 1280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | EXPORT_SYMBOL_GPL(ccw_device_set_timeout); |