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