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