zfcp_ccw.c 7.0 KB

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