cu3088.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * $Id: cu3088.c,v 1.38 2006/01/12 14:33:09 cohuck 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 <cornelia.huck@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/s390_rdev.h>
  29. #include <asm/ccwdev.h>
  30. #include <asm/ccwgroup.h>
  31. #include "cu3088.h"
  32. const char *cu3088_type[] = {
  33. "not a channel",
  34. "CTC/A",
  35. "ESCON channel",
  36. "FICON channel",
  37. "P390 LCS card",
  38. "OSA LCS card",
  39. "CLAW channel device",
  40. "unknown channel type",
  41. "unsupported channel type",
  42. };
  43. /* static definitions */
  44. static struct ccw_device_id cu3088_ids[] = {
  45. { CCW_DEVICE(0x3088, 0x08), .driver_info = channel_type_parallel },
  46. { CCW_DEVICE(0x3088, 0x1f), .driver_info = channel_type_escon },
  47. { CCW_DEVICE(0x3088, 0x1e), .driver_info = channel_type_ficon },
  48. { CCW_DEVICE(0x3088, 0x01), .driver_info = channel_type_p390 },
  49. { CCW_DEVICE(0x3088, 0x60), .driver_info = channel_type_osa2 },
  50. { CCW_DEVICE(0x3088, 0x61), .driver_info = channel_type_claw },
  51. { /* end of list */ }
  52. };
  53. static struct ccw_driver cu3088_driver;
  54. struct device *cu3088_root_dev;
  55. static ssize_t
  56. group_write(struct device_driver *drv, const char *buf, size_t count)
  57. {
  58. const char *start, *end;
  59. char bus_ids[2][BUS_ID_SIZE], *argv[2];
  60. int i;
  61. int ret;
  62. struct ccwgroup_driver *cdrv;
  63. cdrv = to_ccwgroupdrv(drv);
  64. if (!cdrv)
  65. return -EINVAL;
  66. start = buf;
  67. for (i=0; i<2; i++) {
  68. static const char delim[] = {',', '\n'};
  69. int len;
  70. if (!(end = strchr(start, delim[i])))
  71. return count;
  72. len = min_t(ptrdiff_t, BUS_ID_SIZE, end - start + 1);
  73. strlcpy (bus_ids[i], start, len);
  74. argv[i] = bus_ids[i];
  75. start = end + 1;
  76. }
  77. ret = ccwgroup_create(cu3088_root_dev, cdrv->driver_id,
  78. &cu3088_driver, 2, argv);
  79. return (ret == 0) ? count : ret;
  80. }
  81. static DRIVER_ATTR(group, 0200, NULL, group_write);
  82. /* Register-unregister for ctc&lcs */
  83. int
  84. register_cu3088_discipline(struct ccwgroup_driver *dcp)
  85. {
  86. int rc;
  87. if (!dcp)
  88. return -EINVAL;
  89. /* Register discipline.*/
  90. rc = ccwgroup_driver_register(dcp);
  91. if (rc)
  92. return rc;
  93. rc = driver_create_file(&dcp->driver, &driver_attr_group);
  94. if (rc)
  95. ccwgroup_driver_unregister(dcp);
  96. return rc;
  97. }
  98. void
  99. unregister_cu3088_discipline(struct ccwgroup_driver *dcp)
  100. {
  101. if (!dcp)
  102. return;
  103. driver_remove_file(&dcp->driver, &driver_attr_group);
  104. ccwgroup_driver_unregister(dcp);
  105. }
  106. static struct ccw_driver cu3088_driver = {
  107. .owner = THIS_MODULE,
  108. .ids = cu3088_ids,
  109. .name = "cu3088",
  110. .probe = ccwgroup_probe_ccwdev,
  111. .remove = ccwgroup_remove_ccwdev,
  112. };
  113. /* module setup */
  114. static int __init
  115. cu3088_init (void)
  116. {
  117. int rc;
  118. cu3088_root_dev = s390_root_dev_register("cu3088");
  119. if (IS_ERR(cu3088_root_dev))
  120. return PTR_ERR(cu3088_root_dev);
  121. rc = ccw_driver_register(&cu3088_driver);
  122. if (rc)
  123. s390_root_dev_unregister(cu3088_root_dev);
  124. return rc;
  125. }
  126. static void __exit
  127. cu3088_exit (void)
  128. {
  129. ccw_driver_unregister(&cu3088_driver);
  130. s390_root_dev_unregister(cu3088_root_dev);
  131. }
  132. MODULE_DEVICE_TABLE(ccw,cu3088_ids);
  133. MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
  134. MODULE_LICENSE("GPL");
  135. module_init(cu3088_init);
  136. module_exit(cu3088_exit);
  137. EXPORT_SYMBOL_GPL(cu3088_type);
  138. EXPORT_SYMBOL_GPL(register_cu3088_discipline);
  139. EXPORT_SYMBOL_GPL(unregister_cu3088_discipline);