zfcp_ccw.c 6.8 KB

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