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