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