iwch_ev.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
  3. * Copyright (c) 2006 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 <linux/slab.h>
  34. #include <linux/mman.h>
  35. #include <net/sock.h>
  36. #include "iwch_provider.h"
  37. #include "iwch.h"
  38. #include "iwch_cm.h"
  39. #include "cxio_hal.h"
  40. #include "cxio_wr.h"
  41. static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
  42. struct respQ_msg_t *rsp_msg,
  43. enum ib_event_type ib_event,
  44. int send_term)
  45. {
  46. struct ib_event event;
  47. struct iwch_qp_attributes attrs;
  48. struct iwch_qp *qhp;
  49. printk(KERN_ERR "%s - AE qpid 0x%x opcode %d status 0x%x "
  50. "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __FUNCTION__,
  51. CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe),
  52. CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe),
  53. CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
  54. spin_lock(&rnicp->lock);
  55. qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
  56. if (!qhp) {
  57. printk(KERN_ERR "%s unaffiliated error 0x%x qpid 0x%x\n",
  58. __FUNCTION__, CQE_STATUS(rsp_msg->cqe),
  59. CQE_QPID(rsp_msg->cqe));
  60. spin_unlock(&rnicp->lock);
  61. return;
  62. }
  63. if ((qhp->attr.state == IWCH_QP_STATE_ERROR) ||
  64. (qhp->attr.state == IWCH_QP_STATE_TERMINATE)) {
  65. PDBG("%s AE received after RTS - "
  66. "qp state %d qpid 0x%x status 0x%x\n", __FUNCTION__,
  67. qhp->attr.state, qhp->wq.qpid, CQE_STATUS(rsp_msg->cqe));
  68. spin_unlock(&rnicp->lock);
  69. return;
  70. }
  71. atomic_inc(&qhp->refcnt);
  72. spin_unlock(&rnicp->lock);
  73. event.event = ib_event;
  74. event.device = chp->ibcq.device;
  75. if (ib_event == IB_EVENT_CQ_ERR)
  76. event.element.cq = &chp->ibcq;
  77. else
  78. event.element.qp = &qhp->ibqp;
  79. if (qhp->ibqp.event_handler)
  80. (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
  81. if (qhp->attr.state == IWCH_QP_STATE_RTS) {
  82. attrs.next_state = IWCH_QP_STATE_TERMINATE;
  83. iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE,
  84. &attrs, 1);
  85. if (send_term)
  86. iwch_post_terminate(qhp, rsp_msg);
  87. }
  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. __FUNCTION__, 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", __FUNCTION__,
  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. printk(KERN_ERR "%s - CQE Err qpid 0x%x opcode %d status 0x%x "
  165. "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __FUNCTION__,
  166. CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe),
  167. CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe),
  168. CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
  169. (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
  170. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_ACCESS_ERR, 1);
  171. break;
  172. /* Device Fatal Errors */
  173. case TPT_ERR_ECC:
  174. case TPT_ERR_ECC_PSTAG:
  175. case TPT_ERR_INTERNAL_ERR:
  176. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_DEVICE_FATAL, 1);
  177. break;
  178. /* QP Fatal Errors */
  179. case TPT_ERR_OUT_OF_RQE:
  180. case TPT_ERR_PBL_ADDR_BOUND:
  181. case TPT_ERR_CRC:
  182. case TPT_ERR_MARKER:
  183. case TPT_ERR_PDU_LEN_ERR:
  184. case TPT_ERR_DDP_VERSION:
  185. case TPT_ERR_RDMA_VERSION:
  186. case TPT_ERR_OPCODE:
  187. case TPT_ERR_DDP_QUEUE_NUM:
  188. case TPT_ERR_MSN:
  189. case TPT_ERR_TBIT:
  190. case TPT_ERR_MO:
  191. case TPT_ERR_MSN_GAP:
  192. case TPT_ERR_MSN_RANGE:
  193. case TPT_ERR_RQE_ADDR_BOUND:
  194. case TPT_ERR_IRD_OVERFLOW:
  195. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1);
  196. break;
  197. default:
  198. printk(KERN_ERR MOD "Unknown T3 status 0x%x QPID 0x%x\n",
  199. CQE_STATUS(rsp_msg->cqe), qhp->wq.qpid);
  200. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1);
  201. break;
  202. }
  203. done:
  204. if (atomic_dec_and_test(&chp->refcnt))
  205. wake_up(&chp->wait);
  206. iwch_qp_rem_ref(&qhp->ibqp);
  207. out:
  208. dev_kfree_skb_irq(skb);
  209. }