2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
3 * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
33 #include "iwch_provider.h"
37 * Get one cq entry from cxio and map it to openib.
42 * -EAGAIN caller must try again
43 * any other -errno fatal error
45 static int iwch_poll_cq_one(struct iwch_dev
*rhp
, struct iwch_cq
*chp
,
48 struct iwch_qp
*qhp
= NULL
;
49 struct t3_cqe cqe
, *rd_cqe
;
56 rd_cqe
= cxio_next_cqe(&chp
->cq
);
61 qhp
= get_qhp(rhp
, CQE_QPID(*rd_cqe
));
65 spin_lock(&qhp
->lock
);
68 ret
= cxio_poll_cq(wq
, &(chp
->cq
), &cqe
, &cqe_flushed
, &cookie
,
70 if (t3a_device(chp
->rhp
) && credit
) {
71 PDBG("%s updating %d cq credits on id %d\n", __FUNCTION__
,
72 credit
, chp
->cq
.cqid
);
73 cxio_hal_cq_op(&rhp
->rdev
, &chp
->cq
, CQ_CREDIT_UPDATE
, credit
);
84 wc
->vendor_err
= CQE_STATUS(cqe
);
86 PDBG("%s qpid 0x%x type %d opcode %d status 0x%x wrid hi 0x%x "
87 "lo 0x%x cookie 0x%llx\n", __FUNCTION__
,
88 CQE_QPID(cqe
), CQE_TYPE(cqe
),
89 CQE_OPCODE(cqe
), CQE_STATUS(cqe
), CQE_WRID_HI(cqe
),
90 CQE_WRID_LOW(cqe
), (unsigned long long) cookie
);
92 if (CQE_TYPE(cqe
) == 0) {
94 wc
->byte_len
= CQE_LEN(cqe
);
97 wc
->opcode
= IB_WC_RECV
;
99 switch (CQE_OPCODE(cqe
)) {
101 wc
->opcode
= IB_WC_RDMA_WRITE
;
104 wc
->opcode
= IB_WC_RDMA_READ
;
105 wc
->byte_len
= CQE_LEN(cqe
);
108 case T3_SEND_WITH_SE
:
109 wc
->opcode
= IB_WC_SEND
;
112 wc
->opcode
= IB_WC_BIND_MW
;
115 /* these aren't supported yet */
116 case T3_SEND_WITH_INV
:
117 case T3_SEND_WITH_SE_INV
:
119 case T3_FAST_REGISTER
:
121 printk(KERN_ERR MOD
"Unexpected opcode %d "
122 "in the CQE received for QPID=0x%0x\n",
123 CQE_OPCODE(cqe
), CQE_QPID(cqe
));
130 wc
->status
= IB_WC_WR_FLUSH_ERR
;
133 switch (CQE_STATUS(cqe
)) {
134 case TPT_ERR_SUCCESS
:
135 wc
->status
= IB_WC_SUCCESS
;
138 wc
->status
= IB_WC_LOC_ACCESS_ERR
;
141 wc
->status
= IB_WC_LOC_PROT_ERR
;
145 wc
->status
= IB_WC_LOC_ACCESS_ERR
;
148 wc
->status
= IB_WC_GENERAL_ERR
;
151 wc
->status
= IB_WC_LOC_LEN_ERR
;
153 case TPT_ERR_INVALIDATE_SHARED_MR
:
154 case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND
:
155 wc
->status
= IB_WC_MW_BIND_ERR
;
159 case TPT_ERR_PDU_LEN_ERR
:
160 case TPT_ERR_OUT_OF_RQE
:
161 case TPT_ERR_DDP_VERSION
:
162 case TPT_ERR_RDMA_VERSION
:
163 case TPT_ERR_DDP_QUEUE_NUM
:
167 case TPT_ERR_MSN_RANGE
:
168 case TPT_ERR_IRD_OVERFLOW
:
170 wc
->status
= IB_WC_FATAL_ERR
;
172 case TPT_ERR_SWFLUSH
:
173 wc
->status
= IB_WC_WR_FLUSH_ERR
;
176 printk(KERN_ERR MOD
"Unexpected cqe_status 0x%x for "
177 "QPID=0x%0x\n", CQE_STATUS(cqe
), CQE_QPID(cqe
));
183 spin_unlock(&qhp
->lock
);
187 int iwch_poll_cq(struct ib_cq
*ibcq
, int num_entries
, struct ib_wc
*wc
)
189 struct iwch_dev
*rhp
;
195 chp
= to_iwch_cq(ibcq
);
198 spin_lock_irqsave(&chp
->lock
, flags
);
199 for (npolled
= 0; npolled
< num_entries
; ++npolled
) {
205 * Because T3 can post CQEs that are _not_ associated
206 * with a WR, we might have to poll again after removing
210 err
= iwch_poll_cq_one(rhp
, chp
, wc
+ npolled
);
214 } while (err
== -EAGAIN
);
218 spin_unlock_irqrestore(&chp
->lock
, flags
);