39 #include <linux/sched.h>
82 #define MTHCA_CQ_STATUS_OK ( 0 << 28)
83 #define MTHCA_CQ_STATUS_OVERFLOW ( 9 << 28)
84 #define MTHCA_CQ_STATUS_WRITE_FAIL (10 << 28)
85 #define MTHCA_CQ_FLAG_TR ( 1 << 18)
86 #define MTHCA_CQ_FLAG_OI ( 1 << 17)
87 #define MTHCA_CQ_STATE_DISARMED ( 0 << 8)
88 #define MTHCA_CQ_STATE_ARMED ( 1 << 8)
89 #define MTHCA_CQ_STATE_ARMED_SOL ( 4 << 8)
90 #define MTHCA_EQ_STATE_FIRED (10 << 8)
146 #define MTHCA_CQ_ENTRY_OWNER_SW (0 << 7)
147 #define MTHCA_CQ_ENTRY_OWNER_HW (1 << 7)
149 #define MTHCA_TAVOR_CQ_DB_INC_CI (1 << 24)
150 #define MTHCA_TAVOR_CQ_DB_REQ_NOT (2 << 24)
151 #define MTHCA_TAVOR_CQ_DB_REQ_NOT_SOL (3 << 24)
152 #define MTHCA_TAVOR_CQ_DB_SET_CI (4 << 24)
153 #define MTHCA_TAVOR_CQ_DB_REQ_NOT_MULT (5 << 24)
155 #define MTHCA_ARBEL_CQ_DB_REQ_NOT_SOL (1 << 24)
156 #define MTHCA_ARBEL_CQ_DB_REQ_NOT (2 << 24)
157 #define MTHCA_ARBEL_CQ_DB_REQ_NOT_MULT (3 << 24)
171 return get_cqe_from_buf(&cq->
buf, entry);
189 static void dump_cqe(
struct mthca_dev *
dev,
void *cqe_ptr)
194 mthca_dbg(dev,
"CQE contents %08x %08x %08x %08x %08x %08x %08x %08x\n",
207 if (mthca_is_memfree(dev)) {
229 mthca_warn(dev,
"Completion event for bogus CQ %08x\n", cqn);
253 mthca_warn(dev,
"Async event for bogus CQ %08x\n", cqn);
257 event.device = &dev->
ib_dev;
259 event.element.cq = &cq->
ibcq;
260 if (cq->
ibcq.event_handler)
261 cq->
ibcq.event_handler(&event, cq->
ibcq.cq_context);
269 static inline int is_recv_cqe(
struct mthca_cqe *cqe)
273 return !(cqe->
opcode & 0x01);
285 spin_lock_irq(&cq->
lock);
295 cqe_sw(get_cqe(cq, prod_index & cq->
ibcq.cqe));
301 mthca_dbg(dev,
"Cleaning QPN %06x from CQN %06x; ci %d, pi %d\n",
308 while ((
int) --prod_index - (
int) cq->
cons_index >= 0) {
309 cqe = get_cqe(cq, prod_index & cq->
ibcq.cqe);
311 if (srq && is_recv_cqe(cqe))
315 memcpy(get_cqe(cq, (prod_index + nfreed) & cq->
ibcq.cqe),
320 for (i = 0; i < nfreed; ++
i)
324 update_cons_index(dev, cq, nfreed);
327 spin_unlock_irq(&cq->
lock);
340 if (!mthca_is_memfree(to_mdev(cq->
ibcq.device)) &&
343 if (cqe_sw(get_cqe(cq, cq->
ibcq.cqe)))
347 for (i = cq->
cons_index; cqe_sw(get_cqe(cq, i & cq->
ibcq.cqe)); ++i)
365 for (i = 0; i < nent; ++
i)
366 set_cqe_hw(get_cqe_from_buf(buf, i));
387 "(QPN %06x, WQE @ %08x, CQN %06x, index %d)\n",
463 if (mthca_is_memfree(dev))
476 be16_add_cpu(&cqe->
db_cnt, -dbd);
483 static inline int mthca_poll_one(
struct mthca_dev *dev,
498 cqe = next_cqe_sw(cq);
509 mthca_dbg(dev,
"%x/%d: CQE -> QPN %06x, WQE @ %08x\n",
517 is_send = is_error ? cqe->
opcode & 0x01 : cqe->
is_send & 0x80;
527 (dev->
limits.num_qps - 1));
529 mthca_warn(dev,
"CQ entry for unknown QP %06x\n",
536 entry->
qp = &(*cur_qp)->ibqp;
542 entry->
wr_id = (*cur_qp)->wrid[wqe_index +
544 }
else if ((*cur_qp)->ibqp.srq) {
545 struct mthca_srq *srq = to_msrq((*cur_qp)->ibqp.srq);
562 wqe_index = wq->
max - 1;
563 entry->
wr_id = (*cur_qp)->wrid[wqe_index];
576 handle_error_cqe(dev, cq, *cur_qp, wqe_index, is_send,
620 switch (cqe->
opcode & 0x1f) {
677 while (npolled < num_entries) {
678 err = mthca_poll_one(dev, cq, &qp,
679 &freed, entry + npolled);
687 update_cons_index(dev, cq, freed);
705 if (!mthca_is_memfree(dev))
708 if (cqe_sw(get_cqe_from_buf(&cq->
resize_buf->buf,
726 spin_unlock_irqrestore(&cq->
lock, flags);
728 return err == 0 || err == -
EAGAIN ? npolled :
err;
756 mthca_write_db_rec(db_rec, cq->
arm_db);
784 cq->
ibcq.cqe = nent - 1;
791 if (mthca_is_memfree(dev)) {
817 cq_context = mailbox->
buf;
822 goto err_out_mailbox;
830 memset(cq_context, 0,
sizeof *cq_context);
845 if (mthca_is_memfree(dev)) {
852 mthca_warn(dev,
"SW2HW_CQ failed (%d)\n", err);
853 goto err_out_free_mr;
860 spin_unlock_irq(&dev->
cq_table.lock);
861 goto err_out_free_mr;
863 spin_unlock_irq(&dev->
cq_table.lock);
879 if (cq->
is_kernel && mthca_is_memfree(dev))
883 if (cq->
is_kernel && mthca_is_memfree(dev))
901 spin_unlock_irq(&dev->
cq_table.lock);
913 if (IS_ERR(mailbox)) {
914 mthca_warn(dev,
"No memory for mailbox to free CQ.\n");
920 mthca_warn(dev,
"HW2SW_CQ failed (%d)\n", err);
926 printk(
KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n",
929 for (j = 0; j < 16; ++
j)
937 spin_unlock_irq(&dev->
cq_table.lock);
948 if (mthca_is_memfree(dev)) {
968 dev->
limits.reserved_cqs);