33 #include <linux/kernel.h>
35 #include <linux/device.h>
42 static void rds_iw_send_rdma_complete(
struct rds_message *rm,
67 struct rm_rdma_op *
op)
70 ib_dma_unmap_sg(ic->
i_cm_id->device,
71 op->op_sg, op->op_nents,
83 rdsdebug(
"ic %p send %p rm %p\n", ic, send, rm);
85 ib_dma_unmap_sg(ic->
i_cm_id->device,
89 if (rm->
rdma.op_active) {
90 rds_iw_send_unmap_rdma(ic, &rm->
rdma);
112 rds_iw_send_rdma_complete(rm, wc_status);
114 if (rm->
rdma.op_write)
133 for (i = 0, send = ic->
i_sends; i < ic->i_send_ring.w_nr; i++, send++) {
141 send->
s_wr.wr_id =
i;
143 send->
s_wr.num_sge = 1;
145 send->
s_wr.send_flags = 0;
146 send->
s_wr.ex.imm_data = 0;
148 sge = rds_iw_data_sge(ic, send->
s_sge);
151 sge = rds_iw_header_sge(ic, send->
s_sge);
157 if (IS_ERR(send->
s_mr)) {
176 for (i = 0, send = ic->
i_sends; i < ic->i_send_ring.w_nr; i++, send++) {
181 if (send->
s_wr.opcode == 0xdead)
186 rds_iw_send_unmap_rdma(ic, send->
s_op);
207 rdsdebug(
"cq %p conn %p\n", cq, conn);
211 rdsdebug(
"ib_req_notify_cq send failed: %d\n", ret);
213 while (ib_poll_cq(cq, 1, &wc) > 0) {
214 rdsdebug(
"wc wr_id 0x%llx status %u byte_len %u imm_data %u\n",
249 switch (send->
s_wr.opcode) {
252 rds_iw_send_unmap_rm(ic, send, wc.
status);
263 "RDS/IW: %s: unexpected opcode 0x%x in WR!\n",
264 __func__, send->
s_wr.opcode);
268 send->
s_wr.opcode = 0xdead;
269 send->
s_wr.num_sge = 1;
282 rds_iw_send_rdma_complete(rm, wc.
status);
297 "send completion on %pI4 "
298 "had status %u, disconnecting and reconnecting\n",
349 u32 wanted,
u32 *adv_credits,
int need_posted,
int max_posted)
351 unsigned int avail, posted, got = 0, advertise;
364 rdsdebug(
"rds_iw_send_grab_credits(%u): credits=%u posted=%u\n",
365 wanted, avail, posted);
368 if (avail && !posted)
371 if (avail < wanted) {
388 if (posted && (got || need_posted)) {
389 advertise =
min_t(
unsigned int, posted, max_posted);
397 *adv_credits = advertise;
408 rdsdebug(
"rds_iw_send_add_credits(%u): current=%u%s\n",
457 send->
s_wr.send_flags = send_flags;
459 send->
s_wr.num_sge = 2;
465 sge = rds_iw_data_sge(ic, send->
s_sge);
468 sge->
lkey = rds_iw_local_dma_lkey(ic);
470 sge = rds_iw_header_sge(ic, send->
s_sge);
474 send->
s_wr.num_sge = 1;
475 sge = &send->
s_sge[0];
480 sge->
lkey = rds_iw_local_dma_lkey(ic);
497 unsigned int hdr_off,
unsigned int sg,
unsigned int off)
515 int flow_controlled = 0;
533 if (work_alloc == 0) {
540 credit_alloc = work_alloc;
543 adv_credits += posted;
544 if (credit_alloc < work_alloc) {
546 work_alloc = credit_alloc;
549 if (work_alloc == 0) {
565 if (rm->
data.op_nents) {
566 rm->
data.op_count = ib_dma_map_sg(dev,
570 rdsdebug(
"ic %p mapping rm %p: %d\n", ic, rm, rm->
data.op_count);
571 if (rm->
data.op_count == 0) {
578 rm->
data.op_count = 0;
594 if (rm->
rdma.op_active) {
612 rds_message_make_checksum(&rm->
m_inc.i_hdr);
618 adv_credits += posted;
619 BUG_ON(adv_credits > 255);
625 scat = &rm->
data.op_sg[
sg];
635 if (rm->
rdma.op_active && rm->
rdma.op_fence)
649 rds_iw_xmit_populate_wr(ic, send, pos, 0, 0, send_flags);
654 for (; i < work_alloc && scat != &rm->
data.op_sg[rm->
data.op_count]; i++) {
659 len =
min(RDS_FRAG_SIZE, ib_sg_dma_len(dev, scat) - off);
660 rds_iw_xmit_populate_wr(ic, send, pos,
661 ib_sg_dma_address(dev, scat) + off, len,
683 if (flow_controlled && i == (work_alloc-1))
686 rdsdebug(
"send %p wr %p num_sge %u next %p\n", send,
691 if (off == ib_sg_dma_len(dev, scat)) {
714 rds_message_make_checksum(hdr);
732 if (scat == &rm->
data.op_sg[rm->
data.op_count]) {
738 if (i < work_alloc) {
746 failed_wr = &first->
s_wr;
747 ret = ib_post_send(ic->
i_cm_id->qp, &first->
s_wr, &failed_wr);
748 rdsdebug(
"ic %p first %p (wr %p) ret %d wr %p\n", ic,
749 first, &first->
s_wr, ret, failed_wr);
753 "returned %d\n", &conn->
c_faddr, ret);
777 send->
s_wr.wr.fast_reg.length = len;
778 send->
s_wr.wr.fast_reg.rkey = send->
s_mr->rkey;
780 send->
s_wr.wr.fast_reg.page_list_len = nent;
783 send->
s_wr.wr.fast_reg.iova_start = sg_addr;
810 if (!op->op_mapped) {
811 op->op_count = ib_dma_map_sg(ic->
i_cm_id->device,
812 op->op_sg, op->op_nents, (op->op_write) ?
814 rdsdebug(
"ic %p mapping op %p: %d\n", ic, op, op->op_count);
815 if (op->op_count == 0) {
827 if (work_alloc != 1) {
842 if (work_alloc != i) {
851 first = prev = &ic->
i_sends[fr_pos];
856 scat = &op->op_sg[0];
858 num_sge = op->op_count;
860 for (i = 0; i < work_alloc && scat != &op->op_sg[op->op_count]; i++) {
861 send->
s_wr.send_flags = 0;
883 send->
s_wr.wr.rdma.rkey = op->op_rkey;
886 if (num_sge > rds_iwdev->
max_sge) {
890 send->
s_wr.num_sge = num_sge;
897 for (j = 0; j < send->
s_wr.num_sge && scat != &op->op_sg[op->op_count]; j++) {
898 len = ib_sg_dma_len(ic->
i_cm_id->device, scat);
903 send->
s_sge[
j].addr = ib_sg_dma_address(ic->
i_cm_id->device, scat);
904 send->
s_sge[
j].length = len;
905 send->
s_sge[
j].lkey = rds_iw_local_dma_lkey(ic);
909 rdsdebug(
"ic %p sent %d remote_addr %llu\n", ic, sent, remote_addr);
916 send->
s_wr.num_sge = 1;
922 rdsdebug(
"send %p wr %p num_sge %u next %p\n", send,
931 if (scat == &op->op_sg[op->op_count])
934 if (i < work_alloc) {
946 rds_iw_build_send_fastreg(rds_iwdev, ic, &ic->
i_sends[fr_pos],
947 op->op_count, sent, conn->
c_xmit_rm->m_rs->rs_user_addr);
951 failed_wr = &first->
s_wr;
952 ret = ib_post_send(ic->
i_cm_id->qp, &first->
s_wr, &failed_wr);
953 rdsdebug(
"ic %p first %p (wr %p) ret %d wr %p\n", ic,
954 first, &first->
s_wr, ret, failed_wr);
958 "returned %d\n", &conn->
c_faddr, ret);