33 #include <linux/kernel.h>
35 #include <linux/device.h>
42 static char *rds_ib_wc_status_strings[] = {
43 #define RDS_IB_WC_STATUS_STR(foo) \
44 [IB_WC_##foo] = __stringify(IB_WC_##foo)
67 #undef RDS_IB_WC_STATUS_STR
80 static void rds_ib_send_complete(
struct rds_message *rm,
106 struct rm_data_op *
op,
110 ib_dma_unmap_sg(ic->
i_cm_id->device,
111 op->op_sg, op->op_nents,
116 struct rm_rdma_op *op,
120 ib_dma_unmap_sg(ic->
i_cm_id->device,
121 op->op_sg, op->op_nents,
156 struct rm_atomic_op *op,
161 ib_dma_unmap_sg(ic->
i_cm_id->device, op->op_sg, 1,
189 switch (send->
s_wr.opcode) {
193 rds_ib_send_unmap_data(ic, send->
s_op, wc_status);
200 rds_ib_send_unmap_rdma(ic, send->
s_op, wc_status);
207 rds_ib_send_unmap_atomic(ic, send->
s_op, wc_status);
212 "RDS/IB: %s: unexpected opcode 0x%x in WR!\n",
213 __func__, send->
s_wr.opcode);
217 send->
s_wr.opcode = 0xdead;
227 for (i = 0, send = ic->
i_sends; i < ic->i_send_ring.w_nr; i++, send++) {
232 send->
s_wr.wr_id =
i;
234 send->
s_wr.ex.imm_data = 0;
236 sge = &send->
s_sge[0];
250 for (i = 0, send = ic->
i_sends; i < ic->i_send_ring.w_nr; i++, send++) {
251 if (send->
s_op && send->
s_wr.opcode != 0xdead)
263 waitqueue_active(&rds_ib_ring_empty_wait))
264 wake_up(&rds_ib_ring_empty_wait);
287 rdsdebug(
"cq %p conn %p\n", cq, conn);
291 rdsdebug(
"ib_req_notify_cq send failed: %d\n", ret);
293 while (ib_poll_cq(cq, 1, &wc) > 0) {
294 rdsdebug(
"wc wr_id 0x%llx status %u (%s) byte_len %u imm_data %u\n",
316 rm = rds_ib_send_unmap_op(ic, send, wc.
status);
335 rds_ib_sub_signaled(ic, nr_sig);
345 "%u (%s), disconnecting and reconnecting\n",
397 u32 wanted,
u32 *adv_credits,
int need_posted,
int max_posted)
399 unsigned int avail, posted, got = 0, advertise;
412 rdsdebug(
"rds_ib_send_grab_credits(%u): credits=%u posted=%u\n",
413 wanted, avail, posted);
416 if (avail && !posted)
419 if (avail < wanted) {
436 if (posted && (got || need_posted)) {
437 advertise =
min_t(
unsigned int, posted, max_posted);
445 *adv_credits = advertise;
456 rdsdebug(
"rds_ib_send_add_credits(%u): current=%u%s\n",
526 unsigned int hdr_off,
unsigned int sg,
unsigned int off)
538 u32 credit_alloc = 0;
544 int flow_controlled = 0;
554 scat = &rm->
data.op_sg[
sg];
555 ret =
sizeof(
struct rds_header) + RDS_CONG_MAP_BYTES;
567 if (work_alloc == 0) {
576 adv_credits += posted;
577 if (credit_alloc < work_alloc) {
579 work_alloc = credit_alloc;
582 if (work_alloc == 0) {
592 if (rm->
data.op_nents) {
593 rm->
data.op_count = ib_dma_map_sg(dev,
597 rdsdebug(
"ic %p mapping rm %p: %d\n", ic, rm, rm->
data.op_count);
598 if (rm->
data.op_count == 0) {
605 rm->
data.op_count = 0;
619 if (rm->
rdma.op_active) {
637 rds_message_make_checksum(&rm->
m_inc.i_hdr);
644 adv_credits += posted;
645 BUG_ON(adv_credits > 255);
655 if (rm->
rdma.op_active && rm->
rdma.op_fence)
665 unsigned int len = 0;
668 send->
s_wr.send_flags = send_flags;
670 send->
s_wr.num_sge = 1;
683 && scat != &rm->
data.op_sg[rm->
data.op_count]) {
684 len =
min(RDS_FRAG_SIZE, ib_sg_dma_len(dev, scat) - off);
685 send->
s_wr.num_sge = 2;
687 send->
s_sge[1].addr = ib_sg_dma_address(dev, scat) + off;
688 send->
s_sge[1].length = len;
692 if (off == ib_sg_dma_len(dev, scat)) {
698 rds_ib_set_wr_signal_state(ic, send, 0);
703 if (ic->
i_flowctl && flow_controlled && i == (work_alloc-1))
709 rdsdebug(
"send %p wr %p num_sge %u next %p\n", send,
717 rds_message_make_checksum(hdr);
730 }
while (i < work_alloc
731 && scat != &rm->
data.op_sg[rm->
data.op_count]);
739 if (scat == &rm->
data.op_sg[rm->
data.op_count]) {
746 if (i < work_alloc) {
757 failed_wr = &first->
s_wr;
758 ret = ib_post_send(ic->
i_cm_id->qp, &first->
s_wr, &failed_wr);
759 rdsdebug(
"ic %p first %p (wr %p) ret %d wr %p\n", ic,
760 first, &first->
s_wr, ret, failed_wr);
764 "returned %d\n", &conn->
c_faddr, ret);
766 rds_ib_sub_signaled(ic, nr_sig);
801 if (work_alloc != 1) {
814 send->
s_wr.wr.atomic.compare_add = op->op_m_cswp.compare;
815 send->
s_wr.wr.atomic.swap = op->op_m_cswp.swap;
816 send->
s_wr.wr.atomic.compare_add_mask = op->op_m_cswp.compare_mask;
817 send->
s_wr.wr.atomic.swap_mask = op->op_m_cswp.swap_mask;
820 send->
s_wr.wr.atomic.compare_add = op->op_m_fadd.add;
821 send->
s_wr.wr.atomic.swap = 0;
822 send->
s_wr.wr.atomic.compare_add_mask = op->op_m_fadd.nocarry_mask;
823 send->
s_wr.wr.atomic.swap_mask = 0;
825 nr_sig = rds_ib_set_wr_signal_state(ic, send, op->op_notify);
826 send->
s_wr.num_sge = 1;
828 send->
s_wr.wr.atomic.remote_addr = op->op_remote_addr;
829 send->
s_wr.wr.atomic.rkey = op->op_rkey;
835 rdsdebug(
"ic %p mapping atomic op %p. mapped %d pg\n", ic, op, ret);
844 send->
s_sge[0].addr = ib_sg_dma_address(ic->
i_cm_id->device, op->op_sg);
845 send->
s_sge[0].length = ib_sg_dma_len(ic->
i_cm_id->device, op->op_sg);
848 rdsdebug(
"rva %Lx rpa %Lx len %u\n", op->op_remote_addr,
854 failed_wr = &send->
s_wr;
855 ret = ib_post_send(ic->
i_cm_id->qp, &send->
s_wr, &failed_wr);
856 rdsdebug(
"ic %p send %p (wr %p) ret %d wr %p\n", ic,
857 send, &send->
s_wr, ret, failed_wr);
861 "returned %d\n", &conn->
c_faddr, ret);
863 rds_ib_sub_signaled(ic, nr_sig);
868 printk(
KERN_WARNING "RDS/IB: atomic ib_post_send() rc=%d, but failed_wqe updated!\n", ret);
897 if (!op->op_mapped) {
898 op->op_count = ib_dma_map_sg(ic->
i_cm_id->device,
899 op->op_sg, op->op_nents, (op->op_write) ?
901 rdsdebug(
"ic %p mapping op %p: %d\n", ic, op, op->op_count);
902 if (op->op_count == 0) {
915 i =
ceil(op->op_count, max_sge);
918 if (work_alloc != i) {
928 scat = &op->op_sg[0];
930 num_sge = op->op_count;
932 for (i = 0; i < work_alloc && scat != &op->op_sg[op->op_count]; i++) {
933 send->
s_wr.send_flags = 0;
937 nr_sig += rds_ib_set_wr_signal_state(ic, send, op->op_notify);
941 send->
s_wr.wr.rdma.rkey = op->op_rkey;
943 if (num_sge > max_sge) {
947 send->
s_wr.num_sge = num_sge;
955 for (j = 0; j < send->
s_wr.num_sge && scat != &op->op_sg[op->op_count]; j++) {
956 len = ib_sg_dma_len(ic->
i_cm_id->device, scat);
958 ib_sg_dma_address(ic->
i_cm_id->device, scat);
959 send->
s_sge[
j].length = len;
963 rdsdebug(
"ic %p sent %d remote_addr %llu\n", ic, sent, remote_addr);
969 rdsdebug(
"send %p wr %p num_sge %u next %p\n", send,
978 if (scat == &op->op_sg[op->op_count]) {
983 if (i < work_alloc) {
991 failed_wr = &first->
s_wr;
992 ret = ib_post_send(ic->
i_cm_id->qp, &first->
s_wr, &failed_wr);
993 rdsdebug(
"ic %p first %p (wr %p) ret %d wr %p\n", ic,
994 first, &first->
s_wr, ret, failed_wr);
998 "returned %d\n", &conn->
c_faddr, ret);
1000 rds_ib_sub_signaled(ic, nr_sig);