zfcp_ccw.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. mutex_unlock(&zfcp_data.config_mutex);
  83. if (!adapter)
  84. return;
  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(&adapter->port_list_lock);
  90. list_for_each_entry_safe(port, p, &adapter->port_list, list) {
  91. write_lock(&port->unit_list_lock);
  92. list_for_each_entry_safe(unit, u, &port->unit_list, list) {
  93. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  94. &unit->status);
  95. list_move(&unit->list, &unit_remove_lh);
  96. }
  97. write_unlock(&port->unit_list_lock);
  98. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  99. list_move(&port->list, &port_remove_lh);
  100. }
  101. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  102. write_unlock_irq(&adapter->port_list_lock);
  103. mutex_unlock(&zfcp_data.config_mutex);
  104. list_for_each_entry_safe(unit, u, &unit_remove_lh, list)
  105. zfcp_device_unregister(&unit->sysfs_device,
  106. &zfcp_sysfs_unit_attrs);
  107. list_for_each_entry_safe(port, p, &port_remove_lh, list)
  108. zfcp_device_unregister(&port->sysfs_device,
  109. &zfcp_sysfs_port_attrs);
  110. kref_put(&adapter->ref, zfcp_adapter_release);
  111. }
  112. /**
  113. * zfcp_ccw_set_online - set_online function of zfcp driver
  114. * @ccw_device: pointer to belonging ccw device
  115. *
  116. * This function gets called by the common i/o layer and sets an
  117. * adapter into state online. The first call will allocate all
  118. * adapter resources that will be retained until the device is removed
  119. * via zfcp_ccw_remove.
  120. *
  121. * Setting an fcp device online means that it will be registered with
  122. * the SCSI stack, that the QDIO queues will be set up and that the
  123. * adapter will be opened.
  124. */
  125. static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
  126. {
  127. struct zfcp_adapter *adapter;
  128. int ret = 0;
  129. mutex_lock(&zfcp_data.config_mutex);
  130. adapter = dev_get_drvdata(&ccw_device->dev);
  131. if (!adapter) {
  132. ret = zfcp_adapter_enqueue(ccw_device);
  133. if (ret) {
  134. dev_err(&ccw_device->dev,
  135. "Setting up data structures for the "
  136. "FCP adapter failed\n");
  137. goto out;
  138. }
  139. adapter = dev_get_drvdata(&ccw_device->dev);
  140. }
  141. /* initialize request counter */
  142. BUG_ON(!zfcp_reqlist_isempty(adapter));
  143. adapter->req_no = 0;
  144. zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL,
  145. ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  146. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  147. "ccsonl2", NULL);
  148. zfcp_erp_wait(adapter);
  149. out:
  150. mutex_unlock(&zfcp_data.config_mutex);
  151. if (!ret)
  152. flush_work(&adapter->scan_work);
  153. return ret;
  154. }
  155. /**
  156. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  157. * @ccw_device: pointer to belonging ccw device
  158. *
  159. * This function gets called by the common i/o layer and sets an adapter
  160. * into state offline.
  161. */
  162. static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  163. {
  164. struct zfcp_adapter *adapter;
  165. mutex_lock(&zfcp_data.config_mutex);
  166. adapter = dev_get_drvdata(&ccw_device->dev);
  167. zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL);
  168. zfcp_erp_wait(adapter);
  169. mutex_unlock(&zfcp_data.config_mutex);
  170. return 0;
  171. }
  172. /**
  173. * zfcp_ccw_notify - ccw notify function
  174. * @ccw_device: pointer to belonging ccw device
  175. * @event: indicates if adapter was detached or attached
  176. *
  177. * This function gets called by the common i/o layer if an adapter has gone
  178. * or reappeared.
  179. */
  180. static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  181. {
  182. struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
  183. switch (event) {
  184. case CIO_GONE:
  185. dev_warn(&adapter->ccw_device->dev,
  186. "The FCP device has been detached\n");
  187. zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti1", NULL);
  188. break;
  189. case CIO_NO_PATH:
  190. dev_warn(&adapter->ccw_device->dev,
  191. "The CHPID for the FCP device is offline\n");
  192. zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti2", NULL);
  193. break;
  194. case CIO_OPER:
  195. dev_info(&adapter->ccw_device->dev,
  196. "The FCP device is operational again\n");
  197. zfcp_erp_modify_adapter_status(adapter, "ccnoti3", NULL,
  198. ZFCP_STATUS_COMMON_RUNNING,
  199. ZFCP_SET);
  200. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  201. "ccnoti4", NULL);
  202. break;
  203. case CIO_BOXED:
  204. dev_warn(&adapter->ccw_device->dev, "The FCP device "
  205. "did not respond within the specified time\n");
  206. zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", NULL);
  207. break;
  208. }
  209. return 1;
  210. }
  211. /**
  212. * zfcp_ccw_shutdown - handle shutdown from cio
  213. * @cdev: device for adapter to shutdown.
  214. */
  215. static void zfcp_ccw_shutdown(struct ccw_device *cdev)
  216. {
  217. struct zfcp_adapter *adapter;
  218. mutex_lock(&zfcp_data.config_mutex);
  219. adapter = dev_get_drvdata(&cdev->dev);
  220. if (!adapter)
  221. goto out;
  222. zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL);
  223. zfcp_erp_wait(adapter);
  224. zfcp_erp_thread_kill(adapter);
  225. out:
  226. mutex_unlock(&zfcp_data.config_mutex);
  227. }
  228. struct ccw_driver zfcp_ccw_driver = {
  229. .owner = THIS_MODULE,
  230. .name = "zfcp",
  231. .ids = zfcp_ccw_device_id,
  232. .probe = zfcp_ccw_probe,
  233. .remove = zfcp_ccw_remove,
  234. .set_online = zfcp_ccw_set_online,
  235. .set_offline = zfcp_ccw_set_offline,
  236. .notify = zfcp_ccw_notify,
  237. .shutdown = zfcp_ccw_shutdown,
  238. .freeze = zfcp_ccw_suspend,
  239. .thaw = zfcp_ccw_activate,
  240. .restore = zfcp_ccw_activate,
  241. };
  242. /**
  243. * zfcp_ccw_register - ccw register function
  244. *
  245. * Registers the driver at the common i/o layer. This function will be called
  246. * at module load time/system start.
  247. */
  248. int __init zfcp_ccw_register(void)
  249. {
  250. return ccw_driver_register(&zfcp_ccw_driver);
  251. }