zfcp_sysfs_unit.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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(scsi_lun, "0x%x\n", unit->scsi_lun);
  63. ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask
  64. (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status));
  65. ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask
  66. (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status));
  67. ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask
  68. (ZFCP_STATUS_UNIT_SHARED, &unit->status));
  69. ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask
  70. (ZFCP_STATUS_UNIT_READONLY, &unit->status));
  71. /**
  72. * zfcp_sysfs_unit_failed_store - failed state of unit
  73. * @dev: pointer to belonging device
  74. * @buf: pointer to input buffer
  75. * @count: number of bytes in buffer
  76. *
  77. * Store function of the "failed" attribute of a unit.
  78. * If a "0" gets written to "failed", error recovery will be
  79. * started for the belonging unit.
  80. */
  81. static ssize_t
  82. zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  83. {
  84. struct zfcp_unit *unit;
  85. unsigned int val;
  86. char *endp;
  87. int retval = 0;
  88. down(&zfcp_data.config_sema);
  89. unit = dev_get_drvdata(dev);
  90. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) {
  91. retval = -EBUSY;
  92. goto out;
  93. }
  94. val = simple_strtoul(buf, &endp, 0);
  95. if (((endp + 1) < (buf + count)) || (val != 0)) {
  96. retval = -EINVAL;
  97. goto out;
  98. }
  99. zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  100. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  101. zfcp_erp_wait(unit->port->adapter);
  102. out:
  103. up(&zfcp_data.config_sema);
  104. return retval ? retval : (ssize_t) count;
  105. }
  106. /**
  107. * zfcp_sysfs_unit_failed_show - failed state of unit
  108. * @dev: pointer to belonging device
  109. * @buf: pointer to input buffer
  110. *
  111. * Show function of "failed" attribute of unit. Will be
  112. * "0" if unit is working, otherwise "1".
  113. */
  114. static ssize_t
  115. zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
  116. {
  117. struct zfcp_unit *unit;
  118. unit = dev_get_drvdata(dev);
  119. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status))
  120. return sprintf(buf, "1\n");
  121. else
  122. return sprintf(buf, "0\n");
  123. }
  124. static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show,
  125. zfcp_sysfs_unit_failed_store);
  126. static struct attribute *zfcp_unit_attrs[] = {
  127. &dev_attr_scsi_lun.attr,
  128. &dev_attr_failed.attr,
  129. &dev_attr_in_recovery.attr,
  130. &dev_attr_status.attr,
  131. &dev_attr_access_denied.attr,
  132. &dev_attr_access_shared.attr,
  133. &dev_attr_access_readonly.attr,
  134. NULL
  135. };
  136. static struct attribute_group zfcp_unit_attr_group = {
  137. .attrs = zfcp_unit_attrs,
  138. };
  139. /**
  140. * zfcp_sysfs_create_unit_files - create sysfs unit files
  141. * @dev: pointer to belonging device
  142. *
  143. * Create all attributes of the sysfs representation of a unit.
  144. */
  145. int
  146. zfcp_sysfs_unit_create_files(struct device *dev)
  147. {
  148. return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group);
  149. }
  150. /**
  151. * zfcp_sysfs_remove_unit_files - remove sysfs unit files
  152. * @dev: pointer to belonging device
  153. *
  154. * Remove all attributes of the sysfs representation of a unit.
  155. */
  156. void
  157. zfcp_sysfs_unit_remove_files(struct device *dev)
  158. {
  159. sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group);
  160. }
  161. #undef ZFCP_LOG_AREA