LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/client - ra_host.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.2 % 1081 1018
Test Date: 2026-08-29 17:38:31 Functions: 96.3 % 81 78

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include <sys/epoll.h>
      12              : #include <stdlib.h>
      13              : #include <string.h>
      14              : #include <dlfcn.h>
      15              : #include "securec.h"
      16              : #include "hccp.h"
      17              : #include "ra_client_host.h"
      18              : #include "ra.h"
      19              : #include "ra_init.h"
      20              : #include "ra_rdma.h"
      21              : #include "ra_hdc.h"
      22              : #include "ra_hdc_rdma_notify.h"
      23              : #include "ra_hdc_rdma.h"
      24              : #include "ra_hdc_rdma_verbs.h"
      25              : #include "ra_hdc_socket.h"
      26              : #include "ra_peer.h"
      27              : #include "ra_peer_nda.h"
      28              : #include "ra_peer_socket.h"
      29              : #include "ra_rs_comm.h"
      30              : #include "ra_rs_err.h"
      31              : 
      32              : static unsigned int gWhiteListSwitch = 0;
      33              : 
      34              : /* socket: nic on device, need use hdc channel, support: 910, 310 */
      35              : struct RaSocketOps gRaHdcSocketOps = {
      36              :     .raSocketInit = RaHdcSocketInit,
      37              :     .raSocketDeinit = RaHdcSocketDeinit,
      38              :     .raSocketBatchConnect = RaHdcSocketBatchConnect,
      39              :     .raSocketBatchClose = RaHdcSocketBatchClose,
      40              :     .raSocketBatchAbort = RaHdcSocketBatchAbort,
      41              :     .raSocketListenStart = RaHdcSocketListenStart,
      42              :     .raSocketListenStop = RaHdcSocketListenStop,
      43              :     .raGetSockets = RaHdcGetSockets,
      44              :     .raSocketSend = RaHdcSocketSend,
      45              :     .raSocketRecv = RaHdcSocketRecv,
      46              :     .raGetClientSocketErrInfo = NULL,
      47              :     .raGetServerSocketErrInfo = NULL,
      48              :     .raSocketSetWhiteListStatus = NULL,
      49              :     .raSocketGetWhiteListStatus = NULL,
      50              :     .raSocketWhiteListAdd = RaHdcSocketWhiteListAdd,
      51              :     .raSocketWhiteListDel = RaHdcSocketWhiteListDel,
      52              :     .raSocketAcceptCreditAdd = RaHdcSocketAcceptCreditAdd,
      53              : };
      54              : 
      55              : /* socket: nic on host/device, support: cx6, 1822 */
      56              : struct RaSocketOps gRaPeerSocketOps = {
      57              :     .raSocketInit = NULL,
      58              :     .raSocketDeinit = RaPeerSocketDeinit,
      59              :     .raSocketBatchConnect = RaPeerSocketBatchConnect,
      60              :     .raSocketBatchClose = RaPeerSocketBatchClose,
      61              :     .raSocketBatchAbort = RaPeerSocketBatchAbort,
      62              :     .raSocketListenStart = RaPeerSocketListenStart,
      63              :     .raSocketListenStop = RaPeerSocketListenStop,
      64              :     .raGetSockets = RaPeerGetSockets,
      65              :     .raSocketSend = RaPeerSocketSend,
      66              :     .raSocketRecv = RaPeerSocketRecv,
      67              :     .raGetClientSocketErrInfo = RaPeerGetClientSocketErrInfo,
      68              :     .raGetServerSocketErrInfo = RaPeerGetServerSocketErrInfo,
      69              :     .raSocketSetWhiteListStatus = NULL,
      70              :     .raSocketGetWhiteListStatus = NULL,
      71              :     .raSocketWhiteListAdd = RaPeerSocketWhiteListAdd,
      72              :     .raSocketWhiteListDel = RaPeerSocketWhiteListDel,
      73              :     .raSocketAcceptCreditAdd = RaPeerSocketAcceptCreditAdd,
      74              : };
      75              : 
      76              : /* rdma: nic on device, need use hdc channel, support:910 */
      77              : struct RaRdmaOps gRaHdcRdmaOps = {
      78              :     .raRdevInit = RaHdcRdevInit,
      79              :     .raRdevGetPortStatus = RaHdcRdevGetPortStatus,
      80              :     .raGetLbMax = NULL,
      81              :     .raRdevDeinit = RaHdcRdevDeinit,
      82              :     .raSetTsqpDepth = RaHdcSetTsqpDepth,
      83              :     .raGetTsqpDepth = RaHdcGetTsqpDepth,
      84              :     .raQpCreate = RaHdcQpCreate,
      85              :     .raQpCreateWithAttrs = RaHdcQpCreateWithAttrs,
      86              :     .raAiQpCreate = RaHdcAiQpCreate,
      87              :     .raAiQpCreateWithAttrs = RaHdcAiQpCreateWithAttrs,
      88              :     .raTypicalQpCreate = RaHdcTypicalQpCreate,
      89              :     .raTypicalCqCreate = RaHdcTypicalCqCreate,
      90              :     .raTypicalCqDestroy = RaHdcTypicalCqDestroy,
      91              :     .raQpCreateWithCQWithAttrs = RaHdcQpCreateWithCQWithAttrs,
      92              :     .raLoopbackQpCreate = NULL,
      93              :     .raQpDestroy = RaHdcQpDestroy,
      94              :     .raQpDestroyWithoutCQ = RaHdcQpDestroyWithoutCQ,
      95              :     .raTypicalQpModify = RaHdcTypicalQpModify,
      96              :     .raQpBatchModify = RaHdcQpBatchModify,
      97              :     .raSetQpLbValue = NULL,
      98              :     .raGetQpLbValue = NULL,
      99              :     .raQpConnectAsync = RaHdcQpConnectAsync,
     100              :     .raGetQpStatus = RaHdcGetQpStatus,
     101              :     .raMrReg = RaHdcMrReg,
     102              :     .raMrDereg = RaHdcMrDereg,
     103              :     .raRegisterMr = RaHdcTypicalMrReg,
     104              :     .raRemapMr = RaHdcRemapMr,
     105              :     .raDeregisterMr = RaHdcTypicalMrDereg,
     106              :     .raSendWr = RaHdcSendWr,
     107              :     .raSendWrV2 = RaHdcSendWrV2,
     108              :     .raSendWrVerbs = RaHdcSendWrVerbs,
     109              :     .raRecvWrVerbs = RaHdcRecvWrVerbs,
     110              :     .raTypicalSendWr = RaHdcTypicalSendWr,
     111              :     .raSendWrlist = RaHdcSendWrlist,
     112              :     .raSendWrlistExt = RaHdcSendWrlistExt,
     113              :     .raSendNormalWrlist = RaHdcSendNormalWrlist,
     114              :     .raGetNotifyBaseAddr = RaHdcGetNotifyBaseAddr,
     115              :     .raGetNotifyMrInfo = RaHdcGetNotifyMrInfo,
     116              :     .raRecvWrlist = RaHdcRecvWrlist,
     117              :     .raPollCq = RaHdcPollCq,
     118              :     .raPollTypicalCq = RaHdcPollTypicalCq,
     119              :     .raGetQpContext = NULL,
     120              :     .raNormalQpCreate = NULL,
     121              :     .raNormalQpDestroy = NULL,
     122              :     .raCqCreate = NULL,
     123              :     .raCqDestroy = NULL,
     124              :     .raSetQpAttrQos = RaHdcSetQpAttrQos,
     125              :     .raSetQpAttrTimeout = RaHdcSetQpAttrTimeout,
     126              :     .raSetQpAttrRetryCnt = RaHdcSetQpAttrRetryCnt,
     127              :     .raGetQpHyperFeature = NULL,
     128              :     .raCreateCompChannel = NULL,
     129              :     .raDestroyCompChannel = NULL,
     130              :     .raCreateSrq = NULL,
     131              :     .raDestroySrq = NULL,
     132              : };
     133              : 
     134              : /* rdma: nic on host/device, support:cx6 1822 */
     135              : struct RaRdmaOps gRaPeerRdmaOps = {
     136              :     .raRdevInit = RaPeerRdevInit,
     137              :     .raRdevGetPortStatus = RaPeerRdevGetPortStatus,
     138              :     .raGetLbMax = RaPeerGetLbMax,
     139              :     .raRdevDeinit = RaPeerRdevDeinit,
     140              :     .raSetTsqpDepth = RaPeerSetTsqpDepth,
     141              :     .raGetTsqpDepth = RaPeerGetTsqpDepth,
     142              :     .raQpCreate = RaPeerQpCreate,
     143              :     .raQpCreateWithAttrs = RaPeerQpCreateWithAttrs,
     144              :     .raAiQpCreate = NULL,
     145              :     .raAiQpCreateWithAttrs = NULL,
     146              :     .raTypicalQpCreate = NULL,
     147              :     .raTypicalCqCreate = NULL,
     148              :     .raTypicalCqDestroy = NULL,
     149              :     .raQpCreateWithCQWithAttrs = NULL,
     150              :     .raLoopbackQpCreate = RaPeerLoopbackQpCreate,
     151              :     .raQpDestroy = RaPeerQpDestroy,
     152              :     .raQpDestroyWithoutCQ = NULL,
     153              :     .raTypicalQpModify = RaPeerTypicalQpModify,
     154              :     .raQpBatchModify = NULL,
     155              :     .raSetQpLbValue = RaPeerSetQpLbValue,
     156              :     .raGetQpLbValue = RaPeerGetQpLbValue,
     157              :     .raQpConnectAsync = RaPeerQpConnectAsync,
     158              :     .raGetQpStatus = RaPeerGetQpStatus,
     159              :     .raMrReg = RaPeerMrReg,
     160              :     .raMrDereg = RaPeerMrDereg,
     161              :     .raRegisterMr = RaPeerRegisterMr,
     162              :     .raRemapMr = NULL,
     163              :     .raDeregisterMr = RaPeerDeregisterMr,
     164              :     .raSendWr = RaPeerSendWr,
     165              :     .raSendWrV2 = NULL,
     166              :     .raSendWrVerbs = NULL,
     167              :     .raRecvWrVerbs = NULL,
     168              :     .raTypicalSendWr = NULL,
     169              :     .raSendWrlist = RaPeerSendWrlist,
     170              :     .raSendWrlistExt = NULL,
     171              :     .raSendNormalWrlist = NULL,
     172              :     .raGetNotifyBaseAddr = RaPeerGetNotifyBaseAddr,
     173              :     .raGetNotifyMrInfo = NULL,
     174              :     .raRecvWrlist = RaPeerRecvWrlist,
     175              :     .raPollCq = NULL,
     176              :     .raPollTypicalCq = NULL,
     177              :     .raGetQpContext = RaPeerGetQpContext,
     178              :     .raNormalQpCreate = RaPeerNormalQpCreate,
     179              :     .raNormalQpDestroy = RaPeerNormalQpDestroy,
     180              :     .raCqCreate = RaPeerCqCreate,
     181              :     .raCqDestroy = RaPeerCqDestroy,
     182              :     .raSetQpAttrQos = RaPeerSetQpAttrQos,
     183              :     .raSetQpAttrTimeout = RaPeerSetQpAttrTimeout,
     184              :     .raSetQpAttrRetryCnt = RaPeerSetQpAttrRetryCnt,
     185              :     .raGetQpHyperFeature = RaPeerGetQpHyperFeature,
     186              :     .raCreateCompChannel = RaPeerCreateCompChannel,
     187              :     .raDestroyCompChannel = RaPeerDestroyCompChannel,
     188              :     .raCreateSrq = RaPeerCreateSrq,
     189              :     .raDestroySrq = RaPeerDestroySrq,
     190              : };
     191              : 
     192              : struct ErrcodeInfo gErrcodeInfoList[] = {
     193              :     {-EPERM, 1, 0},
     194              :     {-EAGAIN, 1, 1},
     195              :     {-EACCES, 1, 2},
     196              :     {-EINVAL, 1, 3},
     197              :     {-ESYSFUNC, 1, 4},
     198              :     {-EADDRINUSE, 1, 5},
     199              :     {-EADDRNOTAVAIL, 1, 6},
     200              :     {-ESOCKCLOSED, 1, 7},
     201              :     {-EUSERS, TYPE_CODE_OR_ENV_ERR, 8},
     202              :     {-ENOENT, 2, 0},
     203              :     {-ESRCH, 2, 1},
     204              :     {-ENODEV, 2, 2},
     205              :     {-ENOSPC, 2, 3},
     206              :     {-EPROTONOSUPPORT, 2, 4},
     207              :     {-EFILEOPER, 2, 5},
     208              :     {-ENOMEM, 3, 0},
     209              :     {-EFAULT, 3, 1},
     210              :     {-EEXIST, 3, 2},
     211              :     {-EPIPE, 3, 3},
     212              :     {-ENOLINK, 3, 4},
     213              :     {-ENETUNREACH, 3, 5},
     214              :     {-ESAFEFUNC, 3, 6},
     215              :     {-EDEFAULT, 3, 7},
     216              :     {-EINVALIDIP, 3, 8},
     217              :     {-EOPENSRC, 5, 1},
     218              :     {-ENOTSUPP, 5, 2},
     219              : };
     220              : 
     221           41 : int RaInetPton(int family, union HccpIpAddr ip, char netAddr[], unsigned int len)
     222              : {
     223           41 :     const char *str = inet_ntop(family, &(ip.addr), netAddr, len);
     224           41 :     CHK_PRT_RETURN(str == NULL, hccp_err("[ntop_convert][ra_inet]the ip failed err(%d)", errno), -EINVAL);
     225           37 :     return 0;
     226              : }
     227              : 
     228            8 : HCCP_ATTRI_VISI_DEF int RaSocketInit(int mode, struct rdev rdevInfo, void **socketHandle)
     229              : {
     230            8 :     struct RaSocketHandle *socketHandleTmp = NULL;
     231              :     int ret;
     232            8 :     char localIp[MAX_IP_LEN] = {0};
     233              : 
     234            8 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM || socketHandle == NULL,
     235              :         hccp_err("[init][ra_socket]phyId(%u) is invalid! it must be [0,%d) or socket is null!", rdevInfo.phyId,
     236              :             RA_MAX_PHY_ID_NUM),
     237              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     238              : 
     239            7 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, MAX_IP_LEN);
     240            7 :     CHK_PRT_RETURN(ret, hccp_err("[init][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     241              :         ConverReturnCode(HCCP_INIT, ret));
     242              : 
     243            6 :     hccp_run_info("socket init:mode=%d phyId=%u family=%d ip=%s", mode, rdevInfo.phyId, rdevInfo.family, localIp);
     244              : 
     245            6 :     socketHandleTmp = calloc(1, sizeof(struct RaSocketHandle));
     246            6 :     CHK_PRT_RETURN(socketHandleTmp == NULL, hccp_err("[init][ra_socket]calloc socketHandleTmp failed, ret(%d)", ret),
     247              :         ConverReturnCode(HCCP_INIT, -ENOMEM));
     248              : 
     249            5 :     if (mode == NETWORK_OFFLINE) {
     250            4 :         socketHandleTmp->socketOps = &gRaHdcSocketOps;
     251            1 :     } else if (mode == NETWORK_PEER_ONLINE) {
     252            0 :         socketHandleTmp->socketOps = &gRaPeerSocketOps;
     253              :     } else {
     254            1 :         hccp_err("[init][ra_socket]Wrong mode(%d), do not support", mode);
     255            1 :         ret = -EINVAL;
     256            1 :         goto err;
     257              :     }
     258              : 
     259            4 :     ret = memcpy_s(&(socketHandleTmp->rdevInfo), sizeof(struct rdev), &rdevInfo, sizeof(struct rdev));
     260            4 :     if (ret) {
     261            1 :         hccp_err("[init][ra_socket]memcpy_s for rdev_info failed, ret(%d)", ret);
     262            1 :         ret = -ESAFEFUNC;
     263            1 :         goto err;
     264              :     }
     265              : 
     266            3 :     if (rdevInfo.family == AF_INET && rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX &&
     267            3 :         socketHandleTmp->socketOps->raSocketInit != NULL) {
     268              :         // HDC模式只支持IPv4
     269            3 :         if (rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX) {
     270            3 :             ret = socketHandleTmp->socketOps->raSocketInit(rdevInfo);
     271            3 :             if (ret) {
     272            2 :                 hccp_err("[init][ra_socket]ra socket init failed, ret(%d)", ret);
     273            2 :                 goto err;
     274              :             }
     275              :         }
     276              :     }
     277            1 :     *socketHandle = (void *)socketHandleTmp;
     278            1 :     return ret;
     279            4 : err:
     280            4 :     free(socketHandleTmp);
     281            4 :     socketHandleTmp = NULL;
     282            4 :     return ConverReturnCode(HCCP_INIT, ret);
     283              : }
     284              : 
     285            7 : HCCP_ATTRI_VISI_DEF int RaSocketInitV1(int mode, struct SocketInitInfoT socketInit, void **socketHandle)
     286              : {
     287              :     // 支持IPv4/IPv6 socket初始化
     288              :     // IPv6需要输入scope id
     289            7 :     struct RaSocketHandle *socketHandleTmp = NULL;
     290            7 :     char localIp[MAX_IP_LEN] = {0};
     291              :     int ret;
     292              : 
     293            7 :     CHK_PRT_RETURN(socketInit.rdevInfo.phyId >= RA_MAX_PHY_ID_NUM || socketHandle == NULL,
     294              :         hccp_err("[init][ra_socket]phyId(%u) is invalid! it must be [0,%d) or socket is null!",
     295              :             socketInit.rdevInfo.phyId, RA_MAX_PHY_ID_NUM),
     296              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     297              : 
     298            6 :     ret = RaInetPton(socketInit.rdevInfo.family, socketInit.rdevInfo.localIp, localIp, MAX_IP_LEN);
     299            6 :     CHK_PRT_RETURN(ret, hccp_err("[init][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     300              :         ConverReturnCode(HCCP_INIT, ret));
     301              : 
     302            5 :     hccp_run_info("socket init:mode=%d phyId=%u scope_id=%d family=%d ip=%s", mode, socketInit.rdevInfo.phyId,
     303              :         socketInit.scopeId, socketInit.rdevInfo.family, localIp);
     304              : 
     305            5 :     socketHandleTmp = calloc(1, sizeof(struct RaSocketHandle));
     306            5 :     CHK_PRT_RETURN(socketHandleTmp == NULL, hccp_err("[init][ra_socket]calloc for socket_handle failed"),
     307              :         ConverReturnCode(HCCP_INIT, -ENOMEM));
     308              : 
     309            4 :     if (mode == NETWORK_OFFLINE) {
     310            1 :         socketHandleTmp->socketOps = &gRaHdcSocketOps;
     311            1 :         socketHandleTmp->scopeId = socketInit.scopeId;
     312            3 :     } else if (mode == NETWORK_PEER_ONLINE) {
     313            2 :         socketHandleTmp->socketOps = &gRaPeerSocketOps;
     314            2 :         socketHandleTmp->scopeId = socketInit.scopeId;
     315              :     } else {
     316            1 :         hccp_err("[init][ra_socket]Wrong mode(%d), do not support", mode);
     317            1 :         ret = -EINVAL;
     318            1 :         goto err;
     319              :     }
     320              : 
     321            3 :     ret = memcpy_s(&(socketHandleTmp->rdevInfo), sizeof(struct rdev), &socketInit.rdevInfo, sizeof(struct rdev));
     322            3 :     if (ret) {
     323            1 :         hccp_err("[init][ra_socket]memcpy_s for rdev_info failed, ret(%d)", ret);
     324            1 :         ret = -ESAFEFUNC;
     325            1 :         goto err;
     326              :     }
     327              : 
     328            2 :     if (socketInit.rdevInfo.family == AF_INET && socketInit.rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX &&
     329            1 :         socketHandleTmp->socketOps->raSocketInit != NULL) {
     330              :         // HDC模式只支持IPv4
     331            1 :         if (socketInit.rdevInfo.localIp.addr.s_addr < RA_VNIC_MAX) {
     332            1 :             ret = socketHandleTmp->socketOps->raSocketInit(socketInit.rdevInfo);
     333            1 :             if (ret) {
     334            1 :                 hccp_err("[init][ra_socket]ra socket init v1 failed, ret(%d)", ret);
     335            1 :                 goto err;
     336              :             }
     337              :         }
     338              :     }
     339            1 :     *socketHandle = (void *)socketHandleTmp;
     340            1 :     return ret;
     341            3 : err:
     342            3 :     free(socketHandleTmp);
     343            3 :     socketHandleTmp = NULL;
     344            3 :     return ConverReturnCode(HCCP_INIT, ret);
     345              : }
     346              : 
     347            4 : HCCP_ATTRI_VISI_DEF int RaSocketDeinit(void *socketHandle)
     348              : {
     349            4 :     struct RaSocketHandle *socketHandleTmp = NULL;
     350              :     struct rdev rdevInfo;
     351            4 :     char localIp[MAX_IP_LEN] = {0};
     352              :     int ret;
     353              : 
     354            4 :     CHK_PRT_RETURN(socketHandle == NULL, hccp_err("[deinit][ra_socket]socket_handle is NULL"),
     355              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     356              : 
     357            3 :     socketHandleTmp = (struct RaSocketHandle *)socketHandle;
     358            3 :     rdevInfo = socketHandleTmp->rdevInfo;
     359            3 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM,
     360              :         hccp_err("[deinit][ra_socket]phyId(%u) >= %u. invalid", rdevInfo.phyId, RA_MAX_PHY_ID_NUM),
     361              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     362              : 
     363            2 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, MAX_IP_LEN);
     364            2 :     CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     365              :         ConverReturnCode(HCCP_INIT, ret));
     366              : 
     367            2 :     hccp_run_info("Input parameters: phyId[%u] family[%d] local_ip[%s]", rdevInfo.phyId, rdevInfo.family, localIp);
     368              : 
     369            2 :     ret = socketHandleTmp->socketOps->raSocketDeinit(rdevInfo);
     370            2 :     if (ret) {
     371            1 :         hccp_err("[deinit][ra_socket]ra socket deinit failed, ret(%d)", ret);
     372              :     }
     373              : 
     374            2 :     socketHandleTmp->socketOps = NULL;
     375            2 :     free(socketHandleTmp);
     376            2 :     socketHandleTmp = NULL;
     377            2 :     return ConverReturnCode(HCCP_INIT, ret);
     378              : }
     379              : 
     380           10 : STATIC int RaRdevInitCheckIp(int mode, struct rdev rdevInfo, char localIp[])
     381              : {
     382           10 :     struct InterfaceInfo *interfaceInfos = NULL;
     383           10 :     char interfaceIp[MAX_IP_LEN] = {0};
     384           10 :     struct RaGetIfattr config = {0};
     385              :     unsigned int i, interfaceVersion;
     386           10 :     unsigned int num = 0;
     387              :     int ret;
     388              : 
     389           10 :     config.phyId = rdevInfo.phyId;
     390           10 :     config.nicPosition = (unsigned int)mode;
     391           10 :     if (config.nicPosition == NETWORK_OFFLINE) {
     392            7 :         ret = RaGetInterfaceVersion(config.phyId, RA_RS_GET_IFNUM, &interfaceVersion);
     393            7 :         if (ret != 0 || interfaceVersion != RA_RS_GET_IFNUM_VERSION) {
     394            7 :             num = MAX_INTERFACE_NUM;
     395            7 :             goto get_addrs;
     396              :         }
     397              :     }
     398              :     /* get the number of interfaces */
     399            3 :     ret = RaGetIfnum(&config, &num);
     400            3 :     CHK_PRT_RETURN(ret != 0 || num == 0, hccp_err("[check][ip]get_ifnum failed, ret(%d) or num is 0", ret), -EINVAL);
     401              : 
     402            0 : get_addrs:
     403              :     /* calloc for interface_infos according to the real num */
     404            7 :     interfaceInfos = calloc(num, sizeof(struct InterfaceInfo));
     405            7 :     CHK_PRT_RETURN(interfaceInfos == NULL, hccp_err("[check][ip]calloc for interface_infos failed"), -EINVAL);
     406              : 
     407            6 :     ret = RaGetIfaddrs(&config, interfaceInfos, &num);
     408            6 :     if (ret != 0 || (num == 0)) {
     409            4 :         hccp_err("[check][ip]ra_get_ifaddrs for interface_infos failed, ret(%d), num(%u)", ret, num);
     410            4 :         free(interfaceInfos);
     411            4 :         return -EINVALIDIP;
     412              :     }
     413              : 
     414           10 :     for (i = 0; i < num; i++) {
     415            9 :         if (interfaceInfos[i].family != rdevInfo.family) {
     416            8 :             continue;
     417              :         }
     418              : 
     419            1 :         ret = RaInetPton(interfaceInfos[i].family, interfaceInfos[i].ifaddr.ip, interfaceIp, MAX_IP_LEN);
     420            1 :         if (ret != 0) {
     421            1 :             hccp_err("[check][ip]ra_inet_pton for interface_infos[%u] failed, ret(%d)", i, ret);
     422            1 :             free(interfaceInfos);
     423            1 :             return ret;
     424              :         }
     425              : 
     426            0 :         ret = strncmp(interfaceIp, localIp, MAX_IP_LEN - 1);
     427            0 :         if (ret == 0) {
     428            0 :             free(interfaceInfos);
     429            0 :             return 0;
     430              :         }
     431              :     }
     432            1 :     hccp_err("[check][ip]failed, ret(%d) the IP address(%s) in the ranktable is inconsistent with the IP(%s)"
     433              :              "address of the network adapter, please make sure they're consistent. "
     434              :              "num(%u)",
     435              :         ret, localIp, interfaceIp, num);
     436              : 
     437            1 :     free(interfaceInfos);
     438            1 :     return -EINVALIDIP;
     439              : }
     440              : 
     441           14 : int RaRdevInitCheck(int mode, struct rdev rdevInfo, char localIp[], unsigned int num, void *rdmaHandle)
     442              : {
     443              :     int ret;
     444              : 
     445           14 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM,
     446              :         hccp_err("[check][ra_rdev_init]phyId(%u) is invalid! "
     447              :                  "it must be greater than or equal to 0 and less than %d!",
     448              :             rdevInfo.phyId, RA_MAX_PHY_ID_NUM),
     449              :         -EINVAL);
     450              : 
     451           13 :     CHK_PRT_RETURN(rdmaHandle == NULL, hccp_err("[check][ra_rdev_init]phyId(%u) rdma_handle is null!", rdevInfo.phyId),
     452              :         -EINVAL);
     453              : 
     454           12 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, num);
     455           12 :     CHK_PRT_RETURN(ret, hccp_err("[check][ra_rdev_init]ra_inet_pton for local_ip failed, ret(%d)", ret), -EINVAL);
     456              : 
     457           11 :     ret = RaRdevInitCheckIp(mode, rdevInfo, localIp);
     458           11 :     CHK_PRT_RETURN(ret, hccp_err("[check][ra_rdev_init]ra_rdev_init_check_ip failed, ret(%d)", ret), ret);
     459              : 
     460            2 :     return 0;
     461              : }
     462              : 
     463            5 : STATIC int RaGetInitRdmaHandle(int mode, struct RaRdmaHandle *rdmaHandle)
     464              : {
     465            5 :     if (mode == NETWORK_OFFLINE) {
     466            2 :         (void)RaHdcRdmaSetOps(rdmaHandle, &gRaHdcRdmaOps);
     467            3 :     } else if (mode == NETWORK_PEER_ONLINE) {
     468            2 :         (void)RaHdcRdmaSetOps(rdmaHandle, &gRaPeerRdmaOps);
     469              :     } else {
     470            1 :         hccp_err("[init][ra_rdev]Wrong mode(%d), do not support", mode);
     471            1 :         return -EINVAL;
     472              :     }
     473              : 
     474            4 :     CHK_PRT_RETURN(rdmaHandle->rdmaOps->raRdevInit == NULL, hccp_err("[init][ra_rdev] ra_rdev_init is NULL!"), -EINVAL);
     475            4 :     return 0;
     476              : }
     477              : 
     478            2 : STATIC void RaGenerateGidByRdevInfo(struct RaRdmaHandle *rdmaHandle)
     479              : {
     480              : #define RA_GID_SEQ_NUM 4
     481              : #define RA_GID_SEQ_ZERO 0
     482              : #define RA_GID_SEQ_ONE 1
     483              : #define RA_GID_SEQ_TWO 2
     484              : #define RA_GID_SEQ_THREE 3
     485            2 :     union HccpIpAddr localIp = rdmaHandle->rdevInfo.localIp;
     486            2 :     int family = rdmaHandle->rdevInfo.family;
     487              :     unsigned int gidV4[RA_GID_SEQ_NUM];
     488              : 
     489            2 :     if (family == AF_INET6) {
     490            0 :         (void)memcpy_s(rdmaHandle->gid, HCCP_GID_RAW_LEN, &(localIp.addr6), HCCP_GID_RAW_LEN);
     491              :     } else {
     492            2 :         gidV4[RA_GID_SEQ_ZERO] = 0;
     493            2 :         gidV4[RA_GID_SEQ_ONE] = 0;
     494              :         /* The gid format generated by ipv4 is filled with 0xFFFF in [33, 48] */
     495            2 :         gidV4[RA_GID_SEQ_TWO] = htonl(0x0000FFFF);
     496            2 :         gidV4[RA_GID_SEQ_THREE] = localIp.addr.s_addr;
     497            2 :         (void)memcpy_s(rdmaHandle->gid, HCCP_GID_RAW_LEN, gidV4, HCCP_GID_RAW_LEN);
     498              :     }
     499              : 
     500            2 :     return;
     501              : }
     502              : 
     503           17 : STATIC int RaRdevInitWithBackupInfo(struct RdevInitInfo initInfo, struct rdev rdevInfo, struct RaBackupInfo backupInfo,
     504              :     void **rdmaHandle)
     505              : {
     506           17 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
     507           17 :     char localIp[MAX_IP_LEN] = {0};
     508              :     unsigned int rdevIndex;
     509              :     int ret;
     510              : 
     511           17 :     ret = RaRdevInitCheck(initInfo.mode, rdevInfo, localIp, MAX_IP_LEN, rdmaHandle);
     512           17 :     CHK_PRT_RETURN(ret, hccp_err("[init][ra_rdev]ra_rdev_init_check failed ,ret(%d)", ret),
     513              :         ConverReturnCode(HCCP_INIT, ret));
     514              : 
     515            6 :     hccp_run_info("rdev_init:mode=%d phyId=%u family=%d ip=%s notify_type=%u", initInfo.mode, rdevInfo.phyId,
     516              :         rdevInfo.family, localIp, initInfo.notifyType);
     517              : 
     518            6 :     rdmaHandleTmp = calloc(1, sizeof(struct RaRdmaHandle));
     519            6 :     CHK_PRT_RETURN(rdmaHandleTmp == NULL, hccp_err("[init][ra_rdev]calloc for rdma_handle failed"),
     520              :         ConverReturnCode(HCCP_INIT, -ENOMEM));
     521              : 
     522              :     // disabled_lite_thread will be invalid if enabled_910a_lite is false
     523            5 :     rdmaHandleTmp->disabledLiteThread = initInfo.disabledLiteThread;
     524            5 :     rdmaHandleTmp->enabled910aLite = initInfo.enabled910aLite;
     525            5 :     rdmaHandleTmp->enabled2mbLite = initInfo.enabled2mbLite;
     526            5 :     (void)memcpy_s(&rdmaHandleTmp->backupInfo, sizeof(struct RaBackupInfo), &backupInfo, sizeof(struct RaBackupInfo));
     527              : 
     528            5 :     ret = RaGetInitRdmaHandle(initInfo.mode, rdmaHandleTmp);
     529            5 :     if (ret) {
     530            1 :         hccp_err("[init][ra_rdev] get rdma handle failed, ret(%d)", ret);
     531            1 :         goto err;
     532              :     }
     533              : 
     534            4 :     ret = memcpy_s(&(rdmaHandleTmp->rdevInfo), sizeof(struct rdev), &rdevInfo, sizeof(struct rdev));
     535            4 :     if (ret) {
     536            1 :         hccp_err("[init][ra_rdev]memcpy_s for rdev_info failed, ret(%d)", ret);
     537            1 :         ret = -ESAFEFUNC;
     538            1 :         goto err;
     539              :     }
     540              : 
     541            3 :     ret = rdmaHandleTmp->rdmaOps->raRdevInit(rdmaHandleTmp, initInfo.notifyType, rdevInfo, &rdevIndex);
     542            3 :     if (ret) {
     543            1 :         hccp_err("[init][ra_rdev]ra rdev init failed, ret(%d)", ret);
     544            1 :         goto err;
     545              :     }
     546              : 
     547            2 :     rdmaHandleTmp->rdevIndex = rdevIndex;
     548            2 :     RaGenerateGidByRdevInfo(rdmaHandleTmp);
     549            2 :     *rdmaHandle = (void *)rdmaHandleTmp;
     550              : 
     551              :     // save rdev handle for helper
     552            2 :     RaRdevSetHandle(rdevInfo.phyId, *rdmaHandle);
     553              : 
     554            2 :     return ret;
     555            3 : err:
     556            3 :     free(rdmaHandleTmp);
     557            3 :     rdmaHandleTmp = NULL;
     558            3 :     return ConverReturnCode(HCCP_INIT, ret);
     559              : }
     560              : 
     561            2 : HCCP_ATTRI_VISI_DEF int RaRdevInitWithBackup(struct RdevInitInfo *initInfo, struct rdev *rdevInfo,
     562              :     struct rdev *backupRdevInfo, void **rdmaHandle)
     563              : {
     564            2 :     struct RaBackupInfo backupInfo = {0};
     565              : 
     566            2 :     if (initInfo == NULL || rdevInfo == NULL || backupRdevInfo == NULL || rdmaHandle == NULL) {
     567            1 :         hccp_err("[init][ra_rdev]init_info or rdev_info or backup_rdev_info or rdma_handle is NULL");
     568            1 :         return -EINVAL;
     569              :     }
     570              : 
     571            1 :     backupInfo.backupFlag = true;
     572            1 :     (void)memcpy_s(&backupInfo.rdevInfo, sizeof(struct rdev), backupRdevInfo, sizeof(struct rdev));
     573              : 
     574            1 :     return RaRdevInitWithBackupInfo(*initInfo, *rdevInfo, backupInfo, rdmaHandle);
     575              : }
     576              : 
     577           16 : HCCP_ATTRI_VISI_DEF int RaRdevInitV2(struct RdevInitInfo initInfo, struct rdev rdevInfo, void **rdmaHandle)
     578              : {
     579           16 :     struct RaBackupInfo backupInfo = {0};
     580              : 
     581           16 :     return RaRdevInitWithBackupInfo(initInfo, rdevInfo, backupInfo, rdmaHandle);
     582              : }
     583              : 
     584           16 : HCCP_ATTRI_VISI_DEF int RaRdevInit(int mode, unsigned int notifyType, struct rdev rdevInfo, void **rdmaHandle)
     585              : {
     586           16 :     struct RdevInitInfo initInfo = {0};
     587           16 :     initInfo.mode = mode;
     588           16 :     initInfo.notifyType = notifyType;
     589           16 :     initInfo.disabledLiteThread = false; // will start lite thread by default
     590           16 :     initInfo.enabled910aLite = false;    // will disabled lite on 910A by default
     591           16 :     initInfo.enabled2mbLite = false;     // will disabled lite on 2MB page align scenario by default
     592              : 
     593           16 :     return RaRdevInitV2(initInfo, rdevInfo, rdmaHandle);
     594              : }
     595              : 
     596            5 : STATIC int RaRdevDeinitParaCheck(void *rdmaHandle, struct RaRdmaHandle **rdmaHandleTmp)
     597              : {
     598              :     int ret;
     599            5 :     char localIp[MAX_IP_LEN] = {0};
     600              :     struct rdev rdevInfo;
     601              : 
     602            5 :     *rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
     603            5 :     rdevInfo = (*rdmaHandleTmp)->rdevInfo;
     604            5 :     CHK_PRT_RETURN(rdevInfo.phyId >= RA_MAX_PHY_ID_NUM,
     605              :         hccp_err("[deinit][ra_rdev]phyId(%u) "
     606              :                  "must be smaller than %u",
     607              :             rdevInfo.phyId, RA_MAX_PHY_ID_NUM),
     608              :         -EINVAL);
     609              : 
     610            4 :     ret = RaInetPton(rdevInfo.family, rdevInfo.localIp, localIp, MAX_IP_LEN);
     611            4 :     CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_rdev]ra_inet_pton for local_ip failed, ret(%d)", ret), ret);
     612              : 
     613            3 :     CHK_PRT_RETURN((*rdmaHandleTmp)->rdmaOps == NULL || (*rdmaHandleTmp)->rdmaOps->raRdevDeinit == NULL,
     614              :         hccp_err("[deinit][ra_rdev]rdma_ops is NULL or ra_rdev_deinit is NULL"), -EINVAL);
     615              : 
     616            2 :     hccp_run_info("Input parameters: phyId[%u] rdev_index[%u] family[%d] local_ip[%s]", rdevInfo.phyId,
     617              :         (*rdmaHandleTmp)->rdevIndex, rdevInfo.family, localIp);
     618              : 
     619            2 :     return 0;
     620              : }
     621              : 
     622            5 : HCCP_ATTRI_VISI_DEF int RaRdevGetPortStatus(void *rdmaHandle, enum PortStatus *status)
     623              : {
     624            5 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
     625              :     unsigned int phyId;
     626              :     int ret;
     627              : 
     628            5 :     CHK_PRT_RETURN(rdmaHandle == NULL || status == NULL,
     629              :         hccp_err("[get][ra_port_status]rdma_handle or status is NULL, invalid"), ConverReturnCode(RDMA_OP, -EINVAL));
     630              : 
     631            4 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
     632            4 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     633              :         hccp_err("[get][ra_port_status]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     634              :         ConverReturnCode(RDMA_OP, -EINVAL));
     635              : 
     636            3 :     CHK_PRT_RETURN(rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raRdevGetPortStatus == NULL,
     637              :         hccp_err("[get][ra_port_status]rdma_ops is NULL or ra_rdev_get_port_status is NULL, invalid"),
     638              :         ConverReturnCode(RDMA_OP, -EINVAL));
     639              : 
     640            2 :     ret = rdmaHandleTmp->rdmaOps->raRdevGetPortStatus(rdmaHandleTmp, status);
     641            2 :     return ConverReturnCode(RDMA_OP, ret);
     642              : }
     643              : 
     644            6 : HCCP_ATTRI_VISI_DEF int RaRdevDeinit(void *rdmaHandle, unsigned int notifyType)
     645              : {
     646            6 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
     647              :     unsigned int phyId;
     648              :     int ret;
     649              : 
     650            6 :     CHK_PRT_RETURN(rdmaHandle == NULL, hccp_err("[deinit][ra_rdev] rdma_handle is NULL"),
     651              :         ConverReturnCode(HCCP_INIT, -EINVAL));
     652              : 
     653            5 :     ret = RaRdevDeinitParaCheck(rdmaHandle, &rdmaHandleTmp);
     654            5 :     CHK_PRT_RETURN(ret, hccp_err("[deinit][ra_rdev] para check failed, ret(%d)", ret),
     655              :         ConverReturnCode(HCCP_INIT, ret));
     656              : 
     657            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
     658              : 
     659            2 :     ret = rdmaHandleTmp->rdmaOps->raRdevDeinit(rdmaHandleTmp, notifyType);
     660            2 :     if (ret) {
     661            0 :         hccp_err("[deinit][ra_rdev]ra rdev deinit failed, ret(%d)", ret);
     662            0 :         goto free_rdma_handle;
     663              :     }
     664              : 
     665            2 : free_rdma_handle:
     666            2 :     rdmaHandleTmp->rdmaOps = NULL;
     667            2 :     free(rdmaHandleTmp);
     668            2 :     rdmaHandleTmp = NULL;
     669            2 :     RaRdevSetHandle(phyId, NULL);
     670            2 :     return ConverReturnCode(HCCP_INIT, ret);
     671              : }
     672              : 
     673            2 : HCCP_ATTRI_VISI_DEF int RaRdevGetSupportLite(void *rdmaHandle, int *supportLite)
     674              : {
     675            2 :     struct RaRdmaHandle *rdmaHandleTmp = NULL;
     676              : 
     677            2 :     CHK_PRT_RETURN(rdmaHandle == NULL || supportLite == NULL,
     678              :         hccp_err("[get][ra_rdev]rdma_handle is NULL or support_lite is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
     679              : 
     680            1 :     rdmaHandleTmp = (struct RaRdmaHandle *)rdmaHandle;
     681            1 :     *supportLite = rdmaHandleTmp->supportLite;
     682              : 
     683            1 :     hccp_dbg("[get][ra_rdev]support_lite:%d", *supportLite);
     684              : 
     685            1 :     return 0;
     686              : }
     687              : 
     688            4 : HCCP_ATTRI_VISI_DEF int RaSocketBatchConnect(struct SocketConnectInfoT conn[], unsigned int num)
     689              : {
     690            4 :     struct RaSocketHandle *socketHandle = NULL;
     691            4 :     char remoteIp[MAX_IP_LEN] = {0};
     692            4 :     char localIp[MAX_IP_LEN] = {0};
     693              :     unsigned int i;
     694              :     int ret;
     695              : 
     696            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     697              :         hccp_err("[batch_connect][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     698              :             MAX_SOCKET_NUM),
     699              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     700              : 
     701            4 :     for (i = 0; i < num; i++) {
     702            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     703            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     704            2 :             socketHandle->socketOps->raSocketBatchConnect == NULL) {
     705            1 :             hccp_err("[batch_connect][ra_socket]socket_handle or func is NULL");
     706            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     707              :         }
     708              : 
     709            2 :         CHK_PRT_RETURN(socketHandle->rdevInfo.phyId >= RA_MAX_PHY_ID_NUM,
     710              :             hccp_err("[batch_connect][ra_socket]phyId(%u) must be smaller than %u", socketHandle->rdevInfo.phyId,
     711              :                 RA_MAX_PHY_ID_NUM),
     712              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     713              : 
     714            1 :         CHK_PRT_RETURN(strlen(conn[i].tag) >= SOCK_CONN_TAG_SIZE,
     715              :             hccp_err("[batch_connect][ra_socket]conn tag len(%d) more than max len(%d)", strlen(conn[i].tag),
     716              :                 SOCK_CONN_TAG_SIZE),
     717              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     718              : 
     719            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     720            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_connect][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     721              :             ConverReturnCode(SOCKET_OP, ret));
     722              : 
     723            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
     724            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_connect][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
     725              :             ConverReturnCode(SOCKET_OP, ret));
     726              : 
     727            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], remoteIp[%s], port[%u], tag[%s], cnt[%u]", i,
     728              :             socketHandle->rdevInfo.phyId, localIp, remoteIp, conn[i].port, conn[i].tag, socketHandle->connectCnt);
     729              :     }
     730              : 
     731            1 :     socketHandle->connectCnt++;
     732            1 :     ret = socketHandle->socketOps->raSocketBatchConnect(socketHandle->rdevInfo.phyId, conn, num);
     733            1 :     return ConverReturnCode(SOCKET_OP, ret);
     734              : }
     735              : 
     736            4 : HCCP_ATTRI_VISI_DEF int RaSocketBatchClose(struct SocketCloseInfoT conn[], unsigned int num)
     737              : {
     738            4 :     struct RaSocketHandle *socketHandle = NULL;
     739            4 :     char localIp[MAX_IP_LEN] = {0};
     740            4 :     unsigned int phyId = 0;
     741              :     unsigned int i;
     742              :     int ret;
     743              : 
     744            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     745              :         hccp_err("[batch_close][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     746              :             MAX_SOCKET_NUM),
     747              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     748              : 
     749            4 :     for (i = 0; i < num; i++) {
     750            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     751            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     752            2 :             socketHandle->socketOps->raSocketBatchClose == NULL) {
     753            1 :             hccp_warn("[batch_close][ra_socket]socket_handle or func is NULL, no need to close");
     754            1 :             return 0;
     755              :         }
     756            2 :         phyId = socketHandle->rdevInfo.phyId;
     757            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     758              :             hccp_err("[batch_close][ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     759              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     760              : 
     761            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     762            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_connect][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     763              :             ConverReturnCode(SOCKET_OP, ret));
     764              : 
     765            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], cnt[%u]", i, phyId, localIp,
     766              :             socketHandle->closeCnt);
     767              :     }
     768              : 
     769            1 :     socketHandle->closeCnt++;
     770            1 :     ret = socketHandle->socketOps->raSocketBatchClose(phyId, conn, num);
     771            1 :     return ConverReturnCode(SOCKET_OP, ret);
     772              : }
     773              : 
     774            5 : HCCP_ATTRI_VISI_DEF int RaSocketBatchAbort(struct SocketConnectInfoT conn[], unsigned int num)
     775              : {
     776            5 :     struct RaSocketHandle *socketHandle = NULL;
     777            5 :     char remoteIp[MAX_IP_LEN] = {0};
     778            5 :     char localIp[MAX_IP_LEN] = {0};
     779            5 :     unsigned int phyId = 0;
     780              :     unsigned int i;
     781              :     int ret;
     782              : 
     783            5 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     784              :         hccp_err("[batch_abort][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     785              :             MAX_SOCKET_NUM),
     786              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     787              : 
     788            5 :     for (i = 0; i < num; i++) {
     789            4 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     790            4 :         CHK_PRT_RETURN(socketHandle == NULL || socketHandle->socketOps == NULL ||
     791              :                            socketHandle->socketOps->raSocketBatchAbort == NULL,
     792              :             hccp_err("[batch_abort][ra_socket]socket_handle or func is NULL"), ConverReturnCode(SOCKET_OP, -EINVAL));
     793              : 
     794            3 :         phyId = socketHandle->rdevInfo.phyId;
     795            3 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     796              :             hccp_err("[batch_abort][ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     797              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     798              : 
     799            3 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     800            3 :         CHK_PRT_RETURN(ret, hccp_err("[batch_abort][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     801              :             ConverReturnCode(SOCKET_OP, ret));
     802              : 
     803            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
     804            1 :         CHK_PRT_RETURN(ret, hccp_err("[batch_abort][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
     805              :             ConverReturnCode(SOCKET_OP, ret));
     806              : 
     807            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], remoteIp[%s], tag[%s], cnt[%u]", i, phyId,
     808              :             localIp, remoteIp, conn[i].tag, socketHandle->abortCnt);
     809              :     }
     810              : 
     811            1 :     socketHandle->abortCnt++;
     812            1 :     ret = socketHandle->socketOps->raSocketBatchAbort(phyId, conn, num);
     813            1 :     return ConverReturnCode(SOCKET_OP, ret);
     814              : }
     815              : 
     816            4 : HCCP_ATTRI_VISI_DEF int RaSocketListenStart(struct SocketListenInfoT conn[], unsigned int num)
     817              : {
     818            4 :     struct RaSocketHandle *socketHandle = NULL;
     819            4 :     char localIp[MAX_IP_LEN] = {0};
     820            4 :     unsigned int phyId = 0;
     821              :     unsigned int i;
     822              :     int ret;
     823              : 
     824            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     825              :         hccp_err("[listen_start][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     826              :             MAX_SOCKET_NUM),
     827              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     828              : 
     829            4 :     for (i = 0; i < num; i++) {
     830            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     831            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     832            2 :             socketHandle->socketOps->raSocketListenStart == NULL) {
     833            1 :             hccp_err("[listen_start][ra_socket]socket_handle or func is NULL");
     834            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     835              :         }
     836            2 :         phyId = socketHandle->rdevInfo.phyId;
     837            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     838              :             hccp_err("[listen_start][ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     839              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     840              : 
     841            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     842            1 :         CHK_PRT_RETURN(ret, hccp_err("[listen_start][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
     843              :             ConverReturnCode(SOCKET_OP, ret));
     844              : 
     845            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], port[%u]", i, phyId, localIp, conn[i].port);
     846              :     }
     847              : 
     848            1 :     ret = socketHandle->socketOps->raSocketListenStart(phyId, conn, num);
     849            1 :     return ConverReturnCode(SOCKET_OP, ret);
     850              : }
     851              : 
     852            4 : HCCP_ATTRI_VISI_DEF int RaSocketListenStop(struct SocketListenInfoT conn[], unsigned int num)
     853              : {
     854            4 :     struct RaSocketHandle *socketHandle = NULL;
     855            4 :     char localIp[MAX_IP_LEN] = {0};
     856            4 :     unsigned int phyId = 0;
     857              :     unsigned int i;
     858              :     int ret;
     859              : 
     860            4 :     CHK_PRT_RETURN(conn == NULL || num == 0 || num > MAX_SOCKET_NUM,
     861              :         hccp_err("[listen_stop][ra_socket]conn is NULL or num[%u] is zero or num is greater than %d", num,
     862              :             MAX_SOCKET_NUM),
     863              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     864              : 
     865            4 :     for (i = 0; i < num; i++) {
     866            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     867            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL ||
     868            2 :             socketHandle->socketOps->raSocketListenStop == NULL) {
     869            1 :             hccp_err("[listen_stop][ra_socket]socket_handle or func is NULL");
     870            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     871              :         }
     872              : 
     873            2 :         phyId = socketHandle->rdevInfo.phyId;
     874            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     875              :             hccp_err("[listen_stop][ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     876              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     877              : 
     878            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     879            1 :         CHK_PRT_RETURN(ret, hccp_err("[listen_stop][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
     880              :             ConverReturnCode(SOCKET_OP, ret));
     881              : 
     882            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s]", i, phyId, localIp);
     883              :     }
     884              : 
     885            1 :     ret = socketHandle->socketOps->raSocketListenStop(phyId, conn, num);
     886            1 :     return ConverReturnCode(SOCKET_OP, ret);
     887              : }
     888              : 
     889            4 : HCCP_ATTRI_VISI_DEF int RaGetSockets(unsigned int role, struct SocketInfoT conn[], unsigned int num,
     890              :     unsigned int *connectedNum)
     891              : {
     892              :     unsigned int i;
     893            4 :     struct RaSocketHandle *socketHandle = NULL;
     894            4 :     char localIp[MAX_IP_LEN] = {0};
     895            4 :     char remoteIp[MAX_IP_LEN] = {0};
     896              :     int ret;
     897            4 :     unsigned int phyId = 0;
     898              : 
     899            4 :     CHK_PRT_RETURN(conn == NULL || connectedNum == NULL || num == 0 || num > MAX_SOCKET_NUM,
     900              :         hccp_err("[get][ra_socket]conn or connected_num is NULL or num[%u] is zero or num greater than %d", num,
     901              :             MAX_SOCKET_NUM),
     902              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     903              : 
     904            4 :     for (i = 0; i < num; i++) {
     905            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
     906            3 :         if (socketHandle == NULL || socketHandle->socketOps == NULL || socketHandle->socketOps->raGetSockets == NULL) {
     907            1 :             hccp_err("[get][ra_socket]socket_handle or func is NULL");
     908            1 :             return ConverReturnCode(SOCKET_OP, -EINVAL);
     909              :         }
     910              : 
     911            2 :         phyId = socketHandle->rdevInfo.phyId;
     912            2 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     913              :             hccp_err("[get][ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     914              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     915              : 
     916            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     917            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     918              :             ConverReturnCode(SOCKET_OP, ret));
     919              : 
     920            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
     921            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
     922              :             ConverReturnCode(SOCKET_OP, ret));
     923              :     }
     924              : 
     925            1 :     ret = socketHandle->socketOps->raGetSockets(phyId, role, conn, num);
     926            1 :     if (ret >= 0) {
     927            1 :         *connectedNum = (unsigned int)ret;
     928            1 :         return 0;
     929              :     }
     930              : 
     931            0 :     *connectedNum = 0;
     932            0 :     return ConverReturnCode(SOCKET_OP, ret);
     933              : }
     934              : 
     935            5 : HCCP_ATTRI_VISI_DEF int RaSocketRecv(const void *fdHandle, void *data, unsigned long long size,
     936              :     unsigned long long *receivedSize)
     937              : {
     938              :     int ret;
     939              :     unsigned int phyId;
     940            5 :     const struct RaSocketHandle *socketHandleTmp = NULL;
     941            5 :     const struct SocketHdcInfo *fdHandleTmp = (const struct SocketHdcInfo *)fdHandle;
     942              : 
     943            5 :     CHK_PRT_RETURN(fdHandle == NULL || data == NULL || size == 0 || receivedSize == NULL,
     944              :         hccp_err("[recv][ra_socket]fd_handle or data or received_size is NULL or size[%llu] is 0", size),
     945              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     946              : 
     947            4 :     socketHandleTmp = (const struct RaSocketHandle *)(fdHandleTmp->socketHandle);
     948            4 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
     949            3 :         socketHandleTmp->socketOps->raSocketRecv == NULL) {
     950            1 :         hccp_err("[recv][ra_socket]socket_handle_tmp or func is NULL");
     951            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
     952              :     }
     953            3 :     phyId = socketHandleTmp->rdevInfo.phyId;
     954            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     955              :         hccp_err("[recv][ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     956              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     957              : 
     958            2 :     ret = socketHandleTmp->socketOps->raSocketRecv(phyId, fdHandle, data, size);
     959            2 :     if (ret > 0) {
     960            1 :         *receivedSize = (unsigned long long)(unsigned int)ret;
     961            1 :         return 0;
     962            1 :     } else if (ret == 0) {
     963            1 :         hccp_warn("[recv][ra_socket]socket has been closed. received_size is 0");
     964            1 :         ret = -ESOCKCLOSED;
     965              :     }
     966              : 
     967            1 :     *receivedSize = 0;
     968            1 :     return ConverReturnCode(SOCKET_OP, ret);
     969              : }
     970              : 
     971            5 : HCCP_ATTRI_VISI_DEF int RaSocketSend(const void *fdHandle, const void *data, unsigned long long size,
     972              :     unsigned long long *sentSize)
     973              : {
     974              :     int ret;
     975              :     unsigned int phyId;
     976            5 :     const struct RaSocketHandle *socketHandleTmp = NULL;
     977            5 :     const struct SocketHdcInfo *fdHandleTmp = (const struct SocketHdcInfo *)fdHandle;
     978              : 
     979            5 :     CHK_PRT_RETURN(fdHandle == NULL || data == NULL || sentSize == NULL || size == 0,
     980              :         hccp_err("[send][ra_socket]fd_handle or data or sent_size is NULL or size[%llu] is 0", size),
     981              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     982              : 
     983            4 :     socketHandleTmp = (const struct RaSocketHandle *)(fdHandleTmp->socketHandle);
     984            4 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
     985            3 :         socketHandleTmp->socketOps->raSocketSend == NULL) {
     986            1 :         hccp_err("[send][ra_socket]socket_handle_tmp or func is NULL");
     987            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
     988              :     }
     989              : 
     990            3 :     phyId = socketHandleTmp->rdevInfo.phyId;
     991            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
     992              :         hccp_err("[send][ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
     993              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     994              : 
     995            2 :     ret = socketHandleTmp->socketOps->raSocketSend(phyId, fdHandle, data, size);
     996            2 :     if (ret > 0) {
     997            1 :         *sentSize = (unsigned long long)(unsigned int)ret;
     998            1 :         return 0;
     999            1 :     } else if (ret == 0) {
    1000            1 :         hccp_warn("[send][ra_socket]socket has been closed. sent_size is 0");
    1001            1 :         ret = -ESOCKCLOSED;
    1002              :     }
    1003              : 
    1004            1 :     *sentSize = 0;
    1005            1 :     return ConverReturnCode(SOCKET_OP, ret);
    1006              : }
    1007              : 
    1008            0 : HCCP_ATTRI_VISI_DEF int RaEpollCtlAdd(const void *fdHandle, enum RaEpollEvent event)
    1009              : {
    1010            0 :     CHK_PRT_RETURN(fdHandle == NULL, hccp_err("[ra_epoll_ctl_add]fd_handle is NULL"),
    1011              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1012              : 
    1013            0 :     CHK_PRT_RETURN(event != RA_EPOLLIN && event != RA_EPOLLONESHOT,
    1014              :         hccp_err("[ra_epoll_ctl_add]wrong event, only RA_EPOLLIN and RA_EPOLLONESHOT are supported."),
    1015              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1016              : 
    1017            0 :     int ret = RaPeerEpollCtlAdd(fdHandle, event);
    1018            0 :     CHK_PRT_RETURN(ret, hccp_err("[ra_epoll_ctl_add]ra_peer_epoll_ctl_add failed ret(%d)", ret),
    1019              :         ConverReturnCode(SOCKET_OP, ret));
    1020              : 
    1021            0 :     return 0;
    1022              : }
    1023              : 
    1024            0 : HCCP_ATTRI_VISI_DEF int RaEpollCtlMod(const void *fdHandle, enum RaEpollEvent event)
    1025              : {
    1026            0 :     CHK_PRT_RETURN(fdHandle == NULL, hccp_err("[ra_epoll_ctl_mod]fd_handle is NULL"),
    1027              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1028              : 
    1029            0 :     CHK_PRT_RETURN(event != RA_EPOLLIN && event != RA_EPOLLONESHOT,
    1030              :         hccp_err("[ra_epoll_ctl_mod]wrong event, only RA_EPOLLIN and RA_EPOLLONESHOT are supported."),
    1031              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1032              : 
    1033            0 :     int ret = RaPeerEpollCtlMod(fdHandle, event);
    1034            0 :     CHK_PRT_RETURN(ret, hccp_err("[ra_epoll_ctl_mod]ra_peer_epoll_ctl_mod failed ret(%d)", ret),
    1035              :         ConverReturnCode(SOCKET_OP, ret));
    1036              : 
    1037            0 :     return 0;
    1038              : }
    1039              : 
    1040            0 : HCCP_ATTRI_VISI_DEF int RaEpollCtlDel(const void *fdHandle)
    1041              : {
    1042            0 :     CHK_PRT_RETURN(fdHandle == NULL, hccp_err("[ra_epoll_ctl_del]fd_handle is NULL"),
    1043              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1044              : 
    1045            0 :     int ret = RaPeerEpollCtlDel(fdHandle);
    1046            0 :     CHK_PRT_RETURN(ret, hccp_err("[ra_epoll_ctl_del]ra_peer_epoll_ctl_del failed ret(%d)", ret),
    1047              :         ConverReturnCode(SOCKET_OP, ret));
    1048              : 
    1049            0 :     return 0;
    1050              : }
    1051              : 
    1052            3 : HCCP_ATTRI_VISI_DEF int RaSetTcpRecvCallback(const void *socketHandle, const void *callback)
    1053              : {
    1054            3 :     const struct RaSocketHandle *socketHandleTmp = (const struct RaSocketHandle *)socketHandle;
    1055              :     unsigned int phyId;
    1056              : 
    1057            3 :     CHK_PRT_RETURN(socketHandleTmp == NULL || callback == NULL,
    1058              :         hccp_err("[ra_socket]socket_handle is NULL or callback is NULL"), ConverReturnCode(SOCKET_OP, -EINVAL));
    1059              : 
    1060            2 :     phyId = socketHandleTmp->rdevInfo.phyId;
    1061            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1062              :         hccp_err("[ra_socket]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
    1063              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1064              : 
    1065            1 :     RaPeerSetTcpRecvCallback(phyId, callback);
    1066              : 
    1067            1 :     return 0;
    1068              : }
    1069              : 
    1070            4 : HCCP_ATTRI_VISI_DEF int RaGetTsqpDepth(void *rdevHandle, unsigned int *tempDepth, unsigned int *qpNum)
    1071              : {
    1072            4 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1073              :     unsigned int phyId;
    1074              :     int ret;
    1075              : 
    1076            4 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1077              :                        rdmaHandleTmp->rdmaOps->raGetTsqpDepth == NULL,
    1078              :         hccp_err("[get][ra_tsqp_depth]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1079              : 
    1080            3 :     CHK_PRT_RETURN(tempDepth == NULL || qpNum == NULL, hccp_err("[get][ra_tsqp_depth]temp_depth or qp_num is NULL"),
    1081              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1082              : 
    1083            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1084            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1085              :         hccp_err("[get][ra_tsqp_depth]phyId(%u) is invalid! it must be greater than or equal to 0 and less than %d!",
    1086              :             phyId, RA_MAX_PHY_ID_NUM),
    1087              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1088              : 
    1089            1 :     hccp_info("Input parameters: phyId[%u], rdevIndex[%u]", phyId, rdmaHandleTmp->rdevIndex);
    1090              : 
    1091            1 :     ret = rdmaHandleTmp->rdmaOps->raGetTsqpDepth(rdmaHandleTmp, tempDepth, qpNum);
    1092            1 :     return ConverReturnCode(RDMA_OP, ret);
    1093              : }
    1094              : 
    1095            5 : HCCP_ATTRI_VISI_DEF int RaSetTsqpDepth(void *rdevHandle, unsigned int tempDepth, unsigned int *qpNum)
    1096              : {
    1097            5 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1098              :     unsigned int phyId;
    1099              :     int ret;
    1100              : 
    1101            5 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1102              :                        rdmaHandleTmp->rdmaOps->raSetTsqpDepth == NULL,
    1103              :         hccp_err("[set][ra_tsqp_depth]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1104              : 
    1105            4 :     CHK_PRT_RETURN(qpNum == NULL, hccp_err("[set][ra_tsqp_depth]qp_num is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1106              : 
    1107            3 :     CHK_PRT_RETURN(tempDepth < RA_MIN_TEMPTH_DEPTH || tempDepth > RA_MAX_TEMPTH_DEPTH,
    1108              :         hccp_err("[set][ra_tsqp_depth]param error! temp_depth(%u) cannot be smaller than %d or bigger than %d",
    1109              :             tempDepth, RA_MIN_TEMPTH_DEPTH, RA_MAX_TEMPTH_DEPTH),
    1110              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1111              : 
    1112            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1113            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1114              :         hccp_err("[set][ra_tsqp_depth]phyId(%u) is invalid! it must be greater than or equal to 0 and less than %d!",
    1115              :             phyId, RA_MAX_PHY_ID_NUM),
    1116              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1117              : 
    1118            1 :     hccp_run_info("Input parameters: phyId[%u], rdevIndex[%u], tempDepth[%u]", phyId, rdmaHandleTmp->rdevIndex,
    1119              :         tempDepth);
    1120              : 
    1121            1 :     ret = rdmaHandleTmp->rdmaOps->raSetTsqpDepth(rdmaHandleTmp, tempDepth, qpNum);
    1122            1 :     return ConverReturnCode(RDMA_OP, ret);
    1123              : }
    1124              : 
    1125            9 : HCCP_ATTRI_VISI_DEF int RaQpCreate(void *rdevHandle, int flag, int qpMode, void **qpHandle)
    1126              : {
    1127            9 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1128              :     unsigned int phyId;
    1129              :     int ret;
    1130              : 
    1131            9 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raQpCreate == NULL,
    1132              :         hccp_err("[create][ra_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1133              : 
    1134            6 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_qp]qp_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1135              : 
    1136              :     /* 0 means RC mode */
    1137            5 :     CHK_PRT_RETURN(flag != 0, hccp_err("[create][ra_qp]The flag(%d) is invalid, expect 0", flag),
    1138              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1139              : 
    1140            4 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1141            4 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1142              :         hccp_err("[create][ra_qp]phyId(%u) must be greater than or equal to 0 and less than %d!", phyId,
    1143              :             RA_MAX_PHY_ID_NUM),
    1144              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1145              : 
    1146            3 :     CHK_PRT_RETURN(qpMode < 0 || qpMode >= RA_RS_ERR_QP_MODE,
    1147              :         hccp_err("[create][ra_qp]QP mode(%d) must be greater than or equal to 0 and less than %d", qpMode,
    1148              :             RA_RS_ERR_QP_MODE),
    1149              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1150              : 
    1151            2 :     hccp_run_info("Input parameters: phyId[%u], flag[%d] qpMode [%d]", phyId, flag, qpMode);
    1152              : 
    1153            2 :     ret = rdmaHandleTmp->rdmaOps->raQpCreate(rdmaHandleTmp, flag, qpMode, qpHandle);
    1154            2 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1155              :         hccp_err("[create][ra_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId), ConverReturnCode(RDMA_OP, ret));
    1156              : 
    1157            2 :     return 0;
    1158              : }
    1159              : 
    1160            8 : HCCP_ATTRI_VISI_DEF int RaQpCreateWithAttrs(void *rdevHandle, struct QpExtAttrs *extAttrs, void **qpHandle)
    1161              : {
    1162            8 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1163              :     unsigned int phyId;
    1164              :     int ret;
    1165              : 
    1166            8 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1167              :                        rdmaHandleTmp->rdmaOps->raQpCreateWithAttrs == NULL,
    1168              :         hccp_err("[create][ra_qp_with_attrs]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1169              : 
    1170            6 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_qp_with_attrs]qp_handle is NULL"),
    1171              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1172              : 
    1173            5 :     CHK_PRT_RETURN(extAttrs == NULL, hccp_err("[create][ra_qp_with_attrs]ext_attrs is NULL"),
    1174              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1175              : 
    1176            4 :     CHK_PRT_RETURN(extAttrs->version != QP_CREATE_WITH_ATTR_VERSION,
    1177              :         hccp_err("[create][ra_qp_with_attrs]attr version[%d] mismatch, expect [%d]", extAttrs->version,
    1178              :             QP_CREATE_WITH_ATTR_VERSION),
    1179              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1180              : 
    1181            3 :     CHK_PRT_RETURN(extAttrs->qpMode < 0 || extAttrs->qpMode >= RA_RS_ERR_QP_MODE,
    1182              :         hccp_err("[create][ra_qp_with_attrs]QP mode[%d] must be greater than or equal to 0 and less than %d",
    1183              :             extAttrs->qpMode, RA_RS_ERR_QP_MODE),
    1184              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1185              :     // no need and disallow to set data_plane_flag, set it to default value 0
    1186            2 :     extAttrs->dataPlaneFlag.value = 0;
    1187              : 
    1188            2 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1189            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1190              :         hccp_err("[create][ra_qp_with_attrs]phyId(%u) must be greater than or equal to 0 and less than %d!", phyId,
    1191              :             RA_MAX_PHY_ID_NUM),
    1192              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1193              : 
    1194            1 :     hccp_run_info("Input parameters: phyId[%u] qp_mode[%d] cq_attr{%d,%d,%d,%d} qpAttr.cap{%u,%u,%u,%u,%u}"
    1195              :                   " qp_type[%u] sqSigAll[%d], cnt[%u], useResvMem[%u], resvMemPoolId[%u]",
    1196              :         phyId, extAttrs->qpMode, extAttrs->cqAttr.sendCqDepth, extAttrs->cqAttr.sendCqCompVector,
    1197              :         extAttrs->cqAttr.recvCqDepth, extAttrs->cqAttr.recvCqCompVector, extAttrs->qpAttr.cap.max_send_wr,
    1198              :         extAttrs->qpAttr.cap.max_recv_wr, extAttrs->qpAttr.cap.max_send_sge, extAttrs->qpAttr.cap.max_recv_sge,
    1199              :         extAttrs->qpAttr.cap.max_inline_data, extAttrs->qpAttr.qp_type, extAttrs->qpAttr.sq_sig_all,
    1200              :         rdmaHandleTmp->qpCnt, extAttrs->cstmFlag.bs.useResvMem, extAttrs->resvMemPoolId);
    1201              : 
    1202            1 :     rdmaHandleTmp->qpCnt++;
    1203            1 :     ret = rdmaHandleTmp->rdmaOps->raQpCreateWithAttrs(rdmaHandleTmp, extAttrs, qpHandle);
    1204            1 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1205              :         hccp_err("[create][ra_qp_with_attrs]create qp failed, ret(%d) phyId(%u)", ret, phyId),
    1206              :         ConverReturnCode(RDMA_OP, ret));
    1207              : 
    1208            1 :     return 0;
    1209              : }
    1210              : 
    1211            6 : HCCP_ATTRI_VISI_DEF int RaAiQpCreate(void *rdevHandle, struct QpExtAttrs *attrs, struct AiQpInfo *info, void **qpHandle)
    1212              : {
    1213            6 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1214            6 :     unsigned int interfaceVersion = 0;
    1215              :     unsigned int phyId;
    1216              :     int ret;
    1217              : 
    1218            6 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1219              :                        rdmaHandleTmp->rdmaOps->raAiQpCreate == NULL ||
    1220              :                        rdmaHandleTmp->rdmaOps->raAiQpCreateWithAttrs == NULL,
    1221              :         hccp_err("[create][ra_ai_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1222              : 
    1223            5 :     CHK_PRT_RETURN(info == NULL || qpHandle == NULL, hccp_err("[create][ra_ai_qp]info is NULL or qp_handle is NULL"),
    1224              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1225              : 
    1226            4 :     CHK_PRT_RETURN(attrs == NULL, hccp_err("[create][ra_ai_qp]attrs is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1227              : 
    1228            3 :     CHK_PRT_RETURN(attrs->version != QP_CREATE_WITH_ATTR_VERSION,
    1229              :         hccp_err("[create][ra_ai_qp]attr version[%d] mismatch, expect [%d]", attrs->version,
    1230              :             QP_CREATE_WITH_ATTR_VERSION),
    1231              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1232              : 
    1233            2 :     CHK_PRT_RETURN(attrs->qpMode < 0 || attrs->qpMode >= RA_RS_ERR_QP_MODE,
    1234              :         hccp_err("[create][ra_ai_qp]QP mode[%d] must be greater than or equal to 0 and less than %d", attrs->qpMode,
    1235              :             RA_RS_ERR_QP_MODE),
    1236              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1237              : 
    1238            1 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1239            1 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1240              :         hccp_err("[create][ra_ai_qp]phyId(%u) must be greater than or equal to 0 and less than %d!", phyId,
    1241              :             RA_MAX_PHY_ID_NUM),
    1242              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1243              : 
    1244            1 :     hccp_run_info("Input parameters: phyId[%u] qp_mode[%d] cq_attr{%d,%d,%d,%d} cqCstm[%d] "
    1245              :                   "qpAttr.cap{%u,%u,%u,%u,%u} qp_type[%u] sqSigAll[%d]",
    1246              :         phyId, attrs->qpMode, attrs->cqAttr.sendCqDepth, attrs->cqAttr.sendCqCompVector, attrs->cqAttr.recvCqDepth,
    1247              :         attrs->cqAttr.recvCqCompVector, attrs->dataPlaneFlag.bs.cqCstm, attrs->qpAttr.cap.max_send_wr,
    1248              :         attrs->qpAttr.cap.max_recv_wr, attrs->qpAttr.cap.max_send_sge, attrs->qpAttr.cap.max_recv_sge,
    1249              :         attrs->qpAttr.cap.max_inline_data, attrs->qpAttr.qp_type, attrs->qpAttr.sq_sig_all);
    1250              : 
    1251            1 :     ret = RaGetInterfaceVersion(phyId, RA_RS_AI_QP_CREATE_WITH_ATTRS, &interfaceVersion);
    1252            1 :     if (ret == 0 && interfaceVersion >= RA_RS_OPCODE_BASE_VERSION) {
    1253            1 :         ret = rdmaHandleTmp->rdmaOps->raAiQpCreateWithAttrs(rdmaHandleTmp, attrs, info, qpHandle);
    1254              :     } else {
    1255              :         // origin procedure: not support to process data_plane_flag.bs.cq_cstm
    1256            0 :         ret = rdmaHandleTmp->rdmaOps->raAiQpCreate(rdmaHandleTmp, attrs, info, qpHandle);
    1257              :     }
    1258            1 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1259              :         hccp_err("[create][ra_ai_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId), ConverReturnCode(RDMA_OP, ret));
    1260              : 
    1261            1 :     return 0;
    1262              : }
    1263              : 
    1264            8 : HCCP_ATTRI_VISI_DEF int RaTypicalQpCreate(void *rdevHandle, int flag, int qpMode, struct TypicalQp *qpInfo,
    1265              :     void **qpHandle)
    1266              : {
    1267            8 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1268              :     unsigned int phyId;
    1269              :     int ret;
    1270              : 
    1271            8 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1272              :                        rdmaHandleTmp->rdmaOps->raTypicalQpCreate == NULL,
    1273              :         hccp_err("[create][ra_typical_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1274              : 
    1275            6 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_typical_qp]qp_handle is NULL"),
    1276              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1277              : 
    1278            5 :     CHK_PRT_RETURN(qpInfo == NULL, hccp_err("[create][ra_typical_qp]qp_info is NULL"),
    1279              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1280              : 
    1281            4 :     CHK_PRT_RETURN(flag != 0, hccp_err("[create][ra_typical_qp]The flag(%d) is invalid, expect 0", flag),
    1282              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1283              : 
    1284            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1285            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1286              :         hccp_err("[create][ra_typical_qp]phyId(%u) must greater or equal to 0 and less than %d!", phyId,
    1287              :             RA_MAX_PHY_ID_NUM),
    1288              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1289              : 
    1290            2 :     CHK_PRT_RETURN(qpMode < 0 || qpMode >= RA_RS_ERR_QP_MODE,
    1291              :         hccp_err("[create][ra_typical_qp]QP mode(%d) must be greater than or equal to 0 and less than %d", qpMode,
    1292              :             RA_RS_ERR_QP_MODE),
    1293              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1294              : 
    1295            1 :     hccp_run_info("Input parameters: phyId[%u], flag[%d] qpMode[%d]", phyId, flag, qpMode);
    1296              : 
    1297            1 :     ret = rdmaHandleTmp->rdmaOps->raTypicalQpCreate(rdmaHandleTmp, flag, qpMode, qpInfo, qpHandle);
    1298            1 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1299              :         hccp_err("[create][ra_typical_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId),
    1300              :         ConverReturnCode(RDMA_OP, ret));
    1301              : 
    1302            1 :     return 0;
    1303              : }
    1304              : 
    1305            6 : HCCP_ATTRI_VISI_DEF int RaLoopbackQpCreate(void *rdevHandle, struct LoopbackQpPair *qpPair, void **qpHandle)
    1306              : {
    1307            6 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1308              :     unsigned int phyId;
    1309              :     int ret;
    1310              : 
    1311            6 :     CHK_PRT_RETURN(rdmaHandleTmp == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1312              :                        rdmaHandleTmp->rdmaOps->raLoopbackQpCreate == NULL,
    1313              :         hccp_err("[create][ra_loopback_qp]rdev_handle is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1314              : 
    1315            5 :     CHK_PRT_RETURN(qpPair == NULL, hccp_err("[create][ra_loopback_qp]qp_pair is NULL"),
    1316              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1317              : 
    1318            4 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[create][ra_loopback_qp]qp_handle is NULL"),
    1319              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1320              : 
    1321            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1322            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1323              :         hccp_err("[create][ra_loopback_qp]phyId(%u) must greater or equal to 0 and less than %d!", phyId,
    1324              :             RA_MAX_PHY_ID_NUM),
    1325              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1326              : 
    1327            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1328            2 :     ret = rdmaHandleTmp->rdmaOps->raLoopbackQpCreate(rdmaHandleTmp, qpPair, qpHandle);
    1329            2 :     CHK_PRT_RETURN(ret != 0 || *qpHandle == NULL,
    1330              :         hccp_err("[create][ra_loopback_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId),
    1331              :         ConverReturnCode(RDMA_OP, ret));
    1332              : 
    1333            1 :     return 0;
    1334              : }
    1335              : 
    1336            9 : HCCP_ATTRI_VISI_DEF int RaQpDestroy(void *qpHandle)
    1337              : {
    1338            9 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1339              :     int ret;
    1340              : 
    1341            9 :     CHK_PRT_RETURN(qpHandle == NULL, hccp_err("[destroy][ra_qp]qp_handle is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1342              : 
    1343            8 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raQpDestroy == NULL,
    1344              :         hccp_err("[destroy][ra_qp]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_qp_destroy is NULL, invalid"),
    1345              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1346              : 
    1347            7 :     hccp_run_info("Input parameters: qpn[%u], phyId[%u], rdevIndex[%u] qpMode[%d] flag[%d]", raQpHandle->qpn,
    1348              :         raQpHandle->phyId, raQpHandle->rdevIndex, raQpHandle->qpMode, raQpHandle->flag);
    1349              : 
    1350            7 :     ret = raQpHandle->rdmaOps->raQpDestroy(raQpHandle);
    1351            7 :     return ConverReturnCode(RDMA_OP, ret);
    1352              : }
    1353              : 
    1354            3 : HCCP_ATTRI_VISI_DEF int RaQpConnectAsync(void *qpHandle, const void *fdHandle)
    1355              : {
    1356            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1357              :     int ret;
    1358              : 
    1359            3 :     CHK_PRT_RETURN(qpHandle == NULL || fdHandle == NULL,
    1360              :         hccp_err("[connect_async][ra_qp]ra_qp_handle or fd_handle is NULL, para error!"),
    1361              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1362              : 
    1363            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raQpConnectAsync == NULL,
    1364              :         hccp_err("[connect_async][ra_qp]rdma_ops or ra_qp_handle->rdma_ops->ra_qp_connect_async is NULL, invalid"),
    1365              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1366              : 
    1367            1 :     ret = raQpHandle->rdmaOps->raQpConnectAsync(raQpHandle, fdHandle);
    1368            1 :     return ConverReturnCode(RDMA_OP, ret);
    1369              : }
    1370              : 
    1371            3 : HCCP_ATTRI_VISI_DEF int RaGetQpStatus(void *qpHandle, int *status)
    1372              : {
    1373            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1374              :     int ret;
    1375              : 
    1376            3 :     CHK_PRT_RETURN(qpHandle == NULL || status == NULL,
    1377              :         hccp_err("[get][ra_qp_status]ra_qp_handle or status is NULL, para error!"), ConverReturnCode(RDMA_OP, -EINVAL));
    1378              : 
    1379            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raGetQpStatus == NULL,
    1380              :         hccp_err("[get][ra_qp_status]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_get_qp_status is NULL, invalid"),
    1381              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1382              : 
    1383            1 :     ret = raQpHandle->rdmaOps->raGetQpStatus(raQpHandle, status);
    1384            1 :     return ConverReturnCode(RDMA_OP, ret);
    1385              : }
    1386              : 
    1387            3 : HCCP_ATTRI_VISI_DEF int RaMrReg(void *qpHandle, struct MrInfoT *info)
    1388              : {
    1389            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1390              :     int ret;
    1391              : 
    1392            3 :     CHK_PRT_RETURN(qpHandle == NULL || info == NULL,
    1393              :         hccp_err("[reg][ra_mr]qp_handle is NULL or info is NULL, para error!"), ConverReturnCode(RDMA_OP, -EINVAL));
    1394              : 
    1395            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raMrReg == NULL,
    1396              :         hccp_err("[reg][ra_mr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_mr_reg is NULL, invalid"),
    1397              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1398              : 
    1399            1 :     ret = raQpHandle->rdmaOps->raMrReg(raQpHandle, info);
    1400            1 :     return ConverReturnCode(RDMA_OP, ret);
    1401              : }
    1402              : 
    1403            3 : HCCP_ATTRI_VISI_DEF int RaMrDereg(void *qpHandle, struct MrInfoT *info)
    1404              : {
    1405            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1406              :     int ret;
    1407              : 
    1408            3 :     CHK_PRT_RETURN(qpHandle == NULL || info == NULL || info->addr == NULL,
    1409              :         hccp_err("[dereg][ra_mr]qp_handle or info or addr is NULL, para error!"), ConverReturnCode(RDMA_OP, -EINVAL));
    1410              : 
    1411            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raMrDereg == NULL,
    1412              :         hccp_err("[dereg][ra_mr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_mr_dereg is NULL, invalid"),
    1413              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1414              : 
    1415            1 :     ret = raQpHandle->rdmaOps->raMrDereg(raQpHandle, info);
    1416            1 :     return ConverReturnCode(RDMA_OP, ret);
    1417              : }
    1418              : 
    1419            3 : HCCP_ATTRI_VISI_DEF int RaSendWr(void *qpHandle, struct SendWr *wr, struct SendWrRsp *opRsp)
    1420              : {
    1421            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1422              :     int ret;
    1423              : 
    1424            3 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || wr->bufList == NULL || opRsp == NULL,
    1425              :         hccp_err("[send][ra_wr]qp_handle or wr or buf_list or op_rsp is NULL, para error!"),
    1426              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1427              : 
    1428            2 :     CHK_PRT_RETURN(wr->bufList->len > MAX_SG_LIST_LEN_MAX,
    1429              :         hccp_err("[send][ra_wr]sg list len is more than 2G, len(%u)", wr->bufList->len),
    1430              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1431              : 
    1432            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWr == NULL,
    1433              :         hccp_err("[send][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr is NULL, invalid"),
    1434              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1435              : 
    1436            1 :     ret = raQpHandle->rdmaOps->raSendWr(raQpHandle, wr, opRsp);
    1437            1 :     RaRdevIncSendWrNum();
    1438            1 :     return ConverReturnCode(RDMA_OP, ret);
    1439              : }
    1440              : 
    1441            4 : HCCP_ATTRI_VISI_DEF int RaSendWrV2(void *qpHandle, struct SendWrV2 *wr, struct SendWrRsp *opRsp)
    1442              : {
    1443            4 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1444              :     int ret;
    1445              : 
    1446            4 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || wr->bufList == NULL || opRsp == NULL,
    1447              :         hccp_err("[send][ra_wr]qp_handle or wr or buf_list or op_rsp is NULL, para error!"),
    1448              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1449              : 
    1450            3 :     CHK_PRT_RETURN(wr->bufList->len > MAX_SG_LIST_LEN_MAX,
    1451              :         hccp_err("[send][ra_wr]sg list len is more than 2G, len(%u)", wr->bufList->len),
    1452              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1453              : 
    1454            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWrV2 == NULL,
    1455              :         hccp_err("[send][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr_v2 is NULL, invalid"),
    1456              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1457              : 
    1458            1 :     ret = raQpHandle->rdmaOps->raSendWrV2(raQpHandle, wr, opRsp);
    1459            1 :     RaRdevIncSendWrNum();
    1460            1 :     return ConverReturnCode(RDMA_OP, ret);
    1461              : }
    1462              : 
    1463            5 : HCCP_ATTRI_VISI_DEF int RaSendWrlist(void *qpHandle, struct SendWrlistData wr[], struct SendWrRsp opRsp[],
    1464              :     unsigned int sendNum, unsigned int *completeNum)
    1465              : {
    1466              :     int ret;
    1467              :     unsigned int i;
    1468            5 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1469            5 :     struct WrlistSendCompleteNum wrlistNum = {0};
    1470              : 
    1471            5 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || opRsp == NULL || sendNum == 0 || completeNum == NULL,
    1472              :         hccp_err("[send][ra_wrlist]qp_handle or wr or op_rsp or complete_num is NULL or send_num is zero, para error!"),
    1473              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1474              : 
    1475            5 :     for (i = 0; i < sendNum; i++) {
    1476            3 :         if (wr[i].memList.len > MAX_SG_LIST_LEN_MAX) {
    1477            1 :             hccp_err("[send][ra_wrlist]sg list len is more than 2G, len(%u)", wr[i].memList.len);
    1478            1 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    1479              :         }
    1480              :     }
    1481              : 
    1482            2 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWrlist == NULL,
    1483              :         hccp_err("[send][ra_wrlist]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr is NULL, invalid"),
    1484              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1485              : 
    1486            0 :     wrlistNum.sendNum = sendNum;
    1487            0 :     wrlistNum.completeNum = completeNum;
    1488            0 :     ret = raQpHandle->rdmaOps->raSendWrlist(raQpHandle, wr, opRsp, wrlistNum);
    1489            0 :     return ConverReturnCode(RDMA_OP, ret);
    1490              : }
    1491              : 
    1492            1 : HCCP_ATTRI_VISI_DEF int RaSendWrlistExt(void *qpHandle, struct SendWrlistDataExt wr[], struct SendWrRsp opRsp[],
    1493              :     unsigned int sendNum, unsigned int *completeNum)
    1494              : {
    1495            1 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1496            1 :     struct WrlistSendCompleteNum wrlistNum = {0};
    1497              :     unsigned int i;
    1498              :     int ret;
    1499              : 
    1500            1 :     CHK_PRT_RETURN(qpHandle == NULL || wr == NULL || opRsp == NULL || sendNum == 0 || completeNum == NULL,
    1501              :         hccp_err("[send][ra_wrlist]qp_handle or wr or op_rsp or complete_num is NULL "
    1502              :                  "or send_num is zero, para error!"),
    1503              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1504              : 
    1505            2 :     for (i = 0; i < sendNum; i++) {
    1506            1 :         if (wr[i].memList.len > MAX_SG_LIST_LEN_MAX) {
    1507            0 :             hccp_err("[send][ra_wrlist]sg list len is more than 2G, len(%u)", wr[i].memList.len);
    1508            0 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    1509              :         }
    1510              :     }
    1511              : 
    1512            1 :     CHK_PRT_RETURN(raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSendWrlistExt == NULL,
    1513              :         hccp_err("[send][ra_wrlist]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_send_wr is NULL, invalid"),
    1514              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1515              : 
    1516            0 :     wrlistNum.sendNum = sendNum;
    1517            0 :     wrlistNum.completeNum = completeNum;
    1518            0 :     ret = raQpHandle->rdmaOps->raSendWrlistExt(raQpHandle, wr, opRsp, wrlistNum);
    1519            0 :     return ConverReturnCode(RDMA_OP, ret);
    1520              : }
    1521              : 
    1522            3 : HCCP_ATTRI_VISI_DEF int RaGetNotifyBaseAddr(void *rdevHandle, unsigned long long *va, unsigned long long *size)
    1523              : {
    1524            3 :     struct RaRdmaHandle *rdevHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1525              :     int ret;
    1526              : 
    1527            3 :     CHK_PRT_RETURN(rdevHandle == NULL || va == NULL || size == NULL,
    1528              :         hccp_err("[get][ra_notify_base_addr]rdev_handle or va or size is NULL, invalid"),
    1529              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1530              : 
    1531            2 :     CHK_PRT_RETURN(rdevHandleTmp->rdmaOps == NULL || rdevHandleTmp->rdmaOps->raGetNotifyBaseAddr == NULL,
    1532              :         hccp_err("[get][ra_notify_base_addr]rdma_ops is NULL or ra_get_notify_base_addr is NULL, invalid"),
    1533              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1534              : 
    1535            2 :     ret = rdevHandleTmp->rdmaOps->raGetNotifyBaseAddr(rdevHandleTmp, va, size);
    1536            2 :     RaRdevSaveNotifyMr(rdevHandleTmp, ret, *va, *size);
    1537            2 :     return ConverReturnCode(RDMA_OP, ret);
    1538              : }
    1539              : 
    1540            3 : HCCP_ATTRI_VISI_DEF int RaGetNotifyMrInfo(void *rdevHandle, struct MrInfoT *info)
    1541              : {
    1542            3 :     struct RaRdmaHandle *rdevHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1543              :     int ret;
    1544              : 
    1545            3 :     CHK_PRT_RETURN(rdevHandle == NULL || info == NULL,
    1546              :         hccp_err("[get][ra_notify_mr_info]rdev_handle or info is NULL, invalid"), ConverReturnCode(RDMA_OP, -EINVAL));
    1547              : 
    1548            2 :     CHK_PRT_RETURN(rdevHandleTmp->rdmaOps == NULL || rdevHandleTmp->rdmaOps->raGetNotifyMrInfo == NULL,
    1549              :         hccp_err("[get][ra_notify_mr_info]rdma_ops is NULL or ra_get_notify_mr_info is NULL, invalid"),
    1550              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1551              : 
    1552            2 :     ret = rdevHandleTmp->rdmaOps->raGetNotifyMrInfo(rdevHandleTmp, info);
    1553            2 :     RaRdevSaveNotifyMr(rdevHandleTmp, ret, (uint64_t)(uintptr_t)info->addr, info->size);
    1554            2 :     return ConverReturnCode(RDMA_OP, ret);
    1555              : }
    1556              : 
    1557            3 : HCCP_ATTRI_VISI_DEF int RaSocketGetWhiteListStatus(unsigned int *enable)
    1558              : {
    1559            3 :     CHK_PRT_RETURN(enable == NULL, hccp_err("[get][ra_socket_white_list_status]white list switch enable is NULL"),
    1560              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1561              : 
    1562            2 :     *enable = gWhiteListSwitch;
    1563            2 :     hccp_info("white list status: enable[%u]", *enable);
    1564            2 :     return 0;
    1565              : }
    1566              : 
    1567            4 : HCCP_ATTRI_VISI_DEF int RaSocketSetWhiteListStatus(unsigned int enable)
    1568              : {
    1569            4 :     hccp_run_info("Input parameters: enable[%u]", enable);
    1570              : 
    1571            4 :     CHK_PRT_RETURN(enable != WHITE_LIST_DISABLE && enable != WHITE_LIST_ENABLE,
    1572              :         hccp_err("[set][ra_socket_white_list_status]white list switch is invalid, enable(%u)", enable),
    1573              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1574              : 
    1575            3 :     gWhiteListSwitch = enable;
    1576            3 :     return 0;
    1577              : }
    1578              : 
    1579            3 : HCCP_ATTRI_VISI_DEF int RaSocketWhiteListAdd(void *socketHandle, struct SocketWlistInfoT whiteList[], unsigned int num)
    1580              : {
    1581            3 :     struct RaSocketHandle *socketHandleTmp = NULL;
    1582            3 :     char localIp[MAX_IP_LEN] = {0};
    1583              :     unsigned int phyId;
    1584              :     int ret;
    1585              : 
    1586            3 :     CHK_PRT_RETURN(whiteList == NULL || num > MAX_WLIST_NUM || num == 0,
    1587              :         hccp_err("[add][ra_socket_white_list]white_list is NULL, or num(%u) > %u or = 0, invalid", num, MAX_WLIST_NUM),
    1588              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1589              : 
    1590            2 :     socketHandleTmp = (struct RaSocketHandle *)socketHandle;
    1591            2 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
    1592            2 :         socketHandleTmp->socketOps->raSocketWhiteListAdd == NULL) {
    1593            0 :         hccp_err("[add][ra_socket_white_list]socket_handle or func is NULL");
    1594            0 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1595              :     }
    1596              : 
    1597            2 :     ret = RaInetPton(socketHandleTmp->rdevInfo.family, socketHandleTmp->rdevInfo.localIp, localIp, MAX_IP_LEN);
    1598            2 :     CHK_PRT_RETURN(ret, hccp_err("[add][ra_socket_white_list]ra_inet_pton for local_ip failed, ret(%d)", ret),
    1599              :         ConverReturnCode(SOCKET_OP, ret));
    1600              : 
    1601            2 :     phyId = socketHandleTmp->rdevInfo.phyId;
    1602            2 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1603              :         hccp_err("[add][ra_socket_white_list]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM),
    1604              :         ConverReturnCode(SOCKET_OP, -EINVAL));
    1605              : 
    1606            1 :     hccp_info("Input parameters: phyId[%u], localIp[%s], num[%u]", phyId, localIp, num);
    1607              : 
    1608            1 :     ret = socketHandleTmp->socketOps->raSocketWhiteListAdd(socketHandleTmp->rdevInfo, whiteList, num);
    1609            1 :     return ConverReturnCode(SOCKET_OP, ret);
    1610              : }
    1611              : 
    1612            3 : HCCP_ATTRI_VISI_DEF int RaSocketWhiteListDel(void *socketHandle, struct SocketWlistInfoT whiteList[], unsigned int num)
    1613              : {
    1614            3 :     struct RaSocketHandle *socketHandleTmp = NULL;
    1615            3 :     char localIp[MAX_IP_LEN] = {0};
    1616              :     unsigned int phyId;
    1617              :     int ret;
    1618              : 
    1619            3 :     if (whiteList == NULL || num > MAX_WLIST_NUM || num == 0) {
    1620            1 :         hccp_err("[del][ra_socket_white_list]white_list is NULL, or num (%u) > %u or = 0, invalid", num, MAX_WLIST_NUM);
    1621            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1622              :     }
    1623            2 :     socketHandleTmp = (struct RaSocketHandle *)socketHandle;
    1624            2 :     if (socketHandleTmp == NULL || socketHandleTmp->socketOps == NULL ||
    1625            2 :         socketHandleTmp->socketOps->raSocketWhiteListDel == NULL) {
    1626            0 :         hccp_err("[del][ra_socket_white_list]socket_handle or func is NULL");
    1627            0 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1628              :     }
    1629            2 :     ret = RaInetPton(socketHandleTmp->rdevInfo.family, socketHandleTmp->rdevInfo.localIp, localIp, MAX_IP_LEN);
    1630            2 :     if (ret) {
    1631            0 :         hccp_err("[del][ra_socket_white_list]ra_inet_pton for local_ip failed, ret(%d)", ret);
    1632            0 :         return ConverReturnCode(SOCKET_OP, ret);
    1633              :     }
    1634              : 
    1635            2 :     phyId = socketHandleTmp->rdevInfo.phyId;
    1636            2 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    1637            1 :         hccp_err("[del][ra_socket_white_list]phyId(%u) must be smaller than %u", phyId, RA_MAX_PHY_ID_NUM);
    1638            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    1639              :     }
    1640              : 
    1641            1 :     hccp_info("Input parameters: phyId[%u], localIp[%s], num[%u]", phyId, localIp, num);
    1642              : 
    1643            1 :     ret = socketHandleTmp->socketOps->raSocketWhiteListDel(socketHandleTmp->rdevInfo, whiteList, num);
    1644            1 :     return ConverReturnCode(SOCKET_OP, ret);
    1645              : }
    1646              : 
    1647           12 : STATIC int RaIfaddrInfoConverter(unsigned int phyId, bool isAll, struct InterfaceInfo interfaceInfos[],
    1648              :     unsigned int *num)
    1649              : {
    1650           12 :     struct IfaddrInfo *ifaddrInfos = NULL;
    1651           12 :     unsigned int interfaceVersionV2 = 0;
    1652           12 :     unsigned int interfaceVersion = 0;
    1653              :     unsigned int i;
    1654              :     int ret;
    1655              : 
    1656           12 :     ret = RaGetInterfaceVersion(phyId, RA_RS_GET_IFADDRS, &interfaceVersion);
    1657           12 :     CHK_PRT_RETURN(ret != 0 || interfaceVersion == 0,
    1658              :         hccp_err("[converter][ra_ifaddr]get interface version failed, ret(%d), phyId(%u), interfaceVersion(%u)", ret,
    1659              :             phyId, interfaceVersion),
    1660              :         -EINVAL);
    1661              : 
    1662            9 :     ret = RaGetInterfaceVersion(phyId, RA_RS_GET_IFADDRS_V2, &interfaceVersionV2);
    1663            9 :     CHK_PRT_RETURN(ret != 0,
    1664              :         hccp_err("[converter][ra_ifaddr]get interface version failed, ret(%d), phyId(%u), interfaceVersion(%u)", ret,
    1665              :             phyId, interfaceVersion),
    1666              :         -EINVAL);
    1667              : 
    1668            9 :     CHK_PRT_RETURN(interfaceVersionV2 < GET_IFADDRS_VERSION_3 && isAll,
    1669              :         hccp_err("[converter][ra_ifaddr]current version do not support get all device ip addr, interfaceVersion(%u), "
    1670              :                  "interfaceVersionV2(%u), isAll(%d)",
    1671              :             interfaceVersion, interfaceVersionV2, isAll),
    1672              :         -EPROTONOSUPPORT);
    1673              : 
    1674            9 :     if (interfaceVersion == GET_IFADDRS_VERSION_1) {
    1675            3 :         ifaddrInfos = calloc(*num, sizeof(struct IfaddrInfo));
    1676            3 :         if (ifaddrInfos == NULL) {
    1677            1 :             hccp_err("[converter][ra_ifaddr]calloc for ifaddr_infos failed");
    1678            1 :             return -EINVAL;
    1679              :         }
    1680              : 
    1681            2 :         ret = RaHdcGetIfaddrs(phyId, ifaddrInfos, num);
    1682            2 :         if (ret) {
    1683            1 :             hccp_err("[converter][ra_ifaddr]ra_hdc_get_ifaddrs failed, ret(%d), phyId(%u), num(%u)", ret, phyId, *num);
    1684            1 :             free(ifaddrInfos);
    1685            1 :             return ret;
    1686              :         }
    1687              : 
    1688            5 :         for (i = 0; i < *num; i++) {
    1689              :             // device 网卡只支持IPv4
    1690            4 :             interfaceInfos[i].family = AF_INET;
    1691            4 :             interfaceInfos[i].scopeId = 0;
    1692            4 :             ret = memcpy_s(&(interfaceInfos[i].ifaddr.ip), sizeof(union HccpIpAddr), &(ifaddrInfos[i].ip),
    1693              :                 sizeof(union HccpIpAddr));
    1694            4 :             if (ret) {
    1695            0 :                 hccp_err("[converter][ra_ifaddr]memcpy_s interface[%u] ip failed, ret(%d)", i, ret);
    1696            0 :                 free(ifaddrInfos);
    1697            0 :                 return -ESAFEFUNC;
    1698              :             }
    1699              : 
    1700            4 :             ret = memcpy_s(&(interfaceInfos[i].ifaddr.mask), sizeof(struct in_addr), &(ifaddrInfos[i].mask),
    1701              :                 sizeof(struct in_addr));
    1702            4 :             if (ret) {
    1703            0 :                 hccp_err("[converter][ra_ifaddr]memcpy_s interface[%u] mask failed, ret(%d)", i, ret);
    1704            0 :                 free(ifaddrInfos);
    1705            0 :                 return -ESAFEFUNC;
    1706              :             }
    1707              :         }
    1708              : 
    1709            1 :         free(ifaddrInfos);
    1710            6 :     } else if (interfaceVersion == GET_IFADDRS_VERSION_2) { /* version 2 support IPV6 and IPV4 */
    1711            5 :         ret = RaHdcGetIfaddrsV2(phyId, isAll, interfaceInfos, num);
    1712            5 :         CHK_PRT_RETURN(ret,
    1713              :             hccp_err("[converter][ra_ifaddr]ra_hdc_get_ifaddrs_v2 failed, ret(%d), phyId(%u), isAll(%d), num(%u)", ret,
    1714              :                 phyId, isAll, *num),
    1715              :             ret);
    1716              :     } else {
    1717            1 :         hccp_err("[converter][ra_ifaddr]interface version not support, interfaceVersion(%u)", interfaceVersion);
    1718            1 :         return -EINVAL;
    1719              :     }
    1720              : 
    1721            4 :     return 0;
    1722              : }
    1723              : 
    1724           10 : HCCP_ATTRI_VISI_DEF int RaGetIfnum(struct RaGetIfattr *config, unsigned int *num)
    1725              : {
    1726           10 :     unsigned int interfaceVersion = 0;
    1727              :     int ret;
    1728              : 
    1729           10 :     CHK_PRT_RETURN(config == NULL || num == NULL, hccp_err("[get][ra_ifnum]config or num is NULL"),
    1730              :         ConverReturnCode(OTHERS, -EINVAL));
    1731              : 
    1732            9 :     CHK_PRT_RETURN(config->phyId >= RA_MAX_PHY_ID_NUM,
    1733              :         hccp_err("[get][ra_ifnum]phyId(%u) is invalid! it must be greater than or equal to 0 and less than %d!",
    1734              :             config->phyId, RA_MAX_PHY_ID_NUM),
    1735              :         ConverReturnCode(OTHERS, -EINVAL));
    1736              : 
    1737            7 :     hccp_run_info("Input parameters: phyId[%u], nicPosition:[%u], isAll:[%d]", config->phyId, config->nicPosition,
    1738              :         config->isAll);
    1739              : 
    1740            7 :     ret = RaGetInterfaceVersion(config->phyId, RA_RS_GET_IFADDRS_V2, &interfaceVersion);
    1741            7 :     CHK_PRT_RETURN(ret != 0,
    1742              :         hccp_err("[get][ra_ifnum]get interface version failed, ret(%d), phyId(%u), interfaceVersion(%u)", ret,
    1743              :             config->phyId, interfaceVersion),
    1744              :         ConverReturnCode(OTHERS, -EINVAL));
    1745              : 
    1746            7 :     CHK_PRT_RETURN(interfaceVersion < GET_IFADDRS_VERSION_3 && config->nicPosition == NETWORK_OFFLINE && config->isAll,
    1747              :         hccp_err("[get][ra_ifnum]current version do not support get all ip num, interfaceVersion(%u), isAll(%d)",
    1748              :             interfaceVersion, config->isAll),
    1749              :         ConverReturnCode(OTHERS, -ENOTSUPP));
    1750              : 
    1751            6 :     if (config->nicPosition == NETWORK_OFFLINE) {
    1752            1 :         ret = RaHdcGetIfnum(config->phyId, config->isAll, num);
    1753            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifnum]ra_hdc_get_ifnum failed, ret(%d)", ret),
    1754              :             ConverReturnCode(OTHERS, ret));
    1755            5 :     } else if (config->nicPosition == NETWORK_PEER_ONLINE) {
    1756            2 :         ret = RaPeerGetIfnum(config->phyId, num);
    1757            2 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifnum]ra_peer_get_ifnum failed, ret(%d)", ret),
    1758              :             ConverReturnCode(OTHERS, ret));
    1759              :     } else {
    1760            3 :         hccp_err("[get][ra_ifnum]Wrong mode, do not support online mode");
    1761            3 :         return ConverReturnCode(OTHERS, -EPROTONOSUPPORT);
    1762              :     }
    1763              : 
    1764            3 :     CHK_PRT_RETURN((*num) > MAX_SUPPORT_IFNUM,
    1765              :         hccp_err("[get][ra_ifnum]get interface num(%d)! It must greater or equal to 0 and less or equal to %d", (*num),
    1766              :             MAX_SUPPORT_IFNUM),
    1767              :         ConverReturnCode(OTHERS, -EINVAL));
    1768              : 
    1769            3 :     return 0;
    1770              : }
    1771              : 
    1772           12 : HCCP_ATTRI_VISI_DEF int RaGetIfaddrs(struct RaGetIfattr *config, struct InterfaceInfo interfaceInfos[],
    1773              :     unsigned int *num)
    1774              : {
    1775              :     int ret;
    1776              : 
    1777           12 :     CHK_PRT_RETURN(config == NULL || interfaceInfos == NULL || num == NULL,
    1778              :         hccp_err("[get][ra_ifaddrs]config or interface_infos or num is NULL"), ConverReturnCode(OTHERS, -EINVAL));
    1779              : 
    1780           11 :     CHK_PRT_RETURN(config->phyId >= RA_MAX_PHY_ID_NUM,
    1781              :         hccp_err("[get][ra_ifaddrs]phyId(%u) is invalid! it must be greater than or equal to 0 and less than %d!",
    1782              :             config->phyId, RA_MAX_PHY_ID_NUM),
    1783              :         ConverReturnCode(OTHERS, -EINVAL));
    1784              : 
    1785           10 :     CHK_PRT_RETURN(*num == 0,
    1786              :         hccp_err("[get][ra_ifaddrs]interface num(%u) is invalid! it must be greater than 0", *num),
    1787              :         ConverReturnCode(OTHERS, -EINVAL));
    1788              : 
    1789            9 :     hccp_run_info("Input parameters: phyId[%u], nicPosition:[%u], isAll[%d], interface num[%u]", config->phyId,
    1790              :         config->nicPosition, config->isAll, *num);
    1791              : 
    1792            9 :     if (config->nicPosition == NETWORK_OFFLINE) {
    1793            6 :         CHK_PRT_RETURN(*num > MAX_INTERFACE_NUM,
    1794              :             hccp_err("[get][ra_ifaddrs]interface num(%u) is invalid! it must be less than %d!", *num,
    1795              :                 MAX_INTERFACE_NUM),
    1796              :             ConverReturnCode(OTHERS, -EINVAL));
    1797              : 
    1798            5 :         ret = RaIfaddrInfoConverter(config->phyId, config->isAll, interfaceInfos, num);
    1799            5 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifaddrs]ra_hdc_get_ifaddrs failed, ret(%d)", ret),
    1800              :             ConverReturnCode(OTHERS, ret));
    1801            3 :     } else if (config->nicPosition == NETWORK_PEER_ONLINE) {
    1802            1 :         ret = RaPeerGetIfaddrs(config->phyId, interfaceInfos, num);
    1803            1 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_ifaddrs]ra_peer_get_ifaddrs failed, ret(%d)", ret),
    1804              :             ConverReturnCode(OTHERS, ret));
    1805              :     } else {
    1806            2 :         hccp_err("[get][ra_ifaddrs]Wrong mode, do not support online mode");
    1807            2 :         return ConverReturnCode(OTHERS, -EPROTONOSUPPORT);
    1808              :     }
    1809            3 :     return 0;
    1810              : }
    1811              : 
    1812           41 : HCCP_ATTRI_VISI_DEF int RaGetInterfaceVersion(unsigned int phyId, unsigned int interfaceOpcode,
    1813              :     unsigned int *interfaceVersion)
    1814              : {
    1815              :     int ret;
    1816              : 
    1817           41 :     if (interfaceVersion == NULL || phyId >= RA_MAX_PHY_ID_NUM || interfaceOpcode >= RA_RS_EXTER_OP_MAX_NUM) {
    1818            1 :         hccp_err("[get][ra_interface_version]para is invalid! interface_version is NULL or phyId(%u) is "
    1819              :                  "greater than [%u] or interface_opcode(%u) more than [%u]",
    1820              :             phyId, RA_MAX_PHY_ID_NUM, interfaceOpcode, RA_RS_EXTER_OP_MAX_NUM);
    1821            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    1822              :     }
    1823              : 
    1824           40 :     ret = RaHdcGetInterfaceVersion(phyId, interfaceOpcode, interfaceVersion);
    1825           40 :     return ConverReturnCode(OTHERS, ret);
    1826              : }
    1827              : 
    1828          548 : int ConverReturnCode(enum ModuleType module, int erroCode)
    1829              : {
    1830              :     unsigned int i;
    1831          548 :     unsigned int num = sizeof(gErrcodeInfoList) / sizeof(gErrcodeInfoList[0]);
    1832          548 :     int ret = CONVER_ERROR_CODE(module, DEFAULT_ERRCODE_TYPE, DEFAULT_MODULE_ERRCODE);
    1833              : 
    1834          548 :     if (erroCode == 0) {
    1835          140 :         return 0;
    1836              :     }
    1837              : 
    1838          408 :     if (erroCode / ACL_ERRCODE_DIGIT) { /* ACL error codes are transparently transmitted */
    1839            2 :         return erroCode;
    1840              :     }
    1841              : 
    1842         1941 :     for (i = 0; i < num; i++) {
    1843         1940 :         if (erroCode == gErrcodeInfoList[i].origErrcode) {
    1844          405 :             ret = CONVER_ERROR_CODE(module, gErrcodeInfoList[i].errType, gErrcodeInfoList[i].moduleErrcode);
    1845          405 :             break;
    1846              :         }
    1847              :     }
    1848              : 
    1849          406 :     if (erroCode != -EAGAIN) { // 防止刷屏
    1850          406 :         hccp_info("ConverReturnCode: orig_errcode[%d] curr_errcode[%d]", erroCode, ret);
    1851              :     }
    1852          406 :     return ret;
    1853              : }
    1854              : 
    1855            4 : HCCP_ATTRI_VISI_DEF int RaRecvWrlist(void *qpHandle, struct RecvWrlistData *wr, unsigned int recvNum,
    1856              :     unsigned int *completeNum)
    1857              : {
    1858              :     int ret;
    1859              :     unsigned int i;
    1860            4 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1861              : 
    1862            4 :     if (qpHandle == NULL || wr == NULL || recvNum == 0 || completeNum == NULL) {
    1863            1 :         hccp_err("[recv][ra_wrlist]qp_handle or wr or complete_num is NULL or recv_num[%u] is zero, para error!",
    1864              :             recvNum);
    1865            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1866              :     }
    1867              : 
    1868            5 :     for (i = 0; i < recvNum; i++) {
    1869            3 :         if (wr[i].memList.len > MAX_SG_LIST_LEN_MAX) {
    1870            1 :             hccp_err("[recv][ra_wrlist]sg list len is more than 2G, len(%u)", wr[i].memList.len);
    1871            1 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    1872              :         }
    1873              :     }
    1874            2 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raRecvWrlist == NULL) {
    1875            1 :         hccp_err("[recv][ra_wrlist]rdma_ops or ra_recv_wrlist is NULL, invalid");
    1876            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1877              :     }
    1878            1 :     ret = raQpHandle->rdmaOps->raRecvWrlist(raQpHandle, wr, recvNum, completeNum);
    1879            1 :     return ConverReturnCode(RDMA_OP, ret);
    1880              : }
    1881              : 
    1882            3 : HCCP_ATTRI_VISI_DEF int RaGetQpContext(void *qpHandle, void **qp, void **sendCq, void **recvCq)
    1883              : {
    1884              :     int ret;
    1885            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1886              : 
    1887            3 :     if (qpHandle == NULL || qp == NULL || sendCq == NULL || recvCq == NULL) {
    1888            1 :         hccp_err("[request][ra_get_qp_context]qp_handle or qp or sendCq or recvCq is NULL, para error!");
    1889            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1890              :     }
    1891              : 
    1892            2 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raGetQpContext == NULL) {
    1893            1 :         hccp_err("[get][ra_get_qp_context]rdma_ops is NULL or ra_get_qp_context is NULL, invalid");
    1894            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1895              :     }
    1896            1 :     CHK_PRT_RETURN(raQpHandle->phyId >= RA_MAX_PHY_ID_NUM,
    1897              :         hccp_err("[get][rs_get_qp_context]qpPeer->phyId[%u] >= max_dev_num[%u], input is invalid", raQpHandle->phyId,
    1898              :             RA_MAX_PHY_ID_NUM),
    1899              :         -EINVAL);
    1900              : 
    1901            1 :     ret = raQpHandle->rdmaOps->raGetQpContext(raQpHandle, qp, sendCq, recvCq);
    1902            1 :     return ConverReturnCode(RDMA_OP, ret);
    1903              : }
    1904              : 
    1905            4 : HCCP_ATTRI_VISI_DEF int RaCqCreate(void *rdevHandle, struct CqAttr *attr)
    1906              : {
    1907            4 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1908              :     unsigned int phyId;
    1909              :     int ret;
    1910              : 
    1911            4 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raCqCreate == NULL ||
    1912              :                        attr == NULL || attr->ibSendCq == NULL || attr->ibRecvCq == NULL || attr->qpContext == NULL,
    1913              :         hccp_err("[create][ra_cq]para is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1914              : 
    1915            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1916            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1917              :         hccp_err("[create][ra_cq]phyId(%u) must be less than %d!", phyId, RA_MAX_PHY_ID_NUM),
    1918              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1919              : 
    1920            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1921              : 
    1922            2 :     ret = rdmaHandleTmp->rdmaOps->raCqCreate(rdmaHandleTmp, attr);
    1923            2 :     CHK_PRT_RETURN(ret != 0 || *attr->ibSendCq == NULL || *attr->ibRecvCq == NULL || *attr->qpContext == NULL,
    1924              :         hccp_err("[create][ra_cq]create cq failed, ret(%d) phyId(%u)", ret, phyId), ConverReturnCode(RDMA_OP, -EINVAL));
    1925              : 
    1926            0 :     return 0;
    1927              : }
    1928              : 
    1929            4 : HCCP_ATTRI_VISI_DEF int RaCqDestroy(void *rdevHandle, struct CqAttr *attr)
    1930              : {
    1931            4 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1932              :     unsigned int phyId;
    1933              :     int ret;
    1934              : 
    1935            4 :     CHK_PRT_RETURN(rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL ||
    1936              :                        rdmaHandleTmp->rdmaOps->raCqDestroy == NULL || attr == NULL || attr->ibSendCq == NULL ||
    1937              :                        attr->ibRecvCq == NULL || attr->qpContext == NULL,
    1938              :         hccp_err("[destroy][ra_cq]para is NULL or func is NULL"), ConverReturnCode(RDMA_OP, -EINVAL));
    1939              : 
    1940            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1941            3 :     CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM,
    1942              :         hccp_err("[destroy][ra_cq]phyId(%u) must be less than %d!", phyId, RA_MAX_PHY_ID_NUM),
    1943              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1944              : 
    1945            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1946              : 
    1947            2 :     ret = rdmaHandleTmp->rdmaOps->raCqDestroy(rdmaHandleTmp, attr);
    1948            2 :     CHK_PRT_RETURN(ret != 0 || *attr->ibSendCq == NULL || *attr->ibRecvCq == NULL || *attr->qpContext == NULL,
    1949              :         hccp_err("[destroy][ra_cq]destroy cq failed, ret(%d) phyId(%u)", ret, phyId),
    1950              :         ConverReturnCode(RDMA_OP, -EINVAL));
    1951              : 
    1952            0 :     return 0;
    1953              : }
    1954              : 
    1955            5 : HCCP_ATTRI_VISI_DEF int RaNormalQpCreate(void *rdevHandle, struct ibv_qp_init_attr *qpInitAttr, void **qpHandle,
    1956              :     void **qp)
    1957              : {
    1958            5 :     struct RaRdmaHandle *rdmaHandleTmp = (struct RaRdmaHandle *)rdevHandle;
    1959              :     unsigned int phyId;
    1960              :     int ret;
    1961              : 
    1962            5 :     if (rdevHandle == NULL || rdmaHandleTmp->rdmaOps == NULL || rdmaHandleTmp->rdmaOps->raNormalQpCreate == NULL ||
    1963            4 :         qpInitAttr == NULL || qp == NULL) {
    1964            1 :         hccp_err("[create][ra_normal_qp]para is NULL or func is NULL");
    1965            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1966              :     }
    1967              : 
    1968            4 :     if (qpHandle == NULL) {
    1969            1 :         hccp_err("[create][ra_normal_qp]qp_handle is NULL");
    1970            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1971              :     }
    1972              : 
    1973            3 :     phyId = rdmaHandleTmp->rdevInfo.phyId;
    1974            3 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    1975            1 :         hccp_err("[create][ra_normal_qp]phyId(%u) must be less than %d!", phyId, RA_MAX_PHY_ID_NUM);
    1976            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1977              :     }
    1978              : 
    1979            2 :     hccp_run_info("Input parameters: phyId[%u]", phyId);
    1980              : 
    1981            2 :     ret = rdmaHandleTmp->rdmaOps->raNormalQpCreate(rdmaHandleTmp, qpInitAttr, qpHandle, qp);
    1982            2 :     if (ret != 0 || *qpHandle == NULL) {
    1983            1 :         hccp_err("[create][ra_normal_qp]create qp failed, ret(%d) phyId(%u)", ret, phyId);
    1984            1 :         return ConverReturnCode(RDMA_OP, ret);
    1985              :     }
    1986              : 
    1987            1 :     return 0;
    1988              : }
    1989              : 
    1990            5 : HCCP_ATTRI_VISI_DEF int RaNormalQpDestroy(void *qpHandle)
    1991              : {
    1992              :     int ret;
    1993            5 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    1994              : 
    1995            5 :     if (qpHandle == NULL) {
    1996            1 :         hccp_err("[destroy][ra_normal_qp]qp_handle is NULL");
    1997            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    1998              :     }
    1999              : 
    2000            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raNormalQpDestroy == NULL) {
    2001            3 :         hccp_err("[destroy][ra_qp]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_normal_qp_destroy is NULL, invalid");
    2002            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2003              :     }
    2004              : 
    2005            1 :     hccp_run_info("Input parameters: qpn[%u], phyId[%u], rdevIndex[%u]", raQpHandle->qpn, raQpHandle->phyId,
    2006              :         raQpHandle->rdevIndex);
    2007              : 
    2008            1 :     ret = raQpHandle->rdmaOps->raNormalQpDestroy(raQpHandle);
    2009            1 :     return ConverReturnCode(RDMA_OP, ret);
    2010              : }
    2011              : 
    2012            6 : HCCP_ATTRI_VISI_DEF int RaSetQpAttrQos(void *qpHandle, struct QosAttr *attr)
    2013              : {
    2014              :     int ret;
    2015            6 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2016              : 
    2017            6 :     if (qpHandle == NULL || attr == NULL) {
    2018            2 :         hccp_err("[set][ra_qp_attr_qos]qp_handle or attr is NULL, para error!");
    2019            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2020              :     }
    2021              : 
    2022            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSetQpAttrQos == NULL) {
    2023            3 :         hccp_err("[set][ra_qp_attr_qos]rdma_ops is NULL or rdma_ops->ra_set_qp_attr_qos is NULL, invalid");
    2024            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2025              :     }
    2026              : 
    2027            1 :     ret = raQpHandle->rdmaOps->raSetQpAttrQos(raQpHandle, attr);
    2028            1 :     return ConverReturnCode(RDMA_OP, ret);
    2029              : }
    2030              : 
    2031            6 : HCCP_ATTRI_VISI_DEF int RaSetQpAttrTimeout(void *qpHandle, unsigned int *timeout)
    2032              : {
    2033              :     int ret;
    2034            6 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2035              : 
    2036            6 :     if (qpHandle == NULL || timeout == NULL) {
    2037            2 :         hccp_err("[set][ra_qp_attr_timeout]qp_handle or timeout is NULL, para error!");
    2038            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2039              :     }
    2040              : 
    2041            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSetQpAttrTimeout == NULL) {
    2042            3 :         hccp_err("[set][ra_qp_attr_timeout]rdma_ops is NULL or rdma_ops->ra_set_qp_attr_timeout is NULL, invalid");
    2043            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2044              :     }
    2045              : 
    2046            1 :     ret = raQpHandle->rdmaOps->raSetQpAttrTimeout(raQpHandle, timeout);
    2047            1 :     return ConverReturnCode(RDMA_OP, ret);
    2048              : }
    2049              : 
    2050            6 : HCCP_ATTRI_VISI_DEF int RaSetQpAttrRetryCnt(void *qpHandle, unsigned int *retryCnt)
    2051              : {
    2052              :     int ret;
    2053            6 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2054              : 
    2055            6 :     if (qpHandle == NULL || retryCnt == NULL) {
    2056            2 :         hccp_err("[set][ra_qp_attr_retry_cnt]qp_handle or retry_cnt is NULL, para error!");
    2057            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2058              :     }
    2059              : 
    2060            4 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raSetQpAttrRetryCnt == NULL) {
    2061            3 :         hccp_err("[set][ra_qp_attr_retry_cnt]rdma_ops is NULL or rdma_ops->ra_set_qp_attr_retry_cnt is NULL, invalid");
    2062            3 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2063              :     }
    2064              : 
    2065            1 :     ret = raQpHandle->rdmaOps->raSetQpAttrRetryCnt(raQpHandle, retryCnt);
    2066            1 :     return ConverReturnCode(RDMA_OP, ret);
    2067              : }
    2068              : 
    2069            6 : HCCP_ATTRI_VISI_DEF int RaCreateCompChannel(const void *rdmaHandle, void **compChannel)
    2070              : {
    2071              :     int ret;
    2072            6 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2073              : 
    2074            6 :     if (rdmaHandle == NULL) {
    2075            1 :         hccp_err("[ra_create_comp_channel]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2076            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2077              :     }
    2078              : 
    2079            5 :     if (compChannel == NULL) {
    2080            1 :         hccp_err("[ra_create_comp_channel]comp_channel is NULL");
    2081            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2082              :     }
    2083              : 
    2084            4 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raCreateCompChannel == NULL) {
    2085            2 :         hccp_err("[ra_create_comp_channel]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_create_comp_channel "
    2086              :                  "is NULL, invalid");
    2087            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2088              :     }
    2089              : 
    2090            2 :     ret = raRdmaHandle->rdmaOps->raCreateCompChannel(raRdmaHandle, compChannel);
    2091            2 :     return ConverReturnCode(RDMA_OP, ret);
    2092              : }
    2093              : 
    2094            6 : HCCP_ATTRI_VISI_DEF int RaDestroyCompChannel(const void *rdmaHandle, void *compChannel)
    2095              : {
    2096              :     int ret;
    2097            6 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2098              : 
    2099            6 :     if (rdmaHandle == NULL) {
    2100            1 :         hccp_err("[ra_destroy_comp_channel]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2101            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2102              :     }
    2103              : 
    2104            5 :     if (compChannel == NULL) {
    2105            2 :         hccp_err("[ra_destroy_comp_channel]comp_channel is NULL");
    2106            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2107              :     }
    2108              : 
    2109            3 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raDestroyCompChannel == NULL) {
    2110            1 :         hccp_err("[ra_destroy_comp_channel]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_destroy_comp_channel "
    2111              :                  "is NULL, invalid");
    2112            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2113              :     }
    2114              : 
    2115            2 :     ret = raRdmaHandle->rdmaOps->raDestroyCompChannel(compChannel);
    2116            2 :     return ConverReturnCode(RDMA_OP, ret);
    2117              : }
    2118              : 
    2119            4 : HCCP_ATTRI_VISI_DEF int RaGetCqeErrInfo(unsigned int phyId, struct CqeErrInfo *info)
    2120              : {
    2121              :     int ret;
    2122              : 
    2123            4 :     if (info == NULL) {
    2124            2 :         hccp_err("[ra_get_cqe_err_info]cqe_err_info is NULL, para error!");
    2125            2 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2126              :     }
    2127              : 
    2128            2 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    2129            1 :         hccp_err("[ra_get_cqe_err_info]phyId(%u) must be greater than or equal to 0 and less than %d!", phyId,
    2130              :             RA_MAX_PHY_ID_NUM);
    2131            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2132              :     }
    2133              : 
    2134            1 :     ret = RaHdcGetCqeErrInfo(phyId, info);
    2135            1 :     return ConverReturnCode(RDMA_OP, ret);
    2136              : }
    2137              : 
    2138            3 : HCCP_ATTRI_VISI_DEF int RaRdevGetCqeErrInfoList(void *rdmaHandle, struct CqeErrInfo *infoList, unsigned int *num)
    2139              : {
    2140            3 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2141              :     int ret;
    2142              : 
    2143            3 :     if (rdmaHandle == NULL || infoList == NULL || num == NULL) {
    2144            1 :         hccp_err("[get][cqe_err_info_list]rdma_handle or info_list or num is NULL, para error!");
    2145            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2146              :     }
    2147              : 
    2148            2 :     if (*num == 0 || *num > CQE_ERR_INFO_MAX_NUM) {
    2149            1 :         hccp_err("[get][cqe_err_info_list]num(%u) is invalid!", *num);
    2150            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2151              :     }
    2152              : 
    2153            1 :     ret = RaHdcGetCqeErrInfoList(raRdmaHandle, infoList, num);
    2154            1 :     return ConverReturnCode(RDMA_OP, ret);
    2155              : }
    2156              : 
    2157            9 : HCCP_ATTRI_VISI_DEF int RaGetQpAttr(void *qpHandle, struct QpAttr *attr)
    2158              : {
    2159            9 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2160            9 :     int ret = 0;
    2161              : 
    2162            9 :     if (qpHandle == NULL || attr == NULL) {
    2163            4 :         hccp_err("[get][GetQpAttr]qpHandle or attr is NULL, para error!");
    2164            4 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2165              :     }
    2166              : 
    2167            5 :     attr->qpn = raQpHandle->qpn;
    2168            5 :     attr->udpSport = raQpHandle->typicalQpAttr.udpSport;
    2169            5 :     attr->pathMtu = raQpHandle->typicalQpAttr.pathMtu;
    2170            5 :     attr->vendorPrivInfo = raQpHandle->typicalQpAttr.vendorPrivInfo;
    2171            5 :     attr->psn = raQpHandle->psn;
    2172            5 :     attr->gidIdx = raQpHandle->gidIdx;
    2173            5 :     (void)memcpy_s(attr->gid, HCCP_GID_RAW_LEN, raQpHandle->rdmaHandle->gid, HCCP_GID_RAW_LEN);
    2174              : 
    2175            5 :     if (raQpHandle->rdmaOps != NULL && raQpHandle->rdmaOps->raGetQpHyperFeature != NULL) {
    2176            3 :         ret = raQpHandle->rdmaOps->raGetQpHyperFeature(raQpHandle, &attr->feature);
    2177            3 :         if (ret != 0) {
    2178            1 :             hccp_warn("[get][GetQpAttr]raGetQpHyperFeature unsuccessful, ret:%d phyId:%u qpn:%u", ret,
    2179              :                 raQpHandle->phyId, raQpHandle->qpn);
    2180              :         }
    2181              :     }
    2182              : 
    2183            5 :     return 0;
    2184              : }
    2185              : 
    2186            5 : HCCP_ATTRI_VISI_DEF int RaCreateSrq(const void *rdmaHandle, struct SrqAttr *attr)
    2187              : {
    2188              :     int ret;
    2189            5 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2190              : 
    2191            5 :     if (rdmaHandle == NULL) {
    2192            1 :         hccp_err("[ra_create_srq]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2193            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2194              :     }
    2195              : 
    2196            4 :     if (attr == NULL) {
    2197            1 :         hccp_err("[ra_create_srq]srq_attr is NULL");
    2198            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2199              :     }
    2200              : 
    2201              :     // 创建srq&srq cq
    2202            3 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raCreateSrq == NULL) {
    2203            1 :         hccp_err("[ra_create_srq]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_create_srq "
    2204              :                  "is NULL, invalid");
    2205            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2206              :     }
    2207              : 
    2208            2 :     ret = raRdmaHandle->rdmaOps->raCreateSrq(raRdmaHandle, attr);
    2209            2 :     return ConverReturnCode(RDMA_OP, ret);
    2210              : }
    2211              : 
    2212            5 : HCCP_ATTRI_VISI_DEF int RaDestroySrq(const void *rdmaHandle, struct SrqAttr *attr)
    2213              : {
    2214              :     int ret;
    2215            5 :     struct RaRdmaHandle *raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2216              : 
    2217            5 :     if (rdmaHandle == NULL) {
    2218            1 :         hccp_err("[ra_destroy_srq]rdma_handle(%p) is NULL, para error!", rdmaHandle);
    2219            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2220              :     }
    2221              : 
    2222            4 :     if (attr == NULL) {
    2223            1 :         hccp_err("[ra_destroy_srq]srq_handle is NULL");
    2224            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2225              :     }
    2226              : 
    2227              :     // 销毁srq&srq cq
    2228            3 :     if (raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raDestroySrq == NULL) {
    2229            1 :         hccp_err("[ra_destroy_srq]rdma_ops is NULL or ra_rdma_handle->rdma_ops->ra_destroy_srq "
    2230              :                  "is NULL, invalid");
    2231            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2232              :     }
    2233              : 
    2234            2 :     ret = raRdmaHandle->rdmaOps->raDestroySrq(raRdmaHandle, attr);
    2235            2 :     return ConverReturnCode(RDMA_OP, ret);
    2236              : }
    2237              : 
    2238            3 : HCCP_ATTRI_VISI_DEF int RaCreateEventHandle(int *eventHandle)
    2239              : {
    2240              :     int ret;
    2241              : 
    2242            3 :     if (eventHandle == NULL) {
    2243            1 :         hccp_err("[ra_create_event_handle]event_handle is NULL");
    2244            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2245              :     }
    2246              : 
    2247            2 :     ret = RaPeerCreateEventHandle(eventHandle);
    2248            2 :     if (ret) {
    2249            1 :         hccp_err("[ra_create_event_handle]ra_peer_create_event_handle failed ret(%d)", ret);
    2250            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2251              :     }
    2252            1 :     return 0;
    2253              : }
    2254              : 
    2255            6 : HCCP_ATTRI_VISI_DEF int RaCtlEventHandle(int eventHandle, const void *fdHandle, int opcode, enum RaEpollEvent event)
    2256              : {
    2257              :     int ret;
    2258              : 
    2259            6 :     if (eventHandle < 0) {
    2260            1 :         hccp_err("[ra_ctl_event_handle]event_handle[%d] is invalid", eventHandle);
    2261            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2262              :     }
    2263            5 :     if (fdHandle == NULL) {
    2264            1 :         hccp_err("[ra_ctl_event_handle]fd_handle is NULL");
    2265            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2266              :     }
    2267            4 :     if (opcode != EPOLL_CTL_ADD && opcode != EPOLL_CTL_DEL && opcode != EPOLL_CTL_MOD) {
    2268            1 :         hccp_err("[ra_ctl_event_handle]opcode[%d] invalid, valid opcode includes {%d, %d, %d}", opcode, EPOLL_CTL_ADD,
    2269              :             EPOLL_CTL_DEL, EPOLL_CTL_MOD);
    2270            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2271              :     }
    2272            3 :     if (event >= RA_EPOLLINVALD) {
    2273            1 :         hccp_err("[ra_ctl_event_handle]event[%d] invalid, valid range [0, %d)", event, RA_EPOLLINVALD);
    2274            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2275              :     }
    2276              : 
    2277            2 :     ret = RaPeerCtlEventHandle(eventHandle, fdHandle, opcode, event);
    2278            2 :     if (ret) {
    2279            1 :         hccp_err("[ra_ctl_event_handle]ra_peer_ctl_event_handle failed ret(%d)", ret);
    2280            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2281              :     }
    2282            1 :     return 0;
    2283              : }
    2284              : 
    2285            7 : HCCP_ATTRI_VISI_DEF int RaWaitEventHandle(int eventHandle, struct SocketEventInfoT *eventInfos, int timeout,
    2286              :     unsigned int maxevents, unsigned int *eventsNum)
    2287              : {
    2288              :     int ret;
    2289              : 
    2290            7 :     if (eventHandle < 0) {
    2291            1 :         hccp_err("[ra_wait_event_handle]event_handle[%d] is invalid", eventHandle);
    2292            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2293              :     }
    2294              : 
    2295            6 :     if (eventInfos == NULL) {
    2296            1 :         hccp_err("[ra_wait_event_handle]event_infos is NULL");
    2297            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2298              :     }
    2299              : 
    2300            5 :     if (timeout < -1) {
    2301            1 :         hccp_err("[ra_wait_event_handle]timeout[%d ms] is invalid", timeout);
    2302            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2303              :     }
    2304              : 
    2305            4 :     if (maxevents > MAX_SOCKET_EVENT_NUM) {
    2306            1 :         hccp_err("[ra_wait_event_handle]maxevents[%u] exceeds %u", maxevents, MAX_SOCKET_EVENT_NUM);
    2307            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2308              :     }
    2309              : 
    2310            3 :     if (eventsNum == NULL) {
    2311            1 :         hccp_err("[ra_wait_event_handle]events_num is NULL");
    2312            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2313              :     }
    2314              : 
    2315            2 :     ret = RaPeerWaitEventHandle(eventHandle, eventInfos, timeout, maxevents, eventsNum);
    2316            2 :     if (ret) {
    2317            1 :         hccp_err("[ra_wait_event_handle]ra_peer_wait_event_handle failed ret(%d)", ret);
    2318            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2319              :     }
    2320            1 :     return 0;
    2321              : }
    2322              : 
    2323            3 : HCCP_ATTRI_VISI_DEF int RaDestroyEventHandle(int *eventHandle)
    2324              : {
    2325              :     int ret;
    2326              : 
    2327            3 :     if (eventHandle == NULL) {
    2328            1 :         hccp_err("[ra_destroy_event_handle]event_handle is NULL");
    2329            1 :         return ConverReturnCode(SOCKET_OP, -EINVAL);
    2330              :     }
    2331              : 
    2332            2 :     ret = RaPeerDestroyEventHandle(eventHandle);
    2333            2 :     if (ret) {
    2334            1 :         hccp_err("[ra_destroy_event_handle]ra_peer_destroy_event_handle failed ret(%d)", ret);
    2335            1 :         return ConverReturnCode(SOCKET_OP, ret);
    2336              :     }
    2337            1 :     return 0;
    2338              : }
    2339              : 
    2340            4 : HCCP_ATTRI_VISI_DEF int RaPollCq(void *qpHandle, bool isSendCq, unsigned int numEntries, void *wc)
    2341              : {
    2342              :     int ret;
    2343            4 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2344              : 
    2345            4 :     if (qpHandle == NULL || wc == NULL) {
    2346            1 :         hccp_err("[ra_poll]qp_handle is NULL or wc is NULL, para error!");
    2347            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2348              :     }
    2349              : 
    2350            3 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raPollCq == NULL) {
    2351            1 :         hccp_err("[ra_poll]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_poll_cq is NULL, invalid");
    2352            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2353              :     }
    2354              : 
    2355            2 :     ret = raQpHandle->rdmaOps->raPollCq(raQpHandle, isSendCq, numEntries, wc);
    2356            2 :     if (ret < 0) {
    2357            1 :         return ConverReturnCode(RDMA_OP, ret);
    2358              :     }
    2359            1 :     return ret;
    2360              : }
    2361              : 
    2362            3 : HCCP_ATTRI_VISI_DEF int RaTypicalQpModify(void *qpHandle, struct TypicalQp *localQpInfo, struct TypicalQp *remoteQpInfo)
    2363              : {
    2364            3 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2365              :     unsigned int phyId;
    2366              :     int ret;
    2367              : 
    2368            3 :     if (qpHandle == NULL || raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raTypicalQpModify == NULL) {
    2369            1 :         hccp_err("[modify][ra_qp]qp_handle is NULL or func is NULL");
    2370            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2371              :     }
    2372              : 
    2373            2 :     if (localQpInfo == NULL || remoteQpInfo == NULL) {
    2374            1 :         hccp_err("[modify][ra_qp]local_qp_info is NULL or remote_qp_info is NULL");
    2375            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2376              :     }
    2377              : 
    2378            1 :     phyId = raQpHandle->phyId;
    2379            1 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    2380            0 :         hccp_err("[modify][ra_qp]phyId(%u) must be greater than or equal to 0 and less than %d!", phyId,
    2381              :             RA_MAX_PHY_ID_NUM);
    2382            0 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2383              :     }
    2384              : 
    2385            1 :     hccp_run_info("Input parameters: phyId[%u] local_qpn[%u] remote_qpn[%u]", phyId, localQpInfo->qpn,
    2386              :         remoteQpInfo->qpn);
    2387              : 
    2388            1 :     ret = raQpHandle->rdmaOps->raTypicalQpModify(raQpHandle, localQpInfo, remoteQpInfo);
    2389            1 :     if (ret != 0) {
    2390            0 :         hccp_err("[modify][ra_qp]modify qp failed, ret(%d) phyId(%u)", ret, phyId);
    2391            0 :         return ConverReturnCode(RDMA_OP, ret);
    2392              :     }
    2393              : 
    2394            1 :     return 0;
    2395              : }
    2396              : 
    2397            2 : HCCP_ATTRI_VISI_DEF int RaTypicalSendWr(void *qpHandle, struct SendWr *wr, struct SendWrRsp *opRsp)
    2398              : {
    2399            2 :     struct RaQpHandle *raQpHandle = (struct RaQpHandle *)qpHandle;
    2400              :     int ret;
    2401              : 
    2402            2 :     if (qpHandle == NULL || wr == NULL || wr->bufList == NULL || opRsp == NULL) {
    2403            1 :         hccp_err("[send][ra_wr]qp_handle or wr or buf_list or op_rsp is NULL, para error!");
    2404            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2405              :     }
    2406              : 
    2407            1 :     if (wr->bufList->len > MAX_SG_LIST_LEN_MAX) {
    2408            0 :         hccp_err("[send][ra_wr]sg list len is more than 2G, len(%u)", wr->bufList->len);
    2409            0 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2410              :     }
    2411              : 
    2412            1 :     if (raQpHandle->rdmaOps == NULL || raQpHandle->rdmaOps->raTypicalSendWr == NULL) {
    2413            0 :         hccp_err("[send][ra_wr]rdma_ops is NULL or ra_qp_handle->rdma_ops->ra_typical_send_wr is NULL, invalid");
    2414            0 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2415              :     }
    2416              : 
    2417            1 :     ret = raQpHandle->rdmaOps->raTypicalSendWr(raQpHandle, wr, opRsp);
    2418            1 :     return ConverReturnCode(RDMA_OP, ret);
    2419              : }
    2420              : 
    2421            5 : HCCP_ATTRI_VISI_DEF int RaSocketGetVnicIpInfos(unsigned int phyId, enum IdType type, unsigned int ids[],
    2422              :     unsigned int num, struct IpInfo infos[])
    2423              : {
    2424              :     int ret;
    2425              : 
    2426            5 :     if (ids == NULL || num == 0 || infos == NULL) {
    2427            1 :         hccp_err("[get][vnic_ip]ids is NULL or num:%u == 0 or infos is NULL", num);
    2428            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2429              :     }
    2430              : 
    2431            4 :     if (phyId >= RA_MAX_PHY_ID_NUM) {
    2432            1 :         hccp_err("[get][vnic_ip]phyId(%u) is invalid! it must be greater than or equal to 0 and less than %d!", phyId,
    2433              :             RA_MAX_PHY_ID_NUM);
    2434            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2435              :     }
    2436              : 
    2437            3 :     if (type != PHY_ID_VNIC_IP && type != SDID_VNIC_IP) {
    2438            1 :         hccp_err("[get][vnic_ip]type[%u] invalid", type);
    2439            1 :         return ConverReturnCode(OTHERS, -EINVAL);
    2440              :     }
    2441              : 
    2442            2 :     ret = RaHdcGetVnicIpInfos(phyId, type, ids, num, infos);
    2443            2 :     if (ret) {
    2444            2 :         hccp_err("[get][vnic_ip]ra_hdc_get_vnic_ip_infos failed, ret(%d)", ret);
    2445            2 :         return ConverReturnCode(OTHERS, ret);
    2446              :     }
    2447            0 :     return 0;
    2448              : }
    2449              : 
    2450            5 : int RaQpBatchModifyCheckParam(void *rdmaHandle, void *qpHandle[], unsigned int num, int expectStatus)
    2451              : {
    2452              :     unsigned int i;
    2453              : 
    2454            5 :     if (rdmaHandle == NULL || num == 0 || qpHandle == NULL ||
    2455            2 :         ((expectStatus != RA_QP_STATUS_CONNECTED) && (expectStatus != RA_QP_STATUS_PAUSE))) {
    2456            1 :         hccp_err("[batch_modify][check param]expect_status is %d or rdma_handle is NULL or num[%u] is 0!", expectStatus,
    2457              :             num);
    2458            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2459              :     }
    2460              : 
    2461            7 :     for (i = 0; i < num; i++) {
    2462            4 :         if (qpHandle[i] == NULL) {
    2463            1 :             hccp_err("[modify][ra_qp]qp_handle[%u] is NULL", i);
    2464            1 :             return ConverReturnCode(RDMA_OP, -EINVAL);
    2465              :         }
    2466              :     }
    2467              : 
    2468            3 :     return 0;
    2469              : }
    2470              : 
    2471            5 : HCCP_ATTRI_VISI_DEF int RaQpBatchModify(void *rdmaHandle, void *qpHandle[], unsigned int num, int expectStatus)
    2472              : {
    2473            5 :     struct RaRdmaHandle *raRdmaHandle = NULL;
    2474              :     unsigned int phyId;
    2475              :     int ret;
    2476              : 
    2477            5 :     ret = RaQpBatchModifyCheckParam(rdmaHandle, qpHandle, num, expectStatus);
    2478            5 :     CHK_PRT_RETURN(ret, hccp_err("ra_qp_batch_modify_check_param invalid[%d]", ret), ret);
    2479              : 
    2480            3 :     raRdmaHandle = (struct RaRdmaHandle *)rdmaHandle;
    2481            3 :     phyId = raRdmaHandle->rdevInfo.phyId;
    2482            3 :     if (phyId >= RA_MAX_PHY_ID_NUM || raRdmaHandle->rdmaOps == NULL || raRdmaHandle->rdmaOps->raQpBatchModify == NULL) {
    2483            1 :         hccp_err("[modify][ra_qp]phyId(%u) must be greater than or equal to 0 and less than %d or ops is NULL or "
    2484              :                  "ra_rdma_handle->rdma_ops->ra_qp_batch_modify is NULL!",
    2485              :             phyId, RA_MAX_PHY_ID_NUM);
    2486            1 :         return ConverReturnCode(RDMA_OP, -EINVAL);
    2487              :     }
    2488              : 
    2489            2 :     hccp_run_info("Input parameters: phyId[%u] num[%u] expect_status[%d]", phyId, num, expectStatus);
    2490              : 
    2491              :     // avoid poll_cq thread to poll cq
    2492            2 :     if ((raRdmaHandle->supportLite != 0) && expectStatus == RA_QP_STATUS_PAUSE) {
    2493            1 :         RA_PTHREAD_MUTEX_LOCK(&raRdmaHandle->rdevMutex);
    2494              :     }
    2495            2 :     ret = raRdmaHandle->rdmaOps->raQpBatchModify(rdmaHandle, qpHandle, num, expectStatus);
    2496            2 :     if (ret != 0) {
    2497            0 :         hccp_err("[modify][ra_qp_batch_modify]modify qp to [%d] failed, ret[%d] phyId[%u]", expectStatus, ret, phyId);
    2498              :     }
    2499            2 :     if ((raRdmaHandle->supportLite != 0) && expectStatus == RA_QP_STATUS_PAUSE) {
    2500            1 :         RA_PTHREAD_MUTEX_UNLOCK(&raRdmaHandle->rdevMutex);
    2501              :     }
    2502              : 
    2503            2 :     return ret;
    2504              : }
        

Generated by: LCOV version 2.0-1