zfcp_ccw.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * zfcp device driver
  3. *
  4. * Registration and callback for the s390 common I/O layer.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  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 (unit->device)
  68. scsi_remove_device(unit->device);
  69. zfcp_unit_dequeue(unit);
  70. }
  71. zfcp_port_dequeue(port);
  72. }
  73. wait_event(adapter->remove_wq, atomic_read(&adapter->refcount) == 0);
  74. zfcp_adapter_dequeue(adapter);
  75. up(&zfcp_data.config_sema);
  76. }
  77. /**
  78. * zfcp_ccw_set_online - set_online function of zfcp driver
  79. * @ccw_device: pointer to belonging ccw device
  80. *
  81. * This function gets called by the common i/o layer and sets an adapter
  82. * into state online. Setting an fcp device online means that it will be
  83. * registered with the SCSI stack, that the QDIO queues will be set up
  84. * and that the adapter will be opened (asynchronously).
  85. */
  86. static int zfcp_ccw_set_online(struct ccw_device *ccw_device)
  87. {
  88. struct zfcp_adapter *adapter;
  89. int retval;
  90. down(&zfcp_data.config_sema);
  91. adapter = dev_get_drvdata(&ccw_device->dev);
  92. retval = zfcp_erp_thread_setup(adapter);
  93. if (retval)
  94. goto out;
  95. /* initialize request counter */
  96. BUG_ON(!zfcp_reqlist_isempty(adapter));
  97. adapter->req_no = 0;
  98. zfcp_fc_nameserver_init(adapter);
  99. zfcp_erp_modify_adapter_status(adapter, "ccsonl1", NULL,
  100. ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
  101. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  102. "ccsonl2", 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, "ccsoff1", 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, "ccnoti1", 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, "ccnoti2", 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, "ccnoti3", NULL,
  155. ZFCP_STATUS_COMMON_RUNNING,
  156. ZFCP_SET);
  157. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  158. "ccnoti4", NULL);
  159. break;
  160. case CIO_BOXED:
  161. dev_warn(&adapter->ccw_device->dev,
  162. "The ccw device did not respond in time.\n");
  163. zfcp_erp_adapter_shutdown(adapter, 0, "ccnoti5", 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, "ccshut1", 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. }