Commit 4143f34e authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Doug Ledford

xprtrdma: Port to new memory registration API

Instead of maintaining a fastreg page list, keep an sg table
and convert an array of pages to a sg list. Then call ib_map_mr_sg
and construct ib_reg_wr.
Signed-off-by: default avatarSagi Grimberg <sagig@mellanox.com>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Tested-by: default avatarSteve Wise <swise@opengridcomputing.com>
Tested-by: default avatarSelvin Xavier <selvin.xavier@avagotech.com>
Reviewed-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 16c2d702
...@@ -151,9 +151,13 @@ __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device, ...@@ -151,9 +151,13 @@ __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device,
f->fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth); f->fr_mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, depth);
if (IS_ERR(f->fr_mr)) if (IS_ERR(f->fr_mr))
goto out_mr_err; goto out_mr_err;
f->fr_pgl = ib_alloc_fast_reg_page_list(device, depth);
if (IS_ERR(f->fr_pgl)) f->sg = kcalloc(depth, sizeof(*f->sg), GFP_KERNEL);
if (!f->sg)
goto out_list_err; goto out_list_err;
sg_init_table(f->sg, depth);
return 0; return 0;
out_mr_err: out_mr_err:
...@@ -163,9 +167,9 @@ __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device, ...@@ -163,9 +167,9 @@ __frwr_init(struct rpcrdma_mw *r, struct ib_pd *pd, struct ib_device *device,
return rc; return rc;
out_list_err: out_list_err:
rc = PTR_ERR(f->fr_pgl); rc = -ENOMEM;
dprintk("RPC: %s: ib_alloc_fast_reg_page_list status %i\n", dprintk("RPC: %s: sg allocation failure\n",
__func__, rc); __func__);
ib_dereg_mr(f->fr_mr); ib_dereg_mr(f->fr_mr);
return rc; return rc;
} }
...@@ -179,7 +183,7 @@ __frwr_release(struct rpcrdma_mw *r) ...@@ -179,7 +183,7 @@ __frwr_release(struct rpcrdma_mw *r)
if (rc) if (rc)
dprintk("RPC: %s: ib_dereg_mr status %i\n", dprintk("RPC: %s: ib_dereg_mr status %i\n",
__func__, rc); __func__, rc);
ib_free_fast_reg_page_list(r->r.frmr.fr_pgl); kfree(r->r.frmr.sg);
} }
static int static int
...@@ -312,14 +316,10 @@ frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg, ...@@ -312,14 +316,10 @@ frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
struct rpcrdma_mw *mw; struct rpcrdma_mw *mw;
struct rpcrdma_frmr *frmr; struct rpcrdma_frmr *frmr;
struct ib_mr *mr; struct ib_mr *mr;
struct ib_fast_reg_wr fastreg_wr; struct ib_reg_wr reg_wr;
struct ib_send_wr *bad_wr; struct ib_send_wr *bad_wr;
int rc, i, n, dma_nents;
u8 key; u8 key;
int len, pageoff;
int i, rc;
int seg_len;
u64 pa;
int page_no;
mw = seg1->rl_mw; mw = seg1->rl_mw;
seg1->rl_mw = NULL; seg1->rl_mw = NULL;
...@@ -332,64 +332,80 @@ frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg, ...@@ -332,64 +332,80 @@ frwr_op_map(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg,
} while (mw->r.frmr.fr_state != FRMR_IS_INVALID); } while (mw->r.frmr.fr_state != FRMR_IS_INVALID);
frmr = &mw->r.frmr; frmr = &mw->r.frmr;
frmr->fr_state = FRMR_IS_VALID; frmr->fr_state = FRMR_IS_VALID;
mr = frmr->fr_mr;
pageoff = offset_in_page(seg1->mr_offset);
seg1->mr_offset -= pageoff; /* start of page */
seg1->mr_len += pageoff;
len = -pageoff;
if (nsegs > ia->ri_max_frmr_depth) if (nsegs > ia->ri_max_frmr_depth)
nsegs = ia->ri_max_frmr_depth; nsegs = ia->ri_max_frmr_depth;
for (page_no = i = 0; i < nsegs;) { for (i = 0; i < nsegs;) {
rpcrdma_map_one(device, seg, direction); if (seg->mr_page)
pa = seg->mr_dma; sg_set_page(&frmr->sg[i],
for (seg_len = seg->mr_len; seg_len > 0; seg_len -= PAGE_SIZE) { seg->mr_page,
frmr->fr_pgl->page_list[page_no++] = pa; seg->mr_len,
pa += PAGE_SIZE; offset_in_page(seg->mr_offset));
} else
len += seg->mr_len; sg_set_buf(&frmr->sg[i], seg->mr_offset,
seg->mr_len);
++seg; ++seg;
++i; ++i;
/* Check for holes */ /* Check for holes */
if ((i < nsegs && offset_in_page(seg->mr_offset)) || if ((i < nsegs && offset_in_page(seg->mr_offset)) ||
offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len)) offset_in_page((seg-1)->mr_offset + (seg-1)->mr_len))
break; break;
} }
dprintk("RPC: %s: Using frmr %p to map %d segments (%d bytes)\n", frmr->sg_nents = i;
__func__, mw, i, len);
dma_nents = ib_dma_map_sg(device, frmr->sg, frmr->sg_nents, direction);
memset(&fastreg_wr, 0, sizeof(fastreg_wr)); if (!dma_nents) {
fastreg_wr.wr.wr_id = (unsigned long)(void *)mw; pr_err("RPC: %s: failed to dma map sg %p sg_nents %u\n",
fastreg_wr.wr.opcode = IB_WR_FAST_REG_MR; __func__, frmr->sg, frmr->sg_nents);
fastreg_wr.iova_start = seg1->mr_dma + pageoff; return -ENOMEM;
fastreg_wr.page_list = frmr->fr_pgl; }
fastreg_wr.page_shift = PAGE_SHIFT;
fastreg_wr.page_list_len = page_no; n = ib_map_mr_sg(mr, frmr->sg, frmr->sg_nents, PAGE_SIZE);
fastreg_wr.length = len; if (unlikely(n != frmr->sg_nents)) {
fastreg_wr.access_flags = writing ? pr_err("RPC: %s: failed to map mr %p (%u/%u)\n",
IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE : __func__, frmr->fr_mr, n, frmr->sg_nents);
IB_ACCESS_REMOTE_READ; rc = n < 0 ? n : -EINVAL;
mr = frmr->fr_mr; goto out_senderr;
}
dprintk("RPC: %s: Using frmr %p to map %u segments (%u bytes)\n",
__func__, mw, frmr->sg_nents, mr->length);
key = (u8)(mr->rkey & 0x000000FF); key = (u8)(mr->rkey & 0x000000FF);
ib_update_fast_reg_key(mr, ++key); ib_update_fast_reg_key(mr, ++key);
fastreg_wr.rkey = mr->rkey;
reg_wr.wr.next = NULL;
reg_wr.wr.opcode = IB_WR_REG_MR;
reg_wr.wr.wr_id = (uintptr_t)mw;
reg_wr.wr.num_sge = 0;
reg_wr.wr.send_flags = 0;
reg_wr.mr = mr;
reg_wr.key = mr->rkey;
reg_wr.access = writing ?
IB_ACCESS_REMOTE_WRITE | IB_ACCESS_LOCAL_WRITE :
IB_ACCESS_REMOTE_READ;
DECR_CQCOUNT(&r_xprt->rx_ep); DECR_CQCOUNT(&r_xprt->rx_ep);
rc = ib_post_send(ia->ri_id->qp, &fastreg_wr.wr, &bad_wr); rc = ib_post_send(ia->ri_id->qp, &reg_wr.wr, &bad_wr);
if (rc) if (rc)
goto out_senderr; goto out_senderr;
seg1->mr_dir = direction;
seg1->rl_mw = mw; seg1->rl_mw = mw;
seg1->mr_rkey = mr->rkey; seg1->mr_rkey = mr->rkey;
seg1->mr_base = seg1->mr_dma + pageoff; seg1->mr_base = mr->iova;
seg1->mr_nsegs = i; seg1->mr_nsegs = frmr->sg_nents;
seg1->mr_len = len; seg1->mr_len = mr->length;
return i;
return frmr->sg_nents;
out_senderr: out_senderr:
dprintk("RPC: %s: ib_post_send status %i\n", __func__, rc); dprintk("RPC: %s: ib_post_send status %i\n", __func__, rc);
while (i--) ib_dma_unmap_sg(device, frmr->sg, dma_nents, direction);
rpcrdma_unmap_one(device, --seg);
__frwr_queue_recovery(mw); __frwr_queue_recovery(mw);
return rc; return rc;
} }
...@@ -403,22 +419,22 @@ frwr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg) ...@@ -403,22 +419,22 @@ frwr_op_unmap(struct rpcrdma_xprt *r_xprt, struct rpcrdma_mr_seg *seg)
struct rpcrdma_mr_seg *seg1 = seg; struct rpcrdma_mr_seg *seg1 = seg;
struct rpcrdma_ia *ia = &r_xprt->rx_ia; struct rpcrdma_ia *ia = &r_xprt->rx_ia;
struct rpcrdma_mw *mw = seg1->rl_mw; struct rpcrdma_mw *mw = seg1->rl_mw;
struct rpcrdma_frmr *frmr = &mw->r.frmr;
struct ib_send_wr invalidate_wr, *bad_wr; struct ib_send_wr invalidate_wr, *bad_wr;
int rc, nsegs = seg->mr_nsegs; int rc, nsegs = seg->mr_nsegs;
dprintk("RPC: %s: FRMR %p\n", __func__, mw); dprintk("RPC: %s: FRMR %p\n", __func__, mw);
seg1->rl_mw = NULL; seg1->rl_mw = NULL;
mw->r.frmr.fr_state = FRMR_IS_INVALID; frmr->fr_state = FRMR_IS_INVALID;
memset(&invalidate_wr, 0, sizeof(invalidate_wr)); memset(&invalidate_wr, 0, sizeof(invalidate_wr));
invalidate_wr.wr_id = (unsigned long)(void *)mw; invalidate_wr.wr_id = (unsigned long)(void *)mw;
invalidate_wr.opcode = IB_WR_LOCAL_INV; invalidate_wr.opcode = IB_WR_LOCAL_INV;
invalidate_wr.ex.invalidate_rkey = mw->r.frmr.fr_mr->rkey; invalidate_wr.ex.invalidate_rkey = frmr->fr_mr->rkey;
DECR_CQCOUNT(&r_xprt->rx_ep); DECR_CQCOUNT(&r_xprt->rx_ep);
while (seg1->mr_nsegs--) ib_dma_unmap_sg(ia->ri_device, frmr->sg, frmr->sg_nents, seg1->mr_dir);
rpcrdma_unmap_one(ia->ri_device, seg++);
read_lock(&ia->ri_qplock); read_lock(&ia->ri_qplock);
rc = ib_post_send(ia->ri_id->qp, &invalidate_wr, &bad_wr); rc = ib_post_send(ia->ri_id->qp, &invalidate_wr, &bad_wr);
read_unlock(&ia->ri_qplock); read_unlock(&ia->ri_qplock);
......
...@@ -193,7 +193,8 @@ enum rpcrdma_frmr_state { ...@@ -193,7 +193,8 @@ enum rpcrdma_frmr_state {
}; };
struct rpcrdma_frmr { struct rpcrdma_frmr {
struct ib_fast_reg_page_list *fr_pgl; struct scatterlist *sg;
int sg_nents;
struct ib_mr *fr_mr; struct ib_mr *fr_mr;
enum rpcrdma_frmr_state fr_state; enum rpcrdma_frmr_state fr_state;
struct work_struct fr_work; struct work_struct fr_work;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment