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