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