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