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