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