Skip to content

Commit 2d5c008

Browse files
Konstantin Taranovrleon
authored andcommitted
RDMA/mana_ib: Use virtual address in dma regions for MRs
Introduce mana_ib_create_dma_region() to create dma regions with iova for MRs. It allows creating MRs with any page offset. Previously, only page-aligned addresses worked. For dma regions that must have a zero dma offset (e.g., for queues), mana_ib_create_zero_offset_dma_region() is added. To get the zero offset, ib_umem_find_best_pgoff() is used with zero pgoff_bitmask. Fixes: 0266a17 ("RDMA/mana_ib: Add a driver for Microsoft Azure Network Adapter") Signed-off-by: Konstantin Taranov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Zhu Yanjun <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent e02497f commit 2d5c008

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

drivers/infiniband/hw/mana/cq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
4848
return err;
4949
}
5050

51-
err = mana_ib_gd_create_dma_region(mdev, cq->umem, &cq->gdma_region);
51+
err = mana_ib_create_zero_offset_dma_region(mdev, cq->umem, &cq->gdma_region);
5252
if (err) {
5353
ibdev_dbg(ibdev,
5454
"Failed to create dma region for create cq, %d\n",
@@ -57,7 +57,7 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
5757
}
5858

5959
ibdev_dbg(ibdev,
60-
"mana_ib_gd_create_dma_region ret %d gdma_region 0x%llx\n",
60+
"create_dma_region ret %d gdma_region 0x%llx\n",
6161
err, cq->gdma_region);
6262

6363
/*

drivers/infiniband/hw/mana/main.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ mana_ib_gd_add_dma_region(struct mana_ib_dev *dev, struct gdma_context *gc,
301301
return 0;
302302
}
303303

304-
int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
305-
mana_handle_t *gdma_region)
304+
static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
305+
mana_handle_t *gdma_region, unsigned long page_sz)
306306
{
307307
struct gdma_dma_region_add_pages_req *add_req = NULL;
308308
size_t num_pages_processed = 0, num_pages_to_handle;
@@ -314,7 +314,6 @@ int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
314314
size_t max_pgs_create_cmd;
315315
struct gdma_context *gc;
316316
size_t num_pages_total;
317-
unsigned long page_sz;
318317
unsigned int tail = 0;
319318
u64 *page_addr_list;
320319
void *request_buf;
@@ -323,12 +322,6 @@ int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
323322
gc = mdev_to_gc(dev);
324323
hwc = gc->hwc.driver_data;
325324

326-
/* Hardware requires dma region to align to chosen page size */
327-
page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, 0);
328-
if (!page_sz) {
329-
ibdev_dbg(&dev->ib_dev, "failed to find page size.\n");
330-
return -ENOMEM;
331-
}
332325
num_pages_total = ib_umem_num_dma_blocks(umem, page_sz);
333326

334327
max_pgs_create_cmd =
@@ -414,6 +407,35 @@ int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
414407
return err;
415408
}
416409

410+
int mana_ib_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
411+
mana_handle_t *gdma_region, u64 virt)
412+
{
413+
unsigned long page_sz;
414+
415+
page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, virt);
416+
if (!page_sz) {
417+
ibdev_dbg(&dev->ib_dev, "Failed to find page size.\n");
418+
return -EINVAL;
419+
}
420+
421+
return mana_ib_gd_create_dma_region(dev, umem, gdma_region, page_sz);
422+
}
423+
424+
int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
425+
mana_handle_t *gdma_region)
426+
{
427+
unsigned long page_sz;
428+
429+
/* Hardware requires dma region to align to chosen page size */
430+
page_sz = ib_umem_find_best_pgoff(umem, PAGE_SZ_BM, 0);
431+
if (!page_sz) {
432+
ibdev_dbg(&dev->ib_dev, "Failed to find page size.\n");
433+
return -EINVAL;
434+
}
435+
436+
return mana_ib_gd_create_dma_region(dev, umem, gdma_region, page_sz);
437+
}
438+
417439
int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev, u64 gdma_region)
418440
{
419441
struct gdma_context *gc = mdev_to_gc(dev);

drivers/infiniband/hw/mana/mana_ib.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@ static inline struct net_device *mana_ib_get_netdev(struct ib_device *ibdev, u32
160160

161161
int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq);
162162

163-
int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
164-
mana_handle_t *gdma_region);
163+
int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
164+
mana_handle_t *gdma_region);
165+
166+
int mana_ib_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
167+
mana_handle_t *gdma_region, u64 virt);
165168

166169
int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev,
167170
mana_handle_t gdma_region);

drivers/infiniband/hw/mana/mr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length,
127127
goto err_free;
128128
}
129129

130-
err = mana_ib_gd_create_dma_region(dev, mr->umem, &dma_region_handle);
130+
err = mana_ib_create_dma_region(dev, mr->umem, &dma_region_handle, iova);
131131
if (err) {
132132
ibdev_dbg(ibdev, "Failed create dma region for user-mr, %d\n",
133133
err);
134134
goto err_umem;
135135
}
136136

137137
ibdev_dbg(ibdev,
138-
"mana_ib_gd_create_dma_region ret %d gdma_region %llx\n", err,
138+
"create_dma_region ret %d gdma_region %llx\n", err,
139139
dma_region_handle);
140140

141141
mr_params.pd_handle = pd->pd_handle;

drivers/infiniband/hw/mana/qp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd,
357357
}
358358
qp->sq_umem = umem;
359359

360-
err = mana_ib_gd_create_dma_region(mdev, qp->sq_umem,
361-
&qp->sq_gdma_region);
360+
err = mana_ib_create_zero_offset_dma_region(mdev, qp->sq_umem,
361+
&qp->sq_gdma_region);
362362
if (err) {
363363
ibdev_dbg(&mdev->ib_dev,
364364
"Failed to create dma region for create qp-raw, %d\n",
@@ -367,7 +367,7 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd,
367367
}
368368

369369
ibdev_dbg(&mdev->ib_dev,
370-
"mana_ib_gd_create_dma_region ret %d gdma_region 0x%llx\n",
370+
"create_dma_region ret %d gdma_region 0x%llx\n",
371371
err, qp->sq_gdma_region);
372372

373373
/* Create a WQ on the same port handle used by the Ethernet */

drivers/infiniband/hw/mana/wq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct ib_wq *mana_ib_create_wq(struct ib_pd *pd,
4646
wq->wq_buf_size = ucmd.wq_buf_size;
4747
wq->rx_object = INVALID_MANA_HANDLE;
4848

49-
err = mana_ib_gd_create_dma_region(mdev, wq->umem, &wq->gdma_region);
49+
err = mana_ib_create_zero_offset_dma_region(mdev, wq->umem, &wq->gdma_region);
5050
if (err) {
5151
ibdev_dbg(&mdev->ib_dev,
5252
"Failed to create dma region for create wq, %d\n",
@@ -55,7 +55,7 @@ struct ib_wq *mana_ib_create_wq(struct ib_pd *pd,
5555
}
5656

5757
ibdev_dbg(&mdev->ib_dev,
58-
"mana_ib_gd_create_dma_region ret %d gdma_region 0x%llx\n",
58+
"create_dma_region ret %d gdma_region 0x%llx\n",
5959
err, wq->gdma_region);
6060

6161
/* WQ ID is returned at wq_create time, doesn't know the value yet */

0 commit comments

Comments
 (0)