zfcp_ccw.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. };
  51. MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
  52. /**
  53. * zfcp_ccw_probe - probe function of zfcp driver
  54. * @ccw_device: pointer to belonging ccw device
  55. *
  56. * This function gets called by the common i/o layer and sets up the initial
  57. * data structures for each fcp adapter, which was detected by the system.
  58. * Also the sysfs files for this adapter will be created by this function.
  59. * In addition the nameserver port will be added to the ports of the adapter
  60. * and its sysfs representation will be created too.
  61. */
  62. static int
  63. zfcp_ccw_probe(struct ccw_device *ccw_device)
  64. {
  65. struct zfcp_adapter *adapter;
  66. int retval = 0;
  67. down(&zfcp_data.config_sema);
  68. adapter = zfcp_adapter_enqueue(ccw_device);
  69. if (!adapter)
  70. retval = -EINVAL;
  71. else
  72. ZFCP_LOG_DEBUG("Probed adapter %s\n",
  73. zfcp_get_busid_by_adapter(adapter));
  74. up(&zfcp_data.config_sema);
  75. return retval;
  76. }
  77. /**
  78. * zfcp_ccw_remove - remove function of zfcp driver
  79. * @ccw_device: pointer to belonging ccw device
  80. *
  81. * This function gets called by the common i/o layer and removes an adapter
  82. * from the system. Task of this function is to get rid of all units and
  83. * ports that belong to this adapter. And in addition all resources of this
  84. * adapter will be freed too.
  85. */
  86. static void
  87. zfcp_ccw_remove(struct ccw_device *ccw_device)
  88. {
  89. struct zfcp_adapter *adapter;
  90. struct zfcp_port *port, *p;
  91. struct zfcp_unit *unit, *u;
  92. ccw_device_set_offline(ccw_device);
  93. down(&zfcp_data.config_sema);
  94. adapter = dev_get_drvdata(&ccw_device->dev);
  95. ZFCP_LOG_DEBUG("Removing adapter %s\n",
  96. zfcp_get_busid_by_adapter(adapter));
  97. write_lock_irq(&zfcp_data.config_lock);
  98. list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
  99. list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
  100. list_move(&unit->list, &port->unit_remove_lh);
  101. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  102. &unit->status);
  103. }
  104. list_move(&port->list, &adapter->port_remove_lh);
  105. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  106. }
  107. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  108. write_unlock_irq(&zfcp_data.config_lock);
  109. list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
  110. list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
  111. zfcp_unit_dequeue(unit);
  112. }
  113. zfcp_port_dequeue(port);
  114. }
  115. zfcp_adapter_wait(adapter);
  116. zfcp_adapter_dequeue(adapter);
  117. up(&zfcp_data.config_sema);
  118. }
  119. /**
  120. * zfcp_ccw_set_online - set_online function of zfcp driver
  121. * @ccw_device: pointer to belonging ccw device
  122. *
  123. * This function gets called by the common i/o layer and sets an adapter
  124. * into state online. Setting an fcp device online means that it will be
  125. * registered with the SCSI stack, that the QDIO queues will be set up
  126. * and that the adapter will be opened (asynchronously).
  127. */
  128. static int
  129. zfcp_ccw_set_online(struct ccw_device *ccw_device)
  130. {
  131. struct zfcp_adapter *adapter;
  132. int retval;
  133. down(&zfcp_data.config_sema);
  134. adapter = dev_get_drvdata(&ccw_device->dev);
  135. retval = zfcp_erp_thread_setup(adapter);
  136. if (retval) {
  137. ZFCP_LOG_INFO("error: start of error recovery thread for "
  138. "adapter %s failed\n",
  139. zfcp_get_busid_by_adapter(adapter));
  140. goto out;
  141. }
  142. retval = zfcp_adapter_scsi_register(adapter);
  143. if (retval)
  144. goto out_scsi_register;
  145. /* initialize request counter */
  146. BUG_ON(!zfcp_reqlist_isempty(adapter));
  147. adapter->req_no = 0;
  148. zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
  149. ZFCP_SET);
  150. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  151. zfcp_erp_wait(adapter);
  152. goto out;
  153. out_scsi_register:
  154. zfcp_erp_thread_kill(adapter);
  155. out:
  156. up(&zfcp_data.config_sema);
  157. return retval;
  158. }
  159. /**
  160. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  161. * @ccw_device: pointer to belonging ccw device
  162. *
  163. * This function gets called by the common i/o layer and sets an adapter
  164. * into state offline.
  165. */
  166. static int
  167. zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  168. {
  169. struct zfcp_adapter *adapter;
  170. down(&zfcp_data.config_sema);
  171. adapter = dev_get_drvdata(&ccw_device->dev);
  172. zfcp_erp_adapter_shutdown(adapter, 0);
  173. zfcp_erp_wait(adapter);
  174. zfcp_erp_thread_kill(adapter);
  175. up(&zfcp_data.config_sema);
  176. return 0;
  177. }
  178. /**
  179. * zfcp_ccw_notify
  180. * @ccw_device: pointer to belonging ccw device
  181. * @event: indicates if adapter was detached or attached
  182. *
  183. * This function gets called by the common i/o layer if an adapter has gone
  184. * or reappeared.
  185. */
  186. static int
  187. zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  188. {
  189. struct zfcp_adapter *adapter;
  190. down(&zfcp_data.config_sema);
  191. adapter = dev_get_drvdata(&ccw_device->dev);
  192. switch (event) {
  193. case CIO_GONE:
  194. ZFCP_LOG_NORMAL("adapter %s: device gone\n",
  195. zfcp_get_busid_by_adapter(adapter));
  196. debug_text_event(adapter->erp_dbf,1,"dev_gone");
  197. zfcp_erp_adapter_shutdown(adapter, 0);
  198. break;
  199. case CIO_NO_PATH:
  200. ZFCP_LOG_NORMAL("adapter %s: no path\n",
  201. zfcp_get_busid_by_adapter(adapter));
  202. debug_text_event(adapter->erp_dbf,1,"no_path");
  203. zfcp_erp_adapter_shutdown(adapter, 0);
  204. break;
  205. case CIO_OPER:
  206. ZFCP_LOG_NORMAL("adapter %s: operational again\n",
  207. zfcp_get_busid_by_adapter(adapter));
  208. debug_text_event(adapter->erp_dbf,1,"dev_oper");
  209. zfcp_erp_modify_adapter_status(adapter,
  210. ZFCP_STATUS_COMMON_RUNNING,
  211. ZFCP_SET);
  212. zfcp_erp_adapter_reopen(adapter,
  213. ZFCP_STATUS_COMMON_ERP_FAILED);
  214. break;
  215. }
  216. zfcp_erp_wait(adapter);
  217. up(&zfcp_data.config_sema);
  218. return 1;
  219. }
  220. /**
  221. * zfcp_ccw_register - ccw register function
  222. *
  223. * Registers the driver at the common i/o layer. This function will be called
  224. * at module load time/system start.
  225. */
  226. int __init
  227. zfcp_ccw_register(void)
  228. {
  229. int retval;
  230. retval = ccw_driver_register(&zfcp_ccw_driver);
  231. if (retval)
  232. goto out;
  233. retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
  234. if (retval)
  235. ccw_driver_unregister(&zfcp_ccw_driver);
  236. out:
  237. return retval;
  238. }
  239. /**
  240. * zfcp_ccw_shutdown - gets called on reboot/shutdown
  241. *
  242. * Makes sure that QDIO queues are down when the system gets stopped.
  243. */
  244. static void
  245. zfcp_ccw_shutdown(struct ccw_device *cdev)
  246. {
  247. struct zfcp_adapter *adapter;
  248. down(&zfcp_data.config_sema);
  249. adapter = dev_get_drvdata(&cdev->dev);
  250. zfcp_erp_adapter_shutdown(adapter, 0);
  251. zfcp_erp_wait(adapter);
  252. up(&zfcp_data.config_sema);
  253. }
  254. #undef ZFCP_LOG_AREA