cu3088.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * $Id: cu3088.c,v 1.35 2005/03/30 19:28:52 richtera Exp $
  3. *
  4. * CTC / LCS ccw_device driver
  5. *
  6. * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
  7. * Author(s): Arnd Bergmann <arndb@de.ibm.com>
  8. * Cornelia Huck <cohuck@de.ibm.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include <linux/init.h>
  26. #include <linux/module.h>
  27. #include <linux/err.h>
  28. #include <asm/ccwdev.h>
  29. #include <asm/ccwgroup.h>
  30. #include "cu3088.h"
  31. const char *cu3088_type[] = {
  32. "not a channel",
  33. "CTC/A",
  34. "ESCON channel",
  35. "FICON channel",
  36. "P390 LCS card",
  37. "OSA LCS card",
  38. "CLAW channel device",
  39. "unknown channel type",
  40. "unsupported channel type",
  41. };
  42. /* static definitions */
  43. static struct ccw_device_id cu3088_ids[] = {
  44. { CCW_DEVICE(0x3088, 0x08), .driver_info = channel_type_parallel },
  45. { CCW_DEVICE(0x3088, 0x1f), .driver_info = channel_type_escon },
  46. { CCW_DEVICE(0x3088, 0x1e), .driver_info = channel_type_ficon },
  47. { CCW_DEVICE(0x3088, 0x01), .driver_info = channel_type_p390 },
  48. { CCW_DEVICE(0x3088, 0x60), .driver_info = channel_type_osa2 },
  49. { CCW_DEVICE(0x3088, 0x61), .driver_info = channel_type_claw },
  50. { /* end of list */ }
  51. };
  52. static struct ccw_driver cu3088_driver;
  53. struct device *cu3088_root_dev;
  54. static ssize_t
  55. group_write(struct device_driver *drv, const char *buf, size_t count)
  56. {
  57. const char *start, *end;
  58. char bus_ids[2][BUS_ID_SIZE], *argv[2];
  59. int i;
  60. int ret;
  61. struct ccwgroup_driver *cdrv;
  62. cdrv = to_ccwgroupdrv(drv);
  63. if (!cdrv)
  64. return -EINVAL;
  65. start = buf;
  66. for (i=0; i<2; i++) {
  67. static const char delim[] = {',', '\n'};
  68. int len;
  69. if (!(end = strchr(start, delim[i])))
  70. return count;
  71. len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start + 1);
  72. strlcpy (bus_ids[i], start, len);
  73. argv[i] = bus_ids[i];
  74. start = end + 1;
  75. }
  76. ret = ccwgroup_create(cu3088_root_dev, cdrv->driver_id,
  77. &cu3088_driver, 2, argv);
  78. return (ret == 0) ? count : ret;
  79. }
  80. static DRIVER_ATTR(group, 0200, NULL, group_write);
  81. /* Register-unregister for ctc&lcs */
  82. int
  83. register_cu3088_discipline(struct ccwgroup_driver *dcp)
  84. {
  85. int rc;
  86. if (!dcp)
  87. return -EINVAL;
  88. /* Register discipline.*/
  89. rc = ccwgroup_driver_register(dcp);
  90. if (rc)
  91. return rc;
  92. rc = driver_create_file(&dcp->driver, &driver_attr_group);
  93. if (rc)
  94. ccwgroup_driver_unregister(dcp);
  95. return rc;
  96. }
  97. void
  98. unregister_cu3088_discipline(struct ccwgroup_driver *dcp)
  99. {
  100. if (!dcp)
  101. return;
  102. driver_remove_file(&dcp->driver, &driver_attr_group);
  103. ccwgroup_driver_unregister(dcp);
  104. }
  105. static struct ccw_driver cu3088_driver = {
  106. .owner = THIS_MODULE,
  107. .ids = cu3088_ids,
  108. .name = "cu3088",
  109. .probe = ccwgroup_probe_ccwdev,
  110. .remove = ccwgroup_remove_ccwdev,
  111. };
  112. /* module setup */
  113. static int __init
  114. cu3088_init (void)
  115. {
  116. int rc;
  117. cu3088_root_dev = s390_root_dev_register("cu3088");
  118. if (IS_ERR(cu3088_root_dev))
  119. return PTR_ERR(cu3088_root_dev);
  120. rc = ccw_driver_register(&cu3088_driver);
  121. if (rc)
  122. s390_root_dev_unregister(cu3088_root_dev);
  123. return rc;
  124. }
  125. static void __exit
  126. cu3088_exit (void)
  127. {
  128. ccw_driver_unregister(&cu3088_driver);
  129. s390_root_dev_unregister(cu3088_root_dev);
  130. }
  131. MODULE_DEVICE_TABLE(ccw,cu3088_ids);
  132. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
  133. MODULE_LICENSE("GPL");
  134. module_init(cu3088_init);
  135. module_exit(cu3088_exit);
  136. EXPORT_SYMBOL_GPL(cu3088_type);
  137. EXPORT_SYMBOL_GPL(register_cu3088_discipline);
  138. EXPORT_SYMBOL_GPL(unregister_cu3088_discipline);