xref: /OK3568_Linux_fs/kernel/drivers/infiniband/hw/cxgb4/ev.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This software is available to you under a choice of one of two
5*4882a593Smuzhiyun  * licenses.  You may choose to be licensed under the terms of the GNU
6*4882a593Smuzhiyun  * General Public License (GPL) Version 2, available from the file
7*4882a593Smuzhiyun  * COPYING in the main directory of this source tree, or the
8*4882a593Smuzhiyun  * OpenIB.org BSD license below:
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *     Redistribution and use in source and binary forms, with or
11*4882a593Smuzhiyun  *     without modification, are permitted provided that the following
12*4882a593Smuzhiyun  *     conditions are met:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *      - Redistributions of source code must retain the above
15*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
16*4882a593Smuzhiyun  *        disclaimer.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  *      - Redistributions in binary form must reproduce the above
19*4882a593Smuzhiyun  *        copyright notice, this list of conditions and the following
20*4882a593Smuzhiyun  *        disclaimer in the documentation and/or other materials
21*4882a593Smuzhiyun  *        provided with the distribution.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26*4882a593Smuzhiyun  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30*4882a593Smuzhiyun  * SOFTWARE.
31*4882a593Smuzhiyun  */
32*4882a593Smuzhiyun #include <linux/slab.h>
33*4882a593Smuzhiyun #include <linux/mman.h>
34*4882a593Smuzhiyun #include <net/sock.h>
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #include "iw_cxgb4.h"
37*4882a593Smuzhiyun 
print_tpte(struct c4iw_dev * dev,u32 stag)38*4882a593Smuzhiyun static void print_tpte(struct c4iw_dev *dev, u32 stag)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	int ret;
41*4882a593Smuzhiyun 	struct fw_ri_tpte tpte;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	ret = cxgb4_read_tpte(dev->rdev.lldi.ports[0], stag,
44*4882a593Smuzhiyun 			      (__be32 *)&tpte);
45*4882a593Smuzhiyun 	if (ret) {
46*4882a593Smuzhiyun 		dev_err(&dev->rdev.lldi.pdev->dev,
47*4882a593Smuzhiyun 			"%s cxgb4_read_tpte err %d\n", __func__, ret);
48*4882a593Smuzhiyun 		return;
49*4882a593Smuzhiyun 	}
50*4882a593Smuzhiyun 	pr_debug("stag idx 0x%x valid %d key 0x%x state %d pdid %d perm 0x%x ps %d len 0x%llx va 0x%llx\n",
51*4882a593Smuzhiyun 		 stag & 0xffffff00,
52*4882a593Smuzhiyun 		 FW_RI_TPTE_VALID_G(ntohl(tpte.valid_to_pdid)),
53*4882a593Smuzhiyun 		 FW_RI_TPTE_STAGKEY_G(ntohl(tpte.valid_to_pdid)),
54*4882a593Smuzhiyun 		 FW_RI_TPTE_STAGSTATE_G(ntohl(tpte.valid_to_pdid)),
55*4882a593Smuzhiyun 		 FW_RI_TPTE_PDID_G(ntohl(tpte.valid_to_pdid)),
56*4882a593Smuzhiyun 		 FW_RI_TPTE_PERM_G(ntohl(tpte.locread_to_qpid)),
57*4882a593Smuzhiyun 		 FW_RI_TPTE_PS_G(ntohl(tpte.locread_to_qpid)),
58*4882a593Smuzhiyun 		 ((u64)ntohl(tpte.len_hi) << 32) | ntohl(tpte.len_lo),
59*4882a593Smuzhiyun 		 ((u64)ntohl(tpte.va_hi) << 32) | ntohl(tpte.va_lo_fbo));
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
dump_err_cqe(struct c4iw_dev * dev,struct t4_cqe * err_cqe)62*4882a593Smuzhiyun static void dump_err_cqe(struct c4iw_dev *dev, struct t4_cqe *err_cqe)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun 	__be64 *p = (void *)err_cqe;
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun 	dev_err(&dev->rdev.lldi.pdev->dev,
67*4882a593Smuzhiyun 		"AE qpid %d opcode %d status 0x%x "
68*4882a593Smuzhiyun 		"type %d len 0x%x wrid.hi 0x%x wrid.lo 0x%x\n",
69*4882a593Smuzhiyun 		CQE_QPID(err_cqe), CQE_OPCODE(err_cqe),
70*4882a593Smuzhiyun 		CQE_STATUS(err_cqe), CQE_TYPE(err_cqe), ntohl(err_cqe->len),
71*4882a593Smuzhiyun 		CQE_WRID_HI(err_cqe), CQE_WRID_LOW(err_cqe));
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	pr_debug("%016llx %016llx %016llx %016llx - %016llx %016llx %016llx %016llx\n",
74*4882a593Smuzhiyun 		 be64_to_cpu(p[0]), be64_to_cpu(p[1]), be64_to_cpu(p[2]),
75*4882a593Smuzhiyun 		 be64_to_cpu(p[3]), be64_to_cpu(p[4]), be64_to_cpu(p[5]),
76*4882a593Smuzhiyun 		 be64_to_cpu(p[6]), be64_to_cpu(p[7]));
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	/*
79*4882a593Smuzhiyun 	 * Ingress WRITE and READ_RESP errors provide
80*4882a593Smuzhiyun 	 * the offending stag, so parse and log it.
81*4882a593Smuzhiyun 	 */
82*4882a593Smuzhiyun 	if (RQ_TYPE(err_cqe) && (CQE_OPCODE(err_cqe) == FW_RI_RDMA_WRITE ||
83*4882a593Smuzhiyun 				 CQE_OPCODE(err_cqe) == FW_RI_READ_RESP))
84*4882a593Smuzhiyun 		print_tpte(dev, CQE_WRID_STAG(err_cqe));
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun 
post_qp_event(struct c4iw_dev * dev,struct c4iw_cq * chp,struct c4iw_qp * qhp,struct t4_cqe * err_cqe,enum ib_event_type ib_event)87*4882a593Smuzhiyun static void post_qp_event(struct c4iw_dev *dev, struct c4iw_cq *chp,
88*4882a593Smuzhiyun 			  struct c4iw_qp *qhp,
89*4882a593Smuzhiyun 			  struct t4_cqe *err_cqe,
90*4882a593Smuzhiyun 			  enum ib_event_type ib_event)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun 	struct ib_event event;
93*4882a593Smuzhiyun 	struct c4iw_qp_attributes attrs;
94*4882a593Smuzhiyun 	unsigned long flag;
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	dump_err_cqe(dev, err_cqe);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun 	if (qhp->attr.state == C4IW_QP_STATE_RTS) {
99*4882a593Smuzhiyun 		attrs.next_state = C4IW_QP_STATE_TERMINATE;
100*4882a593Smuzhiyun 		c4iw_modify_qp(qhp->rhp, qhp, C4IW_QP_ATTR_NEXT_STATE,
101*4882a593Smuzhiyun 			       &attrs, 0);
102*4882a593Smuzhiyun 	}
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	event.event = ib_event;
105*4882a593Smuzhiyun 	event.device = chp->ibcq.device;
106*4882a593Smuzhiyun 	if (ib_event == IB_EVENT_CQ_ERR)
107*4882a593Smuzhiyun 		event.element.cq = &chp->ibcq;
108*4882a593Smuzhiyun 	else
109*4882a593Smuzhiyun 		event.element.qp = &qhp->ibqp;
110*4882a593Smuzhiyun 	if (qhp->ibqp.event_handler)
111*4882a593Smuzhiyun 		(*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	if (t4_clear_cq_armed(&chp->cq)) {
114*4882a593Smuzhiyun 		spin_lock_irqsave(&chp->comp_handler_lock, flag);
115*4882a593Smuzhiyun 		(*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
116*4882a593Smuzhiyun 		spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
117*4882a593Smuzhiyun 	}
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun 
c4iw_ev_dispatch(struct c4iw_dev * dev,struct t4_cqe * err_cqe)120*4882a593Smuzhiyun void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun 	struct c4iw_cq *chp;
123*4882a593Smuzhiyun 	struct c4iw_qp *qhp;
124*4882a593Smuzhiyun 	u32 cqid;
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	xa_lock_irq(&dev->qps);
127*4882a593Smuzhiyun 	qhp = xa_load(&dev->qps, CQE_QPID(err_cqe));
128*4882a593Smuzhiyun 	if (!qhp) {
129*4882a593Smuzhiyun 		pr_err("BAD AE qpid 0x%x opcode %d status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x\n",
130*4882a593Smuzhiyun 		       CQE_QPID(err_cqe),
131*4882a593Smuzhiyun 		       CQE_OPCODE(err_cqe), CQE_STATUS(err_cqe),
132*4882a593Smuzhiyun 		       CQE_TYPE(err_cqe), CQE_WRID_HI(err_cqe),
133*4882a593Smuzhiyun 		       CQE_WRID_LOW(err_cqe));
134*4882a593Smuzhiyun 		xa_unlock_irq(&dev->qps);
135*4882a593Smuzhiyun 		goto out;
136*4882a593Smuzhiyun 	}
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	if (SQ_TYPE(err_cqe))
139*4882a593Smuzhiyun 		cqid = qhp->attr.scq;
140*4882a593Smuzhiyun 	else
141*4882a593Smuzhiyun 		cqid = qhp->attr.rcq;
142*4882a593Smuzhiyun 	chp = get_chp(dev, cqid);
143*4882a593Smuzhiyun 	if (!chp) {
144*4882a593Smuzhiyun 		pr_err("BAD AE cqid 0x%x qpid 0x%x opcode %d status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x\n",
145*4882a593Smuzhiyun 		       cqid, CQE_QPID(err_cqe),
146*4882a593Smuzhiyun 		       CQE_OPCODE(err_cqe), CQE_STATUS(err_cqe),
147*4882a593Smuzhiyun 		       CQE_TYPE(err_cqe), CQE_WRID_HI(err_cqe),
148*4882a593Smuzhiyun 		       CQE_WRID_LOW(err_cqe));
149*4882a593Smuzhiyun 		xa_unlock_irq(&dev->qps);
150*4882a593Smuzhiyun 		goto out;
151*4882a593Smuzhiyun 	}
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun 	c4iw_qp_add_ref(&qhp->ibqp);
154*4882a593Smuzhiyun 	atomic_inc(&chp->refcnt);
155*4882a593Smuzhiyun 	xa_unlock_irq(&dev->qps);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	/* Bad incoming write */
158*4882a593Smuzhiyun 	if (RQ_TYPE(err_cqe) &&
159*4882a593Smuzhiyun 	    (CQE_OPCODE(err_cqe) == FW_RI_RDMA_WRITE)) {
160*4882a593Smuzhiyun 		post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_REQ_ERR);
161*4882a593Smuzhiyun 		goto done;
162*4882a593Smuzhiyun 	}
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	switch (CQE_STATUS(err_cqe)) {
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	/* Completion Events */
167*4882a593Smuzhiyun 	case T4_ERR_SUCCESS:
168*4882a593Smuzhiyun 		pr_err("AE with status 0!\n");
169*4882a593Smuzhiyun 		break;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	case T4_ERR_STAG:
172*4882a593Smuzhiyun 	case T4_ERR_PDID:
173*4882a593Smuzhiyun 	case T4_ERR_QPID:
174*4882a593Smuzhiyun 	case T4_ERR_ACCESS:
175*4882a593Smuzhiyun 	case T4_ERR_WRAP:
176*4882a593Smuzhiyun 	case T4_ERR_BOUND:
177*4882a593Smuzhiyun 	case T4_ERR_INVALIDATE_SHARED_MR:
178*4882a593Smuzhiyun 	case T4_ERR_INVALIDATE_MR_WITH_MW_BOUND:
179*4882a593Smuzhiyun 		post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_ACCESS_ERR);
180*4882a593Smuzhiyun 		break;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	/* Device Fatal Errors */
183*4882a593Smuzhiyun 	case T4_ERR_ECC:
184*4882a593Smuzhiyun 	case T4_ERR_ECC_PSTAG:
185*4882a593Smuzhiyun 	case T4_ERR_INTERNAL_ERR:
186*4882a593Smuzhiyun 		post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_DEVICE_FATAL);
187*4882a593Smuzhiyun 		break;
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun 	/* QP Fatal Errors */
190*4882a593Smuzhiyun 	case T4_ERR_OUT_OF_RQE:
191*4882a593Smuzhiyun 	case T4_ERR_PBL_ADDR_BOUND:
192*4882a593Smuzhiyun 	case T4_ERR_CRC:
193*4882a593Smuzhiyun 	case T4_ERR_MARKER:
194*4882a593Smuzhiyun 	case T4_ERR_PDU_LEN_ERR:
195*4882a593Smuzhiyun 	case T4_ERR_DDP_VERSION:
196*4882a593Smuzhiyun 	case T4_ERR_RDMA_VERSION:
197*4882a593Smuzhiyun 	case T4_ERR_OPCODE:
198*4882a593Smuzhiyun 	case T4_ERR_DDP_QUEUE_NUM:
199*4882a593Smuzhiyun 	case T4_ERR_MSN:
200*4882a593Smuzhiyun 	case T4_ERR_TBIT:
201*4882a593Smuzhiyun 	case T4_ERR_MO:
202*4882a593Smuzhiyun 	case T4_ERR_MSN_GAP:
203*4882a593Smuzhiyun 	case T4_ERR_MSN_RANGE:
204*4882a593Smuzhiyun 	case T4_ERR_RQE_ADDR_BOUND:
205*4882a593Smuzhiyun 	case T4_ERR_IRD_OVERFLOW:
206*4882a593Smuzhiyun 		post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_FATAL);
207*4882a593Smuzhiyun 		break;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	default:
210*4882a593Smuzhiyun 		pr_err("Unknown T4 status 0x%x QPID 0x%x\n",
211*4882a593Smuzhiyun 		       CQE_STATUS(err_cqe), qhp->wq.sq.qid);
212*4882a593Smuzhiyun 		post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_FATAL);
213*4882a593Smuzhiyun 		break;
214*4882a593Smuzhiyun 	}
215*4882a593Smuzhiyun done:
216*4882a593Smuzhiyun 	if (atomic_dec_and_test(&chp->refcnt))
217*4882a593Smuzhiyun 		wake_up(&chp->wait);
218*4882a593Smuzhiyun 	c4iw_qp_rem_ref(&qhp->ibqp);
219*4882a593Smuzhiyun out:
220*4882a593Smuzhiyun 	return;
221*4882a593Smuzhiyun }
222*4882a593Smuzhiyun 
c4iw_ev_handler(struct c4iw_dev * dev,u32 qid)223*4882a593Smuzhiyun int c4iw_ev_handler(struct c4iw_dev *dev, u32 qid)
224*4882a593Smuzhiyun {
225*4882a593Smuzhiyun 	struct c4iw_cq *chp;
226*4882a593Smuzhiyun 	unsigned long flag;
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun 	xa_lock_irqsave(&dev->cqs, flag);
229*4882a593Smuzhiyun 	chp = xa_load(&dev->cqs, qid);
230*4882a593Smuzhiyun 	if (chp) {
231*4882a593Smuzhiyun 		atomic_inc(&chp->refcnt);
232*4882a593Smuzhiyun 		xa_unlock_irqrestore(&dev->cqs, flag);
233*4882a593Smuzhiyun 		t4_clear_cq_armed(&chp->cq);
234*4882a593Smuzhiyun 		spin_lock_irqsave(&chp->comp_handler_lock, flag);
235*4882a593Smuzhiyun 		(*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
236*4882a593Smuzhiyun 		spin_unlock_irqrestore(&chp->comp_handler_lock, flag);
237*4882a593Smuzhiyun 		if (atomic_dec_and_test(&chp->refcnt))
238*4882a593Smuzhiyun 			wake_up(&chp->wait);
239*4882a593Smuzhiyun 	} else {
240*4882a593Smuzhiyun 		pr_debug("unknown cqid 0x%x\n", qid);
241*4882a593Smuzhiyun 		xa_unlock_irqrestore(&dev->cqs, flag);
242*4882a593Smuzhiyun 	}
243*4882a593Smuzhiyun 	return 0;
244*4882a593Smuzhiyun }
245