Skip to content

Commit 18f83bd

Browse files
dkkranzmrgolin
authored andcommitted
pyverbs/efa: Support EFA DV CQ
Expose the create CQ and read SGID direct verbs. Signed-off-by: Daniel Kranzdorf <[email protected]>
1 parent b901c97 commit 18f83bd

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed

pyverbs/providers/efa/efa_enums.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ cdef extern from 'infiniband/efadv.h':
1111

1212
cpdef enum:
1313
EFADV_QP_DRIVER_TYPE_SRD
14+
15+
cpdef enum:
16+
EFADV_WC_EX_WITH_SGID

pyverbs/providers/efa/efadv.pxd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
2-
# Copyright 2020 Amazon.com, Inc. or its affiliates. All rights reserved.
2+
# Copyright 2020-2022 Amazon.com, Inc. or its affiliates. All rights reserved.
33

44
#cython: language_level=3
55

66
cimport pyverbs.providers.efa.libefa as dv
77

88
from pyverbs.addr cimport AH
99
from pyverbs.base cimport PyverbsObject
10+
from pyverbs.cq cimport CQEX
1011
from pyverbs.device cimport Context
1112
from pyverbs.qp cimport QP, QPEx
1213

@@ -37,3 +38,11 @@ cdef class SRDQPEx(QPEx):
3738

3839
cdef class EfaQPInitAttr(PyverbsObject):
3940
cdef dv.efadv_qp_init_attr qp_init_attr
41+
42+
43+
cdef class EfaCQ(CQEX):
44+
cdef dv.efadv_cq *dv_cq
45+
46+
47+
cdef class EfaDVCQInitAttr(PyverbsObject):
48+
cdef dv.efadv_cq_init_attr cq_init_attr

pyverbs/providers/efa/efadv.pyx

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
cimport pyverbs.providers.efa.efadv_enums as dve
55
cimport pyverbs.providers.efa.libefa as dv
66

7+
from pyverbs.addr cimport GID
78
from pyverbs.base import PyverbsRDMAErrno, PyverbsRDMAError
9+
from pyverbs.cq cimport CQEX, CqInitAttrEx
810
import pyverbs.enums as e
11+
cimport pyverbs.libibverbs as v
912
from pyverbs.pd cimport PD
1013
from pyverbs.qp cimport QP, QPEx, QPInitAttr, QPInitAttrEx
1114

@@ -194,3 +197,55 @@ cdef class SRDQPEx(QPEx):
194197
'RTR': 0,
195198
'RTS': e.IBV_QP_SQ_PSN}
196199
return srd_mask [dst] | e.IBV_QP_STATE
200+
201+
202+
cdef class EfaDVCQInitAttr(PyverbsObject):
203+
"""
204+
Represents efadv_cq_init_attr struct.
205+
"""
206+
def __init__(self, wc_flags=0):
207+
super().__init__()
208+
self.cq_init_attr.wc_flags = wc_flags
209+
210+
@property
211+
def comp_mask(self):
212+
return self.cq_init_attr.comp_mask
213+
214+
@property
215+
def wc_flags(self):
216+
return self.cq_init_attr.wc_flags
217+
218+
@wc_flags.setter
219+
def wc_flags(self, val):
220+
self.cq_init_attr.wc_flags = val
221+
222+
223+
cdef class EfaCQ(CQEX):
224+
"""
225+
Initializes an Efa CQ according to the user-provided data.
226+
:param ctx: Context object
227+
:param attr_ex: CQInitAttrEx object
228+
:param efa_init_attr: EfaDVCQInitAttr object
229+
:return: An initialized EfaCQ
230+
"""
231+
def __init__(self, Context ctx not None, CqInitAttrEx attr_ex not None, EfaDVCQInitAttr efa_init_attr):
232+
if efa_init_attr is None:
233+
efa_init_attr = EfaDVCQInitAttr()
234+
self.cq = dv.efadv_create_cq(ctx.context, &attr_ex.attr, &efa_init_attr.cq_init_attr, sizeof(efa_init_attr.cq_init_attr))
235+
if self.cq == NULL:
236+
raise PyverbsRDMAErrno('Failed to create EFA CQ')
237+
self.ibv_cq = v.ibv_cq_ex_to_cq(self.cq)
238+
self.dv_cq = dv.efadv_cq_from_ibv_cq_ex(self.cq)
239+
self.context = ctx
240+
ctx.add_ref(self)
241+
super().__init__(ctx, attr_ex)
242+
243+
def read_sgid(self):
244+
"""
245+
Read SGID from last work completion, if AH is unknown.
246+
"""
247+
sgid = GID()
248+
err = dv.efadv_wc_read_sgid(self.dv_cq, &sgid.gid)
249+
if err:
250+
return None
251+
return sgid

pyverbs/providers/efa/efadv_enums.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ cdef extern from 'infiniband/efadv.h':
1212

1313
cpdef enum:
1414
EFADV_QP_DRIVER_TYPE_SRD
15+
16+
cpdef enum:
17+
EFADV_WC_EX_WITH_SGID

pyverbs/providers/efa/libefa.pxd

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
2-
# Copyright 2020 Amazon.com, Inc. or its affiliates. All rights reserved.
2+
# Copyright 2020-2022 Amazon.com, Inc. or its affiliates. All rights reserved.
33

44
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t
55
cimport pyverbs.libibverbs as v
@@ -28,6 +28,13 @@ cdef extern from 'infiniband/efadv.h':
2828
uint32_t driver_qp_type;
2929
uint8_t reserved[4];
3030

31+
cdef struct efadv_cq_init_attr:
32+
uint64_t comp_mask;
33+
uint64_t wc_flags;
34+
35+
cdef struct efadv_cq:
36+
uint64_t comp_mask;
37+
3138
int efadv_query_device(v.ibv_context *ibvctx, efadv_device_attr *attrs,
3239
uint32_t inlen)
3340
int efadv_query_ah(v.ibv_ah *ibvah, efadv_ah_attr *attr,
@@ -38,3 +45,9 @@ cdef extern from 'infiniband/efadv.h':
3845
v.ibv_qp_init_attr_ex *attr_ex,
3946
efadv_qp_init_attr *efa_attr,
4047
uint32_t inlen)
48+
v.ibv_cq_ex *efadv_create_cq(v.ibv_context *ibvctx,
49+
v.ibv_cq_init_attr_ex *attr_ex,
50+
efadv_cq_init_attr *efa_attr,
51+
uint32_t inlen)
52+
efadv_cq *efadv_cq_from_ibv_cq_ex(v.ibv_cq_ex *ibvcqx)
53+
int efadv_wc_read_sgid(efadv_cq *efadv_cq, v.ibv_gid *sgid)

0 commit comments

Comments
 (0)