zfcp_ccw.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. write_lock_irq(&zfcp_data.config_lock);
  85. list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
  86. list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
  87. list_move(&unit->list, &unit_remove_lh);
  88. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  89. &unit->status);
  90. }
  91. list_move(&port->list, &port_remove_lh);
  92. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  93. }
  94. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  95. write_unlock_irq(&zfcp_data.config_lock);
  96. list_for_each_entry_safe(port, p, &port_remove_lh, list) {
  97. list_for_each_entry_safe(unit, u, &unit_remove_lh, list) {
  98. if (unit->device)
  99. scsi_remove_device(unit->device);
  100. zfcp_unit_dequeue(unit);
  101. }
  102. zfcp_port_dequeue(port);
  103. }
  104. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  105. zfcp_adapter_dequeue(adapter);
  106. out:
  107. mutex_unlock(&zfcp_data.config_mutex);
  108. }
  109. /**
  110. * zfcp_ccw_set_online - set_online function of zfcp driver
  111. * @ccw_device: pointer to belonging ccw device
  112. *
  113. * This function gets called by the common i/o layer and sets an
  114. * adapter into state online. The first call will allocate all
  115. * adapter resources that will be retained until the device is removed
  116. * via zfcp_ccw_remove.
  117. *
  118. * Setting an fcp device online means that it will be registered with
  119. * the SCSI stack, that the QDIO queues will be set up and that the
  120. * adapter will be opened.
  121. */
  122. static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
  123. {
  124. struct zfcp_adapter *adapter;
  125. int ret = 0;
  126. mutex_lock(&zfcp_data.config_mutex);
  127. adapter = dev_get_drvdata(&ccw_device->dev);
  128. if (!adapter) {
  129. ret = zfcp_adapter_enqueue(ccw_device);
  130. if (ret) {
  131. dev_err(&ccw_device->dev,
  132. "Setting up data structures for the "
  133. "FCP adapter failed\n");
  134. goto out;
  135. }
  136. adapter = dev_get_drvdata(&ccw_device->dev);
  137. }
  138. /* initialize request counter */
  139. BUG_ON(!zfcp_reqlist_isempty(adapter));
  140. adapter->req_no = 0;
  141. zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL,
  142. ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  143. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  144. "ccsonl2", NULL);
  145. zfcp_erp_wait(adapter);
  146. out:
  147. mutex_unlock(&zfcp_data.config_mutex);
  148. if (!ret)
  149. flush_work(&adapter->scan_work);
  150. return ret;
  151. }
  152. /**
  153. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  154. * @ccw_device: pointer to belonging ccw device
  155. *
  156. * This function gets called by the common i/o layer and sets an adapter
  157. * into state offline.
  158. */
  159. static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  160. {
  161. struct zfcp_adapter *adapter;
  162. mutex_lock(&zfcp_data.config_mutex);
  163. adapter = dev_get_drvdata(&ccw_device->dev);
  164. if (!adapter)
  165. goto out;
  166. zfcp_erp_adapter_shutdown(adapter, 0, "ccsoff1", NULL);
  167. zfcp_erp_wait(adapter);
  168. mutex_unlock(&zfcp_data.config_mutex);
  169. out:
  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. zfcp_erp_adapter_shutdown(adapter, 0, "ccshut1", NULL);
  221. zfcp_erp_wait(adapter);
  222. zfcp_erp_thread_kill(adapter);
  223. mutex_unlock(&zfcp_data.config_mutex);
  224. }
  225. static struct ccw_driver zfcp_ccw_driver = {
  226. .owner = THIS_MODULE,
  227. .name = "zfcp",
  228. .ids = zfcp_ccw_device_id,
  229. .probe = zfcp_ccw_probe,
  230. .remove = zfcp_ccw_remove,
  231. .set_online = zfcp_ccw_set_online,
  232. .set_offline = zfcp_ccw_set_offline,
  233. .notify = zfcp_ccw_notify,
  234. .shutdown = zfcp_ccw_shutdown,
  235. .freeze = zfcp_ccw_suspend,
  236. .thaw = zfcp_ccw_activate,
  237. .restore = zfcp_ccw_activate,
  238. };
  239. /**
  240. * zfcp_ccw_register - ccw register function
  241. *
  242. * Registers the driver at the common i/o layer. This function will be called
  243. * at module load time/system start.
  244. */
  245. int __init zfcp_ccw_register(void)
  246. {
  247. return ccw_driver_register(&zfcp_ccw_driver);
  248. }
  249. /**
  250. * zfcp_get_adapter_by_busid - find zfcp_adapter struct
  251. * @busid: bus id string of zfcp adapter to find
  252. */
  253. struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid)
  254. {
  255. struct ccw_device *ccw_device;
  256. struct zfcp_adapter *adapter = NULL;
  257. ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
  258. if (ccw_device) {
  259. adapter = dev_get_drvdata(&ccw_device->dev);
  260. put_device(&ccw_device->dev);
  261. }
  262. return adapter;
  263. }