iwch_ev.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/gfp.h>
  33. #include <linux/mman.h>
  34. #include <net/sock.h>
  35. #include "iwch_provider.h"
  36. #include "iwch.h"
  37. #include "iwch_cm.h"
  38. #include "cxio_hal.h"
  39. #include "cxio_wr.h"
  40. static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
  41. struct respQ_msg_t *rsp_msg,
  42. enum ib_event_type ib_event,
  43. int send_term)
  44. {
  45. struct ib_event event;
  46. struct iwch_qp_attributes attrs;
  47. struct iwch_qp *qhp;
  48. spin_lock(&rnicp->lock);
  49. qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
  50. if (!qhp) {
  51. printk(KERN_ERR "%s unaffiliated error 0x%x qpid 0x%x\n",
  52. __func__, CQE_STATUS(rsp_msg->cqe),
  53. CQE_QPID(rsp_msg->cqe));
  54. spin_unlock(&rnicp->lock);
  55. return;
  56. }
  57. if ((qhp->attr.state == IWCH_QP_STATE_ERROR) ||
  58. (qhp->attr.state == IWCH_QP_STATE_TERMINATE)) {
  59. PDBG("%s AE received after RTS - "
  60. "qp state %d qpid 0x%x status 0x%x\n", __func__,
  61. qhp->attr.state, qhp->wq.qpid, CQE_STATUS(rsp_msg->cqe));
  62. spin_unlock(&rnicp->lock);
  63. return;
  64. }
  65. printk(KERN_ERR "%s - AE qpid 0x%x opcode %d status 0x%x "
  66. "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __func__,
  67. CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe),
  68. CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe),
  69. CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
  70. atomic_inc(&qhp->refcnt);
  71. spin_unlock(&rnicp->lock);
  72. if (qhp->attr.state == IWCH_QP_STATE_RTS) {
  73. attrs.next_state = IWCH_QP_STATE_TERMINATE;
  74. iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE,
  75. &attrs, 1);
  76. if (send_term)
  77. iwch_post_terminate(qhp, rsp_msg);
  78. }
  79. event.event = ib_event;
  80. event.device = chp->ibcq.device;
  81. if (ib_event == IB_EVENT_CQ_ERR)
  82. event.element.cq = &chp->ibcq;
  83. else
  84. event.element.qp = &qhp->ibqp;
  85. if (qhp->ibqp.event_handler)
  86. (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
  87. (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
  88. if (atomic_dec_and_test(&qhp->refcnt))
  89. wake_up(&qhp->wait);
  90. }
  91. void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
  92. {
  93. struct iwch_dev *rnicp;
  94. struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) skb->data;
  95. struct iwch_cq *chp;
  96. struct iwch_qp *qhp;
  97. u32 cqid = RSPQ_CQID(rsp_msg);
  98. rnicp = (struct iwch_dev *) rdev_p->ulp;
  99. spin_lock(&rnicp->lock);
  100. chp = get_chp(rnicp, cqid);
  101. qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
  102. if (!chp || !qhp) {
  103. printk(KERN_ERR MOD "BAD AE cqid 0x%x qpid 0x%x opcode %d "
  104. "status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x \n",
  105. cqid, CQE_QPID(rsp_msg->cqe),
  106. CQE_OPCODE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe),
  107. CQE_TYPE(rsp_msg->cqe), CQE_WRID_HI(rsp_msg->cqe),
  108. CQE_WRID_LOW(rsp_msg->cqe));
  109. spin_unlock(&rnicp->lock);
  110. goto out;
  111. }
  112. iwch_qp_add_ref(&qhp->ibqp);
  113. atomic_inc(&chp->refcnt);
  114. spin_unlock(&rnicp->lock);
  115. /*
  116. * 1) completion of our sending a TERMINATE.
  117. * 2) incoming TERMINATE message.
  118. */
  119. if ((CQE_OPCODE(rsp_msg->cqe) == T3_TERMINATE) &&
  120. (CQE_STATUS(rsp_msg->cqe) == 0)) {
  121. if (SQ_TYPE(rsp_msg->cqe)) {
  122. PDBG("%s QPID 0x%x ep %p disconnecting\n",
  123. __func__, qhp->wq.qpid, qhp->ep);
  124. iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC);
  125. } else {
  126. PDBG("%s post REQ_ERR AE QPID 0x%x\n", __func__,
  127. qhp->wq.qpid);
  128. post_qp_event(rnicp, chp, rsp_msg,
  129. IB_EVENT_QP_REQ_ERR, 0);
  130. iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC);
  131. }
  132. goto done;
  133. }
  134. /* Bad incoming Read request */
  135. if (SQ_TYPE(rsp_msg->cqe) &&
  136. (CQE_OPCODE(rsp_msg->cqe) == T3_READ_RESP)) {
  137. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1);
  138. goto done;
  139. }
  140. /* Bad incoming write */
  141. if (RQ_TYPE(rsp_msg->cqe) &&
  142. (CQE_OPCODE(rsp_msg->cqe) == T3_RDMA_WRITE)) {
  143. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1);
  144. goto done;
  145. }
  146. switch (CQE_STATUS(rsp_msg->cqe)) {
  147. /* Completion Events */
  148. case TPT_ERR_SUCCESS:
  149. /*
  150. * Confirm the destination entry if this is a RECV completion.
  151. */
  152. if (qhp->ep && SQ_TYPE(rsp_msg->cqe))
  153. dst_confirm(qhp->ep->dst);
  154. (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
  155. break;
  156. case TPT_ERR_STAG:
  157. case TPT_ERR_PDID:
  158. case TPT_ERR_QPID:
  159. case TPT_ERR_ACCESS:
  160. case TPT_ERR_WRAP:
  161. case TPT_ERR_BOUND:
  162. case TPT_ERR_INVALIDATE_SHARED_MR:
  163. case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND:
  164. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_ACCESS_ERR, 1);
  165. break;
  166. /* Device Fatal Errors */
  167. case TPT_ERR_ECC:
  168. case TPT_ERR_ECC_PSTAG:
  169. case TPT_ERR_INTERNAL_ERR:
  170. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_DEVICE_FATAL, 1);
  171. break;
  172. /* QP Fatal Errors */
  173. case TPT_ERR_OUT_OF_RQE:
  174. case TPT_ERR_PBL_ADDR_BOUND:
  175. case TPT_ERR_CRC:
  176. case TPT_ERR_MARKER:
  177. case TPT_ERR_PDU_LEN_ERR:
  178. case TPT_ERR_DDP_VERSION:
  179. case TPT_ERR_RDMA_VERSION:
  180. case TPT_ERR_OPCODE:
  181. case TPT_ERR_DDP_QUEUE_NUM:
  182. case TPT_ERR_MSN:
  183. case TPT_ERR_TBIT:
  184. case TPT_ERR_MO:
  185. case TPT_ERR_MSN_GAP:
  186. case TPT_ERR_MSN_RANGE:
  187. case TPT_ERR_RQE_ADDR_BOUND:
  188. case TPT_ERR_IRD_OVERFLOW:
  189. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1);
  190. break;
  191. default:
  192. printk(KERN_ERR MOD "Unknown T3 status 0x%x QPID 0x%x\n",
  193. CQE_STATUS(rsp_msg->cqe), qhp->wq.qpid);
  194. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1);
  195. break;
  196. }
  197. done:
  198. if (atomic_dec_and_test(&chp->refcnt))
  199. wake_up(&chp->wait);
  200. iwch_qp_rem_ref(&qhp->ibqp);
  201. out:
  202. dev_kfree_skb_irq(skb);
  203. }