zfcp_ccw.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. ccw_device_set_offline(ccw_device);
  47. down(&zfcp_data.config_sema);
  48. adapter = dev_get_drvdata(&ccw_device->dev);
  49. write_lock_irq(&zfcp_data.config_lock);
  50. list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
  51. list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
  52. list_move(&unit->list, &port->unit_remove_lh);
  53. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  54. &unit->status);
  55. }
  56. list_move(&port->list, &adapter->port_remove_lh);
  57. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  58. }
  59. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  60. write_unlock_irq(&zfcp_data.config_lock);
  61. list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
  62. list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
  63. if (atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED,
  64. &unit->status))
  65. scsi_remove_device(unit->device);
  66. zfcp_unit_dequeue(unit);
  67. }
  68. zfcp_port_dequeue(port);
  69. }
  70. zfcp_adapter_wait(adapter);
  71. zfcp_adapter_dequeue(adapter);
  72. up(&zfcp_data.config_sema);
  73. }
  74. /**
  75. * zfcp_ccw_set_online - set_online function of zfcp driver
  76. * @ccw_device: pointer to belonging ccw device
  77. *
  78. * This function gets called by the common i/o layer and sets an adapter
  79. * into state online. Setting an fcp device online means that it will be
  80. * registered with the SCSI stack, that the QDIO queues will be set up
  81. * and that the adapter will be opened (asynchronously).
  82. */
  83. static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
  84. {
  85. struct zfcp_adapter *adapter;
  86. int retval;
  87. down(&zfcp_data.config_sema);
  88. adapter = dev_get_drvdata(&ccw_device->dev);
  89. retval = zfcp_erp_thread_setup(adapter);
  90. if (retval)
  91. goto out;
  92. retval = zfcp_adapter_scsi_register(adapter);
  93. if (retval)
  94. goto out_scsi_register;
  95. /* initialize request counter */
  96. BUG_ON(!zfcp_reqlist_isempty(adapter));
  97. adapter->req_no = 0;
  98. zfcp_erp_modify_adapter_status(adapter, 10, NULL,
  99. ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  100. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 85,
  101. NULL);
  102. zfcp_erp_wait(adapter);
  103. goto out;
  104. out_scsi_register:
  105. zfcp_erp_thread_kill(adapter);
  106. out:
  107. up(&zfcp_data.config_sema);
  108. return retval;
  109. }
  110. /**
  111. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  112. * @ccw_device: pointer to belonging ccw device
  113. *
  114. * This function gets called by the common i/o layer and sets an adapter
  115. * into state offline.
  116. */
  117. static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  118. {
  119. struct zfcp_adapter *adapter;
  120. down(&zfcp_data.config_sema);
  121. adapter = dev_get_drvdata(&ccw_device->dev);
  122. zfcp_erp_adapter_shutdown(adapter, 0, 86, NULL);
  123. zfcp_erp_wait(adapter);
  124. zfcp_erp_thread_kill(adapter);
  125. up(&zfcp_data.config_sema);
  126. return 0;
  127. }
  128. /**
  129. * zfcp_ccw_notify - ccw notify function
  130. * @ccw_device: pointer to belonging ccw device
  131. * @event: indicates if adapter was detached or attached
  132. *
  133. * This function gets called by the common i/o layer if an adapter has gone
  134. * or reappeared.
  135. */
  136. static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  137. {
  138. struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
  139. switch (event) {
  140. case CIO_GONE:
  141. dev_warn(&adapter->ccw_device->dev,
  142. "The FCP device has been detached\n");
  143. zfcp_erp_adapter_shutdown(adapter, 0, 87, NULL);
  144. break;
  145. case CIO_NO_PATH:
  146. dev_warn(&adapter->ccw_device->dev,
  147. "The CHPID for the FCP device is offline\n");
  148. zfcp_erp_adapter_shutdown(adapter, 0, 88, NULL);
  149. break;
  150. case CIO_OPER:
  151. dev_info(&adapter->ccw_device->dev,
  152. "The FCP device is operational again\n");
  153. zfcp_erp_modify_adapter_status(adapter, 11, NULL,
  154. ZFCP_STATUS_COMMON_RUNNING,
  155. ZFCP_SET);
  156. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  157. 89, NULL);
  158. break;
  159. }
  160. return 1;
  161. }
  162. /**
  163. * zfcp_ccw_shutdown - handle shutdown from cio
  164. * @cdev: device for adapter to shutdown.
  165. */
  166. static void zfcp_ccw_shutdown(struct ccw_device *cdev)
  167. {
  168. struct zfcp_adapter *adapter;
  169. down(&zfcp_data.config_sema);
  170. adapter = dev_get_drvdata(&cdev->dev);
  171. zfcp_erp_adapter_shutdown(adapter, 0, 90, NULL);
  172. zfcp_erp_wait(adapter);
  173. up(&zfcp_data.config_sema);
  174. }
  175. static struct ccw_device_id zfcp_ccw_device_id[] = {
  176. { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
  177. { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x4) }, /* priv. */
  178. {},
  179. };
  180. MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
  181. static struct ccw_driver zfcp_ccw_driver = {
  182. .owner = THIS_MODULE,
  183. .name = "zfcp",
  184. .ids = zfcp_ccw_device_id,
  185. .probe = zfcp_ccw_probe,
  186. .remove = zfcp_ccw_remove,
  187. .set_online = zfcp_ccw_set_online,
  188. .set_offline = zfcp_ccw_set_offline,
  189. .notify = zfcp_ccw_notify,
  190. .shutdown = zfcp_ccw_shutdown,
  191. };
  192. /**
  193. * zfcp_ccw_register - ccw register function
  194. *
  195. * Registers the driver at the common i/o layer. This function will be called
  196. * at module load time/system start.
  197. */
  198. int __init zfcp_ccw_register(void)
  199. {
  200. return ccw_driver_register(&zfcp_ccw_driver);
  201. }