|
| 1 | +// SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB |
| 2 | +/* |
| 3 | + * Copyright Amazon.com, Inc. or its affiliates. All rights reserved. |
| 4 | + */ |
| 5 | + |
| 6 | +#include <infiniband/cmd_write.h> |
| 7 | + |
| 8 | +int ibv_cmd_create_comp_cntr(struct ibv_context *context, |
| 9 | + struct ibv_comp_cntr *comp_cntr, |
| 10 | + struct ibv_command_buffer *link) |
| 11 | +{ |
| 12 | + DECLARE_COMMAND_BUFFER_LINK(cmdb, UVERBS_OBJECT_COMP_CNTR, |
| 13 | + UVERBS_METHOD_COMP_CNTR_CREATE, 3, link); |
| 14 | + struct ib_uverbs_attr *handle; |
| 15 | + int ret; |
| 16 | + |
| 17 | + comp_cntr->context = context; |
| 18 | + |
| 19 | + handle = fill_attr_out_obj(cmdb, UVERBS_ATTR_CREATE_COMP_CNTR_HANDLE); |
| 20 | + fill_attr_out_ptr(cmdb, UVERBS_ATTR_CREATE_COMP_CNTR_RESP_COUNT_MAX_VALUE, |
| 21 | + &comp_cntr->comp_count_max_value); |
| 22 | + fill_attr_out_ptr(cmdb, UVERBS_ATTR_CREATE_COMP_CNTR_RESP_ERR_COUNT_MAX_VALUE, |
| 23 | + &comp_cntr->err_count_max_value); |
| 24 | + |
| 25 | + ret = execute_ioctl(context, cmdb); |
| 26 | + if (ret) |
| 27 | + return errno; |
| 28 | + |
| 29 | + comp_cntr->handle = read_attr_obj(UVERBS_ATTR_CREATE_COMP_CNTR_HANDLE, handle); |
| 30 | + return 0; |
| 31 | +} |
| 32 | + |
| 33 | +int ibv_cmd_destroy_comp_cntr(struct ibv_comp_cntr *comp_cntr) |
| 34 | +{ |
| 35 | + DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_COMP_CNTR, UVERBS_METHOD_COMP_CNTR_DESTROY, 1); |
| 36 | + int ret; |
| 37 | + |
| 38 | + fill_attr_in_obj(cmdb, UVERBS_ATTR_DESTROY_COMP_CNTR_HANDLE, comp_cntr->handle); |
| 39 | + |
| 40 | + ret = execute_ioctl(comp_cntr->context, cmdb); |
| 41 | + if (verbs_is_destroy_err(&ret)) |
| 42 | + return ret; |
| 43 | + |
| 44 | + return 0; |
| 45 | +} |
| 46 | + |
| 47 | +static int ibv_icmd_modify_comp_cntr(struct ibv_comp_cntr *comp_cntr, |
| 48 | + uint8_t entry, uint8_t op, uint64_t value) |
| 49 | +{ |
| 50 | + DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_COMP_CNTR, UVERBS_METHOD_COMP_CNTR_MODIFY, 4); |
| 51 | + |
| 52 | + fill_attr_in_obj(cmdb, UVERBS_ATTR_MODIFY_COMP_CNTR_HANDLE, comp_cntr->handle); |
| 53 | + fill_attr_const_in(cmdb, UVERBS_ATTR_MODIFY_COMP_CNTR_ENTRY, entry); |
| 54 | + fill_attr_const_in(cmdb, UVERBS_ATTR_MODIFY_COMP_CNTR_OP, op); |
| 55 | + fill_attr_in_uint64(cmdb, UVERBS_ATTR_MODIFY_COMP_CNTR_VALUE, value); |
| 56 | + |
| 57 | + return execute_ioctl(comp_cntr->context, cmdb); |
| 58 | +} |
| 59 | + |
| 60 | +int ibv_cmd_set_comp_cntr(struct ibv_comp_cntr *comp_cntr, uint64_t value) |
| 61 | +{ |
| 62 | + return ibv_icmd_modify_comp_cntr(comp_cntr, IB_UVERBS_COMP_CNTR_ENTRY_COMP, |
| 63 | + IB_UVERBS_COMP_CNTR_MODIFY_OP_SET, value); |
| 64 | +} |
| 65 | + |
| 66 | +int ibv_cmd_set_err_comp_cntr(struct ibv_comp_cntr *comp_cntr, uint64_t value) |
| 67 | +{ |
| 68 | + return ibv_icmd_modify_comp_cntr(comp_cntr, IB_UVERBS_COMP_CNTR_ENTRY_ERR, |
| 69 | + IB_UVERBS_COMP_CNTR_MODIFY_OP_SET, value); |
| 70 | +} |
| 71 | + |
| 72 | +int ibv_cmd_inc_comp_cntr(struct ibv_comp_cntr *comp_cntr, uint64_t amount) |
| 73 | +{ |
| 74 | + return ibv_icmd_modify_comp_cntr(comp_cntr, IB_UVERBS_COMP_CNTR_ENTRY_COMP, |
| 75 | + IB_UVERBS_COMP_CNTR_MODIFY_OP_INC, amount); |
| 76 | +} |
| 77 | + |
| 78 | +int ibv_cmd_inc_err_comp_cntr(struct ibv_comp_cntr *comp_cntr, uint64_t amount) |
| 79 | +{ |
| 80 | + return ibv_icmd_modify_comp_cntr(comp_cntr, IB_UVERBS_COMP_CNTR_ENTRY_ERR, |
| 81 | + IB_UVERBS_COMP_CNTR_MODIFY_OP_INC, amount); |
| 82 | +} |
| 83 | + |
| 84 | +static int ibv_icmd_read_comp_cntr(struct ibv_comp_cntr *comp_cntr, |
| 85 | + uint8_t entry, uint64_t *value) |
| 86 | +{ |
| 87 | + DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_COMP_CNTR, UVERBS_METHOD_COMP_CNTR_READ, 3); |
| 88 | + |
| 89 | + fill_attr_in_obj(cmdb, UVERBS_ATTR_READ_COMP_CNTR_HANDLE, comp_cntr->handle); |
| 90 | + fill_attr_const_in(cmdb, UVERBS_ATTR_READ_COMP_CNTR_ENTRY, entry); |
| 91 | + fill_attr_out_ptr(cmdb, UVERBS_ATTR_READ_COMP_CNTR_RESP_VALUE, value); |
| 92 | + |
| 93 | + return execute_ioctl(comp_cntr->context, cmdb); |
| 94 | +} |
| 95 | + |
| 96 | +int ibv_cmd_read_comp_cntr(struct ibv_comp_cntr *comp_cntr, uint64_t *value) |
| 97 | +{ |
| 98 | + return ibv_icmd_read_comp_cntr(comp_cntr, IB_UVERBS_COMP_CNTR_ENTRY_COMP, value); |
| 99 | +} |
| 100 | + |
| 101 | +int ibv_cmd_read_err_comp_cntr(struct ibv_comp_cntr *comp_cntr, uint64_t *value) |
| 102 | +{ |
| 103 | + return ibv_icmd_read_comp_cntr(comp_cntr, IB_UVERBS_COMP_CNTR_ENTRY_ERR, value); |
| 104 | +} |
| 105 | + |
| 106 | +int ibv_cmd_qp_attach_comp_cntr(struct ibv_qp *qp, struct ibv_comp_cntr *comp_cntr, |
| 107 | + struct ibv_qp_attach_comp_cntr_attr *attr) |
| 108 | +{ |
| 109 | + DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_QP, UVERBS_METHOD_QP_ATTACH_COMP_CNTR, 3); |
| 110 | + uint32_t op_mask = 0; |
| 111 | + |
| 112 | + fill_attr_in_obj(cmdb, UVERBS_ATTR_QP_ATTACH_COMP_CNTR_HANDLE, qp->handle); |
| 113 | + fill_attr_in_obj(cmdb, UVERBS_ATTR_QP_ATTACH_COMP_CNTR_CNTR_HANDLE, comp_cntr->handle); |
| 114 | + |
| 115 | + if (attr->op_mask & IBV_QP_ATTACH_COMP_CNTR_OP_SEND) |
| 116 | + op_mask |= IB_UVERBS_QP_ATTACH_COMP_CNTR_OP_SEND; |
| 117 | + if (attr->op_mask & IBV_QP_ATTACH_COMP_CNTR_OP_RECV) |
| 118 | + op_mask |= IB_UVERBS_QP_ATTACH_COMP_CNTR_OP_RECV; |
| 119 | + if (attr->op_mask & IBV_QP_ATTACH_COMP_CNTR_OP_RDMA_READ) |
| 120 | + op_mask |= IB_UVERBS_QP_ATTACH_COMP_CNTR_OP_RDMA_READ; |
| 121 | + if (attr->op_mask & IBV_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_READ) |
| 122 | + op_mask |= IB_UVERBS_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_READ; |
| 123 | + if (attr->op_mask & IBV_QP_ATTACH_COMP_CNTR_OP_RDMA_WRITE) |
| 124 | + op_mask |= IB_UVERBS_QP_ATTACH_COMP_CNTR_OP_RDMA_WRITE; |
| 125 | + if (attr->op_mask & IBV_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_WRITE) |
| 126 | + op_mask |= IB_UVERBS_QP_ATTACH_COMP_CNTR_OP_REMOTE_RDMA_WRITE; |
| 127 | + |
| 128 | + fill_attr_in_uint32(cmdb, UVERBS_ATTR_QP_ATTACH_COMP_CNTR_OP_MASK, op_mask); |
| 129 | + |
| 130 | + return execute_ioctl(qp->context, cmdb); |
| 131 | +} |
0 commit comments