LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/peer - ra_peer_ctx.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.8 % 353 338
Test Date: 2026-08-04 10:52:23 Functions: 96.6 % 29 28

            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,
     185              :     struct RaLmemHandle *lmemHandle)
     186              : {
     187            3 :     unsigned int phyId = ctxHandle->attr.phyId;
     188            3 :     struct RaRsDevInfo devInfo = {0};
     189            3 :     struct MemRegAttrT memAttr = {0};
     190            3 :     struct MemRegInfoT memInfo = {0};
     191            3 :     int ret = 0;
     192              : 
     193            3 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     194            3 :     ret = RaCtxPrepareLmemRegister(lmemInfo, &memAttr);
     195            3 :     CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_lmem]ra_ctx_prepare_lmem_register failed, ret[%d]",
     196              :         ret), ret);
     197              : 
     198            2 :     RaPeerMutexLock(phyId);
     199            2 :     RsSetCtx(phyId);
     200            2 :     ret = RsCtxLmemReg(&devInfo, &memAttr, &memInfo);
     201            2 :     RaPeerMutexUnlock(phyId);
     202            2 :     CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_lmem]rs_ctx_lmem_reg failed, ret[%d] phyId[%u]", ret, phyId),
     203              :         ret);
     204              : 
     205            1 :     RaCtxGetLmemInfo(&memInfo, lmemInfo, lmemHandle);
     206              : 
     207            1 :     return ret;
     208              : }
     209              : 
     210            2 : int RaPeerCtxLmemUnregister(struct RaCtxHandle *ctxHandle, struct RaLmemHandle *lmemHandle)
     211              : {
     212            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     213            2 :     struct RaRsDevInfo devInfo = {0};
     214            2 :     int ret = 0;
     215              : 
     216            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     217              : 
     218            2 :     RaPeerMutexLock(phyId);
     219            2 :     RsSetCtx(phyId);
     220            2 :     ret = RsCtxLmemUnreg(&devInfo, lmemHandle->addr);
     221            2 :     RaPeerMutexUnlock(phyId);
     222            2 :     if (ret != 0) {
     223            1 :         hccp_err("[init][ra_peer_lmem]rs_ctx_lmem_unreg failed, ret[%d] phyId[%u]", ret, phyId);
     224              :     }
     225              : 
     226            2 :     return ret;
     227              : }
     228              : 
     229            2 : int RaPeerCtxRmemImport(struct RaCtxHandle *ctxHandle, struct MrImportInfoT *rmemInfo)
     230              : {
     231            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     232            2 :     struct MemImportAttrT memAttr = {0};
     233            2 :     struct MemImportInfoT memInfo = {0};
     234            2 :     struct RaRsDevInfo devInfo = {0};
     235            2 :     int ret = 0;
     236              : 
     237            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     238            2 :     RaCtxPrepareRmemImport(rmemInfo, &memAttr);
     239              : 
     240            2 :     RaPeerMutexLock(phyId);
     241            2 :     RsSetCtx(phyId);
     242            2 :     ret = RsCtxRmemImport(&devInfo, &memAttr, &memInfo);
     243            2 :     RaPeerMutexUnlock(phyId);
     244            2 :     CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_rmem]rs_ctx_rmem_import failed, ret[%d] phyId[%u]", ret, phyId),
     245              :         ret);
     246              : 
     247            1 :     rmemInfo->out.ub.targetSegHandle = memInfo.ub.targetSegHandle;
     248              : 
     249            1 :     return ret;
     250              : }
     251              : 
     252            2 : int RaPeerCtxRmemUnimport(struct RaCtxHandle *ctxHandle, struct RaRmemHandle *rmemHandle)
     253              : {
     254            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     255            2 :     struct RaRsDevInfo devInfo = {0};
     256            2 :     int ret = 0;
     257              : 
     258            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     259              : 
     260            2 :     RaPeerMutexLock(phyId);
     261            2 :     RsSetCtx(phyId);
     262            2 :     ret = RsCtxRmemUnimport(&devInfo, rmemHandle->addr);
     263            2 :     RaPeerMutexUnlock(phyId);
     264            2 :     if (ret != 0) {
     265            1 :         hccp_err("[deinit][ra_peer_rmem]rs_ctx_rmem_unimport failed, ret[%d] phyId[%u]", ret, phyId);
     266              :     }
     267              : 
     268            2 :     return ret;
     269              : }
     270              : 
     271            2 : int RaPeerCtxChanCreate(struct RaCtxHandle *ctxHandle, struct ChanInfoT *chanInfo,
     272              :     struct RaChanHandle *chanHandle)
     273              : {
     274            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     275            2 :     struct RaRsDevInfo devInfo = {0};
     276            2 :     int ret = 0;
     277              : 
     278            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     279              : 
     280            2 :     RaPeerMutexLock(phyId);
     281            2 :     RsSetCtx(phyId);
     282            2 :     ret = RsCtxChanCreate(&devInfo, chanInfo->in.dataPlaneFlag, &chanHandle->addr, &chanInfo->out.fd);
     283            2 :     RaPeerMutexUnlock(phyId);
     284            2 :     if (ret != 0) {
     285            1 :         hccp_err("[init][ctx_chan]rs_ctx_chan_create failed, ret[%d] phyId[%u]", ret, phyId);
     286              :     }
     287              : 
     288            2 :     return ret;
     289              : }
     290              : 
     291            2 : int RaPeerCtxChanDestroy(struct RaCtxHandle *ctxHandle, struct RaChanHandle *chanHandle)
     292              : {
     293            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     294            2 :     struct RaRsDevInfo devInfo = {0};
     295            2 :     int ret = 0;
     296              : 
     297            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     298              : 
     299            2 :     RaPeerMutexLock(phyId);
     300            2 :     RsSetCtx(phyId);
     301            2 :     ret = RsCtxChanDestroy(&devInfo, chanHandle->addr);
     302            2 :     RaPeerMutexUnlock(phyId);
     303            2 :     if (ret != 0) {
     304            1 :         hccp_err("[deinit][ctx_chan]rs_ctx_chan_destroy failed, ret[%d] phyId[%u]", ret, phyId);
     305              :     }
     306              : 
     307            2 :     return ret;
     308              : }
     309              : 
     310            2 : int RaPeerCtxCqCreate(struct RaCtxHandle *ctxHandle, struct CqInfoT *info, struct RaCqHandle *cqHandle)
     311              : {
     312            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     313            2 :     struct RaRsDevInfo devInfo = {0};
     314            2 :     struct CtxCqAttr cqAttr = {0};
     315            2 :     struct CtxCqInfo cqInfo = {0};
     316            2 :     int ret = 0;
     317              : 
     318            2 :     CHK_PRT_RETURN(info->in.ub.mode != JFC_MODE_NORMAL, hccp_err("[init][ctx_cq]jfc_mode[%d] not support, phyId[%u]",
     319              :         info->in.ub.mode, phyId), -EINVAL);
     320              : 
     321            1 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     322            1 :     RaCtxPrepareCqCreate(info, &cqAttr);
     323              : 
     324            1 :     RaPeerMutexLock(phyId);
     325            1 :     RsSetCtx(phyId);
     326            1 :     ret = RsCtxCqCreate(&devInfo, &cqAttr, &cqInfo);
     327            1 :     RaPeerMutexUnlock(phyId);
     328            1 :     CHK_PRT_RETURN(ret != 0, hccp_err("[init][ctx_cq]rs_ctx_cq_create failed, ret[%d] phyId[%u]", ret, phyId), ret);
     329              : 
     330            0 :     cqHandle->addr = cqInfo.addr;
     331            0 :     RaCtxGetCqCreateInfo(&cqInfo, info);
     332            0 :     return ret;
     333              : }
     334              : 
     335            2 : int RaPeerCtxCqDestroy(struct RaCtxHandle *ctxHandle, struct RaCqHandle *cqHandle)
     336              : {
     337            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     338            2 :     struct RaRsDevInfo devInfo = {0};
     339            2 :     int ret = 0;
     340              : 
     341            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     342              : 
     343            2 :     RaPeerMutexLock(phyId);
     344            2 :     RsSetCtx(phyId);
     345            2 :     ret = RsCtxCqDestroy(&devInfo, cqHandle->addr);
     346            2 :     RaPeerMutexUnlock(phyId);
     347            2 :     if (ret != 0) {
     348            1 :         hccp_err("[deinit][ctx_cq]rs_ctx_cq_destroy failed, ret[%d] phyId[%u]", ret, phyId);
     349              :     }
     350              : 
     351            2 :     return ret;
     352              : }
     353              : 
     354            3 : int RaPeerCtxQpCreate(struct RaCtxHandle *ctxHandle, struct QpCreateAttr *qpAttr,
     355              :     struct QpCreateInfo *qpInfo, struct RaCtxQpHandle *qpHandle)
     356              : {
     357            3 :     unsigned int devIndex = ctxHandle->devIndex;
     358            3 :     unsigned int phyId = ctxHandle->attr.phyId;
     359            3 :     struct RaRsDevInfo devInfo = {0};
     360            3 :     struct CtxQpAttr ctxQpAttr = {0};
     361            3 :     int ret = 0;
     362              : 
     363            3 :     CHK_PRT_RETURN(qpAttr->ub.mode != JETTY_MODE_URMA_NORMAL, hccp_err("[init][ctx_cq]jetty_mode[%d] not support,"
     364              :         " phyId[%u]", qpAttr->ub.mode, phyId), -EINVAL);
     365              : 
     366            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     367            2 :     ret = RaCtxPrepareQpCreate(qpAttr, &ctxQpAttr);
     368            2 :     CHK_PRT_RETURN(ret, hccp_err("[init][ra_peer_qp]ra_ctx_prepare_qp_create failed ret[%d], phyId[%u] devIndex[%u]",
     369              :         ret, phyId, devIndex), ret);
     370              : 
     371            2 :     RaPeerMutexLock(phyId);
     372            2 :     RsSetCtx(phyId);
     373            2 :     ret = RsCtxQpCreate(&devInfo, &ctxQpAttr, qpInfo);
     374            2 :     RaPeerMutexUnlock(phyId);
     375            2 :     CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_qp]rs_ctx_qp_create failed, ret[%d] phyId[%u]",
     376              :         ret, phyId), ret);
     377              : 
     378            1 :     RaCtxGetQpCreateInfo(ctxHandle, qpAttr, qpInfo, qpHandle);
     379              : 
     380            1 :     return ret;
     381              : }
     382              : 
     383            2 : int RaPeerCtxQpDestroy(struct RaCtxQpHandle *qpHandle)
     384              : {
     385            2 :     unsigned int phyId = qpHandle->phyId;
     386            2 :     struct RaRsDevInfo devInfo = {0};
     387            2 :     int ret = 0;
     388              : 
     389            2 :     RaRsSetDevInfo(&devInfo, phyId, qpHandle->devIndex);
     390              : 
     391            2 :     RaPeerMutexLock(phyId);
     392            2 :     RsSetCtx(phyId);
     393            2 :     ret = RsCtxQpDestroy(&devInfo, qpHandle->id);
     394            2 :     RaPeerMutexUnlock(phyId);
     395            2 :     if (ret != 0) {
     396            1 :         hccp_err("[deinit][ra_peer_qp]rs_ctx_qp_destroy failed, ret[%d] phyId[%u]", ret, phyId);
     397              :     }
     398              : 
     399            2 :     return ret;
     400              : }
     401              : 
     402            2 : int RaPeerCtxGetTpInfoList(struct RaCtxHandle *ctxHandle, struct GetTpCfg *cfg, struct HccpTpInfo infoList[],
     403              :     unsigned int *num)
     404              : {
     405            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     406            2 :     struct RaRsDevInfo devInfo = {0};
     407            2 :     int ret = 0;
     408              : 
     409            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     410              : 
     411            2 :     RaPeerMutexLock(phyId);
     412            2 :     RsSetCtx(phyId);
     413            2 :     ret = RsGetTpInfoList(&devInfo, cfg, infoList, num);
     414            2 :     RaPeerMutexUnlock(phyId);
     415            2 :     if (ret != 0) {
     416            1 :         hccp_err("[get][RaTpInfo]RsGetTpInfoList failed, ret[%d] phyId[%u] devIndex[0x%x]",
     417              :             ret, phyId, ctxHandle->devIndex);
     418              :     }
     419              : 
     420            2 :     return ret;
     421              : }
     422              : 
     423            2 : int RaPeerCtxGetTpAttr(struct RaCtxHandle *ctxHandle, uint64_t tpHandle, uint32_t *attrBitmap, struct TpAttr *attr)
     424              : {
     425            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     426            2 :     struct RaRsDevInfo devInfo = {0};
     427            2 :     int ret = 0;
     428              : 
     429            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     430              : 
     431            2 :     RaPeerMutexLock(phyId);
     432            2 :     RsSetCtx(phyId);
     433            2 :     ret = RsGetTpAttr(&devInfo, attrBitmap, tpHandle, attr);
     434            2 :     RaPeerMutexUnlock(phyId);
     435            2 :     if (ret != 0) {
     436            1 :         hccp_err("[get][RaTpAttr]RsGetTpAttr failed, ret[%d] phyId[%u] devIndex[0x%x]",
     437              :             ret, phyId, ctxHandle->devIndex);
     438              :     }
     439              : 
     440            2 :     return ret;
     441              : }
     442              : 
     443            2 : int RaPeerCtxSetTpAttr(struct RaCtxHandle *ctxHandle, uint64_t tpHandle, uint32_t attrBitmap, struct TpAttr *attr)
     444              : {
     445            2 :     unsigned int phyId = ctxHandle->attr.phyId;
     446            2 :     struct RaRsDevInfo devInfo = {0};
     447            2 :     int ret = 0;
     448              : 
     449            2 :     RaRsSetDevInfo(&devInfo, phyId, ctxHandle->devIndex);
     450              : 
     451            2 :     RaPeerMutexLock(phyId);
     452            2 :     RsSetCtx(phyId);
     453            2 :     ret = RsSetTpAttr(&devInfo, attrBitmap, tpHandle, attr);
     454            2 :     RaPeerMutexUnlock(phyId);
     455            2 :     if (ret != 0) {
     456            1 :         hccp_err("[set][RaTpAttr]RsSetTpAttr failed, ret[%d] phyId[%u] devIndex[0x%x]",
     457              :             ret, phyId, ctxHandle->devIndex);
     458              :     }
     459              : 
     460            2 :     return ret;
     461              : }
     462              : 
     463            2 : STATIC void RaPeerPrepareQpImport(struct QpImportInfoT *qpInfo, struct RsJettyImportAttr *importAttr)
     464              : {
     465            2 :     struct RaRsJettyImportAttr *raRsImportAttr = NULL;
     466              : 
     467            2 :     raRsImportAttr = &(importAttr->attr);
     468            2 :     importAttr->key = qpInfo->in.key;
     469            2 :     RaCtxPrepareQpImport(qpInfo, raRsImportAttr);
     470            2 : }
     471              : 
     472            1 : STATIC void RaPeerGetQpImportInfo(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo,
     473              :     struct RsJettyImportInfo *importInfo, struct RaCtxRemQpHandle *qpHandle)
     474              : {
     475            1 :     struct RaRsJettyImportInfo *raRsImportInfo = NULL;
     476              : 
     477            1 :     raRsImportInfo = &(importInfo->info);
     478            1 :     RaCtxGetQpImportInfo(ctxHandle, qpInfo, raRsImportInfo, qpHandle);
     479            1 :     qpHandle->id = importInfo->remJettyId;
     480            1 : }
     481              : 
     482            2 : int RaPeerCtxQpImport(struct RaCtxHandle *ctxHandle, struct QpImportInfoT *qpInfo,
     483              :     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),
     499              :         ret);
     500              : 
     501            1 :     RaPeerGetQpImportInfo(ctxHandle, qpInfo, &importInfo, remQpHandle);
     502            1 :     return ret;
     503              : }
     504              : 
     505            2 : int RaPeerCtxQpUnimport(struct RaCtxRemQpHandle *remQpHandle)
     506              : {
     507            2 :     unsigned int phyId = remQpHandle->phyId;
     508            2 :     struct RaRsDevInfo devInfo = {0};
     509            2 :     int ret = 0;
     510              : 
     511            2 :     RaRsSetDevInfo(&devInfo, phyId, remQpHandle->devIndex);
     512              : 
     513            2 :     RaPeerMutexLock(phyId);
     514            2 :     RsSetCtx(phyId);
     515            2 :     ret = RsCtxQpUnimport(&devInfo, remQpHandle->qpKey.value, REM_JETTY_ID_SIZE);
     516            2 :     RaPeerMutexUnlock(phyId);
     517            2 :     CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_peer_qp]rs_ctx_qp_unimport failed, ret[%d] phyId[%u]", ret, phyId),
     518              :         ret);
     519              : 
     520            1 :     return ret;
     521              : }
     522              : 
     523            2 : int RaPeerCtxQpBind(struct RaCtxQpHandle *qpHandle, struct RaCtxRemQpHandle *remQpHandle)
     524              : {
     525            2 :     struct RsCtxQpInfo remoteQpInfo = {0};
     526            2 :     struct RsCtxQpInfo localQpInfo = {0};
     527            2 :     unsigned int phyId = qpHandle->phyId;
     528            2 :     struct RaRsDevInfo devInfo = {0};
     529            2 :     int ret = 0;
     530              : 
     531            2 :     RaRsSetDevInfo(&devInfo, phyId, remQpHandle->devIndex);
     532            2 :     localQpInfo.id = qpHandle->id;
     533            2 :     remoteQpInfo.id = remQpHandle->id;
     534              : 
     535            2 :     RaPeerMutexLock(phyId);
     536            2 :     RsSetCtx(phyId);
     537            2 :     ret = RsCtxQpBind(&devInfo, &localQpInfo, &remoteQpInfo);
     538            2 :     RaPeerMutexUnlock(phyId);
     539            2 :     CHK_PRT_RETURN(ret != 0, hccp_err("[init][ra_peer_qp]rs_ctx_qp_bind failed, ret[%d] phyId[%u]", ret, phyId), ret);
     540              : 
     541            1 :     return ret;
     542              : }
     543              : 
     544            2 : int RaPeerCtxQpUnbind(struct RaCtxQpHandle *qpHandle)
     545              : {
     546            2 :     unsigned int phyId = qpHandle->phyId;
     547            2 :     struct RaRsDevInfo devInfo = {0};
     548            2 :     int ret = 0;
     549              : 
     550            2 :     RaRsSetDevInfo(&devInfo, phyId, qpHandle->devIndex);
     551              : 
     552            2 :     RaPeerMutexLock(phyId);
     553            2 :     RsSetCtx(phyId);
     554            2 :     ret = RsCtxQpUnbind(&devInfo, qpHandle->id);
     555            2 :     RaPeerMutexUnlock(phyId);
     556            2 :     CHK_PRT_RETURN(ret != 0, hccp_err("[deinit][ra_peer_qp]rs_ctx_qp_unbind failed, ret[%d] phyId[%u]", ret, phyId),
     557              :         ret);
     558              : 
     559            1 :     return ret;
     560              : }
     561              : 
     562            2 : int RaPeerCtxGetJettyContext(struct RaCtxQpHandle *qpHandle, uint8_t context[], unsigned int *len)
     563              : {
     564            2 :     unsigned int phyId = qpHandle->phyId;
     565            2 :     struct RaRsDevInfo devInfo = {0};
     566            2 :     int ret = 0;
     567              : 
     568            2 :     RaRsSetDevInfo(&devInfo, phyId, qpHandle->devIndex);
     569            2 :     RaPeerMutexLock(phyId);
     570            2 :     RsSetCtx(phyId);
     571            2 :     ret = RsCtxGetUbContext(&devInfo, qpHandle->id, CONTEXT_TYPE_JETTY, context, len);
     572            2 :     RaPeerMutexUnlock(phyId);
     573            2 :     CHK_PRT_RETURN(ret != 0, hccp_err("[get][jettyContext]RsCtxGetJettyContext failed, ret[%d] phyId[%u] devIndex[%u]",
     574              :         ret, phyId, qpHandle->devIndex), ret);
     575              : 
     576            1 :     return ret;
     577              : }
        

Generated by: LCOV version 2.0-1