zfcp_sysfs_unit.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_sysfs_unit_release - gets called when a struct device unit is released
  25. * @dev: pointer to belonging device
  26. */
  27. void
  28. zfcp_sysfs_unit_release(struct device *dev)
  29. {
  30. kfree(dev);
  31. }
  32. /**
  33. * ZFCP_DEFINE_UNIT_ATTR
  34. * @_name: name of show attribute
  35. * @_format: format string
  36. * @_value: value to print
  37. *
  38. * Generates attribute for a unit.
  39. */
  40. #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
  41. static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \
  42. char *buf) \
  43. { \
  44. struct zfcp_unit *unit; \
  45. \
  46. unit = dev_get_drvdata(dev); \
  47. return sprintf(buf, _format, _value); \
  48. } \
  49. \
  50. static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
  51. ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
  52. ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
  53. (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
  54. ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
  55. (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
  56. ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
  57. (ZFCP_STATUS_UNIT_SHARED, &unit->status));
  58. ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
  59. (ZFCP_STATUS_UNIT_READONLY, &unit->status));
  60. /**
  61. * zfcp_sysfs_unit_failed_store - failed state of unit
  62. * @dev: pointer to belonging device
  63. * @buf: pointer to input buffer
  64. * @count: number of bytes in buffer
  65. *
  66. * Store function of the "failed" attribute of a unit.
  67. * If a "0" gets written to "failed", error recovery will be
  68. * started for the belonging unit.
  69. */
  70. static ssize_t
  71. zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  72. {
  73. struct zfcp_unit *unit;
  74. unsigned int val;
  75. char *endp;
  76. int retval = 0;
  77. down(&zfcp_data.config_sema);
  78. unit = dev_get_drvdata(dev);
  79. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
  80. retval = -EBUSY;
  81. goto out;
  82. }
  83. val = simple_strtoul(buf, &endp, 0);
  84. if (((endp + 1) < (buf + count)) || (val != 0)) {
  85. retval = -EINVAL;
  86. goto out;
  87. }
  88. zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  89. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  90. zfcp_erp_wait(unit->port->adapter);
  91. out:
  92. up(&zfcp_data.config_sema);
  93. return retval ? retval : (ssize_t) count;
  94. }
  95. /**
  96. * zfcp_sysfs_unit_failed_show - failed state of unit
  97. * @dev: pointer to belonging device
  98. * @buf: pointer to input buffer
  99. *
  100. * Show function of "failed" attribute of unit. Will be
  101. * "0" if unit is working, otherwise "1".
  102. */
  103. static ssize_t
  104. zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
  105. {
  106. struct zfcp_unit *unit;
  107. unit = dev_get_drvdata(dev);
  108. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
  109. return sprintf(buf, "1\n");
  110. else
  111. return sprintf(buf, "0\n");
  112. }
  113. static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
  114. zfcp_sysfs_unit_failed_store);
  115. static struct attribute *zfcp_unit_attrs[] = {
  116. &dev_attr_failed.attr,
  117. &dev_attr_in_recovery.attr,
  118. &dev_attr_status.attr,
  119. &dev_attr_access_denied.attr,
  120. &dev_attr_access_shared.attr,
  121. &dev_attr_access_readonly.attr,
  122. NULL
  123. };
  124. static struct attribute_group zfcp_unit_attr_group = {
  125. .attrs = zfcp_unit_attrs,
  126. };
  127. /**
  128. * zfcp_sysfs_create_unit_files - create sysfs unit files
  129. * @dev: pointer to belonging device
  130. *
  131. * Create all attributes of the sysfs representation of a unit.
  132. */
  133. int
  134. zfcp_sysfs_unit_create_files(struct device *dev)
  135. {
  136. return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
  137. }
  138. /**
  139. * zfcp_sysfs_remove_unit_files - remove sysfs unit files
  140. * @dev: pointer to belonging device
  141. *
  142. * Remove all attributes of the sysfs representation of a unit.
  143. */
  144. void
  145. zfcp_sysfs_unit_remove_files(struct device *dev)
  146. {
  147. sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
  148. }
  149. #undef ZFCP_LOG_AREA