|
| 1 | +# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) |
| 2 | +# Copyright Amazon.com, Inc. or its affiliates. All rights reserved. |
| 3 | + |
| 4 | +#cython: language_level=3 |
| 5 | + |
| 6 | +from pyverbs.base import PyverbsRDMAErrno, PyverbsRDMAError |
| 7 | +from pyverbs.device cimport Context |
| 8 | +cimport pyverbs.libibverbs as v |
| 9 | + |
| 10 | + |
| 11 | +cdef class CompCntrInitAttr(PyverbsObject): |
| 12 | + """Represents ibv_comp_cntr_init_attr struct.""" |
| 13 | + def __init__(self, comp_mask=0, type=0, flags=0): |
| 14 | + super().__init__() |
| 15 | + self.attr.comp_mask = comp_mask |
| 16 | + self.attr.type = type |
| 17 | + self.attr.flags = flags |
| 18 | + |
| 19 | + @property |
| 20 | + def comp_mask(self): |
| 21 | + return self.attr.comp_mask |
| 22 | + |
| 23 | + @property |
| 24 | + def type(self): |
| 25 | + return self.attr.type |
| 26 | + |
| 27 | + @property |
| 28 | + def flags(self): |
| 29 | + return self.attr.flags |
| 30 | + |
| 31 | + |
| 32 | +cdef class QPAttachCompCntrAttr(PyverbsObject): |
| 33 | + """Represents ibv_qp_attach_comp_cntr_attr struct.""" |
| 34 | + def __init__(self, op_mask=0): |
| 35 | + super().__init__() |
| 36 | + self.attr.op_mask = op_mask |
| 37 | + |
| 38 | + @property |
| 39 | + def op_mask(self): |
| 40 | + return self.attr.op_mask |
| 41 | + |
| 42 | + |
| 43 | +cdef class CompCntr(PyverbsCM): |
| 44 | + """Represents a Completion Counter.""" |
| 45 | + def __init__(self, Context ctx not None, CompCntrInitAttr attr not None): |
| 46 | + super().__init__() |
| 47 | + self.comp_cntr = v.ibv_create_comp_cntr(ctx.context, &attr.attr) |
| 48 | + if self.comp_cntr == NULL: |
| 49 | + raise PyverbsRDMAErrno('Failed to create comp_cntr') |
| 50 | + self.ctx = ctx |
| 51 | + |
| 52 | + def close(self): |
| 53 | + if self.comp_cntr != NULL: |
| 54 | + rc = v.ibv_destroy_comp_cntr(self.comp_cntr) |
| 55 | + if rc: |
| 56 | + raise PyverbsRDMAError('Failed to destroy comp_cntr', rc) |
| 57 | + self.comp_cntr = NULL |
| 58 | + |
| 59 | + @property |
| 60 | + def comp_count_max_value(self): |
| 61 | + return self.comp_cntr.comp_count_max_value |
| 62 | + |
| 63 | + @property |
| 64 | + def err_count_max_value(self): |
| 65 | + return self.comp_cntr.err_count_max_value |
| 66 | + |
| 67 | + def set(self, value): |
| 68 | + rc = v.ibv_set_comp_cntr(self.comp_cntr, value) |
| 69 | + if rc: |
| 70 | + raise PyverbsRDMAError('Failed to set comp_cntr', rc) |
| 71 | + |
| 72 | + def set_err(self, value): |
| 73 | + rc = v.ibv_set_err_comp_cntr(self.comp_cntr, value) |
| 74 | + if rc: |
| 75 | + raise PyverbsRDMAError('Failed to set_err comp_cntr', rc) |
| 76 | + |
| 77 | + def inc(self, amount): |
| 78 | + rc = v.ibv_inc_comp_cntr(self.comp_cntr, amount) |
| 79 | + if rc: |
| 80 | + raise PyverbsRDMAError('Failed to inc comp_cntr', rc) |
| 81 | + |
| 82 | + def inc_err(self, amount): |
| 83 | + rc = v.ibv_inc_err_comp_cntr(self.comp_cntr, amount) |
| 84 | + if rc: |
| 85 | + raise PyverbsRDMAError('Failed to inc_err comp_cntr', rc) |
| 86 | + |
| 87 | + def read(self): |
| 88 | + cdef unsigned long value = 0 |
| 89 | + rc = v.ibv_read_comp_cntr(self.comp_cntr, &value) |
| 90 | + if rc: |
| 91 | + raise PyverbsRDMAError('Failed to read comp_cntr', rc) |
| 92 | + return value |
| 93 | + |
| 94 | + def read_err(self): |
| 95 | + cdef unsigned long value = 0 |
| 96 | + rc = v.ibv_read_err_comp_cntr(self.comp_cntr, &value) |
| 97 | + if rc: |
| 98 | + raise PyverbsRDMAError('Failed to read_err comp_cntr', rc) |
| 99 | + return value |
0 commit comments