zfcp_ccw.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * linux/drivers/s390/scsi/zfcp_ccw.c
  3. *
  4. * FCP adapter driver for IBM eServer zSeries
  5. *
  6. * CCW driver 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_CCW_C_REVISION "$Revision: 1.58 $"
  30. #include "zfcp_ext.h"
  31. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG
  32. static int zfcp_ccw_probe(struct ccw_device *);
  33. static void zfcp_ccw_remove(struct ccw_device *);
  34. static int zfcp_ccw_set_online(struct ccw_device *);
  35. static int zfcp_ccw_set_offline(struct ccw_device *);
  36. static int zfcp_ccw_notify(struct ccw_device *, int);
  37. static void zfcp_ccw_shutdown(struct device *);
  38. static struct ccw_device_id zfcp_ccw_device_id[] = {
  39. {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
  40. ZFCP_CONTROL_UNIT_MODEL,
  41. ZFCP_DEVICE_TYPE,
  42. ZFCP_DEVICE_MODEL)},
  43. {CCW_DEVICE_DEVTYPE(ZFCP_CONTROL_UNIT_TYPE,
  44. ZFCP_CONTROL_UNIT_MODEL,
  45. ZFCP_DEVICE_TYPE,
  46. ZFCP_DEVICE_MODEL_PRIV)},
  47. {},
  48. };
  49. static struct ccw_driver zfcp_ccw_driver = {
  50. .owner = THIS_MODULE,
  51. .name = ZFCP_NAME,
  52. .ids = zfcp_ccw_device_id,
  53. .probe = zfcp_ccw_probe,
  54. .remove = zfcp_ccw_remove,
  55. .set_online = zfcp_ccw_set_online,
  56. .set_offline = zfcp_ccw_set_offline,
  57. .notify = zfcp_ccw_notify,
  58. .driver = {
  59. .shutdown = zfcp_ccw_shutdown,
  60. },
  61. };
  62. MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
  63. /**
  64. * zfcp_ccw_probe - probe function of zfcp driver
  65. * @ccw_device: pointer to belonging ccw device
  66. *
  67. * This function gets called by the common i/o layer and sets up the initial
  68. * data structures for each fcp adapter, which was detected by the system.
  69. * Also the sysfs files for this adapter will be created by this function.
  70. * In addition the nameserver port will be added to the ports of the adapter
  71. * and its sysfs representation will be created too.
  72. */
  73. static int
  74. zfcp_ccw_probe(struct ccw_device *ccw_device)
  75. {
  76. struct zfcp_adapter *adapter;
  77. int retval = 0;
  78. down(&zfcp_data.config_sema);
  79. adapter = zfcp_adapter_enqueue(ccw_device);
  80. if (!adapter)
  81. retval = -EINVAL;
  82. else
  83. ZFCP_LOG_DEBUG("Probed adapter %s\n",
  84. zfcp_get_busid_by_adapter(adapter));
  85. up(&zfcp_data.config_sema);
  86. return retval;
  87. }
  88. /**
  89. * zfcp_ccw_remove - remove function of zfcp driver
  90. * @ccw_device: pointer to belonging ccw device
  91. *
  92. * This function gets called by the common i/o layer and removes an adapter
  93. * from the system. Task of this function is to get rid of all units and
  94. * ports that belong to this adapter. And in addition all resources of this
  95. * adapter will be freed too.
  96. */
  97. static void
  98. zfcp_ccw_remove(struct ccw_device *ccw_device)
  99. {
  100. struct zfcp_adapter *adapter;
  101. struct zfcp_port *port, *p;
  102. struct zfcp_unit *unit, *u;
  103. ccw_device_set_offline(ccw_device);
  104. down(&zfcp_data.config_sema);
  105. adapter = dev_get_drvdata(&ccw_device->dev);
  106. ZFCP_LOG_DEBUG("Removing adapter %s\n",
  107. zfcp_get_busid_by_adapter(adapter));
  108. write_lock_irq(&zfcp_data.config_lock);
  109. list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
  110. list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
  111. list_move(&unit->list, &port->unit_remove_lh);
  112. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  113. &unit->status);
  114. }
  115. list_move(&port->list, &adapter->port_remove_lh);
  116. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  117. }
  118. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  119. write_unlock_irq(&zfcp_data.config_lock);
  120. list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
  121. list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
  122. zfcp_unit_dequeue(unit);
  123. }
  124. zfcp_port_dequeue(port);
  125. }
  126. zfcp_adapter_wait(adapter);
  127. zfcp_adapter_dequeue(adapter);
  128. up(&zfcp_data.config_sema);
  129. }
  130. /**
  131. * zfcp_ccw_set_online - set_online function of zfcp driver
  132. * @ccw_device: pointer to belonging ccw device
  133. *
  134. * This function gets called by the common i/o layer and sets an adapter
  135. * into state online. Setting an fcp device online means that it will be
  136. * registered with the SCSI stack, that the QDIO queues will be set up
  137. * and that the adapter will be opened (asynchronously).
  138. */
  139. static int
  140. zfcp_ccw_set_online(struct ccw_device *ccw_device)
  141. {
  142. struct zfcp_adapter *adapter;
  143. int retval;
  144. down(&zfcp_data.config_sema);
  145. adapter = dev_get_drvdata(&ccw_device->dev);
  146. retval = zfcp_adapter_debug_register(adapter);
  147. if (retval)
  148. goto out;
  149. retval = zfcp_erp_thread_setup(adapter);
  150. if (retval) {
  151. ZFCP_LOG_INFO("error: start of error recovery thread for "
  152. "adapter %s failed\n",
  153. zfcp_get_busid_by_adapter(adapter));
  154. goto out_erp_thread;
  155. }
  156. retval = zfcp_adapter_scsi_register(adapter);
  157. if (retval)
  158. goto out_scsi_register;
  159. zfcp_erp_modify_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING,
  160. ZFCP_SET);
  161. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  162. zfcp_erp_wait(adapter);
  163. goto out;
  164. out_scsi_register:
  165. zfcp_erp_thread_kill(adapter);
  166. out_erp_thread:
  167. zfcp_adapter_debug_unregister(adapter);
  168. out:
  169. up(&zfcp_data.config_sema);
  170. return retval;
  171. }
  172. /**
  173. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  174. * @ccw_device: pointer to belonging ccw device
  175. *
  176. * This function gets called by the common i/o layer and sets an adapter
  177. * into state offline. Setting an fcp device offline means that it will be
  178. * unregistered from the SCSI stack and that the adapter will be shut down
  179. * asynchronously.
  180. */
  181. static int
  182. zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  183. {
  184. struct zfcp_adapter *adapter;
  185. struct zfcp_port *port;
  186. struct fc_rport *rport;
  187. down(&zfcp_data.config_sema);
  188. adapter = dev_get_drvdata(&ccw_device->dev);
  189. /* might be racy, but we cannot take config_lock due to the fact that
  190. fc_remote_port_delete might sleep */
  191. list_for_each_entry(port, &adapter->port_list_head, list)
  192. if (port->rport) {
  193. rport = port->rport;
  194. port->rport = NULL;
  195. fc_remote_port_delete(rport);
  196. }
  197. zfcp_erp_adapter_shutdown(adapter, 0);
  198. zfcp_erp_wait(adapter);
  199. zfcp_adapter_scsi_unregister(adapter);
  200. zfcp_erp_thread_kill(adapter);
  201. zfcp_adapter_debug_unregister(adapter);
  202. up(&zfcp_data.config_sema);
  203. return 0;
  204. }
  205. /**
  206. * zfcp_ccw_notify
  207. * @ccw_device: pointer to belonging ccw device
  208. * @event: indicates if adapter was detached or attached
  209. *
  210. * This function gets called by the common i/o layer if an adapter has gone
  211. * or reappeared.
  212. */
  213. static int
  214. zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  215. {
  216. struct zfcp_adapter *adapter;
  217. down(&zfcp_data.config_sema);
  218. adapter = dev_get_drvdata(&ccw_device->dev);
  219. switch (event) {
  220. case CIO_GONE:
  221. ZFCP_LOG_NORMAL("adapter %s: device gone\n",
  222. zfcp_get_busid_by_adapter(adapter));
  223. debug_text_event(adapter->erp_dbf,1,"dev_gone");
  224. zfcp_erp_adapter_shutdown(adapter, 0);
  225. break;
  226. case CIO_NO_PATH:
  227. ZFCP_LOG_NORMAL("adapter %s: no path\n",
  228. zfcp_get_busid_by_adapter(adapter));
  229. debug_text_event(adapter->erp_dbf,1,"no_path");
  230. zfcp_erp_adapter_shutdown(adapter, 0);
  231. break;
  232. case CIO_OPER:
  233. ZFCP_LOG_NORMAL("adapter %s: operational again\n",
  234. zfcp_get_busid_by_adapter(adapter));
  235. debug_text_event(adapter->erp_dbf,1,"dev_oper");
  236. zfcp_erp_modify_adapter_status(adapter,
  237. ZFCP_STATUS_COMMON_RUNNING,
  238. ZFCP_SET);
  239. zfcp_erp_adapter_reopen(adapter,
  240. ZFCP_STATUS_COMMON_ERP_FAILED);
  241. break;
  242. }
  243. zfcp_erp_wait(adapter);
  244. up(&zfcp_data.config_sema);
  245. return 1;
  246. }
  247. /**
  248. * zfcp_ccw_register - ccw register function
  249. *
  250. * Registers the driver at the common i/o layer. This function will be called
  251. * at module load time/system start.
  252. */
  253. int __init
  254. zfcp_ccw_register(void)
  255. {
  256. int retval;
  257. retval = ccw_driver_register(&zfcp_ccw_driver);
  258. if (retval)
  259. goto out;
  260. retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
  261. if (retval)
  262. ccw_driver_unregister(&zfcp_ccw_driver);
  263. out:
  264. return retval;
  265. }
  266. /**
  267. * zfcp_ccw_unregister - ccw unregister function
  268. *
  269. * Unregisters the driver from common i/o layer. Function will be called at
  270. * module unload/system shutdown.
  271. */
  272. void __exit
  273. zfcp_ccw_unregister(void)
  274. {
  275. zfcp_sysfs_driver_remove_files(&zfcp_ccw_driver.driver);
  276. ccw_driver_unregister(&zfcp_ccw_driver);
  277. }
  278. /**
  279. * zfcp_ccw_shutdown - gets called on reboot/shutdown
  280. *
  281. * Makes sure that QDIO queues are down when the system gets stopped.
  282. */
  283. static void
  284. zfcp_ccw_shutdown(struct device *dev)
  285. {
  286. struct zfcp_adapter *adapter;
  287. down(&zfcp_data.config_sema);
  288. adapter = dev_get_drvdata(dev);
  289. zfcp_erp_adapter_shutdown(adapter, 0);
  290. zfcp_erp_wait(adapter);
  291. up(&zfcp_data.config_sema);
  292. }
  293. #undef ZFCP_LOG_AREA