zfcp_ccw.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. if (atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED,
  112. &unit->status))
  113. scsi_remove_device(unit->device);
  114. zfcp_unit_dequeue(unit);
  115. }
  116. zfcp_port_dequeue(port);
  117. }
  118. zfcp_adapter_wait(adapter);
  119. zfcp_adapter_dequeue(adapter);
  120. up(&zfcp_data.config_sema);
  121. }
  122. /**
  123. * zfcp_ccw_set_online - set_online function of zfcp driver
  124. * @ccw_device: pointer to belonging ccw device
  125. *
  126. * This function gets called by the common i/o layer and sets an adapter
  127. * into state online. Setting an fcp device online means that it will be
  128. * registered with the SCSI stack, that the QDIO queues will be set up
  129. * and that the adapter will be opened (asynchronously).
  130. */
  131. static int
  132. zfcp_ccw_set_online(struct ccw_device *ccw_device)
  133. {
  134. struct zfcp_adapter *adapter;
  135. int retval;
  136. down(&zfcp_data.config_sema);
  137. adapter = dev_get_drvdata(&ccw_device->dev);
  138. retval = zfcp_erp_thread_setup(adapter);
  139. if (retval) {
  140. ZFCP_LOG_INFO("error: start of error recovery thread for "
  141. "adapter %s failed\n",
  142. zfcp_get_busid_by_adapter(adapter));
  143. goto out;
  144. }
  145. retval = zfcp_adapter_scsi_register(adapter);
  146. if (retval)
  147. goto out_scsi_register;
  148. /* initialize request counter */
  149. BUG_ON(!zfcp_reqlist_isempty(adapter));
  150. adapter->req_no = 0;
  151. zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
  152. ZFCP_SET);
  153. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  154. zfcp_erp_wait(adapter);
  155. goto out;
  156. out_scsi_register:
  157. zfcp_erp_thread_kill(adapter);
  158. out:
  159. up(&zfcp_data.config_sema);
  160. return retval;
  161. }
  162. /**
  163. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  164. * @ccw_device: pointer to belonging ccw device
  165. *
  166. * This function gets called by the common i/o layer and sets an adapter
  167. * into state offline.
  168. */
  169. static int
  170. zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  171. {
  172. struct zfcp_adapter *adapter;
  173. down(&zfcp_data.config_sema);
  174. adapter = dev_get_drvdata(&ccw_device->dev);
  175. zfcp_erp_adapter_shutdown(adapter, 0);
  176. zfcp_erp_wait(adapter);
  177. zfcp_erp_thread_kill(adapter);
  178. up(&zfcp_data.config_sema);
  179. return 0;
  180. }
  181. /**
  182. * zfcp_ccw_notify
  183. * @ccw_device: pointer to belonging ccw device
  184. * @event: indicates if adapter was detached or attached
  185. *
  186. * This function gets called by the common i/o layer if an adapter has gone
  187. * or reappeared.
  188. */
  189. static int
  190. zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  191. {
  192. struct zfcp_adapter *adapter;
  193. down(&zfcp_data.config_sema);
  194. adapter = dev_get_drvdata(&ccw_device->dev);
  195. switch (event) {
  196. case CIO_GONE:
  197. ZFCP_LOG_NORMAL("adapter %s: device gone\n",
  198. zfcp_get_busid_by_adapter(adapter));
  199. debug_text_event(adapter->erp_dbf,1,"dev_gone");
  200. zfcp_erp_adapter_shutdown(adapter, 0);
  201. break;
  202. case CIO_NO_PATH:
  203. ZFCP_LOG_NORMAL("adapter %s: no path\n",
  204. zfcp_get_busid_by_adapter(adapter));
  205. debug_text_event(adapter->erp_dbf,1,"no_path");
  206. zfcp_erp_adapter_shutdown(adapter, 0);
  207. break;
  208. case CIO_OPER:
  209. ZFCP_LOG_NORMAL("adapter %s: operational again\n",
  210. zfcp_get_busid_by_adapter(adapter));
  211. debug_text_event(adapter->erp_dbf,1,"dev_oper");
  212. zfcp_erp_modify_adapter_status(adapter,
  213. ZFCP_STATUS_COMMON_RUNNING,
  214. ZFCP_SET);
  215. zfcp_erp_adapter_reopen(adapter,
  216. ZFCP_STATUS_COMMON_ERP_FAILED);
  217. break;
  218. }
  219. zfcp_erp_wait(adapter);
  220. up(&zfcp_data.config_sema);
  221. return 1;
  222. }
  223. /**
  224. * zfcp_ccw_register - ccw register function
  225. *
  226. * Registers the driver at the common i/o layer. This function will be called
  227. * at module load time/system start.
  228. */
  229. int __init
  230. zfcp_ccw_register(void)
  231. {
  232. int retval;
  233. retval = ccw_driver_register(&zfcp_ccw_driver);
  234. if (retval)
  235. goto out;
  236. retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
  237. if (retval)
  238. ccw_driver_unregister(&zfcp_ccw_driver);
  239. out:
  240. return retval;
  241. }
  242. /**
  243. * zfcp_ccw_shutdown - gets called on reboot/shutdown
  244. *
  245. * Makes sure that QDIO queues are down when the system gets stopped.
  246. */
  247. static void
  248. zfcp_ccw_shutdown(struct ccw_device *cdev)
  249. {
  250. struct zfcp_adapter *adapter;
  251. down(&zfcp_data.config_sema);
  252. adapter = dev_get_drvdata(&cdev->dev);
  253. zfcp_erp_adapter_shutdown(adapter, 0);
  254. zfcp_erp_wait(adapter);
  255. up(&zfcp_data.config_sema);
  256. }
  257. #undef ZFCP_LOG_AREA