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