33 #include <linux/module.h>
37 static int db_delay_usecs = 1;
39 MODULE_PARM_DESC(db_delay_usecs,
"Usecs to delay awaiting db fifo to drain");
41 static int ocqp_support = 1;
48 "db flow control mode (default = 2000)");
55 spin_unlock_irqrestore(&qhp->
lock, flag);
72 dealloc_oc_sq(rdev, sq);
74 dealloc_host_sq(rdev, sq);
79 if (!ocqp_support || !t4_ocqp_supported())
85 rdev->
lldi.vr->ocq.start;
87 rdev->
lldi.vr->ocq.start);
111 wq->
rq.memsize, wq->
rq.queue,
113 dealloc_sq(rdev, &wq->
sq);
146 wq->
sq.sw_sq = kzalloc(wq->
sq.size *
sizeof *wq->
sq.sw_sq,
153 wq->
rq.sw_rq = kzalloc(wq->
rq.size *
sizeof *wq->
rq.sw_rq,
166 if (!wq->
rq.rqt_hwaddr) {
172 ret = alloc_oc_sq(rdev, &wq->
sq);
176 ret = alloc_host_sq(rdev, &wq->
sq);
180 ret = alloc_host_sq(rdev, &wq->
sq);
187 wq->
rq.memsize, &(wq->
rq.dma_addr),
191 PDBG(
"%s sq base va 0x%p pa 0x%llx rq base va 0x%p pa 0x%llx\n",
192 __func__, wq->
sq.queue,
199 wq->
db = rdev->
lldi.db_reg;
213 wr_len =
sizeof *res_wr + 2 *
sizeof *
res;
223 memset(res_wr, 0, wr_len);
279 c4iw_init_wr_wait(&wr_wait);
284 ret = c4iw_wait_for_reply(rdev, &wr_wait, 0, wq->
sq.qid, __func__);
288 PDBG(
"%s sqid 0x%x rqid 0x%x kdb 0x%p squdb 0x%llx rqudb 0x%llx\n",
289 __func__, wq->
sq.qid, wq->
rq.qid, wq->
db,
290 (
unsigned long long)wq->
sq.udb, (
unsigned long long)wq->
rq.udb);
295 wq->
rq.memsize, wq->
rq.queue,
298 dealloc_sq(rdev, &wq->
sq);
324 srcp = (
u8 *)(
unsigned long)wr->
sg_list[
i].addr;
340 len =
roundup(plen +
sizeof *immdp, 16) - (plen +
sizeof *immdp);
353 int num_sge,
u32 *plenp)
360 for (i = 0; i < num_sge; i++) {
366 if (++flitp == queue_end)
369 if (++flitp == queue_end)
382 static int build_rdma_send(
struct t4_sq *sq,
union t4_wr *wqe,
399 wqe->
send.stag_inv = 0;
418 ret = build_immd(sq, wqe->
send.u.immd_src, wr,
427 wqe->
send.u.isgl_src,
436 wqe->
send.u.immd_src[0].r1 = 0;
437 wqe->
send.u.immd_src[0].r2 = 0;
438 wqe->
send.u.immd_src[0].immdlen = 0;
447 static int build_rdma_write(
struct t4_sq *sq,
union t4_wr *wqe,
461 ret = build_immd(sq, wqe->
write.u.immd_src, wr,
470 wqe->
write.u.isgl_src,
479 wqe->
write.u.immd_src[0].r1 = 0;
480 wqe->
write.u.immd_src[0].r2 = 0;
481 wqe->
write.u.immd_src[0].immdlen = 0;
506 wqe->
read.to_src_hi = 0;
507 wqe->
read.to_src_lo = 0;
510 wqe->
read.to_sink_hi = 0;
511 wqe->
read.to_sink_lo = 0;
524 ret = build_isgl((
__be64 *)qhp->
wq.rq.queue,
534 static int build_fastreg(
struct t4_sq *sq,
union t4_wr *wqe,
547 wqe->
fr.qpbinde_to_dcacpu = 0;
550 wqe->
fr.mem_perms = c4iw_ib_to_tpt_access(wr->
wr.
fast_reg.access_flags);
565 for (i = 0; i < wr->
wr.
fast_reg.page_list_len; i++) {
578 *len16 =
DIV_ROUND_UP(
sizeof wqe->
fr +
sizeof *imdp + pbllen, 16);
593 PDBG(
"%s ib_qp %p\n", __func__, qp);
599 PDBG(
"%s ib_qp %p\n", __func__, qp);
618 qhp = to_c4iw_qp(ibqp);
620 if (t4_wq_in_error(&qhp->
wq)) {
621 spin_unlock_irqrestore(&qhp->
lock, flag);
624 num_wrs = t4_sq_avail(&qhp->
wq);
626 spin_unlock_irqrestore(&qhp->
lock, flag);
635 wqe = (
union t4_wr *)((
u8 *)qhp->
wq.sq.queue +
643 swsqe = &qhp->
wq.sq.sw_sq[qhp->
wq.sq.pidx];
654 err = build_rdma_send(&qhp->
wq.sq, wqe, wr, &len16);
659 err = build_rdma_write(&qhp->
wq.sq, wqe, wr, &len16);
669 err = build_rdma_read(wqe, wr, &len16);
673 if (!qhp->
wq.sq.oldest_read)
674 qhp->
wq.sq.oldest_read = swsqe;
679 err = build_fastreg(&qhp->
wq.sq, wqe, wr, &len16);
686 err = build_inv_stag(wqe, wr, &len16);
689 PDBG(
"%s post of type=%d TBD!\n", __func__,
697 swsqe->
idx = qhp->
wq.sq.pidx;
702 init_wr_hdr(wqe, qhp->
wq.sq.pidx, fw_opcode, fw_flags, len16);
704 PDBG(
"%s cookie 0x%llx pidx 0x%x opcode 0x%x read_len %u\n",
705 __func__, (
unsigned long long)wr->
wr_id, qhp->
wq.sq.pidx,
709 t4_sq_produce(&qhp->
wq, len16);
712 if (t4_wq_db_enabled(&qhp->
wq))
713 t4_ring_sq_db(&qhp->
wq, idx);
714 spin_unlock_irqrestore(&qhp->
lock, flag);
729 qhp = to_c4iw_qp(ibqp);
731 if (t4_wq_in_error(&qhp->
wq)) {
732 spin_unlock_irqrestore(&qhp->
lock, flag);
735 num_wrs = t4_rq_avail(&qhp->
wq);
737 spin_unlock_irqrestore(&qhp->
lock, flag);
750 err = build_rdma_recv(qhp, wqe, wr, &len16);
758 qhp->
wq.rq.sw_rq[qhp->
wq.rq.pidx].wr_id = wr->
wr_id;
762 wqe->
recv.wrid = qhp->
wq.rq.pidx;
766 wqe->
recv.len16 = len16;
767 PDBG(
"%s cookie 0x%llx pidx %u\n", __func__,
768 (
unsigned long long) wr->
wr_id, qhp->
wq.rq.pidx);
769 t4_rq_produce(&qhp->
wq, len16);
774 if (t4_wq_db_enabled(&qhp->
wq))
775 t4_ring_rq_db(&qhp->
wq, idx);
776 spin_unlock_irqrestore(&qhp->
lock, flag);
785 static inline void build_term_codes(
struct t4_cqe *err_cqe,
u8 *layer_type,
921 static void post_terminate(
struct c4iw_qp *qhp,
struct t4_cqe *err_cqe,
928 PDBG(
"%s qhp %p qid 0x%x tid %u\n", __func__, qhp, qhp->
wq.sq.qid,
931 skb = alloc_skb(
sizeof *wqe, gfp);
936 wqe = (
struct fw_ri_wr *)__skb_put(skb,
sizeof(*wqe));
937 memset(wqe, 0,
sizeof *wqe);
964 PDBG(
"%s qhp %p rchp %p schp %p\n", __func__, qhp, rchp, schp);
968 spin_lock(&qhp->
lock);
972 spin_unlock(&qhp->
lock);
973 spin_unlock_irqrestore(&rchp->
lock, flag);
976 (*rchp->
ibcq.comp_handler)(&rchp->
ibcq, rchp->
ibcq.cq_context);
982 spin_lock(&qhp->
lock);
986 spin_unlock(&qhp->
lock);
987 spin_unlock_irqrestore(&schp->
lock, flag);
990 (*schp->
ibcq.comp_handler)(&schp->
ibcq, schp->
ibcq.cq_context);
995 static void flush_qp(
struct c4iw_qp *qhp)
1000 rchp = get_chp(qhp->
rhp, qhp->
attr.rcq);
1001 schp = get_chp(qhp->
rhp, qhp->
attr.scq);
1003 if (qhp->
ibqp.uobject) {
1004 t4_set_wq_in_error(&qhp->
wq);
1005 t4_set_cq_in_error(&rchp->
cq);
1007 (*rchp->
ibcq.comp_handler)(&rchp->
ibcq, rchp->
ibcq.cq_context);
1010 t4_set_cq_in_error(&schp->
cq);
1012 (*schp->
ibcq.comp_handler)(&schp->
ibcq,
1013 schp->
ibcq.cq_context);
1018 __flush_qp(qhp, rchp, schp);
1028 PDBG(
"%s qhp %p qid 0x%x tid %u\n", __func__, qhp, qhp->
wq.sq.qid,
1036 wqe = (
struct fw_ri_wr *)__skb_put(skb,
sizeof(*wqe));
1037 memset(wqe, 0,
sizeof *wqe);
1051 ret = c4iw_wait_for_reply(&rhp->
rdev, &ep->
com.wr_wait, qhp->
ep->hwtid,
1052 qhp->
wq.sq.qid, __func__);
1054 PDBG(
"%s ret %d\n", __func__, ret);
1058 static void build_rtr_msg(
u8 p2p_type,
struct fw_ri_init *
init)
1060 PDBG(
"%s p2p_type = %d\n", __func__, p2p_type);
1061 memset(&init->u, 0,
sizeof init->u);
1068 init->u.write.len16 =
DIV_ROUND_UP(
sizeof init->u.write +
1078 init->u.read.len16 =
DIV_ROUND_UP(
sizeof init->u.read, 16);
1089 PDBG(
"%s qhp %p qid 0x%x tid %u\n", __func__, qhp, qhp->
wq.sq.qid,
1097 wqe = (
struct fw_ri_wr *)__skb_put(skb,
sizeof(*wqe));
1098 memset(wqe, 0,
sizeof *wqe);
1109 wqe->
u.
init.mpareqbit_p2ptype =
1113 if (qhp->
attr.mpa_attr.recv_marker_enabled)
1115 if (qhp->
attr.mpa_attr.xmit_marker_enabled)
1117 if (qhp->
attr.mpa_attr.crc_enabled)
1123 if (!qhp->
ibqp.uobject)
1139 rhp->
rdev.lldi.vr->rq.start);
1140 if (qhp->
attr.mpa_attr.initiator)
1141 build_rtr_msg(qhp->
attr.mpa_attr.p2p_type, &wqe->
u.
init);
1147 ret = c4iw_wait_for_reply(&rhp->
rdev, &qhp->
ep->com.wr_wait,
1148 qhp->
ep->hwtid, qhp->
wq.sq.qid, __func__);
1150 PDBG(
"%s ret %d\n", __func__, ret);
1161 int delay = db_delay_usecs;
1171 (qhp->
rhp->rdev.lldi.dbfifo_int_thresh << 5)) {
1177 delay =
min(delay << 1, 2000);
1196 PDBG(
"%s qhp %p sqid 0x%x rqid 0x%x ep %p state %d -> %d\n", __func__,
1197 qhp, qhp->
wq.sq.qid, qhp->
wq.rq.qid, qhp->
ep, qhp->
attr.state,
1228 qhp->
attr = newattr;
1232 ret = ring_kernel_db(qhp, qhp->
wq.sq.qid, attrs->
sq_db_inc);
1236 ret = ring_kernel_db(qhp, qhp->
wq.rq.qid, attrs->
rq_db_inc);
1240 if (!(mask & C4IW_QP_ATTR_NEXT_STATE))
1245 switch (qhp->
attr.state) {
1259 qhp->
ep = qhp->
attr.llp_stream_handle;
1269 ret = rdma_init(rhp, qhp);
1293 if (qhp->
ibqp.uobject)
1294 t4_set_wq_in_error(&qhp->
wq);
1295 ret = rdma_fini(rhp, qhp, ep);
1303 if (qhp->
ibqp.uobject)
1304 t4_set_wq_in_error(&qhp->
wq);
1313 if (qhp->
ibqp.uobject)
1314 t4_set_wq_in_error(&qhp->
wq);
1337 qhp->
attr.llp_stream_handle =
NULL;
1354 if (!t4_sq_empty(&qhp->
wq) || !t4_rq_empty(&qhp->
wq)) {
1369 __func__, qhp->
attr.state);
1376 PDBG(
"%s disassociating ep %p qpid 0x%x\n", __func__, qhp->
ep,
1380 qhp->
attr.llp_stream_handle =
NULL;
1412 PDBG(
"%s exit state %d\n", __func__, qhp->
attr.state);
1416 static int enable_qp_db(
int id,
void *p,
void *
data)
1420 t4_enable_wq_db(&qp->
wq);
1431 qhp = to_c4iw_qp(ib_qp);
1441 spin_lock_irq(&rhp->
lock);
1442 remove_handle_nolock(rhp, &rhp->
qpidr, qhp->
wq.sq.qid);
1446 rhp->
rdev.stats.db_state_transitions++;
1450 spin_unlock_irq(&rhp->
lock);
1456 destroy_qp(&rhp->
rdev, &qhp->
wq,
1457 ucontext ? &ucontext->
uctx : &rhp->
rdev.uctx);
1459 PDBG(
"%s ib_qp %p qpid 0x%0x\n", __func__, ib_qp, qhp->
wq.sq.qid);
1464 static int disable_qp_db(
int id,
void *p,
void *
data)
1468 t4_disable_wq_db(&qp->
wq);
1486 PDBG(
"%s ib_pd %p\n", __func__, pd);
1491 php = to_c4iw_pd(pd);
1493 schp = get_chp(rhp, ((
struct c4iw_cq *)attrs->
send_cq)->cq.cqid);
1494 rchp = get_chp(rhp, ((
struct c4iw_cq *)attrs->
recv_cq)->cq.cqid);
1501 rqsize =
roundup(attrs->
cap.max_recv_wr + 1, 16);
1503 return ERR_PTR(-
E2BIG);
1505 sqsize =
roundup(attrs->
cap.max_send_wr + 1, 16);
1507 return ERR_PTR(-
E2BIG);
1515 qhp->
wq.sq.size = sqsize;
1516 qhp->
wq.sq.memsize = (sqsize + 1) *
sizeof *qhp->
wq.sq.queue;
1517 qhp->
wq.rq.size = rqsize;
1518 qhp->
wq.rq.memsize = (rqsize + 1) *
sizeof *qhp->
wq.rq.queue;
1525 PDBG(
"%s sqsize %u sqmemsize %zu rqsize %u rqmemsize %zu\n",
1526 __func__, sqsize, qhp->
wq.sq.memsize, rqsize, qhp->
wq.rq.memsize);
1528 ret = create_qp(&rhp->
rdev, &qhp->
wq, &schp->
cq, &rchp->
cq,
1529 ucontext ? &ucontext->
uctx : &rhp->
rdev.uctx);
1533 attrs->
cap.max_recv_wr = rqsize - 1;
1534 attrs->
cap.max_send_wr = sqsize - 1;
1541 qhp->
attr.sq_num_entries = attrs->
cap.max_send_wr;
1542 qhp->
attr.rq_num_entries = attrs->
cap.max_recv_wr;
1543 qhp->
attr.sq_max_sges = attrs->
cap.max_send_sge;
1544 qhp->
attr.sq_max_sges_rdma_write = attrs->
cap.max_send_sge;
1545 qhp->
attr.rq_max_sges = attrs->
cap.max_recv_sge;
1548 qhp->
attr.enable_rdma_read = 1;
1549 qhp->
attr.enable_rdma_write = 1;
1550 qhp->
attr.enable_bind = 1;
1551 qhp->
attr.max_ord = 1;
1552 qhp->
attr.max_ird = 1;
1558 spin_lock_irq(&rhp->
lock);
1560 t4_disable_wq_db(&qhp->
wq);
1562 rhp->
rdev.stats.db_state_transitions++;
1566 ret = insert_handle_nolock(rhp, &rhp->
qpidr, qhp, qhp->
wq.sq.qid);
1567 spin_unlock_irq(&rhp->
lock);
1592 if (t4_sq_onchip(&qhp->
wq.sq)) {
1602 uresp.
sqid = qhp->
wq.sq.qid;
1605 uresp.
rqid = qhp->
wq.rq.qid;
1622 ret = ib_copy_to_udata(udata, &uresp,
sizeof uresp);
1626 mm1->
addr = qhp->
wq.sq.phys_addr;
1628 insert_mmap(ucontext, mm1);
1632 insert_mmap(ucontext, mm2);
1634 mm3->
addr = qhp->
wq.sq.udb;
1636 insert_mmap(ucontext, mm3);
1638 mm4->
addr = qhp->
wq.rq.udb;
1640 insert_mmap(ucontext, mm4);
1646 insert_mmap(ucontext, mm5);
1649 qhp->
ibqp.qp_num = qhp->
wq.sq.qid;
1651 PDBG(
"%s qhp %p sq_num_entries %d, rq_num_entries %d qpid 0x%0x\n",
1652 __func__, qhp, qhp->
attr.sq_num_entries, qhp->
attr.rq_num_entries,
1666 remove_handle(rhp, &rhp->
qpidr, qhp->
wq.sq.qid);
1668 destroy_qp(&rhp->
rdev, &qhp->
wq,
1669 ucontext ? &ucontext->
uctx : &rhp->
rdev.uctx);
1672 return ERR_PTR(ret);
1676 int attr_mask,
struct ib_udata *udata)
1683 PDBG(
"%s ib_qp %p\n", __func__, ibqp);
1687 attr_mask &= ~IB_QP_STATE;
1693 memset(&attrs, 0,
sizeof attrs);
1694 qhp = to_c4iw_qp(ibqp);
1725 PDBG(
"%s ib_dev %p qpn 0x%x\n", __func__, dev, qpn);
1726 return (
struct ib_qp *)get_qhp(to_c4iw_dev(dev), qpn);
1732 struct c4iw_qp *qhp = to_c4iw_qp(ibqp);
1734 memset(attr, 0,
sizeof *attr);
1735 memset(init_attr, 0,
sizeof *init_attr);