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