zfcp_ccw.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. goto out;
  106. out_scsi_register:
  107. zfcp_erp_thread_kill(adapter);
  108. out:
  109. up(&zfcp_data.config_sema);
  110. return retval;
  111. }
  112. /**
  113. * zfcp_ccw_set_offline - set_offline function of zfcp driver
  114. * @ccw_device: pointer to belonging ccw device
  115. *
  116. * This function gets called by the common i/o layer and sets an adapter
  117. * into state offline.
  118. */
  119. static int zfcp_ccw_set_offline(struct ccw_device *ccw_device)
  120. {
  121. struct zfcp_adapter *adapter;
  122. down(&zfcp_data.config_sema);
  123. adapter = dev_get_drvdata(&ccw_device->dev);
  124. zfcp_erp_adapter_shutdown(adapter, 0, 86, NULL);
  125. zfcp_erp_wait(adapter);
  126. zfcp_erp_thread_kill(adapter);
  127. up(&zfcp_data.config_sema);
  128. return 0;
  129. }
  130. /**
  131. * zfcp_ccw_notify - ccw notify function
  132. * @ccw_device: pointer to belonging ccw device
  133. * @event: indicates if adapter was detached or attached
  134. *
  135. * This function gets called by the common i/o layer if an adapter has gone
  136. * or reappeared.
  137. */
  138. static int zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
  139. {
  140. struct zfcp_adapter *adapter = dev_get_drvdata(&ccw_device->dev);
  141. switch (event) {
  142. case CIO_GONE:
  143. dev_warn(&adapter->ccw_device->dev,
  144. "The FCP device has been detached\n");
  145. zfcp_erp_adapter_shutdown(adapter, 0, 87, NULL);
  146. break;
  147. case CIO_NO_PATH:
  148. dev_warn(&adapter->ccw_device->dev,
  149. "The CHPID for the FCP device is offline\n");
  150. zfcp_erp_adapter_shutdown(adapter, 0, 88, NULL);
  151. break;
  152. case CIO_OPER:
  153. dev_info(&adapter->ccw_device->dev,
  154. "The FCP device is operational again\n");
  155. zfcp_erp_modify_adapter_status(adapter, 11, NULL,
  156. ZFCP_STATUS_COMMON_RUNNING,
  157. ZFCP_SET);
  158. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  159. 89, NULL);
  160. break;
  161. }
  162. return 1;
  163. }
  164. /**
  165. * zfcp_ccw_shutdown - handle shutdown from cio
  166. * @cdev: device for adapter to shutdown.
  167. */
  168. static void zfcp_ccw_shutdown(struct ccw_device *cdev)
  169. {
  170. struct zfcp_adapter *adapter;
  171. down(&zfcp_data.config_sema);
  172. adapter = dev_get_drvdata(&cdev->dev);
  173. zfcp_erp_adapter_shutdown(adapter, 0, 90, NULL);
  174. zfcp_erp_wait(adapter);
  175. up(&zfcp_data.config_sema);
  176. }
  177. static struct ccw_device_id zfcp_ccw_device_id[] = {
  178. { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x3) },
  179. { CCW_DEVICE_DEVTYPE(0x1731, 0x3, 0x1732, 0x4) }, /* priv. */
  180. {},
  181. };
  182. MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
  183. static struct ccw_driver zfcp_ccw_driver = {
  184. .owner = THIS_MODULE,
  185. .name = "zfcp",
  186. .ids = zfcp_ccw_device_id,
  187. .probe = zfcp_ccw_probe,
  188. .remove = zfcp_ccw_remove,
  189. .set_online = zfcp_ccw_set_online,
  190. .set_offline = zfcp_ccw_set_offline,
  191. .notify = zfcp_ccw_notify,
  192. .shutdown = zfcp_ccw_shutdown,
  193. };
  194. /**
  195. * zfcp_ccw_register - ccw register function
  196. *
  197. * Registers the driver at the common i/o layer. This function will be called
  198. * at module load time/system start.
  199. */
  200. int __init zfcp_ccw_register(void)
  201. {
  202. return ccw_driver_register(&zfcp_ccw_driver);
  203. }
  204. /**
  205. * zfcp_get_adapter_by_busid - find zfcp_adapter struct
  206. * @busid: bus id string of zfcp adapter to find
  207. */
  208. struct zfcp_adapter *zfcp_get_adapter_by_busid(char *busid)
  209. {
  210. struct ccw_device *ccw_device;
  211. struct zfcp_adapter *adapter = NULL;
  212. ccw_device = get_ccwdev_by_busid(&zfcp_ccw_driver, busid);
  213. if (ccw_device) {
  214. adapter = dev_get_drvdata(&ccw_device->dev);
  215. put_device(&ccw_device->dev);
  216. }
  217. return adapter;
  218. }