Line data Source code
1 : /**
2 : * Copyright (c) 2025 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 <stdlib.h>
12 : #include "user_log.h"
13 : #include "hccp_ctx.h"
14 : #include "hccp_async_ctx.h"
15 : #include "ra_hdc_async_ctx.h"
16 : #include "ra_ctx.h"
17 :
18 4 : HCCP_ATTRI_VISI_DEF int RaGetEidByIpAsync(void *ctxHandle, struct IpInfo ip[], union HccpEid eid[], unsigned int *num,
19 : void **reqHandle)
20 : {
21 4 : struct RaCtxHandle *ctxHandleTmp = NULL;
22 4 : int ret = 0;
23 :
24 4 : CHK_PRT_RETURN(ctxHandle == NULL || ip == NULL || eid == NULL || num == NULL || reqHandle == NULL,
25 : hccp_err("[get][eid_by_ip]ctx_handle or ip or eid or num or req_handle is NULL"),
26 : ConverReturnCode(RDMA_OP, -EINVAL));
27 :
28 3 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_EID_IP_QUERY_MAX_NUM,
29 : hccp_err("[get][eid_by_ip]num(%u) must greater than 0"
30 : " and less or equal to %d",
31 : *num, HCCP_EID_IP_QUERY_MAX_NUM),
32 : ConverReturnCode(RDMA_OP, -EINVAL));
33 :
34 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
35 :
36 2 : hccp_run_info("Input parameters: phy_id:%u, devIndex:0x%x num:%u", ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex,
37 : *num);
38 2 : ret = RaHdcGetEidByIpAsync(ctxHandleTmp, ip, eid, num, reqHandle);
39 2 : if (ret != 0) {
40 1 : hccp_err("[get][eid_by_ip]ra_hdc_get_eid_by_ip_async failed, ret(%d) phyId(%u), devIndex(0x%x)", ret,
41 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
42 : }
43 :
44 2 : return ret;
45 : }
46 :
47 4 : HCCP_ATTRI_VISI_DEF int RaGetIpByEidAsync(void *ctxHandle, union HccpEid eid[], struct IpInfo ip[], unsigned int *num,
48 : void **reqHandle)
49 : {
50 4 : struct RaCtxHandle *ctxHandleTmp = NULL;
51 4 : int ret = 0;
52 :
53 4 : CHK_PRT_RETURN(ctxHandle == NULL || eid == NULL || ip == NULL || num == NULL || reqHandle == NULL,
54 : hccp_err("[get][IpByEid]ctxHandle or eid or ip or num or reqHandle is NULL"),
55 : ConverReturnCode(RDMA_OP, -EINVAL));
56 :
57 3 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_EID_IP_QUERY_MAX_NUM,
58 : hccp_err("[get][IpByEid]num(%u) must greater than 0"
59 : " and less or equal to %d",
60 : *num, HCCP_EID_IP_QUERY_MAX_NUM),
61 : ConverReturnCode(RDMA_OP, -EINVAL));
62 :
63 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
64 :
65 2 : hccp_run_info("Input parameters: phy_id:%u, devIndex:0x%x num:%u", ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex,
66 : *num);
67 2 : ret = RaHdcGetIpByEidAsync(ctxHandleTmp, eid, ip, num, reqHandle);
68 2 : if (ret != 0) {
69 1 : hccp_err("[get][IpByEid]RaHdcGetIpByEidAsync failed, ret(%d) phyId(%u), devIndex(0x%x)", ret,
70 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
71 : }
72 :
73 2 : return ret;
74 : }
75 :
76 2 : HCCP_ATTRI_VISI_DEF int RaCtxLmemRegisterAsync(void *ctxHandle, struct MrRegInfoT *lmemInfo, void **lmemHandle,
77 : void **reqHandle)
78 : {
79 2 : struct RaLmemHandle *lmemHandleTmp = NULL;
80 2 : struct RaCtxHandle *ctxHandleTmp = NULL;
81 2 : int ret = 0;
82 :
83 2 : CHK_PRT_RETURN(ctxHandle == NULL || lmemInfo == NULL || lmemHandle == NULL || reqHandle == NULL,
84 : hccp_err("[init][ra_lmem]ctx_handle or lmem_info or lmem_handle or req_handle is NULL"),
85 : ConverReturnCode(RDMA_OP, -EINVAL));
86 :
87 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
88 2 : lmemHandleTmp = calloc(1, sizeof(struct RaLmemHandle));
89 2 : CHK_PRT_RETURN(lmemHandleTmp == NULL,
90 : hccp_err("[init][ra_lmem]calloc lmem_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)", errno,
91 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex),
92 : ConverReturnCode(RDMA_OP, -ENOMEM));
93 :
94 2 : ret = RaHdcCtxLmemRegisterAsync(ctxHandleTmp, lmemInfo, lmemHandleTmp, reqHandle);
95 2 : if (ret != 0) {
96 1 : hccp_err("[init][ra_lmem]register_async failed, ret(%d) phyId(%u), devIndex(%u)", ret, ctxHandleTmp->attr.phyId,
97 : ctxHandleTmp->devIndex);
98 1 : goto err;
99 : }
100 :
101 1 : *lmemHandle = (void *)lmemHandleTmp;
102 1 : return 0;
103 :
104 1 : err:
105 1 : free(lmemHandleTmp);
106 1 : lmemHandleTmp = NULL;
107 1 : return ConverReturnCode(RDMA_OP, ret);
108 : }
109 :
110 3 : HCCP_ATTRI_VISI_DEF int RaCtxLmemUnregisterAsync(void *ctxHandle, void *lmemHandle, void **reqHandle)
111 : {
112 3 : struct RaLmemHandle *lmemHandleTmp = NULL;
113 3 : struct RaCtxHandle *ctxHandleTmp = NULL;
114 : int ret;
115 :
116 3 : CHK_PRT_RETURN(ctxHandle == NULL || lmemHandle == NULL || reqHandle == NULL,
117 : hccp_err("[deinit][ra_lmem]ctx_handle or lmem_handle or req_handle is NULL"),
118 : ConverReturnCode(RDMA_OP, -EINVAL));
119 :
120 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
121 3 : lmemHandleTmp = (struct RaLmemHandle *)lmemHandle;
122 3 : ret = RaHdcCtxLmemUnregisterAsync(ctxHandleTmp, lmemHandleTmp, reqHandle);
123 3 : if (ret != 0) {
124 1 : hccp_err("[deinit][ra_lmem]unregister_async failed, ret(%d) phyId(%u), devIndex(%u)", ret,
125 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex);
126 : }
127 :
128 3 : free(lmemHandleTmp);
129 3 : lmemHandleTmp = NULL;
130 3 : return ConverReturnCode(RDMA_OP, ret);
131 : }
132 :
133 3 : HCCP_ATTRI_VISI_DEF int RaCtxQpCreateAsync(void *ctxHandle, struct QpCreateAttr *attr, struct QpCreateInfo *info,
134 : void **qpHandle, void **reqHandle)
135 : {
136 3 : struct RaCtxQpHandle *qpHandleTmp = NULL;
137 3 : struct RaCtxHandle *ctxHandleTmp = NULL;
138 : int ret;
139 :
140 3 : CHK_PRT_RETURN(ctxHandle == NULL || attr == NULL || info == NULL || qpHandle == NULL || reqHandle == NULL,
141 : hccp_err("[init][ra_qp]ctx_handle or attr or info or qp_handle or req_handle is NULL"),
142 : ConverReturnCode(RDMA_OP, -EINVAL));
143 :
144 3 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
145 3 : qpHandleTmp = calloc(1, sizeof(struct RaCtxQpHandle));
146 3 : CHK_PRT_RETURN(qpHandleTmp == NULL,
147 : hccp_err("[init][ra_qp]calloc qp_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)", errno,
148 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex),
149 : ConverReturnCode(RDMA_OP, -ENOMEM));
150 :
151 3 : ret = RaHdcCtxQpCreateAsync(ctxHandleTmp, attr, info, qpHandleTmp, reqHandle);
152 3 : if (ret != 0) {
153 1 : hccp_err("[init][ra_qp]create_async failed, ret(%d) phyId(%u), devIndex(%u)", ret, ctxHandleTmp->attr.phyId,
154 : ctxHandleTmp->devIndex);
155 1 : goto err;
156 : }
157 :
158 2 : *qpHandle = (void *)qpHandleTmp;
159 2 : return 0;
160 :
161 1 : err:
162 1 : free(qpHandleTmp);
163 1 : qpHandleTmp = NULL;
164 1 : return ConverReturnCode(RDMA_OP, ret);
165 : }
166 :
167 2 : HCCP_ATTRI_VISI_DEF int RaCtxQpDestroyAsync(void *qpHandle, void **reqHandle)
168 : {
169 2 : struct RaCtxQpHandle *qpHandleTmp = NULL;
170 : int ret;
171 :
172 2 : CHK_PRT_RETURN(qpHandle == NULL || reqHandle == NULL, hccp_err("[deinit][ra_qp]qp_handle or req_handle is NULL"),
173 : ConverReturnCode(RDMA_OP, -EINVAL));
174 :
175 2 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle;
176 2 : ret = RaHdcCtxQpDestroyAsync(qpHandleTmp, reqHandle);
177 2 : if (ret != 0) {
178 1 : hccp_err("[deinit][ra_qp]destroy_async failed, ret(%d) phyId(%u), devIndex(%u) qp_id(%u)", ret,
179 : qpHandleTmp->phyId, qpHandleTmp->devIndex, qpHandleTmp->id);
180 : }
181 :
182 2 : free(qpHandleTmp);
183 2 : qpHandleTmp = NULL;
184 2 : return ConverReturnCode(RDMA_OP, ret);
185 : }
186 :
187 2 : STATIC void RaFreeQpHandleBatch(void *qpHandle[], unsigned int num)
188 : {
189 : unsigned int i;
190 :
191 4 : for (i = 0; i < num; ++i) {
192 2 : if (qpHandle[i] != NULL) {
193 2 : free(qpHandle[i]);
194 2 : qpHandle[i] = NULL;
195 : }
196 : }
197 2 : }
198 :
199 8 : HCCP_ATTRI_VISI_DEF int RaCtxQpDestroyBatchAsync(void *ctxHandle, void *qpHandle[], unsigned int *num, void **reqHandle)
200 : {
201 8 : struct RaCtxHandle *ctxHandleTmp = NULL;
202 : int ret;
203 :
204 8 : CHK_PRT_RETURN(ctxHandle == NULL || qpHandle == NULL || reqHandle == NULL || num == NULL,
205 : hccp_err("[destroy_batch][ra_qp]ctx_handle or qp_handle or req_handle or num is NULL"),
206 : ConverReturnCode(RDMA_OP, -EINVAL));
207 4 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_MAX_QP_DESTROY_BATCH_NUM,
208 : hccp_err("[destroy_batch][ra_qp]num(%u) is out of range(0, %u]", *num, HCCP_MAX_QP_DESTROY_BATCH_NUM),
209 : ConverReturnCode(RDMA_OP, -EINVAL));
210 :
211 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
212 2 : ret = RaHdcCtxQpDestroyBatchAsync(ctxHandleTmp, qpHandle, num, reqHandle);
213 2 : if (ret != 0) {
214 1 : hccp_err("[destroy_batch][ra_qp]qp_destroy_batch_async failed, ret[%d] phyId[%u] num[%u] devIndex[%u]", ret,
215 : ctxHandleTmp->attr.phyId, *num, ctxHandleTmp->devIndex);
216 : }
217 :
218 2 : RaFreeQpHandleBatch(qpHandle, *num);
219 2 : return ConverReturnCode(RDMA_OP, ret);
220 : }
221 :
222 2 : HCCP_ATTRI_VISI_DEF int RaCtxQpImportAsync(void *ctxHandle, struct QpImportInfoT *info, void **remQpHandle,
223 : void **reqHandle)
224 : {
225 2 : struct RaCtxRemQpHandle *remQpHandleTmp = NULL;
226 2 : struct RaCtxHandle *ctxHandleTmp = NULL;
227 : int ret;
228 :
229 2 : CHK_PRT_RETURN(ctxHandle == NULL || info == NULL || remQpHandle == NULL || reqHandle == NULL,
230 : hccp_err("[init][ra_qp]ctx_handle or info or rem_qp_handle or req_handle is NULL"),
231 : ConverReturnCode(RDMA_OP, -EINVAL));
232 :
233 2 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
234 2 : remQpHandleTmp = calloc(1, sizeof(struct RaCtxRemQpHandle));
235 2 : CHK_PRT_RETURN(remQpHandleTmp == NULL,
236 : hccp_err("[init][ra_qp]calloc rem_qp_handle_tmp failed, errno(%d) phyId(%u) devIndex(%u)", errno,
237 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex),
238 : ConverReturnCode(RDMA_OP, -ENOMEM));
239 :
240 2 : ret = RaHdcCtxQpImportAsync(ctxHandleTmp, info, remQpHandleTmp, reqHandle);
241 2 : if (ret != 0) {
242 1 : hccp_err("[init][ra_qp]import_async failed, ret(%d) phyId(%u), devIndex(%u)", ret, ctxHandleTmp->attr.phyId,
243 : ctxHandleTmp->devIndex);
244 1 : goto err;
245 : }
246 :
247 1 : *remQpHandle = (void *)remQpHandleTmp;
248 1 : return 0;
249 :
250 1 : err:
251 1 : free(remQpHandleTmp);
252 1 : remQpHandleTmp = NULL;
253 1 : return ConverReturnCode(RDMA_OP, ret);
254 : }
255 :
256 2 : HCCP_ATTRI_VISI_DEF int RaCtxQpUnimportAsync(void *remQpHandle, void **reqHandle)
257 : {
258 2 : struct RaCtxRemQpHandle *remQpHandleTmp = NULL;
259 : int ret;
260 :
261 2 : CHK_PRT_RETURN(remQpHandle == NULL || reqHandle == NULL,
262 : hccp_err("[deinit][ra_qp]rem_qp_handle or req_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
263 :
264 2 : remQpHandleTmp = (struct RaCtxRemQpHandle *)remQpHandle;
265 2 : ret = RaHdcCtxQpUnimportAsync(remQpHandleTmp, reqHandle);
266 2 : if (ret != 0) {
267 1 : hccp_err("[deinit][ra_qp]unimport_async failed, ret(%d) phyId(%u) devIndex(%u) qp_id(%u)", ret,
268 : remQpHandleTmp->phyId, remQpHandleTmp->devIndex, remQpHandleTmp->id);
269 : }
270 :
271 2 : free(remQpHandleTmp);
272 2 : remQpHandleTmp = NULL;
273 2 : return ConverReturnCode(RDMA_OP, ret);
274 : }
275 :
276 8 : HCCP_ATTRI_VISI_DEF int RaGetTpInfoListAsync(void *ctxHandle, struct GetTpCfg *cfg, struct HccpTpInfo infoList[],
277 : unsigned int *num, void **reqHandle)
278 : {
279 8 : struct RaCtxHandle *ctxHandleTmp = NULL;
280 : int ret;
281 :
282 8 : CHK_PRT_RETURN(ctxHandle == NULL || cfg == NULL || reqHandle == NULL,
283 : hccp_err("[get][ra_tp_info]ctx_handle or cfg or req_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
284 5 : CHK_PRT_RETURN(infoList == NULL || num == NULL, hccp_err("[get][ra_tp_info]info_list or num is NULL"),
285 : ConverReturnCode(RDMA_OP, -EINVAL));
286 3 : CHK_PRT_RETURN(*num == 0 || *num > HCCP_MAX_TPID_INFO_NUM,
287 : hccp_err("[get][ra_tp_info]*num(%u) is out of range[0, %d]", *num, HCCP_MAX_TPID_INFO_NUM),
288 : ConverReturnCode(RDMA_OP, -EINVAL));
289 :
290 1 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
291 1 : ret = RaHdcGetTpInfoListAsync(ctxHandleTmp, cfg, infoList, num, reqHandle);
292 1 : CHK_PRT_RETURN(ret != 0,
293 : hccp_err("[get][ra_tp_info]get_tp_info_list_async failed, ret[%d] phyId[%u], devIndex"
294 : "[%u]",
295 : ret, ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex),
296 : ConverReturnCode(RDMA_OP, ret));
297 :
298 1 : return ConverReturnCode(RDMA_OP, ret);
299 : }
300 :
301 0 : HCCP_ATTRI_VISI_DEF int RaGetTpAttrAsync(void *ctxHandle, uint64_t tpHandle, uint32_t *attrBitmap, struct TpAttr *attr,
302 : void **reqHandle)
303 : {
304 0 : struct RaCtxHandle *ctxHandleTmp = NULL;
305 : int ret;
306 :
307 0 : CHK_PRT_RETURN(ctxHandle == NULL || attrBitmap == NULL || reqHandle == NULL || attr == NULL,
308 : hccp_err("[get][ra_tp_attr]ctx_handle or attr_bitmap or req_handle or attr is NULL"),
309 : ConverReturnCode(RDMA_OP, -EINVAL));
310 :
311 0 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
312 0 : ret = RaHdcGetTpAttrAsync(ctxHandleTmp, tpHandle, attrBitmap, attr, reqHandle);
313 0 : CHK_PRT_RETURN(ret != 0,
314 : hccp_err("[get][ra_tp_attr]get_tp_attr_async failed, ret[%d] phyId[%u] devIndex[0x%x]", ret,
315 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex),
316 : ConverReturnCode(RDMA_OP, ret));
317 :
318 0 : return ConverReturnCode(RDMA_OP, ret);
319 : }
320 :
321 0 : HCCP_ATTRI_VISI_DEF int RaSetTpAttrAsync(void *ctxHandle, uint64_t tpHandle, uint32_t attrBitmap, struct TpAttr *attr,
322 : void **reqHandle)
323 : {
324 0 : struct RaCtxHandle *ctxHandleTmp = NULL;
325 : int ret;
326 :
327 0 : CHK_PRT_RETURN(ctxHandle == NULL || attr == NULL || reqHandle == NULL,
328 : hccp_err("[set][ra_tp_attr]ctx_handle or attr or req_handle or attr is NULL"),
329 : ConverReturnCode(RDMA_OP, -EINVAL));
330 :
331 0 : ctxHandleTmp = (struct RaCtxHandle *)ctxHandle;
332 0 : ret = RaHdcSetTpAttrAsync(ctxHandleTmp, tpHandle, attrBitmap, attr, reqHandle);
333 0 : CHK_PRT_RETURN(ret != 0,
334 : hccp_err("[set][ra_tp_attr]set_tp_attr_async failed, ret[%d] phyId[%u] devIndex[0x%x]", ret,
335 : ctxHandleTmp->attr.phyId, ctxHandleTmp->devIndex),
336 : ConverReturnCode(RDMA_OP, ret));
337 :
338 0 : return ConverReturnCode(RDMA_OP, ret);
339 : }
|