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