Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Extend mlx5 flow steering coverage #1585

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyverbs/providers/mlx5/libmlx5.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ cdef extern from 'infiniband/mlx5dv.h':
mlx5dv_flow_match_parameters *match_mask;
uint64_t comp_mask;
mlx5_ib_uapi_flow_table_type ft_type;
uint32_t ib_port;

cdef struct mlx5dv_flow_matcher

Expand Down
6 changes: 6 additions & 0 deletions pyverbs/providers/mlx5/mlx5_enums.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ cdef extern from 'infiniband/mlx5dv.h':
cpdef enum:
MLX5DV_UMEM_MASK_DMABUF

cpdef enum mlx5dv_flow_matcher_attr_mask:
MLX5DV_FLOW_MATCHER_MASK_FT_TYPE
MLX5DV_FLOW_MATCHER_MASK_IB_PORT

cdef unsigned long long MLX5DV_RES_TYPE_QP
cdef unsigned long long MLX5DV_RES_TYPE_RWQ
cdef unsigned long long MLX5DV_RES_TYPE_DBR
Expand All @@ -320,6 +324,8 @@ cdef extern from 'infiniband/mlx5_api.h':
cdef int MLX5DV_FLOW_TABLE_TYPE_NIC_RX
cdef int MLX5DV_FLOW_TABLE_TYPE_NIC_TX
cdef int MLX5DV_FLOW_TABLE_TYPE_FDB
cdef int MLX5DV_FLOW_TABLE_TYPE_RDMA_TRANSPORT_RX
cdef int MLX5DV_FLOW_TABLE_TYPE_RDMA_TRANSPORT_TX

cdef int MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2
cdef int MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL
Expand Down
2 changes: 2 additions & 0 deletions pyverbs/providers/mlx5/mlx5_enums.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ MLX5DV_FLOW_TABLE_TYPE_RDMA_TX_ = MLX5DV_FLOW_TABLE_TYPE_RDMA_TX
MLX5DV_FLOW_TABLE_TYPE_NIC_RX_ = MLX5DV_FLOW_TABLE_TYPE_NIC_RX
MLX5DV_FLOW_TABLE_TYPE_NIC_TX_ = MLX5DV_FLOW_TABLE_TYPE_NIC_TX
MLX5DV_FLOW_TABLE_TYPE_FDB_ = MLX5DV_FLOW_TABLE_TYPE_FDB
MLX5DV_FLOW_TABLE_TYPE_RDMA_TRANSPORT_RX_ = MLX5DV_FLOW_TABLE_TYPE_RDMA_TRANSPORT_RX
MLX5DV_FLOW_TABLE_TYPE_RDMA_TRANSPORT_TX_ = MLX5DV_FLOW_TABLE_TYPE_RDMA_TRANSPORT_TX

MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2_ = \
MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2
Expand Down
18 changes: 12 additions & 6 deletions pyverbs/providers/mlx5/mlx5dv_flow.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from libc.string cimport memcpy

from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsError, \
PyverbsUserError
from pyverbs.device cimport Context
from pyverbs.providers.mlx5.mlx5dv cimport Mlx5DevxObj
from pyverbs.base import PyverbsRDMAErrno
from pyverbs.base cimport close_weakrefs
from pyverbs.device cimport Context
Expand Down Expand Up @@ -53,7 +53,7 @@ cdef class Mlx5FlowMatchParameters(PyverbsObject):
cdef class Mlx5FlowMatcherAttr(PyverbsObject):
def __init__(self, Mlx5FlowMatchParameters match_mask,
attr_type=v.IBV_FLOW_ATTR_NORMAL, flags=0, priority=0,
match_criteria_enable=0, comp_mask=0, ft_type=0):
match_criteria_enable=0, comp_mask=0, ft_type=0, ib_port=0):
"""
Initialize a Mlx5FlowMatcherAttr object over an underlying
mlx5dv_flow_matcher_attr C object that defines matcher's attributes.
Expand All @@ -73,8 +73,8 @@ cdef class Mlx5FlowMatcherAttr(PyverbsObject):
Bit 3: misc_parameters_2
Bit 4: misc_parameters_3
Bit 5: misc_parameters_4
:param comp_mask: MLX5DV_FLOW_MATCHER_MASK_FT_TYPE for ft_type (the
only option that is currently supported)
:param comp_mask: MLX5DV_FLOW_MATCHER_MASK_FT_TYPE for ft_type,
MLX5DV_FLOW_MATCHER_MASK_IB_PORT for ib_port.
:param ft_type: Specified in which flow table type, the matcher will
store the flow rules: MLX5DV_FLOW_TABLE_TYPE_NIC_RX:
Specified this matcher will store ingress flow rules.
Expand All @@ -87,6 +87,7 @@ cdef class Mlx5FlowMatcherAttr(PyverbsObject):
rules.
MLX5DV_FLOW_TABLE_TYPE_RDMA_TX - matcher will store
egress RDMA flow rules.
:param ib_port: Specifies to which vport to attach the matcher.
"""
super().__init__()
self.attr.type = attr_type
Expand All @@ -96,6 +97,7 @@ cdef class Mlx5FlowMatcherAttr(PyverbsObject):
self.attr.match_mask = match_mask.params
self.attr.comp_mask = comp_mask
self.attr.ft_type = ft_type
self.attr.ib_port = ib_port


