zfcp_sysfs_unit.c 4.4 KB

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