Line data Source code
1 : /**
2 : * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "ra_client_host.h"
12 :
13 0 : HCCP_ATTRI_VISI_DEF int RaQpCreateWithCQWithAttrs(void *rdevHandle, struct QpExtAttrs *extAttrs, unsigned int sendCqn,
14 : unsigned int recvCqn, void **qpHandle)
15 : {
16 0 : struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
17 : unsigned int phyId;
18 : int ret;
19 :
20 0 : CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
21 : rdmaHandleTmp->rdmaOps->raQpCreateWithCQWithAttrs == NULL,
22 : hccp_err("[create][ra_qp_with_cq_attrs]rdev_handle is NULL or func is NULL"),
23 : ConverReturnCode(RDMA_OP, -EINVAL));
24 :
25 0 : CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_qp_with_cq_attrs]qp_handle is NULL"),
26 : ConverReturnCode(RDMA_OP, -EINVAL));
27 :
28 0 : CHK_PRT_RETURN(extAttrs == NULL, hccp_err("[create][ra_qp_with_cq_attrs]ext_attrs is NULL"),
29 : ConverReturnCode(RDMA_OP, -EINVAL));
30 :
31 0 : CHK_PRT_RETURN(extAttrs->version != QP_CREATE_WITH_ATTR_VERSION,
32 : hccp_err("[create][ra_qp_with_cq_attrs]attr version[%d] mismatch, expect [%d]", extAttrs->version,
33 : QP_CREATE_WITH_ATTR_VERSION),
34 : ConverReturnCode(RDMA_OP, -EINVAL));
35 :
36 0 : CHK_PRT_RETURN(extAttrs->qpMode < 0 || extAttrs->qpMode >= RA_RS_ERR_QP_MODE,
37 : hccp_err("[create][ra_qp_with_cq_attrs]QP mode[%d] must greater or equal to 0 and less than %d",
38 : extAttrs->qpMode, RA_RS_ERR_QP_MODE),
39 : ConverReturnCode(RDMA_OP, -EINVAL));
40 : // no need and disallow to set data_plane_flag, set it to default value 0
41 0 : extAttrs->dataPlaneFlag.value = 0;
42 :
43 0 : phyId = rdmaHandleTmp->rdevInfo.phyId;
44 0 : CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
45 : hccp_err("[create][ra_qp_with_cq_attrs]phyId(%u) must greater or equal to 0 and less than %d!", phyId,
46 : RA_MAX_PHY_ID_NUM),
47 : ConverReturnCode(RDMA_OP, -EINVAL));
48 :
49 0 : hccp_run_info("Input parameters: phyId[%u] qp_mode[%d] sendCqn[%u] recvCqn[%u] qpAttr.cap{%u,%u,%u,%u,%u}"
50 : " qp_type[%u] sqSigAll[%d], cnt[%u]",
51 : phyId, extAttrs->qpMode, sendCqn, recvCqn, extAttrs->qpAttr.cap.max_send_wr, extAttrs->qpAttr.cap.max_recv_wr,
52 : extAttrs->qpAttr.cap.max_send_sge, extAttrs->qpAttr.cap.max_recv_sge, extAttrs->qpAttr.cap.max_inline_data,
53 : extAttrs->qpAttr.qp_type, extAttrs->qpAttr.sq_sig_all, rdmaHandleTmp->qpCnt);
54 :
55 0 : rdmaHandleTmp->qpCnt++;
56 0 : ret = rdmaHandleTmp->rdmaOps->raQpCreateWithCQWithAttrs(rdmaHandleTmp, extAttrs, sendCqn, recvCqn, qpHandle);
57 0 : CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
58 : hccp_err("[create][ra_qp_with_cq_attrs]create qp failed, ret(%d) phyId(%u)", ret, phyId),
59 : ConverReturnCode(RDMA_OP, ret));
60 :
61 0 : return 0;
62 : }
63 :
64 0 : HCCP_ATTRI_VISI_DEF int RaTypicalCqCreate(void *rdevHandle, unsigned int cqDepth, unsigned int *cqn, void **cqHandle)
65 : {
66 0 : struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
67 : unsigned int phyId;
68 : int ret;
69 :
70 0 : CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
71 : rdmaHandleTmp->rdmaOps->raTypicalCqCreate == NULL,
72 : hccp_err("[create][ra_typical_cq]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
73 :
74 0 : CHK_PRT_RETURN(cqHandle == NULL || cqn == NULL, hccp_err("[create][ra_typical_cq]cq_handle or cqn is NULL"),
75 : ConverReturnCode(RDMA_OP, -EINVAL));
76 :
77 0 : phyId = rdmaHandleTmp->rdevInfo.phyId;
78 0 : CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
79 : hccp_err("[create][ra_typical_cq]phyId(%u) exceeds max(%u)", phyId, RA_MAX_PHY_ID_NUM),
80 : ConverReturnCode(RDMA_OP, -EINVAL));
81 :
82 0 : hccp_run_info("RaTypicalCqCreate: phyId[%u], cqDepth[%u]", phyId, cqDepth);
83 :
84 0 : ret = rdmaHandleTmp->rdmaOps->raTypicalCqCreate(rdmaHandleTmp, cqDepth, cqn, cqHandle);
85 0 : CHK_PRT_RETURN(ret != 0 || *cqHandle == NULL,
86 : hccp_err("[create][ra_typical_cq]create cq failed ret(%d) phyId(%u)", ret, phyId),
87 : ConverReturnCode(RDMA_OP, ret));
88 :
89 0 : return 0;
90 : }
91 :
92 0 : HCCP_ATTRI_VISI_DEF int RaTypicalCqDestroy(void *rdevHandle, unsigned int cqn, void *cqHandle)
93 : {
94 0 : struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
95 : unsigned int phyId;
96 : int ret;
97 :
98 0 : CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
99 : rdmaHandleTmp->rdmaOps->raTypicalCqDestroy == NULL,
100 : hccp_err("[destroy][ra_typical_cq]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
101 :
102 0 : CHK_PRT_RETURN(cqHandle == NULL, hccp_err("[destroy][ra_typical_cq]cq_handle is NULL"),
103 : ConverReturnCode(RDMA_OP, -EINVAL));
104 :
105 0 : phyId = rdmaHandleTmp->rdevInfo.phyId;
106 0 : CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
107 : hccp_err("[destroy][ra_typical_cq]phyId(%u) exceeds max(%u)", phyId, RA_MAX_PHY_ID_NUM),
108 : ConverReturnCode(RDMA_OP, -EINVAL));
109 :
110 0 : hccp_run_info("RaTypicalCqDestroy: phyId[%u], cqn[%u]", phyId, cqn);
111 :
112 0 : ret = rdmaHandleTmp->rdmaOps->raTypicalCqDestroy(rdmaHandleTmp, cqn, cqHandle);
113 0 : CHK_PRT_RETURN(ret != 0, hccp_err("[destroy][ra_typical_cq]destroy cq failed ret(%d) phyId(%u)", ret, phyId),
114 : ConverReturnCode(RDMA_OP, ret));
115 :
116 0 : return 0;
117 : }
118 :
119 0 : HCCP_ATTRI_VISI_DEF int RaQpDestroyWithoutCQ(void *qpHandle)
120 : {
121 0 : struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
122 : int ret;
123 :
124 0 : CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[destroy][ra_qp]qp_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
125 :
126 0 : CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raQpDestroyWithoutCQ == NULL,
127 : hccp_err(
128 : "[destroy][ra_qp]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_qp_destroy_without_cq is NULL, invalid"),
129 : ConverReturnCode(RDMA_OP, -EINVAL));
130 :
131 0 : hccp_run_info("Input parameters: qpn[%u], phyId[%u], rdevIndex[%u] qpMode[%d] flag[%d]", raQpHandle->qpn,
132 : raQpHandle->phyId, raQpHandle->rdevIndex, raQpHandle->qpMode, raQpHandle->flag);
133 :
134 0 : ret = raQpHandle->rdmaOps->raQpDestroyWithoutCQ(raQpHandle);
135 0 : return ConverReturnCode(RDMA_OP, ret);
136 : }
137 :
138 0 : HCCP_ATTRI_VISI_DEF int RaSendWrVerbs(void *qpHandle, struct SendWrVerbs *wr, struct SendWrRsp *opRsp)
139 : {
140 0 : struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
141 : int ret;
142 :
143 0 : CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || wr->sgList == NULL || opRsp == NULL,
144 : hccp_err("[send][ra_wr]qp_handle or wr or sg_list or op_rsp is NULL, para error!"),
145 : ConverReturnCode(RDMA_OP, -EINVAL));
146 :
147 0 : CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWrVerbs == NULL,
148 : hccp_err("[send][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr_verbs is NULL, invalid"),
149 : ConverReturnCode(RDMA_OP, -EINVAL));
150 :
151 0 : ret = raQpHandle->rdmaOps->raSendWrVerbs(raQpHandle, wr, opRsp);
152 0 : return ConverReturnCode(RDMA_OP, ret);
153 : }
154 :
155 0 : HCCP_ATTRI_VISI_DEF int RaRecvWrVerbs(void *qpHandle, struct RecvWrVerbs *wr)
156 : {
157 0 : struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
158 : int ret;
159 :
160 0 : CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || wr->sgList == NULL,
161 : hccp_err("[recv][ra_wr]qp_handle or wr or sg_list is NULL, para error!"), ConverReturnCode(RDMA_OP, -EINVAL));
162 :
163 0 : CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raRecvWrVerbs == NULL,
164 : hccp_err("[recv][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_recv_wr_verbs is NULL, invalid"),
165 : ConverReturnCode(RDMA_OP, -EINVAL));
166 :
167 0 : ret = raQpHandle->rdmaOps->raRecvWrVerbs(raQpHandle, wr);
168 0 : return ConverReturnCode(RDMA_OP, ret);
169 : }
170 :
171 0 : HCCP_ATTRI_VISI_DEF int RaPollTypicalCq(void *cqHandle, unsigned int numEntries, void *wc)
172 : {
173 0 : struct RaTypicalCqHandle *cqHdc = (struct RaTypicalCqHandle *)cqHandle;
174 0 : if (cqHandle == NULL || wc == NULL) {
175 0 : hccp_err("[ra_poll]cq_handle is NULL or wc is NULL, para error!");
176 0 : return ConverReturnCode(RDMA_OP, -EINVAL);
177 : }
178 0 : if (cqHdc->rdmaOps == NULL || cqHdc->rdmaOps->raPollTypicalCq == NULL) {
179 0 : hccp_err("[ra_poll]rdma_ops is NULL or ra_poll_typical_cq is NULL, invalid");
180 0 : return ConverReturnCode(RDMA_OP, -EINVAL);
181 : }
182 0 : int ret = cqHdc->rdmaOps->raPollTypicalCq(cqHdc, numEntries, wc);
183 0 : if (ret < 0) {
184 0 : return ConverReturnCode(RDMA_OP, ret);
185 : }
186 0 : return ret;
187 : }
|