zfcp_ccw.c 6.8 KB

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