2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
32 #include "iwch_provider.h"
35 static int __iwch_poll_cq_one(struct iwch_dev *rhp, struct iwch_cq *chp,
36 struct iwch_qp *qhp, struct ib_wc *wc)
38 struct t3_wq *wq = qhp ? &qhp->wq : NULL;
45 ret = cxio_poll_cq(wq, &(chp->cq), &cqe, &cqe_flushed, &cookie,
47 if (t3a_device(chp->rhp) && credit) {
48 pr_debug("%s updating %d cq credits on id %d\n", __func__,
49 credit, chp->cq.cqid);
50 cxio_hal_cq_op(&rhp->rdev, &chp->cq, CQ_CREDIT_UPDATE, credit);
60 wc->qp = qhp ? &qhp->ibqp : NULL;
61 wc->vendor_err = CQE_STATUS(cqe);
64 pr_debug("%s qpid 0x%x type %d opcode %d status 0x%x wrid hi 0x%x lo 0x%x cookie 0x%llx\n",
66 CQE_QPID(cqe), CQE_TYPE(cqe),
67 CQE_OPCODE(cqe), CQE_STATUS(cqe), CQE_WRID_HI(cqe),
68 CQE_WRID_LOW(cqe), (unsigned long long)cookie);
70 if (CQE_TYPE(cqe) == 0) {
72 wc->byte_len = CQE_LEN(cqe);
75 wc->opcode = IB_WC_RECV;
76 if (CQE_OPCODE(cqe) == T3_SEND_WITH_INV ||
77 CQE_OPCODE(cqe) == T3_SEND_WITH_SE_INV) {
78 wc->ex.invalidate_rkey = CQE_WRID_STAG(cqe);
79 wc->wc_flags |= IB_WC_WITH_INVALIDATE;
82 switch (CQE_OPCODE(cqe)) {
84 wc->opcode = IB_WC_RDMA_WRITE;
87 wc->opcode = IB_WC_RDMA_READ;
88 wc->byte_len = CQE_LEN(cqe);
92 case T3_SEND_WITH_INV:
93 case T3_SEND_WITH_SE_INV:
94 wc->opcode = IB_WC_SEND;
97 wc->opcode = IB_WC_LOCAL_INV;
99 case T3_FAST_REGISTER:
100 wc->opcode = IB_WC_REG_MR;
103 pr_err("Unexpected opcode %d in the CQE received for QPID=0x%0x\n",
104 CQE_OPCODE(cqe), CQE_QPID(cqe));
111 wc->status = IB_WC_WR_FLUSH_ERR;
114 switch (CQE_STATUS(cqe)) {
115 case TPT_ERR_SUCCESS:
116 wc->status = IB_WC_SUCCESS;
119 wc->status = IB_WC_LOC_ACCESS_ERR;
122 wc->status = IB_WC_LOC_PROT_ERR;
126 wc->status = IB_WC_LOC_ACCESS_ERR;
129 wc->status = IB_WC_GENERAL_ERR;
132 wc->status = IB_WC_LOC_LEN_ERR;
134 case TPT_ERR_INVALIDATE_SHARED_MR:
135 case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND:
136 wc->status = IB_WC_MW_BIND_ERR;
140 case TPT_ERR_PDU_LEN_ERR:
141 case TPT_ERR_OUT_OF_RQE:
142 case TPT_ERR_DDP_VERSION:
143 case TPT_ERR_RDMA_VERSION:
144 case TPT_ERR_DDP_QUEUE_NUM:
148 case TPT_ERR_MSN_RANGE:
149 case TPT_ERR_IRD_OVERFLOW:
151 wc->status = IB_WC_FATAL_ERR;
153 case TPT_ERR_SWFLUSH:
154 wc->status = IB_WC_WR_FLUSH_ERR;
157 pr_err("Unexpected cqe_status 0x%x for QPID=0x%0x\n",
158 CQE_STATUS(cqe), CQE_QPID(cqe));
167 * Get one cq entry from cxio and map it to openib.
172 * -EAGAIN caller must try again
173 * any other -errno fatal error
175 static int iwch_poll_cq_one(struct iwch_dev *rhp, struct iwch_cq *chp,
179 struct t3_cqe *rd_cqe;
182 rd_cqe = cxio_next_cqe(&chp->cq);
187 qhp = get_qhp(rhp, CQE_QPID(*rd_cqe));
189 spin_lock(&qhp->lock);
190 ret = __iwch_poll_cq_one(rhp, chp, qhp, wc);
191 spin_unlock(&qhp->lock);
193 ret = __iwch_poll_cq_one(rhp, chp, NULL, wc);
198 int iwch_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
200 struct iwch_dev *rhp;
206 chp = to_iwch_cq(ibcq);
209 spin_lock_irqsave(&chp->lock, flags);
210 for (npolled = 0; npolled < num_entries; ++npolled) {
213 * Because T3 can post CQEs that are _not_ associated
214 * with a WR, we might have to poll again after removing
218 err = iwch_poll_cq_one(rhp, chp, wc + npolled);
219 } while (err == -EAGAIN);
223 spin_unlock_irqrestore(&chp->lock, flags);