cdef class Mlx5FlowMatcher(PyverbsObject):
Expand Down Expand Up @@ -166,14 +168,15 @@ cdef class Mlx5PacketReformatFlowAction(FlowAction):

cdef class Mlx5FlowActionAttr(PyverbsObject):
def __init__(self, action_type=None, QP qp=None,
FlowAction flow_action=None):
FlowAction flow_action=None, Mlx5DevxObj obj=None):
"""
Initialize a Mlx5FlowActionAttr object over an underlying
mlx5dv_flow_action_attr C object that defines actions attributes for
the flow matcher.
:param action_type: Type of the action
:param qp: A QP target for go to QP action
:param flow_action: An action to perform for the flow
:param obj: DEVX object
"""
super().__init__()
if action_type:
Expand All @@ -184,6 +187,8 @@ cdef class Mlx5FlowActionAttr(PyverbsObject):
elif action_type == dv.MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION:
self.attr.action = flow_action.action
self.action = flow_action
elif action_type == dv.MLX5DV_FLOW_ACTION_DEST_DEVX:
self.attr.obj = obj.obj
elif action_type:
raise PyverbsUserError(f'Unsupported action type: {action_type}.')

Expand Down Expand Up @@ -250,7 +255,8 @@ cdef class Mlx5Flow(Flow):
if (<Mlx5FlowActionAttr>attr).attr.type == dv.MLX5DV_FLOW_ACTION_DEST_IBV_QP:
(<QP>(attr.qp)).add_ref(self)
self.qp = (<Mlx5FlowActionAttr>attr).qp
elif (<Mlx5FlowActionAttr>attr).attr.type not in [dv.MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION]:
elif (<Mlx5FlowActionAttr>attr).attr.type not in \
[dv.MLX5DV_FLOW_ACTION_IBV_FLOW_ACTION, dv.MLX5DV_FLOW_ACTION_DEST_DEVX]:
raise PyverbsUserError(f'Unsupported action type: '
f'{<Mlx5FlowActionAttr>attr).attr.type}.')
memcpy(tmp_addr, &(<Mlx5FlowActionAttr>attr).attr,
Expand Down
53 changes: 30 additions & 23 deletions tests/mlx5_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,35 @@ def create_cq(self):
raise ex


def create_privileged_context(agr_obj):
"""
Creates a mlx5 privileged context.
:param agr_obj: Aggregation object which contains all resources necessary.
"""
fds_paths = ['/dev/infiniband/mlx5_perm_ctrl_local',
'/dev/infiniband/mlx5_perm_ctrl_other_vhca']
open_fds = []
try:
for file_path in fds_paths:
fd = open(file_path, 'rb')
open_fds.append(fd)
agr_obj.fds = FdArr(arr=[fd.fileno() for fd in open_fds], count=len(open_fds))
attr = Mlx5DVContextAttr(flags=dve.MLX5DV_CONTEXT_FLAGS_DEVX,
comp_mask=dve.MLX5DV_CONTEXT_ATTR_MASK_FD_ARRAY,
fds=agr_obj.fds)
agr_obj.ctx = Mlx5Context(attr, agr_obj.dev_name)
for fd in open_fds: fd.close()
except FileNotFoundError:
for fd in open_fds: fd.close()
raise unittest.SkipTest(f'FDs file not found')
except PyverbsUserError as ex:
for fd in open_fds: fd.close()
raise unittest.SkipTest(f'Could not open mlx5 context ({ex})')
except PyverbsRDMAError as ex:
for fd in open_fds: fd.close()
raise unittest.SkipTest(f'Opening mlx5 DevX context is not supported ({ex})')


class Mlx5PrivilegedRC(Mlx5RcResources):
def __init__(self, dev_name, ib_port, gid_index, msg_size=1024, **kwargs):
"""
Expand All @@ -1061,29 +1090,7 @@ def __init__(self, dev_name, ib_port, gid_index, msg_size=1024, **kwargs):
super().__init__(dev_name, ib_port, gid_index, msg_size=msg_size, **kwargs)

def create_context(self):
fds_paths = ['/dev/infiniband/mlx5_perm_ctrl_local',
'/dev/infiniband/mlx5_perm_ctrl_other_vhca']
fd_array = []
try:
for file_path in fds_paths:
fd = open(file_path, 'rb')
self.open_fds.append(fd)
fd_array.append(fd.fileno())
self.fds = FdArr(arr=fd_array, count=len(fd_array))
attr = Mlx5DVContextAttr(flags=dve.MLX5DV_CONTEXT_FLAGS_DEVX,
comp_mask=dve.MLX5DV_CONTEXT_ATTR_MASK_FD_ARRAY,
fds=self.fds)
self.ctx = Mlx5Context(attr, self.dev_name)
self.close_fds()
except FileNotFoundError:
self.close_fds()
raise unittest.SkipTest(f'FDs file not found')
except PyverbsUserError as ex:
self.close_fds()
raise unittest.SkipTest(f'Could not open mlx5 context ({ex})')
except PyverbsRDMAError as ex:
self.close_fds()
raise unittest.SkipTest(f'Opening mlx5 DevX context is not supported ({ex})')
return create_privileged_context(self)

def close_fds(self):
for open_fd in self.open_fds:
Expand Down
Loading