ccwgroup.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. * bus driver for ccwgroup
  3. *
  4. * Copyright IBM Corp. 2002, 2009
  5. *
  6. * Author(s): Arnd Bergmann (arndb@de.ibm.com)
  7. * Cornelia Huck (cornelia.huck@de.ibm.com)
  8. */
  9. #include <linux/module.h>
  10. #include <linux/errno.h>
  11. #include <linux/slab.h>
  12. #include <linux/list.h>
  13. #include <linux/device.h>
  14. #include <linux/init.h>
  15. #include <linux/ctype.h>
  16. #include <linux/dcache.h>
  17. #include <asm/ccwdev.h>
  18. #include <asm/ccwgroup.h>
  19. #define CCW_BUS_ID_SIZE 20
  20. /* In Linux 2.4, we had a channel device layer called "chandev"
  21. * that did all sorts of obscure stuff for networking devices.
  22. * This is another driver that serves as a replacement for just
  23. * one of its functions, namely the translation of single subchannels
  24. * to devices that use multiple subchannels.
  25. */
  26. /* a device matches a driver if all its slave devices match the same
  27. * entry of the driver */
  28. static int
  29. ccwgroup_bus_match (struct device * dev, struct device_driver * drv)
  30. {
  31. struct ccwgroup_device *gdev;
  32. struct ccwgroup_driver *gdrv;
  33. gdev = to_ccwgroupdev(dev);
  34. gdrv = to_ccwgroupdrv(drv);
  35. if (gdev->creator_id == gdrv->driver_id)
  36. return 1;
  37. return 0;
  38. }
  39. static int
  40. ccwgroup_uevent (struct device *dev, struct kobj_uevent_env *env)
  41. {
  42. /* TODO */
  43. return 0;
  44. }
  45. static struct bus_type ccwgroup_bus_type;
  46. static void
  47. __ccwgroup_remove_symlinks(struct ccwgroup_device *gdev)
  48. {
  49. int i;
  50. char str[8];
  51. for (i = 0; i < gdev->count; i++) {
  52. sprintf(str, "cdev%d", i);
  53. sysfs_remove_link(&gdev->dev.kobj, str);
  54. sysfs_remove_link(&gdev->cdev[i]->dev.kobj, "group_device");
  55. }
  56. }
  57. /*
  58. * Remove references from ccw devices to ccw group device and from
  59. * ccw group device to ccw devices.
  60. */
  61. static void __ccwgroup_remove_cdev_refs(struct ccwgroup_device *gdev)
  62. {
  63. struct ccw_device *cdev;
  64. int i;
  65. for (i = 0; i < gdev->count; i++) {
  66. cdev = gdev->cdev[i];
  67. if (!cdev)
  68. continue;
  69. spin_lock_irq(cdev->ccwlock);
  70. dev_set_drvdata(&cdev->dev, NULL);
  71. spin_unlock_irq(cdev->ccwlock);
  72. gdev->cdev[i] = NULL;
  73. put_device(&cdev->dev);
  74. }
  75. }
  76. static ssize_t ccwgroup_online_store(struct device *dev,
  77. struct device_attribute *attr,
  78. const char *buf, size_t count);
  79. static ssize_t ccwgroup_online_show(struct device *dev,
  80. struct device_attribute *attr,
  81. char *buf);
  82. /*
  83. * Provide an 'ungroup' attribute so the user can remove group devices no
  84. * longer needed or accidentially created. Saves memory :)
  85. */
  86. static void ccwgroup_ungroup_callback(struct device *dev)
  87. {
  88. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  89. mutex_lock(&gdev->reg_mutex);
  90. if (device_is_registered(&gdev->dev)) {
  91. __ccwgroup_remove_symlinks(gdev);
  92. device_unregister(dev);
  93. __ccwgroup_remove_cdev_refs(gdev);
  94. }
  95. mutex_unlock(&gdev->reg_mutex);
  96. }
  97. static ssize_t
  98. ccwgroup_ungroup_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  99. {
  100. struct ccwgroup_device *gdev;
  101. int rc;
  102. gdev = to_ccwgroupdev(dev);
  103. /* Prevent concurrent online/offline processing and ungrouping. */
  104. if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
  105. return -EAGAIN;
  106. if (gdev->state != CCWGROUP_OFFLINE) {
  107. rc = -EINVAL;
  108. goto out;
  109. }
  110. /* Note that we cannot unregister the device from one of its
  111. * attribute methods, so we have to use this roundabout approach.
  112. */
  113. rc = device_schedule_callback(dev, ccwgroup_ungroup_callback);
  114. out:
  115. if (rc) {
  116. if (rc != -EAGAIN)
  117. /* Release onoff "lock" when ungrouping failed. */
  118. atomic_set(&gdev->onoff, 0);
  119. return rc;
  120. }
  121. return count;
  122. }
  123. static DEVICE_ATTR(ungroup, 0200, NULL, ccwgroup_ungroup_store);
  124. static DEVICE_ATTR(online, 0644, ccwgroup_online_show, ccwgroup_online_store);
  125. static struct attribute *ccwgroup_attrs[] = {
  126. &dev_attr_online.attr,
  127. &dev_attr_ungroup.attr,
  128. NULL,
  129. };
  130. static struct attribute_group ccwgroup_attr_group = {
  131. .attrs = ccwgroup_attrs,
  132. };
  133. static const struct attribute_group *ccwgroup_attr_groups[] = {
  134. &ccwgroup_attr_group,
  135. NULL,
  136. };
  137. static void
  138. ccwgroup_release (struct device *dev)
  139. {
  140. kfree(to_ccwgroupdev(dev));
  141. }
  142. static int
  143. __ccwgroup_create_symlinks(struct ccwgroup_device *gdev)
  144. {
  145. char str[8];
  146. int i, rc;
  147. for (i = 0; i < gdev->count; i++) {
  148. rc = sysfs_create_link(&gdev->cdev[i]->dev.kobj, &gdev->dev.kobj,
  149. "group_device");
  150. if (rc) {
  151. for (--i; i >= 0; i--)
  152. sysfs_remove_link(&gdev->cdev[i]->dev.kobj,
  153. "group_device");
  154. return rc;
  155. }
  156. }
  157. for (i = 0; i < gdev->count; i++) {
  158. sprintf(str, "cdev%d", i);
  159. rc = sysfs_create_link(&gdev->dev.kobj, &gdev->cdev[i]->dev.kobj,
  160. str);
  161. if (rc) {
  162. for (--i; i >= 0; i--) {
  163. sprintf(str, "cdev%d", i);
  164. sysfs_remove_link(&gdev->dev.kobj, str);
  165. }
  166. for (i = 0; i < gdev->count; i++)
  167. sysfs_remove_link(&gdev->cdev[i]->dev.kobj,
  168. "group_device");
  169. return rc;
  170. }
  171. }
  172. return 0;
  173. }
  174. static int __get_next_bus_id(const char **buf, char *bus_id)
  175. {
  176. int rc, len;
  177. char *start, *end;
  178. start = (char *)*buf;
  179. end = strchr(start, ',');
  180. if (!end) {
  181. /* Last entry. Strip trailing newline, if applicable. */
  182. end = strchr(start, '\n');
  183. if (end)
  184. *end = '\0';
  185. len = strlen(start) + 1;
  186. } else {
  187. len = end - start + 1;
  188. end++;
  189. }
  190. if (len < CCW_BUS_ID_SIZE) {
  191. strlcpy(bus_id, start, len);
  192. rc = 0;
  193. } else
  194. rc = -EINVAL;
  195. *buf = end;
  196. return rc;
  197. }
  198. static int __is_valid_bus_id(char bus_id[CCW_BUS_ID_SIZE])
  199. {
  200. int cssid, ssid, devno;
  201. /* Must be of form %x.%x.%04x */
  202. if (sscanf(bus_id, "%x.%1x.%04x", &cssid, &ssid, &devno) != 3)
  203. return 0;
  204. return 1;
  205. }
  206. /**
  207. * ccwgroup_create_from_string() - create and register a ccw group device
  208. * @root: parent device for the new device
  209. * @creator_id: identifier of creating driver
  210. * @cdrv: ccw driver of slave devices
  211. * @num_devices: number of slave devices
  212. * @buf: buffer containing comma separated bus ids of slave devices
  213. *
  214. * Create and register a new ccw group device as a child of @root. Slave
  215. * devices are obtained from the list of bus ids given in @buf and must all
  216. * belong to @cdrv.
  217. * Returns:
  218. * %0 on success and an error code on failure.
  219. * Context:
  220. * non-atomic
  221. */
  222. int ccwgroup_create_from_string(struct device *root, unsigned int creator_id,
  223. struct ccw_driver *cdrv, int num_devices,
  224. const char *buf)
  225. {
  226. struct ccwgroup_device *gdev;
  227. int rc, i;
  228. char tmp_bus_id[CCW_BUS_ID_SIZE];
  229. const char *curr_buf;
  230. gdev = kzalloc(sizeof(*gdev) + num_devices * sizeof(gdev->cdev[0]),
  231. GFP_KERNEL);
  232. if (!gdev)
  233. return -ENOMEM;
  234. atomic_set(&gdev->onoff, 0);
  235. mutex_init(&gdev->reg_mutex);
  236. mutex_lock(&gdev->reg_mutex);
  237. gdev->creator_id = creator_id;
  238. gdev->count = num_devices;
  239. gdev->dev.bus = &ccwgroup_bus_type;
  240. gdev->dev.parent = root;
  241. gdev->dev.release = ccwgroup_release;
  242. device_initialize(&gdev->dev);
  243. curr_buf = buf;
  244. for (i = 0; i < num_devices && curr_buf; i++) {
  245. rc = __get_next_bus_id(&curr_buf, tmp_bus_id);
  246. if (rc != 0)
  247. goto error;
  248. if (!__is_valid_bus_id(tmp_bus_id)) {
  249. rc = -EINVAL;
  250. goto error;
  251. }
  252. gdev->cdev[i] = get_ccwdev_by_busid(cdrv, tmp_bus_id);
  253. /*
  254. * All devices have to be of the same type in
  255. * order to be grouped.
  256. */
  257. if (!gdev->cdev[i]
  258. || gdev->cdev[i]->id.driver_info !=
  259. gdev->cdev[0]->id.driver_info) {
  260. rc = -EINVAL;
  261. goto error;
  262. }
  263. /* Don't allow a device to belong to more than one group. */
  264. spin_lock_irq(gdev->cdev[i]->ccwlock);
  265. if (dev_get_drvdata(&gdev->cdev[i]->dev)) {
  266. spin_unlock_irq(gdev->cdev[i]->ccwlock);
  267. rc = -EINVAL;
  268. goto error;
  269. }
  270. dev_set_drvdata(&gdev->cdev[i]->dev, gdev);
  271. spin_unlock_irq(gdev->cdev[i]->ccwlock);
  272. }
  273. /* Check for sufficient number of bus ids. */
  274. if (i < num_devices && !curr_buf) {
  275. rc = -EINVAL;
  276. goto error;
  277. }
  278. /* Check for trailing stuff. */
  279. if (i == num_devices && strlen(curr_buf) > 0) {
  280. rc = -EINVAL;
  281. goto error;
  282. }
  283. dev_set_name(&gdev->dev, "%s", dev_name(&gdev->cdev[0]->dev));
  284. gdev->dev.groups = ccwgroup_attr_groups;
  285. rc = device_add(&gdev->dev);
  286. if (rc)
  287. goto error;
  288. get_device(&gdev->dev);
  289. rc = __ccwgroup_create_symlinks(gdev);
  290. if (!rc) {
  291. mutex_unlock(&gdev->reg_mutex);
  292. put_device(&gdev->dev);
  293. return 0;
  294. }
  295. device_unregister(&gdev->dev);
  296. error:
  297. for (i = 0; i < num_devices; i++)
  298. if (gdev->cdev[i]) {
  299. spin_lock_irq(gdev->cdev[i]->ccwlock);
  300. if (dev_get_drvdata(&gdev->cdev[i]->dev) == gdev)
  301. dev_set_drvdata(&gdev->cdev[i]->dev, NULL);
  302. spin_unlock_irq(gdev->cdev[i]->ccwlock);
  303. put_device(&gdev->cdev[i]->dev);
  304. gdev->cdev[i] = NULL;
  305. }
  306. mutex_unlock(&gdev->reg_mutex);
  307. put_device(&gdev->dev);
  308. return rc;
  309. }
  310. EXPORT_SYMBOL(ccwgroup_create_from_string);
  311. static int ccwgroup_notifier(struct notifier_block *nb, unsigned long action,
  312. void *data);
  313. static struct notifier_block ccwgroup_nb = {
  314. .notifier_call = ccwgroup_notifier
  315. };
  316. static int __init init_ccwgroup(void)
  317. {
  318. int ret;
  319. ret = bus_register(&ccwgroup_bus_type);
  320. if (ret)
  321. return ret;
  322. ret = bus_register_notifier(&ccwgroup_bus_type, &ccwgroup_nb);
  323. if (ret)
  324. bus_unregister(&ccwgroup_bus_type);
  325. return ret;
  326. }
  327. static void __exit cleanup_ccwgroup(void)
  328. {
  329. bus_unregister_notifier(&ccwgroup_bus_type, &ccwgroup_nb);
  330. bus_unregister(&ccwgroup_bus_type);
  331. }
  332. module_init(init_ccwgroup);
  333. module_exit(cleanup_ccwgroup);
  334. /************************** driver stuff ******************************/
  335. static int
  336. ccwgroup_set_online(struct ccwgroup_device *gdev)
  337. {
  338. struct ccwgroup_driver *gdrv;
  339. int ret;
  340. if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
  341. return -EAGAIN;
  342. if (gdev->state == CCWGROUP_ONLINE) {
  343. ret = 0;
  344. goto out;
  345. }
  346. if (!gdev->dev.driver) {
  347. ret = -EINVAL;
  348. goto out;
  349. }
  350. gdrv = to_ccwgroupdrv (gdev->dev.driver);
  351. if ((ret = gdrv->set_online ? gdrv->set_online(gdev) : 0))
  352. goto out;
  353. gdev->state = CCWGROUP_ONLINE;
  354. out:
  355. atomic_set(&gdev->onoff, 0);
  356. return ret;
  357. }
  358. static int
  359. ccwgroup_set_offline(struct ccwgroup_device *gdev)
  360. {
  361. struct ccwgroup_driver *gdrv;
  362. int ret;
  363. if (atomic_cmpxchg(&gdev->onoff, 0, 1) != 0)
  364. return -EAGAIN;
  365. if (gdev->state == CCWGROUP_OFFLINE) {
  366. ret = 0;
  367. goto out;
  368. }
  369. if (!gdev->dev.driver) {
  370. ret = -EINVAL;
  371. goto out;
  372. }
  373. gdrv = to_ccwgroupdrv (gdev->dev.driver);
  374. if ((ret = gdrv->set_offline ? gdrv->set_offline(gdev) : 0))
  375. goto out;
  376. gdev->state = CCWGROUP_OFFLINE;
  377. out:
  378. atomic_set(&gdev->onoff, 0);
  379. return ret;
  380. }
  381. static ssize_t
  382. ccwgroup_online_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  383. {
  384. struct ccwgroup_device *gdev;
  385. struct ccwgroup_driver *gdrv;
  386. unsigned long value;
  387. int ret;
  388. if (!dev->driver)
  389. return -EINVAL;
  390. gdev = to_ccwgroupdev(dev);
  391. gdrv = to_ccwgroupdrv(dev->driver);
  392. if (!try_module_get(gdrv->driver.owner))
  393. return -EINVAL;
  394. ret = strict_strtoul(buf, 0, &value);
  395. if (ret)
  396. goto out;
  397. if (value == 1)
  398. ret = ccwgroup_set_online(gdev);
  399. else if (value == 0)
  400. ret = ccwgroup_set_offline(gdev);
  401. else
  402. ret = -EINVAL;
  403. out:
  404. module_put(gdrv->driver.owner);
  405. return (ret == 0) ? count : ret;
  406. }
  407. static ssize_t
  408. ccwgroup_online_show (struct device *dev, struct device_attribute *attr, char *buf)
  409. {
  410. int online;
  411. online = (to_ccwgroupdev(dev)->state == CCWGROUP_ONLINE);
  412. return sprintf(buf, online ? "1\n" : "0\n");
  413. }
  414. static int
  415. ccwgroup_probe (struct device *dev)
  416. {
  417. struct ccwgroup_device *gdev;
  418. struct ccwgroup_driver *gdrv;
  419. int ret;
  420. gdev = to_ccwgroupdev(dev);
  421. gdrv = to_ccwgroupdrv(dev->driver);
  422. ret = gdrv->probe ? gdrv->probe(gdev) : -ENODEV;
  423. return ret;
  424. }
  425. static int
  426. ccwgroup_remove (struct device *dev)
  427. {
  428. struct ccwgroup_device *gdev;
  429. struct ccwgroup_driver *gdrv;
  430. if (!dev->driver)
  431. return 0;
  432. gdev = to_ccwgroupdev(dev);
  433. gdrv = to_ccwgroupdrv(dev->driver);
  434. if (gdrv->remove)
  435. gdrv->remove(gdev);
  436. return 0;
  437. }
  438. static void ccwgroup_shutdown(struct device *dev)
  439. {
  440. struct ccwgroup_device *gdev;
  441. struct ccwgroup_driver *gdrv;
  442. if (!dev->driver)
  443. return;
  444. gdev = to_ccwgroupdev(dev);
  445. gdrv = to_ccwgroupdrv(dev->driver);
  446. if (gdrv->shutdown)
  447. gdrv->shutdown(gdev);
  448. }
  449. static int ccwgroup_pm_prepare(struct device *dev)
  450. {
  451. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  452. struct ccwgroup_driver *gdrv = to_ccwgroupdrv(gdev->dev.driver);
  453. /* Fail while device is being set online/offline. */
  454. if (atomic_read(&gdev->onoff))
  455. return -EAGAIN;
  456. if (!gdev->dev.driver || gdev->state != CCWGROUP_ONLINE)
  457. return 0;
  458. return gdrv->prepare ? gdrv->prepare(gdev) : 0;
  459. }
  460. static void ccwgroup_pm_complete(struct device *dev)
  461. {
  462. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  463. struct ccwgroup_driver *gdrv = to_ccwgroupdrv(dev->driver);
  464. if (!gdev->dev.driver || gdev->state != CCWGROUP_ONLINE)
  465. return;
  466. if (gdrv->complete)
  467. gdrv->complete(gdev);
  468. }
  469. static int ccwgroup_pm_freeze(struct device *dev)
  470. {
  471. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  472. struct ccwgroup_driver *gdrv = to_ccwgroupdrv(gdev->dev.driver);
  473. if (!gdev->dev.driver || gdev->state != CCWGROUP_ONLINE)
  474. return 0;
  475. return gdrv->freeze ? gdrv->freeze(gdev) : 0;
  476. }
  477. static int ccwgroup_pm_thaw(struct device *dev)
  478. {
  479. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  480. struct ccwgroup_driver *gdrv = to_ccwgroupdrv(gdev->dev.driver);
  481. if (!gdev->dev.driver || gdev->state != CCWGROUP_ONLINE)
  482. return 0;
  483. return gdrv->thaw ? gdrv->thaw(gdev) : 0;
  484. }
  485. static int ccwgroup_pm_restore(struct device *dev)
  486. {
  487. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  488. struct ccwgroup_driver *gdrv = to_ccwgroupdrv(gdev->dev.driver);
  489. if (!gdev->dev.driver || gdev->state != CCWGROUP_ONLINE)
  490. return 0;
  491. return gdrv->restore ? gdrv->restore(gdev) : 0;
  492. }
  493. static const struct dev_pm_ops ccwgroup_pm_ops = {
  494. .prepare = ccwgroup_pm_prepare,
  495. .complete = ccwgroup_pm_complete,
  496. .freeze = ccwgroup_pm_freeze,
  497. .thaw = ccwgroup_pm_thaw,
  498. .restore = ccwgroup_pm_restore,
  499. };
  500. static struct bus_type ccwgroup_bus_type = {
  501. .name = "ccwgroup",
  502. .match = ccwgroup_bus_match,
  503. .uevent = ccwgroup_uevent,
  504. .probe = ccwgroup_probe,
  505. .remove = ccwgroup_remove,
  506. .shutdown = ccwgroup_shutdown,
  507. .pm = &ccwgroup_pm_ops,
  508. };
  509. static int ccwgroup_notifier(struct notifier_block *nb, unsigned long action,
  510. void *data)
  511. {
  512. struct device *dev = data;
  513. if (action == BUS_NOTIFY_UNBIND_DRIVER)
  514. device_schedule_callback(dev, ccwgroup_ungroup_callback);
  515. return NOTIFY_OK;
  516. }
  517. /**
  518. * ccwgroup_driver_register() - register a ccw group driver
  519. * @cdriver: driver to be registered
  520. *
  521. * This function is mainly a wrapper around driver_register().
  522. */
  523. int ccwgroup_driver_register(struct ccwgroup_driver *cdriver)
  524. {
  525. /* register our new driver with the core */
  526. cdriver->driver.bus = &ccwgroup_bus_type;
  527. return driver_register(&cdriver->driver);
  528. }
  529. static int
  530. __ccwgroup_match_all(struct device *dev, void *data)
  531. {
  532. return 1;
  533. }
  534. /**
  535. * ccwgroup_driver_unregister() - deregister a ccw group driver
  536. * @cdriver: driver to be deregistered
  537. *
  538. * This function is mainly a wrapper around driver_unregister().
  539. */
  540. void ccwgroup_driver_unregister(struct ccwgroup_driver *cdriver)
  541. {
  542. struct device *dev;
  543. /* We don't want ccwgroup devices to live longer than their driver. */
  544. get_driver(&cdriver->driver);
  545. while ((dev = driver_find_device(&cdriver->driver, NULL, NULL,
  546. __ccwgroup_match_all))) {
  547. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  548. mutex_lock(&gdev->reg_mutex);
  549. __ccwgroup_remove_symlinks(gdev);
  550. device_unregister(dev);
  551. __ccwgroup_remove_cdev_refs(gdev);
  552. mutex_unlock(&gdev->reg_mutex);
  553. put_device(dev);
  554. }
  555. put_driver(&cdriver->driver);
  556. driver_unregister(&cdriver->driver);
  557. }
  558. /**
  559. * ccwgroup_probe_ccwdev() - probe function for slave devices
  560. * @cdev: ccw device to be probed
  561. *
  562. * This is a dummy probe function for ccw devices that are slave devices in
  563. * a ccw group device.
  564. * Returns:
  565. * always %0
  566. */
  567. int ccwgroup_probe_ccwdev(struct ccw_device *cdev)
  568. {
  569. return 0;
  570. }
  571. /**
  572. * ccwgroup_remove_ccwdev() - remove function for slave devices
  573. * @cdev: ccw device to be removed
  574. *
  575. * This is a remove function for ccw devices that are slave devices in a ccw
  576. * group device. It sets the ccw device offline and also deregisters the
  577. * embedding ccw group device.
  578. */
  579. void ccwgroup_remove_ccwdev(struct ccw_device *cdev)
  580. {
  581. struct ccwgroup_device *gdev;
  582. /* Ignore offlining errors, device is gone anyway. */
  583. ccw_device_set_offline(cdev);
  584. /* If one of its devices is gone, the whole group is done for. */
  585. spin_lock_irq(cdev->ccwlock);
  586. gdev = dev_get_drvdata(&cdev->dev);
  587. if (!gdev) {
  588. spin_unlock_irq(cdev->ccwlock);
  589. return;
  590. }
  591. /* Get ccwgroup device reference for local processing. */
  592. get_device(&gdev->dev);
  593. spin_unlock_irq(cdev->ccwlock);
  594. /* Unregister group device. */
  595. mutex_lock(&gdev->reg_mutex);
  596. if (device_is_registered(&gdev->dev)) {
  597. __ccwgroup_remove_symlinks(gdev);
  598. device_unregister(&gdev->dev);
  599. __ccwgroup_remove_cdev_refs(gdev);
  600. }
  601. mutex_unlock(&gdev->reg_mutex);
  602. /* Release ccwgroup device reference for local processing. */
  603. put_device(&gdev->dev);
  604. }
  605. MODULE_LICENSE("GPL");
  606. EXPORT_SYMBOL(ccwgroup_driver_register);
  607. EXPORT_SYMBOL(ccwgroup_driver_unregister);
  608. EXPORT_SYMBOL(ccwgroup_probe_ccwdev);
  609. EXPORT_SYMBOL(ccwgroup_remove_ccwdev);