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