zfcp_sysfs_unit.c 5.4 KB

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