@@ -289,13 +289,6 @@ void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length)
int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
enum rxe_mr_copy_dir dir)
{
- int err;
- int bytes;
- u8 *va;
- struct rxe_map **map;
- struct rxe_phys_buf *buf;
- int m;
- int i;
size_t offset;
if (length == 0)
@@ -315,49 +308,36 @@ int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length,
WARN_ON_ONCE(!mr->map);
- err = mr_check_range(mr, iova, length);
- if (err) {
- err = -EFAULT;
- goto err1;
- }
-
- lookup_iova(mr, iova, &m, &i, &offset);
-
- map = mr->map + m;
- buf = map[0]->buf + i;
+ if (mr_check_range(mr, iova, length))
+ return -EFAULT;
+ offset = (iova - mr->ibmr.iova + mr->offset) & mr->page_mask;
while (length > 0) {
- u8 *src, *dest;
-
- va = (u8 *)(uintptr_t)buf->addr + offset;
- src = (dir == RXE_TO_MR_OBJ) ? addr : va;
- dest = (dir == RXE_TO_MR_OBJ) ? va : addr;
+ u8 *src, *dest, *va;
+ int bytes;
bytes = mr->ibmr.page_size - offset;
if (bytes > length)
bytes = length;
+ va = iova_to_vaddr(mr, iova, bytes);
+ if (!va)
+ return -EFAULT;
+
+ src = (dir == RXE_TO_MR_OBJ) ? addr : va;
+ dest = (dir == RXE_TO_MR_OBJ) ? va : addr;
+
memcpy(dest, src, bytes);
length -= bytes;
addr += bytes;
+ iova += bytes;
offset = 0;
- buf++;
- i++;
-
- if (i == RXE_BUF_PER_MAP) {
- i = 0;
- map++;
- buf = map[0]->buf;
- }
}
return 0;
-
-err1:
- return err;
}
/* copy data in or out of a wqe, i.e. sg list
Make the code more friendly and readable by using iova_to_vaddr() This commit also remove the err1 label in rxe_mr_copy(). Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> --- drivers/infiniband/sw/rxe/rxe_mr.c | 46 +++++++++--------------------- 1 file changed, 13 insertions(+), 33 deletions(-)