Skip to content

Commit 01aa334

Browse files
committed
libxscale: Add support for pd and mr
This patch adds support for pd and mr operations including: 1. alloc_pd 2. dealloc_pd 3. reg_mr 4. dereg_mr Signed-off-by: Tian Xin <[email protected]> Signed-off-by: Wei Honggang <[email protected]> Signed-off-by: Zhao Qianwei <[email protected]> Signed-off-by: Li Qiang <[email protected]> Signed-off-by: Yan Lei <[email protected]>
1 parent 15d7d9c commit 01aa334

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

providers/xscale/verbs.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,98 @@ int xsc_query_port(struct ibv_context *context, u8 port,
3636
return ibv_cmd_query_port(context, port, attr, &cmd, sizeof(cmd));
3737
}
3838

39+
struct ibv_pd *xsc_alloc_pd(struct ibv_context *context)
40+
{
41+
struct ibv_alloc_pd cmd;
42+
struct xsc_alloc_pd_resp resp;
43+
struct xsc_pd *pd;
44+
45+
pd = calloc(1, sizeof(*pd));
46+
if (!pd)
47+
return NULL;
48+
49+
if (ibv_cmd_alloc_pd(context, &pd->ibv_pd, &cmd, sizeof(cmd),
50+
&resp.ibv_resp, sizeof(resp))) {
51+
free(pd);
52+
return NULL;
53+
}
54+
55+
atomic_init(&pd->refcount, 1);
56+
pd->pdn = resp.pdn;
57+
xsc_dbg(to_xctx(context)->dbg_fp, XSC_DBG_PD, "pd number:%u\n",
58+
pd->pdn);
59+
60+
return &pd->ibv_pd;
61+
}
62+
63+
int xsc_free_pd(struct ibv_pd *pd)
64+
{
65+
int ret;
66+
struct xsc_pd *xpd = to_xpd(pd);
67+
68+
if (atomic_load(&xpd->refcount) > 1)
69+
return EBUSY;
70+
71+
ret = ibv_cmd_dealloc_pd(pd);
72+
if (ret)
73+
return ret;
74+
75+
xsc_dbg(to_xctx(pd->context)->dbg_fp, XSC_DBG_PD, "dealloc pd\n");
76+
free(xpd);
77+
78+
return 0;
79+
}
80+
81+
struct ibv_mr *xsc_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
82+
u64 hca_va, int acc)
83+
{
84+
struct xsc_mr *mr;
85+
struct ibv_reg_mr cmd;
86+
int ret;
87+
enum ibv_access_flags access = (enum ibv_access_flags)acc;
88+
struct ib_uverbs_reg_mr_resp resp;
89+
90+
mr = calloc(1, sizeof(*mr));
91+
if (!mr)
92+
return NULL;
93+
94+
ret = ibv_cmd_reg_mr(pd, addr, length, hca_va, access, &mr->vmr, &cmd,
95+
sizeof(cmd), &resp, sizeof(resp));
96+
if (ret) {
97+
xsc_free_buf(&mr->buf);
98+
free(mr);
99+
return NULL;
100+
}
101+
mr->alloc_flags = acc;
102+
103+
xsc_dbg(to_xctx(pd->context)->dbg_fp, XSC_DBG_MR, "lkey:%u, rkey:%u\n",
104+
mr->vmr.ibv_mr.lkey, mr->vmr.ibv_mr.rkey);
105+
106+
return &mr->vmr.ibv_mr;
107+
}
108+
109+
void xsc_free_buf(struct xsc_buf *buf)
110+
{
111+
ibv_dofork_range(buf->buf, buf->length);
112+
free(buf->buf);
113+
}
114+
115+
int xsc_dereg_mr(struct verbs_mr *vmr)
116+
{
117+
int ret;
118+
119+
if (vmr->mr_type == IBV_MR_TYPE_NULL_MR)
120+
goto free;
121+
122+
ret = ibv_cmd_dereg_mr(vmr);
123+
if (ret)
124+
return ret;
125+
126+
free:
127+
free(vmr);
128+
return 0;
129+
}
130+
39131
static void xsc_set_fw_version(struct ibv_device_attr *attr,
40132
union xsc_ib_fw_ver *fw_ver)
41133
{

providers/xscale/xscale.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ static void xsc_free_context(struct ibv_context *ibctx);
3333

3434
static const struct verbs_context_ops xsc_ctx_common_ops = {
3535
.query_port = xsc_query_port,
36+
.alloc_pd = xsc_alloc_pd,
37+
.dealloc_pd = xsc_free_pd,
38+
.reg_mr = xsc_reg_mr,
39+
.dereg_mr = xsc_dereg_mr,
3640
.query_device_ex = xsc_query_device_ex,
3741
.free_context = xsc_free_context,
3842
};

0 commit comments

Comments
 (0)