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