33 #include <linux/kernel.h>
34 #include <linux/slab.h>
35 #include <linux/pci.h>
42 static struct kmem_cache *rds_iw_incoming_slab;
48 rdsdebug(
"frag %p page %p\n", frag, frag->
f_page);
55 rdsdebug(
"frag %p page %p\n", frag, frag->
f_page);
74 rdsdebug(
"recv %p frag %p page %p\n", recv, frag, frag->
f_page);
76 ib_dma_unmap_page(ic->
i_cm_id->device,
87 for (i = 0, recv = ic->
i_recvs; i < ic->i_recv_ring.w_nr; i++, recv++) {
98 sge = rds_iw_data_sge(ic, recv->
r_sge);
103 sge = rds_iw_header_sge(ic, recv->
r_sge);
118 rds_iw_recv_unmap_page(ic, recv);
120 rds_iw_frag_drop_page(recv->
r_frag);
121 rds_iw_frag_free(recv->
r_frag);
131 rds_iw_recv_clear_one(ic, &ic->
i_recvs[i]);
134 rds_iw_frag_drop_page(&ic->
i_frag);
157 INIT_LIST_HEAD(&recv->
r_iwinc->ii_frags);
165 INIT_LIST_HEAD(&recv->
r_frag->f_item);
176 dma_addr = ib_dma_map_page(ic->
i_cm_id->device,
181 if (ib_dma_mapping_error(ic->
i_cm_id->device, dma_addr))
193 sge = rds_iw_data_sge(ic, recv->
r_sge);
197 sge = rds_iw_header_sge(ic, recv->
r_sge);
201 get_page(recv->
r_frag->f_page);
225 gfp_t page_gfp,
int prefill)
230 unsigned int posted = 0;
234 while ((prefill || rds_conn_up(conn)) &&
244 ret = rds_iw_recv_refill_one(conn, recv, kptr_gfp, page_gfp);
251 ret = ib_post_recv(ic->
i_cm_id->qp, &recv->
r_wr, &failed_wr);
252 rdsdebug(
"recv %p iwinc %p page %p addr %lu ret %d\n", recv,
254 (
long) recv->
r_frag->f_mapped, ret);
257 "%pI4 returned %d, disconnecting and "
258 "reconnecting\n", &conn->
c_faddr,
283 rdsdebug(
"purging iwinc %p inc %p\n", iwinc, inc);
286 list_del_init(&frag->
f_item);
287 rds_iw_frag_drop_page(frag);
288 rds_iw_frag_free(frag);
298 rds_iw_inc_purge(inc);
299 rdsdebug(
"freeing iwinc %p inc %p\n", iwinc, inc);
311 struct iovec *iov = first_iov;
312 unsigned long to_copy;
313 unsigned long frag_off = 0;
314 unsigned long iov_off = 0;
323 while (copied < size && copied < len) {
329 while (iov_off == iov->
iov_len) {
335 to_copy =
min_t(
size_t, to_copy, size - copied);
336 to_copy =
min_t(
unsigned long, to_copy, len - copied);
338 rdsdebug(
"%lu bytes to user [%p, %zu] + %lu from frag "
369 sge->
lkey = rds_iw_local_dma_lkey(ic);
400 #ifndef KERNEL_HAS_ATOMIC64
410 spin_unlock_irqrestore(&ic->
i_ack_lock, flags);
422 spin_unlock_irqrestore(&ic->
i_ack_lock, flags);
447 static void rds_iw_send_ack(
struct rds_iw_connection *ic,
unsigned int adv_credits)
454 seq = rds_iw_get_ack(ic);
456 rdsdebug(
"send_ack: ic %p ack %llu\n", ic, (
unsigned long long) seq);
460 rds_message_make_checksum(hdr);
518 unsigned int adv_credits;
536 rds_iw_send_ack(ic, adv_credits);
557 return rds_iw_get_ack(ic);
571 struct rds_cong_map *
map;
572 unsigned int map_off;
575 unsigned long frag_off;
576 unsigned long to_copy;
577 unsigned long copied;
594 while (copied < RDS_CONG_MAP_BYTES) {
598 to_copy =
min(RDS_FRAG_SIZE - frag_off,
PAGE_SIZE - map_off);
603 src = addr + frag_off;
604 dst = (
void *)map->m_page_addrs[map_page] + map_off;
605 for (k = 0; k < to_copy; k += 8) {
608 uncongested |= ~(*src) & *
dst;
622 if (frag_off == RDS_FRAG_SIZE) {
644 unsigned int ack_required:1;
659 rdsdebug(
"ic %p iwinc %p recv %p byte len %u\n", ic, iwinc, recv,
664 "from %pI4 didn't include a "
665 "header, disconnecting and "
675 if (!rds_message_verify_checksum(ihdr)) {
677 "from %pI4 has corrupted header - "
678 "forcing a reconnect\n",
709 rds_iw_frag_drop_page(recv->
r_frag);
724 hdr = &iwinc->
ii_inc.i_hdr;
725 memcpy(hdr, ihdr,
sizeof(*hdr));
728 rdsdebug(
"ic %p iwinc %p rem %u flag 0x%x\n", ic, iwinc,
731 hdr = &iwinc->
ii_inc.i_hdr;
739 "fragment header mismatch; forcing reconnect\n");
754 rds_iw_cong_recv(conn, iwinc);
788 rdsdebug(
"conn %p cq %p\n", conn, cq);
803 rdsdebug(
"wc wr_id 0x%llx status %u byte_len %u imm_data %u\n",
804 (
unsigned long long)
wc.wr_id,
wc.status,
wc.byte_len,
810 rds_iw_recv_unmap_page(ic, recv);
817 if (rds_conn_up(conn) || rds_conn_connecting(conn)) {
820 rds_iw_process_recv(conn, recv,
wc.byte_len, state);
823 "%pI4 had status %u, disconnecting and "
824 "reconnecting\n", &conn->
c_faddr,
839 rds_poll_cq(ic, &state);
841 rds_poll_cq(ic, &state);
849 if (rds_conn_up(conn))
870 rdsdebug(
"conn %p\n", conn);
883 if (rds_conn_up(conn))
901 if (!rds_iw_incoming_slab)
907 if (!rds_iw_frag_slab)