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