Skip to content

Commit b210588

Browse files
Konstantin Taranovjgunthorpe
authored andcommitted
RDMA/mana_ib: Support memory windows
Implement .alloc_mw() and .dealloc_mw() for mana device. This is just the basic infrastructure, MW is not practically usable until additional kernel support for allowing user space to submit MW work requests is completed. Link: https://patch.msgid.link/r/[email protected] Signed-off-by: Konstantin Taranov <[email protected]> Reviewed-by: Long Li <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 7244491 commit b210588

4 files changed

Lines changed: 69 additions & 1 deletion

File tree

drivers/infiniband/hw/mana/device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ static const struct ib_device_ops mana_ib_dev_ops = {
1717
.uverbs_abi_ver = MANA_IB_UVERBS_ABI_VERSION,
1818

1919
.add_gid = mana_ib_gd_add_gid,
20+
.alloc_mw = mana_ib_alloc_mw,
2021
.alloc_pd = mana_ib_alloc_pd,
2122
.alloc_ucontext = mana_ib_alloc_ucontext,
2223
.create_ah = mana_ib_create_ah,
2324
.create_cq = mana_ib_create_cq,
2425
.create_qp = mana_ib_create_qp,
2526
.create_rwq_ind_table = mana_ib_create_rwq_ind_table,
2627
.create_wq = mana_ib_create_wq,
28+
.dealloc_mw = mana_ib_dealloc_mw,
2729
.dealloc_pd = mana_ib_dealloc_pd,
2830
.dealloc_ucontext = mana_ib_dealloc_ucontext,
2931
.del_gid = mana_ib_gd_del_gid,
@@ -53,6 +55,7 @@ static const struct ib_device_ops mana_ib_dev_ops = {
5355

5456
INIT_RDMA_OBJ_SIZE(ib_ah, mana_ib_ah, ibah),
5557
INIT_RDMA_OBJ_SIZE(ib_cq, mana_ib_cq, ibcq),
58+
INIT_RDMA_OBJ_SIZE(ib_mw, mana_ib_mw, ibmw),
5659
INIT_RDMA_OBJ_SIZE(ib_pd, mana_ib_pd, ibpd),
5760
INIT_RDMA_OBJ_SIZE(ib_qp, mana_ib_qp, ibqp),
5861
INIT_RDMA_OBJ_SIZE(ib_ucontext, mana_ib_ucontext, ibucontext),

drivers/infiniband/hw/mana/mana_ib.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ struct mana_ib_ah {
125125
dma_addr_t dma_handle;
126126
};
127127

128+
struct mana_ib_mw {
129+
struct ib_mw ibmw;
130+
mana_handle_t mw_handle;
131+
};
132+
128133
struct mana_ib_mr {
129134
struct ib_mr ibmr;
130135
struct ib_umem *umem;
@@ -736,6 +741,9 @@ void mana_drain_gsi_sqs(struct mana_ib_dev *mdev);
736741
int mana_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
737742
int mana_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
738743

744+
int mana_ib_alloc_mw(struct ib_mw *mw, struct ib_udata *udata);
745+
int mana_ib_dealloc_mw(struct ib_mw *mw);
746+
739747
struct ib_mr *mana_ib_reg_user_mr_dmabuf(struct ib_pd *ibpd, u64 start, u64 length,
740748
u64 iova, int fd, int mr_access_flags,
741749
struct ib_dmah *dmah,

drivers/infiniband/hw/mana/mr.c

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "mana_ib.h"
77

88
#define VALID_MR_FLAGS (IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_WRITE | IB_ACCESS_REMOTE_READ |\
9-
IB_ACCESS_REMOTE_ATOMIC | IB_ZERO_BASED)
9+
IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND | IB_ZERO_BASED)
1010

1111
#define VALID_DMA_MR_FLAGS (IB_ACCESS_LOCAL_WRITE)
1212

@@ -27,6 +27,9 @@ mana_ib_verbs_to_gdma_access_flags(int access_flags)
2727
if (access_flags & IB_ACCESS_REMOTE_ATOMIC)
2828
flags |= GDMA_ACCESS_FLAG_REMOTE_ATOMIC;
2929

30+
if (access_flags & IB_ACCESS_MW_BIND)
31+
flags |= GDMA_ACCESS_FLAG_BIND_MW;
32+
3033
return flags;
3134
}
3235

@@ -287,6 +290,55 @@ struct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags)
287290
return ERR_PTR(err);
288291
}
289292

