Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/cio/ccwgroup.c |
| 3 | * bus driver for ccwgroup |
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 | */ |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/ctype.h> |
| 17 | #include <linux/dcache.h> |
| 18 | |
| 19 | #include <asm/semaphore.h> |
| 20 | #include <asm/ccwdev.h> |
| 21 | #include <asm/ccwgroup.h> |
| 22 | |
| 23 | /* In Linux 2.4, we had a channel device layer called "chandev" |
| 24 | * that did all sorts of obscure stuff for networking devices. |
| 25 | * This is another driver that serves as a replacement for just |
| 26 | * one of its functions, namely the translation of single subchannels |
| 27 | * to devices that use multiple subchannels. |
| 28 | */ |
| 29 | |
| 30 | /* a device matches a driver if all its slave devices match the same |
| 31 | * entry of the driver */ |
| 32 | static int |
| 33 | ccwgroup_bus_match (struct device * dev, struct device_driver * drv) |
| 34 | { |
| 35 | struct ccwgroup_device *gdev; |
| 36 | struct ccwgroup_driver *gdrv; |
| 37 | |
| 38 | gdev = container_of(dev, struct ccwgroup_device, dev); |
| 39 | gdrv = container_of(drv, struct ccwgroup_driver, driver); |
| 40 | |
| 41 | if (gdev->creator_id == gdrv->driver_id) |
| 42 | return 1; |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | static int |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame^] | 47 | ccwgroup_uevent (struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
| 49 | /* TODO */ |
| 50 | return 0; |
| 51 | } |
| 52 | |
Russell King | f9ccf45 | 2006-01-05 14:42:09 +0000 | [diff] [blame] | 53 | static struct bus_type ccwgroup_bus_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 55 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | __ccwgroup_remove_symlinks(struct ccwgroup_device *gdev) |
| 57 | { |
| 58 | int i; |
| 59 | char str[8]; |
| 60 | |
| 61 | for (i = 0; i < gdev->count; i++) { |
| 62 | sprintf(str, "cdev%d", i); |
| 63 | sysfs_remove_link(&gdev->dev.kobj, str); |
| 64 | sysfs_remove_link(&gdev->cdev[i]->dev.kobj, "group_device"); |
| 65 | } |
| 66 | |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Provide an 'ungroup' attribute so the user can remove group devices no |
| 71 | * longer needed or accidentially created. Saves memory :) |
| 72 | */ |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 73 | static void ccwgroup_ungroup_callback(struct device *dev) |
| 74 | { |
| 75 | struct ccwgroup_device *gdev = to_ccwgroupdev(dev); |
| 76 | |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 77 | mutex_lock(&gdev->reg_mutex); |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 78 | __ccwgroup_remove_symlinks(gdev); |
| 79 | device_unregister(dev); |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 80 | mutex_unlock(&gdev->reg_mutex); |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 81 | } |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 84 | ccwgroup_ungroup_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
| 86 | struct ccwgroup_device *gdev; |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 87 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | gdev = to_ccwgroupdev(dev); |
| 90 | |
| 91 | if (gdev->state != CCWGROUP_OFFLINE) |
| 92 | return -EINVAL; |
| 93 | |
Alan Stern | d9a9cdf | 2007-03-15 15:50:34 -0400 | [diff] [blame] | 94 | /* Note that we cannot unregister the device from one of its |
| 95 | * attribute methods, so we have to use this roundabout approach. |
| 96 | */ |
| 97 | rc = device_schedule_callback(dev, ccwgroup_ungroup_callback); |
| 98 | if (rc) |
| 99 | count = rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return count; |
| 101 | } |
| 102 | |
| 103 | static DEVICE_ATTR(ungroup, 0200, NULL, ccwgroup_ungroup_store); |
| 104 | |
| 105 | static void |
| 106 | ccwgroup_release (struct device *dev) |
| 107 | { |
| 108 | struct ccwgroup_device *gdev; |
| 109 | int i; |
| 110 | |
| 111 | gdev = to_ccwgroupdev(dev); |
| 112 | |
| 113 | for (i = 0; i < gdev->count; i++) { |
| 114 | gdev->cdev[i]->dev.driver_data = NULL; |
| 115 | put_device(&gdev->cdev[i]->dev); |
| 116 | } |
| 117 | kfree(gdev); |
| 118 | } |
| 119 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 120 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | __ccwgroup_create_symlinks(struct ccwgroup_device *gdev) |
| 122 | { |
| 123 | char str[8]; |
| 124 | int i, rc; |
| 125 | |
| 126 | for (i = 0; i < gdev->count; i++) { |
| 127 | rc = sysfs_create_link(&gdev->cdev[i]->dev.kobj, &gdev->dev.kobj, |
| 128 | "group_device"); |
| 129 | if (rc) { |
| 130 | for (--i; i >= 0; i--) |
| 131 | sysfs_remove_link(&gdev->cdev[i]->dev.kobj, |
| 132 | "group_device"); |
| 133 | return rc; |
| 134 | } |
| 135 | } |
| 136 | for (i = 0; i < gdev->count; i++) { |
| 137 | sprintf(str, "cdev%d", i); |
| 138 | rc = sysfs_create_link(&gdev->dev.kobj, &gdev->cdev[i]->dev.kobj, |
| 139 | str); |
| 140 | if (rc) { |
| 141 | for (--i; i >= 0; i--) { |
| 142 | sprintf(str, "cdev%d", i); |
| 143 | sysfs_remove_link(&gdev->dev.kobj, str); |
| 144 | } |
| 145 | for (i = 0; i < gdev->count; i++) |
| 146 | sysfs_remove_link(&gdev->cdev[i]->dev.kobj, |
| 147 | "group_device"); |
| 148 | return rc; |
| 149 | } |
| 150 | } |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | /* |
| 155 | * try to add a new ccwgroup device for one driver |
| 156 | * argc and argv[] are a list of bus_id's of devices |
| 157 | * belonging to the driver. |
| 158 | */ |
| 159 | int |
| 160 | ccwgroup_create(struct device *root, |
| 161 | unsigned int creator_id, |
| 162 | struct ccw_driver *cdrv, |
| 163 | int argc, char *argv[]) |
| 164 | { |
| 165 | struct ccwgroup_device *gdev; |
| 166 | int i; |
| 167 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
| 169 | if (argc > 256) /* disallow dumb users */ |
| 170 | return -EINVAL; |
| 171 | |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 172 | gdev = kzalloc(sizeof(*gdev) + argc*sizeof(gdev->cdev[0]), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | if (!gdev) |
| 174 | return -ENOMEM; |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | atomic_set(&gdev->onoff, 0); |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 177 | mutex_init(&gdev->reg_mutex); |
| 178 | mutex_lock(&gdev->reg_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | for (i = 0; i < argc; i++) { |
| 180 | gdev->cdev[i] = get_ccwdev_by_busid(cdrv, argv[i]); |
| 181 | |
| 182 | /* all devices have to be of the same type in |
| 183 | * order to be grouped */ |
| 184 | if (!gdev->cdev[i] |
| 185 | || gdev->cdev[i]->id.driver_info != |
| 186 | gdev->cdev[0]->id.driver_info) { |
| 187 | rc = -EINVAL; |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 188 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | /* Don't allow a device to belong to more than one group. */ |
| 191 | if (gdev->cdev[i]->dev.driver_data) { |
| 192 | rc = -EINVAL; |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 193 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | gdev->cdev[i]->dev.driver_data = gdev; |
Cornelia Huck | 1708822 | 2006-07-27 14:00:33 +0200 | [diff] [blame] | 196 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | gdev->creator_id = creator_id; |
| 199 | gdev->count = argc; |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 200 | gdev->dev.bus = &ccwgroup_bus_type; |
| 201 | gdev->dev.parent = root; |
| 202 | gdev->dev.release = ccwgroup_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | snprintf (gdev->dev.bus_id, BUS_ID_SIZE, "%s", |
| 205 | gdev->cdev[0]->dev.bus_id); |
| 206 | |
| 207 | rc = device_register(&gdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (rc) |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 209 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | get_device(&gdev->dev); |
| 211 | rc = device_create_file(&gdev->dev, &dev_attr_ungroup); |
| 212 | |
| 213 | if (rc) { |
| 214 | device_unregister(&gdev->dev); |
| 215 | goto error; |
| 216 | } |
| 217 | |
| 218 | rc = __ccwgroup_create_symlinks(gdev); |
| 219 | if (!rc) { |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 220 | mutex_unlock(&gdev->reg_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | put_device(&gdev->dev); |
| 222 | return 0; |
| 223 | } |
| 224 | device_remove_file(&gdev->dev, &dev_attr_ungroup); |
| 225 | device_unregister(&gdev->dev); |
| 226 | error: |
| 227 | for (i = 0; i < argc; i++) |
| 228 | if (gdev->cdev[i]) { |
Cornelia Huck | 1708822 | 2006-07-27 14:00:33 +0200 | [diff] [blame] | 229 | if (gdev->cdev[i]->dev.driver_data == gdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | gdev->cdev[i]->dev.driver_data = NULL; |
Cornelia Huck | 1708822 | 2006-07-27 14:00:33 +0200 | [diff] [blame] | 231 | put_device(&gdev->cdev[i]->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 233 | mutex_unlock(&gdev->reg_mutex); |
| 234 | put_device(&gdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return rc; |
| 236 | } |
| 237 | |
| 238 | static int __init |
| 239 | init_ccwgroup (void) |
| 240 | { |
| 241 | return bus_register (&ccwgroup_bus_type); |
| 242 | } |
| 243 | |
| 244 | static void __exit |
| 245 | cleanup_ccwgroup (void) |
| 246 | { |
| 247 | bus_unregister (&ccwgroup_bus_type); |
| 248 | } |
| 249 | |
| 250 | module_init(init_ccwgroup); |
| 251 | module_exit(cleanup_ccwgroup); |
| 252 | |
| 253 | /************************** driver stuff ******************************/ |
| 254 | |
| 255 | static int |
| 256 | ccwgroup_set_online(struct ccwgroup_device *gdev) |
| 257 | { |
| 258 | struct ccwgroup_driver *gdrv; |
| 259 | int ret; |
| 260 | |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 261 | if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return -EAGAIN; |
| 263 | if (gdev->state == CCWGROUP_ONLINE) { |
| 264 | ret = 0; |
| 265 | goto out; |
| 266 | } |
| 267 | if (!gdev->dev.driver) { |
| 268 | ret = -EINVAL; |
| 269 | goto out; |
| 270 | } |
| 271 | gdrv = to_ccwgroupdrv (gdev->dev.driver); |
Cornelia Huck | a001640 | 2005-11-07 00:59:05 -0800 | [diff] [blame] | 272 | if ((ret = gdrv->set_online ? gdrv->set_online(gdev) : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | goto out; |
| 274 | |
| 275 | gdev->state = CCWGROUP_ONLINE; |
| 276 | out: |
| 277 | atomic_set(&gdev->onoff, 0); |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | static int |
| 282 | ccwgroup_set_offline(struct ccwgroup_device *gdev) |
| 283 | { |
| 284 | struct ccwgroup_driver *gdrv; |
| 285 | int ret; |
| 286 | |
Martin Schwidefsky | 973bd99 | 2006-01-06 00:19:07 -0800 | [diff] [blame] | 287 | if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | return -EAGAIN; |
| 289 | if (gdev->state == CCWGROUP_OFFLINE) { |
| 290 | ret = 0; |
| 291 | goto out; |
| 292 | } |
| 293 | if (!gdev->dev.driver) { |
| 294 | ret = -EINVAL; |
| 295 | goto out; |
| 296 | } |
| 297 | gdrv = to_ccwgroupdrv (gdev->dev.driver); |
Cornelia Huck | a001640 | 2005-11-07 00:59:05 -0800 | [diff] [blame] | 298 | if ((ret = gdrv->set_offline ? gdrv->set_offline(gdev) : 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | goto out; |
| 300 | |
| 301 | gdev->state = CCWGROUP_OFFLINE; |
| 302 | out: |
| 303 | atomic_set(&gdev->onoff, 0); |
| 304 | return ret; |
| 305 | } |
| 306 | |
| 307 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 308 | ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
| 310 | struct ccwgroup_device *gdev; |
| 311 | struct ccwgroup_driver *gdrv; |
| 312 | unsigned int value; |
| 313 | int ret; |
| 314 | |
| 315 | gdev = to_ccwgroupdev(dev); |
| 316 | if (!dev->driver) |
| 317 | return count; |
| 318 | |
| 319 | gdrv = to_ccwgroupdrv (gdev->dev.driver); |
| 320 | if (!try_module_get(gdrv->owner)) |
| 321 | return -EINVAL; |
| 322 | |
Heiko Carstens | d2c993d | 2006-07-12 16:41:55 +0200 | [diff] [blame] | 323 | value = simple_strtoul(buf, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | ret = count; |
| 325 | if (value == 1) |
| 326 | ccwgroup_set_online(gdev); |
| 327 | else if (value == 0) |
| 328 | ccwgroup_set_offline(gdev); |
| 329 | else |
| 330 | ret = -EINVAL; |
| 331 | module_put(gdrv->owner); |
| 332 | return ret; |
| 333 | } |
| 334 | |
| 335 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 336 | ccwgroup_online_show (struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
| 338 | int online; |
| 339 | |
| 340 | online = (to_ccwgroupdev(dev)->state == CCWGROUP_ONLINE); |
| 341 | |
| 342 | return sprintf(buf, online ? "1\n" : "0\n"); |
| 343 | } |
| 344 | |
| 345 | static DEVICE_ATTR(online, 0644, ccwgroup_online_show, ccwgroup_online_store); |
| 346 | |
| 347 | static int |
| 348 | ccwgroup_probe (struct device *dev) |
| 349 | { |
| 350 | struct ccwgroup_device *gdev; |
| 351 | struct ccwgroup_driver *gdrv; |
| 352 | |
| 353 | int ret; |
| 354 | |
| 355 | gdev = to_ccwgroupdev(dev); |
| 356 | gdrv = to_ccwgroupdrv(dev->driver); |
| 357 | |
| 358 | if ((ret = device_create_file(dev, &dev_attr_online))) |
| 359 | return ret; |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | ret = gdrv->probe ? gdrv->probe(gdev) : -ENODEV; |
| 362 | if (ret) |
| 363 | device_remove_file(dev, &dev_attr_online); |
| 364 | |
| 365 | return ret; |
| 366 | } |
| 367 | |
| 368 | static int |
| 369 | ccwgroup_remove (struct device *dev) |
| 370 | { |
| 371 | struct ccwgroup_device *gdev; |
| 372 | struct ccwgroup_driver *gdrv; |
| 373 | |
| 374 | gdev = to_ccwgroupdev(dev); |
| 375 | gdrv = to_ccwgroupdrv(dev->driver); |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | device_remove_file(dev, &dev_attr_online); |
| 378 | |
| 379 | if (gdrv && gdrv->remove) |
| 380 | gdrv->remove(gdev); |
| 381 | return 0; |
| 382 | } |
| 383 | |
Russell King | f9ccf45 | 2006-01-05 14:42:09 +0000 | [diff] [blame] | 384 | static struct bus_type ccwgroup_bus_type = { |
| 385 | .name = "ccwgroup", |
| 386 | .match = ccwgroup_bus_match, |
| 387 | .uevent = ccwgroup_uevent, |
| 388 | .probe = ccwgroup_probe, |
| 389 | .remove = ccwgroup_remove, |
| 390 | }; |
| 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | int |
| 393 | ccwgroup_driver_register (struct ccwgroup_driver *cdriver) |
| 394 | { |
| 395 | /* register our new driver with the core */ |
Heiko Carstens | 292888c | 2006-08-30 14:33:35 +0200 | [diff] [blame] | 396 | cdriver->driver.bus = &ccwgroup_bus_type; |
| 397 | cdriver->driver.name = cdriver->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | return driver_register(&cdriver->driver); |
| 400 | } |
| 401 | |
Cornelia Huck | b0744bd | 2005-06-25 14:55:27 -0700 | [diff] [blame] | 402 | static int |
Cornelia Huck | 887ab59 | 2006-06-29 14:56:52 +0200 | [diff] [blame] | 403 | __ccwgroup_match_all(struct device *dev, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { |
Cornelia Huck | 887ab59 | 2006-06-29 14:56:52 +0200 | [diff] [blame] | 405 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | void |
| 409 | ccwgroup_driver_unregister (struct ccwgroup_driver *cdriver) |
| 410 | { |
Cornelia Huck | 887ab59 | 2006-06-29 14:56:52 +0200 | [diff] [blame] | 411 | struct device *dev; |
| 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | /* We don't want ccwgroup devices to live longer than their driver. */ |
| 414 | get_driver(&cdriver->driver); |
Cornelia Huck | 887ab59 | 2006-06-29 14:56:52 +0200 | [diff] [blame] | 415 | while ((dev = driver_find_device(&cdriver->driver, NULL, NULL, |
| 416 | __ccwgroup_match_all))) { |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 417 | struct ccwgroup_device *gdev = to_ccwgroupdev(dev); |
| 418 | |
| 419 | mutex_lock(&gdev->reg_mutex); |
| 420 | __ccwgroup_remove_symlinks(gdev); |
Cornelia Huck | 887ab59 | 2006-06-29 14:56:52 +0200 | [diff] [blame] | 421 | device_unregister(dev); |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 422 | mutex_unlock(&gdev->reg_mutex); |
Cornelia Huck | 887ab59 | 2006-06-29 14:56:52 +0200 | [diff] [blame] | 423 | put_device(dev); |
| 424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | put_driver(&cdriver->driver); |
| 426 | driver_unregister(&cdriver->driver); |
| 427 | } |
| 428 | |
| 429 | int |
| 430 | ccwgroup_probe_ccwdev(struct ccw_device *cdev) |
| 431 | { |
| 432 | return 0; |
| 433 | } |
| 434 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 435 | static struct ccwgroup_device * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | __ccwgroup_get_gdev_by_cdev(struct ccw_device *cdev) |
| 437 | { |
| 438 | struct ccwgroup_device *gdev; |
| 439 | |
| 440 | if (cdev->dev.driver_data) { |
| 441 | gdev = (struct ccwgroup_device *)cdev->dev.driver_data; |
| 442 | if (get_device(&gdev->dev)) { |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 443 | mutex_lock(&gdev->reg_mutex); |
Daniel Ritz | d305ef5 | 2005-09-22 00:47:24 -0700 | [diff] [blame] | 444 | if (device_is_registered(&gdev->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | return gdev; |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 446 | mutex_unlock(&gdev->reg_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | put_device(&gdev->dev); |
| 448 | } |
| 449 | return NULL; |
| 450 | } |
| 451 | return NULL; |
| 452 | } |
| 453 | |
| 454 | void |
| 455 | ccwgroup_remove_ccwdev(struct ccw_device *cdev) |
| 456 | { |
| 457 | struct ccwgroup_device *gdev; |
| 458 | |
| 459 | /* Ignore offlining errors, device is gone anyway. */ |
| 460 | ccw_device_set_offline(cdev); |
| 461 | /* If one of its devices is gone, the whole group is done for. */ |
| 462 | gdev = __ccwgroup_get_gdev_by_cdev(cdev); |
| 463 | if (gdev) { |
| 464 | __ccwgroup_remove_symlinks(gdev); |
| 465 | device_unregister(&gdev->dev); |
Cornelia Huck | d76123e | 2007-04-27 16:01:37 +0200 | [diff] [blame] | 466 | mutex_unlock(&gdev->reg_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | put_device(&gdev->dev); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | MODULE_LICENSE("GPL"); |
| 472 | EXPORT_SYMBOL(ccwgroup_driver_register); |
| 473 | EXPORT_SYMBOL(ccwgroup_driver_unregister); |
| 474 | EXPORT_SYMBOL(ccwgroup_create); |
| 475 | EXPORT_SYMBOL(ccwgroup_probe_ccwdev); |
| 476 | EXPORT_SYMBOL(ccwgroup_remove_ccwdev); |