|
| 1 | +// SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB) |
| 2 | +/* |
| 3 | + * Copyright (c) 2024 ZTE Corporation. |
| 4 | + * |
| 5 | + * This software is available to you under a choice of one of two |
| 6 | + * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | + * General Public License (GPL) Version 2, available from the file |
| 8 | + * COPYING in the main directory of this source tree, or the |
| 9 | + * OpenIB.org BSD license below: |
| 10 | + * |
| 11 | + * Redistribution and use in source and binary forms, with or |
| 12 | + * without modification, are permitted provided that the following |
| 13 | + * conditions are met: |
| 14 | + * |
| 15 | + * - Redistributions of source code must retain the above |
| 16 | + * copyright notice, this list of conditions and the following |
| 17 | + * disclaimer. |
| 18 | + * |
| 19 | + * - Redistributions in binary form must reproduce the above |
| 20 | + * copyright notice, this list of conditions and the following |
| 21 | + * disclaimer in the documentation and/or other materials |
| 22 | + * provided with the distribution. |
| 23 | + * |
| 24 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 | + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 | + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 29 | + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 | + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | + * SOFTWARE. |
| 32 | + */ |
| 33 | +#include <rdma/zxdh_user_ioctl_cmds.h> |
| 34 | +#include <rdma/zxdh_user_ioctl_verbs.h> |
| 35 | +#include "private_verbs_cmd.h" |
| 36 | +#include "zxdh_dv.h" |
| 37 | + |
| 38 | +static inline uint32_t get_log2(uint32_t x) |
| 39 | +{ |
| 40 | + uint32_t r = 0; |
| 41 | + |
| 42 | + for (x >>= 1; x > 0; x >>= 1) |
| 43 | + r++; |
| 44 | + return r; |
| 45 | +} |
| 46 | + |
| 47 | +static void copy_query_qpc(struct zxdh_query_qpc_resp *resp, |
| 48 | + struct zxdh_rdma_qpc *qpc) |
| 49 | +{ |
| 50 | + qpc->ack_err_flag = resp->ack_err_flag; |
| 51 | + qpc->retry_flag = resp->retry_flag; |
| 52 | + qpc->rnr_retry_flag = resp->rnr_retry_flag; |
| 53 | + qpc->cur_retry_count = resp->cur_retry_count; |
| 54 | + qpc->retry_cqe_sq_opcode = resp->retry_cqe_sq_opcode; |
| 55 | + qpc->err_flag = resp->err_flag; |
| 56 | + qpc->package_err_flag = resp->package_err_flag; |
| 57 | + qpc->recv_err_flag = resp->recv_err_flag; |
| 58 | + qpc->tx_last_ack_psn = resp->tx_last_ack_psn; |
| 59 | + qpc->retry_count = resp->retry_count; |
| 60 | + qpc->read_retry_flag = resp->read_retry_flag; |
| 61 | +} |
| 62 | + |
| 63 | +static int _zxdh_query_qpc(struct ibv_qp *qp, struct zxdh_rdma_qpc *qpc) |
| 64 | +{ |
| 65 | + DECLARE_COMMAND_BUFFER(cmd, ZXDH_IB_OBJECT_QP_OBJ, |
| 66 | + ZXDH_IB_METHOD_QP_QUERY_QPC, 2); |
| 67 | + int ret; |
| 68 | + struct zxdh_query_qpc_resp resp_ex = { 0 }; |
| 69 | + |
| 70 | + fill_attr_in_obj(cmd, ZXDH_IB_ATTR_QP_QUERY_HANDLE, qp->handle); |
| 71 | + fill_attr_out_ptr(cmd, ZXDH_IB_ATTR_QP_QUERY_RESP, &resp_ex); |
| 72 | + |
| 73 | + ret = execute_ioctl(qp->context, cmd); |
| 74 | + if (ret) |
| 75 | + return ret; |
| 76 | + |
| 77 | + copy_query_qpc(&resp_ex, qpc); |
| 78 | + return 0; |
| 79 | +} |
| 80 | + |
| 81 | +static struct zxdh_uvcontext_ops zxdh_ctx_ops = { |
| 82 | + .query_qpc = _zxdh_query_qpc, |
| 83 | +}; |
| 84 | + |
| 85 | +static inline struct zxdh_uvcontext *to_zxdhtx(struct ibv_context *ibctx) |
| 86 | +{ |
| 87 | + return container_of(ibctx, struct zxdh_uvcontext, ibv_ctx.context); |
| 88 | +} |
| 89 | + |
| 90 | +int zxdh_reset_qp(struct ibv_qp *qp, uint64_t opcode) |
| 91 | +{ |
| 92 | + struct zxdh_uvcontext_ops *dvops = to_zxdhtx(qp->context)->cxt_ops; |
| 93 | + |
| 94 | + if (!dvops || !dvops->reset_qp) |
| 95 | + return -EOPNOTSUPP; |
| 96 | + return dvops->reset_qp(qp, opcode); |
| 97 | +} |
| 98 | + |
| 99 | +int zxdh_modify_qpc(struct ibv_qp *qp, struct zxdh_rdma_qpc *qpc, |
| 100 | + uint64_t qpc_mask) |
| 101 | +{ |
| 102 | + struct zxdh_uvcontext_ops *dvops = to_zxdhtx(qp->context)->cxt_ops; |
| 103 | + |
| 104 | + if (!dvops || !dvops->modify_qpc) |
| 105 | + return -EOPNOTSUPP; |
| 106 | + return dvops->modify_qpc(qp, qpc, qpc_mask); |
| 107 | +} |
| 108 | + |
| 109 | +int zxdh_query_qpc(struct ibv_qp *qp, struct zxdh_rdma_qpc *qpc) |
| 110 | +{ |
| 111 | + struct zxdh_uvcontext_ops *dvops = to_zxdhtx(qp->context)->cxt_ops; |
| 112 | + |
| 113 | + if (!dvops || !dvops->query_qpc) |
| 114 | + return -EOPNOTSUPP; |
| 115 | + |
| 116 | + return dvops->query_qpc(qp, qpc); |
| 117 | +} |
| 118 | + |
| 119 | +void add_private_ops(struct zxdh_uvcontext *iwvctx) |
| 120 | +{ |
| 121 | + iwvctx->cxt_ops = &zxdh_ctx_ops; |
| 122 | +} |
0 commit comments