293+
static int mana_ib_gd_create_mw(struct mana_ib_dev *dev, struct mana_ib_pd *pd, struct ib_mw *ibmw)
294+
{
295+
struct mana_ib_mw *mw = container_of(ibmw, struct mana_ib_mw, ibmw);
296+
struct gdma_context *gc = mdev_to_gc(dev);
297+
struct gdma_create_mr_response resp = {};
298+
struct gdma_create_mr_request req = {};
299+
int err;
300+
301+
mana_gd_init_req_hdr(&req.hdr, GDMA_CREATE_MR, sizeof(req), sizeof(resp));
302+
req.hdr.req.msg_version = GDMA_MESSAGE_V2;
303+
req.pd_handle = pd->pd_handle;
304+
305+
switch (mw->ibmw.type) {
306+
case IB_MW_TYPE_1:
307+
req.mr_type = GDMA_MR_TYPE_MW1;
308+
break;
309+
case IB_MW_TYPE_2:
310+
req.mr_type = GDMA_MR_TYPE_MW2;
311+
break;
312+
default:
313+
return -EINVAL;
314+
}
315+
316+
err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
317+
if (err)
318+
return err;
319+
320+
mw->ibmw.rkey = resp.rkey;
321+
mw->mw_handle = resp.mr_handle;
322+
323+
return 0;
324+
}
325+
326+
int mana_ib_alloc_mw(struct ib_mw *ibmw, struct ib_udata *udata)
327+
{
328+
struct mana_ib_dev *mdev = container_of(ibmw->device, struct mana_ib_dev, ib_dev);
329+
struct mana_ib_pd *pd = container_of(ibmw->pd, struct mana_ib_pd, ibpd);
330+
331+
return mana_ib_gd_create_mw(mdev, pd, ibmw);
332+
}
333+
334+
int mana_ib_dealloc_mw(struct ib_mw *ibmw)
335+
{
336+
struct mana_ib_dev *dev = container_of(ibmw->device, struct mana_ib_dev, ib_dev);
337+
struct mana_ib_mw *mw = container_of(ibmw, struct mana_ib_mw, ibmw);
338+
339+
return mana_ib_gd_destroy_mr(dev, mw->mw_handle);
340+
}
341+
290342
int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata)
291343
{
292344
struct mana_ib_mr *mr = container_of(ibmr, struct mana_ib_mr, ibmr);

include/net/mana/gdma.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ enum gdma_mr_access_flags {
778778
GDMA_ACCESS_FLAG_REMOTE_READ = BIT_ULL(2),
779779
GDMA_ACCESS_FLAG_REMOTE_WRITE = BIT_ULL(3),
780780
GDMA_ACCESS_FLAG_REMOTE_ATOMIC = BIT_ULL(4),
781+
GDMA_ACCESS_FLAG_BIND_MW = BIT_ULL(5),
781782
};
782783

783784
/* GDMA_CREATE_DMA_REGION */
@@ -870,6 +871,10 @@ enum gdma_mr_type {
870871
GDMA_MR_TYPE_ZBVA = 4,
871872
/* Device address MRs */
872873
GDMA_MR_TYPE_DM = 5,
874+
/* Memory Window type 1 */
875+
GDMA_MR_TYPE_MW1 = 6,
876+
/* Memory Window type 2 */
877+
GDMA_MR_TYPE_MW2 = 7,
873878
};
874879

875880
struct gdma_create_mr_params {

0 commit comments

Comments
 (0)