c2_intr.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
  3. * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include "c2.h"
  34. #include <rdma/iw_cm.h>
  35. #include "c2_vq.h"
  36. static void handle_mq(struct c2_dev *c2dev, u32 index);
  37. static void handle_vq(struct c2_dev *c2dev, u32 mq_index);
  38. /*
  39. * Handle RNIC interrupts
  40. */
  41. void c2_rnic_interrupt(struct c2_dev *c2dev)
  42. {
  43. unsigned int mq_index;
  44. while (c2dev->hints_read != be16_to_cpu(*c2dev->hint_count)) {
  45. mq_index = readl(c2dev->regs + PCI_BAR0_HOST_HINT);
  46. if (mq_index & 0x80000000) {
  47. break;
  48. }
  49. c2dev->hints_read++;
  50. handle_mq(c2dev, mq_index);
  51. }
  52. }
  53. /*
  54. * Top level MQ handler
  55. */
  56. static void handle_mq(struct c2_dev *c2dev, u32 mq_index)
  57. {
  58. if (c2dev->qptr_array[mq_index] == NULL) {
  59. pr_debug("handle_mq: stray activity for mq_index=%d\n",
  60. mq_index);
  61. return;
  62. }
  63. switch (mq_index) {
  64. case (0):
  65. /*
  66. * An index of 0 in the activity queue
  67. * indicates the req vq now has messages
  68. * available...
  69. *
  70. * Wake up any waiters waiting on req VQ
  71. * message availability.
  72. */
  73. wake_up(&c2dev->req_vq_wo);
  74. break;
  75. case (1):
  76. handle_vq(c2dev, mq_index);
  77. break;
  78. case (2):
  79. /* We have to purge the VQ in case there are pending
  80. * accept reply requests that would result in the
  81. * generation of an ESTABLISHED event. If we don't
  82. * generate these first, a CLOSE event could end up
  83. * being delivered before the ESTABLISHED event.
  84. */
  85. handle_vq(c2dev, 1);
  86. c2_ae_event(c2dev, mq_index);
  87. break;
  88. default:
  89. /* There is no event synchronization between CQ events
  90. * and AE or CM events. In fact, CQE could be
  91. * delivered for all of the I/O up to and including the
  92. * FLUSH for a peer disconenct prior to the ESTABLISHED
  93. * event being delivered to the app. The reason for this
  94. * is that CM events are delivered on a thread, while AE
  95. * and CM events are delivered on interrupt context.
  96. */
  97. c2_cq_event(c2dev, mq_index);
  98. break;
  99. }
  100. return;
  101. }
  102. /*
  103. * Handles verbs WR replies.
  104. */
  105. static void handle_vq(struct c2_dev *c2dev, u32 mq_index)
  106. {
  107. void *adapter_msg, *reply_msg;
  108. struct c2wr_hdr *host_msg;
  109. struct c2wr_hdr tmp;
  110. struct c2_mq *reply_vq;
  111. struct c2_vq_req *req;
  112. struct iw_cm_event cm_event;
  113. int err;
  114. reply_vq = (struct c2_mq *) c2dev->qptr_array[mq_index];
  115. /*
  116. * get next msg from mq_index into adapter_msg.
  117. * don't free it yet.
  118. */
  119. adapter_msg = c2_mq_consume(reply_vq);
  120. if (adapter_msg == NULL) {
  121. return;
  122. }
  123. host_msg = vq_repbuf_alloc(c2dev);
  124. /*
  125. * If we can't get a host buffer, then we'll still
  126. * wakeup the waiter, we just won't give him the msg.
  127. * It is assumed the waiter will deal with this...
  128. */
  129. if (!host_msg) {
  130. pr_debug("handle_vq: no repbufs!\n");
  131. /*
  132. * just copy the WR header into a local variable.
  133. * this allows us to still demux on the context
  134. */
  135. host_msg = &tmp;
  136. memcpy(host_msg, adapter_msg, sizeof(tmp));
  137. reply_msg = NULL;
  138. } else {
  139. memcpy(host_msg, adapter_msg, reply_vq->msg_size);
  140. reply_msg = host_msg;
  141. }
  142. /*
  143. * consume the msg from the MQ
  144. */
  145. c2_mq_free(reply_vq);
  146. /*
  147. * wakeup the waiter.
  148. */
  149. req = (struct c2_vq_req *) (unsigned long) host_msg->context;
  150. if (req == NULL) {
  151. /*
  152. * We should never get here, as the adapter should
  153. * never send us a reply that we're not expecting.
  154. */
  155. vq_repbuf_free(c2dev, host_msg);
  156. pr_debug("handle_vq: UNEXPECTEDLY got NULL req\n");
  157. return;
  158. }
  159. if (reply_msg)
  160. err = c2_errno(reply_msg);
  161. else
  162. err = -ENOMEM;
  163. if (!err) switch (req->event) {
  164. case IW_CM_EVENT_ESTABLISHED:
  165. c2_set_qp_state(req->qp,
  166. C2_QP_STATE_RTS);
  167. /*
  168. * Until ird/ord negotiation via MPAv2 support is added, send
  169. * max supported values
  170. */
  171. cm_event.ird = cm_event.ord = 128;
  172. case IW_CM_EVENT_CLOSE:
  173. /*
  174. * Move the QP to RTS if this is
  175. * the established event
  176. */
  177. cm_event.event = req->event;
  178. cm_event.status = 0;
  179. cm_event.local_addr = req->cm_id->local_addr;
  180. cm_event.remote_addr = req->cm_id->remote_addr;
  181. cm_event.private_data = NULL;
  182. cm_event.private_data_len = 0;
  183. req->cm_id->event_handler(req->cm_id, &cm_event);
  184. break;
  185. default:
  186. break;
  187. }
  188. req->reply_msg = (u64) (unsigned long) (reply_msg);
  189. atomic_set(&req->reply_ready, 1);
  190. wake_up(&req->wait_object);
  191. /*
  192. * If the request was cancelled, then this put will
  193. * free the vq_req memory...and reply_msg!!!
  194. */
  195. vq_req_put(c2dev, req);
  196. }