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

Generated by: LCOV version 2.0-1