zfcp_sysfs_driver.c 4.9 KB

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