Greg Kroah-Hartman | 724117b | 2017-11-14 18:38:02 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-1.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 | * bus driver for ccw devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 2002, 2008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Author(s): Arnd Bergmann (arndb@de.ibm.com) |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 7 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 9 | */ |
Peter Oberparleiter | a7ae2c02 | 2009-12-07 12:51:20 +0100 | [diff] [blame] | 10 | |
| 11 | #define KMSG_COMPONENT "cio" |
| 12 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 13 | |
Paul Gortmaker | a00f761 | 2016-10-30 16:37:24 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
| 16 | #include <linux/spinlock.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/list.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <linux/workqueue.h> |
Sebastian Ott | 188561a | 2013-04-13 12:53:21 +0200 | [diff] [blame] | 23 | #include <linux/delay.h> |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 24 | #include <linux/timer.h> |
Peter Oberparleiter | de400d6 | 2011-10-30 15:16:04 +0100 | [diff] [blame] | 25 | #include <linux/kernel_stat.h> |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 26 | #include <linux/sched/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include <asm/ccwdev.h> |
| 29 | #include <asm/cio.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 30 | #include <asm/param.h> /* HZ */ |
Cornelia Huck | 1842f2b | 2007-10-12 16:11:22 +0200 | [diff] [blame] | 31 | #include <asm/cmb.h> |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 32 | #include <asm/isc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 34 | #include "chp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include "cio.h" |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 36 | #include "cio_debug.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include "css.h" |
| 38 | #include "device.h" |
| 39 | #include "ioasm.h" |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 40 | #include "io_sch.h" |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 41 | #include "blacklist.h" |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 42 | #include "chsc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 44 | static struct timer_list recovery_timer; |
Cornelia Huck | 486d0a0 | 2008-02-19 15:29:23 +0100 | [diff] [blame] | 45 | static DEFINE_SPINLOCK(recovery_lock); |
Peter Oberparleiter | 90ab133 | 2008-01-26 14:10:52 +0100 | [diff] [blame] | 46 | static int recovery_phase; |
| 47 | static const unsigned long recovery_delay[] = { 3, 30, 300 }; |
| 48 | |
Sebastian Ott | 0ad8f714a | 2013-04-13 13:06:27 +0200 | [diff] [blame] | 49 | static atomic_t ccw_device_init_count = ATOMIC_INIT(0); |
| 50 | static DECLARE_WAIT_QUEUE_HEAD(ccw_device_init_wq); |
| 51 | static struct bus_type ccw_bus_type; |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /******************* bus type handling ***********************/ |
| 54 | |
| 55 | /* The Linux driver model distinguishes between a bus type and |
| 56 | * the bus itself. Of course we only have one channel |
| 57 | * subsystem driver and one channel system per machine, but |
| 58 | * we still use the abstraction. T.R. says it's a good idea. */ |
| 59 | static int |
| 60 | ccw_bus_match (struct device * dev, struct device_driver * drv) |
| 61 | { |
| 62 | struct ccw_device *cdev = to_ccwdev(dev); |
| 63 | struct ccw_driver *cdrv = to_ccwdrv(drv); |
| 64 | const struct ccw_device_id *ids = cdrv->ids, *found; |
| 65 | |
| 66 | if (!ids) |
| 67 | return 0; |
| 68 | |
| 69 | found = ccw_device_id_match(ids, &cdev->id); |
| 70 | if (!found) |
| 71 | return 0; |
| 72 | |
| 73 | cdev->id.driver_info = found->driver_info; |
| 74 | |
| 75 | return 1; |
| 76 | } |
| 77 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 78 | /* Store modalias string delimited by prefix/suffix string into buffer with |
| 79 | * specified size. Return length of resulting string (excluding trailing '\0') |
| 80 | * even if string doesn't fit buffer (snprintf semantics). */ |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 81 | static int snprint_alias(char *buf, size_t size, |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 82 | struct ccw_device_id *id, const char *suffix) |
| 83 | { |
| 84 | int len; |
| 85 | |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 86 | len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 87 | if (len > size) |
| 88 | return len; |
| 89 | buf += len; |
| 90 | size -= len; |
| 91 | |
| 92 | if (id->dev_type != 0) |
| 93 | len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type, |
| 94 | id->dev_model, suffix); |
| 95 | else |
| 96 | len += snprintf(buf, size, "dtdm%s", suffix); |
| 97 | |
| 98 | return len; |
| 99 | } |
| 100 | |
| 101 | /* Set up environment variables for ccw device uevent. Return 0 on success, |
| 102 | * non-zero otherwise. */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 103 | static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 105 | struct ccw_device *cdev = to_ccwdev(dev); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 106 | struct ccw_device_id *id = &(cdev->id); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 107 | int ret; |
| 108 | char modalias_buf[30]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 110 | /* CU_TYPE= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 111 | ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 112 | if (ret) |
| 113 | return ret; |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 114 | |
| 115 | /* CU_MODEL= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 116 | ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 117 | if (ret) |
| 118 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | /* The next two can be zero, that's ok for us */ |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 121 | /* DEV_TYPE= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 122 | ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 123 | if (ret) |
| 124 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 126 | /* DEV_MODEL= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 127 | ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 128 | if (ret) |
| 129 | return ret; |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 130 | |
| 131 | /* MODALIAS= */ |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 132 | snprint_alias(modalias_buf, sizeof(modalias_buf), id, ""); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 133 | ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf); |
| 134 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 137 | static void io_subchannel_irq(struct subchannel *); |
| 138 | static int io_subchannel_probe(struct subchannel *); |
| 139 | static int io_subchannel_remove(struct subchannel *); |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 140 | static void io_subchannel_shutdown(struct subchannel *); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 141 | static int io_subchannel_sch_event(struct subchannel *, int); |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 142 | static int io_subchannel_chp_event(struct subchannel *, struct chp_link *, |
| 143 | int); |
Kees Cook | 846d0c6 | 2017-10-16 16:43:25 -0700 | [diff] [blame] | 144 | static void recovery_func(struct timer_list *unused); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 146 | static struct css_device_id io_subchannel_ids[] = { |
| 147 | { .match_flags = 0x1, .type = SUBCHANNEL_TYPE_IO, }, |
| 148 | { /* end of list */ }, |
| 149 | }; |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 150 | |
Cornelia Huck | 93a2759 | 2009-06-16 10:30:23 +0200 | [diff] [blame] | 151 | static int io_subchannel_prepare(struct subchannel *sch) |
| 152 | { |
| 153 | struct ccw_device *cdev; |
| 154 | /* |
| 155 | * Don't allow suspend while a ccw device registration |
| 156 | * is still outstanding. |
| 157 | */ |
| 158 | cdev = sch_get_cdev(sch); |
| 159 | if (cdev && !device_is_registered(&cdev->dev)) |
| 160 | return -EAGAIN; |
| 161 | return 0; |
| 162 | } |
| 163 | |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 164 | static int io_subchannel_settle(void) |
Sebastian Ott | 8ea7f55 | 2009-09-22 22:58:35 +0200 | [diff] [blame] | 165 | { |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 166 | int ret; |
| 167 | |
| 168 | ret = wait_event_interruptible(ccw_device_init_wq, |
| 169 | atomic_read(&ccw_device_init_count) == 0); |
| 170 | if (ret) |
| 171 | return -EINTR; |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 172 | flush_workqueue(cio_work_q); |
Sebastian Ott | b4c7072 | 2010-02-26 22:37:27 +0100 | [diff] [blame] | 173 | return 0; |
Sebastian Ott | 8ea7f55 | 2009-09-22 22:58:35 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Cornelia Huck | f7e5d67 | 2007-05-10 15:45:43 +0200 | [diff] [blame] | 176 | static struct css_driver io_subchannel_driver = { |
Sebastian Ott | e6aed12 | 2011-03-15 17:08:30 +0100 | [diff] [blame] | 177 | .drv = { |
| 178 | .owner = THIS_MODULE, |
| 179 | .name = "io_subchannel", |
| 180 | }, |
Cornelia Huck | f08adc0 | 2008-07-14 09:59:03 +0200 | [diff] [blame] | 181 | .subchannel_type = io_subchannel_ids, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | .irq = io_subchannel_irq, |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 183 | .sch_event = io_subchannel_sch_event, |
| 184 | .chp_event = io_subchannel_chp_event, |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 185 | .probe = io_subchannel_probe, |
| 186 | .remove = io_subchannel_remove, |
| 187 | .shutdown = io_subchannel_shutdown, |
Cornelia Huck | 93a2759 | 2009-06-16 10:30:23 +0200 | [diff] [blame] | 188 | .prepare = io_subchannel_prepare, |
Sebastian Ott | 8ea7f55 | 2009-09-22 22:58:35 +0200 | [diff] [blame] | 189 | .settle = io_subchannel_settle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
Sebastian Ott | 2f17644 | 2009-09-22 22:58:33 +0200 | [diff] [blame] | 192 | int __init io_subchannel_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | int ret; |
| 195 | |
Kees Cook | 846d0c6 | 2017-10-16 16:43:25 -0700 | [diff] [blame] | 196 | timer_setup(&recovery_timer, recovery_func, 0); |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 197 | ret = bus_register(&ccw_bus_type); |
| 198 | if (ret) |
| 199 | return ret; |
Cornelia Huck | 25b7bb5 | 2008-01-26 14:10:41 +0100 | [diff] [blame] | 200 | ret = css_driver_register(&io_subchannel_driver); |
| 201 | if (ret) |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 202 | bus_unregister(&ccw_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | return ret; |
| 205 | } |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | /************************ device handling **************************/ |
| 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 211 | devtype_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
| 213 | struct ccw_device *cdev = to_ccwdev(dev); |
| 214 | struct ccw_device_id *id = &(cdev->id); |
| 215 | |
| 216 | if (id->dev_type != 0) |
| 217 | return sprintf(buf, "%04x/%02x\n", |
| 218 | id->dev_type, id->dev_model); |
| 219 | else |
| 220 | return sprintf(buf, "n/a\n"); |
| 221 | } |
| 222 | |
| 223 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 224 | cutype_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | { |
| 226 | struct ccw_device *cdev = to_ccwdev(dev); |
| 227 | struct ccw_device_id *id = &(cdev->id); |
| 228 | |
| 229 | return sprintf(buf, "%04x/%02x\n", |
| 230 | id->cu_type, id->cu_model); |
| 231 | } |
| 232 | |
| 233 | static ssize_t |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 234 | modalias_show (struct device *dev, struct device_attribute *attr, char *buf) |
| 235 | { |
| 236 | struct ccw_device *cdev = to_ccwdev(dev); |
| 237 | struct ccw_device_id *id = &(cdev->id); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 238 | int len; |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 239 | |
Cornelia Huck | 086a6c6 | 2007-07-17 13:36:08 +0200 | [diff] [blame] | 240 | len = snprint_alias(buf, PAGE_SIZE, id, "\n"); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 241 | |
| 242 | return len > PAGE_SIZE ? PAGE_SIZE : len; |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 246 | online_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | struct ccw_device *cdev = to_ccwdev(dev); |
| 249 | |
| 250 | return sprintf(buf, cdev->online ? "1\n" : "0\n"); |
| 251 | } |
| 252 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 253 | int ccw_device_is_orphan(struct ccw_device *cdev) |
| 254 | { |
| 255 | return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent)); |
| 256 | } |
| 257 | |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 258 | static void ccw_device_unregister(struct ccw_device *cdev) |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 259 | { |
Sebastian Ott | 7d253b9 | 2009-12-07 12:51:33 +0100 | [diff] [blame] | 260 | if (device_is_registered(&cdev->dev)) { |
Sebastian Ott | 24a1872 | 2009-12-07 12:51:34 +0100 | [diff] [blame] | 261 | /* Undo device_add(). */ |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 262 | device_del(&cdev->dev); |
Sebastian Ott | 24a1872 | 2009-12-07 12:51:34 +0100 | [diff] [blame] | 263 | } |
| 264 | if (cdev->private->flags.initialized) { |
| 265 | cdev->private->flags.initialized = 0; |
Sebastian Ott | 3b554a1 | 2009-09-11 10:28:26 +0200 | [diff] [blame] | 266 | /* Release reference from device_initialize(). */ |
| 267 | put_device(&cdev->dev); |
| 268 | } |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 269 | } |
| 270 | |
Sebastian Ott | d40f7b7 | 2009-12-07 12:51:41 +0100 | [diff] [blame] | 271 | static void io_subchannel_quiesce(struct subchannel *); |
| 272 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 273 | /** |
| 274 | * ccw_device_set_offline() - disable a ccw device for I/O |
| 275 | * @cdev: target ccw device |
| 276 | * |
| 277 | * This function calls the driver's set_offline() function for @cdev, if |
| 278 | * given, and then disables @cdev. |
| 279 | * Returns: |
| 280 | * %0 on success and a negative error value on failure. |
| 281 | * Context: |
| 282 | * enabled, ccw device lock not held |
| 283 | */ |
| 284 | int ccw_device_set_offline(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
Sebastian Ott | d40f7b7 | 2009-12-07 12:51:41 +0100 | [diff] [blame] | 286 | struct subchannel *sch; |
| 287 | int ret, state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | if (!cdev) |
| 290 | return -ENODEV; |
| 291 | if (!cdev->online || !cdev->drv) |
| 292 | return -EINVAL; |
| 293 | |
| 294 | if (cdev->drv->set_offline) { |
| 295 | ret = cdev->drv->set_offline(cdev); |
| 296 | if (ret != 0) |
| 297 | return ret; |
| 298 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | spin_lock_irq(cdev->ccwlock); |
Sebastian Ott | d40f7b7 | 2009-12-07 12:51:41 +0100 | [diff] [blame] | 300 | sch = to_subchannel(cdev->dev.parent); |
Sebastian Ott | 74bd0d8 | 2013-12-16 10:51:54 +0100 | [diff] [blame] | 301 | cdev->online = 0; |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 302 | /* Wait until a final state or DISCONNECTED is reached */ |
| 303 | while (!dev_fsm_final_state(cdev) && |
| 304 | cdev->private->state != DEV_STATE_DISCONNECTED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | spin_unlock_irq(cdev->ccwlock); |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 306 | wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) || |
| 307 | cdev->private->state == DEV_STATE_DISCONNECTED)); |
| 308 | spin_lock_irq(cdev->ccwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
Sebastian Ott | d40f7b7 | 2009-12-07 12:51:41 +0100 | [diff] [blame] | 310 | do { |
| 311 | ret = ccw_device_offline(cdev); |
| 312 | if (!ret) |
| 313 | break; |
| 314 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, device " |
| 315 | "0.%x.%04x\n", ret, cdev->private->dev_id.ssid, |
| 316 | cdev->private->dev_id.devno); |
| 317 | if (ret != -EBUSY) |
| 318 | goto error; |
| 319 | state = cdev->private->state; |
| 320 | spin_unlock_irq(cdev->ccwlock); |
| 321 | io_subchannel_quiesce(sch); |
| 322 | spin_lock_irq(cdev->ccwlock); |
| 323 | cdev->private->state = state; |
| 324 | } while (ret == -EBUSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | spin_unlock_irq(cdev->ccwlock); |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 326 | wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) || |
| 327 | cdev->private->state == DEV_STATE_DISCONNECTED)); |
Peter Oberparleiter | a7ae2c02 | 2009-12-07 12:51:20 +0100 | [diff] [blame] | 328 | /* Inform the user if set offline failed. */ |
| 329 | if (cdev->private->state == DEV_STATE_BOXED) { |
Joe Perches | baebc70 | 2016-03-03 20:49:57 -0800 | [diff] [blame] | 330 | pr_warn("%s: The device entered boxed state while being set offline\n", |
| 331 | dev_name(&cdev->dev)); |
Peter Oberparleiter | a7ae2c02 | 2009-12-07 12:51:20 +0100 | [diff] [blame] | 332 | } else if (cdev->private->state == DEV_STATE_NOT_OPER) { |
Joe Perches | baebc70 | 2016-03-03 20:49:57 -0800 | [diff] [blame] | 333 | pr_warn("%s: The device stopped operating while being set offline\n", |
| 334 | dev_name(&cdev->dev)); |
Peter Oberparleiter | a7ae2c02 | 2009-12-07 12:51:20 +0100 | [diff] [blame] | 335 | } |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 336 | /* Give up reference from ccw_device_set_online(). */ |
| 337 | put_device(&cdev->dev); |
| 338 | return 0; |
| 339 | |
| 340 | error: |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 341 | cdev->private->state = DEV_STATE_OFFLINE; |
| 342 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 343 | spin_unlock_irq(cdev->ccwlock); |
| 344 | /* Give up reference from ccw_device_set_online(). */ |
| 345 | put_device(&cdev->dev); |
| 346 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 349 | /** |
| 350 | * ccw_device_set_online() - enable a ccw device for I/O |
| 351 | * @cdev: target ccw device |
| 352 | * |
| 353 | * This function first enables @cdev and then calls the driver's set_online() |
| 354 | * function for @cdev, if given. If set_online() returns an error, @cdev is |
| 355 | * disabled again. |
| 356 | * Returns: |
| 357 | * %0 on success and a negative error value on failure. |
| 358 | * Context: |
| 359 | * enabled, ccw device lock not held |
| 360 | */ |
| 361 | int ccw_device_set_online(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
| 363 | int ret; |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 364 | int ret2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | if (!cdev) |
| 367 | return -ENODEV; |
| 368 | if (cdev->online || !cdev->drv) |
| 369 | return -EINVAL; |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 370 | /* Hold on to an extra reference while device is online. */ |
| 371 | if (!get_device(&cdev->dev)) |
| 372 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | spin_lock_irq(cdev->ccwlock); |
| 375 | ret = ccw_device_online(cdev); |
| 376 | spin_unlock_irq(cdev->ccwlock); |
| 377 | if (ret == 0) |
| 378 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 379 | else { |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 380 | CIO_MSG_EVENT(0, "ccw_device_online returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 381 | "device 0.%x.%04x\n", |
| 382 | ret, cdev->private->dev_id.ssid, |
| 383 | cdev->private->dev_id.devno); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 384 | /* Give up online reference since onlining failed. */ |
| 385 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | return ret; |
| 387 | } |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 388 | spin_lock_irq(cdev->ccwlock); |
| 389 | /* Check if online processing was successful */ |
| 390 | if ((cdev->private->state != DEV_STATE_ONLINE) && |
| 391 | (cdev->private->state != DEV_STATE_W4SENSE)) { |
| 392 | spin_unlock_irq(cdev->ccwlock); |
Peter Oberparleiter | a7ae2c02 | 2009-12-07 12:51:20 +0100 | [diff] [blame] | 393 | /* Inform the user that set online failed. */ |
| 394 | if (cdev->private->state == DEV_STATE_BOXED) { |
Joe Perches | baebc70 | 2016-03-03 20:49:57 -0800 | [diff] [blame] | 395 | pr_warn("%s: Setting the device online failed because it is boxed\n", |
| 396 | dev_name(&cdev->dev)); |
Peter Oberparleiter | a7ae2c02 | 2009-12-07 12:51:20 +0100 | [diff] [blame] | 397 | } else if (cdev->private->state == DEV_STATE_NOT_OPER) { |
Joe Perches | baebc70 | 2016-03-03 20:49:57 -0800 | [diff] [blame] | 398 | pr_warn("%s: Setting the device online failed because it is not operational\n", |
| 399 | dev_name(&cdev->dev)); |
Peter Oberparleiter | a7ae2c02 | 2009-12-07 12:51:20 +0100 | [diff] [blame] | 400 | } |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 401 | /* Give up online reference since onlining failed. */ |
| 402 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return -ENODEV; |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | spin_unlock_irq(cdev->ccwlock); |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 406 | if (cdev->drv->set_online) |
| 407 | ret = cdev->drv->set_online(cdev); |
| 408 | if (ret) |
| 409 | goto rollback; |
Sebastian Ott | 74bd0d8 | 2013-12-16 10:51:54 +0100 | [diff] [blame] | 410 | |
| 411 | spin_lock_irq(cdev->ccwlock); |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 412 | cdev->online = 1; |
Sebastian Ott | 74bd0d8 | 2013-12-16 10:51:54 +0100 | [diff] [blame] | 413 | spin_unlock_irq(cdev->ccwlock); |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 414 | return 0; |
| 415 | |
| 416 | rollback: |
| 417 | spin_lock_irq(cdev->ccwlock); |
| 418 | /* Wait until a final state or DISCONNECTED is reached */ |
| 419 | while (!dev_fsm_final_state(cdev) && |
| 420 | cdev->private->state != DEV_STATE_DISCONNECTED) { |
| 421 | spin_unlock_irq(cdev->ccwlock); |
| 422 | wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) || |
| 423 | cdev->private->state == DEV_STATE_DISCONNECTED)); |
| 424 | spin_lock_irq(cdev->ccwlock); |
| 425 | } |
| 426 | ret2 = ccw_device_offline(cdev); |
| 427 | if (ret2) |
| 428 | goto error; |
| 429 | spin_unlock_irq(cdev->ccwlock); |
| 430 | wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) || |
| 431 | cdev->private->state == DEV_STATE_DISCONNECTED)); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 432 | /* Give up online reference since onlining failed. */ |
| 433 | put_device(&cdev->dev); |
Michael Ernst | 217ee6c | 2009-09-11 10:28:21 +0200 | [diff] [blame] | 434 | return ret; |
| 435 | |
| 436 | error: |
| 437 | CIO_MSG_EVENT(0, "rollback ccw_device_offline returned %d, " |
| 438 | "device 0.%x.%04x\n", |
| 439 | ret2, cdev->private->dev_id.ssid, |
| 440 | cdev->private->dev_id.devno); |
| 441 | cdev->private->state = DEV_STATE_OFFLINE; |
| 442 | spin_unlock_irq(cdev->ccwlock); |
| 443 | /* Give up online reference since onlining failed. */ |
| 444 | put_device(&cdev->dev); |
| 445 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Sebastian Ott | e74fe0c | 2009-03-26 15:24:08 +0100 | [diff] [blame] | 448 | static int online_store_handle_offline(struct ccw_device *cdev) |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 449 | { |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 450 | if (cdev->private->state == DEV_STATE_DISCONNECTED) { |
| 451 | spin_lock_irq(cdev->ccwlock); |
| 452 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG_EVAL); |
| 453 | spin_unlock_irq(cdev->ccwlock); |
Sebastian Ott | 7cd4031 | 2010-08-09 18:12:52 +0200 | [diff] [blame] | 454 | return 0; |
| 455 | } |
| 456 | if (cdev->drv && cdev->drv->set_offline) |
Sebastian Ott | e74fe0c | 2009-03-26 15:24:08 +0100 | [diff] [blame] | 457 | return ccw_device_set_offline(cdev); |
Sebastian Ott | 7cd4031 | 2010-08-09 18:12:52 +0200 | [diff] [blame] | 458 | return -EINVAL; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static int online_store_recog_and_online(struct ccw_device *cdev) |
| 462 | { |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 463 | /* Do device recognition, if needed. */ |
Sebastian Ott | 99f6a570 | 2009-03-31 19:16:07 +0200 | [diff] [blame] | 464 | if (cdev->private->state == DEV_STATE_BOXED) { |
Peter Oberparleiter | 1f5bd3848 | 2009-12-07 12:51:23 +0100 | [diff] [blame] | 465 | spin_lock_irq(cdev->ccwlock); |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 466 | ccw_device_recognition(cdev); |
Peter Oberparleiter | 1f5bd3848 | 2009-12-07 12:51:23 +0100 | [diff] [blame] | 467 | spin_unlock_irq(cdev->ccwlock); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 468 | wait_event(cdev->private->wait_q, |
| 469 | cdev->private->flags.recog_done); |
Sebastian Ott | 156013f | 2009-03-31 19:16:03 +0200 | [diff] [blame] | 470 | if (cdev->private->state != DEV_STATE_OFFLINE) |
| 471 | /* recognition failed */ |
| 472 | return -EAGAIN; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 473 | } |
| 474 | if (cdev->drv && cdev->drv->set_online) |
Sebastian Ott | 7cd4031 | 2010-08-09 18:12:52 +0200 | [diff] [blame] | 475 | return ccw_device_set_online(cdev); |
| 476 | return -EINVAL; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 477 | } |
Sebastian Ott | 156013f | 2009-03-31 19:16:03 +0200 | [diff] [blame] | 478 | |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 479 | static int online_store_handle_online(struct ccw_device *cdev, int force) |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 480 | { |
| 481 | int ret; |
| 482 | |
| 483 | ret = online_store_recog_and_online(cdev); |
Sebastian Ott | 156013f | 2009-03-31 19:16:03 +0200 | [diff] [blame] | 484 | if (ret && !force) |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 485 | return ret; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 486 | if (force && cdev->private->state == DEV_STATE_BOXED) { |
| 487 | ret = ccw_device_stlck(cdev); |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 488 | if (ret) |
| 489 | return ret; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 490 | if (cdev->id.cu_type == 0) |
| 491 | cdev->private->state = DEV_STATE_NOT_OPER; |
Sebastian Ott | 156013f | 2009-03-31 19:16:03 +0200 | [diff] [blame] | 492 | ret = online_store_recog_and_online(cdev); |
| 493 | if (ret) |
| 494 | return ret; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 495 | } |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 496 | return 0; |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static ssize_t online_store (struct device *dev, struct device_attribute *attr, |
| 500 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | { |
| 502 | struct ccw_device *cdev = to_ccwdev(dev); |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 503 | int force, ret; |
| 504 | unsigned long i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Peter Oberparleiter | a2fc848 | 2011-04-04 09:43:32 +0200 | [diff] [blame] | 506 | /* Prevent conflict between multiple on-/offline processing requests. */ |
Peter Oberparleiter | 350e912 | 2009-12-07 12:51:28 +0100 | [diff] [blame] | 507 | if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | return -EAGAIN; |
Peter Oberparleiter | a2fc848 | 2011-04-04 09:43:32 +0200 | [diff] [blame] | 509 | /* Prevent conflict between internal I/Os and on-/offline processing. */ |
| 510 | if (!dev_fsm_final_state(cdev) && |
| 511 | cdev->private->state != DEV_STATE_DISCONNECTED) { |
| 512 | ret = -EAGAIN; |
Sebastian Ott | 00381ee | 2013-12-16 10:54:13 +0100 | [diff] [blame] | 513 | goto out; |
Peter Oberparleiter | a2fc848 | 2011-04-04 09:43:32 +0200 | [diff] [blame] | 514 | } |
| 515 | /* Prevent conflict between pending work and on-/offline processing.*/ |
| 516 | if (work_pending(&cdev->private->todo_work)) { |
| 517 | ret = -EAGAIN; |
Sebastian Ott | 00381ee | 2013-12-16 10:54:13 +0100 | [diff] [blame] | 518 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | if (!strncmp(buf, "force\n", count)) { |
| 521 | force = 1; |
| 522 | i = 1; |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 523 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | } else { |
| 525 | force = 0; |
Jingoo Han | 0178722 | 2013-07-22 10:18:15 +0900 | [diff] [blame] | 526 | ret = kstrtoul(buf, 16, &i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 528 | if (ret) |
| 529 | goto out; |
Sebastian Ott | 00381ee | 2013-12-16 10:54:13 +0100 | [diff] [blame] | 530 | |
| 531 | device_lock(dev); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 532 | switch (i) { |
| 533 | case 0: |
Sebastian Ott | e74fe0c | 2009-03-26 15:24:08 +0100 | [diff] [blame] | 534 | ret = online_store_handle_offline(cdev); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 535 | break; |
| 536 | case 1: |
Michael Ernst | c78aa6c | 2008-07-14 09:59:22 +0200 | [diff] [blame] | 537 | ret = online_store_handle_online(cdev, force); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 538 | break; |
| 539 | default: |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 540 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
Sebastian Ott | 00381ee | 2013-12-16 10:54:13 +0100 | [diff] [blame] | 542 | device_unlock(dev); |
| 543 | |
Cornelia Huck | 2f97220 | 2008-04-30 13:38:33 +0200 | [diff] [blame] | 544 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | atomic_set(&cdev->private->onoff, 0); |
Sebastian Ott | e74fe0c | 2009-03-26 15:24:08 +0100 | [diff] [blame] | 546 | return (ret < 0) ? ret : count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 550 | available_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
| 552 | struct ccw_device *cdev = to_ccwdev(dev); |
| 553 | struct subchannel *sch; |
| 554 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 555 | if (ccw_device_is_orphan(cdev)) |
| 556 | return sprintf(buf, "no device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | switch (cdev->private->state) { |
| 558 | case DEV_STATE_BOXED: |
| 559 | return sprintf(buf, "boxed\n"); |
| 560 | case DEV_STATE_DISCONNECTED: |
| 561 | case DEV_STATE_DISCONNECTED_SENSE_ID: |
| 562 | case DEV_STATE_NOT_OPER: |
| 563 | sch = to_subchannel(dev->parent); |
| 564 | if (!sch->lpm) |
| 565 | return sprintf(buf, "no path\n"); |
| 566 | else |
| 567 | return sprintf(buf, "no device\n"); |
| 568 | default: |
| 569 | /* All other states considered fine. */ |
| 570 | return sprintf(buf, "good\n"); |
| 571 | } |
| 572 | } |
| 573 | |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 574 | static ssize_t |
| 575 | initiate_logging(struct device *dev, struct device_attribute *attr, |
| 576 | const char *buf, size_t count) |
| 577 | { |
| 578 | struct subchannel *sch = to_subchannel(dev); |
| 579 | int rc; |
| 580 | |
| 581 | rc = chsc_siosl(sch->schid); |
| 582 | if (rc < 0) { |
Joe Perches | baebc70 | 2016-03-03 20:49:57 -0800 | [diff] [blame] | 583 | pr_warn("Logging for subchannel 0.%x.%04x failed with errno=%d\n", |
| 584 | sch->schid.ssid, sch->schid.sch_no, rc); |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 585 | return rc; |
| 586 | } |
| 587 | pr_notice("Logging for subchannel 0.%x.%04x was triggered\n", |
| 588 | sch->schid.ssid, sch->schid.sch_no); |
| 589 | return count; |
| 590 | } |
| 591 | |
Sebastian Ott | 84c57ad | 2013-01-28 19:32:27 +0100 | [diff] [blame] | 592 | static ssize_t vpm_show(struct device *dev, struct device_attribute *attr, |
| 593 | char *buf) |
| 594 | { |
| 595 | struct subchannel *sch = to_subchannel(dev); |
| 596 | |
| 597 | return sprintf(buf, "%02x\n", sch->vpm); |
| 598 | } |
| 599 | |
Joe Perches | c828a89 | 2017-12-19 10:15:08 -0800 | [diff] [blame] | 600 | static DEVICE_ATTR_RO(devtype); |
| 601 | static DEVICE_ATTR_RO(cutype); |
| 602 | static DEVICE_ATTR_RO(modalias); |
Joe Perches | b6b996b | 2017-12-19 10:15:07 -0800 | [diff] [blame] | 603 | static DEVICE_ATTR_RW(online); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | static DEVICE_ATTR(availability, 0444, available_show, NULL); |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 605 | static DEVICE_ATTR(logging, 0200, NULL, initiate_logging); |
Joe Perches | c828a89 | 2017-12-19 10:15:08 -0800 | [diff] [blame] | 606 | static DEVICE_ATTR_RO(vpm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 608 | static struct attribute *io_subchannel_attrs[] = { |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 609 | &dev_attr_logging.attr, |
Sebastian Ott | 84c57ad | 2013-01-28 19:32:27 +0100 | [diff] [blame] | 610 | &dev_attr_vpm.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | NULL, |
| 612 | }; |
| 613 | |
Arvind Yadav | f460d11 | 2017-07-19 12:39:13 +0530 | [diff] [blame] | 614 | static const struct attribute_group io_subchannel_attr_group = { |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 615 | .attrs = io_subchannel_attrs, |
Cornelia Huck | 529192f | 2006-12-08 15:55:57 +0100 | [diff] [blame] | 616 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
| 618 | static struct attribute * ccwdev_attrs[] = { |
| 619 | &dev_attr_devtype.attr, |
| 620 | &dev_attr_cutype.attr, |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 621 | &dev_attr_modalias.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | &dev_attr_online.attr, |
| 623 | &dev_attr_cmb_enable.attr, |
| 624 | &dev_attr_availability.attr, |
| 625 | NULL, |
| 626 | }; |
| 627 | |
Arvind Yadav | f460d11 | 2017-07-19 12:39:13 +0530 | [diff] [blame] | 628 | static const struct attribute_group ccwdev_attr_group = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | .attrs = ccwdev_attrs, |
| 630 | }; |
| 631 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 632 | static const struct attribute_group *ccwdev_attr_groups[] = { |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 633 | &ccwdev_attr_group, |
| 634 | NULL, |
| 635 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 637 | static int ccw_device_add(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
| 639 | struct device *dev = &cdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | dev->bus = &ccw_bus_type; |
Sebastian Ott | 7d253b9 | 2009-12-07 12:51:33 +0100 | [diff] [blame] | 642 | return device_add(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 645 | static int match_dev_id(struct device *dev, void *data) |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 646 | { |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 647 | struct ccw_device *cdev = to_ccwdev(dev); |
| 648 | struct ccw_dev_id *dev_id = data; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 649 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 650 | return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); |
| 651 | } |
| 652 | |
Sebastian Ott | b7a610f | 2012-05-15 17:52:07 +0200 | [diff] [blame] | 653 | /** |
| 654 | * get_ccwdev_by_dev_id() - obtain device from a ccw device id |
| 655 | * @dev_id: id of the device to be searched |
| 656 | * |
| 657 | * This function searches all devices attached to the ccw bus for a device |
| 658 | * matching @dev_id. |
| 659 | * Returns: |
| 660 | * If a device is found its reference count is increased and returned; |
| 661 | * else %NULL is returned. |
| 662 | */ |
| 663 | struct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id) |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 664 | { |
| 665 | struct device *dev; |
| 666 | |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 667 | dev = bus_find_device(&ccw_bus_type, NULL, dev_id, match_dev_id); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 668 | |
| 669 | return dev ? to_ccwdev(dev) : NULL; |
| 670 | } |
Sebastian Ott | b7a610f | 2012-05-15 17:52:07 +0200 | [diff] [blame] | 671 | EXPORT_SYMBOL_GPL(get_ccwdev_by_dev_id); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 672 | |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 673 | static void ccw_device_do_unbind_bind(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
Cornelia Huck | eb32ae8 | 2009-03-26 15:24:05 +0100 | [diff] [blame] | 675 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Sebastian Ott | 7d253b9 | 2009-12-07 12:51:33 +0100 | [diff] [blame] | 677 | if (device_is_registered(&cdev->dev)) { |
Cornelia Huck | eb32ae8 | 2009-03-26 15:24:05 +0100 | [diff] [blame] | 678 | device_release_driver(&cdev->dev); |
| 679 | ret = device_attach(&cdev->dev); |
| 680 | WARN_ON(ret == -ENODEV); |
| 681 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | static void |
| 685 | ccw_device_release(struct device *dev) |
| 686 | { |
| 687 | struct ccw_device *cdev; |
| 688 | |
| 689 | cdev = to_ccwdev(dev); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 690 | /* Release reference of parent subchannel. */ |
| 691 | put_device(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | kfree(cdev->private); |
| 693 | kfree(cdev); |
| 694 | } |
| 695 | |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 696 | static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) |
| 697 | { |
| 698 | struct ccw_device *cdev; |
| 699 | |
| 700 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 701 | if (cdev) { |
| 702 | cdev->private = kzalloc(sizeof(struct ccw_device_private), |
| 703 | GFP_KERNEL | GFP_DMA); |
| 704 | if (cdev->private) |
| 705 | return cdev; |
| 706 | } |
| 707 | kfree(cdev); |
| 708 | return ERR_PTR(-ENOMEM); |
| 709 | } |
| 710 | |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 711 | static void ccw_device_todo(struct work_struct *work); |
| 712 | |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 713 | static int io_subchannel_initialize_dev(struct subchannel *sch, |
| 714 | struct ccw_device *cdev) |
| 715 | { |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 716 | struct ccw_device_private *priv = cdev->private; |
| 717 | int ret; |
| 718 | |
| 719 | priv->cdev = cdev; |
| 720 | priv->int_class = IRQIO_CIO; |
| 721 | priv->state = DEV_STATE_NOT_OPER; |
| 722 | priv->dev_id.devno = sch->schib.pmcw.dev; |
| 723 | priv->dev_id.ssid = sch->schid.ssid; |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 724 | |
| 725 | INIT_WORK(&priv->todo_work, ccw_device_todo); |
| 726 | INIT_LIST_HEAD(&priv->cmb_list); |
| 727 | init_waitqueue_head(&priv->wait_q); |
Kees Cook | 846d0c6 | 2017-10-16 16:43:25 -0700 | [diff] [blame] | 728 | timer_setup(&priv->timer, ccw_device_timeout, 0); |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 729 | |
| 730 | atomic_set(&priv->onoff, 0); |
| 731 | cdev->ccwlock = sch->lock; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 732 | cdev->dev.parent = &sch->dev; |
| 733 | cdev->dev.release = ccw_device_release; |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 734 | cdev->dev.groups = ccwdev_attr_groups; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 735 | /* Do first half of device_register. */ |
| 736 | device_initialize(&cdev->dev); |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 737 | ret = dev_set_name(&cdev->dev, "0.%x.%04x", cdev->private->dev_id.ssid, |
| 738 | cdev->private->dev_id.devno); |
| 739 | if (ret) |
| 740 | goto out_put; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 741 | if (!get_device(&sch->dev)) { |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 742 | ret = -ENODEV; |
| 743 | goto out_put; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 744 | } |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 745 | priv->flags.initialized = 1; |
| 746 | spin_lock_irq(sch->lock); |
| 747 | sch_set_cdev(sch, cdev); |
| 748 | spin_unlock_irq(sch->lock); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 749 | return 0; |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 750 | |
| 751 | out_put: |
| 752 | /* Release reference from device_initialize(). */ |
| 753 | put_device(&cdev->dev); |
| 754 | return ret; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch) |
| 758 | { |
| 759 | struct ccw_device *cdev; |
| 760 | int ret; |
| 761 | |
| 762 | cdev = io_subchannel_allocate_dev(sch); |
| 763 | if (!IS_ERR(cdev)) { |
| 764 | ret = io_subchannel_initialize_dev(sch, cdev); |
Sebastian Ott | 06739a8 | 2009-08-23 18:09:04 +0200 | [diff] [blame] | 765 | if (ret) |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 766 | cdev = ERR_PTR(ret); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 767 | } |
| 768 | return cdev; |
| 769 | } |
| 770 | |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 771 | static void io_subchannel_recog(struct ccw_device *, struct subchannel *); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 772 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 773 | static void sch_create_and_recog_new_device(struct subchannel *sch) |
| 774 | { |
| 775 | struct ccw_device *cdev; |
| 776 | |
| 777 | /* Need to allocate a new ccw device. */ |
| 778 | cdev = io_subchannel_create_ccwdev(sch); |
| 779 | if (IS_ERR(cdev)) { |
| 780 | /* OK, we did everything we could... */ |
| 781 | css_sch_device_unregister(sch); |
| 782 | return; |
| 783 | } |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 784 | /* Start recognition for the new ccw device. */ |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 785 | io_subchannel_recog(cdev, sch); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 786 | } |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | /* |
| 789 | * Register recognized device. |
| 790 | */ |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 791 | static void io_subchannel_register(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | struct subchannel *sch; |
Sebastian Ott | a290156 | 2010-03-08 12:25:17 +0100 | [diff] [blame] | 794 | int ret, adjust_init_count = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | unsigned long flags; |
| 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 5fb6b85 | 2008-12-25 13:39:08 +0100 | [diff] [blame] | 798 | /* |
| 799 | * Check if subchannel is still registered. It may have become |
| 800 | * unregistered if a machine check hit us after finishing |
| 801 | * device recognition but before the register work could be |
| 802 | * queued. |
| 803 | */ |
| 804 | if (!device_is_registered(&sch->dev)) |
| 805 | goto out_err; |
Cornelia Huck | 82b7ac0 | 2007-04-27 16:01:36 +0200 | [diff] [blame] | 806 | css_update_ssd_info(sch); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 807 | /* |
| 808 | * io_subchannel_register() will also be called after device |
| 809 | * recognition has been done for a boxed device (which will already |
| 810 | * be registered). We need to reprobe since we may now have sense id |
| 811 | * information. |
| 812 | */ |
Cornelia Huck | d6a3076 | 2008-12-25 13:39:11 +0100 | [diff] [blame] | 813 | if (device_is_registered(&cdev->dev)) { |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 814 | if (!cdev->drv) { |
| 815 | ret = device_reprobe(&cdev->dev); |
| 816 | if (ret) |
| 817 | /* We can't do much here. */ |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 818 | CIO_MSG_EVENT(0, "device_reprobe() returned" |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 819 | " %d for 0.%x.%04x\n", ret, |
| 820 | cdev->private->dev_id.ssid, |
| 821 | cdev->private->dev_id.devno); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 822 | } |
Sebastian Ott | a290156 | 2010-03-08 12:25:17 +0100 | [diff] [blame] | 823 | adjust_init_count = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | goto out; |
| 825 | } |
Cornelia Huck | fa1a8c2 | 2007-04-26 00:12:03 -0700 | [diff] [blame] | 826 | /* |
| 827 | * Now we know this subchannel will stay, we can throw |
| 828 | * our delayed uevent. |
| 829 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 830 | dev_set_uevent_suppress(&sch->dev, 0); |
Cornelia Huck | fa1a8c2 | 2007-04-26 00:12:03 -0700 | [diff] [blame] | 831 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | /* make it known to the system */ |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 833 | ret = ccw_device_add(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 835 | CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n", |
| 836 | cdev->private->dev_id.ssid, |
| 837 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 838 | spin_lock_irqsave(sch->lock, flags); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 839 | sch_set_cdev(sch, NULL); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 840 | spin_unlock_irqrestore(sch->lock, flags); |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 841 | /* Release initial device reference. */ |
| 842 | put_device(&cdev->dev); |
Cornelia Huck | 5fb6b85 | 2008-12-25 13:39:08 +0100 | [diff] [blame] | 843 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | out: |
| 846 | cdev->private->flags.recog_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | wake_up(&cdev->private->wait_q); |
Cornelia Huck | 5fb6b85 | 2008-12-25 13:39:08 +0100 | [diff] [blame] | 848 | out_err: |
Sebastian Ott | a290156 | 2010-03-08 12:25:17 +0100 | [diff] [blame] | 849 | if (adjust_init_count && atomic_dec_and_test(&ccw_device_init_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | wake_up(&ccw_device_init_wq); |
| 851 | } |
| 852 | |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 853 | static void ccw_device_call_sch_unregister(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | struct subchannel *sch; |
| 856 | |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 857 | /* Get subchannel reference for local processing. */ |
| 858 | if (!get_device(cdev->dev.parent)) |
| 859 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 861 | css_sch_device_unregister(sch); |
Peter Oberparleiter | 46fbe4e | 2008-10-10 21:33:05 +0200 | [diff] [blame] | 862 | /* Release subchannel reference for local processing. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | put_device(&sch->dev); |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | * subchannel recognition done. Called from the state machine. |
| 868 | */ |
| 869 | void |
| 870 | io_subchannel_recog_done(struct ccw_device *cdev) |
| 871 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | if (css_init_done == 0) { |
| 873 | cdev->private->flags.recog_done = 1; |
| 874 | return; |
| 875 | } |
| 876 | switch (cdev->private->state) { |
Sebastian Ott | 47593bf | 2009-03-31 19:16:05 +0200 | [diff] [blame] | 877 | case DEV_STATE_BOXED: |
| 878 | /* Device did not respond in time. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | case DEV_STATE_NOT_OPER: |
| 880 | cdev->private->flags.recog_done = 1; |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 881 | /* Remove device found not operational. */ |
| 882 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 884 | wake_up(&ccw_device_init_wq); |
| 885 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | case DEV_STATE_OFFLINE: |
| 887 | /* |
| 888 | * We can't register the device in interrupt context so |
| 889 | * we schedule a work item. |
| 890 | */ |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 891 | ccw_device_sched_todo(cdev, CDEV_TODO_REGISTER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | break; |
| 893 | } |
| 894 | } |
| 895 | |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 896 | static void io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | /* Increase counter of devices currently in recognition. */ |
| 899 | atomic_inc(&ccw_device_init_count); |
| 900 | |
| 901 | /* Start async. device sensing. */ |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 902 | spin_lock_irq(sch->lock); |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 903 | ccw_device_recognition(cdev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 904 | spin_unlock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 907 | static int ccw_device_move_to_sch(struct ccw_device *cdev, |
| 908 | struct subchannel *sch) |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 909 | { |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 910 | struct subchannel *old_sch; |
Sebastian Ott | 0c609fc | 2009-12-07 12:51:37 +0100 | [diff] [blame] | 911 | int rc, old_enabled = 0; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 912 | |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 913 | old_sch = to_subchannel(cdev->dev.parent); |
| 914 | /* Obtain child reference for new parent. */ |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 915 | if (!get_device(&sch->dev)) |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 916 | return -ENODEV; |
Sebastian Ott | 0c609fc | 2009-12-07 12:51:37 +0100 | [diff] [blame] | 917 | |
| 918 | if (!sch_is_pseudo_sch(old_sch)) { |
| 919 | spin_lock_irq(old_sch->lock); |
| 920 | old_enabled = old_sch->schib.pmcw.ena; |
| 921 | rc = 0; |
| 922 | if (old_enabled) |
| 923 | rc = cio_disable_subchannel(old_sch); |
| 924 | spin_unlock_irq(old_sch->lock); |
| 925 | if (rc == -EBUSY) { |
| 926 | /* Release child reference for new parent. */ |
| 927 | put_device(&sch->dev); |
| 928 | return rc; |
| 929 | } |
| 930 | } |
| 931 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 932 | mutex_lock(&sch->reg_mutex); |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 933 | rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 934 | mutex_unlock(&sch->reg_mutex); |
| 935 | if (rc) { |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 936 | CIO_MSG_EVENT(0, "device_move(0.%x.%04x,0.%x.%04x)=%d\n", |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 937 | cdev->private->dev_id.ssid, |
| 938 | cdev->private->dev_id.devno, sch->schid.ssid, |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 939 | sch->schib.pmcw.dev, rc); |
Sebastian Ott | 0c609fc | 2009-12-07 12:51:37 +0100 | [diff] [blame] | 940 | if (old_enabled) { |
| 941 | /* Try to reenable the old subchannel. */ |
| 942 | spin_lock_irq(old_sch->lock); |
| 943 | cio_enable_subchannel(old_sch, (u32)(addr_t)old_sch); |
| 944 | spin_unlock_irq(old_sch->lock); |
| 945 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 946 | /* Release child reference for new parent. */ |
Cornelia Huck | 6eff208 | 2008-12-25 13:39:07 +0100 | [diff] [blame] | 947 | put_device(&sch->dev); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 948 | return rc; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 949 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 950 | /* Clean up old subchannel. */ |
| 951 | if (!sch_is_pseudo_sch(old_sch)) { |
| 952 | spin_lock_irq(old_sch->lock); |
| 953 | sch_set_cdev(old_sch, NULL); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 954 | spin_unlock_irq(old_sch->lock); |
| 955 | css_schedule_eval(old_sch->schid); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 956 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 957 | /* Release child reference for old parent. */ |
| 958 | put_device(&old_sch->dev); |
| 959 | /* Initialize new subchannel. */ |
| 960 | spin_lock_irq(sch->lock); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 961 | cdev->ccwlock = sch->lock; |
| 962 | if (!sch_is_pseudo_sch(sch)) |
| 963 | sch_set_cdev(sch, cdev); |
| 964 | spin_unlock_irq(sch->lock); |
| 965 | if (!sch_is_pseudo_sch(sch)) |
| 966 | css_update_ssd_info(sch); |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static int ccw_device_move_to_orph(struct ccw_device *cdev) |
| 971 | { |
| 972 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 973 | struct channel_subsystem *css = to_css(sch->dev.parent); |
| 974 | |
| 975 | return ccw_device_move_to_sch(cdev, css->pseudo_subchannel); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 976 | } |
| 977 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 978 | static void io_subchannel_irq(struct subchannel *sch) |
| 979 | { |
| 980 | struct ccw_device *cdev; |
| 981 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 982 | cdev = sch_get_cdev(sch); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 983 | |
Sebastian Ott | efd986d | 2009-09-11 10:28:18 +0200 | [diff] [blame] | 984 | CIO_TRACE_EVENT(6, "IRQ"); |
| 985 | CIO_TRACE_EVENT(6, dev_name(&sch->dev)); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 986 | if (cdev) |
| 987 | dev_fsm_event(cdev, DEV_EVENT_INTERRUPT); |
Peter Oberparleiter | de400d6 | 2011-10-30 15:16:04 +0100 | [diff] [blame] | 988 | else |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 989 | inc_irq_stat(IRQIO_CIO); |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 990 | } |
| 991 | |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 992 | void io_subchannel_init_config(struct subchannel *sch) |
| 993 | { |
| 994 | memset(&sch->config, 0, sizeof(sch->config)); |
| 995 | sch->config.csense = 1; |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 996 | } |
| 997 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 998 | static void io_subchannel_init_fields(struct subchannel *sch) |
| 999 | { |
| 1000 | if (cio_is_console(sch->schid)) |
| 1001 | sch->opm = 0xff; |
| 1002 | else |
| 1003 | sch->opm = chp_get_sch_opm(sch); |
| 1004 | sch->lpm = sch->schib.pmcw.pam & sch->opm; |
Cornelia Huck | 3a3fc29 | 2008-07-14 09:58:58 +0200 | [diff] [blame] | 1005 | sch->isc = cio_is_console(sch->schid) ? CONSOLE_ISC : IO_SCH_ISC; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1006 | |
| 1007 | CIO_MSG_EVENT(6, "Detected device %04x on subchannel 0.%x.%04X" |
| 1008 | " - PIM = %02X, PAM = %02X, POM = %02X\n", |
| 1009 | sch->schib.pmcw.dev, sch->schid.ssid, |
| 1010 | sch->schid.sch_no, sch->schib.pmcw.pim, |
| 1011 | sch->schib.pmcw.pam, sch->schib.pmcw.pom); |
Sebastian Ott | 13952ec | 2008-12-25 13:39:13 +0100 | [diff] [blame] | 1012 | |
| 1013 | io_subchannel_init_config(sch); |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1016 | /* |
| 1017 | * Note: We always return 0 so that we bind to the device even on error. |
| 1018 | * This is needed so that our remove function is called on unregister. |
| 1019 | */ |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1020 | static int io_subchannel_probe(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | { |
Sebastian Ott | f92519e | 2011-03-15 17:08:27 +0100 | [diff] [blame] | 1022 | struct io_subchannel_private *io_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | struct ccw_device *cdev; |
| 1024 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
Peter Oberparleiter | 6d7c5af | 2009-10-14 12:43:50 +0200 | [diff] [blame] | 1026 | if (cio_is_console(sch->schid)) { |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1027 | rc = sysfs_create_group(&sch->dev.kobj, |
| 1028 | &io_subchannel_attr_group); |
| 1029 | if (rc) |
| 1030 | CIO_MSG_EVENT(0, "Failed to create io subchannel " |
| 1031 | "attributes for subchannel " |
| 1032 | "0.%x.%04x (rc=%d)\n", |
| 1033 | sch->schid.ssid, sch->schid.sch_no, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | /* |
Peter Oberparleiter | 6d7c5af | 2009-10-14 12:43:50 +0200 | [diff] [blame] | 1035 | * The console subchannel already has an associated ccw_device. |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1036 | * Throw the delayed uevent for the subchannel, register |
Peter Oberparleiter | 6d7c5af | 2009-10-14 12:43:50 +0200 | [diff] [blame] | 1037 | * the ccw_device and exit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | */ |
Ming Lei | f67f129 | 2009-03-01 21:10:49 +0800 | [diff] [blame] | 1039 | dev_set_uevent_suppress(&sch->dev, 0); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1040 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
Peter Oberparleiter | 6d7c5af | 2009-10-14 12:43:50 +0200 | [diff] [blame] | 1041 | cdev = sch_get_cdev(sch); |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 1042 | rc = ccw_device_add(cdev); |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1043 | if (rc) { |
| 1044 | /* Release online reference. */ |
| 1045 | put_device(&cdev->dev); |
| 1046 | goto out_schedule; |
| 1047 | } |
Sebastian Ott | 0ad8f714a | 2013-04-13 13:06:27 +0200 | [diff] [blame] | 1048 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1049 | wake_up(&ccw_device_init_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | return 0; |
| 1051 | } |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1052 | io_subchannel_init_fields(sch); |
Sebastian Ott | f444cc0 | 2008-12-25 13:39:14 +0100 | [diff] [blame] | 1053 | rc = cio_commit_config(sch); |
| 1054 | if (rc) |
| 1055 | goto out_schedule; |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1056 | rc = sysfs_create_group(&sch->dev.kobj, |
| 1057 | &io_subchannel_attr_group); |
| 1058 | if (rc) |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1059 | goto out_schedule; |
Cornelia Huck | cd6b4f2 | 2008-01-26 14:10:43 +0100 | [diff] [blame] | 1060 | /* Allocate I/O subchannel private data. */ |
Sebastian Ott | f92519e | 2011-03-15 17:08:27 +0100 | [diff] [blame] | 1061 | io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA); |
| 1062 | if (!io_priv) |
Peter Oberparleiter | 48e4c38 | 2009-12-07 12:51:15 +0100 | [diff] [blame] | 1063 | goto out_schedule; |
Sebastian Ott | f92519e | 2011-03-15 17:08:27 +0100 | [diff] [blame] | 1064 | |
| 1065 | set_io_private(sch, io_priv); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1066 | css_schedule_eval(sch->schid); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1067 | return 0; |
Peter Oberparleiter | 48e4c38 | 2009-12-07 12:51:15 +0100 | [diff] [blame] | 1068 | |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1069 | out_schedule: |
Peter Oberparleiter | 390935a | 2009-12-07 12:51:18 +0100 | [diff] [blame] | 1070 | spin_lock_irq(sch->lock); |
| 1071 | css_sched_sch_todo(sch, SCH_TODO_UNREG); |
| 1072 | spin_unlock_irq(sch->lock); |
Cornelia Huck | 90ed2b6 | 2008-12-25 13:39:09 +0100 | [diff] [blame] | 1073 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
Sebastian Ott | 135a8b4 | 2018-03-15 15:03:43 +0100 | [diff] [blame^] | 1076 | static int io_subchannel_remove(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | { |
Sebastian Ott | f92519e | 2011-03-15 17:08:27 +0100 | [diff] [blame] | 1078 | struct io_subchannel_private *io_priv = to_io_private(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | struct ccw_device *cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1081 | cdev = sch_get_cdev(sch); |
| 1082 | if (!cdev) |
Peter Oberparleiter | 48e4c38 | 2009-12-07 12:51:15 +0100 | [diff] [blame] | 1083 | goto out_free; |
Sebastian Ott | 135a8b4 | 2018-03-15 15:03:43 +0100 | [diff] [blame^] | 1084 | |
| 1085 | ccw_device_unregister(cdev); |
| 1086 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1087 | sch_set_cdev(sch, NULL); |
Sebastian Ott | f92519e | 2011-03-15 17:08:27 +0100 | [diff] [blame] | 1088 | set_io_private(sch, NULL); |
Sebastian Ott | 135a8b4 | 2018-03-15 15:03:43 +0100 | [diff] [blame^] | 1089 | spin_unlock_irq(sch->lock); |
Peter Oberparleiter | 48e4c38 | 2009-12-07 12:51:15 +0100 | [diff] [blame] | 1090 | out_free: |
Sebastian Ott | f92519e | 2011-03-15 17:08:27 +0100 | [diff] [blame] | 1091 | kfree(io_priv); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 1092 | sysfs_remove_group(&sch->dev.kobj, &io_subchannel_attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | return 0; |
| 1094 | } |
| 1095 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame] | 1096 | static void io_subchannel_verify(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | { |
| 1098 | struct ccw_device *cdev; |
| 1099 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1100 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | if (cdev) |
| 1102 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1103 | } |
| 1104 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1105 | static void io_subchannel_terminate_path(struct subchannel *sch, u8 mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | { |
| 1107 | struct ccw_device *cdev; |
| 1108 | |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1109 | cdev = sch_get_cdev(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | if (!cdev) |
| 1111 | return; |
Peter Oberparleiter | 4257aae | 2009-12-07 12:51:29 +0100 | [diff] [blame] | 1112 | if (cio_update_schib(sch)) |
| 1113 | goto err; |
| 1114 | /* Check for I/O on path. */ |
| 1115 | if (scsw_actl(&sch->schib.scsw) == 0 || sch->schib.pmcw.lpum != mask) |
| 1116 | goto out; |
| 1117 | if (cdev->private->state == DEV_STATE_ONLINE) { |
| 1118 | ccw_device_kill_io(cdev); |
| 1119 | goto out; |
| 1120 | } |
| 1121 | if (cio_clear(sch)) |
| 1122 | goto err; |
| 1123 | out: |
| 1124 | /* Trigger path verification. */ |
| 1125 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1126 | return; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1127 | |
Peter Oberparleiter | 4257aae | 2009-12-07 12:51:29 +0100 | [diff] [blame] | 1128 | err: |
| 1129 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 1132 | static int io_subchannel_chp_event(struct subchannel *sch, |
| 1133 | struct chp_link *link, int event) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1134 | { |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 1135 | struct ccw_device *cdev = sch_get_cdev(sch); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1136 | int mask; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1137 | |
Cornelia Huck | 99611f8 | 2008-07-14 09:59:02 +0200 | [diff] [blame] | 1138 | mask = chp_ssd_get_mask(&sch->ssd_info, link); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1139 | if (!mask) |
| 1140 | return 0; |
| 1141 | switch (event) { |
| 1142 | case CHP_VARY_OFF: |
| 1143 | sch->opm &= ~mask; |
| 1144 | sch->lpm &= ~mask; |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 1145 | if (cdev) |
| 1146 | cdev->private->path_gone_mask |= mask; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1147 | io_subchannel_terminate_path(sch, mask); |
| 1148 | break; |
| 1149 | case CHP_VARY_ON: |
| 1150 | sch->opm |= mask; |
| 1151 | sch->lpm |= mask; |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 1152 | if (cdev) |
| 1153 | cdev->private->path_new_mask |= mask; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1154 | io_subchannel_verify(sch); |
| 1155 | break; |
| 1156 | case CHP_OFFLINE: |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 1157 | if (cio_update_schib(sch)) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1158 | return -ENODEV; |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 1159 | if (cdev) |
| 1160 | cdev->private->path_gone_mask |= mask; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1161 | io_subchannel_terminate_path(sch, mask); |
| 1162 | break; |
| 1163 | case CHP_ONLINE: |
Sebastian Ott | cdb912a | 2008-12-25 13:39:12 +0100 | [diff] [blame] | 1164 | if (cio_update_schib(sch)) |
| 1165 | return -ENODEV; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1166 | sch->lpm |= mask & sch->opm; |
Sebastian Ott | 585b954 | 2010-10-25 16:10:34 +0200 | [diff] [blame] | 1167 | if (cdev) |
| 1168 | cdev->private->path_new_mask |= mask; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1169 | io_subchannel_verify(sch); |
| 1170 | break; |
| 1171 | } |
| 1172 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Sebastian Ott | 6e9a0f6 | 2009-12-07 12:51:38 +0100 | [diff] [blame] | 1175 | static void io_subchannel_quiesce(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | struct ccw_device *cdev; |
| 1178 | int ret; |
| 1179 | |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 1180 | spin_lock_irq(sch->lock); |
Cornelia Huck | db6a642 | 2008-01-26 14:10:46 +0100 | [diff] [blame] | 1181 | cdev = sch_get_cdev(sch); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1182 | if (cio_is_console(sch->schid)) |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 1183 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | if (!sch->schib.pmcw.ena) |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 1185 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | ret = cio_disable_subchannel(sch); |
| 1187 | if (ret != -EBUSY) |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 1188 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | if (cdev->handler) |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 1190 | cdev->handler(cdev, cdev->private->intparm, ERR_PTR(-EIO)); |
| 1191 | while (ret == -EBUSY) { |
| 1192 | cdev->private->state = DEV_STATE_QUIESCE; |
Peter Oberparleiter | 376ae47 | 2010-10-25 16:10:44 +0200 | [diff] [blame] | 1193 | cdev->private->iretry = 255; |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 1194 | ret = ccw_device_cancel_halt_clear(cdev); |
| 1195 | if (ret == -EBUSY) { |
| 1196 | ccw_device_set_timeout(cdev, HZ/10); |
| 1197 | spin_unlock_irq(sch->lock); |
| 1198 | wait_event(cdev->private->wait_q, |
| 1199 | cdev->private->state != DEV_STATE_QUIESCE); |
| 1200 | spin_lock_irq(sch->lock); |
| 1201 | } |
| 1202 | ret = cio_disable_subchannel(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | } |
Sebastian Ott | 56e6b79 | 2009-12-07 12:51:35 +0100 | [diff] [blame] | 1204 | out_unlock: |
| 1205 | spin_unlock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Sebastian Ott | 6e9a0f6 | 2009-12-07 12:51:38 +0100 | [diff] [blame] | 1208 | static void io_subchannel_shutdown(struct subchannel *sch) |
| 1209 | { |
| 1210 | io_subchannel_quiesce(sch); |
| 1211 | } |
| 1212 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1213 | static int device_is_disconnected(struct ccw_device *cdev) |
| 1214 | { |
| 1215 | if (!cdev) |
| 1216 | return 0; |
| 1217 | return (cdev->private->state == DEV_STATE_DISCONNECTED || |
| 1218 | cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID); |
| 1219 | } |
| 1220 | |
| 1221 | static int recovery_check(struct device *dev, void *data) |
| 1222 | { |
| 1223 | struct ccw_device *cdev = to_ccwdev(dev); |
Sebastian Ott | 55fb734 | 2017-09-14 13:55:22 +0200 | [diff] [blame] | 1224 | struct subchannel *sch; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1225 | int *redo = data; |
| 1226 | |
| 1227 | spin_lock_irq(cdev->ccwlock); |
| 1228 | switch (cdev->private->state) { |
Sebastian Ott | 55fb734 | 2017-09-14 13:55:22 +0200 | [diff] [blame] | 1229 | case DEV_STATE_ONLINE: |
| 1230 | sch = to_subchannel(cdev->dev.parent); |
| 1231 | if ((sch->schib.pmcw.pam & sch->opm) == sch->vpm) |
| 1232 | break; |
| 1233 | /* fall through */ |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1234 | case DEV_STATE_DISCONNECTED: |
| 1235 | CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n", |
| 1236 | cdev->private->dev_id.ssid, |
| 1237 | cdev->private->dev_id.devno); |
| 1238 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1239 | *redo = 1; |
| 1240 | break; |
| 1241 | case DEV_STATE_DISCONNECTED_SENSE_ID: |
| 1242 | *redo = 1; |
| 1243 | break; |
| 1244 | } |
| 1245 | spin_unlock_irq(cdev->ccwlock); |
| 1246 | |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | static void recovery_work_func(struct work_struct *unused) |
| 1251 | { |
| 1252 | int redo = 0; |
| 1253 | |
| 1254 | bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check); |
| 1255 | if (redo) { |
| 1256 | spin_lock_irq(&recovery_lock); |
| 1257 | if (!timer_pending(&recovery_timer)) { |
| 1258 | if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1) |
| 1259 | recovery_phase++; |
| 1260 | mod_timer(&recovery_timer, jiffies + |
| 1261 | recovery_delay[recovery_phase] * HZ); |
| 1262 | } |
| 1263 | spin_unlock_irq(&recovery_lock); |
| 1264 | } else |
Sebastian Ott | 55fb734 | 2017-09-14 13:55:22 +0200 | [diff] [blame] | 1265 | CIO_MSG_EVENT(3, "recovery: end\n"); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static DECLARE_WORK(recovery_work, recovery_work_func); |
| 1269 | |
Kees Cook | 846d0c6 | 2017-10-16 16:43:25 -0700 | [diff] [blame] | 1270 | static void recovery_func(struct timer_list *unused) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1271 | { |
| 1272 | /* |
| 1273 | * We can't do our recovery in softirq context and it's not |
| 1274 | * performance critical, so we schedule it. |
| 1275 | */ |
| 1276 | schedule_work(&recovery_work); |
| 1277 | } |
| 1278 | |
Sebastian Ott | 55fb734 | 2017-09-14 13:55:22 +0200 | [diff] [blame] | 1279 | void ccw_device_schedule_recovery(void) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1280 | { |
| 1281 | unsigned long flags; |
| 1282 | |
Sebastian Ott | 55fb734 | 2017-09-14 13:55:22 +0200 | [diff] [blame] | 1283 | CIO_MSG_EVENT(3, "recovery: schedule\n"); |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1284 | spin_lock_irqsave(&recovery_lock, flags); |
| 1285 | if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) { |
| 1286 | recovery_phase = 0; |
| 1287 | mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ); |
| 1288 | } |
| 1289 | spin_unlock_irqrestore(&recovery_lock, flags); |
| 1290 | } |
| 1291 | |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 1292 | static int purge_fn(struct device *dev, void *data) |
| 1293 | { |
| 1294 | struct ccw_device *cdev = to_ccwdev(dev); |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1295 | struct ccw_dev_id *id = &cdev->private->dev_id; |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 1296 | |
| 1297 | spin_lock_irq(cdev->ccwlock); |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1298 | if (is_blacklisted(id->ssid, id->devno) && |
Peter Oberparleiter | a2fc848 | 2011-04-04 09:43:32 +0200 | [diff] [blame] | 1299 | (cdev->private->state == DEV_STATE_OFFLINE) && |
| 1300 | (atomic_cmpxchg(&cdev->private->onoff, 0, 1) == 0)) { |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1301 | CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", id->ssid, |
| 1302 | id->devno); |
| 1303 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Peter Oberparleiter | a2fc848 | 2011-04-04 09:43:32 +0200 | [diff] [blame] | 1304 | atomic_set(&cdev->private->onoff, 0); |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1305 | } |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 1306 | spin_unlock_irq(cdev->ccwlock); |
Peter Oberparleiter | ecf5d9e | 2008-10-10 21:33:06 +0200 | [diff] [blame] | 1307 | /* Abort loop in case of pending signal. */ |
| 1308 | if (signal_pending(current)) |
| 1309 | return -EINTR; |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
| 1313 | |
| 1314 | /** |
| 1315 | * ccw_purge_blacklisted - purge unused, blacklisted devices |
| 1316 | * |
| 1317 | * Unregister all ccw devices that are offline and on the blacklist. |
| 1318 | */ |
| 1319 | int ccw_purge_blacklisted(void) |
| 1320 | { |
| 1321 | CIO_MSG_EVENT(2, "ccw: purging blacklisted devices\n"); |
| 1322 | bus_for_each_dev(&ccw_bus_type, NULL, NULL, purge_fn); |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
Peter Oberparleiter | 6afcc77 | 2009-10-06 10:34:02 +0200 | [diff] [blame] | 1326 | void ccw_device_set_disconnected(struct ccw_device *cdev) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1327 | { |
| 1328 | if (!cdev) |
| 1329 | return; |
| 1330 | ccw_device_set_timeout(cdev, 0); |
| 1331 | cdev->private->flags.fake_irb = 0; |
| 1332 | cdev->private->state = DEV_STATE_DISCONNECTED; |
| 1333 | if (cdev->online) |
| 1334 | ccw_device_schedule_recovery(); |
| 1335 | } |
| 1336 | |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1337 | void ccw_device_set_notoper(struct ccw_device *cdev) |
| 1338 | { |
| 1339 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 1340 | |
| 1341 | CIO_TRACE_EVENT(2, "notoper"); |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 1342 | CIO_TRACE_EVENT(2, dev_name(&sch->dev)); |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1343 | ccw_device_set_timeout(cdev, 0); |
| 1344 | cio_disable_subchannel(sch); |
| 1345 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1346 | } |
| 1347 | |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1348 | enum io_sch_action { |
| 1349 | IO_SCH_UNREG, |
| 1350 | IO_SCH_ORPH_UNREG, |
| 1351 | IO_SCH_ATTACH, |
| 1352 | IO_SCH_UNREG_ATTACH, |
| 1353 | IO_SCH_ORPH_ATTACH, |
| 1354 | IO_SCH_REPROBE, |
| 1355 | IO_SCH_VERIFY, |
| 1356 | IO_SCH_DISC, |
| 1357 | IO_SCH_NOP, |
| 1358 | }; |
| 1359 | |
| 1360 | static enum io_sch_action sch_get_action(struct subchannel *sch) |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1361 | { |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1362 | struct ccw_device *cdev; |
| 1363 | |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1364 | cdev = sch_get_cdev(sch); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1365 | if (cio_update_schib(sch)) { |
| 1366 | /* Not operational. */ |
| 1367 | if (!cdev) |
| 1368 | return IO_SCH_UNREG; |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 1369 | if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK) |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1370 | return IO_SCH_UNREG; |
| 1371 | return IO_SCH_ORPH_UNREG; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1372 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1373 | /* Operational. */ |
| 1374 | if (!cdev) |
| 1375 | return IO_SCH_ATTACH; |
| 1376 | if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) { |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 1377 | if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK) |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1378 | return IO_SCH_UNREG_ATTACH; |
| 1379 | return IO_SCH_ORPH_ATTACH; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1380 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1381 | if ((sch->schib.pmcw.pam & sch->opm) == 0) { |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 1382 | if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK) |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1383 | return IO_SCH_UNREG; |
| 1384 | return IO_SCH_DISC; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1385 | } |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1386 | if (device_is_disconnected(cdev)) |
| 1387 | return IO_SCH_REPROBE; |
Sebastian Ott | 31370f75 | 2012-10-24 11:22:52 +0200 | [diff] [blame] | 1388 | if (cdev->online && !cdev->private->flags.resuming) |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1389 | return IO_SCH_VERIFY; |
Sebastian Ott | 43d0be7 | 2012-09-05 14:19:42 +0200 | [diff] [blame] | 1390 | if (cdev->private->state == DEV_STATE_NOT_OPER) |
| 1391 | return IO_SCH_UNREG_ATTACH; |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1392 | return IO_SCH_NOP; |
| 1393 | } |
| 1394 | |
| 1395 | /** |
| 1396 | * io_subchannel_sch_event - process subchannel event |
| 1397 | * @sch: subchannel |
| 1398 | * @process: non-zero if function is called in process context |
| 1399 | * |
| 1400 | * An unspecified event occurred for this subchannel. Adjust data according |
| 1401 | * to the current operational state of the subchannel and device. Return |
| 1402 | * zero when the event has been handled sufficiently or -EAGAIN when this |
| 1403 | * function should be called again in process context. |
| 1404 | */ |
| 1405 | static int io_subchannel_sch_event(struct subchannel *sch, int process) |
| 1406 | { |
| 1407 | unsigned long flags; |
| 1408 | struct ccw_device *cdev; |
| 1409 | struct ccw_dev_id dev_id; |
| 1410 | enum io_sch_action action; |
| 1411 | int rc = -EAGAIN; |
| 1412 | |
| 1413 | spin_lock_irqsave(sch->lock, flags); |
| 1414 | if (!device_is_registered(&sch->dev)) |
| 1415 | goto out_unlock; |
Peter Oberparleiter | 390935a | 2009-12-07 12:51:18 +0100 | [diff] [blame] | 1416 | if (work_pending(&sch->todo_work)) |
| 1417 | goto out_unlock; |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1418 | cdev = sch_get_cdev(sch); |
| 1419 | if (cdev && work_pending(&cdev->private->todo_work)) |
| 1420 | goto out_unlock; |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1421 | action = sch_get_action(sch); |
| 1422 | CIO_MSG_EVENT(2, "event: sch 0.%x.%04x, process=%d, action=%d\n", |
| 1423 | sch->schid.ssid, sch->schid.sch_no, process, |
| 1424 | action); |
| 1425 | /* Perform immediate actions while holding the lock. */ |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1426 | switch (action) { |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1427 | case IO_SCH_REPROBE: |
| 1428 | /* Trigger device recognition. */ |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1429 | ccw_device_trigger_reprobe(cdev); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1430 | rc = 0; |
| 1431 | goto out_unlock; |
| 1432 | case IO_SCH_VERIFY: |
| 1433 | /* Trigger path verification. */ |
| 1434 | io_subchannel_verify(sch); |
| 1435 | rc = 0; |
| 1436 | goto out_unlock; |
| 1437 | case IO_SCH_DISC: |
| 1438 | ccw_device_set_disconnected(cdev); |
| 1439 | rc = 0; |
| 1440 | goto out_unlock; |
| 1441 | case IO_SCH_ORPH_UNREG: |
| 1442 | case IO_SCH_ORPH_ATTACH: |
Peter Oberparleiter | 6afcc77 | 2009-10-06 10:34:02 +0200 | [diff] [blame] | 1443 | ccw_device_set_disconnected(cdev); |
Peter Oberparleiter | 91c3691 | 2008-08-21 19:46:39 +0200 | [diff] [blame] | 1444 | break; |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1445 | case IO_SCH_UNREG_ATTACH: |
| 1446 | case IO_SCH_UNREG: |
Sebastian Ott | 16d2ce2 | 2010-11-10 10:05:53 +0100 | [diff] [blame] | 1447 | if (!cdev) |
| 1448 | break; |
| 1449 | if (cdev->private->state == DEV_STATE_SENSE_ID) { |
| 1450 | /* |
| 1451 | * Note: delayed work triggered by this event |
| 1452 | * and repeated calls to sch_event are synchronized |
| 1453 | * by the above check for work_pending(cdev). |
| 1454 | */ |
| 1455 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 1456 | } else |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1457 | ccw_device_set_notoper(cdev); |
| 1458 | break; |
| 1459 | case IO_SCH_NOP: |
| 1460 | rc = 0; |
| 1461 | goto out_unlock; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1462 | default: |
| 1463 | break; |
| 1464 | } |
| 1465 | spin_unlock_irqrestore(sch->lock, flags); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1466 | /* All other actions require process context. */ |
| 1467 | if (!process) |
| 1468 | goto out; |
| 1469 | /* Handle attached ccw device. */ |
| 1470 | switch (action) { |
| 1471 | case IO_SCH_ORPH_UNREG: |
| 1472 | case IO_SCH_ORPH_ATTACH: |
| 1473 | /* Move ccw device to orphanage. */ |
| 1474 | rc = ccw_device_move_to_orph(cdev); |
| 1475 | if (rc) |
| 1476 | goto out; |
| 1477 | break; |
| 1478 | case IO_SCH_UNREG_ATTACH: |
Sebastian Ott | 3368ba2 | 2012-09-05 14:20:41 +0200 | [diff] [blame] | 1479 | spin_lock_irqsave(sch->lock, flags); |
Sebastian Ott | 74b6127 | 2010-10-25 16:10:26 +0200 | [diff] [blame] | 1480 | if (cdev->private->flags.resuming) { |
| 1481 | /* Device will be handled later. */ |
| 1482 | rc = 0; |
Sebastian Ott | 3368ba2 | 2012-09-05 14:20:41 +0200 | [diff] [blame] | 1483 | goto out_unlock; |
Sebastian Ott | 74b6127 | 2010-10-25 16:10:26 +0200 | [diff] [blame] | 1484 | } |
Sebastian Ott | 3368ba2 | 2012-09-05 14:20:41 +0200 | [diff] [blame] | 1485 | sch_set_cdev(sch, NULL); |
| 1486 | spin_unlock_irqrestore(sch->lock, flags); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1487 | /* Unregister ccw device. */ |
Sebastian Ott | 74b6127 | 2010-10-25 16:10:26 +0200 | [diff] [blame] | 1488 | ccw_device_unregister(cdev); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1489 | break; |
| 1490 | default: |
| 1491 | break; |
| 1492 | } |
| 1493 | /* Handle subchannel. */ |
| 1494 | switch (action) { |
| 1495 | case IO_SCH_ORPH_UNREG: |
| 1496 | case IO_SCH_UNREG: |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1497 | if (!cdev || !cdev->private->flags.resuming) |
| 1498 | css_sch_device_unregister(sch); |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1499 | break; |
| 1500 | case IO_SCH_ORPH_ATTACH: |
| 1501 | case IO_SCH_UNREG_ATTACH: |
| 1502 | case IO_SCH_ATTACH: |
| 1503 | dev_id.ssid = sch->schid.ssid; |
| 1504 | dev_id.devno = sch->schib.pmcw.dev; |
| 1505 | cdev = get_ccwdev_by_dev_id(&dev_id); |
| 1506 | if (!cdev) { |
| 1507 | sch_create_and_recog_new_device(sch); |
| 1508 | break; |
| 1509 | } |
| 1510 | rc = ccw_device_move_to_sch(cdev, sch); |
| 1511 | if (rc) { |
| 1512 | /* Release reference from get_ccwdev_by_dev_id() */ |
| 1513 | put_device(&cdev->dev); |
| 1514 | goto out; |
| 1515 | } |
| 1516 | spin_lock_irqsave(sch->lock, flags); |
| 1517 | ccw_device_trigger_reprobe(cdev); |
| 1518 | spin_unlock_irqrestore(sch->lock, flags); |
| 1519 | /* Release reference from get_ccwdev_by_dev_id() */ |
| 1520 | put_device(&cdev->dev); |
| 1521 | break; |
| 1522 | default: |
| 1523 | break; |
| 1524 | } |
| 1525 | return 0; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1526 | |
Peter Oberparleiter | 5d6e6b6 | 2009-12-07 12:51:17 +0100 | [diff] [blame] | 1527 | out_unlock: |
| 1528 | spin_unlock_irqrestore(sch->lock, flags); |
| 1529 | out: |
| 1530 | return rc; |
Cornelia Huck | c820de3 | 2008-07-14 09:58:45 +0200 | [diff] [blame] | 1531 | } |
| 1532 | |
Sebastian Ott | 137a14f | 2014-01-27 13:29:15 +0100 | [diff] [blame] | 1533 | static void ccw_device_set_int_class(struct ccw_device *cdev) |
| 1534 | { |
| 1535 | struct ccw_driver *cdrv = cdev->drv; |
| 1536 | |
| 1537 | /* Note: we interpret class 0 in this context as an uninitialized |
| 1538 | * field since it translates to a non-I/O interrupt class. */ |
| 1539 | if (cdrv->int_class != 0) |
| 1540 | cdev->private->int_class = cdrv->int_class; |
| 1541 | else |
| 1542 | cdev->private->int_class = IRQIO_CIO; |
| 1543 | } |
| 1544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | #ifdef CONFIG_CCW_CONSOLE |
Sebastian Ott | 1e53209 | 2014-01-27 13:28:10 +0100 | [diff] [blame] | 1546 | int __init ccw_device_enable_console(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | { |
Sebastian Ott | 1e53209 | 2014-01-27 13:28:10 +0100 | [diff] [blame] | 1548 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | int rc; |
| 1550 | |
Sebastian Ott | 1e53209 | 2014-01-27 13:28:10 +0100 | [diff] [blame] | 1551 | if (!cdev->drv || !cdev->handler) |
| 1552 | return -EINVAL; |
| 1553 | |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1554 | io_subchannel_init_fields(sch); |
Sebastian Ott | f444cc0 | 2008-12-25 13:39:14 +0100 | [diff] [blame] | 1555 | rc = cio_commit_config(sch); |
| 1556 | if (rc) |
| 1557 | return rc; |
Cornelia Huck | 0ae7a7b | 2008-07-14 09:58:43 +0200 | [diff] [blame] | 1558 | sch->driver = &io_subchannel_driver; |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 1559 | io_subchannel_recog(cdev, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | /* Now wait for the async. recognition to come to an end. */ |
| 1561 | spin_lock_irq(cdev->ccwlock); |
| 1562 | while (!dev_fsm_final_state(cdev)) |
Sebastian Ott | 188561a | 2013-04-13 12:53:21 +0200 | [diff] [blame] | 1563 | ccw_device_wait_idle(cdev); |
| 1564 | |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1565 | /* Hold on to an extra reference while device is online. */ |
| 1566 | get_device(&cdev->dev); |
| 1567 | rc = ccw_device_online(cdev); |
| 1568 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | goto out_unlock; |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | while (!dev_fsm_final_state(cdev)) |
Sebastian Ott | 188561a | 2013-04-13 12:53:21 +0200 | [diff] [blame] | 1572 | ccw_device_wait_idle(cdev); |
| 1573 | |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1574 | if (cdev->private->state == DEV_STATE_ONLINE) |
| 1575 | cdev->online = 1; |
| 1576 | else |
| 1577 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | out_unlock: |
| 1579 | spin_unlock_irq(cdev->ccwlock); |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1580 | if (rc) /* Give up online reference since onlining failed. */ |
| 1581 | put_device(&cdev->dev); |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 1582 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Sebastian Ott | 1e53209 | 2014-01-27 13:28:10 +0100 | [diff] [blame] | 1585 | struct ccw_device * __init ccw_device_create_console(struct ccw_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | { |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 1587 | struct io_subchannel_private *io_priv; |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1588 | struct ccw_device *cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | sch = cio_probe_console(); |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1592 | if (IS_ERR(sch)) |
| 1593 | return ERR_CAST(sch); |
Sebastian Ott | 863fc84 | 2013-04-13 13:01:50 +0200 | [diff] [blame] | 1594 | |
| 1595 | io_priv = kzalloc(sizeof(*io_priv), GFP_KERNEL | GFP_DMA); |
| 1596 | if (!io_priv) { |
| 1597 | put_device(&sch->dev); |
| 1598 | return ERR_PTR(-ENOMEM); |
| 1599 | } |
Sebastian Ott | 2c3e7e1 | 2014-06-11 13:06:57 +0200 | [diff] [blame] | 1600 | set_io_private(sch, io_priv); |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1601 | cdev = io_subchannel_create_ccwdev(sch); |
| 1602 | if (IS_ERR(cdev)) { |
| 1603 | put_device(&sch->dev); |
| 1604 | kfree(io_priv); |
| 1605 | return cdev; |
| 1606 | } |
Sebastian Ott | 2253e8d | 2014-01-27 13:26:10 +0100 | [diff] [blame] | 1607 | cdev->drv = drv; |
Sebastian Ott | 137a14f | 2014-01-27 13:29:15 +0100 | [diff] [blame] | 1608 | ccw_device_set_int_class(cdev); |
Sebastian Ott | afdfed0 | 2013-04-13 13:03:03 +0200 | [diff] [blame] | 1609 | return cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | } |
Cornelia Huck | 1f4e7ed | 2008-10-10 21:33:14 +0200 | [diff] [blame] | 1611 | |
Sebastian Ott | 1e53209 | 2014-01-27 13:28:10 +0100 | [diff] [blame] | 1612 | void __init ccw_device_destroy_console(struct ccw_device *cdev) |
| 1613 | { |
| 1614 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 1615 | struct io_subchannel_private *io_priv = to_io_private(sch); |
| 1616 | |
| 1617 | set_io_private(sch, NULL); |
| 1618 | put_device(&sch->dev); |
| 1619 | put_device(&cdev->dev); |
| 1620 | kfree(io_priv); |
| 1621 | } |
| 1622 | |
Sebastian Ott | 188561a | 2013-04-13 12:53:21 +0200 | [diff] [blame] | 1623 | /** |
| 1624 | * ccw_device_wait_idle() - busy wait for device to become idle |
| 1625 | * @cdev: ccw device |
| 1626 | * |
| 1627 | * Poll until activity control is zero, that is, no function or data |
| 1628 | * transfer is pending/active. |
| 1629 | * Called with device lock being held. |
| 1630 | */ |
| 1631 | void ccw_device_wait_idle(struct ccw_device *cdev) |
| 1632 | { |
| 1633 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 1634 | |
| 1635 | while (1) { |
| 1636 | cio_tsch(sch); |
| 1637 | if (sch->schib.scsw.cmd.actl == 0) |
| 1638 | break; |
| 1639 | udelay_simple(100); |
| 1640 | } |
| 1641 | } |
| 1642 | |
Martin Schwidefsky | 6664845 | 2009-06-16 10:30:28 +0200 | [diff] [blame] | 1643 | static int ccw_device_pm_restore(struct device *dev); |
| 1644 | |
Sebastian Ott | f10ccca | 2013-04-13 12:56:51 +0200 | [diff] [blame] | 1645 | int ccw_device_force_console(struct ccw_device *cdev) |
Martin Schwidefsky | 6664845 | 2009-06-16 10:30:28 +0200 | [diff] [blame] | 1646 | { |
Sebastian Ott | f10ccca | 2013-04-13 12:56:51 +0200 | [diff] [blame] | 1647 | return ccw_device_pm_restore(&cdev->dev); |
Martin Schwidefsky | 6664845 | 2009-06-16 10:30:28 +0200 | [diff] [blame] | 1648 | } |
| 1649 | EXPORT_SYMBOL_GPL(ccw_device_force_console); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | #endif |
| 1651 | |
| 1652 | /* |
| 1653 | * get ccw_device matching the busid, but only if owned by cdrv |
| 1654 | */ |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1655 | static int |
| 1656 | __ccwdev_check_busid(struct device *dev, void *id) |
| 1657 | { |
| 1658 | char *bus_id; |
| 1659 | |
Cornelia Huck | 12975ae | 2006-10-11 15:31:47 +0200 | [diff] [blame] | 1660 | bus_id = id; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1661 | |
Kay Sievers | 98df67b | 2008-12-25 13:38:55 +0100 | [diff] [blame] | 1662 | return (strcmp(bus_id, dev_name(dev)) == 0); |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1666 | /** |
| 1667 | * get_ccwdev_by_busid() - obtain device from a bus id |
| 1668 | * @cdrv: driver the device is owned by |
| 1669 | * @bus_id: bus id of the device to be searched |
| 1670 | * |
| 1671 | * This function searches all devices owned by @cdrv for a device with a bus |
| 1672 | * id matching @bus_id. |
| 1673 | * Returns: |
| 1674 | * If a match is found, its reference count of the found device is increased |
| 1675 | * and it is returned; else %NULL is returned. |
| 1676 | */ |
| 1677 | struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, |
| 1678 | const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | { |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1680 | struct device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Sebastian Ott | 9f30ea9 | 2012-01-24 13:35:02 -0500 | [diff] [blame] | 1682 | dev = driver_find_device(&cdrv->driver, NULL, (void *)bus_id, |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1683 | __ccwdev_check_busid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1685 | return dev ? to_ccwdev(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | /************************** device driver handling ************************/ |
| 1689 | |
| 1690 | /* This is the implementation of the ccw_driver class. The probe, remove |
| 1691 | * and release methods are initially very similar to the device_driver |
| 1692 | * implementations, with the difference that they have ccw_device |
| 1693 | * arguments. |
| 1694 | * |
| 1695 | * A ccw driver also contains the information that is needed for |
| 1696 | * device matching. |
| 1697 | */ |
| 1698 | static int |
| 1699 | ccw_device_probe (struct device *dev) |
| 1700 | { |
| 1701 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1702 | struct ccw_driver *cdrv = to_ccwdrv(dev->driver); |
| 1703 | int ret; |
| 1704 | |
| 1705 | cdev->drv = cdrv; /* to let the driver call _set_online */ |
Sebastian Ott | 137a14f | 2014-01-27 13:29:15 +0100 | [diff] [blame] | 1706 | ccw_device_set_int_class(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | if (ret) { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1709 | cdev->drv = NULL; |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 1710 | cdev->private->int_class = IRQIO_CIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | return ret; |
| 1712 | } |
| 1713 | |
| 1714 | return 0; |
| 1715 | } |
| 1716 | |
Sebastian Ott | 74bd0d8 | 2013-12-16 10:51:54 +0100 | [diff] [blame] | 1717 | static int ccw_device_remove(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | { |
| 1719 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1720 | struct ccw_driver *cdrv = cdev->drv; |
Sebastian Ott | 135a8b4 | 2018-03-15 15:03:43 +0100 | [diff] [blame^] | 1721 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | int ret; |
| 1723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | if (cdrv->remove) |
| 1725 | cdrv->remove(cdev); |
Sebastian Ott | 74bd0d8 | 2013-12-16 10:51:54 +0100 | [diff] [blame] | 1726 | |
| 1727 | spin_lock_irq(cdev->ccwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | if (cdev->online) { |
| 1729 | cdev->online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | ret = ccw_device_offline(cdev); |
| 1731 | spin_unlock_irq(cdev->ccwlock); |
| 1732 | if (ret == 0) |
| 1733 | wait_event(cdev->private->wait_q, |
| 1734 | dev_fsm_final_state(cdev)); |
| 1735 | else |
Michael Ernst | 139b83dd | 2008-05-07 09:22:54 +0200 | [diff] [blame] | 1736 | CIO_MSG_EVENT(0, "ccw_device_offline returned %d, " |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 1737 | "device 0.%x.%04x\n", |
| 1738 | ret, cdev->private->dev_id.ssid, |
| 1739 | cdev->private->dev_id.devno); |
Cornelia Huck | 9cd6742 | 2008-12-25 13:39:06 +0100 | [diff] [blame] | 1740 | /* Give up reference obtained in ccw_device_set_online(). */ |
| 1741 | put_device(&cdev->dev); |
Sebastian Ott | 74bd0d8 | 2013-12-16 10:51:54 +0100 | [diff] [blame] | 1742 | spin_lock_irq(cdev->ccwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | } |
| 1744 | ccw_device_set_timeout(cdev, 0); |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1745 | cdev->drv = NULL; |
Heiko Carstens | 420f42e | 2013-01-02 15:18:18 +0100 | [diff] [blame] | 1746 | cdev->private->int_class = IRQIO_CIO; |
Sebastian Ott | 135a8b4 | 2018-03-15 15:03:43 +0100 | [diff] [blame^] | 1747 | sch = to_subchannel(cdev->dev.parent); |
Sebastian Ott | 74bd0d8 | 2013-12-16 10:51:54 +0100 | [diff] [blame] | 1748 | spin_unlock_irq(cdev->ccwlock); |
Sebastian Ott | 135a8b4 | 2018-03-15 15:03:43 +0100 | [diff] [blame^] | 1749 | io_subchannel_quiesce(sch); |
Sebastian Ott | a6ef156 | 2015-09-07 19:51:39 +0200 | [diff] [blame] | 1750 | __disable_cmf(cdev); |
| 1751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | return 0; |
| 1753 | } |
| 1754 | |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1755 | static void ccw_device_shutdown(struct device *dev) |
| 1756 | { |
| 1757 | struct ccw_device *cdev; |
| 1758 | |
| 1759 | cdev = to_ccwdev(dev); |
| 1760 | if (cdev->drv && cdev->drv->shutdown) |
| 1761 | cdev->drv->shutdown(cdev); |
Sebastian Ott | 1bc6664 | 2015-09-15 13:11:42 +0200 | [diff] [blame] | 1762 | __disable_cmf(cdev); |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1763 | } |
| 1764 | |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1765 | static int ccw_device_pm_prepare(struct device *dev) |
| 1766 | { |
| 1767 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1768 | |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1769 | if (work_pending(&cdev->private->todo_work)) |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1770 | return -EAGAIN; |
| 1771 | /* Fail while device is being set online/offline. */ |
| 1772 | if (atomic_read(&cdev->private->onoff)) |
| 1773 | return -EAGAIN; |
| 1774 | |
| 1775 | if (cdev->online && cdev->drv && cdev->drv->prepare) |
| 1776 | return cdev->drv->prepare(cdev); |
| 1777 | |
| 1778 | return 0; |
| 1779 | } |
| 1780 | |
| 1781 | static void ccw_device_pm_complete(struct device *dev) |
| 1782 | { |
| 1783 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1784 | |
| 1785 | if (cdev->online && cdev->drv && cdev->drv->complete) |
| 1786 | cdev->drv->complete(cdev); |
| 1787 | } |
| 1788 | |
| 1789 | static int ccw_device_pm_freeze(struct device *dev) |
| 1790 | { |
| 1791 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1792 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 1793 | int ret, cm_enabled; |
| 1794 | |
| 1795 | /* Fail suspend while device is in transistional state. */ |
| 1796 | if (!dev_fsm_final_state(cdev)) |
| 1797 | return -EAGAIN; |
| 1798 | if (!cdev->online) |
| 1799 | return 0; |
| 1800 | if (cdev->drv && cdev->drv->freeze) { |
| 1801 | ret = cdev->drv->freeze(cdev); |
| 1802 | if (ret) |
| 1803 | return ret; |
| 1804 | } |
| 1805 | |
| 1806 | spin_lock_irq(sch->lock); |
| 1807 | cm_enabled = cdev->private->cmb != NULL; |
| 1808 | spin_unlock_irq(sch->lock); |
| 1809 | if (cm_enabled) { |
| 1810 | /* Don't have the css write on memory. */ |
| 1811 | ret = ccw_set_cmf(cdev, 0); |
| 1812 | if (ret) |
| 1813 | return ret; |
| 1814 | } |
| 1815 | /* From here on, disallow device driver I/O. */ |
| 1816 | spin_lock_irq(sch->lock); |
| 1817 | ret = cio_disable_subchannel(sch); |
| 1818 | spin_unlock_irq(sch->lock); |
| 1819 | |
| 1820 | return ret; |
| 1821 | } |
| 1822 | |
| 1823 | static int ccw_device_pm_thaw(struct device *dev) |
| 1824 | { |
| 1825 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1826 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 1827 | int ret, cm_enabled; |
| 1828 | |
| 1829 | if (!cdev->online) |
| 1830 | return 0; |
| 1831 | |
| 1832 | spin_lock_irq(sch->lock); |
| 1833 | /* Allow device driver I/O again. */ |
| 1834 | ret = cio_enable_subchannel(sch, (u32)(addr_t)sch); |
| 1835 | cm_enabled = cdev->private->cmb != NULL; |
| 1836 | spin_unlock_irq(sch->lock); |
| 1837 | if (ret) |
| 1838 | return ret; |
| 1839 | |
| 1840 | if (cm_enabled) { |
| 1841 | ret = ccw_set_cmf(cdev, 1); |
| 1842 | if (ret) |
| 1843 | return ret; |
| 1844 | } |
| 1845 | |
| 1846 | if (cdev->drv && cdev->drv->thaw) |
| 1847 | ret = cdev->drv->thaw(cdev); |
| 1848 | |
| 1849 | return ret; |
| 1850 | } |
| 1851 | |
| 1852 | static void __ccw_device_pm_restore(struct ccw_device *cdev) |
| 1853 | { |
| 1854 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1855 | |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1856 | spin_lock_irq(sch->lock); |
| 1857 | if (cio_is_console(sch->schid)) { |
| 1858 | cio_enable_subchannel(sch, (u32)(addr_t)sch); |
| 1859 | goto out_unlock; |
| 1860 | } |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1861 | /* |
| 1862 | * While we were sleeping, devices may have gone or become |
| 1863 | * available again. Kick re-detection. |
| 1864 | */ |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1865 | cdev->private->flags.resuming = 1; |
Sebastian Ott | b17295e | 2011-01-12 09:55:10 +0100 | [diff] [blame] | 1866 | cdev->private->path_new_mask = LPM_ANYPATH; |
Sebastian Ott | 817e500 | 2011-12-01 13:32:19 +0100 | [diff] [blame] | 1867 | css_sched_sch_todo(sch, SCH_TODO_EVAL); |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1868 | spin_unlock_irq(sch->lock); |
Sebastian Ott | 817e500 | 2011-12-01 13:32:19 +0100 | [diff] [blame] | 1869 | css_wait_for_slow_path(); |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1870 | |
| 1871 | /* cdev may have been moved to a different subchannel. */ |
| 1872 | sch = to_subchannel(cdev->dev.parent); |
| 1873 | spin_lock_irq(sch->lock); |
| 1874 | if (cdev->private->state != DEV_STATE_ONLINE && |
| 1875 | cdev->private->state != DEV_STATE_OFFLINE) |
| 1876 | goto out_unlock; |
| 1877 | |
Peter Oberparleiter | 736b5db | 2009-12-07 12:51:21 +0100 | [diff] [blame] | 1878 | ccw_device_recognition(cdev); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1879 | spin_unlock_irq(sch->lock); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1880 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev) || |
| 1881 | cdev->private->state == DEV_STATE_DISCONNECTED); |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1882 | spin_lock_irq(sch->lock); |
| 1883 | |
| 1884 | out_unlock: |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1885 | cdev->private->flags.resuming = 0; |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1886 | spin_unlock_irq(sch->lock); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | static int resume_handle_boxed(struct ccw_device *cdev) |
| 1890 | { |
| 1891 | cdev->private->state = DEV_STATE_BOXED; |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 1892 | if (ccw_device_notify(cdev, CIO_BOXED) == NOTIFY_OK) |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1893 | return 0; |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1894 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1895 | return -ENODEV; |
| 1896 | } |
| 1897 | |
| 1898 | static int resume_handle_disc(struct ccw_device *cdev) |
| 1899 | { |
| 1900 | cdev->private->state = DEV_STATE_DISCONNECTED; |
Sebastian Ott | 76e6fb4 | 2010-02-26 22:37:28 +0100 | [diff] [blame] | 1901 | if (ccw_device_notify(cdev, CIO_GONE) == NOTIFY_OK) |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1902 | return 0; |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1903 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1904 | return -ENODEV; |
| 1905 | } |
| 1906 | |
| 1907 | static int ccw_device_pm_restore(struct device *dev) |
| 1908 | { |
| 1909 | struct ccw_device *cdev = to_ccwdev(dev); |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1910 | struct subchannel *sch; |
| 1911 | int ret = 0; |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1912 | |
| 1913 | __ccw_device_pm_restore(cdev); |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1914 | sch = to_subchannel(cdev->dev.parent); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1915 | spin_lock_irq(sch->lock); |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1916 | if (cio_is_console(sch->schid)) |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1917 | goto out_restore; |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1918 | |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1919 | /* check recognition results */ |
| 1920 | switch (cdev->private->state) { |
| 1921 | case DEV_STATE_OFFLINE: |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1922 | case DEV_STATE_ONLINE: |
| 1923 | cdev->private->flags.donotify = 0; |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1924 | break; |
| 1925 | case DEV_STATE_BOXED: |
| 1926 | ret = resume_handle_boxed(cdev); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1927 | if (ret) |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1928 | goto out_unlock; |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1929 | goto out_restore; |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1930 | default: |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1931 | ret = resume_handle_disc(cdev); |
| 1932 | if (ret) |
| 1933 | goto out_unlock; |
| 1934 | goto out_restore; |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1935 | } |
| 1936 | /* check if the device type has changed */ |
| 1937 | if (!ccw_device_test_sense_data(cdev)) { |
| 1938 | ccw_device_update_sense_data(cdev); |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 1939 | ccw_device_sched_todo(cdev, CDEV_TODO_REBIND); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1940 | ret = -ENODEV; |
| 1941 | goto out_unlock; |
| 1942 | } |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1943 | if (!cdev->online) |
| 1944 | goto out_unlock; |
| 1945 | |
| 1946 | if (ccw_device_online(cdev)) { |
| 1947 | ret = resume_handle_disc(cdev); |
| 1948 | if (ret) |
| 1949 | goto out_unlock; |
| 1950 | goto out_restore; |
| 1951 | } |
| 1952 | spin_unlock_irq(sch->lock); |
| 1953 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 1954 | spin_lock_irq(sch->lock); |
| 1955 | |
| 1956 | if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_BAD) { |
| 1957 | ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); |
| 1958 | ret = -ENODEV; |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1959 | goto out_unlock; |
| 1960 | } |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1961 | |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1962 | /* reenable cmf, if needed */ |
| 1963 | if (cdev->private->cmb) { |
| 1964 | spin_unlock_irq(sch->lock); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1965 | ret = ccw_set_cmf(cdev, 1); |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1966 | spin_lock_irq(sch->lock); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1967 | if (ret) { |
Sebastian Ott | f014824 | 2009-09-11 10:28:23 +0200 | [diff] [blame] | 1968 | CIO_MSG_EVENT(2, "resume: cdev 0.%x.%04x: cmf failed " |
| 1969 | "(rc=%d)\n", cdev->private->dev_id.ssid, |
| 1970 | cdev->private->dev_id.devno, ret); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1971 | ret = 0; |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | out_restore: |
Sebastian Ott | 0d01bb8 | 2010-02-26 22:37:29 +0100 | [diff] [blame] | 1976 | spin_unlock_irq(sch->lock); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1977 | if (cdev->online && cdev->drv && cdev->drv->restore) |
| 1978 | ret = cdev->drv->restore(cdev); |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1979 | return ret; |
| 1980 | |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1981 | out_unlock: |
| 1982 | spin_unlock_irq(sch->lock); |
| 1983 | return ret; |
| 1984 | } |
| 1985 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1986 | static const struct dev_pm_ops ccw_pm_ops = { |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 1987 | .prepare = ccw_device_pm_prepare, |
| 1988 | .complete = ccw_device_pm_complete, |
| 1989 | .freeze = ccw_device_pm_freeze, |
| 1990 | .thaw = ccw_device_pm_thaw, |
| 1991 | .restore = ccw_device_pm_restore, |
| 1992 | }; |
| 1993 | |
Sebastian Ott | d5ab527 | 2011-03-23 10:16:03 +0100 | [diff] [blame] | 1994 | static struct bus_type ccw_bus_type = { |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1995 | .name = "ccw", |
| 1996 | .match = ccw_bus_match, |
| 1997 | .uevent = ccw_uevent, |
| 1998 | .probe = ccw_device_probe, |
| 1999 | .remove = ccw_device_remove, |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 2000 | .shutdown = ccw_device_shutdown, |
Sebastian Ott | 823d494 | 2009-06-16 10:30:20 +0200 | [diff] [blame] | 2001 | .pm = &ccw_pm_ops, |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 2002 | }; |
| 2003 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 2004 | /** |
| 2005 | * ccw_driver_register() - register a ccw driver |
| 2006 | * @cdriver: driver to be registered |
| 2007 | * |
| 2008 | * This function is mainly a wrapper around driver_register(). |
| 2009 | * Returns: |
| 2010 | * %0 on success and a negative error value on failure. |
| 2011 | */ |
| 2012 | int ccw_driver_register(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | { |
| 2014 | struct device_driver *drv = &cdriver->driver; |
| 2015 | |
| 2016 | drv->bus = &ccw_bus_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | |
| 2018 | return driver_register(drv); |
| 2019 | } |
| 2020 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 2021 | /** |
| 2022 | * ccw_driver_unregister() - deregister a ccw driver |
| 2023 | * @cdriver: driver to be deregistered |
| 2024 | * |
| 2025 | * This function is mainly a wrapper around driver_unregister(). |
| 2026 | */ |
| 2027 | void ccw_driver_unregister(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | { |
| 2029 | driver_unregister(&cdriver->driver); |
| 2030 | } |
| 2031 | |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 2032 | static void ccw_device_todo(struct work_struct *work) |
| 2033 | { |
| 2034 | struct ccw_device_private *priv; |
| 2035 | struct ccw_device *cdev; |
| 2036 | struct subchannel *sch; |
| 2037 | enum cdev_todo todo; |
| 2038 | |
| 2039 | priv = container_of(work, struct ccw_device_private, todo_work); |
| 2040 | cdev = priv->cdev; |
| 2041 | sch = to_subchannel(cdev->dev.parent); |
| 2042 | /* Find out todo. */ |
| 2043 | spin_lock_irq(cdev->ccwlock); |
| 2044 | todo = priv->todo; |
| 2045 | priv->todo = CDEV_TODO_NOTHING; |
| 2046 | CIO_MSG_EVENT(4, "cdev_todo: cdev=0.%x.%04x todo=%d\n", |
| 2047 | priv->dev_id.ssid, priv->dev_id.devno, todo); |
| 2048 | spin_unlock_irq(cdev->ccwlock); |
| 2049 | /* Perform todo. */ |
| 2050 | switch (todo) { |
| 2051 | case CDEV_TODO_ENABLE_CMF: |
| 2052 | cmf_reenable(cdev); |
| 2053 | break; |
| 2054 | case CDEV_TODO_REBIND: |
| 2055 | ccw_device_do_unbind_bind(cdev); |
| 2056 | break; |
| 2057 | case CDEV_TODO_REGISTER: |
| 2058 | io_subchannel_register(cdev); |
| 2059 | break; |
| 2060 | case CDEV_TODO_UNREG_EVAL: |
| 2061 | if (!sch_is_pseudo_sch(sch)) |
| 2062 | css_schedule_eval(sch->schid); |
| 2063 | /* fall-through */ |
| 2064 | case CDEV_TODO_UNREG: |
| 2065 | if (sch_is_pseudo_sch(sch)) |
| 2066 | ccw_device_unregister(cdev); |
| 2067 | else |
| 2068 | ccw_device_call_sch_unregister(cdev); |
| 2069 | break; |
| 2070 | default: |
| 2071 | break; |
| 2072 | } |
| 2073 | /* Release workqueue ref. */ |
| 2074 | put_device(&cdev->dev); |
| 2075 | } |
| 2076 | |
| 2077 | /** |
| 2078 | * ccw_device_sched_todo - schedule ccw device operation |
| 2079 | * @cdev: ccw device |
| 2080 | * @todo: todo |
| 2081 | * |
| 2082 | * Schedule the operation identified by @todo to be performed on the slow path |
| 2083 | * workqueue. Do nothing if another operation with higher priority is already |
| 2084 | * scheduled. Needs to be called with ccwdev lock held. |
| 2085 | */ |
| 2086 | void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo) |
| 2087 | { |
| 2088 | CIO_MSG_EVENT(4, "cdev_todo: sched cdev=0.%x.%04x todo=%d\n", |
| 2089 | cdev->private->dev_id.ssid, cdev->private->dev_id.devno, |
| 2090 | todo); |
| 2091 | if (cdev->private->todo >= todo) |
| 2092 | return; |
| 2093 | cdev->private->todo = todo; |
| 2094 | /* Get workqueue ref. */ |
| 2095 | if (!get_device(&cdev->dev)) |
| 2096 | return; |
Sebastian Ott | be5d382 | 2010-02-26 22:37:24 +0100 | [diff] [blame] | 2097 | if (!queue_work(cio_work_q, &cdev->private->todo_work)) { |
Peter Oberparleiter | 37de53b | 2009-12-07 12:51:19 +0100 | [diff] [blame] | 2098 | /* Already queued, release workqueue ref. */ |
| 2099 | put_device(&cdev->dev); |
| 2100 | } |
| 2101 | } |
| 2102 | |
Michael Ernst | fd0457a | 2010-08-09 18:12:50 +0200 | [diff] [blame] | 2103 | /** |
| 2104 | * ccw_device_siosl() - initiate logging |
| 2105 | * @cdev: ccw device |
| 2106 | * |
| 2107 | * This function is used to invoke model-dependent logging within the channel |
| 2108 | * subsystem. |
| 2109 | */ |
| 2110 | int ccw_device_siosl(struct ccw_device *cdev) |
| 2111 | { |
| 2112 | struct subchannel *sch = to_subchannel(cdev->dev.parent); |
| 2113 | |
| 2114 | return chsc_siosl(sch->schid); |
| 2115 | } |
| 2116 | EXPORT_SYMBOL_GPL(ccw_device_siosl); |
| 2117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | EXPORT_SYMBOL(ccw_device_set_online); |
| 2119 | EXPORT_SYMBOL(ccw_device_set_offline); |
| 2120 | EXPORT_SYMBOL(ccw_driver_register); |
| 2121 | EXPORT_SYMBOL(ccw_driver_unregister); |
| 2122 | EXPORT_SYMBOL(get_ccwdev_by_busid); |