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