LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/hdc - ra_hdc_ctx.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 91.8 % 487 447
Test Date: 2026-08-18 17:47:01 Functions: 97.6 % 41 40

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

Generated by: LCOV version 2.0-1