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 <asm/delay.h>
34 #include <linux/mutex.h>
35 #include <linux/netdevice.h>
36 #include <linux/sched.h>
37 #include <linux/spinlock.h>
38 #include <linux/pci.h>
39 #include <linux/dma-mapping.h>
40 #include <linux/slab.h>
41 #include <net/net_namespace.h>
43 #include "cxio_resource.h"
45 #include "cxgb3_offload.h"
48 static LIST_HEAD(rdev_list);
49 static cxio_hal_ev_callback_func_t cxio_ev_cb = NULL;
51 static struct cxio_rdev *cxio_hal_find_rdev_by_name(char *dev_name)
53 struct cxio_rdev *rdev;
55 list_for_each_entry(rdev, &rdev_list, entry)
56 if (!strcmp(rdev->dev_name, dev_name))
61 static struct cxio_rdev *cxio_hal_find_rdev_by_t3cdev(struct t3cdev *tdev)
63 struct cxio_rdev *rdev;
65 list_for_each_entry(rdev, &rdev_list, entry)
66 if (rdev->t3cdev_p == tdev)
71 int cxio_hal_cq_op(struct cxio_rdev *rdev_p, struct t3_cq *cq,
72 enum t3_cq_opcode op, u32 credit)
78 struct rdma_cq_op setup;
80 setup.credits = (op == CQ_CREDIT_UPDATE) ? credit : 0;
82 ret = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_OP, &setup);
84 if ((ret < 0) || (op == CQ_CREDIT_UPDATE))
88 * If the rearm returned an index other than our current index,
89 * then there might be CQE's in flight (being DMA'd). We must wait
90 * here for them to complete or the consumer can miss a notification.
92 if (Q_PTR2IDX((cq->rptr), cq->size_log2) != ret) {
98 * Keep the generation correct by bumping rptr until it
99 * matches the index returned by the rearm - 1.
101 while (Q_PTR2IDX((rptr+1), cq->size_log2) != ret)
105 * Now rptr is the index for the (last) cqe that was
106 * in-flight at the time the HW rearmed the CQ. We
107 * spin until that CQE is valid.
109 cqe = cq->queue + Q_PTR2IDX(rptr, cq->size_log2);
110 while (!CQ_VLD_ENTRY(rptr, cq->size_log2, cqe)) {
113 printk(KERN_ERR "%s: stalled rnic\n",
125 static int cxio_hal_clear_cq_ctx(struct cxio_rdev *rdev_p, u32 cqid)
127 struct rdma_cq_setup setup;
129 setup.base_addr = 0; /* NULL address */
130 setup.size = 0; /* disaable the CQ */
132 setup.credit_thres = 0;
134 return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup));
137 static int cxio_hal_clear_qp_ctx(struct cxio_rdev *rdev_p, u32 qpid)
140 struct t3_modify_qp_wr *wqe;
141 struct sk_buff *skb = alloc_skb(sizeof(*wqe), GFP_KERNEL);
143 PDBG("%s alloc_skb failed\n", __func__);
146 wqe = (struct t3_modify_qp_wr *) skb_put(skb, sizeof(*wqe));
147 memset(wqe, 0, sizeof(*wqe));
148 build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_QP_MOD,
149 T3_COMPLETION_FLAG | T3_NOTIFY_FLAG, 0, qpid, 7,
151 wqe->flags = cpu_to_be32(MODQP_WRITE_EC);
152 sge_cmd = qpid << 8 | 3;
153 wqe->sge_cmd = cpu_to_be64(sge_cmd);
154 skb->priority = CPL_PRIORITY_CONTROL;
155 return iwch_cxgb3_ofld_send(rdev_p->t3cdev_p, skb);
158 int cxio_create_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq, int kernel)
160 struct rdma_cq_setup setup;
161 int size = (1UL << (cq->size_log2)) * sizeof(struct t3_cqe);
163 size += 1; /* one extra page for storing cq-in-err state */
164 cq->cqid = cxio_hal_get_cqid(rdev_p->rscp);
168 cq->sw_queue = kzalloc(size, GFP_KERNEL);
172 cq->queue = dma_alloc_coherent(&(rdev_p->rnic_info.pdev->dev), size,
173 &(cq->dma_addr), GFP_KERNEL);
178 dma_unmap_addr_set(cq, mapping, cq->dma_addr);
179 memset(cq->queue, 0, size);
181 setup.base_addr = (u64) (cq->dma_addr);
182 setup.size = 1UL << cq->size_log2;
183 setup.credits = 65535;
184 setup.credit_thres = 1;
185 if (rdev_p->t3cdev_p->type != T3A)
189 return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup));
193 int cxio_resize_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq)
195 struct rdma_cq_setup setup;
197 setup.base_addr = (u64) (cq->dma_addr);
198 setup.size = 1UL << cq->size_log2;
199 setup.credits = setup.size;
200 setup.credit_thres = setup.size; /* TBD: overflow recovery */
202 return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup));
206 static u32 get_qpid(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx)
208 struct cxio_qpid_list *entry;
212 mutex_lock(&uctx->lock);
213 if (!list_empty(&uctx->qpids)) {
214 entry = list_entry(uctx->qpids.next, struct cxio_qpid_list,
216 list_del(&entry->entry);
220 qpid = cxio_hal_get_qpid(rdev_p->rscp);
223 for (i = qpid+1; i & rdev_p->qpmask; i++) {
224 entry = kmalloc(sizeof *entry, GFP_KERNEL);
228 list_add_tail(&entry->entry, &uctx->qpids);
232 mutex_unlock(&uctx->lock);
233 PDBG("%s qpid 0x%x\n", __func__, qpid);
237 static void put_qpid(struct cxio_rdev *rdev_p, u32 qpid,
238 struct cxio_ucontext *uctx)
240 struct cxio_qpid_list *entry;
242 entry = kmalloc(sizeof *entry, GFP_KERNEL);
245 PDBG("%s qpid 0x%x\n", __func__, qpid);
247 mutex_lock(&uctx->lock);
248 list_add_tail(&entry->entry, &uctx->qpids);
249 mutex_unlock(&uctx->lock);
252 void cxio_release_ucontext(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx)
254 struct list_head *pos, *nxt;
255 struct cxio_qpid_list *entry;
257 mutex_lock(&uctx->lock);
258 list_for_each_safe(pos, nxt, &uctx->qpids) {
259 entry = list_entry(pos, struct cxio_qpid_list, entry);
260 list_del_init(&entry->entry);
261 if (!(entry->qpid & rdev_p->qpmask))
262 cxio_hal_put_qpid(rdev_p->rscp, entry->qpid);
265 mutex_unlock(&uctx->lock);
268 void cxio_init_ucontext(struct cxio_rdev *rdev_p, struct cxio_ucontext *uctx)
270 INIT_LIST_HEAD(&uctx->qpids);
271 mutex_init(&uctx->lock);
274 int cxio_create_qp(struct cxio_rdev *rdev_p, u32 kernel_domain,
275 struct t3_wq *wq, struct cxio_ucontext *uctx)
277 int depth = 1UL << wq->size_log2;
278 int rqsize = 1UL << wq->rq_size_log2;
280 wq->qpid = get_qpid(rdev_p, uctx);
284 wq->rq = kzalloc(depth * sizeof(struct t3_swrq), GFP_KERNEL);
288 wq->rq_addr = cxio_hal_rqtpool_alloc(rdev_p, rqsize);
292 wq->sq = kzalloc(depth * sizeof(struct t3_swsq), GFP_KERNEL);
296 wq->queue = dma_alloc_coherent(&(rdev_p->rnic_info.pdev->dev),
297 depth * sizeof(union t3_wr),
298 &(wq->dma_addr), GFP_KERNEL);
302 memset(wq->queue, 0, depth * sizeof(union t3_wr));
303 dma_unmap_addr_set(wq, mapping, wq->dma_addr);
304 wq->doorbell = (void __iomem *)rdev_p->rnic_info.kdb_addr;
306 wq->udb = (u64)rdev_p->rnic_info.udbell_physbase +
307 (wq->qpid << rdev_p->qpshift);
309 PDBG("%s qpid 0x%x doorbell 0x%p udb 0x%llx\n", __func__,
310 wq->qpid, wq->doorbell, (unsigned long long) wq->udb);
315 cxio_hal_rqtpool_free(rdev_p, wq->rq_addr, rqsize);
319 put_qpid(rdev_p, wq->qpid, uctx);
323 int cxio_destroy_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq)
326 err = cxio_hal_clear_cq_ctx(rdev_p, cq->cqid);
328 dma_free_coherent(&(rdev_p->rnic_info.pdev->dev),
329 (1UL << (cq->size_log2))
330 * sizeof(struct t3_cqe) + 1, cq->queue,
331 dma_unmap_addr(cq, mapping));
332 cxio_hal_put_cqid(rdev_p->rscp, cq->cqid);
336 int cxio_destroy_qp(struct cxio_rdev *rdev_p, struct t3_wq *wq,
337 struct cxio_ucontext *uctx)
339 dma_free_coherent(&(rdev_p->rnic_info.pdev->dev),
340 (1UL << (wq->size_log2))
341 * sizeof(union t3_wr), wq->queue,
342 dma_unmap_addr(wq, mapping));
344 cxio_hal_rqtpool_free(rdev_p, wq->rq_addr, (1UL << wq->rq_size_log2));
346 put_qpid(rdev_p, wq->qpid, uctx);
350 static void insert_recv_cqe(struct t3_wq *wq, struct t3_cq *cq)
354 PDBG("%s wq %p cq %p sw_rptr 0x%x sw_wptr 0x%x\n", __func__,
355 wq, cq, cq->sw_rptr, cq->sw_wptr);
356 memset(&cqe, 0, sizeof(cqe));
357 cqe.header = cpu_to_be32(V_CQE_STATUS(TPT_ERR_SWFLUSH) |
358 V_CQE_OPCODE(T3_SEND) |
361 V_CQE_QPID(wq->qpid) |
362 V_CQE_GENBIT(Q_GENBIT(cq->sw_wptr,
364 *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) = cqe;
368 int cxio_flush_rq(struct t3_wq *wq, struct t3_cq *cq, int count)
373 PDBG("%s wq %p cq %p\n", __func__, wq, cq);
376 PDBG("%s rq_rptr %u rq_wptr %u skip count %u\n", __func__,
377 wq->rq_rptr, wq->rq_wptr, count);
378 ptr = wq->rq_rptr + count;
379 while (ptr++ != wq->rq_wptr) {
380 insert_recv_cqe(wq, cq);
386 static void insert_sq_cqe(struct t3_wq *wq, struct t3_cq *cq,
391 PDBG("%s wq %p cq %p sw_rptr 0x%x sw_wptr 0x%x\n", __func__,
392 wq, cq, cq->sw_rptr, cq->sw_wptr);
393 memset(&cqe, 0, sizeof(cqe));
394 cqe.header = cpu_to_be32(V_CQE_STATUS(TPT_ERR_SWFLUSH) |
395 V_CQE_OPCODE(sqp->opcode) |
398 V_CQE_QPID(wq->qpid) |
399 V_CQE_GENBIT(Q_GENBIT(cq->sw_wptr,
401 cqe.u.scqe.wrid_hi = sqp->sq_wptr;
403 *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2)) = cqe;
407 int cxio_flush_sq(struct t3_wq *wq, struct t3_cq *cq, int count)
411 struct t3_swsq *sqp = wq->sq + Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2);
413 ptr = wq->sq_rptr + count;
414 sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2);
415 while (ptr != wq->sq_wptr) {
417 insert_sq_cqe(wq, cq, sqp);
419 sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2);
426 * Move all CQEs from the HWCQ into the SWCQ.
428 void cxio_flush_hw_cq(struct t3_cq *cq)
430 struct t3_cqe *cqe, *swcqe;
432 PDBG("%s cq %p cqid 0x%x\n", __func__, cq, cq->cqid);
433 cqe = cxio_next_hw_cqe(cq);
435 PDBG("%s flushing hwcq rptr 0x%x to swcq wptr 0x%x\n",
436 __func__, cq->rptr, cq->sw_wptr);
437 swcqe = cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2);
439 swcqe->header |= cpu_to_be32(V_CQE_SWCQE(1));
442 cqe = cxio_next_hw_cqe(cq);
446 static int cqe_completes_wr(struct t3_cqe *cqe, struct t3_wq *wq)
448 if (CQE_OPCODE(*cqe) == T3_TERMINATE)
451 if ((CQE_OPCODE(*cqe) == T3_RDMA_WRITE) && RQ_TYPE(*cqe))
454 if ((CQE_OPCODE(*cqe) == T3_READ_RESP) && SQ_TYPE(*cqe))
457 if (CQE_SEND_OPCODE(*cqe) && RQ_TYPE(*cqe) &&
458 Q_EMPTY(wq->rq_rptr, wq->rq_wptr))
464 void cxio_count_scqes(struct t3_cq *cq, struct t3_wq *wq, int *count)
471 while (!Q_EMPTY(ptr, cq->sw_wptr)) {
472 cqe = cq->sw_queue + (Q_PTR2IDX(ptr, cq->size_log2));
473 if ((SQ_TYPE(*cqe) ||
474 ((CQE_OPCODE(*cqe) == T3_READ_RESP) && wq->oldest_read)) &&
475 (CQE_QPID(*cqe) == wq->qpid))
479 PDBG("%s cq %p count %d\n", __func__, cq, *count);
482 void cxio_count_rcqes(struct t3_cq *cq, struct t3_wq *wq, int *count)
488 PDBG("%s count zero %d\n", __func__, *count);
490 while (!Q_EMPTY(ptr, cq->sw_wptr)) {
491 cqe = cq->sw_queue + (Q_PTR2IDX(ptr, cq->size_log2));
492 if (RQ_TYPE(*cqe) && (CQE_OPCODE(*cqe) != T3_READ_RESP) &&
493 (CQE_QPID(*cqe) == wq->qpid) && cqe_completes_wr(cqe, wq))
497 PDBG("%s cq %p count %d\n", __func__, cq, *count);
500 static int cxio_hal_init_ctrl_cq(struct cxio_rdev *rdev_p)
502 struct rdma_cq_setup setup;
504 setup.base_addr = 0; /* NULL address */
505 setup.size = 1; /* enable the CQ */
508 /* force SGE to redirect to RspQ and interrupt */
509 setup.credit_thres = 0;
511 return (rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_CQ_SETUP, &setup));
514 static int cxio_hal_init_ctrl_qp(struct cxio_rdev *rdev_p)
517 u64 sge_cmd, ctx0, ctx1;
519 struct t3_modify_qp_wr *wqe;
522 skb = alloc_skb(sizeof(*wqe), GFP_KERNEL);
524 PDBG("%s alloc_skb failed\n", __func__);
527 err = cxio_hal_init_ctrl_cq(rdev_p);
529 PDBG("%s err %d initializing ctrl_cq\n", __func__, err);
532 rdev_p->ctrl_qp.workq = dma_alloc_coherent(
533 &(rdev_p->rnic_info.pdev->dev),
534 (1 << T3_CTRL_QP_SIZE_LOG2) *
536 &(rdev_p->ctrl_qp.dma_addr),
538 if (!rdev_p->ctrl_qp.workq) {
539 PDBG("%s dma_alloc_coherent failed\n", __func__);
543 dma_unmap_addr_set(&rdev_p->ctrl_qp, mapping,
544 rdev_p->ctrl_qp.dma_addr);
545 rdev_p->ctrl_qp.doorbell = (void __iomem *)rdev_p->rnic_info.kdb_addr;
546 memset(rdev_p->ctrl_qp.workq, 0,
547 (1 << T3_CTRL_QP_SIZE_LOG2) * sizeof(union t3_wr));
549 mutex_init(&rdev_p->ctrl_qp.lock);
550 init_waitqueue_head(&rdev_p->ctrl_qp.waitq);
552 /* update HW Ctrl QP context */
553 base_addr = rdev_p->ctrl_qp.dma_addr;
555 ctx0 = (V_EC_SIZE((1 << T3_CTRL_QP_SIZE_LOG2)) |
556 V_EC_BASE_LO((u32) base_addr & 0xffff));
558 ctx0 |= V_EC_CREDITS(FW_WR_NUM);
560 ctx1 = (u32) base_addr;
562 ctx1 |= ((u64) (V_EC_BASE_HI((u32) base_addr & 0xf) | V_EC_RESPQ(0) |
563 V_EC_TYPE(0) | V_EC_GEN(1) |
564 V_EC_UP_TOKEN(T3_CTL_QP_TID) | F_EC_VALID)) << 32;
565 wqe = (struct t3_modify_qp_wr *) skb_put(skb, sizeof(*wqe));
566 memset(wqe, 0, sizeof(*wqe));
567 build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_QP_MOD, 0, 0,
568 T3_CTL_QP_TID, 7, T3_SOPEOP);
569 wqe->flags = cpu_to_be32(MODQP_WRITE_EC);
570 sge_cmd = (3ULL << 56) | FW_RI_SGEEC_START << 8 | 3;
571 wqe->sge_cmd = cpu_to_be64(sge_cmd);
572 wqe->ctx1 = cpu_to_be64(ctx1);
573 wqe->ctx0 = cpu_to_be64(ctx0);
574 PDBG("CtrlQP dma_addr 0x%llx workq %p size %d\n",
575 (unsigned long long) rdev_p->ctrl_qp.dma_addr,
576 rdev_p->ctrl_qp.workq, 1 << T3_CTRL_QP_SIZE_LOG2);
577 skb->priority = CPL_PRIORITY_CONTROL;
578 return iwch_cxgb3_ofld_send(rdev_p->t3cdev_p, skb);
584 static int cxio_hal_destroy_ctrl_qp(struct cxio_rdev *rdev_p)
586 dma_free_coherent(&(rdev_p->rnic_info.pdev->dev),
587 (1UL << T3_CTRL_QP_SIZE_LOG2)
588 * sizeof(union t3_wr), rdev_p->ctrl_qp.workq,
589 dma_unmap_addr(&rdev_p->ctrl_qp, mapping));
590 return cxio_hal_clear_qp_ctx(rdev_p, T3_CTRL_QP_ID);
593 /* write len bytes of data into addr (32B aligned address)
594 * If data is NULL, clear len byte of memory to zero.
595 * caller acquires the ctrl_qp lock before the call
597 static int cxio_hal_ctrl_qp_write_mem(struct cxio_rdev *rdev_p, u32 addr,
600 u32 i, nr_wqe, copy_len;
602 u8 wr_len, utx_len; /* length in 8 byte flit */
603 enum t3_wr_flags flag;
607 nr_wqe = len % 96 ? len / 96 + 1 : len / 96; /* 96B max per WQE */
608 PDBG("%s wptr 0x%x rptr 0x%x len %d, nr_wqe %d data %p addr 0x%0x\n",
609 __func__, rdev_p->ctrl_qp.wptr, rdev_p->ctrl_qp.rptr, len,
611 utx_len = 3; /* in 32B unit */
612 for (i = 0; i < nr_wqe; i++) {
613 if (Q_FULL(rdev_p->ctrl_qp.rptr, rdev_p->ctrl_qp.wptr,
614 T3_CTRL_QP_SIZE_LOG2)) {
615 PDBG("%s ctrl_qp full wtpr 0x%0x rptr 0x%0x, "
616 "wait for more space i %d\n", __func__,
617 rdev_p->ctrl_qp.wptr, rdev_p->ctrl_qp.rptr, i);
618 if (wait_event_interruptible(rdev_p->ctrl_qp.waitq,
619 !Q_FULL(rdev_p->ctrl_qp.rptr,
620 rdev_p->ctrl_qp.wptr,
621 T3_CTRL_QP_SIZE_LOG2))) {
622 PDBG("%s ctrl_qp workq interrupted\n",
626 PDBG("%s ctrl_qp wakeup, continue posting work request "
627 "i %d\n", __func__, i);
629 wqe = (__be64 *)(rdev_p->ctrl_qp.workq + (rdev_p->ctrl_qp.wptr %
630 (1 << T3_CTRL_QP_SIZE_LOG2)));
632 if (i == (nr_wqe - 1)) {
634 flag = T3_COMPLETION_FLAG;
636 utx_len = len / 32 + 1;
642 * Force a CQE to return the credit to the workq in case
643 * we posted more than half the max QP size of WRs
646 (i % (((1 << T3_CTRL_QP_SIZE_LOG2)) >> 1) == 0)) {
647 flag = T3_COMPLETION_FLAG;
648 PDBG("%s force completion at i %d\n", __func__, i);
651 /* build the utx mem command */
652 wqe += (sizeof(struct t3_bypass_wr) >> 3);
653 utx_cmd = (T3_UTX_MEM_WRITE << 28) | (addr + i * 3);
655 utx_cmd |= (utx_len << 28) | ((utx_len << 2) + 1);
656 *wqe = cpu_to_be64(utx_cmd);
658 copy_data = (u8 *) data + i * 96;
659 copy_len = len > 96 ? 96 : len;
661 /* clear memory content if data is NULL */
663 memcpy(wqe, copy_data, copy_len);
665 memset(wqe, 0, copy_len);
667 memset(((u8 *) wqe) + copy_len, 0,
668 32 - (copy_len % 32));
669 wr_len = ((sizeof(struct t3_bypass_wr)) >> 3) + 1 +
671 wqe = (__be64 *)(rdev_p->ctrl_qp.workq + (rdev_p->ctrl_qp.wptr %
672 (1 << T3_CTRL_QP_SIZE_LOG2)));
674 /* wptr in the WRID[31:0] */
675 ((union t3_wrid *)(wqe+1))->id0.low = rdev_p->ctrl_qp.wptr;
678 * This must be the last write with a memory barrier
681 build_fw_riwrh((struct fw_riwrh *) wqe, T3_WR_BP, flag,
682 Q_GENBIT(rdev_p->ctrl_qp.wptr,
683 T3_CTRL_QP_SIZE_LOG2), T3_CTRL_QP_ID,
685 if (flag == T3_COMPLETION_FLAG)
686 ring_doorbell(rdev_p->ctrl_qp.doorbell, T3_CTRL_QP_ID);
688 rdev_p->ctrl_qp.wptr++;
693 /* IN: stag key, pdid, perm, zbva, to, len, page_size, pbl_size and pbl_addr
695 * TBD: shared memory region support
697 static int __cxio_tpt_op(struct cxio_rdev *rdev_p, u32 reset_tpt_entry,
698 u32 *stag, u8 stag_state, u32 pdid,
699 enum tpt_mem_type type, enum tpt_mem_perm perm,
700 u32 zbva, u64 to, u32 len, u8 page_size,
701 u32 pbl_size, u32 pbl_addr)
704 struct tpt_entry tpt;
708 if (cxio_fatal_error(rdev_p))
711 stag_state = stag_state > 0;
712 stag_idx = (*stag) >> 8;
714 if ((!reset_tpt_entry) && !(*stag != T3_STAG_UNSET)) {
715 stag_idx = cxio_hal_get_stag(rdev_p->rscp);
718 *stag = (stag_idx << 8) | ((*stag) & 0xFF);
720 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
721 __func__, stag_state, type, pdid, stag_idx);
723 mutex_lock(&rdev_p->ctrl_qp.lock);
725 /* write TPT entry */
727 memset(&tpt, 0, sizeof(tpt));
729 tpt.valid_stag_pdid = cpu_to_be32(F_TPT_VALID |
730 V_TPT_STAG_KEY((*stag) & M_TPT_STAG_KEY) |
731 V_TPT_STAG_STATE(stag_state) |
732 V_TPT_STAG_TYPE(type) | V_TPT_PDID(pdid));
733 BUG_ON(page_size >= 28);
734 tpt.flags_pagesize_qpid = cpu_to_be32(V_TPT_PERM(perm) |
735 ((perm & TPT_MW_BIND) ? F_TPT_MW_BIND_ENABLE : 0) |
736 V_TPT_ADDR_TYPE((zbva ? TPT_ZBTO : TPT_VATO)) |
737 V_TPT_PAGE_SIZE(page_size));
738 tpt.rsvd_pbl_addr = cpu_to_be32(V_TPT_PBL_ADDR(PBL_OFF(rdev_p, pbl_addr)>>3));
739 tpt.len = cpu_to_be32(len);
740 tpt.va_hi = cpu_to_be32((u32) (to >> 32));
741 tpt.va_low_or_fbo = cpu_to_be32((u32) (to & 0xFFFFFFFFULL));
742 tpt.rsvd_bind_cnt_or_pstag = 0;
743 tpt.rsvd_pbl_size = cpu_to_be32(V_TPT_PBL_SIZE(pbl_size >> 2));
745 err = cxio_hal_ctrl_qp_write_mem(rdev_p,
747 (rdev_p->rnic_info.tpt_base >> 5),
750 /* release the stag index to free pool */
752 cxio_hal_put_stag(rdev_p->rscp, stag_idx);
754 wptr = rdev_p->ctrl_qp.wptr;
755 mutex_unlock(&rdev_p->ctrl_qp.lock);
757 if (wait_event_interruptible(rdev_p->ctrl_qp.waitq,
758 SEQ32_GE(rdev_p->ctrl_qp.rptr,
764 int cxio_write_pbl(struct cxio_rdev *rdev_p, __be64 *pbl,
765 u32 pbl_addr, u32 pbl_size)
770 PDBG("%s *pdb_addr 0x%x, pbl_base 0x%x, pbl_size %d\n",
771 __func__, pbl_addr, rdev_p->rnic_info.pbl_base,
774 mutex_lock(&rdev_p->ctrl_qp.lock);
775 err = cxio_hal_ctrl_qp_write_mem(rdev_p, pbl_addr >> 5, pbl_size << 3,
777 wptr = rdev_p->ctrl_qp.wptr;
778 mutex_unlock(&rdev_p->ctrl_qp.lock);
782 if (wait_event_interruptible(rdev_p->ctrl_qp.waitq,
783 SEQ32_GE(rdev_p->ctrl_qp.rptr,
790 int cxio_register_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid,
791 enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len,
792 u8 page_size, u32 pbl_size, u32 pbl_addr)
794 *stag = T3_STAG_UNSET;
795 return __cxio_tpt_op(rdev_p, 0, stag, 1, pdid, TPT_NON_SHARED_MR, perm,
796 zbva, to, len, page_size, pbl_size, pbl_addr);
799 int cxio_reregister_phys_mem(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid,
800 enum tpt_mem_perm perm, u32 zbva, u64 to, u32 len,
801 u8 page_size, u32 pbl_size, u32 pbl_addr)
803 return __cxio_tpt_op(rdev_p, 0, stag, 1, pdid, TPT_NON_SHARED_MR, perm,
804 zbva, to, len, page_size, pbl_size, pbl_addr);
807 int cxio_dereg_mem(struct cxio_rdev *rdev_p, u32 stag, u32 pbl_size,
810 return __cxio_tpt_op(rdev_p, 1, &stag, 0, 0, 0, 0, 0, 0ULL, 0, 0,
814 int cxio_allocate_window(struct cxio_rdev *rdev_p, u32 * stag, u32 pdid)
816 *stag = T3_STAG_UNSET;
817 return __cxio_tpt_op(rdev_p, 0, stag, 0, pdid, TPT_MW, 0, 0, 0ULL, 0, 0,
821 int cxio_deallocate_window(struct cxio_rdev *rdev_p, u32 stag)
823 return __cxio_tpt_op(rdev_p, 1, &stag, 0, 0, 0, 0, 0, 0ULL, 0, 0,
827 int cxio_allocate_stag(struct cxio_rdev *rdev_p, u32 *stag, u32 pdid, u32 pbl_size, u32 pbl_addr)
829 *stag = T3_STAG_UNSET;
830 return __cxio_tpt_op(rdev_p, 0, stag, 0, pdid, TPT_NON_SHARED_MR,
831 0, 0, 0ULL, 0, 0, pbl_size, pbl_addr);
834 int cxio_rdma_init(struct cxio_rdev *rdev_p, struct t3_rdma_init_attr *attr)
836 struct t3_rdma_init_wr *wqe;
837 struct sk_buff *skb = alloc_skb(sizeof(*wqe), GFP_ATOMIC);
840 PDBG("%s rdev_p %p\n", __func__, rdev_p);
841 wqe = (struct t3_rdma_init_wr *) __skb_put(skb, sizeof(*wqe));
842 wqe->wrh.op_seop_flags = cpu_to_be32(V_FW_RIWR_OP(T3_WR_INIT));
843 wqe->wrh.gen_tid_len = cpu_to_be32(V_FW_RIWR_TID(attr->tid) |
844 V_FW_RIWR_LEN(sizeof(*wqe) >> 3));
846 wqe->qpid = cpu_to_be32(attr->qpid);
847 wqe->pdid = cpu_to_be32(attr->pdid);
848 wqe->scqid = cpu_to_be32(attr->scqid);
849 wqe->rcqid = cpu_to_be32(attr->rcqid);
850 wqe->rq_addr = cpu_to_be32(attr->rq_addr - rdev_p->rnic_info.rqt_base);
851 wqe->rq_size = cpu_to_be32(attr->rq_size);
852 wqe->mpaattrs = attr->mpaattrs;
853 wqe->qpcaps = attr->qpcaps;
854 wqe->ulpdu_size = cpu_to_be16(attr->tcp_emss);
855 wqe->rqe_count = cpu_to_be16(attr->rqe_count);
856 wqe->flags_rtr_type = cpu_to_be16(attr->flags |
857 V_RTR_TYPE(attr->rtr_type) |
859 wqe->ord = cpu_to_be32(attr->ord);
860 wqe->ird = cpu_to_be32(attr->ird);
861 wqe->qp_dma_addr = cpu_to_be64(attr->qp_dma_addr);
862 wqe->qp_dma_size = cpu_to_be32(attr->qp_dma_size);
863 wqe->irs = cpu_to_be32(attr->irs);
864 skb->priority = 0; /* 0=>ToeQ; 1=>CtrlQ */
865 return iwch_cxgb3_ofld_send(rdev_p->t3cdev_p, skb);
868 void cxio_register_ev_cb(cxio_hal_ev_callback_func_t ev_cb)
873 void cxio_unregister_ev_cb(cxio_hal_ev_callback_func_t ev_cb)
878 static int cxio_hal_ev_handler(struct t3cdev *t3cdev_p, struct sk_buff *skb)
881 struct cxio_rdev *rdev_p = NULL;
882 struct respQ_msg_t *rsp_msg = (struct respQ_msg_t *) skb->data;
883 PDBG("%d: %s cq_id 0x%x cq_ptr 0x%x genbit %0x overflow %0x an %0x"
884 " se %0x notify %0x cqbranch %0x creditth %0x\n",
885 cnt, __func__, RSPQ_CQID(rsp_msg), RSPQ_CQPTR(rsp_msg),
886 RSPQ_GENBIT(rsp_msg), RSPQ_OVERFLOW(rsp_msg), RSPQ_AN(rsp_msg),
887 RSPQ_SE(rsp_msg), RSPQ_NOTIFY(rsp_msg), RSPQ_CQBRANCH(rsp_msg),
888 RSPQ_CREDIT_THRESH(rsp_msg));
889 PDBG("CQE: QPID 0x%0x genbit %0x type 0x%0x status 0x%0x opcode %d "
890 "len 0x%0x wrid_hi_stag 0x%x wrid_low_msn 0x%x\n",
891 CQE_QPID(rsp_msg->cqe), CQE_GENBIT(rsp_msg->cqe),
892 CQE_TYPE(rsp_msg->cqe), CQE_STATUS(rsp_msg->cqe),
893 CQE_OPCODE(rsp_msg->cqe), CQE_LEN(rsp_msg->cqe),
894 CQE_WRID_HI(rsp_msg->cqe), CQE_WRID_LOW(rsp_msg->cqe));
895 rdev_p = (struct cxio_rdev *)t3cdev_p->ulp;
897 PDBG("%s called by t3cdev %p with null ulp\n", __func__,
901 if (CQE_QPID(rsp_msg->cqe) == T3_CTRL_QP_ID) {
902 rdev_p->ctrl_qp.rptr = CQE_WRID_LOW(rsp_msg->cqe) + 1;
903 wake_up_interruptible(&rdev_p->ctrl_qp.waitq);
904 dev_kfree_skb_irq(skb);
905 } else if (CQE_QPID(rsp_msg->cqe) == 0xfff8)
906 dev_kfree_skb_irq(skb);
908 (*cxio_ev_cb) (rdev_p, skb);
910 dev_kfree_skb_irq(skb);
915 /* Caller takes care of locking if needed */
916 int cxio_rdev_open(struct cxio_rdev *rdev_p)
918 struct net_device *netdev_p = NULL;
920 if (strlen(rdev_p->dev_name)) {
921 if (cxio_hal_find_rdev_by_name(rdev_p->dev_name)) {
924 netdev_p = dev_get_by_name(&init_net, rdev_p->dev_name);
929 } else if (rdev_p->t3cdev_p) {
930 if (cxio_hal_find_rdev_by_t3cdev(rdev_p->t3cdev_p)) {
933 netdev_p = rdev_p->t3cdev_p->lldev;
934 strncpy(rdev_p->dev_name, rdev_p->t3cdev_p->name,
935 T3_MAX_DEV_NAME_LEN);
937 PDBG("%s t3cdev_p or dev_name must be set\n", __func__);
941 list_add_tail(&rdev_p->entry, &rdev_list);
943 PDBG("%s opening rnic dev %s\n", __func__, rdev_p->dev_name);
944 memset(&rdev_p->ctrl_qp, 0, sizeof(rdev_p->ctrl_qp));
945 if (!rdev_p->t3cdev_p)
946 rdev_p->t3cdev_p = dev2t3cdev(netdev_p);
947 rdev_p->t3cdev_p->ulp = (void *) rdev_p;
949 err = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, GET_EMBEDDED_INFO,
952 printk(KERN_ERR "%s t3cdev_p(%p)->ctl returned error %d.\n",
953 __func__, rdev_p->t3cdev_p, err);
956 if (G_FW_VERSION_MAJOR(rdev_p->fw_info.fw_vers) != CXIO_FW_MAJ) {
957 printk(KERN_ERR MOD "fatal firmware version mismatch: "
958 "need version %u but adapter has version %u\n",
960 G_FW_VERSION_MAJOR(rdev_p->fw_info.fw_vers));
965 err = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, RDMA_GET_PARAMS,
966 &(rdev_p->rnic_info));
968 printk(KERN_ERR "%s t3cdev_p(%p)->ctl returned error %d.\n",
969 __func__, rdev_p->t3cdev_p, err);
972 err = rdev_p->t3cdev_p->ctl(rdev_p->t3cdev_p, GET_PORTS,
973 &(rdev_p->port_info));
975 printk(KERN_ERR "%s t3cdev_p(%p)->ctl returned error %d.\n",
976 __func__, rdev_p->t3cdev_p, err);
981 * qpshift is the number of bits to shift the qpid left in order
982 * to get the correct address of the doorbell for that qp.
984 cxio_init_ucontext(rdev_p, &rdev_p->uctx);
985 rdev_p->qpshift = PAGE_SHIFT -
987 ilog2(rdev_p->rnic_info.udbell_len >>
989 rdev_p->qpnr = rdev_p->rnic_info.udbell_len >> PAGE_SHIFT;
990 rdev_p->qpmask = (65536 >> ilog2(rdev_p->qpnr)) - 1;
991 PDBG("%s rnic %s info: tpt_base 0x%0x tpt_top 0x%0x num stags %d "
992 "pbl_base 0x%0x pbl_top 0x%0x rqt_base 0x%0x, rqt_top 0x%0x\n",
993 __func__, rdev_p->dev_name, rdev_p->rnic_info.tpt_base,
994 rdev_p->rnic_info.tpt_top, cxio_num_stags(rdev_p),
995 rdev_p->rnic_info.pbl_base,
996 rdev_p->rnic_info.pbl_top, rdev_p->rnic_info.rqt_base,
997 rdev_p->rnic_info.rqt_top);
998 PDBG("udbell_len 0x%0x udbell_physbase 0x%lx kdb_addr %p qpshift %lu "
999 "qpnr %d qpmask 0x%x\n",
1000 rdev_p->rnic_info.udbell_len,
1001 rdev_p->rnic_info.udbell_physbase, rdev_p->rnic_info.kdb_addr,
1002 rdev_p->qpshift, rdev_p->qpnr, rdev_p->qpmask);
1004 err = cxio_hal_init_ctrl_qp(rdev_p);
1006 printk(KERN_ERR "%s error %d initializing ctrl_qp.\n",
1010 err = cxio_hal_init_resource(rdev_p, cxio_num_stags(rdev_p), 0,
1011 0, T3_MAX_NUM_QP, T3_MAX_NUM_CQ,
1014 printk(KERN_ERR "%s error %d initializing hal resources.\n",
1018 err = cxio_hal_pblpool_create(rdev_p);
1020 printk(KERN_ERR "%s error %d initializing pbl mem pool.\n",
1024 err = cxio_hal_rqtpool_create(rdev_p);
1026 printk(KERN_ERR "%s error %d initializing rqt mem pool.\n",
1032 cxio_hal_pblpool_destroy(rdev_p);
1034 cxio_hal_destroy_resource(rdev_p->rscp);
1036 cxio_hal_destroy_ctrl_qp(rdev_p);
1038 rdev_p->t3cdev_p->ulp = NULL;
1039 list_del(&rdev_p->entry);
1043 void cxio_rdev_close(struct cxio_rdev *rdev_p)
1046 cxio_hal_pblpool_destroy(rdev_p);
1047 cxio_hal_rqtpool_destroy(rdev_p);
1048 list_del(&rdev_p->entry);
1049 cxio_hal_destroy_ctrl_qp(rdev_p);
1050 cxio_hal_destroy_resource(rdev_p->rscp);
1051 rdev_p->t3cdev_p->ulp = NULL;
1055 int __init cxio_hal_init(void)
1057 if (cxio_hal_init_rhdl_resource(T3_MAX_NUM_RI))
1059 t3_register_cpl_handler(CPL_ASYNC_NOTIF, cxio_hal_ev_handler);
1063 void __exit cxio_hal_exit(void)
1065 struct cxio_rdev *rdev, *tmp;
1067 t3_register_cpl_handler(CPL_ASYNC_NOTIF, NULL);
1068 list_for_each_entry_safe(rdev, tmp, &rdev_list, entry)
1069 cxio_rdev_close(rdev);
1070 cxio_hal_destroy_rhdl_resource();
1073 static void flush_completed_wrs(struct t3_wq *wq, struct t3_cq *cq)
1075 struct t3_swsq *sqp;
1076 __u32 ptr = wq->sq_rptr;
1077 int count = Q_COUNT(wq->sq_rptr, wq->sq_wptr);
1079 sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2);
1081 if (!sqp->signaled) {
1083 sqp = wq->sq + Q_PTR2IDX(ptr, wq->sq_size_log2);
1084 } else if (sqp->complete) {
1087 * Insert this completed cqe into the swcq.
1089 PDBG("%s moving cqe into swcq sq idx %ld cq idx %ld\n",
1090 __func__, Q_PTR2IDX(ptr, wq->sq_size_log2),
1091 Q_PTR2IDX(cq->sw_wptr, cq->size_log2));
1092 sqp->cqe.header |= htonl(V_CQE_SWCQE(1));
1093 *(cq->sw_queue + Q_PTR2IDX(cq->sw_wptr, cq->size_log2))
1102 static void create_read_req_cqe(struct t3_wq *wq, struct t3_cqe *hw_cqe,
1103 struct t3_cqe *read_cqe)
1105 read_cqe->u.scqe.wrid_hi = wq->oldest_read->sq_wptr;
1106 read_cqe->len = wq->oldest_read->read_len;
1107 read_cqe->header = htonl(V_CQE_QPID(CQE_QPID(*hw_cqe)) |
1108 V_CQE_SWCQE(SW_CQE(*hw_cqe)) |
1109 V_CQE_OPCODE(T3_READ_REQ) |
1114 * Return a ptr to the next read wr in the SWSQ or NULL.
1116 static void advance_oldest_read(struct t3_wq *wq)
1119 u32 rptr = wq->oldest_read - wq->sq + 1;
1120 u32 wptr = Q_PTR2IDX(wq->sq_wptr, wq->sq_size_log2);
1122 while (Q_PTR2IDX(rptr, wq->sq_size_log2) != wptr) {
1123 wq->oldest_read = wq->sq + Q_PTR2IDX(rptr, wq->sq_size_log2);
1125 if (wq->oldest_read->opcode == T3_READ_REQ)
1129 wq->oldest_read = NULL;
1136 * check the validity of the first CQE,
1137 * supply the wq assicated with the qpid.
1139 * credit: cq credit to return to sge.
1140 * cqe_flushed: 1 iff the CQE is flushed.
1141 * cqe: copy of the polled CQE.
1145 * -1 CQE skipped, try again.
1147 int cxio_poll_cq(struct t3_wq *wq, struct t3_cq *cq, struct t3_cqe *cqe,
1148 u8 *cqe_flushed, u64 *cookie, u32 *credit)
1151 struct t3_cqe *hw_cqe, read_cqe;
1155 hw_cqe = cxio_next_cqe(cq);
1157 PDBG("%s CQE OOO %d qpid 0x%0x genbit %d type %d status 0x%0x"
1158 " opcode 0x%0x len 0x%0x wrid_hi_stag 0x%x wrid_low_msn 0x%x\n",
1159 __func__, CQE_OOO(*hw_cqe), CQE_QPID(*hw_cqe),
1160 CQE_GENBIT(*hw_cqe), CQE_TYPE(*hw_cqe), CQE_STATUS(*hw_cqe),
1161 CQE_OPCODE(*hw_cqe), CQE_LEN(*hw_cqe), CQE_WRID_HI(*hw_cqe),
1162 CQE_WRID_LOW(*hw_cqe));
1165 * skip cqe's not affiliated with a QP.
1173 * Gotta tweak READ completions:
1174 * 1) the cqe doesn't contain the sq_wptr from the wr.
1175 * 2) opcode not reflected from the wr.
1176 * 3) read_len not reflected from the wr.
1177 * 4) cq_type is RQ_TYPE not SQ_TYPE.
1179 if (RQ_TYPE(*hw_cqe) && (CQE_OPCODE(*hw_cqe) == T3_READ_RESP)) {
1182 * If this is an unsolicited read response, then the read
1183 * was generated by the kernel driver as part of peer-2-peer
1184 * connection setup. So ignore the completion.
1186 if (!wq->oldest_read) {
1187 if (CQE_STATUS(*hw_cqe))
1194 * Don't write to the HWCQ, so create a new read req CQE
1197 create_read_req_cqe(wq, hw_cqe, &read_cqe);
1199 advance_oldest_read(wq);
1203 * T3A: Discard TERMINATE CQEs.
1205 if (CQE_OPCODE(*hw_cqe) == T3_TERMINATE) {
1211 if (CQE_STATUS(*hw_cqe) || wq->error) {
1212 *cqe_flushed = wq->error;
1216 * T3A inserts errors into the CQE. We cannot return
1217 * these as work completions.
1219 /* incoming write failures */
1220 if ((CQE_OPCODE(*hw_cqe) == T3_RDMA_WRITE)
1221 && RQ_TYPE(*hw_cqe)) {
1225 /* incoming read request failures */
1226 if ((CQE_OPCODE(*hw_cqe) == T3_READ_RESP) && SQ_TYPE(*hw_cqe)) {
1231 /* incoming SEND with no receive posted failures */
1232 if (CQE_SEND_OPCODE(*hw_cqe) && RQ_TYPE(*hw_cqe) &&
1233 Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) {
1237 BUG_ON((*cqe_flushed == 0) && !SW_CQE(*hw_cqe));
1244 if (RQ_TYPE(*hw_cqe)) {
1247 * HW only validates 4 bits of MSN. So we must validate that
1248 * the MSN in the SEND is the next expected MSN. If its not,
1249 * then we complete this with TPT_ERR_MSN and mark the wq in
1253 if (Q_EMPTY(wq->rq_rptr, wq->rq_wptr)) {
1259 if (unlikely((CQE_WRID_MSN(*hw_cqe) != (wq->rq_rptr + 1)))) {
1261 hw_cqe->header |= htonl(V_CQE_STATUS(TPT_ERR_MSN));
1268 * If we get here its a send completion.
1270 * Handle out of order completion. These get stuffed
1271 * in the SW SQ. Then the SW SQ is walked to move any
1272 * now in-order completions into the SW CQ. This handles
1274 * 1) reaping unsignaled WRs when the first subsequent
1275 * signaled WR is completed.
1276 * 2) out of order read completions.
1278 if (!SW_CQE(*hw_cqe) && (CQE_WRID_SQ_WPTR(*hw_cqe) != wq->sq_rptr)) {
1279 struct t3_swsq *sqp;
1281 PDBG("%s out of order completion going in swsq at idx %ld\n",
1283 Q_PTR2IDX(CQE_WRID_SQ_WPTR(*hw_cqe), wq->sq_size_log2));
1285 Q_PTR2IDX(CQE_WRID_SQ_WPTR(*hw_cqe), wq->sq_size_log2);
1296 * Reap the associated WR(s) that are freed up with this
1299 if (SQ_TYPE(*hw_cqe)) {
1300 wq->sq_rptr = CQE_WRID_SQ_WPTR(*hw_cqe);
1301 PDBG("%s completing sq idx %ld\n", __func__,
1302 Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2));
1303 *cookie = wq->sq[Q_PTR2IDX(wq->sq_rptr, wq->sq_size_log2)].wr_id;
1306 PDBG("%s completing rq idx %ld\n", __func__,
1307 Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2));
1308 *cookie = wq->rq[Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)].wr_id;
1309 if (wq->rq[Q_PTR2IDX(wq->rq_rptr, wq->rq_size_log2)].pbl_addr)
1310 cxio_hal_pblpool_free(wq->rdev,
1311 wq->rq[Q_PTR2IDX(wq->rq_rptr,
1312 wq->rq_size_log2)].pbl_addr, T3_STAG0_PBL_SIZE);
1313 BUG_ON(Q_EMPTY(wq->rq_rptr, wq->rq_wptr));
1319 * Flush any completed cqes that are now in-order.
1321 flush_completed_wrs(wq, cq);
1324 if (SW_CQE(*hw_cqe)) {
1325 PDBG("%s cq %p cqid 0x%x skip sw cqe sw_rptr 0x%x\n",
1326 __func__, cq, cq->cqid, cq->sw_rptr);
1329 PDBG("%s cq %p cqid 0x%x skip hw cqe rptr 0x%x\n",
1330 __func__, cq, cq->cqid, cq->rptr);
1334 * T3A: compute credits.
1336 if (((cq->rptr - cq->wptr) > (1 << (cq->size_log2 - 1)))
1337 || ((cq->rptr - cq->wptr) >= 128)) {
1338 *credit = cq->rptr - cq->wptr;
1339 cq->wptr = cq->rptr;