zfcp_sysfs_adapter.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. #define ZFCP_SYSFS_ADAPTER_C_REVISION "$Revision: 1.38 $"
  30. #include "zfcp_ext.h"
  31. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  32. /**
  33. * ZFCP_DEFINE_ADAPTER_ATTR
  34. * @_name: name of show attribute
  35. * @_format: format string
  36. * @_value: value to print
  37. *
  38. * Generates attributes for an adapter.
  39. */
  40. #define ZFCP_DEFINE_ADAPTER_ATTR(_name, _format, _value) \
  41. static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, struct device_attribute *attr, \
  42. char *buf) \
  43. { \
  44. struct zfcp_adapter *adapter; \
  45. \
  46. adapter = dev_get_drvdata(dev); \
  47. return sprintf(buf, _format, _value); \
  48. } \
  49. \
  50. static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
  51. ZFCP_DEFINE_ADAPTER_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
  52. ZFCP_DEFINE_ADAPTER_ATTR(peer_wwnn, "0x%016llx\n", adapter->peer_wwnn);
  53. ZFCP_DEFINE_ADAPTER_ATTR(peer_wwpn, "0x%016llx\n", adapter->peer_wwpn);
  54. ZFCP_DEFINE_ADAPTER_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
  55. ZFCP_DEFINE_ADAPTER_ATTR(physical_wwpn, "0x%016llx\n", adapter->physical_wwpn);
  56. ZFCP_DEFINE_ADAPTER_ATTR(physical_s_id, "0x%06x\n", adapter->physical_s_id);
  57. ZFCP_DEFINE_ADAPTER_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
  58. ZFCP_DEFINE_ADAPTER_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
  59. ZFCP_DEFINE_ADAPTER_ATTR(hardware_version, "0x%08x\n",
  60. adapter->hardware_version);
  61. ZFCP_DEFINE_ADAPTER_ATTR(in_recovery, "%d\n", atomic_test_mask
  62. (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status));
  63. /**
  64. * zfcp_sysfs_port_add_store - add a port to sysfs tree
  65. * @dev: pointer to belonging device
  66. * @buf: pointer to input buffer
  67. * @count: number of bytes in buffer
  68. *
  69. * Store function of the "port_add" attribute of an adapter.
  70. */
  71. static ssize_t
  72. zfcp_sysfs_port_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  73. {
  74. wwn_t wwpn;
  75. char *endp;
  76. struct zfcp_adapter *adapter;
  77. struct zfcp_port *port;
  78. int retval = -EINVAL;
  79. down(&zfcp_data.config_sema);
  80. adapter = dev_get_drvdata(dev);
  81. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
  82. retval = -EBUSY;
  83. goto out;
  84. }
  85. wwpn = simple_strtoull(buf, &endp, 0);
  86. if ((endp + 1) < (buf + count))
  87. goto out;
  88. port = zfcp_port_enqueue(adapter, wwpn, 0, 0);
  89. if (!port)
  90. goto out;
  91. retval = 0;
  92. zfcp_erp_port_reopen(port, 0);
  93. zfcp_erp_wait(port->adapter);
  94. zfcp_port_put(port);
  95. out:
  96. up(&zfcp_data.config_sema);
  97. return retval ? retval : (ssize_t) count;
  98. }
  99. static DEVICE_ATTR(port_add, S_IWUSR, NULL, zfcp_sysfs_port_add_store);
  100. /**
  101. * zfcp_sysfs_port_remove_store - remove a port from sysfs tree
  102. * @dev: pointer to belonging device
  103. * @buf: pointer to input buffer
  104. * @count: number of bytes in buffer
  105. *
  106. * Store function of the "port_remove" attribute of an adapter.
  107. */
  108. static ssize_t
  109. zfcp_sysfs_port_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  110. {
  111. struct zfcp_adapter *adapter;
  112. struct zfcp_port *port;
  113. wwn_t wwpn;
  114. char *endp;
  115. int retval = 0;
  116. down(&zfcp_data.config_sema);
  117. adapter = dev_get_drvdata(dev);
  118. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
  119. retval = -EBUSY;
  120. goto out;
  121. }
  122. wwpn = simple_strtoull(buf, &endp, 0);
  123. if ((endp + 1) < (buf + count)) {
  124. retval = -EINVAL;
  125. goto out;
  126. }
  127. write_lock_irq(&zfcp_data.config_lock);
  128. port = zfcp_get_port_by_wwpn(adapter, wwpn);
  129. if (port && (atomic_read(&port->refcount) == 0)) {
  130. zfcp_port_get(port);
  131. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  132. list_move(&port->list, &adapter->port_remove_lh);
  133. }
  134. else {
  135. port = NULL;
  136. }
  137. write_unlock_irq(&zfcp_data.config_lock);
  138. if (!port) {
  139. retval = -ENXIO;
  140. goto out;
  141. }
  142. zfcp_erp_port_shutdown(port, 0);
  143. zfcp_erp_wait(adapter);
  144. zfcp_port_put(port);
  145. zfcp_port_dequeue(port);
  146. out:
  147. up(&zfcp_data.config_sema);
  148. return retval ? retval : (ssize_t) count;
  149. }
  150. static DEVICE_ATTR(port_remove, S_IWUSR, NULL, zfcp_sysfs_port_remove_store);
  151. /**
  152. * zfcp_sysfs_adapter_failed_store - failed state of adapter
  153. * @dev: pointer to belonging device
  154. * @buf: pointer to input buffer
  155. * @count: number of bytes in buffer
  156. *
  157. * Store function of the "failed" attribute of an adapter.
  158. * If a "0" gets written to "failed", error recovery will be
  159. * started for the belonging adapter.
  160. */
  161. static ssize_t
  162. zfcp_sysfs_adapter_failed_store(struct device *dev, struct device_attribute *attr,
  163. const char *buf, size_t count)
  164. {
  165. struct zfcp_adapter *adapter;
  166. unsigned int val;
  167. char *endp;
  168. int retval = 0;
  169. down(&zfcp_data.config_sema);
  170. adapter = dev_get_drvdata(dev);
  171. if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status)) {
  172. retval = -EBUSY;
  173. goto out;
  174. }
  175. val = simple_strtoul(buf, &endp, 0);
  176. if (((endp + 1) < (buf + count)) || (val != 0)) {
  177. retval = -EINVAL;
  178. goto out;
  179. }
  180. zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
  181. ZFCP_SET);
  182. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  183. zfcp_erp_wait(adapter);
  184. out:
  185. up(&zfcp_data.config_sema);
  186. return retval ? retval : (ssize_t) count;
  187. }
  188. /**
  189. * zfcp_sysfs_adapter_failed_show - failed state of adapter
  190. * @dev: pointer to belonging device
  191. * @buf: pointer to input buffer
  192. *
  193. * Show function of "failed" attribute of adapter. Will be
  194. * "0" if adapter is working, otherwise "1".
  195. */
  196. static ssize_t
  197. zfcp_sysfs_adapter_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
  198. {
  199. struct zfcp_adapter *adapter;
  200. adapter = dev_get_drvdata(dev);
  201. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status))
  202. return sprintf(buf, "1\n");
  203. else
  204. return sprintf(buf, "0\n");
  205. }
  206. static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_adapter_failed_show,
  207. zfcp_sysfs_adapter_failed_store);
  208. static struct attribute *zfcp_adapter_attrs[] = {
  209. &dev_attr_failed.attr,
  210. &dev_attr_in_recovery.attr,
  211. &dev_attr_port_remove.attr,
  212. &dev_attr_port_add.attr,
  213. &dev_attr_peer_wwnn.attr,
  214. &dev_attr_peer_wwpn.attr,
  215. &dev_attr_peer_d_id.attr,
  216. &dev_attr_physical_wwpn.attr,
  217. &dev_attr_physical_s_id.attr,
  218. &dev_attr_card_version.attr,
  219. &dev_attr_lic_version.attr,
  220. &dev_attr_status.attr,
  221. &dev_attr_hardware_version.attr,
  222. NULL
  223. };
  224. static struct attribute_group zfcp_adapter_attr_group = {
  225. .attrs = zfcp_adapter_attrs,
  226. };
  227. /**
  228. * zfcp_sysfs_create_adapter_files - create sysfs adapter files
  229. * @dev: pointer to belonging device
  230. *
  231. * Create all attributes of the sysfs representation of an adapter.
  232. */
  233. int
  234. zfcp_sysfs_adapter_create_files(struct device *dev)
  235. {
  236. return sysfs_create_group(&dev->kobj, &zfcp_adapter_attr_group);
  237. }
  238. /**
  239. * zfcp_sysfs_remove_adapter_files - remove sysfs adapter files
  240. * @dev: pointer to belonging device
  241. *
  242. * Remove all attributes of the sysfs representation of an adapter.
  243. */
  244. void
  245. zfcp_sysfs_adapter_remove_files(struct device *dev)
  246. {
  247. sysfs_remove_group(&dev->kobj, &zfcp_adapter_attr_group);
  248. }
  249. #undef ZFCP_LOG_AREA