34 #include <linux/slab.h>
35 #include <linux/rbtree.h>
56 static unsigned int rds_pages_in_vec(
struct rds_iovec *vec)
79 else if (key > mr->
r_key)
86 rb_link_node(&insert->
r_rb_node, parent, p);
96 static void rds_destroy_mr(
struct rds_mr *mr)
99 void *trans_private =
NULL;
102 rdsdebug(
"RDS: destroy mr key is %x refcnt %u\n",
157 static int rds_pin_pages(
unsigned long user_addr,
unsigned int nr_pages,
164 if (ret >= 0 && ret < nr_pages) {
177 unsigned int nr_pages;
197 nr_pages = rds_pages_in_vec(&args->
vec);
203 rdsdebug(
"RDS: get_mr addr %llx len %llu nr_pages %u\n",
204 args->
vec.addr, args->
vec.bytes, nr_pages);
241 ret = rds_pin_pages(args->
vec.addr, nr_pages, pages, 1);
255 for (i = 0 ; i < nents; i++)
256 sg_set_page(&sg[i], pages[i],
PAGE_SIZE, 0);
258 rdsdebug(
"RDS: trans_private nents is %u\n", nents);
267 if (IS_ERR(trans_private)) {
268 for (i = 0 ; i < nents; i++)
271 ret = PTR_ERR(trans_private);
277 rdsdebug(
"RDS: get_mr put_user key is %x cookie_addr %p\n",
299 BUG_ON(found && found != mr);
301 rdsdebug(
"RDS: get_mr key is %x\n", mr->
r_key);
326 return __rds_rdma_map(rs, &args,
NULL,
NULL);
350 return __rds_rdma_map(rs, &new_args,
NULL,
NULL);
418 printk(
KERN_ERR "rds: trying to unuse MR with unknown r_key %u!\n", r_key);
447 for (i = 0; i < ro->op_nents; i++) {
448 struct page *
page = sg_page(&ro->op_sg[i]);
460 kfree(ro->op_notifier);
461 ro->op_notifier =
NULL;
467 struct page *
page = sg_page(ao->op_sg);
475 kfree(ao->op_notifier);
476 ao->op_notifier =
NULL;
484 static int rds_rdma_pages(
struct rds_iovec iov[],
int nr_iovecs)
487 unsigned int nr_pages;
491 for (i = 0; i < nr_iovecs; i++) {
492 nr_pages = rds_pages_in_vec(&iov[i]);
496 tot_pages += nr_pages;
514 unsigned int nr_pages;
520 for (i = 0; i < args->
nr_local; i++) {
525 nr_pages = rds_pages_in_vec(&vec);
529 tot_pages += nr_pages;
550 struct rm_rdma_op *
op = &rm->
rdma;
552 unsigned int nr_bytes;
554 struct rds_iovec iovstack[UIO_FASTIOV], *iovs = iovstack;
560 || rm->
rdma.op_active)
590 nr_pages = rds_rdma_pages(iovs, args->
nr_local);
615 if (op->op_notify || op->op_recverr) {
622 if (!op->op_notifier) {
626 op->op_notifier->n_user_token = args->
user_token;
637 op->op_rkey = rds_rdma_cookie_key(args->
cookie);
638 op->op_remote_addr = args->
remote_vec.addr + rds_rdma_cookie_offset(args->
cookie);
642 rdsdebug(
"RDS: rdma prepare nr_local %llu rva %llx rkey %x\n",
647 for (i = 0; i < args->
nr_local; i++) {
650 unsigned int nr = rds_pages_in_vec(iov);
658 ret = rds_pin_pages(iov->
addr, nr, pages, !op->op_write);
662 rdsdebug(
"RDS: nr_bytes %u nr %u iov->bytes %llu iov->addr %llx\n",
665 nr_bytes += iov->
bytes;
667 for (j = 0; j <
nr; j++) {
671 sg = &op->op_sg[op->op_nents +
j];
672 sg_set_page(sg, pages[j],
676 rdsdebug(
"RDS: sg->offset %x sg->len %x iov->addr %llx iov->bytes %llu\n",
687 rdsdebug(
"RDS nr_bytes %u remote_bytes %u do not match\n",
693 op->op_bytes = nr_bytes;
696 if (iovs != iovstack)
742 rm->
rdma.op_rdma_mr = mr;
784 rm->
atomic.op_m_fadd.nocarry_mask = 0;
789 rm->
atomic.op_m_fadd.nocarry_mask = args->
m_fadd.nocarry_mask;
793 rm->
atomic.op_m_cswp.compare = args->
cswp.compare;
795 rm->
atomic.op_m_cswp.compare_mask = ~0;
796 rm->
atomic.op_m_cswp.swap_mask = ~0;
802 rm->
atomic.op_m_cswp.compare_mask = args->
m_cswp.compare_mask;
803 rm->
atomic.op_m_cswp.swap_mask = args->
m_cswp.swap_mask;
825 ret = rds_pin_pages(args->
local_addr, 1, &page, 1);
839 if (!rm->
atomic.op_notifier) {