zfcp_ccw.c 6.9 KB

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