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 "securec.h"
12 : #include "user_log.h"
13 : #include "ra_async.h"
14 : #include "ra_rs_comm.h"
15 : #include "ra_rs_err.h"
16 : #include "ra_rs_ctx.h"
17 : #include "ra_hdc_ctx.h"
18 : #include "ra_hdc_async.h"
19 : #include "ra_hdc_async_ctx.h"
20 :
21 4 : int RaHdcGetEidByIpAsync(struct RaCtxHandle *ctxHandle, struct IpInfo ip[], union HccpEid eid[], unsigned int *num,
22 : void **reqHandle)
23 : {
24 4 : struct RaRequestHandle *reqHandleTmp = NULL;
25 4 : unsigned int phyId = ctxHandle->attr.phyId;
26 4 : struct RaResponseEidList *asyncRsp = NULL;
27 4 : union OpGetEidByIpData asyncData = {0};
28 4 : int ret = 0;
29 :
30 4 : asyncRsp = (struct RaResponseEidList *)calloc(1, sizeof(struct RaResponseEidList));
31 4 : CHK_PRT_RETURN(asyncRsp == NULL,
32 : hccp_err("[get][eid_by_ip]calloc async_rsp failed, phyId[%u] devIndex[0x%x]", phyId, ctxHandle->devIndex),
33 : -ENOMEM);
34 2 : asyncRsp->eidList = eid;
35 2 : asyncRsp->num = num;
36 :
37 2 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
38 2 : if (reqHandleTmp == NULL) {
39 0 : hccp_err("[get][eid_by_ip]calloc req_handle_tmp failed, phyId[%u], devIndex[0x%x]", phyId, ctxHandle->devIndex);
40 0 : ret = -ENOMEM;
41 0 : goto out;
42 : }
43 :
44 2 : RaHdcPrepareGetEidByIp(ctxHandle, ip, *num, &asyncData);
45 2 : reqHandleTmp->devIndex = ctxHandle->devIndex;
46 2 : reqHandleTmp->privData = (void *)asyncRsp;
47 2 : ret = RaHdcSendMsgAsync(RA_RS_GET_EID_BY_IP, phyId, (char *)&asyncData, sizeof(union OpGetEidByIpData),
48 : reqHandleTmp);
49 2 : if (ret != 0) {
50 1 : hccp_err("[get][eid_by_ip]hdc async send message failed ret[%d], phyId[%u], devIndex[0x%x]", ret, phyId,
51 : ctxHandle->devIndex);
52 1 : free(reqHandleTmp);
53 1 : reqHandleTmp = NULL;
54 1 : goto out;
55 : }
56 :
57 1 : *reqHandle = (void *)reqHandleTmp;
58 1 : return ret;
59 :
60 1 : out:
61 1 : free(asyncRsp);
62 1 : asyncRsp = NULL;
63 1 : return ret;
64 : }
65 :
66 1 : void RaHdcAsyncHandleGetEidByIp(struct RaRequestHandle *reqHandle)
67 : {
68 1 : struct RaResponseEidList *asyncRsp = NULL;
69 1 : union OpGetEidByIpData *asyncData = NULL;
70 1 : unsigned int ipNum = 0;
71 1 : int ret = 0;
72 :
73 1 : asyncData = (union OpGetEidByIpData *)reqHandle->recvBuf;
74 1 : asyncRsp = (struct RaResponseEidList *)reqHandle->privData;
75 1 : ipNum = *asyncRsp->num;
76 :
77 1 : ret = RaHdcGetEidResults(asyncData, ipNum, asyncRsp->eidList, asyncRsp->num);
78 1 : if (ret != 0) {
79 0 : hccp_err("[get][eid_by_ip]ra_hdc_get_eid_results failed ret[%d], phyId[%u] devIndex[0x%x]", ret,
80 : reqHandle->phyId, reqHandle->devIndex);
81 0 : reqHandle->opRet = ret;
82 : }
83 :
84 1 : free(reqHandle->privData);
85 1 : reqHandle->privData = NULL;
86 1 : return;
87 : }
88 :
89 4 : int RaHdcGetIpByEidAsync(struct RaCtxHandle *ctxHandle, union HccpEid eid[], struct IpInfo ip[], unsigned int *num,
90 : void **reqHandle)
91 : {
92 4 : struct RaRequestHandle *reqHandleTmp = NULL;
93 4 : unsigned int phyId = ctxHandle->attr.phyId;
94 4 : struct RaResponseIpList *asyncRsp = NULL;
95 4 : union OpGetIpByEidData asyncData = {0};
96 4 : int ret = 0;
97 :
98 4 : asyncRsp = (struct RaResponseIpList *)calloc(1, sizeof(struct RaResponseIpList));
99 4 : CHK_PRT_RETURN(asyncRsp == NULL,
100 : hccp_err("[get][IpByEid]calloc asyncRsp failed, phyId[%u] devIndex[0x%x]", phyId, ctxHandle->devIndex),
101 : -ENOMEM);
102 2 : asyncRsp->ipList = ip;
103 2 : asyncRsp->num = num;
104 :
105 2 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
106 2 : if (reqHandleTmp == NULL) {
107 0 : hccp_err("[get][IpByEid]calloc reqHandleTmp failed, phyId[%u], devIndex[0x%x]", phyId, ctxHandle->devIndex);
108 0 : ret = -ENOMEM;
109 0 : goto free_async;
110 : }
111 :
112 2 : RaHdcPrepareGetIpByEid(ctxHandle, eid, *num, &asyncData);
113 2 : reqHandleTmp->devIndex = ctxHandle->devIndex;
114 2 : reqHandleTmp->privData = (void *)asyncRsp;
115 2 : ret = RaHdcSendMsgAsync(RA_RS_GET_IP_BY_EID, phyId, (char *)&asyncData, sizeof(union OpGetIpByEidData),
116 : reqHandleTmp);
117 2 : if (ret != 0) {
118 1 : hccp_err("[get][IpByEid]hdc async send message failed ret[%d], phyId[%u], devIndex[0x%x]", ret, phyId,
119 : ctxHandle->devIndex);
120 1 : free(reqHandleTmp);
121 1 : reqHandleTmp = NULL;
122 1 : goto free_async;
123 : }
124 :
125 1 : *reqHandle = (void *)reqHandleTmp;
126 1 : return ret;
127 :
128 1 : free_async:
129 1 : free(asyncRsp);
130 1 : asyncRsp = NULL;
131 1 : return ret;
132 : }
133 :
134 1 : void RaHdcAsyncHandleGetIpByEid(struct RaRequestHandle *reqHandle)
135 : {
136 1 : union OpGetIpByEidData *asyncData = NULL;
137 1 : struct RaResponseIpList *asyncRsp = NULL;
138 1 : unsigned int eidNum = 0;
139 1 : int ret = 0;
140 :
141 1 : asyncData = (union OpGetIpByEidData *)reqHandle->recvBuf;
142 1 : asyncRsp = (struct RaResponseIpList *)reqHandle->privData;
143 1 : eidNum = *asyncRsp->num;
144 :
145 1 : ret = RaHdcGetIpResults(asyncData, eidNum, asyncRsp->ipList, asyncRsp->num);
146 1 : if (ret != 0) {
147 0 : hccp_err("[get][IpByEid]RaHdcGetIpResults failed ret[%d], phyId[%u] devIndex[0x%x]", ret, reqHandle->phyId,
148 : reqHandle->devIndex);
149 0 : reqHandle->opRet = ret;
150 : }
151 :
152 1 : free(reqHandle->privData);
153 1 : reqHandle->privData = NULL;
154 1 : return;
155 : }
156 :
157 1 : int RaHdcCtxLmemRegisterAsync(struct RaCtxHandle *ctxHandle, struct MrRegInfoT *lmemInfo,
158 : struct RaLmemHandle *lmemHandle, void **reqHandle)
159 : {
160 1 : struct RaRequestHandle *reqHandleTmp = NULL;
161 1 : unsigned int phyId = ctxHandle->attr.phyId;
162 1 : union OpLmemRegInfoData asyncData = {0};
163 : int ret;
164 :
165 1 : ret = RaHdcCtxPrepareLmemRegister(ctxHandle, lmemInfo, &asyncData);
166 1 : CHK_PRT_RETURN(ret != 0,
167 : hccp_err("[init][ra_hdc_lmem]prepare register failed ret[%d], phyId[%u] devIndex[%u]", ret, phyId,
168 : ctxHandle->devIndex),
169 : ret);
170 :
171 1 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
172 1 : CHK_PRT_RETURN(reqHandleTmp == NULL,
173 : hccp_err("[init][ra_hdc_lmem]calloc req_handle_tmp failed, phyId[%u], devIndex[0x%x]", phyId,
174 : ctxHandle->devIndex),
175 : -ENOMEM);
176 :
177 1 : reqHandleTmp->devIndex = ctxHandle->devIndex;
178 1 : reqHandleTmp->privData = (void *)&lmemInfo->out;
179 1 : reqHandleTmp->privHandle = (void *)lmemHandle;
180 1 : ret = RaHdcSendMsgAsync(RA_RS_LMEM_REG, phyId, (char *)&asyncData, sizeof(union OpLmemRegInfoData), reqHandleTmp);
181 1 : if (ret != 0) {
182 0 : hccp_err("[init][ra_hdc_lmem]hdc async send message failed ret[%d], phyId[%u], devIndex[0x%x]", ret, phyId,
183 : ctxHandle->devIndex);
184 0 : free(reqHandleTmp);
185 0 : reqHandleTmp = NULL;
186 0 : return ret;
187 : }
188 :
189 1 : *reqHandle = (void *)reqHandleTmp;
190 1 : return 0;
191 : }
192 :
193 1 : void RaHdcAsyncHandleLmemRegister(struct RaRequestHandle *reqHandle)
194 : {
195 1 : union OpLmemRegInfoData *asyncData = NULL;
196 1 : struct RaLmemHandle *lmemHandle = NULL;
197 1 : struct MemRegInfo *info = NULL;
198 : int ret;
199 :
200 1 : asyncData = (union OpLmemRegInfoData *)reqHandle->recvBuf;
201 1 : lmemHandle = (struct RaLmemHandle *)reqHandle->privHandle;
202 1 : info = (struct MemRegInfo *)reqHandle->privData;
203 1 : ret = memcpy_s(info, sizeof(struct MemRegInfo), &asyncData->rxData.memInfo, sizeof(struct MemRegInfoT));
204 1 : if (ret != 0) {
205 1 : hccp_err("[init][ra_hdc_lmem]memcpy_s mem_info failed ret[%d], phyId[%u] devIndex[0x%x]", ret, reqHandle->phyId,
206 : reqHandle->devIndex);
207 1 : reqHandle->opRet = -ESAFEFUNC;
208 1 : return;
209 : }
210 :
211 0 : lmemHandle->addr = info->ub.targetSegHandle;
212 0 : return;
213 : }
214 :
215 2 : int RaHdcCtxLmemUnregisterAsync(struct RaCtxHandle *ctxHandle, struct RaLmemHandle *lmemHandle, void **reqHandle)
216 : {
217 2 : struct RaRequestHandle *reqHandleTmp = NULL;
218 2 : union OpLmemUnregInfoData asyncData = {0};
219 2 : unsigned int phyId = ctxHandle->attr.phyId;
220 2 : int ret = 0;
221 :
222 2 : asyncData.txData.phyId = phyId;
223 2 : asyncData.txData.devIndex = ctxHandle->devIndex;
224 2 : asyncData.txData.addr = lmemHandle->addr;
225 2 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
226 2 : CHK_PRT_RETURN(reqHandleTmp == NULL,
227 : hccp_err("[deinit][ra_hdc_lmem]calloc req_handle_tmp failed, phyId[%u], devIndex[0x%x]", phyId,
228 : ctxHandle->devIndex),
229 : -ENOMEM);
230 :
231 2 : ret = RaHdcSendMsgAsync(RA_RS_LMEM_UNREG, phyId, (char *)&asyncData, sizeof(union OpLmemUnregInfoData),
232 : reqHandleTmp);
233 2 : if (ret != 0) {
234 0 : hccp_err("[deinit][ra_hdc_lmem]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
235 : ctxHandle->devIndex);
236 0 : free(reqHandleTmp);
237 0 : reqHandleTmp = NULL;
238 0 : return ret;
239 : }
240 :
241 2 : *reqHandle = (void *)reqHandleTmp;
242 2 : return 0;
243 : }
244 :
245 2 : int RaHdcCtxQpCreateAsync(struct RaCtxHandle *ctxHandle, struct QpCreateAttr *attr, struct QpCreateInfo *info,
246 : struct RaCtxQpHandle *qpHandle, void **reqHandle)
247 : {
248 2 : struct RaRequestHandle *reqHandleTmp = NULL;
249 2 : unsigned int phyId = ctxHandle->attr.phyId;
250 2 : union OpCtxQpCreateData asyncData = {0};
251 : int ret;
252 :
253 2 : ret = RaHdcCtxPrepareQpCreate(ctxHandle, attr, &asyncData);
254 2 : CHK_PRT_RETURN(ret != 0,
255 : hccp_err("[init][ra_hdc_qp]prepare qp_create failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
256 : ctxHandle->devIndex),
257 : ret);
258 :
259 2 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
260 2 : CHK_PRT_RETURN(reqHandleTmp == NULL,
261 : hccp_err("[init][ra_hdc_qp]calloc req_handle_tmp failed, phyId[%u], devIndex[0x%x]", phyId,
262 : ctxHandle->devIndex),
263 : -ENOMEM);
264 2 : reqHandleTmp->devIndex = ctxHandle->devIndex;
265 2 : reqHandleTmp->privData = (void *)info;
266 2 : qpHandle->ctxHandle = ctxHandle;
267 2 : qpHandle->devIndex = ctxHandle->devIndex;
268 2 : qpHandle->phyId = ctxHandle->attr.phyId;
269 2 : qpHandle->protocol = ctxHandle->protocol;
270 2 : (void)memcpy_s(&qpHandle->qpAttr, sizeof(struct QpCreateAttr), attr, sizeof(struct QpCreateAttr));
271 2 : reqHandleTmp->privHandle = (void *)qpHandle;
272 :
273 2 : ret = RaHdcSendMsgAsync(RA_RS_CTX_QP_CREATE, phyId, (char *)&asyncData, sizeof(union OpCtxQpCreateData),
274 : reqHandleTmp);
275 2 : if (ret != 0) {
276 0 : hccp_err("[init][ra_hdc_qp]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
277 : ctxHandle->devIndex);
278 0 : free(reqHandleTmp);
279 0 : reqHandleTmp = NULL;
280 0 : return ret;
281 : }
282 :
283 2 : *reqHandle = (void *)reqHandleTmp;
284 2 : return 0;
285 : }
286 :
287 0 : void RaHdcAsyncHandleQpCreate(struct RaRequestHandle *reqHandle)
288 : {
289 0 : union OpCtxQpCreateData *asyncData = NULL;
290 0 : struct RaCtxQpHandle *qpHandle = NULL;
291 0 : struct QpCreateInfo *info = NULL;
292 :
293 0 : asyncData = (union OpCtxQpCreateData *)reqHandle->recvBuf;
294 0 : info = (struct QpCreateInfo *)reqHandle->privData;
295 0 : qpHandle = (struct RaCtxQpHandle *)reqHandle->privHandle;
296 0 : (void)memcpy_s(info, sizeof(struct QpCreateInfo), &asyncData->rxData.qpInfo, sizeof(struct QpCreateInfo));
297 0 : qpHandle->id = info->ub.id;
298 0 : (void)memcpy_s(&qpHandle->qpInfo, sizeof(struct QpCreateInfo), info, sizeof(struct QpCreateInfo));
299 :
300 0 : return;
301 : }
302 :
303 1 : int RaHdcCtxQpDestroyAsync(struct RaCtxQpHandle *qpHandle, void **reqHandle)
304 : {
305 1 : struct RaRequestHandle *reqHandleTmp = NULL;
306 1 : union OpCtxQpDestroyData asyncData = {0};
307 1 : unsigned int phyId = qpHandle->phyId;
308 : int ret;
309 :
310 1 : asyncData.txData.phyId = phyId;
311 1 : asyncData.txData.devIndex = qpHandle->devIndex;
312 1 : asyncData.txData.id = qpHandle->id;
313 :
314 1 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
315 1 : CHK_PRT_RETURN(reqHandleTmp == NULL,
316 : hccp_err("[deinit][ra_hdc_qp]calloc req_handle_tmp failed, phyId[%u], devIndex[0x%x]", phyId,
317 : qpHandle->devIndex),
318 : -ENOMEM);
319 :
320 1 : ret = RaHdcSendMsgAsync(RA_RS_CTX_QP_DESTROY, phyId, (char *)&asyncData, sizeof(union OpCtxQpDestroyData),
321 : reqHandleTmp);
322 1 : if (ret != 0) {
323 0 : hccp_err("[deinit][ra_hdc_qp]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
324 : qpHandle->devIndex);
325 0 : free(reqHandleTmp);
326 0 : reqHandleTmp = NULL;
327 0 : return ret;
328 : }
329 :
330 1 : *reqHandle = (void *)reqHandleTmp;
331 1 : return 0;
332 : }
333 :
334 1 : int RaHdcCtxQpImportAsync(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *info,
335 : struct RaCtxRemQpHandle *remQpHandle, void **reqHandle)
336 : {
337 1 : struct RaRequestHandle *reqHandleTmp = NULL;
338 1 : unsigned int phyId = ctxHandle->attr.phyId;
339 1 : union OpCtxQpImportData asyncData = {0};
340 1 : int ret = 0;
341 :
342 1 : ret = RaHdcCtxPrepareQpImport(ctxHandle, info, &asyncData);
343 1 : CHK_PRT_RETURN(ret != 0,
344 : hccp_err("[init][ra_hdc_qp]prepare qp_import failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
345 : ctxHandle->devIndex),
346 : ret);
347 :
348 1 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
349 1 : CHK_PRT_RETURN(reqHandleTmp == NULL,
350 : hccp_err("[init][ra_hdc_qp]calloc req_handle_tmp failed, phyId[%u], devIndex[0x%x]", phyId,
351 : ctxHandle->devIndex),
352 : -ENOMEM);
353 :
354 1 : reqHandleTmp->devIndex = ctxHandle->devIndex;
355 1 : reqHandleTmp->privData = (void *)&info->out;
356 1 : remQpHandle->devIndex = ctxHandle->devIndex;
357 1 : remQpHandle->phyId = ctxHandle->attr.phyId;
358 1 : remQpHandle->protocol = ctxHandle->protocol;
359 1 : remQpHandle->qpKey = info->in.key;
360 1 : reqHandleTmp->privHandle = (void *)remQpHandle;
361 :
362 1 : ret = RaHdcSendMsgAsync(RA_RS_CTX_QP_IMPORT, phyId, (char *)&asyncData, sizeof(union OpCtxQpImportData),
363 : reqHandleTmp);
364 1 : if (ret != 0) {
365 0 : hccp_err("[init][ra_hdc_qp]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
366 : ctxHandle->devIndex);
367 0 : free(reqHandleTmp);
368 0 : reqHandleTmp = NULL;
369 0 : return ret;
370 : }
371 :
372 1 : *reqHandle = (void *)reqHandleTmp;
373 1 : return 0;
374 : }
375 :
376 1 : void RaHdcAsyncHandleQpImport(struct RaRequestHandle *reqHandle)
377 : {
378 1 : struct RaCtxRemQpHandle *remQpHandle = NULL;
379 1 : union OpCtxQpImportData *asyncData = NULL;
380 1 : struct QpImportInfo *info = NULL;
381 :
382 1 : asyncData = (union OpCtxQpImportData *)reqHandle->recvBuf;
383 1 : info = (struct QpImportInfo *)reqHandle->privData;
384 1 : remQpHandle = (struct RaCtxRemQpHandle *)reqHandle->privHandle;
385 :
386 1 : info->ub.tjettyHandle = asyncData->rxData.info.tjettyHandle;
387 1 : info->ub.tpn = asyncData->rxData.info.tpn;
388 1 : remQpHandle->id = asyncData->rxData.remJettyId;
389 :
390 1 : return;
391 : }
392 :
393 1 : int RaHdcCtxQpUnimportAsync(struct RaCtxRemQpHandle *remQpHandle, void **reqHandle)
394 : {
395 1 : struct RaRequestHandle *reqHandleTmp = NULL;
396 1 : union OpCtxQpUnimportData asyncData = {0};
397 1 : unsigned int phyId = remQpHandle->phyId;
398 : int ret;
399 :
400 1 : asyncData.txData.phyId = phyId;
401 1 : asyncData.txData.devIndex = remQpHandle->devIndex;
402 1 : (void)memcpy_s(asyncData.txData.rawRemJettyId, REM_JETTY_ID_SIZE, remQpHandle->qpKey.value, REM_JETTY_ID_SIZE);
403 :
404 1 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
405 1 : CHK_PRT_RETURN(reqHandleTmp == NULL,
406 : hccp_err("[deinit][ra_hdc_qp]calloc req_handle_tmp failed, phyId[%u], devIndex[0x%x]", phyId,
407 : remQpHandle->devIndex),
408 : -ENOMEM);
409 :
410 1 : ret = RaHdcSendMsgAsync(RA_RS_CTX_QP_UNIMPORT, phyId, (char *)&asyncData, sizeof(union OpCtxQpUnimportData),
411 : reqHandleTmp);
412 1 : if (ret != 0) {
413 0 : hccp_err("[deinit][ra_hdc_qp]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
414 : remQpHandle->devIndex);
415 0 : free(reqHandleTmp);
416 0 : reqHandleTmp = NULL;
417 0 : return ret;
418 : }
419 :
420 1 : *reqHandle = (void *)reqHandleTmp;
421 1 : return 0;
422 : }
423 :
424 2 : int RaHdcGetTpInfoListAsync(struct RaCtxHandle *ctxHandle, struct GetTpCfg *cfg, struct HccpTpInfo infoList[],
425 : unsigned int *num, void **reqHandle)
426 : {
427 2 : struct RaResponseTpInfoList *asyncRsp = NULL;
428 2 : struct RaRequestHandle *reqHandleTmp = NULL;
429 2 : union OpGetTpInfoListData asyncData = {0};
430 2 : unsigned int phyId = ctxHandle->attr.phyId;
431 2 : int ret = 0;
432 :
433 2 : asyncRsp = (struct RaResponseTpInfoList *)calloc(1, sizeof(struct RaResponseTpInfoList));
434 2 : CHK_PRT_RETURN(asyncRsp == NULL,
435 : hccp_err("[get][ra_hdc_tp_info]calloc async_rsp failed, phyId[%u] devIndex[0x%x]", phyId, ctxHandle->devIndex),
436 : -ENOMEM);
437 2 : asyncRsp->infoList = infoList;
438 2 : asyncRsp->num = num;
439 :
440 2 : asyncData.txData.phyId = phyId;
441 2 : asyncData.txData.devIndex = ctxHandle->devIndex;
442 2 : asyncData.txData.num = *num;
443 2 : (void)memcpy_s(&asyncData.txData.cfg, sizeof(struct GetTpCfg), cfg, sizeof(struct GetTpCfg));
444 :
445 2 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
446 2 : if (reqHandleTmp == NULL) {
447 0 : hccp_err("[get][ra_hdc_tp_info]calloc RaRequestHandle failed, phyId[%u], devIndex[0x%x]", phyId,
448 : ctxHandle->devIndex);
449 0 : ret = -ENOMEM;
450 0 : goto out;
451 : }
452 :
453 2 : reqHandleTmp->devIndex = ctxHandle->devIndex;
454 2 : reqHandleTmp->privData = (void *)asyncRsp;
455 2 : ret = RaHdcSendMsgAsync(RA_RS_GET_TP_INFO_LIST, phyId, (char *)&asyncData, sizeof(union OpGetTpInfoListData),
456 : reqHandleTmp);
457 2 : if (ret != 0) {
458 1 : hccp_err("[get][ra_hdc_tp_info]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
459 : ctxHandle->devIndex);
460 1 : free(reqHandleTmp);
461 1 : reqHandleTmp = NULL;
462 1 : goto out;
463 : }
464 :
465 1 : *reqHandle = (void *)reqHandleTmp;
466 1 : return 0;
467 1 : out:
468 1 : free(asyncRsp);
469 1 : asyncRsp = NULL;
470 1 : return ret;
471 : }
472 :
473 4 : void RaHdcAsyncHandleTpInfoList(struct RaRequestHandle *reqHandle)
474 : {
475 4 : struct RaResponseTpInfoList *asyncRsp = NULL;
476 4 : union OpGetTpInfoListData *asyncData = NULL;
477 : int ret;
478 :
479 4 : if (reqHandle->opRet != 0) {
480 1 : goto out;
481 : }
482 3 : asyncData = (union OpGetTpInfoListData *)reqHandle->recvBuf;
483 3 : asyncRsp = (struct RaResponseTpInfoList *)reqHandle->privData;
484 3 : if (asyncData->rxData.num == 0) {
485 1 : *asyncRsp->num = asyncData->rxData.num;
486 1 : goto out;
487 : }
488 :
489 2 : ret = memcpy_s(asyncRsp->infoList, (*asyncRsp->num) * sizeof(struct HccpTpInfo), asyncData->rxData.infoList,
490 2 : asyncData->rxData.num * sizeof(struct HccpTpInfo));
491 2 : if (ret != 0) {
492 1 : hccp_err("[get][ra_hdc_tp_info]memcpy_s tp_info failed ret[%d] *async_rsp->num[%u] rx_data.num[%u], "
493 : "phyId[%u] devIndex[0x%x]",
494 : ret, *asyncRsp->num, asyncData->rxData.num, reqHandle->phyId, reqHandle->devIndex);
495 1 : reqHandle->opRet = -ESAFEFUNC;
496 1 : goto out;
497 : }
498 1 : *asyncRsp->num = asyncData->rxData.num;
499 4 : out:
500 4 : free(reqHandle->privData);
501 4 : reqHandle->privData = NULL;
502 4 : return;
503 : }
504 :
505 0 : int RaHdcGetTpAttrAsync(struct RaCtxHandle *ctxHandle, uint64_t tpHandle, uint32_t *attrBitmap, struct TpAttr *attr,
506 : void **reqHandle)
507 : {
508 0 : struct RaResponseGetTpAttr *asyncRsp = NULL;
509 0 : struct RaRequestHandle *reqHandleTmp = NULL;
510 0 : unsigned int phyId = ctxHandle->attr.phyId;
511 0 : union OpGetTpAttrData asyncData = {0};
512 0 : int ret = 0;
513 :
514 0 : asyncRsp = (struct RaResponseGetTpAttr *)calloc(1, sizeof(struct RaResponseGetTpAttr));
515 0 : CHK_PRT_RETURN(asyncRsp == NULL,
516 : hccp_err("[get][ra_hdc_tp_attr]calloc ra_response_get_tp_attr failed, phyId[%u] devIndex[0x%x]", phyId,
517 : ctxHandle->devIndex),
518 : -ENOMEM);
519 0 : asyncRsp->attr = attr;
520 0 : asyncRsp->attrBitmap = attrBitmap;
521 :
522 0 : asyncData.txData.devIndex = ctxHandle->devIndex;
523 0 : asyncData.txData.phyId = phyId;
524 0 : asyncData.txData.tpHandle = tpHandle;
525 0 : asyncData.txData.attrBitmap = *attrBitmap;
526 0 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
527 0 : if (reqHandleTmp == NULL) {
528 0 : hccp_err("[get][ra_hdc_tp_attr]calloc RaRequestHandle failed, phyId[%u] devIndex[0x%x]", phyId,
529 : ctxHandle->devIndex);
530 0 : ret = -ENOMEM;
531 0 : goto out;
532 : }
533 :
534 0 : reqHandleTmp->devIndex = ctxHandle->devIndex;
535 0 : reqHandleTmp->privData = (void *)asyncRsp;
536 0 : ret = RaHdcSendMsgAsync(RA_RS_GET_TP_ATTR, phyId, (char *)&asyncData, sizeof(union OpGetTpAttrData), reqHandleTmp);
537 0 : if (ret != 0) {
538 0 : hccp_err("[get][ra_hdc_tp_attr]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
539 : ctxHandle->devIndex);
540 0 : free(reqHandleTmp);
541 0 : reqHandleTmp = NULL;
542 0 : goto out;
543 : }
544 :
545 0 : *reqHandle = (void *)reqHandleTmp;
546 0 : return 0;
547 0 : out:
548 0 : free(asyncRsp);
549 0 : asyncRsp = NULL;
550 0 : return ret;
551 : }
552 :
553 0 : void RaHdcAsyncHandleGetTpAttr(struct RaRequestHandle *reqHandle)
554 : {
555 0 : struct RaResponseGetTpAttr *asyncRsp = NULL;
556 0 : union OpGetTpAttrData *asyncData = NULL;
557 :
558 0 : if (reqHandle->opRet != 0) {
559 0 : goto out;
560 : }
561 0 : asyncData = (union OpGetTpAttrData *)reqHandle->recvBuf;
562 0 : asyncRsp = (struct RaResponseGetTpAttr *)reqHandle->privData;
563 0 : *asyncRsp->attrBitmap = asyncData->rxData.attrBitmap;
564 0 : (void)memcpy_s(asyncRsp->attr, sizeof(struct TpAttr), &asyncData->rxData.attr, sizeof(struct TpAttr));
565 :
566 0 : out:
567 0 : free(reqHandle->privData);
568 0 : reqHandle->privData = NULL;
569 0 : return;
570 : }
571 :
572 0 : int RaHdcSetTpAttrAsync(struct RaCtxHandle *ctxHandle, uint64_t tpHandle, uint32_t attrBitmap, struct TpAttr *attr,
573 : void **reqHandle)
574 : {
575 0 : struct RaRequestHandle *reqHandleTmp = NULL;
576 0 : unsigned int phyId = ctxHandle->attr.phyId;
577 0 : union OpSetTpAttrData asyncData = {0};
578 0 : int ret = 0;
579 :
580 0 : asyncData.txData.devIndex = ctxHandle->devIndex;
581 0 : asyncData.txData.phyId = phyId;
582 0 : asyncData.txData.tpHandle = tpHandle;
583 0 : asyncData.txData.attrBitmap = attrBitmap;
584 0 : (void)memcpy_s(&asyncData.txData.attr, sizeof(struct TpAttr), attr, sizeof(struct TpAttr));
585 0 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
586 0 : CHK_PRT_RETURN(reqHandleTmp == NULL,
587 : hccp_err("[set][ra_hdc_tp_attr]calloc RaRequestHandle failed, phyId[%u] devIndex[0x%x]", phyId,
588 : ctxHandle->devIndex),
589 : -ENOMEM);
590 :
591 0 : reqHandleTmp->devIndex = ctxHandle->devIndex;
592 0 : ret = RaHdcSendMsgAsync(RA_RS_SET_TP_ATTR, phyId, (char *)&asyncData, sizeof(union OpSetTpAttrData), reqHandleTmp);
593 0 : if (ret != 0) {
594 0 : hccp_err("[set][ra_hdc_tp_attr]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret, phyId,
595 : ctxHandle->devIndex);
596 0 : free(reqHandleTmp);
597 0 : reqHandleTmp = NULL;
598 0 : return ret;
599 : }
600 :
601 0 : *reqHandle = (void *)reqHandleTmp;
602 0 : return 0;
603 : }
604 :
605 6 : STATIC int QpDestroyBatchParamCheck(struct RaCtxHandle *ctxHandle, void *qpHandle[], unsigned int ids[],
606 : unsigned int *num)
607 : {
608 6 : struct RaCtxQpHandle *qpHandleTmp = NULL;
609 : unsigned int i;
610 :
611 9 : for (i = 0; i < *num; ++i) {
612 6 : qpHandleTmp = (struct RaCtxQpHandle *)qpHandle[i];
613 6 : CHK_PRT_RETURN(qpHandleTmp == NULL, hccp_err("[destroy_batch][ra_hdc_ctx_qp]qp_handle[%u] is NULL", i),
614 : -EINVAL);
615 5 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle == NULL,
616 : hccp_err("[destroy_batch][ra_hdc_ctx_qp]ctx_handle[%u] is NULL", i), -EINVAL);
617 4 : CHK_PRT_RETURN(qpHandleTmp->ctxHandle != ctxHandle,
618 : hccp_err("[destroy_batch][ra_hdc_ctx_qp]qp_handle[%u]->ctx_handle is different from others", i), -EINVAL);
619 :
620 3 : ids[i] = qpHandleTmp->id;
621 : }
622 :
623 3 : return 0;
624 : }
625 :
626 4 : int RaHdcCtxQpDestroyBatchAsync(struct RaCtxHandle *ctxHandle, void *qpHandle[], unsigned int *num, void **reqHandle)
627 : {
628 4 : union OpCtxQpDestroyBatchData asyncData = {0};
629 4 : struct RaRequestHandle *reqHandleTmp = NULL;
630 4 : unsigned int phyId = ctxHandle->attr.phyId;
631 : int ret;
632 :
633 4 : ret = QpDestroyBatchParamCheck(ctxHandle, qpHandle, asyncData.txData.ids, num);
634 4 : CHK_PRT_RETURN(ret != 0,
635 : hccp_err("[destroy_batch][ra_hdc_ctx_qp]param check failed, phyId[%u] devIndex[0x%x]", phyId,
636 : ctxHandle->devIndex),
637 : ret);
638 :
639 3 : asyncData.txData.phyId = phyId;
640 3 : asyncData.txData.devIndex = ctxHandle->devIndex;
641 3 : asyncData.txData.num = *num;
642 :
643 3 : reqHandleTmp = (struct RaRequestHandle *)calloc(1, sizeof(struct RaRequestHandle));
644 3 : CHK_PRT_RETURN(reqHandleTmp == NULL,
645 : hccp_err("[destroy_batch][ra_hdc_ctx_qp]calloc RaRequestHandle failed, "
646 : "phyId[%u] devIndex[0x%x]",
647 : phyId, ctxHandle->devIndex),
648 : -ENOMEM);
649 :
650 2 : reqHandleTmp->devIndex = ctxHandle->devIndex;
651 2 : reqHandleTmp->privData = (void *)num;
652 2 : ret = RaHdcSendMsgAsync(RA_RS_CTX_QP_DESTROY_BATCH, phyId, (char *)&asyncData,
653 : sizeof(union OpCtxQpDestroyBatchData), reqHandleTmp);
654 2 : if (ret != 0) {
655 1 : hccp_err("[destroy_batch][ra_hdc_ctx_qp]hdc async send message failed ret[%d], phyId[%u] devIndex[0x%x]", ret,
656 : phyId, ctxHandle->devIndex);
657 1 : free(reqHandleTmp);
658 1 : reqHandleTmp = NULL;
659 1 : return ret;
660 : }
661 :
662 1 : *reqHandle = (void *)reqHandleTmp;
663 1 : return 0;
664 : }
665 :
666 1 : void RaHdcAsyncHandleQpDestroyBatch(struct RaRequestHandle *reqHandle)
667 : {
668 1 : union OpCtxQpDestroyBatchData *asyncData = NULL;
669 1 : unsigned int *num = NULL;
670 :
671 1 : asyncData = (union OpCtxQpDestroyBatchData *)reqHandle->recvBuf;
672 1 : num = (unsigned int *)reqHandle->privData;
673 1 : *num = asyncData->rxData.num;
674 :
675 1 : return;
676 : }
|