iwch_ev.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. unsigned long flag;
  49. spin_lock(&rnicp->lock);
  50. qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
  51. if (!qhp) {
  52. printk(KERN_ERR "%s unaffiliated error 0x%x qpid 0x%x\n",
  53. __func__, CQE_STATUS(rsp_msg->cqe),
  54. CQE_QPID(rsp_msg->cqe));
  55. spin_unlock(&rnicp->lock);
  56. return;
  57. }
  58. if ((qhp->attr.state == IWCH_QP_STATE_ERROR) ||
  59. (qhp->attr.state == IWCH_QP_STATE_TERMINATE)) {
  60. PDBG("%s AE received after RTS - "
  61. "qp state %d qpid 0x%x status 0x%x\n", __func__,
  62. qhp->attr.state, qhp->wq.qpid, CQE_STATUS(rsp_msg->cqe));
  63. spin_unlock(&rnicp->lock);
  64. return;
  65. }
  66. printk(KERN_ERR "%s - AE qpid 0x%x opcode %d status 0x%x "
  67. "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __func__,
  68. CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe),
  69. CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe),
  70. CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
  71. atomic_inc(&qhp->refcnt);
  72. spin_unlock(&rnicp->lock);
  73. if (qhp->attr.state == IWCH_QP_STATE_RTS) {
  74. attrs.next_state = IWCH_QP_STATE_TERMINATE;
  75. iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE,
  76. &attrs, 1);
  77. if (send_term)
  78. iwch_post_terminate(qhp, rsp_msg);
  79. }
  80. event.event = ib_event;
  81. event.device = chp->ibcq.device;
  82. if (ib_event == IB_EVENT_CQ_ERR)
  83. event.element.cq = &chp->ibcq;
  84. else
  85. event.element.qp = &qhp->ibqp;
  86. if (qhp->ibqp.event_handler)
  87. (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
  88. spin_lock_irqsave(&chp->comp_handler_lock, flag);
  89. (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
  90. spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
  91. if (atomic_dec_and_test(&qhp->refcnt))
  92. wake_up(&qhp->wait);
  93. }
  94. void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
  95. {
  96. struct iwch_dev *rnicp;
  97. struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) skb->data;
  98. struct iwch_cq *chp;
  99. struct iwch_qp *qhp;
  100. u32 cqid = RSPQ_CQID(rsp_msg);
  101. unsigned long flag;
  102. rnicp = (struct iwch_dev *) rdev_p->ulp;
  103. spin_lock(&rnicp->lock);
  104. chp = get_chp(rnicp, cqid);
  105. qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
  106. if (!chp || !qhp) {
  107. printk(KERN_ERR MOD "BAD AE cqid 0x%x qpid 0x%x opcode %d "
  108. "status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x \n",
  109. cqid, CQE_QPID(rsp_msg->cqe),
  110. CQE_OPCODE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe),
  111. CQE_TYPE(rsp_msg->cqe), CQE_WRID_HI(rsp_msg->cqe),
  112. CQE_WRID_LOW(rsp_msg->cqe));
  113. spin_unlock(&rnicp->lock);
  114. goto out;
  115. }
  116. iwch_qp_add_ref(&qhp->ibqp);
  117. atomic_inc(&chp->refcnt);
  118. spin_unlock(&rnicp->lock);
  119. /*
  120. * 1) completion of our sending a TERMINATE.
  121. * 2) incoming TERMINATE message.
  122. */
  123. if ((CQE_OPCODE(rsp_msg->cqe) == T3_TERMINATE) &&
  124. (CQE_STATUS(rsp_msg->cqe) == 0)) {
  125. if (SQ_TYPE(rsp_msg->cqe)) {
  126. PDBG("%s QPID 0x%x ep %p disconnecting\n",
  127. __func__, qhp->wq.qpid, qhp->ep);
  128. iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC);
  129. } else {
  130. PDBG("%s post REQ_ERR AE QPID 0x%x\n", __func__,
  131. qhp->wq.qpid);
  132. post_qp_event(rnicp, chp, rsp_msg,
  133. IB_EVENT_QP_REQ_ERR, 0);
  134. iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC);
  135. }
  136. goto done;
  137. }
  138. /* Bad incoming Read request */
  139. if (SQ_TYPE(rsp_msg->cqe) &&
  140. (CQE_OPCODE(rsp_msg->cqe) == T3_READ_RESP)) {
  141. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1);
  142. goto done;
  143. }
  144. /* Bad incoming write */
  145. if (RQ_TYPE(rsp_msg->cqe) &&
  146. (CQE_OPCODE(rsp_msg->cqe) == T3_RDMA_WRITE)) {
  147. post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1);
  148. goto done;
  149. }
  150. switch (CQE_STATUS(rsp_msg->cqe)) {
  151. /* Completion Events */
  152. case TPT_ERR_SUCCESS:
  153. /*
  154. * Confirm the destination entry if this is a RECV completion.
  155. */
  156. if (qhp->ep && SQ_TYPE(rsp_msg->cqe))
  157. dst_confirm(qhp->ep->dst);
  158. spin_lock_irqsave(&chp->comp_handler_lock, flag);
  159. (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
  160. spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
  161. break;
  162. case TPT_ERR_STAG:
  163. case TPT_ERR_PDID:
  164. case TPT_ERR_QPID:
  165. case TPT_ERR_ACCESS:
  166. case TPT_ERR_WRAP:
  167. case TPT_ERR_BOUND:
  168. case TPT_ERR_INVALIDATE_SHARED_MR:
  169. case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND:
  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. }