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