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); |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 55 | printk(KERN_WARNING "cio: ccw device bus id: %s\n", |
| 56 | dev_name(&cdev->dev)); |
| 57 | printk(KERN_WARNING "cio: subchannel bus id: %s\n", |
| 58 | dev_name(&sch->dev)); |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 59 | printk(KERN_WARNING "cio: subchannel lpm: %02x, opm: %02x, " |
| 60 | "vpm: %02x\n", sch->lpm, sch->opm, sch->vpm); |
| 61 | |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 62 | if (orb->tm.b) { |
| 63 | printk(KERN_WARNING "cio: orb indicates transport mode\n"); |
| 64 | printk(KERN_WARNING "cio: last tcw:\n"); |
| 65 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
| 66 | (void *)(addr_t)orb->tm.tcw, |
| 67 | sizeof(struct tcw), 0); |
| 68 | } else { |
| 69 | printk(KERN_WARNING "cio: orb indicates command mode\n"); |
| 70 | if ((void *)(addr_t)orb->cmd.cpa == &private->sense_ccw || |
| 71 | (void *)(addr_t)orb->cmd.cpa == cdev->private->iccws) |
| 72 | printk(KERN_WARNING "cio: last channel program " |
| 73 | "(intern):\n"); |
| 74 | else |
| 75 | printk(KERN_WARNING "cio: last channel program:\n"); |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 76 | |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 77 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
| 78 | (void *)(addr_t)orb->cmd.cpa, |
| 79 | sizeof(struct ccw1), 0); |
| 80 | } |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 81 | printk(KERN_WARNING "cio: ccw device state: %d\n", |
| 82 | cdev->private->state); |
| 83 | printk(KERN_WARNING "cio: store subchannel returned: cc=%d\n", cc); |
| 84 | printk(KERN_WARNING "cio: schib:\n"); |
| 85 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
| 86 | &schib, sizeof(schib), 0); |
| 87 | printk(KERN_WARNING "cio: ccw device flags:\n"); |
| 88 | print_hex_dump(KERN_WARNING, "cio: ", DUMP_PREFIX_NONE, 16, 1, |
| 89 | &cdev->private->flags, sizeof(cdev->private->flags), 0); |
| 90 | } |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* |
| 93 | * Timeout function. It just triggers a DEV_EVENT_TIMEOUT. |
| 94 | */ |
| 95 | static void |
| 96 | ccw_device_timeout(unsigned long data) |
| 97 | { |
| 98 | struct ccw_device *cdev; |
| 99 | |
| 100 | cdev = (struct ccw_device *) data; |
| 101 | spin_lock_irq(cdev->ccwlock); |
Sebastian Ott | 14ff56b | 2008-01-26 14:10:37 +0100 | [diff] [blame] | 102 | if (timeout_log_enabled) |
| 103 | ccw_timeout_log(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | dev_fsm_event(cdev, DEV_EVENT_TIMEOUT); |
| 105 | spin_unlock_irq(cdev->ccwlock); |
| 106 | } |
| 107 | |
| 108 | /* |
| 109 | * Set timeout |
| 110 | */ |
| 111 | void |
| 112 | ccw_device_set_timeout(struct ccw_device *cdev, int expires) |
| 113 | { |
| 114 | if (expires == 0) { |
| 115 | del_timer(&cdev->private->timer); |
| 116 | return; |
| 117 | } |
| 118 | if (timer_pending(&cdev->private->timer)) { |
| 119 | if (mod_timer(&cdev->private->timer, jiffies + expires)) |
| 120 | return; |
| 121 | } |
| 122 | cdev->private->timer.function = ccw_device_timeout; |
| 123 | cdev->private->timer.data = (unsigned long) cdev; |
| 124 | cdev->private->timer.expires = jiffies + expires; |
| 125 | add_timer(&cdev->private->timer); |
| 126 | } |
| 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* |
| 129 | * Cancel running i/o. This is called repeatedly since halt/clear are |
| 130 | * asynchronous operations. We do one try with cio_cancel, two tries |
| 131 | * with cio_halt, 255 tries with cio_clear. If everythings fails panic. |
| 132 | * Returns 0 if device now idle, -ENODEV for device not operational and |
| 133 | * -EBUSY if an interrupt is expected (either from halt/clear or from a |
| 134 | * status pending). |
| 135 | */ |
| 136 | int |
| 137 | ccw_device_cancel_halt_clear(struct ccw_device *cdev) |
| 138 | { |
| 139 | struct subchannel *sch; |
| 140 | int ret; |
| 141 | |
| 142 | sch = to_subchannel(cdev->dev.parent); |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 143 | if (cio_update_schib(sch)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return -ENODEV; |
Cornelia Huck | 2470b64 | 2007-03-05 23:36:02 +0100 | [diff] [blame] | 145 | if (!sch->schib.pmcw.ena) |
| 146 | /* Not operational -> done. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | return 0; |
| 148 | /* Stage 1: cancel io. */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 149 | if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_HALT_PEND) && |
| 150 | !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) { |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 151 | if (!scsw_is_tm(&sch->schib.scsw)) { |
| 152 | ret = cio_cancel(sch); |
| 153 | if (ret != -EINVAL) |
| 154 | return ret; |
| 155 | } |
| 156 | /* cancel io unsuccessful or not applicable (transport mode). |
| 157 | * Continue with asynchronous instructions. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | cdev->private->iretry = 3; /* 3 halt retries. */ |
| 159 | } |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 160 | if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | /* Stage 2: halt io. */ |
| 162 | if (cdev->private->iretry) { |
| 163 | cdev->private->iretry--; |
| 164 | ret = cio_halt(sch); |
Peter Oberparleiter | ba4ba8a | 2006-07-27 14:00:23 +0200 | [diff] [blame] | 165 | if (ret != -EBUSY) |
| 166 | return (ret == 0) ? -EBUSY : ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | /* halt io unsuccessful. */ |
| 169 | cdev->private->iretry = 255; /* 255 clear retries. */ |
| 170 | } |
| 171 | /* Stage 3: clear io. */ |
| 172 | if (cdev->private->iretry) { |
| 173 | cdev->private->iretry--; |
| 174 | ret = cio_clear (sch); |
| 175 | return (ret == 0) ? -EBUSY : ret; |
| 176 | } |
| 177 | panic("Can't stop i/o on subchannel.\n"); |
| 178 | } |
| 179 | |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 180 | void ccw_device_update_sense_data(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 182 | memset(&cdev->id, 0, sizeof(cdev->id)); |
| 183 | cdev->id.cu_type = cdev->private->senseid.cu_type; |
| 184 | cdev->id.cu_model = cdev->private->senseid.cu_model; |
| 185 | cdev->id.dev_type = cdev->private->senseid.dev_type; |
| 186 | cdev->id.dev_model = cdev->private->senseid.dev_model; |
| 187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 189 | int ccw_device_test_sense_data(struct ccw_device *cdev) |
| 190 | { |
| 191 | return 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 && |
| 194 | cdev->id.dev_model == cdev->private->senseid.dev_model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * The machine won't give us any notification by machine check if a chpid has |
| 199 | * been varied online on the SE so we have to find out by magic (i. e. driving |
| 200 | * the channel subsystem to device selection and updating our path masks). |
| 201 | */ |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 202 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | __recover_lost_chpids(struct subchannel *sch, int old_lpm) |
| 204 | { |
| 205 | int mask, i; |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 206 | struct chp_id chpid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 208 | chp_id_init(&chpid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | for (i = 0; i<8; i++) { |
| 210 | mask = 0x80 >> i; |
| 211 | if (!(sch->lpm & mask)) |
| 212 | continue; |
| 213 | if (old_lpm & mask) |
| 214 | continue; |
Peter Oberparleiter | f86635f | 2007-04-27 16:01:26 +0200 | [diff] [blame] | 215 | chpid.id = sch->schib.pmcw.chpid[i]; |
Peter Oberparleiter | 83b3370 | 2007-04-27 16:01:34 +0200 | [diff] [blame] | 216 | if (!chp_is_registered(chpid)) |
| 217 | css_schedule_eval_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * Stop device recognition. |
| 223 | */ |
| 224 | static void |
| 225 | ccw_device_recog_done(struct ccw_device *cdev, int state) |
| 226 | { |
| 227 | struct subchannel *sch; |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 228 | int old_lpm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | sch = to_subchannel(cdev->dev.parent); |
| 231 | |
Sebastian Ott | ec64333 | 2009-12-07 12:51:36 +0100 | [diff] [blame] | 232 | if (cio_disable_subchannel(sch)) |
| 233 | state = DEV_STATE_NOT_OPER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /* |
| 235 | * Now that we tried recognition, we have performed device selection |
| 236 | * through ssch() and the path information is up to date. |
| 237 | */ |
| 238 | old_lpm = sch->lpm; |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 239 | |
Cornelia Huck | 4ffa923 | 2005-07-29 14:03:37 -0700 | [diff] [blame] | 240 | /* Check since device may again have become not operational. */ |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 241 | if (cio_update_schib(sch)) |
Cornelia Huck | 4ffa923 | 2005-07-29 14:03:37 -0700 | [diff] [blame] | 242 | state = DEV_STATE_NOT_OPER; |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 243 | else |
| 244 | sch->lpm = sch->schib.pmcw.pam & sch->opm; |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) |
| 247 | /* Force reprobe on all chpids. */ |
| 248 | old_lpm = 0; |
| 249 | if (sch->lpm != old_lpm) |
| 250 | __recover_lost_chpids(sch, old_lpm); |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 251 | if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID && |
| 252 | (state == DEV_STATE_NOT_OPER || state == DEV_STATE_BOXED)) { |
| 253 | cdev->private->flags.recog_done = 1; |
| 254 | cdev->private->state = DEV_STATE_DISCONNECTED; |
| 255 | wake_up(&cdev->private->wait_q); |
| 256 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 258 | if (cdev->private->flags.resuming) { |
| 259 | cdev->private->state = state; |
| 260 | cdev->private->flags.recog_done = 1; |
| 261 | wake_up(&cdev->private->wait_q); |
| 262 | return; |
| 263 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | switch (state) { |
| 265 | case DEV_STATE_NOT_OPER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | break; |
| 267 | case DEV_STATE_OFFLINE: |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 268 | if (!cdev->online) { |
| 269 | ccw_device_update_sense_data(cdev); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 270 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 272 | cdev->private->state = DEV_STATE_OFFLINE; |
| 273 | cdev->private->flags.recog_done = 1; |
| 274 | if (ccw_device_test_sense_data(cdev)) { |
| 275 | cdev->private->flags.donotify = 1; |
| 276 | ccw_device_online(cdev); |
| 277 | wake_up(&cdev->private->wait_q); |
| 278 | } else { |
| 279 | ccw_device_update_sense_data(cdev); |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 280 | ccw_device_sched_todo(cdev, CDEV_TODO_REBIND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 282 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | case DEV_STATE_BOXED: |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 284 | if (cdev->id.cu_type != 0) { /* device was recognized before */ |
| 285 | cdev->private->flags.recog_done = 1; |
| 286 | cdev->private->state = DEV_STATE_BOXED; |
| 287 | wake_up(&cdev->private->wait_q); |
| 288 | return; |
| 289 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | break; |
| 291 | } |
| 292 | cdev->private->state = state; |
| 293 | io_subchannel_recog_done(cdev); |
Sebastian Ott | 156013f | 2009-03-31 19:16:03 +0200 | [diff] [blame] | 294 | wake_up(&cdev->private->wait_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Function called from device_id.c after sense id has completed. |
| 299 | */ |
| 300 | void |
| 301 | ccw_device_sense_id_done(struct ccw_device *cdev, int err) |
| 302 | { |
| 303 | switch (err) { |
| 304 | case 0: |
| 305 | ccw_device_recog_done(cdev, DEV_STATE_OFFLINE); |
| 306 | break; |
| 307 | case -ETIME: /* Sense id stopped by timeout. */ |
| 308 | ccw_device_recog_done(cdev, DEV_STATE_BOXED); |
| 309 | break; |
| 310 | default: |
| 311 | ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER); |
| 312 | break; |
| 313 | } |
| 314 | } |
| 315 | |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 316 | /** |
| 317 | * ccw_device_notify() - inform the device's driver about an event |
| 318 | * @cdev: device for which an event occured |
| 319 | * @event: event that occurred |
| 320 | * |
| 321 | * Returns: |
| 322 | * -%EINVAL if the device is offline or has no driver. |
| 323 | * -%EOPNOTSUPP if the device's driver has no notifier registered. |
| 324 | * %NOTIFY_OK if the driver wants to keep the device. |
| 325 | * %NOTIFY_BAD if the driver doesn't want to keep the device. |
| 326 | */ |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 327 | int ccw_device_notify(struct ccw_device *cdev, int event) |
| 328 | { |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 329 | int ret = -EINVAL; |
| 330 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 331 | if (!cdev->drv) |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 332 | goto out; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 333 | if (!cdev->online) |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 334 | goto out; |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 335 | CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n", |
| 336 | cdev->private->dev_id.ssid, cdev->private->dev_id.devno, |
| 337 | event); |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 338 | if (!cdev->drv->notify) { |
| 339 | ret = -EOPNOTSUPP; |
| 340 | goto out; |
| 341 | } |
| 342 | if (cdev->drv->notify(cdev, event)) |
| 343 | ret = NOTIFY_OK; |
| 344 | else |
| 345 | ret = NOTIFY_BAD; |
| 346 | out: |
| 347 | return ret; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 350 | static void ccw_device_oper_notify(struct ccw_device *cdev) |
| 351 | { |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 352 | if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_OK) { |
Cornelia Huck | ee04bbc | 2007-03-05 23:35:56 +0100 | [diff] [blame] | 353 | /* Reenable channel measurements, if needed. */ |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 354 | ccw_device_sched_todo(cdev, CDEV_TODO_ENABLE_CMF); |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | /* Driver doesn't want device back. */ |
| 358 | ccw_device_set_notoper(cdev); |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 359 | ccw_device_sched_todo(cdev, CDEV_TODO_REBIND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Finished with online/offline processing. |
| 364 | */ |
| 365 | static void |
| 366 | ccw_device_done(struct ccw_device *cdev, int state) |
| 367 | { |
| 368 | struct subchannel *sch; |
| 369 | |
| 370 | sch = to_subchannel(cdev->dev.parent); |
| 371 | |
Cornelia Huck | f1ee328 | 2006-10-04 20:02:02 +0200 | [diff] [blame] | 372 | ccw_device_set_timeout(cdev, 0); |
| 373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | if (state != DEV_STATE_ONLINE) |
| 375 | cio_disable_subchannel(sch); |
| 376 | |
| 377 | /* Reset device status. */ |
| 378 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 379 | |
| 380 | cdev->private->state = state; |
| 381 | |
Peter Oberparleiter | 9a33211 | 2009-10-06 10:34:01 +0200 | [diff] [blame] | 382 | switch (state) { |
| 383 | case DEV_STATE_BOXED: |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 384 | CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n", |
| 385 | cdev->private->dev_id.devno, sch->schid.sch_no); |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 386 | if (cdev->online && |
| 387 | ccw_device_notify(cdev, CIO_BOXED) != NOTIFY_OK) |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 388 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 389 | cdev->private->flags.donotify = 0; |
Peter Oberparleiter | 9a33211 | 2009-10-06 10:34:01 +0200 | [diff] [blame] | 390 | break; |
| 391 | case DEV_STATE_NOT_OPER: |
Sebastian Ott | 626e476 | 2009-09-11 10:28:17 +0200 | [diff] [blame] | 392 | CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n", |
| 393 | cdev->private->dev_id.devno, sch->schid.sch_no); |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 394 | if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK) |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 395 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Peter Oberparleiter | 6afcc77 | 2009-10-06 10:34:02 +0200 | [diff] [blame] | 396 | else |
| 397 | ccw_device_set_disconnected(cdev); |
Sebastian Ott | 626e476 | 2009-09-11 10:28:17 +0200 | [diff] [blame] | 398 | cdev->private->flags.donotify = 0; |
Peter Oberparleiter | 9a33211 | 2009-10-06 10:34:01 +0200 | [diff] [blame] | 399 | break; |
| 400 | case DEV_STATE_DISCONNECTED: |
| 401 | CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel " |
| 402 | "%04x\n", cdev->private->dev_id.devno, |
| 403 | sch->schid.sch_no); |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 404 | if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK) |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 405 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Peter Oberparleiter | 9a33211 | 2009-10-06 10:34:01 +0200 | [diff] [blame] | 406 | else |
| 407 | ccw_device_set_disconnected(cdev); |
| 408 | cdev->private->flags.donotify = 0; |
| 409 | break; |
| 410 | default: |
| 411 | break; |
Sebastian Ott | 626e476 | 2009-09-11 10:28:17 +0200 | [diff] [blame] | 412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | if (cdev->private->flags.donotify) { |
| 415 | cdev->private->flags.donotify = 0; |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 416 | ccw_device_oper_notify(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | wake_up(&cdev->private->wait_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | * Start device recognition. |
| 423 | */ |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 424 | void ccw_device_recognition(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 426 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * We used to start here with a sense pgid to find out whether a device |
| 430 | * is locked by someone else. Unfortunately, the sense pgid command |
| 431 | * code has other meanings on devices predating the path grouping |
| 432 | * algorithm, so we start with sense id and box the device after an |
| 433 | * timeout (or if sense pgid during path verification detects the device |
| 434 | * is locked, as may happen on newer devices). |
| 435 | */ |
| 436 | cdev->private->flags.recog_done = 0; |
| 437 | cdev->private->state = DEV_STATE_SENSE_ID; |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 438 | if (cio_enable_subchannel(sch, (u32) (addr_t) sch)) { |
| 439 | ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER); |
| 440 | return; |
| 441 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | ccw_device_sense_id_start(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | /* |
Peter Oberparleiter | 39f5360 | 2009-12-07 12:51:26 +0100 | [diff] [blame] | 446 | * Handle events for states that use the ccw request infrastructure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | */ |
Peter Oberparleiter | 39f5360 | 2009-12-07 12:51:26 +0100 | [diff] [blame] | 448 | static void ccw_device_request_event(struct ccw_device *cdev, enum dev_event e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Peter Oberparleiter | 39f5360 | 2009-12-07 12:51:26 +0100 | [diff] [blame] | 450 | switch (e) { |
| 451 | case DEV_EVENT_NOTOPER: |
| 452 | ccw_request_notoper(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | break; |
Peter Oberparleiter | 39f5360 | 2009-12-07 12:51:26 +0100 | [diff] [blame] | 454 | case DEV_EVENT_INTERRUPT: |
| 455 | ccw_request_handler(cdev); |
| 456 | break; |
| 457 | case DEV_EVENT_TIMEOUT: |
| 458 | ccw_request_timeout(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | break; |
| 460 | default: |
Peter Oberparleiter | 39f5360 | 2009-12-07 12:51:26 +0100 | [diff] [blame] | 461 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | void |
| 466 | ccw_device_verify_done(struct ccw_device *cdev, int err) |
| 467 | { |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 468 | struct subchannel *sch; |
| 469 | |
| 470 | sch = to_subchannel(cdev->dev.parent); |
| 471 | /* Update schib - pom may have changed. */ |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 472 | if (cio_update_schib(sch)) { |
Peter Oberparleiter | 7c4d964 | 2009-12-07 12:51:22 +0100 | [diff] [blame] | 473 | err = -ENODEV; |
| 474 | goto callback; |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 475 | } |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 476 | /* Update lpm with verified path mask. */ |
| 477 | sch->lpm = sch->vpm; |
| 478 | /* Repeat path verification? */ |
| 479 | if (cdev->private->flags.doverify) { |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 480 | ccw_device_verify_start(cdev); |
| 481 | return; |
| 482 | } |
Peter Oberparleiter | 7c4d964 | 2009-12-07 12:51:22 +0100 | [diff] [blame] | 483 | callback: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | switch (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | case 0: |
| 486 | ccw_device_done(cdev, DEV_STATE_ONLINE); |
| 487 | /* Deliver fake irb to device driver, if needed. */ |
| 488 | if (cdev->private->flags.fake_irb) { |
| 489 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 490 | cdev->private->irb.scsw.cmd.cc = 1; |
| 491 | cdev->private->irb.scsw.cmd.fctl = SCSW_FCTL_START_FUNC; |
| 492 | cdev->private->irb.scsw.cmd.actl = SCSW_ACTL_START_PEND; |
| 493 | cdev->private->irb.scsw.cmd.stctl = |
| 494 | SCSW_STCTL_STATUS_PEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | cdev->private->flags.fake_irb = 0; |
| 496 | if (cdev->handler) |
| 497 | cdev->handler(cdev, cdev->private->intparm, |
| 498 | &cdev->private->irb); |
| 499 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 500 | } |
| 501 | break; |
| 502 | case -ETIME: |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 503 | case -EUSERS: |
Peter Oberparleiter | 8b42f5c | 2006-10-18 18:30:43 +0200 | [diff] [blame] | 504 | /* Reset oper notify indication after verify error. */ |
| 505 | cdev->private->flags.donotify = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | ccw_device_done(cdev, DEV_STATE_BOXED); |
| 507 | break; |
Peter Oberparleiter | 7c4d964 | 2009-12-07 12:51:22 +0100 | [diff] [blame] | 508 | case -EACCES: |
| 509 | /* Reset oper notify indication after verify error. */ |
| 510 | cdev->private->flags.donotify = 0; |
| 511 | ccw_device_done(cdev, DEV_STATE_DISCONNECTED); |
| 512 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | default: |
Peter Oberparleiter | 8b42f5c | 2006-10-18 18:30:43 +0200 | [diff] [blame] | 514 | /* Reset oper notify indication after verify error. */ |
| 515 | cdev->private->flags.donotify = 0; |
Peter Oberparleiter | 7c4d964 | 2009-12-07 12:51:22 +0100 | [diff] [blame] | 516 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | break; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | * Get device online. |
| 523 | */ |
| 524 | int |
| 525 | ccw_device_online(struct ccw_device *cdev) |
| 526 | { |
| 527 | struct subchannel *sch; |
| 528 | int ret; |
| 529 | |
| 530 | if ((cdev->private->state != DEV_STATE_OFFLINE) && |
| 531 | (cdev->private->state != DEV_STATE_BOXED)) |
| 532 | return -EINVAL; |
| 533 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 534 | ret = cio_enable_subchannel(sch, (u32)(addr_t)sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | if (ret != 0) { |
| 536 | /* Couldn't enable the subchannel for i/o. Sick device. */ |
| 537 | if (ret == -ENODEV) |
| 538 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 539 | return ret; |
| 540 | } |
Peter Oberparleiter | 52ef060 | 2009-12-07 12:51:31 +0100 | [diff] [blame] | 541 | /* Start initial path verification. */ |
| 542 | cdev->private->state = DEV_STATE_VERIFY; |
| 543 | ccw_device_verify_start(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | void |
| 548 | ccw_device_disband_done(struct ccw_device *cdev, int err) |
| 549 | { |
| 550 | switch (err) { |
| 551 | case 0: |
| 552 | ccw_device_done(cdev, DEV_STATE_OFFLINE); |
| 553 | break; |
| 554 | case -ETIME: |
| 555 | ccw_device_done(cdev, DEV_STATE_BOXED); |
| 556 | break; |
| 557 | default: |
Peter Oberparleiter | 3ecb0a5 | 2007-05-31 17:38:07 +0200 | [diff] [blame] | 558 | cdev->private->flags.donotify = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
| 560 | break; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | /* |
| 565 | * Shutdown device. |
| 566 | */ |
| 567 | int |
| 568 | ccw_device_offline(struct ccw_device *cdev) |
| 569 | { |
| 570 | struct subchannel *sch; |
| 571 | |
Peter Oberparleiter | b301ea8 | 2008-09-09 12:38:59 +0200 | [diff] [blame] | 572 | /* Allow ccw_device_offline while disconnected. */ |
| 573 | if (cdev->private->state == DEV_STATE_DISCONNECTED || |
| 574 | cdev->private->state == DEV_STATE_NOT_OPER) { |
| 575 | cdev->private->flags.donotify = 0; |
| 576 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
| 577 | return 0; |
| 578 | } |
Peter Oberparleiter | 102e835 | 2009-10-06 10:34:03 +0200 | [diff] [blame] | 579 | if (cdev->private->state == DEV_STATE_BOXED) { |
| 580 | ccw_device_done(cdev, DEV_STATE_BOXED); |
| 581 | return 0; |
| 582 | } |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 583 | if (ccw_device_is_orphan(cdev)) { |
| 584 | ccw_device_done(cdev, DEV_STATE_OFFLINE); |
| 585 | return 0; |
| 586 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | sch = to_subchannel(cdev->dev.parent); |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 588 | if (cio_update_schib(sch)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | return -ENODEV; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 590 | if (scsw_actl(&sch->schib.scsw) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | return -EBUSY; |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 592 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 593 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | /* Are we doing path grouping? */ |
Peter Oberparleiter | 454e1fa | 2009-12-07 12:51:30 +0100 | [diff] [blame] | 595 | if (!cdev->private->flags.pgroup) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | /* No, set state offline immediately. */ |
| 597 | ccw_device_done(cdev, DEV_STATE_OFFLINE); |
| 598 | return 0; |
| 599 | } |
| 600 | /* Start Set Path Group commands. */ |
| 601 | cdev->private->state = DEV_STATE_DISBAND_PGID; |
| 602 | ccw_device_disband_start(cdev); |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | /* |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 607 | * Handle not operational event in non-special state. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | */ |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 609 | static void ccw_device_generic_notoper(struct ccw_device *cdev, |
| 610 | enum dev_event dev_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 612 | if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK) |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 613 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Peter Oberparleiter | 6afcc77 | 2009-10-06 10:34:02 +0200 | [diff] [blame] | 614 | else |
| 615 | ccw_device_set_disconnected(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* |
Peter Oberparleiter | 1f1148c | 2009-09-11 10:28:14 +0200 | [diff] [blame] | 619 | * Handle path verification event in offline state. |
| 620 | */ |
| 621 | static void ccw_device_offline_verify(struct ccw_device *cdev, |
| 622 | enum dev_event dev_event) |
| 623 | { |
| 624 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 625 | |
| 626 | css_schedule_eval(sch->schid); |
| 627 | } |
| 628 | |
| 629 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | * Handle path verification event. |
| 631 | */ |
| 632 | static void |
| 633 | ccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event) |
| 634 | { |
| 635 | struct subchannel *sch; |
| 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | if (cdev->private->state == DEV_STATE_W4SENSE) { |
| 638 | cdev->private->flags.doverify = 1; |
| 639 | return; |
| 640 | } |
| 641 | sch = to_subchannel(cdev->dev.parent); |
| 642 | /* |
| 643 | * Since we might not just be coming from an interrupt from the |
| 644 | * subchannel we have to update the schib. |
| 645 | */ |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 646 | if (cio_update_schib(sch)) { |
| 647 | ccw_device_verify_done(cdev, -ENODEV); |
| 648 | return; |
| 649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 651 | if (scsw_actl(&sch->schib.scsw) != 0 || |
| 652 | (scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) || |
| 653 | (scsw_stctl(&cdev->private->irb.scsw) & SCSW_STCTL_STATUS_PEND)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | /* |
| 655 | * No final status yet or final status not yet delivered |
| 656 | * to the device driver. Can't do path verfication now, |
| 657 | * delay until final status was delivered. |
| 658 | */ |
| 659 | cdev->private->flags.doverify = 1; |
| 660 | return; |
| 661 | } |
| 662 | /* Device is idle, we can do the path verification. */ |
| 663 | cdev->private->state = DEV_STATE_VERIFY; |
| 664 | ccw_device_verify_start(cdev); |
| 665 | } |
| 666 | |
| 667 | /* |
Peter Oberparleiter | d7d12ef | 2009-12-07 12:51:32 +0100 | [diff] [blame] | 668 | * Handle path verification event in boxed state. |
| 669 | */ |
| 670 | static void ccw_device_boxed_verify(struct ccw_device *cdev, |
| 671 | enum dev_event dev_event) |
| 672 | { |
| 673 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 674 | |
| 675 | if (cdev->online) { |
| 676 | if (cio_enable_subchannel(sch, (u32) (addr_t) sch)) |
| 677 | ccw_device_done(cdev, DEV_STATE_NOT_OPER); |
| 678 | else |
| 679 | ccw_device_online_verify(cdev, dev_event); |
| 680 | } else |
| 681 | css_schedule_eval(sch->schid); |
| 682 | } |
| 683 | |
| 684 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | * Got an interrupt for a normal io (state online). |
| 686 | */ |
| 687 | static void |
| 688 | ccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 689 | { |
| 690 | struct irb *irb; |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 691 | int is_cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 693 | irb = (struct irb *)&S390_lowcore.irb; |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 694 | is_cmd = !scsw_is_tm(&irb->scsw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | /* Check for unsolicited interrupt. */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 696 | if (!scsw_is_solicited(&irb->scsw)) { |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 697 | if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | !irb->esw.esw0.erw.cons) { |
| 699 | /* Unit check but no sense data. Need basic sense. */ |
| 700 | if (ccw_device_do_sense(cdev, irb) != 0) |
| 701 | goto call_handler_unsol; |
Cornelia Huck | e0ec574 | 2006-06-04 02:51:27 -0700 | [diff] [blame] | 702 | memcpy(&cdev->private->irb, irb, sizeof(struct irb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | cdev->private->state = DEV_STATE_W4SENSE; |
| 704 | cdev->private->intparm = 0; |
| 705 | return; |
| 706 | } |
| 707 | call_handler_unsol: |
| 708 | if (cdev->handler) |
| 709 | cdev->handler (cdev, 0, irb); |
Cornelia Huck | 18374d3 | 2007-02-05 21:17:09 +0100 | [diff] [blame] | 710 | if (cdev->private->flags.doverify) |
| 711 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | return; |
| 713 | } |
| 714 | /* Accumulate status and find out if a basic sense is needed. */ |
| 715 | ccw_device_accumulate_irb(cdev, irb); |
Peter Oberparleiter | 83262d6 | 2008-07-14 09:58:51 +0200 | [diff] [blame] | 716 | if (is_cmd && cdev->private->flags.dosense) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (ccw_device_do_sense(cdev, irb) == 0) { |
| 718 | cdev->private->state = DEV_STATE_W4SENSE; |
| 719 | } |
| 720 | return; |
| 721 | } |
| 722 | /* Call the handler. */ |
| 723 | if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify) |
| 724 | /* Start delayed path verification. */ |
| 725 | ccw_device_online_verify(cdev, 0); |
| 726 | } |
| 727 | |
| 728 | /* |
| 729 | * Got an timeout in online state. |
| 730 | */ |
| 731 | static void |
| 732 | ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 733 | { |
| 734 | int ret; |
| 735 | |
| 736 | ccw_device_set_timeout(cdev, 0); |
| 737 | ret = ccw_device_cancel_halt_clear(cdev); |
| 738 | if (ret == -EBUSY) { |
| 739 | ccw_device_set_timeout(cdev, 3*HZ); |
| 740 | cdev->private->state = DEV_STATE_TIMEOUT_KILL; |
| 741 | return; |
| 742 | } |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 743 | if (ret == -ENODEV) |
| 744 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 745 | else if (cdev->handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | cdev->handler(cdev, cdev->private->intparm, |
| 747 | ERR_PTR(-ETIMEDOUT)); |
| 748 | } |
| 749 | |
| 750 | /* |
| 751 | * Got an interrupt for a basic sense. |
| 752 | */ |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 753 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | ccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event) |
| 755 | { |
| 756 | struct irb *irb; |
| 757 | |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 758 | irb = (struct irb *)&S390_lowcore.irb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | /* Check for unsolicited interrupt. */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 760 | if (scsw_stctl(&irb->scsw) == |
| 761 | (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) { |
| 762 | if (scsw_cc(&irb->scsw) == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | /* Basic sense hasn't started. Try again. */ |
| 764 | ccw_device_do_sense(cdev, irb); |
| 765 | else { |
Michael Ernst | 139b83d | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 766 | CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 767 | "interrupt during w4sense...\n", |
| 768 | cdev->private->dev_id.ssid, |
| 769 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | if (cdev->handler) |
| 771 | cdev->handler (cdev, 0, irb); |
| 772 | } |
| 773 | return; |
| 774 | } |
Cornelia Huck | 3ba1998 | 2006-03-24 03:15:12 -0800 | [diff] [blame] | 775 | /* |
| 776 | * Check if a halt or clear has been issued in the meanwhile. If yes, |
| 777 | * only deliver the halt/clear interrupt to the device driver as if it |
| 778 | * had killed the original request. |
| 779 | */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 780 | if (scsw_fctl(&irb->scsw) & |
| 781 | (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) { |
Cornelia Huck | 3ba1998 | 2006-03-24 03:15:12 -0800 | [diff] [blame] | 782 | cdev->private->flags.dosense = 0; |
| 783 | memset(&cdev->private->irb, 0, sizeof(struct irb)); |
| 784 | ccw_device_accumulate_irb(cdev, irb); |
| 785 | goto call_handler; |
| 786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | /* Add basic sense info to irb. */ |
| 788 | ccw_device_accumulate_basic_sense(cdev, irb); |
| 789 | if (cdev->private->flags.dosense) { |
| 790 | /* Another basic sense is needed. */ |
| 791 | ccw_device_do_sense(cdev, irb); |
| 792 | return; |
| 793 | } |
Cornelia Huck | 3ba1998 | 2006-03-24 03:15:12 -0800 | [diff] [blame] | 794 | call_handler: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | cdev->private->state = DEV_STATE_ONLINE; |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 796 | /* In case sensing interfered with setting the device online */ |
| 797 | wake_up(&cdev->private->wait_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | /* Call the handler. */ |
| 799 | if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify) |
| 800 | /* Start delayed path verification. */ |
| 801 | ccw_device_online_verify(cdev, 0); |
| 802 | } |
| 803 | |
| 804 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event) |
| 806 | { |
| 807 | struct subchannel *sch; |
| 808 | |
| 809 | sch = to_subchannel(cdev->dev.parent); |
| 810 | ccw_device_set_timeout(cdev, 0); |
Cornelia Huck | 7c8427c | 2007-03-05 23:35:59 +0100 | [diff] [blame] | 811 | /* Start delayed path verification. */ |
| 812 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | /* OK, i/o is dead now. Call interrupt handler. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | if (cdev->handler) |
| 815 | cdev->handler(cdev, cdev->private->intparm, |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 816 | ERR_PTR(-EIO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | static void |
| 820 | ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 821 | { |
| 822 | int ret; |
| 823 | |
| 824 | ret = ccw_device_cancel_halt_clear(cdev); |
| 825 | if (ret == -EBUSY) { |
| 826 | ccw_device_set_timeout(cdev, 3*HZ); |
| 827 | return; |
| 828 | } |
Cornelia Huck | 7c8427c | 2007-03-05 23:35:59 +0100 | [diff] [blame] | 829 | /* Start delayed path verification. */ |
| 830 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | if (cdev->handler) |
| 832 | cdev->handler(cdev, cdev->private->intparm, |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 833 | ERR_PTR(-EIO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 836 | void ccw_device_kill_io(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | { |
| 838 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | ret = ccw_device_cancel_halt_clear(cdev); |
| 841 | if (ret == -EBUSY) { |
| 842 | ccw_device_set_timeout(cdev, 3*HZ); |
| 843 | cdev->private->state = DEV_STATE_TIMEOUT_KILL; |
| 844 | return; |
| 845 | } |
Cornelia Huck | 7c8427c | 2007-03-05 23:35:59 +0100 | [diff] [blame] | 846 | /* Start delayed path verification. */ |
| 847 | ccw_device_online_verify(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | if (cdev->handler) |
| 849 | cdev->handler(cdev, cdev->private->intparm, |
Cornelia Huck | e7769b4 | 2006-10-11 15:31:41 +0200 | [diff] [blame] | 850 | ERR_PTR(-EIO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | static void |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 854 | 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] | 855 | { |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 856 | /* Start verification after current task finished. */ |
Cornelia Huck | 7e56081 | 2006-07-12 16:40:19 +0200 | [diff] [blame] | 857 | cdev->private->flags.doverify = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | ccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event) |
| 862 | { |
| 863 | struct subchannel *sch; |
| 864 | |
| 865 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | edf2209 | 2008-04-30 13:38:39 +0200 | [diff] [blame] | 866 | if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | /* Couldn't enable the subchannel for i/o. Sick device. */ |
| 868 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID; |
| 870 | ccw_device_sense_id_start(cdev); |
| 871 | } |
| 872 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 873 | void ccw_device_trigger_reprobe(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | { |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 875 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | if (cdev->private->state != DEV_STATE_DISCONNECTED) |
| 878 | return; |
| 879 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 880 | sch = to_subchannel(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | /* Update some values. */ |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 882 | if (cio_update_schib(sch)) |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 883 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | /* |
| 885 | * The pim, pam, pom values may not be accurate, but they are the best |
| 886 | * we have before performing device selection :/ |
| 887 | */ |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 888 | sch->lpm = sch->schib.pmcw.pam & sch->opm; |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 889 | /* |
| 890 | * Use the initial configuration since we can't be shure that the old |
| 891 | * paths are valid. |
| 892 | */ |
| 893 | io_subchannel_init_config(sch); |
Sebastian Ott | f444cc0 | 2008-12-25 13:39:14 +0100 | [diff] [blame] | 894 | if (cio_commit_config(sch)) |
| 895 | return; |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | /* We should also udate ssd info, but this has to wait. */ |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 898 | /* Check if this is another device which appeared on the same sch. */ |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 899 | if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) |
| 900 | css_schedule_eval(sch->schid); |
| 901 | else |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 902 | ccw_device_start_id(cdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Peter Oberparleiter | 16b9a05 | 2009-12-07 12:51:24 +0100 | [diff] [blame] | 905 | static void ccw_device_disabled_irq(struct ccw_device *cdev, |
| 906 | enum dev_event dev_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | { |
| 908 | struct subchannel *sch; |
| 909 | |
| 910 | sch = to_subchannel(cdev->dev.parent); |
| 911 | /* |
Peter Oberparleiter | 16b9a05 | 2009-12-07 12:51:24 +0100 | [diff] [blame] | 912 | * An interrupt in a disabled state means a previous disable was not |
Cornelia Huck | ed04b89 | 2009-03-26 15:24:06 +0100 | [diff] [blame] | 913 | * successful - should not happen, but we try to disable again. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | */ |
| 915 | cio_disable_subchannel(sch); |
| 916 | } |
| 917 | |
| 918 | static void |
| 919 | ccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event) |
| 920 | { |
| 921 | retry_set_schib(cdev); |
| 922 | cdev->private->state = DEV_STATE_ONLINE; |
| 923 | dev_fsm_event(cdev, dev_event); |
| 924 | } |
| 925 | |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 926 | static void ccw_device_update_cmfblock(struct ccw_device *cdev, |
| 927 | enum dev_event dev_event) |
| 928 | { |
| 929 | cmf_retry_copy_block(cdev); |
| 930 | cdev->private->state = DEV_STATE_ONLINE; |
| 931 | dev_fsm_event(cdev, dev_event); |
| 932 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
| 934 | static void |
| 935 | ccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event) |
| 936 | { |
| 937 | ccw_device_set_timeout(cdev, 0); |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 938 | cdev->private->state = DEV_STATE_NOT_OPER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | wake_up(&cdev->private->wait_q); |
| 940 | } |
| 941 | |
| 942 | static void |
| 943 | ccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event) |
| 944 | { |
| 945 | int ret; |
| 946 | |
| 947 | ret = ccw_device_cancel_halt_clear(cdev); |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 948 | if (ret == -EBUSY) { |
| 949 | ccw_device_set_timeout(cdev, HZ/10); |
| 950 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 952 | wake_up(&cdev->private->wait_q); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
| 956 | /* |
| 957 | * No operation action. This is used e.g. to ignore a timeout event in |
| 958 | * state offline. |
| 959 | */ |
| 960 | static void |
| 961 | ccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event) |
| 962 | { |
| 963 | } |
| 964 | |
| 965 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | * device statemachine |
| 967 | */ |
| 968 | fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = { |
| 969 | [DEV_STATE_NOT_OPER] = { |
| 970 | [DEV_EVENT_NOTOPER] = ccw_device_nop, |
Peter Oberparleiter | 16b9a05 | 2009-12-07 12:51:24 +0100 | [diff] [blame] | 971 | [DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
| 973 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 974 | }, |
| 975 | [DEV_STATE_SENSE_PGID] = { |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 976 | [DEV_EVENT_NOTOPER] = ccw_device_request_event, |
| 977 | [DEV_EVENT_INTERRUPT] = ccw_device_request_event, |
| 978 | [DEV_EVENT_TIMEOUT] = ccw_device_request_event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 980 | }, |
| 981 | [DEV_STATE_SENSE_ID] = { |
Peter Oberparleiter | 39f5360 | 2009-12-07 12:51:26 +0100 | [diff] [blame] | 982 | [DEV_EVENT_NOTOPER] = ccw_device_request_event, |
| 983 | [DEV_EVENT_INTERRUPT] = ccw_device_request_event, |
| 984 | [DEV_EVENT_TIMEOUT] = ccw_device_request_event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 986 | }, |
| 987 | [DEV_STATE_OFFLINE] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 988 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Peter Oberparleiter | 16b9a05 | 2009-12-07 12:51:24 +0100 | [diff] [blame] | 989 | [DEV_EVENT_INTERRUPT] = ccw_device_disabled_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
Peter Oberparleiter | 1f1148c | 2009-09-11 10:28:14 +0200 | [diff] [blame] | 991 | [DEV_EVENT_VERIFY] = ccw_device_offline_verify, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | }, |
| 993 | [DEV_STATE_VERIFY] = { |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 994 | [DEV_EVENT_NOTOPER] = ccw_device_request_event, |
| 995 | [DEV_EVENT_INTERRUPT] = ccw_device_request_event, |
| 996 | [DEV_EVENT_TIMEOUT] = ccw_device_request_event, |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 997 | [DEV_EVENT_VERIFY] = ccw_device_delay_verify, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | }, |
| 999 | [DEV_STATE_ONLINE] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1000 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | [DEV_EVENT_INTERRUPT] = ccw_device_irq, |
| 1002 | [DEV_EVENT_TIMEOUT] = ccw_device_online_timeout, |
| 1003 | [DEV_EVENT_VERIFY] = ccw_device_online_verify, |
| 1004 | }, |
| 1005 | [DEV_STATE_W4SENSE] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1006 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | [DEV_EVENT_INTERRUPT] = ccw_device_w4sense, |
| 1008 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
| 1009 | [DEV_EVENT_VERIFY] = ccw_device_online_verify, |
| 1010 | }, |
| 1011 | [DEV_STATE_DISBAND_PGID] = { |
Peter Oberparleiter | 9679baa | 2009-12-07 12:51:27 +0100 | [diff] [blame] | 1012 | [DEV_EVENT_NOTOPER] = ccw_device_request_event, |
| 1013 | [DEV_EVENT_INTERRUPT] = ccw_device_request_event, |
| 1014 | [DEV_EVENT_TIMEOUT] = ccw_device_request_event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1016 | }, |
| 1017 | [DEV_STATE_BOXED] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1018 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Peter Oberparleiter | d7d12ef | 2009-12-07 12:51:32 +0100 | [diff] [blame] | 1019 | [DEV_EVENT_INTERRUPT] = ccw_device_nop, |
| 1020 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
| 1021 | [DEV_EVENT_VERIFY] = ccw_device_boxed_verify, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | }, |
| 1023 | /* states to wait for i/o completion before doing something */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | [DEV_STATE_TIMEOUT_KILL] = { |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 1025 | [DEV_EVENT_NOTOPER] = ccw_device_generic_notoper, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | [DEV_EVENT_INTERRUPT] = ccw_device_killing_irq, |
| 1027 | [DEV_EVENT_TIMEOUT] = ccw_device_killing_timeout, |
| 1028 | [DEV_EVENT_VERIFY] = ccw_device_nop, //FIXME |
| 1029 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | [DEV_STATE_QUIESCE] = { |
| 1031 | [DEV_EVENT_NOTOPER] = ccw_device_quiesce_done, |
| 1032 | [DEV_EVENT_INTERRUPT] = ccw_device_quiesce_done, |
| 1033 | [DEV_EVENT_TIMEOUT] = ccw_device_quiesce_timeout, |
| 1034 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1035 | }, |
| 1036 | /* special states for devices gone not operational */ |
| 1037 | [DEV_STATE_DISCONNECTED] = { |
| 1038 | [DEV_EVENT_NOTOPER] = ccw_device_nop, |
| 1039 | [DEV_EVENT_INTERRUPT] = ccw_device_start_id, |
Peter Oberparleiter | 16b9a05 | 2009-12-07 12:51:24 +0100 | [diff] [blame] | 1040 | [DEV_EVENT_TIMEOUT] = ccw_device_nop, |
Peter Oberparleiter | 28bdc6f | 2006-09-20 15:59:59 +0200 | [diff] [blame] | 1041 | [DEV_EVENT_VERIFY] = ccw_device_start_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | }, |
| 1043 | [DEV_STATE_DISCONNECTED_SENSE_ID] = { |
Peter Oberparleiter | 39f5360 | 2009-12-07 12:51:26 +0100 | [diff] [blame] | 1044 | [DEV_EVENT_NOTOPER] = ccw_device_request_event, |
| 1045 | [DEV_EVENT_INTERRUPT] = ccw_device_request_event, |
| 1046 | [DEV_EVENT_TIMEOUT] = ccw_device_request_event, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1048 | }, |
| 1049 | [DEV_STATE_CMFCHANGE] = { |
| 1050 | [DEV_EVENT_NOTOPER] = ccw_device_change_cmfstate, |
| 1051 | [DEV_EVENT_INTERRUPT] = ccw_device_change_cmfstate, |
| 1052 | [DEV_EVENT_TIMEOUT] = ccw_device_change_cmfstate, |
| 1053 | [DEV_EVENT_VERIFY] = ccw_device_change_cmfstate, |
| 1054 | }, |
Cornelia Huck | 94bb063 | 2006-06-29 15:08:41 +0200 | [diff] [blame] | 1055 | [DEV_STATE_CMFUPDATE] = { |
| 1056 | [DEV_EVENT_NOTOPER] = ccw_device_update_cmfblock, |
| 1057 | [DEV_EVENT_INTERRUPT] = ccw_device_update_cmfblock, |
| 1058 | [DEV_EVENT_TIMEOUT] = ccw_device_update_cmfblock, |
| 1059 | [DEV_EVENT_VERIFY] = ccw_device_update_cmfblock, |
| 1060 | }, |
Peter Oberparleiter | d7d12ef | 2009-12-07 12:51:32 +0100 | [diff] [blame] | 1061 | [DEV_STATE_STEAL_LOCK] = { |
| 1062 | [DEV_EVENT_NOTOPER] = ccw_device_request_event, |
| 1063 | [DEV_EVENT_INTERRUPT] = ccw_device_request_event, |
| 1064 | [DEV_EVENT_TIMEOUT] = ccw_device_request_event, |
| 1065 | [DEV_EVENT_VERIFY] = ccw_device_nop, |
| 1066 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | }; |
| 1068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | EXPORT_SYMBOL_GPL(ccw_device_set_timeout); |