zfcp_ccw.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * This file is part of the zfcp device driver for
  3. * FCP adapters for IBM System z9 and zSeries.
  4. *
  5. * (C) Copyright IBM Corp. 2002, 2006
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include "zfcp_ext.h"
  22. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  23. static int zfcp_ccw_probe(struct ccw_device *);
  24. static void zfcp_ccw_remove(struct ccw_device *);
  25. static int zfcp_ccw_set_online(struct ccw_device *);
  26. static int zfcp_ccw_set_offline(struct ccw_device *);
  27. static int zfcp_ccw_notify(struct ccw_device *, int);
  28. static void zfcp_ccw_shutdown(struct ccw_device *);
  29. static struct ccw_device_id zfcp_ccw_device_id[] = {
  30. {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
  31. ZFCP_CONTROL_UNIT_MODEL,
  32. ZFCP_DEVICE_TYPE,
  33. ZFCP_DEVICE_MODEL)},
  34. {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
  35. ZFCP_CONTROL_UNIT_MODEL,
  36. ZFCP_DEVICE_TYPE,
  37. ZFCP_DEVICE_MODEL_PRIV)},
  38. {},
  39. };
  40. static struct ccw_driver zfcp_ccw_driver = {
  41. .owner = THIS_MODULE,
  42. .name = ZFCP_NAME,
  43. .ids = zfcp_ccw_device_id,
  44. .probe = zfcp_ccw_probe,
  45. .remove = zfcp_ccw_remove,
  46. .set_online = zfcp_ccw_set_online,
  47. .set_offline = zfcp_ccw_set_offline,
  48. .notify = zfcp_ccw_notify,
  49. .shutdown = zfcp_ccw_shutdown,
  50. .driver = {
  51. .groups = zfcp_driver_attr_groups,
  52. },
  53. };
  54. MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
  55. /**
  56. * zfcp_ccw_probe - probe function of zfcp driver
  57. * @ccw_device: pointer to belonging ccw device
  58. *
  59. * This function gets called by the common i/o layer and sets up the initial
  60. * data structures for each fcp adapter, which was detected by the system.
  61. * Also the sysfs files for this adapter will be created by this function.
  62. * In addition the nameserver port will be added to the ports of the adapter
  63. * and its sysfs representation will be created too.
  64. */
  65. static int
  66. zfcp_ccw_probe(struct ccw_device *ccw_device)
  67. {
  68. struct zfcp_adapter *adapter;
  69. int retval = 0;
  70. down(&zfcp_data.config_sema);
  71. adapter = zfcp_adapter_enqueue(ccw_device);
  72. if (!adapter)
  73. retval = -EINVAL;
  74. else
  75. ZFCP_LOG_DEBUG("Probed adapter %s\n",
  76. zfcp_get_busid_by_adapter(adapter));
  77. up(&zfcp_data.config_sema);
  78. return retval;
  79. }
  80. /**
  81. * zfcp_ccw_remove - remove function of zfcp driver
  82. * @ccw_device: pointer to belonging ccw device
  83. *
  84. * This function gets called by the common i/o layer and removes an adapter
  85. * from the system. Task of this function is to get rid of all units and
  86. * ports that belong to this adapter. And in addition all resources of this
  87. * adapter will be freed too.
  88. */
  89. static void
  90. zfcp_ccw_remove(struct ccw_device *ccw_device)
  91. {
  92. struct zfcp_adapter *adapter;
  93. struct zfcp_port *port, *p;
  94. struct zfcp_unit *unit, *u;
  95. ccw_device_set_offline(ccw_device);
  96. down(&zfcp_data.config_sema);
  97. adapter = dev_get_drvdata(&ccw_device->dev);
  98. ZFCP_LOG_DEBUG("Removing adapter %s\n",
  99. zfcp_get_busid_by_adapter(adapter));
  100. write_lock_irq(&zfcp_data.config_lock);
  101. list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
  102. list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
  103. list_move(&unit->list, &port->unit_remove_lh);
  104. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  105. &unit->status);
  106. }
  107. list_move(&port->list, &adapter->port_remove_lh);
  108. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  109. }
  110. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  111. write_unlock_irq(&zfcp_data.config_lock);
  112. list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
  113. list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
  114. if (atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED,
  115. &unit->status))
  116. scsi_remove_device(unit->device);
  117. zfcp_unit_dequeue(unit);
  118. }
  119. zfcp_port_dequeue(port);
  120. }
  121. zfcp_adapter_wait(adapter);
  122. zfcp_adapter_dequeue(adapter);
  123. up(&zfcp_data.config_sema);
  124. }
  125. /**
  126. * zfcp_ccw_set_online - set_online function of zfcp driver
  127. * @ccw_device: pointer to belonging ccw device
  128. *
  129. * This function gets called by the common i/o layer and sets an adapter
  130. * into state online. Setting an fcp device online means that it will be
  131. * registered with the SCSI stack, that the QDIO queues will be set up
  132. * and that the adapter will be opened (asynchronously).
  133. */
  134. static int
  135. zfcp_ccw_set_online(struct ccw_device *ccw_device)
  136. {
  137. struct zfcp_adapter *adapter;
  138. int retval;
  139. down(&zfcp_data.config_sema);
  140. adapter = dev_get_drvdata(&ccw_device->dev);
  141. retval = zfcp_erp_thread_setup(adapter);
  142. if (retval) {
  143. ZFCP_LOG_INFO("error: start of error recovery thread for "
  144. "adapter %s failed\n",
  145. zfcp_get_busid_by_adapter(adapter));
  146. goto out;
  147. }
  148. retval = zfcp_adapter_scsi_register(adapter);
  149. if (retval)
  150. goto out_scsi_register;
  151. /* initialize request counter */
  152. BUG_ON(!zfcp_reqlist_isempty(adapter));
  153. adapter->req_no = 0;
  154. zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
  155. ZFCP_SET);
  156. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  157. zfcp_erp_wait(adapter);
  158. goto out;
  159. out_scsi_register:
  160. zfcp_erp_thread_kill(adapter);
  161. out:
  162. up(&zfcp_data.config_sema);
  163. return retval;
  164. }
  165. /**
  166. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  167. * @ccw_device: pointer to belonging ccw device
  168. *
  169. * This function gets called by the common i/o layer and sets an adapter
  170. * into state offline.
  171. */
  172. static int
  173. zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  174. {
  175. struct zfcp_adapter *adapter;
  176. down(&zfcp_data.config_sema);
  177. adapter = dev_get_drvdata(&ccw_device->dev);
  178. zfcp_erp_adapter_shutdown(adapter, 0);
  179. zfcp_erp_wait(adapter);
  180. zfcp_erp_thread_kill(adapter);
  181. up(&zfcp_data.config_sema);
  182. return 0;
  183. }
  184. /**
  185. * zfcp_ccw_notify
  186. * @ccw_device: pointer to belonging ccw device
  187. * @event: indicates if adapter was detached or attached
  188. *
  189. * This function gets called by the common i/o layer if an adapter has gone
  190. * or reappeared.
  191. */
  192. static int
  193. zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  194. {
  195. struct zfcp_adapter *adapter;
  196. down(&zfcp_data.config_sema);
  197. adapter = dev_get_drvdata(&ccw_device->dev);
  198. switch (event) {
  199. case CIO_GONE:
  200. ZFCP_LOG_NORMAL("adapter %s: device gone\n",
  201. zfcp_get_busid_by_adapter(adapter));
  202. debug_text_event(adapter->erp_dbf,1,"dev_gone");
  203. zfcp_erp_adapter_shutdown(adapter, 0);
  204. break;
  205. case CIO_NO_PATH:
  206. ZFCP_LOG_NORMAL("adapter %s: no path\n",
  207. zfcp_get_busid_by_adapter(adapter));
  208. debug_text_event(adapter->erp_dbf,1,"no_path");
  209. zfcp_erp_adapter_shutdown(adapter, 0);
  210. break;
  211. case CIO_OPER:
  212. ZFCP_LOG_NORMAL("adapter %s: operational again\n",
  213. zfcp_get_busid_by_adapter(adapter));
  214. debug_text_event(adapter->erp_dbf,1,"dev_oper");
  215. zfcp_erp_modify_adapter_status(adapter,
  216. ZFCP_STATUS_COMMON_RUNNING,
  217. ZFCP_SET);
  218. zfcp_erp_adapter_reopen(adapter,
  219. ZFCP_STATUS_COMMON_ERP_FAILED);
  220. break;
  221. }
  222. zfcp_erp_wait(adapter);
  223. up(&zfcp_data.config_sema);
  224. return 1;
  225. }
  226. /**
  227. * zfcp_ccw_register - ccw register function
  228. *
  229. * Registers the driver at the common i/o layer. This function will be called
  230. * at module load time/system start.
  231. */
  232. int __init
  233. zfcp_ccw_register(void)
  234. {
  235. return ccw_driver_register(&zfcp_ccw_driver);
  236. }
  237. /**
  238. * zfcp_ccw_shutdown - gets called on reboot/shutdown
  239. *
  240. * Makes sure that QDIO queues are down when the system gets stopped.
  241. */
  242. static void
  243. zfcp_ccw_shutdown(struct ccw_device *cdev)
  244. {
  245. struct zfcp_adapter *adapter;
  246. down(&zfcp_data.config_sema);
  247. adapter = dev_get_drvdata(&cdev->dev);
  248. zfcp_erp_adapter_shutdown(adapter, 0);
  249. zfcp_erp_wait(adapter);
  250. up(&zfcp_data.config_sema);
  251. }
  252. #undef ZFCP_LOG_AREA