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