zfcp_ccw.c 8.8 KB

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