zfcp_ccw.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * zfcp device driver
  3. *
  4. * Registration and callback for the s390 common I/O layer.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include "zfcp_ext.h"
  11. #define ZFCP_MODEL_PRIV 0x4
  12. static int zfcp_ccw_suspend(struct ccw_device *cdev)
  13. {
  14. struct zfcp_adapter *adapter = dev_get_drvdata(&cdev->dev);
  15. if (!adapter)
  16. return 0;
  17. mutex_lock(&zfcp_data.config_mutex);
  18. zfcp_erp_adapter_shutdown(adapter, 0, "ccsusp1", NULL);
  19. zfcp_erp_wait(adapter);
  20. mutex_unlock(&zfcp_data.config_mutex);
  21. return 0;
  22. }
  23. static int zfcp_ccw_activate(struct ccw_device *cdev)
  24. {
  25. struct zfcp_adapter *adapter = dev_get_drvdata(&cdev->dev);
  26. if (!adapter)
  27. return 0;
  28. zfcp_erp_modify_adapter_status(adapter, "ccresu1", NULL,
  29. ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  30. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  31. "ccresu2", NULL);
  32. zfcp_erp_wait(adapter);
  33. flush_work(&adapter->scan_work);
  34. return 0;
  35. }
  36. static struct ccw_device_id zfcp_ccw_device_id[] = {
  37. { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
  38. { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, ZFCP_MODEL_PRIV) },
  39. {},
  40. };
  41. MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
  42. /**
  43. * zfcp_ccw_priv_sch - check if subchannel is privileged
  44. * @adapter: Adapter/Subchannel to check
  45. */
  46. int zfcp_ccw_priv_sch(struct zfcp_adapter *adapter)
  47. {
  48. return adapter->ccw_device->id.dev_model == ZFCP_MODEL_PRIV;
  49. }
  50. /**
  51. * zfcp_ccw_probe - probe function of zfcp driver
  52. * @ccw_device: pointer to belonging ccw device
  53. *
  54. * This function gets called by the common i/o layer for each FCP
  55. * device found on the current system. This is only a stub to make cio
  56. * work: To only allocate adapter resources for devices actually used,
  57. * the allocation is deferred to the first call to ccw_set_online.
  58. */
  59. static int zfcp_ccw_probe(struct ccw_device *ccw_device)
  60. {
  61. return 0;
  62. }
  63. /**
  64. * zfcp_ccw_remove - remove 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 removes an adapter
  68. * from the system. Task of this function is to get rid of all units and
  69. * ports that belong to this adapter. And in addition all resources of this
  70. * adapter will be freed too.
  71. */
  72. static void zfcp_ccw_remove(struct ccw_device *ccw_device)
  73. {
  74. struct zfcp_adapter *adapter;
  75. struct zfcp_port *port, *p;
  76. struct zfcp_unit *unit, *u;
  77. LIST_HEAD(unit_remove_lh);
  78. LIST_HEAD(port_remove_lh);
  79. ccw_device_set_offline(ccw_device);
  80. mutex_lock(&zfcp_data.config_mutex);
  81. adapter = dev_get_drvdata(&ccw_device->dev);
  82. if (!adapter)
  83. goto out;
  84. mutex_unlock(&zfcp_data.config_mutex);
  85. cancel_work_sync(&adapter->scan_work);
  86. mutex_lock(&zfcp_data.config_mutex);
  87. /* this also removes the scsi devices, so call it first */
  88. zfcp_adapter_scsi_unregister(adapter);
  89. write_lock_irq(&zfcp_data.config_lock);
  90. list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
  91. list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
  92. list_move(&unit->list, &unit_remove_lh);
  93. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  94. &unit->status);
  95. }
  96. list_move(&port->list, &port_remove_lh);
  97. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  98. }
  99. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  100. write_unlock_irq(&zfcp_data.config_lock);
  101. list_for_each_entry_safe(port, p, &port_remove_lh, list) {
  102. list_for_each_entry_safe(unit, u, &unit_remove_lh, list)
  103. zfcp_unit_dequeue(unit);
  104. zfcp_port_dequeue(port);
  105. }
  106. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  107. zfcp_adapter_dequeue(adapter);
  108. out:
  109. mutex_unlock(&zfcp_data.config_mutex);
  110. }
  111. /**
  112. * zfcp_ccw_set_online - set_online function of zfcp driver
  113. * @ccw_device: pointer to belonging ccw device
  114. *
  115. * This function gets called by the common i/o layer and sets an
  116. * adapter into state online. The first call will allocate all
  117. * adapter resources that will be retained until the device is removed
  118. * via zfcp_ccw_remove.
  119. *
  120. * Setting an fcp device online means that it will be registered with
  121. * the SCSI stack, that the QDIO queues will be set up and that the
  122. * adapter will be opened.
  123. */
  124. static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
  125. {
  126. struct zfcp_adapter *adapter;
  127. int ret = 0;
  128. mutex_lock(&zfcp_data.config_mutex);
  129. adapter = dev_get_drvdata(&ccw_device->dev);
  130. if (!adapter) {
  131. ret = zfcp_adapter_enqueue(ccw_device);
  132. if (ret) {
  133. dev_err(&ccw_device->dev,
  134. "Setting up data structures for the "
  135. "FCP adapter failed\n");
  136. goto out;
  137. }
  138. adapter = dev_get_drvdata(&ccw_device->dev);
  139. }
  140. /* initialize request counter */
  141. BUG_ON(!zfcp_reqlist_isempty(adapter));
  142. adapter->req_no = 0;
  143. zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL,
  144. ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  145. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  146. "ccsonl2", NULL);
  147. zfcp_erp_wait(adapter);
  148. out:
  149. mutex_unlock(&zfcp_data.config_mutex);
  150. if (!ret)
  151. flush_work(&adapter->scan_work);
  152. return ret;
  153. }
  154. /**
  155. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  156. * @ccw_device: pointer to belonging ccw device
  157. *
  158. * This function gets called by the common i/o layer and sets an adapter
  159. * into state offline.
  160. */
  161. static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  162. {
  163. struct zfcp_adapter *adapter;
  164. mutex_lock(&zfcp_data.config_mutex);
  165. adapter = dev_get_drvdata(&ccw_device->dev);
  166. zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL);
  167. zfcp_erp_wait(adapter);
  168. mutex_unlock(&zfcp_data.config_mutex);
  169. return 0;
  170. }
  171. /**
  172. * zfcp_ccw_notify - ccw notify function
  173. * @ccw_device: pointer to belonging ccw device
  174. * @event: indicates if adapter was detached or attached
  175. *
  176. * This function gets called by the common i/o layer if an adapter has gone
  177. * or reappeared.
  178. */
  179. static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  180. {
  181. struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
  182. switch (event) {
  183. case CIO_GONE:
  184. dev_warn(&adapter->ccw_device->dev,
  185. "The FCP device has been detached\n");
  186. zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL);
  187. break;
  188. case CIO_NO_PATH:
  189. dev_warn(&adapter->ccw_device->dev,
  190. "The CHPID for the FCP device is offline\n");
  191. zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL);
  192. break;
  193. case CIO_OPER:
  194. dev_info(&adapter->ccw_device->dev,
  195. "The FCP device is operational again\n");
  196. zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL,
  197. ZFCP_STATUS_COMMON_RUNNING,
  198. ZFCP_SET);
  199. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  200. "ccnoti4", NULL);
  201. break;
  202. case CIO_BOXED:
  203. dev_warn(&adapter->ccw_device->dev, "The FCP device "
  204. "did not respond within the specified time\n");
  205. zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL);
  206. break;
  207. }
  208. return 1;
  209. }
  210. /**
  211. * zfcp_ccw_shutdown - handle shutdown from cio
  212. * @cdev: device for adapter to shutdown.
  213. */
  214. static void zfcp_ccw_shutdown(struct ccw_device *cdev)
  215. {
  216. struct zfcp_adapter *adapter;
  217. mutex_lock(&zfcp_data.config_mutex);
  218. adapter = dev_get_drvdata(&cdev->dev);
  219. if (!adapter)
  220. goto out;
  221. zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL);
  222. zfcp_erp_wait(adapter);
  223. zfcp_erp_thread_kill(adapter);
  224. out:
  225. mutex_unlock(&zfcp_data.config_mutex);
  226. }
  227. struct ccw_driver zfcp_ccw_driver = {
  228. .owner = THIS_MODULE,
  229. .name = "zfcp",
  230. .ids = zfcp_ccw_device_id,
  231. .probe = zfcp_ccw_probe,
  232. .remove = zfcp_ccw_remove,
  233. .set_online = zfcp_ccw_set_online,
  234. .set_offline = zfcp_ccw_set_offline,
  235. .notify = zfcp_ccw_notify,
  236. .shutdown = zfcp_ccw_shutdown,
  237. .freeze = zfcp_ccw_suspend,
  238. .thaw = zfcp_ccw_activate,
  239. .restore = zfcp_ccw_activate,
  240. };
  241. /**
  242. * zfcp_ccw_register - ccw register function
  243. *
  244. * Registers the driver at the common i/o layer. This function will be called
  245. * at module load time/system start.
  246. */
  247. int __init zfcp_ccw_register(void)
  248. {
  249. return ccw_driver_register(&zfcp_ccw_driver);
  250. }