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