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 "ra_rs_ctx.h"
12 : #include "ra_peer.h"
13 : #include "rs_ctx.h"
14 : #include "ra_ctx_comm.h"
15 : #include "ra_peer_ctx.h"
16 :
17 2 : int RaPeerGetDevEidInfoNum(struct RaInfo info, unsigned int *num)
18 : {
19 2 : unsigned int phyId = info.phyId;
20 2 : int ret = 0;
21 :
22 2 : RaPeerMutexLock(phyId);
23 2 : RsSetCtx(phyId);
24 2 : ret = RsGetDevEidInfoNum(phyId, num);
25 2 : if (ret != 0) {
26 1 : hccp_err("[get][eid]rs_get_dev_eid_info_num failed ret[%d], phyId[%u]", ret, phyId);
27 : }
28 2 : RaPeerMutexUnlock(phyId);
29 2 : return ret;
30 : }
31 :
32 2 : int RaPeerGetDevEidInfoList(unsigned int phyId, struct HccpDevEidInfo infoList[], unsigned int *num)
33 : {
34 2 : unsigned int startIndex = 0;
35 2 : unsigned int count = *num;
36 2 : int ret = 0;
37 :
38 2 : RaPeerMutexLock(phyId);
39 2 : RsSetCtx(phyId);
40 2 : ret = RsGetDevEidInfoList(phyId, infoList, startIndex, count);
41 2 : if (ret != 0) {
42 1 : *num = 0;
43 1 : hccp_err("[get][eid]rs_get_dev_eid_info_list failed ret[%d], phyId[%u]", ret, phyId);
44 : } else {
45 1 : *num = count;
46 : }
47 2 : RaPeerMutexUnlock(phyId);
48 2 : return ret;
49 : }
50 :
51 2 : int RaPeerCtxInit(struct RaCtxHandle *ctxHandle, struct CtxInitAttr *attr, unsigned int *devIndex,
52 : struct DevBaseAttr *devBaseAttr)
53 : {
54 2 : unsigned int phyId = ctxHandle->attr.phyId;
55 2 : int ret = 0;
56 :
57 2 : RaPeerMutexLock(phyId);
58 2 : RsSetCtx(phyId);
59 2 : ret = RsCtxInit(attr, devIndex, devBaseAttr);
60 2 : if (ret != 0) {
61 1 : hccp_err("[init][ra_peer_ctx]ctx init failed, ret[%d] phy_id[%u]", ret, phyId);
62 : }
63 :
64 2 : RaPeerMutexUnlock(phyId);
65 2 : return ret;
66 : }
67 :
68 0 : int RaPeerCtxGetAsyncEvents(struct RaCtxHandle *ctxHandle, struct AsyncEvent events[], unsigned int *num)
69 : {
70 0 : unsigned int phyId = ctxHandle->attr.phyId;
71 0 : struct RaRsDevInfo devInfo = {0};
72 0 : int ret = 0;
73 :
74 0 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
75 :
76 0 : RaPeerMutexLock(phyId);
77 0 : RsSetCtx(phyId);
78 0 : ret = RsCtxGetAsyncEvents(&devInfo, events, num);
79 0 : RaPeerMutexUnlock(phyId);
80 0 : if (ret != 0) {
81 0 : hccp_err("[get][async_events]RsCtxGetAsyncEvents failed ret:%d phyId:%u devIndex:0x%x", ret, phyId,
82 : ctxHandle->devIndex);
83 : }
84 :
85 0 : return ret;
86 : }
87 :
88 2 : int RaPeerCtxDeinit(struct RaCtxHandle *ctxHandle)
89 : {
90 2 : unsigned int phyId = ctxHandle->attr.phyId;
91 2 : struct RaRsDevInfo devInfo = {0};
92 2 : int ret = 0;
93 :
94 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
95 :
96 2 : RaPeerMutexLock(phyId);
97 2 : RsSetCtx(phyId);
98 2 : ret = RsCtxDeinit(&devInfo);
99 2 : if (ret != 0) {
100 1 : hccp_err("[deinit][ra_peer_ctx]ctx deinit failed[%d] phy_id[%u]", ret, phyId);
101 : }
102 :
103 2 : RaPeerMutexUnlock(phyId);
104 2 : return ret;
105 : }
106 :
107 2 : int RaPeerGetEidByIp(struct RaCtxHandle *ctxHandle, struct IpInfo ip[], union HccpEid eid[], unsigned int *num)
108 : {
109 2 : unsigned int phyId = ctxHandle->attr.phyId;
110 2 : struct RaRsDevInfo devInfo = {0};
111 2 : int ret = 0;
112 :
113 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
114 :
115 2 : RaPeerMutexLock(phyId);
116 2 : RsSetCtx(phyId);
117 2 : ret = RsGetEidByIp(&devInfo, ip, eid, num);
118 2 : RaPeerMutexUnlock(phyId);
119 2 : if (ret != 0) {
120 1 : hccp_err("[get][eid_by_ip]rs_get_eid_by_ip failed ret[%d] phy_id[%u]", ret, phyId);
121 : }
122 :
123 2 : return ret;
124 : }
125 :
126 2 : int RaPeerGetIpByEid(struct RaCtxHandle *ctxHandle, union HccpEid eid[], struct IpInfo ip[], unsigned int *num)
127 : {
128 2 : unsigned int phyId = ctxHandle->attr.phyId;
129 2 : struct RaRsDevInfo devInfo = {0};
130 2 : int ret = 0;
131 :
132 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
133 :
134 2 : RaPeerMutexLock(phyId);
135 2 : RsSetCtx(phyId);
136 2 : ret = RsGetIpByEid(&devInfo, eid, ip, num);
137 2 : RaPeerMutexUnlock(phyId);
138 2 : if (ret != 0) {
139 1 : hccp_err("[get][IpByEid]RsGetIpByEid failed ret[%d] phyId[%u]", ret, phyId);
140 : }
141 :
142 2 : return ret;
143 : }
144 :
145 2 : int RaPeerCtxTokenIdAlloc(struct RaCtxHandle *ctxHandle, struct HccpTokenId *info,
146 : struct RaTokenIdHandle *tokenIdHandle)
147 : {
148 2 : unsigned int phyId = ctxHandle->attr.phyId;
149 2 : struct RaRsDevInfo devInfo = {0};
150 2 : int ret = 0;
151 :
152 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
153 :
154 2 : RaPeerMutexLock(phyId);
155 2 : RsSetCtx(phyId);
156 2 : ret = RsCtxTokenIdAlloc(&devInfo, &tokenIdHandle->addr, &info->tokenId);
157 2 : RaPeerMutexUnlock(phyId);
158 2 : if (ret != 0) {
159 1 : hccp_err("[init][ra_token_id]rs_ctx_token_id_alloc failed, ret[%d] phyId[%u]", ret, phyId);
160 : }
161 :
162 2 : return ret;
163 : }
164 :
165 2 : int RaPeerCtxTokenIdFree(struct RaCtxHandle *ctxHandle, struct RaTokenIdHandle *tokenIdHandle)
166 : {
167 2 : unsigned int phyId = ctxHandle->attr.phyId;
168 2 : struct RaRsDevInfo devInfo = {0};
169 2 : int ret = 0;
170 :
171 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
172 :
173 2 : RaPeerMutexLock(phyId);
174 2 : RsSetCtx(phyId);
175 2 : ret = RsCtxTokenIdFree(&devInfo, tokenIdHandle->addr);
176 2 : RaPeerMutexUnlock(phyId);
177 2 : if (ret != 0) {
178 1 : hccp_err("[deinit][ra_token_id]rs_ctx_token_id_free failed, ret[%d] phyId[%u]", ret, phyId);
179 : }
180 :
181 2 : return ret;
182 : }
183 :
184 3 : int RaPeerCtxLmemRegister(struct RaCtxHandle *ctxHandle, struct MrRegInfoT *lmemInfo, struct RaLmemHandle *lmemHandle)
185 : {
186 3 : unsigned int phyId = ctxHandle->attr.phyId;
187 3 : struct RaRsDevInfo devInfo = {0};
188 3 : struct MemRegAttrT memAttr = {0};
189 3 : struct MemRegInfoT memInfo = {0};
190 3 : int ret = 0;
191 :
192 3 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
193 3 : ret = RaCtxPrepareLmemRegister(lmemInfo, &memAttr);
194 3 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_lmem]ra_ctx_prepare_lmem_register failed, ret[%d]", ret), ret);
195 :
196 2 : RaPeerMutexLock(phyId);
197 2 : RsSetCtx(phyId);
198 2 : ret = RsCtxLmemReg(&devInfo, &memAttr, &memInfo);
199 2 : RaPeerMutexUnlock(phyId);
200 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_lmem]rs_ctx_lmem_reg failed, ret[%d] phyId[%u]", ret, phyId),
201 : ret);
202 :
203 1 : RaCtxGetLmemInfo(&memInfo, lmemInfo, lmemHandle);
204 :
205 1 : return ret;
206 : }
207 :
208 2 : int RaPeerCtxLmemUnregister(struct RaCtxHandle *ctxHandle, struct RaLmemHandle *lmemHandle)
209 : {
210 2 : unsigned int phyId = ctxHandle->attr.phyId;
211 2 : struct RaRsDevInfo devInfo = {0};
212 2 : int ret = 0;
213 :
214 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
215 :
216 2 : RaPeerMutexLock(phyId);
217 2 : RsSetCtx(phyId);
218 2 : ret = RsCtxLmemUnreg(&devInfo, lmemHandle->addr);
219 2 : RaPeerMutexUnlock(phyId);
220 2 : if (ret != 0) {
221 1 : hccp_err("[init][ra_peer_lmem]rs_ctx_lmem_unreg failed, ret[%d] phyId[%u]", ret, phyId);
222 : }
223 :
224 2 : return ret;
225 : }
226 :
227 2 : int RaPeerCtxRmemImport(struct RaCtxHandle *ctxHandle, struct MrImportInfoT *rmemInfo)
228 : {
229 2 : unsigned int phyId = ctxHandle->attr.phyId;
230 2 : struct MemImportAttrT memAttr = {0};
231 2 : struct MemImportInfoT memInfo = {0};
232 2 : struct RaRsDevInfo devInfo = {0};
233 2 : int ret = 0;
234 :
235 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
236 2 : RaCtxPrepareRmemImport(rmemInfo, &memAttr);
237 :
238 2 : RaPeerMutexLock(phyId);
239 2 : RsSetCtx(phyId);
240 2 : ret = RsCtxRmemImport(&devInfo, &memAttr, &memInfo);
241 2 : RaPeerMutexUnlock(phyId);
242 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_rmem]rs_ctx_rmem_import failed, ret[%d] phyId[%u]", ret, phyId),
243 : ret);
244 :
245 1 : rmemInfo->out.ub.targetSegHandle = memInfo.ub.targetSegHandle;
246 :
247 1 : return ret;
248 : }
249 :
250 2 : int RaPeerCtxRmemUnimport(struct RaCtxHandle *ctxHandle, struct RaRmemHandle *rmemHandle)
251 : {
252 2 : unsigned int phyId = ctxHandle->attr.phyId;
253 2 : struct RaRsDevInfo devInfo = {0};
254 2 : int ret = 0;
255 :
256 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
257 :
258 2 : RaPeerMutexLock(phyId);
259 2 : RsSetCtx(phyId);
260 2 : ret = RsCtxRmemUnimport(&devInfo, rmemHandle->addr);
261 2 : RaPeerMutexUnlock(phyId);
262 2 : if (ret != 0) {
263 1 : hccp_err("[deinit][ra_peer_rmem]rs_ctx_rmem_unimport failed, ret[%d] phyId[%u]", ret, phyId);
264 : }
265 :
266 2 : return ret;
267 : }
268 :
269 2 : int RaPeerCtxChanCreate(struct RaCtxHandle *ctxHandle, struct ChanInfoT *chanInfo, struct RaChanHandle *chanHandle)
270 : {
271 2 : unsigned int phyId = ctxHandle->attr.phyId;
272 2 : struct RaRsDevInfo devInfo = {0};
273 2 : int ret = 0;
274 :
275 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
276 :
277 2 : RaPeerMutexLock(phyId);
278 2 : RsSetCtx(phyId);
279 2 : ret = RsCtxChanCreate(&devInfo, chanInfo->in.dataPlaneFlag, &chanHandle->addr, &chanInfo->out.fd);
280 2 : RaPeerMutexUnlock(phyId);
281 2 : if (ret != 0) {
282 1 : hccp_err("[init][ctx_chan]rs_ctx_chan_create failed, ret[%d] phyId[%u]", ret, phyId);
283 : }
284 :
285 2 : return ret;
286 : }
287 :
288 2 : int RaPeerCtxChanDestroy(struct RaCtxHandle *ctxHandle, struct RaChanHandle *chanHandle)
289 : {
290 2 : unsigned int phyId = ctxHandle->attr.phyId;
291 2 : struct RaRsDevInfo devInfo = {0};
292 2 : int ret = 0;
293 :
294 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
295 :
296 2 : RaPeerMutexLock(phyId);
297 2 : RsSetCtx(phyId);
298 2 : ret = RsCtxChanDestroy(&devInfo, chanHandle->addr);
299 2 : RaPeerMutexUnlock(phyId);
300 2 : if (ret != 0) {
301 1 : hccp_err("[deinit][ctx_chan]rs_ctx_chan_destroy failed, ret[%d] phyId[%u]", ret, phyId);
302 : }
303 :
304 2 : return ret;
305 : }
306 :
307 2 : int RaPeerCtxCqCreate(struct RaCtxHandle *ctxHandle, struct CqInfoT *info, struct RaCqHandle *cqHandle)
308 : {
309 2 : unsigned int phyId = ctxHandle->attr.phyId;
310 2 : struct RaRsDevInfo devInfo = {0};
311 2 : struct CtxCqAttr cqAttr = {0};
312 2 : struct CtxCqInfo cqInfo = {0};
313 2 : int ret = 0;
314 :
315 2 : CHK_PRT_RETURN(info->in.ub.mode != JFC_MODE_NORMAL,
316 : hccp_err("[init][ctx_cq]jfc_mode[%d] not support, phyId[%u]", info->in.ub.mode, phyId), -EINVAL);
317 :
318 1 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
319 1 : RaCtxPrepareCqCreate(info, &cqAttr);
320 :
321 1 : RaPeerMutexLock(phyId);
322 1 : RsSetCtx(phyId);
323 1 : ret = RsCtxCqCreate(&devInfo, &cqAttr, &cqInfo);
324 1 : RaPeerMutexUnlock(phyId);
325 1 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ctx_cq]rs_ctx_cq_create failed, ret[%d] phyId[%u]", ret, phyId), ret);
326 :
327 0 : cqHandle->addr = cqInfo.addr;
328 0 : RaCtxGetCqCreateInfo(&cqInfo, info);
329 0 : return ret;
330 : }
331 :
332 2 : int RaPeerCtxCqDestroy(struct RaCtxHandle *ctxHandle, struct RaCqHandle *cqHandle)
333 : {
334 2 : unsigned int phyId = ctxHandle->attr.phyId;
335 2 : struct RaRsDevInfo devInfo = {0};
336 2 : int ret = 0;
337 :
338 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
339 :
340 2 : RaPeerMutexLock(phyId);
341 2 : RsSetCtx(phyId);
342 2 : ret = RsCtxCqDestroy(&devInfo, cqHandle->addr);
343 2 : RaPeerMutexUnlock(phyId);
344 2 : if (ret != 0) {
345 1 : hccp_err("[deinit][ctx_cq]rs_ctx_cq_destroy failed, ret[%d] phyId[%u]", ret, phyId);
346 : }
347 :
348 2 : return ret;
349 : }
350 :
351 3 : int RaPeerCtxQpCreate(struct RaCtxHandle *ctxHandle, struct QpCreateAttr *qpAttr, struct QpCreateInfo *qpInfo,
352 : struct RaCtxQpHandle *qpHandle)
353 : {
354 3 : unsigned int devIndex = ctxHandle->devIndex;
355 3 : unsigned int phyId = ctxHandle->attr.phyId;
356 3 : struct RaRsDevInfo devInfo = {0};
357 3 : struct CtxQpAttr ctxQpAttr = {0};
358 3 : int ret = 0;
359 :
360 3 : CHK_PRT_RETURN(qpAttr->ub.mode != JETTY_MODE_URMA_NORMAL,
361 : hccp_err("[init][ctx_cq]jetty_mode[%d] not support,"
362 : " phyId[%u]",
363 : qpAttr->ub.mode, phyId),
364 : -EINVAL);
365 :
366 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
367 2 : ret = RaCtxPrepareQpCreate(qpAttr, &ctxQpAttr);
368 2 : CHK_PRT_RETURN(ret != 0,
369 : hccp_err("[init][ra_peer_qp]ra_ctx_prepare_qp_create failed ret[%d] phyId[%u], devIndex[%u]", ret, phyId,
370 : devIndex),
371 : ret);
372 :
373 2 : RaPeerMutexLock(phyId);
374 2 : RsSetCtx(phyId);
375 2 : ret = RsCtxQpCreate(&devInfo, &ctxQpAttr, qpInfo);
376 2 : RaPeerMutexUnlock(phyId);
377 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_qp]rs_ctx_qp_create failed, ret[%d] phyId[%u]", ret, phyId), ret);
378 :
379 1 : RaCtxGetQpCreateInfo(ctxHandle, qpAttr, qpInfo, qpHandle);
380 :
381 1 : return ret;
382 : }
383 :
384 2 : int RaPeerCtxQpDestroy(struct RaCtxQpHandle *qpHandle)
385 : {
386 2 : unsigned int phyId = qpHandle->phyId;
387 2 : struct RaRsDevInfo devInfo = {0};
388 2 : int ret = 0;
389 :
390 2 : RaRsSetDevInfo(&devInfo, phyId, qpHandle->devIndex);
391 :
392 2 : RaPeerMutexLock(phyId);
393 2 : RsSetCtx(phyId);
394 2 : ret = RsCtxQpDestroy(&devInfo, qpHandle->id);
395 2 : RaPeerMutexUnlock(phyId);
396 2 : if (ret != 0) {
397 1 : hccp_err("[deinit][ra_peer_qp]rs_ctx_qp_destroy failed, ret[%d] phyId[%u]", ret, phyId);
398 : }
399 :
400 2 : return ret;
401 : }
402 :
403 2 : int RaPeerCtxGetTpInfoList(struct RaCtxHandle *ctxHandle, struct GetTpCfg *cfg, struct HccpTpInfo infoList[],
404 : unsigned int *num)
405 : {
406 2 : unsigned int phyId = ctxHandle->attr.phyId;
407 2 : struct RaRsDevInfo devInfo = {0};
408 2 : int ret = 0;
409 :
410 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
411 :
412 2 : RaPeerMutexLock(phyId);
413 2 : RsSetCtx(phyId);
414 2 : ret = RsGetTpInfoList(&devInfo, cfg, infoList, num);
415 2 : RaPeerMutexUnlock(phyId);
416 2 : if (ret != 0) {
417 1 : hccp_err("[get][RaTpInfo]RsGetTpInfoList failed, ret[%d] phyId[%u] devIndex[0x%x]", ret, phyId,
418 : ctxHandle->devIndex);
419 : }
420 :
421 2 : return ret;
422 : }
423 :
424 2 : int RaPeerCtxGetTpAttr(struct RaCtxHandle *ctxHandle, uint64_t tpHandle, uint32_t *attrBitmap, struct TpAttr *attr)
425 : {
426 2 : unsigned int phyId = ctxHandle->attr.phyId;
427 2 : struct RaRsDevInfo devInfo = {0};
428 2 : int ret = 0;
429 :
430 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
431 :
432 2 : RaPeerMutexLock(phyId);
433 2 : RsSetCtx(phyId);
434 2 : ret = RsGetTpAttr(&devInfo, attrBitmap, tpHandle, attr);
435 2 : RaPeerMutexUnlock(phyId);
436 2 : if (ret != 0) {
437 1 : hccp_err("[get][RaTpAttr]RsGetTpAttr failed, ret[%d] phyId[%u] devIndex[0x%x]", ret, phyId,
438 : ctxHandle->devIndex);
439 : }
440 :
441 2 : return ret;
442 : }
443 :
444 2 : int RaPeerCtxSetTpAttr(struct RaCtxHandle *ctxHandle, uint64_t tpHandle, uint32_t attrBitmap, struct TpAttr *attr)
445 : {
446 2 : unsigned int phyId = ctxHandle->attr.phyId;
447 2 : struct RaRsDevInfo devInfo = {0};
448 2 : int ret = 0;
449 :
450 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
451 :
452 2 : RaPeerMutexLock(phyId);
453 2 : RsSetCtx(phyId);
454 2 : ret = RsSetTpAttr(&devInfo, attrBitmap, tpHandle, attr);
455 2 : RaPeerMutexUnlock(phyId);
456 2 : if (ret != 0) {
457 1 : hccp_err("[set][RaTpAttr]RsSetTpAttr failed, ret[%d] phyId[%u] devIndex[0x%x]", ret, phyId,
458 : ctxHandle->devIndex);
459 : }
460 :
461 2 : return ret;
462 : }
463 :
464 2 : STATIC void RaPeerPrepareQpImport(struct QpImportInfoT *qpInfo, struct RsJettyImportAttr *importAttr)
465 : {
466 2 : struct RaRsJettyImportAttr *raRsImportAttr = NULL;
467 :
468 2 : raRsImportAttr = &(importAttr->attr);
469 2 : importAttr->key = qpInfo->in.key;
470 2 : RaCtxPrepareQpImport(qpInfo, raRsImportAttr);
471 2 : }
472 :
473 1 : STATIC void RaPeerGetQpImportInfo(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo,
474 : struct RsJettyImportInfo *importInfo, struct RaCtxRemQpHandle *qpHandle)
475 : {
476 1 : struct RaRsJettyImportInfo *raRsImportInfo = NULL;
477 :
478 1 : raRsImportInfo = &(importInfo->info);
479 1 : RaCtxGetQpImportInfo(ctxHandle, qpInfo, raRsImportInfo, qpHandle);
480 1 : qpHandle->id = importInfo->remJettyId;
481 1 : }
482 :
483 2 : int RaPeerCtxQpImport(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo, struct RaCtxRemQpHandle *remQpHandle)
484 : {
485 2 : unsigned int phyId = ctxHandle->attr.phyId;
486 2 : struct RsJettyImportAttr importAttr = {0};
487 2 : struct RsJettyImportInfo importInfo = {0};
488 2 : struct RaRsDevInfo devInfo = {0};
489 2 : int ret = 0;
490 :
491 2 : RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
492 2 : RaPeerPrepareQpImport(qpInfo, &importAttr);
493 :
494 2 : RaPeerMutexLock(phyId);
495 2 : RsSetCtx(phyId);
496 2 : ret = RsCtxQpImport(&devInfo, &importAttr, &importInfo);
497 2 : RaPeerMutexUnlock(phyId);
498 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_qp]rs_ctx_qp_import failed, ret[%d] phyId[%u]", ret, phyId), ret);
499 :
500 1 : RaPeerGetQpImportInfo(ctxHandle, qpInfo, &importInfo, remQpHandle);
501 1 : return ret;
502 : }
503 :
504 2 : int RaPeerCtxQpUnimport(struct RaCtxRemQpHandle *remQpHandle)
505 : {
506 2 : unsigned int phyId = remQpHandle->phyId;
507 2 : struct RaRsDevInfo devInfo = {0};
508 2 : int ret = 0;
509 :
510 2 : RaRsSetDevInfo(&devInfo, phyId, remQpHandle->devIndex);
511 :
512 2 : RaPeerMutexLock(phyId);
513 2 : RsSetCtx(phyId);
514 2 : ret = RsCtxQpUnimport(&devInfo, remQpHandle->qpKey.value, REM_JETTY_ID_SIZE);
515 2 : RaPeerMutexUnlock(phyId);
516 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_peer_qp]rs_ctx_qp_unimport failed, ret[%d] phyId[%u]", ret, phyId),
517 : ret);
518 :
519 1 : return ret;
520 : }
521 :
522 2 : int RaPeerCtxQpBind(struct RaCtxQpHandle *qpHandle, struct RaCtxRemQpHandle *remQpHandle)
523 : {
524 2 : struct RsCtxQpInfo remoteQpInfo = {0};
525 2 : struct RsCtxQpInfo localQpInfo = {0};
526 2 : unsigned int phyId = qpHandle->phyId;
527 2 : struct RaRsDevInfo devInfo = {0};
528 2 : int ret = 0;
529 :
530 2 : RaRsSetDevInfo(&devInfo, phyId, remQpHandle->devIndex);
531 2 : localQpInfo.id = qpHandle->id;
532 2 : remoteQpInfo.id = remQpHandle->id;
533 :
534 2 : RaPeerMutexLock(phyId);
535 2 : RsSetCtx(phyId);
536 2 : ret = RsCtxQpBind(&devInfo, &localQpInfo, &remoteQpInfo);
537 2 : RaPeerMutexUnlock(phyId);
538 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_qp]rs_ctx_qp_bind failed, ret[%d] phyId[%u]", ret, phyId), ret);
539 :
540 1 : return ret;
541 : }
542 :
543 2 : int RaPeerCtxQpUnbind(struct RaCtxQpHandle *qpHandle)
544 : {
545 2 : unsigned int phyId = qpHandle->phyId;
546 2 : struct RaRsDevInfo devInfo = {0};
547 2 : int ret = 0;
548 :
549 2 : RaRsSetDevInfo(&devInfo, phyId, qpHandle->devIndex);
550 :
551 2 : RaPeerMutexLock(phyId);
552 2 : RsSetCtx(phyId);
553 2 : ret = RsCtxQpUnbind(&devInfo, qpHandle->id);
554 2 : RaPeerMutexUnlock(phyId);
555 2 : CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_peer_qp]rs_ctx_qp_unbind failed, ret[%d] phyId[%u]", ret, phyId),
556 : ret);
557 :
558 1 : return ret;
559 : }
560 :
561 2 : int RaPeerCtxGetJettyContext(struct RaCtxQpHandle *qpHandle, uint8_t context[], unsigned int *len)
562 : {
563 2 : unsigned int phyId = qpHandle->phyId;
564 2 : struct RaRsDevInfo devInfo = {0};
565 2 : int ret = 0;
566 :
567 2 : RaRsSetDevInfo(&devInfo, phyId, qpHandle->devIndex);
568 2 : RaPeerMutexLock(phyId);
569 2 : RsSetCtx(phyId);
570 2 : ret = RsCtxGetUbContext(&devInfo, qpHandle->id, CONTEXT_TYPE_JETTY, context, len);
571 2 : RaPeerMutexUnlock(phyId);
572 2 : CHK_PRT_RETURN(ret != 0,
573 : hccp_err("[get][jettyContext]RsCtxGetJettyContext failed, ret[%d] phyId[%u], devIndex[%u]", ret, phyId,
574 : qpHandle->devIndex),
575 : ret);
576 :
577 1 : return ret;
578 : }
|