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 <string.h>
13 : #include <arpa/inet.h>
14 : #include <unistd.h>
15 : #include <errno.h>
16 : #include "securec.h"
17 : #include "user_log.h"
18 : #include "hccp_ctx.h"
19 : #include "ra.h"
20 : #include "ra_ctx.h"
21 : #include "ra_ctx_comm.h"
22 : #include "ra_rs_err.h"
23 : #include "ra_hdc.h"
24 : #include "ra_hdc_ctx.h"
25 :
26 1 : int RaHdcGetDevEidInfoNum(struct RaInfo info, unsigned int *num)
27 : {
28 1 : union OpGetDevEidInfoNumData opData = {0};
29 : int ret;
30 :
31 1 : *num = 0;
32 1 : opData.txData.phyId = info.phyId;
33 1 : ret = RaHdcProcessMsg(RA_RS_GET_DEV_EID_INFO_NUM, info.phyId, (char *)&opData,
34 : sizeof(union OpGetDevEidInfoNumData));
35 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid]hdc message process failed ret[%d], phyId[%u]",
36 : ret, info.phyId), ret);
37 :
38 1 : *num = opData.rxData.num;
39 1 : return 0;
40 : }
41 :
42 2 : STATIC int RaHdcGetDevEidSubInfoList(unsigned int phyId, struct HccpDevEidInfo infoList[],
43 : unsigned int startIndex, unsigned int count)
44 : {
45 2 : union OpGetDevEidInfoListData opData = {0};
46 : int ret;
47 :
48 2 : opData.txData.phyId = phyId;
49 2 : opData.txData.startIndex = startIndex;
50 2 : opData.txData.count = count;
51 2 : ret = RaHdcProcessMsg(RA_RS_GET_DEV_EID_INFO_LIST, phyId, (char *)&opData,
52 : sizeof(union OpGetDevEidInfoListData));
53 2 : CHK_PRT_RETURN(ret, hccp_err("[get][eid]hdc message process failed ret[%d], phyId[%u]", ret, phyId), ret);
54 :
55 2 : (void)memcpy_s(infoList, sizeof(struct HccpDevEidInfo) * MAX_DEV_INFO_TRANS_NUM,
56 : opData.rxData.infoList, sizeof(struct HccpDevEidInfo) * MAX_DEV_INFO_TRANS_NUM);
57 2 : return 0;
58 : }
59 :
60 1 : int RaHdcGetDevEidInfoList(unsigned int phyId, struct HccpDevEidInfo infoList[], unsigned int *num)
61 : {
62 1 : struct HccpDevEidInfo subInfoList[MAX_DEV_INFO_TRANS_NUM] = {0};
63 1 : unsigned int infoSize = *num;
64 1 : unsigned int remainCount = 0;
65 1 : unsigned int startIndex = 0;
66 1 : int ret = 0;
67 :
68 1 : *num = 0;
69 : // get MAX_DEV_INFO_TRANS_NUM num of eid info every time: will fallthrough here
70 2 : for (startIndex = 0; startIndex + MAX_DEV_INFO_TRANS_NUM <= infoSize; startIndex += MAX_DEV_INFO_TRANS_NUM) {
71 1 : ret = RaHdcGetDevEidSubInfoList(phyId, subInfoList, startIndex, MAX_DEV_INFO_TRANS_NUM);
72 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid]get sub_info_list failed, ret(%d) phyId(%u) "
73 : "startIndex(%u) count(%d)", ret, phyId, startIndex, MAX_DEV_INFO_TRANS_NUM), ret);
74 :
75 1 : *num += MAX_DEV_INFO_TRANS_NUM;
76 1 : (void)memcpy_s(infoList + startIndex, sizeof(struct HccpDevEidInfo) * MAX_DEV_INFO_TRANS_NUM,
77 : subInfoList, sizeof(struct HccpDevEidInfo) * MAX_DEV_INFO_TRANS_NUM);
78 : }
79 :
80 1 : remainCount = infoSize % MAX_DEV_INFO_TRANS_NUM;
81 1 : if (remainCount == 0) {
82 0 : return ret;
83 : }
84 :
85 : // get remain count of eid info
86 1 : ret = RaHdcGetDevEidSubInfoList(phyId, subInfoList, startIndex, remainCount);
87 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid]get sub_info_list failed, ret(%d) phyId(%u) "
88 : "startIndex(%u) remainCount(%u)", ret, phyId, startIndex, remainCount), ret);
89 :
90 1 : *num += remainCount;
91 1 : (void)memcpy_s(infoList + startIndex, sizeof(struct HccpDevEidInfo) * remainCount,
92 : subInfoList, sizeof(struct HccpDevEidInfo) * remainCount);
93 1 : return ret;
94 : }
95 :
96 1 : int RaHdcCtxInit(struct RaCtxHandle *ctxHandle, struct CtxInitAttr *attr, unsigned int *devIndex,
97 : struct DevBaseAttr *devAttr)
98 : {
99 1 : unsigned int phyId = ctxHandle->attr.phyId;
100 1 : union OpCtxInitData opData = {0};
101 : int ret;
102 :
103 1 : (void)memcpy_s(&(opData.txData.attr), sizeof(struct CtxInitAttr), attr, sizeof(struct CtxInitAttr));
104 1 : ret = RaHdcProcessMsg(RA_RS_CTX_INIT, attr->phyId, (char *)&opData, sizeof(union OpCtxInitData));
105 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_hdc_ctx]hdc message process failed ret[%d], phyId[%u]",
106 : ret, phyId), ret);
107 :
108 1 : *devIndex = opData.rxData.devIndex;
109 1 : (void)memcpy_s(devAttr, sizeof(struct DevBaseAttr), &opData.rxData.devAttr, sizeof(struct DevBaseAttr));
110 :
111 1 : return 0;
112 : }
113 :
114 0 : int RaHdcCtxGetAsyncEvents(struct RaCtxHandle *ctxHandle, struct AsyncEvent events[], unsigned int *num)
115 : {
116 0 : union OpCtxGetAsyncEventsData opData = {0};
117 0 : unsigned int phyId = ctxHandle->attr.phyId;
118 0 : unsigned int expectedNum = *num;
119 : unsigned int i;
120 0 : int ret = 0;
121 :
122 0 : opData.txData.phyId = phyId;
123 0 : opData.txData.devIndex = ctxHandle->devIndex;
124 0 : opData.txData.num = *num;
125 0 : ret = RaHdcProcessMsg(RA_RS_CTX_GET_ASYNC_EVENTS, phyId, (char *)&opData,
126 : sizeof(union OpCtxGetAsyncEventsData));
127 :
128 0 : CHK_PRT_RETURN(opData.rxData.num > expectedNum, hccp_err("[get][async_events]rxData.num:%u > expectedNum:%u,"
129 : " phyId:%u dev_index:0x%x", opData.rxData.num, expectedNum, phyId, ctxHandle->devIndex), -EINVAL);
130 :
131 0 : for (i = 0; i < opData.rxData.num; i++) {
132 0 : (void)memcpy_s(&events[i], sizeof(struct AsyncEvent), &opData.rxData.events[i], sizeof(struct AsyncEvent));
133 : }
134 0 : *num = opData.rxData.num;
135 :
136 0 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][async_events]hdc message process failed ret:%d, phyId:%u"
137 : " dev_index:0x%x", ret, phyId, ctxHandle->devIndex), ret);
138 :
139 0 : return ret;
140 : }
141 :
142 1 : int RaHdcCtxDeinit(struct RaCtxHandle *ctxHandle)
143 : {
144 1 : unsigned int phyId = ctxHandle->attr.phyId;
145 1 : union OpCtxDeinitData opData = {0};
146 : int ret;
147 :
148 1 : opData.txData.phyId = phyId;
149 1 : opData.txData.devIndex = ctxHandle->devIndex;
150 1 : ret = RaHdcProcessMsg(RA_RS_CTX_DEINIT, phyId, (char *)&opData, sizeof(union OpCtxDeinitData));
151 1 : CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_hdc_ctx]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
152 : ret, phyId, ctxHandle->devIndex), ret);
153 :
154 1 : return 0;
155 : }
156 :
157 4 : void RaHdcPrepareGetEidByIp(struct RaCtxHandle *ctxHandle, struct IpInfo ip[], unsigned int ipNum,
158 : union OpGetEidByIpData *opData)
159 : {
160 4 : unsigned int i = 0;
161 :
162 4 : opData->txData.phyId = ctxHandle->attr.phyId;
163 4 : opData->txData.devIndex = ctxHandle->devIndex;
164 4 : opData->txData.num = ipNum;
165 132 : for (i = 0; i < ipNum; i++) {
166 128 : (void)memcpy_s(&opData->txData.ip[i], sizeof(struct IpInfo), &ip[i], sizeof(struct IpInfo));
167 : }
168 4 : }
169 :
170 1 : int RaHdcGetEidResults(union OpGetEidByIpData *opData, unsigned int ipNum, union HccpEid eid[], unsigned int *num)
171 : {
172 1 : unsigned int i = 0;
173 :
174 1 : *num = 0;
175 1 : CHK_PRT_RETURN(opData->rxData.num > ipNum, hccp_err("[get][eid_by_ip]rx_data.num:%u > ip_num:%u",
176 : opData->rxData.num, ipNum), -EINVAL);
177 :
178 1 : *num = opData->rxData.num;
179 2 : for (i = 0; i < opData->rxData.num; i++) {
180 1 : (void)memcpy_s(&eid[i], sizeof(union HccpEid), &opData->rxData.eid[i], sizeof(union HccpEid));
181 : }
182 :
183 1 : return 0;
184 : }
185 :
186 2 : int RaHdcGetEidByIp(struct RaCtxHandle *ctxHandle, struct IpInfo ip[], union HccpEid eid[], unsigned int *num)
187 : {
188 2 : unsigned int phyId = ctxHandle->attr.phyId;
189 2 : union OpGetEidByIpData opData = {0};
190 2 : unsigned int ipNum = *num;
191 2 : int retTmp = 0;
192 2 : int ret = 0;
193 :
194 2 : RaHdcPrepareGetEidByIp(ctxHandle, ip, ipNum, &opData);
195 2 : ret = RaHdcProcessMsg(RA_RS_GET_EID_BY_IP, phyId, (char *)&opData, sizeof(union OpGetEidByIpData));
196 :
197 2 : retTmp = RaHdcGetEidResults(&opData, ipNum, eid, num);
198 2 : CHK_PRT_RETURN(retTmp != 0, hccp_err("[get][eid_by_ip]ra_hdc_get_eid_results failed ret[%d], phyId[%u]"
199 : " devIndex[0x%x]", retTmp, phyId, ctxHandle->devIndex), retTmp);
200 :
201 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][eid_by_ip]hdc message process failed ret[%d], phyId[%u]"
202 : " devIndex[0x%x]", ret, phyId, ctxHandle->devIndex), ret);
203 :
204 1 : return ret;
205 : }
206 :
207 4 : void RaHdcPrepareGetIpByEid(struct RaCtxHandle *ctxHandle, union HccpEid eid[], unsigned int eidNum,
208 : union OpGetIpByEidData *opData)
209 : {
210 4 : unsigned int i = 0;
211 :
212 4 : opData->txData.phyId = ctxHandle->attr.phyId;
213 4 : opData->txData.devIndex = ctxHandle->devIndex;
214 4 : opData->txData.num = eidNum;
215 132 : for (i = 0; i < eidNum; i++) {
216 128 : (void)memcpy_s(&opData->txData.eid[i], sizeof(union HccpEid), &eid[i], sizeof(union HccpEid));
217 : }
218 4 : }
219 :
220 1 : int RaHdcGetIpResults(union OpGetIpByEidData *opData, unsigned int eidNum, struct IpInfo ip[], unsigned int *num)
221 : {
222 1 : unsigned int i = 0;
223 :
224 1 : *num = 0;
225 1 : CHK_PRT_RETURN(opData->rxData.num > eidNum, hccp_err("[get][IpByEid]rxData.num:%u > eidNum:%u",
226 : opData->rxData.num, eidNum), -EINVAL);
227 :
228 1 : *num = opData->rxData.num;
229 2 : for (i = 0; i < opData->rxData.num; i++) {
230 1 : (void)memcpy_s(&ip[i], sizeof(struct IpInfo), &opData->rxData.ip[i], sizeof(struct IpInfo));
231 : }
232 :
233 1 : return 0;
234 : }
235 :
236 2 : int RaHdcGetIpByEid(struct RaCtxHandle *ctxHandle, union HccpEid eid[], struct IpInfo ip[], unsigned int *num)
237 : {
238 2 : unsigned int phyId = ctxHandle->attr.phyId;
239 2 : union OpGetIpByEidData opData = {0};
240 2 : unsigned int eidNum = *num;
241 2 : int retTmp = 0;
242 2 : int ret = 0;
243 :
244 2 : RaHdcPrepareGetIpByEid(ctxHandle, eid, eidNum, &opData);
245 2 : ret = RaHdcProcessMsg(RA_RS_GET_IP_BY_EID, phyId, (char *)&opData, sizeof(union OpGetIpByEidData));
246 :
247 2 : retTmp = RaHdcGetIpResults(&opData, eidNum, ip, num);
248 2 : CHK_PRT_RETURN(retTmp != 0, hccp_err("[get][IpByEid]RaHdcGetIpResults failed ret[%d], phyId[%u]"
249 : " devIndex[0x%x]", retTmp, phyId, ctxHandle->devIndex), retTmp);
250 :
251 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][IpByEid]hdc message process failed ret[%d], phyId[%u]"
252 : " devIndex[0x%x]", ret, phyId, ctxHandle->devIndex), ret);
253 :
254 1 : return ret;
255 : }
256 :
257 2 : int RaHdcCtxTokenIdAlloc(struct RaCtxHandle *ctxHandle, struct HccpTokenId *info,
258 : struct RaTokenIdHandle *tokenIdHandle)
259 : {
260 2 : unsigned int phyId = ctxHandle->attr.phyId;
261 2 : union OpTokenIdAllocData opData = {0};
262 : int ret;
263 :
264 2 : opData.txData.phyId = phyId;
265 2 : opData.txData.devIndex = ctxHandle->devIndex;
266 :
267 2 : ret = RaHdcProcessMsg(RA_RS_CTX_TOKEN_ID_ALLOC, phyId, (char *)&opData,
268 : sizeof(union OpTokenIdAllocData));
269 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_token_id]hdc message process failed ret[%d], phyId[%u] "
270 : "devIndex[%u]", ret, phyId, ctxHandle->devIndex), ret);
271 :
272 2 : info->tokenId = opData.rxData.tokenId;
273 2 : tokenIdHandle->addr = opData.rxData.addr;
274 2 : return 0;
275 : }
276 :
277 1 : int RaHdcCtxTokenIdFree(struct RaCtxHandle *ctxHandle, struct RaTokenIdHandle *tokenIdHandle)
278 : {
279 1 : unsigned int phyId = ctxHandle->attr.phyId;
280 1 : union OpTokenIdFreeData opData = {0};
281 : int ret;
282 :
283 1 : opData.txData.phyId = phyId;
284 1 : opData.txData.devIndex = ctxHandle->devIndex;
285 1 : opData.txData.addr = tokenIdHandle->addr;
286 1 : ret = RaHdcProcessMsg(RA_RS_CTX_TOKEN_ID_FREE, phyId, (char *)&opData,
287 : sizeof(union OpTokenIdFreeData));
288 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_token_id]hdc message process failed ret[%d], phyId[%u] "
289 : "devIndex[%u]", ret, phyId, ctxHandle->devIndex), ret);
290 :
291 1 : return 0;
292 : }
293 :
294 3 : int RaHdcCtxPrepareLmemRegister(struct RaCtxHandle *ctxHandle, struct MrRegInfoT *lmemInfo,
295 : union OpLmemRegInfoData *opData)
296 : {
297 3 : struct MemRegAttrT *memAttr = NULL;
298 3 : int ret = 0;
299 :
300 3 : memAttr = &(opData->txData.memAttr);
301 3 : opData->txData.phyId = ctxHandle->attr.phyId;
302 3 : opData->txData.devIndex = ctxHandle->devIndex;
303 3 : ret = RaCtxPrepareLmemRegister(lmemInfo, memAttr);
304 3 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_hdc_lmem]ra_ctx_prepare_lmem_register failed, ret[%d]", ret), ret);
305 :
306 3 : return 0;
307 : }
308 :
309 2 : int RaHdcCtxLmemRegister(struct RaCtxHandle *ctxHandle, struct MrRegInfoT *lmemInfo,
310 : struct RaLmemHandle *lmemHandle)
311 : {
312 2 : unsigned int phyId = ctxHandle->attr.phyId;
313 2 : union OpLmemRegInfoData opData = {0};
314 : int ret;
315 :
316 2 : ret = RaHdcCtxPrepareLmemRegister(ctxHandle, lmemInfo, &opData);
317 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_hdc_lmem]prepare register failed ret[%d], phyId[%u] devIndex[%u]",
318 : ret, phyId, ctxHandle->devIndex), ret);
319 :
320 2 : ret = RaHdcProcessMsg(RA_RS_LMEM_REG, phyId, (char *)&opData, sizeof(union OpLmemRegInfoData));
321 2 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_hdc_lmem]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
322 : ret, phyId, ctxHandle->devIndex), ret);
323 :
324 2 : RaCtxGetLmemInfo(&(opData.rxData.memInfo), lmemInfo, lmemHandle);
325 :
326 2 : return 0;
327 : }
328 :
329 1 : int RaHdcCtxLmemUnregister(struct RaCtxHandle *ctxHandle, struct RaLmemHandle *lmemHandle)
330 : {
331 1 : unsigned int phyId = ctxHandle->attr.phyId;
332 1 : union OpLmemUnregInfoData opData = {0};
333 : int ret;
334 :
335 1 : opData.txData.phyId = phyId;
336 1 : opData.txData.devIndex = ctxHandle->devIndex;
337 1 : opData.txData.addr = lmemHandle->addr;
338 1 : ret = RaHdcProcessMsg(RA_RS_LMEM_UNREG, phyId, (char *)&opData, sizeof(union OpLmemUnregInfoData));
339 1 : CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_hdc_lmem]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
340 : ret, phyId, ctxHandle->devIndex), ret);
341 :
342 1 : return 0;
343 : }
344 :
345 1 : STATIC void RaHdcPrepareRmemImport(struct RaCtxHandle *ctxHandle, union OpRmemImportInfoData *opData,
346 : struct MrImportInfoT *rmemInfo)
347 : {
348 1 : struct MemImportAttrT *memAttr = NULL;
349 :
350 1 : memAttr = &(opData->txData.memAttr);
351 1 : opData->txData.phyId = ctxHandle->attr.phyId;
352 1 : opData->txData.devIndex = ctxHandle->devIndex;
353 1 : RaCtxPrepareRmemImport(rmemInfo, memAttr);
354 1 : }
355 :
356 1 : int RaHdcCtxRmemImport(struct RaCtxHandle *ctxHandle, struct MrImportInfoT *rmemInfo)
357 : {
358 1 : unsigned int phyId = ctxHandle->attr.phyId;
359 1 : union OpRmemImportInfoData opData = {0};
360 : int ret;
361 :
362 1 : RaHdcPrepareRmemImport(ctxHandle, &opData, rmemInfo);
363 :
364 1 : ret = RaHdcProcessMsg(RA_RS_RMEM_IMPORT, phyId, (char *)&opData, sizeof(union OpRmemImportInfoData));
365 1 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_hdc_rmem]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
366 : ret, phyId, ctxHandle->devIndex), ret);
367 :
368 1 : rmemInfo->out.ub.targetSegHandle = opData.rxData.memInfo.ub.targetSegHandle;
369 1 : return 0;
370 : }
371 :
372 1 : int RaHdcCtxRmemUnimport(struct RaCtxHandle *ctxHandle, struct RaRmemHandle *rmemHandle)
373 : {
374 1 : union OpRmemUnimportInfoData opData = {0};
375 1 : unsigned int phyId = ctxHandle->attr.phyId;
376 : int ret;
377 :
378 1 : opData.txData.phyId = phyId;
379 1 : opData.txData.devIndex = ctxHandle->devIndex;
380 1 : opData.txData.addr = rmemHandle->addr;
381 1 : ret = RaHdcProcessMsg(RA_RS_RMEM_UNIMPORT, phyId, (char *)&opData, sizeof(union OpRmemUnimportInfoData));
382 1 : CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_hdc_rmem]hdc message process failed ret[%d], phyId[%u], devIndex[%u]",
383 : ret, phyId, ctxHandle->devIndex), ret);
384 :
385 1 : return 0;
386 : }
387 :
388 1 : int RaHdcCtxChanCreate(struct RaCtxHandle *ctxHandle, struct ChanInfoT *chanInfo,
389 : struct RaChanHandle *chanHandle)
390 : {
391 1 : unsigned int phyId = ctxHandle->attr.phyId;
392 1 : union OpCtxChanCreateData opData = {0};
393 : int ret;
394 :
395 1 : opData.txData.phyId = phyId;
396 1 : opData.txData.devIndex = ctxHandle->devIndex;
397 1 : opData.txData.dataPlaneFlag = chanInfo->in.dataPlaneFlag;
398 1 : ret = RaHdcProcessMsg(RA_RS_CTX_CHAN_CREATE, phyId, (char *)&opData, sizeof(union OpCtxChanCreateData));
399 1 : CHK_PRT_RETURN(ret, hccp_err("[init][ctx_chan]hdc message process failed ret[%d], phyId[%u], devIndex[%u]",
400 : ret, phyId, ctxHandle->devIndex), ret);
401 :
402 1 : chanHandle->addr = opData.rxData.addr;
403 1 : chanInfo->out.fd = opData.rxData.fd;
404 1 : return 0;
405 : }
406 :
407 1 : int RaHdcCtxChanDestroy(struct RaCtxHandle *ctxHandle, struct RaChanHandle *chanHandle)
408 : {
409 1 : unsigned int phyId = ctxHandle->attr.phyId;
410 1 : union OpCtxChanDestroyData opData = {0};
411 : int ret;
412 :
413 1 : opData.txData.phyId = phyId;
414 1 : opData.txData.devIndex = ctxHandle->devIndex;
415 1 : opData.txData.addr = chanHandle->addr;
416 :
417 1 : ret = RaHdcProcessMsg(RA_RS_CTX_CHAN_DESTROY, phyId, (char *)&opData, sizeof(union OpCtxChanDestroyData));
418 1 : CHK_PRT_RETURN(ret, hccp_err("[deinit][ctx_chan]hdc message process failed ret[%d], phyId[%u], devIndex[%u]",
419 : ret, phyId, ctxHandle->devIndex), ret);
420 :
421 1 : return 0;
422 : }
423 :
424 3 : STATIC void RaHdcPrepareCqCreate(struct RaCtxHandle *ctxHandle, union OpCtxCqCreateData *opData,
425 : struct CqInfoT *info)
426 : {
427 3 : struct CtxCqAttr *cqAttr = NULL;
428 :
429 3 : cqAttr = &(opData->txData.attr);
430 3 : opData->txData.phyId = ctxHandle->attr.phyId;
431 3 : opData->txData.devIndex = ctxHandle->devIndex;
432 3 : RaCtxPrepareCqCreate(info, cqAttr);
433 3 : if (opData->txData.attr.ub.mode == JFC_MODE_CCU_POLL && info->in.ub.ccuExCfg.valid) {
434 2 : opData->txData.attr.ub.ccuExCfg.valid = info->in.ub.ccuExCfg.valid;
435 2 : opData->txData.attr.ub.ccuExCfg.cqeFlag = info->in.ub.ccuExCfg.cqeFlag;
436 : }
437 3 : }
438 :
439 3 : int RaHdcCtxCqCreate(struct RaCtxHandle *ctxHandle, struct CqInfoT *info, struct RaCqHandle *cqHandle)
440 : {
441 3 : unsigned int phyId = ctxHandle->attr.phyId;
442 3 : union OpCtxCqCreateData opData = {0};
443 : int ret;
444 :
445 3 : RaHdcPrepareCqCreate(ctxHandle, &opData, info);
446 :
447 3 : ret = RaHdcProcessMsg(RA_RS_CTX_CQ_CREATE, phyId, (char *)&opData, sizeof(union OpCtxCqCreateData));
448 3 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_cq]hdc message process failed ret[%d], phyId[%u], devIndex[%u]",
449 : ret, phyId, ctxHandle->devIndex), ret);
450 :
451 3 : cqHandle->addr = opData.rxData.info.addr;
452 3 : RaCtxGetCqCreateInfo(&opData.rxData.info, info);
453 3 : return 0;
454 : }
455 :
456 2 : int RaHdcCtxCqDestroy(struct RaCtxHandle *ctxHandle, struct RaCqHandle *cqHandle)
457 : {
458 2 : unsigned int phyId = ctxHandle->attr.phyId;
459 2 : union OpCtxCqDestroyData opData = {0};
460 : int ret;
461 :
462 2 : opData.txData.phyId = phyId;
463 2 : opData.txData.devIndex = ctxHandle->devIndex;
464 2 : opData.txData.addr = cqHandle->addr;
465 2 : ret = RaHdcProcessMsg(RA_RS_CTX_CQ_DESTROY, phyId, (char *)&opData, sizeof(union OpCtxCqDestroyData));
466 2 : CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_cq]hdc message process failed ret[%d], phyId[%u], devIndex[%u]",
467 : ret, phyId, ctxHandle->devIndex), ret);
468 :
469 2 : return 0;
470 : }
471 :
472 5 : int RaHdcCtxPrepareQpCreate(struct RaCtxHandle *ctxHandle, struct QpCreateAttr *qpAttr,
473 : union OpCtxQpCreateData *opData)
474 : {
475 5 : struct CtxQpAttr *ctxQpAttr = NULL;
476 5 : int ret = 0;
477 :
478 5 : opData->txData.phyId = ctxHandle->attr.phyId;
479 5 : opData->txData.devIndex = ctxHandle->devIndex;
480 5 : ctxQpAttr = &opData->txData.qpAttr;
481 5 : ret = RaCtxPrepareQpCreate(qpAttr, ctxQpAttr);
482 5 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_hdc_qp]ra_ctx_prepare_qp_create failed, ret[%d]", ret), ret);
483 :
484 5 : if (ctxQpAttr->ub.mode == JETTY_MODE_CCU_TA_CACHE) {
485 2 : ctxQpAttr->ub.taCacheMode.lockFlag = qpAttr->ub.taCacheMode.lockFlag;
486 2 : ctxQpAttr->ub.taCacheMode.sqeBufIdx = qpAttr->ub.taCacheMode.sqeBufIdx;
487 : } else {
488 3 : ctxQpAttr->ub.extMode.sq = qpAttr->ub.extMode.sq;
489 3 : ctxQpAttr->ub.extMode.piType = qpAttr->ub.extMode.piType;
490 3 : ctxQpAttr->ub.extMode.cstmFlag = qpAttr->ub.extMode.cstmFlag;
491 3 : ctxQpAttr->ub.extMode.sqebbNum = qpAttr->ub.extMode.sqebbNum;
492 : }
493 :
494 5 : return 0;
495 : }
496 :
497 3 : int RaHdcCtxQpCreate(struct RaCtxHandle *ctxHandle, struct QpCreateAttr *qpAttr,
498 : struct QpCreateInfo *qpInfo, struct RaCtxQpHandle *qpHandle)
499 : {
500 3 : unsigned int devIndex = ctxHandle->devIndex;
501 3 : unsigned int phyId = ctxHandle->attr.phyId;
502 3 : union OpCtxQpCreateData opData = {0};
503 : int ret;
504 :
505 3 : ret = RaHdcCtxPrepareQpCreate(ctxHandle, qpAttr, &opData);
506 3 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_hdc_qp]prepare qp_create failed ret[%d], phyId[%u] devIndex[%u]",
507 : ret, phyId, devIndex), ret);
508 :
509 3 : ret = RaHdcProcessMsg(RA_RS_CTX_QP_CREATE, phyId, (char *)&opData, sizeof(union OpCtxQpCreateData));
510 3 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_hdc_qp]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
511 : ret, phyId, devIndex), ret);
512 :
513 3 : RaCtxGetQpCreateInfo(ctxHandle, qpAttr, &(opData.rxData.qpInfo), qpHandle);
514 3 : (void)memcpy_s(qpInfo, sizeof(struct QpCreateInfo), &(opData.rxData.qpInfo), sizeof(struct QpCreateInfo));
515 :
516 3 : return 0;
517 : }
518 :
519 2 : int RaHdcCtxQpDestroy(struct RaCtxQpHandle *qpHandle)
520 : {
521 2 : unsigned int phyId = qpHandle->phyId;
522 2 : union OpCtxQpDestroyData opData = {0};
523 : int ret;
524 :
525 2 : opData.txData.phyId = phyId;
526 2 : opData.txData.devIndex = qpHandle->devIndex;
527 2 : opData.txData.id = qpHandle->id;
528 :
529 2 : ret = RaHdcProcessMsg(RA_RS_CTX_QP_DESTROY, phyId, (char *)&opData, sizeof(union OpCtxQpDestroyData));
530 2 : CHK_PRT_RETURN(ret == -ENODEV, hccp_warn("[deinit][ra_hdc_qp]hdc message process ret[%d], phyId[%u] devIndex[%u]",
531 : ret, phyId, qpHandle->devIndex), ret);
532 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_hdc_qp]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
533 : ret, phyId, qpHandle->devIndex), ret);
534 2 : return 0;
535 : }
536 :
537 2 : int RaHdcCtxPrepareQpImport(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo,
538 : union OpCtxQpImportData *opData)
539 : {
540 2 : struct RaRsJettyImportAttr *importAttr = NULL;
541 :
542 2 : importAttr = &(opData->txData.attr);
543 2 : opData->txData.devIndex = ctxHandle->devIndex;
544 2 : opData->txData.phyId = ctxHandle->attr.phyId;
545 2 : opData->txData.key = qpInfo->in.key;
546 2 : RaCtxPrepareQpImport(qpInfo, importAttr);
547 :
548 2 : return 0;
549 : }
550 :
551 1 : int RaHdcCtxQpImport(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo,
552 : struct RaCtxRemQpHandle *remQpHandle)
553 : {
554 1 : unsigned int devIndex = ctxHandle->devIndex;
555 1 : unsigned int phyId = ctxHandle->attr.phyId;
556 1 : union OpCtxQpImportData opData = {0};
557 : int ret;
558 :
559 1 : ret = RaHdcCtxPrepareQpImport(ctxHandle, qpInfo, &opData);
560 1 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_hdc_qp]prepare qp_import failed ret[%d], phyId[%u] devIndex[%u]",
561 : ret, phyId, devIndex), ret);
562 :
563 1 : ret = RaHdcProcessMsg(RA_RS_CTX_QP_IMPORT, phyId, (char *)&opData, sizeof(union OpCtxQpImportData));
564 1 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_hdc_qp]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
565 : ret, phyId, devIndex), ret);
566 :
567 1 : RaCtxGetQpImportInfo(ctxHandle, qpInfo, &(opData.rxData.info), remQpHandle);
568 1 : remQpHandle->id = opData.rxData.remJettyId;
569 :
570 1 : return 0;
571 : }
572 :
573 1 : int RaHdcCtxQpUnimport(struct RaCtxRemQpHandle *remQpHandle)
574 : {
575 1 : unsigned int phyId = remQpHandle->phyId;
576 1 : union OpCtxQpUnimportData opData = {0};
577 : int ret;
578 :
579 1 : opData.txData.phyId = phyId;
580 1 : opData.txData.devIndex = remQpHandle->devIndex;
581 1 : (void)memcpy_s(opData.txData.rawRemJettyId, REM_JETTY_ID_SIZE, remQpHandle->qpKey.value, REM_JETTY_ID_SIZE);
582 1 : ret = RaHdcProcessMsg(RA_RS_CTX_QP_UNIMPORT, phyId, (char *)&opData, sizeof(union OpCtxQpUnimportData));
583 1 : CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_qp]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
584 : ret, phyId, remQpHandle->devIndex), ret);
585 :
586 1 : return 0;
587 : }
588 :
589 1 : int RaHdcCtxQpBind(struct RaCtxQpHandle *qpHandle, struct RaCtxRemQpHandle *remQpHandle)
590 : {
591 1 : unsigned int devIndex = qpHandle->devIndex;
592 1 : unsigned int phyId = qpHandle->phyId;
593 1 : union OpCtxQpBindData opData = {0};
594 : int ret;
595 :
596 1 : opData.txData.phyId = qpHandle->phyId;
597 1 : opData.txData.devIndex = qpHandle->devIndex;
598 1 : opData.txData.id = qpHandle->id;
599 1 : opData.txData.remId = remQpHandle->id;
600 :
601 1 : ret = RaHdcProcessMsg(RA_RS_CTX_QP_BIND, phyId, (char *)&opData, sizeof(union OpCtxQpBindData));
602 1 : CHK_PRT_RETURN(ret, hccp_err("[init][ra_hdc_qp]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
603 : ret, phyId, devIndex), ret);
604 :
605 1 : return 0;
606 : }
607 :
608 2 : int RaHdcCtxQpUnbind(struct RaCtxQpHandle *qpHandle)
609 : {
610 2 : union OpCtxQpUnbindData opData = {0};
611 2 : unsigned int phyId = qpHandle->phyId;
612 : int ret;
613 :
614 2 : opData.txData.phyId = phyId;
615 2 : opData.txData.devIndex = qpHandle->devIndex;
616 2 : opData.txData.id = qpHandle->id;
617 :
618 2 : ret = RaHdcProcessMsg(RA_RS_CTX_QP_UNBIND, phyId, (char *)&opData, sizeof(union OpCtxQpUnbindData));
619 2 : CHK_PRT_RETURN(ret == -ENODEV, hccp_warn("[deinit][ra_qp]hdc message process ret[%d], phyId[%u] devIndex[%u]",
620 : ret, phyId, qpHandle->devIndex), ret);
621 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_qp]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
622 : ret, phyId, qpHandle->devIndex), ret);
623 1 : return 0;
624 : }
625 :
626 2 : STATIC int RaHdcSendWrDataProtocolInit(struct SendWrData *wr, struct BatchSendWrData *wrData,
627 : enum ProtocolTypeT protocol, bool *isInline)
628 : {
629 2 : struct RaCtxRemQpHandle *remQpHandle = NULL;
630 2 : struct RaRmemHandle *rmemHandle = NULL;
631 : int ret;
632 :
633 2 : if (protocol == PROTOCOL_UDMA) {
634 1 : *isInline = (wr->ub.flags.bs.inlineFlag != 0);
635 1 : wrData->ub.userCtx = wr->ub.userCtx;
636 1 : wrData->ub.opcode = wr->ub.opcode;
637 1 : wrData->ub.flags = wr->ub.flags;
638 : /* nop no need to init other infos */
639 1 : if (wr->ub.opcode == RA_UB_OPC_NOP) {
640 0 : return 0;
641 : }
642 1 : remQpHandle = (struct RaCtxRemQpHandle *)wr->ub.remQpHandle;
643 1 : wrData->ub.remJetty = remQpHandle->id;
644 : /* notify */
645 1 : if (wr->ub.opcode == RA_UB_OPC_WRITE_NOTIFY) {
646 0 : wrData->ub.notifyInfo.notifyAddr = wr->ub.notifyInfo.notifyAddr;
647 0 : wrData->ub.notifyInfo.notifyData = wr->ub.notifyInfo.notifyData;
648 0 : rmemHandle = (struct RaRmemHandle *)(wr->ub.notifyInfo.notifyHandle);
649 0 : wrData->ub.notifyInfo.notifyHandle = rmemHandle->addr;
650 : }
651 : } else {
652 1 : *isInline = ((wr->rdma.flags & RA_SEND_INLINE) != 0);
653 1 : ret = memcpy_s(&wrData->rdma, sizeof(wrData->rdma),
654 1 : &(wr->rdma), sizeof(wr->rdma));
655 1 : CHK_PRT_RETURN(ret, hccp_err("[send][ra_hdc_ctx]memcpy_s protocol failed, ret[%d]", ret),
656 : -ESAFEFUNC);
657 : }
658 :
659 2 : return 0;
660 : }
661 :
662 2 : STATIC int RaHdcSendWrDataInit(struct RaCtxQpHandle *qpHandle, struct SendWrData wrList[],
663 : union OpCtxBatchSendWrData *opData, unsigned int completeCnt, unsigned int sendNum)
664 : {
665 2 : unsigned int currBatchNum = (sendNum - completeCnt) >= MAX_CTX_WR_NUM ?
666 : MAX_CTX_WR_NUM : (sendNum - completeCnt);
667 2 : struct RaLmemHandle *lmemHandle = NULL;
668 2 : struct RaRmemHandle *rmemHandle = NULL;
669 2 : struct BatchSendWrData *hdcWr = NULL;
670 2 : struct SendWrData *wr = NULL;
671 : unsigned int i, j;
672 : bool isInline;
673 : int ret;
674 :
675 2 : (void)memset_s(opData, sizeof(union OpCtxBatchSendWrData), 0, sizeof(union OpCtxBatchSendWrData));
676 2 : opData->txData.baseInfo.phyId = qpHandle->phyId;
677 2 : opData->txData.baseInfo.devIndex = qpHandle->devIndex;
678 2 : opData->txData.baseInfo.qpn = qpHandle->id;
679 2 : opData->txData.sendNum = currBatchNum;
680 :
681 4 : for (i = 0; i < currBatchNum; i++) {
682 2 : wr = &wrList[completeCnt + i];
683 2 : hdcWr = &opData->txData.wrData[i];
684 : /* protocol cfg */
685 2 : ret = RaHdcSendWrDataProtocolInit(wr, hdcWr, qpHandle->protocol, &isInline);
686 2 : if (ret != 0) {
687 0 : hccp_err("[send][ra_hdc_ctx]init protocol cfg failed, ret[%d], wr[%u]",
688 : ret, (completeCnt + i));
689 0 : return ret;
690 : }
691 :
692 : /* nop no need init other infos */
693 2 : if (qpHandle->protocol == PROTOCOL_UDMA && wr->ub.opcode == RA_UB_OPC_NOP) {
694 0 : continue;
695 : }
696 :
697 : /* lmem */
698 2 : if (isInline) {
699 2 : ret = memcpy_s(hdcWr->inlineData, MAX_INLINE_SIZE, wr->inlineData, wr->inlineSize);
700 2 : CHK_PRT_RETURN(ret, hccp_err("[send][ra_hdc_ctx]memcpy_s inline data failed, ret[%d]",
701 : ret), -ESAFEFUNC);
702 2 : hdcWr->inlineSize = wr->inlineSize;
703 : } else {
704 0 : for (j = 0; j < wr->numSge; j++) {
705 0 : hdcWr->sges[j].addr = wr->sges[j].addr;
706 0 : hdcWr->sges[j].len = wr->sges[j].len;
707 0 : lmemHandle = (struct RaLmemHandle *)wr->sges[j].lmemHandle;
708 0 : hdcWr->sges[j].devLmemHandle = lmemHandle->addr;
709 : }
710 0 : hdcWr->numSge = wr->numSge;
711 : }
712 :
713 : /* rmem */
714 2 : hdcWr->remoteAddr = wr->remoteAddr;
715 2 : rmemHandle = (struct RaRmemHandle *)(wr->rmemHandle);
716 2 : hdcWr->devRmemHandle = rmemHandle->addr;
717 :
718 : /* inline reduce */
719 2 : hdcWr->ub.reduceInfo = wr->ub.reduceInfo;
720 :
721 : /* imm data */
722 2 : hdcWr->immData = wr->immData;
723 : }
724 :
725 2 : return 0;
726 : }
727 :
728 2 : int RaHdcCtxBatchSendWr(struct RaCtxQpHandle *qpHandle, struct SendWrData wrList[],
729 : struct SendWrResp opResp[], unsigned int sendNum, unsigned int *completeNum)
730 : {
731 2 : union OpCtxBatchSendWrData opData = {0};
732 2 : unsigned int completeCnt = 0;
733 : unsigned int currSendNum;
734 2 : bool isFinished = false;
735 2 : int ret = 0;
736 :
737 2 : while (completeCnt < sendNum) {
738 2 : ret = RaHdcSendWrDataInit(qpHandle, wrList, &opData, completeCnt, sendNum);
739 2 : if (ret != 0) {
740 0 : hccp_err("[send][ra_hdc_ctx]ra_hdc_send_wr_data_init failed, ret[%d] phyId[%u] devIndex[%u] qp_id[%u]",
741 : ret, qpHandle->phyId, qpHandle->devIndex, qpHandle->id);
742 0 : break;
743 : }
744 :
745 2 : currSendNum = opData.txData.sendNum;
746 2 : ret = RaHdcProcessMsg(RA_RS_CTX_BATCH_SEND_WR, qpHandle->phyId, (char *)&opData,
747 : sizeof(union OpCtxBatchSendWrData));
748 :
749 2 : if (opData.rxData.completeNum > currSendNum) {
750 0 : hccp_err("[send][ra_hdc_ctx]complete_num[%u] is larger than send_num[%u], ret[%d]",
751 : opData.rxData.completeNum, currSendNum, ret);
752 0 : ret = -EINVAL;
753 0 : break;
754 : }
755 2 : if (ret != 0 || opData.rxData.completeNum < currSendNum) {
756 2 : hccp_err("[send][ra_hdc_ctx]batch send wr failed, ret[%d], sendNum[%u], completeNum[%u]",
757 : ret, currSendNum, opData.rxData.completeNum);
758 2 : ret = -EOPENSRC;
759 2 : isFinished = true;
760 : }
761 :
762 2 : ret = memcpy_s(&opResp[completeCnt], (sizeof(struct SendWrResp) * (sendNum - completeCnt)),
763 2 : opData.rxData.wrResp, (sizeof(struct SendWrResp) * opData.rxData.completeNum));
764 2 : if (ret != 0) {
765 0 : hccp_err("[send][ra_hdc_ctx]memcpy_s wr_resp failed, ret[%d]", ret);
766 0 : break;
767 : }
768 :
769 2 : completeCnt = completeCnt + opData.rxData.completeNum;
770 2 : if (isFinished) {
771 2 : break;
772 : }
773 : }
774 :
775 2 : *completeNum = completeCnt;
776 2 : return ret;
777 : }
778 :
779 1 : int RaHdcCtxUpdateCi(struct RaCtxQpHandle *qpHandle, uint16_t ci)
780 : {
781 1 : unsigned int phyId = qpHandle->phyId;
782 1 : union OpCtxUpdateCiData opData = {0};
783 : int ret;
784 :
785 1 : opData.txData.phyId = phyId;
786 1 : opData.txData.devIndex = qpHandle->devIndex;
787 1 : opData.txData.jettyId = qpHandle->id;
788 1 : opData.txData.ci = ci;
789 :
790 1 : ret = RaHdcProcessMsg(RA_RS_CTX_UPDATE_CI, phyId, (char *)&opData, sizeof(union OpCtxUpdateCiData));
791 1 : CHK_PRT_RETURN(ret, hccp_err("[update][ra_qp]hdc message process failed ret[%d], phyId[%u] devIndex[%u]",
792 : ret, phyId, qpHandle->devIndex), ret);
793 :
794 1 : return 0;
795 : }
796 :
797 3 : int RaHdcCtxQpQueryBatch(unsigned int phyId, unsigned int devIndex, unsigned int ids[],
798 : struct JettyAttr attr[], unsigned int *num)
799 : {
800 3 : union OpCtxQpQueryBatchData opData = {0};
801 : int ret, retTmp;
802 :
803 3 : opData.txData.phyId = phyId;
804 3 : opData.txData.devIndex = devIndex;
805 3 : opData.txData.num = *num;
806 3 : (void)memcpy_s(opData.txData.ids, sizeof(unsigned int) * (*num), ids, sizeof(unsigned int) * (*num));
807 3 : ret = RaHdcProcessMsg(RA_RS_CTX_QUERY_QP_BATCH, phyId, (char *)&opData,
808 : sizeof(union OpCtxQpQueryBatchData));
809 3 : CHK_PRT_RETURN(opData.rxData.num > *num, hccp_err("[query][ra_qp]op_data.rx_data.num[%u] is larger than num[%u], "
810 : "ret[%d]", opData.rxData.num, *num, ret), ret);
811 :
812 2 : if(ret != 0 || opData.rxData.num < *num) {
813 2 : hccp_err("[query][ra_qp]hdc message process failed ret[%d], phyId[%u], num[%u], opData.rxData.num[%u]",
814 : ret, phyId, *num, opData.rxData.num);
815 2 : ret = -EOPENSRC;
816 : }
817 :
818 2 : retTmp = memcpy_s(attr, sizeof(struct JettyAttr) * (*num), opData.rxData.attr,
819 2 : sizeof(struct JettyAttr) * opData.rxData.num);
820 2 : CHK_PRT_RETURN(retTmp != 0, hccp_err("[query][ra_qp]memcpy_s failed, ret[%d], phyId[%u], num[%u],"
821 : "opData.rxData.num[%u]", ret, phyId, *num, opData.rxData.num), ret);
822 :
823 2 : *num = opData.rxData.num;
824 2 : return ret;
825 : }
826 :
827 2 : int RaHdcCtxGetAuxInfo(struct RaCtxHandle *ctxHandle, struct HccpAuxInfoIn *in, struct HccpAuxInfoOut *out)
828 : {
829 2 : unsigned int phyId = ctxHandle->attr.phyId;
830 2 : union OpCtxGetAuxInfoData opData = {0};
831 2 : int ret = 0;
832 :
833 2 : opData.txData.phyId = phyId;
834 2 : opData.txData.devIndex = ctxHandle->devIndex;
835 2 : (void)memcpy_s(&(opData.txData.info), sizeof(struct HccpAuxInfoIn), in, sizeof(struct HccpAuxInfoIn));
836 2 : ret = RaHdcProcessMsg(RA_RS_CTX_GET_AUX_INFO, phyId, (char *)&opData,
837 : sizeof(union OpCtxGetAuxInfoData));
838 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][aux_info]hdc message process failed ret[%d], phyId[%u] "
839 : "devIndex[0x%x]", ret, phyId, ctxHandle->devIndex), ret);
840 :
841 1 : (void)memcpy_s(&(out->auxInfoType), sizeof(unsigned int) * AUX_INFO_NUM_MAX,
842 : &(opData.rxData.info.auxInfoType), sizeof(unsigned int) * AUX_INFO_NUM_MAX);
843 1 : (void)memcpy_s(&(out->auxInfoValue), sizeof(unsigned int) * AUX_INFO_NUM_MAX,
844 : &(opData.rxData.info.auxInfoValue), sizeof(unsigned int) * AUX_INFO_NUM_MAX);
845 1 : out->auxInfoNum = opData.rxData.info.auxInfoNum;
846 1 : return ret;
847 : }
848 :
849 2 : int RaHdcCtxGetCrErrInfoList(struct RaCtxHandle *ctxHandle, struct CrErrInfo *infoList, unsigned int *num)
850 : {
851 2 : union OpCtxGetCrErrInfoListData opData = {0};
852 2 : unsigned int phyId = ctxHandle->attr.phyId;
853 2 : unsigned int expectedNum = *num;
854 : unsigned int i;
855 2 : int ret = 0;
856 :
857 2 : opData.txData.phyId = phyId;
858 2 : opData.txData.devIndex = ctxHandle->devIndex;
859 2 : opData.txData.num = *num;
860 2 : ret = RaHdcProcessMsg(RA_RS_CTX_GET_CR_ERR_INFO_LIST, phyId, (char *)&opData,
861 : sizeof(union OpCtxGetCrErrInfoListData));
862 :
863 2 : if (opData.rxData.num > expectedNum) {
864 0 : hccp_err("[get][cr_err_info_list]rx_data.num(%u) > expected_num(%u), phyId(%u) devIndex(0x%x)",
865 : opData.rxData.num, expectedNum, phyId, ctxHandle->devIndex);
866 0 : return -EINVAL;
867 : }
868 :
869 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][cr_err_info_list]hdc message process failed ret[%d], phyId[%u]"
870 : " devIndex[0x%x]", ret, phyId, ctxHandle->devIndex), ret);
871 :
872 1 : for (i = 0; i < opData.rxData.num; i++) {
873 0 : (void)memcpy_s(&infoList[i], sizeof(struct CrErrInfo),
874 0 : &opData.rxData.infoList[i], sizeof(struct CrErrInfo));
875 : }
876 1 : *num = opData.rxData.num;
877 :
878 1 : return ret;
879 : }
880 :
881 3 : int RaHdcCtxGetJettyContext(struct RaCtxQpHandle *qpHandle, uint8_t context[], unsigned int *len)
882 : {
883 3 : union OpCtxGetContextData opData = {0};
884 3 : unsigned int phyId = qpHandle->phyId;
885 3 : int ret = 0;
886 :
887 3 : opData.txData.phyId = phyId;
888 3 : opData.txData.devIndex = qpHandle->devIndex;
889 3 : opData.txData.id = qpHandle->id;
890 3 : opData.txData.contextType = CONTEXT_TYPE_JETTY;
891 3 : opData.txData.len = *len;
892 3 : ret = RaHdcProcessMsg(RA_RS_CTX_GET_UB_CONTEXT, phyId, (char *)&opData,
893 : sizeof(union OpCtxGetContextData));
894 3 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][jettyContext]hdc message process failed ret:%d, phyId:%u"
895 : " devIndex:0x%x", ret, phyId, qpHandle->devIndex), ret);
896 :
897 2 : ret = memcpy_s(context, *len, opData.rxData.context, opData.rxData.len);
898 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[get][jettyContext]memcpy_s for context failed, ret:%d", ret), -ESAFEFUNC);
899 1 : *len = opData.rxData.len;
900 1 : return ret;
901 : }
|