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.6 % 341 326
Test Date: 2026-07-28 12:11:00 Functions: 96.4 % 28 27

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

Generated by: LCOV version 2.0-1