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