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