zfcp_sysfs_driver.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * linux/drivers/s390/scsi/zfcp_sysfs_driver.c
  3. *
  4. * FCP adapter driver for IBM eServer zSeries
  5. *
  6. * sysfs driver related routines
  7. *
  8. * (C) Copyright IBM Corp. 2003, 2004
  9. *
  10. * Authors:
  11. * Martin Peschke <mpeschke@de.ibm.com>
  12. * Heiko Carstens <heiko.carstens@de.ibm.com>
  13. * Andreas Herrmann <aherrman@de.ibm.com>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2, or (at your option)
  18. * any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. #define ZFCP_SYSFS_DRIVER_C_REVISION "$Revision: 1.17 $"
  30. #include "zfcp_ext.h"
  31. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  32. /**
  33. * ZFCP_DEFINE_DRIVER_ATTR - define for all loglevels sysfs attributes
  34. * @_name: name of attribute
  35. * @_define: name of ZFCP loglevel define
  36. *
  37. * Generates store function for a sysfs loglevel attribute of zfcp driver.
  38. */
  39. #define ZFCP_DEFINE_DRIVER_ATTR(_name, _define) \
  40. static ssize_t zfcp_sysfs_loglevel_##_name##_store(struct device_driver *drv, \
  41. const char *buf, \
  42. size_t count) \
  43. { \
  44. unsigned int loglevel; \
  45. unsigned int new_loglevel; \
  46. char *endp; \
  47. \
  48. new_loglevel = simple_strtoul(buf, &endp, 0); \
  49. if ((endp + 1) < (buf + count)) \
  50. return -EINVAL; \
  51. if (new_loglevel > 3) \
  52. return -EINVAL; \
  53. down(&zfcp_data.config_sema); \
  54. loglevel = atomic_read(&zfcp_data.loglevel); \
  55. loglevel &= ~((unsigned int) 0xf << (ZFCP_LOG_AREA_##_define << 2)); \
  56. loglevel |= new_loglevel << (ZFCP_LOG_AREA_##_define << 2); \
  57. atomic_set(&zfcp_data.loglevel, loglevel); \
  58. up(&zfcp_data.config_sema); \
  59. return count; \
  60. } \
  61. \
  62. static ssize_t zfcp_sysfs_loglevel_##_name##_show(struct device_driver *dev, \
  63. char *buf) \
  64. { \
  65. return sprintf(buf,"%d\n", (unsigned int) \
  66. ZFCP_GET_LOG_VALUE(ZFCP_LOG_AREA_##_define)); \
  67. } \
  68. \
  69. static DRIVER_ATTR(loglevel_##_name, S_IWUSR | S_IRUGO, \
  70. zfcp_sysfs_loglevel_##_name##_show, \
  71. zfcp_sysfs_loglevel_##_name##_store);
  72. ZFCP_DEFINE_DRIVER_ATTR(other, OTHER);
  73. ZFCP_DEFINE_DRIVER_ATTR(scsi, SCSI);
  74. ZFCP_DEFINE_DRIVER_ATTR(fsf, FSF);
  75. ZFCP_DEFINE_DRIVER_ATTR(config, CONFIG);
  76. ZFCP_DEFINE_DRIVER_ATTR(cio, CIO);
  77. ZFCP_DEFINE_DRIVER_ATTR(qdio, QDIO);
  78. ZFCP_DEFINE_DRIVER_ATTR(erp, ERP);
  79. ZFCP_DEFINE_DRIVER_ATTR(fc, FC);
  80. static ssize_t zfcp_sysfs_version_show(struct device_driver *dev,
  81. char *buf)
  82. {
  83. return sprintf(buf, "%s\n", zfcp_data.driver_version);
  84. }
  85. static DRIVER_ATTR(version, S_IRUGO, zfcp_sysfs_version_show, NULL);
  86. static struct attribute *zfcp_driver_attrs[] = {
  87. &driver_attr_loglevel_other.attr,
  88. &driver_attr_loglevel_scsi.attr,
  89. &driver_attr_loglevel_fsf.attr,
  90. &driver_attr_loglevel_config.attr,
  91. &driver_attr_loglevel_cio.attr,
  92. &driver_attr_loglevel_qdio.attr,
  93. &driver_attr_loglevel_erp.attr,
  94. &driver_attr_loglevel_fc.attr,
  95. &driver_attr_version.attr,
  96. NULL
  97. };
  98. static struct attribute_group zfcp_driver_attr_group = {
  99. .attrs = zfcp_driver_attrs,
  100. };
  101. /**
  102. * zfcp_sysfs_create_driver_files - create sysfs driver files
  103. * @dev: pointer to belonging device
  104. *
  105. * Create all sysfs attributes of the zfcp device driver
  106. */
  107. int
  108. zfcp_sysfs_driver_create_files(struct device_driver *drv)
  109. {
  110. return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
  111. }
  112. /**
  113. * zfcp_sysfs_remove_driver_files - remove sysfs driver files
  114. * @dev: pointer to belonging device
  115. *
  116. * Remove all sysfs attributes of the zfcp device driver
  117. */
  118. void
  119. zfcp_sysfs_driver_remove_files(struct device_driver *drv)
  120. {
  121. sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
  122. }
  123. #undef ZFCP_LOG_AREA