| 1 |
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) |
| 2 |
# Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file |
| 3 |
|
| 4 |
""" |
| 5 |
Test module for mlx5 packet pacing entry allocation. |
| 6 |
""" |
| 7 |
|
| 8 |
from pyverbs.providers.mlx5.mlx5dv import Mlx5PP, Mlx5Context, Mlx5DVContextAttr |
| 9 |
from pyverbs.pyverbs_error import PyverbsRDMAError, PyverbsUserError |
| 10 |
from pyverbs.providers.mlx5.mlx5_enums import mlx5dv_context_attr_flags, _MLX5DV_PP_ALLOC_FLAGS_DEDICATED_INDEX |
| 11 |
from tests.mlx5_base import Mlx5RDMATestCase |
| 12 |
import unittest |
| 13 |
import struct |
| 14 |
import errno |
| 15 |
|
| 16 |
|
| 17 |
class Mlx5PPRes: |
| 18 |
def __init__(self, dev_name): |
| 19 |
try: |
| 20 |
mlx5dv_attr = Mlx5DVContextAttr(mlx5dv_context_attr_flags.MLX5DV_CONTEXT_FLAGS_DEVX) |
| 21 |
self.ctx = Mlx5Context(mlx5dv_attr, dev_name) |
| 22 |
except PyverbsUserError as ex: |
| 23 |
raise unittest.SkipTest('Could not open mlx5 context ({})' |
| 24 |
.format(str(ex))) |
| 25 |
except PyverbsRDMAError: |
| 26 |
raise unittest.SkipTest('Opening mlx5 DevX context is not supported') |
| 27 |
self.pps = [] |
| 28 |
|
| 29 |
|
| 30 |
class Mlx5PPTestCase(Mlx5RDMATestCase): |
| 31 |
def setUp(self): |
| 32 |
super().setUp() |
| 33 |
self.pp_res = Mlx5PPRes(self.dev_name) |
| 34 |
|
| 35 |
def test_pp_alloc(self): |
| 36 |
""" |
| 37 |
Allocate two packet pacing entries with the same configuration. One of |
| 38 |
the entries is allocated with a dedicated index. |
| 39 |
Then verify that the indexes are different and free the entries. |
| 40 |
""" |
| 41 |
# An arbitrary valid rate limit value (in kbps) |
| 42 |
rate_limit = struct.pack('>I', 100) |
| 43 |
try: |
| 44 |
self.pp_res.pps.append(Mlx5PP(self.pp_res.ctx, rate_limit)) |
| 45 |
# Create a dedicated entry of the same previous configuration |
| 46 |
# and verify that it has a different index |
| 47 |
self.pp_res.pps.append(Mlx5PP(self.pp_res.ctx, rate_limit, |
| 48 |
flags=_MLX5DV_PP_ALLOC_FLAGS_DEDICATED_INDEX)) |
| 49 |
self.assertNotEqual(self.pp_res.pps[0].index, self.pp_res.pps[1].index, |
| 50 |
'Dedicated PP index is not unique') |
| 51 |
for pp in self.pp_res.pps: |
| 52 |
pp.close() |
| 53 |
except PyverbsRDMAError as ex: |
| 54 |
if ex.error_code == errno.EOPNOTSUPP or ex.error_code == errno.EPROTONOSUPPORT: |
| 55 |
raise unittest.SkipTest('Packet pacing entry allocation is not supported') |
| 56 |
raise ex |
| 57 |
finally: |
| 58 |
self.pp_res.ctx.close() |