zfcp_sysfs_adapter.c 8.1 KB

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