iseries_vscsi.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* ------------------------------------------------------------
  2. * iSeries_vscsi.c
  3. * (C) Copyright IBM Corporation 1994, 2003
  4. * Authors: Colin DeVilbiss (devilbis@us.ibm.com)
  5. * Santiago Leon (santil@us.ibm.com)
  6. * Dave Boutcher (sleddog@us.ibm.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. * USA
  22. *
  23. * ------------------------------------------------------------
  24. * iSeries-specific functions of the SCSI host adapter for Virtual I/O devices
  25. *
  26. * This driver allows the Linux SCSI peripheral drivers to directly
  27. * access devices in the hosting partition, either on an iSeries
  28. * hypervisor system or a converged hypervisor system.
  29. */
  30. #include <asm/iseries/vio.h>
  31. #include <asm/iseries/hv_lp_event.h>
  32. #include <asm/iseries/hv_types.h>
  33. #include <asm/iseries/hv_lp_config.h>
  34. #include <asm/vio.h>
  35. #include <linux/device.h>
  36. #include "ibmvscsi.h"
  37. /* global variables */
  38. static struct ibmvscsi_host_data *single_host_data;
  39. /* ------------------------------------------------------------
  40. * Routines for direct interpartition interaction
  41. */
  42. struct srp_lp_event {
  43. struct HvLpEvent lpevt; /* 0x00-0x17 */
  44. u32 reserved1; /* 0x18-0x1B; unused */
  45. u16 version; /* 0x1C-0x1D; unused */
  46. u16 subtype_rc; /* 0x1E-0x1F; unused */
  47. struct viosrp_crq crq; /* 0x20-0x3F */
  48. };
  49. /**
  50. * standard interface for handling logical partition events.
  51. */
  52. static void iseriesvscsi_handle_event(struct HvLpEvent *lpevt)
  53. {
  54. struct srp_lp_event *evt = (struct srp_lp_event *)lpevt;
  55. if (!evt) {
  56. printk(KERN_ERR "ibmvscsi: received null event\n");
  57. return;
  58. }
  59. if (single_host_data == NULL) {
  60. printk(KERN_ERR
  61. "ibmvscsi: received event, no adapter present\n");
  62. return;
  63. }
  64. ibmvscsi_handle_crq(&evt->crq, single_host_data);
  65. }
  66. /* ------------------------------------------------------------
  67. * Routines for driver initialization
  68. */
  69. static int iseriesvscsi_init_crq_queue(struct crq_queue *queue,
  70. struct ibmvscsi_host_data *hostdata,
  71. int max_requests)
  72. {
  73. int rc;
  74. single_host_data = hostdata;
  75. rc = viopath_open(viopath_hostLp, viomajorsubtype_scsi, max_requests);
  76. if (rc < 0) {
  77. printk("viopath_open failed with rc %d in open_event_path\n",
  78. rc);
  79. goto viopath_open_failed;
  80. }
  81. rc = vio_setHandler(viomajorsubtype_scsi, iseriesvscsi_handle_event);
  82. if (rc < 0) {
  83. printk("vio_setHandler failed with rc %d in open_event_path\n",
  84. rc);
  85. goto vio_setHandler_failed;
  86. }
  87. return 0;
  88. vio_setHandler_failed:
  89. viopath_close(viopath_hostLp, viomajorsubtype_scsi, max_requests);
  90. viopath_open_failed:
  91. return -1;
  92. }
  93. static void iseriesvscsi_release_crq_queue(struct crq_queue *queue,
  94. struct ibmvscsi_host_data *hostdata,
  95. int max_requests)
  96. {
  97. vio_clearHandler(viomajorsubtype_scsi);
  98. viopath_close(viopath_hostLp, viomajorsubtype_scsi, max_requests);
  99. }
  100. /**
  101. * reset_crq_queue: - resets a crq after a failure
  102. * @queue: crq_queue to initialize and register
  103. * @hostdata: ibmvscsi_host_data of host
  104. *
  105. * no-op for iSeries
  106. */
  107. static int iseriesvscsi_reset_crq_queue(struct crq_queue *queue,
  108. struct ibmvscsi_host_data *hostdata)
  109. {
  110. return 0;
  111. }
  112. /**
  113. * reenable_crq_queue: - reenables a crq after a failure
  114. * @queue: crq_queue to initialize and register
  115. * @hostdata: ibmvscsi_host_data of host
  116. *
  117. * no-op for iSeries
  118. */
  119. static int iseriesvscsi_reenable_crq_queue(struct crq_queue *queue,
  120. struct ibmvscsi_host_data *hostdata)
  121. {
  122. return 0;
  123. }
  124. /**
  125. * iseriesvscsi_send_crq: - Send a CRQ
  126. * @hostdata: the adapter
  127. * @word1: the first 64 bits of the data
  128. * @word2: the second 64 bits of the data
  129. */
  130. static int iseriesvscsi_send_crq(struct ibmvscsi_host_data *hostdata,
  131. u64 word1, u64 word2)
  132. {
  133. single_host_data = hostdata;
  134. return HvCallEvent_signalLpEventFast(viopath_hostLp,
  135. HvLpEvent_Type_VirtualIo,
  136. viomajorsubtype_scsi,
  137. HvLpEvent_AckInd_NoAck,
  138. HvLpEvent_AckType_ImmediateAck,
  139. viopath_sourceinst(viopath_hostLp),
  140. viopath_targetinst(viopath_hostLp),
  141. 0,
  142. VIOVERSION << 16, word1, word2, 0,
  143. 0);
  144. }
  145. struct ibmvscsi_ops iseriesvscsi_ops = {
  146. .init_crq_queue = iseriesvscsi_init_crq_queue,
  147. .release_crq_queue = iseriesvscsi_release_crq_queue,
  148. .reset_crq_queue = iseriesvscsi_reset_crq_queue,
  149. .reenable_crq_queue = iseriesvscsi_reenable_crq_queue,
  150. .send_crq = iseriesvscsi_send_crq,
  151. };