LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/adapter - ra_adp.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 73.3 % 1105 810
Test Date: 2026-08-17 10:19:35 Functions: 80.0 % 75 60

            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              : #define _GNU_SOURCE
      12              : #include <stdlib.h>
      13              : #include <errno.h>
      14              : #include <sys/prctl.h>
      15              : #include "securec.h"
      16              : #include "user_log.h"
      17              : #include "dl_hal_function.h"
      18              : #include "ra_comm.h"
      19              : #include "ra_hdc.h"
      20              : #include "ra_hdc_async.h"
      21              : #include "ra_hdc_lite.h"
      22              : #include "ra_hdc_rdma_notify.h"
      23              : #include "ra_hdc_rdma.h"
      24              : #include "ra_hdc_socket.h"
      25              : #include "ra_hdc_ping.h"
      26              : #include "ra_rs_comm.h"
      27              : #include "ra_hdc_tlv.h"
      28              : #include "ra_rs_err.h"
      29              : #include "rs.h"
      30              : #include "rs_ping.h"
      31              : #include "ra_adp_tlv.h"
      32              : #include "ra_adp_ping.h"
      33              : #include "ra_adp_socket.h"
      34              : #include "ra_hdc_ctx.h"
      35              : #include "ra_hdc_async_ctx.h"
      36              : #include "ra_adp_ctx.h"
      37              : #include "ra_adp_async.h"
      38              : #include "ra_adp_verbs.h"
      39              : #include "ra_adp.h"
      40              : 
      41              : struct RaHdcServer gHdcServer[RA_MAX_PHY_ID_NUM] = {0};
      42              : struct RaHdcInitPara gHdcInitPara = {0};
      43              : struct RsPthreadInfo gRaThreadInfo = {0};
      44              : 
      45              : struct RsOps {
      46              :     int (*rdevInit)(struct rdev rdevInfo, unsigned int notifyType, unsigned int *rdevIndex);
      47              :     int (*rdevInitWithBackup)(struct rdev rdevInfo, struct rdev backupRdevInfo, unsigned int notifyType,
      48              :         unsigned int *rdevIndex);
      49              :     int (*rdevGetPortStatus)(unsigned int phyId, unsigned int rdevIndex, enum PortStatus *status);
      50              :     int (*rdevDeinit)(unsigned int phyId, unsigned int notifyType, unsigned int rdevIndex);
      51              :     int (*qpCreate)(unsigned int phyId, unsigned int rdevIndex, struct RsQpNorm qpNorm, struct RsQpResp *qpResp);
      52              :     int (*qpCreateWithAttrs)(unsigned int phyId, unsigned int rdevIndex, struct RsQpNormWithAttrs *qpNorm,
      53              :         struct RsQpRespWithAttrs *qpResp);
      54              :     int (*qpDestroy)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn);
      55              :     int (*typicalQpModify)(unsigned int phyId, unsigned int rdevIndex, struct TypicalQp localQpInfo,
      56              :         struct TypicalQp remoteQpInfo, struct TypicalQpAttr *qpAttr);
      57              :     int (*qpBatchModify)(unsigned int phyId, unsigned int rdevIndex, int status, int qpn[], int qpnNum);
      58              :     int (*qpConnectAsync)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, int fd);
      59              :     int (*getQpStatus)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct RsQpStatusInfo *qpInfo);
      60              :     int (*mrReg)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct RdmaMrRegInfo *mrRegInfo);
      61              :     int (*mrDereg)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, char *addr);
      62              :     int (*registerMr)(unsigned int phyId, unsigned int rdevIndex, struct RdmaMrRegInfo *mrRegInfo, void **mrHandle);
      63              :     int (*typicalRegisterMr)(unsigned int phyId, unsigned int rdevIndex, struct RdmaMrRegInfo *mrRegInfo,
      64              :         void **mrHandle);
      65              :     int (*remapMr)(unsigned int phyId, unsigned int rdevIndex, struct MemRemapInfo memList[], unsigned int memNum);
      66              :     int (*typicalDeregisterMr)(unsigned int phyId, unsigned int devIndex, unsigned long long addr);
      67              :     int (*sendWr)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct SendWr *wr,
      68              :         struct SendWrRsp *wrRsp);
      69              :     int (*sendWrList)(struct RsWrlistBaseInfo baseInfo, struct WrInfo *wrList, unsigned int sendNum,
      70              :         struct SendWrRsp *wrRsp, unsigned int *completeNum);
      71              :     int (*getNotifyMrInfo)(unsigned int phyId, unsigned int rdevIndex, struct MrInfoT *info);
      72              :     int (*notifyCfgSet)(unsigned int phyId, unsigned long long va, unsigned long long size);
      73              :     int (*notifyCfgGet)(unsigned int phyId, unsigned long long *va, unsigned long long *size);
      74              :     int (*setHostPid)(unsigned int phyId, pid_t hostPid, const char *pidSign);
      75              :     int (*getInterfaceVersion)(unsigned int opcode, unsigned int *version);
      76              :     int (*setTsqpDepth)(unsigned int phyId, unsigned int rdevIndex, unsigned int tempDepth, unsigned int *qpNum);
      77              :     int (*getTsqpDepth)(unsigned int phyId, unsigned int rdevIndex, unsigned int *tempDepth, unsigned int *qpNum);
      78              :     int (*setQpAttrQos)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct QosAttr *attr);
      79              :     int (*setQpAttrTimeout)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, unsigned int *timeout);
      80              :     int (*setQpAttrRetryCnt)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, unsigned int *retryCnt);
      81              :     int (*getCqeErrInfo)(struct CqeErrInfo *info);
      82              :     int (*getLiteSupport)(unsigned int phyId, unsigned int rdevIndex, int *supportLite);
      83              :     int (*getLiteRdevCap)(unsigned int phyId, unsigned int rdevIndex, struct LiteRdevCapResp *resp);
      84              :     int (*getLiteQpCqAttr)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct LiteQpCqAttrResp *resp);
      85              :     int (*getLiteMemAttr)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn, struct LiteMemAttrResp *resp);
      86              :     int (*getLiteConnectedInfo)(unsigned int phyId, unsigned int rdevIndex, unsigned int qpn,
      87              :         struct LiteConnectedInfoResp *resp);
      88              :     int (*getCqeErrInfoNum)(unsigned int phyId, unsigned int rdevIdx, unsigned int *num);
      89              :     int (*getCqeErrInfoList)(unsigned int phyId, unsigned int rdevIdx, struct CqeErrInfo *info, unsigned int *num);
      90              :     int (*getTlsEnable)(unsigned int phyId, bool *tlsEnable);
      91              :     int (*getSecRandom)(int *value);
      92              :     int (*getHccnCfg)(unsigned int phyId, enum HccnCfgKey key, char *value, unsigned int *valueLen);
      93              : };
      94              : 
      95              : struct RsOps gRaRsOps = {
      96              :     .rdevInit = RsRdevInit,
      97              :     .rdevInitWithBackup = RsRdevInitWithBackup,
      98              :     .rdevGetPortStatus = RsRdevGetPortStatus,
      99              :     .rdevDeinit = RsRdevDeinit,
     100              :     .qpCreate = RsQpCreate,
     101              :     .qpCreateWithAttrs = RsQpCreateWithAttrs,
     102              :     .qpDestroy = RsQpDestroy,
     103              :     .typicalQpModify = RsTypicalQpModify,
     104              :     .qpBatchModify = RsQpBatchModify,
     105              :     .qpConnectAsync = RsQpConnectAsync,
     106              :     .getQpStatus = RsGetQpStatus,
     107              :     .mrReg = RsMrReg,
     108              :     .mrDereg = RsMrDereg,
     109              :     .registerMr = RsTypicalRegisterMrV1,
     110              :     .typicalRegisterMr = RsTypicalRegisterMr,
     111              :     .remapMr = RsRemapMr,
     112              :     .typicalDeregisterMr = RsTypicalDeregisterMr,
     113              :     .sendWr = RsSendWr,
     114              :     .sendWrList = RsSendWrlist,
     115              :     .getNotifyMrInfo = RsGetNotifyMrInfo,
     116              :     .notifyCfgSet = RsNotifyCfgSet,
     117              :     .notifyCfgGet = RsNotifyCfgGet,
     118              :     .setHostPid = RsSetHostPid,
     119              :     .getInterfaceVersion = RsGetInterfaceVersion,
     120              :     .setTsqpDepth = RsSetTsqpDepth,
     121              :     .getTsqpDepth = RsGetTsqpDepth,
     122              :     .setQpAttrQos = RsSetQpAttrQos,
     123              :     .setQpAttrTimeout = RsSetQpAttrTimeout,
     124              :     .setQpAttrRetryCnt = RsSetQpAttrRetryCnt,
     125              :     .getCqeErrInfo = RsGetCqeErrInfo,
     126              :     .getLiteRdevCap = RsGetLiteRdevCap,
     127              :     .getLiteQpCqAttr = RsGetLiteQpCqAttr,
     128              :     .getLiteConnectedInfo = RsGetLiteConnectedInfo,
     129              :     .getLiteMemAttr = RsGetLiteMemAttr,
     130              :     .getLiteSupport = RsGetLiteSupport,
     131              :     .getCqeErrInfoNum = RsGetCqeErrInfoNum,
     132              :     .getCqeErrInfoList = RsGetCqeErrInfoList,
     133              :     .getTlsEnable = RsGetTlsEnable,
     134              :     .getSecRandom = RsDrvGetRandomNum,
     135              :     .getHccnCfg = RsGetHccnCfg,
     136              : };
     137              : 
     138              : struct HdcOps gRaHdcOps = {
     139              :     .getCapacity = DlDrvHdcGetCapacity,
     140              :     .clientCreate = DlDrvHdcClientCreate,
     141              :     .clientDestroy = DlDrvHdcClientDestroy,
     142              :     .sessionConnect = DlDrvHdcSessionConnect,
     143              :     .sessionConnectEx = DlHalHdcSessionConnectEx,
     144              :     .serverCreate = DlDrvHdcServerCreate,
     145              :     .serverDestroy = DlDrvHdcServerDestroy,
     146              :     .sessionAccept = DlDrvHdcSessionAccept,
     147              :     .sessionClose = DlDrvHdcSessionClose,
     148              :     .freeMsg = DlDrvHdcFreeMsg,
     149              :     .reuseMsg = DlDrvHdcReuseMsg,
     150              :     .addMsgBuffer = DlDrvHdcAddMsgBuffer,
     151              :     .getMsgBuffer = DlDrvHdcGetMsgBuffer,
     152              :     .recv = DlHalHdcRecv,
     153              :     .send = DlHalHdcSend,
     154              :     .allocMsg = DlDrvHdcAllocMsg,
     155              :     .setSessionReference = DlDrvHdcSetSessionReference,
     156              : };
     157              : 
     158              : #define RA_HDC_OPS gRaHdcOps
     159              : 
     160          241 : STATIC void MsgHeadBuildUpHw(char *pSendRcvBuf, struct MsgHead *recvMsgHead, int ret, unsigned int msgDataLen)
     161              : {
     162          241 :     struct MsgHead *pSendRcvHead = NULL;
     163              : 
     164          241 :     pSendRcvHead = (struct MsgHead *)pSendRcvBuf;
     165          241 :     pSendRcvHead->opcode = recvMsgHead->opcode;
     166          241 :     pSendRcvHead->asyncReqId = recvMsgHead->asyncReqId;
     167          241 :     pSendRcvHead->ret = ret;
     168          241 :     pSendRcvHead->msgDataLen = msgDataLen;
     169              : 
     170          241 :     return;
     171              : }
     172              : 
     173            0 : STATIC int OpMsgErr(char **outBuf, struct MsgHead *recvMsgHead, int *outBufLen, int opRight)
     174              : {
     175            0 :     unsigned int opcode = recvMsgHead->opcode;
     176            0 :     char *outBufTmp = NULL;
     177            0 :     int msgRet = 0;
     178              : 
     179            0 :     outBufTmp = (char *)calloc(sizeof(struct MsgHead), sizeof(char));
     180            0 :     CHK_PRT_RETURN(outBufTmp == NULL, hccp_err("send_buf calloc failed."), -ENOMEM);
     181              : 
     182            0 :     if (opRight == HAVE_OP_RIGHT) {
     183            0 :         if (opcode >= RA_RS_OP_MAX_NUM || ((opcode < RA_RS_HDC_SESSION_CLOSE) && (opcode >= RA_RS_EXTER_OP_MAX_NUM))) {
     184            0 :             msgRet = -EPROTONOSUPPORT;
     185              :         } else {
     186            0 :             msgRet = -EPIPE;
     187              :         }
     188            0 :     } else if (opRight == TGID_INVALID) {
     189            0 :         msgRet = -EPERM;
     190              :     } else {
     191            0 :         msgRet = -EACCES;
     192              :     }
     193              : 
     194            0 :     MsgHeadBuildUpHw(outBufTmp, recvMsgHead, msgRet, 0);
     195              : 
     196            0 :     *outBuf = outBufTmp;
     197            0 :     *outBufLen = sizeof(struct MsgHead);
     198              : 
     199            0 :     return 0;
     200              : }
     201              : 
     202            2 : STATIC int RaRsRdevInit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     203              : {
     204            2 :     unsigned int rdevIndex = 0;
     205            2 :     union OpRdevInitData *rdevInitData = (union OpRdevInitData *)(inBuf + sizeof(struct MsgHead));
     206              : 
     207              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevInitData), sizeof(struct MsgHead), rcvBufLen, opResult);
     208              : 
     209            2 :     *opResult = gRaRsOps.rdevInit(rdevInitData->txData.rdevInfo, NOTIFY, &rdevIndex);
     210            2 :     if (*opResult != 0) {
     211            1 :         hccp_err("rdev_init failed ret[%d].", *opResult);
     212            1 :         return 0;
     213              :     }
     214              : 
     215            1 :     rdevInitData = (union OpRdevInitData *)(outBuf + sizeof(struct MsgHead));
     216            1 :     rdevInitData->rxData.rdevIndex = rdevIndex;
     217              : 
     218            1 :     return 0;
     219              : }
     220              : 
     221            2 : STATIC int RaRsRdevInitWithBackup(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     222              : {
     223            2 :     union OpRdevInitWithBackupData *rdevInitData = (union OpRdevInitWithBackupData *)(inBuf + sizeof(struct MsgHead));
     224            2 :     unsigned int rdevIndex = 0;
     225              : 
     226              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevInitWithBackupData), sizeof(struct MsgHead), rcvBufLen, opResult);
     227              : 
     228            2 :     *opResult = gRaRsOps.rdevInitWithBackup(rdevInitData->txData.rdevInfo, rdevInitData->txData.backupRdevInfo, NOTIFY,
     229              :         &rdevIndex);
     230            2 :     if (*opResult != 0) {
     231            1 :         hccp_err("rdev_init_with_backup failed ret[%d].", *opResult);
     232            1 :         return 0;
     233              :     }
     234              : 
     235            1 :     rdevInitData = (union OpRdevInitWithBackupData *)(outBuf + sizeof(struct MsgHead));
     236            1 :     rdevInitData->rxData.rdevIndex = rdevIndex;
     237              : 
     238            1 :     return 0;
     239              : }
     240              : 
     241            2 : STATIC int RaRsRdevGetPortStatus(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     242              : {
     243            2 :     union OpRdevGetPortStatusData *statusData = NULL;
     244            2 :     enum PortStatus status = PORT_STATUS_DOWN;
     245              : 
     246              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevGetPortStatusData), sizeof(struct MsgHead), rcvBufLen, opResult);
     247              : 
     248            2 :     statusData = (union OpRdevGetPortStatusData *)(inBuf + sizeof(struct MsgHead));
     249            2 :     *opResult = gRaRsOps.rdevGetPortStatus(statusData->txData.phyId, statusData->txData.rdevIndex, &status);
     250            2 :     if (*opResult != 0) {
     251            1 :         hccp_err("rdev_get_port_status failed ret[%d].", *opResult);
     252            1 :         return 0;
     253              :     }
     254              : 
     255            1 :     statusData = (union OpRdevGetPortStatusData *)(outBuf + sizeof(struct MsgHead));
     256            1 :     statusData->rxData.status = status;
     257              : 
     258            1 :     return 0;
     259              : }
     260              : 
     261            1 : STATIC int RaRsRdevDeinit(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     262              : {
     263            1 :     union OpRdevDeinitData *rdevDeinitData = (union OpRdevDeinitData *)(inBuf + sizeof(struct MsgHead));
     264              : 
     265              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRdevDeinitData), sizeof(struct MsgHead), rcvBufLen, opResult);
     266              : 
     267            1 :     *opResult = gRaRsOps.rdevDeinit(rdevDeinitData->txData.phyId, NOTIFY, rdevDeinitData->txData.rdevIndex);
     268            1 :     if (*opResult != 0) {
     269            0 :         hccp_err("rdev_deinit failed ret[%d].", *opResult);
     270              :     }
     271              : 
     272            1 :     return 0;
     273              : }
     274              : 
     275            2 : STATIC int RaRsGetTsqpDepth(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     276              : {
     277            2 :     unsigned int tempDepth = 0;
     278            2 :     unsigned int qpNum = 0;
     279            2 :     union OpGetTsqpDepthData *getTsqpDepthData = (union OpGetTsqpDepthData *)(inBuf + sizeof(struct MsgHead));
     280              : 
     281              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetTsqpDepthData), sizeof(struct MsgHead), rcvBufLen, opResult);
     282              : 
     283            2 :     *opResult = gRaRsOps.getTsqpDepth(getTsqpDepthData->txData.phyId, getTsqpDepthData->txData.rdevIndex, &tempDepth,
     284              :         &qpNum);
     285            2 :     if (*opResult != 0) {
     286            1 :         hccp_err("set_tsqp_depth failed ret[%d].", *opResult);
     287            1 :         return 0;
     288              :     }
     289              : 
     290            1 :     getTsqpDepthData = (union OpGetTsqpDepthData *)(outBuf + sizeof(struct MsgHead));
     291            1 :     getTsqpDepthData->rxData.tempDepth = tempDepth;
     292            1 :     getTsqpDepthData->rxData.qpNum = qpNum;
     293              : 
     294            1 :     return 0;
     295              : }
     296              : 
     297            2 : STATIC int RaRsSetTsqpDepth(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     298              : {
     299            2 :     unsigned int qpNum = 0;
     300            2 :     union OpSetTsqpDepthData *setTsqpDepthData = (union OpSetTsqpDepthData *)(inBuf + sizeof(struct MsgHead));
     301              : 
     302              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetTsqpDepthData), sizeof(struct MsgHead), rcvBufLen, opResult);
     303              : 
     304            2 :     *opResult = gRaRsOps.setTsqpDepth(setTsqpDepthData->txData.phyId, setTsqpDepthData->txData.rdevIndex,
     305              :         setTsqpDepthData->txData.tempDepth, &qpNum);
     306            2 :     if (*opResult != 0) {
     307            1 :         hccp_err("set_tsqp_depth failed ret[%d].", *opResult);
     308            1 :         return 0;
     309              :     }
     310              : 
     311            1 :     setTsqpDepthData = (union OpSetTsqpDepthData *)(outBuf + sizeof(struct MsgHead));
     312            1 :     setTsqpDepthData->rxData.qpNum = qpNum;
     313              : 
     314            1 :     return 0;
     315              : }
     316              : 
     317            2 : STATIC int RaRsQpCreate(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     318              : {
     319              :     struct RsQpNorm qpNorm;
     320            2 :     struct RsQpResp qpResp = {0};
     321            2 :     union OpQpCreateData *createData = (union OpQpCreateData *)(inBuf + sizeof(struct MsgHead));
     322              : 
     323              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpCreateData), sizeof(struct MsgHead), rcvBufLen, opResult);
     324              : 
     325            2 :     int qpMode = createData->txData.qpMode;
     326            2 :     qpNorm.flag = createData->txData.flag;
     327            2 :     qpNorm.isExp = 1;
     328            2 :     qpNorm.isExt = 1;
     329            2 :     if (qpMode == RA_RS_OP_QP_MODE_EXT) {
     330            0 :         qpNorm.qpMode = RA_RS_OP_QP_MODE;
     331              :     } else {
     332            2 :         qpNorm.qpMode = qpMode;
     333              :     }
     334            2 :     qpNorm.memAlign = createData->txData.memAlign;
     335              : 
     336            2 :     *opResult = gRaRsOps.qpCreate(createData->txData.phyId, createData->txData.rdevIndex, qpNorm, &qpResp);
     337            2 :     if (*opResult != 0) {
     338            1 :         hccp_err("qp create failed ret[%d].", *opResult);
     339            1 :         return 0;
     340              :     }
     341              : 
     342            1 :     createData = (union OpQpCreateData *)(outBuf + sizeof(struct MsgHead));
     343            1 :     createData->rxData.qpn = qpResp.qpn;
     344            1 :     createData->rxData.psn = qpResp.psn;
     345            1 :     createData->rxData.gidIdx = qpResp.gidIdx;
     346              : 
     347            1 :     return 0;
     348              : }
     349              : 
     350            2 : STATIC int RaRsQpCreateWithAttrs(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     351              : {
     352            2 :     union OpQpCreateWithAttrsData *createData = NULL;
     353            2 :     struct RsQpNormWithAttrs qpNorm = {0};
     354            2 :     struct RsQpRespWithAttrs qpResp = {0};
     355              : 
     356              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpCreateWithAttrsData), sizeof(struct MsgHead), rcvBufLen, opResult);
     357              : 
     358            2 :     createData = (union OpQpCreateWithAttrsData *)(inBuf + sizeof(struct MsgHead));
     359              : 
     360            2 :     qpNorm.isExp = 1;
     361            2 :     qpNorm.isExt = 1;
     362            2 :     qpNorm.extAttrs = createData->txData.extAttrs;
     363              : 
     364            2 :     *opResult = gRaRsOps.qpCreateWithAttrs(createData->txData.phyId, createData->txData.rdevIndex, &qpNorm, &qpResp);
     365            2 :     if (*opResult != 0) {
     366            1 :         hccp_err("qp create failed ret[%d].", *opResult);
     367            1 :         return 0;
     368              :     }
     369              : 
     370            1 :     createData = (union OpQpCreateWithAttrsData *)(outBuf + sizeof(struct MsgHead));
     371            1 :     createData->rxData.qpn = qpResp.qpn;
     372            1 :     createData->rxData.psn = qpResp.psn;
     373            1 :     createData->rxData.gidIdx = qpResp.gidIdx;
     374              : 
     375            1 :     return 0;
     376              : }
     377              : 
     378            1 : STATIC int RaRsAiQpCreate(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     379              : {
     380            1 :     union OpAiQpCreateData *createData = NULL;
     381            1 :     struct RsQpNormWithAttrs qpNorm = {0};
     382            1 :     struct RsQpRespWithAttrs qpResp = {0};
     383              : 
     384              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpAiQpCreateData), sizeof(struct MsgHead), rcvBufLen, opResult);
     385              : 
     386            1 :     createData = (union OpAiQpCreateData *)(inBuf + sizeof(struct MsgHead));
     387              : 
     388            1 :     qpNorm.isExp = 1;
     389            1 :     qpNorm.isExt = 1;
     390            1 :     qpNorm.extAttrs = createData->txData.extAttrs;
     391            1 :     qpNorm.aiOpSupport = 1;
     392              : 
     393            1 :     *opResult = gRaRsOps.qpCreateWithAttrs(createData->txData.phyId, createData->txData.rdevIndex, &qpNorm, &qpResp);
     394            1 :     if (*opResult != 0) {
     395            0 :         hccp_err("qp create failed ret[%d].", *opResult);
     396            0 :         return 0;
     397              :     }
     398              : 
     399            1 :     createData = (union OpAiQpCreateData *)(outBuf + sizeof(struct MsgHead));
     400            1 :     createData->rxData.qpn = qpResp.qpn;
     401            1 :     createData->rxData.aiQpAddr = qpResp.aiQpAddr;
     402            1 :     createData->rxData.sqIndex = qpResp.sqIndex;
     403            1 :     createData->rxData.dbIndex = qpResp.dbIndex;
     404            1 :     createData->rxData.psn = qpResp.psn;
     405              : 
     406            1 :     return 0;
     407              : }
     408              : 
     409            1 : STATIC int RaRsAiQpCreateWithData(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     410              : {
     411            1 :     union OpAiQpCreateWithAttrsData *createData = NULL;
     412            1 :     struct RsQpNormWithAttrs qpNorm = {0};
     413            1 :     struct RsQpRespWithAttrs qpResp = {0};
     414              : 
     415              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpAiQpCreateWithAttrsData), sizeof(struct MsgHead), rcvBufLen, opResult);
     416              : 
     417            1 :     createData = (union OpAiQpCreateWithAttrsData *)(inBuf + sizeof(struct MsgHead));
     418              : 
     419            1 :     qpNorm.isExp = 1;
     420            1 :     qpNorm.isExt = 1;
     421            1 :     qpNorm.extAttrs = createData->txData.extAttrs;
     422            1 :     qpNorm.aiOpSupport = 1;
     423              : 
     424            1 :     *opResult = gRaRsOps.qpCreateWithAttrs(createData->txData.phyId, createData->txData.rdevIndex, &qpNorm, &qpResp);
     425            1 :     if (*opResult != 0) {
     426            0 :         hccp_err("qp create failed ret[%d].", *opResult);
     427            0 :         return 0;
     428              :     }
     429              : 
     430            1 :     createData = (union OpAiQpCreateWithAttrsData *)(outBuf + sizeof(struct MsgHead));
     431            1 :     createData->rxData.qpn = qpResp.qpn;
     432            1 :     createData->rxData.gidIdx = qpResp.gidIdx;
     433            1 :     createData->rxData.psn = qpResp.psn;
     434            1 :     createData->rxData.aiQpAddr = qpResp.aiQpAddr;
     435            1 :     createData->rxData.sqIndex = qpResp.sqIndex;
     436            1 :     createData->rxData.dbIndex = qpResp.dbIndex;
     437            1 :     createData->rxData.aiScqAddr = qpResp.aiScqAddr;
     438            1 :     createData->rxData.aiRcqAddr = qpResp.aiRcqAddr;
     439            1 :     (void)memcpy_s(&createData->rxData.dataPlaneInfo, sizeof(struct AiDataPlaneInfo), &qpResp.dataPlaneInfo,
     440              :         sizeof(struct AiDataPlaneInfo));
     441              : 
     442            1 :     return 0;
     443              : }
     444              : 
     445            2 : STATIC int RaRsTypicalQpCreate(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     446              : {
     447            2 :     union OpTypicalQpCreateData *createData = (union OpTypicalQpCreateData *)(inBuf + sizeof(struct MsgHead));
     448            2 :     struct RsQpResp qpResp = {0};
     449              :     struct RsQpNorm qpNorm;
     450              :     int qpMode;
     451              : 
     452              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalQpCreateData), sizeof(struct MsgHead), rcvBufLen, opResult);
     453              : 
     454            2 :     qpMode = createData->txData.qpMode;
     455            2 :     qpNorm.flag = createData->txData.flag;
     456            2 :     qpNorm.isExp = 1;
     457            2 :     qpNorm.isExt = 1;
     458            2 :     if (qpMode == RA_RS_OP_QP_MODE_EXT) {
     459            0 :         qpNorm.qpMode = RA_RS_OP_QP_MODE;
     460              :     } else {
     461            2 :         qpNorm.qpMode = qpMode;
     462              :     }
     463            2 :     qpNorm.memAlign = createData->txData.memAlign;
     464              : 
     465            2 :     *opResult = gRaRsOps.qpCreate(createData->txData.phyId, createData->txData.rdevIndex, qpNorm, &qpResp);
     466            2 :     if (*opResult != 0) {
     467            1 :         hccp_err("qp create failed ret[%d].", *opResult);
     468            1 :         return 0;
     469              :     }
     470              : 
     471            1 :     createData = (union OpTypicalQpCreateData *)(outBuf + sizeof(struct MsgHead));
     472            1 :     createData->rxData.qpn = qpResp.qpn;
     473            1 :     createData->rxData.gidIdx = qpResp.gidIdx;
     474            1 :     createData->rxData.psn = qpResp.psn;
     475            1 :     createData->rxData.gid = qpResp.gid;
     476              : 
     477            1 :     return 0;
     478              : }
     479              : 
     480            1 : STATIC int RaRsQpDestroy(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     481              : {
     482            1 :     union OpQpDestroyData *qpDestroyData = (union OpQpDestroyData *)(inBuf + sizeof(struct MsgHead));
     483              : 
     484              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpDestroyData), sizeof(struct MsgHead), rcvBufLen, opResult);
     485              : 
     486            1 :     *opResult = gRaRsOps.qpDestroy(qpDestroyData->txData.phyId, qpDestroyData->txData.rdevIndex,
     487              :         qpDestroyData->txData.qpn);
     488            1 :     if (*opResult != 0) {
     489            0 :         hccp_err("qp destroy failed ret[%d].", *opResult);
     490              :     }
     491              : 
     492            1 :     return 0;
     493              : }
     494              : 
     495            2 : STATIC int RaRsTypicalQpModify(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     496              : {
     497            2 :     union OpTypicalQpModifyData *qpModifyData = (union OpTypicalQpModifyData *)(inBuf + sizeof(struct MsgHead));
     498            2 :     struct TypicalQpAttr qpAttr = {0};
     499              : 
     500              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalQpModifyData), sizeof(struct MsgHead), rcvBufLen, opResult);
     501              : 
     502            2 :     *opResult = gRaRsOps.typicalQpModify(qpModifyData->txData.phyId, qpModifyData->txData.rdevIndex,
     503              :         qpModifyData->txData.localQpInfo, qpModifyData->txData.remoteQpInfo, &qpAttr);
     504            2 :     if (*opResult != 0) {
     505            1 :         hccp_err("qp info modify failed ret[%d].", *opResult);
     506            1 :         return 0;
     507              :     }
     508              : 
     509            1 :     qpModifyData = (union OpTypicalQpModifyData *)(outBuf + sizeof(struct MsgHead));
     510            1 :     qpModifyData->rxData.udpSport = qpAttr.udpSport;
     511            1 :     qpModifyData->rxData.pathMtu = qpAttr.pathMtu;
     512              : 
     513            1 :     return 0;
     514              : }
     515              : 
     516            1 : STATIC int RaRsQpBatchModify(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     517              : {
     518            1 :     union OpQpBatchModifyData *qpBatchModifyData = (union OpQpBatchModifyData *)(inBuf + sizeof(struct MsgHead));
     519              : 
     520              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpBatchModifyData), sizeof(struct MsgHead), rcvBufLen, opResult);
     521              :     HCCP_CHECK_PARAM_LEN_RET_HOST(qpBatchModifyData->txData.qpnNum, 0, RA_MAX_BATCH_QP_MODIFY_NUM, opResult);
     522              : 
     523            2 :     *opResult = gRaRsOps.qpBatchModify(qpBatchModifyData->txData.phyId, qpBatchModifyData->txData.rdevIndex,
     524            1 :         qpBatchModifyData->txData.status, qpBatchModifyData->txData.qpn, qpBatchModifyData->txData.qpnNum);
     525            1 :     if (*opResult != 0) {
     526            1 :         hccp_err("qp info modify failed ret[%d].", *opResult);
     527              :     }
     528              : 
     529            1 :     return 0;
     530              : }
     531              : 
     532            1 : STATIC int RaRsQpConnectAsync(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     533              : {
     534            1 :     union OpQpConnectData *qpConnectData = (union OpQpConnectData *)(inBuf + sizeof(struct MsgHead));
     535              : 
     536              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpConnectData), sizeof(struct MsgHead), rcvBufLen, opResult);
     537              : 
     538            2 :     *opResult = gRaRsOps.qpConnectAsync(qpConnectData->txData.phyId, qpConnectData->txData.rdevIndex,
     539            1 :         qpConnectData->txData.qpn, qpConnectData->txData.fd);
     540            1 :     if (*opResult != 0) {
     541            0 :         hccp_err("qp info async failed ret[%d].", *opResult);
     542              :     }
     543              : 
     544            1 :     return 0;
     545              : }
     546              : 
     547            2 : STATIC int RaRsGetQpStatus(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     548              : {
     549            2 :     union OpQpStatusData *qpStatusData = (union OpQpStatusData *)(inBuf + sizeof(struct MsgHead));
     550            2 :     struct RsQpStatusInfo qpInfo = {0};
     551              : 
     552              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpStatusData), sizeof(struct MsgHead), rcvBufLen, opResult);
     553              : 
     554            2 :     *opResult = gRaRsOps.getQpStatus(qpStatusData->txData.phyId, qpStatusData->txData.rdevIndex,
     555              :         qpStatusData->txData.qpn, &qpInfo);
     556            2 :     if (*opResult != 0) {
     557            1 :         hccp_err("query qp status async failed ret[%d].", *opResult);
     558            1 :         return 0;
     559              :     }
     560              : 
     561            1 :     qpStatusData = (union OpQpStatusData *)(outBuf + sizeof(struct MsgHead));
     562            1 :     qpStatusData->rxData.status = qpInfo.status;
     563              : 
     564            1 :     return 0;
     565              : }
     566              : 
     567            2 : STATIC int RaRsGetQpInfo(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     568              : {
     569            2 :     union OpQpInfoData *qpInfoData = (union OpQpInfoData *)(inBuf + sizeof(struct MsgHead));
     570            2 :     struct RsQpStatusInfo qpInfo = {0};
     571              : 
     572              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpQpInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
     573              : 
     574            2 :     *opResult = gRaRsOps.getQpStatus(qpInfoData->txData.phyId, qpInfoData->txData.rdevIndex, qpInfoData->txData.qpn,
     575              :         &qpInfo);
     576            2 :     if (*opResult != 0) {
     577            1 :         hccp_err("query qp status async failed ret[%d].", *opResult);
     578            1 :         return 0;
     579              :     }
     580              : 
     581            1 :     qpInfoData = (union OpQpInfoData *)(outBuf + sizeof(struct MsgHead));
     582            1 :     qpInfoData->rxData.status = qpInfo.status;
     583            1 :     qpInfoData->rxData.udpSport = qpInfo.udpSport;
     584              : 
     585            1 :     return 0;
     586              : }
     587              : 
     588            1 : STATIC int RaRsMrReg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     589              : {
     590            1 :     union OpMrRegData *regMrData = (union OpMrRegData *)(inBuf + sizeof(struct MsgHead));
     591            1 :     struct RdmaMrRegInfo mrRegInfo = {0};
     592              : 
     593              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpMrRegData), sizeof(struct MsgHead), rcvBufLen, opResult);
     594              : 
     595            1 :     mrRegInfo.addr = regMrData->txData.mrRegAttr.addr;
     596            1 :     mrRegInfo.len = regMrData->txData.mrRegAttr.len;
     597            1 :     mrRegInfo.access = regMrData->txData.mrRegAttr.access;
     598            1 :     *opResult = gRaRsOps.mrReg(regMrData->txData.phyId, regMrData->txData.rdevIndex, regMrData->txData.qpn, &mrRegInfo);
     599            1 :     if (*opResult != 0) {
     600            0 :         hccp_err("reg_mr failed ret[%d].", *opResult);
     601            0 :         return 0;
     602              :     }
     603              : 
     604            1 :     regMrData = (union OpMrRegData *)(outBuf + sizeof(struct MsgHead));
     605            1 :     regMrData->rxData.lkey = mrRegInfo.lkey;
     606            1 :     regMrData->rxData.rkey = mrRegInfo.rkey;
     607              : 
     608            1 :     return 0;
     609              : }
     610              : 
     611            1 : STATIC int RaRsMrDereg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     612              : {
     613            1 :     union OpMrDeregData *mrDeregData = (union OpMrDeregData *)(inBuf + sizeof(struct MsgHead));
     614              : 
     615              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpMrDeregData), sizeof(struct MsgHead), rcvBufLen, opResult);
     616              : 
     617            1 :     *opResult = gRaRsOps.mrDereg(mrDeregData->txData.phyId, mrDeregData->txData.rdevIndex, mrDeregData->txData.qpn,
     618              :         mrDeregData->txData.addr);
     619            1 :     if (*opResult != 0) {
     620            0 :         hccp_err("dereg_mr failed ret[%d].", *opResult);
     621              :     }
     622              : 
     623            1 :     return 0;
     624              : }
     625              : 
     626            2 : STATIC int RaRsTypicalMrRegV1(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     627              : {
     628            2 :     union OpTypicalMrRegData *regMrData = (union OpTypicalMrRegData *)(inBuf + sizeof(struct MsgHead));
     629            2 :     struct RdmaMrRegInfo mrRegInfo = {0};
     630            2 :     struct ibv_mr *raRsMrHandle = NULL;
     631              : 
     632              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalMrRegData), sizeof(struct MsgHead), rcvBufLen, opResult);
     633              : 
     634            2 :     mrRegInfo.addr = regMrData->txData.mrRegAttr.addr;
     635            2 :     mrRegInfo.len = regMrData->txData.mrRegAttr.len;
     636            2 :     mrRegInfo.access = regMrData->txData.mrRegAttr.access;
     637            2 :     *opResult = gRaRsOps.registerMr(regMrData->txData.phyId, regMrData->txData.rdevIndex, &mrRegInfo,
     638              :         (void **)&raRsMrHandle);
     639            2 :     if (*opResult != 0) {
     640            0 :         hccp_err("reg_mr failed ret[%d].", *opResult);
     641            0 :         return 0;
     642              :     }
     643              : 
     644            2 :     regMrData = (union OpTypicalMrRegData *)(outBuf + sizeof(struct MsgHead));
     645            2 :     regMrData->rxData.lkey = mrRegInfo.lkey;
     646            2 :     regMrData->rxData.rkey = mrRegInfo.rkey;
     647              : 
     648            2 :     return 0;
     649              : }
     650              : 
     651            2 : STATIC int RaRsTypicalMrReg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     652              : {
     653            2 :     union OpTypicalMrRegData *regMrData = (union OpTypicalMrRegData *)(inBuf + sizeof(struct MsgHead));
     654            2 :     struct RdmaMrRegInfo mrRegInfo = {0};
     655            2 :     struct ibv_mr *raRsMrHandle = NULL;
     656              : 
     657              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalMrRegData), sizeof(struct MsgHead), rcvBufLen, opResult);
     658              : 
     659            2 :     mrRegInfo.addr = regMrData->txData.mrRegAttr.addr;
     660            2 :     mrRegInfo.len = regMrData->txData.mrRegAttr.len;
     661            2 :     mrRegInfo.access = regMrData->txData.mrRegAttr.access;
     662            2 :     *opResult = gRaRsOps.typicalRegisterMr(regMrData->txData.phyId, regMrData->txData.rdevIndex, &mrRegInfo,
     663              :         (void **)&raRsMrHandle);
     664            2 :     if (*opResult != 0) {
     665            0 :         hccp_err("reg_mr failed ret[%d].", *opResult);
     666            0 :         return 0;
     667              :     }
     668              : 
     669            2 :     regMrData = (union OpTypicalMrRegData *)(outBuf + sizeof(struct MsgHead));
     670            2 :     regMrData->rxData.lkey = mrRegInfo.lkey;
     671            2 :     regMrData->rxData.rkey = mrRegInfo.rkey;
     672            2 :     regMrData->rxData.addr = (uint64_t)(uintptr_t)raRsMrHandle;
     673              : 
     674            2 :     return 0;
     675              : }
     676              : 
     677            2 : STATIC int RaRsRemapMr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     678              : {
     679            2 :     union OpRemapMrData *opData = (union OpRemapMrData *)(inBuf + sizeof(struct MsgHead));
     680              : 
     681              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpRemapMrData), sizeof(struct MsgHead), rcvBufLen, opResult);
     682              :     HCCP_CHECK_PARAM_LEN_RET_HOST(opData->txData.memNum, 0, REMAP_MR_MAX_NUM, opResult);
     683              : 
     684            2 :     *opResult = gRaRsOps.remapMr(opData->txData.phyId, opData->txData.rdevIndex, opData->txData.memList,
     685              :         opData->txData.memNum);
     686            2 :     if (*opResult) {
     687            1 :         hccp_err("remap_mr failed ret[%d]", *opResult);
     688              :     }
     689            2 :     return 0;
     690              : }
     691              : 
     692            3 : STATIC int RaRsTypicalMrDereg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     693              : {
     694            3 :     union OpTypicalMrDeregData *mrDeregData = (union OpTypicalMrDeregData *)(inBuf + sizeof(struct MsgHead));
     695              : 
     696              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpTypicalMrDeregData), sizeof(struct MsgHead), rcvBufLen, opResult);
     697              : 
     698            6 :     *opResult = gRaRsOps.typicalDeregisterMr(mrDeregData->txData.phyId, mrDeregData->txData.rdevIndex,
     699            3 :         mrDeregData->txData.addr);
     700            3 :     if (*opResult != 0) {
     701            0 :         hccp_err("dereg_mr failed ret[%d].", *opResult);
     702              :     }
     703              : 
     704            3 :     return 0;
     705              : }
     706              : 
     707            1 : STATIC int RaRsSendWr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     708              : {
     709              :     int ret;
     710              : 
     711            1 :     struct SendWrRsp wrRsp = {0};
     712            1 :     union OpSendWrData *sendWrData = (union OpSendWrData *)(inBuf + sizeof(struct MsgHead));
     713            1 :     struct SendWr sWr = {0};
     714              : 
     715              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrData), sizeof(struct MsgHead), rcvBufLen, opResult);
     716              : 
     717            1 :     sWr.bufNum = sendWrData->txData.bufNum;
     718            1 :     sWr.bufList = (struct SgList *)&sendWrData->txData.memList[0];
     719            1 :     sWr.dstAddr = sendWrData->txData.dstAddr;
     720            1 :     sWr.op = sendWrData->txData.op;
     721            1 :     sWr.sendFlag = sendWrData->txData.sendFlags;
     722              : 
     723            1 :     ret = gRaRsOps.sendWr(sendWrData->txData.phyId, sendWrData->txData.rdevIndex, sendWrData->txData.qpn, &sWr, &wrRsp);
     724            1 :     *opResult = ret;
     725            1 :     if (ret) {
     726            0 :         if (ret == -ENOENT) {
     727            0 :             hccp_warn("not found remote mr_info, need try again");
     728              :         } else {
     729            0 :             hccp_err("send wr failed ret[%d].", ret);
     730              :         }
     731              :     }
     732              : 
     733            1 :     sendWrData = (union OpSendWrData *)(outBuf + sizeof(struct MsgHead));
     734            1 :     sendWrData->rxData.wrRsp = wrRsp;
     735              : 
     736            1 :     return 0;
     737              : }
     738              : 
     739            4 : STATIC int RaRsSendWrList(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     740              : {
     741              :     int ret;
     742              :     uint32_t i;
     743            4 :     unsigned int completeNum = 0;
     744            4 :     struct SendWrRsp *wrRsp = NULL;
     745            4 :     struct WrInfo *wrList = NULL;
     746            4 :     struct RsWrlistBaseInfo baseInfo = {0};
     747            4 :     union OpSendWrlistData *sendWrlist = (union OpSendWrlistData *)(inBuf + sizeof(struct MsgHead));
     748              : 
     749              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
     750              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
     751              : 
     752            4 :     wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
     753            4 :     CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
     754              : 
     755            4 :     wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
     756            4 :     if (wrList == NULL) {
     757            0 :         hccp_err("wr_list calloc failed.");
     758            0 :         ret = -ENOMEM;
     759            0 :         goto alloc_wr_list_fail;
     760              :     }
     761              : 
     762            4 :     baseInfo.phyId = sendWrlist->txData.phyId;
     763            4 :     baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
     764            4 :     baseInfo.qpn = sendWrlist->txData.qpn;
     765            4 :     baseInfo.keyFlag = 0;
     766              : 
     767            4 :     for (i = 0; i < sendWrlist->txData.sendNum; i++) {
     768            0 :         wrList[i].op = sendWrlist->txData.wrlist[i].op;
     769            0 :         wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
     770            0 :         wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
     771            0 :         wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
     772            0 :         wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
     773            0 :         wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
     774              :     }
     775            4 :     ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
     776            4 :     *opResult = ret;
     777            4 :     if (ret) {
     778            2 :         if (ret == -ENOENT) {
     779            1 :             hccp_warn("not found remote mr_info, need try again");
     780              :         } else {
     781            1 :             hccp_err("send wr failed ret[%d].", ret);
     782              :         }
     783              :     }
     784            4 :     sendWrlist = (union OpSendWrlistData *)(outBuf + sizeof(struct MsgHead));
     785            4 :     sendWrlist->rxData.completeNum = completeNum;
     786            4 :     ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM_V1, wrRsp,
     787              :         completeNum * sizeof(struct SendWrRsp));
     788            4 :     if (ret) {
     789            1 :         hccp_err("ra_rs_send_wr_list memcpy_s failed, ret[%d]. ", ret);
     790            1 :         ret = -ESAFEFUNC;
     791            1 :         goto copy_wr_rsp_fail;
     792              :     }
     793              : 
     794            3 : copy_wr_rsp_fail:
     795            4 :     free(wrList);
     796            4 :     wrList = NULL;
     797              : 
     798            4 : alloc_wr_list_fail:
     799            4 :     free(wrRsp);
     800            4 :     wrRsp = NULL;
     801            4 :     return 0;
     802              : }
     803              : 
     804            1 : STATIC void GetWrListV2(struct WrInfo *wrList, union OpSendWrlistDataV2 *sendWrlist)
     805              : {
     806              :     uint32_t i;
     807            1 :     for (i = 0; i < sendWrlist->txData.sendNum; i++) {
     808            0 :         wrList[i].op = sendWrlist->txData.wrlist[i].op;
     809            0 :         wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
     810            0 :         wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
     811            0 :         wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
     812            0 :         wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
     813            0 :         wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
     814              :     }
     815            1 :     return;
     816              : }
     817              : 
     818            1 : STATIC int RaRsSendWrListV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     819              : {
     820              :     int ret;
     821            1 :     unsigned int completeNum = 0;
     822            1 :     struct WrInfo *wrList = NULL;
     823            1 :     struct SendWrRsp *wrRsp = NULL;
     824            1 :     struct RsWrlistBaseInfo baseInfo = {0};
     825            1 :     union OpSendWrlistDataV2 *sendWrlist = (union OpSendWrlistDataV2 *)(inBuf + sizeof(struct MsgHead));
     826              : 
     827              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistDataV2), sizeof(struct MsgHead), rcvBufLen, opResult);
     828              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
     829              : 
     830            1 :     wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
     831            1 :     CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
     832              : 
     833            1 :     wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
     834            1 :     if (wrList == NULL) {
     835            0 :         hccp_err("wr_list calloc failed.");
     836            0 :         ret = -ENOMEM;
     837            0 :         goto alloc_wr_list_fail;
     838              :     }
     839              : 
     840            1 :     baseInfo.phyId = sendWrlist->txData.phyId;
     841            1 :     baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
     842            1 :     baseInfo.qpn = sendWrlist->txData.qpn;
     843            1 :     baseInfo.keyFlag = 0;
     844              : 
     845            1 :     GetWrListV2(wrList, sendWrlist);
     846            1 :     ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
     847            1 :     *opResult = ret;
     848            1 :     if (ret) {
     849            0 :         if (ret == -ENOENT) {
     850            0 :             hccp_warn("not found remote mr_info, need try again");
     851              :         } else {
     852            0 :             hccp_err("send wr failed ret[%d].", ret);
     853              :         }
     854              :     }
     855            1 :     sendWrlist = (union OpSendWrlistDataV2 *)(outBuf + sizeof(struct MsgHead));
     856            1 :     sendWrlist->rxData.completeNum = completeNum;
     857            1 :     ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM, wrRsp,
     858              :         completeNum * sizeof(struct SendWrRsp));
     859            1 :     if (ret) {
     860            1 :         hccp_err("ra_rs_send_wr_list memcpy_s failed, ret[%d]. ", ret);
     861            1 :         ret = -ESAFEFUNC;
     862            1 :         goto copy_wr_rsp_fail;
     863              :     }
     864              : 
     865            0 : copy_wr_rsp_fail:
     866            1 :     free(wrList);
     867            1 :     wrList = NULL;
     868              : 
     869            1 : alloc_wr_list_fail:
     870            1 :     free(wrRsp);
     871            1 :     wrRsp = NULL;
     872            1 :     return 0;
     873              : }
     874              : 
     875            1 : STATIC void GetWrList(struct WrInfo *wrList, union OpSendWrlistDataExt *sendWrlist)
     876              : {
     877              :     uint32_t i;
     878            1 :     for (i = 0; i < sendWrlist->txData.sendNum; i++) {
     879            0 :         wrList[i].op = sendWrlist->txData.wrlist[i].op;
     880            0 :         wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
     881            0 :         wrList[i].immData = sendWrlist->txData.wrlist[i].ext.immData;
     882            0 :         wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
     883            0 :         wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
     884            0 :         wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
     885            0 :         wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
     886            0 :         wrList[i].aux.dataType = sendWrlist->txData.wrlist[i].aux.dataType;
     887            0 :         wrList[i].aux.reduceType = sendWrlist->txData.wrlist[i].aux.reduceType;
     888            0 :         wrList[i].aux.notifyOffset = sendWrlist->txData.wrlist[i].aux.notifyOffset;
     889              :     }
     890            1 :     return;
     891              : }
     892              : 
     893            1 : STATIC int RaRsSendWrListExt(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     894              : {
     895              :     int ret;
     896            1 :     unsigned int completeNum = 0;
     897            1 :     struct SendWrRsp *wrRsp = NULL;
     898            1 :     struct WrInfo *wrList = NULL;
     899            1 :     struct RsWrlistBaseInfo baseInfo = {0};
     900            1 :     union OpSendWrlistDataExt *sendWrlist = (union OpSendWrlistDataExt *)(inBuf + sizeof(struct MsgHead));
     901              : 
     902              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistDataExt), sizeof(struct MsgHead), rcvBufLen, opResult);
     903              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
     904              : 
     905            1 :     wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
     906            1 :     CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
     907              : 
     908            1 :     wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
     909            1 :     if (wrList == NULL) {
     910            0 :         hccp_err("wr_list calloc failed.");
     911            0 :         ret = -ENOMEM;
     912            0 :         goto alloc_wr_list_fail;
     913              :     }
     914              : 
     915            1 :     baseInfo.phyId = sendWrlist->txData.phyId;
     916            1 :     baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
     917            1 :     baseInfo.qpn = sendWrlist->txData.qpn;
     918            1 :     baseInfo.keyFlag = 0;
     919            1 :     GetWrList(wrList, sendWrlist);
     920            1 :     ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
     921            1 :     *opResult = ret;
     922            1 :     if (ret) {
     923            0 :         if (ret == -ENOENT) {
     924            0 :             hccp_warn("not found remote mr_info, need try again");
     925              :         } else {
     926            0 :             hccp_err("send wr failed ret[%d].", ret);
     927              :         }
     928              :     }
     929            1 :     sendWrlist = (union OpSendWrlistDataExt *)(outBuf + sizeof(struct MsgHead));
     930            1 :     sendWrlist->rxData.completeNum = completeNum;
     931            1 :     ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM_V1, wrRsp,
     932              :         completeNum * sizeof(struct SendWrRsp));
     933            1 :     if (ret) {
     934            1 :         hccp_err("ra_rs_send_wr_list_ext memcpy_s failed, ret[%d]. ", ret);
     935            1 :         ret = -ESAFEFUNC;
     936            1 :         goto copy_wr_rsp_fail;
     937              :     }
     938              : 
     939            0 : copy_wr_rsp_fail:
     940            1 :     free(wrList);
     941            1 :     wrList = NULL;
     942              : 
     943            1 : alloc_wr_list_fail:
     944            1 :     free(wrRsp);
     945            1 :     wrRsp = NULL;
     946            1 :     return 0;
     947              : }
     948              : 
     949            1 : STATIC void GetWrListExtV2(struct WrInfo *wrList, union OpSendWrlistDataExtV2 *sendWrlist)
     950              : {
     951              :     uint32_t i;
     952            1 :     for (i = 0; i < sendWrlist->txData.sendNum; i++) {
     953            0 :         wrList[i].op = sendWrlist->txData.wrlist[i].op;
     954            0 :         wrList[i].sendFlags = sendWrlist->txData.wrlist[i].sendFlags;
     955            0 :         wrList[i].immData = sendWrlist->txData.wrlist[i].ext.immData;
     956            0 :         wrList[i].dstAddr = sendWrlist->txData.wrlist[i].dstAddr;
     957            0 :         wrList[i].memList.addr = sendWrlist->txData.wrlist[i].memList.addr;
     958            0 :         wrList[i].memList.len = sendWrlist->txData.wrlist[i].memList.len;
     959            0 :         wrList[i].memList.lkey = sendWrlist->txData.wrlist[i].memList.lkey;
     960            0 :         wrList[i].aux.dataType = sendWrlist->txData.wrlist[i].aux.dataType;
     961            0 :         wrList[i].aux.reduceType = sendWrlist->txData.wrlist[i].aux.reduceType;
     962            0 :         wrList[i].aux.notifyOffset = sendWrlist->txData.wrlist[i].aux.notifyOffset;
     963              :     }
     964            1 :     return;
     965              : }
     966              : 
     967            1 : STATIC int RaRsSendWrListExtV2(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
     968              : {
     969              :     int ret;
     970            1 :     unsigned int completeNum = 0;
     971            1 :     struct WrInfo *wrList = NULL;
     972            1 :     struct SendWrRsp *wrRsp = NULL;
     973            1 :     struct RsWrlistBaseInfo baseInfo = {0};
     974            1 :     union OpSendWrlistDataExtV2 *sendWrlist = (union OpSendWrlistDataExtV2 *)(inBuf + sizeof(struct MsgHead));
     975              : 
     976              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendWrlistDataExtV2), sizeof(struct MsgHead), rcvBufLen, opResult);
     977              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
     978              : 
     979            1 :     wrRsp = calloc(sendWrlist->txData.sendNum, sizeof(struct SendWrRsp));
     980            1 :     CHK_PRT_RETURN(wrRsp == NULL, hccp_err("wr_rsp calloc failed."), -ENOMEM);
     981              : 
     982            1 :     wrList = calloc(sendWrlist->txData.sendNum, sizeof(struct WrInfo));
     983            1 :     if (wrList == NULL) {
     984            0 :         hccp_err("wr_list calloc failed.");
     985            0 :         ret = -ENOMEM;
     986            0 :         goto alloc_wr_list_fail;
     987              :     }
     988              : 
     989            1 :     baseInfo.phyId = sendWrlist->txData.phyId;
     990            1 :     baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
     991            1 :     baseInfo.qpn = sendWrlist->txData.qpn;
     992            1 :     baseInfo.keyFlag = 0;
     993            1 :     GetWrListExtV2(wrList, sendWrlist);
     994            1 :     ret = gRaRsOps.sendWrList(baseInfo, wrList, sendWrlist->txData.sendNum, wrRsp, &completeNum);
     995            1 :     *opResult = ret;
     996            1 :     if (ret) {
     997            0 :         if (ret == -ENOENT) {
     998            0 :             hccp_warn("not found remote mr_info, need try again");
     999              :         } else {
    1000            0 :             hccp_err("send wr failed ret[%d].", ret);
    1001              :         }
    1002              :     }
    1003            1 :     sendWrlist = (union OpSendWrlistDataExtV2 *)(outBuf + sizeof(struct MsgHead));
    1004            1 :     sendWrlist->rxData.completeNum = completeNum;
    1005            1 :     ret = memcpy_s(sendWrlist->rxData.wrRsp, sizeof(struct SendWrRsp) * MAX_WR_NUM, wrRsp,
    1006              :         completeNum * sizeof(struct SendWrRsp));
    1007            1 :     if (ret) {
    1008            1 :         hccp_err("ra_rs_send_wr_list_ext_v2 memcpy_s failed, ret[%d]. ", ret);
    1009            1 :         ret = -ESAFEFUNC;
    1010            1 :         goto copy_wr_rsp_fail;
    1011              :     }
    1012              : 
    1013            0 : copy_wr_rsp_fail:
    1014            1 :     free(wrList);
    1015            1 :     wrList = NULL;
    1016              : 
    1017            1 : alloc_wr_list_fail:
    1018            1 :     free(wrRsp);
    1019            1 :     wrRsp = NULL;
    1020            1 :     return 0;
    1021              : }
    1022              : 
    1023            0 : STATIC int RaRsSendNormalWrlist(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1024              : {
    1025            0 :     union OpSendNormalWrlistData *sendWrlistOut = (union OpSendNormalWrlistData *)(outBuf + sizeof(struct MsgHead));
    1026            0 :     union OpSendNormalWrlistData *sendWrlist = (union OpSendNormalWrlistData *)(inBuf + sizeof(struct MsgHead));
    1027            0 :     struct RsWrlistBaseInfo baseInfo = {0};
    1028              : 
    1029              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSendNormalWrlistData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1030              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sendWrlist->txData.sendNum, 0, MAX_WR_NUM, opResult);
    1031              : 
    1032            0 :     baseInfo.phyId = sendWrlist->txData.phyId;
    1033            0 :     baseInfo.rdevIndex = sendWrlist->txData.rdevIndex;
    1034            0 :     baseInfo.qpn = sendWrlist->txData.qpn;
    1035            0 :     baseInfo.keyFlag = 1;
    1036              : 
    1037            0 :     *opResult = gRaRsOps.sendWrList(baseInfo, sendWrlist->txData.wrlist, sendWrlist->txData.sendNum,
    1038            0 :         sendWrlistOut->rxData.wrRsp, &sendWrlistOut->rxData.completeNum);
    1039            0 :     if (*opResult != 0) {
    1040            0 :         hccp_err("send_wr_list failed ret[%d].", *opResult);
    1041              :     }
    1042            0 :     return 0;
    1043              : }
    1044              : 
    1045            1 : STATIC int RaRsGetNotifyBa(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1046              : {
    1047            1 :     union OpGetNotifyBaData *getNotifyBaData = (union OpGetNotifyBaData *)(inBuf + sizeof(struct MsgHead));
    1048            1 :     struct MrInfoT info = {0};
    1049              : 
    1050              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetNotifyBaData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1051              : 
    1052            1 :     *opResult = gRaRsOps.getNotifyMrInfo(getNotifyBaData->txData.phyId, getNotifyBaData->txData.rdevIndex, &info);
    1053            1 :     if (*opResult != 0) {
    1054            0 :         hccp_err("reg_notify_mr failed ret[%d].", *opResult);
    1055            0 :         return 0;
    1056              :     }
    1057              : 
    1058            1 :     getNotifyBaData = (union OpGetNotifyBaData *)(outBuf + sizeof(struct MsgHead));
    1059            1 :     getNotifyBaData->rxData.va = (unsigned long long)(uintptr_t)info.addr;
    1060            1 :     getNotifyBaData->rxData.size = info.size;
    1061            1 :     getNotifyBaData->rxData.access = info.access;
    1062            1 :     getNotifyBaData->rxData.lkey = info.lkey;
    1063              : 
    1064            1 :     return 0;
    1065              : }
    1066              : 
    1067            0 : STATIC int RaRsNotifyCfgSet(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1068              : {
    1069            0 :     union OpNotifyCfgSetData *setNotifyBaData = (union OpNotifyCfgSetData *)(inBuf + sizeof(struct MsgHead));
    1070              : 
    1071              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpNotifyCfgSetData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1072              : 
    1073            0 :     *opResult = gRaRsOps.notifyCfgSet(setNotifyBaData->txData.phyId, setNotifyBaData->txData.va,
    1074              :         setNotifyBaData->txData.size);
    1075            0 :     if (*opResult != 0) {
    1076            0 :         hccp_err("notify_cfg_set failed ret[%d].", *opResult);
    1077              :     }
    1078              : 
    1079            0 :     return 0;
    1080              : }
    1081              : 
    1082            0 : STATIC int RaRsNotifyCfgGet(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1083              : {
    1084            0 :     unsigned long long va = 0;
    1085            0 :     unsigned long long size = 0;
    1086            0 :     union OpNotifyCfgGetData *getNotifyBaData = (union OpNotifyCfgGetData *)(inBuf + sizeof(struct MsgHead));
    1087              : 
    1088              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpNotifyCfgGetData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1089              : 
    1090            0 :     *opResult = gRaRsOps.notifyCfgGet(getNotifyBaData->txData.phyId, &va, &size);
    1091            0 :     if (*opResult != 0) {
    1092            0 :         hccp_err("notify_cfg_set failed ret[%d].", *opResult);
    1093            0 :         return 0;
    1094              :     }
    1095              : 
    1096            0 :     getNotifyBaData = (union OpNotifyCfgGetData *)(outBuf + sizeof(struct MsgHead));
    1097            0 :     getNotifyBaData->rxData.va = va;
    1098            0 :     getNotifyBaData->rxData.size = size;
    1099            0 :     return 0;
    1100              : }
    1101              : 
    1102            1 : STATIC int RaSetPid(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1103              : {
    1104            1 :     union OpSetPidData *setPidData = (union OpSetPidData *)(inBuf + sizeof(struct MsgHead));
    1105              : 
    1106              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetPidData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1107              : 
    1108            1 :     hccp_info("ra get pid is [%d]", setPidData->txData.pid);
    1109              : 
    1110            1 :     *opResult = gRaRsOps.setHostPid(setPidData->txData.phyId, setPidData->txData.pid, setPidData->txData.pidSign);
    1111              : 
    1112            1 :     hccp_info("ra_set_pid finish");
    1113            1 :     return 0;
    1114              : }
    1115              : 
    1116          117 : STATIC int RaRsCloseHdcSession(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1117              : {
    1118          117 :     *opResult = 0;
    1119          117 :     hccp_info("ra_rs_close_hdc_session finish");
    1120          117 :     return 0;
    1121              : }
    1122              : 
    1123            2 : STATIC int RaRsGetInterfaceVersion(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1124              : {
    1125            2 :     unsigned int version = 0;
    1126            2 :     union OpGetVersionData *versionInfoRet = NULL;
    1127            2 :     union OpGetVersionData *versionInfo = (union OpGetVersionData *)(inBuf + sizeof(struct MsgHead));
    1128              : 
    1129              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetVersionData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1130              : 
    1131            2 :     *opResult = gRaRsOps.getInterfaceVersion(versionInfo->txData.opcode, &version);
    1132            2 :     if (*opResult != 0) {
    1133            1 :         hccp_err("get_interface_version failed, opcode %d, ret %d", versionInfo->txData.opcode, *opResult);
    1134            1 :         return 0;
    1135              :     }
    1136              : 
    1137            1 :     versionInfoRet = (union OpGetVersionData *)(outBuf + sizeof(struct MsgHead));
    1138            1 :     versionInfoRet->rxData.version = version;
    1139            1 :     return 0;
    1140              : }
    1141              : 
    1142            0 : STATIC int RaRsSetQpAttrQos(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1143              : {
    1144            0 :     union OpSetQpAttrQosData *attrQosData = (union OpSetQpAttrQosData *)(inBuf + sizeof(struct MsgHead));
    1145              : 
    1146              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetQpAttrQosData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1147              : 
    1148            0 :     *opResult = gRaRsOps.setQpAttrQos(attrQosData->txData.phyId, attrQosData->txData.rdevIndex, attrQosData->txData.qpn,
    1149              :         &(attrQosData->txData.qosAttr));
    1150            0 :     if (*opResult != 0) {
    1151            0 :         hccp_err("set_qp_attr_qos failed ret[%d].", *opResult);
    1152              :     }
    1153              : 
    1154            0 :     return 0;
    1155              : }
    1156              : 
    1157            0 : STATIC int RaRsSetQpAttrTimeout(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1158              : {
    1159            0 :     union OpSetQpAttrTimeoutData *attrTimeData = (union OpSetQpAttrTimeoutData *)(inBuf + sizeof(struct MsgHead));
    1160              : 
    1161              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetQpAttrTimeoutData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1162              : 
    1163            0 :     *opResult = gRaRsOps.setQpAttrTimeout(attrTimeData->txData.phyId, attrTimeData->txData.rdevIndex,
    1164              :         attrTimeData->txData.qpn, &(attrTimeData->txData.timeout));
    1165            0 :     if (*opResult != 0) {
    1166            0 :         hccp_err("set_qp_attr_timeout failed ret[%d].", *opResult);
    1167              :     }
    1168              : 
    1169            0 :     return 0;
    1170              : }
    1171              : 
    1172            0 : STATIC int RaRsSetQpAttrRetryCnt(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1173              : {
    1174            0 :     union OpSetQpAttrRetryCntData *attrRetryCntData = (union OpSetQpAttrRetryCntData *)(inBuf + sizeof(struct MsgHead));
    1175              : 
    1176              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpSetQpAttrRetryCntData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1177              : 
    1178            0 :     *opResult = gRaRsOps.setQpAttrRetryCnt(attrRetryCntData->txData.phyId, attrRetryCntData->txData.rdevIndex,
    1179              :         attrRetryCntData->txData.qpn, &(attrRetryCntData->txData.retryCnt));
    1180            0 :     if (*opResult != 0) {
    1181            0 :         hccp_err("set_qp_attr_retry_cnt failed ret[%d].", *opResult);
    1182              :     }
    1183              : 
    1184            0 :     return 0;
    1185              : }
    1186              : 
    1187            0 : STATIC int RaRsGetCqeErrInfo(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1188              : {
    1189              :     int ret;
    1190            0 :     struct CqeErrInfo info = {0};
    1191            0 :     union OpGetCqeErrInfoData *cqeErrInfoRet = NULL;
    1192              : 
    1193              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetCqeErrInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1194              : 
    1195            0 :     *opResult = gRaRsOps.getCqeErrInfo(&info);
    1196            0 :     if (*opResult != 0) {
    1197            0 :         hccp_err("get_cqe_err_info failed, ret %d", *opResult);
    1198            0 :         return 0;
    1199              :     }
    1200              : 
    1201            0 :     cqeErrInfoRet = (union OpGetCqeErrInfoData *)(outBuf + sizeof(struct MsgHead));
    1202            0 :     ret = memcpy_s(&cqeErrInfoRet->rxData.info, sizeof(struct CqeErrInfo), &info, sizeof(struct CqeErrInfo));
    1203            0 :     CHK_PRT_RETURN(ret, hccp_err("ra_rs_get_cqe_err_info memcpy_s failed, ret[%d]. ", ret), -ESAFEFUNC);
    1204            0 :     return 0;
    1205              : }
    1206              : 
    1207            0 : STATIC int RaRsGetLiteSupport(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1208              : {
    1209            0 :     union OpLiteSupportData *liteSupportData = (union OpLiteSupportData *)(inBuf + sizeof(struct MsgHead));
    1210            0 :     union OpLiteSupportData *liteSupportOut = (union OpLiteSupportData *)(outBuf + sizeof(struct MsgHead));
    1211              : 
    1212              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteSupportData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1213              : 
    1214            0 :     *opResult = gRaRsOps.getLiteSupport(liteSupportData->txData.phyId, liteSupportData->txData.rdevIndex,
    1215              :         &liteSupportOut->rxData.supportLite);
    1216            0 :     if (*opResult != 0) {
    1217            0 :         hccp_err("get_lite_support failed ret[%d].", *opResult);
    1218              :     }
    1219              : 
    1220            0 :     return 0;
    1221              : }
    1222              : 
    1223            0 : STATIC int RaRsGetLiteRdevCap(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1224              : {
    1225            0 :     union OpLiteRdevCapData *liteRdevCapData = (union OpLiteRdevCapData *)(inBuf + sizeof(struct MsgHead));
    1226            0 :     union OpLiteRdevCapData *liteRdevCapOut = (union OpLiteRdevCapData *)(outBuf + sizeof(struct MsgHead));
    1227              : 
    1228              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteRdevCapData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1229              : 
    1230            0 :     *opResult = gRaRsOps.getLiteRdevCap(liteRdevCapData->txData.phyId, liteRdevCapData->txData.rdevIndex,
    1231              :         (void *)&liteRdevCapOut->rxData.resp);
    1232            0 :     if (*opResult != 0) {
    1233            0 :         hccp_err("get_lite_rdev_cap failed ret[%d].", *opResult);
    1234              :     }
    1235              : 
    1236            0 :     return 0;
    1237              : }
    1238              : 
    1239            0 : STATIC int RaRsGetLiteQpCqAttr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1240              : {
    1241            0 :     union OpLiteQpCqAttrData *liteQpCqAttrData = (union OpLiteQpCqAttrData *)(inBuf + sizeof(struct MsgHead));
    1242            0 :     union OpLiteQpCqAttrData *liteQpCqAttrOut = (union OpLiteQpCqAttrData *)(outBuf + sizeof(struct MsgHead));
    1243              : 
    1244              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteQpCqAttrData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1245              : 
    1246            0 :     *opResult = gRaRsOps.getLiteQpCqAttr(liteQpCqAttrData->txData.phyId, liteQpCqAttrData->txData.rdevIndex,
    1247              :         liteQpCqAttrData->txData.qpn, (void *)&liteQpCqAttrOut->rxData.resp);
    1248            0 :     if (*opResult != 0) {
    1249            0 :         hccp_err("get_lite_qp_cq_attr failed ret[%d].", *opResult);
    1250              :     }
    1251              : 
    1252            0 :     return 0;
    1253              : }
    1254              : 
    1255            0 : STATIC int RaRsGetLiteConnectedInfo(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1256              : {
    1257            0 :     union OpLiteConnectedInfoData *liteConnectedInfoData = (union OpLiteConnectedInfoData *)(inBuf +
    1258              :                                                                                              sizeof(struct MsgHead));
    1259            0 :     union OpLiteConnectedInfoData *liteConnectedInfoOut = (union OpLiteConnectedInfoData *)(outBuf +
    1260              :                                                                                             sizeof(struct MsgHead));
    1261              : 
    1262              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteConnectedInfoData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1263              : 
    1264            0 :     *opResult = gRaRsOps.getLiteConnectedInfo(liteConnectedInfoData->txData.phyId,
    1265              :         liteConnectedInfoData->txData.rdevIndex, liteConnectedInfoData->txData.qpn,
    1266              :         (void *)&liteConnectedInfoOut->rxData.resp);
    1267            0 :     if (*opResult != 0) {
    1268            0 :         hccp_err("get_lite_connected_info failed ret[%d].", *opResult);
    1269              :     }
    1270              : 
    1271            0 :     return 0;
    1272              : }
    1273              : 
    1274            0 : STATIC int RaRsGetLiteMemAttr(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1275              : {
    1276            0 :     union OpLiteMemAttrData *liteMemAttrData = (union OpLiteMemAttrData *)(inBuf + sizeof(struct MsgHead));
    1277            0 :     union OpLiteMemAttrData *liteMemAttrOut = (union OpLiteMemAttrData *)(outBuf + sizeof(struct MsgHead));
    1278              : 
    1279              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpLiteMemAttrData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1280              : 
    1281            0 :     *opResult = gRaRsOps.getLiteMemAttr(liteMemAttrData->txData.phyId, liteMemAttrData->txData.rdevIndex,
    1282              :         liteMemAttrData->txData.qpn, (void *)&liteMemAttrOut->rxData.resp);
    1283            0 :     if (*opResult != 0) {
    1284            0 :         hccp_err("get_lite_mem_attr failed ret[%d].", *opResult);
    1285              :     }
    1286              : 
    1287            0 :     return 0;
    1288              : }
    1289              : 
    1290            0 : STATIC int RaRsGetCqeErrInfoNum(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1291              : {
    1292            0 :     union OpGetCqeErrInfoNumData *cqeErrInfoNum = (union OpGetCqeErrInfoNumData *)(inBuf + sizeof(struct MsgHead));
    1293              :     unsigned int num;
    1294              : 
    1295              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetCqeErrInfoNumData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1296              : 
    1297            0 :     *opResult = gRaRsOps.getCqeErrInfoNum(cqeErrInfoNum->txData.phyId, cqeErrInfoNum->txData.rdevIndex, &num);
    1298            0 :     if (*opResult != 0) {
    1299            0 :         hccp_err("get_cqe_err_info_num failed, ret %d", *opResult);
    1300            0 :         return 0;
    1301              :     }
    1302              : 
    1303            0 :     cqeErrInfoNum = (union OpGetCqeErrInfoNumData *)(outBuf + sizeof(struct MsgHead));
    1304            0 :     cqeErrInfoNum->rxData.num = num;
    1305              : 
    1306            0 :     return 0;
    1307              : }
    1308              : 
    1309            0 : STATIC int RaRsGetCqeErrInfoList(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1310              : {
    1311            0 :     union OpGetCqeErrInfoListData *cqeErrInfoList = (union OpGetCqeErrInfoListData *)(inBuf + sizeof(struct MsgHead));
    1312            0 :     union OpGetCqeErrInfoListData *cqeErrInfoListRet = (union OpGetCqeErrInfoListData *)(outBuf +
    1313              :                                                                                          sizeof(struct MsgHead));
    1314              :     unsigned int num;
    1315              : 
    1316              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetCqeErrInfoListData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1317              :     HCCP_CHECK_PARAM_LEN_RET_HOST(cqeErrInfoList->txData.num, 0, CQE_ERR_INFO_MAX_NUM, opResult);
    1318              : 
    1319            0 :     num = cqeErrInfoList->txData.num;
    1320            0 :     *opResult = gRaRsOps.getCqeErrInfoList(cqeErrInfoList->txData.phyId, cqeErrInfoList->txData.rdevIndex,
    1321            0 :         cqeErrInfoListRet->rxData.infoList, &num);
    1322            0 :     if (*opResult != 0) {
    1323            0 :         hccp_err("get_cqe_err_info_list failed, ret %d", *opResult);
    1324            0 :         return 0;
    1325              :     }
    1326              : 
    1327            0 :     cqeErrInfoListRet->rxData.num = num;
    1328              : 
    1329            0 :     return 0;
    1330              : }
    1331              : 
    1332            2 : STATIC int RaRsGetTlsEnable(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1333              : {
    1334            2 :     union OpGetTlsEnableData *opDataRet = (union OpGetTlsEnableData *)(outBuf + sizeof(struct MsgHead));
    1335            2 :     union OpGetTlsEnableData *opData = (union OpGetTlsEnableData *)(inBuf + sizeof(struct MsgHead));
    1336              : 
    1337              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetTlsEnableData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1338              : 
    1339            2 :     *opResult = gRaRsOps.getTlsEnable(opData->txData.phyId, &opDataRet->rxData.tlsEnable);
    1340            2 :     if (*opResult != 0) {
    1341            0 :         hccp_err("get_tls_enable failed, ret %d", *opResult);
    1342              :     }
    1343            2 :     return 0;
    1344              : }
    1345              : 
    1346            1 : STATIC int RaRsGetSecRandom(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1347              : {
    1348            1 :     union OpGetSecRandomData *opDataRet = (union OpGetSecRandomData *)(outBuf + sizeof(struct MsgHead));
    1349              : 
    1350              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetSecRandomData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1351              : 
    1352            1 :     *opResult = gRaRsOps.getSecRandom((int *)&opDataRet->rxData.value);
    1353            1 :     if (*opResult != 0) {
    1354            0 :         hccp_err("get sec random failed, ret %d", *opResult);
    1355              :     }
    1356            1 :     return 0;
    1357              : }
    1358              : 
    1359            1 : STATIC int RaRsGetHccnCfg(char *inBuf, char *outBuf, int *outLen, int *opResult, int rcvBufLen)
    1360              : {
    1361            1 :     union OpGetHccnCfgData *opDataRet = (union OpGetHccnCfgData *)(outBuf + sizeof(struct MsgHead));
    1362            1 :     union OpGetHccnCfgData *opData = (union OpGetHccnCfgData *)(inBuf + sizeof(struct MsgHead));
    1363              : 
    1364              :     HCCP_CHECK_PARAM_LEN_RET_HOST(sizeof(union OpGetHccnCfgData), sizeof(struct MsgHead), rcvBufLen, opResult);
    1365              : 
    1366            1 :     opDataRet->rxData.valueLen = HCCN_CFG_MSG_DATA_LEN;
    1367            1 :     *opResult = gRaRsOps.getHccnCfg(opData->txData.phyId, opData->txData.key, opDataRet->rxData.value,
    1368              :         &opDataRet->rxData.valueLen);
    1369            1 :     if (*opResult != 0) {
    1370            0 :         hccp_err("get hccn cfg failed, ret %d", *opResult);
    1371              :     }
    1372            1 :     return 0;
    1373              : }
    1374              : 
    1375              : #define US_PRE_SECOND 1000000
    1376              : #define US_PRE_MSECOND 1000
    1377              : #define MS_PRE_SECOND 1000
    1378              : 
    1379          242 : STATIC void RaTimeInterval(struct timeval *endTime, struct timeval *startTime, long *msec)
    1380              : {
    1381              :     /* if low position is sufficient, then borrow one from the high position */
    1382          242 :     if (endTime->tv_usec < startTime->tv_usec) {
    1383            0 :         endTime->tv_sec -= 1;
    1384            0 :         endTime->tv_usec += US_PRE_SECOND;
    1385              :     }
    1386              : 
    1387          242 :     *msec = (endTime->tv_sec - startTime->tv_sec) * MS_PRE_SECOND +
    1388          242 :             (endTime->tv_usec - startTime->tv_usec) / US_PRE_MSECOND;
    1389          242 : }
    1390              : 
    1391              : #define OP_TYPE_CFG 0
    1392              : #define OP_TYPE_QUERY 1
    1393              : 
    1394          242 : STATIC void RaGetOpRight(struct RaHdcOpSec *opSec, unsigned int opcode, unsigned int asyncReqId, int *right)
    1395              : {
    1396          242 :     long timeInterval = 0;
    1397              :     struct timeval tCur;
    1398              :     int exeRight;
    1399              :     int ret;
    1400              : 
    1401          242 :     ret = gettimeofday(&tCur, NULL);
    1402          242 :     if (ret) {
    1403            0 :         *right = OP_RIGHT_QUERY_ERR;
    1404            0 :         hccp_err("ra gettimeofday failed ret[%d].", ret);
    1405            0 :         return;
    1406              :     }
    1407              : 
    1408          242 :     RaTimeInterval(&tCur, &opSec->tLast, &timeInterval);
    1409          242 :     opSec->tLast = (timeInterval < 0) ? tCur : opSec->tLast;
    1410          242 :     timeInterval = (timeInterval < 0) ? 0 : timeInterval;
    1411          242 :     opSec->tLast = (timeInterval == 0) ? opSec->tLast : tCur;
    1412          242 :     opSec->tokenNum += timeInterval * TOKEN_RATE;
    1413              : 
    1414          242 :     if (opSec->tokenNum == 0) {
    1415            0 :         *right = HAVE_NOT_OP_RIGHT;
    1416            0 :         hccp_err("ra handle have not op right. opcode[%u].", opcode);
    1417            0 :         return;
    1418              :     }
    1419              : 
    1420          242 :     exeRight = HAVE_OP_RIGHT;
    1421              : 
    1422          242 :     opSec->tokenNum = opSec->tokenNum - 1;
    1423          242 :     opSec->tokenNum = (opSec->tokenNum > BUCKET_DEPTH) ? BUCKET_DEPTH : opSec->tokenNum;
    1424          242 :     if (RaIsOpcodeLogSuppressed(opSec->lastOpcode) && opSec->lastOpcode != opcode) {
    1425            2 :         hccp_dbg("lastOpcode[%u], exeRight[%d], tokenNum[%llu], cfgOpNum[%u], lastOpcodeCnt[%u]", opSec->lastOpcode,
    1426              :             exeRight, opSec->tokenNum, opSec->cfgOpNum, opSec->lastOpcodeCnt);
    1427          240 :     } else if (RaIsOpcodeLogSuppressed(opcode)) {
    1428            2 :         goto out;
    1429              :     }
    1430              : 
    1431          240 :     if (opSec->isAsyncOp) {
    1432            1 :         hccp_dbg("opcode[%u], reqId[%u], exeRight[%d], tokenNum[%llu], cfgOpNum[%u]", opcode, asyncReqId, exeRight,
    1433              :             opSec->tokenNum, opSec->cfgOpNum);
    1434              :     } else {
    1435          239 :         hccp_dbg("opcode[%u], exeRight[%d], tokenNum[%llu], cfgOpNum[%u]", opcode, exeRight, opSec->tokenNum,
    1436              :             opSec->cfgOpNum);
    1437              :     }
    1438              : 
    1439          242 : out:
    1440          488 :     opSec->lastOpcodeCnt = (opcode == opSec->lastOpcode) ? (opSec->lastOpcodeCnt + 1)
    1441          242 :                                                          : (RaIsOpcodeLogSuppressed(opcode) ? 1 : 0);
    1442          242 :     opSec->lastOpcode = opcode;
    1443          242 :     *right = exeRight;
    1444          242 :     return;
    1445              : }
    1446              : 
    1447              : struct RaOpHandle gRaOpHandle[] = {
    1448              :     {RA_RS_SOCKET_CONN, RaRsSocketBatchConnect, sizeof(union OpSocketConnectData)},
    1449              :     {RA_RS_SOCKET_CLOSE, RaRsSocketBatchClose, sizeof(union OpSocketCloseData)},
    1450              :     {RA_RS_SOCKET_ABORT, RaRsSocketBatchAbort, sizeof(union OpSocketConnectData)},
    1451              :     {RA_RS_SOCKET_LISTEN_START, RaRsSocketListenStart, sizeof(union OpSocketListenData)},
    1452              :     {RA_RS_SOCKET_LISTEN_STOP, RaRsSocketListenStop, sizeof(union OpSocketListenData)},
    1453              :     {RA_RS_GET_SOCKET, RaRsGetSockets, sizeof(union OpSocketInfoData)},
    1454              :     {RA_RS_SOCKET_SEND, RaRsSocketSend, sizeof(union OpSocketSendData)},
    1455              :     {RA_RS_SOCKET_RECV, RaRsSocketRecv, sizeof(union OpSocketRecvData)},
    1456              :     {RA_RS_QP_CREATE, RaRsQpCreate, sizeof(union OpQpCreateData)},
    1457              :     {RA_RS_QP_CREATE_WITH_ATTRS, RaRsQpCreateWithAttrs, sizeof(union OpQpCreateWithAttrsData)},
    1458              :     {RA_RS_QP_CREATE_WITH_CQ_WITH_ATTRS, RaRsQpCreateWithCQWithAttrs, sizeof(union OpQpCreateWithCQWithAttrsData)},
    1459              :     {RA_RS_AI_QP_CREATE, RaRsAiQpCreate, sizeof(union OpAiQpCreateData)},
    1460              :     {RA_RS_AI_QP_CREATE_WITH_ATTRS, RaRsAiQpCreateWithData, sizeof(union OpAiQpCreateWithAttrsData)},
    1461              :     {RA_RS_TYPICAL_QP_CREATE, RaRsTypicalQpCreate, sizeof(union OpTypicalQpCreateData)},
    1462              :     {RA_RS_TYPICAL_CQ_CREATE, RaRsTypicalCqCreate, sizeof(union OpTypicalCqCreateData)},
    1463              :     {RA_RS_TYPICAL_CQ_DESTROY, RaRsTypicalCqDestroy, sizeof(union OpTypicalCqDestroyData)},
    1464              :     {RA_RS_QP_DESTROY, RaRsQpDestroy, sizeof(union OpQpDestroyData)},
    1465              :     {RA_RS_QP_DESTROY_WITHOUT_CQ, RaRsQpDestroyWithoutCQ, sizeof(union OpQpDestroyData)},
    1466              :     {RA_RS_TYPICAL_QP_MODIFY, RaRsTypicalQpModify, sizeof(union OpTypicalQpModifyData)},
    1467              :     {RA_RS_QP_BATCH_MODIFY, RaRsQpBatchModify, sizeof(union OpQpBatchModifyData)},
    1468              :     {RA_RS_QP_CONNECT, RaRsQpConnectAsync, sizeof(union OpQpConnectData)},
    1469              :     {RA_RS_QP_STATUS, RaRsGetQpStatus, sizeof(union OpQpStatusData)},
    1470              :     {RA_RS_QP_INFO, RaRsGetQpInfo, sizeof(union OpQpInfoData)},
    1471              :     {RA_RS_MR_REG, RaRsMrReg, sizeof(union OpMrRegData)},
    1472              :     {RA_RS_MR_DEREG, RaRsMrDereg, sizeof(union OpMrDeregData)},
    1473              :     {RA_RS_TYPICAL_MR_REG_V1, RaRsTypicalMrRegV1, sizeof(union OpTypicalMrRegData)},
    1474              :     {RA_RS_TYPICAL_MR_REG, RaRsTypicalMrReg, sizeof(union OpTypicalMrRegData)},
    1475              :     {RA_RS_REMAP_MR, RaRsRemapMr, sizeof(union OpRemapMrData)},
    1476              :     {RA_RS_TYPICAL_MR_DEREG, RaRsTypicalMrDereg, sizeof(union OpTypicalMrDeregData)},
    1477              :     {RA_RS_SEND_WR, RaRsSendWr, sizeof(union OpSendWrData)},
    1478              :     {RA_RS_GET_NOTIFY_BA, RaRsGetNotifyBa, sizeof(union OpGetNotifyBaData)},
    1479              :     {RA_RS_SOCKET_INIT, RaRsSocketInit, sizeof(union OpSocketInitData)},
    1480              :     {RA_RS_SOCKET_DEINIT, RaRsSocketDeinit, sizeof(union OpSocketDeinitData)},
    1481              :     {RA_RS_RDEV_INIT, RaRsRdevInit, sizeof(union OpRdevInitData)},
    1482              :     {RA_RS_RDEV_INIT_WITH_BACKUP, RaRsRdevInitWithBackup, sizeof(union OpRdevInitWithBackupData)},
    1483              :     {RA_RS_RDEV_GET_PORT_STATUS, RaRsRdevGetPortStatus, sizeof(union OpRdevGetPortStatusData)},
    1484              :     {RA_RS_RDEV_DEINIT, RaRsRdevDeinit, sizeof(union OpRdevDeinitData)},
    1485              :     {RA_RS_WLIST_ADD, RaRsSocketWhiteListAdd, sizeof(union OpWlistData)},
    1486              :     {RA_RS_WLIST_ADD_V2, RaRsSocketWhiteListAddV2, sizeof(union OpWlistDataV2)},
    1487              :     {RA_RS_WLIST_DEL, RaRsSocketWhiteListDel, sizeof(union OpWlistData)},
    1488              :     {RA_RS_WLIST_DEL_V2, RaRsSocketWhiteListDelV2, sizeof(union OpWlistDataV2)},
    1489              :     {RA_RS_ACCEPT_CREDIT_ADD, RaRsSocketCreditAdd, sizeof(union OpAcceptCreditData)},
    1490              :     {RA_RS_GET_IFNUM, RaRsGetIfnum, sizeof(union OpIfnumData)},
    1491              :     {RA_RS_GET_IFADDRS, RaRsGetIfaddrs, sizeof(union OpIfaddrData)},
    1492              :     {RA_RS_GET_IFADDRS_V2, RaRsGetIfaddrsV2, sizeof(union OpIfaddrDataV2)},
    1493              :     {RA_RS_GET_INTERFACE_VERSION, RaRsGetInterfaceVersion, sizeof(union OpGetVersionData)},
    1494              :     {RA_RS_SEND_WRLIST, RaRsSendWrList, sizeof(union OpSendWrlistData)},
    1495              :     {RA_RS_SEND_WRLIST_V2, RaRsSendWrListV2, sizeof(union OpSendWrlistDataV2)},
    1496              :     {RA_RS_SEND_WRLIST_EXT, RaRsSendWrListExt, sizeof(union OpSendWrlistDataExt)},
    1497              :     {RA_RS_SEND_WRLIST_EXT_V2, RaRsSendWrListExtV2, sizeof(union OpSendWrlistDataExtV2)},
    1498              :     {RA_RS_SEND_NORMAL_WRLIST, RaRsSendNormalWrlist, sizeof(union OpSendNormalWrlistData)},
    1499              :     {RA_RS_SET_TSQP_DEPTH, RaRsSetTsqpDepth, sizeof(union OpSetTsqpDepthData)},
    1500              :     {RA_RS_GET_TSQP_DEPTH, RaRsGetTsqpDepth, sizeof(union OpGetTsqpDepthData)},
    1501              :     {RA_RS_HDC_SESSION_CLOSE, RaRsCloseHdcSession, sizeof(union OpSocketRecvData)},
    1502              :     {RA_RS_GET_VNIC_IP, RaRsGetVnicIp, sizeof(union OpGetVnicIpData)},
    1503              :     {RA_RS_GET_VNIC_IP_INFOS_V1, RaRsGetVnicIpInfosV1, sizeof(union OpGetVnicIpInfosDataV1)},
    1504              :     {RA_RS_GET_VNIC_IP_INFOS, RaRsGetVnicIpInfos, sizeof(union OpGetVnicIpInfosData)},
    1505              :     {RA_RS_NOTIFY_CFG_SET, RaRsNotifyCfgSet, sizeof(union OpNotifyCfgSetData)},
    1506              :     {RA_RS_NOTIFY_CFG_GET, RaRsNotifyCfgGet, sizeof(union OpNotifyCfgGetData)},
    1507              :     {RA_RS_SET_PID, RaSetPid, sizeof(union OpSetPidData)},
    1508              :     {RA_RS_SET_QP_ATTR_QOS, RaRsSetQpAttrQos, sizeof(union OpSetQpAttrQosData)},
    1509              :     {RA_RS_SET_QP_ATTR_TIMEOUT, RaRsSetQpAttrTimeout, sizeof(union OpSetQpAttrTimeoutData)},
    1510              :     {RA_RS_SET_QP_ATTR_RETRY_CNT, RaRsSetQpAttrRetryCnt, sizeof(union OpSetQpAttrRetryCntData)},
    1511              :     {RA_RS_GET_CQE_ERR_INFO, RaRsGetCqeErrInfo, sizeof(union OpGetCqeErrInfoData)},
    1512              :     {RA_RS_GET_CQE_ERR_INFO_NUM, RaRsGetCqeErrInfoNum, sizeof(union OpGetCqeErrInfoNumData)},
    1513              :     {RA_RS_GET_CQE_ERR_INFO_LIST, RaRsGetCqeErrInfoList, sizeof(union OpGetCqeErrInfoListData)},
    1514              :     {RA_RS_GET_LITE_SUPPORT, RaRsGetLiteSupport, sizeof(union OpLiteSupportData)},
    1515              :     {RA_RS_GET_LITE_RDEV_CAP, RaRsGetLiteRdevCap, sizeof(union OpLiteRdevCapData)},
    1516              :     {RA_RS_GET_LITE_QP_CQ_ATTR, RaRsGetLiteQpCqAttr, sizeof(union OpLiteQpCqAttrData)},
    1517              :     {RA_RS_GET_LITE_QP_ATTR, RaRsGetLiteQpAttr, sizeof(union OpLiteQpAttrData)},
    1518              :     {RA_RS_GET_LITE_CQ_ATTR, RaRsGetLiteCqAttr, sizeof(union OpGetLiteCqAttrData)},
    1519              :     {RA_RS_GET_LITE_CONNECTED_INFO, RaRsGetLiteConnectedInfo, sizeof(union OpLiteConnectedInfoData)},
    1520              :     {RA_RS_GET_LITE_MEM_ATTR, RaRsGetLiteMemAttr, sizeof(union OpLiteMemAttrData)},
    1521              :     {RA_RS_PING_INIT, RaRsPingInit, sizeof(union OpPingInitData)},
    1522              :     {RA_RS_PING_ADD, RaRsPingTargetAdd, sizeof(union OpPingAddData)},
    1523              :     {RA_RS_PING_START, RaRsPingTaskStart, sizeof(union OpPingStartData)},
    1524              :     {RA_RS_PING_GET_RESULTS, RaRsPingGetResults, sizeof(union OpPingResultsData)},
    1525              :     {RA_RS_PING_STOP, RaRsPingTaskStop, sizeof(union OpPingStopData)},
    1526              :     {RA_RS_PING_DEL, RaRsPingTargetDel, sizeof(union OpPingDelData)},
    1527              :     {RA_RS_PING_DEINIT, RaRsPingDeinit, sizeof(union OpPingDeinitData)},
    1528              :     {RA_RS_TLV_INIT_V1, RaRsTlvInitV1, sizeof(union OpTlvInitDataV1)},
    1529              :     {RA_RS_TLV_INIT, RaRsTlvInit, sizeof(union OpTlvInitData)},
    1530              :     {RA_RS_TLV_DEINIT, RaRsTlvDeinit, sizeof(union OpTlvDeinitData)},
    1531              :     {RA_RS_TLV_REQUEST, RaRsTlvRequest, sizeof(union OpTlvRequestData)},
    1532              :     {RA_RS_TLV_REQUEST_V2, RaRsTlvRequestV2, sizeof(union OpTlvRequestDataV2)},
    1533              :     {RA_RS_CUSTOM_CHANNEL_DEPRECATED, RaRsCustomChannel, sizeof(union OpCustomChannelData)},
    1534              :     {RA_RS_GET_TLS_ENABLE, RaRsGetTlsEnable, sizeof(union OpGetTlsEnableData)},
    1535              :     {RA_RS_GET_SEC_RANDOM, RaRsGetSecRandom, sizeof(union OpGetSecRandomData)},
    1536              :     {RA_RS_GET_HCCN_CFG, RaRsGetHccnCfg, sizeof(union OpGetHccnCfgData)},
    1537              :     {RA_RS_ASYNC_HDC_SESSION_CONNECT, RaRsAsyncHdcSessionConnect, sizeof(union OpAsyncHdcConnectData)},
    1538              :     {RA_RS_ASYNC_HDC_SESSION_CLOSE, RaRsAsyncHdcSessionClose, sizeof(union OpAsyncHdcCloseData)},
    1539              :     {RA_RS_GET_DEV_EID_INFO_NUM, RaRsGetDevEidInfoNum, sizeof(union OpGetDevEidInfoNumData)},
    1540              :     {RA_RS_GET_DEV_EID_INFO_LIST, RaRsGetDevEidInfoList, sizeof(union OpGetDevEidInfoListData)},
    1541              :     {RA_RS_CTX_INIT, RaRsCtxInit, sizeof(union OpCtxInitData)},
    1542              :     {RA_RS_CTX_GET_ASYNC_EVENTS, RaRsCtxGetAsyncEvents, sizeof(union OpCtxGetAsyncEventsData)},
    1543              :     {RA_RS_CTX_DEINIT, RaRsCtxDeinit, sizeof(union OpCtxDeinitData)},
    1544              :     {RA_RS_GET_EID_BY_IP, RaRsGetEidByIp, sizeof(union OpGetEidByIpData)},
    1545              :     {RA_RS_GET_IP_BY_EID, RaRsGetIpByEid, sizeof(union OpGetIpByEidData)},
    1546              :     {RA_RS_GET_TP_INFO_LIST, RaRsGetTpInfoList, sizeof(union OpGetTpInfoListData)},
    1547              :     {RA_RS_GET_TP_ATTR, RaRsGetTpAttr, sizeof(union OpGetTpAttrData)},
    1548              :     {RA_RS_SET_TP_ATTR, RaRsSetTpAttr, sizeof(union OpSetTpAttrData)},
    1549              :     {RA_RS_CTX_TOKEN_ID_ALLOC, RaRsCtxTokenIdAlloc, sizeof(union OpTokenIdAllocData)},
    1550              :     {RA_RS_CTX_TOKEN_ID_FREE, RaRsCtxTokenIdFree, sizeof(union OpTokenIdFreeData)},
    1551              :     {RA_RS_LMEM_REG, RaRsLmemReg, sizeof(union OpLmemRegInfoData)},
    1552              :     {RA_RS_LMEM_UNREG, RaRsLmemUnreg, sizeof(union OpLmemUnregInfoData)},
    1553              :     {RA_RS_RMEM_IMPORT, RaRsRmemImport, sizeof(union OpRmemImportInfoData)},
    1554              :     {RA_RS_RMEM_UNIMPORT, RaRsRmemUnimport, sizeof(union OpRmemUnimportInfoData)},
    1555              :     {RA_RS_CTX_CHAN_CREATE, RaRsCtxChanCreate, sizeof(union OpCtxChanCreateData)},
    1556              :     {RA_RS_CTX_CHAN_DESTROY, RaRsCtxChanDestroy, sizeof(union OpCtxChanDestroyData)},
    1557              :     {RA_RS_CTX_CQ_CREATE, RaRsCtxCqCreate, sizeof(union OpCtxCqCreateData)},
    1558              :     {RA_RS_CTX_CQ_DESTROY, RaRsCtxCqDestroy, sizeof(union OpCtxCqDestroyData)},
    1559              :     {RA_RS_CTX_QP_CREATE, RaRsCtxQpCreate, sizeof(union OpCtxQpCreateData)},
    1560              :     {RA_RS_CTX_QUERY_QP_BATCH, RaRsCtxQpQueryBatch, sizeof(union OpCtxQpQueryBatchData)},
    1561              :     {RA_RS_CTX_QP_DESTROY, RaRsCtxQpDestroy, sizeof(union OpCtxQpDestroyData)},
    1562              :     {RA_RS_CTX_QP_DESTROY_BATCH, RaRsCtxQpDestroyBatch, sizeof(union OpCtxQpDestroyBatchData)},
    1563              :     {RA_RS_CTX_QP_IMPORT, RaRsCtxQpImport, sizeof(union OpCtxQpImportData)},
    1564              :     {RA_RS_CTX_QP_UNIMPORT, RaRsCtxQpUnimport, sizeof(union OpCtxQpUnimportData)},
    1565              :     {RA_RS_CTX_QP_UNIMPORT_DEPRECATED, RaRsCtxQpUnimportDeprecated, sizeof(union OpCtxQpUnimportData)},
    1566              :     {RA_RS_CTX_QP_BIND, RaRsCtxQpBind, sizeof(union OpCtxQpBindData)},
    1567              :     {RA_RS_CTX_QP_UNBIND, RaRsCtxQpUnbind, sizeof(union OpCtxQpUnbindData)},
    1568              :     {RA_RS_CTX_BATCH_SEND_WR, RaRsCtxBatchSendWr, sizeof(union OpCtxBatchSendWrData)},
    1569              :     {RA_RS_CTX_UPDATE_CI, RaRsCtxUpdateCi, sizeof(union OpCtxUpdateCiData)},
    1570              :     {RA_RS_CTX_GET_AUX_INFO, RaRsCtxGetAuxInfo, sizeof(union OpCtxGetAuxInfoData)},
    1571              :     {RA_RS_CTX_GET_CR_ERR_INFO_LIST, RaRsCtxGetCrErrInfoList, sizeof(union OpCtxGetCrErrInfoListData)},
    1572              :     {RA_RS_CTX_GET_UB_CONTEXT, RaRsCtxGetUbContext, sizeof(union OpCtxGetContextData)},
    1573              : };
    1574              : 
    1575          242 : STATIC int RaCheckParam(char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen, int *paramCheckResult)
    1576              : {
    1577              :     int i;
    1578          242 :     int ret = 0;
    1579          242 :     struct MsgHead *recvMsgHead = (struct MsgHead *)recvBuf;
    1580          242 :     int num = sizeof(gRaOpHandle) / sizeof(gRaOpHandle[0]);
    1581          242 :     unsigned int dataSize = 0;
    1582              : 
    1583          242 :     *paramCheckResult = 1;
    1584          242 :     if (rcvBufLen < (int)sizeof(struct MsgHead)) { // check rcv_buf_len
    1585            0 :         hccp_err("rcv_buf_len[%d] form ra is invalid", rcvBufLen);
    1586            0 :         ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, RECV_BUF_LEN_INVALID);
    1587            0 :         return ret;
    1588              :     }
    1589              : 
    1590          242 :     if (((recvMsgHead->msgDataLen + sizeof(struct MsgHead)) != (unsigned int)rcvBufLen) ||
    1591          242 :         (recvMsgHead->opcode >= RA_RS_OP_MAX_NUM ||
    1592          242 :             ((recvMsgHead->opcode < RA_RS_HDC_SESSION_CLOSE) && (recvMsgHead->opcode >= RA_RS_EXTER_OP_MAX_NUM)))) {
    1593            0 :         hccp_err("rcv data incomplete, because rcvBufLen[%d] != msg_head_len[%u] + msgDataLen[%u] "
    1594              :                  "or opcode[%u] is wrong, RA_RS_OP_MAX_NUM:[%d], RA_RS_EXTER_OP_MAX_NUM:[%d]",
    1595              :             rcvBufLen, sizeof(struct MsgHead), recvMsgHead->msgDataLen, recvMsgHead->opcode, RA_RS_OP_MAX_NUM,
    1596              :             RA_RS_EXTER_OP_MAX_NUM);
    1597            0 :         ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, HAVE_OP_RIGHT);
    1598            0 :         return ret;
    1599              :     }
    1600        13447 :     for (i = 0; i < num; i++) {
    1601        13447 :         if (gRaOpHandle[i].opcode == recvMsgHead->opcode) {
    1602          242 :             dataSize = gRaOpHandle[i].dataSize;
    1603          242 :             break;
    1604              :         }
    1605              :     }
    1606          242 :     if (recvMsgHead->opcode != RA_RS_SOCKET_RECV && recvMsgHead->msgDataLen != dataSize) {
    1607            0 :         hccp_err("rcv data incomplete. because msg_data_len[%d] != op_data_len[%u]", recvMsgHead->msgDataLen, dataSize);
    1608            0 :         ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, RECV_BUF_LEN_INVALID);
    1609            0 :         return ret;
    1610              :     }
    1611          242 :     *paramCheckResult = 0;
    1612          242 :     return ret;
    1613              : }
    1614              : 
    1615          242 : int RaHandle(struct RaHdcOpSec *opSec, char *recvBuf, int rcvBufLen, char **sendBuf, int *sndBufLen,
    1616              :     unsigned int *closeSession)
    1617              : {
    1618              :     int i;
    1619              :     int ret;
    1620          242 :     int opRight = 0;
    1621          242 :     int paramCheckRet = 0;
    1622          242 :     int opRet = 0;
    1623          242 :     struct MsgHead *recvMsgHead = (struct MsgHead *)recvBuf;
    1624          242 :     int num = sizeof(gRaOpHandle) / sizeof(gRaOpHandle[0]);
    1625              : 
    1626          242 :     ret = RaCheckParam(recvBuf, rcvBufLen, sendBuf, sndBufLen, &paramCheckRet);
    1627          242 :     CHK_PRT_RETURN(paramCheckRet != 0 || ret != 0,
    1628              :         hccp_err("ra param check failed. param check ret:[%d]"
    1629              :                  "function call ret:[%d]",
    1630              :             paramCheckRet, ret),
    1631              :         ret);
    1632              : 
    1633          242 :     RaGetOpRight(opSec, recvMsgHead->opcode, recvMsgHead->asyncReqId, &opRight);
    1634          242 :     CHK_PRT_RETURN(opRight != HAVE_OP_RIGHT, ret = OpMsgErr(sendBuf, recvMsgHead, sndBufLen, opRight), ret);
    1635              : 
    1636          242 :     *sendBuf = (char *)calloc(sizeof(char), recvMsgHead->msgDataLen + sizeof(struct MsgHead));
    1637          242 :     CHK_PRT_RETURN(*sendBuf == NULL, hccp_err("calloc failed."), -ENOMEM);
    1638              : 
    1639        13447 :     for (i = 0; i < num; i++) {
    1640        13447 :         if (gRaOpHandle[i].opcode == recvMsgHead->opcode) {
    1641          242 :             ret = gRaOpHandle[i].opHandle(recvBuf, *sendBuf, sndBufLen, &opRet, rcvBufLen);
    1642          242 :             if (ret) {
    1643            1 :                 hccp_err("ra handle failed. ret:[%d]", ret);
    1644            1 :                 goto out;
    1645              :             }
    1646          241 :             MsgHeadBuildUpHw(*sendBuf, recvMsgHead, opRet, recvMsgHead->msgDataLen);
    1647          241 :             *closeSession = recvMsgHead->opcode == RA_RS_HDC_SESSION_CLOSE ? 1 : 0;
    1648          241 :             *sndBufLen = recvMsgHead->msgDataLen + sizeof(struct MsgHead);
    1649          241 :             return ret;
    1650              :         }
    1651              :     }
    1652              : 
    1653            0 :     hccp_warn("not support opcode:%d", recvMsgHead->opcode);
    1654            0 :     ret = -EPROTONOSUPPORT;
    1655            1 : out:
    1656            1 :     free(*sendBuf);
    1657            1 :     *sendBuf = NULL;
    1658            1 :     return ret;
    1659              : }
    1660              : 
    1661          240 : STATIC int RaSendPkt(struct drvHdcMsg *msgRcv, HDC_SESSION session, void *sendBuf, int sndBufLen)
    1662              : {
    1663              :     int ret;
    1664          240 :     struct drvHdcMsg *msgSnd = NULL;
    1665              : 
    1666          240 :     ret = RA_HDC_OPS.reuseMsg(msgRcv);
    1667          240 :     CHK_PRT_RETURN(ret, hccp_err("reuse msg failed ret %d", ret), ret);
    1668              : 
    1669          240 :     msgSnd = msgRcv;
    1670              : 
    1671          240 :     ret = RA_HDC_OPS.addMsgBuffer(msgSnd, sendBuf, sndBufLen);
    1672          240 :     CHK_PRT_RETURN(ret, hccp_err("add msg buffer failed ret %d", ret), ret);
    1673              : 
    1674          240 :     ret = RA_HDC_OPS.send(session, msgSnd, 0, RA_HDC_RECV_SEND_TIMEOUT);
    1675          240 :     CHK_PRT_RETURN(ret, hccp_err("send msg failed ret %d", ret), ret);
    1676              : 
    1677          240 :     return 0;
    1678              : }
    1679              : 
    1680          242 : STATIC int RecvHandleSendPkt(HDC_SESSION session, unsigned int *closeSession, unsigned int chipId)
    1681              : {
    1682              :     int ret;
    1683          242 :     void *recvBuf = NULL;
    1684          242 :     void *sendBuf = NULL;
    1685          242 :     struct drvHdcMsg *msgRcv = NULL;
    1686              :     int recvBufCnt, sndBufLen, rcvBufLen;
    1687          242 :     RsSetCtx(chipId);
    1688          242 :     ret = RA_HDC_OPS.allocMsg(session, &msgRcv, 1);
    1689          242 :     CHK_PRT_RETURN(ret, hccp_err("alloc hdc msg failed ret %d", ret), ret);
    1690              : 
    1691          242 :     ret = RA_HDC_OPS.recv(session, msgRcv, MAX_HDC_DATA, 0, &recvBufCnt, RA_HDC_RECV_SEND_TIMEOUT);
    1692          242 :     if (ret) {
    1693            1 :         hccp_warn("recv hdc msg unsuccessful, ret %d", ret);
    1694            1 :         goto out;
    1695              :     }
    1696              : 
    1697          241 :     RA_HDC_OPS.getMsgBuffer(msgRcv, 0, (char **)&recvBuf, &rcvBufLen);
    1698          241 :     if (recvBuf == NULL) {
    1699            0 :         hccp_warn("rcv_buf_len is NULL, Session disconnect.");
    1700            0 :         goto out;
    1701              :     }
    1702              : 
    1703          241 :     if (rcvBufLen == 0) {
    1704            0 :         *closeSession = 1;
    1705            0 :         hccp_warn("rcv_buf_len is 0, Session disconnect.");
    1706            0 :         RA_HDC_OPS.freeMsg(msgRcv);
    1707            0 :         return 0;
    1708              :     }
    1709              : 
    1710          241 :     ret = RaHandle(&gHdcServer[chipId].opSec, recvBuf, rcvBufLen, (char **)&sendBuf, &sndBufLen, closeSession);
    1711          241 :     if (ret) {
    1712            1 :         hccp_err("ra_handle failed.");
    1713            1 :         goto out;
    1714              :     }
    1715              : 
    1716          240 :     ret = RaSendPkt(msgRcv, session, sendBuf, sndBufLen);
    1717          240 :     if (ret) {
    1718            0 :         hccp_err("ra send pkt failed ret %d", ret);
    1719            0 :         goto err;
    1720              :     }
    1721              : 
    1722          240 : err:
    1723          240 :     free(sendBuf);
    1724          240 :     sendBuf = NULL;
    1725          242 : out:
    1726          242 :     RA_HDC_OPS.freeMsg(msgRcv);
    1727          242 :     return ret;
    1728              : }
    1729              : 
    1730          242 : STATIC void RaHdcRecvHandleSendPkt(const unsigned int chipId)
    1731              : {
    1732          242 :     unsigned int closeSession = 0;
    1733              :     int ret;
    1734              : 
    1735          242 :     ret = RecvHandleSendPkt(gHdcServer[chipId].hdcSession, &closeSession, chipId);
    1736          242 :     if (closeSession != 0 || ret != 0) {
    1737          119 :         hccp_warn("recv_handle_send_pkt close_session[%u] ret[%d]", closeSession, ret);
    1738          119 :         RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
    1739          119 :         gHdcInitPara.connectStatus = HDC_UNCONNECTED;
    1740          119 :         RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
    1741              :     }
    1742              : 
    1743          242 :     return;
    1744              : }
    1745              : 
    1746          354 : STATIC void RaHwHdcCloseSession(HDC_SESSION *session)
    1747              : {
    1748              :     int ret;
    1749              : 
    1750          354 :     RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
    1751          354 :     if (session == NULL || *session == NULL) {
    1752          236 :         goto out;
    1753              :     }
    1754              : 
    1755          118 :     ret = RA_HDC_OPS.sessionClose(*session);
    1756          118 :     if (ret != 0) {
    1757            0 :         hccp_warn("RA_HDC_OPS.sessionClose unsuccessful, ret:%d", ret);
    1758              :     }
    1759          118 :     *session = NULL;
    1760              : 
    1761          354 : out:
    1762          354 :     RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
    1763          354 :     return;
    1764              : }
    1765              : 
    1766          118 : STATIC void *RaPthread(void *arg)
    1767              : {
    1768          118 :     unsigned int chipId = gHdcInitPara.chipId;
    1769              :     int ret;
    1770              : 
    1771          118 :     ret = pthread_detach(pthread_self());
    1772          118 :     CHK_PRT_RETURN(ret, hccp_err("pthread detach failed ret %d", ret), NULL);
    1773              : 
    1774          118 :     (void)prctl(PR_SET_NAME, (uintptr_t) "hccp_ra", 0, 0, 0);
    1775              : 
    1776          118 :     RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
    1777          118 :     gHdcInitPara.threadStatus = THREAD_RUNNING;
    1778          118 :     RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
    1779              : 
    1780          118 :     RsGetCurTime(&gRaThreadInfo.lastCheckTime);
    1781          118 :     ret = strncpy_s((char *)gRaThreadInfo.pthreadName, sizeof(gRaThreadInfo.pthreadName), "ra_thread",
    1782              :         strlen("ra_thread"));
    1783          118 :     CHK_PRT_RETURN(ret, hccp_err("strncpy_s pthread name failed, ret[%d]", ret), NULL);
    1784              : 
    1785          118 :     hccp_run_info("pthread[%s] is alive!", gRaThreadInfo.pthreadName);
    1786              :     while (1) {
    1787         1207 :         if (gHdcInitPara.threadStatus == THREAD_DESTROYING) {
    1788          118 :             break;
    1789              :         }
    1790              : 
    1791         1089 :         if (gHdcInitPara.connectStatus != HDC_CONNECTED) {
    1792          848 :             usleep(THREAD_SLEEP_TIME);
    1793          848 :             continue;
    1794              :         }
    1795          241 :         RsHeartbeatAlivePrint(&gRaThreadInfo);
    1796          241 :         RaHdcRecvHandleSendPkt(chipId);
    1797              :     }
    1798              : 
    1799          118 :     hccp_info("thread [%d] is out", getpid());
    1800          118 :     RaHwHdcCloseSession(&gHdcServer[chipId].hdcSession);
    1801          118 :     RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
    1802          118 :     gHdcInitPara.threadStatus = THREAD_HALT;
    1803          118 :     RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
    1804          118 :     return NULL;
    1805              : }
    1806              : 
    1807          123 : STATIC int RaHdcServerInit(unsigned int chipId, int hdcType)
    1808              : {
    1809              :     int ret;
    1810              : 
    1811          123 :     CHK_PRT_RETURN(chipId > HCCP_MAX_CHIP_ID || gHdcServer[chipId].hdcSession != NULL,
    1812              :         hccp_err("invalid "
    1813              :                  "chip id %u, or hdcSession is not NULL",
    1814              :             chipId),
    1815              :         -EINVAL);
    1816          122 :     CHK_PRT_RETURN(hdcType != HDC_SERVICE_TYPE_RDMA && hdcType != HDC_SERVICE_TYPE_RDMA_V2,
    1817              :         hccp_err("invalid "
    1818              :                  "hdc_type %d",
    1819              :             hdcType),
    1820              :         -EINVAL);
    1821              : 
    1822          122 :     RaHdcInitOpSec(&gHdcServer[chipId].opSec, BUCKET_DEPTH, false);
    1823              : 
    1824          122 :     ret = RA_HDC_OPS.serverCreate(chipId, hdcType, &gHdcServer[chipId].hdcServer);
    1825          122 :     CHK_PRT_RETURN(ret, hccp_err("Create Server failed, ret(%d) ", ret), -EINVAL);
    1826              : 
    1827          121 :     return 0;
    1828              : }
    1829              : 
    1830          241 : void RaHdcInitOpSec(struct RaHdcOpSec *opSec, unsigned long long tokenNum, bool isAsyncOp)
    1831              : {
    1832          241 :     opSec->tokenNum = tokenNum;
    1833          241 :     opSec->cfgOpNum = 0;
    1834          241 :     opSec->tLast.tv_sec = 0;
    1835          241 :     opSec->tLast.tv_usec = 0;
    1836          241 :     opSec->isAsyncOp = isAsyncOp;
    1837          241 : }
    1838              : 
    1839          237 : int RaHdcSessionAccept(unsigned int chipId, HDC_SESSION *session, int initHostTgid)
    1840              : {
    1841              :     int hostTgid;
    1842          237 :     int ret = 0;
    1843              : 
    1844          237 :     ret = RA_HDC_OPS.sessionAccept(gHdcServer[chipId].hdcServer, session);
    1845          237 :     if (ret != 0) {
    1846          118 :         hccp_warn("Session accept failed, chipId(%u), ret(%d) ", chipId, ret);
    1847          118 :         return ret;
    1848              :     }
    1849              : 
    1850          119 :     RA_HDC_OPS.setSessionReference(*session);
    1851          119 :     ret = DlHalHdcGetSessionAttr(*session, HDC_SESSION_ATTR_PEER_CREATE_PID, &hostTgid);
    1852          119 :     if (ret) {
    1853            0 :         hccp_err("Session get host_pid failed, chipId(%u), ret(%d)", chipId, ret);
    1854            0 :         goto out;
    1855              :     }
    1856              : 
    1857          119 :     if (hostTgid != initHostTgid) {
    1858            0 :         hccp_warn("host_tgid[%d] from ra not equal to the tgid[%d] from hccp_init, invalid", hostTgid, initHostTgid);
    1859            0 :         goto out;
    1860              :     }
    1861              : 
    1862          119 :     return 0;
    1863              : 
    1864            0 : out:
    1865            0 :     RaHdcCloseSession(session);
    1866            0 :     return ret;
    1867              : }
    1868              : 
    1869            3 : int RaHdcAsyncRecvPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void **recvBuf, unsigned int *recvLen)
    1870              : {
    1871            3 :     struct drvHdcMsg *msgRcv = NULL;
    1872            3 :     void *rcvBuf = NULL;
    1873            3 :     int rcvLen = 0;
    1874              :     int ret;
    1875              : 
    1876            3 :     ret = RA_HDC_OPS.allocMsg(asyncInfo->hdcSession, &msgRcv, 1);
    1877            3 :     CHK_PRT_RETURN(ret != 0, hccp_err("alloc hdc msg failed ret %d", ret), ret);
    1878              : 
    1879            3 :     ret = RA_HDC_OPS.recv(asyncInfo->hdcSession, msgRcv, MAX_HDC_DATA, 0, &rcvLen, RA_HDC_RECV_SEND_TIMEOUT);
    1880            3 :     if (ret != 0) {
    1881            1 :         hccp_warn("recv hdc msg unsuccessful ret %d", ret);
    1882            1 :         goto out;
    1883              :     }
    1884              : 
    1885            2 :     RA_HDC_OPS.getMsgBuffer(msgRcv, 0, (char **)&rcvBuf, &rcvLen);
    1886            2 :     if (rcvBuf == NULL || rcvLen == 0) {
    1887            2 :         hccp_warn("get_msg_buffer unsuccessful, rcvBuf is NULL or rcvLen:%d is 0", rcvLen);
    1888            2 :         goto out;
    1889              :     }
    1890              : 
    1891            0 :     *recvBuf = (char *)calloc(rcvLen, sizeof(char));
    1892            0 :     if (*recvBuf == NULL) {
    1893            0 :         hccp_err("calloc recv_buf failed, errno:%d rcvLen:%d", errno, rcvLen);
    1894            0 :         ret = -ENOMEM;
    1895            0 :         goto out;
    1896              :     }
    1897              : 
    1898            0 :     (void)memcpy_s(*recvBuf, rcvLen, rcvBuf, rcvLen);
    1899            0 :     *recvLen = rcvLen;
    1900              : 
    1901            3 : out:
    1902            3 :     RA_HDC_OPS.freeMsg(msgRcv);
    1903            3 :     return ret;
    1904              : }
    1905              : 
    1906            1 : int RaHdcAsyncSendPkt(struct RaHdcAsyncInfo *asyncInfo, unsigned int chipId, void *sendBuf, unsigned int sendLen)
    1907              : {
    1908            1 :     struct drvHdcMsg *msgSnd = NULL;
    1909            1 :     int ret = -EINVAL;
    1910              : 
    1911            1 :     RA_PTHREAD_MUTEX_LOCK(&asyncInfo->sendMutex);
    1912              :     // degrade log level because session will be closed by recv thread and request will be abort
    1913            1 :     if (asyncInfo->hdcSession == NULL) {
    1914            1 :         hccp_warn("[async][send_pkt]hdc_session is NULL, chipId(%u)", chipId);
    1915            1 :         goto alloc_msg_err;
    1916              :     }
    1917              : 
    1918            0 :     ret = RA_HDC_OPS.allocMsg(asyncInfo->hdcSession, &msgSnd, 1);
    1919            0 :     if (ret != 0) {
    1920            0 :         hccp_err("[async][send_pkt]HDC alloc msg err ret(%d) chip_id(%u)", ret, chipId);
    1921            0 :         goto alloc_msg_err;
    1922              :     }
    1923              : 
    1924            0 :     ret = RA_HDC_OPS.addMsgBuffer(msgSnd, sendBuf, sendLen);
    1925            0 :     if (ret != 0) {
    1926            0 :         hccp_err("[async][send_pkt]HDC add msg buffer err ret(%d) chip_id(%u)", ret, chipId);
    1927            0 :         goto msg_err;
    1928              :     }
    1929              : 
    1930            0 :     ret = RA_HDC_OPS.send(asyncInfo->hdcSession, msgSnd, RA_HDC_WAIT_TIMEOUT, RA_HDC_RECV_SEND_TIMEOUT);
    1931            0 :     if (ret != 0) {
    1932            0 :         hccp_err("[async][send_pkt]HDC send err ret(%d) chip_id(%u)", ret, chipId);
    1933            0 :         goto msg_err;
    1934              :     }
    1935              : 
    1936            0 : msg_err:
    1937            0 :     RA_HDC_OPS.freeMsg(msgSnd);
    1938            1 : alloc_msg_err:
    1939            1 :     RA_PTHREAD_MUTEX_UNLOCK(&asyncInfo->sendMutex);
    1940            1 :     return ret;
    1941              : }
    1942              : 
    1943            1 : void RaHdcCloseSession(HDC_SESSION *session)
    1944              : {
    1945            1 :     RA_HDC_OPS.sessionClose(*session);
    1946            1 :     *session = NULL;
    1947            1 :     return;
    1948              : }
    1949              : 
    1950          119 : STATIC void RaHwHdcInit(void *arg)
    1951              : {
    1952          119 :     unsigned int chipId = gHdcInitPara.chipId;
    1953              :     pthread_t tidp;
    1954              :     int ret;
    1955              : 
    1956          119 :     ret = pthread_detach(pthread_self());
    1957          119 :     if (ret) {
    1958            1 :         hccp_err("pthread detach failed ret %d", ret);
    1959            1 :         return;
    1960              :     }
    1961              : 
    1962          118 :     (void)prctl(PR_SET_NAME, (uintptr_t) "hccp_hw_hdc", 0, 0, 0);
    1963              : 
    1964          118 :     hccp_info("chip_id(%u)", chipId);
    1965          118 :     gHdcInitPara.hdcFlag = 1;
    1966              : 
    1967          118 :     ret = pthread_create(&tidp, NULL, (void *)RaPthread, NULL);
    1968          118 :     if (ret) {
    1969            0 :         hccp_err("Create pthread failed, chipId(%u), ret(%d) ", chipId, ret);
    1970            0 :         return;
    1971              :     }
    1972              : 
    1973              :     while (1) {
    1974         2041 :         if (gHdcInitPara.connectStatus != HDC_UNCONNECTED) {
    1975         1805 :             usleep(HDC_ACCEPT_SLEEP_TIME);
    1976         1805 :             continue;
    1977              :         }
    1978          236 :         RaHwHdcCloseSession(&gHdcServer[chipId].hdcSession);
    1979          236 :         ret = RaHdcSessionAccept(chipId, &gHdcServer[chipId].hdcSession, (int)gHdcInitPara.hostTgid);
    1980          236 :         if (ret != 0) {
    1981          118 :             hccp_warn("Session Accept unsuccessful, chipId(%u), ret(%d) ", chipId, ret);
    1982          118 :             gHdcInitPara.hdcFlag = 0;
    1983          118 :             return;
    1984              :         }
    1985              :         // original case, should continue to accept: host_tgid != g_hdc_init_para.host_tgid
    1986          118 :         if (ret == 0 && gHdcServer[chipId].hdcSession == NULL) {
    1987            0 :             continue;
    1988              :         }
    1989          118 :         RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
    1990          118 :         gHdcInitPara.connectStatus = HDC_CONNECTED;
    1991          118 :         RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
    1992              :     }
    1993              : }
    1994              : 
    1995          121 : STATIC void RaHwHdcDeinit(void)
    1996              : {
    1997          121 :     unsigned int chipId = gHdcInitPara.chipId;
    1998              :     int ret, tryAgain;
    1999              : 
    2000          121 :     RA_PTHREAD_MUTEX_LOCK(&gHdcInitPara.mutex);
    2001          121 :     gHdcInitPara.threadStatus = THREAD_DESTROYING;
    2002          121 :     RA_PTHREAD_MUTEX_UNLOCK(&gHdcInitPara.mutex);
    2003              : 
    2004          121 :     tryAgain = HDC_TRY_TIME;
    2005          839 :     while ((gHdcInitPara.threadStatus != THREAD_HALT) && tryAgain != 0) {
    2006          718 :         usleep(HDC_USLEEP_TIME);
    2007          718 :         tryAgain--;
    2008              :     }
    2009          121 :     if (tryAgain == 0) {
    2010            3 :         hccp_warn("hdc message thread quit timeout, chipId:%u", chipId);
    2011              :     }
    2012              : 
    2013          121 :     if (gHdcServer[chipId].hdcServer != NULL) {
    2014            0 :         ret = RA_HDC_OPS.serverDestroy(gHdcServer[chipId].hdcServer);
    2015            0 :         if (ret != 0) {
    2016            0 :             hccp_warn("RA_HDC_OPS.server_destroy unsuccessful, ret:%d, chipId:%u", ret, chipId);
    2017              :         }
    2018            0 :         gHdcServer[chipId].hdcServer = NULL;
    2019              :     } else {
    2020          121 :         hccp_warn("hdc_server is NULL, chipId:%u", chipId);
    2021              :     }
    2022          121 :     pthread_mutex_destroy(&gHdcInitPara.mutex);
    2023          121 : }
    2024              : 
    2025          124 : STATIC int HccpSetAffinity(unsigned int chipId)
    2026              : {
    2027          124 :     unsigned int phyDevid = chipId;
    2028              :     int64_t cpuCoreNum;
    2029              :     int64_t ccpuNum; /* ctrl cpu */
    2030              :     int64_t dcpuNum; /* data cpu */
    2031              :     int64_t acpuNum; /* ai cpu */
    2032              :     cpu_set_t mask;
    2033              :     int64_t cpuId;
    2034              :     int ret;
    2035              : 
    2036          124 :     ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_CCPU, INFO_TYPE_CORE_NUM, &ccpuNum);
    2037          124 :     CHK_PRT_RETURN(ret, hccp_err("get ccpu_num failed, ret(%d)", ret), ret);
    2038              : 
    2039          124 :     ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_DCPU, INFO_TYPE_CORE_NUM, &dcpuNum);
    2040          124 :     CHK_PRT_RETURN(ret, hccp_err("get dcpu_num failed, ret(%d)", ret), ret);
    2041              : 
    2042          124 :     ret = DlHalGetDeviceInfo(chipId, MODULE_TYPE_AICPU, INFO_TYPE_CORE_NUM, &acpuNum);
    2043          124 :     CHK_PRT_RETURN(ret, hccp_err("get acpu_num failed, ret(%d)", ret), ret);
    2044          124 :     cpuCoreNum = ccpuNum + dcpuNum + acpuNum;
    2045              : 
    2046          124 :     ret = DlHalGetPhyDevIdByudevId(chipId, &phyDevid);
    2047          124 :     CHK_PRT_RETURN(ret != 0, hccp_err("DlHalGetPhyDevIdByudevId failed, ret(%d) chipId:%u", ret, chipId), ret);
    2048          124 :     CPU_ZERO(&mask);
    2049          124 :     cpuId = cpuCoreNum * phyDevid + HCCP_RUN_CPU_CORE;
    2050              :     /*lint -e574*/
    2051          124 :     CPU_SET((size_t)cpuId, &mask); // lint !e573
    2052              :     /*lint +e574*/
    2053          124 :     hccp_run_info("chipId:%u phyDevid:%u ccpuNum:%lld, dcpuNum:%lld, acpuNum:%lld, cpuId:%lld", chipId, phyDevid,
    2054              :         ccpuNum, dcpuNum, acpuNum, cpuId);
    2055          124 :     ret = sched_setaffinity(getpid(), sizeof(mask), &mask); /* hccp use core0 of each chip to setaffinity */
    2056          124 :     CHK_PRT_RETURN(ret == -1,
    2057              :         hccp_err("sched_setaffinity failed: ret %d, errno %d chipId:%u phyDevid:%u", ret, errno, chipId, phyDevid),
    2058              :         -ESYSFUNC);
    2059              : 
    2060          123 :     return 0;
    2061              : }
    2062              : 
    2063          121 : STATIC int RaHwInit(unsigned int chipId, pid_t pid)
    2064              : {
    2065              :     int ret;
    2066              :     pthread_t tidp;
    2067          121 :     int timeout = RA_THREAD_TRY_TIME;
    2068              : 
    2069          121 :     gHdcInitPara.chipId = chipId;
    2070          121 :     gHdcInitPara.hostTgid = pid;
    2071              : 
    2072          121 :     ret = pthread_create(&tidp, NULL, (void *)RaHwHdcInit, NULL);
    2073          121 :     CHK_PRT_RETURN(ret, hccp_err("Create pthread failed, ret(%d) ", ret), -ESYSFUNC);
    2074              : 
    2075        10286 :     while (gHdcInitPara.hdcFlag != 1 && timeout > 0) {
    2076        10166 :         usleep(RA_THREAD_SLEEP_TIME);
    2077        10166 :         timeout--;
    2078              :     }
    2079              : 
    2080          120 :     CHK_PRT_RETURN(gHdcInitPara.hdcFlag == 0 || timeout == 0,
    2081              :         hccp_err("HDC server thread create timeout,"
    2082              :                  "flag %d, timeout %d",
    2083              :             gHdcInitPara.hdcFlag, timeout),
    2084              :         -ESRCH);
    2085              : 
    2086          118 :     return 0;
    2087              : }
    2088              : 
    2089          124 : RA_ADP_ATTRI_VISI_DEF int HccpInit(unsigned int chipId, pid_t pid, int hdcType, unsigned int whiteListStatus)
    2090              : {
    2091              :     struct timeval start, end;
    2092          124 :     float timeCost = 0.0;
    2093              :     int ret, retTmp;
    2094              : 
    2095          124 :     hccp_info("hccp[%u] hdc_type[%d] white_list_status[%u] init start", chipId, hdcType, whiteListStatus);
    2096              : 
    2097          124 :     ret = DlHalInit();
    2098          124 :     if (ret != 0) {
    2099            0 :         hccp_err("dl_hal_init failed, ret = %d", ret);
    2100            0 :         return ret;
    2101              :     }
    2102              : 
    2103          124 :     ret = HccpSetAffinity(chipId);
    2104          124 :     if (ret != 0) {
    2105            1 :         hccp_err("hccp_set_affinity failed, ret(%d) ", ret);
    2106            1 :         goto out;
    2107              :     }
    2108              : 
    2109          123 :     RsGetCurTime(&start);
    2110          123 :     ret = RaHdcServerInit(chipId, hdcType);
    2111          123 :     if (ret != 0) {
    2112            2 :         hccp_err("chip_id[%u] hdc_type[%d] ra_hdc_server_init failed, ret[%d] ", chipId, hdcType, ret);
    2113            2 :         goto out;
    2114              :     }
    2115              : 
    2116          121 :     ret = pthread_mutex_init(&gHdcInitPara.mutex, NULL);
    2117          121 :     if (ret != 0) {
    2118            0 :         hccp_err("g_hdc_init_para mutex_init failed ret %d!, normal ret 0", ret);
    2119            0 :         ret = -ESYSFUNC;
    2120            0 :         goto out;
    2121              :     }
    2122              : 
    2123          121 :     ret = RaHwInit(chipId, pid);
    2124          121 :     if (ret != 0) {
    2125            3 :         hccp_err("ra_init failed, ret(%d) ", ret);
    2126            3 :         goto hw_init_err;
    2127              :     }
    2128              : 
    2129          118 :     ret = RaHwAsyncInit(chipId, pid);
    2130          118 :     if (ret != 0) {
    2131            0 :         hccp_err("ra_hw_async_init failed, ret(%d) ", ret);
    2132            0 :         goto hw_init_err;
    2133              :     }
    2134              : 
    2135          118 :     RsGetCurTime(&end);
    2136          118 :     HccpTimeInterval(&end, &start, &timeCost);
    2137          118 :     hccp_info("ra_hw_init ok cost [%f] ms", timeCost);
    2138              : 
    2139          118 :     struct RsInitConfig offlineConfig = {
    2140              :         .chipId = chipId,
    2141              :         .hccpMode = NETWORK_OFFLINE,
    2142              :         .whiteListStatus = whiteListStatus,
    2143              :     };
    2144              : 
    2145          118 :     RsGetCurTime(&start);
    2146          118 :     ret = RsInit(&offlineConfig);
    2147          118 :     if (ret != 0) {
    2148            0 :         hccp_err("rs_init failed (0x%x) ", ret);
    2149            0 :         goto init_err;
    2150              :     }
    2151          118 :     RsGetCurTime(&end);
    2152          118 :     HccpTimeInterval(&end, &start, &timeCost);
    2153          118 :     hccp_info("rs_init ok cost [%f] ms", timeCost);
    2154              : 
    2155          118 :     RsGetCurTime(&start);
    2156          118 :     ret = RsBindHostpid(chipId, pid);
    2157          118 :     if (ret != 0) {
    2158            0 :         hccp_err("rs_bind_hostpid failed, ret=%d ", ret);
    2159            0 :         goto bind_hostpid_err;
    2160              :     }
    2161          118 :     RsGetCurTime(&end);
    2162          118 :     HccpTimeInterval(&end, &start, &timeCost);
    2163          118 :     hccp_info("rs_bind_hostpid ok cost [%f] ms", timeCost);
    2164              : 
    2165          118 :     RsGetCurTime(&start);
    2166          118 :     ret = RsPingHandleInit(chipId, hdcType, whiteListStatus);
    2167          118 :     if (ret != 0) {
    2168            0 :         hccp_err("rs_ping_handle_init failed, ret=%d ", ret);
    2169            0 :         goto bind_hostpid_err;
    2170              :     }
    2171          118 :     RsGetCurTime(&end);
    2172          118 :     HccpTimeInterval(&end, &start, &timeCost);
    2173          118 :     hccp_info("rs_ping_handle_init ok cost [%f] ms", timeCost);
    2174              : 
    2175          118 :     return 0;
    2176            0 : bind_hostpid_err:
    2177            0 :     retTmp = RsDeinit(&offlineConfig);
    2178            0 :     if (retTmp) {
    2179            0 :         hccp_err("rs_deinit failed %d ", retTmp);
    2180              :     }
    2181            0 : init_err:
    2182            0 :     RaHwAsyncDeinit();
    2183            3 : hw_init_err:
    2184            3 :     pthread_mutex_destroy(&gHdcInitPara.mutex);
    2185            6 : out:
    2186            6 :     DlHalDeinit();
    2187            6 :     return ret;
    2188              : }
    2189              : 
    2190          122 : RA_ADP_ATTRI_VISI_DEF int HccpDeinit(unsigned int chipId)
    2191              : {
    2192          122 :     struct RsInitConfig offlineConfig = {
    2193              :         .chipId = chipId,
    2194              :         .hccpMode = NETWORK_OFFLINE,
    2195              :         .whiteListStatus = WHITE_LIST_ENABLE,
    2196              :     };
    2197              :     int ret;
    2198              : 
    2199          122 :     hccp_info("hccp[%u] deinit start", chipId);
    2200              : 
    2201          122 :     ret = RsPingHandleDeinit(chipId);
    2202          122 :     CHK_PRT_RETURN(ret, hccp_err("rs_ping_handle_deinit failed %d ", ret), ret);
    2203              : 
    2204          122 :     ret = RsDeinit(&offlineConfig);
    2205          122 :     CHK_PRT_RETURN(ret, hccp_err("rs_deinit failed %d ", ret), ret);
    2206              : 
    2207          121 :     RaHwHdcDeinit();
    2208              : 
    2209          121 :     RaHwAsyncDeinit();
    2210          121 :     DlHalDeinit();
    2211          121 :     hccp_info("hccp [%u] deinit success", chipId);
    2212              : 
    2213          121 :     return ret;
    2214              : }
        

Generated by: LCOV version 2.0-1