zfcp_sysfs_unit.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * linux/drivers/s390/scsi/zfcp_sysfs_unit.c
  3. *
  4. * FCP adapter driver for IBM eServer zSeries
  5. *
  6. * sysfs unit 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. * Volker Sameske <sameske@de.ibm.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2, or (at your option)
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. */
  30. #define ZFCP_SYSFS_UNIT_C_REVISION "$Revision: 1.30 $"
  31. #include "zfcp_ext.h"
  32. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  33. /**
  34. * zfcp_sysfs_unit_release - gets called when a struct device unit is released
  35. * @dev: pointer to belonging device
  36. */
  37. void
  38. zfcp_sysfs_unit_release(struct device *dev)
  39. {
  40. kfree(dev);
  41. }
  42. /**
  43. * ZFCP_DEFINE_UNIT_ATTR
  44. * @_name: name of show attribute
  45. * @_format: format string
  46. * @_value: value to print
  47. *
  48. * Generates attribute for a unit.
  49. */
  50. #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \
  51. static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \
  52. char *buf) \
  53. { \
  54. struct zfcp_unit *unit; \
  55. \
  56. unit = dev_get_drvdata(dev); \
  57. return sprintf(buf, _format, _value); \
  58. } \
  59. \
  60. static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL);
  61. ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status));
  62. ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
  63. (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
  64. ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
  65. (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
  66. ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
  67. (ZFCP_STATUS_UNIT_SHARED, &unit->status));
  68. ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
  69. (ZFCP_STATUS_UNIT_READONLY, &unit->status));
  70. /**
  71. * zfcp_sysfs_unit_failed_store - failed state of unit
  72. * @dev: pointer to belonging device
  73. * @buf: pointer to input buffer
  74. * @count: number of bytes in buffer
  75. *
  76. * Store function of the "failed" attribute of a unit.
  77. * If a "0" gets written to "failed", error recovery will be
  78. * started for the belonging unit.
  79. */
  80. static ssize_t
  81. zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  82. {
  83. struct zfcp_unit *unit;
  84. unsigned int val;
  85. char *endp;
  86. int retval = 0;
  87. down(&zfcp_data.config_sema);
  88. unit = dev_get_drvdata(dev);
  89. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
  90. retval = -EBUSY;
  91. goto out;
  92. }
  93. val = simple_strtoul(buf, &endp, 0);
  94. if (((endp + 1) < (buf + count)) || (val != 0)) {
  95. retval = -EINVAL;
  96. goto out;
  97. }
  98. zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  99. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  100. zfcp_erp_wait(unit->port->adapter);
  101. out:
  102. up(&zfcp_data.config_sema);
  103. return retval ? retval : (ssize_t) count;
  104. }
  105. /**
  106. * zfcp_sysfs_unit_failed_show - failed state of unit
  107. * @dev: pointer to belonging device
  108. * @buf: pointer to input buffer
  109. *
  110. * Show function of "failed" attribute of unit. Will be
  111. * "0" if unit is working, otherwise "1".
  112. */
  113. static ssize_t
  114. zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
  115. {
  116. struct zfcp_unit *unit;
  117. unit = dev_get_drvdata(dev);
  118. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
  119. return sprintf(buf, "1\n");
  120. else
  121. return sprintf(buf, "0\n");
  122. }
  123. static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
  124. zfcp_sysfs_unit_failed_store);
  125. static struct attribute *zfcp_unit_attrs[] = {
  126. &dev_attr_failed.attr,
  127. &dev_attr_in_recovery.attr,
  128. &dev_attr_status.attr,
  129. &dev_attr_access_denied.attr,
  130. &dev_attr_access_shared.attr,
  131. &dev_attr_access_readonly.attr,
  132. NULL
  133. };
  134. static struct attribute_group zfcp_unit_attr_group = {
  135. .attrs = zfcp_unit_attrs,
  136. };
  137. /**
  138. * zfcp_sysfs_create_unit_files - create sysfs unit files
  139. * @dev: pointer to belonging device
  140. *
  141. * Create all attributes of the sysfs representation of a unit.
  142. */
  143. int
  144. zfcp_sysfs_unit_create_files(struct device *dev)
  145. {
  146. return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
  147. }
  148. /**
  149. * zfcp_sysfs_remove_unit_files - remove sysfs unit files
  150. * @dev: pointer to belonging device
  151. *
  152. * Remove all attributes of the sysfs representation of a unit.
  153. */
  154. void
  155. zfcp_sysfs_unit_remove_files(struct device *dev)
  156. {
  157. sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
  158. }
  159. #undef ZFCP_LOG_AREA