33 #include <linux/kernel.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
42 static struct kmem_cache *rds_ib_incoming_slab;
51 for (i = 0, recv = ic->
i_recvs; i < ic->i_recv_ring.w_nr; i++, recv++) {
62 sge = &recv->
r_sge[0];
67 sge = &recv->
r_sge[1];
83 list_splice_tail(from_last, to);
94 list_splice_entire_tail(tmp, cache->
ready);
143 list_splice_entire_tail(head->
first, caller_list);
149 list_splice_entire_tail(cache->
ready, caller_list);
184 static void rds_ib_recv_cache_put(
struct list_head *new_item,
193 rdsdebug(
"frag %p page %p\n", frag, sg_page(&frag->
f_sg));
210 list_del_init(&frag->
f_item);
211 rds_ib_frag_free(ic, frag);
215 rdsdebug(
"freeing ibinc %p inc %p\n", ibinc, inc);
228 rds_ib_frag_free(ic, recv->
r_frag);
238 rds_ib_recv_clear_one(ic, &ic->
i_recvs[i]);
252 avail_allocs = atomic_add_unless(&rds_ib_allocation,
287 RDS_FRAG_SIZE, page_mask);
294 INIT_LIST_HEAD(&frag->
f_item);
323 recv->
r_ibinc = rds_ib_refill_one_inc(ic, slab_mask);
329 recv->
r_frag = rds_ib_refill_one_frag(ic, slab_mask, page_mask);
333 ret = ib_dma_map_sg(ic->
i_cm_id->device, &recv->
r_frag->f_sg,
337 sge = &recv->
r_sge[0];
341 sge = &recv->
r_sge[1];
362 unsigned int posted = 0;
366 while ((prefill || rds_conn_up(conn)) &&
375 ret = rds_ib_recv_refill_one(conn, recv, prefill);
381 ret = ib_post_recv(ic->
i_cm_id->qp, &recv->
r_wr, &failed_wr);
382 rdsdebug(
"recv %p ibinc %p page %p addr %lu ret %d\n", recv,
387 "%pI4 returned %d, disconnecting and "
388 "reconnecting\n", &conn->
c_faddr,
417 static void rds_ib_recv_cache_put(
struct list_head *new_item,
428 INIT_LIST_HEAD(new_item);
431 chp->
first = new_item;
446 list_splice_entire_tail(old, chp->
first);
461 if (!list_empty(head)) {
476 struct iovec *iov = first_iov;
477 unsigned long to_copy;
478 unsigned long frag_off = 0;
479 unsigned long iov_off = 0;
488 while (copied < size && copied < len) {
494 while (iov_off == iov->
iov_len) {
500 to_copy =
min_t(
size_t, to_copy, size - copied);
501 to_copy =
min_t(
unsigned long, to_copy, len - copied);
503 rdsdebug(
"%lu bytes to user [%p, %zu] + %lu from frag "
506 sg_page(&frag->
f_sg), frag->
f_sg.offset, frag_off);
510 frag->
f_sg.offset + frag_off,
565 #ifndef KERNEL_HAS_ATOMIC64
575 spin_unlock_irqrestore(&ic->
i_ack_lock, flags);
587 spin_unlock_irqrestore(&ic->
i_ack_lock, flags);
612 static void rds_ib_send_ack(
struct rds_ib_connection *ic,
unsigned int adv_credits)
619 seq = rds_ib_get_ack(ic);
621 rdsdebug(
"send_ack: ic %p ack %llu\n", ic, (
unsigned long long) seq);
625 rds_message_make_checksum(hdr);
683 unsigned int adv_credits;
701 rds_ib_send_ack(ic, adv_credits);
722 return rds_ib_get_ack(ic);
736 struct rds_cong_map *
map;
737 unsigned int map_off;
740 unsigned long frag_off;
741 unsigned long to_copy;
742 unsigned long copied;
759 while (copied < RDS_CONG_MAP_BYTES) {
763 to_copy =
min(RDS_FRAG_SIZE - frag_off,
PAGE_SIZE - map_off);
768 src = addr + frag_off;
769 dst = (
void *)map->m_page_addrs[map_page] + map_off;
770 for (k = 0; k < to_copy; k += 8) {
773 uncongested |= ~(*src) & *
dst;
787 if (frag_off == RDS_FRAG_SIZE) {
809 unsigned int ack_required:1;
824 rdsdebug(
"ic %p ibinc %p recv %p byte len %u\n", ic, ibinc, recv,
829 "from %pI4 didn't include a "
830 "header, disconnecting and "
840 if (!rds_message_verify_checksum(ihdr)) {
842 "from %pI4 has corrupted header - "
843 "forcing a reconnect\n",
873 rds_ib_frag_free(ic, recv->
r_frag);
889 hdr = &ibinc->
ii_inc.i_hdr;
890 memcpy(hdr, ihdr,
sizeof(*hdr));
893 rdsdebug(
"ic %p ibinc %p rem %u flag 0x%x\n", ic, ibinc,
896 hdr = &ibinc->
ii_inc.i_hdr;
904 "fragment header mismatch; forcing reconnect\n");
919 rds_ib_cong_recv(conn, ibinc);
953 rdsdebug(
"conn %p cq %p\n", conn, cq);
968 rdsdebug(
"wc wr_id 0x%llx status %u (%s) byte_len %u imm_data %u\n",
969 (
unsigned long long)
wc.wr_id,
wc.status,
984 rds_ib_process_recv(conn, recv,
wc.byte_len, state);
987 if (rds_conn_up(conn) || rds_conn_connecting(conn))
989 "status %u (%s), disconnecting and "
990 "reconnecting\n", &conn->
c_faddr,
1010 rds_poll_cq(ic, &state);
1012 rds_poll_cq(ic, &state);
1020 if (rds_conn_up(conn))
1038 rdsdebug(
"conn %p\n", conn);
1039 if (rds_conn_up(conn))
1057 if (!rds_ib_incoming_slab)
1063 if (!rds_ib_frag_slab)