zfcp_ccw.c 7.2 KB

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