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