blob: abcc9e76962bc11bf442118c546cf49c399271b3 [file] [log] [blame]
Steve Wiseb038ced2007-02-12 16:16:18 -08001/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
Steve Wiseb038ced2007-02-12 16:16:18 -08003 *
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 */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/gfp.h>
Steve Wiseb038ced2007-02-12 16:16:18 -080033#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
41static 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;
Kumar Sanghvif7cc25d2011-10-24 21:20:22 +053049 unsigned long flag;
Steve Wiseb038ced2007-02-12 16:16:18 -080050
Steve Wiseb038ced2007-02-12 16:16:18 -080051 spin_lock(&rnicp->lock);
52 qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
53
54 if (!qhp) {
55 printk(KERN_ERR "%s unaffiliated error 0x%x qpid 0x%x\n",
Harvey Harrison33718362008-04-16 21:01:10 -070056 __func__, CQE_STATUS(rsp_msg->cqe),
Steve Wiseb038ced2007-02-12 16:16:18 -080057 CQE_QPID(rsp_msg->cqe));
58 spin_unlock(&rnicp->lock);
59 return;
60 }
61
62 if ((qhp->attr.state == IWCH_QP_STATE_ERROR) ||
63 (qhp->attr.state == IWCH_QP_STATE_TERMINATE)) {
64 PDBG("%s AE received after RTS - "
Harvey Harrison33718362008-04-16 21:01:10 -070065 "qp state %d qpid 0x%x status 0x%x\n", __func__,
Steve Wiseb038ced2007-02-12 16:16:18 -080066 qhp->attr.state, qhp->wq.qpid, CQE_STATUS(rsp_msg->cqe));
67 spin_unlock(&rnicp->lock);
68 return;
69 }
70
Steve Wise8cfccf02007-03-06 14:44:03 -060071 printk(KERN_ERR "%s - AE qpid 0x%x opcode %d status 0x%x "
Harvey Harrison33718362008-04-16 21:01:10 -070072 "type %d wrid.hi 0x%x wrid.lo 0x%x \n", __func__,
Steve Wise8cfccf02007-03-06 14:44:03 -060073 CQE_QPID(rsp_msg->cqe), CQE_OPCODE(rsp_msg->cqe),
74 CQE_STATUS(rsp_msg->cqe), CQE_TYPE(rsp_msg->cqe),
75 CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
76
Steve Wiseb038ced2007-02-12 16:16:18 -080077 atomic_inc(&qhp->refcnt);
78 spin_unlock(&rnicp->lock);
79
Steve Wiseb9551502010-10-21 12:37:06 +000080 if (qhp->attr.state == IWCH_QP_STATE_RTS) {
81 attrs.next_state = IWCH_QP_STATE_TERMINATE;
82 iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE,
83 &attrs, 1);
84 if (send_term)
85 iwch_post_terminate(qhp, rsp_msg);
86 }
87
Steve Wiseb038ced2007-02-12 16:16:18 -080088 event.event = ib_event;
89 event.device = chp->ibcq.device;
90 if (ib_event == IB_EVENT_CQ_ERR)
91 event.element.cq = &chp->ibcq;
92 else
93 event.element.qp = &qhp->ibqp;
94
95 if (qhp->ibqp.event_handler)
96 (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
97
Kumar Sanghvif7cc25d2011-10-24 21:20:22 +053098 spin_lock_irqsave(&chp->comp_handler_lock, flag);
Steve Wiseb9551502010-10-21 12:37:06 +000099 (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
Kumar Sanghvif7cc25d2011-10-24 21:20:22 +0530100 spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
Steve Wiseb038ced2007-02-12 16:16:18 -0800101
102 if (atomic_dec_and_test(&qhp->refcnt))
103 wake_up(&qhp->wait);
104}
105
106void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
107{
108 struct iwch_dev *rnicp;
109 struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) skb->data;
110 struct iwch_cq *chp;
111 struct iwch_qp *qhp;
112 u32 cqid = RSPQ_CQID(rsp_msg);
Kumar Sanghvif7cc25d2011-10-24 21:20:22 +0530113 unsigned long flag;
Steve Wiseb038ced2007-02-12 16:16:18 -0800114
115 rnicp = (struct iwch_dev *) rdev_p->ulp;
116 spin_lock(&rnicp->lock);
117 chp = get_chp(rnicp, cqid);
118 qhp = get_qhp(rnicp, CQE_QPID(rsp_msg->cqe));
119 if (!chp || !qhp) {
120 printk(KERN_ERR MOD "BAD AE cqid 0x%x qpid 0x%x opcode %d "
121 "status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x \n",
122 cqid, CQE_QPID(rsp_msg->cqe),
123 CQE_OPCODE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe),
124 CQE_TYPE(rsp_msg->cqe), CQE_WRID_HI(rsp_msg->cqe),
125 CQE_WRID_LOW(rsp_msg->cqe));
126 spin_unlock(&rnicp->lock);
127 goto out;
128 }
129 iwch_qp_add_ref(&qhp->ibqp);
130 atomic_inc(&chp->refcnt);
131 spin_unlock(&rnicp->lock);
132
133 /*
134 * 1) completion of our sending a TERMINATE.
135 * 2) incoming TERMINATE message.
136 */
137 if ((CQE_OPCODE(rsp_msg->cqe) == T3_TERMINATE) &&
138 (CQE_STATUS(rsp_msg->cqe) == 0)) {
139 if (SQ_TYPE(rsp_msg->cqe)) {
140 PDBG("%s QPID 0x%x ep %p disconnecting\n",
Harvey Harrison33718362008-04-16 21:01:10 -0700141 __func__, qhp->wq.qpid, qhp->ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800142 iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC);
143 } else {
Harvey Harrison33718362008-04-16 21:01:10 -0700144 PDBG("%s post REQ_ERR AE QPID 0x%x\n", __func__,
Steve Wiseb038ced2007-02-12 16:16:18 -0800145 qhp->wq.qpid);
146 post_qp_event(rnicp, chp, rsp_msg,
147 IB_EVENT_QP_REQ_ERR, 0);
148 iwch_ep_disconnect(qhp->ep, 0, GFP_ATOMIC);
149 }
150 goto done;
151 }
152
153 /* Bad incoming Read request */
154 if (SQ_TYPE(rsp_msg->cqe) &&
155 (CQE_OPCODE(rsp_msg->cqe) == T3_READ_RESP)) {
156 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1);
157 goto done;
158 }
159
160 /* Bad incoming write */
161 if (RQ_TYPE(rsp_msg->cqe) &&
162 (CQE_OPCODE(rsp_msg->cqe) == T3_RDMA_WRITE)) {
163 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_REQ_ERR, 1);
164 goto done;
165 }
166
167 switch (CQE_STATUS(rsp_msg->cqe)) {
168
169 /* Completion Events */
170 case TPT_ERR_SUCCESS:
171
172 /*
173 * Confirm the destination entry if this is a RECV completion.
174 */
175 if (qhp->ep && SQ_TYPE(rsp_msg->cqe))
176 dst_confirm(qhp->ep->dst);
Kumar Sanghvif7cc25d2011-10-24 21:20:22 +0530177 spin_lock_irqsave(&chp->comp_handler_lock, flag);
Steve Wiseb038ced2007-02-12 16:16:18 -0800178 (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
Kumar Sanghvif7cc25d2011-10-24 21:20:22 +0530179 spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
Steve Wiseb038ced2007-02-12 16:16:18 -0800180 break;
181
182 case TPT_ERR_STAG:
183 case TPT_ERR_PDID:
184 case TPT_ERR_QPID:
185 case TPT_ERR_ACCESS:
186 case TPT_ERR_WRAP:
187 case TPT_ERR_BOUND:
188 case TPT_ERR_INVALIDATE_SHARED_MR:
189 case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND:
Steve Wiseb038ced2007-02-12 16:16:18 -0800190 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_ACCESS_ERR, 1);
191 break;
192
193 /* Device Fatal Errors */
194 case TPT_ERR_ECC:
195 case TPT_ERR_ECC_PSTAG:
196 case TPT_ERR_INTERNAL_ERR:
197 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_DEVICE_FATAL, 1);
198 break;
199
200 /* QP Fatal Errors */
201 case TPT_ERR_OUT_OF_RQE:
202 case TPT_ERR_PBL_ADDR_BOUND:
203 case TPT_ERR_CRC:
204 case TPT_ERR_MARKER:
205 case TPT_ERR_PDU_LEN_ERR:
206 case TPT_ERR_DDP_VERSION:
207 case TPT_ERR_RDMA_VERSION:
208 case TPT_ERR_OPCODE:
209 case TPT_ERR_DDP_QUEUE_NUM:
210 case TPT_ERR_MSN:
211 case TPT_ERR_TBIT:
212 case TPT_ERR_MO:
213 case TPT_ERR_MSN_GAP:
214 case TPT_ERR_MSN_RANGE:
215 case TPT_ERR_RQE_ADDR_BOUND:
216 case TPT_ERR_IRD_OVERFLOW:
217 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1);
218 break;
219
220 default:
221 printk(KERN_ERR MOD "Unknown T3 status 0x%x QPID 0x%x\n",
222 CQE_STATUS(rsp_msg->cqe), qhp->wq.qpid);
223 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_FATAL, 1);
224 break;
225 }
226done:
227 if (atomic_dec_and_test(&chp->refcnt))
228 wake_up(&chp->wait);
229 iwch_qp_rem_ref(&qhp->ibqp);
230out:
231 dev_kfree_skb_irq(skb);
232}