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. "Setup of data structures failed.\n");
  26. retval = -EINVAL;
  27. }
  28. up(&zfcp_data.config_sema);
  29. return retval;
  30. }
  31. /**
  32. * zfcp_ccw_remove - remove function of zfcp driver
  33. * @ccw_device: pointer to belonging ccw device
  34. *
  35. * This function gets called by the common i/o layer and removes an adapter
  36. * from the system. Task of this function is to get rid of all units and
  37. * ports that belong to this adapter. And in addition all resources of this
  38. * adapter will be freed too.
  39. */
  40. static void zfcp_ccw_remove(struct ccw_device *ccw_device)
  41. {
  42. struct zfcp_adapter *adapter;
  43. struct zfcp_port *port, *p;
  44. struct zfcp_unit *unit, *u;
  45. ccw_device_set_offline(ccw_device);
  46. down(&zfcp_data.config_sema);
  47. adapter = dev_get_drvdata(&ccw_device->dev);
  48. write_lock_irq(&zfcp_data.config_lock);
  49. list_for_each_entry_safe(port, p, &adapter->port_list_head, list) {
  50. list_for_each_entry_safe(unit, u, &port->unit_list_head, list) {
  51. list_move(&unit->list, &port->unit_remove_lh);
  52. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE,
  53. &unit->status);
  54. }
  55. list_move(&port->list, &adapter->port_remove_lh);
  56. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status);
  57. }
  58. atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &adapter->status);
  59. write_unlock_irq(&zfcp_data.config_lock);
  60. list_for_each_entry_safe(port, p, &adapter->port_remove_lh, list) {
  61. list_for_each_entry_safe(unit, u, &port->unit_remove_lh, list) {
  62. if (atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED,
  63. &unit->status))
  64. scsi_remove_device(unit->device);
  65. zfcp_unit_dequeue(unit);
  66. }
  67. zfcp_port_dequeue(port);
  68. }
  69. zfcp_adapter_wait(adapter);
  70. zfcp_adapter_dequeue(adapter);
  71. up(&zfcp_data.config_sema);
  72. }
  73. /**
  74. * zfcp_ccw_set_online - set_online function of zfcp driver
  75. * @ccw_device: pointer to belonging ccw device
  76. *
  77. * This function gets called by the common i/o layer and sets an adapter
  78. * into state online. Setting an fcp device online means that it will be
  79. * registered with the SCSI stack, that the QDIO queues will be set up
  80. * and that the adapter will be opened (asynchronously).
  81. */
  82. static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
  83. {
  84. struct zfcp_adapter *adapter;
  85. int retval;
  86. down(&zfcp_data.config_sema);
  87. adapter = dev_get_drvdata(&ccw_device->dev);
  88. retval = zfcp_erp_thread_setup(adapter);
  89. if (retval)
  90. goto out;
  91. retval = zfcp_adapter_scsi_register(adapter);
  92. if (retval)
  93. goto out_scsi_register;
  94. /* initialize request counter */
  95. BUG_ON(!zfcp_reqlist_isempty(adapter));
  96. adapter->req_no = 0;
  97. zfcp_erp_modify_adapter_status(adapter, 10, NULL,
  98. ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  99. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 85,
  100. NULL);
  101. zfcp_erp_wait(adapter);
  102. goto out;
  103. out_scsi_register:
  104. zfcp_erp_thread_kill(adapter);
  105. out:
  106. up(&zfcp_data.config_sema);
  107. return retval;
  108. }
  109. /**
  110. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  111. * @ccw_device: pointer to belonging ccw device
  112. *
  113. * This function gets called by the common i/o layer and sets an adapter
  114. * into state offline.
  115. */
  116. static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  117. {
  118. struct zfcp_adapter *adapter;
  119. down(&zfcp_data.config_sema);
  120. adapter = dev_get_drvdata(&ccw_device->dev);
  121. zfcp_erp_adapter_shutdown(adapter, 0, 86, NULL);
  122. zfcp_erp_wait(adapter);
  123. zfcp_erp_thread_kill(adapter);
  124. up(&zfcp_data.config_sema);
  125. return 0;
  126. }
  127. /**
  128. * zfcp_ccw_notify - ccw notify function
  129. * @ccw_device: pointer to belonging ccw device
  130. * @event: indicates if adapter was detached or attached
  131. *
  132. * This function gets called by the common i/o layer if an adapter has gone
  133. * or reappeared.
  134. */
  135. static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  136. {
  137. struct zfcp_adapter *adapter;
  138. down(&zfcp_data.config_sema);
  139. adapter = dev_get_drvdata(&ccw_device->dev);
  140. switch (event) {
  141. case CIO_GONE:
  142. dev_warn(&adapter->ccw_device->dev, "device gone\n");
  143. zfcp_erp_adapter_shutdown(adapter, 0, 87, NULL);
  144. break;
  145. case CIO_NO_PATH:
  146. dev_warn(&adapter->ccw_device->dev, "no path\n");
  147. zfcp_erp_adapter_shutdown(adapter, 0, 88, NULL);
  148. break;
  149. case CIO_OPER:
  150. dev_info(&adapter->ccw_device->dev, "operational again\n");
  151. zfcp_erp_modify_adapter_status(adapter, 11, NULL,
  152. ZFCP_STATUS_COMMON_RUNNING,
  153. ZFCP_SET);
  154. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  155. 89, NULL);
  156. break;
  157. }
  158. zfcp_erp_wait(adapter);
  159. up(&zfcp_data.config_sema);
  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. }