cu3088.c 4.0 KB

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