Skip to content

Commit 6ef999f

Browse files
committed
RDMA/bnxt_re: Use rdma_umem_for_each_dma_block()
This driver is taking the SGL out of the umem and passing it through a struct bnxt_qplib_sg_info. Instead of passing the SGL pass the umem and then use rdma_umem_for_each_dma_block() directly. Move the calls of ib_umem_num_dma_blocks() closer to their actual point of use, npages is only set for non-umem pbl flows. Link: https://lore.kernel.org/r/0-v1-b37437a73f35+49c-bnxt_re_dma_block_jgg@nvidia.com Acked-by: Selvin Xavier <selvin.xavier@broadcom.com> Tested-by: Selvin Xavier <selvin.xavier@broadcom.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 5ce2dce commit 6ef999f

3 files changed

Lines changed: 22 additions & 29 deletions

File tree

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,7 @@ static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd,
940940
return PTR_ERR(umem);
941941

942942
qp->sumem = umem;
943-
qplib_qp->sq.sg_info.sghead = umem->sg_head.sgl;
944-
qplib_qp->sq.sg_info.npages = ib_umem_num_dma_blocks(umem, PAGE_SIZE);
945-
qplib_qp->sq.sg_info.nmap = umem->nmap;
943+
qplib_qp->sq.sg_info.umem = umem;
946944
qplib_qp->sq.sg_info.pgsize = PAGE_SIZE;
947945
qplib_qp->sq.sg_info.pgshft = PAGE_SHIFT;
948946
qplib_qp->qp_handle = ureq.qp_handle;
@@ -955,10 +953,7 @@ static int bnxt_re_init_user_qp(struct bnxt_re_dev *rdev, struct bnxt_re_pd *pd,
955953
if (IS_ERR(umem))
956954
goto rqfail;
957955
qp->rumem = umem;
958-
qplib_qp->rq.sg_info.sghead = umem->sg_head.sgl;
959-
qplib_qp->rq.sg_info.npages =
960-
ib_umem_num_dma_blocks(umem, PAGE_SIZE);
961-
qplib_qp->rq.sg_info.nmap = umem->nmap;
956+
qplib_qp->rq.sg_info.umem = umem;
962957
qplib_qp->rq.sg_info.pgsize = PAGE_SIZE;
963958
qplib_qp->rq.sg_info.pgshft = PAGE_SHIFT;
964959
}
@@ -1612,9 +1607,7 @@ static int bnxt_re_init_user_srq(struct bnxt_re_dev *rdev,
16121607
return PTR_ERR(umem);
16131608

16141609
srq->umem = umem;
1615-
qplib_srq->sg_info.sghead = umem->sg_head.sgl;
1616-
qplib_srq->sg_info.npages = ib_umem_num_dma_blocks(umem, PAGE_SIZE);
1617-
qplib_srq->sg_info.nmap = umem->nmap;
1610+
qplib_srq->sg_info.umem = umem;
16181611
qplib_srq->sg_info.pgsize = PAGE_SIZE;
16191612
qplib_srq->sg_info.pgshft = PAGE_SHIFT;
16201613
qplib_srq->srq_handle = ureq.srq_handle;
@@ -2865,10 +2858,7 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
28652858
rc = PTR_ERR(cq->umem);
28662859
goto fail;
28672860
}
2868-
cq->qplib_cq.sg_info.sghead = cq->umem->sg_head.sgl;
2869-
cq->qplib_cq.sg_info.npages =
2870-
ib_umem_num_dma_blocks(cq->umem, PAGE_SIZE);
2871-
cq->qplib_cq.sg_info.nmap = cq->umem->nmap;
2861+
cq->qplib_cq.sg_info.umem = cq->umem;
28722862
cq->qplib_cq.dpi = &uctx->dpi;
28732863
} else {
28742864
cq->max_cql = min_t(u32, entries, MAX_CQL_PER_POLL);

drivers/infiniband/hw/bnxt_re/qplib_res.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#include <linux/dma-mapping.h>
4646
#include <linux/if_vlan.h>
4747
#include <linux/vmalloc.h>
48+
#include <rdma/ib_verbs.h>
49+
#include <rdma/ib_umem.h>
50+
4851
#include "roce_hsi.h"
4952
#include "qplib_res.h"
5053
#include "qplib_sp.h"
@@ -87,12 +90,11 @@ static void __free_pbl(struct bnxt_qplib_res *res, struct bnxt_qplib_pbl *pbl,
8790
static void bnxt_qplib_fill_user_dma_pages(struct bnxt_qplib_pbl *pbl,
8891
struct bnxt_qplib_sg_info *sginfo)
8992
{
90-
struct scatterlist *sghead = sginfo->sghead;
91-
struct sg_dma_page_iter sg_iter;
93+
struct ib_block_iter biter;
9294
int i = 0;
9395

94-
for_each_sg_dma_page(sghead, &sg_iter, sginfo->nmap, 0) {
95-
pbl->pg_map_arr[i] = sg_page_iter_dma_address(&sg_iter);
96+
rdma_umem_for_each_dma_block(sginfo->umem, &biter, sginfo->pgsize) {
97+
pbl->pg_map_arr[i] = rdma_block_iter_dma_address(&biter);
9698
pbl->pg_arr[i] = NULL;
9799
pbl->pg_count++;
98100
i++;
@@ -104,15 +106,16 @@ static int __alloc_pbl(struct bnxt_qplib_res *res,
104106
struct bnxt_qplib_sg_info *sginfo)
105107
{
106108
struct pci_dev *pdev = res->pdev;
107-
struct scatterlist *sghead;
108109
bool is_umem = false;
109110
u32 pages;
110111
int i;
111112

112113
if (sginfo->nopte)
113114
return 0;
114-
pages = sginfo->npages;
115-
sghead = sginfo->sghead;
115+
if (sginfo->umem)
116+
pages = ib_umem_num_dma_blocks(sginfo->umem, sginfo->pgsize);
117+
else
118+
pages = sginfo->npages;
116119
/* page ptr arrays */
117120
pbl->pg_arr = vmalloc(pages * sizeof(void *));
118121
if (!pbl->pg_arr)
@@ -127,7 +130,7 @@ static int __alloc_pbl(struct bnxt_qplib_res *res,
127130
pbl->pg_count = 0;
128131
pbl->pg_size = sginfo->pgsize;
129132

130-
if (!sghead) {
133+
if (!sginfo->umem) {
131134
for (i = 0; i < pages; i++) {
132135
pbl->pg_arr[i] = dma_alloc_coherent(&pdev->dev,
133136
pbl->pg_size,
@@ -183,14 +186,12 @@ int bnxt_qplib_alloc_init_hwq(struct bnxt_qplib_hwq *hwq,
183186
struct bnxt_qplib_sg_info sginfo = {};
184187
u32 depth, stride, npbl, npde;
185188
dma_addr_t *src_phys_ptr, **dst_virt_ptr;
186-
struct scatterlist *sghead = NULL;
187189
struct bnxt_qplib_res *res;
188190
struct pci_dev *pdev;
189191
int i, rc, lvl;
190192

191193
res = hwq_attr->res;
192194
pdev = res->pdev;
193-
sghead = hwq_attr->sginfo->sghead;
194195
pg_size = hwq_attr->sginfo->pgsize;
195196
hwq->level = PBL_LVL_MAX;
196197

@@ -204,7 +205,7 @@ int bnxt_qplib_alloc_init_hwq(struct bnxt_qplib_hwq *hwq,
204205
aux_pages++;
205206
}
206207

207-
if (!sghead) {
208+
if (!hwq_attr->sginfo->umem) {
208209
hwq->is_user = false;
209210
npages = (depth * stride) / pg_size + aux_pages;
210211
if ((depth * stride) % pg_size)
@@ -213,11 +214,14 @@ int bnxt_qplib_alloc_init_hwq(struct bnxt_qplib_hwq *hwq,
213214
return -EINVAL;
214215
hwq_attr->sginfo->npages = npages;
215216
} else {
217+
unsigned long sginfo_num_pages = ib_umem_num_dma_blocks(
218+
hwq_attr->sginfo->umem, hwq_attr->sginfo->pgsize);
219+
216220
hwq->is_user = true;
217-
npages = hwq_attr->sginfo->npages;
221+
npages = sginfo_num_pages;
218222
npages = (npages * PAGE_SIZE) /
219223
BIT_ULL(hwq_attr->sginfo->pgshft);
220-
if ((hwq_attr->sginfo->npages * PAGE_SIZE) %
224+
if ((sginfo_num_pages * PAGE_SIZE) %
221225
BIT_ULL(hwq_attr->sginfo->pgshft))
222226
if (!npages)
223227
npages++;

drivers/infiniband/hw/bnxt_re/qplib_res.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ struct bnxt_qplib_pbl {
126126
};
127127

128128
struct bnxt_qplib_sg_info {
129-
struct scatterlist *sghead;
130-
u32 nmap;
129+
struct ib_umem *umem;
131130
u32 npages;
132131
u32 pgshft;
133132
u32 pgsize;

0 commit comments

Comments
 (0)