zfcp_sysfs_adapter.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * linux/drivers/s390/scsi/zfcp_sysfs_adapter.c
  3. *
  4. * FCP adapter driver for IBM eServer zSeries
  5. *
  6. * sysfs adapter 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. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 2, or (at your option)
  18. * any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. #include "zfcp_ext.h"
  30. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  31. /**
  32. * ZFCP_DEFINE_ADAPTER_ATTR
  33. * @_name: name of show attribute
  34. * @_format: format string
  35. * @_value: value to print
  36. *
  37. * Generates attributes for an adapter.
  38. */
  39. #define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
  40. static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, struct device_attribute *attr, \
  41. char *buf) \
  42. { \
  43. struct zfcp_adapter *adapter; \
  44. \
  45. adapter = dev_get_drvdata(dev); \
  46. return sprintf(buf, _format, _value); \
  47. } \
  48. \
  49. static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
  50. ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
  51. ZFCP_DEFINE_ADAPTER_ATTR(peer_wwnn, "0x%016llx\n", adapter->peer_wwnn);
  52. ZFCP_DEFINE_ADAPTER_ATTR(peer_wwpn, "0x%016llx\n", adapter->peer_wwpn);
  53. ZFCP_DEFINE_ADAPTER_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
  54. ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
  55. ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
  56. ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
  57. adapter->hardware_version);
  58. ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
  59. (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
  60. /**
  61. * zfcp_sysfs_port_add_store - add a port to sysfs tree
  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 "port_add" attribute of an adapter.
  67. */
  68. static ssize_t
  69. zfcp_sysfs_port_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  70. {
  71. wwn_t wwpn;
  72. char *endp;
  73. struct zfcp_adapter *adapter;
  74. struct zfcp_port *port;
  75. int retval = -EINVAL;
  76. down(&zfcp_data.config_sema);
  77. adapter = dev_get_drvdata(dev);
  78. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
  79. retval = -EBUSY;
  80. goto out;
  81. }
  82. wwpn = simple_strtoull(buf, &endp, 0);
  83. if ((endp + 1) < (buf + count))
  84. goto out;
  85. port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
  86. if (!port)
  87. goto out;
  88. retval = 0;
  89. zfcp_erp_port_reopen(port, 0);
  90. zfcp_erp_wait(port->adapter);
  91. zfcp_port_put(port);
  92. out:
  93. up(&zfcp_data.config_sema);
  94. return retval ? retval : (ssize_t) count;
  95. }
  96. static DEVICE_ATTR(port_add, S_IWUSR, NULL, zfcp_sysfs_port_add_store);
  97. /**
  98. * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
  99. * @dev: pointer to belonging device
  100. * @buf: pointer to input buffer
  101. * @count: number of bytes in buffer
  102. *
  103. * Store function of the "port_remove" attribute of an adapter.
  104. */
  105. static ssize_t
  106. zfcp_sysfs_port_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  107. {
  108. struct zfcp_adapter *adapter;
  109. struct zfcp_port *port;
  110. wwn_t wwpn;
  111. char *endp;
  112. int retval = 0;
  113. down(&zfcp_data.config_sema);
  114. adapter = dev_get_drvdata(dev);
  115. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
  116. retval = -EBUSY;
  117. goto out;
  118. }
  119. wwpn = simple_strtoull(buf, &endp, 0);
  120. if ((endp + 1) < (buf + count)) {
  121. retval = -EINVAL;
  122. goto out;
  123. }
  124. write_lock_irq(&zfcp_data.config_lock);
  125. port = zfcp_get_port_by_wwpn(adapter, wwpn);
  126. if (port && (atomic_read(&port->refcount) == 0)) {
  127. zfcp_port_get(port);
  128. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  129. list_move(&port->list, &adapter->port_remove_lh);
  130. }
  131. else {
  132. port = NULL;
  133. }
  134. write_unlock_irq(&zfcp_data.config_lock);
  135. if (!port) {
  136. retval = -ENXIO;
  137. goto out;
  138. }
  139. zfcp_erp_port_shutdown(port, 0);
  140. zfcp_erp_wait(adapter);
  141. zfcp_port_put(port);
  142. zfcp_port_dequeue(port);
  143. out:
  144. up(&zfcp_data.config_sema);
  145. return retval ? retval : (ssize_t) count;
  146. }
  147. static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
  148. /**
  149. * zfcp_sysfs_adapter_failed_store - failed state of adapter
  150. * @dev: pointer to belonging device
  151. * @buf: pointer to input buffer
  152. * @count: number of bytes in buffer
  153. *
  154. * Store function of the "failed" attribute of an adapter.
  155. * If a "0" gets written to "failed", error recovery will be
  156. * started for the belonging adapter.
  157. */
  158. static ssize_t
  159. zfcp_sysfs_adapter_failed_store(struct device *dev, struct device_attribute *attr,
  160. const char *buf, size_t count)
  161. {
  162. struct zfcp_adapter *adapter;
  163. unsigned int val;
  164. char *endp;
  165. int retval = 0;
  166. down(&zfcp_data.config_sema);
  167. adapter = dev_get_drvdata(dev);
  168. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
  169. retval = -EBUSY;
  170. goto out;
  171. }
  172. val = simple_strtoul(buf, &endp, 0);
  173. if (((endp + 1) < (buf + count)) || (val != 0)) {
  174. retval = -EINVAL;
  175. goto out;
  176. }
  177. zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
  178. ZFCP_SET);
  179. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  180. zfcp_erp_wait(adapter);
  181. out:
  182. up(&zfcp_data.config_sema);
  183. return retval ? retval : (ssize_t) count;
  184. }
  185. /**
  186. * zfcp_sysfs_adapter_failed_show - failed state of adapter
  187. * @dev: pointer to belonging device
  188. * @buf: pointer to input buffer
  189. *
  190. * Show function of "failed" attribute of adapter. Will be
  191. * "0" if adapter is working, otherwise "1".
  192. */
  193. static ssize_t
  194. zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
  195. {
  196. struct zfcp_adapter *adapter;
  197. adapter = dev_get_drvdata(dev);
  198. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
  199. return sprintf(buf, "1\n");
  200. else
  201. return sprintf(buf, "0\n");
  202. }
  203. static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
  204. zfcp_sysfs_adapter_failed_store);
  205. static struct attribute *zfcp_adapter_attrs[] = {
  206. &dev_attr_failed.attr,
  207. &dev_attr_in_recovery.attr,
  208. &dev_attr_port_remove.attr,
  209. &dev_attr_port_add.attr,
  210. &dev_attr_peer_wwnn.attr,
  211. &dev_attr_peer_wwpn.attr,
  212. &dev_attr_peer_d_id.attr,
  213. &dev_attr_card_version.attr,
  214. &dev_attr_lic_version.attr,
  215. &dev_attr_status.attr,
  216. &dev_attr_hardware_version.attr,
  217. NULL
  218. };
  219. static struct attribute_group zfcp_adapter_attr_group = {
  220. .attrs = zfcp_adapter_attrs,
  221. };
  222. /**
  223. * zfcp_sysfs_create_adapter_files - create sysfs adapter files
  224. * @dev: pointer to belonging device
  225. *
  226. * Create all attributes of the sysfs representation of an adapter.
  227. */
  228. int
  229. zfcp_sysfs_adapter_create_files(struct device *dev)
  230. {
  231. return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
  232. }
  233. /**
  234. * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
  235. * @dev: pointer to belonging device
  236. *
  237. * Remove all attributes of the sysfs representation of an adapter.
  238. */
  239. void
  240. zfcp_sysfs_adapter_remove_files(struct device *dev)
  241. {
  242. sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);
  243. }
  244. #undef ZFCP_LOG_AREA