zfcp_sysfs_adapter.c 8.7 KB

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