Skip to content

Commit

Permalink
pyverbs: Add dr packet-reformat action support
Browse files Browse the repository at this point in the history
Add API to support creation of packet-reformat action.

Signed-off-by: Shachar Kagan <skagan@nvidia.com>
Signed-off-by: Edward Srouji <edwards@nvidia.com>
  • Loading branch information
ShacharKagan authored and EdwardSro committed Feb 23, 2022
1 parent 416315b commit 28d735d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pyverbs/providers/mlx5/dr_action.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ cdef class DrActionIBPort(DrAction):

cdef class DrActionDestTir(DrAction):
cdef Mlx5DevxObj devx_obj

cdef class DrActionPacketReformat(DrAction):
cdef DrDomain domain
39 changes: 38 additions & 1 deletion pyverbs/providers/mlx5/dr_action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,41 @@ cdef class DrActionDestTir(DrAction):
if self.action == NULL:
raise PyverbsRDMAErrno('Failed to create TIR action')
self.devx_obj = devx_tir
devx_tir.add_ref(self)
devx_tir.add_ref(self)


cdef class DrActionPacketReformat(DrAction):
def __init__(self, DrDomain domain, flags=0,
reformat_type=dv.MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2,
data=None):
"""
Create DR Packet Reformat action.
:param domain: DrDomain object where the action should be placed.
:param flags: Packet reformat action flags.
:param reformat_type: L2 or L3 encap or decap.
:param data: Encap headers (optional).
"""
super().__init__()
cdef char *reformat_data = NULL
data_len = 0 if data is None else len(data)
if data:
arr = bytearray(data)
reformat_data = <char *>calloc(1, data_len)
for i in range(data_len):
reformat_data[i] = arr[i]
self.action = dv.mlx5dv_dr_action_create_packet_reformat(
domain.domain, flags, reformat_type, data_len, reformat_data)
if data:
free(reformat_data)
if self.action == NULL:
raise PyverbsRDMAErrno('Failed to create dr action packet reformat')
self.domain = domain
domain.dr_actions.add(self)

def __dealloc__(self):
self.close()

cpdef close(self):
if self.action != NULL:
super(DrActionPacketReformat, self).close()
self.domain = None
4 changes: 4 additions & 0 deletions pyverbs/providers/mlx5/libmlx5.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ cdef extern from 'infiniband/mlx5dv.h':
uint32_t vport)
mlx5dv_dr_action *mlx5dv_dr_action_create_dest_ib_port(mlx5dv_dr_domain *dmn,
uint32_t ib_port)
mlx5dv_dr_action *mlx5dv_dr_action_create_packet_reformat(mlx5dv_dr_domain *domain,
uint32_t flags,
unsigned char reformat_type,
size_t data_sz, void *data)
int mlx5dv_dr_rule_destroy(mlx5dv_dr_rule *rule)
void mlx5dv_dr_domain_allow_duplicate_rules(mlx5dv_dr_domain *dmn, bool allow)

Expand Down

0 comments on commit 28d735d

Please sign in to comment.