Skip to content

Commit 81655d3

Browse files
committed
RDMA/mlx4: Use ib_umem_num_dma_blocks()
For the calls linked to mlx4_ib_umem_calc_optimal_mtt_size() use ib_umem_num_dma_blocks() inside the function, it is just some weird static default. All other places are just using it with PAGE_SIZE, switch to ib_umem_num_dma_blocks(). As this is the last call site, remove ib_umem_num_count(). Link: https://lore.kernel.org/r/15-v2-270386b7e60b+28f4-umem_1_jgg@nvidia.com Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 87aebd3 commit 81655d3

6 files changed

Lines changed: 6 additions & 21 deletions

File tree

‎drivers/infiniband/core/umem.c‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,6 @@ void ib_umem_release(struct ib_umem *umem)
350350
}
351351
EXPORT_SYMBOL(ib_umem_release);
352352

353-
int ib_umem_page_count(struct ib_umem *umem)
354-
{
355-
int i, n = 0;
356-
struct scatterlist *sg;
357-
358-
for_each_sg(umem->sg_head.sgl, sg, umem->nmap, i)
359-
n += sg_dma_len(sg) >> PAGE_SHIFT;
360-
361-
return n;
362-
}
363-
EXPORT_SYMBOL(ib_umem_page_count);
364-
365353
/*
366354
* Copy from the given ib_umem's pages to the given buffer.
367355
*

‎drivers/infiniband/hw/mlx4/cq.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ static int mlx4_ib_get_cq_umem(struct mlx4_ib_dev *dev, struct ib_udata *udata,
149149
if (IS_ERR(*umem))
150150
return PTR_ERR(*umem);
151151

152-
n = ib_umem_page_count(*umem);
153152
shift = mlx4_ib_umem_calc_optimal_mtt_size(*umem, 0, &n);
154153
err = mlx4_mtt_init(dev->dev, n, shift, &buf->mtt);
155154

‎drivers/infiniband/hw/mlx4/mr.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ int mlx4_ib_umem_calc_optimal_mtt_size(struct ib_umem *umem, u64 start_va,
271271
u64 total_len = 0;
272272
int i;
273273

274+
*num_of_mtts = ib_umem_num_dma_blocks(umem, PAGE_SIZE);
275+
274276
for_each_sg(umem->sg_head.sgl, sg, umem->nmap, i) {
275277
/*
276278
* Initialization - save the first chunk start as the
@@ -421,7 +423,6 @@ struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
421423
goto err_free;
422424
}
423425

424-
n = ib_umem_page_count(mr->umem);
425426
shift = mlx4_ib_umem_calc_optimal_mtt_size(mr->umem, start, &n);
426427

427428
err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, virt_addr, length,
@@ -511,7 +512,7 @@ int mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags,
511512
mmr->umem = NULL;
512513
goto release_mpt_entry;
513514
}
514-
n = ib_umem_page_count(mmr->umem);
515+
n = ib_umem_num_dma_blocks(mmr->umem, PAGE_SIZE);
515516
shift = PAGE_SHIFT;
516517

517518
err = mlx4_mr_rereg_mem_write(dev->dev, &mmr->mmr,

‎drivers/infiniband/hw/mlx4/qp.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,6 @@ static int create_rq(struct ib_pd *pd, struct ib_qp_init_attr *init_attr,
922922
goto err;
923923
}
924924

925-
n = ib_umem_page_count(qp->umem);
926925
shift = mlx4_ib_umem_calc_optimal_mtt_size(qp->umem, 0, &n);
927926
err = mlx4_mtt_init(dev->dev, n, shift, &qp->mtt);
928927

@@ -1117,7 +1116,6 @@ static int create_qp_common(struct ib_pd *pd, struct ib_qp_init_attr *init_attr,
11171116
goto err;
11181117
}
11191118

1120-
n = ib_umem_page_count(qp->umem);
11211119
shift = mlx4_ib_umem_calc_optimal_mtt_size(qp->umem, 0, &n);
11221120
err = mlx4_mtt_init(dev->dev, n, shift, &qp->mtt);
11231121

‎drivers/infiniband/hw/mlx4/srq.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ int mlx4_ib_create_srq(struct ib_srq *ib_srq,
115115
if (IS_ERR(srq->umem))
116116
return PTR_ERR(srq->umem);
117117

118-
err = mlx4_mtt_init(dev->dev, ib_umem_page_count(srq->umem),
119-
PAGE_SHIFT, &srq->mtt);
118+
err = mlx4_mtt_init(
119+
dev->dev, ib_umem_num_dma_blocks(srq->umem, PAGE_SIZE),
120+
PAGE_SHIFT, &srq->mtt);
120121
if (err)
121122
goto err_buf;
122123

‎include/rdma/ib_umem.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ static inline void __rdma_umem_block_iter_start(struct ib_block_iter *biter,
7474
struct ib_umem *ib_umem_get(struct ib_device *device, unsigned long addr,
7575
size_t size, int access);
7676
void ib_umem_release(struct ib_umem *umem);
77-
int ib_umem_page_count(struct ib_umem *umem);
7877
int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
7978
size_t length);
8079
unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem,
@@ -92,7 +91,6 @@ static inline struct ib_umem *ib_umem_get(struct ib_device *device,
9291
return ERR_PTR(-EINVAL);
9392
}
9493
static inline void ib_umem_release(struct ib_umem *umem) { }
95-
static inline int ib_umem_page_count(struct ib_umem *umem) { return 0; }
9694
static inline int ib_umem_copy_from(void *dst, struct ib_umem *umem, size_t offset,
9795
size_t length) {
9896
return -EINVAL;

0 commit comments

Comments
 (0)