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