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 | * |
| 5 | * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, |
| 6 | * IBM Corporation |
| 7 | * Author(s): Arnd Bergmann (arndb@de.ibm.com) |
Cornelia Huck | 4ce3b30 | 2006-01-14 13:21:04 -0800 | [diff] [blame] | 8 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/spinlock.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/err.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/workqueue.h> |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include "cio.h" |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 27 | #include "cio_debug.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "css.h" |
| 29 | #include "device.h" |
| 30 | #include "ioasm.h" |
| 31 | |
| 32 | /******************* bus type handling ***********************/ |
| 33 | |
| 34 | /* The Linux driver model distinguishes between a bus type and |
| 35 | * the bus itself. Of course we only have one channel |
| 36 | * subsystem driver and one channel system per machine, but |
| 37 | * we still use the abstraction. T.R. says it's a good idea. */ |
| 38 | static int |
| 39 | ccw_bus_match (struct device * dev, struct device_driver * drv) |
| 40 | { |
| 41 | struct ccw_device *cdev = to_ccwdev(dev); |
| 42 | struct ccw_driver *cdrv = to_ccwdrv(drv); |
| 43 | const struct ccw_device_id *ids = cdrv->ids, *found; |
| 44 | |
| 45 | if (!ids) |
| 46 | return 0; |
| 47 | |
| 48 | found = ccw_device_id_match(ids, &cdev->id); |
| 49 | if (!found) |
| 50 | return 0; |
| 51 | |
| 52 | cdev->id.driver_info = found->driver_info; |
| 53 | |
| 54 | return 1; |
| 55 | } |
| 56 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 57 | /* Store modalias string delimited by prefix/suffix string into buffer with |
| 58 | * specified size. Return length of resulting string (excluding trailing '\0') |
| 59 | * even if string doesn't fit buffer (snprintf semantics). */ |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 60 | static int snprint_alias(char *buf, size_t size, |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 61 | struct ccw_device_id *id, const char *suffix) |
| 62 | { |
| 63 | int len; |
| 64 | |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 65 | 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] | 66 | if (len > size) |
| 67 | return len; |
| 68 | buf += len; |
| 69 | size -= len; |
| 70 | |
| 71 | if (id->dev_type != 0) |
| 72 | len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type, |
| 73 | id->dev_model, suffix); |
| 74 | else |
| 75 | len += snprintf(buf, size, "dtdm%s", suffix); |
| 76 | |
| 77 | return len; |
| 78 | } |
| 79 | |
| 80 | /* Set up environment variables for ccw device uevent. Return 0 on success, |
| 81 | * non-zero otherwise. */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 82 | static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
| 84 | struct ccw_device *cdev = to_ccwdev(dev); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 85 | struct ccw_device_id *id = &(cdev->id); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 86 | int ret; |
| 87 | char modalias_buf[30]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 89 | /* CU_TYPE= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 90 | ret = add_uevent_var(env, "CU_TYPE=%04X", id->cu_type); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 91 | if (ret) |
| 92 | return ret; |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 93 | |
| 94 | /* CU_MODEL= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 95 | ret = add_uevent_var(env, "CU_MODEL=%02X", id->cu_model); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 96 | if (ret) |
| 97 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* The next two can be zero, that's ok for us */ |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 100 | /* DEV_TYPE= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 101 | ret = add_uevent_var(env, "DEV_TYPE=%04X", id->dev_type); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 102 | if (ret) |
| 103 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 105 | /* DEV_MODEL= */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 106 | ret = add_uevent_var(env, "DEV_MODEL=%02X", id->dev_model); |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 107 | if (ret) |
| 108 | return ret; |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 109 | |
| 110 | /* MODALIAS= */ |
Cornelia Huck | cfbe9bb | 2007-04-27 16:01:32 +0200 | [diff] [blame] | 111 | snprint_alias(modalias_buf, sizeof(modalias_buf), id, ""); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 112 | ret = add_uevent_var(env, "MODALIAS=%s", modalias_buf); |
| 113 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 116 | struct bus_type ccw_bus_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 118 | static void io_subchannel_irq(struct subchannel *); |
| 119 | static int io_subchannel_probe(struct subchannel *); |
| 120 | static int io_subchannel_remove(struct subchannel *); |
| 121 | static int io_subchannel_notify(struct subchannel *, int); |
| 122 | static void io_subchannel_verify(struct subchannel *); |
| 123 | static void io_subchannel_ioterm(struct subchannel *); |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 124 | static void io_subchannel_shutdown(struct subchannel *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Cornelia Huck | f7e5d67 | 2007-05-10 15:45:43 +0200 | [diff] [blame] | 126 | static struct css_driver io_subchannel_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | .subchannel_type = SUBCHANNEL_TYPE_IO, |
| 128 | .drv = { |
| 129 | .name = "io_subchannel", |
| 130 | .bus = &css_bus_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | }, |
| 132 | .irq = io_subchannel_irq, |
| 133 | .notify = io_subchannel_notify, |
| 134 | .verify = io_subchannel_verify, |
| 135 | .termination = io_subchannel_ioterm, |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 136 | .probe = io_subchannel_probe, |
| 137 | .remove = io_subchannel_remove, |
| 138 | .shutdown = io_subchannel_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | struct workqueue_struct *ccw_device_work; |
| 142 | struct workqueue_struct *ccw_device_notify_work; |
Peter Oberparleiter | 40154b8 | 2006-06-29 14:57:03 +0200 | [diff] [blame] | 143 | wait_queue_head_t ccw_device_init_wq; |
| 144 | atomic_t ccw_device_init_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | static int __init |
| 147 | init_ccw_bus_type (void) |
| 148 | { |
| 149 | int ret; |
| 150 | |
| 151 | init_waitqueue_head(&ccw_device_init_wq); |
| 152 | atomic_set(&ccw_device_init_count, 0); |
| 153 | |
| 154 | ccw_device_work = create_singlethread_workqueue("cio"); |
| 155 | if (!ccw_device_work) |
| 156 | return -ENOMEM; /* FIXME: better errno ? */ |
| 157 | ccw_device_notify_work = create_singlethread_workqueue("cio_notify"); |
| 158 | if (!ccw_device_notify_work) { |
| 159 | ret = -ENOMEM; /* FIXME: better errno ? */ |
| 160 | goto out_err; |
| 161 | } |
| 162 | slow_path_wq = create_singlethread_workqueue("kslowcrw"); |
| 163 | if (!slow_path_wq) { |
| 164 | ret = -ENOMEM; /* FIXME: better errno ? */ |
| 165 | goto out_err; |
| 166 | } |
| 167 | if ((ret = bus_register (&ccw_bus_type))) |
| 168 | goto out_err; |
| 169 | |
| 170 | if ((ret = driver_register(&io_subchannel_driver.drv))) |
| 171 | goto out_err; |
| 172 | |
| 173 | wait_event(ccw_device_init_wq, |
| 174 | atomic_read(&ccw_device_init_count) == 0); |
| 175 | flush_workqueue(ccw_device_work); |
| 176 | return 0; |
| 177 | out_err: |
| 178 | if (ccw_device_work) |
| 179 | destroy_workqueue(ccw_device_work); |
| 180 | if (ccw_device_notify_work) |
| 181 | destroy_workqueue(ccw_device_notify_work); |
| 182 | if (slow_path_wq) |
| 183 | destroy_workqueue(slow_path_wq); |
| 184 | return ret; |
| 185 | } |
| 186 | |
| 187 | static void __exit |
| 188 | cleanup_ccw_bus_type (void) |
| 189 | { |
| 190 | driver_unregister(&io_subchannel_driver.drv); |
| 191 | bus_unregister(&ccw_bus_type); |
| 192 | destroy_workqueue(ccw_device_notify_work); |
| 193 | destroy_workqueue(ccw_device_work); |
| 194 | } |
| 195 | |
| 196 | subsys_initcall(init_ccw_bus_type); |
| 197 | module_exit(cleanup_ccw_bus_type); |
| 198 | |
| 199 | /************************ device handling **************************/ |
| 200 | |
| 201 | /* |
| 202 | * A ccw_device has some interfaces in sysfs in addition to the |
| 203 | * standard ones. |
| 204 | * The following entries are designed to export the information which |
| 205 | * resided in 2.4 in /proc/subchannels. Subchannel and device number |
| 206 | * are obvious, so they don't have an entry :) |
| 207 | * TODO: Split chpids and pimpampom up? Where is "in use" in the tree? |
| 208 | */ |
| 209 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 210 | chpids_show (struct device * dev, struct device_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | struct subchannel *sch = to_subchannel(dev); |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 213 | struct chsc_ssd_info *ssd = &sch->ssd_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | ssize_t ret = 0; |
| 215 | int chp; |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 216 | int mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Peter Oberparleiter | 7ad6a24 | 2007-04-27 16:01:35 +0200 | [diff] [blame] | 218 | for (chp = 0; chp < 8; chp++) { |
| 219 | mask = 0x80 >> chp; |
| 220 | if (ssd->path_mask & mask) |
| 221 | ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id); |
| 222 | else |
| 223 | ret += sprintf(buf + ret, "00 "); |
| 224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | ret += sprintf (buf+ret, "\n"); |
| 226 | return min((ssize_t)PAGE_SIZE, ret); |
| 227 | } |
| 228 | |
| 229 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 230 | pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
| 232 | struct subchannel *sch = to_subchannel(dev); |
| 233 | struct pmcw *pmcw = &sch->schib.pmcw; |
| 234 | |
| 235 | return sprintf (buf, "%02x %02x %02x\n", |
| 236 | pmcw->pim, pmcw->pam, pmcw->pom); |
| 237 | } |
| 238 | |
| 239 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 240 | devtype_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
| 242 | struct ccw_device *cdev = to_ccwdev(dev); |
| 243 | struct ccw_device_id *id = &(cdev->id); |
| 244 | |
| 245 | if (id->dev_type != 0) |
| 246 | return sprintf(buf, "%04x/%02x\n", |
| 247 | id->dev_type, id->dev_model); |
| 248 | else |
| 249 | return sprintf(buf, "n/a\n"); |
| 250 | } |
| 251 | |
| 252 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 253 | cutype_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
| 255 | struct ccw_device *cdev = to_ccwdev(dev); |
| 256 | struct ccw_device_id *id = &(cdev->id); |
| 257 | |
| 258 | return sprintf(buf, "%04x/%02x\n", |
| 259 | id->cu_type, id->cu_model); |
| 260 | } |
| 261 | |
| 262 | static ssize_t |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 263 | modalias_show (struct device *dev, struct device_attribute *attr, char *buf) |
| 264 | { |
| 265 | struct ccw_device *cdev = to_ccwdev(dev); |
| 266 | struct ccw_device_id *id = &(cdev->id); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 267 | int len; |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 268 | |
Cornelia Huck | 086a6c6 | 2007-07-17 13:36:08 +0200 | [diff] [blame] | 269 | len = snprint_alias(buf, PAGE_SIZE, id, "\n"); |
Peter Oberparleiter | db0c2d5 | 2006-09-20 15:59:49 +0200 | [diff] [blame] | 270 | |
| 271 | return len > PAGE_SIZE ? PAGE_SIZE : len; |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 275 | online_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
| 277 | struct ccw_device *cdev = to_ccwdev(dev); |
| 278 | |
| 279 | return sprintf(buf, cdev->online ? "1\n" : "0\n"); |
| 280 | } |
| 281 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 282 | int ccw_device_is_orphan(struct ccw_device *cdev) |
| 283 | { |
| 284 | return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent)); |
| 285 | } |
| 286 | |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 287 | static void ccw_device_unregister(struct ccw_device *cdev) |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 288 | { |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 289 | if (test_and_clear_bit(1, &cdev->private->registered)) |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 290 | device_del(&cdev->dev); |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 293 | static void ccw_device_remove_orphan_cb(struct device *dev) |
| 294 | { |
| 295 | struct ccw_device *cdev = to_ccwdev(dev); |
| 296 | |
| 297 | ccw_device_unregister(cdev); |
| 298 | put_device(&cdev->dev); |
| 299 | } |
| 300 | |
| 301 | static void ccw_device_remove_sch_cb(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
| 303 | struct subchannel *sch; |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 304 | |
| 305 | sch = to_subchannel(dev); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 306 | css_sch_device_unregister(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | /* Reset intparm to zeroes. */ |
| 308 | sch->schib.pmcw.intparm = 0; |
| 309 | cio_modify(sch); |
| 310 | put_device(&sch->dev); |
| 311 | } |
| 312 | |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 313 | static void |
| 314 | ccw_device_remove_disconnected(struct ccw_device *cdev) |
| 315 | { |
| 316 | unsigned long flags; |
| 317 | int rc; |
| 318 | |
| 319 | /* |
| 320 | * Forced offline in disconnected state means |
| 321 | * 'throw away device'. |
| 322 | */ |
| 323 | if (ccw_device_is_orphan(cdev)) { |
| 324 | /* |
| 325 | * Deregister ccw device. |
| 326 | * Unfortunately, we cannot do this directly from the |
| 327 | * attribute method. |
| 328 | */ |
| 329 | spin_lock_irqsave(cdev->ccwlock, flags); |
| 330 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 331 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
| 332 | rc = device_schedule_callback(&cdev->dev, |
| 333 | ccw_device_remove_orphan_cb); |
| 334 | if (rc) |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 335 | CIO_MSG_EVENT(2, "Couldn't unregister orphan " |
| 336 | "0.%x.%04x\n", |
| 337 | cdev->private->dev_id.ssid, |
| 338 | cdev->private->dev_id.devno); |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 339 | return; |
| 340 | } |
| 341 | /* Deregister subchannel, which will kill the ccw device. */ |
| 342 | rc = device_schedule_callback(cdev->dev.parent, |
| 343 | ccw_device_remove_sch_cb); |
| 344 | if (rc) |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 345 | CIO_MSG_EVENT(2, "Couldn't unregister disconnected device " |
| 346 | "0.%x.%04x\n", |
| 347 | cdev->private->dev_id.ssid, |
| 348 | cdev->private->dev_id.devno); |
Cornelia Huck | 59a8a6e | 2007-05-31 17:38:06 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 351 | /** |
| 352 | * ccw_device_set_offline() - disable a ccw device for I/O |
| 353 | * @cdev: target ccw device |
| 354 | * |
| 355 | * This function calls the driver's set_offline() function for @cdev, if |
| 356 | * given, and then disables @cdev. |
| 357 | * Returns: |
| 358 | * %0 on success and a negative error value on failure. |
| 359 | * Context: |
| 360 | * enabled, ccw device lock not held |
| 361 | */ |
| 362 | int ccw_device_set_offline(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
| 364 | int ret; |
| 365 | |
| 366 | if (!cdev) |
| 367 | return -ENODEV; |
| 368 | if (!cdev->online || !cdev->drv) |
| 369 | return -EINVAL; |
| 370 | |
| 371 | if (cdev->drv->set_offline) { |
| 372 | ret = cdev->drv->set_offline(cdev); |
| 373 | if (ret != 0) |
| 374 | return ret; |
| 375 | } |
| 376 | cdev->online = 0; |
| 377 | spin_lock_irq(cdev->ccwlock); |
| 378 | ret = ccw_device_offline(cdev); |
| 379 | if (ret == -ENODEV) { |
| 380 | if (cdev->private->state != DEV_STATE_NOT_OPER) { |
| 381 | cdev->private->state = DEV_STATE_OFFLINE; |
| 382 | dev_fsm_event(cdev, DEV_EVENT_NOTOPER); |
| 383 | } |
| 384 | spin_unlock_irq(cdev->ccwlock); |
| 385 | return ret; |
| 386 | } |
| 387 | spin_unlock_irq(cdev->ccwlock); |
| 388 | if (ret == 0) |
| 389 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 390 | else { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 391 | CIO_MSG_EVENT(2, "ccw_device_offline returned %d, " |
| 392 | "device 0.%x.%04x\n", |
| 393 | ret, cdev->private->dev_id.ssid, |
| 394 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | cdev->online = 1; |
| 396 | } |
| 397 | return ret; |
| 398 | } |
| 399 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 400 | /** |
| 401 | * ccw_device_set_online() - enable a ccw device for I/O |
| 402 | * @cdev: target ccw device |
| 403 | * |
| 404 | * This function first enables @cdev and then calls the driver's set_online() |
| 405 | * function for @cdev, if given. If set_online() returns an error, @cdev is |
| 406 | * disabled again. |
| 407 | * Returns: |
| 408 | * %0 on success and a negative error value on failure. |
| 409 | * Context: |
| 410 | * enabled, ccw device lock not held |
| 411 | */ |
| 412 | int ccw_device_set_online(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
| 414 | int ret; |
| 415 | |
| 416 | if (!cdev) |
| 417 | return -ENODEV; |
| 418 | if (cdev->online || !cdev->drv) |
| 419 | return -EINVAL; |
| 420 | |
| 421 | spin_lock_irq(cdev->ccwlock); |
| 422 | ret = ccw_device_online(cdev); |
| 423 | spin_unlock_irq(cdev->ccwlock); |
| 424 | if (ret == 0) |
| 425 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 426 | else { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 427 | CIO_MSG_EVENT(2, "ccw_device_online returned %d, " |
| 428 | "device 0.%x.%04x\n", |
| 429 | ret, cdev->private->dev_id.ssid, |
| 430 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | return ret; |
| 432 | } |
| 433 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 434 | return -ENODEV; |
| 435 | if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) { |
| 436 | cdev->online = 1; |
| 437 | return 0; |
| 438 | } |
| 439 | spin_lock_irq(cdev->ccwlock); |
| 440 | ret = ccw_device_offline(cdev); |
| 441 | spin_unlock_irq(cdev->ccwlock); |
| 442 | if (ret == 0) |
| 443 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 444 | else |
| 445 | CIO_MSG_EVENT(2, "ccw_device_offline returned %d, " |
| 446 | "device 0.%x.%04x\n", |
| 447 | ret, cdev->private->dev_id.ssid, |
| 448 | cdev->private->dev_id.devno); |
Cornelia Huck | 6cadb78 | 2006-02-17 13:52:49 -0800 | [diff] [blame] | 449 | return (ret == 0) ? -ENODEV : ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 452 | static void online_store_handle_offline(struct ccw_device *cdev) |
| 453 | { |
| 454 | if (cdev->private->state == DEV_STATE_DISCONNECTED) |
| 455 | ccw_device_remove_disconnected(cdev); |
| 456 | else if (cdev->drv && cdev->drv->set_offline) |
| 457 | ccw_device_set_offline(cdev); |
| 458 | } |
| 459 | |
| 460 | static int online_store_recog_and_online(struct ccw_device *cdev) |
| 461 | { |
| 462 | int ret; |
| 463 | |
| 464 | /* Do device recognition, if needed. */ |
| 465 | if (cdev->id.cu_type == 0) { |
| 466 | ret = ccw_device_recognition(cdev); |
| 467 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 468 | CIO_MSG_EVENT(0, "Couldn't start recognition " |
| 469 | "for device 0.%x.%04x (ret=%d)\n", |
| 470 | cdev->private->dev_id.ssid, |
| 471 | cdev->private->dev_id.devno, ret); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 472 | return ret; |
| 473 | } |
| 474 | wait_event(cdev->private->wait_q, |
| 475 | cdev->private->flags.recog_done); |
| 476 | } |
| 477 | if (cdev->drv && cdev->drv->set_online) |
| 478 | ccw_device_set_online(cdev); |
| 479 | return 0; |
| 480 | } |
| 481 | static void online_store_handle_online(struct ccw_device *cdev, int force) |
| 482 | { |
| 483 | int ret; |
| 484 | |
| 485 | ret = online_store_recog_and_online(cdev); |
| 486 | if (ret) |
| 487 | return; |
| 488 | if (force && cdev->private->state == DEV_STATE_BOXED) { |
| 489 | ret = ccw_device_stlck(cdev); |
| 490 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 491 | dev_warn(&cdev->dev, |
| 492 | "ccw_device_stlck returned %d!\n", ret); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 493 | return; |
| 494 | } |
| 495 | if (cdev->id.cu_type == 0) |
| 496 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 497 | online_store_recog_and_online(cdev); |
| 498 | } |
| 499 | |
| 500 | } |
| 501 | |
| 502 | static ssize_t online_store (struct device *dev, struct device_attribute *attr, |
| 503 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
| 505 | struct ccw_device *cdev = to_ccwdev(dev); |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 506 | int i, force; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | char *tmp; |
| 508 | |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 509 | if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | return -EAGAIN; |
| 511 | |
| 512 | if (cdev->drv && !try_module_get(cdev->drv->owner)) { |
| 513 | atomic_set(&cdev->private->onoff, 0); |
| 514 | return -EINVAL; |
| 515 | } |
| 516 | if (!strncmp(buf, "force\n", count)) { |
| 517 | force = 1; |
| 518 | i = 1; |
| 519 | } else { |
| 520 | force = 0; |
| 521 | i = simple_strtoul(buf, &tmp, 16); |
| 522 | } |
Cornelia Huck | f5ba6c8 | 2007-04-27 16:01:30 +0200 | [diff] [blame] | 523 | |
| 524 | switch (i) { |
| 525 | case 0: |
| 526 | online_store_handle_offline(cdev); |
| 527 | break; |
| 528 | case 1: |
| 529 | online_store_handle_online(cdev, force); |
| 530 | break; |
| 531 | default: |
| 532 | count = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | if (cdev->drv) |
| 535 | module_put(cdev->drv->owner); |
| 536 | atomic_set(&cdev->private->onoff, 0); |
| 537 | return count; |
| 538 | } |
| 539 | |
| 540 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 541 | available_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | { |
| 543 | struct ccw_device *cdev = to_ccwdev(dev); |
| 544 | struct subchannel *sch; |
| 545 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 546 | if (ccw_device_is_orphan(cdev)) |
| 547 | return sprintf(buf, "no device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | switch (cdev->private->state) { |
| 549 | case DEV_STATE_BOXED: |
| 550 | return sprintf(buf, "boxed\n"); |
| 551 | case DEV_STATE_DISCONNECTED: |
| 552 | case DEV_STATE_DISCONNECTED_SENSE_ID: |
| 553 | case DEV_STATE_NOT_OPER: |
| 554 | sch = to_subchannel(dev->parent); |
| 555 | if (!sch->lpm) |
| 556 | return sprintf(buf, "no path\n"); |
| 557 | else |
| 558 | return sprintf(buf, "no device\n"); |
| 559 | default: |
| 560 | /* All other states considered fine. */ |
| 561 | return sprintf(buf, "good\n"); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | static DEVICE_ATTR(chpids, 0444, chpids_show, NULL); |
| 566 | static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL); |
| 567 | static DEVICE_ATTR(devtype, 0444, devtype_show, NULL); |
| 568 | static DEVICE_ATTR(cutype, 0444, cutype_show, NULL); |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 569 | static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | static DEVICE_ATTR(online, 0644, online_show, online_store); |
| 571 | extern struct device_attribute dev_attr_cmb_enable; |
| 572 | static DEVICE_ATTR(availability, 0444, available_show, NULL); |
| 573 | |
| 574 | static struct attribute * subch_attrs[] = { |
| 575 | &dev_attr_chpids.attr, |
| 576 | &dev_attr_pimpampom.attr, |
| 577 | NULL, |
| 578 | }; |
| 579 | |
| 580 | static struct attribute_group subch_attr_group = { |
| 581 | .attrs = subch_attrs, |
| 582 | }; |
| 583 | |
Cornelia Huck | 529192f | 2006-12-08 15:55:57 +0100 | [diff] [blame] | 584 | struct attribute_group *subch_attr_groups[] = { |
| 585 | &subch_attr_group, |
| 586 | NULL, |
| 587 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
| 589 | static struct attribute * ccwdev_attrs[] = { |
| 590 | &dev_attr_devtype.attr, |
| 591 | &dev_attr_cutype.attr, |
Bastian Blank | f1fc78a | 2005-10-30 15:00:12 -0800 | [diff] [blame] | 592 | &dev_attr_modalias.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | &dev_attr_online.attr, |
| 594 | &dev_attr_cmb_enable.attr, |
| 595 | &dev_attr_availability.attr, |
| 596 | NULL, |
| 597 | }; |
| 598 | |
| 599 | static struct attribute_group ccwdev_attr_group = { |
| 600 | .attrs = ccwdev_attrs, |
| 601 | }; |
| 602 | |
Cornelia Huck | f7e5d67 | 2007-05-10 15:45:43 +0200 | [diff] [blame] | 603 | static struct attribute_group *ccwdev_attr_groups[] = { |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 604 | &ccwdev_attr_group, |
| 605 | NULL, |
| 606 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | /* this is a simple abstraction for device_register that sets the |
| 609 | * correct bus type and adds the bus specific files */ |
Cornelia Huck | 3c9da7b | 2006-10-27 12:39:33 +0200 | [diff] [blame] | 610 | static int ccw_device_register(struct ccw_device *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
| 612 | struct device *dev = &cdev->dev; |
| 613 | int ret; |
| 614 | |
| 615 | dev->bus = &ccw_bus_type; |
| 616 | |
| 617 | if ((ret = device_add(dev))) |
| 618 | return ret; |
| 619 | |
| 620 | set_bit(1, &cdev->private->registered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | return ret; |
| 622 | } |
| 623 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 624 | struct match_data { |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 625 | struct ccw_dev_id dev_id; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 626 | struct ccw_device * sibling; |
| 627 | }; |
| 628 | |
| 629 | static int |
| 630 | match_devno(struct device * dev, void * data) |
| 631 | { |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 632 | struct match_data * d = data; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 633 | struct ccw_device * cdev; |
| 634 | |
| 635 | cdev = to_ccwdev(dev); |
| 636 | if ((cdev->private->state == DEV_STATE_DISCONNECTED) && |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 637 | !ccw_device_is_orphan(cdev) && |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 638 | ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) && |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 639 | (cdev != d->sibling)) |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 640 | return 1; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 644 | static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id, |
| 645 | struct ccw_device *sibling) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | struct device *dev; |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 648 | struct match_data data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 650 | data.dev_id = *dev_id; |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 651 | data.sibling = sibling; |
Cornelia Huck | e5945b4 | 2005-10-11 08:28:59 -0700 | [diff] [blame] | 652 | dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 654 | return dev ? to_ccwdev(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 657 | static int match_orphan(struct device *dev, void *data) |
| 658 | { |
| 659 | struct ccw_dev_id *dev_id; |
| 660 | struct ccw_device *cdev; |
| 661 | |
| 662 | dev_id = data; |
| 663 | cdev = to_ccwdev(dev); |
| 664 | return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id); |
| 665 | } |
| 666 | |
| 667 | static struct ccw_device * |
| 668 | get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css, |
| 669 | struct ccw_dev_id *dev_id) |
| 670 | { |
| 671 | struct device *dev; |
| 672 | |
| 673 | dev = device_find_child(&css->pseudo_subchannel->dev, dev_id, |
| 674 | match_orphan); |
| 675 | |
| 676 | return dev ? to_ccwdev(dev) : NULL; |
| 677 | } |
| 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 680 | ccw_device_add_changed(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 682 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | struct ccw_device *cdev; |
| 684 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 685 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 686 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | if (device_add(&cdev->dev)) { |
| 688 | put_device(&cdev->dev); |
| 689 | return; |
| 690 | } |
| 691 | set_bit(1, &cdev->private->registered); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 694 | void ccw_device_do_unreg_rereg(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 696 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | struct ccw_device *cdev; |
| 698 | struct subchannel *sch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 700 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 701 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | sch = to_subchannel(cdev->dev.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 704 | ccw_device_unregister(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 706 | ccw_device_add_changed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | queue_work(ccw_device_work, &cdev->private->kick_work); |
| 708 | } |
| 709 | |
| 710 | static void |
| 711 | ccw_device_release(struct device *dev) |
| 712 | { |
| 713 | struct ccw_device *cdev; |
| 714 | |
| 715 | cdev = to_ccwdev(dev); |
| 716 | kfree(cdev->private); |
| 717 | kfree(cdev); |
| 718 | } |
| 719 | |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 720 | static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) |
| 721 | { |
| 722 | struct ccw_device *cdev; |
| 723 | |
| 724 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
| 725 | if (cdev) { |
| 726 | cdev->private = kzalloc(sizeof(struct ccw_device_private), |
| 727 | GFP_KERNEL | GFP_DMA); |
| 728 | if (cdev->private) |
| 729 | return cdev; |
| 730 | } |
| 731 | kfree(cdev); |
| 732 | return ERR_PTR(-ENOMEM); |
| 733 | } |
| 734 | |
| 735 | static int io_subchannel_initialize_dev(struct subchannel *sch, |
| 736 | struct ccw_device *cdev) |
| 737 | { |
| 738 | cdev->private->cdev = cdev; |
| 739 | atomic_set(&cdev->private->onoff, 0); |
| 740 | cdev->dev.parent = &sch->dev; |
| 741 | cdev->dev.release = ccw_device_release; |
Heiko Carstens | 33583c3 | 2007-11-05 11:10:07 +0100 | [diff] [blame] | 742 | INIT_WORK(&cdev->private->kick_work, NULL); |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 743 | cdev->dev.groups = ccwdev_attr_groups; |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 744 | /* Do first half of device_register. */ |
| 745 | device_initialize(&cdev->dev); |
| 746 | if (!get_device(&sch->dev)) { |
| 747 | if (cdev->dev.release) |
| 748 | cdev->dev.release(&cdev->dev); |
| 749 | return -ENODEV; |
| 750 | } |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch) |
| 755 | { |
| 756 | struct ccw_device *cdev; |
| 757 | int ret; |
| 758 | |
| 759 | cdev = io_subchannel_allocate_dev(sch); |
| 760 | if (!IS_ERR(cdev)) { |
| 761 | ret = io_subchannel_initialize_dev(sch, cdev); |
| 762 | if (ret) { |
| 763 | kfree(cdev); |
| 764 | cdev = ERR_PTR(ret); |
| 765 | } |
| 766 | } |
| 767 | return cdev; |
| 768 | } |
| 769 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 770 | static int io_subchannel_recog(struct ccw_device *, struct subchannel *); |
| 771 | |
| 772 | static void sch_attach_device(struct subchannel *sch, |
| 773 | struct ccw_device *cdev) |
| 774 | { |
Cornelia Huck | 82b7ac0 | 2007-04-27 16:01:36 +0200 | [diff] [blame] | 775 | css_update_ssd_info(sch); |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 776 | spin_lock_irq(sch->lock); |
| 777 | sch->dev.driver_data = cdev; |
| 778 | cdev->private->schid = sch->schid; |
| 779 | cdev->ccwlock = sch->lock; |
| 780 | device_trigger_reprobe(sch); |
| 781 | spin_unlock_irq(sch->lock); |
| 782 | } |
| 783 | |
| 784 | static void sch_attach_disconnected_device(struct subchannel *sch, |
| 785 | struct ccw_device *cdev) |
| 786 | { |
| 787 | struct subchannel *other_sch; |
| 788 | int ret; |
| 789 | |
| 790 | other_sch = to_subchannel(get_device(cdev->dev.parent)); |
| 791 | ret = device_move(&cdev->dev, &sch->dev); |
| 792 | if (ret) { |
| 793 | CIO_MSG_EVENT(2, "Moving disconnected device 0.%x.%04x failed " |
| 794 | "(ret=%d)!\n", cdev->private->dev_id.ssid, |
| 795 | cdev->private->dev_id.devno, ret); |
| 796 | put_device(&other_sch->dev); |
| 797 | return; |
| 798 | } |
| 799 | other_sch->dev.driver_data = NULL; |
| 800 | /* No need to keep a subchannel without ccw device around. */ |
| 801 | css_sch_device_unregister(other_sch); |
| 802 | put_device(&other_sch->dev); |
| 803 | sch_attach_device(sch, cdev); |
| 804 | } |
| 805 | |
| 806 | static void sch_attach_orphaned_device(struct subchannel *sch, |
| 807 | struct ccw_device *cdev) |
| 808 | { |
| 809 | int ret; |
| 810 | |
| 811 | /* Try to move the ccw device to its new subchannel. */ |
| 812 | ret = device_move(&cdev->dev, &sch->dev); |
| 813 | if (ret) { |
| 814 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage " |
| 815 | "failed (ret=%d)!\n", |
| 816 | cdev->private->dev_id.ssid, |
| 817 | cdev->private->dev_id.devno, ret); |
| 818 | return; |
| 819 | } |
| 820 | sch_attach_device(sch, cdev); |
| 821 | } |
| 822 | |
| 823 | static void sch_create_and_recog_new_device(struct subchannel *sch) |
| 824 | { |
| 825 | struct ccw_device *cdev; |
| 826 | |
| 827 | /* Need to allocate a new ccw device. */ |
| 828 | cdev = io_subchannel_create_ccwdev(sch); |
| 829 | if (IS_ERR(cdev)) { |
| 830 | /* OK, we did everything we could... */ |
| 831 | css_sch_device_unregister(sch); |
| 832 | return; |
| 833 | } |
| 834 | spin_lock_irq(sch->lock); |
| 835 | sch->dev.driver_data = cdev; |
| 836 | spin_unlock_irq(sch->lock); |
| 837 | /* Start recognition for the new ccw device. */ |
| 838 | if (io_subchannel_recog(cdev, sch)) { |
| 839 | spin_lock_irq(sch->lock); |
| 840 | sch->dev.driver_data = NULL; |
| 841 | spin_unlock_irq(sch->lock); |
| 842 | if (cdev->dev.release) |
| 843 | cdev->dev.release(&cdev->dev); |
| 844 | css_sch_device_unregister(sch); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | |
| 849 | void ccw_device_move_to_orphanage(struct work_struct *work) |
| 850 | { |
| 851 | struct ccw_device_private *priv; |
| 852 | struct ccw_device *cdev; |
| 853 | struct ccw_device *replacing_cdev; |
| 854 | struct subchannel *sch; |
| 855 | int ret; |
| 856 | struct channel_subsystem *css; |
| 857 | struct ccw_dev_id dev_id; |
| 858 | |
| 859 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 860 | cdev = priv->cdev; |
| 861 | sch = to_subchannel(cdev->dev.parent); |
| 862 | css = to_css(sch->dev.parent); |
| 863 | dev_id.devno = sch->schib.pmcw.dev; |
| 864 | dev_id.ssid = sch->schid.ssid; |
| 865 | |
| 866 | /* |
| 867 | * Move the orphaned ccw device to the orphanage so the replacing |
| 868 | * ccw device can take its place on the subchannel. |
| 869 | */ |
| 870 | ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev); |
| 871 | if (ret) { |
| 872 | CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed " |
| 873 | "(ret=%d)!\n", cdev->private->dev_id.ssid, |
| 874 | cdev->private->dev_id.devno, ret); |
| 875 | return; |
| 876 | } |
| 877 | cdev->ccwlock = css->pseudo_subchannel->lock; |
| 878 | /* |
| 879 | * Search for the replacing ccw device |
| 880 | * - among the disconnected devices |
| 881 | * - in the orphanage |
| 882 | */ |
| 883 | replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev); |
| 884 | if (replacing_cdev) { |
| 885 | sch_attach_disconnected_device(sch, replacing_cdev); |
| 886 | return; |
| 887 | } |
| 888 | replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id); |
| 889 | if (replacing_cdev) { |
| 890 | sch_attach_orphaned_device(sch, replacing_cdev); |
| 891 | return; |
| 892 | } |
| 893 | sch_create_and_recog_new_device(sch); |
| 894 | } |
| 895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | /* |
| 897 | * Register recognized device. |
| 898 | */ |
| 899 | static void |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 900 | io_subchannel_register(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 902 | struct ccw_device_private *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | struct ccw_device *cdev; |
| 904 | struct subchannel *sch; |
| 905 | int ret; |
| 906 | unsigned long flags; |
| 907 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 908 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 909 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 82b7ac0 | 2007-04-27 16:01:36 +0200 | [diff] [blame] | 911 | css_update_ssd_info(sch); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 912 | /* |
| 913 | * io_subchannel_register() will also be called after device |
| 914 | * recognition has been done for a boxed device (which will already |
| 915 | * be registered). We need to reprobe since we may now have sense id |
| 916 | * information. |
| 917 | */ |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 918 | if (klist_node_attached(&cdev->dev.knode_parent)) { |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 919 | if (!cdev->drv) { |
| 920 | ret = device_reprobe(&cdev->dev); |
| 921 | if (ret) |
| 922 | /* We can't do much here. */ |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 923 | CIO_MSG_EVENT(2, "device_reprobe() returned" |
| 924 | " %d for 0.%x.%04x\n", ret, |
| 925 | cdev->private->dev_id.ssid, |
| 926 | cdev->private->dev_id.devno); |
Cornelia Huck | 47af551 | 2006-12-04 15:41:07 +0100 | [diff] [blame] | 927 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | goto out; |
| 929 | } |
Cornelia Huck | fa1a8c2 | 2007-04-26 00:12:03 -0700 | [diff] [blame] | 930 | /* |
| 931 | * Now we know this subchannel will stay, we can throw |
| 932 | * our delayed uevent. |
| 933 | */ |
| 934 | sch->dev.uevent_suppress = 0; |
| 935 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | /* make it known to the system */ |
| 937 | ret = ccw_device_register(cdev); |
| 938 | if (ret) { |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 939 | CIO_MSG_EVENT(0, "Could not register ccw dev 0.%x.%04x: %d\n", |
| 940 | cdev->private->dev_id.ssid, |
| 941 | cdev->private->dev_id.devno, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | put_device(&cdev->dev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 943 | spin_lock_irqsave(sch->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | sch->dev.driver_data = NULL; |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 945 | spin_unlock_irqrestore(sch->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | kfree (cdev->private); |
| 947 | kfree (cdev); |
| 948 | put_device(&sch->dev); |
| 949 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 950 | wake_up(&ccw_device_init_wq); |
| 951 | return; |
| 952 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | put_device(&cdev->dev); |
| 954 | out: |
| 955 | cdev->private->flags.recog_done = 1; |
| 956 | put_device(&sch->dev); |
| 957 | wake_up(&cdev->private->wait_q); |
| 958 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 959 | wake_up(&ccw_device_init_wq); |
| 960 | } |
| 961 | |
Cornelia Huck | 3f4cf6e | 2007-10-12 16:11:26 +0200 | [diff] [blame] | 962 | static void ccw_device_call_sch_unregister(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | { |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 964 | struct ccw_device_private *priv; |
| 965 | struct ccw_device *cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | struct subchannel *sch; |
| 967 | |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 968 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 969 | cdev = priv->cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | sch = to_subchannel(cdev->dev.parent); |
Cornelia Huck | 6ab4879 | 2006-07-12 16:39:50 +0200 | [diff] [blame] | 971 | css_sch_device_unregister(sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | /* Reset intparm to zeroes. */ |
| 973 | sch->schib.pmcw.intparm = 0; |
| 974 | cio_modify(sch); |
| 975 | put_device(&cdev->dev); |
| 976 | put_device(&sch->dev); |
| 977 | } |
| 978 | |
| 979 | /* |
| 980 | * subchannel recognition done. Called from the state machine. |
| 981 | */ |
| 982 | void |
| 983 | io_subchannel_recog_done(struct ccw_device *cdev) |
| 984 | { |
| 985 | struct subchannel *sch; |
| 986 | |
| 987 | if (css_init_done == 0) { |
| 988 | cdev->private->flags.recog_done = 1; |
| 989 | return; |
| 990 | } |
| 991 | switch (cdev->private->state) { |
| 992 | case DEV_STATE_NOT_OPER: |
| 993 | cdev->private->flags.recog_done = 1; |
| 994 | /* Remove device found not operational. */ |
| 995 | if (!get_device(&cdev->dev)) |
| 996 | break; |
| 997 | sch = to_subchannel(cdev->dev.parent); |
| 998 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 999 | ccw_device_call_sch_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1001 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1002 | wake_up(&ccw_device_init_wq); |
| 1003 | break; |
| 1004 | case DEV_STATE_BOXED: |
| 1005 | /* Device did not respond in time. */ |
| 1006 | case DEV_STATE_OFFLINE: |
| 1007 | /* |
| 1008 | * We can't register the device in interrupt context so |
| 1009 | * we schedule a work item. |
| 1010 | */ |
| 1011 | if (!get_device(&cdev->dev)) |
| 1012 | break; |
| 1013 | PREPARE_WORK(&cdev->private->kick_work, |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1014 | io_subchannel_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1016 | break; |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | static int |
| 1021 | io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) |
| 1022 | { |
| 1023 | int rc; |
| 1024 | struct ccw_device_private *priv; |
| 1025 | |
| 1026 | sch->dev.driver_data = cdev; |
| 1027 | sch->driver = &io_subchannel_driver; |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1028 | cdev->ccwlock = sch->lock; |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | /* Init private data. */ |
| 1031 | priv = cdev->private; |
Cornelia Huck | 7896426 | 2006-10-11 15:31:38 +0200 | [diff] [blame] | 1032 | priv->dev_id.devno = sch->schib.pmcw.dev; |
| 1033 | priv->dev_id.ssid = sch->schid.ssid; |
| 1034 | priv->schid = sch->schid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | priv->state = DEV_STATE_NOT_OPER; |
| 1036 | INIT_LIST_HEAD(&priv->cmb_list); |
| 1037 | init_waitqueue_head(&priv->wait_q); |
| 1038 | init_timer(&priv->timer); |
| 1039 | |
| 1040 | /* Set an initial name for the device. */ |
Cornelia Huck | fb6958a | 2006-01-06 00:19:25 -0800 | [diff] [blame] | 1041 | snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", |
| 1042 | sch->schid.ssid, sch->schib.pmcw.dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
| 1044 | /* Increase counter of devices currently in recognition. */ |
| 1045 | atomic_inc(&ccw_device_init_count); |
| 1046 | |
| 1047 | /* Start async. device sensing. */ |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1048 | spin_lock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | rc = ccw_device_recognition(cdev); |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1050 | spin_unlock_irq(sch->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | if (rc) { |
| 1052 | if (atomic_dec_and_test(&ccw_device_init_count)) |
| 1053 | wake_up(&ccw_device_init_wq); |
| 1054 | } |
| 1055 | return rc; |
| 1056 | } |
| 1057 | |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1058 | static void ccw_device_move_to_sch(struct work_struct *work) |
| 1059 | { |
| 1060 | struct ccw_device_private *priv; |
| 1061 | int rc; |
| 1062 | struct subchannel *sch; |
| 1063 | struct ccw_device *cdev; |
| 1064 | struct subchannel *former_parent; |
| 1065 | |
| 1066 | priv = container_of(work, struct ccw_device_private, kick_work); |
| 1067 | sch = priv->sch; |
| 1068 | cdev = priv->cdev; |
| 1069 | former_parent = ccw_device_is_orphan(cdev) ? |
| 1070 | NULL : to_subchannel(get_device(cdev->dev.parent)); |
| 1071 | mutex_lock(&sch->reg_mutex); |
| 1072 | /* Try to move the ccw device to its new subchannel. */ |
| 1073 | rc = device_move(&cdev->dev, &sch->dev); |
| 1074 | mutex_unlock(&sch->reg_mutex); |
| 1075 | if (rc) { |
| 1076 | CIO_MSG_EVENT(2, "Moving device 0.%x.%04x to subchannel " |
| 1077 | "0.%x.%04x failed (ret=%d)!\n", |
| 1078 | cdev->private->dev_id.ssid, |
| 1079 | cdev->private->dev_id.devno, sch->schid.ssid, |
| 1080 | sch->schid.sch_no, rc); |
| 1081 | css_sch_device_unregister(sch); |
| 1082 | goto out; |
| 1083 | } |
| 1084 | if (former_parent) { |
| 1085 | spin_lock_irq(former_parent->lock); |
| 1086 | former_parent->dev.driver_data = NULL; |
| 1087 | spin_unlock_irq(former_parent->lock); |
| 1088 | css_sch_device_unregister(former_parent); |
| 1089 | /* Reset intparm to zeroes. */ |
| 1090 | former_parent->schib.pmcw.intparm = 0; |
| 1091 | cio_modify(former_parent); |
| 1092 | } |
| 1093 | sch_attach_device(sch, cdev); |
| 1094 | out: |
| 1095 | if (former_parent) |
| 1096 | put_device(&former_parent->dev); |
| 1097 | put_device(&cdev->dev); |
| 1098 | } |
| 1099 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 1100 | static void io_subchannel_irq(struct subchannel *sch) |
| 1101 | { |
| 1102 | struct ccw_device *cdev; |
| 1103 | |
| 1104 | cdev = sch->dev.driver_data; |
| 1105 | |
| 1106 | CIO_TRACE_EVENT(3, "IRQ"); |
| 1107 | CIO_TRACE_EVENT(3, sch->dev.bus_id); |
| 1108 | if (cdev) |
| 1109 | dev_fsm_event(cdev, DEV_EVENT_INTERRUPT); |
| 1110 | } |
| 1111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | static int |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1113 | io_subchannel_probe (struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | struct ccw_device *cdev; |
| 1116 | int rc; |
| 1117 | unsigned long flags; |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1118 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | if (sch->dev.driver_data) { |
| 1121 | /* |
| 1122 | * This subchannel already has an associated ccw_device. |
| 1123 | * Register it and exit. This happens for all early |
| 1124 | * device, e.g. the console. |
| 1125 | */ |
| 1126 | cdev = sch->dev.driver_data; |
Cornelia Huck | e103178 | 2007-10-12 16:11:23 +0200 | [diff] [blame] | 1127 | cdev->dev.groups = ccwdev_attr_groups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | device_initialize(&cdev->dev); |
| 1129 | ccw_device_register(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | /* |
| 1131 | * Check if the device is already online. If it is |
| 1132 | * the reference count needs to be corrected |
| 1133 | * (see ccw_device_online and css_init_done for the |
| 1134 | * ugly details). |
| 1135 | */ |
| 1136 | if (cdev->private->state != DEV_STATE_NOT_OPER && |
| 1137 | cdev->private->state != DEV_STATE_OFFLINE && |
| 1138 | cdev->private->state != DEV_STATE_BOXED) |
| 1139 | get_device(&cdev->dev); |
| 1140 | return 0; |
| 1141 | } |
Cornelia Huck | d7b5a4c9 | 2006-12-08 15:54:28 +0100 | [diff] [blame] | 1142 | /* |
| 1143 | * First check if a fitting device may be found amongst the |
| 1144 | * disconnected devices or in the orphanage. |
| 1145 | */ |
| 1146 | dev_id.devno = sch->schib.pmcw.dev; |
| 1147 | dev_id.ssid = sch->schid.ssid; |
| 1148 | cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL); |
| 1149 | if (!cdev) |
| 1150 | cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent), |
| 1151 | &dev_id); |
| 1152 | if (cdev) { |
| 1153 | /* |
| 1154 | * Schedule moving the device until when we have a registered |
| 1155 | * subchannel to move to and succeed the probe. We can |
| 1156 | * unregister later again, when the probe is through. |
| 1157 | */ |
| 1158 | cdev->private->sch = sch; |
| 1159 | PREPARE_WORK(&cdev->private->kick_work, |
| 1160 | ccw_device_move_to_sch); |
| 1161 | queue_work(slow_path_wq, &cdev->private->kick_work); |
| 1162 | return 0; |
| 1163 | } |
Cornelia Huck | 7674da7 | 2006-12-08 15:54:21 +0100 | [diff] [blame] | 1164 | cdev = io_subchannel_create_ccwdev(sch); |
| 1165 | if (IS_ERR(cdev)) |
| 1166 | return PTR_ERR(cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1168 | rc = io_subchannel_recog(cdev, sch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | if (rc) { |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1170 | spin_lock_irqsave(sch->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | sch->dev.driver_data = NULL; |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1172 | spin_unlock_irqrestore(sch->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | if (cdev->dev.release) |
| 1174 | cdev->dev.release(&cdev->dev); |
| 1175 | } |
| 1176 | |
| 1177 | return rc; |
| 1178 | } |
| 1179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | static int |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1181 | io_subchannel_remove (struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | { |
| 1183 | struct ccw_device *cdev; |
| 1184 | unsigned long flags; |
| 1185 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1186 | if (!sch->dev.driver_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | return 0; |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1188 | cdev = sch->dev.driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | /* Set ccw device to not operational and drop reference. */ |
| 1190 | spin_lock_irqsave(cdev->ccwlock, flags); |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1191 | sch->dev.driver_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | cdev->private->state = DEV_STATE_NOT_OPER; |
| 1193 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
Cornelia Huck | ef99516 | 2007-04-27 16:01:39 +0200 | [diff] [blame] | 1194 | ccw_device_unregister(cdev); |
| 1195 | put_device(&cdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | return 0; |
| 1197 | } |
| 1198 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 1199 | static int io_subchannel_notify(struct subchannel *sch, int event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | { |
| 1201 | struct ccw_device *cdev; |
| 1202 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 1203 | cdev = sch->dev.driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | if (!cdev) |
| 1205 | return 0; |
| 1206 | if (!cdev->drv) |
| 1207 | return 0; |
| 1208 | if (!cdev->online) |
| 1209 | return 0; |
| 1210 | return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0; |
| 1211 | } |
| 1212 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 1213 | static void io_subchannel_verify(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | { |
| 1215 | struct ccw_device *cdev; |
| 1216 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 1217 | cdev = sch->dev.driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | if (cdev) |
| 1219 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
| 1220 | } |
| 1221 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 1222 | static void io_subchannel_ioterm(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | { |
| 1224 | struct ccw_device *cdev; |
| 1225 | |
Cornelia Huck | 602b20f | 2008-01-26 14:10:39 +0100 | [diff] [blame^] | 1226 | cdev = sch->dev.driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | if (!cdev) |
| 1228 | return; |
Cornelia Huck | d23861f | 2006-12-04 15:41:04 +0100 | [diff] [blame] | 1229 | /* Internal I/O will be retried by the interrupt handler. */ |
| 1230 | if (cdev->private->flags.intretry) |
| 1231 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | cdev->private->state = DEV_STATE_CLEAR_VERIFY; |
| 1233 | if (cdev->handler) |
| 1234 | cdev->handler(cdev, cdev->private->intparm, |
| 1235 | ERR_PTR(-EIO)); |
| 1236 | } |
| 1237 | |
| 1238 | static void |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1239 | io_subchannel_shutdown(struct subchannel *sch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | struct ccw_device *cdev; |
| 1242 | int ret; |
| 1243 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1244 | cdev = sch->dev.driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1246 | if (cio_is_console(sch->schid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | return; |
| 1248 | if (!sch->schib.pmcw.ena) |
| 1249 | /* Nothing to do. */ |
| 1250 | return; |
| 1251 | ret = cio_disable_subchannel(sch); |
| 1252 | if (ret != -EBUSY) |
| 1253 | /* Subchannel is disabled, we're done. */ |
| 1254 | return; |
| 1255 | cdev->private->state = DEV_STATE_QUIESCE; |
| 1256 | if (cdev->handler) |
| 1257 | cdev->handler(cdev, cdev->private->intparm, |
| 1258 | ERR_PTR(-EIO)); |
| 1259 | ret = ccw_device_cancel_halt_clear(cdev); |
| 1260 | if (ret == -EBUSY) { |
| 1261 | ccw_device_set_timeout(cdev, HZ/10); |
| 1262 | wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev)); |
| 1263 | } |
| 1264 | cio_disable_subchannel(sch); |
| 1265 | } |
| 1266 | |
| 1267 | #ifdef CONFIG_CCW_CONSOLE |
| 1268 | static struct ccw_device console_cdev; |
| 1269 | static struct ccw_device_private console_private; |
| 1270 | static int console_cdev_in_use; |
| 1271 | |
Cornelia Huck | 2ec2298 | 2006-12-08 15:54:26 +0100 | [diff] [blame] | 1272 | static DEFINE_SPINLOCK(ccw_console_lock); |
| 1273 | |
| 1274 | spinlock_t * cio_get_console_lock(void) |
| 1275 | { |
| 1276 | return &ccw_console_lock; |
| 1277 | } |
| 1278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | static int |
| 1280 | ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch) |
| 1281 | { |
| 1282 | int rc; |
| 1283 | |
| 1284 | /* Initialize the ccw_device structure. */ |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 1285 | cdev->dev.parent= &sch->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | rc = io_subchannel_recog(cdev, sch); |
| 1287 | if (rc) |
| 1288 | return rc; |
| 1289 | |
| 1290 | /* Now wait for the async. recognition to come to an end. */ |
| 1291 | spin_lock_irq(cdev->ccwlock); |
| 1292 | while (!dev_fsm_final_state(cdev)) |
| 1293 | wait_cons_dev(); |
| 1294 | rc = -EIO; |
| 1295 | if (cdev->private->state != DEV_STATE_OFFLINE) |
| 1296 | goto out_unlock; |
| 1297 | ccw_device_online(cdev); |
| 1298 | while (!dev_fsm_final_state(cdev)) |
| 1299 | wait_cons_dev(); |
| 1300 | if (cdev->private->state != DEV_STATE_ONLINE) |
| 1301 | goto out_unlock; |
| 1302 | rc = 0; |
| 1303 | out_unlock: |
| 1304 | spin_unlock_irq(cdev->ccwlock); |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | struct ccw_device * |
| 1309 | ccw_device_probe_console(void) |
| 1310 | { |
| 1311 | struct subchannel *sch; |
| 1312 | int ret; |
| 1313 | |
| 1314 | if (xchg(&console_cdev_in_use, 1) != 0) |
Peter Oberparleiter | 600b5d1 | 2006-02-01 03:06:35 -0800 | [diff] [blame] | 1315 | return ERR_PTR(-EBUSY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | sch = cio_probe_console(); |
| 1317 | if (IS_ERR(sch)) { |
| 1318 | console_cdev_in_use = 0; |
| 1319 | return (void *) sch; |
| 1320 | } |
| 1321 | memset(&console_cdev, 0, sizeof(struct ccw_device)); |
| 1322 | memset(&console_private, 0, sizeof(struct ccw_device_private)); |
| 1323 | console_cdev.private = &console_private; |
Martin Schwidefsky | c163753 | 2006-12-08 15:53:57 +0100 | [diff] [blame] | 1324 | console_private.cdev = &console_cdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | ret = ccw_device_console_enable(&console_cdev, sch); |
| 1326 | if (ret) { |
| 1327 | cio_release_console(); |
| 1328 | console_cdev_in_use = 0; |
| 1329 | return ERR_PTR(ret); |
| 1330 | } |
| 1331 | console_cdev.online = 1; |
| 1332 | return &console_cdev; |
| 1333 | } |
| 1334 | #endif |
| 1335 | |
| 1336 | /* |
| 1337 | * get ccw_device matching the busid, but only if owned by cdrv |
| 1338 | */ |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1339 | static int |
| 1340 | __ccwdev_check_busid(struct device *dev, void *id) |
| 1341 | { |
| 1342 | char *bus_id; |
| 1343 | |
Cornelia Huck | 12975ae | 2006-10-11 15:31:47 +0200 | [diff] [blame] | 1344 | bus_id = id; |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1345 | |
| 1346 | return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0); |
| 1347 | } |
| 1348 | |
| 1349 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1350 | /** |
| 1351 | * get_ccwdev_by_busid() - obtain device from a bus id |
| 1352 | * @cdrv: driver the device is owned by |
| 1353 | * @bus_id: bus id of the device to be searched |
| 1354 | * |
| 1355 | * This function searches all devices owned by @cdrv for a device with a bus |
| 1356 | * id matching @bus_id. |
| 1357 | * Returns: |
| 1358 | * If a match is found, its reference count of the found device is increased |
| 1359 | * and it is returned; else %NULL is returned. |
| 1360 | */ |
| 1361 | struct ccw_device *get_ccwdev_by_busid(struct ccw_driver *cdrv, |
| 1362 | const char *bus_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | { |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1364 | struct device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | struct device_driver *drv; |
| 1366 | |
| 1367 | drv = get_driver(&cdrv->driver); |
| 1368 | if (!drv) |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1369 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 1371 | dev = driver_find_device(drv, NULL, (void *)bus_id, |
| 1372 | __ccwdev_check_busid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | put_driver(drv); |
| 1374 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1375 | return dev ? to_ccwdev(dev) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /************************** device driver handling ************************/ |
| 1379 | |
| 1380 | /* This is the implementation of the ccw_driver class. The probe, remove |
| 1381 | * and release methods are initially very similar to the device_driver |
| 1382 | * implementations, with the difference that they have ccw_device |
| 1383 | * arguments. |
| 1384 | * |
| 1385 | * A ccw driver also contains the information that is needed for |
| 1386 | * device matching. |
| 1387 | */ |
| 1388 | static int |
| 1389 | ccw_device_probe (struct device *dev) |
| 1390 | { |
| 1391 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1392 | struct ccw_driver *cdrv = to_ccwdrv(dev->driver); |
| 1393 | int ret; |
| 1394 | |
| 1395 | cdev->drv = cdrv; /* to let the driver call _set_online */ |
| 1396 | |
| 1397 | ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV; |
| 1398 | |
| 1399 | if (ret) { |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1400 | cdev->drv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | return ret; |
| 1402 | } |
| 1403 | |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | static int |
| 1408 | ccw_device_remove (struct device *dev) |
| 1409 | { |
| 1410 | struct ccw_device *cdev = to_ccwdev(dev); |
| 1411 | struct ccw_driver *cdrv = cdev->drv; |
| 1412 | int ret; |
| 1413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | if (cdrv->remove) |
| 1415 | cdrv->remove(cdev); |
| 1416 | if (cdev->online) { |
| 1417 | cdev->online = 0; |
| 1418 | spin_lock_irq(cdev->ccwlock); |
| 1419 | ret = ccw_device_offline(cdev); |
| 1420 | spin_unlock_irq(cdev->ccwlock); |
| 1421 | if (ret == 0) |
| 1422 | wait_event(cdev->private->wait_q, |
| 1423 | dev_fsm_final_state(cdev)); |
| 1424 | else |
| 1425 | //FIXME: we can't fail! |
Cornelia Huck | e556bbb | 2007-07-27 12:29:19 +0200 | [diff] [blame] | 1426 | CIO_MSG_EVENT(2, "ccw_device_offline returned %d, " |
| 1427 | "device 0.%x.%04x\n", |
| 1428 | ret, cdev->private->dev_id.ssid, |
| 1429 | cdev->private->dev_id.devno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
| 1431 | ccw_device_set_timeout(cdev, 0); |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 1432 | cdev->drv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | return 0; |
| 1434 | } |
| 1435 | |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1436 | static void ccw_device_shutdown(struct device *dev) |
| 1437 | { |
| 1438 | struct ccw_device *cdev; |
| 1439 | |
| 1440 | cdev = to_ccwdev(dev); |
| 1441 | if (cdev->drv && cdev->drv->shutdown) |
| 1442 | cdev->drv->shutdown(cdev); |
Cornelia Huck | 1842f2b | 2007-10-12 16:11:22 +0200 | [diff] [blame] | 1443 | disable_cmf(cdev); |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1446 | struct bus_type ccw_bus_type = { |
| 1447 | .name = "ccw", |
| 1448 | .match = ccw_bus_match, |
| 1449 | .uevent = ccw_uevent, |
| 1450 | .probe = ccw_device_probe, |
| 1451 | .remove = ccw_device_remove, |
Cornelia Huck | 958974fb | 2007-10-12 16:11:21 +0200 | [diff] [blame] | 1452 | .shutdown = ccw_device_shutdown, |
Cornelia Huck | 8bbace7 | 2006-01-11 10:56:22 +0100 | [diff] [blame] | 1453 | }; |
| 1454 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1455 | /** |
| 1456 | * ccw_driver_register() - register a ccw driver |
| 1457 | * @cdriver: driver to be registered |
| 1458 | * |
| 1459 | * This function is mainly a wrapper around driver_register(). |
| 1460 | * Returns: |
| 1461 | * %0 on success and a negative error value on failure. |
| 1462 | */ |
| 1463 | int ccw_driver_register(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | { |
| 1465 | struct device_driver *drv = &cdriver->driver; |
| 1466 | |
| 1467 | drv->bus = &ccw_bus_type; |
| 1468 | drv->name = cdriver->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
| 1470 | return driver_register(drv); |
| 1471 | } |
| 1472 | |
Cornelia Huck | b2ffd8e | 2007-10-12 16:11:17 +0200 | [diff] [blame] | 1473 | /** |
| 1474 | * ccw_driver_unregister() - deregister a ccw driver |
| 1475 | * @cdriver: driver to be deregistered |
| 1476 | * |
| 1477 | * This function is mainly a wrapper around driver_unregister(). |
| 1478 | */ |
| 1479 | void ccw_driver_unregister(struct ccw_driver *cdriver) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | { |
| 1481 | driver_unregister(&cdriver->driver); |
| 1482 | } |
| 1483 | |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1484 | /* Helper func for qdio. */ |
| 1485 | struct subchannel_id |
| 1486 | ccw_device_get_subchannel_id(struct ccw_device *cdev) |
| 1487 | { |
| 1488 | struct subchannel *sch; |
| 1489 | |
| 1490 | sch = to_subchannel(cdev->dev.parent); |
| 1491 | return sch->schid; |
| 1492 | } |
| 1493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | MODULE_LICENSE("GPL"); |
| 1495 | EXPORT_SYMBOL(ccw_device_set_online); |
| 1496 | EXPORT_SYMBOL(ccw_device_set_offline); |
| 1497 | EXPORT_SYMBOL(ccw_driver_register); |
| 1498 | EXPORT_SYMBOL(ccw_driver_unregister); |
| 1499 | EXPORT_SYMBOL(get_ccwdev_by_busid); |
| 1500 | EXPORT_SYMBOL(ccw_bus_type); |
| 1501 | EXPORT_SYMBOL(ccw_device_work); |
| 1502 | EXPORT_SYMBOL(ccw_device_notify_work); |
Cornelia Huck | a8237fc | 2006-01-06 00:19:21 -0800 | [diff] [blame] | 1503 | EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id); |